3
3
(* A specification of a 'concurrency game' requiring concurrent *)
4
4
(* and symmetrical cooperation - https://cedric.cnam.fr/fichiers/RC474.pdf *)
5
5
(************************************************************************** *)
6
-
7
6
EXTENDS Integers
8
7
8
+ RECURSIVE Sum ( _ , _ )
9
+ Sum ( f , S ) == IF S = { } THEN 0
10
+ ELSE LET x == CHOOSE x \in S : TRUE
11
+ IN f [ x ] + Sum ( f , S \ { x } )
12
+
13
+ -----------------------------------------------------------------------------
14
+
15
+ Color == { "blue" , "red" , "yellow" }
16
+ Faded == CHOOSE c : c \notin Color
17
+
18
+ Complement ( c1 , c2 ) == IF c1 = c2
19
+ THEN c1
20
+ ELSE CHOOSE cid \in Color \ { c1 , c2 } : TRUE
21
+
22
+ -----------------------------------------------------------------------------
23
+
9
24
\* N - number of total meeting after which chameneoses fade
10
25
\* M - number of chameneoses
11
26
CONSTANT N , M
@@ -15,27 +30,23 @@ VARIABLE chameneoses, meetingPlace, numMeetings
15
30
16
31
vars == << chameneoses , meetingPlace , numMeetings >>
17
32
18
- Color == { "blue" , "red" , "yellow" }
19
- Faded == CHOOSE c : c \notin Color
20
-
21
33
ChameneosID == 1 .. M
22
34
MeetingPlaceEmpty == CHOOSE e : e \notin ChameneosID
23
35
24
- RECURSIVE Sum ( _ , _ )
25
- Sum ( f , S ) == IF S = { } THEN 0
26
- ELSE LET x == CHOOSE x \in S : TRUE
27
- IN f [ x ] + Sum ( f , S \ { x } )
36
+ TypeOK ==
37
+ \* For each chameneoses, remember its current color and how many meetings it has been in.
38
+ /\ chameneoses \in [ ChameneosID -> ( Color \cup { Faded } ) \X ( 0 .. N ) ]
39
+ \* A meetingPlace (called Mall in the original paper) keeps track of the chameneoses
40
+ \* creature that is currently waiting to meet another creature.
41
+ /\ meetingPlace \in ChameneosID \cup { MeetingPlaceEmpty }
28
42
29
- TypeOK == /\ chameneoses \in [ ChameneosID -> ( Color \cup { Faded } ) \X ( 0 .. N ) ]
30
- /\ meetingPlace \in ChameneosID \cup { MeetingPlaceEmpty }
31
-
32
- Complement ( c1 , c2 ) == IF c1 = c2
33
- THEN c1
34
- ELSE CHOOSE cid \in Color \ { c1 , c2 } : TRUE
43
+ Init == /\ chameneoses \in [ ChameneosID -> Color \X { 0 } ]
44
+ /\ meetingPlace = MeetingPlaceEmpty
45
+ /\ numMeetings = 0
35
46
36
47
Meet ( cid ) == IF meetingPlace = MeetingPlaceEmpty
37
48
THEN IF numMeetings < N
38
- \* chameneos enters meeting empty meeting place
49
+ \* chameneos enters empty meeting place
39
50
THEN /\ meetingPlace ' = cid
40
51
/\ UNCHANGED << chameneoses , numMeetings >>
41
52
\* chameneos takes on faded color
@@ -51,16 +62,20 @@ Meet(cid) == IF meetingPlace = MeetingPlaceEmpty
51
62
! [ meetingPlace ] = << newColor , @ [ 2 ] + 1 >> ]
52
63
/\ numMeetings ' = numMeetings + 1
53
64
54
- Init == /\ chameneoses \in [ ChameneosID -> Color \X { 0 } ]
55
- /\ meetingPlace = MeetingPlaceEmpty
56
- /\ numMeetings = 0
57
-
58
- \* repeatedly try to enter meeting place for chameneoses that are not faded yet
65
+ \* Repeatedly try to enter meeting place for chameneoses that are not faded yet.
66
+ \* The system terminates once the color of all chameneoses is faded.
59
67
Next == /\ \E c \in { x \in ChameneosID : chameneoses [ x ] [ 1 ] /= Faded } : Meet ( c )
60
68
61
69
Spec == Init /\ [] [ Next ]_ vars
62
70
71
+ -----------------------------------------------------------------------------
72
+
73
+ \* Upon termination, the sum of the (individual) meetings that all creates have
74
+ \* been in, is equal to 2*N. It is *not* guaranteed that all chameneoses have
75
+ \* been in a meeting with another chameneoses. See section A. Game termination
76
+ \* on page 5 of the original papaer).
63
77
SumMet == numMeetings = N => LET f [ c \in ChameneosID ] == chameneoses [ c ] [ 2 ]
64
78
IN Sum ( f , ChameneosID ) = 2 * N
79
+ THEOREM Spec => [] SumMet
65
80
66
81
=============================================================================
0 commit comments