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