This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

\jdate

July, 2018

Multirole Logic and Multiparty Channels

Hongwei Xi and Hanwen Wu
Boston University
   Boston    MA 02215    USA
[email protected], [email protected]
Abstract

We identify multirole logic as a new form of logic in which conjunction/disjunction is interpreted as an ultrafilter on some underlying set of roles and the notion of negation is generalized to endomorphisms on this set. We formulate both multirole logic (MRL) and linear multirole logic (LMRL) as natural generalizations of classical logic (CL) and classical linear logic (CLL), respectively. Among various meta-properties established for MRL and LMRL, we obtain one named multiparty cut-elimination stating that every cut involving one or more sequents (as a generalization of a binary cut involving exactly two sequents) can be eliminated, thus extending the celebrated result of cut-elimination by Gentzen. As a side note, we also give an ultrafilter-based interpretation for intuitionism, formulating MRLJ as a natural generalization of intuitionistic logic (IL). An immediate application of LMRL can be found in a formulation of session types for channels that support multiparty communication in distributed programming. We present a multi-threaded lambda-calculus (MTLC) where threads communicate on linearly typed multiparty channels that are directly rooted in LMRL, establishing for MTLC both type preservation and global progress. The primary contribution of the paper consists of both identifying multirole logic as a new form of logic and establishing a theoretical foundation for it, and the secondary contribution lies in applying multirole logic to the practical domain of distributed programming.

1 Introduction

While the first and foremost inspiration for multirole logic originates from studies on multiparty session types in distributed programming, it seems natural in retrospective to introduce multirole logic by exploring the well-known duality between conjunction and disjunction in classical logic. For instance, in a two-sided presentation of the classical sequent calculus (LK), we have the following rules for conjunction and disjunction:

A¯B¯,AA¯B¯,B(conj-r)A¯B¯,ABA¯,AB¯(conj-l-1)A¯,ABB¯A¯,BB¯(conj-l-2)A¯,ABB¯A¯,AB¯A¯,BB¯(disj-l)A¯,ABB¯A¯B¯,A(disj-r-1)A¯B¯,ABA¯B¯,B(disj-r-2)A¯B¯,AB\begin{array}[]{c}\underline{A}\vdash\underline{B},A\land B\lx@proof@logical@and\underline{A}\vdash\underline{B},A\underline{A}\vdash\underline{B},B\\[6.0pt] \underline{A},A\land B\vdash\underline{B}\underline{A},A\vdash\underline{B}\kern 18.0pt\underline{A},A\land B\vdash\underline{B}\underline{A},B\vdash\underline{B}\\[6.0pt] \underline{A},A\lor B\vdash\underline{B}\lx@proof@logical@and\underline{A},A\vdash\underline{B}\underline{A},B\vdash\underline{B}\\[6.0pt] \underline{A}\vdash\underline{B},A\lor B\underline{A}\vdash\underline{B},A\kern 18.0pt\underline{A}\vdash\underline{B},A\lor B\underline{A}\vdash\underline{B},B\\ \end{array}

where A¯\underline{A} and B¯\underline{B} range over sequents (that are essentially multisets of formulas). One possible explanation of this duality is to think of the availability of two roles 0 and 11 such that the left side of a sequent judgment (of the form A¯B¯\underline{A}\vdash\underline{B}) plays role 11 while the right side does role 0. In addition, there are two logical connectives 0\land_{0} and 1\land_{1}; r\land_{r} is given a conjunction-like interpretation by the side playing role rr and disjunction-like interpretation by the other side playing role 1r1-r, where rr ranges over 0 and 11. With this explanation, it seems entirely natural for us to introduce more roles into classical logic.

Multirole logic is parameterized over a chosen underlying set of roles, which may be infinite, and we use ¯{\overline{\emptyset}} to refer to this set. We use RR to range over role sets, which are just subsets of ¯{\overline{\emptyset}}. Given any role set RR, we use R¯{\overline{R}} for the complement of RR in ¯{\overline{\emptyset}}. Also, we use R1R2R_{1}\uplus R_{2} for the disjoint union of R1R_{1} and R2R_{2} (where R1R2=R_{1}\cap R_{2}=\emptyset is assumed).

For the moment, let us assume that ¯{\overline{\emptyset}} consists all of the natural numbers less than NN for some given N2N\geq 2. Intuitively, a conjunctive multirole logic is one in which there is a logical connective r\land_{r} for each r¯r\in{\overline{\emptyset}} such that r\land_{r} is given a conjunction-like interpretation by a side playing role rr and a disjunction-like interpretation otherwise. If we think of the universal quantifier \forall as an infinite form of conjunction, then what is said about \land can be readily applied to \forall as well. In fact, additive, multiplicative, and exponential connectives in linear logic [\citenameGirard, 1987] can all be treated in a similar manner. Dually, a disjunctive multirole logic can be formulated (by giving r\land_{r} a disjunction-like interpretation if the side plays the role rr and a conjunction-like interpretation otherwise). We primarily focus on conjunctive multirole logic in this paper.

Given a formula AA and a set RR of roles, we write [A]R[A]_{R} for an i-formula, which is some sort of interpretation of AA based on RR. For instance, the interpretation of r\land_{r} based on RR is conjunction-like if rRr\in R holds, and it is disjunction-like otherwise. A crucial point, which we take from studies on multiparty session types, is that interpretation should be based on sets of roles rather than just individual roles. In other words, one side is allowed to play multiple roles simultaneously. A sequent Γ\Gamma in multirole logic is a multiset of i-formulas, and such a sequent is inherently many-sided as each RR appearing in Γ\Gamma represents precisely one side. As can be readily expected, the (binary) cut-rule in (either conjunctive or disjunctive) multirole logic is of the following form:

Γ1,[A]RΓ2,[A]R¯Γ1,Γ2\begin{array}[]{l}\Gamma_{1},\Gamma_{2}\lx@proof@logical@and\Gamma_{1},[A]_{R}\Gamma_{2},[A]_{{\overline{R}}}\end{array}

The cut-rule can be interpreted as some sort of communication between two parties in distributed programming [\citenameAbramsky, 1994, \citenameBellin & Scott, 1994, \citenameCaires & Pfenning, 2010, \citenameWadler, 2012]. For communication between multiple parties, it seems natural to seek a generalization of the cut-rule that involves more than two sequents. In conjunctive multirole logic, the admissibility of the following rule, which is given the name mp-cut-conj(n)\mbox{\it{mp-cut-conj}}(n), can be established:

R¯1R¯n=¯Γ1,[A]R1Γn,[A]RnΓ1,,Γn\begin{array}[]{l}\vdash\Gamma_{1},\ldots,\Gamma_{n}\lx@proof@logical@and{\overline{R}_{1}}\uplus\cdots\uplus{\overline{R}_{n}}={\overline{\emptyset}}\vdash\Gamma_{1},[A]_{R_{1}}\cdots\vdash\Gamma_{n},[A]_{R_{n}}\end{array}

In disjunctive multirole logic, the admissibility of the following rule, which is given the name mp-cut-disj(n)\mbox{\it{mp-cut-disj}}(n), can be established:

R1Rn=¯Γ1,[A]R1Γn,[A]RnΓ1,,Γn\begin{array}[]{l}\vdash\Gamma_{1},\ldots,\Gamma_{n}\lx@proof@logical@and R_{1}\uplus\cdots\uplus R_{n}={\overline{\emptyset}}\vdash\Gamma_{1},[A]_{R_{1}}\cdots\vdash\Gamma_{n},[A]_{R_{n}}\end{array}

We may use the name mp-cut to refer to either mp-cut-conj or mp-cut-disj, which itself is a shorthand for multiparty-cut.

In classical logic, the negation operator is clearly one of a kind. With respect to negation, the conjunction and disjunction operators behave dually, and the universal and existential quantifiers behave dually as well. For the moment, let us write ¬A\lnot{A} for the negation of AA. It seems rather natural to interpret [¬A]R[\lnot{A}]_{R} as [A]R¯[A]_{{\overline{R}}}. Unfortunately, such an interpretation of negation immediately breaks mp-cut(n)\mbox{\it{mp-cut}}(n) for any n3n\geq 3 (and it breaks mp-cut(1)\mbox{\it{mp-cut}}(1) as well). What we discover regarding negation is a bit of surprise: The notion of negation can be generalized to endomorphisms on the underlying set ¯{\overline{\emptyset}} of roles. For instance, if ff maps ii to (i+1)mod3(i+1)~{}\mbox{mod}~{}{3} for i=0,1,2i=0,1,2, then the negation operator ¬f\lnot_{f} based on ff is of order 33, that is, AA and ¬f(¬f(¬f(A)))\lnot_{f}(\lnot_{f}(\lnot_{f}(A))) are equivalent for any formula AA in MRL (which is a multirole version of CL)

Furthermore, we incorporate the notion of multirole into intuitionistic logic as well as linear logic, formulating MRLJ and LMRL as multirole versions of IL and CLL, respectively. An immediate application of multirole logic can be found in the practical domain of distributed programming, where we make direct use of LMRL in a design of linearly typed channels for supporting communication between multiple parties.

The rest of the paper is organized as follows. In Section 2, we formulate MRL, a multirole version of first-order classical predicate logic, and then mention some key meta-properties of MRL. In particular, we formally state the admissibility of a cut-rule (mp-cut) involving nn sequents for any n1n\geq 1. In Section 3, we present an ultrafilter-based interpretation for intuitionism, formulating MRLJ as a multirole version of first-order intuitionistic predicate logic. We move onto formulating LMRL in Section 4 as a multirole version of first-order linear classical predicate logic. In Section 5, we point out a profound relation between LMRL and session types for multiparty channels. Subsequently, we present in Section 6 and Section 7 a multi-threaded lambda-calculus equipped with linearly typed channels for multiparty communication, where the types for channels are directly rooted in LMRL, and briefly mention some implementation work in Section 8. Lastly, we compare with some closely related work and then conclude.

2 MRL: Multirole Logic

Let ¯{\overline{\emptyset}} be the underlying (possibly infinite) set of roles for the multirole logic MRL presented in this section. Strictly speaking, this MRL should be referred to as first-order classical multirole predicate logic.

Definition 2.1

A filter \mathcal{F} on ¯{\overline{\emptyset}} is a subset of the power set of ¯{\overline{\emptyset}} such that

  • ¯{\overline{\emptyset}}\in\mathcal{F}

  • R1R_{1}\in\mathcal{F} and R1R2R_{1}\subseteq R_{2} implies R2R_{2}\in\mathcal{F}

  • R1R_{1}\in\mathcal{F} and R2R_{2}\in\mathcal{F} implies R1R2R_{1}\cap R_{2}\in\mathcal{F}

A filter \mathcal{F} on ¯{\overline{\emptyset}} is an ultrafilter if either RR\in\mathcal{F} or R¯{\overline{R}}\in\mathcal{F} holds for every subset RR of ¯{\overline{\emptyset}}. We use 𝒰\mathcal{U} to range over ultrafilters on ¯{\overline{\emptyset}}. When there is no risk of confusion, we may simply use rr for the principal ultrafilter at rr, which is defined as {R¯rR}\{R\subseteq{\overline{\emptyset}}\mid r\in R\}. If ¯{\overline{\emptyset}} is finite, then it can be readily proven that each 𝒰\mathcal{U} on ¯{\overline{\emptyset}} is a principal filter at some element r¯r\in{\overline{\emptyset}}.

Definition 2.2

Given an endomorphism ff on ¯{\overline{\emptyset}}, that is, a mapping from ¯{\overline{\emptyset}} to itself, we use f(R)f(R) for the set {f(r)rR}\{f(r)\mid r\in R\} (image of RR under ff) and f1(R){f}^{-{\kern-1.0pt}1}(R) for the set {rf(r)R}\{r\mid f(r)\in R\} (pre-image of RR under ff). Clearly, f1()={f}^{-{\kern-1.0pt}1}(\emptyset)=\emptyset and f1(¯)=¯{f}^{-{\kern-1.0pt}1}({\overline{\emptyset}})={\overline{\emptyset}}, and f1{f}^{-{\kern-1.0pt}1} is distributive over the following operations on sets: union, intersection, and complement.

Proposition 2.1

Given ff and \mathcal{F}, we use f()f(\mathcal{F}) for the set {Rf1(R)}\{R\mid{f}^{-{\kern-1.0pt}1}(R)\in\mathcal{F}\}. It is clear that f()f(\mathcal{F}) is a filter (as \mathcal{F} is). If \mathcal{F} is an ultrafilter, then f()f(\mathcal{F}) is also an ultrafilter.

Given an endomorphism ff on ¯{\overline{\emptyset}}, we use ¬f\lnot_{f} for a unary connective. Given an ultrafilter 𝒰\mathcal{U} on ¯{\overline{\emptyset}}, we use 𝒰\land_{\mathcal{U}} for a binary connective and 𝒰\forall_{\mathcal{U}} for a quantifier. Note that we may equally choose the name 𝒰\lor_{\mathcal{U}} for 𝒰\land_{\mathcal{U}} (and 𝒰\exists_{\mathcal{U}} for 𝒰\forall_{\mathcal{U}}) as the meaning of the named connective (quantifier) solely comes from the ultrafilter 𝒰\mathcal{U}.

We use tt for first-order terms, which are standard (and thus not formulated explicitly for brevity). The formulas in MRL are defined as follows:

formulasA,B::=a¬f(A)A𝒰B𝒰(λx.A)\begin{array}[]{lrcl}\mbox{formulas}&A,B&::=&a\mid{\lnot_{f}}(A)\mid A\,{\land_{\mathcal{U}}}\,B\mid{\forall_{\mathcal{U}}}(\lambda x.A)\\ \end{array}

where aa ranges over pre-defined primitive formulas. Instead of writing something like 𝒰x.A\forall_{\mathcal{U}}x.A, we write 𝒰(λx.A)\forall_{\mathcal{U}}(\lambda x.A), where xx is a bound variable. Given a formula AA, a term tt and a variable xx, we use A[t/x]A[t/x] for the result of substituting tt for xx in AA and treat it as a proper subformula of 𝒰(λx.A)\forall_{\mathcal{U}}(\lambda x.A). For notational convenience, we may also write f(A)f(A) for ¬f(A){\lnot_{f}}(A), 𝒰(A1,A2)\mathcal{U}(A_{1},A_{2}) for A1𝒰A2A_{1}\,{\land_{\mathcal{U}}}\,A_{2}, and 𝒰(λx.A)\mathcal{U}(\lambda x.A) for 𝒰(λx.A){\forall_{\mathcal{U}}}(\lambda x.A).

Note that there is no connective for implication in MRL. If desired, one may simply treat Af,𝒰BA\,{\supset_{f,\mathcal{U}}{B}} as 𝒰(f(A),B)\mathcal{U}(f(A),B). We are only to introduce f,𝒰\supset_{f,\mathcal{U}} as a primitive connective corresponding to implication for each given pair of ff and 𝒰\mathcal{U} when formulating an intuitionistic version of MRL.

¯=R1Rn(Id)[a]R1,,[a]RnΓ(Weaken)Γ,[A]RΓ,[A]R,[A]R(Contract)Γ,[A]RΓ,[A]f1(R)(¬)Γ,[¬f(A)]RR𝒰Γ,[A]R(-neg-l)Γ,[A𝒰B]RR𝒰Γ,[B]R(-neg-r)Γ,[A𝒰B]RR𝒰Γ,[A]RΓ,[B]R(-pos)Γ,[A𝒰B]RR𝒰Γ,[A[t/x]]R(-neg)Γ,[𝒰(λx.A)]RR𝒰xΓΓ,[A]R(-pos)Γ,[𝒰(λx.A)]R\begin{array}[]{c}\vdash[a]_{R_{1}},\ldots,[a]_{R_{n}}{\overline{\emptyset}}=R_{1}\uplus\ldots\uplus R_{n}\\[6.0pt] \vdash\Gamma,[A]_{R}\vdash\Gamma\\[6.0pt] \vdash\Gamma,[A]_{R}\vdash\Gamma,[A]_{R},[A]_{R}\\[6.0pt] \vdash\Gamma,[{\lnot_{f}}(A)]_{R}\vdash\Gamma,[A]_{{f}^{-{\kern-1.0pt}1}(R)}\\[6.0pt] \vdash\Gamma,[A\,{\land_{\mathcal{U}}}\,B]_{R}\lx@proof@logical@and R\not\in\mathcal{U}\vdash\Gamma,[A]_{R}\\[6.0pt] \vdash\Gamma,[A\,{\land_{\mathcal{U}}}\,B]_{R}\lx@proof@logical@and R\not\in\mathcal{U}\vdash\Gamma,[B]_{R}\\[6.0pt] \vdash\Gamma,[A\,{\land_{\mathcal{U}}}\,B]_{R}\lx@proof@logical@and R\in\mathcal{U}\vdash\Gamma,[A]_{R}\vdash\Gamma,[B]_{R}\\[6.0pt] \vdash\Gamma,[{\forall_{\mathcal{U}}}(\lambda x.A)]_{R}\lx@proof@logical@and R\not\in\mathcal{U}\vdash\Gamma,[A[t/x]]_{R}\\[6.0pt] \vdash\Gamma,[{\forall_{\mathcal{U}}}(\lambda x.A)]_{R}\lx@proof@logical@and R\in\mathcal{U}x\not\in\Gamma\vdash\Gamma,[A]_{R}\\[6.0pt] \end{array}
Figure 1: The inference rules for MRL

Given a formula AA and a set RR of roles, [A]R[A]_{R} is referred to as an i-formula (for interpretation of AA based on RR). Let us use Γ\Gamma for multisets of i-formulas, which are also referred to as sequents. The inference rules for MRL are listed in Figure 1. In the rule (\forall-pos), xΓx\not\in\Gamma means that xx does not have any free occurrences in i-formulas contained inside Γ\Gamma. Please note that a sequent Γ\Gamma in this formulation is many-sided (rather than one-sided) as every RR appearing Γ\Gamma represents precisely one side.

Let us use |A||A| for the size of AA, which is the number of connectives contained in AA, and use 𝒟\mathcal{D} for derivations of sequents, which are just trees containing nodes that are applications of inference rules. Given a derivation 𝒟\mathcal{D}, ht(𝒟)\mbox{\it ht}(\mathcal{D}) stands for the tree height of 𝒟\mathcal{D}. When writing 𝒟::Γ\mathcal{D}::\Gamma, we mean that 𝒟\mathcal{D} is a derivation of Γ\Gamma, that is, Γ\Gamma is the conclusion of 𝒟\mathcal{D}. We may use the following format to present an inference rule:

(Γ1;;Γn)Γ0(\Gamma_{1};\ldots;\Gamma_{n})\Rightarrow\Gamma_{0}

where Γi\Gamma_{i} for 1in1\leq i\leq n are the premisses of the rule and Γ0\Gamma_{0} the conclusion. Such an inference rule is said to be admissible if its conclusion is derivable whenever its premisses are. Given two i-formulas [A]R1[A]_{R_{1}} and [B]R2[B]_{R_{2}}, we write [A]R1[B]R2[A]_{R_{1}}\Rightarrow[B]_{R_{2}} to mean that the rule (Γ,[A]R1)(Γ,[B]R2)(\Gamma,[A]_{R_{1}})\Rightarrow(\Gamma,[B]_{R_{2}}) is admissible. And we write ABA\Rightarrow B if [A]R[B]R[A]_{R}\Rightarrow[B]_{R} holds for any role set RR. For instance, for any ultrafilter 𝒰\mathcal{U} and formulas AA and BB, we have 𝒰(A,B)𝒰(B,A)\mathcal{U}(A,B)\Rightarrow\mathcal{U}(B,A). In addition, we write [A]R1[B]R2[A]_{R_{1}}\Leftrightarrow[B]_{R_{2}} for both [A]R1[B]R2[A]_{R_{1}}\Rightarrow[B]_{R_{2}} and [B]R2[A]R1[B]_{R_{2}}\Rightarrow[A]_{R_{1}}, and ABA\Leftrightarrow B for both ABA\Rightarrow B and BAB\Rightarrow A.

As a new form of logic, MRL may not seem intuitive. We present as follows some simple properties to facilitate the understanding of MRL.

Proposition 2.2

For each injective endomorphism ff on ¯{\overline{\emptyset}}, we have [A]R[f(A)]f(R)[A]_{R}\Rightarrow[f(A)]_{f(R)} for any formula AA and role set RR.

Proof 2.1.

By the rule (¬\lnot), we have [A]f1(f(R))[f(A)]f(R)[A]_{{f}^{-{\kern-1.0pt}1}(f(R))}\Rightarrow[f(A)]_{f(R)}. Since ff is injective, we have R=f1(f(R))R={f}^{-{\kern-1.0pt}1}(f(R)).

Given an endomorphism ff on ¯{\overline{\emptyset}}, we refer to ff as a permutation if it is actually a bijection and use f¯\overline{f} for the inverse permutation of ff. Please note that f¯(R)=f1(R)\overline{f}(R)={f}^{-{\kern-1.0pt}1}(R) for any role set RR.

Proposition 2.2.

Given any A, we have Af¯(f(A))A\Rightarrow\overline{f}(f(A)) for each permutation ff on ¯{\overline{\emptyset}}.

Proof 2.3.

This proposition follows from Proposition 2.2 as f¯(f(R))=R\overline{f}(f(R))=R for any role set RR.

Given two endomorphisms f1f_{1} and f2f_{2} on ¯{\overline{\emptyset}}, we write f1f2f_{1}\cdot f_{2} for a composition of f1f_{1} and f2f_{2} such that (f1f2)(r)=f2(f1(r))(f_{1}\cdot f_{2})(r)=f_{2}(f_{1}(r)) for r¯r\in{\overline{\emptyset}}. The set of permutations on ¯{\overline{\emptyset}} forms a group where the group unit is the identity function 𝑖𝑑{\it id}, and the group inverse of ff is f¯\overline{f}, and the group product of f1f_{1} and f2f_{2} is f1f2f_{1}\cdot f_{2}. Given a natural number nn, fnf^{n} is defined to be 𝑖𝑑{\it id} if n=0n=0 and ffn1f\cdot{f^{n-1}} if n>0n>0. The order of ff, if exists, is the least positive integer nn such that fn=𝑖𝑑f^{n}={\it id}.

Proposition 2.4.

Assume that ¯{\overline{\emptyset}} is finite. For each permutation ff on ¯{\overline{\emptyset}}, we have Afn(A)A\Leftrightarrow f^{n}(A) for some n1n\geq 1.

Proof 2.5.

By a theorem of Lagrange, every permutation ff on a finite ¯{\overline{\emptyset}} is of some order nn (such that nn divides N!N! for NN being the cardinality of ¯{\overline{\emptyset}}). By Proposition 2.2, we have [A]R[fn(A)]fn(R)[A]_{R}\Rightarrow[f^{n}(A)]_{f^{n}(R)}. Since fn(R)=Rf^{n}(R)=R, we have [A]R[fn(A)]R[A]_{R}\Rightarrow[f^{n}(A)]_{R} (for any RR). In other words, we have Afn(A)A\Rightarrow f^{n}(A). For any RR, we have [A]R,[A]R¯\vdash[A]_{R},[A]_{{\overline{R}}} (by Lemma 2.13); we can derive [A]R,[fn(A)]R¯\vdash[A]_{R},[f^{n}(A)]_{{\overline{R}}} by Proposition 2.2. Assume that Γ,[fn(A)]R\vdash\Gamma,[f^{n}(A)]_{R} is derivable. By cut-elimination (Lemma 2.8), we can derive Γ,[A]R\vdash\Gamma,[A]_{R}. Hence, we have fn(A)Af^{n}(A)\Rightarrow A.

The classical sequent calculus LK of Gentzen is a special case of MRL where ¯={0,1}{\overline{\emptyset}}=\{0,1\}. In a two-sided formulation of LK, let us assume that the left side plays role 11 and the right side does role 0; the negation operator ¬\lnot is ¬f\lnot_{f} for f=(0 1)f=(0\;1), that is, f(0)=1f(0)=1 and f(1)=0f(1)=0; the conjunction operator \land is 0\land_{0}, where 0 refers to the principal ultrafilters at 0, and the disjunction operator \lor is 1\land_{1}; the universal quantifier \forall is 0\forall_{0}, and the existential quantifier \exists is 1\forall_{1}. Clearly, the order of the permutation (0 1)(0\;1) is 22. Therefore, we have A¬(¬(A))A\Leftrightarrow\lnot(\lnot(A)).

Proposition 2.6.

Given a permutation ff and an endomorphism gg, we write f(g)f(g) for the endomorphism fgf¯{f}\cdot{g}\cdot\overline{f}. We have the following equivalences:

(1)f(g(A))f(g)(f(A))(2)f(𝒰(A,B))f(𝒰)(f(A),f(B))(3)f(𝒰(λx.A))f(𝒰)(λx.f(A))(4)𝒰1(A,𝒰2(B1,B2))𝒰2(𝒰1(A,B1),𝒰1(A,B2))\begin{array}[]{lrcl}\mbox{(1)}&f(g(A))&\Leftrightarrow&f(g)(f(A))\\ \mbox{(2)}&f(\mathcal{U}(A,B))&\Leftrightarrow&f(\mathcal{U})(f(A),f(B))\\ \mbox{(3)}&f(\mathcal{U}(\lambda x.A))&\Leftrightarrow&f(\mathcal{U})(\lambda x.f(A))\\ \mbox{(4)}&\mathcal{U}_{1}(A,\mathcal{U}_{2}(B_{1},B_{2}))&\Leftrightarrow&\mathcal{U}_{2}(\mathcal{U}_{1}(A,B_{1}),\mathcal{U}_{1}(A,B_{2}))\\ \end{array}
Proof 2.7.

The (straightforward) proof details are omitted for brevity. Notice that the two De Morgan’s laws in classical propositional logic are unified in (2). Also, please notice that the fact is captured in (4) that conjunction is distributive over disjunction and vice versa.

Clearly, Proposition 2.6 suggests that many notions of duality in mathematics can and should be revisited in the context of multirole logic.

2.1 Cut-Elimination for MRL

We establish in this section that MRL enjoys a form of cut-elimination possibly involving nn sequents for any n1n\geq 1. Essentially, we are to prove the following lemma:

Lemma 2.8 (mp-cut).

Let R1,,RnR_{1},\ldots,R_{n} be subsets of ¯{\overline{\emptyset}} for some n1n\geq 1. If R¯1R¯n=¯{\overline{R}}_{1}\uplus\cdots\uplus{\overline{R}}_{n}={\overline{\emptyset}} holds, then the following inference rule (mp-cut) is admissible in MRL:

(Γ1,[A]R1;;Γn,[A]Rn)(Γ1,,Γn)(\Gamma_{1},[A]_{R_{1}};\ldots;\Gamma_{n},[A]_{R_{n}})\Rightarrow(\Gamma_{1},\ldots,\Gamma_{n})

Let us first present some crucial properties of MRL as follows:

Lemma 2.9.

The following rule is admissible in MRL:

()[A]¯()\Rightarrow{[A]_{{\overline{\emptyset}}}}
Proof 2.10.

By structural induction on AA. Note that we need the fact f1(¯)=¯{f}^{-{\kern-1.0pt}1}({\overline{\emptyset}})={\overline{\emptyset}} in the case where AA is of the form ¬f(B)\lnot_{f}(B).

Let us use {[A]R}\{[A]_{R}\} for a sequent that contains an indefinite number of occurrences of [A]R[A]_{R}.

Lemma 2.11.

(Splitting of Roles) The following rule is admissible in MRL:

(Γ,[A]R1R2)Γ,[A]R1,[A]R2(\Gamma,[A]_{R_{1}\uplus R_{2}})\Rightarrow{\Gamma,[A]_{R_{1}},[A]_{R_{2}}}
Proof 2.12.

We can directly prove the admissibility of the following rule by structural induction on AA:

(Γ,{[A]R1R2})Γ,[A]R1,[A]R2(\Gamma,\{[A]_{R_{1}\uplus R_{2}}\})\Rightarrow{\Gamma,[A]_{R_{1}},[A]_{R_{2}}}

Please note that the opposition of Lemma 2.11 is not valid, that is, the rule (Γ,[A]R1,[A]R2)Γ,[A]R1R2(\Gamma,[A]_{R_{1}},[A]_{R_{2}})\Rightarrow\Gamma,[A]_{R_{1}\uplus R_{2}} is not admissible.

Lemma 2.13.

Assume R1Rn=¯{R}_{1}\uplus\ldots\uplus{R}_{n}={\overline{\emptyset}}. The following rule is admissible in MRL:

()[A]R1,,[A]Rn()\Rightarrow{[A]_{R_{1}},\ldots,[A]_{R_{n}}}
Proof 2.14.

By Lemma 2.9 and Lemma 2.11.

Lemma 2.15.

(1-cut) The following rule is admissible in MRL:

(Γ,[A])Γ(\Gamma,[A]_{\emptyset})\Rightarrow{\Gamma}
Proof 2.16.

We can directly prove the admissibility of the following rule by structural induction on AA:

(Γ,{[A]})Γ(\Gamma,\{[A]_{\emptyset}\})\Rightarrow{\Gamma}

Note that Lemma 2.15 can be seen as a special form of cut-elimination where only one sequent is involved.

Lemma 2.17.

(2-cut with residual) Assume that R¯1{\overline{R}_{1}} and R¯2{\overline{R}_{2}} are disjoint. Then the following rule (2-cut-residual) is admissible in MRL:

(Γ1,[A]R1;Γ2,[A]R2)Γ1,Γ2,[A]R1R2(\Gamma_{1},[A]_{R_{1}};\Gamma_{2},[A]_{R_{2}})\Rightarrow{\Gamma_{1},\Gamma_{2},[A]_{R_{1}\cap R_{2}}}
Proof 2.18.

We omit the proof for this lemma as it can be done in essentially the same manner as is the presented proof of Lemma 4.9 (which is simply the counterpart of the current lemma expressed in the setting of linear multirole logic).

We present as follows a proof of Lemma 2.8 based Lemma 2.15 and Lemma 2.17:

Proof 2.19.

The proof proceeds by induction on nn. If n=1n=1, then this lemma is just Lemma 2.15. Assume that n2n\geq 2 holds. Then we have 𝒟i::(Γi,[A]Ri)\mathcal{D}_{i}::(\Gamma_{i},[A]_{R_{i}}) for 1in1\leq i\leq n. Clearly, R¯1{\overline{R}_{1}} and R¯2{\overline{R}_{2}} are disjoint. By Lemma 2.17, we have 𝒟12::(Γ1,Γ2,[A]R1R2)\mathcal{D}_{12}::(\Gamma_{1},\Gamma_{2},[A]_{{R_{1}\cap R_{2}}}). By induction hypothesis, we can derive the sequent Γ1,Γ2,,Γn\Gamma_{1},\Gamma_{2},\ldots,\Gamma_{n} based on 𝒟12,,𝒟n\mathcal{D}_{12},\ldots,\mathcal{D}_{n}.

This given proof of Lemma 2.8 clearly indicates that multiparty cut-elimination builds on top of Lemma 2.15 (1-cut) and Lemma 2.17 (2-cut-residual). In particular, one may see Lemma 2.15 and Lemma 2.17 as two fundamental meta-properties of a logic.

It should be clear that the rule (2-cut) (that is, the special case of (mp-cut) for 22 sequents) plus Lemma 2.11 implies the rule (2-cut-residual): Assume we have Γ1,[A]R1\vdash\Gamma_{1},[A]_{R_{1}} and Γ2,[A]R2\vdash\Gamma_{2},[A]_{R_{2}} for some R1R_{1} and R2R_{2} such that R¯1{\overline{R}}_{1} and R¯2{\overline{R}}_{2} are disjoint; by applying Lemma 2.11 to Γ1,[A]R1\vdash\Gamma_{1},[A]_{R_{1}}, we have Γ1,[A]R¯2,[A]R1R2\vdash\Gamma_{1},[A]_{{\overline{R}_{2}}},[A]_{R_{1}\cap R_{2}}; by applying (2-cut) to Γ1,[A]R¯2,[A]R1R2\vdash\Gamma_{1},[A]_{{\overline{R}_{2}}},[A]_{R_{1}\cap R_{2}} and Γ2,[A]R2\vdash\Gamma_{2},[A]_{R_{2}}, we have Γ1,Γ2,[A]R1R2\vdash\Gamma_{1},\Gamma_{2},[A]_{R_{1}\cap R_{2}}.

Also, it should be clear that the rule (3-cut) (that is, the special case of (mp-cut) for 33 sequents) immediately implies the rule (2-cut-residual): Assume we have Γ1,[A]R1\vdash\Gamma_{1},[A]_{R_{1}} and Γ2,[A]R2\vdash\Gamma_{2},[A]_{R_{2}} for some R1R_{1} and R2R_{2} such that R¯1{\overline{R}}_{1} and R¯2{\overline{R}}_{2} are disjoint; we also have [A]R3,[A]R¯3\vdash[A]_{R_{3}},[A]_{{\overline{R}_{3}}} for R3=R1R2R_{3}=R_{1}\cap R_{2} by Lemma 2.13; therefore we have Γ1,Γ2,[A]R3\vdash\Gamma_{1},\Gamma_{2},[A]_{R_{3}} by (3-cut) (as R¯1R¯2R3=¯{\overline{R}}_{1}\uplus{\overline{R}}_{2}\uplus{R}_{3}={\overline{\emptyset}}). This is a useful observation as what we actually implement in practice is the rule (3-cut) (for LMRL).

3 MRLJ: Intuitionistic MRL

If in classical logic the most prominent logical connective is negation, then it is implication in intuitionistic logic. Given an endomorphism ff and an ultrafilter 𝒰\mathcal{U} (on ¯{\overline{\emptyset}}), we introduce a logical connective f,𝒰\supset_{f,\mathcal{U}} in MRLJ (for representing the notion of implication). The formulas in MRLJ are defined as follows:

formulasA,B::=a¬f(A)A𝒰BAf,𝒰B𝒰(λx.A)\begin{array}[]{lrcl}\mbox{formulas}&A,B&::=&a\mid{\lnot_{f}}(A)\mid A\,{\land_{\mathcal{U}}}\,B\mid A\,{\supset_{f,\mathcal{U}}{B}}\mid{\forall_{\mathcal{U}}}(\lambda x.A)\\ \end{array}

We may also write 𝒰f(A,B)\mathcal{U}_{f}(A,B) for Af,𝒰BA\,{\supset_{f,\mathcal{U}}{B}}.

Definition 3.1.

Given an ultrafilter 𝒰\mathcal{U}, a sequent Γ\Gamma is 𝒰\mathcal{U}-intuitionistic if there is at most one i-formula [A]R[A]_{R} in Γ\Gamma such that R𝒰R\in\mathcal{U} holds. An inference rule (Γ1,,Γn)Γ0(\Gamma_{1},\ldots,\Gamma_{n})\Rightarrow\Gamma_{0} is 𝒰\mathcal{U}-intuitionistic if Γ0\Gamma_{0} and Γ1,,Γn\Gamma_{1},\ldots,\Gamma_{n} are 𝒰\mathcal{U}-intuitionistic.

Intuitionistic multirole logic is parameterized over a fixed ultrafilter on ¯{\overline{\emptyset}}. In MRLJ, we refer to this ultrafilter as 𝒥\mathcal{J}. Every inference rule in Figure 1 is also an inference rule in MRLJ if it is 𝒥\mathcal{J}-intuitionistic. In addition, we have the following rules for handling implication:

R𝒰Γ,[A]f1(R),[B]R(-neg)Γ,[Af,𝒰B]RR𝒰Γ1,[A]f1(R)Γ2,[B]R(-pos)Γ1,Γ2,[Af,𝒰B]R\begin{array}[]{c}\vdash\Gamma,[A\,{\supset_{f,\mathcal{U}}{B}}]_{R}\lx@proof@logical@and R\not\in\mathcal{U}\vdash\Gamma,[A]_{{f}^{-{\kern-1.0pt}1}(R)},[B]_{R}\\[6.0pt] \vdash\Gamma_{1},\Gamma_{2},[A\,{\supset_{f,\mathcal{U}}{B}}]_{R}\lx@proof@logical@and R\in\mathcal{U}\vdash\Gamma_{1},[A]_{{f}^{-{\kern-1.0pt}1}(R)}\vdash\Gamma_{2},[B]_{R}\\[6.0pt] \end{array}

The intuitionistic sequent calculus LJ of Gentzen is a special case of MRLJ where ¯={0,1}{\overline{\emptyset}}=\{0,1\} and 𝒥\mathcal{J} is the principal filter at 11; the implication connective \supset is f,𝒰\supset_{f,\mathcal{U}} for f=(0 1)f=(0\;1) and 𝒰\mathcal{U} being the principal filter at 0. As an example, the well-known fact that A¬BA\supset\lnot{B} implies B¬AB\supset\lnot{A} in LJ can be generalized in MRLJ as follows:

Proposition 3.2.

Given two permutations ff and gg, we have 𝒰f(A,g(B))𝒰g(B,f(A))\mathcal{U}_{f}(A,g(B))\Leftrightarrow\mathcal{U}_{g}(B,f(A)).

Proof 3.3.

It is a routine to verify that the following sequent is derivable in MRLJ for any role set RR:

([𝒰f(A,g(B))]R¯,[𝒰g(B,f(A))]R)([\mathcal{U}_{f}(A,g(B))]_{{\overline{R}}},[\mathcal{U}_{g}(B,f(A))]_{R})

Assume that Γ,[𝒰f(A,g(B))]R\vdash\Gamma,[\mathcal{U}_{f}(A,g(B))]_{R} is derivable. We have Γ,[𝒰g(B,f(A))]R\vdash\Gamma,[\mathcal{U}_{g}(B,f(A))]_{R} by cut-elimination (Lemma 3.6). Hence, 𝒰f(A,g(B))𝒰g(B,f(A))\mathcal{U}_{f}(A,g(B))\Rightarrow\mathcal{U}_{g}(B,f(A)) holds. By symmetry, we thus have obtained 𝒰f(A,g(B))𝒰g(B,f(A))\mathcal{U}_{f}(A,g(B))\Leftrightarrow\mathcal{U}_{g}(B,f(A)).

In LJ, [A]R[B]R[A]_{R}\Rightarrow[B]_{R} can be internalized as [AB]R[A\supset B]_{R} if R={1}R=\{1\}. This form of internalization can be generalized in MRLJ as follows:

Proposition 3.4.

Assume that [𝒰f(A,B)]R\vdash[\mathcal{U}_{f}(A,B)]_{R} is derivable for R𝒥R\in\mathcal{J} and R𝒰R\not\in\mathcal{U} and f1(R)=R¯{f}^{-{\kern-1.0pt}1}(R)={\overline{R}}. Then [A]R[B]R[A]_{R}\Rightarrow[B]_{R} holds.

Proof 3.5.

It is a routine to verify that the following sequent is derivable in MRLJ:

([𝒰f(A,B)]R¯,[A]R¯,[B]R([\mathcal{U}_{f}(A,B)]_{{\overline{R}}},[A]_{{\overline{R}}},[B]_{R}

Assume that Γ,[A]R\vdash\Gamma,[A]_{R} is derivable. By cut-elimination for MRLJ (Lemma 3.6), we can derive Γ,[B]R\vdash\Gamma,[B]_{R}. Hence, we have [A]R[B]R[A]_{R}\Rightarrow[B]_{R}.

Lemma 3.6 (mp-cut).

Let R1,,RnR_{1},\ldots,R_{n} be subsets of ¯{\overline{\emptyset}} for some n1n\geq 1. If R¯1R¯n=¯{\overline{R}}_{1}\uplus\cdots\uplus{\overline{R}}_{n}={\overline{\emptyset}} holds, then the following inference rule (mp-cut) is admissible in MRLJ:

(Γ1,[A]R1;;Γn,[A]Rn)(Γ1,,Γn)(\Gamma_{1},[A]_{R_{1}};\ldots;\Gamma_{n},[A]_{R_{n}})\Rightarrow(\Gamma_{1},\ldots,\Gamma_{n})

where it is assumed that each (Γi,[A]Ri)(\Gamma_{i},[A]_{R_{i}}) is 𝒥\mathcal{J}-intuitionistic for 1in1\leq i\leq n.

Proof 3.7.

The lemma can be proven in essentially the same fashion as is Lemma 2.8.

We see the very ability to incorporate intuitionism into multirole logic as solid evidence in support of multirole being an inherent notion in logic.

4 LMRL: Linear Multirole Logic

¯=R1Rn(Id)[a]R1,,[a]RnΓ,[A]f1(R)(¬)Γ,[¬f(A)]RR𝒰Γ,[A]R(&-neg-l)Γ,[A&𝒰B]RR𝒰Γ,[B]R(&-neg-r)Γ,[A&𝒰B]RR𝒰Γ,[A]RΓ,[B]R(&-pos)Γ,[A&𝒰B]RR𝒰Γ,[A]R,[B]R(-neg)Γ,[A𝒰B)]RR𝒰Γ1,[A]RΓ2,[B]R(-pos)Γ1,Γ2,[A𝒰B]RR𝒰?(Γ),[A]R(!-pos)?(Γ),[!𝒰(A)]RR𝒰Γ(!-neg-weaken)Γ,[!𝒰(A)]RR𝒰Γ,[A]R(!-neg-derelict)Γ,[!𝒰(A)]RR𝒰Γ,[!𝒰(A)]R,[!𝒰(A)]R(!-neg-contract)Γ,[!𝒰(A)]RR𝒰Γ,[A[t/x]]R(-neg)Γ,[𝒰(λx.A)]RR𝒰xΓΓ,[A]R(-pos)Γ,[𝒰(λx.A)]R\begin{array}[]{c}\vdash[a]_{R_{1}},\ldots,[a]_{R_{n}}{\overline{\emptyset}}=R_{1}\uplus\ldots\uplus R_{n}\\[6.0pt] \vdash\Gamma,[{\lnot_{f}}(A)]_{R}\vdash\Gamma,[A]_{{f}^{-{\kern-1.0pt}1}(R)}\\[6.0pt] \vdash\Gamma,[A\,{{\&}_{\mathcal{U}}{B}}]_{R}\lx@proof@logical@and R\not\in\mathcal{U}\vdash\Gamma,[A]_{R}\\[6.0pt] \vdash\Gamma,[A\,{{\&}_{\mathcal{U}}{B}}]_{R}\lx@proof@logical@and R\not\in\mathcal{U}\vdash\Gamma,[B]_{R}\\[6.0pt] \vdash\Gamma,[A\,{{\&}_{\mathcal{U}}{B}}]_{R}\lx@proof@logical@and R\in\mathcal{U}\vdash\Gamma,[A]_{R}\vdash\Gamma,[B]_{R}\\[6.0pt] \vdash\Gamma,[A\,{{\otimes}_{\mathcal{U}}{B}})]_{R}\lx@proof@logical@and R\not\in\mathcal{U}\vdash\Gamma,[A]_{R},[B]_{R}\\[6.0pt] \vdash\Gamma_{1},\Gamma_{2},[A\,{{\otimes}_{\mathcal{U}}{B}}]_{R}\lx@proof@logical@and R\in\mathcal{U}\vdash\Gamma_{1},[A]_{R}\vdash\Gamma_{2},[B]_{R}\\[6.0pt] \vdash{?}(\Gamma),[{!}_{\mathcal{U}}({A})]_{R}\lx@proof@logical@and R\in\mathcal{U}\vdash{?}(\Gamma),[A]_{R}\\[6.0pt] \vdash\Gamma,[{!}_{\mathcal{U}}({A})]_{R}\lx@proof@logical@and R\not\in\mathcal{U}\vdash\Gamma\\[6.0pt] \vdash\Gamma,[{!}_{\mathcal{U}}({A})]_{R}\lx@proof@logical@and R\not\in\mathcal{U}\vdash\Gamma,[A]_{R}\\[6.0pt] \vdash\Gamma,[{!}_{\mathcal{U}}({A})]_{R}\lx@proof@logical@and R\not\in\mathcal{U}\vdash\Gamma,[{!}_{\mathcal{U}}({A})]_{R},[{!}_{\mathcal{U}}({A})]_{R}\\[6.0pt] \vdash\Gamma,[{\forall_{\mathcal{U}}}(\lambda x.A)]_{R}\lx@proof@logical@and R\not\in\mathcal{U}\vdash\Gamma,[A[t/x]]_{R}\\[6.0pt] \vdash\Gamma,[{\forall_{\mathcal{U}}}(\lambda x.A)]_{R}\lx@proof@logical@and R\in\mathcal{U}x\not\in\Gamma\vdash\Gamma,[A]_{R}\\[6.0pt] \end{array}
Figure 2: The inference rules for LMRL

In this section, we generalize classical linear logic (CLL) to linear multirole logic (LMRL), which is to guide subsequently a design of linearly typed channels for multiparty communication in distributed programming.

Let ¯{\overline{\emptyset}} be the full set of roles for LMRL. For each endomorphism ff on ¯{\overline{\emptyset}}, we assume a corresponding unary connective ¬f\lnot_{f} (generalized negation). For each ultrafilter 𝒰\mathcal{U} on ¯{\overline{\emptyset}}, we assume two binary connectives &𝒰{\&}_{\mathcal{U}} and 𝒰{\otimes}_{\mathcal{U}} (corresponding to &{\&}/{\oplus} and {\otimes}/{\invamp} in linear logic, respectively) and a unary connective !𝒰{!}_{\mathcal{U}} (corresponding to !{!}/?{?} in linear logic) and a quantifier 𝒰\forall_{\mathcal{U}} (corresponding to \forall/\exists). The formulas in LMRL are defined as follows:

formulasA,B::=a¬f(A)A𝒰BA&𝒰B!𝒰(A)𝒰(λx.A)\begin{array}[]{lrcl}\mbox{formulas}&A,B&::=&a\mid{\lnot_{f}}(A)\mid A\,{{\otimes}_{\mathcal{U}}{B}}\mid A\,{{\&}_{\mathcal{U}}{B}}\mid{!}_{\mathcal{U}}({A})\mid{\forall_{\mathcal{U}}}(\lambda x.A)\\ \end{array}

We may write [?(A)]R[{?}(A)]_{R} to mean [!𝒰(A)]R[{!}_{\mathcal{U}}({A})]_{R} for some R𝒰R\not\in\mathcal{U}, and ?(Γ)?(\Gamma) to mean that each i-formula in Γ\Gamma is of the form [?(A)]R[{?}(A)]_{R}.

The inference rules for LMRL are listed in Figure 2. Note that there are one rule for each ¬f\lnot_{f}, and one positive rule and two negative rules for each &𝒰{\&}_{\mathcal{U}}, and one positive rule and one negative rule for each 𝒰{\otimes}_{\mathcal{U}}, and one positive rule and three negative rules for each !𝒰{!}_{\mathcal{U}}, and one positive rule and one negative rule for each 𝒰\forall_{\mathcal{U}}. Let us take the rule (&{\&}-neg-l) as an example; the i-formula [A&𝒰B]R[A\,{{\&}_{\mathcal{U}}{B}}]_{R} is referred to as the major i-formula of the rule. Let us take the rule ({\otimes}-pos) as another example; the i-formula [A𝒰B]R[A\,{{\otimes}_{\mathcal{U}}{B}}]_{R} is referred to as the major i-formula of the rule. The major i-formulas for the other rules (excluding the rule (Id)) should be clear as well. For the rule (Id), each [a]Ri[a]_{R_{i}} is referred to as a major i-formula.

Please recall that |A||A| is for the size of AA that is, the number of connectives contained in AA, and 𝒟\mathcal{D} for a derivation tree and ht(𝒟)\mbox{\it ht}(\mathcal{D}) for the height of the tree. Also, we use 𝒟::Γ\mathcal{D}::\Gamma for a derivation of Γ\Gamma.

The following lemmas in LMRL are the counterparts of of a series of lemmas (Lemma 2.9, Lemma 2.11, Lemma 2.13, Lemma 2.15, Lemma 2.17, and Lemma 2.8) in MRL.

Lemma 4.1.

The following rule is admissible in LMRL:

()[A]¯()\Rightarrow{[A]_{{\overline{\emptyset}}}}
Proof 4.2.

By structural induction on AA.

Given an i-formula [A]R[A]_{R}, let us use {[A]R}\{[A]_{R}\} for a sequent consisting of only [A]R[A]_{R} if AA is not of the form !𝒰(B){!}_{\mathcal{U}}({B}) for R𝒰R\not\in\mathcal{U} or some repeated occurrences of [A]R[A]_{R} otherwise (that is, if AA is of the form !𝒰(B){!}_{\mathcal{U}}({B}) for R𝒰R\not\in\mathcal{U}).

Lemma 4.3.

(Splitting of Roles) The following rule is admissible in LMRL:

(Γ,[A]R1R2)Γ,[A]R1,[A]R2(\Gamma,[A]_{R_{1}\uplus R_{2}})\Rightarrow{\Gamma,[A]_{R_{1}},[A]_{R_{2}}}
Proof 4.4.

We can directly prove the admissibility of the following rule by structural induction on AA:

(Γ,{[A]R1R2})Γ,[A]R1,[A]R2(\Gamma,\{[A]_{R_{1}\uplus R_{2}}\})\Rightarrow{\Gamma,[A]_{R_{1}},[A]_{R_{2}}}
Lemma 4.5.

Assume R1Rn=¯{R}_{1}\uplus\ldots\uplus{R}_{n}={\overline{\emptyset}}. The following rule is admissible in LMRL:

()[A]R1,,[A]Rn()\Rightarrow{[A]_{R_{1}},\ldots,[A]_{R_{n}}}
Proof 4.6.

By Lemma 4.1 and Lemma 4.3.

Lemma 4.7.

(1-cut) The following rule is admissible in LMRL:

(Γ,[A])Γ(\Gamma,[A]_{\emptyset})\Rightarrow{\Gamma}
Proof 4.8.

We can directly prove the admissibility of the following rule by structural induction on AA:

(Γ,{[A]})Γ(\Gamma,\{[A]_{\emptyset}\})\Rightarrow{\Gamma}
Lemma 4.9.

(2-cut with residual) Assume that R¯1{\overline{R}_{1}} and R¯2{\overline{R}_{2}} are disjoint. Then the following rule is admissible in LMRL:

(Γ1,[A]R1;Γ2,[A]R2)Γ1,Γ2,[A]R1R2(\Gamma_{1},[A]_{R_{1}};\Gamma_{2},[A]_{R_{2}})\Rightarrow{\Gamma_{1},\Gamma_{2},[A]_{R_{1}\cap R_{2}}}
Proof 4.10.

The proof for this lemma is given in Section 4.1.

Lemma 4.11 (mp-cut).

Let R1,,RnR_{1},\ldots,R_{n} be subsets of ¯{\overline{\emptyset}} for some n1n\geq 1. If R¯1R¯n=¯{\overline{R}}_{1}\uplus\cdots\uplus{\overline{R}}_{n}={\overline{\emptyset}} holds, then the following inference rule (mp-cut) is admissible in LMRL:

(Γ1,[A]R1;;Γn,[A]Rn)(Γ1,,Γn)(\Gamma_{1},[A]_{R_{1}};\ldots;\Gamma_{n},[A]_{R_{n}})\Rightarrow(\Gamma_{1},\ldots,\Gamma_{n})
Proof 4.12.

By Lemma 4.7 and Lemma 4.9, the lemma can be proven in the same fashion as is Lemma 2.8.

By following some recent work on encoding cut-elimination as reduction in variants of π\pi-calculus [\citenameCaires & Pfenning, 2010, \citenameWadler, 2012], we can readily formulate a variant of π\pi-calculus in which process reduction follows precisely the strategy employed in the proof of Lemma 4.9 for reducing the complexity of a cut-formula. Alternatively, we can interpret formulas in LMRL as session types for channels in a multi-threaded lambda-calculus and various meta-properties of LMRL as certain (primitive) functions on channels. We take the alternative here as it is closer to the goal of implementing session-typed multiparty channels for practical use.

4.1 Proof of Lemma 4.9

Due to the presence of the the structural rules (!{!}-neg-weaken) and (!{!}-neg-contract), we need to prove a strengthened version of Lemma 4.9 stating that the following rule is admissible in LMRL:

(Γ1,{[A]R1};Γ2,{[A]R2})Γ1,Γ2,[A]R1R2(\Gamma_{1},\{[A]_{R_{1}}\};\Gamma_{2},\{[A]_{R_{2}}\})\Rightarrow{\Gamma_{1},\Gamma_{2},[A]_{R_{1}\cap R_{2}}}

where we use {[A]R}\{[A]_{R}\} for a sequent consisting of only [A]R[A]_{R} if AA is not of the form !𝒰(B){!}_{\mathcal{U}}({B}) for R𝒰R\not\in\mathcal{U} or some repeated occurrences of [A]R[A]_{R} if AA is of the form !𝒰(B){!}_{\mathcal{U}}({B}) for R𝒰R\not\in\mathcal{U}. The proof strategy we use is essentially adopted from the one in a proof of cut-elimination for classical linear logic (CLL) [\citenameTroelstra, 1992]. Please see Section A.1 in Appendix for details.

5 LMRL and Session Types

In broad terms, a session is a sequence of interactions between two or more concurrently running processes and a session type is a form of type for specifying or classifying the interactions in a session. In this section, we are to illustrate a profound relation between LMRL and session types by mostly relying on (informal) explanation and examples. In particular, we are to outline the manner in which logical connectives in LMRL and various type constructors for session types are related.

We use AA and BB in the rest of this section both for formulas in LMRL and for session types (which are formally defined in Section 7). We use CH for (logical) channels supporting communication between multiple parties (processes) involved in a session. How such channels can be implemented based on some forms of physical channels is beyond the scope of this paper. It is entirely possible that distinct logical channels can share one underlying physical channel.

We assume that each channel CH consists of one or more endpoints and each process holding one endpoint can communicate with the processes holding the other endpoints (of the same channel). We use CHR\mbox{CH}_{R} to denote one endpoint of CH, where RR is a role set (that is, a subset of ¯{\overline{\emptyset}}). At any given time, if CH consists of nn endpoints CHR1,,CHRn\mbox{CH}_{R_{1}},\ldots,\mbox{CH}_{R_{n}}, then R1Rn=¯{R}_{1}\uplus\cdots\uplus{R}_{n}={\overline{\emptyset}}. We say that a channel CH is of some session type AA if each endpoint CHR\mbox{CH}_{R} can be assigned the type chan(R,A)\mbox{\bf chan}(R,A) (where chan is some linear type constructor). We may write chan(A)\mbox{\bf chan}(A) to mean chan(R,A)\mbox{\bf chan}(R,A) for some role set RR. We see this view of a channel and its endpoints as a style of interpretation for Lemma 4.5.

Note that a process can only hold an endpoint of a channel (rather than a channel per se). Also note that each endpoint is a linear value and it can be consumed by a function call in the sense that the endpoint becomes unavailable for any subsequent use.

5.1 Primitive formulas

Let us use act for both a primitive formula in LMRL and a primitive session type. For each act, there is a function chan_sync of the following type:

chan_sync:chan(R,act)𝟏\mbox{\tt chan\_sync}:\mbox{\bf chan}(R,\mbox{\it act})\rightarrow\mbox{$\mathbf{1}$}

where 𝟏\mathbf{1} refers to the standard unit type. Assume that a channel CH of some session type act consists of nn endpoints CHR1,,CHRn\mbox{CH}_{R_{1}},\ldots,\mbox{CH}_{R_{n}} and each endpoint is held by one process. When the nn (distinct) processes are calling chan_sync simultaneously on the endpoints CHRi\mbox{CH}_{R_{i}} (for i=1,,ni=1,\ldots,n), some actions specified by act happen with respect to the role sets RiR_{i}. It is certainly possible that the actions specified by a particular act can take place asynchronously, but there is no attempt to formally address this issue here.

As an example, let send(r)\mbox{\bf send}(r) be a primitive formula for any given role rr. Assume that CH is of the session type send(r)\mbox{\bf send}(r). Then the specified action by a call of chan_sync on an endpoint CHR\mbox{CH}_{R} can be described as follows:

  • Assume rRr\in{R}. Then chan_sync(CHR)\mbox{\tt chan\_sync}(\mbox{CH}_{R}) consumes CHR\mbox{CH}_{R} after broadcasting a message to the rest of the endpoints of CH.

  • Assume rRr\not\in{R}. Then chan_sync(CHR)\mbox{\tt chan\_sync}(\mbox{CH}_{R}) consumes CHR\mbox{CH}_{R} after receiving a message (sent from the endpoint CHR\mbox{CH}_{R^{\prime}} for the only RR^{\prime} containing rr).

Clearly, we may also have a primitive formula recv(r)\mbox{\bf recv}(r) for any given role rr. The action specified by recv(r)\mbox{\bf recv}(r) is opposite to what is specified by send(r)\mbox{\bf send}(r): The endpoint CHR\mbox{CH}_{R} for the only RR containing rr receives a message from each of the other endpoints.

As another example, let msg(r0,r1)\mbox{\bf msg}(r_{0},r_{1}) be a primitive formula for any given pair of distinct roles r0r_{0} and r1r_{1}. Assume that CH is of the session type msg(r0,r1)\mbox{\bf msg}(r_{0},r_{1}). Then the specified action by a call of chan_sync on CHR\mbox{CH}_{R} can be described as follows:

  • Assume r0Rr_{0}\in{R} and r1Rr_{1}\in{R}. Then chan_sync(CHR)\mbox{\tt chan\_sync}(\mbox{CH}_{R}) simply consumes CHR\mbox{CH}_{R}.

  • Assume r0Rr_{0}\in{R} and r1Rr_{1}\not\in{R}. Then chan_sync(CHR)\mbox{\tt chan\_sync}(\mbox{CH}_{R}) consumes CHR\mbox{CH}_{R} after sending a message to the endpoint CHR\mbox{CH}_{R^{\prime}} for the only RR^{\prime} containing r1r_{1}.

  • Assume r0Rr_{0}\not\in{R} and r1Rr_{1}\in{R}. Then chan_sync(CHR)\mbox{\tt chan\_sync}(\mbox{CH}_{R}) consumes CHR\mbox{CH}_{R} after receiving a message (sent from the endpoint CHR\mbox{CH}_{R^{\prime}} for the only RR^{\prime} containing r0r_{0}).

  • Assume r0Rr_{0}\not\in{R} and r1Rr_{1}\not\in{R}. Then chan_sync(CHR)\mbox{\tt chan\_sync}(\mbox{CH}_{R}) simply consumes CHR\mbox{CH}_{R}.

In other words, msg(r0,r1)\mbox{\bf msg}(r_{0},r_{1}) specifies a form of point-to-point messaging from the endpoint CHR\mbox{CH}_{R} to the endpoint CHR\mbox{CH}_{R^{\prime}} for RR and RR^{\prime} containing r0r_{0} and r1r_{1}, respectively.

5.2 Generalized Negation

Given an endomorphism ff on ¯{\overline{\emptyset}}, there is a unary connective ¬f\lnot_{f} in LMRL that generalizes the notion of negation. The meaning of ¬f(A)\neg_{f}(A) as a session type is given by the following function for eliminating the session type constructor ¬f\lnot_{f}:

chan_neg:chan(R,¬f(A))chan(f1(R),A)\begin{array}[]{lcl}\mbox{\tt chan\_neg}&:&\mbox{\bf chan}(R,\lnot_{f}(A))\rightarrow\mbox{\bf chan}({f}^{-{\kern-1.0pt}1}(R),A)\\ \end{array}

Given an endpoint CHR\mbox{CH}_{R} of type chan(R,¬f(A))\mbox{\bf chan}(R,\lnot_{f}(A)), chan_neg turns this endpoint into one of type chan(f1(R),A)\mbox{\bf chan}({f}^{-{\kern-1.0pt}1}(R),A). In other words, ¬f\lnot_{f} means that the process holding an endpoint CHR\mbox{CH}_{R} needs to change the role set RR attached to the endpoint into the role set f1(R){f}^{-{\kern-1.0pt}1}(R). In the case where ff is a permutation, ¬f\lnot_{f} simply means for a process to permute according to ff the roles it plays (e.g., server and client switch roles).

5.3 Additive conjunction/disjunction

Given a role rr, there is a binary connective &𝒰{\&}_{\mathcal{U}} in LMRL for the principal ultrafilter 𝒰\mathcal{U} at rr (that consists of all of the role sets containing rr). Let us write &r{\&}_{r} for this &𝒰{\&}_{\mathcal{U}}. Also, we may write chan(R,A&B)\mbox{\bf chan}(R,A{\&}B) to mean chan(R,A&rB)\mbox{\bf chan}(R,A{\&}_{r}B) for some rRr\in R and chan(R,AB)\mbox{\bf chan}(R,A{\oplus}B) to mean chan(R,A&rB)\mbox{\bf chan}(R,A{\&}_{r}B) for some rRr\not\in R. For each CH of session type A&rBA{\&}_{r}B, there is exactly one endpoint of type chan(A&B)\mbox{\bf chan}(A{\&}B) and each of the other endpoints is of type chan(AB)\mbox{\bf chan}(A{\oplus}B). Intuitively, a process holding an endpoint of type chan(R,A&B)\mbox{\bf chan}(R,A{\&}B) can issue an order to turn the type of the endpoint into either chan(R,A)\mbox{\bf chan}(R,A) or chan(R,B)\mbox{\bf chan}(R,B) while any process holding an endpoint of type chan(R,AB)\mbox{\bf chan}(R,A{\oplus}B) turns the type of the endpoint into either chan(R,A)\mbox{\bf chan}(R,A) or chan(R,B)\mbox{\bf chan}(R,B) by following an issued order.

Given two (linear) types T1T_{1} and T2T_{2}, let us write T1T2T_{1}\oplus T_{2} for the linear sum type of T1T_{1} and T2T_{2}. The following functions are for eliminating the session type constructor &r{\&}_{r}:

chan_aconj_l:chan(R,A&B)chan(R,A)chan_aconj_r:chan(R,A&B)chan(R,B)chan_adisj:chan(R,AB)chan(R,A)chan(R,B)\begin{array}[]{lcl}\mbox{\tt chan\_aconj\_l}&:&\mbox{\bf chan}(R,A{\&}B)\rightarrow\mbox{\bf chan}(R,A)\\ \mbox{\tt chan\_aconj\_r}&:&\mbox{\bf chan}(R,A{\&}B)\rightarrow\mbox{\bf chan}(R,B)\\ \mbox{\tt chan\_adisj}&:&\mbox{\bf chan}(R,A{\oplus}B)\rightarrow\mbox{\bf chan}(R,A)\oplus\mbox{\bf chan}(R,B)\\ \end{array}

Assume that a channel CH is of session type A&rBA{\&}_{r}B and it consists of nn endpoints of the following types: chan(R1,A&rB),,chan(Rn,A&rB)\mbox{\bf chan}(R_{1},A{\&}_{r}B),\ldots,\mbox{\bf chan}(R_{n},A{\&}_{r}B). Without loss of generality, we may assume that rR1r\in R_{1}. If there are one process calling chan_aconj_l (chan_aconj_r) on CHR1\mbox{CH}_{R_{1}} and n1n-1 processes calling chan_adisj on CHRi\mbox{CH}_{R_{i}} for i=2,,ni=2,\ldots,n, then these calls all return; the one calling chan_aconj_l (chan_aconj_r) obtains the same CHR1\mbox{CH}_{R_{1}} but its type changes to chan(R1,A)\mbox{\bf chan}(R_{1},A) (chan(R1,B)\mbox{\bf chan}(R_{1},B)); each of the other n1n-1 processes obtains a value of the type chan(Ri,A)chan(Ri,B)\mbox{\bf chan}(R_{i},A)\oplus\mbox{\bf chan}(R_{i},B) that is formed by attaching a tag to CHRi\mbox{CH}_{R_{i}} to indicate whether CHRi\mbox{CH}_{R_{i}} is given the type chan(Ri,A)\mbox{\bf chan}(R_{i},A) or chan(Ri,B)\mbox{\bf chan}(R_{i},B). A direct implementation can simply be requiring the process calling chan_aconj_l (chan_aconj_r) on CHR1\mbox{CH}_{R_{1}} to send (via the underlying physical channel for CH) the tag 0 (1) to the other processes calling chan_adisj on CHRi\mbox{CH}_{R_{i}} for i=2,,ni=2,\ldots,n.

It should be noted that the meaning of &/{\&}/{\oplus} based on a reading of chan(A&B)/chan(AB)\mbox{\bf chan}(A{\&}B)/\mbox{\bf chan}(A{\oplus}B) is eliminatory (rather than introductory). Basically, the introductory meaning of a type TT is based on how a value of the type can be formed while the eliminatory meaning of the type is based on how a value of the type can be used. For instance, assume that TT is a sum type T1T2T_{1}\oplus T_{2}; a value of TT can be formed by either left-injecting a value of type T1T_{1} or right-injecting a value of type T2T_{2}; a value of TT can be eliminated by performing case analysis on the value. Introductorily, A&BA{\&}B means to offer choice AA and choice BB while ABA{\oplus}B means to choose either AA or BB.

5.4 Multiplicative conjunction/disjunction

Given a role rr, there is a binary connective 𝒰{\otimes}_{\mathcal{U}} in LMRL for the principal ultrafilter 𝒰\mathcal{U} at rr. Let us write r{\otimes}_{r} for this 𝒰{\otimes}_{\mathcal{U}}. Also, we may write chan(R,AB)\mbox{\bf chan}(R,A{\otimes}B) to mean chan(R,ArB)\mbox{\bf chan}(R,A{\otimes}_{r}B) for some rRr\in R and chan(R,AB)\mbox{\bf chan}(R,A{\invamp}B) to mean chan(R,ArB)\mbox{\bf chan}(R,A{\otimes}_{r}B) for some rRr\not\in R. For each CH of session type ArBA{\otimes}_{r}B, there is exactly one endpoint of type chan(AB)\mbox{\bf chan}(A{\otimes}B) and each of the other endpoints is of type chan(AB)\mbox{\bf chan}(A{\invamp}B). Intuitively, a process holding an endpoint of type chan(R,AB)\mbox{\bf chan}(R,A{\otimes}B) turns it into two endpoints of types chan(R,A)\mbox{\bf chan}(R,A) and chan(R,B)\mbox{\bf chan}(R,B) for being used in any interleaving order while any process holding an endpoint of type chan(R,AB)\mbox{\bf chan}(R,A{\invamp}B) turns it into two endpoints of types chan(R,A)\mbox{\bf chan}(R,A) and chan(R,B)\mbox{\bf chan}(R,B) for being used concurrently. In other words, a process holding an endpoint of type chan(R,AB)\mbox{\bf chan}(R,A{\otimes}B) can choose to interleave the interactions specified by AA and BB in any order while any process holding an endpoint of type chan(R,AB)\mbox{\bf chan}(R,A{\invamp}B) must be able to handle any chosen order of interleaving of interactions specified by AA and BB.

Given two (linear) types T1T_{1} and T2T_{2}, let us write T1T2T_{1}\otimes T_{2} for the linear product type of T1T_{1} and T2T_{2}. We can introduce the following functions for eliminating the session type constructor r{\otimes}_{r}:

chan_mconj:chan(R,AB)chan(R,A)chan(R,B)chan_mdisj_l:(chan(R,AB),chan(R,B)𝟏)chan(R,A)chan_mdisj_r:(chan(R,AB),chan(R,A)𝟏)chan(R,B)\begin{array}[]{lcl}\mbox{\tt chan\_mconj}&:&\mbox{\bf chan}(R,A{\otimes}B)\rightarrow\mbox{\bf chan}(R,A)\otimes\mbox{\bf chan}(R,B)\\ \mbox{\tt chan\_mdisj\_l}&:&(\mbox{\bf chan}(R,A{\invamp}B),\mbox{\bf chan}(R,B)\rightarrow\mbox{$\mathbf{1}$})\rightarrow\mbox{\bf chan}(R,A)\\ \mbox{\tt chan\_mdisj\_r}&:&(\mbox{\bf chan}(R,A{\invamp}B),\mbox{\bf chan}(R,A)\rightarrow\mbox{$\mathbf{1}$})\rightarrow\mbox{\bf chan}(R,B)\\ \end{array}

Assume that a channel CH is of session type ArBA{\otimes}_{r}B and it consists of nn endpoints of the following types: chan(R1,ArB),,chan(Rn,ArB)\mbox{\bf chan}(R_{1},A{\otimes}_{r}B),\ldots,\mbox{\bf chan}(R_{n},A{\otimes}_{r}B). Without loss of generality, we may assume that rR1r\in R_{1}. If there are one process calling chan_mconj on CHR1\mbox{CH}_{R_{1}} and n1n-1 processes calling either chan_mdisj_l or chan_mdisj_r on CHRi\mbox{CH}_{R_{i}} for i=2,,ni=2,\ldots,n and some functions, then these calls all return; the one calling chan_mconj on CHR1\mbox{CH}_{R_{1}} returns a pair of endpoints CHR1\mbox{CH}^{\prime}_{R_{1}} and CHR1′′\mbox{CH}^{\prime\prime}_{R_{1}} of types chanR1(A)\mbox{\bf chan}_{R_{1}}(A) and chanR1(B)\mbox{\bf chan}_{R_{1}}(B), respectively; each of those processes calling chan_mdisj_l on CHRi\mbox{CH}_{R_{i}} (for some ii) and some function obtains a pair of endpoints CHRi\mbox{CH}^{\prime}_{R_{i}} and CHRi′′\mbox{CH}^{\prime\prime}_{R_{i}} and then keeps CHRi\mbox{CH}^{\prime}_{R_{i}} as the return value while passing CHRi′′\mbox{CH}^{\prime\prime}_{R_{i}} to the function and initiating a thread to execute the function call; each of those processes calling chan_mdisj_r does analogously.

We do not specify the manner in which CH\mbox{CH}^{\prime} and CH′′\mbox{CH}^{\prime\prime} are actually created or obtained as there are many possibilities in practice. For instance, it is possible to use CH for CH′′\mbox{CH}^{\prime\prime} after requiring the process holding the endpoint CHR1\mbox{CH}_{R_{1}} to create a fresh channel CH\mbox{CH}^{\prime} so that the process keeps the endpoint CHR1\mbox{CH}^{\prime}_{R_{1}} for itself and sends each CHRi\mbox{CH}^{\prime}_{R_{i}} (via CH) to the process holding CHRi\mbox{CH}_{R_{i}}, where ii ranges from 22 to nn. With this implementation strategy, ABA{\otimes}B (ABA{\invamp}B) is often interpreted as output AA and then behave as BB (input AA and then behave as BB[\citenameWadler, 2012]. However, we see this interpretation as a form of convenience (rather than a logical consequence derived from LMRL). For instance, we can certainly have a different implementation that chooses a particular rr (e.g., 0) and requires the process holding CHR\mbox{CH}_{R} for the only RR containing rr to create CH\mbox{CH}^{\prime} and then sends its endpoints elsewhere. As far as we can see, LMRL specifies in the case of r{\otimes}_{r} whether the two obtained endpoints CHR\mbox{CH}^{\prime}_{R} and CHR′′\mbox{CH}^{\prime\prime}_{R} should be used interleavingly or concurrently but it does not specify how these two endpoints are actually obtained.

5.5 Session concatenation

Given two session types AA and BB, a process holding an endpoint of type chan(R,ArB)\mbox{\bf chan}(R,A{\otimes}_{r}B) for some rRr\in R can turn it into two endpoints of types chan(R,A)\mbox{\bf chan}(R,A) and chan(R,B\mbox{\bf chan}(R,B) and then use them in any interleaving order it desires. We can have @r@_{r} as a variant of r{\otimes}_{r}: A process holding an endpoint of type chan(R,A@rB)\mbox{\bf chan}(R,A@_{r}B) for some rRr\in R can turn it into two endpoints of types chan(R,A)\mbox{\bf chan}(R,A) and chan(R,B\mbox{\bf chan}(R,B) but is required to finish using the one of type chan(R,A)\mbox{\bf chan}(R,A) before starting to use the other. There is actually no need in this case for the process to hold two endpoints simultaneously: We can introduce the following function chan_append that uses an endpoint of type chan(R,A@rB)\mbox{\bf chan}(R,A@_{r}B) first as an endpoint of type chan(R,A)\mbox{\bf chan}(R,A) and then as an endpoint of type chan(R,B)\mbox{\bf chan}(R,B):

chan_append:(chan(R,A@B),chan(R,A)T)Tchan(R,B)\begin{array}[]{lcl}\mbox{\tt chan\_append}&:&(\mbox{\bf chan}(R,A@B),\mbox{\bf chan}(R,A)\rightarrow T)\rightarrow T\otimes\mbox{\bf chan}(R,B)\\ \end{array}

Note that A@BA@B (instead of A@rBA@_{r}B) occurs in the type of chan_append. Unlike chan_mconj (for r{\otimes}_{r}), chan_append is not required to send new endpoints to other processes and thus there is no difference between @r@_{r} and @r@_{r^{\prime}} even if rr and rr^{\prime} are distinct. In essence, the function chan_append takes an endpoint CHR\mbox{CH}_{R} of type chan(R,A@B)\mbox{\bf chan}(R,A@B) and a function; it first treats the endpoint CHR\mbox{CH}_{R} as one of type chan(R,A)\mbox{\bf chan}(R,A) and calls the function on it; the value returned by the function call is then paired with CHR\mbox{CH}_{R} as the return value (of the call to chan_append).

Given two distinct roles r0r_{0} and r1r_{1}, we used msg(r0,r1)\mbox{\bf msg}(r_{0},r_{1}) to mean messaging from r0r_{0} to r1r_{1}. We now use msg(r0,r1,T)\mbox{\bf msg}(r_{0},r_{1},T) to mean a value of type TT sent from r0r_{0} to r1r_{1}. We can introduce the following function for sending:

chan_send:(chan(R,msg(r0,r1,T)@A),T)chan(R,A)\begin{array}[]{lcl}\mbox{\tt chan\_send}&:&(\mbox{\bf chan}(R,\mbox{\bf msg}(r_{0},r_{1},T)@A),T)\rightarrow\mbox{\bf chan}(R,A)\\ \end{array}

where it is assumed that r0Rr_{0}\in R and r1Rr_{1}\not\in R, and the following function for receiving:

chan_recv:(chan(R,msg(r0,r1,T)@A))Tchan(R,A)\begin{array}[]{lcl}\mbox{\tt chan\_recv}&:&(\mbox{\bf chan}(R,\mbox{\bf msg}(r_{0},r_{1},T)@A))\rightarrow T\otimes\mbox{\bf chan}(R,A)\\ \end{array}

where it is assumed that r0Rr_{0}\not\in R and r1Rr_{1}\in R. In the case where there are only two roles 0 and 11, we may choose to write send(T)\mbox{\bf send}(T) for msg(0,1,T)\mbox{\bf msg}(0,1,T) and recv(T)\mbox{\bf recv}(T) for msg(1,0,T)\mbox{\bf msg}(1,0,T). If one desires, one can even write TAT{\otimes}A for send(T)@A\mbox{\bf send}(T)@A and TAT{\invamp}A for recv(T)@A\mbox{\bf recv}(T)@A (or TAT{\otimes}A for recv(T)@A\mbox{\bf recv}(T)@A and TAT{\invamp}A for send(T)@A\mbox{\bf send}(T)@A). In this case, it is fine to interpret /\otimes/\invamp as output/input, and it is also fine to interpret /\otimes/\invamp as input/output.

5.6 More session constructors

We may introduce a primitive formula nil for which the specified action is simply doing nothing. Given a role rr and a session type AA, we define option(r,A)\mbox{\bf option}(r,A) as A&rnilA{\&}_{r}\mbox{\bf nil} and define repseq(r,A)\mbox{\bf repseq}(r,A) recursively as option(r,A@repseq(r,A))\mbox{\bf option}(r,A@\mbox{\bf repseq}(r,A)). Assume rRr\in R. A process holding an endpoint CHR\mbox{CH}_{R} of type chan(R,option(r,A))\mbox{\bf chan}(R,\mbox{\bf option}(r,A)) can choose to perform a session specified by AA on CHR\mbox{CH}_{R} or simply terminate the use of CHR\mbox{CH}_{R}. A process holding an endpoint CHR\mbox{CH}_{R} of type chan(R,repseq(r,A))\mbox{\bf chan}(R,\mbox{\bf repseq}(r,A)) can choose to perform a session specified by AA repeatedly.

Example 1.   Let us assume the availability of 3 roles: Seller(0), Buyer1(1) and Buyer2(2). A description of the one-seller-and-two-buyers (S0B1B2) protocol due to [\citenameHonda et al., 2008] can essentially be given as follows: Buyer1 sends a book title to Seller; Seller replies a price quote to both Buyer1 and Buyer2; Buyer1 tells Buyer2 how much he can contribute; if Buyer2 is willing to pay for the remaining part, she sends Seller a proof of payment and Seller sends her a receipt for the sale (and the session ends); if Buyer2 is not willing, she terminates the session. Following is an encoding of the S0B1B2 protocol as a session type:

title(1, 0)@quote(0, 1)@quote(0, 2)@
contrib(1, 2)@option(2, proof(2, 0)@receipt(0, 2))

where title(1, 0) means sending the title from role 1 to role 0; quote(0, 1) means sending the price quote from role 0 to role 1; contrib(1, 2) means sending the amount of contribution of Buyer1 from role 1 to role 2; etc.

Example 2.   Let us assume the availability of three roles: Client(0), Server(1), and Verifier(2). A protocol for login involving three parties can be described as follows: Client sends userid to Server; Server sends the received userid to Verifier; Verifier queries Client an indefinite number of times; Verifier sends the verification result to Server. Following is an encoding of this protocol as a session type:

userid(0,1)@userid(1,2)@
repseq(2,query(2,0)@answer(0,2))@result(2,1)

where userid(0,1) and userid(1,2) mean sending a userid from role 0 to role 1 and from role 1 to role 2, respectively; query(2,0) means sending a query question from role 2 to role 0; answer(0,2) means sending an answer (to the received question) from role 0 to role 2; result(2,1) means sending a result from role 2 to role 1 (to indicate success or failure of verification).

Example 3.   Let us assume the availability of three roles: Judge(0), Contestant1(1), and Contestant2(2). A protocol for some kind of contest involving three parties can be described as follows: Judge broadcasts a query to Contestant1 and Contestant2; each contestant sends his or her answer to Judge and then receives a score from Judge. Following is an encoding of this protocol as a session type:

query(0)@(mconj(0, answer(1,0)@score(0,1), answer(2,0)@score(0,2)))

where query(0) means broadcasting a query from role 0 to all of the other roles; the syntax mconj(0, ...) means 0{\otimes}_{0}; answer(1,0) means sending an answer from role 1 to role 0 and score(0,1) means sending a score from role 0 to role 1; answer(2,0) and score(0,2) mean similarly. Let AiA_{i} be answer(i,0)@score(0,i)\mbox{\it answer}(i,0)@\mbox{\it score}(0,i) for i=1,2i=1,2. At some moment, Judge holds two endpoints of types chan({0},A1)\mbox{\bf chan}(\{0\},A_{1}) and chan({0},A2)\mbox{\bf chan}(\{0\},A_{2}), and he can certainly use them in two concurrently running threads (but is not required to do so). On the other hand, Contestant1 holds two endpoints of types chan({1},A1)\mbox{\bf chan}(\{1\},A_{1}) and chan({1},A2)\mbox{\bf chan}(\{1\},A_{2}) at the same moment and is required to use them concurrently. And the same can be said about Contestant2.

5.7 Splitting an endpoint

Lemma 4.3 corresponds to a function for splitting a given endpoint:

chan_split:(chan(R1R2,A),chan(R1,A)1)chan(R2,A)\begin{array}[]{lcr}\mbox{\tt chan\_split}&:&(\mbox{\bf chan}(R_{1}\uplus{R}_{2},A),\mbox{\bf chan}(R_{1},A)\rightarrow 1)\rightarrow\mbox{\bf chan}(R_{2},A)\end{array}

When applied to an endpoint CHR1R2\mbox{CH}_{R_{1}\uplus{R}_{2}} and a function, chan_split initiates a thread to call the function on the endpoint (for it being used as CHR1\mbox{CH}_{R_{1}}) and then returns the endpoint (for it to be used as CHR2\mbox{CH}_{R_{2}}).

In the context of session-typed multiparty channels, the inadmissibility of the following inference rule (for disjoint R1R_{1} and R2R_{2}) should be clear:

([A]R1,[A]R2)[A]R1R2([A]_{R_{1}},[A]_{R_{2}})\vdash[A]_{R_{1}\uplus{R}_{2}}

We cannot simply merge two given endpoints CHR1\mbox{CH}^{\prime}_{R_{1}} and CHR2′′\mbox{CH}^{\prime\prime}_{R_{2}} as CH\mbox{CH}^{\prime} and CH′′\mbox{CH}^{\prime\prime} may not be the same channel. If they happen to be the same channel, then allowing a process to hold both CHR1\mbox{CH}^{\prime}_{R_{1}} and CHR2′′\mbox{CH}^{\prime\prime}_{R_{2}} can potentially lead to deadlocking.

5.8 Multiparty cut-elimination

Lemma 4.7 corresponds to the following function that can be called to eliminate any endpoint CH\mbox{CH}_{\emptyset}:

chan_1_cut:(chan(,A))𝟏\begin{array}[]{lcr}\mbox{\tt chan\_1\_cut}&:&(\mbox{\bf chan}(\emptyset,A))\rightarrow\mbox{$\mathbf{1}$}\end{array}

Lemma 4.11 (or more precisely, its proof) indicates the existence of a generic method for forwarding messages between three endpoints of certain matching types:

chan_3_cut:(chan(R1,A),chan(R2,A),chan(R3,A))𝟏\begin{array}[]{lcr}\mbox{\tt chan\_3\_cut}&:&(\mbox{\bf chan}(R_{1},A),\mbox{\bf chan}(R_{2},A),\mbox{\bf chan}(R_{3},A))\rightarrow\mbox{$\mathbf{1}$}\end{array}

where R¯1R¯2R¯3=¯{\overline{R}}_{1}\uplus{\overline{R}}_{2}\uplus{\overline{R}}_{3}={\overline{\emptyset}} is assumed and each endpoint belongs to a distinct channel. The following chan_2_cut can be seen a special case of chan_3_cut where R1=RR_{1}=R, R2=R¯R_{2}={\overline{R}} and R3=¯R_{3}={\overline{\emptyset}}:

chan_2_cut:(chan(R,A),chan(R¯,A))𝟏\begin{array}[]{lcr}\mbox{\tt chan\_2\_cut}&:&(\mbox{\bf chan}(R,A),\mbox{\bf chan}({\overline{R}},A))\rightarrow\mbox{$\mathbf{1}$}\end{array}

When applied to three endpoints CHRii\mbox{CH}^{i}_{R_{i}} for 1i31\leq i\leq 3, chan_3_cut behaves in the following manner: Suppose that a message for role rr is received at CHR11\mbox{CH}^{1}_{R_{1}}; we have rR¯2R¯3r\in{\overline{R}}_{2}\uplus{\overline{R}}_{3} as rR1r\in R_{1} holds; if rR¯2r\in{\overline{R}}_{2}, the received message is sent via the endpoint CHR22\mbox{CH}^{2}_{R_{2}} to the process holding CHR2\mbox{CH}^{2}_{R} for some RR satisfying rRr\in R; if rR¯3r\in{\overline{R}}_{3}, the received message is sent via the endpoint CHR33\mbox{CH}^{3}_{R_{3}} to the process holding CHR3\mbox{CH}^{3}_{R} for some RR satisfying rRr\in R. After chan_3_cut is called on CHR11\mbox{CH}^{1}_{R_{1}}, CHR22\mbox{CH}^{2}_{R_{2}} and CHR33\mbox{CH}^{3}_{R_{3}}, all of the other endpoints of CH1\mbox{CH}^{1}, CH2\mbox{CH}^{2} and CH3\mbox{CH}^{3} are considered belonging to one single channel. Implementing chan_3_cut consists of a crucial step in implementation of multiparty channels.

5.9 Modality and Quantification

The exponentials !/?{!}/{?} in linear logic are modal connectives. Given a role rr, there is a connective !𝒰{!}_{\mathcal{U}} in LMRL for the principal ultrafilter 𝒰\mathcal{U} at rr. Let us write !r{!}_{r} for this !𝒰{!}_{\mathcal{U}}. Essentially, !r(A){!}_{r}(A) for any given AA can be replaced with repeat(r,A)\mbox{\bf repeat}(r,A), which is recursively defined as Arrepeat(r,A)A{\otimes}_{r}\mbox{\bf repeat}(r,A). As a session type, !r(A){!}_{r}(A) means that a sequence of interactions specified by AA can be repeated concurrently (while repseq(r,A)\mbox{\bf repseq}(r,A) means sequential repetition).

Given a role rr, there is also a quantifier 𝒰\forall_{\mathcal{U}} for in LMRL for the principal ultrafilter 𝒰\mathcal{U} at rr. Let us write r\forall_{r} for this 𝒰\forall_{\mathcal{U}}, which is supposed to be used for constructing dependent session types (that are not studied here).

6 MTLC0\mbox{MTLC}_{0}: Linearly typed Multi-threaded λ\lambda-calculus

expr.e::=xfrcc(e)e1,e2fst(e)snd(e)𝚕𝚎𝚝x1,x2=e1𝚒𝚗e2𝚎𝚗𝚍𝚕𝚊𝚖x.e𝚊𝚙𝚙(e1,e2)𝚏𝚒𝚡x.vvaluesv::=xrccc(v)v1,v2𝚕𝚊𝚖x.etypesT::=δ𝟏T1T2T^1iT^2viewtypesT^::=δ^TT^1T^2T^1lT^2\begin{array}[]{lrcl}\mbox{expr.}&e&::=&x\mid f\mid\mbox{\it rc}\mid c(\vec{e})\mid\\ &&&\langle\rangle\mid\langle e_{1},e_{2}\rangle\mid\mbox{\tt fst}(e)\mid\mbox{\tt snd}(e)\mid\\ &&&{\tt let}\;\langle x_{1},x_{2}\rangle=e_{1}\;{\tt in}\;e_{2}\;{\tt end}\mid\\ &&&{\tt lam}\;x.\,e\mid{\tt app}(e_{1},e_{2})\mid{\tt fix}\;x.\,v\\ \mbox{values}&v&::=&x\mid\mbox{\it rc}\mid\mbox{\it cc}(\vec{v})\mid\langle\rangle\mid\langle v_{1},v_{2}\rangle\mid{\tt lam}\;x.\,e\\ \mbox{types}&\mbox{$T$}&::=&\mbox{$\delta$}\mid\mbox{$\mathbf{1}$}\mid\mbox{$T$}_{1}*\mbox{$T$}_{2}\mid\mbox{$\hat{T}$}_{1}\rightarrow_{i}\mbox{$\hat{T}$}_{2}\\ \mbox{viewtypes}&\mbox{$\hat{T}$}&::=&\mbox{$\hat{\delta}$}\mid\mbox{$T$}\mid\mbox{$\hat{T}$}_{1}\otimes\mbox{$\hat{T}$}_{2}\mid\mbox{$\hat{T}$}_{1}\rightarrow_{l}\mbox{$\hat{T}$}_{2}\\ \end{array}
Figure 3: Some syntax for MTLC0\mbox{MTLC}_{0}

While what is presented in Section 5 may sound intuitive, it is not formal. In this section and the next, we formulate a design of linearly typed channels for multiparty communication where the types are directly rooted in LMRL. This formulation itself is standard and the contribution it brings to this paper is mostly technical.

We first present a multi-threaded lambda-calculus MTLC0\mbox{MTLC}_{0} equipped with a simple linear type system, setting up the basic machinery for further development. Some syntax of MTLC0\mbox{MTLC}_{0} is given in Figure 3. We use e\vec{e} and v\vec{v} for sequences of expressions and values, respectively. We use rc for constant resources and cc for constants, which include both constant constructors cc and constant functions cf. We treat resources in MTLC0\mbox{MTLC}_{0} abstractly and will later introduce communication channels as a concrete form of resources. The meaning of various standard forms of expressions in MTLC0\mbox{MTLC}_{0} should be intuitively clear. We may refer to a closed expression (containing no free variables) as a program.

We use TT and T^\hat{T} for (non-linear) types and (linear) viewtypes, respectively. Note that a type is always considered a viewtype and a viewtype is referred to as a true viewtype if it is not a type. We use δ\delta and δ^\hat{\delta} for base types and base viewtypes, respectively. For instance, int and bool are base types for integers and booleans, respectively. We also assume the availability of integer constants and sets of integer constants for forming types. For instance, we may have a singleton type int(i)\mbox{\bf int}(i) for each integer ii, which can only be assigned to a dynamic expression of value equal to ii.

For a simplified presentation, we do not introduce any concrete base viewtypes in MTLC0\mbox{MTLC}_{0}. We assume a signature SIG for assigning a viewtype to each constant resource rc and a constant type (c-type) schema of the form (T^1,,T^n)T^0(\mbox{$\hat{T}$}_{1},\ldots,\mbox{$\hat{T}$}_{n})\Rightarrow\mbox{$\hat{T}$}_{0} to each constant. For instance, we may have a constant function iadd of the following c-type schema:

iadd:(int(i),int(j))int(i+j)\begin{array}[]{rcl}\mbox{\it iadd}&:&(\mbox{\bf int}(i),\mbox{\bf int}(j))\Rightarrow\mbox{\bf int}(i+j)\end{array}

where ii and jj are meta-variables ranging over integer constants. Each occurrence of iadd in a program is given a c-type that is an instance of the c-type schema assigned to iadd.

Let T^1\mbox{$\hat{T}$}_{1} and T^2\mbox{$\hat{T}$}_{2} be two viewtypes. The type constructor \otimes is based on multiplicative conjunction in linear logic. Intuitively, if a resource is assigned the viewtype T^1T^2\mbox{$\hat{T}$}_{1}\otimes\mbox{$\hat{T}$}_{2}, then the resource is a conjunction of two resources of viewtypes T^1\mbox{$\hat{T}$}_{1} and T^2\mbox{$\hat{T}$}_{2}. The type constructor l\rightarrow_{l} is essentially based on linear implication \multimap in linear logic. Given a function of the viewtype T^1lT^2\mbox{$\hat{T}$}_{1}\rightarrow_{l}\mbox{$\hat{T}$}_{2} and a value of the viewtype T^1\mbox{$\hat{T}$}_{1}, applying the function to the value yields a result of the viewtype T^2\mbox{$\hat{T}$}_{2} while the function itself is consumed. If the function is of the type T^1iT^2\mbox{$\hat{T}$}_{1}\rightarrow_{i}\mbox{$\hat{T}$}_{2}, then applying the function does not consume it. The subscript ii in i\rightarrow_{i} is often dropped, that is, \rightarrow is assumed to be i\rightarrow_{i} by default. The meaning of various forms of types and viewtypes is to be made clear and precise when the rules are presented for assigning viewtypes to expressions in MTLC0\mbox{MTLC}_{0}.

There is a special constant function thread_create in MTLC0\mbox{MTLC}_{0} for thread creation, which is assigned the following interesting c-type:

thread_create:(𝟏l𝟏)𝟏\begin{array}[]{rcl}\mbox{\it thread\_create}&:&(\mbox{$\mathbf{1}$}\rightarrow_{l}\mbox{$\mathbf{1}$})\Rightarrow\mbox{$\mathbf{1}$}\end{array}

A function of the type 𝟏l𝟏\mbox{$\mathbf{1}$}\rightarrow_{l}\mbox{$\mathbf{1}$} is a procedure that takes no arguments and returns no result (when its evaluation terminates). Given that 𝟏l𝟏\mbox{$\mathbf{1}$}\rightarrow_{l}\mbox{$\mathbf{1}$} is a true viewtype, a procedure of this type may contain resources and thus must be called exactly once. The operational semantics of thread_create is to be formally defined later.

A variety of mappings, finite or infinite, are to be introduced in the rest of the presentation. We use [][] for the empty mapping and [i1,,ino1,,on][i_{1},\ldots,i_{n}\mapsto o_{1},\ldots,o_{n}] for the finite mapping that maps iki_{k} to oko_{k} for 1kn1\leq k\leq n. Given a mapping mm, we write dom(m)\mbox{\bf dom}(m) for the domain of mm. If idom(m)i\not\in\mbox{\bf dom}(m), we use m[io]m[i\mapsto o] for the mapping that extends mm with a link from ii to oo. If idom(m)i\in\mbox{\bf dom}(m), we use m\im\backslash i for the mapping obtained from removing the link from ii to m(i)m(i) in mm, and m[i:=o]m[i:=o] for (m\i)[io](m\backslash i)[i\mapsto o], that is, the mapping obtained from replacing the link from ii to m(i)m(i) in mm with another link from ii to oo.

ρ(rc)={rc}ρ(c(e1,,en))=ρ(e1)ρ(en)ρ(x)=ρ()=ρ(e1,e2)=ρ(e1)ρ(e2)ρ(fst(e))=ρ(e)ρ(snd(e))=ρ(e)ρ(if(e0,e1,e2))=ρ(e0)ρ(e1)ρ(𝚕𝚎𝚝x1,x2=e1𝚒𝚗e2𝚎𝚗𝚍)=ρ(e1)ρ(e2)ρ(𝚕𝚊𝚖x.e)=ρ(e)ρ(𝚊𝚙𝚙(e1,e2))=ρ(e1)ρ(e2)ρ(𝚏𝚒𝚡x.v)=ρ(v)\begin{array}[]{rcl}\rho(\mbox{\it rc})&=&\{\mbox{\it rc}\}\\ \rho(c(e_{1},\ldots,e_{n}))&=&\rho(e_{1})\uplus\cdots\uplus\rho(e_{n})\\ \rho(x)&=&\emptyset\\ \rho(\langle\rangle)&=&\emptyset\\ \rho(\langle e_{1},e_{2}\rangle)&=&\rho(e_{1})\uplus\rho(e_{2})\\ \rho(\mbox{\tt fst}(e))&=&\rho(e)\\ \rho(\mbox{\tt snd}(e))&=&\rho(e)\\ \rho(\mbox{\tt if}(e_{0},e_{1},e_{2}))&=&\rho(e_{0})\uplus\rho(e_{1})\\ \rho({\tt let}\;\langle x_{1},x_{2}\rangle=e_{1}\;{\tt in}\;e_{2}\;{\tt end})&=&\rho(e_{1})\uplus\rho(e_{2})\\ \rho({\tt lam}\;x.\,e)&=&\rho(e)\\ \rho({\tt app}(e_{1},e_{2}))&=&\rho(e_{1})\uplus\rho(e_{2})\\ \rho({\tt fix}\;x.\,v)&=&\rho(v)\\ \end{array}
Figure 4: The definition of ρ()\rho(\cdot)

We define a function ρ()\rho(\cdot) in Figure 4 to compute the multiset (that is, bag) of constant resources in a given expression. Note that \uplus denotes the multiset union. In the type system of MTLC0\mbox{MTLC}_{0}, it is to be guaranteed that ρ(e1)\rho(e_{1}) equals ρ(e2)\rho(e_{2}) whenever an expression of the form if(e0,e1,e2)\mbox{\tt if}(e_{0},e_{1},e_{2}) is constructed, and this justifies ρ(if(e0,e1,e2))\rho(\mbox{\tt if}(e_{0},e_{1},e_{2})) being defined as ρ(e0)ρ(e1)\rho(e_{0})\uplus\rho(e_{1}).

We use {\mathcal{R}} to range over finite multisets of resources. Therefore, {\mathcal{R}} can also be regarded as a mapping from resources to natural numbers: (rc)=n{\mathcal{R}}(\mbox{\it rc})=n means that there are nn occurrences of rc in {\mathcal{R}}. It is clear that we may not combine resources arbitrarily. For instance, we may want to exclude the combination of one resource stating integer 0 at a location L and another one stating integer 1 at the same location. We fix an abstract collection 𝐑𝐄𝐒{\bf RES} of finite multisets of resources and assume the following:

  • 𝐑𝐄𝐒\emptyset\in{\bf RES}.

  • For any 1{\mathcal{R}}_{1} and 2{\mathcal{R}}_{2}, 2𝐑𝐄𝐒{\mathcal{R}}_{2}\in{\bf RES} if 1𝐑𝐄𝐒{\mathcal{R}}_{1}\in{\bf RES} and 21{\mathcal{R}}_{2}\subseteq{\mathcal{R}}_{1}, where \subseteq is the subset relation on multisets.

We say that {\mathcal{R}} is a valid multiset of resources if 𝐑𝐄𝐒{\mathcal{R}}\in{\bf RES} holds.

In order to formalize threads, we introduce a notion of pools. Conceptually, a pool is just a collection of programs (that is, closed expressions). We use Π\Pi for pools, which are formally defined as finite mappings from thread ids (represented as natural numbers) to (closed) expressions in MTLC0\mbox{MTLC}_{0} such that 0 is always in the domain of such mappings. Given a pool Π\Pi and tiddom(Π)\mbox{\it tid}\in\mbox{\bf dom}(\Pi), we refer to Π(tid)\Pi(\mbox{\it tid}) as a thread in Π\Pi whose id equals tid. In particular, we refer to Π(0)\Pi(0) as the main thread in Π\Pi. The definition of ρ()\rho(\cdot) is extended as follows to compute the multiset of resources in a given pool:

ρ(Π)=tiddom(Π)ρ(Π(tid))\rho(\Pi)=\biguplus_{\mbox{\it tid}\in\mbox{\bf dom}(\Pi)}\rho(\Pi(\mbox{\it tid}))

We are to define a relation on pools in Section 6.2 to simulate multi-threaded program execution.

SIGrc:δ^(ty-res)Γ;rc:δ^SIGc:(T^1,,T^n)T^Γ;Δiei:T^ifor 1in(ty-cst)Γ;Δ1,,Δnc(e1,,en):T^(ty-var-i)(Γ,x:T;)x:T(ty-var-l)(Γ;,x:T^)x:T^ρ(e1)=ρ(e2)Γ;Δ0e0:boolΓ;Δe1:T^Γ;Δe2:T^(ty-if)Γ;Δ0,Δif(e0,e1,e2):T^(ty-unit)Γ;:𝟏Γ;Δ1e1:T1Γ;Δ2e2:T2(ty-tup-i)Γ;Δ1,Δ2e1,e2:T1T2Γ;Δe:T1T2(ty-fst)Γ;Δfst(e):T1Γ;Δe:T1T2(ty-snd)Γ;Δsnd(e):T2Γ;Δ1e1:T^1Γ;Δ2e2:T^2(ty-tup-l)Γ;Δ1,Δ2e1,e2:T^1T^2Γ;Δ1e1:T^1T^2Γ;Δ2,x1:T^1,x2:T^2e2:T^(ty-tup-l-elim)Γ;Δ1,Δ2𝚕𝚎𝚝x1,x2=e1𝚒𝚗e2𝚎𝚗𝚍:T^(Γ;Δ),x:T^1e:T^2(ty-lam-l)Γ;Δ𝚕𝚊𝚖x.e:T^1lT^2Γ;Δ1e1:T^1lT^2Γ;Δ2e2:T^1(ty-app-l)Γ;Δ1,Δ2𝚊𝚙𝚙(e1,e2):T^2(Γ;),x:T^1e:T^2ρ(e)=(ty-lam-i)Γ;𝚕𝚊𝚖x.e:T^1iT^2Γ;Δ1e1:T^1iT^2Γ;Δ2e2:T^1(ty-app-i)Γ;Δ1,Δ2𝚊𝚙𝚙(e1,e2):T^2Γ,x:T;v:T(ty-fix)Γ;𝚏𝚒𝚡x.v:T(;)Π(0):T^(;)Π(tid):𝟏for each 0<tiddom(Π)(ty-pool)Π:T^\begin{array}[]{c}\Gamma;\emptyset\vdash\mbox{\it rc}:\mbox{$\hat{\delta}$}\mbox{\it SIG}\models\mbox{\it rc}:\mbox{$\hat{\delta}$}\\[4.0pt] \Gamma;\Delta_{1},\ldots,\Delta_{n}\vdash c(e_{1},\ldots,e_{n}):\mbox{$\hat{T}$}\lx@proof@logical@and\mbox{\it SIG}\models c:(\mbox{$\hat{T}$}_{1},\ldots,\mbox{$\hat{T}$}_{n})\Rightarrow\mbox{$\hat{T}$}\Gamma;\Delta_{i}\vdash e_{i}:\mbox{$\hat{T}$}_{i}~{}~{}\mbox{for $1\leq i\leq n$}\\[4.0pt] (\Gamma,x:\mbox{$T$};\emptyset)\vdash x:\mbox{$T$}\kern 12.0pt(\Gamma;\emptyset,x:\mbox{$\hat{T}$})\vdash x:\mbox{$\hat{T}$}\\[4.0pt] \Gamma;\Delta_{0},\Delta\vdash\mbox{\tt if}(e_{0},e_{1},e_{2}):\mbox{$\hat{T}$}\lx@proof@logical@and\rho(e_{1})=\rho(e_{2})\Gamma;\Delta_{0}\vdash e_{0}:\mbox{\bf bool}\Gamma;\Delta\vdash e_{1}:\mbox{$\hat{T}$}\Gamma;\Delta\vdash e_{2}:\mbox{$\hat{T}$}\\[4.0pt] \Gamma;\emptyset\vdash\langle\rangle:\mbox{$\mathbf{1}$}\\[4.0pt] \Gamma;\Delta_{1},\Delta_{2}\vdash\langle e_{1},e_{2}\rangle:\mbox{$T$}_{1}*\mbox{$T$}_{2}\lx@proof@logical@and\Gamma;\Delta_{1}\vdash e_{1}:\mbox{$T$}_{1}\Gamma;\Delta_{2}\vdash e_{2}:\mbox{$T$}_{2}\\[4.0pt] \Gamma;\Delta\vdash\mbox{\tt fst}(e):\mbox{$T$}_{1}\Gamma;\Delta\vdash e:\mbox{$T$}_{1}*\mbox{$T$}_{2}\kern 12.0pt\Gamma;\Delta\vdash\mbox{\tt snd}(e):\mbox{$T$}_{2}\Gamma;\Delta\vdash e:\mbox{$T$}_{1}*\mbox{$T$}_{2}\\[4.0pt] \Gamma;\Delta_{1},\Delta_{2}\vdash\langle e_{1},e_{2}\rangle:\mbox{$\hat{T}$}_{1}\otimes\mbox{$\hat{T}$}_{2}\lx@proof@logical@and\Gamma;\Delta_{1}\vdash e_{1}:\mbox{$\hat{T}$}_{1}\Gamma;\Delta_{2}\vdash e_{2}:\mbox{$\hat{T}$}_{2}\\[4.0pt] \Gamma;\Delta_{1},\Delta_{2}\vdash{\tt let}\;\langle x_{1},x_{2}\rangle=e_{1}\;{\tt in}\;e_{2}\;{\tt end}:\mbox{$\hat{T}$}\lx@proof@logical@and\Gamma;\Delta_{1}\vdash e_{1}:\mbox{$\hat{T}$}_{1}\otimes\mbox{$\hat{T}$}_{2}\Gamma;\Delta_{2},x_{1}:\mbox{$\hat{T}$}_{1},x_{2}:\mbox{$\hat{T}$}_{2}\vdash e_{2}:\mbox{$\hat{T}$}\\[4.0pt] \Gamma;\Delta\vdash{\tt lam}\;x.\,e:\mbox{$\hat{T}$}_{1}\rightarrow_{l}\mbox{$\hat{T}$}_{2}(\Gamma;\Delta),x:\mbox{$\hat{T}$}_{1}\vdash e:\mbox{$\hat{T}$}_{2}\\[4.0pt] \Gamma;\Delta_{1},\Delta_{2}\vdash{\tt app}(e_{1},e_{2}):\mbox{$\hat{T}$}_{2}\lx@proof@logical@and\Gamma;\Delta_{1}\vdash e_{1}:\mbox{$\hat{T}$}_{1}\rightarrow_{l}\mbox{$\hat{T}$}_{2}\Gamma;\Delta_{2}\vdash e_{2}:\mbox{$\hat{T}$}_{1}\\[4.0pt] \Gamma;\emptyset\vdash{\tt lam}\;x.\,e:\mbox{$\hat{T}$}_{1}\rightarrow_{i}\mbox{$\hat{T}$}_{2}\lx@proof@logical@and(\Gamma;\emptyset),x:\mbox{$\hat{T}$}_{1}\vdash e:\mbox{$\hat{T}$}_{2}\rho(e)=\emptyset\\[4.0pt] \Gamma;\Delta_{1},\Delta_{2}\vdash{\tt app}(e_{1},e_{2}):\mbox{$\hat{T}$}_{2}\lx@proof@logical@and\Gamma;\Delta_{1}\vdash e_{1}:\mbox{$\hat{T}$}_{1}\rightarrow_{i}\mbox{$\hat{T}$}_{2}\Gamma;\Delta_{2}\vdash e_{2}:\mbox{$\hat{T}$}_{1}\\[4.0pt] \Gamma;\emptyset\vdash{\tt fix}\;x.\,v:\mbox{$T$}\Gamma,x:\mbox{$T$};\emptyset\vdash v:\mbox{$T$}\\[4.0pt] \vdash\Pi:\mbox{$\hat{T}$}\lx@proof@logical@and(\emptyset;\emptyset)\vdash\Pi(0):\mbox{$\hat{T}$}(\emptyset;\emptyset)\vdash\Pi(\mbox{\it tid}):\mbox{$\mathbf{1}$}~{}~{}\mbox{for each $0<\mbox{\it tid}\in\mbox{\bf dom}(\Pi)$}\\[4.0pt] \end{array}
Figure 5: The typing rules for MTLC0\mbox{MTLC}_{0}

6.1 Static Semantics

We use Γ\Gamma for a typing context that assigns (non-linear) types to variables and Δ\Delta for a typing context that assigns (linear) viewtypes to variables. Any typing context can be regarded as a finite mapping as each variable can occur at most once. Given Γ1\Gamma_{1} and Γ2\Gamma_{2} satisfying dom(Γ1)dom(Γ2)=\mbox{\bf dom}(\Gamma_{1})\cap\mbox{\bf dom}(\Gamma_{2})=\emptyset, we write (Γ1,Γ2)(\Gamma_{1},\Gamma_{2}) for the union of Γ1\Gamma_{1} and Γ2\Gamma_{2}. The same notation also applies to linear typing contexts (Δ\Delta). Given Γ\Gamma and Δ\Delta, we can form a combined typing context (Γ;Δ)(\Gamma;\Delta) if dom(Γ)dom(Δ)=\mbox{\bf dom}(\Gamma)\cap\mbox{\bf dom}(\Delta)=\emptyset. Given (Γ;Δ)(\Gamma;\Delta), we may write (Γ;Δ),x:T^(\Gamma;\Delta),x:\mbox{$\hat{T}$} for either (Γ;Δ,x:T^)(\Gamma;\Delta,x:\mbox{$\hat{T}$}) or (Γ,x:T^;Δ)(\Gamma,x:\mbox{$\hat{T}$};\Delta) (if T^\hat{T} is actually a type).

A typing judgment in MTLC0\mbox{MTLC}_{0} is of the form (Γ;Δ)e:T^(\Gamma;\Delta)\vdash e:\mbox{$\hat{T}$}, meaning that ee can be assigned the viewtype T^\hat{T} under (Γ;Δ)(\Gamma;\Delta). The typing rules for MTLC0\mbox{MTLC}_{0} are listed in Figure 5. In the rule (ty-cst), the following judgment requires that the c-type be an instance of the c-type schema assigned to cc in SIG:

SIGc:(T^1,,T^n)T^\mbox{\it SIG}\models c:(\mbox{$\hat{T}$}_{1},\ldots,\mbox{$\hat{T}$}_{n})\Rightarrow\mbox{$\hat{T}$}

By inspecting the typing rules in Figure 5, we can readily see that a closed value cannot contain any resources if the value itself can be assigned a type (rather than a linear type). More formally, we have the following proposition:

Proposition 6.1.

If (;)v:T(\emptyset;\emptyset)\vdash v:\mbox{$T$} is derivable, then ρ(v)=\rho(v)=\emptyset.

This proposition plays a fundamental role in MTLC0\mbox{MTLC}_{0}: The rules in Figure 5 are actually so formulated in order to make the proposition hold.

The following lemma, which is often referred to as Lemma of Canonical Forms, relates the form of a value to its type:

Lemma 6.2.

Assume that (;)v:T^(\emptyset;\emptyset)\vdash v:\mbox{$\hat{T}$} is derivable.

  • If T^=δ\mbox{$\hat{T}$}=\mbox{$\delta$}, then vv is of the form cc(v1,,vn)\mbox{\it cc}(v_{1},\ldots,v_{n}).

  • If T^=δ^\mbox{$\hat{T}$}=\mbox{$\hat{\delta}$}, then vv is of the form rc or cc(v1,,vn)\mbox{\it cc}(v_{1},\ldots,v_{n}).

  • If T^=𝟏\mbox{$\hat{T}$}=\mbox{$\mathbf{1}$}, then vv is \langle\rangle.

  • If T^=T1T2\mbox{$\hat{T}$}=\mbox{$T$}_{1}*\mbox{$T$}_{2} or T^=T^1T^2\mbox{$\hat{T}$}=\mbox{$\hat{T}$}_{1}\otimes\mbox{$\hat{T}$}_{2}, then vv is of the form v1,v2\langle v_{1},v_{2}\rangle.

  • If T^=T^1iT^2\mbox{$\hat{T}$}=\mbox{$\hat{T}$}_{1}\rightarrow_{i}\mbox{$\hat{T}$}_{2} or T^=T^1lT^2\mbox{$\hat{T}$}=\mbox{$\hat{T}$}_{1}\rightarrow_{l}\mbox{$\hat{T}$}_{2}, then vv is of the form 𝚕𝚊𝚖x.e{\tt lam}\;x.\,e.

Proof 6.3.

By an inspection of the rules in Figure 5.

We use θ\theta for substitution on variables xx:

θ::=[]θ[xv]\begin{array}[]{rcl}\theta&::=&[]\mid\theta[x\mapsto v]\\ \end{array}

For each θ\theta, we define the multiset ρ(θ)\rho(\theta) of resources in θ\theta as the union of ρ(θ(x))\rho(\theta(x)) for xdom(θ)x\in\mbox{\bf dom}(\theta). Given an expression ee, we use e[θ]e[\theta] for the result of applying θ\theta to ee. We write (Γ1;Δ1)θ:(Γ2;Δ2)(\Gamma_{1};\Delta_{1})\vdash\theta:(\Gamma_{2};\Delta_{2}) to mean the following:

  • dom(θ)=dom(Γ2)dom(Δ2)\mbox{\bf dom}(\theta)=\mbox{\bf dom}(\Gamma_{2})\cup\mbox{\bf dom}(\Delta_{2}), and

  • (Γ1;)θ(x):Γ2(x)(\Gamma_{1};\emptyset)\vdash\theta(x):\Gamma_{2}(x) is derivable for each xΓ2x\in\Gamma_{2}, and

  • there exists a linear typing context Δ1,x\Delta_{1,x} for each xdom(Δ2)x\in\mbox{\bf dom}(\Delta_{2}) such that (Γ1;Δ1,x)θ(x):Δ2(x)(\Gamma_{1};\Delta_{1,x})\vdash\theta(x):\Delta_{2}(x) is derivable, and

  • Δ1\Delta_{1} is the union of Δ1,x\Delta_{1,x} for xdom(Δ2){x\in\mbox{\bf dom}(\Delta_{2})}.

The following lemma, which is often referred to as Substitution Lemma, is needed to establish the soundness of the type system of MTLC0\mbox{MTLC}_{0}:

Lemma 6.4.

Assume (Γ1;Δ1)θ:(Γ2;Δ2)(\Gamma_{1};\Delta_{1})\vdash\theta:(\Gamma_{2};\Delta_{2}) and (Γ2;Δ2)e:T^(\Gamma_{2};\Delta_{2})\vdash e:\mbox{$\hat{T}$}. Then (Γ1;Δ1)e[θ]:T^(\Gamma_{1};\Delta_{1})\vdash e[\theta]:\mbox{$\hat{T}$} is derivable and ρ(e[θ])=ρ(e)ρ(θ)\rho(e[\theta])=\rho(e)\uplus\rho(\theta).

Proof 6.5.

By induction on the derivation of (Γ2;Δ2)e:T^(\Gamma_{2};\Delta_{2})\vdash e:\mbox{$\hat{T}$}.

6.2 Dynamic Semantics

The evaluation contexts in MTLC0\mbox{MTLC}_{0} are defined below:

eval. ctx.E::=[]c(v,E,e)if(E,e1,e2)E,ev,E𝚕𝚎𝚝x1,x2=E𝚒𝚗e𝚎𝚗𝚍fst(E)snd(E)𝚊𝚙𝚙(E,e)𝚊𝚙𝚙(v,E)\begin{array}[]{l}\mbox{eval.~{}ctx.}E~{}~{}::={}{}\\ {\kern 6.0pt}{[]\mid c(\vec{v},E,\vec{e})\mid\mbox{\tt if}(E,e_{1},e_{2})\mid\langle E,e\rangle\mid\langle v,E\rangle\mid}\\ {\kern 6.0pt}{{\tt let}\;\langle x_{1},x_{2}\rangle=E\;{\tt in}\;e\;{\tt end}\mid\mbox{\tt fst}(E)\mid\mbox{\tt snd}(E)\mid{\tt app}(E,e)\mid{\tt app}(v,E)}\\ \end{array}

Given an evaluation context EE and an expression ee, we use E[e]E[e] for the expression obtained from replacing the only hole [][] in EE with ee.

Definition 6.6.

We define pure redexes and their reducts as follows.

  • if(true,e1,e2)\mbox{\tt if}(\mbox{\it true},e_{1},e_{2}) is a pure redex whose reduct is e1e_{1}.

  • if(false,e1,e2)\mbox{\tt if}(\mbox{\it false},e_{1},e_{2}) is a pure redex whose reduct is e2e_{2}.

  • 𝚕𝚎𝚝x1,x2=v1,v2𝚒𝚗e𝚎𝚗𝚍{\tt let}\;\langle x_{1},x_{2}\rangle=\langle v_{1},v_{2}\rangle\;{\tt in}\;e\;{\tt end} is a pure redex whose reduct is e[x1,x2v1,v2]e[x_{1},x_{2}\mapsto v_{1},v_{2}].

  • fst(v1,v2)\mbox{\tt fst}(\langle v_{1},v_{2}\rangle) is a pure redex whose reduct is v1v_{1}.

  • snd(v1,v2)\mbox{\tt snd}(\langle v_{1},v_{2}\rangle) is a pure redex whose reduct is v2v_{2}.

  • 𝚊𝚙𝚙(𝚕𝚊𝚖x.e,v){\tt app}({\tt lam}\;x.\,e,v) is a pure redex whose reduct is e[xv]e[x\mapsto v].

  • 𝚏𝚒𝚡x.v{\tt fix}\;x.\,v is a pure redex whose reduct is v[x𝚏𝚒𝚡x.v]v[x\mapsto{\tt fix}\;x.\,v].

Evaluating calls to constant functions is of particular importance in MTLC0\mbox{MTLC}_{0}. Assume that cf is a constant function of arity nn. The expression cf(v1,,vn)\mbox{\it cf}(v_{1},\ldots,v_{n}) is an ad-hoc redex if cf is defined at v1,,vnv_{1},\ldots,v_{n}, and any value of cf(v1,,vn)\mbox{\it cf}(v_{1},\ldots,v_{n}) is a reduct of cf(v1,,vn)\mbox{\it cf}(v_{1},\ldots,v_{n}). For instance, 1+11+1 is an ad hoc redex and 22 is its sole reduct. In contrast, 1+true1+\mbox{\it true} is not a redex as it is undefined. We can even have non-deterministic constant functions. For instance, we may assume that the ad-hoc redex randbit()\mbox{\it randbit}() can evaluate to both 0 and 1.

Let ee be a well-typed expression of the form cf(v1,,vn)\mbox{\it cf}(v_{1},\ldots,v_{n}) and ρ(e)\rho(e)\subseteq{\mathcal{R}} holds for some valid {\mathcal{R}} (that is, 𝐑𝐄𝐒{\mathcal{R}}\in{\bf RES}). We always assume that there exists a reduct vv in MTLC0\mbox{MTLC}_{0} for cf(v1,,vn)\mbox{\it cf}(v_{1},\ldots,v_{n}) such that (\ρ(e))ρ(v)𝐑𝐄𝐒({\mathcal{R}}\backslash\rho(e))\uplus\rho(v)\in{\bf RES}. By doing so, we are able to give a presentation with much less clutter.

Definition 6.7.

Given expressions e1e_{1} and e2e_{2}, we write e1e2e_{1}\rightarrow e_{2} if e1=E[e]e_{1}=E[e] and e2=E[e]e_{2}=E[e^{\prime}] for some E,eE,e and ee^{\prime} such that ee is a redex, ee^{\prime} is a reduct of ee, and we may say that e1e_{1} evaluates or reduces to e2e_{2} purely if ee is a pure redex.

Note that resources may be generated as well as consumed when ad-hoc reductions occur. This is an essential issue in any linear type system designed to support practical programming.

Definition 6.8.

Given two pools Π1\Pi_{1} and Π2\Pi_{2}, the relation Π1Π2\Pi_{1}\rightarrow\Pi_{2} is defined according to the following rules:

e1e2(PR0)Π[tide1]Π[tide2]Π(tid0)=E[thread_create(𝚕𝚊𝚖x.e)](PR1)ΠΠ[tid0:=E[]][tid𝚊𝚙𝚙(𝚕𝚊𝚖x.e,)]tid>0(PR2)Π[tid]Π\begin{array}[]{c}\Pi[\mbox{\it tid}\mapsto e_{1}]\rightarrow\Pi[\mbox{\it tid}\mapsto e_{2}]e_{1}\rightarrow e_{2}\\[6.0pt] \Pi\rightarrow\Pi[\mbox{\it tid}_{0}:=E[\langle\rangle]][\mbox{\it tid}\mapsto{\tt app}({\tt lam}\;x.\,e,\langle\rangle)]\Pi(\mbox{\it tid}_{0})=E[\mbox{\it thread\_create}({\tt lam}\;x.\,e)]\\[6.0pt] \Pi[\mbox{\it tid}\mapsto\langle\rangle]\rightarrow\Pi\mbox{\it tid}>0\\[2.0pt] \end{array}

If a pool Π1\Pi_{1} evaluates to another pool Π2\Pi_{2} by the rule (PR0), then one thread in Π1\Pi_{1} evaluates to its counterpart in Π2\Pi_{2} and the rest stay the same; if by the rule (PR1), then a fresh thread is created; if by the rule (PR2), then a thread (that is not the main thread) is terminated.

From this point on, we always (implicitly) assume that ρ(Π)𝐑𝐄𝐒\rho(\Pi)\in{\bf RES} holds whenever Π\Pi is well-typed. The soundness of the type system of MTLC0\mbox{MTLC}_{0} rests upon the following two theorems:

Theorem 6.9.

(Subject Reduction on Pools) Assume that Π1:T^\vdash\Pi_{1}:\mbox{$\hat{T}$} is derivable and Π1Π2\Pi_{1}\rightarrow\Pi_{2} holds for some Π2\Pi_{2} satisfying ρ(Π2)𝐑𝐄𝐒\rho(\Pi_{2})\in{\bf RES}. Then Π2:T^\vdash\Pi_{2}:\mbox{$\hat{T}$} is also derivable.

Proof 6.10.

By structural induction on the derivation of Π1:T^\vdash\Pi_{1}:\mbox{$\hat{T}$}. Note that Lemma 6.4 is needed.

Theorem 6.11.

(Progress Property on Pools) Assume that Π1:T^\vdash\Pi_{1}:\mbox{$\hat{T}$} is derivable. Then we have the following possibilities:

  • Π1\Pi_{1} is a singleton mapping [0v][0\mapsto v] for some vv, or

  • Π1Π2\Pi_{1}\rightarrow\Pi_{2} holds for some Π2\Pi_{2} satisfying ρ(Π2)𝐑𝐄𝐒\rho(\Pi_{2})\in{\bf RES}.

Proof 6.12.

By structural induction on the derivation of Π1:T^\vdash\Pi_{1}:\mbox{$\hat{T}$}. Note that Lemma 6.2 is needed. Essentially, we can readily prove that Π1(tid)\Pi_{1}(\mbox{\it tid}) for any tiddom(Π1)\mbox{\it tid}\in\mbox{\bf dom}(\Pi_{1}) is either a value or of the form E[e]E[e] for some evaluation context EE and redex ee. If Π1(tid)\Pi_{1}(\mbox{\it tid}) is a value for some tid>0\mbox{\it tid}>0, then this value must be \langle\rangle and the rule (PR2) can be used to reduce Π1\Pi_{1}. If Π1(tid)\Pi_{1}(\mbox{\it tid}) is of the form E[e]E[e] for some redex ee, then the rule (PR0) can be used to reduce Π1\Pi_{1}.

By combining Theorem 6.9 and Theorem 6.11, we can immediately conclude that the evaluation of a well-typed pool either leads to a pool that is a singleton mapping of the form [0v][0\mapsto v] for some value vv, or it goes on forever. In other words, MTLC0\mbox{MTLC}_{0} is type-sound.

7 MTLC1\mbox{MTLC}_{1}: Extending MTLC0\mbox{MTLC}_{0} with multiparty channels

There is no support for communication between threads in MTLC0\mbox{MTLC}_{0}, making MTLC0\mbox{MTLC}_{0} uninteresting as a multi-threaded language. We extend MTLC0\mbox{MTLC}_{0} to MTLC1\mbox{MTLC}_{1} with support for synchronous communication channels in this section. Supporting asynchronous communication channels is certainly possible but would result in a more involved theoretical development. In order to assign types to channels, we introduce session types as follows:

S::=msg(r0,r1)S1rS2\begin{array}[]{rcl}\mbox{$S$}&::=&\mbox{\bf msg}(r_{0},r_{1})\mid\mbox{$S$}_{1}{\otimes}_{r}\mbox{$S$}_{2}\\ \end{array}

where r0r_{0} and r1r_{1} range over distinct roles. For a simplified presentation, we use msg(r0,r1)\mbox{\bf msg}(r_{0},r_{1}) to mean messaging from role r0r_{0} to role r1r_{1} (rather than msg(r0,r1,T^)\mbox{\bf msg}(r_{0},r_{1},\mbox{$\hat{T}$}) for specifying a value of viewtype T^\hat{T} being sent from r0r_{0} to r1r_{1}). As for r{\otimes}_{r}, its meaning is explained in Section 5.4. For brevity, we skip session types of the form S1&rS2\mbox{$S$}_{1}{\&}_{r}\mbox{$S$}_{2}.

Given a role set RR and a session type SS, we can form a base viewtype chan(R,S)\mbox{\bf chan}(R,\mbox{$S$}) for an endpoint and refer to RR as the role set attached to this endpoint. A process holding an endpoint of type chan(R,S)\mbox{\bf chan}(R,\mbox{$S$}) is supposed to implement all of the roles in RR.

The function chan_create for creating a channel of two endpoints is assigned the following c-type schema:

chan_create:(chan(R,S)l𝟏)chan(R¯,S)\begin{array}[]{rcl}\mbox{\tt chan\_create}&:&(\mbox{\bf chan}(R,\mbox{$S$})\rightarrow_{l}\mbox{$\mathbf{1}$})\Rightarrow\mbox{\bf chan}({\overline{R}},\mbox{$S$})\\ \end{array}

In order to construct a channel of 3 or more endpoints, we can make use of chan_3_cut. Assume that each CHi\mbox{CH}^{i} has two endpoints CHRii\mbox{CH}^{i}_{R_{i}} and CHR¯ii\mbox{CH}^{i}_{{\overline{R}}_{i}} for i=1,2i=1,2. If R¯1{\overline{R}}_{1} and R¯2{\overline{R}}_{2} are disjoint, then calling chan_create on 𝚕𝚊𝚖x.chan_3_cut(CHR11,CHR22,x){\tt lam}\;x.\,\mbox{\tt chan\_3\_cut}(\mbox{CH}^{1}_{R_{1}},\mbox{CH}^{2}_{R_{2}},x) returns an endpoint CHR1R23\mbox{CH}^{3}_{R_{1}\cap R_{2}} such that the three endpoints CHR¯11\mbox{CH}^{1}_{{\overline{R}_{1}}}, CHR¯22\mbox{CH}^{2}_{{\overline{R}_{2}}}, and CHR1R23\mbox{CH}^{3}_{R_{1}\cap R_{2}} form a new channel.

Please recall that the function chan_sync for msg is given the following c-type schema:

chan_sync:(chan(R,msg(r0,r1)))𝟏\begin{array}[]{rcl}\mbox{\tt chan\_sync}&:&(\mbox{\bf chan}(R,\mbox{\bf msg}(r_{0},r_{1})))\Rightarrow\mbox{$\mathbf{1}$}\end{array}

Given an endpoint CHR\mbox{CH}_{R}, chan_sync sends a message at CHR\mbox{CH}_{R} if r0Rr_{0}\in R and r1Rr_{1}\not\in R, and it receives a message if r0Rr_{0}\not\in R and r1Rr_{1}\in R, and it does nothing otherwise.

There are no new typing rules in MTLC1\mbox{MTLC}_{1} over MTLC0\mbox{MTLC}_{0}. In any type derivation of Π:T^\Pi:\mbox{$\hat{T}$}, the types assigned to the endpoints of any channel CH are required to match in the sense that there exists SS such that these types are of form chan(R1,S),,chan(Rn,S)\mbox{\bf chan}(R_{1},\mbox{$S$}),\ldots,\mbox{\bf chan}(R_{n},\mbox{$S$}) for R1Rn=¯R_{1}\uplus\ldots\uplus{R}_{n}={\overline{\emptyset}}. Clearly, this can be seen as some kind of coherence requirement. For evaluating pools in MTLC1\mbox{MTLC}_{1}, we have the following additional rules:

Π(tid0)=E[chan_create(𝚕𝚊𝚖x.e)](PR3)ΠΠ[tid0:=E[CHR¯]][tide[CHRx]]R1Rn=¯Π(tid1)=E1[chan_sync(CHR1)]Π(tidn)=En[chan_sync(CHRn)](PR4)ΠΠ[tid1:=E1[]][tidn:=En[]]\begin{array}[]{c}\Pi\rightarrow\Pi[\mbox{\it tid}_{0}:=E[\mbox{CH}_{{\overline{R}}}]][\mbox{\it tid}\mapsto e[\mbox{CH}_{R}\mapsto x]]\Pi(\mbox{\it tid}_{0})=E[\mbox{\tt chan\_create}({\tt lam}\;x.\,e)]\\[4.0pt] \Pi\rightarrow\Pi[\mbox{\it tid}_{1}:=E_{1}[\langle\rangle]]\ldots[\mbox{\it tid}_{n}:=E_{n}[\langle\rangle]]\lx@proof@logical@and R_{1}\uplus\ldots\uplus{R_{n}}={\overline{\emptyset}}\Pi(\mbox{\it tid}_{1})=E_{1}[\mbox{\tt chan\_sync}(\mbox{CH}_{R_{1}})]\cdots\Pi(\mbox{\it tid}_{n})=E_{n}[\mbox{\tt chan\_sync}(\mbox{CH}_{R_{n}})]\\[4.0pt] \end{array}

Due to the symmetry between chan_mdisj_l and chan_mdisj_r, we only consider the former in the following presentation. Another rule for evaluating pools in MTLC1\mbox{MTLC}_{1} is given as follows:

R1Rn=¯Π(tid1)=E1[chan_mconj(CHR1)]Π(tid2)=E2[chan_mdisj_l(CHR2,𝚕𝚊𝚖x.e2)]Π(tidn)=En[chan_mdisj_l(CHRn,𝚕𝚊𝚖x.en)](PR5)ΠΠ1[tid2:=E2[CHR2]][tid2e2[xCHR2′′]][tidn:=En[CHRn]][tidnen[xCHRn′′]]\begin{array}[]{c}\Pi\rightarrow\Pi_{1}[\mbox{\it tid}_{2}:=E_{2}[\mbox{CH}^{\prime}_{R_{2}}]][\mbox{\it tid}^{\prime}_{2}\mapsto e_{2}[x\mapsto\mbox{CH}^{\prime\prime}_{R_{2}}]]\cdots[\mbox{\it tid}_{n}:=E_{n}[\mbox{CH}^{\prime}_{R_{n}}]][\mbox{\it tid}^{\prime}_{n}\mapsto e_{n}[x\mapsto\mbox{CH}^{\prime\prime}_{R_{n}}]]$$\begin{array}[]{c}R_{1}\uplus\ldots\uplus{R_{n}}={\overline{\emptyset}}\kern 10.0pt\Pi(\mbox{\it tid}_{1})=E_{1}[\mbox{\tt chan\_mconj}(\mbox{CH}_{R_{1}})]\\ \Pi(\mbox{\it tid}_{2})=E_{2}[\mbox{\tt chan\_mdisj\_l}(\mbox{CH}_{R_{2}},{\tt lam}\;x.\,e_{2})]~{}\cdots~{}\Pi(\mbox{\it tid}_{n})=E_{n}[\mbox{\tt chan\_mdisj\_l}(\mbox{CH}_{R_{n}},{\tt lam}\;x.\,e_{n})]\\ \end{array}$$\\[2.0pt] \end{array}

where CH\mbox{CH}^{\prime} and CH′′\mbox{CH}^{\prime\prime} are two new channels, and Π1=Π[tid1:=E1[CHR1,CHR1′′]]\Pi_{1}=\Pi[\mbox{\it tid}_{1}:=E_{1}[\langle\mbox{CH}^{\prime}_{R_{1}},\mbox{CH}^{\prime\prime}_{R_{1}}\rangle]], and tid2,,tidn\mbox{\it tid}^{\prime}_{2},\ldots,\mbox{\it tid}^{\prime}_{n} are newly created thread ids.

For brevity, we omit rules for other primitive functions on channels (e.g., chan_2_cut and chan_3_cut), which can be formulated by following (PR5).

Theorem 6.9 (Subject Reduction) can be readily established for MTLC1\mbox{MTLC}_{1}. As for Theorem 6.11, we need some special treatment due to the presence of session-typed primitive functions such as chan_create, chan_mconj, chan_mdisj_l, etc.

A partial (ad hoc) redex in MTLC1\mbox{MTLC}_{1} is an expression of one of the following forms: chan_sync(CHR)\mbox{\tt chan\_sync}(\mbox{CH}_{R}), chan_mconj(CHR)\mbox{\tt chan\_mconj}(\mbox{CH}_{R}), chan_mdisj_l(CHR)\mbox{\tt chan\_mdisj\_l}(\mbox{CH}_{R}). We can immediately prove in MTLC1\mbox{MTLC}_{1} that each well-typed program is either a value or of the form E[e]E[e] for some evaluation context EE and expression ee such that ee is either a redex or a partial redex. We refer to an expression as a blocked one if it is of the form E[e]E[e] for some partial redex ee. A set of partial redexes are said to be matching if

  • it consists of chan_sync(CHR1),,chan_sync(CHRn)\mbox{\tt chan\_sync}(\mbox{CH}_{R_{1}}),\ldots,\mbox{\tt chan\_sync}(\mbox{CH}_{R_{n}}) for R1Rn=¯R_{1}\uplus\ldots\uplus{R}_{n}={\overline{\emptyset}}, or

  • it consists of the following:

    chan_mconj(CHR1),chan_mdisj_l(CHR2,v2),,chan_mdisj_l(CHRn,vn)\mbox{\tt chan\_mconj}(\mbox{CH}_{R_{1}}),\mbox{\tt chan\_mdisj\_l}(\mbox{CH}_{R_{2}},v_{2}),\ldots,\mbox{\tt chan\_mdisj\_l}(\mbox{CH}_{R_{n}},v_{n})

    for R1Rn=¯R_{1}\uplus\ldots\uplus{R}_{n}={\overline{\emptyset}}.

A set of blocked expressions are matching if their partial redexes form a matching set. Clearly, a pool containing a set of matching blocked expressions can evaluate according to the rule (PR4) or (PR5). Therefore, a pool is deadlocked only when there is no subset of matching expressions among the entire set of blocked expressions.

Definition 7.1.

Assume there are kk channels CH1,,CHk\mbox{CH}^{1},\ldots,\mbox{CH}^{k} in a pool Π\Pi such that each channel CHi\mbox{CH}^{i} consists of nin_{i} endpoints for i=1,,ki=1,\ldots,k. Let us use #chan(Π)\mbox{\#chan}(\Pi) for kk and #endpt(Π)\mbox{\#endpt}(\Pi) for Σi=1kni\Sigma_{i=1}^{k}n_{i}. In addition, let us use |Π|+|\Pi|^{+} for the number of threads in Π\Pi holding at least one endpoint. We say that Π\Pi is relaxed if |Π|++#chan(Π)#endpt(Π)+1|\Pi|^{+}+\mbox{\#chan}(\Pi)\geq\mbox{\#endpt}(\Pi)+1 holds.

Lemma 7.2.

If Π\Pi is obtained from evaluating an initial pool containing no channels, then Π\Pi is relaxed.

Proof 7.3.

By a careful inspection on the evaluation rules (PR3), (PR4) and (PR5).

Theorem 7.4.

(Progress Property on Pools) Assume that Π1:T\vdash\Pi_{1}:\mbox{$T$} is derivable. If Π1\Pi_{1} is relaxed, then either Π1\Pi_{1} is a singleton mapping [0v][0\mapsto v] for some vv or Π1Π2\Pi_{1}\rightarrow\Pi_{2} holds for some Π2\Pi_{2}.

Proof 7.5.

Assume there are kk channels CH1,,CHk\mbox{CH}^{1},\ldots,\mbox{CH}^{k} in Π1\Pi_{1} for some k>0k>0 such that each channel CHi\mbox{CH}^{i} consists of nin_{i} endpoints for i=1,,ki=1,\ldots,k. Note that |Π1|++k(Σi=1kni)+1|\Pi_{1}|^{+}+k\geq(\Sigma_{i=1}^{k}n_{i})+1 holds as Π1\Pi_{1} is relaxed. Assume that each thread in Π1\Pi_{1} is a blocked expression. By the pigeonhole principle, there must be nin_{i} blocked expressions involving CHi\mbox{CH}^{i} for some ii. Since Π1\Pi_{1} is well-typed, these nin_{i} blocked expressions form a matching set, allowing Π1\Pi_{1} to evaluate to some Π2\Pi_{2} according to the rule (PR4) or (PR5).

Note that Theorem 7.4 establishes a form of global progress in the sense that multiple threads must coordinate in order to make progress in evaluation.

Assume that we start with a well-typed pool Π\Pi containing no channels. By Lemma 7.2, any pool that is reduced from Π\Pi is relaxed. With subject reduction for MTLC1\mbox{MTLC}_{1} and Theorem 7.4, we can conclude that either Π\Pi evaluates to a singleton mapping [0v][0\mapsto v] for some vv or the evaluation goes on forever.

Please assume for the moment that we would like to add into MTLC1\mbox{MTLC}_{1} a function of the name chan2_create of the following type schema:

((chan(R1,S1),chan(R2,S2))l𝟏)(chan(R¯1,S1),chan(R¯2,S2))\begin{array}[]{c}((\mbox{\bf chan}(R_{1},\mbox{$S$}_{1}),\mbox{\bf chan}(R_{2},\mbox{$S$}_{2}))\rightarrow_{l}\mbox{$\mathbf{1}$})\Rightarrow(\mbox{\bf chan}({\overline{R}_{1}},\mbox{$S$}_{1}),\mbox{\bf chan}({\overline{R}_{2}},\mbox{$S$}_{2}))\\ \end{array}

One may think of chan2_create as a “reasonable” generalization of chan_create that creates in a single call two endpoints instead of one. Unfortunately, adding chan2_create into MTLC1\mbox{MTLC}_{1} can potentially cause a deadlock. For instance, a thread may wait for a message on the first of the two endpoints (CH1,CH2)(\mbox{CH}^{1},\mbox{CH}^{2}) returned from a call to chan2_create while the newly created thread waits for a message on the second argument of the function passed to create it, resulting in a deadlocked situation where neither of the two threads is able to send to the other one. Clearly, a pool cannot be relaxed if it contains two threads and two channels such that each channel consist of 22 endpoints.

8 Implementing Multiparty Channels

We have implemented in ATS [\citenameXi, 2008] the session-typed multiparty channels presented in this paper. As far as typechecking is of the concern, the only considerable complication comes from the need for solving constraints that involve various common set operations (on role sets). We currently export such constraints for them to be solved with an external constraint-solver based on Z3 [\citenamede Moura & Bjørner, 2008].

The first implementation is based on shared memory, which is used to construct ATS programs that compile to C. Another implementation is based on processes in Erlang, which is for use in ATS programs that compile to Erlang (so as to take advantage of the infrastructural support for distributed programming in Erlang). For taking a peek at a running implementation of Example 1 in Section 5.6, please visit the following link:

http://pastebin.com/JmZRukRi

where the code should be accessible to someone familiar with ML-like syntax. To facilitate understanding of this example, we outline as follows some key steps involved in building a 3-party session that makes genuine use of non-singleton role sets.

8.1 A Sketch for Building a 3-Party Session

Building a session often requires explicit coordination between the involved parties during the phase of setting-up. In practice, designing and implementing coordination between 3 or more parties is generally considered a difficult issue. By building a multiparty channel based on 2-party channels, we only need to be concerned with two-party coordination, which is usually much easier to handle.

Given a role set RR and a session type SS, we introduce a type 𝐬𝐞𝐫𝐯𝐢𝐜𝐞(R,S){\bf service}(R,\mbox{$S$}) that can be assigned to a value representing some form of persistent service. With such a service, channels of type chan(R,S)\mbox{\bf chan}(R,\mbox{$S$}) can be created repeatedly. A built-in function service_create is assigned the following type for creating a service:

(chan(R¯,S)i𝟏)𝐬𝐞𝐫𝐯𝐢𝐜𝐞(R,S)(\mbox{\bf chan}({\overline{R}},\mbox{$S$})\rightarrow_{i}\mbox{$\mathbf{1}$})\Rightarrow{\bf service}(R,\mbox{$S$})

In contrast with chan_create for creating a channel, service_create requires that its argument be a non-linear function (so that this function can be called repeatedly). A client may call the following function to obtain a channel to communicate with a server that provides the requested service:

service_request:(𝐬𝐞𝐫𝐯𝐢𝐜𝐞(R,S))chan(R,S)\begin{array}[]{rcl}\mbox{\tt service\_request}&:&({\bf service}(R,\mbox{$S$}))\Rightarrow\mbox{\bf chan}(R,\mbox{$S$})\\ \end{array}

Suppose we want to build a 3-party session involving 3 roles: 0, 1, and 2. We may assume that there are two services of types 𝐬𝐞𝐫𝐯𝐢𝐜𝐞({1,2},S){\bf service}(\{1,2\},\mbox{$S$}) and 𝐬𝐞𝐫𝐯𝐢𝐜𝐞({0,2},S){\bf service}(\{0,2\},\mbox{$S$}) available to a party (planning to implement role 2); this party can call service_request on the two services (which are just two names) to obtain two channels CH0\mbox{CH}^{0} and CH1\mbox{CH}^{1} of types chan({1,2},S)\mbox{\bf chan}(\{1,2\},\mbox{$S$}) and chan({0,2},S)\mbox{\bf chan}(\{0,2\},\mbox{$S$}), respectively; it then calls chan_2_cutres(CH0,CH1)\mbox{\tt chan\_2\_cutres}(\mbox{CH}^{0},\mbox{CH}^{1}) to obtain a channel CH2\mbox{CH}^{2} of type chan({2},S)\mbox{\bf chan}(\{2\},\mbox{$S$}) for communicating with two servers providing the requested services. There are certainly many other ways of building a multiparty channel by passing around 2-party channels.

9 Related Work and Conclusion

Multirole as a logical notion generalizes the notion of duality in logic. One may compare multirole to the notion of linearity in linear logic [\citenameGirard, 1987] as multirole/linearity can often be incorporated into an existing logic to form a multirole/linear version of the logic. In this sense, multirole may be referred to as a logical aspect. For instance, it should not be surprising if modal operators can be generalized to ultrafilters as well even though we have not yet formulated any multirole modal logic.

The admissibility of (binary) cut-rule in classical logic and intuitionistic logic goes back to Gentzen’s seminal work on LK and LJ [\citenameGentzen, 1935]. We hereby generalize cut-rule to 1-cut and 2-cut-with-residual, which in turn yield a cut-rule (mp-cut) involving nn sequents for any n1n\geq 1. The proof we give for the admissibility of 2-cut-with-residual is directly based on one for the admissibility of cut-rule in classical linear logic [\citenameTroelstra, 1992].

Session types were introduced by Honda [\citenameHonda, 1993] and further extended subsequently [\citenameTakeuchi et al., 1994, \citenameHonda et al., 1998]. There have since been extensive theoretical studies on session types in the literature(e.g., [\citenameCastagna et al., 2009, \citenameGay & Vasconcelos, 2010, \citenameToninho et al., 2011, \citenameVasconcelos, 2012, \citenameLindley & Morris, 2015]). Multiparty session types, as a generalization of (dyadic) session types, were introduced by Honda and others [\citenameHonda et al., 2008], together with the notion of global types, local types, projection and coherence.

The session types presented in Section 7 are global. In the future, we plan to introduce projection of global session types into local ones. For instance, the local session type for Contestant1 in Example 3 should be given as follows:

query(0)@(mconj(0, answer(1,0)@score(0,1), nil))

as there is no need for Contestant1(1) to learn the protocol that solely specifies communication between Judge(0) and Contestant2(2). Naturally, a set of local session types are coherent if they can be projected from a global session type with respect to some role sets R1,,RnR_{1},\ldots,R_{n} satisfying R1Rn=¯R_{1}\uplus\ldots\uplus R_{n}={\overline{\emptyset}}.

In [\citenameCarbone et al., 2017], a Curry-Howard correspondence is proposed between a language for programming multiparty sessions and a generalization of CLL, where propositions correspond to the local behavior of a party, proofs to processes, and proof normalization to executing communications. In particular, Multiparty Classical Processes (MCP) is developed that generalizes the duality in CLL to a new notion of n-ary compatibility (referred to as coherence) and the cut rule of CLL to a new rule for composing processes. Compared with MCP, we see that our work on multirole logic presents a fundamentally different approach to generalizing the notion of duality in logic (not just in CLL). For instance, we give an interpretation of ABA\otimes B based on LMRL as interleaving of AA and BB in arbitrary order and ABA\invamp B as behaving like AA and BB concurrently while MCP interprets \otimes and \invamp as input and output, respectively. There is little in common between LMRL and MCP except for both sharing a similar motivation on generalizing duality in logic.

There is also very recent work on encoding multiparty session types based on binary session types [\citenameCaires & Pérez, 2016], which relies on an arbiter process to mediate communications between multiple parties while preserving global sequencing information. We see that this form of mediating (formulated based on automata theory) is closely related to performing a multiparty cut.

Probably MTLC1\mbox{MTLC}_{1} is most closely related to SILL [\citenameToninho et al., 2013], a functional programming language that adopts via a contextual monad a computational interpretation of intuitionistic linear sequent calculus as session-typed processes. The approach we use to establish global progress for MTLC1\mbox{MTLC}_{1} can be seen as an adaptation of one used in SILL for the same purpose. Unlike MTLC1\mbox{MTLC}_{1}, there are only binary channels in SILL and the support of linear types in SILL is not direct and only monadic values (representing open process expressions) can be linear.

Also, MTLC1\mbox{MTLC}_{1} is related to previous work on incorporating session types into a multi-threaded functional language [\citenameVasconcelos et al., 2004], where a type safety theorem is established to ensure that the evaluation of a well-typed program can never lead to a so-called faulty configuration. However, this theorem does not imply global progress as a program that is not of faulty configuration can still deadlock. Also, we point out that MTLC1\mbox{MTLC}_{1} is related to recent work on assigning an operational semantics to a variant of GV [\citenameLindley & Morris, 2015], which takes a similar approach to establishing deadlock-freedom (that is, global progress).

Given MRLJ and LMRL, it seems straightforward to formulate LMRLJ as a multirole version of intuitionistic linear logic. As session types can also be directly based on intuitionistic linear propositions [\citenameCaires & Pfenning, 2010], it is only natural to also study multiparty channels in LMRLJ.

There are a variety of programming issues that need to be addressed in order to facilitate the use of session types in practice. Currently, session types are often represented as datatypes in ATS, and programming with such session types tends to involve writing a very significant amount of boilerplate code (as can be seen in the lengthy implementation of the S0B1B2 example). In the presence of large and complex session types, writing such code can be tedious and error-prone. Naturally, we are interested in developing some meta-programming support for generating such code automatically. Also, we are in the process of designing and implementing session combinators (in a spirit similar to parsing combinators [\citenameHutton, 1992]) that can be conveniently called to assemble subsessions into a coherent whole.

Appendix A Appendix

A.1 Proof of Lemma 4.9

Assume 𝒟1::(Γ1,{[A]R1})\mathcal{D}_{1}::(\Gamma_{1},\{[A]_{R_{1}}\}) and 𝒟2::(Γ2,{[A]R2})\mathcal{D}_{2}::(\Gamma_{2},\{[A]_{R_{2}}\}). We proceed by induction on |A||A| (the size of AA) and ht(𝒟1)+ht(𝒟2)\mbox{\it ht}(\mathcal{D}_{1})+\mbox{\it ht}(\mathcal{D}_{2}), lexicographically ordered. For brevity, we are to focus only on the most interesting case where there is one occurrence of [A]Ri[A]_{R_{i}} in {[A]Ri}\{[A]_{R_{i}}\} that is the major formula of the last rule applied in 𝒟i\mathcal{D}_{i}, where ii ranges over 11 and 22. For this case, we have several subcases covering all the possible forms that AA may take.

A.1.1 Assume that AA is a primitive formula

It is a simple (but very meaningful) routine to verify that the sequent (Γ1,Γ2,[A]R1R2)\vdash(\Gamma_{1},\Gamma_{2},[A]_{R_{1}\cap R_{2}}) follows from an application of the rule (Id).

A.1.2 Assume that AA is pf the form ¬f(B)\lnot_{f}(B)

Then 𝒟k\mathcal{D}_{k} is of the following form for each of the cases k=1k=1 and k=2k=2:

𝒟1k::(Γ1k,[B]f1(Rk))(¬)Γk,[A]Rk\vdash\Gamma_{k},[A]_{R_{k}}\mathcal{D}_{1k}::(\Gamma_{1k},[B]_{{f}^{-{\kern-1.0pt}1}(R_{k})})

By induction hypothesis on 𝒟11\mathcal{D}_{11} and 𝒟12\mathcal{D}_{12}, we obtain a derivation:

𝒟::Γ1,Γ2,[B]f1(R1)f1(R2)\mathcal{D}^{\prime}::\Gamma_{1},\Gamma_{2},[B]_{{f}^{-{\kern-1.0pt}1}(R_{1})\cap{f}^{-{\kern-1.0pt}1}(R_{2})}

Note that the f1(R1R2)=f1(R1)f1(R2){f}^{-{\kern-1.0pt}1}(R_{1}\cap{R}_{2})={f}^{-{\kern-1.0pt}1}(R_{1})\cap{f}^{-{\kern-1.0pt}1}(R_{2}). By applying the rule (¬\lnot) to 𝒟\mathcal{D}^{\prime}, we derive Γ,[A]R1R2\vdash\Gamma,[A]_{R_{1}\cap R_{2}}.

A.1.3 Assume that AA is of the form A1𝒰A2A_{1}\,{{\otimes}_{\mathcal{U}}{A_{2}}}

We have three possibilities: R1𝒰R_{1}\in\mathcal{U} and R2𝒰R_{2}\not\in\mathcal{U}, or R1𝒰R_{1}\not\in\mathcal{U} and R2𝒰R_{2}\in\mathcal{U}, or R1𝒰R_{1}\in\mathcal{U} and R2𝒰R_{2}\in\mathcal{U}.

  • Assume R1𝒰R_{1}\in\mathcal{U} and R2𝒰R_{2}\not\in\mathcal{U}. Then 𝒟1\mathcal{D}_{1} is of the following form:

    𝒟11::(Γ11,[A1]R1)𝒟12::(Γ12,[A2]R1)(-pos)Γ1,[A]R1\vdash\Gamma_{1},[A]_{R_{1}}\mathcal{D}_{11}::(\Gamma_{11},[A_{1}]_{R_{1}})\kern 12.0pt\mathcal{D}_{12}::(\Gamma_{12},[A_{2}]_{R_{1}})

    and 𝒟2\mathcal{D}_{2} is of the following form:

    𝒟21::(Γ2,[A1]R2,[A2]R2)(-neg)Γ2,[A]R2\vdash\Gamma_{2},[A]_{R_{2}}\mathcal{D}_{21}::(\Gamma_{2},[A_{1}]_{R_{2}},[A_{2}]_{R_{2}})

    By the induction hypothesis on 𝒟11\mathcal{D}_{11} and 𝒟21\mathcal{D}_{21}, we have a derivation:

    𝒟11::(Γ11,Γ2,[A1]R1R2,[A2]R2)\mathcal{D}^{\prime}_{11}::(\Gamma_{11},\Gamma_{2},[A_{1}]_{R_{1}\cap R_{2}},[A_{2}]_{R_{2}})

    By the induction hypothesis on 𝒟12\mathcal{D}_{12} and 𝒟11\mathcal{D}^{\prime}_{11}, we have a derivation:

    𝒟12::(Γ,[A1]R1R2,[A2]R1R2)\mathcal{D}^{\prime}_{12}::(\Gamma,[A_{1}]_{R_{1}\cap R_{2}},[A_{2}]_{R_{1}\cap R_{2}})

    By applying the rule ({\otimes}-neg) to 𝒟12\mathcal{D}^{\prime}_{12}, we derive Γ,[A]R1R2\vdash\Gamma,[A]_{R_{1}\cap R_{2}}.

  • Assume R1𝒰R_{1}\not\in\mathcal{U} and R2𝒰R_{2}\in\mathcal{U}. Then this case is analogous to the previous one.

  • Assume R1𝒰R_{1}\in\mathcal{U} and R2𝒰R_{2}\in\mathcal{U}. Then 𝒟k\mathcal{D}_{k} is of the following form for each of the cases k=1k=1 and k=2k=2:

    𝒟k1::(Γk1,[A1]Rk)𝒟k2::(Γk2,[A2]Rk)(-pos)Γk,[A]Rk\vdash\Gamma_{k},[A]_{R_{k}}\mathcal{D}_{k1}::(\Gamma_{k1},[A_{1}]_{R_{k}})\kern 12.0pt\mathcal{D}_{k2}::(\Gamma_{k2},[A_{2}]_{R_{k}})

    By the induction hypothesis on 𝒟11\mathcal{D}_{11} and 𝒟21\mathcal{D}_{21}, we obtain a derivation:

    𝒟1::(Γ11,Γ21,[A1]R1R2)\mathcal{D}^{\prime}_{1}::(\Gamma_{11},\Gamma_{21},[A_{1}]_{R_{1}\cap R_{2}})

    By the induction hypothesis on 𝒟12\mathcal{D}_{12} and 𝒟22\mathcal{D}_{22}, we obtain a derivation:

    𝒟2::(Γ12,Γ22,[A2]R1R2)\mathcal{D}^{\prime}_{2}::(\Gamma_{12},\Gamma_{22},[A_{2}]_{R_{1}\cap R_{2}})

    By applying the rule ({\otimes}-pos) to 𝒟1\mathcal{D}^{\prime}_{1} and 𝒟2\mathcal{D}^{\prime}_{2}, we derive Γ,[A]R1R2\vdash\Gamma,[A]_{R_{1}\cap R_{2}}.

A.1.4 Assume that AA is of the form A1&rA2A_{1}\,{{\&}_{r}{A_{2}}}

We have three possibilities: R1𝒰R_{1}\in\mathcal{U} and R2𝒰R_{2}\not\in\mathcal{U}, or R1𝒰R_{1}\not\in\mathcal{U} and R2𝒰R_{2}\in\mathcal{U}, or R1𝒰R_{1}\in\mathcal{U} and R2𝒰R_{2}\in\mathcal{U}.

  • Assume R1𝒰R_{1}\in\mathcal{U} and R2𝒰R_{2}\not\in\mathcal{U}. Then 𝒟1\mathcal{D}_{1} is of the following form:

    𝒟11::(Γ1,[A1]R1)𝒟12::(Γ1,[A2]R1)(&-pos)Γ1,[A]R1\vdash\Gamma_{1},[A]_{R_{1}}\mathcal{D}_{11}::(\Gamma_{1},[A_{1}]_{R_{1}})\kern 12.0pt\mathcal{D}_{12}::(\Gamma_{1},[A_{2}]_{R_{1}})

    and 𝒟2\mathcal{D}_{2} is of the following form for kk being either 11 or 22:

    𝒟2k::(Γ2,[Ak]R2)Γ2,[A]R2\vdash\Gamma_{2},[A]_{R_{2}}\mathcal{D}_{2k}::(\Gamma_{2},[A_{k}]_{R_{2}})

    where the last applied rule in 𝒟2\mathcal{D}_{2} is (&\&-neg-l) or (&\&-neg-r). By induction hypothesis on 𝒟1k\mathcal{D}_{1k} and 𝒟2k\mathcal{D}_{2k}, we obtain a derivation:

    𝒟k::(Γ1,Γ2,[Ak]R1R2)\mathcal{D}^{\prime}_{k}::(\Gamma_{1},\Gamma_{2},[A_{k}]_{R_{1}\cap R_{2}})

    By applying to 𝒟k\mathcal{D}^{\prime}_{k} either (&\&-neg-l) or (&\&-neg-r), we derive Γ1,Γ2,[A]R1R2\vdash\Gamma_{1},\Gamma_{2},[A]_{R_{1}\cap R_{2}}.

  • Assume R1𝒰R_{1}\not\in\mathcal{U} and R2𝒰R_{2}\in\mathcal{U}. Then this case is analogous to the previous one.

  • Assume R1𝒰R_{1}\in\mathcal{U} and R2𝒰R_{2}\in\mathcal{U}. Then 𝒟k\mathcal{D}_{k} is of the following form for each of the cases k=1k=1 and k=2k=2:

    𝒟k1::(Γk1,[A1]Rk)𝒟k2::(Γk2,[A2]Rk)(&-pos)Γk,[A]Rk\vdash\Gamma_{k},[A]_{R_{k}}\mathcal{D}_{k1}::(\Gamma_{k1},[A_{1}]_{R_{k}})\kern 12.0pt\mathcal{D}_{k2}::(\Gamma_{k2},[A_{2}]_{R_{k}})

    By the induction hypothesis on 𝒟11\mathcal{D}_{11} and 𝒟21\mathcal{D}_{21}, we obtain a derivation:

    𝒟1::(Γ11,Γ21,[A1]R1R2)\mathcal{D}^{\prime}_{1}::(\Gamma_{11},\Gamma_{21},[A_{1}]_{R_{1}\cap R_{2}})

    By the induction hypothesis on 𝒟12\mathcal{D}_{12} and 𝒟22\mathcal{D}_{22}, we obtain a derivation:

    𝒟2::(Γ12,Γ22,[A2]R1R2)\mathcal{D}^{\prime}_{2}::(\Gamma_{12},\Gamma_{22},[A_{2}]_{R_{1}\cap R_{2}})

    By applying the rule (&\&-pos) to 𝒟1\mathcal{D}^{\prime}_{1} and 𝒟2\mathcal{D}^{\prime}_{2}, we derive Γ1,Γ2,[A]R1R2\vdash\Gamma_{1},\Gamma_{2},[A]_{R_{1}\cap R_{2}}.

A.1.5 Assume that AA is of the form !𝒰(B){!}_{\mathcal{U}}({B})

This is the most involved subcase. We have three possibilities: R1𝒰R_{1}\in\mathcal{U} and R2𝒰R_{2}\not\in\mathcal{U}, or R1𝒰R_{1}\not\in\mathcal{U} and R2𝒰R_{2}\in\mathcal{U}, or R1𝒰R_{1}\in\mathcal{U} and R2𝒰R_{2}\in\mathcal{U}.

  • Assume R1𝒰R_{1}\in\mathcal{U} and R2𝒰R_{2}\not\in\mathcal{U}. Then 𝒟1\mathcal{D}_{1} is of the following form:

    𝒟11::?(Γ1),[B]R1(!-pos)?(Γ1),[A]R1\vdash{?}(\Gamma_{1}),[A]_{R_{1}}\mathcal{D}_{11}::{?}(\Gamma_{1}),[B]_{R_{1}}

    There are the following three possibilities for 𝒟2\mathcal{D}_{2}:

    • 𝒟2\mathcal{D}_{2} is of the following form:

      𝒟21::Γ2,{[A]R2}(!-neg-weaken)Γ2,{[A]R2}\vdash\Gamma_{2},\{[A]_{R_{2}}\}\mathcal{D}_{21}::\Gamma_{2},\{[A]_{R_{2}}\}

      We obtain a derivation of (Γ1,Γ2,[A]R1R2)(\Gamma_{1},\Gamma_{2},[A]_{R_{1}\cap R_{2}}) by the induction hypothesis on 𝒟1\mathcal{D}_{1} and 𝒟21\mathcal{D}_{21}.

    • 𝒟2\mathcal{D}_{2} is of the following form:

      𝒟21::Γ2,{[A]R2},[B]R(!-neg-derelict)Γ2,{[A]R2}\vdash\Gamma_{2},\{[A]_{R_{2}}\}\mathcal{D}_{21}::\Gamma_{2},\{[A]_{R_{2}}\},[B]_{R}

      By the induction hypothesis on 𝒟1\mathcal{D}_{1} and 𝒟21\mathcal{D}_{21}, we obtain a derivation:

      𝒟121::(Γ1,Γ2,[A]R1R2,[B]R)\mathcal{D}_{121}::(\Gamma_{1},\Gamma_{2},[A]_{R_{1}\cap R_{2}},[B]_{R})

      By the induction hypothesis on 𝒟11\mathcal{D}_{11} and 𝒟121\mathcal{D}_{121}, we obtain a derivation:

      𝒟121::(Γ1,Γ1,Γ2,[A]R1R2)\mathcal{D}^{\prime}_{121}::(\Gamma_{1},\Gamma_{1},\Gamma_{2},[A]_{R_{1}\cap R_{2}})

      By applying the rule (!{!}-neg-contract) to 𝒟121\mathcal{D}^{\prime}_{121} repeatedly, we derive Γ1,Γ2,[A]R1R2\vdash\Gamma_{1},\Gamma_{2},[A]_{R_{1}\cap R_{2}}.

    • 𝒟2\mathcal{D}_{2} is of the following form:

      𝒟21::Γ2,{[A]R2},[A]R2(!-neg-contract)Γ2,{[A]R2}\vdash\Gamma_{2},\{[A]_{R_{2}}\}\mathcal{D}_{21}::\Gamma_{2},\{[A]_{R_{2}}\},[A]_{R_{2}}

      We obtain a derivation of (Γ1,Γ2,[A]R1R2)(\Gamma_{1},\Gamma_{2},[A]_{R_{1}\cap R_{2}}) by the induction hypothesis on 𝒟1\mathcal{D}_{1} and 𝒟21\mathcal{D}_{21}.

  • Assume R1𝒰R_{1}\not\in\mathcal{U} and R2𝒰R_{2}\in\mathcal{U}. This subcase is completely analogous to the previous one.

  • Assume R1𝒰R_{1}\in\mathcal{U} and R2𝒰R_{2}\in\mathcal{U}. Then 𝒟k\mathcal{D}_{k} is of the following form for each of the cases k=1k=1 and k=2k=2:

    𝒟k1::?(Γk),[B]Rk(!-pos)?(Γk),[A]Rk\vdash{?}(\Gamma_{k}),[A]_{R_{k}}\mathcal{D}_{k1}::{?}(\Gamma_{k}),[B]_{R_{k}}

    We obtain 𝒟12::(?(Γ1),?(Γ2),[B]R1R2)\mathcal{D}^{\prime}_{12}::({?}(\Gamma_{1}),{?}(\Gamma_{2}),[B]_{R_{1}\cap R_{2}}) by the induction hypothesis on 𝒟11\mathcal{D}_{11} and 𝒟21\mathcal{D}_{21}. We then obtain a derivation of (?(Γ1),?(Γ2),[A]R1R2)({?}(\Gamma_{1}),{?}(\Gamma_{2}),[A]_{R_{1}\cap R_{2}}) by applying the rule (!{!}-pos) to 𝒟12\mathcal{D}^{\prime}_{12}.

A.1.6 Assume that AA is of the form 𝒰(λx.B)\forall_{\mathcal{U}}(\lambda x.B)

We have three possibilities: R1𝒰R_{1}\in\mathcal{U} and R2𝒰R_{2}\not\in\mathcal{U}, or R1𝒰R_{1}\not\in\mathcal{U} and R2𝒰R_{2}\in\mathcal{U}, or R1𝒰R_{1}\in\mathcal{U} and R2𝒰R_{2}\in\mathcal{U}.

  • Assume R1𝒰R_{1}\in\mathcal{U} and R2𝒰R_{2}\not\in\mathcal{U}. Then 𝒟1\mathcal{D}_{1} is of the following form:

    𝒟11::(Γ1,[B]R1)(-pos)Γ,[A]R1\vdash\Gamma,[A]_{R_{1}}\mathcal{D}_{11}::(\Gamma_{1},[B]_{R_{1}})

    where xx does not have any free occurrences in Γ1\Gamma_{1}, and 𝒟2\mathcal{D}_{2} is of the following form:

    𝒟21::(Γ2,[B[x/t]]R2)(-neg)Γ,[A]R2\vdash\Gamma,[A]_{R_{2}}\mathcal{D}_{21}::(\Gamma_{2},[B[x/t]]_{R_{2}})

    Let 𝒟11\mathcal{D}^{\prime}_{11} be 𝒟11[x/t]\mathcal{D}_{11}[x/t], which is a derivation of (Γ1,[B[x/t]]R1)(\Gamma_{1},[B[x/t]]_{R_{1}}) obtained from substituting tt for every free occurrence of xx in 𝒟11\mathcal{D}_{11}. Clearly, 𝒟11\mathcal{D}^{\prime}_{11} is of the same height as 𝒟11\mathcal{D}_{11}. By the induction hypothesis on 𝒟11\mathcal{D}^{\prime}_{11} and 𝒟21\mathcal{D}_{21}, we have a derivation:

    𝒟121::(Γ1,Γ2,[B[x/t]]R1R2)\mathcal{D}_{121}::(\Gamma_{1},\Gamma_{2},[B[x/t]]_{R_{1}\cap R_{2}})

    By applying the rule (\forall-neg) to 𝒟121\mathcal{D}_{121}, we have a derivation of (Γ1,Γ2,[A]R1R2)(\Gamma_{1},\Gamma_{2},[A]_{R_{1}\cap R_{2}}).

  • Assume R1𝒰R_{1}\not\in\mathcal{U} and R2𝒰R_{2}\in\mathcal{U}. Then this case is analogous to the previous one.

  • Assume R1𝒰R_{1}\in\mathcal{U} and R2𝒰R_{2}\in\mathcal{U}. Then 𝒟k\mathcal{D}_{k} is of the following form for each of the cases k=1k=1 and k=2k=2:

    𝒟k1::(Γk,[A]Rk,[B]Rk)(-pos)Γk,[A]Rk\vdash\Gamma_{k},[A]_{R_{k}}\mathcal{D}_{k1}::(\Gamma_{k},[A]_{R_{k}},[B]_{R_{k}})

    where xx does not have free occurrences in Γk\Gamma_{k}. By the induction hypothesis on 𝒟11\mathcal{D}_{11} and 𝒟21\mathcal{D}_{21}, we have a derivation:

    𝒟12::(Γ1,Γ2,[B]R1R2)\mathcal{D}^{\prime}_{12}::(\Gamma_{1},\Gamma_{2},[B]_{R_{1}\cap R_{2}})

    By applying the rule (\forall-pos) to 𝒟12\mathcal{D}^{\prime}_{12}, we obtain a derivation of (Γ1,Γ2,[A]R1R2)(\Gamma_{1},\Gamma_{2},[A]_{R_{1}\cap R_{2}}).

All of the cases are covered where the cut-formula is the major formula of both 𝒟1\mathcal{D}_{1} and 𝒟2\mathcal{D}_{2}. For brevity, we omit the cases where the cut-formula is not the major formula of either 𝒟1\mathcal{D}_{1} or 𝒟2\mathcal{D}_{2}, which can be trivially handled [\citenameTroelstra, 1992].

References

  • [\citenameAbramsky, 1994] Abramsky, Samson. (1994). Proofs as processes. Theor. comput. sci., 135(1), 5–9.
  • [\citenameBellin & Scott, 1994] Bellin, Gianluigi, & Scott, Philip J. (1994). On the pi-calculus and linear logic. Theor. comput. sci., 135(1), 11–65.
  • [\citenameCaires & Pérez, 2016] Caires, Luís, & Pérez, Jorge A. (2016). Multiparty session types within a canonical binary theory, and beyond. Pages 74–95 of: Formal Techniques for Distributed Objects, Components, and Systems - 36th IFIP WG 6.1 International Conference, FORTE 2016, Held as Part of the 11th International Federated Conference on Distributed Computing Techniques, DisCoTec 2016, Heraklion, Crete, Greece, June 6-9, 2016, Proceedings.
  • [\citenameCaires & Pfenning, 2010] Caires, Luís, & Pfenning, Frank. (2010). Session types as intuitionistic linear propositions. Pages 222–236 of: CONCUR 2010 - Concurrency Theory, 21th International Conference, CONCUR 2010, Paris, France, August 31-September 3, 2010. Proceedings.
  • [\citenameCarbone et al., 2017] Carbone, Marco, Montesi, Fabrizio, Schürmann, Carsten, & Yoshida, Nobuko. (2017). Multiparty session types as coherence proofs. Acta inf.
  • [\citenameCastagna et al., 2009] Castagna, Giuseppe, Dezani-Ciancaglini, Mariangiola, Giachino, Elena, & Padovani, Luca. (2009). Foundations of session types. Pages 219–230 of: Proceedings of the 11th International ACM SIGPLAN Conference on Principles and Practice of Declarative Programming, September 7-9, 2009, Coimbra, Portugal.
  • [\citenamede Moura & Bjørner, 2008] de Moura, Leonardo Mendonça, & Bjørner, Nikolaj. (2008). Z3: an efficient SMT solver. Pages 337–340 of: Tools and Algorithms for the Construction and Analysis of Systems, 14th International Conference, TACAS 2008, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2008, Budapest, Hungary, March 29-April 6, 2008. Proceedings.
  • [\citenameGay & Vasconcelos, 2010] Gay, Simon J., & Vasconcelos, Vasco Thudichum. (2010). Linear type theory for asynchronous session types. J. funct. program., 20(1), 19–50.
  • [\citenameGentzen, 1935] Gentzen, Gerhard. (1935). Untersuchungen über das logische Schlieβ\betaen. Mathematische zeitschrift, 39, 176–210, 405–431.
  • [\citenameGirard, 1987] Girard, Jean-Yves. (1987). Linear logic. Theoretical computer science, 50(1), 1–101.
  • [\citenameHonda, 1993] Honda, Kohei. (1993). Types for dyadic interaction. Pages 509–523 of: CONCUR ’93, 4th International Conference on Concurrency Theory, Hildesheim, Germany, August 23-26, 1993, Proceedings.
  • [\citenameHonda et al., 1998] Honda, Kohei, Vasconcelos, Vasco, & Kubo, Makoto. (1998). Language primitives and type discipline for structured communication-based programming. Pages 122–138 of: Programming Languages and Systems - ESOP’98, 7th European Symposium on Programming, Held as Part of the European Joint Conferences on the Theory and Practice of Software, ETAPS’98, Lisbon, Portugal, March 28 - April 4, 1998, Proceedings.
  • [\citenameHonda et al., 2008] Honda, Kohei, Yoshida, Nobuko, & Carbone, Marco. (2008). Multiparty asynchronous session types. Pages 273–284 of: Proceedings of the 35th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2008, San Francisco, California, USA, January 7-12, 2008.
  • [\citenameHutton, 1992] Hutton, Graham. (1992). Higher-order functions for parsing. J. funct. program., 2(3), 323–343.
  • [\citenameLindley & Morris, 2015] Lindley, Sam, & Morris, J. Garrett. (2015). A semantics for propositions as sessions. Pages 560–584 of: Programming Languages and Systems - 24th European Symposium on Programming, ESOP 2015, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2015, London, UK, April 11-18, 2015. Proceedings.
  • [\citenameTakeuchi et al., 1994] Takeuchi, Kaku, Honda, Kohei, & Kubo, Makoto. (1994). An interaction-based language and its typing system. Pages 398–413 of: PARLE ’94: Parallel Architectures and Languages Europe, 6th International PARLE Conference, Athens, Greece, July 4-8, 1994, Proceedings.
  • [\citenameToninho et al., 2011] Toninho, Bernardo, Caires, Luís, & Pfenning, Frank. (2011). Dependent session types via intuitionistic linear type theory. Pages 161–172 of: Proceedings of the 13th International ACM SIGPLAN Conference on Principles and Practice of Declarative Programming, July 20-22, 2011, Odense, Denmark.
  • [\citenameToninho et al., 2013] Toninho, Bernardo, Caires, Luís, & Pfenning, Frank. (2013). Higher-order processes, functions, and sessions: A monadic integration. Pages 350–369 of: Programming Languages and Systems - 22nd European Symposium on Programming, ESOP 2013, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2013, Rome, Italy, March 16-24, 2013. Proceedings.
  • [\citenameTroelstra, 1992] Troelstra, Anne S. (1992). Lectures on linear logic. CSLI Lecture Notes, vol. 29. Stanford, California: Center for the Study of Language and Information.
  • [\citenameVasconcelos, 2012] Vasconcelos, Vasco T. (2012). Fundamentals of session types. Inf. comput., 217, 52–70.
  • [\citenameVasconcelos et al., 2004] Vasconcelos, Vasco Thudichum, Ravara, António, & Gay, Simon J. (2004). Session types for functional multithreading. Pages 497–511 of: CONCUR 2004 - Concurrency Theory, 15th International Conference, London, UK, August 31 - September 3, 2004, Proceedings.
  • [\citenameWadler, 2012] Wadler, Philip. (2012). Propositions as sessions. Pages 273–286 of: ACM SIGPLAN International Conference on Functional Programming, ICFP’12, Copenhagen, Denmark, September 9-15, 2012.
  • [\citenameXi, 2008] Xi, Hongwei. (2008). The ATS Programming Language System. Available at:  http://www.ats-lang.org/.