| author | wenzelm | 
| Tue, 29 Sep 2009 18:14:08 +0200 | |
| changeset 32760 | ea6672bff5dd | 
| parent 32705 | 04ce6bb14d85 | 
| child 32960 | 69916a850301 | 
| child 32988 | d1d4d7a08a66 | 
| permissions | -rw-r--r-- | 
| 12396 | 1 | (* Title: HOL/Finite_Set.thy | 
| 2 | Author: Tobias Nipkow, Lawrence C Paulson and Markus Wenzel | |
| 16775 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 avigad parents: 
16760diff
changeset | 3 | with contributions by Jeremy Avigad | 
| 12396 | 4 | *) | 
| 5 | ||
| 6 | header {* Finite sets *}
 | |
| 7 | ||
| 15131 | 8 | theory Finite_Set | 
| 29609 | 9 | imports Nat Product_Type Power | 
| 15131 | 10 | begin | 
| 12396 | 11 | |
| 15392 | 12 | subsection {* Definition and basic properties *}
 | 
| 12396 | 13 | |
| 23736 | 14 | inductive finite :: "'a set => bool" | 
| 22262 | 15 | where | 
| 16 |     emptyI [simp, intro!]: "finite {}"
 | |
| 17 | | insertI [simp, intro!]: "finite A ==> finite (insert a A)" | |
| 12396 | 18 | |
| 13737 | 19 | lemma ex_new_if_finite: -- "does not depend on def of finite at all" | 
| 14661 | 20 | assumes "\<not> finite (UNIV :: 'a set)" and "finite A" | 
| 21 | shows "\<exists>a::'a. a \<notin> A" | |
| 22 | proof - | |
| 28823 | 23 | from assms have "A \<noteq> UNIV" by blast | 
| 14661 | 24 | thus ?thesis by blast | 
| 25 | qed | |
| 12396 | 26 | |
| 22262 | 27 | lemma finite_induct [case_names empty insert, induct set: finite]: | 
| 12396 | 28 | "finite F ==> | 
| 15327 
0230a10582d3
changed the order of !!-quantifiers in finite set induction.
 nipkow parents: 
15318diff
changeset | 29 |     P {} ==> (!!x F. finite F ==> x \<notin> F ==> P F ==> P (insert x F)) ==> P F"
 | 
| 12396 | 30 |   -- {* Discharging @{text "x \<notin> F"} entails extra work. *}
 | 
| 31 | proof - | |
| 13421 | 32 |   assume "P {}" and
 | 
| 15327 
0230a10582d3
changed the order of !!-quantifiers in finite set induction.
 nipkow parents: 
15318diff
changeset | 33 | insert: "!!x F. finite F ==> x \<notin> F ==> P F ==> P (insert x F)" | 
| 12396 | 34 | assume "finite F" | 
| 35 | thus "P F" | |
| 36 | proof induct | |
| 23389 | 37 |     show "P {}" by fact
 | 
| 15327 
0230a10582d3
changed the order of !!-quantifiers in finite set induction.
 nipkow parents: 
15318diff
changeset | 38 | fix x F assume F: "finite F" and P: "P F" | 
| 12396 | 39 | show "P (insert x F)" | 
| 40 | proof cases | |
| 41 | assume "x \<in> F" | |
| 42 | hence "insert x F = F" by (rule insert_absorb) | |
| 43 | with P show ?thesis by (simp only:) | |
| 44 | next | |
| 45 | assume "x \<notin> F" | |
| 46 | from F this P show ?thesis by (rule insert) | |
| 47 | qed | |
| 48 | qed | |
| 49 | qed | |
| 50 | ||
| 15484 | 51 | lemma finite_ne_induct[case_names singleton insert, consumes 2]: | 
| 52 | assumes fin: "finite F" shows "F \<noteq> {} \<Longrightarrow>
 | |
| 53 |  \<lbrakk> \<And>x. P{x};
 | |
| 54 |    \<And>x F. \<lbrakk> finite F; F \<noteq> {}; x \<notin> F; P F \<rbrakk> \<Longrightarrow> P (insert x F) \<rbrakk>
 | |
| 55 | \<Longrightarrow> P F" | |
| 56 | using fin | |
| 57 | proof induct | |
| 58 | case empty thus ?case by simp | |
| 59 | next | |
| 60 | case (insert x F) | |
| 61 | show ?case | |
| 62 | proof cases | |
| 23389 | 63 |     assume "F = {}"
 | 
| 64 |     thus ?thesis using `P {x}` by simp
 | |
| 15484 | 65 | next | 
| 23389 | 66 |     assume "F \<noteq> {}"
 | 
| 67 | thus ?thesis using insert by blast | |
| 15484 | 68 | qed | 
| 69 | qed | |
| 70 | ||
| 12396 | 71 | lemma finite_subset_induct [consumes 2, case_names empty insert]: | 
| 23389 | 72 | assumes "finite F" and "F \<subseteq> A" | 
| 73 |     and empty: "P {}"
 | |
| 74 | and insert: "!!a F. finite F ==> a \<in> A ==> a \<notin> F ==> P F ==> P (insert a F)" | |
| 75 | shows "P F" | |
| 12396 | 76 | proof - | 
| 23389 | 77 | from `finite F` and `F \<subseteq> A` | 
| 78 | show ?thesis | |
| 12396 | 79 | proof induct | 
| 23389 | 80 |     show "P {}" by fact
 | 
| 81 | next | |
| 82 | fix x F | |
| 83 | assume "finite F" and "x \<notin> F" and | |
| 84 | P: "F \<subseteq> A ==> P F" and i: "insert x F \<subseteq> A" | |
| 12396 | 85 | show "P (insert x F)" | 
| 86 | proof (rule insert) | |
| 87 | from i show "x \<in> A" by blast | |
| 88 | from i have "F \<subseteq> A" by blast | |
| 89 | with P show "P F" . | |
| 23389 | 90 | show "finite F" by fact | 
| 91 | show "x \<notin> F" by fact | |
| 12396 | 92 | qed | 
| 93 | qed | |
| 94 | qed | |
| 95 | ||
| 32006 | 96 | |
| 29923 | 97 | text{* A finite choice principle. Does not need the SOME choice operator. *}
 | 
| 98 | lemma finite_set_choice: | |
| 99 | "finite A \<Longrightarrow> ALL x:A. (EX y. P x y) \<Longrightarrow> EX f. ALL x:A. P x (f x)" | |
| 100 | proof (induct set: finite) | |
| 101 | case empty thus ?case by simp | |
| 102 | next | |
| 103 | case (insert a A) | |
| 104 | then obtain f b where f: "ALL x:A. P x (f x)" and ab: "P a b" by auto | |
| 105 | show ?case (is "EX f. ?P f") | |
| 106 | proof | |
| 107 | show "?P(%x. if x = a then b else f x)" using f ab by auto | |
| 108 | qed | |
| 109 | qed | |
| 110 | ||
| 23878 | 111 | |
| 15392 | 112 | text{* Finite sets are the images of initial segments of natural numbers: *}
 | 
| 113 | ||
| 15510 | 114 | lemma finite_imp_nat_seg_image_inj_on: | 
| 115 | assumes fin: "finite A" | |
| 116 |   shows "\<exists> (n::nat) f. A = f ` {i. i<n} & inj_on f {i. i<n}"
 | |
| 15392 | 117 | using fin | 
| 118 | proof induct | |
| 119 | case empty | |
| 15510 | 120 | show ?case | 
| 121 |   proof show "\<exists>f. {} = f ` {i::nat. i < 0} & inj_on f {i. i<0}" by simp 
 | |
| 122 | qed | |
| 15392 | 123 | next | 
| 124 | case (insert a A) | |
| 23389 | 125 | have notinA: "a \<notin> A" by fact | 
| 15510 | 126 | from insert.hyps obtain n f | 
| 127 |     where "A = f ` {i::nat. i < n}" "inj_on f {i. i < n}" by blast
 | |
| 128 |   hence "insert a A = f(n:=a) ` {i. i < Suc n}"
 | |
| 129 |         "inj_on (f(n:=a)) {i. i < Suc n}" using notinA
 | |
| 130 | by (auto simp add: image_def Ball_def inj_on_def less_Suc_eq) | |
| 15392 | 131 | thus ?case by blast | 
| 132 | qed | |
| 133 | ||
| 134 | lemma nat_seg_image_imp_finite: | |
| 135 |   "!!f A. A = f ` {i::nat. i<n} \<Longrightarrow> finite A"
 | |
| 136 | proof (induct n) | |
| 137 | case 0 thus ?case by simp | |
| 138 | next | |
| 139 | case (Suc n) | |
| 140 |   let ?B = "f ` {i. i < n}"
 | |
| 141 | have finB: "finite ?B" by(rule Suc.hyps[OF refl]) | |
| 142 | show ?case | |
| 143 | proof cases | |
| 144 | assume "\<exists>k<n. f n = f k" | |
| 145 | hence "A = ?B" using Suc.prems by(auto simp:less_Suc_eq) | |
| 146 | thus ?thesis using finB by simp | |
| 147 | next | |
| 148 | assume "\<not>(\<exists> k<n. f n = f k)" | |
| 149 | hence "A = insert (f n) ?B" using Suc.prems by(auto simp:less_Suc_eq) | |
| 150 | thus ?thesis using finB by simp | |
| 151 | qed | |
| 152 | qed | |
| 153 | ||
| 154 | lemma finite_conv_nat_seg_image: | |
| 155 |   "finite A = (\<exists> (n::nat) f. A = f ` {i::nat. i<n})"
 | |
| 15510 | 156 | by(blast intro: nat_seg_image_imp_finite dest: finite_imp_nat_seg_image_inj_on) | 
| 15392 | 157 | |
| 29920 | 158 | lemma finite_Collect_less_nat[iff]: "finite{n::nat. n<k}"
 | 
| 159 | by(fastsimp simp: finite_conv_nat_seg_image) | |
| 160 | ||
| 26441 | 161 | |
| 15392 | 162 | subsubsection{* Finiteness and set theoretic constructions *}
 | 
| 163 | ||
| 12396 | 164 | lemma finite_UnI: "finite F ==> finite G ==> finite (F Un G)" | 
| 29901 | 165 | by (induct set: finite) simp_all | 
| 12396 | 166 | |
| 167 | lemma finite_subset: "A \<subseteq> B ==> finite B ==> finite A" | |
| 168 |   -- {* Every subset of a finite set is finite. *}
 | |
| 169 | proof - | |
| 170 | assume "finite B" | |
| 171 | thus "!!A. A \<subseteq> B ==> finite A" | |
| 172 | proof induct | |
| 173 | case empty | |
| 174 | thus ?case by simp | |
| 175 | next | |
| 15327 
0230a10582d3
changed the order of !!-quantifiers in finite set induction.
 nipkow parents: 
15318diff
changeset | 176 | case (insert x F A) | 
| 23389 | 177 |     have A: "A \<subseteq> insert x F" and r: "A - {x} \<subseteq> F ==> finite (A - {x})" by fact+
 | 
| 12396 | 178 | show "finite A" | 
| 179 | proof cases | |
| 180 | assume x: "x \<in> A" | |
| 181 |       with A have "A - {x} \<subseteq> F" by (simp add: subset_insert_iff)
 | |
| 182 |       with r have "finite (A - {x})" .
 | |
| 183 |       hence "finite (insert x (A - {x}))" ..
 | |
| 23389 | 184 |       also have "insert x (A - {x}) = A" using x by (rule insert_Diff)
 | 
| 12396 | 185 | finally show ?thesis . | 
| 186 | next | |
| 23389 | 187 | show "A \<subseteq> F ==> ?thesis" by fact | 
| 12396 | 188 | assume "x \<notin> A" | 
| 189 | with A show "A \<subseteq> F" by (simp add: subset_insert_iff) | |
| 190 | qed | |
| 191 | qed | |
| 192 | qed | |
| 193 | ||
| 194 | lemma finite_Un [iff]: "finite (F Un G) = (finite F & finite G)" | |
| 29901 | 195 | by (blast intro: finite_subset [of _ "X Un Y", standard] finite_UnI) | 
| 196 | ||
| 29916 | 197 | lemma finite_Collect_disjI[simp]: | 
| 29901 | 198 |   "finite{x. P x | Q x} = (finite{x. P x} & finite{x. Q x})"
 | 
| 199 | by(simp add:Collect_disj_eq) | |
| 12396 | 200 | |
| 201 | lemma finite_Int [simp, intro]: "finite F | finite G ==> finite (F Int G)" | |
| 202 |   -- {* The converse obviously fails. *}
 | |
| 29901 | 203 | by (blast intro: finite_subset) | 
| 204 | ||
| 29916 | 205 | lemma finite_Collect_conjI [simp, intro]: | 
| 29901 | 206 |   "finite{x. P x} | finite{x. Q x} ==> finite{x. P x & Q x}"
 | 
| 207 |   -- {* The converse obviously fails. *}
 | |
| 208 | by(simp add:Collect_conj_eq) | |
| 12396 | 209 | |
| 29920 | 210 | lemma finite_Collect_le_nat[iff]: "finite{n::nat. n<=k}"
 | 
| 211 | by(simp add: le_eq_less_or_eq) | |
| 212 | ||
| 12396 | 213 | lemma finite_insert [simp]: "finite (insert a A) = finite A" | 
| 214 | apply (subst insert_is_Un) | |
| 14208 | 215 | apply (simp only: finite_Un, blast) | 
| 12396 | 216 | done | 
| 217 | ||
| 15281 | 218 | lemma finite_Union[simp, intro]: | 
| 219 | "\<lbrakk> finite A; !!M. M \<in> A \<Longrightarrow> finite M \<rbrakk> \<Longrightarrow> finite(\<Union>A)" | |
| 220 | by (induct rule:finite_induct) simp_all | |
| 221 | ||
| 31992 | 222 | lemma finite_Inter[intro]: "EX A:M. finite(A) \<Longrightarrow> finite(Inter M)" | 
| 223 | by (blast intro: Inter_lower finite_subset) | |
| 224 | ||
| 225 | lemma finite_INT[intro]: "EX x:I. finite(A x) \<Longrightarrow> finite(INT x:I. A x)" | |
| 226 | by (blast intro: INT_lower finite_subset) | |
| 227 | ||
| 12396 | 228 | lemma finite_empty_induct: | 
| 23389 | 229 | assumes "finite A" | 
| 230 | and "P A" | |
| 231 |     and "!!a A. finite A ==> a:A ==> P A ==> P (A - {a})"
 | |
| 232 |   shows "P {}"
 | |
| 12396 | 233 | proof - | 
| 234 | have "P (A - A)" | |
| 235 | proof - | |
| 23389 | 236 |     {
 | 
| 237 | fix c b :: "'a set" | |
| 238 | assume c: "finite c" and b: "finite b" | |
| 239 | 	and P1: "P b" and P2: "!!x y. finite y ==> x \<in> y ==> P y ==> P (y - {x})"
 | |
| 240 | have "c \<subseteq> b ==> P (b - c)" | |
| 241 | using c | |
| 242 | proof induct | |
| 243 | case empty | |
| 244 | from P1 show ?case by simp | |
| 245 | next | |
| 246 | case (insert x F) | |
| 247 | 	have "P (b - F - {x})"
 | |
| 248 | proof (rule P2) | |
| 249 | from _ b show "finite (b - F)" by (rule finite_subset) blast | |
| 250 | from insert show "x \<in> b - F" by simp | |
| 251 | from insert show "P (b - F)" by simp | |
| 252 | qed | |
| 253 | 	also have "b - F - {x} = b - insert x F" by (rule Diff_insert [symmetric])
 | |
| 254 | finally show ?case . | |
| 12396 | 255 | qed | 
| 23389 | 256 | } | 
| 257 | then show ?thesis by this (simp_all add: assms) | |
| 12396 | 258 | qed | 
| 23389 | 259 | then show ?thesis by simp | 
| 12396 | 260 | qed | 
| 261 | ||
| 29901 | 262 | lemma finite_Diff [simp]: "finite A ==> finite (A - B)" | 
| 263 | by (rule Diff_subset [THEN finite_subset]) | |
| 264 | ||
| 265 | lemma finite_Diff2 [simp]: | |
| 266 | assumes "finite B" shows "finite (A - B) = finite A" | |
| 267 | proof - | |
| 268 | have "finite A \<longleftrightarrow> finite((A-B) Un (A Int B))" by(simp add: Un_Diff_Int) | |
| 269 | also have "\<dots> \<longleftrightarrow> finite(A-B)" using `finite B` by(simp) | |
| 270 | finally show ?thesis .. | |
| 271 | qed | |
| 272 | ||
| 273 | lemma finite_compl[simp]: | |
| 274 | "finite(A::'a set) \<Longrightarrow> finite(-A) = finite(UNIV::'a set)" | |
| 275 | by(simp add:Compl_eq_Diff_UNIV) | |
| 12396 | 276 | |
| 29916 | 277 | lemma finite_Collect_not[simp]: | 
| 29903 | 278 |   "finite{x::'a. P x} \<Longrightarrow> finite{x. ~P x} = finite(UNIV::'a set)"
 | 
| 279 | by(simp add:Collect_neg_eq) | |
| 280 | ||
| 12396 | 281 | lemma finite_Diff_insert [iff]: "finite (A - insert a B) = finite (A - B)" | 
| 282 | apply (subst Diff_insert) | |
| 283 | apply (case_tac "a : A - B") | |
| 284 | apply (rule finite_insert [symmetric, THEN trans]) | |
| 14208 | 285 | apply (subst insert_Diff, simp_all) | 
| 12396 | 286 | done | 
| 287 | ||
| 288 | ||
| 15392 | 289 | text {* Image and Inverse Image over Finite Sets *}
 | 
| 13825 | 290 | |
| 291 | lemma finite_imageI[simp]: "finite F ==> finite (h ` F)" | |
| 292 |   -- {* The image of a finite set is finite. *}
 | |
| 22262 | 293 | by (induct set: finite) simp_all | 
| 13825 | 294 | |
| 31768 | 295 | lemma finite_image_set [simp]: | 
| 296 |   "finite {x. P x} \<Longrightarrow> finite { f x | x. P x }"
 | |
| 297 | by (simp add: image_Collect [symmetric]) | |
| 298 | ||
| 14430 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 paulson parents: 
14331diff
changeset | 299 | lemma finite_surj: "finite A ==> B <= f ` A ==> finite B" | 
| 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 paulson parents: 
14331diff
changeset | 300 | apply (frule finite_imageI) | 
| 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 paulson parents: 
14331diff
changeset | 301 | apply (erule finite_subset, assumption) | 
| 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 paulson parents: 
14331diff
changeset | 302 | done | 
| 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 paulson parents: 
14331diff
changeset | 303 | |
| 13825 | 304 | lemma finite_range_imageI: | 
| 305 | "finite (range g) ==> finite (range (%x. f (g x)))" | |
| 27418 | 306 | apply (drule finite_imageI, simp add: range_composition) | 
| 13825 | 307 | done | 
| 308 | ||
| 12396 | 309 | lemma finite_imageD: "finite (f`A) ==> inj_on f A ==> finite A" | 
| 310 | proof - | |
| 311 |   have aux: "!!A. finite (A - {}) = finite A" by simp
 | |
| 312 | fix B :: "'a set" | |
| 313 | assume "finite B" | |
| 314 | thus "!!A. f`A = B ==> inj_on f A ==> finite A" | |
| 315 | apply induct | |
| 316 | apply simp | |
| 317 |     apply (subgoal_tac "EX y:A. f y = x & F = f ` (A - {y})")
 | |
| 318 | apply clarify | |
| 319 | apply (simp (no_asm_use) add: inj_on_def) | |
| 14208 | 320 | apply (blast dest!: aux [THEN iffD1], atomize) | 
| 12396 | 321 | apply (erule_tac V = "ALL A. ?PP (A)" in thin_rl) | 
| 14208 | 322 | apply (frule subsetD [OF equalityD2 insertI1], clarify) | 
| 12396 | 323 | apply (rule_tac x = xa in bexI) | 
| 324 | apply (simp_all add: inj_on_image_set_diff) | |
| 325 | done | |
| 326 | qed (rule refl) | |
| 327 | ||
| 328 | ||
| 13825 | 329 | lemma inj_vimage_singleton: "inj f ==> f-`{a} \<subseteq> {THE x. f x = a}"
 | 
| 330 |   -- {* The inverse image of a singleton under an injective function
 | |
| 331 | is included in a singleton. *} | |
| 14430 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 paulson parents: 
14331diff
changeset | 332 | apply (auto simp add: inj_on_def) | 
| 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 paulson parents: 
14331diff
changeset | 333 | apply (blast intro: the_equality [symmetric]) | 
| 13825 | 334 | done | 
| 335 | ||
| 336 | lemma finite_vimageI: "[|finite F; inj h|] ==> finite (h -` F)" | |
| 337 |   -- {* The inverse image of a finite set under an injective function
 | |
| 338 | is finite. *} | |
| 22262 | 339 | apply (induct set: finite) | 
| 21575 | 340 | apply simp_all | 
| 14430 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 paulson parents: 
14331diff
changeset | 341 | apply (subst vimage_insert) | 
| 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 paulson parents: 
14331diff
changeset | 342 | apply (simp add: finite_Un finite_subset [OF inj_vimage_singleton]) | 
| 13825 | 343 | done | 
| 344 | ||
| 345 | ||
| 15392 | 346 | text {* The finite UNION of finite sets *}
 | 
| 12396 | 347 | |
| 348 | lemma finite_UN_I: "finite A ==> (!!a. a:A ==> finite (B a)) ==> finite (UN a:A. B a)" | |
| 22262 | 349 | by (induct set: finite) simp_all | 
| 12396 | 350 | |
| 351 | text {*
 | |
| 352 | Strengthen RHS to | |
| 14430 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 paulson parents: 
14331diff
changeset | 353 |   @{prop "((ALL x:A. finite (B x)) & finite {x. x:A & B x \<noteq> {}})"}?
 | 
| 12396 | 354 | |
| 355 | We'd need to prove | |
| 14430 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 paulson parents: 
14331diff
changeset | 356 |   @{prop "finite C ==> ALL A B. (UNION A B) <= C --> finite {x. x:A & B x \<noteq> {}}"}
 | 
| 12396 | 357 | by induction. *} | 
| 358 | ||
| 29918 | 359 | lemma finite_UN [simp]: | 
| 360 | "finite A ==> finite (UNION A B) = (ALL x:A. finite (B x))" | |
| 361 | by (blast intro: finite_UN_I finite_subset) | |
| 12396 | 362 | |
| 29920 | 363 | lemma finite_Collect_bex[simp]: "finite A \<Longrightarrow> | 
| 364 |   finite{x. EX y:A. Q x y} = (ALL y:A. finite{x. Q x y})"
 | |
| 365 | apply(subgoal_tac "{x. EX y:A. Q x y} = UNION A (%y. {x. Q x y})")
 | |
| 366 | apply auto | |
| 367 | done | |
| 368 | ||
| 369 | lemma finite_Collect_bounded_ex[simp]: "finite{y. P y} \<Longrightarrow>
 | |
| 370 |   finite{x. EX y. P y & Q x y} = (ALL y. P y \<longrightarrow> finite{x. Q x y})"
 | |
| 371 | apply(subgoal_tac "{x. EX y. P y & Q x y} = UNION {y. P y} (%y. {x. Q x y})")
 | |
| 372 | apply auto | |
| 373 | done | |
| 374 | ||
| 375 | ||
| 17022 | 376 | lemma finite_Plus: "[| finite A; finite B |] ==> finite (A <+> B)" | 
| 377 | by (simp add: Plus_def) | |
| 378 | ||
| 31080 | 379 | lemma finite_PlusD: | 
| 380 | fixes A :: "'a set" and B :: "'b set" | |
| 381 | assumes fin: "finite (A <+> B)" | |
| 382 | shows "finite A" "finite B" | |
| 383 | proof - | |
| 384 | have "Inl ` A \<subseteq> A <+> B" by auto | |
| 385 |   hence "finite (Inl ` A :: ('a + 'b) set)" using fin by(rule finite_subset)
 | |
| 386 | thus "finite A" by(rule finite_imageD)(auto intro: inj_onI) | |
| 387 | next | |
| 388 | have "Inr ` B \<subseteq> A <+> B" by auto | |
| 389 |   hence "finite (Inr ` B :: ('a + 'b) set)" using fin by(rule finite_subset)
 | |
| 390 | thus "finite B" by(rule finite_imageD)(auto intro: inj_onI) | |
| 391 | qed | |
| 392 | ||
| 393 | lemma finite_Plus_iff[simp]: "finite (A <+> B) \<longleftrightarrow> finite A \<and> finite B" | |
| 394 | by(auto intro: finite_PlusD finite_Plus) | |
| 395 | ||
| 396 | lemma finite_Plus_UNIV_iff[simp]: | |
| 397 |   "finite (UNIV :: ('a + 'b) set) =
 | |
| 398 | (finite (UNIV :: 'a set) & finite (UNIV :: 'b set))" | |
| 399 | by(subst UNIV_Plus_UNIV[symmetric])(rule finite_Plus_iff) | |
| 400 | ||
| 401 | ||
| 15392 | 402 | text {* Sigma of finite sets *}
 | 
| 12396 | 403 | |
| 404 | lemma finite_SigmaI [simp]: | |
| 405 | "finite A ==> (!!a. a:A ==> finite (B a)) ==> finite (SIGMA a:A. B a)" | |
| 406 | by (unfold Sigma_def) (blast intro!: finite_UN_I) | |
| 407 | ||
| 15402 | 408 | lemma finite_cartesian_product: "[| finite A; finite B |] ==> | 
| 409 | finite (A <*> B)" | |
| 410 | by (rule finite_SigmaI) | |
| 411 | ||
| 12396 | 412 | lemma finite_Prod_UNIV: | 
| 413 |     "finite (UNIV::'a set) ==> finite (UNIV::'b set) ==> finite (UNIV::('a * 'b) set)"
 | |
| 414 |   apply (subgoal_tac "(UNIV:: ('a * 'b) set) = Sigma UNIV (%x. UNIV)")
 | |
| 415 | apply (erule ssubst) | |
| 14208 | 416 | apply (erule finite_SigmaI, auto) | 
| 12396 | 417 | done | 
| 418 | ||
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 419 | lemma finite_cartesian_productD1: | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 420 |      "[| finite (A <*> B); B \<noteq> {} |] ==> finite A"
 | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 421 | apply (auto simp add: finite_conv_nat_seg_image) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 422 | apply (drule_tac x=n in spec) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 423 | apply (drule_tac x="fst o f" in spec) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 424 | apply (auto simp add: o_def) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 425 | prefer 2 apply (force dest!: equalityD2) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 426 | apply (drule equalityD1) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 427 | apply (rename_tac y x) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 428 | apply (subgoal_tac "\<exists>k. k<n & f k = (x,y)") | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 429 | prefer 2 apply force | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 430 | apply clarify | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 431 | apply (rule_tac x=k in image_eqI, auto) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 432 | done | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 433 | |
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 434 | lemma finite_cartesian_productD2: | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 435 |      "[| finite (A <*> B); A \<noteq> {} |] ==> finite B"
 | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 436 | apply (auto simp add: finite_conv_nat_seg_image) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 437 | apply (drule_tac x=n in spec) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 438 | apply (drule_tac x="snd o f" in spec) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 439 | apply (auto simp add: o_def) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 440 | prefer 2 apply (force dest!: equalityD2) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 441 | apply (drule equalityD1) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 442 | apply (rename_tac x y) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 443 | apply (subgoal_tac "\<exists>k. k<n & f k = (x,y)") | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 444 | prefer 2 apply force | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 445 | apply clarify | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 446 | apply (rule_tac x=k in image_eqI, auto) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 447 | done | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 448 | |
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 449 | |
| 15392 | 450 | text {* The powerset of a finite set *}
 | 
| 12396 | 451 | |
| 452 | lemma finite_Pow_iff [iff]: "finite (Pow A) = finite A" | |
| 453 | proof | |
| 454 | assume "finite (Pow A)" | |
| 455 |   with _ have "finite ((%x. {x}) ` A)" by (rule finite_subset) blast
 | |
| 456 | thus "finite A" by (rule finite_imageD [unfolded inj_on_def]) simp | |
| 457 | next | |
| 458 | assume "finite A" | |
| 459 | thus "finite (Pow A)" | |
| 460 | by induct (simp_all add: finite_UnI finite_imageI Pow_insert) | |
| 461 | qed | |
| 462 | ||
| 29916 | 463 | lemma finite_Collect_subsets[simp,intro]: "finite A \<Longrightarrow> finite{B. B \<subseteq> A}"
 | 
| 464 | by(simp add: Pow_def[symmetric]) | |
| 15392 | 465 | |
| 29918 | 466 | |
| 15392 | 467 | lemma finite_UnionD: "finite(\<Union>A) \<Longrightarrow> finite A" | 
| 468 | by(blast intro: finite_subset[OF subset_Pow_Union]) | |
| 469 | ||
| 470 | ||
| 31441 | 471 | lemma finite_subset_image: | 
| 472 | assumes "finite B" | |
| 473 | shows "B \<subseteq> f ` A \<Longrightarrow> \<exists>C\<subseteq>A. finite C \<and> B = f ` C" | |
| 474 | using assms proof(induct) | |
| 475 | case empty thus ?case by simp | |
| 476 | next | |
| 477 | case insert thus ?case | |
| 478 | by (clarsimp simp del: image_insert simp add: image_insert[symmetric]) | |
| 479 | blast | |
| 480 | qed | |
| 481 | ||
| 482 | ||
| 26441 | 483 | subsection {* Class @{text finite}  *}
 | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 484 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 485 | setup {* Sign.add_path "finite" *} -- {*FIXME: name tweaking*}
 | 
| 29797 | 486 | class finite = | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 487 | assumes finite_UNIV: "finite (UNIV \<Colon> 'a set)" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 488 | setup {* Sign.parent_path *}
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 489 | hide const finite | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 490 | |
| 27430 | 491 | context finite | 
| 492 | begin | |
| 493 | ||
| 494 | lemma finite [simp]: "finite (A \<Colon> 'a set)" | |
| 26441 | 495 | by (rule subset_UNIV finite_UNIV finite_subset)+ | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 496 | |
| 27430 | 497 | end | 
| 498 | ||
| 26146 | 499 | lemma UNIV_unit [noatp]: | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 500 |   "UNIV = {()}" by auto
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 501 | |
| 26146 | 502 | instance unit :: finite | 
| 503 | by default (simp add: UNIV_unit) | |
| 504 | ||
| 505 | lemma UNIV_bool [noatp]: | |
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 506 |   "UNIV = {False, True}" by auto
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 507 | |
| 26146 | 508 | instance bool :: finite | 
| 509 | by default (simp add: UNIV_bool) | |
| 510 | ||
| 511 | instance * :: (finite, finite) finite | |
| 512 | by default (simp only: UNIV_Times_UNIV [symmetric] finite_cartesian_product finite) | |
| 513 | ||
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 514 | lemma inj_graph: "inj (%f. {(x, y). y = f x})"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 515 | by (rule inj_onI, auto simp add: expand_set_eq expand_fun_eq) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 516 | |
| 26146 | 517 | instance "fun" :: (finite, finite) finite | 
| 518 | proof | |
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 519 |   show "finite (UNIV :: ('a => 'b) set)"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 520 | proof (rule finite_imageD) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 521 |     let ?graph = "%f::'a => 'b. {(x, y). y = f x}"
 | 
| 26792 | 522 | have "range ?graph \<subseteq> Pow UNIV" by simp | 
| 523 |     moreover have "finite (Pow (UNIV :: ('a * 'b) set))"
 | |
| 524 | by (simp only: finite_Pow_iff finite) | |
| 525 | ultimately show "finite (range ?graph)" | |
| 526 | by (rule finite_subset) | |
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 527 | show "inj ?graph" by (rule inj_graph) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 528 | qed | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 529 | qed | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 530 | |
| 27981 | 531 | instance "+" :: (finite, finite) finite | 
| 532 | by default (simp only: UNIV_Plus_UNIV [symmetric] finite_Plus finite) | |
| 533 | ||
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 534 | |
| 15392 | 535 | subsection {* A fold functional for finite sets *}
 | 
| 536 | ||
| 537 | text {* The intended behaviour is
 | |
| 31916 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 538 | @{text "fold f z {x\<^isub>1, ..., x\<^isub>n} = f x\<^isub>1 (\<dots> (f x\<^isub>n z)\<dots>)"}
 | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 539 | if @{text f} is ``left-commutative'':
 | 
| 15392 | 540 | *} | 
| 541 | ||
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 542 | locale fun_left_comm = | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 543 | fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 544 | assumes fun_left_comm: "f x (f y z) = f y (f x z)" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 545 | begin | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 546 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 547 | text{* On a functional level it looks much nicer: *}
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 548 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 549 | lemma fun_comp_comm: "f x \<circ> f y = f y \<circ> f x" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 550 | by (simp add: fun_left_comm expand_fun_eq) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 551 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 552 | end | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 553 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 554 | inductive fold_graph :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> bool"
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 555 | for f :: "'a \<Rightarrow> 'b \<Rightarrow> 'b" and z :: 'b where | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 556 |   emptyI [intro]: "fold_graph f z {} z" |
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 557 | insertI [intro]: "x \<notin> A \<Longrightarrow> fold_graph f z A y | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 558 | \<Longrightarrow> fold_graph f z (insert x A) (f x y)" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 559 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 560 | inductive_cases empty_fold_graphE [elim!]: "fold_graph f z {} x"
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 561 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 562 | definition fold :: "('a \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b" where
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 563 | [code del]: "fold f z A = (THE y. fold_graph f z A y)" | 
| 15392 | 564 | |
| 15498 | 565 | text{*A tempting alternative for the definiens is
 | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 566 | @{term "if finite A then THE y. fold_graph f z A y else e"}.
 | 
| 15498 | 567 | It allows the removal of finiteness assumptions from the theorems | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 568 | @{text fold_comm}, @{text fold_reindex} and @{text fold_distrib}.
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 569 | The proofs become ugly. It is not worth the effort. (???) *} | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 570 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 571 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 572 | lemma Diff1_fold_graph: | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 573 |   "fold_graph f z (A - {x}) y \<Longrightarrow> x \<in> A \<Longrightarrow> fold_graph f z A (f x y)"
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 574 | by (erule insert_Diff [THEN subst], rule fold_graph.intros, auto) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 575 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 576 | lemma fold_graph_imp_finite: "fold_graph f z A x \<Longrightarrow> finite A" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 577 | by (induct set: fold_graph) auto | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 578 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 579 | lemma finite_imp_fold_graph: "finite A \<Longrightarrow> \<exists>x. fold_graph f z A x" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 580 | by (induct set: finite) auto | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 581 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 582 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 583 | subsubsection{*From @{const fold_graph} to @{term fold}*}
 | 
| 15392 | 584 | |
| 15510 | 585 | lemma image_less_Suc: "h ` {i. i < Suc m} = insert (h m) (h ` {i. i < m})"
 | 
| 19868 | 586 | by (auto simp add: less_Suc_eq) | 
| 15510 | 587 | |
| 588 | lemma insert_image_inj_on_eq: | |
| 589 |      "[|insert (h m) A = h ` {i. i < Suc m}; h m \<notin> A; 
 | |
| 590 |         inj_on h {i. i < Suc m}|] 
 | |
| 591 |       ==> A = h ` {i. i < m}"
 | |
| 592 | apply (auto simp add: image_less_Suc inj_on_def) | |
| 593 | apply (blast intro: less_trans) | |
| 594 | done | |
| 595 | ||
| 596 | lemma insert_inj_onE: | |
| 597 |   assumes aA: "insert a A = h`{i::nat. i<n}" and anot: "a \<notin> A" 
 | |
| 598 |       and inj_on: "inj_on h {i::nat. i<n}"
 | |
| 599 |   shows "\<exists>hm m. inj_on hm {i::nat. i<m} & A = hm ` {i. i<m} & m < n"
 | |
| 600 | proof (cases n) | |
| 601 | case 0 thus ?thesis using aA by auto | |
| 602 | next | |
| 603 | case (Suc m) | |
| 23389 | 604 | have nSuc: "n = Suc m" by fact | 
| 15510 | 605 | have mlessn: "m<n" by (simp add: nSuc) | 
| 15532 | 606 | from aA obtain k where hkeq: "h k = a" and klessn: "k<n" by (blast elim!: equalityE) | 
| 27165 | 607 | let ?hm = "Fun.swap k m h" | 
| 15520 | 608 |   have inj_hm: "inj_on ?hm {i. i < n}" using klessn mlessn 
 | 
| 609 | by (simp add: inj_on_swap_iff inj_on) | |
| 15510 | 610 | show ?thesis | 
| 15520 | 611 | proof (intro exI conjI) | 
| 612 |     show "inj_on ?hm {i. i < m}" using inj_hm
 | |
| 15510 | 613 | by (auto simp add: nSuc less_Suc_eq intro: subset_inj_on) | 
| 15520 | 614 | show "m<n" by (rule mlessn) | 
| 615 |     show "A = ?hm ` {i. i < m}" 
 | |
| 616 | proof (rule insert_image_inj_on_eq) | |
| 27165 | 617 |       show "inj_on (Fun.swap k m h) {i. i < Suc m}" using inj_hm nSuc by simp
 | 
| 15520 | 618 | show "?hm m \<notin> A" by (simp add: swap_def hkeq anot) | 
| 619 |       show "insert (?hm m) A = ?hm ` {i. i < Suc m}"
 | |
| 620 | using aA hkeq nSuc klessn | |
| 621 | by (auto simp add: swap_def image_less_Suc fun_upd_image | |
| 622 | less_Suc_eq inj_on_image_set_diff [OF inj_on]) | |
| 15479 | 623 | qed | 
| 624 | qed | |
| 625 | qed | |
| 626 | ||
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 627 | context fun_left_comm | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 628 | begin | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 629 | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 630 | lemma fold_graph_determ_aux: | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 631 |   "A = h`{i::nat. i<n} \<Longrightarrow> inj_on h {i. i<n}
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 632 | \<Longrightarrow> fold_graph f z A x \<Longrightarrow> fold_graph f z A x' | 
| 15392 | 633 | \<Longrightarrow> x' = x" | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 634 | proof (induct n arbitrary: A x x' h rule: less_induct) | 
| 15510 | 635 | case (less n) | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 636 |   have IH: "\<And>m h A x x'. m < n \<Longrightarrow> A = h ` {i. i<m}
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 637 |       \<Longrightarrow> inj_on h {i. i<m} \<Longrightarrow> fold_graph f z A x
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 638 | \<Longrightarrow> fold_graph f z A x' \<Longrightarrow> x' = x" by fact | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 639 | have Afoldx: "fold_graph f z A x" and Afoldx': "fold_graph f z A x'" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 640 |     and A: "A = h`{i. i<n}" and injh: "inj_on h {i. i<n}" by fact+
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 641 | show ?case | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 642 | proof (rule fold_graph.cases [OF Afoldx]) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 643 |     assume "A = {}" and "x = z"
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 644 | with Afoldx' show "x' = x" by auto | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 645 | next | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 646 | fix B b u | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 647 | assume AbB: "A = insert b B" and x: "x = f b u" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 648 | and notinB: "b \<notin> B" and Bu: "fold_graph f z B u" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 649 | show "x'=x" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 650 | proof (rule fold_graph.cases [OF Afoldx']) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 651 |       assume "A = {}" and "x' = z"
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 652 | with AbB show "x' = x" by blast | 
| 15392 | 653 | next | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 654 | fix C c v | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 655 | assume AcC: "A = insert c C" and x': "x' = f c v" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 656 | and notinC: "c \<notin> C" and Cv: "fold_graph f z C v" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 657 |       from A AbB have Beq: "insert b B = h`{i. i<n}" by simp
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 658 | from insert_inj_onE [OF Beq notinB injh] | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 659 |       obtain hB mB where inj_onB: "inj_on hB {i. i < mB}" 
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 660 |         and Beq: "B = hB ` {i. i < mB}" and lessB: "mB < n" by auto 
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 661 |       from A AcC have Ceq: "insert c C = h`{i. i<n}" by simp
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 662 | from insert_inj_onE [OF Ceq notinC injh] | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 663 |       obtain hC mC where inj_onC: "inj_on hC {i. i < mC}"
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 664 |         and Ceq: "C = hC ` {i. i < mC}" and lessC: "mC < n" by auto 
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 665 | show "x'=x" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 666 | proof cases | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 667 | assume "b=c" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 668 | then moreover have "B = C" using AbB AcC notinB notinC by auto | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 669 | ultimately show ?thesis using Bu Cv x x' IH [OF lessC Ceq inj_onC] | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 670 | by auto | 
| 15392 | 671 | next | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 672 | assume diff: "b \<noteq> c" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 673 | 	let ?D = "B - {c}"
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 674 | have B: "B = insert c ?D" and C: "C = insert b ?D" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 675 | using AbB AcC notinB notinC diff by(blast elim!:equalityE)+ | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 676 | have "finite A" by(rule fold_graph_imp_finite [OF Afoldx]) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 677 | with AbB have "finite ?D" by simp | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 678 | then obtain d where Dfoldd: "fold_graph f z ?D d" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 679 | using finite_imp_fold_graph by iprover | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 680 | moreover have cinB: "c \<in> B" using B by auto | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 681 | ultimately have "fold_graph f z B (f c d)" by(rule Diff1_fold_graph) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 682 | hence "f c d = u" by (rule IH [OF lessB Beq inj_onB Bu]) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 683 | moreover have "f b d = v" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 684 | proof (rule IH[OF lessC Ceq inj_onC Cv]) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 685 | show "fold_graph f z C (f b d)" using C notinB Dfoldd by fastsimp | 
| 15392 | 686 | qed | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 687 | ultimately show ?thesis | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 688 | using fun_left_comm [of c b] x x' by (auto simp add: o_def) | 
| 15392 | 689 | qed | 
| 690 | qed | |
| 691 | qed | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 692 | qed | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 693 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 694 | lemma fold_graph_determ: | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 695 | "fold_graph f z A x \<Longrightarrow> fold_graph f z A y \<Longrightarrow> y = x" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 696 | apply (frule fold_graph_imp_finite [THEN finite_imp_nat_seg_image_inj_on]) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 697 | apply (blast intro: fold_graph_determ_aux [rule_format]) | 
| 15392 | 698 | done | 
| 699 | ||
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 700 | lemma fold_equality: | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 701 | "fold_graph f z A y \<Longrightarrow> fold f z A = y" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 702 | by (unfold fold_def) (blast intro: fold_graph_determ) | 
| 15392 | 703 | |
| 704 | text{* The base case for @{text fold}: *}
 | |
| 705 | ||
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 706 | lemma (in -) fold_empty [simp]: "fold f z {} = z"
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 707 | by (unfold fold_def) blast | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 708 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 709 | text{* The various recursion equations for @{const fold}: *}
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 710 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 711 | lemma fold_insert_aux: "x \<notin> A | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 712 | \<Longrightarrow> fold_graph f z (insert x A) v \<longleftrightarrow> | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 713 | (\<exists>y. fold_graph f z A y \<and> v = f x y)" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 714 | apply auto | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 715 | apply (rule_tac A1 = A and f1 = f in finite_imp_fold_graph [THEN exE]) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 716 | apply (fastsimp dest: fold_graph_imp_finite) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 717 | apply (blast intro: fold_graph_determ) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 718 | done | 
| 15392 | 719 | |
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 720 | lemma fold_insert [simp]: | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 721 | "finite A ==> x \<notin> A ==> fold f z (insert x A) = f x (fold f z A)" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 722 | apply (simp add: fold_def fold_insert_aux) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 723 | apply (rule the_equality) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 724 | apply (auto intro: finite_imp_fold_graph | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 725 | cong add: conj_cong simp add: fold_def[symmetric] fold_equality) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 726 | done | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 727 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 728 | lemma fold_fun_comm: | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 729 | "finite A \<Longrightarrow> f x (fold f z A) = fold f (f x z) A" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 730 | proof (induct rule: finite_induct) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 731 | case empty then show ?case by simp | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 732 | next | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 733 | case (insert y A) then show ?case | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 734 | by (simp add: fun_left_comm[of x]) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 735 | qed | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 736 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 737 | lemma fold_insert2: | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 738 | "finite A \<Longrightarrow> x \<notin> A \<Longrightarrow> fold f z (insert x A) = fold f (f x z) A" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 739 | by (simp add: fold_insert fold_fun_comm) | 
| 15392 | 740 | |
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 741 | lemma fold_rec: | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 742 | assumes "finite A" and "x \<in> A" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 743 | shows "fold f z A = f x (fold f z (A - {x}))"
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 744 | proof - | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 745 |   have A: "A = insert x (A - {x})" using `x \<in> A` by blast
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 746 |   then have "fold f z A = fold f z (insert x (A - {x}))" by simp
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 747 |   also have "\<dots> = f x (fold f z (A - {x}))"
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 748 | by (rule fold_insert) (simp add: `finite A`)+ | 
| 15535 | 749 | finally show ?thesis . | 
| 750 | qed | |
| 751 | ||
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 752 | lemma fold_insert_remove: | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 753 | assumes "finite A" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 754 |   shows "fold f z (insert x A) = f x (fold f z (A - {x}))"
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 755 | proof - | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 756 | from `finite A` have "finite (insert x A)" by auto | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 757 | moreover have "x \<in> insert x A" by auto | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 758 |   ultimately have "fold f z (insert x A) = f x (fold f z (insert x A - {x}))"
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 759 | by (rule fold_rec) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 760 | then show ?thesis by simp | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 761 | qed | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 762 | |
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 763 | end | 
| 15392 | 764 | |
| 15480 | 765 | text{* A simplified version for idempotent functions: *}
 | 
| 766 | ||
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 767 | locale fun_left_comm_idem = fun_left_comm + | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 768 | assumes fun_left_idem: "f x (f x z) = f x z" | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 769 | begin | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 770 | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 771 | text{* The nice version: *}
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 772 | lemma fun_comp_idem : "f x o f x = f x" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 773 | by (simp add: fun_left_idem expand_fun_eq) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 774 | |
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 775 | lemma fold_insert_idem: | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 776 | assumes fin: "finite A" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 777 | shows "fold f z (insert x A) = f x (fold f z A)" | 
| 15480 | 778 | proof cases | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 779 | assume "x \<in> A" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 780 | then obtain B where "A = insert x B" and "x \<notin> B" by (rule set_insert) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 781 | then show ?thesis using assms by (simp add:fun_left_idem) | 
| 15480 | 782 | next | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 783 | assume "x \<notin> A" then show ?thesis using assms by simp | 
| 15480 | 784 | qed | 
| 785 | ||
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 786 | declare fold_insert[simp del] fold_insert_idem[simp] | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 787 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 788 | lemma fold_insert_idem2: | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 789 | "finite A \<Longrightarrow> fold f z (insert x A) = fold f (f x z) A" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 790 | by(simp add:fold_fun_comm) | 
| 15484 | 791 | |
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 792 | end | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 793 | |
| 31992 | 794 | context ab_semigroup_idem_mult | 
| 795 | begin | |
| 796 | ||
| 797 | lemma fun_left_comm_idem: "fun_left_comm_idem(op *)" | |
| 798 | apply unfold_locales | |
| 799 | apply (simp add: mult_ac) | |
| 800 | apply (simp add: mult_idem mult_assoc[symmetric]) | |
| 801 | done | |
| 802 | ||
| 803 | end | |
| 804 | ||
| 805 | context lower_semilattice | |
| 806 | begin | |
| 807 | ||
| 808 | lemma ab_semigroup_idem_mult_inf: "ab_semigroup_idem_mult inf" | |
| 809 | proof qed (rule inf_assoc inf_commute inf_idem)+ | |
| 810 | ||
| 811 | lemma fold_inf_insert[simp]: "finite A \<Longrightarrow> fold inf b (insert a A) = inf a (fold inf b A)" | |
| 812 | by(rule fun_left_comm_idem.fold_insert_idem[OF ab_semigroup_idem_mult.fun_left_comm_idem[OF ab_semigroup_idem_mult_inf]]) | |
| 813 | ||
| 814 | lemma inf_le_fold_inf: "finite A \<Longrightarrow> ALL a:A. b \<le> a \<Longrightarrow> inf b c \<le> fold inf c A" | |
| 32064 | 815 | by (induct pred: finite) (auto intro: le_infI1) | 
| 31992 | 816 | |
| 817 | lemma fold_inf_le_inf: "finite A \<Longrightarrow> a \<in> A \<Longrightarrow> fold inf b A \<le> inf a b" | |
| 818 | proof(induct arbitrary: a pred:finite) | |
| 819 | case empty thus ?case by simp | |
| 820 | next | |
| 821 | case (insert x A) | |
| 822 | show ?case | |
| 823 | proof cases | |
| 824 |     assume "A = {}" thus ?thesis using insert by simp
 | |
| 825 | next | |
| 32064 | 826 |     assume "A \<noteq> {}" thus ?thesis using insert by (auto intro: le_infI2)
 | 
| 31992 | 827 | qed | 
| 828 | qed | |
| 829 | ||
| 830 | end | |
| 831 | ||
| 832 | context upper_semilattice | |
| 833 | begin | |
| 834 | ||
| 835 | lemma ab_semigroup_idem_mult_sup: "ab_semigroup_idem_mult sup" | |
| 31993 | 836 | by (rule lower_semilattice.ab_semigroup_idem_mult_inf)(rule dual_semilattice) | 
| 31992 | 837 | |
| 838 | lemma fold_sup_insert[simp]: "finite A \<Longrightarrow> fold sup b (insert a A) = sup a (fold sup b A)" | |
| 31994 | 839 | by(rule lower_semilattice.fold_inf_insert)(rule dual_semilattice) | 
| 31992 | 840 | |
| 841 | lemma fold_sup_le_sup: "finite A \<Longrightarrow> ALL a:A. a \<le> b \<Longrightarrow> fold sup c A \<le> sup b c" | |
| 31993 | 842 | by(rule lower_semilattice.inf_le_fold_inf)(rule dual_semilattice) | 
| 31992 | 843 | |
| 844 | lemma sup_le_fold_sup: "finite A \<Longrightarrow> a \<in> A \<Longrightarrow> sup a b \<le> fold sup b A" | |
| 31993 | 845 | by(rule lower_semilattice.fold_inf_le_inf)(rule dual_semilattice) | 
| 31992 | 846 | |
| 847 | end | |
| 848 | ||
| 849 | ||
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 850 | subsubsection{* The derived combinator @{text fold_image} *}
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 851 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 852 | definition fold_image :: "('b \<Rightarrow> 'b \<Rightarrow> 'b) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'b \<Rightarrow> 'a set \<Rightarrow> 'b"
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 853 | where "fold_image f g = fold (%x y. f (g x) y)" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 854 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 855 | lemma fold_image_empty[simp]: "fold_image f g z {} = z"
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 856 | by(simp add:fold_image_def) | 
| 15392 | 857 | |
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 858 | context ab_semigroup_mult | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 859 | begin | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 860 | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 861 | lemma fold_image_insert[simp]: | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 862 | assumes "finite A" and "a \<notin> A" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 863 | shows "fold_image times g z (insert a A) = g a * (fold_image times g z A)" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 864 | proof - | 
| 29223 | 865 | interpret I: fun_left_comm "%x y. (g x) * y" | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 866 | by unfold_locales (simp add: mult_ac) | 
| 31992 | 867 | show ?thesis using assms by(simp add:fold_image_def) | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 868 | qed | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 869 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 870 | (* | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 871 | lemma fold_commute: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 872 | "finite A ==> (!!z. x * (fold times g z A) = fold times g (x * z) A)" | 
| 22262 | 873 | apply (induct set: finite) | 
| 21575 | 874 | apply simp | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 875 | apply (simp add: mult_left_commute [of x]) | 
| 15392 | 876 | done | 
| 877 | ||
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 878 | lemma fold_nest_Un_Int: | 
| 15392 | 879 | "finite A ==> finite B | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 880 | ==> fold times g (fold times g z B) A = fold times g (fold times g z (A Int B)) (A Un B)" | 
| 22262 | 881 | apply (induct set: finite) | 
| 21575 | 882 | apply simp | 
| 15392 | 883 | apply (simp add: fold_commute Int_insert_left insert_absorb) | 
| 884 | done | |
| 885 | ||
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 886 | lemma fold_nest_Un_disjoint: | 
| 15392 | 887 |   "finite A ==> finite B ==> A Int B = {}
 | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 888 | ==> fold times g z (A Un B) = fold times g (fold times g z B) A" | 
| 15392 | 889 | by (simp add: fold_nest_Un_Int) | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 890 | *) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 891 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 892 | lemma fold_image_reindex: | 
| 15487 | 893 | assumes fin: "finite A" | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 894 | shows "inj_on h A \<Longrightarrow> fold_image times g z (h`A) = fold_image times (g\<circ>h) z A" | 
| 31992 | 895 | using fin by induct auto | 
| 15392 | 896 | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 897 | (* | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 898 | text{*
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 899 | Fusion theorem, as described in Graham Hutton's paper, | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 900 | A Tutorial on the Universality and Expressiveness of Fold, | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 901 | JFP 9:4 (355-372), 1999. | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 902 | *} | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 903 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 904 | lemma fold_fusion: | 
| 27611 | 905 | assumes "ab_semigroup_mult g" | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 906 | assumes fin: "finite A" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 907 | and hyp: "\<And>x y. h (g x y) = times x (h y)" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 908 | shows "h (fold g j w A) = fold times j (h w) A" | 
| 27611 | 909 | proof - | 
| 29223 | 910 | class_interpret ab_semigroup_mult [g] by fact | 
| 27611 | 911 | show ?thesis using fin hyp by (induct set: finite) simp_all | 
| 912 | qed | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 913 | *) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 914 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 915 | lemma fold_image_cong: | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 916 | "finite A \<Longrightarrow> | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 917 | (!!x. x:A ==> g x = h x) ==> fold_image times g z A = fold_image times h z A" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 918 | apply (subgoal_tac "ALL C. C <= A --> (ALL x:C. g x = h x) --> fold_image times g z C = fold_image times h z C") | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 919 | apply simp | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 920 | apply (erule finite_induct, simp) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 921 | apply (simp add: subset_insert_iff, clarify) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 922 | apply (subgoal_tac "finite C") | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 923 | prefer 2 apply (blast dest: finite_subset [COMP swap_prems_rl]) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 924 | apply (subgoal_tac "C = insert x (C - {x})")
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 925 | prefer 2 apply blast | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 926 | apply (erule ssubst) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 927 | apply (drule spec) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 928 | apply (erule (1) notE impE) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 929 | apply (simp add: Ball_def del: insert_Diff_single) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 930 | done | 
| 15392 | 931 | |
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 932 | end | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 933 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 934 | context comm_monoid_mult | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 935 | begin | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 936 | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 937 | lemma fold_image_Un_Int: | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 938 | "finite A ==> finite B ==> | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 939 | fold_image times g 1 A * fold_image times g 1 B = | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 940 | fold_image times g 1 (A Un B) * fold_image times g 1 (A Int B)" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 941 | by (induct set: finite) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 942 | (auto simp add: mult_ac insert_absorb Int_insert_left) | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 943 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 944 | corollary fold_Un_disjoint: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 945 |   "finite A ==> finite B ==> A Int B = {} ==>
 | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 946 | fold_image times g 1 (A Un B) = | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 947 | fold_image times g 1 A * fold_image times g 1 B" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 948 | by (simp add: fold_image_Un_Int) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 949 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 950 | lemma fold_image_UN_disjoint: | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 951 | "\<lbrakk> finite I; ALL i:I. finite (A i); | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 952 |      ALL i:I. ALL j:I. i \<noteq> j --> A i Int A j = {} \<rbrakk>
 | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 953 | \<Longrightarrow> fold_image times g 1 (UNION I A) = | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 954 | fold_image times (%i. fold_image times g 1 (A i)) 1 I" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 955 | apply (induct set: finite, simp, atomize) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 956 | apply (subgoal_tac "ALL i:F. x \<noteq> i") | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 957 | prefer 2 apply blast | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 958 | apply (subgoal_tac "A x Int UNION F A = {}")
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 959 | prefer 2 apply blast | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 960 | apply (simp add: fold_Un_disjoint) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 961 | done | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 962 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 963 | lemma fold_image_Sigma: "finite A ==> ALL x:A. finite (B x) ==> | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 964 | fold_image times (%x. fold_image times (g x) 1 (B x)) 1 A = | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 965 | fold_image times (split g) 1 (SIGMA x:A. B x)" | 
| 15392 | 966 | apply (subst Sigma_def) | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 967 | apply (subst fold_image_UN_disjoint, assumption, simp) | 
| 15392 | 968 | apply blast | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 969 | apply (erule fold_image_cong) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 970 | apply (subst fold_image_UN_disjoint, simp, simp) | 
| 15392 | 971 | apply blast | 
| 15506 | 972 | apply simp | 
| 15392 | 973 | done | 
| 974 | ||
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 975 | lemma fold_image_distrib: "finite A \<Longrightarrow> | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 976 | fold_image times (%x. g x * h x) 1 A = | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 977 | fold_image times g 1 A * fold_image times h 1 A" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 978 | by (erule finite_induct) (simp_all add: mult_ac) | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 979 | |
| 30260 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 980 | lemma fold_image_related: | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 981 | assumes Re: "R e e" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 982 | and Rop: "\<forall>x1 y1 x2 y2. R x1 x2 \<and> R y1 y2 \<longrightarrow> R (x1 * y1) (x2 * y2)" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 983 | and fS: "finite S" and Rfg: "\<forall>x\<in>S. R (h x) (g x)" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 984 | shows "R (fold_image (op *) h e S) (fold_image (op *) g e S)" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 985 | using fS by (rule finite_subset_induct) (insert assms, auto) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 986 | |
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 987 | lemma fold_image_eq_general: | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 988 | assumes fS: "finite S" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 989 | and h: "\<forall>y\<in>S'. \<exists>!x. x\<in> S \<and> h(x) = y" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 990 | and f12: "\<forall>x\<in>S. h x \<in> S' \<and> f2(h x) = f1 x" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 991 | shows "fold_image (op *) f1 e S = fold_image (op *) f2 e S'" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 992 | proof- | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 993 | from h f12 have hS: "h ` S = S'" by auto | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 994 |   {fix x y assume H: "x \<in> S" "y \<in> S" "h x = h y"
 | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 995 | from f12 h H have "x = y" by auto } | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 996 | hence hinj: "inj_on h S" unfolding inj_on_def Ex1_def by blast | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 997 | from f12 have th: "\<And>x. x \<in> S \<Longrightarrow> (f2 \<circ> h) x = f1 x" by auto | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 998 | from hS have "fold_image (op *) f2 e S' = fold_image (op *) f2 e (h ` S)" by simp | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 999 | also have "\<dots> = fold_image (op *) (f2 o h) e S" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1000 | using fold_image_reindex[OF fS hinj, of f2 e] . | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1001 | also have "\<dots> = fold_image (op *) f1 e S " using th fold_image_cong[OF fS, of "f2 o h" f1 e] | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1002 | by blast | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1003 | finally show ?thesis .. | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1004 | qed | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1005 | |
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1006 | lemma fold_image_eq_general_inverses: | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1007 | assumes fS: "finite S" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1008 | and kh: "\<And>y. y \<in> T \<Longrightarrow> k y \<in> S \<and> h (k y) = y" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1009 | and hk: "\<And>x. x \<in> S \<Longrightarrow> h x \<in> T \<and> k (h x) = x \<and> g (h x) = f x" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1010 | shows "fold_image (op *) f e S = fold_image (op *) g e T" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1011 | (* metis solves it, but not yet available here *) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1012 | apply (rule fold_image_eq_general[OF fS, of T h g f e]) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1013 | apply (rule ballI) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1014 | apply (frule kh) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1015 | apply (rule ex1I[]) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1016 | apply blast | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1017 | apply clarsimp | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1018 | apply (drule hk) apply simp | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1019 | apply (rule sym) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1020 | apply (erule conjunct1[OF conjunct2[OF hk]]) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1021 | apply (rule ballI) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1022 | apply (drule hk) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1023 | apply blast | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1024 | done | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1025 | |
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 1026 | end | 
| 22917 | 1027 | |
| 15402 | 1028 | subsection {* Generalized summation over a set *}
 | 
| 1029 | ||
| 30729 
461ee3e49ad3
interpretation/interpret: prefixes are mandatory by default;
 wenzelm parents: 
30325diff
changeset | 1030 | interpretation comm_monoid_add: comm_monoid_mult "0::'a::comm_monoid_add" "op +" | 
| 28823 | 1031 | proof qed (auto intro: add_assoc add_commute) | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 1032 | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1033 | definition setsum :: "('a => 'b) => 'a set => 'b::comm_monoid_add"
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1034 | where "setsum f A == if finite A then fold_image (op +) f 0 A else 0" | 
| 15402 | 1035 | |
| 19535 | 1036 | abbreviation | 
| 21404 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
21249diff
changeset | 1037 |   Setsum  ("\<Sum>_" [1000] 999) where
 | 
| 19535 | 1038 | "\<Sum>A == setsum (%x. x) A" | 
| 1039 | ||
| 15402 | 1040 | text{* Now: lot's of fancy syntax. First, @{term "setsum (%x. e) A"} is
 | 
| 1041 | written @{text"\<Sum>x\<in>A. e"}. *}
 | |
| 1042 | ||
| 1043 | syntax | |
| 17189 | 1044 |   "_setsum" :: "pttrn => 'a set => 'b => 'b::comm_monoid_add"    ("(3SUM _:_. _)" [0, 51, 10] 10)
 | 
| 15402 | 1045 | syntax (xsymbols) | 
| 17189 | 1046 |   "_setsum" :: "pttrn => 'a set => 'b => 'b::comm_monoid_add"    ("(3\<Sum>_\<in>_. _)" [0, 51, 10] 10)
 | 
| 15402 | 1047 | syntax (HTML output) | 
| 17189 | 1048 |   "_setsum" :: "pttrn => 'a set => 'b => 'b::comm_monoid_add"    ("(3\<Sum>_\<in>_. _)" [0, 51, 10] 10)
 | 
| 15402 | 1049 | |
| 1050 | translations -- {* Beware of argument permutation! *}
 | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1051 | "SUM i:A. b" == "CONST setsum (%i. b) A" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1052 | "\<Sum>i\<in>A. b" == "CONST setsum (%i. b) A" | 
| 15402 | 1053 | |
| 1054 | text{* Instead of @{term"\<Sum>x\<in>{x. P}. e"} we introduce the shorter
 | |
| 1055 |  @{text"\<Sum>x|P. e"}. *}
 | |
| 1056 | ||
| 1057 | syntax | |
| 17189 | 1058 |   "_qsetsum" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a" ("(3SUM _ |/ _./ _)" [0,0,10] 10)
 | 
| 15402 | 1059 | syntax (xsymbols) | 
| 17189 | 1060 |   "_qsetsum" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a" ("(3\<Sum>_ | (_)./ _)" [0,0,10] 10)
 | 
| 15402 | 1061 | syntax (HTML output) | 
| 17189 | 1062 |   "_qsetsum" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a" ("(3\<Sum>_ | (_)./ _)" [0,0,10] 10)
 | 
| 15402 | 1063 | |
| 1064 | translations | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1065 |   "SUM x|P. t" => "CONST setsum (%x. t) {x. P}"
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1066 |   "\<Sum>x|P. t" => "CONST setsum (%x. t) {x. P}"
 | 
| 15402 | 1067 | |
| 1068 | print_translation {*
 | |
| 1069 | let | |
| 19535 | 1070 |   fun setsum_tr' [Abs(x,Tx,t), Const ("Collect",_) $ Abs(y,Ty,P)] = 
 | 
| 1071 | if x<>y then raise Match | |
| 1072 | else let val x' = Syntax.mark_bound x | |
| 1073 | val t' = subst_bound(x',t) | |
| 1074 | val P' = subst_bound(x',P) | |
| 1075 | in Syntax.const "_qsetsum" $ Syntax.mark_bound x $ P' $ t' end | |
| 1076 | in [("setsum", setsum_tr')] end
 | |
| 15402 | 1077 | *} | 
| 1078 | ||
| 19535 | 1079 | |
| 15402 | 1080 | lemma setsum_empty [simp]: "setsum f {} = 0"
 | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1081 | by (simp add: setsum_def) | 
| 15402 | 1082 | |
| 1083 | lemma setsum_insert [simp]: | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1084 | "finite F ==> a \<notin> F ==> setsum f (insert a F) = f a + setsum f F" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1085 | by (simp add: setsum_def) | 
| 15402 | 1086 | |
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1087 | lemma setsum_infinite [simp]: "~ finite A ==> setsum f A = 0" | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1088 | by (simp add: setsum_def) | 
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1089 | |
| 15402 | 1090 | lemma setsum_reindex: | 
| 1091 | "inj_on f B ==> setsum h (f ` B) = setsum (h \<circ> f) B" | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1092 | by(auto simp add: setsum_def comm_monoid_add.fold_image_reindex dest!:finite_imageD) | 
| 15402 | 1093 | |
| 1094 | lemma setsum_reindex_id: | |
| 1095 | "inj_on f B ==> setsum f B = setsum id (f ` B)" | |
| 1096 | by (auto simp add: setsum_reindex) | |
| 1097 | ||
| 29674 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1098 | lemma setsum_reindex_nonzero: | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1099 | assumes fS: "finite S" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1100 | and nz: "\<And> x y. x \<in> S \<Longrightarrow> y \<in> S \<Longrightarrow> x \<noteq> y \<Longrightarrow> f x = f y \<Longrightarrow> h (f x) = 0" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1101 | shows "setsum h (f ` S) = setsum (h o f) S" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1102 | using nz | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1103 | proof(induct rule: finite_induct[OF fS]) | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1104 | case 1 thus ?case by simp | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1105 | next | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1106 | case (2 x F) | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1107 |   {assume fxF: "f x \<in> f ` F" hence "\<exists>y \<in> F . f y = f x" by auto
 | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1108 | then obtain y where y: "y \<in> F" "f x = f y" by auto | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1109 | from "2.hyps" y have xy: "x \<noteq> y" by auto | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1110 | |
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1111 | from "2.prems"[of x y] "2.hyps" xy y have h0: "h (f x) = 0" by simp | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1112 | have "setsum h (f ` insert x F) = setsum h (f ` F)" using fxF by auto | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1113 | also have "\<dots> = setsum (h o f) (insert x F)" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1114 | unfolding setsum_insert[OF `finite F` `x\<notin>F`] | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1115 | using h0 | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1116 | apply simp | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1117 | apply (rule "2.hyps"(3)) | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1118 | apply (rule_tac y="y" in "2.prems") | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1119 | apply simp_all | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1120 | done | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1121 | finally have ?case .} | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1122 | moreover | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1123 |   {assume fxF: "f x \<notin> f ` F"
 | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1124 | have "setsum h (f ` insert x F) = h (f x) + setsum h (f ` F)" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1125 | using fxF "2.hyps" by simp | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1126 | also have "\<dots> = setsum (h o f) (insert x F)" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1127 | unfolding setsum_insert[OF `finite F` `x\<notin>F`] | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1128 | apply simp | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1129 | apply (rule cong[OF refl[of "op + (h (f x))"]]) | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1130 | apply (rule "2.hyps"(3)) | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1131 | apply (rule_tac y="y" in "2.prems") | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1132 | apply simp_all | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1133 | done | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1134 | finally have ?case .} | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1135 | ultimately show ?case by blast | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1136 | qed | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1137 | |
| 15402 | 1138 | lemma setsum_cong: | 
| 1139 | "A = B ==> (!!x. x:B ==> f x = g x) ==> setsum f A = setsum g B" | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1140 | by(fastsimp simp: setsum_def intro: comm_monoid_add.fold_image_cong) | 
| 15402 | 1141 | |
| 16733 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 nipkow parents: 
16632diff
changeset | 1142 | lemma strong_setsum_cong[cong]: | 
| 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 nipkow parents: 
16632diff
changeset | 1143 | "A = B ==> (!!x. x:B =simp=> f x = g x) | 
| 
236dfafbeb63
linear arithmetic now takes "&" in assumptions apart.
 nipkow parents: 
16632diff
changeset | 1144 | ==> setsum (%x. f x) A = setsum (%x. g x) B" | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1145 | by(fastsimp simp: simp_implies_def setsum_def intro: comm_monoid_add.fold_image_cong) | 
| 16632 
ad2895beef79
Added strong_setsum_cong and strong_setprod_cong.
 berghofe parents: 
16550diff
changeset | 1146 | |
| 15554 | 1147 | lemma setsum_cong2: "\<lbrakk>\<And>x. x \<in> A \<Longrightarrow> f x = g x\<rbrakk> \<Longrightarrow> setsum f A = setsum g A"; | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1148 | by (rule setsum_cong[OF refl], auto); | 
| 15554 | 1149 | |
| 15402 | 1150 | lemma setsum_reindex_cong: | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1151 | "[|inj_on f A; B = f ` A; !!a. a:A \<Longrightarrow> g a = h (f a)|] | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1152 | ==> setsum h B = setsum g A" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1153 | by (simp add: setsum_reindex cong: setsum_cong) | 
| 15402 | 1154 | |
| 29674 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1155 | |
| 15542 | 1156 | lemma setsum_0[simp]: "setsum (%i. 0) A = 0" | 
| 15402 | 1157 | apply (clarsimp simp: setsum_def) | 
| 15765 | 1158 | apply (erule finite_induct, auto) | 
| 15402 | 1159 | done | 
| 1160 | ||
| 15543 | 1161 | lemma setsum_0': "ALL a:A. f a = 0 ==> setsum f A = 0" | 
| 1162 | by(simp add:setsum_cong) | |
| 15402 | 1163 | |
| 1164 | lemma setsum_Un_Int: "finite A ==> finite B ==> | |
| 1165 | setsum g (A Un B) + setsum g (A Int B) = setsum g A + setsum g B" | |
| 1166 |   -- {* The reversed orientation looks more natural, but LOOPS as a simprule! *}
 | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1167 | by(simp add: setsum_def comm_monoid_add.fold_image_Un_Int [symmetric]) | 
| 15402 | 1168 | |
| 1169 | lemma setsum_Un_disjoint: "finite A ==> finite B | |
| 1170 |   ==> A Int B = {} ==> setsum g (A Un B) = setsum g A + setsum g B"
 | |
| 1171 | by (subst setsum_Un_Int [symmetric], auto) | |
| 1172 | ||
| 29674 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1173 | lemma setsum_mono_zero_left: | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1174 | assumes fT: "finite T" and ST: "S \<subseteq> T" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1175 | and z: "\<forall>i \<in> T - S. f i = 0" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1176 | shows "setsum f S = setsum f T" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1177 | proof- | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1178 | have eq: "T = S \<union> (T - S)" using ST by blast | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1179 |   have d: "S \<inter> (T - S) = {}" using ST by blast
 | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1180 | from fT ST have f: "finite S" "finite (T - S)" by (auto intro: finite_subset) | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1181 | show ?thesis | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1182 | by (simp add: setsum_Un_disjoint[OF f d, unfolded eq[symmetric]] setsum_0'[OF z]) | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1183 | qed | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1184 | |
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1185 | lemma setsum_mono_zero_right: | 
| 30837 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 nipkow parents: 
30729diff
changeset | 1186 | "finite T \<Longrightarrow> S \<subseteq> T \<Longrightarrow> \<forall>i \<in> T - S. f i = 0 \<Longrightarrow> setsum f T = setsum f S" | 
| 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 nipkow parents: 
30729diff
changeset | 1187 | by(blast intro!: setsum_mono_zero_left[symmetric]) | 
| 29674 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1188 | |
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1189 | lemma setsum_mono_zero_cong_left: | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1190 | assumes fT: "finite T" and ST: "S \<subseteq> T" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1191 | and z: "\<forall>i \<in> T - S. g i = 0" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1192 | and fg: "\<And>x. x \<in> S \<Longrightarrow> f x = g x" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1193 | shows "setsum f S = setsum g T" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1194 | proof- | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1195 | have eq: "T = S \<union> (T - S)" using ST by blast | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1196 |   have d: "S \<inter> (T - S) = {}" using ST by blast
 | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1197 | from fT ST have f: "finite S" "finite (T - S)" by (auto intro: finite_subset) | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1198 | show ?thesis | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1199 | using fg by (simp add: setsum_Un_disjoint[OF f d, unfolded eq[symmetric]] setsum_0'[OF z]) | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1200 | qed | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1201 | |
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1202 | lemma setsum_mono_zero_cong_right: | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1203 | assumes fT: "finite T" and ST: "S \<subseteq> T" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1204 | and z: "\<forall>i \<in> T - S. f i = 0" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1205 | and fg: "\<And>x. x \<in> S \<Longrightarrow> f x = g x" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1206 | shows "setsum f T = setsum g S" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1207 | using setsum_mono_zero_cong_left[OF fT ST z] fg[symmetric] by auto | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1208 | |
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1209 | lemma setsum_delta: | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1210 | assumes fS: "finite S" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1211 | shows "setsum (\<lambda>k. if k=a then b k else 0) S = (if a \<in> S then b a else 0)" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1212 | proof- | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1213 | let ?f = "(\<lambda>k. if k=a then b k else 0)" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1214 |   {assume a: "a \<notin> S"
 | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1215 | hence "\<forall> k\<in> S. ?f k = 0" by simp | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1216 | hence ?thesis using a by simp} | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1217 | moreover | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1218 |   {assume a: "a \<in> S"
 | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1219 |     let ?A = "S - {a}"
 | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1220 |     let ?B = "{a}"
 | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1221 | have eq: "S = ?A \<union> ?B" using a by blast | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1222 |     have dj: "?A \<inter> ?B = {}" by simp
 | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1223 | from fS have fAB: "finite ?A" "finite ?B" by auto | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1224 | have "setsum ?f S = setsum ?f ?A + setsum ?f ?B" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1225 | using setsum_Un_disjoint[OF fAB dj, of ?f, unfolded eq[symmetric]] | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1226 | by simp | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1227 | then have ?thesis using a by simp} | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1228 | ultimately show ?thesis by blast | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1229 | qed | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1230 | lemma setsum_delta': | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1231 | assumes fS: "finite S" shows | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1232 | "setsum (\<lambda>k. if a = k then b k else 0) S = | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1233 | (if a\<in> S then b a else 0)" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1234 | using setsum_delta[OF fS, of a b, symmetric] | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1235 | by (auto intro: setsum_cong) | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1236 | |
| 30260 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1237 | lemma setsum_restrict_set: | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1238 | assumes fA: "finite A" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1239 | shows "setsum f (A \<inter> B) = setsum (\<lambda>x. if x \<in> B then f x else 0) A" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1240 | proof- | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1241 | from fA have fab: "finite (A \<inter> B)" by auto | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1242 | have aba: "A \<inter> B \<subseteq> A" by blast | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1243 | let ?g = "\<lambda>x. if x \<in> A\<inter>B then f x else 0" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1244 | from setsum_mono_zero_left[OF fA aba, of ?g] | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1245 | show ?thesis by simp | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1246 | qed | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1247 | |
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1248 | lemma setsum_cases: | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1249 | assumes fA: "finite A" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1250 | shows "setsum (\<lambda>x. if x \<in> B then f x else g x) A = | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1251 | setsum f (A \<inter> B) + setsum g (A \<inter> - B)" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1252 | proof- | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1253 |   have a: "A = A \<inter> B \<union> A \<inter> -B" "(A \<inter> B) \<inter> (A \<inter> -B) = {}" 
 | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1254 | by blast+ | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1255 | from fA | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1256 | have f: "finite (A \<inter> B)" "finite (A \<inter> -B)" by auto | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1257 | let ?g = "\<lambda>x. if x \<in> B then f x else g x" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1258 | from setsum_Un_disjoint[OF f a(2), of ?g] a(1) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1259 | show ?thesis by simp | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1260 | qed | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1261 | |
| 29674 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1262 | |
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1263 | (*But we can't get rid of finite I. If infinite, although the rhs is 0, | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1264 | the lhs need not be, since UNION I A could still be finite.*) | 
| 15402 | 1265 | lemma setsum_UN_disjoint: | 
| 1266 | "finite I ==> (ALL i:I. finite (A i)) ==> | |
| 1267 |         (ALL i:I. ALL j:I. i \<noteq> j --> A i Int A j = {}) ==>
 | |
| 1268 | setsum f (UNION I A) = (\<Sum>i\<in>I. setsum f (A i))" | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1269 | by(simp add: setsum_def comm_monoid_add.fold_image_UN_disjoint cong: setsum_cong) | 
| 15402 | 1270 | |
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1271 | text{*No need to assume that @{term C} is finite.  If infinite, the rhs is
 | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1272 | directly 0, and @{term "Union C"} is also infinite, hence the lhs is also 0.*}
 | 
| 15402 | 1273 | lemma setsum_Union_disjoint: | 
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1274 | "[| (ALL A:C. finite A); | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1275 |       (ALL A:C. ALL B:C. A \<noteq> B --> A Int B = {}) |]
 | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1276 | ==> setsum f (Union C) = setsum (setsum f) C" | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1277 | apply (cases "finite C") | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1278 | prefer 2 apply (force dest: finite_UnionD simp add: setsum_def) | 
| 15402 | 1279 | apply (frule setsum_UN_disjoint [of C id f]) | 
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1280 | apply (unfold Union_def id_def, assumption+) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1281 | done | 
| 15402 | 1282 | |
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1283 | (*But we can't get rid of finite A. If infinite, although the lhs is 0, | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1284 | the rhs need not be, since SIGMA A B could still be finite.*) | 
| 15402 | 1285 | lemma setsum_Sigma: "finite A ==> ALL x:A. finite (B x) ==> | 
| 17189 | 1286 | (\<Sum>x\<in>A. (\<Sum>y\<in>B x. f x y)) = (\<Sum>(x,y)\<in>(SIGMA x:A. B x). f x y)" | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1287 | by(simp add:setsum_def comm_monoid_add.fold_image_Sigma split_def cong:setsum_cong) | 
| 15402 | 1288 | |
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1289 | text{*Here we can eliminate the finiteness assumptions, by cases.*}
 | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1290 | lemma setsum_cartesian_product: | 
| 17189 | 1291 | "(\<Sum>x\<in>A. (\<Sum>y\<in>B. f x y)) = (\<Sum>(x,y) \<in> A <*> B. f x y)" | 
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1292 | apply (cases "finite A") | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1293 | apply (cases "finite B") | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1294 | apply (simp add: setsum_Sigma) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1295 |  apply (cases "A={}", simp)
 | 
| 15543 | 1296 | apply (simp) | 
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1297 | apply (auto simp add: setsum_def | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1298 | dest: finite_cartesian_productD1 finite_cartesian_productD2) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1299 | done | 
| 15402 | 1300 | |
| 1301 | lemma setsum_addf: "setsum (%x. f x + g x) A = (setsum f A + setsum g A)" | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1302 | by(simp add:setsum_def comm_monoid_add.fold_image_distrib) | 
| 15402 | 1303 | |
| 1304 | ||
| 1305 | subsubsection {* Properties in more restricted classes of structures *}
 | |
| 1306 | ||
| 1307 | lemma setsum_SucD: "setsum f A = Suc n ==> EX a:A. 0 < f a" | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1308 | apply (case_tac "finite A") | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1309 | prefer 2 apply (simp add: setsum_def) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1310 | apply (erule rev_mp) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1311 | apply (erule finite_induct, auto) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1312 | done | 
| 15402 | 1313 | |
| 1314 | lemma setsum_eq_0_iff [simp]: | |
| 1315 | "finite F ==> (setsum f F = 0) = (ALL a:F. f a = (0::nat))" | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1316 | by (induct set: finite) auto | 
| 15402 | 1317 | |
| 30859 | 1318 | lemma setsum_eq_Suc0_iff: "finite A \<Longrightarrow> | 
| 1319 | (setsum f A = Suc 0) = (EX a:A. f a = Suc 0 & (ALL b:A. a\<noteq>b \<longrightarrow> f b = 0))" | |
| 1320 | apply(erule finite_induct) | |
| 1321 | apply (auto simp add:add_is_1) | |
| 1322 | done | |
| 1323 | ||
| 1324 | lemmas setsum_eq_1_iff = setsum_eq_Suc0_iff[simplified One_nat_def[symmetric]] | |
| 1325 | ||
| 15402 | 1326 | lemma setsum_Un_nat: "finite A ==> finite B ==> | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1327 | (setsum f (A Un B) :: nat) = setsum f A + setsum f B - setsum f (A Int B)" | 
| 15402 | 1328 |   -- {* For the natural numbers, we have subtraction. *}
 | 
| 29667 | 1329 | by (subst setsum_Un_Int [symmetric], auto simp add: algebra_simps) | 
| 15402 | 1330 | |
| 1331 | lemma setsum_Un: "finite A ==> finite B ==> | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1332 | (setsum f (A Un B) :: 'a :: ab_group_add) = | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1333 | setsum f A + setsum f B - setsum f (A Int B)" | 
| 29667 | 1334 | by (subst setsum_Un_Int [symmetric], auto simp add: algebra_simps) | 
| 15402 | 1335 | |
| 30260 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1336 | lemma (in comm_monoid_mult) fold_image_1: "finite S \<Longrightarrow> (\<forall>x\<in>S. f x = 1) \<Longrightarrow> fold_image op * f 1 S = 1" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1337 | apply (induct set: finite) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1338 | apply simp by (auto simp add: fold_image_insert) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1339 | |
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1340 | lemma (in comm_monoid_mult) fold_image_Un_one: | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1341 | assumes fS: "finite S" and fT: "finite T" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1342 | and I0: "\<forall>x \<in> S\<inter>T. f x = 1" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1343 | shows "fold_image (op *) f 1 (S \<union> T) = fold_image (op *) f 1 S * fold_image (op *) f 1 T" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1344 | proof- | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1345 | have "fold_image op * f 1 (S \<inter> T) = 1" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1346 | apply (rule fold_image_1) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1347 | using fS fT I0 by auto | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1348 | with fold_image_Un_Int[OF fS fT] show ?thesis by simp | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1349 | qed | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1350 | |
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1351 | lemma setsum_eq_general_reverses: | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1352 | assumes fS: "finite S" and fT: "finite T" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1353 | and kh: "\<And>y. y \<in> T \<Longrightarrow> k y \<in> S \<and> h (k y) = y" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1354 | and hk: "\<And>x. x \<in> S \<Longrightarrow> h x \<in> T \<and> k (h x) = x \<and> g (h x) = f x" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1355 | shows "setsum f S = setsum g T" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1356 | apply (simp add: setsum_def fS fT) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1357 | apply (rule comm_monoid_add.fold_image_eq_general_inverses[OF fS]) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1358 | apply (erule kh) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1359 | apply (erule hk) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1360 | done | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1361 | |
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1362 | |
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1363 | |
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1364 | lemma setsum_Un_zero: | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1365 | assumes fS: "finite S" and fT: "finite T" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1366 | and I0: "\<forall>x \<in> S\<inter>T. f x = 0" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1367 | shows "setsum f (S \<union> T) = setsum f S + setsum f T" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1368 | using fS fT | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1369 | apply (simp add: setsum_def) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1370 | apply (rule comm_monoid_add.fold_image_Un_one) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1371 | using I0 by auto | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1372 | |
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1373 | |
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1374 | lemma setsum_UNION_zero: | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1375 | assumes fS: "finite S" and fSS: "\<forall>T \<in> S. finite T" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1376 | and f0: "\<And>T1 T2 x. T1\<in>S \<Longrightarrow> T2\<in>S \<Longrightarrow> T1 \<noteq> T2 \<Longrightarrow> x \<in> T1 \<Longrightarrow> x \<in> T2 \<Longrightarrow> f x = 0" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1377 | shows "setsum f (\<Union>S) = setsum (\<lambda>T. setsum f T) S" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1378 | using fSS f0 | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1379 | proof(induct rule: finite_induct[OF fS]) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1380 | case 1 thus ?case by simp | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1381 | next | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1382 | case (2 T F) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1383 | then have fTF: "finite T" "\<forall>T\<in>F. finite T" "finite F" and TF: "T \<notin> F" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1384 | and H: "setsum f (\<Union> F) = setsum (setsum f) F" by (auto simp add: finite_insert) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1385 | from fTF have fUF: "finite (\<Union>F)" by (auto intro: finite_Union) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1386 | from "2.prems" TF fTF | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1387 | show ?case | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1388 | by (auto simp add: H[symmetric] intro: setsum_Un_zero[OF fTF(1) fUF, of f]) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1389 | qed | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1390 | |
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1391 | |
| 15402 | 1392 | lemma setsum_diff1_nat: "(setsum f (A - {a}) :: nat) =
 | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1393 | (if a:A then setsum f A - f a else setsum f A)" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1394 | apply (case_tac "finite A") | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1395 | prefer 2 apply (simp add: setsum_def) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1396 | apply (erule finite_induct) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1397 | apply (auto simp add: insert_Diff_if) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1398 | apply (drule_tac a = a in mk_disjoint_insert, auto) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1399 | done | 
| 15402 | 1400 | |
| 1401 | lemma setsum_diff1: "finite A \<Longrightarrow> | |
| 1402 |   (setsum f (A - {a}) :: ('a::ab_group_add)) =
 | |
| 1403 | (if a:A then setsum f A - f a else setsum f A)" | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1404 | by (erule finite_induct) (auto simp add: insert_Diff_if) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1405 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1406 | lemma setsum_diff1'[rule_format]: | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1407 |   "finite A \<Longrightarrow> a \<in> A \<longrightarrow> (\<Sum> x \<in> A. f x) = f a + (\<Sum> x \<in> (A - {a}). f x)"
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1408 | apply (erule finite_induct[where F=A and P="% A. (a \<in> A \<longrightarrow> (\<Sum> x \<in> A. f x) = f a + (\<Sum> x \<in> (A - {a}). f x))"])
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1409 | apply (auto simp add: insert_Diff_if add_ac) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1410 | done | 
| 15552 
8ab8e425410b
added setsum_diff1' which holds in more general cases than setsum_diff1
 obua parents: 
15543diff
changeset | 1411 | |
| 31438 | 1412 | lemma setsum_diff1_ring: assumes "finite A" "a \<in> A" | 
| 1413 |   shows "setsum f (A - {a}) = setsum f A - (f a::'a::ring)"
 | |
| 1414 | unfolding setsum_diff1'[OF assms] by auto | |
| 1415 | ||
| 15402 | 1416 | (* By Jeremy Siek: *) | 
| 1417 | ||
| 1418 | lemma setsum_diff_nat: | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1419 | assumes "finite B" and "B \<subseteq> A" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1420 | shows "(setsum f (A - B) :: nat) = (setsum f A) - (setsum f B)" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1421 | using assms | 
| 19535 | 1422 | proof induct | 
| 15402 | 1423 |   show "setsum f (A - {}) = (setsum f A) - (setsum f {})" by simp
 | 
| 1424 | next | |
| 1425 | fix F x assume finF: "finite F" and xnotinF: "x \<notin> F" | |
| 1426 | and xFinA: "insert x F \<subseteq> A" | |
| 1427 | and IH: "F \<subseteq> A \<Longrightarrow> setsum f (A - F) = setsum f A - setsum f F" | |
| 1428 | from xnotinF xFinA have xinAF: "x \<in> (A - F)" by simp | |
| 1429 |   from xinAF have A: "setsum f ((A - F) - {x}) = setsum f (A - F) - f x"
 | |
| 1430 | by (simp add: setsum_diff1_nat) | |
| 1431 | from xFinA have "F \<subseteq> A" by simp | |
| 1432 | with IH have "setsum f (A - F) = setsum f A - setsum f F" by simp | |
| 1433 |   with A have B: "setsum f ((A - F) - {x}) = setsum f A - setsum f F - f x"
 | |
| 1434 | by simp | |
| 1435 |   from xnotinF have "A - insert x F = (A - F) - {x}" by auto
 | |
| 1436 | with B have C: "setsum f (A - insert x F) = setsum f A - setsum f F - f x" | |
| 1437 | by simp | |
| 1438 | from finF xnotinF have "setsum f (insert x F) = setsum f F + f x" by simp | |
| 1439 | with C have "setsum f (A - insert x F) = setsum f A - setsum f (insert x F)" | |
| 1440 | by simp | |
| 1441 | thus "setsum f (A - insert x F) = setsum f A - setsum f (insert x F)" by simp | |
| 1442 | qed | |
| 1443 | ||
| 1444 | lemma setsum_diff: | |
| 1445 | assumes le: "finite A" "B \<subseteq> A" | |
| 1446 |   shows "setsum f (A - B) = setsum f A - ((setsum f B)::('a::ab_group_add))"
 | |
| 1447 | proof - | |
| 1448 | from le have finiteB: "finite B" using finite_subset by auto | |
| 1449 | show ?thesis using finiteB le | |
| 21575 | 1450 | proof induct | 
| 19535 | 1451 | case empty | 
| 1452 | thus ?case by auto | |
| 1453 | next | |
| 1454 | case (insert x F) | |
| 1455 | thus ?case using le finiteB | |
| 1456 | by (simp add: Diff_insert[where a=x and B=F] setsum_diff1 insert_absorb) | |
| 15402 | 1457 | qed | 
| 19535 | 1458 | qed | 
| 15402 | 1459 | |
| 1460 | lemma setsum_mono: | |
| 1461 |   assumes le: "\<And>i. i\<in>K \<Longrightarrow> f (i::'a) \<le> ((g i)::('b::{comm_monoid_add, pordered_ab_semigroup_add}))"
 | |
| 1462 | shows "(\<Sum>i\<in>K. f i) \<le> (\<Sum>i\<in>K. g i)" | |
| 1463 | proof (cases "finite K") | |
| 1464 | case True | |
| 1465 | thus ?thesis using le | |
| 19535 | 1466 | proof induct | 
| 15402 | 1467 | case empty | 
| 1468 | thus ?case by simp | |
| 1469 | next | |
| 1470 | case insert | |
| 19535 | 1471 | thus ?case using add_mono by fastsimp | 
| 15402 | 1472 | qed | 
| 1473 | next | |
| 1474 | case False | |
| 1475 | thus ?thesis | |
| 1476 | by (simp add: setsum_def) | |
| 1477 | qed | |
| 1478 | ||
| 15554 | 1479 | lemma setsum_strict_mono: | 
| 19535 | 1480 |   fixes f :: "'a \<Rightarrow> 'b::{pordered_cancel_ab_semigroup_add,comm_monoid_add}"
 | 
| 1481 |   assumes "finite A"  "A \<noteq> {}"
 | |
| 1482 | and "!!x. x:A \<Longrightarrow> f x < g x" | |
| 1483 | shows "setsum f A < setsum g A" | |
| 1484 | using prems | |
| 15554 | 1485 | proof (induct rule: finite_ne_induct) | 
| 1486 | case singleton thus ?case by simp | |
| 1487 | next | |
| 1488 | case insert thus ?case by (auto simp: add_strict_mono) | |
| 1489 | qed | |
| 1490 | ||
| 15535 | 1491 | lemma setsum_negf: | 
| 19535 | 1492 | "setsum (%x. - (f x)::'a::ab_group_add) A = - setsum f A" | 
| 15535 | 1493 | proof (cases "finite A") | 
| 22262 | 1494 | case True thus ?thesis by (induct set: finite) auto | 
| 15535 | 1495 | next | 
| 1496 | case False thus ?thesis by (simp add: setsum_def) | |
| 1497 | qed | |
| 15402 | 1498 | |
| 15535 | 1499 | lemma setsum_subtractf: | 
| 19535 | 1500 | "setsum (%x. ((f x)::'a::ab_group_add) - g x) A = | 
| 1501 | setsum f A - setsum g A" | |
| 15535 | 1502 | proof (cases "finite A") | 
| 1503 | case True thus ?thesis by (simp add: diff_minus setsum_addf setsum_negf) | |
| 1504 | next | |
| 1505 | case False thus ?thesis by (simp add: setsum_def) | |
| 1506 | qed | |
| 15402 | 1507 | |
| 15535 | 1508 | lemma setsum_nonneg: | 
| 19535 | 1509 |   assumes nn: "\<forall>x\<in>A. (0::'a::{pordered_ab_semigroup_add,comm_monoid_add}) \<le> f x"
 | 
| 1510 | shows "0 \<le> setsum f A" | |
| 15535 | 1511 | proof (cases "finite A") | 
| 1512 | case True thus ?thesis using nn | |
| 21575 | 1513 | proof induct | 
| 19535 | 1514 | case empty then show ?case by simp | 
| 1515 | next | |
| 1516 | case (insert x F) | |
| 1517 | then have "0 + 0 \<le> f x + setsum f F" by (blast intro: add_mono) | |
| 1518 | with insert show ?case by simp | |
| 1519 | qed | |
| 15535 | 1520 | next | 
| 1521 | case False thus ?thesis by (simp add: setsum_def) | |
| 1522 | qed | |
| 15402 | 1523 | |
| 15535 | 1524 | lemma setsum_nonpos: | 
| 19535 | 1525 |   assumes np: "\<forall>x\<in>A. f x \<le> (0::'a::{pordered_ab_semigroup_add,comm_monoid_add})"
 | 
| 1526 | shows "setsum f A \<le> 0" | |
| 15535 | 1527 | proof (cases "finite A") | 
| 1528 | case True thus ?thesis using np | |
| 21575 | 1529 | proof induct | 
| 19535 | 1530 | case empty then show ?case by simp | 
| 1531 | next | |
| 1532 | case (insert x F) | |
| 1533 | then have "f x + setsum f F \<le> 0 + 0" by (blast intro: add_mono) | |
| 1534 | with insert show ?case by simp | |
| 1535 | qed | |
| 15535 | 1536 | next | 
| 1537 | case False thus ?thesis by (simp add: setsum_def) | |
| 1538 | qed | |
| 15402 | 1539 | |
| 15539 | 1540 | lemma setsum_mono2: | 
| 1541 | fixes f :: "'a \<Rightarrow> 'b :: {pordered_ab_semigroup_add_imp_le,comm_monoid_add}"
 | |
| 1542 | assumes fin: "finite B" and sub: "A \<subseteq> B" and nn: "\<And>b. b \<in> B-A \<Longrightarrow> 0 \<le> f b" | |
| 1543 | shows "setsum f A \<le> setsum f B" | |
| 1544 | proof - | |
| 1545 | have "setsum f A \<le> setsum f A + setsum f (B-A)" | |
| 1546 | by(simp add: add_increasing2[OF setsum_nonneg] nn Ball_def) | |
| 1547 | also have "\<dots> = setsum f (A \<union> (B-A))" using fin finite_subset[OF sub fin] | |
| 1548 | by (simp add:setsum_Un_disjoint del:Un_Diff_cancel) | |
| 1549 | also have "A \<union> (B-A) = B" using sub by blast | |
| 1550 | finally show ?thesis . | |
| 1551 | qed | |
| 15542 | 1552 | |
| 16775 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 avigad parents: 
16760diff
changeset | 1553 | lemma setsum_mono3: "finite B ==> A <= B ==> | 
| 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 avigad parents: 
16760diff
changeset | 1554 | ALL x: B - A. | 
| 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 avigad parents: 
16760diff
changeset | 1555 |       0 <= ((f x)::'a::{comm_monoid_add,pordered_ab_semigroup_add}) ==>
 | 
| 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 avigad parents: 
16760diff
changeset | 1556 | setsum f A <= setsum f B" | 
| 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 avigad parents: 
16760diff
changeset | 1557 | apply (subgoal_tac "setsum f B = setsum f A + setsum f (B - A)") | 
| 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 avigad parents: 
16760diff
changeset | 1558 | apply (erule ssubst) | 
| 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 avigad parents: 
16760diff
changeset | 1559 | apply (subgoal_tac "setsum f A + 0 <= setsum f A + setsum f (B - A)") | 
| 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 avigad parents: 
16760diff
changeset | 1560 | apply simp | 
| 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 avigad parents: 
16760diff
changeset | 1561 | apply (rule add_left_mono) | 
| 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 avigad parents: 
16760diff
changeset | 1562 | apply (erule setsum_nonneg) | 
| 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 avigad parents: 
16760diff
changeset | 1563 | apply (subst setsum_Un_disjoint [THEN sym]) | 
| 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 avigad parents: 
16760diff
changeset | 1564 | apply (erule finite_subset, assumption) | 
| 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 avigad parents: 
16760diff
changeset | 1565 | apply (rule finite_subset) | 
| 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 avigad parents: 
16760diff
changeset | 1566 | prefer 2 | 
| 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 avigad parents: 
16760diff
changeset | 1567 | apply assumption | 
| 32698 
be4b248616c0
inf/sup_absorb are no default simp rules any longer
 haftmann parents: 
32697diff
changeset | 1568 | apply (auto simp add: sup_absorb2) | 
| 16775 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 avigad parents: 
16760diff
changeset | 1569 | done | 
| 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 avigad parents: 
16760diff
changeset | 1570 | |
| 19279 | 1571 | lemma setsum_right_distrib: | 
| 22934 
64ecb3d6790a
generalize setsum lemmas from semiring_0_cancel to semiring_0
 huffman parents: 
22917diff
changeset | 1572 |   fixes f :: "'a => ('b::semiring_0)"
 | 
| 15402 | 1573 | shows "r * setsum f A = setsum (%n. r * f n) A" | 
| 1574 | proof (cases "finite A") | |
| 1575 | case True | |
| 1576 | thus ?thesis | |
| 21575 | 1577 | proof induct | 
| 15402 | 1578 | case empty thus ?case by simp | 
| 1579 | next | |
| 1580 | case (insert x A) thus ?case by (simp add: right_distrib) | |
| 1581 | qed | |
| 1582 | next | |
| 1583 | case False thus ?thesis by (simp add: setsum_def) | |
| 1584 | qed | |
| 1585 | ||
| 17149 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1586 | lemma setsum_left_distrib: | 
| 22934 
64ecb3d6790a
generalize setsum lemmas from semiring_0_cancel to semiring_0
 huffman parents: 
22917diff
changeset | 1587 | "setsum f A * (r::'a::semiring_0) = (\<Sum>n\<in>A. f n * r)" | 
| 17149 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1588 | proof (cases "finite A") | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1589 | case True | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1590 | then show ?thesis | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1591 | proof induct | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1592 | case empty thus ?case by simp | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1593 | next | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1594 | case (insert x A) thus ?case by (simp add: left_distrib) | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1595 | qed | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1596 | next | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1597 | case False thus ?thesis by (simp add: setsum_def) | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1598 | qed | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1599 | |
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1600 | lemma setsum_divide_distrib: | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1601 | "setsum f A / (r::'a::field) = (\<Sum>n\<in>A. f n / r)" | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1602 | proof (cases "finite A") | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1603 | case True | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1604 | then show ?thesis | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1605 | proof induct | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1606 | case empty thus ?case by simp | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1607 | next | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1608 | case (insert x A) thus ?case by (simp add: add_divide_distrib) | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1609 | qed | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1610 | next | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1611 | case False thus ?thesis by (simp add: setsum_def) | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1612 | qed | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1613 | |
| 15535 | 1614 | lemma setsum_abs[iff]: | 
| 25303 
0699e20feabd
renamed lordered_*_* to lordered_*_add_*; further localization
 haftmann parents: 
25205diff
changeset | 1615 |   fixes f :: "'a => ('b::pordered_ab_group_add_abs)"
 | 
| 15402 | 1616 | shows "abs (setsum f A) \<le> setsum (%i. abs(f i)) A" | 
| 15535 | 1617 | proof (cases "finite A") | 
| 1618 | case True | |
| 1619 | thus ?thesis | |
| 21575 | 1620 | proof induct | 
| 15535 | 1621 | case empty thus ?case by simp | 
| 1622 | next | |
| 1623 | case (insert x A) | |
| 1624 | thus ?case by (auto intro: abs_triangle_ineq order_trans) | |
| 1625 | qed | |
| 15402 | 1626 | next | 
| 15535 | 1627 | case False thus ?thesis by (simp add: setsum_def) | 
| 15402 | 1628 | qed | 
| 1629 | ||
| 15535 | 1630 | lemma setsum_abs_ge_zero[iff]: | 
| 25303 
0699e20feabd
renamed lordered_*_* to lordered_*_add_*; further localization
 haftmann parents: 
25205diff
changeset | 1631 |   fixes f :: "'a => ('b::pordered_ab_group_add_abs)"
 | 
| 15402 | 1632 | shows "0 \<le> setsum (%i. abs(f i)) A" | 
| 15535 | 1633 | proof (cases "finite A") | 
| 1634 | case True | |
| 1635 | thus ?thesis | |
| 21575 | 1636 | proof induct | 
| 15535 | 1637 | case empty thus ?case by simp | 
| 1638 | next | |
| 21733 | 1639 | case (insert x A) thus ?case by (auto simp: add_nonneg_nonneg) | 
| 15535 | 1640 | qed | 
| 15402 | 1641 | next | 
| 15535 | 1642 | case False thus ?thesis by (simp add: setsum_def) | 
| 15402 | 1643 | qed | 
| 1644 | ||
| 15539 | 1645 | lemma abs_setsum_abs[simp]: | 
| 25303 
0699e20feabd
renamed lordered_*_* to lordered_*_add_*; further localization
 haftmann parents: 
25205diff
changeset | 1646 |   fixes f :: "'a => ('b::pordered_ab_group_add_abs)"
 | 
| 15539 | 1647 | shows "abs (\<Sum>a\<in>A. abs(f a)) = (\<Sum>a\<in>A. abs(f a))" | 
| 1648 | proof (cases "finite A") | |
| 1649 | case True | |
| 1650 | thus ?thesis | |
| 21575 | 1651 | proof induct | 
| 15539 | 1652 | case empty thus ?case by simp | 
| 1653 | next | |
| 1654 | case (insert a A) | |
| 1655 | hence "\<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 | |
| 1656 | also have "\<dots> = \<bar>\<bar>f a\<bar> + \<bar>\<Sum>a\<in>A. \<bar>f a\<bar>\<bar>\<bar>" using insert by simp | |
| 16775 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 avigad parents: 
16760diff
changeset | 1657 | also have "\<dots> = \<bar>f a\<bar> + \<bar>\<Sum>a\<in>A. \<bar>f a\<bar>\<bar>" | 
| 
c1b87ef4a1c3
added lemmas to OrderedGroup.thy (reasoning about signs, absolute value, triangle inequalities)
 avigad parents: 
16760diff
changeset | 1658 | by (simp del: abs_of_nonneg) | 
| 15539 | 1659 | also have "\<dots> = (\<Sum>a\<in>insert a A. \<bar>f a\<bar>)" using insert by simp | 
| 1660 | finally show ?case . | |
| 1661 | qed | |
| 1662 | next | |
| 1663 | case False thus ?thesis by (simp add: setsum_def) | |
| 1664 | qed | |
| 1665 | ||
| 15402 | 1666 | |
| 31080 | 1667 | lemma setsum_Plus: | 
| 1668 | fixes A :: "'a set" and B :: "'b set" | |
| 1669 | assumes fin: "finite A" "finite B" | |
| 1670 | shows "setsum f (A <+> B) = setsum (f \<circ> Inl) A + setsum (f \<circ> Inr) B" | |
| 1671 | proof - | |
| 1672 | have "A <+> B = Inl ` A \<union> Inr ` B" by auto | |
| 1673 |   moreover from fin have "finite (Inl ` A :: ('a + 'b) set)" "finite (Inr ` B :: ('a + 'b) set)"
 | |
| 1674 | by(auto intro: finite_imageI) | |
| 1675 |   moreover have "Inl ` A \<inter> Inr ` B = ({} :: ('a + 'b) set)" by auto
 | |
| 1676 | moreover have "inj_on (Inl :: 'a \<Rightarrow> 'a + 'b) A" "inj_on (Inr :: 'b \<Rightarrow> 'a + 'b) B" by(auto intro: inj_onI) | |
| 1677 | ultimately show ?thesis using fin by(simp add: setsum_Un_disjoint setsum_reindex) | |
| 1678 | qed | |
| 1679 | ||
| 1680 | ||
| 17149 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1681 | text {* Commuting outer and inner summation *}
 | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1682 | |
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1683 | lemma swap_inj_on: | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1684 | "inj_on (%(i, j). (j, i)) (A \<times> B)" | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1685 | by (unfold inj_on_def) fast | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1686 | |
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1687 | lemma swap_product: | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1688 | "(%(i, j). (j, i)) ` (A \<times> B) = B \<times> A" | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1689 | by (simp add: split_def image_def) blast | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1690 | |
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1691 | lemma setsum_commute: | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1692 | "(\<Sum>i\<in>A. \<Sum>j\<in>B. f i j) = (\<Sum>j\<in>B. \<Sum>i\<in>A. f i j)" | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1693 | proof (simp add: setsum_cartesian_product) | 
| 17189 | 1694 | have "(\<Sum>(x,y) \<in> A <*> B. f x y) = | 
| 1695 | (\<Sum>(y,x) \<in> (%(i, j). (j, i)) ` (A \<times> B). f x y)" | |
| 17149 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1696 | (is "?s = _") | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1697 | apply (simp add: setsum_reindex [where f = "%(i, j). (j, i)"] swap_inj_on) | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1698 | apply (simp add: split_def) | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1699 | done | 
| 17189 | 1700 | also have "... = (\<Sum>(y,x)\<in>B \<times> A. f x y)" | 
| 17149 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1701 | (is "_ = ?t") | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1702 | apply (simp add: swap_product) | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1703 | done | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1704 | finally show "?s = ?t" . | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1705 | qed | 
| 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1706 | |
| 19279 | 1707 | lemma setsum_product: | 
| 22934 
64ecb3d6790a
generalize setsum lemmas from semiring_0_cancel to semiring_0
 huffman parents: 
22917diff
changeset | 1708 |   fixes f :: "'a => ('b::semiring_0)"
 | 
| 19279 | 1709 | shows "setsum f A * setsum g B = (\<Sum>i\<in>A. \<Sum>j\<in>B. f i * g j)" | 
| 1710 | by (simp add: setsum_right_distrib setsum_left_distrib) (rule setsum_commute) | |
| 1711 | ||
| 17149 
e2b19c92ef51
Lemmas on dvd, power and finite summation added or strengthened.
 ballarin parents: 
17085diff
changeset | 1712 | |
| 15402 | 1713 | subsection {* Generalized product over a set *}
 | 
| 1714 | ||
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1715 | definition setprod :: "('a => 'b) => 'a set => 'b::comm_monoid_mult"
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1716 | where "setprod f A == if finite A then fold_image (op *) f 1 A else 1" | 
| 15402 | 1717 | |
| 19535 | 1718 | abbreviation | 
| 21404 
eb85850d3eb7
more robust syntax for definition/abbreviation/notation;
 wenzelm parents: 
21249diff
changeset | 1719 |   Setprod  ("\<Prod>_" [1000] 999) where
 | 
| 19535 | 1720 | "\<Prod>A == setprod (%x. x) A" | 
| 1721 | ||
| 15402 | 1722 | syntax | 
| 17189 | 1723 |   "_setprod" :: "pttrn => 'a set => 'b => 'b::comm_monoid_mult"  ("(3PROD _:_. _)" [0, 51, 10] 10)
 | 
| 15402 | 1724 | syntax (xsymbols) | 
| 17189 | 1725 |   "_setprod" :: "pttrn => 'a set => 'b => 'b::comm_monoid_mult"  ("(3\<Prod>_\<in>_. _)" [0, 51, 10] 10)
 | 
| 15402 | 1726 | syntax (HTML output) | 
| 17189 | 1727 |   "_setprod" :: "pttrn => 'a set => 'b => 'b::comm_monoid_mult"  ("(3\<Prod>_\<in>_. _)" [0, 51, 10] 10)
 | 
| 16550 | 1728 | |
| 1729 | translations -- {* Beware of argument permutation! *}
 | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1730 | "PROD i:A. b" == "CONST setprod (%i. b) A" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1731 | "\<Prod>i\<in>A. b" == "CONST setprod (%i. b) A" | 
| 16550 | 1732 | |
| 1733 | text{* Instead of @{term"\<Prod>x\<in>{x. P}. e"} we introduce the shorter
 | |
| 1734 |  @{text"\<Prod>x|P. e"}. *}
 | |
| 1735 | ||
| 1736 | syntax | |
| 17189 | 1737 |   "_qsetprod" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a" ("(3PROD _ |/ _./ _)" [0,0,10] 10)
 | 
| 16550 | 1738 | syntax (xsymbols) | 
| 17189 | 1739 |   "_qsetprod" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a" ("(3\<Prod>_ | (_)./ _)" [0,0,10] 10)
 | 
| 16550 | 1740 | syntax (HTML output) | 
| 17189 | 1741 |   "_qsetprod" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a" ("(3\<Prod>_ | (_)./ _)" [0,0,10] 10)
 | 
| 16550 | 1742 | |
| 15402 | 1743 | translations | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1744 |   "PROD x|P. t" => "CONST setprod (%x. t) {x. P}"
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1745 |   "\<Prod>x|P. t" => "CONST setprod (%x. t) {x. P}"
 | 
| 16550 | 1746 | |
| 15402 | 1747 | |
| 1748 | lemma setprod_empty [simp]: "setprod f {} = 1"
 | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1749 | by (auto simp add: setprod_def) | 
| 15402 | 1750 | |
| 1751 | lemma setprod_insert [simp]: "[| finite A; a \<notin> A |] ==> | |
| 1752 | setprod f (insert a A) = f a * setprod f A" | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1753 | by (simp add: setprod_def) | 
| 15402 | 1754 | |
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1755 | lemma setprod_infinite [simp]: "~ finite A ==> setprod f A = 1" | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1756 | by (simp add: setprod_def) | 
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1757 | |
| 15402 | 1758 | lemma setprod_reindex: | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1759 | "inj_on f B ==> setprod h (f ` B) = setprod (h \<circ> f) B" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1760 | by(auto simp: setprod_def fold_image_reindex dest!:finite_imageD) | 
| 15402 | 1761 | |
| 1762 | lemma setprod_reindex_id: "inj_on f B ==> setprod f B = setprod id (f ` B)" | |
| 1763 | by (auto simp add: setprod_reindex) | |
| 1764 | ||
| 1765 | lemma setprod_cong: | |
| 1766 | "A = B ==> (!!x. x:B ==> f x = g x) ==> setprod f A = setprod g B" | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1767 | by(fastsimp simp: setprod_def intro: fold_image_cong) | 
| 15402 | 1768 | |
| 30837 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 nipkow parents: 
30729diff
changeset | 1769 | lemma strong_setprod_cong[cong]: | 
| 16632 
ad2895beef79
Added strong_setsum_cong and strong_setprod_cong.
 berghofe parents: 
16550diff
changeset | 1770 | "A = B ==> (!!x. x:B =simp=> f x = g x) ==> setprod f A = setprod g B" | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1771 | by(fastsimp simp: simp_implies_def setprod_def intro: fold_image_cong) | 
| 16632 
ad2895beef79
Added strong_setsum_cong and strong_setprod_cong.
 berghofe parents: 
16550diff
changeset | 1772 | |
| 15402 | 1773 | lemma setprod_reindex_cong: "inj_on f A ==> | 
| 1774 | B = f ` A ==> g = h \<circ> f ==> setprod h B = setprod g A" | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1775 | by (frule setprod_reindex, simp) | 
| 15402 | 1776 | |
| 29674 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1777 | lemma strong_setprod_reindex_cong: assumes i: "inj_on f A" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1778 | and B: "B = f ` A" and eq: "\<And>x. x \<in> A \<Longrightarrow> g x = (h \<circ> f) x" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1779 | shows "setprod h B = setprod g A" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1780 | proof- | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1781 | have "setprod h B = setprod (h o f) A" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1782 | by (simp add: B setprod_reindex[OF i, of h]) | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1783 | then show ?thesis apply simp | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1784 | apply (rule setprod_cong) | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1785 | apply simp | 
| 30837 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 nipkow parents: 
30729diff
changeset | 1786 | by (simp add: eq) | 
| 29674 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1787 | qed | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1788 | |
| 30260 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1789 | lemma setprod_Un_one: | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1790 | assumes fS: "finite S" and fT: "finite T" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1791 | and I0: "\<forall>x \<in> S\<inter>T. f x = 1" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1792 | shows "setprod f (S \<union> T) = setprod f S * setprod f T" | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1793 | using fS fT | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1794 | apply (simp add: setprod_def) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1795 | apply (rule fold_image_Un_one) | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1796 | using I0 by auto | 
| 
be39acd3ac85
Added general theorems for fold_image, setsum and set_prod
 chaieb parents: 
29966diff
changeset | 1797 | |
| 15402 | 1798 | |
| 1799 | lemma setprod_1: "setprod (%i. 1) A = 1" | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1800 | apply (case_tac "finite A") | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1801 | apply (erule finite_induct, auto simp add: mult_ac) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1802 | done | 
| 15402 | 1803 | |
| 1804 | lemma setprod_1': "ALL a:F. f a = 1 ==> setprod f F = 1" | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1805 | apply (subgoal_tac "setprod f F = setprod (%x. 1) F") | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1806 | apply (erule ssubst, rule setprod_1) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1807 | apply (rule setprod_cong, auto) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1808 | done | 
| 15402 | 1809 | |
| 1810 | lemma setprod_Un_Int: "finite A ==> finite B | |
| 1811 | ==> setprod g (A Un B) * setprod g (A Int B) = setprod g A * setprod g B" | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1812 | by(simp add: setprod_def fold_image_Un_Int[symmetric]) | 
| 15402 | 1813 | |
| 1814 | lemma setprod_Un_disjoint: "finite A ==> finite B | |
| 1815 |   ==> A Int B = {} ==> setprod g (A Un B) = setprod g A * setprod g B"
 | |
| 1816 | by (subst setprod_Un_Int [symmetric], auto) | |
| 1817 | ||
| 30837 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 nipkow parents: 
30729diff
changeset | 1818 | lemma setprod_mono_one_left: | 
| 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 nipkow parents: 
30729diff
changeset | 1819 | assumes fT: "finite T" and ST: "S \<subseteq> T" | 
| 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 nipkow parents: 
30729diff
changeset | 1820 | and z: "\<forall>i \<in> T - S. f i = 1" | 
| 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 nipkow parents: 
30729diff
changeset | 1821 | shows "setprod f S = setprod f T" | 
| 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 nipkow parents: 
30729diff
changeset | 1822 | proof- | 
| 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 nipkow parents: 
30729diff
changeset | 1823 | have eq: "T = S \<union> (T - S)" using ST by blast | 
| 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 nipkow parents: 
30729diff
changeset | 1824 |   have d: "S \<inter> (T - S) = {}" using ST by blast
 | 
| 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 nipkow parents: 
30729diff
changeset | 1825 | from fT ST have f: "finite S" "finite (T - S)" by (auto intro: finite_subset) | 
| 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 nipkow parents: 
30729diff
changeset | 1826 | show ?thesis | 
| 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 nipkow parents: 
30729diff
changeset | 1827 | by (simp add: setprod_Un_disjoint[OF f d, unfolded eq[symmetric]] setprod_1'[OF z]) | 
| 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 nipkow parents: 
30729diff
changeset | 1828 | qed | 
| 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 nipkow parents: 
30729diff
changeset | 1829 | |
| 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 nipkow parents: 
30729diff
changeset | 1830 | lemmas setprod_mono_one_right = setprod_mono_one_left [THEN sym] | 
| 
3d4832d9f7e4
added strong_setprod_cong[cong] (in analogy with setsum)
 nipkow parents: 
30729diff
changeset | 1831 | |
| 29674 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1832 | lemma setprod_delta: | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1833 | assumes fS: "finite S" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1834 | shows "setprod (\<lambda>k. if k=a then b k else 1) S = (if a \<in> S then b a else 1)" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1835 | proof- | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1836 | let ?f = "(\<lambda>k. if k=a then b k else 1)" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1837 |   {assume a: "a \<notin> S"
 | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1838 | hence "\<forall> k\<in> S. ?f k = 1" by simp | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1839 | hence ?thesis using a by (simp add: setprod_1 cong add: setprod_cong) } | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1840 | moreover | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1841 |   {assume a: "a \<in> S"
 | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1842 |     let ?A = "S - {a}"
 | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1843 |     let ?B = "{a}"
 | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1844 | have eq: "S = ?A \<union> ?B" using a by blast | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1845 |     have dj: "?A \<inter> ?B = {}" by simp
 | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1846 | from fS have fAB: "finite ?A" "finite ?B" by auto | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1847 | have fA1: "setprod ?f ?A = 1" apply (rule setprod_1') by auto | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1848 | have "setprod ?f ?A * setprod ?f ?B = setprod ?f S" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1849 | using setprod_Un_disjoint[OF fAB dj, of ?f, unfolded eq[symmetric]] | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1850 | by simp | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1851 | then have ?thesis using a by (simp add: fA1 cong add: setprod_cong cong del: if_weak_cong)} | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1852 | ultimately show ?thesis by blast | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1853 | qed | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1854 | |
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1855 | lemma setprod_delta': | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1856 | assumes fS: "finite S" shows | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1857 | "setprod (\<lambda>k. if a = k then b k else 1) S = | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1858 | (if a\<in> S then b a else 1)" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1859 | using setprod_delta[OF fS, of a b, symmetric] | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1860 | by (auto intro: setprod_cong) | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1861 | |
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 1862 | |
| 15402 | 1863 | lemma setprod_UN_disjoint: | 
| 1864 | "finite I ==> (ALL i:I. finite (A i)) ==> | |
| 1865 |         (ALL i:I. ALL j:I. i \<noteq> j --> A i Int A j = {}) ==>
 | |
| 1866 | setprod f (UNION I A) = setprod (%i. setprod f (A i)) I" | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1867 | by(simp add: setprod_def fold_image_UN_disjoint cong: setprod_cong) | 
| 15402 | 1868 | |
| 1869 | lemma setprod_Union_disjoint: | |
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1870 | "[| (ALL A:C. finite A); | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1871 |       (ALL A:C. ALL B:C. A \<noteq> B --> A Int B = {}) |] 
 | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1872 | ==> setprod f (Union C) = setprod (setprod f) C" | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1873 | apply (cases "finite C") | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1874 | prefer 2 apply (force dest: finite_UnionD simp add: setprod_def) | 
| 15402 | 1875 | apply (frule setprod_UN_disjoint [of C id f]) | 
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1876 | apply (unfold Union_def id_def, assumption+) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1877 | done | 
| 15402 | 1878 | |
| 1879 | lemma setprod_Sigma: "finite A ==> ALL x:A. finite (B x) ==> | |
| 16550 | 1880 | (\<Prod>x\<in>A. (\<Prod>y\<in> B x. f x y)) = | 
| 17189 | 1881 | (\<Prod>(x,y)\<in>(SIGMA x:A. B x). f x y)" | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1882 | by(simp add:setprod_def fold_image_Sigma split_def cong:setprod_cong) | 
| 15402 | 1883 | |
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1884 | text{*Here we can eliminate the finiteness assumptions, by cases.*}
 | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1885 | lemma setprod_cartesian_product: | 
| 17189 | 1886 | "(\<Prod>x\<in>A. (\<Prod>y\<in> B. f x y)) = (\<Prod>(x,y)\<in>(A <*> B). f x y)" | 
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1887 | apply (cases "finite A") | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1888 | apply (cases "finite B") | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1889 | apply (simp add: setprod_Sigma) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1890 |  apply (cases "A={}", simp)
 | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1891 | apply (simp add: setprod_1) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1892 | apply (auto simp add: setprod_def | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1893 | dest: finite_cartesian_productD1 finite_cartesian_productD2) | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1894 | done | 
| 15402 | 1895 | |
| 1896 | lemma setprod_timesf: | |
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 1897 | "setprod (%x. f x * g x) A = (setprod f A * setprod g A)" | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1898 | by(simp add:setprod_def fold_image_distrib) | 
| 15402 | 1899 | |
| 1900 | ||
| 1901 | subsubsection {* Properties in more restricted classes of structures *}
 | |
| 1902 | ||
| 1903 | lemma setprod_eq_1_iff [simp]: | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1904 | "finite F ==> (setprod f F = 1) = (ALL a:F. f a = (1::nat))" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1905 | by (induct set: finite) auto | 
| 15402 | 1906 | |
| 1907 | lemma setprod_zero: | |
| 23277 | 1908 | "finite A ==> EX x: A. f x = (0::'a::comm_semiring_1) ==> setprod f A = 0" | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1909 | apply (induct set: finite, force, clarsimp) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1910 | apply (erule disjE, auto) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1911 | done | 
| 15402 | 1912 | |
| 1913 | lemma setprod_nonneg [rule_format]: | |
| 30841 
0813afc97522
generalized setprod_nonneg and setprod_pos to ordered_semidom, simplified proofs
 huffman parents: 
30729diff
changeset | 1914 | "(ALL x: A. (0::'a::ordered_semidom) \<le> f x) --> 0 \<le> setprod f A" | 
| 
0813afc97522
generalized setprod_nonneg and setprod_pos to ordered_semidom, simplified proofs
 huffman parents: 
30729diff
changeset | 1915 | by (cases "finite A", induct set: finite, simp_all add: mult_nonneg_nonneg) | 
| 
0813afc97522
generalized setprod_nonneg and setprod_pos to ordered_semidom, simplified proofs
 huffman parents: 
30729diff
changeset | 1916 | |
| 
0813afc97522
generalized setprod_nonneg and setprod_pos to ordered_semidom, simplified proofs
 huffman parents: 
30729diff
changeset | 1917 | lemma setprod_pos [rule_format]: "(ALL x: A. (0::'a::ordered_semidom) < f x) | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1918 | --> 0 < setprod f A" | 
| 30841 
0813afc97522
generalized setprod_nonneg and setprod_pos to ordered_semidom, simplified proofs
 huffman parents: 
30729diff
changeset | 1919 | by (cases "finite A", induct set: finite, simp_all add: mult_pos_pos) | 
| 15402 | 1920 | |
| 30843 | 1921 | lemma setprod_zero_iff[simp]: "finite A ==> | 
| 1922 |   (setprod f A = (0::'a::{comm_semiring_1,no_zero_divisors})) =
 | |
| 1923 | (EX x: A. f x = 0)" | |
| 1924 | by (erule finite_induct, auto simp:no_zero_divisors) | |
| 1925 | ||
| 1926 | lemma setprod_pos_nat: | |
| 1927 | "finite S ==> (ALL x : S. f x > (0::nat)) ==> setprod f S > 0" | |
| 1928 | using setprod_zero_iff by(simp del:neq0_conv add:neq0_conv[symmetric]) | |
| 15402 | 1929 | |
| 30863 | 1930 | lemma setprod_pos_nat_iff[simp]: | 
| 1931 | "finite S ==> (setprod f S > 0) = (ALL x : S. f x > (0::nat))" | |
| 1932 | using setprod_zero_iff by(simp del:neq0_conv add:neq0_conv[symmetric]) | |
| 1933 | ||
| 15402 | 1934 | lemma setprod_Un: "finite A ==> finite B ==> (ALL x: A Int B. f x \<noteq> 0) ==> | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1935 |   (setprod f (A Un B) :: 'a ::{field})
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1936 | = setprod f A * setprod f B / setprod f (A Int B)" | 
| 30843 | 1937 | by (subst setprod_Un_Int [symmetric], auto) | 
| 15402 | 1938 | |
| 1939 | lemma setprod_diff1: "finite A ==> f a \<noteq> 0 ==> | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1940 |   (setprod f (A - {a}) :: 'a :: {field}) =
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1941 | (if a:A then setprod f A / f a else setprod f A)" | 
| 23413 
5caa2710dd5b
tuned laws for cancellation in divisions for fields.
 nipkow parents: 
23398diff
changeset | 1942 | by (erule finite_induct) (auto simp add: insert_Diff_if) | 
| 15402 | 1943 | |
| 31906 
b41d61c768e2
Removed unnecessary conditions concerning nonzero divisors
 paulson parents: 
31465diff
changeset | 1944 | lemma setprod_inversef: | 
| 
b41d61c768e2
Removed unnecessary conditions concerning nonzero divisors
 paulson parents: 
31465diff
changeset | 1945 |   fixes f :: "'b \<Rightarrow> 'a::{field,division_by_zero}"
 | 
| 
b41d61c768e2
Removed unnecessary conditions concerning nonzero divisors
 paulson parents: 
31465diff
changeset | 1946 | shows "finite A ==> setprod (inverse \<circ> f) A = inverse (setprod f A)" | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1947 | by (erule finite_induct) auto | 
| 15402 | 1948 | |
| 1949 | lemma setprod_dividef: | |
| 31906 
b41d61c768e2
Removed unnecessary conditions concerning nonzero divisors
 paulson parents: 
31465diff
changeset | 1950 |   fixes f :: "'b \<Rightarrow> 'a::{field,division_by_zero}"
 | 
| 31916 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 1951 | shows "finite A | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1952 | ==> setprod (%x. f x / g x) A = setprod f A / setprod g A" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1953 | apply (subgoal_tac | 
| 15402 | 1954 | "setprod (%x. f x / g x) A = setprod (%x. f x * (inverse \<circ> g) x) A") | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1955 | apply (erule ssubst) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1956 | apply (subst divide_inverse) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1957 | apply (subst setprod_timesf) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1958 | apply (subst setprod_inversef, assumption+, rule refl) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1959 | apply (rule setprod_cong, rule refl) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1960 | apply (subst divide_inverse, auto) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1961 | done | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 1962 | |
| 29925 | 1963 | lemma setprod_dvd_setprod [rule_format]: | 
| 1964 | "(ALL x : A. f x dvd g x) \<longrightarrow> setprod f A dvd setprod g A" | |
| 1965 | apply (cases "finite A") | |
| 1966 | apply (induct set: finite) | |
| 1967 | apply (auto simp add: dvd_def) | |
| 1968 | apply (rule_tac x = "k * ka" in exI) | |
| 1969 | apply (simp add: algebra_simps) | |
| 1970 | done | |
| 1971 | ||
| 1972 | lemma setprod_dvd_setprod_subset: | |
| 1973 | "finite B \<Longrightarrow> A <= B \<Longrightarrow> setprod f A dvd setprod f B" | |
| 1974 | apply (subgoal_tac "setprod f B = setprod f A * setprod f (B - A)") | |
| 1975 | apply (unfold dvd_def, blast) | |
| 1976 | apply (subst setprod_Un_disjoint [symmetric]) | |
| 1977 | apply (auto elim: finite_subset intro: setprod_cong) | |
| 1978 | done | |
| 1979 | ||
| 1980 | lemma setprod_dvd_setprod_subset2: | |
| 1981 | "finite B \<Longrightarrow> A <= B \<Longrightarrow> ALL x : A. (f x::'a::comm_semiring_1) dvd g x \<Longrightarrow> | |
| 1982 | setprod f A dvd setprod g B" | |
| 1983 | apply (rule dvd_trans) | |
| 1984 | apply (rule setprod_dvd_setprod, erule (1) bspec) | |
| 1985 | apply (erule (1) setprod_dvd_setprod_subset) | |
| 1986 | done | |
| 1987 | ||
| 1988 | lemma dvd_setprod: "finite A \<Longrightarrow> i:A \<Longrightarrow> | |
| 1989 | (f i ::'a::comm_semiring_1) dvd setprod f A" | |
| 1990 | by (induct set: finite) (auto intro: dvd_mult) | |
| 1991 | ||
| 1992 | lemma dvd_setsum [rule_format]: "(ALL i : A. d dvd f i) \<longrightarrow> | |
| 1993 | (d::'a::comm_semiring_1) dvd (SUM x : A. f x)" | |
| 1994 | apply (cases "finite A") | |
| 1995 | apply (induct set: finite) | |
| 1996 | apply auto | |
| 1997 | done | |
| 1998 | ||
| 15402 | 1999 | |
| 12396 | 2000 | subsection {* Finite cardinality *}
 | 
| 2001 | ||
| 15402 | 2002 | text {* This definition, although traditional, is ugly to work with:
 | 
| 2003 | @{text "card A == LEAST n. EX f. A = {f i | i. i < n}"}.
 | |
| 2004 | But now that we have @{text setsum} things are easy:
 | |
| 12396 | 2005 | *} | 
| 2006 | ||
| 31380 | 2007 | definition card :: "'a set \<Rightarrow> nat" where | 
| 2008 | "card A = setsum (\<lambda>x. 1) A" | |
| 2009 | ||
| 2010 | lemmas card_eq_setsum = card_def | |
| 12396 | 2011 | |
| 2012 | lemma card_empty [simp]: "card {} = 0"
 | |
| 31380 | 2013 | by (simp add: card_def) | 
| 12396 | 2014 | |
| 2015 | lemma card_insert_disjoint [simp]: | |
| 2016 | "finite A ==> x \<notin> A ==> card (insert x A) = Suc(card A)" | |
| 31380 | 2017 | by (simp add: card_def) | 
| 15402 | 2018 | |
| 2019 | lemma card_insert_if: | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2020 | "finite A ==> card (insert x A) = (if x:A then card A else Suc(card(A)))" | 
| 31380 | 2021 | by (simp add: insert_absorb) | 
| 2022 | ||
| 2023 | lemma card_infinite [simp]: "~ finite A ==> card A = 0" | |
| 2024 | by (simp add: card_def) | |
| 2025 | ||
| 2026 | lemma card_ge_0_finite: | |
| 2027 | "card A > 0 \<Longrightarrow> finite A" | |
| 2028 | by (rule ccontr) simp | |
| 12396 | 2029 | |
| 24286 
7619080e49f0
ATP blacklisting is now in theory data, attribute noatp
 paulson parents: 
24268diff
changeset | 2030 | lemma card_0_eq [simp,noatp]: "finite A ==> (card A = 0) = (A = {})"
 | 
| 31380 | 2031 | apply auto | 
| 2032 | apply (drule_tac a = x in mk_disjoint_insert, clarify, auto) | |
| 2033 | done | |
| 2034 | ||
| 2035 | lemma finite_UNIV_card_ge_0: | |
| 2036 | "finite (UNIV :: 'a set) \<Longrightarrow> card (UNIV :: 'a set) > 0" | |
| 2037 | by (rule ccontr) simp | |
| 12396 | 2038 | |
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 2039 | lemma card_eq_0_iff: "(card A = 0) = (A = {} | ~ finite A)"
 | 
| 31380 | 2040 | by auto | 
| 24853 | 2041 | |
| 12396 | 2042 | lemma card_Suc_Diff1: "finite A ==> x: A ==> Suc (card (A - {x})) = card A"
 | 
| 14302 | 2043 | apply(rule_tac t = A in insert_Diff [THEN subst], assumption) | 
| 2044 | apply(simp del:insert_Diff_single) | |
| 2045 | done | |
| 12396 | 2046 | |
| 2047 | lemma card_Diff_singleton: | |
| 24853 | 2048 |   "finite A ==> x: A ==> card (A - {x}) = card A - 1"
 | 
| 2049 | by (simp add: card_Suc_Diff1 [symmetric]) | |
| 12396 | 2050 | |
| 2051 | lemma card_Diff_singleton_if: | |
| 24853 | 2052 |   "finite A ==> card (A-{x}) = (if x : A then card A - 1 else card A)"
 | 
| 2053 | by (simp add: card_Diff_singleton) | |
| 2054 | ||
| 2055 | lemma card_Diff_insert[simp]: | |
| 2056 | assumes "finite A" and "a:A" and "a ~: B" | |
| 2057 | shows "card(A - insert a B) = card(A - B) - 1" | |
| 2058 | proof - | |
| 2059 |   have "A - insert a B = (A - B) - {a}" using assms by blast
 | |
| 2060 | then show ?thesis using assms by(simp add:card_Diff_singleton) | |
| 2061 | qed | |
| 12396 | 2062 | |
| 2063 | lemma card_insert: "finite A ==> card (insert x A) = Suc (card (A - {x}))"
 | |
| 24853 | 2064 | by (simp add: card_insert_if card_Suc_Diff1 del:card_Diff_insert) | 
| 12396 | 2065 | |
| 2066 | lemma card_insert_le: "finite A ==> card A <= card (insert x A)" | |
| 24853 | 2067 | by (simp add: card_insert_if) | 
| 12396 | 2068 | |
| 15402 | 2069 | lemma card_mono: "\<lbrakk> finite B; A \<subseteq> B \<rbrakk> \<Longrightarrow> card A \<le> card B" | 
| 15539 | 2070 | by (simp add: card_def setsum_mono2) | 
| 15402 | 2071 | |
| 12396 | 2072 | lemma card_seteq: "finite B ==> (!!A. A <= B ==> card B <= card A ==> A = B)" | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2073 | apply (induct set: finite, simp, clarify) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2074 | apply (subgoal_tac "finite A & A - {x} <= F")
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2075 | prefer 2 apply (blast intro: finite_subset, atomize) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2076 | apply (drule_tac x = "A - {x}" in spec)
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2077 | apply (simp add: card_Diff_singleton_if split add: split_if_asm) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2078 | apply (case_tac "card A", auto) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2079 | done | 
| 12396 | 2080 | |
| 2081 | lemma psubset_card_mono: "finite B ==> A < B ==> card A < card B" | |
| 26792 | 2082 | apply (simp add: psubset_eq linorder_not_le [symmetric]) | 
| 24853 | 2083 | apply (blast dest: card_seteq) | 
| 2084 | done | |
| 12396 | 2085 | |
| 2086 | lemma card_Un_Int: "finite A ==> finite B | |
| 2087 | ==> card A + card B = card (A Un B) + card (A Int B)" | |
| 15402 | 2088 | by(simp add:card_def setsum_Un_Int) | 
| 12396 | 2089 | |
| 2090 | lemma card_Un_disjoint: "finite A ==> finite B | |
| 2091 |     ==> A Int B = {} ==> card (A Un B) = card A + card B"
 | |
| 24853 | 2092 | by (simp add: card_Un_Int) | 
| 12396 | 2093 | |
| 2094 | lemma card_Diff_subset: | |
| 15402 | 2095 | "finite B ==> B <= A ==> card (A - B) = card A - card B" | 
| 2096 | by(simp add:card_def setsum_diff_nat) | |
| 12396 | 2097 | |
| 2098 | lemma card_Diff1_less: "finite A ==> x: A ==> card (A - {x}) < card A"
 | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2099 | apply (rule Suc_less_SucD) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2100 | apply (simp add: card_Suc_Diff1 del:card_Diff_insert) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2101 | done | 
| 12396 | 2102 | |
| 2103 | lemma card_Diff2_less: | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2104 |   "finite A ==> x: A ==> y: A ==> card (A - {x} - {y}) < card A"
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2105 | apply (case_tac "x = y") | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2106 | apply (simp add: card_Diff1_less del:card_Diff_insert) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2107 | apply (rule less_trans) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2108 | prefer 2 apply (auto intro!: card_Diff1_less simp del:card_Diff_insert) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2109 | done | 
| 12396 | 2110 | |
| 2111 | lemma card_Diff1_le: "finite A ==> card (A - {x}) <= card A"
 | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2112 | apply (case_tac "x : A") | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2113 | apply (simp_all add: card_Diff1_less less_imp_le) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2114 | done | 
| 12396 | 2115 | |
| 2116 | lemma card_psubset: "finite B ==> A \<subseteq> B ==> card A < card B ==> A < B" | |
| 14208 | 2117 | by (erule psubsetI, blast) | 
| 12396 | 2118 | |
| 14889 | 2119 | lemma insert_partition: | 
| 15402 | 2120 |   "\<lbrakk> x \<notin> F; \<forall>c1 \<in> insert x F. \<forall>c2 \<in> insert x F. c1 \<noteq> c2 \<longrightarrow> c1 \<inter> c2 = {} \<rbrakk>
 | 
| 2121 |   \<Longrightarrow> x \<inter> \<Union> F = {}"
 | |
| 14889 | 2122 | by auto | 
| 2123 | ||
| 32006 | 2124 | lemma finite_psubset_induct[consumes 1, case_names psubset]: | 
| 2125 | assumes "finite A" and "!!A. finite A \<Longrightarrow> (!!B. finite B \<Longrightarrow> B \<subset> A \<Longrightarrow> P(B)) \<Longrightarrow> P(A)" shows "P A" | |
| 2126 | using assms(1) | |
| 2127 | proof (induct A rule: measure_induct_rule[where f=card]) | |
| 2128 | case (less A) | |
| 2129 | show ?case | |
| 2130 | proof(rule assms(2)[OF less(2)]) | |
| 2131 | fix B assume "finite B" "B \<subset> A" | |
| 2132 | show "P B" by(rule less(1)[OF psubset_card_mono[OF less(2) `B \<subset> A`] `finite B`]) | |
| 2133 | qed | |
| 2134 | qed | |
| 2135 | ||
| 19793 | 2136 | text{* main cardinality theorem *}
 | 
| 14889 | 2137 | lemma card_partition [rule_format]: | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2138 | "finite C ==> | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2139 | finite (\<Union> C) --> | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2140 | (\<forall>c\<in>C. card c = k) --> | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2141 |      (\<forall>c1 \<in> C. \<forall>c2 \<in> C. c1 \<noteq> c2 --> c1 \<inter> c2 = {}) -->
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2142 | k * card(C) = card (\<Union> C)" | 
| 14889 | 2143 | apply (erule finite_induct, simp) | 
| 2144 | apply (simp add: card_insert_disjoint card_Un_disjoint insert_partition | |
| 2145 | finite_subset [of _ "\<Union> (insert x F)"]) | |
| 2146 | done | |
| 2147 | ||
| 31380 | 2148 | lemma card_eq_UNIV_imp_eq_UNIV: | 
| 2149 | assumes fin: "finite (UNIV :: 'a set)" | |
| 2150 | and card: "card A = card (UNIV :: 'a set)" | |
| 2151 | shows "A = (UNIV :: 'a set)" | |
| 2152 | proof | |
| 2153 | show "A \<subseteq> UNIV" by simp | |
| 2154 | show "UNIV \<subseteq> A" | |
| 2155 | proof | |
| 2156 | fix x | |
| 2157 | show "x \<in> A" | |
| 2158 | proof (rule ccontr) | |
| 2159 | assume "x \<notin> A" | |
| 2160 | then have "A \<subset> UNIV" by auto | |
| 2161 | with fin have "card A < card (UNIV :: 'a set)" by (fact psubset_card_mono) | |
| 2162 | with card show False by simp | |
| 2163 | qed | |
| 2164 | qed | |
| 2165 | qed | |
| 12396 | 2166 | |
| 19793 | 2167 | text{*The form of a finite set of given cardinality*}
 | 
| 2168 | ||
| 2169 | lemma card_eq_SucD: | |
| 24853 | 2170 | assumes "card A = Suc k" | 
| 2171 | shows "\<exists>b B. A = insert b B & b \<notin> B & card B = k & (k=0 \<longrightarrow> B={})"
 | |
| 19793 | 2172 | proof - | 
| 24853 | 2173 | have fin: "finite A" using assms by (auto intro: ccontr) | 
| 2174 | moreover have "card A \<noteq> 0" using assms by auto | |
| 2175 | ultimately obtain b where b: "b \<in> A" by auto | |
| 19793 | 2176 | show ?thesis | 
| 2177 | proof (intro exI conjI) | |
| 2178 |     show "A = insert b (A-{b})" using b by blast
 | |
| 2179 |     show "b \<notin> A - {b}" by blast
 | |
| 24853 | 2180 |     show "card (A - {b}) = k" and "k = 0 \<longrightarrow> A - {b} = {}"
 | 
| 2181 | using assms b fin by(fastsimp dest:mk_disjoint_insert)+ | |
| 19793 | 2182 | qed | 
| 2183 | qed | |
| 2184 | ||
| 2185 | lemma card_Suc_eq: | |
| 24853 | 2186 | "(card A = Suc k) = | 
| 2187 |    (\<exists>b B. A = insert b B & b \<notin> B & card B = k & (k=0 \<longrightarrow> B={}))"
 | |
| 2188 | apply(rule iffI) | |
| 2189 | apply(erule card_eq_SucD) | |
| 2190 | apply(auto) | |
| 2191 | apply(subst card_insert) | |
| 2192 | apply(auto intro:ccontr) | |
| 2193 | done | |
| 19793 | 2194 | |
| 31380 | 2195 | lemma finite_fun_UNIVD2: | 
| 2196 |   assumes fin: "finite (UNIV :: ('a \<Rightarrow> 'b) set)"
 | |
| 2197 | shows "finite (UNIV :: 'b set)" | |
| 2198 | proof - | |
| 2199 | from fin have "finite (range (\<lambda>f :: 'a \<Rightarrow> 'b. f arbitrary))" | |
| 2200 | by(rule finite_imageI) | |
| 2201 | moreover have "UNIV = range (\<lambda>f :: 'a \<Rightarrow> 'b. f arbitrary)" | |
| 2202 | by(rule UNIV_eq_I) auto | |
| 2203 | ultimately show "finite (UNIV :: 'b set)" by simp | |
| 2204 | qed | |
| 2205 | ||
| 15539 | 2206 | lemma setsum_constant [simp]: "(\<Sum>x \<in> A. y) = of_nat(card A) * y" | 
| 2207 | apply (cases "finite A") | |
| 2208 | apply (erule finite_induct) | |
| 29667 | 2209 | apply (auto simp add: algebra_simps) | 
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 2210 | done | 
| 15402 | 2211 | |
| 31017 | 2212 | lemma setprod_constant: "finite A ==> (\<Prod>x\<in> A. (y::'a::{comm_monoid_mult})) = y^(card A)"
 | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2213 | apply (erule finite_induct) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2214 | apply (auto simp add: power_Suc) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2215 | done | 
| 15402 | 2216 | |
| 29674 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2217 | lemma setprod_gen_delta: | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2218 | assumes fS: "finite S" | 
| 31017 | 2219 |   shows "setprod (\<lambda>k. if k=a then b k else c) S = (if a \<in> S then (b a ::'a::{comm_monoid_mult}) * c^ (card S - 1) else c^ card S)"
 | 
| 29674 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2220 | proof- | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2221 | let ?f = "(\<lambda>k. if k=a then b k else c)" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2222 |   {assume a: "a \<notin> S"
 | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2223 | hence "\<forall> k\<in> S. ?f k = c" by simp | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2224 | hence ?thesis using a setprod_constant[OF fS, of c] by (simp add: setprod_1 cong add: setprod_cong) } | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2225 | moreover | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2226 |   {assume a: "a \<in> S"
 | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2227 |     let ?A = "S - {a}"
 | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2228 |     let ?B = "{a}"
 | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2229 | have eq: "S = ?A \<union> ?B" using a by blast | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2230 |     have dj: "?A \<inter> ?B = {}" by simp
 | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2231 | from fS have fAB: "finite ?A" "finite ?B" by auto | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2232 | have fA0:"setprod ?f ?A = setprod (\<lambda>i. c) ?A" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2233 | apply (rule setprod_cong) by auto | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2234 | have cA: "card ?A = card S - 1" using fS a by auto | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2235 | have fA1: "setprod ?f ?A = c ^ card ?A" unfolding fA0 apply (rule setprod_constant) using fS by auto | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2236 | have "setprod ?f ?A * setprod ?f ?B = setprod ?f S" | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2237 | using setprod_Un_disjoint[OF fAB dj, of ?f, unfolded eq[symmetric]] | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2238 | by simp | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2239 | then have ?thesis using a cA | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2240 | by (simp add: fA1 ring_simps cong add: setprod_cong cong del: if_weak_cong)} | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2241 | ultimately show ?thesis by blast | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2242 | qed | 
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2243 | |
| 
3857d7eba390
Added theorems setsum_reindex_nonzero, setsum_mono_zero_left, setsum_mono_zero_right, setsum_mono_zero_cong_left, setsum_mono_zero_cong_right, setsum_delta, strong_setprod_reindex_cong, setprod_delta
 chaieb parents: 
29609diff
changeset | 2244 | |
| 15542 | 2245 | lemma setsum_bounded: | 
| 23277 | 2246 |   assumes le: "\<And>i. i\<in>A \<Longrightarrow> f i \<le> (K::'a::{semiring_1, pordered_ab_semigroup_add})"
 | 
| 15542 | 2247 | shows "setsum f A \<le> of_nat(card A) * K" | 
| 2248 | proof (cases "finite A") | |
| 2249 | case True | |
| 2250 | thus ?thesis using le setsum_mono[where K=A and g = "%x. K"] by simp | |
| 2251 | next | |
| 2252 | case False thus ?thesis by (simp add: setsum_def) | |
| 2253 | qed | |
| 2254 | ||
| 15402 | 2255 | |
| 31080 | 2256 | lemma card_UNIV_unit: "card (UNIV :: unit set) = 1" | 
| 2257 | unfolding UNIV_unit by simp | |
| 2258 | ||
| 2259 | ||
| 15402 | 2260 | subsubsection {* Cardinality of unions *}
 | 
| 2261 | ||
| 2262 | lemma card_UN_disjoint: | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2263 | "finite I ==> (ALL i:I. finite (A i)) ==> | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2264 |    (ALL i:I. ALL j:I. i \<noteq> j --> A i Int A j = {})
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2265 | ==> card (UNION I A) = (\<Sum>i\<in>I. card(A i))" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2266 | apply (simp add: card_def del: setsum_constant) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2267 | apply (subgoal_tac | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2268 | "setsum (%i. card (A i)) I = setsum (%i. (setsum (%x. 1) (A i))) I") | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2269 | apply (simp add: setsum_UN_disjoint del: setsum_constant) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2270 | apply (simp cong: setsum_cong) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2271 | done | 
| 15402 | 2272 | |
| 2273 | lemma card_Union_disjoint: | |
| 2274 | "finite C ==> (ALL A:C. finite A) ==> | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2275 |    (ALL A:C. ALL B:C. A \<noteq> B --> A Int B = {})
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2276 | ==> card (Union C) = setsum card C" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2277 | apply (frule card_UN_disjoint [of C id]) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2278 | apply (unfold Union_def id_def, assumption+) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2279 | done | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2280 | |
| 15402 | 2281 | |
| 12396 | 2282 | subsubsection {* Cardinality of image *}
 | 
| 2283 | ||
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2284 | text{*The image of a finite set can be expressed using @{term fold_image}.*}
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2285 | lemma image_eq_fold_image: | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2286 |   "finite A ==> f ` A = fold_image (op Un) (%x. {f x}) {} A"
 | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2287 | proof (induct rule: finite_induct) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2288 | case empty then show ?case by simp | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2289 | next | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 2290 | interpret ab_semigroup_mult "op Un" | 
| 28823 | 2291 | proof qed auto | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2292 | case insert | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2293 | then show ?case by simp | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2294 | qed | 
| 15447 | 2295 | |
| 12396 | 2296 | lemma card_image_le: "finite A ==> card (f ` A) <= card A" | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2297 | apply (induct set: finite) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2298 | apply simp | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2299 | apply (simp add: le_SucI finite_imageI card_insert_if) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2300 | done | 
| 12396 | 2301 | |
| 15402 | 2302 | lemma card_image: "inj_on f A ==> card (f ` A) = card A" | 
| 15539 | 2303 | by(simp add:card_def setsum_reindex o_def del:setsum_constant) | 
| 12396 | 2304 | |
| 31451 | 2305 | lemma bij_betw_same_card: "bij_betw f A B \<Longrightarrow> card A = card B" | 
| 2306 | by(auto simp: card_image bij_betw_def) | |
| 2307 | ||
| 12396 | 2308 | lemma endo_inj_surj: "finite A ==> f ` A \<subseteq> A ==> inj_on f A ==> f ` A = A" | 
| 25162 | 2309 | by (simp add: card_seteq card_image) | 
| 12396 | 2310 | |
| 15111 | 2311 | lemma eq_card_imp_inj_on: | 
| 2312 | "[| finite A; card(f ` A) = card A |] ==> inj_on f A" | |
| 21575 | 2313 | apply (induct rule:finite_induct) | 
| 2314 | apply simp | |
| 15111 | 2315 | apply(frule card_image_le[where f = f]) | 
| 2316 | apply(simp add:card_insert_if split:if_splits) | |
| 2317 | done | |
| 2318 | ||
| 2319 | lemma inj_on_iff_eq_card: | |
| 2320 | "finite A ==> inj_on f A = (card(f ` A) = card A)" | |
| 2321 | by(blast intro: card_image eq_card_imp_inj_on) | |
| 2322 | ||
| 12396 | 2323 | |
| 15402 | 2324 | lemma card_inj_on_le: | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2325 | "[|inj_on f A; f ` A \<subseteq> B; finite B |] ==> card A \<le> card B" | 
| 15402 | 2326 | apply (subgoal_tac "finite A") | 
| 2327 | apply (force intro: card_mono simp add: card_image [symmetric]) | |
| 2328 | apply (blast intro: finite_imageD dest: finite_subset) | |
| 2329 | done | |
| 2330 | ||
| 2331 | lemma card_bij_eq: | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2332 | "[|inj_on f A; f ` A \<subseteq> B; inj_on g B; g ` B \<subseteq> A; | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2333 | finite A; finite B |] ==> card A = card B" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2334 | by (auto intro: le_anti_sym card_inj_on_le) | 
| 15402 | 2335 | |
| 2336 | ||
| 2337 | subsubsection {* Cardinality of products *}
 | |
| 2338 | ||
| 2339 | (* | |
| 2340 | lemma SigmaI_insert: "y \<notin> A ==> | |
| 2341 |   (SIGMA x:(insert y A). B x) = (({y} <*> (B y)) \<union> (SIGMA x: A. B x))"
 | |
| 2342 | by auto | |
| 2343 | *) | |
| 2344 | ||
| 2345 | lemma card_SigmaI [simp]: | |
| 2346 | "\<lbrakk> finite A; ALL a:A. finite (B a) \<rbrakk> | |
| 2347 | \<Longrightarrow> card (SIGMA x: A. B x) = (\<Sum>a\<in>A. card (B a))" | |
| 15539 | 2348 | by(simp add:card_def setsum_Sigma del:setsum_constant) | 
| 15402 | 2349 | |
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 2350 | lemma card_cartesian_product: "card (A <*> B) = card(A) * card(B)" | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 2351 | apply (cases "finite A") | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 2352 | apply (cases "finite B") | 
| 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 2353 | apply (auto simp add: card_eq_0_iff | 
| 15539 | 2354 | dest: finite_cartesian_productD1 finite_cartesian_productD2) | 
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 2355 | done | 
| 15402 | 2356 | |
| 2357 | lemma card_cartesian_product_singleton:  "card({x} <*> A) = card(A)"
 | |
| 15539 | 2358 | by (simp add: card_cartesian_product) | 
| 15409 
a063687d24eb
new and stronger lemmas and improved simplification for finite sets
 paulson parents: 
15402diff
changeset | 2359 | |
| 15402 | 2360 | |
| 29025 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 huffman parents: 
28853diff
changeset | 2361 | subsubsection {* Cardinality of sums *}
 | 
| 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 huffman parents: 
28853diff
changeset | 2362 | |
| 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 huffman parents: 
28853diff
changeset | 2363 | lemma card_Plus: | 
| 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 huffman parents: 
28853diff
changeset | 2364 | assumes "finite A" and "finite B" | 
| 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 huffman parents: 
28853diff
changeset | 2365 | shows "card (A <+> B) = card A + card B" | 
| 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 huffman parents: 
28853diff
changeset | 2366 | proof - | 
| 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 huffman parents: 
28853diff
changeset | 2367 |   have "Inl`A \<inter> Inr`B = {}" by fast
 | 
| 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 huffman parents: 
28853diff
changeset | 2368 | with assms show ?thesis | 
| 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 huffman parents: 
28853diff
changeset | 2369 | unfolding Plus_def | 
| 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 huffman parents: 
28853diff
changeset | 2370 | by (simp add: card_Un_disjoint card_image) | 
| 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 huffman parents: 
28853diff
changeset | 2371 | qed | 
| 
8c8859c0d734
move lemmas from Numeral_Type.thy to other theories
 huffman parents: 
28853diff
changeset | 2372 | |
| 31080 | 2373 | lemma card_Plus_conv_if: | 
| 2374 | "card (A <+> B) = (if finite A \<and> finite B then card(A) + card(B) else 0)" | |
| 2375 | by(auto simp: card_def setsum_Plus simp del: setsum_constant) | |
| 2376 | ||
| 15402 | 2377 | |
| 12396 | 2378 | subsubsection {* Cardinality of the Powerset *}
 | 
| 2379 | ||
| 2380 | lemma card_Pow: "finite A ==> card (Pow A) = Suc (Suc 0) ^ card A" (* FIXME numeral 2 (!?) *) | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2381 | apply (induct set: finite) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2382 | apply (simp_all add: Pow_insert) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2383 | apply (subst card_Un_disjoint, blast) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2384 | apply (blast intro: finite_imageI, blast) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2385 | apply (subgoal_tac "inj_on (insert x) (Pow F)") | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2386 | apply (simp add: card_image Pow_insert) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2387 | apply (unfold inj_on_def) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2388 | apply (blast elim!: equalityE) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2389 | done | 
| 12396 | 2390 | |
| 24342 | 2391 | text {* Relates to equivalence classes.  Based on a theorem of F. Kammüller.  *}
 | 
| 12396 | 2392 | |
| 2393 | lemma dvd_partition: | |
| 15392 | 2394 | "finite (Union C) ==> | 
| 12396 | 2395 | ALL c : C. k dvd card c ==> | 
| 14430 
5cb24165a2e1
new material from Avigad, and simplified treatment of division by 0
 paulson parents: 
14331diff
changeset | 2396 |     (ALL c1: C. ALL c2: C. c1 \<noteq> c2 --> c1 Int c2 = {}) ==>
 | 
| 12396 | 2397 | k dvd card (Union C)" | 
| 15392 | 2398 | apply(frule finite_UnionD) | 
| 2399 | apply(rotate_tac -1) | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2400 | apply (induct set: finite, simp_all, clarify) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2401 | apply (subst card_Un_disjoint) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2402 | apply (auto simp add: dvd_add disjoint_eq_subset_Compl) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2403 | done | 
| 12396 | 2404 | |
| 2405 | ||
| 25162 | 2406 | subsubsection {* Relating injectivity and surjectivity *}
 | 
| 2407 | ||
| 2408 | lemma finite_surj_inj: "finite(A) \<Longrightarrow> A <= f`A \<Longrightarrow> inj_on f A" | |
| 2409 | apply(rule eq_card_imp_inj_on, assumption) | |
| 2410 | apply(frule finite_imageI) | |
| 2411 | apply(drule (1) card_seteq) | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2412 | apply(erule card_image_le) | 
| 25162 | 2413 | apply simp | 
| 2414 | done | |
| 2415 | ||
| 2416 | lemma finite_UNIV_surj_inj: fixes f :: "'a \<Rightarrow> 'a" | |
| 2417 | shows "finite(UNIV:: 'a set) \<Longrightarrow> surj f \<Longrightarrow> inj f" | |
| 2418 | by (blast intro: finite_surj_inj subset_UNIV dest:surj_range) | |
| 2419 | ||
| 2420 | lemma finite_UNIV_inj_surj: fixes f :: "'a \<Rightarrow> 'a" | |
| 2421 | shows "finite(UNIV:: 'a set) \<Longrightarrow> inj f \<Longrightarrow> surj f" | |
| 2422 | by(fastsimp simp:surj_def dest!: endo_inj_surj) | |
| 2423 | ||
| 31992 | 2424 | corollary infinite_UNIV_nat[iff]: "~finite(UNIV::nat set)" | 
| 25162 | 2425 | proof | 
| 2426 | assume "finite(UNIV::nat set)" | |
| 2427 | with finite_UNIV_inj_surj[of Suc] | |
| 2428 | show False by simp (blast dest: Suc_neq_Zero surjD) | |
| 2429 | qed | |
| 2430 | ||
| 31992 | 2431 | (* Often leads to bogus ATP proofs because of reduced type information, hence noatp *) | 
| 2432 | lemma infinite_UNIV_char_0[noatp]: | |
| 29879 | 2433 | "\<not> finite (UNIV::'a::semiring_char_0 set)" | 
| 2434 | proof | |
| 2435 | assume "finite (UNIV::'a set)" | |
| 2436 | with subset_UNIV have "finite (range of_nat::'a set)" | |
| 2437 | by (rule finite_subset) | |
| 2438 | moreover have "inj (of_nat::nat \<Rightarrow> 'a)" | |
| 2439 | by (simp add: inj_on_def) | |
| 2440 | ultimately have "finite (UNIV::nat set)" | |
| 2441 | by (rule finite_imageD) | |
| 2442 | then show "False" | |
| 2443 | by (simp add: infinite_UNIV_nat) | |
| 2444 | qed | |
| 25162 | 2445 | |
| 15392 | 2446 | subsection{* A fold functional for non-empty sets *}
 | 
| 2447 | ||
| 2448 | text{* Does not require start value. *}
 | |
| 12396 | 2449 | |
| 23736 | 2450 | inductive | 
| 22262 | 2451 |   fold1Set :: "('a => 'a => 'a) => 'a set => 'a => bool"
 | 
| 2452 | for f :: "'a => 'a => 'a" | |
| 2453 | where | |
| 15506 | 2454 | fold1Set_insertI [intro]: | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2455 | "\<lbrakk> fold_graph f a A x; a \<notin> A \<rbrakk> \<Longrightarrow> fold1Set f (insert a A) x" | 
| 12396 | 2456 | |
| 15392 | 2457 | constdefs | 
| 2458 |   fold1 :: "('a => 'a => 'a) => 'a set => 'a"
 | |
| 22262 | 2459 | "fold1 f A == THE x. fold1Set f A x" | 
| 15506 | 2460 | |
| 2461 | lemma fold1Set_nonempty: | |
| 22917 | 2462 |   "fold1Set f A x \<Longrightarrow> A \<noteq> {}"
 | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2463 | by(erule fold1Set.cases, simp_all) | 
| 15392 | 2464 | |
| 23736 | 2465 | inductive_cases empty_fold1SetE [elim!]: "fold1Set f {} x"
 | 
| 2466 | ||
| 2467 | inductive_cases insert_fold1SetE [elim!]: "fold1Set f (insert a X) x" | |
| 22262 | 2468 | |
| 2469 | ||
| 2470 | lemma fold1Set_sing [iff]: "(fold1Set f {a} b) = (a = b)"
 | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2471 | by (blast intro: fold_graph.intros elim: fold_graph.cases) | 
| 15392 | 2472 | |
| 22917 | 2473 | lemma fold1_singleton [simp]: "fold1 f {a} = a"
 | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2474 | by (unfold fold1_def) blast | 
| 12396 | 2475 | |
| 15508 | 2476 | lemma finite_nonempty_imp_fold1Set: | 
| 22262 | 2477 |   "\<lbrakk> finite A; A \<noteq> {} \<rbrakk> \<Longrightarrow> EX x. fold1Set f A x"
 | 
| 15508 | 2478 | apply (induct A rule: finite_induct) | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2479 | apply (auto dest: finite_imp_fold_graph [of _ f]) | 
| 15508 | 2480 | done | 
| 15506 | 2481 | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2482 | text{*First, some lemmas about @{const fold_graph}.*}
 | 
| 15392 | 2483 | |
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2484 | context ab_semigroup_mult | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2485 | begin | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2486 | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2487 | lemma fun_left_comm: "fun_left_comm(op *)" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2488 | by unfold_locales (simp add: mult_ac) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2489 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2490 | lemma fold_graph_insert_swap: | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2491 | assumes fold: "fold_graph times (b::'a) A y" and "b \<notin> A" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2492 | shows "fold_graph times z (insert b A) (z * y)" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2493 | proof - | 
| 29223 | 2494 | interpret fun_left_comm "op *::'a \<Rightarrow> 'a \<Rightarrow> 'a" by (rule fun_left_comm) | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2495 | from assms show ?thesis | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2496 | proof (induct rule: fold_graph.induct) | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2497 | case emptyI thus ?case by (force simp add: fold_insert_aux mult_commute) | 
| 15508 | 2498 | next | 
| 22262 | 2499 | case (insertI x A y) | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2500 | have "fold_graph times z (insert x (insert b A)) (x * (z * y))" | 
| 15521 | 2501 |       using insertI by force  --{*how does @{term id} get unfolded?*}
 | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2502 | thus ?case by (simp add: insert_commute mult_ac) | 
| 15508 | 2503 | qed | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2504 | qed | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2505 | |
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2506 | lemma fold_graph_permute_diff: | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2507 | assumes fold: "fold_graph times b A x" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2508 | shows "!!a. \<lbrakk>a \<in> A; b \<notin> A\<rbrakk> \<Longrightarrow> fold_graph times a (insert b (A-{a})) x"
 | 
| 15508 | 2509 | using fold | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2510 | proof (induct rule: fold_graph.induct) | 
| 15508 | 2511 | case emptyI thus ?case by simp | 
| 2512 | next | |
| 22262 | 2513 | case (insertI x A y) | 
| 15521 | 2514 | have "a = x \<or> a \<in> A" using insertI by simp | 
| 2515 | thus ?case | |
| 2516 | proof | |
| 2517 | assume "a = x" | |
| 2518 | with insertI show ?thesis | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2519 | by (simp add: id_def [symmetric], blast intro: fold_graph_insert_swap) | 
| 15521 | 2520 | next | 
| 2521 | assume ainA: "a \<in> A" | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2522 |     hence "fold_graph times a (insert x (insert b (A - {a}))) (x * y)"
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2523 | using insertI by force | 
| 15521 | 2524 | moreover | 
| 2525 |     have "insert x (insert b (A - {a})) = insert b (insert x A - {a})"
 | |
| 2526 | using ainA insertI by blast | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2527 | ultimately show ?thesis by simp | 
| 15508 | 2528 | qed | 
| 2529 | qed | |
| 2530 | ||
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2531 | lemma fold1_eq_fold: | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2532 | assumes "finite A" "a \<notin> A" shows "fold1 times (insert a A) = fold times a A" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2533 | proof - | 
| 29223 | 2534 | interpret fun_left_comm "op *::'a \<Rightarrow> 'a \<Rightarrow> 'a" by (rule fun_left_comm) | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2535 | from assms show ?thesis | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2536 | apply (simp add: fold1_def fold_def) | 
| 15508 | 2537 | apply (rule the_equality) | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2538 | apply (best intro: fold_graph_determ theI dest: finite_imp_fold_graph [of _ times]) | 
| 15508 | 2539 | apply (rule sym, clarify) | 
| 2540 | apply (case_tac "Aa=A") | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2541 | apply (best intro: the_equality fold_graph_determ) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2542 | apply (subgoal_tac "fold_graph times a A x") | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2543 | apply (best intro: the_equality fold_graph_determ) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2544 | apply (subgoal_tac "insert aa (Aa - {a}) = A")
 | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2545 | prefer 2 apply (blast elim: equalityE) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2546 | apply (auto dest: fold_graph_permute_diff [where a=a]) | 
| 15508 | 2547 | done | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2548 | qed | 
| 15508 | 2549 | |
| 15521 | 2550 | lemma nonempty_iff: "(A \<noteq> {}) = (\<exists>x B. A = insert x B & x \<notin> B)"
 | 
| 2551 | apply safe | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2552 | apply simp | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2553 | apply (drule_tac x=x in spec) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2554 |  apply (drule_tac x="A-{x}" in spec, auto)
 | 
| 15508 | 2555 | done | 
| 2556 | ||
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2557 | lemma fold1_insert: | 
| 15521 | 2558 |   assumes nonempty: "A \<noteq> {}" and A: "finite A" "x \<notin> A"
 | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2559 | shows "fold1 times (insert x A) = x * fold1 times A" | 
| 15521 | 2560 | proof - | 
| 29223 | 2561 | interpret fun_left_comm "op *::'a \<Rightarrow> 'a \<Rightarrow> 'a" by (rule fun_left_comm) | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2562 | from nonempty obtain a A' where "A = insert a A' & a ~: A'" | 
| 15521 | 2563 | by (auto simp add: nonempty_iff) | 
| 2564 | with A show ?thesis | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2565 | by (simp add: insert_commute [of x] fold1_eq_fold eq_commute) | 
| 15521 | 2566 | qed | 
| 2567 | ||
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2568 | end | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2569 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2570 | context ab_semigroup_idem_mult | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2571 | begin | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2572 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2573 | lemma fold1_insert_idem [simp]: | 
| 15521 | 2574 |   assumes nonempty: "A \<noteq> {}" and A: "finite A" 
 | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2575 | shows "fold1 times (insert x A) = x * fold1 times A" | 
| 15521 | 2576 | proof - | 
| 29223 | 2577 | interpret fun_left_comm_idem "op *::'a \<Rightarrow> 'a \<Rightarrow> 'a" | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2578 | by (rule fun_left_comm_idem) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2579 | from nonempty obtain a A' where A': "A = insert a A' & a ~: A'" | 
| 15521 | 2580 | by (auto simp add: nonempty_iff) | 
| 2581 | show ?thesis | |
| 2582 | proof cases | |
| 2583 | assume "a = x" | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2584 | thus ?thesis | 
| 15521 | 2585 | proof cases | 
| 2586 |       assume "A' = {}"
 | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2587 | with prems show ?thesis by (simp add: mult_idem) | 
| 15521 | 2588 | next | 
| 2589 |       assume "A' \<noteq> {}"
 | |
| 2590 | with prems show ?thesis | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2591 | by (simp add: fold1_insert mult_assoc [symmetric] mult_idem) | 
| 15521 | 2592 | qed | 
| 2593 | next | |
| 2594 | assume "a \<noteq> x" | |
| 2595 | with prems show ?thesis | |
| 2596 | by (simp add: insert_commute fold1_eq_fold fold_insert_idem) | |
| 2597 | qed | |
| 2598 | qed | |
| 15506 | 2599 | |
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2600 | lemma hom_fold1_commute: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2601 | assumes hom: "!!x y. h (x * y) = h x * h y" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2602 | and N: "finite N" "N \<noteq> {}" shows "h (fold1 times N) = fold1 times (h ` N)"
 | 
| 22917 | 2603 | using N proof (induct rule: finite_ne_induct) | 
| 2604 | case singleton thus ?case by simp | |
| 2605 | next | |
| 2606 | case (insert n N) | |
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2607 | then have "h (fold1 times (insert n N)) = h (n * fold1 times N)" by simp | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2608 | also have "\<dots> = h n * h (fold1 times N)" by(rule hom) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2609 | also have "h (fold1 times N) = fold1 times (h ` N)" by(rule insert) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2610 | also have "times (h n) \<dots> = fold1 times (insert (h n) (h ` N))" | 
| 22917 | 2611 | using insert by(simp) | 
| 2612 | also have "insert (h n) (h ` N) = h ` insert n N" by simp | |
| 2613 | finally show ?case . | |
| 2614 | qed | |
| 2615 | ||
| 32679 | 2616 | lemma fold1_eq_fold_idem: | 
| 2617 | assumes "finite A" | |
| 2618 | shows "fold1 times (insert a A) = fold times a A" | |
| 2619 | proof (cases "a \<in> A") | |
| 2620 | case False | |
| 2621 | with assms show ?thesis by (simp add: fold1_eq_fold) | |
| 2622 | next | |
| 2623 | interpret fun_left_comm_idem times by (fact fun_left_comm_idem) | |
| 2624 | case True then obtain b B | |
| 2625 | where A: "A = insert a B" and "a \<notin> B" by (rule set_insert) | |
| 2626 | with assms have "finite B" by auto | |
| 2627 | then have "fold times a (insert a B) = fold times (a * a) B" | |
| 2628 | using `a \<notin> B` by (rule fold_insert2) | |
| 2629 | then show ?thesis | |
| 2630 | using `a \<notin> B` `finite B` by (simp add: fold1_eq_fold A) | |
| 2631 | qed | |
| 2632 | ||
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2633 | end | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2634 | |
| 15506 | 2635 | |
| 15508 | 2636 | text{* Now the recursion rules for definitions: *}
 | 
| 2637 | ||
| 22917 | 2638 | lemma fold1_singleton_def: "g = fold1 f \<Longrightarrow> g {a} = a"
 | 
| 15508 | 2639 | by(simp add:fold1_singleton) | 
| 2640 | ||
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2641 | lemma (in ab_semigroup_mult) fold1_insert_def: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2642 |   "\<lbrakk> g = fold1 times; finite A; x \<notin> A; A \<noteq> {} \<rbrakk> \<Longrightarrow> g (insert x A) = x * g A"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2643 | by (simp add:fold1_insert) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2644 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2645 | lemma (in ab_semigroup_idem_mult) fold1_insert_idem_def: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2646 |   "\<lbrakk> g = fold1 times; finite A; A \<noteq> {} \<rbrakk> \<Longrightarrow> g (insert x A) = x * g A"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2647 | by simp | 
| 15508 | 2648 | |
| 2649 | subsubsection{* Determinacy for @{term fold1Set} *}
 | |
| 2650 | ||
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2651 | (*Not actually used!!*) | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2652 | (* | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2653 | context ab_semigroup_mult | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2654 | begin | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2655 | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2656 | lemma fold_graph_permute: | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2657 | "[|fold_graph times id b (insert a A) x; a \<notin> A; b \<notin> A|] | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2658 | ==> fold_graph times id a (insert b A) x" | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2659 | apply (cases "a=b") | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2660 | apply (auto dest: fold_graph_permute_diff) | 
| 15506 | 2661 | done | 
| 15376 | 2662 | |
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2663 | lemma fold1Set_determ: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2664 | "fold1Set times A x ==> fold1Set times A y ==> y = x" | 
| 15506 | 2665 | proof (clarify elim!: fold1Set.cases) | 
| 2666 | fix A x B y a b | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2667 | assume Ax: "fold_graph times id a A x" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2668 | assume By: "fold_graph times id b B y" | 
| 15506 | 2669 | assume anotA: "a \<notin> A" | 
| 2670 | assume bnotB: "b \<notin> B" | |
| 2671 | assume eq: "insert a A = insert b B" | |
| 2672 | show "y=x" | |
| 2673 | proof cases | |
| 2674 | assume same: "a=b" | |
| 2675 | hence "A=B" using anotA bnotB eq by (blast elim!: equalityE) | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2676 | thus ?thesis using Ax By same by (blast intro: fold_graph_determ) | 
| 15392 | 2677 | next | 
| 15506 | 2678 | assume diff: "a\<noteq>b" | 
| 2679 |     let ?D = "B - {a}"
 | |
| 2680 | have B: "B = insert a ?D" and A: "A = insert b ?D" | |
| 2681 | and aB: "a \<in> B" and bA: "b \<in> A" | |
| 2682 | using eq anotA bnotB diff by (blast elim!:equalityE)+ | |
| 2683 | with aB bnotB By | |
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2684 | have "fold_graph times id a (insert b ?D) y" | 
| 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2685 | by (auto intro: fold_graph_permute simp add: insert_absorb) | 
| 15506 | 2686 | moreover | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2687 | have "fold_graph times id a (insert b ?D) x" | 
| 15506 | 2688 | by (simp add: A [symmetric] Ax) | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2689 | ultimately show ?thesis by (blast intro: fold_graph_determ) | 
| 15392 | 2690 | qed | 
| 12396 | 2691 | qed | 
| 2692 | ||
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2693 | lemma fold1Set_equality: "fold1Set times A y ==> fold1 times A = y" | 
| 15506 | 2694 | by (unfold fold1_def) (blast intro: fold1Set_determ) | 
| 2695 | ||
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2696 | end | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2697 | *) | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2698 | |
| 15506 | 2699 | declare | 
| 28853 
69eb69659bf3
Added new fold operator and renamed the old oe to fold_image.
 nipkow parents: 
28823diff
changeset | 2700 | empty_fold_graphE [rule del] fold_graph.intros [rule del] | 
| 15506 | 2701 | empty_fold1SetE [rule del] insert_fold1SetE [rule del] | 
| 19931 
fb32b43e7f80
Restructured locales with predicates: import is now an interpretation.
 ballarin parents: 
19870diff
changeset | 2702 |   -- {* No more proofs involve these relations. *}
 | 
| 15376 | 2703 | |
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2704 | subsubsection {* Lemmas about @{text fold1} *}
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2705 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2706 | context ab_semigroup_mult | 
| 22917 | 2707 | begin | 
| 2708 | ||
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2709 | lemma fold1_Un: | 
| 15484 | 2710 | assumes A: "finite A" "A \<noteq> {}"
 | 
| 2711 | shows "finite B \<Longrightarrow> B \<noteq> {} \<Longrightarrow> A Int B = {} \<Longrightarrow>
 | |
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2712 | fold1 times (A Un B) = fold1 times A * fold1 times B" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2713 | using A by (induct rule: finite_ne_induct) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2714 | (simp_all add: fold1_insert mult_assoc) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2715 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2716 | lemma fold1_in: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2717 |   assumes A: "finite (A)" "A \<noteq> {}" and elem: "\<And>x y. x * y \<in> {x,y}"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2718 | shows "fold1 times A \<in> A" | 
| 15484 | 2719 | using A | 
| 2720 | proof (induct rule:finite_ne_induct) | |
| 15506 | 2721 | case singleton thus ?case by simp | 
| 15484 | 2722 | next | 
| 2723 | case insert thus ?case using elem by (force simp add:fold1_insert) | |
| 2724 | qed | |
| 2725 | ||
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2726 | end | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2727 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2728 | lemma (in ab_semigroup_idem_mult) fold1_Un2: | 
| 15497 
53bca254719a
Added semi-lattice locales and reorganized fold1 lemmas
 nipkow parents: 
15487diff
changeset | 2729 | assumes A: "finite A" "A \<noteq> {}"
 | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2730 | shows "finite B \<Longrightarrow> B \<noteq> {} \<Longrightarrow>
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2731 | fold1 times (A Un B) = fold1 times A * fold1 times B" | 
| 15497 
53bca254719a
Added semi-lattice locales and reorganized fold1 lemmas
 nipkow parents: 
15487diff
changeset | 2732 | using A | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2733 | proof(induct rule:finite_ne_induct) | 
| 15497 
53bca254719a
Added semi-lattice locales and reorganized fold1 lemmas
 nipkow parents: 
15487diff
changeset | 2734 | case singleton thus ?case by simp | 
| 15484 | 2735 | next | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2736 | case insert thus ?case by (simp add: mult_assoc) | 
| 18423 | 2737 | qed | 
| 2738 | ||
| 2739 | ||
| 22917 | 2740 | subsubsection {* Fold1 in lattices with @{const inf} and @{const sup} *}
 | 
| 2741 | ||
| 2742 | text{*
 | |
| 2743 |   As an application of @{text fold1} we define infimum
 | |
| 2744 | and supremum in (not necessarily complete!) lattices | |
| 2745 |   over (non-empty) sets by means of @{text fold1}.
 | |
| 2746 | *} | |
| 2747 | ||
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2748 | context lower_semilattice | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2749 | begin | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2750 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2751 | lemma below_fold1_iff: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2752 |   assumes "finite A" "A \<noteq> {}"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2753 | shows "x \<le> fold1 inf A \<longleftrightarrow> (\<forall>a\<in>A. x \<le> a)" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2754 | proof - | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 2755 | interpret ab_semigroup_idem_mult inf | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2756 | by (rule ab_semigroup_idem_mult_inf) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2757 | show ?thesis using assms by (induct rule: finite_ne_induct) simp_all | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2758 | qed | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2759 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2760 | lemma fold1_belowI: | 
| 26757 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2761 | assumes "finite A" | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2762 | and "a \<in> A" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2763 | shows "fold1 inf A \<le> a" | 
| 26757 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2764 | proof - | 
| 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2765 |   from assms have "A \<noteq> {}" by auto
 | 
| 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2766 |   from `finite A` `A \<noteq> {}` `a \<in> A` show ?thesis
 | 
| 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2767 | proof (induct rule: finite_ne_induct) | 
| 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2768 | case singleton thus ?case by simp | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2769 | next | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 2770 | interpret ab_semigroup_idem_mult inf | 
| 26757 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2771 | by (rule ab_semigroup_idem_mult_inf) | 
| 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2772 | case (insert x F) | 
| 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2773 | from insert(5) have "a = x \<or> a \<in> F" by simp | 
| 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2774 | thus ?case | 
| 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2775 | proof | 
| 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2776 | assume "a = x" thus ?thesis using insert | 
| 29667 | 2777 | by (simp add: mult_ac) | 
| 26757 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2778 | next | 
| 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2779 | assume "a \<in> F" | 
| 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2780 | hence bel: "fold1 inf F \<le> a" by (rule insert) | 
| 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2781 | have "inf (fold1 inf (insert x F)) a = inf x (inf (fold1 inf F) a)" | 
| 29667 | 2782 | using insert by (simp add: mult_ac) | 
| 26757 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2783 | also have "inf (fold1 inf F) a = fold1 inf F" | 
| 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2784 | using bel by (auto intro: antisym) | 
| 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2785 | also have "inf x \<dots> = fold1 inf (insert x F)" | 
| 29667 | 2786 | using insert by (simp add: mult_ac) | 
| 26757 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2787 | finally have aux: "inf (fold1 inf (insert x F)) a = fold1 inf (insert x F)" . | 
| 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2788 | moreover have "inf (fold1 inf (insert x F)) a \<le> a" by simp | 
| 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2789 | ultimately show ?thesis by simp | 
| 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2790 | qed | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2791 | qed | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2792 | qed | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2793 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2794 | end | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2795 | |
| 24342 | 2796 | context lattice | 
| 22917 | 2797 | begin | 
| 2798 | ||
| 2799 | definition | |
| 31916 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 2800 |   Inf_fin :: "'a set \<Rightarrow> 'a" ("\<Sqinter>\<^bsub>fin\<^esub>_" [900] 900)
 | 
| 22917 | 2801 | where | 
| 25062 | 2802 | "Inf_fin = fold1 inf" | 
| 22917 | 2803 | |
| 2804 | definition | |
| 31916 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 2805 |   Sup_fin :: "'a set \<Rightarrow> 'a" ("\<Squnion>\<^bsub>fin\<^esub>_" [900] 900)
 | 
| 22917 | 2806 | where | 
| 25062 | 2807 | "Sup_fin = fold1 sup" | 
| 2808 | ||
| 31916 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 2809 | lemma Inf_le_Sup [simp]: "\<lbrakk> finite A; A \<noteq> {} \<rbrakk> \<Longrightarrow> \<Sqinter>\<^bsub>fin\<^esub>A \<le> \<Squnion>\<^bsub>fin\<^esub>A"
 | 
| 24342 | 2810 | apply(unfold Sup_fin_def Inf_fin_def) | 
| 15500 | 2811 | apply(subgoal_tac "EX a. a:A") | 
| 2812 | prefer 2 apply blast | |
| 2813 | apply(erule exE) | |
| 22388 | 2814 | apply(rule order_trans) | 
| 26757 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 2815 | apply(erule (1) fold1_belowI) | 
| 31991 
37390299214a
added boolean_algebra type class; tuned lattice duals
 haftmann parents: 
31916diff
changeset | 2816 | apply(erule (1) lower_semilattice.fold1_belowI [OF dual_semilattice]) | 
| 15500 | 2817 | done | 
| 2818 | ||
| 24342 | 2819 | lemma sup_Inf_absorb [simp]: | 
| 31916 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 2820 | "finite A \<Longrightarrow> a \<in> A \<Longrightarrow> sup a (\<Sqinter>\<^bsub>fin\<^esub>A) = a" | 
| 15512 
ed1fa4617f52
Extracted generic lattice stuff to new Lattice_Locales.thy
 nipkow parents: 
15510diff
changeset | 2821 | apply(subst sup_commute) | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2822 | apply(simp add: Inf_fin_def sup_absorb2 fold1_belowI) | 
| 15504 | 2823 | done | 
| 2824 | ||
| 24342 | 2825 | lemma inf_Sup_absorb [simp]: | 
| 31916 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 2826 | "finite A \<Longrightarrow> a \<in> A \<Longrightarrow> inf a (\<Squnion>\<^bsub>fin\<^esub>A) = a" | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2827 | by (simp add: Sup_fin_def inf_absorb1 | 
| 31991 
37390299214a
added boolean_algebra type class; tuned lattice duals
 haftmann parents: 
31916diff
changeset | 2828 | lower_semilattice.fold1_belowI [OF dual_semilattice]) | 
| 24342 | 2829 | |
| 2830 | end | |
| 2831 | ||
| 2832 | context distrib_lattice | |
| 2833 | begin | |
| 2834 | ||
| 2835 | lemma sup_Inf1_distrib: | |
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2836 | assumes "finite A" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2837 |     and "A \<noteq> {}"
 | 
| 31916 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 2838 |   shows "sup x (\<Sqinter>\<^bsub>fin\<^esub>A) = \<Sqinter>\<^bsub>fin\<^esub>{sup x a|a. a \<in> A}"
 | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2839 | proof - | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 2840 | interpret ab_semigroup_idem_mult inf | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2841 | by (rule ab_semigroup_idem_mult_inf) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2842 | from assms show ?thesis | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2843 | by (simp add: Inf_fin_def image_def | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2844 | hom_fold1_commute [where h="sup x", OF sup_inf_distrib1]) | 
| 26792 | 2845 | (rule arg_cong [where f="fold1 inf"], blast) | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2846 | qed | 
| 18423 | 2847 | |
| 24342 | 2848 | lemma sup_Inf2_distrib: | 
| 2849 |   assumes A: "finite A" "A \<noteq> {}" and B: "finite B" "B \<noteq> {}"
 | |
| 31916 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 2850 |   shows "sup (\<Sqinter>\<^bsub>fin\<^esub>A) (\<Sqinter>\<^bsub>fin\<^esub>B) = \<Sqinter>\<^bsub>fin\<^esub>{sup a b|a b. a \<in> A \<and> b \<in> B}"
 | 
| 24342 | 2851 | using A proof (induct rule: finite_ne_induct) | 
| 15500 | 2852 | case singleton thus ?case | 
| 24342 | 2853 | by (simp add: sup_Inf1_distrib [OF B] fold1_singleton_def [OF Inf_fin_def]) | 
| 15500 | 2854 | next | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 2855 | interpret ab_semigroup_idem_mult inf | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2856 | by (rule ab_semigroup_idem_mult_inf) | 
| 15500 | 2857 | case (insert x A) | 
| 25062 | 2858 |   have finB: "finite {sup x b |b. b \<in> B}"
 | 
| 2859 | by(rule finite_surj[where f = "sup x", OF B(1)], auto) | |
| 2860 |   have finAB: "finite {sup a b |a b. a \<in> A \<and> b \<in> B}"
 | |
| 15500 | 2861 | proof - | 
| 25062 | 2862 |     have "{sup a b |a b. a \<in> A \<and> b \<in> B} = (UN a:A. UN b:B. {sup a b})"
 | 
| 15500 | 2863 | by blast | 
| 15517 | 2864 | thus ?thesis by(simp add: insert(1) B(1)) | 
| 15500 | 2865 | qed | 
| 25062 | 2866 |   have ne: "{sup a b |a b. a \<in> A \<and> b \<in> B} \<noteq> {}" using insert B by blast
 | 
| 31916 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 2867 | have "sup (\<Sqinter>\<^bsub>fin\<^esub>(insert x A)) (\<Sqinter>\<^bsub>fin\<^esub>B) = sup (inf x (\<Sqinter>\<^bsub>fin\<^esub>A)) (\<Sqinter>\<^bsub>fin\<^esub>B)" | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2868 | using insert by (simp add: fold1_insert_idem_def [OF Inf_fin_def]) | 
| 31916 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 2869 | also have "\<dots> = inf (sup x (\<Sqinter>\<^bsub>fin\<^esub>B)) (sup (\<Sqinter>\<^bsub>fin\<^esub>A) (\<Sqinter>\<^bsub>fin\<^esub>B))" by(rule sup_inf_distrib2) | 
| 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 2870 |   also have "\<dots> = inf (\<Sqinter>\<^bsub>fin\<^esub>{sup x b|b. b \<in> B}) (\<Sqinter>\<^bsub>fin\<^esub>{sup a b|a b. a \<in> A \<and> b \<in> B})"
 | 
| 15500 | 2871 | using insert by(simp add:sup_Inf1_distrib[OF B]) | 
| 31916 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 2872 |   also have "\<dots> = \<Sqinter>\<^bsub>fin\<^esub>({sup x b |b. b \<in> B} \<union> {sup a b |a b. a \<in> A \<and> b \<in> B})"
 | 
| 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 2873 | (is "_ = \<Sqinter>\<^bsub>fin\<^esub>?M") | 
| 15500 | 2874 | using B insert | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2875 | by (simp add: Inf_fin_def fold1_Un2 [OF finB _ finAB ne]) | 
| 25062 | 2876 |   also have "?M = {sup a b |a b. a \<in> insert x A \<and> b \<in> B}"
 | 
| 15500 | 2877 | by blast | 
| 2878 | finally show ?case . | |
| 2879 | qed | |
| 2880 | ||
| 24342 | 2881 | lemma inf_Sup1_distrib: | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2882 |   assumes "finite A" and "A \<noteq> {}"
 | 
| 31916 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 2883 |   shows "inf x (\<Squnion>\<^bsub>fin\<^esub>A) = \<Squnion>\<^bsub>fin\<^esub>{inf x a|a. a \<in> A}"
 | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2884 | proof - | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 2885 | interpret ab_semigroup_idem_mult sup | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2886 | by (rule ab_semigroup_idem_mult_sup) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2887 | from assms show ?thesis | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2888 | by (simp add: Sup_fin_def image_def hom_fold1_commute [where h="inf x", OF inf_sup_distrib1]) | 
| 26792 | 2889 | (rule arg_cong [where f="fold1 sup"], blast) | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2890 | qed | 
| 18423 | 2891 | |
| 24342 | 2892 | lemma inf_Sup2_distrib: | 
| 2893 |   assumes A: "finite A" "A \<noteq> {}" and B: "finite B" "B \<noteq> {}"
 | |
| 31916 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 2894 |   shows "inf (\<Squnion>\<^bsub>fin\<^esub>A) (\<Squnion>\<^bsub>fin\<^esub>B) = \<Squnion>\<^bsub>fin\<^esub>{inf a b|a b. a \<in> A \<and> b \<in> B}"
 | 
| 24342 | 2895 | using A proof (induct rule: finite_ne_induct) | 
| 18423 | 2896 | case singleton thus ?case | 
| 24342 | 2897 | by(simp add: inf_Sup1_distrib [OF B] fold1_singleton_def [OF Sup_fin_def]) | 
| 18423 | 2898 | next | 
| 2899 | case (insert x A) | |
| 25062 | 2900 |   have finB: "finite {inf x b |b. b \<in> B}"
 | 
| 2901 | by(rule finite_surj[where f = "%b. inf x b", OF B(1)], auto) | |
| 2902 |   have finAB: "finite {inf a b |a b. a \<in> A \<and> b \<in> B}"
 | |
| 18423 | 2903 | proof - | 
| 25062 | 2904 |     have "{inf a b |a b. a \<in> A \<and> b \<in> B} = (UN a:A. UN b:B. {inf a b})"
 | 
| 18423 | 2905 | by blast | 
| 2906 | thus ?thesis by(simp add: insert(1) B(1)) | |
| 2907 | qed | |
| 25062 | 2908 |   have ne: "{inf a b |a b. a \<in> A \<and> b \<in> B} \<noteq> {}" using insert B by blast
 | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 2909 | interpret ab_semigroup_idem_mult sup | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2910 | by (rule ab_semigroup_idem_mult_sup) | 
| 31916 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 2911 | have "inf (\<Squnion>\<^bsub>fin\<^esub>(insert x A)) (\<Squnion>\<^bsub>fin\<^esub>B) = inf (sup x (\<Squnion>\<^bsub>fin\<^esub>A)) (\<Squnion>\<^bsub>fin\<^esub>B)" | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2912 | using insert by (simp add: fold1_insert_idem_def [OF Sup_fin_def]) | 
| 31916 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 2913 | also have "\<dots> = sup (inf x (\<Squnion>\<^bsub>fin\<^esub>B)) (inf (\<Squnion>\<^bsub>fin\<^esub>A) (\<Squnion>\<^bsub>fin\<^esub>B))" by(rule inf_sup_distrib2) | 
| 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 2914 |   also have "\<dots> = sup (\<Squnion>\<^bsub>fin\<^esub>{inf x b|b. b \<in> B}) (\<Squnion>\<^bsub>fin\<^esub>{inf a b|a b. a \<in> A \<and> b \<in> B})"
 | 
| 18423 | 2915 | using insert by(simp add:inf_Sup1_distrib[OF B]) | 
| 31916 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 2916 |   also have "\<dots> = \<Squnion>\<^bsub>fin\<^esub>({inf x b |b. b \<in> B} \<union> {inf a b |a b. a \<in> A \<and> b \<in> B})"
 | 
| 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 2917 | (is "_ = \<Squnion>\<^bsub>fin\<^esub>?M") | 
| 18423 | 2918 | using B insert | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2919 | by (simp add: Sup_fin_def fold1_Un2 [OF finB _ finAB ne]) | 
| 25062 | 2920 |   also have "?M = {inf a b |a b. a \<in> insert x A \<and> b \<in> B}"
 | 
| 18423 | 2921 | by blast | 
| 2922 | finally show ?case . | |
| 2923 | qed | |
| 2924 | ||
| 24342 | 2925 | end | 
| 2926 | ||
| 2927 | context complete_lattice | |
| 2928 | begin | |
| 2929 | ||
| 22917 | 2930 | text {*
 | 
| 24342 | 2931 | Coincidence on finite sets in complete lattices: | 
| 22917 | 2932 | *} | 
| 2933 | ||
| 24342 | 2934 | lemma Inf_fin_Inf: | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2935 |   assumes "finite A" and "A \<noteq> {}"
 | 
| 31916 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 2936 | shows "\<Sqinter>\<^bsub>fin\<^esub>A = Inf A" | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2937 | proof - | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 2938 | interpret ab_semigroup_idem_mult inf | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2939 | by (rule ab_semigroup_idem_mult_inf) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2940 | from assms show ?thesis | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2941 | unfolding Inf_fin_def by (induct A set: finite) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2942 | (simp_all add: Inf_insert_simp) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2943 | qed | 
| 22917 | 2944 | |
| 24342 | 2945 | lemma Sup_fin_Sup: | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2946 |   assumes "finite A" and "A \<noteq> {}"
 | 
| 31916 
f3227bb306a4
recovered subscripts, which were lost in b41d61c768e2 (due to Emacs accident?);
 wenzelm parents: 
31907diff
changeset | 2947 | shows "\<Squnion>\<^bsub>fin\<^esub>A = Sup A" | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2948 | proof - | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 2949 | interpret ab_semigroup_idem_mult sup | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2950 | by (rule ab_semigroup_idem_mult_sup) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2951 | from assms show ?thesis | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2952 | unfolding Sup_fin_def by (induct A set: finite) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2953 | (simp_all add: Sup_insert_simp) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2954 | qed | 
| 22917 | 2955 | |
| 24342 | 2956 | end | 
| 2957 | ||
| 22917 | 2958 | |
| 2959 | subsubsection {* Fold1 in linear orders with @{const min} and @{const max} *}
 | |
| 2960 | ||
| 2961 | text{*
 | |
| 2962 |   As an application of @{text fold1} we define minimum
 | |
| 2963 | and maximum in (not necessarily complete!) linear orders | |
| 2964 |   over (non-empty) sets by means of @{text fold1}.
 | |
| 2965 | *} | |
| 2966 | ||
| 24342 | 2967 | context linorder | 
| 22917 | 2968 | begin | 
| 2969 | ||
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2970 | lemma ab_semigroup_idem_mult_min: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2971 | "ab_semigroup_idem_mult min" | 
| 28823 | 2972 | proof qed (auto simp add: min_def) | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2973 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2974 | lemma ab_semigroup_idem_mult_max: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2975 | "ab_semigroup_idem_mult max" | 
| 28823 | 2976 | proof qed (auto simp add: max_def) | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2977 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2978 | lemma max_lattice: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2979 | "lower_semilattice (op \<ge>) (op >) max" | 
| 32203 
992ac8942691
adapted to localized interpretation of min/max-lattice
 haftmann parents: 
32075diff
changeset | 2980 | by (fact min_max.dual_semilattice) | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2981 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2982 | lemma dual_max: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2983 | "ord.max (op \<ge>) = min" | 
| 32642 
026e7c6a6d08
be more cautious wrt. simp rules: inf_absorb1, inf_absorb2, sup_absorb1, sup_absorb2 are no simp rules by default any longer
 haftmann parents: 
32437diff
changeset | 2984 | by (auto simp add: ord.max_def_raw min_def expand_fun_eq) | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2985 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2986 | lemma dual_min: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2987 | "ord.min (op \<ge>) = max" | 
| 32642 
026e7c6a6d08
be more cautious wrt. simp rules: inf_absorb1, inf_absorb2, sup_absorb1, sup_absorb2 are no simp rules by default any longer
 haftmann parents: 
32437diff
changeset | 2988 | by (auto simp add: ord.min_def_raw max_def expand_fun_eq) | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2989 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2990 | lemma strict_below_fold1_iff: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2991 |   assumes "finite A" and "A \<noteq> {}"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2992 | shows "x < fold1 min A \<longleftrightarrow> (\<forall>a\<in>A. x < a)" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2993 | proof - | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 2994 | interpret ab_semigroup_idem_mult min | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2995 | by (rule ab_semigroup_idem_mult_min) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2996 | from assms show ?thesis | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2997 | by (induct rule: finite_ne_induct) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2998 | (simp_all add: fold1_insert) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 2999 | qed | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3000 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3001 | lemma fold1_below_iff: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3002 |   assumes "finite A" and "A \<noteq> {}"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3003 | shows "fold1 min A \<le> x \<longleftrightarrow> (\<exists>a\<in>A. a \<le> x)" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3004 | proof - | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 3005 | interpret ab_semigroup_idem_mult min | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3006 | by (rule ab_semigroup_idem_mult_min) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3007 | from assms show ?thesis | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3008 | by (induct rule: finite_ne_induct) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3009 | (simp_all add: fold1_insert min_le_iff_disj) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3010 | qed | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3011 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3012 | lemma fold1_strict_below_iff: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3013 |   assumes "finite A" and "A \<noteq> {}"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3014 | shows "fold1 min A < x \<longleftrightarrow> (\<exists>a\<in>A. a < x)" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3015 | proof - | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 3016 | interpret ab_semigroup_idem_mult min | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3017 | by (rule ab_semigroup_idem_mult_min) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3018 | from assms show ?thesis | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3019 | by (induct rule: finite_ne_induct) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3020 | (simp_all add: fold1_insert min_less_iff_disj) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3021 | qed | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3022 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3023 | lemma fold1_antimono: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3024 |   assumes "A \<noteq> {}" and "A \<subseteq> B" and "finite B"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3025 | shows "fold1 min B \<le> fold1 min A" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3026 | proof cases | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3027 | assume "A = B" thus ?thesis by simp | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3028 | next | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 3029 | interpret ab_semigroup_idem_mult min | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3030 | by (rule ab_semigroup_idem_mult_min) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3031 | assume "A \<noteq> B" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3032 | have B: "B = A \<union> (B-A)" using `A \<subseteq> B` by blast | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3033 | have "fold1 min B = fold1 min (A \<union> (B-A))" by(subst B)(rule refl) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3034 | also have "\<dots> = min (fold1 min A) (fold1 min (B-A))" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3035 | proof - | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3036 | have "finite A" by(rule finite_subset[OF `A \<subseteq> B` `finite B`]) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3037 | moreover have "finite(B-A)" by(rule finite_Diff[OF `finite B`]) (* by(blast intro:finite_Diff prems) fails *) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3038 |     moreover have "(B-A) \<noteq> {}" using prems by blast
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3039 |     moreover have "A Int (B-A) = {}" using prems by blast
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3040 |     ultimately show ?thesis using `A \<noteq> {}` by (rule_tac fold1_Un)
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3041 | qed | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3042 | also have "\<dots> \<le> fold1 min A" by (simp add: min_le_iff_disj) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3043 | finally show ?thesis . | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3044 | qed | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3045 | |
| 22917 | 3046 | definition | 
| 3047 | Min :: "'a set \<Rightarrow> 'a" | |
| 3048 | where | |
| 3049 | "Min = fold1 min" | |
| 3050 | ||
| 3051 | definition | |
| 3052 | Max :: "'a set \<Rightarrow> 'a" | |
| 3053 | where | |
| 3054 | "Max = fold1 max" | |
| 3055 | ||
| 3056 | lemmas Min_singleton [simp] = fold1_singleton_def [OF Min_def] | |
| 3057 | lemmas Max_singleton [simp] = fold1_singleton_def [OF Max_def] | |
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3058 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3059 | lemma Min_insert [simp]: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3060 |   assumes "finite A" and "A \<noteq> {}"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3061 | shows "Min (insert x A) = min x (Min A)" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3062 | proof - | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 3063 | interpret ab_semigroup_idem_mult min | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3064 | by (rule ab_semigroup_idem_mult_min) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3065 | from assms show ?thesis by (rule fold1_insert_idem_def [OF Min_def]) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3066 | qed | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3067 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3068 | lemma Max_insert [simp]: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3069 |   assumes "finite A" and "A \<noteq> {}"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3070 | shows "Max (insert x A) = max x (Max A)" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3071 | proof - | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 3072 | interpret ab_semigroup_idem_mult max | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3073 | by (rule ab_semigroup_idem_mult_max) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3074 | from assms show ?thesis by (rule fold1_insert_idem_def [OF Max_def]) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3075 | qed | 
| 15392 | 3076 | |
| 24427 | 3077 | lemma Min_in [simp]: | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3078 |   assumes "finite A" and "A \<noteq> {}"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3079 | shows "Min A \<in> A" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3080 | proof - | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 3081 | interpret ab_semigroup_idem_mult min | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3082 | by (rule ab_semigroup_idem_mult_min) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3083 | from assms fold1_in show ?thesis by (fastsimp simp: Min_def min_def) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3084 | qed | 
| 15392 | 3085 | |
| 24427 | 3086 | lemma Max_in [simp]: | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3087 |   assumes "finite A" and "A \<noteq> {}"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3088 | shows "Max A \<in> A" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3089 | proof - | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 3090 | interpret ab_semigroup_idem_mult max | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3091 | by (rule ab_semigroup_idem_mult_max) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3092 | from assms fold1_in [of A] show ?thesis by (fastsimp simp: Max_def max_def) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3093 | qed | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3094 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3095 | lemma Min_Un: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3096 |   assumes "finite A" and "A \<noteq> {}" and "finite B" and "B \<noteq> {}"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3097 | shows "Min (A \<union> B) = min (Min A) (Min B)" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3098 | proof - | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 3099 | interpret ab_semigroup_idem_mult min | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3100 | by (rule ab_semigroup_idem_mult_min) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3101 | from assms show ?thesis | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3102 | by (simp add: Min_def fold1_Un2) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3103 | qed | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3104 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3105 | lemma Max_Un: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3106 |   assumes "finite A" and "A \<noteq> {}" and "finite B" and "B \<noteq> {}"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3107 | shows "Max (A \<union> B) = max (Max A) (Max B)" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3108 | proof - | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 3109 | interpret ab_semigroup_idem_mult max | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3110 | by (rule ab_semigroup_idem_mult_max) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3111 | from assms show ?thesis | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3112 | by (simp add: Max_def fold1_Un2) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3113 | qed | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3114 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3115 | lemma hom_Min_commute: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3116 | assumes "\<And>x y. h (min x y) = min (h x) (h y)" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3117 |     and "finite N" and "N \<noteq> {}"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3118 | shows "h (Min N) = Min (h ` N)" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3119 | proof - | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 3120 | interpret ab_semigroup_idem_mult min | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3121 | by (rule ab_semigroup_idem_mult_min) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3122 | from assms show ?thesis | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3123 | by (simp add: Min_def hom_fold1_commute) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3124 | qed | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3125 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3126 | lemma hom_Max_commute: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3127 | assumes "\<And>x y. h (max x y) = max (h x) (h y)" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3128 |     and "finite N" and "N \<noteq> {}"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3129 | shows "h (Max N) = Max (h ` N)" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3130 | proof - | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 3131 | interpret ab_semigroup_idem_mult max | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3132 | by (rule ab_semigroup_idem_mult_max) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3133 | from assms show ?thesis | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3134 | by (simp add: Max_def hom_fold1_commute [of h]) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3135 | qed | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3136 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3137 | lemma Min_le [simp]: | 
| 26757 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 3138 | assumes "finite A" and "x \<in> A" | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3139 | shows "Min A \<le> x" | 
| 32203 
992ac8942691
adapted to localized interpretation of min/max-lattice
 haftmann parents: 
32075diff
changeset | 3140 | using assms by (simp add: Min_def min_max.fold1_belowI) | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3141 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3142 | lemma Max_ge [simp]: | 
| 26757 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 3143 | assumes "finite A" and "x \<in> A" | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3144 | shows "x \<le> Max A" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3145 | proof - | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 3146 | interpret lower_semilattice "op \<ge>" "op >" max | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3147 | by (rule max_lattice) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3148 | from assms show ?thesis by (simp add: Max_def fold1_belowI) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3149 | qed | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3150 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3151 | lemma Min_ge_iff [simp, noatp]: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3152 |   assumes "finite A" and "A \<noteq> {}"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3153 | shows "x \<le> Min A \<longleftrightarrow> (\<forall>a\<in>A. x \<le> a)" | 
| 32203 
992ac8942691
adapted to localized interpretation of min/max-lattice
 haftmann parents: 
32075diff
changeset | 3154 | using assms by (simp add: Min_def min_max.below_fold1_iff) | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3155 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3156 | lemma Max_le_iff [simp, noatp]: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3157 |   assumes "finite A" and "A \<noteq> {}"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3158 | shows "Max A \<le> x \<longleftrightarrow> (\<forall>a\<in>A. a \<le> x)" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3159 | proof - | 
| 29509 
1ff0f3f08a7b
migrated class package to new locale implementation
 haftmann parents: 
29223diff
changeset | 3160 | interpret lower_semilattice "op \<ge>" "op >" max | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3161 | by (rule max_lattice) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3162 | from assms show ?thesis by (simp add: Max_def below_fold1_iff) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3163 | qed | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3164 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3165 | lemma Min_gr_iff [simp, noatp]: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3166 |   assumes "finite A" and "A \<noteq> {}"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3167 | shows "x < Min A \<longleftrightarrow> (\<forall>a\<in>A. x < a)" | 
| 32203 
992ac8942691
adapted to localized interpretation of min/max-lattice
 haftmann parents: 
32075diff
changeset | 3168 | using assms by (simp add: Min_def strict_below_fold1_iff) | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3169 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3170 | lemma Max_less_iff [simp, noatp]: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3171 |   assumes "finite A" and "A \<noteq> {}"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3172 | shows "Max A < x \<longleftrightarrow> (\<forall>a\<in>A. a < x)" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3173 | proof - | 
| 32203 
992ac8942691
adapted to localized interpretation of min/max-lattice
 haftmann parents: 
32075diff
changeset | 3174 | interpret dual: linorder "op \<ge>" "op >" | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3175 | by (rule dual_linorder) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3176 | from assms show ?thesis | 
| 32203 
992ac8942691
adapted to localized interpretation of min/max-lattice
 haftmann parents: 
32075diff
changeset | 3177 | by (simp add: Max_def dual.strict_below_fold1_iff [folded dual.dual_max]) | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3178 | qed | 
| 18493 | 3179 | |
| 24286 
7619080e49f0
ATP blacklisting is now in theory data, attribute noatp
 paulson parents: 
24268diff
changeset | 3180 | lemma Min_le_iff [noatp]: | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3181 |   assumes "finite A" and "A \<noteq> {}"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3182 | shows "Min A \<le> x \<longleftrightarrow> (\<exists>a\<in>A. a \<le> x)" | 
| 32203 
992ac8942691
adapted to localized interpretation of min/max-lattice
 haftmann parents: 
32075diff
changeset | 3183 | using assms by (simp add: Min_def fold1_below_iff) | 
| 15497 
53bca254719a
Added semi-lattice locales and reorganized fold1 lemmas
 nipkow parents: 
15487diff
changeset | 3184 | |
| 24286 
7619080e49f0
ATP blacklisting is now in theory data, attribute noatp
 paulson parents: 
24268diff
changeset | 3185 | lemma Max_ge_iff [noatp]: | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3186 |   assumes "finite A" and "A \<noteq> {}"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3187 | shows "x \<le> Max A \<longleftrightarrow> (\<exists>a\<in>A. x \<le> a)" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3188 | proof - | 
| 32203 
992ac8942691
adapted to localized interpretation of min/max-lattice
 haftmann parents: 
32075diff
changeset | 3189 | interpret dual: linorder "op \<ge>" "op >" | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3190 | by (rule dual_linorder) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3191 | from assms show ?thesis | 
| 32203 
992ac8942691
adapted to localized interpretation of min/max-lattice
 haftmann parents: 
32075diff
changeset | 3192 | by (simp add: Max_def dual.fold1_below_iff [folded dual.dual_max]) | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3193 | qed | 
| 22917 | 3194 | |
| 24286 
7619080e49f0
ATP blacklisting is now in theory data, attribute noatp
 paulson parents: 
24268diff
changeset | 3195 | lemma Min_less_iff [noatp]: | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3196 |   assumes "finite A" and "A \<noteq> {}"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3197 | shows "Min A < x \<longleftrightarrow> (\<exists>a\<in>A. a < x)" | 
| 32203 
992ac8942691
adapted to localized interpretation of min/max-lattice
 haftmann parents: 
32075diff
changeset | 3198 | using assms by (simp add: Min_def fold1_strict_below_iff) | 
| 22917 | 3199 | |
| 24286 
7619080e49f0
ATP blacklisting is now in theory data, attribute noatp
 paulson parents: 
24268diff
changeset | 3200 | lemma Max_gr_iff [noatp]: | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3201 |   assumes "finite A" and "A \<noteq> {}"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3202 | shows "x < Max A \<longleftrightarrow> (\<exists>a\<in>A. x < a)" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3203 | proof - | 
| 32203 
992ac8942691
adapted to localized interpretation of min/max-lattice
 haftmann parents: 
32075diff
changeset | 3204 | interpret dual: linorder "op \<ge>" "op >" | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3205 | by (rule dual_linorder) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3206 | from assms show ?thesis | 
| 32203 
992ac8942691
adapted to localized interpretation of min/max-lattice
 haftmann parents: 
32075diff
changeset | 3207 | by (simp add: Max_def dual.fold1_strict_below_iff [folded dual.dual_max]) | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3208 | qed | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3209 | |
| 30325 | 3210 | lemma Min_eqI: | 
| 3211 | assumes "finite A" | |
| 3212 | assumes "\<And>y. y \<in> A \<Longrightarrow> y \<ge> x" | |
| 3213 | and "x \<in> A" | |
| 3214 | shows "Min A = x" | |
| 3215 | proof (rule antisym) | |
| 3216 |   from `x \<in> A` have "A \<noteq> {}" by auto
 | |
| 3217 | with assms show "Min A \<ge> x" by simp | |
| 3218 | next | |
| 3219 | from assms show "x \<ge> Min A" by simp | |
| 3220 | qed | |
| 3221 | ||
| 3222 | lemma Max_eqI: | |
| 3223 | assumes "finite A" | |
| 3224 | assumes "\<And>y. y \<in> A \<Longrightarrow> y \<le> x" | |
| 3225 | and "x \<in> A" | |
| 3226 | shows "Max A = x" | |
| 3227 | proof (rule antisym) | |
| 3228 |   from `x \<in> A` have "A \<noteq> {}" by auto
 | |
| 3229 | with assms show "Max A \<le> x" by simp | |
| 3230 | next | |
| 3231 | from assms show "x \<le> Max A" by simp | |
| 3232 | qed | |
| 3233 | ||
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3234 | lemma Min_antimono: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3235 |   assumes "M \<subseteq> N" and "M \<noteq> {}" and "finite N"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3236 | shows "Min N \<le> Min M" | 
| 32203 
992ac8942691
adapted to localized interpretation of min/max-lattice
 haftmann parents: 
32075diff
changeset | 3237 | using assms by (simp add: Min_def fold1_antimono) | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3238 | |
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3239 | lemma Max_mono: | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3240 |   assumes "M \<subseteq> N" and "M \<noteq> {}" and "finite N"
 | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3241 | shows "Max M \<le> Max N" | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3242 | proof - | 
| 32203 
992ac8942691
adapted to localized interpretation of min/max-lattice
 haftmann parents: 
32075diff
changeset | 3243 | interpret dual: linorder "op \<ge>" "op >" | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3244 | by (rule dual_linorder) | 
| 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3245 | from assms show ?thesis | 
| 32203 
992ac8942691
adapted to localized interpretation of min/max-lattice
 haftmann parents: 
32075diff
changeset | 3246 | by (simp add: Max_def dual.fold1_antimono [folded dual.dual_max]) | 
| 26041 
c2e15e65165f
locales ACf, ACIf, ACIfSL and ACIfSLlin have been abandoned in favour of the existing algebraic classes ab_semigroup_mult, ab_semigroup_idem_mult, lower_semilattice (resp. uper_semilattice) and linorder
 haftmann parents: 
25571diff
changeset | 3247 | qed | 
| 22917 | 3248 | |
| 32006 | 3249 | lemma finite_linorder_max_induct[consumes 1, case_names empty insert]: | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
26465diff
changeset | 3250 |  "finite A \<Longrightarrow> P {} \<Longrightarrow>
 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
26465diff
changeset | 3251 | (!!A b. finite A \<Longrightarrow> ALL a:A. a < b \<Longrightarrow> P A \<Longrightarrow> P(insert b A)) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
26465diff
changeset | 3252 | \<Longrightarrow> P A" | 
| 32006 | 3253 | proof (induct rule: finite_psubset_induct) | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
26465diff
changeset | 3254 | fix A :: "'a set" | 
| 32006 | 3255 |   assume IH: "!! B. finite B \<Longrightarrow> B < A \<Longrightarrow> P {} \<Longrightarrow>
 | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
26465diff
changeset | 3256 | (!!A b. finite A \<Longrightarrow> (\<forall>a\<in>A. a<b) \<Longrightarrow> P A \<Longrightarrow> P (insert b A)) | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
26465diff
changeset | 3257 | \<Longrightarrow> P B" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
26465diff
changeset | 3258 |   and "finite A" and "P {}"
 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
26465diff
changeset | 3259 | and step: "!!A b. \<lbrakk>finite A; \<forall>a\<in>A. a < b; P A\<rbrakk> \<Longrightarrow> P (insert b A)" | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
26465diff
changeset | 3260 | show "P A" | 
| 26757 
e775accff967
thms Max_ge, Min_le: dropped superfluous premise
 haftmann parents: 
26748diff
changeset | 3261 |   proof (cases "A = {}")
 | 
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
26465diff
changeset | 3262 |     assume "A = {}" thus "P A" using `P {}` by simp
 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
26465diff
changeset | 3263 | next | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
26465diff
changeset | 3264 |     let ?B = "A - {Max A}" let ?A = "insert (Max A) ?B"
 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
26465diff
changeset | 3265 |     assume "A \<noteq> {}"
 | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
26465diff
changeset | 3266 | with `finite A` have "Max A : A" by auto | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
26465diff
changeset | 3267 | hence A: "?A = A" using insert_Diff_single insert_absorb by auto | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
26465diff
changeset | 3268 | moreover have "finite ?B" using `finite A` by simp | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
26465diff
changeset | 3269 |     ultimately have "P ?B" using `P {}` step IH by blast
 | 
| 32006 | 3270 | moreover have "\<forall>a\<in>?B. a < Max A" using Max_ge [OF `finite A`] by fastsimp | 
| 3271 | ultimately show "P A" using A insert_Diff_single step[OF `finite ?B`] by fastsimp | |
| 26748 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
26465diff
changeset | 3272 | qed | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
26465diff
changeset | 3273 | qed | 
| 
4d51ddd6aa5c
Merged theories about wellfoundedness into one: Wellfounded.thy
 krauss parents: 
26465diff
changeset | 3274 | |
| 32006 | 3275 | lemma finite_linorder_min_induct[consumes 1, case_names empty insert]: | 
| 3276 |   "\<lbrakk>finite A; P {}; \<And>A b. \<lbrakk>finite A; \<forall>a\<in>A. b < a; P A\<rbrakk> \<Longrightarrow> P (insert b A)\<rbrakk> \<Longrightarrow> P A"
 | |
| 3277 | by(rule linorder.finite_linorder_max_induct[OF dual_linorder]) | |
| 3278 | ||
| 22917 | 3279 | end | 
| 3280 | ||
| 24380 
c215e256beca
moved ordered_ab_semigroup_add to OrderedGroup.thy
 haftmann parents: 
24342diff
changeset | 3281 | context ordered_ab_semigroup_add | 
| 22917 | 3282 | begin | 
| 3283 | ||
| 3284 | lemma add_Min_commute: | |
| 3285 | fixes k | |
| 25062 | 3286 |   assumes "finite N" and "N \<noteq> {}"
 | 
| 3287 |   shows "k + Min N = Min {k + m | m. m \<in> N}"
 | |
| 3288 | proof - | |
| 3289 | have "\<And>x y. k + min x y = min (k + x) (k + y)" | |
| 3290 | by (simp add: min_def not_le) | |
| 3291 | (blast intro: antisym less_imp_le add_left_mono) | |
| 3292 | with assms show ?thesis | |
| 3293 | using hom_Min_commute [of "plus k" N] | |
| 3294 | by simp (blast intro: arg_cong [where f = Min]) | |
| 3295 | qed | |
| 22917 | 3296 | |
| 3297 | lemma add_Max_commute: | |
| 3298 | fixes k | |
| 25062 | 3299 |   assumes "finite N" and "N \<noteq> {}"
 | 
| 3300 |   shows "k + Max N = Max {k + m | m. m \<in> N}"
 | |
| 3301 | proof - | |
| 3302 | have "\<And>x y. k + max x y = max (k + x) (k + y)" | |
| 3303 | by (simp add: max_def not_le) | |
| 3304 | (blast intro: antisym less_imp_le add_left_mono) | |
| 3305 | with assms show ?thesis | |
| 3306 | using hom_Max_commute [of "plus k" N] | |
| 3307 | by simp (blast intro: arg_cong [where f = Max]) | |
| 3308 | qed | |
| 22917 | 3309 | |
| 3310 | end | |
| 3311 | ||
| 31453 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3312 | |
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3313 | subsection {* Expressing set operations via @{const fold} *}
 | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3314 | |
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3315 | lemma (in fun_left_comm) fun_left_comm_apply: | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3316 | "fun_left_comm (\<lambda>x. f (g x))" | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3317 | proof | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3318 | qed (simp_all add: fun_left_comm) | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3319 | |
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3320 | lemma (in fun_left_comm_idem) fun_left_comm_idem_apply: | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3321 | "fun_left_comm_idem (\<lambda>x. f (g x))" | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3322 | by (rule fun_left_comm_idem.intro, rule fun_left_comm_apply, unfold_locales) | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3323 | (simp_all add: fun_left_idem) | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3324 | |
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3325 | lemma fun_left_comm_idem_insert: | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3326 | "fun_left_comm_idem insert" | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3327 | proof | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3328 | qed auto | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3329 | |
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3330 | lemma fun_left_comm_idem_remove: | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3331 |   "fun_left_comm_idem (\<lambda>x A. A - {x})"
 | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3332 | proof | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3333 | qed auto | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3334 | |
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3335 | lemma fun_left_comm_idem_inter: | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3336 | "fun_left_comm_idem op \<inter>" | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3337 | proof | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3338 | qed auto | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3339 | |
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3340 | lemma fun_left_comm_idem_union: | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3341 | "fun_left_comm_idem op \<union>" | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3342 | proof | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3343 | qed auto | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3344 | |
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3345 | lemma union_fold_insert: | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3346 | assumes "finite A" | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3347 | shows "A \<union> B = fold insert B A" | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3348 | proof - | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3349 | interpret fun_left_comm_idem insert by (fact fun_left_comm_idem_insert) | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3350 | from `finite A` show ?thesis by (induct A arbitrary: B) simp_all | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3351 | qed | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3352 | |
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3353 | lemma minus_fold_remove: | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3354 | assumes "finite A" | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3355 |   shows "B - A = fold (\<lambda>x A. A - {x}) B A"
 | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3356 | proof - | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3357 |   interpret fun_left_comm_idem "\<lambda>x A. A - {x}" by (fact fun_left_comm_idem_remove)
 | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3358 | from `finite A` show ?thesis by (induct A arbitrary: B) auto | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3359 | qed | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3360 | |
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3361 | lemma inter_Inter_fold_inter: | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3362 | assumes "finite A" | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3363 | shows "B \<inter> Inter A = fold (op \<inter>) B A" | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3364 | proof - | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3365 | interpret fun_left_comm_idem "op \<inter>" by (fact fun_left_comm_idem_inter) | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3366 | from `finite A` show ?thesis by (induct A arbitrary: B) | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3367 | (simp_all add: fold_fun_comm Int_commute) | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3368 | qed | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3369 | |
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3370 | lemma union_Union_fold_union: | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3371 | assumes "finite A" | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3372 | shows "B \<union> Union A = fold (op \<union>) B A" | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3373 | proof - | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3374 | interpret fun_left_comm_idem "op \<union>" by (fact fun_left_comm_idem_union) | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3375 | from `finite A` show ?thesis by (induct A arbitrary: B) | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3376 | (simp_all add: fold_fun_comm Un_commute) | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3377 | qed | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3378 | |
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3379 | lemma Inter_fold_inter: | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3380 | assumes "finite A" | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3381 | shows "Inter A = fold (op \<inter>) UNIV A" | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3382 | using assms inter_Inter_fold_inter [of A UNIV] by simp | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3383 | |
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3384 | lemma Union_fold_union: | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3385 | assumes "finite A" | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3386 |   shows "Union A = fold (op \<union>) {} A"
 | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3387 |   using assms union_Union_fold_union [of A "{}"] by simp
 | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3388 | |
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3389 | lemma inter_INTER_fold_inter: | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3390 | assumes "finite A" | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3391 | shows "B \<inter> INTER A f = fold (\<lambda>A. op \<inter> (f A)) B A" (is "?inter = ?fold") | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3392 | proof (rule sym) | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3393 | interpret fun_left_comm_idem "op \<inter>" by (fact fun_left_comm_idem_inter) | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3394 | interpret fun_left_comm_idem "\<lambda>A. op \<inter> (f A)" by (fact fun_left_comm_idem_apply) | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3395 | from `finite A` show "?fold = ?inter" by (induct A arbitrary: B) auto | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3396 | qed | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3397 | |
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3398 | lemma union_UNION_fold_union: | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3399 | assumes "finite A" | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3400 | shows "B \<union> UNION A f = fold (\<lambda>A. op \<union> (f A)) B A" (is "?union = ?fold") | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3401 | proof (rule sym) | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3402 | interpret fun_left_comm_idem "op \<union>" by (fact fun_left_comm_idem_union) | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3403 | interpret fun_left_comm_idem "\<lambda>A. op \<union> (f A)" by (fact fun_left_comm_idem_apply) | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3404 | from `finite A` show "?fold = ?union" by (induct A arbitrary: B) auto | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3405 | qed | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3406 | |
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3407 | lemma INTER_fold_inter: | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3408 | assumes "finite A" | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3409 | shows "INTER A f = fold (\<lambda>A. op \<inter> (f A)) UNIV A" | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3410 | using assms inter_INTER_fold_inter [of A UNIV] by simp | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3411 | |
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3412 | lemma UNION_fold_union: | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3413 | assumes "finite A" | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3414 |   shows "UNION A f = fold (\<lambda>A. op \<union> (f A)) {} A"
 | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3415 |   using assms union_UNION_fold_union [of A "{}"] by simp
 | 
| 
78280bd2860a
lemmas about basic set operations and Finite_Set.fold
 haftmann parents: 
31438diff
changeset | 3416 | |
| 25571 
c9e39eafc7a0
instantiation target rather than legacy instance
 haftmann parents: 
25502diff
changeset | 3417 | end |