• Aucun résultat trouvé

Equational unication in Denali

3.3 Moded equational resolution

3.3.2 Mode restriction anomaly

To this point we have maintained two separate phases of the resolution reduction of a query. First a unier is obtained, and then that unier is applied to the remainder of the query. This separation is not necessary and can actually be counterproductive.

Eliminating the separation leads to a more robust evaluation strategy.

The mode restriction upon a unication predicate leads to an anomaly when it is stricter thanany. Because variables are always of modeany, such a restriction explicitly forbids attempts to unify variables. For example, since the list unication restrictions require that one of the terms be of mode enum, the attempted unication of two list variables, as in

listUnify(L1;L2)

is ill-moded and cannot be solved.

Since two variables can always be directly unied, regardless of the underlying equa-tional theory, imposing mode restrictions upon unication appears to have a serious drawback. We will now evaluate possible solutions to the problem.

Sometimes the apparent need to unify a pair of variables can be avoided because of the ordering eects of modes. One of the variables can become suciently instantiated before the unication literal must be evaluated. This can be illustrated with the predicate prex:

3.3. Moded equational resolution 63 prex =

pred

(list;list)

moding

(enum;any)

prex(append(L1;L2);L1)

This predicate relates the rst argument to its prexes. It can be invoked, for example, with the query query

prex(cons(0;nil);L).

The rst unication step in reducing this query is the query listUnify(cons(0;nil);append(L1;L2));listUnify(L1;L).

Even though the second literal is ill-moded, the rst one is not and can be solved. It has multiple solutions, and in one case leads to

listUnify(cons(0;nil);L),

which is now well-moded and can be solved to yield a solution.

Unfortunately, not all attempts to unify variables can be avoided in this way. To illustrate this, we dene another predicate,

nPrex =

pred

(list;nat;list)

moding

(enum;gnd;any) nPrex(L3;N;L4) prex(L3;L4);length(L4;N).

This predicate reports only prexes of the specied length. As before, the rst step in solving the query

nPrex(cons(0;nil);1;L), involves solving the unication query

listUnify(cons(0;nil);L3);natUnify(1;N);listUnify(L;L4).

Solving the rst two well-moded unication literals does not further instantiate the ill-moded literal, and a mode failure results.

One potential solution to the problem is to treat variable unication as a special case, and always permit it regardless of mode restrictions. Although this solution is appealing in its simplicity, it is defective and cannot be adopted.

Recall that we require that well-modedliterals remainwell-moded under instantiation.

If the variable exception were exploited in the solution of a unication query, it might be possible to instantiate one or both of the variables involved so that the exception no longer applied but the unication literal became ill-moded. For example, even if the variable exception were exploited to solve the query above, solving the query instance

64 3. Equational unication in Denali nPrex(cons(0;nil);1;cons(0;L),

would now lead to a mode failure. Because we want to ensure that the solvability of queries is invariant under instantiation, we reject the simplistic solution.

Fortunately, we can go far toward solving the problem by eliminating the arbitrary division between the unication and reduction steps that is present in our evaluation strategy. Instead, we permit the intermixing of the solution of unication and clause literals. This provides a greater opportunity for one term of a non-uniable pair to become further instantiated.

This change permits the solution of the query above. The rst step in the solution is to form the joint unication/body query:

listUnify(cons(0;nil);L3);natUnify(1;N);

listUnify(L;L4);prex(L3;L4);length(L4;N).

The rst two unication literals can be solved immediately, leading to listUnify(L;L4);prex(cons(0;nil);L4);length(L4;1).

Now, even though the remaining unication literal is ill-moded, theprex and then the length literals can be solved, leading to

listUnify(L;cons(0;nil)).

The unication literal is now well-moded and can be solved, yielding a solution.

The modication to the evaluation strategy described above does not always succeed in preventing mode failure due to attempts to unify pairs of variables. It often does, however, because the inclusion of a variable in a literal is usually a technique for obtaining output from the evaluation of the literal. The modication strictly enlarges the class of queries that could be solved under the old strategy without changing the evaluation of any previously solvable queries. Finally, the change is not particular to pairs of variables.

It helps prevent unication-related mode failures for all terms.

3.4 Related work

Kornfeld [Kornfeld 86] was one of the rst to suggest the power of incorporating equality constraints into Prolog. His observations have inspired a number of other eorts in this direction. He incorporates equality by allowing the Prolog unication procedure to invoke

3.4. Related work 65 Lisp procedures whenever unication fails. This ad hoc approach has no sound formal basis.

Eqlog [Goguen 86] is closely related to our work, as it incorporates equational uni-cation in much the same way as Denali. Its approach to obtaining implementations of equational unication, however, is completely dierent. Instead of relying upon a set of pragmatic techniques for simplifying the unication problem, Eqlog relies upon the narrowing procedure [Fay 79] to compile sets of equations into unication procedures.

Unfortunately, the narrowing procedure is primarily of theoretical interest, as it is gener-ally nonterminating and usugener-ally produces inecient implementations. Furthermore, it is applicable only to sets of equations that can be converted into a canonical set of rewrite rules, and does not exploit modes. Under the narrowing procedure, the programmer has little control over or intuition about the eciency characteristics of unication.

Tablog [Malachi 86] is a logic language based upon the Manna-Waldinger deductive-tableau proof system [Manna 80]. This proof system explicitly handles equations as well as clauses. The language was designed and implemented as a demonstration that a logic programming language can be based upon something other than the resolution procedure.

Its treatment of equality is incomplete, however, as it makes an asymmetrical distinction between primitive and denedfunction symbols.

SLOG [Fribourg 84] is a logic language in which only one predicate may be dened by a programmer. This predicate is equality. Queries are solved with a variant of resolution called innermost superposition. The equality predicate is used to reduce not only entire literals but also inner terms.

4

Data abstraction