You are on page 1of 5

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/228720630

Concurrent pattern calculus in bondi

Article · January 2010

CITATIONS READS
2 59

1 author:

Thomas Given-Wilson
Université Catholique de Louvain - UCLouvain
47 PUBLICATIONS   188 CITATIONS   

SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Wire-speed Packing Detection View project

ACANTO View project

All content following this page was uploaded by Thomas Given-Wilson on 07 October 2014.

The user has requested enhancement of the downloaded file.


Concurrent pattern calculus in bondi

Thomas Given-Wilson
QCIS & School of Software, University of Technology, Sydney, Australia
Thomas.Given-Wilson@uts.edu.au

In concurrent pattern calculus two processes interact through pattern unification. This atomic interac-
tion supports input, output and tests for equality to be performed by both processes simultaneously, as
is natural when exchange or trade. The bondi programming language has been augmented to support
concurrent pattern calculus.

Introduction
The concurrent pattern calculus (CPC) [3] drives interaction by pattern unification. This allows input,
output and tests for equality for be performed simultaneously as an atomic interaction. Such interaction
is natural in trade where both parties exchange information. This paper presents an augmentation of the
bondi programming language [1] to support CPC.

The concurrent pattern calculus


The concurrent pattern calculus generalises the π-calculus [6] by replacing the input and output prefixes
by patterns and with interaction driven by pattern unification. The resulting calculus supports exchange
while supporting encodings of many popular process calculi such as π-calculus, spi calculus [4] and
Linda [2].
The generalisation of prefixes requires the pattern unification support input, output and tests for
equality. This is best illustrated through the translation of π-calculus prefixes into CPC cases p → P with
pattern p and body P:

[[n(x).P]] = (pnq • λ x • z) → [[P]] fresh z


[[nhyi.P]] = (pnq • y • λ z) → [[P]] fresh z .

The channel name n is translated into a protected name pnq that can only be checked for equality in
unification. The input x is translated into a binding name λ x that binds in unification. The output name y
is translated to a variable name y that may be bound or tested for equality in unification. The components
of patterns are combined into one using the compound •. The fresh name z prevents translated outputs
matching against other outputs.
More formally the patterns p, q and processes P, Q of CPC are given by

p, q ::= x | pxq | λ x | p • q
P, Q ::= 0 | P|Q | !P | (νx)P | p → P .

The unification of two patterns p and q seeks substitutions for the binding names in p and q to unify
them. A variable name x can be unified with x or pxq to generate empty substitutions. Similarly a
protected name pxq can be unified with x or pxq. A binding name λ x binds any pattern that contains

Submitted to:
YR-CONCUR 2010
2 Concurrent pattern calculus in bondi

no protected or binding names. Compounds are unified component wise. Otherwise the unification is
undefined.
The interaction rule is given by

p→P|q→Q 7−→ σ P | ρQ

where σ and ρ are substitutions generated by unifying p and q. If the patterns cannot be unified then no
interaction occurs.

A simple trade example


Consider two traders interested in trading shares of the ABC company. A seller who wishes to sell 100
ABC shares at $0.38 and receive some bank account information, can be represented by

(ABC • 100 • $0.38 •Cert • λ a) → S(a) .

A buyer who seeks a price to purchase 100 ABC shares with bank account information b, can be repre-
sented by
(pABCq • 100 • λ p • λ c • b) → B(p, c) .
Of course S(a) and B(p, c) represent successful completion for the seller and buyer respectively. Their
interaction is

ABC • 100 • $0.38 •Cert • λ a → S(a) | pABCq • 100 • λ p • λ c • b → B(c)


7−→ {b/a}S(a) | {$0.38/p,Cert/c}B(p, c)
= S(b) | B($0.38, Cert) .

The traders have matched the company name and number of shares, while exchanging information about
the price and certificates for the bank account.

CPC in bondi syntax


The bondi language has syntax similar to that of Objective Caml [7]. The patterns of CPC are represented
in bondi as follows
[[x]] = x [[λ x]] = \x
[[pxq]] = ~x [[p • q]] = [[p]] [[q]] .

All the names are represented by bondi variables with annotations to differentiate variable x, protected
~x, and binding \x status. Compounds are represented by application as this aligns with bondi’s support
for static patterns such as in | x y -> ... where x and y bind to the components of data structures [5].
Although CPC patterns are syntactically restricted to bondi variables, their value is used at unification
so any bondi value can be used in practice.
The processes of CPC are represented as follows

[[P|Q]] = ([[P]]) | ([[Q]])


[[!P]] = ![[P]]
[[(νx)P]] = rest x in [[P]]
[[p → P]] = cpc [[p]] −> [[P]] .
T. Given-Wilson 3

The parallel composition and replication syntax translate directly. The restriction is styled after let dec-
larations. CPC cases are denoted with the keyword cpc followed by the representations of the pattern
and body separated by the arrow. Any bondi program may be used as the body of a case, thus the null
process is represented by any bondi program that performs no interaction.

Concurrent trading in bondi


The traders can now be represented in bondi with the following code.
let comp = "ABC";;
let numb = 100;;
let price = 0.38;;
let cert = "ABC Share Certificates numbers 1100-1199";;
let seller x = cpc comp numb price cert \a -> print(x^": sold shares");;
let buyer x = rest b in cpc ~comp numb \p \c b -> print(x^": bought "^c);;
The result of instantiating these processes in bondi is
~~ buyer "Buyer 1";seller "Seller 1";;
it: Unit
"Seller 1: sold shares"
"Buyer 1: bought ABC Share Certificates numbers 1100-1199"
~~
where ~~ is the bondi interpreter prompt.
The implementation in bondi is through a CPC engine that manages a process space containing all the
active processes. The engine loops through; adding queued processes, checking each process for internal
reductions, attempting interaction between processes, and cleaning up (non-replicating) processes that
have interacted. More than one such CPC engine is operating at once to allow greater concurrency.
A more interesting example is running sellers 1 to 5 that trade the shares
let cert1 = "ABC Share Certificates numbers 1100-1199";;
let cert2 = "ABC Share Certificates numbers 1200-1299";;
let cert3 = "ABC Share Certificates numbers 1300-1399";;
let cert4 = "ABC Share Certificates numbers 1400-1499";;
let cert5 = "ABC Share Certificates numbers 1500-1599";;
respectively. Running in parallel with buyers A,B,C,D and E results in:
"Seller 1: sold shares"
"Buyer E: bought ABC Share Certificates numbers 1100-1199"
"Seller 5: sold shares"
"Buyer D: bought ABC Share Certificates numbers 1500-1599"
"Seller 4: sold shares"
"Buyer C: bought ABC Share Certificates numbers 1400-1499""
Seller 3: sold shares"
"Buyer B: bought ABC Share Certificates numbers 1300-1399"
"Seller 2: sold shares"
"Buyer A: bought ABC Share Certificates numbers 1200-1299"
where all the buyers and sellers have found trade partners.
4 Concurrent pattern calculus in bondi

Conclusion
The concurrent pattern calculus uses pattern unification to drive interaction allowing for symmetric in-
formation exchange. The bondi programming language can be augmented to support CPC, allowing
support for applications that trade information. Future work may include using bondi to implement
larger scale solutions to concurrent applications, or expanding bondi to support distributed computation.

References
[1] (2010). bondi. Available at bondi.it.uts.edu.au. Retrieved 19 June 2010, from http://bondi.it.uts.edu.au/.
[2] David Gelernter (1985): Generative communication in Linda. ACM Trans. Program. Lang. Syst. 7(1), pp.
80–112.
[3] Thomas Given-Wilson, Daniele Gorla & Barry Jay (2010): Concurrent Pattern Calculus. In: C. Calude &
V. Sassone, editors: Proc. of 6th International IFIP Conference on Theoretical Computer Science (IFIP-TCS
2010), IFIP, Springer.
[4] A.D. Gordon & M. Abadi (1997): A calculus for cryptographic protocols: The spi calculus. 4th ACM Con-
ference on Computer and Communications Security , pp. 36 – 47.
[5] Barry Jay (2009): Pattern Calculus: Computing with Functions and Data Structures. Springer.
[6] Robin Milner, Joachim Parrow & David Walker (1992): A calculus of mobile processes, I–II. Information and
Computation 100(1), pp. 1–77.
[7] The Caml language (2010). The Caml language: Home. Retrieved 19 June 2010, from http://caml.inria.fr/.

View publication stats

You might also like