Artificial Intelligence CS 165A Thursday, October 25, 2007 Knowledge and reasoning (Ch 7) • Propositional logic 1 Who is this key historical AI figure? • Built a calculating machine that could add and subtract (which Pascal’s couldn’t) • But his dream was much grander – to reduce human reasoning to a kind of calculation and to ultimately build a machine capable of carrying out such calculations Gottfried Leibniz (1646-1716) • Co-inventor of the calculus “For it is unworthy of excellent men to lose hours like slaves in the labor of calculation which could safely be relegated to anyone else if the machine were used.” 2 Notes • HW#2 posted, due Tuesday – 5x5 Tic Tac Toe game – Can work in teams of two, but different partner than in HW#1 – Can use your (or your team’s) code from HW#1 as starting point – You’ll need to use a heuristic to evaluate positions and go down N ply in your search so that the program returns an answer in a “short” amount of time About 10 seconds maximum.... X : 2 points O : 3 points ___________ |X|O|X|X|X| | |O|O|X| | | | |O|X| | | | | |O| | | | | | |O| ¯¯¯¯¯¯¯¯¯¯¯ 3 in a row : 1 point 4 in a row : 3 points 5 in a row : 5 points 3 KB Agents True sentences TELL Knowledge Base Domain specific content; facts ASK Inference engine Domain independent algorithms; can deduce new facts from the KB 4 Thursday Quiz 1. If KB is the knowledge base and is a logical sentence, what is the meaning of this statement? KB 2. Propositions P and Q are both true. Is this sentence true or false: P Q Briefly explain. 5 Syntax and semantics example • The PQ system – Syntax – A correct sentence must have the form {0 or more dashes} p {0 or more dashes} q {0 or more dashes} – For example --p---q----- --p---q---- --p---q--p-- -p-q- -p-q-- -q-p-- pq p-q -p-- --p-q- --pq-- --p-p-q---- • The PQ system – Semantics Not allowable – # plus # equals # – Which of the above sentence are TRUE? LEGAL sentences and TRUE sentences are not the same thing! 6 Semantics --p---q----Sentences -pq- --p--q----- World Semantics Representation (abstraction) 2+3=5 Facts 1+0=1 2+2=5 Note: Facts may or may not be true If sentence P is false, then sentence P is true 7 Inference and Entailment • Given a set of (true) sentences, logical inference generates new sentences – Sentence follows from sentences { i } – Sentences { i } entail sentence – The classic example is modus ponens: P Q and P entail what? • A knowledge base (KB) entails sentences KB • An inference procedure i can derive from KB KB i 8 Inference and Entailment (cont.) Sentences Sentence ENTAILS Semantics World Semantics Representation Facts Fact FOLLOWS 9 Using propositional logic: rules of inference • Inference (n.): a. The act or process of deriving logical conclusions from premises known or assumed to be true. b. The act of reasoning from factual knowledge or evidence. • Inference rules capture patterns of sound inference – Once established, we don’t need to show the truth table every time • Examples of inference rules: – ((P H) H) P I.e., if ((P H) H) is in the KB, then we can conclude P – ((P Q) P) Q I.e., if ((P Q) P) is in the KB, then we can conclude Q 10 Inference engine • An inference engine is a program that applies inference rules to knowledge – Goal: To infer new (and useful) knowledge • Separation of – Knowledge – Rules Inference engine – Control Which rules should we apply when? 11 Inference procedures • An inference procedure – Generates new sentences that purport to be entailed by the knowledge base …or... – Reports whether or not a sentence is entailed by the knowledge base • Not every inference procedure can derive all sentences that are entailed by the KB • A sound or truth-preserving inference procedure generates only entailed sentences • Inference derives valid conclusions independent of the semantics (i.e., independent of the interpretation) 12 Inference procedures (cont.) • Soundness of an inference procedure – i is sound if whenever KB i , it is also true that KB – I.e., the procedure only generates entailed sentences • Completeness of an inference procedure – i is complete if whenever KB , it is also true that KB i – I.e., the procedure can find a proof for any sentence that is entailed • The derivation of a sentence by a sound inference procedure is called a proof – Hence, the proof theory of a logical language specifies the reasoning steps that are sound 13 Logics • We will soon define a logic which is expressive enough to say most things of interest, and for which there exists a sound and complete inference procedure – I.e., the procedure will be able to derive anything that is derivable from the KB – This is first-order logic, a.k.a. first-order predicate calculus – But first, we need to define propositional logic 14 Propositional (Boolean) Logic • Symbols represent propositions (statements of fact, sentences) – P means “San Francisco is the capital of California” – Q means “It is raining in Seattle” • Sentences are generated by combining proposition symbols with Boolean (logical) connectives 15 Propositional Logic • Syntax – True, false, propositional symbols – ( ) , (not), (and), (or), (implies), (equivalent) • Examples of sentences in propositional logic P1, P2, etc. (propositions) S1 S2 ( S1 ) S1 S2 S1 true S1 S2 P1 true ( P2 false ) S1 S2 PQ QP 16 Propositional (Boolean) Logic (cont.) • Semantics – Defined by clearly interpreted symbols and straightforward application of truth tables – Rules for evaluating truth: Boolean algebra – Simple method: truth tables 2N rows for N propositions 17 Propositional (Boolean) Logic (cont.) • Make sure you know simple Boolean logic Associative, commutative, and distributive laws PQ QP (P Q) R P (Q R) P (Q R) (P Q) (P R) P P (P Q) P Q (P Q) P Q DeMorgan’s Laws P Q P Q Important! 18 Basic logical equivalences Equivalent Sentences P Q PQ P True P PQ True P Q P False P P P False 19 Satisfiability and Validity • Is this true: ( P Q ) ? – It depends on the values of P and Q – This is a satisfiable sentence – there are some interpretations for which it is true – In other words, it depends: it could be true or false • Is this true: ( P P ) ? – No, it is never true – This is an unsatisfiable sentence (self-contradictory) – there is no interpretation for which it is true • Is this true: ( ((P Q) Q) P ) ? – Yes, independent of the values of P and Q – This is a valid sentence – it is true under all possible interpretations (a.k.a. a tautology) – Truth tables can test for validity 20 Propositional logic (cont.) • AC – The premise implies the conclusion ... or ... The antecedent implies the consequent – What if A C is always true? Example: Then we can say that the antecedent entails the consequent. In other words, P and H can be seen as variables – this is true for any statements P and Q. 21 • One can say that the premise entails the conclusion – ((P H) H) entails P – ((P H) H) P • Have we also shown that ((P H) H) P ? Well, yes and no.... We still don’t have a method to derive this. But if we add this inference rule explicitly to our system, with P and H as variables representing any two propositions, then we do have such a procedure. 22 Using propositional logic: rules of inference • Inference rules capture patterns of sound inference – Once established, don’t need to show the truth table every time – E.g., we can define an inference rule: ((P H) H) P for variables P and H • Alternate notation for inference rule : “If we know , then we can conclude ” (where and are propositional logic sentences) 23 Inference • We’re particularly interested in KB or 1, 2, … • Inference steps KB 1 KB, 1 2 KB, 1, 2 3 … So we need a mechanism to do this! Inference rules that can be applied to sentences in our KB 24 Important Inference Rules for Propositional Logic 25 Resolution Rule: one rule for all inferences p q, q r p r Propositional calculus resolution Remember: p q p q, so let’s rewrite it as: p q, q r p r or a b, b c ac Resolution is really the “chaining” of implications. Would like to show that resolution is sound and (essentially) complete (use Deduction Rule for proof) 26 Inference in Propositional Logic • Three ways to answer: “Is Mary the grandparent of Ann?” – One way: Find sentence P (“Mary is the grandparent of Ann”) in KB – Another way: Put sentence P in the KB, and use inference rules to prove a contradiction (false) – Yet another way: Find sentence Q (“Mary is parent of Frank”), sentence R (“Frank is the parent of Ann”), and sentence Q R S, where S is the proposition “Mary is grandparent of Ann” Then apply modus ponens: Q R S, Q R to conclude S (“Mary is the grandparent of Ann”) “If Mary is the parent of Frank and Frank is the parent of Ann, then Mary is the grandparent of Ann” 27