The Calculus of Communicating Systems Dr. Liam OConnor University - - PowerPoint PPT Presentation

the calculus of communicating systems dr liam o connor
SMART_READER_LITE
LIVE PREVIEW

The Calculus of Communicating Systems Dr. Liam OConnor University - - PowerPoint PPT Presentation

CCS The Calculus of Communicating Systems Dr. Liam OConnor University of Edinburgh LFCS (and UNSW) Term 2 2020 1 CCS Where we are at Last lecture we concluded our examination of proof methods for concurrency by examining compositional


slide-1
SLIDE 1

CCS

The Calculus of Communicating Systems

  • Dr. Liam O’Connor

University of Edinburgh LFCS (and UNSW) Term 2 2020

1

slide-2
SLIDE 2

CCS

Where we are at

Last lecture we concluded our examination of proof methods for concurrency by examining compositional techniques. We also discussed how to prove properties of asynchronous systems. This lecture, we’ll take a brief detour into the world of process algebra, a high level formalism for describing concurrent systems. In particular we will examine CCS, but similar principles apply for other formalisms like CSP and ACP. Many of the resources for this lecture were borrowed from Graham Hutton.

2

slide-3
SLIDE 3

CCS

CCS

The Calculus of Communicating Systems: Is a process algebra, a simple formal language to describe concurrent systems.

3

slide-4
SLIDE 4

CCS

CCS

The Calculus of Communicating Systems: Is a process algebra, a simple formal language to describe concurrent systems. Is given semantics in terms of labelled transition systems.

4

slide-5
SLIDE 5

CCS

CCS

The Calculus of Communicating Systems: Is a process algebra, a simple formal language to describe concurrent systems. Is given semantics in terms of labelled transition systems. Was developed by Turing-award winner Robin Milner in the 1980s. Has an abstract view of synchronization that applies well to message passing.

5

slide-6
SLIDE 6

CCS

CCS

The Calculus of Communicating Systems: Is a process algebra, a simple formal language to describe concurrent systems. Is given semantics in terms of labelled transition systems. Was developed by Turing-award winner Robin Milner in the 1980s. Has an abstract view of synchronization that applies well to message passing. Why do we learn this? This gives us a symbolic way to describe our transition diagrams, and reason about them symbolically rather than diagramatically.

6

slide-7
SLIDE 7

CCS

Processes

Processes in CCS are defined by equations: Example The equation: CLOCK = tick defines a process CLOCK that simply executes the action “tick” and then terminates. This process corresponds to the first location in this labelled transition system (LTS):

  • tick

An LTS is like a transition diagram, save that our transitions are just abstract actions and we have no initial or final location.

7

slide-8
SLIDE 8

CCS

Action Prefixing

Example CLOCK2 = tick.tock defines a process called CLOCK2 that executes the action “tick” then the action “tock” and then terminates.

  • tick

tock The process: CLOCK3 = tock.tick has the same actions as CLOCK2 but arranges them in another order.

slide-9
SLIDE 9

CCS

Action Prefixing

Example CLOCK2 = tick.tock defines a process called CLOCK2 that executes the action “tick” then the action “tock” and then terminates.

  • tick

tock The process: CLOCK3 = tock.tick has the same actions as CLOCK2 but arranges them in another order. Definition If a is an action and P is a process, then x.P is a process that executes x before P. This brackets to the right, so: x.y.z.P = x.(y.(z.P))

slide-10
SLIDE 10

CCS

Action Prefixing

Example CLOCK2 = tick.tock defines a process called CLOCK2 that executes the action “tick” then the action “tock” and then terminates.

  • tick

tock The process: CLOCK3 = tock.tick has the same actions as CLOCK2 but arranges them in another order. Definition If a is an action and P is a process, then x.P is a process that executes x before P. This brackets to the right, so: x.y.z.P = x.(y.(z.P)) Stopping More precisely, we should write: CLOCK2 = tick.tock.STOP where STOP is the trivial process with no transitions.

10

slide-11
SLIDE 11

CCS

Loops

Up to now, all processes make a finite number of transitions and then terminate. Processes that can make a infinite number of transitions can be pictured by allowing loops: Example (Loops)

  • tick

the process that diverges executing “tick” transitions

=

  • tick

tock tick

= the process that alternates

“tick” and “tock” forever We accomplish loops in CCS using recursion.

slide-12
SLIDE 12

CCS

Loops

Up to now, all processes make a finite number of transitions and then terminate. Processes that can make a infinite number of transitions can be pictured by allowing loops: Example (Loops)

  • tick

the process that diverges executing “tick” transitions

=

  • tick

tock tick

= the process that alternates

“tick” and “tock” forever CLOCK4 = tick.CLOCK4 CLOCK5 = tick.tock.CLOCK5 We accomplish loops in CCS using recursion.

12

slide-13
SLIDE 13

CCS

Equality of Processes

These two processes are physically different:

  • tick
  • tick

tick tick CLOCK4 = tick.CLOCK4 CLOCK6 = tick.tick.CLOCK6

13

slide-14
SLIDE 14

CCS

Equality of Processes

These two processes are physically different:

  • tick
  • tick

tick tick CLOCK4 = tick.CLOCK4 CLOCK6 = tick.tick.CLOCK6 But they both have the same behaviour — an infinite sequence of “tick” transitions.

14

slide-15
SLIDE 15

CCS

Equality of Processes

These two processes are physically different:

  • tick
  • tick

tick tick CLOCK4 = tick.CLOCK4 CLOCK6 = tick.tick.CLOCK6 But they both have the same behaviour — an infinite sequence of “tick” transitions. Informal Definition We consider two process to be equal if an external observer cannot distinguish them by their actions. We will refine this definition later.

15

slide-16
SLIDE 16

CCS

A Simple Vending Machine

Vending Machines are very common examples for process algebra. Example (An inflexible machine) Suppose I define my vending machine as: VM1 = in50¢.outCoke.in20¢.outMars.VM1

  • in50¢
  • utCoke

in20¢

  • utMars

16

slide-17
SLIDE 17

CCS

A Simple Vending Machine

Vending Machines are very common examples for process algebra. Example (An inflexible machine) Suppose I define my vending machine as: VM1 = in50¢.outCoke.in20¢.outMars.VM1

  • in50¢
  • utCoke

in20¢

  • utMars

This machine is not very flexible: It only accepts exact money. The customer has no choice: The machine dispenses Coke and Mars bars alternately.

17

slide-18
SLIDE 18

CCS

Choice

To make a more flexible kind of vending machine, we need a (nondeterministic) choice

  • perator.

18

slide-19
SLIDE 19

CCS

Choice

To make a more flexible kind of vending machine, we need a (nondeterministic) choice

  • perator.

Example VM2 = (in50¢.outCoke.VM2) + (in20¢.outMars.VM2)

  • in50¢
  • utCoke

in20¢

  • utMars

Here we have a process VM2 that repeatedly either inputs 50¢ and outputs a coke, or inputs 20¢ and outputs a mars bar.

19

slide-20
SLIDE 20

CCS

Choice

To make a more flexible kind of vending machine, we need a (nondeterministic) choice

  • perator.

Example VM2 = (in50¢.outCoke.VM2) + (in20¢.outMars.VM2)

  • in50¢
  • utCoke

in20¢

  • utMars

Here we have a process VM2 that repeatedly either inputs 50¢ and outputs a coke, or inputs 20¢ and outputs a mars bar. Definition If P and Q are processes then P + Q is a process which can either behave as the process P or the process Q.

20

slide-21
SLIDE 21

CCS

Choice Equalities

Observe that we have the following identities about choice: P + (Q + R) = (P + Q) + R (associativity)

21

slide-22
SLIDE 22

CCS

Choice Equalities

Observe that we have the following identities about choice: P + (Q + R) = (P + Q) + R (associativity) P + Q = Q + P (commutativity)

22

slide-23
SLIDE 23

CCS

Choice Equalities

Observe that we have the following identities about choice: P + (Q + R) = (P + Q) + R (associativity) P + Q = Q + P (commutativity) P + STOP = P (neutral element)

23

slide-24
SLIDE 24

CCS

Choice Equalities

Observe that we have the following identities about choice: P + (Q + R) = (P + Q) + R (associativity) P + Q = Q + P (commutativity) P + STOP = P (neutral element) P + P = P (idempotence)

24

slide-25
SLIDE 25

CCS

Choice Equalities

Observe that we have the following identities about choice: P + (Q + R) = (P + Q) + R (associativity) P + Q = Q + P (commutativity) P + STOP = P (neutral element) P + P = P (idempotence) What about the equation: a.(P + Q)

  • (a.P) + (a.Q)

?

=

  • a

a a P Q P Q

?

=

25

slide-26
SLIDE 26

CCS

Branching Time

Example VM3 = in50¢.(outCoke + outPepsi) VM4 = (in50¢.outCoke) + (in50¢.outPepsi) Or in pictures:

  • in50¢
  • utCoke
  • utPepsi
  • in50¢

in50¢

  • utCoke
  • utPepsi

26

slide-27
SLIDE 27

CCS

Branching Time

Example VM3 = in50¢.(outCoke + outPepsi) VM4 = (in50¢.outCoke) + (in50¢.outPepsi) Or in pictures:

  • in50¢
  • utCoke
  • utPepsi
  • in50¢

in50¢

  • utCoke
  • utPepsi

Reactive Systems VM3 allows the customer to choose which drink to vend after inserting 50¢. In VM4 however, the machine makes the choice when the customer inserts a coin.

27

slide-28
SLIDE 28

CCS

Branching Time

Example VM3 = in50¢.(outCoke + outPepsi) VM4 = (in50¢.outCoke) + (in50¢.outPepsi) Or in pictures:

  • in50¢
  • utCoke
  • utPepsi
  • in50¢

in50¢

  • utCoke
  • utPepsi

Reactive Systems VM3 allows the customer to choose which drink to vend after inserting 50¢. In VM4 however, the machine makes the choice when the customer inserts a coin. They different in this reactive view, but they have the same behaviours!

28

slide-29
SLIDE 29

CCS

Equivalences

The equation a.(P + Q) = (a.P) + (a.Q) is usually not admitted for this reason.

29

slide-30
SLIDE 30

CCS

Equivalences

The equation a.(P + Q) = (a.P) + (a.Q) is usually not admitted for this reason. Exercise It is possible to construct two processes that are equal assuming this equation but do not have the same set of behaviours (and thus do not satisfy the same LTL properties).

30

slide-31
SLIDE 31

CCS

Equivalences

The equation a.(P + Q) = (a.P) + (a.Q) is usually not admitted for this reason. Exercise It is possible to construct two processes that are equal assuming this equation but do not have the same set of behaviours (and thus do not satisfy the same LTL properties). If we do admit it, then our notion of equality is very coarse (it is called partial trace equivalence). This is enough if we want to prove safety properties, but progress is not guaranteed.

Liam: Explain why on the board 31

slide-32
SLIDE 32

CCS

Equivalences

The equation a.(P + Q) = (a.P) + (a.Q) is usually not admitted for this reason. Exercise It is possible to construct two processes that are equal assuming this equation but do not have the same set of behaviours (and thus do not satisfy the same LTL properties). If we do admit it, then our notion of equality is very coarse (it is called partial trace equivalence). This is enough if we want to prove safety properties, but progress is not guaranteed.

Liam: Explain why on the board

Terminology Our notion of equality without this equation is called (strong) bisimulation equivalence

  • r (strong) bisimilarity.

32

slide-33
SLIDE 33

CCS

Exercises

A clock that can stop at any time.

33

slide-34
SLIDE 34

CCS

Exercises

A clock that can stop at any time. A clock that ticks or tocks at each cycle.

34

slide-35
SLIDE 35

CCS

Exercises

A clock that can stop at any time. A clock that ticks or tocks at each cycle. A clock that ticks each cycle or tocks each cycle.

35

slide-36
SLIDE 36

CCS

Exercises

A clock that can stop at any time. A clock that ticks or tocks at each cycle. A clock that ticks each cycle or tocks each cycle. A vending machine for Mars and Coke that gives change.

36

slide-37
SLIDE 37

CCS

Parallel Composition

Definition If P and Q are processes then P | Q is the parallel composition of their processes — i.e. the non-deterministic interleaving of their actions.

37

slide-38
SLIDE 38

CCS

Parallel Composition

Definition If P and Q are processes then P | Q is the parallel composition of their processes — i.e. the non-deterministic interleaving of their actions. Example (Clocks) ACLOCK = tick.beep | tock

  • tick

beep tock CCLOCK = TICLK|TOCLK TICLK = tick.TICLK TOCLK = tock.TOCLK Exercise: Express these processes without parallel composition.

38

slide-39
SLIDE 39

CCS

Synchronization

In CCS, every action a has an opposing coaction a (and a = a): Actions: tick tock in50¢

  • utCoke

. . . Coactions: tick tock in50¢

  • utCoke

. . .

39

slide-40
SLIDE 40

CCS

Synchronization

In CCS, every action a has an opposing coaction a (and a = a): Actions: tick tock in50¢

  • utCoke

. . . Coactions: tick tock in50¢

  • utCoke

. . . It is a convention to think of an action as an output event and a coaction as an input

  • event. If a system can execute both an action and its coaction, it may execute them

both simultaneously by taking an internal transition marked by the special action τ.

40

slide-41
SLIDE 41

CCS

Synchronization

In CCS, every action a has an opposing coaction a (and a = a): Actions: tick tock in50¢

  • utCoke

. . . Coactions: tick tock in50¢

  • utCoke

. . . It is a convention to think of an action as an output event and a coaction as an input

  • event. If a system can execute both an action and its coaction, it may execute them

both simultaneously by taking an internal transition marked by the special action τ. Example (Relay Race) RACE = RUN1 | RUN2 RUN1 = start.baton RUN2 = baton.finish

  • baton

finish start baton τ

41

slide-42
SLIDE 42

CCS

Expansion Theorem

Let P and Q be processes. By expanding recursive definitions and using our existing equations for choice we can express P and Q as n-ary choices of action prefixes: P =

i∈I αi. Pi and Q = j∈J βj. Qj.

42

slide-43
SLIDE 43

CCS

Expansion Theorem

Let P and Q be processes. By expanding recursive definitions and using our existing equations for choice we can express P and Q as n-ary choices of action prefixes: P =

i∈I αi. Pi and Q = j∈J βj. Qj.

Then, the parallel composition can be expressed as follows: P | Q =

  • i∈I

αi.(Pi | Q) +

  • j∈J

βj.(P | Qj) +

  • i∈I, j∈J, αi=βj

τ.(Pi | Qj).

43

slide-44
SLIDE 44

CCS

Expansion Theorem

Let P and Q be processes. By expanding recursive definitions and using our existing equations for choice we can express P and Q as n-ary choices of action prefixes: P =

i∈I αi. Pi and Q = j∈J βj. Qj.

Then, the parallel composition can be expressed as follows: P | Q =

  • i∈I

αi.(Pi | Q) +

  • j∈J

βj.(P | Qj) +

  • i∈I, j∈J, αi=βj

τ.(Pi | Qj). From this, many useful equations are derivable: P | Q = Q | P P | (Q | R) = (P | Q) | R P | STOP = P

44

slide-45
SLIDE 45

CCS

Restriction

We wish a way to say “these are all the processes that there are”, in other words, to force synchronization to happen and not allow certain actions to be taken alone.

45

slide-46
SLIDE 46

CCS

Restriction

We wish a way to say “these are all the processes that there are”, in other words, to force synchronization to happen and not allow certain actions to be taken alone. Definition If P is a process and a is an action (not τ), then P \ a is the same as the process P except that the actions a and a may not be executed. We have (a.P) \ b = a.(P \ b) if a / ∈ {b, b}

46

slide-47
SLIDE 47

CCS

Restriction

We wish a way to say “these are all the processes that there are”, in other words, to force synchronization to happen and not allow certain actions to be taken alone. Definition If P is a process and a is an action (not τ), then P \ a is the same as the process P except that the actions a and a may not be executed. We have (a.P) \ b = a.(P \ b) if a / ∈ {b, b} Example (Relay Race) RACE = (RUN1 | RUN2) \ baton RUN1 = start.baton RUN2 = baton.finish

  • baton

finish start baton τ

47

slide-48
SLIDE 48

CCS

Another Example

A man that eats every time a clock ticks: CLOCK4 = tick.CLOCK4 MAN = tick.eat.MAN EXAMPLE = (MAN | CLOCK4) \ tick

48

slide-49
SLIDE 49

CCS

Another Example

A man that eats every time a clock ticks: CLOCK4 = tick.CLOCK4 MAN = tick.eat.MAN EXAMPLE = (MAN | CLOCK4) \ tick After deriving the picture, we get:

  • τ

eat

49

slide-50
SLIDE 50

CCS

Semantics

Up until now, our semantics were given informally in terms of pictures. Now we will formalise our semantic intuitions.

50

slide-51
SLIDE 51

CCS

Semantics

Up until now, our semantics were given informally in terms of pictures. Now we will formalise our semantic intuitions. Our set of locations in our labelled transition system will be the set of all CCS

  • processes. Locations can now be labelled with what process they are:

50¢.(coke + pepsi) coke + pepsi STOP STOP 50¢ coke pepsi We will now define what transitions exist in our LTS by means of a set of inference

  • rules. This technique is called operational semantics.

51

slide-52
SLIDE 52

CCS

Inference Rules

In logic we often write: A1 A2 · · · An C To indicate that C can be proved by proving all assumptions A1 through An. For example, the classical logical rule of modus ponens is written as follows: A ⇒ B A B Modus Ponens

52

slide-53
SLIDE 53

CCS

Operational Semantics

Liam will incrementally draw these on the board. 53

slide-54
SLIDE 54

CCS

Operational Semantics

Liam will incrementally draw these on the board.

a.P

a

− → P Act P

a

− → P′ P + Q

a

− → P′ Choice1 Q

a

− → Q′ P + Q

a

− → Q′ Choice2 P

a

− → P′ P | Q

a

− → P′ | Q Par1 Q

a

− → Q′ P | Q

a

− → P | Q′ Par2 P

a

− → P′ Q

a

− → Q′ P | Q

τ

− → P′ | Q′ Sync P

a

− → P′ a / ∈ {b, b} P \ b

a

− → P′ \ b Restrict

54

slide-55
SLIDE 55

CCS

Operational Semantics

Liam will incrementally draw these on the board.

a.P

a

− → P Act P

a

− → P′ P + Q

a

− → P′ Choice1 Q

a

− → Q′ P + Q

a

− → Q′ Choice2 P

a

− → P′ P | Q

a

− → P′ | Q Par1 Q

a

− → Q′ P | Q

a

− → P | Q′ Par2 P

a

− → P′ Q

a

− → Q′ P | Q

τ

− → P′ | Q′ Sync P

a

− → P′ a / ∈ {b, b} P \ b

a

− → P′ \ b Restrict Bisimulation Equivalence Two processes (or locations) P and Q are bisimilar iff they can do the same actions and those actions themselves lead to bisimilar processes. All of our previous equalities can be proven by induction on the semantics here.

55

slide-56
SLIDE 56

CCS

Proof Trees

The advantages of this rule presentation is that they can be “stacked” to give a neat tree like derivation of proofs. Exercise: Show ((a.P) + Q) | a.R

τ

− → P | R

56

slide-57
SLIDE 57

CCS

Value Passing

We introduce synchronous channels into CCS by allowing actions and coactions to take parameters. Actions: a(3) c(15) x(True) . . . Coactions: a(x) c(y) c(z) . . .

57

slide-58
SLIDE 58

CCS

Value Passing

We introduce synchronous channels into CCS by allowing actions and coactions to take parameters. Actions: a(3) c(15) x(True) . . . Coactions: a(x) c(y) c(z) . . . The parameter of an action is the value to be sent, and the parameter of a coaction is the variable in which the received value is stored.

58

slide-59
SLIDE 59

CCS

Value Passing

We introduce synchronous channels into CCS by allowing actions and coactions to take parameters. Actions: a(3) c(15) x(True) . . . Coactions: a(x) c(y) c(z) . . . The parameter of an action is the value to be sent, and the parameter of a coaction is the variable in which the received value is stored. Example (Buffers) A one-cell sized buffer is implemented as: BUFF = in(x).out(x).BUFF Larger buffers can be made by stitching multiple BUFF processes together! This is how we model asynchronous communication in CCS.

59

slide-60
SLIDE 60

CCS

Merge and Guards

Example (Merge) Merge two input channels in1 and in2 into one output channel out nondeterministically.

  • n iPad

60

slide-61
SLIDE 61

CCS

Merge and Guards

Example (Merge) Merge two input channels in1 and in2 into one output channel out nondeterministically.

  • n iPad

To do a deterministic (fair) merge, we would need some way to check if one value is larger than another. Rather than add if statements, we add the notion of a guard:

61

slide-62
SLIDE 62

CCS

Merge and Guards

Example (Merge) Merge two input channels in1 and in2 into one output channel out nondeterministically.

  • n iPad

To do a deterministic (fair) merge, we would need some way to check if one value is larger than another. Rather than add if statements, we add the notion of a guard: Definition If P is a value-passing CCS process and ϕ is a formula about the variables in scope, then [ϕ]P is a process that executes just like P if ϕ is holds for the current state and like STOP otherwise.

62

slide-63
SLIDE 63

CCS

Merge and Guards

Example (Merge) Merge two input channels in1 and in2 into one output channel out nondeterministically.

  • n iPad

To do a deterministic (fair) merge, we would need some way to check if one value is larger than another. Rather than add if statements, we add the notion of a guard: Definition If P is a value-passing CCS process and ϕ is a formula about the variables in scope, then [ϕ]P is a process that executes just like P if ϕ is holds for the current state and like STOP otherwise. We can define an if statement like so: if ϕ then P else Q ≡ ([ϕ].P) + ([¬ϕ].Q)

63

slide-64
SLIDE 64

CCS

Merge and Guards

Example (Merge) Merge two input channels in1 and in2 into one output channel out nondeterministically.

  • n iPad

To do a deterministic (fair) merge, we would need some way to check if one value is larger than another. Rather than add if statements, we add the notion of a guard: Definition If P is a value-passing CCS process and ϕ is a formula about the variables in scope, then [ϕ]P is a process that executes just like P if ϕ is holds for the current state and like STOP otherwise. We can define an if statement like so: if ϕ then P else Q ≡ ([ϕ].P) + ([¬ϕ].Q) Exercise: How to write a fair merge process?

64

slide-65
SLIDE 65

CCS

Assignment

Some presentations of value passing CCS also include assignment to update variables in the state:

65

slide-66
SLIDE 66

CCS

Assignment

Some presentations of value passing CCS also include assignment to update variables in the state: Definition If P is a process and x is a variable in the state, and e is an expression, then x := eP is is the same as P except that it first updates the variable x to have the value e before making a transition.

66

slide-67
SLIDE 67

CCS

Assignment

Some presentations of value passing CCS also include assignment to update variables in the state: Definition If P is a process and x is a variable in the state, and e is an expression, then x := eP is is the same as P except that it first updates the variable x to have the value e before making a transition. With this, our value-passing CCS is now just as expressive as Ben-Ari’s pseudocode. Moreover, the connection between CCS and transition diagrams is formalised, enabling us to reason symbolically about processes rather than semantically.

67

slide-68
SLIDE 68

CCS

Process Algebra

This is an example of a process algebra. There are many such algebras and they have been very influential on the design of concurrent programming languages.

68

slide-69
SLIDE 69

CCS

Process Algebra

This is an example of a process algebra. There are many such algebras and they have been very influential on the design of concurrent programming languages. Other process algebras include: The Algebra of Communicating Processes (Bergstra and Klop, 1982) which distinguishes between deadlock and termination. The Communicating Sequential Processes formalism (Hoare, 1978) which resolves certain infelicities about nondeterministic choice. The π-calculus (Milner et al. 1992), a derivative of CCS that allows for first class channels and processes. The PEPA stochastic calculus developed by my new boss, Jane Hillston.

69

slide-70
SLIDE 70

CCS

Process Algebra

This is an example of a process algebra. There are many such algebras and they have been very influential on the design of concurrent programming languages. Other process algebras include: The Algebra of Communicating Processes (Bergstra and Klop, 1982) which distinguishes between deadlock and termination. The Communicating Sequential Processes formalism (Hoare, 1978) which resolves certain infelicities about nondeterministic choice. The π-calculus (Milner et al. 1992), a derivative of CCS that allows for first class channels and processes. The PEPA stochastic calculus developed by my new boss, Jane Hillston. In turns out there are dozens of equivalences other than strong bisimulation that are useful for various scenarios. To learn more about other process algebras, equivalence in concurrent models, and extensions that deal with non-interleaving semantics, among many other topics, I highly recommend COMP6752 as a followup to this course.

70

slide-71
SLIDE 71

CCS

What Now?

Vladimir will take over for two weeks, discussing distributed algorithms and commitment and consensus topics.

71