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