580 Resolution
580 Resolution
Artificial Intelligence
The Resolution Refutation Proof
Technique for First-Order Logic
Fall 2009
Marco Valtorta
mgv@cse.sc.edu
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Acknowledgment
• The slides are based on the textbook [AIMA] and other
sources, including other fine textbooks and the
accompanying slide sets
• The other textbooks I considered are:
– David Poole, Alan Mackworth, and Randy Goebel.
Computational Intelligence: A Logical Approach.
Oxford, 1998
• A second edition (by Poole and Mackworth) is under
development. Dr. Poole allowed us to use a draft of it in this
course
– Ivan Bratko. Prolog Programming for Artificial
Intelligence, Third Edition. Addison-Wesley, 2001
• The fourth edition is under development
– George F. Luger. Artificial Intelligence: Structures and
Strategies for Complex Problem Solving, Sixth Edition.
Addison-Welsey, 2009
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Outline
• Reducing first-order inference to propositional
inference
• Unification
• Generalized Modus Ponens
• Forward chaining
• Backward chaining
• Resolution
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Universal instantiation (UI)
• Every instantiation of a universally quantified sentence is entailed by
it:
v α
Subst({v/g}, α)
for any variable v and ground term g
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Existential instantiation (EI)
• For any sentence α, variable v, and constant symbol k that does not
appear elsewhere in the knowledge base:
v α
Subst({v/k}, α)
Crown(C1) OnHead(C1,John)
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Reduction ctd.
• Every FOL KB can be propositionalized so as to preserve
entailment
Idea: For n = 0 to ∞ do
create a propositional KB by instantiating with depth-n terms
see if α is entailed by this KB
• E.g., from:
x King(x) Greedy(x) Evil(x)
King(John)
y Greedy(y)
Brother(Richard,John)
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Unification
• We can get the inference 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)
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Unification
• We can get the inference 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)
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Unification
• We can get the inference 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)
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Unification
• We can get the inference 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)
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Unification
• We can get the inference 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) {fail}
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Unification
• To unify Knows(John,x) and Knows(y,z),
θ = {y/John, x/z } or θ = {y/John, x/John, z/John}
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
The unification algorithm
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Example knowledge base ctd.
... 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)
Note: This definite clause KB has no functions. It is therefore a Datalog
KB
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Forward chaining algorithm
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Forward chaining proof
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Forward chaining proof
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Forward chaining proof
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Properties of forward chaining
• Sound and complete for first-order definite clauses
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Backward chaining algorithm
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Backward chaining example
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Backward chaining example
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Backward chaining example
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Backward chaining example
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Backward chaining example
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Backward chaining example
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Backward chaining example
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Backward chaining example
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Properties of backward chaining
• Depth-first recursive proof search: space is linear in size of
proof
• Incomplete due to infinite loops
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
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Logic programming: Prolog
• Algorithm = Logic + Control
append([X|L],Y,[X|Z]) :-
append(L,Y,Z).
• query: ?-append(A,B,[1,2])
• 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
• Full disclosure: For completeness, one needs either
– general (non-binary) resolution, in which subsets of literals that are unifiable
are resolved, or
– Factoring, which replaces unifiable atoms literals in a clause with a single
atom
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Conversion to CNF
• Everyone who loves all animals is loved by someone:
x [y Animal(y) Loves(x,y)] [y Loves(y,x)]
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Conversion to CNF contd.
3. Standardize variables: each quantifier should use a
different one
x [y Animal(y) Loves(x,y)] [z Loves(z,x)]
6. Distribute over :
[Animal(F(x)) Loves(G(x),x)] [Loves(x,F(x))
Loves(G(x),x)]
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Completeness of Resolution
• Resolution is refutation-complete: if S is an
unsatisfiable set of clauses, then the application of a
finite number of resolution steps to S will yield a
contradiction
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Resolution proof: definite clauses
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Example KB [Nilsson, 1980]
• Whoever can read is literate • Whoever can read is literate
x[R(x) L(x)] – (1) ~R(x) L(x)
• Dolphins are not literate • Dolphins are not literate
x[D(x) ~L(x)] – (2) ~D(x) ~L(x)
• Some dolphins are intelligent • Some dolphins are intelligent
x[D(x) I(x)] – (3a) D(A)
• Goal: Some who are – (3b) I(A)
intelligent cannot read • Goal: Some who are
x[I(x) ~R(x)] intelligent cannot read
– (4’) ~I(z) R(z)
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
An example proof
• (5) R(A) resolvent of
3b and 4
• (6) L(A) resolvent of
5 and 1
• (7) ~D(A) resolvent
of 6 and 2
• (8) NIL resolvent of
7 and 3a
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Breadth-first strategy
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Set-of-Support Strategy
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Linear-Input Form Strategy
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Ancestry-Filtered Form Strategy
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering
Four more examples
• Prove by resolution the result of exercise 8.2 [AIMA-2]
– The goal is a universal formula!
• Group theory axioms and some consequences of them
[Schoening, example on pp.94-95]
• (a) every dragon is happy if all its children can fly; (b) green
dragons can fly; (c) a dragon is green if it is a child of at least
one green dragon; show that all green dragons are happy
• (a) Every barber shaves all persons who do not shave
themselves; (b) no barber shaves any person who shaves
himself or herself; show that there are no barbers
– Shows the need for factoring or non-binary resolution
(p.297 [AIMA-2])
UNIVERSITYOF
UNIVERSITY OFSOUTH
SOUTHCAROLINA
CAROLINA
DepartmentofofComputer
Department ComputerScience
Scienceand
andEngineering
Engineering