5
5
(* Derivation of a termination detection algorithm for distributed *)
6
6
(* computations (with W.H.J.Feijen and A.J.M. van Gasteren). *)
7
7
(************************************************************************** *)
8
- EXTENDS Naturals , TLAPS
8
+ EXTENDS Naturals
9
9
10
10
CONSTANT N
11
11
ASSUME NAssumption == N \in Nat \ { 0 }
@@ -21,17 +21,21 @@ TypeOK ==
21
21
/\ tpos \in Nodes \* token position
22
22
/\ tcolor \in Color \* token color
23
23
24
- (* Initially the token is black. The other variables may take
25
- any "type-correct" values. *)
24
+ (* **************************************************************************)
25
+ (* Initially the token is black. The other variables may take any *)
26
+ (* "type-correct" values. *)
27
+ (************************************************************************** *)
26
28
Init ==
27
29
/\ active \in [ Nodes -> BOOLEAN ]
28
30
/\ color \in [ Nodes -> Color ]
29
31
/\ tpos \in Nodes
30
32
/\ tcolor = "black"
31
33
32
- (* Node 0 may initiate a probe when it has the token and
33
- when either it is black or the token is black. It passes
34
- a white token to node N-1 and paints itself white. *)
34
+ (* **************************************************************************)
35
+ (* Node 0 may initiate a probe when it has the token and when either it is *)
36
+ (* black or the token is black. It passes a white token to node N-1 and *)
37
+ (* paints itself white. *)
38
+ (************************************************************************** *)
35
39
InitiateProbe ==
36
40
/\ tpos = 0
37
41
/\ tcolor = "black" \/ color [ 0 ] = "black"
@@ -40,15 +44,16 @@ InitiateProbe ==
40
44
/\ active ' = active
41
45
/\ color ' = [ color EXCEPT ! [ 0 ] = "white" ]
42
46
43
- (* A node i different from 0 that possesses the token may pass
44
- it to node i-1 under the following circumstances:
45
- - node i is inactive or
46
- - node i is colored black or
47
- - the token is black.
48
- Note that the last two conditions will result in an
49
- inconclusive round, since the token will be black.
50
- The token will be stained if node i is black, otherwise
51
- its color is unchanged. Node i will be made white. *)
47
+ (* **************************************************************************)
48
+ (* A node i different from 0 that possesses the token may pass it to node *)
49
+ (* i-1 under the following circumstances: *)
50
+ (* - node i is inactive or *)
51
+ (* - node i is colored black or *)
52
+ (* - the token is black. *)
53
+ (* Note that the last two conditions will result in an inconclusive round, *)
54
+ (* since the token will be black. The token will be stained if node i is *)
55
+ (* black, otherwise its color is unchanged. Node i will be made white. *)
56
+ (************************************************************************** *)
52
57
PassToken ( i ) ==
53
58
/\ tpos = i
54
59
/\ ~ active [ i ] \/ color [ i ] = "black" \/ tcolor = "black"
@@ -57,29 +62,39 @@ PassToken(i) ==
57
62
/\ active ' = active
58
63
/\ color ' = [ color EXCEPT ! [ i ] = "white" ]
59
64
65
+ (* **************************************************************************)
60
66
(* token passing actions controlled by the termination detection algorithm *)
67
+ (************************************************************************** *)
61
68
System == InitiateProbe \/ \E i \in Nodes \ { 0 } : PassToken ( i )
62
69
63
- (* An active node i may activate another node j by sending it
64
- a message. If j>i (hence activation goes against the direction
65
- of the token being passed), then node i becomes black. *)
70
+ (* **************************************************************************)
71
+ (* An active node i may activate another node j by sending it a message. *)
72
+ (* If j>i (hence activation goes against the direction of the token being *)
73
+ (* passed), then node i becomes black. *)
74
+ (************************************************************************** *)
66
75
SendMsg ( i ) ==
67
76
/\ active [ i ]
68
77
/\ \E j \in Nodes \ { i } :
69
78
/\ active ' = [ active EXCEPT ! [ j ] = TRUE ]
70
79
/\ color ' = [ color EXCEPT ! [ i ] = IF j > i THEN "black" ELSE @ ]
71
80
/\ UNCHANGED << tpos , tcolor >>
72
81
73
- (* Any active node may become inactive at any moment. *)
82
+ (* **************************************************************************)
83
+ (* Any active node may become inactive at any moment. *)
84
+ (************************************************************************** *)
74
85
Deactivate ( i ) ==
75
86
/\ active [ i ]
76
87
/\ active ' = [ active EXCEPT ! [ i ] = FALSE ]
77
88
/\ UNCHANGED << color , tpos , tcolor >>
78
89
79
- (* actions performed by the underlying algorithm *)
90
+ (* **************************************************************************)
91
+ (* actions performed by the underlying algorithm *)
92
+ (************************************************************************** *)
80
93
Environment == \E i \in Nodes : SendMsg ( i ) \/ Deactivate ( i )
81
94
82
- (* next-state relation: disjunction of above actions *)
95
+ (* **************************************************************************)
96
+ (* next-state relation: disjunction of above actions *)
97
+ (************************************************************************** *)
83
98
Next == System \/ Environment
84
99
85
100
vars == << active , color , tpos , tcolor >>
@@ -141,104 +156,13 @@ Inv ==
141
156
\/ P2 :: tcolor = "black"
142
157
143
158
(* **************************************************************************)
144
- (* Use the following specification to check that the predicate *)
159
+ (* Use the following specification to let TLC check that the predicate *)
145
160
(* TypeOK /\ Inv is inductive for EWD 840: verify that it is an *)
146
161
(* (ordinary) invariant of a specification obtained by replacing the *)
147
162
(* initial condition by that conjunction. *)
148
163
(************************************************************************** *)
149
164
CheckInductiveSpec == TypeOK /\ Inv /\ [] [ Next ]_ vars
150
- -----------------------------------------------------------------------------
151
- (* **************************************************************************)
152
- (* Interactive proof of safety using TLAPS. *)
153
- (************************************************************************** *)
154
-
155
- (* **************************************************************************)
156
- (* The algorithm is type-correct: TypeOK is an inductive invariant. *)
157
- (************************************************************************** *)
158
- LEMMA TypeCorrect == Spec => [] TypeOK
159
- < 1 > 1 . Init => TypeOK
160
- BY DEF Init , TypeOK , Color
161
- < 1 > 2 . TypeOK /\ [ Next ]_ vars => TypeOK '
162
- BY NAssumption DEF TypeOK , Color , Nodes , vars , Next , System , Environment ,
163
- InitiateProbe , PassToken , SendMsg , Deactivate
164
- < 1 > . QED BY < 1 > 1 , < 1 > 2 , PTL DEF Spec
165
-
166
-
167
- (* **************************************************************************)
168
- (* Follows a more detailed proof of the same lemma. It illustrates how *)
169
- (* proofs can be decomposed hierarchically. Use the "Decompose Proof" *)
170
- (* command (C-G C-D) to prepare the skeleton of the level-2 steps. *)
171
- (************************************************************************** *)
172
- LEMMA Spec => [] TypeOK
173
- < 1 > 1 . Init => TypeOK
174
- BY DEF Init , TypeOK , Color
175
- < 1 > 2 . TypeOK /\ [ Next ]_ vars => TypeOK '
176
- < 2 > SUFFICES ASSUME TypeOK ,
177
- [ Next ]_ vars
178
- PROVE TypeOK '
179
- OBVIOUS
180
- < 2 > . USE NAssumption DEF TypeOK , Nodes , Color
181
- < 2 > 1 . CASE InitiateProbe
182
- BY < 2 > 1 DEF InitiateProbe
183
- < 2 > 2 . ASSUME NEW i \in Nodes \ { 0 } ,
184
- PassToken ( i )
185
- PROVE TypeOK '
186
- BY < 2 > 2 DEF PassToken
187
- < 2 > 3 . ASSUME NEW i \in Nodes ,
188
- SendMsg ( i )
189
- PROVE TypeOK '
190
- BY < 2 > 3 DEF SendMsg
191
- < 2 > 4 . ASSUME NEW i \in Nodes ,
192
- Deactivate ( i )
193
- PROVE TypeOK '
194
- BY < 2 > 4 DEF Deactivate
195
- < 2 > 5 . CASE UNCHANGED vars
196
- BY < 2 > 5 DEF vars
197
- < 2 > . QED
198
- BY < 2 > 1 , < 2 > 2 , < 2 > 3 , < 2 > 4 , < 2 > 5 DEF Environment , Next , System
199
- < 1 > . QED BY < 1 > 1 , < 1 > 2 , PTL DEF Spec
200
-
201
- (* **************************************************************************)
202
- (* Prove the main soundness property of the algorithm by (1) proving that *)
203
- (* Inv is an inductive invariant and (2) that it implies correctness. *)
204
- (************************************************************************** *)
205
- THEOREM Safety == Spec => [] TerminationDetection
206
- < 1 > 1 . Init => Inv
207
- BY NAssumption DEF Init , Inv , Nodes
208
- < 1 > 2 . TypeOK /\ Inv /\ [ Next ]_ vars => Inv '
209
- BY NAssumption
210
- DEF TypeOK , Inv , Next , vars , Nodes , Color ,
211
- System , Environment , InitiateProbe , PassToken , SendMsg , Deactivate
212
- < 1 > 3 . Inv => TerminationDetection
213
- BY NAssumption DEF Inv , TerminationDetection , terminationDetected , Nodes
214
- < 1 > . QED
215
- BY < 1 > 1 , < 1 > 2 , < 1 > 3 , TypeCorrect , PTL DEF Spec
216
-
217
-
218
- (* **************************************************************************)
219
- (* Step <1>3 of the above proof shows that Dijkstra's invariant implies *)
220
- (* TerminationDetection. If you find that one-line proof too obscure, here *)
221
- (* is a more detailed, hierarchical proof of that same implication. *)
222
- (************************************************************************** *)
223
- LEMMA Inv => TerminationDetection
224
- < 1 > 1 . SUFFICES ASSUME tpos = 0 , tcolor = "white" ,
225
- color [ 0 ] = "white" , ~ active [ 0 ] ,
226
- Inv
227
- PROVE \A i \in Nodes : ~ active [ i ]
228
- BY < 1 > 1 DEF TerminationDetection , terminationDetected
229
- < 1 > 2 . ~ Inv ! P2 BY tcolor = "white" DEF Inv
230
- < 1 > 3 . ~ Inv ! P1 BY < 1 > 1 DEF Inv
231
- < 1 > . QED
232
- < 2 > 1 . Inv ! P0 BY Inv , < 1 > 2 , < 1 > 3 DEF Inv
233
- < 2 > . TAKE i \in Nodes
234
- < 2 > 3 . CASE i = 0 BY < 2 > 1 , < 1 > 1 , < 2 > 3
235
- < 2 > 4 . CASE i \in 1 .. N - 1
236
- < 3 > 1 . tpos < i BY tpos = 0 , < 2 > 4 , NAssumption
237
- < 3 > 2 . i < N BY NAssumption , < 2 > 4
238
- < 3 > . QED BY < 3 > 1 , < 3 > 2 , < 2 > 1
239
- < 2 > . QED BY < 2 > 3 , < 2 > 4 DEF Nodes
240
-
241
165
=============================================================================
242
166
\* Modification History
243
- \* Last modified Mon May 30 20:40:46 CEST 2016 by merz
167
+ \* Last modified Tue Jun 28 18:17:45 CEST 2016 by merz
244
168
\* Created Mon Sep 09 11:33:10 CEST 2013 by merz
0 commit comments