src/HOL/GroupTheory/Summation.thy
 changeset 13906 eefdd6b14508 parent 13905 3e496c70f2f3 child 13907 2bc462b99e70
1.1 --- a/src/HOL/GroupTheory/Summation.thy	Tue Apr 08 09:44:21 2003 +0200
1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,592 +0,0 @@
1.4 -(*  Title:      Summation Operator for Abelian Groups
1.5 -    ID:         \$Id\$
1.6 -    Author:     Clemens Ballarin, started 19 November 2002
1.8 -*)
1.9 -
1.10 -header {* Summation Operator *}
1.11 -
1.12 -theory Summation = Group:
1.13 -
1.14 -(* Instantiation of LC from Finite_Set.thy is not possible,
1.15 -   because here we have explicit typing rules like x : carrier G.
1.16 -   We introduce an explicit argument for the domain D *)
1.17 -
1.18 -consts
1.19 -  foldSetD :: "['a set, 'b => 'a => 'a, 'a] => ('b set * 'a) set"
1.20 -
1.21 -inductive "foldSetD D f e"
1.22 -  intros
1.23 -    emptyI [intro]: "e : D ==> ({}, e) : foldSetD D f e"
1.24 -    insertI [intro]: "[| x ~: A; f x y : D; (A, y) : foldSetD D f e |] ==>
1.25 -                      (insert x A, f x y) : foldSetD D f e"
1.26 -
1.27 -inductive_cases empty_foldSetDE [elim!]: "({}, x) : foldSetD D f e"
1.28 -
1.29 -constdefs
1.30 -  foldD :: "['a set, 'b => 'a => 'a, 'a, 'b set] => 'a"
1.31 -  "foldD D f e A == THE x. (A, x) : foldSetD D f e"
1.32 -
1.33 -lemma foldSetD_closed:
1.34 -  "[| (A, z) : foldSetD D f e ; e : D; !!x y. [| x : A; y : D |] ==> f x y : D
1.35 -      |] ==> z : D";
1.36 -  by (erule foldSetD.elims) auto
1.37 -
1.38 -lemma Diff1_foldSetD:
1.39 -  "[| (A - {x}, y) : foldSetD D f e; x : A; f x y : D |] ==>
1.40 -   (A, f x y) : foldSetD D f e"
1.41 -  apply (erule insert_Diff [THEN subst], rule foldSetD.intros)
1.42 -   apply auto
1.43 -  done
1.44 -
1.45 -lemma foldSetD_imp_finite [simp]: "(A, x) : foldSetD D f e ==> finite A"
1.46 -  by (induct set: foldSetD) auto
1.47 -
1.48 -lemma finite_imp_foldSetD:
1.49 -  "[| finite A; e : D; !!x y. [| x : A; y : D |] ==> f x y : D |] ==>
1.50 -   EX x. (A, x) : foldSetD D f e"
1.51 -proof (induct set: Finites)
1.52 -  case empty then show ?case by auto
1.53 -next
1.54 -  case (insert F x)
1.55 -  then obtain y where y: "(F, y) : foldSetD D f e" by auto
1.56 -  with insert have "y : D" by (auto dest: foldSetD_closed)
1.57 -  with y and insert have "(insert x F, f x y) : foldSetD D f e"
1.58 -    by (intro foldSetD.intros) auto
1.59 -  then show ?case ..
1.60 -qed
1.61 -
1.62 -subsection {* Left-commutative operations *}
1.63 -
1.64 -locale LCD =
1.65 -  fixes B :: "'b set"
1.66 -  and D :: "'a set"
1.67 -  and f :: "'b => 'a => 'a"    (infixl "\<cdot>" 70)
1.68 -  assumes left_commute: "[| x : B; y : B; z : D |] ==> x \<cdot> (y \<cdot> z) = y \<cdot> (x \<cdot> z)"
1.69 -  and f_closed [simp, intro!]: "!!x y. [| x : B; y : D |] ==> f x y : D"
1.70 -
1.71 -lemma (in LCD) foldSetD_closed [dest]:
1.72 -  "(A, z) : foldSetD D f e ==> z : D";
1.73 -  by (erule foldSetD.elims) auto
1.74 -
1.75 -lemma (in LCD) Diff1_foldSetD:
1.76 -  "[| (A - {x}, y) : foldSetD D f e; x : A; A <= B |] ==>
1.77 -   (A, f x y) : foldSetD D f e"
1.78 -  apply (subgoal_tac "x : B")
1.79 -  prefer 2 apply fast
1.80 -  apply (erule insert_Diff [THEN subst], rule foldSetD.intros)
1.81 -   apply auto
1.82 -  done
1.83 -
1.84 -lemma (in LCD) foldSetD_imp_finite [simp]:
1.85 -  "(A, x) : foldSetD D f e ==> finite A"
1.86 -  by (induct set: foldSetD) auto
1.87 -
1.88 -lemma (in LCD) finite_imp_foldSetD:
1.89 -  "[| finite A; A <= B; e : D |] ==> EX x. (A, x) : foldSetD D f e"
1.90 -proof (induct set: Finites)
1.91 -  case empty then show ?case by auto
1.92 -next
1.93 -  case (insert F x)
1.94 -  then obtain y where y: "(F, y) : foldSetD D f e" by auto
1.95 -  with insert have "y : D" by auto
1.96 -  with y and insert have "(insert x F, f x y) : foldSetD D f e"
1.97 -    by (intro foldSetD.intros) auto
1.98 -  then show ?case ..
1.99 -qed
1.101 -lemma (in LCD) foldSetD_determ_aux:
1.102 -  "e : D ==> ALL A x. A <= B & card A < n --> (A, x) : foldSetD D f e -->
1.103 -    (ALL y. (A, y) : foldSetD D f e --> y = x)"
1.104 -  apply (induct n)
1.105 -   apply (auto simp add: less_Suc_eq)
1.106 -  apply (erule foldSetD.cases)
1.107 -   apply blast
1.108 -  apply (erule foldSetD.cases)
1.109 -   apply blast
1.110 -  apply clarify
1.111 -  txt {* force simplification of @{text "card A < card (insert ...)"}. *}
1.112 -  apply (erule rev_mp)
1.113 -  apply (simp add: less_Suc_eq_le)
1.114 -  apply (rule impI)
1.115 -  apply (rename_tac Aa xa ya Ab xb yb, case_tac "xa = xb")
1.116 -   apply (subgoal_tac "Aa = Ab")
1.117 -    prefer 2 apply (blast elim!: equalityE)
1.118 -   apply blast
1.119 -  txt {* case @{prop "xa \<notin> xb"}. *}
1.120 -  apply (subgoal_tac "Aa - {xb} = Ab - {xa} & xb : Aa & xa : Ab")
1.121 -   prefer 2 apply (blast elim!: equalityE)
1.122 -  apply clarify
1.123 -  apply (subgoal_tac "Aa = insert xb Ab - {xa}")
1.124 -   prefer 2 apply blast
1.125 -  apply (subgoal_tac "card Aa <= card Ab")
1.126 -   prefer 2
1.127 -   apply (rule Suc_le_mono [THEN subst])
1.128 -   apply (simp add: card_Suc_Diff1)
1.129 -  apply (rule_tac A1 = "Aa - {xb}" in finite_imp_foldSetD [THEN exE])
1.130 -  apply (blast intro: foldSetD_imp_finite finite_Diff)
1.131 -(* new subgoal from finite_imp_foldSetD *)
1.132 -    apply best (* blast doesn't seem to solve this *)
1.133 -   apply assumption
1.134 -  apply (frule (1) Diff1_foldSetD)
1.135 -(* new subgoal from Diff1_foldSetD *)
1.136 -    apply best
1.137 -(*
1.138 -apply (best del: foldSetD_closed elim: foldSetD_closed)
1.139 -    apply (rule f_closed) apply assumption apply (rule foldSetD_closed)
1.140 -    prefer 3 apply assumption apply (rule e_closed)
1.141 -    apply (rule f_closed) apply force apply assumption
1.142 -*)
1.143 -  apply (subgoal_tac "ya = f xb x")
1.144 -   prefer 2
1.145 -(* new subgoal to make IH applicable *)
1.146 -  apply (subgoal_tac "Aa <= B")
1.147 -   prefer 2 apply best
1.148 -   apply (blast del: equalityCE)
1.149 -  apply (subgoal_tac "(Ab - {xa}, x) : foldSetD D f e")
1.150 -   prefer 2 apply simp
1.151 -  apply (subgoal_tac "yb = f xa x")
1.152 -   prefer 2
1.153 -(*   apply (drule_tac x = xa in Diff1_foldSetD)
1.154 -     apply assumption
1.155 -     apply (rule f_closed) apply best apply (rule foldSetD_closed)
1.156 -     prefer 3 apply assumption apply (rule e_closed)
1.157 -     apply (rule f_closed) apply best apply assumption
1.158 -*)
1.159 -   apply (blast del: equalityCE dest: Diff1_foldSetD)
1.160 -   apply (simp (no_asm_simp))
1.161 -   apply (rule left_commute)
1.162 -   apply assumption apply best apply best
1.163 - done
1.165 -lemma (in LCD) foldSetD_determ:
1.166 -  "[| (A, x) : foldSetD D f e; (A, y) : foldSetD D f e; e : D; A <= B |]
1.167 -   ==> y = x"
1.168 -  by (blast intro: foldSetD_determ_aux [rule_format])
1.170 -lemma (in LCD) foldD_equality:
1.171 -  "[| (A, y) : foldSetD D f e; e : D; A <= B |] ==> foldD D f e A = y"
1.172 -  by (unfold foldD_def) (blast intro: foldSetD_determ)
1.174 -lemma foldD_empty [simp]:
1.175 -  "e : D ==> foldD D f e {} = e"
1.176 -  by (unfold foldD_def) blast
1.178 -lemma (in LCD) foldD_insert_aux:
1.179 -  "[| x ~: A; x : B; e : D; A <= B |] ==>
1.180 -    ((insert x A, v) : foldSetD D f e) =
1.181 -    (EX y. (A, y) : foldSetD D f e & v = f x y)"
1.182 -  apply auto
1.183 -  apply (rule_tac A1 = A in finite_imp_foldSetD [THEN exE])
1.184 -   apply (fastsimp dest: foldSetD_imp_finite)
1.185 -(* new subgoal by finite_imp_foldSetD *)
1.186 -    apply assumption
1.187 -    apply assumption
1.188 -  apply (blast intro: foldSetD_determ)
1.189 -  done
1.191 -lemma (in LCD) foldD_insert:
1.192 -    "[| finite A; x ~: A; x : B; e : D; A <= B |] ==>
1.193 -     foldD D f e (insert x A) = f x (foldD D f e A)"
1.194 -  apply (unfold foldD_def)
1.195 -  apply (simp add: foldD_insert_aux)
1.196 -  apply (rule the_equality)
1.197 -  apply (auto intro: finite_imp_foldSetD
1.199 -  done
1.201 -lemma (in LCD) foldD_closed [simp]:
1.202 -  "[| finite A; e : D; A <= B |] ==> foldD D f e A : D"
1.203 -proof (induct set: Finites)
1.204 -  case empty then show ?case by (simp add: foldD_empty)
1.205 -next
1.206 -  case insert then show ?case by (simp add: foldD_insert)
1.207 -qed
1.209 -lemma (in LCD) foldD_commute:
1.210 -  "[| finite A; x : B; e : D; A <= B |] ==>
1.211 -   f x (foldD D f e A) = foldD D f (f x e) A"
1.212 -  apply (induct set: Finites)
1.213 -   apply simp
1.214 -  apply (auto simp add: left_commute foldD_insert)
1.215 -  done
1.217 -lemma Int_mono2:
1.218 -  "[| A <= C; B <= C |] ==> A Int B <= C"
1.219 -  by blast
1.221 -lemma (in LCD) foldD_nest_Un_Int:
1.222 -  "[| finite A; finite C; e : D; A <= B; C <= B |] ==>
1.223 -   foldD D f (foldD D f e C) A = foldD D f (foldD D f e (A Int C)) (A Un C)"
1.224 -  apply (induct set: Finites)
1.225 -   apply simp
1.226 -  apply (simp add: foldD_insert foldD_commute Int_insert_left insert_absorb
1.227 -    Int_mono2 Un_subset_iff)
1.228 -  done
1.230 -lemma (in LCD) foldD_nest_Un_disjoint:
1.231 -  "[| finite A; finite B; A Int B = {}; e : D; A <= B; C <= B |]
1.232 -    ==> foldD D f e (A Un B) = foldD D f (foldD D f e B) A"
1.233 -  by (simp add: foldD_nest_Un_Int)
1.235 --- {* Delete rules to do with @{text foldSetD} relation. *}
1.237 -declare foldSetD_imp_finite [simp del]
1.238 -  empty_foldSetDE [rule del]
1.239 -  foldSetD.intros [rule del]
1.240 -declare (in LCD)
1.241 -  foldSetD_closed [rule del]
1.243 -subsection {* Commutative monoids *}
1.245 -text {*
1.246 -  We enter a more restrictive context, with @{text "f :: 'a => 'a => 'a"}
1.247 -  instead of @{text "'b => 'a => 'a"}.
1.248 -*}
1.250 -locale ACeD =
1.251 -  fixes D :: "'a set"
1.252 -    and f :: "'a => 'a => 'a"    (infixl "\<cdot>" 70)
1.253 -    and e :: 'a
1.254 -  assumes ident [simp]: "x : D ==> x \<cdot> e = x"
1.255 -    and commute: "[| x : D; y : D |] ==> x \<cdot> y = y \<cdot> x"
1.256 -    and assoc: "[| x : D; y : D; z : D |] ==> (x \<cdot> y) \<cdot> z = x \<cdot> (y \<cdot> z)"
1.257 -    and e_closed [simp]: "e : D"
1.258 -    and f_closed [simp]: "[| x : D; y : D |] ==> x \<cdot> y : D"
1.260 -lemma (in ACeD) left_commute:
1.261 -  "[| x : D; y : D; z : D |] ==> x \<cdot> (y \<cdot> z) = y \<cdot> (x \<cdot> z)"
1.262 -proof -
1.263 -  assume D: "x : D" "y : D" "z : D"
1.264 -  then have "x \<cdot> (y \<cdot> z) = (y \<cdot> z) \<cdot> x" by (simp add: commute)
1.265 -  also from D have "... = y \<cdot> (z \<cdot> x)" by (simp add: assoc)
1.266 -  also from D have "z \<cdot> x = x \<cdot> z" by (simp add: commute)
1.267 -  finally show ?thesis .
1.268 -qed
1.270 -lemmas (in ACeD) AC = assoc commute left_commute
1.272 -lemma (in ACeD) left_ident [simp]: "x : D ==> e \<cdot> x = x"
1.273 -proof -
1.274 -  assume D: "x : D"
1.275 -  have "x \<cdot> e = x" by (rule ident)
1.276 -  with D show ?thesis by (simp add: commute)
1.277 -qed
1.279 -lemma (in ACeD) foldD_Un_Int:
1.280 -  "[| finite A; finite B; A <= D; B <= D |] ==>
1.281 -    foldD D f e A \<cdot> foldD D f e B =
1.282 -    foldD D f e (A Un B) \<cdot> foldD D f e (A Int B)"
1.283 -  apply (induct set: Finites)
1.284 -   apply (simp add: left_commute LCD.foldD_closed [OF LCD.intro [of D]])
1.285 -(* left_commute is required to show premise of LCD.intro *)
1.286 -  apply (simp add: AC insert_absorb Int_insert_left
1.287 -    LCD.foldD_insert [OF LCD.intro [of D]]
1.288 -    LCD.foldD_closed [OF LCD.intro [of D]]
1.289 -    Int_mono2 Un_subset_iff)
1.290 -  done
1.292 -lemma (in ACeD) foldD_Un_disjoint:
1.293 -  "[| finite A; finite B; A Int B = {}; A <= D; B <= D |] ==>
1.294 -    foldD D f e (A Un B) = foldD D f e A \<cdot> foldD D f e B"
1.295 -  by (simp add: foldD_Un_Int
1.296 -    left_commute LCD.foldD_closed [OF LCD.intro [of D]] Un_subset_iff)
1.298 -subsection {* Abelian groups with summation operator *}
1.300 -lemma (in abelian_group) sum_lcomm:
1.301 -  "[| x : carrier G; y : carrier G; z : carrier G |] ==>
1.302 -   x \<oplus> (y \<oplus> z) = y \<oplus> (x \<oplus> z)"
1.303 -proof -
1.304 -  assume "x : carrier G" "y : carrier G" "z : carrier G"
1.305 -  then have "x \<oplus> (y \<oplus> z) = (x \<oplus> y) \<oplus> z" by (simp add: sum_assoc)
1.306 -  also from prems have "... = (y \<oplus> x) \<oplus> z" by (simp add: sum_commute)
1.307 -  also from prems have "... = y \<oplus> (x \<oplus> z)" by (simp add: sum_assoc)
1.308 -  finally show ?thesis .
1.309 -qed
1.311 -lemmas (in abelian_group) AC = sum_assoc sum_commute sum_lcomm
1.313 -record ('a, 'b) group_with_sum = "'a group" +
1.314 -  setSum :: "['b => 'a, 'b set] => 'a"
1.316 -(* TODO: nice syntax for the summation operator inside the locale
1.317 -   like \<Oplus>\<index> i\<in>A. f i, probably needs hand-coded translation *)
1.319 -locale agroup_with_sum = abelian_group +
1.320 -  assumes setSum_def:
1.321 -  "setSum G f A = (if finite A then foldD (carrier G) (op \<oplus> o f) \<zero> A else \<zero>)"
1.323 -ML_setup {*
1.325 -Context.>> (fn thy => (simpset_ref_of thy :=
1.326 -  simpset_of thy setsubgoaler asm_full_simp_tac; thy)) *}
1.328 -lemma (in agroup_with_sum) setSum_empty [simp]:
1.329 -  "setSum G f {} = \<zero>"
1.330 -  by (simp add: setSum_def)
1.332 -ML_setup {*
1.334 -Context.>> (fn thy => (simpset_ref_of thy :=
1.335 -  simpset_of thy setsubgoaler asm_simp_tac; thy)) *}
1.337 -lemma insert_conj:
1.338 -  "[| a = b; a : B |] ==> a : insert b B"
1.339 -  by blast
1.341 -declare funcsetI [intro]
1.342 -  funcset_mem [dest]
1.344 -lemma (in agroup_with_sum) setSum_insert [simp]:
1.345 -  "[| finite F; a \<notin> F; f : F -> carrier G; f a : carrier G |] ==>
1.346 -   setSum G f (insert a F) = f a \<oplus> setSum G f F"
1.347 -  apply (rule trans)
1.348 -  apply (simp add: setSum_def)
1.349 -  apply (rule trans)
1.350 -  apply (rule LCD.foldD_insert [OF LCD.intro [of "insert a F"]])
1.351 -    apply simp
1.352 -    apply (rule sum_lcomm)
1.353 -      apply fast apply fast apply assumption
1.354 -    apply (fastsimp intro: sum_closed)
1.355 -    apply simp+ apply fast
1.356 -  apply (auto simp add: setSum_def)
1.357 -  done
1.359 -lemma (in agroup_with_sum) setSum_0:
1.360 -  "setSum G (%i. \<zero>) A = \<zero>"
1.361 -(*  apply (case_tac "finite A")
1.362 -   prefer 2 apply (simp add: setSum_def) *)
1.363 -proof (cases "finite A")
1.364 -  case True then show ?thesis
1.365 -  proof (induct set: Finites)
1.366 -    case empty show ?case by simp
1.367 -  next
1.368 -    case (insert A a)
1.369 -    have "(%i. \<zero>) : A -> carrier G" by auto
1.370 -    with insert show ?case by simp
1.371 -  qed
1.372 -next
1.373 -  case False then show ?thesis by (simp add: setSum_def)
1.374 -qed
1.376 -(*
1.377 -lemma setSum_eq_0_iff [simp]:
1.378 -    "finite F ==> (setSum f F = 0) = (ALL a:F. f a = (0::nat))"
1.379 -  by (induct set: Finites) auto
1.381 -lemma setSum_SucD: "setSum f A = Suc n ==> EX a:A. 0 < f a"
1.382 -  apply (case_tac "finite A")
1.383 -   prefer 2 apply (simp add: setSum_def)
1.384 -  apply (erule rev_mp)
1.385 -  apply (erule finite_induct)
1.386 -   apply auto
1.387 -  done
1.389 -lemma card_eq_setSum: "finite A ==> card A = setSum (\<lambda>x. 1) A"
1.390 -*)  -- {* Could allow many @{text "card"} proofs to be simplified. *}
1.391 -(*
1.392 -  by (induct set: Finites) auto
1.393 -*)
1.395 -lemma (in agroup_with_sum) setSum_closed:
1.396 -  "[| finite A; f : A -> carrier G |] ==> setSum G f A : carrier G"
1.397 -proof (induct set: Finites)
1.398 -  case empty show ?case by simp
1.399 -next
1.400 -  case (insert A a)
1.401 -  then have a: "f a : carrier G" by fast
1.402 -  from insert have A: "f : A -> carrier G" by fast
1.403 -  from insert A a show ?case by simp
1.404 -qed
1.405 -(*
1.406 -lemma (in agroup_with_sum) setSum_closed:
1.407 -  "[| finite A; f``A <= carrier G |] ==> setSum G f A : carrier G"
1.409 -lemma (in agroup_with_sum) setSum_closed:
1.410 -  "[| finite A; !!i. i : A ==> f i : carrier G |] ==>
1.411 -   setSum G f A : carrier G"
1.412 -*)
1.414 -lemma funcset_Int_left [simp, intro]:
1.415 -  "[| f : A -> C; f : B -> C |] ==> f : A Int B -> C"
1.416 -  by fast
1.418 -lemma funcset_Int_right:
1.419 -  "(f : A -> B Int C) = (f : A -> B & f : A -> C)"
1.420 -  by fast
1.422 -lemma funcset_Un_right:
1.423 -  "[| f : A -> B; f : A -> C |] ==> f : A -> B Un C"
1.424 -  by fast
1.426 -lemma funcset_Un_left [iff]:
1.427 -  "(f : A Un B -> C) = (f : A -> C & f : B -> C)"
1.428 -  by fast
1.430 -lemma (in agroup_with_sum) setSum_Un_Int:
1.431 -  "[| finite A; finite B; g : A -> carrier G; g : B -> carrier G |] ==>
1.432 -   setSum G g (A Un B) \<oplus> setSum G g (A Int B) = setSum G g A \<oplus> setSum G g B"
1.433 -  -- {* The reversed orientation looks more natural, but LOOPS as a simprule! *}
1.434 -proof (induct set: Finites)
1.435 -  case empty then show ?case by (simp add: setSum_closed)
1.436 -next
1.437 -  case (insert A a)
1.438 -  then have a: "g a : carrier G" by fast
1.439 -  from insert have A: "g : A -> carrier G" by fast
1.440 -  from insert A a show ?case
1.441 -    by (simp add: AC Int_insert_left insert_absorb setSum_closed
1.442 -          Int_mono2 Un_subset_iff)
1.443 -qed
1.445 -lemma (in agroup_with_sum) setSum_Un_disjoint:
1.446 -  "[| finite A; finite B; A Int B = {};
1.447 -      g : A -> carrier G; g : B -> carrier G |]
1.448 -   ==> setSum G g (A Un B) = setSum G g A \<oplus> setSum G g B"
1.449 -  apply (subst setSum_Un_Int [symmetric])
1.450 -    apply (auto simp add: setSum_closed)
1.451 -  done
1.453 -(*
1.454 -lemma setSum_UN_disjoint:
1.455 -  fixes f :: "'a => 'b::plus_ac0"
1.456 -  shows
1.457 -    "finite I ==> (ALL i:I. finite (A i)) ==>
1.458 -        (ALL i:I. ALL j:I. i \<noteq> j --> A i Int A j = {}) ==>
1.459 -      setSum f (UNION I A) = setSum (\<lambda>i. setSum f (A i)) I"
1.460 -  apply (induct set: Finites)
1.461 -   apply simp
1.462 -  apply atomize
1.463 -  apply (subgoal_tac "ALL i:F. x \<noteq> i")
1.464 -   prefer 2 apply blast
1.465 -  apply (subgoal_tac "A x Int UNION F A = {}")
1.466 -   prefer 2 apply blast
1.467 -  apply (simp add: setSum_Un_disjoint)
1.468 -  done
1.469 -*)
1.471 -  "[| finite A; f : A -> carrier G; g : A -> carrier G |] ==>
1.472 -   setSum G (%x. f x \<oplus> g x) A = (setSum G f A \<oplus> setSum G g A)"
1.473 -proof (induct set: Finites)
1.474 -  case empty show ?case by simp
1.475 -next
1.476 -  case (insert A a) then
1.477 -  have fA: "f : A -> carrier G" by fast
1.478 -  from insert have fa: "f a : carrier G" by fast
1.479 -  from insert have gA: "g : A -> carrier G" by fast
1.480 -  from insert have ga: "g a : carrier G" by fast
1.481 -  from insert have fga: "(%x. f x \<oplus> g x) a : carrier G" by (simp add: Pi_def)
1.482 -  from insert have fgA: "(%x. f x \<oplus> g x) : A -> carrier G"
1.483 -    by (simp add: Pi_def)
1.484 -  show ?case  (* check if all simps are really necessary *)
1.485 -    by (simp add: insert fA fa gA ga fgA fga AC setSum_closed Int_insert_left insert_absorb Int_mono2 Un_subset_iff)
1.486 -qed
1.488 -(*
1.489 -lemma setSum_Un: "finite A ==> finite B ==>
1.490 -    (setSum f (A Un B) :: nat) = setSum f A + setSum f B - setSum f (A Int B)"
1.491 -  -- {* For the natural numbers, we have subtraction. *}
1.492 -  apply (subst setSum_Un_Int [symmetric])
1.493 -    apply auto
1.494 -  done
1.496 -lemma setSum_diff1: "(setSum f (A - {a}) :: nat) =
1.497 -    (if a:A then setSum f A - f a else setSum f A)"
1.498 -  apply (case_tac "finite A")
1.499 -   prefer 2 apply (simp add: setSum_def)
1.500 -  apply (erule finite_induct)
1.501 -   apply (auto simp add: insert_Diff_if)
1.502 -  apply (drule_tac a = a in mk_disjoint_insert)
1.503 -  apply auto
1.504 -  done
1.505 -*)
1.507 -lemma (in agroup_with_sum) setSum_cong:
1.508 -  "[| A = B; g : B -> carrier G;
1.509 -      !!i. i : B ==> f i = g i |] ==> setSum G f A = setSum G g B"
1.510 -proof -
1.511 -  assume prems: "A = B" "g : B -> carrier G"
1.512 -    "!!i. i : B ==> f i = g i"
1.513 -  show ?thesis
1.514 -  proof (cases "finite B")
1.515 -    case True
1.516 -    then have "!!A. [| A = B; g : B -> carrier G;
1.517 -      !!i. i : B ==> f i = g i |] ==> setSum G f A = setSum G g B"
1.518 -    proof induct
1.519 -      case empty thus ?case by simp
1.520 -    next
1.521 -      case (insert B x)
1.522 -      then have "setSum G f A = setSum G f (insert x B)" by simp
1.523 -      also from insert have "... = f x \<oplus> setSum G f B"
1.524 -      proof (intro setSum_insert)
1.525 -	show "finite B" .
1.526 -      next
1.527 -	show "x ~: B" .
1.528 -      next
1.529 -	assume "x ~: B" "!!i. i \<in> insert x B \<Longrightarrow> f i = g i"
1.530 -	  "g \<in> insert x B \<rightarrow> carrier G"
1.531 -	thus "f : B -> carrier G" by fastsimp
1.532 -      next
1.533 -	assume "x ~: B" "!!i. i \<in> insert x B \<Longrightarrow> f i = g i"
1.534 -	  "g \<in> insert x B \<rightarrow> carrier G"
1.535 -	thus "f x \<in> carrier G" by fastsimp
1.536 -      qed
1.537 -      also from insert have "... = g x \<oplus> setSum G g B" by fastsimp
1.538 -      also from insert have "... = setSum G g (insert x B)"
1.539 -      by (intro setSum_insert [THEN sym]) auto
1.540 -      finally show ?case .
1.541 -    qed
1.542 -    with prems show ?thesis by simp
1.543 -  next
1.544 -    case False with prems show ?thesis by (simp add: setSum_def)
1.545 -  qed
1.546 -qed
1.548 -lemma (in agroup_with_sum) setSum_cong1 [cong]:
1.549 -  "[| A = B; !!i. i : B ==> f i = g i;
1.550 -      g : B -> carrier G = True |] ==> setSum G f A = setSum G g B"
1.551 -  by (rule setSum_cong) fast+
1.553 -text {*Usually, if this rule causes a failed congruence proof error,
1.554 -   the reason is that the premise @{text "g : B -> carrier G"} cannot be shown.
1.555 -   Adding @{thm [source] Pi_def} to the simpset is often useful. *}
1.557 -declare funcsetI [rule del]
1.558 -  funcset_mem [rule del]
1.560 -(*** Examples --- Summation over the integer interval {..n} ***)
1.562 -(* New locale where index set is restricted to nat *)
1.564 -locale agroup_with_natsum = agroup_with_sum +
1.565 -  assumes "False ==> setSum G f (A::nat set) = setSum G f A"
1.567 -lemma (in agroup_with_natsum) natSum_0 [simp]:
1.568 -  "f : {0::nat} -> carrier G ==> setSum G f {..0} = f 0"
1.571 -lemma (in agroup_with_natsum) natsum_Suc [simp]:
1.572 -  "f : {..Suc n} -> carrier G ==>
1.573 -   setSum G f {..Suc n} = (f (Suc n) \<oplus> setSum G f {..n})"
1.574 -by (simp add: Pi_def atMost_Suc)
1.576 -lemma (in agroup_with_natsum) natsum_Suc2:
1.577 -  "f : {..Suc n} -> carrier G ==>
1.578 -   setSum G f {..Suc n} = (setSum G (%i. f (Suc i)) {..n} \<oplus> f 0)"
1.579 -proof (induct n)
1.580 -  case 0 thus ?case by (simp add: Pi_def)
1.581 -next
1.582 -  case Suc thus ?case by (simp add: sum_assoc Pi_def setSum_closed)
1.583 -qed
1.585 -lemma (in agroup_with_natsum) natsum_zero [simp]:
1.586 -  "setSum G (%i. \<zero>) {..n::nat} = \<zero>"
1.587 -by (induct n) (simp_all add: Pi_def)
1.589 -lemma (in agroup_with_natsum) natsum_add [simp]:
1.590 -  "[| f : {..n} -> carrier G; g : {..n} -> carrier G |] ==>
1.591 -   setSum G (%i. f i \<oplus> g i) {..n::nat} = setSum G f {..n} \<oplus> setSum G g {..n}"
1.592 -by (induct n) (simp_all add: AC Pi_def setSum_closed)
1.594 -end