Anda di halaman 1dari 39

ICS-381 Principles of Artificial Intelligent Week 12 First-Order-Logic Inference in First-Order-Logic

Chapters 8-9

Dr.Tarek Helmy El-Basuny


DR. Tarek Helmy@KFUPM-ICS

First Order Logic / Predicate Logic


Problem of Propositional Logic FOL Syntax Universal Quantifiers Existential Quantifiers Connections between and Thinking in FOL Knowledge Engineering in FOL A Simple Family Tree KB by FOL Inference in FOL Universal Instantiation Existential Instantiation Universal Modus Ponens & Tollens Testing Validity with Diagrams Reducing First-Order Inference to Propositional Inference Quantified Inference Rules Resolution Refutation Converting FOL Sentences to CNF 2

DR. Tarek Helmy@KFUPM-ICS

FOL Inference

Inference rules for propositional logic apply to FOL as well



Modus Ponens, Resolution, etc.

Inference can be done by converting the knowledge base into propositional logic and using propositional logic inference methods. Every FOL KB can be propositionalized so as to preserve entailment. A ground sentence is entailed by new KB iff entailed by original KB. Universal Elimination Universal Instantiation Existential Elimination Existential Instantiation Generalized Modus Ponens (GMP)
3

New (sound) inference rules for use with quantifiers:


DR. Tarek Helmy@KFUPM-ICS

Propositional Logic Inference Rules


p ( p q) p pq
Addition ( p) (q) ( p q) p q pq Conjunction

pq p pq p
Simplification

[ q ( p q ) ] p
q pq p Modus P.

[ ( p q ) (q r ) ] ( p r )
pq qr pr

[ ( p q ) p ] q
pq p q
Disjunctive

[ ( p q ) ( p r ) ] ( q r )
pq p r q r

Hypothetical
DR. Tarek Helmy@KFUPM-ICS

Resolution
4

Examples

[p
It snows today If it snows today we go skiing Therefore: we go skiing

( p q )] q

p p q q

[( p q) (q r)] ( p r)
If it rains we do not have a barbeque today If we dont have a barbeque today, well have one tomorrow Therefore: If it rains today, well have a BBQ tomorrow.
DR. Tarek Helmy@KFUPM-ICS

p q q r p r

Resolution for Propositional Logic


Propositional resolution is a single sound inference rule that is applied to clauses. A clause is a disjunction of literals. i.e (p q r) is a clause.

Resolution:

(1 p), (2 p) (1 2)

Example,

(p q), (q r) ( p r)

DR. Tarek Helmy@KFUPM-ICS

Reduction to Propositional Inference


Suppose the KB contains just the following: x King(x) Greedy(x) Evil(x) King(John) Greedy(John) Brother(Richard,John) Instantiating the universal sentence in all possible ways, we have: King(John) Greedy(John) Evil(John) King(Richard) Greedy(Richard) Evil(Richard) King(John) Greedy(John) Brother(Richard,John) Propositionalization seems to generate lots of irrelevant sentences.

DR. Tarek Helmy@KFUPM-ICS

Universal Instantiation

If x P(x) is true, then P(c) is true, where c is any constant in the domain of x Example: x eats(Zead, x) eats(Zead, IceCream) The variable symbol can be replaced by any ground term,
A ground term is a term with no variables.

DR. Tarek Helmy@KFUPM-ICS

Universal Instantiation (UI)


We can infer any sentence obtained by substituting a ground term g for any variable v: v Subst({v/g}, ) x D, P(x); if aD; P(a).

If some property is true for everything in a domain, then it is true for any particular

thing in the domain. Example: All Italians are good cookers; If Tony is an Italian; Tony is a good cooker.

The variable symbol can be replaced by any ground term, i.e., any constant symbol or function symbol applied to ground terms only. E.g., x King(x) Greedy(x) Evil(x) yields:

King(John) Greedy(John) Evil(John) King(Richard) Greedy(Richard) Evil(Richard) King(Father(John)) Greedy(Father(John)) Evil(Father(John))

These three sentences are obtained with the substitution {x/John}, {x/Richard}, {x/Father(John))
9

DR. Tarek Helmy@KFUPM-ICS

Existential Instantiation

If P(c) is true, then x P(x) is inferred. Example eats(Zead, IceCream) x eats(Zead,x) All instances of the given constant symbol are replaced by the new variable symbol. Note that the variable symbol cannot already exist anywhere in the expression.

DR. Tarek Helmy@KFUPM-ICS

10

Existential Instantiation (EI)


For any sentence , variable v, and constant symbol k that does not appear elsewhere in the knowledge base: v Subst({v/k}, ) E.g., x Crown(x) OnHead(x,John) yields: Crown(C1) OnHead(C1,John) provided C1 is a new constant symbol, called a Skolem constant

DR. Tarek Helmy@KFUPM-ICS

11

Existential Elimination

From x P(x) infer P(c) Example: x eats(Zead, x) eats(Zead, Stuff) Note that the variable is replaced by a brand-new constant not occurring in this or any other sentence in the KB. Also known as skolemization; constant is a skolem constant In other words, we dont want to accidentally draw other inferences about it by introducing the constant Convenient to use this to reason about the unknown object, rather than constantly manipulating the existential quantifier.

DR. Tarek Helmy@KFUPM-ICS

12

Completeness of Inference Techniques


Truth Tabling

Is not complete for FOL because truth table size may be infinite Is not complete for FOL Generalized Modus Ponens is complete for KBs containing only Horn clauses Is complete for FOL

Generalized Modus Ponens


Resolution Refutation

DR. Tarek Helmy@KFUPM-ICS

13

Generalized Modus Ponens


Apply GMP reasoning to generalized rules: Combines And-Introduction, Universal-Elimination, and Modus Ponens E.g, from P(c) and Q(c) and x (P(x) ^ Q(x)) => R(x) derive R(c) x, if P(x) then Q(x); P(a) for a particular a; then Q(a).

Ex-1: For any right triangle, if one of the acute angles is x then the other acute angle is 90-x; Ex-2: In a right triangle, one of the angles is 35; The other acute angle is 55. Universal Modus Tollens x, if P(x) then Q(x); ~Q(a) for a particular a; ~P(a)

DR. Tarek Helmy@KFUPM-ICS

14

Example-1
Everyone in this AI class has takes the ICS 253 course Ahmed is in this class Therefore: Ahmed has takes the ICS 253 course

D(x) = x has takes a math class C(x) = x has takes a CS class. Premises:
x ( D ( x ) C ( x )) D ( Marla )

Conclusion: C ( Marla) Reasoning: x( D( x) C ( x))

D( Marla ) C ( Marla) D( Marla) C ( Marla)

Universal Instantiation Modus Ponens


15

DR. Tarek Helmy@KFUPM-ICS

Example-2
All movies produced by John Sayles are wonderful John Sayles produced a movie about coal-miners Therefore: there a wonderful movie about coal-miners.

s(x) = x is a movie by John Sayles c(x) = x is a movie about coalminers w(x) = x is a wonderful movie.

x( s ( x) w( x)) s ( z ) w( z ) arbitrary z
w( y ) for some y w( y ) c( y ) for some y x( w( x) c( x))

s ( x) c( x)) s ( y ) c( y ) for some y s ( y ) for some y c( y ) for some y

DR. Tarek Helmy@KFUPM-ICS

16

Example-3
If it does not rain or it is not foggy then the sailing race will go on and the lifesaving demonstration will go on. If the sailing is held, then the cup will be awarded and If the cup was not awarded imply it rained.

r = it rains f = it is foggy s = sailing race goes on l = lifesaving demonstration goes on. t = cup awarded.

(r f ) ( s l ) st t r
( r f ) ( s l ) ( s l ) (r f ) ( s l ) ( r f )
Want the conclusion r to be on the right side of the arrow
17

t st s

s l r f r

Combine premises as much as you can


DR. Tarek Helmy@KFUPM-ICS

Testing Validity by Diagrams


Ex: All integers are rational numbers; 5 is an integer; 5 is a rational number.

Integers 5 Rational numbers

Ex: All logicians are mathematicians; John is not a mathematician; John is not a logician. Ex: All Math majors are taking Math306; Bill is taking Math306; Bill is a Math major.
Bill

Logicians

Mathematicians

John

Math majors

Math306 class
DR. Tarek Helmy@KFUPM-ICS

18

Resolution Refutation/ Unification


Resolution refutation is an inferencing technique that requires a Conjunctive Normal Form (CNF) representation.

Any FOL KB can be converted into CNF. CNF: is a conjunction of clauses where:

a clause: is a disjunction of literals e.g. Hot(x) Warn(x) Cold(x)

Literal: an atom either positive or negative (negated) e.g. Happy(Sally), Rich(x)

DR. Tarek Helmy@KFUPM-ICS

19

Resolution Refutation: Proofs


Resolution proofs are a refutation technique:


to prove KB show that KB is unsatisfiable Unsatisfiable: if there does not exist any interpretation under which the sentence is true: if it is false in all models e.g., AA

Resolution refutation repeatedly combines two clauses to make a new one until the empty clause is derived.

The new clauses are called resolvents Empty clause: False, unsatisfiable, a contradiction

Entailment in FOL is only semidecidable:


Can prove if KB Cannot always prove that KB doesn't


20

DR. Tarek Helmy@KFUPM-ICS

Resolution Refutation: Short Example


KB: PhD(x) HighlyQualified(x) PhD(x) EarlyEarnings(x) HighlyQualified(x) Rich(x) EarlyEarnings(x) Prove: KB Rich(Me) 1. Negate query and convert to CNF. Rich(Me) 2. Add query to CNF KB. Must convert KB sentences above into CNF. 3. Infer a contradiction, i.e., False.
DR. Tarek Helmy@KFUPM-ICS

Rich(x)

21

Resolution Refutation: Converting FOL-KB to CNF

Replace implications: PhD(x) HighlyQualified(x) PhD(x) HighlyQualified(x) PhD(x) EarlyEarnings(x) PhD(x) EarlyEarnings(x) HighlyQualified(x) Rich(x) HighlyQualified(x) Rich(x) EarlyEarnings(x) Rich(x) EarlyEarnings(x) Rich(x) becomes becomes becomes? becomes?

DR. Tarek Helmy@KFUPM-ICS

22

Converting FOL-KB to CNF

1. Replace with equivalent (added step)


convert PQ to PQQP

Example:

x,y {Above(x,y) (OnTop(x,y) z{OnTop(x,z) Above(z,y)})}

Becomes?

x,y { [ Above(x,y) (OnTop(x,y) z{OnTop(x,z) Above(z,y)}) ] [ (OnTop(x,y) z{OnTop(x,z) Above(z,y)}) Above(x,y) ] }

DR. Tarek Helmy@KFUPM-ICS

23

Converting FOL-KB to CNF

2. Replace with equivalent


convert PQ to P Q
x,y {

[ Above(x,y) (OnTop(x,y) z{OnTop(x,z) Above(z,y)}) ]

[ (OnTop(x,y) z{OnTop(x,z) Above(z,y)}) Above(x,y) ] }

Becomes?
x,y { [ Above(x,y) (OnTop(x,y) z{OnTop(x,z) Above(z,y)}) ] [ (OnTop(x,y) z{OnTop(x,z) Above(z,y)}) Above(x,y) ] }

DR. Tarek Helmy@KFUPM-ICS

24

Converting FOL-KB to CNF


3. Reduce scope of to single literals convert P to P convert (P Q) to P Q convert (P Q) to P Q convert x P to x P convert x P to x P

(DNE) (de Morgan's) (de Morgan's)

x,y { [ Above(x,y) (OnTop(x,y) z{OnTop(x,z) Above(z,y)}) ] [ (OnTop(x,y) z{OnTop(x,z) Above(z,y)}) Above(x,y) ] } Highlighted part becomes in stages: (OnTop(x,y) z {OnTop(x,z) Above(z,y)}) (de Morgan's) z {OnTop(x,z) Above(z,y)} (x P to x P) { OnTop(x,z) Above(z,y)} (de Morgan's) Highlighted part result: (OnTop(x,y) z{ OnTop(x,z) Above(z,y)})
DR. Tarek Helmy@KFUPM-ICS

25

Converting FOL-KB to CNF


4. Standardize variables apart each quantifier must have a unique variable name which avoids confusion in steps 5 and 6 e.g. convert x P x Q to x P y Q

x,y { [ Above(x,y)(OnTop(x,y) z{OnTop(x,z) Above(z,y)}) ] [ (OnTop(x,y) z{OnTop(x,z) Above(z,y)}) Above(x,y) ] } Becomes? x,y { [ Above(x,y) (OnTop(x,y) z{OnTop(x,z) Above(z,y)}) ] [ (OnTop(x,y) w{OnTop(x,w) Above(w,y)}) Above(x,y) ] }

DR. Tarek Helmy@KFUPM-ICS

26

Converting FOL-KB to CNF 5. Eliminate existential quantifiers (Skolemize)


convert x P(x) to P(K) K must be a new constant (Skolem constant) convert x,y z P(x,y,z) to x,y P(x,y,F(x,y)) F() must be a new function (Skolem function) its arguments are all enclosing universally quantified variables

e.g. Everyone has a name. x Person(x) y Name(y) Has(x,y) wrong: x Person(x) Name(K) Has(x,K) Everyone has the same name K. Want everyone to have a name based on who they are. right: x Person(x) Name(F(x)) Has(x,F(x))
DR. Tarek Helmy@KFUPM-ICS

27

Converting FOL-KB to CNF Eliminate existential quantifiers (Skolemize) convert x,y z P(x,y,z) to x,y P(x,y,F(x,y)) F() must be a new function (Skolem function) its arguments are all enclosing universally quantified variables x,y { [ Above(x,y)(OnTop(x,y) z{OnTop(x,z) Above(z,y)}) ] [ (OnTop(x,y) w{OnTop(x,w) Above(w,y)}) Above(x,y) ] } Becomes? x,y { [Above(x,y)(OnTop(x,y)(OnTop(x,F(x,y))Above(F(x, y),y)))] [ (OnTop(x,y) w{OnTop(x,w) Above(w,y)}) Above(x,y) ] }
DR. Tarek Helmy@KFUPM-ICS

5.

28

Converting FOL-KB to CNF 6. Drop quantifiers after step 5. all variables are universally quantified e.g. convert x P(x) y Q(y) to P(x) Q(y) all variables in KB assumed to be universally quantified

x,y { [Above(x,y)(OnTop(x,y)(OnTop(x,F(x,y))Above(F(x, y),y)))] [(OnTop(x,y) w{OnTop(x,w) Above(w,y)}) Above(x,y)] } Becomes? [Above(x,y)(OnTop(x,y)(OnTop(x,F(x,y))Above(F(x, y),y)))] [(OnTop(x,y) (OnTop(x,w) Above(w,y))) Above(x,y)]
DR. Tarek Helmy@KFUPM-ICS

29

Converting FOL-KB to CNF


7. Distribute over done to get conjunction of disjunctions convert (P Q) R to (P R)(Q R)

[Above(x,y)(OnTop(x,y)(OnTop(x,F(x,y))Above(F(x,y),y)) )] [ (OnTop(x,y) (OnTop(x,w) Above(w,y))) Above(x,y) ] Highlighted part becomes in stages: given A (B (C D)) converts to A ((B C) (B D)) converts to (A (B C)) (A (B D)) Highlighted part result: [ (Above(x,y) (OnTop(x,y) OnTop(x,F(x,y)))) (Above(x,y) (OnTop(x,y) Above(F(x,y),y))) ]
DR. Tarek Helmy@KFUPM-ICS

30

Converting FOL-KB to CNF


7. Distribute over done to get conjunction of disjunctions convert (P Q) R to (P R)(Q R)

[Above(x,y)(OnTop(x,y)(OnTop(x,F(x,y))Above(F(x,y),y)) )] [(OnTop(x,y) (OnTop(x,w) Above(w,y))) Above(x,y)] Highlighted part becomes in stages: given (A B) C converts to (A C) (B C) Highlighted part result: [ (OnTop(x,y) Above(x,y) ) ((OnTop(x,w) Above(w,y)) Above(x,y) )
DR. Tarek Helmy@KFUPM-ICS

31

Converting FOL-KB to CNF 8. Flatten nested conjunctions and disjunctions convert (P Q) R to (P Q R) convert (P Q) R to (P Q R) [ (Above(x,y) (OnTop(x,y) OnTop(x,F(x,y)))) (Above(x,y) (OnTop(x,y) Above(F(x,y),y))) ] (OnTop(x,y) Above(x,y)) ((OnTop(x,w) Above(w,y)) Above(x,y))

Becomes? (Above(x,y) OnTop(x,y) OnTop(x,F(x,y))) (Above(x,y) OnTop(x,y) Above(F(x,y),y)) (OnTop(x,y) Above(x,y)) (OnTop(x,w) Above(w,y) Above(x,y))

DR. Tarek Helmy@KFUPM-ICS

32

Converting FOL-KB to CNF

9. Separate each conjunct (added step)


split at 's so each conjunct is now a CNF clause
(Above(x,y) OnTop(x,y) OnTop(x,F(x,y))) (Above(x,y) OnTop(x,y) Above(F(x,y),y)) (OnTop(x,y) Above(x,y)) (OnTop(x,w) Above(w,y) Above(x,y))

Becomes?
Above(x,y) OnTop(x,y) OnTop(x,F(x,y)) Above(x,y) OnTop(x,y) Above(F(x,y),y) OnTop(x,y) Above(x,y) OnTop(x,w) Above(w,y) Above(x,y)
33

DR. Tarek Helmy@KFUPM-ICS

Converting FOL-KB to CNF


10. Standardize variables apart in each clause (added)

so each clause in KB contains unique variable names during unification the standardize apart step need only be done on deduced clauses (i.e. resolvents)

Above(x,y) OnTop(x,y) OnTop(x,F(x,y)) Above(x,y) OnTop(x,y) Above(F(x,y),y) OnTop(x,y) Above(x,y) OnTop(x,w) Above(w,y) Above(x,y) Becomes?: Above(a,b) OnTop(a,b) OnTop(a,F(a,b)) Above(c,d) OnTop(c,d) Above(F(c,d),d) OnTop(e,f) Above(e,f) OnTop(g,h) Above(h,i) Above(g,i)

DR. Tarek Helmy@KFUPM-ICS

34

Summary

FOL is a more expressive language but inferencing is more complicated Inferencing in FOL can be done by:

Propositionalizing the FOL KB (universal and existential elimination rules) and using sound inference rules from PL

complete for FOL but impractical

Converting KB to Horn Normal Form and using Generalized Modus Ponens rule Converting KB to Conjunctive Normal Form and using Resolution Refutation

complete, all FOL KB can be converted to CNF

DR. Tarek Helmy@KFUPM-ICS

35

Summary: Converting FOL Sentences to CNF

1. Replace with equivalent (added step)


convert P Q

to P Q Q P

2. Replace with equivalent: convert P Q 3. Reduce scope of to single literals


to P Q

convert convert convert convert convert

P (P Q) (P Q) x P x P

to to to to to

P P Q P Q x P x P

(DNE) (de Morgan's) (de Morgan's)

4. Standardize variables apart


each quantifier must have a unique variable name avoids confusion in steps 5 and 6 e.g. convert x P x Q to x P y Q

DR. Tarek Helmy@KFUPM-ICS

36

Summary: Converting FOL Sentences to CNF 5. Eliminate existential quantifiers (Skolemize) convert x P(x) to P(C) (EE) C must be a new constant (Skolem constant) convert x,y z P(x,y,z) to x,y P(x,y,F(x,y)) F() must be a new function (Skolem function) with arguments that are all enclosing universally quantified variables 6. Drop quantifiers all variables are only universally quantified after step 5 e.g. convert x P(x) y Q(y) to P(x) Q(y) all variables in KB will be assumed to be universally quantified 7. Distribute over to get conjunction of disjunctions convert(P Q) R to(P R)(Q R)
DR. Tarek Helmy@KFUPM-ICS

37

Summary: Converting FOL Sentences to CNF

8. Flatten nested conjunctions and disjunctions


convert (P Q) R to (P Q R) convert (P Q) R to (P Q R)

9. Separate each conjunct (added step)


split at 's so each conjunct is now a CNF clause

10. Standardize variables apart in each clause (added step)


each clause in KB must contain unique variable names now during unification the standardize apart step need only be done on deduced clauses (i.e. resolvents)

DR. Tarek Helmy@KFUPM-ICS

38

The End!!

Thank you

Any Questions?

DR. Tarek Helmy@KFUPM-ICS

39

Anda mungkin juga menyukai