propositional logic
play

Propositional Logic CS 486/686 Sept 23, 2008 University of - PowerPoint PPT Presentation

Propositional Logic CS 486/686 Sept 23, 2008 University of Waterloo 1 CS486/686 Lecture Slides (c) 2008 P. Poupart Outline Knowledge base Propositional logic Syntax and semantics Inference Backtracking (DPLL)


  1. Propositional Logic CS 486/686 Sept 23, 2008 University of Waterloo 1 CS486/686 Lecture Slides (c) 2008 P. Poupart

  2. Outline • Knowledge base • Propositional logic – Syntax and semantics • Inference – Backtracking (DPLL) – Resolution – Local search (GSAT, WALKSAT) 2 CS486/686 Lecture Slides (c) 2008 P. Poupart

  3. Introduction • Many tasks can be formalized as search problems • How to design search algorithms that are general, yet efficient? • Generality: problem independent algorithm • Efficiency: exploit domain knowledge – Heuristic function – Constraints • Is there a good language for this? 3 CS486/686 Lecture Slides (c) 2008 P. Poupart

  4. Logic • General language – Can encode any kind of deterministic and discrete knowledge – Well defined syntax and semantics – Knowledge base: store domain knowledge • General algorithms – Search by inference – Can infirm or confirm conclusions 4 CS486/686 Lecture Slides (c) 2008 P. Poupart

  5. Declarative Approach • Do not program the solution • Just describe the problem • Knowledge base – Set of logic sentences • Goal: – Logical formula to be confirmed/infirmed • Solution – Inference algorithm 5 CS486/686 Lecture Slides (c) 2008 P. Poupart

  6. Syntax of a very simple logic • Sentence � AtomicSentence | ComplexSentence • AtomicSentence � True | False | Symbol • Symbol � P | Q | R | … • ComplexSentence � ¬ Sentence | (Sentence ∧ Sentence ) | (Sentence ∨ Sentence) | (Sentence ⇒ Sentence ) | (Sentence ⇔ Sentence) Symbols are binary variables 6 CS486/686 Lecture Slides (c) 2008 P. Poupart

  7. Logical connector semantics P Q ¬ P P ∧ Q P ∨ Q P ⇒ Q P ⇔ Q false false true false false true true false true true false true true false true false false false true false false true true false true true true true 7 CS486/686 Lecture Slides (c) 2008 P. Poupart

  8. Recall the Street Puzzle 2 1 3 4 5 N i = {English, Spaniard, Japanese, Italian, Norwegian} C i = {Red, Green, White, Yellow, Blue} D i = {Tea, Coffee, Milk, Fruit-juice, Water} J i = {Painter, Sculptor, Diplomat, Violinist, Doctor} A i = {Dog, Snails, Fox, Horse, Zebra} The Englishman lives in the Red house Who owns the Zebra? Who owns the Zebra? The Spaniard has a Dog Who drinks Water? Who drinks Water? The Japanese is a Painter The Italian drinks Tea The Norwegian lives in the first house on the left The owner of the Green house drinks Coffee The Green house is on the right of the White house The Sculptor breeds Snails The Diplomat lives in the Yellow house The owner of the middle house drinks Milk The Norwegian lives next door to the Blue house The Violinist drinks Fruit juice The Fox is in the house next to the Doctor’s 8 The Horse is next to the Diplomat’s CS486/686 Lecture Slides (c) 2008 P. Poupart

  9. Example – Street Puzzle • Symbols: V in , V ic , V id , V ij , V ia i ∈ {1,2,3,4,5} n ∈ {English, Spaniard, Japanese, Italian, Norwegian} c ∈ {Red, Green, White, Yellow, Blue} d ∈ {Tea, Coffee, Milk, Fruit-juice, Water} j ∈ {Painter, Sculptor, Diplomat, Violinist, Doctor} a ∈ {Dog, Snails, Fox, Horse, Zebra} • Example: V 2red = true: the 2 nd house is red V 2red = false: the 2 nd house is not red 9 CS486/686 Lecture Slides (c) 2008 P. Poupart

  10. Example – Street Puzzle • Constraint: the Spaniard has a dog (V 1spaniard ⇔ V 1dog ) ∧ (V 2spaniard ⇔ V 2dog ) ∧ (V 3spaniard ⇔ V 3dog ) ∧ (V 4spaniard ⇔ V 4dog ) ∧ (V 5spaniard ⇔ V 5dog ) • Constraint: the green house is on the immediate left of the red house ¬ V 1red ∧ (V 1green ⇔ V 2red ) ∧ (V 2green ⇔ V 3red ) ∧ (V 3green ⇔ V 4red ) ∧ (V 4green ⇔ V 5red ) ∧ ¬ V 5green 10 CS486/686 Lecture Slides (c) 2008 P. Poupart

  11. Example: 4-Queens problem 1 2 3 4 • Symbols: Q ij i,j ∈ {1,2,3,4} 1 • Q ij = true: queen at 2 location (i,j) • Q ij = false: no queen at 3 location (i,j) 4 11 CS486/686 Lecture Slides (c) 2008 P. Poupart

  12. Example: 4-Queens problem 1 2 3 4 • At least one queen in row 1: 1 Q 11 ∨ Q 12 ∨ Q 13 ∨ Q 14 2 • At most one queen in row 1: Q 11 ⇒ ¬ Q 12 ∧ ¬ Q 13 ∧ ¬ Q 14 3 Q 12 ⇒ ¬ Q 11 ∧ ¬ Q 13 ∧ ¬ Q 14 4 Q 13 ⇒ ¬ Q 11 ∧ ¬ Q 12 ∧ ¬ Q 14 Q 14 ⇒ ¬ Q 11 ∧ ¬ Q 12 ∧ ¬ Q 13 12 CS486/686 Lecture Slides (c) 2008 P. Poupart

  13. Knowledge Base (KB) • Knowledge base – Encode problem description and any knowledge that could help solve the problem – Database of facts and constraints – Possible language: propositional logic • Entailment – What can we derive/conclude from KB? – KB |= α : α follows from KB 13 CS486/686 Lecture Slides (c) 2008 P. Poupart

  14. Semantics • Semantics – define the “meaning” of each sentence – define the truth of each sentence with respect to each possible world • Model: – a possible world – each possible configuration of the variables • Examples: – P, Q, R: 8 models (all possible configurations of P, Q and R) – 4-queens problem: 2 16 models – Street puzzle: 2 25 models 14 CS486/686 Lecture Slides (c) 2008 P. Poupart

  15. Semantics • Entailment: KB |= α – α is true in all the models in which KB is true models models models α KB α KB α KB KB |= α KB | ≠ α KB | ≠ α 15 CS486/686 Lecture Slides (c) 2008 P. Poupart

  16. Inference • Process of verifying the truth of a formula • Simple inference algorithm: – Build a truth table that enumerates all models – Verify that formula is true in all models where KB is true 16 CS486/686 Lecture Slides (c) 2008 P. Poupart

  17. Truth table P Q R KB KB: P ⇒ Q, true true true false Q ⇒ R, true true false false ¬ Q true false true false true false false false KB |= P? no KB |= ¬ P? yes false true true false KB |= Q? no false true false false KB |= ¬ Q? yes false false true true KB |= R? no false false false true KB |= ¬ R? no 17 CS486/686 Lecture Slides (c) 2008 P. Poupart

  18. Efficiency • Building a truth table is inefficient: exponential in the number of variables • Alternative: backtracking search – Rewrite “KB |= α ?” as KB’ = (KB and ¬α ) – Show that KB’ is not satisfiable (e.g., there doesn’t exist any model for which KB is true, but α is false) 18 CS486/686 Lecture Slides (c) 2008 P. Poupart

  19. Convenience • KB may contain any formula that follows the syntax of our simple logic. – Inconvenient: too many possible formula – Can we simplify syntax? • Conjunctive normal form (CNF) – Only use ∧ , ∨ , ¬ – Conjunction of clauses, where each clause is a disjunction of (possibly negated) literals – Example: (V1 ∨ V2 ∨ V3) ∧ ( ¬ V1 ∨ V2) ∧ ( ¬ V3 ∨ V2) 19 CS486/686 Lecture Slides (c) 2008 P. Poupart

  20. Logical equivalence • How do we transform a KB in CNF? • Logical equivalence rules – ¬ ( ¬ A) ≡ A – (A ⇒ B) ≡ ¬ A ∨ B – (A ⇔ B) ≡ (A ⇒ B) ∧ (B ⇒ A) – ¬ (A ∨ B) ≡ ( ¬ A ∧ ¬ B) – ¬ (A ∧ B) ≡ ( ¬ A ∨ ¬ B) – (A ∨ (B ∧ C)) ≡ ((A ∨ B) ∧ (A ∨ C)) • Can every KB be transformed in CNF in polynomial time and space? – No: last rule may yield exponentially many clauses 20 CS486/686 Lecture Slides (c) 2008 P. Poupart

  21. Inference Properties • Soundness: an inference algorithm that derives only entailed sentence is sound • Completeness: an inference algorithm is complete if it can derive any sentence that is entailed • Time and space complexity • Backtracking search and truth table building are sound and complete 21 CS486/686 Lecture Slides (c) 2008 P. Poupart

  22. Resolution • Idea: generate new sentences by implications – Unit resolution: A ∧ (A ⇒ B) |= B – General resolution: (A ⇒ B) ∧ (B ⇒ C) |= (A ⇒ C) • How do we do this with KB in CNF? – Unit resolution: A ∧ ( ¬ A ∨ B) |= B – General resolution: ( ¬ A ∨ B) ∧ ( ¬ B ∨ C) |= ( ¬ A ∨ C) 22 CS486/686 Lecture Slides (c) 2008 P. Poupart

  23. Resolution • Algorithm: apply resolution to every possible pair of clauses until – Empty clause is generated: false KB – No more clauses can be generated: all generated clauses are entailed • Complete? Yes • Sound? Yes 23 CS486/686 Lecture Slides (c) 2008 P. Poupart

  24. Local Search • Idea: start with a variable configuration and flip the truth values of some variables until a satisfiable assignment is found • Examples: – GSAT: greedy SAT – WALKSAT: randomized version of GSAT 24 CS486/686 Lecture Slides (c) 2008 P. Poupart

  25. GSAT • Goal: maximize number of satisfied clauses • Algorithm: – Start with a variable configuration – Repeat until configuration satisfies KB • Flip truth assignment of variable that yields that highest number of satisfied clauses • Space: O(N) where N = # of variables • Complete? No, can get stuck in local optima 25 CS486/686 Lecture Slides (c) 2008 P. Poupart

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend