by Francisco Durán, Santiago Escobar and Salvador Lucas.
The ability of dealing with infinite objects is typical of lazy (functional) languages. Although the reductions in Maude are basically innermost (or eager), Maude is able to exhibit a similar behavior by using strategy annotations (see [Lucas03a]).
Maude strategy annotations are lists of non-negative integers associated to function symbols which specify the ordering in which the arguments are (eventually) evaluated in function calls: when considering a function call f(t1,...,tk), only the arguments whose indices are present as positive integers in the local strategy (i1 ··· in) for f are evaluated (following the specified ordering). If 0 is found, a reduction step on the whole term f(t1,...,tk) is attempted. The introduction of "true" replacement restrictions (i.e., that forbid reductions on some arguments) is often sufficient to ensure (and even prove) a terminating behavior of a Maude program even though some expressions that denote an infinite object are involved (see [Lucas03b] for an overview of methods to formally prove termination in these cases).
Full Maude is a language extension of Maude written in Maude itself, that endows Maude with notation for object-oriented programming and with a powerful and extensible module algebra in which Maude modules can be combined together to build more complex modules [DM98,Duran99,CDELMMQ02]. Every Maude module can be loaded in Full Maude by just enclosing it into parentheses. Then, the usual evaluation commands of Maude (e.g., reduce, rewrite, etc.) are available in Full Maude by also enclosing them into parentheses.
As a first example, let us consider the following parameterized modules LAZY-LIST and LIST-OF-NATS. Module LAZY-LIST provides a "polymorphic" sort List(X), and symbols nil (the empty list) and _._ for the construction of polymorphic lists. And module LIST-OF-NATS provides a a function natsFrom, which is able to generate the infinite list of natural numbers.
(fth TRIV is sort Elt . endfth) (fmod LAZY-LIST(X :: TRIV) is protecting INT . sort List(X) . subsort X@Elt < List(X) . op nil : -> List(X) [ctor] . op _._ : X@Elt List(X) -> List(X) [ctor strat (1 0)] . op take : Int List(X) -> List(X) . var N : Int . var X : X@Elt . var Z : List(X) . eq take(0, Z) = nil . eq take(N, X . Z) = X . take(N - 1, Z) . endfm) (view Nat from TRIV to NAT is sort Elt to Nat . endv) (fmod LIST-OF-NATS is protecting LAZY-LIST(Nat) . op natsFrom : Nat -> List(Nat) . var N : Nat . eq natsFrom(N) = N . natsFrom(N + 1) . endfm)
Note the strategy (1 0) associated to the constructor symbol _._, which forbids replacements on its second argument. Given a term of the form X . L, the strategy indicates that its first argument, the subterm X, will first be reduced, and then a reduction step on the whole term would be attempted. The LAZY-LIST module also includes a typical polymorphic operator take which selects the first n components of a list. Even though take has no explicit strategy annotation, Maude internally assigns a by default one (1 2 0). In fact, Maude gives a strategy annotation (1 2 ··· k 0) to each symbol f without an explicit strategy annotation.
Thanks to the strategy annotation (1 0) for the list constructor, after entering these modules into Full Maude, we can evaluate, e.g., the expression take(4, natsFrom(0)) without entering into a non-terminating computation.
Maude> (red take(4, natsFrom(0)) .) reduce in LIST-OF-NATS : take(4, natsFrom(0)) result List`(Nat`) : 0 . take(4 - 1, natsFrom(0 + 1))This example shows a weak point of the use of strategy annotations: they may cause that the normal form(s) of input expressions become unreachable; since the normal form 0 . 1 . 2 . 3 of take(4, natsFrom(0)) is not obtained. In fact, from the user's point of view, this could be thought of as a kind of incorrect evaluation also, when normal forms are expected as the result of a computation. Removing the strategy annotations from module LAZY-LIST is not a solution (we would get a non-terminating program). On the other hand, there are different approaches to solve this problem and they can be summarized as follows:
In this piece of work, we introduce new commands to make normalization via layered normalization and program transformation available for the execution of Maude programs. Both commands are made available in Full Maude 2.0 as Core Maude 2.0 programs which extend some Full Maude modules. See [DEL04] for details. Note that on-demand strategy annotations has also been directly available in Maude at this other link.
We have implemented the normalization via layered evaluation procedure as a new command norm which uses the outcome of usual Maude command red to perform the layered evaluation of the initial expressions. The new command permits to obtain the intended value of the previous expression take(4, natsFrom(0)).
Maude> (norm take(4, natsFrom(0)) .) reduce in LIST-OF-NATS : take(4, natsFrom(0)) result List`(Int`) : 0 . 1 . 2 . 3 . nil
And we have implemented the normalization via program transformation procedure as a new command eval which transforms the original program into another one where the command red is able to obtain the intended normal form associated to the term given to eval (see [AEL02] for further information).
Maude> (eval take(4, natsFrom(0)) .) transforming module LIST-OF-NATS for symbol take transformed module QLIST-OF-NATS is complete for defined symbols: take reduce in QLIST-OF-NATS : unquote(quote(take(4, natsFrom(0)))) result List`(Nat`) : 0 . 1 . 2 . 3 . nilFull Maude and its execution environment are implemented using the reflective capabilities of Maude. In fact, reflection, together with the good properties of rewriting logic as a logical framework [MM02,Meseguer99], makes quite easy to develop formal tools and execution environments in Maude for any logic L of interest, including rewriting logic itself (see e.g. [Duran99,CDEMS99]). More attractive for our goals is the greater flexibility, maintainability, and extensibility that the implementation obtained in this way affords. In particular, in the same way commands like reduce, search, or match can be implemented in Full Maude, we could make new commands available. This is in fact what we have done, and what we present in this piece of work. Of course, instead of making direct calls to metaReduce, metaSearch, or metaMatch, as in the case of the above commands, we shall need to take the appropriate actions for each of them: to define a new rewriting strategy in the case of the norm command (technique 1) or to provide the appropriate transformation in the case of the eval command (technique 2).
First, download the Full Maude file full-maude.maude if it is not already present in the local installation of Maude.
Second, download the following Maude file with auxiliary functions utils.maude.
Third, download the appropriate Maude files:
To make both commands available at the same time, download the Maude file norm-eval.maude, the UNIX shell command fmaude-norm-eval norm-eval.maude and the two previous files norm.maude anD eval.maude.
The example used in the description section above is available here for testing the implementation.
[AEGL02]
M. Alpuente, S. Escobar, B. Gramlich, and S. Lucas.
Improving on-demand strategy annotations.
In Matthias Baaz and Andrei Voronkov, editors, Proc. 9th Int.
Conf. on Logic for Programming, Artificial Intelligence, and Reasoning
(LPAR'02), Lecture Notes in Computer Science, Tbilisi, Georgia, October
2002. Springer-Verlag.
[WRLA02]
M. Alpuente, S. Escobar, S. Lucas.
Correct and Complete (Positive) Strategy Annotations for OBJ.
4th Int'l Workshop on Rewriting Logic and its Applications (WRLA 2002), Pisa (Italy).
Electronic Notes on Theoretical Computer Science, Vol. 71. To appear 2003.
[CDEMS99]
M. Clavel, F. Durán, S. Eker, J. Meseguer, and M.-O. Stehr.
Maude as a formal meta-tool.
In J. Wing, J. Woodcock, and J. Davies, editors,
FM'99 - Formal Methods (Vol. II),
volume 1709 of Lecture Notes in Computer Science,
pages 1684--1704. Springer-Verlag, 1999.
[CDELMMQ02]
M. Clavel, F. Durán, S. Eker, P. Lincoln, N. Martí-Oliet, J. Meseguer,
and J. Quesada.
Maude: specification and programming in rewriting logic.
Theoretical Computer Science 285(2):187-243, 2002.
[Duran99]
F. Durán.
A Reflective Module Algebra with Applications to the Maude Language.
PhD thesis, Universidad de Málaga, June 1999.
[DEL04]
F. Durán, S. Escobar, S. Lucas.
New evaluation commands for Maude within Full Maude.
In Proc. of 5th International Workshop on Rewriting Logic and its Applications,
WRLA'04, ENTCS to appear, 2004.
[DM98]
F. Durán and J. Meseguer.
An extensible module algebra for Maude.
In C. Kirchner and H. Kirchner, editors, Proceedings
of 2nd International Workshop on Rewriting Logic and its Applications
(WRLA'98), volume 15 of Electronic Notes in Theoretical Computer Science, pages 185--206. Elsevier, 1998.
[Lucas02a]
S. Lucas.
Context-sensitive rewriting strategies.
Information and Computation, 178(1):293-343, 2002.
[Lucas02b]
S. Lucas.
Termination of (Canonical) Context-Sensitive Rewriting.
In S. Tison, editor, Proc. 13th International
Conference on Rewriting Techniques and Applications, RTA'02, Lecture Notes in
Computer Science 2378:296-310, Springer, 2002.
[Lucas03a]
S. Lucas.
Semantics of programs with strategy annotations.
Technical Report DSIC-II/08/03, DSIC, Universidad Politécnica de
Valencia, 2003.
[Lucas03b]
S. Lucas.
Termination of programs with strategy annotations.
Technical Report DSIC II/20/03, Universidad Politécnica de
Valencia, Sep. 2003.
[Meseguer99]
J. Meseguer.
Research directions in rewriting logic.
In U. Berger and H. Schwichtenberg, editors, Computational
Logic. Springer-Verlag, 1999.
[MM02]
N. Martí-Oliet and J. Meseguer.
Rewriting logic as a logical and semantic framework.
volume 9, pages 1--87. Kluwer Academic Publishers, second edition,
2002.
ELP | GPLIS | DSIC | UPV |
Last update October 13 2004 # sescobar@dsic.upv.es