CPECSC 481 KnowledgeBased Systems Dr Franz J Kurfess
CPE/CSC 481: Knowledge-Based Systems Dr. Franz J. Kurfess Computer Science Department Cal Poly © 2002 -5 Franz J. Kurfess Logic and Reasoning 1
Overview Logic and Reasoning u Motivation u Reasoning in Knowledge. Based Systems u Objectives u Knowledge u u logic as prototypical reasoning system syntax and semantics validity and satisfiability logic languages u Reasoning u u and Reasoning Methods propositional and predicate calculus inference methods © 2002 -5 Franz J. Kurfess u u shallow and deep reasoning forward and backward chaining alternative inference methods meta-knowledge u Important Concepts and Terms u Chapter Summary Logic and Reasoning 2
Logistics u Term Project u Lab and Homework Assignments u Exams u Grading © 2002 -5 Franz J. Kurfess Logic and Reasoning 3
Dilbert on Reasoning 1 © 2002 -5 Franz J. Kurfess Logic and Reasoning 4
Dilbert on Reasoning 2 © 2002 -5 Franz J. Kurfess Logic and Reasoning 5
Dilbert on Reasoning 3 © 2002 -5 Franz J. Kurfess Logic and Reasoning 6
Pre-Test © 2002 -5 Franz J. Kurfess Logic and Reasoning 7
Motivation u without reasoning, knowledge-based systems would be practically worthless u derivation of new knowledge u examination of the consistency or validity of existing knowledge u reasoning in KBS can perform certain tasks better than humans u reliability, availability, speed u also some limitations common-sense reasoning v complex inferences v © 2002 -5 Franz J. Kurfess Logic and Reasoning 8
Objectives u be u familiar with the essential concepts of logic and reasoning sentence, operators, syntax, semantics, inference methods u appreciate the importance of reasoning for knowledge-based systems u u generating new knowledge explanations u understand u u the main methods of reasoning used in KBS shallow and deep reasoning forward and backward chaining u evaluate reasoning methods for specific tasks and scenarios u apply reasoning methods to simple problems © 2002 -5 Franz J. Kurfess Logic and Reasoning 9
Knowledge Representation Languages u syntax u sentences of the language that are built according to the syntactic rules u some sentences may be nonsensical, but syntactically correct u semantics u refers to the facts about the world for a specific sentence u interprets the sentence in the context of the world u provides meaning for sentences u languages with precisely defined syntax and semantics can be called logics © 2002 -5 Franz J. Kurfess Logic and Reasoning 12
Sentences and the Real World u syntax u describes the principles for constructing and combining sentences v v u e. g. BNF grammar for admissible sentences inference rules to derive new sentences from existing ones semantics u u establishes the relationship between a sentence and the aspects of the real world it describes Sentence can be checked directly by comparing sentences with the corresponding objects in the real world v u not always feasible or practical complex sentences can be checked by examining their individual parts © 2002 -5 Franz J. Kurfess Logic and Reasoning 13
Diagram: Sentences and the Real World Semantics Follows Entails Sentences Symbols Syntax Model Derives Symbol Strings © 2002 -5 Franz J. Kurfess Symbol String Logic and Reasoning 14
Introduction to Logic u expresses notation knowledge in a particular mathematical All birds have wings --> ¥x. Bird(x) -> Has. Wings(x) u rules of inference u guarantee that, given true facts or premises, the new facts or premises derived by applying the rules are also true All robins are birds --> ¥x Robin(x) -> Bird(x) u given these two facts, application of an inference rule gives: ¥x Robin(x) -> Has. Wings(x) © 2002 -5 Franz J. Kurfess Logic and Reasoning 15
Logic and Knowledge u rules of inference act on the superficial structure or syntax of the first 2 formulas u doesn't say anything about the meaning of birds and robins u could have substituted mammals and elephants etc. u major advantages of this approach u deductions are guaranteed to be correct to an extent that other representation schemes have not yet reached u easy to automate derivation of new facts u problems u computational efficiency u uncertain, incomplete, imprecise knowledge © 2002 -5 Franz J. Kurfess Logic and Reasoning 16
Summary of Logic Languages u propositional u u facts true/false/unknown u first-order u u u logic facts, objects, relations true/false/unknown u temporal u logic facts, objects, relations, times true/false/unknown u probability u u u theory facts degree of belief [0. . 1] u fuzzy u logic degree of truth degree of belief [0. . 1] © 2002 -5 Franz J. Kurfess Logic and Reasoning 17
Propositional Logic u Syntax u Semantics u Validity and Inference u Models u Inference Rules u Complexity © 2002 -5 Franz J. Kurfess Logic and Reasoning 18
Syntax u symbols u logical constants True, False u propositional symbols P, Q, … u logical connectives conjunction , disjunction , u negation , u implication , equivalence u u parentheses , u sentences u constructed from simple sentences u conjunction, disjunction, implication, equivalence, negation © 2002 -5 Franz J. Kurfess Logic and Reasoning 19
BNF Grammar Propositional Logic Sentence Atomic. Sentence Complex. Sentence Atomic. Sentence | Complex. Sentence True | False | P | Q | R |. . . (Sentence ) | Sentence Connective Sentence | Sentence Connective | | | ambiguities are resolved through precedence or parentheses e. g. P Q R S is equivalent to ( P) (Q R)) S © 2002 -5 Franz J. Kurfess Logic and Reasoning 20
Semantics u interpretation of the propositional symbols and constants u symbols u can be any arbitrary fact sentences consisting of only a propositional symbols are satisfiable, but not valid u the constants True and False have a fixed interpretation u True indicates that the world is as stated u False indicates that the world is not as stated u specification u frequently © 2002 -5 Franz J. Kurfess of the logical connectives explicitly via truth tables Logic and Reasoning 21
Validity and Satisfiability ua sentence is valid or necessarily true if and only if it is true under all possible interpretations in all possible worlds u u also called a tautology since computers reason mostly at the syntactic level, valid sentences are very important v interpretations can be neglected ua sentence is satisfiable iff there is some interpretation in some world for which it is true u a sentence that is not satisfiable is unsatisfiable u also known as a contradiction © 2002 -5 Franz J. Kurfess Logic and Reasoning 22
Truth Tables for Connectives P Q P False True True False © 2002 -5 Franz J. Kurfess P P Q P Q False True Q False True True False True Logic and Reasoning 23
Validity and Inference u truth tables can be used to test sentences for validity u one row for each possible combination of truth values for the symbols in the sentence u the final value must be True for every sentence © 2002 -5 Franz J. Kurfess Logic and Reasoning 24
Propositional Calculus u properly formed statements that are either True or False u syntax u u logical constants, True and False proposition symbols such as P and Q logical connectives: and ^, or V, equivalence <=>, implies => and not ~ parentheses to indicate complex sentences u sentences in this language are created through application of the following rules u u u True and False are each (atomic) sentences Propositional symbols such as P or Q are each (atomic) sentences Enclosing symbols and connective in parentheses yields (complex) sentences, e. g. , (P ^ Q) © 2002 -5 Franz J. Kurfess Logic and Reasoning 25
Complex Sentences u Combining simpler sentences with logical connectives yields complex sentences u conjunction v u u u disjunction sentence whose main connective is or: A V (P ^ Q) implication (conditional) v v u sentence such as (P ^ Q) => R the left hand side is called the premise or antecedent the right hand side is called the conclusion or consequent implications are also known as rules or if-then statements equivalence (biconditional) v u sentence whose main connective is and: P ^ (Q V R) (P ^ Q) <=> (Q ^ P) negation v v the only unary connective (operates only on one sentence) e. g. , ~P © 2002 -5 Franz J. Kurfess Logic and Reasoning 26
Syntax of Propositional Logic u. A BNF (Backus-Naur Form) grammar of sentences in propositional logic Sentence -> Atomic. Sentence | Complex. Sentence Atomic. Sentence -> True | False | P | Q | R |. . . Complex. Sentence -> (Sentence) | Sentence Connective Sentence | ~Sentence Connective -> ^ | V | <=> | => © 2002 -5 Franz J. Kurfess Logic and Reasoning 27
Semantics u propositions u can be interpreted as any facts you want e. g. , P means "robins are birds", Q means "the wumpus is dead", etc. u meaning of complex sentences is derived from the meaning of its parts u u one method is to use a truth table all are easy except P => Q v v v this says that if P is true, then I claim that Q is true; otherwise I make no claim; P is true and Q is true, then P => Q is true P is true and Q is false, then P => Q is false P is false and Q is true, then P => Q is true P is false and Q is false, then P => Q is true © 2002 -5 Franz J. Kurfess Logic and Reasoning 28
Inference Rules u more efficient than truth tables © 2002 -5 Franz J. Kurfess Logic and Reasoning 30
Modus Ponens u eliminates => (X => Y), X _______ Y u If it rains, then the streets will be wet. u It is raining. u Infer the conclusion: The streets will be wet. (affirms the antecedent) © 2002 -5 Franz J. Kurfess Logic and Reasoning 31
Modus tollens (X => Y), ~Y ________ ¬X u u u If it rains, then the streets will be wet. The streets are not wet. Infer the conclusion: It is not raining. u NOTE: u u u Avoid the fallacy of affirming the consequent: If it rains, then the streets will be wet. The streets are wet. cannot conclude that it is raining. If Bacon wrote Hamlet, then Bacon was a great writer. u Bacon was a great writer. © 2002 -5 J. Kurfess Logic and Reasoning u Franz cannot conclude that Bacon wrote Hamlet. u 32
Syllogism u chain implications to deduce a conclusion) (X => Y), (Y => Z) ___________ (X => Z) © 2002 -5 Franz J. Kurfess Logic and Reasoning 33
More Inference Rules u and-elimination u and-introduction u or-introduction u double-negation u unit elimination resolution © 2002 -5 Franz J. Kurfess Logic and Reasoning 34
Resolution (X v Y), (~Y v Z) _________ (X v Z) u basis for the inference mechanism in the Prolog language and some theorem provers © 2002 -5 Franz J. Kurfess Logic and Reasoning 35
Complexity issues u truth table enumerates 2 n rows of the table for any proof involving n symbol u u it is complete computation time is exponential in n u checking u u a set of sentences for satisfiability is NP-complete but there are some circumstances where the proof only involves a small subset of the KB, so can do some of the work in polynomial time if a KB is monotonic (i. e. , even if we add new sentences to a KB, all the sentences entailed by the original KB are still entailed by the new larger KB), then you can apply an inference rule locally (i. e. , don't have to go checking the entire KB) © 2002 -5 Franz J. Kurfess Logic and Reasoning 36
Inference Methods 1 u deduction u sound conclusions must follow from their premises; prototype of logical reasoning u induction unsound u inference from specific cases (examples) to the general u abduction u reasoning from a true conclusion to premises that may have caused the conclusion u resolution u u sound find two clauses with complementary literals, and combine them u generate u unsound and test unsound a tentative solution is generated and tested for validity often used for efficiency (trial and error) © 2002 -5 Franz J. Kurfess Logic and Reasoning 37
Inference Methods 2 u default u reasoning general or common knowledge is assumed in the absence of specific knowledge u analogy u unsound a conclusion is drawn based on similarities to another situation u heuristics u unsound rules of thumb based on experience u intuition u unsound typically human reasoning method u nonmonotonic u reasoning unsound new evidence may invalidate previous knowledge u autoepistemic u unsound reasoning about your own knowledge © 2002 -5 Franz J. Kurfess Logic and Reasoning 38
Predicate Logic u new concepts (in addition to propositional logic) u complex v objects terms u relations predicates v quantifiers v u syntax u semantics u inference rules u usage © 2002 -5 Franz J. Kurfess Logic and Reasoning 39
Objects u distinguishable u people, cars, computers, programs, . . . u frequently u colors, things in the real world includes concepts stories, light, money, love, . . . u properties u describe v specific aspects of objects green, round, heavy, visible, u can be used to distinguish between objects © 2002 -5 Franz J. Kurfess Logic and Reasoning 40
Relations u establish connections between objects u relations can be defined by the designer or user u neighbor, u functions successor, next to, taller than, younger than, … are a special type of relation u non-ambiguous: © 2002 -5 Franz J. Kurfess only one output for a given input Logic and Reasoning 41
Syntax u also based on sentences, but more complex u sentences u constant u stand symbols: A, B, C, Franz, Square 1, 3, … for unique objects ( in a specific context) u predicate symbols: Adjacent-To, Younger-Than, . . . u describes u function u the can contain terms, which represent objects relations between objects symbols: Father-Of, Square-Position, … given object is related to exactly one other object © 2002 -5 Franz J. Kurfess Logic and Reasoning 42
Semantics u provided by interpretations for the basic constructs u u constants u u the interpretation identifies the object in the real world predicate symbols u usually suggested by meaningful names the interpretation specifies the particular relation in a model may be explicitly defined through the set of tuples of objects that satisfy the relation function symbols u u identifies the object referred to by a tuple of objects may be defined implicitly through other functions, or explicitly through tables © 2002 -5 Franz J. Kurfess Logic and Reasoning 43
BNF Grammar Predicate Logic Sentence Atomic. Sentence Term Connective Quantifier Constant Variable Predicate Function | Sentence Connective Sentence | Quantifier Variable, . . . Sentence | (Sentence) Predicate(Term, …) | Term = Term Function(Term, …) | Constant | Variable | | | | A, B, C, X 1 , X 2, Jim, Jack a, b, c, x 1 , x 2, counter, position Adjacent-To, Younger-Than, Father-Of, Square-Position, Sqrt, Cosine ambiguities are resolved through precedence or parentheses © 2002 -5 Franz J. Kurfess Logic and Reasoning 44
Terms u logical expressions that specify objects u constants and variables are terms u more complex terms are constructed from function symbols and simpler terms, enclosed in parentheses u basically a complicated name of an object u semantics is constructed from the basic components, and the definition of the functions involved u either through explicit descriptions (e. g. table), or via other functions © 2002 -5 Franz J. Kurfess Logic and Reasoning 45
Unification u an operation that tries to find consistent variable bindings (substitutions) for two terms ua substitution is the simultaneous replacement of variable instances by terms, providing a “binding” for the variable u without unification, the matching between rules would be restricted to constants u often used together with the resolution inference rule u unification itself is a very powerful and possibly complex operation v in many practical implementations, restrictions are imposed v e. g. substitutions may occur only in one direction (“matching”) © 2002 -5 Franz J. Kurfess Logic and Reasoning 46
Atomic Sentences u state facts about objects and their relations u specified through predicates and terms u the predicate identifies the relation, the terms identify the objects that have the relation u an atomic sentence is true if the relation between the objects holds u this can be verified by looking it up in the set of tuples that define the relation © 2002 -5 Franz J. Kurfess Logic and Reasoning 47
Complex Sentences u logical connectives can be used to build more complex sentences u semantics is specified as in propositional logic © 2002 -5 Franz J. Kurfess Logic and Reasoning 48
Quantifiers u can be used to express properties of collections of objects u eliminates u predicate the need to explicitly enumerate all objects logic uses two quantifiers quantifier u existential quantifier u universal © 2002 -5 Franz J. Kurfess Logic and Reasoning 49
Universal Quantification u u states that a predicate P is holds for all objects x in the universe under discourse x P(x) the sentence is true if and only if all the individual sentences where the variable x is replaced by the individual objects it can stand for are true © 2002 -5 Franz J. Kurfess Logic and Reasoning 50
Existential Quantification u states that a predicate P holds for some objects in the universe x P(x) u the sentence is true if and only if there is at least one true individual sentence where the variable x is replaced by the individual objects it can stand for © 2002 -5 Franz J. Kurfess Logic and Reasoning 51
Horn clauses or sentences u class of sentences for which a polynomial-time inference procedure exists u P 1 P 2 . . . Pn => Q where Pi and Q are non-negated atomic sentences u not every knowledge base can be written as a collection of Horn sentences u Horn clauses are essentially rules of the form u If P 1 P 2 . . . Pn then Q © 2002 -5 Franz J. Kurfess Logic and Reasoning 52
Reasoning in Knowledge-Based Systems u shallow and deep reasoning u forward and backward chaining u alternative inference methods u metaknowledge © 2002 -5 Franz J. Kurfess Logic and Reasoning 53
Shallow and Deep Reasoning u shallow u u also called experiential reasoning aims at describing aspects of the world heuristically short inference chains possibly complex rules u deep u u reasoning also called causal reasoning aims at building a model of the world that behaves like the “real thing” long inference chains often simple rules that describe cause and effect relationships © 2002 -5 Franz J. Kurfess Logic and Reasoning 54
Examples Shallow and Deep Reasoning u shallow reasoning IF a car has a good battery good spark plugs gas good tires THEN the car can move u deep reasoning IF the battery is good THEN there is electricity IF there is electricity AND spark plugs THEN the spark plugs will fire good IF the spark plugs fire AND there is gas THEN the engine will run IF the engine runs AND there are good tires THEN the car can move © 2002 -5 Franz J. Kurfess Logic and Reasoning 55
Forward Chaining u given a set of basic facts, we try to derive a conclusion from these facts u example: What can we conjecture about Clyde? IF elephant(x) THEN mammal(x) IF mammal(x) THEN animal(x) elephant (Clyde) modus ponens: IF p THEN q p q © 2002 -5 Franz J. Kurfess unification: find compatible values for variables Logic and Reasoning 56
Forward Chaining Example IF elephant(x) THEN mammal(x) unification: IF mammal(x) THEN animal(x) find compatible values for variables elephant(Clyde) modus ponens: IF p THEN q p q IF elephant( x ) THEN mammal( x ) elephant (Clyde) © 2002 -5 Franz J. Kurfess Logic and Reasoning 57
Forward Chaining Example IF elephant(x) THEN mammal(x) unification: IF mammal(x) THEN animal(x) find compatible values for variables elephant(Clyde) modus ponens: IF p THEN q p q IF elephant(Clyde) THEN mammal(Clyde) elephant (Clyde) © 2002 -5 Franz J. Kurfess Logic and Reasoning 58
Forward Chaining Example IF elephant(x) THEN mammal(x) unification: IF mammal(x) THEN animal(x) find compatible values for variables elephant(Clyde) modus ponens: IF p THEN q p q IF mammal( x ) THEN animal( x ) IF elephant(Clyde) THEN mammal(Clyde) elephant (Clyde) © 2002 -5 Franz J. Kurfess Logic and Reasoning 59
Forward Chaining Example IF elephant(x) THEN mammal(x) unification: IF mammal(x) THEN animal(x) find compatible values for variables elephant(Clyde) modus ponens: IF p THEN q p q IF mammal(Clyde) THEN animal(Clyde) IF elephant(Clyde) THEN mammal(Clyde) elephant (Clyde) © 2002 -5 Franz J. Kurfess Logic and Reasoning 60
Forward Chaining Example IF elephant(x) THEN mammal(x) unification: IF mammal(x) THEN animal(x) find compatible values for variables elephant(Clyde) modus ponens: IF p THEN q p animal( x ) q IF mammal(Clyde) THEN animal(Clyde) IF elephant(Clyde) THEN mammal(Clyde) elephant (Clyde) © 2002 -5 Franz J. Kurfess Logic and Reasoning 61
Forward Chaining Example IF elephant(x) THEN mammal(x) unification: IF mammal(x) THEN animal(x) find compatible values for variables elephant(Clyde) modus ponens: IF p THEN q p animal(Clyde) q IF mammal(Clyde) THEN animal(Clyde) IF elephant(Clyde) THEN mammal(Clyde) elephant (Clyde) © 2002 -5 Franz J. Kurfess Logic and Reasoning 62
Backward Chaining u try to find supportive evidence (i. e. facts) for a hypothesis u example: Is there evidence that Clyde is an animal? IF elephant(x) THEN mammal(x) IF mammal(x) THEN animal(x) elephant (Clyde) modus ponens: IF p THEN q p q © 2002 -5 Franz J. Kurfess unification: find compatible values for variables Logic and Reasoning 63
Backward Chaining Example IF elephant(x) THEN mammal(x) unification: IF mammal(x) THEN animal(x) find compatible values for variables elephant(Clyde) modus ponens: IF p THEN q p q animal(Clyde) ? IF mammal( x ) THEN animal( x ) © 2002 -5 Franz J. Kurfess Logic and Reasoning 64
Backward Chaining Example IF elephant(x) THEN mammal(x) unification: IF mammal(x) THEN animal(x) find compatible values for variables elephant(Clyde) modus ponens: IF p THEN q p q animal(Clyde) ? IF mammal(Clyde) THEN animal(Clyde) © 2002 -5 Franz J. Kurfess Logic and Reasoning 65
Backward Chaining Example IF elephant(x) THEN mammal(x) unification: IF mammal(x) THEN animal(x) find compatible values for variables elephant(Clyde) modus ponens: IF p THEN q p animal(Clyde) q ? IF mammal(Clyde) THEN animal(Clyde) ? IF elephant( x ) THEN mammal( x ) © 2002 -5 Franz J. Kurfess Logic and Reasoning 66
Backward Chaining Example IF elephant(x) THEN mammal(x) unification: IF mammal(x) THEN animal(x) find compatible values for variables elephant(Clyde) modus ponens: IF p THEN q p animal(Clyde) q ? IF mammal(Clyde) THEN animal(Clyde) ? IF elephant(Clyde) THEN mammal(Clyde) © 2002 -5 Franz J. Kurfess Logic and Reasoning 67
Backward Chaining Example IF elephant(x) THEN mammal(x) unification: IF mammal(x) THEN animal(x) find compatible values for variables elephant(Clyde) modus ponens: IF p THEN q p animal(Clyde) q ? IF mammal(Clyde) THEN animal(Clyde) ? IF elephant(Clyde) THEN mammal(Clyde) elephant ( x ) © 2002 -5 Franz J. Kurfess ? Logic and Reasoning 68
Backward Chaining Example IF elephant(x) THEN mammal(x) unification: IF mammal(x) THEN animal(x) find compatible values for variables elephant(Clyde) modus ponens: IF p THEN q p animal(Clyde) q IF mammal(Clyde) THEN animal(Clyde) IF elephant(Clyde) THEN mammal(Clyde) elephant (Clyde) © 2002 -5 Franz J. Kurfess Logic and Reasoning 69
Forward vs. Backward Chaining Forward Chaining Backward Chaining planning, control diagnosis data-driven goal-driven (hypothesis) bottom-up reasoning top-down reasoning find possible conclusions supported by given facts find facts that support a given hypothesis similar to breadth-first search similar to depth-first search antecedents (LHS) control evaluation © 2002 -5 Franz J. Kurfess consequents (RHS) control evaluation Logic and Reasoning 70
Alternative Inference Methods u theorem proving u emphasis on mathematical proofs, not so much on performance and ease of use u probabilistic u integrates u fuzzy reasoning probabilities into the reasoning process reasoning u enables the use of ill-defined predicates © 2002 -5 Franz J. Kurfess Logic and Reasoning 71
Metaknowledge u deals with “knowledge about knowledge” u e. g. reasoning about properties of knowledge representation schemes, or inference mechanisms u usually relies on higher order logic in (first order) predicate logic, quantifiers are applied to variables v second-order predicate logic allows the use of quantifiers for function and predicate symbols v v equality is an important second order axiom » two objects are equal if all their properties (predicates) are equal v may result in substantial performance problems © 2002 -5 Franz J. Kurfess Logic and Reasoning 72
Post-Test © 2002 -5 Franz J. Kurfess Logic and Reasoning 73
Important Concepts and Terms u u u u u and operator atomic sentence backward chaining existential quantifier expert system shell forward chaining higher order logic Horn clause inference mechanism If-Then rules implication knowledge base knowledge-based system knowledge representation matching meta-knowledge © 2002 -5 Franz J. Kurfess u u u u u not operator or operator predicate logic propositional logic production rules quantifier reasoning rule satisfiability semantics sentence symbol syntax term validity unification universal quantifier Logic and Reasoning 75
Summary Reasoning u reasoning relies on the ability to generate new knowledge from existing knowledge u implemented through inference rules v related terms: inference procedure, inference mechanism, inference engine u computer-based reasoning relies on syntactic symbol manipulation (derivation) u u inference rules prescribe which combination of sentences can be used to generate new sentences ideally, the outcome should be consistent with the meaning of the respective sentences (“sound” inference rules) u logic provides the formal foundations for many knowledge representation schemes u rules are frequently used in expert systems © 2002 -5 Franz J. Kurfess Logic and Reasoning 76
© 2002 -5 Franz J. Kurfess Logic and Reasoning 77
- Slides: 73