11---------------------------- MODULE SequencesExt ----------------------------
2- EXTENDS Sequences , Naturals , FiniteSets , FiniteSetsExt , Folds , Functions
2+ EXTENDS Sequences , Naturals , FiniteSets , FiniteSetsExt , Folds , Functions , Bags
33\* TLAPM does not play well with LOCAL INSTANCE, reinstate the following
44\* when that issue is fixed.
55\* LOCAL INSTANCE Sequences
@@ -8,6 +8,7 @@ EXTENDS Sequences, Naturals, FiniteSets, FiniteSetsExt, Folds, Functions
88\* LOCAL INSTANCE FiniteSetsExt
99\* LOCAL INSTANCE Folds
1010\* LOCAL INSTANCE Functions
11+ \* LOCAL INSTANCE Bags
1112LOCAL INSTANCE TLC
1213 (* ************************************************************************)
1314 (* Imports the definitions from the modules, but doesn't export them. *)
@@ -33,6 +34,12 @@ LOCAL INSTANCE TLC
3334ToSet ( s ) ==
3435 { s [ i ] : i \in DOMAIN s }
3536
37+ (* *************************************************************************)
38+ (* Convert a sequence to the bag of its elements. *)
39+ (************************************************************************* *)
40+ ToBag ( s ) ==
41+ [ x \in Range ( s ) |-> Cardinality ( { i \in DOMAIN s : s [ i ] = x } ) ]
42+
3643(* *************************************************************************)
3744(* Convert a set to some sequence that contains all the elements of the *)
3845(* set exactly once, and contains no other elements. *)
0 commit comments