scieee AI-readable full text Open interactive document viewer

The computability path ordering

Blanqui, Frédéric,Jouannaud, Jean Pierre,Rubio Gimeno, Alberto

Abstract

This paper aims at carrying out termination proofs for simply typed higher-order calculi automatically by using ordering comparisons. To this end, we introduce the computability path ordering (CPO), a recursive relation on terms obtained by lifting a precedence on function symbols. A first version, core CPO, is essentially obtained from the higher-order recursive path ordering (HORPO) by eliminating type checks from some recursive calls and by incorporating the treatment of bound variables as in the com-putability closure. The well-foundedness proof shows that core CPO captures the essence of computability arguments ^#224, la Tait and Girard, therefore explaining its name. We further show that no further type check can be eliminated from its recursive calls without loosing well-foundedness, but for one for which we found no counterexample yet. Two extensions of core CPO are then introduced which allow one to consider: the first, higher-order inductive types; the second, a precedence in which some function symbols are smaller than application and abstraction.

Full text

arXiv:1506.03943v1 [cs.LO] 12 Jun 2015 THE COMPUTABILITY PATH ORDERING FRÉDÉRIC BLANQUI, JEAN-PIERRE JOUANNAUD, AND ALBERT RUBIO INRIA, Deducteam, France École Polytechnique, LIX, and Université Paris-Sud, France Technical University of Catalonia, Spain Abstract. This paper aims at carrying out termination proofs for simply typed higherorder calculi automatically by using ordering comparisons. To this end, we introduce the computability path ordering (CPO), a recursive relation on terms obtained by lifting a precedence on function symbols. A first version, core CPO, is essentially obtained from the higher-order recursive path ordering (HORPO) by eliminating type checks from some recursive calls and by incorporating the treatment of bound variables as in the computability closure. The well-foundedness proof shows that core CPO captures the essence of computability arguments à la Tait and Girard, therefore explaining its name. We further show that no more type checks can be eliminated from its recursive calls without loosing well-foundedness, but for one for which we found no counter-example yet. Two extensions of core CPO are then introduced which allow one to consider: the first, higher-order inductive types; the second, a precedence in which some function symbols are smaller than application and abstraction. 1. Introduction This paper addresses the problem of automating termination proofs for typed higher-order calculi by reducing them to ordering comparisons between lefthand and righthand sides of rules. It also addresses another, more fundamental problem of mathematical importance. Consider the set of terms generated by a denumerable set of variables, application, abstraction and some set of function symbols with arities, our version of the pure λ-calculus. We shall use a (possibly infinite) set Rof pairs of λ-terms called rewrite rules used as our computing device. Given a term as input, whether our computing device will eventually terminate and return an answer is in general undecidable, even if Ris a singleton set [31]. It may even be undecidable for specific rewrite systems, such as the well-known β-reduction rule (formally defined here as the infinite set of its instances). A major question is the following: can we approximate the set of β-terminating terms by some meaningful subset ? An important answer was given by Turing: the set of simply typed λ-terms, where the word simply refers Frédéric Blanqui thanks the Institute of Software of the Chinese Academy of Sciences for hosting him from June 2012 to August 2013. This research was supported by the Spanish MINECO under grant TIN2013- 45732-C4-3-P. LOGICAL METHODS IN COMPUTER SCIENCE DOI:10.2168/LMCS-??? © Frédéric Blanqui, Jean-Pierre Jouannaud, and Albert Rubio Creative Commons 1 2 FRÉDÉRIC BLANQUI, JEAN-PIERRE JOUANNAUD, AND ALBERT RUBIO to a specific typing discipline introduced by Church in the λ-calculus [24]. This was further generalized by considering more rules (η-reduction, recursors, general schema), and more terms characterized by more elaborate type disciplines (polymorphic, dependent, inductive type systems). When considering β-reduction alone, the obtained approximations of the set of terminating λ-terms are quite satisfactory. But proving the corresponding statement that computations terminate when given a typed λ-term as input, requires using an extremely powerful technique called reducibility1, introduced by Tait for simply typed terms, and further developed by Girard for the richer type disciplines. Given a set of terms and a set of rewrite rules R, a reducibility predicate is defined by axioms that it should satisfy, mainly closure under term constructions, closure under rewriting with R, and containment in the set of terminating terms. Girard exhibited a particular predicate for β-reduction which can be easily adapted for other sets of rules, but there are indeed sets of rules for which some typable terms originate an infinite computation. We therefore turn to a new undecidable question: which sets of rules admit a computability predicate ? The question we answer in this paper is whether this set S(of sets Rof rules) admits some non-trivial decidable subset: our approximation of Sis the set of sets Rof rules such that pairs in Rare ordered by (some instance of) the computability path ordering CPO. The work itself takes its roots in early attempts by Breazu-Tannen and Gallier [23] and independently Okada [75] to consider mixed typed λ-calculi with algebraic rewriting. Both works used Girard’s computability predicates method to show that the strong normalization property of algebraic rewriting was preserved in the union. These results grew into a whole new area, by extending the type discipline on the one hand, and the kind of rules that could be taken care of on the other hand. The type discipline was extended independently by Barbanera and Dougherty in order to cover the whole calculus of constructions [3, 37], while the rule format was extended as described next. Higher-order rewrite rules satisfying the general schema, a generalization of Gödel’s primitive recursion rules for higher types, were introduced by Jouannaud and Okada in the case of a polymorphic type discipline [54, 55]. The latter work was then extended first by Barbanera and Fernández [5, 4] and finally by Barbanera, Fernández and Geuvers to cover the whole calculus of constructions [6]. Recursors for basic inductive types, which constructors admit arguments of a non-functional type only, could be taken care of by the general schema, but arbitrary strictly positive inductive types could not, prompting for an extension of the schema, which was reformulated for that purpose by Blanqui, Jouannaud and Okada [15]. This new formulation was based on the notion of computability closure of a term f( t), defined as a set of terms containing  tand closed under computability preserving operations in the sense of Tait and Girard. Membership to the general schema was then defined for an arbitrary rewrite rule as membership of its righthand side to the computability closure of its lefthand side. This elegant, flexible and powerful definition of the general schema was finally extended by Blanqui in a series of papers, until it covered the entire calculus of inductive constructions including strong elimination rules [10, 11], rewriting modulo some equational theories and rewriting with higher-order pattern-matching [14]. Introduced by Jouannaud and Rubio, HORPO was the next step, the very first order on simply typed λ-terms defined by induction on the term structure, as does Dershowitz recursive path ordering for first-order terms [33]. Comparing two terms with HORPO starts 1In fact, Tait speaks of “convertibility” in [80], realizability in [81]; and Girard of “réductibilité” and ”reducibility” in [42, 43, 44]. Following Gödel, “computability” is used by Troelstra in [85], p. 100. THE COMPUTABILITY PATH ORDERING 3 by comparing their types in a given well-founded ordering on types before to proceed recursively on the structure of the compared terms, in a way which depends on a comparison of the roots of both terms in a given well-founded order on the algebraic signature called the precedence [56]. HORPO was extended to the calculus of constructions by Walukiewicz [87], and to use semantic interpretations of terms instead of a precedence on function symbols by Borralleras and Rubio [21]. An axiomatic presentation of the rules underlying HORPO can be found in [45]. A more recent work in the same direction is [34]. A more general version of HORPO appears in [57], which uses the computability closure to strengthen its expressivity. Blanqui proved that the first version of HORPO is contained in an order defined as a fixpoint of the computability closure definition [12]. Indeed, HORPO and the computability closure share many similar constructs, raising expectations for a simpler and yet more expressive definition, instead of a pair of mutually inductive definitions for the computability closure and the ordering itself. On the positive side, the computability closure makes little use of type comparisons, hence may succeed when HORPO fails for type reason. Unfortunately, its fixpoint is not a syntax-oriented definition, hence has a more limited practical usage. Originally formulated in [16], the question of finding a syntax oriented recursive definition of HORPO that would inherit the advantages of the computability closure paved the way to CPO, the computability path ordering. The first definition was given in [17], later improved as CPO in [18]. A major improvement of CPO is that type comparisons are no more systematic, but occur in very specific cases. This does not only speed up computations, but also boosts the ordering capabilities in an essential way. Further, bound variables are handled explicitly by CPO, allowing for arbitrary abstractions in the righthand sides together with a more uniform definition. In this paper, we present an in-depth study of an improved version of CPO for a simple extension of Church’s simple type discipline [24], before we extend it to inductive types along the lines suggested in [18] following a technique dating back to Mendler [71, 72] and extended to rewriting by Blanqui [10]. In particular, we show that many improvements of CPO cannot be well-founded: type comparisons are necessary when recursive calls deconstruct the lefthand side, but are not otherwise. While this all came out of the well-foundedness proof, it indeed shows a strong relationship between the recursive structure of CPO and the computability predicates method of Tait and Girard that is used to carry out the proof, which explains the name CPO. We then address the treatment of inductive types which remained ad hoc so far, thanks to the use of accessibility, a relationship introduced by Blanqui which generalizes the notion of inductive type [11]. We also introduce another novelty: small symbols. In all previous definitions, function symbols were bigger in the precedence than application and abstraction. Such symbols are now called big, while small symbols behave differently, being possibly smaller than both. Small symbols were suggested by Li to carry out a generalization of CPO to dependent types [53]. In the recent years, the success of HORPO has prompted interest in the generalization to higher-order computations of various other methods used for first-order computations, most notably Art and Giesl’s dependency pairs [2, 40, 48] yielding for instance to [78, 66, 62, 79, 60, 61], and interpretation methods [68, 67, 89, 26] yielding for instance to [86, 46, 77, 39]. The paper is organized as follows. First, we define the sets of types and terms that we consider (simply typed λ-terms with function symbols of fixed arity), and the class of orderings on types that can be used in CPO. We then give a first definition of our ordering (core CPO), and show that it can hardly be improved while keeping the same recursive structure and well-foundedness. We then show how to prove its well-foundedness 4 FRÉDÉRIC BLANQUI, JEAN-PIERRE JOUANNAUD, AND ALBERT RUBIO by extending Tait and Girard’s technique of computability predicates. In the following sections, we consider two extensions of core CPO. In the first one, core CPO is extended by using accessible subterms which allows to handle strictly inductive types. In the second, application or abstraction are allowed to be bigger than a function call. Concluding remarks are given in Section 9. We recommend surveys [35, 83] for rewriting and [7] for typed λ-calculus. 2. Types and admissible type orderings CPO is a relation on well typed terms but, instead of allowing the comparison of terms of the same type only, it allows the type to decrease in some well-founded ordering. However, not any type ordering is admissible. In this section, we first recall the definition of (simple) types and some basic functions on types. Then, we define what are the (strict) orderings on types that can be used in CPO, study some of their properties and give an example based on a well-founded precedence on type constants. Definition 2.1 (Types).Let Sbe a set of sorts. The set Tof types, the arity α(_)and the order o(_)of a type are inductively defined as follows: ●a sort A∈ S is a type of arity α(A) = 0and order o(A) = 0. ●if Tand Uare types, then T→Uis a type of arity α(T→U) = 1+α(U)and order o(T→U) = max{1+o(T), o(U)}. We use capital letters for types and a different font for sorts (e.g. Tand A), and  Tfor a (possibly empty) sequence of types T1,...,Tn, of length ∣ T∣=n. As usual, →associates to the right so that A→A→Aand A→ (A→A)are the same. Given a relation R, let R+(resp. R∗) denote the transitive (resp. transitive and reflexive) closure of R. Definition 2.2 (Admissible type orderings).Let ⊳land ⊳rbe the relations on types such that T→U⊳lTand T→U⊳rUrespectively, and ⊳be the transitive closure of their union. A (strict) ordering >on types is admissible if: ● ⋗ = (> ∪ ⊳l)+is well-founded (typ-sn) ● ⊳r⊆ > (typ-right-subterm) ●if T→U>V, then U≥Vor V=T→U′for some U′<U(typ-arrow) where ≥is the reflexive closure of >. We say that a type Tis compatible (resp. strictly compatible) with a sort A, written SorttA(T)(resp. Sort⋖A(T)) if BtA(resp. B⋖A) for every sort Boccurring in T. Admissible type orderings originate from [57]. Note that a sort can be bigger than an arrow type. If Ais a sort occurring in T, then TuA. Finally, note that the relation ⋗is a simplification ordering [33]. We now give an example of admissible ordering based on a well-founded precedence on sorts. For a concrete use case, see Example 5.3 below. Lemma 2.3. Given a well-founded ordering >Son sorts, let >be the smallest ordering > on types containing >Sand ⊳rand such that, for all U, V, V ′, it holds that V>V′implies U→V>U→V′. Then, >is admissible. Proof. THE COMPUTABILITY PATH ORDERING 5 ●(typ-sn) ⋗is included in the RPO extending >S[32], hence is well-founded. ●(typ-right-subterm) By definition. ●(typ-arrow) Let T→U>V. The proof is by induction on the definition of >. (1) >is >S. Impossible since T→Uis not a sort. (2) >is ⊳r. Then U=V, hence U≥V. (3) V=T→Wand U>W. Immediate. (4) T→U>W>V. By induction hypothesis applied to T→U>W, there are two cases: –U≥W. Then, by transitivity, U>V. –W=T→U′for some U′<U. By induction hypothesis on T→U′>V, there are two cases: ∗U′≥V. By transitivity, U>V. ∗V=T→V′for some V′<U′. By transitivity, U>V′and we are done. In the following, we now prove some properties of admissible type orderings: Lemma 2.4. Let >be an admissible type ordering. If T→U>T′→U′, then U>U′. Proof. By (typ-arrow), either T=T′and U>U′or U≥T′→U′, in which case we conclude by (typ-right-subterm) and transitivity. Lemma 2.5. Let >be an admissible type ordering. If A>U, then Sort⋖A(U). Proof. Let Bbe a sort occurring in U. Then, UuB. Hence, by transitivity, A⋗B. Lemma 2.6. Let >be an admissible type ordering. If T>Uand SorttA(T), then SorttA(U). Proof. Let Cbe a sort occurring in U. We proceed by induction on T. ●T=B. Since SorttA(T),BtA. By Lemma 2.5, Sort⋖B(U)and C⋖B. Therefore, by transitivity, CtA. ●T=S→T′. Then, SorttA(S)and SorttA(T′). By (typ-arrow), there are two cases: –T′≥U. Then, by induction hypothesis, SorttA(U). –U=S→U′and T′>U′. By induction hypothesis, SorttA(U′). Hence SorttA(U). 3. Terms In this section, we define the set of terms on which CPO operates. We consider simply typed λ-terms [24, 7] with function symbols of a fixed arity, that is, a function symbol of arity n always comes with narguments. We follow Pottinger’s approach [76], assuming that every variable or function symbol comes equipped with a fixed type and that α-equivalence replaces a variable by another variable of the same type only. Then, there are no untyped terms, and typing environments become useless for both terms and rules: it is like having a fixed infinite typing environment. Definition 3.1 (Terms).Let Xbe an infinite set of variables, each variable xbeing equipped with a type τ(x)∈ T so that there is an infinite number of variables of each type. Let also Fbe a (finite or infinite) set of function symbols disjoint from X, each function symbol f being equipped with a type τ(f)∈ T and an arity α(f)≤α(τ(f)). The declaration fn∶T indicates the arity nand type Tof f. The set Lof terms is defined inductively as follows: 6 FRÉDÉRIC BLANQUI, JEAN-PIERRE JOUANNAUD, AND ALBERT RUBIO ●a variable xis a term of type τ(x); ●if fn∶T1→... →Tn→Uand t1,...,tnare terms of type T1,...,Tnrespectively, then f(t1,...,tn)is a term of type U; ●if tand uare terms of types U→Vand Urespectively, then tu is a term of type V; ●if xis a variable and tis a term of type T, then λxt is a term of type τ(x) → T. We denote by τ(t)the type of a term t, and write t∶Twhen τ(t)=T. We usually write f∶Tfor the declaration f0∶T, omitting the arity n=0, and ffor f(). Note that a term f( t)may have a functional type, hence can be applied. Application associates to the left so that tuv is the same as (tu)v. We use the letters x, y, z, . . . for variables, f,g,... for function symbols, and a, b, . . ., s, t, u, v, . . .,t′, u′,... for terms. We denote by FV(t)the set of free variables in t, by ⊲the strict subterm relationship on terms, and by ⊴its reflexive closure. The height of a term t, written ∣t∣, is the height of its tree representation: ∣x∣=0,∣f∣=0if α(f)=0,∣f( t)∣ =1+max{∣ti∣ ∣ 1≤i≤α(f)} if α(f)>0, ∣tu∣=1+max{∣t∣,∣u∣} and ∣λxt∣=1+∣t∣. Definition 3.2 (Substitution). ●A substitution is a function σ∶ X →Lsuch that dom(σ)={x∈ X ∣σ(x)≠x}is finite and, for every x,τ(σ(x)) =τ(x). As usual, the application of a substitution σto a term t, written tσ, is defined so as to avoid free-variable captures when renaming some bound variables of tby new variables of the same type [30]. ●A substitution σis away from a finite set of variables Xif (dom(σ)∪FV(σ))∩X= ∅, where FV(σ)=⋃{FV(σ(x)) ∣ x∈dom(σ)}. ●A relation >on terms (or sequences of terms) is stable by substitution away from X if aσ >bσ whenever a>band σis away from X. A relation is stable by substitution if it is stable by substitution away from ∅. We will use the letters σ,θ,... for substitutions, and denote the substitution mapping the variables xof its domain to the terms in  t(hence ∣x∣=∣ t∣) by ( t x). Note that stability by substitution reduces to the standard definition: >is stable by substitution if aσ >bσ whenever a>b(because any substitution is away from ∅). The equivalence relation identifying terms up to type-preserving renaming of their bound variables is called α-equivalence and written =αas usual [30]. Given a relation R, let SNT(R)be the set of terms of type Tfrom which there is no infinite sequence of R-steps, and SN(R)=⋃{SNT(R) ∣ T∈ T }. 4. Relations One ingredient of CPO is a well-founded quasi-ordering on function symbols and, for each equivalence class generated by the corresponding equivalence relation, a status stat ∈{mul}∪ {lex(n) ∣ n>2}prescribing how to compare the arguments of two equivalent symbols, by either its multiset [36] or lexicographic extension. We hereafter recall the necessary definitions and state some simple but important properties of these operations. The product extension is introduced here for technical reasons. Given a relation ≻on terms, let: ● t≻prod uif ∣ t∣=∣u∣and there is j∈{1,...,∣u∣} s.t. tj≻ujand, for all i≠j,ti=ui. THE COMPUTABILITY PATH ORDERING 7 ● t≻mul uif {∣ t∣}(≻1 M)+{∣u∣} where {∣ t∣} is the multiset made of the elements in  tand M+{∣x∣} ≻1 MM+{∣y1,...,yn∣} (n≥0) if, for all i,x≻yi(+being the multiset union); ● t≻lex(n)uif there is j∈{1,...,n}such that tj≻ujand, for all i<j,ti=ui. Note that both ≻mul and ≻lex(n)compares all the arguments whatever their types are, and ≻lex(n)compare them from left to right only. In [14], the first author describes more general version of these statuses that take types into account and allow reordering and filtering of the arguments [2]. We could also consider statuses combining both lexicographic and multiset comparisons [38]. In the following, we will omit nin ≻lex(n)and simply write ≻lex. Here are the properties of statuses we will rely on: Proposition 4.1. Given a relation ≻on terms: ● ≻stat preserves termination: if ≻is well-founded, then ≻stat is well-founded. ● ≻stat contains ≻prod. ● ≻stat preserves stability: if ≻is stable by substitution away from X, then so is ≻stat. 5. Computability path ordering In this section, we give the core definition of the computability path ordering (CPO) before to explore its limits by means of examples and compare it with its father definition, HORPO. 5.1. Definition of core CPO. We assume given: ●an admissible ordering on types >; ●a quasi-ordering ≥Fon F, called precedence, whose equivalence ≥F∩ ≥−1 Fis written ≃Fand strict part ≥F∖ ≥−1 Fis written >Fand assumed well-founded; ●for every f∈ F, a status stat(f)∈{lex,mul}such that symbols equivalent in ≃Fhave the same status. Definition 5.1 (Core computability path relation).The core computability path relation is the relation ≻∅ τ(≻τfor short) where: ●the set Fbof big symbols is identical to F,2 ●for any given finite set Xof variables, ≻Xis inductively defined in Figure 1, ●t≻X τuif t≻Xuand τ(t)≥τ(u), ● ⪰X(resp. ⪰X τ) is the reflexive closure of ≻X(resp. ≻X τ). The parameter Xserves as a meta-level binder to keep track of the variables that were previously bound in the righthand side but have become free when destructuring a righthand side abstraction. We shall say that a variable xis fresh with respect to a comparison u≻Xv if x/∈FV(u)∪X∪FV(v). Note that the parameter Xis carried along computations without change, except in rule (Fbλ). Hence, any comparison u≻Xvgenerated from an initial comparison s≻∅timplies X∩FV(u)= ∅. Explicit variable renamings and the associated freshness conditions are used to make the relation invariant by α-equivalence, the smallest congruence generated by the equation 2In core CPO, all symbols are big. Small symbols will show up in Section 8. 8 FRÉDÉRIC BLANQUI, JEAN-PIERRE JOUANNAUD, AND ALBERT RUBIO Figure 1: Core CPO (Fb⊳)f( t)≻Xvif f∈ Fband (∃i)ti⪰τv (Fb=) f( t)≻Xg(u)if f∈ Fb,f≃Fg,(∀i)f( t)≻Xuiand  t(≻τ)stat(f)u (Fb>) f( t)≻Xg(u)if f∈ Fb,f>Fgand (∀i)f( t)≻Xui (Fb@) f( t)≻Xuv if f∈ Fb,f( t)≻Xuand f( t)≻Xv (Fbλ)f( t)≻Xλyv if f∈ Fb,f( t)≻X∪{z}vz y,τ(y)=τ(z)and zfresh (FbX)f( t)≻Xyif f∈ Fband y∈X (@⊳)tu ≻Xvif t⪰Xvor u⪰X τv (@=) tu ≻Xt′u′if t=t′and u≻Xu′, or tu ≻X @t′and tu ≻X @u′ where tu ≻X @vif t≻X τvor u⪰X τvor tu ≻X τv (@λ)tu ≻Xλyv if tu ≻Xvz yand zfresh (@X)tu ≻Xyif y∈X (@β)(λxt)u≻Xvif tu x⪰Xv (λ⊳)λxt ≻Xvif tz x⪰X τv,τ(x)=τ(z)and zfresh (λ=) λxt ≻Xλyv if tz x≻Xvz y,τ(x)=τ(y)=τ(z)and zfresh (λ≠)λxt ≻Xλyv if λxt ≻Xvz y,τ(x)≠τ(y),τ(y)=τ(z)and zfresh (λX)λxt ≻Xyif y∈X (λη)λx(tx)≻Xvif t⪰Xvand x∉FV(t) λxt =λyty xif τ(x)=τ(y)and y∉FV(λxt)[30], and by appropriate renaming of the variables in X, as we shall prove later. Lemma 6.4 below will show that FV(v)⊆FV(u)∪Xwhenever u≻Xv. Hence, an alternative formulation of rules (@λ) and (λ≠) could therefore be given by replacing the condition “zfresh” by y∉FV(v). Having function symbols equipped with an arity is more general than having uncurried function symbols (i.e. of null arity) only: any uncurried system can be dealt with as it is. However, in this case, the (Fb_) rules are very limited: (Fb⊳) is not applicable, (Fb=) and (Fb>) reduce to the precedence itself. Moreover, applications of the form f twith ∣ t∣>0can only be compared by using the (@_) rules which are more constrained than the corresponding (Fb_) rules, especially (@λ) and (@=). Considering function symbols with non-null arities provides more structure to the terms, and this structure can be used for proving termination [49]. Another, perhaps surprising fact is that the definition of core CPO can be simplified by replacing ≻Xby ≻everywhere but in (Fbλ). This is true at the start since we are interested in ≻τ. This is then an invariant of the computation, for two reasons: Xis never increased, except in (Fbλ); Xis reset to the empty set by (Fb⊳) and (Fb=), which are the only rules which may move from a (Fb) comparison to a (@) or (λ) comparison. We could therefore simplify our definition by removing the superfluous Xsubscripts. This will however no more be true of the extension of core CPO to inductive types, and we prefer to have a uniform definition over the various sections. Further, the present definition will allow us to study a relaxation of (@λ) in the next section. As HORPO, core CPO is not transitive (both include β-reduction which is not transitive). Adding transitivity as a rule yields to non-termination as shown by the following counter-example: THE COMPUTABILITY PATH ORDERING 9 Example 5.2. In the premises of (Fb@), replace ≻Xby (≻X)+. Then, in the system S1 described at the beginning of next section, we have: (1) f(a)≻τ(λxf(x))asince τ(f(a)) =o≥τ((λxf(x))a)=oand, by relaxing (Fb@): (a) f(a)≻+λxf(x)since (i) f(a)≻aby (Fb⊳), and (ii) a≻λxf(x)by (Fbλ) since a≻{x}f(x)by (Fb>)and then (FbX) (b) f(a)≻aby (Fb⊳). (2) (λxf(x))a≻τf(a)since τ((λxf(x))a)=o≥τ(f(a)) =oand by (@β). Similar counter-examples can be build as well for (Fb>) and (Fb=), since the key point is that, by using (≻X)+, we can apply case (Fb⊳) without requiring type decreasingness. Useful implemented heuristics for under-approximating ≻+ τare discussed in [57]. The introduction of small symbols in Section 8 will reduce the need for such heuristics, although not completely. On the other hand, we will show soon that core CPO is a well-founded relation on terms. So is therefore its transitive closure. Surprisingly, core CPO is powerful enough to prove termination of examples that usually require techniques like the ones developed in Section 7. Example 5.3. Consider the breadth-first search of labeled trees using continuations [50], using the sorts Lfor lists of labels and Cfor continuations, the abbreviation ¬T=T→L, and the symbols d∶Cand c1∶ ¬¬C→Cfor building continuations. Let now e∶ ¬Cdefined by the rule: e c(x) → xe Its termination can be checked by core CPO by taking C≥Land c>Fe. Indeed, e c(x)≻τxeholds by (@⊳) since c(x)≻τxefor τ(c(x)) =C≥τ(xe)=Land, by (Fb@), c(x)≻xby (Fb⊳), and c(x)≻eby (Fb>). 5.2. Tightness of core CPO. In this section, we show that almost all possible relaxations (by replacing ≻τby ≻, and ≻by ≻X) of the above definition lead to non-termination by providing appropriate examples that are also meant to help understanding how CPO works. To this end, we will consider three different rewrite systems, using o∶ ∗ to declare a sort o: S1: o∶ ∗;a∶o, f1∶o→o, g∶o→o→o;a>Ff>Fg. S2: o, o′∶ ∗;a∶o, f1∶o→o, j1∶(o′→o→o) → o;a>Ff>Fj. S3: o∶ ∗;a∶o, h2∶o→o→o, k2∶(o→o) → o→o;a>Fh≃Fk; stat(h)=stat(k)=mul. For each rule, we now consider all its natural relaxations. ●(Fb⊳)f( t)≻Xvif (∃i)ti⪰τv –Replace ⪰τby ⪰X τ. Then, in S1, we have: (1) f(a)≻τ(λxf(x))asince τ(f(a)) =o≥τ((λxf(x))a)=oand, by (Fb@): (a) f(a)≻λxf(x)since, by (Fbλ), x∉FV(f(a)) and (i) f(a)≻{x}f(x)since, by relaxing (Fb⊳): a⪰{x} τf(x)since τ(a)=o≥τ(f(x)) =oand, by (Fb>), a≻{x}x by (FbX), (b) f(a)≻aby (Fb⊳). (2) (λxf(x))a≻τf(a)since τ((λxf(x))a)=o≥τ(f(a)) =oand by (@β). –Replace ⪰τby ⪰. Then, in S1, we have: 16 FRÉDÉRIC BLANQUI, JEAN-PIERRE JOUANNAUD, AND ALBERT RUBIO (1) (Fb=) By induction hypothesis and Lemma 4.1, (∀i)f( t)σ≻Xuiσand  tσ (≻τ)stat(f)uσ. Therefore, by (Fb=), f( t)σ≻Xg(u)σ. (Fbλ) Wlog we can assume σaway from {y}. Hence, (λyv)σ=λy(vσ). Let now z′be a variable of the same type as z, fresh for f( t)σ,X,λy(vσ)and λzvz y=αλyv, and such that σis away from {z′}. By induction hypothesis (2), f( t)>(X∪{z})z′ z(vz y)z′ z. Since z∉X,(X∪{z})z′ z=X∪{z′}. Since (z′ z)is away from {y}and z∉FV(v), (vz y)z′ z=vz′ y. By induction hypothesis, f( t)σ>X∪{z′}(vz′ y)σ. Since σis away from {y, z′},(vz′ y)σ=(vσ)z′ y. Therefore, by (Fbλ), f( t)σ≻Xλy(vσ). (λ⊳) Wlog we can assume that σis away from {x}. Hence, (λxt)σ=λx(tσ). After Lemma 6.4 and since σis away from X,FV(v)⊆FV(λxt). Hence, we can also assume wlog that dom(σ)⊆FV(λxt). Let now z′be a variable of the same type as z, fresh for λx(tσ),X,vσ and x, and such that σis away from {z′}. Let σ′=σ∪{(z, z′)}. Since σ′is away from X, by induction hypothesis, (tz x)σ′≻Xvσ′. Since dom(σ)⊆FV(λxt) and σis away from {x, z′},(tz x)σ′=(tσ)z′ x, and since z∉FV(v),vσ′=vσ. Therefore, by (λ=), λx(tσ)≻Xvσ. (λ=) Wlog we can assume that σis away from {x, y}. Hence, (λxt)σ=λx(tσ)and (λyv)σ=λy(vσ). After Lemma 6.4 and since σis away from X,FV(λyv)⊆ FV(λxt). Hence, we can also assume wlog that dom(σ)⊆FV(λxt). Let now z′ be a variable of the same type as z, fresh for λx(tσ),X,λy(vσ),xand y, and such that σis away from {z′}. Let σ′=σ∪{(z, z′)}. Since σ′is away from X, by induction hypothesis, (tz x)σ′≻X(vz y)σ′. Since dom(s)⊆FV(λxt),dom(σ)⊆FV(λyv), and σis away from {x, y, z′},(tz x)σ′=(tσ)z′ xand (vz y)σ′=(vσ)z′ y. Therefore, by (λ=), (λxt)σ≻X(λyv)σ. (λ≠) Wlog we can assume σaway from {x, y}. Hence, (λxt)σ=λx(tσ)and (λyv)σ= λy(vσ). Let z′fresh for λxtσ,Xand λyvσ. By Lemma 6.4, y∉FV(v), hence vz y=vz′ y. By induction hypothesis, (λxt)σ≻Xvz′ yσ. Therefore, by (λ≠), λx(tσ)≻X λy(vσ). (2) (Fbλ) Wlog we can assume (e′ e)away from {y}. Hence, (λyv)e′ e=λy(ve′ e). Let now z′be a variable of the same type as z, fresh for f( t),Xe′ e,λy(ve′ e),λzvz y=αλyv and y. By induction hypothesis, f( t)≻(X∪{z})z′ z(vz y)z′ z. Since z∉X,(X∪{z})z′ z=X∪{z′}. Since z∉FV(λyv),(vz y)z′ z=vz′ y. By induction hypothesis, f( t)≻(X∪{z′})e′ e(vz′ y)e′ e. Since (e′ e)is away from {y, z′},(X∪{z′})e′ e=Xe′ e∪{z′}and (vz′ y)e′ e=(ve′ e)z′ y. Therefore, by (Fbλ), f( t)≻Xe′ eλyve′ e. (λ⊳) Let z′be a variable of the same type as z, fresh for λxt,X,Xe′ e,ve′ eand x. Since (z′ z)is away from X, by induction hypothesis (1), (tz x)z′ z⪰X τvz′ z. Since z′≠xand z∉FV(t),(tz x)z′ z=tz′ x. Since z∉FV(v),vz′ z=v. So, by induction hypothesis, tz′ x⪰Xe′ e τve′ e. Therefore, by (λ⊳), λxt ≻Xe′ eve′ e. (λ=) Wlog we can assume (e′ e)away from {y}. Hence, (λyv)e′ e=λy(ve′ e). Let now z′be a variable of the same type as z, fresh for λxt,X,Xe′ e,λyve′ e,xand y. Since (z′ z)is away from X, by induction hypothesis (1), (tz x)z′ z≻X(vz y)z′ z. Since z′≠xand z∉FV(t), (tz x)z′ z=tz′ x. Since z′≠yand z∉FV(v),(vz y)z′ z=vz′ y. So, by induction hypothesis, THE COMPUTABILITY PATH ORDERING 17 tz′ x≻Xe′ e(vz′ y)e′ e. Since (e′ e)is away from {y, z′},(vz′ y)e′ e=(ve′ e)z′ y. Therefore, by (λ=), λxt ≻Xe′ eλy(ve′ e). (λ≠) Wlog we can assume (e′ e)away from {y}. Hence, (λyv)e′ e=λy(ve′ e). Let z′fresh for λxt,Xe′ eand λy(ve′ e). By Lemma 6.4, y∉FV(v), hence vz y=vz′ y. By the induction hypothesis, λxt ≻Xe′ e(vz′ y)e′ e=(ve′ e)z′ y. Therefore, by (λ≠), λxt ≻Xe′ eλy(ve′ e). 6.2. Tait and Girard’s computability. We now turn to the proof that ≻τis well-founded. This proof is based on the meticulous analysis of the technique of computability predicates of Tait and Girard for proving the termination of β-reduction in typed λ-calculi [80, 43, 81, 44]. This technique consists in the following three steps: (1) interpret each type Tby a set JTKof so-called computable terms; (2) prove that, for every type T,JTKsatisfies some properties among which termination, i.e. JTK⊆SN(≻τ); (3) prove that every (well typed) term is computable. For arrow types, we will use the standard interpretation but, for sorts, we a priori have some freedom and we will indeed use this freedom to extend CPO to inductive types later in Section 7. Definition 6.7 (Computability).A base type interpretation is a map I∶ S →P(L)such that, for all sorts A,I(A)is a set of terms of type A. A base type interpretation naturally extends to types as follows: ●JAKI=I(A) ●JU→VKI={t∈ L ∣t∶U→V∧(∀u)u∈JUKI⇒tu ∈JVKI} Given a base type interpretation I, we say that: ●a term t∶Tis I-computable if t∈JTKI; ●a substitution σis I-computable on a set Xof variables if, for all x∈X,xσ is I-computable; it is I-computable if it is I-computable on X; ●a function symbol f∣ T∣∶ T⇒Uis I-computable if, for all I-computable terms  t∶ T, f( t)is I-computable. Let ΣIbe the set of pairs (f, t)such that f∈ F,f( t)is a term and  tare I-computable. Given a relation on terms R, let (>F, Rstat)lex be the relation on ΣIsuch that (f, t)(>F, Rstat)lex (g,u) if either f>Fg, or f≃Fgand  t Rstat(f)u. Our first lemma has a straightforward proof: Lemma 6.8. Let I1and I2be two base type interpretations, and Tbe a type. Then, JTKI1= JTKI2if I1and I2agree on every sort occurring in T. We then consider the following properties: Definition 6.9 (Sets of neutral terms).A set Nis a set of neutral terms if it satisfies the following properties: ● X ⊆ N (neutral-var) ●for all x, t, u,(λxt)u∈ N (neutral-beta) ●if t∈ N then, for all u,tu ∈ N (neutral-app) ●for all xand t,λxt ∉ N (neutral-not-lam) 18 FRÉDÉRIC BLANQUI, JEAN-PIERRE JOUANNAUD, AND ALBERT RUBIO Definition 6.10 (Computability properties).Given a base type interpretation Iand a set Nof neutral terms, a set Sof terms of type Tis an I-computability predicate if it satisfies the following properties: ●S⊆SN(≻τ)(comp-sn) ●If t∈S, then every ≻τ-reduct of tis I-computable (comp-red) ●t∈Sif t∶T,t∈ N and every ≻τ-reduct of tis I-computable (comp-neutral) ●λxt ∈Sif T=U→V,λxt ∶Tand, for all u∈JUKI,tu xis I-computable (comp-lam) We can then prove that every term is strongly normalizing if the sets JTKIsatisfy some of these properties and function symbols are I-computable, whatever the base type interpretation Iand the set Nof neutral terms are: Theorem 6.11. Given a base type interpretation Iand a set Nof neutral terms, ≻τis well-founded if: ●for every type T,JTKIsatisfies (comp-sn),(comp-neutral) and (comp-lam); ●every function symbol f∈ F is I-computable. Proof. Because, for every T,JTKIsatisfies (comp-sn), it suffices to prove that every term is I-computable. By (neutral-var), variables belongs to N. Because, for every T,JTKIsatisfies (comp-neutral), variables are computable. Hence, the identity substitution is computable. We then prove that, for all t∶Tand computable σ,tσ ∈JTKI, by induction on t. ●t=x. Then, tσ =xσ is computable since σis computable. ●t=uv. By induction hypothesis, uσ and vσ are computable. Therefore, tσ = (uσ)(vσ)is computable. ●t=λxu with x∶V. By renaming x, we can assume that σis away from {x}. Hence, tσ =λx(uσ). By assumption, JTKIsatisfies (comp-lam). Therefore, tσ is computable if, for all computable v∶V,(uσ)v xis computable. Since σis away from {x},(uσ)v x=u(σ∪{(x, v)}) which is computable by induction hypothesis. ●t=f( t)with f∣ T∣∶ T→U. By induction hypothesis,  tσ are computable. Thus, (f, tσ)∈Σand, by assumption, f( t)σis computable. We are therefore left to find a set of neutral terms Nand a base type interpretation Iso that type interpretations are computability predicates and function symbols are computable. First, we are going to study under which conditions the interpretation of an arrow type U→V,JU→VKI, satisfies the above computability properties, whatever the base type interpretation Iand the set of neutral terms Nare. Second, we will define a set of neutral terms Nand a base type interpretation Iso that, for every type T,JTKIsatisfies all the computability properties. Finally, we will prove that function symbols are computable by induction on (>F,(≻τ)stat)lex, which is well-founded when the following conditions are satisfied: Lemma 6.12. Given a base type interpretation Iand a well-founded relation on I-computable terms R,(>F, Rstat)lex is well-founded if, for all f∣ T∣∶ T→U,J TKI⊆SN(R). Proof. If (f, t)∈Σ, then  t∈J TKI. By assumption, J TKI⊆SN(R). Hence, by Lemma 4.1,  t∈SN(Rstat(g))whatever gis. Assume now that there is an infinite (>F, Rstat)lex-decreasing sequence (fi, ti)i≥0. Then, (fi)i≥0is an infinite ≥F-decreasing sequence. Since >Fis wellfounded by assumption, there must be some jsuch that, for all i≥j,fi≃Ffj. Since symbols equivalent in ≃Fhave the same status by assumption, ( ti)i≥jis an infinite Rstat(fj)-decreasing sequence, a contradiction. THE COMPUTABILITY PATH ORDERING 19 6.3. Computability properties of arrow types. In this sub-section, the results hold for any base type interpretation Iand any set of neutral terms N. For the sake of simplicity, we drop the index Iin JTKIand simply write JTK. Lemma 6.13. JU→VKsatisfies (comp-sn) if: ●JUK≠ ∅, which is the case if JUKsatisfies (comp-neutral); ●JVKsatisfies (comp-sn). Proof. Assume that there is an infinite reduction sequence t0≻τt1≻τ... with t0∈JU→VK and ti∶Ti. By definition of JU→VK,T0=U→V. By definition of ≻τ,T0≥T1≥... By assumption, JUK≠ ∅. So, let u∈JUK. By definition of JU→VK, we have t0u∈JVK. We now prove that there is an infinite reduction sequence starting from t0u. Since JVKis assumed to satisfy (comp-sn), this is not possible. Therefore, JU→VKsatisfies (comp-sn) too. By (typ-arrow) there are only two cases: ●For all i,Ti=U→Bifor some Bi. By monotony (Lemma 6.3), t0u≻τt1u≻τ... ●There is isuch that Ti+1is a sort or Ti+1=Ai+1→Bi+1with Ai+1≠U. Let kbe the smallest isatisfying this condition. Hence, for all i≤k, there is Bisuch that Ti=U→Bi. By monotony (Lemma 6.3), t0u≻τ. . . tku. By (typ-arrow), we have Bk≥Tk+1. Hence, by (@⊳), tku≻τtk+1. Lemma 6.14. JU→VKsatisfies (comp-red) if: ●JUK≠ ∅, which is the case if JUKsatisfies (comp-neutral); ●JVKsatisfies (comp-red). Proof. Let t∈JU→VKand t′∶T′such that t≻τt′. By definition of JU→VK,t∶U→V. By definition of ≻τ,U→V≥T′. By (typ-arrow), there are two cases: (1) V≥T′. By assumption, JUK≠ ∅. So, let u∈JUK. By definition of JU→VK,tu ∈JVK. By (@⊳), we have tu ≻τt′. Therefore t′∈JT′Ksince JVKsatisfies (comp-red). (2) T′=U→V′and V≥V′. Let u∈JUK. By monotony (Lemma 6.3), tu ≻τt′u. By definition of JU→VK,tu ∈JVK. Since JVKsatisfies (comp-red), t′u∈JV′K. Therefore, t′∈JT′K. Lemma 6.15. Let t∶U→Vand u∶U. Then, every ≻τ-reduct of tu is computable if: ●every ≻τ-reduct of tis computable; ●uis computable; ●if t=λxv, then vu xis computable; ●for all u′such that u≻τu′,tu′is computable; ●JUKsatisfies (comp-red); ●JVKsatisfies (comp-red); ●JV′Ksatisfies (comp-lam) whenever V′≤V. Proof. We prove that every w∶Wsuch that tu ≻τwis computable, by induction on ∣w∣. By definition of ≻τ, we have V≥W. ●(@⊳) –t⪰w. By (typ-right-subterm), U→V>V. Hence, by transitivity, U→V>W and t≻τw. Therefore, wis computable by assumption. –u⪰τw. Then, wis computable since, by assumption, uis computable and JUK satisfies (comp-red). ●(@=) w=t′u′and either: 20 FRÉDÉRIC BLANQUI, JEAN-PIERRE JOUANNAUD, AND ALBERT RUBIO –t=t′and u≻u′, in which case t′uis computable by assumption since u≻τu′; –or tu ≻@t′and tu ≻@u′. We prove that, for v∈{t′, u′}, if tu ≻@vthen vis computable. There are three cases: ∗t≻τv. Then, vis computable by assumption. ∗u⪰τv. Then, either u=vand vis computable by assumption, or u≻τv and vis computable since uis computable and JUKsatisfies (comp-red). ∗tu ≻τv. Then, since v∈{t′, u′},vis computable by induction hypothesis. ●(@λ)w=λyv,tu ≻vand y∉FV(v)by Lemma 6.4. Then, there are Aand Bsuch that W=A→B. By (typ-right-subterm), W>B. Hence, by transitivity, V>B and tu ≻τv. Thus, by induction hypothesis, vis computable. Since JWKsatisfies (comp-lam), wis computable if, for all computable term a∶A,va yis computable. Since y∉FV(v),va y=v. Therefore, wis computable. ●(@X)w∈ ∅. Impossible. ●(@β)t=λxv and vu x≥∅w. Since τ((λxv)u)=τ(vu x), we have vu x⪰τw. Thus wis computable since vu xis computable and JVKsatisfies (comp-red). Lemma 6.16. Let t∶U→Vand u∶U. Then, tu is computable if: ●every ≻τ-reduct of tis computable; ●uis computable; ●if t=λxv, then vu xis computable; ●either tis neutral or t=λxv; ●JUKsatisfies (comp-red) and (comp-sn); ●JVKsatisfies (comp-red) and (comp-neutral); ●JV′Ksatisfies (comp-lam) whenever V′≤V. Proof. We prove that tu is computable by induction on uwith ≻τas well-founded relation (JUKsatisfies (comp-sn) by assumption). So, by induction hypothesis, for all u′such that u≻τu′,tu′is computable. Hence, by Lemma 6.15, every ≻τ-reduct of tu is computable. Now, tu is neutral because, either tis neutral and tu is neutral by (neutral-app), or t=λxv and tu is neutral by (neutral-beta). Therefore, tu is computable since JVKsatisfies (compneutral). Corollary 6.17. JU→VKsatisfies (comp-neutral) if: ●JUKsatisfies (comp-red) and (comp-sn); ●JVKsatisfies (comp-red) and (comp-neutral); ●JV′Ksatisfies (comp-lam) whenever V′≤V. Proof. Let tbe a neutral term of type U→Vsuch that every ≻τ-reduct of tis computable. By definition, t∈JU→VKif, for all computable u∶U,tu is computable. Since tis neutral, by (neutral-not-lam), tis not of the form λxv. Therefore, by Lemma 6.16, tu is computable since all the required properties are satisfied. Lemma 6.18. Let x∶Uand v∶V. Then, λxv is computable if: ●for all computable u∶U,vu xis computable; ●JUKsatisfies (comp-sn) and (comp-red) and contains a variable, which is the case if it satisfies (comp-neutral) too; ●JVKsatisfies (comp-sn),(comp-red) and (comp-neutral); ●JV′Ksatisfies (comp-lam) whenever V′≤V. THE COMPUTABILITY PATH ORDERING 21 Proof. By definition, λxv is computable if, for all computable u∶U,(λxv)uis computable. By Lemma 6.16, (λxv)uis computable if every ≻τ-reduct of λxv is computable, the other conditions being satisfied. Since JUKcontains a variable, we can wlog assume that this is x. So, vx x=vis computable. Since JVKsatisfies (comp-sn), v∈SN(≻τ). We now prove that every ≻τ-reduct w∶Wof λxv is computable, by induction on (v, ∣w∣) with (≻τ,>N)lex as well-founded relation. By definition of ≻τ, we have U→V≥W. ●(λ⊳)v⪰τw. Since vis computable and JVKsatisfies (comp-red), we have wcomputable. ●(λ=) w=λxb and v≻b. Then, there is Bsuch that W=U→B. Since U→V≥W, by Lemma 2.4, we have V≥B. Hence, v≻τb. Thus, by induction hypothesis, every ≻τ-reduct of λxb is computable. By Lemma 6.16, to prove that λxb is computable, it suffices to check that, for all u∶Ucomputable, bu xis computable. By assumption, vu xis computable. By stability by substitution (Lemma 1), vu x≻τbu x. Therefore, bu x is computable since JVKsatisfies (comp-red) by assumption. ●(λ≠)w=λyb,τ(x)≠τ(y),λxv ≻band y∉FV(b)by Lemma 6.4. Then, there are Aand Bsuch that W=A→B. Since U≠A, by (typ-arrow), V≥W. Since, by assumption, JWKsatisfies (comp-lam), it suffices to prove that, for all computable a∶A,ba yis computable. Since y∉FV(b),ba y=b. By (typ-right-subterm), U→V>V and W>B. Hence, by transitivity, U→V>Band λxv ≻τb. Therefore, since ∣w∣>N∣b∣, by induction hypothesis, bis computable. ●(λX)w∈ ∅. Impossible. ●(λη)v=ax,a⪰wand x∉FV(a). Since τ(λxv)=τ(a), we have a⪰τw. Let u∶Ucomputable. We have au =vu xcomputable by assumption. Therefore, ais computable. By Lemma 6.14, JU→VKsatisfies (comp-red) since JUK≠ ∅ and JVK satisfies (comp-red). Therefore, wis computable too. Corollary 6.19. JU→VKsatisfies (comp-lam) if: ●JUKsatisfies (comp-sn),(comp-red) and (comp-neutral); ●JVKsatisfies (comp-sn),(comp-red) and (comp-neutral); ●JV′Ksatisfies (comp-lam) whenever V′≤V. In conclusion, we can see that JU→VKIis a computability predicate if so are JUKIand JV′KIfor all V′≤V. Therefore, if we can define a base type interpretation Iso that, for every sort A,I(A)is a computability predicate then, for all type T,JTKIwill be a computability predicate. 6.4. Well-foundedness of core CPO. We now define a set of neutral terms Nand a base type interpretation Ifor proving the well-foundedness of core CPO. Definition 6.20 (Neutral terms for core CPO).Let Nbe the smallest set of terms containing the terms of the form f( t)and closed by (neutral-var), (neutral-beta) and (neutral-app). One can easily check that Nsatisfies all the properties of Definition 6.10. In contrast with the usual practice, but as in [57], our interpretation of sorts is not the set of strongly normalizing terms of that sort. To define the base type interpretation I, we proceed by induction on ⋗which is well-founded by (typ-sn). So, let Abe a sort and assume that Iis defined for all sorts B⋖A. Then, let I(A)be the least fixpoint of the monotone function FAdefined as follows: 22 FRÉDÉRIC BLANQUI, JEAN-PIERRE JOUANNAUD, AND ALBERT RUBIO FA(S)={t∈ L ∣t∶A∧(∀u)(∀U)t≻τu∧u∶U⇒u∈JUKI∪{(A,S)}} We now prove that FAis indeed well-defined and monotone. Then, by Knaster and Tarski’s fixpoint theorem [82], FAadmits a (least) fixpoint. Lemma 6.21. FAis well-defined. Proof. The recursive call to JUKI∪{(A,S)} is well-defined because, by definition of ≻τ, we have A≥U. Hence, by Lemma 2.5, SorttA(U). Lemma 6.22. FAis monotone. Proof. Let S⊆S′,J=I∪{(A, S)},J′=I∪{(A, S′)} and t∈FA(S). Then, (1) t∶Aand (2) (∀u)(∀U)t≻τu∧u∶U⇒u∈JUKJ. Now, we have t∈FA(S′)because tsatisfies (1) and (2) with Sreplaced by S′. Indeed, assume that t≻τuand u∶U. By (2), u∈JUKJ. By definition of ≻τ,A≥U. If A=U, then u∈JUKJ′since u∈JUKJ=S⊆S′=JUKJ′. Otherwise, by Lemma 2.5, Sort⋖A(U). Therefore, by Lemma 6.8, JUKJ=JUKJ′and u∈JUKJ′. Note that the least fixpoint of FAcan be reached by transfinite iteration of FAfrom ∅ [65, 29], that is, there is an ordinal a, such that I(A)=Fa A(∅)where: ●F0 A(S)=S ●Fa+1 A(S)=FA(Fa A(S)) ●Fa A(S)=⋃b<aFb A(S)if ais a limit ordinal We now check that type interpretations are computability predicates. Lemma 6.23. Given a sort A,JAKsatisfies (comp-red),(comp-neutral) and (comp-lam). Proof. We show each property in turn. ●(comp-red) Let t∈JAKand assume that t≻τuand u∶U. Since JAK=FA(JAK), we have u∈JUKby definition of FA. ●(comp-neutral) Let t∶Abe a neutral term whose ≻τ-reducts are all computable. Since JAK=FA(JAK), we have t∈JAKby definition of FA. ●(comp-lam) Trivial for typing reasons. Lemma 6.24. Given a sort A,JAKsatisfies (comp-sn) if, for all type U<A,JUKsatisfies (comp-sn). Proof. As already mentioned, JAK=Fa A(∅)for some ordinal a. Since ∅satisfies (comp-sn), it therefore suffices to check that FApreserves termination: if S⊆SN(≻τ), then FA(S)⊆ SN(≻τ). So, let S⊆SN(≻τ)and let t∈FA(S). By definition of FA, we have t∶Aand, if t≻τuand u∶U, then u∈JUKJwhere J=I∪{(A, S)}. By definition of ≻τ,A≥U. If A=U, then JUKJ=Sand u∈SN(≻τ)since S⊆SN(≻τ). Otherwise, u∈SN(≻τ)since JUK⊆SN(≻τ) by assumption. Theorem 6.25. For all type T,JTKis a computability predicates, i.e. satisfies (comp-sn), (comp-red),(comp-neutral) and (comp-lam). Proof. We proceed by induction on ⋗which is well-founded by assumption (typ-sn). If T is a sort, then we can conclude by Lemma 6.23, Lemma 6.24 and induction hypothesis. Otherwise, T=U→V. Since T⊳lU, by induction hypothesis, JUKis a computability predicate. Let now V′be a type such that V≥V′. By (typ-right-subterm) and transitivity, T>V′. Hence, by induction hypothesis, JV′Kis a computability predicate. Therefore, JU→VKsatisfies (comp-sn) by Lemma 6.13, (comp-red) by Lemma 6.14, (comp-neutral) by Corollary 6.17 and (comp-lam) by Corollary 6.19. THE COMPUTABILITY PATH ORDERING 23 Now, we are left to prove that every function symbol is computable. Lemma 6.26. Let f∣ T∣∶ T→Uand  t∈J TK. Then, f( t)∈JUK. Proof. By Theorem 6.25, J TKsatisfies (comp-sn). Hence, by Lemma 6.12, (>F,(≻τ)stat)lex is well-founded. We now prove that, for all (f, t)∈Σ,f( t)is computable, by induction on (>F,(≻τ)stat)lex (1). First, we check that t=f( t)is computable if all its ≻τ-reducts so are. This follows from the facts that, by definition of N,tis neutral and, by Theorem 6.25, JUKsatisfies (comp-neutral). We now prove that, for all finite sets of variables X, for all substitutions σsuch that dom(σ)∩FV( t)= ∅ and σis computable on X, and for all terms wsuch that f( t)≻X w, we have wσ computable, by induction on the size of w(2). Note that  tσ = tsince dom(σ)∩FV( t)= ∅. ●(Fb⊳)(∃i)ti⪰τw. By stability by substitution of ⪰τ(Lemma 1), we have tiσ⪰τwσ. Therefore, wσ is computable since, by Theorem 6.25, JVKsatisfies (comp-red). ●(Fb=) There are gand usuch that w=g(u),f≃Fg,(∀i)f( t)≻Xuiand  t(≻τ)stat(f)u. Since (∀i)f( t)≻Xui, by induction hypothesis (2), uσ are computable. If ti≻τ ujthen, by stability by substitution (Lemma 1), ti=tiσ≻τujσ. Therefore,  t(≻τ)stat(f)uσ and, by induction hypothesis (1), g(u)σis computable. ●(Fb>) Since f( t)≻Xu, by induction hypothesis (2), uσ are computable. Hence, g(u)σis computable by induction hypothesis (1). ●(Fb@) Since f( t)≻Xuand f( t)≻Xv, by induction hypothesis (2), uσ and vσ are computable. Therefore, (uv)σ=(uσ)(vσ)is computable. ●(Fbλ) Wlog we can assume that σis away from {y}and y∉FV(f( t)). Hence, (λyv)σ=λy(vσ). By Theorem 6.25, λy(vσ)is computable if, for all computable u∶τ(y),(vσ)u yis computable. Since σis away from {y},(vσ)u y=(vz y)θwhere θ=σ∪{(z, u)}. Let Z=X∪{z}. Since f( t)≻Zvz y,dom(θ)∩FV(f( t)) = ∅ and θis computable on Z, we have vz yθcomputable by induction hypothesis (2). ●(FbX)w∈X. Then, wσ is computable since σis computable on X. Theorem 6.27. The relation ≻τof Definition 5.1 is well-founded. Proof. After Theorem 6.11, Theorem 6.25 and Lemma 6.26. We can therefore conclude that ≻+ τis a monotone, stable, well-founded order. The well-foundedness proof of core CPO is actually similar to that of HORPO, although the proof here is presented in a quite different style from HORPO’s monolithic proof [57]. This similarity fades away with the two coming extensions, to inductive types and to small symbols. The reason why we have split the proof into small pieces is indeed to factor out its structure and those parts which are common to core CPO and its extensions. 7. Accessibility In this section, we introduce an extension of the core definition that will allow us to handle rewrite rules like the ones defining recursors for strictly positive inductive types as used in the Coq proof assistant [28, 52]. 24 FRÉDÉRIC BLANQUI, JEAN-PIERRE JOUANNAUD, AND ALBERT RUBIO Example 7.1. Consider the inductive type Oof “Brouwer ordinals” whose constructors are zero ∶Ofor zero, suc1∶O→Ofor successor, and lim1∶(N→O) → Ofor limit, where Nis the inductive type of Peano (unary) natural numbers with constructors 0∶Nand s1∶N→N. Given a type A, the recursor (of arity 4) at type A recA O∶O→A→ (O→A→A) → ((N→O) → (N→A) → A) → A can be defined by the following rewrite rules: recA O(zero, u, v, w) → u recA O(suc(x), u, v, w) → v x (recA O(x, u, v, w)) recA O(lim(y), u, v, w) → w y (λn recA O(y n, u, v, w)) To capture such a relation, we need the following two comparisons to succeed: recA O(lim(y), u, v, w)≻yand lim(y)≻τy n. The second comparison cannot succeed unless we allow non empty sets Xof variables in (Fb=) in order to have lim(y)≻{n} τy n, but we have seen in Section 5.2 that this may lead to non-termination. Instead, we will use a specific ordering: the structural ordering introduced by Coquand for dealing with such kind of definitions in the calculus of constructions [27]. For the first comparison to succeed, since the type of yis bigger than the type of lim(y), we must not check types in (Fb⊳), but we have seen in Section 5.2 that this may lead to non-termination. To solve this problem, we will compare in (Fb⊳) the right-hand side with possibly deep subterms of the left-hand side. We cannot take any deep subterm however, as shown by the following example: assuming the signature c1∶(A→B) → Aand f1∶A→ (A→B), the deep subterm comparison f(c(x)) ≻τxleads to non-termination, since, taking t=λx f(x)x, we have f(c(t))c(t)≻τ tc(t)≻τf(c(t))c(t)by monotony and (@β). There are two cases where deep subterms can be used: as for the first, deep subterms whose type is a (sufficiently small) sort [57]; as for the second, Mendler showed that pattern-matching on constructors of a sort Ahaving an argument whose type has a negative occurrence of Awrt the arrow type constructor (see Definition 7.2 just after), leads to non-termination, while, on the contrary, β-reduction combined with recursion combinators for positive inductive types terminates [71]. 7.1. Accessible subterms. In this sub-section, we first define the sets of positive and negative positions of a type, and the notions of accessible and structurally smaller term, before we prove some properties of these notions. Definition 7.2 (Positive and negative positions in a type).The sets Pos(T),Pos(A, T ), Pos+(T)and Pos−(T)of positions, positions of A, positive positions and negative positions in a type Tare inductively defined as follows: ●Pos(A)=Pos+(A)=Pos(A,A)={ε} ●Pos−(A)= ∅ ●Pos(A,B)= ∅ if A≠B ●Pos(T→U)={1p∣p∈Pos(T)} ∪{2p∣p∈Pos(U)} ●Pos(A, T →U)={1p∣p∈Pos(A, T )} ∪{2p∣p∈Pos(A, U)} ●Pos+(T→U)={1p∣p∈Pos−(T)} ∪{2p∣p∈Pos+(U)} ●Pos−(T→U)={1p∣p∈Pos+(T)} ∪{2p∣p∈Pos−(U)} A sort Aoccurs only positively (resp. negatively) in Tif Pos(A, T )⊆Pos+(T)(resp. Pos(A, T )⊆Pos−(T)). THE COMPUTABILITY PATH ORDERING 25 For instance, for T=(A→B) → Bwith A≠B, we have Pos(T)={ε, 1,2,11,12}, Pos+(T)={11,2},Pos−(T)={12},Pos(A, T )={11}and Pos(B, T )={12,2}. Hence, A occurs only positively in T, but Bhas both positive and negative occurrences in T. Definition 7.3 (Accessible arguments).For every fα(f)∶ T→A, we assume given a set Acc(f)of accessible arguments of fsuch that i∈Acc(f)implies SorttA(Ti)and Pos(A, Ti)⊆ Pos+(Ti). Note that, if α(f)<∣ T∣, the output type of fis functional. Let us consider Example 7.1 and assume that O>N. Then, Ooccurs only positively in the type of the first argument of suc, and we can take Acc(suc)={1}. Similarly, we can take Acc(lim)={1}. We can now introduce those sorts Awhich are not bigger than any arrow type and will be interpreted by SNA(≻τ)later: Definition 7.4 (Basic sorts).A sort Ais basic if, for all type T<A,Tis a basic sort and, for all fα(f)∶ T→Aand i∈Acc(f),Ti=Aor Tiis a basic sort. Usually, are basic all first-order data types like unary natural numbers, lists, trees, etc. whose constructors do not take a function as argument. Accessibility blends accessible arguments and subterms of basic sort: Definition 7.5 (Accessibility).A term uis said to be accessible in a term tif: ●uis a subterm of basic sort of tsuch that FV(u)⊆FV(t), written t⊳s bu, or ●there are fα(f)∶ T→A, t∶ Tand i∈Acc(f)such that t=f(t1,...,tα(f))tα(f)+1. . . t∣ T∣ and ti⊵au, written t⊳au, where ⊵s band ⊵aare the reflexive closures of ⊳s band ⊳arespectively. Coming back to Example 7.1, we have xaccessible in suc(x)since suc(x)⊳ax, and y accessible in lim(y)since lim(y)⊳ay. Lemma 7.6. If t⊳au∶U, then there are two sorts Aand Bsuch that t∶A,BtA,SorttB(U) and Pos(B, U)⊆Pos+(U). Proof. By induction on ⊳a, which is clearly well-founded. Assume that there are fα(f)∶ T→ A, t∶ Tand i∈Acc(f)such that t=f(t1,...,tα(f))tα(f)+1. . . t∣ T∣and ti⊵au. By definition of Acc,SorttA(Ti)and Pos(A, Ti)⊆Pos+(Ti). If ti=uthen U=Tiand we are done with B=A. Assume now that ti⊳au. Then, by induction hypothesis, there are two sorts Band Csuch that ti∶B,CtB,SorttC(U)and Pos(C, U)⊆Pos+(U). Since SorttA(Ti)and Ti=B, we have BtA. By transitivity, we get CtA. Corollary 7.7. If t∶A,t⊳au∶Uand Aoccurs in U, then SorttA(U)and Pos(A, U)⊆ Pos+(U). Proof. By Lemma 7.6, there is a sort BtAsuch that SorttB(U)and Pos(B, U)⊆Pos+(U). Since Aoccurs in U,AtB. Therefore, B=Aand we are done. Definition 7.8 ([27]).Given a finite set Xof variables, we say that uis structurally smaller than twrt X, written t⊳X @u, if there are A,vand x∶ Usuch that t∶A,u∶A,u=vx,t⊳av, x∈Xand Pos(A, U)= ∅. One can easily check: Lemma 7.9. ⊳s band ⊳a(resp. ⊳X @) are stable by substitution (resp. away from X). 32 FRÉDÉRIC BLANQUI, JEAN-PIERRE JOUANNAUD, AND ALBERT RUBIO that, for instance, any constructor of a strictly-positive inductive type can be considered a small symbol. 8.1. CPO with small symbols. Definition 8.1 (CPO with small symbols).We assume that the set of function symbols is partitioned into a set Fbof big symbols and a set Fsof small symbols so that: ●no small symbol is greater or equivalent to a big symbol (small-lt-big) ●small symbols with arrow output type have no accessible argument (small-acc) We then extend ≻Xby adding the rules of Figure 3. We will add conditions on the types of small symbols after Definition 8.9 (see Figure 4). Figure 3: Additional CPO rules for small symbols (@Fs)tu ≻Xf(v)if f∈ Fsand (∀i)tu ≻X τvi (λFs)λxt ≻Xf(v)if f∈ Fsand (∀i)λxt ≻X τvi (Fs⊳)f( t)≻Xvif f∈ Fsand (∃i)ti⪰τv (Fs=) f( t)≻Xg(u)if f∈ Fs,f≃Fg,(∀i)f( t)≻X τuiand  t(≻τ∪ ⊳X @⪰τ)stat(f)u (Fs>) f( t)≻Xg(u)if f∈ Fs,f>Fgand (∀i)f( t)≻X τui (Fs@) f( t)≻Xu v if f∈ Fs,f( t)≻X τuand f( t)≻X τv (FsX)f( t)≻Xxif f∈ Fsand x∈X Because of the rules (@Fs) and (Fs@), one may think that the relation is not terminating anymore, but this is not the case for typing reasons. Indeed, in contrast with rules for big symbols, rules for small symbols require type checking the recursive calls systematically. For instance, assume that f∶o→oand g2∶o→o→o. Then, although we have f a ≻τg(a,a)by (@Fs) since f a ≻τaby (@⊳), we do not hopefully have g(a,a)≻τf a by (Fs@) because we do not have g(a,a)≻τffor typing reasons. On the other hand, there is no rule (Fsλ) such that f( t)≻Xλyv if f( t)≻Xvand y∉FV(v)because, together with the rule (λFs), it would lead to non-termination as shown by the following example: given small symbols a∶o→o>Fb∶o,λxb≻τaby (λFs), and a≻τλxbby (Fsλ) since a≻τbby (Fs>). It is however possible to have (Fsλ) if one removes (λFs). We choose to present the case of (Fsλ) because it seems more useful, but the termination proof can be easily adapted if (Fsλ) is replaced by (λFs). Note however that this does not lead to the same definition for the sets SPos,LPos, . . . (Definition 8.9) studied in Section 8.4. Two possible improvements are left. First, take a rule (Fs⊳) similar to the rule (Fb⊳) of Figure 2. Second, get rid of the assumption (small-acc). 8.2. Computability properties. Lemma 8.2 (Basic properties). ● ≻Xis well-defined. ● ≻τis monotone. ●If a≻Xb, then FV(b)⊆FV(a)∪X. ● ≻Xis stable by α-equivalence. THE COMPUTABILITY PATH ORDERING 33 ● ≻Xis stable by substitution away from X. ●If e, e′∈ X,τ(e)=τ(e′),t≻Xuand e′∉FV(λeu), then t≻X−{e}∪{e′}ue′ e. Keeping the same definitions for neutral terms and the base type interpretation as in Section 6, it is easy to check that Lemma 6.13 and Lemma 6.14 still hold. However, because of the new rules (@Fs) and (λFs), Corollary 6.17 and Corollary 6.19, hence Lemma 6.16 and Lemma 6.18 reveal new dependencies that require introducing the following new computability property for a set Sof terms of type T: (comp-small) f( t)∈Sif f( t)∶T,f∈ Fsand  tare computable. Note that big symbols do not need any computability property because they are bigger than everybody else, and therefore other computability properties do not depend upon the computability of big symbols. It follows that they cannot be implied in any circularity. Lemma 8.3. Let t∶U→Vand u∶U. Then, every ≻τ-reduct of tu is computable if: ●every ≻τ-reduct of tis computable; ●uis computable; ●if t=λxv, then vu xis computable; ●for all u′such that u≻τu′,tu′is computable; ●JUKsatisfies (comp-red); ●JVKsatisfies (comp-red); ●JV′Ksatisfies (comp-lam) and (comp-small) whenever V′≤V. Proof. The proof is the same as for Lemma 6.15 except for the new case: ●(@Fs)w=f(v),f∈ Fsand (∀i)tu ≻τvi. By induction hypothesis, vare computable. Since JWKsatisfies (comp-small) by assumption, wis computable. Lemma 8.4. Let t∶U→Vand u∶U. Then, tu is computable if: ●uis computable; ●every ≻τ-reduct of tis computable; ●if t=λxv, then vu xis computable; ●either tis neutral or t=λxv; ●JUKsatisfies (comp-red) and (comp-sn); ●JVKsatisfies (comp-red) and (comp-neutral); ●JV′Ksatisfies (comp-lam) and (comp-small) whenever V′≤V. Proof. As for Lemma 6.16 but using Lemma 8.3 instead. Corollary 8.5. JU→VKsatisfies (comp-neutral) if: ●JUKsatisfies (comp-sn) and (comp-red); ●JVKsatisfies (comp-red) and (comp-neutral); ●JV′Ksatisfies (comp-lam) and (comp-small) whenever V′≤V. Proof. As for Corollary 6.17 but using Lemma 8.4 instead. Lemma 8.6. Let x∶Uand v∶V. Then, λxv is computable if: ●for all computable u∶U,vu xis computable; ●JUKsatisfies (comp-sn) and (comp-red) and contains a variable, which is the case if it satisfies (comp-neutral) too; 34 FRÉDÉRIC BLANQUI, JEAN-PIERRE JOUANNAUD, AND ALBERT RUBIO ●JVKsatisfies (comp-sn),(comp-red) and (comp-neutral); ●JV′Ksatisfies (comp-lam) whenever V′≤V; ●JWKsatisfies (comp-small) whenever W≤U→V. Proof. The proof is the same as for Lemma 6.18 except for the new case: ●(λFs)w=f(v),f∈ Fsand (∀i)λxv ≻τvi. By induction hypothesis, vare computable. Thus, wis computable since, by assumption, JWKsatisfies (comp-small). Corollary 8.7. JU→VKsatisfies (comp-lam) if: ●JUKsatisfies (comp-sn),(comp-red) and (comp-neutral); ●JVKsatisfies (comp-sn),(comp-red) and (comp-neutral); ●JV′Ksatisfies (comp-lam) whenever V′≤V; ●JWKsatisfies (comp-small) whenever W≤U→V. We are left with the new computability property for small symbols: Lemma 8.8. JUKsatisfies (comp-small) if: ●JUKsatisfies (comp-neutral); ●JU′Ksatisfies (comp-small) whenever U′<U; ●for every small f∣ T∣∶ T→U,J TKsatisfies (comp-sn) and (comp-red). Proof. Assume that fα(f)∶ T→Uis small. By assumption, J TKsatisfies (comp-sn) and, by Lemma 7.19, J TK⊆SN(≻τ∪⊐). Therefore, by Lemma 6.12, (>F,(≻τ∪⊐)stat)lex is wellfounded when restricted to small symbols. We can therefore prove that, for all (f, t) ∈ Σ with f∈Fs,f( t)is computable, by induction on (>F,(≻τ∪⊐)stat)lex (1). We first prove that f( t)is computable if all its ≻τ-reducts so are. If Uis a sort, then the result holds since  tare computable. Otherwise, by (small-acc), Acc(f)= ∅ and f( t)is neutral. Therefore, the result holds since JUKsatisfies (comp-neutral) by assumption. We now prove that every ≻τ-reduct w∶Wof f( t)is computable by induction on w(2). By definition of ≻τ, we have U≥W. ●(Fs⊳)(∃i)ti⪰τw. By assumption, J TKsatisfies (comp-red). Thus, wis computable. ●(Fs=) There are g∶ U→Wand u∶ Usuch that w=g(u),(∀i)f( t)≻τui,f≃Fg and  t(≻τ∪ ⊳∅ @⪰τ)stat(f)u. By (small-lt-big), gis small. Since f( t)≻τu, by induction hypothesis (2), uare computable. We distinguish two cases: –U>W. Then, g(u)is computable since JWKsatisfies (comp-small). –U=W. If ti⊳∅ @v⪰τujthen, by Lemma 7.22, ti⊐vand, by Lemma 7.18, v⊒uj. Therefore, by transitivity, ti⊐uj. Hence,  t(≻τ∪⊐)stat(f)uand, by induction hypothesis (1), g(u)is computable. ●(Fs>) There are g∶ U→Wand u∶ Usuch that w=g(u),(∀i)f( t)≻τuiand f>Fg. By (small-lt-big), gis small. Since f( t)≻τu, by induction hypothesis (2), u are computable. We distinguish two cases: –U>W. Then, g(u)is computable since JWKsatisfies (comp-small). –U=W. Then, g(u)is computable by induction hypothesis (1). ●(Fs@) There are uand vsuch that w=uv and f( t)≻τuv. By induction hypothesis (2), uand vare computable. Therefore, uv is computable. ●(FsX) Not possible. THE COMPUTABILITY PATH ORDERING 35 8.3. Well-foundedness of CPO with small symbols. In contrast with the previous cases, we cannot conclude from the above lemmas that, for every type T,JTKis a computability predicate, because of circularities. Indeed, for JAKto satisfy (comp-small), we need, for every small symbol f∶T→A,JTK to satisfy (comp-sn); but for JTKto satisfy (comp-sn) when T=U→V, we need JUKto satisfy (comp-neutral); but for JUKto satisfy (comp-neutral) when U=W→A, we need JAKto satisfy (comp-small). To break this circularity, we will make these dependencies more precise by introducing sets of positions in types that reflect how these computability properties depend from each other. The idea here is that if there is no problematic occurrence of Ain T, then JTKsatisfies (comp-sn), and similarly for the other properties. Instead of sets of positions, we could have simply considered boolean functions returning true if Tcontains a problematic occurrence of A. Considering positions allows us to pinpoint precisely which occurrences are problematic, and therefore to obtain sharper conditions on Fsensuring the absence of cycle in the dependency graph of the computability properties. Of course, one may think that there are different ways to carry out these proofs, resulting in different dependency graphs. We believe that these relationship are intrinsic to the computability properties, although we have not been able to substantiate this claim so far. Definition 8.9 (Computability-property positions).For each computability property (S standing for (comp-sn), Rfor (comp-red), Nfor (comp-neutral), Lfor (comp-lam) and C for (comp-small)), we inductively define a set of positions in a type Twrt a sort Aas follows: ●CPosA(A)={ε}and CPosA(B)= ∅ if B≠A ●SPosA(B)=RPosA(B)=NPosA(B)=LPosA(B)= ∅ whatever Aand Bare ●CPosA(U→V)=NPosA(U→V) ●SPosA(U→V)=RPosA(U→V)={1p∣p∈NPosA(U)} ∪{2p∣p∈SPosA(V)} ●NPosA(U→V)={1p∣p∈SPosA(U)∪RPosA(U)} ∪{2p∣p∈RPosA(V)∪NPosA(V)∪LPosA(V)∪CPosA(V)} ●LPosA(U→V)=CPosA(U→V) ∪{1p∣p∈SPosA(U)∪RPosA(U)∪NPosA(U)} ∪{2p∣p∈SPosA(V)∪RPosA(V)∪NPosA(V)∪LPosA(V)∪CPosA(V)} Note that RPosA(T)=SPosA(T)⊆LPosA(T)and NPosA(T)⊆CPosA(T). Straightforward simplifications then yield: ●NPosA(U→V)={1p∣p∈SPosA(U)} ∪{2p∣p∈LPosA(V)∪CP osA(V)} ●LPosA(U→V) =CPosA(U→V)∪{1p∣p∈SPosA(U)∪NPosA(U)}∪{2p∣p∈LPosA(V)∪CP osA(V)} We can now express in Figure 4 conditions on the types of the small symbols ensuring, as we shall show next, the absence of cycles in the dependency graph. Figure 4: Conditions on types of small symbols ∀f∣ T∣∶ T→A,(∀i)SorttA(Ti)∧SPosA(Ti)= ∅ (small-sort) ∀f∣ T∣∶ T→ U→Awith ∣ U∣>0,Acc(f)= ∅ ∧ (∀i)SorttA(Ti)∧Tit U→A(small-arrow) Consider the (small-sort) case and assume that TitA. Then, either Ti=Aand SPosA(Ti)= ∅ by definition, or Ti⋖Aand SPosA(Ti)= ∅ by Lemma 8.11. The condition for base types is therefore (strictly) weaker than the one for arrow types. This weaker 36 FRÉDÉRIC BLANQUI, JEAN-PIERRE JOUANNAUD, AND ALBERT RUBIO form will indeed be important later for deciding if a function symbol of base output type can be declared small. Lemma 8.10. If Sort⋖A(T), then SPosA(T)=NPosA(T)=LPosA(T)=CPosA(T)= ∅. Proof. By induction on T. ●T=B. Then, SPosA(T)=NPosA(T)=LPosA(T)= ∅ by definition. Since Sort⋖A(T), we have B≠Aand thus CPosA(T)= ∅ too. ●T=U→V. Since Sort<A(U)and Sort<A(V),SPosA(U)=NPosA(U)=LPosA(U)= CPosA(U)= ∅ and SPosA(V)=NPosA(V)=LPosA(V)=CPosA(V)= ∅ by induction hypothesis. Thus, SPosA(T)=NPosA(T)=LPosA(T)=CPosA(T)= ∅. Lemma 8.11. If T>T′and SorttA(T)then: ●SPosA(T′)= ∅ whenever SPosA(T)= ∅, ●NPosA(T′)= ∅ whenever NPosA(T)= ∅, ●LPosA(T′)= ∅ whenever LPosA(T)= ∅, ●CPosA(T′)= ∅ whenever CPosA(T)= ∅. Proof. We proceed by induction on T. Note that SorttA(T′)by Lemma 2.6. ●T=B. Since SorttA(T), we have B≤A. By transitivity, T′<A. Hence, by Lemma 2.5, Sort⋖A(T′). Therefore, SPosA(T′)=NPosA(T′)=LPosA(T′)=CPosA(T′)= ∅ by Lemma 8.10. ●T=U→V. Then, SorttA(U)and SorttA(V). –SPosA(T)= ∅. Then, NPosA(U)= ∅ and SPosA(V)= ∅. By (typ-arrow), there are two cases: ∗V≥T′. Then, SPosA(T′)= ∅ by induction hypothesis. ∗T′=U→V′and V>V′. By induction hypothesis, SPosA(V′)= ∅. Therefore, SPosA(T′)= ∅. –CPosA(T)=NPosA(T)= ∅. Then, SPosA(U)= ∅ and SPosA(V)=NPosA(V)= LPosA(V)=CPosA(V)= ∅. By (typ-arrow), there are two cases: ∗V≥T′. Then, CPosA(T′)=NPosA(T′)= ∅ by induction hypothesis. ∗T′=U→V′and V>V′, hence SPosA(V′)=NPosA(V′)=LPosA(V′)= CPosA(V′)= ∅ by induction hypothesis. CPosA(T′)=NPosA(T′)= ∅ follows. –LPosA(T)= ∅. Then, SPosA(U)=NPosA(U)= ∅ and SPosA(V)=NPosA(V)= LPosA(V)=CPosA(V)= ∅. By (typ-arrow), there are two cases: ∗V≥T′. Then, LPosA(T′)= ∅ by induction hypothesis. ∗T′=U→V′and V>V′. By induction hypothesis, SPosA(V)=NPosA(V)= LPosA(V)=CPosA(V)= ∅. Therefore, LPosA(T′)= ∅. Lemma 8.12. Let Abe a sort such that, for all sort B⋖A,JBKsatisfies (comp-small), and let Tbe a type such that SorttA(T). Then: ●JTKsatisfies (comp-sn) and (comp-red) if SPosA(T)= ∅, ●JTKsatisfies (comp-neutral) if NPosA(T)= ∅, ●JTKsatisfies (comp-lam) if LPosA(T)= ∅, ●JTKsatisfies (comp-small) if CPosA(T)= ∅. Proof. We proceed by induction on ⋗which is well-founded by (typ-sn). ●T=B. Since SorttA(T), we have BtA. THE COMPUTABILITY PATH ORDERING 37 –SPosA(T)= ∅.JTKsatisfies (comp-red) by Lemma 6.23. By Lemma 6.24, JTK satisfies (comp-sn) if, for all U<T,JUKsatisfies (comp-sn). So, let U<T. By transitivity, U⋖A. Hence, by Lemma 2.5, Sort⋖A(U)and, by Lemma 8.10, SPosA(U)= ∅. Therefore, by induction hypothesis, JUKsatisfies (comp-sn). –NPosA(T)= ∅.JTKsatisfies (comp-neutral) by Lemma 6.23. –LPosA(T)= ∅.JTKsatisfies (comp-lam) by Lemma 6.23. –CPosA(T)= ∅. Then, B⋖Aand, by assumption, JTKsatisfies (comp-small). ●T=U→V. Then, SorttA(U)and SorttA(V). –SPosA(T)= ∅. Then, NPosA(U)= ∅ and SPosA(V)= ∅. By induction hypothesis, JUKsatisfies (comp-neutral) and JVKsatisfies (comp-sn) and (comp-red). Hence, JTKsatisfies (comp-sn) and (comp-red) by Lemmas 6.13 and 6.14. –NPosA(T)= ∅. Then, SPosA(U)= ∅ and SPosA(V)=NPosA(V)=LPosA(V)= CPosA(V)= ∅. By induction hypothesis, JUKsatisfies (comp-sn) and (compred). Let now V′≤V. By Lemma 2.6, SorttA(V′). By Lemma 8.11, SPosA(V′)= NPosA(V′)=LPosA(V′)=CPosA(V′)= ∅. By (typ-right-subterm) and transitivity, T>V′. Hence, by induction hypothesis, JV′Ksatisfies (comp-red), (comp-neutral), (comp-lam) and (comp-small). Therefore, by Corollary 8.5, JTKsatisfies (comp-neutral). –CPosA(T)= ∅. Then, NPosA(T)= ∅, hence SPosA(U)= ∅ and SPosA(V)= NPosA(V)=LPosA(V)=CPosA(V)= ∅. We now check the conditions of Lemma 8.8: ∗JTKsatisfies (comp-neutral) since NPosA(T)= ∅. ∗Let W<T. We prove that CPosA(W)= ∅. By (typ-arrow), there are two cases: ⋅V≥W. Then, by Lemma 8.11, CPosA(W)=∅. ⋅W=U→V′and V>V′. Then, by Lemma 8.11, SPosA(V′)= NPosA(V′)=LPosA(V′)=CPosA(V′)=∅. Thus, CPosA(W)=∅. Hence, by induction hypothesis, JWKsatisfies (comp-small). ∗Let now f∣ T∣∶ T→Tbe small. There are  Band Bsuch that V= V→B. So, by (small-arrow), (∀i)SorttB(Ti)and TitT. We first prove that, if SorttA( S→B)and CPosA( S→B)=∅, then B⋖A, by induction on  S. If  Sis empty, then SorttA(B)and CPosA(B)= ∅. Thus, B⋖A. If  S=U V, then CPosA( S→B)=∅implies that CPosA( V→B)=∅. Hence, by induction hypothesis, B⋖A. We therefore have B⋖Afor T=U V→B,SorttA(T)and CPosA(T)=∅. Hence, Sort⋖A( T)and, by Lemma 8.10, SPosA( T)=∅. If Ti⋖T, then JTiK satisfies (comp-red) and (comp-sn) by induction hypothesis. Otherwise, Ti=Tand JTiKsatisfies (comp-red) and (comp-sn) as shown previously. –LPosA(T)=∅. Then, SPosA(U)=NPosA(U)=∅and SPosA(V)=NPosA(V)= LPosA(V)=CPosA(V)=∅. By induction hypothesis, JUKsatisfies (comp-sn), (comp-red) and (comp-neutral). Let now V′≤V. By Lemma 2.6, SorttA(V′). By Lemma 8.11, SPosA(V′)= NPosA(V′)=LPosA(V′)=CPosA(V′)=∅. By (typ-right-subterm) and transitivity, T>V′. Hence, by induction hypothesis, JV′Ksatisfies (comp-sn), (compred), (comp-neutral), (comp-lam) and (comp-small). 38 FRÉDÉRIC BLANQUI, JEAN-PIERRE JOUANNAUD, AND ALBERT RUBIO Let now W≤T. By Lemma 2.6, SorttA(W). Since LPosA(T)=∅, we have CPosA(T)=∅. Hence CPosA(W)=∅by Lemma 8.11. If W=T, we have already seen that JTKsatisfies (comp-small). Otherwise, W>Tand, by induction hypothesis, JWKsatisfies (comp-small). Therefore, by Corollary 8.7, JTKsatisfies (comp-lam). Theorem 8.13. For all type T,JTKis a computability predicate, i.e. satisfies (comp-sn), (comp-red),(comp-neutral),(comp-lam) and (comp-small). Proof. We proceed by induction on ⋗which is well-founded by assumption (typ-sn). We distinguish two cases: ●Tis a sort A. By Lemma 6.23, JAKsatisfies (comp-red), (comp-neutral), (comp-lam). By Lemma 6.24 and induction hypothesis, JAKsatisfies (comp-sn). Let W<A. By Lemma 2.5, Sort⋖A(W). By Lemma 8.10, CPosA(W)=∅. Therefore, JWKsatisfies (comp-small) by Lemma 8.12. Let now fα(f)∶ T→Abe small. By (small-sort), we have (∀i)SorttA(Ti)and SPosA(Ti)=∅. Therefore, J TKsatisfies (comp-sn) and (comp-red) by Lemma 8.12. Hence, JAKsatisfies (comp-small) by Lemma 8.8. ●Otherwise, T=U→V. Since T⊳lU, by induction hypothesis, JUKis a computability predicate. Let now V′be a type such that V≥V′. By (typ-right-subterm) and transitivity, T>V′. By induction hypothesis, JV′Kis a computability predicate. Therefore, JU→VKsatisfies (comp-sn) by Lemma 6.13, (comp-red) by Lemma 6.14, (comp-neutral) by Corollary 8.5, (comp-small) by Lemma 8.8 and (comp-lam) by Corollary 8.7. Theorem 8.14. The relation ≻τof Definition 8.1 is well-founded. Proof. After Theorem 6.11, Theorem 8.13 and Lemma 7.25. 8.4. Checking computability assumptions for small symbols. We explore here simple sufficient conditions under which the set SPosA(T)is empty, and therefore, which symbols whose output type is a sort Acan be declared as small. The order of a type plays an important role here. In case these conditions are not met, it is of course always possible to check (small-sort) and (small-arrow), which are both decidable. Lemma 8.15. SPosA(T)=∅if o(T)≤1. Proof. We proceed by induction on T. ●T=B. Then, SPosA(T)=∅by definition. ●T=U→V. Since o(T)≤1,o(U)≤0and o(V)≤1.Ubeing a sort, NPosA(U)=∅. Since o(V)≤1,SPosA(V)=∅by induction hypothesis. Hence SPosA(T)=∅. Can therefore be declared as small, any symbol whose type is of order less than or equal to 2since its arguments have then a type of order less than or equal to 1. This is in particular the case of the constructors of first-order data types. More generally, can be declared as small every constructor of a strictly-positive inductive type, whatever its order is, which is the class of inductive types allowed in the Coq proof assistant [52]: Lemma 8.16. Given types  Tand a sort A,SPosA( T→A)=∅if Sort⋖A( T). THE COMPUTABILITY PATH ORDERING 39 Proof. By induction on T. ●T=A. Immediate. ●T=U→V. Then, Sort⋖A(U)and Vis of the form  T→Awith Sort⋖A( T). By Lemma 8.10, NPosA(U)=∅. By induction hypothesis, SPosA(V)=∅. Therefore, SPosA(T)=∅. Non-strictly positive types are not available in Coq because strong elimination rules may cause non-terminating computations in Coq’s richer type system [28]. Nothing such can happen in our simple type system in which constructors of non-strictly positive inductive types of order ≤2can be declared as small: Lemma 8.17. NPosA(T)=LPosA(T)=CPosA(T)=∅if o(T)≤1,SorttA(T)and Pos(A, T )⊆ Pos−(T). Proof. We proceed by induction on T. ●T=B. Then, NPosA(T)=LPosA(T)=∅by definition. Since SorttA(T), we have B≤A. Since Pos(A, T )⊆Pos−(T)and Pos−(T)=∅, we have B≠A. Therefore, CPosA(T)=∅. ●T=U→V. Since o(T)≤1, we have o(U)≤0and o(V)≤1. Thus, Uis a sort and SPosA(U)=NPosA(U)=∅. By Lemma 8.15, SPosA(V)=∅. Since SorttA(T), we have SorttA(V). Since Pos(A, T )⊆Pos−(T), we have Pos(A, V )⊆Pos−(V). Hence, by induction hypothesis, NPosA(V)=LPosA(V)=CPosA(V)=∅. Therefore, NPosA(T)=LPosA(T)=CPosA(T)=∅. Lemma 8.18. SPosA(T)=∅if o(T)≤2,SorttA(T)and Pos(A, T )⊆Pos+(T). Proof. We proceed by induction on T. ●T=B. Then, SPosA(T)=∅by definition. ●T=U→V. Since o(T)≤2, we have o(U)≤1and o(V)≤2. Since SorttA(T), we have SorttA(U)and SorttA(V). Since Pos(A, T )⊆Pos+(T), we have Pos(A, U)⊆ Pos−(U)and Pos(A, V )⊆Pos+(V). Hence, by Lemma 8.17, NPosA(U)=∅and, by induction hypothesis, SPosA(V)=∅. Therefore, SPosA(T)=∅. But positivity is not always sufficient as shown by the following example. Assume that f∶T→Awith T=(B→N) → A,N=(B→A) → Band B<A. The sort Aoccurs negatively in Nand positively in T, which is a 3rd order type. We cannot declare fas small since we do not know how to prove that JTKsatisfies (comp-sn) by using our lemmas. Indeed, to prove that JTKsatisfies (comp-sn), we need to prove that JB→NKsatisfies (comp-neutral) (Lemma 6.13). To prove that JB→NKsatisfies (comp-neutral), we need to prove that JNK satisfies (comp-lam) (Corollary 8.5). To prove that JNKsatisfies (comp-lam), we need to prove that JB→AKsatisfies (comp-neutral) (Corollary 8.7). To prove that JB→AKsatisfies (comp-neutral), we need to prove that JAKsatisfies (comp-small) (Corollary 8.5). But, to prove that JAKsatisfies (comp-small), we need to prove that JTKsatisfies (comp-sn) (Lemma 8.8). The circularity has not been broken here, but we can of course declare fas being big instead of small. 8.5. Examples. In this section, we analyze two examples that show the need for small symbols and their use. We will see that CPO with small symbols contains not only core CPO, but also a subset of its transitive closure. But CPO with small symbols is not transitive 40 FRÉDÉRIC BLANQUI, JEAN-PIERRE JOUANNAUD, AND ALBERT RUBIO either, as shown by the second example which needs the use of both small symbols and the transitive closure. Example 8.19. Taken from the Termination Problems Data Base (TPDB) [84] under the name Applicative_05__TreeFlatten. Let abe a sort. Consider the function symbols nil ∶a,flatten ∶a→a,concat1∶a→a,cons2∶a→a→a,append2∶a→a→a,node2∶a→a→a and map2∶(a→a) → a→a. The higher-order rewrite system map(F, nil) → nil map(F, cons(x, v)) → cons(F x, map(F, v)) flatten node(x, v) → cons(x, concat(map(flatten, v))) concat(nil) → nil concat(cons(x, v)) → append(x, concat(v)) append(nil, v) → v append(cons(x, u), v) → cons(x, append(u, v)) can be proved terminating with CPO by considering concat,append,map,cons and nil small, while node and flatten can be either small or big (we consider them as big in the following). All symbols can have multiset status. Let the precedence be concat >Fappend >Fcons, node >Fmap >Fnil,node >Fflatten and map >Fcons. Let us show the proof of the third rule, which is the most interesting one. Since cons is small, we apply first (@Fs) and then we recursively need flatten node(x, v)≻τx, which holds by (@⊳) and then (Fb⊳), and flatten node(x, v)≻τconcat(map(flatten, v)), which needs (@Fs) again. We then recursively need flatten node(x, v)≻τmap(flatten, v), which generates the subgoal node(x, v)≻τmap(flatten, v)by (@⊳), and then the new subgoals node(x, v)≻τflatten and node(x, v)≻τvby (Fb>). We conclude by (Fb>) and (Fb⊳). The above example cannot be shown by core CPO because flatten is curried and the head symbol of the third rule is then an application. There is however a way out with the transitive closure of core CPO if one allows the introduction of new symbols. Let flattenunc1∶a→abe a new symbol. Assuming for example flatten >Fflattenunc and node >F{cons,concat,map,flatten}, we can then show the successive ordering comparisons: flatten node(x, v)≻τ(λx flattenunc(x))node(x, v) (λx flattenunc(x))node(x, v)≻τflattenunc(node(x, v)) flattenunc(node(x, v)) ≻τcons(x, concat(map(flatten, v))) The first reduces to flatten ≻τλx flattenunc(x), the second is a β-reduction, and the third is a classical RPO-like computation. Details are left to the reader. The use of small symbols can therefore help showing termination of examples that would otherwise require the use of the transitive closure of core CPO (as well as a signature extension in the above case). Small symbols, however, do not make CPO transitive. Our second example requires indeed using both small symbols and the transitive closure: Example 8.20. Taken from TPDB under the name AotoYamada_05__014. Let aand bbe sorts. Consider the function symbols 0∶b,nil ∶a,inc ∶a→a,double ∶a→a,s1∶b→b, plus1∶b→b→b,times1∶b→b→b,map1∶(b→b) → a→a, and cons2∶b→a→a. The higher-order rewrite system THE COMPUTABILITY PATH ORDERING 41 plus(0)x→x plus(s(y)) x→s(plus(y)x) times(0)x→0 times(s(y)) x→plus(times(y)x)x map(F)nil →nil map(F)cons(x, v) → cons(F x, map(F)v)) inc →map(plus(s(0))) double →map(times(s(s(0)))) can be proved terminating with CPO by taking a=bin the type ordering, cons and sas small symbols, the precedence times >Fplus,inc >F{map,plus,0},double >F{map,times,0}, and status multiset for all symbols. We consider the 4th rule, for which we shall use the transitive closure of CPO, and the 6th rule, for which small symbols are needed (for the second rule too). For the 4th rule, we exhibit the middle term (λz plus(times(y)z)z)xwhich is smaller than the lefthand side and β-reduces to the righthand side of the rule. To prove that times(s(y))xis greater than this middle term we apply (@=) and since the second arguments are equal we have to show that times(s(y)) ≻τ(λz plus(times(y)z)z). Since, both terms have the same type, by (Fbλ) and then (Fb@), we are left to show times(s(y)) ≻{z}plus(times(y)z), since times(s(y)) ≻{z}zholds by (FbX). For this last check, we apply first (Fb>) and then (Fb@), since times(s(y)) ≻{z}times(y)holds by (Fb=) and then (Fs⊳), and times(s(y)) ≻{z}zholds by (FbX). For the 6th rule we apply first (@Fs) which requires to check map(F)cons(x, v)≻τF x and map(F)cons(x, v)≻τmap(F)v. Since the types of both sides are equivalent, the first one holds by applying (@=) and then (Fb⊳) on the first argument and (Fs⊳) on the second one. Finally, for map(F)cons(x, v)≻τmap(F)vwe apply (@=) and then (Fs⊳) for the second argument. 9. Conclusion We have defined in this paper a well-founded relation on algebraic lambda-terms following a type discipline accepting simple types in the sense of Church, and inductive types in the sense of Martin-Löf. Further, we could easily cope with (implicitly) universally quantified type variables as in [57], a type discipline called weak polymorphism. We want to stress that core CPO has reached a point where we cannot expect any major improvement, as indicated by the counter-examples found to our own attempts to improve it. We are in great debt with Cynthia Kop and Femke van Raamsdonk for igniting this quest, by providing us with an example that removing the type check in the rule (Fb=) results in losing the well-foundedness property [59]. The very existence of these counter-examples supports our conviction that CPO defines an extremely sharp decidable approximation of sets of rules for which there exists a computability predicate. Of course, all these counter-examples still hold when adding inductive types and small symbols. We did our best to exploit the idea of small symbols as much as possible within our proof frame, but cannot argue that the conditions on the signature of small symbols are all necessary and that the corresponding recursive calls cannot be improved: we did not extend our quest for counter-examples to this question. We finally believe that there is