Skip to content

Commit 8cf27fc

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 dc9c597 commit 8cf27fc

2 files changed

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

1313+
(*************************************************************************)
1314+
(* Summing a constant function over a finite set yields the constant *)
1315+
(* multiplied by the cardinality of the set. *)
1316+
(*************************************************************************)
1317+
THEOREM SumFunctionOnSetConst ==
1318+
ASSUME NEW S, IsFiniteSet(S), NEW c \in Int
1319+
PROVE SumFunctionOnSet([s \in S |-> c], S) = c * Cardinality(S)
1320+
<1>. DEFINE fun == [s \in S |-> c]
1321+
<1>. DEFINE P(T) == SumFunctionOnSet(fun, T) = c * Cardinality(T)
1322+
<1>1. P({})
1323+
<2>1. SumFunctionOnSet(fun, {}) = 0
1324+
BY SumFunctionOnSetEmpty
1325+
<2>2. Cardinality({}) = 0
1326+
BY FS_EmptySet
1327+
<2>3. c * Cardinality({}) = 0
1328+
BY <2>2
1329+
<2>. QED BY <2>1, <2>3
1330+
<1>2. ASSUME NEW T \in SUBSET S, IsFiniteSet(T), P(T), NEW x \in S \ T
1331+
PROVE P(T \union {x})
1332+
<2>1. \A j \in T \union {x} : fun[j] = c
1333+
BY <1>2
1334+
<2>2. \A j \in T \union {x} : fun[j] \in Int
1335+
BY <2>1, c \in Int
1336+
<2>3. SumFunctionOnSet(fun, T \union {x}) = fun[x] + SumFunctionOnSet(fun, T)
1337+
BY <1>2, <2>2, SumFunctionOnSetAddIndex
1338+
<2>4. fun[x] = c
1339+
BY <1>2
1340+
<2>5. Cardinality(T \union {x}) = Cardinality(T) + 1
1341+
BY <1>2, FS_AddElement
1342+
<2>6. Cardinality(T) \in Nat
1343+
BY <1>2, FS_CardinalityType
1344+
<2>7. SumFunctionOnSet(fun, T \union {x}) = c + c * Cardinality(T)
1345+
BY <1>2, <2>3, <2>4
1346+
<2>8. c + c * Cardinality(T) = c * (Cardinality(T) + 1)
1347+
BY <2>6
1348+
<2>9. c * (Cardinality(T) + 1) = c * Cardinality(T \union {x})
1349+
BY <2>5
1350+
<2>. QED BY <2>7, <2>8, <2>9
1351+
<1>. QED
1352+
<2>. HIDE DEF P
1353+
<2>. P(S) BY <1>1, <1>2, FS_Induction, IsaM("iprover")
1354+
<2>. QED BY DEF P
1355+
13131356
(*************************************************************************)
13141357
(* Summing a function is monotonic in the function argument. *)
13151358
(*************************************************************************)
@@ -1401,6 +1444,18 @@ THEOREM SumFunctionZero ==
14011444
PROVE SumFunction(fun) = 0 <=> \A x \in DOMAIN fun : fun[x] = 0
14021445
BY SumFunctionOnSetZero DEF SumFunction
14031446

1447+
THEOREM SumFunctionConst ==
1448+
ASSUME NEW S, IsFiniteSet(S), NEW c \in Int
1449+
PROVE SumFunction([s \in S |-> c]) = c * Cardinality(S)
1450+
<1>. DEFINE fun == [s \in S |-> c]
1451+
<1>1. DOMAIN fun = S
1452+
OBVIOUS
1453+
<1>2. SumFunction(fun) = SumFunctionOnSet(fun, S)
1454+
BY <1>1 DEF SumFunction
1455+
<1>3. SumFunctionOnSet(fun, S) = c * Cardinality(S)
1456+
BY SumFunctionOnSetConst
1457+
<1>. QED BY <1>2, <1>3
1458+
14041459
THEOREM SumFunctionMonotonic ==
14051460
ASSUME NEW f, IsFiniteSet(DOMAIN f), NEW g, DOMAIN g = DOMAIN f,
14061461
\A x \in DOMAIN f : f[x] \in Int,

0 commit comments

Comments
 (0)