Useful Call-by-Value: A Semantic Interpretation via Quantitative Types
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 modelsFunding:
Mariana Milicich: ††margin:Copyright and License:
2012 ACM Subject Classification:
Theory of computation Lambda calculus ; Theory of computation Type theory ; Theory of computation Operational semanticsFunding:
This work was supported by the European Union through the MSCA SE project QCOMICAL (Grant Agreement ID: 101182520).Editors:
Stefano Guerrini and Barbara KönigSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
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 to be typed with if 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 terminates in a given evaluation strategy if and only if 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 can be represented as the set . More recent works have adopted a non-idempotent intersection type constructor [30, 22, 25]. In this setting, an intersection can be represented as the multiset . 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 , 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 .
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 may be used in the typing judgement to capture the fact that evaluates in exactly 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 with counter , the program evaluates to normal form in exactly 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 vsc, which enjoys two properties: (1) termination in vsc is equivalent to termination in vsc, and (2) termination in vsc 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 vsc. 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 vsc (Theorem 3) and useful CBV (Corollary 14). Termination in vsc is equivalent to typability in system , which is in turn equivalent to termination in useful CBV. This ensures in particular that vsc 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 is tightly typable with counters and in system if and only if terminates in useful CBV evaluation in exactly function application steps and 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 vsc.
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 for the composition of -steps of . A term is said to be -irreducible, or in -normal form, written , if there is no such that . A term is said to be -weakly terminating (resp. -terminating) if there exists some -normal form such that (resp. there is no infinite -sequence starting at ). A term is -diamond (or enjoys the -diamond property) if and , with , imply there is such that and . A term is -confluent if and imply there is such that and . 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 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 (), the syntax of the vsc is specified by:
describing the sets of terms and values, respectively. We also use the following notions of substitution contexts and weak contexts:
The set of terms includes variables, abstractions, applications, and closures , representing an explicit substitution (ES) on a term . Some recurring terms are the identity function and the operator .
Free and bound occurrences of variables are defined as usual, where free occurrences of in are bound in . Terms are considered up to -renaming of bound variables. Substitution contexts are lists of ESs, and we write for the replacement of the hole in by , which may capture the free variables of . For example, if and , then . We also consider a meta-level operation which substitutes all the free occurrences of by in . Thanks to -renaming, we can assume that this substitution operation is capture-free. The sets of free variables of a term () 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:
The -rule (“istant eta”) is a -like rule that applies an abstraction to an argument , creating an ES that binds to the argument . This rule acts at a distance, meaning an arbitrary list of ESs () may be in between the abstraction and its argument. For example, .
The -rule (“ubstitution of alues”) fires an ES when is bound to a value surrounded by a context . This performs the meta-level substitution of by , potentially producing copies of , while it extrudes the substitution context , which must remain shared. For example, results in the erasure of the value , while produces two copies of but keeps a single copy of . Note that a term like is in vsc-normal form because is not a value.
The notion of reachable variable of a term is sometimes relevant in vsc, due to the fact that reduction is closed by weak contexts. The set of reachable variables is defined as the set of free variables that do not appear inside an abstraction. Formally:
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, 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 (vsc) is given by the vsc syntax and the reduction is defined by the following rules, closed by arbitrary weak contexts:
The -rule is similar to the -rule but requires that the variable occurs free in . For example, reduces to in vsc but is already a vsc-normal form. We assume the -rule to be capture-free, due to -renaming ().
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 vsc. The main result of this section is Theorem 3, which characterises termination in vsc by system : a term is typable in system (or -typable) if and only if terminates in vsc. 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 vsc-termination, ucbv∙-termination, and -typability.
3.1 Defining System
We begin with some preliminary considerations. First, normal forms in vsc and ucbv∙ fall into three categories222See Appendix A for the vsc-normal forms and Section 4 for the ucbv∙-normal forms.. A normal form without ESs may be an abstraction , a variable , or a structure , where and each is recursively in normal form. Normal forms with ESs also fit these categories up to performing all ESs. Thus, for instance, is a structure because it can be understood as representing the term .
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 , where the cardinality 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 , 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 , 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:
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 , and denotes the empty typing environment, mapping each variable to .
The union of arrow multi-types, written , is a multiset of types defined as expected, where is the neutral element. The union of types, written , is the(associative) partial operation on types given by and (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 , we write for the environment mapping each variable to , where and (meaning ) 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, is identical to .
Type assumptions are denoted , meaning that the environment assigns to , 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 , 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 to denote a type derivation in system ending in the typing judgement . 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 can be understood as a multiplicative conjunction . 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 vsc (reduction does not proceed below abstractions). For example, the derivation 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 , we say that the leftmost application constructor in 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 and 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 and 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 , the subexpression is a structure of type . One would perhaps expect to be able to type the abstraction with type . But it is impossible to derive the judgement , because 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 , 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 .
We end this subsection with another example that will be revisited later in the paper.
Example 1.
If 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 , then .
Proof.
See [16, Lemma 7.1].
Note that does not always hold. For instance, but .
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 vsc-Termination).
Let be a term. Then, is -typable if and only if is vsc-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 vsc (cf. subsection 2.2). Additionally, LSC uses a linear substitution rule, which only allows the substitution of a single occurrence of a variable by a term whenever is bound to by an ES. More precisely, the linear substitution rule () of LSC allowing substitutions one occurrence at a time, is defined by the rewriting rule , where denotes an arbitrary evaluation context. Substitution is called linear precisely because it replaces variables one occurrence at a time, for example .
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, is a structure, as it unfolds to . Structures must remain shared in useful evaluation, as substituting them does not create a -redex. Thus, a term like 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 is useful because substituting by creates the -redex . A subtler example of a useful step is , where the substitution indirectly contributes to creating a -redex in the next step: . Such indirect steps are precisely those that are challenging to capture inductively. On the other hand, steps like , and and are not useful, as these substitutions do not contribute to create a -redex.
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, holds by the third rule, while holds by the fourth rule. Note that the fourth rule allows building “chains” such as .
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, holds by the second rule, by the third rule, and 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 , with being a variable and a value such that . 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 is applied in but not in . 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 , the subterms and 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:
For a concrete example in which esLS∙ and esR∙ overlap, consider:
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 is already a normal form for ucbv∙ with respect to , , because substituting by is not useful, as it does not create a -redex. However, if appears on the left of an application, as in , the substitution of by becomes useful, leading to the following reduction sequence:
Conversely, a useful step like may not be allowed if the term is located below a context such as ; in fact, note that cannot be reduced.
A term is -irreducible if there is no term such that . A term belongs to the set if is -irreducible.
An abstraction frame and a structure frame are said to verify the correctness invariant for , written , if and . This invariant is typically assumed in theorems and lemmas. Note that always holds, so for a top-level term , we set and .
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:
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 and , where , and , and . Then there exists such that and .
Some straightforward corollaries of the diamond property are, firstly, that a term is weakly terminating in top-level ucbv∙ if and only if 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 is tightly typable with counters if and only if evaluates in ucbv∙ to a normal form in exactly function application steps (i.e., -steps) and 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 , where and are natural numbers called counters. Under appropriate conditions, these counters correspond exactly to the number of -steps () and -steps () 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 , , and . Note that . 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, if and only if for some . 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 , we may need to track that is bound to an abstraction when applying the inductive hypothesis for the subterm . Specifically, we say that a typing environment is appropriate with respect to an abstraction frame , written if, for each , we have . In other words, must be or an arrow multi-type . For instance, holds, while 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 is tight for every variable . A typing judgement 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 is tight, where the counters indicate that evaluating requires no reduction steps, meaning is already in normal form. In contrast, the judgement is not tight, and the counters provide an upper bound on the number of steps required for evaluating .
Example 8.
Let . 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 and the one concluding in . 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 where and , with . Suppose moreover that if , then either or is a singleton, i.e., of the form . Then, there exists a derivation such that , where if , then and , and if , then and .
Proof.
See [16, Proposition 7.3].
We can now conclude with a quantitative version of soundness: a tight typing derivation of a term with counters guarantees a terminating ucbv∙ reduction sequence, with exactly -steps and -steps.
Theorem 10 (Quantitative Soundness of System ).
Let , and let . Then, there exists a -irreducible term such that reduces to . Moreover, if is tight, then , where and are respectively the number of and steps in the previous reduction sequence.
To illustrate this property, consider the tight derivation for in Example 8, where the counter in the conclusion of is . A reduction sequence from terminates in in exactly -steps and -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 in Example 8 is not tight, as is not tight, and the counters do not correspond to the number of steps needed to reach the normal form of 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 ; this is done by typing the reachable variables in with and those in with . More precisely, given , , and such that , the tight environment for under and is written and defined as the environment such that when , when , and otherwise. Tight environments allow us to type normal forms tightly.
Proposition 11 (Normal Forms are Tight Typable).
Let be a term in and . Then, there exists a tight type such that . Moreover, if , then , and if , then .
Proof.
See [16, Proposition 7.5].
Subject Expansion is analogous to (Subject Reduction). but applies in the reverse direction: given a typable term and a reduction step , the term is typable as well, with the same type and typing environment.
Proposition 12 (Subject Expansion).
Let hold, and suppose where and , with . Furthermore, assume that if , then either or is a singleton, i.e., of the form . Then, there exists a derivation such that , where if , then , and if , then .
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 with exactly -steps and -steps, there exists a tight derivation of with counters :
Theorem 13 (Quantitative Completeness of System ).
Let and consider a reduction sequence , where is -irreducible. Let , where and are respectively the numbers of and steps in the sequence. Then, there exists a tight environment and a tight type such that .
To illustrate this result, take the reduction sequence starting from and ending in (see Example 4). The length of this sequence is , with -step and -steps. Example 8 shows a tight environment and a tight type such that .
Theorems 10 and 13 state that a term is typable in system if and only if 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 is tightly typable with counters in system if and only if terminates in ucbv∙ after function application -steps and substitution -steps.
We can now conclude with the main contribution of this work.
Corollary 15.
Let be a term. The following statements are equivalent:
-
1.
is typable in system .
-
2.
terminates in vsc.
-
3.
terminates in vsc.
-
4.
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 is typable in system if and only if terminates in vsc [19, Theorem 5]. It can also be shown that system characterises termination in vsc (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 denotes the term obtained by replacing the hole in by . Given a reduction system , we define to be observationally equivalent to , written , if and only if for every context we have that -terminates if and only if -terminates. Then and are observationally equivalent if and only if for every , we have .
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 vsc. 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 is tightly typable with counters and in system if and only if terminates in ucbv∙ in exactly function application steps and 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 , and . We remark that .
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 , then a substitution of by takes place, hence we add 1 to the sum of the sizes of the derivations of both and .
We first address the soundness of system with respect to vsc, which states that -typability implies vsc-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 and be two types such that their union is well-defined. Then, the following are equivalent:
-
1.
-
2.
There exist typing derivations and typing contexts such that , and , and .
Moreover, .
Proof.
The proof corresponds to that of [16, Lemma E.3], and it is straightforward to prove that .
Lemma 17 (Type Splitting).
Let , be two optional types and be a type. Then is well-defined and if and only if there exist types and such that and for all .
Proof.
Both directions of the lemma follow by case analysis on and .
Lemma 18 (Substitution).
Let and , with and . Then, there exists a typing derivation such that and moreover .
Proof.
By induction on . We show only case var, as the inductive cases follow easily from the i.h. and Lemmas 16 and 17.
If ends with var, then , since by hypothesis. Then, and is of the form , thus and . We let and we are done. Moreover, .
The condition in the lemma above is necessary, since the statement would not hold otherwise. As a counterexample, take , , and with .
Remark 19.
If , then .
Lemma 20 (Weighted Subject Reduction).
Let and . Then, there exists a derivation such that and moreover .
Proof.
By induction on . We only show the base case . Let , with . We proceed by induction on .
-
. Then, has the form:
where . Notice that . Thus, let and . We separate in cases depending on whether or , showing only the former. Hence , and by Lemma 17 there exist and such that (by idempotency of the union of constant types), and and . Recall that by definition, so in particular .
Applying Lemma 16, we obtain and with and by Remark 19. We can apply Lemma 18 on and , yielding and . Thus, we conclude building :
And .
-
. Then, has the form:
where . Moreover, we can assume by -conversion.
We now build the following derivation :
Moreover, , since . Then, we can apply the i.h., yielding such that and moreover, . Then, we build as follows:
Note that we can assume by -conversion and (Relevance)..
To compare the sizes of both and , we consider two cases, depending on whether or not. Note that by hypothesis.
-
–
If , then in particular . Thus, we have .
-
–
Otherwise, , and recall that by -conversion, so that . Therefore, .
-
–
We now prove the completeness of system with respect to vsc, which states that vsc-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 , with . Then, there exist typing derivations and , typing contexts and , an optional type , and a type satisfying:
-
1.
-
2.
-
3.
and
Moreover, .
Proof.
By structural induction on . We only show the case when is a variable. The inductive cases follow easily from the i.h. and Lemma 16.
When is a variable, then necessarily , as by hypothesis. Then, . We let , and we yield by rule var, so that , , and . Moreover, .
The condition from the previous lemma is necessary, since otherwise, the statement does not hold. As a counterexample, it is sufficient to take with and so that and the derivation .
Lemma 22 (Weighted Subject Expansion).
Let and . Then, there exists such that , with .
Proof.
By induction on where, in particular, Lemma 21 is used in the base case .
To prove completeness of system with respect to vsc 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 vsc-normal forms.
We define three predicates , , and we will use for the characterisation of vsc-normal forms. For any term , the predicate holds if and only for some variable , some term and some substitution context ; the predicate holds if and only for some terms and some substitution context ; and the predicate holds if and only for some variable and some substitution context .
Proposition 23 (Characterisation of vsc-Normal Forms).
Let be a term. Then, if and only if is vsc-irreducible.
Proof.
The proof is by simultaneous induction on the following statements:
-
1.
if and only if is vsc-irreducible and
-
2.
if and only if is vsc-irreducible and
-
3.
if and only if is vsc-irreducible and
-
4.
if and only if is vsc-irreducible
Lemma 24 (Normal Forms in vsc are -Typable).
Let be a vsc-normal form. Then, is -typable with a constant type . More specifically, there exist , , and such that , where for all .
Proof.
The proof is by simultaneous induction on the following statements:
-
1.
If , then there are and such that , and for all .
-
2.
If , then there are and such that , and for all .
-
3.
If , then there are and such that , and for all .
-
4.
If , then there are , , and such that , and for all .
We now state the result of the characterisation of vsc-termination via -typability:
See 3
Proof.
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:
The typing rules of system are:
A term is -typable if there is a derivation in for typing , written .
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 vsc, which states that -typability implies vsc-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 there exists a derivation such that .
Lemma 26 (Substitution).
Let and . Then, there exists a typing derivation such that and moreover .
Proof.
See [20, Lemma 4.18].
Lemma 27 (Weighted Subject Reduction).
Let and . Then, there exists a derivation such that 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 vsc, which states that vsc-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 . Then, there exist typing derivations and , typing contexts and , and a type satisfying:
-
1.
-
2.
-
3.
Moreover, .
Proof.
See [20, Lemma 4.18].
Lemma 29 (Weighted Subject Expansion).
Let and . Then, there exists such that , with .
Proof.
By induction on where, in particular, Lemma 28 is used in the base case .
Lemma 30 (Normal Forms in vsc are -Typable).
Let be a vsc-normal form. Then, is -typable.
Proof.
The proof proceeds by simultaneous induction on the following statements:
-
1.
If , then for every multi-type there exist and such that .
-
2.
If , then for every type there exist and such that .
-
3.
If , then there exist and such that .
-
4.
If , then there exist , , and such that .
We now state the result of the characterisation of vsc-termination via -typability:
Theorem 31.
Let be a term. Then, is vsc-terminating if and only if is -typable.
