-
Notifications
You must be signed in to change notification settings - Fork 0
/
tlcApalache.tla
37 lines (32 loc) · 1.77 KB
/
tlcApalache.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
---- MODULE tlcApalache ----
EXTENDS Integers, FiniteSets, Sequences
(*****************************************************************************)
(* The folding operator, used to implement computation over a set. *)
(* Apalache implements a more efficient encoding than the one below. *)
(* (from the community modules). *)
(*****************************************************************************)
RECURSIVE FoldSet(_,_,_)
FoldSet( Op(_,_), v, S ) == IF S = {}
THEN v
ELSE LET w == CHOOSE x \in S: TRUE
IN LET T == S \ {w}
IN FoldSet( Op, Op(v,w), T )
(*****************************************************************************)
(* The folding operator, used to implement computation over a sequence. *)
(* Apalache implements a more efficient encoding than the one below. *)
(* (from the community modules). *)
(*****************************************************************************)
RECURSIVE FoldSeq(_,_,_)
FoldSeq( Op(_,_), v, seq ) == IF seq = <<>>
THEN v
ELSE FoldSeq( Op, Op(v,Head(seq)), Tail(seq) )
(*****************************************************************************)
(* Convert a set of pairs to a function. *)
(* Apalache implements a more efficient encoding than the one below. *)
(*****************************************************************************)
SetAsFun(S) ==
LET Dom == { x: <<x, y>> \in S }
Rng == { y: <<x, y>> \in S }
IN
[ x \in Dom |-> CHOOSE y \in Rng: <<x, y>> \in S ]
====