Upload
others
View
0
Download
0
Embed Size (px)
Citation preview
An introduction to process calculi:Calculus of Communicating Systems
(CCS)Lecture 2 of Modelli Matematici dei Processi
Concorrenti
Paweł Sobocinski
University of Southampton, UK
Intro to process calculi: CCS – p.1/25
Introduction
In the first lecture we discussed behavioural preordersand equivalences, in particular bisimilarity.
This lecture is an introduction to a well-knownprocess-calculus, the Calculus of CommunicatingSystems (CCS) introduced by Robin Milner in the early1980’s.
Process calculi:a pseudo-programming language which usuallyfocuses on a small language feature;usually try to eliminate syntactic sugar and extraprogrammer-friendly features;idea is to isolate basic principles and reasoningtechniques.
Intro to process calculi: CCS – p.2/25
CCS
focuses on a very simple paradigm of synchronoushandshakes.
processes a?P and a!Q, when executing in parallel(a?P ‖ a!Q);
can synchronise their execution by synchronisingon channel a;after the synchronisation continue as P and Q,respectively;a?P ‖ a!Q → P ‖ Q;
Intro to process calculi: CCS – p.3/25
CCS syntax
Assume that we have a set of names A and a countable setof process variables.
P ::= 0 | a?P | a!P | P ‖ P | P + P | νaP | X | µX.P
NB. sometimes a?P is written aP and a!P is written aP . Inearly texts νaP is written P\a.
a?P : input on a and proceed as P ;
a!P : output on a and proceed as P ;
τP : perform an internal reduction and proceed as P ;
P1 ‖ P2 : put P1 and P2 in parallel;
P1 + P2 : act either as P1 or as P2;
νaP : treat a as a local channel visible only in P ;Intro to process calculi: CCS – p.4/25
Recursion
Infinite behaviour can be added to CCS in several(nonequivalent) ways.
P ::= . . . | X | µX.P
The expression µX.P stands for treats the X as a recursivevariable in P .
Idea:
µX.a?X “ ≡ ” a?a? . . . ;
µX.P ‖ X “ ≡ ” P ‖ P ‖ . . . ;
µX.a!(b?X + c?X) “ ≡ ” ?
Intro to process calculi: CCS – p.5/25
Contexts and Congruences
Definition 1 (Contexts).
C ::= − | P ‖ C | C ‖ P | C + P | P + C | νaC |a?C | a!C
Definition 2 (Substitution). Given a term P and a context C , let C[P ]denote the term obtained by substituting P for −. Free names may becaptured!
Definition 3. A relation R on the terms of CCS is said to be acongruence when
PRQ ⇒ σ(P )Rσ(Q)
for all operations σ of CCS. More formally, if PRQ then C[P ]RC[Q] forall contexts C .
Intro to process calculi: CCS – p.6/25
Structural congruence
P ‖ Q denotes the same system as Q ‖ P ;
We quotient the “raw” syntax via a relation which is acongruence with respect to the operations of CCS.
Definition 4 (SC). Let ≡ be the smallest congruence which includes thefollowing:
(P ‖ Q) ‖ R ≡ P ‖ (Q ‖ R) P ‖ Q ≡ Q ‖ P P ‖ 0 ≡ P
(P + Q) + R ≡ P + (Q + R) P + Q ≡ Q + P P + 0 ≡ P
νa(P ‖ Q) ≡ (νaP ) ‖ Q (a /∈ Q) νaP ≡ νbP [b/a] (b /∈ P )
µX.P ≡ P [µX.P/X]
Remark 5. Contexts are not quotiented by SC. This is because we wantthe contexts to have the power to bind.
Intro to process calculi: CCS – p.7/25
Reduction semantics 1
Idea, basic reduction:
a?P1 + P2 ‖ a!Q1 + Q2 → P1 ‖ Q1
Letting
la,P1,P2,Q1,Q2
def= a?P1 + P2 ‖ a!Q1 + Q2
ra,P1,P2,Q1,Q2
def= P1 ‖ Q1
we want, for all a, P1, P2, Q1, Q2
la,P1,P2,Q1,Q2→ ra,P1,P2,Q1,Q2
Intro to process calculi: CCS – p.8/25
Reduction semantics 2
But parallel composition shouldn’t inhibit reduction, so thatif P → P ′ then for all Q we should also haveP ‖ Q → P ′ ‖ Q. Similarly, νaP → νaP ′.
Evaluation contexts:
E ::= − ‖ P | νa−
Definition 6. P → P ′ iff ∃a, P1, P2, Q1, Q2 and evaluation context Esuch that P ≡ E[la,P1,P2,Q1,Q2
] and P ′ ≡ E[ra,P1,P2,Q1,Q2].
Intro to process calculi: CCS – p.9/25
SOS
There is a useful way of presenting the reduction semanticsusing structural operational semantics (SOS).
a?P1+P2‖a!Q1+Q2→P1‖Q1
P→P ′
P‖Q→P ′‖Q
P→P ′
νaP→νaP ′
The rules above generate a transition system (which wecan think of as an LTS with only one label);
we will refer to this as the reduction transition system.
Intro to process calculi: CCS – p.10/25
Examples
c t
s
c t
s s
M1def= s?(c! + t!) M2
def= s?c! + s?t!
Coffee drinker C1def= s!c?0;
Simulation 1: C1 ‖ M1 → c?0 ‖ (c!0 + t!0) → 0
Simulation 2: C1 ‖ M2 → c?0 ‖ t!0
Intro to process calculi: CCS – p.11/25
Process equivalence?
What is a good notion of process equivalence?we can try bisimilarity on the reduction LTS...but then, for instance, a!P ∼ b!P . In fact, allprocesses which do not reduce are bisimilar. Clearly,this is not sufficient.
Intro to process calculi: CCS – p.12/25
Contextual equivalence
A canonical process equivalence for a process language iscontextual equivalence . The idea originally arose in thetheory of the λ-calculus.
Idea: Processes P and Q can be distinguished if in somecontext C they “behave differently”.
we can try taking the largest bisimulation which is alsoa congruence ;
this almost works, the problem is that processes whichcan always reduce are equated;
Intro to process calculi: CCS – p.13/25
Reduction barbed congruence
One sensible definition of a contextual equivalence for CCSis reduction barbed congruence .Definition 7. A barb is a basic observation. In CCS it makes sense totake the instantaneous ability to input or output on a name. We say that
P ↓a iff P ≡ νk(a!P1 + P2 ‖ P3) or P ≡ νk(a?P1 + P2 ‖ P3) anda /∈ k.
Definition 8. Reduction barb congruence Let ∼= be the largestequivalence relation which is
a congruence;
barb-closed: if P ∼= Q and P ↓a then Q↓a;
reduction-closed: if P ∼= Q and P → P ′ then ∃Q′, Q → Q′ andQ ∼= Q′ (for all contexts C , C[P ] ∼= C[Q], bisimulation on thereduction LTS)
Intro to process calculi: CCS – p.14/25
Examples
Claim 9 (Firewall). νa.a! ∼= 0.
Proof. ?
Intro to process calculi: CCS – p.15/25
Problems with contextual equivalence
∼= is a priori defined to be a congruence;
thus, in principle, to check that P ∼= Q we have to have aproof which takes into account an infinite number ofarbitrarily complex contexts C
Intro to process calculi: CCS – p.16/25
LTS characterisation
We will give a labelled transition system on whichbisimulation characterises contextual equivalence, ie
it is sound : ∼⊆∼=;
it is complete : ∼=⊆∼.
Intro to process calculi: CCS – p.17/25
LTS for CCS
(IN)a?P
a?
−→P(OUT)
a!Pa!
−→P
Pa!
−→P ′ Qa?
−→Q′
(TAU)P‖Q
τ
−→P ′‖Q′
Pα
−→P ′
(PAR)P‖Q
α
−→P ′‖Q
Pα
−→P ′ (a/∈α)(NU)
νaPα
−→νaP ′
P≡P ′ P ′α
−→Q′ Q′≡Q(STRCONG)
Pα
−→Q
Intro to process calculi: CCS – p.18/25
Example
Lemma 10 (Firewall). νa.a! ∼ 0
Proof. Obvious, since both sides do not have any transitions.
Lemma 11 (Expansion). If a 6= b then a? ‖ b! ∼ a?b! + b!a?.
Proof. {(a? ‖ b!, a?b! + b!a?), (b!, b!), (a?, a?), (0, 0)} is abisimulation.
Intro to process calculi: CCS – p.19/25
Proof of soundness
Theorem 12. ∼ is a congruence.
Proof. We’ll do the case − ‖ Q. We will prove thatR = {(P1 ‖ R,P2 ‖ R), P1 ∼ P2} is a bisimulation.
Suppose that P1 ‖ Qα−→ R. We’ll do the case α = τ . If P1
τ−→ P ′
1 and
R ≡ P ′1 ‖ Q then also P2
τ−→ P ′
2 such that P ′1 ∼ P ′
2. Then
P2 ‖ Qτ−→ P ′
2 ‖ Q, but (R,P ′2 ‖ Q) ∈ R.
The case Qτ−→ Q′ such that R ≡ P1 ‖ Q′ is similar.
The other possibility is, P1a!−→ P ′
1 and Qa?−→ Q′ and R ≡ P ′
1 ‖ Q′. But
then P2a!−→ P ′
2 such that P ′1 ∼ P ′
2 and so P2 ‖ Qτ−→ P ′
2 ‖ Q′.
(note the case P1a?−→ P ′
1, Qa!−→ Q′ is symmetric)
Intro to process calculi: CCS – p.20/25
Congruent bisimilarities
Having a congruent bisimilarity is quite useful becauseit allows the use of a familiar algebraic principle –substituting “equal for equal”.
It can also reduce the burden of constructingbisimulations since bisimulations can be deconstructed:
Example 13. If P1 ∼ Q1 and P2 ∼ Q2 then P1 ‖ P2 ∼ Q1 ‖ Q2.
Proof. P1 ‖ P2 ∼ Q1 ‖ P2 ∼ Q1 ‖ Q2.
Intro to process calculi: CCS – p.21/25
Proof of soundness
Lemma 14. P ↓a iff Pa!−→ or P
a?−→.
Lemma 15. Pτ−→ P ′ iff P → P ′.
Theorem 16. ∼⊆∼=.
Proof. Recall that ∼= is defined to be the largest barb and reductionclosed congruence. ∼ is reduction and barbed closed (the two lemmas)and is a congruence. Hence ∼⊆∼=.
Intro to process calculi: CCS – p.22/25
Proof of completeness
Theorem 17. ∼=⊆∼.
We need to make sure that the label transitions do not ob-
serve too much about the processes. Hence for each label
α, we’ll find a context which “observes” the label.
Intro to process calculi: CCS – p.23/25
Weak equivalences
“Weak” in the jargon of process calculists means thatinternal reductions are not observable.
Definition 18 (Weak bisimulation). A relation R is a weak bisimulationwhen
PRQ and Pτ−→ P ′ then Q
τ−→
∗Q′
PRQ and Pα−→ P ′ (α 6= τ) then Q
τ−→
∗ α−→
τ−→
∗Q′;
the symmetric versions of the above hold.
Definition 19. We will write τP for νa(a!‖a?P ) where a is fresh for P .
Example 20.
τa! ≈ a!.
Intro to process calculi: CCS – p.24/25
Weak bisimilarity not a congruence
The counterexample is very simple, we have τa! ≈ a!, but
τa!+b! 6 ≈a!+b!. Weak bisimilarity behaves better with respect
to other operators.
Intro to process calculi: CCS – p.25/25