src/HOL/Big_Operators.thy
 author haftmann Fri Jun 11 17:14:02 2010 +0200 (2010-06-11) changeset 37407 61dd8c145da7 parent 36977 71c8973a604b child 39198 f967a16dfcdd permissions -rw-r--r--
declare lex_prod_def [code del]
 haftmann@35719 ` 1` ```(* Title: HOL/Big_Operators.thy ``` wenzelm@12396 ` 2` ``` Author: Tobias Nipkow, Lawrence C Paulson and Markus Wenzel ``` avigad@16775 ` 3` ``` with contributions by Jeremy Avigad ``` wenzelm@12396 ` 4` ```*) ``` wenzelm@12396 ` 5` haftmann@35719 ` 6` ```header {* Big operators and finite (non-empty) sets *} ``` haftmann@26041 ` 7` haftmann@35719 ` 8` ```theory Big_Operators ``` haftmann@35722 ` 9` ```imports Plain ``` haftmann@26041 ` 10` ```begin ``` haftmann@26041 ` 11` haftmann@35816 ` 12` ```subsection {* Generic monoid operation over a set *} ``` haftmann@35816 ` 13` haftmann@35816 ` 14` ```no_notation times (infixl "*" 70) ``` haftmann@35816 ` 15` ```no_notation Groups.one ("1") ``` haftmann@35816 ` 16` haftmann@35816 ` 17` ```locale comm_monoid_big = comm_monoid + ``` haftmann@35816 ` 18` ``` fixes F :: "('b \ 'a) \ 'b set \ 'a" ``` haftmann@35816 ` 19` ``` assumes F_eq: "F g A = (if finite A then fold_image (op *) g 1 A else 1)" ``` haftmann@35816 ` 20` haftmann@35816 ` 21` ```sublocale comm_monoid_big < folding_image proof ``` haftmann@35816 ` 22` ```qed (simp add: F_eq) ``` haftmann@35816 ` 23` haftmann@35816 ` 24` ```context comm_monoid_big ``` haftmann@35816 ` 25` ```begin ``` haftmann@35816 ` 26` haftmann@35816 ` 27` ```lemma infinite [simp]: ``` haftmann@35816 ` 28` ``` "\ finite A \ F g A = 1" ``` haftmann@35816 ` 29` ``` by (simp add: F_eq) ``` haftmann@35816 ` 30` haftmann@35816 ` 31` ```end ``` haftmann@35816 ` 32` haftmann@35816 ` 33` ```text {* for ad-hoc proofs for @{const fold_image} *} ``` haftmann@35816 ` 34` haftmann@35816 ` 35` ```lemma (in comm_monoid_add) comm_monoid_mult: ``` haftmann@36635 ` 36` ``` "class.comm_monoid_mult (op +) 0" ``` haftmann@35816 ` 37` ```proof qed (auto intro: add_assoc add_commute) ``` haftmann@35816 ` 38` haftmann@35816 ` 39` ```notation times (infixl "*" 70) ``` haftmann@35816 ` 40` ```notation Groups.one ("1") ``` haftmann@35816 ` 41` haftmann@35816 ` 42` nipkow@15402 ` 43` ```subsection {* Generalized summation over a set *} ``` nipkow@15402 ` 44` haftmann@35816 ` 45` ```definition (in comm_monoid_add) setsum :: "('b \ 'a) => 'b set => 'a" where ``` haftmann@35816 ` 46` ``` "setsum f A = (if finite A then fold_image (op +) f 0 A else 0)" ``` haftmann@26041 ` 47` haftmann@35816 ` 48` ```sublocale comm_monoid_add < setsum!: comm_monoid_big "op +" 0 setsum proof ``` haftmann@35816 ` 49` ```qed (fact setsum_def) ``` nipkow@15402 ` 50` wenzelm@19535 ` 51` ```abbreviation ``` wenzelm@21404 ` 52` ``` Setsum ("\_" [1000] 999) where ``` wenzelm@19535 ` 53` ``` "\A == setsum (%x. x) A" ``` wenzelm@19535 ` 54` nipkow@15402 ` 55` ```text{* Now: lot's of fancy syntax. First, @{term "setsum (%x. e) A"} is ``` nipkow@15402 ` 56` ```written @{text"\x\A. e"}. *} ``` nipkow@15402 ` 57` nipkow@15402 ` 58` ```syntax ``` paulson@17189 ` 59` ``` "_setsum" :: "pttrn => 'a set => 'b => 'b::comm_monoid_add" ("(3SUM _:_. _)" [0, 51, 10] 10) ``` nipkow@15402 ` 60` ```syntax (xsymbols) ``` paulson@17189 ` 61` ``` "_setsum" :: "pttrn => 'a set => 'b => 'b::comm_monoid_add" ("(3\_\_. _)" [0, 51, 10] 10) ``` nipkow@15402 ` 62` ```syntax (HTML output) ``` paulson@17189 ` 63` ``` "_setsum" :: "pttrn => 'a set => 'b => 'b::comm_monoid_add" ("(3\_\_. _)" [0, 51, 10] 10) ``` nipkow@15402 ` 64` nipkow@15402 ` 65` ```translations -- {* Beware of argument permutation! *} ``` nipkow@28853 ` 66` ``` "SUM i:A. b" == "CONST setsum (%i. b) A" ``` nipkow@28853 ` 67` ``` "\i\A. b" == "CONST setsum (%i. b) A" ``` nipkow@15402 ` 68` nipkow@15402 ` 69` ```text{* Instead of @{term"\x\{x. P}. e"} we introduce the shorter ``` nipkow@15402 ` 70` ``` @{text"\x|P. e"}. *} ``` nipkow@15402 ` 71` nipkow@15402 ` 72` ```syntax ``` paulson@17189 ` 73` ``` "_qsetsum" :: "pttrn \ bool \ 'a \ 'a" ("(3SUM _ |/ _./ _)" [0,0,10] 10) ``` nipkow@15402 ` 74` ```syntax (xsymbols) ``` paulson@17189 ` 75` ``` "_qsetsum" :: "pttrn \ bool \ 'a \ 'a" ("(3\_ | (_)./ _)" [0,0,10] 10) ``` nipkow@15402 ` 76` ```syntax (HTML output) ``` paulson@17189 ` 77` ``` "_qsetsum" :: "pttrn \ bool \ 'a \ 'a" ("(3\_ | (_)./ _)" [0,0,10] 10) ``` nipkow@15402 ` 78` nipkow@15402 ` 79` ```translations ``` nipkow@28853 ` 80` ``` "SUM x|P. t" => "CONST setsum (%x. t) {x. P}" ``` nipkow@28853 ` 81` ``` "\x|P. t" => "CONST setsum (%x. t) {x. P}" ``` nipkow@15402 ` 82` nipkow@15402 ` 83` ```print_translation {* ``` nipkow@15402 ` 84` ```let ``` wenzelm@35115 ` 85` ``` fun setsum_tr' [Abs (x, Tx, t), Const (@{const_syntax Collect}, _) \$ Abs (y, Ty, P)] = ``` wenzelm@35115 ` 86` ``` if x <> y then raise Match ``` wenzelm@35115 ` 87` ``` else ``` wenzelm@35115 ` 88` ``` let ``` wenzelm@35115 ` 89` ``` val x' = Syntax.mark_bound x; ``` wenzelm@35115 ` 90` ``` val t' = subst_bound (x', t); ``` wenzelm@35115 ` 91` ``` val P' = subst_bound (x', P); ``` wenzelm@35115 ` 92` ``` in Syntax.const @{syntax_const "_qsetsum"} \$ Syntax.mark_bound x \$ P' \$ t' end ``` wenzelm@35115 ` 93` ``` | setsum_tr' _ = raise Match; ``` wenzelm@35115 ` 94` ```in [(@{const_syntax setsum}, setsum_tr')] end ``` nipkow@15402 ` 95` ```*} ``` nipkow@15402 ` 96` haftmann@35816 ` 97` ```lemma setsum_empty: ``` haftmann@35816 ` 98` ``` "setsum f {} = 0" ``` haftmann@35816 ` 99` ``` by (fact setsum.empty) ``` nipkow@15402 ` 100` haftmann@35816 ` 101` ```lemma setsum_insert: ``` nipkow@28853 ` 102` ``` "finite F ==> a \ F ==> setsum f (insert a F) = f a + setsum f F" ``` haftmann@35816 ` 103` ``` by (fact setsum.insert) ``` haftmann@35816 ` 104` haftmann@35816 ` 105` ```lemma setsum_infinite: ``` haftmann@35816 ` 106` ``` "~ finite A ==> setsum f A = 0" ``` haftmann@35816 ` 107` ``` by (fact setsum.infinite) ``` nipkow@15402 ` 108` haftmann@35816 ` 109` ```lemma (in comm_monoid_add) setsum_reindex: ``` haftmann@35816 ` 110` ``` assumes "inj_on f B" shows "setsum h (f ` B) = setsum (h \ f) B" ``` haftmann@35816 ` 111` ```proof - ``` haftmann@35816 ` 112` ``` interpret comm_monoid_mult "op +" 0 by (fact comm_monoid_mult) ``` haftmann@35816 ` 113` ``` from assms show ?thesis by (auto simp add: setsum_def fold_image_reindex dest!:finite_imageD) ``` haftmann@35816 ` 114` ```qed ``` paulson@15409 ` 115` haftmann@35816 ` 116` ```lemma (in comm_monoid_add) setsum_reindex_id: ``` haftmann@35816 ` 117` ``` "inj_on f B ==> setsum f B = setsum id (f ` B)" ``` haftmann@35816 ` 118` ``` by (simp add: setsum_reindex) ``` nipkow@15402 ` 119` haftmann@35816 ` 120` ```lemma (in comm_monoid_add) setsum_reindex_nonzero: ``` chaieb@29674 ` 121` ``` assumes fS: "finite S" ``` chaieb@29674 ` 122` ``` and nz: "\ x y. x \ S \ y \ S \ x \ y \ f x = f y \ h (f x) = 0" ``` chaieb@29674 ` 123` ``` shows "setsum h (f ` S) = setsum (h o f) S" ``` chaieb@29674 ` 124` ```using nz ``` chaieb@29674 ` 125` ```proof(induct rule: finite_induct[OF fS]) ``` chaieb@29674 ` 126` ``` case 1 thus ?case by simp ``` chaieb@29674 ` 127` ```next ``` chaieb@29674 ` 128` ``` case (2 x F) ``` chaieb@29674 ` 129` ``` {assume fxF: "f x \ f ` F" hence "\y \ F . f y = f x" by auto ``` chaieb@29674 ` 130` ``` then obtain y where y: "y \ F" "f x = f y" by auto ``` chaieb@29674 ` 131` ``` from "2.hyps" y have xy: "x \ y" by auto ``` chaieb@29674 ` 132` ``` ``` chaieb@29674 ` 133` ``` from "2.prems"[of x y] "2.hyps" xy y have h0: "h (f x) = 0" by simp ``` chaieb@29674 ` 134` ``` have "setsum h (f ` insert x F) = setsum h (f ` F)" using fxF by auto ``` chaieb@29674 ` 135` ``` also have "\ = setsum (h o f) (insert x F)" ``` haftmann@35816 ` 136` ``` unfolding setsum.insert[OF `finite F` `x\F`] ``` haftmann@35816 ` 137` ``` using h0 ``` chaieb@29674 ` 138` ``` apply simp ``` chaieb@29674 ` 139` ``` apply (rule "2.hyps"(3)) ``` chaieb@29674 ` 140` ``` apply (rule_tac y="y" in "2.prems") ``` chaieb@29674 ` 141` ``` apply simp_all ``` chaieb@29674 ` 142` ``` done ``` chaieb@29674 ` 143` ``` finally have ?case .} ``` chaieb@29674 ` 144` ``` moreover ``` chaieb@29674 ` 145` ``` {assume fxF: "f x \ f ` F" ``` chaieb@29674 ` 146` ``` have "setsum h (f ` insert x F) = h (f x) + setsum h (f ` F)" ``` chaieb@29674 ` 147` ``` using fxF "2.hyps" by simp ``` chaieb@29674 ` 148` ``` also have "\ = setsum (h o f) (insert x F)" ``` haftmann@35816 ` 149` ``` unfolding setsum.insert[OF `finite F` `x\F`] ``` chaieb@29674 ` 150` ``` apply simp ``` haftmann@35816 ` 151` ``` apply (rule cong [OF refl [of "op + (h (f x))"]]) ``` chaieb@29674 ` 152` ``` apply (rule "2.hyps"(3)) ``` chaieb@29674 ` 153` ``` apply (rule_tac y="y" in "2.prems") ``` chaieb@29674 ` 154` ``` apply simp_all ``` chaieb@29674 ` 155` ``` done ``` chaieb@29674 ` 156` ``` finally have ?case .} ``` chaieb@29674 ` 157` ``` ultimately show ?case by blast ``` chaieb@29674 ` 158` ```qed ``` chaieb@29674 ` 159` haftmann@35816 ` 160` ```lemma (in comm_monoid_add) setsum_cong: ``` nipkow@15402 ` 161` ``` "A = B ==> (!!x. x:B ==> f x = g x) ==> setsum f A = setsum g B" ``` haftmann@35816 ` 162` ``` by (cases "finite A") (auto intro: setsum.cong) ``` nipkow@15402 ` 163` haftmann@35816 ` 164` ```lemma (in comm_monoid_add) strong_setsum_cong [cong]: ``` nipkow@16733 ` 165` ``` "A = B ==> (!!x. x:B =simp=> f x = g x) ``` nipkow@16733 ` 166` ``` ==> setsum (%x. f x) A = setsum (%x. g x) B" ``` haftmann@35816 ` 167` ``` by (rule setsum_cong) (simp_all add: simp_implies_def) ``` berghofe@16632 ` 168` haftmann@35816 ` 169` ```lemma (in comm_monoid_add) setsum_cong2: "\\x. x \ A \ f x = g x\ \ setsum f A = setsum g A" ``` haftmann@35816 ` 170` ``` by (auto intro: setsum_cong) ``` nipkow@15554 ` 171` haftmann@35816 ` 172` ```lemma (in comm_monoid_add) setsum_reindex_cong: ``` nipkow@28853 ` 173` ``` "[|inj_on f A; B = f ` A; !!a. a:A \ g a = h (f a)|] ``` nipkow@28853 ` 174` ``` ==> setsum h B = setsum g A" ``` haftmann@35816 ` 175` ``` by (simp add: setsum_reindex cong: setsum_cong) ``` nipkow@15402 ` 176` haftmann@35816 ` 177` ```lemma (in comm_monoid_add) setsum_0[simp]: "setsum (%i. 0) A = 0" ``` haftmann@35816 ` 178` ``` by (cases "finite A") (erule finite_induct, auto) ``` chaieb@29674 ` 179` haftmann@35816 ` 180` ```lemma (in comm_monoid_add) setsum_0': "ALL a:A. f a = 0 ==> setsum f A = 0" ``` haftmann@35816 ` 181` ``` by (simp add:setsum_cong) ``` nipkow@15402 ` 182` haftmann@35816 ` 183` ```lemma (in comm_monoid_add) setsum_Un_Int: "finite A ==> finite B ==> ``` nipkow@15402 ` 184` ``` setsum g (A Un B) + setsum g (A Int B) = setsum g A + setsum g B" ``` nipkow@15402 ` 185` ``` -- {* The reversed orientation looks more natural, but LOOPS as a simprule! *} ``` haftmann@35816 ` 186` ``` by (fact setsum.union_inter) ``` nipkow@15402 ` 187` haftmann@35816 ` 188` ```lemma (in comm_monoid_add) setsum_Un_disjoint: "finite A ==> finite B ``` nipkow@15402 ` 189` ``` ==> A Int B = {} ==> setsum g (A Un B) = setsum g A + setsum g B" ``` haftmann@35816 ` 190` ``` by (fact setsum.union_disjoint) ``` nipkow@15402 ` 191` chaieb@29674 ` 192` ```lemma setsum_mono_zero_left: ``` chaieb@29674 ` 193` ``` assumes fT: "finite T" and ST: "S \ T" ``` chaieb@29674 ` 194` ``` and z: "\i \ T - S. f i = 0" ``` chaieb@29674 ` 195` ``` shows "setsum f S = setsum f T" ``` chaieb@29674 ` 196` ```proof- ``` chaieb@29674 ` 197` ``` have eq: "T = S \ (T - S)" using ST by blast ``` chaieb@29674 ` 198` ``` have d: "S \ (T - S) = {}" using ST by blast ``` chaieb@29674 ` 199` ``` from fT ST have f: "finite S" "finite (T - S)" by (auto intro: finite_subset) ``` chaieb@29674 ` 200` ``` show ?thesis ``` chaieb@29674 ` 201` ``` by (simp add: setsum_Un_disjoint[OF f d, unfolded eq[symmetric]] setsum_0'[OF z]) ``` chaieb@29674 ` 202` ```qed ``` chaieb@29674 ` 203` chaieb@29674 ` 204` ```lemma setsum_mono_zero_right: ``` nipkow@30837 ` 205` ``` "finite T \ S \ T \ \i \ T - S. f i = 0 \ setsum f T = setsum f S" ``` nipkow@30837 ` 206` ```by(blast intro!: setsum_mono_zero_left[symmetric]) ``` chaieb@29674 ` 207` chaieb@29674 ` 208` ```lemma setsum_mono_zero_cong_left: ``` chaieb@29674 ` 209` ``` assumes fT: "finite T" and ST: "S \ T" ``` chaieb@29674 ` 210` ``` and z: "\i \ T - S. g i = 0" ``` chaieb@29674 ` 211` ``` and fg: "\x. x \ S \ f x = g x" ``` chaieb@29674 ` 212` ``` shows "setsum f S = setsum g T" ``` chaieb@29674 ` 213` ```proof- ``` chaieb@29674 ` 214` ``` have eq: "T = S \ (T - S)" using ST by blast ``` chaieb@29674 ` 215` ``` have d: "S \ (T - S) = {}" using ST by blast ``` chaieb@29674 ` 216` ``` from fT ST have f: "finite S" "finite (T - S)" by (auto intro: finite_subset) ``` chaieb@29674 ` 217` ``` show ?thesis ``` chaieb@29674 ` 218` ``` using fg by (simp add: setsum_Un_disjoint[OF f d, unfolded eq[symmetric]] setsum_0'[OF z]) ``` chaieb@29674 ` 219` ```qed ``` chaieb@29674 ` 220` chaieb@29674 ` 221` ```lemma setsum_mono_zero_cong_right: ``` chaieb@29674 ` 222` ``` assumes fT: "finite T" and ST: "S \ T" ``` chaieb@29674 ` 223` ``` and z: "\i \ T - S. f i = 0" ``` chaieb@29674 ` 224` ``` and fg: "\x. x \ S \ f x = g x" ``` chaieb@29674 ` 225` ``` shows "setsum f T = setsum g S" ``` chaieb@29674 ` 226` ```using setsum_mono_zero_cong_left[OF fT ST z] fg[symmetric] by auto ``` chaieb@29674 ` 227` chaieb@29674 ` 228` ```lemma setsum_delta: ``` chaieb@29674 ` 229` ``` assumes fS: "finite S" ``` chaieb@29674 ` 230` ``` shows "setsum (\k. if k=a then b k else 0) S = (if a \ S then b a else 0)" ``` chaieb@29674 ` 231` ```proof- ``` chaieb@29674 ` 232` ``` let ?f = "(\k. if k=a then b k else 0)" ``` chaieb@29674 ` 233` ``` {assume a: "a \ S" ``` chaieb@29674 ` 234` ``` hence "\ k\ S. ?f k = 0" by simp ``` chaieb@29674 ` 235` ``` hence ?thesis using a by simp} ``` chaieb@29674 ` 236` ``` moreover ``` chaieb@29674 ` 237` ``` {assume a: "a \ S" ``` chaieb@29674 ` 238` ``` let ?A = "S - {a}" ``` chaieb@29674 ` 239` ``` let ?B = "{a}" ``` chaieb@29674 ` 240` ``` have eq: "S = ?A \ ?B" using a by blast ``` chaieb@29674 ` 241` ``` have dj: "?A \ ?B = {}" by simp ``` chaieb@29674 ` 242` ``` from fS have fAB: "finite ?A" "finite ?B" by auto ``` chaieb@29674 ` 243` ``` have "setsum ?f S = setsum ?f ?A + setsum ?f ?B" ``` chaieb@29674 ` 244` ``` using setsum_Un_disjoint[OF fAB dj, of ?f, unfolded eq[symmetric]] ``` chaieb@29674 ` 245` ``` by simp ``` chaieb@29674 ` 246` ``` then have ?thesis using a by simp} ``` chaieb@29674 ` 247` ``` ultimately show ?thesis by blast ``` chaieb@29674 ` 248` ```qed ``` chaieb@29674 ` 249` ```lemma setsum_delta': ``` chaieb@29674 ` 250` ``` assumes fS: "finite S" shows ``` chaieb@29674 ` 251` ``` "setsum (\k. if a = k then b k else 0) S = ``` chaieb@29674 ` 252` ``` (if a\ S then b a else 0)" ``` chaieb@29674 ` 253` ``` using setsum_delta[OF fS, of a b, symmetric] ``` chaieb@29674 ` 254` ``` by (auto intro: setsum_cong) ``` chaieb@29674 ` 255` chaieb@30260 ` 256` ```lemma setsum_restrict_set: ``` chaieb@30260 ` 257` ``` assumes fA: "finite A" ``` chaieb@30260 ` 258` ``` shows "setsum f (A \ B) = setsum (\x. if x \ B then f x else 0) A" ``` chaieb@30260 ` 259` ```proof- ``` chaieb@30260 ` 260` ``` from fA have fab: "finite (A \ B)" by auto ``` chaieb@30260 ` 261` ``` have aba: "A \ B \ A" by blast ``` chaieb@30260 ` 262` ``` let ?g = "\x. if x \ A\B then f x else 0" ``` chaieb@30260 ` 263` ``` from setsum_mono_zero_left[OF fA aba, of ?g] ``` chaieb@30260 ` 264` ``` show ?thesis by simp ``` chaieb@30260 ` 265` ```qed ``` chaieb@30260 ` 266` chaieb@30260 ` 267` ```lemma setsum_cases: ``` chaieb@30260 ` 268` ``` assumes fA: "finite A" ``` hoelzl@35577 ` 269` ``` shows "setsum (\x. if P x then f x else g x) A = ``` hoelzl@35577 ` 270` ``` setsum f (A \ {x. P x}) + setsum g (A \ - {x. P x})" ``` chaieb@30260 ` 271` ```proof- ``` hoelzl@35577 ` 272` ``` have a: "A = A \ {x. P x} \ A \ -{x. P x}" ``` hoelzl@35577 ` 273` ``` "(A \ {x. P x}) \ (A \ -{x. P x}) = {}" ``` chaieb@30260 ` 274` ``` by blast+ ``` chaieb@30260 ` 275` ``` from fA ``` hoelzl@35577 ` 276` ``` have f: "finite (A \ {x. P x})" "finite (A \ -{x. P x})" by auto ``` hoelzl@35577 ` 277` ``` let ?g = "\x. if P x then f x else g x" ``` chaieb@30260 ` 278` ``` from setsum_Un_disjoint[OF f a(2), of ?g] a(1) ``` chaieb@30260 ` 279` ``` show ?thesis by simp ``` chaieb@30260 ` 280` ```qed ``` chaieb@30260 ` 281` chaieb@29674 ` 282` paulson@15409 ` 283` ```(*But we can't get rid of finite I. If infinite, although the rhs is 0, ``` paulson@15409 ` 284` ``` the lhs need not be, since UNION I A could still be finite.*) ``` haftmann@35816 ` 285` ```lemma (in comm_monoid_add) setsum_UN_disjoint: ``` haftmann@35816 ` 286` ``` assumes "finite I" and "ALL i:I. finite (A i)" ``` haftmann@35816 ` 287` ``` and "ALL i:I. ALL j:I. i \ j --> A i Int A j = {}" ``` haftmann@35816 ` 288` ``` shows "setsum f (UNION I A) = (\i\I. setsum f (A i))" ``` haftmann@35816 ` 289` ```proof - ``` haftmann@35816 ` 290` ``` interpret comm_monoid_mult "op +" 0 by (fact comm_monoid_mult) ``` haftmann@35816 ` 291` ``` from assms show ?thesis by (simp add: setsum_def fold_image_UN_disjoint cong: setsum_cong) ``` haftmann@35816 ` 292` ```qed ``` nipkow@15402 ` 293` paulson@15409 ` 294` ```text{*No need to assume that @{term C} is finite. If infinite, the rhs is ``` paulson@15409 ` 295` ```directly 0, and @{term "Union C"} is also infinite, hence the lhs is also 0.*} ``` nipkow@15402 ` 296` ```lemma setsum_Union_disjoint: ``` paulson@15409 ` 297` ``` "[| (ALL A:C. finite A); ``` paulson@15409 ` 298` ``` (ALL A:C. ALL B:C. A \ B --> A Int B = {}) |] ``` paulson@15409 ` 299` ``` ==> setsum f (Union C) = setsum (setsum f) C" ``` paulson@15409 ` 300` ```apply (cases "finite C") ``` paulson@15409 ` 301` ``` prefer 2 apply (force dest: finite_UnionD simp add: setsum_def) ``` nipkow@15402 ` 302` ``` apply (frule setsum_UN_disjoint [of C id f]) ``` paulson@15409 ` 303` ``` apply (unfold Union_def id_def, assumption+) ``` paulson@15409 ` 304` ```done ``` nipkow@15402 ` 305` paulson@15409 ` 306` ```(*But we can't get rid of finite A. If infinite, although the lhs is 0, ``` paulson@15409 ` 307` ``` the rhs need not be, since SIGMA A B could still be finite.*) ``` haftmann@35816 ` 308` ```lemma (in comm_monoid_add) setsum_Sigma: ``` haftmann@35816 ` 309` ``` assumes "finite A" and "ALL x:A. finite (B x)" ``` haftmann@35816 ` 310` ``` shows "(\x\A. (\y\B x. f x y)) = (\(x,y)\(SIGMA x:A. B x). f x y)" ``` haftmann@35816 ` 311` ```proof - ``` haftmann@35816 ` 312` ``` interpret comm_monoid_mult "op +" 0 by (fact comm_monoid_mult) ``` haftmann@35816 ` 313` ``` from assms show ?thesis by (simp add: setsum_def fold_image_Sigma split_def cong: setsum_cong) ``` haftmann@35816 ` 314` ```qed ``` nipkow@15402 ` 315` paulson@15409 ` 316` ```text{*Here we can eliminate the finiteness assumptions, by cases.*} ``` paulson@15409 ` 317` ```lemma setsum_cartesian_product: ``` paulson@17189 ` 318` ``` "(\x\A. (\y\B. f x y)) = (\(x,y) \ A <*> B. f x y)" ``` paulson@15409 ` 319` ```apply (cases "finite A") ``` paulson@15409 ` 320` ``` apply (cases "finite B") ``` paulson@15409 ` 321` ``` apply (simp add: setsum_Sigma) ``` paulson@15409 ` 322` ``` apply (cases "A={}", simp) ``` nipkow@15543 ` 323` ``` apply (simp) ``` paulson@15409 ` 324` ```apply (auto simp add: setsum_def ``` paulson@15409 ` 325` ``` dest: finite_cartesian_productD1 finite_cartesian_productD2) ``` paulson@15409 ` 326` ```done ``` nipkow@15402 ` 327` haftmann@35816 ` 328` ```lemma (in comm_monoid_add) setsum_addf: "setsum (%x. f x + g x) A = (setsum f A + setsum g A)" ``` haftmann@35816 ` 329` ``` by (cases "finite A") (simp_all add: setsum.distrib) ``` nipkow@15402 ` 330` nipkow@15402 ` 331` nipkow@15402 ` 332` ```subsubsection {* Properties in more restricted classes of structures *} ``` nipkow@15402 ` 333` nipkow@15402 ` 334` ```lemma setsum_SucD: "setsum f A = Suc n ==> EX a:A. 0 < f a" ``` nipkow@28853 ` 335` ```apply (case_tac "finite A") ``` nipkow@28853 ` 336` ``` prefer 2 apply (simp add: setsum_def) ``` nipkow@28853 ` 337` ```apply (erule rev_mp) ``` nipkow@28853 ` 338` ```apply (erule finite_induct, auto) ``` nipkow@28853 ` 339` ```done ``` nipkow@15402 ` 340` nipkow@15402 ` 341` ```lemma setsum_eq_0_iff [simp]: ``` nipkow@15402 ` 342` ``` "finite F ==> (setsum f F = 0) = (ALL a:F. f a = (0::nat))" ``` nipkow@28853 ` 343` ```by (induct set: finite) auto ``` nipkow@15402 ` 344` nipkow@30859 ` 345` ```lemma setsum_eq_Suc0_iff: "finite A \ ``` nipkow@30859 ` 346` ``` (setsum f A = Suc 0) = (EX a:A. f a = Suc 0 & (ALL b:A. a\b \ f b = 0))" ``` nipkow@30859 ` 347` ```apply(erule finite_induct) ``` nipkow@30859 ` 348` ```apply (auto simp add:add_is_1) ``` nipkow@30859 ` 349` ```done ``` nipkow@30859 ` 350` nipkow@30859 ` 351` ```lemmas setsum_eq_1_iff = setsum_eq_Suc0_iff[simplified One_nat_def[symmetric]] ``` nipkow@30859 ` 352` nipkow@15402 ` 353` ```lemma setsum_Un_nat: "finite A ==> finite B ==> ``` nipkow@28853 ` 354` ``` (setsum f (A Un B) :: nat) = setsum f A + setsum f B - setsum f (A Int B)" ``` nipkow@15402 ` 355` ``` -- {* For the natural numbers, we have subtraction. *} ``` nipkow@29667 ` 356` ```by (subst setsum_Un_Int [symmetric], auto simp add: algebra_simps) ``` nipkow@15402 ` 357` nipkow@15402 ` 358` ```lemma setsum_Un: "finite A ==> finite B ==> ``` nipkow@28853 ` 359` ``` (setsum f (A Un B) :: 'a :: ab_group_add) = ``` nipkow@28853 ` 360` ``` setsum f A + setsum f B - setsum f (A Int B)" ``` nipkow@29667 ` 361` ```by (subst setsum_Un_Int [symmetric], auto simp add: algebra_simps) ``` nipkow@15402 ` 362` haftmann@35816 ` 363` ```lemma (in comm_monoid_add) setsum_eq_general_reverses: ``` chaieb@30260 ` 364` ``` assumes fS: "finite S" and fT: "finite T" ``` chaieb@30260 ` 365` ``` and kh: "\y. y \ T \ k y \ S \ h (k y) = y" ``` chaieb@30260 ` 366` ``` and hk: "\x. x \ S \ h x \ T \ k (h x) = x \ g (h x) = f x" ``` chaieb@30260 ` 367` ``` shows "setsum f S = setsum g T" ``` haftmann@35816 ` 368` ```proof - ``` haftmann@35816 ` 369` ``` interpret comm_monoid_mult "op +" 0 by (fact comm_monoid_mult) ``` haftmann@35816 ` 370` ``` show ?thesis ``` chaieb@30260 ` 371` ``` apply (simp add: setsum_def fS fT) ``` haftmann@35816 ` 372` ``` apply (rule fold_image_eq_general_inverses) ``` haftmann@35816 ` 373` ``` apply (rule fS) ``` chaieb@30260 ` 374` ``` apply (erule kh) ``` chaieb@30260 ` 375` ``` apply (erule hk) ``` chaieb@30260 ` 376` ``` done ``` haftmann@35816 ` 377` ```qed ``` chaieb@30260 ` 378` haftmann@35816 ` 379` ```lemma (in comm_monoid_add) setsum_Un_zero: ``` chaieb@30260 ` 380` ``` assumes fS: "finite S" and fT: "finite T" ``` chaieb@30260 ` 381` ``` and I0: "\x \ S\T. f x = 0" ``` chaieb@30260 ` 382` ``` shows "setsum f (S \ T) = setsum f S + setsum f T" ``` haftmann@35816 ` 383` ```proof - ``` haftmann@35816 ` 384` ``` interpret comm_monoid_mult "op +" 0 by (fact comm_monoid_mult) ``` haftmann@35816 ` 385` ``` show ?thesis ``` chaieb@30260 ` 386` ``` using fS fT ``` chaieb@30260 ` 387` ``` apply (simp add: setsum_def) ``` haftmann@35816 ` 388` ``` apply (rule fold_image_Un_one) ``` chaieb@30260 ` 389` ``` using I0 by auto ``` haftmann@35816 ` 390` ```qed ``` chaieb@30260 ` 391` chaieb@30260 ` 392` ```lemma setsum_UNION_zero: ``` chaieb@30260 ` 393` ``` assumes fS: "finite S" and fSS: "\T \ S. finite T" ``` chaieb@30260 ` 394` ``` and f0: "\T1 T2 x. T1\S \ T2\S \ T1 \ T2 \ x \ T1 \ x \ T2 \ f x = 0" ``` chaieb@30260 ` 395` ``` shows "setsum f (\S) = setsum (\T. setsum f T) S" ``` chaieb@30260 ` 396` ``` using fSS f0 ``` chaieb@30260 ` 397` ```proof(induct rule: finite_induct[OF fS]) ``` chaieb@30260 ` 398` ``` case 1 thus ?case by simp ``` chaieb@30260 ` 399` ```next ``` chaieb@30260 ` 400` ``` case (2 T F) ``` chaieb@30260 ` 401` ``` then have fTF: "finite T" "\T\F. finite T" "finite F" and TF: "T \ F" ``` huffman@35216 ` 402` ``` and H: "setsum f (\ F) = setsum (setsum f) F" by auto ``` huffman@35216 ` 403` ``` from fTF have fUF: "finite (\F)" by auto ``` chaieb@30260 ` 404` ``` from "2.prems" TF fTF ``` chaieb@30260 ` 405` ``` show ?case ``` chaieb@30260 ` 406` ``` by (auto simp add: H[symmetric] intro: setsum_Un_zero[OF fTF(1) fUF, of f]) ``` chaieb@30260 ` 407` ```qed ``` chaieb@30260 ` 408` nipkow@15402 ` 409` ```lemma setsum_diff1_nat: "(setsum f (A - {a}) :: nat) = ``` nipkow@28853 ` 410` ``` (if a:A then setsum f A - f a else setsum f A)" ``` nipkow@28853 ` 411` ```apply (case_tac "finite A") ``` nipkow@28853 ` 412` ``` prefer 2 apply (simp add: setsum_def) ``` nipkow@28853 ` 413` ```apply (erule finite_induct) ``` nipkow@28853 ` 414` ``` apply (auto simp add: insert_Diff_if) ``` nipkow@28853 ` 415` ```apply (drule_tac a = a in mk_disjoint_insert, auto) ``` nipkow@28853 ` 416` ```done ``` nipkow@15402 ` 417` nipkow@15402 ` 418` ```lemma setsum_diff1: "finite A \ ``` nipkow@15402 ` 419` ``` (setsum f (A - {a}) :: ('a::ab_group_add)) = ``` nipkow@15402 ` 420` ``` (if a:A then setsum f A - f a else setsum f A)" ``` nipkow@28853 ` 421` ```by (erule finite_induct) (auto simp add: insert_Diff_if) ``` nipkow@28853 ` 422` nipkow@28853 ` 423` ```lemma setsum_diff1'[rule_format]: ``` nipkow@28853 ` 424` ``` "finite A \ a \ A \ (\ x \ A. f x) = f a + (\ x \ (A - {a}). f x)" ``` nipkow@28853 ` 425` ```apply (erule finite_induct[where F=A and P="% A. (a \ A \ (\ x \ A. f x) = f a + (\ x \ (A - {a}). f x))"]) ``` nipkow@28853 ` 426` ```apply (auto simp add: insert_Diff_if add_ac) ``` nipkow@28853 ` 427` ```done ``` obua@15552 ` 428` nipkow@31438 ` 429` ```lemma setsum_diff1_ring: assumes "finite A" "a \ A" ``` nipkow@31438 ` 430` ``` shows "setsum f (A - {a}) = setsum f A - (f a::'a::ring)" ``` nipkow@31438 ` 431` ```unfolding setsum_diff1'[OF assms] by auto ``` nipkow@31438 ` 432` nipkow@15402 ` 433` ```(* By Jeremy Siek: *) ``` nipkow@15402 ` 434` nipkow@15402 ` 435` ```lemma setsum_diff_nat: ``` nipkow@28853 ` 436` ```assumes "finite B" and "B \ A" ``` nipkow@28853 ` 437` ```shows "(setsum f (A - B) :: nat) = (setsum f A) - (setsum f B)" ``` nipkow@28853 ` 438` ```using assms ``` wenzelm@19535 ` 439` ```proof induct ``` nipkow@15402 ` 440` ``` show "setsum f (A - {}) = (setsum f A) - (setsum f {})" by simp ``` nipkow@15402 ` 441` ```next ``` nipkow@15402 ` 442` ``` fix F x assume finF: "finite F" and xnotinF: "x \ F" ``` nipkow@15402 ` 443` ``` and xFinA: "insert x F \ A" ``` nipkow@15402 ` 444` ``` and IH: "F \ A \ setsum f (A - F) = setsum f A - setsum f F" ``` nipkow@15402 ` 445` ``` from xnotinF xFinA have xinAF: "x \ (A - F)" by simp ``` nipkow@15402 ` 446` ``` from xinAF have A: "setsum f ((A - F) - {x}) = setsum f (A - F) - f x" ``` nipkow@15402 ` 447` ``` by (simp add: setsum_diff1_nat) ``` nipkow@15402 ` 448` ``` from xFinA have "F \ A" by simp ``` nipkow@15402 ` 449` ``` with IH have "setsum f (A - F) = setsum f A - setsum f F" by simp ``` nipkow@15402 ` 450` ``` with A have B: "setsum f ((A - F) - {x}) = setsum f A - setsum f F - f x" ``` nipkow@15402 ` 451` ``` by simp ``` nipkow@15402 ` 452` ``` from xnotinF have "A - insert x F = (A - F) - {x}" by auto ``` nipkow@15402 ` 453` ``` with B have C: "setsum f (A - insert x F) = setsum f A - setsum f F - f x" ``` nipkow@15402 ` 454` ``` by simp ``` nipkow@15402 ` 455` ``` from finF xnotinF have "setsum f (insert x F) = setsum f F + f x" by simp ``` nipkow@15402 ` 456` ``` with C have "setsum f (A - insert x F) = setsum f A - setsum f (insert x F)" ``` nipkow@15402 ` 457` ``` by simp ``` nipkow@15402 ` 458` ``` thus "setsum f (A - insert x F) = setsum f A - setsum f (insert x F)" by simp ``` nipkow@15402 ` 459` ```qed ``` nipkow@15402 ` 460` nipkow@15402 ` 461` ```lemma setsum_diff: ``` nipkow@15402 ` 462` ``` assumes le: "finite A" "B \ A" ``` nipkow@15402 ` 463` ``` shows "setsum f (A - B) = setsum f A - ((setsum f B)::('a::ab_group_add))" ``` nipkow@15402 ` 464` ```proof - ``` nipkow@15402 ` 465` ``` from le have finiteB: "finite B" using finite_subset by auto ``` nipkow@15402 ` 466` ``` show ?thesis using finiteB le ``` wenzelm@21575 ` 467` ``` proof induct ``` wenzelm@19535 ` 468` ``` case empty ``` wenzelm@19535 ` 469` ``` thus ?case by auto ``` wenzelm@19535 ` 470` ``` next ``` wenzelm@19535 ` 471` ``` case (insert x F) ``` wenzelm@19535 ` 472` ``` thus ?case using le finiteB ``` wenzelm@19535 ` 473` ``` by (simp add: Diff_insert[where a=x and B=F] setsum_diff1 insert_absorb) ``` nipkow@15402 ` 474` ``` qed ``` wenzelm@19535 ` 475` ```qed ``` nipkow@15402 ` 476` nipkow@15402 ` 477` ```lemma setsum_mono: ``` haftmann@35028 ` 478` ``` assumes le: "\i. i\K \ f (i::'a) \ ((g i)::('b::{comm_monoid_add, ordered_ab_semigroup_add}))" ``` nipkow@15402 ` 479` ``` shows "(\i\K. f i) \ (\i\K. g i)" ``` nipkow@15402 ` 480` ```proof (cases "finite K") ``` nipkow@15402 ` 481` ``` case True ``` nipkow@15402 ` 482` ``` thus ?thesis using le ``` wenzelm@19535 ` 483` ``` proof induct ``` nipkow@15402 ` 484` ``` case empty ``` nipkow@15402 ` 485` ``` thus ?case by simp ``` nipkow@15402 ` 486` ``` next ``` nipkow@15402 ` 487` ``` case insert ``` wenzelm@19535 ` 488` ``` thus ?case using add_mono by fastsimp ``` nipkow@15402 ` 489` ``` qed ``` nipkow@15402 ` 490` ```next ``` nipkow@15402 ` 491` ``` case False ``` nipkow@15402 ` 492` ``` thus ?thesis ``` nipkow@15402 ` 493` ``` by (simp add: setsum_def) ``` nipkow@15402 ` 494` ```qed ``` nipkow@15402 ` 495` nipkow@15554 ` 496` ```lemma setsum_strict_mono: ``` haftmann@35028 ` 497` ``` fixes f :: "'a \ 'b::{ordered_cancel_ab_semigroup_add,comm_monoid_add}" ``` wenzelm@19535 ` 498` ``` assumes "finite A" "A \ {}" ``` wenzelm@19535 ` 499` ``` and "!!x. x:A \ f x < g x" ``` wenzelm@19535 ` 500` ``` shows "setsum f A < setsum g A" ``` wenzelm@19535 ` 501` ``` using prems ``` nipkow@15554 ` 502` ```proof (induct rule: finite_ne_induct) ``` nipkow@15554 ` 503` ``` case singleton thus ?case by simp ``` nipkow@15554 ` 504` ```next ``` nipkow@15554 ` 505` ``` case insert thus ?case by (auto simp: add_strict_mono) ``` nipkow@15554 ` 506` ```qed ``` nipkow@15554 ` 507` nipkow@15535 ` 508` ```lemma setsum_negf: ``` wenzelm@19535 ` 509` ``` "setsum (%x. - (f x)::'a::ab_group_add) A = - setsum f A" ``` nipkow@15535 ` 510` ```proof (cases "finite A") ``` berghofe@22262 ` 511` ``` case True thus ?thesis by (induct set: finite) auto ``` nipkow@15535 ` 512` ```next ``` nipkow@15535 ` 513` ``` case False thus ?thesis by (simp add: setsum_def) ``` nipkow@15535 ` 514` ```qed ``` nipkow@15402 ` 515` nipkow@15535 ` 516` ```lemma setsum_subtractf: ``` wenzelm@19535 ` 517` ``` "setsum (%x. ((f x)::'a::ab_group_add) - g x) A = ``` wenzelm@19535 ` 518` ``` setsum f A - setsum g A" ``` nipkow@15535 ` 519` ```proof (cases "finite A") ``` nipkow@15535 ` 520` ``` case True thus ?thesis by (simp add: diff_minus setsum_addf setsum_negf) ``` nipkow@15535 ` 521` ```next ``` nipkow@15535 ` 522` ``` case False thus ?thesis by (simp add: setsum_def) ``` nipkow@15535 ` 523` ```qed ``` nipkow@15402 ` 524` nipkow@15535 ` 525` ```lemma setsum_nonneg: ``` haftmann@35028 ` 526` ``` assumes nn: "\x\A. (0::'a::{ordered_ab_semigroup_add,comm_monoid_add}) \ f x" ``` wenzelm@19535 ` 527` ``` shows "0 \ setsum f A" ``` nipkow@15535 ` 528` ```proof (cases "finite A") ``` nipkow@15535 ` 529` ``` case True thus ?thesis using nn ``` wenzelm@21575 ` 530` ``` proof induct ``` wenzelm@19535 ` 531` ``` case empty then show ?case by simp ``` wenzelm@19535 ` 532` ``` next ``` wenzelm@19535 ` 533` ``` case (insert x F) ``` wenzelm@19535 ` 534` ``` then have "0 + 0 \ f x + setsum f F" by (blast intro: add_mono) ``` wenzelm@19535 ` 535` ``` with insert show ?case by simp ``` wenzelm@19535 ` 536` ``` qed ``` nipkow@15535 ` 537` ```next ``` nipkow@15535 ` 538` ``` case False thus ?thesis by (simp add: setsum_def) ``` nipkow@15535 ` 539` ```qed ``` nipkow@15402 ` 540` nipkow@15535 ` 541` ```lemma setsum_nonpos: ``` haftmann@35028 ` 542` ``` assumes np: "\x\A. f x \ (0::'a::{ordered_ab_semigroup_add,comm_monoid_add})" ``` wenzelm@19535 ` 543` ``` shows "setsum f A \ 0" ``` nipkow@15535 ` 544` ```proof (cases "finite A") ``` nipkow@15535 ` 545` ``` case True thus ?thesis using np ``` wenzelm@21575 ` 546` ``` proof induct ``` wenzelm@19535 ` 547` ``` case empty then show ?case by simp ``` wenzelm@19535 ` 548` ``` next ``` wenzelm@19535 ` 549` ``` case (insert x F) ``` wenzelm@19535 ` 550` ``` then have "f x + setsum f F \ 0 + 0" by (blast intro: add_mono) ``` wenzelm@19535 ` 551` ``` with insert show ?case by simp ``` wenzelm@19535 ` 552` ``` qed ``` nipkow@15535 ` 553` ```next ``` nipkow@15535 ` 554` ``` case False thus ?thesis by (simp add: setsum_def) ``` nipkow@15535 ` 555` ```qed ``` nipkow@15402 ` 556` hoelzl@36622 ` 557` ```lemma setsum_nonneg_leq_bound: ``` hoelzl@36622 ` 558` ``` fixes f :: "'a \ 'b::{ordered_ab_group_add}" ``` hoelzl@36622 ` 559` ``` assumes "finite s" "\i. i \ s \ f i \ 0" "(\i \ s. f i) = B" "i \ s" ``` hoelzl@36622 ` 560` ``` shows "f i \ B" ``` hoelzl@36622 ` 561` ```proof - ``` hoelzl@36622 ` 562` ``` have "0 \ (\ i \ s - {i}. f i)" and "0 \ f i" ``` hoelzl@36622 ` 563` ``` using assms by (auto intro!: setsum_nonneg) ``` hoelzl@36622 ` 564` ``` moreover ``` hoelzl@36622 ` 565` ``` have "(\ i \ s - {i}. f i) + f i = B" ``` hoelzl@36622 ` 566` ``` using assms by (simp add: setsum_diff1) ``` hoelzl@36622 ` 567` ``` ultimately show ?thesis by auto ``` hoelzl@36622 ` 568` ```qed ``` hoelzl@36622 ` 569` hoelzl@36622 ` 570` ```lemma setsum_nonneg_0: ``` hoelzl@36622 ` 571` ``` fixes f :: "'a \ 'b::{ordered_ab_group_add}" ``` hoelzl@36622 ` 572` ``` assumes "finite s" and pos: "\ i. i \ s \ f i \ 0" ``` hoelzl@36622 ` 573` ``` and "(\ i \ s. f i) = 0" and i: "i \ s" ``` hoelzl@36622 ` 574` ``` shows "f i = 0" ``` hoelzl@36622 ` 575` ``` using setsum_nonneg_leq_bound[OF assms] pos[OF i] by auto ``` hoelzl@36622 ` 576` nipkow@15539 ` 577` ```lemma setsum_mono2: ``` haftmann@36303 ` 578` ```fixes f :: "'a \ 'b :: ordered_comm_monoid_add" ``` nipkow@15539 ` 579` ```assumes fin: "finite B" and sub: "A \ B" and nn: "\b. b \ B-A \ 0 \ f b" ``` nipkow@15539 ` 580` ```shows "setsum f A \ setsum f B" ``` nipkow@15539 ` 581` ```proof - ``` nipkow@15539 ` 582` ``` have "setsum f A \ setsum f A + setsum f (B-A)" ``` nipkow@15539 ` 583` ``` by(simp add: add_increasing2[OF setsum_nonneg] nn Ball_def) ``` nipkow@15539 ` 584` ``` also have "\ = setsum f (A \ (B-A))" using fin finite_subset[OF sub fin] ``` nipkow@15539 ` 585` ``` by (simp add:setsum_Un_disjoint del:Un_Diff_cancel) ``` nipkow@15539 ` 586` ``` also have "A \ (B-A) = B" using sub by blast ``` nipkow@15539 ` 587` ``` finally show ?thesis . ``` nipkow@15539 ` 588` ```qed ``` nipkow@15542 ` 589` avigad@16775 ` 590` ```lemma setsum_mono3: "finite B ==> A <= B ==> ``` avigad@16775 ` 591` ``` ALL x: B - A. ``` haftmann@35028 ` 592` ``` 0 <= ((f x)::'a::{comm_monoid_add,ordered_ab_semigroup_add}) ==> ``` avigad@16775 ` 593` ``` setsum f A <= setsum f B" ``` avigad@16775 ` 594` ``` apply (subgoal_tac "setsum f B = setsum f A + setsum f (B - A)") ``` avigad@16775 ` 595` ``` apply (erule ssubst) ``` avigad@16775 ` 596` ``` apply (subgoal_tac "setsum f A + 0 <= setsum f A + setsum f (B - A)") ``` avigad@16775 ` 597` ``` apply simp ``` avigad@16775 ` 598` ``` apply (rule add_left_mono) ``` avigad@16775 ` 599` ``` apply (erule setsum_nonneg) ``` avigad@16775 ` 600` ``` apply (subst setsum_Un_disjoint [THEN sym]) ``` avigad@16775 ` 601` ``` apply (erule finite_subset, assumption) ``` avigad@16775 ` 602` ``` apply (rule finite_subset) ``` avigad@16775 ` 603` ``` prefer 2 ``` avigad@16775 ` 604` ``` apply assumption ``` haftmann@32698 ` 605` ``` apply (auto simp add: sup_absorb2) ``` avigad@16775 ` 606` ```done ``` avigad@16775 ` 607` ballarin@19279 ` 608` ```lemma setsum_right_distrib: ``` huffman@22934 ` 609` ``` fixes f :: "'a => ('b::semiring_0)" ``` nipkow@15402 ` 610` ``` shows "r * setsum f A = setsum (%n. r * f n) A" ``` nipkow@15402 ` 611` ```proof (cases "finite A") ``` nipkow@15402 ` 612` ``` case True ``` nipkow@15402 ` 613` ``` thus ?thesis ``` wenzelm@21575 ` 614` ``` proof induct ``` nipkow@15402 ` 615` ``` case empty thus ?case by simp ``` nipkow@15402 ` 616` ``` next ``` nipkow@15402 ` 617` ``` case (insert x A) thus ?case by (simp add: right_distrib) ``` nipkow@15402 ` 618` ``` qed ``` nipkow@15402 ` 619` ```next ``` nipkow@15402 ` 620` ``` case False thus ?thesis by (simp add: setsum_def) ``` nipkow@15402 ` 621` ```qed ``` nipkow@15402 ` 622` ballarin@17149 ` 623` ```lemma setsum_left_distrib: ``` huffman@22934 ` 624` ``` "setsum f A * (r::'a::semiring_0) = (\n\A. f n * r)" ``` ballarin@17149 ` 625` ```proof (cases "finite A") ``` ballarin@17149 ` 626` ``` case True ``` ballarin@17149 ` 627` ``` then show ?thesis ``` ballarin@17149 ` 628` ``` proof induct ``` ballarin@17149 ` 629` ``` case empty thus ?case by simp ``` ballarin@17149 ` 630` ``` next ``` ballarin@17149 ` 631` ``` case (insert x A) thus ?case by (simp add: left_distrib) ``` ballarin@17149 ` 632` ``` qed ``` ballarin@17149 ` 633` ```next ``` ballarin@17149 ` 634` ``` case False thus ?thesis by (simp add: setsum_def) ``` ballarin@17149 ` 635` ```qed ``` ballarin@17149 ` 636` ballarin@17149 ` 637` ```lemma setsum_divide_distrib: ``` ballarin@17149 ` 638` ``` "setsum f A / (r::'a::field) = (\n\A. f n / r)" ``` ballarin@17149 ` 639` ```proof (cases "finite A") ``` ballarin@17149 ` 640` ``` case True ``` ballarin@17149 ` 641` ``` then show ?thesis ``` ballarin@17149 ` 642` ``` proof induct ``` ballarin@17149 ` 643` ``` case empty thus ?case by simp ``` ballarin@17149 ` 644` ``` next ``` ballarin@17149 ` 645` ``` case (insert x A) thus ?case by (simp add: add_divide_distrib) ``` ballarin@17149 ` 646` ``` qed ``` ballarin@17149 ` 647` ```next ``` ballarin@17149 ` 648` ``` case False thus ?thesis by (simp add: setsum_def) ``` ballarin@17149 ` 649` ```qed ``` ballarin@17149 ` 650` nipkow@15535 ` 651` ```lemma setsum_abs[iff]: ``` haftmann@35028 ` 652` ``` fixes f :: "'a => ('b::ordered_ab_group_add_abs)" ``` nipkow@15402 ` 653` ``` shows "abs (setsum f A) \ setsum (%i. abs(f i)) A" ``` nipkow@15535 ` 654` ```proof (cases "finite A") ``` nipkow@15535 ` 655` ``` case True ``` nipkow@15535 ` 656` ``` thus ?thesis ``` wenzelm@21575 ` 657` ``` proof induct ``` nipkow@15535 ` 658` ``` case empty thus ?case by simp ``` nipkow@15535 ` 659` ``` next ``` nipkow@15535 ` 660` ``` case (insert x A) ``` nipkow@15535 ` 661` ``` thus ?case by (auto intro: abs_triangle_ineq order_trans) ``` nipkow@15535 ` 662` ``` qed ``` nipkow@15402 ` 663` ```next ``` nipkow@15535 ` 664` ``` case False thus ?thesis by (simp add: setsum_def) ``` nipkow@15402 ` 665` ```qed ``` nipkow@15402 ` 666` nipkow@15535 ` 667` ```lemma setsum_abs_ge_zero[iff]: ``` haftmann@35028 ` 668` ``` fixes f :: "'a => ('b::ordered_ab_group_add_abs)" ``` nipkow@15402 ` 669` ``` shows "0 \ setsum (%i. abs(f i)) A" ``` nipkow@15535 ` 670` ```proof (cases "finite A") ``` nipkow@15535 ` 671` ``` case True ``` nipkow@15535 ` 672` ``` thus ?thesis ``` wenzelm@21575 ` 673` ``` proof induct ``` nipkow@15535 ` 674` ``` case empty thus ?case by simp ``` nipkow@15535 ` 675` ``` next ``` huffman@36977 ` 676` ``` case (insert x A) thus ?case by auto ``` nipkow@15535 ` 677` ``` qed ``` nipkow@15402 ` 678` ```next ``` nipkow@15535 ` 679` ``` case False thus ?thesis by (simp add: setsum_def) ``` nipkow@15402 ` 680` ```qed ``` nipkow@15402 ` 681` nipkow@15539 ` 682` ```lemma abs_setsum_abs[simp]: ``` haftmann@35028 ` 683` ``` fixes f :: "'a => ('b::ordered_ab_group_add_abs)" ``` nipkow@15539 ` 684` ``` shows "abs (\a\A. abs(f a)) = (\a\A. abs(f a))" ``` nipkow@15539 ` 685` ```proof (cases "finite A") ``` nipkow@15539 ` 686` ``` case True ``` nipkow@15539 ` 687` ``` thus ?thesis ``` wenzelm@21575 ` 688` ``` proof induct ``` nipkow@15539 ` 689` ``` case empty thus ?case by simp ``` nipkow@15539 ` 690` ``` next ``` nipkow@15539 ` 691` ``` case (insert a A) ``` nipkow@15539 ` 692` ``` hence "\\a\insert a A. \f a\\ = \\f a\ + (\a\A. \f a\)\" by simp ``` nipkow@15539 ` 693` ``` also have "\ = \\f a\ + \\a\A. \f a\\\" using insert by simp ``` avigad@16775 ` 694` ``` also have "\ = \f a\ + \\a\A. \f a\\" ``` avigad@16775 ` 695` ``` by (simp del: abs_of_nonneg) ``` nipkow@15539 ` 696` ``` also have "\ = (\a\insert a A. \f a\)" using insert by simp ``` nipkow@15539 ` 697` ``` finally show ?case . ``` nipkow@15539 ` 698` ``` qed ``` nipkow@15539 ` 699` ```next ``` nipkow@15539 ` 700` ``` case False thus ?thesis by (simp add: setsum_def) ``` nipkow@15539 ` 701` ```qed ``` nipkow@15539 ` 702` nipkow@31080 ` 703` ```lemma setsum_Plus: ``` nipkow@31080 ` 704` ``` fixes A :: "'a set" and B :: "'b set" ``` nipkow@31080 ` 705` ``` assumes fin: "finite A" "finite B" ``` nipkow@31080 ` 706` ``` shows "setsum f (A <+> B) = setsum (f \ Inl) A + setsum (f \ Inr) B" ``` nipkow@31080 ` 707` ```proof - ``` nipkow@31080 ` 708` ``` have "A <+> B = Inl ` A \ Inr ` B" by auto ``` nipkow@31080 ` 709` ``` moreover from fin have "finite (Inl ` A :: ('a + 'b) set)" "finite (Inr ` B :: ('a + 'b) set)" ``` nipkow@31080 ` 710` ``` by(auto intro: finite_imageI) ``` nipkow@31080 ` 711` ``` moreover have "Inl ` A \ Inr ` B = ({} :: ('a + 'b) set)" by auto ``` nipkow@31080 ` 712` ``` moreover have "inj_on (Inl :: 'a \ 'a + 'b) A" "inj_on (Inr :: 'b \ 'a + 'b) B" by(auto intro: inj_onI) ``` nipkow@31080 ` 713` ``` ultimately show ?thesis using fin by(simp add: setsum_Un_disjoint setsum_reindex) ``` nipkow@31080 ` 714` ```qed ``` nipkow@31080 ` 715` nipkow@31080 ` 716` ballarin@17149 ` 717` ```text {* Commuting outer and inner summation *} ``` ballarin@17149 ` 718` ballarin@17149 ` 719` ```lemma setsum_commute: ``` ballarin@17149 ` 720` ``` "(\i\A. \j\B. f i j) = (\j\B. \i\A. f i j)" ``` ballarin@17149 ` 721` ```proof (simp add: setsum_cartesian_product) ``` paulson@17189 ` 722` ``` have "(\(x,y) \ A <*> B. f x y) = ``` paulson@17189 ` 723` ``` (\(y,x) \ (%(i, j). (j, i)) ` (A \ B). f x y)" ``` ballarin@17149 ` 724` ``` (is "?s = _") ``` ballarin@17149 ` 725` ``` apply (simp add: setsum_reindex [where f = "%(i, j). (j, i)"] swap_inj_on) ``` ballarin@17149 ` 726` ``` apply (simp add: split_def) ``` ballarin@17149 ` 727` ``` done ``` paulson@17189 ` 728` ``` also have "... = (\(y,x)\B \ A. f x y)" ``` ballarin@17149 ` 729` ``` (is "_ = ?t") ``` ballarin@17149 ` 730` ``` apply (simp add: swap_product) ``` ballarin@17149 ` 731` ``` done ``` ballarin@17149 ` 732` ``` finally show "?s = ?t" . ``` ballarin@17149 ` 733` ```qed ``` ballarin@17149 ` 734` ballarin@19279 ` 735` ```lemma setsum_product: ``` huffman@22934 ` 736` ``` fixes f :: "'a => ('b::semiring_0)" ``` ballarin@19279 ` 737` ``` shows "setsum f A * setsum g B = (\i\A. \j\B. f i * g j)" ``` ballarin@19279 ` 738` ``` by (simp add: setsum_right_distrib setsum_left_distrib) (rule setsum_commute) ``` ballarin@19279 ` 739` nipkow@34223 ` 740` ```lemma setsum_mult_setsum_if_inj: ``` nipkow@34223 ` 741` ```fixes f :: "'a => ('b::semiring_0)" ``` nipkow@34223 ` 742` ```shows "inj_on (%(a,b). f a * g b) (A \ B) ==> ``` nipkow@34223 ` 743` ``` setsum f A * setsum g B = setsum id {f a * g b|a b. a:A & b:B}" ``` nipkow@34223 ` 744` ```by(auto simp: setsum_product setsum_cartesian_product ``` nipkow@34223 ` 745` ``` intro!: setsum_reindex_cong[symmetric]) ``` nipkow@34223 ` 746` haftmann@35722 ` 747` ```lemma setsum_constant [simp]: "(\x \ A. y) = of_nat(card A) * y" ``` haftmann@35722 ` 748` ```apply (cases "finite A") ``` haftmann@35722 ` 749` ```apply (erule finite_induct) ``` haftmann@35722 ` 750` ```apply (auto simp add: algebra_simps) ``` haftmann@35722 ` 751` ```done ``` haftmann@35722 ` 752` haftmann@35722 ` 753` ```lemma setsum_bounded: ``` haftmann@35722 ` 754` ``` assumes le: "\i. i\A \ f i \ (K::'a::{semiring_1, ordered_ab_semigroup_add})" ``` haftmann@35722 ` 755` ``` shows "setsum f A \ of_nat(card A) * K" ``` haftmann@35722 ` 756` ```proof (cases "finite A") ``` haftmann@35722 ` 757` ``` case True ``` haftmann@35722 ` 758` ``` thus ?thesis using le setsum_mono[where K=A and g = "%x. K"] by simp ``` haftmann@35722 ` 759` ```next ``` haftmann@35722 ` 760` ``` case False thus ?thesis by (simp add: setsum_def) ``` haftmann@35722 ` 761` ```qed ``` haftmann@35722 ` 762` haftmann@35722 ` 763` haftmann@35722 ` 764` ```subsubsection {* Cardinality as special case of @{const setsum} *} ``` haftmann@35722 ` 765` haftmann@35722 ` 766` ```lemma card_eq_setsum: ``` haftmann@35722 ` 767` ``` "card A = setsum (\x. 1) A" ``` haftmann@35722 ` 768` ``` by (simp only: card_def setsum_def) ``` haftmann@35722 ` 769` haftmann@35722 ` 770` ```lemma card_UN_disjoint: ``` haftmann@35722 ` 771` ``` "finite I ==> (ALL i:I. finite (A i)) ==> ``` haftmann@35722 ` 772` ``` (ALL i:I. ALL j:I. i \ j --> A i Int A j = {}) ``` haftmann@35722 ` 773` ``` ==> card (UNION I A) = (\i\I. card(A i))" ``` haftmann@35722 ` 774` ```apply (simp add: card_eq_setsum del: setsum_constant) ``` haftmann@35722 ` 775` ```apply (subgoal_tac ``` haftmann@35722 ` 776` ``` "setsum (%i. card (A i)) I = setsum (%i. (setsum (%x. 1) (A i))) I") ``` haftmann@35722 ` 777` ```apply (simp add: setsum_UN_disjoint del: setsum_constant) ``` haftmann@35722 ` 778` ```apply (simp cong: setsum_cong) ``` haftmann@35722 ` 779` ```done ``` haftmann@35722 ` 780` haftmann@35722 ` 781` ```lemma card_Union_disjoint: ``` haftmann@35722 ` 782` ``` "finite C ==> (ALL A:C. finite A) ==> ``` haftmann@35722 ` 783` ``` (ALL A:C. ALL B:C. A \ B --> A Int B = {}) ``` haftmann@35722 ` 784` ``` ==> card (Union C) = setsum card C" ``` haftmann@35722 ` 785` ```apply (frule card_UN_disjoint [of C id]) ``` haftmann@35722 ` 786` ```apply (unfold Union_def id_def, assumption+) ``` haftmann@35722 ` 787` ```done ``` haftmann@35722 ` 788` haftmann@35722 ` 789` ```text{*The image of a finite set can be expressed using @{term fold_image}.*} ``` haftmann@35722 ` 790` ```lemma image_eq_fold_image: ``` haftmann@35722 ` 791` ``` "finite A ==> f ` A = fold_image (op Un) (%x. {f x}) {} A" ``` haftmann@35722 ` 792` ```proof (induct rule: finite_induct) ``` haftmann@35722 ` 793` ``` case empty then show ?case by simp ``` haftmann@35722 ` 794` ```next ``` haftmann@35722 ` 795` ``` interpret ab_semigroup_mult "op Un" ``` haftmann@35722 ` 796` ``` proof qed auto ``` haftmann@35722 ` 797` ``` case insert ``` haftmann@35722 ` 798` ``` then show ?case by simp ``` haftmann@35722 ` 799` ```qed ``` haftmann@35722 ` 800` haftmann@35722 ` 801` ```subsubsection {* Cardinality of products *} ``` haftmann@35722 ` 802` haftmann@35722 ` 803` ```lemma card_SigmaI [simp]: ``` haftmann@35722 ` 804` ``` "\ finite A; ALL a:A. finite (B a) \ ``` haftmann@35722 ` 805` ``` \ card (SIGMA x: A. B x) = (\a\A. card (B a))" ``` haftmann@35722 ` 806` ```by(simp add: card_eq_setsum setsum_Sigma del:setsum_constant) ``` haftmann@35722 ` 807` haftmann@35722 ` 808` ```(* ``` haftmann@35722 ` 809` ```lemma SigmaI_insert: "y \ A ==> ``` haftmann@35722 ` 810` ``` (SIGMA x:(insert y A). B x) = (({y} <*> (B y)) \ (SIGMA x: A. B x))" ``` haftmann@35722 ` 811` ``` by auto ``` haftmann@35722 ` 812` ```*) ``` haftmann@35722 ` 813` haftmann@35722 ` 814` ```lemma card_cartesian_product: "card (A <*> B) = card(A) * card(B)" ``` haftmann@35722 ` 815` ``` by (cases "finite A \ finite B") ``` haftmann@35722 ` 816` ``` (auto simp add: card_eq_0_iff dest: finite_cartesian_productD1 finite_cartesian_productD2) ``` haftmann@35722 ` 817` haftmann@35722 ` 818` ```lemma card_cartesian_product_singleton: "card({x} <*> A) = card(A)" ``` haftmann@35722 ` 819` ```by (simp add: card_cartesian_product) ``` haftmann@35722 ` 820` ballarin@17149 ` 821` nipkow@15402 ` 822` ```subsection {* Generalized product over a set *} ``` nipkow@15402 ` 823` haftmann@35816 ` 824` ```definition (in comm_monoid_mult) setprod :: "('b \ 'a) => 'b set => 'a" where ``` haftmann@35816 ` 825` ``` "setprod f A = (if finite A then fold_image (op *) f 1 A else 1)" ``` haftmann@35816 ` 826` huffman@35938 ` 827` ```sublocale comm_monoid_mult < setprod!: comm_monoid_big "op *" 1 setprod proof ``` haftmann@35816 ` 828` ```qed (fact setprod_def) ``` nipkow@15402 ` 829` wenzelm@19535 ` 830` ```abbreviation ``` wenzelm@21404 ` 831` ``` Setprod ("\_" [1000] 999) where ``` wenzelm@19535 ` 832` ``` "\A == setprod (%x. x) A" ``` wenzelm@19535 ` 833` nipkow@15402 ` 834` ```syntax ``` paulson@17189 ` 835` ``` "_setprod" :: "pttrn => 'a set => 'b => 'b::comm_monoid_mult" ("(3PROD _:_. _)" [0, 51, 10] 10) ``` nipkow@15402 ` 836` ```syntax (xsymbols) ``` paulson@17189 ` 837` ``` "_setprod" :: "pttrn => 'a set => 'b => 'b::comm_monoid_mult" ("(3\_\_. _)" [0, 51, 10] 10) ``` nipkow@15402 ` 838` ```syntax (HTML output) ``` paulson@17189 ` 839` ``` "_setprod" :: "pttrn => 'a set => 'b => 'b::comm_monoid_mult" ("(3\_\_. _)" [0, 51, 10] 10) ``` nipkow@16550 ` 840` nipkow@16550 ` 841` ```translations -- {* Beware of argument permutation! *} ``` nipkow@28853 ` 842` ``` "PROD i:A. b" == "CONST setprod (%i. b) A" ``` nipkow@28853 ` 843` ``` "\i\A. b" == "CONST setprod (%i. b) A" ``` nipkow@16550 ` 844` nipkow@16550 ` 845` ```text{* Instead of @{term"\x\{x. P}. e"} we introduce the shorter ``` nipkow@16550 ` 846` ``` @{text"\x|P. e"}. *} ``` nipkow@16550 ` 847` nipkow@16550 ` 848` ```syntax ``` paulson@17189 ` 849` ``` "_qsetprod" :: "pttrn \ bool \ 'a \ 'a" ("(3PROD _ |/ _./ _)" [0,0,10] 10) ``` nipkow@16550 ` 850` ```syntax (xsymbols) ``` paulson@17189 ` 851` ``` "_qsetprod" :: "pttrn \ bool \ 'a \ 'a" ("(3\_ | (_)./ _)" [0,0,10] 10) ``` nipkow@16550 ` 852` ```syntax (HTML output) ``` paulson@17189 ` 853` ``` "_qsetprod" :: "pttrn \ bool \ 'a \ 'a" ("(3\_ | (_)./ _)" [0,0,10] 10) ``` nipkow@16550 ` 854` nipkow@15402 ` 855` ```translations ``` nipkow@28853 ` 856` ``` "PROD x|P. t" => "CONST setprod (%x. t) {x. P}" ``` nipkow@28853 ` 857` ``` "\x|P. t" => "CONST setprod (%x. t) {x. P}" ``` nipkow@16550 ` 858` haftmann@35816 ` 859` ```lemma setprod_empty: "setprod f {} = 1" ``` haftmann@35816 ` 860` ``` by (fact setprod.empty) ``` nipkow@15402 ` 861` haftmann@35816 ` 862` ```lemma setprod_insert: "[| finite A; a \ A |] ==> ``` nipkow@15402 ` 863` ``` setprod f (insert a A) = f a * setprod f A" ``` haftmann@35816 ` 864` ``` by (fact setprod.insert) ``` nipkow@15402 ` 865` haftmann@35816 ` 866` ```lemma setprod_infinite: "~ finite A ==> setprod f A = 1" ``` haftmann@35816 ` 867` ``` by (fact setprod.infinite) ``` paulson@15409 ` 868` nipkow@15402 ` 869` ```lemma setprod_reindex: ``` nipkow@28853 ` 870` ``` "inj_on f B ==> setprod h (f ` B) = setprod (h \ f) B" ``` nipkow@28853 ` 871` ```by(auto simp: setprod_def fold_image_reindex dest!:finite_imageD) ``` nipkow@15402 ` 872` nipkow@15402 ` 873` ```lemma setprod_reindex_id: "inj_on f B ==> setprod f B = setprod id (f ` B)" ``` nipkow@15402 ` 874` ```by (auto simp add: setprod_reindex) ``` nipkow@15402 ` 875` nipkow@15402 ` 876` ```lemma setprod_cong: ``` nipkow@15402 ` 877` ``` "A = B ==> (!!x. x:B ==> f x = g x) ==> setprod f A = setprod g B" ``` nipkow@28853 ` 878` ```by(fastsimp simp: setprod_def intro: fold_image_cong) ``` nipkow@15402 ` 879` nipkow@30837 ` 880` ```lemma strong_setprod_cong[cong]: ``` berghofe@16632 ` 881` ``` "A = B ==> (!!x. x:B =simp=> f x = g x) ==> setprod f A = setprod g B" ``` nipkow@28853 ` 882` ```by(fastsimp simp: simp_implies_def setprod_def intro: fold_image_cong) ``` berghofe@16632 ` 883` nipkow@15402 ` 884` ```lemma setprod_reindex_cong: "inj_on f A ==> ``` nipkow@15402 ` 885` ``` B = f ` A ==> g = h \ f ==> setprod h B = setprod g A" ``` nipkow@28853 ` 886` ```by (frule setprod_reindex, simp) ``` nipkow@15402 ` 887` chaieb@29674 ` 888` ```lemma strong_setprod_reindex_cong: assumes i: "inj_on f A" ``` chaieb@29674 ` 889` ``` and B: "B = f ` A" and eq: "\x. x \ A \ g x = (h \ f) x" ``` chaieb@29674 ` 890` ``` shows "setprod h B = setprod g A" ``` chaieb@29674 ` 891` ```proof- ``` chaieb@29674 ` 892` ``` have "setprod h B = setprod (h o f) A" ``` chaieb@29674 ` 893` ``` by (simp add: B setprod_reindex[OF i, of h]) ``` chaieb@29674 ` 894` ``` then show ?thesis apply simp ``` chaieb@29674 ` 895` ``` apply (rule setprod_cong) ``` chaieb@29674 ` 896` ``` apply simp ``` nipkow@30837 ` 897` ``` by (simp add: eq) ``` chaieb@29674 ` 898` ```qed ``` chaieb@29674 ` 899` chaieb@30260 ` 900` ```lemma setprod_Un_one: ``` chaieb@30260 ` 901` ``` assumes fS: "finite S" and fT: "finite T" ``` chaieb@30260 ` 902` ``` and I0: "\x \ S\T. f x = 1" ``` chaieb@30260 ` 903` ``` shows "setprod f (S \ T) = setprod f S * setprod f T" ``` chaieb@30260 ` 904` ``` using fS fT ``` chaieb@30260 ` 905` ``` apply (simp add: setprod_def) ``` chaieb@30260 ` 906` ``` apply (rule fold_image_Un_one) ``` chaieb@30260 ` 907` ``` using I0 by auto ``` chaieb@30260 ` 908` nipkow@15402 ` 909` nipkow@15402 ` 910` ```lemma setprod_1: "setprod (%i. 1) A = 1" ``` nipkow@28853 ` 911` ```apply (case_tac "finite A") ``` nipkow@28853 ` 912` ```apply (erule finite_induct, auto simp add: mult_ac) ``` nipkow@28853 ` 913` ```done ``` nipkow@15402 ` 914` nipkow@15402 ` 915` ```lemma setprod_1': "ALL a:F. f a = 1 ==> setprod f F = 1" ``` nipkow@28853 ` 916` ```apply (subgoal_tac "setprod f F = setprod (%x. 1) F") ``` nipkow@28853 ` 917` ```apply (erule ssubst, rule setprod_1) ``` nipkow@28853 ` 918` ```apply (rule setprod_cong, auto) ``` nipkow@28853 ` 919` ```done ``` nipkow@15402 ` 920` nipkow@15402 ` 921` ```lemma setprod_Un_Int: "finite A ==> finite B ``` nipkow@15402 ` 922` ``` ==> setprod g (A Un B) * setprod g (A Int B) = setprod g A * setprod g B" ``` nipkow@28853 ` 923` ```by(simp add: setprod_def fold_image_Un_Int[symmetric]) ``` nipkow@15402 ` 924` nipkow@15402 ` 925` ```lemma setprod_Un_disjoint: "finite A ==> finite B ``` nipkow@15402 ` 926` ``` ==> A Int B = {} ==> setprod g (A Un B) = setprod g A * setprod g B" ``` nipkow@15402 ` 927` ```by (subst setprod_Un_Int [symmetric], auto) ``` nipkow@15402 ` 928` nipkow@30837 ` 929` ```lemma setprod_mono_one_left: ``` nipkow@30837 ` 930` ``` assumes fT: "finite T" and ST: "S \ T" ``` nipkow@30837 ` 931` ``` and z: "\i \ T - S. f i = 1" ``` nipkow@30837 ` 932` ``` shows "setprod f S = setprod f T" ``` nipkow@30837 ` 933` ```proof- ``` nipkow@30837 ` 934` ``` have eq: "T = S \ (T - S)" using ST by blast ``` nipkow@30837 ` 935` ``` have d: "S \ (T - S) = {}" using ST by blast ``` nipkow@30837 ` 936` ``` from fT ST have f: "finite S" "finite (T - S)" by (auto intro: finite_subset) ``` nipkow@30837 ` 937` ``` show ?thesis ``` nipkow@30837 ` 938` ``` by (simp add: setprod_Un_disjoint[OF f d, unfolded eq[symmetric]] setprod_1'[OF z]) ``` nipkow@30837 ` 939` ```qed ``` nipkow@30837 ` 940` nipkow@30837 ` 941` ```lemmas setprod_mono_one_right = setprod_mono_one_left [THEN sym] ``` nipkow@30837 ` 942` chaieb@29674 ` 943` ```lemma setprod_delta: ``` chaieb@29674 ` 944` ``` assumes fS: "finite S" ``` chaieb@29674 ` 945` ``` shows "setprod (\k. if k=a then b k else 1) S = (if a \ S then b a else 1)" ``` chaieb@29674 ` 946` ```proof- ``` chaieb@29674 ` 947` ``` let ?f = "(\k. if k=a then b k else 1)" ``` chaieb@29674 ` 948` ``` {assume a: "a \ S" ``` chaieb@29674 ` 949` ``` hence "\ k\ S. ?f k = 1" by simp ``` chaieb@29674 ` 950` ``` hence ?thesis using a by (simp add: setprod_1 cong add: setprod_cong) } ``` chaieb@29674 ` 951` ``` moreover ``` chaieb@29674 ` 952` ``` {assume a: "a \ S" ``` chaieb@29674 ` 953` ``` let ?A = "S - {a}" ``` chaieb@29674 ` 954` ``` let ?B = "{a}" ``` chaieb@29674 ` 955` ``` have eq: "S = ?A \ ?B" using a by blast ``` chaieb@29674 ` 956` ``` have dj: "?A \ ?B = {}" by simp ``` chaieb@29674 ` 957` ``` from fS have fAB: "finite ?A" "finite ?B" by auto ``` chaieb@29674 ` 958` ``` have fA1: "setprod ?f ?A = 1" apply (rule setprod_1') by auto ``` chaieb@29674 ` 959` ``` have "setprod ?f ?A * setprod ?f ?B = setprod ?f S" ``` chaieb@29674 ` 960` ``` using setprod_Un_disjoint[OF fAB dj, of ?f, unfolded eq[symmetric]] ``` chaieb@29674 ` 961` ``` by simp ``` chaieb@29674 ` 962` ``` then have ?thesis using a by (simp add: fA1 cong add: setprod_cong cong del: if_weak_cong)} ``` chaieb@29674 ` 963` ``` ultimately show ?thesis by blast ``` chaieb@29674 ` 964` ```qed ``` chaieb@29674 ` 965` chaieb@29674 ` 966` ```lemma setprod_delta': ``` chaieb@29674 ` 967` ``` assumes fS: "finite S" shows ``` chaieb@29674 ` 968` ``` "setprod (\k. if a = k then b k else 1) S = ``` chaieb@29674 ` 969` ``` (if a\ S then b a else 1)" ``` chaieb@29674 ` 970` ``` using setprod_delta[OF fS, of a b, symmetric] ``` chaieb@29674 ` 971` ``` by (auto intro: setprod_cong) ``` chaieb@29674 ` 972` chaieb@29674 ` 973` nipkow@15402 ` 974` ```lemma setprod_UN_disjoint: ``` nipkow@15402 ` 975` ``` "finite I ==> (ALL i:I. finite (A i)) ==> ``` nipkow@15402 ` 976` ``` (ALL i:I. ALL j:I. i \ j --> A i Int A j = {}) ==> ``` nipkow@15402 ` 977` ``` setprod f (UNION I A) = setprod (%i. setprod f (A i)) I" ``` nipkow@28853 ` 978` ```by(simp add: setprod_def fold_image_UN_disjoint cong: setprod_cong) ``` nipkow@15402 ` 979` nipkow@15402 ` 980` ```lemma setprod_Union_disjoint: ``` paulson@15409 ` 981` ``` "[| (ALL A:C. finite A); ``` paulson@15409 ` 982` ``` (ALL A:C. ALL B:C. A \ B --> A Int B = {}) |] ``` paulson@15409 ` 983` ``` ==> setprod f (Union C) = setprod (setprod f) C" ``` paulson@15409 ` 984` ```apply (cases "finite C") ``` paulson@15409 ` 985` ``` prefer 2 apply (force dest: finite_UnionD simp add: setprod_def) ``` nipkow@15402 ` 986` ``` apply (frule setprod_UN_disjoint [of C id f]) ``` paulson@15409 ` 987` ``` apply (unfold Union_def id_def, assumption+) ``` paulson@15409 ` 988` ```done ``` nipkow@15402 ` 989` nipkow@15402 ` 990` ```lemma setprod_Sigma: "finite A ==> ALL x:A. finite (B x) ==> ``` nipkow@16550 ` 991` ``` (\x\A. (\y\ B x. f x y)) = ``` paulson@17189 ` 992` ``` (\(x,y)\(SIGMA x:A. B x). f x y)" ``` nipkow@28853 ` 993` ```by(simp add:setprod_def fold_image_Sigma split_def cong:setprod_cong) ``` nipkow@15402 ` 994` paulson@15409 ` 995` ```text{*Here we can eliminate the finiteness assumptions, by cases.*} ``` paulson@15409 ` 996` ```lemma setprod_cartesian_product: ``` paulson@17189 ` 997` ``` "(\x\A. (\y\ B. f x y)) = (\(x,y)\(A <*> B). f x y)" ``` paulson@15409 ` 998` ```apply (cases "finite A") ``` paulson@15409 ` 999` ``` apply (cases "finite B") ``` paulson@15409 ` 1000` ``` apply (simp add: setprod_Sigma) ``` paulson@15409 ` 1001` ``` apply (cases "A={}", simp) ``` paulson@15409 ` 1002` ``` apply (simp add: setprod_1) ``` paulson@15409 ` 1003` ```apply (auto simp add: setprod_def ``` paulson@15409 ` 1004` ``` dest: finite_cartesian_productD1 finite_cartesian_productD2) ``` paulson@15409 ` 1005` ```done ``` nipkow@15402 ` 1006` nipkow@15402 ` 1007` ```lemma setprod_timesf: ``` paulson@15409 ` 1008` ``` "setprod (%x. f x * g x) A = (setprod f A * setprod g A)" ``` nipkow@28853 ` 1009` ```by(simp add:setprod_def fold_image_distrib) ``` nipkow@15402 ` 1010` nipkow@15402 ` 1011` nipkow@15402 ` 1012` ```subsubsection {* Properties in more restricted classes of structures *} ``` nipkow@15402 ` 1013` nipkow@15402 ` 1014` ```lemma setprod_eq_1_iff [simp]: ``` nipkow@28853 ` 1015` ``` "finite F ==> (setprod f F = 1) = (ALL a:F. f a = (1::nat))" ``` nipkow@28853 ` 1016` ```by (induct set: finite) auto ``` nipkow@15402 ` 1017` nipkow@15402 ` 1018` ```lemma setprod_zero: ``` huffman@23277 ` 1019` ``` "finite A ==> EX x: A. f x = (0::'a::comm_semiring_1) ==> setprod f A = 0" ``` nipkow@28853 ` 1020` ```apply (induct set: finite, force, clarsimp) ``` nipkow@28853 ` 1021` ```apply (erule disjE, auto) ``` nipkow@28853 ` 1022` ```done ``` nipkow@15402 ` 1023` nipkow@15402 ` 1024` ```lemma setprod_nonneg [rule_format]: ``` haftmann@35028 ` 1025` ``` "(ALL x: A. (0::'a::linordered_semidom) \ f x) --> 0 \ setprod f A" ``` huffman@30841 ` 1026` ```by (cases "finite A", induct set: finite, simp_all add: mult_nonneg_nonneg) ``` huffman@30841 ` 1027` haftmann@35028 ` 1028` ```lemma setprod_pos [rule_format]: "(ALL x: A. (0::'a::linordered_semidom) < f x) ``` nipkow@28853 ` 1029` ``` --> 0 < setprod f A" ``` huffman@30841 ` 1030` ```by (cases "finite A", induct set: finite, simp_all add: mult_pos_pos) ``` nipkow@15402 ` 1031` nipkow@30843 ` 1032` ```lemma setprod_zero_iff[simp]: "finite A ==> ``` nipkow@30843 ` 1033` ``` (setprod f A = (0::'a::{comm_semiring_1,no_zero_divisors})) = ``` nipkow@30843 ` 1034` ``` (EX x: A. f x = 0)" ``` nipkow@30843 ` 1035` ```by (erule finite_induct, auto simp:no_zero_divisors) ``` nipkow@30843 ` 1036` nipkow@30843 ` 1037` ```lemma setprod_pos_nat: ``` nipkow@30843 ` 1038` ``` "finite S ==> (ALL x : S. f x > (0::nat)) ==> setprod f S > 0" ``` nipkow@30843 ` 1039` ```using setprod_zero_iff by(simp del:neq0_conv add:neq0_conv[symmetric]) ``` nipkow@15402 ` 1040` nipkow@30863 ` 1041` ```lemma setprod_pos_nat_iff[simp]: ``` nipkow@30863 ` 1042` ``` "finite S ==> (setprod f S > 0) = (ALL x : S. f x > (0::nat))" ``` nipkow@30863 ` 1043` ```using setprod_zero_iff by(simp del:neq0_conv add:neq0_conv[symmetric]) ``` nipkow@30863 ` 1044` nipkow@15402 ` 1045` ```lemma setprod_Un: "finite A ==> finite B ==> (ALL x: A Int B. f x \ 0) ==> ``` nipkow@28853 ` 1046` ``` (setprod f (A Un B) :: 'a ::{field}) ``` nipkow@28853 ` 1047` ``` = setprod f A * setprod f B / setprod f (A Int B)" ``` nipkow@30843 ` 1048` ```by (subst setprod_Un_Int [symmetric], auto) ``` nipkow@15402 ` 1049` nipkow@15402 ` 1050` ```lemma setprod_diff1: "finite A ==> f a \ 0 ==> ``` nipkow@28853 ` 1051` ``` (setprod f (A - {a}) :: 'a :: {field}) = ``` nipkow@28853 ` 1052` ``` (if a:A then setprod f A / f a else setprod f A)" ``` haftmann@36303 ` 1053` ``` by (erule finite_induct) (auto simp add: insert_Diff_if) ``` nipkow@15402 ` 1054` paulson@31906 ` 1055` ```lemma setprod_inversef: ``` haftmann@36409 ` 1056` ``` fixes f :: "'b \ 'a::field_inverse_zero" ``` paulson@31906 ` 1057` ``` shows "finite A ==> setprod (inverse \ f) A = inverse (setprod f A)" ``` nipkow@28853 ` 1058` ```by (erule finite_induct) auto ``` nipkow@15402 ` 1059` nipkow@15402 ` 1060` ```lemma setprod_dividef: ``` haftmann@36409 ` 1061` ``` fixes f :: "'b \ 'a::field_inverse_zero" ``` wenzelm@31916 ` 1062` ``` shows "finite A ``` nipkow@28853 ` 1063` ``` ==> setprod (%x. f x / g x) A = setprod f A / setprod g A" ``` nipkow@28853 ` 1064` ```apply (subgoal_tac ``` nipkow@15402 ` 1065` ``` "setprod (%x. f x / g x) A = setprod (%x. f x * (inverse \ g) x) A") ``` nipkow@28853 ` 1066` ```apply (erule ssubst) ``` nipkow@28853 ` 1067` ```apply (subst divide_inverse) ``` nipkow@28853 ` 1068` ```apply (subst setprod_timesf) ``` nipkow@28853 ` 1069` ```apply (subst setprod_inversef, assumption+, rule refl) ``` nipkow@28853 ` 1070` ```apply (rule setprod_cong, rule refl) ``` nipkow@28853 ` 1071` ```apply (subst divide_inverse, auto) ``` nipkow@28853 ` 1072` ```done ``` nipkow@28853 ` 1073` nipkow@29925 ` 1074` ```lemma setprod_dvd_setprod [rule_format]: ``` nipkow@29925 ` 1075` ``` "(ALL x : A. f x dvd g x) \ setprod f A dvd setprod g A" ``` nipkow@29925 ` 1076` ``` apply (cases "finite A") ``` nipkow@29925 ` 1077` ``` apply (induct set: finite) ``` nipkow@29925 ` 1078` ``` apply (auto simp add: dvd_def) ``` nipkow@29925 ` 1079` ``` apply (rule_tac x = "k * ka" in exI) ``` nipkow@29925 ` 1080` ``` apply (simp add: algebra_simps) ``` nipkow@29925 ` 1081` ```done ``` nipkow@29925 ` 1082` nipkow@29925 ` 1083` ```lemma setprod_dvd_setprod_subset: ``` nipkow@29925 ` 1084` ``` "finite B \ A <= B \ setprod f A dvd setprod f B" ``` nipkow@29925 ` 1085` ``` apply (subgoal_tac "setprod f B = setprod f A * setprod f (B - A)") ``` nipkow@29925 ` 1086` ``` apply (unfold dvd_def, blast) ``` nipkow@29925 ` 1087` ``` apply (subst setprod_Un_disjoint [symmetric]) ``` nipkow@29925 ` 1088` ``` apply (auto elim: finite_subset intro: setprod_cong) ``` nipkow@29925 ` 1089` ```done ``` nipkow@29925 ` 1090` nipkow@29925 ` 1091` ```lemma setprod_dvd_setprod_subset2: ``` nipkow@29925 ` 1092` ``` "finite B \ A <= B \ ALL x : A. (f x::'a::comm_semiring_1) dvd g x \ ``` nipkow@29925 ` 1093` ``` setprod f A dvd setprod g B" ``` nipkow@29925 ` 1094` ``` apply (rule dvd_trans) ``` nipkow@29925 ` 1095` ``` apply (rule setprod_dvd_setprod, erule (1) bspec) ``` nipkow@29925 ` 1096` ``` apply (erule (1) setprod_dvd_setprod_subset) ``` nipkow@29925 ` 1097` ```done ``` nipkow@29925 ` 1098` nipkow@29925 ` 1099` ```lemma dvd_setprod: "finite A \ i:A \ ``` nipkow@29925 ` 1100` ``` (f i ::'a::comm_semiring_1) dvd setprod f A" ``` nipkow@29925 ` 1101` ```by (induct set: finite) (auto intro: dvd_mult) ``` nipkow@29925 ` 1102` nipkow@29925 ` 1103` ```lemma dvd_setsum [rule_format]: "(ALL i : A. d dvd f i) \ ``` nipkow@29925 ` 1104` ``` (d::'a::comm_semiring_1) dvd (SUM x : A. f x)" ``` nipkow@29925 ` 1105` ``` apply (cases "finite A") ``` nipkow@29925 ` 1106` ``` apply (induct set: finite) ``` nipkow@29925 ` 1107` ``` apply auto ``` nipkow@29925 ` 1108` ```done ``` nipkow@29925 ` 1109` hoelzl@35171 ` 1110` ```lemma setprod_mono: ``` hoelzl@35171 ` 1111` ``` fixes f :: "'a \ 'b\linordered_semidom" ``` hoelzl@35171 ` 1112` ``` assumes "\i\A. 0 \ f i \ f i \ g i" ``` hoelzl@35171 ` 1113` ``` shows "setprod f A \ setprod g A" ``` hoelzl@35171 ` 1114` ```proof (cases "finite A") ``` hoelzl@35171 ` 1115` ``` case True ``` hoelzl@35171 ` 1116` ``` hence ?thesis "setprod f A \ 0" using subset_refl[of A] ``` hoelzl@35171 ` 1117` ``` proof (induct A rule: finite_subset_induct) ``` hoelzl@35171 ` 1118` ``` case (insert a F) ``` hoelzl@35171 ` 1119` ``` thus "setprod f (insert a F) \ setprod g (insert a F)" "0 \ setprod f (insert a F)" ``` hoelzl@35171 ` 1120` ``` unfolding setprod_insert[OF insert(1,3)] ``` hoelzl@35171 ` 1121` ``` using assms[rule_format,OF insert(2)] insert ``` hoelzl@35171 ` 1122` ``` by (auto intro: mult_mono mult_nonneg_nonneg) ``` hoelzl@35171 ` 1123` ``` qed auto ``` hoelzl@35171 ` 1124` ``` thus ?thesis by simp ``` hoelzl@35171 ` 1125` ```qed auto ``` hoelzl@35171 ` 1126` hoelzl@35171 ` 1127` ```lemma abs_setprod: ``` hoelzl@35171 ` 1128` ``` fixes f :: "'a \ 'b\{linordered_field,abs}" ``` hoelzl@35171 ` 1129` ``` shows "abs (setprod f A) = setprod (\x. abs (f x)) A" ``` hoelzl@35171 ` 1130` ```proof (cases "finite A") ``` hoelzl@35171 ` 1131` ``` case True thus ?thesis ``` huffman@35216 ` 1132` ``` by induct (auto simp add: field_simps abs_mult) ``` hoelzl@35171 ` 1133` ```qed auto ``` hoelzl@35171 ` 1134` haftmann@31017 ` 1135` ```lemma setprod_constant: "finite A ==> (\x\ A. (y::'a::{comm_monoid_mult})) = y^(card A)" ``` nipkow@28853 ` 1136` ```apply (erule finite_induct) ``` huffman@35216 ` 1137` ```apply auto ``` nipkow@28853 ` 1138` ```done ``` nipkow@15402 ` 1139` chaieb@29674 ` 1140` ```lemma setprod_gen_delta: ``` chaieb@29674 ` 1141` ``` assumes fS: "finite S" ``` haftmann@31017 ` 1142` ``` shows "setprod (\k. if k=a then b k else c) S = (if a \ S then (b a ::'a::{comm_monoid_mult}) * c^ (card S - 1) else c^ card S)" ``` chaieb@29674 ` 1143` ```proof- ``` chaieb@29674 ` 1144` ``` let ?f = "(\k. if k=a then b k else c)" ``` chaieb@29674 ` 1145` ``` {assume a: "a \ S" ``` chaieb@29674 ` 1146` ``` hence "\ k\ S. ?f k = c" by simp ``` chaieb@29674 ` 1147` ``` hence ?thesis using a setprod_constant[OF fS, of c] by (simp add: setprod_1 cong add: setprod_cong) } ``` chaieb@29674 ` 1148` ``` moreover ``` chaieb@29674 ` 1149` ``` {assume a: "a \ S" ``` chaieb@29674 ` 1150` ``` let ?A = "S - {a}" ``` chaieb@29674 ` 1151` ``` let ?B = "{a}" ``` chaieb@29674 ` 1152` ``` have eq: "S = ?A \ ?B" using a by blast ``` chaieb@29674 ` 1153` ``` have dj: "?A \ ?B = {}" by simp ``` chaieb@29674 ` 1154` ``` from fS have fAB: "finite ?A" "finite ?B" by auto ``` chaieb@29674 ` 1155` ``` have fA0:"setprod ?f ?A = setprod (\i. c) ?A" ``` chaieb@29674 ` 1156` ``` apply (rule setprod_cong) by auto ``` chaieb@29674 ` 1157` ``` have cA: "card ?A = card S - 1" using fS a by auto ``` chaieb@29674 ` 1158` ``` have fA1: "setprod ?f ?A = c ^ card ?A" unfolding fA0 apply (rule setprod_constant) using fS by auto ``` chaieb@29674 ` 1159` ``` have "setprod ?f ?A * setprod ?f ?B = setprod ?f S" ``` chaieb@29674 ` 1160` ``` using setprod_Un_disjoint[OF fAB dj, of ?f, unfolded eq[symmetric]] ``` chaieb@29674 ` 1161` ``` by simp ``` chaieb@29674 ` 1162` ``` then have ?thesis using a cA ``` haftmann@36349 ` 1163` ``` by (simp add: fA1 field_simps cong add: setprod_cong cong del: if_weak_cong)} ``` chaieb@29674 ` 1164` ``` ultimately show ?thesis by blast ``` chaieb@29674 ` 1165` ```qed ``` chaieb@29674 ` 1166` chaieb@29674 ` 1167` haftmann@35816 ` 1168` ```subsection {* Versions of @{const inf} and @{const sup} on non-empty sets *} ``` haftmann@35816 ` 1169` haftmann@35816 ` 1170` ```no_notation times (infixl "*" 70) ``` haftmann@35816 ` 1171` ```no_notation Groups.one ("1") ``` haftmann@35816 ` 1172` haftmann@35816 ` 1173` ```locale semilattice_big = semilattice + ``` haftmann@35816 ` 1174` ``` fixes F :: "'a set \ 'a" ``` haftmann@35816 ` 1175` ``` assumes F_eq: "finite A \ F A = fold1 (op *) A" ``` haftmann@35816 ` 1176` haftmann@35816 ` 1177` ```sublocale semilattice_big < folding_one_idem proof ``` haftmann@35816 ` 1178` ```qed (simp_all add: F_eq) ``` haftmann@35816 ` 1179` haftmann@35816 ` 1180` ```notation times (infixl "*" 70) ``` haftmann@35816 ` 1181` ```notation Groups.one ("1") ``` haftmann@22917 ` 1182` haftmann@35816 ` 1183` ```context lattice ``` haftmann@35816 ` 1184` ```begin ``` haftmann@35816 ` 1185` haftmann@35816 ` 1186` ```definition Inf_fin :: "'a set \ 'a" ("\\<^bsub>fin\<^esub>_" [900] 900) where ``` haftmann@35816 ` 1187` ``` "Inf_fin = fold1 inf" ``` haftmann@35816 ` 1188` haftmann@35816 ` 1189` ```definition Sup_fin :: "'a set \ 'a" ("\\<^bsub>fin\<^esub>_" [900] 900) where ``` haftmann@35816 ` 1190` ``` "Sup_fin = fold1 sup" ``` haftmann@35816 ` 1191` haftmann@35816 ` 1192` ```end ``` haftmann@35816 ` 1193` haftmann@35816 ` 1194` ```sublocale lattice < Inf_fin!: semilattice_big inf Inf_fin proof ``` haftmann@35816 ` 1195` ```qed (simp add: Inf_fin_def) ``` haftmann@35816 ` 1196` haftmann@35816 ` 1197` ```sublocale lattice < Sup_fin!: semilattice_big sup Sup_fin proof ``` haftmann@35816 ` 1198` ```qed (simp add: Sup_fin_def) ``` haftmann@22917 ` 1199` haftmann@35028 ` 1200` ```context semilattice_inf ``` haftmann@26041 ` 1201` ```begin ``` haftmann@26041 ` 1202` haftmann@36635 ` 1203` ```lemma ab_semigroup_idem_mult_inf: ``` haftmann@36635 ` 1204` ``` "class.ab_semigroup_idem_mult inf" ``` haftmann@35816 ` 1205` ```proof qed (rule inf_assoc inf_commute inf_idem)+ ``` haftmann@35816 ` 1206` haftmann@35816 ` 1207` ```lemma fold_inf_insert[simp]: "finite A \ fold inf b (insert a A) = inf a (fold inf b A)" ``` haftmann@35816 ` 1208` ```by(rule fun_left_comm_idem.fold_insert_idem[OF ab_semigroup_idem_mult.fun_left_comm_idem[OF ab_semigroup_idem_mult_inf]]) ``` haftmann@35816 ` 1209` haftmann@35816 ` 1210` ```lemma inf_le_fold_inf: "finite A \ ALL a:A. b \ a \ inf b c \ fold inf c A" ``` haftmann@35816 ` 1211` ```by (induct pred: finite) (auto intro: le_infI1) ``` haftmann@35816 ` 1212` haftmann@35816 ` 1213` ```lemma fold_inf_le_inf: "finite A \ a \ A \ fold inf b A \ inf a b" ``` haftmann@35816 ` 1214` ```proof(induct arbitrary: a pred:finite) ``` haftmann@35816 ` 1215` ``` case empty thus ?case by simp ``` haftmann@35816 ` 1216` ```next ``` haftmann@35816 ` 1217` ``` case (insert x A) ``` haftmann@35816 ` 1218` ``` show ?case ``` haftmann@35816 ` 1219` ``` proof cases ``` haftmann@35816 ` 1220` ``` assume "A = {}" thus ?thesis using insert by simp ``` haftmann@35816 ` 1221` ``` next ``` haftmann@35816 ` 1222` ``` assume "A \ {}" thus ?thesis using insert by (auto intro: le_infI2) ``` haftmann@35816 ` 1223` ``` qed ``` haftmann@35816 ` 1224` ```qed ``` haftmann@35816 ` 1225` haftmann@26041 ` 1226` ```lemma below_fold1_iff: ``` haftmann@26041 ` 1227` ``` assumes "finite A" "A \ {}" ``` haftmann@26041 ` 1228` ``` shows "x \ fold1 inf A \ (\a\A. x \ a)" ``` haftmann@26041 ` 1229` ```proof - ``` haftmann@29509 ` 1230` ``` interpret ab_semigroup_idem_mult inf ``` haftmann@26041 ` 1231` ``` by (rule ab_semigroup_idem_mult_inf) ``` haftmann@26041 ` 1232` ``` show ?thesis using assms by (induct rule: finite_ne_induct) simp_all ``` haftmann@26041 ` 1233` ```qed ``` haftmann@26041 ` 1234` haftmann@26041 ` 1235` ```lemma fold1_belowI: ``` haftmann@26757 ` 1236` ``` assumes "finite A" ``` haftmann@26041 ` 1237` ``` and "a \ A" ``` haftmann@26041 ` 1238` ``` shows "fold1 inf A \ a" ``` haftmann@26757 ` 1239` ```proof - ``` haftmann@26757 ` 1240` ``` from assms have "A \ {}" by auto ``` haftmann@26757 ` 1241` ``` from `finite A` `A \ {}` `a \ A` show ?thesis ``` haftmann@26757 ` 1242` ``` proof (induct rule: finite_ne_induct) ``` haftmann@26757 ` 1243` ``` case singleton thus ?case by simp ``` haftmann@26041 ` 1244` ``` next ``` haftmann@29509 ` 1245` ``` interpret ab_semigroup_idem_mult inf ``` haftmann@26757 ` 1246` ``` by (rule ab_semigroup_idem_mult_inf) ``` haftmann@26757 ` 1247` ``` case (insert x F) ``` haftmann@26757 ` 1248` ``` from insert(5) have "a = x \ a \ F" by simp ``` haftmann@26757 ` 1249` ``` thus ?case ``` haftmann@26757 ` 1250` ``` proof ``` haftmann@26757 ` 1251` ``` assume "a = x" thus ?thesis using insert ``` nipkow@29667 ` 1252` ``` by (simp add: mult_ac) ``` haftmann@26757 ` 1253` ``` next ``` haftmann@26757 ` 1254` ``` assume "a \ F" ``` haftmann@26757 ` 1255` ``` hence bel: "fold1 inf F \ a" by (rule insert) ``` haftmann@26757 ` 1256` ``` have "inf (fold1 inf (insert x F)) a = inf x (inf (fold1 inf F) a)" ``` nipkow@29667 ` 1257` ``` using insert by (simp add: mult_ac) ``` haftmann@26757 ` 1258` ``` also have "inf (fold1 inf F) a = fold1 inf F" ``` haftmann@26757 ` 1259` ``` using bel by (auto intro: antisym) ``` haftmann@26757 ` 1260` ``` also have "inf x \ = fold1 inf (insert x F)" ``` nipkow@29667 ` 1261` ``` using insert by (simp add: mult_ac) ``` haftmann@26757 ` 1262` ``` finally have aux: "inf (fold1 inf (insert x F)) a = fold1 inf (insert x F)" . ``` haftmann@26757 ` 1263` ``` moreover have "inf (fold1 inf (insert x F)) a \ a" by simp ``` haftmann@26757 ` 1264` ``` ultimately show ?thesis by simp ``` haftmann@26757 ` 1265` ``` qed ``` haftmann@26041 ` 1266` ``` qed ``` haftmann@26041 ` 1267` ```qed ``` haftmann@26041 ` 1268` haftmann@26041 ` 1269` ```end ``` haftmann@26041 ` 1270` haftmann@35816 ` 1271` ```context semilattice_sup ``` haftmann@22917 ` 1272` ```begin ``` haftmann@22917 ` 1273` haftmann@36635 ` 1274` ```lemma ab_semigroup_idem_mult_sup: "class.ab_semigroup_idem_mult sup" ``` haftmann@35816 ` 1275` ```by (rule semilattice_inf.ab_semigroup_idem_mult_inf)(rule dual_semilattice) ``` haftmann@35816 ` 1276` haftmann@35816 ` 1277` ```lemma fold_sup_insert[simp]: "finite A \ fold sup b (insert a A) = sup a (fold sup b A)" ``` haftmann@35816 ` 1278` ```by(rule semilattice_inf.fold_inf_insert)(rule dual_semilattice) ``` haftmann@22917 ` 1279` haftmann@35816 ` 1280` ```lemma fold_sup_le_sup: "finite A \ ALL a:A. a \ b \ fold sup c A \ sup b c" ``` haftmann@35816 ` 1281` ```by(rule semilattice_inf.inf_le_fold_inf)(rule dual_semilattice) ``` haftmann@35816 ` 1282` haftmann@35816 ` 1283` ```lemma sup_le_fold_sup: "finite A \ a \ A \ sup a b \ fold sup b A" ``` haftmann@35816 ` 1284` ```by(rule semilattice_inf.fold_inf_le_inf)(rule dual_semilattice) ``` haftmann@35816 ` 1285` haftmann@35816 ` 1286` ```end ``` haftmann@35816 ` 1287` haftmann@35816 ` 1288` ```context lattice ``` haftmann@35816 ` 1289` ```begin ``` haftmann@25062 ` 1290` wenzelm@31916 ` 1291` ```lemma Inf_le_Sup [simp]: "\ finite A; A \ {} \ \ \\<^bsub>fin\<^esub>A \ \\<^bsub>fin\<^esub>A" ``` haftmann@24342 ` 1292` ```apply(unfold Sup_fin_def Inf_fin_def) ``` nipkow@15500 ` 1293` ```apply(subgoal_tac "EX a. a:A") ``` nipkow@15500 ` 1294` ```prefer 2 apply blast ``` nipkow@15500 ` 1295` ```apply(erule exE) ``` haftmann@22388 ` 1296` ```apply(rule order_trans) ``` haftmann@26757 ` 1297` ```apply(erule (1) fold1_belowI) ``` haftmann@35028 ` 1298` ```apply(erule (1) semilattice_inf.fold1_belowI [OF dual_semilattice]) ``` nipkow@15500 ` 1299` ```done ``` nipkow@15500 ` 1300` haftmann@24342 ` 1301` ```lemma sup_Inf_absorb [simp]: ``` wenzelm@31916 ` 1302` ``` "finite A \ a \ A \ sup a (\\<^bsub>fin\<^esub>A) = a" ``` nipkow@15512 ` 1303` ```apply(subst sup_commute) ``` haftmann@26041 ` 1304` ```apply(simp add: Inf_fin_def sup_absorb2 fold1_belowI) ``` nipkow@15504 ` 1305` ```done ``` nipkow@15504 ` 1306` haftmann@24342 ` 1307` ```lemma inf_Sup_absorb [simp]: ``` wenzelm@31916 ` 1308` ``` "finite A \ a \ A \ inf a (\\<^bsub>fin\<^esub>A) = a" ``` haftmann@26041 ` 1309` ```by (simp add: Sup_fin_def inf_absorb1 ``` haftmann@35028 ` 1310` ``` semilattice_inf.fold1_belowI [OF dual_semilattice]) ``` haftmann@24342 ` 1311` haftmann@24342 ` 1312` ```end ``` haftmann@24342 ` 1313` haftmann@24342 ` 1314` ```context distrib_lattice ``` haftmann@24342 ` 1315` ```begin ``` haftmann@24342 ` 1316` haftmann@24342 ` 1317` ```lemma sup_Inf1_distrib: ``` haftmann@26041 ` 1318` ``` assumes "finite A" ``` haftmann@26041 ` 1319` ``` and "A \ {}" ``` wenzelm@31916 ` 1320` ``` shows "sup x (\\<^bsub>fin\<^esub>A) = \\<^bsub>fin\<^esub>{sup x a|a. a \ A}" ``` haftmann@26041 ` 1321` ```proof - ``` haftmann@29509 ` 1322` ``` interpret ab_semigroup_idem_mult inf ``` haftmann@26041 ` 1323` ``` by (rule ab_semigroup_idem_mult_inf) ``` haftmann@26041 ` 1324` ``` from assms show ?thesis ``` haftmann@26041 ` 1325` ``` by (simp add: Inf_fin_def image_def ``` haftmann@26041 ` 1326` ``` hom_fold1_commute [where h="sup x", OF sup_inf_distrib1]) ``` berghofe@26792 ` 1327` ``` (rule arg_cong [where f="fold1 inf"], blast) ``` haftmann@26041 ` 1328` ```qed ``` nipkow@18423 ` 1329` haftmann@24342 ` 1330` ```lemma sup_Inf2_distrib: ``` haftmann@24342 ` 1331` ``` assumes A: "finite A" "A \ {}" and B: "finite B" "B \ {}" ``` wenzelm@31916 ` 1332` ``` shows "sup (\\<^bsub>fin\<^esub>A) (\\<^bsub>fin\<^esub>B) = \\<^bsub>fin\<^esub>{sup a b|a b. a \ A \ b \ B}" ``` haftmann@24342 ` 1333` ```using A proof (induct rule: finite_ne_induct) ``` nipkow@15500 ` 1334` ``` case singleton thus ?case ``` haftmann@24342 ` 1335` ``` by (simp add: sup_Inf1_distrib [OF B] fold1_singleton_def [OF Inf_fin_def]) ``` nipkow@15500 ` 1336` ```next ``` haftmann@29509 ` 1337` ``` interpret ab_semigroup_idem_mult inf ``` haftmann@26041 ` 1338` ``` by (rule ab_semigroup_idem_mult_inf) ``` nipkow@15500 ` 1339` ``` case (insert x A) ``` haftmann@25062 ` 1340` ``` have finB: "finite {sup x b |b. b \ B}" ``` haftmann@25062 ` 1341` ``` by(rule finite_surj[where f = "sup x", OF B(1)], auto) ``` haftmann@25062 ` 1342` ``` have finAB: "finite {sup a b |a b. a \ A \ b \ B}" ``` nipkow@15500 ` 1343` ``` proof - ``` haftmann@25062 ` 1344` ``` have "{sup a b |a b. a \ A \ b \ B} = (UN a:A. UN b:B. {sup a b})" ``` nipkow@15500 ` 1345` ``` by blast ``` berghofe@15517 ` 1346` ``` thus ?thesis by(simp add: insert(1) B(1)) ``` nipkow@15500 ` 1347` ``` qed ``` haftmann@25062 ` 1348` ``` have ne: "{sup a b |a b. a \ A \ b \ B} \ {}" using insert B by blast ``` wenzelm@31916 ` 1349` ``` have "sup (\\<^bsub>fin\<^esub>(insert x A)) (\\<^bsub>fin\<^esub>B) = sup (inf x (\\<^bsub>fin\<^esub>A)) (\\<^bsub>fin\<^esub>B)" ``` haftmann@26041 ` 1350` ``` using insert by (simp add: fold1_insert_idem_def [OF Inf_fin_def]) ``` wenzelm@31916 ` 1351` ``` also have "\ = inf (sup x (\\<^bsub>fin\<^esub>B)) (sup (\\<^bsub>fin\<^esub>A) (\\<^bsub>fin\<^esub>B))" by(rule sup_inf_distrib2) ``` wenzelm@31916 ` 1352` ``` also have "\ = inf (\\<^bsub>fin\<^esub>{sup x b|b. b \ B}) (\\<^bsub>fin\<^esub>{sup a b|a b. a \ A \ b \ B})" ``` nipkow@15500 ` 1353` ``` using insert by(simp add:sup_Inf1_distrib[OF B]) ``` wenzelm@31916 ` 1354` ``` also have "\ = \\<^bsub>fin\<^esub>({sup x b |b. b \ B} \ {sup a b |a b. a \ A \ b \ B})" ``` wenzelm@31916 ` 1355` ``` (is "_ = \\<^bsub>fin\<^esub>?M") ``` nipkow@15500 ` 1356` ``` using B insert ``` haftmann@26041 ` 1357` ``` by (simp add: Inf_fin_def fold1_Un2 [OF finB _ finAB ne]) ``` haftmann@25062 ` 1358` ``` also have "?M = {sup a b |a b. a \ insert x A \ b \ B}" ``` nipkow@15500 ` 1359` ``` by blast ``` nipkow@15500 ` 1360` ``` finally show ?case . ``` nipkow@15500 ` 1361` ```qed ``` nipkow@15500 ` 1362` haftmann@24342 ` 1363` ```lemma inf_Sup1_distrib: ``` haftmann@26041 ` 1364` ``` assumes "finite A" and "A \ {}" ``` wenzelm@31916 ` 1365` ``` shows "inf x (\\<^bsub>fin\<^esub>A) = \\<^bsub>fin\<^esub>{inf x a|a. a \ A}" ``` haftmann@26041 ` 1366` ```proof - ``` haftmann@29509 ` 1367` ``` interpret ab_semigroup_idem_mult sup ``` haftmann@26041 ` 1368` ``` by (rule ab_semigroup_idem_mult_sup) ``` haftmann@26041 ` 1369` ``` from assms show ?thesis ``` haftmann@26041 ` 1370` ``` by (simp add: Sup_fin_def image_def hom_fold1_commute [where h="inf x", OF inf_sup_distrib1]) ``` berghofe@26792 ` 1371` ``` (rule arg_cong [where f="fold1 sup"], blast) ``` haftmann@26041 ` 1372` ```qed ``` nipkow@18423 ` 1373` haftmann@24342 ` 1374` ```lemma inf_Sup2_distrib: ``` haftmann@24342 ` 1375` ``` assumes A: "finite A" "A \ {}" and B: "finite B" "B \ {}" ``` wenzelm@31916 ` 1376` ``` shows "inf (\\<^bsub>fin\<^esub>A) (\\<^bsub>fin\<^esub>B) = \\<^bsub>fin\<^esub>{inf a b|a b. a \ A \ b \ B}" ``` haftmann@24342 ` 1377` ```using A proof (induct rule: finite_ne_induct) ``` nipkow@18423 ` 1378` ``` case singleton thus ?case ``` haftmann@24342 ` 1379` ``` by(simp add: inf_Sup1_distrib [OF B] fold1_singleton_def [OF Sup_fin_def]) ``` nipkow@18423 ` 1380` ```next ``` nipkow@18423 ` 1381` ``` case (insert x A) ``` haftmann@25062 ` 1382` ``` have finB: "finite {inf x b |b. b \ B}" ``` haftmann@25062 ` 1383` ``` by(rule finite_surj[where f = "%b. inf x b", OF B(1)], auto) ``` haftmann@25062 ` 1384` ``` have finAB: "finite {inf a b |a b. a \ A \ b \ B}" ``` nipkow@18423 ` 1385` ``` proof - ``` haftmann@25062 ` 1386` ``` have "{inf a b |a b. a \ A \ b \ B} = (UN a:A. UN b:B. {inf a b})" ``` nipkow@18423 ` 1387` ``` by blast ``` nipkow@18423 ` 1388` ``` thus ?thesis by(simp add: insert(1) B(1)) ``` nipkow@18423 ` 1389` ``` qed ``` haftmann@25062 ` 1390` ``` have ne: "{inf a b |a b. a \ A \ b \ B} \ {}" using insert B by blast ``` haftmann@29509 ` 1391` ``` interpret ab_semigroup_idem_mult sup ``` haftmann@26041 ` 1392` ``` by (rule ab_semigroup_idem_mult_sup) ``` wenzelm@31916 ` 1393` ``` have "inf (\\<^bsub>fin\<^esub>(insert x A)) (\\<^bsub>fin\<^esub>B) = inf (sup x (\\<^bsub>fin\<^esub>A)) (\\<^bsub>fin\<^esub>B)" ``` haftmann@26041 ` 1394` ``` using insert by (simp add: fold1_insert_idem_def [OF Sup_fin_def]) ``` wenzelm@31916 ` 1395` ``` also have "\ = sup (inf x (\\<^bsub>fin\<^esub>B)) (inf (\\<^bsub>fin\<^esub>A) (\\<^bsub>fin\<^esub>B))" by(rule inf_sup_distrib2) ``` wenzelm@31916 ` 1396` ``` also have "\ = sup (\\<^bsub>fin\<^esub>{inf x b|b. b \ B}) (\\<^bsub>fin\<^esub>{inf a b|a b. a \ A \ b \ B})" ``` nipkow@18423 ` 1397` ``` using insert by(simp add:inf_Sup1_distrib[OF B]) ``` wenzelm@31916 ` 1398` ``` also have "\ = \\<^bsub>fin\<^esub>({inf x b |b. b \ B} \ {inf a b |a b. a \ A \ b \ B})" ``` wenzelm@31916 ` 1399` ``` (is "_ = \\<^bsub>fin\<^esub>?M") ``` nipkow@18423 ` 1400` ``` using B insert ``` haftmann@26041 ` 1401` ``` by (simp add: Sup_fin_def fold1_Un2 [OF finB _ finAB ne]) ``` haftmann@25062 ` 1402` ``` also have "?M = {inf a b |a b. a \ insert x A \ b \ B}" ``` nipkow@18423 ` 1403` ``` by blast ``` nipkow@18423 ` 1404` ``` finally show ?case . ``` nipkow@18423 ` 1405` ```qed ``` nipkow@18423 ` 1406` haftmann@24342 ` 1407` ```end ``` haftmann@24342 ` 1408` haftmann@35719 ` 1409` ```context complete_lattice ``` haftmann@35719 ` 1410` ```begin ``` haftmann@35719 ` 1411` haftmann@35719 ` 1412` ```lemma Inf_fin_Inf: ``` haftmann@35719 ` 1413` ``` assumes "finite A" and "A \ {}" ``` haftmann@35719 ` 1414` ``` shows "\\<^bsub>fin\<^esub>A = Inf A" ``` haftmann@35719 ` 1415` ```proof - ``` haftmann@35719 ` 1416` ``` interpret ab_semigroup_idem_mult inf ``` haftmann@35719 ` 1417` ``` by (rule ab_semigroup_idem_mult_inf) ``` haftmann@35719 ` 1418` ``` from `A \ {}` obtain b B where "A = insert b B" by auto ``` haftmann@35719 ` 1419` ``` moreover with `finite A` have "finite B" by simp ``` haftmann@35719 ` 1420` ``` ultimately show ?thesis ``` haftmann@35719 ` 1421` ``` by (simp add: Inf_fin_def fold1_eq_fold_idem inf_Inf_fold_inf [symmetric]) ``` haftmann@35719 ` 1422` ``` (simp add: Inf_fold_inf) ``` haftmann@35719 ` 1423` ```qed ``` haftmann@35719 ` 1424` haftmann@35719 ` 1425` ```lemma Sup_fin_Sup: ``` haftmann@35719 ` 1426` ``` assumes "finite A" and "A \ {}" ``` haftmann@35719 ` 1427` ``` shows "\\<^bsub>fin\<^esub>A = Sup A" ``` haftmann@35719 ` 1428` ```proof - ``` haftmann@35719 ` 1429` ``` interpret ab_semigroup_idem_mult sup ``` haftmann@35719 ` 1430` ``` by (rule ab_semigroup_idem_mult_sup) ``` haftmann@35719 ` 1431` ``` from `A \ {}` obtain b B where "A = insert b B" by auto ``` haftmann@35719 ` 1432` ``` moreover with `finite A` have "finite B" by simp ``` haftmann@35719 ` 1433` ``` ultimately show ?thesis ``` haftmann@35719 ` 1434` ``` by (simp add: Sup_fin_def fold1_eq_fold_idem sup_Sup_fold_sup [symmetric]) ``` haftmann@35719 ` 1435` ``` (simp add: Sup_fold_sup) ``` haftmann@35719 ` 1436` ```qed ``` haftmann@35719 ` 1437` haftmann@35719 ` 1438` ```end ``` haftmann@35719 ` 1439` haftmann@22917 ` 1440` haftmann@35816 ` 1441` ```subsection {* Versions of @{const min} and @{const max} on non-empty sets *} ``` haftmann@35816 ` 1442` haftmann@35816 ` 1443` ```definition (in linorder) Min :: "'a set \ 'a" where ``` haftmann@35816 ` 1444` ``` "Min = fold1 min" ``` haftmann@22917 ` 1445` haftmann@35816 ` 1446` ```definition (in linorder) Max :: "'a set \ 'a" where ``` haftmann@35816 ` 1447` ``` "Max = fold1 max" ``` haftmann@35816 ` 1448` haftmann@35816 ` 1449` ```sublocale linorder < Min!: semilattice_big min Min proof ``` haftmann@35816 ` 1450` ```qed (simp add: Min_def) ``` haftmann@35816 ` 1451` haftmann@35816 ` 1452` ```sublocale linorder < Max!: semilattice_big max Max proof ``` haftmann@35816 ` 1453` ```qed (simp add: Max_def) ``` haftmann@22917 ` 1454` haftmann@24342 ` 1455` ```context linorder ``` haftmann@22917 ` 1456` ```begin ``` haftmann@22917 ` 1457` haftmann@35816 ` 1458` ```lemmas Min_singleton = Min.singleton ``` haftmann@35816 ` 1459` ```lemmas Max_singleton = Max.singleton ``` haftmann@35816 ` 1460` haftmann@35816 ` 1461` ```lemma Min_insert: ``` haftmann@35816 ` 1462` ``` assumes "finite A" and "A \ {}" ``` haftmann@35816 ` 1463` ``` shows "Min (insert x A) = min x (Min A)" ``` haftmann@35816 ` 1464` ``` using assms by simp ``` haftmann@35816 ` 1465` haftmann@35816 ` 1466` ```lemma Max_insert: ``` haftmann@35816 ` 1467` ``` assumes "finite A" and "A \ {}" ``` haftmann@35816 ` 1468` ``` shows "Max (insert x A) = max x (Max A)" ``` haftmann@35816 ` 1469` ``` using assms by simp ``` haftmann@35816 ` 1470` haftmann@35816 ` 1471` ```lemma Min_Un: ``` haftmann@35816 ` 1472` ``` assumes "finite A" and "A \ {}" and "finite B" and "B \ {}" ``` haftmann@35816 ` 1473` ``` shows "Min (A \ B) = min (Min A) (Min B)" ``` haftmann@35816 ` 1474` ``` using assms by (rule Min.union_idem) ``` haftmann@35816 ` 1475` haftmann@35816 ` 1476` ```lemma Max_Un: ``` haftmann@35816 ` 1477` ``` assumes "finite A" and "A \ {}" and "finite B" and "B \ {}" ``` haftmann@35816 ` 1478` ``` shows "Max (A \ B) = max (Max A) (Max B)" ``` haftmann@35816 ` 1479` ``` using assms by (rule Max.union_idem) ``` haftmann@35816 ` 1480` haftmann@35816 ` 1481` ```lemma hom_Min_commute: ``` haftmann@35816 ` 1482` ``` assumes "\x y. h (min x y) = min (h x) (h y)" ``` haftmann@35816 ` 1483` ``` and "finite N" and "N \ {}" ``` haftmann@35816 ` 1484` ``` shows "h (Min N) = Min (h ` N)" ``` haftmann@35816 ` 1485` ``` using assms by (rule Min.hom_commute) ``` haftmann@35816 ` 1486` haftmann@35816 ` 1487` ```lemma hom_Max_commute: ``` haftmann@35816 ` 1488` ``` assumes "\x y. h (max x y) = max (h x) (h y)" ``` haftmann@35816 ` 1489` ``` and "finite N" and "N \ {}" ``` haftmann@35816 ` 1490` ``` shows "h (Max N) = Max (h ` N)" ``` haftmann@35816 ` 1491` ``` using assms by (rule Max.hom_commute) ``` haftmann@35816 ` 1492` haftmann@26041 ` 1493` ```lemma ab_semigroup_idem_mult_min: ``` haftmann@36635 ` 1494` ``` "class.ab_semigroup_idem_mult min" ``` haftmann@28823 ` 1495` ``` proof qed (auto simp add: min_def) ``` haftmann@26041 ` 1496` haftmann@26041 ` 1497` ```lemma ab_semigroup_idem_mult_max: ``` haftmann@36635 ` 1498` ``` "class.ab_semigroup_idem_mult max" ``` haftmann@28823 ` 1499` ``` proof qed (auto simp add: max_def) ``` haftmann@26041 ` 1500` haftmann@26041 ` 1501` ```lemma max_lattice: ``` haftmann@36635 ` 1502` ``` "class.semilattice_inf (op \) (op >) max" ``` haftmann@32203 ` 1503` ``` by (fact min_max.dual_semilattice) ``` haftmann@26041 ` 1504` haftmann@26041 ` 1505` ```lemma dual_max: ``` haftmann@26041 ` 1506` ``` "ord.max (op \) = min" ``` haftmann@32642 ` 1507` ``` by (auto simp add: ord.max_def_raw min_def expand_fun_eq) ``` haftmann@26041 ` 1508` haftmann@26041 ` 1509` ```lemma dual_min: ``` haftmann@26041 ` 1510` ``` "ord.min (op \) = max" ``` haftmann@32642 ` 1511` ``` by (auto simp add: ord.min_def_raw max_def expand_fun_eq) ``` haftmann@26041 ` 1512` haftmann@26041 ` 1513` ```lemma strict_below_fold1_iff: ``` haftmann@26041 ` 1514` ``` assumes "finite A" and "A \ {}" ``` haftmann@26041 ` 1515` ``` shows "x < fold1 min A \ (\a\A. x < a)" ``` haftmann@26041 ` 1516` ```proof - ``` haftmann@29509 ` 1517` ``` interpret ab_semigroup_idem_mult min ``` haftmann@26041 ` 1518` ``` by (rule ab_semigroup_idem_mult_min) ``` haftmann@26041 ` 1519` ``` from assms show ?thesis ``` haftmann@26041 ` 1520` ``` by (induct rule: finite_ne_induct) ``` haftmann@26041 ` 1521` ``` (simp_all add: fold1_insert) ``` haftmann@26041 ` 1522` ```qed ``` haftmann@26041 ` 1523` haftmann@26041 ` 1524` ```lemma fold1_below_iff: ``` haftmann@26041 ` 1525` ``` assumes "finite A" and "A \ {}" ``` haftmann@26041 ` 1526` ``` shows "fold1 min A \ x \ (\a\A. a \ x)" ``` haftmann@26041 ` 1527` ```proof - ``` haftmann@29509 ` 1528` ``` interpret ab_semigroup_idem_mult min ``` haftmann@26041 ` 1529` ``` by (rule ab_semigroup_idem_mult_min) ``` haftmann@26041 ` 1530` ``` from assms show ?thesis ``` haftmann@26041 ` 1531` ``` by (induct rule: finite_ne_induct) ``` haftmann@26041 ` 1532` ``` (simp_all add: fold1_insert min_le_iff_disj) ``` haftmann@26041 ` 1533` ```qed ``` haftmann@26041 ` 1534` haftmann@26041 ` 1535` ```lemma fold1_strict_below_iff: ``` haftmann@26041 ` 1536` ``` assumes "finite A" and "A \ {}" ``` haftmann@26041 ` 1537` ``` shows "fold1 min A < x \ (\a\A. a < x)" ``` haftmann@26041 ` 1538` ```proof - ``` haftmann@29509 ` 1539` ``` interpret ab_semigroup_idem_mult min ``` haftmann@26041 ` 1540` ``` by (rule ab_semigroup_idem_mult_min) ``` haftmann@26041 ` 1541` ``` from assms show ?thesis ``` haftmann@26041 ` 1542` ``` by (induct rule: finite_ne_induct) ``` haftmann@26041 ` 1543` ``` (simp_all add: fold1_insert min_less_iff_disj) ``` haftmann@26041 ` 1544` ```qed ``` haftmann@26041 ` 1545` haftmann@26041 ` 1546` ```lemma fold1_antimono: ``` haftmann@26041 ` 1547` ``` assumes "A \ {}" and "A \ B" and "finite B" ``` haftmann@26041 ` 1548` ``` shows "fold1 min B \ fold1 min A" ``` haftmann@26041 ` 1549` ```proof cases ``` haftmann@26041 ` 1550` ``` assume "A = B" thus ?thesis by simp ``` haftmann@26041 ` 1551` ```next ``` haftmann@29509 ` 1552` ``` interpret ab_semigroup_idem_mult min ``` haftmann@26041 ` 1553` ``` by (rule ab_semigroup_idem_mult_min) ``` haftmann@26041 ` 1554` ``` assume "A \ B" ``` haftmann@26041 ` 1555` ``` have B: "B = A \ (B-A)" using `A \ B` by blast ``` haftmann@26041 ` 1556` ``` have "fold1 min B = fold1 min (A \ (B-A))" by(subst B)(rule refl) ``` haftmann@26041 ` 1557` ``` also have "\ = min (fold1 min A) (fold1 min (B-A))" ``` haftmann@26041 ` 1558` ``` proof - ``` haftmann@26041 ` 1559` ``` have "finite A" by(rule finite_subset[OF `A \ B` `finite B`]) ``` haftmann@26041 ` 1560` ``` moreover have "finite(B-A)" by(rule finite_Diff[OF `finite B`]) (* by(blast intro:finite_Diff prems) fails *) ``` haftmann@26041 ` 1561` ``` moreover have "(B-A) \ {}" using prems by blast ``` haftmann@26041 ` 1562` ``` moreover have "A Int (B-A) = {}" using prems by blast ``` haftmann@26041 ` 1563` ``` ultimately show ?thesis using `A \ {}` by (rule_tac fold1_Un) ``` haftmann@26041 ` 1564` ``` qed ``` haftmann@26041 ` 1565` ``` also have "\ \ fold1 min A" by (simp add: min_le_iff_disj) ``` haftmann@26041 ` 1566` ``` finally show ?thesis . ``` haftmann@26041 ` 1567` ```qed ``` haftmann@26041 ` 1568` paulson@24427 ` 1569` ```lemma Min_in [simp]: ``` haftmann@26041 ` 1570` ``` assumes "finite A" and "A \ {}" ``` haftmann@26041 ` 1571` ``` shows "Min A \ A" ``` haftmann@26041 ` 1572` ```proof - ``` haftmann@29509 ` 1573` ``` interpret ab_semigroup_idem_mult min ``` haftmann@26041 ` 1574` ``` by (rule ab_semigroup_idem_mult_min) ``` haftmann@26041 ` 1575` ``` from assms fold1_in show ?thesis by (fastsimp simp: Min_def min_def) ``` haftmann@26041 ` 1576` ```qed ``` nipkow@15392 ` 1577` paulson@24427 ` 1578` ```lemma Max_in [simp]: ``` haftmann@26041 ` 1579` ``` assumes "finite A" and "A \ {}" ``` haftmann@26041 ` 1580` ``` shows "Max A \ A" ``` haftmann@26041 ` 1581` ```proof - ``` haftmann@29509 ` 1582` ``` interpret ab_semigroup_idem_mult max ``` haftmann@26041 ` 1583` ``` by (rule ab_semigroup_idem_mult_max) ``` haftmann@26041 ` 1584` ``` from assms fold1_in [of A] show ?thesis by (fastsimp simp: Max_def max_def) ``` haftmann@26041 ` 1585` ```qed ``` haftmann@26041 ` 1586` haftmann@26041 ` 1587` ```lemma Min_le [simp]: ``` haftmann@26757 ` 1588` ``` assumes "finite A" and "x \ A" ``` haftmann@26041 ` 1589` ``` shows "Min A \ x" ``` haftmann@32203 ` 1590` ``` using assms by (simp add: Min_def min_max.fold1_belowI) ``` haftmann@26041 ` 1591` haftmann@26041 ` 1592` ```lemma Max_ge [simp]: ``` haftmann@26757 ` 1593` ``` assumes "finite A" and "x \ A" ``` haftmann@26041 ` 1594` ``` shows "x \ Max A" ``` haftmann@26041 ` 1595` ```proof - ``` haftmann@35028 ` 1596` ``` interpret semilattice_inf "op \" "op >" max ``` haftmann@26041 ` 1597` ``` by (rule max_lattice) ``` haftmann@26041 ` 1598` ``` from assms show ?thesis by (simp add: Max_def fold1_belowI) ``` haftmann@26041 ` 1599` ```qed ``` haftmann@26041 ` 1600` blanchet@35828 ` 1601` ```lemma Min_ge_iff [simp, no_atp]: ``` haftmann@26041 ` 1602` ``` assumes "finite A" and "A \ {}" ``` haftmann@26041 ` 1603` ``` shows "x \ Min A \ (\a\A. x \ a)" ``` haftmann@32203 ` 1604` ``` using assms by (simp add: Min_def min_max.below_fold1_iff) ``` haftmann@26041 ` 1605` blanchet@35828 ` 1606` ```lemma Max_le_iff [simp, no_atp]: ``` haftmann@26041 ` 1607` ``` assumes "finite A" and "A \ {}" ``` haftmann@26041 ` 1608` ``` shows "Max A \ x \ (\a\A. a \ x)" ``` haftmann@26041 ` 1609` ```proof - ``` haftmann@35028 ` 1610` ``` interpret semilattice_inf "op \" "op >" max ``` haftmann@26041 ` 1611` ``` by (rule max_lattice) ``` haftmann@26041 ` 1612` ``` from assms show ?thesis by (simp add: Max_def below_fold1_iff) ``` haftmann@26041 ` 1613` ```qed ``` haftmann@26041 ` 1614` blanchet@35828 ` 1615` ```lemma Min_gr_iff [simp, no_atp]: ``` haftmann@26041 ` 1616` ``` assumes "finite A" and "A \ {}" ``` haftmann@26041 ` 1617` ``` shows "x < Min A \ (\a\A. x < a)" ``` haftmann@32203 ` 1618` ``` using assms by (simp add: Min_def strict_below_fold1_iff) ``` haftmann@26041 ` 1619` blanchet@35828 ` 1620` ```lemma Max_less_iff [simp, no_atp]: ``` haftmann@26041 ` 1621` ``` assumes "finite A" and "A \ {}" ``` haftmann@26041 ` 1622` ``` shows "Max A < x \ (\a\A. a < x)" ``` haftmann@26041 ` 1623` ```proof - ``` haftmann@32203 ` 1624` ``` interpret dual: linorder "op \" "op >" ``` haftmann@26041 ` 1625` ``` by (rule dual_linorder) ``` haftmann@26041 ` 1626` ``` from assms show ?thesis ``` haftmann@32203 ` 1627` ``` by (simp add: Max_def dual.strict_below_fold1_iff [folded dual.dual_max]) ``` haftmann@26041 ` 1628` ```qed ``` nipkow@18493 ` 1629` blanchet@35828 ` 1630` ```lemma Min_le_iff [no_atp]: ``` haftmann@26041 ` 1631` ``` assumes "finite A" and "A \ {}" ``` haftmann@26041 ` 1632` ``` shows "Min A \ x \ (\a\A. a \ x)" ``` haftmann@32203 ` 1633` ``` using assms by (simp add: Min_def fold1_below_iff) ``` nipkow@15497 ` 1634` blanchet@35828 ` 1635` ```lemma Max_ge_iff [no_atp]: ``` haftmann@26041 ` 1636` ``` assumes "finite A" and "A \ {}" ``` haftmann@26041 ` 1637` ``` shows "x \ Max A \ (\a\A. x \ a)" ``` haftmann@26041 ` 1638` ```proof - ``` haftmann@32203 ` 1639` ``` interpret dual: linorder "op \" "op >" ``` haftmann@26041 ` 1640` ``` by (rule dual_linorder) ``` haftmann@26041 ` 1641` ``` from assms show ?thesis ``` haftmann@32203 ` 1642` ``` by (simp add: Max_def dual.fold1_below_iff [folded dual.dual_max]) ``` haftmann@26041 ` 1643` ```qed ``` haftmann@22917 ` 1644` blanchet@35828 ` 1645` ```lemma Min_less_iff [no_atp]: ``` haftmann@26041 ` 1646` ``` assumes "finite A" and "A \ {}" ``` haftmann@26041 ` 1647` ``` shows "Min A < x \ (\a\A. a < x)" ``` haftmann@32203 ` 1648` ``` using assms by (simp add: Min_def fold1_strict_below_iff) ``` haftmann@22917 ` 1649` blanchet@35828 ` 1650` ```lemma Max_gr_iff [no_atp]: ``` haftmann@26041 ` 1651` ``` assumes "finite A" and "A \ {}" ``` haftmann@26041 ` 1652` ``` shows "x < Max A \ (\a\A. x < a)" ``` haftmann@26041 ` 1653` ```proof - ``` haftmann@32203 ` 1654` ``` interpret dual: linorder "op \" "op >" ``` haftmann@26041 ` 1655` ``` by (rule dual_linorder) ``` haftmann@26041 ` 1656` ``` from assms show ?thesis ``` haftmann@32203 ` 1657` ``` by (simp add: Max_def dual.fold1_strict_below_iff [folded dual.dual_max]) ``` haftmann@26041 ` 1658` ```qed ``` haftmann@26041 ` 1659` haftmann@30325 ` 1660` ```lemma Min_eqI: ``` haftmann@30325 ` 1661` ``` assumes "finite A" ``` haftmann@30325 ` 1662` ``` assumes "\y. y \ A \ y \ x" ``` haftmann@30325 ` 1663` ``` and "x \ A" ``` haftmann@30325 ` 1664` ``` shows "Min A = x" ``` haftmann@30325 ` 1665` ```proof (rule antisym) ``` haftmann@30325 ` 1666` ``` from `x \ A` have "A \ {}" by auto ``` haftmann@30325 ` 1667` ``` with assms show "Min A \ x" by simp ``` haftmann@30325 ` 1668` ```next ``` haftmann@30325 ` 1669` ``` from assms show "x \ Min A" by simp ``` haftmann@30325 ` 1670` ```qed ``` haftmann@30325 ` 1671` haftmann@30325 ` 1672` ```lemma Max_eqI: ``` haftmann@30325 ` 1673` ``` assumes "finite A" ``` haftmann@30325 ` 1674` ``` assumes "\y. y \ A \ y \ x" ``` haftmann@30325 ` 1675` ``` and "x \ A" ``` haftmann@30325 ` 1676` ``` shows "Max A = x" ``` haftmann@30325 ` 1677` ```proof (rule antisym) ``` haftmann@30325 ` 1678` ``` from `x \ A` have "A \ {}" by auto ``` haftmann@30325 ` 1679` ``` with assms show "Max A \ x" by simp ``` haftmann@30325 ` 1680` ```next ``` haftmann@30325 ` 1681` ``` from assms show "x \ Max A" by simp ``` haftmann@30325 ` 1682` ```qed ``` haftmann@30325 ` 1683` haftmann@26041 ` 1684` ```lemma Min_antimono: ``` haftmann@26041 ` 1685` ``` assumes "M \ N" and "M \ {}" and "finite N" ``` haftmann@26041 ` 1686` ``` shows "Min N \ Min M" ``` haftmann@32203 ` 1687` ``` using assms by (simp add: Min_def fold1_antimono) ``` haftmann@26041 ` 1688` haftmann@26041 ` 1689` ```lemma Max_mono: ``` haftmann@26041 ` 1690` ``` assumes "M \ N" and "M \ {}" and "finite N" ``` haftmann@26041 ` 1691` ``` shows "Max M \ Max N" ``` haftmann@26041 ` 1692` ```proof - ``` haftmann@32203 ` 1693` ``` interpret dual: linorder "op \" "op >" ``` haftmann@26041 ` 1694` ``` by (rule dual_linorder) ``` haftmann@26041 ` 1695` ``` from assms show ?thesis ``` haftmann@32203 ` 1696` ``` by (simp add: Max_def dual.fold1_antimono [folded dual.dual_max]) ``` haftmann@26041 ` 1697` ```qed ``` haftmann@22917 ` 1698` nipkow@32006 ` 1699` ```lemma finite_linorder_max_induct[consumes 1, case_names empty insert]: ``` urbanc@36079 ` 1700` ``` assumes fin: "finite A" ``` urbanc@36079 ` 1701` ``` and empty: "P {}" ``` urbanc@36079 ` 1702` ``` and insert: "(!!b A. finite A \ ALL a:A. a < b \ P A \ P(insert b A))" ``` urbanc@36079 ` 1703` ``` shows "P A" ``` urbanc@36079 ` 1704` ```using fin empty insert ``` nipkow@32006 ` 1705` ```proof (induct rule: finite_psubset_induct) ``` urbanc@36079 ` 1706` ``` case (psubset A) ``` urbanc@36079 ` 1707` ``` have IH: "\B. \B < A; P {}; (\A b. \finite A; \a\A. a \ P (insert b A))\ \ P B" by fact ``` urbanc@36079 ` 1708` ``` have fin: "finite A" by fact ``` urbanc@36079 ` 1709` ``` have empty: "P {}" by fact ``` urbanc@36079 ` 1710` ``` have step: "\b A. \finite A; \a\A. a < b; P A\ \ P (insert b A)" by fact ``` krauss@26748 ` 1711` ``` show "P A" ``` haftmann@26757 ` 1712` ``` proof (cases "A = {}") ``` urbanc@36079 ` 1713` ``` assume "A = {}" ``` urbanc@36079 ` 1714` ``` then show "P A" using `P {}` by simp ``` krauss@26748 ` 1715` ``` next ``` urbanc@36079 ` 1716` ``` let ?B = "A - {Max A}" ``` urbanc@36079 ` 1717` ``` let ?A = "insert (Max A) ?B" ``` urbanc@36079 ` 1718` ``` have "finite ?B" using `finite A` by simp ``` krauss@26748 ` 1719` ``` assume "A \ {}" ``` krauss@26748 ` 1720` ``` with `finite A` have "Max A : A" by auto ``` urbanc@36079 ` 1721` ``` then have A: "?A = A" using insert_Diff_single insert_absorb by auto ``` urbanc@36079 ` 1722` ``` then have "P ?B" using `P {}` step IH[of ?B] by blast ``` urbanc@36079 ` 1723` ``` moreover ``` urbanc@36079 ` 1724` ``` have "\a\?B. a < Max A" using Max_ge [OF `finite A`] by fastsimp ``` nipkow@32006 ` 1725` ``` ultimately show "P A" using A insert_Diff_single step[OF `finite ?B`] by fastsimp ``` krauss@26748 ` 1726` ``` qed ``` krauss@26748 ` 1727` ```qed ``` krauss@26748 ` 1728` nipkow@32006 ` 1729` ```lemma finite_linorder_min_induct[consumes 1, case_names empty insert]: ``` nipkow@33434 ` 1730` ``` "\finite A; P {}; \b A. \finite A; \a\A. b < a; P A\ \ P (insert b A)\ \ P A" ``` nipkow@32006 ` 1731` ```by(rule linorder.finite_linorder_max_induct[OF dual_linorder]) ``` nipkow@32006 ` 1732` haftmann@22917 ` 1733` ```end ``` haftmann@22917 ` 1734` haftmann@35028 ` 1735` ```context linordered_ab_semigroup_add ``` haftmann@22917 ` 1736` ```begin ``` haftmann@22917 ` 1737` haftmann@22917 ` 1738` ```lemma add_Min_commute: ``` haftmann@22917 ` 1739` ``` fixes k ``` haftmann@25062 ` 1740` ``` assumes "finite N" and "N \ {}" ``` haftmann@25062 ` 1741` ``` shows "k + Min N = Min {k + m | m. m \ N}" ``` haftmann@25062 ` 1742` ```proof - ``` haftmann@25062 ` 1743` ``` have "\x y. k + min x y = min (k + x) (k + y)" ``` haftmann@25062 ` 1744` ``` by (simp add: min_def not_le) ``` haftmann@25062 ` 1745` ``` (blast intro: antisym less_imp_le add_left_mono) ``` haftmann@25062 ` 1746` ``` with assms show ?thesis ``` haftmann@25062 ` 1747` ``` using hom_Min_commute [of "plus k" N] ``` haftmann@25062 ` 1748` ``` by simp (blast intro: arg_cong [where f = Min]) ``` haftmann@25062 ` 1749` ```qed ``` haftmann@22917 ` 1750` haftmann@22917 ` 1751` ```lemma add_Max_commute: ``` haftmann@22917 ` 1752` ``` fixes k ``` haftmann@25062 ` 1753` ``` assumes "finite N" and "N \ {}" ``` haftmann@25062 ` 1754` ``` shows "k + Max N = Max {k + m | m. m \ N}" ``` haftmann@25062 ` 1755` ```proof - ``` haftmann@25062 ` 1756` ``` have "\x y. k + max x y = max (k + x) (k + y)" ``` haftmann@25062 ` 1757` ``` by (simp add: max_def not_le) ``` haftmann@25062 ` 1758` ``` (blast intro: antisym less_imp_le add_left_mono) ``` haftmann@25062 ` 1759` ``` with assms show ?thesis ``` haftmann@25062 ` 1760` ``` using hom_Max_commute [of "plus k" N] ``` haftmann@25062 ` 1761` ``` by simp (blast intro: arg_cong [where f = Max]) ``` haftmann@25062 ` 1762` ```qed ``` haftmann@22917 ` 1763` haftmann@22917 ` 1764` ```end ``` haftmann@22917 ` 1765` haftmann@35034 ` 1766` ```context linordered_ab_group_add ``` haftmann@35034 ` 1767` ```begin ``` haftmann@35034 ` 1768` haftmann@35034 ` 1769` ```lemma minus_Max_eq_Min [simp]: ``` haftmann@35034 ` 1770` ``` "finite S \ S \ {} \ - (Max S) = Min (uminus ` S)" ``` haftmann@35034 ` 1771` ``` by (induct S rule: finite_ne_induct) (simp_all add: minus_max_eq_min) ``` haftmann@35034 ` 1772` haftmann@35034 ` 1773` ```lemma minus_Min_eq_Max [simp]: ``` haftmann@35034 ` 1774` ``` "finite S \ S \ {} \ - (Min S) = Max (uminus ` S)" ``` haftmann@35034 ` 1775` ``` by (induct S rule: finite_ne_induct) (simp_all add: minus_min_eq_max) ``` haftmann@35034 ` 1776` haftmann@35034 ` 1777` ```end ``` haftmann@35034 ` 1778` haftmann@25571 ` 1779` ```end ```