Improving On-Demand Strategy Annotations

18

Transcript of Improving On-Demand Strategy Annotations

Improving On-Demand Strategy Annotations?M. Alpuente1, S. Escobar1, B. Gramlich2, and S. Lucas11 DSIC, UPV, Camino de Vera s/n, E-46022 Valencia, Spain.falpuente,sescobar,[email protected] AG Theoretische Informatik und Logik, Institut f�ur Computersprachen,TU Wien, Favoritenstr. 9, E185/2 A-1040 Wien, [email protected]. In functional languages such as OBJ*, CafeOBJ, and Maude,symbols are given strategy annotations which specify (the order in) whichsubterms are evaluated. Syntactically, they are given either as lists of nat-ural numbers or as lists of integers associated to function symbols whose(absolute) values refer to the arguments of the corresponding symbol.A positive index enables the evaluation of an argument whereas a nega-tive index means \evaluate on-demand". While strategy annotations con-taining only natural numbers have been implemented and received somerecent investigation endeavor (regarding, e.g., termination and complete-ness), fully general annotations (also called on-demand strategy anno-tations), which have been proposed to support laziness in OBJ-like lan-guages, are disappointingly under-explored to date. In this paper, we�rst point out a number of problems of current proposals for handlingon-demand strategy annotations. Then, we propose a solution to theseproblems which is based on a suitable extension of the E-evaluationstrategy of OBJ-like languages (that only considers annotations given asnatural numbers) to on-demand strategy annotations. Our strategy in-corporates a better treatment of demandness and also exhibits good com-putational properties; in particular, we show how to use it for comput-ing (head-)normal forms. We also introduce a transformation for provingtermination of the new evaluation strategy by using standard techniques.Keywords: Declarative programming, demandness, lazy evaluation, OBJ,on-demand strategy annotations1 IntroductionEager rewriting-based programming languages such as Lisp, OBJ*, CafeOBJ,ELAN, or Maude evaluate expressions by innermost rewriting. Since nontermi-nation is a known problem of innermost reduction, syntactic annotations (gen-erally speci�ed as sequences of integers associated to function arguments, calledlocal strategies) have been used in OBJ2 [FGJM85], OBJ3 [GWM+00], CafeOBJ[FN97], and Maude [CELM96] to improve e�ciency and (hopefully) avoid non-termination. Local strategies are used in OBJ programs1 for guiding the evalu-ation strategy (abbr. E-strategy): when considering a function call f(t1; : : : ; tk),? Work partially supported by CICYT TIC2001-2705-C03-01, Acciones IntegradasHI2000-0161, HA2001-0059, HU2001-0019, and Generalitat Valenciana GV01-424.1 As in [GWM+00], by OBJ we mean OBJ2, OBJ3, CafeOBJ, or Maude.

only the arguments whose indices are present as positive integers in the localstrategy for f are evaluated (following the speci�ed ordering). If 0 is found,then the evaluation of f is attempted. The limits of using only positive annota-tions regarding correctness and completeness of computations are discussed in[AEL02,Luc01,Luc02b,OF00,NO01]: the obvious problem is that the absence ofsome indices in the local strategies can have a negative impact in the ability ofsuch strategies to compute normal forms.Example 1. Consider the following OBJ program (borrowed from [NO01]):obj Ex1 issorts Nat LNat .op 0 : -> Nat .op s : Nat -> Nat [strat (1)] .op nil : -> LNat .op cons : Nat LNat -> LNat [strat (1)] .op 2nd : LNat -> Nat [strat (1 0)] .op from : Nat -> LNat [strat (1 0)] .vars X Y : Nat . var Z : LNat .eq 2nd(cons(X,cons(Y,Z))) = Y .eq from(X) = cons(X,from(s(X))) .endoThe OBJ evaluation of 2nd(from(0)) is given by the sequence:2nd(from(0)) ! 2nd(cons(0,from(s(0))))The evaluation stops here since reductions on the second argument of cons aredisallowed. Note that we cannot apply the rule de�ning 2nd because the subtermfrom(s(0)) should be further reduced. Thus, a further step is demanded (by therule of 2nd) in order to obtain the desired outcome:2nd(cons(0,from(s(0)))) ! 2nd(cons(0,cons(s(0),from(s(s(0))))))Now, we do not need to reduce the second argument of the inner occurrence ofcons anymore, since reducing at the root position yields the �nal value:2nd(cons(0,cons(s(0),from(s(s(0))))) ! s(0)Therefore, the rather intuitive notion of demanded evaluation of an argu-ment of a function call (see [AL02] for a survey discussing this topic) arises as apossible solution to this problem. In [OF00,NO01], negative indices are proposedto indicate those arguments that should be evaluated only `on-demand', wherethe `demand' is an attempt to match an argument term with the left-hand sideof a rewrite rule [Eke98,GWM+00,OF00]. For instance, in [NO01] the authorssuggest (1 -2) as the \apt" local strategy for cons in Example 1. The inspira-tion for the local strategies of OBJ comes from lazy rewriting (LR) [FKW00],a demand-driven technique where syntactic annotations allow the eager evalu-ation of function arguments, whereas the default strategy is lazy. However, theextended, on-demand E-strategy of [OF00,NO01] presents a number of draw-backs, which we formally address in the paper. The following example illustratesthat the notion of demandness which is formalized in [NO01] needs to be re�nedto be entirely satisfactory in practice. 2

Example 2. Consider the following OBJ program:obj Ex2 issorts Nat LNat .op 0 : -> Nat .op s : Nat -> Nat [strat (1)] .op nil : -> LNat .op cons : Nat LNat -> LNat [strat (1)] .op from : Nat -> LNat [strat (1 0)] .op length : LNat -> Nat [strat (0)] .op length' : LNat -> Nat [strat (-1 0)] .var X : Nat . var Z : LNat .eq from(X) = cons(X,from(s(X))) .eq length(nil) = 0 .eq length(cons(X,Z)) = s(length'(Z)) .eq length'(Z) = length(Z) .endoThe expression length'(from(0)) is rewritten (in one step) to length(from(0)).No evaluation is demanded on the argument of length' for enabling this stepand no further evaluation on length(from(0)) should be performed due tothe local strategy (0) of length. However, the annotation (-1 0) of functionlength' is treated in such a way that the on-demand evaluation of the expressionlength'(from(0)) yields an in�nite sequence (whether2 we use the operationalmodel3 in [OF00] or whether we use [NO01]). This is because the negative an-notations are implemented as marks on terms which can (unproperly) initiatereductions later on; see Example 3 below.In this paper, after some preliminaries in Section 2, in Section 3 we recall thecurrent proposals for dealing with on-demand E-strategy annotations in OBJlanguages and discuss some drawbacks regarding the treatment of demandness.In Section 4 we (re-)formulate the computational model of on-demand strategyannotations by handling demandness in a di�erent way. We demonstrate thatthe new on-demand strategy outperforms the original one. We also show thatour de�nition behaves better than lazy rewriting (LR) regarding the ability tocompute (head-)normal forms. Section 5 introduces a transformation which canbe used to formally prove termination of programs that use our computationalmodel for implementing arbitrary strategy annotations. Section 6 concludes andsummarizes our contributions.2 PreliminariesGiven a set A, P(A) denotes the set of all subsets ofA. Let R � A�A be a binaryrelation on a set A. We denote the transitive closure by R+ and its re exive andtransitive closure by R� [BN98]. An element a 2 A is an R-normal form, if there2 Actually, the operational models in [OF00] and [NO01] di�er and deliver di�erentcomputations, see Example 4 below.3 Negative annotations are (syntactically) accepted in current OBJ implementations,namely OBJ3 and CafeOBJ, but they have no e�ect over the computations.3

exists no b such that a R b. We say that b is an R-normal form of a (writtena R! b), if b is an R-normal form and a R�b. Throughout the paper, X denotesa countable set of variables and F denotes a signature, i.e. a set of functionsymbols ff; g; : : :g, each having a �xed arity given by a function ar : F ! N.We denote the set of terms built from F and X by T (F ;X ). A term is said tobe linear if it has no multiple occurrences of a single variable. Terms are viewedas labelled trees in the usual way. Positions p; q; : : : 2 N�+ are represented bychains of positive natural numbers used to address subterms of t. We denotethe empty chain by �. By Pos(t) we denote the set of positions of a term t.Positions of non-variable symbols in t are denoted as PosF (t), and PosX (t) arethe positions of variables. Given positions p; q, we denote its concatenation as p:q.Positions are ordered by the standard pre�x ordering �. Given a set of positionsP , minimal�(P ) is the set of minimal positions of P w.r.t. �. The subterm atposition p of t is denoted as tjp, and t[s]p is the term t with the subterm atposition p replaced by s. The symbol labelling the root of t is denoted as root(t).A rewrite rule is an ordered pair (l; r), written l ! r, with l; r 2 T (F ;X ),l 62 X and Var(r) � Var(l). The left-hand side (lhs) of the rule is l and r isthe right-hand side (rhs). A TRS is a pair R = (F ; R) where R is a set ofrewrite rules. L(R) denotes the set of lhs's of R. A TRS R is left-linear if forall l 2 L(R), l is a linear term. Given R = (F ; R), we take F as the disjointunion F = C ] D of symbols c 2 C, called constructors, and symbols f 2 D,called de�ned functions, where D = froot(l) j l ! r 2 Rg and C = F�D. Aninstance �(l) of a lhs l 2 L(R) by any substitution � is called a redex. A termt 2 T (F ;X ) rewrites to s (at position p), written t p!R s (or just t ! s), iftjp = �(l) and s = t[�(r)]p, for l ! r 2 R, p 2 Pos(t) and substitution �.3 Rewriting with strategy annotationsA local strategy for a k-ary symbol f 2 F is a sequence '(f) of integerstaken from f�k; : : : ;�1; 0; 1; : : :; kg which are given in parentheses. We de�nean ordering v between sequences of integers as: nil v L, for all sequence L,(i1 i2 � � � im) v (j1 j2 � � � jn) if i1 = j1 and (i2 � � � im) v (j2 � � � jn), or(i1 i2 � � � im) v (j1 j2 � � � jn) if i1 6= j1 and (i1 i2 � � � im) v (j2 � � � jn).A mapping ' that associates a local strategy '(f) to every f 2 F is called anE-strategy map [Nag99,NO01]. An ordering v between strategy maps is de�ned:' v '0 if for all f 2 F , '(f) v '0(f). Roughly speaking, ' v '0 if for all f 2 F ,'0(f) is '(f) where some additional indices have been included.Semantics of rewriting under a given E-evaluation map ' is usually given bymeans of a mapping eval' : T (F ;X )! P(T (F ;X )) from terms to the set of itscomputed values (technically E-normal forms).Rewriting with positive E-strategy maps. Nagaya describes the map-ping eval' for positive E-strategy maps ' (i.e., E-strategy maps where neg-ative indices are not allowed) by using a reduction relation on pairs ht; pi of4

labelled terms t and positions p [Nag99]. Let L be the set of all lists consist-ing of integers and Ln be the set of all lists of integers whose absolute valuedoes not exceed n 2 N. Given an E-strategy map ' for F , we use the sig-nature FN' = ffL j f 2 F ; L 2 Lar(f) (L v '(f))g and labelled variablesXN' = fxnil j x 2 Xg. An E-strategy map ' for F is extended to a map-ping from T (F ;X ) to T (FN' ;XN' ) by introducing the local strategy associatedto each symbol as a subscript of the symbol. The mapping erase : T (FN' ;XN' ) !T (F ;X ) removes labellings from symbols in the obvious way. Then, given aTRS R = (F ; R) and a positive E-strategy map ' for F , eval' is de�ned aseval'(t) = ferase(s) 2 T (F ;X ) j h'(t);�iN!!'hs;�ig, where the binary relationN!' on T (FN' ;XN' ) � N�+ behaves as follows: given ht; pi, where t 2 T (FN' ;XN' )and p 2 Pos(t), if a positive index i > 0 is found in the list labelling the symbolat tjp, then the index is removed from the list, the \target position" is movedfrom p to p:i, and the subterm tjp:i is next considered. If 0 is found, then theevaluation of tjp is attempted: if possible, a rewriting step is performed; other-wise, the 0 is removed from the list. In both cases, the evaluation continues atthe same position p (see De�nition 6.1.3 of [Nag99] or De�nition 2.2 of [NO01]).The on-demand evaluation strategy. Ogata and Futatsugi [OF00] haveprovided an operational description of the on-demand evaluation strategy eval'where negative integers are also allowed in local strategies. Nakamura and Ogata[NO01] have described the corresponding evaluation mapping eval' by using areduction relation. We recall here the latter one since the former one is notappropriate for our objectives in this paper.Given an E-strategy map ', we use the signature4 F' = ffbL j f 2 F ^ L 2Lar(f):(L v '(f)) ^ b 2 f0; 1gg and labelled variables X' = fx0nil j x 2 Xg. Anon-demand ag b = 1 indicates that the term may be reduced if demanded. AnE-strategy map ' for F is extended to a mapping from T (F ;X ) to T (F';X') asfollows: '(t) = �x0nil if t = x 2 Xf0'(f)('(t1); : : : ; '(tk)) if t = f(t1; : : : ; tk) . On the other hand,the mapping erase : T (F';X') ! T (F ;X ) removes labellings from symbolsin the obvious way. The (partial) function flag : T (F';X') � N�+ ! f0; 1greturns the ag of the function symbol at a position of the term: flag(t; p) = b ifroot(tjp) = fbL. The map up : T (F';X') ! T (F';X') (resp. dn : T (F';X') !T (F';X')) raises (lowers) the on-demand ag of each function symbol in a term,i.e. up(x0nil) = dn(x0nil) = x0nil, up(fbL(t1; : : : ; tk)) = f1L(up(t1); : : : ; up(tk)), anddn(fbL(t1; : : : ; tk)) = f0L(dn(t1); : : : ; dn(tk)).When it is being examined whether a term t matches the left-hand side lof a rule, a top-to-bottom and left-to-right pattern matching is performed. Let4 Note that Nakamura and Ogata's de�nition uses FL and XL instead of F' and X',where the restriction to L v '(f) is not considered. However, using terms over F'does not entail loss of generality; furthermore, it actually provides a more accurateframework for formalizing and studying the strategy, since they are the only class ofterms involved in the computations. 5

Pos 6=(t; l) = fp 2 PosF (t) \ PosF (l) j root(ljp) 6= root(tjp)g be the set of(common) positions of non-variable disagreeing symbols of terms t and l. Then,the map dfl : T (F ;X ) ! N�+ [ f>g returns the �rst position where the termand the lhs di�er (on some non-variable position) or > if each function symbolof the term coincides with l:dfl(t) = �min�lex (Pos 6=(t; l)) if Pos 6=(t; l) 6= ?> otherwisewhere �lex is the lexicographic ordering on positions: p �lex q i� p � q orp = w:i:p0, q = w:j:q0, i; j 2 N, and i < j.Similarly, given a TRS R, the map DFR : T (F ;X )! N�+[ f>g returns the�rst position where the term di�er w.r.t. all lhs's:DFR(t) = �> if dfl(t) = > for some l! r 2 Rmax<lexfdfl(t) j l ! r 2 Rg otherwiseDe�nition 1. Given a TRS R = (F ; R) and an arbitrary E-strategy map 'for F , eval' : T (F ;X ) ! P(T (F ;X )) is de�ned as eval'(t) = ferase(s) 2T (F ;X ) j h'(t);�i !!' hs;�ig. The binary relation !' on T (F';X') � N�+is de�ned as follows ([NO01], De�nition 4.4): ht; pi !' hs; qi if and only ifp 2 Pos(t) and either1. root(tjp) = fbnil, s = t and p = q:i for some i; or2. tjp = fbi:L(t1; : : : ; tk), i > 0, s = t[fbL(t1; : : : ; tk)]p and q = p:i; or3. tjp = fb�i:L(t1; : : : ; tk), i > 0, s = t[fbL(t1; : : : ; up(ti); : : : ; tk)]p and q = p; or4. tjp = fb0:L(t1; : : : ; tk), s = t[t0]p, q = p where t0 is a term such that(a) t0 = �('(r)) if DFR(erase(tjp)) = >, tjp = �(l0), erase(l0) = l andl! r 2 R.(b) t0 = fbL(t1; : : : ; tk) if either DFR(erase(tjp)) = > and erase(tjp) is nota redex, or DFR(erase(tjp)) = �, or DFR(erase(tjp)) = p0 6= � andflag(t; p:p0) = 0;(c) t0 = fbL(t1; : : : ; ti[up(s)]p00 ; : : : ; tk) if DFR(erase(tjp)) = p0 = i:p00,flag(t; p:p0) = 1, hdn(tjp:p0);�i !!' hs;�i, and DFR(erase(tjp[s]p0)) =p0;(d) t0 = tjp[up(s)]p0 if DFR(erase(tjp)) = p0 6= �, flag(t; p:p0) = 1,hdn(tjp:p0);�i !!' hs;�i, and either p0 <lex DFR(erase(tjp[s]p0)) orDFR(erase(tjp[s]p0)) = >;Case 1 means that no more annotations are provided and the evaluation iscompleted. In case 2, a positive argument index is found and the evaluationgoes down to the subterm at such argument. In case 3, the subterm at theargument indicated by the (absolute value of the) negative index is completelymarked with on-demand ags. Case 4 considers the attempt to match the termagainst the left-hand sides of the program rules. Case 4:a applies if the considered(unlabelled) subterm is a redex (which is, then, contracted). If the subterm is nota redex, cases 4:b, 4:c and 4:d are considered possibly involving some on-demand6

evaluation steps on some subterm. The selected demanded position for term t(w.r.t. program R) is denoted as DFR(t) (eventually, symbol > is returned if tmatches the left-hand side of some rule of the TRS). According to DFR(t), case4:b applies if no demanded evaluation is allowed (or required). Cases 4:c and4:d apply if the on-demand evaluation of the subterm tjp:p0 is required. In bothcases, the evaluation is attempted; if it �nishes, the evaluation of tjp continuesaccording to the computed value.Note that the computational description of on-demand strategy annotationsabove involves recursive steps. A single reduction step on a (labelled) term tmay involve the application of more than one reduction step on subterms of t(as shown by steps 4(c) and 4(d)). In fact, the de�nition of a single rewritingstep may depend on the possibility of evaluating some arguments of the con-sidered function call. This implies that the one-step reduction relation proposedby Nakamura and Ogata is generally undecidable. Therefore, associated notionssuch as normal form (w.r.t. their reduction relation) are also undecidable.Furthermore, as remarked in our introduction, the notion of demandnessformalized in [NO01] needs to be re�ned to be entirely satisfactory in practice.Example 3. Following the Example 2. The on-demand evaluation oflength'(from(0)) yields the following in�nite sequence:hlength'0(�1 0)(from0(1 0)(00nil)); �i!' hlength'0(0)(from1(1 0)(01nil)); �i !' hlength0(0)(from1(1 0)(01nil)); �i!�' hs0(1)(length'0(�1 0)(from0(1 0)(s0(1)(01nil)))); �i!' hs0nil(length'0(�1 0)(from0(1 0)(s0(1)(01nil)))); 1i!' � � �Note that within the labelled term length0(0)(from1(1 0)(01nil)), the strategy doesnot recognize that the (activated) on-demand ags on from and 0 does not comefrom the local annotation for length. That is, the strategy does not maintain anykind of memory about the origin of on-demand ags. Hence, it (unnecessarily)evaluates the argument of length. Moreover, at this point, this evaluation doesnot correspond to the `intended' meaning of the strategy annotations which theprogrammer may have in mind (since the speci�c annotation (0) for lengthforbids reductions on its argument).On the other hand, the two existing de�nitions for the on-demand E-strategy(namely Nakamura and Ogata's [NO01] and Ogata and Futatsugi's [OF00]) sen-sibly di�er. For instance, Nakamura and Ogata select a demanded position forevaluating a given term t by taking the maximum of all positions demanded ont by each rule of the TRS (according to the lexicographic ordering on positions).On the other hand, in Ogata and Futatsugi's selection of demanded positions,the ordering of the rules in the program is very important.Example 4. Consider the OBJ program of Example 2 with the strategy (1 0)for length together with the function geq de�ned by the following module:7

obj Ex3 isprotecting Ex2 .sorts Bool .op true : -> Bool .op false : -> Bool .op geq : Nat Nat -> Nat [strat (-1 -2 0)] .vars X Y : Nat .eq geq(s(X),s(Y)) = geq(X,Y) .eq geq(X,0) = true .endoConsider the expression geq(length(from(0)),length(nil)). According toOgata and Futatsugi's de�nition of on-demand E-strategy, an in�nite reduc-tion sequence is started since position 1 is selected as demanded and, thus, its(non-terminating) evaluation attempted. However, Nakamura and Ogata's def-inition of on-demand E-strategy selects position 2 as demanded and, after theevaluation, the second rule is applied, thus obtaining true.We claim that it is possible to provide a more practical framework for implement-ing and studying OBJ computations, which may integrate the most interestingfeatures of modern evaluation strategies with on-demand syntactic annotations.This is made more precise from now on.4 Improving rewriting under on-demand strategyannotationsAs discussed at the end of the previous section, the existing operational modelsfor arbitrary strategy annotations have a number of drawbacks: (1) the one-step reduction relation is, in general, undecidable; (2) the implementation ofdemandness by using negative annotations (via the marking of terms with ag0 or ag 1) allows evaluation steps that shouldn't be possible, since (3) it doesnot properly keep track of the origin of the marks (loss of memory, see Example3). Here, we want to introduce a further consideration which can be used forimproving the previous de�nitions. Let us show it up by means of an example.Example 5. Consider the OBJ program of Example 4 together with the followingfunction lt:obj Ex4 isprotecting Ex3 .op lt : Nat Nat -> Nat [strat (-1 -2 0)] .vars X Y : Nat .eq lt(0,s(Y)) = true .eq lt(s(X),s(Y)) = lt(X,Y) .endoConsider the expression t = lt(length(from(0)),0), which is a head-normalform since no possible evaluation could lead the expression to match the left-hand side of a rule. Neither Nakamura and Ogata's nor Ogata and Futatsugi'sformulations are able to avoid evaluations on t. Nevertheless, by exploiting thestandard distinction between constructor and de�ned symbols of a signature in8

the presence of a TRS, it is easy to detect that no rule could ever be matched.Indeed, 0 is a constructor symbol in the input term t and, hence, it cannot bereduced for improving the matching of t against the left-hand side of the rule forlt. See [AFJV97,AL02,MR92] for a more detailed motivation and formal discus-sion of the use of these ideas for de�ning and using demand-driven strategies.In the following, we propose a recti�ed and re�ned de�nition of the on-demand E-strategy which takes into account all previous considerations.Given a E-strategy map ', we use the signature5 F ]' = [ffL1jL2 ; fL1jL2 j f 2F ^ L1; L2 2 Lar(f):(L1++L2 v '(f))g and labelled variables X ]' = fxniljnil jx 2 Xg for marking ordinary terms t 2 T (F ;X ) as terms t 2 T (F ]';X ]'). Over-lining the root symbol of a subterm means that no evaluation is required forthat subterm and the control goes back to the parent; the auxiliary list L1 inthe subscript L1 j L2 is interpreted as a kind of memory of previously consid-ered annotations. We use f ] to denote f or f for a symbol f 2 F . We de�nethe list of activable indices of a labelled symbol f ]L1 jL2 as activable(f ]L1 jL2) =�L1 if L1 6= nilL2 if L1 = nil . The operator ' is extended to a mapping from T (F ;X ) toT (F ]';X ]') as follows: '(t) = �xniljnil if t = x 2 Xfnilj'(f)('(t1); : : : ; '(tk)) if t = f(t1; : : : ; tk) .Also, the operator erase : T (F ]';X ]')! T (F ;X ) removes labellings from terms.We de�ne the set of demanded positions of t w.r.t. l (a lhs of a rule de�ningroot(t)), i.e. the set of (positions of) maximal disagreeing subterms as:DPl(t) = �minimal�(Pos 6=(t; l)) if minimal�(Pos 6=(t; l)) � PosD(t)? otherwiseand the set of demanded positions of t w.r.t. TRS R as DPR(t) = [fDPl(t) jl ! r 2 R ^ root(t) = root(l)g. Note that the problem described in Example 5is solved (along the lines of [MR92]) by restricting the attention to disagreeingpositions that correspond to de�ned symbols (by using PosD(t)).Example 6. Continuing Example 5. Let t1 = lt(length(from(0)),0),t2 = lt(length(from(0)),length(nil)), and t3 = lt(0,length(nil)). Wehave DPR(t1) = ?, DPR(t2) = f1; 2g, and DPR(t3) = f2g.We de�ne the set of positive positions of a term s 2 T (F ]';X ]') as PosP (s) =f�g [ fi:PosP (sji) j i > 0 and activable(root(s)) contains ig and the set of ac-tivable positions as PosA(s) = f�g [ fi:PosA(sji) j i > 0 and activable(root(s))contains i or �ig. Given a term s 2 T (F ]';X ]'), the total ordering �s betweenactivable positions of s is de�ned as (1) � �s p for all p 2 PosA(s); (2) ifi:p; i:q 2 PosA(s) and p �sji q, then i:p �s i:q; and (3) if i:p; j:q 2 PosA(s),i 6= j, and i (or�i) appears before j (or �j) in activable(root(s)), then i:p �s j:q.The ordering �s allows us to choose a position from the set of all demanded(and activable) positions in s, which is consistent with user's annotations (see5 The function ++ de�nes the concatenation of two sequences of integers.9

min�s below). We de�ne the set ODR(s) of on-demand positions of a terms 2 T (F ]';X ]') w.r.t. TRS R as follows:if DPR(erase(s)) \ PosP (s) 6= ? or DPR(erase(s)) \ PosA(s) = ?then ODR(s) = ? else ODR(s) = fmin�s(DPR(erase(s)) \PosA(s))gExample 7. Continuing Example 2. For t1 = lengthnilj(0)(fromnilj(1 0)(0niljnil)),we have DPR(erase(t1)) = f1g but ODR(t1) = ?. Let us consider t2 =length(�1)j(0)(fromnilj(1 0)(0niljnil)). We have ODR(t2) = f1g. Finally, for t3 =length(1)j(0)(fromnilj(1 0)(0niljnil)), we have ODR(t3) = ?.Given a term t 2 T (F ]';X ]') and position p 2 Pos(t), mark(t; p) is the term swith all symbols above p (except the root) marked as non-evaluable, in symbolsPos(s) = Pos(t) and 8q 2 Pos(t), if � < q < p and root(tjq) = fL1jL2 , thenroot(sjq) = fL1jL2 , otherwise root(sjq) = root(tjq).Example 8. Consider the program of Example 1 and the term t = 2nd(1)j(0)(cons(1 �2)jnil(0niljnil; fromnilj(1 0)(snilj(1)(0niljnil)))). We have thatmark(t; 1:2) =2nd(1)j(0)(cons(1 �2)jnil(0niljnil; fromnilj(1 0)(snilj(1)(0niljnil)))).We formulate a binary relation ]!' on the set T (F ]';X ]') � N�+, such that asingle reduction step on a (labelled) term t does not involve the application ofrecursive reduction steps on t. In the following de�nition, the symbol @ denotesappending an element at the end of a list.De�nition 2. Given a TRS R = (F ; R) and an arbitrary E-strategy map 'for F , eval' : T (F ;X ) ! P(T (F ;X )) is de�ned as eval'(t) = ferase(s) 2T (F ;X ) j h'(t);�i ]!!' hs;�ig. The binary relation ]!' on T (F ]';X ]')� N�+ isde�ned as follows: ht; pi ]!' hs; qi if and only if p 2 Pos(t) and either1. tjp = fLjnil(t1; : : : ; tk), s = t and p = q:i for some i; or2. tjp = fL1ji:L2(t1; : : : ; tk), i > 0, s = t[fL1@ijL2(t1; : : : ; tk)]p and q = p:i; or3. tjp = fL1j�i:L2(t1; : : : ; tk), i > 0, s = t[fL1@�ijL2(t1; : : : ; tk)]p and q = p; or4. tjp = fL1j0:L2(t1; : : : ; tk) = �(l0), erase(l0) = l, s = t[�('(r))]p for somel ! r 2 R and substitution �, q = p; or5. tjp = fL1j0:L2(t1; : : : ; tk), erase(tjp) is not a redex, ODR(tjp) = ?, s =t[fL1jL2(t1; : : : ; tk)]p, and q = p; or6. tjp = fL1 j0:L2(t1; : : : ; tk), erase(tjp) is not a redex, ODR(tjp) = fp0g, s =t[mark(tjp; p0)]p, q = p:p0; or7. tjp = fL1jL2(t1; : : : ; tk), s = t[fL1jL2(t1; : : : ; tk)]p and p = q:i for some i.Cases 1 and 2 of De�nition 2 essentially correspond to cases 1 and 2 ofNakamura and Ogata's de�nition; that is, (1) no more annotations are providedand the evaluation is completed, or (2) a positive argument index is providedand the evaluation goes down to the subterm at such argument (note that theindex is stored). Case 3 only stores the negative index for further use. Cases 4,5, and 6 consider the attempt to match the term against the left-hand sides of10

the rules of the program. Case 4 applies if the considered (unlabelled) subtermis a redex (which is, then, contracted). If the subterm is not a redex, cases 5 and6 are considered (possibly involving some on-demand evaluation). We use thelists of indices labelling the symbols for �xing the concrete positions on whichwe are able to allow on-demand evaluations; in particular, the �rst (memoizing)list is crucial for achieving this (by means of the function activable and theorder �s used in the de�nition of the set ODR(s) of on-demand positions ofa term s). Case 5 applies if no demanded evaluation is allowed (or required).Case 6 applies if the on-demanded evaluation of the subterm tjp:p0 is required. Inthis case, the symbols lying on the path from tjp to tjp:p0 (excluding the endingones) are overlined. Then, the evaluation process continues on tjp:p0 . Once theevaluation of tjp:p0 has �nished, the only possibility is the repeated (but possiblyempty) application of steps issued according to the last case 7 which implementsthe return of the evaluation process back to position p (which originated theon-demand evaluation).Example 9. Following the Examples 2 and 3. The on-demand evaluation oflength'(from(0)) under the re�ned on-demand strategy is the following:hlength'nilj(�1 0)(fromnilj(1 0)(0niljnil)); �i]!' hlength'(�1)j(0)(fromnilj(1 0)(0niljnil)); �i]!' hlengthnilj(0)(fromnilj(1 0)(0niljnil)); �i]!' hlengthniljnil(fromnilj(1 0)(0niljnil)); �iTherefore, we obtain length(from(0)) as the computed value of the evalua-tion since, in the third step, the set of demanded positions ODR is empty (seeExample 7 above).4.1 Properties of the re�ned on-demand strategyThe following theorem shows that, for positive strategy annotations, each reduc-tion step with ]!' exactly corresponds to the originalNagaya's N!' [Nag99,NO01].For an E-strategy map ' and a term t 2 T (F ]';X ]'), we de�ne positive :T (F ]';X ]') ! T (FN' ;XN' ) as positive(xniljnil) = xnil for x 2 X andpositive(f ]L1 jL2(t1; : : : ; tn)) = fL02 (positive(t1); : : : ; positive(tn)) where L02 is L2without negative indices.Theorem 1. Let R be a TRS and ' be a positive E-strategy map. Let t; s 2T (F ]';X ]') and p 2 Pos(t). Then, ht; pi ]!' hs; qi if and only ifhpositive(t); piN!'hpositive(s); qi.Sometimes, it is interesting to disregard from the ordering of indices in localstrategies. Then, we use replacement maps. A mapping � : F ! P(N) is areplacement map (or F-map) if �(f) � f1; : : : ; ar(f)g for all f 2 F [Luc98]. LetMF be the set of all F-maps. The ordering v on MF , the set of all F-maps, is:� v �0 if for all f 2 F , �(f) � �0(f). Let �canR be the canonical replacement map,11

i.e. the most restrictive replacement map which ensures that the non-variablesubterms of the left-hand sides of the rules of R are replacing, which is easilyobtained from R: 8f 2 F , i 2 f1; : : : ; ar(f)g, i 2 �canR (f) i� 9l 2 L(R); p 2PosF (l); (root(ljp) = f ^ p:i 2 PosF(l)). Let CMR = f� 2 MF j �canR v �g bethe set of replacement maps which are less than or equally restrictive to �canR .Given an E-strategy map ', we let �' to be the following replacement map�'(f) = fjij j i 2 '(f) ^ i 6= 0g. We say that ' is a canonical E-strategy map(and, by abuse, we write ' 2 CMR) if �' 2 CMR. Given an E-strategy map,we let 'Nto be the E-strategy map obtained after taking away all negativeindices for each symbol f 2 F . Note that 'Nv ', for all E-strategy map '.We show that, for E-strategy maps ' whose positive part 'Nis canonical, extranegative annotations can be completely disregarded. This means that negativeannotations are only useful if the positive indices do not collect all indices in thecanonical replacement map of the TRS.Theorem 2. Let R be a TRS and ' be an E-strategy map such that 'N2 CMR.Let t; s 2 T (F ]';X ]') and p 2 Pos(t). Then, ht; pi ]!' hs; qi if and only ifhpositive(t); piN!'Nhpositive(s); qi.Example 9 shows that evaluating terms by using on-demand strategy annotationscan lead to terms which are not even head-normal forms. The following resultestablishes conditions ensuring that the normal forms of our re�ned on-demandstrategy are ordinary head{normal forms (w.r.t. the TRS). A TRSR = (C]D; R)is a constructor system (CS) if for all f(l1; : : : ; lk) ! r 2 R, li 2 T (C;X ), for1 � i � k.Theorem 3. Let R = (F ; R) = (C ] D; R) be a left-linear CS, ' 2 CMR and'(f) ends in 0 for all f 2 D. Let t 2 T (F ;X ). If s 2 eval'(t), then s is ahead-normal form of t.Left-linearity and CS conditions cannot be dropped (see [Luc01] for examplesthat also apply to our setting).Theorem 3 suggests the following normalization via '-normalization pro-cedure to obtain normal forms of a term t: given an E-strategy map ' ands = f(s1; : : : ; sk) 2 eval'(t), we continue the evaluation of t by (recursively)normalizing s1; : : : ; sk using eval'. It is not di�cult to see that con uence and'-termination of the TRS guarantee that this procedure actually describes anormalizing strategy (see [Luc01,Luc02a]).In the next section, we show that our on-demand strategy improves lazyrewriting, a popular demand-driven technique to perform lazy functional com-putations which inspired the development of local strategies in OBJ.4.2 Comparison with lazy rewritingIn lazy rewriting [FKW00,Luc02b], reductions are issued on a di�erent kind oflabelled terms. Nodes (or positions) of a term t are labelled with e for the so-called12

eager positions or ` for so-called lazy ones: Let F be a signature and L = fe; `g;then, F � L (or FL) is a new signature of labelled symbols. The labelling of asymbol f 2 F is denoted fe or f` rather than hf; ei or hf; `i. Labelled termsare terms in T (FL;XL). Given t 2 T (FL;XL) and p 2 Pos(t), if root(tjp) = xe(= x`) or root(tjp) = fe (= f`), then we say that p is an eager (resp. lazy)position of t.Given a replacement map � 2 MF and s 2 T (F ;X ), label�(s) denotes thefollowing intended labelling of s: the topmost position � of label�(s) is eager;given a position p 2 Pos(label�(s)) and i 2 f1; : : : ; ar(root(sjp))g, position p:i oflabel�(s) is lazy if and only i 62 �(root(sjp)); otherwise, it is eager.Example 10. Consider the replacement map � given by �(2nd) = �(from) =�(cons) = �(s) = f1g. Then, the labelling of s = 2nd(cons(0,from(s(0))))is t = label�(s) = 2nde(conse(0e,from`(se(0e)))). Thus, �; 1; 1:1; 1:2:1, and1:2:1:1 are eager positions; position 1:2 is lazy.Given t 2 T (FL;XL), erase(t) is the term in T (F ;X ) that (obviously) corre-sponds to t after removing labels.As remarked above, given t 2 T (FL;XL), a position p 2 Pos(t) is eager (resp.lazy) if root(tjp) is labelled with e (resp. `). The so-called active positions of t arethose positions which are always reachable from the root of the term via a pathof eager positions. For instance, positions �; 1, and 1:1 are active in term t ofExample 10; positions 1:2:1 and 1:2:1:1 are eager but not active, since position1:2 below is lazy in t. Let Act(t) be the set of active positions of a labelledterm t 2 T (FL;XL). In lazy rewriting, the set of active nodes may increase asreduction of labelled terms proceeds. Each lazy reduction step on labelled termsmay have two di�erent e�ects:1. changing the \activation" status of a given position within a term, or2. performing a rewriting step (always on an active position).The activation status of a lazy position immediately below an active positionwithin a (labelled) term can be modi�ed if the position is `essential', i.e. `itscontraction may lead to new redexes at active nodes' [FKW00].De�nition 3 (Matching modulo laziness [FKW00]). Let l 2 T (F ;X ) belinear, t 2 T (FL;XL), and p be an active position of t. Then, l matches modulolaziness s = tjp if either l 2 X , or l = f(l1; : : : ; lk), s = fe(s1; : : : ; sk) and, forall i 2 f1; : : : ; kg, if p:i is eager, then li matches modulo laziness si. If positionp:i is lazy and li 62 X , then position p:i is called essential.If p is an active position in t 2 T (FL;XL) and l ! r is a rewrite rule of a left-linear TRS R such that l matches modulo laziness tjp giving rise to an essentialposition q of t and tjq = f`(t1; : : : ; tk), then we write t A! t[fe(t1; : : : ; tk)]q fordenoting the activation of position p.Lazy rewriting reduces active positions: let p be an active position of t 2T (FL;XL), u = tjp and l ! r be a rule of a left-linear TRS R such that l13

matches erase(u) using substitution �. Then, t R!� s, where s is obtained from tby replacing tjp in t by label�(r) with all its variables instantiated according to� but preserving the label of the variable in label�(r), see [Luc02b] for a formalde�nition.Example 11. Consider the program of Example 1 (as a TRS) and the term t ofExample 10. The reduction step that corresponds to such term is:2nde(conse(0e,from`(se(0e)))) A! 2nde(conse(0e,frome(se(0e)))) R!�2nde(conse(0e,conse(se(0e):efrom`(se(se(0e)))))). Note that term2nde(conse(0e,conse(se(0e):efrom`(se(se(0e)))))) is a A!-normal form.The lazy term rewriting relation on labelled terms (LR) is LR!� = A! [ R!�and the evaluation LR-eval�(t) of a term t 2 T (F ;X ) using LR is given byLR-eval�(t) = ferase(s) 2 T (F ;X ) j label�(t) LR�!!� sg. We say that a TRSis LR(�)-terminating if, for all t 2 T (F ;X ), there is no in�nite LR!�-rewritesequence starting from label�(t) [Luc02b].We show that each evaluation step of our re�ned on-demand strategy is in-cluded into some evaluation steps of lazy rewriting. Given a term t 2 T (F ]';X ]')and p 2 Pos(t), we translate the labeling of terms in T (F ]';X ]') into the la-beling of T (FL;XL) as follows: lazyp'(t) = �00p (�0t(label�'N(erase(t)))) where(1) �0t(fb(t1; : : : ; tn)) = fe(�0s1(t1); : : : ; �0sn(tn)) if t = fL1jL2(s1; : : : ; sn), (2)�0t(fb(t1; : : : ; tn)) = fb(�0s1(t1); : : : ; �0sn(tn)) if t = fL1jL2(s1; : : : ; sn), and (3)�00p(s) = s[fe(s1; : : : ; sk)]p for sjp = fb(s1; : : : ; sk). We de�ne the ordering �lazybetween terms T (FL;XL) by extending the ordering fe �lazy fe and f` �lazyfe, for all f 2 F , to terms.The following theorem shows that each evaluation step of our re�ned on-demand strategy corresponds to some evaluation steps of lazy rewriting. Also,it shows that lazy rewriting (potentially) activates as many symbols (within aterm) as our strategy (we use the ordering �lazy for expressing this fact).Theorem 4. Let R be a left-linear TRS and ' be an E-strategy map. Let t 2T (F ]';X ]'), p 2 Pos(t) and � = �'N. If ht; pi ]!' hs; qi and p 2 Act(lazyp'(t)),then q 2 Act(lazyq'(s)), and lazyp'(t) LR�!�� s0 for s0 2 T (F ]';X ]') such thatlazyq'(s) �lazy s0.In general, our strategy is strictly more restrictive than LR as the followingexample shows.Example 12. Consider the TRS R and the E-strategy map ' of program ofExample 2. In Example 14 below, we prove that R is '{terminating. How-ever, LR enters an in�nite reduction sequence starting with the expressionlabel�'(length'(from(0))):length'e(from`(0e)) R!� lengthe(from`(0e)) A! lengthe(frome(0e))R!� lengthe(conse(0e;from`(se(0e)))) R!� se(length'e(from`(se(0e)))) LR!� � � �14

Note that if no positive annotation is provided for an argument of a symbol, LRfreely demands on this argument. Then, in contrast to ' (where '(length) =(0)) LR can evaluate position 1 in the expression length(from(0)).In the following section, we formulate methods for proving termination of ouron-demand strategy.5 Proving termination of programs with negativeannotations by transformationIn [Luc02b] a method for proving termination of LR as termination of context-sensitive rewriting (CSR [Luc98]) is described. In contrast to LR, context-sensitiverewriting forbids any reduction on the arguments not included into �(f) fora given function call f(t1; : : : ; tk). A TRS R is �-terminating if the context-sensitive rewrite relation associated to R and � is terminating. The idea of theaforementioned method is simple: given a TRS R and a replacement map �,a new TRS R0 and replacement map �0 is obtained in such a way that �0-termination of R0 implies LR(�)-termination of R. Fortunately, there is a num-ber of di�erent techniques for proving termination of CSR (see [GM02,Luc02c]for recent surveys) which provide a formal framework for proving termination oflazy rewriting. A simple modi�cation of such transformation provides a soundtechnique for proving '-termination of TRSs for arbitrary strategy annotations' by taking into account that only those symbols which have associated a neg-ative index may be activated by demandness. Here, as in [Luc01,Luc02b], by'-termination of a TRS R we mean the absence of in�nite ]!' -sequences ofterms starting from h'(t);�i.As for the transformation in [Luc02b], the idea is to encode the demandnessinformation expressed by the rules of the TRS R together with the (negative)annotations of the E-strategy map ' as new symbols and rules (together withthe appropriate modi�cation/extension of ') in such a way that '-terminationis preserved in the new TRS and E-strategy map, but the negative indices are�nally suppressed (by removing from the lhs of the rules the parts that introduceon-demand computations). We iterate on these basic transformation steps untilobtaining a canonical E-strategy map. In this case, we can stop the transforma-tion and use the existing methods for proving termination of CSR. Let ' be anarbitrary E-strategy map. Given l ! r 2 R and p 2 Pos(l), we letI(l; p) = fi > 0 j p:i 2 PosF (l) and � i 2 '(root(ljp))gAssume that I(l; p) = fi1; : : : ; ing for some n > 0 (i.e., I(l; p) 6= ?) and let f =root(ljp). Then, R� = (F�; R�) and '� are as follows: F� = F[ffj j 1 � j � ng,where each fj is a new symbol of arity ar(fj) = ar(f), andR� = R� fl ! rg [ fl0j ! r; l[x]p:ij ! l0j [x]p:ij j 1 � j � ngwhere l0j = l[fj(ljp:1; : : : ; ljp:k)]p if ar(f) = k, and x is a new variable. We let'�(fj) = (ij 0) for 1 � j � n and f 2 D, '�(fj) = (ij) for 1 � j � n and15

f 2 C, and '�(g) = '(g) for all g 2 F :(g 6= f). Moreover, we let '�(f) = 'N(f)if �canR� (f) � �'N(f), or '�(f) = '(f) otherwise. The transformation proceeds inthis way (starting from R� and ��) until obtaining R\ = (F \; R\) and '\ suchthat '\ = '\N. If ' = 'N, then R\ = R and '\ = '.Finally, we can state a su�cient condition for '-termination as terminationof CSR for the transformed TRS.Theorem 5. Let R be a TRS, ' be an E-strategy map. If R\ is �'\-terminating,then R is '-terminating.Example 13. Consider the TRSR associated to Example 1 but where '(cons) =(1 � 2). Then, R\ is:2nd(cons'(x,cons(y,z))) ! y2nd(cons(x,y)) ! 2nd(cons'(x,y))from(x) ! cons(x,from(s(x)))and '\ is given by '\(2nd) = '\(from) = (1 0), '\(cons) = (1), and '\(cons') =(2). The �'\-termination of R\ is proved by using Zantema's transformation forproving termination of CSR [Zan97]: the TRS2nd(cons'(x,cons(y,z))) ! y2nd(cons(x,y)) ! 2nd(cons'(x,activate(y)))from(x) ! cons(x,from'(s(x)))activate(from'(x)) ! from(x)from(x) ! from'(x)activate(x) ! xwhich is obtained in this way (where activate and from' are new symbolsintroduced by Zantema's transformation) is terminating6.Example 14. Consider the TRS R and the E-strategy map ' that correspond tothe OBJ program of Example 2. Our transformation returns the original TRS,i.e., R\ is:from(x) ! cons(x,from(s(x)))length(nil) ! 0length(cons(x,z)) ! s(length'(z))length'(z) ! length(z)together with the simpli�ed E-strategy '\(s) = '\(cons) = (1), '\(from) =(1 0) and '\(length) = '\(length') = (0). The �'\-termination of R can beautomatically proved by splitting up the rules of the program into two modulesR1 (consisting of the rule for from) and R2 (consisting of the rules for lengthand length'). The �'\ -termination of R1 can easily be proved by using Zan-tema's transformation (in fact, the proof can be extracted from that of Example13). The �'\ -termination of R2 is easily proved: in fact, R2 can be proved ter-minating (regarding standard rewriting) by using a polynomial ordering7. Now,�'\-termination of R follows by applying the modularity results of [GL02].6 Using the CiME 2.0 system (available at http://cime.lri.fr).7 CiME 2.0 can also be used for achieving this proof.16

6 ConclusionsWe have provided a suitable extension of the positive E-evaluation strategy ofOBJ-like languages to general (positive as well as negative) annotations. Suchan extension is conservative, i.e., programs which only use positive strategy an-notations and that are executed under our strategy behave exactly as if theywere executed under the standard OBJ evaluation strategy (Theorems 1 and 2).The main contributions of the paper are (a) the de�nition of a recti�ed andwell-de�ned approach to demandness via E-strategies (see Examples 2, 3, 9,and 12 for motivation regarding some of the problems detected on the previousproposals), (b) the better computational properties associated to such a newon-demand strategy (Theorems 3 and 4), (c) the de�nition of techniques for an-alyzing computational properties such as termination (Theorem 5), and that (d)our approach is (hopefully) better suited for implementation. Our on-demandstrategy also improves lazy rewriting, a popular, demand-driven technique toperform lazy functional computations which inspired the development of on-demand strategies in OBJ. We conjecture that the on-demand rewriting (ODR)[Luc01], which extends the context sensitive rewriting of [Luc98] by also consid-ering \negative annotations", can also be compared with our re�ned on-demandstrategy, whereas it does not directly apply to OBJ nor it is comparable to LR.There are still some open problems regarding completeness of our re�nedon-demand strategy which are out of the scope of this paper (see [AEL02] for athorough discussion and proposal of implementable solutions when dealing withprograms that only use positive annotations).Acknowledgements. We thank the anonymous referees for their helpful remarks.References[AEL02] M. Alpuente, S. Escobar, and S. Lucas. Correct and complete (positive)strategy annotations for OBJ. Electronic Notes in Theoretical ComputerScience, volume 71. Elsevier Sciences, to appear 2002.[AFJV97] M. Alpuente, M. Falaschi, P. Juli�an, and G. Vidal. Specialization of LazyFunctional Logic Programs. Sigplan Notices, 32(12):151{162, ACM Press,New York, 1997.[AL02] S. Antoy and S. Lucas. Demandness in rewriting and narrowing. ElectronicNotes in Theoretical Computer Science, volume 76. Elsevier Sciences, toappear 2002.[BN98] F. Baader and T. Nipkow. Term Rewriting and All That. CambridgeUniversity Press, 1998.[CELM96] M. Clavel, S. Eker, P. Lincoln, and J. Meseguer. Principles of Maude. Elec-tronic Notes in Theoretical Computer Science, volume 4. Elsevier Sciences,1996.[Eke98] S. Eker. Term rewriting with operator evaluation strategies. ElectronicNotes in Theoretical Computer Science, volume 15. Elsevier Sciences, 1998.[FGJM85] K. Futatsugi, J. Goguen, J.-P. Jouannaud, and J. Meseguer. Principlesof OBJ2. In Proc. of the 12th Annual ACM Symposium on Principles ofProgramming Languages, POPL'85, pages 52{66. ACM Press, 1985.17

[FKW00] W. Fokkink, J. Kamperman, and P. Walters. Lazy rewriting on eagermachinery. ACM Transactions on Programming Languages and Systems,22(1):45{86, 2000.[FN97] K. Futatsugi and A. Nakagawa. An overview of Cafe speci�cation envi-ronment { an algebraic approach for creating, verifying, and maintainingformal speci�cation over networks {. In Proc. of 1st International Confer-ence on Formal Engineering Methods, 1997.[GL02] B. Gramlich and S. Lucas. Modular termination of context-sensitive rewrit-ing. In C. Kirchner, editor, Proc. of 4th International ACM SIGPLANCon-ference on Principles and Practice of Declarative Programming, PPDP'02,Pittsburg, USA, 2002. ACM Press, New York. To appear, 2002.[GM02] J�urgen Giesl and Aart Middeldorp. Transformation techniques for context-sensitive rewrite systems. Aachener Informatik-Berichte (AIBs) 2002-02,RWTH Aachen, 2002.[GWM+00] J. A. Goguen, T. Winkler, J. Meseguer, K. Futatsugi, and J.P. Jouannaud.Introducing OBJ. In Joseph A. Goguen and Grant Malcolm, editors, Soft-ware Engineering with OBJ: algebraic speci�cation in action. Kluwer, 2000.[Luc98] S. Lucas. Context-sensitive computations in functional and functional logicprograms. Journal of Functional and Logic Programming, 1998:1{61, 1998.[Luc01] S. Lucas. Termination of on-demand rewriting and termination of OBJprograms. In Harald Sondergaard, editor, Proc. 3rd International ACMSIGPLAN Conference on Principles and Practice of Declarative Program-ming (PPDP'01), pages 82{93, Firenze, Italy, September 2001. ACM Press,New York.[Luc02a] S. Lucas. Context-sensitive rewriting strategies. Information and Compu-tation, to appear, 2002.[Luc02b] S. Lucas. Lazy rewriting and context-sensitive rewriting. Electronic Notesin Theoretical Computer Science, volume 64. Elsevier Sciences, to appear,2002.[Luc02c] S. Lucas. Termination of (canonical) context-sensitive rewriting. In SophieTison, editor, Proc. 13th International Conference on Rewriting Techniquesand Applications, RTA'02, LNCS 2378:296-310, Springer-Verlag, Berlin,2002.[MR92] J.J. Moreno-Navarro and M. Rodr��guez-Artalejo. Logic Programming withFunctions and Predicates: the Language BABEL. Journal of Logic Pro-gramming, 12(3):191{223, 1992.[Nag99] T. Nagaya. Reduction Strategies for Term Rewriting Systems, PhD Thesis.School of Information Science, Japan Advanced Institute of Science andTechnology, 1999.[NO01] M. Nakamura and K. Ogata. The evaluation strategy for head normalform with and without on-demand ags. Electronic Notes in TheoreticalComputer Science, volume 36. Elsevier Sciences, 2001.[OF00] K. Ogata and K. Futatsugi. Operational semantics of rewriting with theon-demand evaluation strategy. In Proc of 2000 International Symposiumon Applied Computing, SAC'00, pages 756{763. ACM Press, 2000.[Zan97] H. Zantema. Termination of context-sensitive rewriting. In Proc. of 8th In-ternational Conference on Rewriting Techniques and Applications, RTA'97,pages 172{186. Springer-Verlag, LNCS 1232, 1997.18