770 likes | 852 Views
INFERENCE IN FIRST ORDER LOGIC. S UBST (). S UBST () is a method of substituting particular instances for variables (or vice versa). The syntax is as follows: S UBST ({ v / g }, ) v is some variable, or unknown
E N D
SUBST() • SUBST() is a method of substituting particular instances for variables (or vice versa). • The syntax is as follows: SUBST({v/g}, ) v is some variable, or unknown g is a ground term, a term that contains no variables (i.e. a constant symbol such as e or pi) is a sentence in First-Order logic Thus, the purpose of using the SUBST for a sentence , is to replace a variable v with some ground term g.
Universal Elimination • The purpose of Universal Elimination is to remove all occurrences of the variable v, and replace them with the more specific ground term g. • Which can be written: For any sentence , variable v, and ground term g: v, --------------------- SUBST({v/g}, )
An example of Universal Elimination could be: • : v, Loves(v, A.I.) • Now substitute the ground term ‘Rose’ for v: • SUBST({v/Rose}, ) • And you’re left with: • Loves(Rose, A.I.)
Why does this work? • Think of Universal Elimination as And-Elimination (a^b^c |- a) • Thus, Loves(v, A.I.) represents all instances of people who love A.I. • If the knowledge base consisting of people who love A.I. was comprised of Rose, James, Maggie, and Neil we would have (Rose ^ James ^ Maggie ^ Neil). • Using And-Elimination, we can eliminate James, Maggie, and Neil, and then conclude that Rose does in fact love A.I.
Existential Elimination • The purpose of Existential Elimination, is to give a specific instance a name or symbol that does not already appear in our knowledge base. • The definition is as follows: For any sentence , variable v, and constant symbol k that does not appear elsewhere in the knowledge base: v, ---------------------- SUBST({v/k}, )
An example of Existential Elimination could be: • : There exists a number that is equal to the circumference of a circle divided by its diameter. • Thus, v, Satisfies(v, ) means: there exists some number v which satisfies the equation specified by . • Now, we would like to give v a more specific name, so we might choose the symbol . • So, SUBST({v/ }, ) • And we’re left with: • Satisfies(, ), which reads: is a number which is equal to the circumference of a circle divided by its diameter.
Existential Elimination • It is very important that does not already appear in our knowledge base. • As it would be a large mistake to have two different numbers which can be represented by the symbol .
Existential Introduction: • Existential Introduction is the exact opposite of Existential Elimination. • Its purpose is to replace some symbol or ground term, with a variable. • The definition is as follows: For any sentence , variable v that does not occur in , and ground term g that does occur in : --------------------------- v, SUBST({g/v}, )
An example of Existential Introduction could be: • is a number that is equal to the circumference of a circle divided by its diameter. • Satisfies(, ) • Now, we want to remove from this sentence, and make it more general. • So, we apply our SUBST • SUBST({ /v}, ) • And we’re left with: • v, Satisfies(v, ) which reads: There exists some number that is equal to the circumference of a circle divided by its diameter.
An example of Existential Introduction could be(1): • is a number that is equal to the circumference of a circle divided by its diameter. • Satisfies(, ) • Now, we want to remove from this sentence, and make it more general. • So, we apply our SUBST • SUBST({ /v}, ) • And we’re left with: • v, Satisfies(v, ) which reads: There exists some number that is equal to the circumference of a circle divided by its diameter.
Existential Introduction(1): • Similarly to Existential Elimination, it is important that v does not already occur in the sentence . • And likewise, our ground term () must be in the knowledge base to begin with.
An example of Existential Introduction could be(crime): 1 - The law says that is a crimefor American 2 - to sell weapons to hostile nations. 3 - The country Nono,an enemy of America, 4 - has some missiles, and all of its missiles 5 - were sold to it by Colonel West,who is American
example of Existential(crime) "…it is a crime for an American to sell weapons to hostile nations ." (8_1) : x,y,z American(x) ^ Weapons(y)^ Nation(z) ^ Hostile(z) ^ Sells(x,y,z) Criminal(x)
example of Existential(crime) (8_2) : “None … has some missiles“:$x Owns (Nono,x)^Missile(x) (8_3) : “All of its missiles were sold to it by Colonel West“: $x Owns(Nono,x)^Missile(x) Sells(West,Nono,x)
example of Existential(crime) )8_4( : “ missile is a kind of weapon“: $Missile(x) Weapon(x) )8_5) : “Hostile is an enemy of America“: $Enemy (x,America)Hostile (x) (8_6) : “west,who is American.....“: $ American (West)
example of Existential(crime) (8_7) : ” The country Nono …": $ Nation(Nono) )8_8) : “ Nono ,an enemy of America…" $ Enemy(Nono,America) (8_9( : $ Nation(America) • From (8_2) and Existential Elimination: (8_10) : $ Owns(Nono,M1)^missile(M1)
example of Existential(crime) • From (8_10(, And ,(^) Elimination: (8_11 (: $ Owns(Nono,M1) • From (8_4( and Universal Elimination: )8_13( : $ Missile (M1)Weapon(M1)
example of Existential(crime) • From (8_12),(8_13 (,Modus Ponens(MP): (8_14( : $ Weapon(M1) • From (8_3), Universal Elimination(UE): (8_15) : $Owns(Nono,M1) ^ Missile(M1)Sells(West,Nono,M1)
example of Existential(crime) • From (8_15(,(8_10), MP: (8_16) : $ Sells(West,Nono,M1) • From (8-1), Universal E (3th): (8_17) : $ American (West) ^ Weapon(M1)^ Nation(Nono)^ Hostile (Nono)^ sells(West,Nono,M1)Criminal(West)
example of Existential(crime) • From(8_5), Universal Elimination: (8_18) : $ Enemy (Nono, America) Hostile (Nono) • From(8_18),(8_8),MP : (8_19) : $Hostile (Nono)
example of Existential(crime) • From (8_6),(8_7),(8_14),(8_16),(8_19) : (8_20) : $American (West)^ Weapon(M1)^ Nation(Nono)^ Hostile (Nono)^ Sells(West,Nono,M1) • From (8_17),(8_20),MP : (8_21) : $Criminal(West)
Generalized modus ponens • Generalized modus ponens enables us to take some sentences from a knowledge base and infer a new sentence in a single step. • It is an efficient improvement and is more powerful than the regular modus ponens. • The formula is: For atomic sentences pi, pi1, and q , where there is a substitution such that SUBST(, pi1) = SUBST(, pi), for all i: • p11,p21,...,pn1, (p1^p2^...^pn => q) ----------------------------------------- SUBST(theta, q)
example Example of generalized modus ponens of Existential(2) • p11,p21,...,pn1, (p1^p2^...^pn => q) ----------------------------------------- SUBST(theta, q) P1’ is Missile(M1) p1 is Missile(x) P2’ is Owns(y,M1) p2 is Owns(Nono,x) Theta is {x/M1 , y/Nono} q is Sells (West,Nono,x) • SUBST (theta,q) is Sells ( West,Nono, M1)
Canonical form • Canonical form for modus ponens requires that each sentence in KB be either an atomic sentence or an implication with a conjunction of atomic sentences on the left hand side and a single atom on the right. • Sentences in the canonical form are called Horn sentences.
Horn sentences • Sentences must be in Horn sentence form to use generalized modus ponens. • If all the sentences are horn sentences, then the KB is in Horn Normal Form. • We use and-elimination and existential-elimination to remove conjuncts and existential quantifiers. • Horn sentences are a useful class of sentences for which a polynomial-time inference procedure exists.
Unification • We use the routine UNIFY to take two atomic sentences q and p and return a substitution that would make q and p look the same. • This is how we found an appropriate substitution in the example of generalized modus ponens: • UNIFY(p , q) = , SUBST( , P ) = SUBST( , q )
Why generalized modus ponens are helpful Efficiency: • -it takes bigger steps, combining several small inferences into one. -In just one step it does what is required for -an And-Introduction -a Universal Elimination - and Modus Ponens • -it takes sensible steps - it uses substitutions that are guaranteed to help rather than randomly trying Universal Eliminators. The unification algorithm takes two sentences and returns a substitution that makes them look the same if such a substitution exists. • -it makes use of a pre-compilation step that converts all the sentences in the knowledge base into canonical form.
Unification Example • “John hates everyone he knows .” • Knows(John,x) Hates(John,x) • Knows(John,Jane) • Knows(y,Leonid) • Knows(y,Mother(y)) • Knows(x,Elizabeth)
Unification ExampleContinuance 1 _ UNIFY) Knows( John , x ) , Knows( John , Jane )) = { x / jane } 2_ UNIFY) Knows( John , x ) , Knows( John , Leonid )) = { x / Leonid , y / John} 3_ UNIFY) Knows( John , x ) , Knows( y , Mother (y))) = { y / John , x / Mother ( John ))} 4_ UNIFY) Knows( John , x ) , Knows( x , Leonid )) = fail [A point , in this state . We will see it, soon]
Renaming Renaming: Renaming is where you switch the variable inside a predicate, with another variable. Though after the renaming, the sentences must mean the same thing. Eg. A renaming of the sentence Watches(x, Movies) … Is: Watches(y, Movies) Though: Movies(x, x) and Movies(x, y) are not renamings of each other.
That point is here 4_ UNIFY) Knows( John , x 1) , Knows( x2 , Leonid )) ={x1 / Elizabeth , x2 / John } • x2 Knows( x2 , Elizabeth ) , x Knows( x , Elizabeth ) • Have unification sense
Unification Example( crime ) (8_22) : $American (x)^ Weapon(y)^ Nation(z)^ Hostile (z)^ Sells(x,z,y) Criminal (x)
Unification Example( crime ) (8_23) : $ Owns( Nono , M1) (8_24) : $ Missile( M1) (8_25) : $ Owns( Nono , x ) ^ Missile( x ) Sells( West , Nono ,x )
Unification Example( crime ) (8_26) : $ Missile( x ) Weapon ( x ) (8_27) : $ Enemy( x , America ) Hostile( x ) (8_28) : $ America ( West ) (8_29) : $ Nation ( Nono ) (8_30) : $ Enemy(Nono , America ) (8_31) : $ Nation (America)
Unification Example( crime ) • From (8_24),(8_26),MP : (8_32) : $ Weapon ( M1) From (8_28),(8_32),(8_29),(8_33),(8_34), (8_22), MP : (8_34) : $ Criminal ( west )
Comparing modus ponens with generalized modus ponens We get: (4) x person(x) using Universal Introduction on 2 (5) x,y eatFruit(x,y) using Universal Introduction on 3 (6) x,y person(x) ^eatFruit(x,y) using And Introduction on 4,5 (7) x healthy(x) using modus ponens on 1,6 (8) healthy(Bob) by Universal Elimination on • Using regular modus ponens: Given in the knowledge base: (1) x,y person(x) ^ eatFruit(x,y) => healthy(x) (2) person(Bob) (3) eatFruit(Bob, Mango)
Comparing modus ponens with generalized modus ponens • Using generalized modus ponens: Given in the knowledge base: (1) x,y person(x) ^ eatFruit(x,y) => healthy(x) (2) person(Bob) (3) eatFruit(Bob, Mango) We get: (4) healthy(Bob) using = {x/Bob, y/Mango}
Composition Composition: Another technique we need before we begin is the idea of a composition of substitutions. Compose(1, 2) returns a substitution, whose effect is identical to: Subst(Compose(1, 2), p) = Subst(2, Subst(1, p)) Eg. p = Watches(x, y), 1 = {x / Don}, 2 = {y / TV} Subst(2, Subst(1, p)) = Subst(2, Watches(Don, y)) = Watches(Don, TV). Subst(Compose(1, 2), p) = Subst( {x / Don, y / TV}, p) = Watches(Don, TV).
Forward Chaining Algorithm • This algorithm is used as a reasoning program. • And it is based upon the Generalized Modus Ponens • The algorithm takes sentences currently in the Knowledge Base and generates new conclusions that can be used to infer even more conclusions.
About Forward Chaining • Adds inputted sentences to the Knowledge Base • Uses Generalized Modus Ponens to attempt to infer new facts.
Second half of the Algorithm Procedure Find-And-Infer(KB, premises, conclusion, ) If premises = [] then Forward-Chain(KB, Subst(, conclusion)) else for each p’ in KB s.t. Unify(p’, Subst(, First(premises))) = 2do Find-And-Infer(KB, Rest(premises), conclusion, Compose(, 2)) end
First half of the Algorithm Procedure Forward-Chain(KB, p) If p or a renaming of p is in KBthen Return Add p to KB For each (p1^…^pn -> q) in KB s.t. I, Unify(pi,p) = succeeds do Find-And-Infer( KB, [p1,…, pi-1, Pi+1,…, pn], q, ) End
Forward Chaining Example(crime) (8_36) : $American (x)^ Weapon(y)^ Nation(z)^ Hostile (z)^ Sells(x,z,y) Criminal (x)
Forward Chaining Example(crime) (8_37) : $ Owns (Nono , x ) ^ Missile ( x ) Sells( West , Nono , x ) (8_38) : $ Missle ( x ) Weapon (x) (8_39) : $ Enemy ( x , America ) Hotile( x )
Forward Chaining Example(crime)Addtion Atomic Sentenes To kowledge Base(1) Step 1 : Compatiable with (8_36) defaulte 1_FORWARD _ CHAIN (KB , America (West)) FC unknowns another (8_36)’s defaultes then , fc return with no new inference Step 2 : Compatiable with (8_39) defaulte 2_FORWARD _ CHAIN (KB , Nation(Nono)) There are some lose defaulte then fc return Step 3 : Compatiable with (8_36) defaulte,and {x/Nono} 3_FORWARD _ CHAIN (KB , Enemy(Nono,America))
Forward Chaining Example(crime)Addtion Atomic Sentenes To kowledge Base(2) Step 4 : Compatiable with (8_36)’s default 4_FORWARD _ CHAIN (KB , Hostile(Nono)) Stop processing Step 5 : Compatiable with (8_37)’s default , and {x/ M1} 5_FORWARD _ CHAIN (KB , Owns(Nono,M1)) Stop processing Step 6 : Compatiable with (8_37)’s and (8_38)’s default 6_FORWARD _ CHAIN (KB , Missile(M1))
Forward Chaining Example(crime)Addtion Atomic Sentenes To kowledge Base(3)studing step 6 1_Step 6 : Compatiable with (8_37)’s default
Backward Chaining Algorithm • The same principle that applies for forward chaining, works in reveres for backward chaining. • How it works: • Start with something you wish to prove. • Find implication sentences that would allow you to conclude it. • From there try to establish the premise in turn. • In short it works the same as for the Generalized Modus Ponens, though in reverse.
The Algorithm pt. 1 Function Back-Chain(KB, q) returns a set of substitutions Back-Chain-List(KB, [q], {})