CS 2710 Foundations of AI Lecture 15 Inference in first-order logic Milos Hauskrecht milos@cs.pitt.edu 5329 Sennott Square Logical inference in FOL Logical inference problem: Given a knowledge base KB (a set of sentences) and a sentence, does the KB semantically entail? KB? Logical inference problem in the first-order logic is undecidable!!! No procedure that can decide the entailment for all possible input sentences in a finite number of steps. Methods: Inference rule approach Resolution refutation 1
Inference rules for quantifiers Universal elimination x ( a - is a constant symbol ( a) substitutes a variable with a constant symbol x Likes( IceCream) Likes( Ben, IceCream) Existential elimination. x ( ( a) Substitutes a variable with a constant symbol that does not appear elsewhere in the KB x Kill ( Victim) Kill ( Murderer, Victim) Inference rules for quantifiers Universal instantiation (introduction) x is not free in x Introduces a universal variable which does not affect or its assumptions Sister ( Am Jane) x Sister( Am Jane) Existential instantiation (introduction) ( a) a is a ground term in x ( x is not free in Substitutes a ground term in the sentence with a variable and an existential statement Likes( Ben, IceCream) x Likes( IceCream) 2
Unification Problem in inference: Universal elimination gives us many opportunities for substituting variables with ground terms x ( a - is a constant symbol ( a) Solution: avoid making blind substitutions of ground terms Make substitutions that help to advance inferences Use substitutions matching similar sentences in KB Make inferences on the variable level Do not substitute ground terms if not necessary Unification takes two similar sentences and computes the substitution that makes them look the same, if it exists UNIFY( p, q) s.t. SUBST(σ, p) SUBST (, q) Generalized inference rules Use substitutions that let us make inferences!!!! Example: Generalized Modus Ponens If there exists a substitution such that SUBST, A ) SUBST (, A ') ( i i A1 A2 An B, A1 ', A2 ', An ' SUBST (, B) for all i=1,2, n Substitution that satisfies the generalized inference rule can be build via unification process Advantage of the generalized rules: they are focused only substitutions that allow the inferences to proceed are tried 3
Resolution inference rule Recall: Resolution inference rule is sound and complete (refutation-complete) for the propositional logic and CNF A B, A C B C Generalized resolution rule is sound and refutation complete for the first-order logic and CNF w/o equalities (if unsatisfiable the resolution will find the contradiction) 1 2 k, 1 2 n SUBST (, Example: 1 UNIFY(, ) i 1 i 1 i k j 1 fail P(, Q( John) P( John) j 1 j 1 ) n Inference with the resolution rule Matches the KB in CNF Proof by refutation: Prove that KB, is unsatisfiable resolution is refutation-complete Main procedure (steps): 1. Convert KB, to CNF with ground terms and universal variables only 2. Apply repeatedly the resolution rule while keeping track and consistency of substitutions 3. Stop when empty set (contradiction) is derived or no more new resolvents (conclusions) follow 4
Conversion to CNF 1. Eliminate implications, equivalences ( p q) ( p q) 2. Move negations inside (DeMorgan s Laws, double negation) ( p q) p q x p x p ( p q) p q x p x p p p 3. Standardize variables (rename duplicate variables) ( x P( ) ( x Q( ) ( x P( ) ( y Q( ) 4. Move all quantifiers left (no invalid capture possible ) ( x P( ) ( y Q( ) x y P( Conversion to CNF 5. Skolemization (removal of existential quantifiers through elimination) If no universal quantifier occurs before the existential quantifier, replace the variable with a new constant symbol also called Skolem constant y P( A) P( A) B) If a universal quantifier precedes the existential quantifier replace the variable with a function of the universal variable x y P( x P( F( ) F( - a special function - called Skolem function 5
Conversion to CNF 6. Drop universal quantifiers (all variables are universally quantified) x P( F( ) P( F( ) 7. Convert to CNF using the distributive laws p ( q r) ( p q) ( p r) The result is a CNF with variables, constants, functions Resolution example KB P(,, P(, R(, α S(A) 6
Resolution example KB P(,, P(, R(, α S(A) { y / w} P( Resolution example KB P(,, P(, R(, α S(A) { y / w} P( { x / w} S( 7
Resolution example KB P(,, P(, R(, α S(A) { y / w} P( { x / w} S( { z / w} S( Resolution example KB P(,, P(, R(, α S(A) { y / w} P( { x / w} S( { z / w} S( { w/ A} Empty resolution 8
Resolution example KB P(,, P(, R(, α S(A) { y / w} P( { x / w} S( { z / w} KB S( { w/ A} Empty resolution Contradiction Dealing with equality Resolution works for the first-order logic without equalities To incorporate equalities we need an additional inference rule Demodulation rule UNIFY z i, t ) ( 1 1 2 k, t1 t2 SUB( SUBST (, t ), SUBST (, t ), ) 1 fail where Example: P( f ( a)), f ( x P( a) Paramodulation rule: more powerful Resolution+paramodulation give a refutation-complete proof theory for FOL 2 z i 1 occurs in i 2 k 9
Sentences in Horn normal form Horn normal form (HNF) in the propositional logic a special type of a clause with at most one positive literal ( A B) ( A C D) Typically written as: ( B A) (( A C) D) A clause with one literal, e.g. A, is also called a fact A clause representing an implication (with a conjunction of positive literals in antecedent and one positive literal in consequent), is also called a rule Resolution rule and modus ponens: Both are complete inference rule for unit inferences for KBs in the Horn normal form. Recall: Not all KBs are convertible to HNF!!! Horn normal form in FOL First-order logic (FOL) adds variables and quantifiers, works with terms, predicates HNF in FOL: primitive sentences (propositions) are formed by predicates Generalized modus ponens rule: a substituti on s.t. i SUBST (, ') SUBST (, ) 1', 2', n', 1 2 n SUBST (, ) Generalized resolution and generalized modus ponens: is complete for unit inferences for the KBs in HN; Not all first-order logic sentences can be expressed in HNF i i 10
Forward and backward chaining Two inference procedures based on modus ponens for Horn KBs: Forward chaining Idea: Whenever the premises of a rule are satisfied, infer the conclusion. Continue with rules that became satisfied. Typical usage: If we want to infer all sentences entailed by the existing KB. Backward chaining (goal reduction) Idea: To prove the fact that appears in the conclusion of a rule prove the premises of the rule. Continue recursively. Typical usage: If we want to prove that the target (goal) sentence is entailed by the existing KB. Both procedures are complete for KBs in Horn form!!! Forward chaining example Forward chaining Idea: Whenever the premises of a rule are satisfied, infer the conclusion. Continue with rules that became satisfied Assume the KB with the following rules: KB: : Steamboat ( Sailboat ( Faster ( R2: R3: F1: F2: F3: Sailboat ( RowBoat ( Faster ( Faster ( Faster ( Faster ( Steamboat (Titanic ) Sailboat (Mistral ) RowBoat (PondArrow ) Theorem: Faster ( Titanic, PondArrow )? 11
Forward chaining example KB: : R2: R3: Steamboat( Sailboat ( Sailboat ( RowBoat ( Faster( F1: F3: RowBoat(PondArrow )? Forward chaining example KB: : R2: R3: Steamboat( Sailboat ( Sailboat ( RowBoat ( Faster( F1: F3: RowBoat(PondArrow ) Rule is satisfied: F4: Mistral ) 12
Forward chaining example KB: : R2: R3: Steamboat( Sailboat ( Sailboat ( RowBoat ( Faster( F1: F3: RowBoat(PondArrow ) Rule is satisfied: F4: Mistral ) Rule R2 is satisfied: F5: Faster( Mistral, PondArro Forward chaining example KB: : R2: R3: Steamboat( Sailboat ( Sailboat ( RowBoat ( Faster( F1: F3: RowBoat(PondArrow ) Rule is satisfied: F4: Mistral ) Rule R2 is satisfied: F5: Faster( Mistral, PondArro Rule R3 is satisfied: F6: PondArro 13
Backward chaining example Backward chaining (goal reduction) Idea: To prove the fact that appears in the conclusion of a rule prove the antecedents (if part) of the rule & repeat recursively. KB: : R2: R3: F1: F2: F3: Steamboat( Sailboat ( Sailboat ( RowBoat ( Faster( Sailboat(Mistral) RowBoat(PondArro Theorem: PondArro Backward chaining example PondArro F1: F3: RowBoat(PondArro Sailboat(PondArro Steamboat( Sailboat ( PondArro { x / Titanic, y / PondArrow } 14
Backward chaining example PondArro R2 Sailboat(Titanic) F1: F3: RowBoat(PondArro Sailboat(PondArro RowBoat(PondArro Sailboat ( RowBoat ( PondArro { y / Titanic, z / PondArrow } Backward chaining example PondArro R2 R3 F1: F3: RowBoat(PondArro Sailboat(Titanic) Faster( PondArrow ) Sailboat(PondArro RowBoat(PondArro Faster( PondArro { x / Titanic, z / PondArrow} 15
Backward chaining example PondArro R2 R3 F1: F3: RowBoat(PondArro Sailboat(Titanic) Faster( PondArrow ) Sailboat(PondArro RowBoat(PondArro Sailboat(Mistral) Steamboat( Sailboat( Mistral ) { x / Titanic, y / Mistral } Backward chaining example PondArro R2 R3 y must be bound to the same term Sailboat(Titanic) Faster( Mistral, PondArro Mistral ) Sailboat(PondArro RowBoat(PondArro Sailboat(Mistral) 16
Backward chaining example PondArro R2 R3 F1: F3: RowBoat(PondArro Sailboat(Titanic) Faster( Mistral, PondArro Mistral ) Sailboat(PondArro RowBoat(PondArro R2 Sailboat(Mistral) Sailboat(Mistral) RowBoat(PondArro Backward chaining PondArro R2 R3 Sailboat(Titanic) Faster( Mistral, PondArro Mistral ) Sailboat(PondArro RowBoat(PondArro R2 Sailboat(Mistral) Sailboat(Mistral) RowBoat(PondArro 17