Propositional Logic Reading: Chapter 7.1, 7.3 7.5 [ased on slides from Jerry Zhu, Louis Oliphant and ndrew Moore] Logic If the rules of the world are presented formally, then a decision maker can use logical reasoning to make rational decisions Several types of logic: ( logic Propositional Logic (oolean ( calculus First-Order Logic (aka first-order predicate Non-Monotonic Logic Markov Logic logic includes: syntax: what is a correctly-formed sentence? semantics: what is the meaning of a sentence? Inference procedure (reasoning, entailment): what sentence logically follows given knowledge? slide 1 slide 3 Propositional Logic symbol in PL is a symbolic variable whose value must be either True or False, and which stands for a natural language statement that could be either or = Smith has chest pain = Smith is depressed C = It is raining Propositional Logic Syntax Sentence tomicsentence ComplexSentence tomicsentence True False Symbol Symbol P Q R... ComplexSentence Sentence ( Sentence ( Sentence ( Sentence ( Sentence ( Sentence ( Sentence ( Sentence ( Sentence NF (ackus-naur Form) grammar in propositional logic P ((True R) Q)) S) well formed ( wff or sentence ) ) S) not well formed slide 4 slide 5
Propositional Logic Syntax () control the order of operations Means True P ((True R) Q)) ( S Propositional Logic Syntax Precedence (from highest to lowest): If the order is clear, you can leave off parentheses Means Not Means Or -- disjunction Means nd -- conjunction if-then Means implication P True R Q S ok S not ok Propositional symbols must be specified Means iff -- biconditional slide 6 slide 7 Semantics n interpretation is a complete True / False assignment to all propositional symbols Example symbols: P means It is hot, Q means It is humid, R means It is raining There are 8 interpretations (TTT,..., ( FFF The semantics (meaning) of a sentence is the set of interpretations in which the sentence evaluates to True Example: the semantics of the sentence is the set of 6 interpretations: P=True, Q=True, R=True or False P=True, Q=False, R=True or False P=False, Q=True, R=True or False model of a set of sentences is an interpretation in which all the sentences are Evaluating a Sentence under an Interpretation Calculated using the definitions of all the connectives, recursively Pay attention to 5 is even implies 6 is odd is True! If P is False, regardless of Q, P Q is True No causality needed: 5 is odd implies the Sun is a star is True slide 8 slide 9
Understanding This is an operator. lthough we call it implies or implication, do not try to understand its semantic form from the name. We could have called it foo instead and still defined its semantics the same way. means is sufficient but not necessary to make Example: Let be has a cold and be drink water can be interpreted as should drink water when has a cold. However, you can drink water even when you do not have a cold. Thus is still when is not. Example R Q slide 10 slide 11 Example R Q Example (P R Q) P R Q P Q R ~P Q^R ~PvQ^R ~PvQ^R->Q 0 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 0 1 0 1 1 0 1 1 1 1 1 1 1 0 0 0 0 0 1 1 0 1 0 0 0 1 1 1 0 0 0 0 1 1 1 1 0 1 1 1 Satisfiable: a sentence that is under some interpretations NP-complete Deciding satisfiability of a sentence is slide 12 slide 13
Example (P R Q) P R Q Example () P Q P Q R ~Q R^~Q P^R^~Q P^R P^R->Q final 0 0 0 1 0 0 0 1 0 0 0 1 1 1 0 0 1 0 0 1 0 0 0 0 0 1 0 0 1 1 0 0 0 0 1 0 1 0 0 1 0 0 0 1 0 1 0 1 1 1 1 1 0 0 1 1 0 0 0 0 0 1 0 1 1 1 0 0 0 1 1 0 Unsatisfiable: a sentence that is under all interpretations lso called inconsistent or a contradiction slide 14 slide 15 Example () P Q P Q R ~Q P->Q P^~Q (P->Q)vP^~Q 0 0 0 1 1 0 1 0 0 1 1 1 0 1 0 1 0 0 1 0 1 0 1 1 0 1 0 1 1 0 0 1 0 1 1 1 0 1 1 0 1 1 1 1 0 0 1 0 1 1 1 1 0 1 0 1 Valid: a sentence that is under all interpretations lso called a tautology slide 16 Knowledge ase (K) knowledge base, K, is a set of sentences. Example K: TomGivingLecture (TodayIsTuesday ( TodayIsThursday TomGivingLecture It is equivalent to a single long sentence: the conjunction of all sentences ( TomGivingLecture (TodayIsTuesday TodayIsThursday) ) TomGivingLecture model of a K is an interpretation in which all sentences in K are slide 17
Entailment Entailment is the relation of a sentence logically following from other sentences (e.g., K) = = if and only if, in every interpretation in which is, is also ; whenever is, so is ; all models of and also models of Deduction theorem: = if and only if is ( valid (always Proof by contradiction (refutation, reductio ad absurdum): = if and only if is unsatisfiable There are 2 n interpretations to check, if K has n symbols Entailment Entailment is the relation of a sentence logically following from other sentences (e.g., the K) = = if and only if, in every interpretation in which is, is also ll interpretations is is slide 18 slide 19 Deductive Inference Let s say you write an algorithm which, according to you, proves whether a sentence is entailed by The thing your algorithm does is called deductive inference We don t trust your inference algorithm (yet), so we write things your algorithm finds as - It reads is derived from by your algorithm What properties should your algorithm have? Soundness: the inference algorithm only derives entailed sentences. That is, if - then = Completeness: all entailment can be inferred. That is, if = then - Soundness and Completeness Soundness says that any wff that follows deductively from a set of axioms, K, is valid (i.e., in all models) Completeness says that all valid sentences (i.e., in all models of K), can be proved from K and hence are theorems slide 20 slide 21
Method 1: Inference by Enumeration Inference by Enumeration lso called Model Checking or Truth Table Enumeration LET: K = C, C α = QUERY: K α? LET: K = C, C α = QUERY: K α? 22 C NOTE: The computer doesn't know the meaning of the proposition symbols So, all logically distinct cases must be checked to prove that a sentence can be derived from K slide 22 23 C C C K Rows where all of sentences in K are are the models of K slide 23 Inference by Enumeration Inference by Enumeration 24 LET: K = C, C α = QUERY: K α? YES! C C C K K α α is entailed by K if all models of K are models of α, i.e., all rows where K is, α is also In other words: K α is valid slide 24 Using inference by enumeration to build a complete truth table in order to determine if a sentence is entailed by K is a complete inference algorithm for Propositional Logic ut very slow: takes exponential time slide 25
Method 2: Natural Deduction using Sound Inference Rules Logical Equivalences Goal: Define a more efficient algorithm than enumeration that uses a set of inference rules to incrementally deduce new sentences that are given the initial set of sentences in K plus uses all logical equivalences slide 26 You can use these equivalences to derive or modify sentences slide 27 Sound Inference Rules ( affirms Modus Ponens (Latin: mode that nd-elimination P Q P P Q Note: Prove that an inference rule is sound by using a truth table P (P Q) Q (P (P Q)) Q T T T T T T T T F T F F F T F T F T F T T F F F T F F slide T 28 slide 29 29 Some Sound Inference Rules Implication-Elimination, IE (Modus Ponens, MP) nd-elimination, E nd-introduction, I Or-Introduction, OI Double-Negation Elimination, DNE α β, α β α 1 α 2 α n α i α 1, α 2,, α n α 1 α 2 α n α i α 1 α 2 α n α α
Inference Rules Question Each inference rule formalizes the idea that infers ( - ) in terms of logically follows ( = ) Doesn t say anything about deducibility just says for each interpretation that makes, that interpretation also makes What s the difference between (logical equivalence) = (entailment) - (derived from) slide 30 slide 31 Natural Deduction = Constructing a Proof Proof is a sequence of inference steps that leads from (i.e., K) to This is a search problem! K: 1. () R 2. (S T) Q 3. S 4. T 5. P : R Proof by Natural Deduction 1. S Premise (in K) 2. T Premise 3. S T Conjunction(1, 2) (nd-introduction) 4. (S T) Q Premise 5. Q Modus Ponens(3, 4) 6. P Premise 7. Conjunction(5, 6) 8. () R Premise 9. R Modus Ponens(7, 8) Last line is query sentence slide 32 slide 33
Monotonicity Property Note that natural deduction relies on the monotonicity property of Propositional Logic: Deriving a new sentence and adding it to K does NOT affect what can be entailed from the original K Hence we can incrementally add new sentences that are derived in any order Once something is proved, it will remain Method 3: Resolution Your algorithm can use all the logical equivalences, Modus Ponens, nd-elimination to derive new sentences Resolution rule: a single inference rule Sound: only derives entailed sentences Complete: can derive any entailed sentence Resolution is only refutation complete: if K =, then K - False. ut the sentences need to be preprocessed into a special form ut all sentences can be converted into this form slide 34 slide 37 Resolution Take any two clauses where one contains some symbol, and the other contains its complement ( negative ) R Q S T Merge (resolve) them, throw away the symbol and its complement P R S T If two clauses resolve and there s no symbol left, you have derived the empty clause (False), so K = If no new clauses can be added, K does not entail Resolution Rule of Inference Show K = by proving that K is unsatsifiable, i.e., deducing False from K Resolution Rule of Inference Examples, α β, β γ α γ C D, E F C D E F called unitresolution slide 38 slide 39
Resolution Refutation lgorithm 1. dd negation of query to K 2. Pick 2 sentences that haven t been used before and can be used with the Resolution Rule of inference 3. If none, halt and answer that the query is NOT entailed by K 4. Compute resolvent and add it to K 5. If False in K Then halt and answer that the query IS entailed by K Else Goto 2 slide 40 ( CNF ) Conjunctive Normal Form ( C) ( ) C Replace all using iff/biconditional elimination ( ) ( ) Replace all using implication elimination Move all negations inward using double-negation elimination ( ) - de Morgan's rule ( ) ( ) pply distributivity of over ( ) ( ) ( ) + 1 more slide 41 Convert Sentence into CNF ( C) starting sentence ( ( C)) (( C) ) iff/biconditional elimination C) ( ( C) ) implication elimination C) (( C) ) move negations inward Resolution Steps Given K and (query) dd to K, and convert all sentences to CNF Show this leads to False (aka empty clause ). Proof contradiction by Example K: ( C ( Example query: C) ( ) C ) distribute over calleda clause slide 42 slide 43
Resolution Preprocessing Resolution Example dd to K, and convert to CNF: a1: C a2: a3: C b: c: a1: C a2: a3: C b: c: Want to reach goal: False (empty clause) slide 44 slide 45 Resolution Example Example a1: C a2: a3: C b: c: Given: P R Q R Step 1: resolve a2, c: Prove: R Step 2: resolve above and b: empty slide 46 slide 47
Given: () Q (P P) R (R S) (S Q) Example Given: P P Example Prove: R Prove: R slide 48 slide 49 Efficiency of the Resolution lgorithm Run time can be exponential in the worst case Often much faster Factoring: if a new clause contains duplicates of the same symbol, delete the duplicates P R P T P R T If a clause contains a symbol and its complement, the clause is a tautology and is useless; it can be thrown away ( C a1: ( a2: ( Resolvent of a1 and a2 is: C Which is valid, so throw it away Method 4: Chaining with Horn Clauses Resolution is more powerful than we need for many practical situations weaker form: Horn clauses Disjunction of literals with at most one positive R no R yes K = conjunction of Horn clauses What s the big deal? R R P) Q? slide 50 slide 51
R R P) Q (R P) Q P R P Horn Clauses Every rule in K is in this form (special case, no negative literals): fact (special case, no positive literal): goal clause The big deal: K easy for humans to read Natural forward chaining and backward chaining algorithms; proof easy for humans to read Can decide entailment with Horn clauses in time linear with K size ut Can only ask atomic queries Horn Clauses Only 1 rule of inference needed Generalized Modus Ponens: P, Q, () R R slide 52 slide 53 Forward Chaining pply any rule whose premises are satisfied in the K dd its conclusion to the K until query is derived K: query: Q Forward Chaining 1. 2. 3. 4. P L 5. L 6. 7. 8. L GMP(5,6,7) 9. M GMP(3,7,8) 10. P GMP(2,8,9) 11. Q GMP(1,10) Forward chaining with Horn clause K is complete slide 54 slide 55
ackward Chaining Forward chaining problem: can generate a lot of irrelevant conclusions Search forward, start state = K, goal test = state contains query ackward chaining Work backwards from goal to premises Find all implications of the form ( ) query Prove all the premises of one of these implications void loops: check if new subgoal is already on the goal stack void repeated work: check if new subgoal 1. Has already been proved, or 2. Has already failed slide 65 ackward Chaining 1. 2. 3. 4. P L 5. L 6. 7. 8. Q Goal 9. P Subgoal(1,8) 10. L M Subgoal(2,9) 11. L Subgoal(10) 12. Subgoal(5,11) 13. True(6) 14. True(7) 15. L True(5,13,14) 16. M True(14,15) 17. P True(15,16) 18. Q True(1,17) slide 66 ackward Chaining ackward Chaining P L L P L L slide 67 slide 68
ackward Chaining ackward Chaining P L L P L L slide 69 slide 70 ackward Chaining ackward Chaining P L L P L L slide 71 slide 72
ackward Chaining ackward Chaining P L L P L L slide 73 slide 74 ackward Chaining ackward Chaining P L L P L L slide 75 slide 76
Forward vs. ackward Chaining Forward chaining is data-driven May perform lots of work irrelevant to the goal ackward chaining is goal-driven ppropriate for problem solving Time complexity can be much less than linear in size of K Some form of bi-directional search may be even better Problems with Propositional Logic Consider the game minesweeper on a 10x10 field with only one land mine How do you express the knowledge, with Propositional Logic, that the squares adjacent to the land mine will display the number 1? slide 77 slide 78 Problems with Propositional Logic Consider the game minesweeper on a 10x10 field with only one land mine How do you express the knowledge, with Propositional Logic, that the squares adjacent to the land mine will display the number 1? Intuitively with a rule like (( Number1(Neighbors(x,y Landmine(x,y) but Propositional Logic cannot do this slide 79 Problems with Propositional Logic Propositional Logic has to say, e.g. for cell (3,4): Landmine_3_4 Number1_2_3 Landmine_3_4 Number1_2_4 Landmine_3_4 Number1_2_5 Landmine_3_4 Number1_3_3 Landmine_3_4 Number1_3_5 Landmine_3_4 Number1_4_3 Landmine_3_4 Number1_4_4 Landmine_3_4 Number1_4_5 nd similarly for each of Landmine_1_1, Landmine_1_2, Landmine_1_3,, Landmine_10_10 Difficult to express large domains concisely Don t have objects and relations First-Order Logic is a powerful upgrade slide 80
What You Should Know lot of terms Use truth tables (inference by enumeration) Natural deduction proofs Conjuctive Normal Form (CNF) Resolution Refutation algorithm and proofs Horn clauses Forward chaining algorithm ackward chaining algorithm slide 82