CS 342 Lecture -*- Outline -*- * Logical variables and unification ** logical variables used to abstract from specific (facts or queries): ?- object(event1,X). X = paper yes ground term: has no variables ** substitutions and instances *** substitution map from variables to terms, such variables in domain do not occur in range. *what prolog prints out (part of the substitution). e.g., s: {X, Y} -> {algol, father(me,dad)} such that s[[X]] = algol, s[[Y]] = father(me,dad). empty: {} -> {} counterexample: bad: {X} -> {X} *** instance of a term result of applying a substitution whose domain includes variables in the term e.g., father(me,dad) is an instance of father(X,dad). question asks for substitution with instance in facts. ?- father(X,dad). X = me yes ** 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). e.g., foo(X,3,Y). ?- foo(0,X,X). X = 3 % this is the X of the question % the one in the fact is bound to 0 *** common instance of two terms: term which is instance of both e.g., plus(0,3,3) is common instance of plus(0,3,Y) and plus(0,X,X) *** generality 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). 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 % i.e., X's internal name Z = _0 most general unifier (mgu): unifier that generates most general common instance efficiency: computation of mgu linear in size of the smallest term