Logical Agents Chapter 7. 248 B1,1 B2,1 P1,1 P1,2 P2,1 P2,2 P3,1 R1 R2 R3 R4 R5 KB false false .. false false false false false false false false false false false true . . true true .. true true • . true false .. tree tree • . false false .. false false •. . false true false false false false false true true false true true false false false false false false true true false true false eee false false false false false true true true false -. . true true .. . true false -. . true false true -. . false .. false •. . true •. . false -. . false •. . true -. . true •. . false -. . true true false true true false true false true true true true `ei false false .. true true Figure 7.9 A truth table constructed for the knowledge base given in the text KB is true if RI through R5 are true, which occurs in just 3 of the 128 rows the ones underlined in the right-hand column). In all 3 rows, P1,2 is false, so there is no pit in [1,21. On the other hand, there might (or might not) be a pit in [2,21. function TT-ENTAlLS?(KB, a) returns true or false inputs: KB, the knowledge base, a sentence in propositional logic a, the query, a sentence in propositional logic symbols a list of the proposition symbols in KB and a return TT-CHECK-ALL( KB , a, symbols, {}) function TT-CHECK-ALL(KB, a, symbols, model) returns true or false if EMPTY?(symbols) then if PL - TRUE?(KB, model) then return PL - TRUE?(ct, model) else return true // when KB is false, always return true else do P Fats -r(symbols) rest 4— REST(symbols) return (TT-CHECK-ALL(KB, 0, rest, model U {P = true}) and TT-CHECK-M..(KB, , rest, model U {P = false })) Figure 7.10 A truth-table enumeration algorithm for deciding propositional entailment. (TT stands for truth table.) PL-TRUE? returns true if a sentence holds within a model. The variable model represents a partial model—an assignment to some of the symbols. The keyword "and" is used here as a logical operation on its two arguments, returning true or false. Section 7.5. Propositional Theorem Proving (a A /3) (a V /3) ((a A ,(3) A 7) ((a V 0) V 7) (a 4 /3) (a /3) <=>. –.(a A 0) – (a A (a V Figure 7.11 .( aV 249 commutativity of A (0 V a) commutativity of V (,0 A a) (a A (B A 7)) associativity of A (a V (0 V 7)) associativity of V a double-negation elimination (–/3 4 –, a) contraposition (–a V 0) implication elimination ((a = 0) A (/3 a)) hiconditional elimination (–a V –,,(3) De Morgan a ll –,f3) De Morgan ((a A 3) V (a A 7)) distributivity of A over V ((a V 0) A (a V 7)) distributivity of V over A 13) = (– (0 V 7)) (0 A 7)) Standard logical equivalences. The symbols a, 13, and -y stand for arbitrary sentences of propositional logic. 7.5 PROPOSITIONAL THEOREM PROVING So far, THEOREM PROVING LOSECAL FC.JIVAL EMT VALIDITY TAUTOLOGY DIDLIGTIDN THEOREM we have shown how to determine entailment by model checking: enumerating models and showing that the sentence must hold in all models. In this section, we show how entailment can be done by theorem proving —applying rules of inference directly to the sentences in our knowledge base to construct a proof of the desired sentence without consulting models. If the number of models is large but the length of the proof is short, then theorem proving can be more efficient than model checking. Before we plunge into the details of theorem-proving algorithms, we will need some additional concepts related to entailment. The first concept is logical equivalence: two sentences a and 0 are logically equivalent if they are true in the same set of models. We write this as a 11. For example, we can easily show (using tnith tables) that P A and Q A P are logically equivalent; other equivalences are shown in Figure 7.11. These equivalences play much the same role in logic as arithmetic identities do in ordinary mathematics. An alternative definition of equivalence is as follows: any two sentences a and 0 are equivalent only if each of them entails the other: if and only if Et H 0 and fi if . The second concept we will need is validity. A sentence is valid if it is true in all models. For example, the sentence P V .P is valid. Valid sentences are also known as tautologies—they are necessarill , true. Because the sentence True is true in all models, every valid sentence is logically equivalent to True What good are valid sentences? From our definition of entailment, we can derive the deduction theorem, which was known to the ancient Greeks: For any sentences a and = /3 if and only if the sentence (a fi ) is valid. (Exercise 7.5 asks for a proof.) Hence, we can decide if a /3 by checking that (a 0) is true in every model—which is essentially what the inference algorithm in Figure 7.10 does-
© Copyright 2024