• No results found

Running Examples in SimpleCircus2CSPM

9.1.1

Example 1 – Simple Sequential Case in the Main Action

This example contains three actions,A,B, andC. There are two variables,xandydefined in these actions. Meanwhile, the third variable namedzis introduced in the main action. The actions are made up of assignment commands, sequential composition, prefix action and one of the basic actions, that is,Skip. The main action defined is kept simple with just sequential compositions between each call of a particular action.

The mathematical version of theCircusexample,cp1, is: A= (xb :=1)o 9(a→Skip) B= (yb :=x+1)o 9(b→Skip) C= (cb →Skip) MAIN= (zb :=0)o 9Ao9Bo9C

The output from translator is as follows, using the command,putppd (circus2csp cp1):

A(x,y,z) =ˆ= a -> B(1,y,z)

B(x,y,z) =ˆ= b -> C(x,x+1,z)

C(x,y,z) =ˆ= c -> Skip

MAIN(x,y,z) =ˆ= A(x,y,0)

Comments:By inspecting the mathematical version of this example, it can be seen that the main action of the process calls actionsA,B, andCin sequence. Before calls to actions, the assignment command sets the value of variablezequal to zero. The output fromcircus2cspfunction shows that the process starts by calling actionA, while the expression ofzis substituted in the parameter list. Afterwards, after performing eventa, action B is called with the parameter list having being updated by the assignment command of setting variable xvalue to 1. Similarly, actionBcalls actionsCwith parameter list having being updated by the assignment

86 CHAPTER 9. EVALUATION command of setting variableyvalue tox+1. As actionCis the last in the sequential composition of calls in the MAIN so we find that after performing eventc, the process terminates. The correct output should contain the observable events asa→b→c→Skipwhich is achieved in the translated version.

9.1.2

Example 2 – Adding Extra Disjoint Variables in the Main Action

The mathematical version of theCircusexamplecp2 is: A= (xb :=1)o 9(a→Skip) B= (yb :=x+1)o 9(b→Skip) C= (cb →Skip) MAIN(p,q) = (z:=0)o 9Ao9Bo9C

Comments:ThisCircusprocess is same ascp1. The difference here is the inclusion of extra variables(p,q) by the main action. It can be seen that these variables are disjoint from the ones in the actionsA,B, andC. So, the call toAfrom main just includes parametersx,yandz.

The output from translator functioncircus2cspis as follows, using the command,putppd (circus2csp cp2):

A(x,y,z) =ˆ= a -> B(1,y,z)

B(x,y,z) =ˆ= b -> C(x,x+1,z)

C(x,y,z) =ˆ= c -> Skip

MAIN(P,Q,x,y,z) =ˆ= A(x,y,0)

Comments:The correct output should contain the observable events asa→b→c→Skipwhich is achieved in the translated version. Also the subsituted expression in each call to a particular action is achieved correctly. The disjoint variables from the main action are not included in call to actionA, which is as required in the correct translation.

9.1.3

Example 3 –CircusProcess without the Main Action

The mathematical version of theCircusexamplecp3 is: A= (xb :=1)o

9(a→B)

B= (yb :=x+1)o

9(b→C)

C= (cb →A)

Comments:Here, in this example, there is no MAIN action. If this example is given as an input tocircus2csp

function, the translator chooses to use the action level translation instead. The action level translator function

action2cspdetermines the dependencies for each action and translates theCircusprocess.

The output from the translator is as follows, using the commandputppd (action2csp cp3 "A") A(x,y) =ˆ= a -> B(1,y)

B(x,y) =ˆ= b -> C(x,x+1)

9.1. RUNNING EXAMPLES INSIMPLECIRCUS2CSPM 87

Comments:Here, we can see that the functionaction2cspis producing the rightCSPoutput, as it deter- mines the dependencies for the whole process. Also the subsituted expression in each call to a particular action is achieved correctly.

9.1.4

Example 4 – Two Distinct Sequential Composition Chains of Calling Actions

In theCircusexamplecp4, there is no main action. Here, actionsA,B, andCare calling each other. ActionD calls itself, while actionEcalls actionD.

The mathematical version of theCircusprocesscp4 is: A= (xb :=1)o 9(a→B) B= (yb :=x+1)o 9(b→C) C= (cb →A) D= (ab :=b+1)o 9(d→D) E= (eb →D)

As there is no main action, so we have to use theaction2cspfunction, instead of thecircus2cspfuntion. The output from the translator for actionAis as follows, using the commandputppd (action2csp cp4 "A"):

A(x,y) =ˆ= a -> B(1,y)

B(x,y) =ˆ= b -> C(x,x+1)

C(x,y) =ˆ= c -> A(x,y)

The output from translator for actionDis as follows, using the command putppd (action2csp cp4 "D"):

D(a,b) =ˆ= d -> D(b+1,b)

The output from translator for actionE is as follows, using the command putppd (action2csp cp4 "E"):

D(a,b) =ˆ= d -> D(b+1,b)

E(a,b) =ˆ= e -> D(a,b)

Comments: Here again, we can see that the translator functionaction2cspis producing the rightCSP output for the individual actions in the whole process definition, as it determines the dependencies correctly in case of the actionsA,DandE. The translator correctly identifies thatA,BandCuse different variables from DandE.

9.1.5

Example 5 – the Lift Process

This example is more elaborate as it involves more expression builders as well as guarded commands with external choice between them. The main action calls the initialiser which identifies the variables for the floor number and the state of the lift door. Afterwards, the Lift process operates on the basis of the guarded com- mands and performs events of up, down, close and open. Up and down events change the floor number while close and open events change the status of the lift door.

88 CHAPTER 9. EVALUATION The mathematical version of the lift example is:

INITLIFT= (floorb :=1)o

9(doorState:=closed)

LIFT= (floorb <5∧doorState=closed&(up→floor:=floor+1o 9LIFT))

2

(floor>0∧doorState=closed&(down→floor:=floor−1o 9LIFT))

2

(doorState=open&(close→doorState:=closedo 9LIFT))

2

(doorState=closed&(open→doorState:=openedo 9LIFT))

MAIN=INITLIFT;LIFT

The output from translator functioncircus2cspis as follows, using command,putppd (circus2csp cp5):

INITLIFT(doorState,floor) =ˆ= LIFT(closed,1)

LIFT(doorState,floor) =ˆ= (floor < 5 and doorState = closed & (up -> LIFT(doorState,floor+1)))

[]

((floor > 0 and doorState = closed & (down -> LIFT(doorState,floor-1)))

[]

((doorState = opened &

(close -> LIFT(closed,floor))) []

(doorState = closed &

(open -> LIFT(opened,floor)))))

MAIN(doorState,floor) =ˆ= INITLIFT(doorState,floor)

Comment: Here, the translator is producing the correct output. The main action calls the initialiser func- tionINITLIFT. Here, the initial status ofLIFTis set by passing the initial values of the parameters. The

doorStateparameter is set toclosed, while floor number is set to 1 initially. Then, depending on the eventsup,down,close, andopen, theLIFTprocess continues by calling itself recursively.

9.1.6

Example 6 – Including External Choice in the Main Action

TheCircus examplecp7 contains an external choice between two disjoint sequentially composed chains of calls. Here, the left hand side sequentially composed chain has calls to actionsA,B, andC. Meanwhile, the right hand side chain has calls to actionDandE.

A= (xb :=1)o 9(a→B) B= (yb :=x+1)o 9(b→C) C= (cb →A) D= (ub :=v+1)o 9(d→E) E= (eb →D) MAIN= (Ab o 9Bo9C)2(Do9E)

9.2. CASE STUDY – A CACHE COHERENCE PROTOCOL REPRESENTATION IN SIMPLECIRCUSNOTATION89