Theory Path Orderings? Jurgen Stuber Max-Planck-Institut fur Informatik Im Stadtwald, D-66123 Saarbrucken, Germany Tel: +49-681-9325-228, fax: +49-681-9325-299
[email protected] http://www.mpi-sb.mpg.de/~juergen/
Abstract. We introduce the notion of a theory path ordering (TPO),
which simpli es the construction of term orderings for superposition theorem proving in algebraic theories. To achieve refutational completeness of such calculi we need total, E -compatible and E -antisymmetric simpli cation quasi-orderings. The construction of a TPO takes as its ingredients a status function for interpreted function symbols and a precedence that makes the interpreted function symbols minimal. The properties of the ordering then follow from related properties of the status function. Theory path orderings generalize associative path orderings.
1 Introduction Refutationally complete superposition calculi for algebraic theories require simpli cation orderings which are total on ground terms, and which obey additional restrictions imposed by the algebraic theories. In particular, theorem proving modulo some equational theory E requires that the term ordering is E -compatible. The most important theory in practice is AC (Bachmair and Plaisted 1985, Delor and Puel 1993, Rubio and Nieuwenhuis 1995, Kapur and Sivakumar 1997, Baader 1997). Additionally, presenting the theory by a term rewriting system modulo E (Bachmair, Ganzinger and Stuber 1995, Marche 1996, Stuber 1998a, Stuber 1998b) requires that the ordering orients the rules in this system in the right direction. The same applies to rules in symmetrizations which arise from the interaction of nontheory and theory equations. In some cases, for instance for modules and algebras over a xed ring, these requirements cannot be met by combining orderings known from the literature and necessitate the construction of new orderings (Stuber 1998a). We present a general construction of such an ordering. We distinguish between free and interpreted function symbols, where interpreted function symbols have a special meaning in the given theory. In particular, the function symbols in the set of equations E are contained in the interpreted function symbols. For free function symbols the ordering is de ned analogously to the lexicographic path ?
Part of this work has been supported by Deutsche Forschungsgemeinschaft under grant GA-261/7-1.
ordering. That is, we assume as given a precedence on free function symbols, and use lexicographic status to compare terms with the same free root symbol. Contexts consisting of interpreted function symbols will be handled as a whole by a status function, which is the main ingredient of our ordering. Such a status function can be presented as a function that extends an ordering on constants to an ordering on terms over constants and interpreted function symbols. Finally, the interaction between free and interpreted function symbols is handled by extending the precedence to a quasi-precedence where the interpreted function symbols form the minimal equivalence class. The main problem in the construction of E -compatible reduction orderings is to obtain compatibility with contexts (monotonicity). Considering contexts of depth greater than one in a single application of the status function essentially amounts to attening the context. To obtain compatibility with contexts we let free function symbols have a greater in uence on the ordering than interpreted function symbols. Formally this is re ected by interpreted function symbols being minimal in the precedence, and by requiring the status to have certain multiset properties, which ensure that the status function is compatible with the path ordering also within a context of interpreted function symbols. Our construction can be viewed as a generalization of the associative path ordering (Bachmair and Plaisted 1985). In view of this we call our ordering theory path ordering (TPO). On the other hand our construction is related to the general path ordering (Dershowitz and Hoot 1995, Geser 1996). We use Geser's approach to prove that the ordering has all the properties of a simpli cation quasi-ordering except compatibility with contexts. There are also some overlaps of the properties we require of an extension function with those required by Baader (1997). He combines an E1 - and an E2 -compatible reduction ordering into an E1 [ E2 -compatible one. However, his combination ordering compares terms rst by the maximal number of alternations between E1 and E2 . This makes it unsuitable for our purposes, since we need that free function symbols dominate the ordering. We use quasi-orderings throughout our presentation, since these integrate an ordering and an equivalence relation in a natural way. We split the notion of a quasi-ordering being total up to E into being E -antisymmetric and total. E antisymmetry has the advantage that it is also meaningful for partial orderings, which is useful in the nonground case. However, here we consider only the ground case. In Section 2 we state some preliminaries, in particular about quasi-orderings. Section 3 presents our adaption of the general path ordering of Geser (1996). In Section 4 we de ne the TPO and the notion of a TPO-status, and we show that the TPO has the desired properties. In Section 5 we show that a TPO-status can be given in a natural way as a function that extends an ordering on constants to an ordering on terms. In Section 6 we give examples of theory path orderings.
2 Preliminaries We assume the reader is familiar with term rewriting and the properties of orderings arising in that context (Dershowitz and Jouannaud 1990, Baader and Nipkow 1998). Following the latter we call a binary relation R on terms compatible with contexts if s R t implies u[s] R u[t] for any context u. A binary relation R is compatible with an equivalence relation if x x0 R y0 y implies x R y. An equation is called collapse-free if neither side is a variable. A set of equations is called collapse-free if all its equations are collapse-free. We write
(
argsAC(f )(t) = argsAC(f ) (t1 ) [ argsAC(f ) (t2 ) for t = f (t1 ; t2 ), ftg otherwise, which is the multiset of arguments of f after attening. A quasi-ordering is a binary relation that is re exive and transitive. Each quasi-ordering % can be split into its strict part () = (%) n (-) and its equivalence kernel () = (%) \ (-) = (%) n (). In the context of some quasi-ordering % we always use for its strict part and for its equivalence kernel. On the other hand, if is an equivalence relation and is a strict partial ordering that is compatible with then (%) = () [ () is a quasi-ordering. A quasi-ordering % is total on a set S if x % y or y % x for any two elements of S . It is well-founded if is well-founded. We say a quasi-ordering % on terms is E -compatible if % is compatible with =E . It is E -antisymmetric if s t implies s =E t for all terms s and t. A quasi-ordering may also be viewed as a partial ordering on -equivalence classes. Via this construction the multiset extension of partial orderings induces the multiset extension %mul (%) of a quasi-ordering %. Similarly, quasi-orderings can be combined lexicographically. The lexicographic extension of % to tuples of xed length is denoted by %lex (%). Multiset extension and the lexicographic combination preserve well-foundedness and totality. For a given quasi-ordering % we will also use subscripts to denote their multiset or lexicographic extension, e.g., %mul . Note that in this case mul denotes mul (%), that is, the strict part of the multiset extension of the (non-strict) quasi-ordering. The subterm ordering ⊲ is de ned by s ⊲ t if and only if t is a proper subterm of s. Since ⊲ is well-founded, ⊲mul = mul (D) is also well-founded. In general we will use % both to denote quasi-orderings and quasi-ordering functionals, because then and allow easy access to the strict part and equivalence kernel of the result of the functional applied to some quasi-ordering. We will use superscripts on quasi-ordering functionals to distinguish them from quasi-orderings, where we use no superscripts. We say that a quasi-ordering is strictly compatible with contexts if both % and are compatible with contexts. A reduction quasi-ordering is a quasi-ordering on terms that is well-founded, strictly compatible with contexts and strictly closed under substitutions. If in addition it has the subterm property, it is called a simpli cation quasi-ordering. The strict part of a simpli cation quasi-ordering is a simpli cation ordering. If R () and E () for a term rewriting system R modulo E and a reduction quasi-ordering % then R is terminating modulo E .
3 General path orderings We use the general path ordering (GPO) of Geser (1996) as a starting point for constructing quasi-orderings modulo E on ground terms. However, Geser's method of proving compatibility with contexts from a status being \prepared for contexts" cannot cope with attening, hence it is not applicable in this setting. Consequently, we weaken the notion of a status to that of a prestatus, which need not be prepared for contexts. By inspection of Geser's proofs one sees that his proofs use only the properties of a prestatus, with the exception of the proofs of re exivity and of compatibility with contexts. Fortunately re exivity can easily be proved from the properties of a prestatus alone. Compatibility with contexts will be the main topic of Section 4. Beyond the work of Geser we show that natural conditions on a prestatus imply that the induced GPO is total and E -antisymmetric. Given two terms s and t we let n(s; t) be the set fhs0 ; t0 i j fs; tg ⊲mul fs0 ; t0 gg. That is, a pair hs0 ; t0 i is in n(s; t) if either both terms are proper subterms of s or t, or if one term is equal to s or t and the other is a proper subterm of the other. For instance, n(f (a); g(b)) = fhf (a); bi; hb; f (a)i; ha; g(b)i; hg(b); ai; ha; ai; ha; bi; hb; ai; hb; big: A quasi-ordering functional is a function %st which maps any quasi-ordering % on ground terms to a quasi-ordering %st (%) on ground terms. A quasi-ordering functional %st is subterm founded on a set of pairs of terms S if s %st (%) t is equivalent to s %st (% \ n(s; t)) t for any quasi-ordering % and any pair hs; ti in S . We say that %st is subterm founded if it is subterm founded on the set of all pairs of ground terms. Subterm foundedness ensures that the GPO is wellde ned and allows to use induction to prove its properties. A quasi-ordering functional %st decreases in nite derivations if for every in nite derivation
s1 st (%) s2 st (%) : : : there exists an in nite derivation t1 t2 : : : such that si ⊲ t1 for some i 1. This property ensures well-foundedness of the resulting GPO. A quasiordering functional %st is called a prestatus if (i) %st is subterm founded, and (ii) %st decreases in nite derivations. The general path ordering %gpo = %gpo (%st ) induced by a prestatus %st is the smallest quasi-ordering such that s = f (s1 ; : : : ; sm ) %gpo g(t1 ; : : : ; tn ) = t if 1. si %gpo t for some i = 1; : : : ; m, or 2. s gpo tj for each j = 1; : : : ; n and s st (%gpo ) t. As an example consider a language consisting of a binary function symbol f and a constant a, and de ne %st by s %st (%) t if and only if either 1. s = a, or 2. s = f (s1 ; s2 ), t = f (t1 ; t2 ) and argsAC(f ) (s) %mul argsAC(f ) (t).
Then %st preserves re exivity and transitivity, since the multiset extension does. It is subterm founded, since it invokes its argument ordering only on multisets of its subterms, and it decreases in nite derivations, since the multiset extension does. By inspecting the de nitions one sees that %gpo (%st ) is the recursive path ordering with respect to the precedence a p f and with multiset status for f . Lemma 1 (Geser 1996) Let %st be a prestatus. 1. If s %gpo t and t ⊲ t0 then s gpo t0 . 2. If s ⊲ s0 and s0 %gpo t then s gpo t. 3. %gpo is transitive and well-founded. Geser (1996) proof of transitivity and the proofs of the lemmas below use the following scheme for proving that %gpo has some property P , based on subterm foundedness and preservation of P by %st : { Consider some instance P [t1; : : : ; tn] of P . First prove P [t1; : : : ; tn] for the case where some atom ti % tj in P becomes true by case 1 of the de nition of %gpo . Lemma 1(1+2) can often be used in this case. It remains to consider only case 2, where the prestatus is used. { Let n be the union of all sets n(ti ; tj ) where ti % tj is an atom in P . { Restrict %gpo to n, that is, consider (%gpo ) \ n. { Extend (%gpo ) \ n to some %P that satis es P , and that coincides with %gpo on n. That is, (%gpo ) \ n = (%P ) \ n. { Then by subterm foundedness ti %st (%gpo ) tj if and only if ti %st (%gpo \ n) tj if and only if ti %st (%P \ n) tj if and only if ti %st (%P ) tj : { Use that %st preserves P to conclude that P [t1; : : : ; tn] holds for %st (%gpo ) and hence for %gpo . Lemma 2 Let %st be a prestatus. Then %gpo is re exive. Lemma 3 Let %st be a prestatus that preserves totality. Then %gpo is total. Our example prestatus preserves totality. Either one of the terms is a, or both have f at their root and we may use that the multiset extension preserves totality. Lemma 4 Let %st be a prestatus that preserves E -antisymmetry. Then %gpo is E -antisymmetric. For our example let E = AC(f ) = AC. We claim that %st preserves ACantisymmetry. If s st t then either s = t = a or argsAC(f ) (s) = fs1; : : : ; sk g mul ft1 ; : : : ; tk g = argsAC(f ) (t). Then there exists a permutation of f1; : : :; kg such that si t(i) for i = 1; : : : ; k, and si =AC t(i) by AC-antisymmetry of %. By combining the equational proofs for si =AC t(i) with a proof derived from the permutation we can then obtain s =AC t.
We say that a quasi-ordering functional %st is prepared for E -compatibility if s st (%) t for any ground instance s t of an equation s t in E and for any quasi-ordering %.
Lemma 5 Let E be a set of equations, let %st be a prestatus that is prepared for E -compatibility, and suppose that %gpo is compatible with contexts. Then %gpo is E -compatible.
Proof: By induction on hs; ti with respect to ⊲mul . Let s = f (s1 ; : : : ; sm ) and t = g(t1 ; : : : ; tn ). We have to show s %gpo t for any E -step s ,E t. Symmetry of ,E and re exivity and transitivity of %gpo then imply (=E ) (%gpo ). (1) Suppose the E -step is not at the root of s and t. Then si ,E ti for some i = 1; : : : ; n and sj = tj for all j 6= i in 1; : : : ; n. By using the induction hypothesis we get si %gpo ti and s %gpo t by compatibility with contexts. (2) It remains to consider an E -step at the root position. We can write s as s0 and t as t0 where s0 t0 or t0 s0 is the equation in E that is used. Since %st is prepared for E -compatibility, s %st (%gpo ) t follows. ut
By construction our example prestatus is prepared for E -compatibility. We conclude for the moment that our example GPO is a well-founded E -compatible and E -antisymmetric quasi-ordering on terms that has the subterm property. It remains to consider compatibility with contexts.
4 Theory path orderings Theory path orderings generalize the idea underlying the APO that compatibility with contexts can be achieved for path orderings if interpreted function symbols are minimal in the precedence. It combines a lexicographic path ordering on nontheory function symbols with a special treatment of symbols in the theory, which is formalized by a status function. We let F denote the set of all function symbols, FE the function symbols in E and FT the function symbols in the theory T . Since in general not all function symbols in FT need to be treated specially by the ordering, we select a set FI of interpreted function symbols such that FE FI FT . Function symbols not in FI are called free. We let I be the set of terms over F with an interpreted function symbol at the root, and A the set of terms with a free function symbol at the root. Terms in A are called atomic. A precedence %p is a quasi-ordering on function symbols whose strict part is well-founded. A precedence %p is called TPO-admissible for FI if f p g for any pair of function symbols from FI , f p g whenever f 62 FI and g 2 FI , and f = g whenever f p g for f and g not in FI . A well-founded partial ordering on F n FI can be extended to a TPOadmissible quasi-ordering on F by letting f % g whenever either (i) f and g not in FI and f g, or (ii) g in FI . If is total this is the only TPO-admissible extension. E.g., for FI = f+; 0g and free function symbols fa; f g with a given precedence f p a the TPO-admissible extension is f p a p + p 0.
We now come to the properties of a quasi-ordering functional which ensure compatibility with contexts. A quasi-ordering functional %st is strictly internally prepared for contexts with respect to FI if
s %st (%) t implies f (: : : ; s; : : : ) %st (%) f (: : : ; t; : : : ) and s st (%) t implies f (: : : ; s; : : : ) st (%) f (: : : ; t; : : : ) for any f in FI . We say that a quasi-ordering functional %st has the multiset properties for FI if it satis es s % t () s %st t for s 2 A and t 2 A (M0) s1 %st t _ : : : _ sm %st t (= f (s1 ; : : : ; sm ) %st t for t 2 A (M1) s1 %st t _ : : : _ sm %st t =) f (s1 ; : : : ; sm ) %st t (M2) (M3) s st t1 ^ : : : ^ s st tn =) s %st f (t1 ; : : : ; tn ) for s 2 A s st t1 ^ : : : ^ s st tn (= s %st f (t1 ; : : : ; tn ) (M4) for any f in FI , where %st denotes %st (%). A quasi-ordering functional %st is called a TPO-status for FI if it is subterm founded on I 2 , decreases in nite derivations in I , is strictly internally prepared for contexts with respect to FI , and has the multiset properties for FI . The theory path ordering %tpo = %tpo (%p ; %st ) induced by a TPO-admissible precedence %p and a TPO-status %st is de ned as the smallest binary relation such that s = g(s1 ; : : : ; sm ) %tpo h(t1 ; : : : ; tn ) = t if 1. si %tpo t for some i = 1; : : : ; m, or 2. s tpo tj for each j = 1; : : : ; n and either (a) g p h, (b) g p h 62 FI and hs1 ; : : : ; sm i %lex (%tpo ) ht1 ; : : : ; tn i, or (c) g p h 2 FI and s %st (%tpo ) t. We assume that each function symbol has a xed arity, hence m = n in case 2b. To view %tpo as a general path ordering we have to de ne a suitable quasiordering functional. We de ne %sttpo = %tpost (%p ; %st ) by s = g(s1 ; : : : ; sm ) %sttpo (%) h(t1 ; : : : ; tn ) = t if and only if (a) g p h, (b) g p h 62 FI and hs1 ; : : : ; smi %lex (%) ht1 ; : : : ; tn i; or (c) g p h 2 FI and s %st (%) t. Then clearly %tpo (%p ; %st ) = %gpo (%tpost (%p ; %st )) for any precedence %p and TPO-status %st . For our running example we let FI = ff g and a p f . To satisfy the multiset properties we have to modify %st such that it uses % on the (only) atomic term a. We let s %st (%) t if and only if argsAC(f ) (s) %mul argsAC(f ) (t). Note that a
becomes a singleton multiset, hence (M0) is satis ed. The other properties of a TPO-status are also easily veri ed. Moreover, the resulting %sttpo is the prestatus of Section 3. To obtain E -compatibility in the context of a simpli cation ordering we require E to be collapse-free. A collapsing equation t x would lead to a con ict with the subterm property, since x has to occur in t for any nontrivial theory. Lemma 6 Let E be a set of collapse-free equations, let FI FE , let %p be a precedence that is TPO-admissible for FI , and let %st be a TPO-status. 1. Then %sttpo is a prestatus. 2. If %p is total and if %st preserves totality on I 2 then %sttpo preserves totality. 3. If %st preserves E -antisymmetry on I 2 then %sttpo preserves E -antisymmetry. 4. If %st is prepared for E -compatibility then so is %sttpo . Proof: The proof is straightforward. We consider only the last item in order to show where collapse-freeness is needed. (Prepared for E -compatibility ) Let s = s^ t^ = t be a ground instance of an equation s^ t^ in E , where s = g(s1 ; : : : ; sm ) and t = h(t1 ; : : : ; tn ). Since E is collapse-free, g and h are both in FI . Then g p h and s %st (%) t for any quasi-ordering %, since %st is prepared for E -compatibility. This implies ut s %sttpo (%) t. Next we show that due to the multiset properties a TPO-status and the resulting TPO are identical within contexts of interpreted function symbols. Lemma 7 Let %p be a precedence that is TPO-admissible for FI , and let %st be a quasi-ordering functional that is subterm founded on I 2 and has the multiset properties for FI . Then s %tpo t if and only if s %st (%tpo ) t. Proof: We use induction on the pairs hs; ti with respect to ⊲mul . Let s = g(s1 ; : : : ; sm ) and t = h(t1 ; : : : ; tn ). (1) Suppose g and h are not in FI . Then s %tpo t if and only if s %st (%tpo ) t by (M0). (2) Suppose g is in FI and h is not, which implies h p g. Then s %tpo t if and only if there exists some i = 1; : : : ; m such that si %tpo t. This is equivalent to si %st (%tpo ) t by the induction hypothesis, and to s %st (%tpo ) t by (M1) and (M2). (3) Suppose g is not in FI and h is, which implies g p h. Then s %tpo t is equivalent to s tpo tj for all j = 1; : : : ; n by case 2 of the de nition of %tpo . Note that case 1 implies case 2 in this context. By induction hypothesis this is equivalent to s st (%tpo ) tj for all j = 1; : : : ; n, and to s %st (%tpo ) t by (M3) and (M4). (4) Otherwise g and h are in FI . For the only-if-direction suppose s %tpo t. If s %tpo t by case 1 of the de nition of %tpo then there exists some i = 1; : : : ; m such that si %tpo t. This implies si %st (%tpo ) t by induction hypothesis, and s %st (%tpo ) t by (M2). Otherwise case 2 of the de nition of %tpo holds, which explicitly includes s %st (%tpo ) t.
For the if-direction assume s %st (%tpo ) t. Then s st (%tpo ) tj for all j = 1; : : : ; n by (M4), and s %tpo tj for all j = 1; : : : ; n by induction hypothesis. Together with s %st (%tpo ) t this satis es case 2 of the de nition of %tpo , hence ut s %tpo t. Theorem 8 Let E be a set of collapse-free equations, let FI FE , let %p be a precedence that is TPO-admissible for FI , and let %st be a TPO-status for FI . 1. Then %tpo is a simpli cation quasi-ordering. 2. If %p is total and %st preserves totality on I 2 then %tpo is total. 3. If %st preserves E -antisymmetry on I 2 then %tpo is E -antisymmetric. 4. If %st is prepared for E -compatibility then %tpo is E -compatible. Proof: (Simpli cation quasi-ordering ) By Lemma 6 %sttpo is a prestatus. Thus %tpo is a well-founded quasi-ordering on ground terms that has the subterm property. It remains to show compatibility with contexts and strict compatibility with contexts. Let s = g(s1 ; : : : ; sm ), t = h(t1 ; : : : ; tn ), s0 = f (u1 ; : : : ; ui ; s; ui+1 ; : : : ; uk ), 0t = f (u1 ; : : : ; ui ; t; ui+1 ; : : : ; uk ), and suppose s %tpo t. By the subterm property s0 gpo uj for j = 1; : : : ; k, and s0 tpo t by Lemma 1. (Compatibility with contexts ) We have to show s0 %tpo t0 . (1) Suppose f 62 FI . Then s0 %sttpo (%tpo ) t0 because
hu1 ; : : : ; ui ; s; ui+1 ; : : : ; uk i %lex (%tpo ) hu1 ; : : : ; ui ; t; ui+1 ; : : : ; uk i by de nition of %lex . (2) Otherwise f 2 FI . From s %tpo t we get s %st (%tpo ) t by Lemma 7, and by internal preparedness for contexts s0 %st (%tpo ) t0 , which is equivalent to s0 %sttpo (%tpo ) t0 for f in FI . (Strict compatibility with contexts ) We have to show s0 tpo t0 under the assumption s tpo t. Since there cannot exist a j = 1; : : : ; n such that tj %tpo s, case 1 of the de nition of %tpo cannot be used to obtain t0 %tpo s0 . Hence it suces to show s0 sttpo (%tpo ) t0 in order to conclude s0 tpo t0 . (1) Suppose f 62 FI . Then s0 sttpo (%tpo ) t0 if and only if
hu1 ; : : : ; ui ; s; ui+1 ; : : : ; uk i lex (%tpo ) hu1 ; : : : ; ui ; t; ui+1 ; : : : ; uk i; which follows from the de nition of %lex . (2) Otherwise f 2 FI . From s tpo t we get s st (%tpo ) t by Lemma 7, and by strict internal preparedness for contexts s0 st (%tpo ) t0 , which implies s0 sttpo (%tpo ) t0 and in turn s0 tpo t0 . (Totality ) Since %p is total and %st preserves totality on I 2 , we get that %sttpo preserves totality by Lemma 6(2). Hence %tpo is total by Lemma 3. (E -antisymmetry ) %st preserves E -antisymmetry on I 2 , hence %sttpo preserves E -antisymmetry by Lemma 6(3), and %tpo is E -antisymmetric by Lemma 4. (E -compatibility ) Since %st is prepared for E -compatibility we get that %sttpo is prepared for E -compatibility by Lemma 6(4). Since %tpo is compatible with contexts it is E -compatible by Lemma 5. ut
5 From extension function to TPO-status When de ning a TPO-status it is often useful to represent atomic subterms by constants. This ensures that the ordering obtained from the status for atomic subterms is determined only by its argument quasi-ordering. For instance, the de nition of a TPO-status often involves normalizing with respect to some distributivity rules. By hiding atomic subterms in constants no rewriting can take place in atomic subterms. Also, extending an ordering on constants to terms is more natural and allows to reuse known simpli cation quasi-orderings in a status function. We let FC be the set of new constants fct j t 2 Ag. That is, we assume that FC and F are disjoint, where A contains only terms over F . Then for a given ordering % on terms over F we de ne the ordering %c (%) on constants in FC by cs %c(%) ct if and only if s % t. We will pack atomic subterms into constants from FC and compare them according to %c(%). Technically, we let U be the convergent term rewriting system fct ) t j t 2 Ag, and write U (t) for the normal form of t with respect to U . We use the term rewriting system
P = ft ) ct j t ground term over F [ FC , t 62 FC , t0 = U (t) and t0 2 Ag 0
for packing atomic subterms into constants. The unpacking of t in the de nition of P is needed to remove nested constants in t. For termination of P observe that the number of symbols from F decreases in each step. For con uence observe that P contains a rule u[cs ] ) ct for each critical pair 0
0
ct (P u[s] )P u[cs ] where t0 = U (u[s]), s0 = U (s) and u is a nonempty F -context, since U (u[cs ]) = U (u[s]) = t0 2 A. It remains to obtain a quasi-ordering on the packed terms. Let %t be a function that maps any quasi-ordering %c on constants FC to a quasi-ordering on terms over FI [ FC , with the following properties: 1. %t (%c ) extends %c , is strictly compatible with contexts and has the subterm property. 2. Whenever there is an in nite descending chain t1 t (%c) t2 t (%c) : : : of terms over FI [ FC then there exists an in nite descending chain c1 c c2 c : : : of constants in FC such that c1 occurs in some tj for j 1. 3. Let c be a constant in FC . If c c c0 for all constants c0 occurring in a term t then c t (%c ) t. 4. If t %t (%c ) c then c0 %c c for some constant c0 in t. Then we will call %t an extension function. Property 3 is the constant dominance condition of Baader (1997). Note that it implies property 4 for total %c. We can now de ne a TPO-status %stt by s %stt (%) t if and only if P (s) %t (%c (%)) P (t). Lemma 9 Let %t be an extension function. Then %stt is a TPO-status for FI . 0
0
0
ut
Proof: The proof is straightforward.
Proposition 10 Let %t be an extension function such that %t(%c) is total for
any total quasi-ordering %c on constants. Then %stt preserves totality.
Lemma 11 Let
%t be an extension function such that %t (%c ) is (E [ c )antisymmetric for any quasi-ordering %c on constants. Then %stt preserves E antisymmetry.
Proof: Suppose % is E -antisymmetric and s stt (%) t. Then P (s) t (%c) P (t) and hence P (s) =E[c P (t). Since % is E -antisymmetric, cs c ct implies s0 =E t0 for any atomic subterms s0 and t0 of s and t. Hence s =E t. ut 0
0
Lemma 12 Suppose FI FE , and let %t be an extension function such that
%t (%c )
is E -compatible for any quasi-ordering %c on constants. Then %stt is prepared for E -compatibility. Proof: Observe that due to FI FE contexts at the root consisting of function symbols in E are left intact by packing. Hence for any instance of an equation in E packing both sides results again in an instance of the same equation. Thus for an equation s t in E we have P (s) = s0 %t (%c ) t0 = P (t) by E compatibility of %t , where we de ne 0 by x0 = P (x) for all variables x in E . We conclude that s %stt (%) t for any ground instance s t of an equation s t in E . ut
Theorem 13 Let E be a set of collapse-free equations, let %t be an extension function such that %t (%c ) is total, (E [ c)-antisymmetric and E -compatible for any total quasi-ordering %c on FC , and let %p be a precedence that is TPOadmissible for FI . Then %tpo (%p ; %stt ) is a total E -antisymmetric and E -compatible simpli cation quasi-ordering.
6 Examples of theory path orderings In a trivial way any simpli cation quasi-ordering can be constructed as a TPO, by taking FI = F and letting %t be the original ordering. Then A and FC are empty, and properties (3) and (4) of an extension function become void. Being a simpli cation quasi-ordering, %t satis es properties (1) and (2). On the other end of the spectrum is the lexicographic path ordering, which is obtained for FI = ;. The simplest nontrivial example is the associative path ordering for a single associative and commutative symbol f which we already have used as an example in Sections 3 and 4. That is, we have E = AC(f ) and FI = FE = ff g. Terms over FI [ FC are ordered according to the multiset of constants from FC they contain. Formally, we associate the complexity (t) = argsAC(f ) (t) to each term t over FI [ FC , and de ne %t (%c) by s %t (%c) t if and only if (s) %mul (%c ) (t). We
now show that this extension function satis es the requirements of Theorem 13. Associativity and commutativity are collapse-free. Clearly %t (%c ) extends %c and satis es properties 3 and 4. The multiset extension of a quasi-ordering has the following properties: (1) M1 %mul M2 implies N [ M1 %mul N [ M2 M1 mul M2 implies N [ M1 mul N [ M2 (2) (3) M1 ( M2 implies M1 mul M2 : Strict compatibility with FI -contexts is a consequence of (1) and (2). The subterm property follows by (3). The multiset extension preserves well-foundedness, hence an in nite descending chain in %t (%c ) can only arise from an in nite descending chain in %c. Since we can restrict the ordering to the constants occurring in the in nite descending chain of multisets, there is an in nite descending chain of constants occurring in these multisets. Thus %t is an extension function. If %c is total then %t (%c) is total, since the multiset extension preserves totality. AC-compatibility is obvious from the construction. Finally we show that the quasi-ordering %t (%c) is (AC [ c)-antisymmetric. Suppose s t (%c) t. To take care of c we select a representative rep(c) for each c-equivalence class in FC . That is, c c d if and only if rep(c) = rep(d) for any two constants c and d in FC . We replace each constant c in s and t by its representative and obtain terms s0 and t0 , respectively. Then s0 t(%c ) t0 , (s0 ) = M1 = fc1 ; : : : ; ck g and (t0 ) = M2 = fd1 ; : : : ; dl g; and M1 mul (%c) M2 . Since c-equivalent constants are equal in s0 and t0 , we even have M1 = M2 and hence s0 =AC t0 . Combining this with s =c s0 and t =c t0 we get s =AC[c t. We conclude that %t (%c) is AC [c -antisymmetric. Thus %tpo (%p ; %stt ) is a total, E -antisymmetric and E -compatible simpli cation quasi-ordering. To express a general associative path ordering as a TPO one would put the AC-function symbols and the symbols below them in the precedence into FI and keep the precedence on the other symbols in %p . The TPO-status would consist of the APO obtained by reusing the precedence on FI and extending it above by the ordering on the constants in FC . One easily sees that this is an extension function, and that the resulting TPO is equal to the original APO. As a larger example we present a quasi-simpli cation ordering for modules over some xed ring R. We assume as given a well-ordering R on R such that a R 1 R 0 for any a 2 R n f0; 1g. The module is described by the following term rewriting system modulo AC, where the vi are variables for scalars and is scalar multiplication: x+0x (M.1) 0x0 (M.2) 1xx (M.3)
v00 (M.4) v (x + y) v x + v y (M.5) v1 (v2 x) v x [v = v1 v2 ] (M.6) x + x v x [v = 1 + 1] (M.7) v1 x + x v x [v = v1 + 1] (M.8) v1 x + v2 x v x [v = v1 + v2 ] (M.9) We denote the set of ground instances of these rules that satisfy the constraints by M. The ordering should orient rules in M from left to right. Furthermore, the symmetrization requires that a t M a00 t + a0 r for any terms t and r and a; a0 ; a00 2 R such that t is atomic, t M r and a R a00 . The particular problem that rules out standard orderings is that (M.9) combines arbitrary coecients to a possibly greater coecient, while the reduction in the coecient from a to a00 must suce to make room for any term r smaller than t. We let FI = FM = f+; ; 0; 1g [ R, assume a total precedence p on F n FI , and let %p denote its TPO-admissible extension to F . Let D be the convergent term rewriting system consisting of the ground instances of the distributivity rule (M.5). We denote the normal form of a term t with respect to D by D(t). Let t be a ground term over FI [ FC in D-normal form. Then t is of the form t = a11 a1k1 c1 + + an1 ankn cn where n 1, ki 0, ci 2 FC [ f0; 1g, and aij 2 R for i = 1; : : : ; n and j = 1; : : : ; ki . We assign a complexity to any such t as follows. Again we assume a function rep : FC ! FC such that rep(c) = rep(d) if and only if c c d. We extend rep to FC [ f0; 1g by rep(0) = 0 and rep(1) = 1. The ordering %c is extended to FC [ f0; 1g such that c c 1 c 0 for any constant c in SFC . We let occ(t; ci ) = fj j cj c ci g, #(t; ci ) = jocc(t; ci )j, and cs(t; ci ) = j2occ(t;ci ) fhaj1 ; : : : ; ajk1 ig. That is, occ(t; ci ) is the set of indices of the occurrences of constants in the same c-equivalence class as ci , #(t; ci ) is the number of these occurrences, and cs(t; ci ) is the multiset of the tuples of coecients associated with these occurrences. To each equivalence class we associate the tuple hrep(ci ); #(t; ci ); cs(t; ci )i. Finally, we let (t) be the set of tuples for the constants from FC that occur in t. We order these complexities according to the multiset extension of the lexicographic combination of %c, > and the multiset extension of the length-lexicographic extension of R . We denote the ordering on complexities by % . Then we de ne the ordering %t on terms over FI [ FC by s %t t if and only if (D(s)) % (D(t)) where s and t are terms over FI [ FC . Finally we get the TPO-status %st1 as the status derived from %t , and let %1 (p ) = %tpo (%p ; %st1 ). Theorem 14 %1(p) is a total AC [ D-compatible and AC [ D-antisymmetric simpli cation quasi-ordering on ground terms that contains M n D. Proof: We do not have enough space for the complete proof that %t satis es the requirements of Theorem 13. As an example, we show how strict compatibility with contexts can be obtained:
Let fu[] be the function that maps any complexity (t) to (D(u[t])), where t = a11 a1k1 c1 + + an1 ankn cn is a ground term in D-normal form. To see that fu[] is well-de ned, observe that t can be reconstructed up to AC [ c -equivalence from (t), and that maps terms in an AC [c -equivalence class to the same complexity. We show that fu[] is strictly monotonic for any context u[] by considering contexts of depth one. (1) Consider u = s + []. (1.1) Suppose s = b1 bl d. (1.1.1) Suppose no ci is c -equivalent to d. Then fu[] ((t)) = (t) [ fhrep(d); 1; fhb1 ; : : : ; bl igig and fu[] is strictly monotonic by properties (1) and (1) of the multiset extension. (1.1.2) Otherwise d c ci for some i = 1; : : : ; n. Suppose without loss of generality d c c1 . Then fu[] ((t)) = fhc1 ; #(t; c1 ) + 1; cs(t; c1 ) [ fhb1; : : : ; bl igig [ fhci ; #(t; ci ); cs(t; ci )i j ci 6c c1 g: Consider the function that maps a tuple hc; n; M i to hc; n + 1; M [ fhb1; : : : ; bl igi if c c d and to hc; n; M i otherwise. This function is strictly monotonic. Hence its multiset extension fu[] is strictly monotonic. (1.2) Otherwise s is a proper sum, and fu[] can be obtained as a nite composition of the strictly monotonic functions of case (1.1). Hence fu[] is strictly monotonic. (2) Consider u = a []. Then fu[] maps any tuple ha1 ; : : : ; ak i of coecients in the multiset in the third component to ha; a1 ; : : : ; ak i. This mapping is strictly monotonic. By multiset extension, lexicographic product with identity functions for the rst two components and again multiset extension we obtain fu[] , which thus is strictly monotonic. ut From %1 we obtain an ordering that orients D from left to right and that is ACantisymmetric by combining %1 lexicographically with a polynomial ordering and the ACRPO of Rubio and Nieuwenhuis (1995).
7 Conclusion and Further Work We have presented a general path ordering for the purpose of superposition theorem proving in algebraic theories. We have used this construction successfully for the cases of abelian groups, commutative rings, and modules and algebras over a xed ring. In practice it will be necessary to consider also nonground terms. Clearly lifting depends on the particular TPO-status chosen. An approach that should be applicable in many cases is to compare two nonground terms by considering a nite set of their instances (Bachmair and Plaisted 1985).
Waldmann (1998) shows how to extend an arbitrary reduction ordering on terms over free function symbols to an ACU-compatible reduction ordering by semantic labeling, using essentially an APO for a single AC-symbol. It seems feasible to extend this approach to other theories via TPOs.
Acknowledgments I thank Uwe Waldmann and the anonymous referees for their detailed and helpful comments and Harald Ganzinger for his support.
References Baader, F. (1997). Combination of compatible reduction orderings that are total on
ground terms. In 12th Ann. IEEE Symp. on Logic in Computer Science, Warsaw, pp. 2{13. IEEE Computer Society Press. Baader, F. and Nipkow, T. (1998). Term rewriting and all that. Cambridge University Press, Cambridge, UK. Bachmair, L. and Plaisted, D. (1985). Termination orderings for associativecommutative rewriting systems. Journal of Symbolic Computation 1: 329{349. Bachmair, L., Ganzinger, H. and Stuber, J. (1995). Combining algebra and universal algebra in rst-order theorem proving: The case of commutative rings. In Proc. 10th Workshop on Speci cation of Abstract Data Types, Santa Margherita, Italy, LNCS 906, pp. 1{29. Springer. Delor, C. and Puel, L. (1993). Extension of the associative path ordering to a chain of associative commutative symbols. In Proc. 5th Int. Conf. on Rewriting Techniques and Applications, Montreal, LNCS 690, pp. 389{404. Springer. Dershowitz, N. and Hoot, C. (1995). Natural termination. Theoretical Computer Science 142: 179{207. Dershowitz, N. and Jouannaud, J.-P. (1990). Rewrite systems. In J. van Leeuwen (ed.), Handbook of Theoretical Computer Science: Formal Models and Semantics, Vol. B, chapter 6, pp. 243{320. Elsevier/MIT Press. Geser, A. (1996). An improved general path order. Applicable Algebra in Engineering, Communication and Computing 7: 469{511. Kapur, D. and Sivakumar, G. (1997). A total ground path ordering for proving termination of AC-rewrite systems. In Proc. 8th Int. Conf. on Rewriting Techniques and Applications, Sitges, Spain, LNCS 1103, pp. 142{156. Springer. Marche, C. (1996). Normalised rewriting: an alternative to rewriting modulo a set of equations. Journal of Symbolic Computation 21: 253{288. Rubio, A. and Nieuwenhuis, R. (1995). A total AC-compatible ordering based on RPO. Theoretical Computer Science 142: 209{227. Stuber, J. (1998a). Superposition theorem proving for abelian groups represented as integer modules. Theoretical Computer Science 208(1{2): 149{177. Stuber, J. (1998b). Superposition theorem proving for commutative rings. In W. Bibel and P. H. Schmitt (eds), Automated Deduction - A Basis for Applications. Volume III. Applications, chapter 2, pp. 31{55. Kluwer, Dordrecht, The Netherlands. Waldmann, U. (1998). Extending reduction orderings to ACU-compatible reduction orderings. Information Processing Letters 67(1): 43{49.