460 likes | 669 Views
Unification & Resolution Examples. Andrew Kuipers amkuiper@cpsc.ucalgary.ca Please include [CPSC433] in the subject line of any emails regarding this course. Unification – A Quick Review. Unification is needed to compute mgu (most general unifier) Yet another set-based search problem:
E N D
Unification & Resolution Examples Andrew Kuipers amkuiper@cpsc.ucalgary.ca Please include [CPSC433] in the subject line of any emails regarding this course. CPSC 433 Artificial Intelligence
Unification – A Quick Review Unification is needed to compute mgu(most general unifier) Yet another set-based search problem: States: set of term equations u v, with indicating failure Transitions: Extension Rules to generate new term equations Goal condition: all equations in the state have form x t and Occurcheck and Substitute are not applicable CPSC 433 Artificial Intelligence
Unification – A Quick Review Delete: E {t t} E Decompose: E {f(t1,…,tn) f(s1,…,sn)} E {t1 s1,…,tn sn} Orient: E {t x} (if t not a var) E {x t} CPSC 433 Artificial Intelligence
Unification – A Quick Review Substitute: E {x t, t' s'} E {x t, t'[xt] s'[xt]} Occurcheck: E {x t} Clash: E {f(t1,…,tn) g(s1,…,sn)} if x not in t s[xt] : replace all x’s in s with t if x in t if f g CPSC 433 Artificial Intelligence
Unification Example 1: mgu( f(g(x,y),c), f(g(f(d,x),z),c) ) CPSC 433 Artificial Intelligence
Unification Example 1: mgu( f(g(x,y),c), f(g(f(d,x),z),c) ) E = { f(g(x, y), c) ≈ f(g(f(d, x), z), c) } CPSC 433 Artificial Intelligence
Unification Example 1: mgu( f(g(x,y),c), f(g(f(d,x),z),c) ) E = { f(g(x, y), c) ≈ f(g(f(d, x), z), c) } • Decompose E {f(t1,…,tn) f(s1,…,sn)} E {t1 s1,…,tn sn} E = { g(x, y) ≈ g(f(d,x),z), c ≈ c } CPSC 433 Artificial Intelligence
Unification Example 1: mgu( f(g(x,y),c), f(g(f(d,x),z),c) ) E = { g(x, y) ≈ g(f(d,x),z), c ≈ c } CPSC 433 Artificial Intelligence
Unification Example 1: mgu( f(g(x,y),c), f(g(f(d,x),z),c) ) E = { g(x, y) ≈ g(f(d,x),z), c ≈ c } 2. Delete E {t t} E E = { g(x, y) ≈ g(f(d,x),z) } CPSC 433 Artificial Intelligence
Unification Example 1: mgu( f(g(x,y),c), f(g(f(d,x),z),c) ) E = { g(x, y) ≈ g(f(d,x),z) } CPSC 433 Artificial Intelligence
Unification Example 1: mgu( f(g(x,y),c), f(g(f(d,x),z),c) ) E = { g(x, y) ≈ g(f(d,x),z) } 3. Decompose E {f(t1,…,tn) f(s1,…,sn)} E {t1 s1,…,tn sn} E = { x ≈ f(d, x), y ≈ z } CPSC 433 Artificial Intelligence
Unification Example 1: mgu( f(g(x,y),c), f(g(f(d,x),z),c) ) E = { x ≈ f(d, x), y ≈ z } CPSC 433 Artificial Intelligence
Unification Example 1: mgu( f(g(x,y),c), f(g(f(d,x),z),c) ) E = { x ≈ f(d, x), y ≈ z } 4. Occurcheck E {x t} if x in t E = , f(g(x,y), c) and f(g(f(d,x),z),c) not unifiable CPSC 433 Artificial Intelligence
Unification Example 2: mgu( h(c,d,g(x,y)), h(z,d,g(g(a,y),z)) ) CPSC 433 Artificial Intelligence
Unification Example 2: mgu( h(c,d,g(x,y)), h(z,d,g(g(a,y),z)) ) E = { h(c,d,g(x,y)) ≈ h(z,d,g(g(a,y),z)) } CPSC 433 Artificial Intelligence
Unification Example 2: mgu( h(c,d,g(x,y)), h(z,d,g(g(a,y),z)) ) E = { h(c,d,g(x,y)) ≈ h(z,d,g(g(a,y),z)) } 1. Decompose E {f(t1,…,tn) f(s1,…,sn)} E {t1 s1,…,tn sn} E = { c ≈ z, d ≈ d, g(x, y) ≈ g(g(a, y), z) } CPSC 433 Artificial Intelligence
Unification Example 2: mgu( h(c,d,g(x,y)), h(z,d,g(g(a,y),z)) ) E = { c ≈ z, d ≈ d, g(x, y) ≈ g(g(a, y), z) } CPSC 433 Artificial Intelligence
Unification Example 2: mgu( h(c,d,g(x,y)), h(z,d,g(g(a,y),z)) ) E = { c ≈ z, d ≈ d, g(x, y) ≈ g(g(a, y), z) } 2. Delete E {t t} E E = { c ≈ z, g(x, y) ≈ g(g(a, y), z) } CPSC 433 Artificial Intelligence
Unification Example 2: mgu( h(c,d,g(x,y)), h(z,d,g(g(a,y),z)) ) E = { c ≈ z, g(x, y) ≈ g(g(a, y), z) } CPSC 433 Artificial Intelligence
Unification Example 2: mgu( h(c,d,g(x,y)), h(z,d,g(g(a,y),z)) ) E = { c ≈ z, g(x, y) ≈ g(g(a, y), z) } 3. Decompose E {f(t1,…,tn) f(s1,…,sn)} E {t1 s1,…,tn sn} E = { c ≈ z, x ≈ g(a, y), y ≈ z } CPSC 433 Artificial Intelligence
Unification Example 2: mgu( h(c,d,g(x,y)), h(z,d,g(g(a,y),z)) ) E = { c ≈ z, x ≈ g(a, y), y ≈ z } CPSC 433 Artificial Intelligence
Unification Example 2: mgu( h(c,d,g(x,y)), h(z,d,g(g(a,y),z)) ) E = { c ≈ z, x ≈ g(a, y), y ≈ z } 4. Substitute E {x t, t' s'} E {x t, t'[xt] s'[xt]} E = { c ≈ z, x ≈ g(a, z), y ≈ z } CPSC 433 Artificial Intelligence
Unification Example 2: mgu( h(c,d,g(x,y)), h(z,d,g(g(a,y),z)) ) E = { c ≈ z, x ≈ g(a, z), y ≈ z } CPSC 433 Artificial Intelligence
Unification Example 2: mgu( h(c,d,g(x,y)), h(z,d,g(g(a,y),z)) ) E = { c ≈ z, x ≈ g(a, z), y ≈ z } 5. Orient E {t x} E {x t} E = { z ≈ c, x ≈ g(a, z), y ≈ z } CPSC 433 Artificial Intelligence
Unification Example 2: mgu( h(c,d,g(x,y)), h(z,d,g(g(a,y),z)) ) E = { z ≈ c, x ≈ g(a, z), y ≈ z } CPSC 433 Artificial Intelligence
Unification Example 2: mgu( h(c,d,g(x,y)), h(z,d,g(g(a,y),z)) ) E = { z ≈ c, x ≈ g(a, z), y ≈ z } 6. Substitute E {x t, t' s'} E {x t, t'[xt] s'[xt]} E = { z ≈ c, x ≈ g(a, c), y ≈ c } CPSC 433 Artificial Intelligence
Unification Example 2: mgu( h(c,d,g(x,y)), h(z,d,g(g(a,y),z)) ) E = { z ≈ c, x ≈ g(a, c), y ≈ c } CPSC 433 Artificial Intelligence
Unification Example 2: mgu( h(c,d,g(x,y)), h(z,d,g(g(a,y),z)) ) E = { z ≈ c, x ≈ g(a, c), y ≈ c } No more applicable extensions! CPSC 433 Artificial Intelligence
Resolution – A Quick Review Used to prove a consequence from a set of logical formulae States: Sets of clauses L1(t11,…,t1,n1) … Lm(tm1,…,tm,nm) - Li is a predicate symbol or its negation,- tij terms out of function symbols and variables (x,y…)- variables in different clauses are disjunct Initially: The consequence we want to prove is negated and added to the set of clauses representing the initial state Goal: Derive the empty clause (), ie: reductio ad absurdum CPSC 433 Artificial Intelligence
Resolution – A Quick Review Transitions: New clauses generated by Resolution or Factorization Resolution: C P , D P’ (C D) Factorization: C P P' (C P) Note: clauses are commutative: pq qp, pqr same as rpq where = mgu(P,P’) where = mgu(P,P’) CPSC 433 Artificial Intelligence
Resolution Example 3: • ¬P(x) P(f(x)) • ¬Q(a, y) ¬R(y, x) P(x) • R(b, g(a, z)) • Q(a, b) Goal: P(f(g(a, c))) CPSC 433 Artificial Intelligence
Resolution Example 3: • Negate goal, add to folmulas 1. ¬P(x) P(f(x)) 2. ¬Q(a, y) ¬R(y, x) P(x) 3. R(b, g(a, z)) 4. Q(a, b) CPSC 433 Artificial Intelligence
Resolution Example 3: • Negate goal, add to folmulas 1. ¬P(x) P(f(x)) 2. ¬Q(a, y) ¬R(y, x) P(x) 3. R(b, g(a, z)) 4. Q(a, b) 5. ¬P(f(g(a, c))) CPSC 433 Artificial Intelligence
Resolution Example 3: • Negate goal, add to folmulas • Resolve (4) and (2) 1. ¬P(x) P(f(x)) 2. ¬Q(a, y) ¬R(y, x) P(x) 3. R(b, g(a, z)) 4. Q(a, b) 5. ¬P(f(g(a, c))) CPSC 433 Artificial Intelligence
Resolution Example 3: • Negate goal, add to folmulas • Resolve (4) and (2) 1. ¬P(x) P(f(x)) 2. ¬Q(a, y) ¬R(y, x) P(x) 3. R(b, g(a, z)) 4. Q(a, b) 5. ¬P(f(g(a, c))) ¬Q(a, y) ¬R(y, x) P(x), Q(a, b) ¬R(b, x) P(x) σ = { y ≈ b } CPSC 433 Artificial Intelligence
Resolution Example 3: • Negate goal, add to folmulas • Resolve (4) and (2) 1. ¬P(x) P(f(x)) 2. ¬Q(a, y) ¬R(y, x) P(x) 3. R(b, g(a, z)) 4. Q(a, b) 5. ¬P(f(g(a, c))) 6. ¬R(b, x) P(x) ¬Q(a, y) ¬R(y, x) P(x), Q(a, b) ¬R(b, x) P(x) σ = { y ≈ b } CPSC 433 Artificial Intelligence
Resolution Example 3: • Negate goal, add to folmulas • Resolve (4) and (2) • Resolve (6) and (3) 1. ¬P(x) P(f(x)) 2. ¬Q(a, y) ¬R(y, x) P(x) 3. R(b, g(a, z)) 4. Q(a, b) 5. ¬P(f(g(a, c))) 6. ¬R(b, x) P(x) CPSC 433 Artificial Intelligence
Resolution Example 3: • Negate goal, add to folmulas • Resolve (4) and (2) • Resolve (6) and (3) 1. ¬P(x) P(f(x)) 2. ¬Q(a, y) ¬R(y, x) P(x) 3. R(b, g(a, z)) 4. Q(a, b) 5. ¬P(f(g(a, c))) 6. ¬R(b, x) P(x) ¬R(b, x) P(x), R(b, g(a, z)) P(g(a, z)) σ = { x ≈ g(a,z) } CPSC 433 Artificial Intelligence
Resolution Example 3: • Negate goal, add to folmulas • Resolve (4) and (2) • Resolve (6) and (3) 1. ¬P(x) P(f(x)) 2. ¬Q(a, y) ¬R(y, x) P(x) 3. R(b, g(a, z)) 4. Q(a, b) 5. ¬P(f(g(a, c))) 6. ¬R(b, x) P(x) 7. P(g(a, z)) ¬R(b, x) P(x), R(b, g(a, z)) P(g(a, z)) σ = { x ≈ g(a,z) } CPSC 433 Artificial Intelligence
Resolution Example 3: • Negate goal, add to folmulas • Resolve (4) and (2) • Resolve (6) and (3) • Resolve (7) and (1) 1. ¬P(x) P(f(x)) 2. ¬Q(a, y) ¬R(y, x) P(x) 3. R(b, g(a, z)) 4. Q(a, b) 5. ¬P(f(g(a, c))) 6. ¬R(b, x) P(x) 7. P(g(a, z)) CPSC 433 Artificial Intelligence
Resolution Example 3: • Negate goal, add to folmulas • Resolve (4) and (2) • Resolve (6) and (3) • Resolve (7) and (1) 1. ¬P(x) P(f(x)) 2. ¬Q(a, y) ¬R(y, x) P(x) 3. R(b, g(a, z)) 4. Q(a, b) 5. ¬P(f(g(a, c))) 6. ¬R(b, x) P(x) 7. P(g(a, z)) P(g(a, z)), ¬P(x) P(f(x)) P(f(g(a,z))) σ = { x ≈ g(a,z) } CPSC 433 Artificial Intelligence
Resolution Example 3: • Negate goal, add to folmulas • Resolve (4) and (2) • Resolve (6) and (3) • Resolve (7) and (1) 1. ¬P(x) P(f(x)) 2. ¬Q(a, y) ¬R(y, x) P(x) 3. R(b, g(a, z)) 4. Q(a, b) 5. ¬P(f(g(a, c))) 6. ¬R(b, x) P(x) 7. P(g(a, z)) 8. P(f(g(a, z))) P(g(a, z)), ¬P(x) P(f(x)) P(f(g(a,z))) σ = { x ≈ g(a,z) } CPSC 433 Artificial Intelligence
Resolution Example 3: • Negate goal, add to folmulas • Resolve (4) and (2) • Resolve (6) and (3) • Resolve (7) and (1) • Resolve (8) and (5) 1. ¬P(x) P(f(x)) 2. ¬Q(a, y) ¬R(y, x) P(x) 3. R(b, g(a, z)) 4. Q(a, b) 5. ¬P(f(g(a, c))) 6. ¬R(b, x) P(x) 7. P(g(a, z)) 8. P(f(g(a, z))) CPSC 433 Artificial Intelligence
Resolution Example 3: • Negate goal, add to folmulas • Resolve (4) and (2) • Resolve (6) and (3) • Resolve (7) and (1) • Resolve (8) and (5) 1. ¬P(x) P(f(x)) 2. ¬Q(a, y) ¬R(y, x) P(x) 3. R(b, g(a, z)) 4. Q(a, b) 5. ¬P(f(g(a, c))) 6. ¬R(b, x) P(x) 7. P(g(a, z)) 8. P(f(g(a, z))) P(f(g(a, z))), ¬P(f(g(a, c))) □ σ = { z ≈ c } CPSC 433 Artificial Intelligence
Resolution Example 3: • Negate goal, add to folmulas • Resolve (4) and (2) • Resolve (6) and (3) • Resolve (7) and (1) • Resolve (8) and (5) • Search complete, goal proved 1. ¬P(x) P(f(x)) 2. ¬Q(a, y) ¬R(y, x) P(x) 3. R(b, g(a, z)) 4. Q(a, b) 5. ¬P(f(g(a, c))) 6. ¬R(b, x) P(x) 7. P(g(a, z)) 8. P(f(g(a, z))) 9. □ CPSC 433 Artificial Intelligence