An introduction to process calculi: Calculus of Communicating Systems (CCS) Lecture 2 of Modelli Matematici dei Processi Concorrenti Paweł Sobociński University of Southampton, UK Intro to process calculi: CCS p.1/25
Introduction In the first lecture we discussed behavioural preorders and equivalences, in particular bisimilarity. This lecture is an introduction to a well-known process-calculus, the Calculus of Communicating Systems (CCS) introduced by Robin Milner in the early 1980 s. Process calculi: a pseudo-programming language which usually focuses on a small language feature; usually try to eliminate syntactic sugar and extra programmer-friendly features; idea is to isolate basic principles and reasoning techniques. Intro to process calculi: CCS p.2/25
CCS focuses on a very simple paradigm of synchronous handshakes. processes a?p and a!q, when executing in parallel (a?p a!q); can synchronise their execution by synchronising on 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 set of 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. In early 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 ; P 1 P 2 : put P 1 and P 2 in parallel; P 1 + P 2 : act either as P 1 or as P 2 ; ν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 recursive variable 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 be captured! Definition 3. A relation R on the terms of CCS is said to be a congruence when P RQ σ(p)rσ(q) for all operations σ of CCS. More formally, if PRQ then C[P]RC[Q] for all 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 a congruence with respect to the operations of CCS. Definition 4 (SC). Let be the smallest congruence which includes the following: (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 want the contexts to have the power to bind. Intro to process calculi: CCS p.7/25
Reduction semantics 1 Idea, basic reduction: a?p 1 + P 2 a!q 1 + Q 2 P 1 Q 1 Letting l a,p1,p 2,Q 1,Q 2 def = a?p 1 + P 2 a!q 1 + Q 2 r a,p1,p 2,Q 1,Q 2 def = P 1 Q 1 we want, for all a,p 1,P 2,Q 1,Q 2 l a,p1,p 2,Q 1,Q 2 r a,p1,p 2,Q 1,Q 2 Intro to process calculi: CCS p.8/25
Reduction semantics 2 But parallel composition shouldn t inhibit reduction, so that if P P then for all Q we should also have P Q P Q. Similarly, νap νap. Evaluation contexts: E ::= P νa Definition 6. P P iff a,p 1,P 2,Q 1,Q 2 and evaluation context E such that P E[l a,p1,p 2,Q 1,Q 2 ] and P E[r a,p1,p 2,Q 1,Q 2 ]. Intro to process calculi: CCS p.9/25
SOS There is a useful way of presenting the reduction semantics using structural operational semantics (SOS). a?p 1 +P 2 a!q 1 +Q 2 P 1 Q 1 P P P Q P Q P P νap νap The rules above generate a transition system (which we can 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 s s s c t c t M 1 def = s?(c! + t!) M 2 def = s?c! + s?t! Coffee drinker C 1 def = s!c?0; Simulation 1: C 1 M 1 c?0 (c!0 + t!0) 0 Simulation 2: C 1 M 2 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, all processes 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 is contextual equivalence. The idea originally arose in the theory of the λ-calculus. Idea: Processes P and Q can be distinguished if in some context C they behave differently. we can try taking the largest bisimulation which is also a congruence; this almost works, the problem is that processes which can always reduce are equated; Intro to process calculi: CCS p.13/25
Reduction barbed congruence One sensible definition of a contextual equivalence for CCS is reduction barbed congruence. Definition 7. A barb is a basic observation. In CCS it makes sense to take the instantaneous ability to input or output on a name. We say that P a iff P νk(a!p 1 + P 2 P 3 ) or P νk(a?p 1 + P 2 P 3 ) and a / k. Definition 8. Reduction barb congruence Let = be the largest equivalence 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 and Q = Q (for all contexts C, C[P] = C[Q], bisimulation on the reduction 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 a proof which takes into account an infinite number of arbitrarily complex contexts C Intro to process calculi: CCS p.16/25
LTS characterisation We will give a labelled transition system on which bisimulation characterises contextual equivalence, ie it is sound: =; it is complete: =. Intro to process calculi: CCS p.17/25
LTS for CCS a?p a? P (IN) a!p a! P (OUT) P a! P Q a? Q (TAU) P Q τ P Q P α P P Q α P Q (PAR) P α P νap α νap (a/ α) (NU) 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 b then a? b! a?b! + b!a?. Proof. {(a? b!,a?b! + b!a?), (b!,b!), (a?,a?), (0, 0)} is a bisimulation. 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 that R = {(P 1 R,P 2 R),P 1 P 2 } is a bisimulation. Suppose that P 1 Q α R. We ll do the case α = τ. If P 1 τ P 1 and R P 1 Q then also P 2 τ P 2 such that P 1 P 2. Then P 2 Q τ P 2 Q, but (R,P 2 Q) R. The case Q τ Q such that R P 1 Q is similar. The other possibility is, P 1 a! P 1 and Q a? Q and R P 1 Q. But then P 2 a! P 2 such that P 1 P 2 and so P 2 Q τ P 2 Q. (note the case P 1 a? P 1, Q a! Q is symmetric) Intro to process calculi: CCS p.20/25
Congruent bisimilarities Having a congruent bisimilarity is quite useful because it allows the use of a familiar algebraic principle substituting equal for equal. It can also reduce the burden of constructing bisimulations since bisimulations can be deconstructed: Example 13. If P 1 Q 1 and P 2 Q 2 then P 1 P 2 Q 1 Q 2. Proof. P 1 P 2 Q 1 P 2 Q 1 Q 2. Intro to process calculi: CCS p.21/25
Proof of soundness Lemma 14. P a iff P a! or P a?. Lemma 15. P τ P iff P P. Theorem 16. =. Proof. Recall that = is defined to be the largest barb and reduction closed 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 observe 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 that internal reductions are not observable. Definition 18 (Weak bisimulation). A relation R is a weak bisimulation when PRQ and P τ P then Q τ Q PRQ and P α P (α τ) 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! a!+b!. Weak bisimilarity behaves better with respect to other operators. Intro to process calculi: CCS p.25/25