Polarised Intermediate Representation of Lambda - Gallium
Transcription
Polarised Intermediate Representation of Lambda - Gallium
1 Polarised Intermediate Representation of Lambda Calculus with Sums Guillaume Munch-Maccagnoni Gabriel Scherer University of Cambridge Inria Paris-Rocquencourt AbstractβManipulating π-terms with extensional sums is harder than with only pairs and functions. Following recent and less recent developments in proof theory, we propose an untyped representationβan intermediate calculusβfor the π-calculus with sums, based on the following principles: 1) Computation is described as the reduction of pairs of an expression and a context; the context is represented inside-out, 2) Operations are represented abstractly by their transition rule, 3) Positive and negative expressions are respectively eager and lazy; this polarity is an approximation of the type. We explain the approach from the ground up, and we review the beneο¬ts. A structure of alternating phases naturally emerges through the study of normal forms, oο¬ering a reconstruction of focusing. Considering further purity assumption, we obtain maximal multifocusing. As an application, we can deduce an algorithm to decide the equivalence of normal forms in the simply-typed π-calculus with sums, and justify it with our intermediate calculus. I. Introduction The rewriting theory of π-terms in the presence of extensional sums is sensibly more complex than with pairs and functions alone. Witness the diversity of approaches to decide the π½π-equivalence in the simply-typed π-calculus with sums, proposed since 1995: based either on a non-immediate rewriting theory (Ghani [21]; Lindley [38]) or on normalisation by evaluation (Altenkirch, Dybjer, Hofmann and Scott [3]; Balat, di Cosmo and Fiore [6]). (In Figure 1 we recall the simply-typed π-calculus with sums in equational form, see e.g. [19, 38].) But, on the side of proof theory, sums become as simple as products once cast into Gentzenβs sequent calculus [20], perhaps because sequent calculus has an inherent symmetry that reο¬ects the categorical duality between sums and products. For instance, commutations (Figure 2) are not needed (see e.g. Girard [25]). A. Abstract-machine-like calculi Term syntaxes can beneο¬t from the symmetry of sequent calculus at the condition of following certain principles, among which treating seriously the duality between expressions and contexts, as discovered with Curien and Herbelinβs abstractmachine-like calculi [11]. These calculi evidence a correspondence between sequent calculus (Gentzen [20]), abstract machines (Landin [32, 33]) and continuation-passing style (Van Wijngaarden [53]). In particular they illustrate the links that continuation-passing style has with categorical duality April 2015. π‘, π’, π£ β©΄ π₯ | ππ₯.π‘ | π‘ π’ | <π‘; π’> | π1 (π‘) | π2 (π‘) | π1 (π‘) | π2 (π‘) | πΏ(π‘, π₯.π’, π¦.π£) π΄, π΅ β©΄ π | π΄ β π΅ | π΄ × π΅ | π΄ + π΅ (a) Terms and types Ξ β’ π‘ βΆ π΄π β Ξ β’ ππ (π‘) βΆ π΄1 + π΄2 β Ξ, π₯ βΆ π΄ β’ π₯ βΆ π΄ π β {1, 2} Ξ β’ π‘ βΆ π΄ 1 + π΄2 Ξ, π₯π βΆ π΄π β’ π’π βΆ π΅ (βπβ{1,2}) β Ξ β’ πΏ(π‘, π₯1 .π’1 , π₯2 .π’2 ) βΆ π΅ Ξ β’π‘βΆπ΄ Ξ β’π’βΆπ΅ β Ξ β’ <π‘; π’> βΆ π΄ × π΅ Ξ, π₯ βΆ π΄ β’ π‘ βΆ π΅ β Ξ β’ ππ₯.π‘ βΆ π΄ β π΅ Ξ β’ π‘ βΆ π΄1 × π΄ 2 β Ξ β’ ππ (π‘) βΆ π΄π π β {1, 2} Ξ β’π‘βΆπ΄βπ΅ Ξ β’π’βΆπ΄ β Ξ β’ π‘π’ βΆ π΅ (b) Typing rules (ππ₯.π‘) π’ β π‘[π’/π₯] ππ (<π‘1 ; π‘2 >) β π‘π πΏ(ππ (π‘), π₯1 .π’1 , π₯2 .π’2 ) β π’π [π‘/π₯π ] (c) π½-reductions π‘ β ππ₯.(π‘ π₯) π‘ β <π1 (π‘); π2 (π‘)> π’[π‘/π¦] β πΏ(π‘, π₯1 .π’[π1 (π₯1 )/π¦], π₯2 .π’[π2 (π₯2 )/π¦]) (d) π-expansions β Figure 1: π-calculus with sums (Filinski [18]; Thielecke [52]; Selinger [49]) and with abstract machines (Reus and Streicher [51]; Ager, Biernacki, Danvy, and Midtgaard [2]; Danvy and Millikin [14]). CurienHerbelinβs calculi are however set in classical logic and include variants of Schemeβs call/cc control operator. There are now abstract-machine-like calculi, with various applications, by various authors, that are based on the same technique [11, 54, 30, 5, 39, 12, 41, 43, 7, 17, 42, 50]. The ο¬rst goal of the article is to adapt the technique to the π-calculus with sums. (In this article we refer to this new calculus as Lint .) We remove the full power of call/cc following an idea of Herbelin [30]. In doing this adaptation, we ο¬rst advocate in Section II that the abstract-machine-like calculi can be summarised via two principles: the inside-out representation of contexts is primitive, and: language constructs are the abstract solutions of equations given by their machine transitions. These principles lead us to a ο¬rst calculus in call-by-name . referred to in this article as Lβ int Following the latter idea, not all the constructs of the π-calculus with sums are given as primitives of Lint . But, an axiom but as an external property, similar in status to normalisation. The polarised calculus Lint is introduced in Section III, and it is a polarised abstract-machine-like calculus consistent with Girardβs [23, 26, Section 12.B] and Liang and Millerβs [37] suggestions for a polarised intuitionistic logic. Lint also determines an intuitionistic variant of Danos, Joinet and Schellinxβs π LKπ [13]. It is also meant to be a direct language for (variants of) Levyβs Call-by-push-value models [35, 36], though a precise correspondence will be the subject of another work. In the article, we follow Curryβs style: the terms are not annotated by their types. The polarity is therefore also the least amount of information that has to be added to the calculus so that the evaluation order is uniquely determined, before any reference is made to the types. (We follow the same technique as appeared previously in M.-M. [39, 43, 42].) (ππ₯.π‘) π’ β» π‘[π’/π₯] ππ (<π‘1 ; π‘2 >) β» π‘π πΏ(ππ (π‘), π₯1 .π’1 , π₯2 .π’2 ) β» π’π [π‘/π₯π ] (a) Main reductions πΏ(π‘, π₯1 .π’1 , π₯2 .π’2 ) π£ β» πΏ(π‘, π₯1 .(π’1 π£), π₯2 .(π’2 π£)) ππ (πΏ(π‘, π₯1 .π’1 , π₯2 .π’2 )) β» πΏ(π‘, π₯1 .ππ (π’1 ), π₯2 .ππ (π’2 )) πΏπ£ (πΏ(π‘, π₯1 .π’1 , π₯2 .π’2 )) β» πΏ(π‘, π₯1 .πΏπ£ (π’1 ), π₯2 .πΏπ£ (π’2 )) where πΏπ£ (π‘) = πΏ(π‘, π¦1 .π£1 , π¦2 .π£2 ). (b) Commutations β Figure 2: Reduction relation for the π-calculus with sums they are all retrieved in a methodical way, as we will see. Therefore we advocate that abstract-machine-like calculi should be seen as intermediate calculi that reveal the hidden structure of the termsβan analogy with intermediate representations used by compilers, which enable program transformation and analysis. In fact, our principles synthesise (and inherit from) continuation-passing style, defunctionalisation and direct style, as we will see. C. Focusing and untyped normal forms Focalisation is formulated as the phenomenon by which certain introduction rules hide cuts, as a consequence of polarisation. Thus we formulate focalisation as a restriction on the normalisation of proofs rather than on the structure of the proofs. From our point of view, focused proofs are retrieved through the study of normal forms. Section IV shows that normal forms have a syntactic structure of alternating phases of constructors and abstractors. This indeed corresponds to focused proof disciplines (Andreoli [4]): in contrast with the lambda-calculus, Lint would systematically use invertible rules for each connectiveβs abstractor, with noninvertible rules only on constructors. We build an π-equivalence algorithm which is not type-directed, but inspects the syntactic structure of normal forms, adapting existing techniques (Abel and Coquand [10, 1]). Variable and co-variable scoping fully determines independence of neighbouring phases: if reordering two fragments of a normal form does not break any variable binding, it should be semantically correct. This is immediate for abstractor phases (which corresponds to the easy permutations of invertible steps), yet requires explicit purity assumptions for constructor phases, related to the associativity of composition. Rewriting phases according to their dependencies corresponds to the idea of maximal multi-focusing [9, 8], a canonical representation of focused derivations. We give a fairly uniform, syntactic deο¬nition of canonical forms as normal forms of phase-permuting and phase-merging rewriting relations. In particular, π½π-equivalence of typed π-terms with sums can be decided by comparing the untyped normal forms. B. Intuitionistic polarisation Recall that in the presence of ο¬xed points and extensional sums, any two π-terms of the same type are equivalent, by a diagonal argument involving the ο¬xed point of the function ππ₯.πΏ(π₯, π¦.π2 (π¦), π¦.π1 (π¦)) [34, 31, 16]. As a consequence, the calculus from Figure 1 cannot be considered untyped. Polarisation, introduced by Girard for classical logic [22], is a well-studied mean to circumvent a similar degeneracy that strikes Cartesian-closed categories in the presence of an π΄ isomorphism π΄ β π π natural in π΄βby not requiring all the axioms of a category in the ο¬rst place. In fact, polarisation relaxes the hypothesis that composition is associative, in a meaningful way that admits a positive characterisation with duploids [41, 43]. For our current matters, polarisation corresponds to the hypothesis that: an expression is either positive or negative depending on the type; this polarity determines whether it reduces strictly or lazily. We can assume that such polarities are involved in the validity of π-expansions in the π-calculus with sums. Indeed, according to Danos, Joinet and Schellinx [13] (although in the context of classical sequent calculus), connectives can be distinguished upon whether the π-expansion seems to force or to delay the reduction. For instance, expanding π’[π‘/π¦] into πΏ(π‘, π₯1 .π’[π1 (π₯1 )/π¦], π₯2 .π’[ π2 (π₯2 )/π¦ ]) forces the evaluation of π‘. They show (with π LKπ ) how by making the reduction match, for each connective, the behaviour thus dictated by possible π-expansions, one essentially ο¬nds back polarisation in the sense of Girard. This is why declaring sums positive (strict) and functions negative (lazy) ensures that π-expansions do not modify the evaluation order. Polarities only matter when call by value and call by name diο¬er. In the context of the pure π-calculus, only nontermination can discriminate call by value from call by name. Polarisation therefore suggests a novel approach to typed πcalculi where associativity of composition is not seen as D. Notations In the grammars that we deο¬ne, a dot indicates that variables before it are bound in what comes after. (For instance with π(π₯β β).π, the variables π₯ and β are bound in π.) If β³ is a rewriting relation, then the compatible closure of β³ is denoted by β and the compatible equivalence relation (β βͺ β)β is denoted with β. Reductions are denoted with β³R and expansions with β³E . In this context we deο¬ne β³RE β β³R βͺ β³E . 2 E. Acknowledgements In other words, adjoint reductions state that the destructive operations of π-calculus are, by analogy with linear algebra, adjoint to the constructions on contexts (Girard [24]). As a consequence, they build the context inside-out, as in our example: The sections II and III are adapted from the ο¬rst authorβs PhD thesis [41, Chapter I]βmany thanks to Pierre-Évariste Dagand and Olivier Danvy for their criticisms and suggestions. The authors would like to thank the anonymous reviewers for their comments. The ο¬rst author gratefully acknowledges partial support from the ERC project Ecsym and from the French National Research Agency (ANR-12-JS02-006-01, ANR-10BLAN-0213, ANR-11-BS02-0010). β¨πΏ((ππ₯.π1 (π‘)) π’, π¦.π£, π§.π€) β ββ© β³R β¨(ππ₯.π1 (π‘)) π’ β [π¦.π£|π§.π€]β ββ© β³R β¨ππ₯.π1 (π‘) β π’β [π¦.π£|π§.π€]β ββ© β³R β¨π1 (π‘[π’/π₯]) β [π¦.π£|π§.π€]β ββ© β³R β¨π£[π‘[π’/π₯]/π¦] β ββ© II. A Principled Introduction to Abstract-Machine-Like Calculi In this section we explain the principles behind abstractmachine-like calculi and review their advantages in relationship to the study of π-calculus with sums. We leave expansions aside until Section III. This exposition complements Wadlerβs introduction to term assignments for Gentzenβs classical sequent calculus LK [54], Curien and the ο¬rst authorβs reconstruction of LK from abstract machines [12], and Spiwakβs motivation of abstract-machine-like calculi for the programming language theory [50]. In this example, the context π’β [π¦.π£|π§.π€]β β corresponds to the expression with a hole πΏ(β‘ π’, π¦.π£, π§.π€) read from the inside to the outside. B. Solving equations for expressions We would like to relate the evaluation of terms to their normalisation. Notice that the reductions from Figure 1c are not enough to normalize a term such as πΏ(π₯, π¦1 .ππ§.π‘, π¦2 .ππ§.π’) π§. Commutation rules (Figure 2), coming from natural deduction in logic, are necessary to obtain the simpler form πΏ(π₯, π¦1 .π‘, π¦2 .π’). A distinct solution, as we are going to see, is to represent the various constructs of the abstract machine abstractlyβas the solutions to the equations given by their transition rules. Let us explain this latter idea. Let us rephrase reductions (1) and (2) as mappings from stacks to commands: A. Abstract machines Abstract machines are deο¬ned by a grammar of expressions π‘, a grammar of contexts π, and rewriting rules on pairs π = β¨π‘ β πβ© (commands). A command β¨ π‘ β π β© represents the computation of π‘ in the context π. Intuitively, contexts correspond to expressions with a hole: a distinguished variable β‘ that appears exactly once. For instance, the following extension of the Krivine abstract machine decomposes a term such as πΏ((ππ₯.π1 (π‘)) π’, π¦.π£, π§.π€) into the context πΏ(β‘, π¦.π£, π§.π€) and the redex (ππ₯.π1 (π‘)) π’. The abstract machine therefore determines an evaluation strategyβhere, call by nameβfor reductions in Figure 1c. The contexts are for now stacks π of the following form: π‘ π’ βΆ π β¦ β¨π‘ β π’β πβ© As explained by Curien and the ο¬rst author [12], one can βreadβ deο¬nitions oο¬ these mappings. A binder π is introduced for the purpose: π‘ π’ β πβ.β¨π‘ β π’β ββ© β¨πβ.π β πβ© β³R π[π /β] The symbol β represents the empty context. The reduction relation β³R on commands is deο¬ned by two sets of reduction rules: β’ Main reductions: Variables are substituted, pairs are projected and branches are selected: In fact, any equation of the form (3), assuming that π is substitutive, can be solved in this way: π β (π‘) β πβ.β¨π‘ β π (β)β© Let us pause on the idea of solving equations. This improved wording has two purposes: β’ Emphasise the conscious step taken, to underline that abstract-machine-like calculi do not serve as replacements for π-calculiβone still has to determine which equations are interesting to consider. β’ Making us comfortable with the fact that, later in Section III, there may be two solutions, depending on the polarity. The empty context β is now a context variable (or covariable) bound in πβ.π and is the only one that can be bound by π. (Originally, the notation π comes from Parigotβs ππcalculus [45], where diο¬erent co-variables name the diο¬erent conclusions of a classical sequent. The idea of restricting to a single co-variable for modelling intuitionistic sequents with one conclusion is due to Herbelin [30].) β¨ππ₯.π‘ β π’β πβ© β³R β¨π‘[π’/π₯] β πβ© β¨<π‘1 ; π‘2 > β ππ β πβ© β³R β¨π‘π β πβ© β¨ππ (π‘) β [π₯1 .π’1 |π₯2 .π’2 ]β πβ© β³R β¨π’π [π‘/π₯π ] β πβ© Adjoint reductions: Function applications, projections and branching build up the context. β¨π‘ π’ β πβ© β³R β¨π‘ β π’β πβ© (1) β¨ππ (π’) β πβ© β³R β¨π’ β ππ β πβ© β¨πΏ(π‘, π₯.π’, π¦.π£) β πβ© β³R β¨π‘ β [π₯.π’|π¦.π£]β πβ© (2) Notice that these reductions deο¬ne β³R as a deterministic relation: if π β³R π β² and π β³R π β³ then π β² = π β³ . The reductions that we call adjoint are all of the form: β¨π β (π‘) β πβ© β³R β¨π‘ β π (π)β© πΏ(π‘, π₯.π’, π¦.π£) β πβ.β¨π‘ β [π₯.π’|π¦.π£]β ββ© In words, destructors are represented abstractly by their transition rule in the machine. The expression πβ.π maps stacks to commands thanks to the following reduction rule: (π =) π β©΄ β | π’β π | π1 β π | π2 β π | [π₯.π’|π¦.π£]β π β’ πΏ(π‘, π₯.π’, π¦.π£) βΆ π β¦ β¨π‘ β [π₯.π’|π¦.π£]β πβ© (3) 3 π‘, π’, π£ β©΄ π₯ | ππ (π‘) | πβ.π | π(π₯β β).π | π<β.π1 ; β.π2 > (π =) π β©΄ β | π’β π | ππ β π | [π₯.π’|π¦.π£]β π π β©΄ β¨π‘ β πβ© π β {1, 2} β¨πβ.π β πβ© β¨π(π₯β β).π β π‘β πβ© β¨π<β.π1 ; β.π2 > β ππ β πβ© β¨ππ (π‘) β [π₯1 .π’1 |π₯2 .π’2 ]β πβ© (a) Expressions, contexts, and commands β³R β³R β³R β³R π[π /β] π[π‘/π₯, π /β] ππ [π/β] β¨π’π [π‘/π₯] β πβ© (b) Reductions ππ₯.π‘ β π(π₯β β).β¨π‘ β ββ© π‘π’ β πβ.β¨π‘ β π’β ββ© <π‘; π’> β π<β.β¨π‘ β ββ©; β.β¨π’ β ββ©> ππ (π‘) β πβ.β¨π‘ β ππ β ββ© πΏ(π‘, π₯.π’, π¦.π£) β πβ.β¨π‘ β [π₯.π’|π¦.π£]β ββ© (c) Embedding the π-calculus with sums Ξ β’π‘βΆπ΄ , Ξβ£πβΆπ΄ β’Ξ , where Ξ = β βΆ π΅ β¨π‘ β πβ© βΆ (Ξ β’ Ξ) (d) Judgements β Ξ, π₯ βΆ π΄ β’ π₯ βΆ π΄ Ξ β’ π‘ βΆ π΄π β Ξ β’ ππ (π‘) βΆ π΄1 + π΄2 π β {1, 2} π βΆ (Ξ β’ β βΆ π΄) β Ξ β’ πβ.π βΆ π΄ β Ξβ£ββΆπ΄ β’ββΆπ΄ π βΆ (Ξ β’ β βΆ π΄) π β² βΆ (Ξ β’ β βΆ π΅) β Ξ β’ π<β.π ; β.π β² > βΆ π΄ × π΅ Ξ β’π‘βΆπ΄ Ξβ£πβΆπ΄ β’Ξ β β¨π‘ β πβ© βΆ (Ξ β’ Ξ) Ξ β£ π βΆ π΄π β’ Ξ β Ξ β£ ππ β π βΆ π΄1 × π΄2 β’ Ξ π βΆ (Ξ, π₯ βΆ π΄ β’ β βΆ π΅) β Ξ β’ π(π₯β β).π βΆ π΄ β π΅ Ξβ£π βΆπΆ β’Ξ Ξ, π₯π βΆ π΄π β’ π‘π βΆ πΆ (βπβ{1,2}) β Ξ β£ [π₯1 .π‘1 |π₯2 .π‘2 ]β π βΆ π΄1 + π΄2 β’ Ξ π β {1, 2} Ξ β’π‘βΆπ΄ Ξβ£π βΆπ΅ β’Ξ β Ξ β£ π‘β π βΆ π΄ β π΅ β’ Ξ (e) Typing of machines in Gentzenβs sequent calculus (wrong) β Figure 3: A ο¬rst abstract-machine-like calculus with sums C. Compatible reduction and its conο¬uence The category π is no longer restricted to occur at the top level: commands now have sub-commands. Therefore we can deο¬ne the compatible closure βR of β³R in an immediate way: one has π βR π (for π an expression, context, or command) whenever π is obtained from π by applying β³R on one of its sub-commands (possibly itself). To relate this notion of compatible closure to the one of π-calculus, we however need a closure property similar to the following one: if β¨π‘ β ββ© ββR β¨π‘β² β ββ© then β¨ππ₯.π‘ β ββ© ββR β¨ππ₯.π‘β² β ββ© D. Typing of machines The typing of abstract-machine-like calculi in Gentzenβs sequent calculus is standard. (See Wadler [54], Curien and M.M. [12], for introductions.) We introduce the type system for the calculus considered so far in Figure 3e. The correspondence with sequent calculus is not obtained yet: 1) Left-introduction rules cannot be performed on arbitrary formulae; they stack. 2) The rule for [ π₯.π’ | π¦.π£ ]β π is still the one from natural deduction. (4) The solution is again to introduce an abstract notation for π by solving the corresponding transition rule: E. Solving equations for contexts ππ₯.π‘ βΆ π’β π β¦ β¨π‘[π’/π₯] β πβ© ππ₯.π‘ β π(π₯β β).β¨π‘ β ββ© (β β fv(π‘)) (5) The calculus in Figure 3 still fails to normalize terms without using commutations, for instance in the following: Thus we extend π to match patterns on stacks: β¨π(π₯β β).π β π‘β πβ© β³R π[π‘/π₯, π /β] β¨πΏ(π₯, π¦1 .ππ§.π‘, π¦2 .ππ§.π’) π§ β ββ© β³βR β¨π₯ β [π¦1 .ππ§.π‘|π¦2 .ππ§.π‘]β π§β ββ© Thanks to the abstract deο¬nition of π, our streamlined deο¬nition of compatible closure implies the clause (4): The commutation on expressions is only rephrased as a similar commutation on contexts. Once again, let us describe the context [π₯.π’|π¦.π£]β π as a pair of mappings: if β¨π‘ β ββ© ββR β¨π‘β² β ββ© then π(π₯β β).β¨π‘ β ββ© ββR π(π₯β β).β¨π‘β² β ββ© For the same reason, pairs <π‘; π’> are represented abstractly as a pair of transition rules: <π‘; π’> βΆ π1 β π β¦ β¨π‘ β πβ© , π1 (π₯) β¦ β¨π’ β πβ© π2 β π β¦ β¨π’ β πβ© , π2 (π¦) β¦ β¨π£ β πβ© This suggests that the branching context can be written abstractly, by introducing a new binder π:Μ <π‘; π’> β π<β.β¨π‘ β ββ©; β.β¨π’ β ββ©> We summarise in Figure 3 the calculus that we obtain so far by adding π to the abstract machine and by removing the constructs that can be deο¬ned. It is easy to notice that one has for all π‘, π, π: β β fv(π) and β β fv(π) but β β fv(π‘). In particular the proviso in (5) is always satisο¬ed. Thanks to the separation between expressions, contexts and commands, we have a reduction β³R which is left-linear and has no critical pair. As a consequence, βR is conο¬uent, by application of Tait and Martin-Löfβs parallel reduction technique (see for instance Nipkow [44]). This argument will hold for all the abstract-machine-like calculi of the article. [π₯.π’|π¦.π£]β π = πΜ[π₯.β¨π’ β πβ©|π¦.β¨π£ β πβ©] (6) The stack π[π₯ Μ 1 .π1 |π₯2 .π2 ] is symmetric in shape to the constructor for pairs, and associates to any injection ππ the appropriate command π1 or π2 : Μ 1 .π1 |π₯2 .π2 ]β© β³R ππ [π‘/π₯π ] β¨ππ (π‘) β π[π₯ (βπ β {1, 2}) In fact, we only consider the contexts [π₯.π’ | π¦.π£]β β in the deο¬nition of branching: πΏ(π‘, π₯.π’, π¦.π£) β πβ.β¨π‘ β πΜ[π₯.β¨π’ β ββ©|π¦.β¨π£ β ββ©]β© While π was duplicated in (6), this deο¬nition is local. 4 (7) Lβ int consists in Figure 3 extended as follows: |π¦.π β² ] π β©΄ β¦ | π[π₯.π Μ π β©΄ π | ππ₯.π Μ β¨π‘ β ππ₯.πβ© Μ β³R π[π‘/π₯] β¨ππ (π‘) β π[π₯ Μ 1 .π1 |π₯2 .π2 ]β© β³R ππ [π‘/π₯π ] [π₯.π‘|π¦.π’]β π is removed from the grammar [π₯.π‘|π¦.π’]β β β πΜ[π₯.β¨π’ β ββ©|π¦.β¨π£ β ββ©] (a) Stacks and contexts (b) New reductions (c) Deο¬nition of branching π βΆ (Ξ, π₯ βΆ π΄ β’ Ξ) β Ξ β£ ππ₯.π Μ βΆπ΄ β’Ξ π βΆ (Ξ, π₯ βΆ π΄ β’ Ξ) π β² βΆ (Ξ, π¦ βΆ π΅ β’ Ξ) β |π¦.π β² ] βΆ π΄ + π΅ β’ Ξ Ξ β£ π[π₯.π Μ Ξ β’π‘βΆπ΄ Ξβ£πβΆπ΅ β’Ξ β β Ξ β£ π‘β π βΆ π΄ β π΅ β’ Ξ (d) New rules Ξβ£πβΆπ΄ β’Ξ β β Ξ β£ π1 β π βΆ π΄ × π΅ β’ Ξ (e) Admissible rules β Figure 4: The calculus Lβ int We may as well consider the context ππ₯.π Μ which can be used to represent an arbitrary mapping from expressions to commands: on arbitrary formulaeβin particular, contexts π’β π and ππ β π corresponding to unrestricted left-introduction rules (Figure 4e) can be deο¬ned, using π,Μ as the solutions to the following equations: β¨π‘ β ππ₯.πβ© Μ β³R π[π‘/π₯] It is easy to see that a context ππ₯. Μ β¨π’ β ββ© behaves like the expression with a hole (ππ₯.π’) β‘. Now, the existence of the command β¨πβ.π β ππ₯.π Μ β² β© shows that we cannot consider the context ππ₯.π Μ among the grammar of stacks π, since we do not want to introduce a critical pair in the reduction β³R . Therefore we now make the contexts π a strict superset of the stacks πβ we arrive at Curien and Herbelinβs characterisation of call by name [11]. |π¦.π β² ] belongs to the syntactic category π Notice that π[π₯.π Μ of stacks. (It no longer describes stacks per se, but any context against which the π reduces.) We may criticise the call-byname bias for the ο¬rst time, for introducing this arbitrary difference between ππ₯.π Μ and π[π₯ Μ 1 .π1 |π₯2 .π2 ], while we motivated both in the same way. The calculus Lβ (Figure 4) summarises our development so int far. Since β³R is still without critical pairs, βR is still conο¬uent. β¨π‘ β π’β πβ© β³R β¨πβ.β¨π‘ β π’β ββ© β πβ© β¨π‘ β ππ β πβ© β³R β¨πβ.β¨π‘ β ππ β ββ© β πβ© The rules from Figure 4e are derivable modulo weakening of the premiss π, which is admissible in the standard way. (For simplicity we did not formulate Lβ in the multiplicative style int with explicit weakening, which would let us state directly that the unrestricted rules are derivable.) In words, unrestricted left-introduction rules in Lβ int hide cuts. We call focalisation this phenomenon by which certain introduction rules hide cuts. It is indeed responsible for the shape of synchronous phases in focusing. H. Inside-out contexts are primitive Every context π corresponds to a term with a hole Eπ [ ]. Thus, every command β¨π‘ β πβ© (or equivalently every expression πβ.β¨π‘ β πβ©) corresponds to a π-term Eπ [π‘]. We map commands to expressions as follows: F. Commutation rules are redundant The term πΏ(π₯, π¦1 .ππ§.π‘, π¦2 .ππ§.π’) π§ now reduces as follows: Eβ β‘ β β‘ Eππ β π β‘ β Eπ [ππ (β‘)] Eππ₯.β¨π‘ Eπ β π β‘ β Eπ [β‘ π ] Μ β πβ© β‘ β (ππ₯.Eπ [π‘]) β‘ EπΜ[π₯.β¨π‘ β πβ© | π¦.β¨π’ β πβ² β©] β‘ β πΏ(β‘, π₯.Eπ [π‘], π¦.Eπβ² [π’]) β¨πΏ(π₯, π¦1 .ππ§.π‘, π¦2 .ππ§.π’) π§ β πβ© β³R β¨πΏ(π₯, π¦1 .ππ§.π‘, π¦2 .ππ§.π’) β π§β πβ© β³R β¨π₯ β πΜ[π¦1 .β¨ππ§.π‘ β π§β πβ©|π¦2 .β¨ππ§.π’ β π§β πβ©]β© ββR β¨π₯ β πΜ[π¦1 .β¨π‘ β πβ©|π¦2 .β¨π’ β πβ©]β© In words, a command β¨π‘ β πβ© is converted into an expression by rewinding the adjoint reductions leading to π and by expressing πΜ as π or πΏ. The deο¬nition ensures that β‘ appears exactly once in Eπ [ ]βindeed an expression with a hole. Conversely, in the presence of π,Μ any expression with a hole πΈ[ ] can be represented as ππ₯. Μ β¨πΈ[π₯] β ββ© . Furthermore, the latter gets, after reduction, the canonical form that we expect. For instance, considering πΈ1 [ ] β (ππ₯.π‘) β‘ and πΈ2 [ ] β πΏ(β‘ π‘, π¦.π’, π§.π£), we have: In particular, β¨πΏ(π₯, π¦1 .ππ§.π‘, π¦2 .ππ§.π’) π§ β ββ© does not reduce into β¨πΏ(π₯, π¦1 .π‘, π¦2 .π’) β ββ© despite what commutation rules would prescribe. However, they have the following common reduct: β¨π₯ β πΜ[π¦1 .β¨π‘ β ββ©|π¦2 .β¨π’ β ββ©]β© The same happens with the two other commutation rules. In other words, commutation rules are redundant in Lβ int , and at the same time Lβ oο¬ers a novel reduction theory compared int to the π-calculus with sums and commutations. In particular, normalisation in the proof theoretic sense is obtained with the compatible closure (βR ) of evaluation (β³R ). β Μ ππ₯.β¨πΈ Μ β ββ© 1 [π₯] β ββ© βR ππ₯.β¨π‘ β ππ₯.β¨πΈ Μ Μ β¨π₯ β π‘β πΜ[π¦.β¨π’ β ββ©|π§.β¨π£ β ββ©]β© 2 [π₯] β ββ© βR ππ₯. where ππ₯.β¨π‘ Μ Μ Μ β ββ© and π‘β [ππ¦.β¨π’ β ββ©|ππ§.β¨π£ β ββ©] are the contexts that we can expect to obtain from (ππ₯.π‘) β‘ and πΏ(β‘ π‘, π¦.π’, π§.π£). In fact, provided that we reο¬ne the deο¬nition of abstraction as ππ₯.π‘ β π(π¦β β). β¨ π¦ β ππ₯.β¨π‘ Μ β ββ© β© (as suggested for instance in Espírito Santo [48]), one has for any context π: G. Focalisation Any proof in the propositional intuitionistic sequent calculus derivation. Indeed, the typing rule can be retrieved as an Lβ int for πΜ (Figure 4d) allows left-introduction rules to be performed β¨Eπ [π‘] β ββ© ββR β¨π‘ β πβ© 5 (It might matter for rewriting purposes that the reduction is actually a single parallel reduction step.) In this sense, contexts are equivalent to expressions with a hole. But we argue that inside-out contexts are more primitive. β’ When the reduction is directly deο¬ned on expressions πΈ[π‘], an external propertyβthe so-called unique context lemmaβ replaces the adjoint reductions in the role of reaching a main reduction. β’ Above, it is more diο¬cult to express inside-out contexts as expressions with a hole than the contrary, because it requires an external deο¬nition by induction. Inside-out contexts reveal intermediate steps in the reduction, which, once they are expressed as part of the formalism, render such external properties and deο¬nitions unnecessary. is equivalent to the standard π-expansion of sums: πΈ[π‘] βRE πΏ(π‘, π₯.πΈ[π1 (π₯)], π¦.πΈ[π2 (π¦)]) (8) In fact, the traditional π-expansions of sequent calculus suggests extensionality axioms that all have a regular shape: π‘ β³E π(π₯β β).β¨π‘ β π₯β ββ© π‘ β³E π<β.β¨π‘ β π1 β ββ©; β.β¨π‘ β π2 β ββ©> π β³E πΜ[π₯.β¨π1 (π₯) β πβ©|π¦.β¨π2 (π¦) β πβ©] (9) However, the degeneracy of π-calculus with extensional sums and ο¬xed points mentioned in Section I-B applies: in untyped Lβ , one has π‘ βRE π’ for any two expressions π‘ and π’ by an int immediate adaptation of Dougherty [16]. I. A parte: Defunctionalised CPS in direct style C. Positive sums The contexts ππ₯.π Μ are functional abstractions of the remainder of the computation, that is, per deο¬nition, continuations. In fact, abstract-machine-like calculi could alternatively be introduced as the continuity of continuation-passing-style semantics. Indeed, although inside-out contexts are considered in term calculi since Herbelinβs study of the intuitionistic sequent calculus [29], such an inverted representation appeared with continuations as early as Wand [55]. Moreover, Danvy and Nielsen [15] recognised in Wandβs technique an instance of Reynoldβs defunctionalisation [46]. They also mention the βisomorphismβ between expressions with a hole and inside-out contexts. In addition, Ager, Biernacki, Danvy, and Midtgaard [2] show how to obtain abstract machines from evaluators via CPS transformation, closure conversion, and defunctionalisation. Thus, in terms of continuation-passing style, abstractmachine-like calculi describe defunctionalised CPS, in direct style (in the sense that the encodings of π-calculi are local, like in Figure 3c). But it is novel to aο¬rm that the representation of contexts inside-out can and should be taken as primitive, since it is made possible by the idea of representing destructors abstractly, as the adjoints of context constructors. Positive sums, unlike the sums of Lβ , are called by value. A int diο¬erence is therefore introduced, among expressions, between values π (such as π1 (π₯)) and non-values (such as π‘ π’), as follows: β’ β¨π β ππ₯.πβ© Μ β³R π[π /π₯] β’ , The reduction of a non-value πβ.π (including π‘ π’) takes precedence over the one deο¬ned by the context; in other words every positive context is a stack. As a consequence, the equation (9) no longer converts an arbitrary context into a stack. In addition, it becomes equivalent to the following π-expansion for sums restricted to values: πΈ[π ] βRE πΏ(π , π₯.πΈ[π1 (π₯)], π¦.πΈ[π2 (π¦)]) Thus, when sums are positive, (as observed for the classical sequent calculus [13],) the extensionality axiom does not interfere with the order of evaluation. D. The polarised calculus Lint Lint is a polarised variant of Lβ introduced in Figure 5. In int addition to the negative connectives β, × it proposes positive pairs and sums (β, +). a) Polarisation as a locally-determined strategy: Polarisation, unlike the call-by-value evaluation strategy, assigns a strict evaluation to sums without changing the evaluation . The evaluation order order of the other connectives of Lβ int is determined at the level of each command by a polarity π β {β, +} assigned to every expression and every context, impacting the reduction rules as follows: III. Polarisation and Extensional Sums A. Conversions on expressions vs. on commands In this section, we consider extensionality principles formulated as expansions β³E deο¬ned, unlike β³R , on expressions and on contexts. The following expansions are standard: π‘ β³E πβ.β¨π‘ β ββ© The reduction of πΜ is restricted to values: π β³E ππ₯.β¨π₯ Μ β πβ© (π₯ β fv(π)) They enunciate that one has π‘ βRE π’ if and only if for all π, β¨π‘ β πβ© βRE β¨π’ β πβ© (and symmetrically for contexts): there is only one notion of equivalence which coincides between expressions, contexts and commands. B. Extensionality for sums with a regular shape Converting, as described in Section II-H, contexts π into expressions with a hole πΈ[ ] (and conversely) shows that the following: Negative polarity Every expression is a value (CBN) Positive polarity Every context is a stack (CBV) Polarities in this sense are similar to Danos, Joinet and Schellinxβs [13] βπ‘/πβ annotations on the classical sequent calculusβLint in fact determines an intuitionistic variant of π their polarised classical logic LKπ . π βRE πΜ[π₯.β¨π1 (π₯) β πβ©|π¦.β¨π2 (π¦) β πβ©] 6 β¦ : Main additions to Figure 4 πβ©΄β|+ π‘, π’ (a) Polarities Refer to the subscript/superscript convention in Section III-D π‘β , π’β β©΄ π₯β | π ββ.π | π(π₯π β β).π | π<β.π ; β.π β² > { π‘+ , π’+ β©΄ π₯+ | (π , π ) | ππ (π ) | π+β.π πβ β©΄ β | π β π | ππ β π | ππ₯ Μ β.π π { π β©΄ β | ππ₯ Μ +.π | π(π₯ Μ π1 , π¦π2 ).π | π[π₯ Μ π1.π |π¦π2.π] + π , π β©΄ π₯+ | (π , π ) | ππ (π ) | π‘β π β©΄ β¨π‘ β πβ© π β©΄ β | π β π | ππ β π | π+ (c) Expressions and values (b) Commands (d) Contexts and stacks β π΄, π΅ π΄β , π΅β β©΄ π β | π΄ β π΅ | π΄ × π΅ { π΄+ , π΅+ β©΄ π+ | π΄ β π΅ | π΄ + π΅ β Ξ, π₯ βΆ π΄ β’ π₯ βΆ π΄ β Ξβ£ββΆπ΄ β’ββΆπ΄ π₯ βΆ π΄ stands for π₯π βΆ π΄π π βΆ (Ξ, π₯ βΆ π΄ β’ Ξ) β Ξ β£ ππ₯.π Μ βΆπ΄ β’Ξ π βΆ (Ξ β’ β βΆ π΄π ) β Ξ β’ π π β.π βΆ π΄π (e) Types Ξ β’π‘βΆπ΄ Ξβ£πβΆπ΄ β’Ξ β β¨π‘ β πβ© βΆ (Ξ β’ Ξ) (f) Identity π βΆ (Ξ, π₯ βΆ π΄ β’ β βΆ π΅) β Ξ β’ π(π₯β β).π βΆ π΄ β π΅ ππ βΆ (Ξ β’ β βΆ π΄π ) (βπβ{1,2}) β Ξ β’ π<β.π1 ; β.π2 > βΆ π΄1 × π΄2 Ξ β’π βΆπ΄ Ξ β’π βΆπ΅ β Ξ β’ (π , π ) βΆ π΄ β π΅ Ξ β’ π βΆ π΄π β Ξ β’ ππ (π ) βΆ π΄1 + π΄2 Ξ β’π βΆπ΄ Ξβ£π βΆπ΅ β’Ξ β Ξ β£ π β π βΆ π΄ β π΅ β’ Ξ Ξ β£ π βΆ π΄π β’ Ξ β Ξ β£ ππ β π βΆ π΄1 × π΄2 β’ Ξ π βΆ (Ξ, π₯ βΆ π΄, π¦ βΆ π΅ β’ Ξ) β Ξ β£ π(π₯, Μ π¦).π βΆ π΄ β π΅ β’ Ξ ππ βΆ (Ξ, π₯π βΆ π΄π β’ Ξ) (βπβ{1,2}) β Ξ β£ π[π₯ Μ 1 .π1 |π₯2 .π2 ] βΆ π΄1 + π΄2 β’ Ξ (g) Logic β (π π)Μ β¨ ππ β ππ₯ Μ π.πβ© β³R π[ππ /π₯π ] (π π) β¨π π β.π β ππ β© β³R π[ππ /β] (π β) β¨π(π₯π β β).π β ππ β πβ© β³R π[ππ /π₯π , π /β] β³R ππ [π/β] β³R π[ππ1 /π₯π1 , ππ2 /π¦π2 ] β³R ππ [πππ /π₯π π ] (π ×π ) (π β) (π +π ) β¨π<β.π1 ; β.π2 > β ππ β πβ© π1 π2 β¨(ππ1 , ππ2 ) β π(π₯ Μ , π¦ ).πβ© π π β¨ππ (πππ ) β π[π₯ Μ 11.π1 |π₯22.π2 ]β© (πΈπ) (πΈβ) (πΈ×) (πΈ π)Μ (πΈβ) (πΈ+) π π‘π π‘β π‘β ππ π+ π+ β³E β³E β³E β³E β³E β³E π π β.β¨π‘π β ββ© π(π₯β β).β¨π‘β β π₯β ββ© π<β.β¨π‘β β π1 β ββ©; β.β¨π‘β β π2 β ββ©> ππ₯ Μ π.β¨π₯π β ππ β© π(π₯, Μ π¦).β¨(π₯, π¦) β πβ β© πΜ[π₯.β¨π1 (π₯) β π+ β©|π¦.β¨π2 (π¦) β π+ β©] (i) Expansions (h) Reductions β Figure 5: Lint : grammar (top) β simple types (middle) β conversions (bottom) b) The subscript/superscript convention: The polarity of an expression (π‘β or π‘+ ) or a context (πβ or π+ ) is deο¬ned in the Figures 5c and 5d. Whenever necessary, the polarity annotation is part of the grammar: that is variables (π₯β, π₯+), binders (π ββ.π, π+β.π), and type variables (π β, π+). These notations conform to the following convention for polarity annotations: β’ β’ What we show with Lint is that all the information relevant for evaluation can be captured in a grammar, requiring no complete inspection of the terms, thanks to appropriate polarity annotations. We only needed to make sure that the conversion rules are grammatically well deο¬ned despite the presence of annotations, but this is easy to verify. On the other hand, polarities are no types: a polarity in superscript (π₯π ) indicates an annotation which is part of the grammar, a polarity in subscript (π‘π ) is not part of the grammar and only asserts that the term has this polarity. β’ β’ c) Polarisation as an approximation of types: A system of simple types, which corresponds to an intuitionistic sequent calculus, is provided on top of the Curry-style Lint . It is easy to see that: β’ β’ if one has Ξ β’ π‘ βΆ π΄π then π‘ has polarity π, if one has Ξ β£ π βΆ π΄π β’ Ξ then π has polarity π. like in the pure π calculus, it is possible to deο¬ne arbitrary ο¬xed-points, and in particular Lint is Turing-complete. it is possible to obtain ill-formed commands β¨π‘β β π+ β© by reducing well-polarised (but ill-typed) commands such as β β β¨ π(π₯ β β).β¨π₯ β ββ© β π‘β β π+ β© . (Such mixed commands do not reduce, and the reader should not expect to see them appear in the rest of the article.) d) Conο¬uence: Note that an expression is positive or negative but not both, and only the empty context (β) is both positive and negative. In particular, π+β.π is never a value, and ππ₯ Μ β.π is never a stack. With this observation in mind, it is easy to see that once again β³R has no critical pairs. Therefore βR is conο¬uent. Therefore, for typeable terms, the type determines the order of evaluation. Now, calculating on terms together with their typing derivations is tediousβit requires intimate knowledge of the properties of the type system (for instance subject reduction). With more complex type systems than the simple types, such properties can even be uncertain. e) Adjoint equations: Since there are now two distinct binders π ββ.π and π+β.π, adjoint equations β¨π β (π‘) β π β© β³R β¨π‘ β π (π)β© for substitutive π now have two solutions depending 7 π₯π΄ ππ₯ .π‘ (π‘ π’π΅ )π΄ <π‘; π’> ππ (π‘)π΄ ππ (π‘π΄ ) πΏ(π‘, π₯.π’, π¦.π£)π΄ π΄ and negative type variables π+, π β of Lβ’ . In Figure 6 we int deο¬ne two translations: β π₯π β π(π¦π β β).β¨π¦π β ππ₯ Μ π.β¨π‘ β ββ©β© π π2 β π β.β¨π’ β ππ₯ Μ .β¨π‘ β π₯π2 β ββ©β© β π<β.β¨π‘ β ββ©; β.β¨π’ β ββ©> β π π β.β¨π‘ β ππ β ββ© ββ π+β.β¨π‘ β ππ₯ Μ +.β¨ππ (π₯+) β ββ©β© π β π β.β¨π‘ β πΜ[π₯.β¨π’ β ββ©|π¦.β¨π£ β ββ©]β© β’ Nβ¦β β§ βΆ Lint β Ξβ’ Proposition 1. 1) If Ξ β’L π‘ βΆ π΄ then π‘ βRE Sβ¦Nβ¦π‘β§β§. int 2) If Ξ β’Ξ π‘ βΆ π΄ then π‘ β Nβ¦Sβ¦π‘β§β§. β’ 3) If π‘ βRE π’ in Lint then Nβ¦π‘β§ β Nβ¦π’β§. (a) Deο¬nition in Lβ’ of the operations of Ξβ’ , inducing a int β’ β’ translation Sβ¦β β§ βΆ Ξ β Lint . β β β β β β β β β β β Of course, it cannot be the case that π‘ β π’ in Ξβ’ implies , unless Lint identiο¬es all expressions. Sβ¦π‘β§ βRE Sβ¦π’β§ in Lβ’ int Indeed, one would have (ππ₯+.(πβ ππ.π₯+))(π¦ π§)+ βRE πβ ππ.(π¦ π§)+ in Lint . For π¦ = ππ§.π‘+ and πβ = ππ§β.π ββ.π[(π§β π)+/π π₯+] when π‘+ and π are arbitrary, this implies β¨π‘+ β ππ₯ Μ +.πβ© βRE π[π‘+/π π₯+]β where the focalising substitution [ π’+/π π₯+ ] is deο¬ned using focalisation in the sense of Section II-G: π₯π΄ Nβ¦πβ§ ππ₯π΄ .Nβ¦πβ§ <Nβ¦πβ§; Nβ¦π β² β§> ππ (Nβ¦π β§) Eπ [Nβ¦π‘β§] β‘ Eπ [ππ (β‘)] Eπ [β‘ Nβ¦π β§] (ππ₯π΄ .Nβ¦πβ§) β‘ πΏ(β‘, π₯π΄ .Nβ¦πβ§, π¦π΅ .Nβ¦π β² β§) Deο¬nition 2. Unrestricted expressions and contexts are deο¬ned as follows (in addition to ππ (π‘+ ) deο¬ned as in Figure 6a): π‘+ β π ββ ππ₯ Μ β.β¨π‘+ β ππ¦ Μ +.β¨π₯β β π¦+β πβ©β© π β πβ ββ‘ ππ₯ Μ β.β¨π ββ.β¨π₯β β π β ββ© β πβ β© ππ β πβ ββ‘ ππ₯ Μ β.β¨π ββ.β¨π₯β β ππ β ββ© β πβ β© (β : When π‘+ is not a valueββ‘: When πβ is not a stack.) β’ (b) Translation Nβ¦β β§ βΆ Lint β Ξβ’ β Figure 6: Translations between Ξβ’ and Lβ’ int Now let us call (π½) the following equation: β¨π‘+ β ππ₯ Μ +.πβ© β³π½ π[π‘+/π π₯+] on the polarity of π: β π π For instance there are actually one version of branching πΏ(π‘, π₯.π’, π¦.π£)π for each π β {β, +}, only one of which is a value, and similarly for function application: (π‘ π’)π . This splitting reο¬ects the fact that according to polarisation, πΏ(π‘, π₯.π’, π¦.π£) is either strict or lazy depending on whether π’ and π£ are strict or lazy. This observation is not an artefact and has several implications studied elsewhere: β’ (π½) which is equivalent to the associativity of the composition in Lint (See M.-M. [43]). In Lint one can already derive modulo βRE all the conversions of Ξβ’ with the following restriction: the arguments of π and πΏ are restricted to values. Using (π½) one can substitute positive variables, which are values, with arbitrary positive expressions. Therefore: π (π‘) β π β.β¨π‘ β π (β)β© β’ β’ Sβ¦β β§ βΆ Ξβ’ β Lint These translations are well deο¬ned: if Ξ β’Lint π‘ βΆ π΄ then Ξ β’Ξ Nβ¦π‘β§ βΆ π΄ and if Ξ β’Ξ π‘ βΆ π΄ then Ξ β’Lint Sβ¦π‘β§ βΆ π΄. In addition: where π΄ has polarity π and π΅ has polarity π2 . β : when π‘π΄ is not a value. Nβ¦π₯π΄ β§ Nβ¦ππ΄ β.πβ§ Nβ¦π(π₯π΄ β β).πβ§ Nβ¦π<β.π ; β.π β² >β§ Nβ¦π1 (π )β§ Nβ¦β¨π‘ β πβ©β§ Eβ β‘ Eππ β π β‘ Eπ β π β‘ Eππ₯Μ π΄ .π β‘ Eπ[π₯ Μ π΄ .π | π¦π΅ .π β² ] β‘ , Proposition 3. If π‘ β π’ in Ξβ’ then Sβ¦π‘β§ βREπ½ Sβ¦π’β§ in Lβ’ . int A programming language based on Lint would deο¬ne the polarity of an expression by a shallow inspection. Function application would require an explicit annotation determining the polarity of the result; such an information could be synthesised during type inference. (M.-M. [42].) One should not seek to model Lint in a category directly: composition is not associative, but deο¬nes a pre-duploid. (M.-M. [43].) In fact, in (untyped) Lint extended with (π½), one can apply the same diagonal argument as in Section III-B, and therefore (π½) is incoherent in Lint , as we claimed. But, (π½) is compatible with Lβ’ in the following sense: int Lemma 4. Let π‘+ be an expression such that β’L π‘+ βΆ π΅+ . int There exists a closed value π+ such that β¨π‘+ β ββ© β³βR β¨π+ β ββ©, and therefore π‘+ βRE π+ . Proof: This is a corollary of the adequacy lemma form M.M. [39], adapted to intuitionistic logic (as in [40]). Adapting the polarised orthogonality-based realizability from [39] is straightforward: any intuitionistic proof can be seen as a classical proof. Now, the linearity restriction on β implies in Section II-C, β β fv(π+ ) as we already noticed for Lβ int therefore we can conclude π‘+ βRE π+ βin words, intuitionistic computation is referentially transparent. β E. Relating Lint to the π-calculus with sums We relate typed restrictions of Lint (minus the positive pair β) and the π-calculus with sums. Let us denote with Lβ’ int and Ξβ’ the simply-typed Lint (without β) and π-calculus with sums, that is to say restricted by the typing judgements from Figures 5 (minus the positive pair β) and 1 respectively. For simplicity we will omit the typing judgements and may choose to write explicit type annotations (à la Church). We give these systems the same grammar of types by assuming that the set of type variables π of Ξβ’ coincides with the set of positive Proposition 5. Lβ’ satisο¬es (π½) whenever π‘+ is closed. int In a separate note, we prove that (π½) actually belongs to the observational closure of βR . The technique, based on 8 example, β¨π1 (π₯β) β ββ© (πΈπ)-expands into the phase-separated command β¨π1 (πββ.β¨π₯β β ββ©) β ββ©. polarised realizability, generalises beyond simple typesβfor instance, extensions to second- and higher-order are immediate. Polarisation therefore oο¬ers an approach to typed π-calculi where the associativity of composition is an external property similar to normalisation. If we adopt this point of view, then it is not surprising that the rewriting theory of the π-calculus with sums is complex, and that it is even computationally incoherent in the presence of ο¬xed-points. Lemma 6. Any valid (βR )-normal form is (βEβ π,πΜ )-expansible to a unique focused form π . B. Algorithmic equality for expansion rules We deο¬ne the algorithmic equality relation (β‘A ) as a system of inference rules on pairs of commands, which captures extensional equivalence: (β‘A ) decides (βE ) on βR -normal terms. If we worked on typed normal forms, we could perform maximal type-directed π-expansion; for the sake of generality and its intrinsic interest, we work with untyped normal forms. The purely syntactic approch is to perform, in both commands to be compared, the π-expansions for the abstractors that appear in either commands. This untyped equivalence is inspired by previous works [10, 1] that compute π-equivalence of π-terms by looking at the terms only, doing an π-expansion when either term starts with a π. In Figure 8a we deο¬ne (β‘A ) by mutual recursion with a sub-relation (β‘Aπ ) that only relates π -normal forms. We have omitted the symmetric counterparts of the abstractor rules. In the two last cases, we consider that (β‘A ) is deο¬ned on expressions and contexts as the congruence closure of (β‘A ) on sub-commands. For example, π1 (πβ.π) β‘A π‘β² if and only if π‘β² is of the form π1 (πβ.π β² ) for some π β² such that π β‘A π β² . We use the term algorithmic because this equivalence is almost syntax-directed. If both sides of the equivalence start with an abstractor application, there is a non-syntax-directed choice of which side to inspect ο¬rst: for π‘, π’ ο¬xed there may be several distinct derivations of π‘ β‘A π’. Notice that, whenever π1 is aβR -normal form, then the substitutions involved in the deο¬nition of algorithm equivalence, such as π1 [(π₯1 , π₯2 )/π₯+], are strongly normalizing as well. Indeed, while the substitution may create new reduction opportunities, for example in β¨π₯+ β π(π¦1 , π¦2 ).π β² β©, those reductions would in turn only create substitutions of variables for variables ([π₯1/π¦1 ] and [π₯2/π¦2 ] in the example above), which do not produce any new redexes. IV. The Structure of Normal Forms and Their Equivalence This section studies the βR -normal forms of Lint . Their equivalence can be deο¬ned and decided by equivalence relations that are more uniform than the rewriting-based approaches targeting π-calculus. A. The phase structure of normal forms Figure 7a describes the syntax of valid R-normal forms, where a constructor is never opposed to an abstractor for another connective; for example β¨π1 (π‘) β π(π₯, Μ π¦).πβ© would be an invalid normal form. A normal command of the form β¨π+ β ββ© or β¨π₯β β πβ β© starts with a constructor, head computation is ο¬nished. A command of the form β¨π₯+ β π+ ⧡ ππ₯ Μ +.πβ© (any π+ that + β is not a ππ₯ Μ .π) or β¨π‘β ⧡ π β.π β ββ© starts with an abstractor whose computation is blocked by the lack of information on the opposite side. We thus decompose the structure of normal commands as a succession of phases, with constructor phases π πΆ and abstractor phases π π· . Remark that functions have their constructor and abstractors inversed with respect to their constructor and destructor in π calculi: function introduction π(π₯β β).π is an abstractor expression, while function application π’β π is a context constructor. Figure 7b describes the structure of phase-separated normal forms. We call them focused forms. A focused form π is a focused command π π for some phase variable π, which is either πΆ or π·βwe will write πΜ for the phase opposite to π. A focused command π π is either a focused value π π against β, or a focused stack π π against some variable π₯. Constructor values π πΆ start with a head expression constructor, followed by other head constructors until π ββ.π or a variable is reached, ending the phase. Constructor stacks π πΆ are non-empty compositions of stack constructors ended by a ππ₯ Μ +.π . Abstractor values or stacks are either a variable or β, or a π-form that immediately ends the phase. An informal way to think of focused commands, which correspond to our intuition of normal sequent proofs, is to see the focused command β¨π₯ β π π β© as a βplay on π₯β, and correspondingly β¨π π β ββ© as a βplay on ββ. This syntactic phase separation resembles focused proofs [4]. We work on an untyped calculus, so we cannot enforce that phases be maximally long; but otherwise constructor phases correspond to non-inversible, or synchronous rules, while abstractor phases correspond to inversible, or asynchronous inference rules. Not all βR -normal forms are focused forms, as they may not respect the constraint that phase change be explicitly marked by a π-form. But a normal form can be easily rewritten into a focused form: inserting a phase change is a valid expansion. For Lemma 7. Soundness of algorithmic equivalence: if π‘ β‘A π’ then π‘ βRE π’. C. Completeness of algorithmic equality on normal forms Abel and Coquand [1] discuss the problem of transitivity of their syntax-directed algorithmic equality: while it morally captures our intuition of βgoodβ π-equivalences, it fails to account for some seemingly-absurd equivalences that can be derived on untyped terms, such as ππ₯.(π‘ π₯) βπ <π1 π‘; π2 π‘>, the transitive combination of ππ₯.(π‘ π₯) βπ π‘ and π‘ βπ <π1 π‘; π2 π‘>. To accept those absurd equivalences, Abel and Coquand had to extend their relation with type-incorrect rules such as: π‘ β‘A π π₯ π1 π β‘A π π2 π β‘A π β ππ₯.(π‘ π₯) β‘A <π; π > This change suο¬ces to regain transitivity and capture untyped π-conversion. Unfortunately, this technique requires a number of additional rules quadratic in the number of diο¬erent 9 β¨π+ β ββ© β¨π₯+ β π+ ⧡ ππ₯ Μ +.πβ© β β¨π₯ β πβ β© β¨π‘β ⧡ π ββ.π β ββ© π = π π β©΄ β¨π₯ β π π β© | β¨π π β ββ© ππ + π {π π· πΆ± where πΆ± π β©΄ πΆ | π· (phase: constructors, abstractors) β©΄ π₯ | (π , π ) | π1 (π ) | π2 (π πΆ± ) β©΄ π₯β | π(π₯β β).π | π<β.π ; β.π > πΆ πΆ± ππ ππ· {π πΆ π πΆ± β©΄ π πΆ | π ββ.π |π¦.π ] | π(π₯, β©΄ β | π[π₯.π Μ Μ π¦).π β©΄ β | π πΆ± β π πΆ± | ππ β π πΆ± π πΆ± β©΄ π πΆ | ππ₯ Μ +.π (a) β³R -normal forms (b) Focused forms β Figure 7: Normal and focused forms π ββR π1 (β) π1 β‘A π1β² (β)π1β² ββR π β² π β π β‘A π β² π[(π₯1 , π₯2 )/π₯+] β‘A π β² [(π₯1 , π₯2 )/π₯+] β β¨π₯+ β π(π₯1 , π₯2 ).πβ© β‘A π β² A-pair π π[(π₯β β)/πΌ] β‘A π β² [(π₯β β)/β] β β¨π(π₯β β).π β πΌβ© β‘A π β² A-R π2 [π2 π₯2 /π₯+] β‘A π β² [π2 π₯2 /π₯+] π1 [π1 π₯1 /π₯+] β‘A π β² [π1 π₯1 /π₯+] β + β¨π₯ β π[π₯ Μ 1 .π1 |π₯2 .π2 ]β© β‘A π β² A-sum π A-fun π π1 [π1 β β /β] β‘A π β² [π1 β β /β] π2 [π2 β β /β] β‘A π β² [π2 β β /β] β β¨π<β.π1 ; β.π2 > β ββ© β‘A π β² A-neg-pair π π1πΆ β‘A π2πΆ β β¨π₯β β π1πΆ β© β‘A β¨π₯β β π2πΆ β© π1πΆ β‘A π2πΆ β β¨π1πΆ β ββ© β‘A β¨π2πΆ β ββ© A-cocong π A-cong π (a) Algorithmic equivalence π[(π₯1 , π₯2 )/π+ ] β‘A+ π β² [(π₯1 , π₯2 )/π+ ] A+pair β β¨π+ β π(π₯1 , π₯2 ).πβ© β‘A+ π β² π π[(π₯β β)/πβ ] β‘A+ π β² [(π₯β β)/πβ ] A+fun β β¨π(π₯β β).π β πβ β© β‘A+π π β² π1 [π1 π₯1 /π+ ] β‘A π β² [π1 π₯1 /π+ ] π2 [π2 π₯1 /π+ ] β‘A π β² [π2 π₯1 /π+ ] A+sum β Μ 1 .π1 |π₯2 .π2 ]β© β‘A+ π β² β¨π+ β π[π₯ π π1 [π1 β /πβ ] β‘A+ π β² [π1 β /πβ ] π1 [π2 β /πβ ] β‘A+ π β² [π2 β /πβ ] A+negpair β β¨π<β.π1 ; β.π2 > β πβ β© β‘A+π π β² (b) Extended algorithm equality rules β¨π1 (π¦1 ) β ββ© β‘A+ β¨π1 (π¦1 ) β ββ© β¨π2 (π¦1 ) β ββ© β‘A+ β¨π2 (π¦1 ) β ββ© π π β β¨(π₯1 , π₯2 ) β ββ© β‘A+π β¨(π₯1 , π₯2 ) β πΜ[π¦1 .β¨(π₯1 , π₯2 ) β ββ©|π¦2 .β¨(π₯1 , π₯2 ) β ββ©]β© β + + + + + β¨π₯ β π(π₯1 , π₯2 ).β¨π₯ β ββ©β© β‘A+π β¨π₯ β πΜ[π¦1 .β¨π₯ β ββ©|π¦2 .β¨π₯ β ββ©]β© β + + + + (π πΎπ (π₯1 , π₯2 ) π»πΎ π₯ ππ π₯ ) β‘A+ πΏ(π₯ , π1 (π¦1 ).π₯ , π2 (π¦2 ).π₯+) π A+sum A+pair β¨(π₯1 , π₯2 ) β π¦β ββ© β‘A+ β¨(π₯1 , π₯2 ) β π¦β ββ© π A+pair β + + π₯ π(π₯ β¨ β 1 , π₯2 ).β¨(π₯1 , π₯2 ) β π¦β ββ©β© β‘A+π β¨π₯ β π¦β ββ© β A+fun + + β¨π₯ β π(π₯1 , π₯2 ).β¨(π₯1 , π₯2 ) β ββ©β© β‘A+π β¨π(π¦β β).β¨π₯ β π¦β ββ© β ββ© β (π πΎπ (π₯1 , π₯2 ) π»πΎ π₯+ ππ (π₯1 , π₯2 )) β‘A+ ππ¦.(π₯+ π¦) π (c) Deriving (instances of) Abel and Coquandβs [1] transitivity rules from (β‘A+ ). β Figure 8: Algorithmic equivalence constructors of the language. Our richer syntax allows the deο¬nition in Figure 8b of an extended algorithmic equivalence (β‘A+ ) without introducing any new rule, but by extending each constructor rule A-fun, A-pair etc. in a simple (but potentially type-incorrect) way. The notation π[π‘/π ] substitutes syntactic occurences of the term π by π‘; there is a unique context decomposition of π into π β² [π ] with π β π β² , and then π[π‘/π ] is π β² [π‘]. On valid terms, this extended equivalence coincides with the previous algorithmic equivalence. Indeed, in the case of a normal command β¨π+ β π(π₯1 , π₯2 ).πβ© for example, a valid π+ can only be a variable π₯+, in which case the rule A-pair and A+pair are identical. The extension only applies when π+ has a head constructor that is not the pair, in which case the expression is in normal form but invalid. Figure 8c shows that this extension subsumes the rules of Abel and Coquand: we can derive their instances. Notice how the left-hand-side of the left premise of the topmost rule is obtained by the apparently-nonsensical substitution β¨(π₯1 , π₯2 ) β ββ©[π1 π¦1/(π₯1 , π₯2 )] produced by the extended sum rule on an invalid command. We consider this baroque extension 10 only a curiosity of the meta-theory. Lemma 8 (Soundness). π‘ β‘A+ π’ implies π‘ βRE π’. Lemma 9 (Reο¬exivity). If π‘ is βR -normalizing then π‘ β‘A+ π‘. Lemma 10 (Transitivity). If π‘1 β‘A+ π‘2 and π‘2 β‘A+ π‘3 then π‘1 β‘A+ π‘3 . Lemma 11 (Completeness). If π βRE π β² then π β‘A+ π β² . Theorem 12. If π1 and π2 are (βR )-normalizable commands, then π1 βRE π2 if and only if π1 β‘A+ π2 . D. Phase equivalence Algorithmic equality demonstrates that the focused forms are a suitable structure to compute (βRE )-equivalence. However, this (βRE )-equivalence is more restrictive than the usual π½π-equivalences considered for π-terms. For example, π πΎπ π¦+ π»πΎ π₯ π ππ π1 (π‘β ) is not (βRE )-equivalent to π1 (π πΎπ π¦+ π»πΎ π₯ π ππ π‘β )βintuitively, the applications of constructors may perform arbitrary eο¬ects and thus are not reorderable. π π [ ] β©΄ β¨π₯ β π π [ ]β© | β¨π π [ ] β ββ© π πΆ [ ] β©΄ (π πΆ± , π πΆ± [ ]) | (π πΆ± [ ], π πΆ± ) | ππ (π πΆ± [ ]) ππ {π π· [ ] β©΄ π(π₯β β).[ ] | π<β.[ ]; β.[ ]> π πΆ± β©΄ π πΆ [ ] | π ββ.[ ] π π· β©΄ π[π₯.[ Μ Μ π¦).[ ] ]|π₯.[ ]] | π(π₯, ππ {π πΆ β©΄ π πΆ± [ ]β π πΆ± | π πΆ± β π πΆ± [ ] | ππ β π πΆ± [ ] π πΆ± β©΄ π πΆ [ ] | ππ₯ Μ +.[ ] β Deο¬nition 15. We call phase equivalence the relation (βP ) deο¬ned as the (closure of the) union of (βP ) and (βP ). πΆ E. Recovering π½π-equivalence Figure 9: Commutative contexts We can strengthen the equational theory of the untyped language, under the additional assumption that the terms are pure and strongly normalising setting, by allowing identical phases to be merged, and unused phases to be dropped. This is the purpose of Section IV-E, which recovers a theory equivalent to π½π for π-calculus. As a ο¬rst step, we study in this section the reodering of independent phases. This is no stronger than ( βRE ), but captures the global aspect of equivalence: merging and weakening can then be deο¬ned locally. We write π π [ ], π π [ ] and π π [ ] for focused command contexts (respectively value contexts, stack contexts) with one or several holes, all in a position where a subcommand is expected. We are interested in reordering π1 [π2 [ ]] into π2 [π1 [ ]]. Two command contexts π1 [ ] and π2 [ ] are independent, written π1 # π2 , if reodering them respects scope: the variables (and β) of π1 bound by π1 are not free in π2 , and conversely. Deο¬nition 13. We deο¬ne the commutative contexts for focused commands, values and stacks by the grammar of Figure 9. For a given phase π, we deο¬ne the phase equivalence (βPπ ) with the reordering: π π· Appendix A gives a rewriting relation to decide (βP )equivalence, similarly to the preemptive rewriting of maximal multi-focusing [9]. π π2 [π1 [ ]] β³Pπ π1 [π2 [ ]] π when π1 # π2 . Note that some abstractor commutative contexts, e.g. β¨π₯+β π[π₯ Μ 1 .[ ]|π₯2 .[ ]]β©, may have several holesβphase reordering may thus result in (de-)duplication. Constructor commutative contexts have exactly one hole; for example, (π πΆ± , [ ]) and ([ ], π πΆ± ) are both valid shapes for a commutative value context, but we do not deο¬ne ([ ], [ ]) as a commutative context. One can relate this diο¬erence to the additive or multiplicative status of connectives in linear logic, or to the syntactic idea that control may ο¬ow into either branches of the sum elimination construction. In particular, π[π₯.π Μ 1 | π¦.[ ]] is not a commutative context, since π [ β¨π₯ β π[π¦ Μ 1 .π1 |π¦2 .π2 ]β© ] is very diο¬erent from Μ 1 .π1 |π¦2 .π[π ]]β© in general. β¨π₯ β π[π¦ Lemma 14. (βPπ· ) is derivable: if π1 βPπ· π2 then π1 βRE π2 . While (βPπ ) is deο¬ned entirely on the structure of focused normal forms, the intermediary (βRE )-reasoning step used to justify commutativity are free to disrespect this focused structure. These exchanges between the normalized and the non-normalized world are interesting and justify, we think, studying ο¬rst the dynamics of the system (or, said otherwise, proof/type systems with a cut), and looking at their normal forms only later, instead of starting with cut-free systems directly. 11 If π is a substitution from variables to variables, and π π [ ] (resp. π π [ ]) is a focused context, we write π π [π[ ]] for the focused context where each of the variables bound by π π [ ] that scope over its hole are renamed according to π, and only those are in the domain of π. In particular, there exists a π such π π π π that π1 [π[ ]] = π2 [ ] when π1 and π2 modulo renaming of outgoing variablesβfor example π(π₯1 , π₯2 ).[ ] and π(π₯β²1 , π₯β²2 ).[ ]. Deο¬nition 16. We deο¬ne the merging simpliο¬cation (β³M ) as the smallest relation such that, for each pair of independent π π commutative contexts π1 # π2 and substitution π such that π π π π π π1 = π2 [π], we have π1 [π2 [π3 ]] β³M π1 [π[π3 ]]. βM is normalizing, since it decreases strictly the size of the command. Deο¬nition 17. We deο¬ne the weakening simpliο¬cation (β³W ) as the smallest relation such that, whenever none of the variable bound by the commutative context π[ ] over its hole are used in π , we have π[π ] β³W π . Note that commutative contexts of the form β¨π π [ ] β ββ© are neither mergeable nor weakenable, since all possible holes of π π [ ] shadow the variable β, breaking the independence requirement, and all pluggable commands π use the variable β, breaking the weakening requirement. Semantically it would make no sense, of course, to claim something to the eο¬ect of π1 (π1 (πβ.π)) βM π1 (πβ.π) or π1 (πβ.π ) βW π , but we directly recover this from Lint without having to break the uniformity of our deο¬nitions. We will write (βREPMW ) the closure of the unions of (βRE ), (βP ), (βM ) and (βW ). It is decidable on βR -normalizable terms by normalizing by (βR ), then taking the (βP )-normal form, the βMW -normal form, and ο¬nally (β‘A+ ) to decide equivalences. We now prove that is sound and complete with respect to (βREπ½ ), which corresponds to the π½π-equality of πcalculus as demonstrated in Section III-E. Proposition 18. If π‘ βMW π’ then π‘ βREπ½ π’. Theorem 19. If π‘ βREπ½ π’, then π‘ βREPMW π’. This concludes our study of the normal forms. We have demonstrated that the equivalence (βREπ½ ), which corresponds on typed terms to the natural equality of well-typed π-terms, can be re-deο¬ned (and decided) in a syntactically uniform way based on sequences of constructor and abstractor phases. References [1] Andreas Abel and Thierry Coquand, Untyped Algorithmic Equality for Martin-Löfβs Logical Framework with Surjective Pairs, Typed Lambda Calculi and Applications (PaweΕ Urzyczyn, ed.), Lecture Notes in Computer Science, vol. 3461, Springer Berlin Heidelberg, 2005, pp. 23β38 (English). [2] Mads Sig Ager, Dariusz Biernacki, Olivier Danvy, and Jan Midtgaard, A Functional Correspondence between Evaluators and Abstract Machines, PPDP, 2003, pp. 8β19. [3] Thorsten Altenkirch, Peter Dybjer, Martin Hofmann, and Philip Scott, Normalization by evaluation for typed lambda calculus with coproducts, Logic in Computer Science, 2001. Proceedings. 16th Annual IEEE Symposium on, IEEE, 2001, pp. 303β310. [4] Jean-Marc Andreoli, Logic Programming with Focusing Proof in Linear Logic, Journal of Logic and Computation 2 (1992), no. 3, 297β347. [5] Zena M Ariola, Aaron Bohannon, and Amr Sabry, Sequent calculi and abstract machines, ACM Transactions on Programming Languages and Systems (TOPLAS) 31 (2009), no. 4, 13. [6] Vincent Balat, Roberto Di Cosmo, and Marcelo P. Fiore, Extensional normalisation and type-directed partial evaluation for typed lambda calculus with sums, POPL, 2004, pp. 64β76. [7] Aloïs Brunel, Quantitative classical realizability, Information and Computation (2014). [8] Kaustuv Chaudhuri, Stefan Hetzl, Dale Miller, et al., A Systematic Approach to Canonicity in the Classical Sequent Calculus, 21st EACSL Annual Conference on Computer Science Logic, vol. 16, 2012, pp. 183β 197. [9] Kaustuv Chaudhuri, Dale Miller, and Alexis Saurin, Canonical sequent proofs via multi-focusing, Fifth Iο¬p International Conference On Theoretical Computer ScienceβTcs 2008, Springer, 2008, pp. 383β396. [10] Thierry Coquand, Logical Frameworks, Cambridge University Press, New York, NY, USA, 1991, pp. 255β279. [11] Pierre-Louis Curien and Hugo Herbelin, The duality of computation, ACM SIGPLAN Notices 35 (2000), 233β243. [12] Pierre-Louis Curien and Guillaume Munch-Maccagnoni, The duality of computation under focus, Proc. IFIP TCS, 2010, Extended version. [13] Vincent Danos, Jean-Baptiste Joinet, and Harold Schellinx, A New Deconstructive Logic: Linear Logic, Journal of Symbolic Logic 62 (3) (1997), 755β807. [14] Olivier Danvy and Kevin Millikin, A Rational Deconstruction of Landinβs SECD Machine with the J Operator, Logical Methods in Computer Science 4 (2008), no. 4. [15] Olivier Danvy and Lasse R. Nielsen, Defunctionalization at Work, Research Report BRICS RS-01-23, Department of Computer Science, Aarhus University, Aarhus, Denmark, July 2001, Extended version of an article presented at the Third International Conference on Principles and Practice of Declarative Programming (PPDP 2001), Firenze, Italy, September 5-7, 2001; most inο¬uential paper at PPDP 2001, 10 years after. [16] Daniel J. Dougherty, Some Lambda Calculi With Categorical Sums and Products, Rewriting Techniques and Applications, 1993. [17] Paul Downen and Zena M Ariola, The duality of construction, European Symposium on Programming, Springer, 2014, pp. 249β269. [18] Andrzej Filinski, Declarative Continuations and Categorical Duality, Masterβs thesis, DIKU, Computer Science Department, University of Copenhagen, Aug 1989, DIKU Rapport 89/11. [19] Marcelo Fiore, Roberto Di Cosmo, and Vincent Balat, Remarks on isomorphisms in typed lambda calculi with empty and sum types, Logic in Computer Science, 2002. Proceedings. 17th Annual IEEE Symposium on, IEEE, 2002, pp. 147β156. [20] Gerhard Gentzen, Untersuchungen über das logische Schließen, Mathematische Zeitschrift 39 (1935), 176β210,405β431. [21] Neil Ghani, π½π-equality for coproducts, Typed Lambda Calculi and Applications, Springer, 1995, pp. 171β185. [22] Jean-Yves Girard, A new constructive logic: Classical logic, Math. Struct. Comp. Sci. 1 (1991), no. 3, 255β296. [23] _ , On the Unity of Logic, Ann. Pure Appl. Logic 59 (1993), no. 3, 201β217. [24] _ , Locus Solum: From the Rules of Logic to the Logic of Rules, Mathematical Structures in Computer Science 11 (2001), 301β506. [25] _ , Le Point Aveugle, Cours de logique, Tome I: Vers la Perfection, Vision des Sciences, Hermann, 2006, published subsequently in English [27]. [26] _ , Le Point Aveugle, Cours de logique, Tome II: Vers lβimperfection, Visions des Sciences, Hermann, 2007, published subsequently in English [27]. [27] _ , The Blind Spot: Lectures on Logic, European Mathematical Society, 2011. [28] Healfdene Goguen, Justifying Algorithms for Ξ²Ξ·-Conversion, Foundations of Software Science and Computational Structures (Vladimiro Sassone, ed.), Lecture Notes in Computer Science, vol. 3441, Springer Berlin Heidelberg, 2005, pp. 410β424 (English). 12 [29] Hugo Herbelin, Lambda-calculus structure isomorphic to sequent calculus structure, CSL, CSL, 1994. [30] Hugo Herbelin, Cβest maintenant quβon calcule, au cΕur de la dualité, 2005, Habilitation thesis. [31] Hagen Huwig and Axel Poigné, A Note on Inconsistencies Caused by Fixpoints in a Cartesian Closed Category, Theor. Comput. Sci. 73 (1990), no. 1, 101β112. [32] Peter J. Landin, The mechanical evaluation of expressions, The Computer Journal 6 (1964), no. 4, 308β320. [33] _ , A correspondence between algol 60 and Churchβs Lambdanotation, Commun. ACM 8 (1965), no. 2, 89β101 and 158β165. [34] F. William Lawvere, Diagonal arguments and cartesian closed categories, Lecture Notes in Mathematics 92 (1969), 134β145. [35] Paul Blain Levy, Call-By-Push-Value: A Functional/Imperative Synthesis, Semantics Structures in Computation, vol. 2, Springer, 2004. [36] _ , Adjunction models for call-by-push-value with stacks, Proc. Cat. Th. and Comp. Sci., ENTCS, vol. 69, 2005. [37] Chuck Liang and Dale Miller, Focusing and Polarization in Intuitionistic Logic, CSL, 2007, pp. 451β465. [38] Sam Lindley, Extensional rewriting with sums, Typed Lambda Calculi and Applications, Springer, 2007, pp. 255β271. [39] Guillaume Munch-Maccagnoni, Focalisation and Classical Realisability, Proc. CSL β09, LNCS, Springer-Verlag, 2009. [40] _ , π-calcul, machines et orthogonalité, Unpublished manuscript, October 2011. [41] _ , Syntax and Models of a non-Associative Composition of Programs and Proofs, Ph.D. thesis, Univ. Paris Diderot, 2013. [42] _ , Formulae-as-Types for an Involutive Negation, Proceedings of the joint meeting of the Twenty-Third EACSL Annual Conference on Computer Science Logic and the Twenty-Ninth Annual ACM/IEEE Symposium on Logic in Computer Science (CSL-LICS), 2014, To appear. [43] _ , Models of a Non-Associative Composition, FoSSaCS (A. Muscholl, ed.), LNCS, vol. 8412, Springer, 2014, pp. 397β412. [44] Tobias Nipkow, Higher-Order Critical Pairs, Proc. 6th IEEE Symp. Logic in Computer Science, IEEE Press, 1991, pp. 342β349. [45] Michel Parigot, Lambda-Mu-Calculus: An Algorithmic Interpretation of Classical Natural Deduction, LPAR, 1992, pp. 190β201. [46] John C. Reynolds, Deο¬nitional Interpreters for Higher-Order Programming Languages, Proceedings of 25th ACM National Conference (Boston, Massachusetts), 1972, Reprinted in Higher-Order and Symbolic Computation 11(4):363-397, 1998, with a foreword [47], pp. 717β740. [47] _ , Deο¬nitional Interpreters Revisited, Higher-Order and Symbolic Computation 11 (1998), no. 4, 355β361. [48] José Espírito Santo, Completing Herbelinβs programme, Typed Lambda Calculi and Applications, Springer, 2007, pp. 118β132. [49] Peter Selinger, Control Categories and Duality: On the Categorical Semantics of the Lambda-Mu Calculus, Math. Struct in Comp. Sci. 11 (2001), no. 2, 207β260. [50] Arnaud Spiwak, A dissection of L, Submitted, 2014. [51] Thomas Streicher and Bernhard Reus, Classical Logic, Continuation Semantics and Abstract Machines, J. Funct. Program. 8 (1998), no. 6, 543β572. [52] Hayo Thielecke, Categorical Structure of Continuation Passing Style, Ph.D. thesis, University of Edinburgh, 1997. [53] Adriaan van Wijngaarden, Recursive deο¬nition of syntax and semantics, Formal Language Description Languages for Computer Programming, North Holland Publishing Company, 1966. [54] Philip Wadler, Call-by-value is dual to call-by-name, SIGPLAN Not. 38 (2003), no. 9, 189β201. [55] Mitchell Wand, Continuation-Based Program Transformation Strategies, J. ACM 27 (1980), no. 1, 164β180. Contents I Introduction I-A Abstract-machine-like calculi . . . . I-B Intuitionistic polarisation . . . . . . I-C Focusing and untyped normal forms I-D Notations . . . . . . . . . . . . . . . I-E Acknowledgements . . . . . . . . . π π β¨π₯ β π [β¨π [ ] β ββ©]β© . . . . . . . . . . II A Principled Introduction to Abstract-MachineLike Calculi II-A Abstract machines . . . . . . . . . . . . II-B Solving equations for expressions . . . . II-C Compatible reduction and its conο¬uence II-D Typing of machines . . . . . . . . . . . II-E Solving equations for contexts . . . . . II-F Commutation rules are redundant . . . II-G Focalisation . . . . . . . . . . . . . . . II-H Inside-out contexts are primitive . . . . II-I A parte: Defunctionalised CPS in direct style . . . . . . . . . . . . . . . . . . . III Polarisation and Extensional Sums III-A Conversions on expressions vs. on commands . . . . . . . . . . . . . . . . . . III-B Extensionality for sums with a regular shape . . . . . . . . . . . . . . . . . . . III-C Positive sums . . . . . . . . . . . . . . III-D The polarised calculus Lint . . . . . . . III-E Relating Lint to the π-calculus with sums π π β¨π₯ β π [β¨π¦ β π2 [ ]β©]β© 1 1 2 2 2 3 π Μ π π1 [π π [π2 [ ]]] βLP π π β¨π [β¨π₯ β π [ ]β©] β ββ© βLP π β¨π¦ β π2 [β¨π₯ β π [ ]β©]β© β³GP π1 [π2 [π π [ ]]] π π π Μ In the deο¬nitions above we assume commutativity and independence of the reordered command contexts. β Figure 10: Focused equivalences the only diο¬erence between (βRE ) (which we deconstructed as (βR )-normalization followed by algorithmic equivalence) and (βπ½π ) is the addition (βPπΆ ), reordering of independent constructors. Inspired by the work on multi-focusing [9], Figure 10 deο¬nes two subrelations of (βP ): a local phase equivalence (βLP ), permuting focused values and stacks inside a single phase, and a global phase reordering (βGP ). The global rewrite lets a focused commutative context of phase π (which may be only a fragment of a larger context) jump across another context of opposite phase π.Μ Note that it must jump into another context of the same phase, and thus cannot split the π-Μ context in twoβwe say that a focused context inside a focused command is maximal if its the surrounding contexts are of the opposite phase. This restriction is necessary for the rewrite to be terminating: with the orientation of the reduction and this restriction, the outermost maximal contexts grows bigger at each rewrite step. 3 3 3 4 4 4 5 5 5 6 6 6 6 6 6 8 Lemma 20. (β³GP ) is terminating. Μ IV The Structure of Normal Forms and Their Equivalence IV-A The phase structure of normal forms . . IV-B Algorithmic equality for expansion rules IV-C Completeness of algorithmic equality on normal forms . . . . . . . . . . . . . . IV-D Phase equivalence . . . . . . . . . . . . IV-E Recovering π½π-equivalence . . . . . . . 9 10 11 References 11 Appendix A: Phase Normal Forms 13 Appendix B: Proofs from Section IV 14 Note that the reordered π π may be duplicated if π2 has several holes. The termination order is thus the tree of sizes of maximal contexts; the tree with the biggest element coming ο¬rst is the smaller. This is well-ordered if the total size of trees arising from the rewrite of a given element is bounded. The possible rewrites of a term of size π are bounded in size by 2π (impossible worst case where all elements are duplicating and get rewritten in a such a way that they do duplicate the rest of the term). The relations (βLP ) and (β³GP ) are not just subrelations: combined, they subsume (βP ). 9 9 9 Lemma 21. π1 βP π2 if and only if π1 β³GP β π1β² and π2 β³GP β π2β² with π1β² βLP π2β² . Appendix A Phase Normal Forms This section proves that phase equivalence is decidable. As (βPπΆ ) is not derivable, phase equivalence relates terms that are not in (βRE ). For example, β + Μ +.πβ©) β β β© βPπΆ we have β¨ π1 (πβ .β¨π₯ β π β ππ¦ + + β π₯ π β ππ¦ Μ .β¨π (πβ .π) ββ© . We wish to prove, in the β β β¨ β© 1 remainder of this section, that combining (βP ) and the algorithmic equivalence (β‘A+ ) of the previous section (which decides π-equivalences) captures the natural equivalence on βeο¬ect-freeβ commands, and in particular coincides with the (βπ½π ) equivalence of the lambda-calculus. This implies that 13 The equivalence (βLP ) is decidable and local, so it is natural to manipulate terms up to this equivalence. One way to do this is to introduce an explicit multi-focusing syntax that performs a series of independent plays simultaneously on diο¬erent variables and optionally on β; that corresponds to a multi-let syntax (π πΎπ π₯Μ π»πΎ π Μ ππ π‘) in some calculi, or to the multi-case pattern-matching construct of Altenkirch et al. [3]. Another equivalent choice, which we adopt for simplicity, is to pick an arbitrary order to order local phases. Deο¬nition 22. We deο¬ne βπ βLP as an arbitrary choice of representative in the (βLP )-equivalence class of the focused command π . We will also write βπ βGP for the unique (βGP )normal form of π , and βπ βP for ββπ βGP βLP . Finally, if π is a (βR )-normalizable command, whose normal form has a (unique) focused form π , we will write βπβP for βπ βP . We just need to extend this result to prove that π βRE β¨π+ β π(π₯1 , π₯2 ).π[(π₯1 , π₯2 )/π+ ]β©: π Appendix B Proofs from Section IV × Proof of Lemma 6: We deterministically rewrite any normal command π into a focused command β¦πβ§ as follows: β¦β¨π+ β ββ©β§ = β¨β¦π+ β§π+ β ββ© = β¨π₯+ β β¦π+ β§π+ βππ₯Μ +.π β© β¦β¨π₯+ β π+ β©β§ β¦β¨π₯β β πβ β©β§ = β¨π₯β β β¦πβ β§πβ β© β¦β¨π‘β β ββ©β§ = β¨β¦π‘ββ§π‘β ⧡πββ.π β ββ© β¦π₯+β§π+ β¦(π1 , π2 )β§π+ β¦π1 π β§π+ β¦π+ β§π β¦π ββ .πβ§π β¦π‘ββ§π β¦π₯ββ§π‘β ⧡πββ.π β¦π(π₯ β β).πβ§π‘β ⧡πββ.π = = = = = βEπ = = β² Rπ Μ β Eβ β³ Rπ Μ Proof of lemma 9.: By induction. To justify the induction we need an induction measure that is strictly decreasing on, for example, π[(π₯1 , π₯2 )/π+ ] β‘A β¨(π₯1 , π₯2 ) β π(π₯1 , π₯2 ).π[(π₯1 , π₯2 )/π+ ]β© β β¨π+ β π(π₯1 , π₯2 ).πβ© β‘Aπ β¨π+ β π(π₯1 , π₯2 ).πβ© π₯+ (β¦π1 β§π , β¦π2 β§π ) π1 β¦π β§π β¦π+ β§π+ π ββ .β¦πβ§ π ββ .β¨β¦π‘β β§π‘β ⧡πββ.π β ββ© π₯β π(π₯ β β).β¦πβ§ As in the article of Abel and Coquand and in Goguen [28] they reference, we simply need an induction measure that favors abstractors over constructors, eg: |β¨π β ππ.πβ©| Μ |β¨ππ.π β πβ©| |β¨π [ππ ] β π[ππ ]β©| βΆ= 2.|π| βΆ= 2.|π| βΆ= Ξ£π |ππ | + Ξ£π |ππ | + 1 Remark then that the sum of the measures of the premises is strictly inferior to the sum of the measures of its conclusion, justifying building such derivations by induction. β To prove transitivity of the extended algorithmic equivalence, we ο¬rst need a lemma. Let us write βπβR for the βR -normal form of π. Lemma 23. Any derivation of βπ1 βR β‘A+π βπ2 βR can be turned into a derivation of βπ1 [π/π+ ]βR β‘A+π βπ2 [π/π+ ]βR (resp. βπ1 [π/πβ ]βR β‘A+π βπ2 [π/πβ ]βR ) of equal or smaller height when π does not appear in π1 , π2 . Proof of lemma 23.: The proof goes by induction on the ( β‘A+π )-derivation, with a strengthened induction hypothesis: for any substitution π, pattern π and value π+ (respectively stack πβ ), any derivation of βπ1 πβR β‘A+π βπ2 πβR can be turned into a derivation of βπ1 [π/π+ ]πβR β‘A+π βπ2 [π/π+ ]βR (respectively βπ1 [π/πβ ]πβR β‘A+π βπ2 [π/πβ ]βR ) of equal or smaller length, when π does not appear in π1 , π2 or π. Let us assume, for instance, that the last rules of our assumption are of the following form: βπ1 π[π1/π1 π]βR β‘A+π βπ2 π[π1/π1 π]βR β π1 π[π1/π1 π] β‘A+ π2 π[π1/π1 π] β β¨π1 π β ππ1 .π1 πβ© β‘A+π π2 π β¨π₯+ β ππ₯ Μ +.π β³ β© + Μ +.π β³ β©β© β¨π₯ β π(π₯1 , π₯2 ).β¨(π₯1 , π₯2 ) β ππ₯ + β³ β¨π₯ β π(π₯1 , π₯2 ).π [(π₯1 , π₯2 )/π₯+]β© If we use this property with π β³ = π β² , we obtain π β² βRE β¨π₯+ β π(π₯1 , π₯2 ).π β² [(π₯1 , π₯2 )/π₯+]β© If we use it with β¨π₯+ β π(π₯1 , π₯2 ).πβ© as a whole, we get: βRE = βRβ β¨π+ β ππ₯ Μ +.π[π₯+/π+ ]β© Μ +.π[π₯+/π+ ]β©β© β¨π+ β π(π₯1 , π₯2 ).β¨(π₯1 , π₯2 ) β ππ₯ β¨π+ β π(π₯1 , π₯2 ).π[(π₯1 , π₯2 )/π+ ]β© (Note that π[π₯+/π+ ][(π₯1 , π₯2 )/π₯+] = π[(π₯1 , π₯2 )/π+ ] because π₯ is assumed fresh in π by the Barendregt convention) β β¦ββ§πβ = β β¦π β πβ§πβ = β¦π β§π β β¦πβ§π β¦ππ₯ Μ +.πβ§π = ππ₯.β¦πβ§ Μ ππ₯.β¨β Μ β¦π+ β§π βEπΜ β β¦π+ β§π+ βππ₯Μ +.π β© β¦ββ§π+ βππ₯Μ +.π = β β¦π[π₯ Μ 1 .π1 |π₯2 .π2 ]β§π+ βππ₯Μ +.π = π[π₯ Μ 1 .β¦π1 β§ |π₯2 .β¦π2 β§] π(π₯, Μ π¦).π = π(π₯, Μ π¦).β¦πβ§ Note that the two ways to translate β¨π₯+β ββ©, as either β¨π+ β ββ© or β¨π₯+ β π+ ⧡ ππ₯ Μ +.πβ©, give the same translation β¨π₯+ β ββ©. β Proof of lemma 7.: By induction on the derivation of algorithmic equivalence. For example in the π(π₯, π¦) case, we need to prove that β¨π₯+ β π(π₯1 , π₯2 ).π β© βRE π β² . Let us remark that we have, for any command π β³ : πβ³ β Rπ Μ β Eβ βR β¨π₯+ β π(π₯1 , π₯2 ).πβ© + + β¨π₯ β π(π₯1 , π₯2 ).β¨π₯ β π(π₯1 , π₯2 ).πβ©[(π₯1 , π₯2 )/π₯ ]β© + + β¨π₯ β π(π₯1 , π₯2 ).β¨(π₯1 , π₯2 ) β π(π₯1 , π₯2 ).π[(π₯1 , π₯2 )/π₯ ]β©β© + + β¨π₯ β π(π₯1 , π₯2 ).π[(π₯1 , π₯2 )/π₯ ]β© + Then, to show that β¨ π₯+ β π(π₯1 , π₯2 ).π[(π₯1 , π₯2 )/π₯+] β© and β¨π₯+ β π(π₯1 , π₯2 ).π β² [(π₯1 , π₯2 )/π₯+]β© are equivalent, it suο¬ces to show that π[(π₯1 , π₯2 )/π₯+] and π β² [(π₯1 , π₯2 )/π₯+] are equivalent, and this is exactly our induction hypothesis. β Proof of lemma 8.: The proof is as for the non-extended version. We used as an intermediate lemma the fact that, for any π, we have π βRE β¨ π₯+ β π(π₯1 , π₯2 ).π[(π₯1 , π₯2 )/π₯+] β© . 14 We have to ο¬nd a derivation for ββ¨π1 β ππ1 .π1 β©[π/π ]πβR β‘A+π βπ2 [π/π ]πβR of equal and smaller height. There are two possible cases for the structure of ββ¨π1 β ππ1 .π1 β©[π/π ]πβR that is ββ¨π1 [π/π ]π β ππ1 .π1 [π/π ]πβ©βR : either the constructor π1 [ π/π ]π does not match the abstractor ππ1 , and the βR -normal form is just β¨ π1 [π/π ]π β ππ1 .βπ1 [π/π ]πβR β© , or it does, and we have a head β³R -reduction to perform. In the ο¬rst case, let us write π1β² for βπ1 [π/π ]βR . We can perform the following ο¬rst steps of inference (with the top sequent still to be proved). Let us take π3β² βΆ= π3 [π1/π1 ]. We build a derivation of the form: ββπ1 [π/π ]πβR [π1/π1 π]βR β‘A+π ββπ2 [π/π ]πβR [π1 /π1 π]βR β βπ1 [π/π ]πβR [π1/π1β² π] β‘A+ βπ2 [π/π ]πβR [π1/π1β² π] β β¨π1β² π β ππ1 .βπ1 [π/π ]πβR β© β‘A+ βπ2 [π/π ]πβR π βπ1 [π1/π1 ]βR [π3 /βπ3β² βR ] β‘A βπ3 [π1 /π1 ]βR [π3/βπ3β² βR ] β βπ1 [π1 /π1 ]βR β‘A+π ββ¨ππ3 .π3 [π1/π1 ] β π β²3 β©βR β π1 [π1/π1 ] β‘A+ β¨ππ3 .π3 [π1/π1 ] β π β²3 β© β β¨π1 β ππ1 .π1 β© β‘A+π β¨ππ3 .π3 β π3 β© Notice that ββπ1 [π/π ]πβR [π1/π1β² π]βR is equal to β² ββπ1 [π/π ]πβR [π1/π1 π]βR . The top sequent is then proved by induction hypothesis, using the larger substitution π[π1/π1β² π]. In the second case, we assume that π1 [π/π ]π starts with the same head constructor as the pattern π1 . But we assumed that β¨π1 β ππ1 .π1 β©π was a normal form, so we know that π1 π and π1 do not match. If π1 π does not match π1 but π1 [π/π ]π does, the matching part is either brought by π (this means that the occurence of π in π1 is at the top) or the substitution of π1 [π/π ] by π. But the latter is impossible, given that we assumed that π does not appear in π. So we have that π1 = π , and π1 [π/π ]π = π [π/π ]π = ππ = π . In particular, we can always πΌ-rename π1 to be equal to π, and then we can prove our goal To conclude our proof, we need to prove the premise π1 [ π1/π1 ][ π3/π3β² ] β‘A π3 [ π1/π1 ][ π3/π3β² ] (we omit the βR normalization marks for readability of the notation). We build it by induction hypothesis, using transitivity on two (β‘A ) derivations of smaller height. The ο¬rst is π1 [π1/π1 ][π3/π3β² ] β‘A π2 [π1/π1 ][π3/π3β² ], obtained from our hypothesis π1 [π1/π1 ] β‘A π2 [π1/π1 ] by applying the previous lemmaβit is thus strictly smaller than the derivation of β¨π1 β ππ1 .π1 β© β‘Aπ π2 we had as hypothesis. The second, π2 [π1/π1 ][π3/π3β² ] β‘A π3 [π1/π1 ][π3/π3β² ], requires applying the technical lemma on our assumption π2 β‘Aπ β¨ ππ3 .π3 β π3 β© , to get a non-larger derivation of π2 [ π1/π1 ] β‘A β¨ ππ3 .π3 [π1/π1 ] β π3β² β© ; inspecting this derivation, which starts with the same structure as the one for π2 β‘Aπ β¨ππ3 .π3 β π3 β© , gives a non-larger derivation of π2 [π1/π1 ][π3/π3β² ] β‘A π3 [π1/π1 ][π3/π3β² ]. β β² β² ββ¨π1 β ππ1 .π1 β©[π/π ]πβR β‘A+π βπ2 [π/π ]πβR from our assumption βπ1 π[π1 /π1 π]βR β‘A+π βπ2 π[π1/π1 π]βR by the following equational reasoning: = π1 =π = πβπ = π1 =π = = (β³R ) = πβπ = (π1 =π)β§(π1 =π ) = ββ¨π1 β ππ1 .π1 β©[π/π ]πβR β‘A+ βπ2 [π/π ]πβR π ββ¨π1 [π/π ] β ππ1 .π1 [π/π ]β©πβR β‘A+ βπ2 [π/π ]πβR π ββ¨π β ππ1 .π1 [π/π ]β©πβR β‘A+π βπ2 [π/π ]πβR ββ¨ππ β ππ1 .π1 [π/π ]πβ©βR β‘A+π βπ2 [π/π ]πβR Proof of lemma 11.: The proof goes by proving each equation of ( βRE ) admissible for ( β‘A ). This is immediate for ( βR )-reductions thanks to the rule A-R. For the expansions, we have for example the case β¨ π₯+ β π+ β© βEβ + β¨ π₯ β π(π₯1 , π₯2 ).β¨(π₯1 , π₯2 ) β π+ β© β© which is proved by the following inference. β¨(π₯1 , π₯2 ) β π+ β©[(π₯1 , π₯2 )/π₯+] = β¨π₯+ β π+ β©[(π₯1 , π₯2 )/π₯+] β + + β¨π₯ β π(π₯1 , π₯2 ).β¨(π₯1 , π₯2 ) β π+ β©β© β‘A β¨π₯ β π+ β© Note that we do not need to handle the case of the extensions πΈπ and πΈ π,Μ only those that inspect value or stack constructors. Indeed, putting a normal form into focused form, as described in Lemma 6, normalizes the πΈπ, πΜ structure: we have π β³πΈπ,πΜ π β² only if π = π β² . β ββ¨π β ππ1 .π1 [π/π ]πβ©βR β‘A+π βπ2 [π/π ]πβR ββ¨π1 β ππ1 .π1 [π/π ]πβ©βR β‘A+π βπ2 [π/π ]πβR βπ1 [π/π ]πβR β‘A+π βπ2 [π/π ]πβR βπ1 π[π/π π]βR β‘A+π βπ2 π[π/π π]βR βπ1 [π1/π1 ]πβR β‘A+π βπ2 [π1 /π1 ]πβR Proof of lemma 14.: Consider for example the case π1 = β¨π₯+ β π[π§ Μ 1 .[ ]1 |π§2 .[ ]2 ]β©. Given an arbitrary π2 , let us deο¬ne: β Proof of lemma 10.: Combining π1 β‘A π2 and π2 β‘A π3 gives the following series of relations: π1 βR π1β² β‘Aπ π2β² βR π2 βR π2β³ β‘Aπ π3β² βR π3 . By conο¬uence of (βR ) we know that π2β² = π2β³ (they are both normal forms), so we have to prove transitivity with π1β² β‘Aπ π2β² β‘Aπ π3β² . We need to inspect both inference rules; the easy cases are when π2β² starts with an abstractor which guides the equivalence on both sides. The more interesting cases arise when the abstractors guiding the equivalence are in π1β² or π3β² . We detail one of those cases. Suppose we have: π1 [π1/π1 ] β‘A π2 [π1/π1 ] π2 [π3 /π3 ] β‘A π3 [π3/π3 ] β β β¨π1 β ππ1 .π1 β© β‘Aπ π2 π2 β‘Aπ β¨ππ3 .π3 β π3 β© 15 π+ β ππ₯ Μ +.π2 [π1 [ ]] = ππ₯ Μ +.π2 [β¨π₯+ β π[π§ Μ 1 .[ ]1 |π§2 .[ ]2 ]β©] Then we have: π2 [π1 [ ]] β²RπΜ β¨π₯+ β π+ β© βEβ β¨π₯+ β πΜ[π§1 .β¨π1 (π§1 ) β π+ β©|π§2 .β¨π2 (π§2 ) β π+ β©]β© β + βRπ,β Μ 1 .π2 [ ]1 |π§1 .π2 [ ]2 ]β© β¨π₯ β π[π§ Μ =π1 [π2 [ ]] This concludes the proof in the case π1 = Μ 1 .[ ]|π§2 .[ ]] β© . The other cases are rather similar. β¨ π₯+ β π[π§ For example, if π1 = β¨ π₯+ β π(π¦ Μ 1 , π¦2 ).[ ] β© , then again with π+ βΆ= ππ₯ Μ +.π2 [π1 [ ]] we have: π2 [π1 [ ]] β²RπΜ β¨π₯+ β π+ β© βEβ β¨π₯+ β π(π¦ Μ 1 , π¦2 ).β¨(π¦1 , π¦2 ) β π+ β©β© βRπΜ β¨π₯+ β π(π¦ Μ 1 , π¦2 ).π2 [β¨(π¦1 , π¦2 ) β π(π¦ Μ 1 , π¦2 ).[ ]β©]β© βRβ β β¨π₯+ β π(π¦ Μ 1 , π¦2 ).π2 [ ]β© =π1 [π2 [ ]] β Proof of 18: We show that (βM ) β (βREπ½ ) and (βW ) β (βREπ½ ) separately. For (βW ) β (βREπ½ ) we have to show that if π[ ] is a commutative context and π uses no variable bound by π[ ] over its hole(s), then π[π ] βREπ½ π . By case analysis on commutative contexts, we see that π[ ] is necessarily of the form π β² [ππΜ +.[]] (π cannot bind β as π necessarily uses it). We thus have that π[π ] = π β² [ ππΜ +.π ] βRπ β¨ π+β.π β² [β] β ππ₯ Μ +.β¨π₯+ β ππΜ +.π β© β© for a fresh π₯. We now prove that, if π does not use π, then ππΜ +.π βRE ππ¦Μ +.π for a fresh π¦; this allows to conclude with + β² Μ +.β¨π₯+ β ππΜ +.π β©β© βRE β¨π+β.π β² [β] β ππ¦ Μ +.π β© β³π½ π . β¨π β.π [β] β ππ₯ If ππΜ +.π is of the form ππ§ Μ +.π for some variable π§, the result is immediate by πΌ-conversion. If ππΜ +.π is of the form π(π§ Μ 1 , π§2 ).π where π does not use π§1 Μ 1 , π§2 ).β¨(π§1 , π§2 ) β ππ¦Μ +.π β© or π§2 , then we have π(π§ Μ 1 , π§2 ).π βRπΜ π(π§ + for some fresh π¦ , and this is the (πΈβ)-expansion of ππ¦ Μ +.π . + |π§.π ] where π does not use π§, If ππΜ .π is of the form π[π§.π Μ |π§.π ] βR πΜ[π§.β¨π1 π§ β ππ¦ Μ +.π β©|π§.β¨π2 π§ β ππ¦ Μ +.π β©] we have that π[π§.π Μ + for some fresh π¦ , and this is the (πΈβ)-expansion of ππ¦ Μ +.π . For (βM ) β (βREπ½ ) , we have to prove that for any pair of π π independent commutative contexts π1 # π2 and substitution π π π π π π such that π1 = π2 [π], we have π1 [π2 [π ]] βREπ½ π1 [π[π ]] for any focused command π . Again by case analysis on commutative contexts we see that π1 , π2 cannot bind β: a context that binds β over its hole must necessarily have a free occurence of it, and thus cannot be independent with (an πΌ-renaming of) itself. Thus π1 , π2 are of the form π β² [ππΜ +1.[ ]], π β² [ππΜ +2.[ ]] for π1 and π2 πΌ-equivalent through the variable-variable substitution π. We prove that π β² [ππΜ +1.π β² [ππΜ +2.π ]] βREπ½ π β² [ππΜ +1.π [π1/π2 ]] as follows for some fresh π =πΌ π1 =πΌ π2 : β²π½ π β² [ππΜ +1.π β² [ππΜ +2.π ]] + + + β² β¨π β.π [β] β ππΜ 1.β¨π β.π [β] β ππΜ 2.π β©β© + β² Μ +.β¨π₯+ β ππΜ +1.β¨π₯+ β ππΜ +2.π β©β©β© β¨π β.π [β] β ππ₯ βE π+β.π β² [β] ππΜ +.β¨π+ β ππ₯ Μ +.β¨π₯+ β ππΜ +1.β¨π₯+ β ππΜ +2.π β©β©β© β β¨ β© β³R π Μ + + + + β² + + β¨π β.π [β] β ππΜ .β¨π β ππΜ 1.β¨π β ππΜ 2.π β©β©β© β¨π+β.π β² [β] β ππΜ +.π [π/π1 ][π/π2 ]β© β¨π+β.π β² [β] β ππΜ +1.π [π1/π2 ]β© π β² [π [π1/π2 ]] β²Rπ βR =πΌ β³RοΏ½ + β² β Proof of theorem 19.: We have to show that β¨π‘+ β ππ₯ Μ +.π0 β© βREPMW π0 [π‘+/π π₯+ ]. The term π‘ is either of 16 the formπ+β.π0 , or it is a valueβin which case the result is immediate. Let us deο¬ne π1 as the focused normal-form of π0 , and π1 as the focused normal form of π0 . We also deο¬ne as π[ ] the command context, with holes expecting contexts, such that π[β] = π1 and β β fv(π), and as π[ ] the command context, with holes expecting expressions, such that π[π₯+] = π1 and π₯+ β fv(π). We need to prove that π[π+β.π[β]] βREPM β¨π+β.π[β] β ππ₯ Μ +.π[π₯+]β© , the latter being + + (βRE )-equivalent to π[ππ₯ Μ .π[π₯ ]]. The main idea of the proof is that π[ π+β.[ ] ] is covered by (compositions of) commutative contexts independent from π[ ππ₯ Μ +.[ ] ]: it can be described as a multi-hole context π[ β‘1 ][ β‘2 ] β¦ [ β‘π ] such that for each family of values π1 , β¦ , ππ and each family of holes π β [1; π], π[ π1 ] β¦ [ ππβ1 ][ β‘π ][ ππ+1 ] β¦ [ ππ ] is a composition of commutative contexts so that π[ π1 ] β¦ [ ππβ1 ][ π+β.π [ππ₯ Μ +.β¨π₯+ β ββ©] ][ ππ+1 ] β¦ [ ππ ] βP + + π [ππ₯ Μ .π[π1 ] β¦ [ππβ1 ][π β.β¨π₯+ β ββ©][ππ+1 ] β¦ [ππ ]]. Note that the commutation is possible because the contexts are independent. Indeed, the commutative contexts of π[π+β.[ ]] neither use π₯+ (by construction of π[ ]) nor bind it over its hole (any expression binder could be πΌ-renamed), and π[ππ₯ Μ +.] does not use β by construction, and cannot bind it over one of its hole, for β would then be shadowed in π1 = π[β]. In the special case π = 0, π[ ] is in fact a focused command π, and we have to show that π[ππ₯ Μ +.π] βREPMW π. This is immediate by weakening simpliο¬cation (β³W ), as π₯+ is not used in π by construction. Otherwise (π β₯ 1), by iteration on [1; π] we can reorder π copies of π[ππ₯+.[ ]] in front of π, obtaining the term: Μ +1. β¦ π [ππ₯ Μ +π.π [π+β.β¨π₯1 β ββ©] β¦ [π+β.β¨π₯π β ββ©]]] π [ππ₯ those copies can be merged, so this is (βM )-equivalent to π[ππ₯ Μ +.π[π₯+]] as desired. Note that there is no need to interleave merging and phase reordering, as merging does not create new opportunities for phase reordering. It is essential, however, to apply merging on the maximally-reordered command, as reordering command creates merging opportunities. We remark that there is a fundamental asymmetry in the proof technique that follows the asymmetry of the intuitionistic restriction: we permute, duplicate and reorder the value context π[ππ₯ Μ +.[ ]] rather than the control context π[π+β.[ ]], reyling on a notion of βpurityβ that would be invalid in the full classical setting. β