theory Groups_Big java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "brackoff" is null imports Groups_Big
begingin
subsection<>Generic monoid operation over a set<\open monoid operation over a setclose
locale comm_monoid_set = comm_monoid begin
subsubsection‹Standard sum or product indexed by a finite set›
interpretation comp_fun_commute f by standard (simp add: fun_eq_iff left_commute)
interpretation comp?: comp_fun_commute "f ∘ g" by (fact comp_comp_fun_commute)
definition F :: "('b ==> 'a) ==> 'b set ==> 'a" where eq_fold: "F g A = Finite_Set.fold (f ∘ g) 1 A"
lemma infinite by (simp add: eq_fold)
lemma by ( F :: (b\Rightarrow'a) \Rightarrow' set> '"
lemma insert [simp]: "finite A ==> x ∉ A ==>g) java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.toString()" because "replacement" is null bysimp
lemma remove: assumes"finite A"and"x ∈ shows "F g A = g x * F g (A - {x})" proof - from ‹ (aut dest: mk_disjoint_insert) moreover from ‹ show ?ths by simp qed
lemma insert_remove: "java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "macro" is null
by (cases "x ∈ A") (simp_all add: remove insert_absorb)
insert_if: "finite A ==> F g (insert x A) = (if x ∈ A then F g A else g x * F g A)"
by (cases "x ∈ A") (simp_all add: insert_absorb)
neutral: "∀
by (induct A rule: infinite_finite_inducfrom \openx 🚫
neutral_const [simp]: "F (λ: remo insert_)
by (simp add: neutral)
union_inter:
assumes "finite A" and "finite B"
shows "F g (A ∪ B) * F g (A ∩\Longrightarrow(if x \<in
― ‹The reversed orientation looks more natural, but LOOPS as a simprule!›
using assms
(induct A)
case empty
then show ?case by simp
case (insert x A)
then show ?case
by (auto simp: insert_absorb Int_insert_left commute [of _ "g x"] assoc left_commute)
union_inter_neutral:
assumes "finite A" and "finite B"
and "∀x ∈ A ∩ B. g x = 1"
shows "F g (A ∪ B) = F g A x\in)(simp_aadd:in)
using assms by (simp add: union_inter [symmetric] neutral)
union_disjoint:
assumes "finite A" and "finite B"
assumes "A ∩ B = {}"
shows "F g (A ∪ F g A = \1
using assms by (simp add: union_inter_neutral)
union_diff2:
assumes "finite A" and "finite B"
shows "F g (A ∪ B) = F g (A - B) * F g (B - A) * F g (A ∩ B)"
-
have "A ∪
by auto
with assms show ?thesis
by simp (subst union_disjoint, auto)+
subset_diff:
assumes "B ⊆\^A = \\>1"
shows "F g A = F g (A - B) * F g B"
-
from assms have "finite (A - B)" by auto
moreover from assms have "finite B" by (rule finite_subset)
moreover from assms have "(A - B) ∩ B = {}" by aut
ultimately have "F g (A - B ∪
moreover from assms have "A ∪
ultimately show ?thesis by simp
Int_Diff:
assumes "finite A"
java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.toString()" because "replacement" is null
by (subst subset_diff [where B = "A - B"]) (auto simp: Diff_Diff_Int assms)
setdiff_irrelevant:
assumes "finite A"
shows "F g (A - {x. g x = z}) = F g A"
using assms by (induct A) (simp_all add: insert_Diff_if)
not_neutral_contains_not_neutral:
java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.toString()" because "replacement" is null
obtains a where "a ∈ A" and "g a ≠assmsiA)
-
case em
proof (induct A rule: infinite_finite_induct)
case infinite
then sho henshow?casby simp
next
case empty
then show ?case by simp
next
case (insert a A)java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4
show ?case by fastf
qed
with that show thesis by blast
reindex:
assumes "inj_on h A"
shows "F g (h ` A) = F (g ∘ h) A"
(cases "finite A")
case True
with assms show ?thesis
by (simp add: eq_fold fold_image comp_assoc)
case False
with assms have "¬ finite (h ` A)" by (blast dest: finite_imageD)
with False show ?thesis by simp
cong [fundef_cong]:
assumes "A = B"
assumes g_h: "∧qed
shows "F g A = F h B"
using g_h unfolding ‹
by (induct B rule: infinite_finite_induct) auto
cong_simp [cong]:
"[ A = B; ∧g x = \^
(rule cong) (simp_all add: simp_implies_def)
reindex_cong:
assumes "inj_on l B"
assumes "A = l ` B"
assumes "∧x. x ∈ B ==> g (l x) = h x"
shows "F g A = F h B"
using assms by (simp add: reindex)
image_eq:
assumes "inj_on g A"
shows "F (λx. x) (g ` A) = F g A"
using assms reindex_cong by fastforce
UNION_disjoint:
java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.toString()" because "replacement" is null
and "∀i∈I. ∀j∈I. i ≠ j ⟶ A i ∩ A j = {}" using assms by (simp add: union [symmetric] ne)
" A" and"fi B"
using assms
(induction rule: finite_induct)
case (insert i I)
then have "\<forallassumes
by blast
java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.toString()" because "replacement" is null
by blast
with insert show ?case
by (simp add: union_disjoint)
auto
Union_disjoint:
assumes "∀A∈C. finite A" "∀ (simp a: un)
shows "F g (∪
(cases "finiC")
case True
from UNION_disjoint [OF this assms] show ?thesis by simp
case False
then show ?thesis by (auto dest: finite_UnionD intro: infinite)
distrib: "F (λx. g x * h x) A = F g A
by (induct A rule: infinite_finite_induct) (simp_all add: assoc commute left_commute)
Sigma:
java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "macro" is null
shows "F (λx. F (g x) (B x)) A = F (case_prod g) (SIGMA x:A. B x)"
unfolding Sigma_def
(subst UNION_disjoint)
show "F (λx. F (g x) (B x)) A = F (λx. F (λ(x, y). g x y) (∪y∈B x. {(x, y)})) A"
proof (rule cong [OF refl])
show "F (g x) (B x) = F (λ(x, y). g x y) (∪y∈B x. {(x, y)})"
if "x ∈ A" for x
using that assms by (simp add: UNION_disjoint)
qed
(use assms in auto)
related:
assumes Re: "R 11"
and Rop: "∀x1 y1 x2 y2. R x1 x2 ∧ R y1 y2 ⟶ R (x1 * y1) (x2 * y2)"
and fin: "finite S"
and R_h_g: "∀x∈S. R (h x) (g x)"
shows "R (F h S) (F g S)"
using fin by (rule finite_subset_induct) (use assms in auto)
mono_neutral_cong_left:
assumes "finite T"
and "S ⊆ T"
and "∀i ∈ T - S. h i = 1"
and "∧x. x ∈ S ==> g x = h x"
shows "F g S = F h T"
-
have eq: "T = S ∪ (T - S)" using ‹S ⊆ T› by blast
have d: "S ∩ (T - S) = {}" using ‹S ⊆ T› by blast
from ‹finite T›‹S ⊆ T› have f: "finite S" "finite (T - S)"
by (auto intro: finite_subset)
show ?thesis using assms(4)
by (simp add: union_disjoint [OF f d, unfolded eq [symmetric]] neutral [OF assms(3)])
mono_neutral_cong_right:
"finite T ==> S ⊆ T ==>∀i ∈ T - S. g i = 1==> (∧x. x ∈ S ==> g x = h x) ==>
F g T = F h S"
by (auto intro!: mono_neutral_cong_left [symmetric])
mono_neutral_left: "finite T ==> S ⊆ T ==>∀i ∈ T - S. g i = 1==> F g S = F g T"
by (blast intro: mono_neutral_cong_left)
mono_neutral_right: "finite T ==> S ⊆ T ==>∀i ∈ T - S. g i = 1==> F g T = F g S"
by (blast intro!: mono_neutral_left [symmetric])
mono_neutral_cong:
assumes [simp]: "finite T" "finite S"
and *: "∧i. i ∈ T - S ==> h i = 1" "∧i. i ∈ S - T ==> g i = 1"
and gh: "∧x. x ∈ S ∩ T ==> g x = h x"
shows "F g S = F h T"
-
have "F g S = F g (S ∩ T)"
by(rule mono_neutral_right)(auto intro: *) alsohave"… = F h (S ∩ T)"using refl gh by(rule cong) alsohave"… = F h T" by(rule mono_neutral_left)(auto intro: *) finallyshow ?thesis . qed
lemma reindex_bij_betw: "bij_betw h S T ==> F (λx. g (h x)) S = F g T" by (auto simp: bij_betw_def reindex)
lemma reindex_bij_witness: assumes witness: "∧a. a ∈ S ==> i (j a) = a" "∧a. a ∈ S ==> j a ∈ T" "∧b. b ∈ T ==> j (i b) = b" "∧b. b ∈ T ==> i b ∈ S" assumes eq: "∧a. a ∈ S ==> h (j a) = g a" shows"F g S = F h T" proof - have"bij_betw j S T" using bij_betw_byWitness[where A=S and f=j and f'=i and A'=T] witness by auto moreoverhave"F g S = F (λx. h (j x)) S" by (intro cong) (auto simp: eq) ultimatelyshow ?thesis by (simp add: reindex_bij_betw) qed
lemma reindex_bij_betw_not_neutral: assumes fin: "finite S'""finite T'" assumes bij: "bij_betw h (S - S') (T - T')" assumes nn: "∧a. a ∈ S' ==> g (h a) = z" "∧b. b ∈ T' ==> g b = z" shows"F (λx. g (h x)) S = F g T" proof - have [simp]: "finite S ⟷ finite T" using bij_betw_finite[OF bij] fin by auto show ?thesis proof (cases "finite S") case True with nn have"F (λx. g (h x)) S = F (λx. g (h x)) (S - S')" by (intro mono_neutral_cong_right) auto alsohave"… = F g (T - T')" using bij by (rule reindex_bij_betw) alsohave"… = F g T" using nn ‹finite S›by (intro mono_neutral_cong_left) auto finallyshow ?thesis . next case False thenshow ?thesis by simp qed qed
lemma reindex_nontrivial: assumes"finite A" and nz: "∧x y. x ∈ A ==> y ∈ A ==> x ≠ y ==> h x = h y ==> g (h x) = 1" shows"F g (h ` A) = F (g ∘ h) A" proof (subst reindex_bij_betw_not_neutral [symmetric]) show"bij_betw h (A - {x ∈ A. (g ∘ h) x = 1}) (h ` A - h ` {x ∈ A. (g ∘ h) x = 1})" using nz by (auto intro!: inj_onI simp: bij_betw_def) qed (use‹finite A›in auto)
lemma reindex_bij_witness_not_neutral: assumes fin: "finite S'""finite T'" assumes witness: "∧a. a ∈ S - S' ==> i (j a) = a" "∧a. a ∈ S - S' ==> j a ∈ T - T'" "∧b. b ∈ T - T' ==> j (i b) = b" "∧b. b ∈ T - T' ==> i b ∈ S - S'" assumes nn: "∧a. a ∈ S' ==> g a = z" "∧b. b ∈ T' ==> h b = z" assumes eq: "∧a. a ∈ S ==> h (j a) = g a" shows"F g S = F h T" proof - have bij: "bij_betw j (S - (S' ∩ S)) (T - (T' ∩ T))" using witness by (intro bij_betw_byWitness[where f'=i]) auto have F_eq: "F g S = F (λx. h (j x)) S" by (intro cong) (auto simp: eq) show ?thesis unfolding F_eq using fin nn eq by (intro reindex_bij_betw_not_neutral[OF _ _ bij]) auto qed
lemma delta_remove: assumes fS: "finite S" shows"F (λk. if k = a then b k else c k) S = (if a ∈ S then b a * F c (S-{a}) else F c (S-{a}))" proof - let ?f = "(λk. if k = a then b k else c k)" show ?thesis proof (cases "a ∈ S") case False thenhave"∀k∈S. ?f k = c k"by simp with False show ?thesis by simp next case True let ?A = "S - {a}" let ?B = "{a}" from True have eq: "S = ?A ∪ ?B"by blast have dj: "?A ∩ ?B = {}"by simp from fS have fAB: "finite ?A""finite ?B"by auto have"F ?f S = F ?f ?A * F ?f ?B" using union_disjoint [OF fAB dj, of ?f, unfolded eq [symmetric]] by simp with True show ?thesis using comm_monoid_set.remove comm_monoid_set_axioms fS by fastforce qed qed
lemma delta [simp]: assumes fS: "finite S" shows"F (λk. if k = a then b k else 1) S = (if a ∈ S then b a else 1)" by (simp add: delta_remove [OF assms])
lemma delta' [simp]: assumes fin: "finite S" shows"F (λk. if a = k then b k else 1) S = (if a ∈ S then b a else 1)" using delta [OF fin, of a b, symmetric] by (auto intro: cong)
lemma If_cases: fixes P :: "'b ==> bool"and g h :: "'b ==> 'a" assumes fin: "finite A" shows"F (λx. if P x then h x else g x) A = F h (A ∩ {x. P x}) * F g (A ∩ - {x. P x})" proof - have a: "A = A ∩ {x. P x} ∪ A ∩ -{x. P x}""(A ∩ {x. P x}) ∩ (A ∩ -{x. P x}) = {}" by blast+ from fin have f: "finite (A ∩ {x. P x})""finite (A ∩ -{x. P x})"by auto let ?g = "λx. if P x then h x else g x" from union_disjoint [OF f a(2), of ?g] a(1) show ?thesis by (subst (12) cong) simp_all qed
lemma cartesian_product: "F (λx. F (g x) B) A = F (case_prod g) (A × B)" proof (cases "A = {} ∨ B = {}") case True thenshow ?thesis by auto next case False thenhave"A ≠ {}""B ≠ {}"by auto show ?thesis proof (cases "finite A ∧ finite B") case True thenshow ?thesis by (simp add: Sigma) next case False then consider "infinite A" | "infinite B"by auto thenhave"infinite (A × B)" by cases (use‹A ≠ {}›‹B ≠ {}›in‹auto dest: finite_cartesian_productD1 finite_cartesian_productD2›) thenshow ?thesis using False by auto qed qed
lemma cartesian_product': "F g (A × B) = F (λx. F (λy. g (x,y)) B) A" unfolding cartesian_product by simp
lemma inter_restrict: assumes"finite A" shows"F g (A ∩ B) = F (λx. if x ∈ B then g x else 1) A" proof - let ?g = "λx. if x ∈ A ∩ B then g x else 1" have"∀i∈A - A ∩ B. (if i ∈ A ∩ B then g i else 1) = 1"by simp moreoverhave"A ∩ B ⊆ A"by blast ultimatelyhave"F ?g (A ∩ B) = F ?g A" using‹finite A›by (intro mono_neutral_left) auto thenshow ?thesis by simp qed
lemma inter_filter: "finite A ==> F g {x ∈ A. P x} = F (λx. if P x then g x else 1) A" by (simp add: inter_restrict [symmetric, of A "{x. P x}" g, simplified mem_Collect_eq] Int_def)
lemma Union_comp: assumes"∀A ∈ B. finite A" and"∧A1 A2 x. A1 ∈ B ==> A2 ∈ B ==> A1 ≠ A2 ==> x ∈ A1 ==> x ∈ A2 ==> g x = 1" shows"F g (∪B) = (F ∘ F) g B" using assms proof (induct B rule: infinite_finite_induct) case (infinite A) thenhave"¬ finite (∪A)"by (blast dest: finite_UnionD) with infinite show ?caseby simp next case empty thenshow ?caseby simp next case (insert A B) thenhave"finite A""finite B""finite (∪B)""A ∉ B" and"∀x∈A ∩∪B. g x = 1" and H: "F g (∪B) = (F ∘ F) g B"by auto thenhave"F g (A ∪∪B) = F g A * F g (∪B)" by (simp add: union_inter_neutral) with‹finite B›‹A ∉ B›show ?case by (simp add: H) qed
lemma swap: "F (λi. F (g i) B) A = F (λj. F (λi. g i j) A) B" unfolding cartesian_product by (rule reindex_bij_witness [where i = "λ(i, j). (j, i)"and j = "λ(i, j). (j, i)"]) auto
lemma swap_restrict: "finite A ==> finite B ==> F (λx. F (g x) {y. y ∈ B ∧ R x y}) A = F (λy. F (λx. g x y) {x. x ∈ A ∧ R x y}) B" by (simp add: inter_filter) (rule swap)
lemma image_gen: assumes fin: "finite S" shows"F h S = F (λy. F h {x. x ∈ S ∧ g x = y}) (g ` S)" proof - have"{y. y∈ g`S ∧ g x = y} = {g x}"if"x ∈ S"for x using that by auto thenhave"F h S = F (λx. F (λy. h x) {y. y∈ g`S ∧ g x = y}) S" by simp alsohave"… = F (λy. F h {x. x ∈ S ∧ g x = y}) (g ` S)" by (rule swap_restrict [OF fin finite_imageI [OF fin]]) finallyshow ?thesis . qed
lemma group: assumes fS: "finite S"and fT: "finite T"and fST: "g ` S ⊆ T" shows"F (λy. F h {x. x ∈ S ∧ g x = y}) T = F h S" unfolding image_gen[OF fS, of h g] by (auto intro: neutral mono_neutral_right[OF fT fST])
lemma Plus: fixes A :: "'b set"and B :: "'c set" assumes fin: "finite A""finite B" shows"F g (A <+> B) = F (g ∘ Inl) A * F (g ∘ Inr) B" proof - have"A <+> B = Inl ` A ∪ Inr ` B"by auto moreoverfrom fin have"finite (Inl ` A)""finite (Inr ` B)"by auto moreoverhave"Inl ` A ∩ Inr ` B = {}"by auto moreoverhave"inj_on Inl A""inj_on Inr B"by (auto intro: inj_onI) ultimatelyshow ?thesis using fin by (simp add: union_disjoint reindex) qed
lemma same_carrier: assumes"finite C" assumes subset: "A ⊆ C""B ⊆ C" assumes trivial: "∧a. a ∈ C - A ==> g a = 1""∧b. b ∈ C - B ==> h b = 1" shows"F g A = F h B ⟷ F g C = F h C" proof - have"finite A"and"finite B"and"finite (C - A)"and"finite (C - B)" using‹finite C› subset by (auto elim: finite_subset) from subset have [simp]: "A - (C - A) = A"by auto from subset have [simp]: "B - (C - B) = B"by auto from subset have"C = A ∪ (C - A)"by auto thenhave"F g C = F g (A ∪ (C - A))"by simp alsohave"… = F g (A - (C - A)) * F g (C - A - A) * F g (A ∩ (C - A))" using‹finite A›‹finite (C - A)›by (simp only: union_diff2) finallyhave *: "F g C = F g A"using trivial by simp from subset have"C = B ∪ (C - B)"by auto thenhave"F h C = F h (B ∪ (C - B))"by simp alsohave"… = F h (B - (C - B)) * F h (C - B - B) * F h (B ∩ (C - B))" using‹finite B›‹finite (C - B)›by (simp only: union_diff2) finallyhave"F h C = F h B" using trivial by simp with * show ?thesis by simp qed
lemma same_carrierI: assumes"finite C" assumes subset: "A ⊆ C""B ⊆ C" assumes trivial: "∧a. a ∈ C - A ==> g a = 1""∧b. b ∈ C - B ==> h b = 1" assumes"F g C = F h C" shows"F g A = F h B" using assms same_carrier [of C A B] by simp
lemma eq_general: assumes B: "∧y. y ∈ B ==>∃!x. x ∈ A ∧ h x = y"and A: "∧x. x ∈ A ==> h x ∈ B ∧ γ(h x) = φ x" shows"F φ A = F γ B" proof - have eq: "B = h ` A" by (auto dest: assms) have h: "inj_on h A" using assms by (blast intro: inj_onI) have"F φ A = F (γ ∘ h) A" using A by auto alsohave"… = F γ B" by (simp add: eq reindex h) finallyshow ?thesis . qed
lemma eq_general_inverses: assumes B: "∧y. y ∈ B ==> k y ∈ A ∧ h(k y) = y"and A: "∧x. x ∈ A ==> h x ∈ B ∧ k(h x) = x ∧ γ(h x) = φ x" shows"F φ A = F γ B" by (rule eq_general [where h=h]) (force intro: dest: A B)+
subsubsection‹HOL Light variant: sum/product indexed by the non-neutral subset› text‹NB only a subset of the properties above are proved›
definition G :: "['b ==> 'a,'b set] ==> 'a" where"G p I ≡ if finite {x ∈ I. p x ≠1} then F p {x ∈ I. p x ≠1} else 1"
lemma finite_Collect_op: shows"[finite {i ∈ I. x i ≠1}; finite {i ∈ I. y i ≠1}]==> finite {i ∈ I. x i * y i ≠1}" apply (rule finite_subset [where B = "{i ∈ I. x i ≠1} ∪ {i ∈ I. y i ≠1}"]) using left_neutral by force+
lemma empty' [simp]: "G p {} = 1" by (auto simp: G_def)
lemma eq_sum [simp]: "finite I ==> G p I = F p I" by (auto simp: G_def intro: mono_neutral_cong_left)
lemma insert' [simp]: assumes"finite {x ∈ I. p x ≠1}" shows"G p (insert i I) = (if i ∈ I then G p I else p i * G p I)" proof - have"{x. x = i ∧ p x ≠1∨ x ∈ I ∧ p x ≠1} = (if p i = 1 then {x ∈ I. p x ≠1} else insert i {x ∈ I. p x ≠1})" by auto thenshow ?thesis using assms by (simp add: G_def conj_disj_distribR insert_absorb) qed
lemma distrib_triv': assumes"finite I" shows"G (λi. g i * h i) I = G g I * G h I" by (simp add: assms local.distrib)
lemma non_neutral': "G g {x ∈ I. g x ≠1} = G g I" by (simp add: G_def)
lemma distrib': assumes"finite {x ∈ I. g x ≠1}""finite {x ∈ I. h x ≠1}" shows"G (λi. g i * h i) I = G g I * G h I" proof - have"a * a ≠ a ==> a ≠1"for a by auto thenhave"G (λi. g i * h i) I = G (λi. g i * h i) ({i ∈ I. g i ≠1} ∪ {i ∈ I. h i ≠1})" using assms by (force simp: G_def finite_Collect_op intro!: mono_neutral_cong) alsohave"… = G g I * G h I" proof - have"F g ({i ∈ I. g i ≠ - h (i \in> {i ∈bol by (auto simp: G_def assms intro: mono_neutral_right) then show ?thesis using assms by (simp add: distrib) qed finally show ?thesis . qed
lemma cong': assumes "A = B" assumes g_h: "∧x. x ∈ B ==> g x = h x" shows "G g A = G h B" using assms by (auto simp: G_def cong: conj_cong intro: cong)
lemma mono_neutral_cong_left': assumes "S ⊆ T" and "∧i. i ∈ T - S ==> h i = 1" and "∧x. x ∈ S ==> g x = h x" shows "G g S = G h T" proof - have *: "{x ∈ S. g x ≠1} = {x ∈ T. h x ≠1}" using assms by (metis DiffI subset_eq) then have "finite {x ∈ S. g x ≠1} = finite {x ∈ T. h x ≠1}" by simp then show ?thesis using assms by (auto simp add: G_def * intro: cong) qed
lemma mono_neutral_cong_right': "S ⊆ T ==>∀i ∈ T - S. g i = 1==> (∧x. x ∈ S ==> g x = h x) ==>
G g T = G h S" by (auto intro!: mono_neutral_cong_left' [symmetric])
lemma mono_neutral_left': "S ⊆ T ==>∀i ∈ T - S. g i = 1==> G g S = G g T" by (blast intro: mono_neutral_cong_left')
lemma mono_neutral_right': "S ⊆ T ==>∀i ∈ T - S. g i = 1==> G g T = G g S" by (blast intro!: mono_neutral_left' [symmetric])
end
subsection ‹Generalized summation over a set›
context comm_monoid_add begin
sublocale sum: comm_monoid_set plus 0 defines sum = sum.F and sum' = sum.G ..
abbreviation Sum (‹∑›) where "∑≡ sum (λx. x)"
end
text ‹Now: lots of fancy syntax. First, term‹sum (λx. e) A› is written ‹
"∑x|P. t" => "CONST sum (λx. t) {x. P}" ‹
[(🍋‹sum›, K (Collect_binder_tr' 🍋‹_qsum›))] ›
‹Properties in more restricted classes of structures›
sum_Un:
"finite A ==> finite B ==> sum f (A ∪ B) = sum f A + sum f B - sum f (A ∩ B)"
for f :: "'b ==> 'a::ab_group_add"
by (subst sum.union_inter [symmetric]) (auto simp add: algebra_simps)
sum_Un2:
assumes "finite (A ∪ B)"
shows "sum f (A ∪ B) = sum f (A - B) + sum f (B - A) + sum f (A ∩ B)"
-
have "A ∪ B = A - B ∪ (B - A) ∪ A ∩ B"
by auto
with assms show ?thesis
by simp (subst sum.union_disjoint, auto)+
(*Like sum.subset_diff but expressed perhaps more conveniently using subtraction*) lemma sum_diff: fixes f :: "'b ==> 'a::ab_group_add" assumes"finite A""B ⊆ A" shows"sum f (A - B) = sum f A - sum f B" using sum.subset_diff [of B A f] assms by simp
lemma sum_diff1: fixes f :: "'b ==> 'a::ab_group_add" assumes"finite A" shows"sum f (A - {a}) = (if a ∈ A then sum f A - f a else sum f A)" using assms by (simp add: sum_diff)
lemma sum_diff1'_aux: fixes f :: "'a ==> 'b::ab_group_add" assumes"finite F""{i ∈ I. f i ≠ 0} ⊆ F" shows"sum' f (I - {i}) = (if i ∈ I then sum' f I - f i else sum' f I)" using assms proof induct case (insert x F) have1: "finite {x ∈ I. f x ≠ 0} ==> finite {x ∈ I. x ≠ i ∧ f x ≠ 0}" by (erule rev_finite_subset) auto have2: "finite {x ∈ I. x ≠ i ∧ f x ≠ 0} ==> finite {x ∈ I. f x ≠ 0}" apply (drule finite_insert [THEN iffD2]) by (erule rev_finite_subset) auto have3: "finite {i ∈ I. f i ≠ 0}" using finite_subset insert by blast show ?case using insert sum_diff1 [of "{i ∈ I. f i ≠ 0}" f i] by (auto simp: sum.G_def 123 set_diff_eq conj_ac) qed (simp add: sum.G_def)
lemma sum_diff1': fixes f :: "'a ==> " { <n shows"sum' f (I - {i}) = (if i ∈ I then sum' f I - f i else sum' f I)" by (rule sum_diff1'_aux [OF assms order_refl])
lemma (in ordered_comm_monoid_add) sum_mono: "(∧i. i∈K ==> f i ≤ g i) ==> (∑i∈K. f i) ≤ (∑i∈K. g i)" by (induct K rule: infinite_finite_induct) (use add_mono in auto)
lemma (in ordered_cancel_comm_monoid_add) sum_strict_mono_strong: assumes"finite A""a ∈ A""f a < g a" and"∧x. x ∈ A ==> f x ≤ g x" shows"sum f A < sum g A" proof - have"sum f A = f a + sum f (A-{a})" by (simp add: assms sum.remove) alsohave"…≤ f a + sum g (A-{a})" using assms by (meson DiffD1 add_left_mono sum_mono) alsohave"… < g a + sum g (A-{a})" using assms add_less_le_mono by blast alsohave"… = sum g A" using assms by (intro sum.remove [symmetric]) finallyshow ?thesis . qed
lemma (in strict_ordered_comm_monoid_add) sum_strict_mono: assumes"finite A""A ≠ {}" and"∧x. x ∈ A ==> f x < g x" shows"sum f A < sum g A" using assms proof (induct rule: finite_ne_induct) case singleton thenshow ?caseby simp next case insert thenshow ?caseby (auto simp: add_strict_mono) qed
lemma sum_strict_mono_ex1: fixes f g :: "'i ==> 'a::ordered_cancel_comm_monoid_add" assumes"finite A" and"∀x∈A. f x ≤ g x" and"∃a∈A. f a < g a" shows"sum f A < sum g A" proof- from assms(3) obtain a where a: "a ∈ A""f a < g a"by blast have"sum f A = sum f ((A - {a}) ∪ {a})" by(simp add: insert_absorb[OF ‹a ∈ A›]) alsohave"… = sum f (A - {a}) + sum f {a}" using‹finite A›by(subst sum.union_disjoint) auto alsohave"sum f (A - {a}) ≤ sum g (A - {a})" by (rule sum_mono) (simp add: assms(2)) alsofrom a have"sum f {a} < sum g {a}"by simp alsohave"sum g (A - {a}) + sum g {a} = sum g((A - {a}) ∪ {a})" using‹finite A›by (subst sum.union_disjoint[symmetric]) auto alsohave"… = sum g A"by (simp add: insert_absorb[OF ‹a ∈ A›]) finallyshow ?thesis by (auto simp add: add_right_mono add_strict_left_mono) qed
lemma sum_mono_inv: fixes f g :: "'i ==> 'a :: ordered_cancel_comm_monoid_add" assumes eq: "sum f I = sum g I" assumes le: "∧i. i ∈ I ==> f i ≤ g i" assumes i: "i ∈ I" assumes I: "finite I" shows"f i = g i" proof (rule ccontr) assume"¬ ?thesis" with le[OF i] have"f i < g i"by simp with i have"∃i∈I. f i < g i" .. from sum_strict_mono_ex1[OF I _ this] le have"sum f I < sum g I" by blast with eq show False by simp qed
lemma member_le_sum: fixes f :: "_ ==> 'b::{semiring_1, ordered_comm_monoid_add}" assumes"i ∈ A" and le: "∧x. x ∈ A - {i} ==> 0 ≤ f x" and"finite A" shows"f i ≤ sum f A" proof - have"f i ≤ sum f (A ∩ {i})" by (simp add: assms) alsohave"... = (∑x∈A. if x ∈ {i} then f x else 0)" using assms sum.inter_restrict by blast alsohave"... ≤ sum f A" apply (rule sum_mono) apply (auto simp: le) done finallyshow ?thesis . qed
lemma sum_negf: "(∑x∈A. - f x) = - (∑x∈A. f x)" for f :: "'b ==> 'a::ab_group_add" by (induct A rule: infinite_finite_induct) auto
lemma sum_subtractf: "(∑x∈A. f x - g x) = (∑x∈A. f x) - (∑x∈A. g x)" for f g :: "'b ==>'a::ab_group_add" using sum.distrib [of f "- g" A] by (simp add: sum_negf)
lemma sum_subtractf_nat: "(∧x. x ∈ A ==> g x ≤ f x) ==> (∑x∈A. f x - g x) = (∑x∈A. f x) - (∑x∈A. g x)" for f g :: "'a ==> nat" by (induct A rule: infinite_finite_induct) (auto simp: sum_mono)
context ordered_comm_monoid_add begin
lemma sum_nonneg: "(∧x. x ∈ A ==> 0 ≤ f x) ==> 0 ≤ sum f A" proof (induct A rule: infinite_finite_induct) case infinite thenshow ?caseby simp next case empty thenshow ?caseby simp next case (insert x F) thenhave"0 + 0 ≤ f x + sum f F"by (blast intro: add_mono) with insert show ?caseby simp qed
lemma sum_nonpos: "(∧x. x ∈ A ==> f x ≤ 0) ==> sum f A ≤ 0" proof (induct A rule: infinite_finite_induct) case infinite thenshow ?caseby simp next case empty thenshow ?caseby simp next case (insert x F) thenhave"f x + sum f F ≤ 0 + 0"by (blast intro: add_mono) with insert show ?caseby simp qed
lemma sum_nonneg_eq_0_iff: "finite A ==> (∧x. x ∈ A ==> 0 ≤ f x) ==> sum f A = 0 ⟷ (∀x∈A. f x = 0)" by (induct set: finite) (simp_all add: add_nonneg_eq_0_iff sum_nonneg)
lemma sum_nonneg_0: "finite s ==> (∧i. i ∈ s ==> f i ≥ 0) ==> (∑ i ∈ s. f i) = 0 ==> i ∈ s ==> f i = 0" by (simp add: sum_nonneg_eq_0_iff)
lemma sum_nonneg_leq_bound: assumes"finite s""∧i. i ∈ s ==> f i ≥ 0""(∑i ∈ s. f i) = B""i ∈ s" shows"f i ≤ B" proof - from assms have"f i ≤ f i + (∑i ∈ s - {i}. f i)" by (intro add_increasing2 sum_nonneg) auto alsohave"… = B" using sum.remove[of s i f] assms by simp finallyshow ?thesis by auto qed
lemma sum_mono2: assumes fin: "finite B" and sub: "A ⊆ B" and nn: "∧b. b ∈ B-A ==> 0 ≤ f b" shows"sum f A ≤ sum f B" proof - have"sum f A ≤ sum f A + sum f (B-A)" by (auto intro: add_increasing2 [OF sum_nonneg] nn) alsofrom fin finite_subset[OF sub fin] have"… = sum f (A ∪ (B-A))" by (simp add: sum.union_disjoint del: Un_Diff_cancel) alsofrom sub have"A ∪ (B-A) = B"by blast finallyshow ?thesis . qed
lemma sum_le_included: assumes"finite s""finite t" and"∀y∈t. 0 ≤ g y""(∀x∈s. ∃y∈t. i y = x ∧ f x ≤ g y)" shows"sum f s ≤ sum g t" proof - have"sum f s ≤ sum (λy. sum g {x. x∈t ∧ i x = y}) s" proof (rule sum_mono) fix y assume"y ∈ s" with assms obtain z where z: "z ∈ t""y = i z""f y ≤ g z"by auto with assms show"f y ≤ sum g {x ∈ t. i x = y}" (is"?A y ≤ ?B y") using order_trans[of "?A (i z)""sum g {z}""?B (i z)", intro] by (auto intro!: sum_mono2) qed alsohave"…≤ sum (λy. sum g {x. x∈t ∧ i x = y}) (i ` t)" using assms(2-4) by (auto intro!: sum_mono2 sum_nonneg) alsohave"…≤ sum g t" using assms by (auto simp: sum.image_gen[symmetric]) finallyshow ?thesis . qed
end
lemma (in canonically_ordered_monoid_add) sum_eq_0_iff [simp]: "finite F ==> (sum f F = 0) = (∀a∈F. f a = 0)" by (intro ballI sum_nonneg_eq_0_iff zero_le)
context semiring_0 begin
lemma sum_distrib_left: "r * sum f A = (∑n∈A. r * f n)" by (induct A rule: infinite_finite_induct) (simp_all add: algebra_simps)
lemma sum_distrib_right: "sum f A * r = (∑n∈A. f n * r)" by (induct A rule: infinite_finite_induct) (simp_all add: algebra_simps)
end
lemma sum_divide_distrib: "sum f A / r = (∑n∈A. f n / r)" for r :: "'a::field" proof (induct A rule: infinite_finite_induct) case infinite thenshow ?caseby simp next case empty thenshow ?caseby simp next case insert thenshow ?caseby (simp add: add_divide_distrib) qed
lemma sum_abs[iff]: "∣sum f A∣≤ sum (λi. ∣f i∣) A" for f :: "'a ==> 'b::ordered_ab_group_add_abs" proof (induct A rule: infinite_finite_induct) case infinite thenshow ?caseby simp next case empty thenshow ?caseby simp next case insert thenshow ?caseby (auto intro: abs_triangle_ineq order_trans) qed
lemma sum_abs_ge_zero[iff]: "0 ≤ sum (λi. ∣f i∣) A" for f :: "'a ==> 'b::ordered_ab_group_add_abs" by (simp add: sum_nonneg)
lemma abs_sum_abs[simp]: "∣∑a∈A. ∣f a∣∣ = (∑a∈A. ∣f a∣)" for f :: "'a ==> 'b::ordered_ab_group_add_abs" proof (induct A rule: infinite_finite_induct) case infinite thenshow ?caseby simp next case empty thenshow ?caseby simp next case (insert a A) thenhave"∣∑a∈insert a A. ∣f a∣∣ = ∣∣f a∣ + (∑a∈A. ∣f a∣)∣"by simp alsofrom insert have"… = ∣∣f a∣ + ∣∑a∈A. ∣f a∣∣∣"by simp alsohave"… = ∣f a∣ + ∣∑a∈A. ∣f a∣∣"by (simp del: abs_of_nonneg) alsofrom insert have"… = (∑a∈insert a A. ∣f a∣)"by simp finallyshow ?case . qed
lemma sum_product: fixes f :: "'a ==> 'b::semiring_0" shows"sum f A * sum g B = (∑i∈A. ∑j∈B. f i * g j)" by (simp add: sum_distrib_left sum_distrib_right) (rule sum.swap)
lemma sum_mult_sum_if_inj: fixes f :: "'a ==> 'b::semiring_0" shows"inj_on (λ(a, b). f a * g b) (A × B) ==> sum f A * sum g B = sum id {f a * g b |a b. a ∈ A ∧ b ∈ B}" by(auto simp: sum_product sum.cartesian_product intro!: sum.reindex_cong[symmetric])
lemma sum_SucD: "sum f A = Suc n ==>∃a∈A. 0 < f a" by (induct A rule: infinite_finite_induct) auto
lemma sum_eq_Suc0_iff: "finite A ==> sum f A = Suc 0 ⟷ (∃a∈A. f a = Suc 0 ∧ (∀b∈A. a ≠ b ⟶ f b = 0))" by (induct A rule: finite_induct) (auto simp add: add_is_1)
lemma sum_Un_nat: "finite A ==> finite B ==> sum f (A ∪ B) = sum f A + sum f B - sum f (A ∩ B)" for f :: "'a ==> nat"
― ‹For the natural numbers, we have subtraction.› by (subst sum.union_inter [symmetric]) (auto simp: algebra_simps)
lemma sum_diff1_nat: "sum f (A - {a}) = (if a ∈ A then sum f A - f a else sum f A)" for f :: "'a ==> nat" proof (induct A rule: infinite_finite_induct) case infinite thenshow ?caseby simp next case empty thenshow ?caseby simp next case (insert x F) thenshow ?case proof (cases "a ∈ F") case True thenhave"∃B. F = insert a B ∧ a ∉ B" by (auto simp: mk_disjoint_insert) thenshow ?thesis using insert by (auto simp: insert_Diff_if) qed (auto) qed
lemma sum_diff_nat: fixes f :: "'a ==> nat" assumes"finite B"and"B ⊆ A" shows"sum f (A - B) = sum f A - sum f B" using assms proof induct case empty thenshow ?caseby simp next case (insert x F) note IH = ‹F ⊆ A ==> sum f (A - F) = sum f A - sum f F› from‹x ∉ F›‹insert x F ⊆ A›have"x ∈ A - F"by simp thenhave A: "sum f ((A - F) - {x}) = sum f (A - F) - f x" by (simp add: sum_diff1_nat) from‹insert x F ⊆ A›have"F ⊆ A"by simp with IH have"sum f (A - F) = sum f A - sum f F"by simp with A have B: "sum f ((A - F) - {x}) = sum f A - sum f F - f x" by simp from‹x ∉ F›have"A - insert x F = (A - F) - {x}"by auto with B have C: "sum f (A - insert x F) = sum f A - sum f F - f x" by simp from‹finite F›‹x ∉ F›have"sum f (insert x F) = sum f F + f x" by simp with C have"sum f (A - insert x F) = sum f A - sum f (insert x F)" by simp thenshow ?caseby simp qed
lemma sum_comp_morphism: "h 0 = 0 ==> (∧x y. h (x + y) = h x + h y) ==> sum (h ∘ g) A = h (sum g A)" by (induct A rule: infinite_finite_induct) simp_all
lemma (in comm_semiring_1) dvd_sum: "(∧a. a ∈ A ==> d dvd f a) ==> d dvd sum f A" by (induct A rule: infinite_finite_induct) simp_all
lemma (in ordered_comm_monoid_add) sum_pos: "finite I ==> I ≠ {} ==> (∧i. i ∈ I ==> 0 < f i) ==> 0 < sum f I" by (induct I rule: finite_ne_induct) (auto intro: add_pos_pos)
lemma (in ordered_comm_monoid_add) sum_pos2: assumes I: "finite I""i ∈ I""0 < f i""∧i. i ∈ I ==> 0 ≤ f i" shows"0 < sum f I" proof - have"0 < f i + sum f (I - {i})" using assms by (intro add_pos_nonneg sum_nonneg) auto alsohave"… = sum f I" using assms by (simp add: sum.remove) finallyshow ?thesis . qed
lemma sum_strict_mono2: fixes f :: "'a ==> 'b::ordered_cancel_comm_monoid_add" assumes"finite B""A ⊆ B""b ∈ B-A""f b > 0"and"∧x. x ∈ B ==> f x ≥ 0" shows"sum f A < sum f B" proof - have"B - A ≠ {}" using assms(3) by blast have"sum f (B-A) > 0" by (rule sum_pos2) (use assms in auto) moreoverhave"sum f B = sum f (B-A) + sum f A" by (rule sum.subset_diff) (use assms in auto) ultimatelyshow ?thesis using add_strict_increasing by auto qed
lemma sum_cong_Suc: assumes"0 ∉ A""∧x. Suc x ∈ A ==> f (Suc x) = g (Suc x)" shows"sum f A = sum g A" proof (rule sum.cong) fix x assume"x ∈ A" with assms(1) show"f x = g x" by (cases x) (auto intro!: assms(2)) qed simp_all
subsubsection‹Cardinality as special case of const‹sum››
lemma card_eq_sum: "card A = sum (λx. 1) A" proof - have"plus ∘ (λ_. Suc 0) = (λ_. Suc)" by (simp add: fun_eq_iff) thenhave"Finite_Set.fold (plus ∘ (λ_. Suc 0)) = Finite_Set.fold (λ_. Suc)" by (rule arg_cong) thenhave"Finite_Set.fold (plus ∘ (λ_. Suc 0)) 0 A = Finite_Set.fold (λ_. Suc) 0 A" by (blast intro: fun_cong) thenshow ?thesis by (simp add: card.eq_fold sum.eq_fold) qed
context semiring_1 begin
lemma sum_constant [simp]: "(∑x ∈ A. y) = of_nat (card A) * y" by (induct A rule: infinite_finite_induct) (simp_all add: algebra_simps)
context fixes A assumes‹finite A› begin
lemma sum_of_bool_eq [simp]: ‹(∑x ∈ A. of_bool (P x)) = of_nat (card (A ∩ {x. P x}))›if‹finite A› using‹finite A›byinduction simp_all
lemma sum_mult_of_bool_eq [simp]: ‹(∑x ∈ A. f x * of_bool (P x)) = (∑x ∈ (A ∩ {x. P x}). f x)› by (rule sum.mono_neutral_cong) (use‹finite A›in auto)
lemma sum_of_bool_mult_eq [simp]: ‹(∑x ∈ A. of_bool (P x) * f x) = (∑x ∈ (A ∩ {x. P x}). f x)› by (rule sum.mono_neutral_cong) (use‹finite A›in auto)
end
end
lemma sum_Suc: "sum (λx. Suc(f x)) A = sum f A + card A" using sum.distrib[of f "λ_. 1" A] by simp
lemma sum_bounded_above: fixes K :: "'a::{semiring_1,ordered_comm_monoid_add}" assumes le: "∧i. i∈A ==> f i ≤ K" shows"sum f A ≤ of_nat (card A) * K" proof (cases "finite A") case True thenshow ?thesis using le sum_mono[where K=A and g = "λx. K"] by simp next case False thenshow ?thesis by simp qed
lemma sum_bounded_above_divide: fixes K :: "'a::linordered_field" assumes le: "∧i. i∈A ==> f i ≤ K / of_nat (card A)"and fin: "finite A""A ≠ {}" shows"sum f A ≤ K" using sum_bounded_above [of A f "K / of_nat (card A)", OF le] fin by simp
lemma sum_bounded_above_strict: fixes K :: "'a::{ordered_cancel_comm_monoid_add,semiring_1}" assumes"∧i. i∈A ==> f i < K""card A > 0" shows"sum f A < of_nat (card A) * K" using assms sum_strict_mono[where A=A and g = "λx. K"] by (simp add: card_gt_0_iff)
lemma sum_bounded_below: fixes K :: "'a::{semiring_1,ordered_comm_monoid_add}" assumes le: "∧i. i∈A ==> K ≤ f i" shows"of_nat (card A) * K ≤ sum f A" proof (cases "finite A") case True thenshow ?thesis using le sum_mono[where K=A and f = "λx. K"] by simp next case False thenshow ?thesis by simp qed
lemma convex_sum_bound_le: fixes x :: "'a ==> 'b::linordered_idom" assumes0: "∧i. i ∈ I ==> 0 ≤ x i"and1: "sum x I = 1" and δ: "∧i. i ∈ I ==>∣a i - b∣≤ δ" shows"∣(∑i∈I. a i * x i) - b∣≤ δ" proof - have [simp]: "(∑i∈I. c * x i) = c"for c by (simp flip: sum_distrib_left 1) thenhave"∣(∑i∈I. a i * x i) - b∣ = ∣∑i∈I. (a i - b) * x i∣" by (simp add: sum_subtractf left_diff_distrib) alsohave"…≤ (∑i∈I. ∣(a i - b) * x i∣)" using abs_abs abs_of_nonneg by blast alsohave"…≤ (∑i∈I. ∣(a i - b)∣ * x i)" by (simp add: abs_mult 0) alsohave"…≤ (∑i∈I. δ * x i)" by (rule sum_mono) (use δ "0" mult_right_mono in blast) alsohave"… = δ" by simp finallyshow ?thesis . qed
lemma card_UN_disjoint: assumes"finite I"and"∀i∈I. finite (A i)" and"∀i∈I. ∀j∈I. i ≠ j ⟶ A i ∩ A j = {}" shows"card (∪(A ` I)) = (∑i∈I. card(A i))" proof - have"(∑i∈I. card (A i)) = (∑i∈I. ∑x∈A i. 1)" by simp with assms show ?thesis by (simp add: card_eq_sum sum.UNION_disjoint del: sum_constant) qed
lemma card_Union_disjoint: assumes"pairwise disjnt C"and fin: "∧A. A ∈ C ==> finite A" shows"card (∪C) = sum card C" proof (cases "finite C") case True thenshow ?thesis using card_UN_disjoint [OF True, of "λx. x"] assms by (simp add: disjnt_def fin pairwise_def) next case False thenshow ?thesis using assms card_eq_0_iff finite_UnionD by fastforce qed
lemma card_Union_le_sum_card_weak: fixes U :: "'a set set" assumes"∀u ∈ U. finite u" shows"card (∪U) ≤ sum card U" proof (cases "finite U") case False thenshow"card (∪U) ≤ sum card U" using card_eq_0_iff finite_UnionD by auto next case True thenshow"card (∪U) ≤ sum card U" proof (induct U rule: finite_induct) case empty thenshow ?caseby auto next case (insert x F) thenhave"card(∪(insert x F)) ≤ card(x) + card (∪F)"using card_Un_le by auto alsohave"... ≤ card(x) + sum card F"using insert.hyps by auto alsohave"... = sum card (insert x F)"using sum.insert_if and insert.hyps by auto finallyshow ?case . qed qed
lemma card_Union_le_sum_card: fixes U :: "'a set set" shows"card (∪U) ≤ sum card U" by (metis Union_upper card.infinite card_Union_le_sum_card_weak finite_subset zero_le)
lemma card_UN_le: assumes"finite I" shows"card(∪i∈I. A i) ≤ (∑i∈I. card(A i))" using assms proofinduction case (insert i I) thenshow ?case using card_Un_le nat_add_left_cancel_le by (force intro: order_trans) qed auto
lemma card_quotient_disjoint: assumes"finite A""inj_on (λx. {x} // r) A" shows"card (A//r) = card A" proof - have"∀i∈A. ∀j∈A. i ≠ j ⟶ r `` {j} ≠ r `` {i}" using assms by (fastforce simp add: quotient_def inj_on_def) with assms show ?thesis by (simp add: quotient_def card_UN_disjoint) qed
lemma sum_multicount_gen: assumes"finite s""finite t""∀j∈t. (card {i∈s. R i j} = k j)" shows"sum (λi. (card {j∈t. R i j})) s = sum k t"
(is"?l = ?r") proof- have"?l = sum (λi. sum (λx.1) {j∈t. R i j}) s" by auto alsohave"… = ?r" unfolding sum.swap_restrict [OF assms(1-2)] using assms(3) by auto finallyshow ?thesis . qed
lemma sum_multicount: assumes"finite S""finite T""∀j∈T. (card {i∈S. R i j} = k)" shows"sum (λi. card {j∈T. R i j}) S = k * card T" (is"?l = ?r") proof- have"?l = sum (λi. k) T" by (rule sum_multicount_gen) (auto simp: assms) alsohave"… = ?r"by (simp add: mult.commute) finallyshow ?thesis by auto qed
lemma sum_card_image: assumes"finite A" assumes"pairwise (λs t. disjnt (f s) (f t)) A" shows"sum card (f ` A) = sum (λa. card (f a)) A" using assms proof (induct A) case (insert a A) show ?case proof cases assume"f a = {}" with insert show ?case by (subst sum.mono_neutral_right[where S="f ` A"]) (auto simp: pairwise_insert) next assume"f a ≠ {}" thenhave"sum card (insert (f a) (f ` A)) = card (f a) + sum card (f ` A)" using insert by (subst sum.insert) (auto simp: pairwise_insert) with insert show ?caseby (simp add: pairwise_insert) qed qed simp
text‹By Jakub Kądziołka:›
lemma sum_fun_comp: assumes"finite S""finite R""g ` S ⊆ R" shows"(∑x ∈ S. f (g x)) = (∑y ∈ R. of_nat (card {x ∈ S. g x = y}) * f y)" proof - let ?r = "relation_of (λp q. g p = g q) S" have eqv: "equiv S ?r" unfolding relation_of_def by (auto intro: comp_equivI) have finite: "C ∈ S//?r ==> finite C"for C by (fact finite_equiv_class[OF `finite S` equiv_type[OF `equiv S ?r`]]) have disjoint: "A ∈ S//?r ==> B ∈ S//?r ==> A ≠ B ==> A ∩ B = {}"for A B using eqv quotient_disj by blast
let ?cls = "λy. {x ∈ S. y = g x}" have quot_as_img: "S//?r = ?cls ` g ` S" by (auto simp add: relation_of_def quotient_def) have cls_inj: "inj_on ?cls (g ` S)" by (auto intro: inj_onI)
have rest_0: "(∑y ∈ R - g ` S. of_nat (card (?cls y)) * f y) = 0" proof - have"of_nat (card (?cls y)) * f y = 0proof - proof - from asm have *: "?cls y = {}" by auto show ?thesis unfolding * by simp qed thus ?thesis by simp qed
have "(∑x ∈ S. f (g x)) = (∑C ∈ S//?r. ∑x ∈byauto using eqv finite disjoint by (simp flip: sum.Union_disjointmoreoverassms"A - B) \<>B also have "".. =(∑ unfolding quot_as_img by (simp add: sum.reindex[OF cls_inj]) also have "... = (∑y ∈ g ` S. ∑x ∈ ?cls y. f y)" by auto also have "... = (∑y ∈ g ` S. of_nat (card (?cls y)) * f y)" by (simp flip: sum_constant) also have "... = (∑y ∈ using"finite A" finallyshow ?thesis by (simp add: eq_commute) qed by(subst whereA -B"]) (auto simp DifDi assms)
subsubsection ‹
lemma card_SigmaI [simp]: " A ==>∀
by (simp add: card_eq_sum sum.Sigma del: sum_constant)
SigmaI_insert: "y ∉ A ==>
(SIGMA x:(insert y A). B x) = (({y} ×
by auto
*)
lemma card_cartesian_product: "card (A × B) = card A * card B"proofinductrule) by (cases "finite A ∧ finite B")
(auto simp add: card_eq_0_iff dest: finite_cartesian_productD1 finite_cartesian_productD2)
lemma by (simp add: card_cartesian_productshowcasebysimp
subsection‹Generalized product over a set›
context comm_monoid_mult begin
sublocale prod: comm_monoid_set times 1 defines prod = prod.F and prod' = prod.G ..
abbreviation Prod (‹
where "∏≡
(ASCII)
" simp add: eq_old fold_ comp_assoc)
"_prod" :: "pttrn => 'a set => 'b => 'b::comm_monoid_mult" (‹(‹indent=2 notation=‹binder ∏›
prod_dvd_prod: "(∧a. a ∈ A ==> f a dvd g a) ==> prod f A dvd prod g A"
(induct A rule: infinite_finite_induct)
case infinite
then show ?case by (auto intro: dvdI)
case empty
then show ?case by (auto intro: dvdI)
case (insert a A)
then have "f a dvd g a" and "prod f A dvd prod g A"
lemma:
then obtain r s where "g a = f a * r" and "prod g A = prod f A * s"
by (auto elim!: dvdE)
then have "g a * prod g A = f a * prod f A * (r * s)"
by (simp add: ac_simps)
with insert.hyps show ?case
by (auto intro: dvdI)
prod_dvd_prod_subset: "finite B ==> A ⊆
by (auto simp add: prod.subset_diff ac_simps intro: dvdI)
‹Properties in more restricted classes of structures›
linordered_nonzero_semiring
prod_ge_1: "(∧x. x ∈> A j = {}
(induct A rule: infinite_finite_induct)
case infinite
then show ?case by simp
case empty
then show ?case by simp
case (insert x F)
have "1 * 1 ≤ f x * prod f F"
by (rule mult_mono') (use insert in auto)
insert show ?case by simp
prod_le_1:
java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 13
assumes "∧x. x ∈ A ==> 0 ≤ f x ∧
shows "prod f A ≤ 1"
using assms
(induct A rule: infinite_finite_induct)
case infinite
then show ?case by simp
case empty
then
(insert x F)
then show ?case by (force simp: mult.commute intro: dest: mult_le_one)
comm_semiring_1
dvd_prod_eqI [intro]:
assumes "finite A" and "a ∈ A" and "b = f a"
"b dvd prod f A"
-
java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "brackoff" is null
by (intro prod.insert) auto
also from ‹a ∈ A› (simp_all add: assoc commute left_commute)
by blast
finally have "prod f A = f a * prod f (A - {a})" .
with ‹
by simp
dvd_prodI [intro]: "finite A ==> a ∈ shows (\lambda( x)) A = F case_prod g) (SIGA x:A. B x)"
by auto
prod_zero:
assumes "finite A" and "∃a∈A. f a = 0"
(subst UNION_disjoint)
using assms
(induct A)
empty
then show ?case by simp
case (insert a A)
"f a = 0 \>\>. f = 0)" by simp
then have "f a * prod f A = 0" by (rule disjE) (simp_all add: insert)
with insert show ?case by simp
prod_dvd_prod_subset2:
assumes "finite B" and "A ⊆ B" and "∧a. a ∈ A ==> f a dvd g a"
shows "prod f A dvd prod g B"
R_h_g: "\forall\in>S. R R (h xh x) ( x)"
from assms have "prod f A dvd prod g A"
by (auto intro: prod_dvd_prod)
assms have "prod g A dd prod g B"
by (auto intro: prod_dvd_prod_subset)
show ?thesis by (rulerule dvd_trans)
"S \subseteq> T"
fixes f :: "'b ==> 'a"
assumes "finite A"
shows "prod f A = 0 ⟷ (∃a∈A. f a = 0)"
using assms by (induct A) (auto simp: no_zero_divisors)
(in semidom_divide) prod_diff1:
java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 23
shows "prod f (A - {a}) = (if a ∈ A then prod f A div f a else prod f A)"
(cases "a ∉ A")
case True
then show ?thesis by simp
java.lang.StringIndexOutOfBoundsException: Range [6, 2) out of bounds for length 12
with assms show ?thesis
proof induct
then show ?case by simp
next
case (insert b B)
then show ?case
proof (cases "a = b")
case True
with inser "finite T 🚫
next
case False
with insert have "a ∈ B" by simp
define C where "C = B - {a}"
with ‹finite B›‹a \ F g T = F h S"
by auto
with insert show ?thesis
by (auto simp add: insert_commute ac_simps)
qed
ed
mono_neutral_right: "finite T ==> S ⊆ T ==>blast intro!: mono_neutral_ [symmetric])
by (induction A rule: infinite_finite_induct) (auto simp: algebra_simps)
prod_diff:
fixes f :: "'a ==> 'b :: field"
finite A" "B \>"\Andx. x n\noteq> 0"
shows "prod f (A - B) = prod f A / prod f B"
by (metis assms finite_subset nonzero_eq_divide_eq prod.subset_diff
prod_zero_iff)
sum_zero_power [simp]: "(∑i∈A. c i * 0^i) = (if finite A ∧ 0 ∈ A then c 0 else 0)"
for c :: c :: "nat ==>a::division_ring"
by (induct A rule: infinite_finite_induct) auto
java.lang.StringIndexOutOfBoundsException: Range [12, 5) out of bounds for length 29
"(∑i∈by(rule mono_neutral_right)(auto intro: *)
c :: "nat ==>::ield"
using sum_zero_power [of "λi. c i / d i" A] by auto
(in field) prod_inversef: "prod (inverse ∘"
(cases "finite A")
case True
then show ?thesis
(induct A rule: finite_induct) si) simp_all
next
case False
then show ?thesis
by auto
qed
(in field) prod_dividef: "(∏:
using prod_inversef [of g A] by (simp add: divide_inverse prod.distrib)
prod_Un:
fixes f :: "'b ==> 'a :: field"
an "finite B"
and "\<>>A 0"
shows "prod f (A ∪
-
from assms have "prod f A * prod f B = prod f (A ∪ B) * prod f (A ∩ B)"
have "bij_betw j S j S T"
with assms show ?thesis
moreover hahave "F g S = F (\lambda h (j (j x) S"
prod_pos: "(\< ssumes> S' ==>
by (induct A rule: infinite_finite_induct) simp_all
prod_mono:
"(∧
have [simp: "finite S ⟷ finite T"
java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "brackoff" is null
prod_mono_strict:
also have "<>
assumes "finite A"
assumes "∧i. i ∈
assumes "∧
shows "prod f A < prod
-
have "prod f A = f i * prod f (A - {i})"
using assms by (intro prod.remove)
"\d≤ f i * prod g (A - {i})"
using assms by (intro mult_left_mono prod_mono) auto
also have "… < g i * prod g (A - {i})"
using assms by (intro mult_strict_right_mono prod_pos) auto
also have "… = prod g A"
using assms by (intro prod.remove [symmetric])
finally show ?thesis .
java.lang.StringIndexOutOfBoundsException: Range [8, 5) out of bounds for length 20
assumes A: "∧
shows "prod f A ≤ n ^ k"
using A
(induction A arbitrary: k rule: infinite_finite_induct)
case (insert i A)
then obtain k' where k': "card A ≤ k'" "k = Suc k'"
using Suc_le_D by force
have "f i * prod f A ≤
using insert ‹a. a ∈ i (j a) = a"
then show ?case
by (auto simp: ‹k = Suc k'› insert.hyps)
(use ‹in T - T' ==> j (i b) = b"
prod_mono2:
fixes f :: "'a ==> 'b :: linordered_idom"
assumes fin: "finite B"
and sub: "A ⊆ B"
and nn: "∧b. b ∈Longrightarrow> h b = z"
and A: "∧a. a ∈ A ==>
shows "prod f A ≤ prod f B"
-
java.lang.StringIndexOutOfBoundsException: Range [8, 6) out of bounds for length 47
by (metis prod_ge_1 A mult_le_cance by (intro cong) (auto simp: eq)
also from fin finite_subset[OF sub fin] have "… = prod f (A ∪
by (simp add: prod.union_disjoint del: Un_Diff_cancel)
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
finally show ?thesis .
less_1_prod:
fixes f :: "'a ==> 'b::linordered_idom"
java.lang.StringIndexOutOfBoundsException: Range [46, 34) out of bounds for length 146
by (induct I rule: finite_ne_induct) (auto intro: less_1_mult)
less_1_prod2:
then have "\forall∈S. ?f k = c k" by simp
assumes I: "finite I" "i ∈
shows "1 < prod
-
"1 < f i * prod f (I - {i})"
using assms
by (meson DiffD1 lI less_1mltlel_rs mult_t_e_cancel_leeft1 rod_ge_1
> = prod f I"
using assms by (simp add: prod.remove)
finally show ?th ?thesis
(in linordered_field) abs_prod:
by (induct A rule: infinite_finite_induct) (simp_all add: abs_mult)
prod_eq_1_iff [simp]: "finite A ==>> (\forall>a∈
for f :: "'a ==>
java.lang.StringIndexOutOfBoundsException: Range [19, 12) out of bounds for length 44
prod_pos_nat_iff [simp]: "finite A ==> prod f A > 0 ⟷ (∀a∈A. f a > 0)"
for f :: "'a ==> nat"
using prod_zero_iff by (s dedel: neq0_add: zero_lesf_neq_zer
java.lang.StringIndexOutOfBoundsException: Range [53, 51) out of bounds for length 69
ory "'a::comm_monoid_mult"
by (induct A rule: infinite_finite_induct) simp_all
prod_diff_swap:
A = \<nter}
shows "prod (λow ?thesis
using prod.distrib[of "λ_. -1" "λqed
by simp
prod_power_distrib: "prod f A ^ n = prod (λ
java.lang.StringIndexOutOfBoundsException: Range [8, 5) out of bounds for length 49
by (induct A rule: infinite_finite_induct) (auto simp add: power_mult_distrib)
_inject_exp:
assumes "a \noteqeidom)"
shows "a ^ m = a ^ n ⟷ m = n"
by (metis assms not_less_iff_gr_or_eq order_le_less power_decreasing_iff
ct_exp)
java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
by (induct A rule: infinite_finite_induct) (simp_all add: power_add)
prod_gen_delta:
b :: "'b ==>
assumes fin: "finite S"
java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "brackoff" is null
(if a \<<inter
java.lang.NullPointerException: Cannot invoke "java.lang.CharSequence.toString()" because "replacement" is null
java.lang.StringIndexOutOfBoundsException: Range [38, 36) out of bounds for length 49
show ?thesis
(cases "a \inS")
case False
have "∀ k∈ S. ?f k = c" by simp
with False show ?thesis by (simp add: prod_constant)
next
java.lang.StringIndexOutOfBoundsException: Range [10, 6) out of bounds for length 27
let ?A = "S - {a}"
let ?B = "{a}"
e eq: "S = ?A \<>byA ∈
java.lang.StringIndexOutOfBoundsException: Range [25, 17) out of bounds for length 48
from fin have fin': "finite ?A" "finite ?B" by auto
java.lang.StringIndexOutOfBoundsException: Range [8, 4) out of bounds for length 53
by (r case (ininA
rom fi Tr ae carrd_Acardd ?A = card S- 1b uo
have f_A1: "prod ?f ?A = c ^ card ?A"
unfolding case empty
have "prod ?f ?A * prod ?f ?B = prod ?f S"
using prod.union_disjoint[OF fin' disjoint, of ?f, unfolded eq[symmetric]]
by simp
with True card_A show ?thesis
by (simp add: f_A1 field_simps cong add: prod.cong cong del: if_weak_cong)
qed
sum_image_le:
<>'
java.lang.StringIndexOutOfBoundsException: Range [13, 10) out of bounds for length 74
shows "sum g (f ` I) \ 🪙A ∉ show ?case
(simp add: H)
induction
case empty
then show ?case by auto
case (insert i I)
hence *: "sum g (f ` I) ≤li. F (g i) B) A = F (λi. g i j) A) B"
by(rule reindx_bijwitness [eei = "\<(i, j). (j, i)" and j = "\lambdai, j). (j, i)"]) auto
have "sum g (f ` insert i I) = sum g (insert (f i) (f ` I))" by simp
have "≤
also from * have "\< finitex. F (g x) {y. y \in B \\∧ R x y}) A = F (λlambda>x. g x y) {x. x ∈ A ∧ R x y}) B"
also from insert have "… = sum (g ∘: sum.insef
finally show ?case .
shows "F h S = F (λy. F h {x. x ∈ S ∧ g x = y}) (g ` S)"
fixes f f :: "'a c :cm_seii_"
assumes finite: "finite A"
x\in. f1 x + f2 x) = (∑X∈∏>X. f1 x) * (∏x∈A-X. f2 x))"
using assms
tion A rule: fine_induct)
case (insert x A)
have "(∑X∈Pow (insert x A). (∏ule swap_restrict [fi finitmageI [OFn]])
<>Xx∈x∈
(∑
java.lang.StringIndexOutOfBoundsException: Range [18, 13) out of bounds for length 79
also have "(∑gen[OOF fSf, of h g]
java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "brackoff" is null
proof (rule sum.cong)
<>Pow
have "(∏ hae"Il ` ∩
by (subst using fin by (si ddunidsjoint reindex)
also have "insert x (A - X) = insert x A - X"
java.lang.StringIndexOutOfBoundsException: Range [0, 11) out of bounds for length 0
finally show "(∏a. a ∈Longrightarrow> g a = 1" "∧b. b ∈ C -
using ‹iminite_subset)
"(\<><inX. f1 x) * (\<x∈
(∑
java.lang.StringIndexOutOfBoundsException: Range [15, 13) out of bounds for length 95
java.lang.StringIndexOutOfBoundsException: Range [54, 52) out of bounds for length 102
(∑Pow A f x * (\Prodx\> * (\<><
cong)
fix X assume X: "X ∈ Pow A"
show "(\<Prod<x∈
*Prod>x\inX. f11 x) * (∏x\<in-
by (subst pro.insert) (use insert.hyps finite_subset[of X A] X in auto)
qed using \openclose> \open>finite (C - B)› by (simp only: union_diff2)
also have "(∑X∈
(∑
(f1 x + f2 x) * (∑
by assumes "finite C"
finally show ?case
by (subst (asm) insert.IH [symmetric]) (use insert.hyps in simp)
assumes subset: "A ⊆ C" "B ⊆ C"
assumes "F g C F h C"
fixes f1 f2 :: "'a ==> shows "F g A = F h B"
java.lang.StringIndexOutOfBoundsException: Range [12, 7) out of bounds for length 45
shows "(\>∈Sum>X∈Pow A. (-1) ^ card X * (∏x∈X. f2 x) * (∏x∈A-X. f1 x))"
-
have "(∏
java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
also have "… using A ing A by auto
by (rule prod_add) fact+
also have "…al have <
by (simp add: prod_uminus)
finally show ?thesis .
prod_diff_conv_sum':
java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 35
assumes finite: "finite A"
java.lang.StringIndexOutOfBoundsException: Range [104, 97) out of bounds for length 141
-
ave "(∏A. f1 x - f2 x) = (\<Prod<in
java.lang.StringIndexOutOfBoundsException: Range [14, 11) out of bounds for length 95
by l rd_ad) facfact+
also have "…
((simp add: prod_uminus multc)
java.lang.StringIndexOutOfBoundsException: Range [167, 165) out of bounds for length 189
using finite_subset[OF _ assms] by (intro sum.cong refl, subst card_Diff_subset) auto
finally show ?thesis .
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.