Skip to content

Commit a20cc8e

Browse files
committed
Theorems for sum of constant function
Add SumFunctionOnSetConst and SumFunctionConst stating that summing a constant function over a finite set equals the constant times the cardinality of the set, together with corresponding proofs and an example in the doc comments. [Feature] Signed-off-by: Markus Alexander Kuppe <[email protected]> Signed-off-by: Stephan Merz <[email protected]> Signed-off-by: Markus Alexander Kuppe <[email protected]>
1 parent b0fa012 commit a20cc8e

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

modules/FunctionTheorems.tla

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,18 @@ THEOREM SumFunctionOnSetZero ==
767767
NEW fun, \A x \in S : fun[x] \in Nat
768768
PROVE SumFunctionOnSet(fun, S) = 0 <=> \A x \in S : fun[x] = 0
769769

770+
(*************************************************************************)
771+
(* Given any Int-valued function f and finite set S such that f[s] = c *)
772+
(* for all s \in S, summing f over S yields c multiplied by the *)
773+
(* cardinality of S. For example, for *)
774+
(* f == [s \in {"a", "b", "c"} |-> IF s = "c" THEN 42 ELSE 5], *)
775+
(* SumFunctionOnSet(f, {"a","b"}) = 10. *)
776+
(*************************************************************************)
777+
THEOREM SumFunctionOnSetConst ==
778+
ASSUME NEW D, NEW S \in SUBSET D, IsFiniteSet(S),
779+
NEW f \in [D -> Int], NEW c \in Int, \A x \in S : f[x] = c
780+
PROVE SumFunctionOnSet(f, S) = c * Cardinality(S)
781+
770782
(*************************************************************************)
771783
(* Summing a function is monotonic in the function argument. *)
772784
(*************************************************************************)
@@ -825,6 +837,15 @@ THEOREM SumFunctionZero ==
825837
\A x \in DOMAIN fun : fun[x] \in Nat
826838
PROVE SumFunction(fun) = 0 <=> \A x \in DOMAIN fun : fun[x] = 0
827839

840+
(*************************************************************************)
841+
(* Summing a constant function yields the constant multiplied by the *)
842+
(* cardinality of its domain. For example, *)
843+
(* SumFunction([s \in {"a","b","c"} |-> 5]) = 15. *)
844+
(*************************************************************************)
845+
THEOREM SumFunctionConst ==
846+
ASSUME NEW S, IsFiniteSet(S), NEW c \in Int
847+
PROVE SumFunction([s \in S |-> c]) = c * Cardinality(S)
848+
828849
THEOREM SumFunctionMonotonic ==
829850
ASSUME NEW f, IsFiniteSet(DOMAIN f), NEW g, DOMAIN g = DOMAIN f,
830851
\A x \in DOMAIN f : f[x] \in Int,

modules/FunctionTheorems_proofs.tla

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,33 @@ THEOREM SumFunctionOnSetZero ==
13101310
<2>. P(S) BY <1>1, <1>2, FS_Induction, IsaM("iprover")
13111311
<2>. QED BY DEF P
13121312

1313+
(*************************************************************************)
1314+
(* Given any Int-valued function f and finite set S such that f[s] = c *)
1315+
(* for all s \in S, summing f over S yields c multiplied by the *)
1316+
(* cardinality of S. *)
1317+
(*************************************************************************)
1318+
THEOREM SumFunctionOnSetConst ==
1319+
ASSUME NEW D, NEW S \in SUBSET D, IsFiniteSet(S),
1320+
NEW f \in [D -> Int], NEW c \in Int, \A x \in S : f[x] = c
1321+
PROVE SumFunctionOnSet(f, S) = c * Cardinality(S)
1322+
<1>. DEFINE P(T) == SumFunctionOnSet(f, T) = c * Cardinality(T)
1323+
<1>1. P({})
1324+
<2>1. SumFunctionOnSet(f, {}) = 0
1325+
BY SumFunctionOnSetEmpty
1326+
<2>2. Cardinality({}) = 0
1327+
BY FS_EmptySet
1328+
<2>. QED BY <2>1, <2>2
1329+
<1>2. ASSUME NEW T \in SUBSET S, IsFiniteSet(T), P(T), NEW x \in S \ T
1330+
PROVE P(T \union {x})
1331+
<2>1. SumFunctionOnSet(f, T \union {x}) = c + SumFunctionOnSet(f, T)
1332+
BY <1>2, SumFunctionOnSetAddIndex
1333+
<2>2. Cardinality(T \union {x}) = Cardinality(T) + 1
1334+
BY <1>2, FS_AddElement
1335+
<2>3. Cardinality(T) \in Nat
1336+
BY <1>2, FS_CardinalityType
1337+
<2>. QED BY <1>2, <2>1, <2>2, <2>3
1338+
<1>. QED BY <1>1, <1>2, FS_Induction, IsaM("iprover")
1339+
13131340
(*************************************************************************)
13141341
(* Summing a function is monotonic in the function argument. *)
13151342
(*************************************************************************)
@@ -1401,6 +1428,11 @@ THEOREM SumFunctionZero ==
14011428
PROVE SumFunction(fun) = 0 <=> \A x \in DOMAIN fun : fun[x] = 0
14021429
BY SumFunctionOnSetZero DEF SumFunction
14031430

1431+
THEOREM SumFunctionConst ==
1432+
ASSUME NEW S, IsFiniteSet(S), NEW c \in Int
1433+
PROVE SumFunction([s \in S |-> c]) = c * Cardinality(S)
1434+
BY SumFunctionOnSetConst DEF SumFunction
1435+
14041436
THEOREM SumFunctionMonotonic ==
14051437
ASSUME NEW f, IsFiniteSet(DOMAIN f), NEW g, DOMAIN g = DOMAIN f,
14061438
\A x \in DOMAIN f : f[x] \in Int,

0 commit comments

Comments
 (0)