| OCR Text |
Show 113 6.2.1 A General Semantic Unification Algorithm The process of unifying two terms can be viewed as one of solving simultaneous equations [83]. For example, the problem of unifying f {s 1, ... ,sn) wit h f{t 1 , ... ,tn) is equivalent to solving the set of equations {s 1 =t 1 , s2=t2, .. . , sn =tn}. A solution of these equations, if one exists, is of the form { x1 =p1, x2=p2, ... , xm =pm} where the xi are variables and the pi are terms. In conventional unification, an equation g(t 1 , .. . ,tP) = g'(s 1, .. . sq) is not solvable if g and g' are not identical or if p ~ q, since g and g' are both treated as constructors. In contrast, semantic unification allows either g or g' or both (or any function symbol in the equation) to be functions that are defined in EQN. Two terms are semantically unifiable if there exist semantically equivalent forms (obtained by reduction(s) on any reducible term in the equation) which are unifiable. An algorithm reflecting this idea is given in Figure 18.* The facility of using reduction to simulate equality of function terms has limited power: certain restrictions must be imposed in order not to lose completeness. One such restriction is that the function terms involved in the two input terms must be ground. (We call that a term f(t 1, ... ,tn) is a function term if f is defined in EQN.) However, this is quite adequate for the programming features we advocate in this chapter. Recall that our initial goal was to combine functional programming and logic programming. Functional programming in this context does not completely subsume the facility of "reasoning about equations." For example, consider the two terms p(f(X)) and p(g(Y) ), and an equation f(a} = g(b}. Although there exists a substitution rr = {x = a} such that rr(p(f(x)}) is equivalent to p(g(b}} (since f(a} can reduce to g(b) after the substitution), which is unifiable with p(g(Y)) with Y bound to b, the notion of semantic unification cannot handle such situations. A more powerful computational mechanism is needed; for example, the narrowing method described in [73]. We will come back to this point a little later in Section 6.2.2. * We ignore the so called occur checks [17). |