Skip to content

Commit 7c13d06

Browse files
generalize SumFunctionOnSetConst
Signed-off-by: Stephan Merz <stephan.merz@loria.fr>
1 parent 8cf27fc commit 7c13d06

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

modules/FunctionTheorems.tla

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,14 +767,28 @@ 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 constant function over a finite set yields the constant *)
772784
(* multiplied by the cardinality of the set. For example, *)
773785
(* SumFunctionOnSet([s \in {"a","b","c"} |-> 5], {"a","b","c"}) = 15. *)
774786
(*************************************************************************)
787+
(*
775788
THEOREM SumFunctionOnSetConst ==
776789
ASSUME NEW S, IsFiniteSet(S), NEW c \in Int
777790
PROVE SumFunctionOnSet([s \in S |-> c], S) = c * Cardinality(S)
791+
*)
778792

779793
(*************************************************************************)
780794
(* Summing a function is monotonic in the function argument. *)

modules/FunctionTheorems_proofs.tla

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,10 +1310,38 @@ 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 constant function over a finite set yields the constant *)
13151342
(* multiplied by the cardinality of the set. *)
13161343
(*************************************************************************)
1344+
(*
13171345
THEOREM SumFunctionOnSetConst ==
13181346
ASSUME NEW S, IsFiniteSet(S), NEW c \in Int
13191347
PROVE SumFunctionOnSet([s \in S |-> c], S) = c * Cardinality(S)
@@ -1352,6 +1380,7 @@ THEOREM SumFunctionOnSetConst ==
13521380
<2>. HIDE DEF P
13531381
<2>. P(S) BY <1>1, <1>2, FS_Induction, IsaM("iprover")
13541382
<2>. QED BY DEF P
1383+
*)
13551384

13561385
(*************************************************************************)
13571386
(* Summing a function is monotonic in the function argument. *)
@@ -1447,6 +1476,8 @@ BY SumFunctionOnSetZero DEF SumFunction
14471476
THEOREM SumFunctionConst ==
14481477
ASSUME NEW S, IsFiniteSet(S), NEW c \in Int
14491478
PROVE SumFunction([s \in S |-> c]) = c * Cardinality(S)
1479+
BY SumFunctionOnSetConst DEF SumFunction
1480+
(*
14501481
<1>. DEFINE fun == [s \in S |-> c]
14511482
<1>1. DOMAIN fun = S
14521483
OBVIOUS
@@ -1455,6 +1486,7 @@ THEOREM SumFunctionConst ==
14551486
<1>3. SumFunctionOnSet(fun, S) = c * Cardinality(S)
14561487
BY SumFunctionOnSetConst
14571488
<1>. QED BY <1>2, <1>3
1489+
*)
14581490

14591491
THEOREM SumFunctionMonotonic ==
14601492
ASSUME NEW f, IsFiniteSet(DOMAIN f), NEW g, DOMAIN g = DOMAIN f,

0 commit comments

Comments
 (0)