### Resolution-Based Inference

Resolution-Based Inference
R&N: §9.3-9.6
Michael Rovatsos
University of Edinburgh
10th February 2015
Informatics 2D
Outline
• Forward chaining
• Backward chaining
• Resolution
Informatics 2D
Forward chaining algorithm
Pattern-matching
Facts irrelevant to the goal can be generated
Informatics 2D
‘West’ Knowledge Base
American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)
 Criminal(x)
Owns(Nono,M1) and Missile(M1)
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missile(x)  Weapon(x)
Enemy(x,America)  Hostile(x)
American(West) and Enemy(Nono,America)
Informatics 2D
Forward chaining proof
American(x)  Weapon(y)  Sells(x,y,z) 
Hostile(z)  Criminal(x)
Owns(Nono,M1) and Missile(M1)
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missile(x)  Weapon(x)
Enemy(x,America)  Hostile(x)
American(West) and Enemy(Nono,America)
Informatics 2D
Forward chaining proof
American(x)  Weapon(y)  Sells(x,y,z) 
Hostile(z)  Criminal(x)
Owns(Nono,M1) and Missile(M1)
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missile(x)  Weapon(x)
Enemy(x,America)  Hostile(x)
American(West) and Enemy(Nono,America)
Informatics 2D
Forward chaining proof
American(x)  Weapon(y)  Sells(x,y,z) 
Hostile(z)  Criminal(x)
Owns(Nono,M1) and Missile(M1)
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missile(x)  Weapon(x)
Enemy(x,America)  Hostile(x)
American(West) and Enemy(Nono,America)
Informatics 2D
Properties of forward chaining II
• Sound and complete for first-order definite clauses
– Definite clause = exactly one positive literal.
• Datalog = first-order definite clauses + no functions
• May not terminate in general if α is not entailed
• This is unavoidable: entailment with definite clauses is
semi-decidable
Informatics 2D
Efficiency of forward chaining I
Incremental forward chaining: no need to match a rule on
iteration k if a premise wasn't added on iteration k-1
 match each rule whose premise contains a newly added positive
literal
Matching itself can be expensive:
Database indexing allows O(1) retrieval of known facts
– e.g., query Missile(x) retrieves Missile(M1)
Forward chaining is widely used in deductive databases
Informatics 2D
Efficiency of forward chaining II
• Pattern Matching
– For each θ such that SUBST(θ, p1 ˄ … ˄ pn) = SUBST(θ, p’1 ˄
… ˄ p’n) for some p’1, … , p’n in KB
– Finding all possible unifiers can be very expensive
• Example
– Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
– Can find each object owned by Nono in constant time and then
check if it is a missible
– But what if Nono owns many objects but very few missiles?
– Conjunct Ordering: Better (cost-wise) to find all missiles first
and then check whether they are owned by Nono
– Optimal ordering is NP-hard. Heuristics available: e.g. MRV
from CSP if each conjunct is viewed as a constraint on its vars
Informatics 2D
Hard matching example
Diff(wa,nt)  Diff(wa,sa)  Diff(nt,q) 
Diff(nt,sa)  Diff(q,nsw)  Diff(q,sa) 
Diff(nsw,v)  Diff(nsw,sa)  Diff(v,sa) 
Colourable
Diff(Red,Blue) Diff (Red,Green)
Diff(Green,Red) Diff(Green,Blue)
Diff(Blue,Red) Diff(Blue,Green)
• Every finite domain CSP can be expressed as a single definite
clause + ground facts
• Colourable is inferred iff the CSP has a solution
• CSPs include 3SAT as a special case, hence matching is NP-hard
Informatics 2D
Backward chaining algorithm
Fetch rules
that might
unify
A function that
returns multiple times,
each time giving one
possible result
SUBST(COMPOSE(θ1, θ2), p) = SUBST(θ2, SUBST(θ1, p))
Informatics 2D
Backward chaining example
American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)
Owns(Nono,M1) and Missile(M1)
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missile(x)  Weapon(x)
Enemy(x,America)  Hostile(x)
American(West) and Enemy(Nono,America)
Informatics 2D
Backward chaining example
American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)
Owns(Nono,M1) and Missile(M1)
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missile(x)  Weapon(x)
Enemy(x,America)  Hostile(x)
American(West) and Enemy(Nono,America)
Informatics 2D
Backward chaining example
American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)
Owns(Nono,M1) and Missile(M1)
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missile(x)  Weapon(x)
Enemy(x,America)  Hostile(x)
American(West) and Enemy(Nono,America)
Informatics 2D
Backward chaining example
American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)
Owns(Nono,M1) and Missile(M1)
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missile(x)  Weapon(x)
Enemy(x,America)  Hostile(x)
American(West) and Enemy(Nono,America)
Informatics 2D
Backward chaining example
American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)
Owns(Nono,M1) and Missile(M1)
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missile(x)  Weapon(x)
Enemy(x,America)  Hostile(x)
American(West) and Enemy(Nono,America)
Informatics 2D
Backward chaining example
American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)
Owns(Nono,M1) and Missile(M1)
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missile(x)  Weapon(x)
Enemy(x,America)  Hostile(x)
American(West) and Enemy(Nono,America)
Informatics 2D
Backward chaining example
American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x)
Owns(Nono,M1) and Missile(M1)
Missile(x)  Owns(Nono,x)  Sells(West,x,Nono)
Missile(x)  Weapon(x)
Enemy(x,America)  Hostile(x)
American(West) and Enemy(Nono,America)
Informatics 2D
Properties of backward chaining
• Depth-first recursive proof search: space is
linear in size of proof
• Incomplete due to infinite loops
– partial fix by checking current goal against every goal
on stack
• Inefficient due to repeated subgoals (both
success and failure)
– fix using caching of previous results (extra space)
• Widely used for logic programming
Informatics 2D
Ground Binary Resolution
CP
D  ¬P
CD
Soundness:
C  P iff ¬C  P
D  ¬P iff P  D
– Therefore, ¬C  D
– Which is equivalent to C  D
Note: if both C and D are empty then resolution
deduces the empty clause, i.e. false.
Informatics 2D
Non-Ground Binary Resolution
D  ¬P’
CP
(C  D)
where  is the mgu of P and P’
• The two clauses are assumed to be standardized apart
so that they share no variables.
• Soundness: apply  to premises then appeal to ground
binary resolution.
C  P
D  ¬P
C  D
Informatics 2D
Example
Rich(x)  Unhappy(x)
Unhappy(Ken)
with θ = {x/Ken}
Informatics 2D
Rich(Ken)
Factoring
C  P1  …  Pm
(C  P1)
• where  is the mgu of the Pi
• Soundness: by universal instantiation
and deletion of duplicates.
Informatics 2D
Full Resolution
C  P1  …  Pm
D  ¬P1’  …  Pn’
(C  D)
where θ is mgu of all Pi and Pi’
• Soundness: by combination of factoring and binary
resolution.
• To prove α: apply resolution steps to CNF(KB  α);
– complete for FOL, if full resolution or binary resolution +
factoring is used
Informatics 2D
Conversion to CNF
Example:
Everyone who loves all animals is loved by someone:
x. [y. Animal(y)  Loves(x,y)]  [y. Loves(y,x)]
1. Eliminate all biconditionals and implications
x. [y. Animal(y)  Loves(x,y)]  [y. Loves(y,x)]
2. Move  inwards, use: x. p ≡ x. p,
 x. p ≡ x. p, etc.
x. [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)]
Informatics 2D
Conversion to CNF contd.
3.
Standardize variables apart: each quantifier should use a
different one
x. [y. Animal(y)  Loves(x,y)]  [z. Loves(z,x)]
4.
Skolemize: a more general form of existential instantiation
Each existential variable is replaced by a Skolem function of the
enclosing universally quantified variables:
x. [Animal(F(x))  Loves(x,F(x))]  Loves(G(x),x)
5.
Drop universal quantifiers:
No enclosing universal
quantifier? Just
replace with Skolem
constant i.e. a function
with no argument
[Animal(F(x))  Loves(x,F(x))]  Loves(G(x),x)
6.
Distribute  over  :
[Animal(F(x))  Loves(G(x),x)]  [Loves(x,F(x))  Loves(G(x),x)]
Informatics 2D
‘West’ Clauses
¬American(x)  ¬Weapon(y)  ¬Sells(x,y,z) 
¬Hostile(z)  Criminal(x)
Owns(Nono,M1) and Missile(M1)
¬Missile(x)  ¬Owns(Nono,x)  Sells(West,x,Nono)
¬Missile(x)  Weapon(x)
¬Enemy(x,America)  Hostile(x)
American(West)
and
Enemy(Nono,America)
Informatics 2D
Resolution proof: definite clauses
¬
Informatics 2D
Summary
• Forward chaining
• Backward chaining
• Resolution
Informatics 2D