Lecture 1 Characterisations of AI
Download
Report
Transcript Lecture 1 Characterisations of AI
Artificial Intelligence
8. The Resolution Method
Course V231
Department of Computing
Imperial College, London
Jeremy Gow
Soundness & Completeness
Want to prove theorem T from Axioms Ax
Chosen a set of inference rules R
A B means B is entailed by A
A B means B is derived from A using R
R should be sound: if A
Want R to be complete: if A
B then A
B
B then A
B
Choose Your Search Space
Soundness and completeness of R isn’t enough
We want a reasonable search space
–
–
–
R determines operators, so influences the space
Can I see where I’m going? (Heuristic measure)
Can I restrict options at each state? (Branching)
Three main approaches
–
–
–
Forwards chaining: no heuristic guidance
Backwards chaining: large branching (many things entail KB)
Proof by refutation: clear goal (false), forwards inference
Proof by Refutation
Proof by contradiction, reductio ad absurdum
1.
Negate the theorem & add to axioms (¬T,Ax)
Use rules of inference to derive the False
2.
So sentences (¬T,Ax) can’t all be true (unsatisfiable)
But the axioms Ax are true
Hence the negated theorem ¬T must be false
Hence the theorem T must be true
The Resolution Method
Proof by refutation with a single inference rule
–
–
No need to worry about choice of rule
Just how we apply the one rule
Resolution is complete for FOL
–
Refutation-complete [Robinson 1965]
–
If (¬T,Ax) unsatisfiable it will derive a contradiction
So if will prove any true theorem of FOL
Even so, it might take a long time (> universe)
–
–
–
Even fairly trivial theorems can take a long time
Can use search heuristics to speed it up (next lecture)
No guarantees if it’s not a theorem
Binary Resolution (Propositional)
Unit resolution rule (last lecture)
AB, ¬B
A
Binary resolution rule
AB, ¬BC
AC
The literals B and ¬B are resolved
Binary Resolution (First-Order)
Binary resolution rule
AB, ¬CD
Subst(, AD)
if substitution s.t. Subst(,B) = Subst(,C)
The literals B and ¬C are resolved
–
B and C have been made the same by
Resolution in FOL (This Lecture)
What if KB contains non-disjuncts?
–
How do we find substitution ?
–
Preprocessing step: rewrite to CNF
The unification algorithm
But what if more than two disjuncts?
–
Extend binary resolution to full resolution
Conjunctive Normal Form
A conjunction of clauses
–
–
–
Each clause is a disjunction of literals
Prop. literal: proposition or negated proposition
FO literal: predicate or negated predicate
No quantifiers (all variables implicitly universal)
Example FO clause
likes(george, X) ¬likes(tony, houseof(george)) ¬is_mad(maggie)
Any FO sentence can be rewritten as CNF
Converting FOL to CNF (see notes)
1.
2.
3.
4.
5.
6.
7.
8.
Eliminate implication/equivalence (rewrite)
Move ¬ inwards (rewrite)
Rename variables apart (substitution)
Move quantifiers outwards (rewrite)
Skolemise existential variables (substitution)
Distribute over (rewrite)
Flatten binary connectives (rewrite)
(Optional: Reintroduce implications)
Example CNF Conversion
Propositional example (B (A C)) (B ¬A)
1. Remove implication:
¬(B (A C)) (B ¬A)
2. Move ¬ inwards (De Morgan’s x 2):
(¬B ¬(A C)) (B ¬A)
(¬B (¬A ¬C)) (B ¬A)
(Skip 3 to 5 as no variables.)
Example CNF Conversion (Contd)
(¬B (¬A ¬C)) (B ¬A)
6. Distribute over :
(¬B (B ¬A)) ((¬A ¬C) (B ¬A))
7. Flatten connectives
(¬B B ¬A) (¬A ¬C B ¬A)
Drop 1st clause (¬B B), remove duplicate from 2nd:
¬A ¬C B
Kowalski Normal Form
Can reintroduce to CNF, e.g.
¬A ¬C B becomes (A C) B
Kowalski form
(A1 … An) (B1 … Bn)
Binary resolution…
AB, BC
AC
Resembles Horn clauses (basis for Prolog)
Skolemisation
Replace V with a ‘something’ term
–
–
If no preceeding U use fresh Skolem constant
Otherwise fresh Skolem function
parameterised by all preceeding U
X Y (person(X) has(X, Y) heart(Y))
to
person(X) has(X, f(X)) heart(f(X))
(The particular heart f(X) depends on person
X)
Substitutions & Inference Rules
Propositional inference rules used in first-order logic
But in FOL we can make substitutions
–
–
Sometimes a substitution can allow a rule to be applied
cf. FO binary resolution
knows(john, X) hates(john, X)
knows(john, mary)
Substitution + Modus Ponens: infer hates(john, mary)
Need to find substitution that makes literals equal
–
Known as a unifier
Unifying Predicates
We unified these two predicates:
–
knows(john, X) and knows(john, mary)
By saying that X should be substituted by mary
Why? Because john = john and can {X\mary}
For knows(jack, mary) and knows(john, X)
–
–
–
john doesn’t match jack
So we cannot unify the two predicates
Hence we cannot use the rule of inference
Unification
Want an algorithm which:
–
–
Takes two FOL sentences as input
Outputs a substitution {X/mary, Y/Z, etc.}
–
Which assigns terms to variables in the sentences
So that the first sentence looks exactly like the second
Or fails if there is no way to unify the sentences
Example:
Unify(“knows(john, X)”, “knows(john,mary)”) = {X/mary}
Unify(“knows(john, X)”, “knows(jack,mary)”) = Fail
Functions Within the
Unify Algorithm
isa_variable(x)
–
isa_list(x)
–
checks whether x is a variable
checks whether x is a list
head(x)
–
outputs the head of a list (first term)
e.g., head([a,b,c]) = a
tail(x)
–
outputs the elements other than the head in a list
e.g., tail([a,b,c]) = [b,c]
More Internal Functions
(Compound Expressions)
isa_compound(x)
–
–
checks whether x is compound expression
(either a predicate, a function or a connective)
args(x)
–
finds the subparts of the compound expression x
–
arguments of a predicate, function or connective
Returns the list of arguments
op(x)
–
predicate name/function name/connective symbol
Two Parts of the
Unification Algorithm
Algorithm is recursive (it calls itself)
–
–
unify(x,y) = unify_internal(x,y,{})
–
x and y are either a variable, constant, list, or compound
unify_internal(x,y,mu)
–
–
Passes around a set of substitutions, called mu
Making sure that new substitutions are consistent with old ones
x and y are sentences, mu is a set of substitutions
finds substitutions making x look exactly like y
unify_variable(var,x,mu)
–
–
var is a variable
finds a single substitution (which may be in mu already)
unify_internal
unify_internal(x,y,mu)
---------------------Cases
1.if (mu=failure) then return failure
2.if (x=y) then return mu.
3.if (isa_variable(x)) then return unify_variable(x,y,mu)
4.if (isa_variable(y)) then return unify_variable(y,x,mu)
5.if (isa_compound(x) and isa_compound(y)) then return
unify_internal(args(x),args(y),unify_internal(op(x),op(y),mu))
6.if (isa_list(x) and isa_list(y)) then return
unify_internal(tail(x),tail(y),unify_internal(head(x),head(y),mu))
7.return failure
unify_variable
unify_variable(var,x,mu)
-----------------------Cases
1. if (a substitution var/val is in mu)
then return unify_internal(val,x,mu)
2. if (a substitution x/val is in mu) then
return unify_internal(var,val,mu)
3. if (var occurs anywhere in x) return
failure
4. add var/x to mu and return
Notes on the Unification Algorithm
unify_internal will not match a constant to a constant,
unless they are equal (case 2)
Case 5 in unify_internal checks that two compound
operators are the same (e.g. same predicate name)
Case 6 in unify_internal causes the algorithm to
recursivly unify the whole list
Cases 1 and 2 in unify_variable check that neither
inputs have already been substituted
The Occurs Check
Suppose we needed to substitute X with f(X,Y)
–
–
This would give us f(X,Y) instead of X
But there is still an X in there,
so the substitution isn’t complete:
we need f(f(X,Y),Y), then f(f(f(X,Y),Y),Y) and so on
We need to avoid this situation
–
Otherwise the algorithm won’t stop
Case 3 in unify_variable checks this
–
Known as the “occurs check”
–
Occurs check slows the algorithm down
–
Order (n2), where n is size of expressions being unified
An Example Unification
Suppose we want to unify these sentences:
1. p(X,tony) q(george,X,Z)
2. p(f(tony),tony) q(B,C,maggie)
By inspection, this is a good substitution:
–
This makes both sentences become:
–
p(f(tony),tony) q(george, f(tony), maggie)
Note that we want to substitute X for C
–
{X/f(tony), B/george, C/f(tony), Z/maggie}
But we have substituted f(tony) for X already
See the notes for this as a worked example
–
–
Using the unification algorithm
Requires five iterations!
Binary Resolution (First-Order)
Binary resolution rule (using unification)
AB, ¬CD
Subst(, AD)
if Unify(B, C) =
Unification algorithm finds Most General
Unifier (MGU)
–
Don’t substitute any more than need to
The Full Resolution Rule
If Unify(Pj, ¬Qk) = (¬ makes them unifiable)
P1 … Pm,
Q 1 … Qn
Subst(, P1 … (no Pj) … Pm Q1 … (no Qk) ... Qn)
Pj and Qk are resolved
Arbitrary number of disjuncts
Relies on preprocessing into CNF
Using Full Resolution
Sentences already in CNF
Pick two clauses
–
–
–
–
Pick positive literal P from first
Pick negative literal N from second
Find MGU of ¬P and N
Write both clauses as one big disjunction
With P and N missing
Apply to the new clause
Resolution Proof Search
Keep on resolving clause pairs
–
–
Eventually result in zero-length clause
This indicates that some literal K was true at the
same time as the literal ¬K
–
–
Only way to reduce sentence to be empty
Hence there was an inconsistency
Which proves the theorem
Topic of the next lecture
Coursework: War of Life
http://www.doc.ic.ac.uk/~sgc/teaching/v231/
Two player version of Game of Life
–
–
Implement several strategies in Prolog
Run a tournament
On CATE this afternoon
Submit via CATE (more to follow…)
Deadline: 3 weeks today