| author | wenzelm | 
| Mon, 13 Jul 2020 22:07:18 +0200 | |
| changeset 72031 | b7cec26e41d1 | 
| parent 71356 | ce45299cce44 | 
| child 72089 | 8348bba699e6 | 
| 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 | 
| 66364 | 11 | imports Power | 
| 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 | ||
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 168 | lemma UNION_disjoint: | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 169 | assumes "finite I" and "\<forall>i\<in>I. finite (A i)" | 
| 63654 | 170 |     and "\<forall>i\<in>I. \<forall>j\<in>I. i \<noteq> j \<longrightarrow> A i \<inter> A j = {}"
 | 
| 69275 | 171 | shows "F g (\<Union>(A ` I)) = F (\<lambda>x. F g (A x)) I" | 
| 70128 | 172 | using assms | 
| 173 | proof (induction rule: finite_induct) | |
| 174 | case (insert i I) | |
| 175 | then have "\<forall>j\<in>I. j \<noteq> i" | |
| 176 | by blast | |
| 177 |   with insert.prems have "A i \<inter> \<Union>(A ` I) = {}"
 | |
| 178 | by blast | |
| 179 | with insert show ?case | |
| 180 | by (simp add: union_disjoint) | |
| 181 | qed auto | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 182 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 183 | lemma Union_disjoint: | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 184 |   assumes "\<forall>A\<in>C. finite A" "\<forall>A\<in>C. \<forall>B\<in>C. A \<noteq> B \<longrightarrow> A \<inter> B = {}"
 | 
| 61952 | 185 | shows "F g (\<Union>C) = (F \<circ> F) g C" | 
| 63654 | 186 | proof (cases "finite C") | 
| 187 | case True | |
| 188 | from UNION_disjoint [OF this assms] show ?thesis by simp | |
| 189 | next | |
| 190 | case False | |
| 191 | then show ?thesis by (auto dest: finite_UnionD intro: infinite) | |
| 192 | qed | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 193 | |
| 63654 | 194 | lemma distrib: "F (\<lambda>x. g x \<^bold>* h x) A = F g A \<^bold>* F h A" | 
| 63092 | 195 | 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 | 196 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 197 | lemma Sigma: | 
| 70128 | 198 | assumes "finite A" "\<forall>x\<in>A. finite (B x)" | 
| 199 | shows "F (\<lambda>x. F (g x) (B x)) A = F (case_prod g) (SIGMA x:A. B x)" | |
| 200 | unfolding Sigma_def | |
| 201 | proof (subst UNION_disjoint) | |
| 202 |   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"
 | |
| 203 | proof (rule cong [OF refl]) | |
| 204 |     show "F (g x) (B x) = F (\<lambda>(x, y). g x y) (\<Union>y\<in>B x. {(x, y)})"
 | |
| 205 | if "x \<in> A" for x | |
| 206 | using that assms by (simp add: UNION_disjoint) | |
| 207 | qed | |
| 208 | qed (use assms in auto) | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 209 | |
| 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 | 210 | lemma related: | 
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 211 | assumes Re: "R \<^bold>1 \<^bold>1" | 
| 63654 | 212 | and Rop: "\<forall>x1 y1 x2 y2. R x1 x2 \<and> R y1 y2 \<longrightarrow> R (x1 \<^bold>* y1) (x2 \<^bold>* y2)" | 
| 213 | and fin: "finite S" | |
| 214 | 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 | 215 | shows "R (F h S) (F g S)" | 
| 63654 | 216 | 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 | 217 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 218 | lemma mono_neutral_cong_left: | 
| 63654 | 219 | assumes "finite T" | 
| 220 | and "S \<subseteq> T" | |
| 221 | and "\<forall>i \<in> T - S. h i = \<^bold>1" | |
| 222 | and "\<And>x. x \<in> S \<Longrightarrow> g x = h x" | |
| 223 | shows "F g S = F h T" | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 224 | proof- | 
| 60758 | 225 | have eq: "T = S \<union> (T - S)" using \<open>S \<subseteq> T\<close> by blast | 
| 226 |   have d: "S \<inter> (T - S) = {}" using \<open>S \<subseteq> T\<close> by blast
 | |
| 227 | 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 | 228 | by (auto intro: finite_subset) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 229 | show ?thesis using assms(4) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 230 | 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 | 231 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 232 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 233 | lemma mono_neutral_cong_right: | 
| 63654 | 234 | "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> | 
| 235 | F g T = F h S" | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 236 | by (auto intro!: mono_neutral_cong_left [symmetric]) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 237 | |
| 63654 | 238 | 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 | 239 | by (blast intro: mono_neutral_cong_left) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 240 | |
| 63654 | 241 | 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 | 242 | by (blast intro!: mono_neutral_left [symmetric]) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 243 | |
| 64979 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 244 | lemma mono_neutral_cong: | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 245 | assumes [simp]: "finite T" "finite S" | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 246 | 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 | 247 | 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 | 248 | shows "F g S = F h T" | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 249 | proof- | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 250 | have "F g S = F g (S \<inter> T)" | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 251 | by(rule mono_neutral_right)(auto intro: *) | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 252 | 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 | 253 | also have "\<dots> = F h T" | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 254 | by(rule mono_neutral_left)(auto intro: *) | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 255 | finally show ?thesis . | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 256 | qed | 
| 
20a623d03d71
move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
 hoelzl parents: 
64272diff
changeset | 257 | |
| 57129 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 258 | 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 | 259 | by (auto simp: bij_betw_def reindex) | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 260 | |
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 261 | lemma reindex_bij_witness: | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 262 | assumes witness: | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 263 | "\<And>a. a \<in> S \<Longrightarrow> i (j a) = a" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 264 | "\<And>a. a \<in> S \<Longrightarrow> j a \<in> T" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 265 | "\<And>b. b \<in> T \<Longrightarrow> j (i b) = b" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 266 | "\<And>b. b \<in> T \<Longrightarrow> i b \<in> S" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 267 | assumes eq: | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 268 | "\<And>a. a \<in> S \<Longrightarrow> h (j a) = g a" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 269 | shows "F g S = F h T" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 270 | proof - | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 271 | have "bij_betw j S T" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 272 | 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 | 273 | 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 | 274 | by (intro cong) (auto simp: eq) | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 275 | ultimately show ?thesis | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 276 | by (simp add: reindex_bij_betw) | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 277 | qed | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 278 | |
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 279 | lemma reindex_bij_betw_not_neutral: | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 280 | assumes fin: "finite S'" "finite T'" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 281 | assumes bij: "bij_betw h (S - S') (T - T')" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 282 | assumes nn: | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 283 | "\<And>a. a \<in> S' \<Longrightarrow> g (h a) = z" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 284 | "\<And>b. b \<in> T' \<Longrightarrow> g b = z" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 285 | shows "F (\<lambda>x. g (h x)) S = F g T" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 286 | proof - | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 287 | have [simp]: "finite S \<longleftrightarrow> finite T" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 288 | using bij_betw_finite[OF bij] fin by auto | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 289 | show ?thesis | 
| 63654 | 290 | proof (cases "finite S") | 
| 291 | case True | |
| 57129 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 292 | 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 | 293 | by (intro mono_neutral_cong_right) auto | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 294 | also have "\<dots> = F g (T - T')" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 295 | using bij by (rule reindex_bij_betw) | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 296 | also have "\<dots> = F g T" | 
| 60758 | 297 | 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 | 298 | finally show ?thesis . | 
| 63654 | 299 | next | 
| 300 | case False | |
| 301 | then show ?thesis by simp | |
| 302 | qed | |
| 57129 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 303 | qed | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 304 | |
| 57418 | 305 | lemma reindex_nontrivial: | 
| 306 | assumes "finite A" | |
| 63654 | 307 | 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 | 308 | shows "F g (h ` A) = F (g \<circ> h) A" | 
| 309 | 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 | 310 |   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 | 311 | using nz by (auto intro!: inj_onI simp: bij_betw_def) | 
| 63654 | 312 | qed (use \<open>finite A\<close> in auto) | 
| 57418 | 313 | |
| 57129 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 314 | lemma reindex_bij_witness_not_neutral: | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 315 | assumes fin: "finite S'" "finite T'" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 316 | assumes witness: | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 317 | "\<And>a. a \<in> S - S' \<Longrightarrow> i (j a) = a" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 318 | "\<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 | 319 | "\<And>b. b \<in> T - T' \<Longrightarrow> j (i b) = b" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 320 | "\<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 | 321 | assumes nn: | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 322 | "\<And>a. a \<in> S' \<Longrightarrow> g a = z" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 323 | "\<And>b. b \<in> T' \<Longrightarrow> h b = z" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 324 | assumes eq: | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 325 | "\<And>a. a \<in> S \<Longrightarrow> h (j a) = g a" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 326 | shows "F g S = F h T" | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 327 | proof - | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 328 | 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 | 329 | using witness by (intro bij_betw_byWitness[where f'=i]) auto | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 330 | 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 | 331 | by (intro cong) (auto simp: eq) | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 332 | show ?thesis | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 333 | unfolding F_eq using fin nn eq | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 334 | by (intro reindex_bij_betw_not_neutral[OF _ _ bij]) auto | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 335 | qed | 
| 
7edb7550663e
introduce more powerful reindexing rules for big operators
 hoelzl parents: 
56545diff
changeset | 336 | |
| 67673 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 337 | lemma delta_remove: | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 338 | assumes fS: "finite S" | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 339 |   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 | 340 | proof - | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 341 | 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 | 342 | show ?thesis | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 343 | proof (cases "a \<in> S") | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 344 | case False | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 345 | 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 | 346 | with False show ?thesis by simp | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 347 | next | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 348 | case True | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 349 |     let ?A = "S - {a}"
 | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 350 |     let ?B = "{a}"
 | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 351 | 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 | 352 |     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 | 353 | 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 | 354 | 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 | 355 | 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 | 356 | with True show ?thesis | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 357 | 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 | 358 | qed | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 359 | qed | 
| 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 360 | |
| 67683 
817944aeac3f
Lots of new material about matrices, etc.
 paulson <lp15@cam.ac.uk> parents: 
67673diff
changeset | 361 | lemma delta [simp]: | 
| 
817944aeac3f
Lots of new material about matrices, etc.
 paulson <lp15@cam.ac.uk> parents: 
67673diff
changeset | 362 | assumes fS: "finite S" | 
| 
817944aeac3f
Lots of new material about matrices, etc.
 paulson <lp15@cam.ac.uk> parents: 
67673diff
changeset | 363 | 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 | 364 | by (simp add: delta_remove [OF assms]) | 
| 
817944aeac3f
Lots of new material about matrices, etc.
 paulson <lp15@cam.ac.uk> parents: 
67673diff
changeset | 365 | |
| 
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 fin: "finite S" | 
| 
817944aeac3f
Lots of new material about matrices, etc.
 paulson <lp15@cam.ac.uk> parents: 
67673diff
changeset | 368 | 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 | 369 | 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 | 370 | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 371 | lemma If_cases: | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 372 | fixes P :: "'b \<Rightarrow> bool" and g h :: "'b \<Rightarrow> 'a" | 
| 63654 | 373 | assumes fin: "finite A" | 
| 374 |   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 | 375 | proof - | 
| 63654 | 376 |   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 | 377 | by blast+ | 
| 63654 | 378 |   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 | 379 | let ?g = "\<lambda>x. if P x then h x else g x" | 
| 63654 | 380 | 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 | 381 | by (subst (1 2) cong) simp_all | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 382 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 383 | |
| 63654 | 384 | lemma cartesian_product: "F (\<lambda>x. F (g x) B) A = F (case_prod g) (A \<times> B)" | 
| 70128 | 385 | proof (cases "A = {} \<or> B = {}")
 | 
| 386 | case True | |
| 387 | then show ?thesis | |
| 388 | by auto | |
| 389 | next | |
| 390 | case False | |
| 391 |   then have "A \<noteq> {}" "B \<noteq> {}" by auto
 | |
| 392 | show ?thesis | |
| 393 | proof (cases "finite A \<and> finite B") | |
| 394 | case True | |
| 395 | then show ?thesis | |
| 396 | by (simp add: Sigma) | |
| 397 | next | |
| 398 | case False | |
| 399 | then consider "infinite A" | "infinite B" by auto | |
| 400 | then have "infinite (A \<times> B)" | |
| 401 |       by cases (use \<open>A \<noteq> {}\<close> \<open>B \<noteq> {}\<close> in \<open>auto dest: finite_cartesian_productD1 finite_cartesian_productD2\<close>)
 | |
| 402 | then show ?thesis | |
| 403 | using False by auto | |
| 404 | qed | |
| 405 | qed | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 406 | |
| 57418 | 407 | lemma inter_restrict: | 
| 408 | 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 | 409 | shows "F g (A \<inter> B) = F (\<lambda>x. if x \<in> B then g x else \<^bold>1) A" | 
| 57418 | 410 | proof - | 
| 63290 
9ac558ab0906
boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
 haftmann parents: 
63092diff
changeset | 411 | let ?g = "\<lambda>x. if x \<in> A \<inter> B then g x else \<^bold>1" | 
| 63654 | 412 | 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 | 413 | moreover have "A \<inter> B \<subseteq> A" by blast | 
| 63654 | 414 | ultimately have "F ?g (A \<inter> B) = F ?g A" | 
| 415 | using \<open>finite A\<close> by (intro mono_neutral_left) auto | |
| 57418 | 416 | then show ?thesis by simp | 
| 417 | qed | |
| 418 | ||
| 419 | 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 | 420 |   "finite A \<Longrightarrow> F g {x \<in> A. P x} = F (\<lambda>x. if P x then g x else \<^bold>1) A"
 | 
| 57418 | 421 |   by (simp add: inter_restrict [symmetric, of A "{x. P x}" g, simplified mem_Collect_eq] Int_def)
 | 
| 422 | ||
| 423 | lemma Union_comp: | |
| 424 | assumes "\<forall>A \<in> B. finite A" | |
| 63654 | 425 | 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 | 426 | shows "F g (\<Union>B) = (F \<circ> F) g B" | 
| 63654 | 427 | using assms | 
| 428 | proof (induct B rule: infinite_finite_induct) | |
| 57418 | 429 | case (infinite A) | 
| 430 | then have "\<not> finite (\<Union>A)" by (blast dest: finite_UnionD) | |
| 431 | with infinite show ?case by simp | |
| 432 | next | |
| 63654 | 433 | case empty | 
| 434 | then show ?case by simp | |
| 57418 | 435 | next | 
| 436 | case (insert A B) | |
| 437 | 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 | 438 | and "\<forall>x\<in>A \<inter> \<Union>B. g x = \<^bold>1" | 
| 63654 | 439 | 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 | 440 | then have "F g (A \<union> \<Union>B) = F g A \<^bold>* F g (\<Union>B)" | 
| 57418 | 441 | by (simp add: union_inter_neutral) | 
| 60758 | 442 | with \<open>finite B\<close> \<open>A \<notin> B\<close> show ?case | 
| 57418 | 443 | by (simp add: H) | 
| 444 | qed | |
| 445 | ||
| 66804 
3f9bb52082c4
avoid name clashes on interpretation of abstract locales
 haftmann parents: 
66364diff
changeset | 446 | lemma swap: "F (\<lambda>i. F (g i) B) A = F (\<lambda>j. F (\<lambda>i. g i j) A) B" | 
| 57418 | 447 | unfolding cartesian_product | 
| 448 | by (rule reindex_bij_witness [where i = "\<lambda>(i, j). (j, i)" and j = "\<lambda>(i, j). (j, i)"]) auto | |
| 449 | ||
| 66804 
3f9bb52082c4
avoid name clashes on interpretation of abstract locales
 haftmann parents: 
66364diff
changeset | 450 | lemma swap_restrict: | 
| 57418 | 451 | "finite A \<Longrightarrow> finite B \<Longrightarrow> | 
| 452 |     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 | 453 | by (simp add: inter_filter) (rule swap) | 
| 57418 | 454 | |
| 69510 | 455 | lemma image_gen: | 
| 456 | assumes fin: "finite S" | |
| 457 |   shows "F h S = F (\<lambda>y. F h {x. x \<in> S \<and> g x = y}) (g ` S)"
 | |
| 458 | proof - | |
| 459 |   have "{y. y\<in> g`S \<and> g x = y} = {g x}" if "x \<in> S" for x
 | |
| 460 | using that by auto | |
| 461 |   then have "F h S = F (\<lambda>x. F (\<lambda>y. h x) {y. y\<in> g`S \<and> g x = y}) S"
 | |
| 462 | by simp | |
| 463 |   also have "\<dots> = F (\<lambda>y. F h {x. x \<in> S \<and> g x = y}) (g ` S)"
 | |
| 464 | by (rule swap_restrict [OF fin finite_imageI [OF fin]]) | |
| 465 | finally show ?thesis . | |
| 466 | qed | |
| 467 | ||
| 468 | lemma group: | |
| 469 | assumes fS: "finite S" and fT: "finite T" and fST: "g ` S \<subseteq> T" | |
| 470 |   shows "F (\<lambda>y. F h {x. x \<in> S \<and> g x = y}) T = F h S"
 | |
| 471 | unfolding image_gen[OF fS, of h g] | |
| 472 | by (auto intro: neutral mono_neutral_right[OF fT fST]) | |
| 473 | ||
| 57418 | 474 | lemma Plus: | 
| 475 | fixes A :: "'b set" and B :: "'c set" | |
| 476 | 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 | 477 | shows "F g (A <+> B) = F (g \<circ> Inl) A \<^bold>* F (g \<circ> Inr) B" | 
| 57418 | 478 | proof - | 
| 479 | have "A <+> B = Inl ` A \<union> Inr ` B" by auto | |
| 63654 | 480 | moreover from fin have "finite (Inl ` A)" "finite (Inr ` B)" by auto | 
| 481 |   moreover have "Inl ` A \<inter> Inr ` B = {}" by auto
 | |
| 482 | moreover have "inj_on Inl A" "inj_on Inr B" by (auto intro: inj_onI) | |
| 483 | ultimately show ?thesis | |
| 484 | using fin by (simp add: union_disjoint reindex) | |
| 57418 | 485 | qed | 
| 486 | ||
| 58195 | 487 | lemma same_carrier: | 
| 488 | assumes "finite C" | |
| 489 | 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 | 490 | 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 | 491 | shows "F g A = F h B \<longleftrightarrow> F g C = F h C" | 
| 492 | proof - | |
| 63654 | 493 | have "finite A" and "finite B" and "finite (C - A)" and "finite (C - B)" | 
| 494 | using \<open>finite C\<close> subset by (auto elim: finite_subset) | |
| 58195 | 495 | from subset have [simp]: "A - (C - A) = A" by auto | 
| 496 | from subset have [simp]: "B - (C - B) = B" by auto | |
| 497 | from subset have "C = A \<union> (C - A)" by auto | |
| 498 | 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 | 499 | also have "\<dots> = F g (A - (C - A)) \<^bold>* F g (C - A - A) \<^bold>* F g (A \<inter> (C - A))" | 
| 60758 | 500 | using \<open>finite A\<close> \<open>finite (C - A)\<close> by (simp only: union_diff2) | 
| 63654 | 501 | finally have *: "F g C = F g A" using trivial by simp | 
| 58195 | 502 | from subset have "C = B \<union> (C - B)" by auto | 
| 503 | 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 | 504 | also have "\<dots> = F h (B - (C - B)) \<^bold>* F h (C - B - B) \<^bold>* F h (B \<inter> (C - B))" | 
| 60758 | 505 | using \<open>finite B\<close> \<open>finite (C - B)\<close> by (simp only: union_diff2) | 
| 63654 | 506 | finally have "F h C = F h B" | 
| 507 | using trivial by simp | |
| 508 | with * show ?thesis by simp | |
| 58195 | 509 | qed | 
| 510 | ||
| 511 | lemma same_carrierI: | |
| 512 | assumes "finite C" | |
| 513 | 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 | 514 | 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 | 515 | assumes "F g C = F h C" | 
| 516 | shows "F g A = F h B" | |
| 517 | using assms same_carrier [of C A B] by simp | |
| 518 | ||
| 69700 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 519 | lemma eq_general: | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 520 | 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 | 521 | 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 | 522 | proof - | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 523 | have eq: "B = h ` A" | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 524 | by (auto dest: assms) | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 525 | 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 | 526 | 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 | 527 | 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 | 528 | using A by auto | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 529 | 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 | 530 | 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 | 531 | finally show ?thesis . | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 532 | qed | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 533 | |
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 534 | lemma eq_general_inverses: | 
| 
7a92cbec7030
new material about summations and powers, along with some tweaks
 paulson <lp15@cam.ac.uk> parents: 
69654diff
changeset | 535 | 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 | 536 | 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 | 537 | 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 | 538 | |
| 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 | 539 | 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 | 540 | 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 | 541 | |
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 542 | 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 | 543 |   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 | 544 | |
| 
da5857dbcbb9
More group theory. Sum and product indexed by the non-neutral part of a set
 paulson <lp15@cam.ac.uk> parents: 
69802diff
changeset | 545 | 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 | 546 |   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 | 547 |   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 | 548 | 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 | 549 | |
| 
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 | 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 | 551 | 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 | 552 | |
| 
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 | 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 | 554 | 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 | 555 | |
| 
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 | 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 | 557 |   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 | 558 | 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 | 559 | 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 | 560 |   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 | 561 | 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 | 562 | 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 | 563 | 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 | 564 | 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 | 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 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 | 567 | 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 | 568 | 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 | 569 | 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 | 570 | |
| 
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 | 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 | 572 | 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 | 573 | |
| 
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 | 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 | 575 |   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 | 576 | 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 | 577 | 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 | 578 | 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 | 579 | 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 | 580 |   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 | 581 | 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 | 582 | 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 | 583 | 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 | 584 |     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 | 585 |          "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 | 586 | 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 | 587 | 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 | 588 | 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 | 589 | 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 | 590 | 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 | 591 | 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 | 592 | |
| 
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 | 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 | 594 | 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 | 595 | 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 | 596 | 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 | 597 | 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 | 598 | |
| 
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 | |
| 
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 | 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 | 601 | 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 | 602 | 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 | 603 | 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 | 604 | 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 | 605 | 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 | 606 |   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 | 607 | 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 | 608 |   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 | 609 | 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 | 610 | 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 | 611 | 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 | 612 | 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 | 613 | |
| 
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 | 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 | 615 | "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 | 616 | 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 | 617 | 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 | 618 | |
| 
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 | 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 | 620 | 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 | 621 | |
| 
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 | 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 | 623 | 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 | 624 | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 625 | end | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 626 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 627 | |
| 60758 | 628 | subsection \<open>Generalized summation over a set\<close> | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 629 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 630 | context comm_monoid_add | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 631 | begin | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 632 | |
| 64267 | 633 | 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 | 634 | defines sum = sum.F and sum' = sum.G .. | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 635 | |
| 69767 
d10fafeb93c0
less special syntax: make \<Sum> an ordinary function symbol
 nipkow parents: 
69700diff
changeset | 636 | abbreviation Sum ("\<Sum>")
 | 
| 
d10fafeb93c0
less special syntax: make \<Sum> an ordinary function symbol
 nipkow parents: 
69700diff
changeset | 637 | where "\<Sum> \<equiv> sum (\<lambda>x. x)" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 638 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 639 | end | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 640 | |
| 69593 | 641 | 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 | 642 | |
| 61955 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61952diff
changeset | 643 | syntax (ASCII) | 
| 67268 
bdf25939a550
new/improved theories involving convergence; better pretty-printing for bounded quantifiers and sum/product
 paulson <lp15@cam.ac.uk> parents: 
66936diff
changeset | 644 |   "_sum" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b::comm_monoid_add"  ("(3SUM (_/:_)./ _)" [0, 51, 10] 10)
 | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 645 | syntax | 
| 67268 
bdf25939a550
new/improved theories involving convergence; better pretty-printing for bounded quantifiers and sum/product
 paulson <lp15@cam.ac.uk> parents: 
66936diff
changeset | 646 |   "_sum" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b::comm_monoid_add"  ("(2\<Sum>(_/\<in>_)./ _)" [0, 51, 10] 10)
 | 
| 61799 | 647 | translations \<comment> \<open>Beware of argument permutation!\<close> | 
| 64267 | 648 | "\<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 | 649 | |
| 69593 | 650 | 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 | 651 | |
| 61955 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61952diff
changeset | 652 | syntax (ASCII) | 
| 64267 | 653 |   "_qsum" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a"  ("(3SUM _ |/ _./ _)" [0, 0, 10] 10)
 | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 654 | syntax | 
| 64267 | 655 |   "_qsum" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a"  ("(2\<Sum>_ | (_)./ _)" [0, 0, 10] 10)
 | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 656 | translations | 
| 64267 | 657 |   "\<Sum>x|P. t" => "CONST sum (\<lambda>x. t) {x. P}"
 | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 658 | |
| 60758 | 659 | print_translation \<open> | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 660 | let | 
| 69593 | 661 | fun sum_tr' [Abs (x, Tx, t), Const (\<^const_syntax>\<open>Collect\<close>, _) $ Abs (y, Ty, P)] = | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 662 | if x <> y then raise Match | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 663 | else | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 664 | let | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 665 | val x' = Syntax_Trans.mark_bound_body (x, Tx); | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 666 | val t' = subst_bound (x', t); | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 667 | val P' = subst_bound (x', P); | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 668 | in | 
| 69593 | 669 | Syntax.const \<^syntax_const>\<open>_qsum\<close> $ Syntax_Trans.mark_bound_abs (x, Tx) $ P' $ t' | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 670 | end | 
| 64267 | 671 | | sum_tr' _ = raise Match; | 
| 69593 | 672 | in [(\<^const_syntax>\<open>sum\<close>, K sum_tr')] end | 
| 60758 | 673 | \<close> | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 674 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 675 | |
| 60758 | 676 | subsubsection \<open>Properties in more restricted classes of structures\<close> | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 677 | |
| 64267 | 678 | lemma sum_Un: | 
| 679 | "finite A \<Longrightarrow> finite B \<Longrightarrow> sum f (A \<union> B) = sum f A + sum f B - sum f (A \<inter> B)" | |
| 63654 | 680 | for f :: "'b \<Rightarrow> 'a::ab_group_add" | 
| 64267 | 681 | 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 | 682 | |
| 64267 | 683 | lemma sum_Un2: | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 684 | assumes "finite (A \<union> B)" | 
| 64267 | 685 | 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 | 686 | proof - | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 687 | 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 | 688 | by auto | 
| 63654 | 689 | with assms show ?thesis | 
| 64267 | 690 | by simp (subst sum.union_disjoint, auto)+ | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 691 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 692 | |
| 64267 | 693 | lemma sum_diff1: | 
| 63654 | 694 | fixes f :: "'b \<Rightarrow> 'a::ab_group_add" | 
| 695 | assumes "finite A" | |
| 64267 | 696 |   shows "sum f (A - {a}) = (if a \<in> A then sum f A - f a else sum f A)"
 | 
| 63654 | 697 | using assms by induct (auto simp: insert_Diff_if) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 698 | |
| 64267 | 699 | lemma sum_diff: | 
| 63654 | 700 | fixes f :: "'b \<Rightarrow> 'a::ab_group_add" | 
| 701 | assumes "finite A" "B \<subseteq> A" | |
| 64267 | 702 | shows "sum f (A - B) = sum f A - sum f B" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 703 | proof - | 
| 63654 | 704 | from assms(2,1) have "finite B" by (rule finite_subset) | 
| 705 | from this \<open>B \<subseteq> A\<close> | |
| 706 | show ?thesis | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 707 | proof induct | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 708 | case empty | 
| 63654 | 709 | thus ?case by simp | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 710 | next | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 711 | case (insert x F) | 
| 63654 | 712 | with \<open>finite A\<close> \<open>finite B\<close> show ?case | 
| 64267 | 713 | by (simp add: Diff_insert[where a=x and B=F] sum_diff1 insert_absorb) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 714 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 715 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 716 | |
| 70045 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 717 | 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 | 718 | 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 | 719 |   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 | 720 |   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 | 721 | 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 | 722 | 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 | 723 | 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 | 724 |   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 | 725 | 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 | 726 |   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 | 727 | 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 | 728 | 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 | 729 |   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 | 730 | 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 | 731 | 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 | 732 |     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 | 733 | 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 | 734 | 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 | 735 | |
| 
7b6add80e3a5
fixed markup in Poly_Mapping; Free_Abelian_Groups (but not yet imported by Algebra!)
 paulson <lp15@cam.ac.uk> parents: 
70044diff
changeset | 736 | 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 | 737 | 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 | 738 |   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 | 739 |   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 | 740 | 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 | 741 | |
| 64267 | 742 | lemma (in ordered_comm_monoid_add) sum_mono: | 
| 63915 | 743 | "(\<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)" | 
| 744 | 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 | 745 | |
| 64267 | 746 | lemma (in strict_ordered_comm_monoid_add) sum_strict_mono: | 
| 63654 | 747 |   assumes "finite A" "A \<noteq> {}"
 | 
| 748 | and "\<And>x. x \<in> A \<Longrightarrow> f x < g x" | |
| 64267 | 749 | shows "sum f A < sum g A" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 750 | using assms | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 751 | proof (induct rule: finite_ne_induct) | 
| 63654 | 752 | case singleton | 
| 753 | then show ?case by simp | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 754 | next | 
| 63654 | 755 | case insert | 
| 756 | then show ?case by (auto simp: add_strict_mono) | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 757 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 758 | |
| 64267 | 759 | 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 | 760 | fixes f g :: "'i \<Rightarrow> 'a::ordered_cancel_comm_monoid_add" | 
| 63654 | 761 | assumes "finite A" | 
| 762 | and "\<forall>x\<in>A. f x \<le> g x" | |
| 763 | and "\<exists>a\<in>A. f a < g a" | |
| 64267 | 764 | shows "sum f A < sum g A" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 765 | proof- | 
| 63654 | 766 | from assms(3) obtain a where a: "a \<in> A" "f a < g a" by blast | 
| 64267 | 767 |   have "sum f A = sum f ((A - {a}) \<union> {a})"
 | 
| 63654 | 768 | by(simp add: insert_absorb[OF \<open>a \<in> A\<close>]) | 
| 64267 | 769 |   also have "\<dots> = sum f (A - {a}) + sum f {a}"
 | 
| 770 | using \<open>finite A\<close> by(subst sum.union_disjoint) auto | |
| 771 |   also have "sum f (A - {a}) \<le> sum g (A - {a})"
 | |
| 772 | by (rule sum_mono) (simp add: assms(2)) | |
| 773 |   also from a have "sum f {a} < sum g {a}" by simp
 | |
| 774 |   also have "sum g (A - {a}) + sum g {a} = sum g((A - {a}) \<union> {a})"
 | |
| 775 | using \<open>finite A\<close> by (subst sum.union_disjoint[symmetric]) auto | |
| 776 | also have "\<dots> = sum g A" by (simp add: insert_absorb[OF \<open>a \<in> A\<close>]) | |
| 63654 | 777 | finally show ?thesis | 
| 778 | 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 | 779 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 780 | |
| 64267 | 781 | lemma sum_mono_inv: | 
| 63561 
fba08009ff3e
add lemmas contributed by Peter Gammie
 Andreas Lochbihler parents: 
63357diff
changeset | 782 | fixes f g :: "'i \<Rightarrow> 'a :: ordered_cancel_comm_monoid_add" | 
| 64267 | 783 | assumes eq: "sum f I = sum g I" | 
| 63561 
fba08009ff3e
add lemmas contributed by Peter Gammie
 Andreas Lochbihler parents: 
63357diff
changeset | 784 | 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 | 785 | assumes i: "i \<in> I" | 
| 
fba08009ff3e
add lemmas contributed by Peter Gammie
 Andreas Lochbihler parents: 
63357diff
changeset | 786 | assumes I: "finite I" | 
| 
fba08009ff3e
add lemmas contributed by Peter Gammie
 Andreas Lochbihler parents: 
63357diff
changeset | 787 | shows "f i = g i" | 
| 63654 | 788 | proof (rule ccontr) | 
| 789 | assume "\<not> ?thesis" | |
| 63561 
fba08009ff3e
add lemmas contributed by Peter Gammie
 Andreas Lochbihler parents: 
63357diff
changeset | 790 | with le[OF i] have "f i < g i" by simp | 
| 63654 | 791 | with i have "\<exists>i\<in>I. f i < g i" .. | 
| 64267 | 792 | from sum_strict_mono_ex1[OF I _ this] le have "sum f I < sum g I" | 
| 63654 | 793 | by blast | 
| 63561 
fba08009ff3e
add lemmas contributed by Peter Gammie
 Andreas Lochbihler parents: 
63357diff
changeset | 794 | with eq show False by simp | 
| 
fba08009ff3e
add lemmas contributed by Peter Gammie
 Andreas Lochbihler parents: 
63357diff
changeset | 795 | qed | 
| 
fba08009ff3e
add lemmas contributed by Peter Gammie
 Andreas Lochbihler parents: 
63357diff
changeset | 796 | |
| 64267 | 797 | lemma member_le_sum: | 
| 63938 | 798 |   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 | 799 | assumes "i \<in> A" | 
| 
0e640e04fc56
New theorems; stronger theorems; tidier theorems. Also some renaming
 paulson <lp15@cam.ac.uk> parents: 
66089diff
changeset | 800 |     and le: "\<And>x. x \<in> A - {i} \<Longrightarrow> 0 \<le> f x"
 | 
| 63938 | 801 | and "finite A" | 
| 64267 | 802 | shows "f i \<le> sum f A" | 
| 63938 | 803 | proof - | 
| 64267 | 804 |   have "f i \<le> sum f (A \<inter> {i})"
 | 
| 63938 | 805 | by (simp add: assms) | 
| 806 |   also have "... = (\<Sum>x\<in>A. if x \<in> {i} then f x else 0)"
 | |
| 64267 | 807 | using assms sum.inter_restrict by blast | 
| 808 | also have "... \<le> sum f A" | |
| 809 | apply (rule sum_mono) | |
| 63938 | 810 | apply (auto simp: le) | 
| 811 | done | |
| 812 | finally show ?thesis . | |
| 813 | qed | |
| 814 | ||
| 64267 | 815 | lemma sum_negf: "(\<Sum>x\<in>A. - f x) = - (\<Sum>x\<in>A. f x)" | 
| 63654 | 816 | for f :: "'b \<Rightarrow> 'a::ab_group_add" | 
| 63915 | 817 | by (induct A rule: infinite_finite_induct) auto | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 818 | |
| 64267 | 819 | lemma sum_subtractf: "(\<Sum>x\<in>A. f x - g x) = (\<Sum>x\<in>A. f x) - (\<Sum>x\<in>A. g x)" | 
| 63654 | 820 | for f g :: "'b \<Rightarrow>'a::ab_group_add" | 
| 64267 | 821 | 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 | 822 | |
| 64267 | 823 | lemma sum_subtractf_nat: | 
| 63654 | 824 | "(\<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)" | 
| 825 | for f g :: "'a \<Rightarrow> nat" | |
| 64267 | 826 | 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 | 827 | |
| 63654 | 828 | context ordered_comm_monoid_add | 
| 829 | begin | |
| 830 | ||
| 65680 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 831 | lemma sum_nonneg: "(\<And>x. x \<in> A \<Longrightarrow> 0 \<le> f x) \<Longrightarrow> 0 \<le> sum f A" | 
| 63915 | 832 | proof (induct A rule: infinite_finite_induct) | 
| 833 | case infinite | |
| 834 | then show ?case by simp | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 835 | next | 
| 63915 | 836 | case empty | 
| 837 | then show ?case by simp | |
| 838 | next | |
| 839 | case (insert x F) | |
| 64267 | 840 | then have "0 + 0 \<le> f x + sum f F" by (blast intro: add_mono) | 
| 63915 | 841 | with insert show ?case by simp | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 842 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 843 | |
| 65680 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 844 | lemma sum_nonpos: "(\<And>x. x \<in> A \<Longrightarrow> f x \<le> 0) \<Longrightarrow> sum f A \<le> 0" | 
| 63915 | 845 | proof (induct A rule: infinite_finite_induct) | 
| 846 | case infinite | |
| 847 | then show ?case by simp | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 848 | next | 
| 63915 | 849 | case empty | 
| 850 | then show ?case by simp | |
| 851 | next | |
| 852 | case (insert x F) | |
| 64267 | 853 | then have "f x + sum f F \<le> 0 + 0" by (blast intro: add_mono) | 
| 63915 | 854 | with insert show ?case by simp | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 855 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 856 | |
| 64267 | 857 | 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 | 858 | "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 | 859 | 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 | 860 | |
| 64267 | 861 | 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 | 862 | "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 | 863 | 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 | 864 | |
| 64267 | 865 | lemma sum_nonneg_leq_bound: | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 866 | 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 | 867 | shows "f i \<le> B" | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 868 | proof - | 
| 63654 | 869 |   from assms have "f i \<le> f i + (\<Sum>i \<in> s - {i}. f i)"
 | 
| 64267 | 870 | 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 | 871 | also have "\<dots> = B" | 
| 64267 | 872 | 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 | 873 | finally show ?thesis by auto | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 874 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 875 | |
| 64267 | 876 | lemma sum_mono2: | 
| 63654 | 877 | assumes fin: "finite B" | 
| 878 | and sub: "A \<subseteq> B" | |
| 879 | and nn: "\<And>b. b \<in> B-A \<Longrightarrow> 0 \<le> f b" | |
| 64267 | 880 | shows "sum f A \<le> sum f B" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 881 | proof - | 
| 64267 | 882 | 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 | 883 | by (auto intro: add_increasing2 [OF sum_nonneg] nn) | 
| 64267 | 884 | also from fin finite_subset[OF sub fin] have "\<dots> = sum f (A \<union> (B-A))" | 
| 885 | by (simp add: sum.union_disjoint del: Un_Diff_cancel) | |
| 63654 | 886 | 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 | 887 | finally show ?thesis . | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 888 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 889 | |
| 64267 | 890 | lemma sum_le_included: | 
| 57418 | 891 | assumes "finite s" "finite t" | 
| 892 | 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 | 893 | shows "sum f s \<le> sum g t" | 
| 57418 | 894 | proof - | 
| 64267 | 895 |   have "sum f s \<le> sum (\<lambda>y. sum g {x. x\<in>t \<and> i x = y}) s"
 | 
| 896 | proof (rule sum_mono) | |
| 63654 | 897 | fix y | 
| 898 | assume "y \<in> s" | |
| 57418 | 899 | with assms obtain z where z: "z \<in> t" "y = i z" "f y \<le> g z" by auto | 
| 64267 | 900 |     with assms show "f y \<le> sum g {x \<in> t. i x = y}" (is "?A y \<le> ?B y")
 | 
| 901 |       using order_trans[of "?A (i z)" "sum g {z}" "?B (i z)", intro]
 | |
| 902 | by (auto intro!: sum_mono2) | |
| 57418 | 903 | qed | 
| 64267 | 904 |   also have "\<dots> \<le> sum (\<lambda>y. sum g {x. x\<in>t \<and> i x = y}) (i ` t)"
 | 
| 905 | using assms(2-4) by (auto intro!: sum_mono2 sum_nonneg) | |
| 906 | also have "\<dots> \<le> sum g t" | |
| 69510 | 907 | using assms by (auto simp: sum.image_gen[symmetric]) | 
| 57418 | 908 | finally show ?thesis . | 
| 909 | qed | |
| 910 | ||
| 63654 | 911 | end | 
| 912 | ||
| 64267 | 913 | lemma (in canonically_ordered_monoid_add) sum_eq_0_iff [simp]: | 
| 914 | "finite F \<Longrightarrow> (sum f F = 0) = (\<forall>a\<in>F. f a = 0)" | |
| 915 | 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 | 916 | |
| 66936 | 917 | context semiring_0 | 
| 918 | begin | |
| 919 | ||
| 920 | lemma sum_distrib_left: "r * sum f A = (\<Sum>n\<in>A. r * f n)" | |
| 921 | 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 | 922 | |
| 64267 | 923 | lemma sum_distrib_right: "sum f A * r = (\<Sum>n\<in>A. f n * r)" | 
| 66936 | 924 | by (induct A rule: infinite_finite_induct) (simp_all add: algebra_simps) | 
| 925 | ||
| 926 | end | |
| 63654 | 927 | |
| 64267 | 928 | lemma sum_divide_distrib: "sum f A / r = (\<Sum>n\<in>A. f n / r)" | 
| 63654 | 929 | for r :: "'a::field" | 
| 63915 | 930 | proof (induct A rule: infinite_finite_induct) | 
| 931 | case infinite | |
| 932 | then show ?case by simp | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 933 | next | 
| 63915 | 934 | case empty | 
| 935 | then show ?case by simp | |
| 936 | next | |
| 937 | case insert | |
| 938 | then show ?case by (simp add: add_divide_distrib) | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 939 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 940 | |
| 64267 | 941 | lemma sum_abs[iff]: "\<bar>sum f A\<bar> \<le> sum (\<lambda>i. \<bar>f i\<bar>) A" | 
| 63654 | 942 | for f :: "'a \<Rightarrow> 'b::ordered_ab_group_add_abs" | 
| 63915 | 943 | proof (induct A rule: infinite_finite_induct) | 
| 944 | case infinite | |
| 945 | then show ?case by simp | |
| 63654 | 946 | next | 
| 63915 | 947 | case empty | 
| 948 | then show ?case by simp | |
| 949 | next | |
| 950 | case insert | |
| 951 | then show ?case by (auto intro: abs_triangle_ineq order_trans) | |
| 63654 | 952 | qed | 
| 953 | ||
| 64267 | 954 | lemma sum_abs_ge_zero[iff]: "0 \<le> sum (\<lambda>i. \<bar>f i\<bar>) A" | 
| 63654 | 955 | for f :: "'a \<Rightarrow> 'b::ordered_ab_group_add_abs" | 
| 64267 | 956 | by (simp add: sum_nonneg) | 
| 63654 | 957 | |
| 64267 | 958 | lemma abs_sum_abs[simp]: "\<bar>\<Sum>a\<in>A. \<bar>f a\<bar>\<bar> = (\<Sum>a\<in>A. \<bar>f a\<bar>)" | 
| 63654 | 959 | for f :: "'a \<Rightarrow> 'b::ordered_ab_group_add_abs" | 
| 63915 | 960 | proof (induct A rule: infinite_finite_induct) | 
| 961 | case infinite | |
| 962 | then show ?case by simp | |
| 963 | next | |
| 964 | case empty | |
| 965 | then show ?case by simp | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 966 | next | 
| 63915 | 967 | case (insert a A) | 
| 968 | 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 | |
| 969 | also from insert have "\<dots> = \<bar>\<bar>f a\<bar> + \<bar>\<Sum>a\<in>A. \<bar>f a\<bar>\<bar>\<bar>" by simp | |
| 970 | also have "\<dots> = \<bar>f a\<bar> + \<bar>\<Sum>a\<in>A. \<bar>f a\<bar>\<bar>" by (simp del: abs_of_nonneg) | |
| 971 | also from insert have "\<dots> = (\<Sum>a\<in>insert a A. \<bar>f a\<bar>)" by simp | |
| 972 | finally show ?case . | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 973 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 974 | |
| 64267 | 975 | lemma sum_product: | 
| 63654 | 976 | fixes f :: "'a \<Rightarrow> 'b::semiring_0" | 
| 64267 | 977 | 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 | 978 | 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 | 979 | |
| 64267 | 980 | lemma sum_mult_sum_if_inj: | 
| 63654 | 981 | fixes f :: "'a \<Rightarrow> 'b::semiring_0" | 
| 982 | shows "inj_on (\<lambda>(a, b). f a * g b) (A \<times> B) \<Longrightarrow> | |
| 64267 | 983 |     sum f A * sum g B = sum id {f a * g b |a b. a \<in> A \<and> b \<in> B}"
 | 
| 984 | 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 | 985 | |
| 64267 | 986 | lemma sum_SucD: "sum f A = Suc n \<Longrightarrow> \<exists>a\<in>A. 0 < f a" | 
| 63915 | 987 | by (induct A rule: infinite_finite_induct) auto | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 988 | |
| 64267 | 989 | lemma sum_eq_Suc0_iff: | 
| 990 | "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 | 991 | 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 | 992 | |
| 64267 | 993 | 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 | 994 | |
| 64267 | 995 | lemma sum_Un_nat: | 
| 996 | "finite A \<Longrightarrow> finite B \<Longrightarrow> sum f (A \<union> B) = sum f A + sum f B - sum f (A \<inter> B)" | |
| 63654 | 997 | for f :: "'a \<Rightarrow> nat" | 
| 61799 | 998 | \<comment> \<open>For the natural numbers, we have subtraction.\<close> | 
| 64267 | 999 | by (subst sum.union_inter [symmetric]) (auto simp: algebra_simps) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1000 | |
| 64267 | 1001 | lemma sum_diff1_nat: "sum f (A - {a}) = (if a \<in> A then sum f A - f a else sum f A)"
 | 
| 63654 | 1002 | for f :: "'a \<Rightarrow> nat" | 
| 63915 | 1003 | proof (induct A rule: infinite_finite_induct) | 
| 1004 | case infinite | |
| 1005 | then show ?case by simp | |
| 1006 | next | |
| 1007 | case empty | |
| 1008 | then show ?case by simp | |
| 1009 | next | |
| 1010 | case insert | |
| 1011 | then show ?case | |
| 1012 | apply (auto simp: insert_Diff_if) | |
| 63654 | 1013 | apply (drule mk_disjoint_insert) | 
| 1014 | apply auto | |
| 1015 | done | |
| 1016 | qed | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1017 | |
| 64267 | 1018 | lemma sum_diff_nat: | 
| 63654 | 1019 | fixes f :: "'a \<Rightarrow> nat" | 
| 1020 | assumes "finite B" and "B \<subseteq> A" | |
| 64267 | 1021 | shows "sum f (A - B) = sum f A - sum f B" | 
| 63654 | 1022 | using assms | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1023 | proof induct | 
| 63654 | 1024 | case empty | 
| 1025 | then show ?case by simp | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1026 | next | 
| 63654 | 1027 | case (insert x F) | 
| 64267 | 1028 | note IH = \<open>F \<subseteq> A \<Longrightarrow> sum f (A - F) = sum f A - sum f F\<close> | 
| 63654 | 1029 | from \<open>x \<notin> F\<close> \<open>insert x F \<subseteq> A\<close> have "x \<in> A - F" by simp | 
| 64267 | 1030 |   then have A: "sum f ((A - F) - {x}) = sum f (A - F) - f x"
 | 
| 1031 | by (simp add: sum_diff1_nat) | |
| 63654 | 1032 | from \<open>insert x F \<subseteq> A\<close> have "F \<subseteq> A" by simp | 
| 64267 | 1033 | with IH have "sum f (A - F) = sum f A - sum f F" by simp | 
| 1034 |   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 | 1035 | by simp | 
| 63654 | 1036 |   from \<open>x \<notin> F\<close> have "A - insert x F = (A - F) - {x}" by auto
 | 
| 64267 | 1037 | 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 | 1038 | by simp | 
| 64267 | 1039 | from \<open>finite F\<close> \<open>x \<notin> F\<close> have "sum f (insert x F) = sum f F + f x" | 
| 63654 | 1040 | by simp | 
| 64267 | 1041 | 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 | 1042 | by simp | 
| 63654 | 1043 | then show ?case by simp | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1044 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1045 | |
| 64267 | 1046 | lemma sum_comp_morphism: | 
| 1047 | "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 | 1048 | by (induct A rule: infinite_finite_induct) simp_all | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1049 | |
| 64267 | 1050 | lemma (in comm_semiring_1) dvd_sum: "(\<And>a. a \<in> A \<Longrightarrow> d dvd f a) \<Longrightarrow> d dvd sum f A" | 
| 59010 | 1051 | by (induct A rule: infinite_finite_induct) simp_all | 
| 1052 | ||
| 64267 | 1053 | lemma (in ordered_comm_monoid_add) sum_pos: | 
| 1054 |   "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 | 1055 | 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 | 1056 | |
| 64267 | 1057 | 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 | 1058 | assumes I: "finite I" "i \<in> I" "0 < f i" "\<And>i. i \<in> I \<Longrightarrow> 0 \<le> f i" | 
| 64267 | 1059 | 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 | 1060 | proof - | 
| 64267 | 1061 |   have "0 < f i + sum f (I - {i})"
 | 
| 1062 | using assms by (intro add_pos_nonneg sum_nonneg) auto | |
| 1063 | also have "\<dots> = sum f I" | |
| 1064 | 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 | 1065 | finally show ?thesis . | 
| 
6a6f15d8fbc4
New material and fixes related to the forthcoming Stone-Weierstrass development
 paulson <lp15@cam.ac.uk> parents: 
60758diff
changeset | 1066 | qed | 
| 
6a6f15d8fbc4
New material and fixes related to the forthcoming Stone-Weierstrass development
 paulson <lp15@cam.ac.uk> parents: 
60758diff
changeset | 1067 | |
| 64267 | 1068 | lemma sum_cong_Suc: | 
| 61524 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61378diff
changeset | 1069 | assumes "0 \<notin> A" "\<And>x. Suc x \<in> A \<Longrightarrow> f (Suc x) = g (Suc x)" | 
| 64267 | 1070 | shows "sum f A = sum g A" | 
| 1071 | proof (rule sum.cong) | |
| 63654 | 1072 | fix x | 
| 1073 | assume "x \<in> A" | |
| 1074 | with assms(1) show "f x = g x" | |
| 1075 | by (cases x) (auto intro!: assms(2)) | |
| 61524 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61378diff
changeset | 1076 | qed simp_all | 
| 
f2e51e704a96
added many small lemmas about setsum/setprod/powr/...
 eberlm parents: 
61378diff
changeset | 1077 | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1078 | |
| 69593 | 1079 | 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 | 1080 | |
| 64267 | 1081 | 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 | 1082 | proof - | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1083 | have "plus \<circ> (\<lambda>_. Suc 0) = (\<lambda>_. Suc)" | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1084 | by (simp add: fun_eq_iff) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1085 | 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 | 1086 | by (rule arg_cong) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1087 | 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 | 1088 | by (blast intro: fun_cong) | 
| 63654 | 1089 | then show ?thesis | 
| 64267 | 1090 | by (simp add: card.eq_fold sum.eq_fold) | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1091 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1092 | |
| 66936 | 1093 | context semiring_1 | 
| 1094 | begin | |
| 1095 | ||
| 1096 | lemma sum_constant [simp]: | |
| 1097 | "(\<Sum>x \<in> A. y) = of_nat (card A) * y" | |
| 1098 | by (induct A rule: infinite_finite_induct) (simp_all add: algebra_simps) | |
| 1099 | ||
| 1100 | end | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1101 | |
| 64267 | 1102 | lemma sum_Suc: "sum (\<lambda>x. Suc(f x)) A = sum f A + card A" | 
| 1103 | using sum.distrib[of f "\<lambda>_. 1" A] by simp | |
| 58349 | 1104 | |
| 64267 | 1105 | lemma sum_bounded_above: | 
| 63654 | 1106 |   fixes K :: "'a::{semiring_1,ordered_comm_monoid_add}"
 | 
| 1107 | assumes le: "\<And>i. i\<in>A \<Longrightarrow> f i \<le> K" | |
| 64267 | 1108 | shows "sum f A \<le> of_nat (card A) * K" | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1109 | proof (cases "finite A") | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1110 | case True | 
| 63654 | 1111 | then show ?thesis | 
| 64267 | 1112 | 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 | 1113 | next | 
| 63654 | 1114 | case False | 
| 1115 | then show ?thesis by simp | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1116 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1117 | |
| 69144 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1118 | 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 | 1119 | 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 | 1120 |   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 | 1121 | 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 | 1122 | 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 | 1123 | |
| 64267 | 1124 | lemma sum_bounded_above_strict: | 
| 63654 | 1125 |   fixes K :: "'a::{ordered_cancel_comm_monoid_add,semiring_1}"
 | 
| 1126 | assumes "\<And>i. i\<in>A \<Longrightarrow> f i < K" "card A > 0" | |
| 64267 | 1127 | shows "sum f A < of_nat (card A) * K" | 
| 1128 | using assms sum_strict_mono[where A=A and g = "\<lambda>x. K"] | |
| 63654 | 1129 | 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 | 1130 | |
| 64267 | 1131 | lemma sum_bounded_below: | 
| 63654 | 1132 |   fixes K :: "'a::{semiring_1,ordered_comm_monoid_add}"
 | 
| 1133 | assumes le: "\<And>i. i\<in>A \<Longrightarrow> K \<le> f i" | |
| 64267 | 1134 | 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 | 1135 | proof (cases "finite A") | 
| 
6a6f15d8fbc4
New material and fixes related to the forthcoming Stone-Weierstrass development
 paulson <lp15@cam.ac.uk> parents: 
60758diff
changeset | 1136 | case True | 
| 63654 | 1137 | then show ?thesis | 
| 64267 | 1138 | 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 | 1139 | next | 
| 63654 | 1140 | case False | 
| 1141 | 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 | 1142 | qed | 
| 
6a6f15d8fbc4
New material and fixes related to the forthcoming Stone-Weierstrass development
 paulson <lp15@cam.ac.uk> parents: 
60758diff
changeset | 1143 | |
| 69144 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1144 | 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 | 1145 | 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 | 1146 | 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 | 1147 | 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 | 1148 | 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 | 1149 | proof - | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1150 | 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 | 1151 | 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 | 1152 | 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 | 1153 | 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 | 1154 | 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 | 1155 | 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 | 1156 | 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 | 1157 | 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 | 1158 | 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 | 1159 | 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 | 1160 | 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 | 1161 | 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 | 1162 | 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 | 1163 | qed | 
| 
f13b82281715
new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
 paulson <lp15@cam.ac.uk> parents: 
69127diff
changeset | 1164 | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1165 | lemma card_UN_disjoint: | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1166 | assumes "finite I" and "\<forall>i\<in>I. finite (A i)" | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1167 |     and "\<forall>i\<in>I. \<forall>j\<in>I. i \<noteq> j \<longrightarrow> A i \<inter> A j = {}"
 | 
| 69275 | 1168 | 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 | 1169 | proof - | 
| 63654 | 1170 | have "(\<Sum>i\<in>I. card (A i)) = (\<Sum>i\<in>I. \<Sum>x\<in>A i. 1)" | 
| 1171 | by simp | |
| 1172 | with assms show ?thesis | |
| 64267 | 1173 | 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 | 1174 | qed | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1175 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1176 | 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 | 1177 | 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 | 1178 | 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 | 1179 | 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 | 1180 | case True | 
| 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1181 | then show ?thesis | 
| 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1182 | 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 | 1183 | 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 | 1184 | next | 
| 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1185 | case False | 
| 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1186 | then show ?thesis | 
| 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1187 | 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 | 1188 | qed | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1189 | |
| 71356 | 1190 | lemma card_Union_le_sum_card: | 
| 1191 | fixes U :: "'a set set" | |
| 1192 | assumes "\<forall>u \<in> U. finite u" | |
| 1193 | shows "card (\<Union>U) \<le> sum card U" | |
| 1194 | proof (cases "finite U") | |
| 1195 | case False | |
| 1196 | then show "card (\<Union>U) \<le> sum card U" | |
| 1197 | using card_eq_0_iff finite_UnionD by auto | |
| 1198 | next | |
| 1199 | case True | |
| 1200 | then show "card (\<Union>U) \<le> sum card U" | |
| 1201 | proof (induct U rule: finite_induct) | |
| 1202 | case empty | |
| 1203 | then show ?case by auto | |
| 1204 | next | |
| 1205 | case (insert x F) | |
| 1206 | then have "card(\<Union>(insert x F)) \<le> card(x) + card (\<Union>F)" using card_Un_le by auto | |
| 1207 | also have "... \<le> card(x) + sum card F" using insert.hyps by auto | |
| 1208 | also have "... = sum card (insert x F)" using sum.insert_if and insert.hyps by auto | |
| 1209 | finally show ?case . | |
| 1210 | qed | |
| 1211 | qed | |
| 1212 | ||
| 70723 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70128diff
changeset | 1213 | lemma card_UN_le: | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70128diff
changeset | 1214 | assumes "finite I" | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70128diff
changeset | 1215 | 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 | 1216 | using assms | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70128diff
changeset | 1217 | proof induction | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70128diff
changeset | 1218 | case (insert i I) | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70128diff
changeset | 1219 | then show ?case | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70128diff
changeset | 1220 | 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 | 1221 | qed auto | 
| 
4e39d87c9737
imported new material mostly due to Sébastien Gouëzel
 paulson <lp15@cam.ac.uk> parents: 
70128diff
changeset | 1222 | |
| 64267 | 1223 | lemma sum_multicount_gen: | 
| 57418 | 1224 |   assumes "finite s" "finite t" "\<forall>j\<in>t. (card {i\<in>s. R i j} = k j)"
 | 
| 64267 | 1225 |   shows "sum (\<lambda>i. (card {j\<in>t. R i j})) s = sum k t"
 | 
| 63654 | 1226 | (is "?l = ?r") | 
| 57418 | 1227 | proof- | 
| 64267 | 1228 |   have "?l = sum (\<lambda>i. sum (\<lambda>x.1) {j\<in>t. R i j}) s"
 | 
| 63654 | 1229 | by auto | 
| 1230 | also have "\<dots> = ?r" | |
| 66804 
3f9bb52082c4
avoid name clashes on interpretation of abstract locales
 haftmann parents: 
66364diff
changeset | 1231 | unfolding sum.swap_restrict [OF assms(1-2)] | 
| 57418 | 1232 | using assms(3) by auto | 
| 1233 | finally show ?thesis . | |
| 1234 | qed | |
| 1235 | ||
| 64267 | 1236 | lemma sum_multicount: | 
| 57418 | 1237 |   assumes "finite S" "finite T" "\<forall>j\<in>T. (card {i\<in>S. R i j} = k)"
 | 
| 64267 | 1238 |   shows "sum (\<lambda>i. card {j\<in>T. R i j}) S = k * card T" (is "?l = ?r")
 | 
| 57418 | 1239 | proof- | 
| 64267 | 1240 | have "?l = sum (\<lambda>i. k) T" | 
| 1241 | 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 | 1242 | also have "\<dots> = ?r" by (simp add: mult.commute) | 
| 57418 | 1243 | finally show ?thesis by auto | 
| 1244 | qed | |
| 1245 | ||
| 67511 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1246 | lemma sum_card_image: | 
| 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1247 | 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 | 1248 | assumes "pairwise (\<lambda>s t. disjnt (f s) (f t)) A" | 
| 67511 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1249 | shows "sum card (f ` A) = sum (\<lambda>a. card (f a)) A" | 
| 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1250 | using assms | 
| 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1251 | proof (induct A) | 
| 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1252 | case (insert a A) | 
| 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1253 | show ?case | 
| 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1254 | proof cases | 
| 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1255 |     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 | 1256 | 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 | 1257 | 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 | 1258 | next | 
| 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1259 |     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 | 1260 | 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 | 1261 | using insert | 
| 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1262 | 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 | 1263 | with insert show ?case by (simp add: pairwise_insert) | 
| 67511 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1264 | qed | 
| 68975 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1265 | qed simp | 
| 67511 
a6f5a78712af
include lemmas generally useful for combinatorial proofs
 bulwahn parents: 
67268diff
changeset | 1266 | |
| 68975 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1267 | |
| 60758 | 1268 | subsubsection \<open>Cardinality of products\<close> | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1269 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1270 | lemma card_SigmaI [simp]: | 
| 63654 | 1271 | "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 | 1272 | 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 | 1273 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1274 | (* | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1275 | lemma SigmaI_insert: "y \<notin> A ==> | 
| 61943 | 1276 |   (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 | 1277 | by auto | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1278 | *) | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1279 | |
| 63654 | 1280 | 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 | 1281 | by (cases "finite A \<and> finite B") | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1282 | (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 | 1283 | |
| 63654 | 1284 | lemma card_cartesian_product_singleton:  "card ({x} \<times> A) = card A"
 | 
| 1285 | by (simp add: card_cartesian_product) | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1286 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1287 | |
| 60758 | 1288 | subsection \<open>Generalized product over a set\<close> | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1289 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1290 | context comm_monoid_mult | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1291 | begin | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1292 | |
| 64272 | 1293 | 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 | 1294 | defines prod = prod.F and prod' = prod.G .. | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1295 | |
| 64272 | 1296 | abbreviation Prod ("\<Prod>_" [1000] 999)
 | 
| 1297 | where "\<Prod>A \<equiv> prod (\<lambda>x. x) A" | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1298 | |
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1299 | end | 
| 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1300 | |
| 61955 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61952diff
changeset | 1301 | syntax (ASCII) | 
| 67268 
bdf25939a550
new/improved theories involving convergence; better pretty-printing for bounded quantifiers and sum/product
 paulson <lp15@cam.ac.uk> parents: 
66936diff
changeset | 1302 |   "_prod" :: "pttrn => 'a set => 'b => 'b::comm_monoid_mult"  ("(4PROD (_/:_)./ _)" [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 | 1303 | syntax | 
| 67268 
bdf25939a550
new/improved theories involving convergence; better pretty-printing for bounded quantifiers and sum/product
 paulson <lp15@cam.ac.uk> parents: 
66936diff
changeset | 1304 |   "_prod" :: "pttrn => 'a set => 'b => 'b::comm_monoid_mult"  ("(2\<Prod>(_/\<in>_)./ _)" [0, 51, 10] 10)
 | 
| 61799 | 1305 | translations \<comment> \<open>Beware of argument permutation!\<close> | 
| 64272 | 1306 | "\<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 | 1307 | |
| 69593 | 1308 | 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 | 1309 | |
| 61955 
e96292f32c3c
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
 wenzelm parents: 
61952diff
changeset | 1310 | syntax (ASCII) | 
| 64272 | 1311 |   "_qprod" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a"  ("(4PROD _ |/ _./ _)" [0, 0, 10] 10)
 | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1312 | syntax | 
| 64272 | 1313 |   "_qprod" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a"  ("(2\<Prod>_ | (_)./ _)" [0, 0, 10] 10)
 | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1314 | translations | 
| 64272 | 1315 |   "\<Prod>x|P. t" => "CONST prod (\<lambda>x. t) {x. P}"
 | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1316 | |
| 59010 | 1317 | context comm_monoid_mult | 
| 1318 | begin | |
| 1319 | ||
| 64272 | 1320 | lemma prod_dvd_prod: "(\<And>a. a \<in> A \<Longrightarrow> f a dvd g a) \<Longrightarrow> prod f A dvd prod g A" | 
| 59010 | 1321 | proof (induct A rule: infinite_finite_induct) | 
| 63654 | 1322 | case infinite | 
| 1323 | then show ?case by (auto intro: dvdI) | |
| 1324 | next | |
| 1325 | case empty | |
| 1326 | then show ?case by (auto intro: dvdI) | |
| 59010 | 1327 | next | 
| 63654 | 1328 | case (insert a A) | 
| 64272 | 1329 | then have "f a dvd g a" and "prod f A dvd prod g A" | 
| 63654 | 1330 | by simp_all | 
| 64272 | 1331 | then obtain r s where "g a = f a * r" and "prod g A = prod f A * s" | 
| 63654 | 1332 | by (auto elim!: dvdE) | 
| 64272 | 1333 | then have "g a * prod g A = f a * prod f A * (r * s)" | 
| 63654 | 1334 | by (simp add: ac_simps) | 
| 1335 | with insert.hyps show ?case | |
| 1336 | by (auto intro: dvdI) | |
| 59010 | 1337 | qed | 
| 1338 | ||
| 64272 | 1339 | lemma prod_dvd_prod_subset: "finite B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> prod f A dvd prod f B" | 
| 1340 | by (auto simp add: prod.subset_diff ac_simps intro: dvdI) | |
| 59010 | 1341 | |
| 1342 | end | |
| 1343 | ||
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1344 | |
| 60758 | 1345 | subsubsection \<open>Properties in more restricted classes of structures\<close> | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1346 | |
| 65687 | 1347 | context linordered_nonzero_semiring | 
| 1348 | begin | |
| 68975 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1349 | |
| 65687 | 1350 | lemma prod_ge_1: "(\<And>x. x \<in> A \<Longrightarrow> 1 \<le> f x) \<Longrightarrow> 1 \<le> prod f A" | 
| 1351 | proof (induct A rule: infinite_finite_induct) | |
| 1352 | case infinite | |
| 1353 | then show ?case by simp | |
| 1354 | next | |
| 1355 | case empty | |
| 1356 | then show ?case by simp | |
| 1357 | next | |
| 1358 | case (insert x F) | |
| 1359 | have "1 * 1 \<le> f x * prod f F" | |
| 1360 | by (rule mult_mono') (use insert in auto) | |
| 1361 | with insert show ?case by simp | |
| 1362 | qed | |
| 1363 | ||
| 1364 | lemma prod_le_1: | |
| 1365 | fixes f :: "'b \<Rightarrow> 'a" | |
| 1366 | assumes "\<And>x. x \<in> A \<Longrightarrow> 0 \<le> f x \<and> f x \<le> 1" | |
| 1367 | shows "prod f A \<le> 1" | |
| 1368 | using assms | |
| 1369 | proof (induct A rule: infinite_finite_induct) | |
| 1370 | case infinite | |
| 1371 | then show ?case by simp | |
| 1372 | next | |
| 1373 | case empty | |
| 1374 | then show ?case by simp | |
| 1375 | next | |
| 1376 | case (insert x F) | |
| 1377 | then show ?case by (force simp: mult.commute intro: dest: mult_le_one) | |
| 1378 | qed | |
| 1379 | ||
| 1380 | end | |
| 1381 | ||
| 59010 | 1382 | context comm_semiring_1 | 
| 1383 | begin | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1384 | |
| 64272 | 1385 | lemma dvd_prod_eqI [intro]: | 
| 59010 | 1386 | assumes "finite A" and "a \<in> A" and "b = f a" | 
| 64272 | 1387 | shows "b dvd prod f A" | 
| 59010 | 1388 | proof - | 
| 64272 | 1389 |   from \<open>finite A\<close> have "prod f (insert a (A - {a})) = f a * prod f (A - {a})"
 | 
| 1390 | by (intro prod.insert) auto | |
| 63654 | 1391 |   also from \<open>a \<in> A\<close> have "insert a (A - {a}) = A"
 | 
| 1392 | by blast | |
| 64272 | 1393 |   finally have "prod f A = f a * prod f (A - {a})" .
 | 
| 63654 | 1394 | with \<open>b = f a\<close> show ?thesis | 
| 1395 | by simp | |
| 59010 | 1396 | qed | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1397 | |
| 64272 | 1398 | lemma dvd_prodI [intro]: "finite A \<Longrightarrow> a \<in> A \<Longrightarrow> f a dvd prod f A" | 
| 63654 | 1399 | by auto | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1400 | |
| 64272 | 1401 | lemma prod_zero: | 
| 59010 | 1402 | assumes "finite A" and "\<exists>a\<in>A. f a = 0" | 
| 64272 | 1403 | shows "prod f A = 0" | 
| 63654 | 1404 | using assms | 
| 1405 | proof (induct A) | |
| 1406 | case empty | |
| 1407 | then show ?case by simp | |
| 59010 | 1408 | next | 
| 1409 | case (insert a A) | |
| 1410 | then have "f a = 0 \<or> (\<exists>a\<in>A. f a = 0)" by simp | |
| 64272 | 1411 | then have "f a * prod f A = 0" by rule (simp_all add: insert) | 
| 59010 | 1412 | with insert show ?case by simp | 
| 1413 | qed | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1414 | |
| 64272 | 1415 | lemma prod_dvd_prod_subset2: | 
| 59010 | 1416 | assumes "finite B" and "A \<subseteq> B" and "\<And>a. a \<in> A \<Longrightarrow> f a dvd g a" | 
| 64272 | 1417 | shows "prod f A dvd prod g B" | 
| 59010 | 1418 | proof - | 
| 64272 | 1419 | from assms have "prod f A dvd prod g A" | 
| 1420 | by (auto intro: prod_dvd_prod) | |
| 1421 | moreover from assms have "prod g A dvd prod g B" | |
| 1422 | by (auto intro: prod_dvd_prod_subset) | |
| 59010 | 1423 | ultimately show ?thesis by (rule dvd_trans) | 
| 1424 | qed | |
| 1425 | ||
| 1426 | end | |
| 1427 | ||
| 64272 | 1428 | lemma (in semidom) prod_zero_iff [simp]: | 
| 63924 | 1429 | fixes f :: "'b \<Rightarrow> 'a" | 
| 59010 | 1430 | assumes "finite A" | 
| 64272 | 1431 | shows "prod f A = 0 \<longleftrightarrow> (\<exists>a\<in>A. f a = 0)" | 
| 59010 | 1432 | using assms by (induct A) (auto simp: no_zero_divisors) | 
| 1433 | ||
| 64272 | 1434 | lemma (in semidom_divide) prod_diff1: | 
| 60353 
838025c6e278
implicit partial divison operation in integral domains
 haftmann parents: 
59867diff
changeset | 1435 | assumes "finite A" and "f a \<noteq> 0" | 
| 64272 | 1436 |   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 | 1437 | proof (cases "a \<notin> A") | 
| 63654 | 1438 | case True | 
| 1439 | then show ?thesis by simp | |
| 60353 
838025c6e278
implicit partial divison operation in integral domains
 haftmann parents: 
59867diff
changeset | 1440 | next | 
| 63654 | 1441 | case False | 
| 1442 | with assms show ?thesis | |
| 1443 | proof induct | |
| 1444 | case empty | |
| 1445 | then show ?case by simp | |
| 60353 
838025c6e278
implicit partial divison operation in integral domains
 haftmann parents: 
59867diff
changeset | 1446 | next | 
| 
838025c6e278
implicit partial divison operation in integral domains
 haftmann parents: 
59867diff
changeset | 1447 | case (insert b B) | 
| 
838025c6e278
implicit partial divison operation in integral domains
 haftmann parents: 
59867diff
changeset | 1448 | then show ?case | 
| 
838025c6e278
implicit partial divison operation in integral domains
 haftmann parents: 
59867diff
changeset | 1449 | proof (cases "a = b") | 
| 63654 | 1450 | case True | 
| 1451 | with insert show ?thesis by simp | |
| 60353 
838025c6e278
implicit partial divison operation in integral domains
 haftmann parents: 
59867diff
changeset | 1452 | next | 
| 63654 | 1453 | case False | 
| 1454 | with insert have "a \<in> B" by simp | |
| 63040 | 1455 |       define C where "C = B - {a}"
 | 
| 63654 | 1456 | with \<open>finite B\<close> \<open>a \<in> B\<close> have "B = insert a C" "finite C" "a \<notin> C" | 
| 1457 | by auto | |
| 1458 | with insert show ?thesis | |
| 1459 | by (auto simp add: insert_commute ac_simps) | |
| 60353 
838025c6e278
implicit partial divison operation in integral domains
 haftmann parents: 
59867diff
changeset | 1460 | qed | 
| 
838025c6e278
implicit partial divison operation in integral domains
 haftmann parents: 
59867diff
changeset | 1461 | qed | 
| 
838025c6e278
implicit partial divison operation in integral domains
 haftmann parents: 
59867diff
changeset | 1462 | qed | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1463 | |
| 64267 | 1464 | 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 | 1465 | for c :: "nat \<Rightarrow> 'a::division_ring" | 
| 1466 | 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 | 1467 | |
| 64267 | 1468 | lemma sum_zero_power' [simp]: | 
| 63654 | 1469 | "(\<Sum>i\<in>A. c i * 0^i / d i) = (if finite A \<and> 0 \<in> A then c 0 / d 0 else 0)" | 
| 1470 | for c :: "nat \<Rightarrow> 'a::field" | |
| 64267 | 1471 | 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 | 1472 | |
| 65680 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 1473 | 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 | 1474 | 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 | 1475 | case True | 
| 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 1476 | then show ?thesis | 
| 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 1477 | 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 | 1478 | next | 
| 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 1479 | case False | 
| 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 1480 | then show ?thesis | 
| 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 1481 | by auto | 
| 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 1482 | qed | 
| 59010 | 1483 | |
| 65680 
378a2f11bec9
Simplification of some proofs. Also key lemmas using !! rather than ! in premises
 paulson <lp15@cam.ac.uk> parents: 
64979diff
changeset | 1484 | 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 | 1485 | 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 | 1486 | |
| 64272 | 1487 | lemma prod_Un: | 
| 59010 | 1488 | fixes f :: "'b \<Rightarrow> 'a :: field" | 
| 1489 | assumes "finite A" and "finite B" | |
| 63654 | 1490 | and "\<forall>x\<in>A \<inter> B. f x \<noteq> 0" | 
| 64272 | 1491 | shows "prod f (A \<union> B) = prod f A * prod f B / prod f (A \<inter> B)" | 
| 59010 | 1492 | proof - | 
| 64272 | 1493 | from assms have "prod f A * prod f B = prod f (A \<union> B) * prod f (A \<inter> B)" | 
| 1494 | by (simp add: prod.union_inter [symmetric, of A B]) | |
| 63654 | 1495 | with assms show ?thesis | 
| 1496 | by simp | |
| 59010 | 1497 | qed | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1498 | |
| 68361 | 1499 | context linordered_semidom | 
| 1500 | begin | |
| 1501 | ||
| 1502 | lemma prod_nonneg: "(\<forall>a\<in>A. 0 \<le> f a) \<Longrightarrow> 0 \<le> prod f A" | |
| 59010 | 1503 | by (induct A rule: infinite_finite_induct) simp_all | 
| 1504 | ||
| 68361 | 1505 | lemma prod_pos: "(\<forall>a\<in>A. 0 < f a) \<Longrightarrow> 0 < prod f A" | 
| 59010 | 1506 | by (induct A rule: infinite_finite_induct) simp_all | 
| 1507 | ||
| 68361 | 1508 | lemma prod_mono: | 
| 67673 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 1509 | "(\<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 | 1510 | 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 | 1511 | |
| 68361 | 1512 | lemma prod_mono_strict: | 
| 67673 
c8caefb20564
lots of new material, ultimately related to measure theory
 paulson <lp15@cam.ac.uk> parents: 
67511diff
changeset | 1513 |   assumes "finite A" "\<And>i. i \<in> A \<Longrightarrow> 0 \<le> f i \<and> f i < g i" "A \<noteq> {}"
 | 
| 64272 | 1514 | shows "prod f A < prod g A" | 
| 63654 | 1515 | using assms | 
| 1516 | proof (induct A rule: finite_induct) | |
| 1517 | case empty | |
| 1518 | then show ?case by simp | |
| 1519 | next | |
| 1520 | case insert | |
| 64272 | 1521 | then show ?case by (force intro: mult_strict_mono' prod_nonneg) | 
| 63654 | 1522 | qed | 
| 60974 
6a6f15d8fbc4
New material and fixes related to the forthcoming Stone-Weierstrass development
 paulson <lp15@cam.ac.uk> parents: 
60758diff
changeset | 1523 | |
| 68361 | 1524 | end | 
| 1525 | ||
| 1526 | lemma prod_mono2: | |
| 1527 | fixes f :: "'a \<Rightarrow> 'b :: linordered_idom" | |
| 1528 | assumes fin: "finite B" | |
| 1529 | and sub: "A \<subseteq> B" | |
| 1530 | and nn: "\<And>b. b \<in> B-A \<Longrightarrow> 1 \<le> f b" | |
| 1531 | and A: "\<And>a. a \<in> A \<Longrightarrow> 0 \<le> f a" | |
| 1532 | shows "prod f A \<le> prod f B" | |
| 1533 | proof - | |
| 1534 | have "prod f A \<le> prod f A * prod f (B-A)" | |
| 1535 | by (metis prod_ge_1 A mult_le_cancel_left1 nn not_less prod_nonneg) | |
| 1536 | also from fin finite_subset[OF sub fin] have "\<dots> = prod f (A \<union> (B-A))" | |
| 1537 | by (simp add: prod.union_disjoint del: Un_Diff_cancel) | |
| 1538 | also from sub have "A \<union> (B-A) = B" by blast | |
| 1539 | finally show ?thesis . | |
| 1540 | qed | |
| 1541 | ||
| 1542 | lemma less_1_prod: | |
| 1543 | fixes f :: "'a \<Rightarrow> 'b::linordered_idom" | |
| 1544 |   shows "finite I \<Longrightarrow> I \<noteq> {} \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> 1 < f i) \<Longrightarrow> 1 < prod f I"
 | |
| 1545 | by (induct I rule: finite_ne_induct) (auto intro: less_1_mult) | |
| 1546 | ||
| 1547 | lemma less_1_prod2: | |
| 1548 | fixes f :: "'a \<Rightarrow> 'b::linordered_idom" | |
| 1549 | assumes I: "finite I" "i \<in> I" "1 < f i" "\<And>i. i \<in> I \<Longrightarrow> 1 \<le> f i" | |
| 1550 | shows "1 < prod f I" | |
| 1551 | proof - | |
| 1552 |   have "1 < f i * prod f (I - {i})"
 | |
| 1553 | using assms | |
| 1554 | by (meson DiffD1 leI less_1_mult less_le_trans mult_le_cancel_left1 prod_ge_1) | |
| 1555 | also have "\<dots> = prod f I" | |
| 1556 | using assms by (simp add: prod.remove) | |
| 1557 | finally show ?thesis . | |
| 1558 | qed | |
| 1559 | ||
| 64272 | 1560 | lemma (in linordered_field) abs_prod: "\<bar>prod f A\<bar> = (\<Prod>x\<in>A. \<bar>f x\<bar>)" | 
| 59010 | 1561 | 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 | 1562 | |
| 64272 | 1563 | lemma prod_eq_1_iff [simp]: "finite A \<Longrightarrow> prod f A = 1 \<longleftrightarrow> (\<forall>a\<in>A. f a = 1)" | 
| 63654 | 1564 | for f :: "'a \<Rightarrow> nat" | 
| 59010 | 1565 | by (induct A rule: finite_induct) simp_all | 
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1566 | |
| 64272 | 1567 | lemma prod_pos_nat_iff [simp]: "finite A \<Longrightarrow> prod f A > 0 \<longleftrightarrow> (\<forall>a\<in>A. f a > 0)" | 
| 63654 | 1568 | for f :: "'a \<Rightarrow> nat" | 
| 64272 | 1569 | 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 | 1570 | |
| 67969 
83c8cafdebe8
Syntax for the special cases Min(A`I) and Max (A`I)
 paulson <lp15@cam.ac.uk> parents: 
67683diff
changeset | 1571 | lemma prod_constant [simp]: "(\<Prod>x\<in> A. y) = y ^ card A" | 
| 63654 | 1572 | for y :: "'a::comm_monoid_mult" | 
| 62481 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
 haftmann parents: 
62378diff
changeset | 1573 | 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 | 1574 | |
| 64272 | 1575 | lemma prod_power_distrib: "prod f A ^ n = prod (\<lambda>x. (f x) ^ n) A" | 
| 63654 | 1576 | for f :: "'a \<Rightarrow> 'b::comm_semiring_1" | 
| 1577 | 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 | 1578 | |
| 64267 | 1579 | 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 | 1580 | 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 | 1581 | |
| 64272 | 1582 | lemma prod_gen_delta: | 
| 63654 | 1583 | fixes b :: "'b \<Rightarrow> 'a::comm_monoid_mult" | 
| 1584 | assumes fin: "finite S" | |
| 64272 | 1585 | shows "prod (\<lambda>k. if k = a then b k else c) S = | 
| 63654 | 1586 | (if a \<in> S then b a * c ^ (card S - 1) else c ^ card S)" | 
| 1587 | proof - | |
| 62481 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
 haftmann parents: 
62378diff
changeset | 1588 | let ?f = "(\<lambda>k. if k=a then b k else c)" | 
| 63654 | 1589 | show ?thesis | 
| 1590 | proof (cases "a \<in> S") | |
| 1591 | case False | |
| 1592 | then have "\<forall> k\<in> S. ?f k = c" by simp | |
| 64272 | 1593 | with False show ?thesis by (simp add: prod_constant) | 
| 63654 | 1594 | next | 
| 1595 | case True | |
| 62481 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
 haftmann parents: 
62378diff
changeset | 1596 |     let ?A = "S - {a}"
 | 
| 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
 haftmann parents: 
62378diff
changeset | 1597 |     let ?B = "{a}"
 | 
| 63654 | 1598 | from True have eq: "S = ?A \<union> ?B" by blast | 
| 1599 |     have disjoint: "?A \<inter> ?B = {}" by simp
 | |
| 1600 | from fin have fin': "finite ?A" "finite ?B" by auto | |
| 64272 | 1601 | have f_A0: "prod ?f ?A = prod (\<lambda>i. c) ?A" | 
| 1602 | by (rule prod.cong) auto | |
| 63654 | 1603 | from fin True have card_A: "card ?A = card S - 1" by auto | 
| 64272 | 1604 | have f_A1: "prod ?f ?A = c ^ card ?A" | 
| 1605 | unfolding f_A0 by (rule prod_constant) | |
| 1606 | have "prod ?f ?A * prod ?f ?B = prod ?f S" | |
| 1607 | 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 | 1608 | by simp | 
| 63654 | 1609 | with True card_A show ?thesis | 
| 64272 | 1610 | by (simp add: f_A1 field_simps cong add: prod.cong cong del: if_weak_cong) | 
| 63654 | 1611 | qed | 
| 62481 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
 haftmann parents: 
62378diff
changeset | 1612 | qed | 
| 
b5d8e57826df
tuned bootstrap order to provide type classes in a more sensible order
 haftmann parents: 
62378diff
changeset | 1613 | |
| 64267 | 1614 | lemma sum_image_le: | 
| 69127 | 1615 | 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 | 1616 | assumes "finite I" "\<And>i. i \<in> I \<Longrightarrow> 0 \<le> g(f i)" | 
| 64267 | 1617 | 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 | 1618 | using assms | 
| 
354808e9f44b
new material connected with HOL Light measure theory, plus more rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63938diff
changeset | 1619 | proof induction | 
| 
354808e9f44b
new material connected with HOL Light measure theory, plus more rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63938diff
changeset | 1620 | case empty | 
| 
354808e9f44b
new material connected with HOL Light measure theory, plus more rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63938diff
changeset | 1621 | 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 | 1622 | next | 
| 69127 | 1623 | case (insert x F) | 
| 1624 | from insertI1 have "0 \<le> g (f x)" by (rule insert) | |
| 1625 | hence 1: "sum g (f ` F) \<le> g (f x) + sum g (f ` F)" using add_increasing by blast | |
| 1626 | have 2: "sum g (f ` F) \<le> sum (g \<circ> f) F" using insert by blast | |
| 64267 | 1627 | have "sum g (f ` insert x F) = sum g (insert (f x) (f ` F))" by simp | 
| 69127 | 1628 | also have "\<dots> \<le> g (f x) + sum g (f ` F)" by (simp add: 1 insert sum.insert_if) | 
| 1629 | also from 2 have "\<dots> \<le> g (f x) + sum (g \<circ> f) F" by (rule add_left_mono) | |
| 1630 | also from insert(1, 2) have "\<dots> = sum (g \<circ> f) (insert x F)" 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 | 1631 | finally show ?case . | 
| 
354808e9f44b
new material connected with HOL Light measure theory, plus more rationalisation
 paulson <lp15@cam.ac.uk> parents: 
63938diff
changeset | 1632 | qed | 
| 68975 
5ce4d117cea7
A few new results, elimination of duplicates and more use of "pairwise"
 paulson <lp15@cam.ac.uk> parents: 
68361diff
changeset | 1633 | |
| 54744 
1e7f2d296e19
more algebraic terminology for theories about big operators
 haftmann parents: diff
changeset | 1634 | end |