A Distributed Pi-Calculus - Hennessy
A Distributed Pi-Calculus - Hennessy
A DISTRIBUTED pi-calculus
Distributed systems are fast becoming the norm in computer science. Formal
mathematical models and theories of distributed behaviour are needed in order to
understand them. This book proposes a distributed pi-calculus called aDpi, for
describing the behaviour of mobile agents in a distributed world. It is based on an
existing formal language, the pi-calculus, to which it adds a network layer and a
primitive migration construct.
A mathematical theory of the behaviour of these distributed systems is developed,
in which the presence of types plays a major role. It is also shown how, in principle,
this theory can be used to develop verification techniques for guaranteeing the
behaviour of distributed agents.
The text is accessible to computer scientists with a minimal background in
discrete mathematics. It contains an elementary account of the pi-calculus, and
the associated theory of bisimulations. It also develops the type theory required by
aDpi from first principles.
A DISTRIBUTED pi-calculus
Cambridge University Press has no responsibility for the persistence or accuracy of urls
for external or third-party internet websites referred to in this publication, and does not
guarantee that any content on such websites is, or will remain, accurate or appropriate.
To the memory of John and Ray
Contents
Preface ix
Acknowledgements xvii
1 Inductive principles 1
1.1 Induction 1
1.2 Coinduction 4
1.3 Bisimulation equivalence 6
Sources 244
List of figures 248
Notation 250
Bibliography 254
Index 257
Preface
From ATM machines dispensing cash from our bank accounts, to online
shopping websites, interactive systems permeate our everyday life. The underlying
technology to support these systems, both hardware and software, is well advanced.
However design principles and techniques for assuring their correct behaviour are
at a much more primitive stage.
The provision of solid foundations for such activities, mathematical models
of system behaviour and associated reasoning tools, has been a central theme of
theoretical computer science over the last two decades. One approach has been the
design of formal calculi in which the fundamental concepts underlying interactive
systems can be described, and studied. The most obvious analogy is the use of the
λ-calculus as a simple model for the study of sequential computation, or indeed the
study of sequential programming languages. CCS (a Calculus for Communicating
Systems) [28] was perhaps the first calculus proposed for the study of interactive
systems, and was followed by numerous variations. This calculus consists of:
• A simple formal language for describing systems in terms of their structure; how they are
constructed from individual, but interconnected, components.
• A semantic theory that seeks to understand the behaviour of systems described in the
language, in terms of their ability to interact with users.
ix
x Preface
entities, or agents, are highly mobile, and as they roam the underlying network they
forge new communication links with other entities, and perhaps relinquish existing
links.
The pi-calculus [9, 29] is a development from CCS that seeks to address at
least some dynamic aspects of such agents. Specifically it includes the dynamic
generation of communication channels and thus allows the underlying connection
topology to vary as systems evolve. Just as importantly it allows private
communication links to be established and maintained between agents, which adds
considerably to its expressive power. Indeed the pi-calculus very quickly became
the focus of intensive research, both in providing for it a semantic understanding,
and in its promotion as a suitable foundation for a theory of distributed systems;
see [39] for a comprehensive account.
But many concepts fundamental to modern distributed systems, in particular
those based on local area networks, are at most implicit in the pi-calculus. Perhaps
the most obvious is that of domain, to be understood quite generally as a locus for
computational activity. Thus one could view a distributed system as consisting of
a collection of domains, each capable of hosting computational processes, which
in turn can migrate between domains.
The aim of this book is to develop an extension of the pi-calculus in which
these domains have an explicit representation. Of course when presented with such
a prospect there is a bewildering number of concerns on which we may wish to
focus. For example:
Indeed the list is endless. Here our approach is conservative. We wish to develop
a minimal extension of the pi-calculus in which the concept of domain plays a
meaningful, and non-trivial role. However their presence automatically brings a
change of focus. The set of communication channels that in the pi-calculus
determines the interprocess communication topology now has to be reconciled with
the distribution topology. Following our minimalistic approach we decide on a very
simple distribution topology, namely a set of independent and non-overlapping
domains, and only allow communication to happen within individual domains.
This makes the communication channels of the pi-calculus into local entities, in
the sense that they only have significance relative to a particular domain. Indeed
we will view them as a particularly simple form of local resource, to be used by
Preface xi
migrant agents. Thus we view our extension of the pi-calculus, called aDpi – for
asynchronous Distributed pi-calculus, as a calculus for distributed systems in
which
• dynamically created domains are hosts to resources, which may be used by agents
• agents reside in domains, and may migrate between domains for the purpose of using
locally defined resources.
Types and type inference systems now form an intrinsic part of computer science.
They are traditionally used in programming languages as a form of static analysis
to ensure that no runtime errors occur during program execution. Increasingly
sophisticated type-theoretic concepts have emerged in order to handle modern
programming constructs [36]. However the application of type theory is very
diverse. For example types can be used to
• check the correctness of security protocols [12]
• detect deadlocks and livelocks in concurrent programs [26]
• analyse information flow in security systems [22].
In this book we also demonstrate how type systems can be developed to manage
access control to resources in distributed systems. In aDpi we can view domains
as offering resources, modelled as communication channels, to migrating agents.
Moreover a domain may wish to restrict access to certain resources to selected
agents. More generally we can think of resources having capabilities associated
with them. In our case two natural capabilities spring to mind:
• the ability to update a resource, that is write to a communication channel
• the ability to look up a resource, that is read from a communication channel.
Then domains may wish to distribute selectively to agents such capabilities on its
local resources.
We could develop a version of aDpi in which the principal values manipulated by
agents are these capabilities. But this would be a rather complex language, having
to explicitly track their generation, management, and distribution. Instead we show
that these capabilities can be implicitly managed by using a typed version of aDpi.
Moreover the required types are only a mild generalisation of those used in a type
inference system for ensuring the absence of runtime errors, when aDpi systems
are considered as distributed programs.
The behavioural theory of processes originally developed for CCS [28] based on
bisimulations, has been extended to the pi-calculus, and can be readily extended
to aDpi. Indeed the framework is quite general. The behaviour of processes can
be described, independently of the syntax, in terms of their ability to interact with
other processes, or more generally with their computing environment. The form
xii Preface
these interactions take depend on the nature of the processes, and in general will
depend on the process description language. They can be described mathematically
as relations between processes, with
l
P −→ Q
meaning the process P by interacting with its environment can be transformed into
the process Q. The label l serves to record the kind of interaction involved, and
perhaps some data used in the interaction. For example one can easily imagine the
behaviour of an ATM machine being described in this manner, in terms of its internal
states, and the evolution between these states depending of the different kinds of
interactions with a customer. Such a behavioural description is formalised as a
labelled transition system, or lts, and often refered to as an operational semantics.
The theory of bisimulations enables one to take such abstract behavioural
descriptions of processes and generate a behavioural equivalence between
processes. Intuitively
P≈Q (1)
will mean that no user, or computing environment, will be able to distinguish
between P and Q using the interactions described in their behavioural descriptions.
However the use of types in aDpi has a serious impact on this general behavioural
framework, particularly as these types implicitly represent the limited capabilities
that agents have over resources. In other words these types limit the ways in which
agents can interact with other agents. Consequently whether or not two agents are
deemed equivalent will depend on the current distribution of the capabilities on the
resources in the system.
The third and final aim of this book is to address this issue. We demonstrate
that the general theory of bisimulations can be adapted to take the presence of
types into account. We develop a relativised version of behavioural equivalence in
which judgements such as (1) can never be made in absolute terms, but relative to a
description of current capabilities. Moreover we will show that the proof techniques
associated with standard bisimulations, based on coinduction, can be adapted to this
more general framework, at least in principle.
A secondary aim of the book is didactic. Research into the use of formal calculi
to model distributed or interactive systems, or even understanding the application
of such calculi, requires detailed knowledge of a variety of mathematical concepts.
We hope that the book will provide a good introduction to a range of these concepts,
and equip the reader with sufficient understanding and familiarity to enable them
to pursue independent research in the area. But we do not start from first principles.
We assume the reader is at least familiar with elementary discrete mathematics,
Preface xiii
Structure
As already stated, Chapter 1: Background recalls elementary notions of induction
and coinduction, which will be used extensively in all subsequent chapters.
However the only form of coinduction to be used is that associated with
bisimulations, the theory of which is also reviewed.
The pi-calculus, or at least our version of it – called aPi, for asynchronous
pi-calculus, is explained in Chapter 2: The asynchronous PI-CALCULUS. This
exposition starts from first principles, giving a detailed account of both syntactic and
semantic concerns. We give two semantic accounts. The first, a so-called reduction
semantics, may be viewed as a description, at a suitable level of abstraction, of a
prototypical implementation of the language, explaining how aPi processes can be
executed. The second gives an lts for aPi, explaining how processes can interact,
by communicating along channels, with their peers. As we have already indicated
this automatically gives us a bisimulation equivalence between processes, and
moreover bisimulation theory supplies a very powerful coinductive proof principle
for establishing equivalences.
However perhaps the most important topic in this chapter is a discussion of
appropriate behavioural equivalences for process description languages in general.
On the basis of some simple criteria we give a definition of a behavioural
equivalence between processes, called reduction barbed congruence, =, ∼ which
has the advantage of being applicable, or at least easily adapted to, most process
description languages. We will also argue that it is the most natural semantic
equivalence between processes; it relies essentially only on the process description
language having a reduction semantics, and therefore is widely applicable. The
chapter ends by showing how bisimulation equivalence needs to be adapted so as
to coincide with =,∼ thereby providing a complete coinductive proof principle for
this natural behavioural equivalence.
In Chapter 3: Types in API we turn our attention to types, using a typed version
of our language, typed aPi. By focusing on a straightforward notion of runtime
error for aPi, we first explain the use of type systems, the general structure that the
types need to take and the associated typechecking system. We then elaborate on
xiv Preface
the kind of technical results one needs to establish about such a framework. These
cumulate to the demonstration of:
• Subject reduction: the property of being well-typed is preserved under the reduction
semantics.
• Type safety: well-typed processes do not give rise to runtime errors.
Chapter 1: Background
Chapter 2: API
formal account of the role of types in aDpi. This involves defining a version
of aDpi, called tagged-aDpi, in which capabilities, rather than values, are the
main entities manipulated by agents. This is a rather complicated language as the
capabilities, and their propagation, have to be explicitly managed by the reduction
semantics. However we demonstrate that in reality, there is no need for such a
detailed language; in the presence of the capability-based type system aDpi can
be considered as a more abstract, and therefore more manageable, version of
tagged-aDpi.
In Chapter 6: Behavioural equivalences for ADPI we adapt the parameterised
theory of bisimulation equivalence from Chapter 4 to aDpi. In fact we spare the
reader most of the technical proofs, as they can easily be adapted from those for
aPi. Instead we show, via a number of examples, that at least in theory many of the
standard methodologies associated with bisimulation equivalence can be adapted
to prove equivalences between aDpi systems.
We also revisit the principal topic of Chapter 2. We justify our parameterised
version of bisimulation equivalence by showing that it coincides with a natural
intuitively defined behavioural equivalence, a typed version of reduction barbed
congruence.
xvi Preface
We end with a brief section, entitled Sources, with references to the original
research papers on which our material is based, together with some pointers to
related work.
The book is essentially divided into two parts. After reviewing some required
background material in Chapter 2, the following three chapters aim to give a
coherent and detailed introduction to the pi-calculus. These chapters could form
the basis of a postgraduate course on the pi-calculus. Although they pursue
a particular viewpoint, students completing them should be competent in the
mathematical techniques underlying the theory of the pi-calculus, and therefore
should have no problem absorbing supplementary material, taken for example from
[39], [29], or the research literature.
The second part of the book, Chapter 5 and Chapter 6, give a detailed account
of the language aDpi, and its behavioural theory. This could form the core of a
postgraduate course on process calculi for distributed systems, for students familiar
with the pi-calculus. However once more this would need to be augmented with
additional material from the research literature, to reflect the varied approaches to
the subject.
Alternatively, a less theoretical course could be based upon the first four sections
of Chapter 2, Chapter 3 and the first three sections of Chapter 5. This foregoes most
of the material on behavioural equivalences, concentrating on the basic semantics
of the languages (the reduction semantics), and typing.
Each chapter ends with a set of exercises, which the reader is encouraged to
answer. For the most part these are related directly to the material of the chapter,
perhaps extending it in certain directions, or illustrating certain consequences. By
and large they should present no difficulties, although a few may be non-trivial.
Acknowledgements
Most of the research reported on here was carried out over the years with a
large number of colleagues. The main language of the book, aDpi, was originally
developed in conjunction with James Riely, while the behavioural theory, in
Chapter 4 and Chapter 6, was developed jointly with Julian Rathke. Other
colleagues whose contributions and collaborative efforts I wish to acknowledge
include Alberto Ciaffaglione, Adrian Francalanza, Samuel Hym, Massimo Merro
and Nobuko Yoshida.
The book was largely written while the author held a Royal Society/Leverhulme
Trust Senior Fellowship during the academic year 2005/2006, although some
preliminary material on which it was based was presented at the Bertinoro
International Spring School for Graduate Studies in Computer Science in March
2004.
Finally a number of colleagues read parts of the book in draft form, and made
numerous useful suggestions for improvements. These include Adrian Francalanza,
Samuel Hym, Sergio Maffeis, Julian Rathke, James Riely and Nobuko Yoshida.
xvii
1
Inductive principles
Throughout the book we will make extensive use of both induction and coinduction,
and their associated proof techniques. Here we give a brief review of these concepts,
and an indication of how we intend to use them.
1.1 Induction
Figure 1.1 contains a definition of the (abstract) syntax of a simple language of
machines. Here a ranges over some set of action labels Act, and intuitively a
machine can carry out sequences of these actions, and periodically has a choice of
which actions to perform. Let M be the set of all machines defined in Figure 1.1.
Formally this is an inductive definition of a set, namely the least set S that satisfies
• stop ∈ S
• M ∈ S implies a.M ∈ S for every action label a in Act
• M1 , M2 ∈ S implies M1 + M2 ∈ S.
The fact that M is the least set that satisfies these conditions gives us a proof
technique for defining and proving properties of machines in M; any other set
satisfying the conditions is guaranteed to contain M.
As an example consider the following definition of the size of a machine:
• | stop | = 0
• |a.M | = 1 + |M |
• |M1 + M2 | = |M1 | + |M2 |.
We know by induction that this function is now defined for every machine.
Belabouring the point for emphasis let D be the domain of the size function | |,
the set of elements for which it is defined. The three clauses in the definition of
| | above imply that D satisfies the three defining properties of M. So we can
conclude that M ⊆ D; that is every machine is in the domain of | |. We refer to
1
2 Inductive principles
this form of induction as structural induction, as it uses the structure of the language
of machines.
We can also use induction to define the intended behaviour of machines. These
machines perform sequences of actions, but these sequences can be characterised
indirectly by describing what initial action a machine M can perform, and the
residual of M after the action, the part of M that subsequently remains to be
executed. This is given by defining a ternary relation over M × Act × M, with
a
M −→ N (1.1)
indicating that the machine M can perform an action labelled a, with N as residual.
a
Formally the relation M −→ N is defined inductively, as the least relation that
satisfies the axiom (m-move), and the rules (m-choice.l) and (m-choice.r) in
Figure 1.2. The general form of these rules is
(m-rule)
premise1 , . . . premisen
conclusion
This consists of a number, possibly zero, of premises, and a conclusion, meaning
that if all of the premises can be established then the conclusion is true. When the
set of premises is empty, we have an axiom, which will be written more simply as
(m-axiom)
conclusion
The nature of these rules ensures that there is always a least relation satisfying
them. Informally each rule can be viewed as a property of relations; it is true of R
if, whenever each premise is true of R it follows that the conclusion is also true
of R. Now consider a collection of such rules, C . Suppose Ri , i ∈ I , is a family
of relations, all of which satisfy each rule in C . Then one can check that ∩I Ri also
satisfies them. So the least relation satisfying the rules C can be taken to be the
intersection of all the relations satisfying them. In fact we take this least relation to
be the relation defined by the rules C .
More prosaically one can show this least relation simply consists of all
judgements for which there is a proof using the rules from C . As an example of such
a C take those in Figure 1.2, consisting of one axiom and two rules. We can take
(1.1) above to be the relation defined by C . Thus if we assert (1.1) for a particular
M , N and a, then we have a proof of this fact, using a series of applications of this
axiom and of the two rules. For example we can prove
a
a.(b. stop + a. stop) + b.(a. stop + c.b. stop) −→ (b. stop + a. stop) (1.2)
in two steps. The first is an application of the axiom (m-move) to obtain
a
a.(b. stop + a. stop) −→ (b. stop + a. stop)
Then an application of (m-choice.l) to this gives (1.2).
So if we want to prove a property of any judgement of the form (1.1) above we
can use induction on the length of its proof; that is on the number of applications of
rules or axioms, or more generally on the structure of the proof. We call this form
of induction rule induction.
As an example of its use let us prove the following, rather obvious, fact:
Lemma 1.1 If M −
→a
M then |M | < |M |.
Proof: There is an embarrassing number of inductive definitions involved in this
statement; the set of machines over which M and M range, the inductively defined
a
function | | and the inductively defined relation M −→ N ; for the purposes of
exposition we concentrate on this last.
Since M −→ a
M we have a proof of this fact using the rules in Figure 1.2. We
prove the statement of the lemma using induction on the structure of this proof;
that is we use rule induction.
The proof must have non-zero length, and we examine the last rule used in its
derivation. There are three possibilities.
• The first is when this last rule is (m-move), in which case the length of the proof is one.
Then M and M are of the form a.N and N respectively, for some machine N . Looking up
the definition of the function | | we immediately find that |a.N | = 1 + |N |, and therefore
the required result is true.
• The second possibility is that the rule (m-choice.l) is used. So M has the form M1 + M2
and we know that M1 −→ a
M . Moreover the derivation of this latter judgement is strictly
contained in that of M −→ M . Therefore we may apply the inductive hypothesis to
a
conclude that |M | < |M1 |. Again looking up the definition of the function we see that
|M | = |M1 | + |M2 |, and therefore |M1 | ≤ |M |. The requirement, that |M | < |M |,
therefore again follows.
• The third and final possibility is that (m-choice.r) is the last rule used. This is another
inductive case, and the argument is identical to the second possibility.
4 Inductive principles
Let us end this section by remarking that formally we have defined (1.1) as a
ternary relation over M × Act × M. However we will often view this as a family
a
of relations −→, one for each a in Act.
1.2 Coinduction
Induction is a mathematical argument obtained by virtue of the fact that some
relation R is defined to be the least one satisfying certain properties; any other
relation satisfying these properties contains R. Coinduction, the dual argument,
is obtained by virtue of the fact that a relation R is defined to be the largest
one satisfying certain properties; then any other relation satisfying the defining
properties is contained in R. To see an example let us first set up the general
framework we will use in our behavioural descriptions of languages.
Definition 1.2 (lts) A labelled transition system, or more briefly, an lts, consists of
• a set of configurations or states, S
• a set of action labels, Act
• for each action label a, a binary next state relation Ra ⊆ S × S.
a
We will often use suggestive notation such as P −→ Q to denote the fact that P, Q
The set of states S will often be simply the set of terms of some language and the
relations will define the various ways in which observers or users can interact with
programs or processes written in the language. Figures 1.1 and 1.2 give a typical
example. Taken together they define the following lts:
• The set of states are all terms M that can be defined using the rules in Figure 1.1.
• For each action label a in Act the relation Ra consists of all pairs M , M
for which the
a
judgement M −→ M can be derived using the rules in Figure 1.2.
for every action a in Act. These properties are often written graphically (less
precisely); for example the property (1) of R above can be represented as:
This is often called the strong transfer property for R in the lts in question; in
these diagrams the dotted arrow refers to a relation that is required, as opposed
to the standard arrow that indicates a given relation. Note that property (2)
is equivalent to requiring that the inverse of R, denoted R−1 , also satisfies this
transfer property. In other words R is a bisimulation if it, and its inverse, satisfies
the transfer property. In general there is no requirement for a bisimulation to be
symmetric; but if it happens to be symmetric then checking (2), the transfer property
for its inverse, is vacuous.
We use ∼bis to denote the largest bisimulation, which is referred to as strong
bisimulation equivalence. Note that if Ri is any family of bisimulations, where
i ranges over some index set I , then it is easy to check that ∪I Ri is also a
bisimulation. From this we see that ∼bis exists since we can define it to be the
set theoretic union of all bisimulations.
The fact that ∼bis is the largest relation satisfying the transfer property gives us
a proof technique: any other relation satisfying the transfer property is contained
in ∼bis . So, for example, to prove that P ∼bis Q for some particular pair of states
P, Q, it is sufficient to exhibit any bisimulation containing the pair P, Q
. For
example
a.(b. stop + b. stop) + a.b. stop ∼bis a.b. stop
because the following is a bisimulation:
a.(b. stop + b. stop) + a.b. stop ↔ a.b. stop
b. stop + b. stop ↔ b. stop
b. stop ↔ b. stop
stop ↔ stop
Here we have given a graphical representation of a relation R over machine states
by enumerating all its elements; P ↔ Q signifies that the pair P, Q
is in R.
Demonstrating that R is indeed a bisimulation requires some checking. But an
exhaustive analysis will show that this relation does indeed satisfy the transfer
6 Inductive principles
We know that for some R, P ∼bis R and R ∼bis Q. So there exists a matching
move from R, that is some R −→ a
R such that P ∼bis R . Furthermore this
move from R can be matched by one from Q: there exists some Q −→ a
Q
such that R ∼bis Q . But this is the required matching move, since by
definition P R Q .
• P1 R P2 and P2 =⇒ P2 implies P1 =⇒ P1 for some state P1 such that P1 R P2
s s
for every s in eAct∗ . Diagrammatically we require both R and its inverse to satisfy:
As with strong bisimulations, we know that the largest bisimulation exists and
we denote it by ≈bis . Moreover it comes with its own form of coinduction: for
example to show P ≈bis Q it is sufficient to exhibit a bisimulation containing
8 Inductive principles
the pair P, Q
. For example a.b. stop ≈bis a.τ .b. stop because the following is a
bisimulation:
a.b. stop ↔ a.τ .b. stop
b. stop ↔ τ .b. stop
b. stop ↔ b. stop
stop ↔ stop
We can also use coinduction in more general reasoning about the equivalence ≈bis ;
for example we can mimic the arguments given above for ∼bis to prove that ≈bis
is an equivalence relation.
To prove that a relation has the transfer property, as currently formulated, is quite
onerous; there is a quantification over all sequences s of action labels from eAct∗ .
It turns out that this can be considerably relaxed; it is sufficient to match strings of
length at most one. In fact we can go further and demand only that strong actions,
µ
P1 −→ P1 where µ ranges over Act, be matched; of course this matching may be
done by a weak action, one allowing an arbitrary number of interspersed internal
actions.
Definition 1.6 (simple bisimulations) First some notation. For any µ ∈ Act let
µ̂
P1 =⇒ P1 mean
µ
• P1 =⇒ P1 if µ is an external action label, that is an element of eAct
τ
• P1 −→∗ P1 if µ is the internal action τ .
α
Thus we demand that a strong external action, P1 −→ P1 where α ∈ eAct, be
α
matched by a weak external action P2 =⇒ P2 but allow single internal actions,
1.3 Bisimulation equivalence 9
τ
P1 −→ P1 , to be matched by an action consisting of a series of zero or more internal
τ ∗
actions P2 −→ P2 .
Theorem 1.7 If P1 R P2 , where R is a simple bisimulation, then P1 ≈bis P2 .
Proof: It suffices to show that R is a bisimulation. Suppose P1 =⇒ s
P1 . We find
the matching move by induction on the overall size of the derivation of P1 =⇒s
P1 .
Then there are three possibilities:
• The sequence s is empty , and indeed the entire derivation sequence is empty, that is
P1 =⇒ P1 because P1 is P1 .
In this case the matching move is also the trivial move P2 =⇒ P2 .
α s
• The derivation can be deconstructed into P1 −→ Q1 =⇒ P1 , where α is an external action.
In this case s has the form α.s .
We can use the fact that R is a simple bisimulation to find a corresponding weak action
α s
P2 =⇒ Q2 such that Q1 R Q2 . But now we can apply induction to the move Q1 =⇒ P1 ,
s
to obtain a matching move Q2 =⇒ P2 such that P1 R P2 . These two moves can now be
α.s
combined to give the required matching move P2 =⇒ P2 .
τ
• The derivation can be deconstructed into P1 −→ Q1 =⇒ P1 .
s
τ ∗
Here we again apply the definition of simple bisimulations to obtain a move P2 −→ Q2
s
such that Q1 R Q2 . As in the previous case induction gives a move Q2 =⇒ P2 such that
P1 R P2 , and these two moves can be again combined to give the required matching move
P2 =⇒s
P2 .
It is this form of bisimulation that we use throughout the book, and we will omit
the qualifier simple. For the various languages considered we give an operational
semantics in the form of an lts. Intuitively
• The states will consist of the collection of processes that can be defined using the language;
sometimes these will be more general configurations consisting of processes combined
with interfaces to external users.
• The action labels, which will always include τ , will be the different ways in which we
believe users or observers can interact with processes.
µ
• The next-state relations −→, defined inductively, will represent the manner in which these
interactions can change processes.
Given this framework we immediately obtain a behavioural equivalence ≈bis for the
processes definable in the language. As we have seen this equivalence automatically
comes equipped with powerful coinductive proof techniques. Their properties will
be developed, using the notion of simple bisimulations, rather than the original one
from Definition 1.5.
2
The asynchronous pi-calculus
10
2.1 The language aPi 11
simple values; these in turn consist of identifiers or basic values. See Figure 2.2 for
their syntax. The value V = (v1 , . . . , vk ) is said to have arity k.
• Input from a channel c is represented by the term c?(X ) R, where X is a pattern that may be
used to deconstruct the incoming value. Patterns are constructed by the tupling together
of variables, as described in Figure 2.2; for simplicity we also assume occurrences of
variables in patterns are always unique. The process c?(X ) R may input a value V along
the channel c, deconstruct it using the pattern X and then execute R into which the
components of V have been substituted, which we will denote by R{|V/X |}; see Notation 2.1
below.
• if v1 = v2 then R1 else R2 is a test for the identity of simple values.
• R1 | R2 represents two processes running in parallel; they may exchange values using
input/output on channels.
• (new n) R is a scoping mechanism for names. For example in the process
R1 | (new n) R2
the name n is known to R2 but not to R1 ; of course names are values and so in the course
of a computation n may be made known to R1 as the result of a communication; this will
be referred to as the scope extrusion of the name n.
12 The asynchronous PI-CALCULUS
tuple of values; that is no value is sent and the channel ack is simply used for
synchronisation. However in future, to avoid the proliferation of brackets, we will
render the transmission along these synchronisation channels simply by ack!
.
This also explains the input notation. In ack?() R the syntax() represents the empty
pattern. That is no data is expected on the channel; more correctly this process
should be rendered as ack?(()) R.
This acknowledgement scheme is used in the following revision of the forwarder:
F2 (b, c, ack) ⇐ rec z. b?(x, y) ( c! x, ack
| ack?() (y!
| z))
Here the input channel b receives from a source client a value to be forwarded, bound
to x, and an acknowledgement channel, bound to y. The value is then output to the
destination client on the channel c, together with the name of the acknowledgement
channel ack. At this point the acknowledgement is awaited on ack; when it is
received the original acknowledgement, bound to y, is sent to the source client, and
the forwarder is ready for a new input on channel b.
Now consider the revised system
FF2 ⇐ (new c)(F2 (b, c, ack) | F2 (c, d , ack))
where F2 (c, d , ack) is defined by replacing b, c in F2 (b, c, ack) with c, d
respectively. Here there is more hope of the order of values forwarded from
b to d being preserved. But there is confusion about the use of the channel
ack; it is used to arrange acknowledgements internally, between the two internal
systems F2 (b, c, ack) and F2 (c, d , ack), and externally, between the system and the
destination client. Moreover these two distinct roles can become intertwined.
Instead of the individual components F2 (b, c, ack) and F2 (c, d , ack) relying on
a globally available channel ack, an alternative, defensive, strategy would be for
these forwarders to generate a new acknowledgement channel for each particular
communication, with each acknowledgement channel being used exactly once.
Here is how such a forwarder would look:
F(b, c) ⇐ rec z. b?(x, y) (new ack)(c! x, ack
| ack?() (y!
| z))
A system forwarding values from b to d in order using such forwarders would be
defined by:
FF ⇐ (new c)(F(b, c) | F(c, d ))
where F(c, d ) is obtained in the obvious manner from F(b, c).
At this stage, before we give further examples that rely on the transmission of
newly generated channels, it is best if we first define a formal semantics that will
explain in detail how this mechanism works. Using this formal semantics we can
then investigate the actual behaviour of processes such as FF, and see whether this
14 The asynchronous PI-CALCULUS
Note that every static context contains exactly one occurrence of the marker −.
For any process P we let C[P] denote the process that results from syntactically
replacing the occurrence of − with P in C[−]. Note that this replacement is very
different from the notion of substitution defined in Notation 2.1; here names that
are free in P may become bound when placed in the context C[−]. For example
if C[−] is the context (new b)(− | R) and P is the process a! b
then C[P] is the
process (new b)(a! b
| R); the free name b in P has become bound.
Now we can see that a relation R over processes is contextual if and only if it is
preserved by (static contexts); that is P R Q implies C[P] R C[Q] for every static
context C[−]; see Question 1 at the end of the chapter.
Returning to the discussion on equating certain processes we take ≡, referred
to as structural equivalence, to be the least relation between processes (i.e. closed
terms) that
(i) extends α-equivalence
(ii) is an equivalence relation; that is, is reflexive, symmetric and transitive
(iii) is contextual
(iv) and satisfies the axioms in Figure 2.3.
The condition (i) is only mentioned for emphasis; in reality, since we view terms
as representing equivalence classes, it is redundant. Condition (ii) means that ≡
acts like an identity relation over terms. Condition (iii) just means that the axioms
in Figure 2.3 can be applied anywhere in static contexts. The axiom (s-stop) is a
The only possible reduction from this process is an unwinding of one of these
recursive definitions. It is instructive to see how such a step can be inferred from
the definition of the reduction relation −→. Recall that F1 (b, c) represents the
recursive process rec z. b?(x) (c! x
| z), and therefore an instance of the reduction
rule (r-unwind) gives
For notational convenience let us use B(b, c) to denote the residual of this
judgement, namely b?(x) (c! x
| F1 (b, c)). So in summary one application of
(r-unwind) gives
F1 (b, c) −→ B(b, c)
Let us now see how this reduction can take place as part of the larger system
FF1 . The fact that −→ is contextual means that it satisfies two inference rules,
which essentially say that the rules in Figure 2.4 may be applied anywhere under
occurrences of the static operators | and (new n):
(r-par) (r-new)
P −→ P P −→ P
P | Q −→ P | Q (new n) P −→ (new n) P
Q | P −→ Q | P
So we have the following formal derivation, where the inferences are justified by
the rules used:
1 F1 (b, c) −→ B(b, c) (r-unwind)
2 F1 (b, c) | F1 (c, d ) −→ B(b, c) | F1 (c, d ) (r-par) to 1
3 FF1 −→ (new c)(B(b, c) | F1 (c, d )) (r-new) to 2
In other words one possible computation step from the system FF1 is given by
(r-unwind) to the other recursive process F1 (c, d ), no more reductions are possible;
the system is in a stable state awaiting input on c:
(new c)(B(b, c) | B(c, d ))
However we can place FF1 in a context in which the channels b and d are used:
b! v
| FF1 | d ?(x) print! x
(2.1)
Note that here we are implicitly using the structural equivalence; formally we should
write
(b! v
| FF1 ) | d ?(x) print! x
or b! v
| (FF1 | d ?(x) print! x
)
But these terms are structurally equivalent and because of the rule (r-struct) it
does not actually matter which we use. Consequently when writing down a number
of processes in parallel we omit the bracketing. Let us refer to this initial process,
(2.1) above, as Sys1 .
Here once more the only possible initial moves are these unwindings of the
recursive definitions, which gives
Sys1 −→∗ b! v
| (new c)(B(b, c) | B(c, d )) | d ?(x) print! x
(Sys2 )
and let us refer to this latter process as Sys2 . At this point, to obtain a reduction,
we will need to use the rule (r-struct), using the fact that
b! v
| (new c)(B(b, c) | B(c, d )) ≡ (new c)(b! v
| B(b, c) | B(c, d )) (2.2)
Here the private channel c has been extruded, using the structural rule (s-extr),
to allow the inference of the communication along the channel b. This inference
uses the axiom (r-comm), followed by an application of the rule (r-par) and then
(r-new), to give the reduction
(new c)(b! v
| B(b, c) | B(c, d )) −→ (new c)(c! v
| F1 (b, c) | B(c, d )) (2.3)
Thus an application of (r-struct) to (2.2) and (2.3), followed by (r-par), gives
the reduction
Sys2 −→ (new c)(c! v
| F1 (b, c) | B(c, d )) | d ?(x) print! x
(Sys3 )
At this point, in Sys3 , communication is possible along the channel c, at least
intuitively, but to formally derive it we again need various applications of the rules.
The basic axiom used is
c! v
| B(c, d ) −→ d ! v
| F1 (c, d )
an instance of (r-comm). An application of (r-par), then (r-struct), then
(r-new), then (r-par), gives:
Sys3 −→ FF1 | d ! v
| d ?(x) print! x
(Sys4 )
2.2 Reduction semantics for aPi 21
Such a sequence of individual reductions, each derivable from the defining rules of
the reduction semantics, is called a computation. The initial state of this computation
is Sys1 , and the terminal state is the process FF1 | print! v
. Note that this terminal
state is stable; there is no further reduction that can be made from it.
There are slight variations in the possible computations starting from the initial
state Sys1 , essentially caused by the unwinding of recursive definitions. But it is
possible to prove that
• all are finite; they must end in a stable state, from which no further reductions are
possible
• all these stable states are structurally equivalent to (FF1 | print! v
).
In the next example we see how the reduction semantics correctly handles
dynamically created channels, and their scoping.
Example 2.9 Consider the forwarder from b to c, defined by
F(b, c) ⇐ rec z. b?(x, y) (new ack)(c! x, ack
| ack?(y! | z))
Such forwarders can be combined together as in the previous example but their
use requires that an implicit protocol be followed. Consider the new system Sys
defined by
Sys ⇐ User | FF | Print
The composite forwarder FF, defined in Section 2.1, consists of two forwarders
linked together:
FF ⇐ (new c)(F(b, c) | F(c, d ))
The User sequentially supplies two values to the system,
User ⇐ (new ack1 )(b! v1 , ack1
| ack 1 ? (new ack2 ) b! v2 , ack2
)
22 The asynchronous PI-CALCULUS
and the process Print inputs two values sequentially from channel d and prints the
second one,
Print ⇐ d ?(x1 , x2 ) (x2 ! | d ?(y1 , y2 ) (y2 ! | print! y1
))
In Sys the only possible initial reductions are, once more, the unwindings of the
recursive definitions, giving
Sys −→∗ User | (new c)(B(b, c) | B(c, d )) | Print (Sys1 )
Here we use B(−, −) to denote the result of unwinding the definition of a forwarder;
for example B(b, c) represents b?(x, y) (new ack)(c! x, ack
| ack?(y! | F(b, c))).
At this stage, intuitively, communication is possible along the channel b between
User and FF. However the axiom (r-comm) can only be applied if c and also
ack1 , part of the value being communicated, is first extruded using (s-extr). One
possible rearrangement using the structural rules is given by
Sys1 ≡ (new c, ack1 )(User | (B(b, c) | B(c, d ))) | Print
because c and ack1 do not occur in User. Now the axiom (r-comm) can be applied
to User | B(b, c), and subsequently using (r-par) and (r-new) we obtain
(new c, ack1 )(User | (B(b, c) | B(c, d ))) −→ (new c, ack1 )
(User1 | (B1 (b, c) | B(c, d )))
where User1 and B1 (b, c) represent the obvious processes,
ack1 ? (new ack2 ) b! v2 , ack2
and (new ack)(c! v1 , ack
|ack?(ack1 !|F(b, c)))
respectively. So an application of (r-par) and (r-struct), gives
Sys1 −→ (new c, ack1 )(User1 | B1 (b, c) | B(c, d )) | Print (Sys2 )
Note that a priori, from the syntactic form of Sys2 , it may seem that c is actually
shared between the user and the composite forwarder. However Sys2 is structurally
equivalent to
(new ack1 )(User1 | (new c)(B1 (b, c) | B(c, d ))) | Print
a term that gives a truer picture of the sharing of resources.
In Sys2 an internal communication within the forwarder, of the value v1 along
the channel c, is now possible. This leads to the reduction from Sys2 to
(new c, ack1 )(User1 | (new ack)(ack?(ack1 ! | F(b, c)) | B1 (c, d ))) | Print
(Sys3 )
where B1 (c, d ) represents (new ack2 )(d ! v1 , ack2
| ack 2 ?(ack! | F(c, d ))); for
the sake of clarity, and to comply with Barengregt’s convention, we have used
2.2 Reduction semantics for aPi 23
At this point there are three acknowledgements awaiting reception and no further
communications along b, c or d are possible until at least some are delivered. In fact
progress depends on the acknowledgement ack2 from the printer being delivered
to the second forwarder; this will liberate the acknowledgement ack, which when
delivered will in turn liberate ack1 , on which User1 is waiting. This leads to the
series of reductions
Sys4 −→∗ (new c, ack1 , ack, ack2 )(User2 | F(b, c) | F(c, d ) | Print2 ) (2.4)
where User2 represents
(new ack2 ) b! v2 , ack2
However the current term can be simplified considerably using the derived structural
equation already mentioned:
(new n) P ≡ P if n ∈ fn(P)
The channels ack1 , ack and ack2 do not occur freely in the residual process in (2.4)
and therefore applying this rule we obtain
(new c, ack 1 , ack, ack2 )(User2 | F(b, c) | F(c, d ) | Print2 )
≡ (new c)(User2 | F(b, c) | F(c, d ) | Print2 )
24 The asynchronous PI-CALCULUS
and since c does not appear freely in User2 and Print2 we can apply (s-extr) to
obtain
(new c)(User2 | F(b, c) | F(c, d ) | Print2 ) ≡ User2 | FF | Print2
Thus an application of (r-struct) to (2.4) above gives
Sys4 −→∗ (User2 | FF | Print2 ) (Sys5 )
In Sys5 the user may send the second value, which eventually makes its way
through the system, followed by a series of acknowledgements travelling in the
opposite direction.
We have just seen one possible computation from the system
User | FF | Print
Again there are possible variations, depending on recursive unwindings. But again
it is possible to prove that all must terminate and the resulting stable process must be
structurally equivalent to FF | print! v2
. This shows that the values are forwarded
through the composite forwarder in a sequential manner. This should be contrasted
with the possible computations from
User | FF1 | Print
where FF1 is the simple composite forwarder, which uses no acknowledgements.
This system can indeed evolve to a stable state, similar to the one above,
namely FF1 | print! v2
. But it may also evolve to the very different stable state
FF1 | print! v1
, in which the first value sent is actually printed. These two
possibilities constitute a formal demonstration that the first composite forwarder
does not necessarily forward values in sequence.
In the next example we see a very powerful use of the dynamic creation of
channels. With them we can give a very simple definition of compute servers,
which can service an arbitrary number of independent clients, even clients who are
not known when the servers are originally installed.
Example 2.10 [A Compute Server] A compute server, when given some appropriate
data, performs a specific computation on the data and returns the result. We will
abstract from the details of the actual computation, representing it as an operation
on values. To be specific let us assume an operation isprime that takes an integer
and returns true or false, depending on whether the input is prime. Then the
corresponding compute server is defined by
primeS ⇐ rec z. inp ?(x, y) (z | y! isprime(x)
)
At the service point inp a pair of values is received, the first of which should be
an integer and the second a channel. The integer is tested for primality and the
2.2 Reduction semantics for aPi 25
result is returned on the received channel. The recursive definition ensures that the
service is always available and can handle an arbitrary number of calls. The use of
isprime is meant to signify some auxiliary computation, the details of which are not
of interest. However in a more expressive language the body of the server would
be better written as
inp ?(x, y) (z | let a = isprime(x) in y! a
)
emphasising that the auxiliary computation is performed eagerly by the server.
The interest in sending a reply channel with the data is to ensure that different
calls to the service are not confused. For example if Client1 sends the value 27 and,
more or less at the same time, Client2 sends 29 then we have to ensure that the first
receives the answer false and the second true, and not vice-versa. To make this
clear let us define these clients:
Clienti (v) ⇐ (new r)(inp ! v, r
| r?(x) printi ! x
)
The client generates a new return channel r, sends it together with an integer v,
awaits the result on the reply channel, and prints it. Now consider the system
Sys ⇐ Client1 (27) | Client2 (29) | primeS
Each client can access the service in any order, and their respective interactions with
the service can even overlap. But we are assured that only false will be available
at print1 and only true at print2 . In particular if
Sys −→∗ Q
where Q is a stable process, then it is structurally equivalent to the process
print1 ! false
| print2 ! true
| primeS
We give one more example of the power of communication channels, showing
how they can be used to implement a notion of state or memory.
Example 2.11 [A Memory] A channel may be viewed as a very restricted form of
memory cell, where, unlike a normal memory cell the value it contains disappears
once it is read. However we can use it to mimic a standard memory cell if we ensure
that the current value is reinstated each time it is read. This is the idea behind the
following process, which uses a private resource s in which to store the current
value:
Mem ⇐ (new s)(s! 0
The initial value is set to 0. There are then two methods for accessing the cell:
• To obtain the current value the user must send along the access channel get a return
channel that is bound to the variable y. The current value is read from s and sent to the
user along the return channel. In addition the value is reinstated in the local store s.
• To change the value of the cell a user must send the new value, which will be bound to x,
and an acknowledgement channel, to be bound to y. The current value is read from s and
ignored. The new value is installed and the user is sent an acknowledgement.
Client | Mem
print! 4
| Mem
Indeed up to structural equivalence this is the only stable term to which it can
reduce.
Consider a client that puts in two values, and then retrieves the current state of
the memory:
Client2 | Mem
print! 6
| Mem
In all of the examples seen so far systems have been described in terms of
their components, together with communication channels, between them. However
this connectivity between the system components, such as users and servers, has
been relatively static, although various acknowledgement and reply channels are
2.3 An action semantics for aPi 27
generated dynamically on demand. But aPi can also describe systems in which the
connectivity, that is the sharing of communication channels between processes, can
vary arbitrarily. For example consider the following server, for providing forwarders
between channels:
GenF ⇐ rec w. for?(f, t)(w | F(f, t))
where F(f, t) is shorthand for the recursive code
rec z. f?(x, y) (new ack)(t! x, ack
| ack?(y! | z))
The process GenF when it receives a pair of channels at for, say b, c, spawns off
the forwarder F(b, c) and concurrently awaits another request on for. Repeated
use of this server will lead to many different communication linkages being
established, some of which may subsequently disappear. So dynamically changing
communication topologies are very easy to program in aPi.
Notation 2.12 The symbol αi will be used to range over all input action labels,
those of the form c?V , while αo will refer to an arbitrary output label, (b̃)c!V . We
will use α to represent an arbitrary external action label, input or output, while µ
will range over all possible actions; that is it may also include τ . We use bn(µ) to
denote the set of bound names in the action µ: if this is an input action then bn(α)
28 The asynchronous PI-CALCULUS
is empty, while if it is the output action (b̃)c!V then it is the set {b̃}. Finally n(µ)
denotes the set of names that appear anywhere in µ, while fn(µ), the free names in
µ, are those in n(µ) that are not in bn(µ).
It is worth emphasising that here we are not concerned with any external view of
these actions. We are simply defining, very intentionally, the ability of processes
to perform these actions rather than the ability of some observer to discern that
these actions have taken place. This more subtle viewpoint will be discussed in
Section 2.6.
These relations are defined to be the least relations between processes, that is
closed terms in aPi, which satisfy the inference rules in Figure 2.5. The first two
axioms, (l-in) and (l-out), are straightforward but note that the input move is only
possible when the substitution of V for X in R is well-defined.
The output axiom (l-out) needs no explanation. The rule (l-open) allows new
names to be exported. For example using this rule, and (l-out), we may deduce
that the process (new b) c! b
can export the new name b along the channel c:
(b)c!b
(new b) c! b
−
−−→ stop
However it is essential to note that (l-open) can only be applied when the resulting
action label (n)αo is well-defined; for example if α is c!V then this demands that n
is different from c, and that it appears in the value V .
2.3 An action semantics for aPi 29
τ
The rule (l-comm), consisting of two symmetric rules, defines the action −→ as
the simultaneous occurrence of input and output actions. For example we have the
action
τ
c?(x) R | c! v
−→ R{|v/x|} | stop
The rule (l-comm) also implements scope extrusion. For example it can be used
to deduce
τ
c?(x) x! v
| (new b) c! b
−→ (new b)(b! v
| stop)
from the two prior judgements
c?b (b)c!b
c?(x) x! v
−→ b! v
and (new b) c! b
−
−−→ stop
A more interesting example is
τ
c?(x) (x! v
| P) | (new b)(c! b
| b?(x) R) −→ (new b)(b! v
| P|
stop |b?(x) R)
where we assume x does not occur in P. Here the process (new b)(c! b
| b?(x) R)
uses the channel c to send a private channel b to its partner, on which it, and only it,
can receive data. Its partner uses this newly acquired private channel to send some
private data, say v, resulting in the system
(new b)(stop |P | stop |R{|v/x|})
Since b is guaranteed not to occur in P this term is effectively the same as
P | R{|v/x|}
For example these two terms can be shown to be structurally equivalent. They
represent a system in which the original process has successfully obtained the
private data from its partner, and the private link between them used for the transfer
of this data has disappeared.
Note the side conditions in the rule (l-comm); the extruded names (b̃) should
not occur free in Q or otherwise those free occurrences would be captured in the
residual. So for example we can not deduce
τ
(c?(x) x! b
) | (new b)(c! b
) −→ (new b)(b! b
| stop) (2.5)
Intuitively the process (new b)(c! b
) is exporting some arbitrary but fresh name
along c and consequently it cannot be the same as the existing name b belonging
to its partner. However recall that processes are identified up to α-equivalence
and therefore we can take a different representative for (new b) c! b
, for example
(new d ) c! d
. Then with applications of (l-in) and (l-out), followed by a valid
30 The asynchronous PI-CALCULUS
On the other hand if n is free in the output label then (l-open) gives
(n)(b̃)c!V
−−−−→ P2 and we get the slightly different move
(new n) P2 −
τ
P1 | (new n) P2 −→ (new n) (new b̃)(P1 | P2 )
The symmetric case, when P has the form P1 | (new n) P2 , and Q is (new n)(P1 |
P2 ) is equally delicate. Again a careful analysis of the derivation of the action
µ
P −→ P is required in order to find the corresponding action from Q. For example
the action could be a communication from (new n) P2 to P1 in which n is exported.
τ
In this case P will have the form (new n)(P1 |P2 ) and one can show that P1 |P2 −→
P1 | P2 , thereby providing the required move from Q.
This completes our examination of the one axiom (s-extr). Luckily, all the other
axioms are completely straightforward as indeed are the two inductive cases in the
definition of ≡.
τ
Proposition 2.14 P −→ Q implies P −
→ Q for some Q such that Q ≡ Q .
Proof: This is proved by rule induction on the definition of the relation P −→ Q.
τ
In other words we have to show that the relation −→ satisfies all the defining axioms
and rules of −→, given in Figure 2.4.
All the axioms are straightforward and the one explicit inductive rule (s-struct)
is covered by the previous lemma. The implicit inductive rules, present because −→
is defined to be contextual, are also straightforward because of (l-cntx).
The converse is much more straightforward. In fact the reduction relation can
τ
mimic precisely internal actions. However, since P −→ Q is defined in terms of
2.3 An action semantics for aPi 33
α
the external actions P −→ Q, when giving the proof of this fact we also require
auxiliary properties of these more general actions.
Proposition 2.15
(b̃)c! V
Proof: The proofs of the first two statements are simple rule inductions, on the
(b̃)c!V c?V
inference of the actions P − −−→ Q and P − −→ Q.
The final statement, which is the most interesting, is also by induction on the
τ
inference of P −→ Q. If this is an instance of the axioms (l-eq), (l-neq) or
(l-unwind) then the result is immediate since these axioms are also used in the
definition of reduction. So suppose (l-comm) is used. Without loss of generality
we can assume the internal action has the form
τ
P1 | P2 −→ (new b̃)(P1 | P2 )
c?V (b̃)c!V
where P1 − −→P1 and P2 − −−→P2 ; that is P has the form P1 |P2 and Q is (new b̃)(P1 |
P2 ). Here we can use the first two parts of the proposition to give the structure of
the processes involved, up to structural equivalence. We have
P2 ≡ (new b̃)(P2 | c! V
)
and
Moreover, using α-conversion if necessary, we can choose the bound names (ñ)
and (b̃) so that they are different from each other and also different from all the free
names in both P1 and P2 ; this will be useful when manipulating the terms up to
structural equivalence. The second part of this proposition also gives the structure
of the residual P1 :
using the reduction rules from Figure 2.4. But, since (ñ) do not occur free in P2 , this
term is structurally equivalent to (new b̃)(P1 | P2 ). So an application of (r-struct)
gives the required
P1 | P2 −→ (new b̃)(P1 | P2 )
τ
There are two more cases to consider in the possible derivations for P −→ Q.
These are the inductive cases, where the instances of the rule (l-cntx) are used.
However they are straightforward and left to the reader.
τ
We can now sum up the relationship between the two relations −→ and −→.
τ
Corollary 2.16 P −→ Q if and only if P −
→ Q for some Q such that Q ≡ Q .
Note however that R must include ≈bis . This is because processes of the
form (new n) R may extrude n as part of an output action. For example one
(n)αo
possible action from (new n) P1 is (new n) P1 −−−→ P1 , where αo is an output
αo
action P1 −→ P1 . This latter can be matched by a partner process, one such that
(new n) P1 S (new n) P2 , because P1 ≈bis P2 . Because of this equivalence there is
αˆo
an action P2 =⇒ P2 such that P1 ≈bis P2 ; this in turn can be transformed into an
(n)αˆo
action matching the original one from (new n) P1 , (new n) P2 ==⇒ P2 . But note
that the resulting pair P1 , P2
is not in S ; however it is in R, which is all that is
required for the proof to go through.
We show R is a bisimulation from which the result will follow because of the
second clause. Note that by definition R is symmetric and therefore we need only
prove the transfer property in one direction.
µ
Let P, Q
∈ R and P −→ P . We must find a matching move from Q, a move
µ̂
Q =⇒ Q such that P , Q
∈ R. How we find this matching move depends on the
structure of P and Q. To discover this structure we do an induction on the proof
that the pair is in R. There are three possibilities:
• P, Q
∈ R because P ≈bis Q. The fact that ≈bis is a bisimulation immediately gives the
required matching move.
• P, Q have the form P1 | Q , P2 | Q , respectively, and P1 , P2
∈ R. Here induction will
ensure that every move from P1 can be matched by a move from P2 .
µ
The proof proceeds by rule induction on the derivation of the action P −→ P . There are
numerous cases and we only examine one, when µ is τ because of an output from P1 to
Q . So we have actions
(b̃)αo αi
P1 −−−→ P1 Q −→ Q
where P is (new b̃)(P1 | Q ); here αo is some simple output action a!V and αi the
complementary input action a?V .
(b̃)αo
Induction now gives a matching move from P2 , an action P2 ===⇒ P2 such that
P1 , P2
∈ R. We can combine this matching move with the complementary action
τ ∗
from Q to give Q −→ (new b̃)(P2 | Q ). This is the required matching move; the
second, and more particularly the third, clause in the definition of R, ensures that
P , (new b̃)(P2 | Q )
∈ R.
2.5 Contextual equivalences 37
• The final possibility is handled in a similar manner. Here P, Q have the form (new n) P1
and (new n) P2 , respectively, for some n, and P1 , P2
∈ R. The move from P is
determined by a move from P1 , induction gives a matching move from P2 , which in
turn gives the required matching move from Q.
In this section we step back and examine the extent to which it is the most appropriate
semantic equivalence for aPi, despite these favourable properties.
From the most general point of view, processes should only be considered to
be semantically different if a user can observe a difference in their behaviour.
The difficulty is in formalising how users interact with processes and how they
can come to discern differences. In aPi users can only interact with processes
by communicating on channels, and these interactions form the basis of the
definition of ≈bis . Consequently we would expect that bisimulation equivalence
will imply whatever semantic equivalence based on user interaction that emerges.
Nevertheless, there is still room for discussion on what this more basic notion of
equivalence should be.
As a first attempt we could say that two processes are distinguishable only if
there is some action that one can perform and the other cannot; a priori a user
could then discern a difference by asking for this action to be performed. But this
is easily seen to be much too weak a notion. Defined in the following manner P1
and Q1 would be considered to be semantically equivalent, as they both offer the
same interaction on channel a:
P1 ⇐ (new n)(a! n
| n?b!) Q1 ⇐ (new n)(a! n
| n?c!) (2.6)
But they obviously should be considered semantically different and the difference
can be discerned by subsequent interaction. An observer that inputs on the channel
received on a, will receive either a or b, depending on whether they are observing P1
38 The asynchronous PI-CALCULUS
or Q1 . In other words our semantic equivalence should take into account repeated,
or more complex, methods for interacting with, or observing processes.
The literature is littered with various attempts at formalising what it means to
observe processes, many of which are difficult to justify. Here we take a different
approach; we define our semantic equivalence in terms of desirable, and reasonable,
properties we would like it to enjoy. The approach is straightforward. We list
desirable properties P1 , . . . , . . . , Pn and define our semantic equivalence to be the
largest equivalence relation between processes that satisfies all of them. In other
words processes will be distinguished only if it is required by one of our desirable
properties.
The first property is purely observational:
(b̃)c!V
Definition 2.22 (observations) Let P ⇓barb c if P ===⇒ P , for some P , (b̃) and
value V .
We say a relation R over processes preserves observations if
P, Q
∈ R implies P ⇓barb c if and only if Q ⇓barb c
This notion of observation is easy to justify. We can design a simple test that will
determine if a process can perform such an observation. For example let Cc [−] be
the context given by
[−] |c?(x)eureka!
(b̃)c!v
Then the overall system Cc [P] will be able to report eureka if and only if P ===⇒P ,
for some P , for some simple value v.
Nevertheless we have already seen that this property alone is not sufficient to
determine a good semantic equivalence; for example P1 and Q1 defined above in
(2.6) would not be distinguished.
Another desirable property is preservation by contexts; as we have already
mentioned this means that the equivalence could be used in the compositional
construction and analysis of systems. To keep life simple we will concentrate on
static contexts. So as a second attempt we could use these two properties:
This is a considerable improvement on our first attempt. For example, this satisfies
the property
for any static context C[ ]. Indeed this property enables us to show that P1 Q1 ,
where these processes are defined in (2.6). To see this it is sufficient to observe them
in a static context, which examines the further actions they perform. Let Cab [−] be
the context
Then Cab [P1 ] ⇓barb eureka whereas Cab [Q1 ] ⇓barb eureka. Consequently
Cab [P1 ] Cab [Q1 ], and therefore P Q.
This is the standard method for showing that two processes are not related via ;
find a static context and an observation that will distinguish them when placed in that
context. But proving that two processes are equivalent is far less straightforward.
In the following example we use
P⊕Q (2.7)
as an abbreviation for
where n is chosen so that it does not occur in either of P, Q. This is called the
internal choice between P and Q because it may non-deterministically choose to
execute either of these processes. Consider
P2 can output on c after having received an input on b. Q2 also has this behaviour
but it may, in addition, evolve into the deadlocked state stop; in other words Q2
may (randomly) decide either to act like P2 , or become deadlocked. It turns out that
P2 Q2 but how do we prove it?
We could construct a relation R that
• contains the pair P2 , Q2
• is contextual
• preserves observations.
Since is the largest relation with the last two properties it will follow that
R ⊆ and therefore that P2 Q2 . However constructing such as R turns
40 The asynchronous PI-CALCULUS
We add this to our list of desirable properties, to give us our third, and final property
based semantic equivalence:
Intuitively the reason for not being able to distinguish between c?c! and stop is
that, regardless of the context in which these are placed, it is difficult to conceive
of an observation that can distinguish them. One can send a message along c to the
former, but since output is asynchronous, that is no behaviour can depend on its
receipt, an observation can also not depend on it. Another more general example is
given by
c?(x) (c! x
| c?(x) R) =
∼ c?(x) R
Bisimulation equivalence is defined in terms of the ability of processes to perform
input and output actions whereas = ∼ is defined on the ability of contexts to
observe these actions. Thus Proposition 2.28 is understandable; but underlying
these counter-examples to the converse implication is the fact that certain actions
cannot be observed.
for any process P. Intuitively this means that, when an observer proffers the value
V along c, the value may just remain there waiting for the process to consume
it; the value is delivered to the process P, but it awaits consumption. The final
rules are borrowed directly from Figure 2.5 and simply allow the axioms to occur
appropriately under static contexts.
The properties of the new asynchronous input action are very close to those of
the standard (synchronous) version:
Lemma 2.30
• P− −→ P implies P −−→a P .
c?V c?V
(b̃)c!V τ ∗
• P1 −−→a P1 and P2 −
c?V
−−→ P2 implies P1 | P2 −
→ Q for some Q structurally equivalent
to (new b̃)(P1 | P2 ).
2.6 An observational lts for aPi 45
Proof: The proof of the first statement is straightforward, as all the defining rules
for P −−→ P are included in those of P −
c?V
−→a P .
c?V
by the axiom (a-con) the result is immediate since we have P1 − −→ P1 . The
c?V
non-trivial case is when it is inferred by the axiom (a-delv). In this case P1 is
P1 | c! V
and from Proposition 2.15 we know P2 is structurally equivalent to
(new b̃)(c! V
|P2 ). So, via applications of (s-extr), (new b̃)(P1 |P2 ) is structurally
equivalent to P1 |P2 ; the bound variables can be chosen fresh to P1 . And so trivially,
τ ∗
up to structural equivalence, P1 | P2 −→ (new b̃)(P1 | P2 ), in zero steps.
c?V
The inductive cases, when P1 −−→a P1 is inferred by the rules in (a-cntx), are
routine. For example suppose P1 , P1 have the form (new d ) P, (new d ) P , where
P− −→a P ; let us choose the bound name d so that it is new to P2 . Then by induction
c?V
we have
τ ∗
P | P2 −→ Q
such that Q ≡ (new b̃)(P | P2 ). An application of (l-cntx) gives
τ ∗
(new d )(P | P2 ) −→ (new d ) Q
Note that P1 | P2 is structurally equivalent to (new d )(P | P2 ) and therefore an
application of Lemma 2.13 then gives
τ ∗
P1 | P2 −→ Q
for some Q ≡ (new d ) Q . This is the required matching move, because, since d is
chosen to be fresh, we have (new d ) Q ≡ (new b̃)(P1 | P2 ).
With these inference rules we now have a new interpretation of aPi as an lts:
• the configurations are, as before, the closed terms in aPi
• the relations over the configurations are given by the actions
c?V
– P− −→a Q
(b̃)c!V
– P −−−→ Q
τ
– P −→ Q.
We refer to this as the asynchronous lts for aPi, or the asynchronous interpretation
of aPi. For notational convenience an arbitrary action in this lts will be denoted
µ
by P −→ a P , although for output and internal actions this will coincide with the
µ
standard actions P −→ P . In particular, it is worth remembering that the internal
τ
action P −→a P is still defined in terms of the standard (synchronous) input and
output actions.
Definition 2.31 (asynchronous bisimulations for aPi) Any relation that satisfies
the transfer properties in the asynchronous lts for aPi is called an asynchronous
46 The asynchronous PI-CALCULUS
−→a P ; See
c?V
This is straightforward by induction on the derivation of the action P −
Question 5 at the end of the chapter.
With this result the proof now follows as in Proposition 2.19.
• P1 | Q, P2 | Q
∈ R for every process Q
• (new n) P1 , (new n) P2
∈ R for every name n.
Here we employ Lemma 2.30. Using the first part we know P1 − −→a P1 and
c?V
c?V
therefore by induction this can be matched by a move P2 ==⇒a P2 . Now employing
the second part of the same lemma we have, up to structural induction, a required
τ ∗
matching move P2 | Q −→ (new b̃)(P2 | Q ).
Note that there is a subtlety here with the bound names in actions; these can only
occur in output actions. The tests cannot provoke exactly the same reaction from a
(b)c! a,b
succ! | P .
τ ∗
To prove the converse first suppose T | P −→ Q. It is easy to see that Q has
τ α
either the form T | P where P −→ P or it has the form succ! | P where P =⇒
∗ P.
2.7 Justifying bisimulation equivalence contextually 49
Note that the use of fail in the test ensures that if Q ⇓barb fail then the process
being tested has to have performed the output action.
The next lemma enables us to recover the full use of the residuals obtained
by using these tests to provoke actions, essentially stripping off the bound names
inherited from output actions.
50 The asynchronous PI-CALCULUS
Lemma 2.38 (extrusion) Suppose (ñ) ⊆ (m̃), where both are sequences of distinct
names.
Then (new ñ) (P | succ! m̃
) =
∼ (new ñ) (Q | succ! m̃
) implies P =
∼ Q, provided
succ is fresh.
Proof: We define a relation R by letting P R Q if there is some succ fresh to P
and Q and some (ñ) ⊆ (m̃) such that
The result follows if we can show that R satisfies the defining properties of =.
∼ Note
that because of Question 10, the actual fresh name used here, succ, is not actually
important; for if succ is another fresh name then (2.9) also implies, by applying
an injective substitution, that
succ?(X ) xi ?eureka!
where eureka is some fresh name, and the pattern X is chosen to match (m̃). Then
because P ⇓barb b we also have
Since
Because =
∼ is contextual we know that
T | P1 =
∼ T | P2
We also know that
T | P1 −→∗ (new bn(α))(succ! bn(α)
| P1 )
and therefore T | P2 −→∗ Q for some Q such that
(new bn(α))(succ! bn(α)
| P1 ) =
∼Q
This means that Q ⇓barb succ and Q ⇓barb fail and so the second part of definability
gives that Q is structurally equivalent to some process (new bn(α))(succ! bn(α)
|
α
P2 ), where P2 =⇒
a P2 . Since structural equivalence is contained in = we know
∼
(new bn(α))(succ! bn(α)
| P1 ) =
∼ (new bn(α))(succ! bn(α)
| P2 )
to which the extrusion lemma can be applied to obtain the required P1 =
∼ P2 .
This completes our exposition of our version of the pi-calculus, aPi. The
primary semantics of the language is expressed as a reduction semantics, which
describes how in principle processes perform computations. This reduction
semantics is in turn the main ingredient in the behavioural equivalence between
processes, =,
∼ which is designed to capture how processes behave as components in
larger systems. We then established that bisimulations provide a proof methodology
for establishing such behavioural equivalences. Finally we showed how the
definition of bisimulations could be adjusted, so that the result, asynchronous
bisimulations, provides a complete proof methodology for =; ∼ if two processes are
behaviourally indistinguishable there is an asynchronous bisimulation that relates
them.
2.8 Questions
1. Prove that a relation R over aPi processes is contextual, according to Definition 2.5,
if and only if P R Q implies C[P] R C[Q] for every static context C[−].
2. If the axiom (s-flip) from Figure 2.3 is dropped from the definition of structural
equivalence does Corollary 2.16 still remain true?
What about when either of the axioms in (s-stop) are dropped?
3. Prove that =
∼ is an equivalence relation.
4. Show that P ≡ Q implies P = Q.
µ µ∼
5. Prove that ≡ ◦ −→ a ⊆ − → a ◦ ≡ .
6. If n does not appear in the free names of P show that (new n) P ≡ P.
7. Prove that an asynchronous bisimulation up to ≡ for aPi is also an asynchronous
bisimulation.
8. Show that b?c! b?c! ⊕ stop where is defined in Definition 2.23.
2.8 Questions 53
Q such that P | c! V
−→∗ Q .
(ii) Use part (i) to prove that P ≈bis Q implies P ≈a Q.
13. Let Pi be the language obtained by replacing the asynchronous output c! V
in aPi with
c! V
.P. The reduction semantics for the new language is obtained by replacing the
rule (r-comm) in Figure 2.4, with
(r-syn.comm)
c! V
.P | c?(X ) R −→ P | R{|V/X |}
In this chapter we look at type systems for the language aPi. The traditional view
of types is that they provide an aid to programmers to avoid runtime errors during
the execution of programs. We start with this view, explaining what runtime errors
might occur during the execution of aPi processes, and design a type system that
eliminates the possibility of such errors.
We then modify the set of types, so that they implement a more subtle notion of
resource access control. Here the resources are simply channels, and the more subtle
type system enables access to these resources to be managed; that is read and write
accesses can be controlled. The view taken is that one no longer programs directly
with resource names. Instead programming is in terms of capabilities on these
names, the ability to read to or write from a particular resource. These capabilities
are managed by the owners of resources and may be selectively distributed to be
used by other processes.
55
56 Types for aPi
a successor function succ for integers or not on booleans. Then we may have
processes in which a value of one type finds itself in a context where a value of a
different type is expected:
c! 0
| c?(x) d ! not(x)
c?(x) x! v
the channel c is obviously expecting to receive a channel. But as part of the larger
system
c! true
| c?(x) x! v
(3.1)
it will actually receive the boolean value true. This is another kind of error we
would like to eliminate.
Even ignoring base values, there are also errors that can arise because of the
shape of values being transmitted through channels, so-called arity mismatches.
For example the process
c?(x, y) x! y
(3.2)
expects a pair of values, the first of which incidentally should be a channel. But in
c! v
| c?(x, y)y! x
(3.3)
rec x. (a?(y) x! y
| x) (3.4)
mind, while the rule (err-str) and the implicit contextual rules give more contexts
in which these errors might occur.
So the object of our analysis is to ensure that if a process P passes then it will
never give rise to a term Q such that Q −→err ; that is for every Q such that P −→∗ Q
we should have Q −→err .
Let us now investigate briefly what form this static analysis should take. If we
look at example (3.1) above it is not clear which sub-process, the sender or the
receiver, is at fault. It actually depends on the intended use of the channel c, either
to transmit boolean values, or to transmit channels. In the current description of
the process there is no indication of this intention. In fact we need to augment the
language with a facility for indicating the intended use of channels. When a new
channel is declared it must have associated with it a declaration type, indicating
the valid uses to which it may be put. Thus in
(new c : D)(c! true
| c?(x) x! v
) (3.5)
if the declaration type D indicates a boolean channel, that is a channel for carrying
boolean values, then the right-hand process is misusing c, while if it indicates a
channel that carries channels the fault lies with the left-hand one.
In general the declaration type of a channel should indicate the kind of values that
it can handle. These could be integer values, boolean values, or in turn channels.
But looking at the example (3.3) above the type should also indicate the structure
of the value. Here one process thinks it is receiving a pair of values while the other
is sending a single identifier.
We also need to differentiate between the different kinds of channels that can be
transmitted. In
c?(x) x! a
we can deduce that c carries channels but a priori there are no constraints on the
transmitted value a. However in
(c! d
| d ?(y) y! 0
) | c?(x) x! a
(3.6)
58 Types for aPi
we see that it is further constrained to only carry channels that in turn can carry
integer channels. If the value output on y were changed to true then the declaration
type of c would have to indicate that it transmits channels that in turn transmit
boolean channels.
The precise definition of the types, called simple types, is given in Figure 3.2,
where they are classified into different kinds. The most important is that of channel
type, rw T
, where T denotes the type of values that can be transmitted. Thus,
following our discussion, in (3.6) the channel c should have the declaration type
rw rw rw int
where now the environment will need a type to associate with the variable x; this
will be the object type of D. But what this latter point also implies is that type
environments need to associate types not only with names but also with variables.
Essentially type environments are finite lists of type associations, pairs of the
form u : A. But in order to check the correct use of recursion variables we also
need to include type associations of the form x : proc. This will indicate that x is
only to be used for the purpose of a recursive definition; it is important to realise
that this special proc will only play a role in the construction of type environments,
and will not be used, for example, to type values. So let us introduce a further
meta-variable for the class of types that can appear in environments:
E ::= A | proc (3.7)
Then an environment will have the form
u1 : E1 , u2 : E2 , . . . , un : En , n ≥ 0
subject to some mild restrictions. Rather than impose these restrictions globally let
us give a formal definition of what it means to have a valid type environment.
In Figure 3.3 we give rules for inferring valid environments, using judgements
of the form
s env
The first rule, an axiom, says that the empty association list is a valid type
environment while the second says that an existing environment may be augmented
by adding a new identifier, a name or a variable, and an associated channel type
C; here dom() is the set of identifiers that have an associated type in . We are
also allowed to add new variables assigned to base types, with (e-new.base) and
new recursion variables, with (e-proc); here base ranges over the collection of
60 Types for aPi
base types, which we leave unspecified. This is perhaps being overly formalistic,
as basically a valid type environment is a finite type association list, a list of pairs
u : C, x : base or x : proc, where each identifier has a unique entry. But later we
will see that the formation of type environments will get non-trivial, and thus we
will make a distinction between an association list and a valid type environment.
We will also use the notation , to denote the association list obtained by adding
on the associations in to those in ; of course there is no guarantee that the
resulting association list is a valid type environment.
The association between identifiers and types determined by an environment
can be generalised to arbitrary values V , by structural induction, and the rules for
making the judgements
s V : T
are given in Figure 3.4. The intuition behind s V : T is that relative to the
environment the value V may be used anywhere a value of type T is required.
To deal with base values we assume base types are actually sets of base values; for
example int and bool are the set of integers, booleans respectively. Then the rule
(sty-base) assigns to the base values the type to which they belong.
We can still view the reduction semantics of Chapter 2 as applying to typed aPi,
simply by viewing the unannotated term (3.8) as standing for any term of the
form (3.9). Indeed it is appropriate that the reduction semantics should not refer
to the types of any of the names involved. Moreover we will continue with this
view, omitting the declaration types in terms unless they are directly relevant to the
discussion. However formally we must define structural equivalence, an important
component of the reduction semantics, as a relation over typed processes. So the
defining axioms, in Figure 2.3, must be interpreted as acting on typed processes.
For example (s-extr) now means that for every type D,
where R is an arbitrary, possibly open, process term. There is one rule for each
construct in the language. Most of the rules are straightforward. (sty-stop) says that
term stop represents a well-typed process relative to any valid type environment. To
typecheck R1 |R2 it is sufficient to typecheck the components R1 and R2 individually,
(sty-par), while to typecheck (new n : D) R relative to the environment we need
to check the term R relative to the augmented environment , n : D. The treatment
of if v1 = v2 then R1 else R2 also uses induction. must know the values v1 , v2
and in turn the terms R1 and R2 must be typechecked.
62 Types for aPi
The only non-trivial rules are for input and output, which in turn refer to the
judgements in Figure 3.4 for assigning types to values. The term u! V
is well-typed
relative to if
• can assign to u a channel type
• can assign to the value being sent, V , the object type of that assigned to u.
The input rule (sty-in) says that for u?(X ) R to be well-typed relative to
• u must have a channel type of the form rw T
in
• the residual R must be well-typed in an augmented type environment.
v1 :A1
, . . . , vn :An
Referring once more to the rule (sty-in), one consequence of this definition is that
there is no possibility of typechecking a term of the form u?(X ) R relative to an
environment unless the object type of u in that environment matches the pattern X .
Before looking at some examples it is worth emphasising the way in which we
treat bound variables in typing judgements. Throughout we make the restriction
that typing rules can only be applied to judgements
s
R : proc
when the domain of does not contain any bound name in R; indeed this is another
application of the Barendregt convention, Convention 2.4. So for example in the
rule (sty-new) we know that n is new to and therefore the extended environment
, n : D is well-formed, assuming is. Similarly in (sty-in) we know that all the
variables in the pattern X are new to and therefore , X :T
will be a valid
environment, assuming X matches T . But there may be times, for example when
generating the proof of a typing judgement, when we are required to form a sub-
judgement of the form
s (new n : D) R : proc (3.10)
where n already appears in . In such cases we recall the fact that terms actually
denote equivalence classes under α-conversion, and we interpret rules involving
bound variables, such as (sty-new), as saying that to infer (3.10) above it is
sufficient to infer
s (new m : D) R : proc
for some m not in the domain of , such that
(new m : D) R ≡α (new n : D) R
In the sequel we will say a term R is well-typed if it can be typechecked, that is
if there is some environment such that s R : proc can be inferred from the rules
in Figure 3.10. It will also often be convenient to drop these occurrences of proc,
rendering typing judgements simply as s R.
Example 3.3 Consider the typechecking of the process
(new d : D)(c! d
| d ?(y) y! 0
) | c?(x) x! b
, d : rw rw int
It is easy to see that for the process to be well-typed the form of the type D is
determined by that of c. Also all the entries in c,b are necessary to type this
process in the sense that if is any other environment for which
s
(new d : D)(c! d
| d ?(y) y! 0
) | c?(x) x! b
can be derived, then dom() must include at least b, c and must coincide with
c,b on these names.
Example 3.4 [Typing the Compute Server ] Recall from Example 2.10 that this is
defined by
primeS ⇐ rec z. (z | in?(x, y) y! isprime(x)
)
where isprime represents some test for primality. The only free name occurring in
primeS is in and therefore we should be able to type it relative to some environment
s that simply maps in to some type S. This channel expects two pieces of data, an
integer and a channel; moreover the channel will be used to return a boolean value.
So S has to be
rw (int, rw bool
)
The second uses an application of (sty-in), followed by (sty-out), and the above
(sty-op). The former requires an instance of a value judgement, (sty-id).
Now consider the typed version of the clients:
Clienti (v) ⇐ (new r : Dr ) in! v, r
| r?(x) printi ! x
The declaration type of the reply channel Dr is determined by that of in; it has to
be rw bool
. Assuming that v is an integer one can infer
s , printi : rw bool
s Clienti (v)
Summing up, we can type the overall system
Sys ⇐ Client1 (27) | Client2 (29) | primeS
relative to any type environment s such that
s s
in : S, printi : rw bool
Proof: The first statement is proved by induction on the size of . The base case
is when this is empty, which is trivial. Otherwise it has the form , u : E and the
judgement
, , u : E s env
must have been inferred from one of the three rules (e-new.id), (e-new.base) or
(e-proc). But the premise in each rule allows us to conclude that , s env. We
can now apply induction to this statement to obtain the required s env.
The proofs of the second and third statements are by induction on the derivation
of the judgement in question; it is sufficient to carry out a case analysis on the last
rule used. Thus the proof of the second statement has four cases, since the proof of
the judgement could end in any of the four rules in Figure 3.4, while the proof of
the third has eight cases, arising from the seven rules in Figure 3.5, and the trivial
possibility of an application of (sty-id), when R is a variable. Note that some of
these cases, for example the rule (sty-new), rely on part (i), while others, such as
(sty-in), rely on part (ii).
One minor, but crucial, property of the typing system in Figure 3.4 is that, relative
to a given environment, it assigns unique types to values; however the reader should
be warned that this will not be true of later typing systems.
3.3 Properties of typechecking 67
This result means that we can view a type environment as a function that maps
identifiers in its domain dom() to types. We use (u) to denote the type associated
with the identifier u.
Although we have been careful in the construction of environments, it turns out
that the order in which type associations are added does not really matter:
Proposition 3.7 (interchange) Let and denote the lists 1 , u : E, u : E , 2
and 1 , u : E , u : E, 2 respectively. Then
• s env implies s env
• s V : T implies s V : T
• s R implies s R.
Proof: The first statement is proved by induction on the size of , with the only
non-trivial case being when it is empty where a case analysis is required on the
forms of u, u ; the inductive case is taken care of by Lemma 3.5(i).
The other two statements are proved by rule induction, and an analysis of the
last rule used. The essential fact underlying these results is that any derivation of
a judgement using can be replaced by one using ; environments have unique
entries for identifiers and in typechecking they are essentially only used as look-up
tables.
The following are more substantial, but the structure of the proofs are similar; they
also require the property (interchange).
Proposition 3.8
• (Weakening) Suppose , s env. Then
– s V : T implies , s V : T
– s R implies , s R.
• (Strengthening)
– If , u : E s V : T where u does not occur in V , then s V : T.
– If , u : E s R where u does not occur in R, then s R.
Proof: The proof details, which are considerable but mundane, are left to the reader;
here we only give their structure, and some typical example cases.
• (Weakening): Both cases are proved by rule induction, and an analysis of the last rule
used in the derivation. For example if s V : T is proved by an instance of (sty-id),
then exactly the same rule can be applied to the extended environment , , to conclude
, s V : T.
68 Types for aPi
The most important technical property of the type inference system is that in some
sense typing is preserved by the substitution of values into variables, provided the
types assigned to these values and variables coincide.
, x : A s u : rw T
, x : A s V : T
for some transmission type T. We can apply part (i) of the proposition to both judgements
to obtain s u : rw T
and s V : T. An application of (sty-out) now gives the
required s u ! V
.
3.3 Properties of typechecking 69
, x : A s u : rw T
, x : A, Y :T
s S
for some transmission type T. Note that the ability to apply (sty-in) means that x cannot
be in the pattern Y . This time we apply part (i) of the proposition to the first judgement
to obtain
s
u : rw T
, Y :T
, x : A s S
, Y :T
s S
s
u ?(Y ) S that is s
R
All other cases are similar, using the part (i) of the proposition or induction. But note
that the cases (sty-rec) and (sty-new) also require an application of (interchange),
while that of (sty-zero) needs (weakening).
The final result, for recursion, is proved in a similar manner, by rule induction
on the inference , x : proc s R2 . Let us examine two cases.
We are now nearly ready to prove subject reduction. Recall that the structural
equivalence plays a large role in the reduction semantics. So let us first factor
this out.
Proposition 3.11 Suppose P ≡ Q. Then s P implies s Q.
Proof: This is proved by induction on the proof of P ≡ Q. The contextual rules
in the definition of ≡ pose no problem. For example suppose P, Q have the
form (new n : D) P , (new n : D) Q and they are structurally equivalent because
P ≡ Q . Because s P we know , n : D s P and therefore by induction we have
that , n : D s Q . An application of (sty-new) then gives the required s Q.
So we need only consider the axioms in the definition of structural equivalence,
the typed versions of those in Figure 2.3. Most are straightforward, but note that
one part of (s-stop) requires (strengthening).
The only non-trivial axiom is (s-extr), which might be expected. So suppose
P s (new n : D)(P | Q), where n does not occur free in P. This could only have
been derived by an application of (sty-new) preceded by one of (sty-par) and
therefore we must have
, n : D s P
, n : D s Q
s
P | (new n : D) Q
• Suppose s c! V
| c?(X ) R. We have to show s R{|V/X |}, which will follow from
Corollary 3.10 if we can show that for some type T
, X :T
s R and
s
V :T (3.13)
But we know s c! V
from which we can obtain s V : T1 for some type T1 . In fact
this is a type for which we also know s c : rw T1
. In addition from s c?(X ) R we
obtain , X :T2
s R for some type T2 , a type for which we can deduce s c : rw T2
.
But inferred channel types are unique – see Proposition 3.6, and therefore T1 = T2 . The
result therefore follows from (3.13).
• Suppose s rec x. B. This could only have been derived using (sty-rec) and therefore
we know , x : proc s B. We can now immediately apply Proposition 3.9 (processes) to
obtain the required s B{|rec x. B/x|}.
Proof: The proof is straightforward, which is not surprising since the typechecking
system was designed with the particular definition of −→err in mind.
We prove, by rule induction, that if P −→err then there is no for which s P
can be derived. Looking at the definition in Figure 3.1 we see that seven possibilities
have to be considered.
• (err-chan): Obvious. For example if v is not a name then there is no way to infer a type
for v! V
using (sty-out).
• (err-comm): This is the only case that is not completely trivial. Here P has the form
a?(X ) R | a! V
and the pattern X and value V do not match. Suppose that for some
environment we were able to type at least a! V
. This would mean that there is a type
T, the object type of a in , such that s V : T. But such an inference is only possible
if V matches the type T, which means that T does not match the pattern X . So the list
extension , X :T
is not defined and therefore (sty-in) cannot be used to complete the
typing of R.
• (err-rec): Here P has the form rec x. B and the substitution B{|rec x. B/x|} is not defined.
For any we can apply Proposition 3.9 (recursion), with R1 and R2 instantiated to
rec x. B, B respectively. This implies that either s rec x. B or , x : proc s B. But the
latter possibility also means that s rec x. B as the only way to infer the well-typing of
a recursive definition is with (sty-rec).
All the other possibilities follow by induction. Suppose, for example, that
(new n : D) P −→err because P −→err . By induction P is not typeable and therefore
we cannot use (sty-new), the only possible rule, to infer that (new n : D) P is
well-typed.
Combining these two results we can now conclude that being well-typed
precludes the possibility of runtime errors.
72 Types for aPi
Corollary 3.14 Suppose s P. Then Q −→err for every process Q such that
P −→∗ Q.
Proof: Subject reduction implies that s Q and therefore we can apply type safety
to obtain Q −→err .
that, as we shall see, is determined in turn by that of the access point to the
service s.
. . . a! v
. . .
for such a value v, where a reader on a may be expecting values with all the
capabilities of the type T1 . Again this is discussed further in Example 3.32.
We now use the rules of Figure 3.7 to give a formal definition of the set of
capability types, and the subtyping relation between them.
Definition 3.16 (capability types) Let us write T : ty to mean that the judgement
T <: T can be derived using the rules in Figure 3.7. We use Types to denote the
set of all such T. Note that we have now dropped the superscript s , indicating that
we are no longer dealing with simple types.
We also have a subtyping relation between members of Types; for T1 , T2 ∈
Types let T1 <: T2 whenever the judgement T1 <: T2 can be derived from the
rules.
76 Types for aPi
It is worthwhile noting that this formal definition implements the informal constraint
on the construction on channel types given in Figure 3.6:
Lemma 3.17
(i) If rw Tr , Tw
: ty then Tw <: Tr .
(ii) If the judgement T1 <: T2 can be derived then T1 : ty and T2 : ty.
Proof:
(i) rw Tr , Tw
: ty means that we can derive rw Tr , Tw
<: rw Tr , Tw
. The only rule
for doing so is (sub-chan.a), the premise of which ensures the required result.
(ii) A simple proof by induction on the derivation of the judgement T1 <: T2 . For example
suppose these are rw Tr1 , Tw1
, rw Tr2 , Tw2
respectively, and the judgement was inferred
via an application of (sub-chan.a). This means we already have the judgements Tr1 <:
Tr2 , Tw2 <: Tw1 and Tw1 <: Tr1 , to all of which we can apply induction. So for example
this gives Tr1 <: Tr1 , Tw1 <: Tw1 , and therefore, because we already know that Tw1 <: Tr1 ,
we can apply the same rule to establish rw Tr1 , Tw1
: ty. Establishing rw Tr2 , Tw2
: ty
is equally straightforward, since Tw2 <: Tw1 <: Tr1 <: Tr2 .
In fact we can easily show that this pre-order is actually a partial order, that is <:
is anti-symmetric over capability types. However we will not use this property.
3.4 Types as capabilities 77
Note that lubs and glbs need not be unique, although they will be whenever A, <
is a partial order. Nevertheless we still use the standard notation a b and a b for
arbitrarily chosen instances.
This definition of upper and lower bounds can be generalised from pairs of elements
to subsets of a pre-order A. For example if S ⊆ A we will write S ↓ to mean that
there is some element c in A with the property that c < a for every a in S. One can
show that if A is partially complete then for every non-empty finite subset S, S ↓
implies S has a greatest lower bound, which we will denote as S; see Question 5
at the end of the chapter.
Proposition 3.20 The pre-order Types, <:
is partially complete.
Proof: The proof proceeds in three steps. First we define two symmetric partial
operations on types, T1 T2 and T1 T2 , by simultaneous structural induction.
The base case is when both T1 and T2 are base types, where we have the obvious
clauses:
int int = int int int =
bool bool = bool bool bool = bool
Other base types would have similar clauses.
For channel types T1 T2 may be read off from the following schema, where
now superscripts r,w are used to indicate the role of the type expressions to which
78 Types for aPi
r T1r
r T2r
= r T1r T2r
r T1r
w T2w
= rw T1r , T2w
provided T2w <: T1r
r T1
rw T2r , T2w
= rw T1r T2r , T2w
r T1r
r T2r
= r T1r T2r
r T1r
rw T2r , T2w
= rw T1r T2r , T2w
w T1w
rw T2r , T2w
= rw T2r , T1w T2w
rw T1r , T1w
rw T2r , T2w
= rw T1r T2r , T1w T2w
Finally the definitions are extended to tuple types in the obvious manner:
(T1 , . . . , Tn ) (T1 , . . . , Tn ) = (T1 T1 , . . . , Tn Tn )
(T1 , . . . , Tn ) (T1 , . . . , Tn ) = (T1 T1 , . . . , Tn Tn )
The second step is to establish:
• if there is a Tl such that Tl <: T1 and Tl <: T2 then T1 T2 exists
• if there is a Th such that T1 <: Th and T2 <: Th then T1 T2 exists.
However because of the rules of subtyping, in Figure 3.7, we know that T1w <: Tlw
and T2w <: Tlw , and so by induction we have (1). The subtyping rules also give
Tlr <: T1r . Moreover they enforce the invariant Tlw <: Tlr , from which (2) follows.
Note incidentally that these two conditions ensure that T1 T2 , that is
rw T1r , T1w T2w
, is a valid type; since T1 is a valid type we know T1w <: T1r ,
and so using (2) we obtain the consistency requirement T1w T2w <: T1r .
3.4 Types as capabilities 79
The final step is to show that whenever these operations are defined the resulting
types have the required properties:
• Tl <: T1 T2 for every Tl such that Tl <: T1 and Tl <: T2
• T1 T2 <: Th for every Th such that T1 <: Th and T2 <: Th .
formally the judgements for valid type environment formation and for assigning
types to values need to be defined by simultaneous induction.
This assignment of types to values also needs to be adjusted; the new rules are
given in Figure 3.9. The first (new) one, (ty-sub), merely says that any name known
at a type A, may be used at any supertype A of it; this is perfectly understandable
via the (informal) intuition of a type being a set of capabilities and A <: A meaning
A is a subset of A. The second (new) rule (ty-meet) allows us to combine known
capabilities of a given name. Thus if denotes the environment (3.16) above,
(ty-meet) enables us to deduce c : rw int
. As stated, this rule has a slight
lacuna as a priori we do not necessarily know if the meet A A exists. So for the
moment let us say that this rule can only be applied whenever we know it exists. But
as we shall see, in Proposition 3.26 below, the premises actually always guarantee
its existence.
c! v
Tv <: T and rw Tr , Tw
<: w T
Tv <: Tw
In other words to send a value on the channel c the value must have at least all the
capabilities required by the output type Tw .
A similar analysis will show that c?(x) R(x) is well-typed if the residual R(x)
uses x with at most the capabilities required by the input type Tr . That is we must
be able to infer
, x : Tx R(x)
for some type Tx such that Tr <: Tx . However there is a further implicit constraint.
In the type entry for c, rw Tr , Tw
, there is the constraint Tw <: Tr ; Tr can have
at most the capabilities of Tw . Effectively the constraint on Tx is Tw <: Tr <: Tx .
So in the best possible world the receiving code R(x) can use the incoming value,
bound to x, with at most the capabilities allowed by the write capability of the
channel used in the communication.
The third new rule (ty-match) in Figure 3.5 takes advantage of the extra
structure of types and is particularly relevant for capability based typing systems.
However it does require some motivation. In capability based type systems, as we
have already noted, a process only receives values with some specific capabilities.
Subsequently it may receive some further capabilities on that value and it should
be able to accumulate these for future use. For example the process
receives two values from the resources inA and inB , presumably with certain
capabilities. When executing the code R1 it is known that these two values are
in fact the same and therefore within R1 that actual value should be available at
both the capabilities received along inA and along inB . This is the purpose of the
rule (ty-match). It says we can assume if v1 = v2 then R1 else R2 is well-typed
relative to if
• R2 is well-typed relative to
• v1 and v2 have associated with them some capabilities, given by A1 and A2 respectively
• R1 is well-typed in an environment where v1 has in addition the capabilities of v2 , namely
the type A2 , and vice-versa for v2 .
• symmetrically, adding the knowledge that v2 has the capabilities of v1 , adding v2 :A1
.
Of course this extra information may render the environment inconsistent; that is
, v1 :A2
, v2 :A1
is not a valid type environment. In this case the rule (ty-match)
cannot be successfully applied, as our type system will have a property similar to
the (sanity checks), Lemma 3.5: whenever the judgement P can be inferred
we will be assured that env. But for this case we have the alternative rule
(ty-mis.match), from Figure 3.10. It turns out that whenever value terms v1 and
v2 can be assigned incompatible types they can never be made identical using any
well-typed substitution. Consequently here we know that the true branch will never
be executed, and only R2 needs to be checked.
Example 3.21 [Typing the Memory Server ] Let us now reconsider the memory
server from Example 3.15, which in turn uses the memory code Mem from
Example 2.11. First let us decide on the declaration types of the get and put methods.
Since they are read by the memory and written to by clients they need to be declared
with both read and write capabilities. But the channels transmitted are only ever
used for writing. Therefore appropriate definitions are
Dg = rw w int
Dp = rw (int, w
)
where Sp , Sg are the types at which the server wishes clients to have access to
the put and get methods, respectively. Since it wishes to retain read capability for
itself these are released with the write capability only:
Sp = w (int, w
)
Sg = w w int
Note that these in turn allow the memory to only use the write capability on the
return channels sent via these methods.
To sum up, s assigns to s the type
rw w (w (int, w
)
, w w int
Da = rw
Db = rw int
requires that
Dr <: S, that is rw Cp , Cg
<: w Sp , Sg
Example 3.22 [Using the Rule (ty-match) ] Consider the process OOI
(new s : rw)(outr ! s
| outw ! s
| R)
where R is the recursive process
rec x. in?(y) (if y = s then (give! gold
| x) else (give! brass
| x))
Here we use rw as an abbreviation for the type of a synchronisation channel, one
that can send and receive the empty tuple, rw ()
; in a similar manner we use r, w
to represent r ()
, w ()
respectively.
The process R accepts a value on the port in and only if this is the newly created
resource s does it give out gold; in other cases it gives out brass.
Suppose has the following entries:
outr → rw r
outw → rw w
in → rw rw
OOI
But is it possible to type a process that can successfully obtain the treasured gold?
The important point is that in will only accept values that have both the read and
write capabilities, and these are distributed separately via the ports outr , outw
respectively.
Let Probe be defined by
When Probe is run in parallel with OOI the sought after gold will be spent.
Moreover
Probe
But the rule (ty-match), from Figure 3.10, is essential to the inference. The crucial
step is the inference of
, x : r, y : w if x = y then (in! x
| give?(z) spend! z
) else stop
, x : r, y : w, x : w, y : r in! x
| give?(z) print! z
in : w rw
x : rw
where the last judgement is inferred via an instance of (ty-meet) from Figure 3.9.
It is easy to see that the rule (sty-eq), from Figure 3.5, is not sufficient to type
Probe; with this rule the capabilities on x can never be augmented to satisfy the
requirements of in.
a → rw int
in → rw rw bool
, x : rw int
x : rw int
, x : rw int
a : rw bool
and rw int
↓ rw bool
.
In other words the conditional nature of (ty-match) leads to occurrences of
untyped sub-terms within well-typed processes. However these untyped sub-terms
can never be executed. One may be tempted to add an extra premise to the rule
(ty-mis.match), requiring that R1 be well-typed with respect to , despite the fact
that it will never be executed. However for the effect of this see Question 15 at the
end of the chapter.
Here if u does not appear in both required statements (1) and (2) are immediate;
for if u is in the domain of it must be that u and u coincide, and therefore {u}
is the singleton set {E }.
So we may assume that u is in the domain of . Then induction applied to (2)
gives u : ( {u}), and using a simple argument on value judgements this can
be extended to
u : ( {u}) (3.17)
Now if u is different from u then {u} is the same as {u}; so (1) follows
by induction, and (2) coincides with (3.17). So we may assume that u = u, and
therefore that {u} = {u} ∪ {E }.
1. As we have already seen, induction applied to (2) gives u : ( {u}). Therefore
the side condition on the formation rule (e-ext) ensures that (( {u})) ↓ E , which is
enough to ensure that {u} ↓ .
2. We now know from (1) that (( {u})) E exists, and it is easy to see that it is a greatest
lower bound for the set {u}. So we need only establish (( {u})) E . But this
follows from an application of (ty-meet), to (3.17) and u : E .
With this lemma we can now easily interpret well-formed environments as partial
functions.
Definition 3.25 (environments as partial functions) For every u in dom() let (u)
denote ({u}).
We also use r and w for the related partial functions for looking up the read or
write capabilities on a given identifier. For example r (u) is only defined if (u)
is defined and has one of the forms r Tr
or rw Tw , Tr
, in which case it returns
the type Tr . We will also use the notation (u) ↓def , r (u) ↓def , etc. to indicate
that these partial functions are defined for a particular element, u. The properties
of these functions are pursued in Question 9.
This makes the set of all type environments into a pre-order, and it is worth noting
that it is not a partial order. For example with
1 = c : r int
, c : w int
and 2 = c : rw int
we have 1 <: 2 and 2 <: 1 although they are different. We will write 1 ≡ 2
to mean that both 1 <: 2 and 2 <: 1 are true; we say the environments 1
and 2 are equivalent.
Proposition 3.28 (weakening) Suppose <: . Then
• V : T implies V : T
• R implies R.
(1) v1 : A1
(2) v2 : A2
(3) R2
(4) , v1 :A2
, v2 :A1
R1 .
(1’) v1 : A1
(2’) v2 : A2
(3’) R2 .
(4’) , v1 :A2
, v2 :A1
R1
(a) v1 : A and A ↓ A2 or
(b) v2 : A and A ↓ A1 .
It is worth pointing out that this proof of (weakening) does not rely on the
property (interchange), unlike the corresponding proof for simple types, that of
Proposition 3.8.
This last result says that equivalent environments are equally powerful, from
the point of view of typechecking. Despite not using (interchange) in the previous
90 Types for aPi
proof it remains true in this new typechecking system, and provides an important
example of equivalent environments:
Lemma 3.29 (interchange) Suppose 1 , u : E, u : E , 2 env. Then
• 1 , u : E , u : E, 2 env
• 1 , u : E, u : E , 2 ≡ 1 , u : E , u : E, 2 .
Note that the more restricted version of (interchange) used in Proposition 3.7 is an
immediate corollary of the two results we have just given. Finally (strengthening)
from Proposition 3.8 also remains true. The proof we give here relies on
(interchange), but a more general version may be found in Question 12.
Proposition 3.30 (strengthening)
• , u : E V : T implies V : T, provided u does not occur in V .
• , u : E R implies R, provided u does not occur in R.
Proof: In each case the proof proceeds by induction on the derivation involved,
and a case analysis on the last rule used in the derivation. Let us consider a typical
case, for the second statement, when R has the form if v1 = v2 then R1 else R2
and the rule used is (ty-match). Then we have
(1) , u : E v1 : A1 , v2 : A2
(2) , u : E R2
(3) , u : E, v1 :A2
, v2 :A1
R1 .
Since v1 and v2 cannot be u, the corresponding result for value judgements, and
induction, give
(1’) v1 : A1 , v2 : A2
(2’) R2 .
Now (ty-match), applied to (1’), (2’), (3”) gives the required result.
3.4 Types as capabilities 91
At this stage we have developed for capability types all of the properties of the proof
inference system that underlie both the substitution result and subject reduction for
simple types.
Theorem 3.31 (subject reduction for capability types) Suppose P and P −→
Q. Then Q.
Proof: As in the case of simple types subject reduction relies essentially
on developing corresponding substitution results, along the lines of those in
Proposition 3.9, the main one being:
v : A and , x : A R implies R{|v/x|} (3.18)
However despite having accumulated all the necessary properties used in the proof
of Proposition 3.9, these are not sufficient to establish (3.18) for capability types.
With simple types, the proof of (3.18) in the case when R has the form if v1 =
v2 then R1 else R2 is handled in a straightforward manner by induction, because of
the purely inductive nature of the corresponding typing rule, (sty-eq) in Figure 3.5.
With capability types the corresponding rule, (ty-match) in Figure 3.10 is more
complicated, and it turns out we need to formulate a more general substitution result
than (3.18).
We refrain from doing so here. The details will be spelt out in a more sophisticated
setting in Chapter 5; see the proof of Proposition 5.31. However having established
(3.18), the proof of subject reduction itself is a minor extension to the proof of the
corresponding result for simple types, Theorem 3.12; again the details are spelt out
in the more sophisticated setting of Chapter 5, in Theorem 5.34.
For those wishing to complete the theorem directly for typed aPi, see Question 17
at the end of the chapter.
Instead let us look at some examples that re-enforce the various requirements we
have made on the subtyping relation for capability types.
Example 3.32 [Contra-variance of Write ] We work with an environment 1 such
that 1 (a) = rw rw
, 1 (c) = r, where, as in Example 3.22, rw, r stand for
rw ()
, r ()
respectively. Note rw <: r.
Suppose on the contrary we allowed subtyping to be co-variant on write
capabilities, with the rule
T1 <: T2
(3.19)
w T1
<: w T2
So we would have w rw
<: w r
. Note that this would allow us to infer
a! c
because of the rule (ty-sub), in Figure 3.9. This spells trouble; a reader on a, with
type rw rw
, may be expecting a value with both read and write capabilities, while
c, in the environment 1 , has only the read capability. Such a reader is defined by
a?(y) (y? | y!)
With (3.19) it would be straightforward to infer
1 a! c
| a?(y) (y? | y!)
Yet
a! c
| a?(y) (y? | y!) −→ c? | c!
and 1 c? | c!.
Example 3.33 [Constraint on Read Write/Types ] Here we show that the constraint
Tw <: Tr is required when forming the type rw Tr , Tw
in Figure 3.7. Suppose this
were dropped. Then F = rw rw, r
would be a valid type and
2 a! c
| a?(y) (new b : F)(b! y
| b?(x) x! | x?)
where 2 is such that 2 (a) and 2 (c) are rw r
, r respectively. Here again trouble
brews; c is sent on channel a, which only transmits read capabilities. It is passed
through b, which can magically fabricate new capabilities. We have
a! c
| a?(y) (new b : F)(b! y
| b?(x) x! | x?) −→∗ (new b : F)(c! | c?)
and this latter process cannot be typed by 2 .
We started this chapter by remarking that a type checking system is best justified
by a clear definition of the runtime errors it eliminates. But for the type system
3.5 Questions 93
3.5 Questions
1. Prove R implies R.
s
2. Prove the following more general form of (strengthening) for simple types:
(i) , u : E, s env implies , s env.
(ii) If , u : E, s V : T where u does not occur in V , then , s V : T.
(iii) If , u : E, s R where u does not occur free in R, then , s R.
Your proof should not rely on (interchange), Proposition 3.7.
3. Show that the processes memSERV, mClient and badClient from Example 3.15 can
all be typed relative to some simple type environment, as defined in Section 3.2. You
should also instantiate the declaration types used by these processes with simple types.
4. Show that (new n : D) R implies that D has to be a channel type.
5. Suppose A, <
is a partially complete pre-order.
• Prove that S ↓ implies S has a greatest lower bound, whenever S is a finite non-empty
subset of A.
• Prove a similar result for upper bounds; that is, providing S is finite and non-empty,
S ↑ implies S has a least upper bound.
• Show that if a and b are both greatest lower bounds for a subset S of A then a < b
and b < a.
6. Prove the following inversion properties of subtyping:
(i) For any base type, T <: base implies T = base.
(ii) If S <: (T1 , . . . Tn ) then S = (S1 , . . . , Sn ), where Si <: Ti .
(iii) If S <: r Tr
then
• either S = r Sr
, where Sr <: Tr
• or S = rw Sr , Sw
, where Sr <: Tr .
94 Types for aPi
(iv) If S <: w Tw
then
• either S = w Sw
, where Tw <: Sw
• or S = rw Sr , Sw
, where Tw <: Sw .
(v) If S <: rw Tr , Tw
then S = rw Sr , Tw
, where Sr <: Tr and Tw <: Sr .
7. In a similar vein show how the structure of T is determined by that of S, whenever
S <: T.
8. (Interchange) for capability types. Prove that 1 , u : E, u : E , 2 env implies
(i) 1 , u : E , u : E, 2 env
(ii) 1 , u : E, u : E , 2 ≡ 1 , u : E , u : E, 2 .
9. Suppose u is in the domain of the capability type environment . Prove
(i) u : r Tr
implies r (u) is defined and r (u) <: Tr
(ii) u : w Tw
implies w (u) is defined and Tw <: r (u).
10. Let A, <
be a partially complete pre-order. S ⊆ A is said to be pairwise consistent if
a ↓ b for every pair a, b ∈ S.
(i) Prove that in Types, <:
, every finite non-empty pairwise consistent subset of
Types has a greatest lower bound.
(ii) Is this true for an arbitrary partially complete pre-order?
11. Suppose σ is a mapping over Names ∪ Vars that maps names to names and variables
to variables. For such a σ let σ be the type association list obtained by replacing each
u : E in by σ (u) : E.
Assuming σ is injective on the domain of , prove:
(i) ty implies σ ty
(ii) V : T implies σ σ (V ) : T
(iii) R implies σ Rσ .
Show that these are not generally true when σ is not injective.
12. Without using (interchange) prove the following more general form of (strengthening):
, u : E, R implies , R, whenever u does not occur in R.
13. Let Typesps be the subset of capability types of the form r Tr
, w Tw
or rw T
. Show
that the pre-order Typesps , <:
is not partially complete.
14. Show that well-defined type environments are not necessarily preserved by well-typed
substitutions. That is, if v : A then , {|v/x|} env does not necessarily follow
from , x; A, env.
15. Suppose we replace the rule (ty-mis.match) with
(ty-mis.match.bis)
v1 : A1 , v2 : A2
R1 : proc
R2 : proc
A1 ↓ A2
if v1 = v2 then R1 else R2 : proc
Show that subject reduction no longer holds for the revised typing system.
3.5 Questions 95
16. Without using (interchange) prove the following substitution property for the capability
typechecking system: suppose v : A and x is new to , and , {|v/x|} env. Then
, x : A, R implies , {|v/x|} R{|v/x|}.
17. Use the result of the previous question to prove Theorem 3.31, subject reduction for
capability types. There should be no need to use (interchange).
4
Types and behaviour in aPi
|= P ≈ Q (4.1)
indicating that P and Q are equivalent from the point of view of any user typeable
by . Then if client is such that client s : w S
we would expect
96
Types and behaviour in aPi 97
Using this principle we would then be able to deduce from client Client and
(4.2) above that
P ⇐ (new c : rw)(a! c
| c?P )
Q ⇐ (new c : rw)(a! c
| stop)
and suppose that they are typeable with respect to an environment whose only
entry for a is rw r
; in other words, a can only be used to transmit channel names
that themselves in turn can only be used for at most read access.
We would expect
|= P ≈ Q
because no observing process can exercise the c?P component of P. This follows
since the observing process can only gain knowledge of the new channel c by
receiving it on the channel a; but this method of transmission ensures that it can
never obtain write access on c, because of the type of a in , and therefore can
never activate the c?P component.
More importantly this example demonstrates that the observing environment
can evolve to be different from that of the observed processes. Here, after the
transmission of c on a, the residuals of the observed processes P and Q are working
in an environment in which c has both read and write capabilities, while the
observing environment only has write access. If we call the former i , the internal
environment, and the latter e , the external environment, we have in this example
i <: e .
98 Types and behaviour in aPi
Life can get even more complicated; situations may arise in which the external
environment knows more than the internal environment.
Example 4.2 Consider the two processes
P ⇐ a(x)?R1
Q ⇐ a(x)?R2
and an observer trying to decide on the judgement
|= P ≈ Q
where allows a to read/write identifiers with write capability only. Here, a priori,
is both the internal and external environment.
As part of the investigation an observer may generate a completely new name
n, new to , with both read and write capabilities, and transmit it along a to the
observed processes, P and Q. The result now is that the external environment has
n with both read and write capabilities, while the internal environment only has it
with the write capability. We have e <: i .
These two examples indicate that to be completely general we need to develop
a theory of judgements of the form
e ; i |= P ≈ Q
where e and i are two consistent type environments constraining the observing
and the observed respectively. This is a rather daunting prospect. Instead we make
a choice and we make a choice to use one environment only. Moreover this lies
somewhere between e and i . We develop judgements of the form
I |= P ≈ Q (4.5)
where I is a type environment representing the observer’s current knowledge of
the declared capabilities of P and Q. We ignore everything else in the observer’s
environment, while the internal type environment i , will remain implicit; it will
periodically play a role. When making judgements of the form (4.5) it will for the
most part be assumed that there is some, unspecified, type environment i that
types P and Q. Moreover by careful development of the theory we will be able to
assume i <: I ; that is, despite Example 4.2, the observer’s knowledge is always
contained in that of the observed.
I P
where P is a process from typed aPi and I is a type environment such that i P
for some other type environment i such that i <: I ; we say I is compatible with
i . Since P is a closed term we can assume that both i and I do not contain any
variables.
Thus we define the judgements, called actions-in-context, which take the form
µ
I P −→ I P (4.6)
Notation 4.4
• We will use the complementary notation, µ introduced briefly in the proof of
Proposition 2.21, on these actions; as usual τ is τ itself, while (c̃ : D̃)a?V is (c̃ : D̃)a!V ,
and (c̃ : D̃)a!V is (c̃ : D̃)a?V .
• If µ is an external action, (c̃ : D̃)a!V or (c̃ : D̃)a?V , then (c̃) are the bound names of µ,
denoted bn(µ), while ch(µ) denotes the channel used in µ, namely a.
• As in Notation 2.12 we use αi , αo to range over all valid input and output labels
respectively.
The rules for generating these judgements are formally defined in Figure 4.1, for
the input and output actions, and in Figure 4.2 for internal actions. The first rule,
(l-in), allows the process a?(X ) R to input the value V , assuming the environment
4.1 Actions-in-context for aPi 101
has write permission on the channel a, that is the type I w (a) is defined, and the
value V is already known to the environment at a type suitable to be sent on a,
that is I V : I w (a); as indicated in Definition 3.25, we use I w (a)↓def to say
that the partial function I w is defined for a. The next rule, (l-weak), allows the
environment to invent new names to send to the observed process. For example
suppose n is a fresh name. Then this rule means
(n:D)a?n
I a?(x) R −−−−→ I , n : D R{|n/x|}
for any type D satisfying D <: I w (a), because
a?n
I , n : D a?(x) R −→ I , n : D R{|n/x|}
can be inferred from (l-in). Note that there are implicit side conditions in the rule
(l-weak), enforced by insisting that the rule can only be applied when the action
label in question, (n : D)αi is well-formed. For example if αi is (c̃ : D̃)a?V , in
order for the action label (n : D)αi to be well-defined, n must be different from
a and all the names in (c̃), and it must appear somewhere in V . So the rule can
only be applied in these circumstances. The explicit side-condition, that n be fresh,
might be automatically inferred from Barendregt’s principle but just to be safe we
mention it as part of the rule.
There are also two rules governing output. If I has read capability on the channel
a then (l-out) allows the process a! V
to output the value V on a; moreover the
observer obtains on V the capabilities determined by its read capabilities on a.
The extra knowledge gained is captured by extending the type environment with
V :I r (a)
. Note that the fact that I a! V
is a configuration ensures that the
augmented association list, I , V :I r (a)
, is a valid environment; see Question 3 at
the end of the chapter.
The second output rule, (l-open), allows the observed process to export new
names. For example suppose the channel a is known to the environment as one
102 Types and behaviour in aPi
from which values may be read at some type Cr , that is I r (a) is Cr . Then (l-open)
allows us to deduce
(b:D)a!b
I (new b : D)(a! b
| b?(x) R) −−−−→ I , b : Cr stop |b?(x) R
Note that the observer gains the new name b not at the declaration type D but at
its read type on the export channel a, namely Cr . Barendregt’s convention ensures
that b does not occur in I and therefore this action represents the export of a new
name to the environment.
Also, as with (l-weak), the rule (l-open) has extra implicit side-conditions. If
αo is the label (c̃ : D̃)a!V , then to ensure that the resulting label is well-defined n
must be different from a and all of (c̃), and must occur somewhere in V ; in addition
Barendregt’s convention ensures that n does not occur in I .
Finally in Figure 4.1 there is a straightforward contextual rule, with some explicit
side-conditions to ensure the proper functioning of free and bound names.
The rules for internal actions-in-context, in Figure 4.2 are also for the most part
straightforward; (l-rec), (l-eq) and (l-neq) are all borrowed from the reduction
semantics in Figure 2.4. So we concentrate on explaining the communication rule
(l-comm). Intuitively a τ action represents some internal communication, which
is therefore independent of the ability of an observer to see it happen. However to
make the definition of actions-in-context inductive in character we need to define
these in terms of observable input and output actions-in-context. For this reason, in
(l-comm) we allow the input and complementary output actions to occur relative
to arbitrary knowledge environments, I1 and I2 respectively. Note however that
in the conclusion the observer’s environment I does not change after the internal
action has occurred. This is in agreement with the intuition that internal actions are
independent of the observer; the rule is constructed so that if a process can perform
a τ action-in-context with respect to some environment I it can do so with respect
to any environment; see Corollary 4.13. Note also that the sender and receiver do
not a priori have to agree on the declaration types of the newly generated channels.
Finally let us point out that there are some alternative formulations we could
have used in the presentation of these rules. For example instead of (l-in) we could
have:
(l-in )
I a : w T
I V :T
a?V
I a?(X ) R −−→ I R{|V/X |}
4.1 Actions-in-context for aPi 103
a!V
I a! V
−
−→ I , V :T
stop
This of course implies (l-out) as the type T may be chosen to be I r (a) but in
general allows many more actions to be derivable. However the extra actions
are not of great interest as they simply consist in exporting V at supertypes
of I r (a).
The remainder of this section is devoted to a detailed analysis of actions-in-
context, and their properties. For example, although we have given rules for the
deducing actions-in-context (4.6) as of yet we have no guarantee that the residual
I P is a valid configuration, even if I P is; indeed we need to develop a
considerable number of consistency results about these judgements before being
able to prove so. In order to give the material some structure we divide it into
three convenient subsections. Throughout these it will be very convenient to have
a simple criteria for ensuring that an extension of a valid environment is again a
valid environment; if I env, when can we be sure that I , V :T
is also a valid
environment? A sufficient condition is given in the following:
Lemma 4.5 Suppose <: I are two valid environments, and (ñ) are fresh names.
Then , ñ:D̃
V : T implies I , V :T
env.
Definition 4.6 (action residuals) The partial function after from type environments
and typed action labels to type environments is defined as follows:
• I after τ is always defined to be I
• if µ is the input label (c̃ : D̃)a?V then I after µ is always defined to be I, c̃:D̃
, where
each ci is new to I
• if µ is the output label (c̃ : D̃)a!V then I after µ is defined to be I, V :I r (a)
, whenever
this is a valid environment; again here we assume that each ci is new to I.
104 Types and behaviour in aPi
µ
Proposition 4.7 Suppose I P −→ I P is an action-in-context. Then (I after µ)
is a well-defined environment and coincides with I .
µ
Proof: By induction on the inference of I P −→ I P , and an examination
of the last rule used. Note that we can ignore the case when µ is τ , as the result is
trivial.
As an example suppose the last rule used is (l-out). Then I a! V
is a
configuration and I r (a) ↓def ; we have to show that I , V :I r (a)
env. This
will follow from Lemma 4.5 if we can find a valid type environment <: I such
that V : I r (a).
Since I a! V
is a configuration we know there is some type environment
i <: I such that i a! V
; this is the required . For we know there is some
type T such that i V : T and i a : w T
. Also i <: I implies that i a :
r I r (a)
. So from part (ii) of Proposition 3.26 we have that T <: ir (a). Therefore
(subsumption) from the same proposition gives the required i V : I r (a).
All other cases are considerably simpler, and left to the reader.
to simply
µ
I P −→ Q
µ
Further we will write P −→ Q to mean that there exists some I such that
µ
I P −→ Q.
µ
The notation P −→ Q may seem like odd notation but it simply indicates that P,
under the right external circumstances, has the ability to perform the action µ. The
right external circumstances, necessary to allow the action µ to happen, is also
easy to define.
4.1 Actions-in-context for aPi 105
Definition 4.9 (allowing actions) We define the partial predicate allows between
environments and action labels as follows:
• I allows τ is always true
• I allows (c̃ : D̃)a?V is true whenever I w (a) is defined and I, c̃:D̃
V : I w (a)
• I allows (c̃ : D̃)a!V is true whenever I r (a) is defined.
As usual here, as we view ci as bound variables, the implicit assumption is that they
are new to I .
The next result states that if a process P has the ability to perform an action and
the environment I allows the action to happen, then the action can occur in the
configuration I P:
µ
Proposition 4.10 Suppose I1 P −
→ Q. Then
• I1 allows µ
µ
• if I2 allows µ then I2 P −
→ Q, whenever I2 P is a configuration.
Proof: The first result is again a simple proof by induction on the derivation of the
µ
judgement I1 P −→ Q. So we concentrate on the second. Suppose
µ
I1 P −→ Q (4.7)
• Suppose (4.7) is inferred using (l-in). This case is straightforward. We know µ has
the simple form a?V , and the hypothesis, I2 allows µ, means that I2w (a) is defined
and I2 V : I2w (a) is precisely the premise required to apply (l-in) to obtain the
required
µ
I2 P −→ Q
• Suppose (4.7) is inferred using (l-out). Here µ has the form a!V , P is a! V
and
the hypothesis is that I2r (a) is defined. The crucial point here is that I a! V
is a
configuration, and we repeat the argument already used in the proof of Proposition 4.7.
There is a type environment i <: I such that i a! V
. From the former we can
deduce that i a : r I r (a)
, and from the latter we have i a : w T
for some T such
that i V : T. The second part of Proposition 3.26 ensures that T <: I r (a), and then
(subsumption) gives i V : I r (a). Once more Lemma 4.5 ensures that I, V :I r (a)
is a valid type environment. This means that (l-out) can be applied to deduce the
required
µ
I2 P −→ Q
106 Types and behaviour in aPi
• All of the inductive cases are straightforward. We examine one instance, when (4.7) is
inferred using (l-weak). Here µ has the form (n : D)αi where αi is an input action label
(c̃ : D̃)a?V and the action has the form
µ
I1 P −→ Q
because
αi
I1 , n : D P −→ Q (4.8)
The hypothesis, I2 allows µ unravels to the assumption that I2w (a) is defined and I2 , n :
D, c̃:D̃
V : I2w (a).
We turn this hypothesis into a statement about the environment (I2 , n : D). Since the
action label is well-defined n must be different from a and so (I2 , n : D)w (a) is exactly
the same as I2w (a). In other words we have that (I2 , n : D)w (a) is well-defined and
(I2 , n : D), c̃:D̃
V : (I2 , n : D)w (a); that is (I2 , n : D) allows αi . So we can apply
induction to (4.8) to obtain
αi
I2 , n : D P −→ Q
An application of (l-weak) now gives the required conclusion.
µ
The fact that the derivation of the actions-in-context I P −→ Q depends
on specific information present in I means that they are preserved by various
manipulations on I . We give two examples in the next result.
and , X :Tr
R; the former gives our first requirement, that r (a)↓def .
Here ( after µ) unravels to , V : r (a)
and so let us assume that this is a
well-defined environment. Since r (a) <: Tr this means ( after µ) V : Tr .
Then by (weakening) we have after µ, X :Tr
R and so the substitution
result, Proposition 3.9 adapted to capability types, gives the required after
µ R{|V/X |}.
Suppose (l-out) is the last rule used in the derivation of (4.10). So the action is
a!V
I a! V
−
−→ I , V :I r (a)
stop
The typing rule (ty-out) from Figure 3.10 gives a type Tw such that a :
w Tw
, V : Tw ; again the first part implies w (a)↓def . Here ( after µ) is simply
and the contra-variance of w −
, together with the second part of Proposition 3.26,
therefore gives ( after µ) V : w (a), and we are finished, since trivially
( after µ) stop.
108 Types and behaviour in aPi
because
(c̃:D̃ )a?V
I1 P −−−−−→ I1 P
(c̃:D̃)a!V
(4.11)
−−−−→ I2 Q
and I2 Q −
a : w w (a)
, c̃:D
Q , V : w (a)
a : r r (a)
, V : r (a)
P , provided , V : r (a)
env
because
(c̃:D̃)a?V
−−−−→ I Q
I, b : D P − (4.12)
The inductive hypothesis applied to (4.12) gives the existence of (I , b : D)r (a).
But since a and b must be different this must coincide with I r (a).
Now suppose , V :I r (a)
is a well-defined environment. Once more, since
I (a) coincides with (I , b : D)r (a), we can apply the inductive hypothesis to
r
The second case, when n is not exported in αo is much more straightforward; P2
must have the form (new n : D) P2 and the output move must have been inferred
using (l-ctxt) from
αo
I2 P2 −→ P2
The required matching move may therefore be found by applying (l-com) to this
move and the corresponding input rule above, followed by an application of the
second part of (l-ctxt).
τ
Corollary 4.15 Suppose I P is a configuration and P −→ Q. Then I P −
→ Q
for some Q ≡ Q.
c! V
| c?(X ) R −→ R{|V/X |}
Since I c! V
|c?(X ) R is a configuration we know that there is some environment
i compatible with I such that i c! V
| c?(X ) R. This type judgement provides
enough information to establish the premises to applications of the rules (l-out)
and (l-in) from Figure 4.1, to conclude ensure that
c!V
i c! V
−→ stop
c?V
i c?(X ) R −
−→ R{|V/X |}
respectively. An application of (l-comm) from Figure 4.2 then gives the required
τ
I c! V
| c?(X ) R −→ stop |R{|V/X |}
112 Types and behaviour in aPi
respectively. Assuming some Ia that knows about the channel a at the type
rw (w, r)
, the configurations Ia P and Ia Q can perform different output
actions, labelled
(n : rw, m : rw)a!(m, n) (m : w, n : r)a!(m, n)
respectively. So a bisimulation equivalence based on these actions would
distinguish them.
However one can argue that no reasonable observer, constrained by the type
environment I , would be able to distinguish between these two processes. Both
deliver a new name on the channel a, and that is it. So although we have not yet
reformulated =∼ to take types into account, any reasonable formulation would result
in P and Q being considered indistinguishable.
4.2 Typed bisimulation equivalence 113
Basically the output actions, labelled with the declaration types of new channels,
are much too intensional.
Definition 4.19 (untyped output actions-in-context) For any set of names {c̃} we
write
(c̃)a!V
I P−−−→ I Q
(c̃:D̃)a!V
if there is some collection of types (D̃) such that I P −
−−−−→ I Q. As with all
action labels we make no distinction between the order in the bound names (c̃).
We let ≈bis denote the standard bisimulation equivalence in the resulting lts; thus
this is now a relation between configurations, rather than, as in Chapter 2, between
processes.
Example 4.21 Let us revisit Example 4.1 and the two processes
P1 ⇐ (new c : rw)(a! c
| c?P )
P2 ⇐ (new c : rw)(a! c
| stop)
As in the previous example, let Ia denote some type environment in which Ia (a) =
rw r
, and let us assume that Ia P1 and Ia P2 are both configurations. To show
Ia P1 ≈bis Ia P2
we need to exhibit a bisimulation R containing the pair Ia P1 , Ia P2
.
Let P1 , P2 denote the processes (stop |c?P ), (stop | stop) respectively and
Iac denote the type environment Ia , c : r. Then the required R consists of
Ia P1 ↔ Ia P2
Iac P1 ↔ Iac P2
This is easy to check as the only actions-in-context that can be performed by these
configurations are
(c)a!c
−−→ Iac P1
Ia P1 −
(c)a!c
−−→ Iac P2
Ia P2 −
Although in principle a bisimulation R may relate arbitrary configurations we will
only ever use them to relate configurations with identical knowledge environments.
A convenient way of specifying such restricted bisimulations is by defining a family
of relations R over processes, parameterised by type environments I , with the
property that whenever P, Q
∈ RI then both I P and I Q are configurations.
In this formulation we use the more suggestive notation
I |= P R Q (4.15)
to denote the fact that P RI Q, for a particular environment I .
Because of Proposition 4.7, the transfer property for bisimulations then amounts
to demanding that whenever (4.15) above holds then every action-in-context
µ
I P −→ P
must be matched by an action
µ̂
I Q =⇒ Q (4.16)
4.2 Typed bisimulation equivalence 115
(I after µ) |= P R Q
If we can show that each individual relation RI in the family, and its inverse, has
this parameterised transfer property, then we know from (4.15) that I P≈bis I Q;
continuing with our more suggestive notation we will write this as
I |= P ≈bis Q
(I after µ) |= P R Q
I |= P ≈bis Q (4.17)
Our results will largely depend on the (sanity checks) in Lemma 4.11. One would
not expect this relation to be preserved by increasing the environment’s knowledge
I . That is if Im <: I then one would not expect (4.17) to imply Im |= P ≈bis Q.
Example 4.21 provides an instance. With Ia (a) = rw r
we have
Ia |= (new c : rw)(a! c
| c?P ) ≈bis (new c : rw)(a! c
| stop)
Im |= (new c : rw)(a! c
| c?P ) ≈bis (new c : rw)(a! c
| stop)
I |= P R Q
I |= P R Q
(I after µ) |= P R Q (4.20)
follows because one can calculate that (I afterµ) ≡ (I1 afterµ), n : C. For example
if µ is the output action (c̃ : C̃)a!V then (I after µ) ≡ (I1 , n : C), V :I r (a)
.
But because of the freshness of n, I r (a) coincides with I1r (a), and so this latter
environment is equivalent to (I1 , V :I1r (a)
), n : C, that is (I1 after µ), n : C.
4.2.2 Compositionality
We wish to establish the compositionality principle (4.3) for bisimulation
equivalence:
and show that the result generates a bisimulation. There are at least two problems
here.
The first is exemplified by Example 4.18. We will never be able to show that
Ia |= (new n : rw) a! n
R (new n : r) a! n
(4.22)
The third clause in the definition of R only allows the same binding to be applied to
related processes. Although (4.22) is not a direct instance of the compositionality
principle it will arise in an analysis of the case when Q, in (4.21) above, is b?(x) a! x
Ia |= (new n : rw)(a! n
| stop) R (new n : r)(a! n
| stop)
because Ia , n : r |= a! n
≈bis a! n
.
Since each relation RI is symmetric it is sufficient to show how each action-in-
context from the left-hand side
µ
I (new 0 )(P1 | Q) −→ T (4.24)
can be matched, up to structural induction, by one from the right-hand side. First
consider the case when this is an external action, say an output (c̃ : D̃)a!V ; the case
of input is similar but more straightforward. This action must be the responsibility
of either P1 or Q, and again we look at the more complicated case, the former. So
(4.24) must take the form
µ
I (new 0 )(P1 | Q) −→ (new l )(P1 | Q)
such that
(I , I0 ) after α |= P1 ≈bis P2
Furthermore from (4.25) we know I allows α , and so Proposition 4.10 enables
us to obtain
α
I P2 =⇒ P2 (4.28)
120 Types and behaviour in aPi
Note that here the types of the exported names, (D̃ ), need not coincide with
those in αo . But this is irrelevant as a lookup of Definition 4.6 gives
(I , I0 ) after (c̃ : D̃ )a!V = (I , I0 ) after α
that is the form I , I0 , I1 .
An application of (l-comm) to the moves (4.30) and (ii) above, followed by
numerous applications of (l-ctxt) now gives, up to structural equivalence,
τ
I (new 0 )(P2 | Q) =⇒ (new 0 , 1 )(P2 | Q )
where 1 represents the environment c̃:D̃
.
One can then check that this is the required matching move since we have
accumulated all the information necessary to establish
I |= (new 0 , 1 )(P1 | Q ) R (new 0 , 1 )(P2 | Q )
To see this note that (I , I0 ) after α has the form I , I0 , I0 and so in this case we
can take the typed associations required in the definition of R to be (I0 , I0 ) and
the original and respectively. Then by subject reduction, Theorem 4.12,
we have
• , 0 , 1 P1 and , 0 , 1 P2
• (I, I0 ) after α Q , since we know (I, I0 ) Q
and the required compatibilities between the various type environments are easily
seen to be true.
Output from Q to P 1 : This case is similar, consisting first of a decomposition of
the move into the contributions from Q and P1 , finding a match to the latter from
P2 and a recomposition to obtain an internal move. The details are marginally
simpler as the types of the imported names do not change.
This result gives a very powerful proof principle for reasoning about bisimulation
equivalence ≈bis in a typed setting. Let us return to the discussion of Example 3.21
at the beginning of this chapter, and show that the results we have developed do
indeed support the informal reasoning outlined there. First note that it is trivial to
establish
client |= memSERV ≈bis stop
as the relation
client memSERV ↔ client stop
is a bisimulation; neither configuration can perform any action in context. Also
since client Client the compositionality principle immediately gives
client |= Client | memSERV ≈bis Client | stop
122 Types and behaviour in aPi
What we hope this chapter has demonstrated is that standard bisimulation theory
can be adapted to our version of aPi with capability types. But of course the
critique of bisimulation equivalence given in Section 2.5 applies equally well
in the presence of types. To what extent is typed bisimulation equivalence an
appropriate behavioural equivalence for typed aPi?
It is possible to develop a typed version of reduction barbed congruence, from
Section 2.5, and the inadequacies of bisimulation equivalence with respect to this
touchstone equivalence demonstrated there carry over to the typed case. However
we can also develop a typed version of asynchronous bisimulations to overcome
these inadequacies. But we postpone this discussion until Section 6.7, where it is
examined in a distributed setting.
4.3 Questions
µ
1. Suppose I P −→ I P .
(i) If µ is the input label a?V , prove
• fn(P ) ⊆ fn(P) ∪ n(V ).
(ii) If µ is the output label (c̃ : D̃)a!V , prove
• fn(P ) ⊆ fn(P) ∪ bn(c̃)
• n(V ) ⊆ fn(P) ∪ bn(c̃).
(iii) If µ is τ then fn(P ) ⊆ fn(P).
2. Suppose 1 , 2 are two valid capability type environments, such that 1 <: 2 , and
suppose that (ñ) are fresh. Prove
(i) 1 , ñ:D̃
V : T implies 2 , V :T
env
(ii) 1 , ñ:D̃
<: (2 , V :T
).
3. Use Question 2 to prove that if I a! V
is a valid configuration and I r (a)↓def , then
I, V :I r (a)
is also a valid configuration.
This means that when the rule (l-out) from Figure 4.1 is applied to a valid configuration,
the conclusion is also a valid configuration.
4. Suppose Im <: I, where (Im after µ) is defined, and I allows µ. Prove that
(i) (I after µ) is also defined
(ii) (Im after µ) <: (I after µ).
4.3 Questions 123
(I after µ) |= P R Q
Here Aga and Agb represent two mobile agents currently residing at the domain l
that contains the three local resources, r1, r2 and r3 that they may use to interact.
A distributed system may then be viewed as a collection of these independent
domains. A typical example, consisting of three domains named s, k and l, is
given in Figure 5.1. Here there are five agents distributed through the domains,
Sa, Sb, A, R, S, and five local resources, a, b at domain s, e at k and c, d at l.
We use aPi to describe these mobile agents, although we require a new primitive
to enable migration between domains. Thus we augment aPi with the construct
goto l.P
If the agent goto l.P is currently residing at k it can migrate to the domain l and
continue there with the execution of P.
To keep the language basic we have an extremely primitive notion of local
resource, simply locally declared channels; thus throughout this chapter we will use
resource and channel interchangeably. Then an agent currently residing at domain l
may use the channels declared locally at l to communicate; referring to the diagram
above, these would be channels named r1, r2 and r3. When an agent migrates to
124
A distributed asynchronous pi-calculus 125
another domain k these resources at l are no longer available for it to use; of course
it may subsequently migrate back from k to l and then they become available once
more. More sophisticated notions of local resource need to be programmed in terms
of these local channels. For example if the domain l wishes to offer a service for
testing primality, as described in Example 2.10 then it would declare a local channel
called inp , start the agent primeS running locally, and distribute to its clients the
write capability only on its local channel inp . Retaining the read capability on the
local inp ensures the integrity of the service.
Also for simplicity we assume that the structure of domains is flat, that is there are
no subdomains. However domains can be declared dynamically and knowledge of
domains may be transmitted between agents along channels. Since the language is
typed we need to introduce a new class of types for locations. These types describe
the resources available at a location, together with the types at which the resources
may be used. Thus the general form of a location type is
loc[c1 : C1 , c2 : C2 , . . . , cn : Cn ], n ≥ 0
If the name of a domain is received at this type then any one of the channels c1 , . . . , cn
located there may be exercised with the associated capabilities C1 , . . . , Cn . For
example a domain named m to be used to host a memory cell, along the lines of
that described in Example 2.11, could be declared with the type
loc[put : rw Cp
, get : rw Cg
, kill : rw Ck
] (5.1)
where Cp , Cg , Ck represent the capabilities allowed on the values transmitted by
the located channels put, get, kill. The domain m could have in permanent residence
126 A distributed asynchronous pi-calculus
an agent whose task would be to service calls on these resources; this agent would
be defined as an elaboration on Example 2.11.
Knowledge of m may now be distributed via supertypes of the declaration
type (5.1) above. The general rule determining the supertype relation over location
types is given by
loc[c1 : C1 , c2 : C2 , . . . , ck : Ck , . . . , cn : Cn ] <: loc[c1 : C1 , c2 : C2 , . . . , ck : Ck ]
where k ≤ n and Ci <: Ci for each i between 1 and k. Thus an agent may know only
a subset of the resources available at a domain, and may have limited capabilities
at these resources. So, for example, the name m of the domain hosting the memory
cell could be distributed at the type
loc[put : w Cp
, get : w Cg
] (5.2)
to the clients of the memory, and at the type
loc[put : r Cp
, get : r Cg
, kill : rw Ck
]
to the manager.
Individual resources or channels at a domain m may also be transmitted between
agents. However in aDpi it is important to realise that all channels are located. Thus
in general they are represented by compound names of the form
c @k
where k is the name of a domain and c is the name of a resource located there. So,
for example, when a client sends a reply channel to a memory cell, the name of
this reply channel is now a compound name, r @k, representing the channel named
r located at the domain k. Of course the use of these compound values in turn leads
to a new kind of type, that of located channel types.
The ability of channels to transmit compound names means that we have to
extend the definition of transmission types, the types at which values may be sent
and received, to include appropriate types for these structured values. Since domain
names may also be transmitted, we must also include location types. For example a
manager of a suite of memory cells, distributed throughout various domains, may
maintain a broadcasting agent that informs clients of available cells. At a particular
point in time this agent could contain the code
. . . outcl ! mi
. . .
where mi is a domain hosting a cell. The declaration type of the channel outcl would
now be of the form rw M
, where M represents the type (5.2) above.
A priori sorting out the exact nature of what values may be transmitted, and
how, looks complicated. However we show that an extension of the type system
5.1 The language aDpi 127
of Section 3.4 can be used in a natural manner to control the behaviour of agents.
In effect these types enable system designers to specify access control policies for
domains.
The elaboration of the language aDpi and its associated type system is the
subject of this chapter. Later, in the following chapter, we will also see that a
typed behavioural equivalence can be developed for the resulting typed language,
and moreover this can be justified contextually.
The constructs for the testing of identifiers, parallel composition and recursion
are as before, in aPi.
Example 5.1 [A Distributed Compute Server] Let us reconsider Example 2.10 in
which a service of testing for primality is considered. In aDpi this service has to be
located in some domain, say s, and therefore takes the form
sDprimeS
where DprimeS is the agent maintaining the service. This agent requires an address
to which the result is to be returned and in aDpi this means both a location and a
channel at that location. In other words the agent needs to be sent
• the value to be tested, an integer
• and a located resource name c@h, an address, where the result is to be sent.
if, as already suggested in Section 2.2, the language were augmented with a
construct let x = e1 in e2 for explicitly sequencing computations.
A client generates a new reply channel at its current location, sends an agent to
the service domain with the required information and awaits a reply. Thus this takes
the form
hClient(v)
where the agent Client(v) is defined by
DisF(k1 , b, k2 , c) ⇐ goto k1 .
rec z. b?(x, y) goto k2 .(new ack)(c! x, ack
| ack?goto k1 .(y! | z))
The agent first goes to the source site k1 and installs a recursive agent. From the
local source channel b it inputs the value to be forwarded, bound to x, and an
acknowledgement channel, bound to y. It then migrates to the second site k2 ,
generates a new acknowledgement channel ack that it transmits, together with
the value x, to the target channel c at k2 . It waits at the delivery site, k2 , for the
acknowledgement; when it arrives the agent returns to the source site k1 where in
turn it delivers its acknowledgement on y and awaits a new message on the source
channel.
The language aDpi inherits from aPi all the standard notational conventions, the
notions of free and bound variables and names, capture-avoiding substitutions and
α-equivalence. However, as we have seen in the introduction to this chapter, channel
names can appear in (location) types. This must be taken into account in the formal
definitions of the function for calculating free and bound names, fn(−), bn(−)
respectively, when applied to terms in aDpi. So for example in these definitions
applied to processes we have clauses of the form
5.1 The language aDpi 131
where n(D) denotes the names that occur in the type expression D; this will be empty
unless D is a location type. A similar definition applies to system level terms, but
there is a subtlety associated with the, as of yet unexplained, scoping mechanism
(new e : D) M at the system level; this will be elaborated on below, in (5.4). We
will use the word system to denote a closed system term, that is a system term that
contains no free occurrences of variables. We will use the word process and agent
for closed process terms.
The reduction semantics is similar in style to that of aPi, and uses a structural
equivalence ≡ to factor out inessential details in the syntax. The reduction relation
is defined to be the least contextual relation between systems
M −→ N
that satisfies the rules in Figure 5.4. Note that the definition of contextual in
Definition 2.5 can be applied to systems, as they have both a parallel constructor
− | − and a new name constructor (new e : D)(−). The axioms (r-eq), (r-neq),
(r-str) and (r-unwind) are taken directly from the reduction semantics for aPi,
but now apply to located processes; the structural equivalence used in (r-str) is
inherited from aPi, although there is a complication involving bound names; this
will be explained presently.
The rule (r-comm) is also inherited from aPi, although note that the
communicating agents are obliged to be at the same location. Thus in aDpi
132 A distributed asynchronous pi-calculus
k goto l.P −→ l P
accounts for migration. Note that migration is at the level of agent rather than
domain. In fact the latter would not make any sense in view of the flat structure of
domains.
Finally the creation rules allow us to export names declared by an individual agent
to the system level. The rule for exporting domain declarations, (r-l.create), is
straightforward; k (newloc l : Dl ) (R) evolves to (new l : Dl ) (k R). This may
seem an innocuous move, but the code R may now send an agent to the new
location, to install resources and run processes there. For example if R has the form
(P | goto l.Q) then we will have the reductions
where now the residual P running at the original k can broadcast the existence of
the new site l, and its resources; moreover the code Q has been installed at the new
site to service these resources. This is such a natural manner for generating new
locations that we introduce a specific notation for it.
The rules for creating local channels are similar. But note that in (r-c.create),
when the new channel c of type Dc , local to k, is exported to the system level, its
location has to be noted; the name c created locally at site k is referred to globally
as c@k. In other words at the system level we have simple names, k referring to
locations, and located names, c@k, referring to actual located channels or resources.
In future we use the meta-variable e to range over the corresponding compound
values, which may be simple values v, or located identifiers u@w where both u and
w are simple identifiers, that is either names or variables; so when variables are not
involved, these compound values are either simple names or located names.
There is a subtlety involved in the use of these located names. In the system
(new c@k:Dc ) (M ) only occurrences of c in M are bound; the location name k
5.1 The language aDpi 133
is simply used as a tag, to denote where this private resource c exists. So when
extending the notions of free and bound names to systems we must have the clauses
bn( (new c@k:Dc ) M ) = {c} ∪ bn(M )
(5.4)
fn( (new c@k:Dc ) M ) = ({k} ∪ fn(M ) ∪ n(Dc )) − {c}
The corresponding clauses for the other kind of name declarations are as discussed
above in (5.3).
These located names also have an effect on the definition of structural equivalence
between systems. As with aPi this is defined to be the largest contextual
equivalence that satisfies a set of axioms. These are given in Figure 5.5, and are
modelled directly on those for aPi in Figure 2.3. But note that now in (s-extr) we
have to be careful about the actual name being extruded; here bn(e) refers to c if e
is the located name c@k and otherwise is e itself. So for example, assuming there
is no occurrence of c in P,
(new c@l : Dc )(l P | k Q) ≡ l P | (new c@l : Dc ) k Q
Similarly in (s-flip) we have to make sure that the role of scoped names does not
become confused. For example
(new k : Dk ) (new c@k : Dc ) M ≡ (new c@k : Dc ) (new k : Dk )M
because k is contained in c@k. The side-conditions placed on (s-flip) are a slight
generalisation of those used for typed aPi, discussed on page 61. Recall that types
may now contain names, and therefore we need also to ensure that the bound names
bn(e1 ), bn(e2 ) do not appear in the types D2 , D1 respectively.
Let us now look at some examples of the use of this reduction semantics; as usual
we will sometimes elide the actual types of bound names; indeed we continue to
do so throughout the chapter unless they are relevant to the discussion at hand. The
subject of the types required for bound names will be taken up in Section 5.2.
Example 5.5 Let us examine the possible reductions from the system
sDprimeS | hClient(11)
where the agents DprimeS and Client(11) are defined in Example 5.1.
134 A distributed asynchronous pi-calculus
These are two independent agents, each in evaluation contexts, and therefore are
subject to any of the applicable rules in Figure 5.4. For example the rule (r-unwind)
can be applied to sDprimeS and we get the reduction
sDprimeS | hClient(11)
−→ (5.5)
sinp ?(x, y@w) (DprimeS | goto w.y! isprime(x)
) | hClient(11)
The server is now in a stable state, waiting on input at the port inp .
The client on the other hand needs first to extrude the new reply channel, using
(r-c.create):
The client is now ready to send the requesting agent to the server. But in order
to formally derive the reduction we need to use the structural equivalence to re-
arrange the system so that the relevant axioms can be applied. We have already seen
numerous instances of these re-arrangements in aPi, all using suitable applications
of the extrusion axiom (s-extr); for one example see Example 2.9.
First note that
because of the rule (s-extr); r does not occur free in h. . .. Therefore applying
the rule (r-str) to the last reduction we obtain
thereby isolating the agent, currently at h, which is about to move. Applying this
reduction in context we obtain the third reduction step:
(new r @h : Dr )( sinp ?(x, y@w) . . . | hr?(x) print! x
| goto s.inp ! 11, r @h
)
−→ (new r @h : Dr )( sinp ?(x, y@w) . . .|
hr?(x) print! x
| hgoto s.inp ! 11, r @h
) (5.7)
Here the migration of the agent may be derived using (r-move):
hgoto s.inp ! 11, r @h
−→ sinp ! 11, r @h
and applying this in context, together with an application of (r-str), gives
(new r : Dr @h)(sinp ?(x, y@w) . . . | hr?(x) print! x
| hgoto s.inp ! 11, r @h
)
−→ (5.8)
(new r : Dr @h)(sinp ?(x, y@w) . . . | sinp ! 11, r @h
| hr?(x) print! x
)
We now have at the server site s
• an agent who wishes to transmit a message along the local channel inp
• and an agent who is willing to service this message.
The axiom (r-comm) may be used to obtain
sinp ?(x, y@w) . . . | sinp ! 11, r @h
−→ sDprimeS | goto h.r! isprime(11)
For variety let us use (r-split) on the resulting system, to obtain
sinp ?(x, y@w) . . . | sinp ! 11, r @h
−→−→ sDprimeS
| sgoto h.r! isprime(11)
Now there is a local communication possible at h, along the reply channel r. From
(r-comm) we obtain
hr! true
| hr?(x) print! x
−→ hprint! true
that in context gives the reduction
(new r @h : Dr )(sDprimeS | hr! true
| hr?(x) print! x
)
−→
(new r @h : Dr )(sDprimeS | hprint! true
)
However the channel name r does not appear free in the code DprimeS, or in the
code at h and so using the derived structural equation
(new e : D) N ≡ N if bn(e) ∈ fn(N )
similar to that discussed in Example 2.9, and an application of (r-str) we obtain
the final reduction
(new r @h : Dr )(sDprimeS | hr! isprime(11)
| hr?(x) print! x
)
−→ (5.11)
sDprimeS | hprint! true
where m is the location of the cell and LMem is the code running there. This is
much the same as the code Mem from Example 2.11 except that now the locations
of the methods must be catered for:
LMem ⇐ (newc s : S) (s! 0
| a? (newc r : Dr ) ( m.get! r @c
| r?(x) print! x
)
The reduction semantics can be applied to the system
mLMem | cClient
and many different sequences of reductions are possible. But the variations are
minor. All will involve four applications of the axiom (r-comm), two at the
memory site m and two at client site c. They will also require four applications
of (r-move), two in each direction, together with some house-keeping moves
involving (r-c.create), (r-split) and (r-unwind). There is some variation in
the sequence of application of these rules but all sequences will eventually end in
a system structurally equivalent to
mLMem | cprint! 4
Although the mobility construct of aDpi, goto k.P, is elementary it can be used
to describe more complex frameworks, such as code servers that on request will
initialise code at different locations. A typical generic example is given by:
serverinit?(x, y) goto y.code(x)
Here code(x) represents some general useful code, with some initialisation
paramater x. The code server, located at server receives requests at init, which
expects to receive some initialisation data say n, to be bound to x, and a location k,
138 A distributed asynchronous pi-calculus
to be bound to y. It spawns an agent that migrates to k and runs the intialised code
code(n) there.
Of course to be useful this server must be able to respond to repeated requests.
This is easily achieved, by transforming the body into a recursive agent. We pursue
this idea in the following example.
Example 5.7 [A Located Memory Server ] Let us now see how to describe a
distributed version of the memory service described in Example 3.15. We will
in fact see two versions.
The server takes the form
sLmemS (5.12)
where LmemS is the code assuring the service. The server location s contains a
request channel req where requests are received. A client sends a reply address, a
located channel, the server generates a new located memory cell, using the code
of the previous example LMem, and delivers the new location name at the reply
address:
A system containing the server and two clients takes the form
A client generates a new reply channel, sends a request to the server, for which it
needs to know the address of the server, the location s and the appropriate method
there req, and awaits for the server to deliver the location of the new memory cell.
The reduction semantics, including a judicious use of the structural equivalence,
can be used to deduce a derivation from the system (5.13) to the system
There are a number of points worth making about this system. First the type system
needs to ensure that friends of, say the first client, who have gained capabilities
on the instances of put and get at m1 cannot use these capabilities at m2 . Also
the form of the resulting system (5.14) indicates that Clienti has control over
knowledge of its respective memory mi . By extending the capability based type
system of Section 3.4 to aDpi we can ensure that these clients can selectively
distribute restricted capabilities on their own memory cells.
5.2 Access control types for aDpi 139
Also the methods put and get now exist at two separate locations, m1 and m2 .
The type system will allow such use of method, or resource, names. Here the server
ensures that they are declared with the same type but a priori our typechecking
system will not impose any type consistency between the various instantiations of
a resource name at different locations. This question will be addressed in Section 5.5.
The server we have defined, in (5.12) above, has the responsibility to generate
the location of the memory cell. An alternative strategy would be for the clients
themselves to generate the site, send the name to the server, who then installs the
appropriate servicing code at the proffered site. Here the server code, running at
the server site s, takes the form
Clientbisi ⇐ (newc a : Da )
(newloc m : M) with s.req! (mi , a@ci )
in a? Ci (m)
A client, such as
c1 Clientbis1
This of course immediately leaves the newly created site to deliver a request to the
server. Meanwhile at the client’s site c1 an acknowledgement is awaited from the
server that the servicing code has been installed at m1 .
Once more the reduction semantics can be used to reduce the system
The subtyping relation between types is a direct generalisation of that used for
aPi. The defining rules are given in Figure 5.7 and are a natural extension of those
in Figure 3.7 for aPi types. As already mentioned in the introduction the main new
rule pertains to location types. Whenever k ≤ n, and Ci <: Ci for each i between
0 and k, we can conclude
loc[a1 : C1 , . . . , an : Cn ] <: loc[a1 : C1 , . . . , ak : Ck ]
Note that this implies L <: loc for every location type L. The relation is extended
to global channel types homomorphically with the rule (sub-hom).
Definition 5.8 (capability types for ADPI) We define the capability types for aDpi
to be the set of all T such that
T <: T
can be derived using the subtyping rules, given in Figure 5.7. We reuse Types for
this set of valid types, and will also use the notation T : ty to denote the fact that
T is a valid type.
The join operation, total on location types, is defined in a slightly different manner;
K L is given by
loc[c1 : D1 , . . . , cm : Dk ]
where this time c1 , . . . , ck , . . . , cm is the set of names that appear in both a1 . . . an
and b1 . . . bn and for which the corresponding type Dk exists; if ck = ai = bj then
Dk is taken to be Ci Cj .
So for example if K, L are
loc[a : w int
, b : w bool
] loc[a : r int
, c : r bool
]
loc[a : rw int
, b : w bool
, c : r bool
] and loc[]
M
where M is a system term and a type environment. Here type environments are
more complicated, which is not surprising in view of the range of roles declared
names may play. The main added complexity stems from the fact that some
names only have local significance, those used for resources, while others, those
used for locations, have global significance. Consequently we need to introduce
some additional notation, which at first sight may seem unnecessarily tedious.
However we will quickly develop some conventions that will tame the added
complexity.
5.2 Access control types for aDpi 143
Again type environments are lists of associations between identifiers and types,
and the following forms are allowed:
• u : loc, indicating that u is the name of a domain
• u@w : C, indicating that the identifier u, used at the domain w, represents a resource at
type C there; these are local channel type associations
• x@w : proc, indicating that the variable x is used in the definition of a recursive process,
running at location w
• x : base, indicating that the variable x is to be bound to a base value of type base.
It is important to note that in u@w : C both u and w may be identifiers; both may
be either names or variables. These will be essential to type systems such as
Here we will eventually end up typing the body x?(z) P relative to an environment
with the associations x@y : C, and y : loc.
As with aPi, it is convenient to have an extra meta-variable for the class of types
that can appear in these new environments; we re-use that employed in Chapter 3:
e1 : E1 , e2 : E2 , . . . , en : En , n ≥ 0
w V :T (5.16)
and are designed so that they can only be inferred when w is known in to be a
domain name. But, as we shall see, in many cases the actual location w may be
omitted from these judgements.
First let us consider the rules for valid environment formation. Recall that for
typed aPi, because of our view of types as capabilities, we allowed multiple entries
for a given identifier, provided all the entries were consistent. Here we carry over
this idea, but now consistency will in general be relative to a specific location.
Definition 5.10 (local consistency) Let ↓w u : E denote the fact that for every
type E , w u : E implies E ↓ E.
144 A distributed asynchronous pi-calculus
As we shall see for many types, in particular location types, this predicate is
actually independent of the particular location w, and therefore it will often be
omitted.
The rules for constructing new environments are given in Figure 5.8, although the
base case, (e-empty) from Figure 3.3 is omitted. It will be technically convenient
to allow multiple entries of location name declarations, and variables of base type.
This is allowed by the rules (e-loc) and (e-base), where the side-conditions use the
notation just introduced. Also note that the rule for introducing recursion variables,
(e-proc), ensures that these are declared at a specific location. The rule for adding
local channel names is very natural. To add the entry u@w : C we have to ensure w
is actually a location, and that the type C is consistent with all existing entries for
u at the proposed location w, that is ↓w u : C.
The rules for type assignment to values are given in Figure 5.9, and many
are adapted directly from Figure 3.9, the corresponding rules for aPi, to take
5.2 Access control types for aDpi 145
into account the fact that judgements are now local to a particular domain. The
environment look-up rule from there, (ty-sub), now has four different versions
depending on the type of the identifier in question. The first two, (ty-c.sub)
for channels and (ty-proc.sub) for recursive definitions, are local. The slightly
artificial rule (ty-loc.sub) for locations is required in order to be able to apply
the global rule (ty-g.sub); because of our constraints on environment formation
this can only be used when E is either a base type, or the degenerate loc. The new
rule (ty-loc) is used to assign a location type K = loc[a1 : C1 , . . . an : Cn ] to
an identifier, while (ty-located.channel) is the obvious rule to assign a global
channel type to a located identifier. Notice that in both these new rules w, the location
at which this typing is inferred, plays a limited role. This is true of many types in
the judgements (5.16) above, and we will call such types global; specifically value
types of the form base, K and C@loc are said to be global, while a transmission
type T is global if all of its components are global. We leave the reader to check
the following simple observation:
Lemma 5.11 If T is a global type then w V : T implies w V : T for every w
such that w : loc.
It is worthwhile comparing this definition with the corresponding one for aPi,
Definition 3.2. Here we need the extra parameter, a location w, which is actually
only used in the case of a (local) channel type C. In addition we need two new
cases, for location types, and for located identifiers. But note that for global types,
as we have defined above, w plays no role. For such types we will often abbreviate
V :T
@w to simply V :T
. Indeed this global notation may be further extended by
letting u@w:C
be the singleton list, u@w : C. In this way we will have a way of
constructing a type association list e:D
for every name creation (new e : D)(−)
allowed in well-typed aDpi systems; this notation will be used extensively in the
following chapter.
But again note that these lists, both located and unlocated, are only defined if the
structure of the value V matches that of the type T, and in many cases the result is
not a valid environment; for example in the case for tuples the different components
may add conflicting information about an identifier to the list. However, there is
a simple criterion for being able to extend well-defined type environments with
these lists, at least in the case of simple values; this is a generalisation of the rule
(e-chan) from Figure 5.8.
Lemma 5.13 (extension lemma) Suppose env. Then ↓w u : D implies
, u:D
@w env.
Proof: If D is a local channel type this follows from (e-chan); so let us assume
it is the location type loc[c1 : C1 , . . . cn : Cn ]; we have to show , u : loc, c1 @u :
C1 , . . . , cn @w : Cn env.
5.2 Access control types for aDpi 147
5.2.3 Typechecking
At last we are in a position to give the typechecking rules for aDpi systems. As we
have already noted judgements are of the form
M
where is an association list and M a system; the inference rules are given in
Figure 5.10. These are designed so that such a judgement can only be inferred
when is a valid type environment and, as usual, they can only be applied to
systems M whose bound names do not appear in . The rule (ty-zero) says that
the empty system 0 is well-typed relative to any valid type environment . To
ensure the composite system M | N is well-typed, the rule (ty-con) dictates that
it is sufficient to infer that the individual components M and N are well-typed.
There are two different kinds of entities that can be declared globally for a system
and for the sake of clarity each has its own inference rule. First let us consider the
declaration of local resources, which is straightforward. According to (ty-cnew)
the system (new c@k : C) M is well-typed relative to ,
, c@k : C M
environment. It is also worth noting that, using the notation introduced on page 146
after Definition 5.12, these two rules can be subsumed by the more generic:
(ty-new)
, e:D
M
(new e : D) M
However for the sake of clarity, we have preferred to spell out the individual cases.
Finally, to typecheck the located agent k P relative to we use the rule
(ty-agent); this ensures that the agent it well-typed to run at k. Agents need to be
checked relative to locations because of the use of local channels. For example the
agent
c?(x) R
will only be well-typed to run at a location k if there is a local channel named c
declared at k. Thus for agents we require judgements of the form
w P : proc
indicating that P is well-typed to run at location w. An instance of this is used in
(ty-agent) to check that the located agent k P is well-typed.
So now let us turn to this typechecking of agent terms, relative to a location
w. The inference rules are given in Figure 5.11 and, although relativised to the
location w, have much in common with those for typechecking aPi, in Figure 3.10
and Figure 3.5. The rules (ty-stop) and (ty-par) are inherited directly while the
rules for input and output are minor variations. For example to infer
w u?(X ) R : proc
we must ensure that u is a channel declared locally at w, with an appropriate
capability,
w u : r T
w V :T
5.2 Access control types for aDpi 149
There are two rules for typing local declarations, (ty-cp.new), (ty-lp.new). We
have already discussed at length the corresponding rules at the system level, and
these are very similar. For example to typecheck
(newc c : C) R
relative to at the location w, we need to typecheck the process term R relative to
the extended environment , c@w : C. Because we are typechecking the process
to run at w the locally declared channel c is added to the environment with the
compound name c@w.
150 A distributed asynchronous pi-calculus
5.2.4 Examples
Throughout this section, and indeed for the remainder of the chapter we will
abbreviate the agent judgements w P : proc to simply w P.
As a first example let us consider how pattern matching, and the environment
construction mechanism given in Definition 5.12, plays a central role in
distinguishing between local and global channels.
Example 5.14 [Pattern Matching ] First suppose that 1 is a (valid) type
environment that contains the type association in@s : rw rw int
@s s x! 7
(5.18)
since, by (ty-c.sub) of Figure 5.9, 1 s in : r rw int
This in turn could only be inferred via (ty-out), which would require
1 , x@s : rw int
k x : w int
This of course is impossible, as x has just been established as a channel name local
to the original site at which it was received, s; as a bound variable in the system
being typed, x cannot occur in 1 .
Channels that are not local to the domain s can only be received at s as part of a
compound value. To see how these are typed let 2 be an environment such that
2 s in : rw rw int
@loc
and consequently (5.20) is easily derived using (ty-go) and (ty-out), as x has
been recorded as a channel located at y.
However channels can sometimes be assumed to exist by virtue of their
occurrence in a location type. To illustrate this consider a third environment 3
such that
3 s in : rw L
where L = loc[r : w int
]
Then
3 sin?(y) goto y.r! 7
can be established. The crucial step is to derive
3 , y:L
@s s goto y.r! 7
In the next example we examine the declaration of channels and see how the
typing system enforces the local nature of their use.
Example 5.15 (Local Channel Declarations) Consider the following system:
M1 ⇐ l (new c : rw int
) goto s.(c! 1
| c?(x) R)
An agent declares a channel c at the location l, migrates to s, and then tries to use
c at the new location. Intuitively there is something amiss here; c is declared to be
a resource available at l, but an attempt is made to use it at a different location.
152 A distributed asynchronous pi-calculus
But this is clearly impossible. We know c is fresh to , and so (ty-out) can never
be used here, since c only exists at the location l, and not s.
As a variation consider
M2 ⇐ l (new c : rw int
) goto s.in! c
and the type environment 1 used in the previous example; it has the type association
in@s : rw rw int
So inp is known to be a channel at the site s that can be used for both reading
and writing of pairs, the first of which must be an integer. A value at the type
w bool
@loc is a global channel along which may be sent a boolean; thus the value
will be a located name, of the form a@l, where a is located at l. To see how we can
derive the judgement
sDprimeS
let us work backwards through a derivation. This will follow from
s DprimeS (5.22)
using (ty-agent). To get to (5.22) an application of (ty-rec) to
, z @s : proc s inp ?(x, y@w) (z | goto w.y! isprime(x)
)
is required. Here we need an instance of (ty-in). From our assumption we know
that
s inp : r int, w bool
@loc
This judgement is an instance of (ty-c.sub) from Figure 5.9 and uses the
subtyping relation. Also Definition 5.12 can be applied to calculate the environment
(x, y@w):(int, w bool
@loc)
@s, giving
x : int, w : loc, y@w : w bool
that is one of the premises for an application of (ty-out) with (5.24) as a conclusion.
The other premise
, z @w : proc, x : int, w : loc, y@w : w bool
w isprime(x) : bool
154 A distributed asynchronous pi-calculus
But we have to decide on the type Dr for the generated reply channel. We have seen
that the server requires a write capability on any reply channel it receives while the
client reads from it. So we let
Dr = rw bool
We only consider the first of these, (5.26). As above we can deduce , via (ty-c.sub),
The rule (ty-go) may then be applied, to obtain the required (5.26).
Example 5.17 (Typing the Memory Cell) Here we examine what is required to type
the code for a memory cell
LMem ⇐ (new s : S)(s! 0
m put : r Tp
Note that the functionality of the code LMem is independent of its location, provided
that location hosts a declaration of put and get at these types.
In Example 5.6 we saw the behaviour of a typical client of a memory, residing
at the site c:
Client ⇐ (newc a : Da ) (m.put! 4, a@c
| a? (new r : Dr )(m.get! r @c
| r?(x) print! x
)
This generates two local channels, an acknowledgement channel a whose
declaration type should be
Da = rw
and an integer reply channel r whose declaration type is required to be
Dr = rw int
In each case the write permission is exported, to the memory, and the read permission
is retained by the client. So, to type the client code we need
c get : w Tg
c put : w Tp
c print : w int
provided that the locally declared names, a and r are declared at the types Da and
Dr respectively. Note that the client’s code requires not only the knowledge of the
server’s location, m, but also its own location c.
Example 5.18 [Typing the Located Memory Servers ] Let us consider the typing of
the memory services discussed in Example 5.7. First let us consider the minimal
requirements on req in order to be able to derive
req sLmemS | c1 Client1 | c2 Client2 (5.29)
where the code for LmemS and the clients may be found in Example 5.7. The
server, in response to a request, generates a new location m at type M and installs
the code LMem there. We have just discussed the typing of this code, and from this
discussion it should be apparent that the declaration type M should be
loc[put : rw Tp
, get : rw Tg
] (5.30)
where Tp and Tg are (int, w@loc) and w int
@loc respectively. Note that although
the server only uses the read capability on put and get, clients require the write
capability, and therefore both must be in the declaration type of m.
The clients generate return channels at type Dr on which the name of the newly
generated channel is to be sent. Therefore we need to set this declaration type to be
rw M
; again the clients only use the read capability but the sever uses the write.
The request channel req is a free name in the overall system, being read by
the server, and written to by the clients; it must therefore be assigned a type by
5.2 Access control types for aDpi 157
req . The values being transmitted on req are the return channels generated by the
clients. So one possibility would be for it to have the type rw Dr @loc
; note that the
transmission type is a global channel, as the return channel must be accompanied
by its location. But this is unnecessarily liberal, as the return channels will only
be written to by the server. So a sufficient type for req to have in req is the more
restricted rw w M
@loc
.
Summing up, we leave the reader to check that (5.29) can be derived whenever
• req req : rw w M
@loc
• the client code r?(x)Ci (x) is properly typed, that is req , x:M
ci Ci (x).
But there is a subtlety involved in establishing the judgement (5.29) above. The
names put and get are used both by the server, in the declaration type M of the
new locations, and the clients, in the declaration type Dr of the return channels.
These are completely independent systems and a priori could independently assign
conflicting types to these names. In Section 5.5 we outline an extension to our
typing system that will enable the consistency of resource types to be maintained
across different domains.
it is sufficient for req to have as an entry for the request channel req the type
rw M, w@loc
.
As a final example in this section let us re-emphasise the use of typed channels
to implement the selective distribution of capabilities, already touched upon with
aPi in Example 3.15.
where for convenience we ignore the presence of the actual server, and assume the
presence of friends bob and jane. Only c1 knows about the memory m1 , which it
158 A distributed asynchronous pi-calculus
uses in the code C1 (m2 ), while only c2 knows about m2 , which it uses in C2 (m2 ).
Let us see how bob and jane are informed aboout these new memories.
One possible instantiation of their respective codes is given by:
The channels xpti are used by the clients to inform bob and jane of these resources;
the first client exports the name of its private cell m1 to bob using xpt1 while the
second uses xpt2 to inform jane of m2 . Using the reduction semantics one can show
that Sys may evolve to
The question now is what resources at mi can bob and jane use in Sys1 ; that is
what resource access have they achieved at these sites?
This of course depends on the type environment used for (5.31). Here we assume
that M is the type
loc[put : rw Tp
, get : rw Tg
]
as discussed in Example 5.18, and let bj contain the entries xpt1 @bob : rw Mp
we are enforcing the access policy that bob has only write access on put at m1
and that jane has only write access on get at m2 . For example establishing (5.32)
requires, among other things,
bj , x:Mp
bob B(x)
that unravels to
Since x is fresh to bj , in the code B(x) the only resource available at the location
x is put, and this can only be used with the capability w Tp
.
5.3 Subject reduction for aDpi 159
This is not a major issue; computations are essentially carried out by agents and
therefore we concentrate on these judgements. In particular we need to develop
substitution results, similar to those in Proposition 3.9 for agents; these of course
will rely on similar results for values.
(2) Typing judgements for both agents and values are relative to locations, with judgements
of the form k P and k V : T respectively.
This means that our substitution results have to take into account both the location
of the judgement being made and the location of the value being substituted, which
may be different.
(3) (Interchange), as in Proposition 3.7, does not hold in aDpi.
Recall that for aDpi valid type environments can contain entries of the
form u : E or u@w : E, and consequently dom() will in general be a finite
set of compound identifiers. Nevertheless modulo this slight complication, the
interpretation of environments as functions from their domain to types given in
Definition 3.25 carries over. Extending the notation used there, we let {e}, for any
e in dom(), denote the non-empty set of types E such that e : E occurs in .
Lemma 5.21 Suppose env . Then
• e ∈ dom() implies {e} ↓
• u ∈ dom() implies u : ({u})
• u@w ∈ dom() implies w u : ({u@w}).
Proof: Note that here, in the second clause, we are using the abbreviated form of
typing judgements for global types, justified by Lemma 5.11, where the location
subscript is omited from typing judgements. If a simple identifier u is in dom(),
then it will have associated with it a global type; specifically this can only be loc
or a base type.
The proof is a straightforward adaptation of that of Lemma 3.24, to the notation
for located judgements.
The properties of value typing for aPi, given in Proposition 3.26, also generalise
in the natural manner:
Proposition 5.23 In aDpi
(i) u : A implies (u) exists, and (u) <: A
(ii) w u : C implies (u@w) exists and (u@w) <: C
(iii) w u : r T1
and w u : w T2
implies T2 <: T1
(iv) w V : T1 and w V : T2 implies T1 T2 exists and w V : (T1 T2 )
(v) (subsumption) w V : T1 and T1 <: T2 implies V : T2 .
Let us now check that apart from (interchange) most of the properties for
capabilities typing given in Section 3.4.3 carry over. As usual we will leave the
detailed proofs to the reader, and be content to lay down the sequence in which
5.3 Subject reduction for aDpi 161
the various results can be established. We adapt the method used to compare type
environments from the previous chapter, in Definition 3.27.
Definition 5.24 (comparing environments) For valid type environments let 1 <:
2 if for every identifier w, 2 w u : E implies 1 w u : E. As in Section 3.4 we
write 1 ≡ 2 whenever 1 <: 2 and 2 <: 1 .
To state uniformly results for both value and agent judgements, let us write w
J : G to denote either of these kinds of judgements, w V : T or w R : proc.
Then
Proposition 5.25
• (Weakening) w J : G and <: implies w J : G.
• (Environment strengthening) Suppose , e : E, env, where bn(e) does not occur in
. Then , env.
• (Strengthening) Suppose , e : E, w J : G, where bn(e) does not occur in , w, J
or G. Then , w J : T.
Proof: The proof of (weakening) is by rule induction, with a (long) case analysis of
the last rule used. That of (environment strengthening) is by induction on the size
of . The case when this is empty, the base case, is an instance of the first part of the
(sanity checks), Proposition 5.20 above. Otherwise it has the form , e : E and
again the (sanity checks) ensure that , e : E, env. So by induction , env.
We now have to argue that this can safely be extended by e : E . There are four
possible cases, and each in turn follows by virtue of the fact that , e : E, can be
safely extended by e : E . For example if e : E is u@w : C then we have to show
that if , w u : C then C ↓ C . But by (weakening) , w u : C implies
, e : E, , u@w : C w u : C and therefore the required C ↓ C follows from part
(iv) of Proposition 5.23.
Finally (strengthening) is once more a long rule induction proof, with the
various base cases, such as the application of (ty-c.sub), (ty-zero), relying on the
just established (environment strengthening). Let us examine one inductive case.
Suppose
, e : E, w (new c : C) R
because
, e : E, , c@w : C w R
Then we are assured that bn(e) does not appear in (, c@w : C), and therefore we
can apply induction to obtain
, , c@w : C w R
An application of (ty-cp.new) gives the required , w (new c : C) R.
162 A distributed asynchronous pi-calculus
Note that this version of (strengthening) is somewhat more general than that stated
in Proposition 3.30 for typed aPi; the generality means that it does not require any
interchange property.
As we have already indicated, we do not have an interchange law for typing
judgements. 1 , e1 : E1 , e2 : E2 , 2 w J : G does not necessarily imply 1 , e2 :
E2 , e1 : E1 , 2 w J : G because 1 , e2 : E2 , e1 : E1 , 2 may not be a valid type
environment. However there are certain constraints on e1 , e2 , which ensure that
they can be safely interchanged. One is given in the following lemma, although
there are valid exchanges not covered by it; see Question 6 at the end of the chapter.
Proof: The first result requires a tedious analysis of the possible forms of e1 : E1
and e2 : E2 ; in each case we have to first argue that , e2 : E2 env, and then argue
that it can safely be extended by the entry e1 : E1 . For example suppose e1 : E
is w : loc and e2 : E2 is u @w : C. Then since w must be different from w, the
reason for being able to safely extend , e1 : E1 with e2 : E2 , an application of
(e-chan), applies equally well to , and so we have , e2 : E2 env. The extension
to , e2 : E2 , e1 : E1 is now justified by an application of (e-loc).
The second result is a straightforward proof by rule induction, as typechecking
essentially still uses environments as lookup tables, despite the presence of multiple
entries for identifiers.
This exchange can be extended from single type association entries to the more
general extensions given in Definition 5.12; we confine our attention to the global
version of this notation.
Proof: A case by case analysis is required of the types Ai . The case when both
are channel types is covered by the previous proposition (partial interchange), and
when they are base types the proof is straightforward. The non-trivial case is when
either are location types. The requirement that bn(e1 ) occurs neither in e2 nor in
the type A2 , ensures that even in this case (partial interchange) can be applied;
in general multiple applications will be required.
These permitted forms of interchange are not sufficiently general to allow the
straightforward transfer of the substitution results from aPi to aDpi. But they
5.3 Subject reduction for aDpi 163
Let us now turn our attention to the substitution results, which are a central
component of subject reduction. As we have already explained these will be
somewhat more complex than for aPi, because of the lack of (interchange). The
complexity occurs because we have to consider not only substitutions into values
and processes, but also environments. First let us look at value judgements.
Proposition 5.29 (substitution for values) Suppose w1 v : A, and that
, x:A
@w1 , w2 u : B, where x is fresh to . Then, assuming , {|v/x|} env, it
follows that , {|v/x|} w2 u{|v/x|} : B, where w2 denotes w2 {|v/x|}.
Proof: Here is a list of type associations, and {|v/x|} is the result of substituting
each occurrence of the variable x in with v. But note that variables cannot occur
in types, and therefore in effect the substitutions only take place in the compound
identifiers in . Also note that the locations w1 and w2 need not be the same, and
that for the sake of clarity we use B to range over an arbitary value type.
The proof is by induction on the inference of , x:A
@w1 , w2 u : B, and
an examination of the last rule used; throughout we use the notation J as in
Proposition 3.9, to denote the substitution J {|v/x|}, for any syntactic category J .
As an example suppose (ty-c.sub) is the last rule used; this may be applied to
an occurrence of u@w2 : Bs , for some subtype Bs of B, which may appear in ,
in , or in the list x:A
@w1 . In the first case we know that w2 u : B and an
application of (weakening), from Proposition 5.25, gives , w2 u : B and the
required result follows because we know both w2 and u must be different from x.
164 A distributed asynchronous pi-calculus
This ends our analysis of the case when (ty-c.sub) is the last rule used. There
are seven other cases to consider, corresponding to each of the possible rules in
Figure 5.9. But all are either a case analysis, much simpler than the one we have
just done, or follow trivially by induction.
We can now extend this generalised substitution result from value judgements,
Proposition 5.29, to agent judgements:
Proposition 5.31 (simple substitution for agents) Suppose w1 v : A and x is
fresh to . Then provided , {|v/x|} is a valid environment, , x:A
@w1 , w2 R
implies , {|v/x|} w2 R{|v/x|}, where w2 denotes w2 {|v/x|}.
Proof: This follows the lines of the proof of Proposition 3.9, using induction on
the derivation of the judgement , x:A
@w1 , w2 R, but the details are somewhat
more subtle. We examine three cases; as usual we use the shorthand notation J for
J {|v/x|}.
Suppose , x:A
@w1 , w2 u?(Y ) R because
(i) , x:A
@w1 , w2 u : r T
(ii) , x:A
@w1 , , Y :T
@w2 w2 R
for some type T. In other words (ty-in) was the last rule used in the inference. Now
we are assuming , env, and therefore we may apply Proposition 5.29 to (i) to
obtain
(i’) , w
2
u : r T
.
Since all the variables in the pattern Y can be assumed to be fresh we also have
that , env implies , , Y :T
@w2 env. This latter environment is actually
, (, Y :T
@w2 ) , which means that we can apply induction to (ii) to obtain
(ii’) , , Y :T
@w2 w
2
R .
So (ty-in) can now be applied to (i’) and (ii’) to obtain the required , w2 R .
Note that this case, unlike in the proof of Proposition 3.9, we did not need to apply
any (interchange).
The case when (ty-lp.new) is the last rule used is similar. Here we have
, x:A
@w1 , w2 (newloc k : K) R
because , x:A
@w1 , , k:K
w2 R. As before, we can assume k is fresh and
therefore , , k:K
is a well-formed environment; moreover it coincides with
, (, k:K
) . Therefore applying induction we get , , k:K
w2 R . A final
application of (ty-lp.new) gives the required result.
Let us now examine the most interesting case. Suppose (ty-match) is the last
rule used. So
, x:A
@w1 , w2 if v1 = v2 then R1 else R2
because for some types A1 , A2
(i) , x:A
@w1 , w2 v1 : A1
(ii) , x:A
@w1 , w2 v2 : A2
166 A distributed asynchronous pi-calculus
(iii) , x:A
@w1 , w2 R2
(iv) , x:A
@w1 , e w2 R1
So let us consider the possibility that , (e ) is not a valid environment; note that
here we can assume that v1 and v2 are different, as otherwise , (e ) ≡ , . We
show that (ty-mis.match) can be applied to obtain (5.33), although not necessarily
with the types A1 , A2 used above in (i), (ii).
Now , (e ) unravels to , , v1 :A2
@w2 , v2 :A1
@w2 and there are only
two reasons why it might not be a valid environment, although , is.
• Suppose , , v1 :A2
@w2 env. Here A2 cannot be a base type, and so we can apply
the extension lemma, Lemma 5.13. This means that there must exist some type A such
that A ↓ A2 and w2 v1 : A. So we can use this, together with (ii’) and (iii’) above, as
premises to (ty-mis.match) to obtain the required (5.33).
• So we can assume , , v1 :A2
@w2 is a valid type environment and therefore another
application of the extension lemma gives a type B such that B ↓ A1 and , ,
v1 :A2
@w2 w2 v2 : B. But since v1 and v2 are different this actually means that ,
w2 v2 : B, which again allows us to apply (ty-mis.match) to obtain the result.
Corollary 5.32 (substitution for agents) Suppose w1 V : T and all variables in
X are fresh to . Then , X :T
@w1 w2 R implies w2 R{|V/X |}, where w2 denotes
w2 {|V/X |}.
Proof: By induction on the structure of the pattern X . The base case, when it is a
simple variable, is given in the previous proposition. So suppose it has the located
form x@y, in which case the type T must be of the form C@loc, and the value V of
the form v @w.
So we know, by unravelling the environment,
, y : loc, x1 @y : C w2 R
5.3 Subject reduction for aDpi 167
But w1 V : T means that w : loc, and the freshness of x ensures that
, x@w : C is a valid environment. So we may apply the previous result to obtain
, x@w : C w2 R{|w/y|}
where w2 denotes w2 {|w/y|}. But w1 V : T also means that w v : C, and since
this latter environment has the form , x:C
@w the result can be applied again to
obtain w2 (R{|w/y|}){|v/x|}, where w2 denotes w2 {|v/x|}. But this is the required result
since w2 is w2 {|V/X |} and (R{|w/y|}){|v/x|} is R{|V/X |}.
The final case, when X is the pattern (X1 , . . . , Xn ) is handled in a similar
manner, assuming by induction that the result already holds for the individual
components Xi .
We have now accumulated all the auxiliary results required for subject reduction.
Theorem 5.34 (subject reduction for ADPI) Suppose M −→ N , where M , N are
systems in aDpi. Then M implies N .
Proof: The proof is by induction on the derivation of M −→ N . As in the proof of
Theorem 3.12 we can concentrate on the defining rules, given in Figure 5.5. The
rule (r-str) has already been covered by Proposition 5.28 and so we look at some
of the defining axioms.
Consider the axiom (r-comm). By the hypothesis we know
k c! V
| k c?(X ) R (5.34)
and we have to prove
k R{|V/X |}
168 A distributed asynchronous pi-calculus
k u : r T2
, X :T2
@k k R
for some types T1 and T2 . Here we can apply part (iii) of Proposition 5.23 to
deduce T1 <: T2 . Then (subsumption), the final part of the same proposition, gives
k V : T2 and we have the required hypothesis of Corollary 5.32, with being
the empty environment, to conclude (5.35) above.
The proofs for the two creation rules, (r-l.create) and (r-c.create) are
very similar and rely on the relationship between the typing rules for systems,
(ty-cnew), (ty-lnew) in Figure 5.10, and the corresponding rules for agents in
Figure 5.11, (ty-cp.new) and (ty-lp.new). As an example consider the rule for
location generation
(r-l.create) k (newloc l : L) P −→ (new l : L) k P
and suppose k (newloc l : L) P . This means k (newloc l : L) P, which
can only be inferred using the rule (ty-lp.new) from , l:L
k P. But this implies
, l:L
k P , which is the premise required for an application of (ty-lnew) with
the conclusion
(new l : L) k P
Now consider the rule (r-eq); from
k if v = v then P else Q (5.36)
we have to prove k P. This judgement cannot be derived from an application of
(ty-mis.match); this would require two types Ai such that A1 ↓ A2 and
k v : Ai
which contradicts part (iv) of Proposition 5.23. So (5.36) can only be derived using
the rule (ty-match), in which case we have
, v:A1
@k, v:A2
@k k P
for some types Ai such that k v : Ai . But here it is easy to show that
, v:A2
@k, v:A2
@k ≡
from which the required k P follows.
5.4 Type safety for aDpi 169
However our typing system does much more than enforce the proper use of
location and channel names. In the introduction to Section 5.2 we have proposed it as
a mechanism for controlling capabilities on names, and therefore for implementing
access control policies on domains. This idea was briefly alluded to at the end of
Chapter 3, and now we explain it in detail. This is best approached via an example.
Example 5.36 Let us revisit Example 5.19 where clients have used the memory
server to obtain their private instances of located memory cells; this in turn is based
on Example 5.18 and the related Example 5.7. Here we consider the following
variation:
Sysb ⇐ bobcodeB | (new m : M)(mLMem | cC(m)) (5.38)
where M is the type loc[put : rw Tp
, get : rw Tg
] and
codeB ⇐ xptp ?(x) B(x)
C(m) ⇐ goto bob.xptp ! m
The client c makes available the existence of its private memory cell m to bob
along the channel xptp . Moreover, as already explained in Example 5.19, it is
made available with restricted access rights. Using the reduction semantics Sysb
evolves to
Sysb1 ⇐ (new m : M)( bobB(m) | mLMem ) (5.39)
where, as we have seen, the resource capabilities at m accessible to bob are
determined by the write capability on the export channel xptp .
Suppose b contains the entries
. . . , xptp @bob : rw Mp
, print @bob : rw int
, . . .
where Mp is loc[put : w Tp
], a supertype of M. Thus, as explained in Example 5.19,
intuitively b enforces the access policy in which bob has only write access on put
at m. Yet, as we shall see, type safety, based on the runtime errors of Figure 5.12, is
largely independent of the actual instantiations of B(x) in (5.38) above. For example
with
B(x) ⇐ (newc r : R) (r?(y) print! y
| goto x.get! r @bob
)
the original system, Sysb from (5.38), is type safe, assuming R is correctly
instantiated; that is no runtime errors can occur, relative to b . Formally one can
show that S −→err b ∗
b for every S such that Sys −→ S.
172 A distributed asynchronous pi-calculus
However this is not possible since in the extended environment there is a write
capability on get at m.
Thus the notion of runtime error is not sufficiently discriminating to pick up this
misuse of capabilities by bob. Nevertheless the type system was designed to forbid
such misuses, and one can show that
b Sysb
The problem arises when trying to establish b bob xptp ?(x) B(x). Because of the
type of xptp at bob in b this requires deriving
be x get : w Tg
where be is an extension of b in which the only entries involving x are x : loc and
put : Tp @x.
This example demonstrates that, although the type system does enforce some form
of constraints on the capabilities available to agents, the current notion of runtime
error is incapable of describing these constraints. In order to capture the power of
the type system in an independent manner we need a version of the language in
which the capabilities obtained by agents are explicitly described.
In the next section we describe such a language, tagged-aDpi. With this explicit
representation of agent capabilities, it will be straightforward to define a version of
runtime error that represents more clearly the misuse by agents of their acquired
capabilities.
This is followed by a further section in which we explain how properly typed
aDpi systems may be interpreted as tagged systems. Moreover these tagged systems
will be guaranteed to be free from tag-based runtime errors. In other words the type
system for aDpi alleviates the user from explicitly programming and reasoning
about an agent’s capabilities.
5.4 Type safety for aDpi 173
5.4.1 TAGGED-ADPI
It may seem rather daunting to embark on the definition of a new language, with
its associated reduction semantics and typing system. But the only new construct
we actually need is a representation of the capabilities, or permissions of agents.
For this we employ the syntax
k P
where is a list of type associations; this represents the agent P running at location
k, with the permissions given in . So the syntax of tagged-aDpi is given by simply
replacing the syntax for systems, in Figure 5.2, with that given in Figure 5.13; we
use Mt , Nt as meta-variables for tagged systems, in order to distinguish them from
untagged systems of aDpi. Formally here simply ranges over association lists
between names and types. Although much of the technical development of this
section will only make sense when is actually a valid type environment, in
examples we will be less demanding. It is also worth noting that the definition
allows the formation of tagged systems such as
(new k:K)(l P 1 | k P 2 )
where the bound name k may appear in either or both of the capability descriptions
1 , 2 .
This new language tagged-aDpi needs to be endowed with a new reduction
semantics, describing the manner in which agents acquire new capabilities. As we
have already indicated these are required as a result of a communication between
two agents; after the communication of a value V along a location channel c at
location k, the receiver obtains the capabilities on the values V ordained by its
current read capabilities on c at k. To formalise this concept we use the notation
developed in Definition 5.22 for interpreting environments as partial functions from
compound identifiers, to types.
Let us consider the two agents
k c! v
1 | k c?(x) P 2
co-located at k. The first is willing to send a simple value v on c, while the second
is waiting to receive a value on it. The latter’s ability to use c is determined by its
current capabilities, described in 2 . So for example if there is no read capability on
c at k in 2 then the communication is not possible. If there is, the communication
can happen and moreover the capabilities received on v are determined by the read
capability on c at the site k in 2 . After the communication the receiving agent,
and its capabilities, are described by
k P{|v/x|}2 , v:r2 (c@k)
@k
The value v may already be known in 2 , in which case extra capabilities on it have
been acquired, or it may have been a completely unknown value, in which case it
is now known by the receiver, and may be used in accordance with the capabilities
described in v:r2 (c@k)
@k; this represents the capabilities that the receiving agent
can acquire using the channel c at k, according to its current permissions 2 .
Formally the reduction semantics is given as a binary relation between tagged
systems
Mt −→t Nt
which is the least contextual relation satisfying the axioms and rules given in
Figure 5.13. The main rule is (rt -comm), which we have just described in detail, at
least for simple values. This axiom is interpreted to only hold when V :r2 (c@k)
@k
is well-defined; that is, whenever it unravels according to Definition 5.12 to a list
5.4 Type safety for aDpi 175
of type associations. So at the very least r2 (c@k) is required to exist, but it must
also match the structure of the value V .
The remaining rules are inherited directly from the reduction semantics of aDpi,
in Figure 5.5. Note that in (rt -move) agents retain their capabilities as they
move between domains; also in the housekeeping move (rt -split) capabilities
are preserved as agents divide in preparation for communication or migration.
The rules for newly created names, (rt -c.create) and (rt -l.create), need to
update the agent’s tag with the declared capabilities on the newly created name.
The remaining rules are omitted, as the reader can reconstruct them directly from
Figure 5.5. Of course (rt -str) requires a structural equivalence between tagged
systems; its definition is in turn inherited from that for aDpi, in Figure 5.4; the only
change required is to replace the untagged k stop in the axiom (s-zero) with its
tagged version k stop .
Example 5.37 [Tagged Systems ] Consider the following variation on the system
described in Example 5.36:
j
Syst ⇐ janecodeJj | (new m : M)(mLMemm | cC(m)c ) (5.41)
where this time we have the code
C(m) ⇐ goto jane.xptp ! m
with R the type appropriate to a reply channel being sent on put, namely rw. Of
course in a complete example jane would not only put the value (7, r @jane) into
the memory but would continue computing on receipt of an acknowledgement on
r; but for simplicity we ignore this continuation. Suppose further that the current
capabilities of jane and the client are
c : xptp @jane : w Mp
, m : loc, put@m : Tp , get@m : Tg
j : xptp @jane : r Mp
Here the migrating agent has acquired the declared permissions on the newly
generated reply channel r; 2j represents
So we must restrict attention to tagged systems that are in some sense consistent;
there must be some coherency between an agent’s code and its permissions. There
are further issues, concerning consistency between the views of different agents.
Example 5.39 Suppose in the previous example that l , k are
s:loc, req@s:r str
, in@k:rw Ls
in@k:rw Ks
Referring to Example 5.38 one can check that there is no possible for which
Sys can be derived. The problem occurs when trying to establish
l l goto k.in! s
l
This is ruled out by (ii) above, as we would need to establish
l l goto k.in! s
and therefore an application of the same rule to (i), (ii’) and (iii) gives the required
l P .
As a second example consider (rt -comm); so we know k c! V
1 |
k c?(X ) R2 and we have to prove
k R{|V/X |}n2 , (5.42)
5.4 Type safety for aDpi 179
This follows from Question 5 at the end of the chapter. Moreover since n2 is a
well-defined environment
(ii) n2 k V :r2 (c@k).
The typing of the input agent implies 2 k c?(X ) R that, by virtue of (ty-in),
means 2 , X :r2 (c@k)
@k k R. Therefore in view of (ii) the substitution result,
Corollary 5.32, gives
(iii) n2 k R{|V/X |}.
An application of the new rule (tyt -agent) to (i) and (iii) now gives the required
(5.42).
This result has an interesting corollary, which says that if the unannotated aDpi
system M is well-typed with respect to , then no runtime errors will occur in
the annotated version of M , where all agents are initialised with the permissions
described in :
Corollary 5.45 Suppose M . Then Nt −→err for every Nt such that
tag (M ) −→∗t Nt .
Proof: From the previous theorem we know tag (M ) and the result therefore
follows immediately from type safety for tagged-aDpi, Proposition 5.42.
It is worth emphasising the import of this corollary. It means that there is no reason
to get involved in the complexities of tagged-aDpi, in which capabilities need to be
explicitly represented and managed at runtime. Instead of considering the tagged
system tag (M ) and its behaviour relative to the tagged reduction semantics, it
is sufficient to consider the untagged system M and its behaviour relative to the
simpler untagged reduction semantics. So long as M we are assured that
tag (M ), running relative to the tagged reduction semantics, will never give rise
to a runtime error.
Example 5.46 Let us reconsider the aDpi system
Sysj ⇐ janecodeJ | (new m : M)(mLMem | cC(m))
182 A distributed asynchronous pi-calculus
where the code for C(m) and codeJ is given in Example 5.37. And suppose j
is such that j jane xptp : rw Mp
, and it has sufficient capabilities to type the
memory correctly.
Then one can check that j Sysj and consequently the explicitly annotated
system tagj (Sysj ) will never raise a runtime error relative to the tagged reduction
semantics; agents will only ever use resources for which they have explicit
permission.
However this is not the case for the system involving bob, Sysb in Example 5.36.
A corresponding type environment is some b , with respect to which the only
type that can be inferred for xptp at bob is rw Mp
. Here we have b Sysb
and therefore the explicitly annotated system tagb (Sysb ) is not type-safe;
consequently there is a possibility of runtime errors. Indeed a runtime error does
occur, as detailed in Example 5.41. There the explicit permissions are slightly
different, but the same runtime error occurs in tagb (Sysb ); an agent emanating
from bob that tries to use the get method at m without permission.
Corollary 5.45 justifies the type system for aDpi in terms of the reduction
semantics of tagged-aDpi. But we can go even further by showing that this
reduction semantics of tagged-aDpi is essentially the same as that of aDpi. The
relationship is not completely straightforward, as reductions are not preserved under
the function tag ( ). That is M −→ N does not necessarily imply tag (M ) −→t
tag (N ), as the following very simple example shows.
Example 5.47 Let be a type environment such that k c : rw w
and let M
denote the system
k c?(x) x! | (new a@k:rw) k c! a
Note that M . Then M −→ N , where N is (new a@k : rw)(k a!) but
tag (M ) −→t tag (N ) . For tag (M ) decodes to the tagged system
k c?(x) x! | (new a@k : rw)(k c! a
rw )
where rw represents , a@k:rw. Note that the channel c can only transmit write
capabilities, and therefore the only tagged reduction from this, according to the rules
in Figure 5.13, is to a system structurally equivalent to (new a@k : rw) k a! w
where w represents , a@k:w.
But tag (N ), which decodes to (new a@k : rw) k a! rw , cannot be structurally
equivalent to this system.
Of course this is not surprising as the tagged reduction semantics keeps a detailed
account of the distributions of permissions, which is not even represented in the
untagged systems. So to relate reductions in the two languages we need a more
subtle analysis.
5.4 Type safety for aDpi 183
Definition 5.48 (tagging systems loosely) For each aDpi system M let Tag (M )
be the least (finite) set of tagged-aDpi systems that satisfies
• 0 ∈ Tag (0) whenever env
• kP ∈ Tag (kP) if <: and k P
• Mt | Nt ∈ Tag (M | N ) if Mt ∈ Tag (M ) and Nt ∈ Tag (N )
• (new e : D) Mt ∈ Tag ((new e : D) M ) if Mt ∈ Tag, e:D
(M ).
Proof: The first statement is proved by induction on the structure of M . The two
base cases, when M is 0 or k P follow by definition, and the remaining two cases
follow trivially by induction.
The second statement also follows by a simple inductive argument on the
structure of M , the interesting case being when it has the form k P . By definition
Mt must, in this case, take the form k P for some such that <: and
k P. But (weakening) immediately gives Mt .
kc! V
| kc?(X ) R −→ kR{|V/X |}
kc! V
1 | kc?(X ) R2
where 1 k c! V
, 2 k c?(X ) R, and <: 1 , <: 2 . The typing of the input
agent ensures that r2 (c@k) exists. The typing of the output agent, and (weakening),
184 A distributed asynchronous pi-calculus
means k V : w 1 (c@k), and the third part of Proposition 5.23 can be employed to
derive w1 (c @k) <: (c@k). This is enough to ensure that V and (c@k) match, and
r
2
r
2
therefore that V :2 (c@k)
@k is well-defined.
r
So we can apply the rule (rt -comm) of the reduction semantics for tagged-aDpi to get
Mt −→t kR{|V/X |}2
where 2 is 2 , V :r2 (c@k)
@k.
We know by the previous lemma that Mt , and therefore using subject reduction for
tagged-aDpi, Theorem 5.40, we have
kR{|V/X |}2
The remaining axioms are similar, and all of the rules, apart from (r-str), follow
by induction. For (r-str) we need to establish the relationship between structural
equivalence and Tag ( ). See Question 11 at the end of this chapter.
The second statement is proved in a similar manner, by induction on the inference
of Mt −→t Nt , and an analysis of why Mt is in Tag (M ). The details are left to
the reader. The only non-trivial case is when the tagged reduction is an instance of
(rt -comm), where subject reduction for tagged-aDpi is used.
The next, and final, result emphasises the import of this theorem. It shows that the
computations in the untagged language from system M , well-typed with respect to
, are essentially the same as the tagged computations from tag (M ).
Corollary 5.51 Suppose M . Then M −→∗ N if and only if tag (M ) −→∗t Nt
for some Nt ∈ Tag (N ).
Proof: Since M we know tag (M ) ∈ Tag (M ). Therefore the result follows
by repeated application of the previous theorem.
5.5 Distributed consistency of local channels 185
To summarise this section, we have shown that the resource access types for
aDpi developed in Section 5.2.1 enforce an implicit regime of access permissions
to resources. Specifically an aDpi system M , well-typed with respect to , may
be taken to represent the explicitly annotated system Tag (M ). Because it is well-
typed we are assured that Tag (M ), when run relative to the reduction semantics
in which permissions are explicitly manipulated and managed, will never misuse
these permissions. Moreover this runtime behaviour, with explicit management
of permissions, is adequately modelled in the reduction semantics of aDpi, when
restricted to well-typed systems.
where the location types Si contain the local resource name print. This sets up
two new sites s1 , s2 , which are locally serviced by the code P1 , P2 respectively,
and the print, created at each site, is exported along the distribution channels xpti ;
the actual values exported are located, consisting of the name print together with
where it is defined. A user or client, with access to both export channels, xpt1 and
xpt2 will gain knowledge of the existence of the resource print at these two distinct
locations, via the located names print @s1 and print @s2 respectively.
However despite sharing the same name, a priori, there is no reason for these
two local resources to have anything in common. In this instance their types are
determined by the type associated with the newly created locations. These, for
example, could be given by
S1 = loc[print : rw str
, . . .]
S2 = loc[print : (int, r w bool
), . . .]
Then at location s1 , print is a resource for handling strings, while at s2 print expects
pairs, the first of which should be an integer, and the second a local channel, with
some specific capabilities. Although our type system will correctly manage the
disparity between the two instances of the resource name print, it puts considerable
strain on any user of these resources, since they have to continually remember
which occurrence of print is being used.
186 A distributed asynchronous pi-calculus
But the type system can be modified so as to ensure consistency between multiple
instances of the same local resource name. There are various approaches, depending
on the level of consistency one wishes to enforce, and in the remainder of this chapter
we outline one possibility. The general idea is to introduce a new form of global
declaration, for registered resource names, and to insist that when new locations
are generated they can only use resource names that have already been registered;
moreover the types at which the locations use these names must be consistent with
the types at which they have been registered. There are various possibilities for
what is meant by consistent here. We outline a simple example, demanding that
the type of a resource at each location must be a supertype of the type at which it
has been registered. With such an approach there will be no type environment
for which
s P
where P is given by (5.43) above. For the resource name print must be registered
in at some type, say Tp ; this we will denote as an entry print : rc Tp
in , and
well-typing will impose the two constraints
Tp <: rw str
Tp <: (int, r w bool
)
which are unsatisfiable; these two types have no lower bound.
We now outline the changes necessary to implement this scheme as part of
the typing system; for clarity let us use rc in place of when discussing the extra
requirements. First we must adapt the formation rules for well-formed environments
to allow the new kind of entries, of the form n : rc C
, indicating that n is a globally
defined registered resource name. The details are outlined in Figure 5.15. The new
rule (e-rc) allows new registered names to be added to environments at a so-called
registration type rc C
; note that for simplicity we will only allow names, and not
variables, to be registered.
The effect of the presence of registered names is felt in the new rules for adding
information about a local channel u, which replace the general rule (e-chan) in
Figure 5.9. The first, (e-chan.rc), applies when u already appears in as a globally
defined registered name; in this case the newly added capability, at any site w, must
be supported by the registration type. The second rule, (e-chan.nrc), is essentially
the same as the old rule; when u is not registered the added capability must be
consistent with all existing capabilities on u at the site in question; the notation
rc u : rc just means that there is no entry of the form u : rc C
in . Note that
these rules rely on value typing judgements; these remain unchanged, inheriting
the judgements from Figure 5.9.
However the most significant modification is to the subtyping rules in Figure 5.7,
which also implicitly dictate the rules for constructing well-formed types. Now the
5.5 Distributed consistency of local channels 187
Proposition 5.52 For every valid type environment , the pre-order Types , <:
is partially complete.
Proof: The proof is virtually identical to that of Proposition 5.9, despite the presence
of the extra parameter .
This new notion of type environment can now be used in typing judgements for
systems and processes. The rules in Figures 5.10 and 5.11 can remain virtually
unchanged. But we need to modify the manner in which new location declarations
are handled; see Figure 5.16. For example to ensure that (new k : K) M typechecks
relative to we need to check that M typechecks relative to the augmented
environment , k:K
as before, but also that K is a well-formed location type,
that is rc K : ty; this ensures that all the resource names used in K have already
been registered.
5.5 Distributed consistency of local channels 189
However we also need to revise our rules for typing the match construct if v1 =
v2 then R1 else R2 . Recall that for aDpi the rule (ty-mis.match) in Figure 5.11 is
necessary in order to cover the possibility that the augmented environment used in
the premise of (ty-match), , v1 :A2
@w, v2 :A1
@w w R1 , is not well-defined.
In aDpi if is a well-defined environment, then so is , v1 :A2
@w, v2 :A1
@w,
unless A1 ↓ A2 . However in the presence of registered names it turns out that there
are more reasons for this augmented environment to be ill-defined, not covered
by the rule (ty-mis.match). To cover all possibilities we therefore use the rule
(ty-mis.match.gen), which simply says that when the augmented environment
is not well-defined it is sufficient to type R2 in the original environment. We are
guaranteed that if , v1 :A2
@w, v2 :A1
@w, is not a well-defined environment, then
v1 and v2 must be different and therefore only the else branch will ever actually be
executed. See Question 17 at the end of this chapter for an alternative approach to
typing the match construct.
This new typechecking framework enforces a primitive form of consistency
between independent systems that use the same name for independent local
resources. A typical example occurs in the typing of the memory servers from
Example 5.7, discussed in Example 5.18.
190 A distributed asynchronous pi-calculus
Example 5.54 (Located Memory Servers, Again) Let us reconsider the system
sLmemS | c1 Client1 | c2 Client2
from Example 5.7, where the server at s generates memory cells at type M and
clients generate reply channels at type R to be sent to the server. A priori these clients
are completely independent from the server, but there is an implicit dependency
between them, in the requirements on these types. Both use the resource names
put, get and there is an agreement in principle that they are each declared locally
at the same types, Tp and Tg respectively.
First let us see that the type judgement for this example system, given in
Example 5.18, no longer works in the presence of resource registration types. Let
us assume req has as an entry req : rw w M
@loc
, in addition to whatever is
required to type the clients; moreover since req is inherited from the previous
section we also assume it contains no registered resources names. Typechecking
now breaks down when we try to establish
req
rc
sLmemS
that requires the judgement
req rc
s (new m : M)(LmemS | . . .)
The only possible rule to apply here is the revised (ty-lp.new), which now requires
the premise
req rc M : ty (5.46)
Recall from (5.30) on page 156 that M is the type loc[put : rw Tp
, get : rw Tg
],
and so establishing (5.46) via the derived rule (ty-l.type) in (5.44) above would
require rc put : rc Tp
. But this is not possible, as neither of the resources put
and get are registered in req .
However let pg be a type environment with the entries
put : rc Tp
, get : rc Tg
, req : req : rw w M
@loc
Then any system defined relative to this type environment is working under clear
assumptions about the purpose of the two names put and get; they must be used at
all locations in a manner consistent with their registered types. This refers to clients
generating reply channels at types that use these names, but more importantly to
the server when it wishes to generate new domains that offer resources with these
names.
Indeed it is now easy to see that the derivation of the original type judgement
can easily be adapted to obtain
pg
rc
sLmemS | c1 Client1 | c2 Client2
5.6 Questions 191
Here we can derive the required judgement pg rc M : ty using (ty-l.type)
because put and get have been declared as registered resources in pg . But equally
important is the fact that any other client, who wishes to use the resource names
put and get, for example in new location declarations, is obliged to use them at a
type consistent with their registration type in pg .
Definition 5.55 (comparing environments with registered resources) For valid type
environments, we write 1 <: 2 if for every identifier w,
(i) 2 rc
w u : A implies 1 w u : A
(ii) 1 rc
w u : rc C
if and only if 1 rc
w u : rc C
.
In other words we do not allow any subtyping with respect to the types at which
resources are declared; 1 <: 2 only if both environments have exactly the same
registered resources, with exactly the same declaration types.
With this generalisation the properties such as (weakening), (strengthening), etc.,
from Section 5.3 still hold. We leave their proofs to the reader, and simply state the
most important one:
Theorem 5.56 (subject reduction with registered resources) Suppose rc M and
M −→ N . Then rc N .
5.6 Questions
1. Prove that (new e : D) M ≡ M whenever the bound names in e does not occur free
in M .
2. • Show that the subtyping relation over the set Types, as given in Definition 5.8, is a
partial order.
• Prove that Types, <:
is partially complete; that is fill in the details to the proof of
Proposition 5.9.
3. Consider the following server for generating distributed forwarders, based on
Example 5.3: sDisFServ where the code DisFServ is given by
When run at a specific domain, it reads some data from the channel test, and runs a
check on it, with the predicate good. If the check passes it reports to some home base
h. Otherwise it uses the channel neigh to find a neighbour of the current location, and
starts the searching process all over again from there.
Show that it is not possible to type the system kSearch, for any location k.
How could the typing system be extended so that kSearch could be properly typed?
5. This is a generalisation of Question 2 from Chapter 4 to aDpi. Suppose 1 , 2 are two
valid type environments with 1 <: 2 . Prove
(i) 1 , ẽ:D̃
env implies 2 , ẽ:D̃
env.
Note that here there is no assumption about identifiers in (ẽ) being fresh.
(ii) If bn(ẽ) are fresh to 1 then 2 , ẽ:D̃
env implies 1 , ẽ:D̃
env.
(iii) 1 w V : T implies 2 , V :T
@w env.
(iv) 1 <: 2 , V :T
@w.
Show that these four results also hold for type environments with registered resources,
from Section 5.5.
6. Let us say that e1 , e2 interchange, if one of the following conditions hold:
• both e1 , e2 are located identifiers
• both are simple names
• e1 is a simple name that does not occur in e2 .
10. Here we generalise Question 11 of Chapter 3 Let σ be a mapping over Names ∪ Vars
that maps names to names and variables to variables. Let σ be the type association
list obtained from by
• replacing every occurrence of u : E with σ (u) : (Eσ )
• replacing every occurrence of u@w : C with σ (u)@σ (w) : (Cσ ).
Note that channel types and registered name types can contain names; thus (E)σ is the
result of substituting every occurrence of n by σ (n) in E. Assuming σ is injective on
the set of (simple) identifiers that occur in , prove:
(i) M implies σ M σ
(ii) rc M implies σ rc M σ .
11. Suppose M ≡ N . Prove that Mt ∈ Tag (M ) implies there exists some Nt ∈ Tag (N )
such that Mt ≡ Nt .
12. Show that subject reduction still holds in the typing system of Figure 5.10, if
(ty-mis.match) in Figure 5.11 is replaced by (ty-mis.match.gen) from Figure 5.16.
13. Consider the type system with registered names from Section 5.5. A type environment
is called reduced if rcw1 n : C1 and rcw2 n : C2 implies w1 = w2 , whenever
rc n : rc. In other words local channel names exist at a unique site unless they have
been declared as a registered resource.
Suppose rc M , where is reduced. Then show that rc M can be inferred using
judgements that only contain reduced environments.
14. Prove Theorem 5.56, subject reduction for the typing system with registered resource
names.
15. Show that the substitution result Proposition 5.31 no longer holds in the presence of
registered resources if (ty-mis.match.gen) is replaced by (ty-mis.match).
16. Use the previous question to show that subject reduction also does not hold
in the presence of registered resources, if (ty-mis.match.gen) is replaced by
(ty-mis.match).
17. Prove that subject reduction will hold for the system with registered resource names if
(ty-mis.match.gen) is replaced by (ty-mis.match) together with the following two
rules:
(ty-mis.match.r1 )
w v1 : A1
dec v2 : rc A2
w R2 : proc
A2 <: A1
w if v1 = v2 then R1 else R2 : proc
(ty-mis.match.r2 )
w v2 : A2
dec v1 : rc A1
w R2 : proc
A1 <: A2
w if v1 = v2 then R1 else R2 : proc
Here the notation dec v : rc A
means that the type association v : rc A
occurs in .
6
Behavioural equivalences for aDpi
In this chapter we apply the theory developed for aPi in Chapter 4 to aDpi. For
technical reasons it is best to work relative to the extended typing system developed
in Section 5.5, although to avoid unnecessary clutter we will abbreviate rc to
simply .
The motivation for this theory, the relativisation of behavioural equivalences to
the partial knowledge of observers as explained in Chapter 4, applies equally well, if
not more so, in a distributed setting. Consequently it is not repeated here. Moreover
the technical framework, developed in detail in Chapter 4, is easily adapted to
aDpi. So we simply apply it, modifying the various concepts as necessary to the
distributed setting, in what we hope is a natural manner.
In the first section we discuss distributed actions-in-context and the associated
typed bisimulation equivalence, ≈bis , for aDpi systems. Most proofs of the expected
properties of this equivalence are left to the reader as they can be easily constructed
from the corresponding ones in Sections 4.1 and 4.2.
This is followed by a section on examples, which demonstrates that at least
in principle standard bisimulation-based proof methodologies can be adapted to
our setting. Necessarily there are more syntactic details to contend with; but in
time appropriate software tools, based for example on theorem provers, could be
developed to partially alleviate the tedium.
In the final section we revisit the subject first broached in the untyped setting of
aPi, in Section 2.5, namely the justification of our typed bisimulation equivalence
for aDpi. This involves developing a typed version of the touchstone equivalence
=
∼ and applying it to the distributed setting of aDpi. We show that bisimulation
equivalence ≈bis is sound with respect to =, ∼ thus establishing that bisimulations
provide an adequate technique for establishing behavioural identities. Of course
readers still familiar with the contents of Section 2.5 will realise that the converse
is not true; Example 2.29 is readily adapted to aDpi. So there are distributed
systems that cannot be reasonably distinguished, but that can never be related
194
6.1 Actions-in-context for aDpi 195
using a bisimulation. The attentive reader will also know the remedy. We develop
an asynchronous version of bisimulation for aDpi, and adapt the technique of
Section 2.7 to show that this asynchronous version of bisimulation equivalence
is complete relative to =;
∼ if two aDpi configurations are related via =
∼ then there
exists some (typed) asynchronous bisimulation that relates them.
We extend the complementary notation for action labels, µ, used for aPi, in the
obvious manner; τ is τ itself; if αo is (ẽ : D̃)k.a!V then αo is the corresponding
input label (ẽ : D̃)k.a?V , while αi is the output label (ẽ : D̃)k.a!V , if αi is the
output (ẽ : D̃)k.a!V .
As usual the standard assumptions on bound variables in these actions (6.1) are
in force. Thus all bound names are assumed to be fresh, relative to the environment
I and system M , although for emphasis this requirement is sometimes explicitly
mentioned. We also employ the same consistency requirements on these µ as in
196 Behavioural equivalences for aDpi
Section 4.1, adapted to take into account possible compound names. So for example
for (e : D)α to be well-formed we require α to be well-formed, and the bound name
in e to
• be different from the location and channel used in α
• be different from the bound names in α
• appear somewhere in α.
Finally note that although the moves are decorated only with new global
information, (ẽ : D̃), new local information can also be generated. For example
when αi is (b@k : C)k.a?b the label represents the transmission of a newly created
local channel b, created at the site local to the action, namely k.
Output is also governed by two rules, (l-out) for the transmission of values
that intuitively are assumed to be known to the observer, and (l-open) for the
transmission of newly created names, this time newly created by the system
being observed. Note that, as with typed aPi, there is an important implicit side-
condition here, namely that the resulting label is well-defined. Thus to apply this
rule the bound name in e must appear somewhere in the label αo , although it is
also required to be different from all the existing bound names there. Also as in
typed aPi the observer receives values at the transmission type of channel a at
k, rather than at the declaration type; the example discussed on page 102 is easily
198 Behavioural equivalences for aDpi
generalised to the distributed case. Again as in typed aPi, in (l-out) the fact that
I k a! V
is a configuration ensures that the augmented association list, namely
I , V :I r (a@k)
@k, is always a well-defined type environment; see Question 3 at
the end of the chapter. The final rule in Figure 4.1 (l-ctxt) is a standard contextual
rule; but note that the side-condition in the second clause, bn(e) ∈ µ has extra
significance here as bn(e) may in principle occur in the types used in µ.
Most of the rules governing internal actions-in-context are taken directly from
the reduction semantics; the only exception, (l-comm), is adapted from typed
aPi. The internal communication does not change the external knowledge I , and
is independent of the actual environments I1 and I2 necessary to provoke the
constituent actions.
In Chapter 4 we went into considerable detail developing the properties of
actions-in-context for aPi. Here we spare the reader many of the detailed proofs;
instead we will simply state their properties, leaving it to the reader to check that the
proofs given there can be adapted to aDpi. But we do need to develop the notation
required to state these properties.
Notation 6.2 We first define the effect of actions on environments, generalising
Definition 4.6. Let the partial function after be defined by
• (I after τ ) is I.
• If µ is the input label (ẽ : D̃)k.a?V then (I after µ) is defined to be I, ẽ:D̃
; recall that
here we know that all the bound names in (ẽ) are fresh to I.
• If µ is the output label (ẽ : D̃)k.a!V then (I after µ) is defined to be I, V :I r (a@k)
@k.
Next let us define another partial predicate allows, which determines when an
action is possible in an environment.
µ
Finally we write, mimicking Notation 4.8, M −→ N to mean that there exist some
µ
environments I , I , such that I M −→ I N ; this means that M can in principle
perform the action µ.
Note that as with typed aPi, the definitions of (I after µ) and (I allows µ)
are independent of the types in µ, whenever it is an output label. Specifically let
µ ∼ µ mean that un(µ) = un(µ ), where un( ) is the obvious generalisation of
the function given in Section 4.2.1, which eliminates the types from output labels,
and leaves others untouched. Then
• (I after µ) = (I after µ )
• (I allows µ) if and only if (I allows µ ).
– the judgements
µ
(I M ) −→ (I after µ N )
that are derivable from the rules in Figures 6.1 and 6.2, when µ is an input action or
the internal action τ ;
– the judgements
(ẽ:Ẽ)k.a!V
(I M ) −
−−−−−→ (I after µ N )
for some collection of types (Ẽ), when µ is the output action (ẽ)k.a!V .
The reason for abstracting away from the types in output moves is explained in detail
in Example 4.18 for aPi but it applies equally well to aDpi. Essentially observers
are oblivious to the declaration types of newly acquired resource names, and simply
receive them at the capabilities determined by the output type of the channel through
which they are transmitted. We also extend the equivalence between action labels
for aPi, given on page 113, in the obvious manner. If µ and µ are output labels
then µ ∼ µ means that their untyped versions are the same; otherwise µ and µ
must be identical.
Consequently we can apply the standard definition, to obtain a bisimulation
equivalence between aDpi configurations. As usual we are principally interested in
comparing systems under the same external assumptions and consequently we use
6.2 Typed bisimulation equivalence for aDpi 201
However rather than spend more effort on repeating these proofs let us consider how
we may adapt standard techniques to demonstrate the parameterised equivalence
between systems.
202 Behavioural equivalences for aDpi
What this means is that axioms for structural equivalence in Figure 5.4 can be used
as equational laws for manipulating system descriptions. So for example we now
know
(new e : D)(M | N ) ≈bis M | (new e : D) N whenever bn(e) ∈ fn(M )
We will later see more such laws.
Another approach to alleviating the burden of exhibiting witness bisimulations
is to extract structure common from the system descriptions. (Compositionality),
item (C) above, justifies one such instance, where the common structure involves
a concurrent system. Another instance is justified by the following result.
Proposition 6.4 (scoping) Suppose that both I (new e : D) M and I
(new e : D) N are configurations. Then I |= M ≈bis N implies I |=
(new e : D) M ≈bis (new e : D) N .
Proof: Note that our ongoing implicit assumptions about the freshness of bound
names, ensures that in this statement we know that the bound name in e does not
appear in I .
Let R be the family of relations defined as follows: I |= M R N if
(i) I |= M ≈bis N
(ii) or M , N have the form (new e : D) M1 , (new e : D) N1 respectively, where I |=
M1 ≈bis N1 .
I M −τ→
β
N
Lemma 6.5
τ τ
• M −
→β
N implies I M −
→β
N for every configuration I M .
τβ τβ
• M ≡ N and I M − → M implies I N −→ N for some N such that M ≡ N .
The main technical property of β-moves is given in the following lemma. Here,
and often in the sequel, for the sake of clarity we revert to the original notation for
describing actions-in-context, as relations over configurations.
τβ
Lemma 6.6 (β-commutativity) Suppose I M −
→ I M . Then for every other
µ
move I M −→ (I after µ) N either
(i) µ is τ and N is M ,
τβ µ
(ii) or there is a system N and moves (I after µ) N −
→ (I after µ) N and I M −
→
(I after µ) N .
In such diagrams we use the solid lines to indicate the moves that are given, and
the dotted lines those that are required.
6.3 Describing bisimulations 205
µ
• N is M1 | M2 and I M2 −→ (I after µ) M2 .
Diagrammatically we have
Here the second clause (ii) is automatically fulfilled, with the required N being M1 | M2 .
To see this note that the first part of the previous lemma can be applied to I M1 −τ→I
β
M1
τβ
to obtain (I after µ) M1 −→ (I after µ) M1 and an application of (l-ctxt) gives
the move (I after µ) M1 | M2 −τ→ β
(I after µ) M1 | M2 .
Since the free names of M1 are contained in those of M1 , the contextual rule (l-ctxt)
µ µ
can be applied to I M2 −→ (I after µ) M2 , to obtain the move I M1 | M2 −→
I M1 | M2 . In other words we have the required commuting diagram
206 Behavioural equivalences for aDpi
α α
• The label µ is τ , N is (new ẽ : D̃)(M1 | M2 ) and I1 M1 −→
1
I1 M1 , I2 M2 −→
2
I2 M2 , for some suitable labels α1 , α2 . In other words we have to complete the diagram:
(6.2)
We use these commuting moves to construct the moves required to complete the diagram
(6.2) above:
This result is lifted to sequences of β-moves, by the use of some more convenient
µ̂
notation. Extending the ˆ notation introduced in Chapter 1, let I M −→ I N if
µ
• I M −→ I N , whenever µ is an external action
τ
• I M −→ I N , or I = I and N = M , whenever µ is an internal action, that is τ
annotated or not; so τ̂ represents 0 or 1 internal moves.
τβ ∗ µ
Corollary 6.7 Suppose I M − → I M . Then for every move I M − → (I after
τβ ∗
µ) N there is a system N and moves (I after µ) N − → (I after µ) N and
µ̂
I M −→ (I after µ) N . Diagrammatically given
Thus in some sense sequences of β-moves do not affect the possible occurrence of
other moves. For this reason they preserve bisimulation equivalence.
208 Behavioural equivalences for aDpi
τβ ∗
Proposition 6.8 Suppose I M −
→ M . Then I |= M ≈bis M .
• I M is a configuration
τβ
• either M = M or M −→ M .
This result gives us many useful instances of bisimulation equivalence, all albeit
expected. Examples include
I |= k P | Q ≈bis k P | k Q
I |= k rec z. B ≈bis k P{|rec z. B/z|}
(6.3)
I |= k (newc c : C) P ≈bis (new c@k : C)(k P
I |= k goto l.P ≈bis l P
assuming of course that I is such that all of these are configurations.
More importantly β-moves enable us to develop a notion of bisimulation-up-
to-β-reduction, which can cut down considerably on the complexity of exhibiting
bisimulations. The general idea is to define a modified bisimulation relation R in
which the condition for matching residuals is relaxed; instead of demanding that
they be again related by R we allow an approximate matching. We have already
seen one instance of this, where the approximation is implemented with structural
equivalence. Here we use β-moves; our formulation takes advantage of the fact
that both −τ→
β ∗
and structural equivalence, ≡, can be viewed as relations over both
systems and configurations. Most of the abstract reasoning we are about to perform
is independent of the precise syntax for configurations, and holds in an arbitrary lts.
Consequently we will often use general meta-variables such as C , D to range over
configurations; indeed the previous two results, Corollary 6.7 and Proposition 6.8
could also have been treated at this level of abstraction.
6.3 Describing bisimulations 209
for some label µ such that µ ∼ µ , where Al , Ar are the approximation relations
(−τ→
β ∗
)◦ ≡ and ≈bis
µ
respectively. In other words the move C −→ C need only be matched by a move
µ
D =⇒ D where some β-residual of C is approximately related to D . This means
the existence of C −τ→
β ∗
C such that
C ≡ ◦ S ◦ ≈bis D
These relations allow considerable flexibility in how actions are matched, with the
result that they are in general much smaller than real bisimulations. Intuitively in
such an S the single pair C , D
represents any pair C , D
, where D ≈bis D , and
C β-reduces to some configuration structurally equivalent to C .
The relevant properties of the left-hand approximation relation are given by:
Lemma 6.12
• Al ⊆ ≈bis
• Al ◦ Al = Al , that is Al is idempotent.
Proof: Note that Al is a relation both over configurations and over systems; here
we view it as being over configurations.
The proof of the first property is straightforward, in view of Proposition 6.8.
To prove the second, let Id denote the identity relation on configurations. Since
τb ∗
Id ⊆ (−→ ) and Id ⊆ ≡ it follows trivially that Id ⊆ Al . Therefore Al ⊆ Al ◦ Al ,
because if C Al D then we have C Al C Al D.
So we prove the converse, and for the sake of variety let us reason directly on
the relations. First note that expanding out Al ◦ Al we get
τb ∗ τb ∗
−→ ◦ ≡ ◦ −→ ◦ ≡ (6.4)
However the second part of Lemma 6.5 implies
τb ∗ τb ∗
≡ ◦ −→ ⊆ −→ ◦ ≡
τb ∗
For if D ≡ ◦ −→ C then we know that there is some C such that D ≡ C and
τb ∗ τb ∗
C −→ C . Repeated application of the lemma to C −→ C gives some D such that
τb ∗ τb ∗
D −→ D and D ≡ C . The existence of this D ensures that D −→ ◦ ≡ C.
So (6.4) above can be rewritten to
τb ∗ τb ∗
−→ ◦ −→ ≡ ◦ ≡
that coincides with Al , since both component relations are transitive.
Then the second part of Lemma 6.5 allows us to find D such that
µ
We use induction on the size of the action-in-context C =⇒ C to show the existence
of some D such that
(∗)
6.3 Describing bisimulations 213
τ µ
and µ ∼ µ . Here size means the number of actual strong moves −→ and −→ used
µ
in the derivation of C =⇒ C . There are three cases.
µ
• Suppose C −→ C . Then the result follows from the strong β-transfer property.
τ µ
• Suppose C −→ C1 =⇒ C . Applying the strong transfer property to
gives
gives
µ̂
Here the essential point is that the size of the derivation C2 =⇒ C2 is at most that of
µ
C1 =⇒ C . So we may apply induction to
214 Behavioural equivalences for aDpi
to obtain
for some µ ∼ µ. Now we can use the fact that D2 Ar D1 , that is D2 ≈bis D1 , to obtain
a move D1 =µ⇒ D such that D2 Ar D . The matching move required in (∗) above is
τ̂ µ
D =⇒ D1 =⇒ D , since by the second part of Lemma 6.12 C Al ◦ S ◦ Ar D .
µ τ
• The final possibility, which we leave to the reader, is that C −→ C1 =⇒ C ; the proof is
similar to the case we have just completed.
This result is the essential ingredient in the proof that bisimulations-up-to-β yield
bisimulation equivalence.
Theorem 6.15 If I |= M R N , where R is a bisimulation-up-to-β, then I |=
M ≈bis N .
Proof: Let S denote the relation ≈bis ◦ R ◦ ≈bis over configurations. We show that
this is a bisimulation, from which the result follows. The proof relies on the fact
that R and its inverse satisfy the weak β-transfer property, which we know to be
true from the previous proposition.
First suppose
(∗∗)
But Lemma 6.12 ensures that Al ⊆ ≈bis and therefore we actually have C S D1 ;
recall that Ar is actually ≈bis . Now since D1 ≈bis D we can find a move D =µ⇒ D
such that D1 ≈bis D . This is the matching move required in (∗∗) above, since
C S D .
Note that the relation S is not necessarily symmetric, since R may not be. So we
µ
have to also prove that every move from D, D −→ D , must be properly matched
by an appropriate one from C . However the argument is essentially the same, but
this time relying on the fact that R−1 satisfies the weak β-transfer property.
But unfortunately this statement is not true. The basic reason is that this
framework allows a context in which there is another server, providing a different,
perhaps unexpected, response to requests on the resource inp at site s; we have
already come across this argument, in a slightly different setting, in Example 3.15.
Consider the system
sbadServer
where badServer is the code
This server, which also uses inp at s with the type r Tin
, simply decrees that
all integers are prime. Now if the statement (6.5) above were true, then since
sbadServer, the compositionality principle would dictate that
would also be true. But this is obviously not the case. In the first system, the client at
h1 could communicate with badServer, and get back the answer true and print it.
This behaviour is not possible in the second system. Formally the first configuration
can perform the weak move
h1 . print!(true)
========⇒
and this cannot be matched by the second.
Nevertheless we would still like to prove that the server/client interaction works
correctly, provided sDprimeS is the only server in the environment. By restricting
the type environment we can prove a slightly stronger result; in any environment
in which the read capability on inp is not available, the statement (6.5) above is
true.
As a first step towards this proof we consider a slightly simpler situation.
Is s inp : w Tin
where Tin is (int, w bool
@loc)
Is s inp : T implies w Tin
<: T
So we confine our contexts to those in which inp @s can only be used to send values,
of the appropriate type.
6.4 Servers and clients 217
This code, placed at the server site s, responds correctly to one client request. We
show this formally by proving
Is |= sDprimeS1 | h1 Client(27) ≈bis h1 print! false
(6.6)
Let R be the relation over configurations consisting of all pairs of the form
Is Ml , Is Mr
where Ml , Mr
ranges over the following pairs:
sDprimeS1 | h1 Client(27) ↔ h1 print! false
(new r @h1 : R)(sDprimeS1 |
sinp ! 27, r
| h1 wait) ↔ h1 print! false
(new r @h1 : R)(h1 r! false
| h1 wait) ↔ h1 print! false
h1 print! false
↔ h1 print! false
0 ↔ 0
Here wait is the code r?(x) print! x
.
Then it is easy to check that R is a bisimulation-up-to-β. For example the only
possible move from an instance of Is Mr is
s. print!(false)
Is Mr −−−−−−−→ hstop
This can be matched by a move from any corresponding I Ml . For example if
Ml is
(new r @h1 : R)(h1 r! false
| h1 wait)
then the required move is
τ s. print!(false)
Is Ml −→ −−−−−−−→ (new r @h1 : R)(hstop)
This follows since one can show
(new e : D) M ≡ M
whenever bn(e) does not occur free in M ; and of course from (s-zero) in Figure 5.4
we have hstop ≡ 0; see Question 1 at the end of Chapter 5.
Similarly all the moves from Is Ml can be matched by the corresponding
Is Mr ; in fact other than the actual print move, the matching is by the empty
move. For example suppose Ml is
(new r @h1 : R)(sDprimeS1 | sinp ! 27, r
| h1 wait)
218 Behavioural equivalences for aDpi
Then the only possible move is the communication of the value 27 to the server:
τ
Is Ml −→ Ml
where Ml denotes (new r @h1 : R)(sgoto h1 .r! false
| sstop | h1 wait). The
required matching move is
τ 0
Is Mr −→ Mr
This is because
Ml −τ→
β
(new r @h1 : R)(h1 r! false
| sstop | h1 wait)
and this latter system is structurally equivalent to (new r @h1 : R)(h1 r! false
|
h1 wait), which in turn is related to Mr at Is by R.
This ends our proof of the statement (6.6) above.
It would be tempting to use this result, (6.6), to establish the more general
Is |= sDprimeS | h1 Client(27) ≈bis sDprimeS | h1 print! false
(6.7)
By exhibiting a specific bisimulation-up-to-β, it is possible to show
Is |= sDprimeS ≈bis sDprimeS | sDprimeS1
An application of (compositionality) then gives
Is |= sDprimeS | h1 Client(27) ≈bis sDprimeS | sDprimeS1 |
h1 Client(27)
since Is h1 Client(27). From this we could then conclude (6.7), again by
(compositionality), under the hypothesis
Is sDprimeS
But unfortunately this hypothesis is not true; indeed the knowledge environment
was designed to explicitly rule out systems that can read from the request service
inp at s.
However we can establish (6.7) directly by giving a witness bisimulation-up-to-β
slightly more complicated than that in Example 6.16.
Example 6.17 Let S denote the system
sinp ?(x, y@w) goto w.y! isprime(x)
| DprimeS
Note that sDprimeS −τ→
β
S and therefore by Proposition 6.8
Is |= sDprimeS ≈bis S.
In this example we will show
Is |= S | h1 Client(27) ≈bis S | h1 print! false
(6.8)
6.4 Servers and clients 219
I Ml , I Mr
I hj : loc
I hj rj : w bool
• It is a move from S. Here there are a number of possibilities, depending on whether the
location and/or the channel received on inp at s is fresh. When both are fresh we get
moves of the form
αi
Ih1 print! false
| B | S −→
h1 print! false
| B | sgoto h.r isprime(vj )
| DprimeS (6.9)
where αi is the action (h : H, r @h : Tr )s.inp ?(v, r @h). Note that this action can be
continued, via τβ moves, to a system that is once more of the form Mr , up to structural
induction:
h1 print! false
| B | sgoto h.r isprime(v)
| DprimeS −τ→
β ∗
h1 print! false
| (B | hr! isprime(v)
) | S
Each possible Ml can allow the S component to execute the same input action, followed
by a τ move to obtain
I Ml =α⇒
i
M
for some M that is once more of the required form Ml . Here matching the residuals is
with respect to the augmented environment I after αi , which unravels to I, h:H
, r @h :
Tr . Note that requirements (iii) above are satisfied by this environment, because the
action-in-context (6.9) can only be inferred provided
I, h:H
, r @h : Tr s r @h : w bool
@loc
There are a number of mild variations to the exact form of αi in the move (6.9) above;
for example it could be (r @hj : Tr )s.inp ?(r @hj ), for some hj already known to I. But in
each case the reasoning is more or less the same.
• Finally it might be a move from B. Here we can argue as in the previous case that it can
be matched by a similar move from I Ml ; indeed in this case reasoning up-to-β is not
necessary.
We also have to consider all possible moves from each of the forms of Ml . If B
or S is responsible arguments similar to those already employed can be repeated.
As an example of the remaining cases let us consider when Ml has the form (a) and
the move is
Ih1 Client(27) | B | S −τ→
β
This can now be matched by the empty move from the right-hand side:
τ̂
IMr =⇒ Mr
The remaining possibilities of moves from the left-hand side are treated similarly; in
each case the corresponding move from the right-hand side is the empty move.
So we have established that one client can interact successfully with the server,
(6.7) above:
Is |= sDprimeS | h1 Client(27) ≈bis sDprimeS | h1 print! false
But simple compositional reasoning can now be used to generalise this to an
arbitrary number of clients. As an example let us consider a second client
h2 Client(11), and let us assume that Is also types this correctly; that is, it knows
that h2 is a location. Then, since Is h2 Client(11), (compositionality) applied
to (6.7) gives
Is |= sDprimeS | h1 Client(27) | h2 Client(11)
≈bis sDprimeS | h1 print! false
| h2 Client(11) (6.10)
A repeat of the argument in Example 6.17 establishes
Is |= sDprimeS | h2 Client(11)
≈bis sDprimeS | h2 print! true
A further application of (compositionality) to this, gives
Is |= sDprimeS | h2 Client(11) | h1 print! false
≈bis sDprimeS | h2 print! true
| h1 print! false
Then, by the transitivity of ≈bis , and the commutativity of |, (6.10) gives
Is |= sDprimeS | h1 Client(27) | h2 Client(11)
≈bis sDprimeS | h1 print! false
| h2 print! true
This argument can be extended to demonstrate that the server can properly handle
an arbitrary number of clients.
F = loc[info : rw I
, req : rw R
]
that allows access to two resources info and req in f. Then P could, for example,
maintain appropriate services at these resources; of course P would also be able to
use non-local resources it knows about in its current environment.
In this very simplified scenario the existence of the firewall is made known
to only one (trusted) agent, a, which is strictly speaking another domain, via the
information channel tell located at a; a more realistic scenario would have some
method for generating such trusted agents. A typical example of the code for this
trusted agent is given by
where a is informed of f by inputting on the local channel tell: we have the execution
Fr = loc[info : w I
, req : r R
]
a supertype of the declaration type F. Then in (6.11) Q, having gained entry into
the firewall, can only write to resource info and read from req.
Let us now consider the correctness of this simple protocol for allowing access
to one agent, a to the firewall. Let be any type environment such that
F |A (6.12)
But this happens not to be true, because of an implicit assumption; namely that the
information channel tell can only be accessed by partners in the entry protocol, f
and a; we have already seen this phenomenon when considering servers and clients.
6.5 Modelling a firewall 223
However, as with the previous example on the server and its clients, our
framework allows us to amend the correctness statement (6.13) above, to take into
account the implicit assumption about the information channel tell. The essential
point is that the protocol works provided that only the firewall can write on tell. This
can be formalised by proving the equivalence between the two systems relative to
a restricted environment, one that does not allow write access to tell.
Suppose I is a type environment that satisfies
(i) I a tell : T implies r Fr
<: T
(ii) I aR
(iii) I (new f : F) fP.
The import of the first requirement, which is the most important, is that systems
in the computational context cannot write on tell. The other requirements, which
are mainly for convenience, ensure that the residual behaviour at a and f is well-
behaved, although a side-effect is that they also cannot write on tell. Note that in (iii),
because we are using aDpi, the capabilities in the firewall type F are expected to
be registered resources. Under these assumptions we prove
I |= F | A ≈bis (new f : F)(fInform | P | Q) | aR (6.14)
But
and this can be matched, up to structural equivalence, by essentially the same moves:
τ ∗
I N −→ I fInform | fQ |
(j+1) (. . .)
and this can be matched by the empty sequence of internal actions from I N .
We leave the reader to check the converse; namely that every action-in-context
from J N can also be matched by actions from J M . The details are similar,
but somewhat simpler.
This completes our proof of (6.14) above. Note that the firewall F allows in
principle multiple entries of agents from a. So, for example suppose R, in (6.14)
above, has the form
S | tell?(x) goto x.Q1
Let us show how the second agent, executing Q1 , can also gain access through the
firewall.
Let F1 denote the firewall containing the first agent Q:
F1 ⇐ (new f : F) fP | Q | Inform
Then the reasoning we have just completed could be repeated, to prove
I |= F1 | aR ≈bis (new f : F)(fInform | P | Q | Q1 ) | aS
This, combined with (6.14), gives
I |= F | A ≈bis (new f : F)(fInform | P | Q | Q1 ) | aS
Here the domain a has managed to send two separate agents into the firewall.
226 Behavioural equivalences for aDpi
So observations are localised to specific locations, and note that the observer
requires both the read and write capability on the channel being observed.
6.6 Typed contextual equivalences 227
The major change from the untyped case, Definition 2.5, is that we only expect
related systems to remain related when run in parallel with a restricted set of other
systems, namely those that can be typed by the current knowledge of the observers.
However knowledge of names is carefully managed by type environments and
so we also need to add a form of weakening. We expect contextual relations to
be preserved by inventing completely new names; with aDpi these could be new
locations, new resources at existing locations, or even new registered resources.
Note that although typed relations are formally families of relations over aDpi
systems, the standard set theoretic operations, such as ⊆, ∪, ∩ can be defined
point-wise on them, and consequently it makes sense to talk of the largest typed
relation satisfying a collection of properties.
context whether it refers to a relation over untyped processes from aPi or a typed
relation over systems in aDpi, that is a relation over aDpi configurations.
This behavioural equivalence inherits all the advantages and disadvantages
discussed in Section 2.5. The advantages include:
• It is intuitively reasonable, as systems are only distinguished on the basis of three
intuitively appealing behavioural properties.
• It takes into account the observer’s current knowledge of the capabilities of systems, in
a manner consistent with the ideas elaborated in the introduction to Chapter 4.
• By definition it satisfies the compositionality principle, given in (4.3).
The major disadvantage is that in general it is difficult to prove that two systems
are equivalent relative to a given I . To emphasise this let us attempt such a proof.
Example 6.24 Let us revisit the located memory mLMem discussed in
Examples 5.17 and 5.6. In order for a client to use the memory it needs to know the
access methods at the appropriate types get@m : w Tg
, put@m : w Tp
. Suppose
on the contrary that Ir is some type environment that has no entries for get@m and
put@m. Then one would expect
Ir |= mLMem =
∼0 (6.16)
to be true; this formalises the intuitive idea that knowledge of the memory’s access
methods, and their location, is necessary in order to use it.
To prove (6.16) we need to construct a typed relation R, which satisfies the three
defining properties of =,
∼ such that
Ir |= mLMem R 0
The obvious approach is to define the family of relations R inductively as the least
ones such that
• mLMem RIr 0
• for every I, M RI N implies M | O RI N | O and O | M RI O | N for every O
such that I O
• M RI , e:D
N implies (new e : D) M RI (new e : D) N
• M RI N implies M RI , e:D
N , whenever the bound name of e is fresh to I, M , N .
Ir |= mLMem R 0
Ir |= mLMem =
∼0
However the reader still familiar with the contents of Chapter 2 should easily be
able to establish that this proof method for =
∼ is not complete:
• I |= M = N does not necessarily imply I |= M ≈bis N .
∼
It is simply a matter of adapting Example 2.29 to the distributed language:
Example 6.26 Let Ia be a type environment in which k is a location and Ia k a:
rw. Then obviously
where α is an input label, of the form (ẽ : D̃)k.a?V . These are the least relations
satisfying the rules in Figure 6.3 and are based directly on those in Figure 2.6, which
define the untyped asynchronous actions for aPi. The rule (a-con) coincides with
the standard rule for inputing values, (l-in) from Figure 6.1, while (a-delv) is the
typed version of (a-delv) from Figure 2.6. The latter represents the delivery of the
value V to the channel a located at k, while the former represents its consumption.
Note that both require the environment to have the ability to send the value along a
at k. The two final rules (a-weak) and (a-ctxt) simply allow these asynchronous
actions to happen within evaluation contexts.
We leave the reader to check that the properties (1)–(5) on page 199 also apply to
these asynchronous actions-in-context, and we use the associated notation without
comment. The main extra property of these new actions is summarised in the
following result:
Proposition 6.27 (asynchronous actions) Let αi denote the input label
(ẽ : D̃)k.a?V and suppose I allows αi . Then
αi τ ∗
(i) I M −→ a N implies I, ẽ:D̃
M | ka! V
−
→ N , for some N ≡ N .
τ ∗
(ii) Conversely, assuming (ẽ) are fresh to M , I, ẽ:D̃
M | ka! V
− → N implies
αi
I M =⇒a N for some N ≡ N .
Proof: Part (i) is proved by induction on the derivation of the asynchronous action-
αi
in-context I M −→ a N , and there are four cases, depending on the last rule applied;
in the first two αi is guaranteed to be of the simple form k.a?V .
6.7 Justifying bisimulation equivalence contextually in aDpi 231
k.a?V
(a-con): Here we have I ka?(X ) R − −−→a kR{|V/X |} because I w (a@k) ↓def and
I k V : I (a@k). But this information is sufficient to allow an application of (l-in)
w
We can apply induction to this action-in-context, which will actually give us the
required sequence of τ moves:
τ ∗
I, e:D
, d̃ :D̃
M | ka! V
−→ N
(a-ctxt): We leave this case, which is similar, to the reader.
Let us now prove the converse, part (ii); we use induction on the number of steps
in the computation
τ ∗
I , ẽ:D̃
M | k a! V
−→ N
zero: From the relation (I allows αi ), and the fact that (ẽ) are fresh, we have enough
information to enable an application of (a-delv) to obtain
k.a?V
I, ẽ:D̃
M −
−−→a M | ka! V
αi
Then the required move, I M −→ a M | ka! V
follows by a series of applications
of (a-weak).
232 Behavioural equivalences for aDpi
we can apply induction. Otherwise the first step must involve an application of
(l-comm), and so the derivation takes the form
τ τ ∗
I, ẽ:D̃
M | ka! V
−→ I, ẽ:D̃
M | kstop) −→ I, ẽ:D̃
N
βi
for some M such that IM M −→ M , for some IM , where βi denotes the label
k.a?V . But I allows αi implies I, ẽ:D̃
allows βi , and so we can apply (2) on
βi . Also synchronous actions-in-context are also
page 199 to obtain I, ẽ:D̃
M −→M
βi
asynchronous, and so we have I, ẽ:D̃
M −→ a M . Now a series of applications
αi
of (a-weak) will give I M −→a M .
τ ∗
Moreover in this case N must be of the form M | kstop, where M −→ M .
αi
Therefore the required asynchronous action-in-context is I M =⇒a M .
Following the development in Section 2.6, these revised input actions give rise
to an observational lts for aDpi. Here the configurations are of the form I M , as
before, and the actions over configurations are given by
(ẽ:D̃)k.c?V
input: I M − −−−−−→a I N
(ẽ)k.c!V
output: I M − −−−→ I N
τ
internal: I M −→ I N
This is called the asynchronous lts for aDpi, and for notational convenience, as in
µ
Chapter 2, we will denote an arbitrary action in this lts by I M −→ a I N,
µ
although in two cases this coincides with the standard action I M −→ I N .
Definition 6.28 (asynchronous bisimulations for aDpi) A relation over aDpi
systems is called an asynchronous bisimulation if it satisfies the standard transfer
properties in the asynchronous lts.
We let I |= M ≈a N denote the fact that there is some asynchronous bisimulation
R such that I M R I N .
We leave the reader to check that this new equivalence corrects the mismatch in
Example 6.26 between bisimulation equivalence and reduction barbed congruence;
see Question 7 at the end of the chapter. Indeed the aim of this section is to show that
these asynchronous bisimulations capture exactly reduction barbed congruence.
Theorem 6.29 I |= M ≈a N implies I |= M = ∼ N.
Proof: It is simply a matter of checking that ≈a , viewed as a typed relation, satisfies
the defining properties of =,
∼ in Definition 6.23 applied to aDpi. By definition it
is reduction-closed, and it is simple to prove that it preserves typed observations.
The proof that it is contextual is, of course, non-trivial. However the proof of
Proposition 4.24 can be adapted to aDpi with asynchronous actions, as can that
6.7 Justifying bisimulation equivalence contextually in aDpi 233
Thus the various examples treated in Section 6.3, and the general proof methods
developed there, can now be considered to pertain to our touchstone equivalence, =.
∼
Our aim is to show that asynchronous bisimulations actually provide a complete
proof method; that is whenever I |= M = ∼ N we can exhibit an asynchronous
bisimulation R containing the pair (I M , I N ). However this is only true in
a restricted setting.
Example 6.31 Let be any environment that types both the systems
k b! a
(new c@k : rw) k b! c
234 Behavioural equivalences for aDpi
Note that it is only the last clause that is different from Definition 6.1; it requires
that all names necessary to type M must be at least known to I .
µ
Proposition 6.33 Suppose I M is a strict configuration. Then I M −
→ I M
implies I M is also a strict configuration.
Proof: From result (4) on page 199 we know that I M is a configuration;
that is M for some such that <: I . To establish the current proposition
we re-do the proof of this result, mimicking that of the corresponding result for
aPi, Corollary 4.13, checking the extra requirement, that a can be found whose
domain is contained within that of I .
First suppose µ is the output action (ẽ:D̃)k.a!V , in which case I is
I , V :I r (a@k)
@k, and subject reduction, (3) on page 199, gives , ẽ:D̃
M . A
careful analysis of the rules for generating actions-in-context will reveal that each
ei will actually appear in the domain of V :I r (a@k)
@k, from which it follows that
the required is , ẽ:D̃
; such an analysis is given in Question 1 at the end of the
chapter.
Now suppose µ is the input label (ẽ : D̃)k.a?V . Here we know that I is I , ẽ:Ẽ
,
where (ẽ) are fresh to I . They can also be assumed to be fresh to and therefore
Question 5 of the previous chapter assures us that , ẽ:Ẽ
is a valid environment.
We can now mimic the input case in the proof of Corollary 4.13 to obtain , ẽ:Ẽ
M , which establishes the required result.
So for the remainder of this section let us consider the restricted asynchronous
lts consisting only of strict configurations. The previous proposition means that
bisimulation equivalence is also well-defined in this restricted setting. Moreover
within this restricted setting we are able to repeat the general completeness argument
of the untyped setting of Section 2.7. But this time round it is considerably
6.7 Justifying bisimulation equivalence contextually in aDpi 235
more complicated due to the presence of types, and the parameterisation of the
equivalences with respect to knowledge environments.
A typical example is the definability of actions-in-context, generalising
Theorem 2.37, in which contexts are defined for mimicking actions. These actions
are located, and the values that are sent and received may only make sense at the
location of the action. But we will need to manipulate these values, perhaps at
varying locations. Consequently we need to transform them into global values,
with global types.
Moreover, as in Theorem 2.37, we need to make available at some standardised
place the new names generated by the action we are defining. But here, in addition,
we need to also make available their capabilities, and even new capabilities on
names that are already known. So first let us develop some notation.
Definition 6.34 (standard environment extensions) The type environment , V :T
What this means is that new located channels in the extension cannot be registered
resources.
µ
Lemma 6.35 If I M −
→ a M then (I after µ) is a standard extension of I .
Proof: If µ is the internal label τ then this is immediate, since I after τ coincides
with I . If it is the input action (ẽ : D̃)k.a?U then I after µ is I , ẽ:D̃
. There may
be a non-global entry in D̃, a local channel type C. But this can be replaced by the
global entry C@loc.
Also if c@l is new to I it must appear in (ẽ). Therefore we know, because of the
well-definedness of the label µ, that c must be new to I , and therefore is certainly
not a registered resource known to I .
When µ is the output action label (ẽ : D̃)k.a!U , the reason is the same. First
if c@l is new to I in I after µ, which in this case unravels to I , U :I r (a@k)
,
then c@l must again appear in (ẽ). This follows from subject reduction, (3) on
page 199, from which we can deduce that , ẽ:D̃
k U : w (a@k), for some
whose domain coincides with that of I . Secondly the types used in the extended
environment, I r (a@k), can easily be globalised, by replacing each occurrence of C
with C@loc.
the performance of the action labelled α in the environment I will make available
the new information vI (α) at the type tyI (α) at some fresh location. To this end,
when discussing an action labelled α we use Ih to denote the extended environment
I , succ : rc rw tyI (α)
, fail : rc rw
,
h : loc, succ@h : rw tyI (α)
, fail@h : rw
where succ, fail, h are all assumed to be fresh to I . Here the location h may
be viewed as a home base at which information may be collected. But its actual
identity is not important. For if Ih |= M = ∼ N for a particular h, then we can assume
Ih |= M =N for any fresh h , where I is obtained from I in the obvious manner,
∼ h h
by renaming the entries at h, to h . This follows because = ∼ preserved by injective
is
renamings; see Question 10 at the end of the chapter.
Theorem 6.36 (definability in aDpi) Let α denote an external action, (ẽ : D̃)k.a!V
or (ẽ : D̃)k.a?V , and suppose I allows α. Then there is a system T (α) with the
following properties:
1. Ih T (α).
2. If I M is a strict configuration then
α ∗
(a) I M − → a M implies T (α) | M −→ (new ẽ : D̃)(hsucc! vI (α)
| M )
∗
(b) T (α) | M −→ R, where R ⇓ barb h.succ and R ⇓ barb h.fail implies that R is
structurally equivalent to (new ẽ : D̃ )(hsucc! vI (α)
| M ) for some M such
α
that I M =⇒ a M , where α ∼ α .
Proof: First consider the output case. We give the proof for a specific instance
αo = (c@k : C)k.a! c, l
; the general case should be apparent from this example.
Let T (αo ) denote
hfail! | k a?(x, y) if P(x, y, l, I )
then goto h.fail?succ! x@k, y
else stop
Here P(x, y, l, I ) is shorthand for code that checks the incoming values at k, bound
to x and y, are what is expected; the second must be equal to l while the first must be
completely new. This means being completely new at k in the implicit underlying
type environment with respect to which we are working. But since we are restricting
attention to strict configurations this can be checked by ensuring that the first value
is not declared at k in the domain of I . So the testing code can be expressed as
if y = l then (if x ∈ I then goto h.fail?succ! x@k, y
else stop) else stop
where in turn x ∈ I can be coded up as a sequence of tests of x against the names
b such that b@k is in the domain of I . The use of fail in T (αo ) is to be able to
6.7 Justifying bisimulation equivalence contextually in aDpi 237
guarantee, by the absence of a barb on fail, that the output action and subsequent
tests have indeed occurred.
1. It is straightforward to show that the test is well-typed, Ih T (αo ).
2. (a) Suppose I M −α→ o
a N ; recall that synchronous and asynchronous outputs coincide.
Then an application of (l-comm) from Figure 6.2, followed by applications
of the (l-eq), and then (l-move) followed by another (l-comm) to affect the
synchronisation on fail, gives
τ ∗
I T (αo ) | M −→ (new ẽ : D̃)(hsucc! c@k, l
| N )
Now (6) on page 200 can be used to turn these τ moves into reductions.
(b) Finally suppose T (αo ) | M −→∗ R, where R ⇓barb h.succ and R ⇓barb h.fail. Then
τ ∗
by the same point we also know I T (αo ) | M −→ Rτ , where Rτ ⇓barb h.succ
and Rτ ⇓ barb h.fail, since barbs are preserved by structural equivalence. Here the
inability to do a barb on fail is crucial; by examining the possible execution tree we
see that Rτ must be of the form (new ẽ : D̃ )(hsucc! c@k, l
| M ) for some M
for which we can derive I M =α⇒a M , where α ∼ α.
Now let us consider the input case, and again we only consider a typical example,
when αi is (c@k : C, d @l1 : C )k.a?(c, d @l1 , l2 ). Here the test has to generate the
new names, c at k and d at l1 and then send them, together with the existing l2 ,
along a at location k; at the same time it exports the new names, suitably globalised
at h. Let T (αi ) denote the system
hfail! |
goto l1 .(new d : C ) goto k.(new c : C) a! c, d @l1 , l2
|
goto h.fail?succ! c@k, d @l1 , l2
Here we leave the reader to check that T (αi ) has the required properties; the
reasoning is similar to that in the proof of Proposition 6.27. Here the role of fail
is less important; it merely ensures that the various new names, declared locally,
have been exported to the systems level. However the use of the asynchronous
actions-in-context instead of synchronous ones is crucial, as the test T (αi ) cannot
guarantee that the actual communication along a at k has happened.
As in the untyped case for aPi, these tests do not provoke exactly the same
reaction in systems as the actions-in-context they are mimicking. When the test is
applied the bound names of the action still scope the residual of the system. We
need an extrusion lemma, generalising Lemma 2.38, which will allow us to strip
off these from the residuals. It helps to simplify the situation a little if we use a
slightly weaker version of =,
∼ which we call = ∼p .
Definition 6.37 (pcontextuality) A typed relation R is pcontextual if it is preserved
by parallel contexts and a restricted form of weakening. Referring to Definition 6.22,
238 Behavioural equivalences for aDpi
we only require that the first clause and special instances of the third clause be
satisfied. Specifically we say R is pcontextual if it satisfies:
• (Parallel) I |= M R N and I kP implies I |= M | kP R Q | kP and
I |= kP | M R kP | N .
• (Fresh location weakening) I |= M R N implies that for every location type L there is
some l fresh to I such that I, l:L
|= M R N .
Let =∼p be the largest typed relation over processes that is reduction-closed,
preserves typed observations, and is pcontextual. Note that we only require
weakening with respect to some fresh location l. But it turns out that Weakening
follows for arbitrary fresh locations; see Question 10 at the end of the chapter. The
purpose of this restricted form of contextual equivalence is to facilitate the proof
of the following result.
Lemma 6.38 (extrusion for aDpi) Suppose I , V :T
is a standard extension of I ,
and that in the extended environment Ih the type of succ at h is rw T
. If
Ih |= (new ẽ : D̃) M | hsucc! V
=
∼p (new ẽ : D̃ ) N | hsucc! V
,
where each ei occurs in V then I , V :T
|= M =
∼p N .
Proof: We define the typed relation R by letting J |= M R N whenever
(i) J ≡ I, V :T
, for some standard extension of I
(ii) Ih |= (new ẽ : D̃)(M |hsucc! V
) =
∼p (new ẽ : D̃ )(N |hsucc! V
), for some fresh
h, where we assume each ei occurs in V .
and since =
∼p preserves barbs we have
((new ẽ : D̃ )(N | hsucc! V
) | hB) ⇓barb
Ih,h h .succ
But, again because of the design of B, this can only happen if M can produce an
output on a at k, that is M ⇓barb
J k.a.
So let us turn our attention to proving that R is pcontextual. First let us consider
(fresh location weakening). Suppose J |= M R N . We have to show
J , l:L
|= M R N (6.20)
for some l fresh to J ; it is convenient to pick one different from the special name
h. This assumption enables us to assert that
(I , l:L
)h ≡ Ih , l:L
and so in (6.22) k P may use the data V to interact with M and N , although
the hypothesis (6.21) a priori does not compare the behaviour of M and N in the
presence of the knowledge of V . But this knowledge is available on succ at h. We
proceed as in the untyped version of the extrusion lemma, Lemma 2.38. Let Fhk
denote the following system, which delivers the value V from h to the site k:
(a) I, X :T
k PX
(b) I, V :T
|= P ≈bis PX {|V/X |}.
In (a) the use of the typing rule (ty-match) is essential, as we have just explained.
The term PX {|V/X |} does not correspond precisely with P, because of the required
insertions of matchings. But (b) follows because the behaviour of PX {|V/X |} does
mimic that of P precisely except that periodically it has to perform some β-moves
of the form if n = n then Q else 0 −→ Q.
From (a) above it is now straightforward to see that Ih Fhk and so we can
apply pcontextuality to (6.21) to obtain
Since =∼p is preserved by (environment strengthening), from Question 11, the same
identity is also true for the more restricted environment Ih .
Now it is a simple matter of rewriting these system terms in a semantics preserving
manner, to obtain the required result. Exhibiting an explicit bisimulation-up-to-β
6.7 Justifying bisimulation equivalence contextually in aDpi 241
Note that this is true because the location h is not available to the environment; it
does not occur in Ih . Since I |= M1 ≈bis M2 implies I |= M1 = ∼p M2 , the required
(6.22) follows, since the same identity holds for N .
where
Ih |= R =∼p (new ẽ : D̃)(hsucc! vI (α)
| M )
But =∼p also preserves barbs and so we must have R ⇓
barb h.succ and R ⇓barb
6.8 Questions
µ
1. Suppose I M −→ I M .
(i) If µ is the input label (ẽ : D̃)k.a?V , prove
• each ei appears in the domain of V :I w (a@k)
@k
• fn(M ) ⊆ fn(M ) ∪ n(V ).
(ii) If µ is the output label (ẽ : D̃)k.a!V , prove
• each ei appears in the domain of V :I r (a@k)
@k
• fn(M ) ⊆ fn(M ) ∪ bn(ẽ)
• n(V ) ⊆ fn(M ) ∪ bn(ẽ).
(iii) If µ is τ then fn(M ) ⊆ fn(M ).
µ
2. Suppose I M −→ I M , where µ is the label (c@l : C)k.a!c. Show that l and k
must coincide.
3. Use Question 5 from Chapter 5 to prove that whenever the rule (l-out) is applied to a
valid configuration, the result, I V :I r (a@k)
@k kstop, is also a valid configuration.
µ
4. (Weakening) Suppose I M −→ M is an action-in-context for aDpi. Let Im M be
µ
a configuration such that Im <: I. Prove that Im M −→ M is also a valid action-in-
context.
(See Lemma 4.11.)
5. (Fresh strengthening). State and prove a suitable generalisation of (fresh strengthening)
from Lemma 4.11 to the actions in context of aDpi.
6.8 Questions 243
244
Sources 245
discussed in Section 5.5 were first introduced in [15]. The approach to type safety
for aDpi, in Section 5.4, using tagged agents, is also taken directly from [18]. An
alternative approach, in which occurrences of resource names are tagged, was given
in [34], and is reported in [39].
Work on aDpi has been developed further in various directions. As presented
in Chapter 5, the control of behaviour offered by types depends on a global type
environment, and the assurance that all players in a system are well-typed. This is
246 Sources
relaxed in [37], where each domain maintains its own type environment, recording
its current knowledge of the network; this is periodically updated, with the arrival
of new agents. A notion of trust is added to the type of domains, and it is shown
how dynamic typing can protect trusted sites from untyped agents. In [17] aDpi
is extended with the ability to transfer parameterised higher-order code between
domains, which can be instantiated with local parameters by the receiving site.
Within this framework both host and agent security can be maintained by the
use of dependent and existential types. Finally in [23] recursive types have been
added; to appreciate the usefulness of recursive types see Question 4 at the end of
Chapter 5.
Chapter 6: The behavioural theory was originally presented in [15], while the
example proofs come from [1]. This behavioural theory, parameterised with respect
to type environments, should be widely applicable. For example, it has been
extended to the higher-order version of aDpi, already referred to above, in [17].
Finally in [11] it has been extended to a version of the language in which locations,
and the connectivity links between them, may fail.
General methods for reducing the size of witness bisimulation relations were
studied in [38] for CCS and the pi-calculus, and are reported in [39]. Many
of these transfer to aDpi, but care must be taken in the presence of types. Our
technique based on β-moves, in Section 6.3, was influenced by [25], although
similar techniques are widely used in the literature; see for example [14, 13].
aDpi represents only one of the many attempts to add notions of location
or domain to the pi-calculus. The website http://lampwww.epfl.ch/
mobility/ maintains an up-to-date account of research activities in the area.
Here we mention only briefly a sample of the more obviously related approaches.
Nomadic Pict [42, 40] is conceptually closely related to aDpi, in that the space of
domains is flat, and agents migrate between these domains of their own volition.
However, unlike aDpi, agents are explicitly named and these names are used in
inter-agent communication. Nevertheless all communication is still channel-based
and local to particular domains.
On the other hand in Klaim [3, 4], communication is global, in the sense
that agents at different domains may nevertheless communicate. In addition
the underlying communication mechanism is quite different from that in aDpi.
Here every domain maintains a data-set, often called a tuple-space and agents
communicate indirectly by performing a set of pre-defined look-up and update
operations on these spaces.
In the Seal calculus [8], domains are hierarchically organised computational sites
in which inter-seal communication, which is channel-based, is only allowed among
siblings, or between parents and siblings. Seals themselves may be communicated;
Sources 247
248
List of figures 249
Meta-variables:
n, m, a, b, c, l, k Names
x, y, z Vars
bv basic values, integers, etc. Figure 2.2
u, w identifiers, Names ∪ Vars
v simple values Figure 2.2
V values, (v1 , . . . , vn ) Figure 2.2, Figure 5.3
e compound values Figure 5.3
R, S, B terms in aPi Figure 2.1
agent terms in aDpi Figure 5.2
P, Q processes, closed terms in aPi Notation 2.1
agents, closed process terms
in aDpi page 131
M , N, O systems in aDpi Figure 5.2
Mt , Nt tagged systems in tagged-aDpi Figure 5.13
µ, α, αo , αi , τ action labels aPi page 27
typed aPi page 99
T transmission types aDpi page 195
typed aPi Figure 3.2,
Figure 3.6
aDpi Figure 5.6
A value types typed aPi Figure 3.2,
Figure 3.6
aDpi Figure 5.6
C channel types in typed aPi Figure 3.2, Figure 3.6
local channel types in aDpi Figure 5.6
250
Notation 251
Types
a↓b {a, b} has a lower bound Definition 3.19
a↑b {a, b} has an upper bound Definition 3.19
S↓ page 77
T1 ↓ T2 aPi Proposition 3.20
aDpi Proposition 5.9
a b, a b lower/upper bounds Definition 3.19
T 1 T2 , T 1 T 2 aPi Proposition 3.20
aDpi Proposition 5.9
tyI (α) aDpi page 236
vI (α) aDpi page 236
Type environments
V :T aPi Definition 3.2
V :T@k aDpi Definition 5.12
e:T aDpi page 146
I after µ aPi Definition 4.6
aDpi Notation 6.2
I allows µ aPi Definition 4.9
aDpi Notation 6.2
(u), r (u), w (u), (u)↓def aPi Definition 3.25
(e), r (e), w (e), (e)↓def aDpi Definition 5.22
1 <: 2 , 1 ≡ 2 aPi Definition 3.27
page 88
aDpi Definition 5.24
aDpi with registered
names Definition 5.55
252 Notation
Typing:
T <: U typed aPi Figure 3.7
aDpi Figure 5.7
T <: U aDpi with registered
names Figure 5.15
sT : ty aPi Notation 3.1
T : ty aPi Definition 3.16
aDpi Definition 5.8
rc T : ty aDpi page 187
s env typed aPi Figure 3.3
env typed aPi Figure 3.8
aDpi Figure 5.8
aDpi with registered
resources Figure 5.15
s V :T typed aPi Figure 3.4
V :T typed aPi Figure 3.9
w V : T aDpi Figure 5.9
s R : proc typed aPi Figure 3.5
R : proc typed aPi Figure 3.10
w R : proc aDpi Figure 5.11
s M aDpi Figure 5.10
Operational semantics:
P≡Q structural equivalence aPi Figure 2.3
M ≡N aDpi Figure 5.5
Mt ≡ Nt tagged-aDpi Figure 5.13
P −→ Q reduction semantics aPi Figure 2.4
M −→ N aDpi Figure 5.4
Mt −→t Nt tagged-aDpi Figure 5.13
P −→err runtime errors aPi Figure 3.1
M −→err
aDpi Figure 5.12
Mt −→err tagged-aDpi Figure 5.14
Notation 253
Semantic equivalences
un(µ) output type omission aPi page 113
aDpi page 199
µ ∼ µ action equivalence aPi page 199
aDpi page 199
[1] Julian Rathke, Alberto Ciaffaglione, and Matthew Hennessy. Proof methodologies
for behavioural equivalence in distributed pi-calculus. Computer Science Report
3:2005, University of Sussex, 2005.
[2] R. Amadio, I. Castellani, and D. Sangiorgi. On bisimulations for the asynchronous
π -calculus. Theoretical Computer Science, 195:291–324, 1998.
[3] Lorenzo Bettini, Viviana Bono, Rocco De Nicola, Gian Luigi Ferrari, Daniele Gorla,
Michele Loreti, Eugenio Moggi, Rosario Pugliese, Emilio Tuosto, and Betti Venneri.
The klaim project: Theory and practice. In Corrado Priami, ed., Global Computing,
volume 2874 of Lecture Notes in Computer Science, pp. 88–150. Springer, 2003.
[4] Lorenzo Bettini and Rocco De Nicola. Mobile distributed programming in x-klaim.
In Marco Bernardo and Alessandro Bogliolo, eds, SFM, volume 3465 of Lecture
Notes in Computer Science, pp. 29–68. Springer, 2005.
[5] G. Boudol. Asynchrony and the π-calculus. Technical Report 1702, INRIA-Sophia
Antipolis, 1992.
[6] Luca Cardelli and Andrew D. Gordon. Types for mobile ambients. In POPL ’99:
Proceedings of the 26th ACM SIGPLAN-SIGACT symposium on principles of
programming languages, pp. 79–92, New York, NY, USA, 1999. ACM Press.
[7] Luca Cardelli and Andrew D. Gordon. Mobile ambients. Theoretical Computer
Science, 240(1):177–213, 2000.
[8] G. Castagna, J. Vitek, and F. Zappa Nardelli. The seal calculus. Information and
Computation, 201(1):1–54, 2005.
[9] U. Engberg and M. Nielsen. A calculus of communicating systems with
label-passing. Technical Report, Arhus University, 1986.
[10] Uffe H. Engberg and Mogens Nielsen. A calculus of communicating systems with
label passing-ten years after. In Gordon Plotkin, Colin Stirling and Mads Tofte, eds,
Proof, Language, and Interaction; Essays in Honour of Robin Milner, Foundations
of Computing, chapter V, Mobility, pp. 599–622. MIT Press, 2000.
[11] Adrian Francalanza and Matthew Hennessy. A theory of system behaviour in the
presence of node and link failures. In Conference on Concurrency Theory,
pp. 368–382, 2005.
[12] A.D. Gordon and A.S.A. Jeffrey. Types and effects for asymmetric cryptographic
protocols. Journal of Computer Security, 12(3/4):435–484, 2004.
254
Bibliography 255
[13] J.F. Groote and M.P.A. Sellink. Confluence for process verification. Theoretical
Computer Science, 170(1–2):47–81, 1996.
[14] Jan Friso Groote and Jaco van de Pol. State space reduction using partial
tau-confluence. In Mathematical Foundations of Computer Science, pp. 383–393,
2000.
[15] Matthew Hennessy, Massimo Merro, and Julian Rathke. Towards a behavioural
theory of access and mobility control in distributed systems. Theoretical Computer
Science, 322:615–669, 2003.
[16] Matthew Hennessy and Julian Rathke. Typed behavioural equivalences for processes
in the presence of subtyping. Mathematical Structures in Computer Science,
14:651–684, 2004.
[17] Matthew Hennessy, Julian Rathke, and Nobuko Yoshida. Safedpi: A language for
controlling mobile code. Acta Informatica, 42(4-5):227–290, 2005.
[18] Matthew Hennessy and James Riely. Resource access control in systems of mobile
agents. Information and Computation, 173:82–120, 2002.
[19] K. Honda and N. Yoshida. On reduction-based process semantics. Theoretical
Computer Science, 152(2):437–486, 1995.
[20] Kohei Honda and Mario Tokoro. An object calculus for asynchronous
communication. In ECOOP ’91: Proceedings of the European Conference on
Object-Oriented Programming, pp. 133–147, London, UK, 1991. Springer-Verlag.
[21] Kohei Honda and Mario Tokoro. On asynchronous communication semantics. In
P. Wegner, M. Tokoro, and O. Nierstrasz, eds, Proceedings of the ECOOP ’91
Workshop on Object-Based Concurrent Computing, volume 612 of LNCS 612.
Springer-Verlag, 1992.
[22] Kohei Honda and Nobuko Yoshida. A uniform type structure for secure information
flow. In Symposium on Principles of Programming Languages, pp. 81–92, 2002.
[23] Samuel Hym and Matthew Hennessy. Adding recursion to dpi. In Peter D. Mosses
and Irek Ulidowski, eds, Preliminary Proceedings of the Second Workshop on
Structural Operational Semantics, pp. 50–67, 2005. Full version available as
Computer Science Report 2005:06, University of Sussex.
[24] A.S.A. Jeffrey and J. Rathke. Full abstraction for polymorphic pi-calculus. In
Proceedings of Foundations of Software Science and Computation Structures,
volume 3441 of Lecture Notes in Computer Science, pp. 266–281. Springer-Verlag,
2005.
[25] Alan Jeffrey and Julian Rathke. A theory of bisimulation for a fragment of
concurrent ml with local names. Theoretical Computer Science, 323:1–48, 2004.
[26] Naoki Kobayashi. Type systems for concurrent processes: From deadlock-freedom
to livelock-freedom, time-boundedness. In Jan van Leeuwen, Osamu Watanabe,
Masami Hagiya, Peter D. Mosses, and Takayasu Ito, eds, IFIP TCS, volume 1872 of
Lecture Notes in Computer Science, pp. 365–389. Springer, 2000.
[27] Massimo Merro and Francesco Zappa Nardelli. Behavioural theory for mobile
ambients. In Jean-Jacques Lévy, Ernst W. Mayr, and John C. Mitchell, eds, IFIP
TCS, pp. 549–562. Kluwer, 2004.
[28] R. Milner. Communication and Concurrency. Prentice-Hall, 1989.
[29] R. Milner. Comunicating and mobile systems: the π -calculus. Cambridge University
Press, 1999.
[30] R. Milner, J. Parrow, and D. Walker. A calculus of mobile processes, Part I.
Information and Computation, 100(1):1–40, 1992.
256 Bibliography
[31] R. Milner, J. Parrow, and D. Walker. A calculus of mobile processes, Part II.
Information and Computation, 100(1):41–77, 1992.
[32] R. Milner and D. Sangiorgi. Barbed bisimulation. In W. Kuich, ed., Proceedings
19th ICALP, volume 623 of Lecture Notes in Computer Science, pp. 685–695.
Springer-Verlag, 1992.
[33] Robin Milner. The polyadic π-calculus: a tutorial. In Proceedings International
Summer School on Logic and Algebra of Specification, Marktoberdorf, 1991.
[34] B. Pierce and D. Sangiorgi. Typing and subtyping for mobile processes. Journal of
Mathematical Structures in Computer Science, 6(5):409–454, 1996. An extended
abstract in Proceedings LICS 93, IEEE Computer Society Press.
[35] B. Pierce and D. Sangiorgi. Behavioral equivalence in the polymorphic pi-calculus.
Journal of the ACM, 47(3):531–584, 2000.
[36] B.C. Pierce. Types and programming languages. The MIT Press, 2002.
[37] James Riely and Matthew Hennessy. Trust and partial typing in open systems of
mobile agents. Journal of Automated Reasoning, 31:335–370, 2003.
[38] D. Sangiorgi. On the bisimulation proof method. Mathematical Structures in
Computer Science, 8:447–479, 1998.
[39] D. Sangiorgi and D. Walker. The π -calculus: a Theory of Mobile Processes.
Cambridge University Press, 2001.
[40] Peter Sewell, Paweł T. Wojciechowski, and Benjamin C. Pierce.
Location-independent communication for mobile agents: a two-level architecture. In
Internet Programming Languages, LNCS 1686, pp. 1–31. Springer-Verlag, October
1999.
[41] G. Winskel. The Formal Semantics of Programming Languages. The MIT Press,
1992.
[42] Paweł T. Wojciechowski and Peter Sewell. Nomadic Pict: Language and
infrastructure design for mobile agents. In Proceedings of ASA/MA 99: Agent
Systems and Applications/Mobile Agents (Palm Springs), pp. 2–12, October 1999.
Index
257
258 Index