Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Logic Logical Inference We want to tell our computers facts that are true of the world. “It is raining.” Some of these facts specify how one thing is related to another. “It is raining implies it is wet.” We want our computers to be able to infer what else must be true of the world. “It is wet.” A logic is a system for inference from facts. CS 3793/5233 Artificial Intelligence Logical Inference – 2 Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Propositional Logic Syntax . . . . . . . . . . . . . . . Informal Semantics . . . . . . . Informal Semantics Example Formal Semantics 1 . . . . . . Formal Semantics 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Examples Simple Example . . . . . Simple Example . . . . . Electrical Environment Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 . 8 . 9 10 11 Proof Procedures Proofs . . . . . . . . . . . . . . . Brute Force Inference . . . . . CSP Inference . . . . . . . . . . Definite Clause Inference . . . Definite Clause Example . . . Proof by Contradiction . . . . Inference Rules . . . . . . . . . Resolution Theorem Proving Resolution Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 12 13 14 15 16 17 18 19 20 . . . . . . . . . . . . 1 3 3 4 5 6 7 Propositional Logic 3 Syntax A proposition is something that is true or false. An atomic proposition or atom consists of a single symbol. (≈ boolean variable) A compound proposition is constructed from simpler propositions p and q using logical operators (≈ boolean expression): – – – – – – ¬p (read “not p”)–negation p ∧ q (read “p and q”)–conjunction p ∨ q (read “p or q”)–disjunction p → q (read “p implies q”)–implication q ← p (read “q if p”)–implication p ↔ q (read “p iff q”)–equivalence [Note: I prefer using → to ←.] CS 3793/5233 Artificial Intelligence Logical Inference – 3 2 Informal Semantics Formal Semantics 2 Semantics maps between symbols and the world. Begin with a task domain. Choose symbols in the computer to denote propositions. Symbol ≈ variable name Tell the system knowledge about the domain. Knowledge ≈ code and inputs Ask the system true/false questions. Ask questions ≈ run a function The system should answer true, false or unknown as appropriate. You can interpret the answer because you know the meaning of the symbols. CS 3793/5233 Artificial Intelligence Logical Inference – 4 Informal Semantics Example ¬p false false true true p∧q true false false false Logical Inference – 5 p∨q true true true false p→q true false true true CS 3793/5233 Artificial Intelligence KB = {p → q, An interpretation I maps atoms to true or false. Based on how logical operators work, an interpretation maps each proposition to a truth value. Propositions may have different truth values in different interpretations. p q true true true false false true false false Logical Inference – 7 8 Simple Example Formal Semantics 1 Examples In computer: sw up ∧ power ∧ unlit l1 → l1 broken In user’s mind: sw up = switch is up, power = there is power in, unlit l1 = light #1 isn’t lit, l1 broken = light #1 is broken The computer doesn’t know the meaning of the symbols. The user can interpret the symbols using their meaning. CS 3793/5233 Artificial Intelligence A knowledge base is a set of propositions that the agent is given as being true. A model of knowledge base is an interpretation in which all the propositions in the knowledge base are true. If KB is a knowledge base and p is a proposition, KB entails p (written KB |= p) if p is true in every model of KB. KB |= p means that no interpretation exists in which KB is true and p is false. If KB |= p we also say p logically follows from KB, or p is a logical consequence of KB. I1 I2 I3 I4 I5 p true false true true true q true false true true true p, r true false false true false s → r} s true false false false true model? Which of p, q, r, s are entailed by KB? CS 3793/5233 Artificial Intelligence Logical Inference – 8 q←p p↔q true true false false true false true true CS 3793/5233 Artificial Intelligence Logical Inference – 6 3 4 Simple Example KB = {p → q, I1 I2 I3 I4 I5 p true false true true true q true false true true true p, r true false false true false Representation light l1 light l2 down s1 up s2 up s3 ok l1 ok l2 ok cb1 ok cb2 live outside s → r} s true false false false true model of KB? yes no yes yes no Which of p, q, r, s are entailed by KB? p and q CS 3793/5233 Artificial Intelligence Logical Inference – 9 live live live live live live live live live live live live w0 ∧ ok l1 → lit l1 w1 ∧ up s2 → live w0 w2 ∧ down s2 → live w0 w3 ∧ up s1 → live w1 w3 ∧ down s1 → live w2 w4 ∧ ok l2 → lit l2 w3 ∧ up s3 → live w4 w3 → live p1 w5 ∧ ok cb1 → live w3 w6 → live p2 w5 ∧ ok cb2 → live w6 outside → live w5 CS 3793/5233 Artificial Intelligence Logical Inference – 11 Electrical Environment Proof Procedures 12 Proofs A proof is a derivation that a proposition logically follows from a knowledge base. Given a proof procedure, KB ⊢ p means p can be derived or proved from KB. Recall KB |= p means KB entails p, that p is true in all models of KB. A proof procedure is sound if KB ⊢ p only if KB |= p. Anything that is proved is also entailed. A proof procedure is complete if KB |= p then also KB ⊢ p. Everything that is entailed can be proved. CS 3793/5233 Artificial Intelligence Logical Inference – 12 Brute Force Inference CS 3793/5233 Artificial Intelligence Logical Inference – 10 Enumerate all interpretations. Determine which interpretations are models of the KB. Determine which atoms (and any other propositions of interest) are true in all models (or false in all models). This is Ω(2n) where n is the number of atoms. CS 3793/5233 Artificial Intelligence 5 Logical Inference – 13 6 CSP Inference Proof by Contradiction Set up KB as a CSP. Each atom is a variable with two possible values. Each proposition in the KB is a constraint. Solutions of CSP = models of KB. Run arc consistency/domain splitting. Don’t stop after finding one CSP solution (KB model). Find them all. Determine which atoms are true in all models (or false in all models). This is still potentially exponential, but more efficient than brute force. See Section 4.6.1. CS 3793/5233 Artificial Intelligence Logical Inference – 14 CS 3793/5233 Artificial Intelligence Suppose all propositions in KB are definite clauses, either: an atom (e.g., an observation), or of the form p → q, where p and q are atoms (e.g., a rule about the behavior of the world) – of the form p1 ∧ . . . ∧ pk → q, where q and each pi are atoms Running CSP inference is efficient (linear in the length of the KB). See Section 5.2. CS 3793/5233 Artificial Intelligence Logical Inference – 15 Derive c from a and a → c. Remember p and q and r can be any propositions, not just atoms. Logical Inference – 18 Resolution Theorem Proving KB = {a, b, a → c, b ∧ c → d, d ∧ e → f } Know a and b. If KB |= p ∨ q and KB |= ¬p, then KB |= q. If KB |= p ∨ q and KB |= ¬p ∨ r, then KB |= q ∨ r. CS 3793/5233 Artificial Intelligence Definite Clause Example Modus ponens is an inference rule. If p is true, and if p → q is true, then q is true. That is, if KB |= p and KB |= p → q, then KB |= q. Resolution inference rule (really, two rules) – – – – Logical Inference – 17 Inference Rules Definite Clause Inference Suppose we want to determine if KB |= p. Let KB ′ = KB ∪ {¬p} Determine that no model exists for KB ′. Conclude that KB |= p. Should probably show that KB has at least one model. Resolution theorem proving is a sound and complete inference procedure for propositional logic. Transform the KB to conjunctive normal form, meaning each propositions in the KB is of the form l or l1 ∨ . . . ∨ lk , where each li is a literal, an atom or the negation of an atom. To show KB |= p, let KB ′ = KB ∪ {¬p}, and ensure KB ′ is in CNF. Proof is by deriving a contradiction, derive both a and ¬a for some atom a. Worst-case exponential-time. Lots of approaches to reduce the exponential. CS 3793/5233 Artificial Intelligence Derive d from b and c and b ∧ c → d Logical Inference – 19 Cannot derive e or f . CS 3793/5233 Artificial Intelligence Logical Inference – 16 7 8 Resolution Example KB = {a ∨ b, b ∨ c, ¬a ∨ ¬b, ¬a ∨ ¬c, ¬b ∨ ¬c} To prove KB |= b, add ¬b and prove a contradiction using the resolution inference rule. ~b aVb a bVc c ~a V ~b ~a V c b b V ~c ~b CS 3793/5233 Artificial Intelligence ~a V ~c ~c ~b V ~c a V ~c ~a Logical Inference – 20 9