cs345-9

2 unifythatheadwithanysubgoalsofany

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cessary Technique: Unification x We unify two atoms by finding the simplest substitution for the variables that makes them identical. x Linear­time algorithm known. 18 Example x The unification of p(f(X,Y), Z) and p(A,g(B,C)) is p(f(X,Y),g(B,C)). x Uses A ­> f(X,Y); Z ­> g(B,C); identity mapping on other variables. x p(X,X) and p(Y,f(Y)) have no unification. x Neither do p(X) and q(X). 19 Elimination of Function Symbols x Repeat: 1. Take any rule with function symbol(s) in the head. 2. Unify that head with any subgoals, of any rule, with which it unifies. x But first make head variables be new,unique symbols. x Finally, replace IDB predicates + function­symbol patterns by new predicates. 20 Example r1: manc(X,Y) :- m(X,Y) r2: manc(X,Y) :- f(X,Z) & manc(Z,Y) r3: manc(X,Y) :- m(X,Z) & manc(Z,Y) r4: f(X,g(X,Y)) :- v1(X,Y) r5: m(g(X,Y),Y) :- v1(X,Y) r6: m(X,Y) :- v2(X,Y) Unify 21 Example ­­­ (2) r2: manc(X,Y) :- f(X,Z) & manc(Z,Y) r4: f(A,g(B,C)) :r7: manc(X,Y) :- f(X,g(B,C)) & manc(g(B,C),Y) Important point: in the unification of X and A, any variable could be used, but it must appear in both these places. 22 Example ­­­ (3) r1: manc(X,Y) :- m(X,Y) r3: manc(X,Y) :- m(X,Z) & manc(Z,Y) r5: m(g(A,B),C) :r8: manc(g(A,B),Y) :- m(g(A,B),Y) r9:manc(g(A,B),Y) :- m(g(A,B),Z) & manc(Z,Y) 23 Example ­­­ (4) x Now we have a new pattern: manc(g(A,B),C) . x We must unify it with manc subgoals in r2, r3, r7, and r9. x r2 and r7 yield nothing new, but r3 and r9 do. 24 Example ­­­ (5) r3: manc(X,Y) :- m(X,Z) & manc(Z,Y) r9:manc(g(A,B),Y) :- m(g(A,B),Z) & manc(Z,Y) manc(g(C,D),E) r10: manc(X,Y) :- m(X,g(A,B)) & manc(g(A,B),Y) r11: manc(g(A,B),Y) :m(g(A,B),g(C,D)) & manc(g(C,D),Y) 25 Cleaning Up the Rules 1. For each IDB predicate (manc in our example) introduce a new predicate for each fun...
View Full Document

Ask a homework question - tutors are online