Download symbolic logic and logic processing

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Fuzzy concept wikipedia , lookup

AI winter wikipedia , lookup

Personal knowledge base wikipedia , lookup

Fuzzy logic wikipedia , lookup

Expert system wikipedia , lookup

History of artificial intelligence wikipedia , lookup

Logic programming wikipedia , lookup

Knowledge representation and reasoning wikipedia , lookup

Transcript
SYMBOLIC LOGIC AND
LOGIC PROCESSING
SYMBOLIC LOGIC AND
LOGIC PROCESSING
By
Ms. Bindu Bansal
UNIVERSITY SCIENCE PRESS
(An Imprint of Laxmi Publications Pvt. Ltd.)
BANGALORE · CHENNAI
JALANDHAR
· KOLKATA
· COCHIN
· GUWAHATI
· HYDERABAD
· LUCKNOW
· MUMBAI
· PATNA
RANCHI
· NEW DELHI
Copyright © 2013 by Laxmi Publications Pvt. Ltd. All rights reserved. No
part of this publication may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, electronic, mechanical, photocopying,
recording or otherwise without the prior written permission of the publisher.
Published by :
UNIVERSITY SCIENCE PRESS
(An Imprint of Laxmi Publications Pvt. Ltd.)
113, Golden House, Daryaganj,
New Delhi-110002
Phone : 011-43 53 25 00
Fax : 011-43 53 25 28
www.laxmipublications.com
[email protected]
Price : < 275.00 Only.
First Edition: 2013
OFFICES
Bangalore
Cochin
Hyderabad
Kolkata
Mumbai
080-26 75 69 30
0484-237 70 04, 405 13 03
040-24 65 23 33
033-22 27 43 84
022-24 91 54 15, 24 92 78 69
USL-9665-275-SYMBOLIC LOGIC PROC-BAN
Typesetted at : Shubham Composer, New Delhi.
Chennai
Guwahati
Jalandhar
Lucknow
Ranchi
044-24 34 47 26
0361-251 36 69, 251 38 81
0181-222 12 72
0522-220 99 16
0651-2204464, 221 47 64
C—
Printed at :
CONTENTS
CHAPTER 1. Introduction to Logic and Knowledge
1.1 Logic-a Preliminary Definition
1.2 Formal and Informal Logics
1.3 Symbolic Logic
1.4 Knowledge-Definition and Importance
1.5 Knowledge Based Systems (KBS)
1.6 Knowledge Organization
1.7 Knowledge Manipulation
1.8 Knowledge Acquisition
Review Questions
CHAPTER 2. Introduction to Artificial Intelligence
2.1
2.2
2.3
2.4
2.5
2.6
What is Intelligence?
Evolving Artificial Intelligence
Introduction of Artificial Intelligence
Strong AI, Applied AI and CS Cognitive Simulation
Disciplines of Artificial Intelligence
Applications of Artificial Intelligence Techniques
Review Questions
1–6
1
2
3
4
5
5
6
6
6
7–17
7
8
9
12
13
15
17
CHAPTER 3. The Search Process
3.1 Search as a Problem-Solving Technique
3.2 Terminology
3.3 Search Strategies
3.4 Data Driven (Forward Chaining) and Goal Driven
(Backward Chaining) Search
3.5 Brute Force Search (Uninformed Search)
3.6 Informed Search or Heuristic Search or Intelligent Search
3.7 Various Heuristic Search Techniques
3.8 Applications of Search Techniques in Game Playing
3.9 Game Playing Strategies
3.10 Performance of Game Playing Algorithms
3.11 Problems Associated with Minimax Procedure
Review Questions
18–56
18
19
20
CHAPTER 4. Knowledge Representation
4.1 Framework of Knowledge Representation
4.2 Representing Knowledge or Levels of KR
4.3 Approaches to Knowledge Representation or KR Schemes
4.4 Issues in Knowledge Representation
Review Questions
(v)
57–67
57
59
61
64
67
21
22
27
28
39
40
44
44
56
vi
CHAPTER 5. KR Using Logic
5.1 Propositional Logic (PL)
5.2 Predicate Calculus or First Order Predicate Logic (FOPL)
5.3 Conversion to Clausal Normal Form
5.4 Resolution
Review Questions
68–94
68
76
81
85
93
CHAPTER 6. Other Knowledge Representation Techniques
6.1 Logical Representations
6.2 Semantic Networks (Associative Networks)
6.3 Production Rule Representations
6.4 Frame Representations
6.5 Scripts
Review Questions
95–122
95
97
105
116
121
122
CHAPTER 7. Programming Languages in Artificial Intelligence
7.1 AI Programming Languages
7.2 Functional Programming
7.3 Functional Programming in Lisp
7.4 Logical Programming in Prolog
7.5 Other Programming Approaches
Review Questions
123–134
123
124
124
130
134
134
CHAPTER 8. Introduction to Logic Programming and Prolog
8.1 Logic Programming
8.2 History of Logic Programming
8.3 Brief Overview of the Logic Programming Paradigm
8.4 Introduction to Prolog
8.5 Interpreters and Compilers
8.6 Varieties of Prolog
8.7 Some Prolog Variants
8.8 Characteristics of Prolog
Review Questions
135–142
135
136
137
138
139
140
140
142
142
CHAPTER 9. Syntax & Semantics of Prolog
9.1 Syntax of Prolog
9.2 Features of Prolog
9.3 Prolog as a Relational Language
9.4 What is a Prolog Program?
9.5 Answering Queries
9.6 Declarative Meaning of Prolog Programs
9.7 Procedural Meaning of Prolog Programs
9.8 An Initial Session with Prolog
9.9 The Prolog Database
9.10 Abstract Data Types (ADTS) in Prolog
Review Questions
143–165
143
145
152
153
154
156
157
158
160
162
165
CHAPTER 10. Operators, Arithmetic & List Manipulation
10.1 Operator Notation
166–185
166
vii
10.2
10.3
10.4
10.5
10.6
10.7
10.8
10.9
10.10
10.11
Arithmetic in Prolog
Character Strings
Inputting a Line as a String or an Atom
Structures
The “Occurs Check”
Data Storage Strategies
Lists
List Manipulation Operations
Manipulating Sets in Prolog
Use of Accumulators
Review Questions
167
170
171
171
172
173
174
176
180
181
184
CHAPTER 11. Backtracking, Cuts & Negation
11.1 Backtracking
11.2 Introducing Cuts
11.3 The Closed World Assumption
11.4 Negation as Failure
11.5 Cut-Fail Combination
11.6 Disjunction
Review Questions
186–200
186
188
196
197
198
198
199
CHAPTER 12. Input Output and Built-in Predicates
12.1 Communication between Prolog & Files
12.2 Reading and Writing Terms
12.3 Displaying Lists
12.4 Examples on Output Predicates
12.5 Computing Versus Printing
12.6 Forcing Backtracking with Fail
12.7 Reading and Writing Characters
12.8 Reading Programs
12.9 File Handling: See, Seen, Tell, Told
Review Questions
201–211
201
202
203
204
205
205
207
207
210
211
CHAPTER 13. More on Built in Predicates
13.1 Meta-Logical Predicates
13.2 Analysing and Constructing Terms
13.3 Static and Dynamic Predicates
13.4 Database Manipulation
13.5 All Solutions and Aggregate Predicates
Review Questions
212–228
212
216
220
221
225
227
CHAPTER 14. Logic Foundations of Prolog
14.1 Translating Prolog Clauses into Formulas
14.2 Horn Formulas and Resolution
14.3 Prolog Implementation for Conversion of a Wff to Clausal Form
Review Questions
229–234
229
230
232
234
CHAPTER 15. Resolution in Prolog (SLD-Resolution)
15.1 SLD-Derivation
15.2 SLD-Refutation
236–244
236
237
viii
15.3
15.4
15.5
15.6
15.7
The Computation Rule & Search Rule
Failed Derivation
SLD–Tree
Proof Trees
Soundness and Completeness of SLD-Resolution
Review Questions
238
240
240
241
243
244
CHAPTER 16. Searching and Sorting in Prolog
16.1 Sorting in Prolog
16.2 Searching in Prolog
Review Questions
245–254
245
247
254
CHAPTER 17. Definite Clause Grammars
17.1 Context Free Grammars
17.2 Definite Clause Grammars
Review Questions
255–262
255
259
262
CHAPTER 18. Coding Standards & Debugging in Prolog
18.1 Layout of Programs
18.2 Naming Conventions
18.3 Documentation
18.4 Language Idioms
18.5 Development, Debugging and Testing
18.6 Tips for Good Programming Style
18.7 Commenting
18.8 Debugging
18.9 Tracing Model
18.10 The Procedure Box Model or Byrad’s Box Model
18.11 Debugging and Tracing Options
18.12 SWI-Prolog Tracer and Graphical Debugger
Review Questions
263–280
263
267
268
270
271
274
274
275
275
276
277
278
280
CHAPTER 19. Assessment of Prolog
281–283
CHAPTER 20. Fuzzy Logic and Neural Network
20.1 Theory of Fuzzy Sets
20.2 Basic Terms and Fuzzy Operations
20.3 Properties of Fuzzy Sets
20.4 Applications of Fuzzy Systems
20.5 Artificial Neural Networks
20.6 Neural Fuzzy Systems
20.7 Fuzzy Expert System
284–300
284
285
286
287
289
294
298
Appendices
301–355
Index
356–360
PREFACE
Artificial Intelligence is a blend of three main academic disciplines namely psychology (cognitive
science), philosophy (mind) and computer science with further strands from mathematics, logic
and linguistics. The aim of AI is broad: to get below the surface of human behaviour; to discover the
processes, systems and principles that make intelligent behaviour possible. There are many practical
applications of AI which include the design of computer systems that can perceive, learn, solve
problems, and make plans and converse in natural language like English. Some systems that are
commercially in use are medical diagnosis, identifying ships from satellite pictures, language
translation and science training.
This book does not require much formal mathematics but does require some mathematical
maturity. Much of the material, in theory, can be read & understood with no more background
than high school mathematics. This volume is an outgrowth of my accumulated experience of
teaching the subject as well as conducting various research activities in this field.
The comprehensive text is primarily designed for post graduate and graduate students of
computer science, compiler engineering, computer applications and information technology.
It really serves as a useful text for students of B.E. and B.Tech, offering courses in artificial intelligence
or symbolic logic or logic programming or expert systems. The book covers almost all essential
components of AI and knowledge based systems and syllabus of various universities of India. It
includes concepts of AI as well as logic programming PROLOG.
To the possible extent each chapter has been kept independent and stands alone. The book has
been organized in three parts with total 20 chapters. Chapter 1 includes an introduction to logic
and knowledge. Chapter 2 presents introduction to AI. Chapter 3 focuses on the search strategies
which are extremely useful in AI. Chapter 4 contains an introduction to knowledge representation.
Chapter 5 contains the important knowledge representation technique i.e., logic. Chapter 6 further
throws light on other KR techniques viz., semantic nets, production rules, frames, scripts.
Part 2 of the book is based on logic programming i.e., PROLOG. Chapters 7–19 contain a complete
full-fledged concept of PROLOG in detail. Chapter 19 assesses about PROLOG.
Part 3 i.e., chapter 20 throws light on the important issues of AI i.e., Fuzzy Logic & Neural
Networks. There is appendix about the terminology of AI & Prolog. It is possible to treat topics
selectively to plan a one or two semester course on AI or Expert Systems or SLLP.
There are number of individuals whose grateful help I would like to acknowledge. I am thankful
to all my friends and colleagues who inspired me to write this book. I am thankful to Prof. HPS
Dhami who encourage me to write I would like to thank Laxmi Publications for publishing this
book & helping me to complete the manuscript. I also owe much to my family. Last but not least I
would like to thank GOD without whose wish this day would not be possible for me to see.
I hope students & faculty will enjoy reading this book. Nobody is perfect in universe. So, your
suggestions are always welcome.
—Author
(ix)
Introduction to Logic and Knowledge
1
1
INTRODUCTION TO LOGIC
AND KNOWLEDGE
This chapter deals with an introduction to logic and knowledge. Logic plays an important role in
the foundation of computer science and has two important roles to play in this area.
1. In the study of computer science foundations, theoretically from outside. Here, logic acts as a
meta computer which offers classification of problems and computability according to their
complexity.
2. As a basis of logic programming, Logic acts as a paradigm for programming in logic. Practical
logic programming language called Prolog is widely used for building many applications.
1.1 LOGIC-A PRELIMINARY DEFINITION
The term “logic” has been derived from the Greek word logos, which is translated as “sentence”,
“discourse”, “reason”, “rule”, and “ratio”. Of course, it is not enough to help us understand the
specialized meaning of “logic”.
So, what is logic? Briefly speaking, logic can be defined as the study of the principles of correct
reasoning. Some scholar’s definitions for logic are:
Averroes defined logic as “The tool for distinguishing between the true and the false”;
Richard Whately, “The Science, as well as the Art of reasoning”;
Frege. “The science of the most general laws of truth”.
The Greek philosopher Aristotle is generally regarded as the “father” of the logic. His conception
of syllogistic logic remains a cornerstone of the study of logic even today. Others who have played
important role in the development of logic includes Peter Abelard, William of Occam, Wilhelm Leibniz,
Gottlob Frege, Kurt Goedel, and John Venn.
The central focus of logic falls on the systematized study of valid and sound reasoning. In
particular, it is interested in the study of the structure of proposition rather than their actual
content.
1
2 Symbolic Logic and Logic Processing
The reasoning studied can be either Deductive or Inductive, although studies of logic more often
involves deductive arguments.
Aristotle configured 2 different types of logic. (i) Deductive Reasoning (ii) Inductive Reasoning.
(i) A deductive argument is one which claims that it is impossible for the premises to be true,
but the conclusion false. Thus, conclusion follows necessarily from the premises and inferences. In this way, it is supposed to be a definitive proof of the truth of the claim (conclusion).
For example:
1. All men are mortal. (premise)
2. John was a man. (premise)
3. John was mortal. (conclusion)
(ii) Inductive arguments follow the method of reasoning known as induction, which involves
developing, by interencing, some general laws from particular cases and instances.
1.1.1
Types of Logic
1. Informal logic is the study of natural language arguments. The study of fallacies is an especially important branch of informal logic.
2. Formal logic is the study of inference with purely formal content. An inference process
possesses a purely formal content if it can be expressed as a particular application of a
wholly abstract rule, i.e. a rule that is not about any particular thing or property.
3. Symbolic logic is the study of symbolic abstractions that capture the formal feature of
logical inference. Symbolic logic is divided into two branches, propositional logic and predicate logic.
4. Mathematical logic is an extension of symbolic logic into other areas, in particular in the
study of model theory, proof theory, set theory, and recursion theory.
1.1.2
Properties of Logical Systems
The important properties of logical systems are:
1. Consistency, which means that no theorem of the system contradicts another.
2. Validity, which means that the system’s rules of proof will never allow a false inference from
true premises.
3. Soundness, which means that the system’s rules of proof will never allow a false inference
from true premises, and the premises prove true. Soundness results from both validity and
true premises. If a system is sound and its axioms are true, then its theorems are also guaranteed to be true.
4. Completeness, which means that if a theorem is true, it can be proven.
1.2 FORMAL AND INFORMAL LOGICS
The term “Informal Logic” is the study of reasoning and fallacies in the context of everyday life.
While “Formal No Paragraph Logic” is mainly concerned with formal systems of logic. These
systems specially constructed for carrying out proofs, where the languages and rules of reasoning
are carefully and precisely defined. Sentential logic (also known as “Propositional logic”) and
Predicate Logic are both examples of formal systems of logic.
Introduction to Logic and Knowledge
3
There are many reasons for studying formal logic. One is that formal logic helps us to identify
patterns of good reasoning and patterns of bad reasoning, so we can know which to follow and
which to avoid. That’s why studying basic formal logic helps improving critical thinking. Formal
systems of logic are also used by linguists to study natural languages. Computer scientists also use
formal systems of logic in research relating to Artificial Intelligence. Finally, many philosophers
also like to use formal logic when dealing with complicated philosophical problems, in order to
make their reasoning more explicit and precise.
1.3 SYMBOLIC LOGIC
Symbolic logic is the area of mathematics which studies the purely formal properties of strings of
symbols. The interest in this area springs from two sources:
(i) The symbols used in symbolic logic can be seen as representing the words used in philosophical logic.
(ii) The rules for manipulating symbols found in symbolic logic can be implemented on a computing machine.
Symbolic logic is usually divided into two subfields, propositional logic and predicate logic.
Other logics of interest include temporal logic, model logic and fuzzy logic.
1.3.1
Propositional Logic
The area of symbolic logic called propositional logic, originally called propositional calculus studies
the properties of sentences formed from constants, usually designated p, q, r,… and five logical
operators, AND, OR, IF…THEN, IF AND ONLY IF and NOT. The corresponding logical operations
are, respectively, as conjunction, disjunction, material conditional, biconditional, and negation.
These five operators are sometimes denoted as keywords. All except NOT are binary operators;
NOT is a unary operator which precedes its operand. The values of these operators are given by
truth tables.
The Sheffer operator, commonly represented as |, parallels the nand operator in computer language, is also used to mark logical incompatibility or binary inconsistency. The neither…nor operator, represented by a downwards arrow, (¯) is also commonplace. All complex connectors
(conditional, biconditional, sheffer, neither…nor) can be reduced to the three fundamental connectors which are the conjuction, disjunction and negation (NOT).
1.3.2
Predicate Logic
Predicate logic is the generic term for symbolic formal systems such as first-order logic, secondorder logic, many-sorted logic, and infinitary logic.
Predicate logic, originally called predicate calculus, expands on propositional logic by the introduction of variables, usually denoted by x, y, z, or other lowercase letters and also by the introduction of sentence containing variables called Predicates, usually denoted by an uppercase letter
followed by a list of variables, such as P(x) or Q(y, z). In addition, predicate logic allows the use of
quantifiers, representing ALL and EXISTS. It is used to express a wide set of arguments occurring in
natural language.
4 Symbolic Logic and Logic Processing
One another type of logic is called modal logic. Modal logic involves the study of the reasoning
behind what might be true-that is, the study of the reasoning behind different modes of reality. The
letter L is used to represent “it is necessary that” and the letter M is used to represent “it is possible
that”. Thus, (Lp) means” it is necessary that p” and (Mp) means “it is possible that p.”
1.4 KNOWLEDGE-DEFINITION AND IMPORTANCE
Knowledge can be defined as the set of facts and principle accumulated by human being or the act,
fact or state of knowing. This definition is true but incomplete. Knowledge can be defined more
completely as: Knowledge is familiarity with languages, concepts, rules, procedures, abstractions, places, facts and assoWisdom
ciation etc, coupled with the notion of using all of these in
Intelligence
modeling different aspects of the world more effectively.” There
lies a strong relationship between knowledge and intelligence.
Knowledge
“Intelligence requires possession of and access to knowledge.
Information
Also, we know intelligent people possess more knowledge than
Data
others. So, the thrust force behind every intelligent system is
Symbols
knowledge. Figure 1.1 shows the hierarchy of knowledge.
Members of the hierarchy are:
Fig. 1.1 Hierarchy of Knowledge
1. Symbols: At the base, we have symbols that forms the means of representation.
2. Data: It is simply a collection of symbols.
3. Information: On processing data, we get information.
4. Knowledge: Knowledge is organized information. We can consider knowledge as a piece of
information that helps in decision making.
5. Intelligence: It is ability to draw inferences from the available knowledge.
6. Wisdom: It is the maturity of human brain (mind) that directs its intelligence to achieve
desired goals.
Knowledge should not be confused with data. Knowledge includes and requires use of data and
information and further it also combines relationships, correlations, dependencies with data and
information. This can be illustrated with this example. A physician treats a patient using both
knowledge and data. Here, data is the patient's record which includes patient's history, disease
history, drugs given, response to drugs etc. while knowledge is what physician has learned in his
medical studies, specialization and experience.
A human expert has two types of knowledge:
1. Domain Specific Knowledge.
2. Common Sense Knowledge.
Domain specific knowledge is the one which deals with all kinds of knowledge about a particular domain. Common sense knowledge is one which deals with all other pieces of knowledge that
helps in other than domain specific knowledge. If common sense knowledge is coupled with domain specific knowledge it then increases the performance capability of the system.
Introduction to Logic and Knowledge
5
There are four types of domain specific knowledge:
1. Knowledge about an item or an object.
2. Knowledge about events: Here, knowledge is stored as a set of procedures.
3. Knowledge about task-performance.
4. Knowledge about knowledge: It is also called meta knowledge. i.e piece of knowledge which
helps in controlling and planning the reasoning process. Meta-Knowledge has two main
components.
· Meta Assertion: deals with beliefs about beliefs
· Meta rules: deals with rules about rules
Further knowledge can be of two types i.e. Declarative and Procedural. Declarative knowledge is
passive knowledge expressed as statements of facts about the world eg. personal database. While
procedural knowledge is in complied form related to performance of some task eg. steps required to
solve a problem.
Here, we need to distinguish knowledge from other concepts.
1. Belief: It is a meaningful and coherent expression that can be represented. So, it can be true
or false.
2. Hypothesis: It is a justified belief that is not known to be true. So, a hypothesis is a belief
which has some supporting evidences, but it may still be false.
1.5 KNOWLEDGE BASED SYSTEMS (KBS)
Initially, in AI general purpose problem solvers used a limited number of laws or axioms which
were weak is effective solving complex problem. This realized to the design of KBS which depends
on a rich base of knowledge to perform difficult tasks. Due to this a lot of work done in AI is related
to KBSs which includs work in vision, general problem solving (GPS), learning and natural language understanding. KBSs get their power from expect knowledge that is coded in form be facts,
rules, procedures and heuristics. This knowledge is stored in a knowledge base which is separate
from control and inferencing components. It helps to add new knowledge or refine existing knowledge without recompiling controls and inferencing programs.
Inferencing
and control
unit (ICW)
I/O
Unit
Fig.1.2
1.6
Knowledge
Base
(KB)
Components of KBS
KNOWLEDGE ORGANIZATION
For efficient processing proper organization of knowledge in memory is very important. Our KBS
may have tens of thousand of facts and rules to do the intended task. So, it should be easy to locate
and retrieve the facts and rules in the knowledge base, which otherwise will waste a lot of time in
searching and testing.
Knowledge can be organized in memory by indexing. It means to group the knowledge such that
keywords can be used to access the group. So, to search a specific part of the knowledge we will be
limited to a group only not searching the whole memory.