src/HOL/Groups_Big.thy
author wenzelm
Sat, 10 Nov 2018 19:01:20 +0100
changeset 69281 599b6d0d199b
parent 69275 9bbd5497befd
child 69316 248696d0a05f
permissions -rw-r--r--
tuned signature;
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
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
     2
    Author:     Tobias Nipkow
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
     3
    Author:     Lawrence C Paulson
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
     4
    Author:     Markus Wenzel
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
     5
    Author:     Jeremy Avigad
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
     6
*)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
     7
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
     8
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
     9
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    10
theory Groups_Big
66364
fa3247e6ee4b tuning imports
blanchet
parents: 66112
diff changeset
    11
  imports Power
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    12
begin
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    13
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
    14
subsection \<open>Generic monoid operation over a set\<close>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    15
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    16
locale comm_monoid_set = comm_monoid
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    17
begin
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    18
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    19
interpretation comp_fun_commute f
61169
4de9ff3ea29a tuned proofs -- less legacy;
wenzelm
parents: 61032
diff changeset
    20
  by standard (simp add: fun_eq_iff left_commute)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    21
54745
46e441e61ff5 disambiguation of interpretation prefixes
haftmann
parents: 54744
diff changeset
    22
interpretation comp?: comp_fun_commute "f \<circ> g"
46e441e61ff5 disambiguation of interpretation prefixes
haftmann
parents: 54744
diff changeset
    23
  by (fact comp_comp_fun_commute)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    24
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    25
definition F :: "('b \<Rightarrow> 'a) \<Rightarrow> 'b set \<Rightarrow> 'a"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    26
  where 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
    27
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    28
lemma infinite [simp]: "\<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
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    31
lemma empty [simp]: "F g {} = \<^bold>1"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    32
  by (simp add: eq_fold)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    33
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    34
lemma insert [simp]: "finite A \<Longrightarrow> x \<notin> A \<Longrightarrow> F g (insert x A) = g x \<^bold>* F g A"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    35
  by (simp add: eq_fold)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    36
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    37
lemma remove:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    38
  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
    39
  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
    40
proof -
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    41
  from \<open>x \<in> A\<close> obtain B where B: "A = insert x B" and "x \<notin> B"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    42
    by (auto dest: mk_disjoint_insert)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    43
  moreover from \<open>finite A\<close> B have "finite B" by simp
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    44
  ultimately show ?thesis by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    45
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    46
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    47
lemma insert_remove: "finite A \<Longrightarrow> F g (insert x A) = g x \<^bold>* F g (A - {x})"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    48
  by (cases "x \<in> A") (simp_all add: remove insert_absorb)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    49
63952
354808e9f44b new material connected with HOL Light measure theory, plus more rationalisation
paulson <lp15@cam.ac.uk>
parents: 63938
diff changeset
    50
lemma insert_if: "finite A \<Longrightarrow> F g (insert x A) = (if x \<in> A then F g A else g x \<^bold>* F g A)"
354808e9f44b new material connected with HOL Light measure theory, plus more rationalisation
paulson <lp15@cam.ac.uk>
parents: 63938
diff changeset
    51
  by (cases "x \<in> A") (simp_all add: insert_absorb)
354808e9f44b new material connected with HOL Light measure theory, plus more rationalisation
paulson <lp15@cam.ac.uk>
parents: 63938
diff changeset
    52
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    53
lemma neutral: "\<forall>x\<in>A. g x = \<^bold>1 \<Longrightarrow> F g A = \<^bold>1"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    54
  by (induct A rule: infinite_finite_induct) simp_all
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    55
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    56
lemma neutral_const [simp]: "F (\<lambda>_. \<^bold>1) A = \<^bold>1"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    57
  by (simp add: neutral)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    58
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    59
lemma union_inter:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    60
  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
    61
  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
    62
  \<comment> \<open>The reversed orientation looks more natural, but LOOPS as a simprule!\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    63
  using assms
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    64
proof (induct A)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    65
  case empty
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    66
  then show ?case by simp
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    67
next
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    68
  case (insert x A)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    69
  then show ?case
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    70
    by (auto simp: insert_absorb Int_insert_left commute [of _ "g x"] assoc left_commute)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    71
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    72
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    73
corollary union_inter_neutral:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    74
  assumes "finite A" and "finite B"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    75
    and "\<forall>x \<in> A \<inter> B. g x = \<^bold>1"
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
    76
  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
    77
  using assms by (simp add: union_inter [symmetric] neutral)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    78
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    79
corollary union_disjoint:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    80
  assumes "finite A" and "finite B"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    81
  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
    82
  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
    83
  using assms by (simp add: union_inter_neutral)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    84
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
    85
lemma union_diff2:
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
    86
  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
    87
  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
    88
proof -
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
    89
  have "A \<union> B = A - B \<union> (B - A) \<union> A \<inter> B"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
    90
    by auto
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    91
  with assms show ?thesis
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
    92
    by simp (subst union_disjoint, auto)+
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
    93
qed
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
    94
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    95
lemma subset_diff:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    96
  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
    97
  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
    98
proof -
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
    99
  from assms have "finite (A - B)" by auto
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   100
  moreover from assms have "finite B" by (rule finite_subset)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   101
  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
   102
  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
   103
  moreover from assms have "A \<union> B = A" by auto
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   104
  ultimately show ?thesis by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   105
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   106
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56544
diff changeset
   107
lemma setdiff_irrelevant:
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56544
diff changeset
   108
  assumes "finite A"
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56544
diff changeset
   109
  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
   110
  using assms by (induct A) (simp_all add: insert_Diff_if)
58195
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   111
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56544
diff changeset
   112
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
   113
  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
   114
  obtains a where "a \<in> A" and "g a \<noteq> \<^bold>1"
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56544
diff changeset
   115
proof -
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   116
  from assms have "\<exists>a\<in>A. g a \<noteq> \<^bold>1"
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56544
diff changeset
   117
  proof (induct A rule: infinite_finite_induct)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   118
    case infinite
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   119
    then show ?case by simp
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   120
  next
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   121
    case empty
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   122
    then show ?case by simp
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   123
  next
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56544
diff changeset
   124
    case (insert a A)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   125
    then show ?case by fastforce
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   126
  qed
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56544
diff changeset
   127
  with that show thesis by blast
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56544
diff changeset
   128
qed
8f1e7596deb7 more operations and lemmas
haftmann
parents: 56544
diff changeset
   129
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   130
lemma reindex:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   131
  assumes "inj_on h A"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   132
  shows "F g (h ` A) = F (g \<circ> h) A"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   133
proof (cases "finite A")
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   134
  case True
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   135
  with assms show ?thesis
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   136
    by (simp add: eq_fold fold_image comp_assoc)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   137
next
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   138
  case False
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   139
  with assms have "\<not> finite (h ` A)" by (blast dest: finite_imageD)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   140
  with False show ?thesis by simp
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   141
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   142
63357
bf2cf0653741 added fundef_cong rule
nipkow
parents: 63290
diff changeset
   143
lemma cong [fundef_cong]:
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   144
  assumes "A = B"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   145
  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
   146
  shows "F g A = F h B"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   147
  using g_h unfolding \<open>A = B\<close>
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   148
  by (induct B rule: infinite_finite_induct) auto
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   149
69164
74f1b0f10b2b uniform naming of strong congruence rules
nipkow
parents: 69144
diff changeset
   150
lemma cong_strong [cong]:
74f1b0f10b2b uniform naming of strong congruence rules
nipkow
parents: 69144
diff changeset
   151
  "\<lbrakk> A = B;  \<And>x. x \<in> B =simp=> g x = h x \<rbrakk> \<Longrightarrow> F (\<lambda>x. g x) A = F (\<lambda>x. h x) B"
74f1b0f10b2b uniform naming of strong congruence rules
nipkow
parents: 69144
diff changeset
   152
by (rule cong) (simp_all add: simp_implies_def)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   153
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   154
lemma reindex_cong:
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   155
  assumes "inj_on l B"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   156
  assumes "A = l ` B"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   157
  assumes "\<And>x. x \<in> B \<Longrightarrow> g (l x) = h x"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   158
  shows "F g A = F h B"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   159
  using assms by (simp add: reindex)
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   160
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   161
lemma UNION_disjoint:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   162
  assumes "finite I" and "\<forall>i\<in>I. finite (A i)"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   163
    and "\<forall>i\<in>I. \<forall>j\<in>I. i \<noteq> j \<longrightarrow> A i \<inter> A j = {}"
69275
9bbd5497befd clarified status of legacy input abbreviations
haftmann
parents: 69164
diff changeset
   164
  shows "F g (\<Union>(A ` I)) = F (\<lambda>x. F g (A x)) I"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   165
  apply (insert assms)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   166
  apply (induct rule: finite_induct)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   167
   apply simp
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   168
  apply atomize
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   169
  apply (subgoal_tac "\<forall>i\<in>Fa. x \<noteq> i")
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   170
   prefer 2 apply blast
69275
9bbd5497befd clarified status of legacy input abbreviations
haftmann
parents: 69164
diff changeset
   171
  apply (subgoal_tac "A x \<inter> \<Union>(A ` Fa) = {}")
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   172
   prefer 2 apply blast
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   173
  apply (simp add: union_disjoint)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   174
  done
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   175
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   176
lemma Union_disjoint:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   177
  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
   178
  shows "F g (\<Union>C) = (F \<circ> F) g C"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   179
proof (cases "finite C")
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   180
  case True
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   181
  from UNION_disjoint [OF this assms] show ?thesis by simp
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   182
next
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   183
  case False
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   184
  then show ?thesis by (auto dest: finite_UnionD intro: infinite)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   185
qed
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   186
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   187
lemma distrib: "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
   188
  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
   189
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   190
lemma Sigma:
61032
b57df8eecad6 standardized some occurences of ancient "split" alias
haftmann
parents: 60974
diff changeset
   191
  "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)"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   192
  apply (subst Sigma_def)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   193
  apply (subst UNION_disjoint)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   194
     apply assumption
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   195
    apply simp
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   196
   apply blast
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   197
  apply (rule cong)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   198
   apply rule
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   199
  apply (simp add: fun_eq_iff)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   200
  apply (subst UNION_disjoint)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   201
     apply simp
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   202
    apply simp
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   203
   apply blast
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   204
  apply (simp add: comp_def)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   205
  done
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   206
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
   207
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
   208
  assumes Re: "R \<^bold>1 \<^bold>1"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   209
    and Rop: "\<forall>x1 y1 x2 y2. R x1 x2 \<and> R y1 y2 \<longrightarrow> R (x1 \<^bold>* y1) (x2 \<^bold>* y2)"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   210
    and fin: "finite S"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   211
    and R_h_g: "\<forall>x\<in>S. R (h x) (g x)"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   212
  shows "R (F h S) (F g S)"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   213
  using fin by (rule finite_subset_induct) (use assms in auto)
54744
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_left:
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   216
  assumes "finite T"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   217
    and "S \<subseteq> T"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   218
    and "\<forall>i \<in> T - S. h i = \<^bold>1"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   219
    and "\<And>x. x \<in> S \<Longrightarrow> g x = h x"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   220
  shows "F g S = F h T"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   221
proof-
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   222
  have eq: "T = S \<union> (T - S)" using \<open>S \<subseteq> T\<close> by blast
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   223
  have d: "S \<inter> (T - S) = {}" using \<open>S \<subseteq> T\<close> by blast
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   224
  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
   225
    by (auto intro: finite_subset)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   226
  show ?thesis using assms(4)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   227
    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
   228
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   229
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   230
lemma mono_neutral_cong_right:
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   231
  "finite T \<Longrightarrow> S \<subseteq> T \<Longrightarrow> \<forall>i \<in> T - S. g i = \<^bold>1 \<Longrightarrow> (\<And>x. x \<in> S \<Longrightarrow> g x = h x) \<Longrightarrow>
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   232
    F g T = F h S"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   233
  by (auto intro!: mono_neutral_cong_left [symmetric])
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   234
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   235
lemma mono_neutral_left: "finite T \<Longrightarrow> S \<subseteq> T \<Longrightarrow> \<forall>i \<in> T - S. g i = \<^bold>1 \<Longrightarrow> F g S = F g T"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   236
  by (blast intro: mono_neutral_cong_left)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   237
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   238
lemma mono_neutral_right: "finite T \<Longrightarrow> S \<subseteq> T \<Longrightarrow> \<forall>i \<in> T - S. g i = \<^bold>1 \<Longrightarrow> F g T = F g S"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   239
  by (blast intro!: mono_neutral_left [symmetric])
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   240
64979
20a623d03d71 move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
hoelzl
parents: 64272
diff changeset
   241
lemma mono_neutral_cong:
20a623d03d71 move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
hoelzl
parents: 64272
diff changeset
   242
  assumes [simp]: "finite T" "finite S"
20a623d03d71 move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
hoelzl
parents: 64272
diff changeset
   243
    and *: "\<And>i. i \<in> T - S \<Longrightarrow> h i = \<^bold>1" "\<And>i. i \<in> S - T \<Longrightarrow> g i = \<^bold>1"
20a623d03d71 move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
hoelzl
parents: 64272
diff changeset
   244
    and gh: "\<And>x. x \<in> S \<inter> T \<Longrightarrow> g x = h x"
20a623d03d71 move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
hoelzl
parents: 64272
diff changeset
   245
 shows "F g S = F h T"
20a623d03d71 move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
hoelzl
parents: 64272
diff changeset
   246
proof-
20a623d03d71 move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
hoelzl
parents: 64272
diff changeset
   247
  have "F g S = F g (S \<inter> T)"
20a623d03d71 move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
hoelzl
parents: 64272
diff changeset
   248
    by(rule mono_neutral_right)(auto intro: *)
20a623d03d71 move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
hoelzl
parents: 64272
diff changeset
   249
  also have "\<dots> = F h (S \<inter> T)" using refl gh by(rule cong)
20a623d03d71 move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
hoelzl
parents: 64272
diff changeset
   250
  also have "\<dots> = F h T"
20a623d03d71 move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
hoelzl
parents: 64272
diff changeset
   251
    by(rule mono_neutral_left)(auto intro: *)
20a623d03d71 move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
hoelzl
parents: 64272
diff changeset
   252
  finally show ?thesis .
20a623d03d71 move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
hoelzl
parents: 64272
diff changeset
   253
qed
20a623d03d71 move mono_neutral_cong from AFP/Deep_Learning/PP_Auxiliary
hoelzl
parents: 64272
diff changeset
   254
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   255
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
   256
  by (auto simp: bij_betw_def reindex)
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   257
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   258
lemma reindex_bij_witness:
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   259
  assumes witness:
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   260
    "\<And>a. a \<in> S \<Longrightarrow> i (j a) = a"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   261
    "\<And>a. a \<in> S \<Longrightarrow> j a \<in> T"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   262
    "\<And>b. b \<in> T \<Longrightarrow> j (i b) = b"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   263
    "\<And>b. b \<in> T \<Longrightarrow> i b \<in> S"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   264
  assumes eq:
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   265
    "\<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
   266
  shows "F g S = F h T"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   267
proof -
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   268
  have "bij_betw j S T"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   269
    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
   270
  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
   271
    by (intro cong) (auto simp: eq)
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   272
  ultimately show ?thesis
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   273
    by (simp add: reindex_bij_betw)
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   274
qed
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   275
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   276
lemma reindex_bij_betw_not_neutral:
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   277
  assumes fin: "finite S'" "finite T'"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   278
  assumes bij: "bij_betw h (S - S') (T - T')"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   279
  assumes nn:
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   280
    "\<And>a. a \<in> S' \<Longrightarrow> g (h a) = z"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   281
    "\<And>b. b \<in> T' \<Longrightarrow> g b = z"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   282
  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
   283
proof -
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   284
  have [simp]: "finite S \<longleftrightarrow> finite T"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   285
    using bij_betw_finite[OF bij] fin by auto
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   286
  show ?thesis
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   287
  proof (cases "finite S")
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   288
    case True
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   289
    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
   290
      by (intro mono_neutral_cong_right) auto
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   291
    also have "\<dots> = F g (T - T')"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   292
      using bij by (rule reindex_bij_betw)
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   293
    also have "\<dots> = F g T"
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   294
      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
   295
    finally show ?thesis .
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   296
  next
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   297
    case False
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   298
    then show ?thesis by simp
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   299
  qed
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   300
qed
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   301
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   302
lemma reindex_nontrivial:
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   303
  assumes "finite A"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   304
    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
   305
  shows "F g (h ` A) = F (g \<circ> h) A"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   306
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
   307
  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
   308
    using nz by (auto intro!: inj_onI simp: bij_betw_def)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   309
qed (use \<open>finite A\<close> in auto)
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   310
57129
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   311
lemma reindex_bij_witness_not_neutral:
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   312
  assumes fin: "finite S'" "finite T'"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   313
  assumes witness:
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   314
    "\<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
   315
    "\<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
   316
    "\<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
   317
    "\<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
   318
  assumes nn:
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   319
    "\<And>a. a \<in> S' \<Longrightarrow> g a = z"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   320
    "\<And>b. b \<in> T' \<Longrightarrow> h b = z"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   321
  assumes eq:
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   322
    "\<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
   323
  shows "F g S = F h T"
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   324
proof -
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   325
  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
   326
    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
   327
  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
   328
    by (intro cong) (auto simp: eq)
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   329
  show ?thesis
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   330
    unfolding F_eq using fin nn eq
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   331
    by (intro reindex_bij_betw_not_neutral[OF _ _ bij]) auto
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   332
qed
7edb7550663e introduce more powerful reindexing rules for big operators
hoelzl
parents: 56545
diff changeset
   333
67673
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   334
lemma delta_remove:
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   335
  assumes fS: "finite S"
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   336
  shows "F (\<lambda>k. if k = a then b k else c k) S = (if a \<in> S then b a \<^bold>* F c (S-{a}) else F c (S-{a}))"
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   337
proof -
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   338
  let ?f = "(\<lambda>k. if k = a then b k else c k)"
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   339
  show ?thesis
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   340
  proof (cases "a \<in> S")
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   341
    case False
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   342
    then have "\<forall>k\<in>S. ?f k = c k" by simp
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   343
    with False show ?thesis by simp
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   344
  next
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   345
    case True
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   346
    let ?A = "S - {a}"
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   347
    let ?B = "{a}"
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   348
    from True have eq: "S = ?A \<union> ?B" by blast
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   349
    have dj: "?A \<inter> ?B = {}" by simp
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   350
    from fS have fAB: "finite ?A" "finite ?B" by auto
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   351
    have "F ?f S = F ?f ?A \<^bold>* F ?f ?B"
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   352
      using union_disjoint [OF fAB dj, of ?f, unfolded eq [symmetric]] by simp
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   353
    with True show ?thesis
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   354
      using comm_monoid_set.remove comm_monoid_set_axioms fS by fastforce
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   355
  qed
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   356
qed
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
   357
67683
817944aeac3f Lots of new material about matrices, etc.
paulson <lp15@cam.ac.uk>
parents: 67673
diff changeset
   358
lemma delta [simp]:
817944aeac3f Lots of new material about matrices, etc.
paulson <lp15@cam.ac.uk>
parents: 67673
diff changeset
   359
  assumes fS: "finite S"
817944aeac3f Lots of new material about matrices, etc.
paulson <lp15@cam.ac.uk>
parents: 67673
diff changeset
   360
  shows "F (\<lambda>k. if k = a then b k else \<^bold>1) S = (if a \<in> S then b a else \<^bold>1)"
817944aeac3f Lots of new material about matrices, etc.
paulson <lp15@cam.ac.uk>
parents: 67673
diff changeset
   361
  by (simp add: delta_remove [OF assms])
817944aeac3f Lots of new material about matrices, etc.
paulson <lp15@cam.ac.uk>
parents: 67673
diff changeset
   362
817944aeac3f Lots of new material about matrices, etc.
paulson <lp15@cam.ac.uk>
parents: 67673
diff changeset
   363
lemma delta' [simp]:
817944aeac3f Lots of new material about matrices, etc.
paulson <lp15@cam.ac.uk>
parents: 67673
diff changeset
   364
  assumes fin: "finite S"
817944aeac3f Lots of new material about matrices, etc.
paulson <lp15@cam.ac.uk>
parents: 67673
diff changeset
   365
  shows "F (\<lambda>k. if a = k then b k else \<^bold>1) S = (if a \<in> S then b a else \<^bold>1)"
817944aeac3f Lots of new material about matrices, etc.
paulson <lp15@cam.ac.uk>
parents: 67673
diff changeset
   366
  using delta [OF fin, of a b, symmetric] by (auto intro: cong)
817944aeac3f Lots of new material about matrices, etc.
paulson <lp15@cam.ac.uk>
parents: 67673
diff changeset
   367
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   368
lemma If_cases:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   369
  fixes P :: "'b \<Rightarrow> bool" and g h :: "'b \<Rightarrow> 'a"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   370
  assumes fin: "finite A"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   371
  shows "F (\<lambda>x. if P x then h x else g x) A = 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
   372
proof -
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   373
  have a: "A = A \<inter> {x. P x} \<union> A \<inter> -{x. P x}" "(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
   374
    by blast+
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   375
  from fin have f: "finite (A \<inter> {x. P x})" "finite (A \<inter> -{x. P x})" by auto
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   376
  let ?g = "\<lambda>x. if P x then h x else g x"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   377
  from union_disjoint [OF f a(2), of ?g] a(1) show ?thesis
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   378
    by (subst (1 2) cong) simp_all
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   379
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   380
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   381
lemma cartesian_product: "F (\<lambda>x. F (g x) B) A = F (case_prod g) (A \<times> B)"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   382
  apply (rule sym)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   383
  apply (cases "finite A")
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   384
   apply (cases "finite B")
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   385
    apply (simp add: Sigma)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   386
   apply (cases "A = {}")
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   387
    apply simp
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   388
   apply simp
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   389
   apply (auto intro: infinite dest: finite_cartesian_productD2)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   390
  apply (cases "B = {}")
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   391
   apply (auto intro: infinite dest: finite_cartesian_productD1)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   392
  done
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   393
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   394
lemma inter_restrict:
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   395
  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
   396
  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
   397
proof -
63290
9ac558ab0906 boldify syntax in abstract algebraic structures, to avoid clashes with concrete syntax in corresponding type classes
haftmann
parents: 63092
diff changeset
   398
  let ?g = "\<lambda>x. if x \<in> A \<inter> B then g x else \<^bold>1"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   399
  have "\<forall>i\<in>A - A \<inter> B. (if i \<in> A \<inter> B then g i else \<^bold>1) = \<^bold>1" by simp
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   400
  moreover have "A \<inter> B \<subseteq> A" by blast
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   401
  ultimately have "F ?g (A \<inter> B) = F ?g A"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   402
    using \<open>finite A\<close> by (intro mono_neutral_left) auto
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   403
  then show ?thesis by simp
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   404
qed
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   405
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   406
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
   407
  "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
   408
  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
   409
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   410
lemma Union_comp:
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   411
  assumes "\<forall>A \<in> B. finite A"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   412
    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
   413
  shows "F g (\<Union>B) = (F \<circ> F) g B"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   414
  using assms
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   415
proof (induct B rule: infinite_finite_induct)
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   416
  case (infinite A)
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   417
  then have "\<not> finite (\<Union>A)" by (blast dest: finite_UnionD)
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   418
  with infinite show ?case by simp
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   419
next
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   420
  case empty
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   421
  then show ?case by simp
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   422
next
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   423
  case (insert A B)
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   424
  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
   425
    and "\<forall>x\<in>A \<inter> \<Union>B. g x = \<^bold>1"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   426
    and H: "F g (\<Union>B) = (F \<circ> 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
   427
  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
   428
    by (simp add: union_inter_neutral)
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   429
  with \<open>finite B\<close> \<open>A \<notin> B\<close> show ?case
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   430
    by (simp add: H)
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   431
qed
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   432
66804
3f9bb52082c4 avoid name clashes on interpretation of abstract locales
haftmann
parents: 66364
diff changeset
   433
lemma swap: "F (\<lambda>i. F (g i) B) A = F (\<lambda>j. F (\<lambda>i. g i j) A) B"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   434
  unfolding cartesian_product
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   435
  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
   436
66804
3f9bb52082c4 avoid name clashes on interpretation of abstract locales
haftmann
parents: 66364
diff changeset
   437
lemma swap_restrict:
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   438
  "finite A \<Longrightarrow> finite B \<Longrightarrow>
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   439
    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"
66804
3f9bb52082c4 avoid name clashes on interpretation of abstract locales
haftmann
parents: 66364
diff changeset
   440
  by (simp add: inter_filter) (rule swap)
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   441
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   442
lemma Plus:
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   443
  fixes A :: "'b set" and B :: "'c set"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   444
  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
   445
  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
   446
proof -
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   447
  have "A <+> B = Inl ` A \<union> Inr ` B" by auto
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   448
  moreover from fin have "finite (Inl ` A)" "finite (Inr ` B)" by auto
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   449
  moreover have "Inl ` A \<inter> Inr ` B = {}" by auto
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   450
  moreover have "inj_on Inl A" "inj_on Inr B" by (auto intro: inj_onI)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   451
  ultimately show ?thesis
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   452
    using fin by (simp add: union_disjoint reindex)
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   453
qed
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   454
58195
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   455
lemma same_carrier:
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   456
  assumes "finite C"
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   457
  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
   458
  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
   459
  shows "F g A = F h B \<longleftrightarrow> F g C = F h C"
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   460
proof -
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   461
  have "finite A" and "finite B" and "finite (C - A)" and "finite (C - B)"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   462
    using \<open>finite C\<close> subset by (auto elim: finite_subset)
58195
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   463
  from subset have [simp]: "A - (C - A) = A" by auto
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   464
  from subset have [simp]: "B - (C - B) = B" by auto
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   465
  from subset have "C = A \<union> (C - A)" by auto
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   466
  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
   467
  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
   468
    using \<open>finite A\<close> \<open>finite (C - A)\<close> by (simp only: union_diff2)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   469
  finally have *: "F g C = F g A" using trivial by simp
58195
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   470
  from subset have "C = B \<union> (C - B)" by auto
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   471
  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
   472
  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
   473
    using \<open>finite B\<close> \<open>finite (C - B)\<close> by (simp only: union_diff2)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   474
  finally have "F h C = F h B"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   475
    using trivial by simp
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   476
  with * show ?thesis by simp
58195
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   477
qed
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   478
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   479
lemma same_carrierI:
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   480
  assumes "finite C"
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   481
  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
   482
  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
   483
  assumes "F g C = F h C"
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   484
  shows "F g A = F h B"
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   485
  using assms same_carrier [of C A B] by simp
1fee63e0377d added various facts
haftmann
parents: 57512
diff changeset
   486
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   487
end
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   488
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   489
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   490
subsection \<open>Generalized summation over a set\<close>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   491
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   492
context comm_monoid_add
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   493
begin
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   494
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   495
sublocale sum: comm_monoid_set plus 0
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   496
  defines sum = sum.F ..
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   497
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   498
abbreviation Sum ("\<Sum>_" [1000] 999)
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   499
  where "\<Sum>A \<equiv> sum (\<lambda>x. x) A"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   500
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   501
end
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   502
67268
bdf25939a550 new/improved theories involving convergence; better pretty-printing for bounded quantifiers and sum/product
paulson <lp15@cam.ac.uk>
parents: 66936
diff changeset
   503
text \<open>Now: lots of fancy syntax. First, @{term "sum (\<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
   504
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
   505
syntax (ASCII)
67268
bdf25939a550 new/improved theories involving convergence; better pretty-printing for bounded quantifiers and sum/product
paulson <lp15@cam.ac.uk>
parents: 66936
diff changeset
   506
  "_sum" :: "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
   507
syntax
67268
bdf25939a550 new/improved theories involving convergence; better pretty-printing for bounded quantifiers and sum/product
paulson <lp15@cam.ac.uk>
parents: 66936
diff changeset
   508
  "_sum" :: "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
   509
translations \<comment> \<open>Beware of argument permutation!\<close>
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   510
  "\<Sum>i\<in>A. b" \<rightleftharpoons> "CONST sum (\<lambda>i. b) A"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   511
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
   512
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
   513
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
   514
syntax (ASCII)
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   515
  "_qsum" :: "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
   516
syntax
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   517
  "_qsum" :: "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
   518
translations
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   519
  "\<Sum>x|P. t" => "CONST sum (\<lambda>x. t) {x. P}"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   520
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   521
print_translation \<open>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   522
let
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   523
  fun sum_tr' [Abs (x, Tx, t), Const (@{const_syntax Collect}, _) $ Abs (y, Ty, P)] =
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   524
        if x <> y then raise Match
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   525
        else
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   526
          let
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   527
            val x' = Syntax_Trans.mark_bound_body (x, Tx);
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   528
            val t' = subst_bound (x', t);
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   529
            val P' = subst_bound (x', P);
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   530
          in
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   531
            Syntax.const @{syntax_const "_qsum"} $ Syntax_Trans.mark_bound_abs (x, Tx) $ P' $ t'
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   532
          end
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   533
    | sum_tr' _ = raise Match;
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   534
in [(@{const_syntax sum}, K sum_tr')] end
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   535
\<close>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   536
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   537
(* TODO generalization candidates *)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   538
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   539
lemma (in comm_monoid_add) sum_image_gen:
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   540
  assumes fin: "finite S"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   541
  shows "sum g S = sum (\<lambda>y. sum g {x. x \<in> S \<and> f x = y}) (f ` S)"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   542
proof -
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   543
  have "{y. y\<in> f`S \<and> f x = y} = {f x}" if "x \<in> S" for x
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   544
    using that by auto
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   545
  then have "sum g S = sum (\<lambda>x. sum (\<lambda>y. g x) {y. y\<in> f`S \<and> f x = y}) S"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   546
    by simp
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   547
  also have "\<dots> = sum (\<lambda>y. sum g {x. x \<in> S \<and> f x = y}) (f ` S)"
66804
3f9bb52082c4 avoid name clashes on interpretation of abstract locales
haftmann
parents: 66364
diff changeset
   548
    by (rule sum.swap_restrict [OF fin finite_imageI [OF fin]])
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   549
  finally show ?thesis .
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   550
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   551
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   552
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
   553
subsubsection \<open>Properties in more restricted classes of structures\<close>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   554
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   555
lemma sum_Un:
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   556
  "finite A \<Longrightarrow> finite B \<Longrightarrow> sum f (A \<union> B) = sum f A + sum f B - sum f (A \<inter> B)"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   557
  for f :: "'b \<Rightarrow> 'a::ab_group_add"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   558
  by (subst sum.union_inter [symmetric]) (auto simp add: algebra_simps)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   559
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   560
lemma sum_Un2:
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   561
  assumes "finite (A \<union> B)"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   562
  shows "sum f (A \<union> B) = sum f (A - B) + sum f (B - A) + sum f (A \<inter> B)"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   563
proof -
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   564
  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
   565
    by auto
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   566
  with assms show ?thesis
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   567
    by simp (subst sum.union_disjoint, auto)+
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   568
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   569
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   570
lemma sum_diff1:
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   571
  fixes f :: "'b \<Rightarrow> 'a::ab_group_add"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   572
  assumes "finite A"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   573
  shows "sum f (A - {a}) = (if a \<in> A then sum f A - f a else sum f A)"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   574
  using assms by induct (auto simp: insert_Diff_if)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   575
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   576
lemma sum_diff:
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   577
  fixes f :: "'b \<Rightarrow> 'a::ab_group_add"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   578
  assumes "finite A" "B \<subseteq> A"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   579
  shows "sum f (A - B) = sum f A - sum f B"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   580
proof -
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   581
  from assms(2,1) have "finite B" by (rule finite_subset)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   582
  from this \<open>B \<subseteq> A\<close>
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   583
  show ?thesis
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   584
  proof induct
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   585
    case empty
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   586
    thus ?case by simp
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   587
  next
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   588
    case (insert x F)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   589
    with \<open>finite A\<close> \<open>finite B\<close> show ?case
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   590
      by (simp add: Diff_insert[where a=x and B=F] sum_diff1 insert_absorb)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   591
  qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   592
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   593
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   594
lemma (in ordered_comm_monoid_add) sum_mono:
63915
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   595
  "(\<And>i. i\<in>K \<Longrightarrow> f i \<le> g i) \<Longrightarrow> (\<Sum>i\<in>K. f i) \<le> (\<Sum>i\<in>K. g i)"
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   596
  by (induct K rule: infinite_finite_induct) (use add_mono in auto)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   597
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   598
lemma (in strict_ordered_comm_monoid_add) sum_strict_mono:
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   599
  assumes "finite A" "A \<noteq> {}"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   600
    and "\<And>x. x \<in> A \<Longrightarrow> f x < g x"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   601
  shows "sum f A < sum g A"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   602
  using assms
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   603
proof (induct rule: finite_ne_induct)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   604
  case singleton
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   605
  then show ?case by simp
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   606
next
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   607
  case insert
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   608
  then show ?case by (auto simp: add_strict_mono)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   609
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   610
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   611
lemma sum_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
   612
  fixes f g :: "'i \<Rightarrow> 'a::ordered_cancel_comm_monoid_add"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   613
  assumes "finite A"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   614
    and "\<forall>x\<in>A. f x \<le> g x"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   615
    and "\<exists>a\<in>A. f a < g a"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   616
  shows "sum f A < sum g A"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   617
proof-
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   618
  from assms(3) obtain a where a: "a \<in> A" "f a < g a" by blast
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   619
  have "sum f A = sum f ((A - {a}) \<union> {a})"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   620
    by(simp add: insert_absorb[OF \<open>a \<in> A\<close>])
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   621
  also have "\<dots> = sum f (A - {a}) + sum f {a}"
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   622
    using \<open>finite A\<close> by(subst sum.union_disjoint) auto
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   623
  also have "sum f (A - {a}) \<le> sum g (A - {a})"
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   624
    by (rule sum_mono) (simp add: assms(2))
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   625
  also from a have "sum f {a} < sum g {a}" by simp
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   626
  also have "sum g (A - {a}) + sum g {a} = sum g((A - {a}) \<union> {a})"
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   627
    using \<open>finite A\<close> by (subst sum.union_disjoint[symmetric]) auto
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   628
  also have "\<dots> = sum g A" by (simp add: insert_absorb[OF \<open>a \<in> A\<close>])
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   629
  finally show ?thesis
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   630
    by (auto simp add: add_right_mono add_strict_left_mono)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   631
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   632
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   633
lemma sum_mono_inv:
63561
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63357
diff changeset
   634
  fixes f g :: "'i \<Rightarrow> 'a :: ordered_cancel_comm_monoid_add"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   635
  assumes eq: "sum f I = sum g I"
63561
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63357
diff changeset
   636
  assumes le: "\<And>i. i \<in> I \<Longrightarrow> f i \<le> g i"
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63357
diff changeset
   637
  assumes i: "i \<in> I"
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63357
diff changeset
   638
  assumes I: "finite I"
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63357
diff changeset
   639
  shows "f i = g i"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   640
proof (rule ccontr)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   641
  assume "\<not> ?thesis"
63561
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63357
diff changeset
   642
  with le[OF i] have "f i < g i" by simp
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   643
  with i have "\<exists>i\<in>I. f i < g i" ..
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   644
  from sum_strict_mono_ex1[OF I _ this] le have "sum f I < sum g I"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   645
    by blast
63561
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63357
diff changeset
   646
  with eq show False by simp
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63357
diff changeset
   647
qed
fba08009ff3e add lemmas contributed by Peter Gammie
Andreas Lochbihler
parents: 63357
diff changeset
   648
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   649
lemma member_le_sum:
63938
f6ce08859d4c More mainly topological results
paulson <lp15@cam.ac.uk>
parents: 63924
diff changeset
   650
  fixes f :: "_ \<Rightarrow> 'b::{semiring_1, ordered_comm_monoid_add}"
66112
0e640e04fc56 New theorems; stronger theorems; tidier theorems. Also some renaming
paulson <lp15@cam.ac.uk>
parents: 66089
diff changeset
   651
  assumes "i \<in> A"
0e640e04fc56 New theorems; stronger theorems; tidier theorems. Also some renaming
paulson <lp15@cam.ac.uk>
parents: 66089
diff changeset
   652
    and le: "\<And>x. x \<in> A - {i} \<Longrightarrow> 0 \<le> f x"
63938
f6ce08859d4c More mainly topological results
paulson <lp15@cam.ac.uk>
parents: 63924
diff changeset
   653
    and "finite A"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   654
  shows "f i \<le> sum f A"
63938
f6ce08859d4c More mainly topological results
paulson <lp15@cam.ac.uk>
parents: 63924
diff changeset
   655
proof -
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   656
  have "f i \<le> sum f (A \<inter> {i})"
63938
f6ce08859d4c More mainly topological results
paulson <lp15@cam.ac.uk>
parents: 63924
diff changeset
   657
    by (simp add: assms)
f6ce08859d4c More mainly topological results
paulson <lp15@cam.ac.uk>
parents: 63924
diff changeset
   658
  also have "... = (\<Sum>x\<in>A. if x \<in> {i} then f x else 0)"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   659
    using assms sum.inter_restrict by blast
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   660
  also have "... \<le> sum f A"
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   661
    apply (rule sum_mono)
63938
f6ce08859d4c More mainly topological results
paulson <lp15@cam.ac.uk>
parents: 63924
diff changeset
   662
    apply (auto simp: le)
f6ce08859d4c More mainly topological results
paulson <lp15@cam.ac.uk>
parents: 63924
diff changeset
   663
    done
f6ce08859d4c More mainly topological results
paulson <lp15@cam.ac.uk>
parents: 63924
diff changeset
   664
  finally show ?thesis .
f6ce08859d4c More mainly topological results
paulson <lp15@cam.ac.uk>
parents: 63924
diff changeset
   665
qed
f6ce08859d4c More mainly topological results
paulson <lp15@cam.ac.uk>
parents: 63924
diff changeset
   666
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   667
lemma sum_negf: "(\<Sum>x\<in>A. - f x) = - (\<Sum>x\<in>A. f x)"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   668
  for f :: "'b \<Rightarrow> 'a::ab_group_add"
63915
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   669
  by (induct A rule: infinite_finite_induct) auto
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   670
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   671
lemma sum_subtractf: "(\<Sum>x\<in>A. f x - g x) = (\<Sum>x\<in>A. f x) - (\<Sum>x\<in>A. g x)"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   672
  for f g :: "'b \<Rightarrow>'a::ab_group_add"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   673
  using sum.distrib [of f "- g" A] by (simp add: sum_negf)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   674
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   675
lemma sum_subtractf_nat:
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   676
  "(\<And>x. x \<in> A \<Longrightarrow> g x \<le> f x) \<Longrightarrow> (\<Sum>x\<in>A. f x - g x) = (\<Sum>x\<in>A. f x) - (\<Sum>x\<in>A. g x)"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   677
  for f g :: "'a \<Rightarrow> nat"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   678
  by (induct A rule: infinite_finite_induct) (auto simp: sum_mono)
59416
fde2659085e1 generalized sum_diff_distrib to setsum_subtractf_nat
hoelzl
parents: 59010
diff changeset
   679
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   680
context ordered_comm_monoid_add
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   681
begin
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   682
65680
378a2f11bec9 Simplification of some proofs. Also key lemmas using !! rather than ! in premises
paulson <lp15@cam.ac.uk>
parents: 64979
diff changeset
   683
lemma sum_nonneg: "(\<And>x. x \<in> A \<Longrightarrow> 0 \<le> f x) \<Longrightarrow> 0 \<le> sum f A"
63915
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   684
proof (induct A rule: infinite_finite_induct)
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   685
  case infinite
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   686
  then show ?case by simp
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   687
next
63915
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   688
  case empty
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   689
  then show ?case by simp
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   690
next
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   691
  case (insert x F)
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   692
  then have "0 + 0 \<le> f x + sum f F" by (blast intro: add_mono)
63915
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   693
  with insert show ?case by simp
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   694
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   695
65680
378a2f11bec9 Simplification of some proofs. Also key lemmas using !! rather than ! in premises
paulson <lp15@cam.ac.uk>
parents: 64979
diff changeset
   696
lemma sum_nonpos: "(\<And>x. x \<in> A \<Longrightarrow> f x \<le> 0) \<Longrightarrow> sum f A \<le> 0"
63915
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   697
proof (induct A rule: infinite_finite_induct)
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   698
  case infinite
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   699
  then show ?case by simp
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   700
next
63915
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   701
  case empty
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   702
  then show ?case by simp
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   703
next
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   704
  case (insert x F)
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   705
  then have "f x + sum f F \<le> 0 + 0" by (blast intro: add_mono)
63915
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   706
  with insert show ?case by simp
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   707
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   708
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   709
lemma sum_nonneg_eq_0_iff:
65680
378a2f11bec9 Simplification of some proofs. Also key lemmas using !! rather than ! in premises
paulson <lp15@cam.ac.uk>
parents: 64979
diff changeset
   710
  "finite A \<Longrightarrow> (\<And>x. x \<in> A \<Longrightarrow> 0 \<le> f x) \<Longrightarrow> sum f A = 0 \<longleftrightarrow> (\<forall>x\<in>A. f x = 0)"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   711
  by (induct set: finite) (simp_all add: add_nonneg_eq_0_iff sum_nonneg)
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
   712
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   713
lemma sum_nonneg_0:
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
   714
  "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"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   715
  by (simp add: sum_nonneg_eq_0_iff)
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
   716
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   717
lemma sum_nonneg_leq_bound:
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   718
  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
   719
  shows "f i \<le> B"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   720
proof -
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   721
  from assms have "f i \<le> f i + (\<Sum>i \<in> s - {i}. f i)"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   722
    by (intro add_increasing2 sum_nonneg) auto
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
   723
  also have "\<dots> = B"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   724
    using sum.remove[of s i f] assms 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
   725
  finally show ?thesis by auto
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   726
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   727
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   728
lemma sum_mono2:
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   729
  assumes fin: "finite B"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   730
    and sub: "A \<subseteq> B"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   731
    and nn: "\<And>b. b \<in> B-A \<Longrightarrow> 0 \<le> f b"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   732
  shows "sum f A \<le> sum f B"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   733
proof -
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   734
  have "sum f A \<le> sum f A + sum f (B-A)"
65680
378a2f11bec9 Simplification of some proofs. Also key lemmas using !! rather than ! in premises
paulson <lp15@cam.ac.uk>
parents: 64979
diff changeset
   735
    by (auto intro: add_increasing2 [OF sum_nonneg] nn)
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   736
  also from fin finite_subset[OF sub fin] have "\<dots> = sum f (A \<union> (B-A))"
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   737
    by (simp add: sum.union_disjoint del: Un_Diff_cancel)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   738
  also from sub have "A \<union> (B-A) = B" by blast
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   739
  finally show ?thesis .
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   740
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   741
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   742
lemma sum_le_included:
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   743
  assumes "finite s" "finite t"
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   744
  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)"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   745
  shows "sum f s \<le> sum g t"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   746
proof -
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   747
  have "sum f s \<le> sum (\<lambda>y. sum g {x. x\<in>t \<and> i x = y}) s"
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   748
  proof (rule sum_mono)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   749
    fix y
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   750
    assume "y \<in> s"
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   751
    with assms obtain z where z: "z \<in> t" "y = i z" "f y \<le> g z" by auto
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   752
    with assms show "f y \<le> sum g {x \<in> t. i x = y}" (is "?A y \<le> ?B y")
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   753
      using order_trans[of "?A (i z)" "sum g {z}" "?B (i z)", intro]
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   754
      by (auto intro!: sum_mono2)
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   755
  qed
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   756
  also have "\<dots> \<le> sum (\<lambda>y. sum g {x. x\<in>t \<and> i x = y}) (i ` t)"
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   757
    using assms(2-4) by (auto intro!: sum_mono2 sum_nonneg)
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   758
  also have "\<dots> \<le> sum g t"
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   759
    using assms by (auto simp: sum_image_gen[symmetric])
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   760
  finally show ?thesis .
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   761
qed
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
   762
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   763
end
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   764
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   765
lemma (in canonically_ordered_monoid_add) sum_eq_0_iff [simp]:
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   766
  "finite F \<Longrightarrow> (sum f F = 0) = (\<forall>a\<in>F. f a = 0)"
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   767
  by (intro ballI sum_nonneg_eq_0_iff zero_le)
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
   768
66936
cf8d8fc23891 tuned some proofs and added some lemmas
haftmann
parents: 66804
diff changeset
   769
context semiring_0
cf8d8fc23891 tuned some proofs and added some lemmas
haftmann
parents: 66804
diff changeset
   770
begin
cf8d8fc23891 tuned some proofs and added some lemmas
haftmann
parents: 66804
diff changeset
   771
cf8d8fc23891 tuned some proofs and added some lemmas
haftmann
parents: 66804
diff changeset
   772
lemma sum_distrib_left: "r * sum f A = (\<Sum>n\<in>A. r * f n)"
cf8d8fc23891 tuned some proofs and added some lemmas
haftmann
parents: 66804
diff changeset
   773
  by (induct A rule: infinite_finite_induct) (simp_all add: algebra_simps)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   774
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   775
lemma sum_distrib_right: "sum f A * r = (\<Sum>n\<in>A. f n * r)"
66936
cf8d8fc23891 tuned some proofs and added some lemmas
haftmann
parents: 66804
diff changeset
   776
  by (induct A rule: infinite_finite_induct) (simp_all add: algebra_simps)
cf8d8fc23891 tuned some proofs and added some lemmas
haftmann
parents: 66804
diff changeset
   777
cf8d8fc23891 tuned some proofs and added some lemmas
haftmann
parents: 66804
diff changeset
   778
end
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   779
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   780
lemma sum_divide_distrib: "sum f A / r = (\<Sum>n\<in>A. f n / r)"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   781
  for r :: "'a::field"
63915
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   782
proof (induct A rule: infinite_finite_induct)
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   783
  case infinite
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   784
  then show ?case by simp
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   785
next
63915
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   786
  case empty
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   787
  then show ?case by simp
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   788
next
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   789
  case insert
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   790
  then show ?case by (simp add: add_divide_distrib)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   791
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   792
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   793
lemma sum_abs[iff]: "\<bar>sum f A\<bar> \<le> sum (\<lambda>i. \<bar>f i\<bar>) A"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   794
  for f :: "'a \<Rightarrow> 'b::ordered_ab_group_add_abs"
63915
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   795
proof (induct A rule: infinite_finite_induct)
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   796
  case infinite
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   797
  then show ?case by simp
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   798
next
63915
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   799
  case empty
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   800
  then show ?case by simp
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   801
next
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   802
  case insert
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   803
  then show ?case by (auto intro: abs_triangle_ineq order_trans)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   804
qed
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   805
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   806
lemma sum_abs_ge_zero[iff]: "0 \<le> sum (\<lambda>i. \<bar>f i\<bar>) A"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   807
  for f :: "'a \<Rightarrow> 'b::ordered_ab_group_add_abs"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   808
  by (simp add: sum_nonneg)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   809
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   810
lemma abs_sum_abs[simp]: "\<bar>\<Sum>a\<in>A. \<bar>f a\<bar>\<bar> = (\<Sum>a\<in>A. \<bar>f a\<bar>)"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   811
  for f :: "'a \<Rightarrow> 'b::ordered_ab_group_add_abs"
63915
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   812
proof (induct A rule: infinite_finite_induct)
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   813
  case infinite
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   814
  then show ?case by simp
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   815
next
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   816
  case empty
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   817
  then show ?case by simp
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   818
next
63915
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   819
  case (insert a A)
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   820
  then have "\<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
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   821
  also from insert have "\<dots> = \<bar>\<bar>f a\<bar> + \<bar>\<Sum>a\<in>A. \<bar>f a\<bar>\<bar>\<bar>" by simp
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   822
  also have "\<dots> = \<bar>f a\<bar> + \<bar>\<Sum>a\<in>A. \<bar>f a\<bar>\<bar>" by (simp del: abs_of_nonneg)
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   823
  also from insert have "\<dots> = (\<Sum>a\<in>insert a A. \<bar>f a\<bar>)" by simp
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   824
  finally show ?case .
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   825
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   826
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   827
lemma sum_diff1_ring:
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   828
  fixes f :: "'b \<Rightarrow> 'a::ring"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   829
  assumes "finite A" "a \<in> A"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   830
  shows "sum f (A - {a}) = sum f A - (f a)"
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   831
  unfolding sum.remove [OF assms] by auto
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   832
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   833
lemma sum_product:
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   834
  fixes f :: "'a \<Rightarrow> 'b::semiring_0"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   835
  shows "sum f A * sum g B = (\<Sum>i\<in>A. \<Sum>j\<in>B. f i * g j)"
66804
3f9bb52082c4 avoid name clashes on interpretation of abstract locales
haftmann
parents: 66364
diff changeset
   836
  by (simp add: sum_distrib_left sum_distrib_right) (rule sum.swap)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   837
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   838
lemma sum_mult_sum_if_inj:
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   839
  fixes f :: "'a \<Rightarrow> 'b::semiring_0"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   840
  shows "inj_on (\<lambda>(a, b). f a * g b) (A \<times> B) \<Longrightarrow>
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   841
    sum f A * sum g B = sum id {f a * g b |a b. a \<in> A \<and> b \<in> B}"
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   842
  by(auto simp: sum_product sum.cartesian_product intro!: sum.reindex_cong[symmetric])
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   843
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   844
lemma sum_SucD: "sum f A = Suc n \<Longrightarrow> \<exists>a\<in>A. 0 < f a"
63915
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   845
  by (induct A rule: infinite_finite_induct) auto
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   846
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   847
lemma sum_eq_Suc0_iff:
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   848
  "finite A \<Longrightarrow> sum f A = Suc 0 \<longleftrightarrow> (\<exists>a\<in>A. f a = Suc 0 \<and> (\<forall>b\<in>A. a \<noteq> b \<longrightarrow> f b = 0))"
63915
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   849
  by (induct A rule: finite_induct) (auto simp add: add_is_1)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   850
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   851
lemmas sum_eq_1_iff = sum_eq_Suc0_iff[simplified One_nat_def[symmetric]]
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   852
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   853
lemma sum_Un_nat:
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   854
  "finite A \<Longrightarrow> finite B \<Longrightarrow> sum f (A \<union> B) = sum f A + sum f B - sum f (A \<inter> B)"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   855
  for f :: "'a \<Rightarrow> nat"
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61776
diff changeset
   856
  \<comment> \<open>For the natural numbers, we have subtraction.\<close>
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   857
  by (subst sum.union_inter [symmetric]) (auto simp: algebra_simps)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   858
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   859
lemma sum_diff1_nat: "sum f (A - {a}) = (if a \<in> A then sum f A - f a else sum f A)"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   860
  for f :: "'a \<Rightarrow> nat"
63915
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   861
proof (induct A rule: infinite_finite_induct)
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   862
  case infinite
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   863
  then show ?case by simp
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   864
next
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   865
  case empty
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   866
  then show ?case by simp
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   867
next
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   868
  case insert
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   869
  then show ?case
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   870
    apply (auto simp: insert_Diff_if)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   871
    apply (drule mk_disjoint_insert)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   872
    apply auto
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   873
    done
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   874
qed
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   875
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   876
lemma sum_diff_nat:
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   877
  fixes f :: "'a \<Rightarrow> nat"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   878
  assumes "finite B" and "B \<subseteq> A"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   879
  shows "sum f (A - B) = sum f A - sum f B"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   880
  using assms
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   881
proof induct
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   882
  case empty
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   883
  then show ?case by simp
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   884
next
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   885
  case (insert x F)
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   886
  note IH = \<open>F \<subseteq> A \<Longrightarrow> sum f (A - F) = sum f A - sum f F\<close>
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   887
  from \<open>x \<notin> F\<close> \<open>insert x F \<subseteq> A\<close> have "x \<in> A - F" by simp
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   888
  then have A: "sum f ((A - F) - {x}) = sum f (A - F) - f x"
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   889
    by (simp add: sum_diff1_nat)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   890
  from \<open>insert x F \<subseteq> A\<close> have "F \<subseteq> A" by simp
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   891
  with IH have "sum f (A - F) = sum f A - sum f F" by simp
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   892
  with A have B: "sum f ((A - F) - {x}) = sum f A - sum f F - f x"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   893
    by simp
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   894
  from \<open>x \<notin> F\<close> have "A - insert x F = (A - F) - {x}" by auto
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   895
  with B have C: "sum f (A - insert x F) = sum f A - sum f F - f x"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   896
    by simp
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   897
  from \<open>finite F\<close> \<open>x \<notin> F\<close> have "sum f (insert x F) = sum f F + f x"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   898
    by simp
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   899
  with C have "sum f (A - insert x F) = sum f A - sum f (insert x F)"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   900
    by simp
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   901
  then show ?case by simp
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   902
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   903
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   904
lemma sum_comp_morphism:
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   905
  "h 0 = 0 \<Longrightarrow> (\<And>x y. h (x + y) = h x + h y) \<Longrightarrow> sum (h \<circ> g) A = h (sum g A)"
63915
bab633745c7f tuned proofs;
wenzelm
parents: 63654
diff changeset
   906
  by (induct A rule: infinite_finite_induct) simp_all
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   907
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   908
lemma (in comm_semiring_1) dvd_sum: "(\<And>a. a \<in> A \<Longrightarrow> d dvd f a) \<Longrightarrow> d dvd sum f A"
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
   909
  by (induct A rule: infinite_finite_induct) simp_all
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
   910
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   911
lemma (in ordered_comm_monoid_add) sum_pos:
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   912
  "finite I \<Longrightarrow> I \<noteq> {} \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> 0 < f i) \<Longrightarrow> 0 < sum f I"
62377
ace69956d018 moved more proofs to ordered_comm_monoid_add; introduced strict_ordered_ab_semigroup/comm_monoid_add
hoelzl
parents: 62376
diff changeset
   913
  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
   914
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   915
lemma (in ordered_comm_monoid_add) sum_pos2:
62377
ace69956d018 moved more proofs to ordered_comm_monoid_add; introduced strict_ordered_ab_semigroup/comm_monoid_add
hoelzl
parents: 62376
diff changeset
   916
  assumes I: "finite I" "i \<in> I" "0 < f i" "\<And>i. i \<in> I \<Longrightarrow> 0 \<le> f i"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   917
  shows "0 < sum f I"
60974
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   918
proof -
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   919
  have "0 < f i + sum f (I - {i})"
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   920
    using assms by (intro add_pos_nonneg sum_nonneg) auto
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   921
  also have "\<dots> = sum f I"
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   922
    using assms by (simp add: sum.remove)
60974
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   923
  finally show ?thesis .
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   924
qed
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   925
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   926
lemma sum_cong_Suc:
61524
f2e51e704a96 added many small lemmas about setsum/setprod/powr/...
eberlm
parents: 61378
diff changeset
   927
  assumes "0 \<notin> A" "\<And>x. Suc x \<in> A \<Longrightarrow> f (Suc x) = g (Suc x)"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   928
  shows "sum f A = sum g A"
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   929
proof (rule sum.cong)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   930
  fix x
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   931
  assume "x \<in> A"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   932
  with assms(1) show "f x = g x"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   933
    by (cases x) (auto intro!: assms(2))
61524
f2e51e704a96 added many small lemmas about setsum/setprod/powr/...
eberlm
parents: 61378
diff changeset
   934
qed simp_all
f2e51e704a96 added many small lemmas about setsum/setprod/powr/...
eberlm
parents: 61378
diff changeset
   935
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   936
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   937
subsubsection \<open>Cardinality as special case of @{const sum}\<close>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   938
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   939
lemma card_eq_sum: "card A = sum (\<lambda>x. 1) A"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   940
proof -
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   941
  have "plus \<circ> (\<lambda>_. Suc 0) = (\<lambda>_. Suc)"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   942
    by (simp add: fun_eq_iff)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   943
  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
   944
    by (rule arg_cong)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   945
  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
   946
    by (blast intro: fun_cong)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   947
  then show ?thesis
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   948
    by (simp add: card.eq_fold sum.eq_fold)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   949
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   950
66936
cf8d8fc23891 tuned some proofs and added some lemmas
haftmann
parents: 66804
diff changeset
   951
context semiring_1
cf8d8fc23891 tuned some proofs and added some lemmas
haftmann
parents: 66804
diff changeset
   952
begin
cf8d8fc23891 tuned some proofs and added some lemmas
haftmann
parents: 66804
diff changeset
   953
cf8d8fc23891 tuned some proofs and added some lemmas
haftmann
parents: 66804
diff changeset
   954
lemma sum_constant [simp]:
cf8d8fc23891 tuned some proofs and added some lemmas
haftmann
parents: 66804
diff changeset
   955
  "(\<Sum>x \<in> A. y) = of_nat (card A) * y"
cf8d8fc23891 tuned some proofs and added some lemmas
haftmann
parents: 66804
diff changeset
   956
  by (induct A rule: infinite_finite_induct) (simp_all add: algebra_simps)
cf8d8fc23891 tuned some proofs and added some lemmas
haftmann
parents: 66804
diff changeset
   957
cf8d8fc23891 tuned some proofs and added some lemmas
haftmann
parents: 66804
diff changeset
   958
end
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   959
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   960
lemma sum_Suc: "sum (\<lambda>x. Suc(f x)) A = sum f A + card A"
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   961
  using sum.distrib[of f "\<lambda>_. 1" A] by simp
58349
107341a15946 added lemma
nipkow
parents: 58195
diff changeset
   962
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   963
lemma sum_bounded_above:
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   964
  fixes K :: "'a::{semiring_1,ordered_comm_monoid_add}"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   965
  assumes le: "\<And>i. i\<in>A \<Longrightarrow> f i \<le> K"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   966
  shows "sum f A \<le> of_nat (card A) * K"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   967
proof (cases "finite A")
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   968
  case True
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   969
  then show ?thesis
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   970
    using le sum_mono[where K=A and g = "\<lambda>x. K"] by simp
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   971
next
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   972
  case False
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   973
  then show ?thesis by simp
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   974
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
   975
69144
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
   976
lemma sum_bounded_above_divide:
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
   977
  fixes K :: "'a::linordered_field"
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
   978
  assumes le: "\<And>i. i\<in>A \<Longrightarrow> f i \<le> K / of_nat (card A)" and fin: "finite A" "A \<noteq> {}"
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
   979
  shows "sum f A \<le> K"
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
   980
  using sum_bounded_above [of A f "K / of_nat (card A)", OF le] fin by simp
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
   981
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   982
lemma sum_bounded_above_strict:
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   983
  fixes K :: "'a::{ordered_cancel_comm_monoid_add,semiring_1}"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   984
  assumes "\<And>i. i\<in>A \<Longrightarrow> f i < K" "card A > 0"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   985
  shows "sum f A < of_nat (card A) * K"
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   986
  using assms sum_strict_mono[where A=A and g = "\<lambda>x. K"]
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   987
  by (simp add: card_gt_0_iff)
60974
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   988
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   989
lemma sum_bounded_below:
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   990
  fixes K :: "'a::{semiring_1,ordered_comm_monoid_add}"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   991
  assumes le: "\<And>i. i\<in>A \<Longrightarrow> K \<le> f i"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   992
  shows "of_nat (card A) * K \<le> sum f A"
60974
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   993
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
   994
  case True
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   995
  then show ?thesis
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
   996
    using le sum_mono[where K=A and f = "\<lambda>x. K"] by simp
60974
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
   997
next
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   998
  case False
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
   999
  then show ?thesis by simp
60974
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
  1000
qed
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
  1001
69144
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
  1002
lemma convex_sum_bound_le:
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
  1003
  fixes x :: "'a \<Rightarrow> 'b::linordered_idom"
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
  1004
  assumes 0: "\<And>i. i \<in> I \<Longrightarrow> 0 \<le> x i" and 1: "sum x I = 1"
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
  1005
      and \<delta>: "\<And>i. i \<in> I \<Longrightarrow> \<bar>a i - b\<bar> \<le> \<delta>"
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
  1006
    shows "\<bar>(\<Sum>i\<in>I. a i * x i) - b\<bar> \<le> \<delta>"
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
  1007
proof -
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
  1008
  have [simp]: "(\<Sum>i\<in>I. c * x i) = c" for c
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
  1009
    by (simp flip: sum_distrib_left 1)
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
  1010
  then have "\<bar>(\<Sum>i\<in>I. a i * x i) - b\<bar> = \<bar>\<Sum>i\<in>I. (a i - b) * x i\<bar>"
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
  1011
    by (simp add: sum_subtractf left_diff_distrib)
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
  1012
  also have "\<dots> \<le> (\<Sum>i\<in>I. \<bar>(a i - b) * x i\<bar>)"
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
  1013
    using abs_abs abs_of_nonneg by blast
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
  1014
  also have "\<dots> \<le> (\<Sum>i\<in>I. \<bar>(a i - b)\<bar> * x i)"
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
  1015
    by (simp add: abs_mult 0)
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
  1016
  also have "\<dots> \<le> (\<Sum>i\<in>I. \<delta> * x i)"
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
  1017
    by (rule sum_mono) (use \<delta> "0" mult_right_mono in blast)
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
  1018
  also have "\<dots> = \<delta>"
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
  1019
    by simp
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
  1020
  finally show ?thesis .
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
  1021
qed
f13b82281715 new theory Abstract_Topology with lots of stuff from HOL Light's metric.sml
paulson <lp15@cam.ac.uk>
parents: 69127
diff changeset
  1022
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1023
lemma card_UN_disjoint:
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1024
  assumes "finite I" and "\<forall>i\<in>I. finite (A i)"
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1025
    and "\<forall>i\<in>I. \<forall>j\<in>I. i \<noteq> j \<longrightarrow> A i \<inter> A j = {}"
69275
9bbd5497befd clarified status of legacy input abbreviations
haftmann
parents: 69164
diff changeset
  1026
  shows "card (\<Union>(A ` I)) = (\<Sum>i\<in>I. card(A i))"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1027
proof -
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1028
  have "(\<Sum>i\<in>I. card (A i)) = (\<Sum>i\<in>I. \<Sum>x\<in>A i. 1)"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1029
    by simp
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1030
  with assms show ?thesis
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
  1031
    by (simp add: card_eq_sum sum.UNION_disjoint del: sum_constant)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1032
qed
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1033
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1034
lemma card_Union_disjoint:
68975
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1035
  assumes "pairwise disjnt C" and fin: "\<And>A. A \<in> C \<Longrightarrow> finite A"
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1036
  shows "card (\<Union>C) = sum card C"
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1037
proof (cases "finite C")
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1038
  case True
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1039
  then show ?thesis
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1040
    using card_UN_disjoint [OF True, of "\<lambda>x. x"] assms
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1041
    by (simp add: disjnt_def fin pairwise_def)
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1042
next
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1043
  case False
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1044
  then show ?thesis
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1045
    using assms card_eq_0_iff finite_UnionD by fastforce
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1046
qed
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1047
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
  1048
lemma sum_multicount_gen:
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
  1049
  assumes "finite s" "finite t" "\<forall>j\<in>t. (card {i\<in>s. R i j} = k j)"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
  1050
  shows "sum (\<lambda>i. (card {j\<in>t. R i j})) s = sum k t"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1051
    (is "?l = ?r")
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
  1052
proof-
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
  1053
  have "?l = sum (\<lambda>i. sum (\<lambda>x.1) {j\<in>t. R i j}) s"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1054
    by auto
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1055
  also have "\<dots> = ?r"
66804
3f9bb52082c4 avoid name clashes on interpretation of abstract locales
haftmann
parents: 66364
diff changeset
  1056
    unfolding sum.swap_restrict [OF assms(1-2)]
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
  1057
    using assms(3) by auto
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
  1058
  finally show ?thesis .
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
  1059
qed
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
  1060
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
  1061
lemma sum_multicount:
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
  1062
  assumes "finite S" "finite T" "\<forall>j\<in>T. (card {i\<in>S. R i j} = k)"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
  1063
  shows "sum (\<lambda>i. card {j\<in>T. R i j}) S = k * card T" (is "?l = ?r")
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
  1064
proof-
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
  1065
  have "?l = sum (\<lambda>i. k) T"
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
  1066
    by (rule sum_multicount_gen) (auto simp: assms)
57512
cc97b347b301 reduced name variants for assoc and commute on plus and mult
haftmann
parents: 57418
diff changeset
  1067
  also have "\<dots> = ?r" by (simp add: mult.commute)
57418
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
  1068
  finally show ?thesis by auto
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
  1069
qed
6ab1c7cb0b8d fact consolidation
haftmann
parents: 57275
diff changeset
  1070
67511
a6f5a78712af include lemmas generally useful for combinatorial proofs
bulwahn
parents: 67268
diff changeset
  1071
lemma sum_card_image:
a6f5a78712af include lemmas generally useful for combinatorial proofs
bulwahn
parents: 67268
diff changeset
  1072
  assumes "finite A"
68975
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1073
  assumes "pairwise (\<lambda>s t. disjnt (f s) (f t)) A"
67511
a6f5a78712af include lemmas generally useful for combinatorial proofs
bulwahn
parents: 67268
diff changeset
  1074
  shows "sum card (f ` A) = sum (\<lambda>a. card (f a)) A"
a6f5a78712af include lemmas generally useful for combinatorial proofs
bulwahn
parents: 67268
diff changeset
  1075
using assms
a6f5a78712af include lemmas generally useful for combinatorial proofs
bulwahn
parents: 67268
diff changeset
  1076
proof (induct A)
a6f5a78712af include lemmas generally useful for combinatorial proofs
bulwahn
parents: 67268
diff changeset
  1077
  case (insert a A)
a6f5a78712af include lemmas generally useful for combinatorial proofs
bulwahn
parents: 67268
diff changeset
  1078
  show ?case
a6f5a78712af include lemmas generally useful for combinatorial proofs
bulwahn
parents: 67268
diff changeset
  1079
  proof cases
a6f5a78712af include lemmas generally useful for combinatorial proofs
bulwahn
parents: 67268
diff changeset
  1080
    assume "f a = {}"
68975
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1081
    with insert show ?case
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1082
      by (subst sum.mono_neutral_right[where S="f ` A"]) (auto simp: pairwise_insert)
67511
a6f5a78712af include lemmas generally useful for combinatorial proofs
bulwahn
parents: 67268
diff changeset
  1083
  next
a6f5a78712af include lemmas generally useful for combinatorial proofs
bulwahn
parents: 67268
diff changeset
  1084
    assume "f a \<noteq> {}"
68975
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1085
    then have "sum card (insert (f a) (f ` A)) = card (f a) + sum card (f ` A)"
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1086
      using insert
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1087
      by (subst sum.insert) (auto simp: pairwise_insert)
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1088
    with insert show ?case by (simp add: pairwise_insert)
67511
a6f5a78712af include lemmas generally useful for combinatorial proofs
bulwahn
parents: 67268
diff changeset
  1089
  qed
68975
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1090
qed simp
67511
a6f5a78712af include lemmas generally useful for combinatorial proofs
bulwahn
parents: 67268
diff changeset
  1091
a6f5a78712af include lemmas generally useful for combinatorial proofs
bulwahn
parents: 67268
diff changeset
  1092
lemma card_Union_image:
a6f5a78712af include lemmas generally useful for combinatorial proofs
bulwahn
parents: 67268
diff changeset
  1093
  assumes "finite S"
68975
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1094
  assumes "\<And>s. s \<in> S \<Longrightarrow> finite (f s)"
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1095
  assumes "pairwise (\<lambda>s t. disjnt (f s) (f t)) S"
67511
a6f5a78712af include lemmas generally useful for combinatorial proofs
bulwahn
parents: 67268
diff changeset
  1096
  shows "card (\<Union>(f ` S)) = sum (\<lambda>x. card (f x)) S"
a6f5a78712af include lemmas generally useful for combinatorial proofs
bulwahn
parents: 67268
diff changeset
  1097
proof -
68975
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1098
  have "pairwise disjnt (f ` S)"
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1099
    using assms(3)
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1100
    by (metis pairwiseD pairwise_imageI) 
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1101
  then have "card (\<Union>(f ` S)) = sum card (f ` S)"
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1102
    by (subst card_Union_disjoint) (use assms in auto)
67511
a6f5a78712af include lemmas generally useful for combinatorial proofs
bulwahn
parents: 67268
diff changeset
  1103
  also have "... = sum (\<lambda>x. card (f x)) S"
68975
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1104
    by (metis (mono_tags, lifting) assms(1) assms(3) sum_card_image)
67511
a6f5a78712af include lemmas generally useful for combinatorial proofs
bulwahn
parents: 67268
diff changeset
  1105
  finally show ?thesis .
a6f5a78712af include lemmas generally useful for combinatorial proofs
bulwahn
parents: 67268
diff changeset
  1106
qed
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1107
68975
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1108
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
  1109
subsubsection \<open>Cardinality of products\<close>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1110
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1111
lemma card_SigmaI [simp]:
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1112
  "finite A \<Longrightarrow> \<forall>a\<in>A. finite (B a) \<Longrightarrow> card (SIGMA x: A. B x) = (\<Sum>a\<in>A. card (B a))"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
  1113
  by (simp add: card_eq_sum sum.Sigma del: sum_constant)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1114
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1115
(*
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1116
lemma SigmaI_insert: "y \<notin> A ==>
61943
7fba644ed827 discontinued ASCII replacement syntax <*>;
wenzelm
parents: 61799
diff changeset
  1117
  (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
  1118
  by auto
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1119
*)
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1120
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1121
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
  1122
  by (cases "finite A \<and> finite B")
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1123
    (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
  1124
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1125
lemma card_cartesian_product_singleton:  "card ({x} \<times> A) = card A"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1126
  by (simp add: card_cartesian_product)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1127
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1128
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
  1129
subsection \<open>Generalized product over a set\<close>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1130
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1131
context comm_monoid_mult
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1132
begin
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1133
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1134
sublocale prod: comm_monoid_set times 1
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1135
  defines prod = prod.F ..
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1136
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1137
abbreviation Prod ("\<Prod>_" [1000] 999)
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1138
  where "\<Prod>A \<equiv> prod (\<lambda>x. x) A"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1139
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1140
end
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1141
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
  1142
syntax (ASCII)
67268
bdf25939a550 new/improved theories involving convergence; better pretty-printing for bounded quantifiers and sum/product
paulson <lp15@cam.ac.uk>
parents: 66936
diff changeset
  1143
  "_prod" :: "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
  1144
syntax
67268
bdf25939a550 new/improved theories involving convergence; better pretty-printing for bounded quantifiers and sum/product
paulson <lp15@cam.ac.uk>
parents: 66936
diff changeset
  1145
  "_prod" :: "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
  1146
translations \<comment> \<open>Beware of argument permutation!\<close>
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1147
  "\<Prod>i\<in>A. b" == "CONST prod (\<lambda>i. b) A"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1148
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
  1149
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
  1150
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61952
diff changeset
  1151
syntax (ASCII)
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1152
  "_qprod" :: "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
  1153
syntax
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1154
  "_qprod" :: "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
  1155
translations
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1156
  "\<Prod>x|P. t" => "CONST prod (\<lambda>x. t) {x. P}"
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1157
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1158
context comm_monoid_mult
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1159
begin
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1160
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1161
lemma prod_dvd_prod: "(\<And>a. a \<in> A \<Longrightarrow> f a dvd g a) \<Longrightarrow> prod f A dvd prod g A"
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1162
proof (induct A rule: infinite_finite_induct)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1163
  case infinite
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1164
  then show ?case by (auto intro: dvdI)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1165
next
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1166
  case empty
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1167
  then show ?case by (auto intro: dvdI)
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1168
next
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1169
  case (insert a A)
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1170
  then have "f a dvd g a" and "prod f A dvd prod g A"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1171
    by simp_all
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1172
  then obtain r s where "g a = f a * r" and "prod g A = prod f A * s"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1173
    by (auto elim!: dvdE)
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1174
  then have "g a * prod g A = f a * prod f A * (r * s)"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1175
    by (simp add: ac_simps)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1176
  with insert.hyps show ?case
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1177
    by (auto intro: dvdI)
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1178
qed
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1179
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1180
lemma prod_dvd_prod_subset: "finite B \<Longrightarrow> A \<subseteq> B \<Longrightarrow> prod f A dvd prod f B"
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1181
  by (auto simp add: prod.subset_diff ac_simps intro: dvdI)
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1182
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1183
end
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1184
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1185
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60494
diff changeset
  1186
subsubsection \<open>Properties in more restricted classes of structures\<close>
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1187
65687
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1188
context linordered_nonzero_semiring
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1189
begin
68975
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1190
65687
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1191
lemma prod_ge_1: "(\<And>x. x \<in> A \<Longrightarrow> 1 \<le> f x) \<Longrightarrow> 1 \<le> prod f A"
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1192
proof (induct A rule: infinite_finite_induct)
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1193
  case infinite
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1194
  then show ?case by simp
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1195
next
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1196
  case empty
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1197
  then show ?case by simp
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1198
next
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1199
  case (insert x F)
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1200
  have "1 * 1 \<le> f x * prod f F"
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1201
    by (rule mult_mono') (use insert in auto)
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1202
  with insert show ?case by simp
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1203
qed
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1204
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1205
lemma prod_le_1:
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1206
  fixes f :: "'b \<Rightarrow> 'a"
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1207
  assumes "\<And>x. x \<in> A \<Longrightarrow> 0 \<le> f x \<and> f x \<le> 1"
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1208
  shows "prod f A \<le> 1"
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1209
    using assms
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1210
proof (induct A rule: infinite_finite_induct)
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1211
  case infinite
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1212
  then show ?case by simp
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1213
next
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1214
  case empty
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1215
  then show ?case by simp
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1216
next
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1217
  case (insert x F)
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1218
  then show ?case by (force simp: mult.commute intro: dest: mult_le_one)
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1219
qed
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1220
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1221
end
a68973661472 two new theorems
paulson <lp15@cam.ac.uk>
parents: 65680
diff changeset
  1222
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1223
context comm_semiring_1
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1224
begin
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1225
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1226
lemma dvd_prod_eqI [intro]:
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1227
  assumes "finite A" and "a \<in> A" and "b = f a"
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1228
  shows "b dvd prod f A"
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1229
proof -
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1230
  from \<open>finite A\<close> have "prod f (insert a (A - {a})) = f a * prod f (A - {a})"
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1231
    by (intro prod.insert) auto
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1232
  also from \<open>a \<in> A\<close> have "insert a (A - {a}) = A"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1233
    by blast
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1234
  finally have "prod f A = f a * prod f (A - {a})" .
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1235
  with \<open>b = f a\<close> show ?thesis
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1236
    by simp
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1237
qed
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1238
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1239
lemma dvd_prodI [intro]: "finite A \<Longrightarrow> a \<in> A \<Longrightarrow> f a dvd prod f A"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1240
  by auto
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1241
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1242
lemma prod_zero:
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1243
  assumes "finite A" and "\<exists>a\<in>A. f a = 0"
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1244
  shows "prod f A = 0"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1245
  using assms
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1246
proof (induct A)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1247
  case empty
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1248
  then show ?case by simp
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1249
next
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1250
  case (insert a A)
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1251
  then have "f a = 0 \<or> (\<exists>a\<in>A. f a = 0)" by simp
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1252
  then have "f a * prod f A = 0" by rule (simp_all add: insert)
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1253
  with insert show ?case by simp
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1254
qed
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1255
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1256
lemma prod_dvd_prod_subset2:
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1257
  assumes "finite B" and "A \<subseteq> B" and "\<And>a. a \<in> A \<Longrightarrow> f a dvd g a"
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1258
  shows "prod f A dvd prod g B"
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1259
proof -
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1260
  from assms have "prod f A dvd prod g A"
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1261
    by (auto intro: prod_dvd_prod)
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1262
  moreover from assms have "prod g A dvd prod g B"
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1263
    by (auto intro: prod_dvd_prod_subset)
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1264
  ultimately show ?thesis by (rule dvd_trans)
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1265
qed
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1266
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1267
end
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1268
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1269
lemma (in semidom) prod_zero_iff [simp]:
63924
f91766530e13 more generic algebraic lemmas
haftmann
parents: 63918
diff changeset
  1270
  fixes f :: "'b \<Rightarrow> 'a"
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1271
  assumes "finite A"
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1272
  shows "prod f A = 0 \<longleftrightarrow> (\<exists>a\<in>A. f a = 0)"
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1273
  using assms by (induct A) (auto simp: no_zero_divisors)
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1274
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1275
lemma (in semidom_divide) prod_diff1:
60353
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1276
  assumes "finite A" and "f a \<noteq> 0"
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1277
  shows "prod f (A - {a}) = (if a \<in> A then prod f A div f a else prod f A)"
60353
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1278
proof (cases "a \<notin> A")
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1279
  case True
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1280
  then show ?thesis by simp
60353
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1281
next
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1282
  case False
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1283
  with assms show ?thesis
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1284
  proof induct
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1285
    case empty
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1286
    then show ?case by simp
60353
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1287
  next
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1288
    case (insert b B)
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1289
    then show ?case
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1290
    proof (cases "a = b")
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1291
      case True
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1292
      with insert show ?thesis by simp
60353
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1293
    next
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1294
      case False
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1295
      with insert have "a \<in> B" by simp
63040
eb4ddd18d635 eliminated old 'def';
wenzelm
parents: 62481
diff changeset
  1296
      define C where "C = B - {a}"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1297
      with \<open>finite B\<close> \<open>a \<in> B\<close> have "B = insert a C" "finite C" "a \<notin> C"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1298
        by auto
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1299
      with insert show ?thesis
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1300
        by (auto simp add: insert_commute ac_simps)
60353
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1301
    qed
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1302
  qed
838025c6e278 implicit partial divison operation in integral domains
haftmann
parents: 59867
diff changeset
  1303
qed
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1304
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
  1305
lemma sum_zero_power [simp]: "(\<Sum>i\<in>A. c i * 0^i) = (if finite A \<and> 0 \<in> A then c 0 else 0)"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1306
  for c :: "nat \<Rightarrow> 'a::division_ring"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1307
  by (induct A rule: infinite_finite_induct) auto
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1308
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
  1309
lemma sum_zero_power' [simp]:
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1310
  "(\<Sum>i\<in>A. c i * 0^i / d i) = (if finite A \<and> 0 \<in> A then c 0 / d 0 else 0)"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1311
  for c :: "nat \<Rightarrow> 'a::field"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
  1312
  using sum_zero_power [of "\<lambda>i. c i / d i" A] by auto
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1313
65680
378a2f11bec9 Simplification of some proofs. Also key lemmas using !! rather than ! in premises
paulson <lp15@cam.ac.uk>
parents: 64979
diff changeset
  1314
lemma (in field) prod_inversef: "prod (inverse \<circ> f) A = inverse (prod f A)"
378a2f11bec9 Simplification of some proofs. Also key lemmas using !! rather than ! in premises
paulson <lp15@cam.ac.uk>
parents: 64979
diff changeset
  1315
 proof (cases "finite A")
378a2f11bec9 Simplification of some proofs. Also key lemmas using !! rather than ! in premises
paulson <lp15@cam.ac.uk>
parents: 64979
diff changeset
  1316
   case True
378a2f11bec9 Simplification of some proofs. Also key lemmas using !! rather than ! in premises
paulson <lp15@cam.ac.uk>
parents: 64979
diff changeset
  1317
   then show ?thesis
378a2f11bec9 Simplification of some proofs. Also key lemmas using !! rather than ! in premises
paulson <lp15@cam.ac.uk>
parents: 64979
diff changeset
  1318
     by (induct A rule: finite_induct) simp_all
378a2f11bec9 Simplification of some proofs. Also key lemmas using !! rather than ! in premises
paulson <lp15@cam.ac.uk>
parents: 64979
diff changeset
  1319
 next
378a2f11bec9 Simplification of some proofs. Also key lemmas using !! rather than ! in premises
paulson <lp15@cam.ac.uk>
parents: 64979
diff changeset
  1320
   case False
378a2f11bec9 Simplification of some proofs. Also key lemmas using !! rather than ! in premises
paulson <lp15@cam.ac.uk>
parents: 64979
diff changeset
  1321
   then show ?thesis
378a2f11bec9 Simplification of some proofs. Also key lemmas using !! rather than ! in premises
paulson <lp15@cam.ac.uk>
parents: 64979
diff changeset
  1322
     by auto
378a2f11bec9 Simplification of some proofs. Also key lemmas using !! rather than ! in premises
paulson <lp15@cam.ac.uk>
parents: 64979
diff changeset
  1323
 qed
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1324
65680
378a2f11bec9 Simplification of some proofs. Also key lemmas using !! rather than ! in premises
paulson <lp15@cam.ac.uk>
parents: 64979
diff changeset
  1325
lemma (in field) prod_dividef: "(\<Prod>x\<in>A. f x / g x) = prod f A / prod g A"
378a2f11bec9 Simplification of some proofs. Also key lemmas using !! rather than ! in premises
paulson <lp15@cam.ac.uk>
parents: 64979
diff changeset
  1326
  using prod_inversef [of g A] by (simp add: divide_inverse prod.distrib)
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1327
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1328
lemma prod_Un:
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1329
  fixes f :: "'b \<Rightarrow> 'a :: field"
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1330
  assumes "finite A" and "finite B"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1331
    and "\<forall>x\<in>A \<inter> B. f x \<noteq> 0"
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1332
  shows "prod f (A \<union> B) = prod f A * prod f B / prod f (A \<inter> B)"
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1333
proof -
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1334
  from assms have "prod f A * prod f B = prod f (A \<union> B) * prod f (A \<inter> B)"
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1335
    by (simp add: prod.union_inter [symmetric, of A B])
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1336
  with assms show ?thesis
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1337
    by simp
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1338
qed
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1339
68361
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1340
context linordered_semidom
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1341
begin
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1342
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1343
lemma prod_nonneg: "(\<forall>a\<in>A. 0 \<le> f a) \<Longrightarrow> 0 \<le> prod f A"
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1344
  by (induct A rule: infinite_finite_induct) simp_all
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1345
68361
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1346
lemma prod_pos: "(\<forall>a\<in>A. 0 < f a) \<Longrightarrow> 0 < prod f A"
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1347
  by (induct A rule: infinite_finite_induct) simp_all
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1348
68361
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1349
lemma prod_mono:
67673
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
  1350
  "(\<And>i. i \<in> A \<Longrightarrow> 0 \<le> f i \<and> f i \<le> g i) \<Longrightarrow> prod f A \<le> prod g A"
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
  1351
  by (induct A rule: infinite_finite_induct) (force intro!: prod_nonneg mult_mono)+
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1352
68361
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1353
lemma prod_mono_strict:
67673
c8caefb20564 lots of new material, ultimately related to measure theory
paulson <lp15@cam.ac.uk>
parents: 67511
diff changeset
  1354
  assumes "finite A" "\<And>i. i \<in> A \<Longrightarrow> 0 \<le> f i \<and> f i < g i" "A \<noteq> {}"
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1355
  shows "prod f A < prod g A"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1356
  using assms
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1357
proof (induct A rule: finite_induct)
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1358
  case empty
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1359
  then show ?case by simp
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1360
next
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1361
  case insert
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1362
  then show ?case by (force intro: mult_strict_mono' prod_nonneg)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1363
qed
60974
6a6f15d8fbc4 New material and fixes related to the forthcoming Stone-Weierstrass development
paulson <lp15@cam.ac.uk>
parents: 60758
diff changeset
  1364
68361
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1365
end
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1366
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1367
lemma prod_mono2:
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1368
  fixes f :: "'a \<Rightarrow> 'b :: linordered_idom"
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1369
  assumes fin: "finite B"
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1370
    and sub: "A \<subseteq> B"
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1371
    and nn: "\<And>b. b \<in> B-A \<Longrightarrow> 1 \<le> f b"
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1372
    and A: "\<And>a. a \<in> A \<Longrightarrow> 0 \<le> f a"
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1373
  shows "prod f A \<le> prod f B"
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1374
proof -
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1375
  have "prod f A \<le> prod f A * prod f (B-A)"
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1376
    by (metis prod_ge_1 A mult_le_cancel_left1 nn not_less prod_nonneg)
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1377
  also from fin finite_subset[OF sub fin] have "\<dots> = prod f (A \<union> (B-A))"
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1378
    by (simp add: prod.union_disjoint del: Un_Diff_cancel)
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1379
  also from sub have "A \<union> (B-A) = B" by blast
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1380
  finally show ?thesis .
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1381
qed
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1382
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1383
lemma less_1_prod:
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1384
  fixes f :: "'a \<Rightarrow> 'b::linordered_idom"
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1385
  shows "finite I \<Longrightarrow> I \<noteq> {} \<Longrightarrow> (\<And>i. i \<in> I \<Longrightarrow> 1 < f i) \<Longrightarrow> 1 < prod f I"
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1386
  by (induct I rule: finite_ne_induct) (auto intro: less_1_mult)
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1387
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1388
lemma less_1_prod2:
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1389
  fixes f :: "'a \<Rightarrow> 'b::linordered_idom"
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1390
  assumes I: "finite I" "i \<in> I" "1 < f i" "\<And>i. i \<in> I \<Longrightarrow> 1 \<le> f i"
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1391
  shows "1 < prod f I"
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1392
proof -
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1393
  have "1 < f i * prod f (I - {i})"
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1394
    using assms
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1395
    by (meson DiffD1 leI less_1_mult less_le_trans mult_le_cancel_left1 prod_ge_1)
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1396
  also have "\<dots> = prod f I"
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1397
    using assms by (simp add: prod.remove)
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1398
  finally show ?thesis .
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1399
qed
20375f232f3b infinite product material
paulson <lp15@cam.ac.uk>
parents: 67969
diff changeset
  1400
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1401
lemma (in linordered_field) abs_prod: "\<bar>prod f A\<bar> = (\<Prod>x\<in>A. \<bar>f x\<bar>)"
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1402
  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
  1403
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1404
lemma prod_eq_1_iff [simp]: "finite A \<Longrightarrow> prod f A = 1 \<longleftrightarrow> (\<forall>a\<in>A. f a = 1)"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1405
  for f :: "'a \<Rightarrow> nat"
59010
ec2b4270a502 generalized lemmas and tuned proofs
haftmann
parents: 58889
diff changeset
  1406
  by (induct A rule: finite_induct) simp_all
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1407
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1408
lemma prod_pos_nat_iff [simp]: "finite A \<Longrightarrow> prod f A > 0 \<longleftrightarrow> (\<forall>a\<in>A. f a > 0)"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1409
  for f :: "'a \<Rightarrow> nat"
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1410
  using prod_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
  1411
67969
83c8cafdebe8 Syntax for the special cases Min(A`I) and Max (A`I)
paulson <lp15@cam.ac.uk>
parents: 67683
diff changeset
  1412
lemma prod_constant [simp]: "(\<Prod>x\<in> A. y) = y ^ card A"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1413
  for y :: "'a::comm_monoid_mult"
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1414
  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
  1415
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1416
lemma prod_power_distrib: "prod f A ^ n = prod (\<lambda>x. (f x) ^ n) A"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1417
  for f :: "'a \<Rightarrow> 'b::comm_semiring_1"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1418
  by (induct A rule: infinite_finite_induct) (auto simp add: power_mult_distrib)
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1419
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
  1420
lemma power_sum: "c ^ (\<Sum>a\<in>A. f a) = (\<Prod>a\<in>A. c ^ f a)"
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1421
  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
  1422
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1423
lemma prod_gen_delta:
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1424
  fixes b :: "'b \<Rightarrow> 'a::comm_monoid_mult"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1425
  assumes fin: "finite S"
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1426
  shows "prod (\<lambda>k. if k = a then b k else c) S =
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1427
    (if a \<in> S then b a * c ^ (card S - 1) else c ^ card S)"
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1428
proof -
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1429
  let ?f = "(\<lambda>k. if k=a then b k else c)"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1430
  show ?thesis
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1431
  proof (cases "a \<in> S")
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1432
    case False
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1433
    then have "\<forall> k\<in> S. ?f k = c" by simp
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1434
    with False show ?thesis by (simp add: prod_constant)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1435
  next
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1436
    case True
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1437
    let ?A = "S - {a}"
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1438
    let ?B = "{a}"
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1439
    from True have eq: "S = ?A \<union> ?B" by blast
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1440
    have disjoint: "?A \<inter> ?B = {}" by simp
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1441
    from fin have fin': "finite ?A" "finite ?B" by auto
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1442
    have f_A0: "prod ?f ?A = prod (\<lambda>i. c) ?A"
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1443
      by (rule prod.cong) auto
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1444
    from fin True have card_A: "card ?A = card S - 1" by auto
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1445
    have f_A1: "prod ?f ?A = c ^ card ?A"
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1446
      unfolding f_A0 by (rule prod_constant)
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1447
    have "prod ?f ?A * prod ?f ?B = prod ?f S"
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1448
      using prod.union_disjoint[OF fin' disjoint, of ?f, unfolded eq[symmetric]]
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1449
      by simp
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1450
    with True card_A show ?thesis
64272
f76b6dda2e56 setprod -> prod
nipkow
parents: 64267
diff changeset
  1451
      by (simp add: f_A1 field_simps cong add: prod.cong cong del: if_weak_cong)
63654
f90e3926e627 misc tuning and modernization;
wenzelm
parents: 63561
diff changeset
  1452
  qed
62481
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1453
qed
b5d8e57826df tuned bootstrap order to provide type classes in a more sensible order
haftmann
parents: 62378
diff changeset
  1454
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
  1455
lemma sum_image_le:
69127
4596b580d1dd generalization due to Alexander Maletzky
nipkow
parents: 68975
diff changeset
  1456
  fixes g :: "'a \<Rightarrow> 'b::ordered_comm_monoid_add"
63952
354808e9f44b new material connected with HOL Light measure theory, plus more rationalisation
paulson <lp15@cam.ac.uk>
parents: 63938
diff changeset
  1457
  assumes "finite I" "\<And>i. i \<in> I \<Longrightarrow> 0 \<le> g(f i)"
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
  1458
    shows "sum g (f ` I) \<le> sum (g \<circ> f) I"
63952
354808e9f44b new material connected with HOL Light measure theory, plus more rationalisation
paulson <lp15@cam.ac.uk>
parents: 63938
diff changeset
  1459
  using assms
354808e9f44b new material connected with HOL Light measure theory, plus more rationalisation
paulson <lp15@cam.ac.uk>
parents: 63938
diff changeset
  1460
proof induction
354808e9f44b new material connected with HOL Light measure theory, plus more rationalisation
paulson <lp15@cam.ac.uk>
parents: 63938
diff changeset
  1461
  case empty
354808e9f44b new material connected with HOL Light measure theory, plus more rationalisation
paulson <lp15@cam.ac.uk>
parents: 63938
diff changeset
  1462
  then show ?case by auto
354808e9f44b new material connected with HOL Light measure theory, plus more rationalisation
paulson <lp15@cam.ac.uk>
parents: 63938
diff changeset
  1463
next
69127
4596b580d1dd generalization due to Alexander Maletzky
nipkow
parents: 68975
diff changeset
  1464
  case (insert x F)
4596b580d1dd generalization due to Alexander Maletzky
nipkow
parents: 68975
diff changeset
  1465
  from insertI1 have "0 \<le> g (f x)" by (rule insert)
4596b580d1dd generalization due to Alexander Maletzky
nipkow
parents: 68975
diff changeset
  1466
  hence 1: "sum g (f ` F) \<le> g (f x) + sum g (f ` F)" using add_increasing by blast
4596b580d1dd generalization due to Alexander Maletzky
nipkow
parents: 68975
diff changeset
  1467
  have 2: "sum g (f ` F) \<le> sum (g \<circ> f) F" using insert by blast
64267
b9a1486e79be setsum -> sum
nipkow
parents: 63952
diff changeset
  1468
  have "sum g (f ` insert x F) = sum g (insert (f x) (f ` F))" by simp
69127
4596b580d1dd generalization due to Alexander Maletzky
nipkow
parents: 68975
diff changeset
  1469
  also have "\<dots> \<le> g (f x) + sum g (f ` F)" by (simp add: 1 insert sum.insert_if)
4596b580d1dd generalization due to Alexander Maletzky
nipkow
parents: 68975
diff changeset
  1470
  also from 2 have "\<dots> \<le> g (f x) + sum (g \<circ> f) F" by (rule add_left_mono)
4596b580d1dd generalization due to Alexander Maletzky
nipkow
parents: 68975
diff changeset
  1471
  also from insert(1, 2) have "\<dots> = sum (g \<circ> f) (insert x F)" by (simp add: sum.insert_if)
63952
354808e9f44b new material connected with HOL Light measure theory, plus more rationalisation
paulson <lp15@cam.ac.uk>
parents: 63938
diff changeset
  1472
  finally show ?case .
354808e9f44b new material connected with HOL Light measure theory, plus more rationalisation
paulson <lp15@cam.ac.uk>
parents: 63938
diff changeset
  1473
qed
68975
5ce4d117cea7 A few new results, elimination of duplicates and more use of "pairwise"
paulson <lp15@cam.ac.uk>
parents: 68361
diff changeset
  1474
54744
1e7f2d296e19 more algebraic terminology for theories about big operators
haftmann
parents:
diff changeset
  1475
end