Inference.c15 16

download Inference.c15 16

of 49

Transcript of Inference.c15 16

  • 8/3/2019 Inference.c15 16

    1/49

    1

    CMSC 471

    Fall 2002

    Class #15/16Monday, October 21 / Wednesday, October 23

  • 8/3/2019 Inference.c15 16

    2/49

    2

    Todays class

    Inference in first-order logic

    Inference rules

    Forward chainingBackward chaining

    Resolution

    Unification

    Proofs Clausal form

    Resolution as search

  • 8/3/2019 Inference.c15 16

    3/49

    3

    Inference in

    First-Order Logic

    Chapter 9

    Some material adopted from notes

    by Andreas Geyer-Schulz

    and Chuck Dyer

  • 8/3/2019 Inference.c15 16

    4/49

    4

    Inference rules for FOL

    Inference rules for propositional logic apply to FOL as well

    Modus Ponens, And-Introduction, And-Elimination,

    New (sound) inference rules for use with quantifiers:

    Universal elimination

    Existential introduction

    Existential elimination

    Generalized Modus Ponens (GMP)

  • 8/3/2019 Inference.c15 16

    5/49

    5

    Universal elimination

    If (x) P(x) is true, then P(c) is true, where c is any

    constant in the domain of x

    Example:

    (x) eats(Ziggy, x) => eats(Ziggy, IceCream)

    The variable symbol can be replaced by any ground term,

    i.e., any constant symbol or function symbol applied to

    ground terms only

  • 8/3/2019 Inference.c15 16

    6/49

    6

    Existential introduction

    If P(c) is true, then (x) P(x) is inferred.

    Example

    eats(Ziggy, IceCream) => (x) eats(Ziggy, 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

  • 8/3/2019 Inference.c15 16

    7/497

    Existential elimination

    From (x) P(x) infer P(c)

    Example:

    (x) eats(Ziggy, x) => eats(Ziggy, Stuff)

    Note that the variable is replaced by a brand-new constantnot 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 otherinferences about it by introducing the constant

    Convenient to use this to reason about the unknown object,

    rather than constantly manipulating the existential quantifier

  • 8/3/2019 Inference.c15 16

    8/498

    Generalized Modus Ponens (GMP)

    Apply modus ponens 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) deriveR(c)

    General case: Given

    atomic sentences P1, P2, ..., PN

    implication sentence (Q1 ^ Q2 ^ ... ^ QN) => R Q1, ..., QN and R are atomic sentences

    substitution subst(, Pi) = subst(, Qi) for i=1,...,N

    Derive new sentence: subst(, R)

    Substitutions

    subst(, ) denotes the result of applying a set of substitutions defined by to the sentence

    A substitution list = {v1/t1, v2/t2, ..., vn/tn} means to replace all occurrencesof variable symbol vi by term ti

    Substitutions are made in left-to-right order in the list

    subst({x/IceCream, y/Ziggy}, eats(y,x)) = eats(Ziggy, IceCream)

  • 8/3/2019 Inference.c15 16

    9/499

    Automated inference for FOL

    Automated inference using FOL is harder than PL

    Variables can potentially take on an infinite number ofpossible values from their domains

    Hence there are potentially an infinite number of ways toapply the Universal-Elimination rule of inference

    Godel's Completeness Theorem says that FOLentailment is only semidecidable

    If a sentence is true given a set of axioms, there is aprocedure that will determine this

    If the sentence is false, then there is no guarantee that aprocedure will ever determine thisi.e., it may neverhalt

  • 8/3/2019 Inference.c15 16

    10/4910

    Completeness of some inference techniques

    Truth Tabling is not complete for FOL because truth table

    size may be infinite

    Natural Deduction is complete for FOL but is not practical

    because the branching factor in the search is too large

    (swe would have to potentially try every inference rule in

    every possible way using the set of known sentences)

    Generalized Modus Ponens is not complete for FOL

    Generalized Modus Ponens is complete for KBs containing

    only Horn clauses

  • 8/3/2019 Inference.c15 16

    11/4911

    Horn clauses

    A Horn clause is a sentence of the form:

    (x) P1(x) ^ P2(x) ^ ... ^ Pn(x) => Q(x)

    where

    there are 0 or more Pis and 0 or 1 Qthe Pis and Q are positive (i.e., non-negated) literals

    Equivalently: P1(x) P2(x) Pn(x)where the Pis are

    all atomic and at most one of them is positive

    Prolog is based on Horn clauses Horn clauses represent a subsetof the set of sentences

    representable in FOL

  • 8/3/2019 Inference.c15 16

    12/4912

    Horn clauses II

    Special cases

    P1 ^ P2^ Pn => Q

    P1 ^ P2^ Pn => false

    true => Q

    These are not Horn clauses:

    p(a) q(a)

    P ^ Q => R S

  • 8/3/2019 Inference.c15 16

    13/4913

    Unification

    Unification is a pattern-matching procedure Takes two atomic sentences, called literals, as input

    Returns Failure if they do not match and a substitution list, , if

    they do That is, unify(p,q) = means subst(, p) = subst(, q) for

    two atomic sentences,p and q

    is called the most general unifier (mgu)

    All variables in the given two literals are implicitlyuniversally quantified

    To make literals match, replace (universally quantified)variables by terms

  • 8/3/2019 Inference.c15 16

    14/4914

    Unification algorithm

    procedure unify(p, q, )

    Scan p and q left-to-right and find the first corresponding

    terms where p and q disagree (i.e., p and q not equal)

    If there is no disagreement, return (success!)

    Let r and s be the terms in p and q, respectively,where disagreement first occurs

    If variable(r) then {

    Let = union(, {r/s})

    Recurse and return unify(subst(, p), subst(, q), )

    } else if variable(s) then {

    Let = union(, {s/r})

    Recurse and return unify(subst(, p), subst(, q), )

    } else return Failure

    end

  • 8/3/2019 Inference.c15 16

    15/4915

    Unification: Remarks

    Unify is a linear-time algorithm that returns the most

    general unifier (mgu), i.e., the shortest-length substitution

    list that makes the two literals match.

    In general, there is not a unique minimum-length

    substitution list, but unify returns one of minimum length

    A variable can never be replaced by a term containing that

    variable

    Example: x/f(x) is illegal.

    This occurs check should be done in the above pseudo-

    code before making the recursive calls

  • 8/3/2019 Inference.c15 16

    16/49

  • 8/3/2019 Inference.c15 16

    17/49

  • 8/3/2019 Inference.c15 16

    18/49

    18

    Forward chaining algorithm

  • 8/3/2019 Inference.c15 16

    19/49

    19

    Backward chaining

    Backward-chaining deduction using GMP is complete for

    KBs containing only Horn clauses

    Proofs start with the goal query, find implications that

    would allow you to prove it, and then prove each of the

    antecedents in the implication, continuing to work

    backwards until you arrive at the axioms, which we know

    are true

    Example: Does Ziggy eat fish

    (x) eats(Ziggy, x) => eats(Ziggy, Stuff)

  • 8/3/2019 Inference.c15 16

    20/49

  • 8/3/2019 Inference.c15 16

    21/49

    21

    Completeness of GMP

    GMP (using forward or backward chaining) is complete forKBs that contain only Horn clauses

    It is not complete for simple KBs that contain non-Hornclauses

    The following entail that S(A) is true:(x) P(x) => Q(x)

    (x) ~P(x) => R(x)

    (x) Q(x) => S(x)

    (x) R(x) => S(x)

    If we want to conclude S(A), with GMP we cannot, sincethe second one is not a Horn form

    It is equivalent to P(x) R(x)

  • 8/3/2019 Inference.c15 16

    22/49

    22

    Resolution

    Resolution is a sound and complete inference procedure forFOL

    Resolution Rule for PL:

    P1 P2 ... Pn

    ~P1 Q2 ... Qm

    Resolvent: P2 ... v Pn Q2 ... Qm

    Examples

    P and ~P Q, derive Q (Modus Ponens)

    (~P Q) and (~Q R), derive ~P R

    P and ~P, derive False [contradiction!]

    (P Q) and (~P ~Q), derive True

  • 8/3/2019 Inference.c15 16

    23/49

    23

    FOL resolution

    Given sentencesP1 ... Pn

    Q1 ... Qm

    where each Pi and Qi is a literal, i.e., a positive or negated

    predicate symbol with its terms, if Pj and ~Qkunify withsubstitution list , then derive the resolvent sentence:

    subst(, P1... Pj-1 Pj+1 ... Pn Q1Qk-1 Qk+1... Qm)

    Example

    From clause P(x, f(a)) P(x, f(y)) Q(y) and clause ~P(z, f(a)) ~Q(z),

    derive resolvent clause P(z, f(y)) Q(y) ~Q(z)

    using = {x/z}

  • 8/3/2019 Inference.c15 16

    24/49

    24

    A resolution proof tree

  • 8/3/2019 Inference.c15 16

    25/49

    25

    Resolution refutation proofs

    Given a consistent set of axioms KB and goal sentence Q,show that KB |= Q

    Proof by contradiction: Add ~Q to KB and try to provefalse.

    i.e., (KB |- Q) (KB ~Q |- False)

    Resolution can establish that a given sentence Q is entailed byKB, but cant (in general) be used to generate all logicalconsequences of a set sentences

    Also, it cannot be used to prove that Q is not entailed by KB.

    Resolution wont always give an answer since entailment isonly semidecidable

    And you cant just run two proofs in parallel, one trying to prove Q andthe other trying to prove ~Q, since KB might not entail either one

  • 8/3/2019 Inference.c15 16

    26/49

    26

    Procedure

    procedure resolution(KB, Q)

    ;; KB is a set of consistent, true FOL sentences, Q is a goal sentence

    ;; to derive. Returns success if KB |- Q, and failure otherwise

    KB = union(KB, ~Q)

    while false KB do

    Choose 2 sentences, S1 and S2, in KB that contain

    literals that unify

    if none, return Failure

    resolvent = resolution-rule(S1, S2)KB = union(KB, resolvent)

    return Success

    end

  • 8/3/2019 Inference.c15 16

    27/49

    27

    Refutation resolution proof tree

  • 8/3/2019 Inference.c15 16

    28/49

    28

    Resolutionissues

    Resolution is only applicable to sentences in clausal form, e.g.

    P1 P2... Pn

    where Pis are negated or non-negated atomic predicatesIssues:

    Can we convert every FOL sentence into this form?

    Yesas we will see shortly

    How to pick which pair of sentences to resolve?

    Determines the search strategy of the prover more later

    How to pick which pair of literals, one from each sentence, to unify?

    Again, part of the search strategy

  • 8/3/2019 Inference.c15 16

    29/49

    29

    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)

  • 8/3/2019 Inference.c15 16

    30/49

    30

    Example proof, cont.

    Did Curiosity kill the cat? Convert to implicative normal form

    A1. [True => ] Dog(D)

    A2. [True => ] Owns(Jack,D)

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

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

    D. [True => ] Kills(Jack,Tuna) v Kills(Curiosity,Tuna)

    E. [True => ] Cat(Tuna)

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

    Add the query:

    Q. Kills(Curiosity, Tuna) => False

  • 8/3/2019 Inference.c15 16

    31/49

    31

    Example proof III

    Did Curiosity kill the cat?

    The Proof

    G. A1, B, {y/D}: Owns(x,D) => AnimalLover(x)

    H. A2, G, {x/Jack}: [True => ] AnimalLover(Jack)

    I. E,F, {x/Tuna}: [True => ] Animal(Tuna)

    J. C,I, {y/Tuna}: AnimalLover(x) ^ Kills(x,Tuna) =>False

    K. H,J: {x/Jack} Kills(Jack,Tuna) => FalseL. D,Q: [True => ] Kills(Jack,Tuna)

    M. L,K: [True => ] False

  • 8/3/2019 Inference.c15 16

    32/49

    32

    Curiosity Killed the Cat

  • 8/3/2019 Inference.c15 16

    33/49

    33

    Converting to clausal form

    The canonical (standard) form for resolution is

    Conjunctive Normal Form (conjunction of disjunctions),

    or equivalently, Implicative Normal Form (conjunction

    implies disjunction)

    Example: If Johns house is big, then it is a lot of work,

    unless he has a housekeeper and does not have a garden

    FOL:

    Big(h) ^ House(h,j) => Work(h) (Cleans(c,h) ^ ~Garden(g,h))

    Implicative Normal Form:

    Big(h) ^ House(h,j) => Work(h) Cleans(c,h)

    Big(h) ^ House(h,j) ^ Garden(g,h) => Work(h)

  • 8/3/2019 Inference.c15 16

    34/49

  • 8/3/2019 Inference.c15 16

    35/49

    35

    Converting sentences to clausal formSkolem constants and functions

    5. Eliminate existential quantification by introducing Skolem

    constants/functions

    (x)P(x) ==> P(c)

    c is a Skolem constant (a brand-new constant symbol that is not

    used in any other sentence)(x)(y)P(x,y) ==> (x)P(x, f(x))

    since is within the scope of a universally quantified variable, use a

    Skolem function fto construct a new value that depends on the

    universally quantified variable

    f must be a brand-new function name not occurring in any othersentence in the KB.

    E.g., (x)(y)loves(x,y) ==> (x)loves(x,f(x))

    In this case, f(x) specifies the person that x loves

  • 8/3/2019 Inference.c15 16

    36/49

    36

    Converting sentences to clausal form

    6. Remove universal quantifiers by (1) moving them all to the

    left end; (2) making the scope of each the entire sentence;

    and (3) dropping the prefix part

    Ex: (x)P(x) ==> P(x)

    7. Put into conjunctive normal form (conjunction of

    disjunctions)

    (P ^ Q) R ==> (P R) ^ (Q R)

    (P Q) R ==> (P Q R)

    8. Split conjuncts into a separate clauses

    9. Standardize variables so each clause contains only variable

    names that do not occur in any other clause

  • 8/3/2019 Inference.c15 16

    37/49

  • 8/3/2019 Inference.c15 16

    38/49

    38

    Example

    7. Convert to conjunction of disjunctions

    (~P(x) ~P(y) P(f(x,y))) ^ (~P(x) Q(x,g(x))) ^

    (~P(x) ~P(g(x)))

    8. Create separate clauses

    ~P(x) ~P(y) P(f(x,y))

    ~P(x) Q(x,g(x))

    ~P(x) ~P(g(x))

    9. Standardize variables~P(x) ~P(y) P(f(x,y))

    ~P(z) Q(z,g(z))

    ~P(w) ~P(g(w))

  • 8/3/2019 Inference.c15 16

    39/49

    39

    Resolution TP as search

    Resolution can be thought of as the bottom-up

    construction of a search tree, where the leaves are the

    clauses produced by KB and the negation of the goal

    When a pair of clauses generates a new resolvent clause,

    add a new node to the tree with arcs directed from the

    resolvent to the two parent clauses

    Resolution succeeds when a node containing the False

    clause is produced, becoming the root node of the tree

    A strategy is complete if its use guarantees that the empty

    clause (i.e., false) can be derived whenever it is entailed

  • 8/3/2019 Inference.c15 16

    40/49

    40

    Breadth-first search

    Level 0 clauses are the original axioms and the negation of

    the goal

    Level k clauses are the resolvents computed from two

    clauses, one of which must be from level k-1 and the other

    from any earlier level

    Compute all possible level 1 clauses, then all possible level

    2 clauses, etc.

    Complete, but very inefficient

  • 8/3/2019 Inference.c15 16

    41/49

  • 8/3/2019 Inference.c15 16

    42/49

    42

    Set of support

    At least one parent clause must be the negation of the goal

    ora descendant of such a goal clause (i.e., derived from a

    goal clause)

    Complete (assuming all possible set-of-support clauses are

    derived)

    Gives a goal-directed character to the search

  • 8/3/2019 Inference.c15 16

    43/49

    43

    Unit resolution

    Prefer resolution steps in which at least one parent clause is

    a unit clause, i.e., a clause containing a single literal

    Not complete in general, but complete for Horn clause KBs

  • 8/3/2019 Inference.c15 16

    44/49

    44

    Input resolution

    At least one parent must be one of the input sentences (i.e.,

    either a sentence in the original KB or the negation of the

    goal)

    Not complete in general, but complete for Horn clause KBs

    Linear resolution

    Extension of input resolution

    One of the parent sentences must be an input sentence oran ancestor

    of an input sentece Complete

  • 8/3/2019 Inference.c15 16

    45/49

    45

    Ordered resolution

    Search for resolvable sentences in order (left to right)

    This is how Prolog operates

    Resolve the first element in the sentence first

    This forces the user to define what is important in

    generating the code

    The way the sentences are written controls the resolution

  • 8/3/2019 Inference.c15 16

    46/49

    46

    Subsumption

    Eliminate all sentences that are subsumed by (more specific

    than) an existing sentence to keep the KB small

    Like factoring, this is just removing things that merely

    clutter up the space and will not affect the final result

    E.g., if P(x) is already in the KB, adding P(A) makes no

    senseP(x) is a superset of P(A)

    Likewise adding P(A) Q(B) would add nothing to the KB

  • 8/3/2019 Inference.c15 16

    47/49

    47

    Proof tree that West is a criminal

  • 8/3/2019 Inference.c15 16

    48/49

    48

    A failed proof tree

  • 8/3/2019 Inference.c15 16

    49/49

    Sketch of a completeness proof for resolution