UNIVERSITY OF ILLINOIS LIBRARY AT URBANA-CHAMPAIGN Sow y efore «* i5L?b2 borrowed ^5 2 / ore o rroro •"CT/™^ *»"> »™ new due da(e W(w L162 lopy 2j ' • i ul r n UIUCDCS-R-79-986 A Note on Simplification Orderings by Nachum Dershowitz UILU-ENG 79 1736 ' t" implies f(...t...) > f(...t'...) and 2) £(...t...) > t. Note that this definition does not require that ^ be well-founded (cf. [5,7]). We shall assume throughout this note that all function symbols have fixed arity. A term-rewriting system P over a set of terms T is a finite set of rewrite rules of the form £.(a) -*■ r.(a), where the a are variables i i ranging over T. Such a rule is applied to a term t e T in the following manner: if t contains a subterm £.(a), i.e. the variables a are instantiated l ' with terms a, then replace that subterm with the corresponding term r.(a), thereby obtaining t 1 . The choice of rule and subterm is nondeterministic. We write t =* t f to indicate that the term t' can be derived from the term t by a single application of a rule in P to one of the subterms of t. (The variables appearing in r, must be a subset of those in I. . ) For example, the system consisting of the one rule (a*3)*Y "* ot*(£*Y) reparenthesizes a product by associating to the right. Applying that rule twice to the term t = (a»b) • ((c*d) »e) , -1- -2- we get t ■* a-(b*((cd)«e)) ■* a* (b* (c (d«e))) or, alternatively, t =* (a«b) • (c* (d*e)) =* a* (b* (c* (d*e)) ) . In either case, no further applications of the rule are possible. We say that a term-rewriting system P terminates , if there exist no infinite sequences of terms t. e T such that t =* t => t =*• . . . . In general, It is undecidable whether a system terminates [21. The following theorem gives a sufficient criterion for proving that a term-rewriting system terminates for all inputs. Termination Theorem : A term-rewriting system P = {Z . -> r . } . , over a set of 11 i=l terms T terminates if there exists a simplification ordering > over T such that £ i ^ r i ' i=1 '-'- >P > for any assignment of terms in T to the variables of £ . . The proof of this theorem is based on the following: Tree Theorem [4]: In any infinite sequence t-,t_,... of terms over a finite set of function symbols, there exists a pair of terms t. and t., i < j, such that t. is homeomorphically embedded in t. (when t. and t. are viewed as trees) . We shall denote this embedding relation by <. We have s = f(s ,s ,...,s ) < g(t ,t ,...,t ) = t , 1 z m — 1 z n -3- if and only if (a) f = g and s,, < t . for all i, l 1) have already been chosen, then let t. be a minimal size (that is, number of function symbols) i-th element of a counterexample sequence beginning with the elements already chosen. We need the following observation: Let s = (s ) . be any infinite sequence whose elements are proper subterms of successive elements of some subsequence of t. By the assumption of minimality of t, if s 1 is a subterm of some t, , then the sequence t- 9 t , . . . ,t, . ,s. ,s«. . . must contain an embedding pair s. < s . (i < j). Moreover, there must exist an infinite chain s. _ over T. Proof of Lemma : The proof is by induction on the size of t. Assume that s' js t' implies s' < t 1 for any t' smaller than t. By the definition of < y if s = f(s ,s 2 ,.. .s m ) < g(t-,t 2 ,... ,t ) = t (m or n may be 0), then either (a) f = g and s. < t. for all l_ we have I. ^ r., then it follows (using property (1)) that t-, ^ t~ ^ ...» and by transitivity that t. > t. for all i < i . But, by the Tree Theorem t. (asymmetry follows from transitivity and irref lexivity) . D This result may be used to simplify proofs of well-foundedness and termination, e.g. those in [1, 3, 6, 9, 10]. 2. SOME EXAMPLES Consider the one-rule term-rewriting system (or3) *Y "*" «• (3*y) and the following recursively defined ordering: t ^ t' for two terms t and t' , if (i) |t| > |t'|, where |t| denotes the number of function symbols in t, or else t and t 1 are products of the forms a*3 and ct'^B 1 , respectively, and (ii) |t| = | t 1 | and a > a' or else (iii) |t| = |t' | , a = a 1 , and 3 > g' (cf. the ordering in [3]). To see that this is a simplification ordering, note that t > t' implies 1 1| _> 1 1' | . Thus, if a > a 1 , then a* 3 > a' •£ (by (i) or (ii)) and 3*a^ B'a' (by (i) or (iii)). Furthermore, | ex • 3 1 > |a|,|3| and therefore a*3 ^ a, 3 (by (i)). To prove termination, we need only verify that (a*3)*Y ^ a*(3*y) in this ordering. This follows (by (ii)) from the fact that | (a* B) * Y | = | a* (6 • y) | and | ex * 3 | > |ot|. -6- As a second example, we prove that the system a- (8+7) + (a»8)+(a«Y) (S+7)'a ■*- (B*a)+(ya), for distributing multiplication over addition, terminates. Let the function t map terms into multisets recursively: (i) for any sum a+8, x(a+8) = T(a)Ux(8), where U denotes union of multisets, (ii) for any product a«8, x (a»0) = (T(a)Ux(8) } , and (iii) for any atomic term u, x(u) = {0}, where denotes the empty multiset. For example, x( ((a+b) • (c+d) )+e) = {{0,0,0,0} ,0} . We use the following simplification ordering: t > t' , for two terms t and t' , if x(t) » x(t') in the nested multiset ordering ». In this ordering (see [1]), XUZ » YUZ, for multisets X ^ 0, Y, and Z, if for each element y e Y there is some x e X such that x » y. For example, {{0,0,0,0},0} » {{0,0,0},{0,0,0},0h since {0,0,0,0} » {0,0,0}. It should be obvious from this definition of » that XUZ » YUZ if X»Y and that XUZ» Z if X 4 0. It is also easy to prove that {...X...} » X for any multiset X, by induction on the nested depth of X. With these facts in mind, it is straightforward to verify that ^ is a simplification ordering on terms. To prove termination it remains to show that a* (8+7) ^ (a*0)+(a , y) and (B+y)*a^ (8 # a)+(ya), i.e. we must show x(a*(8+y)) = x((0+7)*a) = {x(a)U T (B)U T ( Y )} » x((a-8)+(a- Y )) = t ((B-a)+(ya)) = {x(a)U T (8), x(a)U T (y)}. This in turn follows from the fact that the multisets x(0) and x(y) cannot be empty and therefore x (a)U T (8)U T (y) » x(a)U T (8), x(a)U T (y). 3. AN APPLICATION As an application of the Termination Theorem, consider the following class of orderings: With each function symbol f of arity n >^ associate -7- some real polynomial F(x-,...,x ) of n variables. Then extend this relation i n to a morphism on terms, i.e. f(t.,...,t ) = F(t,,...,t ), where t is the real 1 n l n expression associated with the term t. The set of terms T constructed from those function symbols may be ordered according to the real values of the associated expressions, i.e. t^ t' , for two terms t and t' in T, if and only if t > t' . Thus, to prove that a term- rewriting system P over T terminates, one must show that the polynomials F(x , ...,x ) satisfy the two conditions for simplification orderings (1) x > x' implies F(...x...) > F(...x'...) and (2) F(r..x...) > x, and that FT > r~" for each rule I. -*■ r . in P. Conveniently, these are all decidable properties for polynomials over the reals [11]. By the same token, it is decidable if there exists any polynomial of degree lees than any given n that demonstrates termination. In this manner, the undecidability for polynomials over the natural numbers, encountered in the method of [6], is circumvented. Finally, we note that the Termination Theorem provides sufficient but not necessary conditions for termination. To see this, consider, for example, the one-rule system ffa -> fgfa, where f and g are unary function symbols. This system always terminates, since each application of the rule decreases the number of adjacent f's. On the other hand, ffa <_ fgfa and therefore ffa 4 fgfa in any simplification ordering. Consequently, there is no simplification ordering ^ under which ffa ^ fgfa. Moreover, there can be no well-ordering ^ of all the terms constructable from f and g - that satisfies the monotonicity property (1) - under which ffa ^ fgfa. (Since ^ cannot be a implif ication ordering, for some term a it must be that a^ ha, where h is f or g; consequently, a^ha^hha^... is an infinite descending sequence and ^ cannot be a well-ordering. ) -8- REFERENCES [1] N. Dershowitz and Z. Manna [Aug. 19 79], Proving termination with multiset orderings , Comm. ACM, vol. 22, no. 8, pp. 465-476. [2] G. Huet and D. S. Lankford [1978], On the uniform halting problem for term rewriting systems , Report 2 83, IRIA, Le Chesney, France. [3] D. E. Knuth and P. B. Bendix [1969], Simple word problems in universal algebras , Computational Problems in Universal Algebras (J. Leech, ed.), Pergamon Press, Oxford, pp. 263-297. [4] J. B. Kruskal [May 1960], Well-quasi-ordering, the tree theorem, and Vazsonyi's conjecture , Trans. Amer. Math. Soc. , vol. 95, pp. 210-225. [5] D. S. Lankford [May 19 75], Canonical algebraic simplification in computational logic , Memo ATP-25, Automatic Theorem Proving Project, Univ. of Texas, Austin, TX. [6] D. S. Lankford [May 19 79], On proving term rewriting systems are Noetherian , Memo MTP-3, Mathematics Dept. , Louisiana Tech. Univ. , Ruston, LA. [7] Z. Manna and S. Ness [Jan. 19 70], On the termination of Markov algorithms , Proc. Third Hawaii Intl. Conf. on System Sciences, Honolulu, HI, pp. 789-792 [8] C. St. J. A. Nash-Williams [1963], On well-quasi-ordering finite trees , Proc. Cambridge Philos. Soc, vol. 59, pp. 833-835. [9] D. Plaisted [July 1978], Well-founded orderings for proving the termination of rewrite rules, Report R-78-932, Dept. of Computer Science, Univ. of Illinois, Urbana, IL. [10] D. Plaisted [Sept. 1978], A recursively defined ordering for proving termination of term rewriting systems , Report R-78-943, Dept. of Computer Science, Univ. of Illinois, Urbana, IL. 11] A. Tarski [1951], A decision method for elementary algebra and geometry , Univ. of California Press, Berkeley, CA. BIBLIOGRAPHIC DATA SHEET 1. Report No. UIUCDCS-R-79-986 2. 3. Recipient's Accession No. 4. Title and Subtitle A Note on Simplification Orderings 5. Report Date April 19 79 6. 7. Author(s) Nachum Dershowitz 8. Performing Organization Rept. No. 9. Performing Organization Name and Address Dept. of Computer Science University of Illinois Urbana, IL 61801 10. Project/Task/Work Unit No. 11. Contract /Grant No. NSF MCS 77-22830 12. Sponsoring Organization Name and Address National Science Foundation Washington, D.C. 13. Type of Report & Period Covered 14. 15. Supplementary Notes 16. Abstracts A new method is given for proving that term- rewriting systems terminate. Examples of its use are given. In particular, the method allows the use of polynomials over the reals in termination proofs. 17. Key Words and Document Analysis. 17a. Descriptors simplification orderings, term- rewriting, termination, well-founded orderings. 17b. Identifiers/Open-Ended Terms 17c. COSATI Field/Group 18. Availability Statement 19. Security Class (This Report) UNCLASSIFIED 21. No. of Pages 11 20. Security Class (This Page UNCLASSIFIED 22. Price FORM NTIS-38 (10-70) USCOMM-DC 40329-P7I FEB 20