On termination of higher-order rewriting Femke van Raamsdonk Division of Mathematics and Computer Science Faculty of Sciences, Vrije Universiteit De Boelelaan 1081a, 1081 HV Amsterdam The Netherlands
[email protected] CWI P.O. Box 94079, 1090 GB Amsterdam
Abstract. We discuss and compare various methods to prove termination of higher-order rewriting systems.
1
Introduction
A rewriting system is said to be terminating if all rewrite sequences are finite. Many methods to prove termination of first-order term rewriting have been studied. For higher-order rewriting, where bound variables may be present, there are so far significantly fewer results available. What makes this situation even worse is that there are several brands of higher-order rewriting, and it is often not immediately clear how to apply or adapt a result obtained in one framework to another one. We distinguish here three variants of higher-order rewriting. The first one are the higher-order rewriting systems (HRSs) introduced by Nipkow [16]. Here rewriting is defined modulo βη of simply typed λ-calculus. The second one are the combinatory reduction systems (CRSs) introduced by Klop [10]. The third one are the algebraic-functional systems (AFSs) introduced by Jouannaud and Okada [6]. Here the reduction relation of interest is the union of β-reduction and the reduction relation induced by the algebraic rewrite rule (which may be higher-order). Matching is syntactic (not modulo β). The first termination method for HRSs is due to Van De Pol [18]. It is a semantical method using an interpretation (to be given by the user) of the function symbols as functionals. The kernel is an adaptation of the proof of termination of simply typed λ-calculus using functionals [4]. This method is a generalization to the higher-order case of the method using termination models [5, 21]. Higher-order termination models are also studied in [9]. For AFSs the first termination method is due to Jouannaud and Okada [6], and makes use of the notion of general schema. The general scheme is designed to make the proof of termination of typed λ-calculus due to Tait and Girard adaptable to the case of the particular AFS. Blanqui [2] studies versions of the general scheme for higher-order rewriting with a CRS-like syntax and for HRSs.
2 An important method to prove termination of a first-order term rewriting system is the one using the recursive path ordering due to Dershowitz [3]. For higher-order rewriting several orderings have been designed to prove termination [12, 13, 7]. The problem was always to prove well-foundedness of the ordering: well-foundedness of the recursive path ordering is proved using Kruskal’s tree theorem, of which so far no sufficiently expressive higher-order variant seems to be known. Jouannaud and Rubio [8] present a generalization of the recursive path order for the higher-order case, in the framework of AFSs. The crucial idea is to show well-foundedness of the order using the notion of computability from the proof of termination of typed λ-calculi due to Tait and Girard. The main purpose of this paper is to make the termination method using the higher-order version of the recursive path ordering (horpo) more widely available by presenting it for HRSs and CRSs. In [8] horpo is upgraded using a version of the general scheme. Here we consider versions of the general scheme for HRSs and CRSs. The methods using horpo and using the general scheme are incomparable, as shown by examples. As in [8] we can consider an upgrading of horpo using the general scheme, but we leave it to further work to design a compact criterion with the power of horpo upgraded with the general scheme, or the other way around. In the appendix we consider well-foundedness of the recursive path ordering for first-order term rewriting. The proof makes use of the induction argument as in [8] that is used at several places in this paper.
2
Higher-order rewriting
In this paper we are mainly concerned with higher-order rewriting systems (HRSs) as introduced by Nipkow [16] and combinatory reduction systems (CRSs) as introduced by Klop [10]. In this section we briefly recall the syntax of those formats. For more detailed accounts we refer to [16, 14, 19, 10, 11]. Examples of higher-order rewriting systems in HRS, CRS, and AFS format are available at http://www.cs.vu.nl/ femke/papers.html. 2.1
Higher-order rewriting systems
In a HRS we work modulo the βη-relation of simply typed λ-calculus. Types are built from a non-empty set of base types and the binary type constructor → as usual. We assume a countably infinite set of typed variables, written as x, y, z, . . .. A signature is a non-empty set of function symbols, each with a fixed type. The set of pre-terms of type A over a signature Σ consists exactly of the expressions s for which we can derive s : A using the following rules: 1. 2. 3. 4.
x : A for a variable x of type A, f : A for a function symbol f of type A in Σ, if A = A′ → A′′ , and x : A′ and s : A′′ , then (x. s) : A′ → A′′ , if s : A′ → A and t : A′ , then (s t) : A.
3 The abstraction operator . binds variables, so occurrences of x in s in the pre-term x. s are bound. We work modulo α and assume that bound variables are renamed whenever necessary in order to avoid unintended capturing of free variables. Parentheses may be omitted according to the usual conventions. We make use of the usual notions of substitution of a pre-term t for the free occurrences of a variable x in a pre-term s, notation s[x := t], and replacement in a context, notation C[t]. Here a context is a pre-term with one occurrence of . The β-reduction relation, notation →β , is the smallest relation on pre-terms that is compatible with formation of pre-terms and that satisfies the following: (x. s) t →β s[x := t] The restricted η-expansion relation, notation →η , is defined as follows. We have C[s] →η C[x. (s x)] if s : A → B, and x : A is a fresh variable, and no β-redex is created (hence the terminology restricted η-expansion). The latter condition is satisfied if s is not an abstraction (so not of the form z. s′ ), and doesn’t occur in C[s] as the left part of an application (so doesn’t occur in a sub-preterm of the form (s s′ )). In the sequel we employ only pre-terms in η-normal form, where every subpreterm has the right number of arguments. A pre-term is then of the form x1 . . . xn . s0 (s1 , . . . , sm ) with s0 (s1 , . . . , sm ) of base type and all si in η-normal form. A term is a pre-term in β-normal form. It is also in η-normal form because η-normal forms are closed under β-reduction. A term is of the form x1 . . . xn . a(s1 , . . . , sm ) with a a function symbol or a variable. Because the βηreduction relation is confluent and terminating on the set of pre-terms, every βη-equivalence class of pre-terms contains a unique term, which is taken as the representative of that class. The rewrite relation of a HRS is defined on terms. Because in the discussion we will often use pre-terms, we use here the notation sσ for the replacement of variables according to the substitution σ, and write explicitly sσ ↓β for its β-normal form. A rewrite rule is a pair of terms (l, r), written as l → r, satisfying the following requirements: 1. 2. 3. 4.
l and r are of the same base type, l is of the form f (l1 , . . . , ln ), all free variables in r occur also in l, a free variable x in l occurs in the form x(y1 , . . . , yn ) with yi η-equivalent to different bound variables.
The last requirement guarantees that the rewrite relation is decidable because unification of patterns is decidable [15]. Without it we get the higher-order term rewriting systems defined in [20]. The rewrite rules induce a rewrite relation → on the set of terms which is defined by the following rules: 1. 2. 3. 4.
if if if if
s→t s→t s→t l→r
then x(. . . , s, . . .) → x(. . . , t, . . .), then f (. . . , s, . . .) → f (. . . , t, . . .), then x. s → x. t, is a rewrite rule and σ is a substitution then lσ ↓β → rσ ↓β .
4 2.2
Combinatory reduction systems
We assume countably infinite sets of variables, written as x, y, z, . . ., and metavariables, written as X, Y, Z, . . .. Every meta-variable has a fixed arity, expressing the number of arguments it is supposed to get. A signature is a non-empty set of function symbols, each with a fixed arity. The set of meta-terms of arity n over a signature Σ is inductively defined by the following clauses: 1. a variable x is a meta-term of arity 0 2. if f is a function symbol in Σ of arity m and s1 , . . . , sm are meta-terms, then f (s1 , . . . , sm ) is a meta-term of arity 0, 3. if s is a meta-term of arity m, then [x]s is a meta-term of arity m + 1, 4. a meta-variable Z of arity n is a meta-term of arity n 5. if s0 is a meta-term of arity n and s1 , . . . , sm are meta-terms of arity 0, then s0 (s1 , . . . , sm ) is a meta-term of arity 0. This definition of meta-term differs from the usual one: a meta-term can be a meta-variable applied to meta-terms, but also an abstraction applied to one or more meta-terms. In this way the meta-terms contain what are usually called the substitutes. A term is a meta-term without meta-variables or meta-application, so built using only the first three clauses of this definition. The abstraction operator [ ] binds variables, so occurrences of x in s in the meta-term [x]s are bound A term is a meta-term built using only the first three clauses of this definition. We make use of the following b-reduction rule: ([x1 . . . xm ]s0 )(s1 , . . . , sm ) →b s0 [x1 := s1 . . . xm := sm ] Because a variable x doesn’t occur in a submetaterm of the form x(s1 , . . . , sm ), an application of the b-reduction rule doesn’t create new b-redexes. The relation →b is like a development, and it is confluent and terminating on the set of meta-terms. A rewrite rule of a CRS is a pair of terms (l, r), written as l → r, satisfying the following requirements: 1. 2. 3. 4.
l and r are closed meta-terms of arity 0, l is of the form f (l1 , . . . , ln ), all meta-variables in r occur also in l, all meta-variables in l occur in the form Z(x1 , . . . , xm ) with x1 , . . . , xm different bound variables.
We use the notation sσ for s where all meta-variables are replaced according to the definition of the substitution σ. Such a substitution assigns meta-terms of arity n to meta-variables of arity n. The rewrite rules induce a rewrite relation → on the set of terms which is defined by the following rules: 1. if s → t then f (. . . , s, . . .) → f (. . . , t, . . .), 2. if s → t then [x]s → [x]t, 3. if l → r is a rewrite rule and σ is a substitution, then lσ ↓b → rσ ↓b .
5
3
Computability
In the following sections we will make use of the notion of computability due to Tait and Girard with respect to a relation ≫ on terms, pre-terms, or meta-terms. Here we give the definition for both the typed HRS case and the untyped CRS case where we use the arity of a meta-term. The definition and the properties we use later are the well-known ones, also used in [8]. Definition 1. The computable expressions of type A (of some arity) are defined by induction on the structure of A as follows: 1. If s : B with B a base type (with s of arity 0) then s is computable with respect to ≫ if t is WF with respect to ≫ for all t such that s ≫ t. 2. If s is of type A1 → . . . → An → B with B a base type (of arity n), then s is computable with respect to ≫ if for all computable u1 , . . . , un of type A1 , . . . , An we have that s(u1 . . . un ) is computable with respect to ≫. Lemma 1. 1. If s is computable with respect to ≫ then s is WF with respect to ≫. 2. If s is computable with respect to ≫ and s ≫ t then t is computable. 3. If s : B with B a base type (of arity 0) and s′ is computable for every s′ such that s ≫ s′ then s is computable. 4. (HRS case) If s[x := u] is computable for every computable u of the right type, and (x. s) (u) ≫ s[x := u], then x. s is computable. (CRS case) If s[x := u] is computable for every computable u and we have ([x]s) (u) ≫ s[x := u], then [x]s is computable.
4
The higher-order recursive path ordering
This section is concerned with the higher-order version of the recursive path ordering (horpo). Jouannaud and Rubio [8] define horpo for what we call here AFSs. Here we present a method to prove termination of HRSs and a method to prove termination of CRSs. Both methods use an adaption of horpo as in [8]. 4.1
Horpo for HRSs
We assume a quasi-ordering on the base-types that is extended to a well-founded ordering > on types, and a well-founded precedence ⊲ on the function symbols. Definition 2. We have s ≻ t for pre-terms s : A and t : A′ if A ≥ A′ and one of the following clauses holds: 1. s = f (s1 , . . . , sm ) t = g(t1 , . . . , tn ) f ⊲g for all i ∈ {1, . . . , n}: either s ≻ ti or sj ti for some j
6 2. s = f (s1 , . . . , sm ) t = f (t1 , . . . , tm ) (s1 , . . . , sm ) ≻ (t1 , . . . , tm ) for all i ∈ {1, . . . , n}: either s ≻ ti or sj ti for some j 3. s = f (s1 , . . . , sm ) si t for some si 4. s = f (s1 , . . . , sm ) t = t0 (t1 , . . . , tn ) for all i ∈ {1, . . . , n}: either s ≻ ti or sj ti for some j 5. s = x(s1 , . . . , sm ) t = x(t1 , . . . , tm ) si ≻ ti for some i si ti for all i 6. s = s0 (s1 , . . . , sm ) t = t0 (t1 , . . . , tm ) si ≻ ti for some i si ti for all i 7. s = x. s0 t = x. t0 s 0 ≻ t0 The first three clauses are the same as for the first-order case. The difference is that here we need to take care of the types: in order to derive s ≻ t we need that the type of s is larger than or equal to the type of t. The condition ‘for all i ∈ {1, . . . , n} either s ≻ ti or sj ti ’ in the clauses 1, 2, and 4 is to be understood as follows: if ti : A′ with A ≥ A′ then s ≻ t, otherwise ti : B ′ then sj ti for some sj : B with B ≥ B ′ . Note further that in clause 2 we use the notation ≻ also for the multiset or lexicographic (depending on the function symbol f ) extension of the relation ≻ on pre-terms. The clause 4 takes care of substitution. For instance, we have f (x. z(x), a) ≻ z(a) because z(a) =η (x. z(x)) a and we have x. z(x) x. z(x) and f (x. z(x), a) ≻ a. In clause 6 it is assumed that s0 is not (η-equivalent to) a function symbol or a variable and that m ≥ 1. The clauses 2, 5, 6, and 7 make that ≻ is compatible with the structure of pre-terms. One might wish to consider an ordering on terms instead of on pre-terms, using the clauses 1 - 4 of the previous definition where then the term t in clause 4 is to be understood as the β-normal form of t0 (t1 , . . . , tn ). That yields however a relation that is not closed under substitution: Let σ = {z 7→ y. g(y)}. Then we have f (x. z(x), a) ≻ z(a) but not f (x. z(x), a)σ = f (x. g(x), a) ≻ g(a) = z(a)σ if g ⊲ f in the precedence. Therefore horpo is defined on pre-terms, in fact as in [8]. The termination method using horpo is as follows: a HRS is terminating if for every rewrite rule l → r there exists a pre-term r′ such that l ≻ r′ ։β r. We call this the horpo criterion (for HRSs). In the examples we often abbreviate the left-hand side of the rewrite rule under consideration by l and its right-hand side by r. Example 1.
7 1. Consider for example the beta-reduction rule of untyped λ-calculus: app(abs(x. Z(x)), Z ′ ) → Z(Z ′ ) Clause 3 does not yield that abs(x. Z(x)) ≻ x. Z(x) because abs(x. Z(x)) has type T and x. Z(x) has type T → T. 2. The rewrite rule map(x. F (x), cons(h, t)) → cons(F (h), map(x. F (x), t)) of the HRS for map can be shown to be terminating. First we show l ≻ r′ with r′ = cons((x. F (x))(h), map(x. F (x), t)). Let map ⊲ cons and natlist > nat. First, we have x. F (x) x. F (x). Second, because natlist ≥ nat, we can derive map(x. F (x), cons(h, t)) ≻ h. Then it follows from clause 4 that map(x. F (x), cons(h, t)) ≻ (x. F (x))(h). Further, cons(h, t) t and so l ≻ map(x. F (x), t). We conclude that by clause 1 l ≻ r′ . Finally, r′ ։β r. 3. The rewrite rule f (a) → g(x. a) with f : A → A and g : (A → A) → A cannot be shown to be terminating using horpo because there is no subterm in the left-hand side to deal with the subterm x. a of functional type. In the remainder of this section we show that the condition l ≻ r′ ։β r for every rewrite rule indeed guarantees termination of the HRS. We make use of the notion of computability with respect to ≻ ∪ →β . The following lemma follows immediately from the definition of ≻. Lemma 2. If s ≻ t for pre-terms s and t then C[s] ≻ C[t]. The proof of the following lemma makes use of induction on a triple as in [8]. Lemma 3. If s1 , . . . , sm are computable, then f (s1 , . . . , sm ) is computable. Proof. The proof proceeds by induction on triples of the form (f, (s1 , . . . , sm ), n) with f a function symbol, s1 , . . . , sm computable pre-terms, and n a natural number, ordered by (⊲, ≻ ∪ →β , >). This ordering is also written as >. Let s1 , . . . , sm be computable pre-terms. Suppose that f (s1 , . . . , sm ) ≻ t or f (s1 , . . . , sm ) →β t. We show that t is computable. The following cases are distinguished. 1. t = g(t1 , . . . , tn ) with f ⊲ g and for all i ∈ {1, . . . , n}: either s ≻ ti or sj ti for some j. If s ≻ ti , then because (f, (s1 , . . . , sm ), |t|) > (f, (s1 , . . . , sm ), |ti |) we can apply the induction hypothesis and conclude that ti is computable. If sj ti for some j, we have that ti is computable because computability is closed under ≻. So all the ti are computable. Suppose that g(t1 , . . . , tn ) ≻ u or g(t1 , . . . , tn ) →β u. Because we have (f, (s1 , . . . , sm ), |t|) > (g, (t1 , . . . , tn ), |u|), the pre-term u is computable by the induction hypothesis. Hence t is computable.
8 2. t = f (t1 , . . . , tm ) with (s1 , . . . , sm ) ≻ (t1 , . . . , tm ) and for all i ∈ {1, . . . , m}: either s ≻ ti or sj ti for some j. We can show as in the previous case that all ti are computable. Suppose that f (t1 , . . . , tm ) ≻ u or f (t1 , . . . , tm ) →β u. Because we have (f, (s1 , . . . , sm ), t) > (f, (t1 , . . . , tm ), u), the pre-term u is computable. Hence t is computable. 3. si t for some si . Because si is computable with respect to ≻ ∪ →β by assumption, and computability is closed under ≻, also t is computable. 4. t = t0 (t1 , . . . , tn ) with for all i ∈ {1, . . . , n}: either s ≻ ti or sj ti for a j. As before, we can show that all ti are computable. By the definition of computability we have that t is computable. 5. t = f (s1 , . . . , s′i , . . . , sm ) with si →β s′i . Suppose that f (. . . , s′i , . . .) ≻ u or f (. . . , s′i , . . .) →β u. Because we have that (f, (s1 , . . . , sm ), t) > (f, (s1 , . . . , s′i , . . . , sm ), u), it follows from the induction hypothesis that u is computable. This yields that t is computable. Theorem 1. If σ is a computable substitution, then sσ is computable. Proof. By induction on the definition of pre-terms using Lemmas 3 and 1. A consequence of this theorem is that all pre-terms are computable. That means that there is no infinite sequence of pre-terms s0 ≻ ∪ →β s1 ≻ ∪ →β s2 ≻ ∪ →β . . . where every step is either ≻ or →β . Now the aim is to use this to show that there is no infinite sequence of terms s0 → s1 → s2 → . . . with → the rewrite relation of a HRS satisfying the horpo criterion. Lemma 4. Let l → r be a rewrite rule with l ≻ d ։β r for some pre-term d. Let σ be a substitution. Then there exists a pre-term u such that lσ ↓β ≻ u ։β rσ ↓β . Proof. The proof proceeds by induction on |l| + |d|. We distinguish cases according to the definition of ≻. Let l = f (l1 , . . . , lm ). 1. d = g(d1 , . . . , dn ) with f ⊲ g and for all i ∈ {1, . . . , n}: either l ≻ di or lj di for some j. We have r = g(r1 , . . . , rn ) with ri = di ↓β . If l ≻ di then by the induction hypothesis a pre-term ui with lσ ↓β ≻ ui ։β riσ ↓β exists. If lj ri then by the induction hypothesis a pre-term ui with ljσ ↓β ui ։β riσ ↓β exists. σ Hence we have lσ ↓β = f (l1σ ↓β , . . . , lm ↓β ) ≻ g(u1 , . . . , un ) ։β g(r1σ ↓β σ σ , . . . , rn ↓β ) = r ↓β . So take u = g(u1 , . . . , un ). 2. r = f (d1 , . . . , dm ) with (l1 , . . . , lm ) ≻ (d1 , . . . , dm ) and for all i ∈ {1, . . . , n}: either l ≻ di or lj di for some j. We have r = f (r1 , . . . , rm ) with ri = di ↓β . For both the lexicographic and the multiset extension of ≻ the existence of suitable pre-terms ui ’s follows σ from the induction hypothesis. Then we have lσ ↓β = f (l1σ ↓β , . . . , lm ↓β σ σ σ ) ≻ f (u1 , . . . , um ) ։β f (r1 ↓β , . . . , rm ↓β ) = r ↓β . So we take u = f (u1 , . . . , um ).
9 3. li d for some li . We have r = d. By the induction hypothesis there is a pre-term u with liσ ↓β u ։β rσ ↓β . Hence lσ ↓β ≻ u ։β rσ ↓β . 4. d = d0 (d1 , . . . , dn ) with for all i ∈ {1, . . . , n}: either l ≻ di or lj di for some j. We have r = d0 (d1 , . . . , dn ) ↓β . By the induction hypothesis there exist preterms ui such that for every i we have either lσ ↓β ≻ ui ։β ((di ↓β )σ ) ↓β or ljσ ↓β ≻ ui ։β ((di ↓β )σ ) ↓β . σ We have lσ ↓β = f (l1σ ↓β , . . . , lm ↓β ) ≻ u0 (u1 , . . . , un ) ։β rσ ↓β because σ σ r ↓β = ((d0 (d1 , . . . , dn )) ↓β ) ↓β which equals the β-normal form of the pre-term ((d0 ↓β )σ ) ↓β (((d1 ↓β )σ ) ↓β , . . . , ((dn ↓β )σ ) ↓β ). 5. l = x(l1 , . . . , lm ) and d = x(d1 , . . . , dm ) with li ≻ di for some i and li di for all i. Because all li are η-equivalent to different bound variables, we can only have l d because l = d. Then also lσ ↓β dσ ↓β . 6. l = x. l0 and d = x. d0 with l0 ≻ d0 . We have r = x. d0 ↓β . By the induction hypothesis a pre-term u0 exists such that loσ ↓β ≻ u0 ։β dσ0 ↓β . Hence lσ ↓β ≻ x. u0 ։ rσ ↓β . The previous lemma doesn’t hold if the left-hand side of a rewrite rule is not a pattern. Consider for example the would-be rewrite rule f (z(a)) → f (z(b)). We have f (z(a)) ≻ f (z(b)) using the precedence a⊲b. However using the substitution σ = {z 7→ x. a} we do not have f (z(a))σ ↓β = f (a) ≻ f (a) = f (z(b))σ ↓β . Lemma 5. If s → t then there exists a pre-term u such that s ≻ u and u ։β t. Proof. By induction on the definition of the rewrite relation using Lemma 4. Theorem 2. A HRS satisfying the horpo criterion is terminating. Proof. Suppose that we have an infinite rewrite sequence s0 → s1 → s2 → . . .. By Lemma 5 s0 ≻ u0 ։β s1 ≻ u1 ։β s2 . . .. This contradicts Theorem 1. 4.2
Horpo for CRSs
A well-founded precedence ⊲ on the set of function symbols is assumed. Definition 3. We have s ≻ t for meta-terms s and t if s and t have the same arity and one of the following clauses holds: 1. s = f (s1 , . . . , sm ) t = g(t1 , . . . , tn ) f ⊲g for all i ∈ {1, . . . , n}: either s ≻ ti or sj ti for some j 2. s = f (s1 , . . . , sm ) t = f (t1 , . . . , tm ) (s1 , . . . , sm ) ≻ (t1 , . . . , tm ) for all i ∈ {1, . . . , n}: either s ≻ ti or sj ti for some j
10 3. s = f (s1 , . . . , sm ) si ≻ t for some i 4. s = f (s1 , . . . , sm ) t = ti (t1 , . . . , tn ) for all i ∈ {1, . . . , n}: either s ≻ ti or sj ti for some j 5. s = Z(s1 , . . . , sm ) t = Z(t1 , . . . , tm ) for some i: si ≻ ti for all i : si ti 6. s = s0 (s1 , . . . , sm ) t = t0 (t1 , . . . , tm ) for some i: si ≻ ti for all i : si ti 7. s = [x]s0 t = [x]t0 s 0 ≻ t0 The method to prove termination of a CRS is similar to the one for HRSs: a CRS is terminating if for every rewrite rule l → r there exists a meta-term r′ such that l ≻ r′ ։b r. We call this the horpo criterion (for CRSs). Example 2. 1. Consider the beta-reduction rule of untyped λ-calculus: app(abs([x]Z(x)), Z ′ ) → Z(Z ′ ). We do not have abs([x]Z(x)) ≻ [x]Z(x) because abs([x]Z(x)) has arity 0 and [x]Z(x) has arity 1. 2. Consider the following rewrite rule from the CRS for map: map([x]F (x), cons(h, t)) → cons(F (h), map([x]F (x), t)). Note that ([x]F (x))(h) →b F (h). Because [x]F (x) [x]F (x) and moreover l ≻ h, we have map([x]F (x), cons(h, t)) ≻ ([x]F (x))(h). Further, because [x]F (x) [x]F (x) and map([x]F (x), cons(h, t)) ≻ t, we have, using the precedence map⊲cons that map([x]F (x), cons(h, t)) ≻ cons(F (h), map([x]F (x), t)). 3. The rewrite rule f (a) → g([x]a) cannot be shown to be terminating using horpo because there is no subterm in the left-hand side to deal with [x]a which has arity 1. Now we can show that if the horpo criterion indeed guarantees termination of the CRS. We use computability with respect to ≻ ∪ →b . The proofs and auxiliary results are similar to the one for the HRS case. That is, we show the following:
11 • If σ is computable, then sσ is computable. Therefore all meta-terms without meta-variables (but possibly with meta-applications) are computable. The key step is again to show that a meta-term f (s1 , . . . , sm ) is computable if s1 , . . . , sm is computable. This is shown by induction on a triple. • If s → t then there exists a t′ such that s ≻ t′ and t′ ։b t. More details can be found in the appendix. Now we have the following. Theorem 3. A CRS satisfying the horpo criterion is terminating.
5
The general schema
The general schema states conditions on the right-hand side of a rewrite rule that guarantee a termination proof `a la Tait and Girard to work. There occur several incarnations of the general schema in the literature. The first one is due to Jouannaud and Okada [6]. In many later works different versions of the general scheme (depending on the for of the AFS and its typing system) are considered. For instance termination of the calculus of constructions and algebraic rewriting, proved using the general schema, is shown in [1]. In [2] the general scheme is used to prove termination of typed higher-order rewriting systems with a CRS-like syntax, and also a HRS version is given. In this section we present two versions of the general scheme: one for HRSs and one for CRSs. They are more naive than the ones of [2], and closer to the one for AFSs used in [8] (although simpler). 5.1
The general scheme for HRSs
We assume a well-founded ordering ⊲ on the function symbols. Definition 4. Let s = f (s1 , . . . , sm ) and let X be a set of variables not occurring free in s. We have t ∈ C(s, X) for a pre-term t if one of the following clauses holds: 1. t = g(t1 , . . . , tn ) f ⊲g ti ∈ C(s, X) for all i 2. t = f (t1 , . . . , tm ) (s1 , . . . , sm ) ⊃ (t1 , . . . , tn ) ti ∈ C(s, X) for all i 3. t = si for some i 4. t ⊂ si for some i, with t of base type, and all variables of t occur in s 5. t = x ∈ X 6. t = t0 (t1 , . . . , tn ) ti ∈ C(s, X) for all i 7. t = x. t0 t0 ∈ C(s, X ∪ {x}) (x not free in s)
12 The termination method using the general schema works as follows: a HRS is terminating if for every rewrite rule l → r there is a pre-term r′ such that r′ ∈ C(l) and r′ ։β r. We call this the general scheme criterion (for HRSs). Example 3. 1. It is not possible to show that the beta-reduction rule of untyped λ-calculus app(abs(x. Z(x)), Z ′ ) → Z(Z ′ ) is terminating. The pre-term Z(x) is of base-type but contains a free variable (x) that is not free in the left-hand side of the rewrite rule. So clause 4 does not yield that Z(x) ∈ C(app(abs(x. Z(x))), X) for any X. Further note that the variable Z (or its η-expanded form) is not in C(l) because of its type. 2. Using the general schema we can show termination of the rewrite rule map(x. F (x), cons(h, t)) → cons(F (h), map(x. F (x), t)) of the HRS for map. We take r′ = cons((x. F (x))(h), map(x. F (x), t)) We have cons(h, t) ⊃ t. Further x. F (x) ∈ C(l) by clause 3 and t ∈ C(l) by clause 4 This yields that map(x. F (x), t) ∈ C(l). Further, because x. F (x) ∈ C(l) and h ∈ C(l), we have (x. F (x)) h ∈ C(l). Now we conclude by clause 1, using the precedence map ⊲ cons. 3. The rewrite rule f (a) → g(x. a) that cannot be shown to be terminating using horpo, can be shown to be terminating using the general scheme. We have a ∈ C(f (a), {x}) and hence x. a ∈ C(f (a)). Using the precedence f ⊲ g, we can conclude by clause 1 that g(x. a) ∈ C(f (a)). 4. The rewrite rule f (a) → f (b) cannot be shown to be terminating using the general scheme. Note that clause 2 cannot be applied. Using the general scheme as in [2] this rule can be shown to be terminating because b is a constructor. However, if we add for instance the rule b → c so that b is not a constructor, this version of the general scheme cannot be used anymore either. Now we show that the general scheme criterion indeed guarantees termination of the HRS. We use computability with respect to ∪ →β . Here the relation is defined as the smallest one that is closed under pre-term formation, and that contains lσ ↓β lσ for every rewrite rule l → r. Also in [10, 17] such a decomposition of the rewrite step is used to get more grip on the rewrite relation. The aim is to show that all pre-terms are computable with respect to ∪ →β . The development is similar to the one in [8] and consists of the following steps: • If t ∈ C(s) then tσ ∈ C(sσ ). For the case that s is a pattern without βredexes, we have tσ ∈ C(sσ ↓β ).
13 • If s1 , . . . , sm are computable, then f (s1 , . . . , sm ) are computable. We show that t is computable for every t such that f (s1 , . . . , sm ) ∪ →β t. This is done by induction on a pair. In case the reduction takes place in an si , we use the induction hypothesis. In case the reduction takes place at the root, we use the information that r ∈ C(l) for every rewrite rule, and the lemma’s derived from that. • We conclude that all pre-terms are computable with respect to ∪ →β . More details concerning these steps can be found in the appendix. Theorem 4. A HRS satisfying the general scheme criterion is terminating. Proof. A rewrite step s → t can be decomposed as s u ։β t. Because all pre-terms are computable with respect to ∪ →β there are no infinite rewrite sequences. 5.2
The general scheme for CRSs
We assume a well-founded precedence ⊲ on the set of function symbols. Definition 5. Let s = f (s1 , . . . , sm ) and let X be a set of variables not occurring in s. We have t ∈ C(s, X) if one of the following clauses hold: 1. t = g(t1 , . . . , tn ) f ⊲g ti ∈ C(s, X) for all i 2. t = f (t1 , . . . , tm ) (s1 , . . . , sm ) ⊃ (t1 , . . . , tm ) ti ∈ C(s, X) 3. t = si for some i 4. t ⊂ si for some i, all variables in t occur in s, and t is of arity 0 5. t = x ∈ X 6. t = t0 (t1 , . . . , tn ) ti ∈ C(s, X) for all i 7. t = [x]t0 t0 ∈ C(s, X ∪ {x}) Note that we do not include b-reduction. The termination method using the general scheme is as follows: A CRS is terminating if for every rewrite rule l → r there is a meta-term r′ such that r′ ∈ C(l) and r′ ։b r. We call this the general scheme criterion (for CRSs). Example 4. 1. Consider the beta-reduction rule for untyped λ-calculus: app(abs([x]Z(x)), Z ′ ) → Z(Z ′ ). Clause 4 does not yield that [x]Z(x) ∈ C(app(abs([x]Z(x)), Z ′ )) because [x]Z(x) has arity 1. Also we do not have Z ∈ C(app(abs([x]Z(x)), Z ′ )). Further, clause 4 does not yield that Z(x)C(app(abs([x]Z(x)), Z ′ )) because the variable x is not free in app(abs([x]Z(x)), Z ′ ).
14 2. Consider the rewrite rule map([x]F (x), cons(h, t)) → cons(F (h), map([x]F (x), t)) from the CRS for map. We take r′ = cons([x]F (x)(h), map([x]F (x), t)). We can derive that r′ ∈ C(l). 3. Consider the rewrite rule f (z) → g([x]a). We have a ∈ C(f (a), {x}) and hence [x]a ∈ C(f (a)). Take r′ = g([x]a), then r′ ∈ C(f (a)). This rule cannot be shown to be terminating using horpo. 4. Consider the rewrite rule f ([x]Z(x)) → Z([y]y) We take r′ = [x]Z(x)([y]y). We have y ∈ C(f ([x]Z(x)), {y}) and hence [y]y ∈ C(f ([x]Z(x))). Because also [x]Z(x) ∈ C(f ([x]Z(x))) we have Z([y]y) ∈ C(f ([x]Z(x))). We show that the general scheme criterion indeed guarantees termination of a CRS. We consider computability with respect to ∪ →b where the is defined as the smallest relation that is closed under term formation and that satisfies: lσ ↓b rσ for every rewrite rule l → r. The steps are similar to the ones for the HRS case and can be found in the appendix. Theorem 5. A CRS satisfying the general scheme criterion is terminating.
References 1. F. Barbanera, M. Fern´ andez, and H. Geuvers. Modularity of strong normalization in the algebraic lambda-cube. Jounal of Functional Programming, 7(6):613–660, 1997. An earlier version appears in the Proceedings of LICS ’94. 2. F. Blanqui. Termination and confluence of higher-order rewrite systems. In L. Bachmair, editor, Proceedings of the 10th International Conference on Rewriting Techniques and Applications (RTA ’99), number 1833 in LNCS, pages 47–62, Norwich, UK, July 2000. Springer Verlag. 3. N. Dershowitz. Orderings for term rewriting systems. Theoretical Computer Science, 17(3):279–301, 1982. 4. R.O. Gandy. Proofs of strong normalization. In J.R. Hindley and J.P Seldin, editors, To H.B. Curry: Essays on Combinatory Logic, Lambda Calculus and Formalism. Academic Press, London, 1980. 5. G. Huet and D.C. Oppen. Equations and rewrite rules: A survey. In R.V Book, editor, Formal Language Theory: Perspectives and Open Problems, pages 349–405. Academic Press, London, 1980. 6. J.-P. Jouannaud and M. Okada. A computation model for executable higherorder algebraic specification languages. In Proceedings of the 6th annual IEEE Symposium on Logic in Computer Science (LICS ’91), pages 350–361, Amsterdam, The Netherlands, July 1991. journal version ?
15 7. J.-P. Jouannaud and A. Rubio. A recursive path ordering for higher-order terms in η-long β-normal form. In H. Gantzinger, editor, Proceedings of the 7th International Conference on Rewriting Techniques and Applications (RTA ’96), number 1103 in LNCS, pages 108–122, New Brunswick, USA, July 1996. Springer Verlag. 8. J.-P. Jouannaud and A. Rubio. The higher-order recursive path ordering. In Proceedings of the 14th annual IEEE Symposium on Logic in Computer Science (LICS ’99), pages 402–411, Trento, Italy, July 1999. 9. S. Kahrs. Towards a domain theory for termination proofs. In J. Hsiang, editor, Proceedings of the 6th International Conference on Rewriting Techniques and Applications (RTA ’95), number 914 in LNCS, pages 241–255, Kaiserslautern, Germany, April 1995. Springer Verlag. 10. J.W. Klop. Combinatory Reduction Systems. Number 127 in Mathematical Centre Tracts. CWI, Amsterdam, The Netherlands, 1980. PhD Thesis. 11. J.W. Klop, V. van Oostrom, and F. van Raamsdonk. Combinatory Reduction Systems: introduction and survey. Theoretical Computer Science, 121:279–308, 1993. Special issue in honour of Corrado B¨ ohm. 12. C. Loria-Saenz and J. Steinbach. Termination of combined (rewrite and lambdacalculus) systems. In M. Rusinowitch and J.-L. R´emy, editors, Proceedings of the 3rd International Workshop on Conditional Term Rewriting Systems (CTRS ’92), number 656 in LNCS, pages 143–147, Pont-` a-Mousson, France, April 1993. Springer Verlag. 13. O. Lysne and J. Piris. A termination ordering for higher order rewrite systems. In J. Hsiang, editor, Proceedings of the 6th International Conference on Rewriting Techniques and Applications (RTA ’95), number 914 in LNCS, pages 26–40, Kaiserslautern, Germany, April 1995. Springer Verlag. 14. R. Mayr and T. Nipkow. Higher-order rewrite systems and their confluence. Theoretical Computer Science, 192:3–29, 1998. 15. D. Miller. A logic programming language with lambda-abstraction, function variables, and simple unification. Journal of Logic and Computation, 1(4):497–536, 1991. 16. T. Nipkow. Higher-order critical pairs. In Proceedings of the 6th annual IEEE Symposium on Logic in Computer Science (LICS ’91), pages 342–349, Amsterdam, The Netherlands, July 1991. 17. V. van Oostrom. Higher-order families. In H. Gantzinger, editor, Proceedings of the 7th International Conference on Rewriting Techniques and Applications (RTA ’96), number 1103 in LNCS, pages 392–407, New Brunswick, USA, July 1996. Springer Verlag. 18. J.C. van de Pol. Termination of higher-order rewrite systems. PhD thesis, Utrecht University, Utrecht, The Netherlands, December 1996. 19. F. van Raamsdonk. Higher-order rewriting. In P. Narendran and M. Rusinowitch, editors, Proceedings of the 9th International Conference on Rewriting Techniques and Applications (RTA ’99), number 1631 in LNCS, pages 220–239, Trento, Italy, July 1999. Springer Verlag. 20. D.A. Wolfram. The Clausal Theory of Types, volume 21 of Cambridge Tracts in Theoretical Computer Science. Cambridge University Press, 1993. 21. H. Zantema. Termination of term rewriting: interpretation and type elimination. Journal of Symbolic Computation, 17:23–50, 1994.
Appendix
16
A
The recursive path ordering
This section is concerned with the special case of first-order term rewriting. A well-founded precedence ⊲ on the set of function symbols is assumed. The recursive path ordering (rpo) due to Dershowitz [3] is defined as follows. Definition 6. We have s ≻ t if one of the following clauses holds: 1. s = f (s1 , . . . , sm ) for some m ≥ 0 t = g(t1 , . . . , tn ) f ⊲g s ≻ ti for all i ∈ {1, . . . , n} 2. s = f (s1 , . . . , sm ) for some m ≥ 0 t = f (t1 , . . . , tm ) (s1 , . . . , sm ) ≻ (t1 , . . . , tn ) s ≻ ti for all i ∈ {1, . . . , m} 3. s = f (s1 , . . . , sm ) for some m > 0 si ≻ t for some i ∈ {1, . . . , m} or si = t for some i ∈ {1, . . . , m} Note that we also use the notation ≻ for the lexicographic and multiset extension of ≻; moreover, we assume that it is clear from the context which extension is to be taken. The termination method using rpo works as follows: show that l ≻ r for every rewrite rule l → r. This yields termination of the term rewriting system because, first, s → t implies s ≻ t, and second, rpo is well-founded. Here we only show well-foundedness (WF). We make use of the following basic observation. Lemma 6. If t is WF for every t such that s ≻ t, then s is WF. The crucial step in the proof that all terms are WF is to show that f (s1 , . . . , sm ) is WF if s1 , . . . , sm are WF. This step is expressed in the following lemma. Its proof is a special case of the one presented in [8], and proceeds by induction on a triple. We write |t| for the number of symbols in t. Lemma 7. If s1 , . . . , sm are WF and f (s1 , . . . , sm ) ≻ t, then t is WF. Proof. The proof proceeds by induction on triples of the form (f, (s1 , . . . , sm ), n) with f a function symbol, s1 , . . . , sm WF terms, and n a natural number, ordered by (⊲, ≻, >). By well-known results the multiset or lexicographic extension of ≻ is WF on tuples with WF elements. Let s = f (s1 , . . . , sm ) with s1 , . . . , sm WF, and assume that s ≻ t. We show that t is WF by induction on (f, (s1 , . . . , sm ), |t|). Three cases are distinguished, according to the definition of ≻. 1. t = g(t1 , . . . , tn ) with f ⊲ g and f (s1 , . . . , sm ) ≻ ti for all i. Since (f, (s1 , . . . , sm ), |t|) > (f, (s1 , . . . , sm ), |ti |), the terms ti are by the induction hypothesis WF. Suppose that f (t1 , . . . , tm ) ≻ u. Because we have (f, (s1 , . . . , sm ), |t|) > (g, (t1 , . . . , tn ), |u|), the term u is WF by the induction hypothesis. Then by Lemma 6 we have that t = g(t1 , . . . , tn ) is WF.
17 2. t = f (t1 , . . . , tm ) with (s1 , . . . , sm ) ≻ (t1 , . . . , tm ) and f (s1 , . . . , sm ) ≻ ti for all i. As in the previous case we have that all ti are WF by the induction hypothesis because (f, (s1 , . . . , sm ), |t|) > (f, (s1 , . . . , sm ), |ti |). Suppose that f (t1 , . . . , tm ) ≻ u. Because (f, (s1 , . . . , sm ), |t|) > (f, (t1 , . . . , tm ), |u|) we have that u is WF by the induction hypothesis. Then by Lemma 6 t is WF. 3. sj t for some j. Because sj is WF and well-foundedness is closed under ≻, the term t is WF. Theorem 6. All terms are WF. Proof. By induction on the definition of terms, using Lemma 7.
B
Horpo for CRSs
Lemma 8. If s ≻ t for meta-terms s and t then C[s] ≻ C[t]. Proof. Immediate from the definition on ≻. Lemma 9. If s1 , . . . , sm are computable, then f (s1 , . . . , sm ) is computable. Proof. The proof proceeds by induction on triples of the form (f, (s1 , . . . , sm ), n) with f a function symbol, s1 , . . . , sm computable meta-terms, and n a natural number, ordered by (⊲, ≻ ∪ →b , >). This ordering is also written as >. Let s1 , . . . , sm be computable meta-terms. Suppose that f (s1 , . . . , sm ) ≻ t or f (s1 , . . . , sm ) →b t. We show that t is computable. The following cases are distinguished. 1. s = f (s1 , . . . , sm ) and t = g(t1 , . . . , tn ) with f ⊲ g and for all i ∈ {1, . . . , n}: either s ≻ ti or sj ti for some j. If s ≻ ti , then because (f, (s1 , . . . , sm ), |t|) > (f, (s1 , . . . , sm ), |ti |) we can apply the induction hypothesis and conclude that ti is computable. If sj ti for some j, we have that ti is computable because computability is closed under ≻. So all the ti are computable. Suppose that g(t1 , . . . , tn ) ≻ u or g(t1 , . . . , tn ) →b u. Because we have (f, (s1 , . . . , sm ), |t|) > (g, (t1 , . . . , tn ), |u|), the meta-term u is computable by the induction hypothesis. Hence t is computable. 2. s = f (s1 , . . . , sm ) and t = f (t1 , . . . , tm ) with (s1 , . . . , sm ) ≻ (t1 , . . . , tm ) and for all i ∈ {1, . . . , n}: either s ≻ ti or sj ti for some j. We can show as in the previous case that all ti are computable. Suppose that f (t1 , . . . , tm ) ≻ u or f (t1 , . . . , tm ) →b u. Because we have (f, (s1 , . . . , sm ), t) > (f, (t1 , . . . , tm ), u), the meta-term u is computable. So also t is computable. 3. s = f (s1 , . . . , sm ) with si ≻ t for some i Because si is computable and computability is closed under ≻, also t is computable.
18 4. s = f (s1 , . . . , sm ) and t = ti (t1 , . . . , tn ) with for all i ∈ {1, . . . , n}: either s ≻ ti or sj ti for some j. As before, we can show that all ti are computable. By the definition of computability, t is computable. 5. t = f (s1 , . . . , s′i , . . . , sm ) with si →b s′i . Suppose that f (. . . , s′i , . . .) ≻ u or f (. . . , s′i , . . .) →b u. Because we have that (f, (s1 , . . . , sm ), t) > (f, (s1 , . . . , s′i , . . . , sm ), u), it follows from the induction hypothesis that u is computable. This yields that t is computable. Theorem 7. If σ is a computable substitution, then sσ is computable. Proof. By induction on the definition of meta-terms using Lemma 9. 1. s = x. Then sσ = x is computable. 2. s = f (s1 , . . . , sm ). By the induction hypothesis sσ1 , . . . , sσm are computable. Then by Lemma 9 sσ is computable. 3. s = [x]s0 . Let u be a computable meta-term. We need to show that ([x]s0 )σ u is computable. By the induction hypothesis, sσ0 is computable. We use Lemma 1. 4. s = Z(s1 , . . . , sm ). By assumption σ(Z) is computable. By the induction hypothesis all sσi are computable. Hence σ(Z)(sσ1 , . . . , sσm ) is computable. 5. s = s0 (s1 , . . . , sm ). By the induction hypothesis all sσi are computable. Hence by the definition of computability sσ is computable. Theorem 8. If σ is computable then sσ is computable. Proof. By induction on the definition of meta-terms, using Lemma 9. As a consequence, all meta-terms without meta-variables but possibly containing meta-applications are computable. Lemma 10. Let l → r be a rewrite rule with l ≻ d ։b r for some meta-term d. Let σ be a substitution. Then there exists a meta-term u such that lσ ≻ u ։b rσ . Proof. The proof proceeds by induction on |l| + |d|. We distinguish cases according to the definition of ≻. Let l = f (l1 , . . . , lm ). 1. d = g(d1 , . . . , dn ) with f ⊲ g and for all i ∈ {1, . . . , n}: either l ≻ di or lj di for some j. We have r = g(r1 , . . . , tn ) with ri = di ↓b . If l ≻ di then by the induction hypothesis there exists a meta-term ui such that lσ ≻ ui ։b riσ . If lj di then by the induction hypothesis a meta-term ui with ljσ ui ։b riσ exists. σ Hence we have lσ = f (l1σ , . . . , lm ) ≻ g(u1 , . . . , un ) ։b g(r1σ , . . . , rnσ ) = rσ . So take u = g(u1 , . . . , un ).
19 2. r = f (r1 , . . . , rm ) with (l1 , . . . , lm ) ≻ (r1 , . . . , rm ) and for all i ∈ {1, . . . , n}: either l ≻ ri or lj ri for some j. For both the lexicographic and the multiset extension of ≻ the existence of suitable meta-terms ui ’s follows from the induction hypothesis. Then we σ σ have lσ = f (l1σ , . . . , lm ) ≻ f (u1 , . . . , um ) ։b f (r1σ , . . . , rm ) = rσ . So we take u = f (u1 , . . . , um ). 3. li d for some li . By the induction hypothesis there is a meta-term u with liσ ui ։b rσ . Hence lσ ≻ uσi ։b rσ . 4. d = d0 (d1 , . . . , dn ) with for all i ∈ {1, . . . , n}: either l ≻ di or lj di for some j By the induction hypothesis there exist meta-terms ui such that for every i we have either lσ ≻ ui ։b di ↓σb ↓b or ljσ ≻ ui ։b di ↓σb ↓b . We have lσ = σ f (l1σ , . . . , lm ) ≻ u0 (u1 , . . . , un ) ։b rσ ↓b by commutation of substitution and b-reduction. 5. l = Z(x, . . . , xm ) d = Z(d1 , . . . , dm ) li ≻ di for some i li di for all i We have di = xi and hence lσ rσ . 6. l = [x]l0 d = [x]d0 l0 ≻ d0 We have r = [x]r0 with r0 = d0 ↓b . By the induction hypothesis there exists a meta-term u0 such that l0σ ≻ u0 ։b r0σ . Take u = [x]u0 . Lemma 11. If s → t then there exists a u such that s ≻ u and t′ ։b t. Proof. The proof proceeds by induction on the definition of the rewrite relation. 1. Suppose s = f (. . . , si , . . .) and t = f (. . . , ti , . . .) with ti → t′i . By the induction hypothesis a meta-term ui exists such that si ≻ ui ։b ti . Take u = f (. . . , ui , . . .). 2. Suppose s = [x]s0 and t = [x]t0 with s0 → t0 . By the induction hypothesis a meta-term u0 exists such that so ≻ u0 ։b t0 . Take u = [x]u0 . 3. Suppose that s = lσ and t = rσ with l → r a rewrite rule and σ a substitution. We use Lemma 10. Theorem 9. A CRS satisfying the horpo criterion is terminating. Proof. A rewrite step s → t can be decomposed into s ≻ u ։b t. The decomposition involves meta-terms without meta-variables, which are computable. Hence there are no infinite rewrite sequences.
C
The general scheme for HRSs
Lemma 12. Let l = f (l1 , . . . , lm ) be a pattern and suppose that r ∈ C(l). Then rσ ∈ C(lσ ).
20 Proof. The proof proceeds by induction on r, distinguishing different cases according to the definition of the computable closure. 1. r = g(r1 , . . . , rn ) with f ⊲ g and ri ∈ C(l, X) for all i. By the induction hypothesis riσ ∈ C(lσ , X). This yields that rσ ∈ C(lσ , X). 2. r = f (r1 , . . . , rm ) with (l1 , . . . , lm ) ⊃ (r1 , . . . , rn ) and ri ∈ C(l, X) for all i. By the induction hypothesis riσ ∈ C(lσ , X). Note that substitution is used here without it being followed by a reduction to β-normal form. Hence σ σ (l1σ , . . . , lm ) ⊃ (r1σ , . . . , rm ) . This yields that rσ ∈ C(lσ , X). 3. r = li for some i. rσ = liσ and hence rσ ∈ C(lσ , X). 4. r ⊂ li with r of base type and all variables in r occur in l We have that rσ is of base type, and also that all variables of rσ occur in lσ . Further rσ ⊂ lσ hence rσ ∈ C(lσ , X). 5. r = x with x ∈ C(l, X) (x not free in l). The variables in X are assumed to be disjoint from the domain of σ. Hence rσ = x, and x ∈ C(lσ , X). 6. r = r0 (r1 , . . . , rn ) with ri ∈ C(l, X) for all i. By the induction hypothesis we have riσ ∈ C(lσ X). So rσ ∈ C(lσ , X). 7. r = x. r0 with r0 ∈ C(l, X ∪ {x}). By the induction hypothesis we have r0σ ∈ C(lσ , X ∪ {x}). We may assume that the variables introduced by σ do not occur in X. Then x. r0σ = rσ ∈ C(lσ X). Lemma 13. If l is the left-hand side of a rewrite rule, and t ∈ C(lσ ), then t ∈ C(lσ ↓β ). Proof. Free variables in l occur in the form z(x1 , . . . , xm ) with x1 , . . . , xm distinct bound variables. Because l is moreover a term, all β-redexes in lσ are of the form x1 . . . xm . s (y1 , . . . , ym ). We inspect the definition of C(C). Lemma 14. Let s = f (s1 , . . . , sm ) and suppose that s1 , . . . , sm are computable. Suppose that if t1 , . . . , tn are computable and (f, (s1 , . . . , sm )) > (g, (t1 , . . . , tn )) then we have that g(t1 , . . . , tn ) is computable. Here >= (⊲, ∪ →β ∪ ⊃). Then: if t ∈ C(s) then t is computable with respect to ∪ →β . Proof. Let t ∈ C(s, X). We show that tσ is computable for every computable substitution σ. The proof proceeds by induction on t. We distinguish cases according to the definition of C. 1. t = g(t1 , . . . , tn ) with f ⊲ g and ti ∈ C(s, X) for all i. By the induction hypothesis all tσi are computable. Hence by the assumption g(tσ1 , . . . , tσn ) is computable, because (f, (s1 , . . . , sm )) > (g, (tσ1 , . . . , tσn )). 2. t = f (t1 , . . . , tm ) with (s1 , . . . , sm ) ⊃ (t1 , . . . , tm ) and ti ∈ C(s, X) for all i. By the induction hypothesis all ti σ are computable. The variables in X are disjunct from those in s. If (s1 , . . . , sm ) ⊃ (t1 , . . . , tm ) , then σ doesn’t change the ti . Hence (f, (s1 , . . . , sm )) > (g, (tσ1 , . . . , tσm )), which yields that tσ is computable.
21 3. t = si . Again σ doesn’t change t, and hence t is by assumption computable 4. ti is a subterm of base type some si . Because sσi is computable also its subterms of base type are computable. 5. t = x ∈ X. We have that tσ is computable because σ is computable. 6. t = t0 (t1 , . . . , tn ) with ti ∈ C(s, X) for all i. By the induction hypothesis all tσi are computable. By the definition of computability tσ is computable. 7. t = x. t0 with t0 ∈ C(s, X ∪ {x}). By the induction hypothesis tσ0 is computable. Let u be a computable term. We need to show that (x. tσ0 ) u is computable. By the induction hypothe′ sis tσ0 with σ ′ = σ ∪ {x 7→ u} is computable. Now we use a property of computability. Lemma 15. Suppose that the general scheme criterion is satisfied. If s1 , . . . , sm are computable, then f (s1 , . . . , sm ) is computable. Proof. The proof proceeds by induction on pairs of the form (f, (s1 , . . . , sm )) with f a function symbol and s1 , . . . , sm computable terms, ordered by (⊲, ∪ →β ∪ ⊃). This ordering is also written as >. Suppose that s1 , . . . , sm are computable and that f (s1 , . . . , sm ) ∪ →β t. We show that t is computable. 1. Suppose that t = f (. . . , s′i , . . .) with si ∪ →β s′i . Since (f, (. . . , si , . . .)) > ′ (f, (. . . , si , . . .)) we have by the induction hypothesis that t is computable. 2. Suppose that s = lσ ↓β and t = rσ for a rewrite rule l → t and a substitution σ. Because of the general scheme criterion, we have r ∈ C(l). By Lemma 12 this yields that rσ ∈ C(lσ ). Applying Lemma 13 gives rσ ∈ C(lσ ↓β ). Now we conclude by Lemma 14 that rσ is computable. Theorem 10. If σ is a computable substitution, then sσ is computable. Proof. By induction on the definition of pre-terms, using Lemma 15.
D
The general scheme for CRSs
Lemma 16. Let l = f (l1 , . . . , lm ) be a pattern and suppose that r ∈ C(l). Then rσ ∈ C(lσ ). Proof. The proof proceeds by induction on r, distinguishing different cases according to the definition of the computable closure. 1. t = g(t1 , . . . , tn ) with f ⊲ g and ti ∈ C(s, X) for all i. By the induction hypothesis riσ ∈ C(lσ , X). This yields that rσ ∈ C(lσ , X). 2. t = f (t1 , . . . , tm ) with (s1 , . . . , sm ) ⊃ (t1 , . . . , tm ) and ti ∈ C(s, X). σ σ By the induction hypothesis riσ ∈ C(lσ , X). Hence (l1σ , . . . , lm ) ⊃ (r1σ , . . . , rm ) σ σ . This yields that r ∈ C(l , X).
22 3. t = si for some i. rσ = liσ and hence rσ ∈ C(lσ , X). 4. t ⊃ si for some i, all variables in t occur in s, and t is of arity 0. We have that rσ is of arity 0, and also that all variables of rσ occur in lσ . Further rσ ⊂ lσ hence rσ ∈ C(lσ , X). 5. t = x ∈ X. The variables in X are assumed to be disjoint from the domain of σ. Hence rσ = x, and x ∈ C(lσ , X). 6. t = t0 (t1 , . . . , tn ) with ti ∈ C(s, X) for all i. By the induction hypothesis we have riσ ∈ C(lσ X). So rσ ∈ C(lσ , X). 7. t = [x]t0 with t0 ∈ C(s, X ∪ {x}). By the induction hypothesis we have r0σ ∈ C(lσ , X ∪ {x}). We may assume that the variables introduced by σ do not occur in X. Then x. r0σ = rσ ∈ C(lσ X). Lemma 17. If l is the left-hand side of a rewrite rule, and t ∈ C(lσ ), then t ∈ C(lσ ↓b ). Lemma 18. Let s = f (s1 , . . . , sm ) and suppose that s1 , . . . , sm are computable. Suppose that if t1 , . . . , tn are computable and (f, (s1 , . . . , sm )) > (g, (t1 , . . . , tn )) then we have that g(t1 , . . . , tn ) is computable. Here >= (⊲, ∪ →b ∪ ⊃). Then: if t ∈ C(s) then t is computable with respect to ∪ →b . Proof. Let t ∈ C(s, X). We show that tσ is computable for every computable substitution σ. The proof proceeds by induction on t. We distinguish cases according to the definition of C. t = g(t1 , . . . , tn ) with f ⊲ g and ti ∈ C(s, X) for all i. By the induction hypothesis all tσi are computable. Hence by the assumption σ g(t1 , . . . , tσn ) is computable, because (f, (s1 , . . . , sm )) > (g, (tσ1 , . . . , tσn )). t = f (t1 , . . . , tm ) with (s1 , . . . , sm ) ⊃ (t1 , . . . , tm ) and ti ∈ C(s, X). By the induction hypothesis all ti σ are computable. The variables in X are disjunct from those in s. If (s1 , . . . , sm ) ⊃ (t1 , . . . , tm ) , then σ doesn’t change the ti . Hence (f, (s1 , . . . , sm )) > (g, (tσ1 , . . . , tσm )), which yields that tσ is computable. t = si for some i Again σ doesn’t change t, and hence t is by assumption computable. t ⊃ si for some i, all variables in t occur in s, and t is of arity 0. Because sσi is computable also its 0-ary subterms are computable. t = x ∈ X. We have that tσ is computable because σ is computable. t = t0 (t1 , . . . , tn ) with ti ∈ C(s, X) for all i. By the induction hypothesis all tσi are computable. By the definition of computability tσ is computable. t = [x]t0 with t0 ∈ C(s, X ∪ {x}). By the induction hypothesis tσ0 is computable. Let u be a computable term. ′ We need to show that (x. tσ0 ) u is computable. By the induction hypothesis tσ0 with σ ′ = σ ∪ {x 7→ u} is computable. Now we use a property of computability.
23 Lemma 19. Suppose that the general scheme criterion is satisfied. If s1 , . . . , sm are computable, then f (s1 , . . . , sm ) is computable. Proof. The proof proceeds by induction on pairs of the form (f, (s1 , . . . , sm )) with f a function symbol and s1 , . . . , sm computable terms, ordered by (⊲, ∪ →b ∪ ⊃). This ordering is also written as >. Suppose that s1 , . . . , sm are computable and that f (s1 , . . . , sm ) ∪ →b t. We show that t is computable. 1. Suppose that t = f (. . . , s′i , . . .) with si ∪ →b s′i . Since (f, (. . . , si , . . .)) > ′ (f, (. . . , si , . . .)) we have by the induction hypothesis that t is computable. 2. Suppose that s = lσ ↓b and t = rσ for a rewrite rule l → t and a substitution σ. Because of the general scheme criterion, we have r ∈ C(l). By Lemma 16 this yields that rσ ∈ C(lσ ). Applying Lemma 17 gives rσ ∈ C(lσ ↓b ). Now we conclude by Lemma 18 that rσ is computable. Theorem 11. If σ is a computable substitution, then sσ is computable. Proof. By induction on the definition of meta-terms, using Lemma 19.