src/HOL/Groups_Big.thy
author wenzelm
Tue, 19 Jul 2016 09:55:03 +0200
changeset 63520 2803d2b8f85d
parent 63357 bf2cf0653741
child 63561 fba08009ff3e
permissions -rw-r--r--
Linux platform base-line is Ubuntu 12.04 LTS;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
     1
(*  Title:      HOL/Groups_Big.thy
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
     2
    Author:     Tobias Nipkow, Lawrence C Paulson and Markus Wenzel
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
     3
                with contributions by Jeremy Avigad
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
     4
*)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
     5
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
     6
section \<open>Big sum and product over finite (non-empty) sets\<close>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
     7
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
     8
theory Groups_Big
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
     9
imports Finite_Set Power
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    10
begin
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    11
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
    12
subsection \<open>Generic monoid operation over a set\<close>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    13
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    14
locale comm_monoid_set = comm_monoid
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    15
begin
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    16
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    17
interpretation comp_fun_commute f
61169
4de9ff3ea29a tuned proofs -- less legacy;
wenzelm
parents: 61032
diff changeset
    18
  by standard (simp add: fun_eq_iff left_commute)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    19
54745
46e441e61ff5 disambiguation of interpretation prefixes
haftmann
parents: 54744
diff changeset
    20
interpretation comp?: comp_fun_commute "f \<circ> g"
46e441e61ff5 disambiguation of interpretation prefixes
haftmann
parents: 54744
diff changeset
    21
  by (fact comp_comp_fun_commute)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    22
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    23
definition F :: "('b \<Rightarrow> 'a) \<Rightarrow> 'b set \<Rightarrow> 'a"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    24
where
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
    25
  eq_fold: "F g A = Finite_Set.fold (f \<circ> g) \<^bold>1 A"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    26
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    27
lemma infinite [simp]:
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
    28
  "\<not> finite A \<Longrightarrow> F g A = \<^bold>1"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    29
  by (simp add: eq_fold)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    30
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    31
lemma empty [simp]:
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
    32
  "F g {} = \<^bold>1"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    33
  by (simp add: eq_fold)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    34
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    35
lemma insert [simp]:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    36
  assumes "finite A" and "x \<notin> A"
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
    37
  shows "F g (insert x A) = g x \<^bold>* F g A"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    38
  using assms by (simp add: eq_fold)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    39
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    40
lemma remove:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    41
  assumes "finite A" and "x \<in> A"
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
    42
  shows "F g A = g x \<^bold>* F g (A - {x})"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    43
proof -
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
    44
  from \<open>x \<in> A\<close> obtain B where A: "A = insert x B" and "x \<notin> B"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    45
    by (auto dest: mk_disjoint_insert)
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
    46
  moreover from \<open>finite A\<close> A have "finite B" by simp
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    47
  ultimately show ?thesis by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    48
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    49
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    50
lemma insert_remove:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    51
  assumes "finite A"
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
    52
  shows "F g (insert x A) = g x \<^bold>* F g (A - {x})"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    53
  using assms by (cases "x \<in> A") (simp_all add: remove insert_absorb)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    54
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    55
lemma neutral:
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
    56
  assumes "\<forall>x\<in>A. g x = \<^bold>1"
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
    57
  shows "F g A = \<^bold>1"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    58
  using assms by (induct A rule: infinite_finite_induct) simp_all
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    59
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    60
lemma neutral_const [simp]:
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
    61
  "F (\<lambda>_. \<^bold>1) A = \<^bold>1"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    62
  by (simp add: neutral)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    63
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    64
lemma union_inter:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    65
  assumes "finite A" and "finite B"
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
    66
  shows "F g (A \<union> B) \<^bold>* F g (A \<inter> B) = F g A \<^bold>* F g B"
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61776
diff changeset
    67
  \<comment> \<open>The reversed orientation looks more natural, but LOOPS as a simprule!\<close>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    68
using assms proof (induct A)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    69
  case empty then show ?case by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    70
next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    71
  case (insert x A) then show ?case
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    72
    by (auto simp add: insert_absorb Int_insert_left commute [of _ "g x"] assoc left_commute)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    73
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    74
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    75
corollary union_inter_neutral:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    76
  assumes "finite A" and "finite B"
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
    77
  and I0: "\<forall>x \<in> A \<inter> B. g x = \<^bold>1"
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
    78
  shows "F g (A \<union> B) = F g A \<^bold>* F g B"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    79
  using assms by (simp add: union_inter [symmetric] neutral)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    80
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    81
corollary union_disjoint:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    82
  assumes "finite A" and "finite B"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    83
  assumes "A \<inter> B = {}"
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
    84
  shows "F g (A \<union> B) = F g A \<^bold>* F g B"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    85
  using assms by (simp add: union_inter_neutral)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    86
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
    87
lemma union_diff2:
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
    88
  assumes "finite A" and "finite B"
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
    89
  shows "F g (A \<union> B) = F g (A - B) \<^bold>* F g (B - A) \<^bold>* F g (A \<inter> B)"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
    90
proof -
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
    91
  have "A \<union> B = A - B \<union> (B - A) \<union> A \<inter> B"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
    92
    by auto
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
    93
  with assms show ?thesis by simp (subst union_disjoint, auto)+
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
    94
qed
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
    95
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    96
lemma subset_diff:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    97
  assumes "B \<subseteq> A" and "finite A"
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
    98
  shows "F g A = F g (A - B) \<^bold>* F g B"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    99
proof -
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   100
  from assms have "finite (A - B)" by auto
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   101
  moreover from assms have "finite B" by (rule finite_subset)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   102
  moreover from assms have "(A - B) \<inter> B = {}" by auto
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   103
  ultimately have "F g (A - B \<union> B) = F g (A - B) \<^bold>* F g B" by (rule union_disjoint)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   104
  moreover from assms have "A \<union> B = A" by auto
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   105
  ultimately show ?thesis by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   106
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   107
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56544
diff changeset
   108
lemma setdiff_irrelevant:
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56544
diff changeset
   109
  assumes "finite A"
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56544
diff changeset
   110
  shows "F g (A - {x. g x = z}) = F g A"
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   111
  using assms by (induct A) (simp_all add: insert_Diff_if)
58195
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   112
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56544
diff changeset
   113
lemma not_neutral_contains_not_neutral:
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   114
  assumes "F g A \<noteq> \<^bold>1"
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   115
  obtains a where "a \<in> A" and "g a \<noteq> \<^bold>1"
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56544
diff changeset
   116
proof -
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   117
  from assms have "\<exists>a\<in>A. g a \<noteq> \<^bold>1"
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56544
diff changeset
   118
  proof (induct A rule: infinite_finite_induct)
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56544
diff changeset
   119
    case (insert a A)
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56544
diff changeset
   120
    then show ?case by simp (rule, simp)
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56544
diff changeset
   121
  qed simp_all
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56544
diff changeset
   122
  with that show thesis by blast
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56544
diff changeset
   123
qed
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56544
diff changeset
   124
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   125
lemma reindex:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   126
  assumes "inj_on h A"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   127
  shows "F g (h ` A) = F (g \<circ> h) A"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   128
proof (cases "finite A")
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   129
  case True
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   130
  with assms show ?thesis by (simp add: eq_fold fold_image comp_assoc)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   131
next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   132
  case False with assms have "\<not> finite (h ` A)" by (blast dest: finite_imageD)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   133
  with False show ?thesis by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   134
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   135
63357
bf2cf0653741 added fundef_cong rule
nipkow
parents: 63290
diff changeset
   136
lemma cong [fundef_cong]:
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   137
  assumes "A = B"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   138
  assumes g_h: "\<And>x. x \<in> B \<Longrightarrow> g x = h x"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   139
  shows "F g A = F h B"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   140
  using g_h unfolding \<open>A = B\<close>
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   141
  by (induct B rule: infinite_finite_induct) auto
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   142
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   143
lemma strong_cong [cong]:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   144
  assumes "A = B" "\<And>x. x \<in> B =simp=> g x = h x"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   145
  shows "F (\<lambda>x. g x) A = F (\<lambda>x. h x) B"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   146
  by (rule cong) (insert assms, simp_all add: simp_implies_def)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   147
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   148
lemma reindex_cong:
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   149
  assumes "inj_on l B"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   150
  assumes "A = l ` B"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   151
  assumes "\<And>x. x \<in> B \<Longrightarrow> g (l x) = h x"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   152
  shows "F g A = F h B"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   153
  using assms by (simp add: reindex)
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   154
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   155
lemma UNION_disjoint:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   156
  assumes "finite I" and "\<forall>i\<in>I. finite (A i)"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   157
  and "\<forall>i\<in>I. \<forall>j\<in>I. i \<noteq> j \<longrightarrow> A i \<inter> A j = {}"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   158
  shows "F g (UNION I A) = F (\<lambda>x. F g (A x)) I"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   159
apply (insert assms)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   160
apply (induct rule: finite_induct)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   161
apply simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   162
apply atomize
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   163
apply (subgoal_tac "\<forall>i\<in>Fa. x \<noteq> i")
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   164
 prefer 2 apply blast
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   165
apply (subgoal_tac "A x Int UNION Fa A = {}")
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   166
 prefer 2 apply blast
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   167
apply (simp add: union_disjoint)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   168
done
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   169
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   170
lemma Union_disjoint:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   171
  assumes "\<forall>A\<in>C. finite A" "\<forall>A\<in>C. \<forall>B\<in>C. A \<noteq> B \<longrightarrow> A \<inter> B = {}"
61952
546958347e05 prefer symbols for "Union", "Inter";
wenzelm
parents: 61944
diff changeset
   172
  shows "F g (\<Union>C) = (F \<circ> F) g C"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   173
proof cases
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   174
  assume "finite C"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   175
  from UNION_disjoint [OF this assms]
56166
9a241bc276cd normalising simp rules for compound operators
haftmann
parents: 55096
diff changeset
   176
  show ?thesis by simp
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   177
qed (auto dest: finite_UnionD intro: infinite)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   178
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   179
lemma distrib:
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   180
  "F (\<lambda>x. g x \<^bold>* h x) A = F g A \<^bold>* F h A"
63092
a949b2a5f51d eliminated use of empty "assms";
wenzelm
parents: 63040
diff changeset
   181
  by (induct A rule: infinite_finite_induct) (simp_all add: assoc commute left_commute)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   182
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   183
lemma Sigma:
61032
b57df8eecad6 standardized some occurences of ancient "split" alias
haftmann
parents: 60974
diff changeset
   184
  "finite A \<Longrightarrow> \<forall>x\<in>A. finite (B x) \<Longrightarrow> F (\<lambda>x. F (g x) (B x)) A = F (case_prod g) (SIGMA x:A. B x)"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   185
apply (subst Sigma_def)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   186
apply (subst UNION_disjoint, assumption, simp)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   187
 apply blast
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   188
apply (rule cong)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   189
apply rule
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   190
apply (simp add: fun_eq_iff)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   191
apply (subst UNION_disjoint, simp, simp)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   192
 apply blast
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   193
apply (simp add: comp_def)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   194
done
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   195
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   196
lemma related:
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   197
  assumes Re: "R \<^bold>1 \<^bold>1"
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   198
  and Rop: "\<forall>x1 y1 x2 y2. R x1 x2 \<and> R y1 y2 \<longrightarrow> R (x1 \<^bold>* y1) (x2 \<^bold>* y2)"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   199
  and fS: "finite S" and Rfg: "\<forall>x\<in>S. R (h x) (g x)"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   200
  shows "R (F h S) (F g S)"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   201
  using fS by (rule finite_subset_induct) (insert assms, auto)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   202
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   203
lemma mono_neutral_cong_left:
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   204
  assumes "finite T" and "S \<subseteq> T" and "\<forall>i \<in> T - S. h i = \<^bold>1"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   205
  and "\<And>x. x \<in> S \<Longrightarrow> g x = h x" shows "F g S = F h T"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   206
proof-
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   207
  have eq: "T = S \<union> (T - S)" using \<open>S \<subseteq> T\<close> by blast
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   208
  have d: "S \<inter> (T - S) = {}" using \<open>S \<subseteq> T\<close> by blast
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   209
  from \<open>finite T\<close> \<open>S \<subseteq> T\<close> have f: "finite S" "finite (T - S)"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   210
    by (auto intro: finite_subset)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   211
  show ?thesis using assms(4)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   212
    by (simp add: union_disjoint [OF f d, unfolded eq [symmetric]] neutral [OF assms(3)])
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   213
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   214
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   215
lemma mono_neutral_cong_right:
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   216
  "\<lbrakk> finite T; S \<subseteq> T; \<forall>i \<in> T - S. g i = \<^bold>1; \<And>x. x \<in> S \<Longrightarrow> g x = h x \<rbrakk>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   217
   \<Longrightarrow> F g T = F h S"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   218
  by (auto intro!: mono_neutral_cong_left [symmetric])
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   219
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   220
lemma mono_neutral_left:
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   221
  "\<lbrakk> finite T; S \<subseteq> T; \<forall>i \<in> T - S. g i = \<^bold>1 \<rbrakk> \<Longrightarrow> F g S = F g T"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   222
  by (blast intro: mono_neutral_cong_left)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   223
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   224
lemma mono_neutral_right:
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   225
  "\<lbrakk> finite T;  S \<subseteq> T;  \<forall>i \<in> T - S. g i = \<^bold>1 \<rbrakk> \<Longrightarrow> F g T = F g S"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   226
  by (blast intro!: mono_neutral_left [symmetric])
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   227
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   228
lemma reindex_bij_betw: "bij_betw h S T \<Longrightarrow> F (\<lambda>x. g (h x)) S = F g T"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   229
  by (auto simp: bij_betw_def reindex)
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   230
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   231
lemma reindex_bij_witness:
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   232
  assumes witness:
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   233
    "\<And>a. a \<in> S \<Longrightarrow> i (j a) = a"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   234
    "\<And>a. a \<in> S \<Longrightarrow> j a \<in> T"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   235
    "\<And>b. b \<in> T \<Longrightarrow> j (i b) = b"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   236
    "\<And>b. b \<in> T \<Longrightarrow> i b \<in> S"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   237
  assumes eq:
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   238
    "\<And>a. a \<in> S \<Longrightarrow> h (j a) = g a"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   239
  shows "F g S = F h T"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   240
proof -
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   241
  have "bij_betw j S T"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   242
    using bij_betw_byWitness[where A=S and f=j and f'=i and A'=T] witness by auto
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   243
  moreover have "F g S = F (\<lambda>x. h (j x)) S"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   244
    by (intro cong) (auto simp: eq)
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   245
  ultimately show ?thesis
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   246
    by (simp add: reindex_bij_betw)
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   247
qed
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   248
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   249
lemma reindex_bij_betw_not_neutral:
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   250
  assumes fin: "finite S'" "finite T'"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   251
  assumes bij: "bij_betw h (S - S') (T - T')"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   252
  assumes nn:
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   253
    "\<And>a. a \<in> S' \<Longrightarrow> g (h a) = z"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   254
    "\<And>b. b \<in> T' \<Longrightarrow> g b = z"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   255
  shows "F (\<lambda>x. g (h x)) S = F g T"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   256
proof -
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   257
  have [simp]: "finite S \<longleftrightarrow> finite T"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   258
    using bij_betw_finite[OF bij] fin by auto
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   259
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   260
  show ?thesis
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   261
  proof cases
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   262
    assume "finite S"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   263
    with nn have "F (\<lambda>x. g (h x)) S = F (\<lambda>x. g (h x)) (S - S')"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   264
      by (intro mono_neutral_cong_right) auto
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   265
    also have "\<dots> = F g (T - T')"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   266
      using bij by (rule reindex_bij_betw)
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   267
    also have "\<dots> = F g T"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   268
      using nn \<open>finite S\<close> by (intro mono_neutral_cong_left) auto
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   269
    finally show ?thesis .
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   270
  qed simp
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   271
qed
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   272
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   273
lemma reindex_nontrivial:
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   274
  assumes "finite A"
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   275
  and nz: "\<And>x y. x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> x \<noteq> y \<Longrightarrow> h x = h y \<Longrightarrow> g (h x) = \<^bold>1"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   276
  shows "F g (h ` A) = F (g \<circ> h) A"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   277
proof (subst reindex_bij_betw_not_neutral [symmetric])
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   278
  show "bij_betw h (A - {x \<in> A. (g \<circ> h) x = \<^bold>1}) (h ` A - h ` {x \<in> A. (g \<circ> h) x = \<^bold>1})"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   279
    using nz by (auto intro!: inj_onI simp: bij_betw_def)
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   280
qed (insert \<open>finite A\<close>, auto)
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   281
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   282
lemma reindex_bij_witness_not_neutral:
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   283
  assumes fin: "finite S'" "finite T'"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   284
  assumes witness:
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   285
    "\<And>a. a \<in> S - S' \<Longrightarrow> i (j a) = a"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   286
    "\<And>a. a \<in> S - S' \<Longrightarrow> j a \<in> T - T'"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   287
    "\<And>b. b \<in> T - T' \<Longrightarrow> j (i b) = b"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   288
    "\<And>b. b \<in> T - T' \<Longrightarrow> i b \<in> S - S'"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   289
  assumes nn:
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   290
    "\<And>a. a \<in> S' \<Longrightarrow> g a = z"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   291
    "\<And>b. b \<in> T' \<Longrightarrow> h b = z"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   292
  assumes eq:
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   293
    "\<And>a. a \<in> S \<Longrightarrow> h (j a) = g a"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   294
  shows "F g S = F h T"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   295
proof -
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   296
  have bij: "bij_betw j (S - (S' \<inter> S)) (T - (T' \<inter> T))"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   297
    using witness by (intro bij_betw_byWitness[where f'=i]) auto
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   298
  have F_eq: "F g S = F (\<lambda>x. h (j x)) S"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   299
    by (intro cong) (auto simp: eq)
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   300
  show ?thesis
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   301
    unfolding F_eq using fin nn eq
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   302
    by (intro reindex_bij_betw_not_neutral[OF _ _ bij]) auto
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   303
qed
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   304
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   305
lemma delta:
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   306
  assumes fS: "finite S"
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   307
  shows "F (\<lambda>k. if k = a then b k else \<^bold>1) S = (if a \<in> S then b a else \<^bold>1)"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   308
proof-
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   309
  let ?f = "(\<lambda>k. if k=a then b k else \<^bold>1)"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   310
  { assume a: "a \<notin> S"
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   311
    hence "\<forall>k\<in>S. ?f k = \<^bold>1" by simp
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   312
    hence ?thesis  using a by simp }
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   313
  moreover
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   314
  { assume a: "a \<in> S"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   315
    let ?A = "S - {a}"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   316
    let ?B = "{a}"
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   317
    have eq: "S = ?A \<union> ?B" using a by blast
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   318
    have dj: "?A \<inter> ?B = {}" by simp
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   319
    from fS have fAB: "finite ?A" "finite ?B" by auto
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   320
    have "F ?f S = F ?f ?A \<^bold>* F ?f ?B"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   321
      using union_disjoint [OF fAB dj, of ?f, unfolded eq [symmetric]]
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   322
      by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   323
    then have ?thesis using a by simp }
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   324
  ultimately show ?thesis by blast
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   325
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   326
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   327
lemma delta':
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   328
  assumes fS: "finite S"
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   329
  shows "F (\<lambda>k. if a = k then b k else \<^bold>1) S = (if a \<in> S then b a else \<^bold>1)"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   330
  using delta [OF fS, of a b, symmetric] by (auto intro: cong)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   331
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   332
lemma If_cases:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   333
  fixes P :: "'b \<Rightarrow> bool" and g h :: "'b \<Rightarrow> 'a"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   334
  assumes fA: "finite A"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   335
  shows "F (\<lambda>x. if P x then h x else g x) A =
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   336
    F h (A \<inter> {x. P x}) \<^bold>* F g (A \<inter> - {x. P x})"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   337
proof -
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   338
  have a: "A = A \<inter> {x. P x} \<union> A \<inter> -{x. P x}"
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   339
          "(A \<inter> {x. P x}) \<inter> (A \<inter> -{x. P x}) = {}"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   340
    by blast+
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   341
  from fA
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   342
  have f: "finite (A \<inter> {x. P x})" "finite (A \<inter> -{x. P x})" by auto
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   343
  let ?g = "\<lambda>x. if P x then h x else g x"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   344
  from union_disjoint [OF f a(2), of ?g] a(1)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   345
  show ?thesis
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   346
    by (subst (1 2) cong) simp_all
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   347
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   348
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   349
lemma cartesian_product:
61943
7fba644ed827 discontinued ASCII replacement syntax <*>;
wenzelm
parents: 61799
diff changeset
   350
   "F (\<lambda>x. F (g x) B) A = F (case_prod g) (A \<times> B)"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   351
apply (rule sym)
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   352
apply (cases "finite A")
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   353
 apply (cases "finite B")
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   354
  apply (simp add: Sigma)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   355
 apply (cases "A={}", simp)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   356
 apply simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   357
apply (auto intro: infinite dest: finite_cartesian_productD2)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   358
apply (cases "B = {}") apply (auto intro: infinite dest: finite_cartesian_productD1)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   359
done
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   360
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   361
lemma inter_restrict:
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   362
  assumes "finite A"
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   363
  shows "F g (A \<inter> B) = F (\<lambda>x. if x \<in> B then g x else \<^bold>1) A"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   364
proof -
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   365
  let ?g = "\<lambda>x. if x \<in> A \<inter> B then g x else \<^bold>1"
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   366
  have "\<forall>i\<in>A - A \<inter> B. (if i \<in> A \<inter> B then g i else \<^bold>1) = \<^bold>1"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   367
   by simp
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   368
  moreover have "A \<inter> B \<subseteq> A" by blast
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   369
  ultimately have "F ?g (A \<inter> B) = F ?g A" using \<open>finite A\<close>
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   370
    by (intro mono_neutral_left) auto
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   371
  then show ?thesis by simp
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   372
qed
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   373
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   374
lemma inter_filter:
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   375
  "finite A \<Longrightarrow> F g {x \<in> A. P x} = F (\<lambda>x. if P x then g x else \<^bold>1) A"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   376
  by (simp add: inter_restrict [symmetric, of A "{x. P x}" g, simplified mem_Collect_eq] Int_def)
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   377
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   378
lemma Union_comp:
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   379
  assumes "\<forall>A \<in> B. finite A"
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   380
    and "\<And>A1 A2 x. A1 \<in> B \<Longrightarrow> A2 \<in> B  \<Longrightarrow> A1 \<noteq> A2 \<Longrightarrow> x \<in> A1 \<Longrightarrow> x \<in> A2 \<Longrightarrow> g x = \<^bold>1"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   381
  shows "F g (\<Union>B) = (F \<circ> F) g B"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   382
using assms proof (induct B rule: infinite_finite_induct)
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   383
  case (infinite A)
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   384
  then have "\<not> finite (\<Union>A)" by (blast dest: finite_UnionD)
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   385
  with infinite show ?case by simp
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   386
next
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   387
  case empty then show ?case by simp
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   388
next
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   389
  case (insert A B)
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   390
  then have "finite A" "finite B" "finite (\<Union>B)" "A \<notin> B"
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   391
    and "\<forall>x\<in>A \<inter> \<Union>B. g x = \<^bold>1"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   392
    and H: "F g (\<Union>B) = (F o F) g B" by auto
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   393
  then have "F g (A \<union> \<Union>B) = F g A \<^bold>* F g (\<Union>B)"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   394
    by (simp add: union_inter_neutral)
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   395
  with \<open>finite B\<close> \<open>A \<notin> B\<close> show ?case
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   396
    by (simp add: H)
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   397
qed
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   398
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   399
lemma commute:
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   400
  "F (\<lambda>i. F (g i) B) A = F (\<lambda>j. F (\<lambda>i. g i j) A) B"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   401
  unfolding cartesian_product
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   402
  by (rule reindex_bij_witness [where i = "\<lambda>(i, j). (j, i)" and j = "\<lambda>(i, j). (j, i)"]) auto
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   403
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   404
lemma commute_restrict:
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   405
  "finite A \<Longrightarrow> finite B \<Longrightarrow>
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   406
    F (\<lambda>x. F (g x) {y. y \<in> B \<and> R x y}) A = F (\<lambda>y. F (\<lambda>x. g x y) {x. x \<in> A \<and> R x y}) B"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   407
  by (simp add: inter_filter) (rule commute)
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   408
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   409
lemma Plus:
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   410
  fixes A :: "'b set" and B :: "'c set"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   411
  assumes fin: "finite A" "finite B"
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   412
  shows "F g (A <+> B) = F (g \<circ> Inl) A \<^bold>* F (g \<circ> Inr) B"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   413
proof -
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   414
  have "A <+> B = Inl ` A \<union> Inr ` B" by auto
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   415
  moreover from fin have "finite (Inl ` A :: ('b + 'c) set)" "finite (Inr ` B :: ('b + 'c) set)"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   416
    by auto
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   417
  moreover have "Inl ` A \<inter> Inr ` B = ({} :: ('b + 'c) set)" by auto
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   418
  moreover have "inj_on (Inl :: 'b \<Rightarrow> 'b + 'c) A" "inj_on (Inr :: 'c \<Rightarrow> 'b + 'c) B"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   419
    by (auto intro: inj_onI)
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   420
  ultimately show ?thesis using fin
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   421
    by (simp add: union_disjoint reindex)
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   422
qed
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   423
58195
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   424
lemma same_carrier:
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   425
  assumes "finite C"
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   426
  assumes subset: "A \<subseteq> C" "B \<subseteq> C"
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   427
  assumes trivial: "\<And>a. a \<in> C - A \<Longrightarrow> g a = \<^bold>1" "\<And>b. b \<in> C - B \<Longrightarrow> h b = \<^bold>1"
58195
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   428
  shows "F g A = F h B \<longleftrightarrow> F g C = F h C"
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   429
proof -
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   430
  from \<open>finite C\<close> subset have
58195
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   431
    "finite A" and "finite B" and "finite (C - A)" and "finite (C - B)"
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   432
    by (auto elim: finite_subset)
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   433
  from subset have [simp]: "A - (C - A) = A" by auto
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   434
  from subset have [simp]: "B - (C - B) = B" by auto
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   435
  from subset have "C = A \<union> (C - A)" by auto
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   436
  then have "F g C = F g (A \<union> (C - A))" by simp
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   437
  also have "\<dots> = F g (A - (C - A)) \<^bold>* F g (C - A - A) \<^bold>* F g (A \<inter> (C - A))"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   438
    using \<open>finite A\<close> \<open>finite (C - A)\<close> by (simp only: union_diff2)
58195
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   439
  finally have P: "F g C = F g A" using trivial by simp
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   440
  from subset have "C = B \<union> (C - B)" by auto
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   441
  then have "F h C = F h (B \<union> (C - B))" by simp
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   442
  also have "\<dots> = F h (B - (C - B)) \<^bold>* F h (C - B - B) \<^bold>* F h (B \<inter> (C - B))"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   443
    using \<open>finite B\<close> \<open>finite (C - B)\<close> by (simp only: union_diff2)
58195
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   444
  finally have Q: "F h C = F h B" using trivial by simp
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   445
  from P Q show ?thesis by simp
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   446
qed
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   447
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   448
lemma same_carrierI:
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   449
  assumes "finite C"
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   450
  assumes subset: "A \<subseteq> C" "B \<subseteq> C"
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   451
  assumes trivial: "\<And>a. a \<in> C - A \<Longrightarrow> g a = \<^bold>1" "\<And>b. b \<in> C - B \<Longrightarrow> h b = \<^bold>1"
58195
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   452
  assumes "F g C = F h C"
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   453
  shows "F g A = F h B"
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   454
  using assms same_carrier [of C A B] by simp
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   455
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   456
end
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   457
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   458
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   459
subsection \<open>Generalized summation over a set\<close>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   460
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   461
context comm_monoid_add
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   462
begin
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   463
61605
1bf7b186542e qualifier is mandatory by default;
wenzelm
parents: 61566
diff changeset
   464
sublocale setsum: comm_monoid_set plus 0
61776
57bb7da5c867 modernized
haftmann
parents: 61605
diff changeset
   465
defines
57bb7da5c867 modernized
haftmann
parents: 61605
diff changeset
   466
  setsum = setsum.F ..
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   467
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
   468
abbreviation Setsum ("\<Sum>_" [1000] 999)
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
   469
  where "\<Sum>A \<equiv> setsum (\<lambda>x. x) A"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   470
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   471
end
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   472
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
   473
text \<open>Now: lot's of fancy syntax. First, @{term "setsum (\<lambda>x. e) A"} is written \<open>\<Sum>x\<in>A. e\<close>.\<close>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   474
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
   475
syntax (ASCII)
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
   476
  "_setsum" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b::comm_monoid_add"  ("(3SUM _:_./ _)" [0, 51, 10] 10)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   477
syntax
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
   478
  "_setsum" :: "pttrn \<Rightarrow> 'a set \<Rightarrow> 'b \<Rightarrow> 'b::comm_monoid_add"  ("(2\<Sum>_\<in>_./ _)" [0, 51, 10] 10)
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61776
diff changeset
   479
translations \<comment> \<open>Beware of argument permutation!\<close>
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
   480
  "\<Sum>i\<in>A. b" \<rightleftharpoons> "CONST setsum (\<lambda>i. b) A"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   481
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
   482
text \<open>Instead of @{term"\<Sum>x\<in>{x. P}. e"} we introduce the shorter \<open>\<Sum>x|P. e\<close>.\<close>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   483
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
   484
syntax (ASCII)
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
   485
  "_qsetsum" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a"  ("(3SUM _ |/ _./ _)" [0, 0, 10] 10)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   486
syntax
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
   487
  "_qsetsum" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a"  ("(2\<Sum>_ | (_)./ _)" [0, 0, 10] 10)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   488
translations
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
   489
  "\<Sum>x|P. t" => "CONST setsum (\<lambda>x. t) {x. P}"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   490
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   491
print_translation \<open>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   492
let
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   493
  fun setsum_tr' [Abs (x, Tx, t), Const (@{const_syntax Collect}, _) $ Abs (y, Ty, P)] =
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   494
        if x <> y then raise Match
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   495
        else
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   496
          let
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   497
            val x' = Syntax_Trans.mark_bound_body (x, Tx);
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   498
            val t' = subst_bound (x', t);
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   499
            val P' = subst_bound (x', P);
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   500
          in
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   501
            Syntax.const @{syntax_const "_qsetsum"} $ Syntax_Trans.mark_bound_abs (x, Tx) $ P' $ t'
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   502
          end
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   503
    | setsum_tr' _ = raise Match;
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   504
in [(@{const_syntax setsum}, K setsum_tr')] end
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   505
\<close>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   506
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   507
text \<open>TODO generalization candidates\<close>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   508
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   509
lemma (in comm_monoid_add) setsum_image_gen:
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   510
  assumes fS: "finite S"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   511
  shows "setsum g S = setsum (\<lambda>y. setsum g {x. x \<in> S \<and> f x = y}) (f ` S)"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   512
proof-
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   513
  { fix x assume "x \<in> S" then have "{y. y\<in> f`S \<and> f x = y} = {f x}" by auto }
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   514
  hence "setsum g S = setsum (\<lambda>x. setsum (\<lambda>y. g x) {y. y\<in> f`S \<and> f x = y}) S"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   515
    by simp
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   516
  also have "\<dots> = setsum (\<lambda>y. setsum g {x. x \<in> S \<and> f x = y}) (f ` S)"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   517
    by (rule setsum.commute_restrict [OF fS finite_imageI [OF fS]])
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   518
  finally show ?thesis .
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   519
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   520
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   521
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   522
subsubsection \<open>Properties in more restricted classes of structures\<close>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   523
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   524
lemma setsum_Un: "finite A ==> finite B ==>
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   525
  (setsum f (A Un B) :: 'a :: ab_group_add) =
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   526
   setsum f A + setsum f B - setsum f (A Int B)"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   527
by (subst setsum.union_inter [symmetric], auto simp add: algebra_simps)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   528
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   529
lemma setsum_Un2:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   530
  assumes "finite (A \<union> B)"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   531
  shows "setsum f (A \<union> B) = setsum f (A - B) + setsum f (B - A) + setsum f (A \<inter> B)"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   532
proof -
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   533
  have "A \<union> B = A - B \<union> (B - A) \<union> A \<inter> B"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   534
    by auto
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   535
  with assms show ?thesis by simp (subst setsum.union_disjoint, auto)+
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   536
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   537
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   538
lemma setsum_diff1: "finite A \<Longrightarrow>
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   539
  (setsum f (A - {a}) :: ('a::ab_group_add)) =
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   540
  (if a:A then setsum f A - f a else setsum f A)"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   541
by (erule finite_induct) (auto simp add: insert_Diff_if)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   542
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   543
lemma setsum_diff:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   544
  assumes le: "finite A" "B \<subseteq> A"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   545
  shows "setsum f (A - B) = setsum f A - ((setsum f B)::('a::ab_group_add))"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   546
proof -
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   547
  from le have finiteB: "finite B" using finite_subset by auto
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   548
  show ?thesis using finiteB le
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   549
  proof induct
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   550
    case empty
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   551
    thus ?case by auto
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   552
  next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   553
    case (insert x F)
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   554
    thus ?case using le finiteB
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   555
      by (simp add: Diff_insert[where a=x and B=F] setsum_diff1 insert_absorb)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   556
  qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   557
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   558
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   559
lemma (in ordered_comm_monoid_add) setsum_mono:
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   560
  assumes le: "\<And>i. i\<in>K \<Longrightarrow> f i \<le> g i"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   561
  shows "(\<Sum>i\<in>K. f i) \<le> (\<Sum>i\<in>K. g i)"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   562
proof (cases "finite K")
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   563
  case True
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   564
  thus ?thesis using le
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   565
  proof induct
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   566
    case empty
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   567
    thus ?case by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   568
  next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   569
    case insert
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   570
    thus ?case using add_mono by fastforce
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   571
  qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   572
next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   573
  case False then show ?thesis by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   574
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   575
62377
ace69956d018 moved more proofs to ordered_comm_monoid_add; introduced strict_ordered_ab_semigroup/comm_monoid_add
hoelzl
parents: 62376
diff changeset
   576
lemma (in strict_ordered_comm_monoid_add) setsum_strict_mono:
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   577
  assumes "finite A"  "A \<noteq> {}" and "\<And>x. x \<in> A \<Longrightarrow> f x < g x"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   578
  shows "setsum f A < setsum g A"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   579
  using assms
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   580
proof (induct rule: finite_ne_induct)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   581
  case singleton thus ?case by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   582
next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   583
  case insert thus ?case by (auto simp: add_strict_mono)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   584
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   585
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   586
lemma setsum_strict_mono_ex1:
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   587
  fixes f g :: "'i \<Rightarrow> 'a::ordered_cancel_comm_monoid_add"
62377
ace69956d018 moved more proofs to ordered_comm_monoid_add; introduced strict_ordered_ab_semigroup/comm_monoid_add
hoelzl
parents: 62376
diff changeset
   588
  assumes "finite A" and "\<forall>x\<in>A. f x \<le> g x" and "\<exists>a\<in>A. f a < g a"
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   589
  shows "setsum f A < setsum g A"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   590
proof-
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   591
  from assms(3) obtain a where a: "a:A" "f a < g a" by blast
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   592
  have "setsum f A = setsum f ((A-{a}) \<union> {a})"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   593
    by(simp add:insert_absorb[OF \<open>a:A\<close>])
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   594
  also have "\<dots> = setsum f (A-{a}) + setsum f {a}"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   595
    using \<open>finite A\<close> by(subst setsum.union_disjoint) auto
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   596
  also have "setsum f (A-{a}) \<le> setsum g (A-{a})"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   597
    by(rule setsum_mono)(simp add: assms(2))
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   598
  also have "setsum f {a} < setsum g {a}" using a by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   599
  also have "setsum g (A - {a}) + setsum g {a} = setsum g((A-{a}) \<union> {a})"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   600
    using \<open>finite A\<close> by(subst setsum.union_disjoint[symmetric]) auto
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   601
  also have "\<dots> = setsum g A" by(simp add:insert_absorb[OF \<open>a:A\<close>])
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   602
  finally show ?thesis by (auto simp add: add_right_mono add_strict_left_mono)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   603
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   604
59416
fde2659085e1 generalized sum_diff_distrib to setsum_subtractf_nat
hoelzl
parents: 59010
diff changeset
   605
lemma setsum_negf: "(\<Sum>x\<in>A. - f x::'a::ab_group_add) = - (\<Sum>x\<in>A. f x)"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   606
proof (cases "finite A")
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   607
  case True thus ?thesis by (induct set: finite) auto
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   608
next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   609
  case False thus ?thesis by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   610
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   611
59416
fde2659085e1 generalized sum_diff_distrib to setsum_subtractf_nat
hoelzl
parents: 59010
diff changeset
   612
lemma setsum_subtractf: "(\<Sum>x\<in>A. f x - g x::'a::ab_group_add) = (\<Sum>x\<in>A. f x) - (\<Sum>x\<in>A. g x)"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   613
  using setsum.distrib [of f "- g" A] by (simp add: setsum_negf)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   614
59416
fde2659085e1 generalized sum_diff_distrib to setsum_subtractf_nat
hoelzl
parents: 59010
diff changeset
   615
lemma setsum_subtractf_nat:
fde2659085e1 generalized sum_diff_distrib to setsum_subtractf_nat
hoelzl
parents: 59010
diff changeset
   616
  "(\<And>x. x \<in> A \<Longrightarrow> g x \<le> f x) \<Longrightarrow> (\<Sum>x\<in>A. f x - g x::nat) = (\<Sum>x\<in>A. f x) - (\<Sum>x\<in>A. g x)"
fde2659085e1 generalized sum_diff_distrib to setsum_subtractf_nat
hoelzl
parents: 59010
diff changeset
   617
  by (induction A rule: infinite_finite_induct) (auto simp: setsum_mono)
fde2659085e1 generalized sum_diff_distrib to setsum_subtractf_nat
hoelzl
parents: 59010
diff changeset
   618
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   619
lemma (in ordered_comm_monoid_add) setsum_nonneg:
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   620
  assumes nn: "\<forall>x\<in>A. 0 \<le> f x"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   621
  shows "0 \<le> setsum f A"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   622
proof (cases "finite A")
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   623
  case True thus ?thesis using nn
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   624
  proof induct
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   625
    case empty then show ?case by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   626
  next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   627
    case (insert x F)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   628
    then have "0 + 0 \<le> f x + setsum f F" by (blast intro: add_mono)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   629
    with insert show ?case by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   630
  qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   631
next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   632
  case False thus ?thesis by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   633
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   634
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   635
lemma (in ordered_comm_monoid_add) setsum_nonpos:
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   636
  assumes np: "\<forall>x\<in>A. f x \<le> 0"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   637
  shows "setsum f A \<le> 0"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   638
proof (cases "finite A")
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   639
  case True thus ?thesis using np
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   640
  proof induct
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   641
    case empty then show ?case by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   642
  next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   643
    case (insert x F)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   644
    then have "f x + setsum f F \<le> 0 + 0" by (blast intro: add_mono)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   645
    with insert show ?case by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   646
  qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   647
next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   648
  case False thus ?thesis by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   649
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   650
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   651
lemma (in ordered_comm_monoid_add) setsum_nonneg_eq_0_iff:
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   652
  "finite A \<Longrightarrow> \<forall>x\<in>A. 0 \<le> f x \<Longrightarrow> setsum f A = 0 \<longleftrightarrow> (\<forall>x\<in>A. f x = 0)"
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   653
  by (induct set: finite, simp) (simp add: add_nonneg_eq_0_iff setsum_nonneg)
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   654
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   655
lemma (in ordered_comm_monoid_add) setsum_nonneg_0:
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   656
  "finite s \<Longrightarrow> (\<And>i. i \<in> s \<Longrightarrow> f i \<ge> 0) \<Longrightarrow> (\<Sum> i \<in> s. f i) = 0 \<Longrightarrow> i \<in> s \<Longrightarrow> f i = 0"
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   657
  by (simp add: setsum_nonneg_eq_0_iff)
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   658
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   659
lemma (in ordered_comm_monoid_add) setsum_nonneg_leq_bound:
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   660
  assumes "finite s" "\<And>i. i \<in> s \<Longrightarrow> f i \<ge> 0" "(\<Sum>i \<in> s. f i) = B" "i \<in> s"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   661
  shows "f i \<le> B"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   662
proof -
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   663
  have "f i \<le> f i + (\<Sum>i \<in> s - {i}. f i)"
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   664
    using assms by (intro add_increasing2 setsum_nonneg) auto
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   665
  also have "\<dots> = B"
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   666
    using setsum.remove[of s i f] assms by simp
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   667
  finally show ?thesis by auto
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   668
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   669
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   670
lemma (in ordered_comm_monoid_add) setsum_mono2:
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   671
  assumes fin: "finite B" and sub: "A \<subseteq> B" and nn: "\<And>b. b \<in> B-A \<Longrightarrow> 0 \<le> f b"
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   672
  shows "setsum f A \<le> setsum f B"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   673
proof -
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   674
  have "setsum f A \<le> setsum f A + setsum f (B-A)"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   675
    by(simp add: add_increasing2[OF setsum_nonneg] nn Ball_def)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   676
  also have "\<dots> = setsum f (A \<union> (B-A))" using fin finite_subset[OF sub fin]
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   677
    by (simp add: setsum.union_disjoint del:Un_Diff_cancel)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   678
  also have "A \<union> (B-A) = B" using sub by blast
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   679
  finally show ?thesis .
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   680
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   681
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   682
lemma (in ordered_comm_monoid_add) setsum_le_included:
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   683
  assumes "finite s" "finite t"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   684
  and "\<forall>y\<in>t. 0 \<le> g y" "(\<forall>x\<in>s. \<exists>y\<in>t. i y = x \<and> f x \<le> g y)"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   685
  shows "setsum f s \<le> setsum g t"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   686
proof -
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   687
  have "setsum f s \<le> setsum (\<lambda>y. setsum g {x. x\<in>t \<and> i x = y}) s"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   688
  proof (rule setsum_mono)
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   689
    fix y assume "y \<in> s"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   690
    with assms obtain z where z: "z \<in> t" "y = i z" "f y \<le> g z" by auto
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   691
    with assms show "f y \<le> setsum g {x \<in> t. i x = y}" (is "?A y \<le> ?B y")
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   692
      using order_trans[of "?A (i z)" "setsum g {z}" "?B (i z)", intro]
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   693
      by (auto intro!: setsum_mono2)
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   694
  qed
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   695
  also have "... \<le> setsum (\<lambda>y. setsum g {x. x\<in>t \<and> i x = y}) (i ` t)"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   696
    using assms(2-4) by (auto intro!: setsum_mono2 setsum_nonneg)
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   697
  also have "... \<le> setsum g t"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   698
    using assms by (auto simp: setsum_image_gen[symmetric])
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   699
  finally show ?thesis .
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   700
qed
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   701
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   702
lemma (in ordered_comm_monoid_add) setsum_mono3:
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   703
  "finite B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> \<forall>x\<in>B - A. 0 \<le> f x \<Longrightarrow> setsum f A \<le> setsum f B"
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   704
  by (rule setsum_mono2) auto
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   705
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   706
lemma (in canonically_ordered_monoid_add) setsum_eq_0_iff [simp]:
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   707
  "finite F \<Longrightarrow> (setsum f F = 0) = (\<forall>a\<in>F. f a = 0)"
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   708
  by (intro ballI setsum_nonneg_eq_0_iff zero_le)
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   709
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   710
lemma setsum_right_distrib:
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   711
  fixes f :: "'a => ('b::semiring_0)"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   712
  shows "r * setsum f A = setsum (%n. r * f n) A"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   713
proof (cases "finite A")
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   714
  case True
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   715
  thus ?thesis
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   716
  proof induct
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   717
    case empty thus ?case by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   718
  next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   719
    case (insert x A) thus ?case by (simp add: distrib_left)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   720
  qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   721
next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   722
  case False thus ?thesis by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   723
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   724
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   725
lemma setsum_left_distrib:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   726
  "setsum f A * (r::'a::semiring_0) = (\<Sum>n\<in>A. f n * r)"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   727
proof (cases "finite A")
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   728
  case True
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   729
  then show ?thesis
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   730
  proof induct
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   731
    case empty thus ?case by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   732
  next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   733
    case (insert x A) thus ?case by (simp add: distrib_right)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   734
  qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   735
next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   736
  case False thus ?thesis by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   737
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   738
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   739
lemma setsum_divide_distrib:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   740
  "setsum f A / (r::'a::field) = (\<Sum>n\<in>A. f n / r)"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   741
proof (cases "finite A")
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   742
  case True
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   743
  then show ?thesis
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   744
  proof induct
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   745
    case empty thus ?case by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   746
  next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   747
    case (insert x A) thus ?case by (simp add: add_divide_distrib)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   748
  qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   749
next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   750
  case False thus ?thesis by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   751
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   752
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   753
lemma setsum_abs[iff]:
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   754
  fixes f :: "'a => ('b::ordered_ab_group_add_abs)"
61944
5d06ecfdb472 prefer symbols for "abs";
wenzelm
parents: 61943
diff changeset
   755
  shows "\<bar>setsum f A\<bar> \<le> setsum (%i. \<bar>f i\<bar>) A"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   756
proof (cases "finite A")
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   757
  case True
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   758
  thus ?thesis
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   759
  proof induct
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   760
    case empty thus ?case by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   761
  next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   762
    case (insert x A)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   763
    thus ?case by (auto intro: abs_triangle_ineq order_trans)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   764
  qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   765
next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   766
  case False thus ?thesis by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   767
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   768
60974
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   769
lemma setsum_abs_ge_zero[iff]:
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   770
  fixes f :: "'a => ('b::ordered_ab_group_add_abs)"
61944
5d06ecfdb472 prefer symbols for "abs";
wenzelm
parents: 61943
diff changeset
   771
  shows "0 \<le> setsum (%i. \<bar>f i\<bar>) A"
60974
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   772
  by (simp add: setsum_nonneg)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   773
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   774
lemma abs_setsum_abs[simp]:
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   775
  fixes f :: "'a => ('b::ordered_ab_group_add_abs)"
61944
5d06ecfdb472 prefer symbols for "abs";
wenzelm
parents: 61943
diff changeset
   776
  shows "\<bar>\<Sum>a\<in>A. \<bar>f a\<bar>\<bar> = (\<Sum>a\<in>A. \<bar>f a\<bar>)"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   777
proof (cases "finite A")
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   778
  case True
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   779
  thus ?thesis
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   780
  proof induct
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   781
    case empty thus ?case by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   782
  next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   783
    case (insert a A)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   784
    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
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   785
    also have "\<dots> = \<bar>\<bar>f a\<bar> + \<bar>\<Sum>a\<in>A. \<bar>f a\<bar>\<bar>\<bar>"  using insert by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   786
    also have "\<dots> = \<bar>f a\<bar> + \<bar>\<Sum>a\<in>A. \<bar>f a\<bar>\<bar>"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   787
      by (simp del: abs_of_nonneg)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   788
    also have "\<dots> = (\<Sum>a\<in>insert a A. \<bar>f a\<bar>)" using insert by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   789
    finally show ?case .
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   790
  qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   791
next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   792
  case False thus ?thesis by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   793
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   794
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   795
lemma setsum_diff1_ring: assumes "finite A" "a \<in> A"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   796
  shows "setsum f (A - {a}) = setsum f A - (f a::'a::ring)"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   797
  unfolding setsum.remove [OF assms] by auto
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   798
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   799
lemma setsum_product:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   800
  fixes f :: "'a => ('b::semiring_0)"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   801
  shows "setsum f A * setsum g B = (\<Sum>i\<in>A. \<Sum>j\<in>B. f i * g j)"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   802
  by (simp add: setsum_right_distrib setsum_left_distrib) (rule setsum.commute)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   803
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   804
lemma setsum_mult_setsum_if_inj:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   805
fixes f :: "'a => ('b::semiring_0)"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   806
shows "inj_on (%(a,b). f a * g b) (A \<times> B) ==>
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   807
  setsum f A * setsum g B = setsum id {f a * g b|a b. a:A & b:B}"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   808
by(auto simp: setsum_product setsum.cartesian_product
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   809
        intro!:  setsum.reindex_cong[symmetric])
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   810
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   811
lemma setsum_SucD: "setsum f A = Suc n ==> EX a:A. 0 < f a"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   812
apply (case_tac "finite A")
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   813
 prefer 2 apply simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   814
apply (erule rev_mp)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   815
apply (erule finite_induct, auto)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   816
done
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   817
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   818
lemma setsum_eq_Suc0_iff: "finite A \<Longrightarrow>
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   819
  setsum f A = Suc 0 \<longleftrightarrow> (EX a:A. f a = Suc 0 & (ALL b:A. a\<noteq>b \<longrightarrow> f b = 0))"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   820
apply(erule finite_induct)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   821
apply (auto simp add:add_is_1)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   822
done
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   823
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   824
lemmas setsum_eq_1_iff = setsum_eq_Suc0_iff[simplified One_nat_def[symmetric]]
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   825
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   826
lemma setsum_Un_nat: "finite A ==> finite B ==>
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   827
  (setsum f (A Un B) :: nat) = setsum f A + setsum f B - setsum f (A Int B)"
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61776
diff changeset
   828
  \<comment> \<open>For the natural numbers, we have subtraction.\<close>
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   829
by (subst setsum.union_inter [symmetric], auto simp add: algebra_simps)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   830
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   831
lemma setsum_diff1_nat: "(setsum f (A - {a}) :: nat) =
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   832
  (if a:A then setsum f A - f a else setsum f A)"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   833
apply (case_tac "finite A")
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   834
 prefer 2 apply simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   835
apply (erule finite_induct)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   836
 apply (auto simp add: insert_Diff_if)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   837
apply (drule_tac a = a in mk_disjoint_insert, auto)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   838
done
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   839
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   840
lemma setsum_diff_nat:
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   841
assumes "finite B" and "B \<subseteq> A"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   842
shows "(setsum f (A - B) :: nat) = (setsum f A) - (setsum f B)"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   843
using assms
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   844
proof induct
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   845
  show "setsum f (A - {}) = (setsum f A) - (setsum f {})" by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   846
next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   847
  fix F x assume finF: "finite F" and xnotinF: "x \<notin> F"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   848
    and xFinA: "insert x F \<subseteq> A"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   849
    and IH: "F \<subseteq> A \<Longrightarrow> setsum f (A - F) = setsum f A - setsum f F"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   850
  from xnotinF xFinA have xinAF: "x \<in> (A - F)" by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   851
  from xinAF have A: "setsum f ((A - F) - {x}) = setsum f (A - F) - f x"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   852
    by (simp add: setsum_diff1_nat)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   853
  from xFinA have "F \<subseteq> A" by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   854
  with IH have "setsum f (A - F) = setsum f A - setsum f F" by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   855
  with A have B: "setsum f ((A - F) - {x}) = setsum f A - setsum f F - f x"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   856
    by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   857
  from xnotinF have "A - insert x F = (A - F) - {x}" by auto
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   858
  with B have C: "setsum f (A - insert x F) = setsum f A - setsum f F - f x"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   859
    by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   860
  from finF xnotinF have "setsum f (insert x F) = setsum f F + f x" by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   861
  with C have "setsum f (A - insert x F) = setsum f A - setsum f (insert x F)"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   862
    by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   863
  thus "setsum f (A - insert x F) = setsum f A - setsum f (insert x F)" by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   864
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   865
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   866
lemma setsum_comp_morphism:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   867
  assumes "h 0 = 0" and "\<And>x y. h (x + y) = h x + h y"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   868
  shows "setsum (h \<circ> g) A = h (setsum g A)"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   869
proof (cases "finite A")
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   870
  case False then show ?thesis by (simp add: assms)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   871
next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   872
  case True then show ?thesis by (induct A) (simp_all add: assms)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   873
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   874
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
   875
lemma (in comm_semiring_1) dvd_setsum:
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
   876
  "(\<And>a. a \<in> A \<Longrightarrow> d dvd f a) \<Longrightarrow> d dvd setsum f A"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
   877
  by (induct A rule: infinite_finite_induct) simp_all
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
   878
62377
ace69956d018 moved more proofs to ordered_comm_monoid_add; introduced strict_ordered_ab_semigroup/comm_monoid_add
hoelzl
parents: 62376
diff changeset
   879
lemma (in ordered_comm_monoid_add) setsum_pos:
ace69956d018 moved more proofs to ordered_comm_monoid_add; introduced strict_ordered_ab_semigroup/comm_monoid_add
hoelzl
parents: 62376
diff changeset
   880
  "finite I \<Longrightarrow> I \<noteq> {} \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> 0 < f i) \<Longrightarrow> 0 < setsum f I"
ace69956d018 moved more proofs to ordered_comm_monoid_add; introduced strict_ordered_ab_semigroup/comm_monoid_add
hoelzl
parents: 62376
diff changeset
   881
  by (induct I rule: finite_ne_induct) (auto intro: add_pos_pos)
ace69956d018 moved more proofs to ordered_comm_monoid_add; introduced strict_ordered_ab_semigroup/comm_monoid_add
hoelzl
parents: 62376
diff changeset
   882
ace69956d018 moved more proofs to ordered_comm_monoid_add; introduced strict_ordered_ab_semigroup/comm_monoid_add
hoelzl
parents: 62376
diff changeset
   883
lemma (in ordered_comm_monoid_add) setsum_pos2:
ace69956d018 moved more proofs to ordered_comm_monoid_add; introduced strict_ordered_ab_semigroup/comm_monoid_add
hoelzl
parents: 62376
diff changeset
   884
  assumes I: "finite I" "i \<in> I" "0 < f i" "\<And>i. i \<in> I \<Longrightarrow> 0 \<le> f i"
ace69956d018 moved more proofs to ordered_comm_monoid_add; introduced strict_ordered_ab_semigroup/comm_monoid_add
hoelzl
parents: 62376
diff changeset
   885
  shows "0 < setsum f I"
60974
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   886
proof -
62377
ace69956d018 moved more proofs to ordered_comm_monoid_add; introduced strict_ordered_ab_semigroup/comm_monoid_add
hoelzl
parents: 62376
diff changeset
   887
  have "0 < f i + setsum f (I - {i})"
ace69956d018 moved more proofs to ordered_comm_monoid_add; introduced strict_ordered_ab_semigroup/comm_monoid_add
hoelzl
parents: 62376
diff changeset
   888
    using assms by (intro add_pos_nonneg setsum_nonneg) auto
ace69956d018 moved more proofs to ordered_comm_monoid_add; introduced strict_ordered_ab_semigroup/comm_monoid_add
hoelzl
parents: 62376
diff changeset
   889
  also have "\<dots> = setsum f I"
60974
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   890
    using assms by (simp add: setsum.remove)
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   891
  finally show ?thesis .
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   892
qed
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   893
61524
f2e51e704a96 added many small lemmas about setsum/setprod/powr/...
eberlm
parents: 61378
diff changeset
   894
lemma setsum_cong_Suc:
f2e51e704a96 added many small lemmas about setsum/setprod/powr/...
eberlm
parents: 61378
diff changeset
   895
  assumes "0 \<notin> A" "\<And>x. Suc x \<in> A \<Longrightarrow> f (Suc x) = g (Suc x)"
f2e51e704a96 added many small lemmas about setsum/setprod/powr/...
eberlm
parents: 61378
diff changeset
   896
  shows   "setsum f A = setsum g A"
f2e51e704a96 added many small lemmas about setsum/setprod/powr/...
eberlm
parents: 61378
diff changeset
   897
proof (rule setsum.cong)
f2e51e704a96 added many small lemmas about setsum/setprod/powr/...
eberlm
parents: 61378
diff changeset
   898
  fix x assume "x \<in> A"
f2e51e704a96 added many small lemmas about setsum/setprod/powr/...
eberlm
parents: 61378
diff changeset
   899
  with assms(1) show "f x = g x" by (cases x) (auto intro!: assms(2))
f2e51e704a96 added many small lemmas about setsum/setprod/powr/...
eberlm
parents: 61378
diff changeset
   900
qed simp_all
f2e51e704a96 added many small lemmas about setsum/setprod/powr/...
eberlm
parents: 61378
diff changeset
   901
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   902
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   903
subsubsection \<open>Cardinality as special case of @{const setsum}\<close>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   904
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   905
lemma card_eq_setsum:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   906
  "card A = setsum (\<lambda>x. 1) A"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   907
proof -
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   908
  have "plus \<circ> (\<lambda>_. Suc 0) = (\<lambda>_. Suc)"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   909
    by (simp add: fun_eq_iff)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   910
  then have "Finite_Set.fold (plus \<circ> (\<lambda>_. Suc 0)) = Finite_Set.fold (\<lambda>_. Suc)"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   911
    by (rule arg_cong)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   912
  then have "Finite_Set.fold (plus \<circ> (\<lambda>_. Suc 0)) 0 A = Finite_Set.fold (\<lambda>_. Suc) 0 A"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   913
    by (blast intro: fun_cong)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   914
  then show ?thesis by (simp add: card.eq_fold setsum.eq_fold)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   915
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   916
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   917
lemma setsum_constant [simp]:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   918
  "(\<Sum>x \<in> A. y) = of_nat (card A) * y"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   919
apply (cases "finite A")
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   920
apply (erule finite_induct)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   921
apply (auto simp add: algebra_simps)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   922
done
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   923
59615
fdfdf89a83a6 A few new lemmas and a bit of tidying up
paulson <lp15@cam.ac.uk>
parents: 59416
diff changeset
   924
lemma setsum_Suc: "setsum (\<lambda>x. Suc(f x)) A = setsum f A + card A"
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   925
  using setsum.distrib[of f "\<lambda>_. 1" A]
59615
fdfdf89a83a6 A few new lemmas and a bit of tidying up
paulson <lp15@cam.ac.uk>
parents: 59416
diff changeset
   926
  by simp
58349
107341a15946 added lemma
nipkow
parents: 58195
diff changeset
   927
60974
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   928
lemma setsum_bounded_above:
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   929
  assumes le: "\<And>i. i\<in>A \<Longrightarrow> f i \<le> (K::'a::{semiring_1, ordered_comm_monoid_add})"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   930
  shows "setsum f A \<le> of_nat (card A) * K"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   931
proof (cases "finite A")
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   932
  case True
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   933
  thus ?thesis using le setsum_mono[where K=A and g = "%x. K"] by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   934
next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   935
  case False thus ?thesis by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   936
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   937
60974
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   938
lemma setsum_bounded_above_strict:
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   939
  assumes "\<And>i. i\<in>A \<Longrightarrow> f i < (K::'a::{ordered_cancel_comm_monoid_add,semiring_1})"
60974
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   940
          "card A > 0"
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   941
  shows "setsum f A < of_nat (card A) * K"
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   942
using assms setsum_strict_mono[where A=A and g = "%x. K"]
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   943
by (simp add: card_gt_0_iff)
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   944
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   945
lemma setsum_bounded_below:
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
   946
  assumes le: "\<And>i. i\<in>A \<Longrightarrow> (K::'a::{semiring_1, ordered_comm_monoid_add}) \<le> f i"
60974
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   947
  shows "of_nat (card A) * K \<le> setsum f A"
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   948
proof (cases "finite A")
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   949
  case True
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   950
  thus ?thesis using le setsum_mono[where K=A and f = "%x. K"] by simp
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   951
next
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   952
  case False thus ?thesis by simp
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   953
qed
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   954
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   955
lemma card_UN_disjoint:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   956
  assumes "finite I" and "\<forall>i\<in>I. finite (A i)"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   957
    and "\<forall>i\<in>I. \<forall>j\<in>I. i \<noteq> j \<longrightarrow> A i \<inter> A j = {}"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   958
  shows "card (UNION I A) = (\<Sum>i\<in>I. card(A i))"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   959
proof -
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   960
  have "(\<Sum>i\<in>I. card (A i)) = (\<Sum>i\<in>I. \<Sum>x\<in>A i. 1)" by simp
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   961
  with assms show ?thesis by (simp add: card_eq_setsum setsum.UNION_disjoint del: setsum_constant)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   962
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   963
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   964
lemma card_Union_disjoint:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   965
  "finite C ==> (ALL A:C. finite A) ==>
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   966
   (ALL A:C. ALL B:C. A \<noteq> B --> A Int B = {})
61952
546958347e05 prefer symbols for "Union", "Inter";
wenzelm
parents: 61944
diff changeset
   967
   ==> card (\<Union>C) = setsum card C"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   968
apply (frule card_UN_disjoint [of C id])
56166
9a241bc276cd normalising simp rules for compound operators
haftmann
parents: 55096
diff changeset
   969
apply simp_all
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   970
done
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   971
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   972
lemma setsum_multicount_gen:
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   973
  assumes "finite s" "finite t" "\<forall>j\<in>t. (card {i\<in>s. R i j} = k j)"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   974
  shows "setsum (\<lambda>i. (card {j\<in>t. R i j})) s = setsum k t" (is "?l = ?r")
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   975
proof-
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   976
  have "?l = setsum (\<lambda>i. setsum (\<lambda>x.1) {j\<in>t. R i j}) s" by auto
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   977
  also have "\<dots> = ?r" unfolding setsum.commute_restrict [OF assms(1-2)]
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   978
    using assms(3) by auto
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   979
  finally show ?thesis .
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   980
qed
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   981
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   982
lemma setsum_multicount:
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   983
  assumes "finite S" "finite T" "\<forall>j\<in>T. (card {i\<in>S. R i j} = k)"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   984
  shows "setsum (\<lambda>i. card {j\<in>T. R i j}) S = k * card T" (is "?l = ?r")
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   985
proof-
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   986
  have "?l = setsum (\<lambda>i. k) T" by (rule setsum_multicount_gen) (auto simp: assms)
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 57418
diff changeset
   987
  also have "\<dots> = ?r" by (simp add: mult.commute)
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   988
  finally show ?thesis by auto
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   989
qed
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   990
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   991
subsubsection \<open>Cardinality of products\<close>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   992
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   993
lemma card_SigmaI [simp]:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   994
  "\<lbrakk> finite A; ALL a:A. finite (B a) \<rbrakk>
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   995
  \<Longrightarrow> card (SIGMA x: A. B x) = (\<Sum>a\<in>A. card (B a))"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   996
by(simp add: card_eq_setsum setsum.Sigma del:setsum_constant)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   997
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   998
(*
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   999
lemma SigmaI_insert: "y \<notin> A ==>
61943
7fba644ed827 discontinued ASCII replacement syntax <*>;
wenzelm
parents: 61799
diff changeset
  1000
  (SIGMA x:(insert y A). B x) = (({y} \<times> (B y)) \<union> (SIGMA x: A. B x))"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1001
  by auto
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1002
*)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1003
61943
7fba644ed827 discontinued ASCII replacement syntax <*>;
wenzelm
parents: 61799
diff changeset
  1004
lemma card_cartesian_product: "card (A \<times> B) = card(A) * card(B)"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1005
  by (cases "finite A \<and> finite B")
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1006
    (auto simp add: card_eq_0_iff dest: finite_cartesian_productD1 finite_cartesian_productD2)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1007
61943
7fba644ed827 discontinued ASCII replacement syntax <*>;
wenzelm
parents: 61799
diff changeset
  1008
lemma card_cartesian_product_singleton:  "card({x} \<times> A) = card(A)"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1009
by (simp add: card_cartesian_product)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1010
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1011
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
  1012
subsection \<open>Generalized product over a set\<close>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1013
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1014
context comm_monoid_mult
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1015
begin
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1016
61605
1bf7b186542e qualifier is mandatory by default;
wenzelm
parents: 61566
diff changeset
  1017
sublocale setprod: comm_monoid_set times 1
61776
57bb7da5c867 modernized
haftmann
parents: 61605
diff changeset
  1018
defines
57bb7da5c867 modernized
haftmann
parents: 61605
diff changeset
  1019
  setprod = setprod.F ..
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1020
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1021
abbreviation
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1022
  Setprod ("\<Prod>_" [1000] 999) where
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1023
  "\<Prod>A \<equiv> setprod (\<lambda>x. x) A"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1024
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1025
end
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1026
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
  1027
syntax (ASCII)
60494
e726f88232d3 correccted the pretty-printing specs for setsum and setprod
paulson <lp15@cam.ac.uk>
parents: 60429
diff changeset
  1028
  "_setprod" :: "pttrn => 'a set => 'b => 'b::comm_monoid_mult"  ("(4PROD _:_./ _)" [0, 51, 10] 10)
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
  1029
syntax
60494
e726f88232d3 correccted the pretty-printing specs for setsum and setprod
paulson <lp15@cam.ac.uk>
parents: 60429
diff changeset
  1030
  "_setprod" :: "pttrn => 'a set => 'b => 'b::comm_monoid_mult"  ("(2\<Prod>_\<in>_./ _)" [0, 51, 10] 10)
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61776
diff changeset
  1031
translations \<comment> \<open>Beware of argument permutation!\<close>
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
  1032
  "\<Prod>i\<in>A. b" == "CONST setprod (\<lambda>i. b) A"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1033
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
  1034
text \<open>Instead of @{term"\<Prod>x\<in>{x. P}. e"} we introduce the shorter \<open>\<Prod>x|P. e\<close>.\<close>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1035
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
  1036
syntax (ASCII)
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
  1037
  "_qsetprod" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a"  ("(4PROD _ |/ _./ _)" [0, 0, 10] 10)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1038
syntax
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
  1039
  "_qsetprod" :: "pttrn \<Rightarrow> bool \<Rightarrow> 'a \<Rightarrow> 'a"  ("(2\<Prod>_ | (_)./ _)" [0, 0, 10] 10)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1040
translations
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
  1041
  "\<Prod>x|P. t" => "CONST setprod (\<lambda>x. t) {x. P}"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1042
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1043
context comm_monoid_mult
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1044
begin
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1045
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
  1046
lemma setprod_dvd_setprod:
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1047
  "(\<And>a. a \<in> A \<Longrightarrow> f a dvd g a) \<Longrightarrow> setprod f A dvd setprod g A"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1048
proof (induct A rule: infinite_finite_induct)
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1049
  case infinite then show ?case by (auto intro: dvdI)
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1050
next
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1051
  case empty then show ?case by (auto intro: dvdI)
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1052
next
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1053
  case (insert a A) then
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1054
  have "f a dvd g a" and "setprod f A dvd setprod g A" by simp_all
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1055
  then obtain r s where "g a = f a * r" and "setprod g A = setprod f A * s" by (auto elim!: dvdE)
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1056
  then have "g a * setprod g A = f a * setprod f A * (r * s)" by (simp add: ac_simps)
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1057
  with insert.hyps show ?case by (auto intro: dvdI)
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1058
qed
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1059
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1060
lemma setprod_dvd_setprod_subset:
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1061
  "finite B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> setprod f A dvd setprod f B"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1062
  by (auto simp add: setprod.subset_diff ac_simps intro: dvdI)
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1063
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1064
end
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1065
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1066
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
  1067
subsubsection \<open>Properties in more restricted classes of structures\<close>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1068
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1069
context comm_semiring_1
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1070
begin
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1071
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1072
lemma dvd_setprod_eqI [intro]:
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1073
  assumes "finite A" and "a \<in> A" and "b = f a"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1074
  shows "b dvd setprod f A"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1075
proof -
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
  1076
  from \<open>finite A\<close> have "setprod f (insert a (A - {a})) = f a * setprod f (A - {a})"
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1077
    by (intro setprod.insert) auto
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
  1078
  also from \<open>a \<in> A\<close> have "insert a (A - {a}) = A" by blast
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1079
  finally have "setprod f A = f a * setprod f (A - {a})" .
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
  1080
  with \<open>b = f a\<close> show ?thesis by simp
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1081
qed
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1082
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1083
lemma dvd_setprodI [intro]:
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1084
  assumes "finite A" and "a \<in> A"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1085
  shows "f a dvd setprod f A"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1086
  using assms by auto
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1087
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1088
lemma setprod_zero:
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1089
  assumes "finite A" and "\<exists>a\<in>A. f a = 0"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1090
  shows "setprod f A = 0"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1091
using assms proof (induct A)
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1092
  case empty then show ?case by simp
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1093
next
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1094
  case (insert a A)
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1095
  then have "f a = 0 \<or> (\<exists>a\<in>A. f a = 0)" by simp
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1096
  then have "f a * setprod f A = 0" by rule (simp_all add: insert)
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1097
  with insert show ?case by simp
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1098
qed
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1099
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1100
lemma setprod_dvd_setprod_subset2:
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1101
  assumes "finite B" and "A \<subseteq> B" and "\<And>a. a \<in> A \<Longrightarrow> f a dvd g a"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1102
  shows "setprod f A dvd setprod g B"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1103
proof -
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1104
  from assms have "setprod f A dvd setprod g A"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1105
    by (auto intro: setprod_dvd_setprod)
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1106
  moreover from assms have "setprod g A dvd setprod g B"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1107
    by (auto intro: setprod_dvd_setprod_subset)
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1108
  ultimately show ?thesis by (rule dvd_trans)
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1109
qed
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1110
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1111
end
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1112
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1113
lemma setprod_zero_iff [simp]:
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1114
  assumes "finite A"
59833
ab828c2c5d67 clarified no_zero_devisors: makes only sense in a semiring;
haftmann
parents: 59615
diff changeset
  1115
  shows "setprod f A = (0::'a::semidom) \<longleftrightarrow> (\<exists>a\<in>A. f a = 0)"
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1116
  using assms by (induct A) (auto simp: no_zero_divisors)
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1117
60353
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1118
lemma (in semidom_divide) setprod_diff1:
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1119
  assumes "finite A" and "f a \<noteq> 0"
60429
d3d1e185cd63 uniform _ div _ as infix syntax for ring division
haftmann
parents: 60353
diff changeset
  1120
  shows "setprod f (A - {a}) = (if a \<in> A then setprod f A div f a else setprod f A)"
60353
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1121
proof (cases "a \<notin> A")
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1122
  case True then show ?thesis by simp
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1123
next
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1124
  case False with assms show ?thesis
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1125
  proof (induct A rule: finite_induct)
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1126
    case empty then show ?case by simp
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1127
  next
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1128
    case (insert b B)
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1129
    then show ?case
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1130
    proof (cases "a = b")
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1131
      case True with insert show ?thesis by simp
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1132
    next
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1133
      case False with insert have "a \<in> B" by simp
63040
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 62481
diff changeset
  1134
      define C where "C = B - {a}"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
  1135
      with \<open>finite B\<close> \<open>a \<in> B\<close>
60353
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1136
        have *: "B = insert a C" "finite C" "a \<notin> C" by auto
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1137
      with insert show ?thesis by (auto simp add: insert_commute ac_simps)
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1138
    qed
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1139
  qed
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1140
qed
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1141
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1142
lemma setsum_zero_power [simp]:
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1143
  fixes c :: "nat \<Rightarrow> 'a::division_ring"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1144
  shows "(\<Sum>i\<in>A. c i * 0^i) = (if finite A \<and> 0 \<in> A then c 0 else 0)"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1145
apply (cases "finite A")
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1146
  by (induction A rule: finite_induct) auto
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1147
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1148
lemma setsum_zero_power' [simp]:
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1149
  fixes c :: "nat \<Rightarrow> 'a::field"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1150
  shows "(\<Sum>i\<in>A. c i * 0^i / d i) = (if finite A \<and> 0 \<in> A then c 0 / d 0 else 0)"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1151
  using setsum_zero_power [of "\<lambda>i. c i / d i" A]
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1152
  by auto
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1153
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
  1154
lemma (in field) setprod_inversef:
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1155
  "finite A \<Longrightarrow> setprod (inverse \<circ> f) A = inverse (setprod f A)"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1156
  by (induct A rule: finite_induct) simp_all
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1157
59867
58043346ca64 given up separate type classes demanding `inverse 0 = 0`
haftmann
parents: 59833
diff changeset
  1158
lemma (in field) setprod_dividef:
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1159
  "finite A \<Longrightarrow> (\<Prod>x\<in>A. f x / g x) = setprod f A / setprod g A"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1160
  using setprod_inversef [of A g] by (simp add: divide_inverse setprod.distrib)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1161
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1162
lemma setprod_Un:
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1163
  fixes f :: "'b \<Rightarrow> 'a :: field"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1164
  assumes "finite A" and "finite B"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1165
  and "\<forall>x\<in>A \<inter> B. f x \<noteq> 0"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1166
  shows "setprod f (A \<union> B) = setprod f A * setprod f B / setprod f (A \<inter> B)"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1167
proof -
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1168
  from assms have "setprod f A * setprod f B = setprod f (A \<union> B) * setprod f (A \<inter> B)"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1169
    by (simp add: setprod.union_inter [symmetric, of A B])
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1170
  with assms show ?thesis by simp
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1171
qed
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1172
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1173
lemma (in linordered_semidom) setprod_nonneg:
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1174
  "(\<forall>a\<in>A. 0 \<le> f a) \<Longrightarrow> 0 \<le> setprod f A"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1175
  by (induct A rule: infinite_finite_induct) simp_all
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1176
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1177
lemma (in linordered_semidom) setprod_pos:
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1178
  "(\<forall>a\<in>A. 0 < f a) \<Longrightarrow> 0 < setprod f A"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1179
  by (induct A rule: infinite_finite_induct) simp_all
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1180
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1181
lemma (in linordered_semidom) setprod_mono:
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
  1182
  "\<forall>i\<in>A. 0 \<le> f i \<and> f i \<le> g i \<Longrightarrow> setprod f A \<le> setprod g A"
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
  1183
  by (induct A rule: infinite_finite_induct) (auto intro!: setprod_nonneg mult_mono)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1184
60974
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
  1185
lemma (in linordered_semidom) setprod_mono_strict:
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
  1186
    assumes"finite A" "\<forall>i\<in>A. 0 \<le> f i \<and> f i < g i" "A \<noteq> {}"
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
  1187
    shows "setprod f A < setprod g A"
62376
85f38d5f8807 Rename ordered_comm_monoid_add to ordered_cancel_comm_monoid_add. Introduce ordreed_comm_monoid_add, canonically_ordered_comm_monoid and dioid. Setup nat, entat and ennreal as dioids.
hoelzl
parents: 61955
diff changeset
  1188
using assms
60974
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
  1189
apply (induct A rule: finite_induct)
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
  1190
apply (simp add: )
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
  1191
apply (force intro: mult_strict_mono' setprod_nonneg)
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
  1192
done
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
  1193
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1194
lemma (in linordered_field) abs_setprod:
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1195
  "\<bar>setprod f A\<bar> = (\<Prod>x\<in>A. \<bar>f x\<bar>)"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1196
  by (induct A rule: infinite_finite_induct) (simp_all add: abs_mult)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1197
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1198
lemma setprod_eq_1_iff [simp]:
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1199
  "finite A \<Longrightarrow> setprod f A = 1 \<longleftrightarrow> (\<forall>a\<in>A. f a = (1::nat))"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1200
  by (induct A rule: finite_induct) simp_all
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1201
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1202
lemma setprod_pos_nat_iff [simp]:
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1203
  "finite A \<Longrightarrow> setprod f A > 0 \<longleftrightarrow> (\<forall>a\<in>A. f a > (0::nat))"
62378
85ed00c1fe7c generalize more theorems to support enat and ennreal
hoelzl
parents: 62377
diff changeset
  1204
  using setprod_zero_iff by (simp del: neq0_conv add: zero_less_iff_neq_zero)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1205
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1206
lemma setprod_constant:
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1207
  "(\<Prod>x\<in> A. (y::'a::comm_monoid_mult)) = y ^ card A"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1208
  by (induct A rule: infinite_finite_induct) simp_all
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1209
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1210
lemma setprod_power_distrib:
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1211
  fixes f :: "'a \<Rightarrow> 'b::comm_semiring_1"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1212
  shows "setprod f A ^ n = setprod (\<lambda>x. (f x) ^ n) A"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1213
proof (cases "finite A")
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1214
  case True then show ?thesis
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1215
    by (induct A rule: finite_induct) (auto simp add: power_mult_distrib)
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1216
next
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1217
  case False then show ?thesis
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1218
    by simp
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1219
qed
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1220
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1221
lemma power_setsum:
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1222
  "c ^ (\<Sum>a\<in>A. f a) = (\<Prod>a\<in>A. c ^ f a)"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1223
  by (induct A rule: infinite_finite_induct) (simp_all add: power_add)
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1224
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1225
lemma setprod_gen_delta:
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1226
  assumes fS: "finite S"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1227
  shows "setprod (\<lambda>k. if k=a then b k else c) S = (if a \<in> S then (b a ::'a::comm_monoid_mult) * c^ (card S - 1) else c^ card S)"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1228
proof-
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1229
  let ?f = "(\<lambda>k. if k=a then b k else c)"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1230
  {assume a: "a \<notin> S"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1231
    hence "\<forall> k\<in> S. ?f k = c" by simp
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1232
    hence ?thesis using a setprod_constant by simp }
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1233
  moreover
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1234
  {assume a: "a \<in> S"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1235
    let ?A = "S - {a}"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1236
    let ?B = "{a}"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1237
    have eq: "S = ?A \<union> ?B" using a by blast
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1238
    have dj: "?A \<inter> ?B = {}" by simp
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1239
    from fS have fAB: "finite ?A" "finite ?B" by auto
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1240
    have fA0:"setprod ?f ?A = setprod (\<lambda>i. c) ?A"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1241
      by (rule setprod.cong) auto
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1242
    have cA: "card ?A = card S - 1" using fS a by auto
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1243
    have fA1: "setprod ?f ?A = c ^ card ?A"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1244
      unfolding fA0 by (rule setprod_constant)
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1245
    have "setprod ?f ?A * setprod ?f ?B = setprod ?f S"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1246
      using setprod.union_disjoint[OF fAB dj, of ?f, unfolded eq[symmetric]]
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1247
      by simp
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1248
    then have ?thesis using a cA
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1249
      by (simp add: fA1 field_simps cong add: setprod.cong cong del: if_weak_cong)}
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1250
  ultimately show ?thesis by blast
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1251
qed
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1252
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1253
end