Krivine Machine and Taylor Expansion in a Non-uniform Setting
Antoine Allioux (Institut de Recherche en Informatique Fondamentale,, Paris, France)

TL;DR
This paper extends the Krivine machine to the algebraic lambda-calculus, enabling resource annotations and probabilistic interpretations, with coefficients derived from Taylor expansions.
Contribution
It generalizes the resource-sensitive Krivine machine to algebraic lambda-calculus, linking resource annotations to Taylor expansion coefficients and probabilistic semantics.
Findings
Coefficients in the machine correspond to resource usage probabilities.
Taylor expansion coefficients can recover resource annotations.
The approach applies to probabilistic lambda-calculus models.
Abstract
The Krivine machine is an abstract machine implementing the linear head reduction of lambda-calculus. Ehrhard and Regnier gave a resource sensitive version returning the annotated form of a lambda-term accounting for the resources used by the linear head reduction. These annotations take the form of terms in the resource lambda-calculus. We generalize this resource-driven Krivine machine to the case of the algebraic lambda-calculus. The latter is an extension of the pure lambda-calculus allowing for the linear combination of lambda-terms with coefficients taken from a semiring. Our machine associates a lambda-term M and a resource annotation t with a scalar k in the semiring describing some quantitative properties of the linear head reduction of M. In the particular case of non-negative real numbers and of algebraic terms M representing probability distributions, the coefficient k…
| Algebraic equalities of the -module |
|---|
| Linear properties |
| Algebraic state | Resource state | ||||
|---|---|---|---|---|---|
| Term | Env. | Stack | Term | Env. | Stack |
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.
Krivine Machine and Taylor Expansion in a Non-uniform Setting
Antoine Allioux Institut de Recherche en Informatique Fondamentale
Paris, France [email protected]
Abstract
The Krivine machine is an abstract machine implementing the linear head reduction of -calculus. Ehrhard and Regnier gave a resource sensitive version returning the annotated form of a -term accounting for the resources used by the linear head reduction. These annotations take the form of terms in the resource -calculus.
We generalize this resource-driven Krivine machine to the case of the algebraic -calculus. The latter is an extension of the pure -calculus allowing for the linear combination of -terms with coefficients taken from a semiring. Our machine associates a -term and a resource annotation with a scalar in the semiring describing some quantitative properties of the linear head reduction of .
In the particular case of non-negative real numbers and of algebraic terms representing probability distributions, the coefficient gives the probability that the linear head reduction actually uses exactly the resources annotated by . In the general case, we prove that the coefficient can be recovered from the coefficient of in the Taylor expansion of and from the normal form of .
1 Introduction
The Krivine machine is an abstract machine implementing the linear head reduction [2] on the pure -calculus. Ehrhard and Regnier gave a resource sensitive version [4] returning the annotated form of a -term accounting for the resources used by the linear head reduction. These annotations take the form of terms in the resource -calculus. As an example, the ordinary term which reduces to the constant is annotated by the following resource term . This resource term informs us that is used twice during the reduction and and are used once.
We generalize this resource-driven Krivine machine to the case of the algebraic -calculus111This machine has been implemented and is available online at http://allioux.iiens.net/taylor/.. The latter is an extension of the pure -calculus allowing for the linear combination of -terms with coefficients taken from a semiring. Some properties enjoyed by the ordinary -calculus do not hold anymore in the case of the algebraic -calculus and some results become nontrivial. Our machine associates a -term and a resource annotation with a scalar in the semiring describing some quantitative properties of the linear head reduction of . We will only consider terms reducing to a multiple of a constant for the sake of convenience.
In the particular case of non-negative real numbers and of terms representing probability distributions, the coefficient gives the probability that the linear head reduction actually uses exactly the resources annotated by . In the general case, we prove that the coefficient can be recovered from the coefficient of in the Taylor expansion of and from the normal form of . A more detailed report concerning this work can be found at http://allioux.iiens.net/taylor/report.pdf.
2 Algebraic lambda calculus
The algebraic -calculus is an extension of the pure -calculus allowing for the linear combination of -terms. More precisely, we endow it with a structure of left -module where is a semiring. We shall follow the presentation of the algebraic -calculus given in [6].
2.1 Grammar
Let be a variable in , the set of variables, and let be a scalar in . The grammar of the algebraic -calculus is the following:
[TABLE]
We denote the equivalence relation described in Table 1 making into a left -module and providing linear properties to terms. We consider the terms of the quotient set up to -conversion and we call them algebraic terms. We define free variables and -conversion as in [6].
2.2 Algebraic states
The behaviour of the Krivine machine is defined on some structures we call states with which we can associate a unique algebraic term rather than on algebraic terms directly. A state is a snapshot of the abstract machine at a given time and represents the dissection of a unique -term.
Algebraic environment
An algebraic environment is a finite partial function mapping variables to closures. We introduce the notation to refer to the environment which behaves like for variables other than and which maps to .
Algebraic closure
An algebraic closure is a pair composed of an algebraic term and of an environment such that where denotes the free variables of and denotes the domain of .
Algebraic state
An algebraic state is a nonempty stack of closures. We choose to denote states as triples where is the first closure of the stack and is the stack of the remaining closures. Indeed, our Krivine machine implementing the linear head reduction, we reduce according to the structure of the first closure and we give it a special status. We refer to the set of the algebraic states by .
The intuition behind algebraic states can be made explicit by defining the function which given an algebraic state returns its unique associated algebraic term.
Given any algebraic closure and any stack of algebraic closures with , we first define T on closures and then extend it to states as follows:
[TABLE]
2.3 Krivine machine
In this particular section the semiring is complete — its sum is infinitary.
We give a description of the Krivine machine as the limit of the sequence defined by induction on lexicographically ordered where is a non-negative integer and is an algebraic term. The induction on turns the reduction of into a finite process even for non-normalizing terms. We also enrich the grammar of the algebraic -calculus with the constant as we restrict our study to closed terms reducing to this constant.
- •
,
- •
,
- •
if ,
- •
assuming ,
- •
.
These rules, excluding the first two ones, are the ones of the original Krivine machine. As the algebraic -calculus is just an extension of the ordinary -calculus, it suffices to add the two following rules to the description of the Krivine machine to handle it:
- •
,
- •
.
Finally we set .
3 Resource lambda calculus
We recall the syntax and the reduction of the resource -calculus which has been defined in [5]. Indeed, we will define the Taylor expansion of an algebraic term in terms of a sum of resource terms.
3.1 Grammar
The resource -calculus shares its syntax with the ordinary -calculus with the exception that the application takes multisets of terms as argument. We use the multiplicative notation to denote multisets so the multiplicative unit is the empty multiset. For example is the multiset formed of two occurrences of and one occurrence of . Multisets are commutative. The multiset union of and is denoted . The multiplicity of an element in a multiset is given by . The support of , denoted , is the set of elements of whose multiplicity is nonzero.
The grammar of simple terms in the resource -calculus is:
[TABLE]
where , the set of variables and where is a finite multiset of simple terms. We denote the set of simple terms and we refer to its elements using lower case letters . The set of finite multisets of simple terms is denoted . We call its elements simple poly-terms and we refer to them using upper case letters . When a term can either be a simple term or a simple poly-term we say it is in .
When denoting an application, we use the Krivine notation which we recall: for any simple term and any simple poly-terms , we denote the application by the simplified form .
The module is the set of linear combinations of simple (poly-)terms with coefficients in . We call its elements (poly-)terms in opposition to simple (poly-)terms which are not part of a linear combination. These combinations can not be expressed in the syntax of the resource -calculus contrarily to the algebraic -calculus. We refer to (poly-)terms using the letters . We denote the coefficient of the (poly-)term in . Finally we extend the grammar of the resource -calculus to all (poly-)terms by multilinearity so that: , and .
3.2 Linear substitution and reduction
The reduction of the resource -calculus is based on a particular notion of linear substitution. What distinguishes linear substitutions from classical substitutions is that, in the former case, substituted terms have to be used once and only once whereas this restriction does not apply in the latter case.
For a variable and a term , we define deg to be the number of occurrences of in and we call it the degree in of .
Let be the resource term obtained from a resource term by renaming its different occurrences of to with . is such that for all , deg and .
Let be a simple term and let be any poly-term with being a non-negative integer, the linear substitution of by is defined as follows:
[TABLE]
with being the group of permutations on the set . This construction can be extended to simple (poly-)terms.
We extend this notation to the linear substitution of several variables. For all poly-terms with being a non-negative integer,
[TABLE]
This substitution does not depend on the order of the iterated substitutions as the variables are pairwise distincts.
We derive the -reduction relation for the resource -calculus from this linear substitution. A redex in the resource -calculus is of the form and reduces as follows: .
We extend this relation to by defining it as being the least relation closed under the following rules, assuming with and :
This relation is confluent and strongly normalizing for as proved in [3] and we derive NF, the unique normalization map , where stands for the set of normal simple terms.
3.3 Resource states
Similarly to the case of the algebraic -calculus, we define resource closures, resource environments and resource states in a mutually recursive fashion.
Resource environment
A resource environment is a total function from the set of variables to resource closures. is the empty environment mapping any variable in to the empty closure . We use the notation to refer to the environment which maps the variable to the closure and all the other variables to the closure . Given two environments and , we define their pointwise concatenation such that for all variables , .
Resource closure
A resource closure is defined as a pair where is a simple poly-term and is a resource environment. A resource closure is said to be elementary when its multiset is a singleton. The empty closure is . We use letters for general resource closures and for elementary resource closures.
Resource state
A resource state is a triple where is an elementary resource closure and where is a stack of resource closures. We denote the set of resource states .
4 Quantitative Krivine machine and Taylor expansion
4.1 Quantitative Krivine machine
In turn we define our quantitative Krivine machine (qKAM) 222This machine has been implemented and is available online at http://allioux.iiens.net/taylor/. which draws its inspiration from the one described in [4]. This definition is the main contribution of this paper. It is important to note that for the sake of convenience we will only consider closed algebraic terms which reduce to the constant . From now on, we therefore enrich the syntax of the resource -calculus with this same constant .
The following machine computes a coefficient associated with an algebraic state and a resource state. We remind that an algebraic state corresponds to a unique -term and a resource state corresponds to a unique sum of resource terms. Therefore, in the case of algebraic terms whose sums correspond to probability distributions, this coefficient will be the sum of the probabilities that each resource term in the sum describe a resource usage of the reduction of the algebraic term to .
Definition 4.1**.**
(Quantitative Krivine machine)
The quantitative Krivine machine is defined as a matrix . It is defined by induction on the pair 333The size of a term is its number of symbols. lexicographically ordered. denotes the coefficient in associated with the pair .
- •
,
- •
if and is such that ,
- •
if and where w.l.o.g ,
- •
,
The major difference with the case of the ordinary -calculus appears in the following two cases:
- •
,
- •
,
- •
Otherwise .
As we do not want to deal with states directly, we hide them by defining which takes terms instead of states.
Definition 4.2**.**
For any algebraic term and any resource term ,
[TABLE]
This machine is defined for all semirings and in the particular case of computes a coefficient we shall characterize in Theorem 4.5.
We shall give some examples of execution. Let and . Consider the two examples and , where .
[TABLE]
Table 2 exposes the succession of states taken by the machine which are associated with a nonzero coefficient during the execution of this example. In fact, in this very case all the states have the coefficient 1 in . We shall detail the transition from the to the state as this is the only one which involves a sum with several summands even though only one of these summands is nonzero.
Let be the algebraic state and let be the algebraic state .
Then the transition from the to the state in Table 2 given by Definition 4.1 is:
[TABLE]
But both and are equal to 0 according to Definition 4.1.
That is why we only show the pair of states in Table 2.
We will not give the full breakdown of the execution of the machine for the next example.
[TABLE]
There are two non-deterministic reductions of which lead to . The first one with multiplicity and the second one with multiplicity which correspond to the two non-deterministic choices induced by the sum .
4.2 Taylor expansion
In this setting we choose to restrict , the semiring over which is defined our algebraic -calculus, to any semiring having a multiplicative inverse such as . Taylor expanding an algebraic term then comes down to expanding its applications according to the following formula:
[TABLE]
where denotes the Taylor expansion of the algebraic term and where is the sum of multisets of cardinality whose elements are in the support of associated with a coefficient we will not detail here but which can be found in the report.
We justify the terminology “Taylor expansion” by pointing out that in analysis the Taylor series of an infinitely differentiable function at [math] is . This is, indeed, quite similar to the form of the Taylor expansion of the application in the -calculus. See [3] for more details.
This operation can alternatively be defined by means of coefficients defined inductively on algebraic and resource terms. To this effect, we recall the coefficient described in [5] accounting for the intrinsic contribution of a resource term to its coefficient in the Taylor expansion of an algebraic term and we introduce the weights which account for the dependance in of this coefficient.
Definition 4.3**.**
The multiplicity of a resource term and the weight of a resource term in an algebraic term are inductively defined as follows:
[TABLE]
The coefficient corresponds to the number of permutations of variable occurrences of preserving the name of the variables and letting the term unchanged. Finally, contrary to the case of the ordinary -calculus, the multiplicity of in the Taylor expansion of does not only depend on but also depends on . The weights account for this phenomenon and represent one of the contributions of this paper.
We shall give some examples to enlighten the reader about these coefficients.
[TABLE]
As for the weights, their use is motivated by terms of the form and . Otherwise, if a term is a pure -term and not an algebraic term then for any , is equal to if and [math] otherwise.
Consider the following example:
[TABLE]
Therefore, there are 9 ways to derive from .
Finally, the expression of the Taylor expansion can alternatively be given by the following definition:
Definition 4.4**.**
(Taylor expansion) Given an algebraic term , its Taylor expansion is:
[TABLE]
It is easy to show this definition leads to an inductive definition of the Taylor expansion on the shape of algebraic terms which is compatible with Equation 6. This motivates our terminology.
4.3 Connection between the qKAM and the Taylor expansion
The following theorem, which is one of the main contributions of this paper, along with the definition of the qKAM, links the behaviour of the qKAM with the Taylor expansion of algebraic terms.
Theorem 4.5**.**
For all algebraic terms , for all resource terms and provided that has a multiplicative inverse,
[TABLE]
where is the coefficient of in and is the coefficient of in .
This theorem is a particular case of a more general result applying to any algebraic state and any resource state. It can be found in the report.
4.4 Computational complexity
At first, it seemed that Theorem 4.5 informed us of an efficient way to compute . Indeed, the Krivine machine reduces to compute a subset of its Taylor expansion whereas the equation (8) gave hope we could obtain the same result more efficiently as the right-hand side does not involve the reduction of . Although can be computed statically by means of the coefficients and , it is folklore that determining is NP-complete.
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1[1]
- 2[2] Vincent Danos & Laurent Regnier (1999): Reversible, irreversible and optimal λ 𝜆 \lambda -machines . Theoretical Computer Science 227(1), pp. 79–97, 10.1016/S 0304-3975(99)00049-3 . · doi ↗
- 3[3] Thomas Ehrhard & Laurent Regnier (2003): The differential lambda-calculus . Theoretical Computer Science 309(1-3), pp. 1–41, 10.1016/S 0304-3975(03)00392-X . Available at https://hal.archives-ouvertes.fr/hal-00150572 . 41 pages. · doi ↗
- 4[4] Thomas Ehrhard & Laurent Regnier (2006): Böhm trees, Krivine machine and the Taylor expansion of ordinary lambda-terms . In A. Beckmann, U. Berger, B. Löwe & J.V. Tucker, editors: Second Conference on Computability in Europe, Ci E 2006 , LNCS 3988, Springer Berlin / Heidelberg, Swansea, United Kingdom, pp. 186–197, 10.1007/11780342_20 . Available at https://hal.archives-ouvertes.fr/hal-00150273 . 12 pages. · doi ↗
- 5[5] Thomas Ehrhard & Laurent Regnier (2008): Uniformity and the Taylor expansion of ordinary lambda-terms . Journal of Theoretical Computer Science 403(2-3), pp. 347–372, 10.1016/j.tcs.2008.06.001 . Available at https://hal.archives-ouvertes.fr/hal-00150275 . · doi ↗
- 6[6] Lionel Vaux (2009): The algebraic lambda calculus . Mathematical Structures in Computer Science 19, pp. 1029–1059, 10.1017/S 0960129509990089 . Available at http://journals.cambridge.org/article_S 0960129509990089 . · doi ↗
