Order-sorted termination: The unsorted way

15

Transcript of Order-sorted termination: The unsorted way

Order-Sorted Termination: the Unsorted Way

Peter Csaba �Olveczky1 and Olav Lysne2

1 Department of Informatics, University of BergenThe High Technology Center, 5020 Bergen, NORWAY

E-mail: [email protected]

2 Department of Informatics, University of OsloPo. box 1080 Blindern, 0316 Oslo, NORWAY

E-mail: Olav.Lysne@i�.uio.no

Keywords: Order-sortedness, Termination

Abstract. We consider the problem of proving termination of order-sorted rewrite systems. The dominating method for proving terminationof order-sorted systems has been to simply ignore sort information, anduse the techniques developed for unsorted rewriting. The problem withthis approach is that many order-sorted rewrite systems terminate be-cause of the structure of the set of sorts. In these cases the correspondingunsorted system would not terminate.In this paper we approach the problem of order-sorted termination bymapping the order-sorted rewrite system into an unsorted one such thattermination of the latter implies termination of the former. By encodingsort information into the unsorted mapping, we are able to use gen-eral purpose termination orderings to prove termination of order-sortedrewrite systems whose termination depend on the sort hierarchy. Wepresent a sequence of gradually stronger methods, and show that a pre-viously 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 hasbeen introduced to term rewriting to provide for a more powerful type concept,allowing us to express partiality of functions, error handling and subtype inher-itance [8]. In languages like OBJ3 [9] and ABEL [1], order-sorted speci�cationsare given an operational semantics based on term rewriting.

One of the most important properties a rewrite system may have is termi-nation, which means that no in�nite computation in the system can take place.In general it is undecidable whether a rewrite system terminates, but numeroustechniques have been developed that with varying degrees of success may beused to prove termination of unsorted rewrite systems. These techniques includethe path orderings [10, 2, 3], interpretation techniques [12], and not to forget theseminal Knuth and Bendix ordering [11].

The dominating method for proving termination of order-sorted systems hasbeen to simply ignore sort information, and use the methods developed for un-sorted rewriting [7, 5]. The problem with this approach is that many order-sortedrewrite systems terminate because of the structure of the set of sorts. In thesecases the corresponding unsorted system would not terminate, as is illustratedby 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 isto de�ne is even over the positive numbers �rst and to extend it to the negativenumbers 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 : Zeros : Pos!NzPos

p : Neg!NzNeg

true : Boolfalse : Boolis 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 rulewould 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 sortNzPos, so y cannot be instantiated with opposite(t) for any term t.

In [4] Ganzinger studied completion of order-sorted rewrite systems, and heintroduced the idea of transforming an order-sorted rewrite system into a many-sorted equational one. Ganzinger lets each function declaration f : w!s inducea (many-sorted) function symbol fw!s. This idea was adopted by Gnaedig [6]who used these labeled function symbols to prove termination of order-sortedrewrite 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 mustbe incomparable with respect to �.

We will also pursue the idea of labeling each function symbol in a term. Weshall, however, use another labeling technique, and we shall also use anothermapping from order-sorted rewrite systems to unsorted ones. By doing this weavoid the limitation to minimal signatures, and we are able to show that ourmethod is a proper extension of the one in [6].

The paper is organized as follows: After de�ning basic notions of order-sortedrewriting, we introduce the basic concepts of our approach in section 3. In sec-tion 4 we show that the �rst version of our technique is unreasonably weak andpropose a straight-forward amelioration, obtaining a method stronger than pre-vious approaches to the problem of order-sorted termination. This method isthen made stronger, though somewhat more complicated (section 5), and is ex-tended to handle non-sort-decreasing rules as well (section 6) before the proposedmethod is compared to Gnaedig's approach to order-sorted termination [6] andGanzinger'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 extensionto our proposed method and then indicate a di�erent approach to order-sortedtermination 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] comparesthe two main semantic variations of order-sorted algebra { overloading vs. non-overloading. In this paper, where the rewrite relation is based on overloadedalgebra semantics, notions and notations mainly follow [8] and [7].

Order-sorted algebra is based on a subsort relation, a partial order � on aset S of sorts. We write s0 < s when s0 � s and s0 6= s and � for the symmetricrelation of �. The subsort relation � can be extended to n-tuples of sorts (oftendenoted w) where w = hs1; : : : ; sni � hs01; : : : ; s

0ni = 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 andw and w0 only di�ers in one position, e.g. w = hs1; : : : ; si�1; si; si+1; : : : ; sni,w0 = hs1; : : : ; si�1; s

0i; si+1; : : : ; sni and si < s0i.

A function declaration has the form f : s1; : : : ; sn!s where each si is asort symbol. If n = 0 then f is called a constant and the declaration is writtenf : s. An order-sorted signature hS;�; �i, usually denoted just �, consists of apartially 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, andf(t1; : : : ; tn) 2 T (�;X)s if there exists a declaration f : s1; : : : ; sn!s0 such thatti is a term of sort si for i = 1::n and s0 � s. The set T (�;X) is de�ned asT (�;X) = f

Ss2S T (�;X)sg and an element of any set T (�;X)s is called a

(well-formed) term. In this paper we assume that every order-sorted signatureis �nite (i. e. contains a �nite number of sort and function symbols), that everyterm has a unique least sort, denoted LS(t) and that there exists a ground termof every sort in the signature.

A term may be viewed as a tree in the obvious way. A position in a term canbe seen as a �nite sequence of natural numbers, identifying a path from the rootof 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 rootsymbol at position p. The result of replacing the subterm of t at position p bythe term u is written t[u]p. If p and q are positions we write p:q to denote theconcatenation of p and q.

A substitution � = f�s : Xs!T (�; Y )s j s 2 Sg is a mapping from variablesto terms. We shall use lowercase Greek letters to denote substitutions. The ap-plication of a substitution � to a term t consists of simultaneously replacing thevariables occurring in t by a term according to the mapping. The result of thisapplication is written t�.

A specialization, often written �, is a substitution � : X!Y that maps avariable 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 andr are terms in T (�;X) and where the least sorts of the terms l and r are in thesame connected component (i. e. in the same equivalence class of the symmetricand transitive closure) of hS;� i. Given a rewrite system, i. e. a set of rewriterules, R, a term t 2 T (�;X) rewrites to t0 with a rule (8Y ) l�!r in R atposition p, denoted t�!

Rt0 if

1. there is a substitution � : Y!T (�;X) such that l� = tjp and t0 = t[r�]pand

2. there is a sort s such that, for x a variable of sort s, t[x]p is a well-formedterm and l�; r� 2 T (�;X)s.

We write t �!+R

t0 when t rewrites to t0 in one or more steps. A system is sort-decreasing if every rule l�!r is sort-decreasing, i. e. LS(l�) � LS(r�) for everysubstitution �. Sort-decreasingness ensures 1) that condition 2 in the abovede�nition of rewriting is satis�ed when the �rst condition is ful�lled, 2) thatthe rewrite relations based on non-overloaded and overloaded semantics resp.coincide, 3) that the critical pair lemma is valid and 4) that Birkho�'s theoremis valid for con uent systems [7]. In sections 3 to 5 every rewrite system isassumed to be sort-decreasing.

3 Re ections of Order-Sorted Rewriting

In this section we propose a technique for proving termination of an order-sortedrewrite system R by transforming it into an unsorted system R0.

De�nition 1 An unsorted rewrite system R0 re ects an order-sorted rewritesystem R with signature � i� there exists a mapping M from T (�;X) to aset of unsorted terms such that t�!

Rt0 =)M(t)�!+

R0 M(t0) for all terms t; t0 2

T (�;X).

Example 2. For any order-sorted rewrite system the trivial mapping to unsortedrewriting by removing all sort information is a re ection.

Proposition 1. An order-sorted rewrite system terminates if it has a terminat-ing unsorted re ection.

The challenge is therefore to �nd a suitable re ection for any given order-sortedrewrite system. One way to �nd such a re ection would be to implement order-sorted rewriting by means of an unsorted system. This would, however, indicatethe introduction of a lot of new rewrite rules whose only mission would be toperform the actions of order-sorted rewriting, and to prove the termination ofthese rules would be a challenge in itself.

We shall propose a simpler method for �nding re ections, that gives an un-sorted 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 corre-sponding 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 � w0g

where the arity of fw is jwj.

A term t in T (�;X) is represented in T (F;X) by the term btc where eachfunction 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 translationof � is de�ned inductively as follows:

{ bx : sc = x for a variable x 2 Xs.{ bf(t1; : : : ; tn)c = fLS(t1);:::;LS(tn)(bt1c; : : : ; 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�!brcj l�!r 2 Rg is not su�cient: the rule blc�!brc will notin 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 rulebl�c�!br�c for every specialization � of each rule l�!r in R. Unfortunately,the following example shows that not even this de�nition is su�cient to makeR0 a re ection of an order-sorted system R:

Example 3. Let a rewrite system R be given by

sorts: s; s1; s2s1; s2 � s

funcs: f; g : s!s

g : s1!s2a : sb : s1

rule: a�!b

The term f(g(a)) rewrites to f(g(b)) in R but bf(g(a))c = fs(gs(a)) and alsobf(g(b))c = fs2(gs1(b)) so we need fs(gs(a))�!

+

R0 fs2(gs1(b)) which is not true if

R0 contains only the rule a�!b.

In the above example all the (mapped) function symbols in the term changedeven 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 rewritesystem and that the rule is applied at position p in t. There is a function symboljump, often just called an F -jump, from fw to fw0 if there is a position q in t

such that btcjq = fw(: : :) and bt0cjq = fw0(: : :) and there is no position r suchthat q = p:r.

In the previous example we had two F -jumps, from fs to fs2 and from gs togs1 respectively. Sort-decreasingness and monotonicity properties of order-sortedsignatures imply that w0lw when an F -jump from fw to fw0 occurs. To handlethis, a so-called jump rule

fw(x1; : : : ; xn)�!fw0(x1; : : : ; xn)

is added to R0 for all symbols fw; fw0 in F when w0lw. In example 2, R0 wouldhave 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 wherethe rewrite sequence fs(gs(a))�!R0 fs(gs(b))�!R0 fs(gs1(b))�!R0 fs2(gs1(b)) yieldsthe desired bf(g(a))c�!+

R0 bf(g(b))c.

Theorem2. Let R be an order-sorted rewrite system, and let

R0 = fbl�c�!br�c j l�!r 2 R; � specialization gS

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.

Proof: Assume that t�!R

t0 by applying rule l�!r 2 R at position p in t withsubstitution �. We must show that btc�!+

R0 bt0c. 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; : : : ; x

0

n 7! bxn�cg: Then it can be shown that bt�c = bt�c�0

for all terms t. Now we have

btc = bt[tjp]pc = bt[l�]pc = btc[bl�c]p = btc[bl�c�0]p�!R0 btc[br�c�0]p = btc[br�c]p

thus btc rewrites by R0 to btc[br�c]p in one step.It is easy to see that btc[br�c]p and bt

0c = bt[r�]pc only di�er in the positionswhere function symbol jumps have occurred. Since R is sort-decreasing we knowthat the F -jumps will all be of the form fw to fw0 , where w

0l w. But then we

know that btc[br�c]p�!+

R0 bt[r�]pc = bt0c 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 = fbl�c�!br�c j l�!r 2 R; � specialization gS

ffw(x1; : : : ; xn)�!fw0(x1; : : : ; xn) j fw 2 F;w0 l w:g

If R0 terminates then so does R.

Let us see how the method can be applied to the following system, whichcannot 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 : sb : s0

rules: (8x :s0) f(x)�!g(x)g(a)�!f(a)

We use the lexicographic path ordering. Since s0 < s the precedence % on func-tion symbols must satisfy gs � gs0 and fs � fs0 in order to show termination ofthe jump rules. In addition we must have

bf(x :s0)c = fs0(x) �lpo gs0(x) = bg(x)cbg(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 1can be proved by using corollary 3 and the lexicographic path ordering with theprecedence

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 w0l 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 takeplace.

2. There are cases where the F -jumps can occur, but where the jump rulescause 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 howjump-rules may be avoided by considering equivalence classes of mapped functionsymbols. In section 5 we introduce the possibility of replacing jump-rules by aninductive schema of rules. Finally we open for detection of which F -jumps canactually take place, and thereby detection of which jump rules that are strictlynecessary.

4 Equivalences of Mapped Function Symbols

One of the main disadvantages of (the �rst version of) our method is that werequire 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 beweaker 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 : srules: f(a)�!f(b)

(8x :s0) f(x)�!a

Assume that we want to show termination of R by a path ordering using prece-dences on function symbols. Ignoring the sorts, termination of the system isproved with the precedence f � a � b. Using our method from the previoussection, 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 becausethe 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 weintroduce 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 followingwe let [fw]� denote the equivalence class of fw under �. To ensure that termsremain well-formed, we require that gw � fw0 only if these function symbolshave 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 equivalencerelation 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 ectionR0�on F� by replacing each fw in the re ection of corollary 3 with [fw]� and

omitting jump rules [fw]�(x1; : : : ; xn)�![fw0 ]�(x1; : : : ; xn) if [fw]� = [fw0 ]�:

Proposition 4. Let R be a �nite, sort-decreasing order-sorted rewrite system,and let � be an equivalence as above and let

R0�

= fbl�c��!br�c� j l�!r 2 R; � specialization gS

f[fw]�(x1; : : : ; xn)�![fw0 ]�(x1; : : : ; xn) j fw 2 F;w0 l w ^ [fw]� 6= [fw0 ]�g:

Then R0�

is an unsorted re ection of R.

The proof of this proposition is a straightforward modi�cation of the proof fortheorem 2, considering equivalence classes of mapped function symbols insteadof the symbols themselves.

Example 7. The method that discards all sort information is contained in themethod indicated in proposition 4 by letting fw � fw0 (and gw 6� fw0 for allg 6= f). Our method from theorem 2 is contained by letting fw 6� fw0 for allw 6= w0.

Note that even though the method indicated in proposition 4 is more generalthan the the method proposed in section 3, the re ection given in theorem 2always 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 =) (8w00jw0 � 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 allunsorted function symbols fw in the remaining of this paper. Furthermore, wewill assume that � is any equivalence as described above.

Example 8. Let an order-sorted rewrite system R be given by

sorts: s; s1; s2; s11s1; s2 � s

s11 � s1funcs: f : s!s

g : s1!s2a : s1b : s11

rules: (8x :s1) f(x)�!f(g(x))f(b)�!f(a)(8y :s11) f(y)!b

Using any path ordering, neither the sort-ignoring approach nor the �rst versionof our method can show that R terminates.

The method indicated in proposition 4 amounts to showing bl�c �lpo br�cfor all specializations � of all rules l�!r 2 R provided that the underlyingprecedence % on F satis�es w0 � w =) fw % fw0 for all order-sorted functionsymbols 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 jumprule 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 distinguishbetween 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 : sb : s0

rules: (8x :s0) f(x)�!f(g(x))a�!b

Using the techniques from the previous sections in an attempt to establish ter-mination 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 anF -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 closerlook at the structure of the terms where the F -jumps can occur. In the examplethere are two kinds of rewrite steps that lead to F -jumps from fs to fs0 . The�rst is f(a)�!

Rf(b), where the function symbol f occurs directly above the sort

decreasing rewrite redex. The other possibility is that the rewrite redex is anon-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))�!

Rf(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 inthe following proposition.

Proposition 5. Let R0�

be a re ection of an order-sorted rewrite system R inthe way described in the previous sections. Furthermore let

fs1;::;si;::;sn(x1; : : : ; xi; : : : ; xn)�!fs1;::;s0i;::;sn(x1; : : : ; xi; : : : ; xn)

be a jump rule in R0�. Let R00

�be R0

�where the above jump rule is replaced by

fs1;::;si;::;sn(x1; : : : ; bl�c�; : : : ; xn)�!fs1;::;s0i;::;sn(x1; : : : ; br�c

�; : : : ; xn)

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

fs1;::;si;::;sn(x1; : : : ; gw(y1; : : : ; ym); : : : ; xn)�!fs1;::;s0i;::;sn(x1; : : : ; gw0(y1; : : : ; ym); : : : ; xn)

for each pair gw; gw0 of function symbols in F where w0 l w, LS(g(x :w)) = siand LS(g(y :w0)) = s0i. Then R00

�is a re ection of R.

The proof of the proposition is straightforward by induction on the lengthof the path from the position where the F -jump occurs down to the position ofthe rewrite redex.

The method indicated in this proposition is stronger than the one in section4, 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 hsto hs0 are treated by a jump rule. This gives the following rewrite rules in theunsorted 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 \induc-tion step rule" fs(gw(x))�!fs0(gw0(x)) in R0 is replaced by rules on the formfs(gw(bl�c))�!fs0(gw0(br�c)) and on the form fs(gw(hs1(x)))�!fs0(gw0(hs2(x)))for all necessary rule specializations and pairs fhs1 ; hs2g of F -symbols. This willclearly 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 -jumpfrom 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 preservingsystems there are no F -jumps at all.

Our method can be strengthened by computing the set of F -jumps thatactually can take place. An F -jump from fs1;:::;si;:::;sn to fs1;:::;s0i;:::;sn can occurwhen either

{ there exists a rewrite rule l�!r 2 R and a specialization � such thatLS(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

andLS(g(x1 : w1; : : : ; xi : w

0

i; : : : ; xn : wn)) = s0i:

This means that from an order-sorted rewrite system R the set of all possibleF -jumps may be computed by repeatedly checking for the two conditions, untilno further F -jumps can be added to the set. In a �nite system there are a �nitenumber of possible F -jumps, all of which can be computed e�ciently, ensuringthat this process terminates. Any possible F -jump can then be handled in theway described in the previous sections.

A more thorough analysis also has the advantage that the proposed methodcan be used on non-sort-decreasing systems as well, something which is demon-strated in the following example:

Example 11. Let a terminating rewrite system be given by

sorts: s; s1; s2; s3; s4s1; s2; s3; s4 � s

funcs: f; g : s!s

g : s3!s1g : s4!s2h : s1!s2a : s3b : s4

rules: a�!b

(8x :s1) f(x)�!f(h(x))

The second rule implies that an unsorted analysis cannot prove termination ofthe system which is non-sort-decreasing by the �rst rule. An analysis of thesystem gives the set of possible F -jumps as follows:

gs3 to gs4 (g(a)�!R

g(b))gs1 to gs2 (g(g(a))�!

Rg(g(b))

fs3 to fs4 (f(a)�!R

f(b))fs1 to fs2 (f(g(a))�!

Rf(g(b))

We may then create a re ection containing only the jump rules that arenecessary. If we use the lexicographic path ordering, each possible F -jump fromfw1

to fw2implies a restriction fw1

% fw2on the precedence. In this example we

would have the restrictions gs3 % gs4 ; gs1 % gs2 ; fs3 % fs4 and fs1 % fs2 whichcombined 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 oforder sorted rewrite systems, namely ignoring all sort information, is triviallycontained in our method.

To the best of our knowledge the problem of order sorted termination as suchhas only been discussed by Gnaedig in [6]. In the method presented there it isrequired that the signatures are regular (see [8]), and minimal implying thatthere 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 symbolsin [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 themapping b c is de�ned in the straightforward way. The restriction to minimalsignatures implies that it is not necessary to consider rule specializations. Themethod 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 isequal (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 bemade minimal by transforming it into an \equivalent" minimal signature, so thatthe method described can be applied, even though nothing is said about howthe transformation should be done. There exists rewrite systems such that by�rst transforming the signature into a minimal one and change the rewrite rulesaccordingly, the new minimalized system can be shown terminating by Gnaedig'smethod, but where termination of the original system cannot be proved with anymethod presented in this paper. In those cases, our methods could of course beapplied on the new (minimalized) system as well, maintaining the fact that oursis stronger.

A comparison between the di�erent approaches to prove order-sorted termi-nation is given in �gure 1, where a method M2 is strictly stronger than a methodM1 i�

{ whenever M1 combined with a particular unsorted termination proof tech-nique can prove termination of a system, so can method M2, and

{ there exist terminating order-sorted rewrite systems and (well-known) un-sorted termination proof techniques such that method M1 combined withthe 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 usedsomewhat 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 ter-mination. An arrow from a method M1 to a method M2 indicates that M2 is strictlystronger than M1.

order to de�ne an order-sorted completion procedure, and the resulting systemis not well suited for proving termination. Even if we transform this many-sortedsystem into an unsorted one, skipping sort injections and analyzing possible F -jumps, it can be shown that any straight-forward extension of this transformationis included in our method for the purpose of proving termination.

Transformation techniques combined with the labeling of function symbolshave 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 fo-cus on providing an unsorted translation with as few \unnecessary" rewrites aspossible3. The resulting unsorted translation can then be transformed to maketermination 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 order-sorted system into a many-sorted one for completion purposes, but introducesthe idea of labeling function symbols. Our approach has been shown to be sig-ni�cantly stronger than the method proposed in [6].

The method can be improved in many ways, e. g. in �nding more suitable or-derings which tackle the speci�c problems with the method, making the methodmore e�cient. Another improvement, mentioned above, is to \preprocess" therewrite 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 sorts1 or sort s2.

3 The �rst generic re ection presented in this paper is a special case of quasi-modelsemantic labeling in [14] (where the modelM is the poset of sorts S, tM is LS(t), andthe labeling function is the identity on S�), but as shown in example 9, we generallyneed to �nd better translations than this.

Our technique is only one of many possible approaches to the problem ofproving termination of order-sorted rewriting. A totally di�erent idea we havebeen looking at, is to handle variables in better ways in the termination order-ings, always achieving the crucial t � t0 =) t� � t0�. In unsorted orderings, avariable 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 becomparable 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 4thInternational 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 Com-puter Science, 89:3{32, 1991.

5. I. Gnaedig. ELIOS-OBJ: theorem proving in a speci�cation language. In Proceed-ings of the 4th European Symposion on Programming, LNCS 582, pages 182{199,1992.

6. I. Gnaedig. Termination of order-sorted rewriting. In Proceedings 3rd Interna-tional 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-sortedalgebras. Theoretical Computer Science, 72:169{202, 1990.

8. J. A. Goguen and J. Meseguer. Order-sorted algebra I: Equational deduction formultiple inheritance, overloading, exceptions and partial operators. Technical re-port, Programming Research Group, Oxford University Computing Laboratory,1989.

9. J. A. Goguen and T. Winkler. Introducing OBJ3. Technical report, SRI Interna-tional, Computer Science Lab, 1988.

10. S. Kamin and J.-J. L�evy. Two generalizations of the recursive path ordering. Un-published 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. InJ. Leech, editor, Computational Problems in Abstract Algebra, pages 263{297. Perg-amon Press, Oxford, 1970.

12. P. Lescanne. Termination of rewrite systems by elementary interpretations. InProceedings 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 Sci-ence, 94:1{35, 1992.

14. H. Zantema. Termination of term rewriting by semantic labelling. FundamentaInformaticae, 24:89{105, 1995.

This article was processed using the LATEX macro package with LLNCS style