LIX Beniamino Accattoli
email: beniamino.accattoli@inria.fr

Stéphane Graham-Lengrand
email: graham-lengrand@lix.polytechnique.fr

Delia Kesner
email: kesner@irif.fr.

Tight Typings and Split Bounds

Keywords: CCS Concepts:, Software and its engineering → General programming languages, • Social and professional topics → History of programming languages, lambda-calculus, type systems, cost models ACM Reference Format:

Multi types-aka non-idempotent intersection types-have been used to obtain quantitative bounds on higherorder programs, as pioneered by de Carvalho. Notably, they bound at the same time the number of evaluation steps and the size of the result. Recent results show that the number of steps can be taken as a reasonable time complexity measure. At the same time, however, these results suggest that multi types provide quite lax complexity bounds, because the size of the result can be exponentially bigger than the number of steps.

Starting from this observation, we refine and generalise a technique introduced by Bernadet & Graham-Lengrand to provide exact bounds for the maximal strategy. Our typing judgements carry two counters, one measuring evaluation lengths and the other measuring result sizes. In order to emphasise the modularity of the approach, we provide exact bounds for four evaluation strategies, both in the λ-calculus (head, leftmostoutermost, and maximal evaluation) and in the linear substitution calculus (linear head evaluation).

Our work aims at both capturing the results in the literature and extending them with new outcomes. Concerning the literature, it unifies de Carvalho and Bernadet & Graham-Lengrand via a uniform technique and a complexity-based perspective. The two main novelties are exact split bounds for the leftmost strategythe only known strategy that evaluates terms to full normal forms and provides a reasonable complexity measure-and the observation that the computing device hidden behind multi types is the notion of substitution at a distance, as implemented by the linear substitution calculus.

INTRODUCTION

Type systems enforce properties of programs, such as termination, deadlock-freedom, or productivity. This paper studies a class of type systems for the λ-calculus that refines termination by providing exact bounds for evaluation lengths and normal forms.

Intersection types and multi types. One of the cornerstones of the theory of λ-calculus is that intersection types characterise termination: not only typed programs terminate, but all terminating programs are typable as well [Coppo andDezani-Ciancaglini 1978, 1980;[START_REF] Krivine | Lambda-calculus, types and models[END_REF][START_REF] Pottinger | A Type Assignment for The Strongly Normalizable λ-terms[END_REF]. In fact, the λ-calculus comes with different notions of evaluation (e.g. call-by-name, call-byvalue, call-by-need, etc) to different notions of normal forms (head/weak/full, etc) and, accordingly, with different systems of intersection types.

Intersection types are a flexible tool and, even when one fixes a particular notion of evaluation and normal form, the type system can be formulated in various ways. A flavour that became quite convenient in the last 10 years is that of non-idempotent intersection types [START_REF] Daniel De | Sémantiques de la logique linéaire et temps de calcul[END_REF][START_REF] Gardner | Discovering Needed Reductions Using Type Theory[END_REF][START_REF] Assaf | A linearization of the Lambda-calculus and consequences[END_REF][START_REF] Peter | Types, potency, and idempotency: why nonlinearity and amnesia make a type system work[END_REF] (a survey can be found in [START_REF] Bucciarelli | Non-idempotent intersection types for the Lambda-Calculus[END_REF]), where the intersection A ∩ A is not equivalent to A. Non-idempotent intersection types are more informative than idempotent ones because they give rise to a quantitative approach, that allows counting resource consumption.

Non-idempotent intersections can be seen as multi-sets, which is why, to ease the language, we prefer to call them multi types rather than non-idempotent intersection types. Multi types have two main features:

(1) Bounds on evaluation lengths: they go beyond simply qualitative characterisations of termination, as typing derivations provide quantitative bounds on the length of evaluation (i.e. on the number of β-steps). Therefore, they give intensional insights on programs, and seem to provide a tool to reason about the complexity of programs.

(2) Linear logic interpretation: multi types are deeply linked to linear logic. The relational model [START_REF] Bucciarelli | On phase semantics and denotational semantics: the exponentials[END_REF][START_REF] Girard | Normal functors, power series and the λ-calculus[END_REF]] of linear logic (often considered as a sort of canonical model of linear logic) is based on multi-sets, and multi types can be seen as a syntactic presentation of the relational model of the λ-calculus induced by the interpretation into linear logic. These two facts together have a potential, fascinating consequence: they suggest that denotational semantics may provide abstract tools for complexity analyses, that are theoretically solid, being grounded on linear logic.

Various works in the literature explore the bounding power of multi types. Often, the bounding power is used qualitatively, i.e. without explicitely counting the number of steps, to characterise termination and / or the properties of the induced relational model. Indeed, multi types provide combinatorial proofs of termination that are simpler than those developed for (idempotent) intersection types (e.g. reducibility candidates). Several papers explore this approach under the call-by-name [START_REF] Bucciarelli | A relational semantics for parallelism and nondeterminism in a functional setting[END_REF][START_REF] Kesner | A Resource Aware Computational Interpretation for Herbelin's Syntax[END_REF][START_REF] Kesner | Types as Resources for Classical Natural Deduction[END_REF][START_REF] Ong | Quantitative semantics of the lambda calculus: Some generalisations of the relational model[END_REF][START_REF] Paolini | Essential and relational models[END_REF] or the call-by-value [START_REF] Carraro | A Semantical and Operational Account of Call-by-Value Solvability[END_REF][START_REF] Díaz-Caro | Call-by-Value Non-determinism in a Linear Logic Type Discipline[END_REF][START_REF] Ehrhard | Collapsing non-idempotent intersection types[END_REF]] operational semantics, or both [START_REF] Ehrhard | The Bang Calculus: an untyped lambda-calculus generalizing call-by-name and call-by-value[END_REF]. Sometimes, precise quantitative bounds are provided instead, as in [Bernadet and Graham-Lengrand 2013b;[START_REF] Daniel De | Sémantiques de la logique linéaire et temps de calcul[END_REF]. Multi types can also be used to provide characterisation of complexity classes [START_REF] Benedetti | A type assignment for λ-calculus complete both for FPTIME and strong normalization[END_REF]. Other qualitative [START_REF] Daniel De | The Relational Model Is Injective for Multiplicative Exponential Linear Logic[END_REF][START_REF] Guerrieri | Computing Connected Proof(-Structure)s From Their Taylor Expansion[END_REF]] and quantitative [START_REF] Daniel De Carvalho | A semantic measure of the execution time in linear logic[END_REF][START_REF] De | A semantic account of strong normalization in linear logic[END_REF] studies are also sometimes done in the more general context of linear logic, rather than in the λ-calculus.

Reasonable cost models. Usually, the quantitative works define a measure for typing derivations and show that the measure provides a bound on the length of evaluation sequences for typed terms. A criticism that could be raised against these results is, or rather was, that the number of β-steps of the bounded evaluation strategies might not be a reasonable cost model, that is, it might not be a reliable complexity measure. This is because no reasonable cost models for the λ-calculus were known at the time. But the understanding of cost models for the λ-calculus made significant progress in the last few years. Since the nineties, it is known that the number of steps for weak strategies (i.e. not reducing under abstraction) is a reasonable cost model [START_REF] Blelloch | Parallelism in Sequential Functional Languages[END_REF], where reasonable means polynomially related to the cost model of Turing machines. It is only in 2014, that a solution for the general case has been obtained: the length of leftmost evaluation to normal form was shown to be a reasonable cost model in [START_REF] Accattoli | Leftmost-Outermost) Beta-Reduction is Invariant, Indeed[END_REF]. In this work we essentially update the study of the bounding power of multi types with the insights coming from the study of reasonable cost models. In particular, we provide new answers to the question of whether denotational semantics can really be used as an accurate tool for complexity analyses.

Size explosion and lax bounds. The study of cost models made clear that evaluation lengths are independent from the size of their results. The skepticism about taking the number of β-steps as a reliable complexity measure comes from the size explosion problem, that is, the fact that the size of terms can grow exponentially with respect to the number of β-steps. When λ-terms are used to encode decision procedures, the normal forms (encoding true or false) are of constant size, and therefore there is no size explosion issue. But when λ-terms are used to compute other normal forms than Boolean values, there are families of terms {t n } n ∈N where t n has size linear in n, it evaluates to normal form in n β-steps, and produces a result p n of size Ω(2 n ), i.e. exponential in n. Moreover, the size explosion problem is extremely robust, as there are families for which the size explosion is independent of the evaluation strategy. The difficulty in proving that the length of a given strategy provides a reasonable cost model lies precisely in the fact that one needs a compact representation of normal forms, to avoid to fully compute them (because they can be huge and it would be too expensive). A divulgative introduction to reasonable cost models and size explosion is [START_REF] Accattoli | Efficiency and Reasonable Cost Models[END_REF]]. Now, multi typings do bound the number of β-steps of reasonable strategies, but these bounds are too generous since they bound at the same time the length of evaluations and the size of the normal forms. Therefore, even a notion of minimal typing (in the sense of being the smallest derivation) provides a bound that in some cases is exponentially worse than the number of β-steps.

Our observation is that the typings themselves are in fact much bigger than evaluation lengths, and so the widespread point of view for which multi types-and so the relational model of linear logic-faithfully capture evaluation lengths, or even the complexity, is misleading.

Contributions

The tightening technique. Our starting point is a technique introduced in a technical report by [Bernadet and Graham-Lengrand 2013a]. They study the case of strong normalisation, and present a multi type system where typing derivations of terms provide an upper bound on the number of β-steps to normal form. More interestingly, they show that every strongly normalising term admits a typing derivation that is sufficiently tight, where the obtained bound is exactly the length of the longest β-reduction path. This improved on previous results, e.g. [Bernadet and Graham-Lengrand 2013b;[START_REF] Bernadet | Complexity of Strongly Normalising Lambda-Terms via Non-idempotent Intersection Types[END_REF] where multi types provided the exact measure of longest evaluation paths plus the size of the normal forms which, as discussed above, can be exponentially bigger. Finally, they enrich the structure of base types so that, for those typing derivations providing the exact lengths, the type of a term gives the structure (and hence the size) of its normal form. This paper embraces this tightening technique, simplifying it with the use of tight constants for base types, and generalising it to a range of other evaluation strategies, described below.

It is natural to wonder how natural the tightening technique is-a malicious reader may indeed suspect that we are cooking up an ad-hoc way of measuring evaluation lengths, betraying the linear-logic-in-disguise spirit of multi types. To remove any doubt, we show that our tight typings are actually isomorphic to minimal multi typings without tight constants. Said differently, the tightening technique turns out to be a way of characterising minimal typings in the standard multi type framework (aka the relational model). Let us point out that, in the literature, there are characterisations of minimal typings (so-called principal typings) only for normal forms, and they extend to non-normal terms only indirectly, that is, by subject expansion of those for normal forms. Our approach, instead, provides a direct description, for any typable term.

Modular approach. We develop all our results by using a unique schema that modularly applies to different evaluation strategies. Our approach isolates the key concepts for the correctness and completeness of multi types, providing a powerful and modular technique, having at least two by-products. First, it reveals the relevance of neutral terms and of their properties with respect to types. Second, the concrete instantiations of the schema on four different cases always require subtle definitions, stressing the key conceptual properties of each case study.

Head and leftmost evaluation. Our first application of the tightening technique is to the head and leftmost evaluation strategies. The head case is the simplest possible one. The leftmost case is the natural iteration of the head one, and the only known strong strategy whose number of steps provides a reasonable cost model [START_REF] Accattoli | Leftmost-Outermost) Beta-Reduction is Invariant, Indeed[END_REF]. Multi types bounding the lengths of leftmost normalising terms have been also studied in [START_REF] Kesner | Quantitative Types for the Linear Substitution Calculus[END_REF], but the exact number of steps taken by the leftmost strategy has not been measured via multi types before-therefore, this is a new result, as we now explain.

The study of the head and the leftmost strategies, at first sight, seems to be a minor reformulation of de Carvalho's results about measuring via multi types the length of executions of the Krivine abstract machine (shortened KAM)-implementing weak head evaluation-and of the iterated KAM-that implements leftmost evaluation [START_REF] Daniel De | Execution Time of lambda-Terms via Denotational Semantics and Intersection Types[END_REF]. The study of cost models is here enlightening: de Carvalho's iterated KAM does implement leftmost evaluation, but the overhead of the machine (that is counted by de Carvalho's measure) is exponential in the number of β-steps, while here we only measure the number of β-steps, thus providing a much more parsimonious (and yet reasonable) measure.

The work of de Carvalho, Pagani and Tortora de Falco [START_REF] Daniel De Carvalho | A semantic measure of the execution time in linear logic[END_REF], using the relational model of linear logic to measure evaluation lengths in proof nets, is also closely related. They do not however split the bounds, that is, they do not have a way to measure separately the number of steps and the size of the normal form. Moreover, their notion of cut-elimination by levels does not correspond to leftmost evaluation.

Maximal evaluation. We also apply the technique to the maximal strategy, which takes the maximum number of steps to normal form, if any, and diverges otherwise. The maximal strategy has been bounded in [START_REF] Bernadet | Complexity of Strongly Normalising Lambda-Terms via Non-idempotent Intersection Types[END_REF], and exactly measured in [Bernadet and Graham-Lengrand 2013a] via the idea of tightening, as described above. With respect to [Bernadet and Graham-Lengrand 2013a], our technical development is simpler. The differences are:

(1) Uniformity with other strategies: The typing system used in [Bernadet and Graham-Lengrand 2013a] for the maximal strategy has a special rule for typing a λ-abstraction whose bound variable does not appear in the body. This special case is due to the fact that the empty multi type is forbidden in the grammar of function types. Here, we align the type grammar with that used for other evaluation strategies, allowing the empty multi type, which in turn allows the typing rules for λ-abstractions to be the same as for head and leftmost evaluation. This is not only simpler, but it also contributes to making the whole approach more uniform across the different strategies that we treat in the paper. Following the head and leftmost evaluation cases, our completeness theorem for the maximal strategy bears quantitative information (about e.g. evaluation lengths), in contrast with [Bernadet and Graham-Lengrand 2013a].

(2) Quantitative aspects of normal forms: Bernadet and Graham-Lengrand encode the shape of normal forms into base types. We simplify this by only using two tight constants for base types. On the other hand, we decompose the actual size of a typing derivation as the sum of two quantities: the first one is shown to match the maximal evaluation length of the typed term, and the second one is shown to match the size of its normal form together with the size of all terms that are erased by the evaluation process. Identifying what the second quantity captures is a new contribution.

(3) Neutral terms: we emphasise the key role of neutral terms in the technical development by describing their specificities with respect to typing. This is not explicitly broached in [Bernadet and Graham-Lengrand 2013a].

Linear head evaluation. Last, we apply the tightening technique to linear head evaluation [START_REF] Danos | Head Linear Reduction[END_REF][START_REF] Mascari | Head Linear Reduction and Pure Proof Net Extraction[END_REF] (lhd for short), formulated in the linear substitution calculus (LSC) [START_REF] Accattoli | An Abstract Factorization Theorem for Explicit Substitutions[END_REF][START_REF] Accattoli | A nonstandard standardization theorem[END_REF]], a λ-calculus with explicit substitutions that is strongly related to linear logic proof nets, and also a minor variation over a calculus by Milner [START_REF] Milner | Local Bigraphs and Confluence: Two Conjectures[END_REF]]. The literature contains a characterisation of lhd-normalisable terms [START_REF] Kesner | Quantitative Types for the Linear Substitution Calculus[END_REF]. Moreover, [START_REF] Daniel De | Sémantiques de la logique linéaire et temps de calcul[END_REF] measures the executions of the KAM, a result that can also be interpreted as a measure of lhd-evaluation. What we show however is stronger, and somewhat unexpected.

To bound lhd-evaluation, in fact, we can strongly stand on the bounds obtained for head evaluation. More precisely, the result for the exact bounds for head evaluation takes only into account the number of abstraction and application typing rules. For linear head evaluation, instead, we simply need to count also the axioms, i.e. the rules typing variable occurrences, nothing else. It turns out that the length of a linear head evaluation plus the size of the linear head normal form is exactly the size of the tight typing.

Said differently, multi typings simply encode evaluations in the LSC. In particular, we do not have to adapt multi types to the LSC, as for instance de Carvalho does to deal with the KAM. It actually is the other way around. As they are, multi typings naturally measure evaluations in the LSC. To measure evaluations in the λ-calculus, instead, one has to forget the role of the axioms. The best way to stress it, probably, is that the LSC is the computing device behind multi types.

Most proofs are provided in the long version of this paper [START_REF] Accattoli | Tight Typings and Split Bounds[END_REF]].

Other Related Works

Apart from the papers already cited, let us mention some other related works. A recent, general categorical framework to define intersection and multi type systems is in [START_REF] Mazza | Polyadic approximations, fibrations and intersection types[END_REF]].

While the inhabitation problem is undecidable for idempotent intersection types [Urzyczyn 1999], the quantitative aspects provided by multi types make it decidable [START_REF] Bucciarelli | The Inhabitation Problem for Non-idempotent Intersection Types[END_REF]. Intersection type are also used in [START_REF] Dudenhefner | Intersection type calculi of bounded dimension[END_REF] to give a bounded dimensional description of λ-terms via a notion of norm, which is resource-aware and orthogonal to that of rank. It is proved that inhabitation in bounded dimension is decidable (EXPSPACE-complete) and subsumes decidability in rank 2 [Urzyczyn 2009].

Other works propose a more practical perspective on resource-aware analyses for functional programs. In particular, type-based techniques for automatically inferring bounds on higher-order functions have been developed, based on sized types [START_REF] Avanzini | Automating sized-type inference for complexity analysis[END_REF][START_REF] Hughes | Proving the Correctness of Reactive Systems Using Sized Types[END_REF][START_REF] Álvaro | Cost Analysis Using Automatic Size and Time Inference[END_REF][START_REF] Vasconcelos | Inferring Cost Equations for Recursive, Polymorphic and Higher-Order Functional Programs[END_REF] or amortized analysis [START_REF] Hoffmann | Amortized Resource Analysis with Polynomial Potential -A Static Inference of Polynomial Bounds for Functional Programs[END_REF][START_REF] Hofmann | Static prediction of heap space usage for first-order functional programs[END_REF][START_REF] Jost | Type-Based Cost Analysis for Lazy Functional Languages[END_REF]. This led to practical cost analysis tools like Resource-Aware ML [START_REF] Hoffmann | Resource Aware ML[END_REF]] (see raml.co). Intersection types have been used [START_REF] Hugo | Using Intersection Types for Cost-Analysis of Higher-Order Polymorphic Functional Programs[END_REF]] to address the size aliasing problem of sized types, whereby cost analysis sometimes overapproximates cost to the point of losing all cost information [START_REF] Álvaro | Cost Analysis Using Automatic Size and Time Inference[END_REF]. How our multi types could further refine the integration of intersection types with sized types is a direction for future work, as is the more general combination of our method with the type-based cost analysis techniques mentioned above.

A BIRD'S EYE VIEW

Our study is based on a schema that is repeated for different evaluation strategies, making most notions parametric in the strategy -→ S under study. The following concepts constitute the main ingredients of our technique:

(1) Strategy, together with the normal, neutral, and abs predicates: there is a (deterministic) evaluation strategy -→ S whose normal forms are characterised via two related predicates, normal S (t) and neutral S (t), the intended meaning of the second one is that t is S-normal and can never behave as an abstraction (that is, it does not create a redex when applied to an argument). We further parametrise also this last notion by using a predicate abs S (t) identifying abstractions, because the definition of deterministic strategies requires some subterms to not be abstractions.

(2) Typing derivations: there is a multi types system which has three features:

• Tight constants: there are two new type constants neutral and abs, and rules to introduce them. As their name suggests, the constants neutral and abs are used to type terms whose normal form is neutral or an abstraction, respectively. • Tight derivations: there is a notion of tight derivation that requires a special use of the constants. • Indices: typing judgements have the shape Γ ⊢ ⊢ ⊢ (b,r ) t : τ , where b and r are indices meant to count, respectively, the number of steps to normal form and the size of the normal form.

(3) Sizes: there is a notion of size of terms that depends on the strategy, noted |t | S . Moreover, there is a notion of size of typing derivations |Φ| S that also depends on the strategy / type system, that coincides with the sum of the indices associated to the last judgement of Φ. (4) Characterisation: we prove that Γ ⊢ ⊢ ⊢ (b,r ) t : τ is a tight typing relatively to -→ S if and only if there exists an S normal term p such that t → b/2 S p and |p| S = r . (5) Proof technique: the characterisation is obtained always through the same sequence of intermediate results. Correctness follows from the fact that all tight typings of normal forms precisely measure their size, a substitution lemma for typing derivations and subject reduction. Completeness follows from the fact that every normal form admits a tight typing, an anti-substitution lemma for typing derivations, and subject expansion. (6) Neutral terms: we stress the relevance of neutral terms in normalisation proofs from a typing perspective. In particular, correctness theorems always rely on a lemma about them. Neutral terms are a common concept in the study of λ-calculus, playing a key role in, for instance, the reducibility candidate technique [START_REF] Girard | Proofs and types[END_REF]]. The proof schema is illustrated in the next section on two standard strategies, namely head and leftmost-outermost evaluation. It is then slightly adapted to deal with maximal evaluation in Sect. 5 and linear head evaluation in Sect. 6.

Evaluation systems. Each case study treated in the paper relies on the same properties of the strategy -→ S and the related predicates normal S (t), neutral S (t), and abs S (t), that we collect under the notion of evaluation system. Definition 2.1 (Evaluation system). Let T S be a set of terms, -→ S be a (deterministic) strategy and normal S , neutral S , and abs S be predicates on T S . All together they form an evaluation system S if for all t, p, p 1 , p 2 ∈ T S :

(

HEAD AND LEFTMOST-OUTERMOST EVALUATION

In this section we consider two evaluation systems at once. The two strategies are the famous head and leftmost-outermost evaluation. We treat the two cases together to stress the modularity of our technique. The set of λ-terms Λ is given by ordinary λ-terms: λ-Terms t, p x | λx .t | tp Normal, neutral, and abs predicates. The predicates normal hd and normal lo defining head and leftmost-outermost (shortened LO in the text and lo in mathematical symbols) normal terms are in Fig. 1, and they are based on two auxiliary predicates defining neutral terms: neutral hd and neutral lo -note that neutral lo (t) implies neutral hd (t). The predicates abs hd (t) and abs lo (t) are equal for the systems hd and lo and they are true simply when t is an abstraction.

Small-step semantics. The head and leftmost-outermost strategies -→ hd and -→ lo are both defined in Fig. 2. Note that these definitions rely on the predicates defining neutral terms and abstractions. Proposition 3.1 (Head and LO evaluation systems). Let S ∈ {hd, lo}. Then (Λ, -→ S , neutral S , normal S , abs S ) is an evaluation system.

The proof is routine.

Sizes. The notions of head size |t | hd and LO size |t | lo of a term t are defined as follows-the difference is on applications: Multi types. We define the following notions about types.

Head size LO size |x | hd := 0 |x | lo := 0 |λx .p| hd := |p| hd + 1 |λx .p| lo := |p| lo + 1 |pu | hd := |p| hd + 1 |pu | lo := |p| lo + |u| lo + 1 ' & $ % ax x : [τ ] ⊢ ⊢ ⊢ (0,0) x : τ Γ ⊢ ⊢ ⊢ (b,r ) t : τ fun b Γ \\ x ⊢ ⊢ ⊢ (b+1,r ) λx .t : Γ(x) → τ Γ ⊢ ⊢ ⊢ (b,r ) t : tight tight(Γ(x)) fun r Γ \\ x ⊢ ⊢ ⊢ (b,r +1) λx .t : abs Γ ⊢ ⊢ ⊢ (b,r ) t : M → τ ∆ ⊢ ⊢ ⊢ (b ′ ,r ′ ) p : M app b Γ ⊎ ∆ ⊢ ⊢ ⊢ (b+b ′ +1,r +r ′ ) tp : τ Γ ⊢ ⊢ ⊢ (b,r ) t : neutral app hd r Γ ⊢ ⊢ ⊢ (b,r +1) tp : neutral (∆ i ⊢ ⊢ ⊢ (b i ,r i ) t : τ i ) i ∈I many ⊎ i ∈I ∆ i ⊢ ⊢ ⊢ (+ i ∈I b i ,+ i ∈I r i ) t : [τ i ] i ∈I Γ ⊢ ⊢ ⊢ (b,r ) t : neutral ∆ ⊢ ⊢ ⊢ (b ′ ,r ′ ) p : tight app lo r Γ ⊎ ∆ ⊢ ⊢ ⊢ (b+b ′ ,r +r ′ +1) tp : neutral
• Multi types are defined by the following grammar:

Tight constants tight ::= neutral | abs Types τ , σ ::= tight | X | M → τ Multi-sets M ::= [τ i ] i ∈I (I a finite set)
where X ranges over a non-empty set of atomic types and ) for all x, in which case we also say that Γ is tight. • The multi-set union ⊎ is extended to typing contexts point-wise, i.e. Γ ⊎ ∆ maps each variable

x to Γ(x) ⊎ ∆(x). This notion is extended to several contexts as expected so that ⊎ i ∈I Γ i denotes a finite union of contexts (when I = ∅ the notation is to be understood as the empty context). We write Γ; x : M for Γ ⊎ (x → M) only if x dom(Γ). More generally, we write Γ; ∆ if the intersection between the domains of Γ and ∆ is empty.

• The restricted context Γ with respect to the variable x, written Γ\\x is defined by (Γ\\x)(x) := [ ] and (Γ \\ x)(y) := Γ(y) if y x.
Typing systems. There are two typing systems, one for head and one for LO evaluation. Their typing rules are presented in Fig. 3, the head system hd contains all the rules except app lo r , the LO system lo contains all the rules except app hd r . Roughly, the intuitions behind the typing rules are (please ignore the indices b and r for the time being):

• Rules ax, fun b , and app b : this rules are essentially the traditional rules for multi types for head and LO evaluation (see e.g. [START_REF] Bucciarelli | Non-idempotent intersection types for the Lambda-Calculus[END_REF]), modulo the presence of the indices. • Rule many: this is a structural rule allowing typing terms with a multi-set of types. In some presentations of multi types many is hardcoded in the right premise of the app b rule (that requires a multi-set). For technical reasons, it is preferable to separate it from app b . Morally, it corresponds to the !-promotion rule in linear logic. • Rule fun r : t has already been tightly typed, and all the types associated to x are also tight constants. Then λx .t receives the tight constant abs for abstractions. The consequence is that this abstraction can no longer be applied, because it has not an arrow type, and there are no rules to apply terms of type abs. Therefore, the abstraction constructor cannot be consumed by evaluation and it ends up in the normal form of the term, that has the form λx .t ′ . • Rule app hd r : t has already been tightly typed with neutral and so morally it head normalises to a term t ′ having neutral form xu 1 . . . u k . The rule adds a further argument p that cannot be consumed by evaluation, because t will never become an abstraction. Therefore, p ends up in the head normal form t ′ p of tp, that is still neutral-correctly, so that tp is also typed with neutral. Note that there is no need to type p because head evaluation never enters into arguments.

• Rule app lo r : similar to rule app hd r , except that LO evaluation enters into arguments and so the added argument p now also has to be typed, and with a tight constant. Note a key difference with app b : in app lo r the argument p is typed exactly once (that is, the type is not a multi-set)correctly, because its LO normal form p ′ appears exactly once in the LO normal form t ′ p ′ of tp (where t ′ is the LO normal form of t).

• Tight constants and predicates: there is of course a correlation between the tight constants neutral and abs and the predicates neutral S and abs S . Namely, a term t is S-typable with neutral if and only if the S-normal form of t verifies the predicate neutral S , as we shall prove. For the tight constant abs and the predicate abs S the situation is similar but weaker: if the S-normal form of t verifies abs S then t is typable with abs, but not the other way around-for instance a variable is typable with abs without being an abstraction. • The type systems are not syntax-directed, e.g. given an abstraction (resp. an application), it can be typed with rule fun r or fun b (resp. app r or app b ), depending on whether the constructor typed by the rule ends up in the normal form or not. Thus for example, given the term II, where I is the identity function λz.z, the second occurrence of I can be typed with abs using rule fun r , while the first one can be typed with [abs] → abs using rule fun b . Typing judgements are of the form Γ ⊢ ⊢ ⊢ (b,r ) t : τ , where (b, r ) is a pair of integers whose intended meaning is explained in the next paragraph. We write Φ ▷ S Γ ⊢ ⊢ ⊢ (b,r ) t : τ , with S being either hd or lo, if Φ is a typing derivation in the system S and ends in the judgement Γ ⊢ ⊢ ⊢ (b,r ) t : τ .

Indices. The roles of b and r can be described as follows:

• b and β-steps: b counts the rules of the derivation that can be used to form β-redexes, i.e. the number of fun b and app b rules. Morally, b is at least twice the number of β-steps to normal form because typing a β-redex requires two rules. For tight typing derivations (introduced below), we are going to prove that b is the exact (double of the) length of the evaluation of the typed term to its normal form, according to the chosen evaluation strategy. • r and size of the result: r counts the rules typing constructors that cannot be consumed by β-reduction according to the chosen evaluation strategy. It counts the number of fun r and app r . These rules type the result of the evaluation, according to the chosen strategy, and measure the size of the result. Both the notion of result and the way its size is measured depend on the evaluation strategy.

Typing size. We define both the head and the LO size |Φ| hd and |Φ| lo of a typing derivation Φ as the number of rules in Φ, not counting rules ax and many. The size of a derivation is reflected by the pair of indices (b, r ) on its final judgement: whenever Φ ▷ S Γ ⊢ ⊢ ⊢ (b,r ) t : τ , we have b + r = |Φ| S . Note indeed that every rule (except ax and many) adds exactly 1 to this size.

For systems hd and lo, the indices on typing judgements are not really needed, as b can be recovered as the number of fun b and app b rules, and r as the number of fun r and app hd r /app lo r rules. We prefer to make them explicit because 1) we want to stress the separate counting, and 2) for linear head evaluation in Sect. 6 the counting shall be more involved, and the indices shall not be recoverable.

The fact that ax is not counted for |Φ| hd and |Φ| lo shall change in Sect. 6, where we show that counting ax rules corresponds to measure evaluations in the linear substitution calculus. The fact that many is not counted, instead, is due to the fact that it does not correspond to any constructor on terms. A further reason is that the rule may be eliminated by absorbing it in the app b rule, that is the only rule that uses multi-sets-it is however technically convenient to separate the two.

Subtleties and easy facts. Let us overview some peculiarities and consequences of the definition of our type systems.

(1) Relevance: No weakening is allowed in axioms. An easy induction on typing derivations shows that a variable declaration x : M [ ] appears explicitly in the typing context Γ of a type derivation for t only if x occurs free in some typed subterm of t. In system lo, all subterms of t are typed, and so x : M [ ] appears in Γ if and only if x ∈ fv(t). In system hd, instead, arguments of applications might not be typed (because of rule app hd r ), and so there may be x ∈ fv(t) but not appearing in Γ.

(2) Vacuous abstractions: we rely on the convention that the two abstraction rules can always abstract a variable x not explicitly occurring in the context. Indeed, in the fun b rule, if

x dom(Γ), then Γ \\ x is equal to Γ and Γ(x) is [ ], while in the fun r rule, if x dom(Γ), then Γ(x)
is [ ] and thus tight([ ]) holds.

(3) Head typings and applications: note the app hd r rule types an application tp without typing the right subterm p. This matches the fact that tp is a head normal form when t is, independently of the status of p. Tight derivations. A given term t may have many different typing derivations, indexed by different pairs (b, r ). They always provide upper bounds on -→ S -evaluation lengths and lower bounds on the S-size | • | S of S-normal forms, respectively. The interesting aspect of our type systems, however, is that there is a simple description of a class of typing derivations that provide exact bounds for these quantities, as we shall show. Their definition relies on tight constants. Definition 3.2 (Tight derivations).

Let S ∈ {hd, lo}. A derivation Φ ▷ S Γ ⊢ ⊢ ⊢ (b,r ) t : σ is tight if tight(σ ) and tight(Γ).
Let us stress that, remarkably, tightness is expressed as a property of the last judgement only. This is however not so unusual: characterisations of weakly normalising terms via intersection/multi types also rely on properties of the last judgement only, as discussed in Sect. 7.

In Sect. 7, in particular, we show the the size of a tight derivation for a term t is minimal among derivations for t. Moreover, it is also the same size of the minimal derivations making no use of tight constants nor rules using them. Therefore, tight derivations may be thought as a characterisation of minimal derivations.

Example. Let t 0 = (λx 1 .(λx 0 .x 0 x 1 )x 1 )I, where I is the identity function λz.z. Let us first consider the head evaluation of t 0 to hd normal-form:

(λx 1 .(λx 0 .x 0 x 1 )x 1 )I - → hd (λx 0 .x 0 I)I - → hd II - → hd I
The evaluation sequence has length 3. The head normal form has size 1. To give a tight typing for the term t 0 let us write abs 1 for [abs] → abs. Then,

x 0 : [abs 1 ] ⊢ ⊢ ⊢ (0, 0) x 0 : abs 1 x 1 : [abs] ⊢ ⊢ ⊢ (0, 0) x 1 : abs x 1 : [abs] ⊢ ⊢ ⊢ (0, 0) x 1 : [abs]
x 0 : [abs 1 ], x 1 : [abs] ⊢ ⊢ ⊢ (1, 0) x 0 x 1 : abs

x 1 : [abs] ⊢ ⊢ ⊢ (2, 0) λx 0 .x 0 x 1 : [abs 1 ] → abs x 1 : [abs 1 ] ⊢ ⊢ ⊢ (0, 0) x 1 : abs 1 x 1 : [abs 1 ] ⊢ ⊢ ⊢ (0, 0) x 1 : [abs 1 ] x 1 : [abs, abs 1 ] ⊢ ⊢ ⊢ (3, 0) (λx 0 .x 0 x 1 )x 1 : abs ⊢ ⊢ ⊢ (4, 0) λx 1 .(λx 0 .x 0 x 1 )x 1 : [abs, abs 1 ] → abs . . . ⊢ ⊢ ⊢ (1, 1) I : [abs, abs 1 ]
⊢ ⊢ ⊢ (6, 1) (λx 1 .(λx 0 .x 0 x 1 )x 1 )I : abs Indeed, the pair (6, 1) represents 6/2 = 3 evaluation steps to hd normal-form and a head normal form of size 1.

Tight Correctness

Correctness of tight typings is the fact that whenever a term is tightly typable with indices (b, r ), then b is exactly (the double of) the number of evaluation steps to S-normal form while r is exactly the size of the S-normal form. Thus, tight typing in system hd (resp. lo) gives information about hd-evaluation to hd-normal form (resp. lo-evaluation to lo-normal form). The correctness theorem is always obtained via three intermediate steps.

First step: tight typings of normal forms. The first step is to show that, when a tightly typed term is a S-normal form, then the first index b of its type derivation is 0, so that it correctly captures the (double of the) number of steps, and the second index r coincides exactly with its S-size. Proposition 3.3 (Properties of hd and lo tight typings for normal forms). Let S ∈ {hd, lo}, t be such that normal S (t), and Φ ▷ S Γ ⊢ ⊢ ⊢ (b,r ) t : τ be a typing derivation.

(1) Size bound: |t | S ≤ |Φ| S .

(2) Tightness: if Φ is tight then b = 0 and r = |t | S .

(3) Neutrality: if τ = neutral then neutral S (t).

The proof is by induction on the typing derivation Φ. Let us stress three points:

(1) Minimality: the size of typings of a normal form t always bounds the size of t (Proposition 3.3.1), and therefore tight typings, that provide an exact bound (Proposition 3.3.2), are typing of minimal size. For the sake of conciseness, in most of the paper we focus on tight typings only. In Sect. 7, however, we study in detail the relationship between arbitrary typings and tight typings, extending their minimality beyond normal forms.

(2) Size of tight typings: note that Proposition 3.3.2 indirectly shows that all tight typings have the same indices, and therefore the same size. The only way in which two tight typings can differ, in fact, is whether the variables in the typing context are typed with neutral or abs, but the structure of different typings is necessarily the same (which is also the structure of the S-normal form itself).

(3) Unveiling of a key structural property: Proposition 3.3 relies on the following interesting lemma about S-neutral terms and tight typings.

Lemma 3.4 (Tight spreading on neutral terms). Let S ∈ {hd, lo}, t be such that neutral hd (t), and Φ ▷ S Γ ⊢ ⊢ ⊢ (b,r ) t : τ be a typing derivation such that tight(Γ). Then tight(τ ).

The lemma expresses the fact that tightness of neutral terms only depends on their contexts. Morally, this fact is what makes tightness to be expressible as a property of the final judgement only. We shall see in Sect. 7 that a similar property is hidden in more traditional approaches to weak normalisation (see Lemma 7.6). Such a spreading property appears repeatedly in our study, and we believe that its isolation is one of the contributions of our work, induced by the modular and comparative study of various strategies.

Second step: substitution lemma. Then one has to show that types, typings, and indices behave well with respect to substitution, which is essential, given that β-reduction is based on it. Lemma 3.5 (Substitution and typings for hd and lo). The following rule is admissible in both systems hd and lo:

Γ ⊢ ⊢ ⊢ (b,r ) p : M ∆; x : M ⊢ ⊢ ⊢ (b ′ ,r ′ ) t : τ subs Γ ⊎ ∆ ⊢ ⊢ ⊢ (b+b ′ ,r +r ′ ) t {x p} : τ
Moreover if the derivations of the premisses are tight then so is the derivation of the conclusion.

The proof is by induction on the derivation of ∆; x : M ⊢ ⊢ ⊢ (b ′ ,r ′ ) t : τ . Note that the lemma also holds for M = [ ], in which case Γ is necessarily empty. In system lo, it is also true that if M = [ ] then x fv(t) and t {x p} = t, because all free variables of t have non empty type in the typing context. As already pointed out, in system hd such a matching between free variables and typing contexts does not hold, and it can be that M = [ ] and yet x ∈ fv(t) and t {x p} t.

Third step: quantitative subject reduction. Finally, one needs to shows a quantitative form of type preservation along evaluation. When the typing is tight, every evaluation step decreases the first index b of exactly 2 units, accounting for the application and abstraction constructor consumed by the firing of the redex. Proposition 3.6 (Quantitative subject reduction for hd and lo). Let S ∈ {hd, lo}. If Φ ▷ S Γ ⊢ ⊢ ⊢ (b,r ) t : τ is tight and t -→ S p then b ≥ 2 and there exists a tight typing Φ ′ such that Φ ′ ▷ S Γ ⊢ ⊢ ⊢ (b-2,r ) p : τ .

The proof is by induction on t -→ S p, and it relies on the substitution lemma (Lemma 3.5) for the base case of β-reduction at top level.

It is natural to wonder what happens when the typing is not tight. In the head case, the index b still decreases exactly of 2. In the lo case things are subtler-they are discussed in Sect. 7.

Summing up. The tight correctness theorem is proved by a straightforward induction on the evaluation length relying on quantitative subject reduction (Proposition 3.6) for the inductive case, and the properties of tight typings for normal forms (Proposition 3.3) for the base case.

Theorem 3.7 (Tight correctness for hd and lo). Let S ∈ {hd, lo} and Φ ▷ S Γ ⊢ ⊢ ⊢ (b,r ) t : τ be a tight derivation. Then there exists p such that t -→ b/2 S p, normal S (p), and |p| S = r . Moreover, if τ = neutral then neutral S (p).

Tight Completeness

Completeness of tight typings (in system S ∈ {hd, lo}) expresses the fact that every S-normalising term has a tight derivation (in system S). As for correctness, the completeness theorem is always obtained via three intermediate steps, dual to those for correctness. Essentially, one shows that every normal form has a tight derivation and then extends the result to S-normalising term by pulling typability back through evaluation using a subject expansion property.

First step: normal forms are tightly typable. A simple induction on the structure of normal forms proves the following proposition. Proposition 3.8 (Normal forms are tightly typable for hd and lo). Let S ∈ {hd, lo} and t be such that normal S (t). Then there exists a tight derivation Φ ▷ S Γ ⊢ ⊢ ⊢ (0, |t | S ) t : τ . Moreover, if neutral S (t) then τ = neutral, and if abs S (t) then τ = abs.

In contrast to the proposition for normal forms of the correctness part (Proposition 3.3), here there are no auxiliary lemmas, so the property is simpler.

Second step: anti-substitution lemma. In order to pull typability back along evaluation sequence, we have to first show that typability can also be pulled back along substitutions. Lemma 3.9 (Anti-substitution and typings for hd and lo). Let S ∈ {hd, lo} and Φ ▷ S Γ ⊢ ⊢ ⊢ (b,r ) t {x p} : τ . Then there exist:

• a multi-set M;

• a typing derivation Φ t ▷ S Γ t ; x : M ⊢ ⊢ ⊢ (b t ,r t ) t : τ ; and

• a typing derivation Φ p ▷ S Γ p ⊢ ⊢ ⊢ (b p ,r p ) p : M such that:

• Typing context:

Γ = Γ t ⊎ Γ p ; • Indices: (b, r ) = (b t + b p , r t + r p ). Moreover, if Φ is tight then so are Φ t and Φ p .
The proof is by induction on Φ. Let us point out that the anti-substitution lemma holds also in the degenerated case in which x does not occur in t and p is not S-normalising: rule many can indeed be used to type any term p with ⊢ ⊢ ⊢ (0,0) p : [ ] by taking an empty set I of indices for the premises. Note also that this is forced by the fact that x fv(t), and so Γ t (x) = [ ]. Finally, this fact does not contradict the correctness theorem, because here p is typed with a multi-set, while the theorem requires a type.

Third step: quantitative subject expansion. This property guarantees that typability can be pulled back along evaluation sequences. Proposition 3.10 (Quantitative subject expansion for hd and lo). Let S ∈ {hd, lo} and Φ ▷ S Γ ⊢ ⊢ ⊢ (b,r ) p : τ be a tight derivation. If t -→ S p then there exists a (tight) typing Φ ′ such that

Φ ′ ▷ S Γ ⊢ ⊢ ⊢ (b+2,r ) t : τ .
The proof is a simple induction over t -→ S p using the anti-substitution lemma in the base case of evaluation at top level.

Summing up. The tight completeness theorem is proved by a straightforward induction on the evaluation length relying on quantitative subject expansion (Proposition 3.10) for the inductive case, and the existence of tight typings for normal forms (Proposition 3.8) for the base case.

Theorem 3.11 (Tight completeness for hd and lo). Let S ∈ {hd, lo} and t -→ k S p with normal S (p). Then there exists a tight typing Φ ▷ S Γ ⊢ ⊢ ⊢ (2k, |p | S ) t : τ . Moreover, if neutral S (p) then τ = neutral, and if abs S (p) then τ = abs.

EXTENSIONS AND DEEPER ANALYSES

In the rest of the paper we are going to further explore the properties of the tight approach to multi types along three independent axes:

(1) Maximal evaluation: we adapt the methodology to the case of maximal evaluation, which relates to strong normalisation in that the maximal evaluation strategy terminates only if the term being evaluated is strongly normalising. This case is a simplification of [Bernadet and Graham-Lengrand 2013a] that can be directly related to the head and leftmost evaluation cases. It is in fact very close to leftmost evaluation but for the fact that, during evaluation, typing contexts are not necessarily preserved and the size of the terms being erased has to be taken into account. The statements of the properties in Sections 3.1 and 3.2 have to be adapted accordingly.

(2) Linear head evaluation: we reconsider head evaluation in the linear substitution calculus obtaining exact bounds on the number of steps and on the size of normal forms. The surprise here is that the type system is essentially unchanged and that it is enough to count also axiom rules (that are ignored for head evaluation in the λ-calculus) in order to exactly bound also the number of linear substitution steps.

(3) LO evaluation and minimal typings: we explore the relationship between tight typings and traditional typings without tight constants. This study is done in the context of LO evaluation, that is the more relevant one with respect to cost models for the λ-calculus. We show in particular that tight typings are isomorphic to minimal traditional typings. Let us stress that these three variations on a theme can be read independently.

MAXIMAL EVALUATION

In this section we consider the maximal strategy, which gives the longest evaluation sequence from any strongly normalising term to its normal form. The maximal evaluation strategy is perpetual in that, if a term t has a diverging evaluation path then the maximal strategy diverges on t. Therefore, its termination subsumes the termination of any other strategy, which is why it is often used to reason about the strong normalisation property [START_REF] Femke Van Raamsdonk | Perpetual Reductions in Lambda-Calculus[END_REF].

Strong normalisation and erasing steps. It is well-known that in the framework of relevant (i.e. without weakening) multi types it is technically harder to deal with strong normalisation (all evaluations terminate)-which is equivalent to the termination of the maximal strategy-than with weak normalisation (there is a terminating evaluation)-which is equivalent to the termination of the LO strategy. The reason is that one has to ensure that all subterms that are erased along any evaluation are themselves strongly normalising.

The simple proof technique that we used in the previous section does not scale up-in general-to strong normalisation (or to the maximal strategy), because subject reduction breaks for erasing steps, as they change the final typing judgement. Of course the same is true for subject expansion. There are at least three ways of circumventing this problem:

(1) Memory: to add a memory constructor, as in Klop's calculus [START_REF] Willem | Combinatory Reduction Systems[END_REF], that records the erased terms and allows evaluation inside the memory, so that diverging subterms are preserved. Subject reduction then is recovered. (2) Subsumption/weakening: adding a simple form of sub-typing, that allows stabilising the final typing judgement in the case of an erasing step, or more generally, adding a strong form of weakening, that essentially removes the empty multi type. (3) Big-step subject reduction: abandon the preservation of the typing judgement in the erasing cases, and rely on a more involved big-step subject reduction property relating the term directly to its normal form, stating in particular that the normal form is typable, potentially by a different type. Surprisingly, the tight characterisation of the maximal strategy that we are going to develop does not need any of these workarounds: in the case of tight typings subject reduction for the maximal strategy holds, and the simple proof technique used before adapts smoothly. To be precise, an evaluation step may still change the final typing judgement, but the key point is that the judgement stays tight. Morally, we are employing a form of subsumption of tight contexts, but an Typing rules {ax, fun b , fun r , app b , app lo r } plus extremely light one, that in particular does not require a sub-typing relation. We believe that this is a remarkable feature of tight multi types.

' & $ % x ∈ fv(u) (λx .u)q 0 - → mx u{x q} normal mx (q) x fv(u) (λx .u)q |q | mx ----→ mx u t r - → mx p x fv(u) (λx .u)t r - → mx (λx .u)p t r - → mx p λx .t r - → mx λx .p ¬abs mx (t) t r - → mx p tu r - → mx pu neutral mx (u) t r - → mx p ut r - → mx up
(∆ i ⊢ ⊢ ⊢ (b i ,r i ) t : τ i ) i ∈I |I | > 0 many >0 + i ∈I ∆ i ⊢ ⊢ ⊢ (+ i ∈I b i ,+ i ∈I r i ) t : [τ i ] i ∈I ∆ ⊢ ⊢ ⊢ (b,r ) t : τ none ∆ ⊢ ⊢ ⊢ (b,r ) t : [ ]
Maximal evaluation and predicates. The maximal strategy shares with LO evaluation the predicates neutral lo , normal lo , abs lo , and the notion of term size |t | lo , which we respectively write neutral mx , normal mx , abs mx , and |t | mx . We actually define, in Fig. 4, a version of the maximal strategy, denoted r -→ mx , that is indexed by an integer r representing the size of what is erased by the evaluation step. We define the transitive closure of r -→ mx as follows:

t 0 - → 0 mx t t r 1 -→ mx p p r 2 -→ k mx u t r 1 +r 2 ----→ k +1 mx u t r - → k mx p t r - → * mx p
Proposition 5.1 (mx evaluation system). (Λ, -→ mx , neutral mx , normal mx , abs mx ) is an evaluation system. Also in this case the proof is routine.

Multi types. Multi types are defined exactly as in Section 3. The type system mx for mx-evaluation is defined in Fig. 5. Rules many >0 and none, which is a special 0-ary version of many, are used to prevent an argument p in rule app b to be untyped: either it is typed by means of rule many >0 -and thus it is typed with at least one type-or it is typed by means of rule none-and thus it is typed with exactly one type: the type itself is then forgotten, but requiring the premise to have a type forces the term to be normalising. The fact that arguments are always typed, even those that are erased during reduction, is essential to guarantee strong normalisation: system mx cannot type anymore a term like x Ω. Note that if Φ ▷ mx Γ ⊢ ⊢ ⊢ (b,r )

t : τ , then x ∈ fv(t) if and only if Γ(x) [ ].
Similarly to the head and leftmost-outermost cases, we define the size |Φ| mx of a typing derivation Φ as the number of rule applications in Φ, not counting rules ax and many >0 and none. And again

if Φ ▷ mx Γ ⊢ ⊢ ⊢ (b,r ) t : τ then b + r = |Φ| mx .
For maximal evaluation, we need also to refine the notion of tightness of typing derivations, which becomes a global condition because it is no longer a property of the final judgment only: Definition 5.2 (Mx-tight derivations). A derivation Φ ▷ mx Γ ⊢ ⊢ ⊢ (b,r ) t : τ is garbage-tight if in every instance of rule (none) in Φ we have tight(τ ). It is mx-tight if also Φ is tight, in the sense of Definition 3.2.

Similarly to the head and LO cases, the quantitative information in mx-tight derivations characterises evaluation lengths and sizes of normal forms, as captured by the correctness and completeness theorems.

Tight Correctness

The correctness theorem is proved following the same schema used for head and LO evaluations. Most proofs are similar, and are therefore omitted.

We start with the properties of typed normal forms. As before, we need an auxiliary lemma about neutral terms, analogous to Proposition 3.3. Lemma 5.3 (Tight spreading on neutral terms for mx). If neutral hd (t) and Φ▷ mx Γ ⊢ ⊢ ⊢ (b,r ) t : τ such that tight(Γ), then tight(τ ).

The general properties of typed normal forms hold as well.

Proposition 5.4 (Properties of mx-tight typings for normal forms). Given Φ▷ mx Γ ⊢ ⊢ ⊢ (b,r ) t : τ with normal mx (t),

(1) Size bound:

|t | mx ≤ b + r . (2) Tightness: if Φ is mx-tight then b = 0 and r = |t | mx .
(3) Neutrality: if τ = neutral then neutral mx (t).

Then we can type substitutions:

Lemma 5.5 (Substitution and typings for mx). The following rule is admissible in system mx:

Γ ⊢ ⊢ ⊢ (b,r ) p : M ∆; x : M ⊢ ⊢ ⊢ (b ′ ,r ′ ) t : τ M [ ] subs Γ ⊎ ∆ ⊢ ⊢ ⊢ (b+b ′ ,r +r ′ ) t {x p} : τ
Moreover if the derivations of the premisses are garbage-tight, then so is the derivation of the conclusion.

Note that, in contrast to Lemma 3.5 in Section 3.1, we assume that the multi-set M is not empty, so that the left premiss is derived with rule many >0 rather than none.

Subject reduction. The statement here slightly differs from the corresponding one in Section 3.1. Indeed, the typing environment Γ for term t is not necessarily preserved when typing p, because the evaluation step may erase a subterm. Consider for instance term t = (λx .x ′ )(yy). In any mx-typing derivation of t, the typing context must declare y with an appropriate type that ensures that, when applying a well-typed substitution to t, the resulting term is still normalising for -→ mx . For instance, the context should declare y : [[τ ] → τ , τ ], or even y : [neutral] if the typing derivation for t is mx-tight. However, as t 1 -→ mx x ′ , the typing derivation for x ′ will clearly have a typing environment Γ ′ that maps y to [ ]. Hence, the subject reduction property has to take into account the change of typing context, as shown below.

Proposition 5.6 (Quantitative subject reduction for mx). If Φ ▷ mx Γ ⊢ ⊢ ⊢ (b,r ) t : τ is mx-tight and t e -→ mx p, then there exist Γ ′ and an mx-tight typing Φ ′ such that Φ ′ ▷ mx Γ ′ ⊢ ⊢ ⊢ (b-2,r -e) p : τ . [START_REF] Accattoli | Tight Typings and Split Bounds[END_REF]. □ Correctness theorem. Now the correctness theorem easily follows. It differs from the corresponding theorem in Section 3.1 in that the second index in the mx-tight typing judgement does not only measure the size of the normal form but also the sizes of all the terms erased during evaluation (and necessarily in normal form).

Proof. See the long version of this paper

Theorem 5.7 (Tight correctness for mx-evaluation). Let Φ ▷ mx Γ ⊢ ⊢ ⊢ (b,r ) t : τ be a mx-tight derivation. Then there is an integer e and a term p such that normal mx (p), t e -→ b/2 mx p and |p| mx + e = r . Moreover, if τ = neutral then neutral mx (p).

Tight Completeness

Completeness is again similar to that in Section 3.2, and differs from it in the same way as correctness differs from that in Section 3.1. Namely, the second index in the completeness theorem also accounts for the size of erased terms, and the long version of this paper [START_REF] Accattoli | Tight Typings and Split Bounds[END_REF] provides the proof of the subject expansion property. The completeness statement follows.

Proposition 5.8 (Normal forms are tightly typable in mx). Let t be such that normal mx (t). Then there exists a mx-tight derivation Φ ▷ mx Γ ⊢ ⊢ ⊢ (0, |t | mx ) t : τ . Moreover, if neutral mx (t) then τ = neutral, and if abs mx (t) then τ = abs. Lemma 5.9 (Anti-substitution and typings for mx). If Φ ▷ mx Γ ⊢ ⊢ ⊢ (b,r ) t {x p} : τ and x ∈ fv(t), then there exist:

• a multiset M different from [ ]; • a typing derivation Φ t ▷ mx Γ t ; x : M ⊢ ⊢ ⊢ (b t ,r t ) t : τ ; and
• a typing derivation Φ p ▷ mx Γ p ⊢ ⊢ ⊢ (b p ,r p ) p : M such that:

• Typing context: Γ = Γ t ⊎ Γ p ;

• Indices: (b, r ) = (b t + b p , r t + r p ). Moreover, if Φ is garbage-tight then so are Φ t and Φ p .

Proposition 5.10 (Quantitative subject expansion for mx). If Φ ▷ mx Γ ⊢ ⊢ ⊢ (b,r ) p : τ is mx-tight and t e -→ mx p, then there exist Γ ′ and an mx-tight typing Φ ′ such that Φ ′ ▷ mx Γ ′ ⊢ ⊢ ⊢ (b+2,r +e) t : τ .

Proof. See the long version of this paper [START_REF] Accattoli | Tight Typings and Split Bounds[END_REF]. □ Theorem 5.11 (Tight completeness for for mx). If t e -→ k mx p with normal mx (p), then there exists an mx-tight typing Φ ▷ mx Γ ⊢ ⊢ ⊢ (2k, |p | mx +e) t : τ . Moreover, if neutral mx (p) then τ = neutral, and if abs mx (p) then τ = abs.

LINEAR HEAD EVALUATION

In this section we consider the linear version of the head evaluation system, where linear comes from the linear substitution calculus (LSC) [START_REF] Accattoli | An Abstract Factorization Theorem for Explicit Substitutions[END_REF][START_REF] Accattoli | A nonstandard standardization theorem[END_REF]], a refinement of the λ-calculus where the language is extended with an explicit substitution constructor t[x\p], and linear substitution is a micro-step rewriting rule replacing one occurrence at a time-therefore, linear does not mean that variables have at most one occurrence, only that their occurrences are replaced one by one. Linear head evaluation-first studied in [START_REF] Danos | Head Linear Reduction[END_REF][START_REF] Mascari | Head Linear Reduction and Pure Proof Net Extraction[END_REF]-admits various presentations. The one in the LSC adopted here has been introduced in [START_REF] Accattoli | An Abstract Factorization Theorem for Explicit Substitutions[END_REF]] and is the simplest one.

The insight here is that switching from head to linear head, and from the λ-calculus to the LSC only requires counting ax rules for the size of typings and the head variable for the size of terms-the type system, in particular is the same. The correspondence between the two system is spelled out in the last subsection of this part. Of course, switching to the LSC some details have to be adapted: a further index traces linear substitution steps, there is a new typing rule to type the new explicit substitution constructor, and the proof schema slightly changes, as the (anti-)substitution lemma is replaced by a partial substitution one-these are unavoidable and yet inessential modifications.

Thus, the main point of this section is to split the complexity measure among the multiplicative steps (beta steps) and the exponential ones (substitutions). Moreover, linear logic proof-nets are known to simulate the λ-calculus, and LSC is known to be isomorphic to the proof-nets used in the simulation. Therefore, the results of this section directly apply to those proof-nets.

Explicit substitutions. We start by introducing the syntax of our language, which is given by the following set Λ lsc of terms, where t[x\p] is a new constructor called explicit substitution (shortened ES), that is equivalent to let x = p in t:

LSC Terms t, p x | λx .t | tp | t[x\p]
The notion of free variable is defined as expected, in particular, fv (t[x\p]) := (fv(t) \ {x }) ∪ fv(p).

(List of) substitutions and linear head contexts are given by the following grammars:

(List of) substitution contexts

L ::= ⟨•⟩ | L[x\t] Linear head contexts H ::= ⟨•⟩ | λx .H | Ht | H[x\t]
We write L⟨t⟩ (resp. H⟨t⟩) for the term obtained by replacing the whole ⟨•⟩ in context L (resp. H) by the term t. This plugging operation, as usual with contexts, can capture variables. We write H⟨⟨t⟩⟩ when we want to stress that the context H does not capture the free variables of t.

Normal, neutral, and abs predicates. The predicate normal lhd defining linear head normal terms and neutral lhd defining linear head neutral terms are introduced in Fig. 6. They are a bit more involved than before, because switching to the micro-step granularity of the LSC the study of normal forms requires a finer analysis. The predicates are now based on three auxiliary predicates neutral x lhd , normal x lhd , and normal # lhd : the first two characterise neutral and normal terms whose head variable x is free, the third instead characterises normal forms whose head variable is bound. Note also that the abstraction predicate abs lhd is now defined modulo ES, that is, a term such as (λx . Small-step semantics. Linear head evaluation is often specified by means of a non-deterministic strategy (having the diamond property) [START_REF] Accattoli | An Abstract Factorization Theorem for Explicit Substitutions[END_REF]]. Here, however, we present a minor deterministic variant, in order to follow the general schema presented in the introduction. The deterministic notion of linear head evaluation lhd is given in Fig. 7. An example of → lhd -sequence is

((λz.(xx)[x\y])p)[y\w] - → lhd (xx)[x\y][z\p][y\w] - → lhd (yx)[x\y][z\p][y\w] - → lhd (wx)[x\y][z\p][y\w]
From now on, we split the evaluation relation → lhd in two different relations, multiplicative -→ m and exponential -→ e evaluation, where -→ m (resp.

-→ e ) is generated by the base case (lhd m ) (resp. (lhd e )) and closed by the three rules (lhd λ ), (lhd @ ), (lhd s ). The terminology multiplicative and exponential comes from the linear logic interpretation of the LSC. The literature contains also an alternative terminology, using B at a distance for -→ m (or distant B, where B is a common name for the variant of β introducing an ES instead of using meta-level substitution) and linear substitution for -→ e .

Proposition 6.1 (linear head evaluation system). (Λ lsc , → lhd , neutral lhd , normal lhd , abs lhd ) is an evaluation system. In the linear case the proof is subtler than for the head, LO, and maximal cases. It can be found in the long version of this paper [START_REF] Accattoli | Tight Typings and Split Bounds[END_REF].

(lhd m ) L⟨λx .t⟩u - → lhd L⟨t[x\u]⟩ (lhd e ) H⟨⟨x⟩⟩[x\t] - → lhd H⟨⟨t⟩⟩[x\t] t - → lhd u (lhd λ ) λx .t - → lhd λx .u t - → lhd u ¬abs lhd (t) (lhd @ ) tv - → lhd uv t - → lhd u t H⟨⟨x⟩⟩ (lhd s ) t[x\v] - → lhd u[x\v]
Sizes. The notion of linear head size |t | lhd extends the head size to terms with ES by counting 1 for variables-note that ES do not contribute to the linear head size:

Linear head size

|x | lhd := 1 |λx .t | lhd := |t | lhd + 1 |tu | lhd := |t | lhd + 1 |t[x\u]| lhd := |t | lhd
Multi types. We consider the same multi types of Sect. 3, but now typing judgements are of the form Γ ⊢ ⊢ ⊢ (b,e,r ) t : τ , where (b, e, r ) is a triple of integers whose intended meaning is explained in the next paragraph. The typing system lhd is defined in Fig. 8. By abuse of notation, we use for all the typing rules-except ES which is a new rule-the same names used for hd.

The linear head size |Φ| lhd of a typing derivation Φ is the number of rules in Φ, without counting the occurrences of many.

Note that Γ ⊢ ⊢ ⊢ (b,e,r ) H⟨⟨x⟩⟩ : Indices. The roles of the three components of (b, e, r ) in a typing derivation Γ ⊢ ⊢ ⊢ (b,e,r ) t : τ can be described as follows:

τ implies that Γ = Γ ′ ; x : M with M [ ]. ' & $ % ax x : [τ ] ⊢ ⊢ ⊢ (0,0,1) x : τ (∆ i ⊢ ⊢ ⊢ (b i ,e i ,r i ) t : τ i ) i ∈I many ⊎ i ∈I ∆ i ⊢ ⊢ ⊢ (+ i ∈I b i ,+e i ,+ i ∈I r i ) t : [τ i ] i ∈I Γ; x : M ⊢ ⊢ ⊢ (b,e,r ) t : τ fun b Γ ⊢ ⊢ ⊢ (b+1,e+|M|,r -|M |) λx .t : M → τ Γ; x : Tight ⊢ ⊢ ⊢ (b,e,r ) t : tight fun r Γ ⊢ ⊢ ⊢ (b,e,r +1) λx .t : abs Γ ⊢ ⊢ ⊢ (b,e,r ) t : M → τ ∆ ⊢ ⊢ ⊢ (b ′ ,e ′ ,r ′ ) p : M app b Γ ⊎ i ∈I ∆ i ⊢ ⊢ ⊢ (b+b ′ +1,e+e ′ ,r +r ′ ) tp : τ Γ ⊢ ⊢ ⊢ (b,e,r ) t : neutral app r Γ ⊢ ⊢ ⊢ (b,e,r +1) tu : neutral Γ; x : M ⊢ ⊢ ⊢ (b,e,r ) t : τ ∆ ⊢ ⊢ ⊢ (b ′ ,e ′ ,r ′ ) u : M ES Γ ⊎ ∆ ⊢ ⊢ ⊢ (b+b ′ ,e+e ′ + |M |,r +r ′ -|M |) t[x\u] : τ
• b and multiplicative steps: b counts the rules of the derivation that can be used to form multiplicative redexes, i.e. subterms of the form L⟨λx .t⟩u. To count this kind of redexes it is necessary to count the number of fun b and app b rules. As in the case of head evaluation (Sect. 3), b is at least twice the number of multiplicative steps to normal form because typing such redexes requires (at least) these two rules. • e and exponential steps: e counts the rules of the derivation that can be used to form exponential redexes, i.e. subterms of the form H⟨⟨x⟩⟩[x\t]. To count this kind of redexes it is necessary to count, for every variable x, the number of occurrences that can be substituted during evaluation. The ES is not counted because a single ES can be involved in many exponential steps along an evaluation sequence. • r and size of the result: r counts the rules typing variables, abstractions and applications (i.e.

ax, fun r and app r ) that cannot be consumed by lhd evaluation, so that they appear in the linear head normal form of a term. Note that the ES constructor is not consider part of the head of terms. Note also that the typing rules assume that variable occurrences (corresponding to ax rules) end up in the result, by having the third index set to 1. When a variable x becomes bound by an ES (rule ES) or by an abstraction destined to be applied (fun b ), the number of uses of x, expressed by the multiplicity of the multi-set M typing it, is subtracted from the size of the result, because those uses of x correspond to the times that it shall be replaced via a linear substitution step, and thus they should no longer be considered as contributing to the result. Coherently, that number instead contributes to the index tracing linear substitution steps. Definition 6.2 (Tight derivations). A derivation Φ ▷ lhd Γ ⊢ ⊢ ⊢ (b,e,r ) t : σ is tight if tight(σ ) and tight(Γ).

Example. Let us give a concret example in system lhd. Consider again the term t 0 = (λx 1 .(λx 0 .x 0 x 1 )x 1 )I, where I is the identity function λz.z. The linear head evaluation sequence from t 0 to lhd normalform is given below, in which we distinguish the multiplicative steps from the exponential ones.

(λx 1 .(λx 0 .x 0 x 1 )x 1 )I - → m ((λx 0 .x 0 x 1 )x 1 )[x 1 \I] - → m (x 0 x 1 )[x 0 \x 1 ][x 1 \I] - → e (x 1 x 1 )[x 0 \x 1 ][x 1 \I] - → e (Ix 1 )[x 0 \x 1 ][x 1 \I] - → m x 3 [x 3 \x 1 ][x 0 \x 1 ][x 1 \I] - → e x 1 [x 3 \x 1 ][x 0 \x 1 ][x 1 \I] - → e I[x 3 \x 1 ][x 0 \x 1 ][x 1 \I]
The evaluation sequence has length 7: 3 multiplicative steps and 4 exponential steps. The linear head normal form has size 2. We now give a tight typing for the term t 0 , by writing again abs 1 for [abs] → abs.

x 0 : [abs 1 ] ⊢ ⊢ ⊢ (0, 0, 1) x 0 : abs 1

x 1 : [abs] ⊢ ⊢ ⊢ (0, 0, 1) x 1 : abs 6, 4, 2) (λx 1 .(λx 0 .x 0 x 1 )x 1 )I : abs Indeed, the pair (6, 4, 2) represents 6/2 = 3 (resp. 4) multiplicative (resp. exponential) evaluation steps to lhd normal-form, and a linear head normal form of size 2.

x 1 : [abs] ⊢ ⊢ ⊢ (0, 0, 1) x 1 : [abs] x 0 : [abs 1 ], x 1 : [abs] ⊢ ⊢ ⊢ (1, 0, 2) x 0 x 1 : abs x 1 : [abs] ⊢ ⊢ ⊢ (2, 1, 1) λx 0 .x 0 x 1 : [abs 1 ] → abs x 1 : [abs 1 ] ⊢ ⊢ ⊢ (0, 0, 1) x 1 : abs 1 x 1 : [abs 1 ] ⊢ ⊢ ⊢ (0, 0, 1) x 1 : [abs 1 ] x 1 : [abs, abs 1 ] ⊢ ⊢ ⊢ (3, 1, 2) (λx 0 .x 0 x 1 )x 1 : abs ⊢ ⊢ ⊢ (4, 3, 0) λx 1 .(λx 0 .x 0 x 1 )x 1 : [abs, abs 1 ] → abs . . . ⊢ ⊢ ⊢ (1, 1, 2) I : [abs, abs 1 ] ⊢ ⊢ ⊢ (

Tight Correctness

As in the case of head and LO evaluation, the correctness proof is based on three main properties: properties of normal forms-themselves based on a lemma about neutral terms-the interaction between (linear head) substitution and typings, and subject reduction.

Neutral terms ad properties of normal forms. As for the head case, the properties of tight typing of lhd normal forms depend on a spreading property of lhd neutral terms. Additionally, they also need to characterise the shape of typing contexts for tight typings of neutral and normal terms. Lemma 6.3 (Tight spreading on neutral terms, plus typing contexts). Let Φ▷ lhd Γ ⊢ ⊢ ⊢ (b,e,r ) t : τ be a derivation.

(1

) If neutral x lhd (t) then x ∈ dom(Γ). Moreover, if Γ(x) = Tight then τ = tight and dom(Γ) = {x }. (2) If normal x lhd (t) then x ∈ dom(Γ). Moreover, if Γ(x) = Tight then dom(Γ) = {x }. (3) If normal #
lhd (t) and τ = tight then τ = abs and Γ is empty.

Proposition 6.4 (Properties of lhd tight typings for normal forms). Let t be such that normal lhd (t), and Φ ▷ lhd Γ ⊢ ⊢ ⊢ (b,e,r ) t : τ be a typing derivation.

(1) Size bound: |t | lhd ≤ |Φ| lhd .

(2) Tightness: if Φ is tight then b = e = 0 and r = |t | lhd .

(3) Neutrality: if τ = neutral then neutral lhd (t).

Partial substitution lemma. The main difference in the proof schema with respect to the head case is about the substitution lemma, that is now expressed differently, because evaluation no longer relies on meta-level substitution. Linear substitutions consume one type at a time: performing a linear head substitution on a term of the form H⟨⟨x⟩⟩[x\t] consumes exactly one type resource associated to the variable x, and all the other ones remain in the typing context after the partial substitution. Formally, an induction on H is used to show: Lemma 6.5 (Partial substitution and typings for lhd). The following rule is admissible in system lhd:

x : M; Γ ⊢ ⊢ ⊢ (b,e,r ) H⟨⟨x⟩⟩ : τ Γ u ⊢ ⊢ ⊢ (b u ,e u ,r u ) u : σ σ ∈ M partial-subs x : M \ σ ; Γ ⊎ Γ u ⊢ ⊢ ⊢ (b+b u ,e+e u ,r +r u -1) H⟨⟨u⟩⟩ : τ Subject reduction and correctness. Quantitative subject reduction is also refined, by taking into account the fact that now there are two evaluation steps, whose numbers are traced by two different indices. Proposition 6.6 (Quantitative subject reduction for lhd). If Φ ▷ Γ ⊢ (b,e,r ) t:τ then (1) If t -→ m u then b ≥ 2 and there is a typing Φ ′ such that Φ ′ ▷ Γ ⊢ (b-2,e,r ) u:τ . (2) If t -→ e u then e ≥ 1 and there is a typing Φ ′ such that Φ ′ ▷ Γ ⊢ (b,e-1,r ) u:τ .

The proof is by induction on t -→ m u and t -→ e u, using Lemma 6.5. Note that quantitative subject reduction does not assume that the typing derivation is tight: as for the head case, the tight hypothesis is only used for the study of normal forms-it is needed for subject reduction / expansion only if evaluation can take place inside arguments, as in the leftmost and maximal cases.

According to the spirit of tight typings, linear head correctness does not only provide the size of (linear head) normal forms, but also the lengths of evaluation sequences to (linear head) normal form: the two first integers b and e in the final judgement count exactly the total number of evaluation steps to (linear-head) normal form. Theorem 6.7 (Tight correctness for lhd). Let Φ ▷ lhd Γ ⊢ ⊢ ⊢ (b,e,r ) t : τ be a tight derivation. Then there exists p such that t → b/2+e lhd p, normal lhd (p) and |p| lhd = r . Moreover, if τ = neutral then neutral lhd (p).

Tight Completeness

As in the case of head and LO evaluation the completeness proof is based on the following properties: typability of linear head normal forms, interaction between (linear head) anti-substitution and typings, and subject expansion. The proofs are analogous to those of the completeness for head and LO evaluation, up to the changes for the linear case, that are instead analogous to those of the correctness of the previous subsection. The statements follow. Proposition 6.8 (Linear head normal forms are tightly typable for lhd). Let t be such that normal lhd (t). Then there exists a tight typing Φ ▷ lhd Γ ⊢ ⊢ ⊢ (0,0, |t | l hd ) t : τ . Moreover, if neutral lhd (t) then τ = neutral, and if abs lhd (t) then τ = abs. Lemma 6.9 (Partial anti-substitution and typings for lhd). Let Φ ▷ lhd Γ ⊢ ⊢ ⊢ (b,e,r ) H⟨⟨u⟩⟩ : τ , where x u. Then there exists

• a type σ • a typing derivation Φ u ▷ lhd Γ u ⊢ ⊢ ⊢ (b u ,e u ,r u ) u : σ • a typing derivation Φ H ⟨⟨x ⟩⟩ ▷ lhd Γ ′ + x:[σ ] ⊢ ⊢ ⊢ (b ′ ,e ′ ,r ′ ) H⟨⟨x⟩⟩ : τ such that • Typing contexts: Γ = Γ ′ ⊎ Γ u .
• Indices: (b, e, r ) = (b ′ + b u , e ′ + e u , r ′ + r u -1). Moreover, if Φ is tight then so are Φ u and Φ H ⟨⟨x ⟩⟩ . Proposition 6.10 (Quantitative subject expansion for lhd). If Φ ′ ▷ lhd Γ ⊢ ⊢ ⊢ (b,e,r ) t ′ : τ then (1) If t -→ m t ′ then there is a derivation Φ ▷ lhd Γ ⊢ ⊢ ⊢ (b+2,e,r ) t : τ . (2) If t -→ e t ′ then there is a derivation Φ ▷ lhd Γ ⊢ ⊢ ⊢ (b,e+1,r ) t : τ .

As for linear head correctness, linear head completeness also refines the information provided about the lenghts of the evaluation sequences: the number k of evaluation steps to (linear head) normal form is now split into two integers k 1 and k 2 representing, respectively, the multiplicative and exponential steps in such evaluation sequence. Theorem 6.11 (Tight completeness for lhd). Let t → k lhd p, where normal lhd (p). Then there exists a tight type derivation Φ ▷ lhd Γ ⊢ ⊢ ⊢ (2k 1 ,k 2 , |p | l hd ) t : τ , where k = k 1 +k 2 . Moreover, if neutral lhd (p), then τ = neutral, and if abs lhd (p) then τ = abs.

Relationship Between Head and Linear Head

The head and linear head strategies are specifications at different granularities of the same notion of evaluation. Their type systems are also closely related-in a sense that we now make explicit, they are the same system.

In order to formalise this relationship we define the transformation L of hd-derivations into (linear, hence the notation) lhd-derivations as: ax in hd is mapped to ax in lhd, fun r in hd is mapped to fun r in lhd, fun b in hd is mapped to fun b in lhd, and so on. This transformation preserves the context and the type of all the typing judgements. Of course, if one restricts the lhd system to λterms, there is an inverse transformation N of lhd-derivations into (non-linear, hence the notation) hd-derivations, defined as expected. Together, the two transformation realise an isomorphism. Proposition 6.12 (Head isomorphism). Let t be a λ-term without explicit substitutions. Then (1) Non-linear to linear: if Φ ▷ hd Γ ⊢ ⊢ ⊢ (b,r ) t : τ then there exists e ≥ 0 such that L(Φ) ▷ lhd Γ ⊢ ⊢ ⊢ (b,e,r +1) t : τ . Moreover, N (L(Φ)) = Φ.

(2) Linear to non-linear: if Φ▷ lhd Γ ⊢ ⊢ ⊢ (b,e,r ) t : τ then N (Φ)▷ hd Γ ⊢ ⊢ ⊢ (b,r -1) t : τ . Moreover, L(N (Φ)) = Φ.

The proof is straightforward. Morally, the same type system measures both head and linear head evaluations. The difference is that to measure head evaluation and head normal forms one forgets the number of axiom typing rules, that coincides exactly with the number of linear substitution steps, plus 1 for the head variable of the linear normal form. In this sense, multi types more naturally measure linear head evaluation. Roughly, a tight multi type derivation for a term is nothing else but a coding of the evaluation in the LSC, including the normal form itself.

On the number of substitution steps. It is natural to wonder how the index e introduced by L in Proposition 6.12.1 is related to the other indices b and r . This kind of questions has been studied at length in the literature about reasonable cost models. It is known that e = O(b 2 ) for any λ-term, even for untypable ones, see [START_REF] Accattoli | On the Invariance of the Unitary Cost Model for Head Reduction[END_REF] for details. The bound is typically reached by the diverging term δδ , which is untypable, but also by the following typable term t n := (λx n . . . . (λx 1 .(λx 0 .(x 0 x 1 . . . x n ))x 1 )x 2 . . . x n )I . Indeed, t n evaluates in 2n multiplicative steps (one for turning each β-redex into an ES, and one for each time that the identity comes in head position) and Ω(n 2 ) exponential steps.

On terms with ES. Relating typings for λ-terms with ES to typings for ordinary λ-terms is a bit trickier-we only sketch the idea. One needs to introduce the unfolding operation (•) → : Λ lsc → Λ on λ-terms with ES, that turns all ES into meta-level substitutions, producing the underlying ordinary λ-term. For instance, (x[x\y][y\z]) → = z. As in Proposition 6.12.2, types are preserved: Lemma 6.13 (Unfolding and lhd derivations). Let t ∈ Λ lsc . If Φ ▷ lhd Γ ⊢ ⊢ ⊢ (b,e,r ) t : τ then there exists Φ ′ ▷ hd Γ ⊢ ⊢ ⊢ (b,r -1) t → : τ .

1:24

Beniamino Accattoli, Stéphane Graham-Lengrand, and Delia Kesner

Note that the indices are also preserved. It is possible to also spell out the relationship between Φ and Φ ′ (as done in [START_REF] Kesner | Call-by-need, neededness and all that[END_REF]), that simply requires a notion of unfolding of typing derivations, and that collapses on the transformation N in the case of ordinary λ-terms.

LEFTMOST EVALUATION AND MINIMAL TYPINGS

This section focuses on the LO system and on the relationship between tight and tight-free-deemed traditional-typings. Contributions are manyfold:

(1) LO normalisation, revisited: we revisit the characterisation of LO normalising terms as those typable with shrinking typings, that is, those where the empty multi-set has no negative occurrences. The insight is that the shrinking and tight constraints are of a very similar nature, showing that our technique is natural rather than ad-hoc. Moreover, our notion of shrinking derivation can also include the tight constants, thus we provide a strict generalisation of the characterisation in the literature.

(2) Minimality: we show that tight typings can be seen as a characterisation of minimal traditional shrinking typings. The insight here is that tight typings are simply a device to focalise what traditional types can already observe in a somewhat more technical way. (3) Type bound: we show that for traditional shrinking typings already the type itself-with no need of the typing derivation-provides a bound on the size of the normal form, and this bound is exact if the typing is minimal. The insight is then the inherent inadequacy of multi types as a tool for reliable complexity measures. This study is done with respect to LO evaluation because among the case studies of the paper it is the most relevant one for reasonable cost models. It may however be easily adapted, mutatis mutandis, to the other systems.

Shrinking typings. It is standard to characterise LO normalising terms as those typable with intersection types without negative occurrences of Ω [START_REF] Krivine | Lambda-calculus, types and models[END_REF]], or, those typable with multi types without occurrence of the empty multi-set [ ] [ [START_REF] Bucciarelli | Non-idempotent intersection types for the Lambda-Calculus[END_REF]]. We call this constraint shrinking. We need some basic notions. We use the notation T to denote a (multi)-type, that is, either a type τ or a multi-set of types M. Definition 7.1 (Positive and negative occurrences). Let T be a (multi)-type. The sets of positive and negative occurrences of T in a type/multi-set of types/typing context are defined by mutual induction as follows:

τ ∈ Occ + (τ ) ∃σ ∈ M such that T ∈ Occ + (σ ) T ∈ Occ + (M) ∃σ ∈ M such that T ∈ Occ -(σ ) T ∈ Occ -(M) M ∈ Occ + (M) T ∈ Occ -(M) or T ∈ Occ + (τ ) T ∈ Occ + (M → τ ) T ∈ Occ + (M) or T ∈ Occ -(τ ) T ∈ Occ -(M → τ ) T ∈ Occ + (M) or T ∈ Occ + (Γ) T ∈ Occ + (x : M, Γ) T ∈ Occ -(M) or T ∈ Occ -(Γ) T ∈ Occ -(x : M, Γ)
Shrinking typings are defined by imposing a condition on the final judgement of the derivation, similarly to tight typings. Definition 7.2 (Shrinking typing). Let Φ ▷ lo Γ ⊢ (b,r ) t:τ be a typing derivation.

• the typing context Γ is shrinking

if [ ] Occ -(Γ); • the final type τ is shrinking if [ ] Occ + (τ );
• The typing derivation Φ is shrinking if both Γ and τ are shrinking.

Note that

• Final judgement: being shrinking depends only on the final judgement of a typing derivation, and that • Tight implies shrinking: a tight typing derivation is always shrinking. In this section we also have a close look to traditional derivations without tight constants. Definition 7.3 (Traditional typings). Let Φ ▷ lo Γ ⊢ (b,r ) t:τ be a typing derivation. Then Φ is traditional if no type occurring in Φ is a tight type (and so rules fun r and app lo r do not occur in Φ). One of our results is that the type itself bounds the size of lo normal forms, for traditional typings, according to the following notion of type size. Here we show that shrinking typability is preserved by LO evaluation and that the size of shrinking typings decreases along it-hence the name-so that every shrinkingly typable term is LO normalising. For the sake of completeness, we also show that typability is always preserved, but if the typing is not shrinking then its size may not decrease.

Once more, we follow the abstract schema of the other sections (but replacing tight with shrinking and obtaining bounds that are less tight). The properties of the typings of normal forms and the substitution lemma for the lo system have already been proved (Proposition 3.3 and Lemma 3.5). We deal again with normal forms, however, because we now focus on traditional typings, and show that their type bounds the size of the LO normal form. As in the previous sections, neutral terms play a key role, showing that our isolation of the relevance of neutral terms for characterisation via multi types is not specific to tight types. Proposition 7.5 (Traditional types bounds the size of neutral and normal terms). Let Φ ▷ lo Γ ⊢ (b,r ) t:τ be a traditional typing. Then:

( As usual, shrinking correctness is based on a subject reduction property. In turn, subject reduction depends as usual on a spreading property on neutral terms, that is expressed by the following lemma.

Lemma 7.6 (Neutral terms and positive occurrences). Let t be such that neutral lo (t) and Φ ▷ lo Γ ⊢ ⊢ ⊢ (b,r ) t : τ be a typing derivation. Then τ is a positive occurrence of Γ.

It is interesting to note that this lemma subsumes the tight spreading on neutral terms property of Lemma 3.4, showing a nice harmony between the shrinking and tight predicates on derivations. If the typing context Γ is tight, indeed, the fact that τ is a positive occurrence of Γ implies that τ is tight.

Proposition 7.7 (Shrinking subject reduction). Let Φ ▷ lo Γ ⊢ (b,r )

t:τ . If t - → lo p then b ≥ 2 and there exists Φ ′ such that Φ ′ ▷ lo Γ ⊢ (b ′ ,r ) p:τ with b ′ ≤ b (and so |Φ ′ | lo ≤ |Φ| lo ). Moreover, if Φ is shrinking then b ′ ≤ b -2 (and so |Φ ′ | lo ≤ |Φ| lo -2).
Note that a LO diverging term like x(δδ ) is typable in system lo by assigning to x the type [ ] → X and typing δδ with [ ], and that its type is preserved by LO evaluation, by Proposition 7.7. Note however that the resulting judgement is not shrinking-only shrinkingly typable terms are LO normalising, in fact.

Theorem 7.8 (Shrinking correctness). Let Φ ▷ lo Γ ⊢ ⊢ ⊢ (b,r ) Minimality. The minimality of tight typings is hidden in the statement of the shrinking correctness theorem. By combining together its two points, indeed, we obtain that |p| lo + 2k ≤ |Φ| lo , that is, the size of every typing derivation bounds both the number of LO steps and the size of the LO normal form. Consequently, tight typings-whose size is exactly the sum of these two quantitiesare minimal typings. To complete the picture, one should show that there also exist traditional shrinking typings that are minimal. We come back to this point at the end of the completeness part.

Shrinking Completeness

The proof of completeness for shrinking typings also follows, mutatis mutandis, the usual schema. Normal forms and anti-substitution have already been treated (Proposition 3.8 and Lemma 3.9). Again, however, we repeat the study of (the existence of typings for) LO normal forms focussing now on traditional typings and on the bound provided by types. Their study is yet another instance of spreading on (LO) neutral terms, in this case of the size bound provided by types: for neutral terms the size of the typing context Γ allows bounding both the size of the term and the size of its type, which is stronger than what happens for general LO normal terms. Proposition 7.9 (Neutral and normal terms have minimal traditional shrinking typings).

(1) If neutral lo (t) then for every type τ there exists a traditional shrinking typing Φ ▷ lo Γ ⊢ (|t | l o ,0) t:τ such that |τ | ty + |t | lo = |Γ| ty . (2) If normal lo (t) then there exists a type τ and a traditional shrinking typing Φ ▷ lo Γ ⊢ (|t | l o ,0) t:τ such that |t | lo = |Φ| ty .

Note that the typings given by the propositions are minimal because they satisfy |Φ| lo = |t | lo and |t | lo is a lower bound on the size of the typings of t by Proposition 3.3.1-note that it is also the size of a tight typing of t by Proposition 3.8.

The last bit is a subject expansion property. Note in particular that since β-redexes are typed using traditional rules, the expansion preserves traditional typings. Proposition 7.10 (Shrinking subject expansion). If t -→ lo p and Φ ▷ lo Γ ⊢ (b,r ) p:τ then there exists Φ ′ such that Φ ′ ▷ lo Γ ⊢ (b ′ ,r ) t:τ with b ′ ≥ b. Moreover, if Φ is shrinking then b ′ ≥ b + 2, and if Φ is traditional then Φ ′ is traditional.

The completeness theorem then follows.

Theorem 7.11 (Shrinking completeness). Let t -→ k lo p with p such that normal lo (p). Then there exists a traditional shrinking typing Φ ▷ lo Γ ⊢ (b,0) t:τ such that k ≤ b/2 and |p| lo = |Φ| ty . Minimality, again. We have shown that there exist minimal traditional shrinking (MTS for short) typings of normal forms of the same size of the tight typings (Proposition 7.9). It is possible to lift such a correspondence to all typable terms. This refinement is however left to a longer version of the paper, because it requires additional technicalities, needed to strengthen subject expansion.

Let us nonetheless assume, for the sake of the discussion, that tight types characterise minimal typings for all typable terms. What's the difference between the two approaches then? It is easy to describe MTS typings for normal forms: an explicit description can be extracted from the proof of Proposition 7.9, and essentially it interprets the terms linearly, that is, typing arguments of applications only once, similarly to the tight app lo r rule. For non-normal terms, however, MTS typings can be obtained only indirectly: first obtaining a MTS typing of the normal form, and then pulling the MTS property back via subject expansion. Tightness instead is a predicate that applies directly to derivations of any typable term, and is then a direct alternative to MTS typings.

Type bounds. The fact that for traditional typings the type itself provides a bound on the size of the normal form is a very strong property. It is in particular the starting point for de Carvalho's transfer of the study of bounds to the relational semantics of terms [START_REF] Daniel De | Sémantiques de la logique linéaire et temps de calcul[END_REF][START_REF] Daniel De | Execution Time of lambda-Terms via Denotational Semantics and Intersection Types[END_REF]]-a term is interpreted as the set of its possible types (including the typing context), that is a notion independent of the typing derivations themselves. Because of the size explosion problem, however, such property also shows that the bounds provided by the relational semantics are doomed to be lax and not really informative.

Relational denotational semantics. As we said in the introduction, multi types can be seen as a syntactic presentation of relational denotational semantics, which is the model obtained by interpreting the λ-calculus into the relational model of linear logic [START_REF] Bucciarelli | On phase semantics and denotational semantics: the exponentials[END_REF][START_REF] Daniel De | Sémantiques de la logique linéaire et temps de calcul[END_REF][START_REF] Daniel De | The Relational Model Is Injective for Multiplicative Exponential Linear Logic[END_REF][START_REF] Girard | Normal functors, power series and the λ-calculus[END_REF], often considered as a canonical model.

The idea is that the interpretation (or semantics) of a term is simply the set of its types, together with their typing contexts. More precisely, let t be a term and x 1 , . . . , x n (with n ≥ 0) be pairwise distinct variables. If fv(t) ⊆ {x 1 , . . . , x n }, we say that the list ì x = (x 1 , . . . , x n ) is suitable for t. If ì x = (x 1 , . . . , x n ) is suitable for t, the (relational) semantics of t for ì

x is

[[t]] ì

x := {((M 1 , . . . , M n ), τ ) | ∃ Φ ▷ lo x 1 : M 1 , . . . , x n : M n ⊢ (b,r ) t:τ } .

By subject reduction and expansion, the interpretation [[t]] ì

x is an invariant of evaluation, and by correctness and completeness it is non-empty if and only if t is LO normalisable. Said differently, multi types provide an adequate denotational model with respect to the chosen notion of evaluation, here the LO one. If the interpretation is restricted to traditional typing derivations (in the sense of Definition 7.3), then it coincides with the one in the relational model in the literature. General derivations still provide a relational model, but a slightly different one, with the two new types abs and neutral, whose categorical semantics still has to be studied.

CONCLUSIONS

Type systems provide guarantees both internally and externally. Internally, a typing discipline ensures that a program in isolation has a given desired property. Externally, the property is ensured compositionally: plugging a typed program in a typed environment preserves the desired property. Multi types (a.k.a. non-idempotent intersection types) are used in the literature to quantify the resources that are needed to produce normal forms. Minimal typing derivations provide exact upper bounds on the number of β-steps plus the size of the normal form-this is the internal guarantee. Unfortunately, such minimal typings provide almost no compositionality, as they essentially force the program to interact with a linear environment. Non-minimal typings allow compositions with less trivial environments, at the price of laxer bounds.

In this paper we have engineered typing so that, via the use of tight constants among base types, some typing judgements express compositional properties of programs while other typing judgements, namely the tight ones, provide exact and separate bounds on the lengths of evaluation sequences on the one hand, and on the sizes of normal forms on the other hand. The distinction between the two counts is motivated by the size explosion problem, where the size of terms can grow exponentially with respect to the number of evaluation steps.

We conducted this study, building on some of the ideas in [Bernadet and Graham-Lengrand 2013a], by presenting a flexible and parametric typing framework, which we systematically applied to three evaluation strategies of the pure λ-calculus: head, leftmost-outermost, and maximal.

In the case of leftmost-outermost evaluation, we have also developed the traditional shrinking approach which does not make use of tight constants. One of the results is that the number of (leftmost) evaluation steps can be measured using only the (sizes) of the types of the final typing judgement, in contrast to the size of the whole typing derivation. Another point, is the connection between tight typings and minimal shrinking typings without tight constants.

In the case of maximal evaluation, we have circumvented the traditional techniques to show strong normalisation: by focusing on the maximal deterministic strategy, we do not require any use of memory operator or subtyping for abstractions to recover subject reduction.

We have also extended our (pure) typing framework to linear head evaluation, presented in the linear substitution calculus (LSC). The result is that tight typings naturally encode evaluation in the LSC, which can be seen as the natural computing devide behind multi types. In particular, and surprisingly, exact bounds for head and linear head evaluation rely on the same type system.

Different future directions are suggested by our contribution. It is natural to extend this framework to other evaluation strategies such as call-by-value and call-by-need. Richer programming features such as pattern matching, or control operators deserve also special attention.

Fig. 3 .

 3 Fig. 3. Type system for head and LO evaluations

  [. . .] denotes the multi-set constructor. • Examples of multisets: [τ , τ , σ ] is a multi-set containing two occurrences of τ and one occurrence of σ , and [ ] is the empty multi-set. • A typing context Γ is a map from variables to finite multisets M of types such that only finitely many variables are not mapped to the empty multi-set [ ]. We write dom(Γ) for the domain of Γ, i.e. the set {x | Γ(x) [ ]}. • Tightness: we use the notation Tight for [tight] i ∈I (I a finite set). Moreover, we write tight(τ ) if τ is of the form tight, tight(M) if M is of the form Tight, and tight(Γ) if tight(Γ(x)

Fig. 4 .

 4 Fig. 4. Deterministic maximal strategy

Fig. 5 .

 5 Fig. 5. Type system for maximal evaluation

  t)[z\p][y\u] satisfies the predicate. It is worth noticing that a term t of the form H⟨⟨y⟩⟩ does not necessarily verify normal lhd (t), e.g. (λz.(yx)[x\y])p. Examples of linear head normal forms are λx .xy and (yx)[x\z](II ).

Fig. 7 .

 7 Fig. 7. Deterministic linear-head evaluation

Fig. 8 .

 8 Fig. 8. Type system for linear head evaluation.

  Definition 7.4 (Type size). The type size | • | ty of types, multi-sets, typing contexts, and derivations is defined as follows: |X | ty := 0 |tight| ty := 0 |M| ty := τ ∈M |τ | ty |M → τ | ty := |M| ty + |τ | ty + 1 |ϵ | ty := 0 |x : M; Γ| ty := |M| ty + |Γ| ty |Φ| ty := |Γ| ty + |τ | ty if Φ ▷ Γ ⊢ (b,r ) t:τ 7.1 Shrinking Correctness

  Characterisation of S-neutral terms: neutral S (t) if and only if normal S (t) and ¬abs S (t).

	'					$
		Head normal forms
		neutral hd (t)	neutral hd (t)	normal hd (t)
	neutral hd (x)	neutral hd (tp)	normal hd (t)	normal hd (λy.t)
		Leftmost-outermost normal forms
	neutral lo (t) normal lo (p)	neutral lo (t)	normal lo (t)
	& neutral lo (x)	neutral lo (tp)	normal lo (t)	normal lo (λy.t)	%
	Fig. 1. Head and leftmost-outermost neutral and normal terms
	'					$
			Head evaluation
			t -→ hd p	t -→ hd p ¬abs hd (t)
	(λx .u)q -→ hd u{x q}	λx .t -→ hd λx .p	tu -→ hd pu
		Leftmost-outermost evaluation
		t -→ lo p	t -→ lo p ¬abs lo (t)	neutral lo (u) t -→ lo p
	& (λx .u)q -→ lo u{x q}	λx .t -→ lo λx .p	tu -→ lo pu	ut -→ lo up	%
		Fig. 2. Head and leftmost-outermost strategies
	1) Determinism of -→ S : if t -→ S p 1 and t -→ S p 2 then p 1 = p 2 . (2) Characterisation of S-normal terms: t is -→ S -normal if and only if normal S (t).
	(3) Given a strategy -→ S we use -→ k S for its k t h iteration and -→ * S for its transitive closure.

  1) If neutral lo (t) then |τ | ty + |t | lo ≤ |Γ| ty . (2) If normal lo (t) then |t | lo ≤ |Φ| ty .

  Result size: |p| lo ≤ |Φ| lo -2k; Moreover, if Φ is traditional then |t | lo ≤ |Φ| ty .

	t : τ be a shrinking derivation. Then
	there exists a -→ lo normal form p and k ≤ b/2 such that (1) Steps: t -→ lo -evaluates to p in k steps, i.e. t -→ k lo p; (2)

Proceedings of the ACM on Programming Languages, Vol. 1, No. CONF, Article 1. Publication date: January 2018.

ACKNOWLEDGMENTS

We are grateful to Alexis Bernadet, Giulio Guerrieri and anonymous reviewers for useful discussions and comments. This work has been partially funded by the ANR JCJC grant COCA HOLA (ANR-16-CE40-004-01).