330 likes | 595 Views
Inference in First Order Logic. Introduction to Artificial Intelligence CS440/ECE448 Lecture 12 New homework out today, due March 2. Last lecture. Examples of sentences Simple inference rules Inference with quantifiers This lecture Substitutions and unification Generalized Modus Ponens
E N D
Inference in First Order Logic Introduction to Artificial Intelligence CS440/ECE448 Lecture 12 New homework out today, due March 2
Last lecture • Examples of sentences • Simple inference rules • Inference with quantifiers This lecture • Substitutions and unification • Generalized Modus Ponens • Resolution and refutation Reading • Chapter 9
Substitutions Given a sentence and binding list , the result of applying the substitution to is denoted by Subst(, ). Example: s = {x/Sam, y/Pam} = Likes(x,y) Subst({x/Sam, y/Pam}, Likes(x,y)) = Likes(Sam, Pam)
Inference with Universal Quantifiers Universal Elimination (UE): x Subst({x/}, ) [ must be a ground term (i.e., no variables).] Example Imagine Universe of Discourse is {Rodrigo, Sharon, David, Jonathan} x At (x, UIUC) OK(x) At(Rodrigo, UIUC) OK(Rodrigo) substitution list
Inference with Existential Quantifiers Existential Elimination: Subst({/k}, ) where k is a new (Skolem) constant. Example From x Teaches(x, CS348) we can infer that Teaches(PorkyPig, CS348) if the symbol PorkyPig hasnot appeared before.
A simple proof • Premises: • Bob is a buffalo • Pat is a pig • Buffaloes outrun pigs • Prove that “Bob outruns Pat”. • Buffalo(Bob) • Pig(Pat) • x,y Buffalo(x)Pig(y)Faster(x,y) 4. Buffalo(Bob) Pig(Pat) AI 1, 2 5. Buffalo(Bob) Pig(Pat) Faster(Bob, Pat) UE 3, {x/Bob, y/Pat} 6. Faster(Bob, Pat) MP 4, 5
Search with primitive inference rules • Operators are inference rules. • States are sets of sentences. • Goal test checks state to see if it contains query sentence.. • Problem: branching factor huge, esp. for UE. • AI, UE, MP is a common inference pattern. • Idea: find a substitution that makes the rule premise match some known facts. A single, more powerful inference rule.
Unification A substitution unifies atomic sentences p and q if Subst(, p)= Subst(, q) (also denoted p=q). p q Knows(John,x) Knows(John, Jane) { x/Jane } { y/John, x/Amy } Knows(John,x) Knows(y, Amy) { y/John, x/Mother(John) } Knows(John,x) Knows(y, Mother(y)) Idea: Unify rule premises with known facts, apply unifier to conclusion. E.g., if we know both q and Knows(John,x) Likes(John,x) then we conclude: Likes(John,Jane) Likes(John,Amy) Likes(John,Mother(John))
A bit more on substitutions A substitution is a set of pairings of variables with terms: • = { v1/term1, v2/term2, … } such that: • each variable is paired at most once; and • a variable’s pairing term may not contain the variable directly or indirectly [ e.g. can’t have substitution { x/f(y), y/f(x) } ]. When unifying expressions and , the variable names in and the variable names in should be disjoint. • UNIFY(Loves (John, x), Loves (x, Jane)) ! No unifier • UNIFY(Loves (John, x), Loves (y, Jane)) ! = {x/Jane,y/John}
Most General Unifier • A substitution is more general than iff there is a substitution such that =. • e.g. = { z/ F(w) } is more general than = { z/F(C) } since = { w/C } • A most general unifier of and is such that, for any unifier of and , there exists a substitution = = (). • Informally, the most general unifier (MGU) imposes the fewest constraints on the terms (contains the most variables). • MGU’s are unique up to variable reordering and changes of naming of variables in terms. • The unification procedure on p. 278 gives the MGU.
Generalized Modus Ponens (GMP) p1’, p2’,…, pn’, (p1p2… pn q) wherepi’ = pi q for all i For example, let p1’ = Faster (Bob, Pat) p2’ = Faster (Pat, Steve) Faster (x, y) Faster (y, z) Faster (x, z) Unify p1’ and p2’ with the premise = { x/Bob, y/Pat, z/Steve } Apply substitution to the conclusion q = Faster(Bob, Steve) pi and q atomic sentences Universally quantified variables
A GMP Inference Engine • Perform inference search using only one inference rule, Generalized Modus Ponens. • Every sentence in the database should be put in canonical form • an atomic sentence, or • p1 p2 … pn q where piand q are atomic sentences. • These are Horn sentences. Can convert other sentences to Horn sentences using Existential Elimination and And-Elimination. • All variables are assumed to be universally quantified. • Previous proof is now one step.
Forward chaining When a new fact P is added to the KB: For each rule such that P unifies with a premise, if the other premises are known then add the conclusion to the KB and continue chaining. Forward chaining is data-driven, e.g., inferring properties and categories from percepts.
Forward Chaining Example • White: Facts added in turn • Yellow: The result of implication of rules. • Buffalo(x) Pig(y) Faster(x, y) • Pig(y) Slug(z) Faster(y, z) • Faster(x, y) Faster(y, z) Faster(x, z) • Buffalo(Bob) [ Unifies with 1-a ] • Pig(Pat) [ Unifies with 1-b, GMP Fires ] [ Unifies with 2-a ] • Faster(Bob,Pat) [ Unifies with 3-a, 3-b ] • Slug(Steve) [ Unifies with 2-b, GMP Fires ] • Faster(Pat, Steve) [ Unifies with 3-b and with 6,GMP Fires ] • Faster (Bob, Steve) • …
Backward chaining p1 p2 … pn q • When a query q is examined: if a matching fact q' is known, return the unifier; for each rule whose consequent q' matchesq, attempt to prove each premise of the rule by backward chaining. • (Some added complications in keeping track of the unifiers.) • (More complications help to avoid infinite loops.) • Two versions: (1) find any solution, (2) find all solutions. • Backward chaining is the basis for “logic programming,” e.g., Prolog.
Pig(y) Slug(z) Faster (y, z) Slimy(a) Creeps(a) Slug(a) Pig(Pat) Slimy(Steve) Creeps(Steve) Backward Chaining Example
Soundness & Completeness • An inference procedure is sound if the conclusion is true in all cases where the premises are true. • Easy to show the Generalized Modus Ponens (GMP) is sound. • Completeness: If KB entails , can GMP be used to infer ? PhD(x) HighlyQualified(x) PhD(x) EarlyEarnings(x) HighlyQualified(x) Rich(x) EarlyEarnings(x) Rich(x) Should be able to infer Rich(Me) [or Rich(Kiki) for that matter], but can’t since PhD(x) EarlyEarnings(x)is not a Horn sentence. • Therefore, GMP is NOT complete!
Refutation Proofs • Given • a knowledge base KB (collection of true sentences), • a proposition P, we wish to prove that P is true. • Proof by contradiction (refutation): • Assume that P is FALSE (i.e., that P is TRUE). • Show that a contradiction arises. • A complete approach to refutation can be obtained using a single inference rule: resolution.
Resolution Inference Rule • Idea: If is true or is true and is false or is true then or must be true • Basic resolution rule from propositional logic: • Can be expressed in terms of implications , • Note that Resolution rule is a generalization of Modus Ponens , is equivalent to TRUE , TRUE
Generalized Resolution Generalized resolution rule for first order logic (with variables) If pj can be unified with qk, then we can apply the resolution rule: p1 … pj … pm q1 … qk … qn Subst(, (p1 … pj-1 pj+1 … pm q1 … qk-1 qk+1 … qn)) where = Unify (pj, qk) • Example: KB: Rich(x) Unhappy(x) Rich(Me) Substitution: = { x/Me } Conclusion: Unhappy(Me)
Canonical Form • For generalized Modus Ponens, entire knowledge base is represented as Horn Sentences. • For resolution, entire database will be represented using Conjunctive Normal Form (CNF) • Any first order logic sentence can be converted to a Canonical CNF form. • Note: Can also do resolution with implicative form, but let’s stick to CNF.
Converting any FOL to CNF • Literal = (possibly negated) atomic sentence, e.g., Rich(Me) • Clause = disjunction of literals, e.g., Rich(Me) Unhappy(Me) • The KB is a conjunction of clauses • Any FOL sentence can be converted to CNF as follows: • Replace P QbyP Q • Move inwards to literals, e.g., x P becomes x P • Standardize variables, e.g., (x P) (x Q) becomes (x P) (y Q) • Move quantifiers left in order, e.g., x P y Q becomes x y P Q • Eliminate by Skolemization (next slide) • Drop universal quantifiers • Distribute over , e.g., (P Q) R becomes (P R) (Q R) • Flatten nested conjunctions & disjunctions, e.g. (P Q) R P Q R
Skolemization (Thoralf Skolem 1920) • The process of removing existential quantifiers by elimination. • Simple case: No universal quantifiers. Existential Elimination Rule • For example: x Rich(x) becomes Rich(G1) where G1 is a new ``Skolem constant'‘. • More tricky when is inside .
Skolemization – continued • More tricky when is inside E.g., ``Everyone has a heart'' x Person(x) y Heart(y) Has(x,y) • Incorrect: x Person(x) Heart(H1) Has(x,H1) This means everyone has the same heart calledH1. • Problem is that for each person, we need another “heart” – i.e., consider the “heart” to be a function of the person. • Correct: Person(x) Heart(H(x)) Has(x,H(x)) where H is a new symbol (``Skolem function'') • Skolem function arguments: all enclosing universally quantified variables.
Resolution proof p1 … pj … pm q1 … qk … qn Subst(, (p1 … pj-1 pj+1 … pm q1 … qk-1 qk+1 … qn)) • To prove : • Negate . • Convert to CNF. • Add to CNF KB. • Infer contradiction using the resolution rule (a contradiction is detected when resolution derives the empty clause). • E.g., to prove Rich(Me),add Rich(Me) to the CNF KB, then: PhD(x) HighlyQualified(x) PhD(x) EarlySalary(x) HighlyQualified(x) Rich(x) EarlySalary(x) Rich(x)
Resolution Proof Rich(Me) PhD(x) HighlyQualified(x) PhD(x) EarlySalary(x) HighlyQualified(x) Rich(x) EarlySalary(x) Rich(x)
Resolution Proof Rich(Me) PhD(x) HighlyQualified(x) PhD(x) EarlySalary(x) HighlyQualified(x) Rich(x) EarlySalary(x) Rich(x)
Resolution Proof Rich(Me) PhD(x) HighlyQualified(x) PhD(x) EarlySalary(x) HighlyQualified(x) Rich(x) EarlySalary(x) Rich(x)
Resolution Proof Rich(Me) PhD(x) HighlyQualified(x) PhD(x) EarlySalary(x) HighlyQualified(x) Rich(x) EarlySalary(x) Rich(x)
All birds fly. No bird swims Pete is a bird Does Pete Fly? The Knowledge base 1. Bird(x) Flies(x) 2. Bird(y)Swims(y) Bird(Pete) The query Flies ( Pete) Applying Resolution 5. Swims(Pete) 2,3 Bird(Pete) 1,4 { } 3,6 True-or-False Question
Decidability How hard is it to determine if KB entails ? • Propositional logic (zeroth order) is decidable: • Can determine whether or not KB entails in finite time. • Second order logic is undecidable: • Cannot determine whether KB entails in finite time. • First order logic is semi-decidable: • If KB entails or , then a proof will be found in finite time. • But, if KB neither entails or , then proof process may never terminate.
Resolution • Resolution is sound. • Resolution refutation is complete. (See Section 9.5 for proof.) • Resolution (and any proof procedure) is at best semi-decidable. • Note: checking consistency of a database is also semidecidable.