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