confluent reductions: abstract properties and applications...

25
Confluent Reductions: Abstract Properties and Applications to Term Rewriting Systems GERARD HUET INR1A, Le Chesnay,France ABSTRACT This paper gives new results, and presents old ones m a umfied formahsm, concerning Church- Rosser theorems for rewrmng systems Abstract confluence propentes, depending solely on axioms for a binary relatton called reduction, are first presented Results of Newman and others are presented m a unified formahsm The systemattc use of a powerful mductmn pnnciple permRs the generahzauon of results of Sethl on reduction modulo eqmvalence. Simphficatton systems operating on terms of a first-order logic are then considered. Results by Rosen and Knuth and Bendix are extended to give several new crtteria for confluence of these systems It ts then shown how these criteria yield new methods for the mechanizaUon of equattonal theories KEY WORDS AND PHRASES Church-Rosser property, confluence, combinatorial theories, equattonal theories, operauonal semantics, equality theorem prowng CRCATEGORIES. 5 21, 5 24 1. Introduction Term rewriting systems are an interesting model of computation. They may be used to represent abstract interpreters of programming languages and to model formula manipu- latmg systems used in various applications, such as program optimization, program validation, and automatic theorem proving. A generalization of these systems consists in considering rewritings on equivalence classes of terms, defined by a set of equations. These equations may be used, for mstance, to define abstract data types. A fundamental property of term rewriting systems is confluence, depicted in Figure 3. In confluent systems replacements may be effected deterministically, i.e., there is no need to backtrack to consider other possible rewritmgs. Confluence is equivalent to the Church- Rosser property, which expresses the fact that mterconvertlbility of two terms can be checked by mere simplification to a common form. Confluent term rewriting systems in which every computation termmates determine a decision procedure for the corresponding equational theory, since every term possesses a unique canonical form. We consider m this paper sufficient conditions for the confluence of a term rewriting system. The general strategy is inspired by Knuth and Bendix [16]. We show that confluence is implied by the confluence of certain special cases, the critical pairs. Critical pairs are computed by a superposition algorithm, where one attempts to match in a most general way the left-hand side of some rule with a nonvariable subterm of some other left- hand side. For instance, the two rules F(G(x, y, A )) ~ H(x, y) and G(B, x, y) --~ K(y, x) determine a cnucal pair (F(K(A, x)), H(B, x)). We show that various closure conditions on the critical pairs imply the closure of corresponding diagrams in the general case. The Permission to copy wRhout fee all or part of this material is granted provided that the copies are not made or dtstrtbuted for dtrect commerctal advantage, the ACM copyrtght nottce and the tttle of the pubhcation and its date appear, and notice is gwen that copying is by pertmsslon of the Association for Computing Machinery. To copy otherwtse, or to repubhsh, requires a fee and/or spectfic permission A prehmmary version of this paper was presented at the 18th IEEE Symposmm on Foundations of Computer Sctence, Provtdence, R !, October 1977 Author's address' INRIA, Domame de Voluceau-Roequencourt, B.P. 105-78150 Le Chesnay, France. © 1980 ACM 0004-541 !/80/1000-0797 $00 75 Journal of the Arssocuttton for Computing Machinery, Vol 27. No 4, October 1980, pp 797-821

Upload: others

Post on 14-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

Confluent Reductions: Abstract Properties and Applications to Term Rewriting Systems

GERARD HUET

INR1A, Le Chesnay, France

ABSTRACT This paper gives new results, and presents old ones m a umfied formahsm, concerning Church- Rosser theorems for rewrmng systems

Abstract confluence propentes, depending solely on axioms for a binary relatton called reduction, are first presented Results of Newman and others are presented m a unified formahsm The systemattc use of a powerful mductmn pnnciple permRs the generahzauon of results of Sethl on reduction modulo eqmvalence.

Simphficatton systems operating on terms of a first-order logic are then considered. Results by Rosen and Knuth and Bendix are extended to give several new crtteria for confluence of these systems It ts then shown how these criteria yield new methods for the mechanizaUon of equattonal theories

KEY WORDS AND PHRASES Church-Rosser property, confluence, combinatorial theories, equattonal theories, operauonal semantics, equality theorem prowng

CR CATEGORIES. 5 21, 5 24

1. Introduction

Term rewriting systems are an interesting model o f computat ion. They may be used to represent abstract interpreters o f p rogramming languages and to mode l formula manipu- la tmg systems used in various applications, such as p rogram optimizat ion, p rogram validation, and automat ic theorem proving. A general izat ion o f these systems consists in considering rewritings on equivalence classes o f terms, def ined by a set o f equations. These equat ions may be used, for mstance, to define abstract data types.

A fundamenta l property o f term rewriting systems is confluence, depicted in F igure 3. In conf luent systems replacements may be effected determinist ically, i.e., there is no need to backtrack to consider other possible rewritmgs. Conf luence is equivalent to the C h u r c h - Rosser property, which expresses the fact that mterconvert lbi l i ty o f two terms can be checked by mere simplif ication to a c o m m o n form. Conf luen t term rewrit ing systems in which every computa t ion te rmmates determine a decision procedure for the corresponding equat ional theory, since every term possesses a unique canonical form.

We consider m this paper sufficient condit ions for the conf luence o f a te rm rewrit ing system. The general strategy is inspired by Knu th and Bendix [16]. We show that confluence is implied by the confluence o f certain special cases, the critical pairs. Cri t ical pairs are computed by a superposi t ion algori thm, where one at tempts to match in a most general way the left-hand side o f some rule with a nonvar iable subterm o f some o ther left- hand side. For instance, the two rules F(G(x, y, A )) ~ H(x, y) and G(B, x, y) --~ K(y, x) determine a c n u c a l pair (F(K(A, x)), H(B, x)). We show that var ious closure condi t ions on the critical pairs imply the closure o f corresponding diagrams in the general case. The

Permission to copy wRhout fee all or part of this material is granted provided that the copies are not made or dtstrtbuted for dtrect commerctal advantage, the ACM copyrtght nottce and the tttle of the pubhcation and its date appear, and notice is gwen that copying is by pertmsslon of the Association for Computing Machinery. To copy otherwtse, or to repubhsh, requires a fee and/or spectfic permission A prehmmary version of this paper was presented at the 18th IEEE Symposmm on Foundations of Computer Sctence, Provtdence, R !, October 1977 Author's address' INRIA, Domame de Voluceau-Roequencourt, B.P. 105-78150 Le Chesnay, France. © 1980 ACM 0004-541 !/80/1000-0797 $00 75

Journal of the Arssocuttton for Computing Machinery, Vol 27. No 4, October 1980, pp 797-821

Page 2: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

7 9 8 GERARD HUET

diagrams in turn imply confluence under certain conditions. For instance, we show that a left-linear term rewriting system ~ is confluent when P ~ Q for every critical pair (P, Q }, where ~ is parallel disjoint reduction by #~, generalizing a theorem of Rosen. We show how some of these results carry over to rewritings of equational classes of terms, yielding a decision procedure for the confluence of certain equational theories.

All our results are carefully partit ioned between abstract diagrammatic properties that depend solely on axiomatic conditions on the reduction relation and properties depend- ing on the term structure. The abstract confluence properties are studied separately in Section 2, which unifies and extends results of Newman [23] and Sethi [34].

2. Abstract Reduction Properties

2.1 GENERALITIES. Let 8 be an arbitrary set. We give in this section some more or less well-known properties of a binary relation --) on 8, which we call reduction. These properties are abstract in the sense that they depend solely on axioms for the reduction relation.

Notatwn

t is the identity relation on ~ : , = {(x, x) I x E ~}. • is relation composition: --)a.--)b = {(x, y) 13z x ---), z & z ---)b y}. ...)-1 is the inverse of relat ion--): ._)-i = {(x, y ) lY ~ x}.

For any relation ~ on 8, we now define 0 - - . > z ~

,-.% = - - ) U * = --) .--) V i > 0

+ - - ~ = U,>o

reflexive closure of---); /-fold composition o f - * ; transitive closure of ~ ; transitive-reflexive closure of--) ; symmetric closure of---).

I f x is minimal with respect to --,, i.e., ~ y x ~ y, we say that x is a --)-normal form, and we let X be the set of all such elements. For x ~ 8, if there exists y E ~A:such tha tx --~ y, we say that y is a - , -normal form o fx .

For a given relation ---), we let

x ] , y ~ 3 z x ~ z & y ~ z, x] 'y ~ 3z z--~ x & z ~ y,

A(x) = m a x { i l 3 y x--~ y } E N U {~}, A(x) = { y l x ---) y} ,

A+(x) = { y l x ~ y}, a*(x) = a÷(x) u {x}.

Definition. We say that relation ~ is

(i) inductive i f f for every sequence xl ~ x2 ~ . . . ---> x , ~ . . . , there existsy such that Vi_> 1 x,-% y;

(ii) acyclic iff ~ is irreflexive (and then ~ is a part ial ordering relation); (iii) noetherian iff there is no infinite sequence x~ ~ x2 ~ . . . ~ x , ~ . . . ( then-~ is

well founded); (iv) bounded lff Vx A(x) < ~ ( then-~ is of order type o~; this is called the finiteness

property in !1, 34]).

Every bounded relation is noetherian, and every noetherian relation is inductive and acydic.

Let P be any predicate on g. We say that P is ---)-complete iff

Vx E 8 [Vy E A+(x) P (y ) ] =* P(x).

Our interest in noetherian relations stems from the following.

Page 3: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

Confluent Reductions 799

X

x 3 + . . ~. x n

Figure 1

Figure 2

Principle of Noethertan Inducnon. Let --> be a n o e t h e n a n relation, and let P be a -+-complete predicate. Then Vx ~ 8 P(x).

This principle is as powerful as the usual forms of transfinite reduction. It has the advantage of not requir ing the construction of a (total) well ordering, using directly the partial ordering -~ instead. For its justif ication see [5], and for examples of its use see [3].

Defimtion. We say that relation ~ is locally finite iff Vx ~ 8,~(x) is finite. Let ~ be a locally finite relation. For every x in 8, if A(x) -- o0, then there exists an

infinite sequence x = xl ~ x2 -~ . - - ~ xn -~ . . . , using Koenig 's lemma. Therefore a locally finite relation is bounded iff it is noetherian.

We say that relation ~ is globally finite iff Vx E 8 A*(x) is finite.

Let ~ be a locally finite relation. For every x in 8, if ~*(x) is infinite, then A(x) = o0, and, as above, there exists an infinite sequence x = x~ --> x2 ~ . . . - o xn --> • . . . Therefore a noether ian locally finite relation is globally finite. Conversely, any acydic globally finite relation is bounded.

Finally, note that acychc and noether ian does not imply bounded, as shown by Fig- ure I. Also, acyclic, inductive, and locally finite implies nei ther noether ian nor globally finite, as shown by the dual example in Figure 2.

2.2 CONFLUENCE PROPERTIES. Suppose we are interested in the equivalence ~ gen- erated by a relation -+. We are going to give condit ions on ~ that permit us to recogmze if x ~ * y when performing only reductions (-~) from x and y.

Definition. We say that the relation ~ is confluent iff Vxy x Ty ~ x~y.

We express this property with the diagram in Figure 3. In this sort of diagram, dashed arrows denote (existential) reductions depending on the (universal) reductions shown by full arrows.

The results of this section appear in N e w m a n [23]. They have been rediscovered by several authors in various contexts, where --, is interpreted as the fl-reduction relat ion in h-calculus [4, 6, 9], the deduct ion relation in a formal system, or the operat ional semantics in a p rogramming language.

LEMMA 2.1 I f ---~ is confluent, then the followmg "Church-Rosser" property holds: Vxy x ~---~yc-~x~y.

Page 4: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

800

/ \ x y v z \ / " \ / \ / \ /

\ I \ / \ / \ / v V

Figure 3 Figure 4

PROOF. By induction on n, where x ~ y. []

GI~RARD HUET

LEMMA 2.2 I f --~ is confluent, then the normal form of any element, i f it exists, is unique.

PROOF. Trivial. [ ]

The converse of this lemma, when ~ is such that every element possesses a normal form, is also true. This will be the case, for instance, with acyclic inductive relations (using Zorn's lemma).

The two preceding lemmas show the interest of confluent relations. The rest of this section is devoted to finding sufficient conditions for a relation to be confluent. First, R is easy to partially localize the test for confluence.

LEMMA 2.3 ~ is confluent i f fVxyz x ---, y & x -% z ~ y~z.

PROOF. By induction on n, where x--~ z. []

In the case of noetherian relations it is possible to localize the confluence test completely.

Definition. We say that relation ~ is locally confluent iff

Vxyz x ~ y & x ~ z ~ y ~,z.

The corresponding diagram is shown in Figure 4.

LEMMA 2.4. A noetherian relation is confluent iff it is locally confluent.

This lemma appears in various places in the literature in weaker forms: either the relation is required to be bounded (easy induction on A(x)) [1, 34], or it is assumed to be locally finite [17], or it is proved for a specific noetherian relation [16] (ad hoc induction). Several weaker forms are given in [36]. It appears in its full generality in [23], but with an unnecessarily complex proof. Let us show how noetherian induction permits an easy and natural proof.

PROOF OF LEMMA 2.4. The "only if" part is trivial. For the " i f" part, assume ~ is a noetherian locally confluent relation. We prove P(x): Vyz x -% y & x -% z =-~ y ~z t3y noetherian induction, showing that P is a -comple te .

Let x ~ y and x --~ z. We show that 3t y -% t & z -% t.

(i) I f m -- 0, we choose t = z; i fn = 0, we choose t = y . (ii) Otherwise, let x ~ y] -%y & x ~ zl -% z.

By local confluence, 3u y] -% u & z] -% u. By the induction hypothesis P(YO, 3v y -% v & u --~ v. By the induction hypothesis P(z]), 3t v -% t & z -% t, proving P(x).

The induction step of the proof is shown in the diagram of Figure 5. []

Lemma 2.4 fails if we just suppose --~ to be inductive and acyclic, as shown by the counterexample in Figure 6a, due to Newman, or inductive and fmite, as shown by Figure 6b, due to Hindley. Note that the two diagrams are two projections of a 3-D object.

For the relations that are not noetherian, much stronger local hypotheses are necessary to yield confluence.

Page 5: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

801

Figure 5

× , / \ ¥, Ind u z ~ ~ v ,nd/.

(a)

Confluent Reductions

(b)

Figurc 6

Definition. We say that the relation ~ is strongly confluent iff

Vxyz x --~ y & x ~ z ~ 3u y--~ u & z-.~ u.

The corresponding diagram is shown in Figure 7.

Remark. Beware of the symmetry between y and z in the definition above. It is only slightly weaker than requiring y ~ u & z ~ u. For instance, the relation ---> in Figure 6 is not strongly confluent.

LEMMA 2.5. Any strongly confluent relation is confluent.

PROOF. It is easy to show by induction on n that if ~ is strongly confluent, then Vxyz x -'-> y & x --~ z --~ 3u y--~ u & z -~ u. The result then follows from L e m m a 2.3. []

It may seem that the condition of strong confluence is too restrictive to be of practical use. However, Lemma 2.5 can be used as follows. If we are able to define, from the reduction relation ---~, a strongly confluent relation ---~s with the same transitive closure as --~:--~ = -->s, the confluence of ~ follows from Lemma 2.5. This is the basis of the TaR and Martin-L6f method for proving the Church-Rosser theorem in h-calculus [10]. Actually, a weaker condition than ~ = --~s is sufficient: it is enough to show that -->s is a compatible refinement of---* in the sense of Staples [36].

Page 6: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

802 GERARD HUET

\ /

t .\ /" I ! \ /

--,i Figure 7 Figure 8

Various other axiomatic conditions imply confluence, for instance, using decompositions of--~ as the union of two or more relations. See in particular [23, 33, 36]. For instance, Lemma 2.5 is a consequence of the commutativity lemma in Rosen [33].

2.3 REDUCTION MODULO EQUIVALENCE. Our motivation in studying reduction rela- tions stems from practical problems arising in formula manipulation systems such as theorem provers, program optimizers, and algebraic simplifiers. The problem is to define some efficient operational semantics for an equational theory. This theory is usually defined by axioms of two forms: "structural" axioms such as associativlty and commuta- tivity of operators, and "simplification rules" such as "if true then x else y ~ x." Whde the latter usually define a noetherian relation on the terms of the language, the former can often be taken into account by a specific data structure used to represent these terms.

We now model this situation by considering a reduction relation ---~, together with an equivalence relauon ~, in the same manner as [ l, 34].

Definition. We say that the relation ~ is confluent modulo ~ iff

V x y x ' y" x ~ y & x -% x " & y - ~ y " ~ 3$f i x" --% £ & y ' -% f i & ~ ~ y.

The corresponding diagram is given in Figure 8.

Note that this condition is different from ---~/~ being confluent in 8 / ~ , since we do not allow ~ along the --)-derivations. If ~ has the property o f defining at least one normal form for every element, we get a weak form of Lemma 2.2.

LEMMA 2.6. Let ~ normalize 8; i.e., Vx ~ 8 3 y E X x --% y. Then ~ is confluent

modulo ~ i f f

V x y E g V u v E . A r x =- y & x--% u & y--% v ~ u ~ v,

where ~- is (~--~ O ~)*.

PROOF. The proof is trivial and is left to the reader. [ ]

We are now going to search for sufficient conditions for ~ to be confluent modulo ~. The first step is to generalize Lemma 2.4, assuming ~ noetherian. Lemma 2.7 below generalizes Theorem 2.2 of Sethi [34], who requires ~ to be bounded. This generalization will be useful in practice, since one frequently proves termination results using lexico- graphic orderings on terms that are noetherian but not bounded [ 16]. But the main interest here lies in the technique of proof, based on noetherian induction.

Definition. We say that relation ~ is locally confluent modulo ~ iff conditions a and B are satisfied:

a: V x y z x ~ y & z ~ y ~-, y~z ,

jS: V x y z x ~ y & x - - - , z ~ y~z ,

where y ~ z ~ 3uv y ~ u & z -~ v & u ~ v.

Page 7: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

Confluent Reductions

x x ~ y

c~: y z /3 z ~'. /

\ / x \ I

\ I . \ / . .x. , \ / \\ I

. I

803

F*gure 9

The corresponding diagrams are shown in Figure 9. Property a (respectively, fl) is called P3 (respectively, PI) in [341.

We can now state the generalization of Lemma 2.4.

LEMMA 2.7. Let --* be a noetherian relation. For any equivalence ~, ~ is confluent modulo ~ t f f ---~ is locally confluent modulo ~.

Before giving the proof of this lemma, let us state a preliminary technical proposition.

Definition ! I ( x , y ) -E~ ( x , y ) *-~ x - * x ' & y = y ' ,

(x, y } -~ (x ' , y ' ) ~ x ~ x ' & x---, y ' ,

(x, y ) ~ (x ' , y ' } "~, x = x ' & y - + y ' ,

( x, y ) "Z~ ( x ' , y ' ) *-~ y---) x ' & y - + y ' ,

-~ = ~ o ~ , -~ = -~ u -~, . - , = T O T .

PROPOSITION 2. !. If---) is noetherian, then ~ is a noetherian relation in e 2.

PROOF. Let

First we show that ~ is noetherian. Assume the existence of an infinite -w~-sequence. Since -z~is noetherian, it must be of the form -~ --~ ~ --~ . . . , which implies the existence of an

1 . I o l

infinite A-sequence of its first projections, contrary to the hypothesis that ~ is noetherian. Similarly, ~ is noetberian. Therefore, any infinite -* sequence must be o f the form:

~<x,, y,> .~ <x2, yz> ~ <x3, y~> -~ <x,,ya -~ <x,, ya -~ <x~,ya . . . ,

which imphes the existence of an infinite ---*-sequence,

x~ ---, y2---, ya--* x4 --% xs---~ y6---* . . . ,

a contradiction. []

PROOF or LEMMA 2.7. Let ~ be a noetherian relation locally confluent modulo ~. We shall use noetherian induction in 82, applied to ---* and to the property

P(x, y): x ~ y ~ [Vx' , y ' x - ~ , x ' & y - + y ' ~ x '~y ' ] .

Let us show that P is - , - comple te . For that, let x, y, x ' , y ' ~ c s u c h that x ~ y, x ---~x', y--~ y ' . We show 3£, fi: x ' --% £, y"--% fi, x ~ y.

I f n = 0 and m = 0, the result is trivial. Otherwise, let us assume wRhout loss of generality that n > 0, and let x -* x~-Z, x ' . By applying property fl to x , y , x~, we get u and v such that x~---> u,y--% v, u ~ v. There are two cases.

Page 8: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

804

X ~ y = y '

x ~ v

g ' ~ g ~ !

X ~ y = v

' / \ . x w ~ z y'

Gi~RARD HUET

(a) (b)

.x1~~ x ~ Y"

x u ~ v w ~ z y'

(c)

Figure 10

Case 1. m = 0. Let ~' , ~, and f be A-no rma l forms of x ' , u, and v, respectively. We get g ' ~ ~ by the induction hypothesis P(xl, xl) and t~ ~ F by the induction hypothesis P(u, v), completing the proof of case I. The diagram is shown in Figure 10a.

Case 2. m > 0. Let y ~ yl --~ y ' . Again there are two cases.

2a. v = y. We again apply property fl to y, u, yl, getting w and z such that u --~ w, y~ --~ z, w - z. Let £ ' , ~, ~, andf i ' be ---y-normal forms o f x ' , w, z and y ' , respectively. We get £ ' ~ • by the hypothesis P(xl, xl), ~ ~ ~ by P(w, z), and ~ ~ fi' by P(y~, y~), completing the proof o f this case. The diagram is shown in Figure 10b.

2b. Otherwise, let y ~ t--~ v. We now apply property a to y, y~, t, getting w and z such that t--~ w, y~ --~ z, w ~ z. Let £ ' , ~, F, ~, ~, and fi' be normal forms, respectively, of x ' , u, v, w, z, and y ' . We get ~ ' ~ tTby the induction hypothesis P(xl, x0, t7 ~ Fby P(u, v), F ~ ~ by P(t, t), ~ ~ f b y P(w, z), and finally, f ~ f i ' by P(Y~,YO, completing the proof of the lemma. The diagram is shown in Figure 10c.

We leave it to the reader to check that we used the hypothesis P(?~, #) only when (x, y ) ~ (~, #). Actually, the definition of ~ was inspired directly by the diagrams we wished to prove, which makes this method a very natural one to use for this sort of proof. The diagrams are the same as in Sethi's proof [34]. []

Next, we further localize property fl, when considering ~ as generated by a symmetric relation I'-'t; i.e., ~ -- t--q.

Definition. Property 7:

Vxyz x ~ y & x --, z =~ y ~ z with ~ = I---~.

The corresponding diagram is shown in Figure 11.

Page 9: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

Confluent Reductions 805

x l I V

I 7 . f

I I i

\ \ I

I

' ~ I

Figure I I

Definition. I f x ~ y, we define p(x, y) as the smallest k such that x ~ y. In a similar way as above, we define a relation ~ in g 2 by

(x, y ) ~ (x ' , y ' )

iff

(i) either (x, y ) ---* (x ' , y ' ) with same defini t ion as above, (ii) or x ~ y ~ x ' - y ' and p(x, y ) > p(x', y').

PROPOSITION 2.2. If---*.-- is noetherian (or, equivalently, if---y~~ is noetherian m 8 /~) , then ~-* is a noetherian relation in 0 .2.

The proof follows that o f Proposit ion 2.1, but in the quotient, set g / ~ . Note that we need a stronger condi t ion than for Proposit ion 2.1.

LEMMA 2.8. Let H be a symmetric relation, and let ~ = ~2_~. Let--* be any relation such that ---~.~ is noetherian. Then ---> is confluent modulo ~ iff properties a and y are satisfied.

Paoov. The "only i f" part is obvious. For the " i f" part, let us assume that ---~.~ is noe thenan and that properties a and T hold. We again use noether ian induc t ion in g2, applied to ~--*, and the same property P as in the proof of Lemma 2.7.

Le tx , y , x ' , y ' E g b e s u c h t h a t x ~ y , x - ~ ' " y ' . x , y ~ We show the existence of £ and )7 such that x ' --% .~, y ' -% y'~ and x ~ y.

There are two cases.

Case 1. x = y .

la. I f n = 0 or m -~ 0, it is trivial. I b. Otherwise, let x ~ u ~ x ' and y ~ v ~ y ' . Applying property a to x, u, and v, we

get the existence of w and z such that u --% w, v --% z, and w ~ z. Let .~', ~, ~, and f i ' be - - , -normal forms of x ', w, z, and y ' , respectively. We get £ ' ~ ~ by the induc t ion hypothesis P(u, u), • ~ F b y hypothesis P(w, z), and ~ - )7' by hypothesis P(v, v), complet ing the proof of case l according to the diagram in Figure 12a.

Case 2. p(x, y) > O.

2a. If n = 0 and m = 0, it is trivial. 2b. Otherwise, let us assume without loss of generality that n > 0, and let x

u -~, x ' . Let us choose v such that x H v ~ y, with p(v, y ) = p(x, y) - 1. Apply ing property to x, v, and u, we get w and z such that u --% w, v ~ z, and w - z. We complete the proof

as in case 1, applying induct ion hypotheses P(u, u), P(w, z), and P(v, y). Note that we always have ( x , y ) ~ (w, z) . This concludes the proof, according to the d iagram in Figure 12b. []

Remarks. Sethl's Theorem 2.3 [34] is similar to Lemma 2.8 in the special case H = ~1 U -2 , where ~~ and ~2 are two equivalence relations. But his condi t ions are significantly

Page 10: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

806 GI~RARD HUET x = y

x

w z ~ y

x I I v ~ Y

x w ~ z y' "'n'.t'n't''n" t" - ' ~ ~ ~ g '

(a) (b) Figure 12

| I ~ 1 ~ I

(a) (b) Figure 13

more restrictive: he demands that ~ U ~ be bounded, because he explicttly constructs an ordinal for the induction.

Nivat shows in [24] an equivalent of Lemma 2.8 for a reduction relaUon defined by word rewritings in a free monoid.

Note the symmetry between properties a and 7. Both express locahzmg the confluence check to one application of the generators of ~ and ~, respectively.

The rather strong condition that ---~.~ be noetherian is essential. For instance, Figure 13 gives examples (inspired by the ones in Figure 6) where ~ is noetherian and a and -y are true. Still, ~ is not confluent modulo ~.

3. Applications to Term Rewriting Systems

3.1 THE SUBSUMPTION LATTICE OF FIRST-ORDER TERMS. We briefly survey properties of the set 3 - o f terms of a first-order language, ordered by substitution. Full proofs may be found in 112], and related results in 130, 31].

Let ~/'be a denumerable set of elements called variables, denoted x, y, z . . . . . Let .~ be a finite or denumerable set, with ~ r3 y- = ~ , graded by an arity function a: ~ ~ N. Elements in ~ are called function symbols, denoted F, G, H, . . . . We define ~ = {F E ~ l a (F) = n}.

The set .g-of terms is defined as the free a-graded .g-algebra generated by q<" That is, a term is either a variable or is o f the form FM1M2 . . . M , for some F E ~ and M], M2, . . . , M , E .~. We denote terms by letters M, N, P, Q. We define a few functions on terms:

Y'(M) C y-( the set of variables of M):

y-(x) = {x) Vx ~ rl Y-(FMt . . . M,) = ,U a Y-(M,) V F E ~ .

v(M) = I Y-(M) I E N. I f ~ M ) = 0 we say term M is a closed (or ground) term.

Page 11: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

Confluent Reductions

A(M) _> 1 (the length of M):

A(x)---- 1 n

A(FMi . . . M , ) = I + ~ )~(g,) 1--1

O(M) _> 0 (the size of M):

o ( x ) = o n

O(FM~ . . . M , ) = I + X O(M,) I - -1

Vx EYff,

VFE .~ .

Vx E ~

VFE 4 .

807

# ( M ) = h ( M ) - v ( M ) . It IS easy to show that # ( M ) _> O(M), which shows that # (M) _> 0 & #(M) = 0 ~=* M E YC

If/ . t(M) = O(M), we say that M is linear; this means that all var iable occurrences in M are distinct.

We now formalize the not ion o f occurrence o f a subterm in a term. Let N.?- be the set o f sequences o f positive integers, A the empty sequence in N+*, and • the concatenat ion operat ion on sequences. We shall call the members o f N+* occurrences and denote them u, v, w. We define thepref ix ordering _< in N+* by u _< v ~=0 3w v = u .w; in this case we define v/u = w. Occurrences u and v are said to be disjoint, denoted u I v, i f f "~u _< v and ~ v _< u. Finally, we let u < v lff u ~_ v and u # v.

For any M E J , we define its set o f occurrences ¢9(M) C N+* and the subterm o f M at u, M / u E J , for u E ¢9(M), as follows.

(i) I f M = x E ~ then (9(M) = {A) and M / A = M. (n) I f M = FM1 . . . M , , then 60(M) = {A} O {ml t <_ n, u E (9(M,)), M / A =~ M, and

M / i u -- M, /u .

We say that u is an occurrence o f M / u in M. (Note that our terminology extends the tradit ional one.)

Finally, for M E J , u E (9(M), and N E J , we define M [ u ~- N] ~ J ' b y

M [ A ~ N] = N, (FM1 . . . M,)[iu ~- N] = FMi . . . M,- i (M,[u ~-- N])M,+i . . . M , , i_< n.

These definit ions are consistent with [33], and in the rest o f the paper we shall make free use o f the fol lowing proposition, which corresponds to Lemmas 4.6 and 4.7 in [33].

PROPOSITION 3.1

(1) v m , N, P E J , u ~ (9(m), v ~ O(N):

(a) M [ u ~-- N ] / u . v = N /v , embedding; (b) M [ u ~ N][u. v ~- P] = M [ u ~- N[v ~ P]], associatiwty.

(2) VM, N, P E J , u, v E (9(M), with u I v:

(a) M [ u ~-- N ] / v = M / v , persistence; (b) M [ u <--- N][v ~-- e] = M [ v <-- e][u <--- N], commutativay.

(3) VM, N, P E J , u , v ~ d~(M), with v ~_ u:

(a) M [ u <--- N ] / v = ( M / v ) [ u / v <-- N], distributivity; (b) M [ u ~-- N][v ~-- P] = M [ v <-- P], dominance.

Definitions. A substttution is a mapping a f rom ~" to g , with a(x) ffi x almost everywhere. Substitutions are denoted by o, p, ~/. Substitutions are extended as morphisms of 9 - by

o(FMi . . . M , ) = Fo(M~) . . . o(M,) .

Bijective morphisms are called permutations and are denoted by ~, $', . . . . G iven a substitution o, the finite set ~(o) = {x E ~ [ o ( x ) # x) C "1/" is called the domain ofo .

Page 12: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

808

For V C ~ , we defme the restriction or r V of a to V as

(oF V)(x) = (a (x ) f f x E V, otherwise.

For all o, M, and V,

GI~RARD HUET

~:(M) ~ V ~ o(t) = (o t V)(M),

and ~(o) n :(M) = ~ ~ o(M) = M.

We define the quasi-ordering _< of subsumption in 5- by

M ~ N ~ 3o N = o(M).

It can be shown that if such a o exists, o F ~:(M) is unique. We call it the match of N by M, and denote it by N :: M.

We define M -= N ~-~ M ~_ N & N _< M. It can be shown that M -= N iff there exists a permutation ~ such that N = ~(M). Note that v, A, and 0 are preserved by -=. Finally, we define

M> N~.N_< M& M~gN.

PROPOSITION 3.2. > is a noetherian relation in ~.

The proof o f this proposition is given in [12] and consists in showing that M > N #(M) > #(N).

Let ,~ be any bijection between 5-x 5-and ~. We define a binary operation A in 5- inductively by

(i) FMi ... Mn A FNi ... Nn ffi F(M~ A N~) ... (Mn ANn) VF E o~. (ii) M A N = ~M, N) in all other cases.

M A N is uniquely determined from 4, and, for distinct ,~'s, is unique up to -=.

PROPOSITION 3.3. M A N is a g.l.b, of M and N under the subsumption quasi-ordering.

Let ~" be the quotient set 5-/-=, completed with a maximum element T. From Proposi- tions 3.2 and 3.3 there follows directly:

THEOREM 3.1. ~ris a complete lattice.

The proof of Proposition 3.3, of Theorem 3. I and various other results concerning the structure of 5-, and of its completion by infinite terms, may be found in [12]. See also [29] and [3 I] for similar constructions.

A direct consequence of Theorem 3. I is the existence, for any two terms M and N that have a common instance (i.e., such that 30, o' o(M) -~ o'(N)) of an l.u.b. M V N, which is a most general such instance. The term M V N is unique modulo -= and may be found by the unification algorithm [32]. Efficient ways of unifying terms are described in [12, 25]. If such an Lu.b. exists, we write M V N and say that M and N are unifiable.

We shall need in the next sections the following propositions, whose proofs are omitted here.

PROPOSITION 3.4. do(o(M)) ---- do(M) U OM/u-x {U.V[ V E do(O(X))}.

i f M / u = N 6~ ~, then o(M) /u -- o(N), V u E do(M), i f M / u x ~ ~, then o (M) /u . v = o(x)/v V v E do(o(x)).

PROPOSITION 3.5. VM, N E J , VU E do(M), o(M)[u ~ o(N)] = o(M[u ~ N]).

3.2 TERM REWRITING SYSTEMS AND CRITICAL PAIRS

Definition. We call a term rewriting system any set ~ o f pairs of terms (~ --~ ~8), such that ~(fl) C ~0x) .

We say that u is a redex occurrence o f ~ in term M iff u ~ d0(M) and 3 ( a ~ ~8) E g¢

Page 13: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

Confluent Reductions 809

such that c~ _< M/u. Taking o = (M/u): :a and N = M[u ~-- o(fl)], we say that M reduces to N m u, and we write M-_~ N.

Example. Let ~ = { ( I x ~ x ) } , with a(I) = 1. We have I I x ~ I x in two possible ways, with redex occurrence A or 1.

Definition. Let ~ be a relation over .~. We say that ~ is

(i) stable iff Vo, VM, N, M ~ N ~ a(M) --~ a(N); (ii) compatible i f f VP E J , Vu E ~)(P), VM, N, M ~ N ~ P[u ~- M] ~ P[u ~- N].

It is easy to show, using Propositions 3.1 and 3.4, that---~ is the smallest compatible stable relation contaimng ~ .

Term rewriting systems are a general model of computation. They generalize to arbitrary algebras the semi-Thue systems in free monoids.

PROPOSITION 3.6. Let ~ be any compatible relation in J , and let a and a' be substitutions such that

o(x ) ---, a'(x), o(y) = a ' (y) Vy # x.

Let M be any term, and let ul . . . . . un E ~ (M) be all the occurrences o f x m M (assumed to be dtstinct). Defining Mo = o(M) and M, = M,-l[u, ~ o'(x)] (1 _< i <_ n), we have

M, , - 1 o ' (M) (O_< i_< n).

PROOF. Using Proposition 3.4 we show that M,/u, = o(x), and therefore Vi 0 _< i _< n M, ~ M,+x. We then show that M, -- o'(M) by an induction on M, using the compatibil i ty of--~. []

We now describe a superposition algorithm, used to define critical pairs o f terms in a term rewriting system. This algorithm is taken from Knuth and Bendix [16].

Superposition Algorithm. Let (a l ~ f l0 , (a2 ~ f12) E ~ and u E ¢9(al) such that M = al/u ~ "//'and M V a2. Let N ~ M V a2 such that "/P(N) N 'f/'(al) = ~ . We say that the superposition o f (a2 ~ f12) on (a~ ~ ~ ) in u determines the criticalpair (P, Q) , defined by

e = o l (a l ) [u ~ o~(13~)], Q = o I ( # 0 ,

where a l = N: : M and ~r2 = N: : a2. In words, this means that we match in the most general way the left-hand side of some rule with a nonvariable subterm of another (or the same) left-hand side. The critical pair cons~ists of the two ways in which the common instance reduces by the two rules.

Remark. For any (a~ ~ i l l ) , (a2 --~ f12), and u, the critical pair is unique up to a permutation. We may choose (az -* 13z) -- (al ~ 131L as in Example (c) below, but in this case (and in this case only) we shall not consider the case u ffi A, which gives only trivial critical pairs (P, P ).

Examples. For convenience we use parentheses in the terms of our examples.

( a ) a l = F(x, G(x, A )), 131 = H ( x ) , a2 = G(B, x), 132 = K(x) w i t h u ffi 2 determine the pair P = F(B, K(A)) , Q = H(B).

(b) a l = F(x, H(x ')) , [31 = K(x ' , .c), a2 = H(G(x , x ' )) , 132 = L(x , x ' ) with u = 2 determine P = F(x, L ( y , z)), Q = K(G(y , z), x).

(c) al = c~2 -- H(H(x) ) , 131 = 132 = K(x ) with u -- 1 determine P = H ( K ( y ) ) , Q = K(H(y ) ) .

Remark. The condition ~ ( N ) N ~e~(al) = O may be replaced by the weaker condition ~ ( N ) f3 ( ~ ( a 0 - ~ ( M ) ) = @. Example (b) shows why this condition is necessary: choosr

Page 14: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

810 OI~RARD HUET

ing the pair (F(x, L(x, x')), K(G(x, x') , x)) would be strictly less general than the pair (P, Q) . I f we compute N by unification of M and ~(a~), where ~ is a permutation renaming variables in ~(a~) ~ ~(ot2), we get ~ ( N ) C ( ~ ( M ) t3 ~(~(a2))), and the condition above is thus satisfied.

PROPOSITION 3.7. Let (a~ ~ fl~), (o~ ~ f12) ~ Yt and u ~ do(al) such that M = a~/u or'and there exist ol and oz such that o~(M) ffi oz(o~z). Then there exist a critical pair (P, Q )

o f ~ and a substitution p such that o;(ot0[u <-- o2(flz)] -- p(P) and o~(fl~) ffi p(Q).

PROOF. We know that M V ct2. Let N m M V ae such that ~/r(N) ~ ~/'(C~l) = @, and let o ~- N::M, o' ffi N::a2, as determined by the superposition algorithm, which constructs a critical pair (P, Q) with e = o(oq)[u <-- o'(flz)] and Q ffi o(fl~).

We consider substitutions ~/ffi o2(~) :: N -- o~(M) :: N and p ffi [~/[ "ff(N)] t3 [o~ ~ 3v'(a0]. (This is meaningful, since "¢(N) ~ "f/'(a~) = @.) By construction we have o~(M) -- ~i(o(M)), and therefore

(i) ~¢x e "¢'(M) o,(x) ffi al(o(x)) = p(o(x)) because 3v'(o(x)) _C "~(N). (ii) Yx ~ #/'(aO - "f'(M) o(x) = x because @(o) C ~¢(M), and p(x) = o~(x) by definition

ofp .

Therefore

Vx E ~(al) ol(x) = pto(x)). (1)

Similarly, o2(a2) = ~(o'(a2)) gives

Vx ~ ~r(,~2) o2(x) = ~(o ' (x ) ) = p (o ' (x ) ) . (2)

Since ~(fll) C ~/'(al) and ~(f12) C ~(a2), we get

a~68~) = p ( o ~ ) ) by (1) -- p(Q),

and

Ol(Oll)[U ~ O2( j~2 ) ] = p(a(aO)[u <--- p(o'(fl2)) by (1) and (2) -- p(P) by Proposition 3.5. []

We arc interested in critical pairs because of the next lcmma, which shows that the test for local confluence may be restricted to critical pairs.

From now on we shall generally abbreviate ~ by -*. As in Section 2, we use the notation M A N for 3 P M--~ P & N--% P.

LEMMA 3.1. The relation-7, is locally confluent if f for every critical pair ( P, Q) o f ~ we have e J, Q.

PROOF. Using the notation of the supcrposition algorithm, a critical pair (P, Q) is such that ol(al) ~ P and Ol(a0 ~ Q, which shows the "only if" part.

For the " i f" part, assume that for every critical pair (P, Q) o f ~ we have P~, Q. Let M be an arbitrary term, with M ~ N~ and M ~ N2; i.e., 3u~, u2 E ~ M ) , 3(a~ ~ riO, (a2 -* f12) ~ ~ , and 3al, 02 such that M/ul = o1(al), M/U2 = 02(¢3¢2), N1 = M[ul o~(fl~)], and N2 = M[u2 ~- 02(fl2)].

There are two cases, according to the relative positions of the two redex occurrences.

Case 1. Disjoint redexes: u~]u2. We then have N~/u2 = 02(a2) by persistence, and similarly, N2/ul ffi o~(a~). Furthermore, we have M = Nl[u2 ~ 02~z)] = N2[uz ~- 0168~)] by commutativity, and therefore N, ~ M and N2 --, ~ .

Case 2. Prefix redexes. Let us assume, without loss of generality, that u~ _< u2. Let v = u2/m. By cancellation we get Ol(a0/v ffi 02(a2), and by distributivity we get N2/u~ =

Let us show that there exists ~t such that o~(fll) ~ 3~t and N2/u~ *~ M. It will then follow that Ni ~ Nz, by compatibility o f - * .

Page 15: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

Confluent Reductions 811

According to Proposition 3.4, there are two cases.

2a. v = vl . v2, al /vl = x E ~, a2(~x2) = a~(x)/v2. Let us consider the substitution ol defined by

oi(x) = o,(x)[v2 ,--a~(B~)], oi(y) = o~(y) V y ¢ x,

and let 33 = oi(fll). We have o~(x) --,, oi(x), and by Proposition 3.6 we get o~(fll) ~ 33 and Ol(al)[V ¢e--- O2(B2)] ~ Oi(O/l). Since ~ is stable, we get dl(al) --o 33, which concludes the proof of case 2a.

2b. a~/v q~ ~ a2(a2) = o(a~/v). Using Proposition 3.7, there exist ~/critical pair (P, Q) and a substitution p such that

o~(a,)[v ~-- o2(flz)] = piP) and o,(fl~) = p(Q).

By hypothesis, there exists R such that P ~ R and Q ~ R. We may choose 33 = p(R), and the result follows by the stability o f -o . []

Remark. Lemma 3.1 is inspired by Knuth and Bendix [16], but our proof, unlike theirs, does not reqmre ~ to be noetherian.

Example. Let ~¢ be {(F(x) ~ A) , (F(x) ~ G(F(x))), (G(F(x)) ~ F(H(x))) , (G(F(x)) ~ B)}. We leave it to the reader to check that for every critical pair (P, Q) of aM we have P J, Q. Therefore ~ is locally confluent. However, ---, is not confluent, since it is not noetherian. Actually, note that the diagram of reductions from F(x) using aM is identical to Figure 6a. In the case of noethenan relations we get the following theorem, essentially identical to the corollary to Theorem 5 of [16].

THEOREM 3.2. Let aM be a term rewriting system such that 7 is noetherian. Let 33 denote an arbitrary 7 -norma lJorm o f M, f o r M ~ ~ . Then 7 is confluent i f f f o r every critical pair (P, Q) o f aM we have P = Q.

PROOF

7 . For any critical pair (P, Q) o f ~ , 3 M M---, P & M---, Q, If--~ is confluent, then by Lemma 2.2 the term M admits a unique --,-normal form ff ffi Q.

~ . /~ = Q implies P ~ Q, and ~ is locally confluent by Lemma 3.1 and therefore confluent by Lemma 3.4. []

Remark. If ~ is noetherian, we may get )i4 from M by an arbitrary sequence of rewritings using rules in aM, termination being guaranteed. Theorem 3.2 gives us in this case an effective way of testing the confluence o f - . , provided we have only a flmte number of criucal pairs (P, Q). This will happen in particular when aM is finite.

Examples

(a) Let aM = {(H(H(x)) --~ K(x))} . As we saw in Example (c) above, we have a critical pair P = H(K(y)) , Q = K(H(y)). Since P and Q are distinct --,-normal forms, aM is not a confluent system. ^ (b) I f we form aM' by adding to aM above the rule (H(K(x)) ~ K(H(x))) , we now have

P = Q = K(H(y) ) . A new critical pair appears by superposition of the two rules P' = H(K(H(y))) and Q' = K(K(y ) ) . But e ' ~ K ( H ( H ( y ) ) ) --, K ( K ( y ) ) -- Q'. aM' being noetherian (we shall discuss this problem below), we have shown that it is confluent.

(c) Group theory. Let

ffi ( (F(E , x) --, x ) , (F ( I ( x ) , x) ~ e ) , ( I ( E ) ~ E ) , (F(F(x , y), z) ~ F(x, F(y, z))) , ( F( I (x ) , F(x , y)) ~ y) , (F(x, E) ~ x) , ( I ( I ( x ) ) ~ x ) , (F(x , l ( x ) ) ~ E) , (F(x , F( I (x ) , y)) ~ y ) , ( l ( F ( x , y)) ---> F ( l ( y ) , I (x))) }.

Page 16: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

812 Gi~RARD HUET

We leave it to the reader to show that for all critical pairs (e, Q) we have/ ; = {~. We show below that ~ is noetherian. ~ is therefore a confluent system. This example is taken from [16].

Proving #t Noetherian. The main difficulty in using Theorem 3.2 consists in showing ---, to be noetherian. For that one must find a noetherian, stable, compatible strict partial order I> such a I> fl for every (a --~ fl) in #L Knuth and Bendix [16] propose a tricky lexicographic ordering for this purpose. Providing the user specifies integer weights to the function symbols, this test can be completely mechanized. Further studies of these orderings are given in [2, 7, 27, 28].

More generally, this problem is equivalent to finding some interpretation X of our term language over some well-founded domain (~, <~), such that for every F in .~,, x(F) is monotone increasing in each of its arguments. To prove --* noetherian, we have to show that for every (a --* fl) in ~ , X(B) "<~ X(a) is identically true for every assignment ofx(x,) in ~. This method was proposed by Manna and Ness in [22] and used by Lankford in [17] (where ×(F) were polynomials over N). For instance, the ten group reductions of Example (c) above may be shown to be noetherian using the interpretation

x(F) = ~ y . x(! + 2y), X(1) = Ax. x 2, ×(E) = 2,

over integers greater than 1. Another method is given in [2 I]. The general problem of showing that ~ is noetherian

is shown in [13] to be undecidable of order 0", even for terms restricted to monadic function symbols, but to be decidable for ground systems (i.e., such that #(~x) -~ ~(B) = O for every (~ ~ ~8) in ~).

Completing ~ to a Confluent System. Theorem 3.2 also gives hints on how to complete to a confluent system when it is not: the idea is to include in ~, for every (P, Q) such

that P # Q, either (P--~ Q), (Q---~ P), or (P---. M) and (Q---~ M) for some term M. Of course, one must show that the new pairs preserve termination, and there is no guarantee that the "completing" process will terminate. We shall not explain further the details of the method, which is explained in [16] and illustrated by numerous examples. Note that if we consider ~ as an equational theory, the critical pairs are consequences of the original axioms. Moreover, they usually turn out to be very useful lemmas. For instance, note that in Example (a) above we know in one step that H and K must commute, from the assumption that K is the square of H. This makes this completing procedure a very efficient semidecision procedure for equational theories in the cases where it applies. If the procedure terminates, it may be viewed as the compilation of a decision procedure from the axioms of an equational theory. For instance, Knuth and Bendix mechanically generate the set ~ of Example (c) above from the three group axioms F(E, x) = x, F(l(x), x) -- E, and F(F(x, y), z) = F(x, l~(y, z)). Now M = N is a consequence of these axioms if and only if M is identical to N, where M is obtained from M by an arbitrary sequence of rewritings using rules o f ~ , until none applies.

This method may be considered as the theoretical justificauon of earlier methods for mechanizing equality theorem proving [8, Il]. It is further explored in [2, 17], and related methods are considered in [35]. We give an extension of this method in Section 3.4.

3.3 LINEAR TERM REWRITING SYSTEMS. We are now going to give sufficient conditions for confluence that do not depend on termination conditions. The idea is to impose on critical pairs (P, Q) o f ~ a condition stronger than P,~ Q, inspired by the strong confluency condition.

Definition. A term rewriting system ~ is strongly closed iff, for every critical pair (P, Q) of #~, there exist R and S such that P --~ R ~-~ Q and P ~ S ~ Q. Note that this condition alone is not sufficient to ensure confluence, as shown by the counterexample

Page 17: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

Confluent Reductions 813

= {(F(x, x) ---~ A ) , <F(x, G(x)) ~ B) , (C---~ G(C) ) ) , since the term F(C, C) possesses two distinct normal forms A and B. Note that ~ has no critical pair, since F(x, x )~ F(x , G(x)). Note that the diagram of reductions of F(C, C) is identical to Figure 6a. Another interesting counterexample is due to Barendregt, simplifying a result of Klop [15], namely,

= ( (F(x , x ) -.-, A ) , (G(x) ---~ F(x, G(x))) , (C ~ G(C))}, since G(C) ..~ A and G(C) --% G(A), but A ~ G(A), although here the normal form of every term, when it exists, is unique.

Both of these systems contain nonlinear terms, which mouvates the following definition.

Definition. We say that ~ is left linear (respectively, right linear) iff Y(a ~ fl) E a (respectively, fl) is linear.

L[MMA 3.2. I f Yt is a left- and right-linear strongly closed term rewriting system, -~ is strongly confluent.

PROOV. Let us assume that ~ is left and right linear and strongly closed, and let us abbreviate 7 by ---~.

Let M ~ N1 and M ~ N2; i.e., 3ul, u2 ~ 0(M), (al ~ ill), (as ~ fls) E ~ , and substitutions Ol and o2 such that M/u1 = o~(aO, N~ = g [ u l ~ o~(fl0], M / u s = 02(as), and N2 = M[u2 ~ 02(fls)]. We show that there exist Na and N4 such that N1 --~ Na ~ Ns and N1-% N4 <--* Ns.

There are two cases, according to the relative positions of redex occurrences ul and u2; the proof is similar to that of Lemma 3.1.

Case 1. Disjoint redexes: ul [ u2. We take

Nz = N4 = Nl[u2 ~ o~(f12)] = N2[u, ~-- ol(fla)].

Case 2. Prefix redexes. Let us assume, without loss o f generality, that u~ _< us. Let V = U2/Ul. W e have o2(aD = ol(al ) /v and N2 = M[ua ~ ol(aO[v ~ os(fls)]].

2a. os(a2) is completely introduced by Ol; i.e., 3vl , v2 v = vi.vs, al /Vl = x E ~, Ol(X)/v2 = o2(aD. We define a substitution o3 by

o3(x) = o~(x)[v~ , - o~(Bs)], o~(y) ffi ° l (y) Vy ~ x,

and we take N3 = N4 = M[u~ ~ o3(fll)]. Since ~ is left linear, x occurs in a~ only in occurrence v~, and we get

o~(~) ffi o~(,~)[v~ ~ o3(x)] = o l (~) [v~ ~ o,(x)[vs ~ os(#s)]]

= o ~ ( a , ) [ v ,.-- o~($~)] ,

whence N2 = M[Ul ~-- o3(aJ], which shows Ns --~ Nz. There are again two cases.

(i) x ~ ~f(fl~). Then trivially o3(f10 ffi o~(flO, and therefore N3 = N~. (ii) 3 w ~ ~(B1) B1/w = x. Since ~ is fight linear, w is the unique occurrence of x in

fl~, and we get

O3(#1) ffi Ol(f l l ) [W <--" GI(X)[V2 <-" O2(fl2)]] "~" Gt(]~I)[W ° F2 ~ 02(#2) ] .

Since of f f lO/w, v2 = o~(az), we get N~ ~ Na using redex occurrence u. w. v2.

2b. o2(as) partially exists in Otl; i.e., v ~ d?(al), a l / v q~ ~, ol(al/V) ffi OS(a2). According to Proposition 3.7, there exist a critical pair (P, Q) and a substitution p such

that

p(P) = offa~)[v ~ o2(fl2)] and p(Q) ffi o~(fl~),

and thus

By the P --~ S ~ Q, and therefore we can take N3 = M[Ul ~ p(P)] and N4 = M [ u l <--- p(Q)].

N1 = M[u~ ~ p(Q)] and N2 = M[ul ~ p(P)].

closure hypothesis , there exist R and S such that P ~ R 4 - Q and [ ]

Page 18: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

814 GI~RARD HUET

Using Lemma 2.5, we get

COROLLARY. I f ~ is a left- and right-linear strongly closed system, -~ is confluent.

Example. Let

~t = { (H(F(x, y)) ~ F(H(R(x)), y)) , (F(x, K(y, z)) - , G(e(y), Q(z, x))) , (H(Q(x, y)) ~ Q(x, H(R(y)))) , ( Q(x, H(R(y))) --, H(Q(x, y))), (H(~(x, y ) )~ G(x, H(y))) }.

We have two critical pairs. First between the first two rules,

P = H(G(P(y), Q(z, x))), Q -- F(H(R(x)), K(y, z)).

But, taking R = G(e(y), H(Q(z, x))) and S = G(P(y), Q(z, H(R(x)))), we check that P R ~ - S ~ - Q .

Finally, between the next two rules we get

P' = H(H(Q(x, y))), Q' = Q(x, H(R(H(R(y))))),

and taking T = H(Q(x, H(R(y)))), we check that P ' ~ T ~-- Q'. This shows that ~t is strongly closed and therefore confluent. Note that it is not noetherian, since the rules 3 and 4 form a loop.

I f #~ is only left linear, the condition "strongly closed" is not sufficient to ensure the confluence, as shown by the following counterexample due to J.J. L6vy:

= {(F(A, A) ~ G(B, B)), (A ~ A') , (F(A', x) ~ F(x, x)) , ( F ( x , a ' ) - ~ F(x ,x ) ) , (G(B ,B) - - , F(A ,A) ) , (B--> B') , ( 6(B', x) ~ G(x, x)) , ( G(x, B') ~ G(x, x)) ),

since F(A', A ' ) ~ G(B', B') and F(A', A'),L CG(B', B') is still false. Still, it is very desirable to find sufficient conditions for a term rewriting system to be

confluent that do not depend on right linearity, a rather unnatural condition. One way to do this is to change the closure condition, as we shall see. Let us first give some new definitions.

Defimtion. For any term rewriting system ~ , we define a relation 7 (parallel-disjoint reduction) as follows. Let M E ~ , and let U ffi {ul . . . . . un} be a set of mutually disjoint redex occurrences of Yt in M: Vi _< n M/u, = o,(a,), (a, ~ fl,) E Yt, and i # j==~ u,[uj.

We define N = M[u, ~ o,(fl,)[i _< n] as the term M[ul ~ o1(j81)] . . - [Un ~ o,(B,)]. It is easy to show by commutativity that the order in which we reduce redexes is irrelevant. We say that M reduces m parallel to N, which we write M ~ N. It is easy to show that

is the smallest reflexive relation containing 7 and verifying

(*) M1 ~ Nl & . . . & Mn ~ N . ~=~ Fmi . . . Mn ~ FN1 . . . Nn VF E ~,~.

Also ~ is stable, and - ~ ffi -~.

Let us now give two techmcal propositions.

PROPOSITION 3.8. For any substitution o and term M,

o(M) ---- M[u ~- o (x ) lM/u = x ~ ~] .

PROPOSITION 3.9. Let ~ be any reflexive relation verifying (*). Let U be a set o f disjoint occurrences in term M. Then

Vu E U Pu-~-~ Q,, =z M[u ~-- PuIu E U] - ~ M[u ~-- Qu]u ~ U].

Propositions 3.8 and 3.9 are easily proved by induction on M.

Page 19: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

Confluent Reductions 815

Defimtion. A term rewriting system ~ is parallel closed iff for every critical pair (P, Q) of ~ we have P ~ Q.

L~MMA 3.3 I f ~ is a left-linear parallel closed term rewriting system, - ~ is strongly confluent.

PROOF. We abbreviate -~, as -~-,. Let M ~ N1 with set o f redex occurrences U, and

M ~ N z w i t h s e t V. Let W = (u ~ U[3v E V v _< u} U { r E V[3u E U u _< v} and = [ ( u u v ) - ~ u ( u n v). W and ~" are two sets of mutually disjoint occurrences o f M. We prove 3 N N1

N & N2 ~ N by complete induction onp(M, U, V) = ~wewX(M/w). (We recall that ~(M) is the length of M, as defined in Section 3.1.)

Part I. Let u be any redex occurrence in W. We may assume, without loss of generality, that u E U. Let Vu = {u ~ Vlu ~_ v}. We shall now show the existence of a term Mu such that Nl/u ~ M~, and N2/u ~ Mu.

Let (c~ ~ fl) be the rule o f ~ used in u in the parallel reduction U, with substitution o :

M/u = o(a) and Nl/u = o(fl). There are two cases.

Case 1. No v is crmcal in u; i.e., for all v in V~ we have v/u = w. w' with a /w = x ~." (This covers the case V~ = ~.) This case is illustrated m Figure 14.

Let x be any variable of a. Since the term a is linear by hypothesis, there is a unique w ~ (9(a) such that a/w = x. Let W' be the set of occurrences in o(x) of redex occurrences of V: W' = (v /u .w I u .w <_ v E Vu}. Let (a,, fl,) be the rule o f ~ corresponding to w,' in the reductmn V, with substitution o,: o(x)/w; -- o,(a,).

We define the term Sx = o(x)[w/~-- o,(fl,)l w; E W']. Doing this for every x in a, we now define a substitution o' of domain ~/'(a) by o'(x) = Sx Vx E C(a). By construction we have o(x) ~ Sx, and therefore o(fl) - ~ o'(fl), using Propositions 3.8 and 3.9. Also, using Proposition 3.8, we have N2/u = o'(fl). We may therefore choose M, ffi o'(fl).

Case 2. Let v~ in V,, be crincal in u; i.e., ot/w ~ ~, with w = vl/u. Let (a l --~/31) be the rule of ~ corresponding to vx m the reduction V, with substitutmn o~. Using Proposiuon 3=7, there exist a critical pair (P, Q) o r e and a substitution p such that Nl/u = p(Q) and M = M/u[w ~ ol(fll)] = p(P).

By the closure hypothesis P ~ Q and by the stabdity of-m,-* we get hit ~ N~/u. Let be the set of redex occurrences of M in this reduction. We have also M ~ N2/u, using the set of redex occurrences V ' = {v/ulv E V , - {vQ}.

Now let p ' = ~ , , ~ k(M/u .v ' ) We have p(M, V', I~) <_ p ' by cases on the relative positions of occurrences in V' and I~ r. The four cases are shown in Figure 15, where the contribution to p(M, V', I~) (respectively, p ' ) is the shaded surface in Figure 15a (respectively, 15b).

Because ~(M/v~) > 0, we h a v e p ' < ~o~v, ?~(M/v) _<p(M, U, V), since V, _C W. Therefore p(M, V', t~) < p(M, U, V), and we may use the induction hypothesis, showing the existence of M~.

Part 2. We now consider M = M[u ~ M~ l u ~ W]. Since W dominates all the occurrences in U, we have N~ = M[u ~-- N~/u[u C /~.'], and similarly for Nz. Using Proposition 3.9 we get Nt ~ ~ t and N2 ~ h~t, which concludes the proof []

Using Lemma 2.5 and the fact that ~ = *~, we get

COROLLARY. Any left-hnear parallel closed term rewriting system is confluent.

This result is important in practice. It can be used, for instance, to show the consistency of operational semantics for recurslve programming languages. It is the generalizanon to schemata of the main theorem of Rosen [33], which apphes only to ground terms (no variables), and which requires the stronger closure condition (P ~ Q) ~ ~ . Note that

Page 20: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

816

/

M/u:

Figure 14

GI~RARD HUET

VF~ Wl,W 2

A A Wl V 1 ,V 2

(a) (b) Figure 15

Rosen's Theorem 6.5 gives only a very particular case of Lemma 3.3 (no critical pairs). Computations in left-linear term rewriting systems with no critical pairs are further studied in [14].

Examples

(a) Combinatory logic. The reduction rules of the combinators S and K may be expressed by the following term rewriting system, with A denoting the application oper- ator:

= {(A(A(A(S, x),y), z)) ~ A(A(x,y), A(y, z))), (A(A(K, x), y) --'> x) }.

Because of the first rule, ~ is neither right linear nor noetherian (for instance, the term A(A(M, M), M), with M = A(A(S, S), S) does not admit a normal form). Still, the confluence of ~ is immediate, since it is left linear and there are no critical pairs.

The same argument applies to show the consistency of operational semantics for recursive program schemes.

(b) Let

= {(F(G(x, A, B)) ~ x), ( G(F(H(C, D)), x, p) ~ n(K,(x), K2(y))} , (Ki(A) -.-* C), (Kz(B) ---* O)}.

The system ~ is left linear, and there is only one critical pair (P, Q), with P -~ F(H(Kt(A), K2(B))) and Q = F(H(C, D)). Since P -~* Q, the system ~ is confluent.

3.4 COr~FLU~r~T EQUATIONAL TnEomv.s, We shall now use the results of Section 2.3 to extend the applicability of Lemma 3.1.

We suppose that we are interested in an equational first-order theory defined by a set o f equational axioms ~ c ,.q,2. We assume that the rules o f inference of substitution of terms for free variables and of replacement of equals are valid. We write ._qtl- M = N iff M = N can be deduced from ~ using these rules.

Let us now partition .~/into ~ U ~, where ~ and ~f verify

Page 21: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

Confluent Reductions 817

We shall use ~ as a term rewriting system, defining -~ as above, and ,¢ as a symmetric term rewriting system, defining the symmetric relation ~7] ffi ~ U -~-~. Note that because of the condition on variables in equatmns of 8, we have ..~-1 ffi ~,-J) ; i.e., the only substitutions considered are those obtained by matching. From now on we shall abbreviate --,,, as ~ and ~ . as [--t. Note that ~ t - M = N ~=~ M(*-, U [.--[)*N.

We say that (~, 8) is a confluent equational theory iff--~ is confluent modulo ~, where ~ ffi I * 1. In this case, provided ~ normalizes J , Lemma 2.6 gives us a way of reducing the problem .~¢1- M = N to the problem h4 ~ N, where M and N are -F-normal forms of M and N, respectively.

We now show how Lemma 3.1 can be generalized to equational theories which will give sufficient conditions for an equational theory to be confluent, using Lemma 2.8.

Let us recall property a of Figure 9:

a: VM, N1, N2 M--->Ni&M---~N2~Ni~N2,

where M ~ N *-~ 3M' ,N ' M-~-~ M' & N-~.~ N' & M' ~ N '.

LEMMA 3.4. (~, 8) verifies property a iff for every critical pair (P, Q) of ~¢, we have PJ, Q.

PROOF. The proof follows closely that of Lemma 3.1. We use the same notation and indicate here only the points that differ.

Cases 1 and 2a are kept unchanged. For case 2b let (P, Q) be the critical pair of involved.

By hypothesis, there exist R and S such that P - ~ R, Q~* S, and R ~ S. Let us consider R ffi o(R) and S = o(S). We get oa(fl~) ffi o(Q) "~ _S, since ~ is stable and N2/u~ = o(P) -~ R as well. Therefore o~(fl~) ~ Nz/Ul, and thus N~ ~, Ns since ~ and ~ are compatible, which concludes the proof. []

We want now to get a similar result for property y, which we recall here:

7: VM, N , P M--~N&M~--~Pff i~N~P.

Deflnitwn. Let (~, ~) be an equational theory. We call a eriticalpair ofd~/~ any pair (P, Q) constructed by the superposition algorithm, but now applied to a~,/~, as, f12 such that either

(a~ = i l l ) ~ ~ U ~ -I and (tIt2 "'> ~2) ~ ~

o r

(a~ ~ ,81) E ~ and (a2 ffi f12) ~ 8 U 8 -l.

LEMMA 3.5. Let (~, 8) be an equational theory such that ~ is left linear. Then property ? holds ifffor every criticalpair (P, Q) orS/a, we have P ~ Q.

PROOF. The proof follows the same general pattern as that of Lemma 3.1. Using the notation of the superposition algorithm, a critical pair (P, Q) o f 8 / ~ is such that ol(a~) ~ P and ol(a~) H Q, which shows the "only if" part.

For the "if" part, assume that for every critical pair (P, Q) of 8 /~ , P~ Q. Let M be an arbitrary term, and N1 and N2 be such that M ~ N1 and M H Ne; i.e., 3ul, u2 E (9(M), (al ~ ill) E ~ , (a2 = f12) E 8, and substitutions ol and o2 such that M/Ul m ol(otl), g/u2 ffi oz(a2), Ni = M[m ~ m(fl~)], and N2 = g[u2 ,-- os(flz)] (the symmetric case is obtained in interchanging a2 and f12 below throughout).

There are here three cases, according to the relative positions of the occurrences Ul and uz.

Case 1. ul l u2. With ~t = Nl[u2 ~ 02(flz)] ffi N2[m ~ ol(fl0], we get N1 ~ ~t and Nz ~ ~t, and therefore Ni J, N2.

Page 22: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

818 Gi~.RARD HUET

Case 2. ul _< u2. Let v = u~/ul. We have 01(al)/v = 02(a2) and N2/ul = ol(aO[v ~-- o2(fle)]. There are two cases.

2a. v = h . v2, al/vl = x E ~, 02(a2) = ol(x)/v2. . Let us consider substitution o~ defined by

o;(x) = o,(x)[v2 , - o2(#2)], of(y) = o,(y) Vy # x,

and let M = o~(/3d. We have o1(B1) ~ M by Proposition 3.6. Also, o~(aO[v ~ as(B2)] ffi a~(a0, since v~ is the

only occurrence of x in a~, ~ being left linear by hypothesis. a~(a~) ---~ h4 by the stability of--->, and thus, taking M ffi M[u~ ~ M], we get N~ - IQ and

N2 ~ M by the compatibility of ~ and ~---]. 2b. a~/v q~ ~, o2(a2) = o~(a~/v). By Proposition 3.7 there exist a critical pair (P, Q)

of g / ~ and a substituuon p such that

o1(#1) = p(Q) and ol(al)[v ~-- o2(B2)] = p(P).

By hypothesis, P~ Q, whence p(P)~p(Q) by stability, and N, ~ N2 by compatibility. This concludes case 2.

Case 3. u2 _< u~. Let v = ul/u2. As in case 2, there are two cases.

3a. v = vl. vz, a2/vl = x E ~, ~l(al) ffi o2(x)/v2. We define substitution a[ by

of(x) = ,~,(x)[v2 ~ o~(#,)], of(y) = ,~2(y) Vy ,~ x,

and we consider M = ~(/~2). We have a:(#2) --~ M by Proposit ion 3.6, and also N1/u2 = 02(a2)[v ~ a~(B~)]--~

o~(az) 1--~ ~ , which shows N~ ~, N2. 3b. a2/v f~ ~, o~(a~) = oz(a2/v). Again there exist a critical pair (P, Q) of glut and

a substitution p such that o2(B:) = p(Q) and o2(a2)[v ~ o~(Bl)] ffi p(P). By hypothesis, P~ Q, and therefore N~ ~ N2, which concludes the proof. []

Remark. The condition ~t left linear is essential and cannot be removed. For instance, w i t h e = {(F(x, x) ~ G(x))} and ¢ ~ {(A = B)}, and taking M = F(A, A), N~ = G(A), and Nz = F(A, B), we do not have N~ J, N=. Note that there are no such restrictions for the equations in &

We are now able to state our main result. Let us define the set of critical pairs of an equational theory (~, d~) as the set of all critical pairs o f ~ and critical pairs of ~ / ~ , as defined above.

THI~OI~M 3.3. Let (~ , ~ ) be an equational theory such that

(1) V(a ~ fl) ~ £ ~ ( ~ ) ~ Y'(a) and a is linear, (2) V(a ffi ~8) ~ ~f 3e~(#) ffi "f/'(a); (3) -->.~ is noetherian with ~ = .~ and ~ ffi ~ .

Let ~ t denote any--y-normal form of M, obtained by any sequence o f reductions o f fft, for any M ~ ~. The theory (91, ~) is confluent ifffor all its criticalpairs (P, Q) we have P ~ Q, and then (~!, ~f) t-- M = N iff M ~ N.

PROOF. Directly from Lemmas 2.6, 2.8, 3.4, and 3.5. []

Remarks. The notion of critical pair of (~ , d*) involves trying all supcrpositions of equations in ~ with simplifications in ~ , and conversely, and mutual superpositions of simplifications in ~ . But there is no need to superpose two equations in $',

To check the termination condition --~. ~ noetherian, the method given in Section 3.2 is

Page 23: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

Confluent Reductions 819

still valid, provided the interpretation X chosen is such that X(a) -- X(fl) is identically true for every equation (a = fl) in ¢.

Note that it is important to get termination criteria as general as possible in Lemmas 2.4, 2.7, and 2.8. For instance, the conditions of [34] are too restrictive to be used with Knuth and Bendix's lexicographic ordering [16].

When Y¢ and 8 are finite, Theorem 3.3 gives us a decision procedure for the confluence of (~t, 8 ) , since there is a finite number of critical pairs. Furthermore, it is possible to extend the Knuth and Bendix method, to attempt to complete a theory to a confluent one, as follows. We start from ~ and 8 satisfying conditions !, 2, and 3 of Theorem 3.3. We generate the set ~ of critical pairs. For ev^ery (P, ~ ) in c¢ such that P 7 ~ Q, we either add (P = Q) to c o t one of the rules (/~--) Q) and (Q ~ / ~ ) t o n . Of course we must check that all the conditions of Theorem 3.3 are still valid. I f this completion succeeds for every element of c¢, we iterate the process with the new critical pairs that may have been created. The whole process may stop with success, resulting in a confluent equational theory equivalent to the initial one (i.e., with same deducibility relation ~); this may be considered as compiling axioms into simplification rules, replacing deduction by computation. The process may also fail or loop forever, generating progressively an infinite confluent equational theory.

A generalization of the Knuth and Bendix completion algorithm for handling commu- tative axioms is given in [ 18] and extended in [ 19] to a class of axioms called permutative axioms. This approach is different from ours: first because the condition checked in these papers is the confluence o f - -~ /~ , rather than the confluence of ~ modulo ~; second, because they consider arbitrary simplifications, but the equations must be such that the equwalence classes of - are finite, whereas our equations are arbitrary, but our simplifi- cations must be left linear.

Another approach to the generalization of [16] consists in embedding equations into specialized unification algorithms, in the manner of [30]. This method may be used for commutative and associative axioms, as shown in [20, 26] for Abelian groups, commutative rings, and distributive lattices.

Let us end this section with an example of the use of Theorem 3.3.

Example. We use the binary symbols + and • in infix notation. Let

= {(E(x + y)--~ E(x) .E(y) ) , (E(O)--) 1), (x + O--~ x) , (O + x - - ) x) , (x . l - -~ x) , ( l . x - - * x ) )

and

8 = {(x + y = y + x), ((x + y) + z = x + ( y + z)), ( x . y = y . x ) , ~(x.y)z = x ( y . , ) > }.

We leave it to the reader to check that conditions l, 2, and 3 of Theorem 3.3 are fulfilled and that for every critical pair (P, Q) we have/~ ~ 0, proving that (~ , ¢ ) is a confluent equational theory. This example suggests the use of Theorem 3.3 for the study of operational semantics of recursive programs operating on abstract data types, with modeling the computation rules, and g the axiomatic definition of the data type.

4. Conclusion

We have presented in Section 2 of this paper general axiomatic properties that are sufficient to prove the confluence of a reduction relation. These results permit us, under certain conditions, to localize the confluence test to simpler diagrams. We consider in Section 3 term rewriting systems and show that many closure conditions expressed by these diagrams can be spectalized to the critical pairs. These methods give us systematic ways of mecha- nizing an equational theory, favoring simplifications over arbitrary equality replacements. This problem arises in formula manipulating systems for various applications: program

Page 24: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

820 GERARD HUET

optimization, program validation, automatic theorem proving, operational semantics of programming languages, and semantics of parallel systems.

ACKNOWLEDGMENTS. I wish to thank J.J. Levy, B. Rosen, and R. Sethi for their helpful remarks.

REFERENCES

| . A~o, A., Sg~'m, R , Ah'D ULLU~N, J. Code optimization and finite Church-Rosser systems In Proceedings o f Courant Computer Science Symposmm 5, R Rustm, Ed., Prenttc, e Hall, Englewood Cliffs, N.J, 1972, pp 89-105

2. BgowN, T A structured design method for spectahzed proof p~ocedures Ph D Thesis, Cahfornta lnsUtute of TechnolOgy, Pasadena, Calif., 1975

3 BURSTALL, R Proving properties of programs by structural induction Comput J. 12 (1969), 41--48 4. CRURCti, A., AND ROSSER, J.B. Some properties of conversion. Trans. AMS 39 (1936), 472-482. 5. COl-iN, P M Universal algebra. Harper and Row, New York, 1965. 6 CURRY, H B., AND FEYS, R Combmatory Logic, Vol 1 North Holland, Amsterdam, 1958 7. DERSHOWITZ, N, AND MANNA, Z Proving termination with multiset ordermgs Commun ACM 22, 8

(Aug. 1979), 465-476 8 GUARD, J R , OGLESBY, F.C, BEIqNETT, J.H., AND SETTLE, L.G. Semi-automated mathematics J. ACM 16

(1969), 49-62. 9. HINDLEY, R An abstract Church-Rosser theorem Pt 1, J Symbohc Logic 34 (1969), 545-560, Pt 2, J

Symbohc Logic 39 (1974), 1-21. 10 HINDLEY, R, LERCHER, B., AND SELDIN, J.P. Introduction to combmatory logxc In London Mathematical

Society Lecture Notes 7, Cambridge University Press, Cambridge, England, 1972 1 I. HUET, G. Experiments with an interactive prover for logic with equality Rep. i 106, Jenmngs Computing

Center, Case Western Reserve Unlv, Cleveland, Ohio, 1970. 12 Hu~r, G R6solution d'6quatlons dans des langages d'ordre 1, 2 . . . . ~ Th~se d'Etat, Umv Paris VII,

Parts, Sept 1976. 13 HUET, G , AND LANKFORD, D.S On the uniform haltmg problem for term rewriting systems Lab Rep No

283, INRIA, Le Chesnay, France, March 1978 14. HUET, G., AND LEVY, J J. Call by need computations in non-ambiguous linear term rewriting systems. Lab.

Rep. No. 359, INRIA, Le Chesnay, France, Aug. 1979 15. KLOI~, J W A counter example to the Church-Rosser property for lambda calculus with subjective pairing

Preprint No 102, Dep of Mathemaucs, Umv. of Utrecht, Utrecht, The Netherlands, 1978. 16. KNUTH, D., AND BENDIX, P. Simple word problems in umversal algebras In Computational Problems in

Abstract Algebra, J Leech, FEd., Pergamon Press, Elmsford, N.Y, 1970, pp. 263-297 17. LANKFOgD, D S. Canonical inference Rep ATP-25, Dep. Mathematics and Computer Sciences, Univ. of

Texas, Austin, Texas, Dec 1975 18. LANKFORD, D S., AND BALLANTYNE, A.M Decision procedures for s,mple equational theories with com-

mutaUve axioms" Complete sets of commutative reductmns. Rep. ATP-35, Dep. Mathematics and Computer Sc,ences, Umv of Texas, Austin, Texas, March 1977

19. LANKFORD, D.S, AND BALLANTYNE, A M. Decision procedures for simple equational theories wRh per- mutatlve axioms' Complete sets of permutatmve reduct,ons Rep. ATP-37, Dep. of Mathematics and Computer Sciences, Umv of Texas, Austin, Texas, April 1977

20 LANKFORD, D.S, AND BALLANTYNE, A.M DecJsmon procedures for s,mple equational theories with com- mutative-associative axioms: Complete sets of commutative-associative reductions Rep ATP-39, Dep Mathemaucs and Computer Sciences, Univ. of Texas, Austin, Texas, Aug. 1977.

21. LIPTON, R.J, AND S~YDER, L On the halting of tree replacement systems Proc of Waterloo Conf. on Theoretical Computer Science, Univ of Waterloo, Waterloo, Ontario, Aug 1977, pp 43--46

22. MANNA, Z., AND NESS, S. On the termmauon of Markov algorithms. Proc 3rd Hawan Int. Conf. on System Sciences, Jan. 1970, pp. 789-792.

23. NEWMAN, M.H A On theories with a combmatona! defimuon of "eqmvalence" Ann Math, 43 (1942), 223-243

24. NIVAT, M. Congruences parfaltes et quasl-parfaRes Sdmmalre Dubreud 7, 1971-72, see also prehmmary version- On some families of |anguages related to the Dyck language. Proc 2nd Ann. ACM Syrup on Theory of Computing, Northampton, Mass., Mat, 1970, pp. 221-225

25 PATERSON, M.S., AND WEGMAN, M N Linear umficatmn Proc 8th Ann ACM Syrup. on Theory of Computing, Hershey, Pa, May 1976, pp. 181-186.

26. PETERSON, G E, AND STICKEL, M E Complete sets of reductions for equational theories wRh complete unification algonthms Tech. Rep., Dep. of Computer Science, Umv. of Arizona, Tucson, Ariz., Sept 1977.

27 PLAISTED, D. Well-founded ordermgs for prowng termination of systems of rewrite rules Tech Rep. 78- 932, Dep. of Computer Science, Umv. of llhnois, Urbana-Champalgn, 111, July 1978.

28. PLAISTED, D. A recurslvely defined ordering for proving termination of term rewriting systems Tech. Rep 78-943, Dep of Computer Science, Untv of llhnols, Urbana-Champaign, 111, Sept 1978

Page 25: Confluent Reductions: Abstract Properties and Applications ...rwh/courses/chtt/pdfs/huetcrs.pdfGI~RARD HUET LEMMA 2.2 If --~ is confluent, then the normal form of any element, if it

Con f luen t R e d u c t i o n s 821

29 PLOTKIN, G Lattice-theoretic properties ofsubsumption Memo MIP-R77, Univ. of Edinburgh, Edinburgh, Scotland, 1970

30 PLOTKIN G. Buddmg-m equational theories in Machine lntelhgence 7, B. Meltzer and D. Michie, Eds., American Elsevier, New York, 1972, pp 73-90

31. REYNOLDS, J Transformational systems and the algebraic structure of atomic formulas. In Machine lntelhgence .5, B Meltzer and D Michie, Eds, American Elsevier, New York, 1970, pp. 135-152.

32 ROBINSON, J .A. A machine-oriented lbglc based on the resolution principle J. ACM 12, 1 (Jan. 1965), 23- 41

33 ROSEN, B K. Tree-mampulatmg systems and Church-Rosser theorems J. ACM 20, i (Jan. 1973), 160-187 34. SETHI, R Testing for the Church-Rosser property J ACM 21, 4 (Oct 1974), 671-679, Errata, J. ACM 22,

3 (July 1975), 424 35 SLAGLE, J R Automated theorem-proving for theories with stmphfiers, commutattvity, and associativity.

J ACM 21, 4 (Oct 1974), 622-642 36 STAPLES, J Church-Rosser theorems for replacement systems In Algebra and Logic, J. Crossley, Ed.,

Lecture Notes m Mathematics No 450, Sprmger-Verlag, 1975

RECEIVED FEBRUARY 1978; REVISED SEPTEMBER 1979; ACCEPTED JANUARY 1980

Journal oftbe Assoclauon for Computing MachJaery, Vol 27, No 4. October 1980