CS 541 Lecture -*- Outline -*- * Unification Problem with the logical basics of prolog from the point of view of computation is that one has to make guesses to match existential queries against universally quantified rules unification takes care of that... ** comparing terms note: since scope of variables is limited to a clause, always comparing two terms with different variables (may look the same to you, but internally different). -------------- foo(X,3,Y). ?- foo(0,X,X). X = 3 % this is the X of the question, one in fact bound to 0 -------------- *** generality def: a term T is more general than a term V if V is an instance of T, but T is not an instance of V. (they are alphabetic variants if both instances of each other) *** unifier: a subsitution that makes two terms identical. determines a common instance (by applying the substitution). terms that have a unifier are said to unify -------------------- star(algol). ?- star(X). X = algol % star(X) unifies with star(algol) % by substituion s(X)=algol g(X,3). ?- g(4,Y). Y = 3 % and (X = 4) not shown h(X,X). ?- h(Y,Z). Y = _0 % and X = _0 is not shown. Z = _0 % they can all be anything as long as it's the same. ---------------------- **** def: most general unifier (mgu) is a unifier that generates most general common instance efficiency: computation of mgu linear in size of the smallest term **** def: an occurs check ensures that the two terms being unified have no variables in common most practical unification algorithms omit occurs check, if they don't it's not linear... ** exercises ------- For each of the following pairs, compute the mgu, if any member(3,[3]) member(X,[X]) member(Y,[3]) member(X,[X]) member(3,[4]) member(X,[X|L]) length([3],N) member(X,[X|L]) member(X,[X |L]) member(Y,[tree(Y,[],[])|M]) -------