Interpreting a concurrent λ-calculus in differential proof nets (extended version)
IInterpreting a concurrent λ -calculus in differentialproof nets - Extended version Yann Hamdaoui
IRIF, Univ. Paris [email protected]
Abstract
In this paper, we show how to interpret a language featuring concurrency, references and rep-lication into proof nets, which correspond to a fragment of differential linear logic. We prove asimulation and adequacy theorem. A key element in our translation are routing areas, a familyof nets used to implement communication primitives which we define and study in detail.
Dummy classification
Keywords and phrases linear logic concurrency simulation
Digital Object Identifier
The distinctive feature of Linear Logic [5] ( LL ) is to be a resource-aware logic, which explainsits success as a tool to study computational processes. The native language for LL proofs- or rather, programs - are proof nets, a graph representation endowed with a local andasynchronous cut-elimination procedure. The fine-grained computations and the explicitmanagement of resources in LL make it an expressive target to translate various computationalprimitives. Girard provided two translations in its original paper, later clarified as respectivelya call-by-value and call-by-name translation of the λ -calculus [11]. PCF [9] has also beenconsidered. Other works have tackled the intricate question of modeling side-effects. Statehas been considered in a λ -calculus with references [16]. Another direction which has beenexplored is concurrency and non-determinism. The extension of LL with dual structural rules,Differential Linear Logic [4], happens to be powerful enough to accommodate non-determinismas demonstrated by the encoding of a π -calculus without replication [3].These translations allow to relate and compare different computational frameworks. Theybenefit from the consequent work on the semantic and the dynamic of LL which has beencarried for thirty years. They are also of practical interest : the proof net representationnaturally leads to parallel implementations [8, 14, 15] and forms the basis for concreteoperational semantics in the form of token-based automata [2, 7]. In this regard, one mayconsider LL as a “functional assembly language” with a diverse collection of semantics andabstract machines.While λ -calculus is a fundamental tool in the study and design of functional programminglanguages, mainstream programming languages are pervaded with features that enableproductive development such as support for parallelism and concurrency, communicationprimitives, imperative references, etc . Most of them imply side-effects, which are challengingto model, to compose, and to reason about. While some have been investigated individuallythrough the lens of LL , our goal is to go one step further by modeling a language featuringat the same time concurrency, references and replication. The constructs involved in thetranslation are inspired by the approach in [3] for concurrency and non-determinism coupledwith a monadic translation [16] for references. Our goal is to exploit the ability of proof nets © Yann Hamdaoui;licensed under Creative Commons License CC-BY42nd Conference on Very Important Topics (CVIT 2016).Editors: John Q. Open and Joan R. Access; Article No. 23; pp. 23:1–23:36Leibniz International Proceedings in InformaticsSchloss Dagstuhl – Leibniz-Zentrum für Informatik, Dagstuhl Publishing, Germany a r X i v : . [ c s . L O ] F e b λ -calculus in differential proof nets - Extended version to enable independent computations to be done in parallel without breaking the originaloperational semantic. The translation we propose can be seen as a compilation from a globalshared memory model to a local message passing one, in line with proof nets philosophy. Routing areas
In a concurrent imperative language, references are a means to exchange information betweenthreads. In order to implement communication primitives in proof nets, we use and extendthe concept of communication areas introduced in [3]. A communication area is a particularproof net whose external interface, composed of wires, is split between an equal number ofinputs and outputs. Inputs and outputs are grouped by pairs representing a plug on whichother nets can be connected. They are simple yet elegant devices, whose role is similar tothe one of a network switch which connects several agents. Connecting two communicationareas yields a communication area again: this key feature enables their use as modular blocksthat can be combined into complex assemblies. In this paper, we introduce routing areas ,which allows a finer control on the wiring diagram. They are parametrized by a relationwhich specifies which inputs and outputs are connected. Extending our network analogy, communication areas are rather hubs: they simply broadcast every incoming message to anyconnected agent. On the other hand, routing areas are more like switches: they are able tochoose selectively the recipients of messages depending on their origin.
Routing areas aresubject to atomic operations that decompose the operation of connecting communicationareas . These operations also have counterparts on relations.We show that routing areas are sufficient to actually describe all the normal forms ofthe fragment of proof nets composed solely of structural rules. The algebraic description of routing areas then provides a semantic for this fragment.
A Concurrent λ -calculus We consider a paradigmatic concurrent lambda-calculus with higher-order references – λ C below – which has been introduced by Amadio in [1]. It is a call-by-value λ -calculus extendedwith:a notion of threads and an operator k for parallel composition of threads,two terms set( r, V ) and get( r ), to respectively assign a value to and read from a reference,special threads r ⇐ V , called stores, accounting for assignments.In this language, the stores are global and cumulative: their scope is the whole program, andeach assignment adds a new binding that does not erase the previous ones. Reading from astore is a non deterministic process that chooses a value among the available ones. Referencesare able to handle an unlimited number of values and are understood as a typed abstractionof possibly several concrete memory cells. This feature allows λ C to simulate various othercalculi with references such as variants with dynamic references or communication [10]. Thelanguage is endowed with an appropriate type and effects system ensuring termination. Thetranslation is presented on an explicit substitutions version of λ C , introduced to serve as anintermediate representation. This intermediate language is presented and studied in detailsin [6]. Contributions.
The contributions of this paper are: . Hamdaoui 23:3
We introduce and study routing areas which are flexible devices for implementing commu-nication in proof nets. From routing areas we derive a semantic for a fragment of proofnets.We illustrate the use of routing areas by translating a concurrent λ -calculus to proof nets.Routing areas are the building block of this translation.We prove a simulation and adequacy theorem for this translation. Plan of the paper.
In Section 2, we detail our proof nets setting and state its propertiesWe go on to define routing areas and study them more in detail in Section 3.In Section 4, we introduce the source language of our translation, the concurrent λ -calculus λ C .Section 5 is devoted to the translation. We explain its underlying principles and givesome representative cases.Section 6 gives the simulation, termination and adequacy theorems together with theirproof. In this section, we detail the proof nets that we are considering in the rest of the paper.We do not attempt to give a full treatment of proof nets. We recall the important notionsand specify the system that we use. The interested reader may find more details in [13] forexample. Proof nets are a representation of proofs as multigraphs, where edges - called wires - correspond to the formulas, and nodes - cells - correspond to the rules. We can decomposeour system into three different layers:
Multiplicative
The multiplicative fragment is composed of the conjunction ⊗ and the dualdisjunction ` . These connectors can express the linear implication (cid:40) and are thus ableto encode a linear λ -calculus, where all bound variables must occur exactly once in thebody of an abstraction. Exponential
The exponentials enable structural rules to be applied on particular formulasdistinguished by the ! modality (its dual being ?). Structural rules correspond to duplica-tion (contraction) and erasure (weakening) : the multiplicative exponential fragment isthe typical setting to interpret the λ -calculus. Differential
Non determinism is expressed by using two rules from Differential LL : cocon-traction and coweakening. Semantically, contraction is thought as a family of diagonalmorphisms cntr A : ! A → ! A ⊗ ! A , each one taking a resource ! A and duplicate it into apair ! A ⊗ ! A . Dually, cocontraction is a morphism going in the opposite direction, packingtwo resources of the same type into one : cocntr A : ! A ⊗ ! A → ! A . What happens whenthe resulting resource is to be consumed ? Two incompatible possibilities : either the leftone is used and the right one is erased, or vice-versa. This corresponds to the rule nd → (see Table 2) in proof nets: the reduction produces the non-deterministic sum of the twooutcomes. Cocontraction will be used as an internalized non-deterministic sum. Whileweakening weak A : ! A → erases a resource, the dual coweakening produces a resourceex nihilo: coweak A : → ! A . This resource can be duplicated or erased, but any attemptto consume it will turn the whole net to . Coweakening produces a Pandora box with a0 inside. It is the neutral element of cocontraction. C V I T 2 0 1 6 λ -calculus in differential proof nets - Extended version one tensor par derelictioncontraction cocontraction weakening coweakening exponential box (! p ) Table 1
Cells and box
One can define a correctness criterion to discriminate nets that are well-behaved - theones that are the representation of a valid proof - ensuring termination and confluence of thereduction. We will not require it here (cf Section 7). Without the correctness criterion, thefull fledged reduction of (differential) LL is not even confluent, let alone terminating. We addconstraints in order to recover an suitable system that is confluent and verifies a terminationproperty (Theorem 3). Let us now give the definition of proof nets and their reduction: (cid:73) Notation 1.
We recall some vocabulary of rewriting theory that we use in the following.A term of a language or a proof net t is A normal form if it can’t be reduced further
Weakly normalizing if there exists a normal form n such that t → ∗ n Strongly normalizing if it has no infinite reduction sequence
Confluent if for all u, u such that u ∗ ← t → ∗ u , there exists v such that u → ∗ v ∗ ← u A rewriting relation is confluent if all terms are. (cid:73)
Definition 1.
Proof netsGiven a countable set, whose elements are called ports, a proof net is given by A finite set of ports A finite set of cells. A cell is a finite non-empty sequence of pairwise distinct ports, andtwo cells have pairwise distinct ports. The first port of a cell c is called the p rincipal portand written p ( c ), and the ( i + 1)th the i th auxiliary port noted p i ( c ). The number ofauxiliary ports is called the a rity of the cell. A port is free if it does not occur in a cell. A labelling of cells by symbols amongst { , ⊗ , ` , ? , ! } . We ask moreover that the arityrespects the following table: Symbol ` ⊗ ? ! ! p Arity 2 2 0 , , i ≥ A partition of its ports into pairs called w ires. A wire with one (resp. two) free port is afree (resp. floating) wire. A labelling of wires by MELL formulas: F ::= 1 | ⊥ | F ` F | F ⊗ F | ! F | ? F . A wire( p , p ) labelled by F is identified with the reversed wire ( p , p ) labelled by F ⊥ . We willabusively confuse ports with the wire attached to them. A mapping from ! p nodes - called exponential boxes - to proof nets with no floating wiresand n ≥ A and the remaining ones by ! B , . . . , ! B n − . The corresponding ! p node must have! A as principal port and ! B , . . . , ! B n − as auxiliary ports.The different kind of cells are illustrated in Figure 1. We directly represent ! p cells astheir associated proof net delimited by a rectangular shape. We impose that labels of wiresconnected to a cell respect the one given in Figure 1, i.e that nets are well-typed . . Hamdaoui 23:5 ` ⊗ m → ?! π e → π ? ! π d → ! π ! π ?! π er → (cid:15) ! π ! σ c → ! π ! σ ? ! nd → ?? + ?? ! ? ba → !!?? ! ? s → !! ! ? s → ??! ? (cid:15) → (cid:15) Table 2
Reduction rules ? ≡ ? ? ? ≡ ? ? ? ? ≡ ! ≡ ! ! ! ≡ ! ! ! ! ≡ Table 3
Equivalence relation
The reduction rules are illustrated in Table 2. Notice that the exponential reductions arerequired to operate on closed boxes (boxes without auxiliary doors). er → and e → may beperformed at any depth. All the other rules are only allowed at the surface: reduction insideboxes is prohibited.We quotient the proof nets by associativity and commutativity of contraction and cocon-tractions. We also include in the relation the neutrality of (co)weakening for (co)contraction(Table 3).We denote by → the full reduction, extended to sums of nets in the same way as in [4]. (cid:73) Theorem 2.
ConfluenceThe reduction → is confluent. Proof.
The reduction is similar in spirit to an orthogonal reduction in a term rewritingsystem. In the same approach as the proof of confluence of the λ -caluclus, we can definea parallel reduction ⇒ , which allow to perform an abritrary number of step in parallel(meaning that we can’t reduce redexes that are created by other the other steps). Thisparallel reduction verifies →⊆⇒⊆→ ∗ . Then we prove that ⇒ has the diamond property,and the previous expression ensures that → ∗ ⊆⇒ ∗ , thus → ∗ is confluent. (cid:74) (cid:73) Theorem 3.
A net is weakly normalizing if and only if it is strongly normalizing.
C V I T 2 0 1 6 λ -calculus in differential proof nets - Extended version To prove Theorem 3, we proceed in two steps. First, we consider the system where allreductions are restricted to the surface. This reduction is constrained enough so that itverifies the diamond property, which is known to implies the Theorem 3. Then, we considerthe non-surface er → and e → reductions, that we write (cid:32) , and show that adding it to * doesnot invalid the theorem. In this subsection, we denote by * all the reductions rules ofFigure 2 applied at the surface. We have the decomposition → = * ∪ (cid:32) . The followinglemma shows that * and (cid:32) have a commutation property: (cid:73) Lemma 4.
SwappingLet S (cid:32) ∗ R and R * + R . Then there exists S such that R R S S * + * + (cid:32) ∗ (cid:32) ∗ Proof.
Lemma 4By induction on both the length of the reduction S (cid:32) ∗ R and R → + R . We consider thefundamental case where both reductions are one-step : R R S * (cid:32) We make the following remarks:As (cid:32) reduction happens inside boxes, and * outside, we can put in a one-to-onecorrespondence the boxes at depth 0 - and thus the * -redexes - of R and S If the reduction in R does not involve a box, it does not interact with (cid:32) , and the diagramcan be closed as a square with one step reduction in every directionIf the reduction in R erases a box, we can erase the corresponding one in S , which maydelete the (cid:32) redex involved reduced in S . In any case we can reduce S to S in one stepby erasing this box and S to R by at most one (cid:32) step.If the reduction in R opens a box, we can open the corresponding one in S . If the (cid:32) -redex was at depth 1 in the same box, then it becomes a * -redex as it now appearsat the surface. Otherwise, it can be performed in one (cid:32) step. In any case, we can closethe diagram by peforming either one * step followed by one (cid:32) step, or two * steps.In the cases listed above, the length of the reduction between R and S never exceedsone, hence we can always fill the following diagram : R R S S ** + (cid:32) (cid:32) Where the bottom line does not involve duplication ( S (cid:32) R if S = R or S (cid:32) R ).Duplication is the only * reduction that can create new (cid:32) redexes, but the bottom * reduction requires exactly one step in S . This corresponds to the following diagram: . Hamdaoui 23:7 R R S S ** (cid:32) (cid:32) ∗ Let us now prove the lemma. We consider the two cases separately : let us assumethat R * R is not a duplication. We perform an induction on the length of the reduction S (cid:32) k R . The induction hypothesis is that we can always fill the following diagram R R S S ** ∗ (cid:32) k (cid:32) k With k ≤ k , and where the bottom reduction does not contain any duplication step.The base case k = 0 is trivially true. For the induction step, if we have S (cid:32) k T (cid:32) R , weuse the first diagram of the remarks to get the middle line T * ∗ T p . Then, we apply theinduction hypothesis on each reduction step T i → T i +1 , which we can do precisely becauseour IH states that the lengths k i of each reduction S i (cid:32) k i T i verify k i ≤ k i − ≤ . . . ≤ k . Wepaste all the diagrams and get R R T T . . . T p S S . . . S p * * * * * * * (cid:32) (cid:32)(cid:32) ∗ (cid:32) ∗ (cid:32) ∗ The case of duplication is simpler as the step R * R is reflected by just one step S * S in the second diagram of the remarks. Our IH is now that we can fill the diagram, withoutfurther assertion on the length of the (cid:32) reduction. Indeed, if S (cid:32) k T (cid:32) R , we use theone-step diagram to get T and apply the IH to fill the bottom part with S : R R T T S S *** (cid:32)(cid:32) k (cid:32) ∗ (cid:32) ∗ Finally, we can perform a second induction on the length of the reduction
R → + R toget the final result. (cid:74) Writing a reduction
R → ∗ S as blocks R (cid:32) ∗ R * ∗ R (cid:32) ∗ . . . * ∗ R n , we can iterateLemma 4 to form a new reduction sequence with only two distinct blocks: C V I T 2 0 1 6 λ -calculus in differential proof nets - Extended version (cid:73) Lemma 5.
StandardizationLet
R → ∗ S . Then R * ∗ R (cid:32) ∗ S . Moreover, if the original reduction contains at least one * step, then R * + R . Proof.
Lemma 5This follows from the previous lemma: we decompose the reduction
R → ∗ S as blocks R (cid:32) ∗ R * ∗ R (cid:32) ∗ . . . * ∗ R n , and iterate 4 to gather the reductions into only two distinctblocks. (cid:74) Lemma 6 follows from the observation that as * only acts on surface and (cid:32) inside boxes,the latter can not interact with the redexes of the former. (cid:73) Lemma 6.
Neutrality of (cid:32)(cid:32) does not create nor erase * -redexes. In particular, if R (cid:32) ∗ R , then R is * -normal ifand only if R is. We also need some properties about termination of the reduction * and (cid:32) : (cid:73) Lemma 7.
Strong normalization for (cid:32)(cid:32) is strongly normalizing.
Proof.
It suffices to note that opening or deleting a box strictly decreases the total numberof boxes in the net. (cid:74)(cid:73)
Lemma 8.
Theorem 3 is true when replacing → with * . Proof.
The surface reduction satisfies the diamond property, which excludes the existence ofa weakly normalizing term with an infinite reduction. (cid:74)
We can finally prove Theorem 3:
Proof.
Theorem 3We prove two auxiliary properties: (a) → -weak normalization implies * -weak normalization Let R be → -weakly normalizing, R → ∗ N a reduction to its normal form. By 5, we canwrite R * ∗ S (cid:32) ∗ N . N being a → -normal form, it is also a * -normal form, and by 6so is S . R is thus a * -weakly normalizing. (b) an infinite → -reduction gives an infinite * -reduction Let R be a net with an infinite reduction, written R → ∗ ∞ . We will prove by inductionthat for any n ≥
0, there exists R n such that R * n R n → ∗ ∞ .Case n = 0We just take R = R Inductive caseIf R * n R n → ∗ ∞ , we take any infinite reduction starting from R n . If the first stepis R n * S , then we take R n +1 = S . Otherwise, the first step is a (cid:32) step, and we takethe maximal block of (cid:32) reduction starting from R n . By 7, this block must indeed befinite and we can write R n (cid:32) ∗ S * S → ∞ . By 4, we can swap the two blocks suchthat R n * R * ∗ R (cid:32) ∗ S , and we take R n +1 = R .From these two points follows that → -weak normalization implies → -strong normalization.If a net is → -weakly normalizing, then it is * -weakly normalizing by (a). By 8, it is also * -strongly normalizing. But by (b) it must be also → -strongly normalizing. (cid:74) The next section focuses on a specific family of proof nets that play a key role in theexpression of communication primitives inside proof nets. . Hamdaoui 23:9
Let us now define and study a special kind of nets: the routing areas . It is a generalization ofthe construction of communication areas introduced in [3]. The approach is similar: we aimat constructing nets to be used as building blocks to implement communication primitives.We shall see that this seemingly restricted class of nets is actually the set of normal formsof a fragment of proof nets (Theorem 16). Routing areas are composed only of structuralrules: contraction, weakening, cocontraction and coweakening. These basic components actas resource dispatchers (a resource designates a closed exponential box in the following):A free wire acts as the identity. It passively forwards a resource that is connected on the input (the left port) to the output (the right port).?A contraction is a broadcaster with one input and two outputs. A resource connected onthe left will be copied to both outputs on the right. A weakening is a degenerate caseof a broadcaster with zero outputs as broadcasting something to no one is the same aserasing it.!Dually, a cocontraction is a packer with two inputs and one output. A packer aggregatesits two inputs non deterministically. When a dereliction is connected to the output toconsume two packed resources, a non-deterministic sum of the two possible choices forthe one to be provided is produced. Similarly, coweakening is seen as a degenerate packerwith no inputs.A routing area can be seen as a router, or a circuit, between inputs and outputs. Inputsare connected to contractions which broadcast resources they receive to cocontractions.Cocontractions may gather resources from multiple such sources. The conclusion of thesecocontractions form the outputs. A routing area is then described by a slight generalizationof a relation between sets, a multirelation . Its role is to define the wiring diagram whichspecifies which inputs and outputs are connected. Let us first introduce multirelations:
Multirelation
Let A and B be two sets, a multirelation R between A and B is a multiset ofelements of A × B , or concretely a map R : A × B → N . For k ∈ N , we write x R k y if R ( x, y ) = k . Relations and multirelations
A relation R between A and B can be seen as a multirelationby taking its characteristic function R .Conversely, we can forget the multiplicity ofa multirelation S and recover a relation by taking the subset of A × B defined by { ( x, y ) ∈ A × B | S ( x, y ) ≥ } . Composition
Multirelations enjoy a composition operation that computes all the ways togo from an element to another with multiplicities. For multirelations
R, S respectivelybetween A and B , and B and C ,( S ◦ R )( x, z ) = X y ∈ B R ( x, y ) S ( y, z )This composition is associative, coincides with the usual one for relations, and hasthe identity relation (seen as a multirelation) for neutral. This is in fact the matrixmultiplication, seeing a multirelation between A and B as a | B | × | A | matrix with integercoefficients R ( i, j ) (identifying finite sets with their cardinal). C V I T 2 0 1 6 λ -calculus in differential proof nets - Extended version The FMRel Category
Finite sets and multirelations between them form a category
FMRel ,with the category
FRel of finite sets and relations as a subcategory.
FMRel has finitecoproducts, extending the one of
FRel , and corresponding to the direct sum of matrices.A routing area is described by a multirelation between its inputs and its outputs. Itsvalue at the pair ( i, o ) indicates how many times the input i is connected to the output o .We are now ready to construct the routing area defined by a multirelation. (cid:73) Definition 9.
Routing areaLet L i , L o be two finite sets called the input labels and the output labels, and a multirelation R between L i and L o . A routing area R associated to the triplet ( L i , L o , R ) is a netconstructed as follows:It has |L i | + |L o | free wires partitioned into |L i | inputs and |L o | outputs . Each input islabelled by a distinct element of L i , while outputs are labelled by distinct elements of L o .Each input (resp. output) is connected to the main port of a contraction (resp. cocon-traction) tree. Then, for every ( i, o ) ∈ L i × L o , we connect the tree of the input i to thetree of output o with exactly R ( i, o ) wires.?? !!We represent them as rectangular boxes, with the inputs appearing on the left and outputson the right. (cid:73) Definition 10.
ArityLet ( L i , L o , R ) be a routing area. For an input i ∈ L i , we define its arity as the number ofleafs of the associated contraction tree given by ar ( i ) = P o ∈L o R ( i, o ). Similarly, the arityof an output o ∈ L o is defined by ar ( o ) = P i ∈L i R ( i, o ). The set of outputs (resp. inputs)connected to an input i (resp. output o ) is defined as co ( i ) = { o ∈ L o | R ( i, o ) ≥ } (resp. co ( o ) = { i ∈ L i | R ( i, o ) ≥ } ). In general, for an input or an output x , ar ( x ) ≤ | co ( x ) | .This is an equality for all x if and only if R is a relation.Routing areas may be combined in two ways such that the resulting proof net reduces toa new routing area. The multirelation describing the result can be computed directly fromthe initial multirelations of routing areas involved, giving a way of building complex circuitsfrom small components. Operations
The first operation, juxtaposition, amounts to put side by side two routing areas. Theresult is immediately seen as a routing area itself, described by the coproduct of the twomultirelations: (cid:73)
Definition 11.
JuxtapositionLet R = ( L i , L o , R ) and S = ( L i , L o , S ), we define the juxtaposition R + S by ( L i + L i , L o + L o , R + S ). The corresponding net is obtained by juxtaposing the nets of R and S : RS = R + S . Hamdaoui 23:11 The second one is more involved: the trace operation consists in connecting an input to anoutput given that they are not related to begin with, to avoid the creation of a cycle. Doingso, we remove this output and input from the external interface, and create new internalpaths between remaining inputs and outputs. If we reduce the resulting net to a normalform, we obtain a new area, whose multirelation can be computed from the initial one. (cid:73)
Definition 12.
TraceLet R = ( L i , L o , R ) be a routing area, and ( i, o ) ∈ L i × L o . The trace at ( i, o ) of R isobtained by connecting the input i with the output o of R and reducing this net to its normalform. (cid:73) Property 1.
Trace is a routing areaLet R = ( L i , L o , R ) be a routing area, and ( i, o ) ∈ L i × L o such that i R o . Then the traceat ( i, o ) of R is a routing area T : R → ∗ T Where T = ( L i − { i } , L o − { o } , T ) is defined by the multirelation : T ( x, y ) = R ( x, y ) + R ( x, o ) R ( i, y ) (1)The formula 1 expresses that in the resulting routing area T , the total number of waysto go from an input x to an output y is the number of direct paths R ( x, y ) from x to y thatwere originally in R , plus all the ways of going from x to o times the ways of going from i to y . Indeed, any pair of such paths yields a new distinct path in the trace once i and o havebeen connected. Proof.
Property 1If ar ( i ) = ar ( o ) = 0, then we connected a coweakening to a weakening and we can erase themto recover the desired area where T is just the restriction of R to ( L i − { i } ) × ( L o − { o } ),which agrees with the formula of 1 as the product R ( x, o ) R ( i, y ) is always zero.Now, assume that ar ( o ) = 0 < ar ( i ). We can reduce the introduced redex as follow :! ? → ∗ !!These coweakening are connected to the trees of the outputs co ( i ). These are eitherconnected to a wire, or a cocontraction tree and we can eliminate superfluous coweakeningusing the equivalence relation. Once again, we didn’t create new paths and recover an areawhose relation is the restriction of R , still agreeing with the formula as ar ( i ) = 0 implies R ( x, o ) R ( i, y ) being zero again. The dual case ar ( i ) = 0 < ar ( o ) is treated the same way.The general case relies on the commutation of contractions and cocontractions trees thatcan be derived by iterating the ba → rule. We can apply the following reduction on the trees of i and o that have been connected : C V I T 2 0 1 6 λ -calculus in differential proof nets - Extended version where wires i , . . . , i p are connected to the trees of the inputs in co ( o ) and o , . . . , o q tothe trees of the outputs of co ( i ). The reduced net now has the shape of a routing area. Asbefore, the direct paths between x and y when x = i and y = o are left unchanged. But anycouple of paths in R between x and o arriving at some i k and between i and y arriving atsome o l yields exactly one new path between x and y in the new area (see 4 below). Bydefinition, there are R ( x, o ) paths connecting x to o and R ( i, y ) connecting i to y : hencethere are R ( x, o ) R ( i, y ) such couples. (cid:74) These two operations are sufficient to implement composition which is the connectionof an output of an area to an input of another area. Composition is a fundamental featureof routing areas. This is what makes them modular, allowing to build routing areas bycomposing simple blocks. To connect an output o of R to an input i of S , we first performthe juxtaposition followed by a trace at ( i, o ). This is similar both in form and in spirit, tothe composition of Game Semantic or Geometry of Interaction whose motto is “composition= parallel composition plus hiding”. (cid:73) Corollary 13.
CompositionLet R = ( L i , L o , R ) and S = ( L i , L o , S ) be two routing areas, o ∈ L o and i ∈ L i . Then thenet resulting from connecting the output o to the input i can be reduced to a new routing area T = ( L i + L i − { i } , L o + L o − { o } , T ) R S → ∗ T (cid:73) Remark.
This operation can be generalized to the connection of n outputs of R to n inputsof S . When n = |L o | = |L i | , the multirelation T describing the resulting routing area is thecomposed S ◦ R .The following property gives the high level operational behavior of a routing area. Itsupports our interpretation of routing areas as dispatchers of exponential boxes. Given aclosed exponential box, we connect it to the auxiliary port of a cocontraction to obtain amodule which can then be connected to an input i of an area. Through reduction, the boxwill traverse the area and be duplicated R ( i, o ) times to each output o . The role of theadditional cocontraction is to preserve the area and allow future connections to the sameinput. We would get a similar transit property connecting directly the exponential box to i ,but the process is destructive as it erases the input wire of i and prevents any future use. (cid:73) Property 2.
TransitLet σ be a closed exponential box, R = ( L i , L o , R ) a routing area, i ∈ L i . Let { o , . . . , o p } = co ( i ) and for 1 ≤ k ≤ p, c k = R ( i, o k ). Then : . Hamdaoui 23:13 The property is straightforward application of reduction rules and the net equivalence.
Routing areas do not only fulfill practical needs. They are general enough to be the languageof normal forms of routing nets . Let us first give a precise definition. A correct net is a netsatisfying the correctness criterion defined in [4]: (cid:73)
Definition 14.
Routing netsA routing net R is a correct net composed only of weakenings, coweakenings, contractions,cocontractions, and possibly floating wires. Moreover, we ask that all wires are labelled withthe same formula ! A , fixing de facto their orientation.Paths will also be of interest in the rest of this subsection. (cid:73) Definition 15.
PathsLet R be a net. We recall that for a cell c of R , we write p i ( c ) for its i -th auxiliary port (if itexists) and p ( c ) for its main port. For a wire w , s ( w ) designates the source port of w while e ( w ) is its end port. Let R be a net without exponential boxes, we construct the associatedundirected graph G ( R ) with ports as vertices and: Wire edges
For any wire w of R , we add an edge between s ( w ) and e ( w ). Cell edges
For every auxiliary port p i ( c ) of a cell, we add an edge between p i ( c ) and p ( c ).A path p in R is a finite sequence ( p , e , p , e , . . . , e n , p n +1 ) such that p i is a port of R , e i an edge of G ( R ) linking p i and p i +1 and such that e i and e i +1 are of distinct nature(cell/wire edge). We extend s and e to operate on path, defined by s ( p ) = p and e ( p ) = p n +1 .Paths whose starting and ending edges are wire edges can also be described as a sequence ofcorresponding wires ( w , . . . , w m ) as internal ports and cell edges can be recovered. We note P ( R ) the set of paths in R and P f ( R ) the paths starting and ending on free ports.Albeit closed to switching paths (the ones involved in the correctness criterion), theydo not match exactly. A path in a switching graph can arrive at an auxiliary port of acocontraction and bounce back in the other, while the paths we have defined here mustcontinue via the principal port. However, a correct (routing) net do not contain cyclic paths,which means that switching acyclicity implies acyclicity: (cid:73) Property 3.
Acyclicity of correct netsA routing net is acyclic, that is there is no path p such that s ( p ) = t ( p ). Proof. (cid:74)
We now state a fundamental property relating reduction to paths: (cid:73)
Property 4.
Path preservationLet R be a routing net, p and p be free ports. We write P f ( R , p , p ) = { p ∈ P f ( R ) | s ( p ) = p , e ( p ) = p } . If R → R , then P f ( R , p , p ) = P f ( R , p , p ). In particular, P f ( R ) = P P f ( R , p i , p i ) = P f ( R ). C V I T 2 0 1 6 λ -calculus in differential proof nets - Extended version Proof. P f ( R, p , p ) mustbegin and end in a free port, it can’t go through a weakening or a coweakening, and thecorresponding reductions leave such paths unchanged. The only relevant reduction is the ba → rule: Let us define the application τ : P f ( R, p , p ) → P f ( R , p , p ). For a path p which does notcross the redex, τ ( p ) = p . Otherwise, we replace any subsequence in the left column by theone in the right column: Subsequence Image by τi , c, o i , c , o i , c, o i , c , o i , c, o i , c , o i , c, o i , c , o We omitted the four other possibilities which can be deduced from this table by reversingboth the subsequence and its image. It is easily seen that τ is an bijection. (cid:74) The following theorem establishes the link between routing areas and normal forms ofrouting nets. We propose two different intuitive explanations of why the theorem holds: The basic components of routing nets, (co)contractions, wires and (co)weakenings, arerouting areas. Then, juxtaposition and trace operations are general enough to combinethem into an arbitrary routing net that reduces to a routing area according to Property 1. In a routing net, the ba → rule allows to commute all contractions and cocontractions. Then,by equivalence, we can erase weakenings and coweakenings that are not connected to afree wire. At the end of this process, the resulting net must have the shape of a routingarea. (cid:73) Theorem 16.
Routing area characterizationThe normal form of a routing net S is a routing area R = ( L i , L o , R ) . For a routing net S , we can define the application (cid:74) . (cid:75) : S 7→ R that maps S to themultirelation R describing its normal form. By unicity of normal forms, this application isinvariant by reduction and is thus a semantic for routing nets. It has the following properties: Soundness
The multirelation only depends on the normal form.
Adequacy
Two routing nets with the same denotation have the same normal form because amultirelation defines a routing area uniquely.
Full completeness
Any multirelation between finite sets is realized by the associated routingarea.
Compositionnality
We can compute the semantic of a net in a compositional way from thesemantic of its smaller parts through juxtaposition and trace.
Proof.
Theorem 16We prove the result by induction on the number n of cells of R .( n = 0) R is only composed of free wires. We take L i = { s ( w ) | w wire } , L o = { e ( w ) | w wire } and R is the relation defined by i R o ⇐⇒ ∃ w, i = s ( w ) , o = e ( w ). . Hamdaoui 23:15 (induction step) Let take any node N of R . We call R the subnet obtained by removing N and replacing its ports by free ports.By induction, R can be reduced to a routing area R . (co)weakening If N is a weakening or coweakening, it is a routing area and can becomposed with R , and reduced to a new routing area R according to 13. Thus wecan reduce the whole net to R . (co)contraction If N is a contraction or a cocontraction, it can still be seen as a routingarea and we juxtapose it to R . What remains to do is to perform three tracesoperations to recover the original net and reduce the whole net to a routing area R .However, we must ensure that the input and the output we connect at each step arenot already connected in the routing area. The first operation is always legal, as it isactually a merge operation of previously disjoint areas. The following traces are alsovalid, as reduction does not create cycles, as implied by 4. (cid:74) For a routing net S , we can define the application (cid:74) . (cid:75) : S 7→ R that maps S to themultirelation R describing its normal form. By unicity of normal forms, the applicationis invariant by reduction and is thus a semantic for our routing nets, with the followingremarkable properties: Sound
The multirelation only depends on the normal form, this is invariant by reduction.
Adequate
Two routing nets with the same denotation have the same normal form, as amultirelation define a routing area uniquely.
Fully complete
Any multirelation on finite sets is realised by the associated routing area.
Compositionnal
We can compute the semantic of a net in a compositional way from thesemantic of its smaller parts, through juxtaposition and trace.This semantic can be defined without resorting reduction, by counting paths. (cid:73)
Theorem 17.
Path semanticLet S be a routing net. Let L i be the set of free ports of S which are the source point of awire, and L o the ones that are the end point. Then (cid:74) S (cid:75) is the multirelation between L i and L o given by (cid:74) S (cid:75) ( i, o ) = | P f ( S , i, o ) | Proof. (cid:74) S (cid:75) : (cid:74) S (cid:75) ( i, o ) counts precisely the number of paths starting at port i andending at port o . C V I T 2 0 1 6 λ -calculus in differential proof nets - Extended version Otherwise, by path preservation (4), this quantity is invariant by reduction. We concludeby induction on the length of the longest reduction of S to its normal form. (cid:74)(cid:73) Remark.
Communication AreasThe communication areas defined in [3] are a special case of routing areas: for n ≤
1, the n -communication area is the routing area ( { , . . . , n } , { , . . . , n } , R ) where x R y ⇐⇒ x = y . (cid:73) Remark.
Canonicity of multirelationsThe multirelation defining an area is actually not unique from a set-theoretic point of view:indeed, for R = ( L i , L o , R ), then all multirelations in { τ − ◦ R ◦ σ : E → F | σ : E → L i , τ : F → L o , σ and τ bijective } describe the same area. Even though this object is a properclass, all these relations are considered isomorphic (for example, in the arrow category of FMRel ). After all, even finite deterministic automata suffer this kind of subtlety, which isnot relevant in practice.We are now armed to encode communication primitives. This is illustrated in Section 5by the translation of the λ C calculus, succinctly described in the following section. λ -calculus λ C We present the λ C [1] calculus, following the presentation in Madet’s Ph.D thesis [10].The λ C calculus is a call-by-value λ -calculus, equipped with references that abstract thenotion of global memory cells. The calculus is enriched with a parallel composition operator k for modeling concurrency. Variables are denoted with x, y, . . . while references are denoted with r, s, . . . . The languageconsists of values , terms , stores and programs . A store is a top-value set of associationsbetween references and values, while a program is a store together with a set of terms. Theterms in a program can be regarded as threads running in parallel, while the stores representthe state of the global memory. Programs are the objects of interest in λ C . -values V ::= x | ∗ | λx.M -terms M ::= V | M M | get( r ) | set( r, V ) | M k M -stores S ::= r ⇐ V | ( S k S )-programs P ::= M | S | ( P k P ) The constant value ∗ stands for the return value of a reference assignation: it carries noparticular information. The primitives set( r, V ) and get( r ) respectively writes a value V toand reads from a given reference r . While assignments can be only performed on values, amore general set( r, M ) can be encoded as ( λx. set( r, x )) M for an arbitrary term M . Oncereduced, a set( r, V ) produces the special kind of thread r ⇐ V at top level in a store, adding V as the possible values available for the reference r . Parallelism is accounted for using theoperator k . Terms, programs and stores can be placed in parallel. For stores, this simplymeans that all the corresponding associations reference/value are available for substitutionof reference in the threads. . Hamdaoui 23:17 P k P = P k P ( P k P ) k P = P k ( P k P ) Table 4
Structural Rules E ::= [ . ] | E M | M EC ::= [ . ] | ( C k P ) | ( P k C ) Table 5
Evaluation Contexts( β v ) C [ E [( λx.M ) V ] → C [ E [ M [ V /x ]]]( get ) C [ E [get( r )]] k r ⇐ V → C [ E [ V ]] k r ⇐ V ( set ) C [ E [set( r, V )]] → C [ E [ ∗ ]] k r ⇐ V Table 6
Reduction Rules
The calculus is endowed with the usual structural rules for the parallel operator, namelyassociativity and commutativity (Table 4). The rewrite rules for the language are found inTable 6. Together with the β v rule are two new reductions, one that turns an assignment toa store and one that turns a get to a value. The rules use the evaluation contexts defined inTable 5 to handle congruence. The context E denotes a weak call-by-value weak reductionwhich is neither right-to-left or left-to-right. The context C allows reduction to occurs in anythread of a program.The substitution of a reference is a non-deterministic operation. Reference must beseen as an abstraction for a set of typed memory cells that can hold many values. Letproj = λxy.x and proj = λxy.y be the Church projections, and consider the term P = ( λx.x V V ) get( r ) k ( λy. set( r, y )) get( s ) k set( s, proj ) k set( s, proj )The two assignment can be reduced to stores : P → ∗ ( λx.x V V ) get( r ) k ( λy. set( r, y )) get( s ) k ∗ k ∗ k s ⇐ proj k s ⇐ proj for some distinct values V and V . Here, get( s ) have essentially two incompatible ways toreduce : either it is replaced by proj or by proj . In the first case, P → ∗ ( λx.x V V ) get( r ) k set( r, proj ) k P → ∗ ( λx.x V V ) get( r ) k ∗ k r ⇐ proj k P → ∗ ( λx.x V V ) proj k ∗ k r ⇐ proj k P → ∗ V k ∗ k r ⇐ proj k P where P = ∗ k ∗ k s ⇐ proj k s ⇐ proj . However if get( s ) is replaced by proj , we getthat P → ∗ V k ∗ k r ⇐ proj k P : P has two distinct normal forms.Despite the k operator being a static constructor, it can be embedded in abstractions andthus dynamically liberated or duplicated. For example, the term ( λf.f ∗ k f ∗ ) act like a fork operation: if applied to M , it generates two copy of its argument in two parallel threads M ∗ k M ∗ . The next section is devoted to detailing how terms of λ C are translated to proofnets described in 2, thanks to the areas introduced in 3. To implement the translation, we make use of two specific routing areas that we introducebelow. In the following, E i = { , . . . , i } and R i is the binary relation defined on E i by k R i l ⇐⇒ k = l . C V I T 2 0 1 6 λ -calculus in differential proof nets - Extended version The γ area is defined by ( E , E , R γ = R ). γ is actually a communication area, composedof 3 pairs of input and outputs grouped by label. Each such pair represents a plug to whichtranslated terms will be connected. The definition of R γ expresses that the input and theoutput of a plug are not connected, as a component should not receive the data it sent himself:this would be the analog of a short-circuit. All others inputs and output are connected.The δ area is an analog structure with 4 plugs: ( E , E , R δ ). It is designed to handle theapplication M N which includes three potential sources of effects : The effects e produced by reducing M to λx.M The effects e produced by reducing N to value V N The effects e produced by reducing M [ V N /x ] to the final result V The reduction of λ C imposes that e and e happen before e , while e and e may happenconcurrently. For 1 ≤ i ≤
3, the plug ( i, i ) of δ corresponds to the effects e i . The last oneis the external interface for future connections. We easily accommodate δ to implementsthe sequentiality constraint by removing the couples (3 ,
1) and (3 ,
2) from R to form R δ .Indeed e and e happens before e thus can not observe any assignment made by the latter.Thus we just cut the corresponding wires. We see that the formalism of routing areas allowsus to easily encode the order of effects. Before translating terms, we need to translate the types from the type and effects system for λ C to plain LL formulas. We use the approach of [16], a monadic translation, explained in thefollowing. Before translating to LL , let us first try to take a type with effects and translate itto a pure simple type. Let e = { r , . . . , r n } be an effect (a finite set of references), assumewe can assign a simple type R i to each reference r i . We can type a store S e = R × . . . × R n representing the current state of the memory. We transform a term M of type A producingeffects to a pure term which takes the initial state of the store, and returns the value itcomputes together with the new state of the store after this computation. Using curryficationfor the arrow type, we define the translation: T e ( α ) = S → S × αT e ( A e → α ) = A → ( S → ( S × α )) ∼ = A × S → S × α From there, we go to LL types by implementing the pair type A × B as ! A ⊗ ! B , and theusual call-by-value translation for the arrow ( A → B ) • = !( A • (cid:40) B • ) [11]. We still have todetermine each R i first. Using the previous formula, we may associate an LL type variable X r i to each reference and plug everything together to obtain the following equations (where A i is the type given to r i by the reference context): Unit • = !1( A { s ,...,s m } → α ) • = !(( A • ⊗ X s . . . ⊗ X s m ) (cid:40) ( X s ⊗ . . . ⊗ X s m ⊗ α • )) X r i = A i • This system is solvable precisely because the type system is stratified [16], and we canthus translates all the types of λ C to plain LL types. The behavior type B will be translatedto types of the form A ` . . . ` A n as the translation remembers the types of each threads. . Hamdaoui 23:19 The general form of the translation of a term x : A , . . . , x n : A n ‘ M : ( α, { r , . . . , r k } ) isgiven by M • α • ! X r k r k ! X r k r ! X r k r k ! X r r A • x A • n x n We distinguish three different types of free wires:
Output wire
The right wire, labelled by α • , corresponds to the result of the whole term. Variable wires
Each wire on the left corresponds to a variable of the context. The (explicit)substitution of a variable x for a term V • is obtained by connecting the output wire of V • to the wire of x . References wires
The wires positioned at the top are input wires corresponding to referencesand have a similar role as variable wires, while the wires at the bottom corresponds duallyto the output. References wires will be connected by routing areas.We present some representative cases of the translation: get( r ) and set( r, V ) for referencemanagement, the abstraction to show how effects are thunked in a function’s body followingthe monadic translation, and the application that shows the usage of routing areas to handlenon-trivial effects scheduling. We start with reference operations, which serve as switch fromand to reference wires: Set (Figure 1)
A set( r, V ) connects the output of the translation of V to the output reference wire cor-responding to r . As other assignments are not relevant a weakening is connected on theinput wire to ignore any incoming resource. In λ C , a set reduces to ∗ as it does not computeanything valuable. Consequently the output is the conclusion of a banged 1 which is thetranslation of ∗ .One important remark is that an additional exponential layer is added around thetranslation of V . In a call-by-value language, the non determinism is strict in the sensethat non-deterministic term must be evaluated before any copy. For example, the term( λf x.f x x ) get( r ) k r ⇐ V k r ⇐ V can reduce either to f V V or f V V but not to f V V . Differential LL rather implements the latter call-by-name semantic as hinted at bythe ba → rule which expresses that duplication and non-determinism should commute. Themismatch is due to two different usages we want to make of the !:The first one allows to discriminate what proof nets can be the target of structural rules,which implements substitution. In call-by-value, the only terms that can be substitutedare values. The ! is introduced by the translations of values, using ! p , and eliminated atusage - when applied to another term - for each copy by a dereliction.The second usage relates to the differential part. The bang denotes resources that may bepacked non deterministically by a cocontraction. The choice is made when a derelictionis met.But as we noted, these two usages are in contradiction: a non-deterministic packingshould not be allowed to be substituted. Technically, the dereliction corresponding to the C V I T 2 0 1 6 λ -calculus in differential proof nets - Extended version R ; Γ ‘ r : Reg r A R ; Γ ‘ V : ( A, ∅ ) R ; Γ ‘ set ( r, V ) : (Unit , { r } ) ( set ) Figure 1
Translation of set( r, V ) R ‘ Γ R ; Γ ‘ get( r ) : ( A, { r } ) ( get ) Figure 2
Translation of get( r ) place of usage and the dereliction corresponding to the non-deterministic choice should notbe the same. This is the reason of the additional ! layer introduced by an exponential boxaround V • . The corresponding dereliction is found in the translation of get( r ). Get (Figure 2)
The get( r ), dual of the set, takes a resource from the corresponding input reference wire andredirects it to the output wire. It outputs a coweakening on the reference wire as it does notproduce any assignment. As mentioned in the previous case, a dereliction is added on theinput wire to force the non-deterministic choice and strip the exponential layer added by theset. Abstraction (Figure 3)
The abstraction thunks the potential effects of the body M in the pure term λx.M . Followingthe monadic translation, the input effects are tensorized with the bound variable, and theoutput effects with the output of M . Finally the whole term is put in an exponential box asit is a value. Application (Figure 4)
Finally, the application put the routing area at use. Using the same terminology as inthe introduction of this section, we see the effects e and e coming respectively from theevaluation of M and N , and e , liberated by the body of the function being applied, pluggedon the δ area. R ; x : A, Γ ‘ M : ( α, e ) R ; Γ ‘ λx.M : ( A e → α, ∅ ) ( lam ) Figure 3
Translation of λx.M . Hamdaoui 23:21 R ; Γ ‘ M : ( A e → α, e ) R ; Γ ‘ N : ( A, e ) R ; Γ ‘ V ∈ E i : ( R ( r i ) , ∅ ) R ; Γ ‘ M N [ V ] λ : ( α, e = e ∪ e ∪ e ) ( app ) Figure 4
Translation of
M N λ cES into proof nets We presented some interesting cases of the translation of λ C to proof nets to provide thereader with some intuition. However the complete translation is rather operating on theintermediate language λ cES . A translation and a simulation theorem between λ C and λ cES are given in [6], completing the picture. Typing derivation TranslationΓ , x : A ‘ x : ( A, ∅ ) ( var )Γ ‘ ∗ : ( Unit , ∅ ) ( unit ) x : A, Γ ‘ M : ( α, e )Γ ‘ λx.M : ( A e → α, ∅ ) ( lam )Γ ‘ M : ( A e → α, e ) Γ ‘ N : ( A, e ) Γ ‘ V ∈ E i : ( B i , ∅ )Γ ‘ M N [ V ] λ : ( α, e = e ∪ e ∪ e ) ( app ) C V I T 2 0 1 6 λ -calculus in differential proof nets - Extended version ‘ ΓΓ ‘ get( r ) : ( A, { r } ) ( get ) i = 1 , R ; Γ ‘ P i : α i R ; Γ ‘ P k P : B ( par ) R ; Γ , x : A ‘ M : ( α, e ) R ; Γ ‘ V : ( A, ∅ ) R ; Γ ‘ M [ σ ] : ( α, e ) ( subst ) R ; Γ ‘ M : ( α, e ) R ; Γ ‘ V i : ( A i , ∅ ) R ; Γ ‘ subst ↓| λ ( r i ) = ( V i ) in M : ( α, e ) ( subst - r ↓ ) R ; Γ ‘ M : ( α, e ) R ; Γ ‘ V i : ( A i , ∅ ) R ; Γ ‘ subst ↑ ( r i ) = ( V i ) in M : ( α, e ) ( subst - r ↑ ) We proceed to give the properties satisfied by the translation.
The first result is the simulation theorem. The formulation precises that a deterministicstep in λ C is mapped to a deterministic reduction in nets, and only the reduction of get( r )produces a non-deterministic sum. (cid:73) Theorem 18.
SimulationLet ‘ M : ( α, e ) be a closed well-typed term of λ C . ThenIf M → N by ( β v ) or ( set ) then M • → ∗ N • If M → N i by ( get ) then M • → ∗ R + P i N i • The presence of the additional term R is linked to the local nature of non-determinism inproof nets. When facing a get reduction, the proof net can either select one of the available . Hamdaoui 23:23 assignment, or drop them all and wait for an hypothetical future one, which corresponds tothis R net. This is better understood when stating the simulation theorem on λ cES : (cid:73) Theorem 19.
Simulation for λ cES Let ‘ M : ( α, e ) be a closed well-typed term of λ cES . If M → ∗ N , then M • → ∗ N • . Here, the term R is totally internalized in λ cES and we get a clean simulation theorem.To derive this result, we start by defining a notion of typed context and a translation ofcontexts to nets. (cid:73) Definition 20.
Hole typing rule R ‘ ( α, e ) R, [ . ] : ( α, e ) ‘ [ . ] : ( α, e ) ( hole )[ . ] can be seen just as a special kind of variable in the typing derivation that can besubstituted by something else than a value. We use the usual typing rules to build derivationsof typed contexts. A context can then be translated to a net, with an interface determinedby α and e , labelling free ports. This is what we call net contexts. The substitution of netsconsists in plugging the translation of a term with a matching type in this interface. (cid:73) Definition 21.
Hole translationWe define the translation of a typed hole R ‘ [ . ] : ( α, e ) as R ‘ ( α, e ) R, [ . ] : ( α, e ) ‘ [ . ] : ( α, e ) ( hole ) We can then carry on and use the usual term translation to build the translation of acontext ( C [ E ]) • , which is a net of the formThe substitution of M • , or of any net with a compatible interface for that matter, in( C [ E ]) • is defined by just connecting the free wires of the substituted net to the correspondingfree wire of the context hole : C V I T 2 0 1 6 λ -calculus in differential proof nets - Extended version The fundamental property of net contexts and net substitutions is that the substitutioncommutes with the translation, in the following sense : (cid:73)
Property 5.
Nets substitutionLet ‘ [ . ] : ( α, e ) be a typed hole, [ . ] : ( α, e ) ‘ C [ E ] : ( β, e ) a typed context, and ‘ M : ( α, e )a term. Then :( C [ E [ M ]]) • = ( C [ E ]) • [ M • ]The very definition of net reduction immediately entails that if M • → ∗ N • then( C [ E ]) • [ M • ] → ∗ ( C [ E ]) • [ N • ]. Together with Property 5, this ensures that we can focus onthe case where C = E = [ . ], as the general case follows seamlessly.From here, we check that each reduction rule of λ cES can be simulated on the net side,relying on the definition of the reduction and the behavior of routing areas. Let us show the simulation for ( subst ) rules, involving mainly duplication. Thanks to theprevious theorem, we can assume that contexts are empty without loss of generality. Weconsider only closed terms. Indeed, since reduction contexts
S, C, E do not bind variables,all the terms appearing in the premise of a rule are thus closed terms, and we can omit theircontext. For each rule, we write the translation of the premise followed by its reduction innets, which matches the conclusion.The fundamental rule is the variable one. ( subst var ) ( σ ( x ) undefined) → ∗ ( subst var ) ( σ ( x ) defined) → ∗ When reaching a get( r ) or a ∗ , the substitution simply vanishes. ( subst unit ) → ∗ The ( subst app ), ( subst subst-r ) and ( subst subst-r’ ) perform a duplication and propagatethe substitution inside reference substitutions. . Hamdaoui 23:25 ( subst app ) → ∗ ( subst subst-r ) → ∗ ( subst subst-r’ ) → ∗ The ( subst k ) just duplicate the variable substitution to the two threads C V I T 2 0 1 6 λ -calculus in differential proof nets - Extended version ( subst k ) → ∗ Finally, the ( subst merge ) distributes the outter substitution to both the term and theinner substitution. ( subst merge ) → ∗ The propagation of references substitutions relies on the behavior of routing area, andespecially Property 2. The fundamental case is the non deterministic reduction happeningwhen reducing a get( r ) whose redex is ( subst-r get ) Then for each V in the image of V , there will be exactly one summand of the followingform . Hamdaoui 23:27 → ∗ The remaining term does indeed reduce to the translation of get( r ): → ∗ ( subst-r val ), ( subst-r k ) and ( subst-r app ) are just direct application of the Property 2. ( subst-r val ) → ∗ ( subst-r k ) → ∗ C V I T 2 0 1 6 λ -calculus in differential proof nets - Extended version ( subst-r app ) → ∗ ( subst-r merge ) and ( subst-r subst-r’ ) amount to nothing in nets, as the translation alreadyidentifies the redex and the reduct of these rules. ( subst-r subst-r’ ) ( subst-r merge ) . Hamdaoui 23:296.1.0.3 Upward reference substitutions reduction As for downward substitutions, the main ingredient is the Transit lemma applies to ourspecific routing area δ and γ . ( subst-r’ k ) → ∗ ( subst-r’ lapp ) → ∗ ( subst-r’ rapp ) → ∗ C V I T 2 0 1 6 λ -calculus in differential proof nets - Extended version The second result states that the translation of a term is strongly normalizing: (cid:73)
Theorem 22.
TerminationThe translation of a well typed term of λ C terminates. The theorem that we will actually prove is rather the following: (cid:73)
Theorem 23.
Termination of λ cES The translation of the normal form of a well-typed term of λ cES terminates. While λ cES is closer to nets that λ C , unfortunately a normal form of λ cES is not translatedto a normal form in proof nets. The corresponding net can still perform some reductions.But we will see that these are unessential and limited: in a few steps, a normal form isreached in nets.We proceed in two stages: first, we extend λ cES to a language λ cES + that is able to dojust a little more reductions than λ cES . The extension of the translation and the simulationtheorem for λ cES + are straightforward. Then, we show that λ cES + also terminates, give anexplicit grammar for its normal forms, and show that the translation of these normal formsare strongly normalizing proof nets. λ cES + We add a labelled reference substitution variable substitution to λ cES : M [ |V| ] ↓ | M [ | x/N | ].The first one, M [ |V| ] ↓ , correspond to a downward reference substitution where V has nofree variables. The second one corresponds to a variable substitution of a term that is not avalue. Both can appear during the reduction in proof nets but are not accounted for in λ cES . M [ | x/N | ] can’t be reduced, either in N or by ( subst ) rules (whether N is a value or not). Thelabelled reference forbids any reduction under it, except for the labelled reference substitutions.We extend the reduction rules ( subst-r ) to the labelled substitution [ |V| ] ↓ . They can beperformed anywhere (included under a variable substitution) except under abstraction, in acontext defined by the following grammar: J ::= [ . ] | J M | M J | J [ V ] ↓ | J [ σ ] | J [ | x/N | ].We also add a β -rule to fire such labelled substitution :( β V )( λx.M ) N [ V ] λ → M [ |V| ] ↓ [ | x/N | ]This corresponds to the additional reduction nets can do. Indeed a β redex can always befired in nets even if the argument is not a value. But then, the corresponding term do needto be reduced before any duplication, erasure or substitution. Let us now show terminationand describe the normal forms of λ cES +: (cid:73) Definition 6.1. F -normal formsLet M be a normal form of the form of λ cES . It belongs to the grammar M norm (cf [6]). Then M reduces to a sum of terms in λ cES + that belongs to the following grammar of F -normalforms : F norm ::= get( r ) | F norm V [ V ] λ | F norm F norm [ V ] λ | M [ | x/F norm | ] where the M is in λ cES (contains no labelled substitution). . Hamdaoui 23:31 Proof.
By induction on the structure of M , with the additional hypothesis that only theadditional rules are performed (no upward substitution) : M = get( r ) : ok M = M norm V [ V ] λ : by induction, M norm reduces to a sum of F norm . Take one suchsummand N , then M → ∗ N norm V [ V ] λ (because no rule ( subst-r’ > ) was used) M = M norm M norm [ V ] λ : we proceed as the previous case M = V M norm [ V ] λ : by induction, M norm reduces to some N in F norm grammar, so M → ∗ V N [ V ] λ . Then, by inversion of typing rules, V is of the form λx.P and we canapply the new β -reduction to get P [ |V| ] ↓ [ | x/N | ]. By pushing down [ |V| ] ↓ in P , we canreduce it to a sum of P i s where each P i do not contain labelled substitutions. Then M → ∗ P i P i [ x/N ] (cid:74)(cid:73) Lemma 24. F -normal forms are normal. Proof.
By induction : M = get( r ) : ok M = F norm V [ V ] λ : by induction, F norm is normal, and values are not F -normal form, sothe application can’t create any β -redex. M = M norm M norm [ V ] λ : same as the previous case M = M [ | x/F normal | ] : the explicit substitution prevents any reduction except ( subst-r )ones for labelled reference substitution, but by definition, M does not contain any. (cid:74) F -normal forms and proof nets We will see in the following that the translation of a F -normal form has not many possiblereductions left. However, a few steps may remain to eventually reach a normal form. Thefirst step is to collect and merge all the routing areas that are created and connected duringthe translation. Doing so, we separate the net between a part that closely follows thetranslated term structure, and a big routing area which connects various subterms to enablecommunication through references between them. Once this is done, a few starving readsmay interact with the routing area, but nothing more. The following definition give theshape obtained after the merging of routing: (cid:73) Definition 25.
SeparabilityLet R be the translation of a λ cES + term, then R is say to be separable if it can be reducedto the following form :where R is a routing area and S a net with free wires labelled by i , . . . , i n , o , . . . , o m , O ,satisfying : (a) There is no redex in S (b) i , . . . , i n are either connected to the auxiliary port of a ⊗ cell, to the auxiliary port ofa cocontraction or to the principal port of a dereliction (c) o , . . . , o m , O are either connected to a ` cell, or to the principal door of an open box C V I T 2 0 1 6 λ -calculus in differential proof nets - Extended version The translation of term with at least one free variable is separable. The reason is thatconstructors such as application, substitution, parallel composition, etc. preserve separab-ility. Moreover, the translation of values with free variables are obviously separable. Theweakenings, which correspond to free variables, materialize as auxiliary doors of exponentialboxes, thus blocking further reduction. (cid:73)
Lemma 26.
Open terms separabilityLet Γ , x : A ‘ M : ( α, e ) a λ cES well-typed term, then its translation M • is separable. Proof.
Values
As stated above, we can first observe that the translation of ∗ , of a variable x andan abstraction all satisfy the separability conditions. Indeed, they are composed of a boxwith at least one auxiliary door, and the inside of the box is a normal form (by inductionfor abstraction and trivially for others). As they are pure terms, m = n = 0. Get
It is almost the same as values, except that the output o corresponding to the referenceof get( r ) is connected to a dereliction, which is allowed in (b) . Application
By induction, M • and N • are separable, thus can be decomposed in the followingway :We can merge the 3 routing areas R , R and δ . All the inputs or outputs previouslyconnected to one of the small areas immediately satisfy the conditions (b,c) by IH. Thetwo remaining wires i and o are respectively connected to the auxiliary port of a par andthe auxiliary port of a cocontraction, thus satisfy (b,c) . S and S are normal by IH, andthe translation of V is easily seen as normal. O is the conclusion of a par, hence satisfies (b,c) . It only remains to see that the whole net excepted the routing areas is normal,but the only redex that could appear is the connection of a dereliction to M • . By (c) ,the output of M • is either the conclusion of an open box or a par which do not form aredex. The condition (a) is verified. Parallel
Similar to application
Variable substitution
As for application, we apply the IH on M • and V • , merge the routingareas, and just check that the connection of V • to M • can not create new redexes using (b) on the output wire of V • . Reference substitutions
Again, the same technique is applied. (cid:74) . Hamdaoui 23:33
Finally, the main result we rely on as explained above is the following one : (cid:73)
Lemma 27.
Normal form separabilityThe translation of a F -normal form is separable It is proved as Lemma 26, by induction on the syntax of F -normal forms. We caneventually prove from this last lemma: (cid:73) Lemma 28.
Termination of λ cES +The translation of a F -normal form is strongly normalizing. From which we deduce: (cid:73)
Corollary 29.
Strong normalization The translation of a closed well-typed term of λ cES + is strongly normalizing. The translation of a closed well-typed term of λ cES is strongly normalizing (Theorem 23). Proof.
Lemma 28We apply 27 to reduce the translation of a F -normal form F to a routing area R connectedto S satisfying separability conditions. S and R are normal. The potential redexes mustinvolve a wire at the interface of R and S . The inputs of R are connected to S , either to apar or to the conclusion of an open box and thus can’t form any redex with (co)weakeningsand (co)contractions of R .The outputs of R are either connected to the auxiliary port of a tensor, the auxiliaryport of a cocontraciton or to a dereliction. Only the latter may form a new redex. If theoutput of R is a coweakening, then everything reduces to . If it is just a wire, then thedereliction is connected through this wire to an input of R which again can’t be part of anyredex. The only remaining case is when the output of R is a cocontraction tree. Then wecan perform the non-deterministic ba → reductions, and we go back to exactly the two previouscases as the dereliction is finally connected to a leaf of the tree of an input.Hence, after we performed finitely many ba → reductions, we finally get a normal form,which is either , or a sum of the previous net S connected to simpler routing area R i . (cid:74) Simulation and termination ensure that if a term M reduces to T = V k . . . k V n , then:By simulation, the translation M • can be reduced to a non deterministic sum in whichone summand will be T • By termination, this does not depend on the path of reduction we chose: any reductionwill converge to a normal form whose summands contain the net T • .The normal form of M • must contain the summand T . However, this does not tell usanything about what are the other summands of M • . Let us pretend the support for integersin λ C . Assume that a term M have 2 as only normal form. Because of this additional term R appearing in the simulation theorem, our results do not prevent M • to reduce to 1 • + 2 • + 3 • .In such a case, one may argue that the proof nets do not reflect faithfully the language asthey may have a lot more possible outcomes. The adequacy theorem states that the summands of the normal form of M • are either thetranslation of a normal form T = V k . . . k V n that is a reduct of the original M , or garbage,that is a non correct net that corresponds to execution paths which deadlocked. We canrecognize this garbage, thus eliminate it: with this additional operation, the summands ofthe normal form of M • coincide with the values that are reachable by M . C V I T 2 0 1 6 λ -calculus in differential proof nets - Extended version (cid:73) Theorem 30.
AdequacyLet M be well-typed term of λ C . We write Val ( M ) := { T = k i V i | M → ∗ T } . Similarly,for a net R with normal form N , we define Val ( R ) = {S | N = S + S , S is a value net } .Then Val ( M ) = Val ( M • )We first need to prove adequacy between λ C and λ cES : (cid:73) Theorem 31.
Adequacy for λ cES Let P be a term of λ C and M = e P its translation in λ cES , if M → ∗ P i M i a normal form,then ∀ i, P → ∗ P i such that M i v e P i . In other words, any term appearing in the normal formof the translation of P is bounded by the translation of a reduct of P . In particular, applied to values, this gives the sought property for λ cES : (cid:73) Corollary 32.
Let P be a term of λ C , M = e P its translation in λ cES such that M → ∗ M + M where M is a normal form.If M = V k N , then P → ∗ U k Q with V = e U .In particular, if M = k i V i , then P → ∗ k i U i with V i = e U i The only problematic case is the non deterministic reduction ( subst-r get ) which createsnew summands. The proof consist in showing that these summands are actually limited inwhat they can do. Formally, they are bounded by the initial term that is being reduced, inthe sense of the preorder v defined in [6]. The following lemma state that indeed the case ofdeterministic reduction is trivial: (cid:73) Lemma 33.
Values preservationLet M be a term of λ C , and M → ∗ M without using ( subst-r get ). We define NF ( M ) = { T | T normal and M → ∗ T } . Then NF ( M ) = NF ( M ) Proof.
If we do not use ( subst-r get ), the two reduction (full and non-deterministic) coincideand we use the confluence in λ C . (cid:74)(cid:73) Lemma 34.
Let M = e P be the translation of a λ C term, such that M → M . Then thereexists M , N , such that M → ∗ M v f N and N → { , } N , with all reductions from M to M not being ( subst-r get ). Proof.
The only redexes in M are either premises of ( subst-r’ ), ( β v ) or ( subst-r get ). Inthe first case, it corresponds to a reducible set whose reduction can be carried on in M bypushing the upward substitution to the top and pushing down the corresponding generateddownward substitutions, to obtain the translation of N (which is N where we the set isreduced). We can proceed the same way with ( β v ) : this corresponds to a β -redex in N ,where N is the result of reducing it, and M is obtained by pushing down the generatedsubstitutions (variable and refenreces).Finally, if the reduction rule is ( subst-r get ), then either it choosed one of the availablevalues and it corresponds exactly to a get reduction N → N , or it threw away availablevalues, in which case N = N , M = M and clearly M v f N . (cid:74) Proof.
Theorem 31We proceed by induction on η ( M ), the length of the longest reduction starting from M . If η ( M ) = 0, ie M is a normal form, this is trivially true.To prove the induction step, consider a reduct M of M . We use 34 to get M → ∗ M v f P for some reduct P of P , such that the reduction to M doesn’t use ( subst-r get ). Thus, by . Hamdaoui 23:35
33, NF( M ) = NF( M ). By induction on M , ∀ T ∈ NF( M ) , ∃ Q, P → ∗ Q and T v e Q . Butthis is true for any reduct M , and we have NF( M ) = S M → M NF( M ), hence this is truefor M . (cid:74) From there, we get the result combining Theorem 31 and Theorem 19. One can extractfrom the proof of Lemma 27 that the translation of a summand that is not a parallel ofvalues either reduces to , or to a net which is not a translation of a value. In this paper, we presented a translation of a λ -calculus with higher order references andconcurrency inside a fragment of differential proof nets. While several translations of effectfullanguages have been proposed in the literature, none supports this combination of features toour knowledge. We introduced a generalization of communication areas, routing areas, whichturned out to be a useful device to encode references. More generally, we think that routingareas can be used to express various kind of non-deterministic, concurrent communications.Modeling concurrency comes at a price, as terms such as ( λx. set( r, x )) get( r ) k ( λx. set( r, x )) get( r ))translates to a net that do not respect the differential proofs nets correctness criterion [4].Inside each thread, the set( r, x ) depends on the get( r ) whose value will replace the x variable.But of these get( r ) may also depend from the set( r, x ) of the other thread, creating a seem-ingly circular dependence which breaks the acyclicity required for correctness. This ambiguityis avoided at execution, as the first get( r ) to reduce will be forced to chose an availableassignment: these set-get dependencies are in fact mutually exclusive. But proof nets seemsunable to express this subtlety. Differential LL seems to suffer from more fundamentallimitations as a model of concurrency as pointed out by Mazza [12]. It is yet to be clarifiedhow these results apply to the fragment presented here. While seriously limiting what canbe modeled in proof nets, this might not be an obstacle when aiming for practical parallel ordistributed implementations.The enrichment of the source language, such as switching to a more realistic erase-on-writesemantic for stores, or the addition of new effects and features (synchronization operations,sum types, divergence either by fixpoint or references, etc . ) is the main focus of futurework. References Roberto M. Amadio. On stratified regions. In Zhenjiang Hu, editor,
Programming Lan-guages and Systems: 7th Asian Symposium, APLAS 2009, Seoul, Korea, December 14-16,2009. Proceedings , pages 210–225, Berlin, Heidelberg, 2009. Springer Berlin Heidelberg. doi:10.1007/978-3-642-10672-9_16 . Vincent Danos and Laurent Regnier. Reversible, irreversible and optimal λ -machines: Extended abstract. Electronic Notes in Theoretical Computer Science ,3(Supplement C):40 – 60, 1996. Linear Logic 96 Tokyo Meeting. URL: , doi:https://doi.org/10.1016/S1571-0661(05)80402-5 . Thomas Ehrhard and Olivier Laurent. Interpreting a finitary pi-calculus in differentialinteraction nets.
Information and Computation , 208(6):606 – 633, 2010. Special Issue:18th International Conference on Concurrency Theory (CONCUR 2007). URL: , doi:https://doi.org/10.1016/j.ic.2009.06.005 . C V I T 2 0 1 6 λ -calculus in differential proof nets - Extended version Thomas Ehrhard and Laurent Regnier. Differential interaction nets.
TheoreticalComputer Science , 364(2):166–195, November 2006. 30 pages. URL: https://hal.archives-ouvertes.fr/hal-00150274 , doi:10.1016/j.tcs.2006.08.003 . Jean-Yves Girard. Linear logic.
Theoretical Computer Science , 50(1):1 – 101, 1987.URL: , doi:https://doi.org/10.1016/0304-3975(87)90045-4 . Yann Hamdaoui and Benoit Valiron. An interactive proof of termination for a concur-rent λ -calculus with references and explicit substitutions. http://yago.gb2n.org/papers/explicit-substs.pdf , 2018. [Online]. Ugo Dal Lago, Claudia Faggian, Benoit Valiron, and Akira Yoshimizu. Parallelism and syn-chronization in an infinitary context. In
Proceedings of the 2015 30th Annual ACM/IEEESymposium on Logic in Computer Science (LICS) , LICS ’15, pages 559–572, Washington,DC, USA, 2015. IEEE Computer Society. URL: http://dx.doi.org/10.1109/LICS.2015.58 , doi:10.1109/LICS.2015.58 . Ian Mackie.
Applications of the Geometry of Interaction to language implementation . PhDthesis, Univ. of London, 1994. Ian Mackie. The geometry of interaction machine. In
Proceedings of the 22Nd ACMSIGPLAN-SIGACT Symposium on Principles of Programming Languages , POPL ’95, pages198–208, New York, NY, USA, 1995. ACM. URL: http://doi.acm.org/10.1145/199448.199483 , doi:10.1145/199448.199483 . Antoine Madet.
Complexité Implicite de Lambda-Calculs Concurrents . Theses, UniversitéParis-Diderot - Paris VII, December 2012. URL: https://tel.archives-ouvertes.fr/tel-00794977 . John Maraist, Martin Odersky, David N. Turner, and Philip Wadler. Call-by-name,call-by-value, call-by-need, and the linear lambda calculus.
Electronic Notes in The-oretical Computer Science , 1(Supplement C):370 – 392, 1995. MFPS XI, Mathemat-ical Foundations of Programming Semantics, Eleventh Annual Conference. URL: , doi:https://doi.org/10.1016/S1571-0661(04)00022-2 . Damiano Mazza. The true concurrency of differential interaction nets.
Mathematical Struc-tures in Computer Science , FirstView:1–29, 11 2016. doi:10.1017/S0960129516000402 . Michele Pagani. Visible acyclic differential nets, part i: Semantics.
Ann. Pure Appl. Logic ,163(3):238–265, 2012. Marco Pedicini and Francesco Quaglia. Pelcr: Parallel environment for optimal lambda-calculus reduction.
ACM Trans. Comput. Logic , 8(3), July 2007. URL: http://doi.acm.org/10.1145/1243996.1243997 , doi:10.1145/1243996.1243997 . Jorge Sousa Pinto. Parallel implementation models for the lambda-calculus using the geo-metry of interaction. In
Proceedings of the 5th International Conference on Typed LambdaCalculi and Applications , TLCA’01, pages 385–399, Berlin, Heidelberg, 2001. Springer-
Verlag. URL: http://dl.acm.org/citation.cfm?id=1754621.1754653 . Paolo Tranquilli. Translating types and effects with state monads and linear logic. 14 pages,January 2010. URL: https://hal.archives-ouvertes.fr/hal-00465793https://hal.archives-ouvertes.fr/hal-00465793