src/HOL/Analysis/Henstock_Kurzweil_Integration.thy
author wenzelm
Tue Jan 17 13:59:10 2017 +0100 (2017-01-17)
changeset 64911 f0e07600de47
parent 64773 223b2ebdda79
child 65036 ab7e11730ad8
permissions -rw-r--r--
isabelle update_cartouches -c -t;
wenzelm@53399
     1
(*  Author:     John Harrison
lp15@60428
     2
    Author:     Robert Himmelmann, TU Muenchen (Translation from HOL light); proofs reworked by LCP
wenzelm@53399
     3
*)
wenzelm@53399
     4
hoelzl@63594
     5
section \<open>Henstock-Kurzweil gauge integration in many dimensions.\<close>
hoelzl@63594
     6
hoelzl@63594
     7
theory Henstock_Kurzweil_Integration
wenzelm@41413
     8
imports
hoelzl@63957
     9
  Lebesgue_Measure Tagged_Division
himmelma@35172
    10
begin
himmelma@35172
    11
hoelzl@63957
    12
(* BEGIN MOVE *)
hoelzl@63957
    13
lemma norm_minus2: "norm (x1-x2, y1-y2) = norm (x2-x1, y2-y1)"
hoelzl@63957
    14
  by (simp add: norm_minus_eqI)
hoelzl@63957
    15
hoelzl@63957
    16
lemma norm_diff2: "\<lbrakk>y = y1 + y2; x = x1 + x2; e = e1 + e2; norm(y1 - x1) \<le> e1; norm(y2 - x2) \<le> e2\<rbrakk>
hoelzl@63957
    17
  \<Longrightarrow> norm(y - x) \<le> e"
hoelzl@63957
    18
  using norm_triangle_mono [of "y1 - x1" "e1" "y2 - x2" "e2"]
hoelzl@63957
    19
  by (simp add: add_diff_add)
hoelzl@63957
    20
hoelzl@63957
    21
lemma setcomp_dot1: "{z. P (z \<bullet> (i,0))} = {(x,y). P(x \<bullet> i)}"
hoelzl@63886
    22
  by auto
hoelzl@63886
    23
hoelzl@63957
    24
lemma setcomp_dot2: "{z. P (z \<bullet> (0,i))} = {(x,y). P(y \<bullet> i)}"
hoelzl@63957
    25
  by auto
hoelzl@63957
    26
hoelzl@63957
    27
lemma Sigma_Int_Paircomp1: "(Sigma A B) \<inter> {(x, y). P x} = Sigma (A \<inter> {x. P x}) B"
hoelzl@63957
    28
  by blast
hoelzl@63957
    29
hoelzl@63957
    30
lemma Sigma_Int_Paircomp2: "(Sigma A B) \<inter> {(x, y). P y} = Sigma A (\<lambda>z. B z \<inter> {y. P y})"
hoelzl@63957
    31
  by blast
hoelzl@63957
    32
(* END MOVE *)
hoelzl@59425
    33
wenzelm@60420
    34
subsection \<open>Content (length, area, volume...) of an interval.\<close>
himmelma@35172
    35
hoelzl@63886
    36
abbreviation content :: "'a::euclidean_space set \<Rightarrow> real"
hoelzl@63886
    37
  where "content s \<equiv> measure lborel s"
hoelzl@63886
    38
hoelzl@63886
    39
lemma content_cbox_cases:
nipkow@64272
    40
  "content (cbox a b) = (if \<forall>i\<in>Basis. a\<bullet>i \<le> b\<bullet>i then prod (\<lambda>i. b\<bullet>i - a\<bullet>i) Basis else 0)"
hoelzl@63886
    41
  by (simp add: measure_lborel_cbox_eq inner_diff)
hoelzl@63886
    42
hoelzl@63886
    43
lemma content_cbox: "\<forall>i\<in>Basis. a\<bullet>i \<le> b\<bullet>i \<Longrightarrow> content (cbox a b) = (\<Prod>i\<in>Basis. b\<bullet>i - a\<bullet>i)"
hoelzl@63886
    44
  unfolding content_cbox_cases by simp
hoelzl@63886
    45
hoelzl@63886
    46
lemma content_cbox': "cbox a b \<noteq> {} \<Longrightarrow> content (cbox a b) = (\<Prod>i\<in>Basis. b\<bullet>i - a\<bullet>i)"
hoelzl@63886
    47
  by (simp add: box_ne_empty inner_diff)
wenzelm@49970
    48
wenzelm@53408
    49
lemma content_real: "a \<le> b \<Longrightarrow> content {a..b} = b - a"
hoelzl@63886
    50
  by simp
immler@56188
    51
wenzelm@61945
    52
lemma abs_eq_content: "\<bar>y - x\<bar> = (if x\<le>y then content {x .. y} else content {y..x})"
paulson@61204
    53
  by (auto simp: content_real)
paulson@61204
    54
hoelzl@63886
    55
lemma content_singleton: "content {a} = 0"
hoelzl@63886
    56
  by simp
hoelzl@63886
    57
hoelzl@63886
    58
lemma content_unit[iff]: "content (cbox 0 (One::'a::euclidean_space)) = 1"
hoelzl@63886
    59
  by simp
hoelzl@63886
    60
hoelzl@63886
    61
lemma content_pos_le[intro]: "0 \<le> content (cbox a b)"
hoelzl@63886
    62
  by simp
hoelzl@63886
    63
hoelzl@63886
    64
corollary content_nonneg [simp]: "~ content (cbox a b) < 0"
hoelzl@63886
    65
  using not_le by blast
hoelzl@63886
    66
hoelzl@63886
    67
lemma content_pos_lt: "\<forall>i\<in>Basis. a\<bullet>i < b\<bullet>i \<Longrightarrow> 0 < content (cbox a b)"
nipkow@64272
    68
  by (auto simp: less_imp_le inner_diff box_eq_empty intro!: prod_pos)
hoelzl@63886
    69
hoelzl@63886
    70
lemma content_eq_0: "content (cbox a b) = 0 \<longleftrightarrow> (\<exists>i\<in>Basis. b\<bullet>i \<le> a\<bullet>i)"
hoelzl@63886
    71
  by (auto simp: content_cbox_cases not_le intro: less_imp_le antisym eq_refl)
immler@56188
    72
immler@56188
    73
lemma content_eq_0_interior: "content (cbox a b) = 0 \<longleftrightarrow> interior(cbox a b) = {}"
hoelzl@63886
    74
  unfolding content_eq_0 interior_cbox box_eq_empty by auto
hoelzl@63886
    75
hoelzl@63886
    76
lemma content_pos_lt_eq: "0 < content (cbox a (b::'a::euclidean_space)) \<longleftrightarrow> (\<forall>i\<in>Basis. a\<bullet>i < b\<bullet>i)"
nipkow@64272
    77
  by (auto simp add: content_cbox_cases less_le prod_nonneg)
wenzelm@49970
    78
wenzelm@53399
    79
lemma content_empty [simp]: "content {} = 0"
hoelzl@63886
    80
  by simp
himmelma@35172
    81
paulson@60762
    82
lemma content_real_if [simp]: "content {a..b} = (if a \<le> b then b - a else 0)"
paulson@60762
    83
  by (simp add: content_real)
paulson@60762
    84
hoelzl@63886
    85
lemma content_subset: "cbox a b \<subseteq> cbox c d \<Longrightarrow> content (cbox a b) \<le> content (cbox c d)"
hoelzl@63886
    86
  unfolding measure_def
hoelzl@63886
    87
  by (intro enn2real_mono emeasure_mono) (auto simp: emeasure_lborel_cbox_eq)
immler@56188
    88
immler@56188
    89
lemma content_lt_nz: "0 < content (cbox a b) \<longleftrightarrow> content (cbox a b) \<noteq> 0"
nipkow@44890
    90
  unfolding content_pos_lt_eq content_eq_0 unfolding not_ex not_le by fastforce
himmelma@35172
    91
lp15@60615
    92
lemma content_Pair: "content (cbox (a,c) (b,d)) = content (cbox a b) * content (cbox c d)"
hoelzl@63886
    93
  unfolding measure_lborel_cbox_eq Basis_prod_def
nipkow@64272
    94
  apply (subst prod.union_disjoint)
hoelzl@63886
    95
  apply (auto simp: bex_Un ball_Un)
nipkow@64272
    96
  apply (subst (1 2) prod.reindex_nontrivial)
hoelzl@63886
    97
  apply auto
hoelzl@63886
    98
  done
lp15@60615
    99
lp15@60615
   100
lemma content_cbox_pair_eq0_D:
lp15@60615
   101
   "content (cbox (a,c) (b,d)) = 0 \<Longrightarrow> content (cbox a b) = 0 \<or> content (cbox c d) = 0"
lp15@60615
   102
  by (simp add: content_Pair)
lp15@60615
   103
hoelzl@63886
   104
lemma content_0_subset: "content(cbox a b) = 0 \<Longrightarrow> s \<subseteq> cbox a b \<Longrightarrow> content s = 0"
hoelzl@63886
   105
  using emeasure_mono[of s "cbox a b" lborel]
hoelzl@63886
   106
  by (auto simp: measure_def enn2real_eq_0_iff emeasure_lborel_cbox_eq)
hoelzl@63593
   107
hoelzl@63593
   108
lemma content_split:
hoelzl@63593
   109
  fixes a :: "'a::euclidean_space"
hoelzl@63593
   110
  assumes "k \<in> Basis"
hoelzl@63593
   111
  shows "content (cbox a b) = content(cbox a b \<inter> {x. x\<bullet>k \<le> c}) + content(cbox a b \<inter> {x. x\<bullet>k \<ge> c})"
wenzelm@64911
   112
  \<comment> \<open>Prove using measure theory\<close>
hoelzl@63593
   113
proof cases
hoelzl@63593
   114
  note simps = interval_split[OF assms] content_cbox_cases
hoelzl@63593
   115
  have *: "Basis = insert k (Basis - {k})" "\<And>x. finite (Basis-{x})" "\<And>x. x\<notin>Basis-{x}"
hoelzl@63593
   116
    using assms by auto
hoelzl@63593
   117
  have *: "\<And>X Y Z. (\<Prod>i\<in>Basis. Z i (if i = k then X else Y i)) = Z k X * (\<Prod>i\<in>Basis-{k}. Z i (Y i))"
hoelzl@63593
   118
    "(\<Prod>i\<in>Basis. b\<bullet>i - a\<bullet>i) = (\<Prod>i\<in>Basis-{k}. b\<bullet>i - a\<bullet>i) * (b\<bullet>k - a\<bullet>k)"
hoelzl@63593
   119
    apply (subst *(1))
hoelzl@63593
   120
    defer
hoelzl@63593
   121
    apply (subst *(1))
nipkow@64272
   122
    unfolding prod.insert[OF *(2-)]
hoelzl@63593
   123
    apply auto
hoelzl@63593
   124
    done
hoelzl@63593
   125
  assume as: "\<forall>i\<in>Basis. a \<bullet> i \<le> b \<bullet> i"
hoelzl@63593
   126
  moreover
hoelzl@63593
   127
  have "\<And>x. min (b \<bullet> k) c = max (a \<bullet> k) c \<Longrightarrow>
hoelzl@63593
   128
    x * (b\<bullet>k - a\<bullet>k) = x * (max (a \<bullet> k) c - a \<bullet> k) + x * (b \<bullet> k - max (a \<bullet> k) c)"
hoelzl@63593
   129
    by  (auto simp add: field_simps)
hoelzl@63593
   130
  moreover
hoelzl@63593
   131
  have **: "(\<Prod>i\<in>Basis. ((\<Sum>i\<in>Basis. (if i = k then min (b \<bullet> k) c else b \<bullet> i) *\<^sub>R i) \<bullet> i - a \<bullet> i)) =
hoelzl@63593
   132
      (\<Prod>i\<in>Basis. (if i = k then min (b \<bullet> k) c else b \<bullet> i) - a \<bullet> i)"
hoelzl@63593
   133
    "(\<Prod>i\<in>Basis. b \<bullet> i - ((\<Sum>i\<in>Basis. (if i = k then max (a \<bullet> k) c else a \<bullet> i) *\<^sub>R i) \<bullet> i)) =
hoelzl@63593
   134
      (\<Prod>i\<in>Basis. b \<bullet> i - (if i = k then max (a \<bullet> k) c else a \<bullet> i))"
nipkow@64272
   135
    by (auto intro!: prod.cong)
hoelzl@63593
   136
  have "\<not> a \<bullet> k \<le> c \<Longrightarrow> \<not> c \<le> b \<bullet> k \<Longrightarrow> False"
hoelzl@63593
   137
    unfolding not_le
hoelzl@63593
   138
    using as[unfolded ,rule_format,of k] assms
hoelzl@63593
   139
    by auto
hoelzl@63593
   140
  ultimately show ?thesis
hoelzl@63593
   141
    using assms
hoelzl@63593
   142
    unfolding simps **
hoelzl@63593
   143
    unfolding *(1)[of "\<lambda>i x. b\<bullet>i - x"] *(1)[of "\<lambda>i x. x - a\<bullet>i"]
hoelzl@63593
   144
    unfolding *(2)
hoelzl@63593
   145
    by auto
hoelzl@63593
   146
next
hoelzl@63593
   147
  assume "\<not> (\<forall>i\<in>Basis. a \<bullet> i \<le> b \<bullet> i)"
hoelzl@63593
   148
  then have "cbox a b = {}"
hoelzl@63593
   149
    unfolding box_eq_empty by (auto simp: not_le)
hoelzl@63593
   150
  then show ?thesis
hoelzl@63593
   151
    by (auto simp: not_le)
hoelzl@63593
   152
qed
hoelzl@63593
   153
wenzelm@49970
   154
lemma division_of_content_0:
immler@56188
   155
  assumes "content (cbox a b) = 0" "d division_of (cbox a b)"
wenzelm@49970
   156
  shows "\<forall>k\<in>d. content k = 0"
wenzelm@49970
   157
  unfolding forall_in_division[OF assms(2)]
lp15@60384
   158
  by (metis antisym_conv assms content_pos_le content_subset division_ofD(2))
wenzelm@49970
   159
nipkow@64267
   160
lemma sum_content_null:
hoelzl@63957
   161
  assumes "content (cbox a b) = 0"
hoelzl@63957
   162
    and "p tagged_division_of (cbox a b)"
nipkow@64267
   163
  shows "sum (\<lambda>(x,k). content k *\<^sub>R f x) p = (0::'a::real_normed_vector)"
nipkow@64267
   164
proof (rule sum.neutral, rule)
hoelzl@63957
   165
  fix y
hoelzl@63957
   166
  assume y: "y \<in> p"
hoelzl@63957
   167
  obtain x k where xk: "y = (x, k)"
hoelzl@63957
   168
    using surj_pair[of y] by blast
hoelzl@63957
   169
  note assm = tagged_division_ofD(3-4)[OF assms(2) y[unfolded xk]]
hoelzl@63957
   170
  from this(2) obtain c d where k: "k = cbox c d" by blast
hoelzl@63957
   171
  have "(\<lambda>(x, k). content k *\<^sub>R f x) y = content k *\<^sub>R f x"
hoelzl@63957
   172
    unfolding xk by auto
hoelzl@63957
   173
  also have "\<dots> = 0"
hoelzl@63957
   174
    using content_subset[OF assm(1)[unfolded k]] content_pos_le[of c d]
hoelzl@63957
   175
    unfolding assms(1) k
wenzelm@53399
   176
    by auto
hoelzl@63957
   177
  finally show "(\<lambda>(x, k). content k *\<^sub>R f x) y = 0" .
hoelzl@63593
   178
qed
hoelzl@63593
   179
hoelzl@63593
   180
lemma operative_content[intro]: "add.operative content"
hoelzl@63957
   181
  by (force simp add: add.operative_def content_split[symmetric] content_eq_0_interior)
hoelzl@63593
   182
nipkow@64267
   183
lemma additive_content_division: "d division_of (cbox a b) \<Longrightarrow> sum content d = content (cbox a b)"
nipkow@64267
   184
  by (metis operative_content sum.operative_division)
hoelzl@63593
   185
hoelzl@63593
   186
lemma additive_content_tagged_division:
nipkow@64267
   187
  "d tagged_division_of (cbox a b) \<Longrightarrow> sum (\<lambda>(x,l). content l) d = content (cbox a b)"
nipkow@64267
   188
  unfolding sum.operative_tagged_division[OF operative_content, symmetric] by blast
hoelzl@63593
   189
hoelzl@63593
   190
lemma content_real_eq_0: "content {a .. b::real} = 0 \<longleftrightarrow> a \<ge> b"
hoelzl@63593
   191
  by (metis atLeastatMost_empty_iff2 content_empty content_real diff_self eq_iff le_cases le_iff_diff_le_0)
hoelzl@63593
   192
hoelzl@63957
   193
lemma property_empty_interval: "\<forall>a b. content (cbox a b) = 0 \<longrightarrow> P (cbox a b) \<Longrightarrow> P {}"
hoelzl@63957
   194
  using content_empty unfolding empty_as_interval by auto
hoelzl@63944
   195
hoelzl@63944
   196
subsection \<open>Gauge integral\<close>
hoelzl@63944
   197
hoelzl@63944
   198
text \<open>Case distinction to define it first on compact intervals first, then use a limit. This is only
hoelzl@63944
   199
much later unified. In Fremlin: Measure Theory, Volume 4I this is generalized using residual sets.\<close>
hoelzl@63944
   200
hoelzl@63944
   201
definition has_integral :: "('n::euclidean_space \<Rightarrow> 'b::real_normed_vector) \<Rightarrow> 'b \<Rightarrow> 'n set \<Rightarrow> bool"
hoelzl@63944
   202
  (infixr "has'_integral" 46)
hoelzl@63944
   203
  where "(f has_integral I) s \<longleftrightarrow>
hoelzl@63944
   204
    (if \<exists>a b. s = cbox a b
hoelzl@63944
   205
      then ((\<lambda>p. \<Sum>(x,k)\<in>p. content k *\<^sub>R f x) \<longlongrightarrow> I) (division_filter s)
hoelzl@63944
   206
      else (\<forall>e>0. \<exists>B>0. \<forall>a b. ball 0 B \<subseteq> cbox a b \<longrightarrow>
hoelzl@63944
   207
        (\<exists>z. ((\<lambda>p. \<Sum>(x,k)\<in>p. content k *\<^sub>R (if x \<in> s then f x else 0)) \<longlongrightarrow> z) (division_filter (cbox a b)) \<and>
hoelzl@63944
   208
          norm (z - I) < e)))"
hoelzl@63944
   209
hoelzl@63944
   210
lemma has_integral_cbox:
hoelzl@63944
   211
  "(f has_integral I) (cbox a b) \<longleftrightarrow> ((\<lambda>p. \<Sum>(x,k)\<in>p. content k *\<^sub>R f x) \<longlongrightarrow> I) (division_filter (cbox a b))"
hoelzl@63944
   212
  by (auto simp add: has_integral_def)
hoelzl@63944
   213
hoelzl@63944
   214
lemma has_integral:
hoelzl@63944
   215
  "(f has_integral y) (cbox a b) \<longleftrightarrow>
hoelzl@63944
   216
    (\<forall>e>0. \<exists>d. gauge d \<and>
hoelzl@63944
   217
      (\<forall>p. p tagged_division_of (cbox a b) \<and> d fine p \<longrightarrow>
nipkow@64267
   218
        norm (sum (\<lambda>(x,k). content(k) *\<^sub>R f x) p - y) < e))"
hoelzl@63944
   219
  by (auto simp: dist_norm eventually_division_filter has_integral_def tendsto_iff)
hoelzl@63944
   220
hoelzl@63944
   221
lemma has_integral_real:
hoelzl@63944
   222
  "(f has_integral y) {a .. b::real} \<longleftrightarrow>
hoelzl@63944
   223
    (\<forall>e>0. \<exists>d. gauge d \<and>
hoelzl@63944
   224
      (\<forall>p. p tagged_division_of {a .. b} \<and> d fine p \<longrightarrow>
nipkow@64267
   225
        norm (sum (\<lambda>(x,k). content(k) *\<^sub>R f x) p - y) < e))"
hoelzl@63944
   226
  unfolding box_real[symmetric]
hoelzl@63944
   227
  by (rule has_integral)
hoelzl@63944
   228
hoelzl@63944
   229
lemma has_integralD[dest]:
hoelzl@63944
   230
  assumes "(f has_integral y) (cbox a b)"
hoelzl@63944
   231
    and "e > 0"
hoelzl@63944
   232
  obtains d
hoelzl@63944
   233
    where "gauge d"
hoelzl@63944
   234
      and "\<And>p. p tagged_division_of (cbox a b) \<Longrightarrow> d fine p \<Longrightarrow>
hoelzl@63944
   235
        norm ((\<Sum>(x,k)\<in>p. content k *\<^sub>R f x) - y) < e"
hoelzl@63944
   236
  using assms unfolding has_integral by auto
hoelzl@63944
   237
hoelzl@63944
   238
lemma has_integral_alt:
hoelzl@63944
   239
  "(f has_integral y) i \<longleftrightarrow>
hoelzl@63944
   240
    (if \<exists>a b. i = cbox a b
hoelzl@63944
   241
     then (f has_integral y) i
hoelzl@63944
   242
     else (\<forall>e>0. \<exists>B>0. \<forall>a b. ball 0 B \<subseteq> cbox a b \<longrightarrow>
hoelzl@63944
   243
      (\<exists>z. ((\<lambda>x. if x \<in> i then f x else 0) has_integral z) (cbox a b) \<and> norm (z - y) < e)))"
hoelzl@63944
   244
  by (subst has_integral_def) (auto simp add: has_integral_cbox)
hoelzl@63944
   245
hoelzl@63944
   246
lemma has_integral_altD:
hoelzl@63944
   247
  assumes "(f has_integral y) i"
hoelzl@63944
   248
    and "\<not> (\<exists>a b. i = cbox a b)"
hoelzl@63944
   249
    and "e>0"
hoelzl@63944
   250
  obtains B where "B > 0"
hoelzl@63944
   251
    and "\<forall>a b. ball 0 B \<subseteq> cbox a b \<longrightarrow>
hoelzl@63944
   252
      (\<exists>z. ((\<lambda>x. if x \<in> i then f(x) else 0) has_integral z) (cbox a b) \<and> norm(z - y) < e)"
hoelzl@63944
   253
  using assms has_integral_alt[of f y i] by auto
hoelzl@63944
   254
hoelzl@63944
   255
definition integrable_on (infixr "integrable'_on" 46)
hoelzl@63944
   256
  where "f integrable_on i \<longleftrightarrow> (\<exists>y. (f has_integral y) i)"
hoelzl@63944
   257
hoelzl@63944
   258
definition "integral i f = (SOME y. (f has_integral y) i \<or> ~ f integrable_on i \<and> y=0)"
hoelzl@63944
   259
hoelzl@63944
   260
lemma integrable_integral[dest]: "f integrable_on i \<Longrightarrow> (f has_integral (integral i f)) i"
hoelzl@63944
   261
  unfolding integrable_on_def integral_def by (metis (mono_tags, lifting) someI_ex)
hoelzl@63944
   262
hoelzl@63944
   263
lemma not_integrable_integral: "~ f integrable_on i \<Longrightarrow> integral i f = 0"
hoelzl@63944
   264
  unfolding integrable_on_def integral_def by blast
hoelzl@63944
   265
hoelzl@63944
   266
lemma has_integral_integrable[intro]: "(f has_integral i) s \<Longrightarrow> f integrable_on s"
hoelzl@63944
   267
  unfolding integrable_on_def by auto
hoelzl@63944
   268
hoelzl@63944
   269
lemma has_integral_integral: "f integrable_on s \<longleftrightarrow> (f has_integral (integral s f)) s"
hoelzl@63944
   270
  by auto
hoelzl@63944
   271
wenzelm@60420
   272
subsection \<open>Basic theorems about integrals.\<close>
himmelma@35172
   273
wenzelm@53409
   274
lemma has_integral_unique:
immler@56188
   275
  fixes f :: "'n::euclidean_space \<Rightarrow> 'a::real_normed_vector"
wenzelm@53410
   276
  assumes "(f has_integral k1) i"
wenzelm@53410
   277
    and "(f has_integral k2) i"
wenzelm@53409
   278
  shows "k1 = k2"
wenzelm@53410
   279
proof (rule ccontr)
wenzelm@53842
   280
  let ?e = "norm (k1 - k2) / 2"
wenzelm@61165
   281
  assume as: "k1 \<noteq> k2"
wenzelm@53410
   282
  then have e: "?e > 0"
wenzelm@53410
   283
    by auto
hoelzl@63944
   284
  have lem: "(f has_integral k1) (cbox a b) \<Longrightarrow> (f has_integral k2) (cbox a b) \<Longrightarrow> k1 = k2"
wenzelm@61165
   285
    for f :: "'n \<Rightarrow> 'a" and a b k1 k2
hoelzl@63944
   286
    by (auto simp: has_integral_cbox intro: tendsto_unique[OF division_filter_not_empty])
wenzelm@53410
   287
  {
immler@56188
   288
    presume "\<not> (\<exists>a b. i = cbox a b) \<Longrightarrow> False"
wenzelm@53410
   289
    then show False
lp15@60396
   290
      using as assms lem by blast
wenzelm@53410
   291
  }
immler@56188
   292
  assume as: "\<not> (\<exists>a b. i = cbox a b)"
wenzelm@55751
   293
  obtain B1 where B1:
wenzelm@55751
   294
      "0 < B1"
immler@56188
   295
      "\<And>a b. ball 0 B1 \<subseteq> cbox a b \<Longrightarrow>
immler@56188
   296
        \<exists>z. ((\<lambda>x. if x \<in> i then f x else 0) has_integral z) (cbox a b) \<and>
wenzelm@55751
   297
          norm (z - k1) < norm (k1 - k2) / 2"
wenzelm@55751
   298
    by (rule has_integral_altD[OF assms(1) as,OF e]) blast
wenzelm@55751
   299
  obtain B2 where B2:
wenzelm@55751
   300
      "0 < B2"
immler@56188
   301
      "\<And>a b. ball 0 B2 \<subseteq> cbox a b \<Longrightarrow>
immler@56188
   302
        \<exists>z. ((\<lambda>x. if x \<in> i then f x else 0) has_integral z) (cbox a b) \<and>
wenzelm@55751
   303
          norm (z - k2) < norm (k1 - k2) / 2"
wenzelm@55751
   304
    by (rule has_integral_altD[OF assms(2) as,OF e]) blast
immler@56188
   305
  have "\<exists>a b::'n. ball 0 B1 \<union> ball 0 B2 \<subseteq> cbox a b"
immler@56188
   306
    apply (rule bounded_subset_cbox)
wenzelm@53410
   307
    using bounded_Un bounded_ball
wenzelm@53410
   308
    apply auto
wenzelm@53410
   309
    done
immler@56188
   310
  then obtain a b :: 'n where ab: "ball 0 B1 \<subseteq> cbox a b" "ball 0 B2 \<subseteq> cbox a b"
wenzelm@53410
   311
    by blast
wenzelm@53410
   312
  obtain w where w:
immler@56188
   313
    "((\<lambda>x. if x \<in> i then f x else 0) has_integral w) (cbox a b)"
wenzelm@53410
   314
    "norm (w - k1) < norm (k1 - k2) / 2"
wenzelm@53410
   315
    using B1(2)[OF ab(1)] by blast
wenzelm@53410
   316
  obtain z where z:
immler@56188
   317
    "((\<lambda>x. if x \<in> i then f x else 0) has_integral z) (cbox a b)"
wenzelm@53410
   318
    "norm (z - k2) < norm (k1 - k2) / 2"
wenzelm@53410
   319
    using B2(2)[OF ab(2)] by blast
wenzelm@53410
   320
  have "z = w"
wenzelm@53410
   321
    using lem[OF w(1) z(1)] by auto
wenzelm@53410
   322
  then have "norm (k1 - k2) \<le> norm (z - k2) + norm (w - k1)"
wenzelm@53410
   323
    using norm_triangle_ineq4 [of "k1 - w" "k2 - z"]
wenzelm@53410
   324
    by (auto simp add: norm_minus_commute)
wenzelm@53410
   325
  also have "\<dots> < norm (k1 - k2) / 2 + norm (k1 - k2) / 2"
wenzelm@53410
   326
    apply (rule add_strict_mono)
wenzelm@53410
   327
    apply (rule_tac[!] z(2) w(2))
wenzelm@53410
   328
    done
wenzelm@53410
   329
  finally show False by auto
wenzelm@53410
   330
qed
wenzelm@53410
   331
wenzelm@53410
   332
lemma integral_unique [intro]: "(f has_integral y) k \<Longrightarrow> integral k f = y"
wenzelm@53410
   333
  unfolding integral_def
wenzelm@53410
   334
  by (rule some_equality) (auto intro: has_integral_unique)
wenzelm@53410
   335
lp15@62463
   336
lemma eq_integralD: "integral k f = y \<Longrightarrow> (f has_integral y) k \<or> ~ f integrable_on k \<and> y=0"
lp15@62463
   337
  unfolding integral_def integrable_on_def
lp15@62463
   338
  apply (erule subst)
lp15@62463
   339
  apply (rule someI_ex)
lp15@62463
   340
  by blast
lp15@62463
   341
hoelzl@63944
   342
hoelzl@63944
   343
lemma has_integral_const [intro]:
hoelzl@63944
   344
  fixes a b :: "'a::euclidean_space"
hoelzl@63944
   345
  shows "((\<lambda>x. c) has_integral (content (cbox a b) *\<^sub>R c)) (cbox a b)"
hoelzl@63944
   346
  using eventually_division_filter_tagged_division[of "cbox a b"]
hoelzl@63944
   347
     additive_content_tagged_division[of _ a b]
nipkow@64267
   348
  by (auto simp: has_integral_cbox split_beta' scaleR_sum_left[symmetric]
hoelzl@63944
   349
           elim!: eventually_mono intro!: tendsto_cong[THEN iffD1, OF _ tendsto_const])
hoelzl@63944
   350
hoelzl@63944
   351
lemma has_integral_const_real [intro]:
hoelzl@63944
   352
  fixes a b :: real
hoelzl@63944
   353
  shows "((\<lambda>x. c) has_integral (content {a .. b} *\<^sub>R c)) {a .. b}"
hoelzl@63944
   354
  by (metis box_real(2) has_integral_const)
hoelzl@63944
   355
hoelzl@63944
   356
lemma integral_const [simp]:
hoelzl@63944
   357
  fixes a b :: "'a::euclidean_space"
hoelzl@63944
   358
  shows "integral (cbox a b) (\<lambda>x. c) = content (cbox a b) *\<^sub>R c"
hoelzl@63944
   359
  by (rule integral_unique) (rule has_integral_const)
hoelzl@63944
   360
hoelzl@63944
   361
lemma integral_const_real [simp]:
hoelzl@63944
   362
  fixes a b :: real
hoelzl@63944
   363
  shows "integral {a .. b} (\<lambda>x. c) = content {a .. b} *\<^sub>R c"
hoelzl@63944
   364
  by (metis box_real(2) integral_const)
hoelzl@63944
   365
wenzelm@53410
   366
lemma has_integral_is_0:
immler@56188
   367
  fixes f :: "'n::euclidean_space \<Rightarrow> 'a::real_normed_vector"
wenzelm@53410
   368
  assumes "\<forall>x\<in>s. f x = 0"
wenzelm@53410
   369
  shows "(f has_integral 0) s"
wenzelm@53410
   370
proof -
hoelzl@63944
   371
  have lem: "(\<forall>x\<in>cbox a b. f x = 0) \<Longrightarrow> (f has_integral 0) (cbox a b)" for a  b and f :: "'n \<Rightarrow> 'a"
hoelzl@63944
   372
    unfolding has_integral_cbox
hoelzl@63944
   373
    using eventually_division_filter_tagged_division[of "cbox a b"]
hoelzl@63944
   374
    by (subst tendsto_cong[where g="\<lambda>_. 0"])
nipkow@64267
   375
       (auto elim!: eventually_mono intro!: sum.neutral simp: tag_in_interval)
wenzelm@53410
   376
  {
immler@56188
   377
    presume "\<not> (\<exists>a b. s = cbox a b) \<Longrightarrow> ?thesis"
lp15@60396
   378
    with assms lem show ?thesis
lp15@60396
   379
      by blast
wenzelm@53410
   380
  }
wenzelm@53410
   381
  have *: "(\<lambda>x. if x \<in> s then f x else 0) = (\<lambda>x. 0)"
wenzelm@53410
   382
    apply (rule ext)
wenzelm@53410
   383
    using assms
wenzelm@53410
   384
    apply auto
wenzelm@53410
   385
    done
immler@56188
   386
  assume "\<not> (\<exists>a b. s = cbox a b)"
wenzelm@53410
   387
  then show ?thesis
lp15@60396
   388
    using lem
lp15@60396
   389
    by (subst has_integral_alt) (force simp add: *)
wenzelm@53410
   390
qed
himmelma@35172
   391
immler@56188
   392
lemma has_integral_0[simp]: "((\<lambda>x::'n::euclidean_space. 0) has_integral 0) s"
wenzelm@53410
   393
  by (rule has_integral_is_0) auto
himmelma@35172
   394
himmelma@35172
   395
lemma has_integral_0_eq[simp]: "((\<lambda>x. 0) has_integral i) s \<longleftrightarrow> i = 0"
himmelma@35172
   396
  using has_integral_unique[OF has_integral_0] by auto
himmelma@35172
   397
wenzelm@53410
   398
lemma has_integral_linear:
immler@56188
   399
  fixes f :: "'n::euclidean_space \<Rightarrow> 'a::real_normed_vector"
wenzelm@53410
   400
  assumes "(f has_integral y) s"
wenzelm@53410
   401
    and "bounded_linear h"
wenzelm@61736
   402
  shows "((h \<circ> f) has_integral ((h y))) s"
wenzelm@53410
   403
proof -
wenzelm@53410
   404
  interpret bounded_linear h
wenzelm@53410
   405
    using assms(2) .
wenzelm@53410
   406
  from pos_bounded obtain B where B: "0 < B" "\<And>x. norm (h x) \<le> norm x * B"
wenzelm@53410
   407
    by blast
hoelzl@63944
   408
  have lem: "\<And>a b y f::'n\<Rightarrow>'a. (f has_integral y) (cbox a b) \<Longrightarrow> ((h \<circ> f) has_integral h y) (cbox a b)"
nipkow@64267
   409
    unfolding has_integral_cbox by (drule tendsto) (simp add: sum scaleR split_beta')
wenzelm@53410
   410
  {
immler@56188
   411
    presume "\<not> (\<exists>a b. s = cbox a b) \<Longrightarrow> ?thesis"
wenzelm@53410
   412
    then show ?thesis
lp15@60396
   413
      using assms(1) lem by blast
wenzelm@53410
   414
  }
immler@56188
   415
  assume as: "\<not> (\<exists>a b. s = cbox a b)"
wenzelm@53410
   416
  then show ?thesis
lp15@60396
   417
  proof (subst has_integral_alt, clarsimp)
wenzelm@53410
   418
    fix e :: real
wenzelm@53410
   419
    assume e: "e > 0"
nipkow@56541
   420
    have *: "0 < e/B" using e B(1) by simp
wenzelm@53410
   421
    obtain M where M:
wenzelm@53410
   422
      "M > 0"
immler@56188
   423
      "\<And>a b. ball 0 M \<subseteq> cbox a b \<Longrightarrow>
immler@56188
   424
        \<exists>z. ((\<lambda>x. if x \<in> s then f x else 0) has_integral z) (cbox a b) \<and> norm (z - y) < e / B"
wenzelm@53410
   425
      using has_integral_altD[OF assms(1) as *] by blast
immler@56188
   426
    show "\<exists>B>0. \<forall>a b. ball 0 B \<subseteq> cbox a b \<longrightarrow>
immler@56188
   427
      (\<exists>z. ((\<lambda>x. if x \<in> s then (h \<circ> f) x else 0) has_integral z) (cbox a b) \<and> norm (z - h y) < e)"
wenzelm@61166
   428
    proof (rule_tac x=M in exI, clarsimp simp add: M, goal_cases)
wenzelm@61167
   429
      case prems: (1 a b)
wenzelm@53410
   430
      obtain z where z:
immler@56188
   431
        "((\<lambda>x. if x \<in> s then f x else 0) has_integral z) (cbox a b)"
wenzelm@53410
   432
        "norm (z - y) < e / B"
wenzelm@61167
   433
        using M(2)[OF prems(1)] by blast
wenzelm@53410
   434
      have *: "(\<lambda>x. if x \<in> s then (h \<circ> f) x else 0) = h \<circ> (\<lambda>x. if x \<in> s then f x else 0)"
lp15@60396
   435
        using zero by auto
wenzelm@53410
   436
      show ?case
wenzelm@53410
   437
        apply (rule_tac x="h z" in exI)
hoelzl@63944
   438
        apply (simp add: * lem[OF z(1)])
wenzelm@61165
   439
        apply (metis B diff le_less_trans pos_less_divide_eq z(2))
wenzelm@61165
   440
        done
wenzelm@53410
   441
    qed
wenzelm@53410
   442
  qed
wenzelm@53410
   443
qed
wenzelm@53410
   444
lp15@60615
   445
lemma has_integral_scaleR_left:
hoelzl@57447
   446
  "(f has_integral y) s \<Longrightarrow> ((\<lambda>x. f x *\<^sub>R c) has_integral (y *\<^sub>R c)) s"
hoelzl@57447
   447
  using has_integral_linear[OF _ bounded_linear_scaleR_left] by (simp add: comp_def)
hoelzl@57447
   448
hoelzl@57447
   449
lemma has_integral_mult_left:
lp15@62463
   450
  fixes c :: "_ :: real_normed_algebra"
hoelzl@57447
   451
  shows "(f has_integral y) s \<Longrightarrow> ((\<lambda>x. f x * c) has_integral (y * c)) s"
hoelzl@57447
   452
  using has_integral_linear[OF _ bounded_linear_mult_left] by (simp add: comp_def)
hoelzl@57447
   453
lp15@62463
   454
text\<open>The case analysis eliminates the condition @{term "f integrable_on s"} at the cost
wenzelm@62837
   455
     of the type class constraint \<open>division_ring\<close>\<close>
lp15@62463
   456
corollary integral_mult_left [simp]:
lp15@62463
   457
  fixes c:: "'a::{real_normed_algebra,division_ring}"
lp15@62463
   458
  shows "integral s (\<lambda>x. f x * c) = integral s f * c"
lp15@62463
   459
proof (cases "f integrable_on s \<or> c = 0")
lp15@62463
   460
  case True then show ?thesis
lp15@62463
   461
    by (force intro: has_integral_mult_left)
lp15@62463
   462
next
lp15@62463
   463
  case False then have "~ (\<lambda>x. f x * c) integrable_on s"
lp15@62463
   464
    using has_integral_mult_left [of "(\<lambda>x. f x * c)" _ s "inverse c"]
lp15@62463
   465
    by (force simp add: mult.assoc)
lp15@62463
   466
  with False show ?thesis by (simp add: not_integrable_integral)
lp15@62463
   467
qed
lp15@62463
   468
lp15@62463
   469
corollary integral_mult_right [simp]:
lp15@62463
   470
  fixes c:: "'a::{real_normed_field}"
lp15@62463
   471
  shows "integral s (\<lambda>x. c * f x) = c * integral s f"
lp15@62463
   472
by (simp add: mult.commute [of c])
lp15@60615
   473
lp15@62533
   474
corollary integral_divide [simp]:
lp15@62533
   475
  fixes z :: "'a::real_normed_field"
lp15@62533
   476
  shows "integral S (\<lambda>x. f x / z) = integral S (\<lambda>x. f x) / z"
lp15@62533
   477
using integral_mult_left [of S f "inverse z"]
lp15@62533
   478
  by (simp add: divide_inverse_commute)
lp15@62533
   479
paulson@60762
   480
lemma has_integral_mult_right:
paulson@60762
   481
  fixes c :: "'a :: real_normed_algebra"
paulson@60762
   482
  shows "(f has_integral y) i \<Longrightarrow> ((\<lambda>x. c * f x) has_integral (c * y)) i"
paulson@60762
   483
  using has_integral_linear[OF _ bounded_linear_mult_right] by (simp add: comp_def)
wenzelm@61165
   484
wenzelm@53410
   485
lemma has_integral_cmul: "(f has_integral k) s \<Longrightarrow> ((\<lambda>x. c *\<^sub>R f x) has_integral (c *\<^sub>R k)) s"
wenzelm@53410
   486
  unfolding o_def[symmetric]
lp15@60396
   487
  by (metis has_integral_linear bounded_linear_scaleR_right)
himmelma@35172
   488
hoelzl@50104
   489
lemma has_integral_cmult_real:
hoelzl@50104
   490
  fixes c :: real
hoelzl@50104
   491
  assumes "c \<noteq> 0 \<Longrightarrow> (f has_integral x) A"
hoelzl@50104
   492
  shows "((\<lambda>x. c * f x) has_integral c * x) A"
wenzelm@53410
   493
proof (cases "c = 0")
wenzelm@53410
   494
  case True
wenzelm@53410
   495
  then show ?thesis by simp
wenzelm@53410
   496
next
wenzelm@53410
   497
  case False
hoelzl@50104
   498
  from has_integral_cmul[OF assms[OF this], of c] show ?thesis
hoelzl@50104
   499
    unfolding real_scaleR_def .
wenzelm@53410
   500
qed
wenzelm@53410
   501
lp15@62463
   502
lemma has_integral_neg: "(f has_integral k) s \<Longrightarrow> ((\<lambda>x. -(f x)) has_integral -k) s"
lp15@60396
   503
  by (drule_tac c="-1" in has_integral_cmul) auto
wenzelm@53410
   504
wenzelm@53410
   505
lemma has_integral_add:
immler@56188
   506
  fixes f :: "'n::euclidean_space \<Rightarrow> 'a::real_normed_vector"
wenzelm@53410
   507
  assumes "(f has_integral k) s"
wenzelm@53410
   508
    and "(g has_integral l) s"
himmelma@35172
   509
  shows "((\<lambda>x. f x + g x) has_integral (k + l)) s"
wenzelm@53410
   510
proof -
hoelzl@63944
   511
  have lem: "(f has_integral k) (cbox a b) \<Longrightarrow> (g has_integral l) (cbox a b) \<Longrightarrow>
hoelzl@63944
   512
    ((\<lambda>x. f x + g x) has_integral (k + l)) (cbox a b)"
wenzelm@61165
   513
    for f :: "'n \<Rightarrow> 'a" and g a b k l
hoelzl@63944
   514
    unfolding has_integral_cbox
nipkow@64267
   515
    by (simp add: split_beta' scaleR_add_right sum.distrib[abs_def] tendsto_add)
wenzelm@53410
   516
  {
immler@56188
   517
    presume "\<not> (\<exists>a b. s = cbox a b) \<Longrightarrow> ?thesis"
wenzelm@53410
   518
    then show ?thesis
lp15@60396
   519
      using assms lem by force
wenzelm@53410
   520
  }
immler@56188
   521
  assume as: "\<not> (\<exists>a b. s = cbox a b)"
wenzelm@53410
   522
  then show ?thesis
wenzelm@61166
   523
  proof (subst has_integral_alt, clarsimp, goal_cases)
wenzelm@61165
   524
    case (1 e)
wenzelm@61165
   525
    then have *: "e / 2 > 0"
wenzelm@53410
   526
      by auto
wenzelm@55751
   527
    from has_integral_altD[OF assms(1) as *]
wenzelm@55751
   528
    obtain B1 where B1:
wenzelm@55751
   529
        "0 < B1"
immler@56188
   530
        "\<And>a b. ball 0 B1 \<subseteq> cbox a b \<Longrightarrow>
immler@56188
   531
          \<exists>z. ((\<lambda>x. if x \<in> s then f x else 0) has_integral z) (cbox a b) \<and> norm (z - k) < e / 2"
wenzelm@55751
   532
      by blast
wenzelm@55751
   533
    from has_integral_altD[OF assms(2) as *]
wenzelm@55751
   534
    obtain B2 where B2:
wenzelm@55751
   535
        "0 < B2"
immler@56188
   536
        "\<And>a b. ball 0 B2 \<subseteq> (cbox a b) \<Longrightarrow>
immler@56188
   537
          \<exists>z. ((\<lambda>x. if x \<in> s then g x else 0) has_integral z) (cbox a b) \<and> norm (z - l) < e / 2"
wenzelm@55751
   538
      by blast
wenzelm@53410
   539
    show ?case
lp15@60396
   540
    proof (rule_tac x="max B1 B2" in exI, clarsimp simp add: max.strict_coboundedI1 B1)
wenzelm@53410
   541
      fix a b
immler@56188
   542
      assume "ball 0 (max B1 B2) \<subseteq> cbox a (b::'n)"
immler@56188
   543
      then have *: "ball 0 B1 \<subseteq> cbox a (b::'n)" "ball 0 B2 \<subseteq> cbox a (b::'n)"
wenzelm@53410
   544
        by auto
wenzelm@53410
   545
      obtain w where w:
immler@56188
   546
        "((\<lambda>x. if x \<in> s then f x else 0) has_integral w) (cbox a b)"
wenzelm@53410
   547
        "norm (w - k) < e / 2"
wenzelm@53410
   548
        using B1(2)[OF *(1)] by blast
wenzelm@53410
   549
      obtain z where z:
immler@56188
   550
        "((\<lambda>x. if x \<in> s then g x else 0) has_integral z) (cbox a b)"
wenzelm@53410
   551
        "norm (z - l) < e / 2"
wenzelm@53410
   552
        using B2(2)[OF *(2)] by blast
wenzelm@53410
   553
      have *: "\<And>x. (if x \<in> s then f x + g x else 0) =
wenzelm@53410
   554
        (if x \<in> s then f x else 0) + (if x \<in> s then g x else 0)"
wenzelm@53410
   555
        by auto
immler@56188
   556
      show "\<exists>z. ((\<lambda>x. if x \<in> s then f x + g x else 0) has_integral z) (cbox a b) \<and> norm (z - (k + l)) < e"
wenzelm@53410
   557
        apply (rule_tac x="w + z" in exI)
lp15@60396
   558
        apply (simp add: lem[OF w(1) z(1), unfolded *[symmetric]])
wenzelm@53410
   559
        using norm_triangle_ineq[of "w - k" "z - l"] w(2) z(2)
wenzelm@53410
   560
        apply (auto simp add: field_simps)
wenzelm@53410
   561
        done
wenzelm@53410
   562
    qed
wenzelm@53410
   563
  qed
wenzelm@53410
   564
qed
himmelma@35172
   565
himmelma@35172
   566
lemma has_integral_sub:
wenzelm@53410
   567
  "(f has_integral k) s \<Longrightarrow> (g has_integral l) s \<Longrightarrow>
wenzelm@53410
   568
    ((\<lambda>x. f x - g x) has_integral (k - l)) s"
wenzelm@53410
   569
  using has_integral_add[OF _ has_integral_neg, of f k s g l]
lp15@63469
   570
  by (auto simp: algebra_simps)
wenzelm@53410
   571
lp15@62463
   572
lemma integral_0 [simp]:
immler@56188
   573
  "integral s (\<lambda>x::'n::euclidean_space. 0::'m::real_normed_vector) = 0"
wenzelm@53410
   574
  by (rule integral_unique has_integral_0)+
wenzelm@53410
   575
wenzelm@53410
   576
lemma integral_add: "f integrable_on s \<Longrightarrow> g integrable_on s \<Longrightarrow>
wenzelm@53410
   577
    integral s (\<lambda>x. f x + g x) = integral s f + integral s g"
lp15@60396
   578
  by (rule integral_unique) (metis integrable_integral has_integral_add)
wenzelm@53410
   579
lp15@62463
   580
lemma integral_cmul [simp]: "integral s (\<lambda>x. c *\<^sub>R f x) = c *\<^sub>R integral s f"
lp15@62463
   581
proof (cases "f integrable_on s \<or> c = 0")
lp15@62463
   582
  case True with has_integral_cmul show ?thesis by force
lp15@62463
   583
next
lp15@62463
   584
  case False then have "~ (\<lambda>x. c *\<^sub>R f x) integrable_on s"
lp15@62463
   585
    using has_integral_cmul [of "(\<lambda>x. c *\<^sub>R f x)" _ s "inverse c"]
lp15@62463
   586
    by force
lp15@62463
   587
  with False show ?thesis by (simp add: not_integrable_integral)
lp15@62463
   588
qed
lp15@62463
   589
lp15@62463
   590
lemma integral_neg [simp]: "integral s (\<lambda>x. - f x) = - integral s f"
lp15@62463
   591
proof (cases "f integrable_on s")
lp15@62463
   592
  case True then show ?thesis
lp15@62463
   593
    by (simp add: has_integral_neg integrable_integral integral_unique)
lp15@62463
   594
next
lp15@62463
   595
  case False then have "~ (\<lambda>x. - f x) integrable_on s"
lp15@62463
   596
    using has_integral_neg [of "(\<lambda>x. - f x)" _ s ]
lp15@62463
   597
    by force
lp15@62463
   598
  with False show ?thesis by (simp add: not_integrable_integral)
lp15@62463
   599
qed
wenzelm@53410
   600
lp15@61806
   601
lemma integral_diff: "f integrable_on s \<Longrightarrow> g integrable_on s \<Longrightarrow>
wenzelm@53410
   602
    integral s (\<lambda>x. f x - g x) = integral s f - integral s g"
lp15@60396
   603
  by (rule integral_unique) (metis integrable_integral has_integral_sub)
himmelma@35172
   604
himmelma@35172
   605
lemma integrable_0: "(\<lambda>x. 0) integrable_on s"
himmelma@35172
   606
  unfolding integrable_on_def using has_integral_0 by auto
himmelma@35172
   607
wenzelm@53410
   608
lemma integrable_add: "f integrable_on s \<Longrightarrow> g integrable_on s \<Longrightarrow> (\<lambda>x. f x + g x) integrable_on s"
himmelma@35172
   609
  unfolding integrable_on_def by(auto intro: has_integral_add)
himmelma@35172
   610
wenzelm@53410
   611
lemma integrable_cmul: "f integrable_on s \<Longrightarrow> (\<lambda>x. c *\<^sub>R f(x)) integrable_on s"
himmelma@35172
   612
  unfolding integrable_on_def by(auto intro: has_integral_cmul)
himmelma@35172
   613
hoelzl@50104
   614
lemma integrable_on_cmult_iff:
wenzelm@53410
   615
  fixes c :: real
wenzelm@53410
   616
  assumes "c \<noteq> 0"
hoelzl@50104
   617
  shows "(\<lambda>x. c * f x) integrable_on s \<longleftrightarrow> f integrable_on s"
wenzelm@60420
   618
  using integrable_cmul[of "\<lambda>x. c * f x" s "1 / c"] integrable_cmul[of f s c] \<open>c \<noteq> 0\<close>
hoelzl@50104
   619
  by auto
hoelzl@50104
   620
lp15@62533
   621
lemma integrable_on_cmult_left:
lp15@62533
   622
  assumes "f integrable_on s"
lp15@62533
   623
  shows "(\<lambda>x. of_real c * f x) integrable_on s"
lp15@62533
   624
    using integrable_cmul[of f s "of_real c"] assms
lp15@62533
   625
    by (simp add: scaleR_conv_of_real)
lp15@62533
   626
wenzelm@53410
   627
lemma integrable_neg: "f integrable_on s \<Longrightarrow> (\<lambda>x. -f(x)) integrable_on s"
himmelma@35172
   628
  unfolding integrable_on_def by(auto intro: has_integral_neg)
himmelma@35172
   629
lp15@61806
   630
lemma integrable_diff:
wenzelm@53410
   631
  "f integrable_on s \<Longrightarrow> g integrable_on s \<Longrightarrow> (\<lambda>x. f x - g x) integrable_on s"
himmelma@35172
   632
  unfolding integrable_on_def by(auto intro: has_integral_sub)
himmelma@35172
   633
himmelma@35172
   634
lemma integrable_linear:
wenzelm@53410
   635
  "f integrable_on s \<Longrightarrow> bounded_linear h \<Longrightarrow> (h \<circ> f) integrable_on s"
himmelma@35172
   636
  unfolding integrable_on_def by(auto intro: has_integral_linear)
himmelma@35172
   637
himmelma@35172
   638
lemma integral_linear:
wenzelm@53410
   639
  "f integrable_on s \<Longrightarrow> bounded_linear h \<Longrightarrow> integral s (h \<circ> f) = h (integral s f)"
lp15@60396
   640
  apply (rule has_integral_unique [where i=s and f = "h \<circ> f"])
lp15@60396
   641
  apply (simp_all add: integrable_integral integrable_linear has_integral_linear )
wenzelm@53410
   642
  done
wenzelm@53410
   643
wenzelm@53410
   644
lemma integral_component_eq[simp]:
immler@56188
   645
  fixes f :: "'n::euclidean_space \<Rightarrow> 'm::euclidean_space"
wenzelm@53410
   646
  assumes "f integrable_on s"
wenzelm@53410
   647
  shows "integral s (\<lambda>x. f x \<bullet> k) = integral s f \<bullet> k"
lp15@63938
   648
  unfolding integral_linear[OF assms(1) bounded_linear_inner_left,unfolded o_def] ..
himmelma@36243
   649
nipkow@64267
   650
lemma has_integral_sum:
wenzelm@53410
   651
  assumes "finite t"
wenzelm@53410
   652
    and "\<forall>a\<in>t. ((f a) has_integral (i a)) s"
nipkow@64267
   653
  shows "((\<lambda>x. sum (\<lambda>a. f a x) t) has_integral (sum i t)) s"
wenzelm@53410
   654
  using assms(1) subset_refl[of t]
wenzelm@53410
   655
proof (induct rule: finite_subset_induct)
wenzelm@53410
   656
  case empty
wenzelm@53410
   657
  then show ?case by auto
wenzelm@53410
   658
next
wenzelm@53410
   659
  case (insert x F)
lp15@60396
   660
  with assms show ?case
lp15@60396
   661
    by (simp add: has_integral_add)
lp15@60396
   662
qed
lp15@60396
   663
nipkow@64267
   664
lemma integral_sum:
lp15@60396
   665
  "\<lbrakk>finite t;  \<forall>a\<in>t. (f a) integrable_on s\<rbrakk> \<Longrightarrow>
nipkow@64267
   666
   integral s (\<lambda>x. sum (\<lambda>a. f a x) t) = sum (\<lambda>a. integral s (f a)) t"
nipkow@64267
   667
  by (auto intro: has_integral_sum integrable_integral)
nipkow@64267
   668
nipkow@64267
   669
lemma integrable_sum:
nipkow@64267
   670
  "\<lbrakk>finite t;  \<forall>a\<in>t. (f a) integrable_on s\<rbrakk> \<Longrightarrow> (\<lambda>x. sum (\<lambda>a. f a x) t) integrable_on s"
wenzelm@53410
   671
  unfolding integrable_on_def
wenzelm@53410
   672
  apply (drule bchoice)
nipkow@64267
   673
  using has_integral_sum[of t]
wenzelm@53410
   674
  apply auto
wenzelm@53410
   675
  done
himmelma@35172
   676
himmelma@35172
   677
lemma has_integral_eq:
lp15@60615
   678
  assumes "\<And>x. x \<in> s \<Longrightarrow> f x = g x"
wenzelm@53410
   679
    and "(f has_integral k) s"
wenzelm@53410
   680
  shows "(g has_integral k) s"
himmelma@35172
   681
  using has_integral_sub[OF assms(2), of "\<lambda>x. f x - g x" 0]
wenzelm@53410
   682
  using has_integral_is_0[of s "\<lambda>x. f x - g x"]
wenzelm@53410
   683
  using assms(1)
wenzelm@53410
   684
  by auto
wenzelm@53410
   685
lp15@60615
   686
lemma integrable_eq: "(\<And>x. x \<in> s \<Longrightarrow> f x = g x) \<Longrightarrow> f integrable_on s \<Longrightarrow> g integrable_on s"
wenzelm@53410
   687
  unfolding integrable_on_def
lp15@60615
   688
  using has_integral_eq[of s f g] has_integral_eq by blast
lp15@60615
   689
lp15@60615
   690
lemma has_integral_cong:
lp15@60615
   691
  assumes "\<And>x. x \<in> s \<Longrightarrow> f x = g x"
lp15@60615
   692
  shows "(f has_integral i) s = (g has_integral i) s"
lp15@60615
   693
  using has_integral_eq[of s f g] has_integral_eq[of s g f] assms
wenzelm@53410
   694
  by auto
wenzelm@53410
   695
lp15@60615
   696
lemma integral_cong:
lp15@60615
   697
  assumes "\<And>x. x \<in> s \<Longrightarrow> f x = g x"
lp15@60615
   698
  shows "integral s f = integral s g"
lp15@60615
   699
  unfolding integral_def
lp15@62463
   700
by (metis (full_types, hide_lams) assms has_integral_cong integrable_eq)
lp15@60615
   701
lp15@62533
   702
lemma integrable_on_cmult_left_iff [simp]:
lp15@62533
   703
  assumes "c \<noteq> 0"
lp15@62533
   704
  shows "(\<lambda>x. of_real c * f x) integrable_on s \<longleftrightarrow> f integrable_on s"
lp15@62533
   705
        (is "?lhs = ?rhs")
lp15@62533
   706
proof
lp15@62533
   707
  assume ?lhs
lp15@62533
   708
  then have "(\<lambda>x. of_real (1 / c) * (of_real c * f x)) integrable_on s"
lp15@62533
   709
    using integrable_cmul[of "\<lambda>x. of_real c * f x" s "1 / of_real c"]
lp15@62533
   710
    by (simp add: scaleR_conv_of_real)
lp15@62533
   711
  then have "(\<lambda>x. (of_real (1 / c) * of_real c * f x)) integrable_on s"
lp15@62533
   712
    by (simp add: algebra_simps)
lp15@62533
   713
  with \<open>c \<noteq> 0\<close> show ?rhs
lp15@62533
   714
    by (metis (no_types, lifting) integrable_eq mult.left_neutral nonzero_divide_eq_eq of_real_1 of_real_mult)
lp15@62533
   715
qed (blast intro: integrable_on_cmult_left)
lp15@62533
   716
lp15@62533
   717
lemma integrable_on_cmult_right:
lp15@62533
   718
  fixes f :: "_ \<Rightarrow> 'b :: {comm_ring,real_algebra_1,real_normed_vector}"
lp15@62533
   719
  assumes "f integrable_on s"
lp15@62533
   720
  shows "(\<lambda>x. f x * of_real c) integrable_on s"
lp15@62533
   721
using integrable_on_cmult_left [OF assms] by (simp add: mult.commute)
lp15@62533
   722
lp15@62533
   723
lemma integrable_on_cmult_right_iff [simp]:
lp15@62533
   724
  fixes f :: "_ \<Rightarrow> 'b :: {comm_ring,real_algebra_1,real_normed_vector}"
lp15@62533
   725
  assumes "c \<noteq> 0"
lp15@62533
   726
  shows "(\<lambda>x. f x * of_real c) integrable_on s \<longleftrightarrow> f integrable_on s"
lp15@62533
   727
using integrable_on_cmult_left_iff [OF assms] by (simp add: mult.commute)
lp15@62533
   728
lp15@62533
   729
lemma integrable_on_cdivide:
lp15@62533
   730
  fixes f :: "_ \<Rightarrow> 'b :: real_normed_field"
lp15@62533
   731
  assumes "f integrable_on s"
lp15@62533
   732
  shows "(\<lambda>x. f x / of_real c) integrable_on s"
lp15@62533
   733
by (simp add: integrable_on_cmult_right divide_inverse assms of_real_inverse [symmetric] del: of_real_inverse)
lp15@62533
   734
lp15@62533
   735
lemma integrable_on_cdivide_iff [simp]:
lp15@62533
   736
  fixes f :: "_ \<Rightarrow> 'b :: real_normed_field"
lp15@62533
   737
  assumes "c \<noteq> 0"
lp15@62533
   738
  shows "(\<lambda>x. f x / of_real c) integrable_on s \<longleftrightarrow> f integrable_on s"
lp15@62533
   739
by (simp add: divide_inverse assms of_real_inverse [symmetric] del: of_real_inverse)
lp15@62533
   740
hoelzl@63944
   741
lemma has_integral_null [intro]: "content(cbox a b) = 0 \<Longrightarrow> (f has_integral 0) (cbox a b)"
hoelzl@63944
   742
  unfolding has_integral_cbox
hoelzl@63944
   743
  using eventually_division_filter_tagged_division[of "cbox a b"]
nipkow@64267
   744
  by (subst tendsto_cong[where g="\<lambda>_. 0"]) (auto elim: eventually_mono intro: sum_content_null)
hoelzl@63944
   745
hoelzl@63944
   746
lemma has_integral_null_real [intro]: "content {a .. b::real} = 0 \<Longrightarrow> (f has_integral 0) {a .. b}"
hoelzl@63944
   747
  by (metis box_real(2) has_integral_null)
immler@56188
   748
immler@56188
   749
lemma has_integral_null_eq[simp]: "content (cbox a b) = 0 \<Longrightarrow> (f has_integral i) (cbox a b) \<longleftrightarrow> i = 0"
lp15@60396
   750
  by (auto simp add: has_integral_null dest!: integral_unique)
wenzelm@53410
   751
lp15@60615
   752
lemma integral_null [simp]: "content (cbox a b) = 0 \<Longrightarrow> integral (cbox a b) f = 0"
lp15@60396
   753
  by (metis has_integral_null integral_unique)
wenzelm@53410
   754
lp15@60615
   755
lemma integrable_on_null [intro]: "content (cbox a b) = 0 \<Longrightarrow> f integrable_on (cbox a b)"
lp15@60615
   756
  by (simp add: has_integral_integrable)
wenzelm@53410
   757
wenzelm@53410
   758
lemma has_integral_empty[intro]: "(f has_integral 0) {}"
lp15@60396
   759
  by (simp add: has_integral_is_0)
wenzelm@53410
   760
wenzelm@53410
   761
lemma has_integral_empty_eq[simp]: "(f has_integral i) {} \<longleftrightarrow> i = 0"
lp15@60396
   762
  by (auto simp add: has_integral_empty has_integral_unique)
wenzelm@53410
   763
wenzelm@53410
   764
lemma integrable_on_empty[intro]: "f integrable_on {}"
wenzelm@53410
   765
  unfolding integrable_on_def by auto
wenzelm@53410
   766
wenzelm@53410
   767
lemma integral_empty[simp]: "integral {} f = 0"
wenzelm@53410
   768
  by (rule integral_unique) (rule has_integral_empty)
wenzelm@53410
   769
wenzelm@53410
   770
lemma has_integral_refl[intro]:
immler@56188
   771
  fixes a :: "'a::euclidean_space"
immler@56188
   772
  shows "(f has_integral 0) (cbox a a)"
wenzelm@53410
   773
    and "(f has_integral 0) {a}"
wenzelm@53410
   774
proof -
immler@56188
   775
  have *: "{a} = cbox a a"
wenzelm@53410
   776
    apply (rule set_eqI)
immler@56188
   777
    unfolding mem_box singleton_iff euclidean_eq_iff[where 'a='a]
wenzelm@53410
   778
    apply safe
wenzelm@53410
   779
    prefer 3
wenzelm@53410
   780
    apply (erule_tac x=b in ballE)
wenzelm@53410
   781
    apply (auto simp add: field_simps)
wenzelm@53410
   782
    done
immler@56188
   783
  show "(f has_integral 0) (cbox a a)" "(f has_integral 0) {a}"
wenzelm@53410
   784
    unfolding *
wenzelm@53410
   785
    apply (rule_tac[!] has_integral_null)
wenzelm@53410
   786
    unfolding content_eq_0_interior
immler@56188
   787
    unfolding interior_cbox
immler@56188
   788
    using box_sing
immler@56188
   789
    apply auto
immler@56188
   790
    done
immler@56188
   791
qed
immler@56188
   792
immler@56188
   793
lemma integrable_on_refl[intro]: "f integrable_on cbox a a"
wenzelm@53410
   794
  unfolding integrable_on_def by auto
wenzelm@53410
   795
paulson@60762
   796
lemma integral_refl [simp]: "integral (cbox a a) f = 0"
wenzelm@53410
   797
  by (rule integral_unique) auto
wenzelm@53410
   798
paulson@60762
   799
lemma integral_singleton [simp]: "integral {a} f = 0"
paulson@60762
   800
  by auto
paulson@60762
   801
immler@61915
   802
lemma integral_blinfun_apply:
immler@61915
   803
  assumes "f integrable_on s"
immler@61915
   804
  shows "integral s (\<lambda>x. blinfun_apply h (f x)) = blinfun_apply h (integral s f)"
immler@61915
   805
  by (subst integral_linear[symmetric, OF assms blinfun.bounded_linear_right]) (simp add: o_def)
immler@61915
   806
immler@61915
   807
lemma blinfun_apply_integral:
immler@61915
   808
  assumes "f integrable_on s"
immler@61915
   809
  shows "blinfun_apply (integral s f) x = integral s (\<lambda>y. blinfun_apply (f y) x)"
immler@61915
   810
  by (metis (no_types, lifting) assms blinfun.prod_left.rep_eq integral_blinfun_apply integral_cong)
immler@61915
   811
eberlm@63295
   812
lemma has_integral_componentwise_iff:
eberlm@63295
   813
  fixes f :: "'a :: euclidean_space \<Rightarrow> 'b :: euclidean_space"
eberlm@63295
   814
  shows "(f has_integral y) A \<longleftrightarrow> (\<forall>b\<in>Basis. ((\<lambda>x. f x \<bullet> b) has_integral (y \<bullet> b)) A)"
eberlm@63295
   815
proof safe
eberlm@63295
   816
  fix b :: 'b assume "(f has_integral y) A"
lp15@63938
   817
  from has_integral_linear[OF this(1) bounded_linear_inner_left, of b]
eberlm@63295
   818
    show "((\<lambda>x. f x \<bullet> b) has_integral (y \<bullet> b)) A" by (simp add: o_def)
eberlm@63295
   819
next
eberlm@63295
   820
  assume "(\<forall>b\<in>Basis. ((\<lambda>x. f x \<bullet> b) has_integral (y \<bullet> b)) A)"
eberlm@63295
   821
  hence "\<forall>b\<in>Basis. (((\<lambda>x. x *\<^sub>R b) \<circ> (\<lambda>x. f x \<bullet> b)) has_integral ((y \<bullet> b) *\<^sub>R b)) A"
eberlm@63295
   822
    by (intro ballI has_integral_linear) (simp_all add: bounded_linear_scaleR_left)
eberlm@63295
   823
  hence "((\<lambda>x. \<Sum>b\<in>Basis. (f x \<bullet> b) *\<^sub>R b) has_integral (\<Sum>b\<in>Basis. (y \<bullet> b) *\<^sub>R b)) A"
nipkow@64267
   824
    by (intro has_integral_sum) (simp_all add: o_def)
eberlm@63295
   825
  thus "(f has_integral y) A" by (simp add: euclidean_representation)
eberlm@63295
   826
qed
eberlm@63295
   827
eberlm@63295
   828
lemma has_integral_componentwise:
eberlm@63295
   829
  fixes f :: "'a :: euclidean_space \<Rightarrow> 'b :: euclidean_space"
eberlm@63295
   830
  shows "(\<And>b. b \<in> Basis \<Longrightarrow> ((\<lambda>x. f x \<bullet> b) has_integral (y \<bullet> b)) A) \<Longrightarrow> (f has_integral y) A"
eberlm@63295
   831
  by (subst has_integral_componentwise_iff) blast
eberlm@63295
   832
eberlm@63295
   833
lemma integrable_componentwise_iff:
eberlm@63295
   834
  fixes f :: "'a :: euclidean_space \<Rightarrow> 'b :: euclidean_space"
eberlm@63295
   835
  shows "f integrable_on A \<longleftrightarrow> (\<forall>b\<in>Basis. (\<lambda>x. f x \<bullet> b) integrable_on A)"
eberlm@63295
   836
proof
eberlm@63295
   837
  assume "f integrable_on A"
eberlm@63295
   838
  then obtain y where "(f has_integral y) A" by (auto simp: integrable_on_def)
eberlm@63295
   839
  hence "(\<forall>b\<in>Basis. ((\<lambda>x. f x \<bullet> b) has_integral (y \<bullet> b)) A)"
eberlm@63295
   840
    by (subst (asm) has_integral_componentwise_iff)
eberlm@63295
   841
  thus "(\<forall>b\<in>Basis. (\<lambda>x. f x \<bullet> b) integrable_on A)" by (auto simp: integrable_on_def)
eberlm@63295
   842
next
eberlm@63295
   843
  assume "(\<forall>b\<in>Basis. (\<lambda>x. f x \<bullet> b) integrable_on A)"
eberlm@63295
   844
  then obtain y where "\<forall>b\<in>Basis. ((\<lambda>x. f x \<bullet> b) has_integral y b) A"
eberlm@63295
   845
    unfolding integrable_on_def by (subst (asm) bchoice_iff) blast
eberlm@63295
   846
  hence "\<forall>b\<in>Basis. (((\<lambda>x. x *\<^sub>R b) \<circ> (\<lambda>x. f x \<bullet> b)) has_integral (y b *\<^sub>R b)) A"
eberlm@63295
   847
    by (intro ballI has_integral_linear) (simp_all add: bounded_linear_scaleR_left)
eberlm@63295
   848
  hence "((\<lambda>x. \<Sum>b\<in>Basis. (f x \<bullet> b) *\<^sub>R b) has_integral (\<Sum>b\<in>Basis. y b *\<^sub>R b)) A"
nipkow@64267
   849
    by (intro has_integral_sum) (simp_all add: o_def)
eberlm@63295
   850
  thus "f integrable_on A" by (auto simp: integrable_on_def o_def euclidean_representation)
eberlm@63295
   851
qed
eberlm@63295
   852
eberlm@63295
   853
lemma integrable_componentwise:
eberlm@63295
   854
  fixes f :: "'a :: euclidean_space \<Rightarrow> 'b :: euclidean_space"
eberlm@63295
   855
  shows "(\<And>b. b \<in> Basis \<Longrightarrow> (\<lambda>x. f x \<bullet> b) integrable_on A) \<Longrightarrow> f integrable_on A"
eberlm@63295
   856
  by (subst integrable_componentwise_iff) blast
eberlm@63295
   857
eberlm@63295
   858
lemma integral_componentwise:
eberlm@63295
   859
  fixes f :: "'a :: euclidean_space \<Rightarrow> 'b :: euclidean_space"
eberlm@63295
   860
  assumes "f integrable_on A"
eberlm@63295
   861
  shows "integral A f = (\<Sum>b\<in>Basis. integral A (\<lambda>x. (f x \<bullet> b) *\<^sub>R b))"
eberlm@63295
   862
proof -
eberlm@63295
   863
  from assms have integrable: "\<forall>b\<in>Basis. (\<lambda>x. x *\<^sub>R b) \<circ> (\<lambda>x. (f x \<bullet> b)) integrable_on A"
eberlm@63295
   864
    by (subst (asm) integrable_componentwise_iff, intro integrable_linear ballI)
eberlm@63295
   865
       (simp_all add: bounded_linear_scaleR_left)
eberlm@63295
   866
  have "integral A f = integral A (\<lambda>x. \<Sum>b\<in>Basis. (f x \<bullet> b) *\<^sub>R b)"
eberlm@63295
   867
    by (simp add: euclidean_representation)
eberlm@63295
   868
  also from integrable have "\<dots> = (\<Sum>a\<in>Basis. integral A (\<lambda>x. (f x \<bullet> a) *\<^sub>R a))"
nipkow@64267
   869
    by (subst integral_sum) (simp_all add: o_def)
eberlm@63295
   870
  finally show ?thesis .
eberlm@63295
   871
qed
eberlm@63295
   872
eberlm@63295
   873
lemma integrable_component:
eberlm@63295
   874
  "f integrable_on A \<Longrightarrow> (\<lambda>x. f x \<bullet> (y :: 'b :: euclidean_space)) integrable_on A"
lp15@63938
   875
  by (drule integrable_linear[OF _ bounded_linear_inner_left[of y]]) (simp add: o_def)
eberlm@63295
   876
eberlm@63295
   877
himmelma@35172
   878
wenzelm@60420
   879
subsection \<open>Cauchy-type criterion for integrability.\<close>
himmelma@35172
   880
hoelzl@37489
   881
(* XXXXXXX *)
wenzelm@53442
   882
lemma integrable_cauchy:
immler@56188
   883
  fixes f :: "'n::euclidean_space \<Rightarrow> 'a::{real_normed_vector,complete_space}"
immler@56188
   884
  shows "f integrable_on cbox a b \<longleftrightarrow>
hoelzl@63944
   885
    (\<forall>e>0. \<exists>d. gauge d \<and>
immler@56188
   886
      (\<forall>p1 p2. p1 tagged_division_of (cbox a b) \<and> d fine p1 \<and>
immler@56188
   887
        p2 tagged_division_of (cbox a b) \<and> d fine p2 \<longrightarrow>
hoelzl@63944
   888
        norm ((\<Sum>(x,k)\<in>p1. content k *\<^sub>R f x) - (\<Sum>(x,k)\<in>p2. content k *\<^sub>R f x)) < e))"
wenzelm@53442
   889
  (is "?l = (\<forall>e>0. \<exists>d. ?P e d)")
wenzelm@53442
   890
proof
wenzelm@53442
   891
  assume ?l
himmelma@35172
   892
  then guess y unfolding integrable_on_def has_integral .. note y=this
wenzelm@53442
   893
  show "\<forall>e>0. \<exists>d. ?P e d"
wenzelm@61166
   894
  proof (clarify, goal_cases)
wenzelm@61165
   895
    case (1 e)
wenzelm@53442
   896
    then have "e/2 > 0" by auto
wenzelm@53494
   897
    then guess d
wenzelm@53494
   898
      apply -
wenzelm@53494
   899
      apply (drule y[rule_format])
wenzelm@53494
   900
      apply (elim exE conjE)
wenzelm@53494
   901
      done
wenzelm@53494
   902
    note d=this[rule_format]
wenzelm@53442
   903
    show ?case
lp15@60396
   904
    proof (rule_tac x=d in exI, clarsimp simp: d)
wenzelm@53442
   905
      fix p1 p2
immler@56188
   906
      assume as: "p1 tagged_division_of (cbox a b)" "d fine p1"
lp15@60396
   907
                 "p2 tagged_division_of (cbox a b)" "d fine p2"
himmelma@35172
   908
      show "norm ((\<Sum>(x, k)\<in>p1. content k *\<^sub>R f x) - (\<Sum>(x, k)\<in>p2. content k *\<^sub>R f x)) < e"
wenzelm@53442
   909
        apply (rule dist_triangle_half_l[where y=y,unfolded dist_norm])
himmelma@35172
   910
        using d(2)[OF conjI[OF as(1-2)]] d(2)[OF conjI[OF as(3-4)]] .
wenzelm@53442
   911
    qed
wenzelm@53442
   912
  qed
wenzelm@53442
   913
next
wenzelm@53442
   914
  assume "\<forall>e>0. \<exists>d. ?P e d"
lp15@60487
   915
  then have "\<forall>n::nat. \<exists>d. ?P (inverse(of_nat (n + 1))) d"
wenzelm@53442
   916
    by auto
himmelma@35172
   917
  from choice[OF this] guess d .. note d=conjunctD2[OF this[rule_format],rule_format]
wenzelm@53442
   918
  have "\<And>n. gauge (\<lambda>x. \<Inter>{d i x |i. i \<in> {0..n}})"
wenzelm@53442
   919
    apply (rule gauge_inters)
wenzelm@53442
   920
    using d(1)
wenzelm@53442
   921
    apply auto
wenzelm@53442
   922
    done
immler@56188
   923
  then have "\<forall>n. \<exists>p. p tagged_division_of (cbox a b) \<and> (\<lambda>x. \<Inter>{d i x |i. i \<in> {0..n}}) fine p"
lp15@60425
   924
    by (meson fine_division_exists)
himmelma@35172
   925
  from choice[OF this] guess p .. note p = conjunctD2[OF this[rule_format]]
wenzelm@53442
   926
  have dp: "\<And>i n. i\<le>n \<Longrightarrow> d i fine p n"
wenzelm@53442
   927
    using p(2) unfolding fine_inters by auto
nipkow@64267
   928
  have "Cauchy (\<lambda>n. sum (\<lambda>(x,k). content k *\<^sub>R (f x)) (p n))"
wenzelm@61166
   929
  proof (rule CauchyI, goal_cases)
wenzelm@61165
   930
    case (1 e)
lp15@62623
   931
    then guess N unfolding real_arch_inverse[of e] .. note N=this
wenzelm@53442
   932
    show ?case
wenzelm@53442
   933
      apply (rule_tac x=N in exI)
lp15@60425
   934
    proof clarify
wenzelm@53442
   935
      fix m n
wenzelm@53442
   936
      assume mn: "N \<le> m" "N \<le> n"
wenzelm@53442
   937
      have *: "N = (N - 1) + 1" using N by auto
himmelma@35172
   938
      show "norm ((\<Sum>(x, k)\<in>p m. content k *\<^sub>R f x) - (\<Sum>(x, k)\<in>p n. content k *\<^sub>R f x)) < e"
wenzelm@53442
   939
        apply (rule less_trans[OF _ N[THEN conjunct2,THEN conjunct2]])
wenzelm@53442
   940
        apply(subst *)
lp15@61609
   941
        using dp p(1) mn d(2) by auto
wenzelm@53442
   942
    qed
wenzelm@53442
   943
  qed
lp15@64287
   944
  then guess y unfolding convergent_eq_Cauchy[symmetric] .. note y=this[THEN LIMSEQ_D]
wenzelm@53442
   945
  show ?l
wenzelm@53442
   946
    unfolding integrable_on_def has_integral
lp15@60425
   947
  proof (rule_tac x=y in exI, clarify)
wenzelm@53442
   948
    fix e :: real
wenzelm@53442
   949
    assume "e>0"
lp15@60615
   950
    then have *:"e/2 > 0" by auto
lp15@62623
   951
    then guess N1 unfolding real_arch_inverse[of "e/2"] .. note N1=this
wenzelm@53442
   952
    then have N1': "N1 = N1 - 1 + 1"
wenzelm@53442
   953
      by auto
himmelma@35172
   954
    guess N2 using y[OF *] .. note N2=this
lp15@60425
   955
    have "gauge (d (N1 + N2))"
lp15@60425
   956
      using d by auto
lp15@60425
   957
    moreover
lp15@60425
   958
    {
wenzelm@53442
   959
      fix q
immler@56188
   960
      assume as: "q tagged_division_of (cbox a b)" "d (N1 + N2) fine q"
lp15@60487
   961
      have *: "inverse (of_nat (N1 + N2 + 1)) < e / 2"
wenzelm@53442
   962
        apply (rule less_trans)
wenzelm@53442
   963
        using N1
wenzelm@53442
   964
        apply auto
wenzelm@53442
   965
        done
lp15@60425
   966
      have "norm ((\<Sum>(x, k)\<in>q. content k *\<^sub>R f x) - y) < e"
wenzelm@53442
   967
        apply (rule norm_triangle_half_r)
wenzelm@53442
   968
        apply (rule less_trans[OF _ *])
wenzelm@53442
   969
        apply (subst N1', rule d(2)[of "p (N1+N2)"])
lp15@60615
   970
        using N1' as(1) as(2) dp
wenzelm@61222
   971
        apply (simp add: \<open>\<forall>x. p x tagged_division_of cbox a b \<and> (\<lambda>xa. \<Inter>{d i xa |i. i \<in> {0..x}}) fine p x\<close>)
lp15@60425
   972
        using N2 le_add2 by blast
lp15@60425
   973
    }
lp15@60425
   974
    ultimately show "\<exists>d. gauge d \<and>
lp15@60425
   975
      (\<forall>p. p tagged_division_of (cbox a b) \<and> d fine p \<longrightarrow>
lp15@60425
   976
        norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - y) < e)"
lp15@60425
   977
      by (rule_tac x="d (N1 + N2)" in exI) auto
wenzelm@53442
   978
  qed
wenzelm@53442
   979
qed
wenzelm@53442
   980
himmelma@35172
   981
wenzelm@60420
   982
subsection \<open>Additivity of integral on abutting intervals.\<close>
himmelma@35172
   983
hoelzl@63957
   984
lemma tagged_division_split_left_inj_content:
lp15@60425
   985
  assumes d: "d tagged_division_of i"
hoelzl@63957
   986
    and "(x1, k1) \<in> d" "(x2, k2) \<in> d" "k1 \<noteq> k2" "k1 \<inter> {x. x\<bullet>k \<le> c} = k2 \<inter> {x. x\<bullet>k \<le> c}" "k \<in> Basis"
wenzelm@53443
   987
  shows "content (k1 \<inter> {x. x\<bullet>k \<le> c}) = 0"
wenzelm@53443
   988
proof -
hoelzl@63957
   989
  from tagged_division_ofD(4)[OF d \<open>(x1, k1) \<in> d\<close>] obtain a b where k1: "k1 = cbox a b"
hoelzl@63957
   990
    by auto
wenzelm@53443
   991
  show ?thesis
hoelzl@63957
   992
    unfolding k1 interval_split[OF \<open>k \<in> Basis\<close>]
hoelzl@63957
   993
    unfolding content_eq_0_interior
hoelzl@63957
   994
    unfolding interval_split[OF \<open>k \<in> Basis\<close>, symmetric] k1[symmetric]
hoelzl@63957
   995
    by (rule tagged_division_split_left_inj[OF assms])
wenzelm@53443
   996
qed
wenzelm@53443
   997
hoelzl@63957
   998
lemma tagged_division_split_right_inj_content:
lp15@60425
   999
  assumes d: "d tagged_division_of i"
hoelzl@63957
  1000
    and "(x1, k1) \<in> d" "(x2, k2) \<in> d" "k1 \<noteq> k2" "k1 \<inter> {x. x\<bullet>k \<ge> c} = k2 \<inter> {x. x\<bullet>k \<ge> c}" "k \<in> Basis"
wenzelm@53494
  1001
  shows "content (k1 \<inter> {x. x\<bullet>k \<ge> c}) = 0"
wenzelm@53443
  1002
proof -
hoelzl@63957
  1003
  from tagged_division_ofD(4)[OF d \<open>(x1, k1) \<in> d\<close>] obtain a b where k1: "k1 = cbox a b"
hoelzl@63957
  1004
    by auto
wenzelm@53443
  1005
  show ?thesis
hoelzl@63957
  1006
    unfolding k1 interval_split[OF \<open>k \<in> Basis\<close>]
hoelzl@63957
  1007
    unfolding content_eq_0_interior
hoelzl@63957
  1008
    unfolding interval_split[OF \<open>k \<in> Basis\<close>, symmetric] k1[symmetric]
hoelzl@63957
  1009
    by (rule tagged_division_split_right_inj[OF assms])
wenzelm@53443
  1010
qed
himmelma@35172
  1011
wenzelm@53468
  1012
lemma has_integral_split:
immler@56188
  1013
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::real_normed_vector"
lp15@60435
  1014
  assumes fi: "(f has_integral i) (cbox a b \<inter> {x. x\<bullet>k \<le> c})"
lp15@60435
  1015
      and fj: "(f has_integral j) (cbox a b \<inter> {x. x\<bullet>k \<ge> c})"
lp15@60435
  1016
      and k: "k \<in> Basis"
immler@56188
  1017
  shows "(f has_integral (i + j)) (cbox a b)"
wenzelm@61166
  1018
proof (unfold has_integral, rule, rule, goal_cases)
wenzelm@61165
  1019
  case (1 e)
wenzelm@53468
  1020
  then have e: "e/2 > 0"
wenzelm@53468
  1021
    by auto
lp15@60615
  1022
    obtain d1
lp15@60435
  1023
    where d1: "gauge d1"
lp15@60615
  1024
      and d1norm:
lp15@60435
  1025
        "\<And>p. \<lbrakk>p tagged_division_of cbox a b \<inter> {x. x \<bullet> k \<le> c};
lp15@60435
  1026
               d1 fine p\<rbrakk> \<Longrightarrow> norm ((\<Sum>(x, k) \<in> p. content k *\<^sub>R f x) - i) < e / 2"
lp15@60435
  1027
       apply (rule has_integralD[OF fi[unfolded interval_split[OF k]] e])
lp15@60435
  1028
       apply (simp add: interval_split[symmetric] k)
lp15@60435
  1029
       done
lp15@60615
  1030
    obtain d2
lp15@60435
  1031
    where d2: "gauge d2"
lp15@60615
  1032
      and d2norm:
lp15@60435
  1033
        "\<And>p. \<lbrakk>p tagged_division_of cbox a b \<inter> {x. c \<le> x \<bullet> k};
lp15@60435
  1034
               d2 fine p\<rbrakk> \<Longrightarrow> norm ((\<Sum>(x, k) \<in> p. content k *\<^sub>R f x) - j) < e / 2"
lp15@60435
  1035
       apply (rule has_integralD[OF fj[unfolded interval_split[OF k]] e])
lp15@60435
  1036
       apply (simp add: interval_split[symmetric] k)
lp15@60435
  1037
       done
wenzelm@61945
  1038
  let ?d = "\<lambda>x. if x\<bullet>k = c then (d1 x \<inter> d2 x) else ball x \<bar>x\<bullet>k - c\<bar> \<inter> d1 x \<inter> d2 x"
lp15@60440
  1039
  have "gauge ?d"
lp15@60440
  1040
    using d1 d2 unfolding gauge_def by auto
lp15@60440
  1041
  then show ?case
lp15@60440
  1042
  proof (rule_tac x="?d" in exI, safe)
wenzelm@53468
  1043
    fix p
immler@56188
  1044
    assume "p tagged_division_of (cbox a b)" "?d fine p"
wenzelm@53494
  1045
    note p = this tagged_division_ofD[OF this(1)]
lp15@60435
  1046
    have xk_le_c: "\<And>x kk. (x, kk) \<in> p \<Longrightarrow> kk \<inter> {x. x\<bullet>k \<le> c} \<noteq> {} \<Longrightarrow> x\<bullet>k \<le> c"
lp15@60435
  1047
    proof -
lp15@60435
  1048
      fix x kk
lp15@60440
  1049
      assume as: "(x, kk) \<in> p" and kk: "kk \<inter> {x. x\<bullet>k \<le> c} \<noteq> {}"
lp15@60435
  1050
      show "x\<bullet>k \<le> c"
lp15@60435
  1051
      proof (rule ccontr)
lp15@60435
  1052
        assume **: "\<not> ?thesis"
lp15@60435
  1053
        from this[unfolded not_le]
lp15@60435
  1054
        have "kk \<subseteq> ball x \<bar>x \<bullet> k - c\<bar>"
lp15@60440
  1055
          using p(2)[unfolded fine_def, rule_format,OF as] by auto
lp15@60440
  1056
        with kk obtain y where y: "y \<in> ball x \<bar>x \<bullet> k - c\<bar>" "y\<bullet>k \<le> c"
lp15@60435
  1057
          by blast
lp15@60615
  1058
        then have "\<bar>x \<bullet> k - y \<bullet> k\<bar> < \<bar>x \<bullet> k - c\<bar>"
lp15@60435
  1059
          using Basis_le_norm[OF k, of "x - y"]
lp15@60440
  1060
          by (auto simp add: dist_norm inner_diff_left intro: le_less_trans)
lp15@60440
  1061
        with y show False
lp15@60440
  1062
          using ** by (auto simp add: field_simps)
lp15@60615
  1063
      qed
lp15@60435
  1064
    qed
lp15@60440
  1065
    have xk_ge_c: "\<And>x kk. (x, kk) \<in> p \<Longrightarrow> kk \<inter> {x. x\<bullet>k \<ge> c} \<noteq> {} \<Longrightarrow> x\<bullet>k \<ge> c"
wenzelm@53468
  1066
    proof -
wenzelm@53468
  1067
      fix x kk
lp15@60440
  1068
      assume as: "(x, kk) \<in> p" and kk: "kk \<inter> {x. x\<bullet>k \<ge> c} \<noteq> {}"
lp15@60435
  1069
      show "x\<bullet>k \<ge> c"
lp15@60435
  1070
      proof (rule ccontr)
lp15@60435
  1071
        assume **: "\<not> ?thesis"
lp15@60435
  1072
        from this[unfolded not_le] have "kk \<subseteq> ball x \<bar>x \<bullet> k - c\<bar>"
lp15@60435
  1073
          using p(2)[unfolded fine_def,rule_format,OF as,unfolded split_conv] by auto
lp15@60440
  1074
        with kk obtain y where y: "y \<in> ball x \<bar>x \<bullet> k - c\<bar>" "y\<bullet>k \<ge> c"
lp15@60435
  1075
          by blast
lp15@60615
  1076
        then have "\<bar>x \<bullet> k - y \<bullet> k\<bar> < \<bar>x \<bullet> k - c\<bar>"
lp15@60435
  1077
          using Basis_le_norm[OF k, of "x - y"]
lp15@60440
  1078
          by (auto simp add: dist_norm inner_diff_left intro: le_less_trans)
lp15@60440
  1079
        with y show False
lp15@60440
  1080
          using ** by (auto simp add: field_simps)
lp15@60435
  1081
      qed
wenzelm@53468
  1082
    qed
wenzelm@53468
  1083
wenzelm@53468
  1084
    have lem1: "\<And>f P Q. (\<forall>x k. (x, k) \<in> {(x, f k) | x k. P x k} \<longrightarrow> Q x k) \<longleftrightarrow>
lp15@60615
  1085
                         (\<forall>x k. P x k \<longrightarrow> Q x (f k))"
lp15@60440
  1086
      by auto
hoelzl@63957
  1087
    have fin_finite: "finite {(x,f k) | x k. (x,k) \<in> s \<and> P x k}"
hoelzl@63957
  1088
      if "finite s" for s and f :: "'a set \<Rightarrow> 'a set" and P :: "'a \<Rightarrow> 'a set \<Rightarrow> bool"
wenzelm@53468
  1089
    proof -
wenzelm@61165
  1090
      from that have "finite ((\<lambda>(x, k). (x, f k)) ` s)"
lp15@60425
  1091
        by auto
wenzelm@61165
  1092
      then show ?thesis
lp15@60425
  1093
        by (rule rev_finite_subset) auto
wenzelm@53468
  1094
    qed
lp15@60435
  1095
    { fix g :: "'a set \<Rightarrow> 'a set"
wenzelm@53468
  1096
      fix i :: "'a \<times> 'a set"
wenzelm@53468
  1097
      assume "i \<in> (\<lambda>(x, k). (x, g k)) ` p - {(x, g k) |x k. (x, k) \<in> p \<and> g k \<noteq> {}}"
wenzelm@53468
  1098
      then obtain x k where xk:
lp15@60435
  1099
              "i = (x, g k)"  "(x, k) \<in> p"
lp15@60435
  1100
              "(x, g k) \<notin> {(x, g k) |x k. (x, k) \<in> p \<and> g k \<noteq> {}}"
lp15@60435
  1101
          by auto
wenzelm@53468
  1102
      have "content (g k) = 0"
wenzelm@53468
  1103
        using xk using content_empty by auto
lp15@60435
  1104
      then have "(\<lambda>(x, k). content k *\<^sub>R f x) i = 0"
wenzelm@53468
  1105
        unfolding xk split_conv by auto
lp15@60435
  1106
    } note [simp] = this
lp15@60435
  1107
    have lem3: "\<And>g :: 'a set \<Rightarrow> 'a set. finite p \<Longrightarrow>
nipkow@64267
  1108
                  sum (\<lambda>(x, k). content k *\<^sub>R f x) {(x,g k) |x k. (x,k) \<in> p \<and> g k \<noteq> {}} =
nipkow@64267
  1109
                  sum (\<lambda>(x, k). content k *\<^sub>R f x) ((\<lambda>(x, k). (x, g k)) ` p)"
nipkow@64267
  1110
      by (rule sum.mono_neutral_left) auto
wenzelm@53468
  1111
    let ?M1 = "{(x, kk \<inter> {x. x\<bullet>k \<le> c}) |x kk. (x, kk) \<in> p \<and> kk \<inter> {x. x\<bullet>k \<le> c} \<noteq> {}}"
lp15@60435
  1112
    have d1_fine: "d1 fine ?M1"
nipkow@62390
  1113
      by (force intro: fineI dest: fineD[OF p(2)] simp add: split: if_split_asm)
wenzelm@53468
  1114
    have "norm ((\<Sum>(x, k)\<in>?M1. content k *\<^sub>R f x) - i) < e/2"
lp15@60435
  1115
    proof (rule d1norm [OF tagged_division_ofI d1_fine])
lp15@60435
  1116
      show "finite ?M1"
lp15@60435
  1117
        by (rule fin_finite p(3))+
immler@56188
  1118
      show "\<Union>{k. \<exists>x. (x, k) \<in> ?M1} = cbox a b \<inter> {x. x\<bullet>k \<le> c}"
wenzelm@53468
  1119
        unfolding p(8)[symmetric] by auto
wenzelm@53468
  1120
      fix x l
wenzelm@53468
  1121
      assume xl: "(x, l) \<in> ?M1"
haftmann@61424
  1122
      then guess x' l' unfolding mem_Collect_eq unfolding prod.inject by (elim exE conjE) note xl'=this
immler@56188
  1123
      show "x \<in> l" "l \<subseteq> cbox a b \<inter> {x. x \<bullet> k \<le> c}"
wenzelm@53468
  1124
        unfolding xl'
wenzelm@53468
  1125
        using p(4-6)[OF xl'(3)] using xl'(4)
lp15@60435
  1126
        using xk_le_c[OF xl'(3-4)] by auto
immler@56188
  1127
      show "\<exists>a b. l = cbox a b"
wenzelm@53468
  1128
        unfolding xl'
wenzelm@53468
  1129
        using p(6)[OF xl'(3)]
wenzelm@53468
  1130
        by (fastforce simp add: interval_split[OF k,where c=c])
wenzelm@53468
  1131
      fix y r
wenzelm@53468
  1132
      let ?goal = "interior l \<inter> interior r = {}"
wenzelm@53468
  1133
      assume yr: "(y, r) \<in> ?M1"
haftmann@61424
  1134
      then guess y' r' unfolding mem_Collect_eq unfolding prod.inject by (elim exE conjE) note yr'=this
wenzelm@53468
  1135
      assume as: "(x, l) \<noteq> (y, r)"
wenzelm@53468
  1136
      show "interior l \<inter> interior r = {}"
wenzelm@53468
  1137
      proof (cases "l' = r' \<longrightarrow> x' = y'")
wenzelm@53468
  1138
        case False
wenzelm@53468
  1139
        then show ?thesis
wenzelm@53468
  1140
          using p(7)[OF xl'(3) yr'(3)] using as unfolding xl' yr' by auto
wenzelm@53468
  1141
      next
wenzelm@53468
  1142
        case True
wenzelm@53468
  1143
        then have "l' \<noteq> r'"
wenzelm@53468
  1144
          using as unfolding xl' yr' by auto
wenzelm@53468
  1145
        then show ?thesis
wenzelm@53468
  1146
          using p(7)[OF xl'(3) yr'(3)] using as unfolding xl' yr' by auto
himmelma@35172
  1147
      qed
himmelma@35172
  1148
    qed
wenzelm@53468
  1149
    moreover
wenzelm@53399
  1150
    let ?M2 = "{(x,kk \<inter> {x. x\<bullet>k \<ge> c}) |x kk. (x,kk) \<in> p \<and> kk \<inter> {x. x\<bullet>k \<ge> c} \<noteq> {}}"
lp15@60435
  1151
    have d2_fine: "d2 fine ?M2"
nipkow@62390
  1152
      by (force intro: fineI dest: fineD[OF p(2)] simp add: split: if_split_asm)
wenzelm@53468
  1153
    have "norm ((\<Sum>(x, k)\<in>?M2. content k *\<^sub>R f x) - j) < e/2"
lp15@60435
  1154
    proof (rule d2norm [OF tagged_division_ofI d2_fine])
lp15@60435
  1155
      show "finite ?M2"
lp15@60435
  1156
        by (rule fin_finite p(3))+
immler@56188
  1157
      show "\<Union>{k. \<exists>x. (x, k) \<in> ?M2} = cbox a b \<inter> {x. x\<bullet>k \<ge> c}"
wenzelm@53468
  1158
        unfolding p(8)[symmetric] by auto
wenzelm@53468
  1159
      fix x l
wenzelm@53468
  1160
      assume xl: "(x, l) \<in> ?M2"
haftmann@61424
  1161
      then guess x' l' unfolding mem_Collect_eq unfolding prod.inject by (elim exE conjE) note xl'=this
immler@56188
  1162
      show "x \<in> l" "l \<subseteq> cbox a b \<inter> {x. x \<bullet> k \<ge> c}"
wenzelm@53468
  1163
        unfolding xl'
lp15@60435
  1164
        using p(4-6)[OF xl'(3)] xl'(4) xk_ge_c[OF xl'(3-4)]
wenzelm@53468
  1165
        by auto
immler@56188
  1166
      show "\<exists>a b. l = cbox a b"
wenzelm@53468
  1167
        unfolding xl'
wenzelm@53468
  1168
        using p(6)[OF xl'(3)]
wenzelm@53468
  1169
        by (fastforce simp add: interval_split[OF k, where c=c])
wenzelm@53468
  1170
      fix y r
wenzelm@53468
  1171
      let ?goal = "interior l \<inter> interior r = {}"
wenzelm@53468
  1172
      assume yr: "(y, r) \<in> ?M2"
haftmann@61424
  1173
      then guess y' r' unfolding mem_Collect_eq unfolding prod.inject by (elim exE conjE) note yr'=this
wenzelm@53468
  1174
      assume as: "(x, l) \<noteq> (y, r)"
wenzelm@53468
  1175
      show "interior l \<inter> interior r = {}"
wenzelm@53468
  1176
      proof (cases "l' = r' \<longrightarrow> x' = y'")
wenzelm@53468
  1177
        case False
wenzelm@53468
  1178
        then show ?thesis
wenzelm@53468
  1179
          using p(7)[OF xl'(3) yr'(3)] using as unfolding xl' yr' by auto
wenzelm@53468
  1180
      next
wenzelm@53468
  1181
        case True
wenzelm@53468
  1182
        then have "l' \<noteq> r'"
wenzelm@53468
  1183
          using as unfolding xl' yr' by auto
wenzelm@53468
  1184
        then show ?thesis
wenzelm@53468
  1185
          using p(7)[OF xl'(3) yr'(3)] using as unfolding xl' yr' by auto
wenzelm@53468
  1186
      qed
wenzelm@53468
  1187
    qed
wenzelm@53468
  1188
    ultimately
himmelma@35172
  1189
    have "norm (((\<Sum>(x, k)\<in>?M1. content k *\<^sub>R f x) - i) + ((\<Sum>(x, k)\<in>?M2. content k *\<^sub>R f x) - j)) < e/2 + e/2"
lp15@60425
  1190
      using norm_add_less by blast
wenzelm@53468
  1191
    also {
lp15@60435
  1192
      have eq0: "\<And>x y. x = (0::real) \<Longrightarrow> x *\<^sub>R (y::'b) = 0"
wenzelm@53468
  1193
        using scaleR_zero_left by auto
lp15@60435
  1194
      have cont_eq: "\<And>g. (\<lambda>(x,l). content l *\<^sub>R f x) \<circ> (\<lambda>(x,l). (x,g l)) = (\<lambda>(x,l). content (g l) *\<^sub>R f x)"
lp15@60435
  1195
        by auto
wenzelm@53468
  1196
      have "((\<Sum>(x, k)\<in>?M1. content k *\<^sub>R f x) - i) + ((\<Sum>(x, k)\<in>?M2. content k *\<^sub>R f x) - j) =
wenzelm@53468
  1197
        (\<Sum>(x, k)\<in>?M1. content k *\<^sub>R f x) + (\<Sum>(x, k)\<in>?M2. content k *\<^sub>R f x) - (i + j)"
wenzelm@53468
  1198
        by auto
hoelzl@50526
  1199
      also have "\<dots> = (\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. x \<bullet> k \<le> c}) *\<^sub>R f x) +
hoelzl@50526
  1200
        (\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. c \<le> x \<bullet> k}) *\<^sub>R f x) - (i + j)"
wenzelm@53468
  1201
        unfolding lem3[OF p(3)]
nipkow@64267
  1202
        by (subst (1 2) sum.reindex_nontrivial[OF p(3)])
hoelzl@63957
  1203
           (auto intro!: k eq0 tagged_division_split_left_inj_content[OF p(1)] tagged_division_split_right_inj_content[OF p(1)]
hoelzl@63957
  1204
                 simp: cont_eq)+
nipkow@64267
  1205
      also note sum.distrib[symmetric]
lp15@60435
  1206
      also have "\<And>x. x \<in> p \<Longrightarrow>
lp15@60435
  1207
                    (\<lambda>(x,ka). content (ka \<inter> {x. x \<bullet> k \<le> c}) *\<^sub>R f x) x +
lp15@60435
  1208
                    (\<lambda>(x,ka). content (ka \<inter> {x. c \<le> x \<bullet> k}) *\<^sub>R f x) x =
lp15@60435
  1209
                    (\<lambda>(x,ka). content ka *\<^sub>R f x) x"
lp15@60435
  1210
      proof clarify
wenzelm@53468
  1211
        fix a b
wenzelm@53468
  1212
        assume "(a, b) \<in> p"
wenzelm@53468
  1213
        from p(6)[OF this] guess u v by (elim exE) note uv=this
wenzelm@53468
  1214
        then show "content (b \<inter> {x. x \<bullet> k \<le> c}) *\<^sub>R f a + content (b \<inter> {x. c \<le> x \<bullet> k}) *\<^sub>R f a =
wenzelm@53468
  1215
          content b *\<^sub>R f a"
wenzelm@53468
  1216
          unfolding scaleR_left_distrib[symmetric]
wenzelm@53468
  1217
          unfolding uv content_split[OF k,of u v c]
wenzelm@53468
  1218
          by auto
wenzelm@53468
  1219
      qed
nipkow@64267
  1220
      note sum.cong [OF _ this]
hoelzl@50526
  1221
      finally have "(\<Sum>(x, k)\<in>{(x, kk \<inter> {x. x \<bullet> k \<le> c}) |x kk. (x, kk) \<in> p \<and> kk \<inter> {x. x \<bullet> k \<le> c} \<noteq> {}}. content k *\<^sub>R f x) - i +
hoelzl@50526
  1222
        ((\<Sum>(x, k)\<in>{(x, kk \<inter> {x. c \<le> x \<bullet> k}) |x kk. (x, kk) \<in> p \<and> kk \<inter> {x. c \<le> x \<bullet> k} \<noteq> {}}. content k *\<^sub>R f x) - j) =
wenzelm@53468
  1223
        (\<Sum>(x, ka)\<in>p. content ka *\<^sub>R f x) - (i + j)"
wenzelm@53468
  1224
        by auto
wenzelm@53468
  1225
    }
wenzelm@53468
  1226
    finally show "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - (i + j)) < e"
wenzelm@53468
  1227
      by auto
wenzelm@53468
  1228
  qed
wenzelm@53468
  1229
qed
wenzelm@53468
  1230
himmelma@35172
  1231
wenzelm@60420
  1232
subsection \<open>A sort of converse, integrability on subintervals.\<close>
himmelma@35172
  1233
wenzelm@53494
  1234
lemma has_integral_separate_sides:
immler@56188
  1235
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::real_normed_vector"
immler@56188
  1236
  assumes "(f has_integral i) (cbox a b)"
wenzelm@53494
  1237
    and "e > 0"
wenzelm@53494
  1238
    and k: "k \<in> Basis"
wenzelm@53494
  1239
  obtains d where "gauge d"
immler@56188
  1240
    "\<forall>p1 p2. p1 tagged_division_of (cbox a b \<inter> {x. x\<bullet>k \<le> c}) \<and> d fine p1 \<and>
immler@56188
  1241
        p2 tagged_division_of (cbox a b \<inter> {x. x\<bullet>k \<ge> c}) \<and> d fine p2 \<longrightarrow>
nipkow@64267
  1242
        norm ((sum (\<lambda>(x,k). content k *\<^sub>R f x) p1 + sum (\<lambda>(x,k). content k *\<^sub>R f x) p2) - i) < e"
wenzelm@53494
  1243
proof -
wenzelm@53494
  1244
  guess d using has_integralD[OF assms(1-2)] . note d=this
lp15@60428
  1245
  { fix p1 p2
immler@56188
  1246
    assume "p1 tagged_division_of (cbox a b) \<inter> {x. x \<bullet> k \<le> c}" "d fine p1"
wenzelm@53494
  1247
    note p1=tagged_division_ofD[OF this(1)] this
immler@56188
  1248
    assume "p2 tagged_division_of (cbox a b) \<inter> {x. c \<le> x \<bullet> k}" "d fine p2"
wenzelm@53494
  1249
    note p2=tagged_division_ofD[OF this(1)] this
himmelma@35172
  1250
    note tagged_division_union_interval[OF p1(7) p2(7)] note p12 = tagged_division_ofD[OF this] this
lp15@60428
  1251
    { fix a b
wenzelm@53494
  1252
      assume ab: "(a, b) \<in> p1 \<inter> p2"
wenzelm@53494
  1253
      have "(a, b) \<in> p1"
wenzelm@53494
  1254
        using ab by auto
lp15@60428
  1255
      with p1 obtain u v where uv: "b = cbox u v" by auto
wenzelm@53494
  1256
      have "b \<subseteq> {x. x\<bullet>k = c}"
wenzelm@53494
  1257
        using ab p1(3)[of a b] p2(3)[of a b] by fastforce
wenzelm@53494
  1258
      moreover
wenzelm@53494
  1259
      have "interior {x::'a. x \<bullet> k = c} = {}"
wenzelm@53494
  1260
      proof (rule ccontr)
wenzelm@53494
  1261
        assume "\<not> ?thesis"
wenzelm@53494
  1262
        then obtain x where x: "x \<in> interior {x::'a. x\<bullet>k = c}"
wenzelm@53494
  1263
          by auto
himmelma@35172
  1264
        then guess e unfolding mem_interior .. note e=this
wenzelm@53494
  1265
        have x: "x\<bullet>k = c"
wenzelm@53494
  1266
          using x interior_subset by fastforce
wenzelm@53494
  1267
        have *: "\<And>i. i \<in> Basis \<Longrightarrow> \<bar>(x - (x + (e / 2) *\<^sub>R k)) \<bullet> i\<bar> = (if i = k then e/2 else 0)"
wenzelm@53494
  1268
          using e k by (auto simp: inner_simps inner_not_same_Basis)
hoelzl@50526
  1269
        have "(\<Sum>i\<in>Basis. \<bar>(x - (x + (e / 2 ) *\<^sub>R k)) \<bullet> i\<bar>) =
lp15@60425
  1270
              (\<Sum>i\<in>Basis. (if i = k then e / 2 else 0))"
nipkow@64267
  1271
          using "*" by (blast intro: sum.cong)
wenzelm@53494
  1272
        also have "\<dots> < e"
nipkow@64267
  1273
          apply (subst sum.delta)
wenzelm@53494
  1274
          using e
wenzelm@53494
  1275
          apply auto
wenzelm@53494
  1276
          done
hoelzl@50526
  1277
        finally have "x + (e/2) *\<^sub>R k \<in> ball x e"
hoelzl@50526
  1278
          unfolding mem_ball dist_norm by(rule le_less_trans[OF norm_le_l1])
wenzelm@53494
  1279
        then have "x + (e/2) *\<^sub>R k \<in> {x. x\<bullet>k = c}"
wenzelm@53494
  1280
          using e by auto
wenzelm@53494
  1281
        then show False
wenzelm@53494
  1282
          unfolding mem_Collect_eq using e x k by (auto simp: inner_simps)
wenzelm@53494
  1283
      qed
wenzelm@53494
  1284
      ultimately have "content b = 0"
wenzelm@53494
  1285
        unfolding uv content_eq_0_interior
lp15@60428
  1286
        using interior_mono by blast
lp15@60428
  1287
      then have "content b *\<^sub>R f a = 0"
wenzelm@53494
  1288
        by auto
lp15@60428
  1289
    }
lp15@60428
  1290
    then have "norm ((\<Sum>(x, k)\<in>p1. content k *\<^sub>R f x) + (\<Sum>(x, k)\<in>p2. content k *\<^sub>R f x) - i) =
lp15@60428
  1291
               norm ((\<Sum>(x, k)\<in>p1 \<union> p2. content k *\<^sub>R f x) - i)"
nipkow@64267
  1292
      by (subst sum.union_inter_neutral) (auto simp: p1 p2)
wenzelm@53494
  1293
    also have "\<dots> < e"
wenzelm@53494
  1294
      by (rule k d(2) p12 fine_union p1 p2)+
lp15@60428
  1295
    finally have "norm ((\<Sum>(x, k)\<in>p1. content k *\<^sub>R f x) + (\<Sum>(x, k)\<in>p2. content k *\<^sub>R f x) - i) < e" .
lp15@60615
  1296
   }
lp15@60428
  1297
  then show ?thesis
lp15@60428
  1298
    by (auto intro: that[of d] d elim: )
wenzelm@53494
  1299
qed
himmelma@35172
  1300
hoelzl@50526
  1301
lemma integrable_split[intro]:
immler@56188
  1302
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::{real_normed_vector,complete_space}"
immler@56188
  1303
  assumes "f integrable_on cbox a b"
wenzelm@53494
  1304
    and k: "k \<in> Basis"
immler@56188
  1305
  shows "f integrable_on (cbox a b \<inter> {x. x\<bullet>k \<le> c})" (is ?t1)
immler@56188
  1306
    and "f integrable_on (cbox a b \<inter> {x. x\<bullet>k \<ge> c})" (is ?t2)
wenzelm@53494
  1307
proof -
wenzelm@53494
  1308
  guess y using assms(1) unfolding integrable_on_def .. note y=this
wenzelm@63040
  1309
  define b' where "b' = (\<Sum>i\<in>Basis. (if i = k then min (b\<bullet>k) c else b\<bullet>i)*\<^sub>R i)"
wenzelm@63040
  1310
  define a' where "a' = (\<Sum>i\<in>Basis. (if i = k then max (a\<bullet>k) c else a\<bullet>i)*\<^sub>R i)"
wenzelm@53494
  1311
  show ?t1 ?t2
wenzelm@53494
  1312
    unfolding interval_split[OF k] integrable_cauchy
wenzelm@53494
  1313
    unfolding interval_split[symmetric,OF k]
wenzelm@53494
  1314
  proof (rule_tac[!] allI impI)+
wenzelm@53494
  1315
    fix e :: real
wenzelm@53494
  1316
    assume "e > 0"
wenzelm@53494
  1317
    then have "e/2>0"
wenzelm@53494
  1318
      by auto
hoelzl@37489
  1319
    from has_integral_separate_sides[OF y this k,of c] guess d . note d=this[rule_format]
immler@56188
  1320
    let ?P = "\<lambda>A. \<exists>d. gauge d \<and> (\<forall>p1 p2. p1 tagged_division_of (cbox a b) \<inter> A \<and> d fine p1 \<and>
immler@56188
  1321
      p2 tagged_division_of (cbox a b) \<inter> A \<and> d fine p2 \<longrightarrow>
hoelzl@37489
  1322
      norm ((\<Sum>(x, k)\<in>p1. content k *\<^sub>R f x) - (\<Sum>(x, k)\<in>p2. content k *\<^sub>R f x)) < e)"
wenzelm@53494
  1323
    show "?P {x. x \<bullet> k \<le> c}"
lp15@60428
  1324
    proof (rule_tac x=d in exI, clarsimp simp add: d)
wenzelm@53494
  1325
      fix p1 p2
lp15@60428
  1326
      assume as: "p1 tagged_division_of (cbox a b) \<inter> {x. x \<bullet> k \<le> c}" "d fine p1"
lp15@60428
  1327
                 "p2 tagged_division_of (cbox a b) \<inter> {x. x \<bullet> k \<le> c}" "d fine p2"
himmelma@35172
  1328
      show "norm ((\<Sum>(x, k)\<in>p1. content k *\<^sub>R f x) - (\<Sum>(x, k)\<in>p2. content k *\<^sub>R f x)) < e"
lp15@60428
  1329
      proof (rule fine_division_exists[OF d(1), of a' b] )
lp15@60428
  1330
        fix p
lp15@60428
  1331
        assume "p tagged_division_of cbox a' b" "d fine p"
lp15@60428
  1332
        then show ?thesis
lp15@60428
  1333
          using as norm_triangle_half_l[OF d(2)[of p1 p] d(2)[of p2 p]]
lp15@60428
  1334
          unfolding interval_split[OF k] b'_def[symmetric] a'_def[symmetric]
wenzelm@53494
  1335
          by (auto simp add: algebra_simps)
wenzelm@53494
  1336
      qed
wenzelm@53494
  1337
    qed
wenzelm@53494
  1338
    show "?P {x. x \<bullet> k \<ge> c}"
lp15@60428
  1339
    proof (rule_tac x=d in exI, clarsimp simp add: d)
wenzelm@53494
  1340
      fix p1 p2
lp15@60428
  1341
      assume as: "p1 tagged_division_of (cbox a b) \<inter> {x. x \<bullet> k \<ge> c}" "d fine p1"
lp15@60428
  1342
                 "p2 tagged_division_of (cbox a b) \<inter> {x. x \<bullet> k \<ge> c}" "d fine p2"
himmelma@35172
  1343
      show "norm ((\<Sum>(x, k)\<in>p1. content k *\<^sub>R f x) - (\<Sum>(x, k)\<in>p2. content k *\<^sub>R f x)) < e"
lp15@60428
  1344
      proof (rule fine_division_exists[OF d(1), of a b'] )
lp15@60428
  1345
        fix p
lp15@60428
  1346
        assume "p tagged_division_of cbox a b'" "d fine p"
lp15@60428
  1347
        then show ?thesis
lp15@60428
  1348
          using as norm_triangle_half_l[OF d(2)[of p p1] d(2)[of p p2]]
wenzelm@53494
  1349
          unfolding interval_split[OF k] b'_def[symmetric] a'_def[symmetric]
wenzelm@53520
  1350
          by (auto simp add: algebra_simps)
wenzelm@53494
  1351
      qed
wenzelm@53494
  1352
    qed
wenzelm@53494
  1353
  qed
wenzelm@53494
  1354
qed
wenzelm@53494
  1355
wenzelm@53494
  1356
lemma operative_integral:
immler@56188
  1357
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::banach"
haftmann@63659
  1358
  shows "comm_monoid.operative (lift_option op +) (Some 0)
haftmann@63659
  1359
    (\<lambda>i. if f integrable_on i then Some (integral i f) else None)"
haftmann@63659
  1360
proof -
haftmann@63659
  1361
  interpret comm_monoid "lift_option plus" "Some (0::'b)"
haftmann@63659
  1362
    by (rule comm_monoid_lift_option)
haftmann@63659
  1363
      (rule add.comm_monoid_axioms)
haftmann@63659
  1364
  show ?thesis
haftmann@63659
  1365
  proof (unfold operative_def, safe)
haftmann@63659
  1366
    fix a b c
haftmann@63659
  1367
    fix k :: 'a
haftmann@63659
  1368
    assume k: "k \<in> Basis"
haftmann@63659
  1369
    show "(if f integrable_on cbox a b then Some (integral (cbox a b) f) else None) =
haftmann@63659
  1370
          lift_option op + (if f integrable_on cbox a b \<inter> {x. x \<bullet> k \<le> c} then Some (integral (cbox a b \<inter> {x. x \<bullet> k \<le> c}) f) else None)
haftmann@63659
  1371
          (if f integrable_on cbox a b \<inter> {x. c \<le> x \<bullet> k} then Some (integral (cbox a b \<inter> {x. c \<le> x \<bullet> k}) f) else None)"
haftmann@63659
  1372
    proof (cases "f integrable_on cbox a b")
haftmann@63659
  1373
      case True
haftmann@63659
  1374
      with k show ?thesis
haftmann@63659
  1375
        apply (simp add: integrable_split)
haftmann@63659
  1376
        apply (rule integral_unique [OF has_integral_split[OF _ _ k]])
lp15@60440
  1377
        apply (auto intro: integrable_integral)
wenzelm@53494
  1378
        done
haftmann@63659
  1379
    next
haftmann@63659
  1380
    case False
haftmann@63659
  1381
      have "\<not> (f integrable_on cbox a b \<inter> {x. x \<bullet> k \<le> c}) \<or> \<not> ( f integrable_on cbox a b \<inter> {x. c \<le> x \<bullet> k})"
haftmann@63659
  1382
      proof (rule ccontr)
haftmann@63659
  1383
        assume "\<not> ?thesis"
haftmann@63659
  1384
        then have "f integrable_on cbox a b"
haftmann@63659
  1385
          unfolding integrable_on_def
haftmann@63659
  1386
          apply (rule_tac x="integral (cbox a b \<inter> {x. x \<bullet> k \<le> c}) f + integral (cbox a b \<inter> {x. x \<bullet> k \<ge> c}) f" in exI)
haftmann@63659
  1387
          apply (rule has_integral_split[OF _ _ k])
haftmann@63659
  1388
          apply (auto intro: integrable_integral)
haftmann@63659
  1389
          done
haftmann@63659
  1390
        then show False
haftmann@63659
  1391
          using False by auto
haftmann@63659
  1392
      qed
haftmann@63659
  1393
      then show ?thesis
wenzelm@53494
  1394
        using False by auto
wenzelm@53494
  1395
    qed
haftmann@63659
  1396
  next
haftmann@63659
  1397
    fix a b :: 'a
hoelzl@63957
  1398
    assume "box a b = {}"
haftmann@63659
  1399
    then show "(if f integrable_on cbox a b then Some (integral (cbox a b) f) else None) = Some 0"
haftmann@63659
  1400
      using has_integral_null_eq
hoelzl@63957
  1401
      by (auto simp: integrable_on_null content_eq_0_interior)
haftmann@63659
  1402
  qed
wenzelm@53494
  1403
qed
wenzelm@53494
  1404
wenzelm@60420
  1405
subsection \<open>Bounds on the norm of Riemann sums and the integral itself.\<close>
himmelma@35172
  1406
wenzelm@53494
  1407
lemma dsum_bound:
immler@56188
  1408
  assumes "p division_of (cbox a b)"
wenzelm@53494
  1409
    and "norm c \<le> e"
nipkow@64267
  1410
  shows "norm (sum (\<lambda>l. content l *\<^sub>R c) p) \<le> e * content(cbox a b)"
lp15@60467
  1411
proof -
nipkow@64267
  1412
  have sumeq: "(\<Sum>i\<in>p. \<bar>content i\<bar>) = sum content p"
nipkow@64267
  1413
    apply (rule sum.cong)
lp15@60467
  1414
    using assms
lp15@60467
  1415
    apply simp
lp15@60467
  1416
    apply (metis abs_of_nonneg assms(1) content_pos_le division_ofD(4))
lp15@60467
  1417
    done
lp15@60467
  1418
  have e: "0 \<le> e"
lp15@60467
  1419
    using assms(2) norm_ge_zero order_trans by blast
nipkow@64267
  1420
  have "norm (sum (\<lambda>l. content l *\<^sub>R c) p) \<le> (\<Sum>i\<in>p. norm (content i *\<^sub>R c))"
nipkow@64267
  1421
    using norm_sum by blast
lp15@60467
  1422
  also have "...  \<le> e * (\<Sum>i\<in>p. \<bar>content i\<bar>)"
nipkow@64267
  1423
    by (simp add: sum_distrib_left[symmetric] mult.commute assms(2) mult_right_mono sum_nonneg)
lp15@60467
  1424
  also have "... \<le> e * content (cbox a b)"
lp15@60467
  1425
    apply (rule mult_left_mono [OF _ e])
lp15@60467
  1426
    apply (simp add: sumeq)
lp15@60467
  1427
    using additive_content_division assms(1) eq_iff apply blast
lp15@60467
  1428
    done
lp15@60467
  1429
  finally show ?thesis .
lp15@60467
  1430
qed
wenzelm@53494
  1431
wenzelm@53494
  1432
lemma rsum_bound:
lp15@60472
  1433
  assumes p: "p tagged_division_of (cbox a b)"
lp15@60472
  1434
      and "\<forall>x\<in>cbox a b. norm (f x) \<le> e"
nipkow@64267
  1435
    shows "norm (sum (\<lambda>(x,k). content k *\<^sub>R f x) p) \<le> e * content (cbox a b)"
immler@56188
  1436
proof (cases "cbox a b = {}")
lp15@60472
  1437
  case True show ?thesis
lp15@60472
  1438
    using p unfolding True tagged_division_of_trivial by auto
wenzelm@53494
  1439
next
wenzelm@53494
  1440
  case False
lp15@60472
  1441
  then have e: "e \<ge> 0"
lp15@63018
  1442
    by (meson ex_in_conv assms(2) norm_ge_zero order_trans)
nipkow@64267
  1443
  have sum_le: "sum (content \<circ> snd) p \<le> content (cbox a b)"
lp15@60472
  1444
    unfolding additive_content_tagged_division[OF p, symmetric] split_def
lp15@60472
  1445
    by (auto intro: eq_refl)
lp15@60472
  1446
  have con: "\<And>xk. xk \<in> p \<Longrightarrow> 0 \<le> content (snd xk)"
lp15@60472
  1447
    using tagged_division_ofD(4) [OF p] content_pos_le
lp15@60472
  1448
    by force
lp15@60472
  1449
  have norm: "\<And>xk. xk \<in> p \<Longrightarrow> norm (f (fst xk)) \<le> e"
lp15@60472
  1450
    unfolding fst_conv using tagged_division_ofD(2,3)[OF p] assms
lp15@60472
  1451
    by (metis prod.collapse subset_eq)
nipkow@64267
  1452
  have "norm (sum (\<lambda>(x,k). content k *\<^sub>R f x) p) \<le> (\<Sum>i\<in>p. norm (case i of (x, k) \<Rightarrow> content k *\<^sub>R f x))"
nipkow@64267
  1453
    by (rule norm_sum)
lp15@60472
  1454
  also have "...  \<le> e * content (cbox a b)"
wenzelm@53494
  1455
    unfolding split_def norm_scaleR
nipkow@64267
  1456
    apply (rule order_trans[OF sum_mono])
wenzelm@53494
  1457
    apply (rule mult_left_mono[OF _ abs_ge_zero, of _ e])
lp15@60472
  1458
    apply (metis norm)
nipkow@64267
  1459
    unfolding sum_distrib_right[symmetric]
nipkow@64267
  1460
    using con sum_le
lp15@60472
  1461
    apply (auto simp: mult.commute intro: mult_left_mono [OF _ e])
lp15@60472
  1462
    done
lp15@60472
  1463
  finally show ?thesis .
wenzelm@53494
  1464
qed
himmelma@35172
  1465
himmelma@35172
  1466
lemma rsum_diff_bound:
immler@56188
  1467
  assumes "p tagged_division_of (cbox a b)"
immler@56188
  1468
    and "\<forall>x\<in>cbox a b. norm (f x - g x) \<le> e"
nipkow@64267
  1469
  shows "norm (sum (\<lambda>(x,k). content k *\<^sub>R f x) p - sum (\<lambda>(x,k). content k *\<^sub>R g x) p) \<le>
lp15@60472
  1470
         e * content (cbox a b)"
wenzelm@53494
  1471
  apply (rule order_trans[OF _ rsum_bound[OF assms]])
nipkow@64267
  1472
  apply (simp add: split_def scaleR_diff_right sum_subtractf eq_refl)
wenzelm@53494
  1473
  done
wenzelm@53494
  1474
wenzelm@53494
  1475
lemma has_integral_bound:
immler@56188
  1476
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::real_normed_vector"
wenzelm@53494
  1477
  assumes "0 \<le> B"
hoelzl@63944
  1478
      and *: "(f has_integral i) (cbox a b)"
lp15@60472
  1479
      and "\<forall>x\<in>cbox a b. norm (f x) \<le> B"
lp15@60472
  1480
    shows "norm i \<le> B * content (cbox a b)"
lp15@60472
  1481
proof (rule ccontr)
wenzelm@53494
  1482
  assume "\<not> ?thesis"
immler@56188
  1483
  then have *: "norm i - B * content (cbox a b) > 0"
wenzelm@53494
  1484
    by auto
wenzelm@53494
  1485
  from assms(2)[unfolded has_integral,rule_format,OF *]
wenzelm@53494
  1486
  guess d by (elim exE conjE) note d=this[rule_format]
himmelma@35172
  1487
  from fine_division_exists[OF this(1), of a b] guess p . note p=this
wenzelm@53494
  1488
  have *: "\<And>s B. norm s \<le> B \<Longrightarrow> \<not> norm (s - i) < norm i - B"
lp15@60472
  1489
    unfolding not_less
lp15@60472
  1490
    by (metis norm_triangle_sub[of i] add.commute le_less_trans less_diff_eq linorder_not_le norm_minus_commute)
wenzelm@53494
  1491
  show False
wenzelm@53494
  1492
    using d(2)[OF conjI[OF p]] *[OF rsum_bound[OF p(1) assms(3)]] by auto
wenzelm@53494
  1493
qed
wenzelm@53494
  1494
lp15@60615
  1495
corollary has_integral_bound_real:
immler@56188
  1496
  fixes f :: "real \<Rightarrow> 'b::real_normed_vector"
immler@56188
  1497
  assumes "0 \<le> B"
lp15@60472
  1498
      and "(f has_integral i) {a .. b}"
lp15@60472
  1499
      and "\<forall>x\<in>{a .. b}. norm (f x) \<le> B"
lp15@60472
  1500
    shows "norm i \<le> B * content {a .. b}"
lp15@60615
  1501
  by (metis assms box_real(2) has_integral_bound)
lp15@60615
  1502
lp15@60615
  1503
corollary integrable_bound:
lp15@60615
  1504
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::real_normed_vector"
lp15@60615
  1505
  assumes "0 \<le> B"
lp15@60615
  1506
      and "f integrable_on (cbox a b)"
lp15@60615
  1507
      and "\<And>x. x\<in>cbox a b \<Longrightarrow> norm (f x) \<le> B"
lp15@60615
  1508
    shows "norm (integral (cbox a b) f) \<le> B * content (cbox a b)"
lp15@60615
  1509
by (metis integrable_integral has_integral_bound assms)
immler@56188
  1510
himmelma@35172
  1511
wenzelm@60420
  1512
subsection \<open>Similar theorems about relationship among components.\<close>
himmelma@35172
  1513
wenzelm@53494
  1514
lemma rsum_component_le:
immler@56188
  1515
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
immler@56188
  1516
  assumes "p tagged_division_of (cbox a b)"
lp15@60472
  1517
      and "\<forall>x\<in>cbox a b. (f x)\<bullet>i \<le> (g x)\<bullet>i"
nipkow@64267
  1518
    shows "(sum (\<lambda>(x,k). content k *\<^sub>R f x) p)\<bullet>i \<le> (sum (\<lambda>(x,k). content k *\<^sub>R g x) p)\<bullet>i"
nipkow@64267
  1519
unfolding inner_sum_left
nipkow@64267
  1520
proof (rule sum_mono, clarify)
wenzelm@53494
  1521
  fix a b
wenzelm@53494
  1522
  assume ab: "(a, b) \<in> p"
lp15@60466
  1523
  note tagged = tagged_division_ofD(2-4)[OF assms(1) ab]
wenzelm@53494
  1524
  from this(3) guess u v by (elim exE) note b=this
wenzelm@53494
  1525
  show "(content b *\<^sub>R f a) \<bullet> i \<le> (content b *\<^sub>R g a) \<bullet> i"
lp15@60472
  1526
    unfolding b inner_simps real_scaleR_def
wenzelm@53494
  1527
    apply (rule mult_left_mono)
lp15@60615
  1528
    using assms(2) tagged
lp15@60472
  1529
    by (auto simp add: content_pos_le)
wenzelm@53494
  1530
qed
himmelma@35172
  1531
hoelzl@50526
  1532
lemma has_integral_component_le:
immler@56188
  1533
  fixes f g :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
hoelzl@50526
  1534
  assumes k: "k \<in> Basis"
wenzelm@53494
  1535
  assumes "(f has_integral i) s" "(g has_integral j) s"
wenzelm@53494
  1536
    and "\<forall>x\<in>s. (f x)\<bullet>k \<le> (g x)\<bullet>k"
hoelzl@50526
  1537
  shows "i\<bullet>k \<le> j\<bullet>k"
hoelzl@50348
  1538
proof -
wenzelm@61165
  1539
  have lem: "i\<bullet>k \<le> j\<bullet>k"
wenzelm@61165
  1540
    if f_i: "(f has_integral i) (cbox a b)"
wenzelm@61165
  1541
    and g_j: "(g has_integral j) (cbox a b)"
wenzelm@61165
  1542
    and le: "\<forall>x\<in>cbox a b. (f x)\<bullet>k \<le> (g x)\<bullet>k"
wenzelm@61165
  1543
    for a b i and j :: 'b and f g :: "'a \<Rightarrow> 'b"
hoelzl@50348
  1544
  proof (rule ccontr)
wenzelm@61165
  1545
    assume "\<not> ?thesis"
wenzelm@53494
  1546
    then have *: "0 < (i\<bullet>k - j\<bullet>k) / 3"
wenzelm@53494
  1547
      by auto
wenzelm@61165
  1548
    guess d1 using f_i[unfolded has_integral,rule_format,OF *] by (elim exE conjE) note d1=this[rule_format]
wenzelm@61165
  1549
    guess d2 using g_j[unfolded has_integral,rule_format,OF *] by (elim exE conjE) note d2=this[rule_format]
lp15@60615
  1550
    obtain p where p: "p tagged_division_of cbox a b" "d1 fine p" "d2 fine p"
lp15@60615
  1551
       using fine_division_exists[OF gauge_inter[OF d1(1) d2(1)], of a b] unfolding fine_inter
lp15@60615
  1552
       by metis
hoelzl@50526
  1553
    note le_less_trans[OF Basis_le_norm[OF k]]
lp15@60474
  1554
    then have "\<bar>((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - i) \<bullet> k\<bar> < (i \<bullet> k - j \<bullet> k) / 3"
lp15@60474
  1555
              "\<bar>((\<Sum>(x, k)\<in>p. content k *\<^sub>R g x) - j) \<bullet> k\<bar> < (i \<bullet> k - j \<bullet> k) / 3"
lp15@60474
  1556
      using  k norm_bound_Basis_lt d1 d2 p
lp15@60474
  1557
      by blast+
wenzelm@53494
  1558
    then show False
hoelzl@50526
  1559
      unfolding inner_simps
wenzelm@61165
  1560
      using rsum_component_le[OF p(1) le]
nipkow@62390
  1561
      by (simp add: abs_real_def split: if_split_asm)
wenzelm@53494
  1562
  qed
lp15@60474
  1563
  show ?thesis
lp15@60474
  1564
  proof (cases "\<exists>a b. s = cbox a b")
lp15@60474
  1565
    case True
lp15@60474
  1566
    with lem assms show ?thesis
lp15@60474
  1567
      by auto
lp15@60474
  1568
  next
lp15@60474
  1569
    case False
lp15@60474
  1570
    show ?thesis
lp15@60474
  1571
    proof (rule ccontr)
lp15@60474
  1572
      assume "\<not> i\<bullet>k \<le> j\<bullet>k"
lp15@60474
  1573
      then have ij: "(i\<bullet>k - j\<bullet>k) / 3 > 0"
lp15@60474
  1574
        by auto
lp15@60474
  1575
      note has_integral_altD[OF _ False this]
lp15@60474
  1576
      from this[OF assms(2)] this[OF assms(3)] guess B1 B2 . note B=this[rule_format]
lp15@60474
  1577
      have "bounded (ball 0 B1 \<union> ball (0::'a) B2)"
lp15@60474
  1578
        unfolding bounded_Un by(rule conjI bounded_ball)+
lp15@60474
  1579
      from bounded_subset_cbox[OF this] guess a b by (elim exE)
lp15@60474
  1580
      note ab = conjunctD2[OF this[unfolded Un_subset_iff]]
lp15@60474
  1581
      guess w1 using B(2)[OF ab(1)] .. note w1=conjunctD2[OF this]
lp15@60474
  1582
      guess w2 using B(4)[OF ab(2)] .. note w2=conjunctD2[OF this]
lp15@60474
  1583
      have *: "\<And>w1 w2 j i::real .\<bar>w1 - i\<bar> < (i - j) / 3 \<Longrightarrow> \<bar>w2 - j\<bar> < (i - j) / 3 \<Longrightarrow> w1 \<le> w2 \<Longrightarrow> False"
nipkow@62390
  1584
        by (simp add: abs_real_def split: if_split_asm)
lp15@60474
  1585
      note le_less_trans[OF Basis_le_norm[OF k]]
lp15@60474
  1586
      note this[OF w1(2)] this[OF w2(2)]
lp15@60474
  1587
      moreover
lp15@60474
  1588
      have "w1\<bullet>k \<le> w2\<bullet>k"
lp15@60474
  1589
        by (rule lem[OF w1(1) w2(1)]) (simp add: assms(4))
lp15@60474
  1590
      ultimately show False
lp15@60474
  1591
        unfolding inner_simps by(rule *)
lp15@60474
  1592
    qed
lp15@60474
  1593
  qed
hoelzl@50526
  1594
qed
hoelzl@37489
  1595
wenzelm@53494
  1596
lemma integral_component_le:
immler@56188
  1597
  fixes g f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
wenzelm@53494
  1598
  assumes "k \<in> Basis"
wenzelm@53494
  1599
    and "f integrable_on s" "g integrable_on s"
wenzelm@53494
  1600
    and "\<forall>x\<in>s. (f x)\<bullet>k \<le> (g x)\<bullet>k"
hoelzl@50526
  1601
  shows "(integral s f)\<bullet>k \<le> (integral s g)\<bullet>k"
wenzelm@53494
  1602
  apply (rule has_integral_component_le)
wenzelm@53494
  1603
  using integrable_integral assms
wenzelm@53494
  1604
  apply auto
wenzelm@53494
  1605
  done
wenzelm@53494
  1606
wenzelm@53494
  1607
lemma has_integral_component_nonneg:
immler@56188
  1608
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
wenzelm@53494
  1609
  assumes "k \<in> Basis"
wenzelm@53494
  1610
    and "(f has_integral i) s"
wenzelm@53494
  1611
    and "\<forall>x\<in>s. 0 \<le> (f x)\<bullet>k"
wenzelm@53494
  1612
  shows "0 \<le> i\<bullet>k"
wenzelm@53494
  1613
  using has_integral_component_le[OF assms(1) has_integral_0 assms(2)]
wenzelm@53494
  1614
  using assms(3-)
wenzelm@53494
  1615
  by auto
wenzelm@53494
  1616
wenzelm@53494
  1617
lemma integral_component_nonneg:
immler@56188
  1618
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
wenzelm@53494
  1619
  assumes "k \<in> Basis"
lp15@62463
  1620
    and  "\<forall>x\<in>s. 0 \<le> (f x)\<bullet>k"
wenzelm@53494
  1621
  shows "0 \<le> (integral s f)\<bullet>k"
lp15@62463
  1622
proof (cases "f integrable_on s")
lp15@62463
  1623
  case True show ?thesis
lp15@62463
  1624
    apply (rule has_integral_component_nonneg)
lp15@62463
  1625
    using assms True
lp15@62463
  1626
    apply auto
lp15@62463
  1627
    done
lp15@62463
  1628
next
lp15@62463
  1629
  case False then show ?thesis by (simp add: not_integrable_integral)
lp15@62463
  1630
qed
wenzelm@53494
  1631
wenzelm@53494
  1632
lemma has_integral_component_neg:
immler@56188
  1633
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
wenzelm@53494
  1634
  assumes "k \<in> Basis"
wenzelm@53494
  1635
    and "(f has_integral i) s"
wenzelm@53494
  1636
    and "\<forall>x\<in>s. (f x)\<bullet>k \<le> 0"
wenzelm@53494
  1637
  shows "i\<bullet>k \<le> 0"
wenzelm@53494
  1638
  using has_integral_component_le[OF assms(1,2) has_integral_0] assms(2-)
wenzelm@53494
  1639
  by auto
hoelzl@50526
  1640
hoelzl@50526
  1641
lemma has_integral_component_lbound:
immler@56188
  1642
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
immler@56188
  1643
  assumes "(f has_integral i) (cbox a b)"
immler@56188
  1644
    and "\<forall>x\<in>cbox a b. B \<le> f(x)\<bullet>k"
wenzelm@53494
  1645
    and "k \<in> Basis"
immler@56188
  1646
  shows "B * content (cbox a b) \<le> i\<bullet>k"
hoelzl@50526
  1647
  using has_integral_component_le[OF assms(3) has_integral_const assms(1),of "(\<Sum>i\<in>Basis. B *\<^sub>R i)::'b"] assms(2-)
wenzelm@53494
  1648
  by (auto simp add: field_simps)
hoelzl@50526
  1649
hoelzl@50526
  1650
lemma has_integral_component_ubound:
immler@56188
  1651
  fixes f::"'a::euclidean_space => 'b::euclidean_space"
immler@56188
  1652
  assumes "(f has_integral i) (cbox a b)"
immler@56188
  1653
    and "\<forall>x\<in>cbox a b. f x\<bullet>k \<le> B"
wenzelm@53494
  1654
    and "k \<in> Basis"
immler@56188
  1655
  shows "i\<bullet>k \<le> B * content (cbox a b)"
wenzelm@53494
  1656
  using has_integral_component_le[OF assms(3,1) has_integral_const, of "\<Sum>i\<in>Basis. B *\<^sub>R i"] assms(2-)
wenzelm@53494
  1657
  by (auto simp add: field_simps)
wenzelm@53494
  1658
wenzelm@53494
  1659
lemma integral_component_lbound:
immler@56188
  1660
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
immler@56188
  1661
  assumes "f integrable_on cbox a b"
immler@56188
  1662
    and "\<forall>x\<in>cbox a b. B \<le> f(x)\<bullet>k"
wenzelm@53494
  1663
    and "k \<in> Basis"
immler@56188
  1664
  shows "B * content (cbox a b) \<le> (integral(cbox a b) f)\<bullet>k"
wenzelm@53494
  1665
  apply (rule has_integral_component_lbound)
wenzelm@53494
  1666
  using assms
wenzelm@53494
  1667
  unfolding has_integral_integral
wenzelm@53494
  1668
  apply auto
wenzelm@53494
  1669
  done
wenzelm@53494
  1670
immler@56190
  1671
lemma integral_component_lbound_real:
immler@56190
  1672
  assumes "f integrable_on {a ::real .. b}"
immler@56190
  1673
    and "\<forall>x\<in>{a .. b}. B \<le> f(x)\<bullet>k"
immler@56190
  1674
    and "k \<in> Basis"
immler@56190
  1675
  shows "B * content {a .. b} \<le> (integral {a .. b} f)\<bullet>k"
immler@56190
  1676
  using assms
immler@56190
  1677
  by (metis box_real(2) integral_component_lbound)
immler@56190
  1678
wenzelm@53494
  1679
lemma integral_component_ubound:
immler@56188
  1680
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
immler@56188
  1681
  assumes "f integrable_on cbox a b"
immler@56188
  1682
    and "\<forall>x\<in>cbox a b. f x\<bullet>k \<le> B"
wenzelm@53494
  1683
    and "k \<in> Basis"
immler@56188
  1684
  shows "(integral (cbox a b) f)\<bullet>k \<le> B * content (cbox a b)"
wenzelm@53494
  1685
  apply (rule has_integral_component_ubound)
wenzelm@53494
  1686
  using assms
wenzelm@53494
  1687
  unfolding has_integral_integral
wenzelm@53494
  1688
  apply auto
wenzelm@53494
  1689
  done
wenzelm@53494
  1690
immler@56190
  1691
lemma integral_component_ubound_real:
immler@56190
  1692
  fixes f :: "real \<Rightarrow> 'a::euclidean_space"
immler@56190
  1693
  assumes "f integrable_on {a .. b}"
immler@56190
  1694
    and "\<forall>x\<in>{a .. b}. f x\<bullet>k \<le> B"
immler@56190
  1695
    and "k \<in> Basis"
immler@56190
  1696
  shows "(integral {a .. b} f)\<bullet>k \<le> B * content {a .. b}"
immler@56190
  1697
  using assms
immler@56190
  1698
  by (metis box_real(2) integral_component_ubound)
himmelma@35172
  1699
wenzelm@60420
  1700
subsection \<open>Uniform limit of integrable functions is integrable.\<close>
himmelma@35172
  1701
lp15@62626
  1702
lemma real_arch_invD:
lp15@62626
  1703
  "0 < (e::real) \<Longrightarrow> (\<exists>n::nat. n \<noteq> 0 \<and> 0 < inverse (real n) \<and> inverse (real n) < e)"
lp15@62626
  1704
  by (subst(asm) real_arch_inverse)
lp15@62626
  1705
wenzelm@53494
  1706
lemma integrable_uniform_limit:
immler@56188
  1707
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::banach"
immler@56188
  1708
  assumes "\<forall>e>0. \<exists>g. (\<forall>x\<in>cbox a b. norm (f x - g x) \<le> e) \<and> g integrable_on cbox a b"
immler@56188
  1709
  shows "f integrable_on cbox a b"
lp15@60487
  1710
proof (cases "content (cbox a b) > 0")
lp15@60487
  1711
  case False then show ?thesis
wenzelm@53494
  1712
      using has_integral_null
lp15@60487
  1713
      by (simp add: content_lt_nz integrable_on_def)
lp15@60487
  1714
next
lp15@60487
  1715
  case True
wenzelm@53494
  1716
  have *: "\<And>P. \<forall>e>(0::real). P e \<Longrightarrow> \<forall>n::nat. P (inverse (real n + 1))"
wenzelm@53494
  1717
    by auto
himmelma@35172
  1718
  from choice[OF *[OF assms]] guess g .. note g=conjunctD2[OF this[rule_format],rule_format]
lp15@60615
  1719
  from choice[OF allI[OF g(2)[unfolded integrable_on_def], of "\<lambda>x. x"]]
lp15@60487
  1720
  obtain i where i: "\<And>x. (g x has_integral i x) (cbox a b)"
lp15@60487
  1721
      by auto
wenzelm@53494
  1722
  have "Cauchy i"
wenzelm@53494
  1723
    unfolding Cauchy_def
lp15@60487
  1724
  proof clarify
wenzelm@53494
  1725
    fix e :: real
wenzelm@53494
  1726
    assume "e>0"
immler@56188
  1727
    then have "e / 4 / content (cbox a b) > 0"
lp15@60487
  1728
      using True by (auto simp add: field_simps)
lp15@60487
  1729
    then obtain M :: nat
lp15@60487
  1730
         where M: "M \<noteq> 0" "0 < inverse (real_of_nat M)" "inverse (of_nat M) < e / 4 / content (cbox a b)"
lp15@62623
  1731
      by (subst (asm) real_arch_inverse) auto
wenzelm@53494
  1732
    show "\<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. dist (i m) (i n) < e"
lp15@60487
  1733
    proof (rule exI [where x=M], clarify)
lp15@60487
  1734
      fix m n
lp15@60487
  1735
      assume m: "M \<le> m" and n: "M \<le> n"
wenzelm@60420
  1736
      have "e/4>0" using \<open>e>0\<close> by auto
wenzelm@53494
  1737
      note * = i[unfolded has_integral,rule_format,OF this]
wenzelm@53494
  1738
      from *[of m] guess gm by (elim conjE exE) note gm=this[rule_format]
wenzelm@53494
  1739
      from *[of n] guess gn by (elim conjE exE) note gn=this[rule_format]
lp15@60615
  1740
      from fine_division_exists[OF gauge_inter[OF gm(1) gn(1)], of a b]
lp15@60487
  1741
      obtain p where p: "p tagged_division_of cbox a b" "(\<lambda>x. gm x \<inter> gn x) fine p"
lp15@60487
  1742
        by auto
lp15@60487
  1743
      { fix s1 s2 i1 and i2::'b
lp15@60487
  1744
        assume no: "norm(s2 - s1) \<le> e/2" "norm (s1 - i1) < e/4" "norm (s2 - i2) < e/4"
wenzelm@53494
  1745
        have "norm (i1 - i2) \<le> norm (i1 - s1) + norm (s1 - s2) + norm (s2 - i2)"
himmelma@35172
  1746
          using norm_triangle_ineq[of "i1 - s1" "s1 - i2"]
wenzelm@53494
  1747
          using norm_triangle_ineq[of "s1 - s2" "s2 - i2"]
wenzelm@53494
  1748
          by (auto simp add: algebra_simps)
wenzelm@53494
  1749
        also have "\<dots> < e"
lp15@60487
  1750
          using no
wenzelm@53494
  1751
          unfolding norm_minus_commute
wenzelm@53494
  1752
          by (auto simp add: algebra_simps)
lp15@60487
  1753
        finally have "norm (i1 - i2) < e" .
lp15@60487
  1754
      } note triangle3 = this
lp15@60487
  1755
      have finep: "gm fine p" "gn fine p"
lp15@60487
  1756
        using fine_inter p  by auto
lp15@60487
  1757
      { fix x
immler@56188
  1758
        assume x: "x \<in> cbox a b"
wenzelm@53399
  1759
        have "norm (f x - g n x) + norm (f x - g m x) \<le> inverse (real n + 1) + inverse (real m + 1)"
wenzelm@53494
  1760
          using g(1)[OF x, of n] g(1)[OF x, of m] by auto
wenzelm@53494
  1761
        also have "\<dots> \<le> inverse (real M) + inverse (real M)"
wenzelm@53494
  1762
          apply (rule add_mono)
lp15@60487
  1763
          using M(2) m n by auto
wenzelm@53494
  1764
        also have "\<dots> = 2 / real M"
wenzelm@53494
  1765
          unfolding divide_inverse by auto
lp15@60487
  1766
        finally have "norm (g n x - g m x) \<le> 2 / real M"
himmelma@35172
  1767
          using norm_triangle_le[of "g n x - f x" "f x - g m x" "2 / real M"]
wenzelm@53494
  1768
          by (auto simp add: algebra_simps simp add: norm_minus_commute)
lp15@60487
  1769
      } note norm_le = this
lp15@60487
  1770
      have le_e2: "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R g n x) - (\<Sum>(x, k)\<in>p. content k *\<^sub>R g m x)) \<le> e / 2"
lp15@60487
  1771
        apply (rule order_trans [OF rsum_diff_bound[OF p(1), where e="2 / real M"]])
lp15@60487
  1772
        apply (blast intro: norm_le)
lp15@60487
  1773
        using M True
lp15@60487
  1774
        by (auto simp add: field_simps)
lp15@60487
  1775
      then show "dist (i m) (i n) < e"
lp15@60487
  1776
        unfolding dist_norm
lp15@60487
  1777
        using gm gn p finep
lp15@60487
  1778
        by (auto intro!: triangle3)
lp15@60487
  1779
    qed
lp15@60487
  1780
  qed
wenzelm@61969
  1781
  then obtain s where s: "i \<longlonglongrightarrow> s"
lp15@64287
  1782
    using convergent_eq_Cauchy[symmetric] by blast
wenzelm@53494
  1783
  show ?thesis
lp15@60487
  1784
    unfolding integrable_on_def has_integral
lp15@60487
  1785
  proof (rule_tac x=s in exI, clarify)
lp15@60487
  1786
    fix e::real
lp15@60487
  1787
    assume e: "0 < e"
wenzelm@53494
  1788
    then have *: "e/3 > 0" by auto
lp15@60487
  1789
    then obtain N1 where N1: "\<forall>n\<ge>N1. norm (i n - s) < e / 3"
lp15@60487
  1790
      using LIMSEQ_D [OF s] by metis
lp15@60487
  1791
    from e True have "e / 3 / content (cbox a b) > 0"
wenzelm@53494
  1792
      by (auto simp add: field_simps)
wenzelm@53494
  1793
    from real_arch_invD[OF this] guess N2 by (elim exE conjE) note N2=this
himmelma@35172
  1794
    from i[of "N1 + N2",unfolded has_integral,rule_format,OF *] guess g' .. note g'=conjunctD2[OF this,rule_format]
lp15@60487
  1795
    { fix sf sg i
lp15@60487
  1796
      assume no: "norm (sf - sg) \<le> e / 3"
lp15@60487
  1797
                 "norm(i - s) < e / 3"
lp15@60487
  1798
                 "norm (sg - i) < e / 3"
wenzelm@53494
  1799
      have "norm (sf - s) \<le> norm (sf - sg) + norm (sg - i) + norm (i - s)"
himmelma@35172
  1800
        using norm_triangle_ineq[of "sf - sg" "sg - s"]
wenzelm@53494
  1801
        using norm_triangle_ineq[of "sg -  i" " i - s"]
wenzelm@53494
  1802
        by (auto simp add: algebra_simps)
wenzelm@53494
  1803
      also have "\<dots> < e"
lp15@60487
  1804
        using no
wenzelm@53494
  1805
        unfolding norm_minus_commute
wenzelm@53494
  1806
        by (auto simp add: algebra_simps)
lp15@60487
  1807
      finally have "norm (sf - s) < e" .
lp15@60615
  1808
    } note lem = this
lp15@60487
  1809
    { fix p
immler@56188
  1810
      assume p: "p tagged_division_of (cbox a b) \<and> g' fine p"
lp15@60487
  1811
      then have norm_less: "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R g (N1 + N2) x) - i (N1 + N2)) < e / 3"
lp15@60487
  1812
        using g' by blast
lp15@60487
  1813
      have "content (cbox a b) < e / 3 * (of_nat N2)"
lp15@60487
  1814
        using N2 unfolding inverse_eq_divide using True by (auto simp add: field_simps)
lp15@60487
  1815
      moreover have "e / 3 * of_nat N2 \<le> e / 3 * (of_nat (N1 + N2) + 1)"
lp15@60487
  1816
        using \<open>e>0\<close> by auto
lp15@60487
  1817
      ultimately have "content (cbox a b) < e / 3 * (of_nat (N1 + N2) + 1)"
lp15@60487
  1818
        by linarith
lp15@60487
  1819
      then have le_e3: "inverse (real (N1 + N2) + 1) * content (cbox a b) \<le> e / 3"
lp15@60487
  1820
        unfolding inverse_eq_divide
lp15@60487
  1821
        by (auto simp add: field_simps)
lp15@60487
  1822
      have ne3: "norm (i (N1 + N2) - s) < e / 3"
lp15@60487
  1823
        using N1 by auto
lp15@60487
  1824
      have "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - s) < e"
lp15@60487
  1825
        apply (rule lem[OF order_trans [OF _ le_e3] ne3 norm_less])
wenzelm@53494
  1826
        apply (rule rsum_diff_bound[OF p[THEN conjunct1]])
lp15@60487
  1827
        apply (blast intro: g)
lp15@60487
  1828
        done }
lp15@60487
  1829
    then show "\<exists>d. gauge d \<and>
lp15@60487
  1830
             (\<forall>p. p tagged_division_of cbox a b \<and> d fine p \<longrightarrow> norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - s) < e)"
lp15@60487
  1831
      by (blast intro: g')
wenzelm@53494
  1832
  qed
wenzelm@53494
  1833
qed
wenzelm@53494
  1834
lp15@61806
  1835
lemmas integrable_uniform_limit_real = integrable_uniform_limit [where 'a=real, simplified]
lp15@61806
  1836
himmelma@35172
  1837
wenzelm@60420
  1838
subsection \<open>Negligible sets.\<close>
himmelma@35172
  1839
immler@56188
  1840
definition "negligible (s:: 'a::euclidean_space set) \<longleftrightarrow>
immler@56188
  1841
  (\<forall>a b. ((indicator s :: 'a\<Rightarrow>real) has_integral 0) (cbox a b))"
wenzelm@53494
  1842
himmelma@35172
  1843
wenzelm@60420
  1844
subsection \<open>Negligibility of hyperplane.\<close>
himmelma@35172
  1845
wenzelm@53495
  1846
lemma content_doublesplit:
immler@56188
  1847
  fixes a :: "'a::euclidean_space"
wenzelm@53495
  1848
  assumes "0 < e"
wenzelm@53495
  1849
    and k: "k \<in> Basis"
wenzelm@61945
  1850
  obtains d where "0 < d" and "content (cbox a b \<inter> {x. \<bar>x\<bullet>k - c\<bar> \<le> d}) < e"
hoelzl@63886
  1851
proof cases
hoelzl@63886
  1852
  assume *: "a \<bullet> k \<le> c \<and> c \<le> b \<bullet> k \<and> (\<forall>j\<in>Basis. a \<bullet> j \<le> b \<bullet> j)"
hoelzl@63886
  1853
  define a' where "a' d = (\<Sum>j\<in>Basis. (if j = k then max (a\<bullet>j) (c - d) else a\<bullet>j) *\<^sub>R j)" for d
hoelzl@63886
  1854
  define b' where "b' d = (\<Sum>j\<in>Basis. (if j = k then min (b\<bullet>j) (c + d) else b\<bullet>j) *\<^sub>R j)" for d
hoelzl@63886
  1855
hoelzl@63886
  1856
  have "((\<lambda>d. \<Prod>j\<in>Basis. (b' d - a' d) \<bullet> j) \<longlongrightarrow> (\<Prod>j\<in>Basis. (b' 0 - a' 0) \<bullet> j)) (at_right 0)"
hoelzl@63886
  1857
    by (auto simp: b'_def a'_def intro!: tendsto_min tendsto_max tendsto_eq_intros)
hoelzl@63886
  1858
  also have "(\<Prod>j\<in>Basis. (b' 0 - a' 0) \<bullet> j) = 0"
hoelzl@63886
  1859
    using k *
nipkow@64272
  1860
    by (intro prod_zero bexI[OF _ k])
nipkow@64267
  1861
       (auto simp: b'_def a'_def inner_diff inner_sum_left inner_not_same_Basis intro!: sum.cong)
hoelzl@63886
  1862
  also have "((\<lambda>d. \<Prod>j\<in>Basis. (b' d - a' d) \<bullet> j) \<longlongrightarrow> 0) (at_right 0) =
hoelzl@63886
  1863
    ((\<lambda>d. content (cbox a b \<inter> {x. \<bar>x\<bullet>k - c\<bar> \<le> d})) \<longlongrightarrow> 0) (at_right 0)"
hoelzl@63886
  1864
  proof (intro tendsto_cong eventually_at_rightI)
hoelzl@63886
  1865
    fix d :: real assume d: "d \<in> {0<..<1}"
hoelzl@63886
  1866
    have "cbox a b \<inter> {x. \<bar>x\<bullet>k - c\<bar> \<le> d} = cbox (a' d) (b' d)" for d
hoelzl@63886
  1867
      using * d k by (auto simp add: cbox_def set_eq_iff Int_def ball_conj_distrib abs_diff_le_iff a'_def b'_def)
hoelzl@63886
  1868
    moreover have "j \<in> Basis \<Longrightarrow> a' d \<bullet> j \<le> b' d \<bullet> j" for j
hoelzl@63886
  1869
      using * d k by (auto simp: a'_def b'_def)
hoelzl@63886
  1870
    ultimately show "(\<Prod>j\<in>Basis. (b' d - a' d) \<bullet> j) = content (cbox a b \<inter> {x. \<bar>x\<bullet>k - c\<bar> \<le> d})"
hoelzl@63886
  1871
      by simp
hoelzl@63886
  1872
  qed simp
hoelzl@63886
  1873
  finally have "((\<lambda>d. content (cbox a b \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d})) \<longlongrightarrow> 0) (at_right 0)" .
hoelzl@63886
  1874
  from order_tendstoD(2)[OF this \<open>0<e\<close>]
hoelzl@63886
  1875
  obtain d' where "0 < d'" and d': "\<And>y. y > 0 \<Longrightarrow> y < d' \<Longrightarrow> content (cbox a b \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> y}) < e"
hoelzl@63886
  1876
    by (subst (asm) eventually_at_right[of _ 1]) auto
wenzelm@53495
  1877
  show ?thesis
hoelzl@63886
  1878
    by (rule that[of "d'/2"], insert \<open>0<d'\<close> d'[of "d'/2"], auto)
wenzelm@53495
  1879
next
hoelzl@63886
  1880
  assume *: "\<not> (a \<bullet> k \<le> c \<and> c \<le> b \<bullet> k \<and> (\<forall>j\<in>Basis. a \<bullet> j \<le> b \<bullet> j))"
hoelzl@63886
  1881
  then have "(\<exists>j\<in>Basis. b \<bullet> j < a \<bullet> j) \<or> (c < a \<bullet> k \<or> b \<bullet> k < c)"
hoelzl@63886
  1882
    by (auto simp: not_le)
hoelzl@63886
  1883
  show thesis
hoelzl@63886
  1884
  proof cases
hoelzl@63886
  1885
    assume "\<exists>j\<in>Basis. b \<bullet> j < a \<bullet> j"
hoelzl@63886
  1886
    then have [simp]: "cbox a b = {}"
hoelzl@63886
  1887
      using box_ne_empty(1)[of a b] by auto
hoelzl@63886
  1888
    show ?thesis
hoelzl@63886
  1889
      by (rule that[of 1]) (simp_all add: \<open>0<e\<close>)
hoelzl@63886
  1890
  next
hoelzl@63886
  1891
    assume "\<not> (\<exists>j\<in>Basis. b \<bullet> j < a \<bullet> j)"
hoelzl@63886
  1892
    with * have "c < a \<bullet> k \<or> b \<bullet> k < c"
hoelzl@63886
  1893
      by auto
hoelzl@63886
  1894
    then show thesis
hoelzl@63886
  1895
    proof
hoelzl@63886
  1896
      assume c: "c < a \<bullet> k"
hoelzl@63886
  1897
      moreover have "x \<in> cbox a b \<Longrightarrow> c \<le> x \<bullet> k" for x
hoelzl@63886
  1898
        using k c by (auto simp: cbox_def)
hoelzl@63886
  1899
      ultimately have "cbox a b \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> (a \<bullet> k - c) / 2} = {}"
hoelzl@63886
  1900
        using k by (auto simp: cbox_def)
hoelzl@63886
  1901
      with \<open>0<e\<close> c that[of "(a \<bullet> k - c) / 2"] show ?thesis
wenzelm@53495
  1902
        by auto
lp15@60492
  1903
    next
hoelzl@63886
  1904
      assume c: "b \<bullet> k < c"
hoelzl@63886
  1905
      moreover have "x \<in> cbox a b \<Longrightarrow> x \<bullet> k \<le> c" for x
hoelzl@63886
  1906
        using k c by (auto simp: cbox_def)
hoelzl@63886
  1907
      ultimately have "cbox a b \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> (c - b \<bullet> k) / 2} = {}"
hoelzl@63886
  1908
        using k by (auto simp: cbox_def)
hoelzl@63886
  1909
      with \<open>0<e\<close> c that[of "(c - b \<bullet> k) / 2"] show ?thesis
hoelzl@63886
  1910
        by auto
hoelzl@63886
  1911
    qed
hoelzl@63886
  1912
  qed
hoelzl@63886
  1913
qed
hoelzl@63886
  1914
hoelzl@50526
  1915
wenzelm@53399
  1916
lemma negligible_standard_hyperplane[intro]:
immler@56188
  1917
  fixes k :: "'a::euclidean_space"
hoelzl@50526
  1918
  assumes k: "k \<in> Basis"
wenzelm@53399
  1919
  shows "negligible {x. x\<bullet>k = c}"
wenzelm@53495
  1920
  unfolding negligible_def has_integral
wenzelm@61166
  1921
proof (clarify, goal_cases)
wenzelm@61165
  1922
  case (1 a b e)
wenzelm@61165
  1923
  from this and k obtain d where d: "0 < d" "content (cbox a b \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}) < e"
wenzelm@61165
  1924
    by (rule content_doublesplit)
hoelzl@50526
  1925
  let ?i = "indicator {x::'a. x\<bullet>k = c} :: 'a\<Rightarrow>real"
wenzelm@53495
  1926
  show ?case
wenzelm@53495
  1927
    apply (rule_tac x="\<lambda>x. ball x d" in exI)
wenzelm@53495
  1928
    apply rule
wenzelm@53495
  1929
    apply (rule gauge_ball)
wenzelm@53495
  1930
    apply (rule d)
wenzelm@53495
  1931
  proof (rule, rule)
wenzelm@53495
  1932
    fix p
immler@56188
  1933
    assume p: "p tagged_division_of (cbox a b) \<and> (\<lambda>x. ball x d) fine p"
wenzelm@53495
  1934
    have *: "(\<Sum>(x, ka)\<in>p. content ka *\<^sub>R ?i x) =
wenzelm@61945
  1935
      (\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. \<bar>x\<bullet>k - c\<bar> \<le> d}) *\<^sub>R ?i x)"
nipkow@64267
  1936
      apply (rule sum.cong)
haftmann@57418
  1937
      apply (rule refl)
wenzelm@53495
  1938
      unfolding split_paired_all real_scaleR_def mult_cancel_right split_conv
wenzelm@53495
  1939
      apply cases
wenzelm@53495
  1940
      apply (rule disjI1)
wenzelm@53495
  1941
      apply assumption
wenzelm@53495
  1942
      apply (rule disjI2)
wenzelm@53495
  1943
    proof -
wenzelm@53495
  1944
      fix x l
wenzelm@53495
  1945
      assume as: "(x, l) \<in> p" "?i x \<noteq> 0"
wenzelm@53495
  1946
      then have xk: "x\<bullet>k = c"
wenzelm@53495
  1947
        unfolding indicator_def
wenzelm@53495
  1948
        apply -
wenzelm@53495
  1949
        apply (rule ccontr)
wenzelm@53495
  1950
        apply auto
wenzelm@53495
  1951
        done
wenzelm@53495
  1952
      show "content l = content (l \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d})"
wenzelm@53495
  1953
        apply (rule arg_cong[where f=content])
wenzelm@53495
  1954
        apply (rule set_eqI)
wenzelm@53495
  1955
        apply rule
wenzelm@53495
  1956
        apply rule
wenzelm@53495
  1957
        unfolding mem_Collect_eq
wenzelm@53495
  1958
      proof -
wenzelm@53495
  1959
        fix y
wenzelm@53495
  1960
        assume y: "y \<in> l"
wenzelm@53495
  1961
        note p[THEN conjunct2,unfolded fine_def,rule_format,OF as(1),unfolded split_conv]
wenzelm@53495
  1962
        note this[unfolded subset_eq mem_ball dist_norm,rule_format,OF y]
wenzelm@53495
  1963
        note le_less_trans[OF Basis_le_norm[OF k] this]
wenzelm@53495
  1964
        then show "\<bar>y \<bullet> k - c\<bar> \<le> d"
wenzelm@53495
  1965
          unfolding inner_simps xk by auto
wenzelm@53495
  1966
      qed auto
wenzelm@53495
  1967
    qed
himmelma@35172
  1968
    note p'= tagged_division_ofD[OF p[THEN conjunct1]] and p''=division_of_tagged_division[OF p[THEN conjunct1]]
wenzelm@53495
  1969
    show "norm ((\<Sum>(x, ka)\<in>p. content ka *\<^sub>R ?i x) - 0) < e"
wenzelm@53495
  1970
      unfolding diff_0_right *
wenzelm@53495
  1971
      unfolding real_scaleR_def real_norm_def
wenzelm@53495
  1972
      apply (subst abs_of_nonneg)
nipkow@64267
  1973
      apply (rule sum_nonneg)
wenzelm@53495
  1974
      apply rule
wenzelm@53495
  1975
      unfolding split_paired_all split_conv
wenzelm@53495
  1976
      apply (rule mult_nonneg_nonneg)
wenzelm@53495
  1977
      apply (drule p'(4))
wenzelm@53495
  1978
      apply (erule exE)+
wenzelm@53495
  1979
      apply(rule_tac b=b in back_subst)
wenzelm@53495
  1980
      prefer 2
wenzelm@53495
  1981
      apply (subst(asm) eq_commute)
wenzelm@53495
  1982
      apply assumption
wenzelm@53495
  1983
      apply (subst interval_doublesplit[OF k])
wenzelm@53495
  1984
      apply (rule content_pos_le)
wenzelm@53495
  1985
      apply (rule indicator_pos_le)
wenzelm@53495
  1986
    proof -
wenzelm@53495
  1987
      have "(\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}) * ?i x) \<le>
wenzelm@53495
  1988
        (\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}))"
nipkow@64267
  1989
        apply (rule sum_mono)
wenzelm@53495
  1990
        unfolding split_paired_all split_conv
wenzelm@53495
  1991
        apply (rule mult_right_le_one_le)
wenzelm@53495
  1992
        apply (drule p'(4))
wenzelm@53495
  1993
        apply (auto simp add:interval_doublesplit[OF k])
wenzelm@53495
  1994
        done
wenzelm@53495
  1995
      also have "\<dots> < e"
nipkow@64267
  1996
      proof (subst sum.over_tagged_division_lemma[OF p[THEN conjunct1]], goal_cases)
wenzelm@61167
  1997
        case prems: (1 u v)
hoelzl@63957
  1998
        then have *: "content (cbox u v) = 0"
hoelzl@63957
  1999
          unfolding content_eq_0_interior by simp
immler@56188
  2000
        have "content (cbox u v \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}) \<le> content (cbox u v)"
wenzelm@53495
  2001
          unfolding interval_doublesplit[OF k]
wenzelm@53495
  2002
          apply (rule content_subset)
wenzelm@53495
  2003
          unfolding interval_doublesplit[symmetric,OF k]
wenzelm@53495
  2004
          apply auto
wenzelm@53495
  2005
          done
wenzelm@53495
  2006
        then show ?case
hoelzl@63957
  2007
          unfolding * interval_doublesplit[OF k]
hoelzl@50348
  2008
          by (blast intro: antisym)
wenzelm@53495
  2009
      next
hoelzl@63593
  2010
        have "(\<Sum>l\<in>snd ` p. content (l \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d})) =
nipkow@64267
  2011
          sum content ((\<lambda>l. l \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d})`{l\<in>snd ` p. l \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d} \<noteq> {}})"
nipkow@64267
  2012
        proof (subst (2) sum.reindex_nontrivial)
hoelzl@63593
  2013
          fix x y assume "x \<in> {l \<in> snd ` p. l \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d} \<noteq> {}}" "y \<in> {l \<in> snd ` p. l \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d} \<noteq> {}}"
hoelzl@63593
  2014
            "x \<noteq> y" and eq: "x \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d} = y \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}"
hoelzl@63593
  2015
          then obtain x' y' where "(x', x) \<in> p" "x \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d} \<noteq> {}" "(y', y) \<in> p" "y \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d} \<noteq> {}"
hoelzl@63593
  2016
            by (auto)
hoelzl@63593
  2017
          from p'(5)[OF \<open>(x', x) \<in> p\<close> \<open>(y', y) \<in> p\<close>] \<open>x \<noteq> y\<close> have "interior (x \<inter> y) = {}"
hoelzl@63593
  2018
            by auto
hoelzl@63593
  2019
          moreover have "interior ((x \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}) \<inter> (y \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d})) \<subseteq> interior (x \<inter> y)"
hoelzl@63593
  2020
            by (auto intro: interior_mono)
hoelzl@63593
  2021
          ultimately have "interior (x \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}) = {}"
hoelzl@63593
  2022
            by (auto simp: eq)
hoelzl@63593
  2023
          then show "content (x \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}) = 0"
hoelzl@63593
  2024
            using p'(4)[OF \<open>(x', x) \<in> p\<close>] by (auto simp: interval_doublesplit[OF k] content_eq_0_interior simp del: interior_Int)
nipkow@64267
  2025
        qed (insert p'(1), auto intro!: sum.mono_neutral_right)
hoelzl@63593
  2026
        also have "\<dots> \<le> norm (\<Sum>l\<in>(\<lambda>l. l \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d})`{l\<in>snd ` p. l \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d} \<noteq> {}}. content l *\<^sub>R 1::real)"
hoelzl@63593
  2027
          by simp
hoelzl@63593
  2028
        also have "\<dots> \<le> 1 * content (cbox a b \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d})"
hoelzl@63593
  2029
          using division_doublesplit[OF p'' k, unfolded interval_doublesplit[OF k]]
hoelzl@63593
  2030
          unfolding interval_doublesplit[OF k] by (intro dsum_bound) auto
hoelzl@63593
  2031
        also have "\<dots> < e"
hoelzl@63593
  2032
          using d(2) by simp
hoelzl@63593
  2033
        finally show "(\<Sum>ka\<in>snd ` p. content (ka \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d})) < e" .
wenzelm@53495
  2034
      qed
hoelzl@50526
  2035
      finally show "(\<Sum>(x, ka)\<in>p. content (ka \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}) * ?i x) < e" .
wenzelm@53495
  2036
    qed
wenzelm@53495
  2037
  qed
wenzelm@53495
  2038
qed
wenzelm@53495
  2039
himmelma@35172
  2040
himmelma@35172
  2041
wenzelm@60420
  2042
subsection \<open>Hence the main theorem about negligible sets.\<close>
himmelma@35172
  2043
wenzelm@53495
  2044
lemma has_integral_negligible:
immler@56188
  2045
  fixes f :: "'b::euclidean_space \<Rightarrow> 'a::real_normed_vector"
wenzelm@53495
  2046
  assumes "negligible s"
wenzelm@53495
  2047
    and "\<forall>x\<in>(t - s). f x = 0"
himmelma@35172
  2048
  shows "(f has_integral 0) t"
wenzelm@53495
  2049
proof -
immler@56188
  2050
  presume P: "\<And>f::'b::euclidean_space \<Rightarrow> 'a.
immler@56188
  2051
    \<And>a b. \<forall>x. x \<notin> s \<longrightarrow> f x = 0 \<Longrightarrow> (f has_integral 0) (cbox a b)"
himmelma@35172
  2052
  let ?f = "(\<lambda>x. if x \<in> t then f x else 0)"
wenzelm@53495
  2053
  show ?thesis
wenzelm@53495
  2054
    apply (rule_tac f="?f" in has_integral_eq)
wenzelm@53495
  2055
    unfolding if_P
wenzelm@53495
  2056
    apply (rule refl)
wenzelm@53495
  2057
    apply (subst has_integral_alt)
wenzelm@53495
  2058
    apply cases
wenzelm@53495
  2059
    apply (subst if_P, assumption)
wenzelm@53495
  2060
    unfolding if_not_P
wenzelm@53495
  2061
  proof -
immler@56188
  2062
    assume "\<exists>a b. t = cbox a b"
wenzelm@53495
  2063
    then guess a b apply - by (erule exE)+ note t = this
wenzelm@53495
  2064
    show "(?f has_integral 0) t"
wenzelm@53495
  2065
      unfolding t
wenzelm@53495
  2066
      apply (rule P)
wenzelm@53495
  2067
      using assms(2)
wenzelm@53495
  2068
      unfolding t
wenzelm@53495
  2069
      apply auto
wenzelm@53495
  2070
      done
wenzelm@53495
  2071
  next
immler@56188
  2072
    show "\<forall>e>0. \<exists>B>0. \<forall>a b. ball 0 B \<subseteq> cbox a b \<longrightarrow>
immler@56188
  2073
      (\<exists>z. ((\<lambda>x. if x \<in> t then ?f x else 0) has_integral z) (cbox a b) \<and> norm (z - 0) < e)"
wenzelm@53495
  2074
      apply safe
wenzelm@53495
  2075
      apply (rule_tac x=1 in exI)
wenzelm@53495
  2076
      apply rule
wenzelm@53495
  2077
      apply (rule zero_less_one)
wenzelm@53495
  2078
      apply safe
wenzelm@53495
  2079
      apply (rule_tac x=0 in exI)
wenzelm@53495
  2080
      apply rule
wenzelm@53495
  2081
      apply (rule P)
wenzelm@53495
  2082
      using assms(2)
wenzelm@53495
  2083
      apply auto
wenzelm@53495
  2084
      done
himmelma@35172
  2085
  qed
wenzelm@53495
  2086
next
wenzelm@53495
  2087
  fix f :: "'b \<Rightarrow> 'a"
wenzelm@53495
  2088
  fix a b :: 'b
wenzelm@53495
  2089
  assume assm: "\<forall>x. x \<notin> s \<longrightarrow> f x = 0"
immler@56188
  2090
  show "(f has_integral 0) (cbox a b)"
wenzelm@53495
  2091
    unfolding has_integral
wenzelm@61166
  2092
  proof (safe, goal_cases)
wenzelm@61167
  2093
    case prems: (1 e)
wenzelm@53495
  2094
    then have "\<And>n. e / 2 / ((real n+1) * (2 ^ n)) > 0"
wenzelm@53495
  2095
      apply -
wenzelm@53495
  2096
      apply (rule divide_pos_pos)
wenzelm@53495
  2097
      defer
wenzelm@53495
  2098
      apply (rule mult_pos_pos)
wenzelm@53495
  2099
      apply (auto simp add:field_simps)
wenzelm@53495
  2100
      done
wenzelm@53495
  2101
    note assms(1)[unfolded negligible_def has_integral,rule_format,OF this,of a b]
wenzelm@53495
  2102
    note allI[OF this,of "\<lambda>x. x"]
himmelma@35172
  2103
    from choice[OF this] guess d .. note d=conjunctD2[OF this[rule_format]]
wenzelm@53495
  2104
    show ?case
wenzelm@53495
  2105
      apply (rule_tac x="\<lambda>x. d (nat \<lfloor>norm (f x)\<rfloor>) x" in exI)
wenzelm@53495
  2106
    proof safe
wenzelm@53495
  2107
      show "gauge (\<lambda>x. d (nat \<lfloor>norm (f x)\<rfloor>) x)"
wenzelm@53495
  2108
        using d(1) unfolding gauge_def by auto
wenzelm@53495
  2109
      fix p
immler@56188
  2110
      assume as: "p tagged_division_of (cbox a b)" "(\<lambda>x. d (nat \<lfloor>norm (f x)\<rfloor>) x) fine p"
himmelma@35172
  2111
      let ?goal = "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - 0) < e"
wenzelm@53495
  2112
      {
wenzelm@53495
  2113
        presume "p \<noteq> {} \<Longrightarrow> ?goal"
wenzelm@53495
  2114
        then show ?goal
wenzelm@53495
  2115
          apply (cases "p = {}")
wenzelm@61167
  2116
          using prems
wenzelm@53495
  2117
          apply auto
wenzelm@53495
  2118
          done
wenzelm@53495
  2119
      }
wenzelm@53495
  2120
      assume as': "p \<noteq> {}"
lp15@61824
  2121
      from real_arch_simple[of "Max((\<lambda>(x,k). norm(f x)) ` p)"] guess N ..
wenzelm@53495
  2122
      then have N: "\<forall>x\<in>(\<lambda>(x, k). norm (f x)) ` p. x \<le> real N"
lp15@61824
  2123
        by (meson Max_ge as(1) dual_order.trans finite_imageI tagged_division_of_finite)
immler@56188
  2124
      have "\<forall>i. \<exists>q. q tagged_division_of (cbox a b) \<and> (d i) fine q \<and> (\<forall>(x, k)\<in>p. k \<subseteq> (d i) x \<longrightarrow> (x, k) \<in> q)"
lp15@61824
  2125
        by (auto intro: tagged_division_finer[OF as(1) d(1)])
himmelma@35172
  2126
      from choice[OF this] guess q .. note q=conjunctD3[OF this[rule_format]]
wenzelm@53495
  2127
      have *: "\<And>i. (\<Sum>(x, k)\<in>q i. content k *\<^sub>R indicator s x) \<ge> (0::real)"
nipkow@64267
  2128
        apply (rule sum_nonneg)
wenzelm@53495
  2129
        apply safe
wenzelm@53495
  2130
        unfolding real_scaleR_def
wenzelm@53495
  2131
        apply (drule tagged_division_ofD(4)[OF q(1)])
nipkow@56536
  2132
        apply (auto intro: mult_nonneg_nonneg)
wenzelm@53495
  2133
        done
wenzelm@61165
  2134
      have **: "finite s \<Longrightarrow> finite t \<Longrightarrow> (\<forall>(x,y) \<in> t. (0::real) \<le> g(x,y)) \<Longrightarrow>
nipkow@64267
  2135
        (\<forall>y\<in>s. \<exists>x. (x,y) \<in> t \<and> f(y) \<le> g(x,y)) \<Longrightarrow> sum f s \<le> sum g t" for f g s t
nipkow@64267
  2136
        apply (rule sum_le_included[of s t g snd f])
wenzelm@61165
  2137
        prefer 4
wenzelm@61165
  2138
        apply safe
wenzelm@61165
  2139
        apply (erule_tac x=x in ballE)
wenzelm@61165
  2140
        apply (erule exE)
wenzelm@61165
  2141
        apply (rule_tac x="(xa,x)" in bexI)
wenzelm@61165
  2142
        apply auto
wenzelm@61165
  2143
        done
nipkow@64267
  2144
      have "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - 0) \<le> sum (\<lambda>i. (real i + 1) *
nipkow@64267
  2145
        norm (sum (\<lambda>(x,k). content k *\<^sub>R indicator s x :: real) (q i))) {..N+1}"
nipkow@64267
  2146
        unfolding real_norm_def sum_distrib_left abs_of_nonneg[OF *] diff_0_right
wenzelm@53495
  2147
        apply (rule order_trans)
nipkow@64267
  2148
        apply (rule norm_sum)
wenzelm@53495
  2149
        apply (subst sum_sum_product)
wenzelm@53495
  2150
        prefer 3
wenzelm@53495
  2151
      proof (rule **, safe)
hoelzl@56193
  2152
        show "finite {(i, j) |i j. i \<in> {..N + 1} \<and> j \<in> q i}"
wenzelm@53495
  2153
          apply (rule finite_product_dependent)
wenzelm@53495
  2154
          using q
wenzelm@53495
  2155
          apply auto
wenzelm@53495
  2156
          done
wenzelm@53495
  2157
        fix i a b
wenzelm@53495
  2158
        assume as'': "(a, b) \<in> q i"
wenzelm@53495
  2159
        show "0 \<le> (real i + 1) * (content b *\<^sub>R indicator s a)"
wenzelm@53495
  2160
          unfolding real_scaleR_def
wenzelm@53495
  2161
          using tagged_division_ofD(4)[OF q(1) as'']
nipkow@56536
  2162
          by (auto intro!: mult_nonneg_nonneg)
wenzelm@53495
  2163
      next
wenzelm@53495
  2164
        fix i :: nat
wenzelm@53495
  2165
        show "finite (q i)"
wenzelm@53495
  2166
          using q by auto
wenzelm@53495
  2167
      next
wenzelm@53495
  2168
        fix x k
wenzelm@53495
  2169
        assume xk: "(x, k) \<in> p"
wenzelm@63040
  2170
        define n where "n = nat \<lfloor>norm (f x)\<rfloor>"
wenzelm@53495
  2171
        have *: "norm (f x) \<in> (\<lambda>(x, k). norm (f x)) ` p"
wenzelm@53495
  2172
          using xk by auto
wenzelm@53495
  2173
        have nfx: "real n \<le> norm (f x)" "norm (f x) \<le> real n + 1"
wenzelm@53495
  2174
          unfolding n_def by auto
wenzelm@53495
  2175
        then have "n \<in> {0..N + 1}"
wenzelm@53495
  2176
          using N[rule_format,OF *] by auto
wenzelm@53495
  2177
        moreover
wenzelm@53495
  2178
        note as(2)[unfolded fine_def,rule_format,OF xk,unfolded split_conv]
wenzelm@53495
  2179
        note q(3)[rule_format,OF xk,unfolded split_conv,rule_format,OF this]
wenzelm@53495
  2180
        note this[unfolded n_def[symmetric]]
wenzelm@53495
  2181
        moreover
wenzelm@53495
  2182
        have "norm (content k *\<^sub>R f x) \<le> (real n + 1) * (content k * indicator s x)"
wenzelm@53495
  2183
        proof (cases "x \<in> s")
wenzelm@53495
  2184
          case False
wenzelm@53495
  2185
          then show ?thesis
wenzelm@53495
  2186
            using assm by auto
wenzelm@53495
  2187
        next
wenzelm@53495
  2188
          case True
wenzelm@53495
  2189
          have *: "content k \<ge> 0"
wenzelm@53495
  2190
            using tagged_division_ofD(4)[OF as(1) xk] by auto
wenzelm@53495
  2191
          moreover
wenzelm@53495
  2192
          have "content k * norm (f x) \<le> content k * (real n + 1)"
wenzelm@53495
  2193
            apply (rule mult_mono)
wenzelm@53495
  2194
            using nfx *
wenzelm@53495
  2195
            apply auto
wenzelm@53495
  2196
            done
wenzelm@53495
  2197
          ultimately
wenzelm@53495
  2198
          show ?thesis
wenzelm@53495
  2199
            unfolding abs_mult
wenzelm@53495
  2200
            using nfx True
wenzelm@53495
  2201
            by (auto simp add: field_simps)
wenzelm@53495
  2202
        qed
hoelzl@56193
  2203
        ultimately show "\<exists>y. (y, x, k) \<in> {(i, j) |i j. i \<in> {..N + 1} \<and> j \<in> q i} \<and> norm (content k *\<^sub>R f x) \<le>
wenzelm@53495
  2204
          (real y + 1) * (content k *\<^sub>R indicator s x)"
wenzelm@53495
  2205
          apply (rule_tac x=n in exI)
wenzelm@53495
  2206
          apply safe
wenzelm@53495
  2207
          apply (rule_tac x=n in exI)
wenzelm@53495
  2208
          apply (rule_tac x="(x,k)" in exI)
wenzelm@53495
  2209
          apply safe
wenzelm@53495
  2210
          apply auto
wenzelm@53495
  2211
          done
wenzelm@53495
  2212
      qed (insert as, auto)
nipkow@64267
  2213
      also have "\<dots> \<le> sum (\<lambda>i. e / 2 / 2 ^ i) {..N+1}"
nipkow@64267
  2214
      proof (rule sum_mono, goal_cases)
wenzelm@61165
  2215
        case (1 i)
wenzelm@53495
  2216
        then show ?case
haftmann@57512
  2217
          apply (subst mult.commute, subst pos_le_divide_eq[symmetric])
wenzelm@61165
  2218
          using d(2)[rule_format, of "q i" i]
wenzelm@53495
  2219
          using q[rule_format]
wenzelm@53495
  2220
          apply (auto simp add: field_simps)
wenzelm@53495
  2221
          done
wenzelm@53495
  2222
      qed
wenzelm@53495
  2223
      also have "\<dots> < e * inverse 2 * 2"
nipkow@64267
  2224
        unfolding divide_inverse sum_distrib_left[symmetric]
wenzelm@53495
  2225
        apply (rule mult_strict_left_mono)
haftmann@60867
  2226
        unfolding power_inverse [symmetric] lessThan_Suc_atMost[symmetric]
hoelzl@56193
  2227
        apply (subst geometric_sum)
wenzelm@61167
  2228
        using prems
wenzelm@53495
  2229
        apply auto
wenzelm@53495
  2230
        done
wenzelm@53495
  2231
      finally show "?goal" by auto
wenzelm@53495
  2232
    qed
wenzelm@53495
  2233
  qed
wenzelm@53495
  2234
qed
wenzelm@53495
  2235
wenzelm@53495
  2236
lemma has_integral_spike:
immler@56188
  2237
  fixes f :: "'b::euclidean_space \<Rightarrow> 'a::real_normed_vector"
wenzelm@53495
  2238
  assumes "negligible s"
wenzelm@53495
  2239
    and "(\<forall>x\<in>(t - s). g x = f x)"
wenzelm@53495
  2240
    and "(f has_integral y) t"
himmelma@35172
  2241
  shows "(g has_integral y) t"
wenzelm@53495
  2242
proof -
wenzelm@53495
  2243
  {
wenzelm@53495
  2244
    fix a b :: 'b
wenzelm@53495
  2245
    fix f g :: "'b \<Rightarrow> 'a"
wenzelm@53495
  2246
    fix y :: 'a
immler@56188
  2247
    assume as: "\<forall>x \<in> cbox a b - s. g x = f x" "(f has_integral y) (cbox a b)"
immler@56188
  2248
    have "((\<lambda>x. f x + (g x - f x)) has_integral (y + 0)) (cbox a b)"
wenzelm@53495
  2249
      apply (rule has_integral_add[OF as(2)])
wenzelm@53495
  2250
      apply (rule has_integral_negligible[OF assms(1)])
wenzelm@53495
  2251
      using as
wenzelm@53495
  2252
      apply auto
wenzelm@53495
  2253
      done
immler@56188
  2254
    then have "(g has_integral y) (cbox a b)"
wenzelm@53495
  2255
      by auto
wenzelm@53495
  2256
  } note * = this
wenzelm@53495
  2257
  show ?thesis
wenzelm@53495
  2258
    apply (subst has_integral_alt)
wenzelm@53495
  2259
    using assms(2-)
wenzelm@53495
  2260
    apply -
wenzelm@53495
  2261
    apply (rule cond_cases)
wenzelm@53495
  2262
    apply safe
wenzelm@53495
  2263
    apply (rule *)
wenzelm@53495
  2264
    apply assumption+
wenzelm@53495
  2265
    apply (subst(asm) has_integral_alt)
wenzelm@53495
  2266
    unfolding if_not_P
wenzelm@53495
  2267
    apply (erule_tac x=e in allE)
wenzelm@53495
  2268
    apply safe
wenzelm@53495
  2269
    apply (rule_tac x=B in exI)
wenzelm@53495
  2270
    apply safe
wenzelm@53495
  2271
    apply (erule_tac x=a in allE)
wenzelm@53495
  2272
    apply (erule_tac x=b in allE)
wenzelm@53495
  2273
    apply safe
wenzelm@53495
  2274
    apply (rule_tac x=z in exI)
wenzelm@53495
  2275
    apply safe
wenzelm@53495
  2276
    apply (rule *[where fa2="\<lambda>x. if x\<in>t then f x else 0"])
wenzelm@53495
  2277
    apply auto
wenzelm@53495
  2278
    done
wenzelm@53495
  2279
qed
himmelma@35172
  2280
himmelma@35172
  2281
lemma has_integral_spike_eq:
wenzelm@53495
  2282
  assumes "negligible s"
wenzelm@53495
  2283
    and "\<forall>x\<in>(t - s). g x = f x"
himmelma@35172
  2284
  shows "((f has_integral y) t \<longleftrightarrow> (g has_integral y) t)"
wenzelm@53495
  2285
  apply rule
wenzelm@53495
  2286
  apply (rule_tac[!] has_integral_spike[OF assms(1)])
wenzelm@53495
  2287
  using assms(2)
wenzelm@53495
  2288
  apply auto
wenzelm@53495
  2289
  done
wenzelm@53495
  2290
wenzelm@53495
  2291
lemma integrable_spike:
wenzelm@53495
  2292
  assumes "negligible s"
wenzelm@53495
  2293
    and "\<forall>x\<in>(t - s). g x = f x"
wenzelm@53495
  2294
    and "f integrable_on t"
himmelma@35172
  2295
  shows "g integrable_on  t"
wenzelm@53495
  2296
  using assms
wenzelm@53495
  2297
  unfolding integrable_on_def
wenzelm@53495
  2298
  apply -
wenzelm@53495
  2299
  apply (erule exE)
wenzelm@53495
  2300
  apply rule
wenzelm@53495
  2301
  apply (rule has_integral_spike)
wenzelm@53495
  2302
  apply fastforce+
wenzelm@53495
  2303
  done
wenzelm@53495
  2304
wenzelm@53495
  2305
lemma integral_spike:
wenzelm@53495
  2306
  assumes "negligible s"
wenzelm@53495
  2307
    and "\<forall>x\<in>(t - s). g x = f x"
himmelma@35172
  2308
  shows "integral t f = integral t g"
lp15@62463
  2309
  using has_integral_spike_eq[OF assms] by (simp add: integral_def integrable_on_def)
wenzelm@53495
  2310
himmelma@35172
  2311
wenzelm@60420
  2312
subsection \<open>Some other trivialities about negligible sets.\<close>
himmelma@35172
  2313
lp15@63945
  2314
lemma negligible_subset:
lp15@63945
  2315
  assumes "negligible s" "t \<subseteq> s"
wenzelm@53495
  2316
  shows "negligible t"
wenzelm@53495
  2317
  unfolding negligible_def
lp15@63945
  2318
    by (metis (no_types) Diff_iff assms contra_subsetD has_integral_negligible indicator_simps(2))
wenzelm@53495
  2319
wenzelm@53495
  2320
lemma negligible_diff[intro?]:
wenzelm@53495
  2321
  assumes "negligible s"
wenzelm@53495
  2322
  shows "negligible (s - t)"
lp15@63945
  2323
  using assms by (meson Diff_subset negligible_subset)
wenzelm@53495
  2324
lp15@63492
  2325
lemma negligible_Int:
wenzelm@53495
  2326
  assumes "negligible s \<or> negligible t"
wenzelm@53495
  2327
  shows "negligible (s \<inter> t)"
lp15@63945
  2328
  using assms negligible_subset by force
wenzelm@53495
  2329
lp15@63492
  2330
lemma negligible_Un:
wenzelm@53495
  2331
  assumes "negligible s"
wenzelm@53495
  2332
    and "negligible t"
wenzelm@53495
  2333
  shows "negligible (s \<union> t)"
wenzelm@53495
  2334
  unfolding negligible_def
wenzelm@61166
  2335
proof (safe, goal_cases)
wenzelm@61165
  2336
  case (1 a b)
wenzelm@53495
  2337
  note assm = assms[unfolded negligible_def,rule_format,of a b]
wenzelm@53495
  2338
  then show ?case
wenzelm@53495
  2339
    apply (subst has_integral_spike_eq[OF assms(2)])
wenzelm@53495
  2340
    defer
wenzelm@53495
  2341
    apply assumption
wenzelm@53495
  2342
    unfolding indicator_def
wenzelm@53495
  2343
    apply auto
wenzelm@53495
  2344
    done
wenzelm@53495
  2345
qed
wenzelm@53495
  2346
lp15@63492
  2347
lemma negligible_Un_eq[simp]: "negligible (s \<union> t) \<longleftrightarrow> negligible s \<and> negligible t"
hoelzl@63956
  2348
  using negligible_Un negligible_subset by blast
himmelma@35172
  2349
immler@56188
  2350
lemma negligible_sing[intro]: "negligible {a::'a::euclidean_space}"
lp15@63945
  2351
  using negligible_standard_hyperplane[OF SOME_Basis, of "a \<bullet> (SOME i. i \<in> Basis)"] negligible_subset by blast
himmelma@35172
  2352
wenzelm@53495
  2353
lemma negligible_insert[simp]: "negligible (insert a s) \<longleftrightarrow> negligible s"
wenzelm@53495
  2354
  apply (subst insert_is_Un)
lp15@63492
  2355
  unfolding negligible_Un_eq
wenzelm@53495
  2356
  apply auto
wenzelm@53495
  2357
  done
wenzelm@53495
  2358
paulson@60762
  2359
lemma negligible_empty[iff]: "negligible {}"
lp15@63945
  2360
  using negligible_insert by blast
wenzelm@53495
  2361
wenzelm@53495
  2362
lemma negligible_finite[intro]:
wenzelm@53495
  2363
  assumes "finite s"
wenzelm@53495
  2364
  shows "negligible s"
wenzelm@53495
  2365
  using assms by (induct s) auto
wenzelm@53495
  2366
lp15@63469
  2367
lemma negligible_Union[intro]:
wenzelm@53495
  2368
  assumes "finite s"
wenzelm@53495
  2369
    and "\<forall>t\<in>s. negligible t"
wenzelm@53495
  2370
  shows "negligible(\<Union>s)"
wenzelm@53495
  2371
  using assms by induct auto
wenzelm@53495
  2372
wenzelm@53495
  2373
lemma negligible:
immler@56188
  2374
  "negligible s \<longleftrightarrow> (\<forall>t::('a::euclidean_space) set. ((indicator s::'a\<Rightarrow>real) has_integral 0) t)"
wenzelm@53495
  2375
  apply safe
wenzelm@53495
  2376
  defer
wenzelm@53495
  2377
  apply (subst negligible_def)
wenzelm@46905
  2378
proof -
wenzelm@53495
  2379
  fix t :: "'a set"
wenzelm@53495
  2380
  assume as: "negligible s"
wenzelm@53495
  2381
  have *: "(\<lambda>x. if x \<in> s \<inter> t then 1 else 0) = (\<lambda>x. if x\<in>t then if x\<in>s then 1 else 0 else 0)"
wenzelm@46905
  2382
    by auto
wenzelm@46905
  2383
  show "((indicator s::'a\<Rightarrow>real) has_integral 0) t"
wenzelm@53495
  2384
    apply (subst has_integral_alt)
wenzelm@53495
  2385
    apply cases
wenzelm@53495
  2386
    apply (subst if_P,assumption)
wenzelm@46905
  2387
    unfolding if_not_P