Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 19

Unification

The objective of the unification procedure is to discover at least one


substitution that cause two literals to match.
Usually there are more than one possible substitution.
The output of the unification algorithm is a list representing the composition
of the substitutions that were performed during the match.
The algorithm returns the most general unifier (mgu).
2. P(x,x)
P(y,z)

Output: (z/y)(y/x)
3. man(john) not man(spot) can not be unified as the
arguments are constants.
4. tryassassinate(marcus,ceasar)
hate(marcus,ceasar) cannot be unified as the
predicate names are not same
Algorithm: Unify (L1, L2)
1. If L1 or L2 is a variable or constant, then:
(a) If L1 and L2 are identical, then return NIL.
(b) Else if L1 is a variable, then if L1 occurs in L2 then
return FAIL, else return {(L2/L1)}.
(c) Else if L2 is a variable, then if L2 occurs in L1 then
return FAIL, else return {(L1/L2)}.
(d) Else return FAIL.
2. If the initial predicate symbols in L1 and L2 are not
identical, then return FAIL.
Algorithm: Unify (L1, L2)
3. If L1 and L2 have a different number of arguments, then
return FAIL.
4. Set SUBST to NIL.
5. For i <-1 to number of arguments in L1:
(a) Call Unify with the i-th argument of L1 and the i-th
argument of L2, putting result in S.
(b) If S = FAIL then return {FAIL}.
(c) If S is not equal to NIL then:
i. Apply S to the remainder of both L1 and L2.
ii. SUBST := APPEND(S, SUBST)
6. Return SUBST.
1. f(x , x)
f(g(x) , g(x))
If we accepted g(x) as a substitution for x, then we would have to substitute
it for x in the reminder of the expressions.
But this leads to infinite recursion since it will never be possible to eliminate x.
2. ( f(g(x,y),c), f(g(f(d,x),z),c) ) not unifiable
3. mgu( h(c,d,g(x,y)), h(z,d,g(g(a,y),z)) ) c/z, g(a, y)/x, c/y unifiable
Examples:
1. p(X,Y,Y) with p(a,Z,b)
2. foo(X,a,goo(Y)) foo(fred,a,goo(Z))
where fred is substituted for X and Z for Y,
i.e., { fred/X, Z/Y }
3. foo(W,a,goo(jack)) where { W/X,
jack/Y }
4. foo(Z,a,goo(moo(Z))) where { Z/X,
moo(Z)/Y }
5.p(X,X) ; p(Y,f(Y))
6. p(foo(X), Y) and p(a, b)
7. p(Y, Y) and p(a, Y)

8. p(f(X),a) p(Y,f(w))

9. p(f(X),Z) p(Y,a)

10. p(a,X,h(g(Z))) ; p(Z,h(Y),h(Y))

11. p(f(a), g(X)) ; p(Y,Y)


Resolution in Predicate Logic
Two literals are contradictory if one of them can be unified with the negation of
the other.
We use the unification algorithm to locate pairs of literals that cancel out.
We also need to use the unifier produced by the unification algorithm to generate
the resolvent clause.
Example:
1. man(Marcus)
2.man(x1) V mortal(x1)
yields the substitution:
Marcus / x1
So it does not yield the resolvent:
mortal(x1)
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)

Goal: P(f(g(a, c)))

You might also like