Skip to content

Commit

Permalink
MapThenSumSet and several theorems for it. (#99)
Browse files Browse the repository at this point in the history
FiniteSetsExt!MapThenSumSet including and support TLAPS theorems.

[Feature]

Signed-off-by: Karolis Petrauskas <karolis.petrauskas@erisata.lt>
  • Loading branch information
kape1395 authored and lemmy committed Feb 21, 2024
1 parent ea36000 commit b4deee7
Show file tree
Hide file tree
Showing 4 changed files with 468 additions and 5 deletions.
14 changes: 12 additions & 2 deletions modules/FiniteSetsExt.tla
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
--------------------------- MODULE FiniteSetsExt ---------------------------
EXTENDS Folds, Functions \* Replace with LOCAL INSTANCE when https://github.com/tlaplus/tlapm/issues/119 is resolved.
LOCAL INSTANCE Naturals
LOCAL INSTANCE FiniteSets
LOCAL INSTANCE Functions
LOCAL INSTANCE Folds

FoldSet(op(_,_), base, set) ==
(*************************************************************************)
Expand Down Expand Up @@ -38,6 +37,17 @@ ReduceSet(op(_, _), set, acc) ==
(*************************************************************************)
FoldSet(op, acc, set)

MapThenSumSet(op(_), set) ==
(*************************************************************************)
(* Calculate the sum of projections of the elements in a set. *)
(* *)
(* Example: *)
(* MapThenSumSet( *)
(* LAMBDA e : e.n, *)
(* {[n |-> 0], [n |-> 1], [n |-> 2]} *)
(* ) = 3 *)
(*************************************************************************)
MapThenFoldSet(+, 0, op, LAMBDA s : CHOOSE x \in s : TRUE, set)

FlattenSet(S) ==
UNION S
Expand Down
53 changes: 53 additions & 0 deletions modules/FiniteSetsExt_theorems.tla
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---- MODULE FiniteSetsExt_theorems ----
EXTENDS FiniteSetsExt, FiniteSets, Naturals

LEMMA MapThenSumSetEmpty ==
ASSUME NEW op(_)
PROVE MapThenSumSet(op, {}) = 0
PROOF OMITTED \* Proof in FiniteSetsExt_theorems_proofs.tla


LEMMA MapThenSumSetType ==
ASSUME NEW S, IsFiniteSet(S), NEW op(_), \A e \in S : op(e) \in Nat
PROVE MapThenSumSet(op, S) \in Nat
PROOF OMITTED \* Proof in FiniteSetsExt_theorems_proofs.tla


THEOREM MapThenSumSetAddElem ==
ASSUME
NEW S, IsFiniteSet(S),
NEW op(_), \A s \in S : op(s) \in Nat,
NEW e, e \notin S, op(e) \in Nat
PROVE MapThenSumSet(op, S \cup {e}) = MapThenSumSet(op, S) + op(e)
PROOF OMITTED \* Proof in FiniteSetsExt_theorems_proofs.tla

LEMMA MapThenSumSetRemElem ==
ASSUME
NEW S, IsFiniteSet(S),
NEW op(_), \A s \in S : op(s) \in Nat,
NEW e \in S
PROVE MapThenSumSet(op, S) = MapThenSumSet(op, S \ {e}) + op(e)
PROOF OMITTED \* Proof in FiniteSetsExt_theorems_proofs.tla

LEMMA MapThenSumSetMonotonic ==
ASSUME
NEW S, IsFiniteSet(S),
NEW op(_), \A s \in S : op(s) \in Nat,
NEW e, e \notin S, op(e) \in Nat
PROVE MapThenSumSet(op, S \cup {e}) >= MapThenSumSet(op, S)
PROOF OMITTED \* Proof in FiniteSetsExt_theorems_proofs.tla

LEMMA MapThenSumSetZero ==
ASSUME NEW S, IsFiniteSet(S),
NEW op(_), \A e \in S: op(e) \in Nat,
MapThenSumSet(op, S) = 0
PROVE \A e \in S: op(e) = 0
PROOF OMITTED \* Proof in FiniteSetsExt_theorems_proofs.tla

LEMMA MapThenSumSetZeros ==
ASSUME NEW S, IsFiniteSet(S),
NEW op(_), \A e \in S: op(e) = 0
PROVE MapThenSumSet(op, S) = 0
PROOF OMITTED \* Proof in FiniteSetsExt_theorems_proofs.tla

====
Loading

0 comments on commit b4deee7

Please sign in to comment.