Abstract 1 Introduction 2 Reduction and Open Call-by-Value 3 The Type System 𝓤 4 Useful Call-by-Value 5 (Quantitative) Soundness and Completeness of System 𝓤 6 Conclusions References Appendix A Proofs of Section 3 Appendix B Proofs of Section 5

Useful Call-by-Value: A Semantic Interpretation via Quantitative Types

Pablo Barenbaum ORCID Universidad Nacional de Quilmes (CONICET), Buenos Aires, Argentina
Instituto de Ciencias de la Computación, UBA, Buenos Aires, Argentina
Delia Kesner ORCID Université Paris Cité, CNRS, IRIF, France Mariana Milicich ORCID Université Paris Cité, CNRS, IRIF, France
Abstract

Useful evaluation is an optimised evaluation mechanism for functional programming languages. It relies on representing terms with sharing and imposing a restricted notion of useful substitutions, that intuitively disallows copying subterms that do not contribute to the progress of the computation.

In particular, useful call-by-value evaluation optimises the standard call-by-value strategy by preserving its original semantics. This preservation result has been shown by means of syntactical rewriting techniques, difficult to adapt to alternative variants of the calculi at play.

In this work, we present the first semantic model of useful call-by-value evaluation through the non-idempotent intersection type system 𝒰. Our first contribution is a characterisation of termination for useful call-by-value evaluation via system 𝒰. That is, a term is typable in system 𝒰 if and only if it terminates in the useful call-by-value strategy. As a second contribution, we show that system 𝒰 provides a quantitative interpretation for useful call-by-value evaluation, offering exact step-count information for program evaluation. Our third contribution is that termination in call-by-value and useful call-by-value are equivalent. This ensures in particular that call-by-value, which is (potentially) erasing, and useful call-by-value, which is non-erasing, are observationally equivalent. Even though the specification of the operational semantics of useful evaluation is highly complex, system 𝒰 is notably simple. As far as we know, system 𝒰 is one of the scarce quantitative type systems capturing exactly the substitution step-count for variables and abstractions in an open call-by-value strategy.

Keywords and phrases:
Lambda calculus, Evaluation strategies, Call-by-Value, Useful Evaluation, Intersection types, Quantitative models
Funding:
Mariana Milicich: ††margin: [Uncaptioned image] This project has received funding from the EU Horizon 2020 research and innovation programme MSCA No 945332.
Copyright and License:
[Uncaptioned image] © Pablo Barenbaum, Delia Kesner, and Mariana Milicich; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation → Lambda calculus
; Theory of computation → Type theory ; Theory of computation → Operational semantics
Related Version:
Technical Report: https://arxiv.org/abs/2404.18874 [16]
Funding:
This work was supported by the European Union through the MSCA SE project QCOMICAL (Grant Agreement ID: 101182520).
Editors:
Stefano Guerrini and Barbara König

1 Introduction

Implementing a model of computation efficiently requires designing an operational semantics that closely adheres to the original model, while optimising the key operations for computational efficiency. This creates a significant gap between the original model and its optimised version, making it crucial to guarantee that both notions are observationally equivalent, meaning that the observable behaviour of any program in the optimised model should be indistinguishable from its behaviour in the original one.

A typical and well-known example of this phenomenon is call-by-need (CBNeed), which can be shown to be observationally equivalent to call-by-name (CBN) [12, 41, 36]. Another recent example of an optimisation technique in the theory of functional programming languages is useful evaluation, introduced by Accattoli and Dal Lago [9]. This notion is based on a graph representation of λ-terms which implements sharing by means of explicit substitutions (ESs) (see [35] for a survey on ES). Useful evaluation aims to perform duplication only when this contributes to the progress of the computation, that is, to the creation of β-redexes.

Defining useful evaluation is challenging because its corresponding operational semantics must precisely capture what “contributing to the progress of the computation” means. Indeed, this makes useful evaluation context-sensitive by nature. In the call-by-value (CBV) framework, useful evaluation can be seen as an optimised implementation of standard CBV that effectively preserves its original semantics [1, 3]. This preservation result has been proved by means of syntactical tools based on rewriting theory.

In general, proving equivalence between two calculi through operational reasoning is inherently complex, often relying on various syntactic techniques such as sharing, unfolding, residual theory, standardisation, among others. Moreover, syntactic proofs of observational equivalence are often ad hoc and difficult to generalise to alternative variants of the calculi at play. In contrast, the semantic methods used in this work have provided abstract and conceptual proofs when applied before to other cases; this is for example the emblematic semantic equivalence between CBNeed and CBN [36]. Here, we extend these methods to the CBV framework to capture in particular usefulness.

Quantitative Interpretations.

We rely on the non-idempotent flavour of intersection types (IT) to provide a model of useful CBV evaluation. IT extend simple types with an intersection type constructor ∩, allowing a program t to be typed with α∩β if t types with both α and β independently. Initially introduced as models to capture qualitative computational properties of functional programs [23, 24], intersection type systems (ITS) are able in particular to characterise termination of evaluation strategies: a program t terminates in a given evaluation strategy if and only if t is typable in an associated type system.

In the original formulation of IT, the type constructor ∩ is considered to be idempotent, meaning that σ∩σ=σ. So, an intersection α1∩…∩αn can be represented as the set {α1,…,αn}. More recent works have adopted a non-idempotent intersection type constructor [30, 22, 25]. In this setting, an intersection α1∩…∩αn can be represented as the multiset [α1,…,αn]. Like their idempotent precursors, non-idempotent ITS still allow characterising operational properties of programs by means of typability but also yield a substantial improvement: they provide quantitative measures about these properties [30, 22, 25]. For instance, from a typing derivation of a program t, it is possible to extract an upper bound – or even an exact measure – for the number of steps which is necessary to reach the normal form of t.

More precisely, exact measures can be obtained in the so-called tight quantitative type systems [2], by decorating the type judgements with counters, and by imposing a tightness condition on typing derivations to ensure that they are minimal. For instance, the counter m may be used in the typing judgement Γ⊢mt:α to capture the fact that t evaluates in exactly m reduction steps to a normal form.

To (quantitatively) characterise termination for a given evaluation strategy in such type systems, one relies on the results of soundness and completeness of the type system with respect to the corresponding evaluation strategy. Here, quantitative soundness means that for any tight type derivation of a program t with counter m, the program t evaluates to normal form in exactly m steps. Conversely, quantitative completeness means that every reduction sequence to normal form of a given length corresponds to a tight typing derivation with appropriate counters.

Quantitative type systems based on non-idempotent ITS have been applied to various evaluation strategies in the λ-calculus for obtaining upper bounds and exact measures [17, 21, 2, 25, 39], as well as in the contexts of classical calculi [37, 38], call-by-value [28, 4, 34, 6], call-by-need [13, 14, 7, 40], call-by-push-value [19], languages with effects [11], linear logic [27, 26], etc. These type systems can be seen as semantic interpretations, akin to relational models in the usual sense of linear logic [32, 18].

In the framework of Plotkin’s CBV [43], non-idempotent ITS have been introduced by Ehrhard [28], and then extended to calculi with sharing (see e.g., [4, 7, 19, 39, 6]). All these type systems characterise termination of the corresponding CBV calculus but their underlying notion of tightness does not seem to be easily adaptable to useful CBV. The problem of finding a semantic model of useful CBV capable of providing the exact number of steps to reach a normal form thus remained open.

Previous definitions of useful CBV in the literature lack semantic models, and existing quantitative models of CBV do not account for usefulness. This work aims to provide the first semantic interpretation of useful CBV evaluation by introducing a quantitative model that admits a tight extension. In particular, our work provides one of the scarce quantitative type systems capturing exactly the substitution step-count for variables and abstractions in an open CBV strategy.

Motivation and Goal of this Paper.

As discussed in the previous subsection, semantic models are often qualitative, in that they capture extensional properties of programs, such as observational equivalence. In contrast, models based on non-idempotent intersection types refine this perspective by capturing intensional properties of programs, such as the length of reductions to normal form, and therefore considered to be quantitative. Qualitative semantic models are unable to distinguish between alternative implementations, such as CBN vs. CBNeed, or CBV vs. useful CBV. The motivation of this work is to deepen the understanding of useful CBV evaluation by developing tools that enable quantitative reasoning about program behaviour. The main goal is to develop a sound and complete quantitative model based on non-idempotent intersection types for useful CBV. In particular, since it is well-known that there can be an exponential gap between function application steps and substitution steps (a.k.a. the size explosion problem, see e.g. [9]), our goal is to include in the design of such a quantitative model a way to distinguish between these two forms of reduction steps. Such a distinction has several applications, in particular, in the analysis of cost models and the design of optimisation techniques.

Contributions and Structure of the Paper.

We begin in Section 2 by recalling Accattoli and Paolini’s Value Substitution Calculus (vsc) [10], the CBV calculus we use in this work. Whereas most functional programming languages rely on reduction for closed terms (i.e., without free variables), reduction in the vsc applies also on open terms (i.e., with free variables). Adopting an open CBV setting broadens the applicability of our results, as open CBV serves as a foundational framework for more complex evaluation models, like strong CBV [33] which is used to implement proof assistants based on dependent type theory.

Since the vsc is a (potentially) erasing calculus (i.e., values can be erased during computation, see subsection 2.3) while useful CBV is not, relating their operational semantics is not easy. To overcome this barrier, we define a non-erasing variant of vsc we dub vscne, which enjoys two properties: (1) termination in vsc is equivalent to termination in vscne, and (2) termination in vscne is equivalent to termination in useful CBV. The first property is relatively routine (see the appendix for details), so most of the paper is devoted to studying the second one, which is challenging.

In Section 3, we define system 𝒰, a non-idempotent intersection type system which is shown to characterise termination in vscne. In Section 4, we recall an inductive formulation of the useful CBV evaluation strategy that has been recently defined [15]. Finally, in Section 5, we show that system 𝒰 is the first semantic model for useful CBV evaluation, addressing the lack of a high-level, semantic characterisation of this strategy.

Our first main result is that system 𝒰 characterises termination in both vscne (Theorem 3) and useful CBV (Corollary 14). Termination in vscne is equivalent to typability in system 𝒰, which is in turn equivalent to termination in useful CBV. This ensures in particular that vscne and useful CBV are observationally equivalent. Therefore, useful CBV evaluation can be seen as an optimisation of CBV that preserves its original semantics.

As a second main result, we refine system 𝒰 to provide exact quantitative information of useful CBV evaluation. Indeed, we equip type judgements of system 𝒰 with counters that are natural numbers, and we define a notion of tightness, intuitively capturing minimality of derivations. The counters are meant to capture the exact step-count for program evaluation. More precisely, we show that a term t is tightly typable with counters m and e in system 𝒰 if and only if t terminates in useful CBV evaluation in exactly m function application steps and e substitution steps (Corollary 14). Our contribution is novel, as previous definitions of useful evaluation (including useful CBV) lack semantic models and current quantitative interpretations of CBV do not consider usefulness. Notably, except for [39], which relies entirely on the persistent/consuming paradigm, this is the only quantitative type system for open CBV that is able to count variable and abstraction substitution steps exactly.

2 Reduction and Open Call-by-Value

In this section, we start by recalling some general notions of rewriting theory. We then review the Value Substitution Calculus (vsc), a CBV calculus introduced by Accattoli and Paolini [10], as well as a non-erasing variant of vsc called vscne.

2.1 Preliminary Notions on Rewriting Theory

Given a reduction system ℛ, we write →ℛ to denote the (one-step) reduction relation associated to ℛ. We write →ℛ= and →ℛ∗ for the reflexive and reflexive-transitive closure of →ℛ, respectively, and →ℛn for the composition of n-steps of →ℛ. A term t is said to be ℛ-irreducible, or in ℛ-normal form, written t↛ℛ, if there is no u such that t→ℛu. A term t is said to be ℛ-weakly terminating (resp. ℛ-terminating) if there exists some ℛ-normal form u such that t→ℛ∗u (resp. there is no infinite ℛ-sequence starting at t). A term t is ℛ-diamond (or enjoys the ℛ-diamond property) if t→ℛt0 and t→ℛt1, with t0≠t1, imply there is t′ such that t0→ℛt′ and t1→ℛt′. A term t is ℛ-confluent if t→ℛ∗t0 and t→ℛ∗t1 imply there is t′ such that t0→ℛ∗t′ and t1→ℛ∗t′. A relation ℛ is weakly-terminating (resp. terminating, diamond, confluent) if and only if every term is ℛ-terminating (resp. ℛ-terminating, ℛ-diamond, ℛ-confluent). Any relation verifying the diamond property is in particular confluent. Moreover, if t is confluent, then its ℛ-normal form, if it exists, is unique [44].

2.2 The Value Substitution Calculus

It is well-known that naive extensions of Plotkin’s CBV [43] to open CBV do not enjoy adequacy, in the sense that normal forms are not necessarily solvable, i.e. “meaningful” 111See [42, 29, 6] for a general discussion on CBV solvability. Our starting point is the Value Substitution Calculus (vsc) [10], an open CBV calculus with explicit substitutions that recovers adequacy and extends Plotkin’s CBV.

Given a denumerable set of variables (x,y,z,…), the syntax of the vsc is specified by:

t,u,s,…::=x∣λ⁢x.t⁢∣t⁢u∣⁢t⁢[x\u]⁢v,w,…::=x∣λ⁢x.t

describing the sets of terms and values, respectively. We also use the following notions of substitution contexts and weak contexts:

𝙻,𝙻′,…::=◇∣𝙻⁢[x\t]⁢𝚆,…::=◇⁢∣𝚆⁢t∣⁢t⁢𝚆⁢∣𝚆⁢[x\t]∣⁢t⁢[x\𝚆]

The set of terms includes variables, abstractions, applications, and closures t⁢[x\u], representing an explicit substitution (ES) [x\u] on a term t. Some recurring terms are the identity function 𝙸:=λ⁢x.x and the operator ω:=λ⁢x.x⁢x.

Free and bound occurrences of variables are defined as usual, where free occurrences of x in t are bound in t⁢[x\u]. Terms are considered up to α-renaming of bound variables. Substitution contexts are lists of ESs, and we write t⁢𝙻 for the replacement of the hole ◇ in 𝙻 by t, which may capture the free variables of t. For example, if 𝙻=[x\y⁢y]⁢[y\z] and t=x, then t⁢𝙻=x⁢[x\y⁢y]⁢[y\z]. We also consider a meta-level operation t⁢{x:=u} which substitutes all the free occurrences of x by u in t. Thanks to α-renaming, we can assume that this substitution operation is capture-free. The sets of free variables of a term (𝖿𝗏⁢(t)) and a context (𝖿𝗏⁢(𝙻)) are defined as expected.

Reduction in vsc is defined by the two following rewriting rules, closed by arbitrary weak contexts, i.e., reduction is not allowed under abstractions:

(λx.t)𝙻u→𝖽𝖻t[x\u]𝙻t[x\v𝙻]→𝗌𝗏t{x:=v}𝙻

The 𝖽𝖻-rule (“𝖽istant 𝖻eta”) is a β-like rule that applies an abstraction λ⁢x.t to an argument u, creating an ES [x\u] that binds x to the argument u. This rule acts at a distance, meaning an arbitrary list of ESs (𝙻) may be in between the abstraction and its argument. For example, (λx.λy.x)tu→𝖽𝖻(λy.x)[x\t]u→𝖽𝖻x[y\u][x\t].

The 𝗌𝗏-rule (“𝗌ubstitution of 𝗏alues”) fires an ES when x is bound to a value v surrounded by a context 𝙻. This performs the meta-level substitution of x by v, potentially producing n≥0 copies of v, while it extrudes the substitution context 𝙻, which must remain shared. For example, x⁢[y\z]→𝗌𝗏x⁢{y:=z}=x results in the erasure of the value z, while (xx)[x\(λy.z)[z\t]]→𝗌𝗏((λy.z)λy.z)[z\t] produces two copies of λ⁢y.z but keeps a single copy of [z\t]. Note that a term like x⁢[x\y⁢y] is in vsc-normal form because y⁢y is not a value.

The notion of reachable variable of a term t is sometimes relevant in vsc, due to the fact that reduction is closed by weak contexts. The set of reachable variables 𝗋𝗏⁢(t) is defined as the set of free variables that do not appear inside an abstraction. Formally:

𝗋𝗏⁢(x):={x}𝗋𝗏(λx.t):=∅𝗋𝗏⁢(t⁢u):=𝗋𝗏⁢(t)∪𝗋𝗏⁢(u)𝗋𝗏⁢(t⁢[x\u]):=(𝗋𝗏⁢(t)∖{x})∪𝗋𝗏⁢(u)

2.3 The Non-Erasing Value Substitution Calculus

As part of this work, we aim to establish a correspondence between CBV and ucbv∙, the useful CBV evaluation strategy defined in [15].

In principle, standard CBV strategies allow erasing some ESs that have become unreachable. For instance, (x⁢x)⁢[y\v]→x⁢x is an erasing step. However, erasing steps are not useful and thus ucbv∙ does not include erasing rules. As we will see in Section 5, ucbv∙ evaluation implements in particular a non-erasing variant of the vsc.

The Non-Erasing Value Substitution Calculus (vscne) is given by the vsc syntax and the reduction is defined by the following rules, closed by arbitrary weak contexts:

(λx.t)𝙻u→𝖽𝖻t[x\u]𝙻t[x\v𝙻]→𝗌𝗏𝗇𝖾t{x:=v}[x\v]𝙻 if x∈𝖿𝗏⁢(t)

The 𝗌𝗏𝗇𝖾-rule is similar to the 𝗌𝗏-rule but requires that the variable x occurs free in t. For example, x⁢[y\z] reduces to x in vsc but is already a vscne-normal form. We assume the 𝗌𝗏𝗇𝖾-rule to be capture-free, due to α-renaming (x∉𝖿𝗏⁢(v)).

3 The Type System 𝓤

We now present a non-idempotent intersection type system (ITS) called 𝒰 and show that it is sound and complete for the non-erasing Value Substitution Calculus vscne. The main result of this section is Theorem 3, which characterises termination in vscne by system 𝒰: a term t is typable in system 𝒰 (or 𝒰-typable) if and only if t terminates in vscne. Later, in Section 5, this same type system 𝒰 is shown to characterise termination of our notion of useful CBV evaluation (ucbv∙) as well, thus establishing a relation between vscne-termination, ucbv∙-termination, and 𝒰-typability.

3.1 Defining System 𝓤

We begin with some preliminary considerations. First, normal forms in vscne and ucbv∙ fall into three categories222See Appendix A for the vscne-normal forms and Section 4 for the ucbv∙-normal forms.. A normal form without ESs may be an abstraction λ⁢x.t, a variable x, or a structure x⁢t1⁢…⁢tn, where n≥1 and each ti is recursively in normal form. Normal forms with ESs also fit these categories up to performing all ESs. Thus, for instance, (z⁢y)⁢[z\x⁢y] is a structure because it can be understood as representing the term x⁢y⁢y.

Second, one key feature of non-idempotent ITS is that a single occurrence of an expression in the (static) source code of a program may be (dynamically) used multiple times during execution, each time playing a different role, expressed by a different type. Specifically, each abstraction is assigned a multiset of arrow types of the form [α1,…,αn], where the cardinality n corresponds to the number of times this abstraction333Or, more precisely, one of the descendants of this abstraction. takes part as the left-hand side of a 𝖽𝖻-redex during evaluation. For example, in (λf.x(fy)(fz))𝙸, the identity function takes part in two 𝖽𝖻-redexes during evaluation, so any type assignment for this term must provide two different arrow types for 𝙸. In contrast, abstractions that are never applied, such as 𝙸 in x⁢[x\𝙸], are typed with the empty multiset [].

As a general rule, terms whose normal form represents an abstraction – including variables bound to abstractions – are assigned finite multisets of arrow types, called arrow multi-types. On the other hand, terms whose normal form represents a structure – including applied variables and variables bound to structures – are assigned a distinguished type, 𝕤. Formally, the types of system 𝒰 are given by the following grammar:

(Arrow Types)α,β::=𝒯?→𝒯(Arrow Multi-Types)ℳ,𝒩,ℳ1,ℳ2,…::=[αi]i∈Iwhere I is a finite set(Types)𝒯,𝒮,𝒯1,𝒯2,…::=𝕤∣ℳ(Optional Types)𝒯?,𝒮?,𝒯1?,𝒯2?,…::=⊥∣𝒯

A type 𝒯 is said to be a constant type if 𝒯∈{𝕤,[]}, in which case we denote 𝒯 by the letter 𝕥. The type 𝕤 is assigned to terms whose normal forms are structures, and [] is assigned to terms whose normal forms are abstractions not taking part in 𝖽𝖻-redexes. Unlike in previous non-idempotent ITS for CBV, we distinguish the type ⊥ from []. The latter is used as explained above, while the former indicates that no typing information is available.

Typing environments Γ,Δ,… are functions mapping variables to optional types, assigning ⊥ to all but finitely many variables. The domain of an environment Γ is 𝖽𝗈𝗆⁢(Γ):={x∣Γ⁢(x)≠⊥}, and ∅ denotes the empty typing environment, mapping each variable to ⊥.

The union of arrow multi-types, written ℳ1⊎ℳ2, is a multiset of types defined as expected, where [] is the neutral element. The union of types, written 𝒯1+𝒯2, is the(associative) partial operation on types given by 𝕤+𝕤:=𝕤 and ℳ1+ℳ2:=ℳ1⊎ℳ2 (where ⊎ denotes multiset union), with all other cases are undefined. The union of optional types is defined by ⊥⁣+⁣⊥⁣:=⁣⊥, ⊥+𝒯:=𝒯, and 𝒯+⊥:=𝒯, making ⊥ the neutral element. For typing environments (Γi)i∈I, we write +i∈IΓi for the environment mapping each variable x to ⊎i∈IΓi⁢(x), where Γ+Δ and Γ+j∈JΔj (meaning Γ+(+j∈JΔj)) are taken to be particular instances of the general notation. When 𝖽𝗈𝗆⁢(Γ)∩𝖽𝗈𝗆⁢(Δ)=∅ we write Γ;Δ instead of Γ+Δ to emphasise that the domains of Γ and Δ are disjoint. As a consequence, Γ;x:⊥ is identical to Γ.

Type assumptions are denoted x:𝒯?, meaning that the environment assigns 𝒯? to x, and ⊥ to any other variable. We define a controlled weakening relation ≪ between optional types and types by declaring that ⊥≪𝕥 and 𝒯≪𝒯 hold.

Typing judgements in system 𝒰 are of the form Γ⊢t:𝒯, where Γ is a type environment and 𝒯 is a type. Typing rules of system 𝒰 are:

A (type) derivation is a tree built by applying the previous (inductive) typing rules. We write Φ⊳𝒰Γ⊢t:𝒯 to denote a type derivation Φ in system 𝒰 ending in the typing judgement Γ⊢t:𝒯. Sometimes, Φ or 𝒰 may be omitted.

Like most non-idempotent ITS, system 𝒰 is inspired by Linear Logic [31] and specifically by the relational semantics of CBV (see e.g., [28]). Indeed, a multiset [α1,…,αn] can be understood as a multiplicative conjunction α1⊗…⊗αn. Moreover, there are no general weakening and contraction rules, though the facts that ⊥≪𝕥 and 𝕥+𝕥=𝕥 hold whenever 𝕥∈{𝕤,[]} can be understood respectively as controlled forms of weakening and contraction.

Rule abs is a standard rule in non-idempotent ITS for CBV [28], and reflects the weak nature of reduction in vscne (reduction does not proceed below abstractions). For example, the derivation ⊳∅⊢λx.Ω:[] is valid even if Ω is non-terminating.

Rule es can be easily reconstructed from rules abs and appC, while rules for applications follow the consuming/persistent paradigm [38, 39] and deserve some discussion. Indeed, system 𝒰 keeps track of the different natures of the application constructors involved in the evaluation process of a program: a term constructor is consuming if it is destroyed during evaluation, whereas a persistent constructor remains as a syntactical part of the normal form. For example, given the following reduction to normal form x((λy.y)z)→vscnexy[y\z], we say that the leftmost application constructor in x((λy.y)z) is persistent, while the rightmost is consuming. Indeed, rule appP (resp. appC) is used to type this persistent (resp. consuming) application. More specifically, rule appP requires the left-hand side of the application to have type 𝕤, ensuring that no redex is created, so the application constructor is persistent. Variables that occur free at the top-level of a term are expected to be given the type 𝕤, which means that the underlined applications in z⁢t¯ and (x⁢t¯)⁢[x\z] would type with rule appP. Rule appC requires the left-hand side of the application to type with an arrow multi-type, ensuring a 𝖽𝖻-redex is created at some point during evaluation. For instance, the underlined applications in (x⁢t¯)⁢[x\𝙸] and (x⁢t¯)⁢[x\y]⁢[y\𝙸] would type with rule appC.

As just explained, system 𝒰 uses the consuming/persistent paradigm exclusively to type applications. This approach contrasts with more radical solutions [39] for CBV, which apply the same paradigm to type all constructors, thereby increasing the number of typing rules and making the type system more difficult to use.

The use of controlled weakening also deserves some discussion. Indeed, in CBV, the arguments of applications and ESs are always evaluated. Since system 𝒰 intends to characterise termination, all arguments must necessarily be typed. For example, in (λx.𝙸)(zz), the subexpression z⁢z is a structure of type 𝕤. One would perhaps expect to be able to type the abstraction λ⁢x.𝙸 with type 𝕤→𝒯. But it is impossible to derive the judgement x:𝕤⊢𝙸:𝒯, because x does not occur free in 𝙸. This is where the controlled weakening relation (≪) in the premise of rules appC and es comes into play. In our example, one can give a “stronger” type to λ⁢x.𝙸, namely ⊥→𝒯, using the fact that ⊥≪𝕤. A similar use of controlled weakening for the rule es is shown below, where it should be recalled that the empty typing environment ∅ is identical to ∅;x:⊥.

We end this subsection with another example that will be revisited later in the paper.

Example 1.

If t=(x⁢z)⁢[x\y⁢[y\𝙸]] and 𝒯:=[𝕤→𝕤], we build the following derivation Φ:

where 𝒯≪𝒯 and 𝕤≪𝕤 trivially hold.

3.2 Properties of System 𝓤

The fact that the var typing rule in 𝒰 is not weakened and that rules appP, appC, and es are multiplicative (which is implemented by means of the operator + on type environments) gives us a relevance property for system 𝒰. Formally:

Lemma 2 (Relevance).

If Φ⊳𝒰Γ⊢t:𝒯, then 𝗋𝗏⁢(t)⊆𝖽𝗈𝗆⁢(Γ)⊆𝖿𝗏⁢(t).

Proof.

See [16, Lemma 7.1]. ◀

Note that 𝖿𝗏⁢(t)⊆𝖽𝗈𝗆⁢(Γ) does not always hold. For instance, ⊳∅⊢λx.y:[] but {y}⊈∅.

Other specific properties of 𝒰 are stated in Section 5. We end this section by stating the key property that the system 𝒰 enjoys:

Theorem 3 (System 𝒰 Characterises vscne-Termination).

Let t be a term. Then, t is 𝒰-typable if and only if t is vscne-terminating.

4 Useful Call-by-Value

This section recalls ucbv∙, the inductive formulation of the useful open CBV strategy which provides a well-suited basis for semantic reasoning. Due to space limitations, we introduce only the main features of ucbv∙; a detailed presentation can be found in [15, 16].

We begin by introducing the key notions of useful evaluation. Then we recall the operational semantics of ucbv∙, and show some relevant properties of ucbv∙, such as the inductive characterisation of ucbv∙-normal forms (Theorem 5) and the diamond property (Theorem 6). The former ensures in particular that the length of any reduction sequence to normal form is independent of the specific order in which reduction rules are applied.

Useful Evaluation.

The calculus with ESs used to implement sharing in Accattoli and Dal Lago’s work [9] is based on a previous ES calculus with reduction at a distance called the Linear Substitution Calculus (LSC) [8]. In LSC, the reduction rule that implements function application is the same 𝖽𝖻-rule as in vscne (cf. subsection 2.2). Additionally, LSC uses a linear substitution rule, which only allows the substitution of a single occurrence of a variable x by a term t whenever x is bound to t by an ES. More precisely, the linear substitution rule (𝗅𝗌) of LSC allowing substitutions one occurrence at a time, is defined by the rewriting rule 𝙲⁢⟨x⟩⁢[x\t]→𝗅𝗌𝙲⁢⟨t⟩⁢[x\t], where 𝙲 denotes an arbitrary evaluation context. Substitution is called linear precisely because it replaces variables one occurrence at a time, for example (x⁢x)⁢[x\y]→𝗅𝗌(x⁢y)⁢[x\y]→𝗅𝗌(y⁢y)⁢[x\y].

Useful evaluation is based on two principles: sharing structures and (linearly) substituting abstractions for progress. We briefly recall them below.

Sharing Structures. In useful evaluation, a structure is a term whose unfolding – the result of performing all substitutions – results in an application headed by a variable. For example, (x⁢x)⁢[x\y⁢𝙸]⁢[y\z⁢z] is a structure, as it unfolds to z⁢z⁢𝙸⁢(z⁢z⁢𝙸). Structures must remain shared in useful evaluation, as substituting them does not create a 𝖽𝖻-redex. Thus, a term like (x⁢x)⁢[x\y⁢𝙸]⁢[y\z⁢z] is a normal form in useful evaluation.

Substituting Abstractions for Progress. In useful evaluation, abstractions are substituted only if they contribute to creating a 𝖽𝖻-redex, ensuring progress in the computation. For example, the reduction step x⁢[x\𝙸]⁢y→𝙸⁢[x\𝙸]⁢y is useful because substituting x by 𝙸 creates the 𝖽𝖻-redex 𝙸⁢[x\𝙸]⁢y. A subtler example of a useful step is (x⁢x)⁢[x\y]⁢[y\𝙸]→𝗅𝗌(y⁢x)⁢[x\y]⁢[y\𝙸], where the substitution indirectly contributes to creating a 𝖽𝖻-redex in the next step: (y⁢x)⁢[x\y]⁢[y\𝙸]→𝗅𝗌(𝙸⁢x)⁢[x\y]⁢[y\𝙸]. Such indirect steps are precisely those that are challenging to capture inductively. On the other hand, steps like x⁢[x\𝙸]→𝙸⁢[x\𝙸], and (x⁢x)⁢[x\y⁢y]→𝗅𝗌((y⁢y)⁢x)⁢[x\y⁢y] and (x⁢x)⁢[x\𝙸]→𝗅𝗌(x⁢𝙸)⁢[x\𝙸] are not useful, as these substitutions do not contribute to create a 𝖽𝖻-redex.

The principles just mentioned not only constitute the basis of useful CBN [9] but also that of useful CBV [1, 3], including ucbv∙ [15].

Towards Useful Call-by-Value Evaluation.

The key step to implement (linear) substituting abstractions for progress in ucbv∙ is to define a family of reduction relations indexed by parameters capturing the essential information from the surrounding evaluation contexts: this is the minimal data that cannot be ignored to decide which substitution step is useful and which is not. Two of these parameters are sets of variables: one is called an (abstraction) frame denoted 𝒜 and the second is called a (structure) frame denoted 𝒮. The purpose of these two kinds of variable sets is to classify the nature of variables bound by ESs.

Identifying terms that are already abstractions as well as those that are currently variables – but will ultimately be substituted with abstractions – is necessary to correctly determine whether a substitution step contributes to the progress of the evaluation. This property is captured by the following definition of hereditary abstractions under the frame 𝒜, written 𝖧𝖠𝒜:

For example, 𝙸⁢[x\y]∈𝖧𝖠∅ holds by the third rule, while x⁢[x\𝙸]∈𝖧𝖠∅ holds by the fourth rule. Note that the fourth rule allows building “chains” such as x⁢[x\y]⁢[y\z⁢[z\𝙸]]∈𝖧𝖠∅.

It is also necessary to identify those terms that represent an application headed by a free variable, called the set of structures under the frame 𝒮, written 𝖲𝗍𝒮, and defined as:

For example, w⁢[x\y]∈𝖲𝗍{w} holds by the second rule, w⁢(𝙸⁢x)∈𝖲𝗍{w} by the third rule, and x⁢[x\w]∈𝖲𝗍{w} by the fourth rule. Some properties of these predicates can be found in [15].

Useful Call-by-Value Reduction Rules.

We can now recall the reduction rules for our useful CBV strategy, ucbv∙. We first define a step kind as an element of the set {𝖽𝖻,𝗅𝗌𝗏,𝗌𝗎𝖻(x,v)}, with x being a variable and v a value such that x∉𝖿𝗏⁢(v). Let →ρ,𝒜,𝒮,μ be a family of binary relations, where ρ is a step kind, 𝒜 is an abstraction frame, 𝒮 a structure frame, and μ∈{@,@} is a constant called a positional flag. The positional flag @ means that the current focus of evaluation is in an applied position, while @ corresponds to a non-applied position. For example, the underlined x is applied in x¯⁢[x\𝙸]⁢t but not in (z⁢x¯)⁢[x\𝙸]. The relation →ρ,𝒜,𝒮,μ444In [15], this same relation is written →∙ρ,𝒜,𝒮,μ. of ucbv∙ is defined inductively as follows:

Reduction in ucbv∙ is weak, i.e., it is not allowed under abstractions, and it’s open, since it allows reducing terms with free occurrences of variables. The specification of ucbv∙ leaves the order of evaluation slightly underspecified. For example, in a term like x⁢t⁢u, the subterms t and u can be evaluated concurrently, without necessarily adhering to a strict (e.g. left-to-right) order. Technically speaking, the rules to evaluate applications are not mutually exclusive, and similarly for ESs. This non-determinism is harmless, as in fact ucbv∙ enjoys the diamond property (cf. Theorem 6). For a concrete example in which rules appL∙ and appR∙ overlap, consider:

x⁢(y⁢[y\𝙸])⁢(𝙸⁢𝙸)←𝖽𝖻,∅,{x},@x⁢(𝙸⁢𝙸)⁢(𝙸⁢𝙸)→𝖽𝖻,∅,{x},@x⁢(𝙸⁢𝙸)⁢(y⁢[y\𝙸])

For a concrete example in which esLS∙ and esR∙ overlap, consider:

(y⁢[y\𝙸])⁢[x\z⁢(𝙸⁢𝙸)]←𝖽𝖻,∅,{z},@(𝙸⁢𝙸)⁢[x\z⁢(𝙸⁢𝙸)]→𝖽𝖻,∅,{z},@(𝙸⁢𝙸)⁢[x\z⁢(y⁢[y\𝙸])]

As discussed in the introduction, useful evaluation is context-sensitive. That is, the context surrounding a term determines whether a step is useful or not. For instance, the term t=x⁢[x\𝙸] is already a normal form for ucbv∙ with respect to 𝒜=∅, 𝒮=∅, μ=@ because substituting x by 𝙸 is not useful, as it does not create a 𝖽𝖻-redex. However, if t appears on the left of an application, as in x⁢[x\𝙸]⁢(y⁢𝙸), the substitution of x by 𝙸 becomes useful, leading to the following reduction sequence:

x⁢[x\𝙸]⁢(y⁢𝙸)→𝗅𝗌𝗏,∅,{y},@𝙸⁢[x\𝙸]⁢(y⁢𝙸)→𝖽𝖻,∅,{y},@z⁢[z\y⁢𝙸]⁢[x\𝙸]

Conversely, a useful step like (x⁢u)⁢[x\𝙸]→𝗅𝗌𝗏,∅,∅,@(𝙸⁢u)⁢[x\𝙸] may not be allowed if the term is located below a context such as λ⁢y.◇; in fact, note that λ⁢y.(x⁢u)⁢[x\𝙸] cannot be reduced.

A term t is (ρ,𝒜,𝒮,μ)-irreducible if there is no term t′ such that t→ρ,𝒜,𝒮,μt′. A term t belongs to the set 𝖨𝗋𝗋𝖾𝖽𝒜,𝒮,μ∙ if t is (ρ,𝒜,𝒮,μ)-irreducible.

An abstraction frame 𝒜 and a structure frame 𝒮 are said to verify the correctness invariant for t, written 𝗂𝗇𝗏⁢(𝒜,𝒮,t), if 𝒜∩𝒮=∅ and 𝖿𝗏⁢(t)⊆𝒜∪𝒮. This invariant is typically assumed in theorems and lemmas. Note that 𝗂𝗇𝗏⁢(∅,𝖿𝗏⁢(t),t) always holds, so for a top-level term t, we set 𝒜:=∅ and 𝒮:=𝖿𝗏⁢(t).

Rule sub∙ is an auxiliary tool to ensure that substitution in ucbv∙ is linear. In general, we care about top-level ucbv∙ reduction, defined as →𝚝𝚘𝚙,𝒮⁣:=⁣→𝖽𝖻,∅,𝒮,@⁣∪⁣→𝗅𝗌𝗏,∅,𝒮,@.

Example 4.

The following is a ucbv∙ reduction sequence to normal form:

(x⁢z)⁢[x\y⁢[y\𝙸]]→𝗅𝗌𝗏,∅,{z},@(y⁢z)⁢[x\y]⁢[y\𝙸]→𝗅𝗌𝗏,∅,{z},@(𝙸⁢z)⁢[x\y]⁢[y\𝙸]→𝖽𝖻,∅,{z},@x1⁢[x1\z]⁢[x\y]⁢[y\𝙸]

To conclude this section, we recall some of the key operational properties of ucbv∙, starting with a characterisation of the set of ucbv∙-normal forms [15, Theorem 1]:

Theorem 5.

The set of irreducible terms 𝖨𝗋𝗋𝖾𝖽𝒜,𝒮,μ∙ is exactly the set 𝖭𝖥𝒜,𝒮,μ∙ defined inductively as:

An important property of top-level ucbv∙ is that it enjoys a strong form of confluence, the Diamond Property [15, Theorem 2]:

Theorem 6.

Let t→ρ1,∅,𝒮,@t1 and t→ρ2,∅,𝒮,@t2, where t1≠t2, and ρ1,ρ2∈{𝖽𝖻,𝗅𝗌𝗏}, and 𝒮=𝖿𝗏⁢(t). Then there exists t′ such that t1→ρ2,∅,𝒮,@t′ and t2→ρ1,∅,𝒮,@t′.

Some straightforward corollaries of the diamond property are, firstly, that a term t is weakly terminating in top-level ucbv∙ if and only if t is terminating in top-level ucbv∙. Secondly, that any two reduction sequences to normal form have the same number of 𝖽𝖻 and 𝗅𝗌𝗏-steps. And finally, top-level ucbv∙ reduction is immediately seen to be confluent. These corollaries are important for reaching our results in Section 5.

5 (Quantitative) Soundness and Completeness of System 𝓤

In this section, we refine system 𝒰 to capture quantitative information of ucbv∙ evaluation. Indeed, we equip typing judgements of system 𝒰 with counters, and we define a notion of tight derivation, intuitively corresponding to that of minimal derivation. The counters are meant to capture exact step-count for program evaluation. More precisely, tight derivations in system 𝒰 not only guarantee termination in ucbv∙ but also provide exact quantitative information about this evaluation strategy: we show that a term t is tightly typable with counters (m,e) if and only if t evaluates in ucbv∙ to a normal form in exactly m function application steps (i.e., 𝖽𝖻-steps) and e substitution steps (i.e., 𝗅𝗌𝗏-steps). In this sense, we say that system 𝒰 is a quantitative interpretation of useful CBV.

5.1 Tightness for System 𝓤

As explained above, we start by refining the typing judgements of system 𝒰 with counters. Formally, typing judgements are now of the form Γ⊢(m,e)t:𝒯, where m and e are natural numbers called counters. Under appropriate conditions, these counters correspond exactly to the number of 𝖽𝖻-steps (m) and 𝗅𝗌𝗏-steps (e) in ucbv∙ evaluation, as shown in Theorems 10 and 13. Typing rules are refined accordingly. To do so, we introduce an operation 𝚝𝚊⁢(_) that counts the number of top-level arrows in a type (or optional type). It is defined by 𝚝𝚊⁢(⊥):=0, 𝚝𝚊⁢(𝕤):=0, and 𝚝𝚊⁢([αi]i∈I):=|I|. Note that 𝚝𝚊⁢(𝒯1+𝒯2)=𝚝𝚊⁢(𝒯1)+𝚝𝚊⁢(𝒯2). Formally, typing rules of system 𝒰 are enriched with counters as follows:

Only two typing rules are increasing the counters. Rule var initialises the second counter to the number of top-level arrows in the type of the variable. This counter corresponds to the number of times the variable is (directly or indirectly) substituted by an abstraction taking part in some 𝖽𝖻-redex during evaluation. That is why the second counter tracks substitution step-count. Rule appC increases the first counter by one, reflecting that the application constructor introduced by this rule is consuming, meaning it will be destroyed during evaluation. That is why the first counter tracks function application step-count.

▶ Remark 7.

Counters are a convenient way to synthesise information already existing in a typing derivation: they do not impose any side conditions on derivations. Formally, ⊳Γ⊢t:𝒯 if and only if ⊳Γ⊢(m,e)t:𝒯 for some (m,e). Moreover, the counters can be entirely extracted from the type information and typing rules of a derivation, no reference to the terms themselves is needed to compute them.

In what follows, we outline some basic properties of system 𝒰.

Appropriateness.

To reason inductively about typing derivations, it is sometimes necessary to ensure invariants for the types of the free variables in a term. For example, for a term like t⁢[x\𝙸], we may need to track that x is bound to an abstraction when applying the inductive hypothesis for the subterm t. Specifically, we say that a typing environment Γ is appropriate with respect to an abstraction frame 𝒜, written 𝚊𝚙𝚙𝚛𝚘𝚙𝚛𝚒𝚊𝚝𝚎𝒜⁢(Γ) if, for each x∈𝒜, we have Γ⁢(x)≠𝕤. In other words, Γ⁢(x) must be ⊥ or an arrow multi-type ℳ. For instance, 𝚊𝚙𝚙𝚛𝚘𝚙𝚛𝚒𝚊𝚝𝚎{x}(x:[],y:𝕤) holds, while 𝚊𝚙𝚙𝚛𝚘𝚙𝚛𝚒𝚊𝚝𝚎{x}(x:𝕤,y:𝕤) does not.

Tightness.

Typing in system 𝒰 not only characterises ucbv∙ termination, but it is also capable of providing exact measures for reduction lengths to normal form. To state this formally, we define a subset of typing derivations, called tight derivations, as follows. A type is tight if it is a constant type 𝕥, i.e., either of the form 𝕤 or []. An optional type 𝒯? is tight if it is either ⊥ or a tight type. A typing environment Γ is tight if Γ⁢(x) is tight for every variable x. A typing judgement Γ⊢(m,e)t:𝒯 is tight if both Γ and 𝒯 are tight. A derivation of a typing judgement is tight if the judgement itself is tight.

For example, the derivable judgement x:[]⊢(0,0)x:[] is tight, where the counters (0,0) indicate that evaluating x requires no reduction steps, meaning x is already in normal form. In contrast, the judgement x:[𝒯→𝒮]⊢(0,1)x:[𝒯→𝒮] is not tight, and the counters (0,1) provide an upper bound on the number of steps required for evaluating x.

Example 8.

Let t=(x⁢z)⁢[x\y⁢[y\𝙸]]. Taking 𝒯:=[𝕤→𝕤], the following derivation Φ′ (a decoration of Φ in Example 1) turns out to be tight:

where 𝕤≪𝕤 and 𝒯=[𝕤→𝕤]≪[𝕤→𝕤]=𝒯 both hold.

Note that the only subderivations of Φ′ which are tight (besides Φ′ itself) correspond to the one concluding in z:𝕤⊢(0,0)z:𝕤 and the one concluding in w:𝕤⊢(0,0)w:𝕤. The remaining subderivations are not tight.

Tightness is essential for proving that system 𝒰 is sound and complete with respect to ucbv∙ (Theorems 10 and 13).

5.2 Soundness and Completeness

We first address the soundness of system 𝒰 with respect to ucbv∙: typability implies ucbv∙-termination. This proof follows well-understood techniques, requiring a subject reduction property based on a substitution lemma. Due to the contextual nature of ucbv∙, these lemmas are not trivial, as they demand formulating complex invariants involving the contextual parameters 𝒜, 𝒮, and μ that define the evaluation strategy.

We first show subject reduction, stating that each ucbv∙ reduction step preserves typing and correctly decrements the counters.

Proposition 9 (Subject Reduction).

Let t→ρ,𝒜,𝒮,μt′ where ρ∈{𝖽𝖻,𝗅𝗌𝗏} and Φ⊳Γ⊢(m,e)t:𝒯, with 𝚊𝚙𝚙𝚛𝚘𝚙𝚛𝚒𝚊𝚝𝚎𝒜⁢(Γ). Suppose moreover that if μ=@, then either 𝒯=𝕤 or 𝒯 is a singleton, i.e., of the form [α]. Then, there exists a derivation Φ′ such that Φ′⊳Γ⊢(m′,e′)t′:𝒯, where if ρ=𝖽𝖻, then m>0 and (m′,e′)=(m−1,e), and if ρ=𝗅𝗌𝗏, then e>0 and (m′,e′)=(m,e−1).

Proof.

See [16, Proposition 7.3]. ◀

We can now conclude with a quantitative version of soundness: a tight typing derivation of a term t with counters (m,e) guarantees a terminating ucbv∙ reduction sequence, with exactly m 𝖽𝖻-steps and e 𝗅𝗌𝗏-steps.

Theorem 10 (Quantitative Soundness of System 𝒰).

Let 𝒮=𝖿𝗏⁢(t), and let Φ⊳Γ⊢(m,e)t:𝒯. Then, there exists a →𝚝𝚘𝚙,𝒮-irreducible term u such that t reduces to u. Moreover, if Φ is tight, then t→𝚝𝚘𝚙,𝒮m+eu, where m and e are respectively the number of 𝖽𝖻 and 𝗅𝗌𝗏 steps in the previous reduction sequence.

To illustrate this property, consider the tight derivation Φ for t=(x⁢z)⁢[x\y⁢[y\𝙸]] in Example 8, where the counter in the conclusion of Φ is (1,2). A reduction sequence from t terminates in x1⁢[x1\z]⁢[x\y]⁢[y\𝙸]∈𝖭𝖥∅,{z},@∙ in exactly 1 𝖽𝖻-steps and 2 𝗅𝗌𝗏-steps (see Example 4). Note how these numbers match the previous counters.

Tightness in the previous example is crucial. Indeed, non-tight judgements may not provide exact information about the length of reduction sequences to normal form. For example, the derivation of the judgement z:𝕤,x:𝒯⊢(1,1)xz:𝕤 in Example 8 is not tight, as 𝒯 is not tight, and the counters (1,1) do not correspond to the number of steps needed to reach the normal form of x⁢z which is already in normal form.

Completeness of system 𝒰 can be proved using standard techniques, requiring a subject expansion property. These statements are quite technical, as the properties must be generalised for inductive reasoning.

The first property guarantees that normal forms are tightly typable in system 𝒰. For that, we need to construct tight environments for each normal form t∈𝖭𝖥𝒜,𝒮,μ∙; this is done by typing the reachable variables in 𝒜 with [] and those in 𝒮 with 𝕤. More precisely, given t, 𝒜, and 𝒮 such that 𝗂𝗇𝗏⁢(𝒜,𝒮,t), the tight environment for t under 𝒜 and 𝒮 is written 𝖳𝖤𝗇𝗏⁢(𝒜,𝒮,t) and defined as the environment Γ such that Γ⁢(x)=[] when x∈𝒜∩𝗋𝗏⁢(t), Γ⁢(x)=𝕤 when x∈𝒮∩𝗋𝗏⁢(t), and Γ⁢(x)=⊥ otherwise. Tight environments allow us to type normal forms tightly.

Proposition 11 (Normal Forms are Tight Typable).

Let t be a term in 𝖭𝖥𝒜,𝒮,μ∙ and 𝗂𝗇𝗏⁢(𝒜,𝒮,t). Then, there exists a tight type 𝕥 such that ⊳𝖳𝖤𝗇𝗏(𝒜,𝒮,t)⊢(0,0)t:𝕥. Moreover, if t∈𝖧𝖠𝒜, then 𝕥=[], and if t∈𝖲𝗍𝒮, then 𝕥=𝕤.

Proof.

See [16, Proposition 7.5]. ◀

Subject Expansion is analogous to (Subject Reduction). but applies in the reverse direction: given a typable term t′ and a reduction step t→ρ,𝒜,𝒮,μt′, the term t is typable as well, with the same type and typing environment.

Proposition 12 (Subject Expansion).

Let 𝗂𝗇𝗏⁢(𝒜,𝒮,t) hold, and suppose t→ρ,𝒜,𝒮,μt′ where ρ∈{𝖽𝖻,𝗅𝗌𝗏} and Φ′⊳Γ⊢(m′,e′)t′:𝒯, with 𝚊𝚙𝚙𝚛𝚘𝚙𝚛𝚒𝚊𝚝𝚎𝒜⁢(Γ). Furthermore, assume that if μ=@, then either 𝒯=𝕤 or 𝒯 is a singleton, i.e., of the form [α]. Then, there exists a derivation Φ such that Φ⊳Γ⊢(m,e)t:𝒯, where if ρ=𝖽𝖻, then (m,e)=(m′+1,e′), and if ρ=𝗅𝗌𝗏, then (m,e)=(m′,e′+1).

Proof.

See [16, Proposition 7.6]. ◀

We now conclude with a quantitative version of completeness of system 𝒰. That is, given a terminating ucbv∙ reduction sequence from t with exactly m 𝖽𝖻-steps and e 𝗅𝗌𝗏-steps, there exists a tight derivation of t with counters (m,e):

Theorem 13 (Quantitative Completeness of System 𝒰).

Let 𝒮=𝖿𝗏⁢(t) and consider a reduction sequence t→𝚝𝚘𝚙,𝒮nu, where u is →𝚝𝚘𝚙,𝒮-irreducible. Let n=m+e, where m and e are respectively the numbers of 𝖽𝖻 and 𝗅𝗌𝗏 steps in the sequence. Then, there exists a tight environment Γ and a tight type 𝕥 such that ⊳Γ⊢(m,e)t:𝕥.

To illustrate this result, take the reduction sequence starting from t=(x⁢z)⁢[x\y⁢[y\𝙸]] and ending in x1⁢[x1\z]⁢[x\y]⁢[y\𝙸]∈𝖭𝖥∅,{z},@∙ (see Example 4). The length of this sequence is 3=m+e, with m=1 𝖽𝖻-step and e=2 𝗅𝗌𝗏-steps. Example 8 shows a tight environment z:𝕤 and a tight type 𝕤 such that Φ⊳z:𝕤⊢(1,2)t:𝕤.

Theorems 10 and 13 state that a term t is typable in system 𝒰 if and only if t is weakly terminating. The characterisation of ucbv∙ termination through typability follows from these theorems and the fact that all reduction sequences to normal form have the same length in ucbv∙ (an easy corollary of Theorem 6). Moreover, this characterisation is quantitative:

Corollary 14 (Quantitative Characterisation of Termination).

A term t is tightly typable with counters (m,e) in system 𝒰 if and only if t terminates in ucbv∙ after m function application 𝖽𝖻-steps and e substitution 𝗅𝗌𝗏-steps.

We can now conclude with the main contribution of this work.

Corollary 15.

Let t be a term. The following statements are equivalent:

  1. 1.

    t is typable in system 𝒰.

  2. 2.

    t terminates in vsc.

  3. 3.

    t terminates in vscne.

  4. 4.

    t terminates in top-level ucbv∙ reduction.

Proof.

(1 ⇔ 3) is Theorem 3. (1 ⇒ 4) Any 𝒰-typable term terminates in ucbv∙ by Proposition 9. (4 ⇒ 1) Immediate by Theorem 13. Therefore (1 ⇔ 3 ⇔ 4).

Subject reduction for vsc fails with respect to 𝒰. Hence, to prove (3 ⇔ 2) we resort to an alternative type system 𝒱 [19], inspired by Ehrhard’s system [28]. Indeed, a term t is typable in system 𝒱 if and only if t terminates in vsc [19, Theorem 5]. It can also be shown that system 𝒱 characterises termination in vscne (see Appendix B for details), thus concluding the last equivalence555An interesting additional consequence is that systems 𝒰 and 𝒱 type the same terms.. ◀

We can conclude this section by emphasising an important consequence. As usual, a context 𝙲 is a term with a single occurrence of a hole ◇, and 𝙲⁢⟨t⟩ denotes the term obtained by replacing the hole in 𝙲 by t. Given a reduction system ℛ, we define t to be observationally equivalent to u, written t≅ℛu, if and only if for every context 𝙲 we have that 𝙲⁢⟨t⟩ ℛ-terminates if and only if 𝙲⁢⟨u⟩ ℛ-terminates. Then ℛ1 and ℛ2 are observationally equivalent if and only if for every t,u, we have t≅ℛ1u⟺t≅ℛ2u.

Corollary 15 above establishes in particular that the (potentially) erasing vsc, and the non-erasing vsc and top-level ucbv∙ strategy are pairwise observational equivalent.

6 Conclusions

This paper presents the first semantic model of useful evaluation in the literature, based on the non-idempotent intersection type system 𝒰. Even though the specification of the operational semantics of useful CBV evaluation is highly complex, system 𝒰 is notably simple. This highlights the ability of semantic approaches based on non-idempotent intersection types to capture intricate operational details with streamlined intuitive methods.

System 𝒰 characterises termination of the ucbv∙ evaluation strategy as well as termination of vscne. This ensures in particular that useful CBV evaluation can be seen as an optimisation of CBV that preserves its original semantics: they are observationally equivalent.

Moreover, system 𝒰 provides exact measures for the lengths of reduction sequences in ucbv∙ to normal form; that is why system 𝒰 is a quantitative interpretation of ucbv∙. More precisely, a term t is tightly typable with counters m and e in system 𝒰 if and only if t terminates in ucbv∙ in exactly m function application steps and e substitution steps.

Our contribution is novel, as previous definitions of useful evaluation (including useful CBV) in the literature lack semantic models, and current quantitative interpretations of CBV do not consider usefulness. Moreover, with the exception of [39], entirely based on the (verbose) persistent/consuming paradigm, this is the only simple and concise quantitative type system for open CBV that is able to count all kind of substitution steps (variables and abstractions) exactly.

Several lines of work stem from this paper. One first objective is to understand the flexibility of system 𝒰, particularly its potential to capture some other optimisations of CBV, such as those in [5]. Additionally, it would be interesting to capture recent alternative specifications of usefulness, such as those in [45], which focus exclusively on direct useful reduction steps. Notably, erasing reduction steps in [45] pose a non-trivial difficulty for non-idempotent type systems designed for usefulness. Another challenging direction is to extend our inductive formalisation of useful evaluation to strong CBV, thus allowing reductions to take place inside abstractions. The methodology we have used to design system 𝒰 could then be applied to such extensions.

References

  • [1] Beniamino Accattoli and Claudio Sacerdoti Coen. On the relative usefulness of fireballs. In 30th Annual ACM/IEEE Symposium on Logic in Computer Science, LICS 2015, Kyoto, Japan, July 6-10, 2015, pages 141–155. IEEE Computer Society, 2015. doi:10.1109/LICS.2015.23.
  • [2] Beniamino Accattoli, Stéphane Graham-Lengrand, and Delia Kesner. Tight typings and split bounds. Proc. ACM Program. Lang., 2(ICFP):94:1–94:30, 2018. doi:10.1145/3236789.
  • [3] Beniamino Accattoli and Giulio Guerrieri. Implementing open call-by-value. In Mehdi Dastani and Marjan Sirjani, editors, Fundamentals of Software Engineering - 7th International Conference, FSEN 2017, Tehran, Iran, April 26-28, 2017, Revised Selected Papers, volume 10522 of Lecture Notes in Computer Science, pages 1–19. Springer, 2017. doi:10.1007/978-3-319-68972-2_1.
  • [4] Beniamino Accattoli and Giulio Guerrieri. Types of fireballs. In Sukyoung Ryu, editor, Programming Languages and Systems - 16th Asian Symposium, APLAS 2018, Wellington, New Zealand, December 2-6, 2018, Proceedings, volume 11275 of Lecture Notes in Computer Science, pages 45–66. Springer, 2018. doi:10.1007/978-3-030-02768-1_3.
  • [5] Beniamino Accattoli and Giulio Guerrieri. Abstract machines for open call-by-value. Sci. Comput. Program., 184, 2019. doi:10.1016/J.SCICO.2019.03.002.
  • [6] Beniamino Accattoli and Giulio Guerrieri. The theory of call-by-value solvability. Proc. ACM Program. Lang., 6(ICFP):855–885, 2022. doi:10.1145/3547652.
  • [7] Beniamino Accattoli, Giulio Guerrieri, and Maico Leberle. Types by need. In Luís Caires, editor, Programming Languages and Systems - 28th European Symposium on Programming, ESOP 2019, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2019, Prague, Czech Republic, April 6-11, 2019, Proceedings, volume 11423 of Lecture Notes in Computer Science, pages 410–439. Springer, 2019. doi:10.1007/978-3-030-17184-1_15.
  • [8] Beniamino Accattoli and Delia Kesner. The structural lambda-calculus. In Anuj Dawar and Helmut Veith, editors, Computer Science Logic, 24th International Workshop, CSL 2010, 19th Annual Conference of the EACSL, Brno, Czech Republic, August 23-27, 2010. Proceedings, volume 6247 of Lecture Notes in Computer Science, pages 381–395. Springer, 2010. doi:10.1007/978-3-642-15205-4_30.
  • [9] Beniamino Accattoli and Ugo Dal Lago. Beta reduction is invariant, indeed. In Thomas A. Henzinger and Dale Miller, editors, Joint Meeting of the Twenty-Third EACSL Annual Conference on Computer Science Logic (CSL) and the Twenty-Ninth Annual ACM/IEEE Symposium on Logic in Computer Science (LICS), CSL-LICS ’14, Vienna, Austria, July 14 - 18, 2014, pages 8:1–8:10. ACM, 2014. doi:10.1145/2603088.2603105.
  • [10] Beniamino Accattoli and Luca Paolini. Call-by-value solvability, revisited. In Tom Schrijvers and Peter Thiemann, editors, Functional and Logic Programming - 11th International Symposium, FLOPS 2012, Kobe, Japan, May 23-25, 2012. Proceedings, volume 7294 of Lecture Notes in Computer Science, pages 4–16. Springer, 2012. doi:10.1007/978-3-642-29822-6_4.
  • [11] Sandra Alves, Delia Kesner, and Miguel Ramos. Quantitative global memory. In Helle Hvid Hansen and Andre Scedrov, editors, Logic, Language, Information, and Computation - 29th International Workshop, WoLLIC 2023, Halifax, Canada, September 20-23, 2023, Proceedings, Lecture Notes in Computer Science, 2023.
  • [12] Zena M. Ariola, Matthias Felleisen, John Maraist, Martin Odersky, and Philip Wadler. The call-by-need lambda calculus. In Ron K. Cytron and Peter Lee, editors, Conference Record of POPL’95: 22nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, San Francisco, California, USA, January 23-25, 1995, pages 233–246. ACM Press, 1995. doi:10.1145/199448.199507.
  • [13] Thibaut Balabonski, Pablo Barenbaum, Eduardo Bonelli, and Delia Kesner. Foundations of strong call by need. Proc. ACM Program. Lang., 1(ICFP):20:1–20:29, 2017. doi:10.1145/3110264.
  • [14] Pablo Barenbaum, Eduardo Bonelli, and Kareem Mohamed. Pattern matching and fixed points: Resource types and strong call-by-need: Extended abstract. In David Sabel and Peter Thiemann, editors, Proceedings of the 20th International Symposium on Principles and Practice of Declarative Programming, PPDP 2018, Frankfurt am Main, Germany, September 03-05, 2018, pages 6:1–6:12. ACM, 2018. doi:10.1145/3236950.3236972.
  • [15] Pablo Barenbaum, Delia Kesner, and Mariana Milicich. A fresh inductive approach to useful call-by-value. In Clark W. Barrett and Uwe Waldmann, editors, Automated Deduction - CADE 30 - 30th International Conference on Automated Deduction, Stuttgart, Germany, July 28-31, 2025, Proceedings, volume 15943 of Lecture Notes in Computer Science, pages 381–399. Springer, 2025. doi:10.1007/978-3-031-99984-0_21.
  • [16] Pablo Barenbaum, Delia Kesner, and Mariana Milicich. Useful evaluation: Syntax and semantics (technical report), 2025. arXiv:2404.18874.
  • [17] Alexis Bernadet and Stéphane Lengrand. Non-idempotent intersection types and strong normalisation. Logical Methods in Computer Science, 9(4), 2013. doi:10.2168/LMCS-9(4:3)2013.
  • [18] Antonio Bucciarelli and Thomas Ehrhard. On phase semantics and denotational semantics: the exponentials. Ann. Pure Appl. Log., 109(3):205–241, 2001. doi:10.1016/S0168-0072(00)00056-7.
  • [19] Antonio Bucciarelli, Delia Kesner, Alejandro Ríos, and Andrés Viso. The bang calculus revisited. In Keisuke Nakano and Konstantinos Sagonas, editors, Functional and Logic Programming - 15th International Symposium, FLOPS 2020, Akita, Japan, September 14-16, 2020, Proceedings, volume 12073 of Lecture Notes in Computer Science, pages 13–32. Springer, 2020. doi:10.1007/978-3-030-59025-3_2.
  • [20] Antonio Bucciarelli, Delia Kesner, Alejandro Ríos, and Andrés Viso. The bang calculus revisited. Inf. Comput., 293:105047, 2023. doi:10.1016/J.IC.2023.105047.
  • [21] Antonio Bucciarelli, Delia Kesner, and Daniel Ventura. Non-idempotent intersection types for the lambda-calculus. Log. J. IGPL, 25(4):431–464, 2017. doi:10.1093/JIGPAL/JZX018.
  • [22] Daniel de Carvalho. Sémantiques de la logique linéaire et temps de calcul. PhD thesis, Ecole Doctorale Physique et Sciences de la Matière (Marseille), 2007.
  • [23] Mario Coppo and Mariangiola Dezani-Ciancaglini. A new type assignment for λ-terms. Arch. Math. Log., 19(1):139–156, 1978. doi:10.1007/BF02011875.
  • [24] Mario Coppo and Mariangiola Dezani-Ciancaglini. An extension of the basic functionality theory for the λ-calculus. Notre Dame J. Formal Log., 21(4):685–693, 1980. doi:10.1305/NDJFL/1093883253.
  • [25] Daniel de Carvalho. Execution time of λ-terms via denotational semantics and intersection types. Mathematical Structures in Computer Science, 28(7):1169–1203, 2018. doi:10.1017/S0960129516000396.
  • [26] Daniel de Carvalho and Lorenzo Tortora de Falco. A semantic account of strong normalization in linear logic. Inf. Comput., 248:104–129, 2016. doi:10.1016/J.IC.2015.12.010.
  • [27] Daniel de Carvalho, Michele Pagani, and Lorenzo Tortora de Falco. A semantic measure of the execution time in linear logic. Theor. Comput. Sci., 412(20):1884–1902, 2011. doi:10.1016/J.TCS.2010.12.017.
  • [28] Thomas Ehrhard. Collapsing non-idempotent intersection types. In Patrick Cégielski and Arnaud Durand, editors, Computer Science Logic (CSL’12) - 26th International Workshop/21st Annual Conference of the EACSL, CSL 2012, September 3-6, 2012, Fontainebleau, France, volume 16 of LIPIcs, pages 259–273. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2012. doi:10.4230/LIPIcs.CSL.2012.259.
  • [29] Álvaro García-Pérez and Pablo Nogueira. No solvable lambda-value term left behind. Log. Methods Comput. Sci., 12(2), 2016. doi:10.2168/LMCS-12(2:12)2016.
  • [30] Philippa Gardner. Discovering needed reductions using type theory. In Theoretical Aspects of Computer Software, pages 555–574. Springer, 1994. doi:10.1007/3-540-57887-0_115.
  • [31] Jean-Yves Girard. Linear logic. Theor. Comput. Sci., 50:1–102, 1987. doi:10.1016/0304-3975(87)90045-4.
  • [32] Jean-Yves Girard. Normal functors, power series and λ-calculus. Ann. Pure Appl. Log., 37(2):129–177, 1988. doi:10.1016/0168-0072(88)90025-5.
  • [33] Benjamin Grégoire and Xavier Leroy. A compiled implementation of strong reduction. In Mitchell Wand and Simon L. Peyton Jones, editors, Proceedings of the Seventh ACM SIGPLAN International Conference on Functional Programming (ICFP ’02), Pittsburgh, Pennsylvania, USA, October 4-6, 2002, pages 235–246. ACM, 2002. doi:10.1145/581478.581501.
  • [34] Giulio Guerrieri. Towards a semantic measure of the execution time in call-by-value lambda-calculus. In Michele Pagani and Sandra Alves, editors, Proceedings Twelfth Workshop on Developments in Computational Models and Ninth Workshop on Intersection Types and Related Systems, DCM/ITRS 2018, Oxford, UK, 8th July 2018, volume 293 of EPTCS, pages 57–72, 2018. doi:10.4204/EPTCS.293.5.
  • [35] Delia Kesner. A theory of explicit substitutions with safe and full composition. Logical Methods in Computer Science, 5(3), 2009. URL: http://arxiv.org/abs/0905.2539.
  • [36] Delia Kesner. Reasoning about call-by-need by means of types. In Bart Jacobs and Christof Löding, editors, Foundations of Software Science and Computation Structures - 19th International Conference, FOSSACS 2016, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2016, Eindhoven, The Netherlands, April 2-8, 2016, Proceedings, volume 9634 of Lecture Notes in Computer Science, pages 424–441. Springer, 2016. doi:10.1007/978-3-662-49630-5_25.
  • [37] Delia Kesner and Pierre Vial. Types as resources for classical natural deduction. In Dale Miller, editor, 2nd International Conference on Formal Structures for Computation and Deduction, FSCD 2017, September 3-9, 2017, Oxford, UK, volume 84 of LIPIcs, pages 24:1–24:17. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2017. doi:10.4230/LIPIcs.FSCD.2017.24.
  • [38] Delia Kesner and Pierre Vial. Consuming and persistent types for classical logic. In Holger Hermanns, Lijun Zhang, Naoki Kobayashi, and Dale Miller, editors, LICS ’20: 35th Annual ACM/IEEE Symposium on Logic in Computer Science, Saarbrücken, Germany, July 8-11, 2020, pages 619–632. ACM, 2020. doi:10.1145/3373718.3394774.
  • [39] Delia Kesner and Andrés Viso. Encoding tight typing in a unified framework. In Florin Manea and Alex Simpson, editors, 30th EACSL Annual Conference on Computer Science Logic, CSL 2022, February 14-19, 2022, Göttingen, Germany (Virtual Conference), volume 216 of LIPIcs, pages 27:1–27:20. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2022. doi:10.4230/LIPIcs.CSL.2022.27.
  • [40] Maico Leberle. Dissecting call-by-need by customizing multi type systems. (Une dissection de l’appel-par-nécessité par la personnalisation des systèmes de multi types). PhD thesis, IP Paris, France, 2021. URL: https://tel.archives-ouvertes.fr/tel-03284370.
  • [41] John Maraist, Martin Odersky, David N. Turner, and Philip Wadler. Call-by-name, call-by-value, call-by-need and the linear lambda calculus. In Stephen D. Brookes, Michael G. Main, Austin Melton, and Michael W. Mislove, editors, Eleventh Annual Conference on Mathematical Foundations of Programming Semantics, MFPS 1995, Tulane University, New Orleans, LA, USA, March 29 - April 1, 1995, volume 1 of Electronic Notes in Theoretical Computer Science, pages 370–392. Elsevier, 1995. doi:10.1016/S1571-0661(04)00022-2.
  • [42] Luca Paolini and Simona Ronchi Della Rocca. Call-by-value solvability. RAIRO Theor. Informatics Appl., 33(6):507–534, 1999. doi:10.1051/ITA:1999130.
  • [43] Gordon D. Plotkin. Call-by-name, call-by-value and the lambda-calculus. Theor. Comput. Sci., 1(2):125–159, 1975. doi:10.1016/0304-3975(75)90017-1.
  • [44] Terese. Term Rewriting Systems, volume 55 of Cambridge Tracts in Theoretical Computer Science. Cambridge University Press, 2003.
  • [45] Jui-Hsuan Wu. Proofs as terms, terms as graphs. In Chung-Kil Hur, editor, Programming Languages and Systems - 21st Asian Symposium, APLAS 2023, Taipei, Taiwan, November 26-29, 2023, Proceedings, volume 14405 of Lecture Notes in Computer Science, pages 91–111. Springer, 2023. doi:10.1007/978-981-99-8311-7_5.

Appendix A Proofs of Section 3

Measures.

Given an optional type 𝒯?, we define its size as |⊥|:=0, |𝕤|:=0 and |[αk]k∈K|:=|K|. We remark that |𝒯1?+𝒯2?|=|𝒯1?|+|𝒯2?|.

In this subsection, we measure typing derivations in system 𝒰 by using a function 𝚜𝚣⁢(_), defined inductively as follows:

When a typing derivation Φ ends with rule es, 𝚜𝚣⁢(Φ) is defined according to two different cases. Whenever x∈𝖿𝗏⁢(u), then a substitution of x by u takes place, hence we add 1 to the sum of the sizes of the derivations of both t and u.

We first address the soundness of system 𝒰 with respect to vscne, which states that 𝒰-typability implies vscne-termination. This proof follows well-understood techniques, requiring a subject reduction property based on a substitution lemma. For proving the latter, we need an additional lemma allowing the decomposition of the multiset types of values:

Lemma 16 (Splitting/Merging).

Let 𝒯1 and 𝒯2 be two types such that their union 𝒯1+𝒯2 is well-defined. Then, the following are equivalent:

  1. 1.

    Φ⊳Γ⊢v:𝒯1+𝒯2

  2. 2.

    There exist typing derivations Φ1,Φ2 and typing contexts Γ1,Γ2 such that Φ1⊳Γ1⊢v:𝒯1, and Φ2⊳Γ2⊢v:𝒯2, and Γ=Γ1+Γ2.

Moreover, 𝚜𝚣⁢(Φ)=𝚜𝚣⁢(Φ1)+𝚜𝚣⁢(Φ2).

Proof.

The proof corresponds to that of [16, Lemma E.3], and it is straightforward to prove that 𝚜𝚣⁢(Φ)=𝚜𝚣⁢(Φ1)+𝚜𝚣⁢(Φ2). ◀

Lemma 17 (Type Splitting).

Let 𝒮1?, 𝒮2? be two optional types and 𝒮 be a type. Then 𝒮1?+𝒮2? is well-defined and 𝒮1?+𝒮2?≪𝒮 if and only if there exist types 𝒮1 and 𝒮2 such that 𝒮1+𝒮2=𝒮 and 𝒮i?≪𝒮i for all i∈{1,2}.

Proof.

Both directions of the lemma follow by case analysis on 𝒮1? and 𝒮2?. ◀

Lemma 18 (Substitution).

Let Φt⊳𝒰Γ;x:𝒮?⊢t:𝒯 and Φv⊳𝒰Δ⊢v:𝒮, with 𝒮?≪𝒮 and x∈𝖿𝗏⁢(t). Then, there exists a typing derivation Φt⁢{x:=v} such that Φt⁢{x:=v}⊳𝒰Γ+Δ⊢t⁢{x:=v}:𝒯 and moreover 𝚜𝚣⁢(Φt⁢{x:=v})=𝚜𝚣⁢(Φt)+𝚜𝚣⁢(Φv)−|𝒮?|.

Proof.

By induction on Φt. We show only case var, as the inductive cases follow easily from the i.h. and Lemmas 16 and 17.

If Φt ends with var, then t=x, since x∈𝖿𝗏⁢(t) by hypothesis. Then, t⁢{x:=v}=v and Φt is of the form x:𝒯⊢x:𝒯, thus Γ=∅ and 𝒮?=𝒮=𝒯. We let Φt⁢{x:=v}:=Φv and we are done. Moreover, 𝚜𝚣⁢(Φt⁢{x:=v})=𝚜𝚣⁢(Φv)=|𝒯|+𝚜𝚣⁢(Φv)−|𝒯|=𝚜𝚣⁢(Φt)+𝚜𝚣⁢(Φv)−|𝒮?|. ◀

The condition x∉𝖿𝗏⁢(t) in the lemma above is necessary, since the statement would not hold otherwise. As a counterexample, take v=z, Δ=z:𝕥, and t=y with y≠x.

▶ Remark 19.

If Φ⊳𝒰Γ⊢v:𝕥, then 𝚜𝚣⁢(Φ)=0.

Lemma 20 (Weighted Subject Reduction).

Let Φ⊳𝒰Γ⊢t:𝒯 and t→vscnet′. Then, there exists a derivation Φ′ such that Φ′⊳𝒰Γ⊢t′:𝒯 and moreover 𝚜𝚣⁢(Φ)>𝚜𝚣⁢(Φ′).

Proof.

By induction on t→vscnet′. We only show the base case t→𝗌𝗏𝗇𝖾t′. Let t=u⁢[x\v⁢𝙻]→𝗌𝗏𝗇𝖾u⁢{x:=v}⁢[x\v]⁢𝙻=t′, with x∈𝖿𝗏⁢(u). We proceed by induction on 𝙻.

  • ■

    𝙻=◇. Then, Φ has the form:

    where Γ=Γ1+Γ2. Notice that 𝒮?=𝒮?+⊥. Thus, let 𝒮1?=𝒮? and 𝒮2?=⊥. We separate in cases depending on whether 𝒮=𝕤 or 𝒮=ℳ, showing only the former. Hence 𝒮=𝕤, and by Lemma 17 there exist 𝒮1=𝕤 and 𝒮2=𝕤 such that 𝒮=𝕤=𝕤+𝕤=𝒮1+𝒮2 (by idempotency of the union of constant types), and 𝒮?≪𝕤 and ⊥≪𝕤. Recall that |𝕤|=|⊥|=0 by definition, so in particular |𝒮?|=|𝒮1?|=0.

    Applying Lemma 16, we obtain Φv1⊳Γ21⊢v:𝕤 and Φv2⊳Γ22⊢v:𝕤 with Γ2=Γ21+Γ22 and 𝚜𝚣⁢(Φv1)+𝚜𝚣⁢(Φv2)=𝚜𝚣⁢(Φv)=0 by Remark 19. We can apply Lemma 18 on Φu and Φv1, yielding Φu⁢{x:=v}⊳Γ1+Γ21⊢u⁢{x:=v}:𝒯 and 𝚜𝚣⁢(Φu⁢{x:=v})=𝚜𝚣⁢(Φu)+𝚜𝚣⁢(Φv1)−|𝒮1?|=𝚜𝚣⁢(Φu). Thus, we conclude building Φ′:

    And 𝚜𝚣⁢(Φ)=1+𝚜𝚣⁢(Φu)+𝚜𝚣⁢(Φv)=1+𝚜𝚣⁢(Φu)>𝚜𝚣⁢(Φu)=𝚜𝚣⁢(Φu⁢{x:=v})=𝚜𝚣⁢(Φu⁢{x:=v})+𝚜𝚣⁢(Φv2)=𝚜𝚣⁢(Φ′).

  • ■

    𝙻=𝙻′⁢[y\s]. Then, Φ has the form:

    where Γ=Γ′+Δ1+Δ2. Moreover, we can assume y∉𝖿𝗏⁢(u) by α-conversion.

    We now build the following derivation Ψ:

    Moreover, u⁢[x\v⁢𝙻′]→𝗌𝗏𝗇𝖾u⁢{x:=v}⁢[x\v]⁢𝙻′, since x∈𝖿𝗏⁢(u). Then, we can apply the i.h., yielding Ψ′ such that Ψ′⊳Γ′+(Δ1;y:ℛ?)⊢u{x:=v}[x\v]𝙻′:𝒯 and moreover, 𝚜𝚣⁢(Ψ)>𝚜𝚣⁢(Ψ′). Then, we build Φ′ as follows:

    Note that we can assume y∉𝖽𝗈𝗆⁢(Γ′) by α-conversion and (Relevance)..

    To compare the sizes of both Φ and Φ′, we consider two cases, depending on whether y∈𝖿𝗏⁢(u⁢{x:=v}⁢[x\v]⁢𝙻′) or not. Note that x∈𝖿𝗏⁢(u) by hypothesis.

    • –

      If y∉𝖿𝗏⁢(u⁢{x:=v}⁢[x\v]⁢𝙻′), then in particular y∉𝖿𝗏⁢(v⁢𝙻′). Thus, we have 𝚜𝚣⁢(Φ)=1+𝚜𝚣⁢(Φu)+𝚜𝚣⁢(Φv⁢𝙻′)+𝚜𝚣⁢(Φs)=𝚜𝚣⁢(Ψ)+𝚜𝚣⁢(Φs)>i.h.𝚜𝚣⁢(Ψ′)+𝚜𝚣⁢(Φs)=𝚜𝚣⁢(Φ′).

    • –

      Otherwise, y∈𝖿𝗏⁢(u⁢{x:=v}⁢[x\v]⁢𝙻′), and recall that y∉𝖿𝗏⁢(u) by α-conversion, so that y∈𝖿𝗏⁢(v⁢𝙻′). Therefore, 𝚜𝚣⁢(Φ)=1+𝚜𝚣⁢(Φu)+1+𝚜𝚣⁢(Φv⁢𝙻′)+𝚜𝚣⁢(Φs)=1+𝚜𝚣⁢(Ψ)+𝚜𝚣⁢(Φs)>i.h.1+𝚜𝚣⁢(Ψ′)+𝚜𝚣⁢(Φs)=𝚜𝚣⁢(Φ′).

◀

We now prove the completeness of system 𝒰 with respect to vscne, which states that vscne-termination implies 𝒰-typability. This result follows well-understood techniques, requiring a subject expansion property based on an anti-substitution lemma.

Lemma 21 (Anti-Substitution).

Let Φt⁢{x:=v}⊳𝒰Γ⊢t⁢{x:=v}:𝒯, with x∈𝖿𝗏⁢(t). Then, there exist typing derivations Φt and Φv, typing contexts Γt and Δ, an optional type 𝒮?, and a type 𝒮 satisfying:

  1. 1.

    Φt⊳𝒰Γt;x:𝒮?⊢t:𝒯

  2. 2.

    Φv⊳𝒰Δ⊢v:𝒮

  3. 3.

    Γ=Γt+Δ and 𝒮?≪𝒮

Moreover, 𝚜𝚣⁢(Φt⁢{x:=v})=𝚜𝚣⁢(Φt)+𝚜𝚣⁢(Φv)−|𝒮?|.

Proof.

By structural induction on t. We only show the case when t is a variable. The inductive cases follow easily from the i.h. and Lemma 16.

When t is a variable, then necessarily t=x, as x∈𝖿𝗏⁢(t) by hypothesis. Then, t⁢{x:=v}=v. We let Φv:=Φt⁢{x:=v}, and we yield Φt⊳x:𝒯⊢x:𝒯 by rule var, so that Γt:=∅, Δ:=Γ, and 𝒮?=𝒮=𝒯. Moreover, 𝚜𝚣⁢(Φt⁢{x:=v})=𝚜𝚣⁢(Φv)=|𝒮|+𝚜𝚣⁢(Φv)−|𝒮|=𝚜𝚣⁢(Φt)+𝚜𝚣⁢(Φv)−|𝒮?|. ◀

The condition x∉𝖿𝗏⁢(t) from the previous lemma is necessary, since otherwise, the statement does not hold. As a counterexample, it is sufficient to take t=y with y≠x and v=z so that t⁢{x:=z}=y and the derivation Φt⁢{x:=z}⊳y:𝒯⊢y:𝒯.

Lemma 22 (Weighted Subject Expansion).

Let t→vscnet′ and Φ′⊳𝒰Γ⊢t′:𝒯. Then, there exists Φ such that Φ⊳𝒰Γ⊢t:𝒯, with 𝚜𝚣⁢(Φ)>𝚜𝚣⁢(Φ′).

Proof.

By induction on t→vscnet′ where, in particular, Lemma 21 is used in the base case t=u⁢[x\v⁢𝙻]→𝗌𝗏u⁢{x:=v}⁢[x\v]⁢𝙻=t′. ◀

To prove completeness of system 𝒰 with respect to vscne evaluation, we first establish a lemma showing that normal forms are 𝒰-typable. We start by defining a grammar of terms and then showing that this grammar characterises the set of vscne-normal forms.

𝚟𝚛::=x⁢∣𝚟𝚛⁢[x\𝚗𝚎]∣⁢𝚟𝚛⁢[x\𝚗𝚘]⁢(x∉𝖿𝗏⁢(𝚟𝚛))𝚗𝚎::=𝚟𝚛⁢𝚗𝚘⁢∣𝚗𝚎⁢𝚗𝚘∣⁢𝚗𝚎⁢[x\𝚗𝚎]∣𝚗𝚎⁢[x\𝚗𝚘]⁢(x∉𝖿𝗏⁢(𝚗𝚎))𝚊𝚋::=λ⁢x.t⁢∣𝚊𝚋⁢[x\𝚗𝚎]∣⁢𝚊𝚋⁢[x\𝚗𝚘]⁢(x∉𝖿𝗏⁢(𝚊𝚋))𝚗𝚘::=𝚟𝚛⁢∣𝚗𝚎∣⁢𝚊𝚋

We define three predicates 𝖺𝖻𝗌⁢(_), 𝖺𝗉𝗉⁢(_), and 𝗏𝖺𝗋⁢(_) we will use for the characterisation of vscne-normal forms. For any term t, the predicate 𝖺𝖻𝗌⁢(t) holds if and only t=(λx.u)𝙻 for some variable x, some term u and some substitution context 𝙻; the predicate 𝖺𝗉𝗉⁢(t) holds if and only t=(u⁢s)⁢𝙻 for some terms u,s and some substitution context 𝙻; and the predicate 𝗏𝖺𝗋⁢(t) holds if and only t=x⁢𝙻 for some variable x and some substitution context 𝙻.

Proposition 23 (Characterisation of vscne-Normal Forms).

Let t be a term. Then, t∈𝚗𝚘 if and only if t is vscne-irreducible.

Proof.

The proof is by simultaneous induction on the following statements:

  1. 1.

    t∈𝚟𝚛 if and only if t is vscne-irreducible and 𝗏𝖺𝗋⁢(t)

  2. 2.

    t∈𝚗𝚎 if and only if t is vscne-irreducible and 𝖺𝗉𝗉⁢(t)

  3. 3.

    t∈𝚊𝚋 if and only if t is vscne-irreducible and 𝖺𝖻𝗌⁢(t)

  4. 4.

    t∈𝚗𝚘 if and only if t is vscne-irreducible

◀

Lemma 24 (Normal Forms in vscne are 𝒰-Typable).

Let t be a vscne-normal form. Then, t is 𝒰-typable with a constant type 𝕥. More specifically, there exist Φ, Γ, and 𝕥 such that Φ⊳𝒰Γ⊢t:𝕥, where Γ⁢(x)=𝕤 for all x∈𝖽𝗈𝗆⁢(Γ).

Proof.

The proof is by simultaneous induction on the following statements:

  1. 1.

    If t∈𝚟𝚛, then there are Φ and Γ such that Φ⊳𝒰Γ⊢t:𝕤, and Γ⁢(y)=𝕤 for all y∈𝖽𝗈𝗆⁢(Γ).

  2. 2.

    If t∈𝚗𝚎, then there are Φ and Γ such that Φ⊳𝒰Γ⊢t:𝕤, and Γ⁢(y)=𝕤 for all y∈𝖽𝗈𝗆⁢(Γ).

  3. 3.

    If t∈𝚊𝚋, then there are Φ and Γ such that Φ⊳𝒰Γ⊢t:[], and Γ⁢(y)=𝕤 for all y∈𝖽𝗈𝗆⁢(Γ).

  4. 4.

    If t∈𝚗𝚘, then there are Φ, Γ, and 𝕥 such that Φ⊳𝒰Γ⊢t:𝕥, and Γ⁢(y)=𝕤 for all y∈𝖽𝗈𝗆⁢(Γ).

◀

We now state the result of the characterisation of vscne-termination via 𝒰-typability:

See 3

Proof.

The only if direction holds by Lemma 20, while the if direction follows from Lemmas 24 and 22. ◀

Appendix B Proofs of Section 5

In this subsection, we detail the equivalence 𝟑⇔𝟐 in the proof of Corollary 15.

The Type System 𝓥.

Consider a set of base types α. The grammar of types in system 𝒱 is given by:

(Types)σ,τ::=α⁢∣ℳ∣⁢ℳ→σ(Multi-Types)ℳ,𝒩::=[σi]i∈Iwhere I is a finite set

The typing rules of system 𝒱 are:

A term t is 𝒱-typable if there is a derivation in 𝒱 for typing t, written Φ⊳𝒱Γ⊢t:σ.

We measure typing derivations in system 𝒱 using the 𝚜𝚣⁢(_) function, which is defined following the same intuitions we used for the homonym function in Appendix A. Specifically:

We start addressing the soundness of system 𝒱 with respect to vscne, which states that 𝒱-typability implies vscne-termination. As with the results for system 𝒰 in Appendix A, the soundness result requires a subject reduction property based on a substitution lemma.

▶ Remark 25.

For every value v there exists a derivation Φ⊳𝒱∅⊢v:[] such that 𝚜𝚣⁢(Φ)=0.

Lemma 26 (Substitution).

Let Φt⊳𝒱Γ;x:ℳ⊢t:σ and Φv⊳𝒱Δ⊢v:ℳ. Then, there exists a typing derivation Φt⁢{x:=v} such that Φt⁢{x:=v}⊳𝒱Γ+Δ⊢t⁢{x:=v}:σ and moreover 𝚜𝚣⁢(Φt⁢{x:=v})=𝚜𝚣⁢(Φt)+𝚜𝚣⁢(Φv)−|ℳ|.

Proof.

See [20, Lemma 4.18]. ◀

Lemma 27 (Weighted Subject Reduction).

Let Φ⊳𝒱Γ⊢t:σ and t→vscnet′. Then, there exists a derivation Φ′ such that Φ′⊳𝒱Γ⊢t′:σ and moreover 𝚜𝚣⁢(Φ)>𝚜𝚣⁢(Φ′).

Proof.

Using Lemma 26, the proof is analogous to the proof of Lemma 20 in Appendix A. ◀

We now prove the completeness of system 𝒱 with respect to vscne, which states that vscne-termination implies 𝒱-typability. As with the results for system 𝒰 in Appendix A, we require to state a subject expansion property based on an anti-substitution lemma.

Lemma 28 (Anti-Substitution).

Let Φt⁢{x:=v}⊳𝒱Γ⊢t⁢{x:=v}:σ. Then, there exist typing derivations Φt and Φv, typing contexts Γt and Δ, and a type 𝒮 satisfying:

  1. 1.

    Φt⊳𝒱Γt;x:ℳ⊢t:σ

  2. 2.

    Φv⊳𝒱Δ⊢v:ℳ

  3. 3.

    Γ=Γt+Δ

Moreover, 𝚜𝚣⁢(Φt⁢{x:=v})=𝚜𝚣⁢(Φt)+𝚜𝚣⁢(Φv)−|ℳ|.

Proof.

See [20, Lemma 4.18]. ◀

Lemma 29 (Weighted Subject Expansion).

Let t→vscnet′ and Φ′⊳𝒱Γ⊢t′:𝒯. Then, there exists Φ such that Φ⊳𝒱Γ⊢t:𝒯, with 𝚜𝚣⁢(Φ)>𝚜𝚣⁢(Φ′).

Proof.

By induction on t→vscnet′ where, in particular, Lemma 28 is used in the base case t=u⁢[x\v⁢𝙻]→𝗌𝗏u⁢{x:=v}⁢[x\v]⁢𝙻=t′. ◀

Lemma 30 (Normal Forms in vscne are 𝒱-Typable).

Let t be a vscne-normal form. Then, t is 𝒱-typable.

Proof.

The proof proceeds by simultaneous induction on the following statements:

  1. 1.

    If t∈𝚟𝚛, then for every multi-type ℳ there exist Φ and Γ such that Φ⊳𝒱Γ⊢t:ℳ.

  2. 2.

    If t∈𝚗𝚎, then for every type σ there exist Φ and Γ such that Φ⊳𝒱Γ⊢t:σ.

  3. 3.

    If t∈𝚊𝚋, then there exist Φ and Γ such that Φ⊳𝒱Γ⊢t:[].

  4. 4.

    If t∈𝚗𝚘, then there exist Φ, Γ, and ℳ such that Φ⊳𝒱Γ⊢t:ℳ.

◀

We now state the result of the characterisation of vscne-termination via 𝒱-typability:

Theorem 31.

Let t be a term. Then, t is vscne-terminating if and only if t is 𝒱-typable.

Proof.

The only if (resp. if) direction follows from Lemma 27 (resp. from Lemmas 30 and 29). ◀