-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathduplicates.tla
87 lines (71 loc) · 2.27 KB
/
duplicates.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
----------------------------- MODULE duplicates -----------------------------
EXTENDS Integers, Sequences, TLC, FiniteSets
S == 1..10
(*--algorithm dup
variable
seq \in S \X S \X S \X S;
index = 1;
seen = {};
is_unique = TRUE;
define
TypeInvariant ==
/\ is_unique \in BOOLEAN
/\ seen \subseteq S
/\ index \in 1..Len(seq)+1
IsUnique(s) ==
\A i, j \in 1..Len(s):
i # j => seq[i] # seq[j]
IsCorrect == pc = "Done" => is_unique = IsUnique(seq)
end define;
begin
Iterate:
while index <= Len(seq) do
if seq[index] \notin seen then
seen := seen \union {seq[index]};
else
is_unique := FALSE;
end if;
index := index + 1;
end while;
end algorithm; *)
\* BEGIN TRANSLATION (chksum(pcal) = "399e52d9" /\ chksum(tla) = "9b980ffb")
VARIABLES seq, index, seen, is_unique, pc
(* define statement *)
TypeInvariant ==
/\ is_unique \in BOOLEAN
/\ seen \subseteq S
/\ index \in 1..Len(seq)+1
IsUnique(s) ==
\A i, j \in 1..Len(s):
i # j => seq[i] # seq[j]
IsCorrect == pc = "Done" => is_unique = IsUnique(seq)
vars == << seq, index, seen, is_unique, pc >>
Init == (* Global variables *)
/\ seq \in S \X S \X S \X S
/\ index = 1
/\ seen = {}
/\ is_unique = TRUE
/\ pc = "Iterate"
Iterate == /\ pc = "Iterate"
/\ IF index <= Len(seq)
THEN /\ IF seq[index] \notin seen
THEN /\ seen' = (seen \union {seq[index]})
/\ UNCHANGED is_unique
ELSE /\ is_unique' = FALSE
/\ seen' = seen
/\ index' = index + 1
/\ pc' = "Iterate"
ELSE /\ pc' = "Done"
/\ UNCHANGED << index, seen, is_unique >>
/\ seq' = seq
(* Allow infinite stuttering to prevent deadlock on termination. *)
Terminating == pc = "Done" /\ UNCHANGED vars
Next == Iterate
\/ Terminating
Spec == Init /\ [][Next]_vars
Termination == <>(pc = "Done")
\* END TRANSLATION
=============================================================================
\* Modification History
\* Last modified Thu Jul 21 21:07:24 CST 2022 by dannypsnl
\* Created Thu Jul 21 20:44:41 CST 2022 by dannypsnl