Towards a Semantic Measure of the Execution Time in Call-by-Value lambda-Calculus
Giulio Guerrieri (University of Bath, Department of Computer Science,, Bath, United Kingdom)

TL;DR
This paper explores a semantic approach to measure execution time in call-by-value lambda calculus using a linear logic-based model, revealing limitations and proposing future refinements for accurate timing analysis.
Contribution
It introduces a semantic framework for estimating execution time in call-by-value lambda calculus and highlights the challenges in transferring quantitative info from derivations to types.
Findings
Interpretation non-emptiness characterizes normalizability.
Type derivation size correlates with execution time.
Quantitative info does not naturally lift to types.
Abstract
We investigate the possibility of a semantic account of the execution time (i.e. the number of beta-steps leading to the normal form, if any) for the shuffling calculus, an extension of Plotkin's call-by-value lambda-calculus. For this purpose, we use a linear logic based denotational model that can be seen as a non-idempotent intersection type system: relational semantics. Our investigation is inspired by similar ones for linear logic proof-nets and untyped call-by-name lambda-calculus. We first prove a qualitative result: a (possibly open) term is normalizable for weak reduction (which does not reduce under abstractions) if and only if its interpretation is not empty. We then show that the size of type derivations can be used to measure the execution time. Finally, we show that, differently from the case of linear logic and call-by-name lambda-calculus, the quantitative information…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Towards a Semantic Measure of the Execution Time in Call-by-Value lambda-Calculus
Giulio Guerrieri University of Bath, Department of Computer Science, Bath, United Kingdom [email protected]
Abstract
We investigate the possibility of a semantic account of the execution time (i.e. the number of -steps leading to the normal form, if any) for the shuffling calculus, an extension of Plotkin’s call-by-value -calculus. For this purpose, we use a linear logic based denotational model that can be seen as a non-idempotent intersection type system: relational semantics. Our investigation is inspired by similar ones for linear logic proof-nets and untyped call-by-name -calculus. We first prove a qualitative result: a (possibly open) term is normalizable for weak reduction (which does not reduce under abstractions) if and only if its interpretation is not empty. We then show that the size of type derivations can be used to measure the execution time. Finally, we show that, differently from the case of linear logic and call-by-name -calculus, the quantitative information enclosed in type derivations does not lift to types (i.e. to the interpretation of terms). To get a truly semantic measure of execution time in a call-by-value setting, we conjecture that a refinement of its syntax and operational semantics is needed.
1 Introduction
Type systems enforce properties of programs, such as termination or deadlock-freedom. The guarantee provided by most type systems for the -calculus is termination.
Intersection types have been introduced as a way of extending simple types for the -calculus to “finite polymorphism”, by adding a new type constructor and new typing rules governing it. Contrary to simple types, intersection types provide a sound and complete characterization of termination: not only typed programs terminate, but all terminating programs are typable as well (see [20, 21, 43, 37] where different intersection type systems characterize different notions of normalization). Intersection types are idempotent, that is, they verify the equation . This corresponds to an interpretation of a typed term as “ can be used both as data of type and as data of type ”.
More recently [25, 36, 39, 16, 17] (a survey can be found in [14]), non-idempotent variants of intersection types have been introduced: they are obtained by dropping the equation . In a non-idempotent setting, the meaning of the typed term is refined as “ can be used twice as data of type and once as data of type ”. This could give to programmers a way to keep control on the performance of their code and to count resource consumption. Finite multisets are the natural setting to interpret the associative, commutative and non-idempotent connective : if and are non-idempotent intersection types, the multiset represents the non-idempotent intersection type .
Non-idempotent intersection types have two main features, both enlightened by de Carvalho [16, 17]:
Bounds on the execution time: they go beyond simply qualitative characterisations of termination, as type derivations provide quantitative bounds on the execution time (i.e. on the number of -steps to reach the -normal form). Therefore, non-idempotent intersection types give intensional insights on programs, and seem to provide a tool to reason about complexity of programs. The approach is defining a measure for type derivations and showing that the measure gives (a bound to) the length of the evaluation of typed terms. 2. 2.
Linear logic interpretation: non-idempotent intersection types are deeply linked to linear logic () [26]. Relational semantics [27, 12] — the category of sets and relations endowed with the comonad of finite multisets — is a sort of “canonical” denotational model of ; the Kleisli category of the comonad is a CCC and then provides a denotational model of the ordinary (i.e. call-by-name) -calculus. Non-idempotent intersection types can be seen as a syntactic presentation of : the semantics of a term is the set of conclusions of all type derivations of .
These two facts together have a potential, fascinating consequence: denotational semantics may provide abstract tools for complexity analysis, that are theoretically solid, being grounded on .
Starting from [16, 17], research on relational semantics/non-idempotent intersection types has proliferated: various works in the literature explore their power in bounding the execution time or in characterizing normalization [18, 13, 11, 34, 10, 19, 41, 35, 14, 38, 4]. All these works study relational semantics/non-idempotent intersection types either in proof-nets (the graphical representation of proofs in ), or in some variant of ordinary (i.e. call-by-name) -calculus. In the second case, the construction of the relational model sketched above essentially relies on Girard’s call-by-name translation of intuitionistic logic into , which decomposes the intuitionistic arrow as .
Ehrhard [23] showed that the relational semantics of induces also a denotational model for the call-by-value -calculus111In call-by-value evaluation , function’s arguments are evaluated before being passed to the function, so that -redexes can fire only when their arguments are values, i.e. abstractions or variables. The idea is that only values can be erased or duplicated. Call-by-value evaluation is the most common parameter passing mechanism used by programming languages. that can still be viewed as a non-idempotent intersection type system.
The syntactic counterpart of this construction is Girard’s (“boring”) call-by-value translation of intuitionistic logic into [26], which decomposes the intuitionistic arrow as . Just few works have started the study of relational semantics/non-idempotent intersection types in a call-by-value setting [23, 22, 15, 24], and no one investigates their bounding power on the execution time in such a framework. Our paper aims to fill this gap and study the information enclosed in relational semantics/non-idempotent intersection types concerning the execution time in the call-by-value -calculus.
A difficulty arises immediately in the qualitative characterization of call-by-value normalization via the relational model. One would expect that the semantics of a term is non-empty if and only if is (strongly) normalizable for (some restriction of) the call-by-value evaluation , but it is impossible to get this result in Plotkin’s original call-by-value -calculus [42]. Indeed, the terms and below are -normal but their semantics in the relational model are empty:
[TABLE]
Actually, and should behave like the famous divergent term , since in they are observationally equivalent to with respect all closing contexts and have the same semantics as in all non-trivial denotational models of Plotkin’s .
The reason of this mismatching is that in there are stuck -redexes such as in Eq. (1), i.e. -redexes that -reduction will never fire because their argument is normal but not a value (nor will it ever become one). The real problem with stuck -redexes is that they may prevent the creation of other -redexes, providing “premature” -normal forms like and in Eq. (1). The issue affects termination and thus can impact on the study of observational equivalence and other operational properties in .
In a call-by-value setting, the issue of stuck -redexes and then of premature -normal forms arises only with open terms (in particular, when the reduction under abstractions is allowed, since it forces to deal with “locally open” terms). Even if to model functional programming languages with a call-by-value parameter passing, such as OCaml, it is usually enough to just consider closed terms and weak evaluation (i.e. not reducing under abstractions: function bodies are evaluated only when all parameters are supplied), the importance to consider open terms in a call-by-value setting can be found, for example, in partial evaluation (which evaluates a function when not all parameters are supplied, see [33]), in the theory of proof assistants such as Coq (in particular, for type checking in a system based on dependent types, see [28]), or to reason about (denotational or operational) equivalences of terms in that are congruences, or about other theoretical properties of such as separability or solvability [40, 46, 8, 15].
To overcome the issue of stuck -redexes, we study relational semantics/non-idempotent intersection types in the shuffling calculus , a conservative extension of Plotkin’s proposed in [15] and further studied in [29, 31, 5, 32]. It keeps the same term syntax as and adds to -reduction two commutation rules, and , which “shuffle” constructors in order to move stuck -redexes: they unblock -redexes that are hidden by the “hyper-sequential structure” of terms. These commutation rules (referred also as -reduction rules) are similar to Regnier’s -rules for the call-by-name -calculus [44, 45] and are inspired by the aforementioned translation of the -calculus into proof-nets.
Following the same approach used in [17] for the call-by-name -calculus and in [18] for proof-nets, we prove that in the shuffling calculus :
(qualitative result) relational semantics is adequate for , i.e. a possibly open term is normalizable for weak reduction (not reducing under ’s) if and only if its interpretation in relational semantics is not empty (Thm. 16); this result was already proven in [15] using different techniques; 2. 2.
(quantiative result) the size of type derivations can be used to measure the execution time, i.e. the number of -steps (and not -steps) to reach the normal form of the weak reduction (Prop. 21).
Finally, we show that, differently from the case of and call-by-name -calculus, we are not able to lift the quantitative information enclosed in type derivations to types (i.e. to the interpretation of terms) following the same technique used in [17, 18], as our Ex. 28 shows. In order to get a genuine semantic measure of execution time in a call-by-value setting, we conjecture that a refinement of its syntax and operational semantics is needed.
Even if our main goal has not yet been achieved, this investigation led to new interesting results:
all normalizing weak reduction sequences (if any) in from a given term have the same number of -steps (Cor. 22); this is not obvious, as we shall explain in Ex. 23; 2. 2.
terms whose weak reduction in ends in a value has an elegant semantic characterization (Prop. 18), and the number of -steps needed to reach their normal form can be computed in a simple way from a specific type derivation (Thm. 24). 3. 3.
all our qualitative and quantitative results for are still valid in Plotkin’s restricted to closed terms (which models functional programming languages), see Thm. 25, Cor. 26 and Thm. 27.
Proofs are omitted. They can be found in [30], the extended version of this paper.
1.1 Preliminaries and notations
The set of -terms is denoted by . We set and . Let .
- •
The reflexive-transitive closure of is denoted by . The -equivalence is the reflexive-transitive and symmetric closure of .
- •
Let be a term: is -normal if there is no term such that ; is -normalizable if there is a -normal term such that , and we then say that is a -normal form of ; is strongly -normalizable if there is no infinite sequence of terms such that and for all . Finally, is strongly normalizing if every is strongly -normalizable.
- •
is confluent if . From confluence it follows that: iff for some term ; and any -normalizable term has a unique -normal form.
2 The shuffling calculus
In this section we introduce the shuffling calculus , namely the call-by-value -calculus defined in [15] and further studied in [29, 31, 5, 32]: it adds two commutation rules — the - and -reductions — to Plotkin’s pure (i.e. without constants) call-by-value -calculus [42]. The syntax for terms of is the same as Plotkin’s and then the same as the ordinary (i.e. call-by-name) -calculus, see Fig. 1.
Clearly, . All terms are considered up to -conversion (i.e. renaming of bound variables). The set of free variables of a term is denoted by : is open if , closed otherwise. Given , denotes the term obtained by the capture-avoiding substitution of for each free occurrence of in the term . Note that values are closed under substitution: if then .
One-hole contexts are defined as usual, see Fig. 1. We use for the term obtained by the capture-allowing substitution of the term for the hole in the context . In Fig. 1 we define also a special kind of contexts, balanced contexts .
Reductions in the shuffling calculus are defined in Fig. 1 as follows: given a root-step rule , we define the -reduction (resp. -reduction ) as the closure of under contexts (resp. balanced contexts). The -reduction is non-deterministic and — because of balanced contexts — can reduce under abstractions, but it is “morally” weak: it reduces under a only when the is applied to an argument. Clearly, since can freely reduce under ’s.
The root-steps used in the shuffling calculus are (the reduction rule in Plotkin’s ), the commutation rules and , and and . The side conditions for and in Fig. 1 can be always fulfilled by -renaming. For any , if then is a -redex and is its -contractum. A term of the shape is a -redex. Clearly, any -redex is a -redex but the converse does not hold: is a -redex but not a -redex. Redexes of different kind may overlap: for instance, the term is a -redex and contains the -redex ; the term is a -redex and contains the -redex , which contains in turn the -redex .
From definitions in Fig. 1 it follows that and , as well as and . The shuffling (resp. balanced shuffling) calculus (resp. ) is the set of terms endowed with the reduction (resp. ). The set endowed with the reduction is Plotkin’s pure call-by-value -calculus [42], a sub-calculus of .
Proposition 1** (Basic properties of reductions, [42, 15]).**
The - and -reductions are confluent and strongly normalizing. The -, -, - and -reductions are confluent.
Example 2**.**
Recall the terms and in Eq. (1): and are the only possible -reduction paths from and respectively: and are not -normalizable and . But and are -normal ( is a stuck -redex) and different, so by confluence of (Prop. 1). Thus, .
Example 2 shows how -reduction shuffles constructors and moves stuck -redex in order to unblock -redexes which are hidden by the “hyper-sequential structure” of terms, avoiding “premature” normal forms. An alternative approach to circumvent the issue of stuck -redexes is given by , the call-by-value -calculus with explicit substitutions introduced in [8], where hidden -redexes are reduced using rules acting at a distance. In [5] it has been shown that and can be embedded in each other preserving termination and divergence. Interestingly, both calculi are inspired by an analysis of Girard’s “boring” call-by-value translation of -terms into linear logic proof-nets [26, 2] according to the linear recursive type , or equivalently . In this translation, -reduction corresponds to cut-elimination, more precisely -steps (resp. -steps) correspond to exponential (resp. multiplicative) cut-elimination steps; -reduction corresponds to cut-elimination at depth [math].
Consider the two subsets of terms defined by mutual induction (notice that ):
[TABLE]
Any is neither a value nor a -redex, but an open applicative term with a free “head variable”.
Proposition 3** (Syntactic characterization on -normal forms).**
Let be a term:
- •
* is -normal iff ;*
- •
* is -normal and is neither a value nor a -redex iff .*
Stuck -redexes correspond to -normal forms of the shape . As a consequence of Prop. 3, the behaviour of closed terms with respect to -reduction (resp. -reduction) is quite simple: either they diverge or they -normalize (resp. -normalize) to a closed value. Indeed:
Corollary 4** (Syntactic characterization of closed - and -normal forms).**
Let be a closed term: is -normal iff is -normal iff is a value iff for some term with .
3 A non-idempotent intersection type system
We recall the non-idempotent intersection type system introduced by Ehrhard [23] (nothing but the call-by-value version of de Carvalho’s system [16, 17]). We use it to characterize the (strong) normalizable terms for the reduction . Types are positive or negative, defined by mutual induction as follows:
[TABLE]
where is a (possibly empty) finite multiset of negative types; in particular the empty multiset (obtained for ) is the only atomic (positive) type. A positive type has to be intended as a conjunction of negative types , for a commutative and associative conjunction connective that is not idempotent and whose neutral element is .
The derivation rules for the non-idempotent intersection type system are in Fig. 2. In this typing system, judgments have the shape where is a term, is a positive type and is an environment (i.e. a total function from variables to positive types whose domain is finite). The sum of environments is defined pointwise via multiset sum: . An environment such that with and for all is often written as . In particular, and (where ) are the same environment; and stands for the judgment where is the empty environment, i.e. (that is, for any variable ). Note that the sum of environments is commutative, associative and its neutral element is the empty environment: given an environment , one has iff . The notation means that is a derivation with conclusion the judgment . We write if is such that for some environment and positive type .
It is worth noticing that the type system in Fig. 2 is syntax oriented: for each type judgment there is a unique derivation rule whose conclusion matches the judgment .
The size of a type derivation is just the the number of rules in . Note that judgments play no role in the size of a derivation.
Example 5**.**
Let . The derivations (typing and with same type and same environment)
[TABLE]
are such that and . Note that and .
The following lemma (whose proof is quite technical) will play a crucial role to prove the substitution lemma (Lemma 7) and the subject reduction (Prop. 8) and expansion (Prop. 10).
Lemma 6** (Judgment decomposition for values).**
*Let
, be an environment, and be positive types (for some ). There is a derivation iff for all there are an environment and a derivation such that . Moreover, .*
The left-to-right direction of Lemma 6 means that, given , for every and every decomposition of the positive type into a multiset sum of positive types , there are environments such that is derivable for all .
Lemma 7** (Substitution).**
*Let
and . If and , then there exists such that .*
We can now prove the subject reduction, with a quantitative flavour about the size of type derivations in order to extract information about the execution time.
Proposition 8** (Quantitative balanced subject reduction).**
*Let
and .*
Shrinkage under -step:* If then and there exists a derivation with conclusion such that .* 2. 2.
Size invariance under -step:* If then and there exists a derivation with conclusion such that .*
In Prop. 8, the fact that does not reduce under ’s is crucial to get the quantitative information, otherwise one can have a term such that every derivation is such that (and then there is no derivation with conclusion such that ): this is the case, for example, for . This shows that the quantitative study for evaluation reducing under ’s is subtler.
In order to prove the quantitative subject expansion (Prop. 10), we first need the following technical lemma stating the commutation of abstraction with abstraction and application.
Lemma 9** (Abstraction commutation).**
Abstraction vs. abstraction:* Let . If and , then there is such that .* 2. 2.
Application vs. abstraction:* If then there exists a derivation such that .*
Proposition 10** (Quantitative balanced subject expansion).**
Let and .
Enlargement under anti--step:* If then there is with .* 2. 2.
Size invariance under anti--step:* If then and there is with .*
Actually, subject reduction and expansion hold for the whole -reduction , not only for the balanced -reduction . The drawback for is that the quantitative information about the size of the derivation is lost in the case of a -step, see the comments just after Prop. 8 and Lemma 12.
Lemma 11** (Subject reduction).**
Let and .
Shrinkage under -step:* If then there is with .* 2. 2.
Size invariance under -step:* If then there is such that .*
Lemma 12** (Subject expansion).**
Let and .
Enlargement under anti--step:* If then there is with .* 2. 2.
Size invariance under anti--step:* If then there is such that .*
In Lemmas 11.1 and 12.1 it is impossible to estimate more precisely the relationship between and . Indeed, Ex. 5 has shown that there are and such that and (where ). So, given , consider the derivations and below:
[TABLE]
Clearly, (but ) and the (resp. ) is the only derivation typing (resp. ) with the same type and environment as (resp. ). One has and , thus the difference of size of the derivations and can be arbitrarely large (since ); in particular , so for the size of derivations does not even strictly decrease.
4 Relational semantics: qualitative results
Lemmas 11 and 12 have an important consequence: the non-idempotent intersection type system of Fig. 2 defines a denotational model for the shuffling calculus (Thm. 14 below).
Definition 13** (Suitable list of variables for a term, semantics of a term).**
Let and let be pairwise distinct variables, for some .
If , then we say that the list is suitable for .
If is suitable for , the (relational) semantics, or interpretation, of for is
[TABLE]
Essentially, the semantics of a term for a suitable list of variables is the set of judgments for and that can be derived in the non-idempotent intersection type system of Fig. 2.
If we identify the negative type with the pair and if we set where:
[TABLE]
then, for any and any suitable list for , one has ; in particular, if is closed and , then (up to an obvious isomorphism). Note that : [23, 15] proved that the latter identity is enough to have a denotational model for . We can also prove it explicitly using Lemmas 11 and 12.
Theorem 14** (Invariance under -equivalence).**
Let , let and let be a suitable list of variables for and . If then .
An interesting property of relational semantics is that all -normal forms have a non-empty interpretation (Lemma 15). To prove that we use the syntactic characterization of -normal forms (Prop. 3). Note that a stronger statement (Lemma 15.1) is required for -normal forms belonging to , in order to handle the case where the -normal form is a -redex.
Lemma 15** (Semantics and typability of -normal forms).**
Let be a term, let and let be a list of variables suitable for .
If then for every positive type there exist positive types and a derivation . 2. 2.
If then there are positive types and a derivation . 3. 3.
If is -normal then .
A consequence of Prop. 8 (and Thm. 14 and Lemma 15) is a qualitative result: a semantic and logical (if we consider our non-idempotent type system as a logical framework) characterization of (strong) -normalizable terms (Thm. 16). In this theorem, the main equivalences are between Points 1, 3 and 5, already proven in [15] using different techniques. Points 2 and 4 can be seen as “intermediate stages” in the proof of the main equivalences, which are informative enough to deserve to be explicitely stated.
Theorem 16** (Semantic and logical characterization of -normalization).**
Let and let be a suitable list of variables for . The following are equivalent:
Normalizability:* is -normalizable;* 2. 2.
Completeness:* for some -normal ;* 3. 3.
Adequacy:* ;* 4. 4.
Derivability:* there is a derivation for some positive types ;* 5. 5.
Strong normalizabilty:* is strongly -normalizable.*
As implication (5)(1) is trivial, the proof of Thm. 16 follows the structure (1)(2)(3)(4)(5): essentially, non-idempotent intersection types are used to prove that normalization implies strong normalization for -reduction. Equivalence (5)(1) means that normalization and strong normalization are equivalent for -reduction, thus in studying the termination of -reduction no intricacy arises from its non-determinism. Although does not evaluate under ’s, this result is not trivial because does not enjoy any form of (quasi-)diamond property, as we show in Ex. 23 below. Equivalence (1)(2) says that -reduction is complete with respect to -equivalence to get -normal forms; in particular, this entails that every -normalizable term is -normalizable. Equivalence (1)(2) is the analogue of a well-known theorem [9, Thm. 8.3.11] for ordinary (i.e. call-by-name) -calculus relating head -reduction and -equivalence: this corroborates the idea that -reduction is the “head reduction” in a call-by-value setting, despite its non-determinism. The equivalence (3)(4) holds by definition of relational semantics.
Implication (1)(3) (or equivalently (1)(4), i.e. “normalizable typable”) does not hold in Plotkin’s : indeed, the (open) terms and in Eq. (1) (see also Ex. 2) are -normal (because of a stuck -redex) but . Equivalences such as the ones in Thm. 16 hold in a call-by-value setting provided that -reduction is extended, e.g. by adding -reduction. In [5], is proved to be termination equivalent to other extensions of (in the framework Open Call-by-Value, where evaluation is call-by-value and weak, on possibly open terms) such as the fireball calculus [46, 28, 3] and the value substitution calculus [8], so Thm. 16 is a general result characterizing termination in those calculi as well.
Lemma 17** (Uniqueness of the derivation with empty types; Semantic and logical characterization of values).**
Let be -normal.
If and , then , , and . More precisely, consists of a rule if is a variable, otherwise is an abstraction and consists of a 0-ary rule . 2. 2.
Given a list of variables suitable for , the following are equivalent:
- (a)
* is a value;* 2. (b)
* ;* 3. (c)
there exists ; 4. (d)
there exists such that .
Qualitatively, Lemma 17 allows us to refine the semantic and logical characterization given by Thm. 16 for a specific class of terms: the valuable ones, i.e. the terms that -normalize to a value. Valuable terms are all and only the terms whose semantics contains a specific element: the point with only empty types.
Proposition 18** (Logical and semantic characterization of valuability).**
Let be a term and be a suitable list of variables for . The following are equivalent:
Valuability:* is -normalizable and the -normal form of is a value;* 2. 2.
Empty point in the semantics:* ;* 3. 3.
Derivability with empty types:* there exists a derivation .*
5 The quantitative side of type derivations
By the quantitative subject reduction (Prop. 8), the size of any derivation typing a (-normalizable) term is an upper bound on the number of -steps in any -normalizing reduction sequence from , since the size of a type derivation decreases by after each -step, and does not change after each -step.
Corollary 19** (Upper bound on the number of -steps).**
Let be a -normalizable term and be its -normal form. For any reduction sequence and any , .
In order to extract from a type derivation the exact number of -steps to reach the -normal form, we have to take into account also the size of derivations of -normal forms. Indeed, by Lemma 17.2, -normal forms that are not values admit only derivations with sizes greater than [math]. The sizes of type derivations of a -normal form are related to a special kind of size of that we now define.
The balanced size of a term , denoted by , is defined by induction on as follows ():
[TABLE]
So, the balanced size of a term is the number of applications occurring in under a balanced context, i.e. the number of pairs such that for some balanced context . For instance, and . The following lemma can be seen as a quantitative version of Lemma 15.
Lemma 20** (Relationship between sizes of normal forms and derivations).**
Let .
If is -normal then . 2. 2.
If is a value then .
Thus, the balanced size of a -normal form equals the minimal size of the type derivation of .
Proposition 21** (Exact number of -steps).**
Let be a -normalizable term and be its -normal form. For every reduction sequence and every and such that and , one has
[TABLE]
If moreover is a value, then .
In particular, Eq. (2) implies that for any reduction sequence and any and such that , one has , since .
Prop. 21 could seem slightly disappointinig: it allows us to know the exact number of -steps of a -normalizing reduction sequence from only if we already know the -normal form of (or the minimal derivation of ), which essentially means that we have to perform the reduction sequence in order to know the exact number of its -steps. However, Prop. 21 says also that this limitation is circumvented in the case -reduces to a value. Moreover, a notable and immediate consequence of Prop. 21 is:
Corollary 22** (Same number of -steps).**
Let be a -normalizable term and be its -normal form. For all reduction sequences and , one has .
Even if -reduction is weak, in the sense that it does not reduce under ’s, Cor. 22 is not obvious at all, since the rewriting theory of -reduction is not quite elegant, in particular it does not enjoy any form of (quasi-)diamond property because of -reduction, as shown by the following example.
Example 23**.**
Let : one has and the only way to join this critical pair is by performing one -step from and two -steps from , so that . Since each -step can create a new -redex in a balanced context (as shown in Ex. 2), a priori there is no evidence that Cor. 22 should hold.
Cor. 22 allows us to define the following function
[TABLE]
In other words, in we can univocally associate with every term the number of -steps needed to reach its -normal form, if any (the infinity is associated with non--normalizable terms). The characterization of -normalization given in Thm. 16 allows us to determine through semantic or logical means if the value of is a finite number or not.
Quantitatively, via Lemma 17 we can simplify the way to compute the number of -steps to reach the -normal form of a valuable (i.e. that reduces to a value) term , using only a specific type derivation of .
Theorem 24** (Exact number of -steps for valuables).**
*If then for . *
Prop. 18 and Thm. 24 provide a procedure to determine if a term -normalizes to a value and, in case, how many -steps are needed to reach its -normal form (this number does not depend on the reduction strategy according to Cor. 22), considering only the term and without performing any -step:
check if there is a derivation with empty types, i.e. ; 2. 2.
if it is so (i.e. if -normalize to a value, according to Prop. 18), compute the size .
Remind that, according to Cor. 4, any closed term either is not -normalizable, or it -normalizes to a (closed) value. So, this procedure completely determines (qualitatively and quantitatively) the behavior of closed terms with respect to -reduction (and to -reduction, as we will see in Sect. 6).
6 Conclusions
Back to Plotkin’s .
The shuffling calculus can be used to prove some properties of Plotkin’s call-by-value -calculus (whose only reduction rule is ) restricted to closed terms. This is an example of how the study of some properties of a framework (in this case, ) can be naturally done in a more general framework (in this case, ). It is worth noting that with only closed terms is an interesting fragment: it represents the core of many functional programming languages, such as OCaml.
The starting point is Cor. 4, which says that, in the closed setting with weak reduction, normal forms for and coincide: they are all and only closed values. We can then reformulate Thm. 16 and Prop. 18 as a semantic and logical characterization of -normalization in Plotkin’s restricted to closed terms.
Theorem 25** (Semantic and logical characterization of -normalization in the closed case).**
Let be a closed term. The following are equivalent:
Normalizability:* is -normalizable;* 2. 2.
Valuability:* for some closed value ;* 3. 3.
Completeness:* for some closed value ;* 4. 4.
Adequacy:* for any list (with ) of pairwise distinct variables;* 5. 5.
Empty point:* for any list () of pairwise distinct variables;* 6. 6.
Derivability with empty types:* there exists a derivation ;* 7. 7.
Derivability:* there exists a derivation for some positive type ; * 8. 8.
Strong normalizabilty:* is strongly -normalizable.*
We have already seen on pp. 16–17 that Thm. 25 does not hold in with open terms: closure is crucial.
Thm. 25 entails that a closed term is -normalizable iff it is -normalizable iff it -reduces to a closed value. Thus, Cor. 22 and Thm. 24 can be reformulated for restricted to closed terms as follows.
Corollary 26** (Same number of -steps).**
Let be a closed -normalizable term and be its -normal form. For all reduction sequences and , one has .
Theorem 27** (Number of -steps).**
If is closed and -normalizable, then for .
Clearly, the procedure sketched on p. 6, when applied to a closed term , determines if -normalizes and, in case, how many -steps are needed to reach its -normal form.
Towards a semantic measure.
In order to get a truly semantic measure of the execution time in the shuffling calculus , we should first be able to give an upper bound to the number of -steps in a -reduction looking only at the semantics of terms. Therefore, we need to define a notion of size for the elements of the semantics of terms. The most natural approach is the following. For any positive type (with ), the size of is . So, the size of a positive type is the number of occurrences of in ; in particular, . For any (with ), the size of is .
The approach of [17, 18] relies on a crucial lemma to find an upper bound (and hence the exact length) of the execution time: it relates the size of a type derivation to the size of its conclusion, for a normal term/proof-net. In this lemma should claim that “For every -normal form , if then ”. Unfortunately, in this property is false!
Example 28**.**
Let , which is a -normal form. Consider the derivation
[TABLE]
Then, , which provides a counterexample to the property demanded above.
We conjecture that in order to overcome this counterexample (and to successfully follow the method of [17, 18] to get a purely semantic measure of the execution time) we should change the syntax and the operational semantics of our calculus, always remaining in a call-by-value setting equivalent (from the termination point of view) to and the other calculi studied in [5]. Intuitively, in Ex. 28 contains one application — — that is a stuck -redex and is the source of one “useless” instance of the rule in . The idea for the new calculus is to “fire” a stuck -redex without performing the substitution (as might not be a value), but just creating an explicit substitution that removes the application but “stores” the stuck -redex. Such a calculus has been recently introduced in [6].
Related work.
This work has been presented at the workshop ITRS 2018. Later, the author further investigated this topic with Beniamino Accattoli in [6], where we applied the same type system (and hence the same relational semantics) to a different call-by-value calculus with weak evaluation, . The techniques used in both papers are similar (but not identical), some differences are due to the distinct calculi the type system is applied to. Some results are analogous: semantic and logical characterization of termination, extraction of quantitative information from type derivations. In [6] we focused on an abstract characterization of the type derivations that provide an exact bound on the number of steps to reach the normal form. Here, the semantic and logical characterization of termination is more informative than in [6] because the reduction in is not deterministic, contrary to (the proof that normalization and strong normalization coincide makes sense only for ). Moreover here, unlike [6], we investigate in detail the case of terms reducing to values and how the general results for can be applied to analyze qualitative and quantitative properties of Plotkin’s restricted to closed terms (see above).
Recently, Mazza, Pellissier and Vial [38] introduced a general, elegant and abstract framework for building intersection (idempotent and non-idempotent) type systems characterizing normalization in different calculi. However, such a work contains a wrong claim in one of its applications to concrete calculi and type systems, confirmed by a personal communication with the authors: they affirm that the same type system as the one used here characterizes normalization in Plotkin’s (endowed with the reduction ), but we have shown on pp. 16–17 that this is false for open terms. Indeed, the property called full expansiveness in [38] (which entails that “normalizable typable”) actually does not hold in . It is still true that their approach can be applied to characterize termination in Plotkin’s restricted to closed terms and in the shuffling calculus . Proving that the abstract properties described in [38] to characterize normalization hold in closed or in amounts essentially to show that subject reduction (our Prop. 8), subject expansion (our Prop. 10) and typability of normal forms (our Lemma 15) hold.
The shuffling calculus is compatible with Girard’s call-by-value translation of -terms into linear logic () proof-nets: according to that, -values (which are the only duplicable and erasable -terms) are the only -terms translated as boxes; also, -reduction corresponds to cut-elimination and -reduction corresponds to cut-elimination at depth [math] (i.e. outside exponential boxes). The exact correspondence has many technical intricacies, which are outside the scope of this paper, anyway it can be recovered by composing the translation of the value substitution calculus (another extension of Plotkin’s ) into proof-nets (see [2]), and the encoding (studied in [5]) of into the value substitution calculus. The relational semantics studied here is nothing but the relational semantics for (see [18]) restricted to fragment of that is the image of Girard’s call-by-value translation. The notion of “experiment” in [18] corresponds to our type derivation, and the “result” of an experiment there corresponds to the conclusion of a type derivation here. The main results of de Carvalho, Pagani and Tortora de Falco [18] are similar to ours: characterization of normalization for proof-nets, extraction of quantitative information from (results of) experiments. Nonetheless, the properties shown here for cannot be derived by simply analyzing the analogous results for proof-nets (proven in [18]) within its call-by-value fragment. Indeed, Ex. 28 shows that some property, which holds in the — apparently — more general case of untyped proof-nets (as proven in [18]), does not hold in the — apparently — special case of terms in . It could seem surprising but, actually, there is no contradiction because proof-nets in [18] always require an explicit constructor for dereliction, whereas is outside of this fragment since variables correspond in proof-nets to exponential axioms (which keep implicit the dereliction).
All the papers cited in this section are (more or less explicitly) inspired by de Carvalho’s seminal work [16, 17], which first used relational semantics and non-idempotent intersection types to count the number of -steps to reach the normal form in the call-by-name -calculus. Our results, although analogous and proven following an approach similar to [16, 17], cannot be derived directly from [16, 17]: indeed, the call-by-name -calculus corresponds to a different fragment of than call-by-value (as said in Sect. 1, call-by-name and call-by-value -calculi are translated into via two distinct embeddings). There is also another difference: de Carvalho [16, 17] counts the number of -steps in linear call-by-name evaluation, which substitutes the argument of a -redex for one variable occurrence at a time; here we compute the number of -steps in non-linear call-by-value evaluation, which substitutes the argument of a -redex for all the free occurrences of the redex-variable in just one step. A comprehensive study of the quantitative information given by non-idempotent intersection type systems for several (linear and non-linear) variants of call-by-name evaluation is provided in [4]. In [7] it has been introduced a non-idempotent intersection type system that combines some features of both call-by-name and call-by-value systems, providing quantitative information about the number of -steps to reach the normal form by call-by-need evaluation.
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1[1]
- 2[2] Beniamino Accattoli (2015): Proof nets and the call-by-value λ 𝜆 \lambda -calculus . Theor. Comput. Sci. 606, pp. 2–24, 10.1016/j.tcs.2015.08.006 . · doi ↗
- 3[3] Beniamino Accattoli & Claudio Sacerdoti Coen (2015): On the Relative Usefulness of Fireballs . In: 30th Annual ACM/IEEE Symposium on Logic in Computer Science (LICS 2015) , IEEE Computer Society, pp. 141–155, 10.1109/LICS.2015.23 . · doi ↗
- 4[4] Beniamino Accattoli, Stéphane Graham-Lengrand & Delia Kesner (2018): Tight typings and split bounds . PACMPL 2(ICFP), pp. 94:1–94:30, 10.1145/3236789 . · doi ↗
- 5[5] Beniamino Accattoli & Giulio Guerrieri (2016): Open Call-by-Value . In Atsushi Igarashi, editor: Programming Languages and Systems - 14th Asian Symposium (APLAS 2016) , Lecture Notes in Computer Science 10017, Springer, pp. 206–226, 10.1007/978-3-319-47958-3_12 . · doi ↗
- 6[6] Beniamino Accattoli & Giulio Guerrieri (2018): Types of Fireballs . In Sukyoung Ryu, editor: Programming Languages and Systems - 16th Asian Symposium (APLAS 2018) , 11275, Springer, pp. 45–66, 10.1007/978-3-030-02768-1_3 . · doi ↗
- 7[7] Beniamino Accattoli, Giulio Guerrieri & Maico Leberle (2019): Types by Need . In Luís Caires, editor: Programming Languages and Systems - 28th European Symposium on Programming (ESOP 2019) , Lecture Notes in Computer Science 11423, Springer, pp. 410–439, 10.1007/978-3-030-17184-1_15 . · doi ↗
- 8[8] Beniamino Accattoli & Luca Paolini (2012): Call-by-Value Solvability, Revisited . In Tom Schrijvers & Peter Thiemann, editors: Functional and Logic Programming - 11th International Symposium (FLOPS 2012) , Lecture Notes in Computer Science 7294, Springer, pp. 4–16, 10.1007/978-3-642-29822-6_4 . · doi ↗
