29.01.2014 Views

Inference in first-order logic

Inference in first-order logic

Inference in first-order logic

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Artificial Intelligence<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong><br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 1


Outl<strong>in</strong>e<br />

♦ Reduc<strong>in</strong>g <strong>first</strong>-<strong>order</strong> <strong>in</strong>ference to propositional <strong>in</strong>ference<br />

♦ Unification<br />

♦ Generalized Modus Ponens<br />

♦ Forward and backward cha<strong>in</strong><strong>in</strong>g<br />

♦ Resolution<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 2


Universal <strong>in</strong>stantiation (UI)<br />

Every <strong>in</strong>stantiation of a universally quantified sentence is entailed<br />

by it:<br />

∀v α<br />

SUBST({v/g},α)<br />

for any variable v and ground term g<br />

E.g., ∀x K<strong>in</strong>g(x) ∧ Greedy(x) → Evil(x) yields<br />

K<strong>in</strong>g(John) ∧ Greedy(John) → Evil(John)<br />

K<strong>in</strong>g(Richard) ∧ Greedy(Richard) → Evil(Richard)<br />

K<strong>in</strong>g(Father(John)) ∧ Greedy(Father(John))<br />

→ Evil(Father(John))<br />

.<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 3


Existential <strong>in</strong>stantiation (EI)<br />

For any sentence α, variable v, and constant symbol k not<br />

appear<strong>in</strong>g <strong>in</strong> the knowledge base:<br />

k is called a Skolem constant<br />

∃v α<br />

SUBST({v/k},α)<br />

♦ E.g., ∃x Crown(x) ∧ OnHead(x,John) yields<br />

Crown(C 1 ) ∧ OnHead(C 1 ,John)<br />

provided C 1 is a new constant symbol<br />

♦ from ∃x d(x y )/dy =x y we obta<strong>in</strong><br />

d(e y )/dy =e y<br />

provided e is a new constant symbol<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 4


Existential <strong>in</strong>stantiation contd.<br />

♦ UI can be applied several times to add new sentences;<br />

♦ the new KB is <strong>logic</strong>ally equivalent to the old<br />

♦ EI can be applied once to replace the existential sentence;<br />

♦ the new KB is not equivalent to the old,<br />

♦ but is satisfiable iff the old KB was satisfiable<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 5


Existential <strong>in</strong>stantiation contd.<br />

♦ UI can be applied several times to add new sentences;<br />

♦ the new KB is <strong>logic</strong>ally equivalent to the old<br />

♦ EI can be applied once to replace the existential sentence;<br />

♦ the new KB is not equivalent to the old,<br />

♦ but is satisfiable iff the old KB was satisfiable<br />

♦ trickier when ∃ <strong>in</strong> the scope of ∀<br />

♦ e.g. “Every person has a heart”<br />

∀x(Person(x) → ∃yHas(x,y) ∧ Heart(y))<br />

wrong: ∀x(Person(x) → Has(x,H 1 ) ∧ Heart(H 1 ))<br />

♦ we don’t share the same heart!<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 5


Propositionalization<br />

Suppose the KB conta<strong>in</strong>s just the follow<strong>in</strong>g:<br />

∀x K<strong>in</strong>g(x) ∧ Greedy(x) → Evil(x)<br />

K<strong>in</strong>g(John)<br />

Greedy(John)<br />

Brother(Richard,John)<br />

Instantiat<strong>in</strong>g the universal sentence <strong>in</strong> all possible ways, we have<br />

K<strong>in</strong>g(John) ∧ Greedy(John) → Evil(John)<br />

K<strong>in</strong>g(Richard) ∧ Greedy(Richard) → Evil(Richard)<br />

K<strong>in</strong>g(John)<br />

Greedy(John)<br />

Brother(Richard,John)<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 6


Propositionalization<br />

K<strong>in</strong>g(John) ∧ Greedy(John) → Evil(John)<br />

K<strong>in</strong>g(Richard) ∧ Greedy(Richard) → Evil(Richard)<br />

K<strong>in</strong>g(John)<br />

Greedy(John)<br />

Brother(Richard,John)<br />

The new KB is propositionalized: proposition symbols are<br />

K<strong>in</strong>g(John), Greedy(John), Evil(John),K<strong>in</strong>g(Richard) etc.<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 7


Problems with propositionalization<br />

♦ Propositionalization seems to generate lots of irrelevant<br />

sentences.<br />

E.g., from<br />

∀x K<strong>in</strong>g(x) ∧ Greedy(x) → Evil(x)<br />

K<strong>in</strong>g(John)<br />

∀y Greedy(y)<br />

Brother(Richard,John)<br />

♦ it seems obvious that Evil(John), but propositionalization<br />

produces lots of facts such as Greedy(Richard) that are<br />

irrelevant<br />

♦ With p k-ary predicates and n constants, there are p · n k<br />

<strong>in</strong>stantiations<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 8


Unification<br />

♦ looks for substitutions <strong>in</strong> a smarter way<br />

♦ e.g. θ = {x/John,y/John} makes K<strong>in</strong>g(x) and Greedy(x)<br />

match K<strong>in</strong>g(John) and ∀y Greedy(y)<br />

♦ <strong>in</strong> general: UNIFY(α,β) = θ if αθ =βθ<br />

α{x 1 /c 1 ,...,x n /c n } ≡ SUBST({x 1 /c 1 },α{x 2 /c 2 ,...,x n /c n })<br />

α β θ<br />

Knows(John, x) Knows(John, Jane)<br />

Knows(John, x) Knows(y, OJ)<br />

Knows(John, x) Knows(y, Mother(y))<br />

Knows(John, x) Knows(x, OJ)<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 9


Unification<br />

♦ looks for substitutions <strong>in</strong> a smarter way<br />

♦ e.g. θ = {x/John,y/John} makes K<strong>in</strong>g(x) and Greedy(x)<br />

match K<strong>in</strong>g(John) and ∀y Greedy(y)<br />

♦ <strong>in</strong> general: UNIFY(α,β) = θ if αθ =βθ<br />

α{x 1 /c 1 ,...,x n /c n } ≡ SUBST({x 1 /c 1 },α{x 2 /c 2 ,...,x n /c n })<br />

α β θ<br />

Knows(John, x) Knows(John, Jane) {x/Jane}<br />

Knows(John, x) Knows(y, OJ)<br />

Knows(John, x) Knows(y, Mother(y))<br />

Knows(John, x) Knows(x, OJ)<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 9


Unification<br />

♦ looks for substitutions <strong>in</strong> a smarter way<br />

♦ e.g. θ = {x/John,y/John} makes K<strong>in</strong>g(x) and Greedy(x)<br />

match K<strong>in</strong>g(John) and ∀y Greedy(y)<br />

♦ <strong>in</strong> general: UNIFY(α,β) = θ if αθ =βθ<br />

α{x 1 /c 1 ,...,x n /c n } ≡ SUBST({x 1 /c 1 },α{x 2 /c 2 ,...,x n /c n })<br />

α β θ<br />

Knows(John, x) Knows(John, Jane) {x/Jane}<br />

Knows(John, x) Knows(y, OJ) {x/OJ, y/John}<br />

Knows(John, x) Knows(y, Mother(y))<br />

Knows(John, x) Knows(x, OJ)<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 9


Unification<br />

♦ looks for substitutions <strong>in</strong> a smarter way<br />

♦ e.g. θ = {x/John,y/John} makes K<strong>in</strong>g(x) and Greedy(x)<br />

match K<strong>in</strong>g(John) and ∀y Greedy(y)<br />

♦ <strong>in</strong> general: UNIFY(α,β) = θ if αθ =βθ<br />

α{x 1 /c 1 ,...,x n /c n } ≡ SUBST({x 1 /c 1 },α{x 2 /c 2 ,...,x n /c n })<br />

α β θ<br />

Knows(John, x) Knows(John, Jane) {x/Jane}<br />

Knows(John, x) Knows(y, OJ) {x/OJ, y/John}<br />

Knows(John, x) Knows(y, Mother(y)) {y/John, x/Mother(John)}<br />

Knows(John, x) Knows(x, OJ)<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 9


Unification<br />

♦ looks for substitutions <strong>in</strong> a smarter way<br />

♦ e.g. θ = {x/John,y/John} makes K<strong>in</strong>g(x) and Greedy(x)<br />

match K<strong>in</strong>g(John) and ∀y Greedy(y)<br />

♦ <strong>in</strong> general: UNIFY(α,β) = θ if αθ =βθ<br />

α{x 1 /c 1 ,...,x n /c n } ≡ SUBST({x 1 /c 1 },α{x 2 /c 2 ,...,x n /c n })<br />

α β θ<br />

Knows(John, x) Knows(John, Jane) {x/Jane}<br />

Knows(John, x) Knows(y, OJ) {x/OJ, y/John}<br />

Knows(John, x) Knows(y, Mother(y)) {y/John, x/Mother(John)}<br />

Knows(John, x) Knows(x, OJ) fail<br />

♦ Standardiz<strong>in</strong>g apart elim<strong>in</strong>ates overlap of variables, e.g.,<br />

Knows(z 17 ,OJ)<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 9


Unification (contd.)<br />

♦ idea: Unify rule premises with known facts, apply unifier to<br />

conclusion<br />

♦ e.g. know<strong>in</strong>g β and assertion<br />

∀x Knows(John,x) → Likes(John,x) we can conclude<br />

♦ Likes(John,Jane)<br />

♦ Likes(John,OJ)<br />

♦ Likes(John,Mother(John))<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 10


Generalized Modus Ponens (GMP)<br />

p 1 ′ , p 2 ′ , ..., p n ′ , (p 1 ∧ p 2 ∧ ... ∧ p n → q)<br />

qθ<br />

where UNIFY(p i ′ ,p i ) =θ for all i<br />

p ′ 1 is K<strong>in</strong>g(John)<br />

p ′ 2 is Greedy(y)<br />

θ is {x/John,y/John}<br />

qθ is Evil(John)<br />

p 1 is K<strong>in</strong>g(x)<br />

p 2 is Greedy(x)<br />

q is Evil(x)<br />

♦ GMP used with KB of def<strong>in</strong>ite clauses (exactly one positive<br />

literal)<br />

♦ All variables assumed universally quantified<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 11


Soundness of GMP<br />

♦ Need to show that<br />

p 1 ′ , ..., p n ′ , (p 1 ∧ ... ∧ p n → q) |= qθ<br />

provided that p i ′ θ =p i θ for all i<br />

♦ Lemma: For any def<strong>in</strong>ite clause p, we have p |= pθ by UI<br />

1. (p 1 ∧ ... ∧ p n → q) |=<br />

(p 1 ∧ ... ∧ p n → q)θ = (p 1 θ ∧ ... ∧ p n θ → qθ)<br />

2. p 1 ′ , ..., p n ′ |= p 1 ′ ∧ ... ∧ p n ′ |= p 1 ′ θ ∧ ... ∧ p n ′ θ<br />

3. From 1 and 2, qθ follows by ord<strong>in</strong>ary Modus Ponens<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 12


Forward cha<strong>in</strong><strong>in</strong>g<br />

♦ When a new fact p is added to the KB<br />

♦ for each rule such that p unifies with a premise<br />

♦ if the other premises are known then add the conclusion to<br />

the KB and cont<strong>in</strong>ue cha<strong>in</strong><strong>in</strong>g<br />

♦ Forward cha<strong>in</strong><strong>in</strong>g is data-driven<br />

E.g., <strong>in</strong>ferr<strong>in</strong>g properties and categories from percepts<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 13


¡<br />

¢<br />

¤ £<br />

¤<br />

¢<br />

new<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 14<br />

Forward cha<strong>in</strong><strong>in</strong>g algorithm<br />

false<br />

<br />

© <br />

¤¡¢<br />

α<br />

§<br />

¨KB<br />

¥¦<br />

¢<br />

FOL-FC-ASK<br />

<br />

¤ <br />

<br />

<br />

<br />

new ← { }<br />

¦<br />

r<br />

¥ ¢ KB<br />

<br />

<br />

<br />

£<br />

<br />

¦<br />

<br />

r<br />

(p1 ∧ . . . ∧ pn → q) ← STANDARDIZE-APART<br />

©<br />

§<br />

(p1 ∧ . . . ∧ pn)θ = (p 1 ′ ∧ . . . ∧ p n)θ<br />

′<br />

p 1, ′ . . .,p n<br />

′<br />

<br />

θ<br />

<br />

<br />

<br />

£<br />

<br />

¦<br />

<br />

¦<br />

KB<br />

<br />

q<br />

©<br />

q ′ ← SUBST<br />

§<br />

¨θ<br />

KB<br />

<br />

!"<br />

<br />

<br />

q ′<br />

<br />

¥<br />

<br />

<br />

new<br />

q ′<br />

<br />

<br />

!<br />

α<br />

©<br />

§<br />

¨q′<br />

¤<br />

¢<br />

fail<br />

<br />

¥<br />

¤¡¢ φ<br />

φ ← UNIFY<br />

φ<br />

new KB<br />

new<br />

false<br />

<br />

<br />

<br />

!<br />

" $<br />

¤¡¢ <br />

¡<br />

¤ ¢<br />

¥ #


Properties of forward cha<strong>in</strong><strong>in</strong>g<br />

♦ Sound and complete for <strong>first</strong>-<strong>order</strong> def<strong>in</strong>ite clauses<br />

(proof similar to propositional proof)<br />

♦ Datalog = <strong>first</strong>-<strong>order</strong> def<strong>in</strong>ite clauses and no functions<br />

♦ FC term<strong>in</strong>ates for Datalog <strong>in</strong> poly iterations: at most p · n k<br />

literals<br />

♦ general case: may not term<strong>in</strong>ate if α is not entailed<br />

♦ unavoidable: entailment with def<strong>in</strong>ite clauses (with<br />

functions) is semidecidable<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 15


Efficiency of forward cha<strong>in</strong><strong>in</strong>g<br />

♦ Simple observation: no need to match a rule on iteration k if<br />

a premise wasn’t added on iteration k − 1<br />

→ match each rule whose premise conta<strong>in</strong>s a newly added<br />

literal<br />

♦ Match<strong>in</strong>g itself can be expensive<br />

♦ Database <strong>in</strong>dex<strong>in</strong>g allows O(1) retrieval of known facts<br />

♦ e.g., query Pig(x) retrieves Pig(babe)<br />

♦ Match<strong>in</strong>g conjunctive premises aga<strong>in</strong>st known facts is<br />

NP-hard<br />

♦ Forward cha<strong>in</strong><strong>in</strong>g is widely used <strong>in</strong> deductive databases<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 16


Backward cha<strong>in</strong><strong>in</strong>g<br />

♦ When a query q is asked<br />

♦ if a match<strong>in</strong>g fact q ′ is known, return the unifier<br />

♦ for each rule whose consequent q ′ matches q attempt to<br />

prove each premise of the rule by backward cha<strong>in</strong><strong>in</strong>g<br />

♦ returns the unifiers (value for variables)<br />

♦ two versions: f<strong>in</strong>d any solution, f<strong>in</strong>d all solutions<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 17


© <br />

¤¡¢<br />

§<br />

<br />

<br />

¥¦<br />

¢<br />

FOL-BC-ASK<br />

¡<br />

¢<br />

¤ £<br />

¨<br />

<br />

<br />

<br />

%<br />

"<br />

¤<br />

©<br />

§<br />

§<br />

©<br />

§<br />

&<br />

<br />

£<br />

<br />

<br />

<br />

¦<br />

<br />

! <br />

¦<br />

§<br />

!<br />

©<br />

§<br />

©<br />

§<br />

§<br />

<br />

<br />

Backward cha<strong>in</strong><strong>in</strong>g algorithm<br />

¨KB<br />

<br />

¨θ<br />

¨KB<br />

ans<br />

goals<br />

q ′ ← SUBST ¨θ FIRST goals<br />

r<br />

θ ′ ← UNIFY ¨q q ′<br />

ans ← FOL-BC-ASK [p 1 , . . .,p n |REST<br />

<br />

<br />

<br />

{θ}<br />

" ¤¡¢ ¢<br />

$ <br />

¥<br />

¤ ¡¢ ans<br />

¥ ¢ KB<br />

" $<br />

STANDARDIZE-APART<br />

© <br />

r<br />

goals<br />

'(p1 ∧ . . . ∧ pn → q)<br />

¨]<br />

COMPOSE<br />

¨θ′<br />

θ<br />

∪ ans<br />

♦ KB is a list of (Horn) clauses<br />

♦ goals a list of conjuncts, the query<br />

♦ θ the current substitution, <strong>in</strong>itially the empty substitution { }<br />

♦ SUBST(COMPOSE(θ 1 ,θ 2 ),p) = SUBST(θ 2 , SUBST(θ 1 ,p))<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 18


Properties of backward cha<strong>in</strong><strong>in</strong>g<br />

♦ Depth-<strong>first</strong> recursive proof search: space is l<strong>in</strong>ear <strong>in</strong> size of<br />

proof<br />

♦ Incomplete due to <strong>in</strong>f<strong>in</strong>ite loops<br />

→ fix by check<strong>in</strong>g current goal aga<strong>in</strong>st every goal on stack<br />

♦ Inefficient due to repeated subgoals (both success and<br />

failure)<br />

→ fix us<strong>in</strong>g cach<strong>in</strong>g of previous results (extra space!)<br />

♦ widely used for <strong>logic</strong> programm<strong>in</strong>g; e.g., Prolog<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 19


Completeness<br />

♦ procedure i is complete if and only if<br />

KB ⊢ i α whenever KB |= α<br />

♦ forward and backward cha<strong>in</strong><strong>in</strong>g are complete for Horn KBs<br />

♦ but <strong>in</strong>complete for general <strong>first</strong>-<strong>order</strong> <strong>logic</strong><br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 20


Resolution: brief summary<br />

l 1 ∨ · · · ∨ l k , m 1 ∨ · · · ∨ m n<br />

(l 1 ∨ · · · ∨ l i−1 ∨ l i+1 ∨ · · · ∨ l k ∨ m 1 ∨ · · · ∨ m j−1 ∨ m j+1 ∨ · · · ∨ m n )θ<br />

where UNIFY(l i , ¬m j ) =θ<br />

♦ e.g.,<br />

¬Rich(x) ∨ Unhappy(x)<br />

Rich(Ken)<br />

Unhappy(Ken)<br />

with θ = {x/Ken}<br />

♦ refutation: apply resolution steps to CNF(KB ∧ ¬α)<br />

♦ complete for FOL<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 21


Conjunctive Normal Form (CNF)<br />

♦ literal: (possibly negated) atomic sentence, e.g., Rich(Ken)<br />

♦ clause: disjunction of literals, e.g.,<br />

¬Rich(x) ∨ Unhappy(x)<br />

♦ KB is a set of clauses (conjunction)<br />

♦ variables are universally quantified<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 22


Conversion to CNF<br />

Everyone who loves all animals is loved by someone:<br />

∀x (∀y Animal(y) → Loves(x,y)) → (∃y Loves(y,x))<br />

1. Elim<strong>in</strong>ate biconditionals and implications: p → q ≡ ¬p ∨ q<br />

∀x (¬∀y ¬Animal(y) ∨ Loves(x,y)) ∨ (∃y Loves(y,x))<br />

2. Move ¬ <strong>in</strong>wards: ¬∀x p ≡ ∃x ¬p, ¬∃x p ≡ ∀x ¬p:<br />

∀x (∃y ¬(¬Animal(y) ∨ Loves(x,y))) ∨ (∃y Loves(y,x))<br />

∀x (∃y ¬¬Animal(y) ∧ ¬Loves(x,y)) ∨ (∃y Loves(y,x))<br />

∀x (∃y Animal(y) ∧ ¬Loves(x,y)) ∨ (∃y Loves(y,x))<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 23


Conversion to CNF contd.<br />

4. standardize variables: each quantifier should use a different<br />

one<br />

∀x (∃y Animal(y) ∧ ¬Loves(x,y)) ∨ (∃z Loves(z,x))<br />

5. skolemization (general form of EI): Each existential variable is<br />

replaced by a Skolem function of the enclos<strong>in</strong>g universally<br />

quantified variables<br />

∀x (Animal(F(x)) ∧ ¬Loves(x,F(x))) ∨ Loves(G(x),x)<br />

6. drop universal quantifiers (variables are UQ)<br />

(Animal(F(x)) ∧ ¬Loves(x,F(x))) ∨ Loves(G(x),x)<br />

7. distribute ∧ over ∨:<br />

(Animal(F(x)) ∨ Loves(G(x),x))∧<br />

(¬Loves(x,F(x)) ∨ Loves(G(x),x))<br />

<strong>Inference</strong> <strong>in</strong> <strong>first</strong>-<strong>order</strong> <strong>logic</strong> – 24

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!