| author | paulson <lp15@cam.ac.uk> | 
| Thu, 10 Apr 2025 17:07:18 +0100 | |
| changeset 82470 | 785615e37846 | 
| parent 82395 | 918c50e0447e | 
| child 82529 | ff4b062aae57 | 
| permissions | -rw-r--r-- | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1 | (* Title: HOL/Groups_Big.thy | 
| 63654 | 2 | Author: Tobias Nipkow | 
| 3 | Author: Lawrence C Paulson | |
| 4 | Author: Markus Wenzel | |
| 5 | Author: Jeremy Avigad | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 6 | *) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 7 | |
| 60758 | 8 | section \<open>Big sum and product over finite (non-empty) sets\<close> | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 9 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 10 | theory Groups_Big | 
| 74979 | 11 | imports Power Equiv_Relations | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 12 | begin | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 13 | |
| 60758 | 14 | subsection \<open>Generic monoid operation over a set\<close> | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 15 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 16 | locale comm_monoid_set = comm_monoid | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 17 | begin | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 18 | |
| 70044 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 19 | subsubsection \<open>Standard sum or product indexed by a finite set\<close> | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 20 | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 21 | interpretation comp_fun_commute f | 
| 61169 | 22 | by standard (simp add: fun_eq_iff left_commute) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 23 | |
| 54745 | 24 | interpretation comp?: comp_fun_commute "f \<circ> g" | 
| 25 | by (fact comp_comp_fun_commute) | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 26 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 27 | definition F :: "('b \<Rightarrow> 'a) \<Rightarrow> 'b set \<Rightarrow> 'a"
 | 
| 63654 | 28 | where eq_fold: "F g A = Finite_Set.fold (f \<circ> g) \<^bold>1 A" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 29 | |
| 63654 | 30 | lemma infinite [simp]: "\<not> finite A \<Longrightarrow> F g A = \<^bold>1" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 31 | by (simp add: eq_fold) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 32 | |
| 63654 | 33 | lemma empty [simp]: "F g {} = \<^bold>1"
 | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 34 | by (simp add: eq_fold) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 35 | |
| 63654 | 36 | lemma insert [simp]: "finite A \<Longrightarrow> x \<notin> A \<Longrightarrow> F g (insert x A) = g x \<^bold>* F g A" | 
| 37 | by (simp add: eq_fold) | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 38 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 39 | lemma remove: | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 40 | assumes "finite A" and "x \<in> A" | 
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 41 |   shows "F g A = g x \<^bold>* F g (A - {x})"
 | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 42 | proof - | 
| 63654 | 43 | from \<open>x \<in> A\<close> obtain B where B: "A = insert x B" and "x \<notin> B" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 44 | by (auto dest: mk_disjoint_insert) | 
| 63654 | 45 | moreover from \<open>finite A\<close> B have "finite B" by simp | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 46 | ultimately show ?thesis by simp | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 47 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 48 | |
| 63654 | 49 | lemma insert_remove: "finite A \<Longrightarrow> F g (insert x A) = g x \<^bold>* F g (A - {x})"
 | 
| 50 | by (cases "x \<in> A") (simp_all add: remove insert_absorb) | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 51 | |
| 63952 
354808e9f44b
new material connected with HOL Light measure theory, plus more rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63938diff
changeset | 52 | lemma insert_if: "finite A \<Longrightarrow> F g (insert x A) = (if x \<in> A then F g A else g x \<^bold>* F g A)" | 
| 
354808e9f44b
new material connected with HOL Light measure theory, plus more rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63938diff
changeset | 53 | by (cases "x \<in> A") (simp_all add: insert_absorb) | 
| 
354808e9f44b
new material connected with HOL Light measure theory, plus more rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63938diff
changeset | 54 | |
| 63654 | 55 | lemma neutral: "\<forall>x\<in>A. g x = \<^bold>1 \<Longrightarrow> F g A = \<^bold>1" | 
| 56 | by (induct A rule: infinite_finite_induct) simp_all | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 57 | |
| 63654 | 58 | lemma neutral_const [simp]: "F (\<lambda>_. \<^bold>1) A = \<^bold>1" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 59 | by (simp add: neutral) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 60 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 61 | lemma union_inter: | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 62 | assumes "finite A" and "finite B" | 
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 63 | shows "F g (A \<union> B) \<^bold>* F g (A \<inter> B) = F g A \<^bold>* F g B" | 
| 61799 | 64 | \<comment> \<open>The reversed orientation looks more natural, but LOOPS as a simprule!\<close> | 
| 63654 | 65 | using assms | 
| 66 | proof (induct A) | |
| 67 | case empty | |
| 68 | then show ?case by simp | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 69 | next | 
| 63654 | 70 | case (insert x A) | 
| 71 | then show ?case | |
| 72 | by (auto simp: insert_absorb Int_insert_left commute [of _ "g x"] assoc left_commute) | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 73 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 74 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 75 | corollary union_inter_neutral: | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 76 | assumes "finite A" and "finite B" | 
| 63654 | 77 | and "\<forall>x \<in> A \<inter> B. g x = \<^bold>1" | 
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 78 | shows "F g (A \<union> B) = F g A \<^bold>* F g B" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 79 | using assms by (simp add: union_inter [symmetric] neutral) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 80 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 81 | corollary union_disjoint: | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 82 | assumes "finite A" and "finite B" | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 83 |   assumes "A \<inter> B = {}"
 | 
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 84 | shows "F g (A \<union> B) = F g A \<^bold>* F g B" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 85 | using assms by (simp add: union_inter_neutral) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 86 | |
| 57418 | 87 | lemma union_diff2: | 
| 88 | assumes "finite A" and "finite B" | |
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 89 | shows "F g (A \<union> B) = F g (A - B) \<^bold>* F g (B - A) \<^bold>* F g (A \<inter> B)" | 
| 57418 | 90 | proof - | 
| 91 | have "A \<union> B = A - B \<union> (B - A) \<union> A \<inter> B" | |
| 92 | by auto | |
| 63654 | 93 | with assms show ?thesis | 
| 94 | by simp (subst union_disjoint, auto)+ | |
| 57418 | 95 | qed | 
| 96 | ||
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 97 | lemma subset_diff: | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 98 | assumes "B \<subseteq> A" and "finite A" | 
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 99 | shows "F g A = F g (A - B) \<^bold>* F g B" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 100 | proof - | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 101 | from assms have "finite (A - B)" by auto | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 102 | moreover from assms have "finite B" by (rule finite_subset) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 103 |   moreover from assms have "(A - B) \<inter> B = {}" by auto
 | 
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 104 | ultimately have "F g (A - B \<union> B) = F g (A - B) \<^bold>* F g B" by (rule union_disjoint) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 105 | moreover from assms have "A \<union> B = A" by auto | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 106 | ultimately show ?thesis by simp | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 107 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 108 | |
| 70097 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
70045diff
changeset | 109 | lemma Int_Diff: | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
70045diff
changeset | 110 | assumes "finite A" | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
70045diff
changeset | 111 | shows "F g A = F g (A \<inter> B) \<^bold>* F g (A - B)" | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
70045diff
changeset | 112 | by (subst subset_diff [where B = "A - B"]) (auto simp: Diff_Diff_Int assms) | 
| 
4005298550a6
The last big tranche of Homology material: invariance of domain; renamings to use generic sum/prod lemmas from their locale
 paulson <lp15@cam.ac.uk> parents: 
70045diff
changeset | 113 | |
| 56545 | 114 | lemma setdiff_irrelevant: | 
| 115 | assumes "finite A" | |
| 116 |   shows "F g (A - {x. g x = z}) = F g A"
 | |
| 62376 
85f38d5f8807
Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
 hoelzl parents: 
61955diff
changeset | 117 | using assms by (induct A) (simp_all add: insert_Diff_if) | 
| 58195 | 118 | |
| 56545 | 119 | lemma not_neutral_contains_not_neutral: | 
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 120 | assumes "F g A \<noteq> \<^bold>1" | 
| 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 121 | obtains a where "a \<in> A" and "g a \<noteq> \<^bold>1" | 
| 56545 | 122 | proof - | 
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 123 | from assms have "\<exists>a\<in>A. g a \<noteq> \<^bold>1" | 
| 56545 | 124 | proof (induct A rule: infinite_finite_induct) | 
| 63654 | 125 | case infinite | 
| 126 | then show ?case by simp | |
| 127 | next | |
| 128 | case empty | |
| 129 | then show ?case by simp | |
| 130 | next | |
| 56545 | 131 | case (insert a A) | 
| 63654 | 132 | then show ?case by fastforce | 
| 133 | qed | |
| 56545 | 134 | with that show thesis by blast | 
| 135 | qed | |
| 136 | ||
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 137 | lemma reindex: | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 138 | assumes "inj_on h A" | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 139 | shows "F g (h ` A) = F (g \<circ> h) A" | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 140 | proof (cases "finite A") | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 141 | case True | 
| 63654 | 142 | with assms show ?thesis | 
| 143 | by (simp add: eq_fold fold_image comp_assoc) | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 144 | next | 
| 63654 | 145 | case False | 
| 146 | with assms have "\<not> finite (h ` A)" by (blast dest: finite_imageD) | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 147 | with False show ?thesis by simp | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 148 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 149 | |
| 63357 | 150 | lemma cong [fundef_cong]: | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 151 | assumes "A = B" | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 152 | assumes g_h: "\<And>x. x \<in> B \<Longrightarrow> g x = h x" | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 153 | shows "F g A = F h B" | 
| 60758 | 154 | using g_h unfolding \<open>A = B\<close> | 
| 57129 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 155 | by (induct B rule: infinite_finite_induct) auto | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 156 | |
| 69654 | 157 | lemma cong_simp [cong]: | 
| 69164 | 158 | "\<lbrakk> A = B; \<And>x. x \<in> B =simp=> g x = h x \<rbrakk> \<Longrightarrow> F (\<lambda>x. g x) A = F (\<lambda>x. h x) B" | 
| 159 | by (rule cong) (simp_all add: simp_implies_def) | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 160 | |
| 57418 | 161 | lemma reindex_cong: | 
| 162 | assumes "inj_on l B" | |
| 163 | assumes "A = l ` B" | |
| 164 | assumes "\<And>x. x \<in> B \<Longrightarrow> g (l x) = h x" | |
| 165 | shows "F g A = F h B" | |
| 166 | using assms by (simp add: reindex) | |
| 167 | ||
| 72089 
8348bba699e6
A new lemma about abstract Sum / Prod
 paulson <lp15@cam.ac.uk> parents: 
71356diff
changeset | 168 | lemma image_eq: | 
| 
8348bba699e6
A new lemma about abstract Sum / Prod
 paulson <lp15@cam.ac.uk> parents: 
71356diff
changeset | 169 | assumes "inj_on g A" | 
| 
8348bba699e6
A new lemma about abstract Sum / Prod
 paulson <lp15@cam.ac.uk> parents: 
71356diff
changeset | 170 | shows "F (\<lambda>x. x) (g ` A) = F g A" | 
| 
8348bba699e6
A new lemma about abstract Sum / Prod
 paulson <lp15@cam.ac.uk> parents: 
71356diff
changeset | 171 | using assms reindex_cong by fastforce | 
| 
8348bba699e6
A new lemma about abstract Sum / Prod
 paulson <lp15@cam.ac.uk> parents: 
71356diff
changeset | 172 | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 173 | lemma UNION_disjoint: | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 174 | assumes "finite I" and "\<forall>i\<in>I. finite (A i)" | 
| 63654 | 175 |     and "\<forall>i\<in>I. \<forall>j\<in>I. i \<noteq> j \<longrightarrow> A i \<inter> A j = {}"
 | 
| 69275 | 176 | shows "F g (\<Union>(A ` I)) = F (\<lambda>x. F g (A x)) I" | 
| 70128 | 177 | using assms | 
| 178 | proof (induction rule: finite_induct) | |
| 179 | case (insert i I) | |
| 180 | then have "\<forall>j\<in>I. j \<noteq> i" | |
| 181 | by blast | |
| 182 |   with insert.prems have "A i \<inter> \<Union>(A ` I) = {}"
 | |
| 183 | by blast | |
| 184 | with insert show ?case | |
| 185 | by (simp add: union_disjoint) | |
| 186 | qed auto | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 187 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 188 | lemma Union_disjoint: | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 189 |   assumes "\<forall>A\<in>C. finite A" "\<forall>A\<in>C. \<forall>B\<in>C. A \<noteq> B \<longrightarrow> A \<inter> B = {}"
 | 
| 61952 | 190 | shows "F g (\<Union>C) = (F \<circ> F) g C" | 
| 63654 | 191 | proof (cases "finite C") | 
| 192 | case True | |
| 193 | from UNION_disjoint [OF this assms] show ?thesis by simp | |
| 194 | next | |
| 195 | case False | |
| 196 | then show ?thesis by (auto dest: finite_UnionD intro: infinite) | |
| 197 | qed | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 198 | |
| 63654 | 199 | lemma distrib: "F (\<lambda>x. g x \<^bold>* h x) A = F g A \<^bold>* F h A" | 
| 63092 | 200 | by (induct A rule: infinite_finite_induct) (simp_all add: assoc commute left_commute) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 201 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 202 | lemma Sigma: | 
| 70128 | 203 | assumes "finite A" "\<forall>x\<in>A. finite (B x)" | 
| 204 | shows "F (\<lambda>x. F (g x) (B x)) A = F (case_prod g) (SIGMA x:A. B x)" | |
| 205 | unfolding Sigma_def | |
| 206 | proof (subst UNION_disjoint) | |
| 207 |   show "F (\<lambda>x. F (g x) (B x)) A = F (\<lambda>x. F (\<lambda>(x, y). g x y) (\<Union>y\<in>B x. {(x, y)})) A"
 | |
| 208 | proof (rule cong [OF refl]) | |
| 209 |     show "F (g x) (B x) = F (\<lambda>(x, y). g x y) (\<Union>y\<in>B x. {(x, y)})"
 | |
| 210 | if "x \<in> A" for x | |
| 211 | using that assms by (simp add: UNION_disjoint) | |
| 212 | qed | |
| 213 | qed (use assms in auto) | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 214 | |
| 62376 
85f38d5f8807
Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
 hoelzl parents: 
61955diff
changeset | 215 | lemma related: | 
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 216 | assumes Re: "R \<^bold>1 \<^bold>1" | 
| 63654 | 217 | and Rop: "\<forall>x1 y1 x2 y2. R x1 x2 \<and> R y1 y2 \<longrightarrow> R (x1 \<^bold>* y1) (x2 \<^bold>* y2)" | 
| 218 | and fin: "finite S" | |
| 219 | and R_h_g: "\<forall>x\<in>S. R (h x) (g x)" | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 220 | shows "R (F h S) (F g S)" | 
| 63654 | 221 | using fin by (rule finite_subset_induct) (use assms in auto) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 222 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 223 | lemma mono_neutral_cong_left: | 
| 63654 | 224 | assumes "finite T" | 
| 225 | and "S \<subseteq> T" | |
| 226 | and "\<forall>i \<in> T - S. h i = \<^bold>1" | |
| 227 | and "\<And>x. x \<in> S \<Longrightarrow> g x = h x" | |
| 228 | shows "F g S = F h T" | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 229 | proof- | 
| 60758 | 230 | have eq: "T = S \<union> (T - S)" using \<open>S \<subseteq> T\<close> by blast | 
| 231 |   have d: "S \<inter> (T - S) = {}" using \<open>S \<subseteq> T\<close> by blast
 | |
| 232 | from \<open>finite T\<close> \<open>S \<subseteq> T\<close> have f: "finite S" "finite (T - S)" | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 233 | by (auto intro: finite_subset) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 234 | show ?thesis using assms(4) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 235 | by (simp add: union_disjoint [OF f d, unfolded eq [symmetric]] neutral [OF assms(3)]) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 236 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 237 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 238 | lemma mono_neutral_cong_right: | 
| 63654 | 239 | "finite T \<Longrightarrow> S \<subseteq> T \<Longrightarrow> \<forall>i \<in> T - S. g i = \<^bold>1 \<Longrightarrow> (\<And>x. x \<in> S \<Longrightarrow> g x = h x) \<Longrightarrow> | 
| 240 | F g T = F h S" | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 241 | by (auto intro!: mono_neutral_cong_left [symmetric]) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 242 | |
| 63654 | 243 | lemma mono_neutral_left: "finite T \<Longrightarrow> S \<subseteq> T \<Longrightarrow> \<forall>i \<in> T - S. g i = \<^bold>1 \<Longrightarrow> F g S = F g T" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 244 | by (blast intro: mono_neutral_cong_left) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 245 | |
| 63654 | 246 | lemma mono_neutral_right: "finite T \<Longrightarrow> S \<subseteq> T \<Longrightarrow> \<forall>i \<in> T - S. g i = \<^bold>1 \<Longrightarrow> F g T = F g S" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 247 | by (blast intro!: mono_neutral_left [symmetric]) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 248 | |
| 64979 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 249 | lemma mono_neutral_cong: | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 250 | assumes [simp]: "finite T" "finite S" | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 251 | and *: "\<And>i. i \<in> T - S \<Longrightarrow> h i = \<^bold>1" "\<And>i. i \<in> S - T \<Longrightarrow> g i = \<^bold>1" | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 252 | and gh: "\<And>x. x \<in> S \<inter> T \<Longrightarrow> g x = h x" | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 253 | shows "F g S = F h T" | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 254 | proof- | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 255 | have "F g S = F g (S \<inter> T)" | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 256 | by(rule mono_neutral_right)(auto intro: *) | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 257 | also have "\<dots> = F h (S \<inter> T)" using refl gh by(rule cong) | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 258 | also have "\<dots> = F h T" | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 259 | by(rule mono_neutral_left)(auto intro: *) | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 260 | finally show ?thesis . | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 261 | qed | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 262 | |
| 57129 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 263 | lemma reindex_bij_betw: "bij_betw h S T \<Longrightarrow> F (\<lambda>x. g (h x)) S = F g T" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 264 | by (auto simp: bij_betw_def reindex) | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 265 | |
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 266 | lemma reindex_bij_witness: | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 267 | assumes witness: | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 268 | "\<And>a. a \<in> S \<Longrightarrow> i (j a) = a" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 269 | "\<And>a. a \<in> S \<Longrightarrow> j a \<in> T" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 270 | "\<And>b. b \<in> T \<Longrightarrow> j (i b) = b" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 271 | "\<And>b. b \<in> T \<Longrightarrow> i b \<in> S" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 272 | assumes eq: | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 273 | "\<And>a. a \<in> S \<Longrightarrow> h (j a) = g a" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 274 | shows "F g S = F h T" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 275 | proof - | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 276 | have "bij_betw j S T" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 277 | using bij_betw_byWitness[where A=S and f=j and f'=i and A'=T] witness by auto | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 278 | moreover have "F g S = F (\<lambda>x. h (j x)) S" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 279 | by (intro cong) (auto simp: eq) | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 280 | ultimately show ?thesis | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 281 | by (simp add: reindex_bij_betw) | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 282 | qed | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 283 | |
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 284 | lemma reindex_bij_betw_not_neutral: | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 285 | assumes fin: "finite S'" "finite T'" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 286 | assumes bij: "bij_betw h (S - S') (T - T')" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 287 | assumes nn: | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 288 | "\<And>a. a \<in> S' \<Longrightarrow> g (h a) = z" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 289 | "\<And>b. b \<in> T' \<Longrightarrow> g b = z" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 290 | shows "F (\<lambda>x. g (h x)) S = F g T" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 291 | proof - | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 292 | have [simp]: "finite S \<longleftrightarrow> finite T" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 293 | using bij_betw_finite[OF bij] fin by auto | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 294 | show ?thesis | 
| 63654 | 295 | proof (cases "finite S") | 
| 296 | case True | |
| 57129 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 297 | with nn have "F (\<lambda>x. g (h x)) S = F (\<lambda>x. g (h x)) (S - S')" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 298 | by (intro mono_neutral_cong_right) auto | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 299 | also have "\<dots> = F g (T - T')" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 300 | using bij by (rule reindex_bij_betw) | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 301 | also have "\<dots> = F g T" | 
| 60758 | 302 | using nn \<open>finite S\<close> by (intro mono_neutral_cong_left) auto | 
| 57129 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 303 | finally show ?thesis . | 
| 63654 | 304 | next | 
| 305 | case False | |
| 306 | then show ?thesis by simp | |
| 307 | qed | |
| 57129 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 308 | qed | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 309 | |
| 57418 | 310 | lemma reindex_nontrivial: | 
| 311 | assumes "finite A" | |
| 63654 | 312 | and nz: "\<And>x y. x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> x \<noteq> y \<Longrightarrow> h x = h y \<Longrightarrow> g (h x) = \<^bold>1" | 
| 57418 | 313 | shows "F g (h ` A) = F (g \<circ> h) A" | 
| 314 | proof (subst reindex_bij_betw_not_neutral [symmetric]) | |
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 315 |   show "bij_betw h (A - {x \<in> A. (g \<circ> h) x = \<^bold>1}) (h ` A - h ` {x \<in> A. (g \<circ> h) x = \<^bold>1})"
 | 
| 57418 | 316 | using nz by (auto intro!: inj_onI simp: bij_betw_def) | 
| 63654 | 317 | qed (use \<open>finite A\<close> in auto) | 
| 57418 | 318 | |
| 57129 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 319 | lemma reindex_bij_witness_not_neutral: | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 320 | assumes fin: "finite S'" "finite T'" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 321 | assumes witness: | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 322 | "\<And>a. a \<in> S - S' \<Longrightarrow> i (j a) = a" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 323 | "\<And>a. a \<in> S - S' \<Longrightarrow> j a \<in> T - T'" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 324 | "\<And>b. b \<in> T - T' \<Longrightarrow> j (i b) = b" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 325 | "\<And>b. b \<in> T - T' \<Longrightarrow> i b \<in> S - S'" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 326 | assumes nn: | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 327 | "\<And>a. a \<in> S' \<Longrightarrow> g a = z" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 328 | "\<And>b. b \<in> T' \<Longrightarrow> h b = z" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 329 | assumes eq: | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 330 | "\<And>a. a \<in> S \<Longrightarrow> h (j a) = g a" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 331 | shows "F g S = F h T" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 332 | proof - | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 333 | have bij: "bij_betw j (S - (S' \<inter> S)) (T - (T' \<inter> T))" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 334 | using witness by (intro bij_betw_byWitness[where f'=i]) auto | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 335 | have F_eq: "F g S = F (\<lambda>x. h (j x)) S" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 336 | by (intro cong) (auto simp: eq) | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 337 | show ?thesis | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 338 | unfolding F_eq using fin nn eq | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 339 | by (intro reindex_bij_betw_not_neutral[OF _ _ bij]) auto | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 340 | qed | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 341 | |
| 67673 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 342 | lemma delta_remove: | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 343 | assumes fS: "finite S" | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 344 |   shows "F (\<lambda>k. if k = a then b k else c k) S = (if a \<in> S then b a \<^bold>* F c (S-{a}) else F c (S-{a}))"
 | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 345 | proof - | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 346 | let ?f = "(\<lambda>k. if k = a then b k else c k)" | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 347 | show ?thesis | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 348 | proof (cases "a \<in> S") | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 349 | case False | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 350 | then have "\<forall>k\<in>S. ?f k = c k" by simp | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 351 | with False show ?thesis by simp | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 352 | next | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 353 | case True | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 354 |     let ?A = "S - {a}"
 | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 355 |     let ?B = "{a}"
 | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 356 | from True have eq: "S = ?A \<union> ?B" by blast | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 357 |     have dj: "?A \<inter> ?B = {}" by simp
 | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 358 | from fS have fAB: "finite ?A" "finite ?B" by auto | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 359 | have "F ?f S = F ?f ?A \<^bold>* F ?f ?B" | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 360 | using union_disjoint [OF fAB dj, of ?f, unfolded eq [symmetric]] by simp | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 361 | with True show ?thesis | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 362 | using comm_monoid_set.remove comm_monoid_set_axioms fS by fastforce | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 363 | qed | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 364 | qed | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 365 | |
| 67683 
817944aeac3f
Lots of new material about matrices, etc.
 paulson <lp15@cam.ac.uk> parents: 
67673diff
changeset | 366 | lemma delta [simp]: | 
| 
817944aeac3f
Lots of new material about matrices, etc.
 paulson <lp15@cam.ac.uk> parents: 
67673diff
changeset | 367 | assumes fS: "finite S" | 
| 
817944aeac3f
Lots of new material about matrices, etc.
 paulson <lp15@cam.ac.uk> parents: 
67673diff
changeset | 368 | shows "F (\<lambda>k. if k = a then b k else \<^bold>1) S = (if a \<in> S then b a else \<^bold>1)" | 
| 
817944aeac3f
Lots of new material about matrices, etc.
 paulson <lp15@cam.ac.uk> parents: 
67673diff
changeset | 369 | by (simp add: delta_remove [OF assms]) | 
| 
817944aeac3f
Lots of new material about matrices, etc.
 paulson <lp15@cam.ac.uk> parents: 
67673diff
changeset | 370 | |
| 
817944aeac3f
Lots of new material about matrices, etc.
 paulson <lp15@cam.ac.uk> parents: 
67673diff
changeset | 371 | lemma delta' [simp]: | 
| 
817944aeac3f
Lots of new material about matrices, etc.
 paulson <lp15@cam.ac.uk> parents: 
67673diff
changeset | 372 | assumes fin: "finite S" | 
| 
817944aeac3f
Lots of new material about matrices, etc.
 paulson <lp15@cam.ac.uk> parents: 
67673diff
changeset | 373 | shows "F (\<lambda>k. if a = k then b k else \<^bold>1) S = (if a \<in> S then b a else \<^bold>1)" | 
| 
817944aeac3f
Lots of new material about matrices, etc.
 paulson <lp15@cam.ac.uk> parents: 
67673diff
changeset | 374 | using delta [OF fin, of a b, symmetric] by (auto intro: cong) | 
| 
817944aeac3f
Lots of new material about matrices, etc.
 paulson <lp15@cam.ac.uk> parents: 
67673diff
changeset | 375 | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 376 | lemma If_cases: | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 377 | fixes P :: "'b \<Rightarrow> bool" and g h :: "'b \<Rightarrow> 'a" | 
| 63654 | 378 | assumes fin: "finite A" | 
| 379 |   shows "F (\<lambda>x. if P x then h x else g x) A = F h (A \<inter> {x. P x}) \<^bold>* F g (A \<inter> - {x. P x})"
 | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 380 | proof - | 
| 63654 | 381 |   have a: "A = A \<inter> {x. P x} \<union> A \<inter> -{x. P x}" "(A \<inter> {x. P x}) \<inter> (A \<inter> -{x. P x}) = {}"
 | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 382 | by blast+ | 
| 63654 | 383 |   from fin have f: "finite (A \<inter> {x. P x})" "finite (A \<inter> -{x. P x})" by auto
 | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 384 | let ?g = "\<lambda>x. if P x then h x else g x" | 
| 63654 | 385 | from union_disjoint [OF f a(2), of ?g] a(1) show ?thesis | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 386 | by (subst (1 2) cong) simp_all | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 387 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 388 | |
| 63654 | 389 | lemma cartesian_product: "F (\<lambda>x. F (g x) B) A = F (case_prod g) (A \<times> B)" | 
| 70128 | 390 | proof (cases "A = {} \<or> B = {}")
 | 
| 391 | case True | |
| 392 | then show ?thesis | |
| 393 | by auto | |
| 394 | next | |
| 395 | case False | |
| 396 |   then have "A \<noteq> {}" "B \<noteq> {}" by auto
 | |
| 397 | show ?thesis | |
| 398 | proof (cases "finite A \<and> finite B") | |
| 399 | case True | |
| 400 | then show ?thesis | |
| 401 | by (simp add: Sigma) | |
| 402 | next | |
| 403 | case False | |
| 404 | then consider "infinite A" | "infinite B" by auto | |
| 405 | then have "infinite (A \<times> B)" | |
| 406 |       by cases (use \<open>A \<noteq> {}\<close> \<open>B \<noteq> {}\<close> in \<open>auto dest: finite_cartesian_productD1 finite_cartesian_productD2\<close>)
 | |
| 407 | then show ?thesis | |
| 408 | using False by auto | |
| 409 | qed | |
| 410 | qed | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 411 | |
| 79492 
c1b0f64eb865
A few new results (mostly brought in from other developments)
 paulson <lp15@cam.ac.uk> parents: 
75669diff
changeset | 412 | lemma cartesian_product': | 
| 
c1b0f64eb865
A few new results (mostly brought in from other developments)
 paulson <lp15@cam.ac.uk> parents: 
75669diff
changeset | 413 | "F g (A \<times> B) = F (\<lambda>x. F (\<lambda>y. g (x,y)) B) A" | 
| 
c1b0f64eb865
A few new results (mostly brought in from other developments)
 paulson <lp15@cam.ac.uk> parents: 
75669diff
changeset | 414 | unfolding cartesian_product by simp | 
| 
c1b0f64eb865
A few new results (mostly brought in from other developments)
 paulson <lp15@cam.ac.uk> parents: 
75669diff
changeset | 415 | |
| 
c1b0f64eb865
A few new results (mostly brought in from other developments)
 paulson <lp15@cam.ac.uk> parents: 
75669diff
changeset | 416 | |
| 57418 | 417 | lemma inter_restrict: | 
| 418 | assumes "finite A" | |
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 419 | shows "F g (A \<inter> B) = F (\<lambda>x. if x \<in> B then g x else \<^bold>1) A" | 
| 57418 | 420 | proof - | 
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 421 | let ?g = "\<lambda>x. if x \<in> A \<inter> B then g x else \<^bold>1" | 
| 63654 | 422 | have "\<forall>i\<in>A - A \<inter> B. (if i \<in> A \<inter> B then g i else \<^bold>1) = \<^bold>1" by simp | 
| 57418 | 423 | moreover have "A \<inter> B \<subseteq> A" by blast | 
| 63654 | 424 | ultimately have "F ?g (A \<inter> B) = F ?g A" | 
| 425 | using \<open>finite A\<close> by (intro mono_neutral_left) auto | |
| 57418 | 426 | then show ?thesis by simp | 
| 427 | qed | |
| 428 | ||
| 429 | lemma inter_filter: | |
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 430 |   "finite A \<Longrightarrow> F g {x \<in> A. P x} = F (\<lambda>x. if P x then g x else \<^bold>1) A"
 | 
| 57418 | 431 |   by (simp add: inter_restrict [symmetric, of A "{x. P x}" g, simplified mem_Collect_eq] Int_def)
 | 
| 432 | ||
| 433 | lemma Union_comp: | |
| 434 | assumes "\<forall>A \<in> B. finite A" | |
| 63654 | 435 | and "\<And>A1 A2 x. A1 \<in> B \<Longrightarrow> A2 \<in> B \<Longrightarrow> A1 \<noteq> A2 \<Longrightarrow> x \<in> A1 \<Longrightarrow> x \<in> A2 \<Longrightarrow> g x = \<^bold>1" | 
| 57418 | 436 | shows "F g (\<Union>B) = (F \<circ> F) g B" | 
| 63654 | 437 | using assms | 
| 438 | proof (induct B rule: infinite_finite_induct) | |
| 57418 | 439 | case (infinite A) | 
| 440 | then have "\<not> finite (\<Union>A)" by (blast dest: finite_UnionD) | |
| 441 | with infinite show ?case by simp | |
| 442 | next | |
| 63654 | 443 | case empty | 
| 444 | then show ?case by simp | |
| 57418 | 445 | next | 
| 446 | case (insert A B) | |
| 447 | then have "finite A" "finite B" "finite (\<Union>B)" "A \<notin> B" | |
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 448 | and "\<forall>x\<in>A \<inter> \<Union>B. g x = \<^bold>1" | 
| 63654 | 449 | and H: "F g (\<Union>B) = (F \<circ> F) g B" by auto | 
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 450 | then have "F g (A \<union> \<Union>B) = F g A \<^bold>* F g (\<Union>B)" | 
| 57418 | 451 | by (simp add: union_inter_neutral) | 
| 60758 | 452 | with \<open>finite B\<close> \<open>A \<notin> B\<close> show ?case | 
| 57418 | 453 | by (simp add: H) | 
| 454 | qed | |
| 455 | ||
| 66804 
3f9bb52082c4
avoid name clashes on interpretation of abstract locales
 haftmann parents: 
66364diff
changeset | 456 | lemma swap: "F (\<lambda>i. F (g i) B) A = F (\<lambda>j. F (\<lambda>i. g i j) A) B" | 
| 57418 | 457 | unfolding cartesian_product | 
| 458 | by (rule reindex_bij_witness [where i = "\<lambda>(i, j). (j, i)" and j = "\<lambda>(i, j). (j, i)"]) auto | |
| 459 | ||
| 66804 
3f9bb52082c4
avoid name clashes on interpretation of abstract locales
 haftmann parents: 
66364diff
changeset | 460 | lemma swap_restrict: | 
| 57418 | 461 | "finite A \<Longrightarrow> finite B \<Longrightarrow> | 
| 462 |     F (\<lambda>x. F (g x) {y. y \<in> B \<and> R x y}) A = F (\<lambda>y. F (\<lambda>x. g x y) {x. x \<in> A \<and> R x y}) B"
 | |
| 66804 
3f9bb52082c4
avoid name clashes on interpretation of abstract locales
 haftmann parents: 
66364diff
changeset | 463 | by (simp add: inter_filter) (rule swap) | 
| 57418 | 464 | |
| 69510 | 465 | lemma image_gen: | 
| 466 | assumes fin: "finite S" | |
| 467 |   shows "F h S = F (\<lambda>y. F h {x. x \<in> S \<and> g x = y}) (g ` S)"
 | |
| 468 | proof - | |
| 469 |   have "{y. y\<in> g`S \<and> g x = y} = {g x}" if "x \<in> S" for x
 | |
| 470 | using that by auto | |
| 471 |   then have "F h S = F (\<lambda>x. F (\<lambda>y. h x) {y. y\<in> g`S \<and> g x = y}) S"
 | |
| 472 | by simp | |
| 473 |   also have "\<dots> = F (\<lambda>y. F h {x. x \<in> S \<and> g x = y}) (g ` S)"
 | |
| 474 | by (rule swap_restrict [OF fin finite_imageI [OF fin]]) | |
| 475 | finally show ?thesis . | |
| 476 | qed | |
| 477 | ||
| 478 | lemma group: | |
| 479 | assumes fS: "finite S" and fT: "finite T" and fST: "g ` S \<subseteq> T" | |
| 480 |   shows "F (\<lambda>y. F h {x. x \<in> S \<and> g x = y}) T = F h S"
 | |
| 481 | unfolding image_gen[OF fS, of h g] | |
| 482 | by (auto intro: neutral mono_neutral_right[OF fT fST]) | |
| 483 | ||
| 57418 | 484 | lemma Plus: | 
| 485 | fixes A :: "'b set" and B :: "'c set" | |
| 486 | assumes fin: "finite A" "finite B" | |
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 487 | shows "F g (A <+> B) = F (g \<circ> Inl) A \<^bold>* F (g \<circ> Inr) B" | 
| 57418 | 488 | proof - | 
| 489 | have "A <+> B = Inl ` A \<union> Inr ` B" by auto | |
| 63654 | 490 | moreover from fin have "finite (Inl ` A)" "finite (Inr ` B)" by auto | 
| 491 |   moreover have "Inl ` A \<inter> Inr ` B = {}" by auto
 | |
| 492 | moreover have "inj_on Inl A" "inj_on Inr B" by (auto intro: inj_onI) | |
| 493 | ultimately show ?thesis | |
| 494 | using fin by (simp add: union_disjoint reindex) | |
| 57418 | 495 | qed | 
| 496 | ||
| 58195 | 497 | lemma same_carrier: | 
| 498 | assumes "finite C" | |
| 499 | assumes subset: "A \<subseteq> C" "B \<subseteq> C" | |
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 500 | assumes trivial: "\<And>a. a \<in> C - A \<Longrightarrow> g a = \<^bold>1" "\<And>b. b \<in> C - B \<Longrightarrow> h b = \<^bold>1" | 
| 58195 | 501 | shows "F g A = F h B \<longleftrightarrow> F g C = F h C" | 
| 502 | proof - | |
| 63654 | 503 | have "finite A" and "finite B" and "finite (C - A)" and "finite (C - B)" | 
| 504 | using \<open>finite C\<close> subset by (auto elim: finite_subset) | |
| 58195 | 505 | from subset have [simp]: "A - (C - A) = A" by auto | 
| 506 | from subset have [simp]: "B - (C - B) = B" by auto | |
| 507 | from subset have "C = A \<union> (C - A)" by auto | |
| 508 | then have "F g C = F g (A \<union> (C - A))" by simp | |
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 509 | also have "\<dots> = F g (A - (C - A)) \<^bold>* F g (C - A - A) \<^bold>* F g (A \<inter> (C - A))" | 
| 60758 | 510 | using \<open>finite A\<close> \<open>finite (C - A)\<close> by (simp only: union_diff2) | 
| 63654 | 511 | finally have *: "F g C = F g A" using trivial by simp | 
| 58195 | 512 | from subset have "C = B \<union> (C - B)" by auto | 
| 513 | then have "F h C = F h (B \<union> (C - B))" by simp | |
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 514 | also have "\<dots> = F h (B - (C - B)) \<^bold>* F h (C - B - B) \<^bold>* F h (B \<inter> (C - B))" | 
| 60758 | 515 | using \<open>finite B\<close> \<open>finite (C - B)\<close> by (simp only: union_diff2) | 
| 63654 | 516 | finally have "F h C = F h B" | 
| 517 | using trivial by simp | |
| 518 | with * show ?thesis by simp | |
| 58195 | 519 | qed | 
| 520 | ||
| 521 | lemma same_carrierI: | |
| 522 | assumes "finite C" | |
| 523 | assumes subset: "A \<subseteq> C" "B \<subseteq> C" | |
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 524 | assumes trivial: "\<And>a. a \<in> C - A \<Longrightarrow> g a = \<^bold>1" "\<And>b. b \<in> C - B \<Longrightarrow> h b = \<^bold>1" | 
| 58195 | 525 | assumes "F g C = F h C" | 
| 526 | shows "F g A = F h B" | |
| 527 | using assms same_carrier [of C A B] by simp | |
| 528 | ||
| 69700 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 529 | lemma eq_general: | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 530 | assumes B: "\<And>y. y \<in> B \<Longrightarrow> \<exists>!x. x \<in> A \<and> h x = y" and A: "\<And>x. x \<in> A \<Longrightarrow> h x \<in> B \<and> \<gamma>(h x) = \<phi> x" | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 531 | shows "F \<phi> A = F \<gamma> B" | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 532 | proof - | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 533 | have eq: "B = h ` A" | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 534 | by (auto dest: assms) | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 535 | have h: "inj_on h A" | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 536 | using assms by (blast intro: inj_onI) | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 537 | have "F \<phi> A = F (\<gamma> \<circ> h) A" | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 538 | using A by auto | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 539 | also have "\<dots> = F \<gamma> B" | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 540 | by (simp add: eq reindex h) | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 541 | finally show ?thesis . | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 542 | qed | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 543 | |
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 544 | lemma eq_general_inverses: | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 545 | assumes B: "\<And>y. y \<in> B \<Longrightarrow> k y \<in> A \<and> h(k y) = y" and A: "\<And>x. x \<in> A \<Longrightarrow> h x \<in> B \<and> k(h x) = x \<and> \<gamma>(h x) = \<phi> x" | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 546 | shows "F \<phi> A = F \<gamma> B" | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 547 | by (rule eq_general [where h=h]) (force intro: dest: A B)+ | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 548 | |
| 70044 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 549 | subsubsection \<open>HOL Light variant: sum/product indexed by the non-neutral subset\<close> | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 550 | text \<open>NB only a subset of the properties above are proved\<close> | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 551 | |
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 552 | definition G :: "['b \<Rightarrow> 'a,'b set] \<Rightarrow> 'a" | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 553 |   where "G p I \<equiv> if finite {x \<in> I. p x \<noteq> \<^bold>1} then F p {x \<in> I. p x \<noteq> \<^bold>1} else \<^bold>1"
 | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 554 | |
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 555 | lemma finite_Collect_op: | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 556 |   shows "\<lbrakk>finite {i \<in> I. x i \<noteq> \<^bold>1}; finite {i \<in> I. y i \<noteq> \<^bold>1}\<rbrakk> \<Longrightarrow> finite {i \<in> I. x i \<^bold>* y i \<noteq> \<^bold>1}"
 | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 557 |   apply (rule finite_subset [where B = "{i \<in> I. x i \<noteq> \<^bold>1} \<union> {i \<in> I. y i \<noteq> \<^bold>1}"]) 
 | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 558 | using left_neutral by force+ | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 559 | |
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 560 | lemma empty' [simp]: "G p {} = \<^bold>1"
 | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 561 | by (auto simp: G_def) | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 562 | |
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 563 | lemma eq_sum [simp]: "finite I \<Longrightarrow> G p I = F p I" | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 564 | by (auto simp: G_def intro: mono_neutral_cong_left) | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 565 | |
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 566 | lemma insert' [simp]: | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 567 |   assumes "finite {x \<in> I. p x \<noteq> \<^bold>1}"
 | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 568 | shows "G p (insert i I) = (if i \<in> I then G p I else p i \<^bold>* G p I)" | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 569 | proof - | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 570 |   have "{x. x = i \<and> p x \<noteq> \<^bold>1 \<or> x \<in> I \<and> p x \<noteq> \<^bold>1} = (if p i = \<^bold>1 then {x \<in> I. p x \<noteq> \<^bold>1} else insert i {x \<in> I. p x \<noteq> \<^bold>1})"
 | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 571 | by auto | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 572 | then show ?thesis | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 573 | using assms by (simp add: G_def conj_disj_distribR insert_absorb) | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 574 | qed | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 575 | |
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 576 | lemma distrib_triv': | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 577 | assumes "finite I" | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 578 | shows "G (\<lambda>i. g i \<^bold>* h i) I = G g I \<^bold>* G h I" | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 579 | by (simp add: assms local.distrib) | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 580 | |
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 581 | lemma non_neutral': "G g {x \<in> I. g x \<noteq> \<^bold>1} = G g I"
 | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 582 | by (simp add: G_def) | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 583 | |
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 584 | lemma distrib': | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 585 |   assumes "finite {x \<in> I. g x \<noteq> \<^bold>1}" "finite {x \<in> I. h x \<noteq> \<^bold>1}"
 | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 586 | shows "G (\<lambda>i. g i \<^bold>* h i) I = G g I \<^bold>* G h I" | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 587 | proof - | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 588 | have "a \<^bold>* a \<noteq> a \<Longrightarrow> a \<noteq> \<^bold>1" for a | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 589 | by auto | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 590 |   then have "G (\<lambda>i. g i \<^bold>* h i) I = G (\<lambda>i. g i \<^bold>* h i) ({i \<in> I. g i \<noteq> \<^bold>1} \<union> {i \<in> I. h i \<noteq> \<^bold>1})"
 | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 591 | using assms by (force simp: G_def finite_Collect_op intro!: mono_neutral_cong) | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 592 | also have "\<dots> = G g I \<^bold>* G h I" | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 593 | proof - | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 594 |     have "F g ({i \<in> I. g i \<noteq> \<^bold>1} \<union> {i \<in> I. h i \<noteq> \<^bold>1}) = G g I"
 | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 595 |          "F h ({i \<in> I. g i \<noteq> \<^bold>1} \<union> {i \<in> I. h i \<noteq> \<^bold>1}) = G h I"
 | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 596 | by (auto simp: G_def assms intro: mono_neutral_right) | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 597 | then show ?thesis | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 598 | using assms by (simp add: distrib) | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 599 | qed | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 600 | finally show ?thesis . | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 601 | qed | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 602 | |
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 603 | lemma cong': | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 604 | assumes "A = B" | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 605 | assumes g_h: "\<And>x. x \<in> B \<Longrightarrow> g x = h x" | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 606 | shows "G g A = G h B" | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 607 | using assms by (auto simp: G_def cong: conj_cong intro: cong) | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 608 | |
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 609 | |
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 610 | lemma mono_neutral_cong_left': | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 611 | assumes "S \<subseteq> T" | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 612 | and "\<And>i. i \<in> T - S \<Longrightarrow> h i = \<^bold>1" | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 613 | and "\<And>x. x \<in> S \<Longrightarrow> g x = h x" | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 614 | shows "G g S = G h T" | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 615 | proof - | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 616 |   have *: "{x \<in> S. g x \<noteq> \<^bold>1} = {x \<in> T. h x \<noteq> \<^bold>1}"
 | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 617 | using assms by (metis DiffI subset_eq) | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 618 |   then have "finite {x \<in> S. g x \<noteq> \<^bold>1} = finite {x \<in> T. h x \<noteq> \<^bold>1}"
 | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 619 | by simp | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 620 | then show ?thesis | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 621 | using assms by (auto simp add: G_def * intro: cong) | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 622 | qed | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 623 | |
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 624 | lemma mono_neutral_cong_right': | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 625 | "S \<subseteq> T \<Longrightarrow> \<forall>i \<in> T - S. g i = \<^bold>1 \<Longrightarrow> (\<And>x. x \<in> S \<Longrightarrow> g x = h x) \<Longrightarrow> | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 626 | G g T = G h S" | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 627 | by (auto intro!: mono_neutral_cong_left' [symmetric]) | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 628 | |
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 629 | lemma mono_neutral_left': "S \<subseteq> T \<Longrightarrow> \<forall>i \<in> T - S. g i = \<^bold>1 \<Longrightarrow> G g S = G g T" | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 630 | by (blast intro: mono_neutral_cong_left') | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 631 | |
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 632 | lemma mono_neutral_right': "S \<subseteq> T \<Longrightarrow> \<forall>i \<in> T - S. g i = \<^bold>1 \<Longrightarrow> G g T = G g S" | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 633 | by (blast intro!: mono_neutral_left' [symmetric]) | 
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 634 | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 635 | end | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 636 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 637 | |
| 60758 | 638 | subsection \<open>Generalized summation over a set\<close> | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 639 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 640 | context comm_monoid_add | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 641 | begin | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 642 | |
| 64267 | 643 | sublocale sum: comm_monoid_set plus 0 | 
| 70044 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 644 | defines sum = sum.F and sum' = sum.G .. | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 645 | |
| 80932 
261cd8722677
standardize mixfix annotations via "isabelle update -u mixfix_cartouches -l Pure HOL" --- to simplify systematic editing;
 wenzelm parents: 
80765diff
changeset | 646 | abbreviation Sum (\<open>\<Sum>\<close>) | 
| 69767 
d10fafeb93c0
less special syntax: make \<Sum> an ordinary function symbol
 nipkow parents: 
69700diff
changeset | 647 | where "\<Sum> \<equiv> sum (\<lambda>x. x)" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 648 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 649 | end | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 650 | |
| 69593 | 651 | text \<open>Now: lots of fancy syntax. First, \<^term>\<open>sum (\<lambda>x. e) A\<close> is written \<open>\<Sum>x\<in>A. e\<close>.\<close> | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 652 | |
| 61955 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61952diff
changeset | 653 | syntax (ASCII) | 
| 80934 | 654 | "_sum" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b::comm_monoid_add" (\<open>(\<open>indent=3 notation=\<open>binder SUM\<close>\<close>SUM (_/:_)./ _)\<close> [0, 51, 10] 10) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 655 | syntax | 
| 80934 | 656 | "_sum" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b::comm_monoid_add" (\<open>(\<open>indent=2 notation=\<open>binder \<Sum>\<close>\<close>\<Sum>(_/\<in>_)./ _)\<close> [0, 51, 10] 10) | 
| 80763 | 657 | |
| 80760 | 658 | syntax_consts | 
| 659 | "_sum" \<rightleftharpoons> sum | |
| 80763 | 660 | |
| 61799 | 661 | translations \<comment> \<open>Beware of argument permutation!\<close> | 
| 64267 | 662 | "\<Sum>i\<in>A. b" \<rightleftharpoons> "CONST sum (\<lambda>i. b) A" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 663 | |
| 80763 | 664 | |
| 69593 | 665 | text \<open>Instead of \<^term>\<open>\<Sum>x\<in>{x. P}. e\<close> we introduce the shorter \<open>\<Sum>x|P. e\<close>.\<close>
 | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 666 | |
| 61955 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61952diff
changeset | 667 | syntax (ASCII) | 
| 80934 | 668 | "_qsum" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a" (\<open>(\<open>indent=3 notation=\<open>binder SUM Collect\<close>\<close>SUM _ |/ _./ _)\<close> [0, 0, 10] 10) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 669 | syntax | 
| 80934 | 670 | "_qsum" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a" (\<open>(\<open>indent=2 notation=\<open>binder \<Sum> Collect\<close>\<close>\<Sum>_ | (_)./ _)\<close> [0, 0, 10] 10) | 
| 80763 | 671 | |
| 80760 | 672 | syntax_consts | 
| 673 | "_qsum" == sum | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 674 | translations | 
| 64267 | 675 |   "\<Sum>x|P. t" => "CONST sum (\<lambda>x. t) {x. P}"
 | 
| 60758 | 676 | print_translation \<open> | 
| 81150 | 677 | [(\<^const_syntax>\<open>sum\<close>, K (Collect_binder_tr' \<^syntax_const>\<open>_qsum\<close>))] | 
| 60758 | 678 | \<close> | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 679 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 680 | |
| 60758 | 681 | subsubsection \<open>Properties in more restricted classes of structures\<close> | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 682 | |
| 64267 | 683 | lemma sum_Un: | 
| 684 | "finite A \<Longrightarrow> finite B \<Longrightarrow> sum f (A \<union> B) = sum f A + sum f B - sum f (A \<inter> B)" | |
| 63654 | 685 | for f :: "'b \<Rightarrow> 'a::ab_group_add" | 
| 64267 | 686 | by (subst sum.union_inter [symmetric]) (auto simp add: algebra_simps) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 687 | |
| 64267 | 688 | lemma sum_Un2: | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 689 | assumes "finite (A \<union> B)" | 
| 64267 | 690 | shows "sum f (A \<union> B) = sum f (A - B) + sum f (B - A) + sum f (A \<inter> B)" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 691 | proof - | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 692 | have "A \<union> B = A - B \<union> (B - A) \<union> A \<inter> B" | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 693 | by auto | 
| 63654 | 694 | with assms show ?thesis | 
| 64267 | 695 | by simp (subst sum.union_disjoint, auto)+ | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 696 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 697 | |
| 75461 
4c3bc0d2568f
Eliminated two unnecessary inductions
 paulson <lp15@cam.ac.uk> parents: 
75078diff
changeset | 698 | (*Like sum.subset_diff but expressed perhaps more conveniently using subtraction*) | 
| 
4c3bc0d2568f
Eliminated two unnecessary inductions
 paulson <lp15@cam.ac.uk> parents: 
75078diff
changeset | 699 | lemma sum_diff: | 
| 
4c3bc0d2568f
Eliminated two unnecessary inductions
 paulson <lp15@cam.ac.uk> parents: 
75078diff
changeset | 700 | fixes f :: "'b \<Rightarrow> 'a::ab_group_add" | 
| 
4c3bc0d2568f
Eliminated two unnecessary inductions
 paulson <lp15@cam.ac.uk> parents: 
75078diff
changeset | 701 | assumes "finite A" "B \<subseteq> A" | 
| 
4c3bc0d2568f
Eliminated two unnecessary inductions
 paulson <lp15@cam.ac.uk> parents: 
75078diff
changeset | 702 | shows "sum f (A - B) = sum f A - sum f B" | 
| 
4c3bc0d2568f
Eliminated two unnecessary inductions
 paulson <lp15@cam.ac.uk> parents: 
75078diff
changeset | 703 | using sum.subset_diff [of B A f] assms by simp | 
| 
4c3bc0d2568f
Eliminated two unnecessary inductions
 paulson <lp15@cam.ac.uk> parents: 
75078diff
changeset | 704 | |
| 64267 | 705 | lemma sum_diff1: | 
| 63654 | 706 | fixes f :: "'b \<Rightarrow> 'a::ab_group_add" | 
| 707 | assumes "finite A" | |
| 64267 | 708 |   shows "sum f (A - {a}) = (if a \<in> A then sum f A - f a else sum f A)"
 | 
| 75461 
4c3bc0d2568f
Eliminated two unnecessary inductions
 paulson <lp15@cam.ac.uk> parents: 
75078diff
changeset | 709 | using assms by (simp add: sum_diff) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 710 | |
| 70045 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 711 | lemma sum_diff1'_aux: | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 712 | fixes f :: "'a \<Rightarrow> 'b::ab_group_add" | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 713 |   assumes "finite F" "{i \<in> I. f i \<noteq> 0} \<subseteq> F"
 | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 714 |   shows "sum' f (I - {i}) = (if i \<in> I then sum' f I - f i else sum' f I)"
 | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 715 | using assms | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 716 | proof induct | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 717 | case (insert x F) | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 718 |   have 1: "finite {x \<in> I. f x \<noteq> 0} \<Longrightarrow> finite {x \<in> I. x \<noteq> i \<and> f x \<noteq> 0}"
 | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 719 | by (erule rev_finite_subset) auto | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 720 |   have 2: "finite {x \<in> I. x \<noteq> i \<and> f x \<noteq> 0} \<Longrightarrow> finite {x \<in> I. f x \<noteq> 0}"
 | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 721 | apply (drule finite_insert [THEN iffD2]) | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 722 | by (erule rev_finite_subset) auto | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 723 |   have 3: "finite {i \<in> I. f i \<noteq> 0}"
 | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 724 | using finite_subset insert by blast | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 725 | show ?case | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 726 |     using insert sum_diff1 [of "{i \<in> I. f i \<noteq> 0}" f i]
 | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 727 | by (auto simp: sum.G_def 1 2 3 set_diff_eq conj_ac) | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 728 | qed (simp add: sum.G_def) | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 729 | |
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 730 | lemma sum_diff1': | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 731 | fixes f :: "'a \<Rightarrow> 'b::ab_group_add" | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 732 |   assumes "finite {i \<in> I. f i \<noteq> 0}"
 | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 733 |   shows "sum' f (I - {i}) = (if i \<in> I then sum' f I - f i else sum' f I)"
 | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 734 | by (rule sum_diff1'_aux [OF assms order_refl]) | 
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 735 | |
| 64267 | 736 | lemma (in ordered_comm_monoid_add) sum_mono: | 
| 63915 | 737 | "(\<And>i. i\<in>K \<Longrightarrow> f i \<le> g i) \<Longrightarrow> (\<Sum>i\<in>K. f i) \<le> (\<Sum>i\<in>K. g i)" | 
| 738 | by (induct K rule: infinite_finite_induct) (use add_mono in auto) | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 739 | |
| 79945 
ca004ccf2352
New material from a variety of sources (including AFP)
 paulson <lp15@cam.ac.uk> parents: 
79670diff
changeset | 740 | lemma (in ordered_cancel_comm_monoid_add) sum_strict_mono_strong: | 
| 
ca004ccf2352
New material from a variety of sources (including AFP)
 paulson <lp15@cam.ac.uk> parents: 
79670diff
changeset | 741 | assumes "finite A" "a \<in> A" "f a < g a" | 
| 
ca004ccf2352
New material from a variety of sources (including AFP)
 paulson <lp15@cam.ac.uk> parents: 
79670diff
changeset | 742 | and "\<And>x. x \<in> A \<Longrightarrow> f x \<le> g x" | 
| 
ca004ccf2352
New material from a variety of sources (including AFP)
 paulson <lp15@cam.ac.uk> parents: 
79670diff
changeset | 743 | shows "sum f A < sum g A" | 
| 
ca004ccf2352
New material from a variety of sources (including AFP)
 paulson <lp15@cam.ac.uk> parents: 
79670diff
changeset | 744 | proof - | 
| 
ca004ccf2352
New material from a variety of sources (including AFP)
 paulson <lp15@cam.ac.uk> parents: 
79670diff
changeset | 745 |   have "sum f A = f a + sum f (A-{a})"
 | 
| 
ca004ccf2352
New material from a variety of sources (including AFP)
 paulson <lp15@cam.ac.uk> parents: 
79670diff
changeset | 746 | by (simp add: assms sum.remove) | 
| 
ca004ccf2352
New material from a variety of sources (including AFP)
 paulson <lp15@cam.ac.uk> parents: 
79670diff
changeset | 747 |   also have "\<dots> \<le> f a + sum g (A-{a})"
 | 
| 
ca004ccf2352
New material from a variety of sources (including AFP)
 paulson <lp15@cam.ac.uk> parents: 
79670diff
changeset | 748 | using assms by (meson DiffD1 add_left_mono sum_mono) | 
| 
ca004ccf2352
New material from a variety of sources (including AFP)
 paulson <lp15@cam.ac.uk> parents: 
79670diff
changeset | 749 |   also have "\<dots> < g a + sum g (A-{a})"
 | 
| 
ca004ccf2352
New material from a variety of sources (including AFP)
 paulson <lp15@cam.ac.uk> parents: 
79670diff
changeset | 750 | using assms add_less_le_mono by blast | 
| 
ca004ccf2352
New material from a variety of sources (including AFP)
 paulson <lp15@cam.ac.uk> parents: 
79670diff
changeset | 751 | also have "\<dots> = sum g A" | 
| 
ca004ccf2352
New material from a variety of sources (including AFP)
 paulson <lp15@cam.ac.uk> parents: 
79670diff
changeset | 752 | using assms by (intro sum.remove [symmetric]) | 
| 
ca004ccf2352
New material from a variety of sources (including AFP)
 paulson <lp15@cam.ac.uk> parents: 
79670diff
changeset | 753 | finally show ?thesis . | 
| 
ca004ccf2352
New material from a variety of sources (including AFP)
 paulson <lp15@cam.ac.uk> parents: 
79670diff
changeset | 754 | qed | 
| 
ca004ccf2352
New material from a variety of sources (including AFP)
 paulson <lp15@cam.ac.uk> parents: 
79670diff
changeset | 755 | |
| 64267 | 756 | lemma (in strict_ordered_comm_monoid_add) sum_strict_mono: | 
| 63654 | 757 |   assumes "finite A" "A \<noteq> {}"
 | 
| 758 | and "\<And>x. x \<in> A \<Longrightarrow> f x < g x" | |
| 64267 | 759 | shows "sum f A < sum g A" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 760 | using assms | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 761 | proof (induct rule: finite_ne_induct) | 
| 63654 | 762 | case singleton | 
| 763 | then show ?case by simp | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 764 | next | 
| 63654 | 765 | case insert | 
| 766 | then show ?case by (auto simp: add_strict_mono) | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 767 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 768 | |
| 64267 | 769 | lemma sum_strict_mono_ex1: | 
| 62376 
85f38d5f8807
Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
 hoelzl parents: 
61955diff
changeset | 770 | fixes f g :: "'i \<Rightarrow> 'a::ordered_cancel_comm_monoid_add" | 
| 63654 | 771 | assumes "finite A" | 
| 772 | and "\<forall>x\<in>A. f x \<le> g x" | |
| 773 | and "\<exists>a\<in>A. f a < g a" | |
| 64267 | 774 | shows "sum f A < sum g A" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 775 | proof- | 
| 63654 | 776 | from assms(3) obtain a where a: "a \<in> A" "f a < g a" by blast | 
| 64267 | 777 |   have "sum f A = sum f ((A - {a}) \<union> {a})"
 | 
| 63654 | 778 | by(simp add: insert_absorb[OF \<open>a \<in> A\<close>]) | 
| 64267 | 779 |   also have "\<dots> = sum f (A - {a}) + sum f {a}"
 | 
| 780 | using \<open>finite A\<close> by(subst sum.union_disjoint) auto | |
| 781 |   also have "sum f (A - {a}) \<le> sum g (A - {a})"
 | |
| 782 | by (rule sum_mono) (simp add: assms(2)) | |
| 783 |   also from a have "sum f {a} < sum g {a}" by simp
 | |
| 784 |   also have "sum g (A - {a}) + sum g {a} = sum g((A - {a}) \<union> {a})"
 | |
| 785 | using \<open>finite A\<close> by (subst sum.union_disjoint[symmetric]) auto | |
| 786 | also have "\<dots> = sum g A" by (simp add: insert_absorb[OF \<open>a \<in> A\<close>]) | |
| 63654 | 787 | finally show ?thesis | 
| 788 | by (auto simp add: add_right_mono add_strict_left_mono) | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 789 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 790 | |
| 64267 | 791 | lemma sum_mono_inv: | 
| 63561 
fba08009ff3e
add lemmas contributed by Peter Gammie
 Andreas Lochbihler parents: 
63357diff
changeset | 792 | fixes f g :: "'i \<Rightarrow> 'a :: ordered_cancel_comm_monoid_add" | 
| 64267 | 793 | assumes eq: "sum f I = sum g I" | 
| 63561 
fba08009ff3e
add lemmas contributed by Peter Gammie
 Andreas Lochbihler parents: 
63357diff
changeset | 794 | assumes le: "\<And>i. i \<in> I \<Longrightarrow> f i \<le> g i" | 
| 
fba08009ff3e
add lemmas contributed by Peter Gammie
 Andreas Lochbihler parents: 
63357diff
changeset | 795 | assumes i: "i \<in> I" | 
| 
fba08009ff3e
add lemmas contributed by Peter Gammie
 Andreas Lochbihler parents: 
63357diff
changeset | 796 | assumes I: "finite I" | 
| 
fba08009ff3e
add lemmas contributed by Peter Gammie
 Andreas Lochbihler parents: 
63357diff
changeset | 797 | shows "f i = g i" | 
| 63654 | 798 | proof (rule ccontr) | 
| 799 | assume "\<not> ?thesis" | |
| 63561 
fba08009ff3e
add lemmas contributed by Peter Gammie
 Andreas Lochbihler parents: 
63357diff
changeset | 800 | with le[OF i] have "f i < g i" by simp | 
| 63654 | 801 | with i have "\<exists>i\<in>I. f i < g i" .. | 
| 64267 | 802 | from sum_strict_mono_ex1[OF I _ this] le have "sum f I < sum g I" | 
| 63654 | 803 | by blast | 
| 63561 
fba08009ff3e
add lemmas contributed by Peter Gammie
 Andreas Lochbihler parents: 
63357diff
changeset | 804 | with eq show False by simp | 
| 
fba08009ff3e
add lemmas contributed by Peter Gammie
 Andreas Lochbihler parents: 
63357diff
changeset | 805 | qed | 
| 
fba08009ff3e
add lemmas contributed by Peter Gammie
 Andreas Lochbihler parents: 
63357diff
changeset | 806 | |
| 64267 | 807 | lemma member_le_sum: | 
| 63938 | 808 |   fixes f :: "_ \<Rightarrow> 'b::{semiring_1, ordered_comm_monoid_add}"
 | 
| 66112 
0e640e04fc56
New theorems; stronger theorems; tidier theorems. Also some renaming
 paulson <lp15@cam.ac.uk> parents: 
66089diff
changeset | 809 | assumes "i \<in> A" | 
| 
0e640e04fc56
New theorems; stronger theorems; tidier theorems. Also some renaming
 paulson <lp15@cam.ac.uk> parents: 
66089diff
changeset | 810 |     and le: "\<And>x. x \<in> A - {i} \<Longrightarrow> 0 \<le> f x"
 | 
| 63938 | 811 | and "finite A" | 
| 64267 | 812 | shows "f i \<le> sum f A" | 
| 63938 | 813 | proof - | 
| 64267 | 814 |   have "f i \<le> sum f (A \<inter> {i})"
 | 
| 63938 | 815 | by (simp add: assms) | 
| 816 |   also have "... = (\<Sum>x\<in>A. if x \<in> {i} then f x else 0)"
 | |
| 64267 | 817 | using assms sum.inter_restrict by blast | 
| 818 | also have "... \<le> sum f A" | |
| 819 | apply (rule sum_mono) | |
| 63938 | 820 | apply (auto simp: le) | 
| 821 | done | |
| 822 | finally show ?thesis . | |
| 823 | qed | |
| 824 | ||
| 64267 | 825 | lemma sum_negf: "(\<Sum>x\<in>A. - f x) = - (\<Sum>x\<in>A. f x)" | 
| 63654 | 826 | for f :: "'b \<Rightarrow> 'a::ab_group_add" | 
| 63915 | 827 | by (induct A rule: infinite_finite_induct) auto | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 828 | |
| 64267 | 829 | lemma sum_subtractf: "(\<Sum>x\<in>A. f x - g x) = (\<Sum>x\<in>A. f x) - (\<Sum>x\<in>A. g x)" | 
| 63654 | 830 | for f g :: "'b \<Rightarrow>'a::ab_group_add" | 
| 64267 | 831 | using sum.distrib [of f "- g" A] by (simp add: sum_negf) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 832 | |
| 64267 | 833 | lemma sum_subtractf_nat: | 
| 63654 | 834 | "(\<And>x. x \<in> A \<Longrightarrow> g x \<le> f x) \<Longrightarrow> (\<Sum>x\<in>A. f x - g x) = (\<Sum>x\<in>A. f x) - (\<Sum>x\<in>A. g x)" | 
| 835 | for f g :: "'a \<Rightarrow> nat" | |
| 64267 | 836 | by (induct A rule: infinite_finite_induct) (auto simp: sum_mono) | 
| 59416 
fde2659085e1
generalized sum_diff_distrib to setsum_subtractf_nat
 hoelzl parents: 
59010diff
changeset | 837 | |
| 63654 | 838 | context ordered_comm_monoid_add | 
| 839 | begin | |
| 840 | ||
| 65680 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 841 | lemma sum_nonneg: "(\<And>x. x \<in> A \<Longrightarrow> 0 \<le> f x) \<Longrightarrow> 0 \<le> sum f A" | 
| 63915 | 842 | proof (induct A rule: infinite_finite_induct) | 
| 843 | case infinite | |
| 844 | then show ?case by simp | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 845 | next | 
| 63915 | 846 | case empty | 
| 847 | then show ?case by simp | |
| 848 | next | |
| 849 | case (insert x F) | |
| 64267 | 850 | then have "0 + 0 \<le> f x + sum f F" by (blast intro: add_mono) | 
| 63915 | 851 | with insert show ?case by simp | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 852 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 853 | |
| 65680 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 854 | lemma sum_nonpos: "(\<And>x. x \<in> A \<Longrightarrow> f x \<le> 0) \<Longrightarrow> sum f A \<le> 0" | 
| 63915 | 855 | proof (induct A rule: infinite_finite_induct) | 
| 856 | case infinite | |
| 857 | then show ?case by simp | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 858 | next | 
| 63915 | 859 | case empty | 
| 860 | then show ?case by simp | |
| 861 | next | |
| 862 | case (insert x F) | |
| 64267 | 863 | then have "f x + sum f F \<le> 0 + 0" by (blast intro: add_mono) | 
| 63915 | 864 | with insert show ?case by simp | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 865 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 866 | |
| 64267 | 867 | lemma sum_nonneg_eq_0_iff: | 
| 65680 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 868 | "finite A \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> 0 \<le> f x) \<Longrightarrow> sum f A = 0 \<longleftrightarrow> (\<forall>x\<in>A. f x = 0)" | 
| 64267 | 869 | by (induct set: finite) (simp_all add: add_nonneg_eq_0_iff sum_nonneg) | 
| 62376 
85f38d5f8807
Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
 hoelzl parents: 
61955diff
changeset | 870 | |
| 64267 | 871 | lemma sum_nonneg_0: | 
| 62376 
85f38d5f8807
Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
 hoelzl parents: 
61955diff
changeset | 872 | "finite s \<Longrightarrow> (\<And>i. i \<in> s \<Longrightarrow> f i \<ge> 0) \<Longrightarrow> (\<Sum> i \<in> s. f i) = 0 \<Longrightarrow> i \<in> s \<Longrightarrow> f i = 0" | 
| 64267 | 873 | by (simp add: sum_nonneg_eq_0_iff) | 
| 62376 
85f38d5f8807
Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
 hoelzl parents: 
61955diff
changeset | 874 | |
| 64267 | 875 | lemma sum_nonneg_leq_bound: | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 876 | assumes "finite s" "\<And>i. i \<in> s \<Longrightarrow> f i \<ge> 0" "(\<Sum>i \<in> s. f i) = B" "i \<in> s" | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 877 | shows "f i \<le> B" | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 878 | proof - | 
| 63654 | 879 |   from assms have "f i \<le> f i + (\<Sum>i \<in> s - {i}. f i)"
 | 
| 64267 | 880 | by (intro add_increasing2 sum_nonneg) auto | 
| 62376 
85f38d5f8807
Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
 hoelzl parents: 
61955diff
changeset | 881 | also have "\<dots> = B" | 
| 64267 | 882 | using sum.remove[of s i f] assms by simp | 
| 62376 
85f38d5f8807
Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
 hoelzl parents: 
61955diff
changeset | 883 | finally show ?thesis by auto | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 884 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 885 | |
| 64267 | 886 | lemma sum_mono2: | 
| 63654 | 887 | assumes fin: "finite B" | 
| 888 | and sub: "A \<subseteq> B" | |
| 889 | and nn: "\<And>b. b \<in> B-A \<Longrightarrow> 0 \<le> f b" | |
| 64267 | 890 | shows "sum f A \<le> sum f B" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 891 | proof - | 
| 64267 | 892 | have "sum f A \<le> sum f A + sum f (B-A)" | 
| 65680 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 893 | by (auto intro: add_increasing2 [OF sum_nonneg] nn) | 
| 64267 | 894 | also from fin finite_subset[OF sub fin] have "\<dots> = sum f (A \<union> (B-A))" | 
| 895 | by (simp add: sum.union_disjoint del: Un_Diff_cancel) | |
| 63654 | 896 | also from sub have "A \<union> (B-A) = B" by blast | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 897 | finally show ?thesis . | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 898 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 899 | |
| 64267 | 900 | lemma sum_le_included: | 
| 57418 | 901 | assumes "finite s" "finite t" | 
| 902 | and "\<forall>y\<in>t. 0 \<le> g y" "(\<forall>x\<in>s. \<exists>y\<in>t. i y = x \<and> f x \<le> g y)" | |
| 64267 | 903 | shows "sum f s \<le> sum g t" | 
| 57418 | 904 | proof - | 
| 64267 | 905 |   have "sum f s \<le> sum (\<lambda>y. sum g {x. x\<in>t \<and> i x = y}) s"
 | 
| 906 | proof (rule sum_mono) | |
| 63654 | 907 | fix y | 
| 908 | assume "y \<in> s" | |
| 57418 | 909 | with assms obtain z where z: "z \<in> t" "y = i z" "f y \<le> g z" by auto | 
| 64267 | 910 |     with assms show "f y \<le> sum g {x \<in> t. i x = y}" (is "?A y \<le> ?B y")
 | 
| 911 |       using order_trans[of "?A (i z)" "sum g {z}" "?B (i z)", intro]
 | |
| 912 | by (auto intro!: sum_mono2) | |
| 57418 | 913 | qed | 
| 64267 | 914 |   also have "\<dots> \<le> sum (\<lambda>y. sum g {x. x\<in>t \<and> i x = y}) (i ` t)"
 | 
| 915 | using assms(2-4) by (auto intro!: sum_mono2 sum_nonneg) | |
| 916 | also have "\<dots> \<le> sum g t" | |
| 69510 | 917 | using assms by (auto simp: sum.image_gen[symmetric]) | 
| 57418 | 918 | finally show ?thesis . | 
| 919 | qed | |
| 920 | ||
| 63654 | 921 | end | 
| 922 | ||
| 64267 | 923 | lemma (in canonically_ordered_monoid_add) sum_eq_0_iff [simp]: | 
| 924 | "finite F \<Longrightarrow> (sum f F = 0) = (\<forall>a\<in>F. f a = 0)" | |
| 925 | by (intro ballI sum_nonneg_eq_0_iff zero_le) | |
| 62376 
85f38d5f8807
Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
 hoelzl parents: 
61955diff
changeset | 926 | |
| 66936 | 927 | context semiring_0 | 
| 928 | begin | |
| 929 | ||
| 930 | lemma sum_distrib_left: "r * sum f A = (\<Sum>n\<in>A. r * f n)" | |
| 931 | by (induct A rule: infinite_finite_induct) (simp_all add: algebra_simps) | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 932 | |
| 64267 | 933 | lemma sum_distrib_right: "sum f A * r = (\<Sum>n\<in>A. f n * r)" | 
| 66936 | 934 | by (induct A rule: infinite_finite_induct) (simp_all add: algebra_simps) | 
| 935 | ||
| 936 | end | |
| 63654 | 937 | |
| 64267 | 938 | lemma sum_divide_distrib: "sum f A / r = (\<Sum>n\<in>A. f n / r)" | 
| 63654 | 939 | for r :: "'a::field" | 
| 63915 | 940 | proof (induct A rule: infinite_finite_induct) | 
| 941 | case infinite | |
| 942 | then show ?case by simp | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 943 | next | 
| 63915 | 944 | case empty | 
| 945 | then show ?case by simp | |
| 946 | next | |
| 947 | case insert | |
| 948 | then show ?case by (simp add: add_divide_distrib) | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 949 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 950 | |
| 64267 | 951 | lemma sum_abs[iff]: "\<bar>sum f A\<bar> \<le> sum (\<lambda>i. \<bar>f i\<bar>) A" | 
| 63654 | 952 | for f :: "'a \<Rightarrow> 'b::ordered_ab_group_add_abs" | 
| 63915 | 953 | proof (induct A rule: infinite_finite_induct) | 
| 954 | case infinite | |
| 955 | then show ?case by simp | |
| 63654 | 956 | next | 
| 63915 | 957 | case empty | 
| 958 | then show ?case by simp | |
| 959 | next | |
| 960 | case insert | |
| 961 | then show ?case by (auto intro: abs_triangle_ineq order_trans) | |
| 63654 | 962 | qed | 
| 963 | ||
| 64267 | 964 | lemma sum_abs_ge_zero[iff]: "0 \<le> sum (\<lambda>i. \<bar>f i\<bar>) A" | 
| 63654 | 965 | for f :: "'a \<Rightarrow> 'b::ordered_ab_group_add_abs" | 
| 64267 | 966 | by (simp add: sum_nonneg) | 
| 63654 | 967 | |
| 64267 | 968 | lemma abs_sum_abs[simp]: "\<bar>\<Sum>a\<in>A. \<bar>f a\<bar>\<bar> = (\<Sum>a\<in>A. \<bar>f a\<bar>)" | 
| 63654 | 969 | for f :: "'a \<Rightarrow> 'b::ordered_ab_group_add_abs" | 
| 63915 | 970 | proof (induct A rule: infinite_finite_induct) | 
| 971 | case infinite | |
| 972 | then show ?case by simp | |
| 973 | next | |
| 974 | case empty | |
| 975 | then show ?case by simp | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 976 | next | 
| 63915 | 977 | case (insert a A) | 
| 978 | then have "\<bar>\<Sum>a\<in>insert a A. \<bar>f a\<bar>\<bar> = \<bar>\<bar>f a\<bar> + (\<Sum>a\<in>A. \<bar>f a\<bar>)\<bar>" by simp | |
| 979 | also from insert have "\<dots> = \<bar>\<bar>f a\<bar> + \<bar>\<Sum>a\<in>A. \<bar>f a\<bar>\<bar>\<bar>" by simp | |
| 980 | also have "\<dots> = \<bar>f a\<bar> + \<bar>\<Sum>a\<in>A. \<bar>f a\<bar>\<bar>" by (simp del: abs_of_nonneg) | |
| 981 | also from insert have "\<dots> = (\<Sum>a\<in>insert a A. \<bar>f a\<bar>)" by simp | |
| 982 | finally show ?case . | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 983 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 984 | |
| 64267 | 985 | lemma sum_product: | 
| 63654 | 986 | fixes f :: "'a \<Rightarrow> 'b::semiring_0" | 
| 64267 | 987 | shows "sum f A * sum g B = (\<Sum>i\<in>A. \<Sum>j\<in>B. f i * g j)" | 
| 66804 
3f9bb52082c4
avoid name clashes on interpretation of abstract locales
 haftmann parents: 
66364diff
changeset | 988 | by (simp add: sum_distrib_left sum_distrib_right) (rule sum.swap) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 989 | |
| 64267 | 990 | lemma sum_mult_sum_if_inj: | 
| 63654 | 991 | fixes f :: "'a \<Rightarrow> 'b::semiring_0" | 
| 992 | shows "inj_on (\<lambda>(a, b). f a * g b) (A \<times> B) \<Longrightarrow> | |
| 64267 | 993 |     sum f A * sum g B = sum id {f a * g b |a b. a \<in> A \<and> b \<in> B}"
 | 
| 994 | by(auto simp: sum_product sum.cartesian_product intro!: sum.reindex_cong[symmetric]) | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 995 | |
| 64267 | 996 | lemma sum_SucD: "sum f A = Suc n \<Longrightarrow> \<exists>a\<in>A. 0 < f a" | 
| 63915 | 997 | by (induct A rule: infinite_finite_induct) auto | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 998 | |
| 64267 | 999 | lemma sum_eq_Suc0_iff: | 
| 1000 | "finite A \<Longrightarrow> sum f A = Suc 0 \<longleftrightarrow> (\<exists>a\<in>A. f a = Suc 0 \<and> (\<forall>b\<in>A. a \<noteq> b \<longrightarrow> f b = 0))" | |
| 63915 | 1001 | by (induct A rule: finite_induct) (auto simp add: add_is_1) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1002 | |
| 64267 | 1003 | lemmas sum_eq_1_iff = sum_eq_Suc0_iff[simplified One_nat_def[symmetric]] | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1004 | |
| 64267 | 1005 | lemma sum_Un_nat: | 
| 1006 | "finite A \<Longrightarrow> finite B \<Longrightarrow> sum f (A \<union> B) = sum f A + sum f B - sum f (A \<inter> B)" | |
| 63654 | 1007 | for f :: "'a \<Rightarrow> nat" | 
| 61799 | 1008 | \<comment> \<open>For the natural numbers, we have subtraction.\<close> | 
| 64267 | 1009 | by (subst sum.union_inter [symmetric]) (auto simp: algebra_simps) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1010 | |
| 64267 | 1011 | lemma sum_diff1_nat: "sum f (A - {a}) = (if a \<in> A then sum f A - f a else sum f A)"
 | 
| 63654 | 1012 | for f :: "'a \<Rightarrow> nat" | 
| 63915 | 1013 | proof (induct A rule: infinite_finite_induct) | 
| 1014 | case infinite | |
| 1015 | then show ?case by simp | |
| 1016 | next | |
| 1017 | case empty | |
| 1018 | then show ?case by simp | |
| 1019 | next | |
| 75669 
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
 Fabian Huch <huch@in.tum.de> parents: 
75461diff
changeset | 1020 | case (insert x F) | 
| 63915 | 1021 | then show ?case | 
| 75669 
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
 Fabian Huch <huch@in.tum.de> parents: 
75461diff
changeset | 1022 | proof (cases "a \<in> F") | 
| 
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
 Fabian Huch <huch@in.tum.de> parents: 
75461diff
changeset | 1023 | case True | 
| 
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
 Fabian Huch <huch@in.tum.de> parents: 
75461diff
changeset | 1024 | then have "\<exists>B. F = insert a B \<and> a \<notin> B" | 
| 
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
 Fabian Huch <huch@in.tum.de> parents: 
75461diff
changeset | 1025 | by (auto simp: mk_disjoint_insert) | 
| 
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
 Fabian Huch <huch@in.tum.de> parents: 
75461diff
changeset | 1026 | then show ?thesis using insert | 
| 
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
 Fabian Huch <huch@in.tum.de> parents: 
75461diff
changeset | 1027 | by (auto simp: insert_Diff_if) | 
| 
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
 Fabian Huch <huch@in.tum.de> parents: 
75461diff
changeset | 1028 | qed (auto) | 
| 63654 | 1029 | qed | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1030 | |
| 64267 | 1031 | lemma sum_diff_nat: | 
| 63654 | 1032 | fixes f :: "'a \<Rightarrow> nat" | 
| 1033 | assumes "finite B" and "B \<subseteq> A" | |
| 64267 | 1034 | shows "sum f (A - B) = sum f A - sum f B" | 
| 63654 | 1035 | using assms | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1036 | proof induct | 
| 63654 | 1037 | case empty | 
| 1038 | then show ?case by simp | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1039 | next | 
| 63654 | 1040 | case (insert x F) | 
| 64267 | 1041 | note IH = \<open>F \<subseteq> A \<Longrightarrow> sum f (A - F) = sum f A - sum f F\<close> | 
| 63654 | 1042 | from \<open>x \<notin> F\<close> \<open>insert x F \<subseteq> A\<close> have "x \<in> A - F" by simp | 
| 64267 | 1043 |   then have A: "sum f ((A - F) - {x}) = sum f (A - F) - f x"
 | 
| 1044 | by (simp add: sum_diff1_nat) | |
| 63654 | 1045 | from \<open>insert x F \<subseteq> A\<close> have "F \<subseteq> A" by simp | 
| 64267 | 1046 | with IH have "sum f (A - F) = sum f A - sum f F" by simp | 
| 1047 |   with A have B: "sum f ((A - F) - {x}) = sum f A - sum f F - f x"
 | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1048 | by simp | 
| 63654 | 1049 |   from \<open>x \<notin> F\<close> have "A - insert x F = (A - F) - {x}" by auto
 | 
| 64267 | 1050 | with B have C: "sum f (A - insert x F) = sum f A - sum f F - f x" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1051 | by simp | 
| 64267 | 1052 | from \<open>finite F\<close> \<open>x \<notin> F\<close> have "sum f (insert x F) = sum f F + f x" | 
| 63654 | 1053 | by simp | 
| 64267 | 1054 | with C have "sum f (A - insert x F) = sum f A - sum f (insert x F)" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1055 | by simp | 
| 63654 | 1056 | then show ?case by simp | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1057 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1058 | |
| 64267 | 1059 | lemma sum_comp_morphism: | 
| 1060 | "h 0 = 0 \<Longrightarrow> (\<And>x y. h (x + y) = h x + h y) \<Longrightarrow> sum (h \<circ> g) A = h (sum g A)" | |
| 63915 | 1061 | by (induct A rule: infinite_finite_induct) simp_all | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1062 | |
| 64267 | 1063 | lemma (in comm_semiring_1) dvd_sum: "(\<And>a. a \<in> A \<Longrightarrow> d dvd f a) \<Longrightarrow> d dvd sum f A" | 
| 59010 | 1064 | by (induct A rule: infinite_finite_induct) simp_all | 
| 1065 | ||
| 64267 | 1066 | lemma (in ordered_comm_monoid_add) sum_pos: | 
| 1067 |   "finite I \<Longrightarrow> I \<noteq> {} \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> 0 < f i) \<Longrightarrow> 0 < sum f I"
 | |
| 62377 
ace69956d018
moved more proofs to ordered_comm_monoid_add; introduced strict_ordered_ab_semigroup/comm_monoid_add
 hoelzl parents: 
62376diff
changeset | 1068 | by (induct I rule: finite_ne_induct) (auto intro: add_pos_pos) | 
| 
ace69956d018
moved more proofs to ordered_comm_monoid_add; introduced strict_ordered_ab_semigroup/comm_monoid_add
 hoelzl parents: 
62376diff
changeset | 1069 | |
| 64267 | 1070 | lemma (in ordered_comm_monoid_add) sum_pos2: | 
| 62377 
ace69956d018
moved more proofs to ordered_comm_monoid_add; introduced strict_ordered_ab_semigroup/comm_monoid_add
 hoelzl parents: 
62376diff
changeset | 1071 | assumes I: "finite I" "i \<in> I" "0 < f i" "\<And>i. i \<in> I \<Longrightarrow> 0 \<le> f i" | 
| 64267 | 1072 | shows "0 < sum f I" | 
| 60974 
6a6f15d8fbc4
New material and fixes related to the forthcoming Stone-Weierstrass development
 paulson <lp15@cam.ac.uk> parents: 
60758diff
changeset | 1073 | proof - | 
| 64267 | 1074 |   have "0 < f i + sum f (I - {i})"
 | 
| 1075 | using assms by (intro add_pos_nonneg sum_nonneg) auto | |
| 1076 | also have "\<dots> = sum f I" | |
| 1077 | using assms by (simp add: sum.remove) | |
| 60974 
6a6f15d8fbc4
New material and fixes related to the forthcoming Stone-Weierstrass development
 paulson <lp15@cam.ac.uk> parents: 
60758diff
changeset | 1078 | finally show ?thesis . | 
| 
6a6f15d8fbc4
New material and fixes related to the forthcoming Stone-Weierstrass development
 paulson <lp15@cam.ac.uk> parents: 
60758diff
changeset | 1079 | qed | 
| 
6a6f15d8fbc4
New material and fixes related to the forthcoming Stone-Weierstrass development
 paulson <lp15@cam.ac.uk> parents: 
60758diff
changeset | 1080 | |
| 72094 | 1081 | lemma sum_strict_mono2: | 
| 1082 | fixes f :: "'a \<Rightarrow> 'b::ordered_cancel_comm_monoid_add" | |
| 1083 | assumes "finite B" "A \<subseteq> B" "b \<in> B-A" "f b > 0" and "\<And>x. x \<in> B \<Longrightarrow> f x \<ge> 0" | |
| 1084 | shows "sum f A < sum f B" | |
| 1085 | proof - | |
| 1086 |   have "B - A \<noteq> {}"
 | |
| 1087 | using assms(3) by blast | |
| 1088 | have "sum f (B-A) > 0" | |
| 1089 | by (rule sum_pos2) (use assms in auto) | |
| 1090 | moreover have "sum f B = sum f (B-A) + sum f A" | |
| 1091 | by (rule sum.subset_diff) (use assms in auto) | |
| 1092 | ultimately show ?thesis | |
| 1093 | using add_strict_increasing by auto | |
| 1094 | qed | |
| 1095 | ||
| 64267 | 1096 | lemma sum_cong_Suc: | 
| 61524 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61378diff
changeset | 1097 | assumes "0 \<notin> A" "\<And>x. Suc x \<in> A \<Longrightarrow> f (Suc x) = g (Suc x)" | 
| 64267 | 1098 | shows "sum f A = sum g A" | 
| 1099 | proof (rule sum.cong) | |
| 63654 | 1100 | fix x | 
| 1101 | assume "x \<in> A" | |
| 1102 | with assms(1) show "f x = g x" | |
| 1103 | by (cases x) (auto intro!: assms(2)) | |
| 61524 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61378diff
changeset | 1104 | qed simp_all | 
| 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61378diff
changeset | 1105 | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1106 | |
| 69593 | 1107 | subsubsection \<open>Cardinality as special case of \<^const>\<open>sum\<close>\<close> | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1108 | |
| 64267 | 1109 | lemma card_eq_sum: "card A = sum (\<lambda>x. 1) A" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1110 | proof - | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1111 | have "plus \<circ> (\<lambda>_. Suc 0) = (\<lambda>_. Suc)" | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1112 | by (simp add: fun_eq_iff) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1113 | then have "Finite_Set.fold (plus \<circ> (\<lambda>_. Suc 0)) = Finite_Set.fold (\<lambda>_. Suc)" | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1114 | by (rule arg_cong) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1115 | then have "Finite_Set.fold (plus \<circ> (\<lambda>_. Suc 0)) 0 A = Finite_Set.fold (\<lambda>_. Suc) 0 A" | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1116 | by (blast intro: fun_cong) | 
| 63654 | 1117 | then show ?thesis | 
| 64267 | 1118 | by (simp add: card.eq_fold sum.eq_fold) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1119 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1120 | |
| 66936 | 1121 | context semiring_1 | 
| 1122 | begin | |
| 1123 | ||
| 1124 | lemma sum_constant [simp]: | |
| 1125 | "(\<Sum>x \<in> A. y) = of_nat (card A) * y" | |
| 1126 | by (induct A rule: infinite_finite_induct) (simp_all add: algebra_simps) | |
| 1127 | ||
| 73535 | 1128 | context | 
| 1129 | fixes A | |
| 1130 | assumes \<open>finite A\<close> | |
| 1131 | begin | |
| 1132 | ||
| 1133 | lemma sum_of_bool_eq [simp]: | |
| 1134 |   \<open>(\<Sum>x \<in> A. of_bool (P x)) = of_nat (card (A \<inter> {x. P x}))\<close> if \<open>finite A\<close>
 | |
| 1135 | using \<open>finite A\<close> by induction simp_all | |
| 1136 | ||
| 1137 | lemma sum_mult_of_bool_eq [simp]: | |
| 1138 |   \<open>(\<Sum>x \<in> A. f x * of_bool (P x)) = (\<Sum>x \<in> (A \<inter> {x. P x}). f x)\<close>
 | |
| 1139 | by (rule sum.mono_neutral_cong) (use \<open>finite A\<close> in auto) | |
| 1140 | ||
| 1141 | lemma sum_of_bool_mult_eq [simp]: | |
| 1142 |   \<open>(\<Sum>x \<in> A. of_bool (P x) * f x) = (\<Sum>x \<in> (A \<inter> {x. P x}). f x)\<close>
 | |
| 1143 | by (rule sum.mono_neutral_cong) (use \<open>finite A\<close> in auto) | |
| 1144 | ||
| 1145 | end | |
| 1146 | ||
| 66936 | 1147 | end | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1148 | |
| 64267 | 1149 | lemma sum_Suc: "sum (\<lambda>x. Suc(f x)) A = sum f A + card A" | 
| 1150 | using sum.distrib[of f "\<lambda>_. 1" A] by simp | |
| 58349 | 1151 | |
| 64267 | 1152 | lemma sum_bounded_above: | 
| 63654 | 1153 |   fixes K :: "'a::{semiring_1,ordered_comm_monoid_add}"
 | 
| 1154 | assumes le: "\<And>i. i\<in>A \<Longrightarrow> f i \<le> K" | |
| 64267 | 1155 | shows "sum f A \<le> of_nat (card A) * K" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1156 | proof (cases "finite A") | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1157 | case True | 
| 63654 | 1158 | then show ?thesis | 
| 64267 | 1159 | using le sum_mono[where K=A and g = "\<lambda>x. K"] by simp | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1160 | next | 
| 63654 | 1161 | case False | 
| 1162 | then show ?thesis by simp | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1163 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1164 | |
| 69144 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1165 | lemma sum_bounded_above_divide: | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1166 | fixes K :: "'a::linordered_field" | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1167 |   assumes le: "\<And>i. i\<in>A \<Longrightarrow> f i \<le> K / of_nat (card A)" and fin: "finite A" "A \<noteq> {}"
 | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1168 | shows "sum f A \<le> K" | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1169 | using sum_bounded_above [of A f "K / of_nat (card A)", OF le] fin by simp | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1170 | |
| 64267 | 1171 | lemma sum_bounded_above_strict: | 
| 63654 | 1172 |   fixes K :: "'a::{ordered_cancel_comm_monoid_add,semiring_1}"
 | 
| 1173 | assumes "\<And>i. i\<in>A \<Longrightarrow> f i < K" "card A > 0" | |
| 64267 | 1174 | shows "sum f A < of_nat (card A) * K" | 
| 1175 | using assms sum_strict_mono[where A=A and g = "\<lambda>x. K"] | |
| 63654 | 1176 | by (simp add: card_gt_0_iff) | 
| 60974 
6a6f15d8fbc4
New material and fixes related to the forthcoming Stone-Weierstrass development
 paulson <lp15@cam.ac.uk> parents: 
60758diff
changeset | 1177 | |
| 64267 | 1178 | lemma sum_bounded_below: | 
| 63654 | 1179 |   fixes K :: "'a::{semiring_1,ordered_comm_monoid_add}"
 | 
| 1180 | assumes le: "\<And>i. i\<in>A \<Longrightarrow> K \<le> f i" | |
| 64267 | 1181 | shows "of_nat (card A) * K \<le> sum f A" | 
| 60974 
6a6f15d8fbc4
New material and fixes related to the forthcoming Stone-Weierstrass development
 paulson <lp15@cam.ac.uk> parents: 
60758diff
changeset | 1182 | proof (cases "finite A") | 
| 
6a6f15d8fbc4
New material and fixes related to the forthcoming Stone-Weierstrass development
 paulson <lp15@cam.ac.uk> parents: 
60758diff
changeset | 1183 | case True | 
| 63654 | 1184 | then show ?thesis | 
| 64267 | 1185 | using le sum_mono[where K=A and f = "\<lambda>x. K"] by simp | 
| 60974 
6a6f15d8fbc4
New material and fixes related to the forthcoming Stone-Weierstrass development
 paulson <lp15@cam.ac.uk> parents: 
60758diff
changeset | 1186 | next | 
| 63654 | 1187 | case False | 
| 1188 | then show ?thesis by simp | |
| 60974 
6a6f15d8fbc4
New material and fixes related to the forthcoming Stone-Weierstrass development
 paulson <lp15@cam.ac.uk> parents: 
60758diff
changeset | 1189 | qed | 
| 
6a6f15d8fbc4
New material and fixes related to the forthcoming Stone-Weierstrass development
 paulson <lp15@cam.ac.uk> parents: 
60758diff
changeset | 1190 | |
| 69144 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1191 | lemma convex_sum_bound_le: | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1192 | fixes x :: "'a \<Rightarrow> 'b::linordered_idom" | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1193 | assumes 0: "\<And>i. i \<in> I \<Longrightarrow> 0 \<le> x i" and 1: "sum x I = 1" | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1194 | and \<delta>: "\<And>i. i \<in> I \<Longrightarrow> \<bar>a i - b\<bar> \<le> \<delta>" | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1195 | shows "\<bar>(\<Sum>i\<in>I. a i * x i) - b\<bar> \<le> \<delta>" | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1196 | proof - | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1197 | have [simp]: "(\<Sum>i\<in>I. c * x i) = c" for c | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1198 | by (simp flip: sum_distrib_left 1) | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1199 | then have "\<bar>(\<Sum>i\<in>I. a i * x i) - b\<bar> = \<bar>\<Sum>i\<in>I. (a i - b) * x i\<bar>" | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1200 | by (simp add: sum_subtractf left_diff_distrib) | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1201 | also have "\<dots> \<le> (\<Sum>i\<in>I. \<bar>(a i - b) * x i\<bar>)" | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1202 | using abs_abs abs_of_nonneg by blast | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1203 | also have "\<dots> \<le> (\<Sum>i\<in>I. \<bar>(a i - b)\<bar> * x i)" | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1204 | by (simp add: abs_mult 0) | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1205 | also have "\<dots> \<le> (\<Sum>i\<in>I. \<delta> * x i)" | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1206 | by (rule sum_mono) (use \<delta> "0" mult_right_mono in blast) | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1207 | also have "\<dots> = \<delta>" | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1208 | by simp | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1209 | finally show ?thesis . | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1210 | qed | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1211 | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1212 | lemma card_UN_disjoint: | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1213 | assumes "finite I" and "\<forall>i\<in>I. finite (A i)" | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1214 |     and "\<forall>i\<in>I. \<forall>j\<in>I. i \<noteq> j \<longrightarrow> A i \<inter> A j = {}"
 | 
| 69275 | 1215 | shows "card (\<Union>(A ` I)) = (\<Sum>i\<in>I. card(A i))" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1216 | proof - | 
| 63654 | 1217 | have "(\<Sum>i\<in>I. card (A i)) = (\<Sum>i\<in>I. \<Sum>x\<in>A i. 1)" | 
| 1218 | by simp | |
| 1219 | with assms show ?thesis | |
| 64267 | 1220 | by (simp add: card_eq_sum sum.UNION_disjoint del: sum_constant) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1221 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1222 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1223 | lemma card_Union_disjoint: | 
| 68975 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1224 | assumes "pairwise disjnt C" and fin: "\<And>A. A \<in> C \<Longrightarrow> finite A" | 
| 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1225 | shows "card (\<Union>C) = sum card C" | 
| 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1226 | proof (cases "finite C") | 
| 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1227 | case True | 
| 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1228 | then show ?thesis | 
| 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1229 | using card_UN_disjoint [OF True, of "\<lambda>x. x"] assms | 
| 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1230 | by (simp add: disjnt_def fin pairwise_def) | 
| 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1231 | next | 
| 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1232 | case False | 
| 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1233 | then show ?thesis | 
| 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1234 | using assms card_eq_0_iff finite_UnionD by fastforce | 
| 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1235 | qed | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1236 | |
| 75078 
ec86cb2418e1
an assortment of new or stronger lemmas
 paulson <lp15@cam.ac.uk> parents: 
74979diff
changeset | 1237 | lemma card_Union_le_sum_card_weak: | 
| 71356 | 1238 | fixes U :: "'a set set" | 
| 1239 | assumes "\<forall>u \<in> U. finite u" | |
| 1240 | shows "card (\<Union>U) \<le> sum card U" | |
| 1241 | proof (cases "finite U") | |
| 1242 | case False | |
| 1243 | then show "card (\<Union>U) \<le> sum card U" | |
| 1244 | using card_eq_0_iff finite_UnionD by auto | |
| 1245 | next | |
| 1246 | case True | |
| 1247 | then show "card (\<Union>U) \<le> sum card U" | |
| 1248 | proof (induct U rule: finite_induct) | |
| 1249 | case empty | |
| 1250 | then show ?case by auto | |
| 1251 | next | |
| 1252 | case (insert x F) | |
| 1253 | then have "card(\<Union>(insert x F)) \<le> card(x) + card (\<Union>F)" using card_Un_le by auto | |
| 1254 | also have "... \<le> card(x) + sum card F" using insert.hyps by auto | |
| 1255 | also have "... = sum card (insert x F)" using sum.insert_if and insert.hyps by auto | |
| 1256 | finally show ?case . | |
| 1257 | qed | |
| 1258 | qed | |
| 1259 | ||
| 75078 
ec86cb2418e1
an assortment of new or stronger lemmas
 paulson <lp15@cam.ac.uk> parents: 
74979diff
changeset | 1260 | lemma card_Union_le_sum_card: | 
| 
ec86cb2418e1
an assortment of new or stronger lemmas
 paulson <lp15@cam.ac.uk> parents: 
74979diff
changeset | 1261 | fixes U :: "'a set set" | 
| 
ec86cb2418e1
an assortment of new or stronger lemmas
 paulson <lp15@cam.ac.uk> parents: 
74979diff
changeset | 1262 | shows "card (\<Union>U) \<le> sum card U" | 
| 
ec86cb2418e1
an assortment of new or stronger lemmas
 paulson <lp15@cam.ac.uk> parents: 
74979diff
changeset | 1263 | by (metis Union_upper card.infinite card_Union_le_sum_card_weak finite_subset zero_le) | 
| 
ec86cb2418e1
an assortment of new or stronger lemmas
 paulson <lp15@cam.ac.uk> parents: 
74979diff
changeset | 1264 | |
| 70723 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70128diff
changeset | 1265 | lemma card_UN_le: | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70128diff
changeset | 1266 | assumes "finite I" | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70128diff
changeset | 1267 | shows "card(\<Union>i\<in>I. A i) \<le> (\<Sum>i\<in>I. card(A i))" | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70128diff
changeset | 1268 | using assms | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70128diff
changeset | 1269 | proof induction | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70128diff
changeset | 1270 | case (insert i I) | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70128diff
changeset | 1271 | then show ?case | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70128diff
changeset | 1272 | using card_Un_le nat_add_left_cancel_le by (force intro: order_trans) | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70128diff
changeset | 1273 | qed auto | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70128diff
changeset | 1274 | |
| 74979 | 1275 | lemma card_quotient_disjoint: | 
| 1276 |   assumes "finite A" "inj_on (\<lambda>x. {x} // r) A"
 | |
| 1277 | shows "card (A//r) = card A" | |
| 1278 | proof - | |
| 1279 |   have "\<forall>i\<in>A. \<forall>j\<in>A. i \<noteq> j \<longrightarrow> r `` {j} \<noteq> r `` {i}"
 | |
| 1280 | using assms by (fastforce simp add: quotient_def inj_on_def) | |
| 1281 | with assms show ?thesis | |
| 1282 | by (simp add: quotient_def card_UN_disjoint) | |
| 1283 | qed | |
| 1284 | ||
| 64267 | 1285 | lemma sum_multicount_gen: | 
| 57418 | 1286 |   assumes "finite s" "finite t" "\<forall>j\<in>t. (card {i\<in>s. R i j} = k j)"
 | 
| 64267 | 1287 |   shows "sum (\<lambda>i. (card {j\<in>t. R i j})) s = sum k t"
 | 
| 63654 | 1288 | (is "?l = ?r") | 
| 57418 | 1289 | proof- | 
| 64267 | 1290 |   have "?l = sum (\<lambda>i. sum (\<lambda>x.1) {j\<in>t. R i j}) s"
 | 
| 63654 | 1291 | by auto | 
| 1292 | also have "\<dots> = ?r" | |
| 66804 
3f9bb52082c4
avoid name clashes on interpretation of abstract locales
 haftmann parents: 
66364diff
changeset | 1293 | unfolding sum.swap_restrict [OF assms(1-2)] | 
| 57418 | 1294 | using assms(3) by auto | 
| 1295 | finally show ?thesis . | |
| 1296 | qed | |
| 1297 | ||
| 64267 | 1298 | lemma sum_multicount: | 
| 57418 | 1299 |   assumes "finite S" "finite T" "\<forall>j\<in>T. (card {i\<in>S. R i j} = k)"
 | 
| 64267 | 1300 |   shows "sum (\<lambda>i. card {j\<in>T. R i j}) S = k * card T" (is "?l = ?r")
 | 
| 57418 | 1301 | proof- | 
| 64267 | 1302 | have "?l = sum (\<lambda>i. k) T" | 
| 1303 | by (rule sum_multicount_gen) (auto simp: assms) | |
| 57512 
cc97b347b301
reduced name variants for assoc and commute on plus and mult
 haftmann parents: 
57418diff
changeset | 1304 | also have "\<dots> = ?r" by (simp add: mult.commute) | 
| 57418 | 1305 | finally show ?thesis by auto | 
| 1306 | qed | |
| 1307 | ||
| 67511 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1308 | lemma sum_card_image: | 
| 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1309 | assumes "finite A" | 
| 68975 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1310 | assumes "pairwise (\<lambda>s t. disjnt (f s) (f t)) A" | 
| 67511 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1311 | shows "sum card (f ` A) = sum (\<lambda>a. card (f a)) A" | 
| 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1312 | using assms | 
| 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1313 | proof (induct A) | 
| 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1314 | case (insert a A) | 
| 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1315 | show ?case | 
| 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1316 | proof cases | 
| 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1317 |     assume "f a = {}"
 | 
| 68975 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1318 | with insert show ?case | 
| 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1319 | by (subst sum.mono_neutral_right[where S="f ` A"]) (auto simp: pairwise_insert) | 
| 67511 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1320 | next | 
| 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1321 |     assume "f a \<noteq> {}"
 | 
| 68975 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1322 | then have "sum card (insert (f a) (f ` A)) = card (f a) + sum card (f ` A)" | 
| 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1323 | using insert | 
| 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1324 | by (subst sum.insert) (auto simp: pairwise_insert) | 
| 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1325 | with insert show ?case by (simp add: pairwise_insert) | 
| 67511 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1326 | qed | 
| 68975 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1327 | qed simp | 
| 67511 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1328 | |
| 74979 | 1329 | text \<open>By Jakub Kądziołka:\<close> | 
| 1330 | ||
| 1331 | lemma sum_fun_comp: | |
| 1332 | assumes "finite S" "finite R" "g ` S \<subseteq> R" | |
| 1333 |   shows "(\<Sum>x \<in> S. f (g x)) = (\<Sum>y \<in> R. of_nat (card {x \<in> S. g x = y}) * f y)"
 | |
| 1334 | proof - | |
| 1335 | let ?r = "relation_of (\<lambda>p q. g p = g q) S" | |
| 1336 | have eqv: "equiv S ?r" | |
| 1337 | unfolding relation_of_def by (auto intro: comp_equivI) | |
| 1338 | have finite: "C \<in> S//?r \<Longrightarrow> finite C" for C | |
| 1339 | by (fact finite_equiv_class[OF `finite S` equiv_type[OF `equiv S ?r`]]) | |
| 1340 |   have disjoint: "A \<in> S//?r \<Longrightarrow> B \<in> S//?r \<Longrightarrow> A \<noteq> B \<Longrightarrow> A \<inter> B = {}" for A B
 | |
| 1341 | using eqv quotient_disj by blast | |
| 1342 | ||
| 1343 |   let ?cls = "\<lambda>y. {x \<in> S. y = g x}"
 | |
| 1344 | have quot_as_img: "S//?r = ?cls ` g ` S" | |
| 1345 | by (auto simp add: relation_of_def quotient_def) | |
| 1346 | have cls_inj: "inj_on ?cls (g ` S)" | |
| 1347 | by (auto intro: inj_onI) | |
| 1348 | ||
| 1349 | have rest_0: "(\<Sum>y \<in> R - g ` S. of_nat (card (?cls y)) * f y) = 0" | |
| 1350 | proof - | |
| 1351 | have "of_nat (card (?cls y)) * f y = 0" if asm: "y \<in> R - g ` S" for y | |
| 1352 | proof - | |
| 1353 |       from asm have *: "?cls y = {}" by auto
 | |
| 1354 | show ?thesis unfolding * by simp | |
| 1355 | qed | |
| 1356 | thus ?thesis by simp | |
| 1357 | qed | |
| 1358 | ||
| 1359 | have "(\<Sum>x \<in> S. f (g x)) = (\<Sum>C \<in> S//?r. \<Sum>x \<in> C. f (g x))" | |
| 1360 | using eqv finite disjoint | |
| 1361 | by (simp flip: sum.Union_disjoint[simplified] add: Union_quotient) | |
| 1362 | also have "... = (\<Sum>y \<in> g ` S. \<Sum>x \<in> ?cls y. f (g x))" | |
| 1363 | unfolding quot_as_img by (simp add: sum.reindex[OF cls_inj]) | |
| 1364 | also have "... = (\<Sum>y \<in> g ` S. \<Sum>x \<in> ?cls y. f y)" | |
| 1365 | by auto | |
| 1366 | also have "... = (\<Sum>y \<in> g ` S. of_nat (card (?cls y)) * f y)" | |
| 1367 | by (simp flip: sum_constant) | |
| 1368 | also have "... = (\<Sum>y \<in> R. of_nat (card (?cls y)) * f y)" | |
| 1369 | using rest_0 by (simp add: sum.subset_diff[OF \<open>g ` S \<subseteq> R\<close> \<open>finite R\<close>]) | |
| 1370 | finally show ?thesis | |
| 1371 | by (simp add: eq_commute) | |
| 1372 | qed | |
| 1373 | ||
| 1374 | ||
| 68975 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1375 | |
| 60758 | 1376 | subsubsection \<open>Cardinality of products\<close> | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1377 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1378 | lemma card_SigmaI [simp]: | 
| 63654 | 1379 | "finite A \<Longrightarrow> \<forall>a\<in>A. finite (B a) \<Longrightarrow> card (SIGMA x: A. B x) = (\<Sum>a\<in>A. card (B a))" | 
| 64267 | 1380 | by (simp add: card_eq_sum sum.Sigma del: sum_constant) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1381 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1382 | (* | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1383 | lemma SigmaI_insert: "y \<notin> A ==> | 
| 61943 | 1384 |   (SIGMA x:(insert y A). B x) = (({y} \<times> (B y)) \<union> (SIGMA x: A. B x))"
 | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1385 | by auto | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1386 | *) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1387 | |
| 63654 | 1388 | lemma card_cartesian_product: "card (A \<times> B) = card A * card B" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1389 | by (cases "finite A \<and> finite B") | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1390 | (auto simp add: card_eq_0_iff dest: finite_cartesian_productD1 finite_cartesian_productD2) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1391 | |
| 63654 | 1392 | lemma card_cartesian_product_singleton:  "card ({x} \<times> A) = card A"
 | 
| 1393 | by (simp add: card_cartesian_product) | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1394 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1395 | |
| 60758 | 1396 | subsection \<open>Generalized product over a set\<close> | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1397 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1398 | context comm_monoid_mult | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1399 | begin | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1400 | |
| 64272 | 1401 | sublocale prod: comm_monoid_set times 1 | 
| 70044 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 1402 | defines prod = prod.F and prod' = prod.G .. | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1403 | |
| 81140 
e66172629fcc
uniform \<Sum> and \<Prod> syntax, following d10fafeb93c0;
 wenzelm parents: 
81125diff
changeset | 1404 | abbreviation Prod (\<open>\<Prod>\<close>) | 
| 
e66172629fcc
uniform \<Sum> and \<Prod> syntax, following d10fafeb93c0;
 wenzelm parents: 
81125diff
changeset | 1405 | where "\<Prod> \<equiv> prod (\<lambda>x. x)" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1406 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1407 | end | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1408 | |
| 61955 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61952diff
changeset | 1409 | syntax (ASCII) | 
| 80934 | 1410 | "_prod" :: "pttrn => 'a set => 'b => 'b::comm_monoid_mult" (\<open>(\<open>indent=4 notation=\<open>binder PROD\<close>\<close>PROD (_/:_)./ _)\<close> [0, 51, 10] 10) | 
| 61955 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61952diff
changeset | 1411 | syntax | 
| 80934 | 1412 | "_prod" :: "pttrn => 'a set => 'b => 'b::comm_monoid_mult" (\<open>(\<open>indent=2 notation=\<open>binder \<Prod>\<close>\<close>\<Prod>(_/\<in>_)./ _)\<close> [0, 51, 10] 10) | 
| 80763 | 1413 | |
| 80760 | 1414 | syntax_consts | 
| 1415 | "_prod" == prod | |
| 80763 | 1416 | |
| 61799 | 1417 | translations \<comment> \<open>Beware of argument permutation!\<close> | 
| 64272 | 1418 | "\<Prod>i\<in>A. b" == "CONST prod (\<lambda>i. b) A" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1419 | |
| 80763 | 1420 | |
| 69593 | 1421 | text \<open>Instead of \<^term>\<open>\<Prod>x\<in>{x. P}. e\<close> we introduce the shorter \<open>\<Prod>x|P. e\<close>.\<close>
 | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1422 | |
| 61955 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61952diff
changeset | 1423 | syntax (ASCII) | 
| 80934 | 1424 | "_qprod" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a" (\<open>(\<open>indent=4 notation=\<open>binder PROD Collect\<close>\<close>PROD _ |/ _./ _)\<close> [0, 0, 10] 10) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1425 | syntax | 
| 80934 | 1426 | "_qprod" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a" (\<open>(\<open>indent=2 notation=\<open>binder \<Prod> Collect\<close>\<close>\<Prod>_ | (_)./ _)\<close> [0, 0, 10] 10) | 
| 80763 | 1427 | |
| 80760 | 1428 | syntax_consts | 
| 1429 | "_qprod" == prod | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1430 | translations | 
| 64272 | 1431 |   "\<Prod>x|P. t" => "CONST prod (\<lambda>x. t) {x. P}"
 | 
| 80765 
1d8ce19d7d71
proper translation for "_qprod", following "_qsum" (see also e14b89d6ef13 and fa7d27ef7e59);
 wenzelm parents: 
80763diff
changeset | 1432 | print_translation \<open> | 
| 81150 | 1433 | [(\<^const_syntax>\<open>prod\<close>, K (Collect_binder_tr' \<^syntax_const>\<open>_qprod\<close>))] | 
| 80765 
1d8ce19d7d71
proper translation for "_qprod", following "_qsum" (see also e14b89d6ef13 and fa7d27ef7e59);
 wenzelm parents: 
80763diff
changeset | 1434 | \<close> | 
| 
1d8ce19d7d71
proper translation for "_qprod", following "_qsum" (see also e14b89d6ef13 and fa7d27ef7e59);
 wenzelm parents: 
80763diff
changeset | 1435 | |
| 59010 | 1436 | context comm_monoid_mult | 
| 1437 | begin | |
| 1438 | ||
| 64272 | 1439 | lemma prod_dvd_prod: "(\<And>a. a \<in> A \<Longrightarrow> f a dvd g a) \<Longrightarrow> prod f A dvd prod g A" | 
| 59010 | 1440 | proof (induct A rule: infinite_finite_induct) | 
| 63654 | 1441 | case infinite | 
| 1442 | then show ?case by (auto intro: dvdI) | |
| 1443 | next | |
| 1444 | case empty | |
| 1445 | then show ?case by (auto intro: dvdI) | |
| 59010 | 1446 | next | 
| 63654 | 1447 | case (insert a A) | 
| 64272 | 1448 | then have "f a dvd g a" and "prod f A dvd prod g A" | 
| 63654 | 1449 | by simp_all | 
| 64272 | 1450 | then obtain r s where "g a = f a * r" and "prod g A = prod f A * s" | 
| 63654 | 1451 | by (auto elim!: dvdE) | 
| 64272 | 1452 | then have "g a * prod g A = f a * prod f A * (r * s)" | 
| 63654 | 1453 | by (simp add: ac_simps) | 
| 1454 | with insert.hyps show ?case | |
| 1455 | by (auto intro: dvdI) | |
| 59010 | 1456 | qed | 
| 1457 | ||
| 64272 | 1458 | lemma prod_dvd_prod_subset: "finite B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> prod f A dvd prod f B" | 
| 1459 | by (auto simp add: prod.subset_diff ac_simps intro: dvdI) | |
| 59010 | 1460 | |
| 1461 | end | |
| 1462 | ||
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1463 | |
| 60758 | 1464 | subsubsection \<open>Properties in more restricted classes of structures\<close> | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1465 | |
| 65687 | 1466 | context linordered_nonzero_semiring | 
| 1467 | begin | |
| 68975 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1468 | |
| 65687 | 1469 | lemma prod_ge_1: "(\<And>x. x \<in> A \<Longrightarrow> 1 \<le> f x) \<Longrightarrow> 1 \<le> prod f A" | 
| 1470 | proof (induct A rule: infinite_finite_induct) | |
| 1471 | case infinite | |
| 1472 | then show ?case by simp | |
| 1473 | next | |
| 1474 | case empty | |
| 1475 | then show ?case by simp | |
| 1476 | next | |
| 1477 | case (insert x F) | |
| 1478 | have "1 * 1 \<le> f x * prod f F" | |
| 1479 | by (rule mult_mono') (use insert in auto) | |
| 1480 | with insert show ?case by simp | |
| 1481 | qed | |
| 1482 | ||
| 1483 | lemma prod_le_1: | |
| 1484 | fixes f :: "'b \<Rightarrow> 'a" | |
| 1485 | assumes "\<And>x. x \<in> A \<Longrightarrow> 0 \<le> f x \<and> f x \<le> 1" | |
| 1486 | shows "prod f A \<le> 1" | |
| 1487 | using assms | |
| 1488 | proof (induct A rule: infinite_finite_induct) | |
| 1489 | case infinite | |
| 1490 | then show ?case by simp | |
| 1491 | next | |
| 1492 | case empty | |
| 1493 | then show ?case by simp | |
| 1494 | next | |
| 1495 | case (insert x F) | |
| 1496 | then show ?case by (force simp: mult.commute intro: dest: mult_le_one) | |
| 1497 | qed | |
| 1498 | ||
| 1499 | end | |
| 1500 | ||
| 59010 | 1501 | context comm_semiring_1 | 
| 1502 | begin | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1503 | |
| 64272 | 1504 | lemma dvd_prod_eqI [intro]: | 
| 59010 | 1505 | assumes "finite A" and "a \<in> A" and "b = f a" | 
| 64272 | 1506 | shows "b dvd prod f A" | 
| 59010 | 1507 | proof - | 
| 64272 | 1508 |   from \<open>finite A\<close> have "prod f (insert a (A - {a})) = f a * prod f (A - {a})"
 | 
| 1509 | by (intro prod.insert) auto | |
| 63654 | 1510 |   also from \<open>a \<in> A\<close> have "insert a (A - {a}) = A"
 | 
| 1511 | by blast | |
| 64272 | 1512 |   finally have "prod f A = f a * prod f (A - {a})" .
 | 
| 63654 | 1513 | with \<open>b = f a\<close> show ?thesis | 
| 1514 | by simp | |
| 59010 | 1515 | qed | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1516 | |
| 64272 | 1517 | lemma dvd_prodI [intro]: "finite A \<Longrightarrow> a \<in> A \<Longrightarrow> f a dvd prod f A" | 
| 63654 | 1518 | by auto | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1519 | |
| 64272 | 1520 | lemma prod_zero: | 
| 59010 | 1521 | assumes "finite A" and "\<exists>a\<in>A. f a = 0" | 
| 64272 | 1522 | shows "prod f A = 0" | 
| 63654 | 1523 | using assms | 
| 1524 | proof (induct A) | |
| 1525 | case empty | |
| 1526 | then show ?case by simp | |
| 59010 | 1527 | next | 
| 1528 | case (insert a A) | |
| 1529 | then have "f a = 0 \<or> (\<exists>a\<in>A. f a = 0)" by simp | |
| 75669 
43f5dfb7fa35
tuned (some HOL lints, by Yecine Megdiche);
 Fabian Huch <huch@in.tum.de> parents: 
75461diff
changeset | 1530 | then have "f a * prod f A = 0" by (rule disjE) (simp_all add: insert) | 
| 59010 | 1531 | with insert show ?case by simp | 
| 1532 | qed | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1533 | |
| 64272 | 1534 | lemma prod_dvd_prod_subset2: | 
| 59010 | 1535 | assumes "finite B" and "A \<subseteq> B" and "\<And>a. a \<in> A \<Longrightarrow> f a dvd g a" | 
| 64272 | 1536 | shows "prod f A dvd prod g B" | 
| 59010 | 1537 | proof - | 
| 64272 | 1538 | from assms have "prod f A dvd prod g A" | 
| 1539 | by (auto intro: prod_dvd_prod) | |
| 1540 | moreover from assms have "prod g A dvd prod g B" | |
| 1541 | by (auto intro: prod_dvd_prod_subset) | |
| 59010 | 1542 | ultimately show ?thesis by (rule dvd_trans) | 
| 1543 | qed | |
| 1544 | ||
| 1545 | end | |
| 1546 | ||
| 64272 | 1547 | lemma (in semidom) prod_zero_iff [simp]: | 
| 63924 | 1548 | fixes f :: "'b \<Rightarrow> 'a" | 
| 59010 | 1549 | assumes "finite A" | 
| 64272 | 1550 | shows "prod f A = 0 \<longleftrightarrow> (\<exists>a\<in>A. f a = 0)" | 
| 59010 | 1551 | using assms by (induct A) (auto simp: no_zero_divisors) | 
| 1552 | ||
| 64272 | 1553 | lemma (in semidom_divide) prod_diff1: | 
| 60353 
838025c6e278
implicit partial divison operation in integral domains
 haftmann parents: 
59867diff
changeset | 1554 | assumes "finite A" and "f a \<noteq> 0" | 
| 64272 | 1555 |   shows "prod f (A - {a}) = (if a \<in> A then prod f A div f a else prod f A)"
 | 
| 60353 
838025c6e278
implicit partial divison operation in integral domains
 haftmann parents: 
59867diff
changeset | 1556 | proof (cases "a \<notin> A") | 
| 63654 | 1557 | case True | 
| 1558 | then show ?thesis by simp | |
| 60353 
838025c6e278
implicit partial divison operation in integral domains
 haftmann parents: 
59867diff
changeset | 1559 | next | 
| 63654 | 1560 | case False | 
| 1561 | with assms show ?thesis | |
| 1562 | proof induct | |
| 1563 | case empty | |
| 1564 | then show ?case by simp | |
| 60353 
838025c6e278
implicit partial divison operation in integral domains
 haftmann parents: 
59867diff
changeset | 1565 | next | 
| 
838025c6e278
implicit partial divison operation in integral domains
 haftmann parents: 
59867diff
changeset | 1566 | case (insert b B) | 
| 
838025c6e278
implicit partial divison operation in integral domains
 haftmann parents: 
59867diff
changeset | 1567 | then show ?case | 
| 
838025c6e278
implicit partial divison operation in integral domains
 haftmann parents: 
59867diff
changeset | 1568 | proof (cases "a = b") | 
| 63654 | 1569 | case True | 
| 1570 | with insert show ?thesis by simp | |
| 60353 
838025c6e278
implicit partial divison operation in integral domains
 haftmann parents: 
59867diff
changeset | 1571 | next | 
| 63654 | 1572 | case False | 
| 1573 | with insert have "a \<in> B" by simp | |
| 63040 | 1574 |       define C where "C = B - {a}"
 | 
| 63654 | 1575 | with \<open>finite B\<close> \<open>a \<in> B\<close> have "B = insert a C" "finite C" "a \<notin> C" | 
| 1576 | by auto | |
| 1577 | with insert show ?thesis | |
| 1578 | by (auto simp add: insert_commute ac_simps) | |
| 60353 
838025c6e278
implicit partial divison operation in integral domains
 haftmann parents: 
59867diff
changeset | 1579 | qed | 
| 
838025c6e278
implicit partial divison operation in integral domains
 haftmann parents: 
59867diff
changeset | 1580 | qed | 
| 
838025c6e278
implicit partial divison operation in integral domains
 haftmann parents: 
59867diff
changeset | 1581 | qed | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1582 | |
| 82395 
918c50e0447e
Lemmas from Manuel Eberl's Q_Analogues
 paulson <lp15@cam.ac.uk> parents: 
81150diff
changeset | 1583 | lemma prod_uminus: "(\<Prod>x\<in>A. -f x :: 'a :: comm_ring_1) = (-1) ^ card A * (\<Prod>x\<in>A. f x)" | 
| 
918c50e0447e
Lemmas from Manuel Eberl's Q_Analogues
 paulson <lp15@cam.ac.uk> parents: 
81150diff
changeset | 1584 | by (induction A rule: infinite_finite_induct) (auto simp: algebra_simps) | 
| 
918c50e0447e
Lemmas from Manuel Eberl's Q_Analogues
 paulson <lp15@cam.ac.uk> parents: 
81150diff
changeset | 1585 | |
| 
918c50e0447e
Lemmas from Manuel Eberl's Q_Analogues
 paulson <lp15@cam.ac.uk> parents: 
81150diff
changeset | 1586 | lemma prod_diff: | 
| 
918c50e0447e
Lemmas from Manuel Eberl's Q_Analogues
 paulson <lp15@cam.ac.uk> parents: 
81150diff
changeset | 1587 | fixes f :: "'a \<Rightarrow> 'b :: field" | 
| 
918c50e0447e
Lemmas from Manuel Eberl's Q_Analogues
 paulson <lp15@cam.ac.uk> parents: 
81150diff
changeset | 1588 | assumes "finite A" "B \<subseteq> A" "\<And>x. x \<in> B \<Longrightarrow> f x \<noteq> 0" | 
| 
918c50e0447e
Lemmas from Manuel Eberl's Q_Analogues
 paulson <lp15@cam.ac.uk> parents: 
81150diff
changeset | 1589 | shows "prod f (A - B) = prod f A / prod f B" | 
| 
918c50e0447e
Lemmas from Manuel Eberl's Q_Analogues
 paulson <lp15@cam.ac.uk> parents: 
81150diff
changeset | 1590 | by (metis assms finite_subset nonzero_eq_divide_eq prod.subset_diff | 
| 
918c50e0447e
Lemmas from Manuel Eberl's Q_Analogues
 paulson <lp15@cam.ac.uk> parents: 
81150diff
changeset | 1591 | prod_zero_iff) | 
| 
918c50e0447e
Lemmas from Manuel Eberl's Q_Analogues
 paulson <lp15@cam.ac.uk> parents: 
81150diff
changeset | 1592 | |
| 64267 | 1593 | lemma sum_zero_power [simp]: "(\<Sum>i\<in>A. c i * 0^i) = (if finite A \<and> 0 \<in> A then c 0 else 0)" | 
| 63654 | 1594 | for c :: "nat \<Rightarrow> 'a::division_ring" | 
| 1595 | by (induct A rule: infinite_finite_induct) auto | |
| 62481 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
 haftmann parents: 
62378diff
changeset | 1596 | |
| 64267 | 1597 | lemma sum_zero_power' [simp]: | 
| 63654 | 1598 | "(\<Sum>i\<in>A. c i * 0^i / d i) = (if finite A \<and> 0 \<in> A then c 0 / d 0 else 0)" | 
| 1599 | for c :: "nat \<Rightarrow> 'a::field" | |
| 64267 | 1600 | using sum_zero_power [of "\<lambda>i. c i / d i" A] by auto | 
| 62481 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
 haftmann parents: 
62378diff
changeset | 1601 | |
| 65680 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 1602 | lemma (in field) prod_inversef: "prod (inverse \<circ> f) A = inverse (prod f A)" | 
| 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 1603 | proof (cases "finite A") | 
| 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 1604 | case True | 
| 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 1605 | then show ?thesis | 
| 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 1606 | by (induct A rule: finite_induct) simp_all | 
| 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 1607 | next | 
| 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 1608 | case False | 
| 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 1609 | then show ?thesis | 
| 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 1610 | by auto | 
| 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 1611 | qed | 
| 59010 | 1612 | |
| 65680 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 1613 | lemma (in field) prod_dividef: "(\<Prod>x\<in>A. f x / g x) = prod f A / prod g A" | 
| 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 1614 | using prod_inversef [of g A] by (simp add: divide_inverse prod.distrib) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1615 | |
| 64272 | 1616 | lemma prod_Un: | 
| 59010 | 1617 | fixes f :: "'b \<Rightarrow> 'a :: field" | 
| 1618 | assumes "finite A" and "finite B" | |
| 63654 | 1619 | and "\<forall>x\<in>A \<inter> B. f x \<noteq> 0" | 
| 64272 | 1620 | shows "prod f (A \<union> B) = prod f A * prod f B / prod f (A \<inter> B)" | 
| 59010 | 1621 | proof - | 
| 64272 | 1622 | from assms have "prod f A * prod f B = prod f (A \<union> B) * prod f (A \<inter> B)" | 
| 1623 | by (simp add: prod.union_inter [symmetric, of A B]) | |
| 63654 | 1624 | with assms show ?thesis | 
| 1625 | by simp | |
| 59010 | 1626 | qed | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1627 | |
| 68361 | 1628 | context linordered_semidom | 
| 1629 | begin | |
| 1630 | ||
| 79670 
f471e1715fc4
A small collection of new and useful facts, including the AM-GM inequality
 paulson <lp15@cam.ac.uk> parents: 
79587diff
changeset | 1631 | lemma prod_nonneg: "(\<And>a. a\<in>A \<Longrightarrow> 0 \<le> f a) \<Longrightarrow> 0 \<le> prod f A" | 
| 59010 | 1632 | by (induct A rule: infinite_finite_induct) simp_all | 
| 1633 | ||
| 79670 
f471e1715fc4
A small collection of new and useful facts, including the AM-GM inequality
 paulson <lp15@cam.ac.uk> parents: 
79587diff
changeset | 1634 | lemma prod_pos: "(\<And>a. a\<in>A \<Longrightarrow> 0 < f a) \<Longrightarrow> 0 < prod f A" | 
| 59010 | 1635 | by (induct A rule: infinite_finite_induct) simp_all | 
| 1636 | ||
| 68361 | 1637 | lemma prod_mono: | 
| 67673 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 1638 | "(\<And>i. i \<in> A \<Longrightarrow> 0 \<le> f i \<and> f i \<le> g i) \<Longrightarrow> prod f A \<le> prod g A" | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 1639 | by (induct A rule: infinite_finite_induct) (force intro!: prod_nonneg mult_mono)+ | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1640 | |
| 79586 | 1641 | text \<open>Only one needs to be strict\<close> | 
| 68361 | 1642 | lemma prod_mono_strict: | 
| 79586 | 1643 | assumes "i \<in> A" "f i < g i" | 
| 1644 | assumes "finite A" | |
| 1645 | assumes "\<And>i. i \<in> A \<Longrightarrow> 0 \<le> f i \<and> f i \<le> g i" | |
| 1646 | assumes "\<And>i. i \<in> A \<Longrightarrow> 0 < g i" | |
| 1647 | shows "prod f A < prod g A" | |
| 1648 | proof - | |
| 1649 |   have "prod f A = f i * prod f (A - {i})"
 | |
| 1650 | using assms by (intro prod.remove) | |
| 1651 |   also have "\<dots> \<le> f i * prod g (A - {i})"
 | |
| 1652 | using assms by (intro mult_left_mono prod_mono) auto | |
| 1653 |   also have "\<dots> < g i * prod g (A - {i})"
 | |
| 1654 | using assms by (intro mult_strict_right_mono prod_pos) auto | |
| 1655 | also have "\<dots> = prod g A" | |
| 1656 | using assms by (intro prod.remove [symmetric]) | |
| 1657 | finally show ?thesis . | |
| 63654 | 1658 | qed | 
| 60974 
6a6f15d8fbc4
New material and fixes related to the forthcoming Stone-Weierstrass development
 paulson <lp15@cam.ac.uk> parents: 
60758diff
changeset | 1659 | |
| 74438 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
73535diff
changeset | 1660 | lemma prod_le_power: | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
73535diff
changeset | 1661 | assumes A: "\<And>i. i \<in> A \<Longrightarrow> 0 \<le> f i \<and> f i \<le> n" "card A \<le> k" and "n \<ge> 1" | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
73535diff
changeset | 1662 | shows "prod f A \<le> n ^ k" | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
73535diff
changeset | 1663 | using A | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
73535diff
changeset | 1664 | proof (induction A arbitrary: k rule: infinite_finite_induct) | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
73535diff
changeset | 1665 | case (insert i A) | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
73535diff
changeset | 1666 | then obtain k' where k': "card A \<le> k'" "k = Suc k'" | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
73535diff
changeset | 1667 | using Suc_le_D by force | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
73535diff
changeset | 1668 | have "f i * prod f A \<le> n * n ^ k'" | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
73535diff
changeset | 1669 | using insert \<open>n \<ge> 1\<close> k' by (intro prod_nonneg mult_mono; force) | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
73535diff
changeset | 1670 | then show ?case | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
73535diff
changeset | 1671 | by (auto simp: \<open>k = Suc k'\<close> insert.hyps) | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
73535diff
changeset | 1672 | qed (use \<open>n \<ge> 1\<close> in auto) | 
| 
5827b91ef30e
new material from the Roth development, mostly about finite sets, disjoint famillies and partitions
 paulson <lp15@cam.ac.uk> parents: 
73535diff
changeset | 1673 | |
| 68361 | 1674 | end | 
| 1675 | ||
| 1676 | lemma prod_mono2: | |
| 1677 | fixes f :: "'a \<Rightarrow> 'b :: linordered_idom" | |
| 1678 | assumes fin: "finite B" | |
| 1679 | and sub: "A \<subseteq> B" | |
| 1680 | and nn: "\<And>b. b \<in> B-A \<Longrightarrow> 1 \<le> f b" | |
| 1681 | and A: "\<And>a. a \<in> A \<Longrightarrow> 0 \<le> f a" | |
| 1682 | shows "prod f A \<le> prod f B" | |
| 1683 | proof - | |
| 1684 | have "prod f A \<le> prod f A * prod f (B-A)" | |
| 1685 | by (metis prod_ge_1 A mult_le_cancel_left1 nn not_less prod_nonneg) | |
| 1686 | also from fin finite_subset[OF sub fin] have "\<dots> = prod f (A \<union> (B-A))" | |
| 1687 | by (simp add: prod.union_disjoint del: Un_Diff_cancel) | |
| 1688 | also from sub have "A \<union> (B-A) = B" by blast | |
| 1689 | finally show ?thesis . | |
| 1690 | qed | |
| 1691 | ||
| 1692 | lemma less_1_prod: | |
| 1693 | fixes f :: "'a \<Rightarrow> 'b::linordered_idom" | |
| 1694 |   shows "finite I \<Longrightarrow> I \<noteq> {} \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> 1 < f i) \<Longrightarrow> 1 < prod f I"
 | |
| 1695 | by (induct I rule: finite_ne_induct) (auto intro: less_1_mult) | |
| 1696 | ||
| 1697 | lemma less_1_prod2: | |
| 1698 | fixes f :: "'a \<Rightarrow> 'b::linordered_idom" | |
| 1699 | assumes I: "finite I" "i \<in> I" "1 < f i" "\<And>i. i \<in> I \<Longrightarrow> 1 \<le> f i" | |
| 1700 | shows "1 < prod f I" | |
| 1701 | proof - | |
| 1702 |   have "1 < f i * prod f (I - {i})"
 | |
| 1703 | using assms | |
| 1704 | by (meson DiffD1 leI less_1_mult less_le_trans mult_le_cancel_left1 prod_ge_1) | |
| 1705 | also have "\<dots> = prod f I" | |
| 1706 | using assms by (simp add: prod.remove) | |
| 1707 | finally show ?thesis . | |
| 1708 | qed | |
| 1709 | ||
| 64272 | 1710 | lemma (in linordered_field) abs_prod: "\<bar>prod f A\<bar> = (\<Prod>x\<in>A. \<bar>f x\<bar>)" | 
| 59010 | 1711 | by (induct A rule: infinite_finite_induct) (simp_all add: abs_mult) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1712 | |
| 64272 | 1713 | lemma prod_eq_1_iff [simp]: "finite A \<Longrightarrow> prod f A = 1 \<longleftrightarrow> (\<forall>a\<in>A. f a = 1)" | 
| 63654 | 1714 | for f :: "'a \<Rightarrow> nat" | 
| 59010 | 1715 | by (induct A rule: finite_induct) simp_all | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1716 | |
| 64272 | 1717 | lemma prod_pos_nat_iff [simp]: "finite A \<Longrightarrow> prod f A > 0 \<longleftrightarrow> (\<forall>a\<in>A. f a > 0)" | 
| 63654 | 1718 | for f :: "'a \<Rightarrow> nat" | 
| 64272 | 1719 | using prod_zero_iff by (simp del: neq0_conv add: zero_less_iff_neq_zero) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1720 | |
| 67969 
83c8cafdebe8
Syntax for the special cases Min(A`I) and Max (A`I)
 paulson <lp15@cam.ac.uk> parents: 
67683diff
changeset | 1721 | lemma prod_constant [simp]: "(\<Prod>x\<in> A. y) = y ^ card A" | 
| 63654 | 1722 | for y :: "'a::comm_monoid_mult" | 
| 62481 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
 haftmann parents: 
62378diff
changeset | 1723 | by (induct A rule: infinite_finite_induct) simp_all | 
| 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
 haftmann parents: 
62378diff
changeset | 1724 | |
| 82395 
918c50e0447e
Lemmas from Manuel Eberl's Q_Analogues
 paulson <lp15@cam.ac.uk> parents: 
81150diff
changeset | 1725 | lemma prod_diff_swap: | 
| 
918c50e0447e
Lemmas from Manuel Eberl's Q_Analogues
 paulson <lp15@cam.ac.uk> parents: 
81150diff
changeset | 1726 | fixes f :: "'a \<Rightarrow> 'b :: comm_ring_1" | 
| 
918c50e0447e
Lemmas from Manuel Eberl's Q_Analogues
 paulson <lp15@cam.ac.uk> parents: 
81150diff
changeset | 1727 | shows "prod (\<lambda>x. f x - g x) A = (-1) ^ card A * prod (\<lambda>x. g x - f x) A" | 
| 
918c50e0447e
Lemmas from Manuel Eberl's Q_Analogues
 paulson <lp15@cam.ac.uk> parents: 
81150diff
changeset | 1728 | using prod.distrib[of "\<lambda>_. -1" "\<lambda>x. f x - g x" A] | 
| 
918c50e0447e
Lemmas from Manuel Eberl's Q_Analogues
 paulson <lp15@cam.ac.uk> parents: 
81150diff
changeset | 1729 | by simp | 
| 
918c50e0447e
Lemmas from Manuel Eberl's Q_Analogues
 paulson <lp15@cam.ac.uk> parents: 
81150diff
changeset | 1730 | |
| 64272 | 1731 | lemma prod_power_distrib: "prod f A ^ n = prod (\<lambda>x. (f x) ^ n) A" | 
| 63654 | 1732 | for f :: "'a \<Rightarrow> 'b::comm_semiring_1" | 
| 1733 | by (induct A rule: infinite_finite_induct) (auto simp add: power_mult_distrib) | |
| 62481 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
 haftmann parents: 
62378diff
changeset | 1734 | |
| 82395 
918c50e0447e
Lemmas from Manuel Eberl's Q_Analogues
 paulson <lp15@cam.ac.uk> parents: 
81150diff
changeset | 1735 | lemma power_inject_exp': | 
| 
918c50e0447e
Lemmas from Manuel Eberl's Q_Analogues
 paulson <lp15@cam.ac.uk> parents: 
81150diff
changeset | 1736 | assumes "a \<noteq> 1" "a > (0 :: 'a :: linordered_semidom)" | 
| 
918c50e0447e
Lemmas from Manuel Eberl's Q_Analogues
 paulson <lp15@cam.ac.uk> parents: 
81150diff
changeset | 1737 | shows "a ^ m = a ^ n \<longleftrightarrow> m = n" | 
| 
918c50e0447e
Lemmas from Manuel Eberl's Q_Analogues
 paulson <lp15@cam.ac.uk> parents: 
81150diff
changeset | 1738 | by (metis assms not_less_iff_gr_or_eq order_le_less power_decreasing_iff | 
| 
918c50e0447e
Lemmas from Manuel Eberl's Q_Analogues
 paulson <lp15@cam.ac.uk> parents: 
81150diff
changeset | 1739 | power_inject_exp) | 
| 
918c50e0447e
Lemmas from Manuel Eberl's Q_Analogues
 paulson <lp15@cam.ac.uk> parents: 
81150diff
changeset | 1740 | |
| 64267 | 1741 | lemma power_sum: "c ^ (\<Sum>a\<in>A. f a) = (\<Prod>a\<in>A. c ^ f a)" | 
| 62481 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
 haftmann parents: 
62378diff
changeset | 1742 | by (induct A rule: infinite_finite_induct) (simp_all add: power_add) | 
| 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
 haftmann parents: 
62378diff
changeset | 1743 | |
| 64272 | 1744 | lemma prod_gen_delta: | 
| 63654 | 1745 | fixes b :: "'b \<Rightarrow> 'a::comm_monoid_mult" | 
| 1746 | assumes fin: "finite S" | |
| 64272 | 1747 | shows "prod (\<lambda>k. if k = a then b k else c) S = | 
| 63654 | 1748 | (if a \<in> S then b a * c ^ (card S - 1) else c ^ card S)" | 
| 1749 | proof - | |
| 62481 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
 haftmann parents: 
62378diff
changeset | 1750 | let ?f = "(\<lambda>k. if k=a then b k else c)" | 
| 63654 | 1751 | show ?thesis | 
| 1752 | proof (cases "a \<in> S") | |
| 1753 | case False | |
| 1754 | then have "\<forall> k\<in> S. ?f k = c" by simp | |
| 64272 | 1755 | with False show ?thesis by (simp add: prod_constant) | 
| 63654 | 1756 | next | 
| 1757 | case True | |
| 62481 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
 haftmann parents: 
62378diff
changeset | 1758 |     let ?A = "S - {a}"
 | 
| 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
 haftmann parents: 
62378diff
changeset | 1759 |     let ?B = "{a}"
 | 
| 63654 | 1760 | from True have eq: "S = ?A \<union> ?B" by blast | 
| 1761 |     have disjoint: "?A \<inter> ?B = {}" by simp
 | |
| 1762 | from fin have fin': "finite ?A" "finite ?B" by auto | |
| 64272 | 1763 | have f_A0: "prod ?f ?A = prod (\<lambda>i. c) ?A" | 
| 1764 | by (rule prod.cong) auto | |
| 63654 | 1765 | from fin True have card_A: "card ?A = card S - 1" by auto | 
| 64272 | 1766 | have f_A1: "prod ?f ?A = c ^ card ?A" | 
| 1767 | unfolding f_A0 by (rule prod_constant) | |
| 1768 | have "prod ?f ?A * prod ?f ?B = prod ?f S" | |
| 1769 | using prod.union_disjoint[OF fin' disjoint, of ?f, unfolded eq[symmetric]] | |
| 62481 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
 haftmann parents: 
62378diff
changeset | 1770 | by simp | 
| 63654 | 1771 | with True card_A show ?thesis | 
| 64272 | 1772 | by (simp add: f_A1 field_simps cong add: prod.cong cong del: if_weak_cong) | 
| 63654 | 1773 | qed | 
| 62481 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
 haftmann parents: 
62378diff
changeset | 1774 | qed | 
| 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
 haftmann parents: 
62378diff
changeset | 1775 | |
| 64267 | 1776 | lemma sum_image_le: | 
| 69127 | 1777 | fixes g :: "'a \<Rightarrow> 'b::ordered_comm_monoid_add" | 
| 63952 
354808e9f44b
new material connected with HOL Light measure theory, plus more rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63938diff
changeset | 1778 | assumes "finite I" "\<And>i. i \<in> I \<Longrightarrow> 0 \<le> g(f i)" | 
| 64267 | 1779 | shows "sum g (f ` I) \<le> sum (g \<circ> f) I" | 
| 63952 
354808e9f44b
new material connected with HOL Light measure theory, plus more rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63938diff
changeset | 1780 | using assms | 
| 
354808e9f44b
new material connected with HOL Light measure theory, plus more rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63938diff
changeset | 1781 | proof induction | 
| 
354808e9f44b
new material connected with HOL Light measure theory, plus more rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63938diff
changeset | 1782 | case empty | 
| 
354808e9f44b
new material connected with HOL Light measure theory, plus more rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63938diff
changeset | 1783 | then show ?case by auto | 
| 
354808e9f44b
new material connected with HOL Light measure theory, plus more rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63938diff
changeset | 1784 | next | 
| 79670 
f471e1715fc4
A small collection of new and useful facts, including the AM-GM inequality
 paulson <lp15@cam.ac.uk> parents: 
79587diff
changeset | 1785 | case (insert i I) | 
| 
f471e1715fc4
A small collection of new and useful facts, including the AM-GM inequality
 paulson <lp15@cam.ac.uk> parents: 
79587diff
changeset | 1786 | hence *: "sum g (f ` I) \<le> g (f i) + sum g (f ` I)" | 
| 
f471e1715fc4
A small collection of new and useful facts, including the AM-GM inequality
 paulson <lp15@cam.ac.uk> parents: 
79587diff
changeset | 1787 | "sum g (f ` I) \<le> sum (g \<circ> f) I" using add_increasing by blast+ | 
| 
f471e1715fc4
A small collection of new and useful facts, including the AM-GM inequality
 paulson <lp15@cam.ac.uk> parents: 
79587diff
changeset | 1788 | have "sum g (f ` insert i I) = sum g (insert (f i) (f ` I))" by simp | 
| 
f471e1715fc4
A small collection of new and useful facts, including the AM-GM inequality
 paulson <lp15@cam.ac.uk> parents: 
79587diff
changeset | 1789 | also have "\<dots> \<le> g (f i) + sum g (f ` I)" by (simp add: * insert sum.insert_if) | 
| 
f471e1715fc4
A small collection of new and useful facts, including the AM-GM inequality
 paulson <lp15@cam.ac.uk> parents: 
79587diff
changeset | 1790 | also from * have "\<dots> \<le> g (f i) + sum (g \<circ> f) I" by (intro add_left_mono) | 
| 
f471e1715fc4
A small collection of new and useful facts, including the AM-GM inequality
 paulson <lp15@cam.ac.uk> parents: 
79587diff
changeset | 1791 | also from insert have "\<dots> = sum (g \<circ> f) (insert i I)" by (simp add: sum.insert_if) | 
| 63952 
354808e9f44b
new material connected with HOL Light measure theory, plus more rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63938diff
changeset | 1792 | finally show ?case . | 
| 
354808e9f44b
new material connected with HOL Light measure theory, plus more rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63938diff
changeset | 1793 | qed | 
| 68975 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1794 | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1795 | end |