Artificial Intelligence Logic Part 2
description
Transcript of Artificial Intelligence Logic Part 2
All rights reserved L. Manevitz Lecture 5 1
Artificial IntelligenceLogic Part 2
L. Manevitz
All rights reserved L. Manevitz Lecture 5 2
Unification
• Alphabetic variant.
• Term substitution.
• “Ground”.
P(x,f(y),B)
S1={z/x,w/y}
S2={g(z)/x,A/y}
S3={C/x,A/y}
P(z,f(w),B)
P(g(z),f(A),B)
P(C,f(A),B)
All rights reserved L. Manevitz Lecture 5 3
Example
x [P(x) Q(x)]
P(a)
Q(a)
x [ P(x) Q(x)]
P(x) Q(x)
P(a) Q(a)
P(a)
P(a)
Q(a)
Substitution
All rights reserved L. Manevitz Lecture 5 4
Unification cont.
m.g.u g: s s’
{Ei}s = {Ei}g s’
{A(x),A(z)} {A(x),A(z)}
{A(a)} {A(x)}S1={a/x,a/
z}S2={x/z}
{Ei} S1 = {Ei}g S2
All rights reserved L. Manevitz Lecture 5 5
Example of m.g.u
{P(x),P(A)}
{P[f(x),y,g(y)],P[f(x),x,g(z)]}
{P[f(x,g(A,y)),g(A,y)],P[f(x,z),z]}
P(A)
P[f(x),x,g(x)]
P[f(x,g(A,y)),g(A,y)]
All rights reserved L. Manevitz Lecture 5 6
Unification – Algorithm
Unify(E1,E2)
• If E1 or E2 is an atom (that is, a predicate symbol, a function symbol, a constant symbol, a negation symbol or a variable),
interchange the arguments E1 and E2 (if necessary) so that E1 is an atom, and do:
All rights reserved L. Manevitz Lecture 5 7
Unification – Algorithm cont.
2. Begin:1. If E1 and E2 are identical, return NIL.2. If E1 is a variable, do:3. Begin:
2. If E1 occurs in E2, return FAIL.3. Return {E2 / E1}.
4. End.5. If E2 is a variable, return {E1 / E2}.6. Return FAIL.
3. End.
All rights reserved L. Manevitz Lecture 5 8
Unification – Algorithm cont.
4. F1the first element of E1, T1 the rest of E1.
5. F2 the first element of E2, T2 the rest of E2.
6. Z1UNIFY(F1,F2).
7. If Z1 = FAIL, return FAIL.
All rights reserved L. Manevitz Lecture 5 9
Unification – Algorithm cont.
8. G1result of applying Z1 to T1.
9. G2result of applying Z1 to T2.
10. Z2UNIFY(G1,G2).
11. If Z2 = FAIL, return FAIL.
12. Return the composition of Z1and Z2.
All rights reserved L. Manevitz Lecture 5 10
4Trace of Unification
• Unify ((fxx), (fAy))– 4. F1 = f; T1 = (xx) ; F2 = f; T2 =(Ay)– 6. Unify (f, f)
• 1. f = f so return NIL8. G1 = NIL(T1) = (xx) G2 = (Ay)10. Unify ((xx, Ay) 4. F1 = x F2 = A etc 6. Unify (x, A) 3.3 Return A/x
8. Apply A/x to (x) (y) get (A y) 10. Unify (A, y) get A/y Return composition of A/x and A/yResult is fAA.
All rights reserved L. Manevitz Lecture 5 11
Example
1. Whoever can read is literate.
2. Dolphins are not literate.
3. Some dolphins are intelligent.
x [R(x) L(x)]
x [D(x) L(x)]
x [D(x) I(x)]
All rights reserved L. Manevitz Lecture 5 12
Example cont.
To prove:
some who are intelligent can not read.
x [I(x) R(x)]
All rights reserved L. Manevitz Lecture 5 13
Example cont.
Clause Form:
1. R(x) L(x)
2. D(y) L(y)
3. Divided to two: A is Skolem constant1. D(A)
2. I(A)
4. Negation of theory:
I(z) R(z)
All rights reserved L. Manevitz Lecture 5 14
Example cont.
I(z) R(z) I(A)
R(A) R(x) L(x)
L(A) D(y) L(y)
D(A) D(A)
NIL
3.2 4
1
2
3.1
All rights reserved L. Manevitz Lecture 5 15
Control Methods
• Breadth First.
• Set of Support.
• Linear Input.
All rights reserved L. Manevitz Lecture 5 16
Breadth First - Example I(z) R(z)I(A)
R(A)
R(x) L(x)
L(A)
D(y) L(y)
L(A)
D(A)
NIL
I(z) L(z) R(y) D(y)
I(A) R(A) I(z) D(z) D(A)L(A)
All rights reserved L. Manevitz Lecture 5 17
Set of Support - Example I(z) R(z) I(A)
R(A)
R(x) L(x)
L(A)
D(y) L(y) D(A)
I(A)
I(y) D(y)
D(A)
L(A)
D(A) D(A)
I(z) L(z)
All rights reserved L. Manevitz Lecture 5 18
Linear Input - ExampleI(A)
R(A)
R(x) L(x)
L(A)
D(y) L(y) D(A)
I(A)
I(y) D(y)L(A) R(A)
I(z) L(z)
I(z) R(z)
R(y) D(y)
I(z) D(z)
L(A)
All rights reserved L. Manevitz Lecture 5 19
A refutation tree(note: no linear input tree)
Q(x) P(x) Q(y) P(y)
Q(w) P(w)
P(A)
P(x)
Q(w)
NIL
Q(u) P(A)
All rights reserved L. Manevitz Lecture 5 20
Ancestor Filtered
• Like linear input but also …
• Additional resolutions where one parent is the ancestor of the other one.
• Surprisingly, this is a complete strategy
All rights reserved L. Manevitz Lecture 5 21
A refutation tree(note: no linear input tree)
Q(x) P(x) Q(y) P(y)
Q(w) P(w)
P(A)
P(x)
Q(w)
NIL
Q(u) P(A)
All rights reserved L. Manevitz Lecture 5 22
Example no.1
x [AT(JOHN,x) AT(FIDO,x)]
AT(JOHN,School)
Where is FIDO ?
x [AT(FIDO,x)]
x [ AT(FIDO,x)]
AT(FIDO,x)
All rights reserved L. Manevitz Lecture 5 23
Example no.1 cont.
Answer:
• Append negation of each clause that arises from negation of theorem to each leaf in derivation tree in which it appears.
• Follow structure of derivation tree.
• Use clause at root as answer.
All rights reserved L. Manevitz Lecture 5 24
Example no.1 cont.AT(FIDO,x)Negation of Goal
AT(JOHN,y) AT(FIDO,y)Axiom 1
NIL
AT(JOHN,x)AT(JOHN,SCHOOL)
Axiom 2
y x
x SCHOOL
All rights reserved L. Manevitz Lecture 5 25
Example no.1-Green’s Trick
AT(JOHN,y) AT(FIDO,y)
AT(FIDO,SCHOOL)
AT(JOHN,SCHOOL)
y x
x SCHOOL
AT(FIDO,x) AT(FIDO,x)
AT(JOHN,x) AT(FIDO,x)
All rights reserved L. Manevitz Lecture 5 26
Example no.2
On (B,A)
On (A,Table)
T.S. Above (B,Table)
The axioms :
x y[On(x,y) Above(x,y)]
x y z[Above(x,y) Above(y,z) Above(x,z)]
All rights reserved L. Manevitz Lecture 5 27
Example no.2 cont.
Clause form:
1. On(u,v) Above(u,v)
2. Above(x,y) Above(y,z) Above(x,z)
3. On(B,A)
4. On(A,Table)
5. Above(B,Table)
All rights reserved L. Manevitz Lecture 5 28
Example no.2 – Resolution
Above(B,y) Above(y,Table)
On(y,Table) Above(B,y)
On(B,y) On(y,Table)
2 5
1
1
3
4 On(A,Table)
NIL
All rights reserved L. Manevitz Lecture 5 29
Example no.3
Predicates:
On(A,Table)
On(B,A)
Function: PutonTable?
x On(x,Table) How to use the function?
Need to add situation parameter
All rights reserved L. Manevitz Lecture 5 30
Frame Problem
AA
BB
BBAA
Operator:
•PutonTable(x):
•If x not on table, it puts x on table.
How should we represent this in logic ?How should we represent this in logic ?
All rights reserved L. Manevitz Lecture 5 31
Making Situation Part of Logic
S0 – initial situation.
On(A,Table,S0)
On(B,A,S0)
PutonTable axiom:
z x [ On(x,Table,z) On(x,Table,PutonTable(x,z)]
(PutonTable is function P:Object X Situation Situation)
All rights reserved L. Manevitz Lecture 5 32
Making Situation Part of Logic
Other axioms (how do we find them ?)
x y z [On(x,y,z) On(y,x,z)]
A = B
A = Table
B = Table
All rights reserved L. Manevitz Lecture 5 33
Frame Problem cont.
When will B be on the Table? Apply Green’s TrickGoal: z On(B,Table,z)
z On(B,Table,z)Axioms: On(B,A,S0)
On(A,Table,S0) z x[ On(x,Table,z) On(x,Table,PutonTable(x,z))] z y x[On(y,x,z) x=Table On(y,Table,z)] x y z[On(y,x,z) On(x,y,z)]
negated
All rights reserved L. Manevitz Lecture 5 34
Frame Problem cont.Clause form:1. On(B,A,S0)2. On(A,Table,S0)3. On(x,Table, S3) On(x,Table,PutonTable(x,S3))4. On(y,z,S4) z=Table On(y,Table,S4)5. (A=B)6. (B=Table)7. (A=Table)8. On(u,v,w) On(v,u,w)9. On(B,Table,s)
Goal Formula
All rights reserved L. Manevitz Lecture 5 35
On(x,Table, S3) On(x,Table,PutonTable(x,S3)) On(B,Table,S)
On(B,Table, S3)
On(B,z,S3) z=Table (A=Table)
On(B,A,S3)
NIL
93
On(y,z,S4) z=Table On(y,Table,S4)4
7
On(B,A,S0)1
x B
y B S4 S3
z A
S3 S0
S PutonTable(B,S3)
Green’s Trick
On(B,Table,S)
On(B,Table, PutonTable(B,S3))
On(B,Table, PutonTable(B,S3))
On(B,Table, PutonTable(B,S0))
On(B,Table, PutonTable(B,S3))
All rights reserved L. Manevitz Lecture 5 36
Frame Problem cont.
Do we know a state where both A and B
on table?
Goal: s[On(B,Table,s) On(A,Table,s)]
Negate + Clause:
On(B,Table,s) On(A,Table,s)
New formula no.9
All rights reserved L. Manevitz Lecture 5 37
Slide Missing on Start of Proofof A and B on table
• Show where you get stuck
All rights reserved L. Manevitz Lecture 5 38
Frame Problem cont.
The knowledge that A stays put
wasn’t put into logic !
Needs a “frame axiom” :
s x y z[On(x,y,s) x=z On(x,y,PutonTable(z,s))]
Clause form:
On(p,q,t) p=r On(p,q,PutonTable(r,t))
Formula no.10
All rights reserved L. Manevitz Lecture 5 39
On(p,q,t) p=r On(p,q,PutonTable(r,t))
On(A,Table,S0) A=B (A=B)
On(A,Table,S0)
NIL
10
5
On(A,Table,S0)2
p A r B
t S0
On(A,Table, PutonTable(B,S0))
9
q Table