Propositional Logic Intro, Syntax Jim Little UBC CS 322 – CSP October 17, 2014 Textbook § 5.1- 5.1.1 – 5.2 Slide 1 Lecture Overview • Recap Planning • Logic Intro • Propositional Definite Clause Logic: Syntax Slide 2 Recap Planning • Represent possible actions with ….. STRIPS • Plan can be found by….. search • Or can be found by mapping planning problem into… CSP Slide 3 Solve planning as CSP: pseudo code solved = false for horizon h=0,1,2,… map STRIPS into a CSP csp with horizon h solve that csp if solution exists then return solution else horizon = horizon + 1 end Slide 4 Planning as CSP Slide 5 STRIPS to CSP applet Allows you: • to specify a planning problem in STRIPS • to map it into a CSP for a given horizon • the CSP translation is automatically loaded into the CSP applet where it can be solved Practice exercise using STRIPS to CSP is available on AIspace Slide 6 • • • • • • Now, do you know how to implement a planner for…. • Emergency Evacuation? Robotics? Space Exploration? Manufacturing Analysis? Games (e.g., Bridge)? Generating Natural language Product Recommendations …. North Q 9 A A J 7 K 9 6 5 5 3 West 6 Q South East 2 8 Slide 7 No , but you (will) know the key ideas ! • Ghallab, Nau, and Traverso Automated Planning: Theory and Practice • Morgan Kaufmann, May 2004 ISBN 1-55860-856-7 Web site: http://www.laas.fr/planning Slide 8 Lecture Overview • Recap Planning • Logic Intro • Propositional Definite Clause Logic: Syntax Slide 9 Lecture Overview • Recap of Lecture 6 • Planning as CSP • Logic • Intro • Propositional Definite Clause Logic (PDCL) • Logical Consequences and Proof Procedures • Bottom Up Proof Procedure Slide 10 Where Are We? Environment Stochastic Deterministic Problem Type Arc Consistency Constraint Vars + Satisfaction ConstraintsSearch Static Belief Nets Logics Query Variable Search Elimination Sequential Planning First Part of the Course STRIPS Search Slide 11 Representation Decision Nets Variable Elimination Markov Processes Value Iteration Reasoning Technique Where Are We? Environment Stochastic Deterministic Problem Type Arc Consistency Constraint Vars + Satisfaction ConstraintsSearch Static Belief Nets Logics Query Variable Search Elimination Sequential Planning Back to static problems, but with richer representation STRIPS Search Slide 12 Representation Decision Nets Variable Elimination Markov Processes Value Iteration Reasoning Technique Logics in AI: Similar slide to the one for planning Propositional Definite Clause Logics Propositional Logics Description Logics Ontologies Semantic Web Information Extraction Semantics and Proof Theory First-Order Logics Satisfiability Testing (SAT) Production Systems Cognitive Architectures Video Games Summarization Slide 13 Hardware Verification Software Verification Product Configuration Applications Tutoring Systems Logics in AI: Similar slide to the one for planning Propositional Definite Clause Logics Propositional Logics Description Logics Ontologies Semantic Web Information Extraction Semantics and Proof Theory First-Order Logics Satisfiability Testing (SAT) Production Systems Cognitive Architectures Hardware Verification Software Verification Product Configuration You will know You will know a little Video Games Summarization Slide 14 Applications Tutoring Systems What you already know about logic... • From programming: Some logical operators • If ((amount > 0) && (amount < 1000)) || !(age < 30) • ... You know what they mean in a “procedural” way Logic is the language of Mathematics. To define formal structures (e.g., sets, graphs) and to prove statements about those "(x)triangle(x) ¾¾ ®[A = B = C¬¾ ®a = b = g ] We use logic as a Representation and Reasoning System that can be used to formalize a domain and to reason about it Slide 15 Logic: a framework for representation & reasoning • When we represent a domain about which we have only partial (but certain) information, we need to represent…. • Objects, properties, sets, groups, actions, events, time, space, … • All these can be represented as • Objects • Relationships between objects • Logic is the language to express knowledge about the world this way • http://en.wikipedia.org/wiki/John_McCarthy (1927 - 2011) Logic and AI “The Advice Taker” Coined “Artificial Intelligence”. Dartmouth W’shop (1956) Slide 16 Why Logics? “Natural” to express knowledge about the world (more natural than a “flat” set of variables & constraints) e.g. “Every 101 student will pass the course” Course (c1) Name-of (c1, 101) "(z)student(z) & registered(z, c1) ¾¾ ® will _ pass(z, c1) • It is easy to incrementally add knowledge • It is easy to check and debug knowledge • Provides language for asking complex queries 17 • Well understood formalSlideproperties Logic: A general framework for reasoning General problem: Query answering • tell the computer how the world works • tell the computer some facts about the world • ask a yes/no question about whether other facts must be true Solving it with Logic 1. 2. 3. 4. 5. Begin with a task domain. Distinguish those things you want to talk about (the ontology) Choose symbols in the computer to denote elements of your ontology Tell the system knowledge about the domain Ask the system whether new statements about the domain are true or false live_w4? lit_l2? Slide 18 Example: Electrical Circuit /down / up Slide 19 /down / up Syntax: are these sentences that a reasoning procedure can process? Semantics: what do these statements say about the world I need to represent? Slide 20 To Define a Logic We Need • Syntax: specifies the symbols used, and how they can be combined to form legal sentences • Knowledge base is a set of sentences in the language • Semantics: specifies the meaning of symbols and sentences • Reasoning theory or proof procedure: a specification of how an answer can be produced. • Sound: only generates correct answers with respect to the semantics • Complete: Guaranteed to find an answer if it exists Slide 21 Propositional Definite Clauses We will start with a simple logic • Primitive elements are propositions: Boolean variables that can be {true, false} Two kinds of statements: • that a proposition is true • that a proposition is true if one or more other propositions are true Why only propositions? • We can exploit the Boolean nature for efficient reasoning • Starting point for more complex logics We need to specify: syntax, semantics, proof procedure Slide 22 Lecture Overview • Recap of Lecture 6 • Planning as CSP • Logic • Intro • Propositional Definite Clause Logic (PDCL) • Syntax and Semantics • Logical Consequences and Proof Procedures • Bottom Up Proof Procedure Slide 23 Propositional Definite Clauses: Syntax Definition (atom) An atom is a symbol starting with a lower case letter Examples: p1; live_l1 Definition (body) A body is an atom or is of the form b1 ∧ b2 where b1 and b2 are bodies. Examples: p1 ∧ p2; ok_w1 ∧ live_w0 Definition (definite clause) Examples: p1 ← p2; A definite clause is live_w0 ← live_w1 ∧ up_s2 - an atom or - a rule of the form h ← b where h is an atom (“head”) and b is a body. (Read this as “h if b”.) Definition (KB) A knowledge base (KB) is a set of Slide definite clauses 24 atoms definite clauses, KB rules Slide 25 PDCL Syntax: more examples Definition (definite clause) A definite clause is - an atom or - a rule of the form h ← b where h is an atom (‘head’) and b is a body. (Read this as ‘h if b.’) A body is an atom or is of the form b1 ∧ b2 where b1 and b2 are bodies How many of the clauses below are legal PDCL clauses? a) ai_is_fun A. 3 B. 4 C. 5 D. 6 b) ai_is_fun ∨ ai_is_boring c) ai_is_fun ← learn_useful_techniques d) ai_is_fun ← learn_useful_techniques ∧ notTooMuch_work e) ai_is_fun ← learn_useful_techniques ∧ TooMuch_work f) ai_is_fun ← f(time_spent, material_learned) g) srtsyj ← errt ∧ gffdgdgd Slide 26 E. 7 PDC Syntax: more examples Legal PDC clause Not a legal PDC clause a) ai_is_fun b) ai_is_fun ∨ ai_is_boring c) ai_is_fun ← learn_useful_techniques d) ai_is_fun ← learn_useful_techniques ∧ notTooMuch_work e) ai_is_fun ← learn_useful_techniques ∧ TooMuch_work f) ai_is_fun ← f(time_spent, material_learned) g) srtsyj ← errt ∧ gffdgdgd Do any of these statements mean anything? Syntax doesn't answer this question! Slide 27 To Define a Logic We Need • Syntax: specifies the symbols used, and how they can be combined to form legal sentences • Knowledge base is a set of sentences in the language • Semantics: specifies the meaning of symbols and sentences • Reasoning theory or proof procedure: a specification of how an answer can be produced. • Sound: only generates correct answers with respect to the semantics • Complete: Guaranteed to find an answer if it exists Slide 28 Propositional Definite Clauses: Semantics • Semantics allows you to relate the symbols in the logic to the domain you’re trying to model. Definition (interpretation) An interpretation I assigns a truth value to each atom. Slide 29 Propositional Definite Clauses: Semantics • Semantics allows you to relate the symbols in the logic to the domain you're trying to model. Definition (interpretation) An interpretation I assigns a truth value to each atom. Slide 30 Propositional Definite Clauses: Semantics Semantics allows you to relate the symbols in the logic to the domain you're trying to model. Definition (interpretation) An interpretation I assigns a truth value to each atom. We can use the interpretation to determine the truth value of clauses Definition (truth values of statements) • A body b1 ∧ b2 is true in I if and only if b1 is true in I and b2 is true in I. • A rule h ← b is false in I if and only if b is true in I and h is false in I. Slide 31 PDC Semantics: Example Truth values under different interpretations F=false, T=true a1 a2 a1 ∧ a2 I1 F F F I2 F T I3 T I4 T h b h←b I1 F F T F I2 F T F F F I3 T F T T T I4 T T T Slide 32 PDC Semantics: Example Truth values under different interpretations F=false, T=true h a1 a2 h ← a1 ∧ a2 I1 F F F I2 F F T I3 F T F I4 F T T I5 T F F I6 T F T I7 T T F I8 T T T Slide 33 PDC Semantics: Example for truth values Truth values under different interpretations F=false, T=true h a1 a2 h ← a1 ∧ a2 h b h←b I1 F F F T I1 F F T I2 F F T T I2 F T F I3 F T F T I3 T F T I4 F T T F I4 T T T I5 T F F T I6 T F T T I7 T T F T I8 T T T T h ← a1 ∧ a2 Body of the clause: a1 ∧ a2 Body is only true if both a1 and a2 are true in I Slide 34 Propositional Definite Clauses: Semantics Semantics allows you to relate the symbols in the logic to the domain you're trying to model. Definition (interpretation) An interpretation I assigns a truth value to each atom. We can use the interpretation to determine the truth value of clauses Definition (truth values of statements) • A body b1 ∧ b2 is true in I if and only if b1 is true in I and b2 is true in I. • A rule h ← b is false in I if and only if b is true in I and h is false in I. • A knowledge base KB is true in I if and only if Slide 35 in I. every clause in KB is true Propositional Definite Clauses: Semantics Definition (interpretation) An interpretation I assigns a truth value to each atom. Definition (truth values of statements) • A body b1 ∧ b2 is true in I if and only if b1 is true in I and b2 is true in I. • A rule h ← b is false in I if and only if b is true in I and h is false in I. • A knowledge base KB is true in I if and only if every clause in KB is true in I. Definition (model) A model of a knowledge base KB is an interpretation in which KB is true. Similar to CSPs: a model Slide 36of a set of clauses is an interpretation that makes all of the clauses true PDC Semantics: Knowledge Base (KB) • A knowledge base KB is true in I if and only if every clause in KB is true in I. I1 p q r s true true false false Slide 37 PDC Semantics: Knowledge Base (KB) • A knowledge base KB is true in I if and only if every clause in KB is true in I. I1 p q r s true true false false Slide 38 PDC Semantics: Example for models Definition (model) A model of a knowledge base KB is an interpretation in which every clause in KB is true. p←q KB = Which of the interpretations below are models of KB? q r ←s A. p q r s I1 T T T T I2 F F F F I3 T T F F I4 T T T F I5 F T F Slide 39 T I3 B. I 1 , I3 C. I 1, I3, I4 D. All of them PDC Semantics: Example for models Definition (model) A model of a knowledge base KB is an interpretation in which every clause in KB is true. p←q KB = Which of the interpretations below are models of KB? All interpretations where KB is true: I1, I3, and I4 q r ←s p q r s I1 T T T T I2 F F F F I3 T T F F I4 T T T F I5 F T F Slide 40 T p←q q r←s KB PDC Semantics: Example for models Definition (model) A model of a knowledge base KB is an interpretation in which every clause in KB is true. p←q KB = Which of the interpretations below are models of KB? All interpretations where KB is true: I1, I3, and I4 q r ←s p q r s p←q q r←s KB I1 T T T T T T T T I2 F F F F T F T F I3 T T F F T T T T I4 T T T F T T T T I5 F T F Slide 41 F T T F F OK but…. …. Who cares? Where are we going with this? Remember what we want to do with Logic 1) Tell the system knowledge about a task domain. • • 2) This is your KB which expresses true statements about the world Ask the system whether new statements about the domain are true or false. • We want the system responses to be – Sound: only generates correct answers with respect to the semantics – Complete: Guaranteed to find an answer if it exists Slide 42 For Instance… 1) Tell the system knowledge about a task domain. p q. KB q. r s. 2) Ask the system whether new statements about the domain are true or false p? r? s? Slide 43 Or, More Interestingly 1) 2) • Tell the system knowledge about a task domain. Ask the system whether new statements about the domain are true or false live_w4? Slide 44 lit_l2? To Obtain This We Need One More Definition We want a reasoning procedure that can find all and only the logical consequences of a knowledge base Slide 45 Study for midterm (Mon Oct 27) Midterm: ~6 short questions (10pts each) + 2 problems (20pts each) • Study: textbook and slides • Work on all practice exercises and revise assignments! • While you revise the learning goals, work on practice questions • Will post a couple of problems from previous offering (maybe slightly more difficult) … but I’ll give you the solutions Slide 46 Next class • Definite clauses Semantics and Proofs (textbook 5.1.2, 5.2.2) Slide 47