equal
deleted
inserted
replaced
1 (* Title: HOL/Finite_Set.thy |
1 (* Title: HOL/Finite_Set.thy |
2 ID: $Id$ |
2 ID: $Id$ |
3 Author: Tobias Nipkow, Lawrence C Paulson and Markus Wenzel |
3 Author: Tobias Nipkow, Lawrence C Paulson and Markus Wenzel |
4 Additions by Jeremy Avigad in Feb 2004 |
4 with contributions by Jeremy Avigad |
5 *) |
5 *) |
6 |
6 |
7 header {* Finite sets *} |
7 header {* Finite sets *} |
8 |
8 |
9 theory Finite_Set |
9 theory Finite_Set |
1135 by (simp add:setsum_Un_disjoint del:Un_Diff_cancel) |
1135 by (simp add:setsum_Un_disjoint del:Un_Diff_cancel) |
1136 also have "A \<union> (B-A) = B" using sub by blast |
1136 also have "A \<union> (B-A) = B" using sub by blast |
1137 finally show ?thesis . |
1137 finally show ?thesis . |
1138 qed |
1138 qed |
1139 |
1139 |
|
1140 lemma setsum_mono3: "finite B ==> A <= B ==> |
|
1141 ALL x: B - A. |
|
1142 0 <= ((f x)::'a::{comm_monoid_add,pordered_ab_semigroup_add}) ==> |
|
1143 setsum f A <= setsum f B" |
|
1144 apply (subgoal_tac "setsum f B = setsum f A + setsum f (B - A)") |
|
1145 apply (erule ssubst) |
|
1146 apply (subgoal_tac "setsum f A + 0 <= setsum f A + setsum f (B - A)") |
|
1147 apply simp |
|
1148 apply (rule add_left_mono) |
|
1149 apply (erule setsum_nonneg) |
|
1150 apply (subst setsum_Un_disjoint [THEN sym]) |
|
1151 apply (erule finite_subset, assumption) |
|
1152 apply (rule finite_subset) |
|
1153 prefer 2 |
|
1154 apply assumption |
|
1155 apply auto |
|
1156 apply (rule setsum_cong) |
|
1157 apply auto |
|
1158 done |
|
1159 |
1140 (* FIXME: this is distributitivty, name as such! *) |
1160 (* FIXME: this is distributitivty, name as such! *) |
1141 |
1161 |
1142 lemma setsum_mult: |
1162 lemma setsum_mult: |
1143 fixes f :: "'a => ('b::semiring_0_cancel)" |
1163 fixes f :: "'a => ('b::semiring_0_cancel)" |
1144 shows "r * setsum f A = setsum (%n. r * f n) A" |
1164 shows "r * setsum f A = setsum (%n. r * f n) A" |
1195 case empty thus ?case by simp |
1215 case empty thus ?case by simp |
1196 next |
1216 next |
1197 case (insert a A) |
1217 case (insert a A) |
1198 hence "\<bar>\<Sum>a\<in>insert a A. \<bar>f a\<bar>\<bar> = \<bar>\<bar>f a\<bar> + (\<Sum>a\<in>A. \<bar>f a\<bar>)\<bar>" by simp |
1218 hence "\<bar>\<Sum>a\<in>insert a A. \<bar>f a\<bar>\<bar> = \<bar>\<bar>f a\<bar> + (\<Sum>a\<in>A. \<bar>f a\<bar>)\<bar>" by simp |
1199 also have "\<dots> = \<bar>\<bar>f a\<bar> + \<bar>\<Sum>a\<in>A. \<bar>f a\<bar>\<bar>\<bar>" using insert by simp |
1219 also have "\<dots> = \<bar>\<bar>f a\<bar> + \<bar>\<Sum>a\<in>A. \<bar>f a\<bar>\<bar>\<bar>" using insert by simp |
1200 also have "\<dots> = \<bar>f a\<bar> + \<bar>\<Sum>a\<in>A. \<bar>f a\<bar>\<bar>" by simp |
1220 also have "\<dots> = \<bar>f a\<bar> + \<bar>\<Sum>a\<in>A. \<bar>f a\<bar>\<bar>" |
|
1221 by (simp del: abs_of_nonneg) |
1201 also have "\<dots> = (\<Sum>a\<in>insert a A. \<bar>f a\<bar>)" using insert by simp |
1222 also have "\<dots> = (\<Sum>a\<in>insert a A. \<bar>f a\<bar>)" using insert by simp |
1202 finally show ?case . |
1223 finally show ?case . |
1203 qed |
1224 qed |
1204 next |
1225 next |
1205 case False thus ?thesis by (simp add: setsum_def) |
1226 case False thus ?thesis by (simp add: setsum_def) |