On the relation between size-based termination and semantic labelling
aa r X i v : . [ c s . L O ] J un On the relation between sized-types basedtermination and semanti labellingFrédéri Blanqui and Cody Roux (INRIA) FIT 3-604, Tsinghua University, Haidian Distri t, Beijing 100084, China,frederi .blanquiinria.fr LORIA ⋆⋆ , Pareo team, Campus S ienti(cid:28)que, BP 239, 54506 Vandoeuvre-lès-Nan y,Cedex, Fran e, ody.rouxloria.frAbstra t. We investigate the relationship between two independentlydeveloped termination te hniques. On the one hand, sized-types basedtermination (SBT) uses types annotated with size expressions and Gi-rard's redu ibility andidates, and applies on systems using onstru -tor mat hing only. On the other hand, semanti labelling transforms arewrite system by annotating ea h fun tion symbol with the semanti sof its arguments, and applies to any rewrite system.First, we introdu e a simpli(cid:28)ed version of SBT for the simply-typedlambda- al ulus. Then, we give new proofs of the orre tness of SBTusing semanti labelling, both in the (cid:28)rst and in the higher-order ase.As a onsequen e, we show that SBT an be extended to systems usingmat hing on de(cid:28)ned symbols (e.g. asso iative fun tions).1 Introdu tionSized types were independently introdu ed by Hughes, Pareto and Sabry [16℄and Giménez [11℄, and were extended to ri her type systems, to rewriting andto ri her size annotations by various resear hers [21, 1, 2, 5, 7℄.Sized types are types annotated with size expressions. For instan e, if T isthe type of binary trees then, for ea h a ∈ N , a type T a is introdu ed to typethe trees of height smaller or equal to a . In the general ase, the size is someordinal related to the interpretation of types in Girard's redu ibility andidates[12℄. However, as suggested in [5℄, other notions of sizes may be interesting.These size annotations an then be used to prove the termination of fun tionsby he king that the size of arguments de reases along re ursive alls, but thisapplies to fun tions de(cid:28)ned by using mat hing on onstru tor terms only.At about the same time, semanti labelling was introdu ed for (cid:28)rst-ordersystems by Zantema [22℄. It re eived a lot of attention in the last years and wasre ently extended to the higher-order ase by Hamana [13℄.In ontrast with SBT, semanti labelling is not a termination riterion buttransforms a system into another one whose termination is equivalent and hope-fully simpler to prove. The transformation onsists in annotating fun tion sym-bols with the semanti s of their arguments in some model of the rewrite system. ⋆⋆ UMR 7503 CNRS-INPL-INRIA-Nan y2-UHPinding a model may of ourse be di(cid:30) ult. We will see that the notion of sizeused in SBT provides su h a model.In this paper, we study the relationship between these two methods. In par-ti ular, we give a new proof of the orre tness of SBT using semanti labelling.This will enable us to extend SBT to systems using mat hing on de(cid:28)ned symbols.Outline. Se tion 2 introdu es our notations. Se tion 3 explains what SBT isand Se tion 4 introdu es a simpli(cid:28)ed version of it. To ease the understanding ofthe paper, we (cid:28)rst present the (cid:28)rst-order ase whi h already ontains the mainideas, and then onsider the higher-order ase whi h requires more knowledge.Hen e, in Se tion 5 (resp. 7), we re all what is semanti labelling in the (cid:28)rst(resp. higher) order ase and show in Se tion 6 (resp. 8) that SBT is an instan eof it. For la k of spa e, some proofs are given in the Appendi es of [8℄.2 PreliminariesFirst-order terms. A signature F is made of a set F n of fun tion symbols ofarity n for ea h n ∈ N . Let F be the set of all fun tion symbols. Given a set X of variables, the set of (cid:28)rst-order terms T ( F , X ) is de(cid:28)ned as usual: X ⊆ T ; if f ∈ F n and t is a sequen e t , . . . , t n ∈ T of length n = | t | , then f ( t ) ∈ T .An F -algebra M is given by a set M and, for ea h symbol f ∈ F n , a fun tion f M : M n → M . Given a valuation µ : X → M , the interpretation of a term t isde(cid:28)ned as follows: [[ x ]] µ = µ ( x ) and [[ f ( t , . . . , t n )]] µ = f M ([[ t ]] µ, . . . , [[ t n ]] µ ) .Positions are words on N . We denote by ε the empty word and by p · q or pq the on atenation of p and q . Given a term t , we denote by t | p the subterm of t at position p , and by t [ u ] p the repla ement of this subterm by u . Let Pos( f , t ) be the set of the positions of the o urren es of f in t .Higher-order terms. The set of (simple) types is T = T ( Σ ) where Σ = B is a set of base types, Σ = {⇒} and Σ n = ∅ otherwise. The sets of positive andnegative positions in a type are indu tively de(cid:28)ned as follows:(cid:21) Pos + ( B ) = ε and Pos − ( B ) = ∅ for ea h B ∈ B ,(cid:21) Pos δ ( T ⇒ U ) = 1 · Pos − δ ( T ) ∪ · Pos δ ( U ) where −− = + and − + = − .Let X be an in(cid:28)nite set of variables. A typing environment Γ is a mapfrom a (cid:28)nite subset of X to T . For ea h type T , we assume given a set F T offun tion symbols of type T . The sets Λ T ( Γ ) of terms of type T in Γ are de(cid:28)nedas usual: F T ⊆ Λ T ( Γ ) ; if ( x, T ) ∈ Γ then x ∈ Λ T ( Γ ) ; if t ∈ Λ U ( Γ, x : T ) , then λx T t ∈ Λ T ⇒ U ( Γ ) ; if t ∈ Λ U ⇒ V ( Γ ) and u ∈ Λ U ( Γ ) , then tu ∈ Λ V ( Γ ) .Let F (resp. Λ ) be the set of all fun tion symbols (resp. terms). Let X ( t ) be the set of free variables of t . A substitution σ is a map from a (cid:28)nite subsetof X to Λ . We denote by ( ux ) the substitution mapping x to u , and by tσ theappli ation of σ to t . A term t β -rewrites to a term u , written t → β u , if thereis p ∈ Pos( t ) su h that t | p = ( λx T v ) w and u = t [ v wx ] p .A rewrite rule is a pair of terms l → r of the same type su h that X ( r ) ⊆ X ( l ) .A rewrite system is a set R of rewrite rules. A term t rewrites to a term u , written t → R u , if there is p ∈ Pos( t ) , l → r ∈ R and σ su h that t | p = lσ and u = t [ rσ ] p .onstru tor systems. A fun tion symbol f is either a onstru tor symbol ifno rule left-hand side is headed by f , or a de(cid:28)ned symbol otherwise. A pattern isa variable or a term of the form c t with c a onstru tor symbol and t patterns. Arewrite system is onstru tor if every rule is of the form f l → r with l patterns.As usual, we assume that onstru tors form a valid indu tive stru ture [6℄,that is, there is a well-founded quasi-ordering ≤ B on B su h that, for ea h basetype B , onstru tor c : T ⇒ B and base type C o uring at position p in T i ,either C < B B or C ≃ B B and p ∈ Pos + ( T i ) . Mendler indeed showed that invalidindu tive stru tures lead to non-termination [18℄.Given a onstru tor c : T ⇒ B , let Ind( c ) be the set of integers i su h that T i ontains a base type C ≃ B B . A onstru tor c with Ind( c ) = ∅ is said re ursive.A onstru tor c : T ⇒ B is stri tly-positive if, for ea h i , either no base typeequivalent to B o urs in T i , or T i is of the form U ⇒ C with C ≃ B B and nobase type equivalent to B o uring in U .SBT applies to onstru tor systems only. By using semanti labelling, we willprove that it an also be applied to some non- onstru tor systems.3 Sized-types based terminationWe now present a simpli(cid:28)ed version of the termination riterion introdu ed in[5℄, where the (cid:28)rst author onsiders rewrite systems on terms of the Cal ulus ofAlgebrai Constru tions, a omplex type system with polymorphi and depen-dent types. Here, we restri t our attention to simply-typed λ -terms sin e thereis no extension of semanti labelling to polymorphi and dependent types yet.This termination riterion is based on the semanti s of types in redu ibility andidates [12℄. An arrow type T ⇒ U is interpreted by the set [[ T ⇒ U ]] = { v ∈ T | ∀ t ∈ [[ T ]] , vt ∈ [[ U ]] } . A base type B is interpreted by the (cid:28)xpoint [[ B ]] ofthe monotoni fun tion F B ( X ) = { v ∈ SN | ∀ onstru tor c : T ⇒ B , ∀ t , ∀ i ∈ Ind( c ) , v → ∗ c t ⇒ t i ∈ [[ T i ]] B X } on the latti e of redu ibility andidates thatis omplete for set in lusion [6℄. This (cid:28)xpoint, de(cid:28)ned by indu tion on the well-founded quasi-ordering ≤ B on base types, an be rea hed by trans(cid:28)nite iterationof F B up to some limit ordinal ω B stri tly smaller than the (cid:28)rst un ountableordinal A . This provides us with the following notion of size: the size of a term t ∈ [[ B ]] is the smallest ordinal o B ( t ) = a < A su h that t ∈ F a B ( ⊥ ) , where ⊥ is the smallest element of the latti e and F a B is the fun tion obtained after a trans(cid:28)nite iterations of F B .This notion of size, whi h orresponds to the tree height for patterns, hasthe following properties: it is well-founded; the size of a pattern is stri tly biggerthan the size of its subterms; if t → t ′ then the size of t ′ is smaller than (sin e → may be non on(cid:29)uent) or equal to the size of t .SBT onsists then in providing a way to synta ti ally represent the sizes ofterms and, given for ea h fun tion symbol an annotation des ribing how the sizeof its output is related to the sizes of its inputs, he k that some measure on thesizes of its arguments de reases in ea h re ursive all.ize algebra. Sizes are represented and ompared by using a (cid:28)rst-order termalgebra A = T ( Σ, X ) equipped with an ordering ≤ A su h that:(cid:21) < A is stable by substitution;(cid:21) ( A , < A ) , where < A is the usual ordering on ordinals, is a model of ( A , < A ) : • every symbol h ∈ Σ n is interpreted by a fun tion h A : A n → A ; • if a < A b then [[ a ]] µ < A [[ b ]] µ for ea h µ : X → A .To denote a size that annot be expressed in A (or a size that we do not are about), Σ is extended with a (biggest) nullary element ∞ . Let A be theextended term algebra in whi h all terms ontaining ∞ are identi(cid:28)ed, < A = < A ∪ { ( a, ∞ ) | a ∈ A} and ≤ A = ≤ A ∪ { ( a, ∞ ) | a ∈ A} . Note that su h an ex-tension is often used in domain theory but with a least element instead.Annotated types. The set of base types is now all the expressions B a su hthat B ∈ B and a ∈ A . The interpretation of B ∞ (also written B ) is [[ B ]] and,given a ∈ A , the interpretation of B a wrt a size valuation µ : X → A is the setof terms in [[ B ]] whose size is smaller or equal to [[ a ]] µ : [[ B a ]] µ = F [[ a ]] µ B ( ⊥ ) .Hen e, we assume that every symbol f ∈ F is given an annotated type τ A f whose size variables, like type variables in ML, are impli itly universally quan-ti(cid:28)ed and an be instantiated by any size expression. Hen e the typing rule forsymbols in Figure 1 allows any size substitution ϕ to be applied to τ A f . Subtypingnaturally follows from the interpretation of types and the ordering on A .Fig. 1. Type system with size annotations ϕ : X → A Γ ⊢ s f : τ A f ϕ ( x, T ) ∈ ΓΓ ⊢ s x : T Γ, x : T ⊢ s u : U x / ∈ ΓΓ ⊢ s λx T u : T ⇒ UΓ ⊢ s t : U ⇒ V Γ ⊢ s u : UΓ ⊢ s tu : V Γ ⊢ s t : T T ≤ T ′ Γ ⊢ s t : T ′ a ≤ A b B a ≤ B b T ′ ≤ T U ≤ U ′ T ⇒ U ≤ T ′ ⇒ U ′ T ≤ U U ≤ VT ≤ V De(cid:28)nition 1. Given a type T , let T ∞ be the type obtained by annotating everybase type with ∞ , and annot α B ( T ) be the type obtained by annotating every basetype C ≃ B B with α , and every base type C B B with ∞ . Conversely, given anannotated type T , let | T | be the type obtained by removing all annotations.Note that, in onstrast to types, terms are un hanged: in λx T u , T = T ∞ .Given a size symbol h ∈ Σ , let Mon + ( h ) (resp. Mon − ( h ) ) be the sets ofintegers i su h that h is monotoni (resp. anti-monotoni ) in its i -th argument.The sets of positive and negative positions in an annotated type are:(cid:21) Pos − ( B a ) = 0 · Pos − ( a ) and Pos + ( B a ) = { ε } ∪ · Pos + ( a ) ,(cid:21) Pos − ( α ) = ∅ , Pos + ( α ) = ε, Pos δ ( h ( a )) = S { i · Pos ǫδ ( a i ) | i ∈ Mon ǫ ( h ) , ǫ ∈ {− , + } } .o ease the expression of termination onditions, for every de(cid:28)ned symbol f , τ A f is assumed to be of the form P ⇒ B α f ⇒ B f A ( α f ) with | τ A f | = τ f , X ( P ) = ∅ and X ( f A ( α f )) ⊆ { α f } where α f are pairwise distin t variables. The argumentsof type B are the ones whose size will be taken into a ount for proving termi-nation. The arguments of type P are parameters and every rule de(cid:28)ning f mustbe of the form f pl → r with p ∈ X , | p | = | P | and | l | = | B | .Moreover, the annotated type of a onstru tor c : T . . . T n ⇒ B is: τ A c = annot α B ( T ) ⇒ . . . ⇒ annot α B ( T n ) ⇒ B c A ( α ) with c A ( α ) = ∞ if c is non-re ursive, and c A ( α ) = s ( α ) otherwise, where s isa monotoni unary symbol interpreted as the ordinal su essor and su h that a < A s ( a ) for ea h a .Termination riterion. We assume given a well-founded quasi-ordering ≥ F on F and, for ea h fun tion symbol f : s T ⇒ B α f ⇒ B f A ( α f ) and set X ∈ {A , A } , an ordered domain ( D X f , < X f ) and a fun tion ζ X f : X | α f | → D X f ompatible with ≃ F (i.e. | α f | = | α g | , D X f = D X g , < X f = < X g and ζ X f = ζ X g whenever f ≃ F g ) and su h that > A f is well-founded and ζ A f ([[ a ]] µ ) < A f ζ A f ([[ b ]] µ ) whenever ζ A f ( a ) < A f ζ A f ( b ) and µ : X → A .Usual domains are A n ordered lexi ographi ally, or the multisets on A orderedwith the multiset extension of > A .Theorem 1 ([5℄). Let R be a onstru tor system. The relation → β ∪ → R terminates if, for ea h de(cid:28)ned f : s P ⇒ B α ⇒ B f A ( α ) and rule f pl → r ∈ R ,there is an environment Γ and a size substitution ( aα ) su h that:(cid:21) pattern ondition: for ea h θ , if p θ ∈ [[ P ]] and l θ ∈ [[ B ]] then there is ν su hthat, for ea h ( x, T ) ∈ Γ , xθ ∈ [[ T ]] ν and [[ a ]] ν ≤ o B ( l θ ) ;(cid:21) argument de reasingness: Γ ⊢ s f a r : B f A ( a ) where ⊢ f a is de(cid:28)ned in Figure 2;(cid:21) size annotations monotoni ity: Pos( α , f A ( α )) ⊆ Pos + ( f A ( α )) .The termination riterion introdu ed in [5℄ is not expressed exa tly like this.The pattern ondition is repla ed by synta ti onditions implying the pattern ondition, but the termination proof is expli itly based on the pattern ondition.This ondition means that a is a valid representation of the size of l , whateverthe instantiation of the variables of l is, and thus that any re ursive all witharguments of size smaller than a is admissible. The existen e of su h a validsynta ti representation depends on l and the size annotations of onstru tors.With the hosen annotations, the ondition is not satis(cid:28)ed by some patterns(whose type admits elements of size bigger than ω , Appendix A). This suggeststo use a more pre ise annotation for onstru tors.The expressive power of the riterion depends on A . Taking the size algebra A redu ed to the su essor symbol s (the de idability of whi h is proved in [3℄) issu(cid:30) ient to handle every primitive re ursive fun tion. As an example, onsiderthe re ursor rec T : O ⇒ T ⇒ ( O ⇒ T ) ⇒ (( N ⇒ O ) ⇒ ( N ⇒ T ) ⇒ T ) ⇒ T on the type O of Brouwer's ordinals whose onstru tors are : O , s : O α ⇒ O s α and lim : ( N ⇒ O α ) ⇒ O s α , where N is the type of natural numbers whose onstru tors are : N and s : N α ⇒ N s α :ig. 2. Computability losure g < F f , ψ : X → A Γ ⊢ s f a g : τ A g ψ + variable, abstra tion, appli ation and subtyping rules of Fig. 1 g ≃ F f g : s U ⇒ C β ⇒ C g A ( β ) Γ ⊢ s f a u : U Γ ⊢ s f a m : B b ζ A f ( b ) < A f ζ A f ( a ) Γ ⊢ s f a g um : C g A ( b ) rec0 uvw → u rec ( s x ) uvw → vx ( rec xuvw ) rec ( lim f ) uvw → wf ( λn rec ( f n ) uvw ) For instan e, with f : N ⇒ O α , we have lim f : O s α , f n : O α and s α > A α .An example of non-simply terminating system satisfying the riterion is thefollowing system de(cid:28)ning a division fun tion / : N α ⇒ N ⇒ N α by using asubtra tion fun tion − : N α ⇒ N ⇒ N α . − x → x − x → − ( s x )( s y ) → − xy / x → / ( s x ) y → s ( / ( − xy ) y ) Indeed, with x : N x , we have s x : N s x , − xy : N x and s x > A x .4 Annotating onstru tor types with a max symbolIn this se tion, we simplify the previous termination riterion by annotating onstru tor types in an algebra made of the following symbols:(cid:21) ∈ Σ interpreted as the ordinal ;(cid:21) s ∈ Σ interpreted as the su essor ordinal;(cid:21) max ∈ Σ interpreted as the max on ordinals.For the annotated type of a onstru tor c : T . . . T n ⇒ B , we now take: τ A c = annot α B ( T ) ⇒ . . . ⇒ annot α n B ( T n ) ⇒ B c A ( α ,...,α n ) with α distin t variables, c A ( α ) = if c is non-re ursive, and c A ( α ) = s ( max ( α i | i ∈ Ind( c ))) otherwise, where max ( α , . . . , α k +1 ) = max ( α , max ( α , . . . , α k +1 )) and max ( α ) = α .This does not a(cid:27)e t the orre tness of Theorem 1 sin e, in this ase too, one an prove that onstru tors are omputable: c ∈ [[ τ A c ]] µ for ea h µ .Moreover, now, both onstru tors and de(cid:28)ned symbols have a type of theform annot α B ( T ) ⇒ . . . ⇒ annot α n B n ( T n ) ⇒ B f A ( α ) with α distin t variables.This means that a onstru tor an be applied to any sequen e of argumentswithout having to use subtyping. Indeed, previously, not all onstru tor ap-pli ations were possible (take c xy with c : B α ⇒ B α ⇒ b s α , x : B x and y : B y ) and some onstru tor appli ations required subtyping (take c x ( d x ) with c : B α ⇒ B α ⇒ b s α , d : B α ⇒ B s α and x : B x ).e an therefore postpone subtyping after typing without losing mu h ex-pressive power . It follows that every term has a most general type given by asimpli(cid:28)ed version of the type inferen e system ⊢ i of [3℄ using uni(cid:28) ation only(see Appendix B).Moreover, the pattern and monotoni ity onditions an always be satis(cid:28)edby de(cid:28)ning, for ea h symbol f : s P ⇒ B α ⇒ U and rule f pl → r ∈ R , a as σ ( l ) where σ ( x ) = x and σ ( c t ) = c A ( σ ( t )) , and Γ as the set of pairs ( x, T ) su h that x ∈ X ( f pl ) and T is:(cid:21) P i if x = p i ,(cid:21) B xi if x = l i ,(cid:21) annot x B i ( T ) if c u x v is a subterm of l i and c : U ⇒ T ⇒ V ⇒ C .Note that, if Γ ⊢ t : T and t is a non-variable pattern then there is a basetype B su h that Γ ⊢ i t : B σ ( t ) . So, σ ( t ) is the most general size of t .Theorem 2. Let R be a onstru tor system. The relation → β ∪ → R terminatesif, for ea h f : s P ⇒ B α ⇒ B f A ( α ) and rule f pl → r ∈ R , we have:(cid:21) argument de reasingness: Γ ⊢ i f a r : B a and a ≤ A f A ( a ) where Γ and a = σ ( l ) are de(cid:28)ned just before and ⊢ i f a is the type inferen e system ⊢ i [3℄ (see AppendixB) with fun tion appli ations restri ted as in Figure 2.The proof is given in Appendix C. In the following, we say that R SB-terminatesif R satis(cid:28)es the onditions of Theorem 2.5 First-order semanti labellingSemanti labelling is a transformation te hnique introdu ed by Hans Zantemafor proving the termination of (cid:28)rst-order rewrite systems [22℄. It onsists inlabelling fun tion symbols by using some model of the rewrite system.Let F be a (cid:28)rst-order signature and M be an F -algebra equipped with apartial order ≤ M . For ea h f ∈ F n , we assume given a non-empty poset ( S f , ≤ f ) and a labelling fun tion π f : M n → S f . Then, let F be the signature su h that F n = { f a | f ∈ F n , a ∈ S f } .The labelling of a term wrt a valuation µ : X → M is de(cid:28)ned as follows: lab µ ( x ) = x and lab µ ( f ( t , . . . , t n )) = f π f ([[ t ]] µ,..., [[ t n ]] µ ) ( lab µ ( t ) , . . . , lab µ ( t n )) .The fundamental theorem of semanti labelling is then:Theorem 3 ([22℄). Given a rewrite system R , an ordered F -algebra ( M , ≤ M ) and a labelling system ( S f , ≤ f , π f ) f ∈F , the relation → R terminates if:1. M is a quasi-model of R , that is:(cid:21) for ea h rule l → r ∈ R and valuation µ : X → M , [[ l ]] µ ≥ M [[ r ]] µ ,(cid:21) for ea h f ∈ F , f M is monotoni ;2. for ea h f ∈ F , π f is monotoni ;. the relation → lab ( R ) ∪ Decr terminates where: lab ( R ) = { lab µ ( l ) → lab µ ( r ) | l → r ∈ R , µ : X → M } , Decr = { f a ( x , . . . , x n ) → f b ( x , . . . , x n ) | f ∈ F , a > f b } .For instan e, by taking M = N , M = 0 , s M ( x ) = x + 1 , − M ( x, y ) = x and / M ( x, y ) = x , and by labelling − and / by the semanti s of their (cid:28)rst argument,we get the following in(cid:28)nite system whi h is easily proved terminating: − i x → x ( i ∈ N ) − x → − i +1 ( s x )( s y ) → − i xy ( i ∈ N ) / x → / i +1 ( s x ) y → s ( / i ( − i xy ) y ) ( i ∈ N ) ω and A = N [6℄. Moreover, bytaking Γ ( x ) = B x for ea h x of type B , every term t has a most general size σ ( t ) given by its most general type: Γ ⊢ i t : C σ ( t ) . This fun tion σ extends to allterms the fun tion σ de(cid:28)ned in the previous se tion by taking σ ( f ( t , . . . , t n )) = f A ( σ ( t ) , . . . , σ ( t n )) for ea h de(cid:28)ned symbol f .Theorem 4. SB-termination implies termination if:(cid:21) R is (cid:28)nitely bran hing and the set of onstru tors of ea h type B is (cid:28)nite;(cid:21) for ea h de(cid:28)ned symbol f , f A and ζ A f are monotoni .Proof. For the interpretation domain, we take M = A = N whi h has a stru tureof poset with ≤ M = ≤ A = ≤ N .If f A is not the onstant fun tion equal to ∞ ( f A = ∞ for short), whi h isthe ase of onstru tors, then let f M ( a ) = [[ f A ( α )]] µ where α µ = a .When f A = ∞ , we pro eed in a way similar to predi tive labelling [15℄, avariant of semanti labelling where only the semanti s of usable symbols need tobe given when M is a ⊔ -algebra (all (cid:28)nite subsets of M have a lub wrt ≤ M ),whi h is the ase of N . Here, the notions of usable symbols and rules are notne essary and a semanti s an be given to all symbols thanks to the strongassumptions of SB-termination.Let ( f , x ) > A ( g , y ) if f > F g or f ≃ F g and ζ A f ( x ) > A f ζ A f ( y ) . The relation > A is well-founded sin e the relations > F and > A f are well-founded. We thende(cid:28)ne f M by indu tion on > A by taking f M ( a ) = max ( { } ∪ { [[ r ]] µ | f l → r ∈R , µ : X → A , [[ l ]] µ ≤ a } ) . This fun tion is well de(cid:28)ned sin e:(cid:21) For ea h subterm g m in r , ( f , σ ( l )) > A ( g , σ ( m )) . Assume that f ≃ F g .Then, σ ( l ) > A σ ( m ) . Hen e, for ea h symbol f o uring in l or m , f A = ∞ .Therefore, [[ l ]] µ = [[ σ ( l )]] µ , [[ m ]] µ = [[ σ ( m )]] µ and ( f , [[ l ]] µ ) > A ( g , [[ m ]] µ ) . The set { ( f l → r, µ ) | f l → r ∈ R , [[ l ]] µ ≤ a } is (cid:28)nite. Indeed, sin e l arepatterns and onstru tors are interpreted by monotoni and stri tly extensivefun tions (i.e. c A ( α ) ≥ A s ( max ( α i | i ∈ Ind( c ))) ), [[ l ]] µ is stri tly monotoni wrt µ and the height of l . We annot have an in(cid:28)nite set of l 's of boundedheight sin e, for ea h base type B , the set of onstru tors of type B is (cid:28)nite.And we annot have an in(cid:28)nite set of r 's sin e R is (cid:28)nitely bran hing.We do not label the onstru tors, i.e. we take any singleton set for S c andthe unique ( onstant) fun tion from M n to S c for π c . For any other symbol f ,we take S f = D A f whi h is well-founded wrt > f , and π f = ζ A f .1. M is a quasi-model of R :(cid:21) Let f : s P ⇒ B α ⇒ B f A ( α ) , l → r ∈ R with l = f pl , and µ : X → M . We have [[ l ]] µ = f M ( a ) where a = [[ l ]] µ . If f A = ∞ , then f M ( a ) = max ( { } ∪ { [[ r ]] µ | f l → r ∈ R , µ : X → A , [[ l ]] µ ≤ a } ) and [[ l ]] µ ≥ [[ r ]] µ .Assume now that f A = ∞ . Sin e Γ ⊢ f a r : i B a and a ≤ A f A ( a ) , we have σ ( r ) = a ≤ A f A ( a ) = σ ( l ) where a = σ ( l ) . By de(cid:28)nition of Γ and σ , forea h i , a i = ∞ ( a = ∞ for short). Therefore, σ ( l ) = ∞ and σ ( r ) ≤ A σ ( l ) .Hen e, [[ l ]] µ = σ ( l ) µ ≤ A σ ( r ) µ = [[ r ]] µ sin e ≤ A is a model of ≤ A .(cid:21) If f is a non-re ursive onstru tor, then f M ( a ) = 0 is monotoni . If f is are ursive onstru tor, then f M ( a ) = sup { a i | i ∈ Ind( c ) } + 1 is monotoni .If f A = ∞ , then f M ( a ) = [[ f A ( α )]] µ where α µ = a is monotoni sin e f A is monotoni by assumption. Finally, if f A = ∞ , then f M ( a ) = max ( { } ∪{ [[ r ]] µ | f l → r ∈ R , µ : X → A , [[ l ]] µ ≤ a } ) is monotoni .2. If f is a de(cid:28)ned symbol, then the fun tion π f is monotoni by assumption. If f is a onstru tor, then the onstant fun tion π f is monotoni too.3. We now prove that → lab ( R ) ∪ Decr is pre eden e-terminating (PT), i.e. thereis a well-founded relation > on symbols su h that, for ea h rule f l → r ∈ lab ( R ) ∪ Decr , every symbol o urring in r is stri tly smaller than f [19℄.Let g a < f b if g < F f or g ≃ F f and a < A f b . The relation > is well-foundedsin e both > F and > A f are well-founded. Decr is learly PT wrt > . Let now f l → r ∈ R , µ : X → M and g t be asubterm of r . The label of f is a = π f ([[ l ]] µ ) = ζ A f ([[ σ ( l )]] µ ) and the label of g is b = ζ A f ([[ σ ( m )]] µ ) . By assumption, ( f , l ) > A ( g , m ) . Therefore, a > A f b . ⊓⊔ It is interesting to note that we ould also have taken M = A , assuming that < A f is stable by substitution ( ζ A f ( a θ ) < A f ζ A f ( b θ ) whenever ζ A f ( a ) < A f ζ A f ( b ) ).The system labelled with A is a synta ti approximation of the system labelledwith A . Although less powerful a priori, it may be interesting sin e it providesa (cid:28)nite representation of the in(cid:28)nite A -labelled system.Finally, we see from the proof that the system does not need to be onstru tor:Theorem 5. Theorem 4 holds for any (non- onstru tor) system R su h that,for ea h rule f l → r ∈ R with f A = ∞ and subterm g m in l :(cid:21) g A is monotoni and stri tly extensive: g A ( α ) ≥ A s ( max ( α i | i ∈ Ind( c ))) ,(cid:21) if g A = ∞ , then g < F f or g ≃ F f and ζ A f ( σ ( m )) < A f ζ A f ( σ ( l )) .xample: assuming that A is the ⇒ -type onstru tor, then the expression F nuv represents the set of n -ary fun tions from u to v . + y → y +( s x ) y → s (+ xy )+(+ xy ) z → + x (+ yz ) F0 uv → v F ( s x ) uv → A u ( F xuv ) F (+ xy ) uv → F xu ( F yuv ) Take + A ( x, y ) = ζ + ( x, y ) = a = 2 x + y + 1 , F A = ∞ and ζ F ( x, u, v ) = x . Theinterpretation of F M is well-de(cid:28)ned sin e x < a and y < a . The labelled systemthat we obtain (where b = 2 y + z + 1 ) is pre eden e-terminating: + y +1 y → y + a +2 ( s x ) y → s (+ a xy )+ a + z +1 (+ a xy ) z → + x + b +1 x (+ b yz ) F uv → v F x +1 ( s x ) uv → A u ( F x xuv ) F a (+ a xy ) uv → F x xu ( F y yuv ) F -monoids [10℄ is studied bythe same author and proved omplete for termination [14℄.The fundamental theorem of higher-order semanti labelling an be statedexa tly as in the (cid:28)rst-order ase, but the notion of model is more involved.CRSs and IDTSs. In CRSs, fun tion symbols have a (cid:28)xed arity. Meta-terms extend terms with the appli ation Z ( t , . . . , t n ) of a meta-variable Z ∈ Z of arity n to n meta-terms t , . . . , t n .An assignment θ maps every meta-variable of arity n to a term of the form λx ..λx n t . Its appli ation to a meta-term t , written tθ , is de(cid:28)ned as follows:(cid:21) xθ = x , ( λxt ) θ = λx ( tθ ) and f ( t , . . . , t n ) θ = f ( t θ, . . . , t n θ ) ;(cid:21) for θ ( Z ) = λx ..λx n t , Z ( t , . . . , t n ) θ = t { x t θ, . . . , x n t n θ } .A rule is a pair of meta-terms l → r su h that l is a higher-order pattern [20℄.In IDTSs, variables, meta-variables and symbols are equipped with types overa dis rete ategory B of base types. However, Hamana only onsiders stru turalmeta-terms where abstra tions only appear as arguments of a fun tion symbol,variables are restri ted to base types, meta-variables to (cid:28)rst-order types andfun tion symbols to se ond-order types. But, as already noti ed by Hamana,this is su(cid:30) ient to handle any rewrite system (see Se tion 8). Let I Z B ( Γ ) be theset of stru tural meta-terms of type B in Γ whose meta-variables are in Z .Models. The key idea of binding algebras [10℄ is to interpret variables bynatural numbers using De Bruijn levels , and to handle bound variables byextending the interpretation to typing environments.Let F be the ategory whose obje ts are the (cid:28)nite ardinals and whose arrowsfrom n to p are all the fun tions from n to p . Let E be the (sli e) ategory oftyping environments whose obje ts are the maps Γ : n → B and whose arrowsfrom Γ : n → B to ∆ : p → B are the fun tions ρ : n → p su h that Γ = ∆ ◦ ρ .Given Γ : n → B , let Γ + B : n + 1 → B be the environment su h that ( Γ + B )( n ) = B and ( Γ + B )( k ) = Γ ( k ) if k < n .et M be the fun tor ategory ( Set E ) B . An obje t of M (presheaf) is given bya family of sets M B ( Γ ) for every base type B and environment Γ and, for everybase type B and arrow f : Γ → ∆ , a fun tion M B ( f ) : M B ( Γ ) → M B ( ∆ ) su hthat M B ( id Γ ) = id M B ( Γ ) and M B ( f ◦ g ) = M B ( f ) ◦ M B ( g ) . An arrow α : M → N in M is a natural transformation, i.e. a family of fun tions α B ( Γ ) : M B ( Γ ) → N B ( Γ ) su h that, for ea h ρ : Γ → ∆ , α B ( ∆ ) ◦ M B ( ρ ) = N B ( ρ ) ◦ α B ( Γ ) .Given M ∈ M , Γ ∈ E and B ∈ B , let up B Γ ( M ) : M ( Γ ) → M ( Γ + B ) be thearrow equal to M ( id Γ + 0 ∆ ) where ∆ is the unique morphism from to ∆ .An X + F -algebra M is given by a presheaf M ∈ M , an interpretation ofvariables ι : X → M and, for every symbol f : ( B ⇒ B ) ⇒ . . . ⇒ ( B n ⇒ B n ) ⇒ B and environment Γ , an arrow f M ( Γ ) : Q ni =1 M B i ( Γ + B i ) → M B ( Γ ) .The ategory M forms a monoidal ategory with unit X and produ t • su hthat ( M • N ) B ( Γ ) is the set of equivalen e lasses on the set of pairs ( t, u ) with t ∈ M B ( ∆ ) and u i ∈ N ∆ ( i ) ( Γ ) for some ∆ , modulo the equivalen e relation ∼ su h that ( t, u ) ∼ ( t ′ , u ′ ) if there is ρ : ∆ → ∆ ′ for whi h t ∈ M B ( ∆ ) , t ′ = M B ( ρ )( t ) and u ′ ρ ( i ) = u i .To interpret substitutions, M must be an F -monoid, i.e. a monoid ( M, µ : M → M ) ompatible with the stru ture of F -algebra [13℄ (see Appendix E).The presheaf I ∅ equipped with the produ t µ B ( Γ )( t, u ) = t { i u i } (simul-taneous substitution) is initial in the ategory of F -monoids [14℄. Hen e, for ea h F -monoid M , there is a unique morphism ! M : I ∅ → M .Labelling. As in the (cid:28)rst-order ase, for ea h f : ( B ⇒ B ) ⇒ . . . ⇒ ( B n ⇒ B n ) ⇒ B , we assume given a non-empty poset ( S f , ≤ f ) for labels and a labellingfun tion π f ( Γ ) : Q ni =1 M B i ( Γ + B i ) → S f . Let F n = { f a | f ∈ F n , a ∈ S f } . Notethat the set of labelled meta-terms has a stru ture of F -monoid [13℄.The labelling of a meta-term wrt a valuation θ : Z → I ∅ is de(cid:28)ned as follows:(cid:21) lab θB ( Γ )( x ) = x ;(cid:21) lab θB ( Γ )( Z ( t , . . . , t n )) = Z ( lab θB ( Γ )( t ) , . . . , lab θB ( Γ )( t n )) ;(cid:21) for f : ( B ⇒ B ) ⇒ . . . ⇒ ( B n ⇒ B n ) ⇒ B and Γ i = Γ, x i : B i , lab θB ( Γ )( f ( λ x t , . . . , λ x n t n )) = f a ( lab θB ( Γ )( t ) , . . . , lab θB n ( Γ n )( t n )) where a = π f (! M B ( Γ )( t θ ) , . . . , ! M B n ( Γ n )( t n θ )) .We an now state Hamana's theorem for higher-order semanti labelling.Theorem 6 ([13℄). Given a stru tural IDTS R , an ordered F -algebra ( M , ≤ M ) and a labelling system ( S f , ≤ f , π f ) f ∈F , the relation → R terminates if:1. ( M , ≤ M ) is a quasi-model of R , that is:(cid:21) for ea h l → r : T ∈ R , θ : Z → I ∅ and Γ , ! M B ( Γ )( lθ ) ≥ M B ( Γ ) ! M B ( Γ )( rθ ) ,(cid:21) for ea h f ∈ F , f M is monotoni ;2. for ea h f ∈ F , π f is monotoni ;3. the relation → lab ( R ) ∪ Decr terminates, where: lab ( R ) = { lab ∅ B ( Γ )( lθ ) → lab ∅ B ( Γ )( rθ ) | l → r : B ∈ R , θ : Z → I ∅ , Γ ∈ E } , Decr = { f a ( . . . , λ x i Z i ( x i ) , . . . ) → f b ( . . . , λ x i Z i ( x i ) , . . . ) | f ∈ F , a > f b } . Higher-order aseIn order to apply Hamana's higher-order semanti labelling, we (cid:28)rst need totranslate into a stru tural IDTS not only the rewrite system R but also β itself.Translation to stru tural IDTS. Following Example 4.1 in [13℄, the rela-tions β and R an be en oded in a stru tural IDTS as follows.Let the set of IDTS base types B be the set T ( Σ ) where Σ = B is the setof base types, Σ = { Arr } and Σ n = ∅ otherwise. A simple type T an thenbe translated into an IDTS base type h T i by taking h T ⇒ U i = Arr ( h T i , h U i ) and h T i = T if T ∈ B . Then, an environment Γ an be translated into an IDTSenvironment h Γ i by taking h∅i = ∅ and h x : T, Γ i = x : h T i , h Γ i . Conversely, let | T | be the simple type su h that h| T |i = T .Let the set of IDTS fun tion symbols be the set hFi made of the symbols h f i : h T i ⇒ . . . ⇒ h T n i ⇒ B su h that f : T ⇒ . . . ⇒ T n ⇒ B , and all thesymbols λ UT : ( T ⇒ U ) ⇒ Arr ( T, U ) and @ UT : Arr ( T, U ) ⇒ T ⇒ U su h that T and U are IDTS base types. Note that only λ UT has a se ond order type.A simply-typed λ -term t su h that Γ ⊢ t : T an then be translated into anIDTS term h t i Γ su h that h Γ i ⊢ h t i Γ : h T i as follows:(cid:21) h x i Γ = x ,(cid:21) h λx T u i Γ = λ h U ih T i ( λx h u i Γ,x : T ) if Γ, x : T ⊢ u : U ,(cid:21) for f : T ⇒ . . . ⇒ T n ⇒ B and U i = T i +1 ⇒ . . . ⇒ T n ⇒ B , h f t . . . t k i Γ = λ h U k +1 ih T k +1 i ( λx k +1 . . . λ h U n ih T n i ( λx n h f i ( h t i Γ , . . . , h t k i Γ , x k +1 , . . . , x n )) ... ) ,(cid:21) h tu i Γ = @ h V ih U i ( h t i Γ , h u i Γ ) if Γ ⊢ t : U ⇒ V .A rewrite rule l → r ∈ R is then translated into the IDTS rule h l i → h r i where the free variables of l are seen as nullary meta-variables, and β -rewritingis translated into the family of IDTS rules h β i = S T,U ∈ B β UT where β UT is: @ UT ( λ UT ( λxZ ( x )) , X ) → Z ( X ) where Z (resp. X ) is a meta-variable of type T ⇒ U (resp. T ). Note that only h β i uses non-nullary meta-variables.Then, → R ∪ → β terminates i(cid:27) → hRi∪h β i terminates (Appendix F).Interpretation domain. We now de(cid:28)ne the interpretation domain M forinterpreting h β i ∪ hRi . First, we interpret environments as arrow types:(cid:21) M T ( Γ ) = N Arr ( Γ,T ) where: Arr ( ∅ , T ) = T and Arr ( Γ + U, T ) =
Arr ( Γ, Arr ( U, T )) .As explained at the beginning of Se tion 3, to every base type B ∈ B orre-sponds a limit ordinal ω B < A that is the number of trans(cid:28)nite iterations of themonotoni fun tion F B that is ne essary to build the interpretation of B .So, a (cid:28)rst idea is to take N B = ω B and the set of fun tions from N T to N U for N Arr ( T,U ) . But taking all fun tions reates some problems. Consider for instan ehe onstru tor lim : ( N ⇒ O ) ⇒ O . We expe t lim M ( ∅ )( f ) = sup { f ( n ) | n ∈ N N } + 1 to be a valid interpretation, but sup { f ( n ) | n ∈ N N } + 1 is not in N O forea h fun tion f . We therefore need to restri t N Arr ( T,U ) to the fun tions that orrespond to (are realized by) some λ -term.Hen e, let N T = { x | ∃ t ∈ T , t ⊢ T x } where ⊢ T is de(cid:28)ned as follows:(cid:21) t ⊢ B a ∈ ω B if t ∈ [[ B ]] and o B ( t ) ≥ a ,(cid:21) v ⊢ Arr ( T,U ) f : N T → N U if v ∈ [[ | T | ⇒ | U | ]] and vt ⊢ U f ( x ) whenever t ⊢ T x .Then, we an now he k that sup { f ( n ) | n ∈ N N } + 1 ∈ N O . Indeed, ifthere are v and t su h that v ⊢ Arr ( N , O ) f and t ⊢ N n , then vt ⊢ O f ( n ) and lim ( v ) ⊢ O sup { f ( n ) | n ∈ N N } + 1 ∈ N O .The a tion of M on E -morphisms is de(cid:28)ned as follows. Given f : Γ → ∆ with Γ : n → B and ∆ : p → B , let M T ( f ) : M T ( Γ ) → M T ( ∆ ) be the fun tionmapping x ∈ N Arr ( Γ,T ) , x ∈ N ∆ (1) , . . . , x p ∈ N ∆ ( p ) to x ( x f (1) , . . . , x f ( n ) ) .Finally, the sets M B ( Γ ) and N T are ordered as follows:(cid:21) x ≤ M B ( Γ ) y if x ≤ N Arr ( Γ,B ) y where: • x ≤ N B y if x ≤ y , • f ≤ N Arr ( T,U ) g if f ( x ) ≤ N U g ( x ) for ea h x ∈ N T .Interpretation of variables and fun tion symbols. As one an expe t,variables are interpreted by proje tions: ι Γ ( i ) ( Γ )( i )( x ) = x i , λ UT by the identity: ( λ UT ) M ( Γ )( f ) = f , and @ UT by the appli ation: (@ UT ) M ( Γ )( f, x )( y ) = f ( y , x ( y )) .One an he k that these fun tions are valid interpretations indeed, i.e. ι Γ ( i ) ( Γ )( i )( x ) ∈ N Γ ( i ) and (@ UT ) M ( Γ )( f, x )( y ) ∈ N U .Moreover, we have (@ UT ) M ( Γ )( f, x )( x ) = µ U ( Γ )( f, p x ) where p i = ι Γ ( i ) ( Γ )( i ) and µ is the monoidal produ t µ B ( Γ )( t, u . . . u n )( x ) = t ( u ( x ) , . . . , u n ( x )) .We an then verify that h β i is valid if ( M, µ ) is an F -monoid, and that ( M, µ ) is an F -monoid if, for ea h f and Γ , f M ( Γ )( x )( y ) = f M ( ∅ )( x ( y ) , . . . , x n ( y )) (Appendix G).One an see that ( λ UT ) M and (@ UT ) M satisfy this property. Moreover, for ea hterm t ∈ I ∅ T ( Γ ) , we have ! M T ( x : T ... x n : T n )( t )( a ) = [[ t ]] µ where x i µ = a i and: [[ x ]] µ = µ ( x ) [[@ UT ( v, t )]] µ = [[ v ]] µ ([[ t ]] µ ) [[ λ UT ( λxu )]] µ = a [[ u ]] µ ax [[ f ( t )]] µ = f M ( ∅ )([[ t ]] µ ) [[ Z ( t )]] µ = µ ( Z )([[ t ]] µ ) Higher-order size algebra. In the (cid:28)rst-order ase, the interpretation ofthe fun tion symbols f su h that f A is not the onstant fun tion equal to ∞ (whi h in ludes onstru tors) is f M ( a ) = [[ f A ( α )]] µ where α µ = a . To be ableto do the same thing in the higher-order ase, we need the size algebra A to bea typed higher-order algebra interpreted in the sets N T .Hen e, now, we assume that size expressions are simply-typed λ -terms overa typed signature Σ , and that every fun tion symbol f : τ f is interpreted by ∞ or a size expression f A : τ f . We then let σ : T → A be the fun tion that repla esin a term every symbol f by f A , all the terms ontaining ∞ being identi(cid:28)ed.Hen e, for ea h term t ontaining no symbol f su h that f A = ∞ , we have [ t ]] µ = [[ σ ( t )]] µ . Finally, we de(cid:28)ne < A as the relation su h that a < A b if, forea h µ , [[ a ]] µ < A [[ b ]] µ .For instan e, for a stri tly-positive onstru tor c : T ⇒ B with T i = U i ⇒ B i , we an assume that there is a symbol c A ∈ Σ interpreted by the fun tion c A ( x ) = sup { x i y i | i ∈ Ind( c ) , y i ∈ N h U i i } + 1 . Hen e, with Brouwer's ordinals,we have σ ( lim f ) = lim A f > A σ ( f n ) = f n .Thus, using su h an higher-order size algebra, we an on lude:Theorem 7. SB-termination implies termination if onstru tors are stri tly-positive and the onditions of Theorems 4 and 5 are satis(cid:28)ed.Proof. The proof is similar to the (cid:28)rst-order ase (Theorem 4). We only pointout the main di(cid:27)eren es.We (cid:28)rst he k that M is a quasi-model. The ase of h β i is detailed inAppendix G. For hRi , we use the fa ts that ! M B ( Γ )( lθ ) ≤ M B ( Γ ) ! M B ( Γ )( rθ ) if ! M B ( Γ )( lθ )( a ) ≤ M B ( ∅ ) ! M B ( Γ )( rθ )( a ) for ea h a , and that ! M B ( Γ )( lθ )( a ) = [[ l ]] θµ where x i µ = a i .We do not label appli ations and abstra tions. And for a de(cid:28)ned symbol f : B ⇒ B , we take S f = ` Γ Q ni =1 M B i ( Γ ) and π f ( Γ )( x ) = ( Γ, x ) .We now de(cid:28)ne a well-founded relation on S f that we will use for provingsome higher-order version of pre eden e-termination. For dealing with lab ( hRi ) ,let ( Γ, x ) > R f ( ∆, y ) if ∆ = Γ + Γ ′ and, for ea h zz ′ , ζ f ( . . . x i ( z ) . . . ) > A f ζ f ( . . . y i ( zz ′ ) . . . ) . For dealing with lab ( h β i ) , let ( Γ, x ) > β f ( ∆, y ) if Γ = ∆ + T and there is e su h that, for ea h i and z , x i ( z , e ( z )) = y i ( z ) . Sin e > R f ◦ > β f isin luded in > R f ∪ > β f ◦ > R f , the relation > f = > R f ∪ > β f is well-founded [9℄.One an easily he k that the fun tions π f and f M are monotoni .We are now left to prove that → lab ( h β i ) ∪ lab ( hRi ) ∪ Decr terminates. First, re-mark that → lab ( h β i ) is in luded in → ∗ Decr → h β i . Indeed, given @ UT ( λ UT ( λxlab U ( Γ + T )( u )) , lab T ( Γ )( t )) → lab U ( Γ )( u tx ) ∈ lab ( h β i ) , a symbol f o uring in u is la-belled in lab U ( Γ + T )( u ) by something like ( Γ + T + ∆, ! M B ( Γ + T + ∆ )( v )) , andby something like ( Γ + ∆, ! M B ( Γ + ∆ )( v tx )) in lab U ( Γ )( u tx ) . Hen e, the relation → lab ( h β i ) ∪ lab ( hRi ) ∪ Decr terminates if → h β i∪ lab ( hRi ) ∪ Decr terminates.By translating ba k IDTS types to simple types and removing the sym-bols λ UT (fun tion | | ), we get a β -IDTS [4℄ su h that → h β i∪ lab ( hRi ) ∪ Decr ter-minates if → |h β i∪ lab ( hRi ) ∪ Decr | terminates (Appendix F). Moreover, after [4℄, → |h β i∪ lab ( hRi ) ∪ Decr | terminates if | lab ( hRi ) ∪ Decr | satis(cid:28)es the General S hema(we do not need the results on solid IDTSs [13℄). This an be easily he ked byusing the pre eden e > on F su h that f a > g b if f > F g or f ≃ F g and a > f b B whose onstru tors are b : B α ⇒ B α ⇒ B s α , c : B α ⇒ B α , d : ( N ⇒ B α ) ⇒ B s α and e : B ∞ .Be ause of the onstru tor d , [[ B ]] has elements of size greater then ω . Forinstan e, d ( j ) where j : N ⇒ B is de(cid:28)ned by the rules j0 → e and j ( s x ) → c ( j x ) ,is of size ω + 1 .Consider now the pattern p = b x ( c ( c y )) for a fun tion f : B α ⇒ T .Sin e the types of the arguments of a onstru tor use the same size variable α , for p to be well typed, we need to take Γ = x : B s ( s β ) , y : B β and a = s ( s ( s β )) .Hen e, assuming that p ∈ [[ B ]] , there must be an ordinal b = βν su h that o ( x ) ≤ b + 2 , o ( y ) ≤ b and b + 3 ≤ o ( p ) = max { o ( x )+ 1 , o ( y )+ 3 } . Unfortunately,if we take an element x of size o ( x ) = ω +1 and an element y of size o ( y ) = 0 , thenthe previous set of onstraints, whi h redu es to ω +1 ≤ b +2 and b +3 ≤ ω +2 , isunsatis(cid:28)able. Indeed, for being satis(cid:28)able, ω should be a su essor ordinal whi his not the ase.B Type inferen eLet X ( Γ ) = S x ∈ dom( Γ ) X ( xΓ ) be the set of size variables o uring in the typesof the variables of dom( Γ ) .Fig. 3. Type inferen e system ( x, T ) ∈ ΓΓ ⊢ i x : T ρ : X ( τ A f ) → X \ X ( Γ ) renaming Γ ⊢ i f : τ A f ρ Γ, x : T ⊢ i u : UΓ ⊢ i λx T u : T ⇒ UΓ ⊢ i t : U ⇒ V Γ ⊢ i u : U ′ ρ : X ( U ′ ) \ X ( Γ ) → X \ ( X ( U ) ∪ X ( Γ )) renaming ϕ = mgu ( U, U ′ ρ ) with X ( Γ ) seen as onstants Γ ⊢ i tu : V ϕ
Lemma 1. The type inferen e relation of Figure 3 is orre t and omplete wrtthe typing relation of Figure 1 with the subtyping rules removed:(cid:21) If Γ ⊢ i t : T then Γ ⊢ t : T .(cid:21) If Γ ⊢ t : T then there is T ′ and ϕ su h that Γ ⊢ i t : T ′ and T ′ ϕ = T .Proof. (cid:21) Corre tness: By indu tion on Γ ⊢ i t : T , using stability by substitution.(cid:21) Completeness: By indu tion on Γ ⊢ t : T . We only detail the appli ation ase. By indu tion hypothesis, there is T ′ and ϕ , and U ′ and ψ su h that Γ ⊢ i t : T ′ , T ′ ϕ = U ⇒ V , Γ ⊢ i u : U ′ and U ′ ψ = U . It follows that T ′ is ofthe form A ⇒ B and U = Aϕ and Bϕ = V . Hen e, there is θ = mgu ( A, U ′ ) and ϕ ′ su h that ϕ = θϕ ′ . Therefore, Γ ⊢ i tu : Bθ and there is ϕ ′ su h that Bθϕ ′ = V . ⊓⊔ Proof of Theorem 2Proof. We prove that, for all θ , if p θ ∈ [[ P ]] and l θ ∈ [[ B ]] then there is ν su hthat, for all ( x, T ) ∈ Γ , xθ ∈ [[ T ]] ν and a ν = o B ( l θ ) .Let T be a type in whi h Pos( α, T ) ⊆ Pos + ( T ) . Then, [[ T ]] a α is a monotoni fun tion on a [5℄. Given t ∈ [[ T ]] A α , let o λαT ( t ) be the smallest ordinal a su h that t ∈ [[ T ]] a α . Note that o λα B α = o B .Let now ( x, T ) ∈ Γ . Sin e we have an indu tive stru ture, Pos( x, T ) ⊆ Pos + ( T ) . One an easily he k that xθ ∈ [[ T ]] µ where µ is the onstant valu-ation equal to A . We an thus de(cid:28)ne xν = o λxT ( xθ ) and we have xθ ∈ [[ T ]] ν .We now prove that a i ν = σ ( l i ) ν = o B ( l i θ ) by indu tion on l i . If l i = x and ( x, T ) ∈ Γ then σ ( l i ) = x , T = B xi and xν = o λx B xi ( xθ ) = o B i ( l i θ ) . Assumenow that l i = c t with c : T ⇒ C . If C is non-re ursive, then σ ( l i ) = 0 and σ ( l i ) ν = 0 = o B i ( l i θ ) . Otherwise, σ ( l i ) = s ( max ( σ ( t i ) , . . . , σ ( t i k ))) . If T i j is abase type then, by indu tion hypothesis, σ ( t i j ) ν = o T ij ( t i j θ ) . Otherwise, thereis ( x, T ) ∈ Γ su h that t i j = x and σ ( t i j ) ν = xν = o λxT ( xθ ) . Sin e o C ( l i θ ) = sup { o λα T ( t θ ) } + 1 , we have σ ( l i ) ν = o B i ( l i θ ) . ⊓⊔ D Example of non- onstru tor systemAssuming that A is the ⇒ -type onstru tor, then the expression F nuv de(cid:28)nedbelow represents the set of n -ary fun tions from u to v . + y → y +( s x ) y → s (+ xy )+( s x ) y → + x ( s y )+(+ xy ) z → + x (+ yz ) F0 uv → v F ( s x ) uv → A u ( F xuv ) F (+ xy ) uv → F xu ( F yuv ) Take + A ( x, y ) = ζ + ( x, y ) = a = 2 x + y + 1 , F A = ∞ and ζ F ( x, u, v ) = x . Theinterpretation of F M is well-de(cid:28)ned sin e x < a and y < a . The labelled systemthat we obtain (where b = 2 y + z + 1 ) is pre eden e-terminating: + y +1 y → y + a +2 ( s x ) y → s (+ a xy )+ a +2 ( s x ) y → + a +1 x ( s y )+ a + z +1 (+ a xy ) z → + x + b +1 x (+ b yz ) F uv → v F x +1 ( s x ) uv → A u ( F x xuv ) F a (+ a xy ) uv → F x xu ( F y yuv ) E F -monoidsTo interpret (higher-order) substitutions, a presheaf M must be an F -monoid,i.e. a monoid ( M, µ : M → M ) ompatible with the stru ture of F -algebra:(cid:21) µ B ( Γ )( ι B ( ∆ )( i ) , u ) = u i ;(cid:21) µ B ( Γ )( t, ι ∆ (1) ( Γ )(1) . . . ι ∆ ( p ) ( Γ )( p )) = t ;(cid:21) for t ∈ M B ( Θ ) , u i ∈ M Θ ( i ) ( ∆ ) and v i ∈ M ∆ ( i ) ( Γ ) , µ B ( Γ )( µ B ( ∆ )( t, u ) , v ) = µ B ( Γ )( t, µ Θ (1) ( Γ )( u , v ) . . . µ Θ ( p ) ( Γ )( u p , v )) ; for f : ( B ⇒ B ) ⇒ . . . ⇒ ( B n ⇒ B n ) ⇒ B and Γ i = Γ + B i , µ B ( Γ )( f M ( ∆ )( t ) , u ) = f M ( Γ )( µ B ( Γ )( t , v ) , . . . , µ B n ( Γ n )( t n , v n )) where v i,j = up B i Γ ( u j ) if j < | ∆ | , and v i,j = | Γ | + j − | ∆ | otherwise.In the ategory of F -monoids, the presheaf of meta-terms I Z equipped withthe produ t µ B ( Γ )( t, u ) = t { x u , . . . , x n u n } (simultaneous substitu-tion) is free. Hen e, given an F -monoid M , any valuation φ : Z → M an beuniquely extended into an F -monoid morphism φ ∗ : I Z → M su h that:(cid:21) φ ∗ B ( Γ )( x ) = ι B ( Γ )( x ) ;(cid:21) for Z : B ⇒ B , φ ∗ B ( Γ )( Z ( t , . . . , t n )) = µ B ( Γ )( φ B ( B )( Z ) , φ ∗ B i ( Γ )( t ) . . . φ ∗ B n ( Γ )( t n )) ;(cid:21) for f : ( B ⇒ B ) ⇒ . . . ⇒ ( B n ⇒ B n ) ⇒ B and Γ i = Γ, x i : B i , φ ∗ B ( Γ )( f ( λ x t , . . . , λ x n t n )) = ( f M ) B ( Γ )( φ ∗ B ( Γ )( t ) , . . . , φ ∗ B n ( Γ n )( t n )) .Given a labelled term t , let | t | be the term obtained after removing all labels.The presheaf of labelled meta-terms I Z has a stru ture of F -monoid for ea hvaluation θ : Z → I ∅ by taking:(cid:21) µ θB ( Γ )( i, u ) = u i ;(cid:21) for Z : B ⇒ B , µ θB ( Γ )( Z ( t , . . . , t n ) , u ) = Z ( µ θB ( Γ )( t ) , . . . , µ θB n ( Γ )( t n )) ;(cid:21) for f : ( B ⇒ B ) ⇒ . . . ⇒ ( B n ⇒ B n ) ⇒ B , Γ i = Γ + B i and u i ∈ I θ, Z ∆ ( i ) ( Γ ) , µ θB ( Γ )( f a ( λ x t , . . . , λ x n t n ) , u ) = f b ( µ θB ( Γ )( t , v ) , . . . , µ θB n ( Γ n )( t n , v n )) where b = π f B ( Γ )(! M B ( Γ )( | t | θ ) , . . . , ! M B n ( Γ n )( | t n | θ )) , v i,j = up B i Γ ( u j ) if j < | ∆ | , and v i,j = | Γ | + j − | ∆ | otherwise.F Translation to IDTS and β -IDTSFor the translation h i from λ -terms to se ond-order IDTS terms, we have thefollowing properties:Lemma 2. (cid:21) For all t and θ , h tθ i = h t ih θ i .(cid:21) If t → β ∪R u then h t i → h β i∪hRi h u i .We now introdu e a translation from a stru tural IDTS I having base typesin B and some symbols λ UT : ( T ⇒ U ) ⇒ Arr ( T, U ) for all T, U ∈ B , to anon-stru tural IDTS J having base types in B and no symbol λ UT : ( T ⇒ U ) ⇒ Arr ( T, U ) . The symbols of J are all the symbols symbols | f | : | T | ⇒ . . . ⇒| T n | ⇒ B su h that f : T ⇒ . . . ⇒ T n ⇒ B is a symbol of I distin t from some λ UT . A meta-term in I Z T ( Γ ) is then translated into a meta-term in | I | Z| T | ( | Γ | ) asfollows:(cid:21) | x | = x ,(cid:21) | f ( t , . . . , t n ) | = | f | ( | t | , . . . , | t n | ) ,(cid:21) λ UT ( λxu ) = λx | u | ,(cid:21) | Z ( t , . . . , t n ) | = Z ( | t | , . . . , | t n | ) .iven a set S of rules in I , let |S| be the set of rules | l | → | r | in | I | su h that l → r ∈ S .Lemma 3. (cid:21) For all t and θ , | tθ | = | t || θ | .(cid:21) If t → S u then | t | → |S| | u | .Note that @ UT ( λ UT ( λxZ ( x )) , X ) is translated into @ UT ( λxZ ( x ) , X ) . Hen e, if I has symbols @ UT : Arr ( T, U ) ⇒ T ⇒ U and rules @ UT ( λ UT ( λxZ ( x )) , X ) , then | I | is a β -IDTS and → h β i∪S terminates if |S| satis(cid:28)es the General S hema [4℄.G Validity of β Using the interpretation of @ UT and λ UT in Se tion 8:Lemma 4. If ( M, µ ) is an F -monoid, then h β i is valid in M .Proof. Let l and r be the left and right hand-sides of the rule β UT , θ : Z → I ∅ and Γ . Assume that θ ( Z ) = λxu and θ ( X ) = t . Then, lθ = @ UT ( λ UT ( λxu ) , t ) and rθ = u tx , and ! M U ( Γ )( lθ ) = (@ UT ) M ( Γ )( u , t ) = µ U ( Γ )( u , p t ) and ! M U ( Γ )( rθ ) =! M U ( Γ )( u tx ) , where u =! M U ( Γ, x : T )( u ) and t =! M T ( Γ )( t ) . We now prove by in-du tion on u that, for all Γ , L = µ U ( Γ )( u , p t ) is equal to R =! M U ( Γ )( u tx ) .(cid:21) u = x . Then, u tx = t , u = p n +1 and L = t = R .(cid:21) u = f ( λ x u , . . . , λ x p u p ) with f : ( B ⇒ B ) ⇒ . . . ⇒ ( B p ⇒ B p ) ⇒ B . Then, u tx = f ( λ x u tx , . . . , λ x p u ptx ) , R = f M ( Γ )( a ) where a i =! M B i ( Γ + B i )( u itx ) , and u = f M ( Γ + T )( u ∗ ) where u ∗ i =! M B i ( Γ + T + B i )( u i ) . Sin e M is an F -monoid, L = f M ( Γ )( b ) where b i = µ B i ( Γ + T + B i )( u ∗ i , v i ) . And, byindu tion hypothesis, we have b i = a i . ⊓⊔ Lemma 5. ( M, µ ) is an F -monoid if f M ( Γ )( x )( y ) = f M ( ∅ )( x ( y ) , . . . , x n ( y )) .Proof. Let f : ( B ⇒ B ) ⇒ . . . ⇒ ( B n ⇒ B n ) ⇒ B and Γ i = Γ + B i . We haveto prove that L = µ B ( Γ )( f M ( ∆ )( t ) , u ) is equal to R = f M ( Γ )( µ B ( Γ )( t , v ) ,. . . , µ B n ( Γ n )( t n , v n )) , where v i,j = up B i Γ ( u j ) if j < | ∆ | , and v i,j = | Γ | + j − | ∆ | otherwise.Let y i ∈ N Γ ( i ) . We have L ( y ) = f M ( ∆ )( t )( u ′ ) where u ′ j = u j ( y ) . Now, byassumption, L ( y ) = f M ( ∅ )( a ) where a i = t i ( u ′ ) , and R ( y ) = f M ( ∅ )( b ) where b i = µ B ( Γ )( t i , v i )( y ) = t i ( v ′ i ) and v ′ i,j = v i,j ( y ) . Hen e, L ( y ) = R ( y ) sin e v ′ i,j = u j ( y ) = u ′ j ..