-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetEuclid.tla
57 lines (48 loc) · 1.97 KB
/
SetEuclid.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
----------------------------- MODULE SetEuclid -----------------------------
EXTENDS Integers, TLC, FiniteSets, GCD
(***************************************************************************)
(* Euclid's Algorithm for Sets *)
(* SetGCD(T): Define the gcd of a set T of positive integers *)
(* SetSum(T): Define the sum of all the elements in a finite set of number *)
(***************************************************************************)
SetGCD(T) == SetMax({d \in Int: \A t \in T: Divides(d, t)})
RECURSIVE SetSum(_)
SetSum(T) == IF T = {} THEN 0
ELSE LET t == CHOOSE x \in T: TRUE
IN t + SetSum(T\{t})
(***************************************************************************
--fair algorithm SetEuclid {
variables S = Nat\{0};
{ while(Cardinality(S)>1)
{ with( x \in S, y \in {s \in S: s>x} )
{ S:= (S\{y}) \cap {y-x}}
}
}
}
***************************************************************************)
\* BEGIN TRANSLATION (chksum(pcal) = "c321d4cd" /\ chksum(tla) = "73d92143")
VARIABLES S, pc
vars == << S, pc >>
Init == (* Global variables *)
/\ S = (Nat\{0})
/\ pc = "Lbl_1"
Lbl_1 == /\ pc = "Lbl_1"
/\ IF Cardinality(S)>1
THEN /\ \E x \in S:
\E y \in {s \in S: s>x}:
S' = ((S\{y}) \cap {y-x})
/\ pc' = "Lbl_1"
ELSE /\ pc' = "Done"
/\ S' = S
(* Allow infinite stuttering to prevent deadlock on termination. *)
Terminating == pc = "Done" /\ UNCHANGED vars
Next == Lbl_1
\/ Terminating
Spec == /\ Init /\ [][Next]_vars
/\ WF_vars(Next)
Termination == <>(pc = "Done")
\* END TRANSLATION
=============================================================================
\* Modification History
\* Last modified Sun Sep 26 10:44:30 CST 2021 by wrz
\* Created Sun Sep 26 10:43:23 CST 2021 by wrz