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