Order-Sorted Termination: the Unsorted Way

0 downloads 0 Views 236KB Size Report
In this paper we approach the problem of order-sorted termination by ...... ings of the 4th European Symposion on Programming, LNCS 582, pages 182{199,.

Order-Sorted Termination: the Unsorted Way Peter Csaba O lveczky1 and Olav Lysne2 1

Department of Informatics, University of Bergen The High Technology Center, 5020 Bergen, NORWAY E-mail: [email protected] 2

Department of Informatics, University of Oslo Po. box 1080 Blindern, 0316 Oslo, NORWAY E-mail: [email protected] .uio.no

Keywords: Order-sortedness, Termination Abstract. We consider the problem of proving termination of order-

sorted rewrite systems. The dominating method for proving termination of order-sorted systems has been to simply ignore sort information, and use the techniques developed for unsorted rewriting. The problem with this approach is that many order-sorted rewrite systems terminate because of the structure of the set of sorts. In these cases the corresponding unsorted system would not terminate. In this paper we approach the problem of order-sorted termination by mapping the order-sorted rewrite system into an unsorted one such that termination of the latter implies termination of the former. By encoding sort information into the unsorted mapping, we are able to use general purpose termination orderings to prove termination of order-sorted rewrite systems whose termination depend on the sort hierarchy. We present a sequence of gradually stronger methods, and show that a previously published method is contained in ours as a special case.

1 Introduction In the last decade we have seen an increasing interest in order-sorted algebras, and its operational counterpart - order-sorted rewriting. Order-sortedness has been introduced to term rewriting to provide for a more powerful type concept, allowing us to express partiality of functions, error handling and subtype inheritance [8]. In languages like OBJ3 [9] and ABEL [1], order-sorted speci cations are given an operational semantics based on term rewriting. One of the most important properties a rewrite system may have is termination, which means that no in nite computation in the system can take place. In general it is undecidable whether a rewrite system terminates, but numerous techniques have been developed that with varying degrees of success may be used to prove termination of unsorted rewrite systems. These techniques include the path orderings [10, 2, 3], interpretation techniques [12], and not to forget the seminal Knuth and Bendix ordering [11].

The dominating method for proving termination of order-sorted systems has been to simply ignore sort information, and use the methods developed for unsorted rewriting [7, 5]. The problem with this approach is that many order-sorted rewrite systems terminate because of the structure of the set of sorts. In these cases the corresponding unsorted system would not terminate, as is illustrated by the following example. The example is a modi ed version of one occurring in [6] where the problem of order-sorted termination was rst addressed. Example 1. This system de nes a predicate is even over the integers. The idea is to de ne is even over the positive numbers rst and to extend it to the negative numbers by using the operation opposite.

sorts: Zero; NzNeg; Neg; NzPos; Pos; Int; Bool Zero  Neg  Int Zero  Pos  Int NzNeg  Neg NzPos  Pos funcs: 0 : Zero s : Pos!NzPos p : Neg!NzNeg true : Bool false : Bool is even : Int!Bool opposite : NzNeg!NzPos rules: is even(0);!true is even(s(0));!false (8x : Pos) is even(s(s(x)));!is even(x) (8y : NzNeg) is even(y);!is even(opposite(y)) opposite(p(0));!s(0) (8y : NzNeg) opposite(p(y));!s(opposite(y)) If sorts were ignored, the system would not terminate since the fourth rule would generate the in nite rewrite sequence

is even(y);!is even(opposite(y));!is even(opposite(opposite(y)));!    However, the system does terminate because opposite(y : NzNeg) is of sort NzPos, so y cannot be instantiated with opposite(t) for any term t. In [4] Ganzinger studied completion of order-sorted rewrite systems, and he introduced the idea of transforming an order-sorted rewrite system into a manysorted equational one. Ganzinger lets each function declaration f : w!s induce a (many-sorted) function symbol fw!s . This idea was adopted by Gnaedig [6] who used these labeled function symbols to prove termination of order-sorted rewrite systems. Gnaedig's method is however restricted to minimal signatures, i. e. if f : w!s and f : w0 !s0 are two function declarations then w and w0 must be incomparable with respect to .

We will also pursue the idea of labeling each function symbol in a term. We shall, however, use another labeling technique, and we shall also use another mapping from order-sorted rewrite systems to unsorted ones. By doing this we avoid the limitation to minimal signatures, and we are able to show that our method is a proper extension of the one in [6]. The paper is organized as follows: After de ning basic notions of order-sorted rewriting, we introduce the basic concepts of our approach in section 3. In section 4 we show that the rst version of our technique is unreasonably weak and propose a straight-forward amelioration, obtaining a method stronger than previous approaches to the problem of order-sorted termination. This method is then made stronger, though somewhat more complicated (section 5), and is extended to handle non-sort-decreasing rules as well (section 6) before the proposed method is compared to Gnaedig's approach to order-sorted termination [6] and Ganzinger's transformation of an order-sorted system to a many-sorted one [4] (section 7). We conclude this paper by brie y mentioning yet another extension to our proposed method and then indicate a di erent approach to order-sorted termination not involving any transformation into an unsorted system.

2 Basic Notions We shall only introduce the syntactic aspects of order-sorted algebra and refer to [8] and [13] for semantics of order-sorted speci cations. The paper [13] compares the two main semantic variations of order-sorted algebra { overloading vs. nonoverloading. In this paper, where the rewrite relation is based on overloaded algebra semantics, notions and notations mainly follow [8] and [7]. Order-sorted algebra is based on a subsort relation, a partial order  on a set S of sorts. We write s0 < s when s0  s and s0 6= s and  for the symmetric relation of . The subsort relation  can be extended to n-tuples of sorts (often denoted w) where w = hs1 ; : : : ; sn i  hs01 ; : : : ; s0n i = w0 i si  s0i for i = 1::n and w < w0 i w  w0 and w 6= w0 . We write w l w0 when w < w0 and w and w0 only di ers in one position, e.g. w = hs1 ; : : : ; si;1 ; si ; si+1 ; : : : ; sn i, w0 = hs1 ; : : : ; si;1 ; s0i ; si+1 ; : : : ; sn i and si < s0i . A function declaration has the form f : s1 ; : : : ; sn !s where each si is a sort symbol. If n = 0 then f is called a constant and the declaration is written f : s. An order-sorted signature hS; ; i, usually denoted just  , consists of a partially ordered sort set hS;  i and a set  of function declarations. Given a set X = fXs j s 2 Sg of disjoint sets, the set of terms of sort s, denoted T (; X )s, is the least set such that Xs0  T (; X )s if s0  s, and f (t1 ; : : : ; tn ) 2 T (; X )s if there exists a declaration f : s1 ; : : : ; sn !s0 such that ti is a term ofS sort si for i = 1::n and s0  s. The set T (; X ) is de ned as T (; X ) = f s2S T (; X )s g and an element of any set T (; X )s is called a (well-formed) term. In this paper we assume that every order-sorted signature is nite (i. e. contains a nite number of sort and function symbols), that every term has a unique least sort, denoted LS (t) and that there exists a ground term of every sort in the signature.

A term may be viewed as a tree in the obvious way. A position in a term can be seen as a nite sequence of natural numbers, identifying a path from the root of the term. The node in the term where the path ends is the actual position. The subterm of t at position p, written tjp , is the subterm of t which has its root symbol at position p. The result of replacing the subterm of t at position p by the term u is written t[u]p . If p and q are positions we write p:q to denote the concatenation of p and q. A substitution  = fs : Xs !T (; Y )s j s 2 Sg is a mapping from variables to terms. We shall use lowercase Greek letters to denote substitutions. The application of a substitution  to a term t consists of simultaneously replacing the variables occurring in t by a term according to the mapping. The result of this application is written t. A specialization, often written , is a substitution  : X!Y that maps a variable x of sort s to a variable x0 of sort s0 less than or equal to s, i. e. (x : s) = x0 : s0 where s0  s. In a nite signature, a nite set of variables has a nite set of specializations. An order-sorted rewrite rule is a directed equation (8X ) l;!r where l and r are terms in T (; X ) and where the least sorts of the terms l and r are in the same connected component (i. e. in the same equivalence class of the symmetric and transitive closure) of hS;  i. Given a rewrite system, i. e. a set of rewrite rules, R, a term t 2 T (; X ) rewrites to t0 with a rule (8Y ) l;!r in R at 0 position p, denoted t;! R t if 1. there is a substitution  : Y !T (; X ) such that l = tjp and t0 = t[r]p and 2. there is a sort s such that, for x a variable of sort s, t[x]p is a well-formed term and l; r 2 T (; X )s . + 0 0 We write t ;! R t when t rewrites to t in one or more steps. A system is sortdecreasing if every rule l;!r is sort-decreasing, i. e. LS (l)  LS (r) for every substitution . Sort-decreasingness ensures 1) that condition 2 in the above de nition of rewriting is satis ed when the rst condition is ful lled, 2) that the rewrite relations based on non-overloaded and overloaded semantics resp. coincide, 3) that the critical pair lemma is valid and 4) that Birkho 's theorem is valid for con uent systems [7]. In sections 3 to 5 every rewrite system is assumed to be sort-decreasing.

3 Re ections of Order-Sorted Rewriting In this section we propose a technique for proving termination of an order-sorted rewrite system R by transforming it into an unsorted system R0 .

De nition 1 An unsorted rewrite system R0 re ects an order-sorted rewrite system R with signature  i there exists a mapping M from T (; X ) to a + 0 0 0 set of unsorted terms such that t;! R t =) M(t);! R0 M(t ) for all terms t; t 2 T (; X ).

Example 2. For any order-sorted rewrite system the trivial mapping to unsorted rewriting by removing all sort information is a re ection. Proposition 1. An order-sorted rewrite system terminates if it has a terminating unsorted re ection. The challenge is therefore to nd a suitable re ection for any given order-sorted rewrite system. One way to nd such a re ection would be to implement ordersorted rewriting by means of an unsorted system. This would, however, indicate the introduction of a lot of new rewrite rules whose only mission would be to perform the actions of order-sorted rewriting, and to prove the termination of these rules would be a challenge in itself. We shall propose a simpler method for nding re ections, that gives an unsorted system which has a closer intuitive connection with the order-sorted one. De nition 2 Let  be an order-sorted signature. Its translation into a corresponding unsorted signature (i. e. a set of function symbols) F is de ned as F = ffw j f : w0 !s declaration in  for some s and w  w0 g where the arity of fw is jwj. A term t in T (; X ) is represented in T (F; X ) by the term btc where each function symbol in t is labeled with the least sorts of its arguments: De nition 3 The mapping b c : T (; X )!T (F; X ) where F is the translation of  is de ned inductively as follows: { bx : sc = x for a variable x 2 Xs. { bf (t1; : : : ; tn)c = fLS(t1);:::;LS(tn)(bt1 c; : : :; btnc). We shall use b c to construct re ections of order-sorted rewrite systems. Let us assume that we have an order-sorted rewrite system R, and that we are trying to nd an unsorted re ection of it, say R0 , using the mapping b c. Letting R0 = fblc;!brcjl;!r 2 Rg is not sucient: the rule blc;!brc will not in general apply to btc even if l;!r applies to t. The reason for this is that LS (u) is not in general the same as LS (u). Therefore R0 must at least contain a rule blc;!brc for every specialization  of each rule l;!r in R. Unfortunately, the following example shows that not even this de nition is sucient to make R0 a re ection of an order-sorted system R: Example 3. Let a rewrite system R be given by

sorts: s; s ; s s ;s  s funcs: f; g : s!s g : s !s a:s b:s rule: a;!b 1

1

2

2

1

1

2

The term f (g(a)) rewrites to f (g(b)) in R but bf (g(a))c = fs (gs (a)) and also + bf (g(b))c = fs2 (gs1 (b)) so we need fs (gs (a));! R0 fs2 (gs1 (b)) which is not true if 0 R contains only the rule a;!b. In the above example all the (mapped) function symbols in the term changed even though the order-sorted rewriting occurred at position 1.1. We call such a \side e ect" of a rewrite step a function symbol jump or just an F-jump : De nition 4 Assume that a term t is rewritten to t0 in an order-sorted rewrite system and that the rule is applied at position p in t. There is a function symbol jump, often just called an F -jump, from fw to fw0 if there is a position q in t such that btcjq = fw (: : :) and bt0 cjq = fw0 (: : :) and there is no position r such that q = p:r. In the previous example we had two F -jumps, from fs to fs2 and from gs to gs1 respectively. Sort-decreasingness and monotonicity properties of order-sorted signatures imply that w0 l w when an F -jump from fw to fw0 occurs. To handle this, a so-called jump rule fw (x1 ; : : : ; xn );!fw0 (x1 ; : : : ; xn ) is added to R0 for all symbols fw ; fw0 in F when w0 lw. In example 2, R0 would have contained the jump rules fs (x);!fs1 (x); fs (x);!fs2 (x) ; gs (x);!gs1 (x) and gs (x);!gs2 (x). Together with a rule a;!b, R0 is a re ection of R where the rewrite sequence fs (gs (a));! R0 fs (gs (b));! R0 fs (gs1 (b));! R0 fs2 (gs1 (b)) yields + the desired bf (g(a))c;! R0 bf (g (b))c. Theorem 2. Let R be an order-sorted rewrite system, and let R0 = fblc;!brc j l;!r 2 R;  specialization g S ffw (x1 ; : : : ; xn );!fw0 (x1 ; : : : ; xn ) j fw 2 F; w0 l wg Then R0 is an unsorted re ection of R wrt. to the mapping b c. 0 Proof: Assume that t;! R t by applying +rule 0l;!r 2 R at position p in t with substitution . We must show that btc;! R0 bt c. Let  be the specialization  = fx1 7! x01 : LS (x1 ); : : : ; xn 7! x0n : LS (xn )g and 0 the unsorted substitution 0 = fx01 7! bx1 c; : : : ; x0n 7! bxn cg: Then it can be shown that btc = btc0 for all terms t. Now we have 0 btc = bt[tjp ]p c = bt[l]p c = btc[blc]p = btc[blc0]p ;! R0 btc[brc ]p = btc[brc]p thus btc rewrites by R0 to btc[brc]p in one step. It is easy to see that btc[brc]p and bt0 c = bt[r]p c only di er in the positions where function symbol jumps have occurred. Since R is sort-decreasing we know that the F -jumps will all be of the form fw to fw0 , where w0 l w. But then we + 0 know that btc[brc]p ;! R0 bt[r ]p c = bt c by the jump rules, which concludes the proof. ut The rst version of our method is thus described by the following corollary:

Corollary 3. Let R be an order-sorted rewrite system, and let R0 = fblc;!brc j l;!r 2 R;  specialization g S ffw (x ; : : : ; xn );!fw0 (x ; : : : ; xn ) j fw 2 F; w0 l w:g If R0 terminates then so does R. 1

1

Let us see how the method can be applied to the following system, which cannot be shown to terminate by ignoring sort information: Example 4. Let a rewrite system R be

sorts: s0; s s0  s funcs: f; g : s!s a:s b : s0 rules: (8x : s0 ) f (x);!g(x) g(a);!f (a)

We use the lexicographic path ordering. Since s0 < s the precedence % on function symbols must satisfy gs  gs0 and fs  fs0 in order to show termination of the jump rules. In addition we must have bf (x : s0 )c = fs0 (x) lpo gs0 (x) = bg(x)c bg(a)c = gs (a) lpo fs (a) = bf (a)c This is satis ed with the precedence gs  fs  fs0  gs0 : Example 5. (Example 1 cont.) Termination of the system given in example 1 can be proved by using corollary 3 and the lexicographic path ordering with the precedence

is evenInt  is evenNeg  is evenNzNeg  oppositeNzNeg  sPos  sNzPos  sZero  is evenPos  is evenNzPos  is evenZero  pNeg  pNzNeg  pZero  true  false  0:

The main disadvantages of the method are: 1. R0 contains a rule fw (x1 ; : : : ; xn );!fw0 (x1 ; : : : ; xn ) whenever w0 l w even in systems where an F -jump from fw to fw0 cannot occur. If, for instance, all specializations of all rules are sort-preserving, then no F -jump can take place. 2. There are cases where the F -jumps can occur, but where the jump rules cause problems in the termination proof. 3. The method requires sort-decreasing rules. These weaknesses are dealt with in the following sections by introducing greater

exibility in the treatment of F -jumps. In the next section we demonstrate how jump-rules may be avoided by considering equivalence classes of mapped function symbols. In section 5 we introduce the possibility of replacing jump-rules by an inductive schema of rules. Finally we open for detection of which F -jumps can actually take place, and thereby detection of which jump rules that are strictly necessary.

4 Equivalences of Mapped Function Symbols One of the main disadvantages of (the rst version of) our method is that we require that fw (x1 ; : : :; xn ) o fw0 (x1 ; : : : ; xn ) under a termination ordering o whenever w0 < w. For many orderings o, this means that our method may be weaker than the simple sort-ignoring one, as shown by the following example: Example 6. Let a rewrite system R be given by

sorts: s; s0 s0  s funcs: f : s!s a : s0 b:s rules: f (a);!f (b) (8x : s0 ) f (x);!a

Assume that we want to show termination of R by a path ordering using precedences on function symbols. Ignoring the sorts, termination of the system is proved with the precedence f  a  b. Using our method from the previous section, we get the re ection

ffs0 (a);!fs (b); fs0 (x);!a; fs (x);!fs0 (x)g that cannot be shown terminating using any such path ordering. This is because the last rule in the re ection requires fs  fs0 , the second rule requires fs0  a, which means that the rst rule needs a  fs . This problem is due to the introduction of jump rules. To overcome it we introduce equivalence relations on the translation F of the order-sorted signature  . We shall use such equivalences to treat fs and fs0 identically in the re ection, and thereby remove the need for a jump rule fs (x);!fs0 (x). In the following we let [fw ] denote the equivalence class of fw under . To ensure that terms remain well-formed, we require that gw  fw0 only if these function symbols have the same arity. The corresponding mapping b c is de ned as follows:

De nition 5 Let  be an order-sorted signature and let  be an equivalence relation on the translation F of  such that -equal symbols have the same arity. Then F  def = f[fw ] j fw 2 Fg and the mapping b c : T (; X )!T (F ; X ) is de ned inductively as follows: { bx : sc = x for x 2 Xs. { bf (t1; : : : ; tn)c = [fLS(t1);:::;LS(tn)](bt1c; : : : ; btnc).

Given an order-sorted rewrite system R on  we can construct the re ection R0 on F  by replacing each fw in the re ection of corollary 3 with [fw ] and omitting jump rules [fw ] (x ; : : : ; xn );![fw0 ] (x ; : : : ; xn ) if [fw ] = [fw0 ] : 1

1

Proposition 4. Let R be a nite, sort-decreasing order-sorted rewrite system, and let  be an equivalence as above and let R0 = fblc ;!brc j l;!r 2 R;  specialization g S f[fw ] (x ; : : : ; xn );![fw0 ] (x ; : : : ; xn ) j fw 2 F; w0 l w ^ [fw ] = 6 [fw0 ] g: 1

1

Then R0 is an unsorted re ection of R.

The proof of this proposition is a straightforward modi cation of the proof for theorem 2, considering equivalence classes of mapped function symbols instead of the symbols themselves. Example 7. The method that discards all sort information is contained in the method indicated in proposition 4 by letting fw  fw0 (and gw 6 fw0 for all g 6= f ). Our method from theorem 2 is contained by letting fw 6 fw0 for all w 6= w0 .

Note that even though the method indicated in proposition 4 is more general than the the method proposed in section 3, the re ection given in theorem 2 always terminates whenever the re ection from proposition 4 does so. It is also worth noticing that for R0 to terminate, the relation  must satisfy

w0 < w ^ fw0  fw =) (8w00 jw0  w00  w =) fw00  fw0  fw ) Otherwise the jump rules would generate the in nite sequence + + + [fw ] (x1 ; : : : ; xn );! R0 [fw00 ] (x1 ; : : : ; xn );! R0 [fw0 ] (x1 ; : : : ; xn );! R0   

Since [fw ] = [fw0 ] , R0 would not be terminating. To enhance readability, we shall in the following write fw for [fw ] for all unsorted function symbols fw in the remaining of this paper. Furthermore, we will assume that  is any equivalence as described above. Example 8. Let an order-sorted rewrite system R be given by

sorts: s; s ; s ; s s ;s  s s s funcs: f : s!s g : s !s a:s b:s rules: (8x : s ) f (x);!f (g(x)) f (b);!f (a) (8y : s ) f (y)!b 1

1

2

11

2

11

1

1

2

1

11

1

11

Using any path ordering, neither the sort-ignoring approach nor the rst version of our method can show that R terminates. The method indicated in proposition 4 amounts to showing blc lpo brc for all specializations  of all rules l;!r 2 R provided that the underlying precedence % on F satis es w0  w =) fw % fw0 for all order-sorted function symbols f and sequences w; w0 of sorts. The precedence

fs  fs1  fs11  fs2  gs1  b  a therefore proves termination of R.

5 A More Elaborate Treatment of Possible F-jumps

Till now we have treated a possible F -jump from fw to fw0 either by a jump rule fw (x1 ; : : : ; xn );! fw0 (x1 ; : : : ; xn ) in the re ection R0 or by not letting the mapping from the order-sorted setting to the unsorted setting distinguish between fw and fw0 . The following example shows a weakness of this approach: Example 9. Let the terminating rewrite system R be given by

sorts: s0 ; s s0  s funcs: f; h : s!s g : s0 !s h : s0 !s0 a:s b : s0 rules: (8x : s0 ) f (x);!f (g(x)) a;!b

Using the techniques from the previous sections in an attempt to establish termination of R gives the non-terminating re ections ffs (x);!fs0 (x); fs0 (x);! fs (gs0 (x)); : : :g and ffs (x);!fs (gs0 (x)); : : :g respectively. Notice also that an F -jump from fs to fs0 may occur because of the second rule. In order to be able to handle examples like the one above we take a closer look at the structure of the terms where the F -jumps can occur. In the example there are two kinds of rewrite steps that lead to F -jumps from fs to fs0 . The rst is f (a);! R f (b), where the function symbol f occurs directly above the sort decreasing rewrite redex. The other possibility is that the rewrite redex is a non-immediate subterm of the occurrence of f . By inspection of the example we nd that this would mean a rewrite step on the form f (h(t));! R f (h(u)) for two terms t and u. Clearly in this case we may replace the jump rule fs (x);!fs0 (x) in the re ection by two new rules fs (a);!fs0 (b) fs (hs (x));!fs0 (hs0 (x)) without altering the fact that it is a re ection. We generalize this property in the following proposition.

Proposition 5. Let R0 be a re ection of an order-sorted rewrite system R in

the way described in the previous sections. Furthermore let

fs1 ;::;si;::;sn (x ; : : : ; xi ; : : : ; xn );!fs1 ;::;s0i;::;sn (x ; : : : ; xi ; : : : ; xn ) 1

1

be a jump rule in R0 . Let R00 be R0 where the above jump rule is replaced by

fs1 ;::;si;::;sn (x ; : : : ; blc ; : : : ; xn );!fs1 ;::;s0i;::;sn (x ; : : : ; brc ; : : : ; xn ) 1

1

for every rule specialization l;!r such that l;!r 2 R, where LS (l) = si and LS (r) = s0i and with a rule

fs1 ;::;si ;::;sn (x ; : : :; gw (y ; : : : ; ym ); : : : ; xn );! fs1 ;::;s0i ;::;sn (x ; : : :; gw0 (y ; : : : ; ym ); : : :; xn ) 1 1

1

1

for each pair gw ; gw0 of function symbols in F where w0 l w, LS (g(x : w)) = si and LS (g(y : w0 )) = s0i . Then R00 is a re ection of R.

The proof of the proposition is straightforward by induction on the length of the path from the position where the F -jump occurs down to the position of the rewrite redex. The method indicated in this proposition is stronger than the one in section 4, since the re ection R0 in proposition 4 is equal to the system obtained by adding the rules mentioned in proposition 5 to R0 . Example 10. (Example 9 cont.) Let us make a re ection where the possible F jumps from fs to fs0 are treated according to proposition 5, and jumps from hs to hs0 are treated by a jump rule. This gives the following rewrite rules in the unsorted re ection.

a;!b fs0 (x);!fs (gs (x)) fs (a);!fs0 (b) fs (hs (x));!fs0 (hs0 (x)) hs (x);!hs0 (x)

The lexicographic path ordering induced by the precedence

a % hs  fs0  fs % gs % gs0 % b % hs0 establishes termination of this re ection, and hence termination of R as well. The induction principle above can of course be nested such that an \induction step rule" fs (gw (x));!fs0 (gw0 (x)) in R0 is replaced by rules on the form fs (gw (blc));!fs0 (gw0 (brc)) and on the form fs (gw (hs1 (x)));!fs0 (gw0 (hs2 (x))) for all necessary rule specializations and pairs fhs1 ; hs2 g of F -symbols. This will clearly create another re ection of the original order-sorted rewrite system.

6 Analysis of Possible F-jumps In the previous sections we have assumed that whenever s0i < si , an F -jump from fs1 ;:::;si ;:::;sn to fs1 ;:::;s0i ;:::;sn can occur. However, in some systems an F jump from fs1 ;:::;si ;:::;sn to fs1 ;:::;s0i ;:::;sn may not occur. Clearly, in sort preserving systems there are no F -jumps at all. Our method can be strengthened by computing the set of F -jumps that actually can take place. An F -jump from fs1 ;:::;si ;:::;sn to fs1 ;:::;s0i ;:::;sn can occur when either { there exists a rewrite rule l;!r 2 R and a specialization  such that LS (l) = si andLS (r) = s0i , or { there exists an F -jump from gw1;:::;wi;:::;wn to gw1;:::;w0i ;:::;wn such that LS (g(x1 : w1 ; : : : ; xi : wi ; : : : ; xn : wn )) = si and LS (g(x1 : w1 ; : : : ; xi : wi0 ; : : : ; xn : wn )) = s0i : This means that from an order-sorted rewrite system R the set of all possible F -jumps may be computed by repeatedly checking for the two conditions, until no further F -jumps can be added to the set. In a nite system there are a nite number of possible F -jumps, all of which can be computed eciently, ensuring that this process terminates. Any possible F -jump can then be handled in the way described in the previous sections. A more thorough analysis also has the advantage that the proposed method can be used on non-sort-decreasing systems as well, something which is demonstrated in the following example: Example 11. Let a terminating rewrite system be given by

sorts: s; s ; s ; s ; s s ;s ;s ;s  s funcs: f; g : s!s g : s !s g : s !s h : s !s a:s b:s rules: a;!b (8x : s ) f (x);!f (h(x)) 1

1

2

2

3

3

4

4

3

1

4

2

1

2

3

4

1

The second rule implies that an unsorted analysis cannot prove termination of the system which is non-sort-decreasing by the rst rule. An analysis of the system gives the set of possible F -jumps as follows: gs3 to gs4 (g(a);! R g (b)) gs1 to gs2 (g(g(a));! R g (g (b)) fs3 to fs4 (f (a);! R f (b)) fs1 to fs2 (f (g(a));! R f (g (b))

We may then create a re ection containing only the jump rules that are necessary. If we use the lexicographic path ordering, each possible F -jump from fw1 to fw2 implies a restriction fw1 % fw2 on the precedence. In this example we would have the restrictions gs3 % gs4 ; gs1 % gs2 ; fs3 % fs4 and fs1 % fs2 which combined with fs1  fs2 , fs1  hs1 and a  b proves termination of the system.

7 Related Work As we have indicated, the most common method for proving termination of order sorted rewrite systems, namely ignoring all sort information, is trivially contained in our method. To the best of our knowledge the problem of order sorted termination as such has only been discussed by Gnaedig in [6]. In the method presented there it is required that the signatures are regular (see [8]), and minimal implying that there is no sequence w such that f : w1 !s 2  , f : w2 !s0 2  and w  w1 ; w2 if w1 6= w2 . Transformed into our notation the translation of function symbols in [6] is de ned as F = ffw!s j f : w!s 2 g and each (sort-decreasing) rewrite rule l;!r is transformed into one unsorted rule blc;!brc where the mapping b c is de ned in the straightforward way. The restriction to minimal signatures implies that it is not necessary to consider rule specializations. The method of Gnaedig is included in our approach by letting fw0  fw if w0  w and f : w!s 2  . Because of minimality and regularity the resulting system is equal (up to renaming of function symbols) to that in Gnaedig's transformation. In [6] it is suggested that in some cases, a non-minimal signature can be made minimal by transforming it into an \equivalent" minimal signature, so that the method described can be applied, even though nothing is said about how the transformation should be done. There exists rewrite systems such that by rst transforming the signature into a minimal one and change the rewrite rules accordingly, the new minimalized system can be shown terminating by Gnaedig's method, but where termination of the original system cannot be proved with any method presented in this paper. In those cases, our methods could of course be applied on the new (minimalized) system as well, maintaining the fact that ours is stronger. A comparison between the di erent approaches to prove order-sorted termination is given in gure 1, where a method M2 is strictly stronger than a method M1 i { whenever M1 combined with a particular unsorted termination proof technique can prove termination of a system, so can method M2 , and { there exist terminating order-sorted rewrite systems and (well-known) unsorted termination proof techniques such that method M1 combined with the technique cannot prove termination while method M2 can do so. In [4], Ganzinger transforms an order-sorted system into an (equational) many-sorted one, using among other constructions jump rules (though used somewhat di erently than in our approach) and sort injections. This is done in

ignoring sort information

&

method section 3 ;! method section 4 ;! method section 5 ;! method s. 6

%

&

&

Gnaedig's method ;! minimalization + ;! minimalisation + ;! Gnaedig's method method section 4

:::

Fig. 1. Comparison of the strength of proposed methods for proving order-sorted termination. An arrow from a method stronger than 1 .

1 to a method

M

M

2 indicates that

2 is strictly

M

M

order to de ne an order-sorted completion procedure, and the resulting system is not well suited for proving termination. Even if we transform this many-sorted system into an unsorted one, skipping sort injections and analyzing possible F jumps, it can be shown that any straight-forward extension of this transformation is included in our method for the purpose of proving termination. Transformation techniques combined with the labeling of function symbols have been used to prove termination of unsorted rewrite systems (see e. g. [14]). In these cases, the goal is to make later proofs of termination easier; we focus on providing an unsorted translation with as few \unnecessary" rewrites as possible3 . The resulting unsorted translation can then be transformed to make termination proofs easier (which is the case in section 4).

8 Conclusion and Further Work The method presented is an extension of the works of Gnaedig [6] and Ganzinger [4]. The latter is not concerned with termination when transforming an ordersorted system into a many-sorted one for completion purposes, but introduces the idea of labeling function symbols. Our approach has been shown to be signi cantly stronger than the method proposed in [6]. The method can be improved in many ways, e. g. in nding more suitable orderings which tackle the speci c problems with the method, making the method more ecient. Another improvement, mentioned above, is to \preprocess" the rewrite system before applying the technique presented here. For instance, a rule (8x : s) l;!r can be replaced by two rules (8x : s1 ) l;!r and (8x : s2 ) l;!r provided that there is no ground term of sort s which is not a term of either sort s1 or sort s2 . 3

The rst generic re ection presented in this paper is a special case of quasi-model semantic labeling in [14] (where the model is the poset of sorts , M is ( ), and the labeling function is the identity on  ), but as shown in example 9, we generally need to nd better translations than this. M

S

S

t

LS t

Our technique is only one of many possible approaches to the problem of proving termination of order-sorted rewriting. A totally di erent idea we have been looking at, is to handle variables in better ways in the termination orderings, always achieving the crucial t  t0 =) t  t0 . In unsorted orderings, a variable is usually not comparable to any term not containing the same variable. This restriction can sometimes be loosened by letting a variable of sort s be comparable to terms that are of a sort di erent from - but comparable to s.

References 1. O.-J. Dahl and O. Owe. Formal development with ABEL. In Proceedings 4th International Symposium of VDM Europe, LNCS 552, 1991. 2. N. Dershowitz. Termination of rewriting. Journal of Symbolic Computation, 3:69{ 116, 1987. 3. N. Dershowitz and C. Hoot. Natural termination. Theoretical Computer Science, 142:179{207, 1995. 4. H. Ganzinger. Order-sorted completion: the many-sorted way. Theoretical Computer Science, 89:3{32, 1991. 5. I. Gnaedig. ELIOS-OBJ: theorem proving in a speci cation language. In Proceedings of the 4th European Symposion on Programming, LNCS 582, pages 182{199, 1992. 6. I. Gnaedig. Termination of order-sorted rewriting. In Proceedings 3rd International Conference on Algebraic and Logic Programming, Pisa (Italy), LNCS 632, pages 37{52, 1992. 7. I. Gnaedig, C. Kirchner, and H. Kirchner. Equational completion in order-sorted algebras. Theoretical Computer Science, 72:169{202, 1990. 8. J. A. Goguen and J. Meseguer. Order-sorted algebra I: Equational deduction for multiple inheritance, overloading, exceptions and partial operators. Technical report, Programming Research Group, Oxford University Computing Laboratory, 1989. 9. J. A. Goguen and T. Winkler. Introducing OBJ3. Technical report, SRI International, Computer Science Lab, 1988. 10. S. Kamin and J.-J. Levy. Two generalizations of the recursive path ordering. Unpublished Note, Department of Computer Science, University of Illinois, Urbana, IL, 1980. 11. D. E. Knuth and P. B. Bendix. Simple word problems in universal algebras. In J. Leech, editor, Computational Problems in Abstract Algebra, pages 263{297. Pergamon Press, Oxford, 1970. 12. P. Lescanne. Termination of rewrite systems by elementary interpretations. In Proceedings 3rd International Conference on Algebraic and Logic Programming, Pisa (Italy), LNCS 632, pages 21{36, 1992. 13. U. Waldman. Semantics of order-sorted speci cations. Theoretical Computer Science, 94:1{35, 1992. 14. H. Zantema. Termination of term rewriting by semantic labelling. Fundamenta Informaticae, 24:89{105, 1995. This article was processed using the LATEX macro package with LLNCS style