AnOperationalAccountofCall-By-Value MinimalandClassical...

15
An Operational Account of Call-By-Value Minimal and Classical λ-calculus in “Natural Deduction” Form (revision fixing a few errors – January 2010) Hugo Herbelin 1 and Stéphane Zimmermann 2 1 INRIA, France 2 PPS, University Paris 7, France Abstract. We give a decomposition of the equational theory of call-by- value λ-calculus into a confluent rewrite system made of three indepen- dent subsystems that refines Moggi’s computational calculus: the purely operational system essentially contains Plotkin’s βv rule and is necessary and sufficient for the evaluation of closed terms; the structural system contains commutation rules that are necessary and sufficient for the reduction of all “computational” redexes of a term, in a sense that we define; the observational system contains rules that have no proper compu- tational content but are necessary to characterize the valid observa- tional equations on finite normal forms. We extend this analysis to the case of λ-calculus with control and pro- vide with the first presentation as a confluent rewrite system of Sabry- Felleisen and Hofmann’s equational theory of λ-calculus with control. Incidentally, we give an alternative definition of standardization in call- by-value λ-calculus that, unlike Plotkin’s original definition, prolongs weak head reduction in an unambiguous way. Introduction The study of call-by-value evaluation in the context of λ-calculus goes back to Plotkin [1] who introduced and studied rules β v and η v and a continuation- passing-style (cps) semantics of a call-by-value λ-calculus, named λ v . Significant contributions were made first by Moggi [2] then by Sabry and Felleisen [3] who provided axiomatizations of call-by-value λ-calculus shown by the last authors to be complete with respect to Plotkin’s cps semantics. In the same paper, Sabry and Felleisen also give a sound and complete axiomatization of call-by-value λ-calculus with control (hereafter referred as classical call-by-value λ-calculus). Independently, Hofmann [4] gave an alternative axiomatization of the classical call-by-value λ-calculus. The theory of call-by-value λ-calculus turns out to be de facto more complex to describe than the one of call-by-name λ-calculus. While β-reduction is enough to evaluate terms in call-by-name λ-calculus and η is enough to characterize the

Transcript of AnOperationalAccountofCall-By-Value MinimalandClassical...

Page 1: AnOperationalAccountofCall-By-Value MinimalandClassical ...pauillac.inria.fr/~herbelin/articles/tlca-HerZim09... · AnOperationalAccountofCall-By-Value MinimalandClassical -calculusin“Natural

An Operational Account of Call-By-ValueMinimal and Classical λ-calculus in “Natural

Deduction” Form(revision fixing a few errors – January 2010)

Hugo Herbelin1 and Stéphane Zimmermann2

1 INRIA, France2 PPS, University Paris 7, France

Abstract. We give a decomposition of the equational theory of call-by-value λ-calculus into a confluent rewrite system made of three indepen-dent subsystems that refines Moggi’s computational calculus:– the purely operational system essentially contains Plotkin’s βv rule

and is necessary and sufficient for the evaluation of closed terms;– the structural system contains commutation rules that are necessary

and sufficient for the reduction of all “computational” redexes of aterm, in a sense that we define;

– the observational system contains rules that have no proper compu-tational content but are necessary to characterize the valid observa-tional equations on finite normal forms.

We extend this analysis to the case of λ-calculus with control and pro-vide with the first presentation as a confluent rewrite system of Sabry-Felleisen and Hofmann’s equational theory of λ-calculus with control.Incidentally, we give an alternative definition of standardization in call-by-value λ-calculus that, unlike Plotkin’s original definition, prolongsweak head reduction in an unambiguous way.

Introduction

The study of call-by-value evaluation in the context of λ-calculus goes back toPlotkin [1] who introduced and studied rules βv and ηv and a continuation-passing-style (cps) semantics of a call-by-value λ-calculus, named λv. Significantcontributions were made first by Moggi [2] then by Sabry and Felleisen [3] whoprovided axiomatizations of call-by-value λ-calculus shown by the last authors tobe complete with respect to Plotkin’s cps semantics. In the same paper, Sabryand Felleisen also give a sound and complete axiomatization of call-by-valueλ-calculus with control (hereafter referred as classical call-by-value λ-calculus).Independently, Hofmann [4] gave an alternative axiomatization of the classicalcall-by-value λ-calculus.

The theory of call-by-value λ-calculus turns out to be de facto more complexto describe than the one of call-by-name λ-calculus. While β-reduction is enoughto evaluate terms in call-by-name λ-calculus and η is enough to characterize the

Page 2: AnOperationalAccountofCall-By-Value MinimalandClassical ...pauillac.inria.fr/~herbelin/articles/tlca-HerZim09... · AnOperationalAccountofCall-By-Value MinimalandClassical -calculusin“Natural

observational equality on finite normal forms (what Böhm separability theoremexpresses, see [5] for a generic account of Böhm theorem vs observational com-pleteness), the situation is more intricate in the call-by-value λ-calculus, where,facing the two rules of the equational theory of call-by-name λ-calculus, the equa-tional theories of call-by-value λ-calculus of Sabry and Felleisen and of Moggirely on about a half dozen rules3.

Though, when we observe call-by-name and call-by-value in the context of se-quent calculus [6, 7], the complexity of the respective theories is about the same.Then, what is so specific to natural deduction (of which the standard λ-calculusis a notation for proofs along the Curry-Howard correspondence) that makescall-by-value more complicated there? Let us first give a more precise look atwhat happens in sequent calculus.

Call-by-name and call-by-value in sequent calculus

In a previous work of the first author with Curien [6], an interpretation of(a variant of) Gentzen’s sequent calculus [8] as a variant of λ-calculus calledλµµ̃-calculus was given, where µ refers to Parigot’s control operator [9]. In thisinterpretation, the left/right symmetry of sequent calculus pervades into a per-fect syntactic duality first between terms and evaluation contexts, and secondlybetween call-by-name and call-by-value reduction. Especially, the operator µ̃,dual to µ, builds an evaluation context that binds the term to which it is ap-plied, as in let x = [ ] in M , in the same way as Parigot’s µ builds a term thatbinds the evaluation context to which it is applied.

The analysis of λ-calculus through sequent calculus given in [7], whether weconsider call-by-name or call-by-value, shows a clear separation between opera-tional rules and observation rules (the operational rules are cut-elimination rulesand they divide into logical rules that contract the interaction of term construc-tors and evaluation context constructors into more elementary interactions, andtwo structural rules, one called (µ) for the contraction of µ and one called (µ̃) forthe contraction of µ̃, that duplicate or erase information, moving terms aroundto possibly create new logical interactions).

A noticeable peculiarity of sequent calculus is that even in the intuitionisticcase, the µ operator is required and when sequent calculus is compared to intu-itionistic natural deduction, it turns out that (µ) acts as a commutative cut.

What is the problem with call-by-value λ-calculus in natural deductionsyntax?

Call-by-value λ-calculus precisely needs commutative cuts so as to revealredexes hidden by β redexes that are not βv redexes. Take as an example theterm ((λx.λy.y)(zt))u with z, t and u as free variables. With respect to λv, this

3 The theory of Moggi has seven rules; the theory of Sabry and Felleisen has six axiomsof which βlift : E[let x = N in M ] → let x = N in E[M ] is redundant; we willsee later on that isolating βlift out is however important from an operational pointof view.

Page 3: AnOperationalAccountofCall-By-Value MinimalandClassical ...pauillac.inria.fr/~herbelin/articles/tlca-HerZim09... · AnOperationalAccountofCall-By-Value MinimalandClassical -calculusin“Natural

term is a normal form, however the reduction between λy and u is possible ifone takes a parallel syntax, like proof-nets or parallel application to obtain theterm (λx.u)(zt).

This is due to the presence of free variables, that can hide potential reduc-tions. When using a parallel syntax, one does not rely anymore on syntacticalshapes, but on calculus dependencies. In our example, the reduction between λxand (zt) is independent from the reduction between λy and u.

This is where the structural rules announced in the abstract come in: theywill denote implicit use of the reduction rule for µ. For call-by-name, we have thewell-known σ-equivalence [10] that disentangle redexes, but we have to be morecareful for call-by-value. So here, the rule ((λx.λy.M)N)P

σ−→ (λy.(λx.M)N)Pis not valid, because one changes the evaluation order of N and P and will breakconfluence in presence of a µ operator. Our structural rules should then preservehead reduction order to avoid such problems.

1 Call-by-value λ-calculus (λCBV -calculus)

In this section, we show how the equational theory of call-by-value λ-calculuscan be decomposed into three independent subsystems of rules. Note that weconsider here only left-to-right call-by-value.

1.1 The splitting of the usual βv rule

To be able to use what sequent calculus teaches us, we need a constructioncorresponding to the µ̃ of λµµ̃. We extend the λ-calculus grammar with a letconstruction, as follows:

V ::= x | λx.MT ::=MN | let x =M in NM,N ::= V | T

The direct counterpart of this splitting is syntactically expressed by the twofollowing rules:

(⇒) (λx.M)N → let x = N in M(letv) let x = V in M → M [x← V ]

To understand the intuition behind this, it is necessary to look at how headreduction is performed on an application. We have to check first if M is a valueor not, and then if N is a value or not to determine what to reduce. So controlis not clear on an application, sometimes it is the left term that has it andsometimes it is the right one.

Using the let is an elegant way to get rid of this. You only need to look atthe left term of an application, and when this term is eventually reduced to a λ,it naturally gives the control to the term of the right thanks to the (⇒) rule.

Thanks to this decomposition, we can now have a clear notion of control, andbe able to determine where to work on. An evaluation context F is now either

Page 4: AnOperationalAccountofCall-By-Value MinimalandClassical ...pauillac.inria.fr/~herbelin/articles/tlca-HerZim09... · AnOperationalAccountofCall-By-Value MinimalandClassical -calculusin“Natural

an application with a hole on the left, or a hole inside a let, say:F ::= [ ]M | let x = [ ] in Mand the mechanism of giving control to the “right” part of the application is nowexplicit. As we will see later, this will help to solve a standardization problemthat arises from this ambiguity.

1.2 Dealing with the implicit (µ) rules

Whenever in the calculus there exists a conditional rule (W )L → R, we willcall a pseudo-redex a term matching L but not satisfying the side condition. Forcall-by-value λ-calculus, the term (λx.x)(yz) is a pseudo-redex, because yz isnot a value.

In our calculus, the pseudo-redexes are not of the shape (λx.M)T , but morelike let x = T in M . Still, they can hide reductions. Take for example theterm (let x = zt in λy.y)u, the counterpart to the term ((λx.λy.y)(zt))u. Thereduction between λy and u is still hidden, and we need to get the u inside thelet, in a sense. This can be done using the two rules (letlet) and (letapp).

(letlet) let x = (let y =M in N) in P→ let y =M in let x = N in P

(letapp) (let x =M in N)P→ let x =M in NP

The (letapp) rule is here to deal with a pseudo-redex on the left side of anapplication. If you have a pseudo-redex inside on the left of an application, youcan get it outside the application without disturbing the evaluation order, andrecover the possible interactions that are independent of the substitution. Usingthis rule on the example above, we get (let x = zt in λy.y)u → let x =zt in (λy.y)u. The subterm zt still has control during the reduction, but we cando the other reductions as well.

The (letlet) rule has the same role, only for the right part of an application.

1.3 Basic properties of the calculus

Our presentation of call-by-value λ-calculus, called λCBV -calculus, is given inFigure 1. The auxiliary definition of evaluation context F (resp. E) is used tofind the sub-term locally (resp. globally) in control in the term.

The (⇒) and (letv) rules correspond to the (βv) rule, and the (letlet) and(letapp) rules are the two rules managing the implicit (µ) reductions.

Regarding notations, we will use as a convention that parentheses on the leftof an application are implicit, meaning that the termMNP stands for ((MN)P ).In the term λx.M , we will say that the occurrence of x in M are bound and byfree variables, we mean variables that are not bound. The set of the free variablesof a term M will be written FV (M).

To avoid problems of capturing variables, we will work modulo α-conversion,i.e. modulo the renaming of bound variables. Therefore, the names for free vari-ables and bound variables in a given term can always be made distinct. By

Page 5: AnOperationalAccountofCall-By-Value MinimalandClassical ...pauillac.inria.fr/~herbelin/articles/tlca-HerZim09... · AnOperationalAccountofCall-By-Value MinimalandClassical -calculusin“Natural

Syntax

V ::= x | λx.M F ::= [ ]M | let x = [ ] in MM,N,P ::= V |MN | let x =M in N E ::= [ ] | xE | F [E]

Operational rules

(⇒) (λx.N)Mr→ let x =M in N

(letv) let x = V in Nr→ N [x← V ]

Structural rules

(letlet) let z = (let x =M in N) in Pr→ let x =M in (let z = N in P )

(letapp) (let x =M in N)Pr→ let x =M in NP

Observational rules

(η⇒) λx.(yx)r→ y

(ηElet) let x =M in E[x]r→ E[M ] if x 6∈ FV (E)

(letvar ) z(let x =M in N)r→ let x =M in zN

Fig. 1. The full λCBV -calculus

M [x ← V ], we mean the capture-free substitution of every occurrence of thefree variable x of M by V .

We write → for the compatible closure of r→ and →∗ for the reflexive andtransitive closure of → . We write = for the equational theory associated.

Proposition 1 (Confluence). The operational subsystem, its extension withstructural rules and the full system of reduction rules are all confluent in λCBV -calculus. Otherwise said, for each of these three systems, if M →∗ N andM →∗ N ′, then there exists P such that N →∗ P and N ′ →∗ P .

Proof (Indication). This statement is proved using Tait – Martin-Löf method,applied to the parallel reduction V defined by the union (of generalizations) ofthe above reduction rules and the following congruence:

– tV t– if M VM ′ then λx.M V λx.M ′

– ifM VM ′ and N V N ′ thenMN VM ′N ′ and let x =M in N V let x =M ′ in N ′

Note that (letvar ) is redundant in the equational theory but necessary in thereduction theory to get the confluence.

We say that a reduction relation → is operationally complete if whenever aclosed M is not a value, it is reducible along → . For instance, usual β-reductionis operationally complete for call-by-name λ-calculus.

Page 6: AnOperationalAccountofCall-By-Value MinimalandClassical ...pauillac.inria.fr/~herbelin/articles/tlca-HerZim09... · AnOperationalAccountofCall-By-Value MinimalandClassical -calculusin“Natural

Proposition 2. λCBV equipped with the rules (⇒) and (letv) is operationallycomplete.

Proof. Any closed term which is not a value has either the form E[let x =λy.M in N ] in which case (letv) is applicable or E[(λx.M)N ] in which case (⇒)is applicable.Remark. For simplicity of the definition of λCBV , we did not consider a minimalset of operational rules. A minimal operationally complete set can be obtained byrestricting both M in (⇒) and V in (letv) to be of the form λy.P . However, thiswould force to explicitly add an observational rule let x = y in N

r→ N [x← y]

and a structural rule (λx.N)(E[yM ])r→ let x = E[yM ] in N (where the notion

of pseudo-redex and erasing rule, see below, is extended to the case of β-redexes).

Associated to reduction rules with constraint, we can define erasing rulesused to erase the pseudo-redex part of the rule. Namely, we will use the systemcomposed of the following rule for this:let x = N in M

er−→ NA term M is normal for a reduction → if it is not reducible for → . It

is structurally normal if, for all N such that M er−→∗

N , N is normal forthe reduction generated by the operational rules. A reduction relation → isstructurally complete if all terms normal for → are structurally normal.

Proposition 3. The set of terms that are normal with respect to the operationaland structural rules is described by the entry Q of the following grammar:

Q ::= λx.Q | S | let x = S in QS ::= x | SQMoreover, the reduction generated by the operational and structural rules of

λCBV -calculus is structurally complete.

Proof (Indication). The two parts are proved by induction quite directly.It is interesting to see that in a normal form like let x = P in Q, the leftmost

subterm of P is always a free variable and the evaluation of P is blocked bythis variable. This suggests an alternative definition of structural completenessbased on the notion of evaluation of open terms: a set of rules is structurallycomplete iff any term which is neither a value nor of the form xM1...Mn orlet y = xM1...Mn in N is reducible.

Let us now focus on the observational rules of Figure 1. Given a confluentreduction → , we say that an equation M = N between normal terms belongsto the observational closure of → if for every closed evaluation context E andevery substitution ρ of the free variables of M and N by closed values, E[ρ(M)]converges along →∗ iff E[ρ(N)] converges.

Proposition 4. The observational rules from Figure 1 belong to the observa-tional closure of the set of operational and structural rules of λCBV -calculus.

Proof. When instantiated by closed values, both sides of (η⇒) and (letvar ) con-verge by respectively using (⇒) and (letv), (⇒) and (letlet). For (ηElet), the result

Page 7: AnOperationalAccountofCall-By-Value MinimalandClassical ...pauillac.inria.fr/~herbelin/articles/tlca-HerZim09... · AnOperationalAccountofCall-By-Value MinimalandClassical -calculusin“Natural

follows by standardization (see below) since at some point, for ρ a substitutionof the free variables of E′[yM ], the reduction of ρ(E′[yM ]) eventually yields avalue and (letv) is applicable.

1.4 The subformula property and structural completeness

The λCBV -calculus can be typed by natural deduction just like the conventional(call-by-name) λ-calculus. The only new construction is the let, which can betyped by the cut rule. The whole typing system is the following:

Γ, x : A ` x : A

Γ, x : A `M : B

Γ ` λx.M : A⇒ B

Γ `M : A⇒ B Γ ` N : A

Γ `MN : B

Γ, x : A `M : B Γ ` N : A

Γ ` let x = N in M : B

Contrary to the call-by-name λ-calculus, the original call-by value λ-calculusdoes not satisfy the subformula property for its normal forms. We can distinguishtwo kinds of “breaking” of this property.

The first one happens with the pseudo-redexes. The term (λx.x)(yz) is anormal form, which can be typed this way, with Γ = y : B ⇒ A, z : B :

Γ ` λx.x : A⇒ A Γ ` yz : A

Γ ` (λx.x)(yz) : A

The problem here comes from the type A ⇒ A that appears after the cutbetween λx.x and yz. If we remember that a cut, in natural deduction, is anintroduction rule followed by a elimination rule, then neither of the two rules,taken alone, are problematic. Think of normal forms like yM , corresponding tothe elimination of implication, and λx.M , corresponding to the introduction ofimplication. It is really the cut that is causing problems.

In λCBV , because the pseudo-redexes correspond to sequent calculus cuts,we can get rid of this problem. The A⇒ A formula become A ` A, and our termbecome (λx.x)(yz) → let x = yz in x, whose proof has the subformula property.

However, this is not enough to get rid of all our problems. With Γ = u :A, z : C ⇒ D, t : C the term (let x = zt in λy.y)u can be typed this way :

Γ ` let x = zt in λy.y : A⇒ B Γ ` u : A

` (let x = zt in λy.y)u : B

Again, there is a A⇒ B type appearing and breaking the subformula prop-erty. This time, it is not a problem of pseudo-redex, but rather one of hiddenredex. To solve this, we need the structural (letapp) rule to reduce the interactionbetween y and u and, in a more general manner our terms have to be structurallycomplete otherwise hidden redexes will create unnecessary arrow types.

Page 8: AnOperationalAccountofCall-By-Value MinimalandClassical ...pauillac.inria.fr/~herbelin/articles/tlca-HerZim09... · AnOperationalAccountofCall-By-Value MinimalandClassical -calculusin“Natural

Pushing pseudo-redexes to more atomic let terms and having structural rulesis sufficient to gain back the subformula property for λCBV , which is expressedby the following property.

Proposition 5. Let M be a term of the λCBV calculus that is normal withrespect to the operational and structural rules. Then if Γ ` M : A, its proofsatisfies the subformula property.

Proof. We shall reason by induction on the proof of Γ ` M : A. The onlytechnical point is to know that on a normal form, the leftmost term on an ap-plication is a variable which is in the context.

1.5 Standardization

Plotkin’s definition of standard reduction sequences in λv does not characterizecanonical standard reduction sequences: the standard reduction of a term is notalways unique. We first recall the definition of head reduction h−→ and standardreduction sequences (s.r.s.) in Plotkin [1]:

– (λx.M)Vh−→ M [x← V ]

– if M h−→ M ′ then MNh−→ M ′N

– if M h−→ M ′ then VM h−→ VM ′

– any variable is a s.r.s.– if M1

h−→ M2 and M2, . . . ,Mn is a s.r.s., then M1,M2, . . . ,Mn is a s.r.s.– if M1, . . . ,Mn is a s.r.s. then λx.M1, . . . , λx.Mn is a s.r.s.– if M1, . . . ,Mn and N1, . . . , Np are s.r.s., then M1N1, . . . ,MnN1, . . . ,MnNp is a

s.r.s.

Now, if we take M and N such that M h−→ M ′ and N h−→ N ′, then the twofollowing reductions are standard:

(λx.M)Ns−→ (λx.M)N ′

s−→ (λx.M ′)N ′

(λx.M)Ns−→ (λx.M ′)N

s−→ (λx.M ′)N ′

The first one is built as an extension of head reduction, while the second oneis built only using the application rule of standard reduction. The explanation isthat in λv, there is no direct way to determine what is in control in an application,so there is no possibility to have a unique general rule for application.

In λCBV , since the (βv) rule was split, the control is unambiguous, so we canget rid of this problem. Weak-head reduction for λCBV and an alternative, nonambiguous, definition of standard reduction sequences are given below.

– Mh−→ M ′ for any subset4 of rules of λCBV

4 If (letv) is present in the subset, we assume that M in the rules (letapp), (letlet),(letvar ) and (ηElet) is restricted to the form E[yM ′] so that head reduction favorsletv. If (ηElet) is present, we assume that N in the rules (letapp), (letlet) and (letvar )is not of the form E[x] so that head reduction favors (ηElet).

Page 9: AnOperationalAccountofCall-By-Value MinimalandClassical ...pauillac.inria.fr/~herbelin/articles/tlca-HerZim09... · AnOperationalAccountofCall-By-Value MinimalandClassical -calculusin“Natural

– if M h−→ M ′ then F [M ]h−→ F [M ′]

– any variable is a s.r.s.– if M1

h−→ M2 and M2, . . . ,Mn is a s.r.s., then M1,M2, . . . ,Mn is a s.r.s.– if M, . . . , E1[V1]

5 is a head reduction sequence, and V1, . . . Vn and E1, . . . , Ep ares.r.s., then M, . . . , E1[V1], . . . E1[Vn], . . . Ep[Vn] is a s.r.s.

– if M1, . . . ,Mn is a s.r.s., then λx.M1, . . . , λx.Mn is a s.r.s.

– [ ] is a s.r.s. on contexts– if M1, . . . ,Mn and E1, . . . , Ep are s.r.s. on terms and on contexts, then the se-

quences E1[let x = [ ] in M1], . . . , E1[let x = [ ] in Mn], . . . , Ep[let x = [ ] in Mn]and E1[[ ]M1], . . . , E1[[ ]Mn], . . . , Ep[[ ]Mn] are s.r.s. on contexts

Note that the definition applies to λv too by using only (βv) in the definitionof head reduction.

Theorem 1 (Standardization). For all M and N , if M →∗ N using anyset of reduction rules there is a unique standard reduction sequence M, . . . , Nextending head reduction. We shall note this reduction M s−→ N

Proof (Indication). We shall proceed by induction, with permutation of non-standard reductions. Uniqueness is by canonicity of the definition of being astandard reduction sequence.

But as we said before, we even got a stronger result. If M is a closed term,its head reduction (so its standard reduction) only uses the two rules (⇒) and(letv), and the other rules are not necessary. We shall prove this, but we needto notice that if M is a closed term, then M cannot be decomposed throughE[yP ], and if M = E[yP ], then M never reduces to a value.

Proposition 6. If M is a closed term such that M →∗ V , then there exists V ′

such that M h−→∗V ′ and V = V ′ with s−→ using only the rules (⇒) and (letv).

Proof (Indication). As it is a consequence of the standard reduction, we justuse an induction on the standard reduction of M .

This result is not surprising, if you think that the (⇒) and (letv) rules cor-respond to the (βv) rule, and that (βv) rule is sufficient to deal with closedterms.

So we have a calculus where all rules have their own purpose, which is clearlydefined.

1.6 Comparison with Moggi’s λc-calculus

In [2], Moggi gives a call-by-value calculus, on the same syntax as λCBV . Thereduction rules and the grammar characterizing normal forms with respect tothe (βv), (let.1), (let.2) and (let.let) rules are given in Figure 2 (T denotes termsthat are not values). This calculus was made to allow more reductions than theoriginal call-by-value calculus while remaining call-by-value.5 Remember that E[] can be empty, so that M reduces to a value.

Page 10: AnOperationalAccountofCall-By-Value MinimalandClassical ...pauillac.inria.fr/~herbelin/articles/tlca-HerZim09... · AnOperationalAccountofCall-By-Value MinimalandClassical -calculusin“Natural

(βv) (λx.M)V → M [x← V ](letv) let x = V in M → M [x← V ](let.1) TM → let x = T in xM with x fresh(let.2) V T → let x = T in V x with x fresh(let.let) let y = (let x =M in N) in P → let x =M in let y = N in P

(η⇒) λx.V x → V if x is not free in V(letid) let x =M in x → M

W ::= x | λx.QQ ::= let x = yW in Q | xW |W

Fig. 2. Moggi’s λC-calculus and its normal forms

We say that two operational theories are in equational correspondence (seeSabry-Felleisen for the original notion [3]) if there is a bijection between theequivalence classes of the theories. Especially, we can show that our theory ofλCBV is in equational correspondence with the one of Moggi.

Proposition 7. The two calculi λc and λCBV are in equational correspondence.

Proof (Indication). We only show here the interesting cases of the simulationof the rules.

letapp = let.1 + let.let+ (let.1)−1

letvar = let.2 + let.let+ (let.2)−1

let.1 = (ηlet x=[] in Nlet )−1

For let.2 we proceed case by case. If V is y, then let.2 = (ηx[]let)−1. If V = λy.M

then let.2 =⇒ +(⇒)−1.Our claim is now that λCBV has a finer structure than λc. First, observe that

in Moggi’s calculus, for the same reason as in λCBV , the rules (βv) and (letv)are sufficient for operational completeness.

Proposition 8. The λc-calculus restricted to the rules (βv) and (letv) is oper-ationally complete.

The λc-calculus equipped with (βv), (letv), (let.1), (let.2) and (let.let) isstructurally complete.

A weird point is the presence of an observational rule, namely (η[]⇒) in thesimulation of the (let.1) and (let.2) rules, providing an ambiguous status to thesetwo rules, used for computation but containing a bit of observation too. Thiscan be related to another not so likable behavior of λc. We remember that thecalculus has the (βv) rule which is sufficient to reduce closed terms to values,but if we reduce the term (λx.x)((λx.x)(λx.x)) with head reduction, we obtainthe following reduction sequence:(λx.x)((λx.x)(λx.x)) → let y = (λx.x)(λx.x) in (λx.x)y →∗ λx.x.

The head reduction uses the rule (let.2) as the first reduction rule, and for theterm ((λx.x)(λxy.y))(λx.x)(λx.x) the head reduction uses the rules (let.1) and

Page 11: AnOperationalAccountofCall-By-Value MinimalandClassical ...pauillac.inria.fr/~herbelin/articles/tlca-HerZim09... · AnOperationalAccountofCall-By-Value MinimalandClassical -calculusin“Natural

(let.let). So, even if we do not need them, these rules appear and the λc-calculustends to do useless expansions.

This was already noticed by Sabry and Wadler in [11] where they showedthat λc is isomorphic to one of its sub-calculi where all the let rules have beenreduced, and applications occur only between two variables. The let constructionis here a way to make the head-reduction flow explicit and to reduce a term, λcfirstly encodes its evaluation flow with some let manipulation, and only thenreduces the term.

By doing this, we lose almost completely a “hidden agent” of the reduction :the structural congruence. In λv, the (βv) rule was sufficient because it could goinside a term to find a redex, as here we almost never investigate in the term.The evaluation flow is encoded in a way that the topmost term always containsthe redex, but is then superseding the structural congruence.

So, the status of the let rules is not clearly defined. They are used for reducingclosed terms to values, but are also necessary for the structural completeness andcontain a taste of observational rules.

Interestingly enough, we can switch between the normal forms or λC andλCBV by using the ηE⇒. Oriented from left-to-right we go from λC to λCBV andconversely with the right-to-left orientation.

2 Call-by-value λµtp-calculus (λµtpCBV -calculus)

2.1 Confluence and standardization

Our calculus is not hard to extend with continuation variables and control oper-ators. We follow the approach of [12] and adopt Parigot’s µ operator [9] togetherwith a toplevel continuation constant tp, what simplifies the reasoning on closedcomputations and the connection with the λ-calculi based on callcc and A orFelleisen’s C operator. We write C[α← [β]E] for the generalization of Parigot’sstructural substitution and we abbreviate C[α← [β]([ ])] as C[α← β].

Since the reductions associated to µ absorb their context, structural rulesshould not change which subterm is in control, but happily structural rules areonly like E[T ] → E′[T ], so we cannot break confluence with them.

We must be careful with µ reductions however. If µ does not have any reduc-tion restrictions, let still can hide µ redexes. Therefore, we need a new structuralrule. The full calculus is given in Figure 3.

Proposition 9. The operational subsystem, its extension with structural rulesand the full system of reduction rules are all confluent in the λµtpCBV -calculus.

Proof. The proof is the same as before, using generalizations of the rules involv-ing µ and let and with the parallel reduction extended with the two followingrules:

– if M VM ′ then [α]M V [α]M ′

– if C V C ′ then µα.C V µα.C ′

Page 12: AnOperationalAccountofCall-By-Value MinimalandClassical ...pauillac.inria.fr/~herbelin/articles/tlca-HerZim09... · AnOperationalAccountofCall-By-Value MinimalandClassical -calculusin“Natural

Syntax

V ::= x | λx.M F ::= [ ]M | let x = [ ] in MM,N,P ::= V |MN | let x =M in N | µα.C E ::= [ ] | xE | F [E]C ::= [q]Mq ::= α | tp

Operational rules

(⇒) (λx.N)Mr−→ let x =M in N

(letv) let x = V in Nr−→ N [x← V ]

(µv) F [µα.C]r−→ µα.C[α← [α]F ]

(µbase) [q]µα.Cr−→ C[α← q]

Structural rules

(letlet) let z = (let x =M in N) in Pr−→ let x =M in (let z = N in P )

(letapp) (let x =M in N)Pr−→ let x =M in NP

(letµ) let x =M in µα.[β]Nr−→ µα[β].let x =M in N

Observational rules

(η⇒) λx.yxr−→ y

(ηElet) let x =M in E[x]r→ E[M ] if x 6∈ FV (E)

(ηµ) µα.[α]Mr−→ M if α not free in M

(letvar ) z(let x =M in N)r−→ let x =M in zN

(µvar ) z(µα.C)r−→ µα.C[α← [α](z[ ])]

Fig. 3. The full λµtpCBV -calculus

Note again the redundancy of (letvar ) and (µvar ) which are here for theconfluence.

As head reduction can be extended with the new rules, we obtain a notionof standardization for this calculus too.

The rule letµ is here to deal with hidden µ-redexes, obfuscated by a let. Asan example, the term (let x = yz in µα.[α]λx.x)t needs first to be reduced to(µα.[α]let x = yz in λx.x)t, then only the reduction between µα and [ ]t canoccur.

It is also interesting to see that being in call-by-value, we immediately dodgeany problems with David and Py’s critical pair [13]. The term λx.(µα.c)x onlyreduces to λx.(µα.c[α← [α][ ]x]), because of the η restriction to values.

We say that M evaluates to V in λµtpCBV if [tp]M reduces to [tp]V and wesay that a reduction relation → is operationally complete if whenever a closedM is not a value, [tp]M is reducible along → .

Page 13: AnOperationalAccountofCall-By-Value MinimalandClassical ...pauillac.inria.fr/~herbelin/articles/tlca-HerZim09... · AnOperationalAccountofCall-By-Value MinimalandClassical -calculusin“Natural

2.2 Normal forms

Not only do we keep the confluence, telling us that the extension is reasonable,but we also keep all the other good properties of the intuitionistic calculus. Thegrammar generating normal forms with respect to the operational and structuralrules, with T as an entry point, and the typing rules associated with the new µconstruction are given in Figure 4 (T is a global parameter of the type systemcorresponding to the type of tp and all rules are generalized with a context ∆on the right). Properties on the normal forms are preserved, as the propositionbelow says.

S ::= x | STQ ::= λx.T | S | let x = S in QT ::= Q | µα.[β]Q

Γ ` u : N | β :M,α : N,∆

Γ ` µβ.[α]u :M | α : N,∆

Γ ` u : T | β :M,∆

Γ ` µβ.[tp]u :M |∆

Fig. 4. Normal forms and new typing rules for the λµtpCBV -calculus

Proposition 10. The λµtpCBV -calculus equipped with its set of operationalrules is operationally complete and the λµtpCBV -calculus equipped with its setsof operational and structural rules is structurally complete.

If T is a term in normal form relatively to the operational and structural rulesof λµtpCBV -calculus and Γ ` T : A | ∆ then its proof satisfies the subformulaproperty.

Proof (Indication). The first point is direct by the same proof as for theintuitionistic case. The second point is solved by induction, with most of thecases not being changed.

2.3 Equational theory

In [3], Sabry and Felleisen devised an equational theory of call-by-value λ-calculus with control operators that is sound and complete with respect to call-by-value continuation-passing-style (cps) semantics. We recall only the part ofthe equations concerning the control operators below, because the other one isverified by Moggi’s calculus and so by λCBV .

(Ccurrent) callcc (λk.kM) = callcc (λkM)(Celim) callcc (λd.M) =M if d 6∈ FV (M)(Clift) E[callcc M ] = callcc (λk.E[M(λf.(kE[f ]))])

if k, f 6∈ FV (E,M)(Cabort) callcc (λk.C[E[kM ]]) = callcc (λk.C[kM ])

for C a term with a hole not binding k(Ctail) callcc (λk.((λz.M)N)) = λz.(callcc (λk.M))N if k 6∈ FV (N)(Abort) E[AM ] = AM

Page 14: AnOperationalAccountofCall-By-Value MinimalandClassical ...pauillac.inria.fr/~herbelin/articles/tlca-HerZim09... · AnOperationalAccountofCall-By-Value MinimalandClassical -calculusin“Natural

Because the language of the equations is not the same as ours, we need sometranslations: callcc and A are encoded by the terms (λx.µα.[α](x(λy.µδ.[α]y)))and λx.µδ.[tp]x while, conversely, we encode µα.[β]M by callcc (λkα.A(kβM)),µα.[tp]M by callcc (λkα.A(M)) and let x = N in M by (λx.M)N .

By unfolding the definitions and doing basic calculations, we obtain the equa-tional correspondence with the equations of Sabry and Felleisen. But instead ofonly having equations, we now have an oriented reduction system.

Proposition 11. There is an equational correspondence at the level of closedexpressions between λµtpCBV and Sabry and Felleisen’s axiomatization of λ-calculus with callcc and A.

Moreover, since we can equip λµtpCBV with a cps-semantics that matchesthe one considered in Sabry and Felleisen as soon as µα.c is interpreted byλkα.c, [α]M by Mkα and [tp]M by Mλx.x, we can transfer Sabry and Felleisencompleteness result to the full theory of λµtpCBV .

Corollary 1. The full calculus λµtpCBV is sound and complete with respect toβη along its cps-semantics.

Since tp has a passive role in the reduction system of λµtpCBV , the confluenceof the different subsystems and the structural and cps completenesses also holdfor λµCBV which is λµtpCBV without tp.

Summary

We studied the equational theory of call-by-value λ-calculus and λµ-calculusfrom a reduction point of view and provided what seems to be the first confluentrewrite systems for λµ-calculus with control that is complete with respect to thecontinuation-passing-style semantics of call-by-value λ-calculus.

The rewrite system we designed is made of three independent blocks thatrespectively address operational completeness (ability to evaluate closed terms),structural completeness (ability to contract hidden redexes in open terms) andpurely observational properties.

The notion of structural completeness is related to the ability to enforce thesubformula property in simply-typed λ-calculus but we failed to find a purelycomputational notion that universally captures the subformula property. Forinstance, any call-by-value reduction system that does not use a let and doesnot smash abstraction and application from redexes of the form (λx.M)(yz)cannot be accompanied with a typing system whose normal forms type derivationsatisfies the subformula property.

It would have been desirable to characterize the block of observational rulesas a block of rules providing observational completeness, in a way similar tothe call-by-name control-free case where β provides operational completenessand η provides observational completeness. Obtaining such a result would how-ever require a Böhm-style separability result for call-by-value λ-calculus andλµ-calculus, what goes beyond the scope of this study.

Page 15: AnOperationalAccountofCall-By-Value MinimalandClassical ...pauillac.inria.fr/~herbelin/articles/tlca-HerZim09... · AnOperationalAccountofCall-By-Value MinimalandClassical -calculusin“Natural

Regarding intuitionistic call-by-value λ-calculus we slightly refined Moggi andSabry and Felleisen rewrite systems by precisely identifying which rules pertainto the operational block, the structural block or the observational block.

Finally, we proposed a new definition of standard reduction sequences forcall-by-value λ-calculus that ensures the uniqueness of standard reduction pathsbetween two terms (when such a path exists).

References

1. Plotkin, G.D.: Call-by-name, call-by-value and the lambda-calculus. Theor. Com-put. Sci. 1 (1975) 125–159

2. Moggi, E.: Computational lambda-calculus and monads. Technical Report ECS-LFCS-88-66, Edinburgh Univ. (1988)

3. Sabry, A., Felleisen, M.: Reasoning about programs in continuation-passing style.Lisp and Symbolic Computation 6(3-4) (1993) 289–360

4. Hofmann, M.: Sound and complete axiomatisations of call-by-value control oper-ators. Mathematical Structures in Computer Science 5(4) (1995) 461–482

5. Dezani-Ciancaglini, M., Giovannetti, E.: From Böhm’s theorem to observationalequivalences: an informal account. Electr. Notes Theor. Comput. Sci. 50(2) (2001)

6. Curien, P.L., Herbelin, H.: The duality of computation. In: Proceedings of ICFP2000. SIGPLAN Notices 35(9), ACM (2000) 233–243

7. Herbelin, H.: C’est maintenant qu’on calcule: au cœur de la dualité. Habilitationthesis, University Paris 11 (December 2005)

8. Gentzen, G.: Untersuchungen über das logische Schließen. MathematischeZeitschrift 39 (1935) 176–210,405–431 English Translation in The Collected Worksof Gerhard Gentzen, Szabo, M. E. editor, pages 68-131.

9. Parigot, M.: Lambda-mu-calculus: An algorithmic interpretation of classical natu-ral deduction. In: International Conference LPAR ’92 Proceedings, St. Petersburg,Russia, Springer-Verlag (1992) 190–201

10. Regnier, L.: Une équivalence sur les lambda-termes. Theor. Comput. Sci. 126(2)(1994) 281–292

11. Sabry, A., Wadler, P.: A reflection on call-by-value. ACM Trans. Program. Lang.Syst. 19(6) (1997) 916–941

12. Ariola, Z.M., Herbelin, H.: Control reduction theories: the benefit of structuralsubstitution. Journal of Functional Programming 18(3) (May 2008) 373–419 witha historical note by Matthias Felleisen.

13. David, R., Py, W.: Lambda-mu-calculus and Böhm’s theorem. J. Symb. Log. 66(1)(2001) 407–413