Skip to content

Commit b346abd

Browse files
theorem library for fold operators
1 parent f5db5ee commit b346abd

File tree

5 files changed

+686
-8
lines changed

5 files changed

+686
-8
lines changed

modules/FiniteSetsExt.tla

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--------------------------- MODULE FiniteSetsExt ---------------------------
22
EXTENDS Folds, Functions \* Replace with LOCAL INSTANCE when https://github.com/tlaplus/tlapm/issues/119 is resolved.
3-
LOCAL INSTANCE Naturals
3+
LOCAL INSTANCE Integers
44
LOCAL INSTANCE FiniteSets
55

66
(*************************************************************************)

modules/FiniteSetsExt_theorems.tla

Lines changed: 114 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,118 @@
1-
---- MODULE FiniteSetsExt_theorems ----
2-
EXTENDS FiniteSetsExt, FiniteSets, Naturals
1+
-------------------------- MODULE FiniteSetsExt_theorems ------------------
2+
EXTENDS FiniteSetsExt, FiniteSets, Integers
3+
(*************************************************************************)
4+
(* This module only lists theorem statements for reference. The proofs *)
5+
(* can be found in module FiniteSetsExt_theorems_proofs.tla. *)
6+
(*************************************************************************)
37

8+
THEOREM FoldSetEmpty ==
9+
ASSUME NEW op(_,_), NEW base
10+
PROVE FoldSet(op, base, {}) = base
11+
12+
THEOREM FoldSetNonempty ==
13+
ASSUME NEW op(_,_), NEW base, NEW S, S # {}, IsFiniteSet(S)
14+
PROVE \E x \in S : FoldSet(op, base, S) = op(x, FoldSet(op, base, S \ {x}))
15+
16+
THEOREM FoldSetType ==
17+
ASSUME NEW Typ, NEW op(_,_), NEW base \in Typ,
18+
NEW S \in SUBSET Typ, IsFiniteSet(S),
19+
\A t,u \in Typ : op(t,u) \in Typ
20+
PROVE FoldSet(op, base, S) \in Typ
21+
22+
\* more useful version for an associative-commutative operator op
23+
THEOREM FoldSetAC ==
24+
ASSUME NEW Typ, NEW op(_,_), NEW base \in Typ,
25+
\A t,u \in Typ : op(t,u) \in Typ,
26+
\A t,u \in Typ : op(t,u) = op(u,t),
27+
\A t,u,v \in Typ : op(t, op(u,v)) = op(op(t,u),v),
28+
NEW S \in SUBSET Typ, IsFiniteSet(S),
29+
NEW x \in S
30+
PROVE FoldSet(op, base, S) = op(x, FoldSet(op, base, S \ {x}))
31+
32+
---------------------------------------------------------------------------
33+
34+
THEOREM SumSetNat ==
35+
ASSUME NEW S \in SUBSET Nat, IsFiniteSet(S)
36+
PROVE SumSet(S) \in Nat
37+
38+
THEOREM SumSetInt ==
39+
ASSUME NEW S \in SUBSET Int, IsFiniteSet(S)
40+
PROVE SumSet(S) \in Int
41+
42+
THEOREM SumSetEmpty == SumSet({}) = 0
43+
44+
THEOREM SumSetNonempty ==
45+
ASSUME NEW S \in SUBSET Int, IsFiniteSet(S), NEW x \in S
46+
PROVE SumSet(S) = x + SumSet(S \ {x})
47+
48+
THEOREM SumSetNatZero ==
49+
ASSUME NEW S \in SUBSET Nat, IsFiniteSet(S)
50+
PROVE SumSet(S) = 0 <=> S \subseteq {0}
51+
52+
---------------------------------------------------------------------------
53+
54+
THEOREM ProductSetNat ==
55+
ASSUME NEW S \in SUBSET Nat, IsFiniteSet(S)
56+
PROVE ProductSet(S) \in Nat
57+
58+
THEOREM ProductSetInt ==
59+
ASSUME NEW S \in SUBSET Int, IsFiniteSet(S)
60+
PROVE ProductSet(S) \in Int
61+
62+
THEOREM ProductSetNonempty ==
63+
ASSUME NEW S \in SUBSET Int, IsFiniteSet(S), NEW x \in S
64+
PROVE ProductSet(S) = x * ProductSet(S \ {x})
65+
66+
THEOREM ProductSetNatOne ==
67+
ASSUME NEW S \in SUBSET Nat, IsFiniteSet(S)
68+
PROVE ProductSet(S) = 1 <=> S \subseteq {1}
69+
70+
THEOREM ProductSetZero ==
71+
ASSUME NEW S \in SUBSET Int, IsFiniteSet(S)
72+
PROVE ProductSet(S) = 0 <=> 0 \in S
73+
74+
---------------------------------------------------------------------------
75+
76+
THEOREM MapThenSumSetNat ==
77+
ASSUME NEW S, IsFiniteSet(S),
78+
NEW op(_), \A s \in S : op(s) \in Nat
79+
PROVE MapThenSumSet(op, S) \in Nat
80+
81+
THEOREM MapThenSumSetInt ==
82+
ASSUME NEW S, IsFiniteSet(S),
83+
NEW op(_), \A s \in S : op(s) \in Int
84+
PROVE MapThenSumSet(op, S) \in Int
85+
86+
THEOREM MapThenSumSetEmpty ==
87+
ASSUME NEW op(_)
88+
PROVE MapThenSumSet(op, {}) = 0
89+
90+
THEOREM MapThenSumSetNonempty ==
91+
ASSUME NEW S, IsFiniteSet(S), NEW x \in S,
92+
NEW op(_), \A s \in S : op(s) \in Int
93+
PROVE MapThenSumSet(op, S) = op(x) + MapThenSumSet(op, S \ {x})
94+
95+
THEOREM MapThenSumSetZero ==
96+
ASSUME NEW S, IsFiniteSet(S),
97+
NEW op(_), \A s \in S : op(s) \in Nat
98+
PROVE MapThenSumSet(op, S) = 0 <=> \A s \in S : op(s) = 0
99+
100+
THEOREM MapThenSumSetMonotonic ==
101+
ASSUME NEW S, IsFiniteSet(S),
102+
NEW f(_), \A s \in S : f(s) \in Int,
103+
NEW g(_), \A s \in S : g(s) \in Int,
104+
\A s \in S : f(s) <= g(s)
105+
PROVE MapThenSumSet(f, S) <= MapThenSumSet(g, S)
106+
107+
THEOREM MapThenSumSetStrictlyMonotonic ==
108+
ASSUME NEW S, IsFiniteSet(S),
109+
NEW f(_), \A s \in S : f(s) \in Int,
110+
NEW g(_), \A s \in S : g(s) \in Int,
111+
\A s \in S : f(s) <= g(s),
112+
\E s \in S : f(s) < g(s)
113+
PROVE MapThenSumSet(f, S) < MapThenSumSet(g, S)
114+
115+
===========================================================================
4116
LEMMA MapThenSumSetEmpty ==
5117
ASSUME NEW op(_)
6118
PROVE MapThenSumSet(op, {}) = 0

0 commit comments

Comments
 (0)