Skip to content

Commit 9ac86fb

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 <github.com@lemmster.de>
1 parent 3ecb8c6 commit 9ac86fb

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

modules/FunctionTheorems.tla

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,15 @@ 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+
(* Summing a constant function over a finite set yields the constant *)
772+
(* multiplied by the cardinality of the set. For example, *)
773+
(* SumFunctionOnSet([s \in {"a","b","c"} |-> 5], {"a","b","c"}) = 15. *)
774+
(*************************************************************************)
775+
THEOREM SumFunctionOnSetConst ==
776+
ASSUME NEW S, IsFiniteSet(S), NEW c \in Int
777+
PROVE SumFunctionOnSet([s \in S |-> c], S) = c * Cardinality(S)
778+
770779
(*************************************************************************)
771780
(* Summing a function is monotonic in the function argument. *)
772781
(*************************************************************************)
@@ -825,6 +834,15 @@ THEOREM SumFunctionZero ==
825834
\A x \in DOMAIN fun : fun[x] \in Nat
826835
PROVE SumFunction(fun) = 0 <=> \A x \in DOMAIN fun : fun[x] = 0
827836

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

modules/FunctionTheorems_proofs.tla

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,37 @@ THEOREM SumFunctionOnSetZero ==
13011301
<2>. P(S) BY <1>1, <1>2, FS_Induction, IsaM("iprover")
13021302
<2>. QED BY DEF P
13031303

1304+
(*************************************************************************)
1305+
(* Summing a constant function over a finite set yields the constant *)
1306+
(* multiplied by the cardinality of the set. *)
1307+
(*************************************************************************)
1308+
THEOREM SumFunctionOnSetConst ==
1309+
ASSUME NEW S, IsFiniteSet(S), NEW c \in Int
1310+
PROVE SumFunctionOnSet([s \in S |-> c], S) = c * Cardinality(S)
1311+
<1>. DEFINE fun == [s \in S |-> c]
1312+
<1>. DEFINE P(T) == SumFunctionOnSet(fun, T) = c * Cardinality(T)
1313+
<1>1. P({})
1314+
BY SumFunctionOnSetEmpty, FS_EmptySet
1315+
<1>2. ASSUME NEW T \in SUBSET S, IsFiniteSet(T), P(T), NEW x \in S \ T
1316+
PROVE P(T \union {x})
1317+
<2>1. \A j \in T \union {x} : fun[j] = c
1318+
BY <1>2
1319+
<2>2. \A j \in T \union {x} : fun[j] \in Int
1320+
BY <2>1
1321+
<2>3. SumFunctionOnSet(fun, T \union {x}) = fun[x] + SumFunctionOnSet(fun, T)
1322+
BY <1>2, <2>2, SumFunctionOnSetAddIndex
1323+
<2>4. fun[x] = c
1324+
BY <1>2
1325+
<2>5. Cardinality(T \union {x}) = Cardinality(T) + 1
1326+
BY <1>2, FS_AddElement
1327+
<2>6. Cardinality(T) \in Nat
1328+
BY <1>2, FS_CardinalityType
1329+
<2>. QED BY <1>2, <2>3, <2>4, <2>5, <2>6
1330+
<1>. QED
1331+
<2>. HIDE DEF P
1332+
<2>. P(S) BY <1>1, <1>2, FS_Induction, IsaM("iprover")
1333+
<2>. QED BY DEF P
1334+
13041335
(*************************************************************************)
13051336
(* Summing a function is monotonic in the function argument. *)
13061337
(*************************************************************************)
@@ -1392,6 +1423,11 @@ THEOREM SumFunctionZero ==
13921423
PROVE SumFunction(fun) = 0 <=> \A x \in DOMAIN fun : fun[x] = 0
13931424
BY SumFunctionOnSetZero DEF SumFunction
13941425

1426+
THEOREM SumFunctionConst ==
1427+
ASSUME NEW S, IsFiniteSet(S), NEW c \in Int
1428+
PROVE SumFunction([s \in S |-> c]) = c * Cardinality(S)
1429+
BY SumFunctionOnSetConst DEF SumFunction
1430+
13951431
THEOREM SumFunctionMonotonic ==
13961432
ASSUME NEW f, IsFiniteSet(DOMAIN f), NEW g, DOMAIN g = DOMAIN f,
13971433
\A x \in DOMAIN f : f[x] \in Int,

0 commit comments

Comments
 (0)