-
Notifications
You must be signed in to change notification settings - Fork 1
/
Chord.tla
233 lines (186 loc) · 8.36 KB
/
Chord.tla
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
------------------------- MODULE Chord1 ------------------------
EXTENDS Naturals, TLC, Sequences
CONSTANT N
Nodes == 1..N
(* --algorithm chord
variables
succ = [row \in Nodes |-> 9 ];
prdc = [row \in Nodes |-> 9 ];
succ2 = [row \in Nodes |-> 9 ];
newsucc = [row \in Nodes |-> 9 ];
canfail = 0;
canjoin = 0;
hasbest=0;
define
between( x, y, z) ==
\/ x < y /\ y < z
\/ x > z /\ \/ x < z
\/ y < z
max(x,y) == IF x < y THEN y ELSE x
member(x) == \/ succ[x] = TRUE
nonmember(x) == \/ succ[x] = FALSE /\ prdc[x] = FALSE /\ succ2[x] = FALSE
(* valid(x) == \/ OneOrderedRing(x) /\ orderedappendage(x,y) /\ FullSuccessorList(x) /\ NoSelfSuccessors(x) /\ OrderedSuccessors(x) /\ BaseNotSkiped(x) /\ ConnectedAppendages(x) *)
end define;
macro fillvalue(row, column, val)
begin
matrix[row][column] := val;
end macro;
procedure orderedappendage(n,m)
variables pre,bet,q;
begin
pp1:
print "Ordered appendage";
pre:=prdc[n]; q:=succ[n];
assert bet=between(pre,m,q);
ret: return;
end procedure;
procedure orderedmerges(n,m)
variables pre,bet,q;
begin
pp1:
cyclemember=succ[n]
print "Ordered merge";
pre:=prdc[n]; q:=succ[n];
assert bet=between(pre,m,q);
ret: return;
end procedure;
procedure hasbest()
variables j=1..N , p;
begin
hsbl: while j # {} do
p := CHOOSE k \in j:TRUE;
if succ[p] # 9 /\ matrix[p][1] = 9 then
hsbest := FALSE;
assert hsbest;
end if;
end while;
hsbret: return;
end procedure;
procedure alloy()
variables hello = "";
begin
LaBeL: print <<"Number of nodes",hello>>;
return;
end procedure;
process chord \in Nodes
begin
label1:
fillvalue(self,1,4);
label2: call alloy();
(* label3: call orderedappendage(1,2);
label4: call hasbest(); *)
end process;
end algorithm
*)
\* BEGIN TRANSLATION
CONSTANT defaultInitValue
VARIABLES matrix, succ, prdc, succ2, newsucc, canfail, canjoin, hsbest, pc,
stack
(* define statement *)
between( x, y, z) ==
\/ x < z /\ x < y /\ y < z
\/ x > z /\ \/ x < z
\/ y < z
max(x,y) == IF x < y THEN y ELSE x
member(x) == \/ succ[x] = TRUE
nonmember(x) == \/ succ[x] = FALSE /\ prdc[x] = FALSE /\ succ2[x] = FALSE
VARIABLES n, m, pre, bet, q, j, p, hello
vars == << matrix, succ, prdc, succ2, newsucc, canfail, canjoin, hsbest, pc,
stack, n, m, pre, bet, q, j, p, hello >>
ProcSet == (Nodes)
Init == (* Global variables *)
/\ matrix = [row \in Nodes |-> [column \in Nodes |-> 9 ]]
/\ succ = [row \in Nodes |-> 9 ]
/\ prdc = [row \in Nodes |-> 9 ]
/\ succ2 = [row \in Nodes |-> 9 ]
/\ newsucc = [row \in Nodes |-> 9 ]
/\ canfail = 0
/\ canjoin = 0
/\ hsbest = 0
(* Procedure orderedappendage *)
/\ n = [ self \in ProcSet |-> defaultInitValue]
/\ m = [ self \in ProcSet |-> defaultInitValue]
/\ pre = [ self \in ProcSet |-> defaultInitValue]
/\ bet = [ self \in ProcSet |-> defaultInitValue]
/\ q = [ self \in ProcSet |-> defaultInitValue]
(* Procedure hasbest *)
/\ j = [ self \in ProcSet |-> 1..N]
/\ p = [ self \in ProcSet |-> defaultInitValue]
(* Procedure alloy *)
/\ hello = [ self \in ProcSet |-> ""]
/\ stack = [self \in ProcSet |-> << >>]
/\ pc = [self \in ProcSet |-> "label1"]
pp1(self) == /\ pc[self] = "pp1"
/\ PrintT("In order")
/\ pre' = [pre EXCEPT ![self] = prdc[n[self]]]
/\ q' = [q EXCEPT ![self] = succ[n[self]]]
/\ Assert(bet[self]=between(pre'[self],m[self],q'[self]),
"Failure of assertion at line 52, column 9.")
/\ pc' = [pc EXCEPT ![self] = "ret"]
/\ UNCHANGED << matrix, succ, prdc, succ2, newsucc, canfail,
canjoin, hsbest, stack, n, m, bet, j, p, hello >>
ret(self) == /\ pc[self] = "ret"
/\ pc' = [pc EXCEPT ![self] = Head(stack[self]).pc]
/\ pre' = [pre EXCEPT ![self] = Head(stack[self]).pre]
/\ bet' = [bet EXCEPT ![self] = Head(stack[self]).bet]
/\ q' = [q EXCEPT ![self] = Head(stack[self]).q]
/\ n' = [n EXCEPT ![self] = Head(stack[self]).n]
/\ m' = [m EXCEPT ![self] = Head(stack[self]).m]
/\ stack' = [stack EXCEPT ![self] = Tail(stack[self])]
/\ UNCHANGED << matrix, succ, prdc, succ2, newsucc, canfail,
canjoin, hsbest, j, p, hello >>
orderedappendage(self) == pp1(self) \/ ret(self)
hsbl(self) == /\ pc[self] = "hsbl"
/\ IF j[self] # {}
THEN /\ p' = [p EXCEPT ![self] = CHOOSE k \in j[self]:TRUE]
/\ IF succ[p'[self]] # 9 /\ matrix[p'[self]][1] = 9
THEN /\ hsbest' = FALSE
/\ Assert(hsbest',
"Failure of assertion at line 63, column 33.")
ELSE /\ TRUE
/\ UNCHANGED hsbest
/\ pc' = [pc EXCEPT ![self] = "hsbl"]
ELSE /\ pc' = [pc EXCEPT ![self] = "hsbret"]
/\ UNCHANGED << hsbest, p >>
/\ UNCHANGED << matrix, succ, prdc, succ2, newsucc, canfail,
canjoin, stack, n, m, pre, bet, q, j, hello >>
hsbret(self) == /\ pc[self] = "hsbret"
/\ pc' = [pc EXCEPT ![self] = Head(stack[self]).pc]
/\ j' = [j EXCEPT ![self] = Head(stack[self]).j]
/\ p' = [p EXCEPT ![self] = Head(stack[self]).p]
/\ stack' = [stack EXCEPT ![self] = Tail(stack[self])]
/\ UNCHANGED << matrix, succ, prdc, succ2, newsucc, canfail,
canjoin, hsbest, n, m, pre, bet, q, hello >>
hasbest(self) == hsbl(self) \/ hsbret(self)
LaBeL(self) == /\ pc[self] = "LaBeL"
/\ PrintT(<<"Number of nodes",hello[self]>>)
/\ pc' = [pc EXCEPT ![self] = Head(stack[self]).pc]
/\ hello' = [hello EXCEPT ![self] = Head(stack[self]).hello]
/\ stack' = [stack EXCEPT ![self] = Tail(stack[self])]
/\ UNCHANGED << matrix, succ, prdc, succ2, newsucc, canfail,
canjoin, hsbest, n, m, pre, bet, q, j, p >>
alloy(self) == LaBeL(self)
label1(self) == /\ pc[self] = "label1"
/\ matrix' = [matrix EXCEPT ![self][1] = 4]
/\ pc' = [pc EXCEPT ![self] = "label2"]
/\ UNCHANGED << succ, prdc, succ2, newsucc, canfail, canjoin,
hsbest, stack, n, m, pre, bet, q, j, p, hello >>
label2(self) == /\ pc[self] = "label2"
/\ stack' = [stack EXCEPT ![self] = << [ procedure |-> "alloy",
pc |-> "Done",
hello |-> hello[self] ] >>
\o stack[self]]
/\ hello' = [hello EXCEPT ![self] = ""]
/\ pc' = [pc EXCEPT ![self] = "LaBeL"]
/\ UNCHANGED << matrix, succ, prdc, succ2, newsucc, canfail,
canjoin, hsbest, n, m, pre, bet, q, j, p >>
chord(self) == label1(self) \/ label2(self)
Next == (\E self \in ProcSet: \/ orderedappendage(self) \/ hasbest(self)
\/ alloy(self))
\/ (\E self \in Nodes: chord(self))
\/ (* Disjunct to prevent deadlock on termination *)
((\A self \in ProcSet: pc[self] = "Done") /\ UNCHANGED vars)
Spec == Init /\ [][Next]_vars
Termination == <>(\A self \in ProcSet: pc[self] = "Done")
\* END TRANSLATION
=====================================================================