first order logic (1)

Upload: durai-raj-kumar

Post on 04-Jun-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 First Order Logic (1)

    1/29

    Inference in first-order logic I

    CIS 391Introduction to Artificial Intelligence

    AIMA Chapter 9.1-9.2 (through p. 278)

    Chapter 9.5 (through p. 300)

  • 8/13/2019 First Order Logic (1)

    2/29

    CIS 391 - Intro to AI 2

    Outline

    Reducing first-order inference to propositionalinference

    Unification

    Generalized Modus Ponens

  • 8/13/2019 First Order Logic (1)

    3/29

    CIS 391 - Intro to AI 3

    Universal instantiation (UI)

    Every instantiation of a universally quantified sentence isentailed by it:

    v Subst({v/g}, )

    for any variable vand ground term g

    E.g., x King(x) Greedy(x) Evil (x)yields any or allof:

    King(John) Greedy(John) Evil(John)

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

    Evil(Father(John))

  • 8/13/2019 First Order Logic (1)

    4/29

    CIS 391 - Intro to AI 4

    Existential instantiation (EI)

    For any sentence , variable v, and constantsymbol k that does no t appear elsewherein theknowledge base:

    v

    Subst({v/k}, )

    E.g., x Crown(x) OnHead(x,John)yields:Crown(C1) OnHead(C1,John)

    provided C1is a new constant symbol, called aSkolem constant

  • 8/13/2019 First Order Logic (1)

    5/29

    CIS 391 - Intro to AI 5

    Existential Instantiation cont inued

    UI can be applied several times to addnewsentences

    the new KB is logically equivalent to the old

    EI can be applied once to replacethe

    existential sentence

    the new KB is not equivalent to the old

    but it is satisfiable iff the old KB wassatisfiable

  • 8/13/2019 First Order Logic (1)

    6/29

  • 8/13/2019 First Order Logic (1)

    7/29

    CIS 391 - Intro to AI 7

    Reduction contd.

    Claim: Every FOL KB can be propositionalized soas to preserve entailment

    (A ground sentence is entailed by new KB iff entailed by

    original KB)

    Idea: propositionalize KB and query, applyresolution, return result

    Problem: with function symbols, there are

    infinitely many ground terms, e.g., Father(Father(Father(John)))

  • 8/13/2019 First Order Logic (1)

    8/29

    CIS 391 - Intro to AI 8

    Reduction contd.

    Theorem: Herbrand (1930). If a sentence is entailed by anFOL KB, it is entailed by a f inite subset of thepropositionalized KB

    Idea: For n= 0 to docreate a propositional KB by instantiating with depth-nterms

    see if is entailed by this KB

    Problem: works if is entailed, loops if is not entailed

    Theorem: Turing (1936), Church (1936) Entailment for FOL is

    semidecidable(algorithms exist that say yes to everyentailed sentence, but no algorithm exists that also says noto every nonentailed sentence.)

  • 8/13/2019 First Order Logic (1)

    9/29

    CIS 391 - Intro to AI 9

    Problems withpropositionalization

    1. Propositionalization seems to generate lots of irrelevantsentences.

    E.g., from:

    x King(x) Greedy(x) Evil (x)King(John)

    y Greedy(y)Brother(Richard,John)

    it seems obvious that Evil(John),but propositionalization

    produces lots of facts such as Greedy(Richard)that are irrelevant

    2. With p k-ary predicates and nconstants, there are pnk

    instantiations.

    With function symbols, it gets much, much worse!

  • 8/13/2019 First Order Logic (1)

    10/29

    CIS 391 - Intro to AI 10

    Unification

    We can get the inference Evil(John) immediately if we can find a

    substitution such that King(x)and Greedy(x)match

    King(John)and Greedy(y)

    = {x/John,y/John}works

    Unify(,) = if =

    p q Knows(John,x) Knows(John,Jane)

    Knows(John,x) Knows(y,OJ)

    Knows(John,x) Knows(y,Mother(y))Knows(John,x) Knows(x,OJ)

  • 8/13/2019 First Order Logic (1)

    11/29

    CIS 391 - Intro to AI11

    Unification

    We can get the inference Evil(John) immediately if we can find a

    substitution such that King(x)and Greedy(x)match

    King(John)and Greedy(y)

    = {x/John,y/John}works

    Unify(,) = if =

    p q Knows(John,x) Knows(John,Jane) {x/Jane}}

    Knows(John,x) Knows(y,OJ)

    Knows(John,x) Knows(y,Mother(y))Knows(John,x) Knows(x,OJ)

  • 8/13/2019 First Order Logic (1)

    12/29

    CIS 391 - Intro to AI12

    Unification

    We can get the inference Evil(John) immediately if we can find a

    substitution such that King(x)and Greedy(x)match

    King(John)and Greedy(y)

    = {x/John,y/John}works

    Unify(,) = if =

    p q Knows(John,x) Knows(John,Jane) {x/Jane}}

    Knows(John,x) Knows(y,OJ) {x/OJ,y/John}}

    Knows(John,x) Knows(y,Mother(y))Knows(John,x) Knows(x,OJ)

  • 8/13/2019 First Order Logic (1)

    13/29

  • 8/13/2019 First Order Logic (1)

    14/29

    CIS 391 - Intro to AI14

    Unification

    We can get the inference Evil(John) immediately if we can find a

    substitution such that King(x)and Greedy(x)match

    King(John)and Greedy(y)

    = {x/John,y/John}works

    Unify(,) = if =

    p q Knows(John,x) Knows(John,Jane) {x/Jane}}

    Knows(John,x) Knows(y,OJ) {x/OJ,y/John}}

    Knows(John,x) Knows(y,Mother(y)) {y/John,x/Mother(John)}}Knows(John,x) Knows(x,OJ) fai l

  • 8/13/2019 First Order Logic (1)

    15/29

    CIS 391 - Intro to AI15

    Unification

    We can get the inference Evil(John) immediately if we can find a

    substitution such that King(x)and Greedy(x)match

    King(John)and Greedy(y)

    = {x/John,y/John}works

    Unify(,) = if =

    p q Knows(John,x) Knows(John,Jane) {x/Jane}}

    Knows(John,x) Knows(y,OJ) {x/OJ,y/John}}

    Knows(John,x) Knows(y,Mother(y)) {y/John,x/Mother(John)}}Knows(John,x) Knows(x,OJ) fai l

    Standardizing apart eliminates overlap of variables, e.g.,

    Knows(z17,OJ)

  • 8/13/2019 First Order Logic (1)

    16/29

    CIS 391 - Intro to AI16

    Unification

    To unify Knows(John ,x) and Knows(y,z),= {y/John , x/z }or = {y/John , x/John , z/John }

    The first unifier is more generalthan the second.

    There is a single most general unifier(MGU) thatis unique up to renaming of variables.

    MGU = { y/John, x/z }

  • 8/13/2019 First Order Logic (1)

    17/29

    CIS 391 - Intro to AI17

    The unification algorithm

  • 8/13/2019 First Order Logic (1)

    18/29

    CIS 391 - Intro to AI18

    The unification algorithm

  • 8/13/2019 First Order Logic (1)

    19/29

    CIS 391 - Intro to AI19

    Generalized Modus Ponens (GMP)

    p1

    ', p2

    ', , pn

    ', ( p1

    p2

    pn

    q)q

    p1'is King(John) p1 is King(x)

    p2'is Greedy(y) p2is Greedy(x)is {x/John,y/John} qis Evil(x)q is Evi l(John)

    GMP used with KB of defini te clauses (exactlyonepositive

    literal)

    All variables assumed universally quantified

    wherepi'= pifor all i

  • 8/13/2019 First Order Logic (1)

    20/29

    CIS 391 - Intro to AI20

    Soundness of GMP

    Need to show that

    p1', , pn', (p1 pnq) qprovided that pi '= pifor all i

    Lemma: For any definite clause p, we have p pby UI

    1. (p1 pnq) (p1 pnq)= (p1 pnq)2. p1', , pn' p1' pn' p1' pn'3. From 1 and 2, qfollows by ordinary Modus Ponens

  • 8/13/2019 First Order Logic (1)

    21/29

    CIS 391 - Intro to AI21

    Resolution: brief summary

    Full first-order version:

    1 k, 1 n(1 i-1 i+1 k 1 j-1 j+1 n)where Unify(i, j) = . The two clauses are assumed to be standardized apart so that

    they share no variables.

    For example,

    Rich(x) Unhappy(x)Rich(Ken)

    Unhappy(Ken)with = {x/Ken}

    Apply resolution steps to CNF(KB ); complete for FOL

  • 8/13/2019 First Order Logic (1)

    22/29

    CIS 391 - Intro to AI22

    Conversion to CNF for FOL

    Everyone who loves all animals is loved by someone:x [ y An imal(y) Lo ves(x,y)] [y Loves(y,x)]

    1. Eliminate biconditionals and implicationsx [y Animal(y) Loves(x,y)] [y Loves(y,x)]

    2. Move inwards: x p x p, x p x px [y (Animal(y) Loves(x,y))] [y Loves(y,x)]

    x [y Animal(y) Loves(x,y)] [y Loves(y,x)]

    x [y Animal(y) Loves(x,y)] [y Loves(y,x)]

  • 8/13/2019 First Order Logic (1)

    23/29

    CIS 391 - Intro to AI23

    Conversion to CNF contd.

    3. Standardize variables: each quantifier should use adifferent onex [y An imal(y) Loves(x,y)] [z Loves(z,x)]

    4. Skolemize: a more general form of existentialinstantiation.

    Each existential variable is replaced by a Skolem functionof theenclosing universally quantified variables:x [Animal(F(x)) Loves(x,F(x))] Loves(G(x),x)

    5. Drop universal quantifiers:[Animal(F(x)) Loves(x,F(x))] Loves(G(x),x)

    6. Distribute over :[Animal(F(x)) Lov es(G(x),x)] [Loves(x,F(x)) Loves(G(x),x)]

  • 8/13/2019 First Order Logic (1)

    24/29

    CIS 391 - Intro to AI24

    Example knowledge base

    The law says that it is a crime for an American tosell weapons to hostile nations. The country

    Nono, an enemy of America, has some missiles,

    and all of its missiles were sold to it by Colonel

    West, who is American.

    Prove that Col. West is a criminal

  • 8/13/2019 First Order Logic (1)

    25/29

    CIS 391 - Intro to AI25

    Example knowledge base contd.

    ... it is a crime for an American to sell weapons to hostile nations:

    American(x) Weapon(y) Sells(x,y,z) Hostile(z) Criminal(x)

    Nono has some missiles, i.e., x Owns(Nono,x) Missile(x):Owns(Nono,M1) and Missile(M1)

    all of its missiles were sold to it by Colonel West

    Missile(x) Owns(Nono,x) Sells(West,x,Nono)

    Missiles are weapons:Missile(x) Weapon(x)

    An enemy of America counts as "hostile:Enemy(x,America) Hostile(x)

    West, who is American American(West)

    The country Nono, an enemy of America Enemy(Nono,America)

  • 8/13/2019 First Order Logic (1)

    26/29

    CIS 391 - Intro to AI26

    Resolution proof: definite clauses

  • 8/13/2019 First Order Logic (1)

    27/29

    CIS 391 - Intro to AI

    27

    Example proof: Did Curiosity kill the cat?

    Jack owns a dog. Every dog owner is an animal lover. Noanimal lover kills an animal. Either Jack or Curiosity killedthe cat, who is named Tuna. Did Curiosity kill the cat?

    The axioms can be represented as follows:

    A. (x) Dog(x) ^ Owns(Jack,x)

    B. (x) ((y) Dog(y) ^ Owns(x, y)) => AnimalLover(x)

    C. (x) AnimalLover(x) => (y) Animal(y) => ~Kills(x,y)

    D. Kills(Jack,Tuna) Kills(Curiosity,Tuna)

    E. Cat(Tuna)

    F. (x) Cat(x) => Animal(x)

    (This and next 2 sl ides adapted from

    CMSC421Fall 2006, Univ . of Maryland)

  • 8/13/2019 First Order Logic (1)

    28/29

    CIS 391 - Intro to AI

    28

    Example: Did Curiosity kill the cat?1. Dog(spike)

    2. Owns(Jack,spike)

    3. ~Dog(y) v ~Owns(x, y) v AnimalLover(x)

    4. ~AnimalLover(x1) v ~Animal(y1) v ~Kills(x1,y1)

    5. Kills(Jack,Tuna) v Kills(Curiosity,Tuna)

    6. Cat(Tuna)

    7. ~Cat(x2) v Animal(x2)

  • 8/13/2019 First Order Logic (1)

    29/29

    CIS 391 - Intro to AI

    29

    1. Dog(spike)

    2. Owns(Jack,spike)

    3. ~Dog(y) v ~Owns(x, y) v AnimalLover(x)

    4. ~AnimalLover(x1) v ~Animal(y1) v ~Kills(x1,y1)

    5. Kills(Jack,Tuna) v Kills(Curiosity,Tuna)

    6. Cat(Tuna)

    7. ~Cat(x2) v Animal(x2)

    8. ~Kills(Curiosity,Tuna) negated goal

    9. Kills(Jack,Tuna) 5,8

    10. ~AnimalLover(Jack) V ~Animal(Tuna) 9,4 x1/Jack,y1/Tuna

    11. ~Dog(y) v ~Owns(Jack,y) V ~Animal(Tuna) 10,3 x/Jack

    12. ~Owns(Jack,spike) v ~Animal(Tuna) 11,1

    13. ~Animal(Tuna) 12,2

    14. ~Cat(Tuna) 13,7 x2/Tuna

    15. False 14,6

    Example: Did Curiosity kill the cat?