A typed parallel λ-calculus for graph-based communication

02/11/2019 ∙ by Federico Aschieri, et al. ∙ 0

We introduce λ_∥ - a simple yet powerful parallel extension of simply typed λ-calculus. λ_∥ is extracted by Curry-Howard correspondence from logics intermediate between classical and intuitionistic logic. Its types are liberal enough to allow arbitrary communication patterns between parallel processes, while guaranteeing that any reduction strategy is terminating. λ_∥ is equipped with an algorithm to extract typing rules from any graph-specified communication topology in such a way that the typed terms can only communicate according to the topology. The expressive power of our language is showcased by examples of parallel programs, ranging from numeric computation to algorithms on graphs.

READ FULL TEXT VIEW PDF
POST COMMENT

Comments

There are no comments yet.

Authors

page 1

page 2

page 3

page 4

This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Introduction

Nowadays powerful computer architectures make parallelism and concurrency feasible, and parallel functional programming is a promising paradigm to exploit them. An effective way for functional processes to communicate is via asynchronous message-passing [1, 12, 19]. Simple examples of interaction between processes, also called communication topologies, are:

Figure 1: Examples of communication topologies

where nodes represent processes, and arcs represent directed communication channels. Other useful forms of communication in process systems include many-to-one and one-to-many; such communications can be implemented for instance in the language Eden [19] using the functions merge and split. In general, different programs, or systems, need different communication topologies. By forbidding communication channels between specified processes, these topologies can also be used to constraint the way processes communicate. Implementing topologies “by hand” is a tedious and sometimes error-prone task. Hence the usefulness of tools like Grace [16] (Graph-based Communication in Eden), which enables programmers to declare and encode network topologies as graphs and provides special constructs to generate the actual process networks: the processes are created and the communication channels are installed.

Functional programming languages are all based on the -calculus, which is deeply connected to logic: every proof in the natural deduction for intuitionistic logic () is isomorphic to a -term and the proved formula can be interpreted as a type. In this paradigm, known as Curry–Howard correspondence [17], evaluation of -terms can be seen as making the proofs more direct (normalization theorem). The main consequence of this correspondence is the possibility of extracting correct-by-construction and terminating programs from logical proofs.

Despite the introduction of various parallel or concurrent -calculi (e.g. [8] [23, 28, 27, 2]), there is no commonly accepted basis for parallel functional computation, no foundation as firm as the -calculus. In general, the unsuccessful attempts to define satisfactory concurrent extensions of the -calculus led Milner [21] to introduce CCS, the forefather of process calculi, the best known of which is the -calculus [22, 26]. Process calculi, nonetheless, are mainly intended for modeling concurrent systems, not for writing functional programs.

In this paper we introduce , a logic-based parallel functional language whose communication schemata can model arbitrary process network topologies. Based on the simply typed -calculus, is obtained by extending the Curry–Howard correspondence to intermediate logics. is equipped with an algorithm to extract typing rules from graph-specified communication topologies in such a way that the typed terms can only communicate according to the topology. We also show that the evaluation of terms always terminates in finitely many steps, regardless of the reduction strategy (strong normalization theorem).

From Logic to Computation: the calculus

Following the ideas of process-oriented programming, an effective way to code a parallel algorithm or a concurrent system into a programming language is to start from a communication topology specified by a directed graph. The next task is to set up the communication structure between the processes involved in the computation. This communication structure, which is enforced in by its typing rules, is defined by using logic. We indeed start by encoding reflexive directed graphs modeling process networks as disjunctive axioms of the form

(1)

such that all are either or a conjunction of some . Intuitively each represents a process in the network specified by the graph, and is the list of processes that are connected to by an outgoing arc, or if there are no such processes. The intuitive reading of is that all conjuncts in , as well as itself, can send messages to . We allow to send a message to itself in case wants to save it for later use, thus simulating a memory mechanism. The addition of these axioms to leads to logics intermediate between classical and intuitionistic logic; examples of such logics include classical logic, cyclic logic [20], Gödel logic, and -valued Gödel logic.

The original Curry-Howard correspondence relates intuitionistic natural deduction proofs and simply typed -terms. Here we establish a correspondence between intermediate logics obtained from by allowing a limited use of the axioms (1) and -terms. The terms typed using the natural deduction rules corresponding to the restricted use of these axioms contain as many parallel processes as the number of premises. For example the decorated version of the rules for the axiom schema , intuitionistically equivalent to the excluded middle law, and are:

with the following restriction:

  1. each one of and is a parallel composition of simply-typed -terms that cannot communicate with each other.

The variable represents a private communication channel that behaves similarly to the -calculus restriction operator  [22, 26]. The typing rules establish how the communication channels connect the terms. For example, encodes the fact that the process can receive a message of type from the process :

where and are contexts. The rule , on the other hand, encodes the fact that can receive a message from , from and from . The behavior of these channels during the actual communications is defined by the reduction rules of the calculus. If we omit reflexive edges, the communication topologies corresponding to the reductions for the above rules are and in Figure 1. In particular, implements the simplest message-passing mechanism, similar to that of the asynchronous -calculus [15], and implements cyclic communication among three processes.

Although the restriction represents a limitation from the logical point of view, it enables us to define very simple and yet expressive reduction rules and to prove the strong normalization of the resulting calculus. Its expressive power is indeed showcased by examples ranging from numeric computation to parallel algorithms on graphs.

Plan of the paper

In Section 2 we briefly recall simply typed -calculus. Section 3 introduces the typing system for the calculus , its terms and the communication structures induced by the typing rules. The basic rules for triggering and resolving the actual communications – the reduction rules of – are presented in Section 4 and used in Section 7 to write programs implementing Scott’s parallel OR, a parallel algorithm for computing , and the parallel version of the Floyd–Warshall algorithm for computing the shortest path between two nodes in a graph. Section 5 describes our method for automatically extracting typing rules from any graph-based communication. Section 6 contains the strong normalization proof, while Section 8 compares to related process calculi and parallel -calculi.

2 Curry–Howard in a nutshell

The calculus is an extension of simply typed -calculus: a fragment of -calculus typed by the function space and Cartesian product types, see e.g. [13]. Table 1 contains the type assignments for -terms. Terms which have been typed by such rules are called simply typed -terms and are denoted here by


 

Table 1: Type assignments for the simply typed -calculus.

We fix basic notation, definitions and terminology that will also apply to . Terms may contain variables of type for every formula . Free and bound variables of a proof term are defined as usual. We assume the standard renaming rules and -equivalences that avoid the capture of variables during reductions.

The typing rules of simply typed -calculus, stripped of -terms, are exactly the inference rules of Gentzen’s natural deduction system for . Actually, if , and all free variables of a term are in , from the logical point of view, represents an intuitionistic natural deduction derivation of from the hypotheses . We will thus write .

This is the so-called Curry–Howard correspondence [17], which reads intuitionistic formulas as types and maps derivations to simply typed -terms. Remarkably, the evaluation of -terms can be seen as a procedure for making derivations more direct, namely, only containing formulas already present in the conclusion or in the premises (subformula property). For example, -reduction corresponds to the following proof transformation:

This reduction and others, introduced in [24], form the logical backbone of the reduction rules for presented in Table 3.

Notation. and associate to the right. By we denote the term and by , for , the term containing the projections that select the th element of the sequence. We define as usual as and as .

3 The Typing System of

The parallel calculus extends the simply typed -calculus with channels for multi-party communication and reduction rules for message exchange.

In order to type parallel terms that interact according to possibly complex communication mechanisms, we build on ideas from [6, 11] and base the Curry–Howard correspondence for on axiomatic extensions of with disjunctive axioms. These axioms can be transformed into rules involving communicating sequents (i.e., hypersequents [6]) and include the class of disjunctive tautologies, interpreted as synchronization schemas in [11]. As shown in Section 5, a subclass of these axioms suffices to encode all communication topologies represented as reflexive directed graphs. An axiom encoding such a graph will, in turn, correspond to a typing rule that allows the terms to communicate only by channels represented in the graph. More precisely, we consider the class of axiom schemata

where are pairwise different propositional variables and are either or conjunctions of distinct propositional variables among . Formally, whenever ; and for any , either or with whenever .

Remark 1

Each disjunct is logically equivalent to . Nevertheless, we keep the second, logically redundant, occurrence of in order to type a memory mechanism for input channels, as we will see in Section 4.

As usual, an instance of an axiom schema is a formula obtained from by uniformly replacing each propositional variable with an actual formula.

Example 1

, , , for , are intuitionistically equivalent to axiom schemas in ; their addition to leads to classical logic, cyclic  [20] (Gödel logic, for ), and -valued Gödel logic, respectively.

arises by extending the Curry–Howard correspondence to the system comprising and the axioms in . The type assignment for terms comprises the rules for the simply typed -calculus in Table 1 and the rules for the parallel operators in Table 2. We denote the variables of simply typed -calculus as and whenever the type is not important simply as By convention, the variables are called intuitionistic variables and stand for terms; they are bound by the operator. On the other hand, the variables are called channels or communication variables and represent private communication channels between parallel processes; they are bound by the operator. The term will be denoted by when is clear from the context or irrelevant. All the free occurrences of in are bound in .

[( contr )] t_1 ∥…∥t_n : A t_1 : A & …& t_n : A

where are simply typed -terms


where is an instance of

 

Table 2: Type assignments for

The rule is useful for representing parallelism without communication, though is logically redundant, since it is an instance of with no channel occurrence.

From a computational perspective the rules produce terms of the shape that put in parallel terms , which are called the processes of ; each term in turn has the shape , where are simply typed -terms and called the threads of . Processes can communicate with each other through the channel , whereas their threads represent parallel independent subprograms than cannot interact with each other. Informally, in order to establish a communication channel connecting two terms and , we require that occurs in , occurs in and is in . On one hand, the argument of a channel application will be interpreted as a message of type that must be transmitted; on the other hand, the channel application will receive batch of messages of type and containing that will replace the whole channel application upon reception. Thus, in general each channel application may send and receive messages. In order to formalize exactly the relation between a process and all the processes such that can send messages to , we need to look at the structure of the axiom schema , because its instances may lose information about its general shape. For this purpose, we introduce the concept of outlink.

Definition 1 (Outlinks)

Let be a term, where

For any and , we say that the term is outlinked to the term if .

The direction of the communication and the direction of are reversed, because the type of the messages, which are arguments of channel occurrences , must be contained in the type of the applications of the receiving channel .

Remark 2

The premises of the rule must be intuitionistically sound proofs; by removing this restriction, the rule is equivalent to an instance of the axiom , which explains the rule’s name.

4 Communications in

In Sec. 3 we showed how to install communication channels connecting processes, we present now the reduction rules of that implement the actual communications. Being higher-order, these communications can transmit as messages arbitrary simply typed -terms, provided their free variables are not bound in the surrounding context. As shown in Sec. 7, this communication mechanism is enough to code interesting parallel programs.

The reduction rules of comprise two groups of rules: those for the simply typed -calculus, called intuitionistic reductions, and those that deal with process communication, called cross reductions. We now discuss the rules and their motivation in detail.

Intuitionistic Reductions. The usual computational rules for the simply typed -calculus represent the operations of applying a function to an argument and extracting a component of a pair [13]. From the logical point of view, they are the standard Prawitz reductions [24] for the natural deduction calculus for .

Cross Reductions. Their goal is to implement communication, namely to transmit programs, in the form of simply typed -terms. Since terms may contain more than one occurrence of a channel application, the first choice to make is which occurrence should contain the next output message. For example, here we have two communicating processes, each one consists of two threads:

where are simply typed -terms not containing . The first process contains three occurrences of the channel . Let us focus on its second thread . The channel application cannot transmit the message , because the channel might be used with a different type in the second process, so type preservation after reduction would fail. Therefore the only possibility here is to choose the second channel application as the one containing the output message, in this case . In general, to make sure that the message does not contain the channel , it is enough to choose as application occurrence that contains the output message the rightmost occurrence of the channel in the whole process. Hence, in any process, the rightmost thread that contains the channel contains the message.

The second choice is which occurrence of a channel application should receive the current message. For example, in the term above, the second process contains three occurrences of . Since a channel can both send and receive, and in particular usually first sends and then receives, we are led to choose again the rightmost occurrence of a channel application as the receiving one. Nonetheless, since the threads of a single process do not communicate with each other, it is best to let all of them receive the message in correspondence of their locally rightmost channel application. Thus in the example, both and will receive messages.

The third choice is what to do with the arguments of a receiving channel. After a few programming examples, like the Floyd–Warshall algorithm of Section 7 (see Remark 4), it is natural to convince oneself that it is better to keep the arguments, a feature that we call memory. In the previous term, if and receive , they will be replaced respectively, with and .

Continuing our example and summing up, we will have the following reduction:

As we can see, the message in correspondence of the rightmost occurrence of in is transmitted by the first process to the rightmost application of in each one of the two threads and of the second process.

The fourth choice to make is which processes should receive messages and which processes should send them. As anticipated in the previous section, we are guided by the typing. Let us consider for instance the term

where and are specific simply typed -terms, and . A cross reduction rule corresponding to this typing rule admits communication in two directions, from left to right and from right to left, because looking at the types, the second process can receive messages from the first and viceversa. The reduction rule for the left to right direction, for instance, is

whereas from right to left is

We can thus see that our reduction rules are naturally non-deterministic. When writing actual code (Section 7), however, we shall fix an intuitive reduction strategy that will choose deterministically at each step which process should receive the next batch of messages. This way programmers can predict the behaviour of their parallel code.

To precisely define communication reductions, we need to introduce two kinds of contexts: one for terms that can communicate, one for terms which are in parallel but cannot communicate.

Definition 2 (Simple Parallel Term)

A simple parallel term is a term , where each , for , is a simply typed -term.

Definition 3

A context is a term with some fixed variable occurring exactly once.

  • A simple context is a context which is a simply typed -term.

  • A simple parallel context is a context which is a simple parallel term.

For any term of the same type of , denotes the term obtained replacing with in , without renaming bound variables.

We can finally explain the general case of the cross reduction. The rule identifies a single process as the receiver and, as consequence, possibly several processes as senders. Once the receiving process is fixed, the senders are determined by the axiom schema that the type of the communication channel occurring in the receiving process instantiates. In particular, in the term

the processes are the senders and the whole process is the receiver; formally, are all the process outlinked (see Definition 1) to . In this latter process, we have highlighted the threads that actually contain the channel : all of them will receive the messages. Consistently with our choices, the displayed occurrences of are rightmost in each and in each The processes containing send them to all the rightmost occurrences of in the processes : hence

provided that for each , its free variables are free in : this condition is needed to avoid that bound variables become free, violating the Subject Reduction. Whenever is a closed term – executable code – the condition is automatically satisfied. As we can see, the reduction retains all of the terms occurring in before the communication.

Remark 3

Unlike in the -calculus [22, 26], in the channel occurrence that sends the message is not consumed. The reason is that the cross reduction rule does adopt the perspective of the receiver rather than that of the senders. A process may wish to send the same message to multiple processes, not only to the current receiver, so it is reasonable to let that possibility open and keep the same output channel application active after the reduction. Therefore, a process will stop sending the same message only when its output channel will be turned into an input channel, that is, when the process will be selected as current receiver. Again, when coding (Section 7), we shall introduce a discipline that will ensure that every process will send its messages to all its potential receivers exactly once.

The fifth, and last, choice to make is what to do with the threads or processes that do not contain any communication channel. The idea is that whenever a term contains no channel occurrence, it has already reached a result, as it does not need to interact with the context further. Hence at the end of the computation we may wish to select out some of the processes that have reached their own results and consider them all together the global result of the computation. Thus we introduce the simplification reduction in Table 3, which also displays all the reduction rules of .

Intuitionistic Reductions

Cross Reductions

Communication

where are all the processes outlinked to the process ; each is a simple context and each is a simple parallel context; the displayed occurrences of are rightmost in each and in each ; finally, the free variables of each are free in .
Simplification

whenever do not contain and .

 

Table 3: Reduction Rules for .

As usual, we adopt the reduction schema: whenever and for any context . With we shall denote the reflexive and transitive closure of the one-step reduction .

We show below that computation steps preserve the type of terms.

Theorem 4.1 (Subject Reduction)

If and , then and all the free variables of appear among those of .

Proof

Since the proof that the intuitionistic reductions preserve the type is completely standard, it is enough to prove the theorem for the cross reductions.

Reductions of the form trivially preserve the type of terms since all processes must have the same type. It is clear, moreover, that no new free variable is created.

Suppose then that we perform a cross reduction step as follows:

As the type of the channel is an instance of the schema where , and since where instantiate respectively, then the term is well defined and its type is the same as that of . Hence the type of the term does not change.

Since the displayed occurrences of are rightmost in each and thus does not occur in , no occurrence of with type different from occurs in the terms . Finally, the free variables of each are free also in , and thus no new free variable is created by the reduction.

The termination of programs is established in Section 6, where we show that every term reduces to a term such that no reduction rule can be applied to it.

5 From Communication Topologies to Programs

We present a method for automatically extracting typing rules from graph-specified communication topologies. Given a directed, reflexive graph whose nodes and edges represent respectively processes and communication channels, we describe how to transform it into an axiom schema corresponding to a typing rule for terms. We will show that this typing rule encodes a process topology which exactly mirrors the graph : two processes may communicate if and only the corresponding graph nodes are connected by an edge and the direction of communication follows the edge. In other words, the edges of the graph correspond to the outlinked relation between processes of Definition 1.

Procedure 1

Given a directed reflexive graph with , the axiom schema encoding is such that for each :

  • , if the -th node in has incoming edges from the non-empty list of pairwise distinct nodes ;

  • , if the -th node in has only one incoming edge.

Before establishing the exact correspondence between directed graphs and communication reductions, we show a simple example.

Example 2

Consider below the axiom corresponding to the graph

4

3

2

1

The corresponding typing rule is the following, where stands for the -th node of the graph

The cross reductions for the terms typed by this rule are

These reductions correspond to the edges of the graph: and can exchange messages in both directions, both and can send messages to , which can only receive messages but cannot transmit, and finally can send messages to but cannot receive any message. Moreover, as discussed in Section 4, the occurrence of in the consequent of each implication provides us with a memorization mechanism for messages, corresponding to the reflexive edges of the graph.

We prove now that the rule extracted from a graph constrains communications to happen as indicated by the edges of the graph.

Proposition 1 (Topology Correspondence)

For any directed reflexive graph and term typed using the rule corresponding to the axiom extracted from by Procedure 1, there is a cross reduction for that transmits a term from to if and only if contains an edge from to .

Proof

Suppose that contains an edge from to . Procedure 1 generates an axiom containing a disjunct of the form and a disjunct of the form . We thus have a reduction of the form :

for and . Such reductions allow the term to be transmitted from the term to the reduced form of the term .

As for the other direction, due to the conditions of cross reductions in Table 3, reductions of the form for a term directly require that the axiom contains a disjunct of the form and one of the form . Procedure 1 produces such disjuncts only if the graph contains nodes and an edge from to .

6 The Strong Normalization Theorem

We prove the strong normalization theorem for : any reduction of every term ends in a finite number of steps into a normal form. This means that the computation of any typed term always terminates independently of the chosen reduction strategy. Instead of struggling directly with the complicated combinatorial properties of process communication, as for the weak normalization in [3, 2], we reduce the strong normalization of to the strong normalization of a non-deterministic reduction relation over simply typed -terms. The idea is to simulate communication by non-determinism, a technique inspired by [5].

Definition 4 (Normal Forms and Strongly Normalizable Terms)

  • A redex is a term such that for some and reduction in Table 3. A term is called a normal form or, simply, normal, if is not a redex.

  • A finite or infinite sequence of terms is said to be a reduction of , if , and for all , . A term of is normalizable if there is a finite reduction of whose last term is normal and is strong normalizable if every reduction of is finite. With we denote the set of the strongly normalizable terms of .

6.1 Non-deterministic Reductions

Strong normalization for parallel -calculi is an intricate problem. Decreasing complexity measures are quite hard to come up with and indeed those introduced in [3, 2] for proving normalization of fragments of fail in case of strong normalization. Given a term , one would like to measure its complexity as a function of the complexities of the terms , for example taking into account the number of channel occurrences and the length of the longest reduction of -redexes in . However, when receives a message its code may drastically change and both those numbers may increase. Moreover, there is a potential circularity to address: channels send messages, so they may generate new -calculus redexes in the receivers; in turn, -calculus redexes may duplicate channel occurrences, generating even more communications and messages.

In order to break this circularity, the idea is to use a radically different complexity measure. The complexity of a process should take into account all the possible messages that may receive. Now, if , then after receiving a message it becomes , where is an arbitrary, from the point of view of , simply typed -term. We thus create a reduction relation over simply typed -terms that simulates the reception “out of the blue” of this kind of messages. Namely, we extend the reduction relation of -calculus with the rule , for every channel and simply typed -term that does not contain channels. In order to simulate the reception of an arbitrary batch of messages, the simply typed -term will be instantiated as in the proof of Theorem 6.3. With this reductions, -terms not containing channels are the usual deterministic ones.

Definition 5 (Deterministic simply typed -terms)

A simply typed -term is called deterministic, if does not contain any channel occurrence.

Definition 6 (The non-deterministic reduction relation )

The reduction relation over simply typed -terms is defined as extension of the relation as follows:

and as usual we close by contexts: whenever and is a simple context. With we shall denote the reflexive and transitive closure of the one-step reduction .

The plan of our proof will be to prove the strong normalization of simply typed -calculus with respect to the reduction (Corollary 2) and then derive the strong normalization of using as the source of the complexity measure (Theorem 6.5). The first result will be proved by the standard Tait–Girard reducibility technique (Definition 7).

In the following, we define to be the set of strongly normalizing simply typed -terms with respect to the non-deterministic reduction . The reduction tree of a strongly normalizable term with respect to

is no more finite, but still well-founded. It is well-known that it is possible to assign to each node of a well-founded tree an ordinal number, in such a way that it decreases passing from a node to any of its children. We will call the

ordinal size of a term the ordinal number assigned to the root of its reduction tree and we denote it by ; thus, if , then . To fix ideas, one may define .

6.2 Reducibility and Properties of Reducible Terms

We define a notion of reducibility for simply typed -terms with respect to the reduction . As usual, we shall prove that every reducible term is strongly normalizable with respect to and afterwards that all simply typed -terms are reducible. The difference with the usual reducibility proof is that we shall first prove that deterministic simply typed -terms are reducible (Theorem 6.1), which makes possible to prove that channels are reducible (Proposition 4) and finally that all terms are reducible (Theorem 6.2). This amounts to prove two times the usual Adequacy Theorem, normally proved just once as final result.

Definition 7 (Reducibility)

Assume is a simply typed -term. We define the relation (“ is reducible of type ”) by induction and by cases according to the form of :

  1. , with atomic, if and only if

  2. if and only if and

  3. if and only if for all , if , then

We prove that the set of reducible terms for a given formula satisfies the usual properties of a Girard reducibility candidate. Following [13], neutral terms are terms that are not “values” and need to be further computed.

Definition 8 (Neutrality)

A simply typed -term is neutral if it is not of the form or .

Definition 9 (Reducibility Candidates)

Extending the approach of [13], we define three properties (CR1)(CR2), (CR3) of reducible terms :

(CR1) If , then .

(CR2) If and , then .

(CR3) If is neutral and for every , implies , then .

We show that every term possesses the reducibility candidate properties. The arguments for (CR1), (CR2), (CR3), are in many cases standard (see [13]).

Proposition 2

Let be a simply typed -term. Then has the properties (CR1), (CR2), (CR3).

Proof

As in [13].

The next task is to prove that all introduction rules of simply typed -calculus define a reducible term from a list of reducible terms for all premises.

Proposition 3

  1. If for every , , then .

  2. If and , then .

Proof

As in [13], using (CR1), (CR2) and (CR3).

6.3 The Mini Adequacy Theorem

We prove that simply typed -terms that do not contain channels are reducible.

Theorem 6.1 (Mini Adequacy Theorem)

Suppose that is a deterministic simply typed -term, with intuitionistic free variables among . For all terms such that

Proof

As the proof of Theorem 6.2 but without case 2., which concerns channels.

Corollary 1 (Mini Strong Normalization of )

Suppose is a deterministic simply typed term. Then and .

Proof

Assume are all the intuitionistic free variables of and thus all its free variables. By (CR3), one has , for . From Theorem 6.1, we derive that . From (CR1), we conclude that .

By the Mini Adequacy Theorem we can prove that channels are reducible.

Proposition 4 (Reducibility of non-Deterministic Channels)

For every non-deterministic channel , .

Proof

Since is neutral, by (CR3) it is enough to show that for all such that , it holds that . Indeed, let us consider any such that ; since must be a deterministic simply typed -term, by Corollary 1 .

6.4 The Adequacy Theorem

We can finally prove that all simply typed -terms are reducible.

Theorem 6.2 (Adequacy Theorem)

Suppose that is any simply typed -term, with intuitionistic free variables among . For all terms such that for

Proof

Notation: for any term and formula , we denote

with . We proceed by induction on the shape of .

  1. If , for some , then . So .

  2. If , for some and channel , then . By Prop. 4, .

  3. If , then and . So , for and by induction hypothesis.

  4. If , then . So, , since we may assume . For every , by induction hypothesis on , . Therefore, by Proposition 3, .

  5. The cases of pairs and projections are straightforward.

Corollary 2 (Strong Normalization of )

Suppose is any simply typed -term. Then .

Proof

. Assume are all the intuitionistic free variables of . By (CR3), one has . From Theorem 6.2, we derive that . From (CR1), we conclude that .

6.5 Strong Normalization of

We are finally in a position to prove the strong normalization of .

Theorem 6.3 (Strong Normalization of )

For any term , .

Proof

Assume and , , . Define , for , as the sequence of the ordinal sizes of with respect to the reduction relation , provided . We proceed by lexicographic induction on the sequence

which we call the complexity of . Let be any term such that : to prove the thesis, it is enough to show that . Let the complexity of . We must consider three cases.

  1. and in turn

    with by contraction of an intuitionistic redex. Then also . Therefore is lexicographically strictly smaller than and we conclude by induction hypothesis that .

  2. and

    where is the sequence of messages transmitted by the cross reduction. Since we have, for each

    we obtain . Therefore is lexicographically strictly smaller than and we conclude by induction hypothesis that .

  3. . As all belong to , we easily obtain .

7 Computing with

We illustrate the expressive power of with examples of programs. We first show that encodes parallel OR and is thus more powerful than simply typed -calculus. The next two examples are -programs encoding the parallel algorithms in [18] for computing approximations of and shortest paths on graphs.

All the terms that we are going to construct will be reduced according to a fixed normalization strategy, which we are going to define now: a recipe for selecting, in any given term, the subterm to which apply one of our reductions. Different normalization strategies for could be defined since by Theorem 6.3 we know that all of them are terminating. We design the normalization strategy that we will adopt according to the following principles, whose goal is to make parallel programming with as efficient and as deterministic as possible. Indeed, as put by R. Harper, whereas concurrency is concerned with nondeterministic composition of programs, parallelism is concerned with asymptotic efficiency of programs with deterministic behavior [14].

(a) Messages should be normalized before being sent. This property is fundamental for efficient parallel computation. Indeed, for instance, a repeatedly forwarded message can be duplicated many times inside a process network, because each process may keep a copy of it; hence if the message is not normal, each process may have to normalize it all over again, wasting resources. This implies in particular that message transmission cannot be triggered according to a call-by-value strategy.

(b) The senders and the receiver of the message should be normalized before the communication. Indeed, the communication behaviour depends on the syntactic shape of a process: it is the rightmost occurrence of the channel in a term to determine what message is sent or received. Hence, a term might send a message while its normal form another one. For example would transmit , while its normal form would transmit . We want to avoid this kind of unpredictable behaviour and make clear what channel is supposed to be the active one, which sends or receives a message.

(c) The reduction strategy should exploit parallelism as much as possible.

Informally, our normalization strategy consists in iterating the basic reduction relation defined below, that takes a term and performs the following operations:

1) We select all the threads of that will send or receive the next message and we let them complete their internal computations. This way, we satisfy (a) and (b). We also exploit parallelism as much as possible, thus (c).

2) We let the selected threads transmit their message.

3) While executing 1) and 2), to avoid inactivity we let the other threads perform some other independent calculations that may be carried out in parallel. This way we satisfy (c).

4) If the previous operations are not possible, we extract the results, if any.

Definition 10 (Reduction Strategy )

Let be a term. We write whenever has been obtained from by applying on of the following:

  1. We select a receiver for the next communication. We normalize, among the threads that contain , those that are rightmost in or in a process outlinked to . If now it is possible, we apply a mini cross reduction

    followed by some intuitionistic reductions.

  2. Provided that by 1. it is impossible to have a reduction where , we apply, if possible, a simplification reduction. We then normalize the remaining simply typed -terms.

We can reduce every -term in normal form just by iterating the reduction relation . Indeed, if any communication is possible, by 1. we can select a suitable receiver and apply a mini cross reduction. If no communication is possible but a simplification is possible, 2. applies and we can simplify the term. Otherwise, we can just normalize the simply typed -terms by 1. or 2.

This normalization strategy leaves some room for non-determinism: it prescribes when a communication reduction should be fired, but does not select a process out of those that can potentially receive messages, thus leaving a number of possible ways of actually performing the communication. To limit this non-determinism, we underline exactly one process and impose that only an underlined process can receive a message. Immediately after the reception of the message, we underline either the next process on the right, if any, or the first one from left otherwise. Another source of non-determinism is due to cross reductions of the form

In this case, we impose that results by selecting from each , with , the leftmost thread not containing .

7.1 Parallel OR

Berry’s sequentiality theorem [7] implies that there is no parallel OR, namely a simply typed -term such that , , for every -term , where are the boolean constants. As a consequence there cannot be a -term such that , , for every -term . A term with the above property can instead be defined in . To implement this term we need to process the two inputs in parallel. If both inputs evaluate to , though, at least one process needs to have all the information in order to output the result . Hence the simple topology

is enough. Procedure 1 extracts from this graph the axiom schema with reduction

We add to the boolean type, and the usual “” construct [13]. We define in