12.07.2013 Views

P(x) - Indian Institute of Technology Kharagpur

P(x) - Indian Institute of Technology Kharagpur

P(x) - Indian Institute of Technology Kharagpur

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Inference in First Order Logic<br />

Course: CS40002<br />

Instructor: Dr. Pallab Dasgupta<br />

Department <strong>of</strong> Computer Science & Engineering<br />

<strong>Indian</strong> <strong>Institute</strong> <strong>of</strong> <strong>Technology</strong> <strong>Kharagpur</strong>


Inference rules<br />

Universal elimination:<br />

∀ x Likes( x, IceCream ) with the substitution<br />

{x / Einstein} gives us Likes( Einstein, IceCream )<br />

The substitution has to be done by a ground term<br />

Existential elimination:<br />

From ∃ x Likes( x, IceCream ) we may infer<br />

Likes( Man, IceCream ) as long as Man does not<br />

appear elsewhere in the Knowledge base<br />

Existential introduction:<br />

From Likes( Monalisa, Monalisa,<br />

IceCream ) we can infer<br />

∃ x Likes( x, IceCream )<br />

CSE, IIT <strong>Kharagpur</strong><br />

2


Reasoning in first-order first order logic<br />

The law says that it is a crime for a Gaul<br />

to sell potion formulas to hostile nations.<br />

The country Rome, an enemy <strong>of</strong> Gaul,<br />

has acquired some potion formulas, and<br />

all <strong>of</strong> its formulas were sold to it by Druid<br />

Traitorix. Traitorix<br />

Traitorix is a Gaul.<br />

Is Traitorix a criminal?<br />

CSE, IIT <strong>Kharagpur</strong><br />

3


Generalized Modus Ponens<br />

For atomic sentences p i, , p i’, ’, and q, where<br />

there is a substitution θ such that<br />

SUBST(θ, SUBST( , p i ’) ) = SUBST(θ, SUBST( , p i), for all i:<br />

′<br />

CSE, IIT <strong>Kharagpur</strong><br />

p′<br />

,..., p′<br />

, ( p p<br />

2 n 1 ∧ ∧...<br />

∧<br />

SUBST ( θ,<br />

q)<br />

), for all i:<br />

p1, p<br />

2<br />

n<br />

⇒ q)<br />

4


Unification<br />

UNIFY(p,q) = θ where SUBST(θ,p) SUBST( ,p) = SUBST(θ,q)<br />

SUBST( ,q)<br />

Examples:<br />

UNIFY( Knows(Erdos<br />

Knows( Erdos, , x),Knows(Erdos<br />

x),Knows( Erdos, , Godel)) Godel))<br />

= {x / Godel} Godel<br />

UNIFY( Knows(Erdos<br />

Knows( Erdos, , x), Knows(y,Godel<br />

Knows(y, Godel)) ))<br />

= {x/Godel {x/ Godel, , y/Erdos y/ Erdos}<br />

CSE, IIT <strong>Kharagpur</strong><br />

5


Unification<br />

UNIFY(p,q) = θ where SUBST(θ,p) SUBST( ,p) = SUBST(θ,q)<br />

SUBST( ,q)<br />

Examples:<br />

UNIFY( Knows(Erdos<br />

Knows( Erdos, , x), Knows(y, Father(y)))<br />

= { y/Erdos y/ Erdos, , x/Father(Erdos<br />

x/Father( Erdos) ) }<br />

UNIFY( Knows(Erdos<br />

Knows( Erdos, , x), Knows(x, Godel)) Godel))<br />

= F<br />

We require the most general unifier<br />

CSE, IIT <strong>Kharagpur</strong><br />

6


Reasoning with Horn Logic<br />

We can convert Horn sentences to a<br />

canonical form and then use generalized<br />

Modus Ponens with unification.<br />

We skolemize existential formulas and<br />

remove the universal ones<br />

This gives us a conjunction <strong>of</strong> clauses, that<br />

are inserted in the KB<br />

Modus Ponens help us in inferring new<br />

clauses<br />

Forward and backward chaining<br />

CSE, IIT <strong>Kharagpur</strong><br />

7


Completeness issues<br />

Reasoning with Modus Ponens is incomplete<br />

Consider the example –<br />

CSE, IIT <strong>Kharagpur</strong><br />

∀x x P(x) ⇒ Q(x) ∀x x ¬P(x) P(x) ⇒ R(x)<br />

∀x x Q(x) ⇒ S(x) ∀x x R(x) ⇒ S(x)<br />

We should be able to conclude S(A)<br />

The problem is that ∀x x ¬P(x) P(x) ⇒ R(x) cannot<br />

be converted to Horn form, and thus cannot<br />

be used by Modus Ponens<br />

8


Godel’s Completeness Theorem<br />

For first-order first order logic, any sentence that is<br />

entailed by another set <strong>of</strong> sentences can be<br />

proved from that set<br />

Godel did not suggest a pro<strong>of</strong> procedure<br />

In 1965 Robinson published his resolution<br />

algorithm<br />

Entailment in first-order first order logic is semi-decidable,<br />

semi decidable,<br />

that is, we can show that sentences follow from<br />

premises if they do, but we cannot always show if<br />

they do not.<br />

CSE, IIT <strong>Kharagpur</strong><br />

9


[<br />

The validity problem <strong>of</strong> first-order first order logic<br />

n<br />

[Church] The validity problem <strong>of</strong> the first-<br />

order predicate calculus is partially solvable.<br />

Consider the following formula:<br />

∧<br />

i =<br />

1<br />

∧<br />

p<br />

∀<br />

(<br />

x<br />

⇒<br />

f<br />

i<br />

∀<br />

∃<br />

CSE, IIT <strong>Kharagpur</strong><br />

(<br />

a<br />

y<br />

z<br />

),<br />

[<br />

p<br />

p<br />

g<br />

(<br />

(<br />

i<br />

x<br />

z<br />

(<br />

,<br />

a<br />

,<br />

z<br />

y<br />

))<br />

)<br />

)<br />

⇒<br />

n<br />

∧<br />

i = 1<br />

p<br />

(<br />

f<br />

i<br />

(<br />

x<br />

),<br />

g<br />

i<br />

(<br />

x<br />

))]]<br />

10


Resolution<br />

Generalized Resolution Rule:<br />

For atoms p i, , qi, , ri, , si, , where Unify(p Unify( j, , qk) ) = θ, ,<br />

we have:<br />

s1<br />

∧ ... ∧ s<br />

SUBST(<br />

θ<br />

,<br />

p<br />

1<br />

p<br />

CSE, IIT <strong>Kharagpur</strong><br />

1<br />

∧ ... p ... ∧ p<br />

∧ ... p<br />

⇒<br />

r<br />

1<br />

j −1<br />

j<br />

∧<br />

n 3<br />

∨ ... r<br />

p<br />

n 2<br />

j + 1<br />

n1<br />

⇒ q<br />

1<br />

⇒<br />

r<br />

... ∧ p<br />

∨ ... q<br />

k −1<br />

1<br />

n1<br />

∨ ... r<br />

k<br />

∧ s<br />

∨ q<br />

1<br />

k + 1<br />

n 2<br />

∨ ... q ... ∨ q<br />

n 4<br />

∧ ... s<br />

n 3<br />

∨ ... ∨ q<br />

n 4<br />

)<br />

11


Our earlier example<br />

CSE, IIT <strong>Kharagpur</strong><br />

P(w) ⇒ Q(w) Q(y) ⇒ S(y)<br />

{y / w}<br />

P(w) ⇒ S(w)<br />

{w / x}<br />

True ⇒ P(x) ∨ R(x)<br />

True ⇒ S(x) ∨ R(x) R(z) ⇒ S(z)<br />

{x/A, z/A}<br />

True ⇒ S(A)<br />

12


Conversion to Normal Form<br />

A formula is said to be in clause form if it is <strong>of</strong><br />

the form:<br />

∀x1 ∀x2 … ∀xn [C 1 ∧ C2 ∧ … ∧ Ck ]<br />

All first-order first order logic formulas can be converted<br />

to clause form<br />

We shall demonstrate the conversion on the<br />

formula:<br />

CSE, IIT <strong>Kharagpur</strong><br />

∀x x {p(x) ⇒ ∃z z { ¬∀y ¬∀y<br />

[q(x,y) ⇒ p(f(x 1))] ))]<br />

∧ ∀y y [q(x,y) ⇒ p(x)] }}<br />

13


Conversion to Normal Form<br />

Step1: Take the existential closure and<br />

eliminate redundant quantifiers. This<br />

introduces ∃x1 and eliminates ∃z, z, so:<br />

CSE, IIT <strong>Kharagpur</strong><br />

∀x x {p(x) ⇒ ∃z { ¬∀y ¬∀y<br />

[q(x,y) ⇒ p(f(x p(f( 1))] ))]<br />

∧ ∀y y [q(x,y) ⇒ p(x)] }}<br />

∃x1 ∀x x {p(x) ⇒ { ¬∀y ¬∀y<br />

[q(x,y) ⇒ p(f(x 1))] ))]<br />

∧ ∀y y [q(x,y) ⇒ p(x)] }}<br />

14


Conversion to Normal Form<br />

Step 2: Rename any variable that is<br />

quantified more than once. y has been<br />

quantified twice, so:<br />

CSE, IIT <strong>Kharagpur</strong><br />

∃x1 ∀x x {p(x) ⇒ { ¬∀y ¬∀y<br />

[q(x,y) ⇒ p(f(x 1))] ))]<br />

∧ ∀y y [q(x,y) ⇒ p(x)] }}<br />

∃x1 ∀x x {p(x) ⇒ { ¬∀y ¬∀y<br />

[q(x,y) ⇒ p(f(x 1))] ))]<br />

∧ ∀z z [q(x,z) ⇒ p(x)] }}<br />

15


Conversion to Normal Form<br />

Step 3: Eliminate implication. implication<br />

CSE, IIT <strong>Kharagpur</strong><br />

∃x1 ∀x x {p(x) ⇒ { ¬∀y ¬∀y<br />

[q(x,y) ⇒ p(f(x 1))] ))]<br />

∧ ∀z z [q(x,z) ⇒ p(x)] }}<br />

∃x1 ∀x x {¬p(x) { p(x) ∨ { ¬∀y ¬∀y<br />

[¬q(x,y) [ q(x,y) ∨ p(f(x 1))] ))]<br />

∧ ∀z z [¬q(x,z) [ q(x,z) ∨ p(x)] }}<br />

16


Conversion to Normal Form<br />

CSE, IIT <strong>Kharagpur</strong><br />

Step 4: Move ¬ all the way inwards. inwards<br />

∃x1 ∀x x {¬p(x) { p(x) ∨ { ¬∀y ¬∀y<br />

[¬q(x,y) [ q(x,y) ∨ p(f(x 1))] ))]<br />

∧ ∀z z [¬q(x,z) [ q(x,z) ∨ p(x)] }}<br />

∃x1 ∀x x {¬p(x) { p(x) ∨ {∃y y [q(x,y) ∧ ¬p(f(x p(f(x1))] ))]<br />

∧ ∀z z [¬q(x,z) [ q(x,z) ∨ p(x)] }}<br />

17


Conversion to Normal Form<br />

Step 5: Push the quantifiers to the right.<br />

CSE, IIT <strong>Kharagpur</strong><br />

∃x1 ∀x x {¬p(x) { p(x) ∨ {∃y y [q(x,y) ∧ ¬p(f(x p(f(x1))] ))]<br />

∧ ∀z z [¬q(x,z) [ q(x,z) ∨ p(x)] }}<br />

∃x1 ∀x x {¬p(x) { p(x) ∨ {[∃y {[ y q(x,y) ∧ ¬p(f(x p(f(x1))] ))]<br />

∧ [∀z z ¬q(x,z) q(x,z) ∨ p(x)] }}<br />

18


Conversion to Normal Form<br />

Step 6: Eliminate existential quantifiers<br />

(Skolemization<br />

Skolemization). ).<br />

CSE, IIT <strong>Kharagpur</strong><br />

Pick out the leftmost ∃y y B(y) and replace it<br />

by B(f(x i1, i1,<br />

x i2 ,…, , xin)), in)),<br />

where:<br />

a) xi1, i1,<br />

x i2 ,…, , xin in are all the distinct free<br />

variables <strong>of</strong> ∃y y B(y) that are universally<br />

quantified to the left <strong>of</strong> ∃y y B(y), and<br />

b) F is any n-ary n ary function constant which<br />

does not occur already<br />

19


Conversion to Normal Form<br />

Skolemization:<br />

Skolemization<br />

CSE, IIT <strong>Kharagpur</strong><br />

∃x1 ∀x x {¬p(x) { p(x) ∨ {[∃y {[ y q(x,y) ∧ ¬p(f( p(f(x1))] ))]<br />

∧ [∀z z ¬q(x,z) q(x,z) ∨ p(x)] }}<br />

∀x x {¬p(x) { p(x) ∨ {[q(x,g(x)) {[ q(x,g(x)) ∧ ¬p( p(f(a) f(a))] )]<br />

∧ [∀z z ¬q(x,z) q(x,z) ∨ p(x)] }}<br />

20


Conversion to Normal Form<br />

Step 7: Move all universal quantifiers to the<br />

left<br />

CSE, IIT <strong>Kharagpur</strong><br />

∀x x {¬p(x) { p(x) ∨ {[q(x,g(x)) ∧ ¬p(f(a))] p(f(a))]<br />

∧ [∀z ¬q(x,z) q(x,z) ∨ p(x)] }}<br />

∀x x ∀z {¬p(x) p(x) ∨ {[q(x,g(x)) ∧ ¬p(f(a))] p(f(a))]<br />

∧ [¬q(x,z) q(x,z) ∨ p(x)] }}<br />

21


Conversion to Normal Form<br />

Step 8: Distribute ∧ over ∨.<br />

CSE, IIT <strong>Kharagpur</strong><br />

∀x x ∀z z {[¬p(x) {[ p(x) ∨ q(x,g(x))]<br />

∧ [¬p(x) p(x) ∨ ¬p(f(a))] p(f(a))]<br />

∧ [¬p(x) p(x) ∨ ¬q(x,z) q(x,z) ∨ p(x)] }<br />

Step 9: (Optional) Simplify<br />

∀x x {[¬p(x) {[ p(x) ∨ q(x,g(x))] ∧ ¬p(f(a)) p(f(a)) }<br />

22


Resolution Refutation Pro<strong>of</strong>s<br />

In refutation pro<strong>of</strong>s, we add the negation <strong>of</strong><br />

the goal to the set <strong>of</strong> clauses and then<br />

attempt to deduce False<br />

CSE, IIT <strong>Kharagpur</strong><br />

23


Example<br />

Harry, Ron and Draco are students <strong>of</strong> the<br />

Hogwarts school for wizards<br />

Every student is either wicked or is a good<br />

Quiditch player, or both<br />

No Quiditch player likes rain and all wicked<br />

students like potions<br />

Draco dislikes whatever Harry likes and likes<br />

whatever Harry dislikes<br />

Draco likes rain and potions<br />

Is there a student who is good in Quiditch but<br />

not in potions?<br />

CSE, IIT <strong>Kharagpur</strong><br />

24


Resolution Refutation Pro<strong>of</strong>s<br />

Example:<br />

Jack owns a dog<br />

Every dog owner is an animal lover<br />

No animal lover kills an animal<br />

Either Jack or Curiosity killed the cat, who<br />

is named Tuna<br />

Goal: Did curiosity kill the cat?<br />

CSE, IIT <strong>Kharagpur</strong><br />

We will add ¬Kills(Curiosity, Kills(Curiosity, Tuna) and try<br />

to deduce False<br />

25

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

Saved successfully!

Ooh no, something went wrong!