Inference in First-Order Logic
Inference in First-Order Logic
Inference Rules
Universal Instantiation
Infer a sentence obtained by substituting a
ground term for the variable.
x cat(x) mammal(x); cat(Felix),
therefore, mammal(Felix)
Existential Generalization
Q(A) x Q(x) ….
2
Inference Rules (from Chap 7)
Modus ponens P(x) Q(x) , P(A)
Q(A)
3
Inference Rules (from Chap 7)
4
Additional Rules of Inference
substitution
SUBST(,S), substituting (or binding list) to sentence S
SUBST({x/5,y/3}, gt(x,y)) = gt(5,3)
Additional Rules
Universal Elimination
x S x Likes(x,IceCream)
SUBST ({x g}, S ) {x/Ben}, Likes(Ben,IceCream)
Existential Elimination
x S x Likes(x,Sally) If Ben doesn’t
SUBST ({x A}, S ) {x/Ben}, Likes(Ben,Sally) appear elsewhere
Existential Introduction
S Likes(John,IceCream)
x SUBST ({g x}, S ) x Likes(x,IceCream) 5
Additional rules of inference
Unification
UNIFY(p, q) = q where SUBST(q, q)
Examples:
UNIFY(Knows(John, x), Knows(John, Jane)) = {x/Jane}
6
Forward Chaining
Start with atomic Knowledge base sentences, apply rules
of inference, adding new atomic sentences, until no
further inferences can be made.
x,y,z gt(x,y) gt(y,z) gt(x,z)
Given: gt(A,B), gt(B,C), and gt(C,D) can we say
gt(A,D)?
Step 1: gt(A,B) gt(B,C) gt(A,C)
Step 2: gt(A,C) gt(C,D) gt(A,D); Therefore, gt(A,D)
–Typically triggered when a new fact, p, is added to
the knowledge base. Then we find all implications
that have p as premise – can also use other premises
that are known to be true 7
Example Problem
John likes all kinds of food.
Apples are food.
Chicken is food.
Anything anyone eats and isn’t killed by
is food.
Bill eats peanuts, and is still alive.
Sue eats everything that Bill eats.
8
Example Problem
John likes all kinds of x food (x) eats(John, x)
food
Apples are food. food(apples)
Chicken is food. food(chicken)
Anything anyone eats and x,y eats(x,y) killed(x)
isn’t killed by is food. food(y)
Bill eats peanuts, and is still eats(Bill,Peanuts)
alive. killed(Bill)
Sue eats everything that Bill x eats (Bill,x)
eats. eats(Sue,x) 9
Answer Questions (by Proof)
Does John eat peanuts?
1) eats(Bill,Peanuts) killed(Bill)
2) x,y eats(x,y) killed(x) food(y)
SUBST({x/Bill,y/Peanuts}), universal elimination, and modus
ponens to derive food(peanuts)
3) x food (x) eats(John, x)
SUBST({x/Peanuts}) and use (2, universal elimination, and
modus ponens to derive eats(John,peanuts)
food(Peanuts)
x,y eats(x,y) killed(x) food(y)
11
More Efficient Forward Chaining
Checking all rules will take too much time.
12
Forward Chaining
• Data Driven
• not directed at finding particular information –
can generate irrelevant conclusions
• Strategy
• match rules that contain recently added literals
• Forward chaining may not terminate
• Especially if desired conclusion is not entailed
(Incomplete)
13
Backward Chaining
Start at the goal, chain through inference rules
to find known facts that support the proof.
Uses Modus Ponens backwards
Designed to answer questions posed to a knowledge
base
In reality, the eats(John, y) Yes, y/peanuts
algorithm would
include all appropriate food (y) Yes, y/peanuts
rules.
eats(x,y) killed(x)
Yes, x/Bill, y/peanuts Yes, x/Bill
14
Backward Chaining
• Depth First recursive proof
• space is linear in size of proof.
• Incomplete
• infinite loops
• Can be inefficient
• repeated subgoals
15
FOL to CNF
Resolution requires that FOL sentences be
represented in Conjunctive Normal Form
(CNF)
Everyone who loves all animals is loved by
someone.
FOL: x[y Animal ( y) Loves( x, y)] [y Loves( y, x)]
CNF:
[ Animal ( F ( x)) Loves(G( x), x)] [Loves( x, F ( x)) Loves(G( x), x)]
16
Resolution
Resolution
a single inference rule
provides a complete inference algorithm
when coupled with any complete search
algorithm.
17
Resolution
Implicative Form Conjunctive normal form
x food (x) eats(John, x) food (x) eats(John, x)
food(apples) food(apples)
food(chicken) food(chicken)
x,y eats(x,y) killed(x) eats(x,y) killed(x) food(y)
food(y)
eats(Bill,Peanuts) eats(Bill,Peanuts)
killed(Bill) killed(Bill)
x eats (Bill,x) eats(Sue,x) eats (Bill,x) eats(Sue,x)
{x/Bill, y/peanuts}
19
Resolution uses unification
Unification: takes two atomic expressions p
and q, and generates a substitution that
makes p and q look the same.
UNIFY(p,q) = q where SUBST(q,p) = SUBST(q,q)
p q q
x,y – implicitly
knows(John, x) knows(John,Jane) {x / Jane} universally quantified
22
Resolution
Implicative Form Conjunctive normal form
x food (x) eats(John, x) food (x) eats(John, x)
food(apples) food(apples)
food(chicken) food(chicken)
x,y eats(x,y) killed(x) eats(x,y) killed(x) food(y)
food(y)
eats(Bill,Peanuts) eats(Bill,Peanuts)
killed(Bill) killed(Bill)
x eats (Bill,x) eats(Sue,x) eats (Bill,x) eats(Sue,x)
{x/Peanuts}
{y/Peanuts}
25
Resolution Refutation
x[y Animal ( y) Loves( x, y)] [y Loves( y, x)]
Procedure
1. Eliminate implications
x [y Animal ( y) Loves( x, y)] [y Loves( y, x)]
27
Conversion to Clause Form
x [ Animal ( F ( x)) Loves( x, F ( x))] [ Loves(G( x), x)]
5. Convert to prenex form – move all universal
quantifiers out
9. Rename variables
(i) Animal ( F ( x1 )) Loves(G( x1 ), x1 )
(ii ) Loves( x2 , F ( x2 )) Loves(G( x2 ), x2 )
29
Conversion to Clause Form (HW)
Solution: 3 clauses
1. P( x1 ) P( y ) P( f ( x1 , y ))
2. P( x2 ) Q( x2 , g ( x2 ))
3. P( x3 ) P( g ( x3 ))
30
Resolution Refutation Theorem Proving
Procedure:
1) Put all sentences in KB into clause (CNF)
form (Step 1)
2) Negate goal state, put into KB in clause
form, and add to KB
3) Resolve clauses
4) Produce contradiction, i.e., the empty clause
5) Therefore, (negated goal) is true.
31
Resolution Refutation: Properties
Sound
any conclusion reached is true.
Complete
inference will eventually provide true
conclusion
Tractability or Feasibility
Inference procedure may never terminate if
expression to be proved is not true.
32
Resolution Refutation: Properties
Resolution Strategies
improve efficiency of process
Unit preference
prefer to do resolutions with unit clauses.
idea: produce short sentences, reduce them to null
(false).
Restricted form of resolution refutation where
every step must involve a unit clause.
33
Resolution Refutation: Properties
Resolution Strategies
Set of support
Eliminate some potential resolutions.
Use a small set of clauses called set of support.
Combine a sentence from the set with another
sentence via resolution, then add the new resolved
sentence to the set.
Works well if the set of support is small relative to
the KB.
Choosing a bad support set can make the
algorithm incomplete.
34