src/HOL/Analysis/Henstock_Kurzweil_Integration.thy
author haftmann
Sun Nov 18 18:07:51 2018 +0000 (8 months ago)
changeset 69313 b021008c5397
parent 69064 5840724b1d71
child 69508 2a4c8a2a3f8e
permissions -rw-r--r--
removed legacy input syntax
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
eberlm@68721
   690
lemma integrable_on_cnj_iff:
eberlm@68721
   691
  "(\<lambda>x. cnj (f x)) integrable_on A \<longleftrightarrow> f integrable_on A"
eberlm@68721
   692
  using integrable_linear[OF _ bounded_linear_cnj, of f A]
eberlm@68721
   693
        integrable_linear[OF _ bounded_linear_cnj, of "cnj \<circ> f" A]
eberlm@68721
   694
  by (auto simp: o_def)
eberlm@68721
   695
eberlm@68721
   696
lemma integral_cnj: "cnj (integral A f) = integral A (\<lambda>x. cnj (f x))"
eberlm@68721
   697
  by (cases "f integrable_on A")
eberlm@68721
   698
     (simp_all add: integral_linear[OF _ bounded_linear_cnj, symmetric]
eberlm@68721
   699
                    o_def integrable_on_cnj_iff not_integrable_integral)
eberlm@68721
   700
wenzelm@53410
   701
lemma integral_component_eq[simp]:
immler@56188
   702
  fixes f :: "'n::euclidean_space \<Rightarrow> 'm::euclidean_space"
lp15@66164
   703
  assumes "f integrable_on S"
lp15@66164
   704
  shows "integral S (\<lambda>x. f x \<bullet> k) = integral S f \<bullet> k"
lp15@63938
   705
  unfolding integral_linear[OF assms(1) bounded_linear_inner_left,unfolded o_def] ..
himmelma@36243
   706
nipkow@64267
   707
lemma has_integral_sum:
lp15@66560
   708
  assumes "finite T"
lp15@66560
   709
    and "\<And>a. a \<in> T \<Longrightarrow> ((f a) has_integral (i a)) S"
lp15@66560
   710
  shows "((\<lambda>x. sum (\<lambda>a. f a x) T) has_integral (sum i T)) S"
lp15@66560
   711
  using assms(1) subset_refl[of T]
wenzelm@53410
   712
proof (induct rule: finite_subset_induct)
wenzelm@53410
   713
  case empty
wenzelm@53410
   714
  then show ?case by auto
wenzelm@53410
   715
next
wenzelm@53410
   716
  case (insert x F)
lp15@60396
   717
  with assms show ?case
lp15@60396
   718
    by (simp add: has_integral_add)
lp15@60396
   719
qed
lp15@60396
   720
nipkow@64267
   721
lemma integral_sum:
lp15@66164
   722
  "\<lbrakk>finite I;  \<And>a. a \<in> I \<Longrightarrow> f a integrable_on S\<rbrakk> \<Longrightarrow>
lp15@66164
   723
   integral S (\<lambda>x. \<Sum>a\<in>I. f a x) = (\<Sum>a\<in>I. integral S (f a))"
lp15@66164
   724
  by (simp add: has_integral_sum integrable_integral integral_unique)
nipkow@64267
   725
nipkow@64267
   726
lemma integrable_sum:
lp15@66089
   727
  "\<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
   728
  unfolding integrable_on_def using has_integral_sum[of I] by metis
himmelma@35172
   729
himmelma@35172
   730
lemma has_integral_eq:
lp15@60615
   731
  assumes "\<And>x. x \<in> s \<Longrightarrow> f x = g x"
wenzelm@53410
   732
    and "(f has_integral k) s"
wenzelm@53410
   733
  shows "(g has_integral k) s"
lp15@66112
   734
  using has_integral_diff[OF assms(2), of "\<lambda>x. f x - g x" 0]
wenzelm@53410
   735
  using has_integral_is_0[of s "\<lambda>x. f x - g x"]
wenzelm@53410
   736
  using assms(1)
wenzelm@53410
   737
  by auto
wenzelm@53410
   738
lp15@66552
   739
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
   740
  unfolding integrable_on_def
lp15@60615
   741
  using has_integral_eq[of s f g] has_integral_eq by blast
lp15@60615
   742
lp15@60615
   743
lemma has_integral_cong:
lp15@60615
   744
  assumes "\<And>x. x \<in> s \<Longrightarrow> f x = g x"
lp15@60615
   745
  shows "(f has_integral i) s = (g has_integral i) s"
lp15@60615
   746
  using has_integral_eq[of s f g] has_integral_eq[of s g f] assms
wenzelm@53410
   747
  by auto
wenzelm@53410
   748
lp15@60615
   749
lemma integral_cong:
lp15@60615
   750
  assumes "\<And>x. x \<in> s \<Longrightarrow> f x = g x"
lp15@60615
   751
  shows "integral s f = integral s g"
lp15@60615
   752
  unfolding integral_def
lp15@62463
   753
by (metis (full_types, hide_lams) assms has_integral_cong integrable_eq)
lp15@60615
   754
lp15@62533
   755
lemma integrable_on_cmult_left_iff [simp]:
lp15@62533
   756
  assumes "c \<noteq> 0"
lp15@62533
   757
  shows "(\<lambda>x. of_real c * f x) integrable_on s \<longleftrightarrow> f integrable_on s"
lp15@62533
   758
        (is "?lhs = ?rhs")
lp15@62533
   759
proof
lp15@62533
   760
  assume ?lhs
lp15@62533
   761
  then have "(\<lambda>x. of_real (1 / c) * (of_real c * f x)) integrable_on s"
lp15@62533
   762
    using integrable_cmul[of "\<lambda>x. of_real c * f x" s "1 / of_real c"]
lp15@62533
   763
    by (simp add: scaleR_conv_of_real)
lp15@62533
   764
  then have "(\<lambda>x. (of_real (1 / c) * of_real c * f x)) integrable_on s"
lp15@62533
   765
    by (simp add: algebra_simps)
lp15@62533
   766
  with \<open>c \<noteq> 0\<close> show ?rhs
lp15@62533
   767
    by (metis (no_types, lifting) integrable_eq mult.left_neutral nonzero_divide_eq_eq of_real_1 of_real_mult)
lp15@62533
   768
qed (blast intro: integrable_on_cmult_left)
lp15@62533
   769
lp15@62533
   770
lemma integrable_on_cmult_right:
lp15@62533
   771
  fixes f :: "_ \<Rightarrow> 'b :: {comm_ring,real_algebra_1,real_normed_vector}"
lp15@62533
   772
  assumes "f integrable_on s"
lp15@62533
   773
  shows "(\<lambda>x. f x * of_real c) integrable_on s"
lp15@62533
   774
using integrable_on_cmult_left [OF assms] by (simp add: mult.commute)
lp15@62533
   775
lp15@62533
   776
lemma integrable_on_cmult_right_iff [simp]:
lp15@62533
   777
  fixes f :: "_ \<Rightarrow> 'b :: {comm_ring,real_algebra_1,real_normed_vector}"
lp15@62533
   778
  assumes "c \<noteq> 0"
lp15@62533
   779
  shows "(\<lambda>x. f x * of_real c) integrable_on s \<longleftrightarrow> f integrable_on s"
lp15@62533
   780
using integrable_on_cmult_left_iff [OF assms] by (simp add: mult.commute)
lp15@62533
   781
lp15@62533
   782
lemma integrable_on_cdivide:
lp15@62533
   783
  fixes f :: "_ \<Rightarrow> 'b :: real_normed_field"
lp15@62533
   784
  assumes "f integrable_on s"
lp15@62533
   785
  shows "(\<lambda>x. f x / of_real c) integrable_on s"
nipkow@68403
   786
by (simp add: integrable_on_cmult_right divide_inverse assms flip: of_real_inverse)
lp15@62533
   787
lp15@62533
   788
lemma integrable_on_cdivide_iff [simp]:
lp15@62533
   789
  fixes f :: "_ \<Rightarrow> 'b :: real_normed_field"
lp15@62533
   790
  assumes "c \<noteq> 0"
lp15@62533
   791
  shows "(\<lambda>x. f x / of_real c) integrable_on s \<longleftrightarrow> f integrable_on s"
nipkow@68403
   792
by (simp add: divide_inverse assms flip: of_real_inverse)
lp15@62533
   793
hoelzl@63944
   794
lemma has_integral_null [intro]: "content(cbox a b) = 0 \<Longrightarrow> (f has_integral 0) (cbox a b)"
hoelzl@63944
   795
  unfolding has_integral_cbox
hoelzl@63944
   796
  using eventually_division_filter_tagged_division[of "cbox a b"]
nipkow@64267
   797
  by (subst tendsto_cong[where g="\<lambda>_. 0"]) (auto elim: eventually_mono intro: sum_content_null)
hoelzl@63944
   798
paulson@66402
   799
lemma has_integral_null_real [intro]: "content {a..b::real} = 0 \<Longrightarrow> (f has_integral 0) {a..b}"
hoelzl@63944
   800
  by (metis box_real(2) has_integral_null)
immler@56188
   801
immler@56188
   802
lemma has_integral_null_eq[simp]: "content (cbox a b) = 0 \<Longrightarrow> (f has_integral i) (cbox a b) \<longleftrightarrow> i = 0"
lp15@60396
   803
  by (auto simp add: has_integral_null dest!: integral_unique)
wenzelm@53410
   804
lp15@60615
   805
lemma integral_null [simp]: "content (cbox a b) = 0 \<Longrightarrow> integral (cbox a b) f = 0"
lp15@60396
   806
  by (metis has_integral_null integral_unique)
wenzelm@53410
   807
lp15@60615
   808
lemma integrable_on_null [intro]: "content (cbox a b) = 0 \<Longrightarrow> f integrable_on (cbox a b)"
lp15@60615
   809
  by (simp add: has_integral_integrable)
wenzelm@53410
   810
wenzelm@53410
   811
lemma has_integral_empty[intro]: "(f has_integral 0) {}"
lp15@66519
   812
  by (meson ex_in_conv has_integral_is_0)
wenzelm@53410
   813
wenzelm@53410
   814
lemma has_integral_empty_eq[simp]: "(f has_integral i) {} \<longleftrightarrow> i = 0"
lp15@60396
   815
  by (auto simp add: has_integral_empty has_integral_unique)
wenzelm@53410
   816
wenzelm@53410
   817
lemma integrable_on_empty[intro]: "f integrable_on {}"
wenzelm@53410
   818
  unfolding integrable_on_def by auto
wenzelm@53410
   819
wenzelm@53410
   820
lemma integral_empty[simp]: "integral {} f = 0"
wenzelm@53410
   821
  by (rule integral_unique) (rule has_integral_empty)
wenzelm@53410
   822
wenzelm@53410
   823
lemma has_integral_refl[intro]:
immler@56188
   824
  fixes a :: "'a::euclidean_space"
immler@56188
   825
  shows "(f has_integral 0) (cbox a a)"
wenzelm@53410
   826
    and "(f has_integral 0) {a}"
wenzelm@53410
   827
proof -
lp15@66112
   828
  show "(f has_integral 0) (cbox a a)"
lp15@66112
   829
     by (rule has_integral_null) simp
lp15@66112
   830
  then show "(f has_integral 0) {a}"
lp15@66112
   831
    by simp
immler@56188
   832
qed
immler@56188
   833
immler@56188
   834
lemma integrable_on_refl[intro]: "f integrable_on cbox a a"
wenzelm@53410
   835
  unfolding integrable_on_def by auto
wenzelm@53410
   836
paulson@60762
   837
lemma integral_refl [simp]: "integral (cbox a a) f = 0"
wenzelm@53410
   838
  by (rule integral_unique) auto
wenzelm@53410
   839
paulson@60762
   840
lemma integral_singleton [simp]: "integral {a} f = 0"
paulson@60762
   841
  by auto
paulson@60762
   842
immler@61915
   843
lemma integral_blinfun_apply:
immler@61915
   844
  assumes "f integrable_on s"
immler@61915
   845
  shows "integral s (\<lambda>x. blinfun_apply h (f x)) = blinfun_apply h (integral s f)"
immler@61915
   846
  by (subst integral_linear[symmetric, OF assms blinfun.bounded_linear_right]) (simp add: o_def)
immler@61915
   847
immler@61915
   848
lemma blinfun_apply_integral:
immler@61915
   849
  assumes "f integrable_on s"
immler@61915
   850
  shows "blinfun_apply (integral s f) x = integral s (\<lambda>y. blinfun_apply (f y) x)"
immler@61915
   851
  by (metis (no_types, lifting) assms blinfun.prod_left.rep_eq integral_blinfun_apply integral_cong)
immler@61915
   852
eberlm@63295
   853
lemma has_integral_componentwise_iff:
eberlm@63295
   854
  fixes f :: "'a :: euclidean_space \<Rightarrow> 'b :: euclidean_space"
eberlm@63295
   855
  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
   856
proof safe
eberlm@63295
   857
  fix b :: 'b assume "(f has_integral y) A"
lp15@63938
   858
  from has_integral_linear[OF this(1) bounded_linear_inner_left, of b]
eberlm@63295
   859
    show "((\<lambda>x. f x \<bullet> b) has_integral (y \<bullet> b)) A" by (simp add: o_def)
eberlm@63295
   860
next
eberlm@63295
   861
  assume "(\<forall>b\<in>Basis. ((\<lambda>x. f x \<bullet> b) has_integral (y \<bullet> b)) A)"
eberlm@63295
   862
  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
   863
    by (intro ballI has_integral_linear) (simp_all add: bounded_linear_scaleR_left)
eberlm@63295
   864
  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
   865
    by (intro has_integral_sum) (simp_all add: o_def)
eberlm@63295
   866
  thus "(f has_integral y) A" by (simp add: euclidean_representation)
eberlm@63295
   867
qed
eberlm@63295
   868
eberlm@63295
   869
lemma has_integral_componentwise:
eberlm@63295
   870
  fixes f :: "'a :: euclidean_space \<Rightarrow> 'b :: euclidean_space"
eberlm@63295
   871
  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
   872
  by (subst has_integral_componentwise_iff) blast
eberlm@63295
   873
eberlm@63295
   874
lemma integrable_componentwise_iff:
eberlm@63295
   875
  fixes f :: "'a :: euclidean_space \<Rightarrow> 'b :: euclidean_space"
eberlm@63295
   876
  shows "f integrable_on A \<longleftrightarrow> (\<forall>b\<in>Basis. (\<lambda>x. f x \<bullet> b) integrable_on A)"
eberlm@63295
   877
proof
eberlm@63295
   878
  assume "f integrable_on A"
eberlm@63295
   879
  then obtain y where "(f has_integral y) A" by (auto simp: integrable_on_def)
eberlm@63295
   880
  hence "(\<forall>b\<in>Basis. ((\<lambda>x. f x \<bullet> b) has_integral (y \<bullet> b)) A)"
eberlm@63295
   881
    by (subst (asm) has_integral_componentwise_iff)
eberlm@63295
   882
  thus "(\<forall>b\<in>Basis. (\<lambda>x. f x \<bullet> b) integrable_on A)" by (auto simp: integrable_on_def)
eberlm@63295
   883
next
eberlm@63295
   884
  assume "(\<forall>b\<in>Basis. (\<lambda>x. f x \<bullet> b) integrable_on A)"
eberlm@63295
   885
  then obtain y where "\<forall>b\<in>Basis. ((\<lambda>x. f x \<bullet> b) has_integral y b) A"
eberlm@63295
   886
    unfolding integrable_on_def by (subst (asm) bchoice_iff) blast
eberlm@63295
   887
  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
   888
    by (intro ballI has_integral_linear) (simp_all add: bounded_linear_scaleR_left)
eberlm@63295
   889
  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
   890
    by (intro has_integral_sum) (simp_all add: o_def)
eberlm@63295
   891
  thus "f integrable_on A" by (auto simp: integrable_on_def o_def euclidean_representation)
eberlm@63295
   892
qed
eberlm@63295
   893
eberlm@63295
   894
lemma integrable_componentwise:
eberlm@63295
   895
  fixes f :: "'a :: euclidean_space \<Rightarrow> 'b :: euclidean_space"
eberlm@63295
   896
  shows "(\<And>b. b \<in> Basis \<Longrightarrow> (\<lambda>x. f x \<bullet> b) integrable_on A) \<Longrightarrow> f integrable_on A"
eberlm@63295
   897
  by (subst integrable_componentwise_iff) blast
eberlm@63295
   898
eberlm@63295
   899
lemma integral_componentwise:
eberlm@63295
   900
  fixes f :: "'a :: euclidean_space \<Rightarrow> 'b :: euclidean_space"
eberlm@63295
   901
  assumes "f integrable_on A"
eberlm@63295
   902
  shows "integral A f = (\<Sum>b\<in>Basis. integral A (\<lambda>x. (f x \<bullet> b) *\<^sub>R b))"
eberlm@63295
   903
proof -
eberlm@63295
   904
  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
   905
    by (subst (asm) integrable_componentwise_iff, intro integrable_linear ballI)
eberlm@63295
   906
       (simp_all add: bounded_linear_scaleR_left)
eberlm@63295
   907
  have "integral A f = integral A (\<lambda>x. \<Sum>b\<in>Basis. (f x \<bullet> b) *\<^sub>R b)"
eberlm@63295
   908
    by (simp add: euclidean_representation)
eberlm@63295
   909
  also from integrable have "\<dots> = (\<Sum>a\<in>Basis. integral A (\<lambda>x. (f x \<bullet> a) *\<^sub>R a))"
nipkow@64267
   910
    by (subst integral_sum) (simp_all add: o_def)
eberlm@63295
   911
  finally show ?thesis .
eberlm@63295
   912
qed
eberlm@63295
   913
eberlm@63295
   914
lemma integrable_component:
eberlm@63295
   915
  "f integrable_on A \<Longrightarrow> (\<lambda>x. f x \<bullet> (y :: 'b :: euclidean_space)) integrable_on A"
lp15@63938
   916
  by (drule integrable_linear[OF _ bounded_linear_inner_left[of y]]) (simp add: o_def)
eberlm@63295
   917
eberlm@63295
   918
himmelma@35172
   919
nipkow@67968
   920
subsection \<open>Cauchy-type criterion for integrability\<close>
himmelma@35172
   921
lp15@66495
   922
proposition integrable_Cauchy:
immler@56188
   923
  fixes f :: "'n::euclidean_space \<Rightarrow> 'a::{real_normed_vector,complete_space}"
immler@56188
   924
  shows "f integrable_on cbox a b \<longleftrightarrow>
lp15@66192
   925
        (\<forall>e>0. \<exists>\<gamma>. gauge \<gamma> \<and>
lp15@66495
   926
          (\<forall>\<D>1 \<D>2. \<D>1 tagged_division_of (cbox a b) \<and> \<gamma> fine \<D>1 \<and>
lp15@66495
   927
            \<D>2 tagged_division_of (cbox a b) \<and> \<gamma> fine \<D>2 \<longrightarrow>
lp15@66495
   928
            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
   929
  (is "?l = (\<forall>e>0. \<exists>\<gamma>. ?P e \<gamma>)")
lp15@66192
   930
proof (intro iffI allI impI)
wenzelm@53442
   931
  assume ?l
lp15@66192
   932
  then obtain y
lp15@66192
   933
    where y: "\<And>e. e > 0 \<Longrightarrow>
lp15@66192
   934
        \<exists>\<gamma>. gauge \<gamma> \<and>
lp15@66495
   935
            (\<forall>\<D>. \<D> tagged_division_of cbox a b \<and> \<gamma> fine \<D> \<longrightarrow>
lp15@66495
   936
                 norm ((\<Sum>(x,K) \<in> \<D>. content K *\<^sub>R f x) - y) < e)"
lp15@66192
   937
    by (auto simp: integrable_on_def has_integral)
lp15@66192
   938
  show "\<exists>\<gamma>. ?P e \<gamma>" if "e > 0" for e
lp15@66192
   939
  proof -
lp15@66192
   940
    have "e/2 > 0" using that by auto
lp15@66192
   941
    with y obtain \<gamma> where "gauge \<gamma>"
lp15@66495
   942
      and \<gamma>: "\<And>\<D>. \<D> tagged_division_of cbox a b \<and> \<gamma> fine \<D> \<Longrightarrow>
lp15@66495
   943
                  norm ((\<Sum>(x,K)\<in>\<D>. content K *\<^sub>R f x) - y) < e/2"
lp15@66192
   944
      by meson
lp15@66192
   945
    show ?thesis
lp15@66192
   946
    apply (rule_tac x=\<gamma> in exI, clarsimp simp: \<open>gauge \<gamma>\<close>)
lp15@66192
   947
        by (blast intro!: \<gamma> dist_triangle_half_l[where y=y,unfolded dist_norm])
lp15@66192
   948
    qed
lp15@66192
   949
next
lp15@66192
   950
  assume "\<forall>e>0. \<exists>\<gamma>. ?P e \<gamma>"
lp15@66192
   951
  then have "\<forall>n::nat. \<exists>\<gamma>. ?P (1 / (n + 1)) \<gamma>"
lp15@66192
   952
    by auto
lp15@66192
   953
  then obtain \<gamma> :: "nat \<Rightarrow> 'n \<Rightarrow> 'n set" where \<gamma>:
lp15@66192
   954
    "\<And>m. gauge (\<gamma> m)"
lp15@66495
   955
    "\<And>m \<D>1 \<D>2. \<lbrakk>\<D>1 tagged_division_of cbox a b;
lp15@66495
   956
              \<gamma> m fine \<D>1; \<D>2 tagged_division_of cbox a b; \<gamma> m fine \<D>2\<rbrakk>
lp15@66495
   957
              \<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
   958
                  < 1 / (m + 1)"
lp15@66192
   959
    by metis
lp15@66192
   960
  have "\<And>n. gauge (\<lambda>x. \<Inter>{\<gamma> i x |i. i \<in> {0..n}})"
lp15@66192
   961
    apply (rule gauge_Inter)
lp15@66192
   962
    using \<gamma> by auto
lp15@66192
   963
  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
   964
    by (meson fine_division_exists)
lp15@66192
   965
  then obtain p where p: "\<And>z. p z tagged_division_of cbox a b"
lp15@66192
   966
                         "\<And>z. (\<lambda>x. \<Inter>{\<gamma> i x |i. i \<in> {0..z}}) fine p z"
lp15@66192
   967
    by meson
lp15@66192
   968
  have dp: "\<And>i n. i\<le>n \<Longrightarrow> \<gamma> i fine p n"
lp15@66192
   969
    using p unfolding fine_Inter
lp15@66192
   970
    using atLeastAtMost_iff by blast
lp15@66192
   971
  have "Cauchy (\<lambda>n. sum (\<lambda>(x,K). content K *\<^sub>R (f x)) (p n))"
lp15@66192
   972
  proof (rule CauchyI)
lp15@66192
   973
    fix e::real
lp15@66192
   974
    assume "0 < e"
lp15@66192
   975
    then obtain N where "N \<noteq> 0" and N: "inverse (real N) < e"
lp15@66192
   976
      using real_arch_inverse[of e] by blast
lp15@66192
   977
    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
   978
    proof (intro exI allI impI)
lp15@66192
   979
      fix m n
lp15@66192
   980
      assume mn: "N \<le> m" "N \<le> n"
lp15@66192
   981
      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
   982
        by (simp add: p(1) dp mn \<gamma>)
lp15@66192
   983
      also have "... < e"
lp15@66192
   984
        using  N \<open>N \<noteq> 0\<close> \<open>0 < e\<close> by (auto simp: field_simps)
lp15@66192
   985
      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
   986
    qed
wenzelm@53442
   987
  qed
lp15@66192
   988
  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
   989
    by (auto simp: convergent_eq_Cauchy[symmetric] dest: LIMSEQ_D)
wenzelm@53442
   990
  show ?l
wenzelm@53442
   991
    unfolding integrable_on_def has_integral
lp15@60425
   992
  proof (rule_tac x=y in exI, clarify)
wenzelm@53442
   993
    fix e :: real
wenzelm@53442
   994
    assume "e>0"
lp15@66192
   995
    then have e2: "e/2 > 0" by auto
lp15@66406
   996
    then obtain N1::nat where N1: "N1 \<noteq> 0" "inverse (real N1) < e/2"
lp15@66192
   997
      using real_arch_inverse by blast
lp15@66406
   998
    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
   999
      using y[OF e2] by metis
lp15@66192
  1000
    show "\<exists>\<gamma>. gauge \<gamma> \<and>
lp15@66495
  1001
              (\<forall>\<D>. \<D> tagged_division_of (cbox a b) \<and> \<gamma> fine \<D> \<longrightarrow>
lp15@66495
  1002
                norm ((\<Sum>(x,K) \<in> \<D>. content K *\<^sub>R f x) - y) < e)"
lp15@66192
  1003
    proof (intro exI conjI allI impI)
lp15@66192
  1004
      show "gauge (\<gamma> (N1+N2))"
lp15@66192
  1005
        using \<gamma> by auto
lp15@66192
  1006
      show "norm ((\<Sum>(x,K) \<in> q. content K *\<^sub>R f x) - y) < e"
lp15@66192
  1007
           if "q tagged_division_of cbox a b \<and> \<gamma> (N1+N2) fine q" for q
lp15@66192
  1008
      proof (rule norm_triangle_half_r)
lp15@66192
  1009
        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
  1010
               < 1 / (real (N1+N2) + 1)"
lp15@66192
  1011
          by (rule \<gamma>; simp add: dp p that)
lp15@66192
  1012
        also have "... < e/2"
lp15@66192
  1013
          using N1 \<open>0 < e\<close> by (auto simp: field_simps intro: less_le_trans)
lp15@66406
  1014
        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
  1015
        show "norm ((\<Sum>(x,K) \<in> p (N1+N2). content K *\<^sub>R f x) - y) < e/2"
lp15@66192
  1016
          using N2 le_add_same_cancel2 by blast
lp15@66192
  1017
      qed
lp15@66192
  1018
    qed
wenzelm@53442
  1019
  qed
wenzelm@53442
  1020
qed
wenzelm@53442
  1021
himmelma@35172
  1022
nipkow@67968
  1023
subsection \<open>Additivity of integral on abutting intervals\<close>
himmelma@35172
  1024
hoelzl@63957
  1025
lemma tagged_division_split_left_inj_content:
lp15@66164
  1026
  assumes \<D>: "\<D> tagged_division_of S"
lp15@66164
  1027
    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
  1028
  shows "content (K1 \<inter> {x. x\<bullet>k \<le> c}) = 0"
wenzelm@53443
  1029
proof -
lp15@66164
  1030
  from tagged_division_ofD(4)[OF \<D> \<open>(x1, K1) \<in> \<D>\<close>] obtain a b where K1: "K1 = cbox a b"
hoelzl@63957
  1031
    by auto
lp15@66164
  1032
  then have "interior (K1 \<inter> {x. x \<bullet> k \<le> c}) = {}"
lp15@66112
  1033
    by (metis tagged_division_split_left_inj assms)
lp15@66164
  1034
  then show ?thesis
lp15@66164
  1035
    unfolding K1 interval_split[OF \<open>k \<in> Basis\<close>] by (auto simp: content_eq_0_interior)
wenzelm@53443
  1036
qed
wenzelm@53443
  1037
hoelzl@63957
  1038
lemma tagged_division_split_right_inj_content:
lp15@66164
  1039
  assumes \<D>: "\<D> tagged_division_of S"
lp15@66164
  1040
    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
  1041
  shows "content (K1 \<inter> {x. x\<bullet>k \<ge> c}) = 0"
wenzelm@53443
  1042
proof -
lp15@66164
  1043
  from tagged_division_ofD(4)[OF \<D> \<open>(x1, K1) \<in> \<D>\<close>] obtain a b where K1: "K1 = cbox a b"
hoelzl@63957
  1044
    by auto
lp15@66164
  1045
  then have "interior (K1 \<inter> {x. c \<le> x \<bullet> k}) = {}"
lp15@66112
  1046
    by (metis tagged_division_split_right_inj assms)
lp15@66164
  1047
  then show ?thesis
lp15@66164
  1048
    unfolding K1 interval_split[OF \<open>k \<in> Basis\<close>]
lp15@66164
  1049
    by (auto simp: content_eq_0_interior)
wenzelm@53443
  1050
qed
himmelma@35172
  1051
lp15@66164
  1052
lp15@66192
  1053
proposition has_integral_split:
immler@56188
  1054
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::real_normed_vector"
lp15@60435
  1055
  assumes fi: "(f has_integral i) (cbox a b \<inter> {x. x\<bullet>k \<le> c})"
lp15@60435
  1056
      and fj: "(f has_integral j) (cbox a b \<inter> {x. x\<bullet>k \<ge> c})"
lp15@60435
  1057
      and k: "k \<in> Basis"
lp15@66192
  1058
shows "(f has_integral (i + j)) (cbox a b)"
lp15@66192
  1059
  unfolding has_integral
lp15@66192
  1060
proof clarify
lp15@66192
  1061
  fix e::real
lp15@66192
  1062
  assume "0 < e"
wenzelm@53468
  1063
  then have e: "e/2 > 0"
wenzelm@53468
  1064
    by auto
lp15@66192
  1065
    obtain \<gamma>1 where \<gamma>1: "gauge \<gamma>1"
lp15@66192
  1066
      and \<gamma>1norm:
lp15@66495
  1067
        "\<And>\<D>. \<lbrakk>\<D> tagged_division_of cbox a b \<inter> {x. x \<bullet> k \<le> c}; \<gamma>1 fine \<D>\<rbrakk>
lp15@66495
  1068
             \<Longrightarrow> norm ((\<Sum>(x,K) \<in> \<D>. content K *\<^sub>R f x) - i) < e/2"
lp15@60435
  1069
       apply (rule has_integralD[OF fi[unfolded interval_split[OF k]] e])
lp15@60435
  1070
       apply (simp add: interval_split[symmetric] k)
lp15@66192
  1071
      done
lp15@66192
  1072
    obtain \<gamma>2 where \<gamma>2: "gauge \<gamma>2"
lp15@66192
  1073
      and \<gamma>2norm:
lp15@66495
  1074
        "\<And>\<D>. \<lbrakk>\<D> tagged_division_of cbox a b \<inter> {x. c \<le> x \<bullet> k}; \<gamma>2 fine \<D>\<rbrakk>
lp15@66495
  1075
             \<Longrightarrow> norm ((\<Sum>(x, k) \<in> \<D>. content k *\<^sub>R f x) - j) < e/2"
lp15@60435
  1076
       apply (rule has_integralD[OF fj[unfolded interval_split[OF k]] e])
lp15@60435
  1077
       apply (simp add: interval_split[symmetric] k)
lp15@60435
  1078
       done
lp15@66192
  1079
  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
  1080
  have "gauge ?\<gamma>"
lp15@66192
  1081
    using \<gamma>1 \<gamma>2 unfolding gauge_def by auto
lp15@66192
  1082
  then show "\<exists>\<gamma>. gauge \<gamma> \<and>
lp15@66495
  1083
                 (\<forall>\<D>. \<D> tagged_division_of cbox a b \<and> \<gamma> fine \<D> \<longrightarrow>
lp15@66495
  1084
                      norm ((\<Sum>(x, k)\<in>\<D>. content k *\<^sub>R f x) - (i + j)) < e)"
lp15@66192
  1085
  proof (rule_tac x="?\<gamma>" in exI, safe)
wenzelm@53468
  1086
    fix p
lp15@66192
  1087
    assume p: "p tagged_division_of (cbox a b)" and "?\<gamma> fine p"
lp15@66192
  1088
    have ab_eqp: "cbox a b = \<Union>{K. \<exists>x. (x, K) \<in> p}"
lp15@66192
  1089
      using p by blast
lp15@66192
  1090
    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
  1091
    proof (rule ccontr)
lp15@66192
  1092
      assume **: "\<not> x \<bullet> k \<le> c"
lp15@66192
  1093
      then have "K \<subseteq> ball x \<bar>x \<bullet> k - c\<bar>"
lp15@66192
  1094
        using \<open>?\<gamma> fine p\<close> as by (fastforce simp: not_le algebra_simps)
lp15@66192
  1095
      with K obtain y where y: "y \<in> ball x \<bar>x \<bullet> k - c\<bar>" "y\<bullet>k \<le> c"
lp15@66192
  1096
        by blast
lp15@66192
  1097
      then have "\<bar>x \<bullet> k - y \<bullet> k\<bar> < \<bar>x \<bullet> k - c\<bar>"
lp15@66192
  1098
        using Basis_le_norm[OF k, of "x - y"]
lp15@66192
  1099
        by (auto simp add: dist_norm inner_diff_left intro: le_less_trans)
lp15@66192
  1100
      with y show False
lp15@66192
  1101
        using ** by (auto simp add: field_simps)
lp15@60435
  1102
    qed
lp15@66192
  1103
    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
  1104
    proof (rule ccontr)
lp15@66192
  1105
      assume **: "\<not> x \<bullet> k \<ge> c"
lp15@66192
  1106
      then have "K \<subseteq> ball x \<bar>x \<bullet> k - c\<bar>"
lp15@66192
  1107
        using \<open>?\<gamma> fine p\<close> as by (fastforce simp: not_le algebra_simps)
lp15@66192
  1108
      with K obtain y where y: "y \<in> ball x \<bar>x \<bullet> k - c\<bar>" "y\<bullet>k \<ge> c"
lp15@66192
  1109
        by blast
lp15@66192
  1110
      then have "\<bar>x \<bullet> k - y \<bullet> k\<bar> < \<bar>x \<bullet> k - c\<bar>"
lp15@66192
  1111
        using Basis_le_norm[OF k, of "x - y"]
lp15@66192
  1112
        by (auto simp add: dist_norm inner_diff_left intro: le_less_trans)
lp15@66192
  1113
      with y show False
lp15@66192
  1114
        using ** by (auto simp add: field_simps)
wenzelm@53468
  1115
    qed
lp15@66192
  1116
    have fin_finite: "finite {(x,f K) | x K. (x,K) \<in> s \<and> P x K}"
hoelzl@63957
  1117
      if "finite s" for s and f :: "'a set \<Rightarrow> 'a set" and P :: "'a \<Rightarrow> 'a set \<Rightarrow> bool"
wenzelm@53468
  1118
    proof -
lp15@66192
  1119
      from that have "finite ((\<lambda>(x,K). (x, f K)) ` s)"
lp15@60425
  1120
        by auto
wenzelm@61165
  1121
      then show ?thesis
lp15@60425
  1122
        by (rule rev_finite_subset) auto
wenzelm@53468
  1123
    qed
lp15@66192
  1124
    { fix \<G> :: "'a set \<Rightarrow> 'a set"
wenzelm@53468
  1125
      fix i :: "'a \<times> 'a set"
lp15@66192
  1126
      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
  1127
      then obtain x K where xk: "i = (x, \<G> K)"  "(x,K) \<in> p"
lp15@66192
  1128
                                 "(x, \<G> K) \<notin> {(x, \<G> K) |x K. (x,K) \<in> p \<and> \<G> K \<noteq> {}}"
lp15@66192
  1129
        by auto
lp15@66192
  1130
      have "content (\<G> K) = 0"
wenzelm@53468
  1131
        using xk using content_empty by auto
lp15@66192
  1132
      then have "(\<lambda>(x,K). content K *\<^sub>R f x) i = 0"
wenzelm@53468
  1133
        unfolding xk split_conv by auto
lp15@60435
  1134
    } note [simp] = this
lp15@66192
  1135
    have "finite p"
lp15@66192
  1136
      using p by blast
lp15@66192
  1137
    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
  1138
    have \<gamma>1_fine: "\<gamma>1 fine ?M1"
lp15@66192
  1139
      using \<open>?\<gamma> fine p\<close> by (fastforce simp: fine_def split: if_split_asm)
wenzelm@53468
  1140
    have "norm ((\<Sum>(x, k)\<in>?M1. content k *\<^sub>R f x) - i) < e/2"
lp15@66192
  1141
    proof (rule \<gamma>1norm [OF tagged_division_ofI \<gamma>1_fine])
lp15@60435
  1142
      show "finite ?M1"
lp15@66192
  1143
        by (rule fin_finite) (use p in blast)
immler@56188
  1144
      show "\<Union>{k. \<exists>x. (x, k) \<in> ?M1} = cbox a b \<inter> {x. x\<bullet>k \<le> c}"
lp15@66192
  1145
        by (auto simp: ab_eqp)
lp15@66192
  1146
lp15@66192
  1147
      fix x L
lp15@66192
  1148
      assume xL: "(x, L) \<in> ?M1"
lp15@66192
  1149
      then obtain x' L' where xL': "x = x'" "L = L' \<inter> {x. x \<bullet> k \<le> c}"
lp15@66192
  1150
                                   "(x', L') \<in> p" "L' \<inter> {x. x \<bullet> k \<le> c} \<noteq> {}"
lp15@66192
  1151
        by blast
lp15@66192
  1152
      then obtain a' b' where ab': "L' = cbox a' b'"
lp15@66192
  1153
        using p by blast
lp15@66192
  1154
      show "x \<in> L" "L \<subseteq> cbox a b \<inter> {x. x \<bullet> k \<le> c}"
lp15@66192
  1155
        using p xk_le_c xL' by auto
lp15@66192
  1156
      show "\<exists>a b. L = cbox a b"
lp15@66192
  1157
        using p xL' ab' by (auto simp add: interval_split[OF k,where c=c])
lp15@66192
  1158
lp15@66192
  1159
      fix y R
lp15@66192
  1160
      assume yR: "(y, R) \<in> ?M1"
lp15@66192
  1161
      then obtain y' R' where yR': "y = y'" "R = R' \<inter> {x. x \<bullet> k \<le> c}"
lp15@66192
  1162
                                   "(y', R') \<in> p" "R' \<inter> {x. x \<bullet> k \<le> c} \<noteq> {}"
lp15@66192
  1163
        by blast
lp15@66192
  1164
      assume as: "(x, L) \<noteq> (y, R)"
lp15@66192
  1165
      show "interior L \<inter> interior R = {}"
lp15@66192
  1166
      proof (cases "L' = R' \<longrightarrow> x' = y'")
wenzelm@53468
  1167
        case False
lp15@66192
  1168
        have "interior R' = {}"
lp15@66192
  1169
          by (metis (no_types) False Pair_inject inf.idem tagged_division_ofD(5) [OF p] xL'(3) yR'(3))
wenzelm@53468
  1170
        then show ?thesis
lp15@66192
  1171
          using yR' by simp
wenzelm@53468
  1172
      next
wenzelm@53468
  1173
        case True
lp15@66192
  1174
        then have "L' \<noteq> R'"
lp15@66192
  1175
          using as unfolding xL' yR' by auto
lp15@66192
  1176
        have "interior L' \<inter> interior R' = {}"
lp15@66192
  1177
          by (metis (no_types) Pair_inject \<open>L' \<noteq> R'\<close> p tagged_division_ofD(5) xL'(3) yR'(3))
wenzelm@53468
  1178
        then show ?thesis
lp15@66192
  1179
          using xL'(2) yR'(2) by auto
himmelma@35172
  1180
      qed
himmelma@35172
  1181
    qed
wenzelm@53468
  1182
    moreover
lp15@66192
  1183
    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
  1184
    have \<gamma>2_fine: "\<gamma>2 fine ?M2"
lp15@66192
  1185
      using \<open>?\<gamma> fine p\<close> by (fastforce simp: fine_def split: if_split_asm)
wenzelm@53468
  1186
    have "norm ((\<Sum>(x, k)\<in>?M2. content k *\<^sub>R f x) - j) < e/2"
lp15@66192
  1187
    proof (rule \<gamma>2norm [OF tagged_division_ofI \<gamma>2_fine])
lp15@60435
  1188
      show "finite ?M2"
lp15@66192
  1189
        by (rule fin_finite) (use p in blast)
immler@56188
  1190
      show "\<Union>{k. \<exists>x. (x, k) \<in> ?M2} = cbox a b \<inter> {x. x\<bullet>k \<ge> c}"
lp15@66192
  1191
        by (auto simp: ab_eqp)
lp15@66192
  1192
lp15@66192
  1193
      fix x L
lp15@66192
  1194
      assume xL: "(x, L) \<in> ?M2"
lp15@66192
  1195
      then obtain x' L' where xL': "x = x'" "L = L' \<inter> {x. x \<bullet> k \<ge> c}"
lp15@66192
  1196
                                   "(x', L') \<in> p" "L' \<inter> {x. x \<bullet> k \<ge> c} \<noteq> {}"
lp15@66192
  1197
        by blast
lp15@66192
  1198
      then obtain a' b' where ab': "L' = cbox a' b'"
lp15@66192
  1199
        using p by blast
lp15@66192
  1200
      show "x \<in> L" "L \<subseteq> cbox a b \<inter> {x. x \<bullet> k \<ge> c}"
lp15@66192
  1201
        using p xk_ge_c xL' by auto
lp15@66192
  1202
      show "\<exists>a b. L = cbox a b"
lp15@66192
  1203
        using p xL' ab' by (auto simp add: interval_split[OF k,where c=c])
lp15@66192
  1204
lp15@66192
  1205
      fix y R
lp15@66192
  1206
      assume yR: "(y, R) \<in> ?M2"
lp15@66192
  1207
      then obtain y' R' where yR': "y = y'" "R = R' \<inter> {x. x \<bullet> k \<ge> c}"
lp15@66192
  1208
                                   "(y', R') \<in> p" "R' \<inter> {x. x \<bullet> k \<ge> c} \<noteq> {}"
lp15@66192
  1209
        by blast
lp15@66192
  1210
      assume as: "(x, L) \<noteq> (y, R)"
lp15@66192
  1211
      show "interior L \<inter> interior R = {}"
lp15@66192
  1212
      proof (cases "L' = R' \<longrightarrow> x' = y'")
wenzelm@53468
  1213
        case False
lp15@66192
  1214
        have "interior R' = {}"
lp15@66192
  1215
          by (metis (no_types) False Pair_inject inf.idem tagged_division_ofD(5) [OF p] xL'(3) yR'(3))
wenzelm@53468
  1216
        then show ?thesis
lp15@66192
  1217
          using yR' by simp
wenzelm@53468
  1218
      next
wenzelm@53468
  1219
        case True
lp15@66192
  1220
        then have "L' \<noteq> R'"
lp15@66192
  1221
          using as unfolding xL' yR' by auto
lp15@66192
  1222
        have "interior L' \<inter> interior R' = {}"
lp15@66192
  1223
          by (metis (no_types) Pair_inject \<open>L' \<noteq> R'\<close> p tagged_division_ofD(5) xL'(3) yR'(3))
wenzelm@53468
  1224
        then show ?thesis
lp15@66192
  1225
          using xL'(2) yR'(2) by auto
wenzelm@53468
  1226
      qed
wenzelm@53468
  1227
    qed
wenzelm@53468
  1228
    ultimately
lp15@66192
  1229
    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
  1230
      using norm_add_less by blast
lp15@66192
  1231
    moreover have "((\<Sum>(x,K) \<in> ?M1. content K *\<^sub>R f x) - i) +
lp15@66192
  1232
                   ((\<Sum>(x,K) \<in> ?M2. content K *\<^sub>R f x) - j) =
lp15@66192
  1233
                   (\<Sum>(x, ka)\<in>p. content ka *\<^sub>R f x) - (i + j)"
lp15@66192
  1234
    proof -
lp15@60435
  1235
      have eq0: "\<And>x y. x = (0::real) \<Longrightarrow> x *\<^sub>R (y::'b) = 0"
lp15@66192
  1236
         by auto
lp15@60435
  1237
      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
  1238
        by auto
lp15@66192
  1239
      have *: "\<And>\<G> :: 'a set \<Rightarrow> 'a set.
lp15@66192
  1240
                  (\<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
  1241
                  (\<Sum>(x,K)\<in>(\<lambda>(x,K). (x, \<G> K)) ` p. content K *\<^sub>R f x)"
lp15@66192
  1242
        by (rule sum.mono_neutral_left) (auto simp: \<open>finite p\<close>)
wenzelm@53468
  1243
      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
  1244
        (\<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
  1245
        by auto
lp15@66192
  1246
      moreover have "\<dots> = (\<Sum>(x,K) \<in> p. content (K \<inter> {x. x \<bullet> k \<le> c}) *\<^sub>R f x) +
lp15@66192
  1247
        (\<Sum>(x,K) \<in> p. content (K \<inter> {x. c \<le> x \<bullet> k}) *\<^sub>R f x) - (i + j)"
lp15@66192
  1248
        unfolding *
lp15@66192
  1249
        apply (subst (1 2) sum.reindex_nontrivial)
lp15@66192
  1250
           apply (auto intro!: k p eq0 tagged_division_split_left_inj_content tagged_division_split_right_inj_content
lp15@66192
  1251
                       simp: cont_eq \<open>finite p\<close>)
lp15@66192
  1252
        done
lp15@66192
  1253
      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
  1254
                                (\<lambda>(a,B). content (B \<inter> {a. c \<le> a \<bullet> k}) *\<^sub>R f a) x =
lp15@66192
  1255
                                (\<lambda>(a,B). content B *\<^sub>R f a) x"
lp15@60435
  1256
      proof clarify
lp15@66192
  1257
        fix a B
lp15@66192
  1258
        assume "(a, B) \<in> p"
lp15@66192
  1259
        with p obtain u v where uv: "B = cbox u v" by blast
lp15@66192
  1260
        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
  1261
          by (auto simp: scaleR_left_distrib uv content_split[OF k,of u v c])
wenzelm@53468
  1262
      qed
lp15@66192
  1263
      ultimately show ?thesis
lp15@66192
  1264
        by (auto simp: sum.distrib[symmetric])
lp15@66192
  1265
      qed
lp15@66192
  1266
    ultimately show "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - (i + j)) < e"
wenzelm@53468
  1267
      by auto
wenzelm@53468
  1268
  qed
wenzelm@53468
  1269
qed
wenzelm@53468
  1270
himmelma@35172
  1271
nipkow@67968
  1272
subsection \<open>A sort of converse, integrability on subintervals\<close>
himmelma@35172
  1273
wenzelm@53494
  1274
lemma has_integral_separate_sides:
immler@56188
  1275
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::real_normed_vector"
lp15@66359
  1276
  assumes f: "(f has_integral i) (cbox a b)"
wenzelm@53494
  1277
    and "e > 0"
wenzelm@53494
  1278
    and k: "k \<in> Basis"
wenzelm@53494
  1279
  obtains d where "gauge d"
immler@56188
  1280
    "\<forall>p1 p2. p1 tagged_division_of (cbox a b \<inter> {x. x\<bullet>k \<le> c}) \<and> d fine p1 \<and>
immler@56188
  1281
        p2 tagged_division_of (cbox a b \<inter> {x. x\<bullet>k \<ge> c}) \<and> d fine p2 \<longrightarrow>
nipkow@64267
  1282
        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
  1283
proof -
lp15@66359
  1284
  obtain \<gamma> where d: "gauge \<gamma>"
lp15@66359
  1285
      "\<And>p. \<lbrakk>p tagged_division_of cbox a b; \<gamma> fine p\<rbrakk>
lp15@66359
  1286
            \<Longrightarrow> norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - i) < e"
lp15@66359
  1287
    using has_integralD[OF f \<open>e > 0\<close>] by metis
lp15@60428
  1288
  { fix p1 p2
lp15@66359
  1289
    assume tdiv1: "p1 tagged_division_of (cbox a b) \<inter> {x. x \<bullet> k \<le> c}" and "\<gamma> fine p1"
lp15@66359
  1290
    note p1=tagged_division_ofD[OF this(1)] 
lp15@66359
  1291
    assume tdiv2: "p2 tagged_division_of (cbox a b) \<inter> {x. c \<le> x \<bullet> k}" and "\<gamma> fine p2"
lp15@66359
  1292
    note p2=tagged_division_ofD[OF this(1)] 
lp15@66497
  1293
    note tagged_division_Un_interval[OF tdiv1 tdiv2] 
lp15@66359
  1294
    note p12 = tagged_division_ofD[OF this] this
lp15@60428
  1295
    { fix a b
wenzelm@53494
  1296
      assume ab: "(a, b) \<in> p1 \<inter> p2"
wenzelm@53494
  1297
      have "(a, b) \<in> p1"
wenzelm@53494
  1298
        using ab by auto
lp15@66359
  1299
      obtain u v where uv: "b = cbox u v"
lp15@66359
  1300
        using \<open>(a, b) \<in> p1\<close> p1(4) by moura
wenzelm@53494
  1301
      have "b \<subseteq> {x. x\<bullet>k = c}"
wenzelm@53494
  1302
        using ab p1(3)[of a b] p2(3)[of a b] by fastforce
wenzelm@53494
  1303
      moreover
wenzelm@53494
  1304
      have "interior {x::'a. x \<bullet> k = c} = {}"
wenzelm@53494
  1305
      proof (rule ccontr)
wenzelm@53494
  1306
        assume "\<not> ?thesis"
wenzelm@53494
  1307
        then obtain x where x: "x \<in> interior {x::'a. x\<bullet>k = c}"
wenzelm@53494
  1308
          by auto
lp15@66359
  1309
        then obtain \<epsilon> where "0 < \<epsilon>" and \<epsilon>: "ball x \<epsilon> \<subseteq> {x. x \<bullet> k = c}"
lp15@66359
  1310
          using mem_interior by metis
wenzelm@53494
  1311
        have x: "x\<bullet>k = c"
wenzelm@53494
  1312
          using x interior_subset by fastforce
lp15@66532
  1313
        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
  1314
          using \<open>0 < \<epsilon>\<close> k by (auto simp: inner_simps inner_not_same_Basis)
lp15@66532
  1315
        have "(\<Sum>i\<in>Basis. \<bar>(x - (x + (\<epsilon>/2 ) *\<^sub>R k)) \<bullet> i\<bar>) =
lp15@66532
  1316
              (\<Sum>i\<in>Basis. (if i = k then \<epsilon>/2 else 0))"
nipkow@64267
  1317
          using "*" by (blast intro: sum.cong)
lp15@66359
  1318
        also have "\<dots> < \<epsilon>"
lp15@66359
  1319
          by (subst sum.delta) (use \<open>0 < \<epsilon>\<close> in auto)
lp15@66359
  1320
        finally have "x + (\<epsilon>/2) *\<^sub>R k \<in> ball x \<epsilon>"
hoelzl@50526
  1321
          unfolding mem_ball dist_norm by(rule le_less_trans[OF norm_le_l1])
lp15@66359
  1322
        then have "x + (\<epsilon>/2) *\<^sub>R k \<in> {x. x\<bullet>k = c}"
lp15@66359
  1323
          using \<epsilon> by auto
wenzelm@53494
  1324
        then show False
lp15@66359
  1325
          using \<open>0 < \<epsilon>\<close> x k by (auto simp: inner_simps)
wenzelm@53494
  1326
      qed
wenzelm@53494
  1327
      ultimately have "content b = 0"
wenzelm@53494
  1328
        unfolding uv content_eq_0_interior
lp15@60428
  1329
        using interior_mono by blast
lp15@60428
  1330
      then have "content b *\<^sub>R f a = 0"
wenzelm@53494
  1331
        by auto
lp15@60428
  1332
    }
lp15@60428
  1333
    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
  1334
               norm ((\<Sum>(x, k)\<in>p1 \<union> p2. content k *\<^sub>R f x) - i)"
nipkow@64267
  1335
      by (subst sum.union_inter_neutral) (auto simp: p1 p2)
wenzelm@53494
  1336
    also have "\<dots> < e"
lp15@66359
  1337
      using d(2) p12 by (simp add: fine_Un k \<open>\<gamma> fine p1\<close> \<open>\<gamma> fine p2\<close>)
lp15@60428
  1338
    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
  1339
   }
lp15@60428
  1340
  then show ?thesis
lp15@66359
  1341
    using d(1) that by auto
wenzelm@53494
  1342
qed
himmelma@35172
  1343
lp15@66154
  1344
lemma integrable_split [intro]:
immler@56188
  1345
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::{real_normed_vector,complete_space}"
lp15@66154
  1346
  assumes f: "f integrable_on cbox a b"
lp15@66154
  1347
      and k: "k \<in> Basis"
lp15@66164
  1348
    shows "f integrable_on (cbox a b \<inter> {x. x\<bullet>k \<le> c})"   (is ?thesis1)
lp15@66154
  1349
    and   "f integrable_on (cbox a b \<inter> {x. x\<bullet>k \<ge> c})"   (is ?thesis2)
wenzelm@53494
  1350
proof -
lp15@66154
  1351
  obtain y where y: "(f has_integral y) (cbox a b)"
lp15@66154
  1352
    using f by blast
wenzelm@63040
  1353
  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
  1354
  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
  1355
  have "\<exists>d. gauge d \<and>
lp15@66154
  1356
            (\<forall>p1 p2. p1 tagged_division_of cbox a b \<inter> {x. x \<bullet> k \<le> c} \<and> d fine p1 \<and>
lp15@66154
  1357
                     p2 tagged_division_of cbox a b \<inter> {x. x \<bullet> k \<le> c} \<and> d fine p2 \<longrightarrow>
lp15@66154
  1358
                     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
  1359
    if "e > 0" for e
lp15@66154
  1360
  proof -
lp15@66154
  1361
    have "e/2 > 0" using that by auto
lp15@66164
  1362
  with has_integral_separate_sides[OF y this k, of c]
lp15@66164
  1363
  obtain d
lp15@66154
  1364
    where "gauge d"
lp15@66164
  1365
         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
  1366
                          p2 tagged_division_of cbox a b \<inter> {x. c \<le> x \<bullet> k}; d fine p2\<rbrakk>
lp15@66164
  1367
                  \<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
  1368
    by metis
lp15@66154
  1369
  show ?thesis
lp15@66154
  1370
    proof (rule_tac x=d in exI, clarsimp simp add: \<open>gauge d\<close>)
wenzelm@53494
  1371
      fix p1 p2
lp15@60428
  1372
      assume as: "p1 tagged_division_of (cbox a b) \<inter> {x. x \<bullet> k \<le> c}" "d fine p1"
lp15@60428
  1373
                 "p2 tagged_division_of (cbox a b) \<inter> {x. x \<bullet> k \<le> c}" "d fine p2"
himmelma@35172
  1374
      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
  1375
      proof (rule fine_division_exists[OF \<open>gauge d\<close>, of a' b])
lp15@60428
  1376
        fix p
lp15@60428
  1377
        assume "p tagged_division_of cbox a' b" "d fine p"
lp15@60428
  1378
        then show ?thesis
lp15@66154
  1379
          using as norm_triangle_half_l[OF d[of p1 p] d[of p2 p]]
lp15@60428
  1380
          unfolding interval_split[OF k] b'_def[symmetric] a'_def[symmetric]
wenzelm@53494
  1381
          by (auto simp add: algebra_simps)
wenzelm@53494
  1382
      qed
wenzelm@53494
  1383
    qed
lp15@66164
  1384
  qed
lp15@66154
  1385
  with f show ?thesis1
lp15@66192
  1386
    by (simp add: interval_split[OF k] integrable_Cauchy)
lp15@66154
  1387
  have "\<exists>d. gauge d \<and>
lp15@66154
  1388
            (\<forall>p1 p2. p1 tagged_division_of cbox a b \<inter> {x. x \<bullet> k \<ge> c} \<and> d fine p1 \<and>
lp15@66154
  1389
                     p2 tagged_division_of cbox a b \<inter> {x. x \<bullet> k \<ge> c} \<and> d fine p2 \<longrightarrow>
lp15@66154
  1390
                     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
  1391
    if "e > 0" for e
lp15@66154
  1392
  proof -
lp15@66154
  1393
    have "e/2 > 0" using that by auto
lp15@66164
  1394
  with has_integral_separate_sides[OF y this k, of c]
lp15@66164
  1395
  obtain d
lp15@66154
  1396
    where "gauge d"
lp15@66164
  1397
         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
  1398
                          p2 tagged_division_of cbox a b \<inter> {x. c \<le> x \<bullet> k}; d fine p2\<rbrakk>
lp15@66164
  1399
                  \<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
  1400
    by metis
lp15@66154
  1401
  show ?thesis
lp15@66154
  1402
    proof (rule_tac x=d in exI, clarsimp simp add: \<open>gauge d\<close>)
wenzelm@53494
  1403
      fix p1 p2
lp15@60428
  1404
      assume as: "p1 tagged_division_of (cbox a b) \<inter> {x. x \<bullet> k \<ge> c}" "d fine p1"
lp15@60428
  1405
                 "p2 tagged_division_of (cbox a b) \<inter> {x. x \<bullet> k \<ge> c}" "d fine p2"
himmelma@35172
  1406
      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
  1407
      proof (rule fine_division_exists[OF \<open>gauge d\<close>, of a b'])
lp15@60428
  1408
        fix p
lp15@60428
  1409
        assume "p tagged_division_of cbox a b'" "d fine p"
lp15@60428
  1410
        then show ?thesis
lp15@66154
  1411
          using as norm_triangle_half_l[OF d[of p p1] d[of p p2]]
wenzelm@53494
  1412
          unfolding interval_split[OF k] b'_def[symmetric] a'_def[symmetric]
wenzelm@53520
  1413
          by (auto simp add: algebra_simps)
wenzelm@53494
  1414
      qed
wenzelm@53494
  1415
    qed
lp15@66164
  1416
  qed
lp15@66154
  1417
  with f show ?thesis2
lp15@66192
  1418
    by (simp add: interval_split[OF k] integrable_Cauchy)
wenzelm@53494
  1419
qed
wenzelm@53494
  1420
haftmann@66492
  1421
lemma operative_integralI:
immler@56188
  1422
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::banach"
nipkow@67399
  1423
  shows "operative (lift_option (+)) (Some 0)
haftmann@63659
  1424
    (\<lambda>i. if f integrable_on i then Some (integral i f) else None)"
haftmann@63659
  1425
proof -
haftmann@63659
  1426
  interpret comm_monoid "lift_option plus" "Some (0::'b)"
haftmann@63659
  1427
    by (rule comm_monoid_lift_option)
haftmann@63659
  1428
      (rule add.comm_monoid_axioms)
haftmann@63659
  1429
  show ?thesis
haftmann@66492
  1430
  proof
haftmann@63659
  1431
    fix a b c
haftmann@63659
  1432
    fix k :: 'a
haftmann@63659
  1433
    assume k: "k \<in> Basis"
haftmann@63659
  1434
    show "(if f integrable_on cbox a b then Some (integral (cbox a b) f) else None) =
nipkow@67399
  1435
          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
  1436
          (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
  1437
    proof (cases "f integrable_on cbox a b")
haftmann@63659
  1438
      case True
haftmann@63659
  1439
      with k show ?thesis
haftmann@63659
  1440
        apply (simp add: integrable_split)
haftmann@63659
  1441
        apply (rule integral_unique [OF has_integral_split[OF _ _ k]])
lp15@60440
  1442
        apply (auto intro: integrable_integral)
wenzelm@53494
  1443
        done
haftmann@63659
  1444
    next
haftmann@63659
  1445
    case False
haftmann@63659
  1446
      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
  1447
      proof (rule ccontr)
haftmann@63659
  1448
        assume "\<not> ?thesis"
haftmann@63659
  1449
        then have "f integrable_on cbox a b"
haftmann@63659
  1450
          unfolding integrable_on_def
haftmann@63659
  1451
          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
  1452
          apply (rule has_integral_split[OF _ _ k])
haftmann@63659
  1453
          apply (auto intro: integrable_integral)
haftmann@63659
  1454
          done
haftmann@63659
  1455
        then show False
haftmann@63659
  1456
          using False by auto
haftmann@63659
  1457
      qed
haftmann@63659
  1458
      then show ?thesis
wenzelm@53494
  1459
        using False by auto
wenzelm@53494
  1460
    qed
haftmann@63659
  1461
  next
haftmann@63659
  1462
    fix a b :: 'a
hoelzl@63957
  1463
    assume "box a b = {}"
haftmann@63659
  1464
    then show "(if f integrable_on cbox a b then Some (integral (cbox a b) f) else None) = Some 0"
haftmann@63659
  1465
      using has_integral_null_eq
hoelzl@63957
  1466
      by (auto simp: integrable_on_null content_eq_0_interior)
haftmann@63659
  1467
  qed
wenzelm@53494
  1468
qed
wenzelm@53494
  1469
nipkow@67968
  1470
subsection \<open>Bounds on the norm of Riemann sums and the integral itself\<close>
himmelma@35172
  1471
wenzelm@53494
  1472
lemma dsum_bound:
immler@56188
  1473
  assumes "p division_of (cbox a b)"
wenzelm@53494
  1474
    and "norm c \<le> e"
nipkow@64267
  1475
  shows "norm (sum (\<lambda>l. content l *\<^sub>R c) p) \<le> e * content(cbox a b)"
lp15@60467
  1476
proof -
nipkow@64267
  1477
  have sumeq: "(\<Sum>i\<in>p. \<bar>content i\<bar>) = sum content p"
nipkow@64267
  1478
    apply (rule sum.cong)
lp15@60467
  1479
    using assms
lp15@60467
  1480
    apply simp
lp15@60467
  1481
    apply (metis abs_of_nonneg assms(1) content_pos_le division_ofD(4))
lp15@60467
  1482
    done
lp15@60467
  1483
  have e: "0 \<le> e"
lp15@60467
  1484
    using assms(2) norm_ge_zero order_trans by blast
nipkow@64267
  1485
  have "norm (sum (\<lambda>l. content l *\<^sub>R c) p) \<le> (\<Sum>i\<in>p. norm (content i *\<^sub>R c))"
nipkow@64267
  1486
    using norm_sum by blast
lp15@60467
  1487
  also have "...  \<le> e * (\<Sum>i\<in>p. \<bar>content i\<bar>)"
nipkow@64267
  1488
    by (simp add: sum_distrib_left[symmetric] mult.commute assms(2) mult_right_mono sum_nonneg)
lp15@60467
  1489
  also have "... \<le> e * content (cbox a b)"
lp15@60467
  1490
    apply (rule mult_left_mono [OF _ e])
lp15@60467
  1491
    apply (simp add: sumeq)
lp15@60467
  1492
    using additive_content_division assms(1) eq_iff apply blast
lp15@60467
  1493
    done
lp15@60467
  1494
  finally show ?thesis .
lp15@60467
  1495
qed
wenzelm@53494
  1496
wenzelm@53494
  1497
lemma rsum_bound:
lp15@60472
  1498
  assumes p: "p tagged_division_of (cbox a b)"
lp15@60472
  1499
      and "\<forall>x\<in>cbox a b. norm (f x) \<le> e"
nipkow@64267
  1500
    shows "norm (sum (\<lambda>(x,k). content k *\<^sub>R f x) p) \<le> e * content (cbox a b)"
immler@56188
  1501
proof (cases "cbox a b = {}")
lp15@60472
  1502
  case True show ?thesis
lp15@60472
  1503
    using p unfolding True tagged_division_of_trivial by auto
wenzelm@53494
  1504
next
wenzelm@53494
  1505
  case False
lp15@60472
  1506
  then have e: "e \<ge> 0"
lp15@63018
  1507
    by (meson ex_in_conv assms(2) norm_ge_zero order_trans)
nipkow@64267
  1508
  have sum_le: "sum (content \<circ> snd) p \<le> content (cbox a b)"
lp15@60472
  1509
    unfolding additive_content_tagged_division[OF p, symmetric] split_def
lp15@60472
  1510
    by (auto intro: eq_refl)
lp15@60472
  1511
  have con: "\<And>xk. xk \<in> p \<Longrightarrow> 0 \<le> content (snd xk)"
lp15@60472
  1512
    using tagged_division_ofD(4) [OF p] content_pos_le
lp15@60472
  1513
    by force
lp15@60472
  1514
  have norm: "\<And>xk. xk \<in> p \<Longrightarrow> norm (f (fst xk)) \<le> e"
lp15@60472
  1515
    unfolding fst_conv using tagged_division_ofD(2,3)[OF p] assms
lp15@60472
  1516
    by (metis prod.collapse subset_eq)
nipkow@64267
  1517
  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
  1518
    by (rule norm_sum)
lp15@60472
  1519
  also have "...  \<le> e * content (cbox a b)"
wenzelm@53494
  1520
    unfolding split_def norm_scaleR
nipkow@64267
  1521
    apply (rule order_trans[OF sum_mono])
wenzelm@53494
  1522
    apply (rule mult_left_mono[OF _ abs_ge_zero, of _ e])
lp15@60472
  1523
    apply (metis norm)
nipkow@64267
  1524
    unfolding sum_distrib_right[symmetric]
nipkow@64267
  1525
    using con sum_le
lp15@60472
  1526
    apply (auto simp: mult.commute intro: mult_left_mono [OF _ e])
lp15@60472
  1527
    done
lp15@60472
  1528
  finally show ?thesis .
wenzelm@53494
  1529
qed
himmelma@35172
  1530
himmelma@35172
  1531
lemma rsum_diff_bound:
immler@56188
  1532
  assumes "p tagged_division_of (cbox a b)"
immler@56188
  1533
    and "\<forall>x\<in>cbox a b. norm (f x - g x) \<le> e"
nipkow@64267
  1534
  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
  1535
         e * content (cbox a b)"
wenzelm@53494
  1536
  apply (rule order_trans[OF _ rsum_bound[OF assms]])
nipkow@64267
  1537
  apply (simp add: split_def scaleR_diff_right sum_subtractf eq_refl)
wenzelm@53494
  1538
  done
wenzelm@53494
  1539
wenzelm@53494
  1540
lemma has_integral_bound:
immler@56188
  1541
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::real_normed_vector"
wenzelm@53494
  1542
  assumes "0 \<le> B"
lp15@66192
  1543
      and f: "(f has_integral i) (cbox a b)"
lp15@66192
  1544
      and "\<And>x. x\<in>cbox a b \<Longrightarrow> norm (f x) \<le> B"
lp15@60472
  1545
    shows "norm i \<le> B * content (cbox a b)"
lp15@60472
  1546
proof (rule ccontr)
wenzelm@53494
  1547
  assume "\<not> ?thesis"
lp15@66192
  1548
  then have "norm i - B * content (cbox a b) > 0"
wenzelm@53494
  1549
    by auto
lp15@66192
  1550
  with f[unfolded has_integral]
lp15@66192
  1551
  obtain \<gamma> where "gauge \<gamma>" and \<gamma>:
lp15@66192
  1552
    "\<And>p. \<lbrakk>p tagged_division_of cbox a b; \<gamma> fine p\<rbrakk>
lp15@66192
  1553
          \<Longrightarrow> norm ((\<Sum>(x, K)\<in>p. content K *\<^sub>R f x) - i) < norm i - B * content (cbox a b)"
lp15@66192
  1554
    by metis
lp15@66192
  1555
  then obtain p where p: "p tagged_division_of cbox a b" and "\<gamma> fine p"
lp15@66192
  1556
    using fine_division_exists by blast
lp15@66192
  1557
  have "\<And>s B. norm s \<le> B \<Longrightarrow> \<not> norm (s - i) < norm i - B"
lp15@60472
  1558
    unfolding not_less
lp15@66192
  1559
    by (metis diff_left_mono dist_commute dist_norm norm_triangle_ineq2 order_trans)
lp15@66192
  1560
  then show False
lp15@66192
  1561
    using \<gamma> [OF p \<open>\<gamma> fine p\<close>] rsum_bound[OF p] assms by metis
wenzelm@53494
  1562
qed
wenzelm@53494
  1563
lp15@60615
  1564
corollary integrable_bound:
lp15@60615
  1565
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::real_normed_vector"
lp15@60615
  1566
  assumes "0 \<le> B"
lp15@60615
  1567
      and "f integrable_on (cbox a b)"
lp15@60615
  1568
      and "\<And>x. x\<in>cbox a b \<Longrightarrow> norm (f x) \<le> B"
lp15@60615
  1569
    shows "norm (integral (cbox a b) f) \<le> B * content (cbox a b)"
lp15@60615
  1570
by (metis integrable_integral has_integral_bound assms)
immler@56188
  1571
himmelma@35172
  1572
nipkow@67968
  1573
subsection \<open>Similar theorems about relationship among components\<close>
himmelma@35172
  1574
wenzelm@53494
  1575
lemma rsum_component_le:
immler@56188
  1576
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
lp15@66192
  1577
  assumes p: "p tagged_division_of (cbox a b)"
lp15@66192
  1578
      and "\<And>x. x \<in> cbox a b \<Longrightarrow> (f x)\<bullet>i \<le> (g x)\<bullet>i"
lp15@66192
  1579
    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
  1580
unfolding inner_sum_left
nipkow@64267
  1581
proof (rule sum_mono, clarify)
lp15@66192
  1582
  fix x K
lp15@66192
  1583
  assume ab: "(x, K) \<in> p"
lp15@66192
  1584
  with p obtain u v where K: "K = cbox u v"
lp15@66192
  1585
    by blast
lp15@66192
  1586
  then show "(content K *\<^sub>R f x) \<bullet> i \<le> (content K *\<^sub>R g x) \<bullet> i"
lp15@66192
  1587
    by (metis ab assms inner_scaleR_left measure_nonneg mult_left_mono tag_in_interval)
wenzelm@53494
  1588
qed
himmelma@35172
  1589
hoelzl@50526
  1590
lemma has_integral_component_le:
immler@56188
  1591
  fixes f g :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
hoelzl@50526
  1592
  assumes k: "k \<in> Basis"
lp15@66199
  1593
  assumes "(f has_integral i) S" "(g has_integral j) S"
lp15@66199
  1594
    and f_le_g: "\<And>x. x \<in> S \<Longrightarrow> (f x)\<bullet>k \<le> (g x)\<bullet>k"
hoelzl@50526
  1595
  shows "i\<bullet>k \<le> j\<bullet>k"
hoelzl@50348
  1596
proof -
lp15@66199
  1597
  have ik_le_jk: "i\<bullet>k \<le> j\<bullet>k"
wenzelm@61165
  1598
    if f_i: "(f has_integral i) (cbox a b)"
wenzelm@61165
  1599
    and g_j: "(g has_integral j) (cbox a b)"
wenzelm@61165
  1600
    and le: "\<forall>x\<in>cbox a b. (f x)\<bullet>k \<le> (g x)\<bullet>k"
wenzelm@61165
  1601
    for a b i and j :: 'b and f g :: "'a \<Rightarrow> 'b"
hoelzl@50348
  1602
  proof (rule ccontr)
wenzelm@61165
  1603
    assume "\<not> ?thesis"
wenzelm@53494
  1604
    then have *: "0 < (i\<bullet>k - j\<bullet>k) / 3"
wenzelm@53494
  1605
      by auto
lp15@66199
  1606
    obtain \<gamma>1 where "gauge \<gamma>1" 
lp15@66199
  1607
      and \<gamma>1: "\<And>p. \<lbrakk>p tagged_division_of cbox a b; \<gamma>1 fine p\<rbrakk>
lp15@66199
  1608
                \<Longrightarrow> norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - i) < (i \<bullet> k - j \<bullet> k) / 3"
lp15@66199
  1609
      using f_i[unfolded has_integral,rule_format,OF *] by fastforce 
lp15@66199
  1610
    obtain \<gamma>2 where "gauge \<gamma>2" 
lp15@66199
  1611
      and \<gamma>2: "\<And>p. \<lbrakk>p tagged_division_of cbox a b; \<gamma>2 fine p\<rbrakk>
lp15@66199
  1612
                \<Longrightarrow> norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R g x) - j) < (i \<bullet> k - j \<bullet> k) / 3"
lp15@66199
  1613
      using g_j[unfolded has_integral,rule_format,OF *] by fastforce 
lp15@66199
  1614
    obtain p where p: "p tagged_division_of cbox a b" and "\<gamma>1 fine p" "\<gamma>2 fine p"
lp15@66199
  1615
       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
  1616
       by metis
lp15@60474
  1617
    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
  1618
         "\<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
  1619
      using le_less_trans[OF Basis_le_norm[OF k]] k \<gamma>1 \<gamma>2 by metis+ 
wenzelm@53494
  1620
    then show False
hoelzl@50526
  1621
      unfolding inner_simps
lp15@66199
  1622
      using rsum_component_le[OF p] le
lp15@66199
  1623
      by (fastforce simp add: abs_real_def split: if_split_asm)
wenzelm@53494
  1624
  qed
lp15@60474
  1625
  show ?thesis
lp15@66199
  1626
  proof (cases "\<exists>a b. S = cbox a b")
lp15@60474
  1627
    case True
lp15@66199
  1628
    with ik_le_jk assms show ?thesis
lp15@60474
  1629
      by auto
lp15@60474
  1630
  next
lp15@60474
  1631
    case False
lp15@60474
  1632
    show ?thesis
lp15@60474
  1633
    proof (rule ccontr)
lp15@60474
  1634
      assume "\<not> i\<bullet>k \<le> j\<bullet>k"
lp15@60474
  1635
      then have ij: "(i\<bullet>k - j\<bullet>k) / 3 > 0"
lp15@60474
  1636
        by auto
lp15@66199
  1637
      obtain B1 where "0 < B1" 
lp15@66199
  1638
           and B1: "\<And>a b. ball 0 B1 \<subseteq> cbox a b \<Longrightarrow>
lp15@66199
  1639
                    \<exists>z. ((\<lambda>x. if x \<in> S then f x else 0) has_integral z) (cbox a b) \<and>
lp15@66199
  1640
                        norm (z - i) < (i \<bullet> k - j \<bullet> k) / 3"
lp15@66199
  1641
        using has_integral_altD[OF _ False ij] assms by blast
lp15@66199
  1642
      obtain B2 where "0 < B2" 
lp15@66199
  1643
           and B2: "\<And>a b. ball 0 B2 \<subseteq> cbox a b \<Longrightarrow>
lp15@66199
  1644
                    \<exists>z. ((\<lambda>x. if x \<in> S then g x else 0) has_integral z) (cbox a b) \<and>
lp15@66199
  1645
                        norm (z - j) < (i \<bullet> k - j \<bullet> k) / 3"
lp15@66199
  1646
        using has_integral_altD[OF _ False ij] assms by blast
lp15@60474
  1647
      have "bounded (ball 0 B1 \<union> ball (0::'a) B2)"
lp15@60474
  1648
        unfolding bounded_Un by(rule conjI bounded_ball)+
lp15@68120
  1649
      from bounded_subset_cbox_symmetric[OF this] 
lp15@66199
  1650
      obtain a b::'a where ab: "ball 0 B1 \<subseteq> cbox a b" "ball 0 B2 \<subseteq> cbox a b"
lp15@68120
  1651
        by (meson Un_subset_iff)
lp15@66199
  1652
      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
  1653
                        and norm_w1:  "norm (w1 - i) < (i \<bullet> k - j \<bullet> k) / 3"
lp15@66199
  1654
                        and int_w2: "((\<lambda>x. if x \<in> S then g x else 0) has_integral w2) (cbox a b)"
lp15@66199
  1655
                        and norm_w2: "norm (w2 - j) < (i \<bullet> k - j \<bullet> k) / 3"
lp15@66199
  1656
        using B1 B2 by blast
lp15@60474
  1657
      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
  1658
        by (simp add: abs_real_def split: if_split_asm)
lp15@66199
  1659
      have "\<bar>(w1 - i) \<bullet> k\<bar> < (i \<bullet> k - j \<bullet> k) / 3"
lp15@66199
  1660
           "\<bar>(w2 - j) \<bullet> k\<bar> < (i \<bullet> k - j \<bullet> k) / 3"
lp15@66199
  1661
        using Basis_le_norm k le_less_trans norm_w1 norm_w2 by blast+
lp15@60474
  1662
      moreover
lp15@60474
  1663
      have "w1\<bullet>k \<le> w2\<bullet>k"
lp15@66199
  1664
        using ik_le_jk int_w1 int_w2 f_le_g by auto
lp15@60474
  1665
      ultimately show False
lp15@60474
  1666
        unfolding inner_simps by(rule *)
lp15@60474
  1667
    qed
lp15@60474
  1668
  qed
hoelzl@50526
  1669
qed
hoelzl@37489
  1670
wenzelm@53494
  1671
lemma integral_component_le:
immler@56188
  1672
  fixes g f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
wenzelm@53494
  1673
  assumes "k \<in> Basis"
lp15@66199
  1674
    and "f integrable_on S" "g integrable_on S"
lp15@66199
  1675
    and "\<And>x. x \<in> S \<Longrightarrow> (f x)\<bullet>k \<le> (g x)\<bullet>k"
lp15@66199
  1676
  shows "(integral S f)\<bullet>k \<le> (integral S g)\<bullet>k"
wenzelm@53494
  1677
  apply (rule has_integral_component_le)
wenzelm@53494
  1678
  using integrable_integral assms
wenzelm@53494
  1679
  apply auto
wenzelm@53494
  1680
  done
wenzelm@53494
  1681
wenzelm@53494
  1682
lemma has_integral_component_nonneg:
immler@56188
  1683
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
wenzelm@53494
  1684
  assumes "k \<in> Basis"
lp15@66199
  1685
    and "(f has_integral i) S"
lp15@66199
  1686
    and "\<And>x. x \<in> S \<Longrightarrow> 0 \<le> (f x)\<bullet>k"
wenzelm@53494
  1687
  shows "0 \<le> i\<bullet>k"
wenzelm@53494
  1688
  using has_integral_component_le[OF assms(1) has_integral_0 assms(2)]
wenzelm@53494
  1689
  using assms(3-)
wenzelm@53494
  1690
  by auto
wenzelm@53494
  1691
wenzelm@53494
  1692
lemma integral_component_nonneg:
immler@56188
  1693
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
wenzelm@53494
  1694
  assumes "k \<in> Basis"
lp15@66199
  1695
    and  "\<And>x. x \<in> S \<Longrightarrow> 0 \<le> (f x)\<bullet>k"
lp15@66199
  1696
  shows "0 \<le> (integral S f)\<bullet>k"
lp15@66199
  1697
proof (cases "f integrable_on S")
lp15@62463
  1698
  case True show ?thesis
lp15@62463
  1699
    apply (rule has_integral_component_nonneg)
lp15@62463
  1700
    using assms True
lp15@62463
  1701
    apply auto
lp15@62463
  1702
    done
lp15@62463
  1703
next
lp15@62463
  1704
  case False then show ?thesis by (simp add: not_integrable_integral)
lp15@62463
  1705
qed
wenzelm@53494
  1706
wenzelm@53494
  1707
lemma has_integral_component_neg:
immler@56188
  1708
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
wenzelm@53494
  1709
  assumes "k \<in> Basis"
lp15@66199
  1710
    and "(f has_integral i) S"
lp15@66199
  1711
    and "\<And>x. x \<in> S \<Longrightarrow> (f x)\<bullet>k \<le> 0"
wenzelm@53494
  1712
  shows "i\<bullet>k \<le> 0"
wenzelm@53494
  1713
  using has_integral_component_le[OF assms(1,2) has_integral_0] assms(2-)
wenzelm@53494
  1714
  by auto
hoelzl@50526
  1715
hoelzl@50526
  1716
lemma has_integral_component_lbound:
immler@56188
  1717
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
immler@56188
  1718
  assumes "(f has_integral i) (cbox a b)"
immler@56188
  1719
    and "\<forall>x\<in>cbox a b. B \<le> f(x)\<bullet>k"
wenzelm@53494
  1720
    and "k \<in> Basis"
immler@56188
  1721
  shows "B * content (cbox a b) \<le> i\<bullet>k"
hoelzl@50526
  1722
  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
  1723
  by (auto simp add: field_simps)
hoelzl@50526
  1724
hoelzl@50526
  1725
lemma has_integral_component_ubound:
immler@56188
  1726
  fixes f::"'a::euclidean_space => 'b::euclidean_space"
immler@56188
  1727
  assumes "(f has_integral i) (cbox a b)"
immler@56188
  1728
    and "\<forall>x\<in>cbox a b. f x\<bullet>k \<le> B"
wenzelm@53494
  1729
    and "k \<in> Basis"
immler@56188
  1730
  shows "i\<bullet>k \<le> B * content (cbox a b)"
wenzelm@53494
  1731
  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
  1732
  by (auto simp add: field_simps)
wenzelm@53494
  1733
wenzelm@53494
  1734
lemma integral_component_lbound:
immler@56188
  1735
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
immler@56188
  1736
  assumes "f integrable_on cbox a b"
immler@56188
  1737
    and "\<forall>x\<in>cbox a b. B \<le> f(x)\<bullet>k"
wenzelm@53494
  1738
    and "k \<in> Basis"
immler@56188
  1739
  shows "B * content (cbox a b) \<le> (integral(cbox a b) f)\<bullet>k"
wenzelm@53494
  1740
  apply (rule has_integral_component_lbound)
wenzelm@53494
  1741
  using assms
wenzelm@53494
  1742
  unfolding has_integral_integral
wenzelm@53494
  1743
  apply auto
wenzelm@53494
  1744
  done
wenzelm@53494
  1745
immler@56190
  1746
lemma integral_component_lbound_real:
paulson@66402
  1747
  assumes "f integrable_on {a ::real..b}"
paulson@66402
  1748
    and "\<forall>x\<in>{a..b}. B \<le> f(x)\<bullet>k"
immler@56190
  1749
    and "k \<in> Basis"
paulson@66402
  1750
  shows "B * content {a..b} \<le> (integral {a..b} f)\<bullet>k"
immler@56190
  1751
  using assms
immler@56190
  1752
  by (metis box_real(2) integral_component_lbound)
immler@56190
  1753
wenzelm@53494
  1754
lemma integral_component_ubound:
immler@56188
  1755
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
immler@56188
  1756
  assumes "f integrable_on cbox a b"
immler@56188
  1757
    and "\<forall>x\<in>cbox a b. f x\<bullet>k \<le> B"
wenzelm@53494
  1758
    and "k \<in> Basis"
immler@56188
  1759
  shows "(integral (cbox a b) f)\<bullet>k \<le> B * content (cbox a b)"
wenzelm@53494
  1760
  apply (rule has_integral_component_ubound)
wenzelm@53494
  1761
  using assms
wenzelm@53494
  1762
  unfolding has_integral_integral
wenzelm@53494
  1763
  apply auto
wenzelm@53494
  1764
  done
wenzelm@53494
  1765
immler@56190
  1766
lemma integral_component_ubound_real:
immler@56190
  1767
  fixes f :: "real \<Rightarrow> 'a::euclidean_space"
paulson@66402
  1768
  assumes "f integrable_on {a..b}"
paulson@66402
  1769
    and "\<forall>x\<in>{a..b}. f x\<bullet>k \<le> B"
immler@56190
  1770
    and "k \<in> Basis"
paulson@66402
  1771
  shows "(integral {a..b} f)\<bullet>k \<le> B * content {a..b}"
immler@56190
  1772
  using assms
immler@56190
  1773
  by (metis box_real(2) integral_component_ubound)
himmelma@35172
  1774
nipkow@67968
  1775
subsection \<open>Uniform limit of integrable functions is integrable\<close>
himmelma@35172
  1776
lp15@62626
  1777
lemma real_arch_invD:
lp15@62626
  1778
  "0 < (e::real) \<Longrightarrow> (\<exists>n::nat. n \<noteq> 0 \<and> 0 < inverse (real n) \<and> inverse (real n) < e)"
lp15@62626
  1779
  by (subst(asm) real_arch_inverse)
lp15@62626
  1780
lp15@66294
  1781
wenzelm@53494
  1782
lemma integrable_uniform_limit:
immler@56188
  1783
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::banach"
lp15@66294
  1784
  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
  1785
  shows "f integrable_on cbox a b"
lp15@60487
  1786
proof (cases "content (cbox a b) > 0")
lp15@60487
  1787
  case False then show ?thesis
lp15@66294
  1788
    using has_integral_null by (simp add: content_lt_nz integrable_on_def)
lp15@60487
  1789
next
lp15@60487
  1790
  case True
lp15@66294
  1791
  have "1 / (real n + 1) > 0" for n
wenzelm@53494
  1792
    by auto
lp15@66294
  1793
  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
  1794
    using assms by blast
lp15@66294
  1795
  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
  1796
                  and int_g: "\<And>n. g n integrable_on cbox a b"
lp15@66294
  1797
    by metis
lp15@66294
  1798
  then obtain h where h: "\<And>n. (g n has_integral h n) (cbox a b)"
lp15@66294
  1799
    unfolding integrable_on_def by metis
lp15@66294
  1800
  have "Cauchy h"
wenzelm@53494
  1801
    unfolding Cauchy_def
lp15@60487
  1802
  proof clarify
wenzelm@53494
  1803
    fix e :: real
wenzelm@53494
  1804
    assume "e>0"
lp15@66294
  1805
    then have "e/4 / content (cbox a b) > 0"
lp15@66294
  1806
      using True by (auto simp: field_simps)
lp15@66294
  1807
    then obtain M where "M \<noteq> 0" and M: "1 / (real M) < e/4 / content (cbox a b)"
lp15@66294
  1808
      by (metis inverse_eq_divide real_arch_inverse)
lp15@66294
  1809
    show "\<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. dist (h m) (h n) < e"
lp15@60487
  1810
    proof (rule exI [where x=M], clarify)
lp15@60487
  1811
      fix m n
lp15@60487
  1812
      assume m: "M \<le> m" and n: "M \<le> n"
wenzelm@60420
  1813
      have "e/4>0" using \<open>e>0\<close> by auto
lp15@66294
  1814
      then obtain gm gn where "gauge gm" "gauge gn"
lp15@66294
  1815
              and gm: "\<And>\<D>. \<D> tagged_division_of cbox a b \<and> gm fine \<D> 
lp15@66294
  1816
                            \<Longrightarrow> norm ((\<Sum>(x,K) \<in> \<D>. content K *\<^sub>R g m x) - h m) < e/4"
lp15@66294
  1817
              and gn: "\<And>\<D>. \<D> tagged_division_of cbox a b \<and> gn fine \<D> \<Longrightarrow>
lp15@66294
  1818
                      norm ((\<Sum>(x,K) \<in> \<D>. content K *\<^sub>R g n x) - h n) < e/4"
lp15@66294
  1819
        using h[unfolded has_integral] by meson
lp15@66294
  1820
      then obtain \<D> where \<D>: "\<D> tagged_division_of cbox a b" "(\<lambda>x. gm x \<inter> gn x) fine \<D>"
lp15@66294
  1821
        by (metis (full_types) fine_division_exists gauge_Int)
lp15@66294
  1822
      have triangle3: "norm (i1 - i2) < e"
lp15@66294
  1823
        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
  1824
      proof -
wenzelm@53494
  1825
        have "norm (i1 - i2) \<le> norm (i1 - s1) + norm (s1 - s2) + norm (s2 - i2)"
himmelma@35172
  1826
          using norm_triangle_ineq[of "i1 - s1" "s1 - i2"]
wenzelm@53494
  1827
          using norm_triangle_ineq[of "s1 - s2" "s2 - i2"]
lp15@66294
  1828
          by (auto simp: algebra_simps)
wenzelm@53494
  1829
        also have "\<dots> < e"
lp15@66294
  1830
          using no by (auto simp: algebra_simps norm_minus_commute)
lp15@66294
  1831
        finally show ?thesis .
lp15@66294
  1832
      qed
lp15@66294
  1833
      have finep: "gm fine \<D>" "gn fine \<D>"
lp15@66294
  1834
        using fine_Int \<D>  by auto
lp15@66294
  1835
      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
  1836
      proof -
lp15@66294
  1837
        have "norm (f x - g n x) + norm (f x - g m x) \<le> 1 / (real n + 1) + 1 / (real m + 1)"          
lp15@66294
  1838
          using g_near_f[OF x, of n] g_near_f[OF x, of m] by simp
lp15@66294
  1839
        also have "\<dots> \<le> 1 / (real M) + 1 / (real M)"
wenzelm@53494
  1840
          apply (rule add_mono)
lp15@66294
  1841
          using \<open>M \<noteq> 0\<close> m n by (auto simp: divide_simps)
wenzelm@53494
  1842
        also have "\<dots> = 2 / real M"
lp15@66294
  1843
          by auto
lp15@66294
  1844
        finally show "norm (g n x - g m x) \<le> 2 / real M"
himmelma@35172
  1845
          using norm_triangle_le[of "g n x - f x" "f x - g m x" "2 / real M"]
lp15@66294
  1846
          by (auto simp: algebra_simps simp add: norm_minus_commute)
lp15@66294
  1847
      qed
lp15@66294
  1848
      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
  1849
        by (blast intro: norm_le rsum_diff_bound[OF \<D>(1), where e="2 / real M"])
lp15@66294
  1850
      also have "... \<le> e/2"
lp15@60487
  1851
        using M True
lp15@66294
  1852
        by (auto simp: field_simps)
lp15@66294
  1853
      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
  1854
      then show "dist (h m) (h n) < e"
lp15@66294
  1855
        unfolding dist_norm using gm gn \<D> finep by (auto intro!: triangle3)
lp15@60487
  1856
    qed
lp15@60487
  1857
  qed
lp15@66294
  1858
  then obtain s where s: "h \<longlonglongrightarrow> s"
lp15@64287
  1859
    using convergent_eq_Cauchy[symmetric] by blast
wenzelm@53494
  1860
  show ?thesis
lp15@60487
  1861
    unfolding integrable_on_def has_integral
lp15@60487
  1862
  proof (rule_tac x=s in exI, clarify)
lp15@60487
  1863
    fix e::real
lp15@60487
  1864
    assume e: "0 < e"
lp15@66294
  1865
    then have "e/3 > 0" by auto
lp15@66294
  1866
    then obtain N1 where N1: "\<forall>n\<ge>N1. norm (h n - s) < e/3"
lp15@60487
  1867
      using LIMSEQ_D [OF s] by metis
lp15@66294
  1868
    from e True have "e/3 / content (cbox a b) > 0"
lp15@66294
  1869
      by (auto simp: field_simps)
lp15@66294
  1870
    then obtain N2 :: nat
lp15@66294
  1871
         where "N2 \<noteq> 0" and N2: "1 / (real N2) < e/3 / content (cbox a b)"
lp15@66294
  1872
      by (metis inverse_eq_divide real_arch_inverse)
lp15@66294
  1873
    obtain g' where "gauge g'"
lp15@66294
  1874
            and g': "\<And>\<D>. \<D> tagged_division_of cbox a b \<and> g' fine \<D> \<Longrightarrow>
lp15@66294
  1875
                    norm ((\<Sum>(x,K) \<in> \<D>. content K *\<^sub>R g (N1 + N2) x) - h (N1 + N2)) < e/3"
lp15@66294
  1876
      by (metis h has_integral \<open>e/3 > 0\<close>)
lp15@66294
  1877
    have *: "norm (sf - s) < e" 
lp15@66294
  1878
        if no: "norm (sf - sg) \<le> e/3" "norm(h - s) < e/3" "norm (sg - h) < e/3" for sf sg h
lp15@66294
  1879
    proof -
lp15@66294
  1880
      have "norm (sf - s) \<le> norm (sf - sg) + norm (sg - h) + norm (h - s)"
himmelma@35172
  1881
        using norm_triangle_ineq[of "sf - sg" "sg - s"]
lp15@66294
  1882
        using norm_triangle_ineq[of "sg -  h" " h - s"]
lp15@66294
  1883
        by (auto simp: algebra_simps)
wenzelm@53494
  1884
      also have "\<dots> < e"
lp15@66294
  1885
        using no by (auto simp: algebra_simps norm_minus_commute)
lp15@66294
  1886
      finally show ?thesis .
lp15@66294
  1887
    qed
lp15@66294
  1888
    { fix \<D>
lp15@66294
  1889
      assume ptag: "\<D> tagged_division_of (cbox a b)" and "g' fine \<D>"
lp15@66294
  1890
      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
  1891
        using g' by blast
lp15@66294
  1892
      have "content (cbox a b) < e/3 * (of_nat N2)"
lp15@66294
  1893
        using \<open>N2 \<noteq> 0\<close> N2 using True by (auto simp: divide_simps)
lp15@66294
  1894
      moreover have "e/3 * of_nat N2 \<le> e/3 * (of_nat (N1 + N2) + 1)"
lp15@60487
  1895
        using \<open>e>0\<close> by auto
lp15@66294
  1896
      ultimately have "content (cbox a b) < e/3 * (of_nat (N1 + N2) + 1)"
lp15@60487
  1897
        by linarith
lp15@66294
  1898
      then have le_e3: "1 / (real (N1 + N2) + 1) * content (cbox a b) \<le> e/3"
lp15@60487
  1899
        unfolding inverse_eq_divide
lp15@66294
  1900
        by (auto simp: field_simps)
lp15@66294
  1901
      have ne3: "norm (h (N1 + N2) - s) < e/3"
lp15@60487
  1902
        using N1 by auto
lp15@66294
  1903
      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
  1904
            \<le> 1 / (real (N1 + N2) + 1) * content (cbox a b)"
lp15@66294
  1905
        by (blast intro: g_near_f rsum_diff_bound[OF ptag])
lp15@66294
  1906
      then have "norm ((\<Sum>(x,K) \<in> \<D>. content K *\<^sub>R f x) - s) < e"
lp15@66294
  1907
        by (rule *[OF order_trans [OF _ le_e3] ne3 norm_less])
lp15@66294
  1908
    }
lp15@60487
  1909
    then show "\<exists>d. gauge d \<and>
lp15@66294
  1910
             (\<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
  1911
      by (blast intro: g' \<open>gauge g'\<close>)
wenzelm@53494
  1912
  qed
wenzelm@53494
  1913
qed
wenzelm@53494
  1914
lp15@61806
  1915
lemmas integrable_uniform_limit_real = integrable_uniform_limit [where 'a=real, simplified]
lp15@61806
  1916
himmelma@35172
  1917
nipkow@67968
  1918
subsection \<open>Negligible sets\<close>
himmelma@35172
  1919
immler@56188
  1920
definition "negligible (s:: 'a::euclidean_space set) \<longleftrightarrow>
immler@56188
  1921
  (\<forall>a b. ((indicator s :: 'a\<Rightarrow>real) has_integral 0) (cbox a b))"
wenzelm@53494
  1922
himmelma@35172
  1923
nipkow@67968
  1924
subsubsection \<open>Negligibility of hyperplane\<close>
himmelma@35172
  1925
wenzelm@53495
  1926
lemma content_doublesplit:
immler@56188
  1927
  fixes a :: "'a::euclidean_space"
wenzelm@53495
  1928
  assumes "0 < e"
wenzelm@53495
  1929
    and k: "k \<in> Basis"
wenzelm@61945
  1930
  obtains d where "0 < d" and "content (cbox a b \<inter> {x. \<bar>x\<bullet>k - c\<bar> \<le> d}) < e"
hoelzl@63886
  1931
proof cases
hoelzl@63886
  1932
  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
  1933
  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
  1934
  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
  1935
hoelzl@63886
  1936
  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
  1937
    by (auto simp: b'_def a'_def intro!: tendsto_min tendsto_max tendsto_eq_intros)
hoelzl@63886
  1938
  also have "(\<Prod>j\<in>Basis. (b' 0 - a' 0) \<bullet> j) = 0"
hoelzl@63886
  1939
    using k *
nipkow@64272
  1940
    by (intro prod_zero bexI[OF _ k])
nipkow@64267
  1941
       (auto simp: b'_def a'_def inner_diff inner_sum_left inner_not_same_Basis intro!: sum.cong)
hoelzl@63886
  1942
  also have "((\<lambda>d. \<Prod>j\<in>Basis. (b' d - a' d) \<bullet> j) \<longlongrightarrow> 0) (at_right 0) =
hoelzl@63886
  1943
    ((\<lambda>d. content (cbox a b \<inter> {x. \<bar>x\<bullet>k - c\<bar> \<le> d})) \<longlongrightarrow> 0) (at_right 0)"
hoelzl@63886
  1944
  proof (intro tendsto_cong eventually_at_rightI)
hoelzl@63886
  1945
    fix d :: real assume d: "d \<in> {0<..<1}"
hoelzl@63886
  1946
    have "cbox a b \<inter> {x. \<bar>x\<bullet>k - c\<bar> \<le> d} = cbox (a' d) (b' d)" for d
hoelzl@63886
  1947
      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
  1948
    moreover have "j \<in> Basis \<Longrightarrow> a' d \<bullet> j \<le> b' d \<bullet> j" for j
hoelzl@63886
  1949
      using * d k by (auto simp: a'_def b'_def)
hoelzl@63886
  1950
    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
  1951
      by simp
hoelzl@63886
  1952
  qed simp
hoelzl@63886
  1953
  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
  1954
  from order_tendstoD(2)[OF this \<open>0<e\<close>]
hoelzl@63886
  1955
  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
  1956
    by (subst (asm) eventually_at_right[of _ 1]) auto
wenzelm@53495
  1957
  show ?thesis
hoelzl@63886
  1958
    by (rule that[of "d'/2"], insert \<open>0<d'\<close> d'[of "d'/2"], auto)
wenzelm@53495
  1959
next
hoelzl@63886
  1960
  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
  1961
  then have "(\<exists>j\<in>Basis. b \<bullet> j < a \<bullet> j) \<or> (c < a \<bullet> k \<or> b \<bullet> k < c)"
hoelzl@63886
  1962
    by (auto simp: not_le)
hoelzl@63886
  1963
  show thesis
hoelzl@63886
  1964
  proof cases
hoelzl@63886
  1965
    assume "\<exists>j\<in>Basis. b \<bullet> j < a \<bullet> j"
hoelzl@63886
  1966
    then have [simp]: "cbox a b = {}"
hoelzl@63886
  1967
      using box_ne_empty(1)[of a b] by auto
hoelzl@63886
  1968
    show ?thesis
hoelzl@63886
  1969
      by (rule that[of 1]) (simp_all add: \<open>0<e\<close>)
hoelzl@63886
  1970
  next
hoelzl@63886
  1971
    assume "\<not> (\<exists>j\<in>Basis. b \<bullet> j < a \<bullet> j)"
hoelzl@63886
  1972
    with * have "c < a \<bullet> k \<or> b \<bullet> k < c"
hoelzl@63886
  1973
      by auto
hoelzl@63886
  1974
    then show thesis
hoelzl@63886
  1975
    proof
hoelzl@63886
  1976
      assume c: "c < a \<bullet> k"
hoelzl@63886
  1977
      moreover have "x \<in> cbox a b \<Longrightarrow> c \<le> x \<bullet> k" for x
hoelzl@63886
  1978
        using k c by (auto simp: cbox_def)
lp15@66532
  1979
      ultimately have "cbox a b \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> (a \<bullet> k - c)/2} = {}"
hoelzl@63886
  1980
        using k by (auto simp: cbox_def)
lp15@66532
  1981
      with \<open>0<e\<close> c that[of "(a \<bullet> k - c)/2"] show ?thesis
wenzelm@53495
  1982
        by auto
lp15@60492
  1983
    next
hoelzl@63886
  1984
      assume c: "b \<bullet> k < c"
hoelzl@63886
  1985
      moreover have "x \<in> cbox a b \<Longrightarrow> x \<bullet> k \<le> c" for x
hoelzl@63886
  1986
        using k c by (auto simp: cbox_def)
lp15@66532
  1987
      ultimately have "cbox a b \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> (c - b \<bullet> k)/2} = {}"
hoelzl@63886
  1988
        using k by (auto simp: cbox_def)
lp15@66532
  1989
      with \<open>0<e\<close> c that[of "(c - b \<bullet> k)/2"] show ?thesis
hoelzl@63886
  1990
        by auto
hoelzl@63886
  1991
    qed
hoelzl@63886
  1992
  qed
hoelzl@63886
  1993
qed
hoelzl@63886
  1994
hoelzl@50526
  1995
lp15@66536
  1996
proposition negligible_standard_hyperplane[intro]:
immler@56188
  1997
  fixes k :: "'a::euclidean_space"
hoelzl@50526
  1998
  assumes k: "k \<in> Basis"
wenzelm@53399
  1999
  shows "negligible {x. x\<bullet>k = c}"
wenzelm@53495
  2000
  unfolding negligible_def has_integral
lp15@66536
  2001
proof clarsimp
lp15@66536
  2002
  fix a b and e::real assume "e > 0"
lp15@66537
  2003
  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
  2004
    by (metis content_doublesplit)
hoelzl@50526
  2005
  let ?i = "indicator {x::'a. x\<bullet>k = c} :: 'a\<Rightarrow>real"
lp15@66536
  2006
  show "\<exists>\<gamma>. gauge \<gamma> \<and>
lp15@66536
  2007
           (\<forall>\<D>. \<D> tagged_division_of cbox a b \<and> \<gamma> fine \<D> \<longrightarrow>
lp15@66536
  2008
                 \<bar>\<Sum>(x,K) \<in> \<D>. content K * ?i x\<bar> < e)"
lp15@66536
  2009
  proof (intro exI, safe)
lp15@66536
  2010
    show "gauge (\<lambda>x. ball x d)"
lp15@66537
  2011
      using \<open>0 < d\<close> by blast
lp15@66536
  2012
  next
lp15@66536
  2013
    fix \<D>
lp15@66536
  2014
    assume p: "\<D> tagged_division_of (cbox a b)" "(\<lambda>x. ball x d) fine \<D>"
lp15@66539
  2015
    have "content L = content (L \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d})" 
lp15@66539
  2016
      if "(x, L) \<in> \<D>" "?i x \<noteq> 0" for x L
wenzelm@53495
  2017
    proof -
lp15@66537
  2018
      have xk: "x\<bullet>k = c"
lp15@66537
  2019
        using that by (simp add: indicator_def split: if_split_asm)
lp15@66539
  2020
      have "L \<subseteq> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}"
lp15@66539
  2021
      proof 
wenzelm@53495
  2022
        fix y
lp15@66539
  2023
        assume y: "y \<in> L"
lp15@66539
  2024
        have "L \<subseteq> ball x d"
lp15@66539
  2025
          using p(2) that(1) by auto
lp15@66539
  2026
        then have "norm (x - y) < d"
lp15@66539
  2027
          by (simp add: dist_norm subset_iff y)
lp15@66539
  2028
        then have "\<bar>(x - y) \<bullet> k\<bar> < d"
lp15@66539
  2029
          using k norm_bound_Basis_lt by blast
lp15@66539
  2030
        then show "y \<in> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}"
wenzelm@53495
  2031
          unfolding inner_simps xk by auto
lp15@66539
  2032
      qed 
lp15@66539
  2033
      then show "content L = content (L \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d})"
lp15@66539
  2034
        by (metis inf.orderE)
wenzelm@53495
  2035
    qed
lp15@66537
  2036
    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
  2037
      by (force simp add: split_paired_all intro!: sum.cong [OF refl])
lp15@66536
  2038
    note p'= tagged_division_ofD[OF p(1)] and p''=division_of_tagged_division[OF p(1)]
lp15@66536
  2039
    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
  2040
    proof -
lp15@66539
  2041
      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
  2042
        by (force simp add: indicator_def intro!: sum_mono)
wenzelm@53495
  2043
      also have "\<dots> < e"
lp15@66539
  2044
      proof (subst sum.over_tagged_division_lemma[OF p(1)])
lp15@66539
  2045
        fix u v::'a
lp15@66539
  2046
        assume "box u v = {}"
hoelzl@63957
  2047
        then have *: "content (cbox u v) = 0"
hoelzl@63957
  2048
          unfolding content_eq_0_interior by simp
lp15@66537
  2049
        have "cbox u v \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d} \<subseteq> cbox u v"
lp15@66537
  2050
          by auto
lp15@66537
  2051
        then have "content (cbox u v \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}) \<le> content (cbox u v)"
lp15@66537
  2052
          unfolding interval_doublesplit[OF k] by (rule content_subset)
lp15@66539
  2053
        then show "content (cbox u v \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}) = 0"
hoelzl@63957
  2054
          unfolding * interval_doublesplit[OF k]
hoelzl@50348
  2055
          by (blast intro: antisym)
wenzelm@53495
  2056
      next
lp15@66536
  2057
        have "(\<Sum>l\<in>snd ` \<D>. content (l \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d})) =
lp15@66536
  2058
          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
  2059
        proof (subst (2) sum.reindex_nontrivial)
lp15@66536
  2060
          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
  2061
            "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
  2062
          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
  2063
            by (auto)
lp15@66536
  2064
          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
  2065
            by auto
hoelzl@63593
  2066
          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
  2067
            by (auto intro: interior_mono)
hoelzl@63593
  2068
          ultimately have "interior (x \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}) = {}"
hoelzl@63593
  2069
            by (auto simp: eq)
hoelzl@63593
  2070
          then show "content (x \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}) = 0"
lp15@66536
  2071
            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
  2072
        qed (insert p'(1), auto intro!: sum.mono_neutral_right)
lp15@66536
  2073
        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
  2074
          by simp
hoelzl@63593
  2075
        also have "\<dots> \<le> 1 * content (cbox a b \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d})"
hoelzl@63593
  2076
          using division_doublesplit[OF p'' k, unfolded interval_doublesplit[OF k]]
hoelzl@63593
  2077
          unfolding interval_doublesplit[OF k] by (intro dsum_bound) auto
hoelzl@63593
  2078
        also have "\<dots> < e"
lp15@66537
  2079
          using d by simp
lp15@66536
  2080
        finally show "(\<Sum>K\<in>snd ` \<D>. content (K \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d})) < e" .
wenzelm@53495
  2081
      qed
lp15@66536
  2082
      finally show "(\<Sum>(x, K)\<in>\<D>. content (K \<inter> {x. \<bar>x \<bullet> k - c\<bar> \<le> d}) * ?i x) < e" .
wenzelm@53495
  2083
    qed
lp15@66536
  2084
    then show "\<bar>\<Sum>(x, K)\<in>\<D>. content K * ?i x\<bar> < e"
lp15@66536
  2085
      unfolding * 
lp15@65680
  2086
      apply (subst abs_of_nonneg)
lp15@66536
  2087
      using measure_nonneg       
lp15@66536
  2088
      by (force simp add: indicator_def intro: sum_nonneg)+
wenzelm@53495
  2089
  qed
wenzelm@53495
  2090
qed
wenzelm@53495
  2091
lp15@67984
  2092
corollary negligible_standard_hyperplane_cart:
lp15@67984
  2093
  fixes k :: "'a::finite"
lp15@67984
  2094
  shows "negligible {x. x$k = (0::real)}"
lp15@67984
  2095
  by (simp add: cart_eq_inner_axis negligible_standard_hyperplane)
lp15@67984
  2096
himmelma@35172
  2097
nipkow@67968
  2098
subsubsection \<open>Hence the main theorem about negligible sets\<close>
lp15@66294
  2099
lp15@66294
  2100
lp15@66294
  2101
lemma has_integral_negligible_cbox:
immler@56188
  2102
  fixes f :: "'b::euclidean_space \<Rightarrow> 'a::real_normed_vector"
lp15@66294
  2103
  assumes negs: "negligible S"
lp15@66294
  2104
    and 0: "\<And>x. x \<notin> S \<Longrightarrow> f x = 0"
lp15@66294
  2105
  shows "(f has_integral 0) (cbox a b)"
lp15@66294
  2106
  unfolding has_integral
lp15@66294
  2107
proof clarify
lp15@66294
  2108
  fix e::real
lp15@66294
  2109
  assume "e > 0"
lp15@66294
  2110
  then have nn_gt0: "e/2 / ((real n+1) * (2 ^ n)) > 0" for n
lp15@66294
  2111
    by simp
lp15@66294
  2112
  then have "\<exists>\<gamma>. gauge \<gamma> \<and>
lp15@66294
  2113
                   (\<forall>\<D>. \<D> tagged_division_of cbox a b \<and> \<gamma> fine \<D> \<longrightarrow>
lp15@66294
  2114
                        \<bar>\<Sum>(x,K) \<in> \<D>. content K *\<^sub>R indicator S x\<bar>
lp15@66294
  2115
                        < e/2 / ((real n + 1) * 2 ^ n))" for n
lp15@66294
  2116
    using negs [unfolded negligible_def has_integral] by auto
lp15@66294
  2117
  then obtain \<gamma> where 
lp15@66294
  2118
    gd: "\<And>n. gauge (\<gamma> n)"
lp15@66294
  2119
    and \<gamma>: "\<And>n \<D>. \<lbrakk>\<D> tagged_division_of cbox a b; \<gamma> n fine \<D>\<rbrakk>
lp15@66294
  2120
                  \<Longrightarrow> \<bar>\<Sum>(x,K) \<in> \<D>. content K *\<^sub>R indicator S x\<bar> < e/2 / ((real n + 1) * 2 ^ n)"
lp15@66294
  2121
    by metis
lp15@66294
  2122
  show "\<exists>\<gamma>. gauge \<gamma> \<and>
lp15@66294
  2123
             (\<forall>\<D>. \<D> tagged_division_of cbox a b \<and> \<gamma> fine \<D> \<longrightarrow>
lp15@66294
  2124
                  norm ((\<Sum>(x,K) \<in> \<D>. content K *\<^sub>R f x) - 0) < e)"
lp15@66294
  2125
  proof (intro exI, safe)
lp15@66294
  2126
    show "gauge (\<lambda>x. \<gamma> (nat \<lfloor>norm (f x)\<rfloor>) x)"
lp15@66294
  2127
      using gd by (auto simp: gauge_def)
lp15@66294
  2128
lp15@66294
  2129
    show "norm ((\<Sum>(x,K) \<in> \<D>. content K *\<^sub>R f x) - 0) < e"
lp15@66294
  2130
      if "\<D> tagged_division_of (cbox a b)" "(\<lambda>x. \<gamma> (nat \<lfloor>norm (f x)\<rfloor>) x) fine \<D>" for \<D>
lp15@66294
  2131
    proof (cases "\<D> = {}")
lp15@66294
  2132
      case True with \<open>0 < e\<close> show ?thesis by simp
lp15@66294
  2133
    next
lp15@66294
  2134
      case False
lp15@66294
  2135
      obtain N where "Max ((\<lambda>(x, K). norm (f x)) ` \<D>) \<le> real N"
lp15@66294
  2136
        using real_arch_simple by blast
lp15@66294
  2137
      then have N: "\<And>x. x \<in> (\<lambda>(x, K). norm (f x)) ` \<D> \<Longrightarrow> x \<le> real N"
lp15@66294
  2138
        by (meson Max_ge that(1) dual_order.trans finite_imageI tagged_division_of_finite)
lp15@66294
  2139
      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
  2140
        by (auto intro: tagged_division_finer[OF that(1) gd])
lp15@66199
  2141
      from choice[OF this] 
lp15@66199
  2142
      obtain q where q: "\<And>n. q n tagged_division_of cbox a b"
lp15@66294
  2143
                        "\<And>n. \<gamma> n fine q n"
lp15@66294
  2144
                        "\<And>n x K. \<lbrakk>(x, K) \<in> \<D>; K \<subseteq> \<gamma> n x\<rbrakk> \<Longrightarrow> (x, K) \<in> q n"
lp15@66199
  2145
        by fastforce
lp15@66294
  2146
      have "finite \<D>"
lp15@66294
  2147
        using that(1) by blast
lp15@66294
  2148
      then have sum_le_inc: "\<lbrakk>finite T; \<And>x y. (x,y) \<in> T \<Longrightarrow> (0::real) \<le> g(x,y);
lp15@66294
  2149
                      \<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
  2150
        by (rule sum_le_included[of \<D> T g snd f]; force)
lp15@66294
  2151
      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
  2152
        unfolding split_def by (rule norm_sum)
lp15@66294
  2153
      also have "... \<le> (\<Sum>(i, j) \<in> Sigma {..N + 1} q.
lp15@66294
  2154
                          (real i + 1) * (case j of (x, K) \<Rightarrow> content K *\<^sub>R indicator S x))"
lp15@66294
  2155
      proof (rule sum_le_inc, safe)
lp15@66294
  2156
        show "finite (Sigma {..N+1} q)"
lp15@66294
  2157
          by (meson finite_SigmaI finite_atMost tagged_division_of_finite q(1)) 
wenzelm@53495
  2158
      next
lp15@66294
  2159
        fix x K
lp15@66294
  2160
        assume xk: "(x, K) \<in> \<D>"
wenzelm@63040
  2161
        define n where "n = nat \<lfloor>norm (f x)\<rfloor>"
lp15@66294
  2162
        have *: "norm (f x) \<in> (\<lambda>(x, K). norm (f x)) ` \<D>"
wenzelm@53495
  2163
          using xk by auto
wenzelm@53495
  2164
        have nfx: "real n \<le> norm (f x)" "norm (f x) \<le> real n + 1"
wenzelm@53495
  2165
          unfolding n_def by auto
wenzelm@53495
  2166
        then have "n \<in> {0..N + 1}"
lp15@66294
  2167
          using N[OF *] by auto
lp15@66294
  2168
        moreover have "K \<subseteq> \<gamma> (nat \<lfloor>norm (f x)\<rfloor>) x"
lp15@66294
  2169
          using that(2) xk by auto
lp15@66294
  2170
        moreover then have "(x, K) \<in> q (nat \<lfloor>norm (f x)\<rfloor>)"
lp15@66294
  2171
          by (simp add: q(3) xk)
lp15@66294
  2172
        moreover then have "(x, K) \<in> q n"
lp15@66294
  2173
          using n_def by blast
wenzelm@53495
  2174
        moreover
lp15@66294
  2175
        have "norm (content K *\<^sub>R f x) \<le> (real n + 1) * (content K * indicator S x)"
lp15@66294
  2176
        proof (cases "x \<in> S")
wenzelm@53495
  2177
          case False
lp15@66294
  2178
          then show ?thesis by (simp add: 0)
wenzelm@53495
  2179
        next
wenzelm@53495
  2180
          case True
lp15@66294
  2181
          have *: "content K \<ge> 0"
lp15@66294
  2182
            using tagged_division_ofD(4)[OF that(1) xk] by auto
lp15@66294
  2183
          moreover have "content K * norm (f x) \<le> content K * (real n + 1)"
lp15@66294
  2184
            by (simp add: mult_left_mono nfx(2))
lp15@66294
  2185
          ultimately show ?thesis
lp15@66294
  2186
            using nfx True by (auto simp: field_simps)
wenzelm@53495
  2187
        qed
lp15@66294
  2188
        ultimately show "\<exists>y. (y, x, K) \<in> (Sigma {..N + 1} q) \<and> norm (content K *\<^sub>R f x) \<le>
lp15@66294
  2189
          (real y + 1) * (content K *\<^sub>R indicator S x)"
lp15@66199
  2190
          by force
lp15@66294
  2191
      qed auto
lp15@66294
  2192
      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
  2193
        apply (rule sum_Sigma_product [symmetric])
lp15@66294
  2194
        using q(1) apply auto
lp15@66294
  2195
        done
lp15@66294
  2196
      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
  2197
        by (rule sum_mono) (simp add: sum_distrib_left [symmetric])
lp15@66532
  2198
      also have "... \<le> (\<Sum>i\<le>N + 1. e/2/2 ^ i)"
lp15@66294
  2199
      proof (rule sum_mono)
lp15@66532
  2200
        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
  2201
          if "i \<in> {..N + 1}" for i
lp15@66294
  2202
          using \<gamma>[of "q i" i] q by (simp add: divide_simps mult.left_commute)
wenzelm@53495
  2203
      qed
lp15@66532
  2204
      also have "... = e/2 * (\<Sum>i\<le>N + 1. (1/2) ^ i)"
lp15@66294
  2205
        unfolding sum_distrib_left by (metis divide_inverse inverse_eq_divide power_one_over)
lp15@66294
  2206
      also have "\<dots> < e/2 * 2"
lp15@66294
  2207
      proof (rule mult_strict_left_mono)
lp15@67980
  2208
        have "sum (power (1/2)) {..N + 1} = sum (power (1/2::real)) {..<N + 2}"
lp15@66294
  2209
          using lessThan_Suc_atMost by auto
lp15@66294
  2210
        also have "... < 2"
lp15@66294
  2211
          by (auto simp: geometric_sum)
lp15@67980
  2212
        finally show "sum (power (1/2::real)) {..N + 1} < 2" .
lp15@66294
  2213
      qed (use \<open>0 < e\<close> in auto)
lp15@66294
  2214
      finally  show ?thesis by auto
wenzelm@53495
  2215
    qed
wenzelm@53495
  2216
  qed
wenzelm@53495
  2217
qed
wenzelm@53495
  2218
lp15@66294
  2219
lp15@66294
  2220
proposition has_integral_negligible:
lp15@66294
  2221
  fixes f :: "'b::euclidean_space \<Rightarrow> 'a::real_normed_vector"
lp15@66294
  2222
  assumes negs: "negligible S"
lp15@66294
  2223
    and "\<And>x. x \<in> (T - S) \<Longrightarrow> f x = 0"
lp15@66294
  2224
  shows "(f has_integral 0) T"
lp15@66294
  2225
proof (cases "\<exists>a b. T = cbox a b")
lp15@66294
  2226
  case True
lp15@66294
  2227
  then have "((\<lambda>x. if x \<in> T then f x else 0) has_integral 0) T"
lp15@66294
  2228
    using assms by (auto intro!: has_integral_negligible_cbox)
lp15@66294
  2229
  then show ?thesis
lp15@66294
  2230
    by (rule has_integral_eq [rotated]) auto
lp15@66294
  2231
next
lp15@66294
  2232
  case False
lp15@66294
  2233
  let ?f = "(\<lambda>x. if x \<in> T then f x else 0)"
lp15@66294
  2234
  have "((\<lambda>x. if x \<in> T then f x else 0) has_integral 0) T"
lp15@66294
  2235
    apply (auto simp: False has_integral_alt [of ?f])
lp15@66294
  2236
    apply (rule_tac x=1 in exI, auto)
lp15@66294
  2237
    apply (rule_tac x=0 in exI, simp add: has_integral_negligible_cbox [OF negs] assms)
lp15@66294
  2238
    done
lp15@66294
  2239
  then show ?thesis
lp15@66294
  2240
    by (rule_tac f="?f" in has_integral_eq) auto
lp15@66294
  2241
qed
lp15@66294
  2242
lp15@67980
  2243
lemma
lp15@67980
  2244
  assumes "negligible S"
lp15@67980
  2245
  shows integrable_negligible: "f integrable_on S" and integral_negligible: "integral S f = 0"
lp15@67980
  2246
  using has_integral_negligible [OF assms]
lp15@67980
  2247
  by (auto simp: has_integral_iff)
lp15@67980
  2248
wenzelm@53495
  2249
lemma has_integral_spike:
immler@56188
  2250
  fixes f :: "'b::euclidean_space \<Rightarrow> 'a::real_normed_vector"
lp15@65587
  2251
  assumes "negligible S"
lp15@65587
  2252
    and gf: "\<And>x. x \<in> T - S \<Longrightarrow> g x = f x"
lp15@65587
  2253
    and fint: "(f has_integral y) T"
lp15@65587
  2254
  shows "(g has_integral y) T"
wenzelm@53495
  2255
proof -
lp15@65587
  2256
  have *: "(g has_integral y) (cbox a b)"
lp15@65587
  2257
       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
  2258
  proof -
immler@56188
  2259
    have "((\<lambda>x. f x + (g x - f x)) has_integral (y + 0)) (cbox a b)"
lp15@65587
  2260
      using that by (intro has_integral_add has_integral_negligible) (auto intro!: \<open>negligible S\<close>)
lp15@65587
  2261
    then show ?thesis
wenzelm@53495
  2262
      by auto
lp15@65587
  2263
  qed
wenzelm@53495
  2264
  show ?thesis
lp15@65587
  2265
    using fint gf
wenzelm@53495
  2266
    apply (subst has_integral_alt)
lp15@65587
  2267
    apply (subst (asm) has_integral_alt)
lp15@66164
  2268
    apply (simp split: if_split_asm)
lp15@66164
  2269
     apply (blast dest: *)
lp15@66164
  2270
      apply (erule_tac V = "\<forall>a b. T \<noteq> cbox a b" in thin_rl)
lp15@66164
  2271
    apply (elim all_forward imp_forward ex_forward all_forward conj_forward asm_rl)
lp15@66164
  2272
     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
  2273
    done
wenzelm@53495
  2274
qed
himmelma@35172
  2275
himmelma@35172
  2276
lemma has_integral_spike_eq:
lp15@65587
  2277
  assumes "negligible S"
lp15@65587
  2278
    and gf: "\<And>x. x \<in> T - S \<Longrightarrow> g x = f x"
lp15@65587
  2279
  shows "(f has_integral y) T \<longleftrightarrow> (g has_integral y) T"
lp15@65587
  2280
    using has_integral_spike [OF \<open>negligible S\<close>] gf
lp15@65587
  2281
    by metis
wenzelm@53495
  2282
wenzelm@53495
  2283
lemma integrable_spike:
lp15@67980
  2284
  assumes "f integrable_on T" "negligible S" "\<And>x. x \<in> T - S \<Longrightarrow> g x = f x"
lp15@67980
  2285
    shows "g integrable_on T"
lp15@65587
  2286
  using assms unfolding integrable_on_def by (blast intro: has_integral_spike)
wenzelm@53495
  2287
wenzelm@53495
  2288
lemma integral_spike:
lp15@65587
  2289
  assumes "negligible S"
lp15@65587
  2290
    and "\<And>x. x \<in> T - S \<Longrightarrow> g x = f x"
lp15@65587
  2291
  shows "integral T f = integral T g"
lp15@65587
  2292
  using has_integral_spike_eq[OF assms]
lp15@65587
  2293
    by (auto simp: integral_def integrable_on_def)
wenzelm@53495
  2294
himmelma@35172
  2295
nipkow@67968
  2296
subsection \<open>Some other trivialities about negligible sets\<close>
himmelma@35172
  2297
lp15@63945
  2298
lemma negligible_subset:
lp15@63945
  2299
  assumes "negligible s" "t \<subseteq> s"
wenzelm@53495
  2300
  shows "negligible t"
wenzelm@53495
  2301
  unfolding negligible_def
lp15@63945
  2302
    by (metis (no_types) Diff_iff assms contra_subsetD has_integral_negligible indicator_simps(2))