CS 57 Introduction to AI Lecture 5 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 = α? In other words: In all interpretations in which sentences in the KB are true, is also α true? 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.
Logical inference problem in the Propositional logic Computational procedures that answer: Three approaches: KB = α? Truth-table approach Inference rules Conversion to the inverse SAT problem Resolution-refutation Inference in FOL: Truth table approach Is the Truth-table approach a viable approach for the FOL?? NO! Why? It would require us to enumerate and list all possible interpretations I I = (assignments of symbols to objects, predicates to relations and functions to relational mappings) Simply there are too many interpretations 2
Inference in FOL: Inference rules Is the Inference rule approach a viable approach for the FOL? Yes. The inference rules represent sound inference patterns one can apply to sentences in the KB What is derived by inference rules follows from the KB Caveat: we need to add rules for handling quantifiers Inference rules Inference rules from the propositional logic: Modus ponens A B, A B Resolution A B, B C A C and others: And-introduction, And-elimination, Orintroduction, Negation elimination Additional inference rules are needed for sentences with quantifiers and variables Rules must involve variable substitutions 3
Sentences with variables First-order logic sentences can include variables. Variable is: Bound if it is in the scope of some quantifier x Free if it is not bound. x Q( Examples: x y Likes ( x, Bound or free? y is free Sentences with variables First-order logic sentences can include variables. Variable is: Bound if it is in the scope of some quantifier x Free if it is not bound. x Q( y is free Examples: x y Likes ( x, Bound x Likes( x, y Likes( y, Raymond) Bound or free? ( ) 4
Sentences with variables First-order logic sentences can include variables. Variable is: Bound if it is in the scope of some quantifier x Free if it is not bound. x Q( y is free Examples: x y Likes ( x, Bound x Likes( x, y Likes( y, Raymond) x is Bound, first y is Free ( ) Sentences with variables First-order logic sentences can include variables. Sentence (formula) is: Closed if it has no free variables y x Q( Open if it is not closed x Q( y is free Ground if it does not have any variables Likes ( John, Jane) 5
Variable substitutions Variables in the sentences can be substituted with terms. (terms = constants, variables, functions) Substitution: Is represented by a mapping from variables to terms { 2 x / t, x2 / t, } Application of the substitution to sentences SUBST ({ x / Sam, y / Pam}, Likes ( x, ) = Likes ( Sam, Pam) SUBST ({ x / z, y / fatherof ( John)}, Likes ( x, ) =? Variable substitutions Variables in the sentences can be substituted with terms. (terms = constants, variables, functions) Substitution: Is represented by a mapping from variables to terms { 2 x / t, x2 / t, } Application of the substitution to sentences SUBST ({ x / Sam, y / Pam}, Likes ( x, ) = Likes ( Sam, Pam) SUBST ({ x / z, y / fatherof ( John)}, Likes( x, ) = Likes( z, fatherof ( John)) 6
Inference rules for quantifiers Universal elimination x φ( a - is a constant symbol φ( a) substitutes a variable with a constant symbol x Likes ( x, 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 ( x, 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 ( Amy, Jane) x Sister ( Amy, 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 ( x, IceCream ) 7
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 neccessary 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) Unification. Examples. Unification: UNIFY ( p, q) = σ s.t. SUBST(σ, p) = SUBST ( σ, q) Examples: UNIFY ( Knows( John,, Knows( John, Jane)) = { x / Jane} UNIFY ( Knows( John,, Knows( y, Ann)) = { x / Ann, y / John} UNIFY ( Knows( John,, Knows( y, MotherOf ( )) = { x / MotherOf ( John), y / John} UNIFY ( Knows( John,, Knows( x, Elizabeth )) = fail 8
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 A A2 An B, A ', A2 ', An ' SUBST( σ, B) for all i=,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 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) φ φ2 φk, ψ 2 ψ n SUBST ( σ, φ φ φ φ Example: σ = UNIFY ( φ, ψ ) i i+ i k j fail, Q( John)? j j+ ψ ) n 9
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) φ φ2 φk, ψ 2 ψ n SUBST ( σ, φ φ φ φ Example: σ = UNIFY ( φ, ψ ) i i+ i k j fail, Q( John) John) j j+ ψ ) n Inference with the resolution rule Proof by refutation: Prove that KB, α is unsatisfiable resolution is refutation-complete Main procedure (steps):. 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 0
Conversion to CNF. 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 ) ( x Q( ) ( x ) ( y Q( ) 4. Move all quantifiers left (no invalid capture possible ) ( x ) ( y Q( ) x y 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 A) A) B) If a universal quantifier precedes the existential quantifier replace the variable with a function of the universal variable x y x F( ) F( - a special function - called Skolem function
Conversion to CNF 6. Drop universal quantifiers (all variables are universally quantified) x F( ) 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 α, Q(,, R( z) z), S(A) 2
Resolution example KB, Q(,, R( z) z), α S(A) { y / w} Resolution example KB α, Q(,, R( z) z), S(A) { y / w} { x / w} S( 3
Resolution example KB, Q(,, R( z) z), α S(A) { y / w} { x / w} S( { z / w} S( Resolution example KB α, Q(,, R( z) z), S(A) { y / w} { x / w} S( { z / w} S( { w/ A} Empty resolution 4
Resolution example KB, Q(,, R( z) z), α S(A) { y / w} { 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 ) ( φ φ2 φk, t = t2 SUB( SUBST ( σ, t ), SUBST ( σ, t ), φ φ φ ) fail where occurs in i φ z i Example: P ( f ( a)), f ( = x a) Paramodulation rule: more powerful Resolution+paramodulation give a refutation-complete proof theory for FOL 2 2 k 5