src/HOL/Analysis/Equivalence_Lebesgue_Henstock_Integration.thy
author immler
Fri Mar 10 23:16:40 2017 +0100 (2017-03-10)
changeset 65204 d23eded35a33
parent 64272 f76b6dda2e56
child 65587 16a8991ab398
permissions -rw-r--r--
modernized construction of type bcontfun; base explicit theorems on Uniform_Limit.thy; added some lemmas
hoelzl@63941
     1
(*  Title:      HOL/Analysis/Equivalence_Lebesgue_Henstock_Integration.thy
hoelzl@63941
     2
    Author:     Johannes Hölzl, TU München
hoelzl@63941
     3
    Author:     Robert Himmelmann, TU München
hoelzl@63941
     4
*)
hoelzl@63941
     5
hoelzl@63886
     6
theory Equivalence_Lebesgue_Henstock_Integration
hoelzl@63941
     7
  imports Lebesgue_Measure Henstock_Kurzweil_Integration Complete_Measure Set_Integral
hoelzl@63886
     8
begin
hoelzl@63886
     9
hoelzl@63940
    10
lemma le_left_mono: "x \<le> y \<Longrightarrow> y \<le> a \<longrightarrow> x \<le> (a::'a::preorder)"
hoelzl@63940
    11
  by (auto intro: order_trans)
hoelzl@63940
    12
hoelzl@63940
    13
lemma ball_trans:
hoelzl@63940
    14
  assumes "y \<in> ball z q" "r + q \<le> s" shows "ball y r \<subseteq> ball z s"
hoelzl@63940
    15
proof safe
hoelzl@63940
    16
  fix x assume x: "x \<in> ball y r"
hoelzl@63940
    17
  have "dist z x \<le> dist z y + dist y x"
hoelzl@63940
    18
    by (rule dist_triangle)
hoelzl@63940
    19
  also have "\<dots> < s"
hoelzl@63940
    20
    using assms x by auto
hoelzl@63940
    21
  finally show "x \<in> ball z s"
hoelzl@63940
    22
    by simp
hoelzl@63940
    23
qed
hoelzl@63940
    24
hoelzl@63940
    25
lemma has_integral_implies_lebesgue_measurable_cbox:
hoelzl@63940
    26
  fixes f :: "'a :: euclidean_space \<Rightarrow> real"
hoelzl@63940
    27
  assumes f: "(f has_integral I) (cbox x y)"
hoelzl@63940
    28
  shows "f \<in> lebesgue_on (cbox x y) \<rightarrow>\<^sub>M borel"
hoelzl@63940
    29
proof (rule cld_measure.borel_measurable_cld)
hoelzl@63940
    30
  let ?L = "lebesgue_on (cbox x y)"
hoelzl@63940
    31
  let ?\<mu> = "emeasure ?L"
hoelzl@63940
    32
  let ?\<mu>' = "outer_measure_of ?L"
hoelzl@63940
    33
  interpret L: finite_measure ?L
hoelzl@63940
    34
  proof
hoelzl@63940
    35
    show "?\<mu> (space ?L) \<noteq> \<infinity>"
hoelzl@63940
    36
      by (simp add: emeasure_restrict_space space_restrict_space emeasure_lborel_cbox_eq)
hoelzl@63940
    37
  qed
hoelzl@63940
    38
hoelzl@63940
    39
  show "cld_measure ?L"
hoelzl@63940
    40
  proof
hoelzl@63940
    41
    fix B A assume "B \<subseteq> A" "A \<in> null_sets ?L"
hoelzl@63940
    42
    then show "B \<in> sets ?L"
hoelzl@63940
    43
      using null_sets_completion_subset[OF \<open>B \<subseteq> A\<close>, of lborel]
hoelzl@63940
    44
      by (auto simp add: null_sets_restrict_space sets_restrict_space_iff intro: )
hoelzl@63940
    45
  next
hoelzl@63940
    46
    fix A assume "A \<subseteq> space ?L" "\<And>B. B \<in> sets ?L \<Longrightarrow> ?\<mu> B < \<infinity> \<Longrightarrow> A \<inter> B \<in> sets ?L"
hoelzl@63940
    47
    from this(1) this(2)[of "space ?L"] show "A \<in> sets ?L"
hoelzl@63940
    48
      by (auto simp: Int_absorb2 less_top[symmetric])
hoelzl@63940
    49
  qed auto
hoelzl@63940
    50
  then interpret cld_measure ?L
hoelzl@63940
    51
    .
hoelzl@63940
    52
hoelzl@63940
    53
  have content_eq_L: "A \<in> sets borel \<Longrightarrow> A \<subseteq> cbox x y \<Longrightarrow> content A = measure ?L A" for A
hoelzl@63940
    54
    by (subst measure_restrict_space) (auto simp: measure_def)
hoelzl@63940
    55
hoelzl@63940
    56
  fix E and a b :: real assume "E \<in> sets ?L" "a < b" "0 < ?\<mu> E" "?\<mu> E < \<infinity>"
hoelzl@63940
    57
  then obtain M :: real where "?\<mu> E = M" "0 < M"
hoelzl@63940
    58
    by (cases "?\<mu> E") auto
hoelzl@63940
    59
  define e where "e = M / (4 + 2 / (b - a))"
hoelzl@63940
    60
  from \<open>a < b\<close> \<open>0<M\<close> have "0 < e"
hoelzl@63940
    61
    by (auto intro!: divide_pos_pos simp: field_simps e_def)
hoelzl@63940
    62
hoelzl@63940
    63
  have "e < M / (3 + 2 / (b - a))"
hoelzl@63940
    64
    using \<open>a < b\<close> \<open>0 < M\<close>
hoelzl@63940
    65
    unfolding e_def by (intro divide_strict_left_mono add_strict_right_mono mult_pos_pos) (auto simp: field_simps)
hoelzl@63940
    66
  then have "2 * e < (b - a) * (M - e * 3)"
hoelzl@63940
    67
    using \<open>0<M\<close> \<open>0 < e\<close> \<open>a < b\<close> by (simp add: field_simps)
hoelzl@63940
    68
hoelzl@63940
    69
  have e_less_M: "e < M / 1"
hoelzl@63940
    70
    unfolding e_def using \<open>a < b\<close> \<open>0<M\<close> by (intro divide_strict_left_mono) (auto simp: field_simps)
hoelzl@63940
    71
hoelzl@63940
    72
  obtain d
hoelzl@63940
    73
    where "gauge d"
hoelzl@63940
    74
      and integral_f: "\<forall>p. p tagged_division_of cbox x y \<and> d fine p \<longrightarrow>
hoelzl@63940
    75
        norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R f x) - I) < e"
hoelzl@63940
    76
    using \<open>0<e\<close> f unfolding has_integral by auto
hoelzl@63940
    77
hoelzl@63940
    78
  define C where "C X m = X \<inter> {x. ball x (1/Suc m) \<subseteq> d x}" for X m
hoelzl@63940
    79
  have "incseq (C X)" for X
hoelzl@63940
    80
    unfolding C_def [abs_def]
hoelzl@63940
    81
    by (intro monoI Collect_mono conj_mono imp_refl le_left_mono subset_ball divide_left_mono Int_mono) auto
hoelzl@63940
    82
hoelzl@63940
    83
  { fix X assume "X \<subseteq> space ?L" and eq: "?\<mu>' X = ?\<mu> E"
hoelzl@63940
    84
    have "(SUP m. outer_measure_of ?L (C X m)) = outer_measure_of ?L (\<Union>m. C X m)"
hoelzl@63940
    85
      using \<open>X \<subseteq> space ?L\<close> by (intro SUP_outer_measure_of_incseq \<open>incseq (C X)\<close>) (auto simp: C_def)
hoelzl@63940
    86
    also have "(\<Union>m. C X m) = X"
hoelzl@63940
    87
    proof -
hoelzl@63940
    88
      { fix x
hoelzl@63940
    89
        obtain e where "0 < e" "ball x e \<subseteq> d x"
hoelzl@63940
    90
          using gaugeD[OF \<open>gauge d\<close>, of x] unfolding open_contains_ball by auto
hoelzl@63940
    91
        moreover
hoelzl@63940
    92
        obtain n where "1 / (1 + real n) < e"
hoelzl@63940
    93
          using reals_Archimedean[OF \<open>0<e\<close>] by (auto simp: inverse_eq_divide)
hoelzl@63940
    94
        then have "ball x (1 / (1 + real n)) \<subseteq> ball x e"
hoelzl@63940
    95
          by (intro subset_ball) auto
hoelzl@63940
    96
        ultimately have "\<exists>n. ball x (1 / (1 + real n)) \<subseteq> d x"
hoelzl@63940
    97
          by blast }
hoelzl@63940
    98
      then show ?thesis
hoelzl@63940
    99
        by (auto simp: C_def)
hoelzl@63940
   100
    qed
hoelzl@63940
   101
    finally have "(SUP m. outer_measure_of ?L (C X m)) = ?\<mu> E"
hoelzl@63940
   102
      using eq by auto
hoelzl@63940
   103
    also have "\<dots> > M - e"
hoelzl@63940
   104
      using \<open>0 < M\<close> \<open>?\<mu> E = M\<close> \<open>0<e\<close> by (auto intro!: ennreal_lessI)
hoelzl@63940
   105
    finally have "\<exists>m. M - e < outer_measure_of ?L (C X m)"
hoelzl@63940
   106
      unfolding less_SUP_iff by auto }
hoelzl@63940
   107
  note C = this
hoelzl@63940
   108
hoelzl@63940
   109
  let ?E = "{x\<in>E. f x \<le> a}" and ?F = "{x\<in>E. b \<le> f x}"
hoelzl@63940
   110
hoelzl@63940
   111
  have "\<not> (?\<mu>' ?E = ?\<mu> E \<and> ?\<mu>' ?F = ?\<mu> E)"
hoelzl@63940
   112
  proof
hoelzl@63940
   113
    assume eq: "?\<mu>' ?E = ?\<mu> E \<and> ?\<mu>' ?F = ?\<mu> E"
hoelzl@63940
   114
    with C[of ?E] C[of ?F] \<open>E \<in> sets ?L\<close>[THEN sets.sets_into_space] obtain ma mb
hoelzl@63940
   115
      where "M - e < outer_measure_of ?L (C ?E ma)" "M - e < outer_measure_of ?L (C ?F mb)"
hoelzl@63940
   116
      by auto
hoelzl@63940
   117
    moreover define m where "m = max ma mb"
hoelzl@63940
   118
    ultimately have M_minus_e: "M - e < outer_measure_of ?L (C ?E m)" "M - e < outer_measure_of ?L (C ?F m)"
hoelzl@63940
   119
      using
hoelzl@63940
   120
        incseqD[OF \<open>incseq (C ?E)\<close>, of ma m, THEN outer_measure_of_mono]
hoelzl@63940
   121
        incseqD[OF \<open>incseq (C ?F)\<close>, of mb m, THEN outer_measure_of_mono]
hoelzl@63940
   122
      by (auto intro: less_le_trans)
hoelzl@63940
   123
    define d' where "d' x = d x \<inter> ball x (1 / (3 * Suc m))" for x
hoelzl@63940
   124
    have "gauge d'"
hoelzl@63940
   125
      unfolding d'_def by (intro gauge_inter \<open>gauge d\<close> gauge_ball) auto
hoelzl@63940
   126
    then obtain p where p: "p tagged_division_of cbox x y" "d' fine p"
hoelzl@63940
   127
      by (rule fine_division_exists)
hoelzl@63940
   128
    then have "d fine p"
hoelzl@63940
   129
      unfolding d'_def[abs_def] fine_def by auto
hoelzl@63940
   130
hoelzl@63940
   131
    define s where "s = {(x::'a, k). k \<inter> (C ?E m) \<noteq> {} \<and> k \<inter> (C ?F m) \<noteq> {}}"
hoelzl@63940
   132
    define T where "T E k = (SOME x. x \<in> k \<inter> C E m)" for E k
hoelzl@63940
   133
    let ?A = "(\<lambda>(x, k). (T ?E k, k)) ` (p \<inter> s) \<union> (p - s)"
hoelzl@63940
   134
    let ?B = "(\<lambda>(x, k). (T ?F k, k)) ` (p \<inter> s) \<union> (p - s)"
hoelzl@63940
   135
hoelzl@63940
   136
    { fix X assume X_eq: "X = ?E \<or> X = ?F"
hoelzl@63940
   137
      let ?T = "(\<lambda>(x, k). (T X k, k))"
hoelzl@63940
   138
      let ?p = "?T ` (p \<inter> s) \<union> (p - s)"
hoelzl@63940
   139
hoelzl@63940
   140
      have in_s: "(x, k) \<in> s \<Longrightarrow> T X k \<in> k \<inter> C X m" for x k
hoelzl@63940
   141
        using someI_ex[of "\<lambda>x. x \<in> k \<inter> C X m"] X_eq unfolding ex_in_conv by (auto simp: T_def s_def)
hoelzl@63940
   142
hoelzl@63940
   143
      { fix x k assume "(x, k) \<in> p" "(x, k) \<in> s"
hoelzl@63940
   144
        have k: "k \<subseteq> ball x (1 / (3 * Suc m))"
hoelzl@63940
   145
          using \<open>d' fine p\<close>[THEN fineD, OF \<open>(x, k) \<in> p\<close>] by (auto simp: d'_def)
hoelzl@63940
   146
        then have "x \<in> ball (T X k) (1 / (3 * Suc m))"
hoelzl@63940
   147
          using in_s[OF \<open>(x, k) \<in> s\<close>] by (auto simp: C_def subset_eq dist_commute)
hoelzl@63940
   148
        then have "ball x (1 / (3 * Suc m)) \<subseteq> ball (T X k) (1 / Suc m)"
hoelzl@63940
   149
          by (rule ball_trans) (auto simp: divide_simps)
hoelzl@63940
   150
        with k in_s[OF \<open>(x, k) \<in> s\<close>] have "k \<subseteq> d (T X k)"
hoelzl@63940
   151
          by (auto simp: C_def) }
hoelzl@63940
   152
      then have "d fine ?p"
hoelzl@63940
   153
        using \<open>d fine p\<close> by (auto intro!: fineI)
hoelzl@63940
   154
      moreover
hoelzl@63940
   155
      have "?p tagged_division_of cbox x y"
hoelzl@63940
   156
      proof (rule tagged_division_ofI)
hoelzl@63940
   157
        show "finite ?p"
hoelzl@63940
   158
          using p(1) by auto
hoelzl@63940
   159
      next
hoelzl@63940
   160
        fix z k assume *: "(z, k) \<in> ?p"
hoelzl@63940
   161
        then consider "(z, k) \<in> p" "(z, k) \<notin> s"
hoelzl@63940
   162
          | x' where "(x', k) \<in> p" "(x', k) \<in> s" "z = T X k"
hoelzl@63940
   163
          by (auto simp: T_def)
hoelzl@63940
   164
        then have "z \<in> k \<and> k \<subseteq> cbox x y \<and> (\<exists>a b. k = cbox a b)"
hoelzl@63940
   165
          using p(1) by cases (auto dest: in_s)
hoelzl@63940
   166
        then show "z \<in> k" "k \<subseteq> cbox x y" "\<exists>a b. k = cbox a b"
hoelzl@63940
   167
          by auto
hoelzl@63940
   168
      next
hoelzl@63940
   169
        fix z k z' k' assume "(z, k) \<in> ?p" "(z', k') \<in> ?p" "(z, k) \<noteq> (z', k')"
hoelzl@63940
   170
        with tagged_division_ofD(5)[OF p(1), of _ k _ k']
hoelzl@63940
   171
        show "interior k \<inter> interior k' = {}"
hoelzl@63940
   172
          by (auto simp: T_def dest: in_s)
hoelzl@63940
   173
      next
hoelzl@63940
   174
        have "{k. \<exists>x. (x, k) \<in> ?p} = {k. \<exists>x. (x, k) \<in> p}"
hoelzl@63940
   175
          by (auto simp: T_def image_iff Bex_def)
hoelzl@63940
   176
        then show "\<Union>{k. \<exists>x. (x, k) \<in> ?p} = cbox x y"
hoelzl@63940
   177
          using p(1) by auto
hoelzl@63940
   178
      qed
hoelzl@63940
   179
      ultimately have I: "norm ((\<Sum>(x, k)\<in>?p. content k *\<^sub>R f x) - I) < e"
hoelzl@63940
   180
        using integral_f by auto
hoelzl@63940
   181
hoelzl@63940
   182
      have "(\<Sum>(x, k)\<in>?p. content k *\<^sub>R f x) =
hoelzl@63940
   183
        (\<Sum>(x, k)\<in>?T ` (p \<inter> s). content k *\<^sub>R f x) + (\<Sum>(x, k)\<in>p - s. content k *\<^sub>R f x)"
hoelzl@63940
   184
        using p(1)[THEN tagged_division_ofD(1)]
nipkow@64267
   185
        by (safe intro!: sum.union_inter_neutral) (auto simp: s_def T_def)
hoelzl@63940
   186
      also have "(\<Sum>(x, k)\<in>?T ` (p \<inter> s). content k *\<^sub>R f x) = (\<Sum>(x, k)\<in>p \<inter> s. content k *\<^sub>R f (T X k))"
nipkow@64267
   187
      proof (subst sum.reindex_nontrivial, safe)
hoelzl@63940
   188
        fix x1 x2 k assume 1: "(x1, k) \<in> p" "(x1, k) \<in> s" and 2: "(x2, k) \<in> p" "(x2, k) \<in> s"
hoelzl@63940
   189
          and eq: "content k *\<^sub>R f (T X k) \<noteq> 0"
hoelzl@63940
   190
        with tagged_division_ofD(5)[OF p(1), of x1 k x2 k] tagged_division_ofD(4)[OF p(1), of x1 k]
hoelzl@63940
   191
        show "x1 = x2"
hoelzl@63940
   192
          by (auto simp: content_eq_0_interior)
nipkow@64267
   193
      qed (use p in \<open>auto intro!: sum.cong\<close>)
hoelzl@63940
   194
      finally have eq: "(\<Sum>(x, k)\<in>?p. content k *\<^sub>R f x) =
hoelzl@63940
   195
        (\<Sum>(x, k)\<in>p \<inter> s. content k *\<^sub>R f (T X k)) + (\<Sum>(x, k)\<in>p - s. content k *\<^sub>R f x)" .
hoelzl@63940
   196
hoelzl@63940
   197
      have in_T: "(x, k) \<in> s \<Longrightarrow> T X k \<in> X" for x k
hoelzl@63940
   198
        using in_s[of x k] by (auto simp: C_def)
hoelzl@63940
   199
hoelzl@63940
   200
      note I eq in_T }
hoelzl@63940
   201
    note parts = this
hoelzl@63940
   202
hoelzl@63940
   203
    have p_in_L: "(x, k) \<in> p \<Longrightarrow> k \<in> sets ?L" for x k
hoelzl@63940
   204
      using tagged_division_ofD(3, 4)[OF p(1), of x k] by (auto simp: sets_restrict_space)
hoelzl@63940
   205
hoelzl@63940
   206
    have [simp]: "finite p"
hoelzl@63940
   207
      using tagged_division_ofD(1)[OF p(1)] .
hoelzl@63940
   208
hoelzl@63940
   209
    have "(M - 3*e) * (b - a) \<le> (\<Sum>(x, k)\<in>p \<inter> s. content k) * (b - a)"
hoelzl@63940
   210
    proof (intro mult_right_mono)
hoelzl@63940
   211
      have fin: "?\<mu> (E \<inter> \<Union>{k\<in>snd`p. k \<inter> C X m = {}}) < \<infinity>" for X
hoelzl@63940
   212
        using \<open>?\<mu> E < \<infinity>\<close> by (rule le_less_trans[rotated]) (auto intro!: emeasure_mono \<open>E \<in> sets ?L\<close>)
hoelzl@63940
   213
      have sets: "(E \<inter> \<Union>{k\<in>snd`p. k \<inter> C X m = {}}) \<in> sets ?L" for X
hoelzl@63940
   214
        using tagged_division_ofD(1)[OF p(1)] by (intro sets.Diff \<open>E \<in> sets ?L\<close> sets.finite_Union sets.Int) (auto intro: p_in_L)
hoelzl@63940
   215
      { fix X assume "X \<subseteq> E" "M - e < ?\<mu>' (C X m)"
hoelzl@63940
   216
        have "M - e \<le> ?\<mu>' (C X m)"
hoelzl@63940
   217
          by (rule less_imp_le) fact
hoelzl@63940
   218
        also have "\<dots> \<le> ?\<mu>' (E - (E \<inter> \<Union>{k\<in>snd`p. k \<inter> C X m = {}}))"
hoelzl@63940
   219
        proof (intro outer_measure_of_mono subsetI)
hoelzl@63940
   220
          fix v assume "v \<in> C X m"
hoelzl@63940
   221
          then have "v \<in> cbox x y" "v \<in> E"
hoelzl@63940
   222
            using \<open>E \<subseteq> space ?L\<close> \<open>X \<subseteq> E\<close> by (auto simp: space_restrict_space C_def)
hoelzl@63940
   223
          then obtain z k where "(z, k) \<in> p" "v \<in> k"
hoelzl@63940
   224
            using tagged_division_ofD(6)[OF p(1), symmetric] by auto
hoelzl@63940
   225
          then show "v \<in> E - E \<inter> (\<Union>{k\<in>snd`p. k \<inter> C X m = {}})"
hoelzl@63940
   226
            using \<open>v \<in> C X m\<close> \<open>v \<in> E\<close> by auto
hoelzl@63940
   227
        qed
hoelzl@63940
   228
        also have "\<dots> = ?\<mu> E - ?\<mu> (E \<inter> \<Union>{k\<in>snd`p. k \<inter> C X m = {}})"
hoelzl@63940
   229
          using \<open>E \<in> sets ?L\<close> fin[of X] sets[of X] by (auto intro!: emeasure_Diff)
hoelzl@63940
   230
        finally have "?\<mu> (E \<inter> \<Union>{k\<in>snd`p. k \<inter> C X m = {}}) \<le> e"
hoelzl@63940
   231
          using \<open>0 < e\<close> e_less_M apply (cases "?\<mu> (E \<inter> \<Union>{k\<in>snd`p. k \<inter> C X m = {}})")
hoelzl@63940
   232
          by (auto simp add: \<open>?\<mu> E = M\<close> ennreal_minus ennreal_le_iff2)
hoelzl@63940
   233
        note this }
hoelzl@63940
   234
      note upper_bound = this
hoelzl@63940
   235
hoelzl@63940
   236
      have "?\<mu> (E \<inter> \<Union>(snd`(p - s))) =
hoelzl@63940
   237
        ?\<mu> ((E \<inter> \<Union>{k\<in>snd`p. k \<inter> C ?E m = {}}) \<union> (E \<inter> \<Union>{k\<in>snd`p. k \<inter> C ?F m = {}}))"
hoelzl@63940
   238
        by (intro arg_cong[where f="?\<mu>"]) (auto simp: s_def image_def Bex_def)
hoelzl@63940
   239
      also have "\<dots> \<le> ?\<mu> (E \<inter> \<Union>{k\<in>snd`p. k \<inter> C ?E m = {}}) + ?\<mu> (E \<inter> \<Union>{k\<in>snd`p. k \<inter> C ?F m = {}})"
hoelzl@63940
   240
        using sets[of ?E] sets[of ?F] M_minus_e by (intro emeasure_subadditive) auto
hoelzl@63940
   241
      also have "\<dots> \<le> e + ennreal e"
hoelzl@63940
   242
        using upper_bound[of ?E] upper_bound[of ?F] M_minus_e by (intro add_mono) auto
hoelzl@63940
   243
      finally have "?\<mu> E - 2*e \<le> ?\<mu> (E - (E \<inter> \<Union>(snd`(p - s))))"
hoelzl@63940
   244
        using \<open>0 < e\<close> \<open>E \<in> sets ?L\<close> tagged_division_ofD(1)[OF p(1)]
hoelzl@63940
   245
        by (subst emeasure_Diff)
hoelzl@63940
   246
           (auto simp: ennreal_plus[symmetric] top_unique simp del: ennreal_plus
hoelzl@63940
   247
                 intro!: sets.Int sets.finite_UN ennreal_mono_minus intro: p_in_L)
hoelzl@63940
   248
      also have "\<dots> \<le> ?\<mu> (\<Union>x\<in>p \<inter> s. snd x)"
hoelzl@63940
   249
      proof (safe intro!: emeasure_mono subsetI)
hoelzl@63940
   250
        fix v assume "v \<in> E" and not: "v \<notin> (\<Union>x\<in>p \<inter> s. snd x)"
hoelzl@63940
   251
        then have "v \<in> cbox x y"
hoelzl@63940
   252
          using \<open>E \<subseteq> space ?L\<close> by (auto simp: space_restrict_space)
hoelzl@63940
   253
        then obtain z k where "(z, k) \<in> p" "v \<in> k"
hoelzl@63940
   254
          using tagged_division_ofD(6)[OF p(1), symmetric] by auto
hoelzl@63940
   255
        with not show "v \<in> UNION (p - s) snd"
hoelzl@63940
   256
          by (auto intro!: bexI[of _ "(z, k)"] elim: ballE[of _ _ "(z, k)"])
hoelzl@63940
   257
      qed (auto intro!: sets.Int sets.finite_UN ennreal_mono_minus intro: p_in_L)
hoelzl@63940
   258
      also have "\<dots> = measure ?L (\<Union>x\<in>p \<inter> s. snd x)"
hoelzl@63940
   259
        by (auto intro!: emeasure_eq_ennreal_measure)
hoelzl@63940
   260
      finally have "M - 2 * e \<le> measure ?L (\<Union>x\<in>p \<inter> s. snd x)"
hoelzl@63940
   261
        unfolding \<open>?\<mu> E = M\<close> using \<open>0 < e\<close> by (simp add: ennreal_minus)
hoelzl@63940
   262
      also have "measure ?L (\<Union>x\<in>p \<inter> s. snd x) = content (\<Union>x\<in>p \<inter> s. snd x)"
hoelzl@63940
   263
        using tagged_division_ofD(1,3,4) [OF p(1)]
hoelzl@63940
   264
        by (intro content_eq_L[symmetric])
hoelzl@63940
   265
           (fastforce intro!: sets.finite_UN UN_least del: subsetI)+
hoelzl@63940
   266
      also have "content (\<Union>x\<in>p \<inter> s. snd x) \<le> (\<Sum>k\<in>p \<inter> s. content (snd k))"
hoelzl@63940
   267
        using p(1) by (auto simp: emeasure_lborel_cbox_eq intro!: measure_subadditive_finite
hoelzl@63940
   268
                            dest!: p(1)[THEN tagged_division_ofD(4)])
hoelzl@63940
   269
      finally show "M - 3 * e \<le> (\<Sum>(x, y)\<in>p \<inter> s. content y)"
hoelzl@63940
   270
        using \<open>0 < e\<close> by (simp add: split_beta)
hoelzl@63940
   271
    qed (use \<open>a < b\<close> in auto)
hoelzl@63940
   272
    also have "\<dots> = (\<Sum>(x, k)\<in>p \<inter> s. content k * (b - a))"
nipkow@64267
   273
      by (simp add: sum_distrib_right split_beta')
hoelzl@63940
   274
    also have "\<dots> \<le> (\<Sum>(x, k)\<in>p \<inter> s. content k * (f (T ?F k) - f (T ?E k)))"
nipkow@64267
   275
      using parts(3) by (auto intro!: sum_mono mult_left_mono diff_mono)
hoelzl@63940
   276
    also have "\<dots> = (\<Sum>(x, k)\<in>p \<inter> s. content k * f (T ?F k)) - (\<Sum>(x, k)\<in>p \<inter> s. content k * f (T ?E k))"
nipkow@64267
   277
      by (auto intro!: sum.cong simp: field_simps sum_subtractf[symmetric])
hoelzl@63940
   278
    also have "\<dots> = (\<Sum>(x, k)\<in>?B. content k *\<^sub>R f x) - (\<Sum>(x, k)\<in>?A. content k *\<^sub>R f x)"
hoelzl@63940
   279
      by (subst (1 2) parts) auto
hoelzl@63940
   280
    also have "\<dots> \<le> norm ((\<Sum>(x, k)\<in>?B. content k *\<^sub>R f x) - (\<Sum>(x, k)\<in>?A. content k *\<^sub>R f x))"
hoelzl@63940
   281
      by auto
hoelzl@63940
   282
    also have "\<dots> \<le> e + e"
hoelzl@63940
   283
      using parts(1)[of ?E] parts(1)[of ?F] by (intro norm_diff_triangle_le[of _ I]) auto
hoelzl@63940
   284
    finally show False
hoelzl@63940
   285
      using \<open>2 * e < (b - a) * (M - e * 3)\<close> by (auto simp: field_simps)
hoelzl@63940
   286
  qed
hoelzl@63940
   287
  moreover have "?\<mu>' ?E \<le> ?\<mu> E" "?\<mu>' ?F \<le> ?\<mu> E"
hoelzl@63940
   288
    unfolding outer_measure_of_eq[OF \<open>E \<in> sets ?L\<close>, symmetric] by (auto intro!: outer_measure_of_mono)
hoelzl@63940
   289
  ultimately show "min (?\<mu>' ?E) (?\<mu>' ?F) < ?\<mu> E"
hoelzl@63940
   290
    unfolding min_less_iff_disj by (auto simp: less_le)
hoelzl@63940
   291
qed
hoelzl@63940
   292
hoelzl@63940
   293
lemma has_integral_implies_lebesgue_measurable_real:
hoelzl@63940
   294
  fixes f :: "'a :: euclidean_space \<Rightarrow> real"
hoelzl@63940
   295
  assumes f: "(f has_integral I) \<Omega>"
hoelzl@63940
   296
  shows "(\<lambda>x. f x * indicator \<Omega> x) \<in> lebesgue \<rightarrow>\<^sub>M borel"
hoelzl@63940
   297
proof -
hoelzl@63940
   298
  define B :: "nat \<Rightarrow> 'a set" where "B n = cbox (- real n *\<^sub>R One) (real n *\<^sub>R One)" for n
hoelzl@63940
   299
  show "(\<lambda>x. f x * indicator \<Omega> x) \<in> lebesgue \<rightarrow>\<^sub>M borel"
hoelzl@63940
   300
  proof (rule measurable_piecewise_restrict)
hoelzl@63940
   301
    have "(\<Union>n. box (- real n *\<^sub>R One) (real n *\<^sub>R One)) \<subseteq> UNION UNIV B"
hoelzl@63940
   302
      unfolding B_def by (intro UN_mono box_subset_cbox order_refl)
hoelzl@63940
   303
    then show "countable (range B)" "space lebesgue \<subseteq> UNION UNIV B"
hoelzl@63940
   304
      by (auto simp: B_def UN_box_eq_UNIV)
hoelzl@63940
   305
  next
hoelzl@63940
   306
    fix \<Omega>' assume "\<Omega>' \<in> range B"
hoelzl@63940
   307
    then obtain n where \<Omega>': "\<Omega>' = B n" by auto
hoelzl@63940
   308
    then show "\<Omega>' \<inter> space lebesgue \<in> sets lebesgue"
hoelzl@63940
   309
      by (auto simp: B_def)
hoelzl@63940
   310
hoelzl@63940
   311
    have "f integrable_on \<Omega>"
hoelzl@63940
   312
      using f by auto
hoelzl@63940
   313
    then have "(\<lambda>x. f x * indicator \<Omega> x) integrable_on \<Omega>"
hoelzl@63940
   314
      by (auto simp: integrable_on_def cong: has_integral_cong)
hoelzl@63940
   315
    then have "(\<lambda>x. f x * indicator \<Omega> x) integrable_on (\<Omega> \<union> B n)"
hoelzl@63940
   316
      by (rule integrable_on_superset[rotated 2]) auto
hoelzl@63940
   317
    then have "(\<lambda>x. f x * indicator \<Omega> x) integrable_on B n"
hoelzl@63940
   318
      unfolding B_def by (rule integrable_on_subcbox) auto
hoelzl@63940
   319
    then show "(\<lambda>x. f x * indicator \<Omega> x) \<in> lebesgue_on \<Omega>' \<rightarrow>\<^sub>M borel"
hoelzl@63940
   320
      unfolding B_def \<Omega>' by (auto intro: has_integral_implies_lebesgue_measurable_cbox simp: integrable_on_def)
hoelzl@63940
   321
  qed
hoelzl@63940
   322
qed
hoelzl@63940
   323
hoelzl@63940
   324
lemma has_integral_implies_lebesgue_measurable:
hoelzl@63940
   325
  fixes f :: "'a :: euclidean_space \<Rightarrow> 'b :: euclidean_space"
hoelzl@63940
   326
  assumes f: "(f has_integral I) \<Omega>"
hoelzl@63940
   327
  shows "(\<lambda>x. indicator \<Omega> x *\<^sub>R f x) \<in> lebesgue \<rightarrow>\<^sub>M borel"
hoelzl@63940
   328
proof (intro borel_measurable_euclidean_space[where 'c='b, THEN iffD2] ballI)
hoelzl@63940
   329
  fix i :: "'b" assume "i \<in> Basis"
hoelzl@63940
   330
  have "(\<lambda>x. (f x \<bullet> i) * indicator \<Omega> x) \<in> borel_measurable (completion lborel)"
hoelzl@63940
   331
    using has_integral_linear[OF f bounded_linear_inner_left, of i]
hoelzl@63940
   332
    by (intro has_integral_implies_lebesgue_measurable_real) (auto simp: comp_def)
hoelzl@63940
   333
  then show "(\<lambda>x. indicator \<Omega> x *\<^sub>R f x \<bullet> i) \<in> borel_measurable (completion lborel)"
hoelzl@63940
   334
    by (simp add: ac_simps)
hoelzl@63940
   335
qed
hoelzl@63940
   336
hoelzl@63886
   337
subsection \<open>Equivalence Lebesgue integral on @{const lborel} and HK-integral\<close>
hoelzl@63886
   338
hoelzl@63886
   339
lemma has_integral_measure_lborel:
hoelzl@63886
   340
  fixes A :: "'a::euclidean_space set"
hoelzl@63886
   341
  assumes A[measurable]: "A \<in> sets borel" and finite: "emeasure lborel A < \<infinity>"
hoelzl@63886
   342
  shows "((\<lambda>x. 1) has_integral measure lborel A) A"
hoelzl@63886
   343
proof -
hoelzl@63886
   344
  { fix l u :: 'a
hoelzl@63886
   345
    have "((\<lambda>x. 1) has_integral measure lborel (box l u)) (box l u)"
hoelzl@63886
   346
    proof cases
hoelzl@63886
   347
      assume "\<forall>b\<in>Basis. l \<bullet> b \<le> u \<bullet> b"
hoelzl@63886
   348
      then show ?thesis
hoelzl@63886
   349
        apply simp
hoelzl@63886
   350
        apply (subst has_integral_restrict[symmetric, OF box_subset_cbox])
hoelzl@63886
   351
        apply (subst has_integral_spike_interior_eq[where g="\<lambda>_. 1"])
hoelzl@63886
   352
        using has_integral_const[of "1::real" l u]
hoelzl@63886
   353
        apply (simp_all add: inner_diff_left[symmetric] content_cbox_cases)
hoelzl@63886
   354
        done
hoelzl@63886
   355
    next
hoelzl@63886
   356
      assume "\<not> (\<forall>b\<in>Basis. l \<bullet> b \<le> u \<bullet> b)"
hoelzl@63886
   357
      then have "box l u = {}"
hoelzl@63886
   358
        unfolding box_eq_empty by (auto simp: not_le intro: less_imp_le)
hoelzl@63886
   359
      then show ?thesis
hoelzl@63886
   360
        by simp
hoelzl@63886
   361
    qed }
hoelzl@63886
   362
  note has_integral_box = this
hoelzl@63886
   363
hoelzl@63886
   364
  { fix a b :: 'a let ?M = "\<lambda>A. measure lborel (A \<inter> box a b)"
hoelzl@63886
   365
    have "Int_stable  (range (\<lambda>(a, b). box a b))"
hoelzl@63886
   366
      by (auto simp: Int_stable_def box_Int_box)
hoelzl@63886
   367
    moreover have "(range (\<lambda>(a, b). box a b)) \<subseteq> Pow UNIV"
hoelzl@63886
   368
      by auto
hoelzl@63886
   369
    moreover have "A \<in> sigma_sets UNIV (range (\<lambda>(a, b). box a b))"
hoelzl@63886
   370
       using A unfolding borel_eq_box by simp
hoelzl@63886
   371
    ultimately have "((\<lambda>x. 1) has_integral ?M A) (A \<inter> box a b)"
hoelzl@63886
   372
    proof (induction rule: sigma_sets_induct_disjoint)
hoelzl@63886
   373
      case (basic A) then show ?case
hoelzl@63886
   374
        by (auto simp: box_Int_box has_integral_box)
hoelzl@63886
   375
    next
hoelzl@63886
   376
      case empty then show ?case
hoelzl@63886
   377
        by simp
hoelzl@63886
   378
    next
hoelzl@63886
   379
      case (compl A)
hoelzl@63886
   380
      then have [measurable]: "A \<in> sets borel"
hoelzl@63886
   381
        by (simp add: borel_eq_box)
hoelzl@63886
   382
hoelzl@63886
   383
      have "((\<lambda>x. 1) has_integral ?M (box a b)) (box a b)"
hoelzl@63886
   384
        by (simp add: has_integral_box)
hoelzl@63886
   385
      moreover have "((\<lambda>x. if x \<in> A \<inter> box a b then 1 else 0) has_integral ?M A) (box a b)"
hoelzl@63886
   386
        by (subst has_integral_restrict) (auto intro: compl)
hoelzl@63886
   387
      ultimately have "((\<lambda>x. 1 - (if x \<in> A \<inter> box a b then 1 else 0)) has_integral ?M (box a b) - ?M A) (box a b)"
hoelzl@63886
   388
        by (rule has_integral_sub)
hoelzl@63886
   389
      then have "((\<lambda>x. (if x \<in> (UNIV - A) \<inter> box a b then 1 else 0)) has_integral ?M (box a b) - ?M A) (box a b)"
hoelzl@63886
   390
        by (rule has_integral_cong[THEN iffD1, rotated 1]) auto
hoelzl@63886
   391
      then have "((\<lambda>x. 1) has_integral ?M (box a b) - ?M A) ((UNIV - A) \<inter> box a b)"
hoelzl@63886
   392
        by (subst (asm) has_integral_restrict) auto
hoelzl@63886
   393
      also have "?M (box a b) - ?M A = ?M (UNIV - A)"
hoelzl@63886
   394
        by (subst measure_Diff[symmetric]) (auto simp: emeasure_lborel_box_eq Diff_Int_distrib2)
hoelzl@63886
   395
      finally show ?case .
hoelzl@63886
   396
    next
hoelzl@63886
   397
      case (union F)
hoelzl@63886
   398
      then have [measurable]: "\<And>i. F i \<in> sets borel"
hoelzl@63886
   399
        by (simp add: borel_eq_box subset_eq)
hoelzl@63886
   400
      have "((\<lambda>x. if x \<in> UNION UNIV F \<inter> box a b then 1 else 0) has_integral ?M (\<Union>i. F i)) (box a b)"
hoelzl@63886
   401
      proof (rule has_integral_monotone_convergence_increasing)
hoelzl@63886
   402
        let ?f = "\<lambda>k x. \<Sum>i<k. if x \<in> F i \<inter> box a b then 1 else 0 :: real"
hoelzl@63886
   403
        show "\<And>k. (?f k has_integral (\<Sum>i<k. ?M (F i))) (box a b)"
nipkow@64267
   404
          using union.IH by (auto intro!: has_integral_sum simp del: Int_iff)
hoelzl@63886
   405
        show "\<And>k x. ?f k x \<le> ?f (Suc k) x"
nipkow@64267
   406
          by (intro sum_mono2) auto
hoelzl@63886
   407
        from union(1) have *: "\<And>x i j. x \<in> F i \<Longrightarrow> x \<in> F j \<longleftrightarrow> j = i"
hoelzl@63886
   408
          by (auto simp add: disjoint_family_on_def)
hoelzl@63886
   409
        show "\<And>x. (\<lambda>k. ?f k x) \<longlonglongrightarrow> (if x \<in> UNION UNIV F \<inter> box a b then 1 else 0)"
nipkow@64267
   410
          apply (auto simp: * sum.If_cases Iio_Int_singleton)
hoelzl@63886
   411
          apply (rule_tac k="Suc xa" in LIMSEQ_offset)
hoelzl@63886
   412
          apply simp
hoelzl@63886
   413
          done
hoelzl@63886
   414
        have *: "emeasure lborel ((\<Union>x. F x) \<inter> box a b) \<le> emeasure lborel (box a b)"
hoelzl@63886
   415
          by (intro emeasure_mono) auto
hoelzl@63886
   416
hoelzl@63886
   417
        with union(1) show "(\<lambda>k. \<Sum>i<k. ?M (F i)) \<longlonglongrightarrow> ?M (\<Union>i. F i)"
hoelzl@63886
   418
          unfolding sums_def[symmetric] UN_extend_simps
hoelzl@63886
   419
          by (intro measure_UNION) (auto simp: disjoint_family_on_def emeasure_lborel_box_eq top_unique)
hoelzl@63886
   420
      qed
hoelzl@63886
   421
      then show ?case
hoelzl@63886
   422
        by (subst (asm) has_integral_restrict) auto
hoelzl@63886
   423
    qed }
hoelzl@63886
   424
  note * = this
hoelzl@63886
   425
hoelzl@63886
   426
  show ?thesis
hoelzl@63886
   427
  proof (rule has_integral_monotone_convergence_increasing)
hoelzl@63886
   428
    let ?B = "\<lambda>n::nat. box (- real n *\<^sub>R One) (real n *\<^sub>R One) :: 'a set"
hoelzl@63886
   429
    let ?f = "\<lambda>n::nat. \<lambda>x. if x \<in> A \<inter> ?B n then 1 else 0 :: real"
hoelzl@63886
   430
    let ?M = "\<lambda>n. measure lborel (A \<inter> ?B n)"
hoelzl@63886
   431
hoelzl@63886
   432
    show "\<And>n::nat. (?f n has_integral ?M n) A"
hoelzl@63886
   433
      using * by (subst has_integral_restrict) simp_all
hoelzl@63886
   434
    show "\<And>k x. ?f k x \<le> ?f (Suc k) x"
hoelzl@63886
   435
      by (auto simp: box_def)
hoelzl@63886
   436
    { fix x assume "x \<in> A"
hoelzl@63886
   437
      moreover have "(\<lambda>k. indicator (A \<inter> ?B k) x :: real) \<longlonglongrightarrow> indicator (\<Union>k::nat. A \<inter> ?B k) x"
hoelzl@63886
   438
        by (intro LIMSEQ_indicator_incseq) (auto simp: incseq_def box_def)
hoelzl@63886
   439
      ultimately show "(\<lambda>k. if x \<in> A \<inter> ?B k then 1 else 0::real) \<longlonglongrightarrow> 1"
hoelzl@63886
   440
        by (simp add: indicator_def UN_box_eq_UNIV) }
hoelzl@63886
   441
hoelzl@63886
   442
    have "(\<lambda>n. emeasure lborel (A \<inter> ?B n)) \<longlonglongrightarrow> emeasure lborel (\<Union>n::nat. A \<inter> ?B n)"
hoelzl@63886
   443
      by (intro Lim_emeasure_incseq) (auto simp: incseq_def box_def)
hoelzl@63886
   444
    also have "(\<lambda>n. emeasure lborel (A \<inter> ?B n)) = (\<lambda>n. measure lborel (A \<inter> ?B n))"
hoelzl@63886
   445
    proof (intro ext emeasure_eq_ennreal_measure)
hoelzl@63886
   446
      fix n have "emeasure lborel (A \<inter> ?B n) \<le> emeasure lborel (?B n)"
hoelzl@63886
   447
        by (intro emeasure_mono) auto
hoelzl@63886
   448
      then show "emeasure lborel (A \<inter> ?B n) \<noteq> top"
hoelzl@63886
   449
        by (auto simp: top_unique)
hoelzl@63886
   450
    qed
hoelzl@63886
   451
    finally show "(\<lambda>n. measure lborel (A \<inter> ?B n)) \<longlonglongrightarrow> measure lborel A"
hoelzl@63886
   452
      using emeasure_eq_ennreal_measure[of lborel A] finite
hoelzl@63886
   453
      by (simp add: UN_box_eq_UNIV less_top)
hoelzl@63886
   454
  qed
hoelzl@63886
   455
qed
hoelzl@63886
   456
hoelzl@63886
   457
lemma nn_integral_has_integral:
hoelzl@63886
   458
  fixes f::"'a::euclidean_space \<Rightarrow> real"
hoelzl@63886
   459
  assumes f: "f \<in> borel_measurable borel" "\<And>x. 0 \<le> f x" "(\<integral>\<^sup>+x. f x \<partial>lborel) = ennreal r" "0 \<le> r"
hoelzl@63886
   460
  shows "(f has_integral r) UNIV"
hoelzl@63886
   461
using f proof (induct f arbitrary: r rule: borel_measurable_induct_real)
hoelzl@63886
   462
  case (set A)
hoelzl@63886
   463
  then have "((\<lambda>x. 1) has_integral measure lborel A) A"
hoelzl@63886
   464
    by (intro has_integral_measure_lborel) (auto simp: ennreal_indicator)
hoelzl@63886
   465
  with set show ?case
hoelzl@63886
   466
    by (simp add: ennreal_indicator measure_def) (simp add: indicator_def)
hoelzl@63886
   467
next
hoelzl@63886
   468
  case (mult g c)
hoelzl@63886
   469
  then have "ennreal c * (\<integral>\<^sup>+ x. g x \<partial>lborel) = ennreal r"
hoelzl@63886
   470
    by (subst nn_integral_cmult[symmetric]) (auto simp: ennreal_mult)
hoelzl@63886
   471
  with \<open>0 \<le> r\<close> \<open>0 \<le> c\<close>
hoelzl@63886
   472
  obtain r' where "(c = 0 \<and> r = 0) \<or> (0 \<le> r' \<and> (\<integral>\<^sup>+ x. ennreal (g x) \<partial>lborel) = ennreal r' \<and> r = c * r')"
hoelzl@63886
   473
    by (cases "\<integral>\<^sup>+ x. ennreal (g x) \<partial>lborel" rule: ennreal_cases)
hoelzl@63886
   474
       (auto split: if_split_asm simp: ennreal_mult_top ennreal_mult[symmetric])
hoelzl@63886
   475
  with mult show ?case
hoelzl@63886
   476
    by (auto intro!: has_integral_cmult_real)
hoelzl@63886
   477
next
hoelzl@63886
   478
  case (add g h)
hoelzl@63886
   479
  then have "(\<integral>\<^sup>+ x. h x + g x \<partial>lborel) = (\<integral>\<^sup>+ x. h x \<partial>lborel) + (\<integral>\<^sup>+ x. g x \<partial>lborel)"
hoelzl@63886
   480
    by (simp add: nn_integral_add)
hoelzl@63886
   481
  with add obtain a b where "0 \<le> a" "0 \<le> b" "(\<integral>\<^sup>+ x. h x \<partial>lborel) = ennreal a" "(\<integral>\<^sup>+ x. g x \<partial>lborel) = ennreal b" "r = a + b"
hoelzl@63886
   482
    by (cases "\<integral>\<^sup>+ x. h x \<partial>lborel" "\<integral>\<^sup>+ x. g x \<partial>lborel" rule: ennreal2_cases)
hoelzl@63886
   483
       (auto simp: add_top nn_integral_add top_add ennreal_plus[symmetric] simp del: ennreal_plus)
hoelzl@63886
   484
  with add show ?case
hoelzl@63886
   485
    by (auto intro!: has_integral_add)
hoelzl@63886
   486
next
hoelzl@63886
   487
  case (seq U)
hoelzl@63886
   488
  note seq(1)[measurable] and f[measurable]
hoelzl@63886
   489
hoelzl@63886
   490
  { fix i x
hoelzl@63886
   491
    have "U i x \<le> f x"
hoelzl@63886
   492
      using seq(5)
hoelzl@63886
   493
      apply (rule LIMSEQ_le_const)
hoelzl@63886
   494
      using seq(4)
hoelzl@63886
   495
      apply (auto intro!: exI[of _ i] simp: incseq_def le_fun_def)
hoelzl@63886
   496
      done }
hoelzl@63886
   497
  note U_le_f = this
hoelzl@63886
   498
hoelzl@63886
   499
  { fix i
hoelzl@63886
   500
    have "(\<integral>\<^sup>+x. U i x \<partial>lborel) \<le> (\<integral>\<^sup>+x. f x \<partial>lborel)"
hoelzl@63886
   501
      using seq(2) f(2) U_le_f by (intro nn_integral_mono) simp
hoelzl@63886
   502
    then obtain p where "(\<integral>\<^sup>+x. U i x \<partial>lborel) = ennreal p" "p \<le> r" "0 \<le> p"
hoelzl@63886
   503
      using seq(6) \<open>0\<le>r\<close> by (cases "\<integral>\<^sup>+x. U i x \<partial>lborel" rule: ennreal_cases) (auto simp: top_unique)
hoelzl@63886
   504
    moreover note seq
hoelzl@63886
   505
    ultimately have "\<exists>p. (\<integral>\<^sup>+x. U i x \<partial>lborel) = ennreal p \<and> 0 \<le> p \<and> p \<le> r \<and> (U i has_integral p) UNIV"
hoelzl@63886
   506
      by auto }
hoelzl@63886
   507
  then obtain p where p: "\<And>i. (\<integral>\<^sup>+x. ennreal (U i x) \<partial>lborel) = ennreal (p i)"
hoelzl@63886
   508
    and bnd: "\<And>i. p i \<le> r" "\<And>i. 0 \<le> p i"
hoelzl@63886
   509
    and U_int: "\<And>i.(U i has_integral (p i)) UNIV" by metis
hoelzl@63886
   510
hoelzl@63886
   511
  have int_eq: "\<And>i. integral UNIV (U i) = p i" using U_int by (rule integral_unique)
hoelzl@63886
   512
hoelzl@63886
   513
  have *: "f integrable_on UNIV \<and> (\<lambda>k. integral UNIV (U k)) \<longlonglongrightarrow> integral UNIV f"
hoelzl@63886
   514
  proof (rule monotone_convergence_increasing)
hoelzl@63886
   515
    show "\<forall>k. U k integrable_on UNIV" using U_int by auto
hoelzl@63886
   516
    show "\<forall>k. \<forall>x\<in>UNIV. U k x \<le> U (Suc k) x" using \<open>incseq U\<close> by (auto simp: incseq_def le_fun_def)
hoelzl@63886
   517
    then show "bounded {integral UNIV (U k) |k. True}"
hoelzl@63886
   518
      using bnd int_eq by (auto simp: bounded_real intro!: exI[of _ r])
hoelzl@63886
   519
    show "\<forall>x\<in>UNIV. (\<lambda>k. U k x) \<longlonglongrightarrow> f x"
hoelzl@63886
   520
      using seq by auto
hoelzl@63886
   521
  qed
hoelzl@63886
   522
  moreover have "(\<lambda>i. (\<integral>\<^sup>+x. U i x \<partial>lborel)) \<longlonglongrightarrow> (\<integral>\<^sup>+x. f x \<partial>lborel)"
hoelzl@63886
   523
    using seq f(2) U_le_f by (intro nn_integral_dominated_convergence[where w=f]) auto
hoelzl@63886
   524
  ultimately have "integral UNIV f = r"
hoelzl@63886
   525
    by (auto simp add: bnd int_eq p seq intro: LIMSEQ_unique)
hoelzl@63886
   526
  with * show ?case
hoelzl@63886
   527
    by (simp add: has_integral_integral)
hoelzl@63886
   528
qed
hoelzl@63886
   529
hoelzl@63886
   530
lemma nn_integral_lborel_eq_integral:
hoelzl@63886
   531
  fixes f::"'a::euclidean_space \<Rightarrow> real"
hoelzl@63886
   532
  assumes f: "f \<in> borel_measurable borel" "\<And>x. 0 \<le> f x" "(\<integral>\<^sup>+x. f x \<partial>lborel) < \<infinity>"
hoelzl@63886
   533
  shows "(\<integral>\<^sup>+x. f x \<partial>lborel) = integral UNIV f"
hoelzl@63886
   534
proof -
hoelzl@63886
   535
  from f(3) obtain r where r: "(\<integral>\<^sup>+x. f x \<partial>lborel) = ennreal r" "0 \<le> r"
hoelzl@63886
   536
    by (cases "\<integral>\<^sup>+x. f x \<partial>lborel" rule: ennreal_cases) auto
hoelzl@63886
   537
  then show ?thesis
hoelzl@63886
   538
    using nn_integral_has_integral[OF f(1,2) r] by (simp add: integral_unique)
hoelzl@63886
   539
qed
hoelzl@63886
   540
hoelzl@63886
   541
lemma nn_integral_integrable_on:
hoelzl@63886
   542
  fixes f::"'a::euclidean_space \<Rightarrow> real"
hoelzl@63886
   543
  assumes f: "f \<in> borel_measurable borel" "\<And>x. 0 \<le> f x" "(\<integral>\<^sup>+x. f x \<partial>lborel) < \<infinity>"
hoelzl@63886
   544
  shows "f integrable_on UNIV"
hoelzl@63886
   545
proof -
hoelzl@63886
   546
  from f(3) obtain r where r: "(\<integral>\<^sup>+x. f x \<partial>lborel) = ennreal r" "0 \<le> r"
hoelzl@63886
   547
    by (cases "\<integral>\<^sup>+x. f x \<partial>lborel" rule: ennreal_cases) auto
hoelzl@63886
   548
  then show ?thesis
hoelzl@63886
   549
    by (intro has_integral_integrable[where i=r] nn_integral_has_integral[where r=r] f)
hoelzl@63886
   550
qed
hoelzl@63886
   551
hoelzl@63886
   552
lemma nn_integral_has_integral_lborel:
hoelzl@63886
   553
  fixes f :: "'a::euclidean_space \<Rightarrow> real"
hoelzl@63886
   554
  assumes f_borel: "f \<in> borel_measurable borel" and nonneg: "\<And>x. 0 \<le> f x"
hoelzl@63886
   555
  assumes I: "(f has_integral I) UNIV"
hoelzl@63886
   556
  shows "integral\<^sup>N lborel f = I"
hoelzl@63886
   557
proof -
hoelzl@63886
   558
  from f_borel have "(\<lambda>x. ennreal (f x)) \<in> borel_measurable lborel" by auto
hoelzl@63886
   559
  from borel_measurable_implies_simple_function_sequence'[OF this] guess F . note F = this
hoelzl@63886
   560
  let ?B = "\<lambda>i::nat. box (- (real i *\<^sub>R One)) (real i *\<^sub>R One) :: 'a set"
hoelzl@63886
   561
hoelzl@63886
   562
  note F(1)[THEN borel_measurable_simple_function, measurable]
hoelzl@63886
   563
hoelzl@63886
   564
  have "0 \<le> I"
hoelzl@63886
   565
    using I by (rule has_integral_nonneg) (simp add: nonneg)
hoelzl@63886
   566
hoelzl@63886
   567
  have F_le_f: "enn2real (F i x) \<le> f x" for i x
hoelzl@63886
   568
    using F(3,4)[where x=x] nonneg SUP_upper[of i UNIV "\<lambda>i. F i x"]
hoelzl@63886
   569
    by (cases "F i x" rule: ennreal_cases) auto
hoelzl@63886
   570
  let ?F = "\<lambda>i x. F i x * indicator (?B i) x"
hoelzl@63886
   571
  have "(\<integral>\<^sup>+ x. ennreal (f x) \<partial>lborel) = (SUP i. integral\<^sup>N lborel (\<lambda>x. ?F i x))"
hoelzl@63886
   572
  proof (subst nn_integral_monotone_convergence_SUP[symmetric])
hoelzl@63886
   573
    { fix x
hoelzl@63886
   574
      obtain j where j: "x \<in> ?B j"
hoelzl@63886
   575
        using UN_box_eq_UNIV by auto
hoelzl@63886
   576
hoelzl@63886
   577
      have "ennreal (f x) = (SUP i. F i x)"
hoelzl@63886
   578
        using F(4)[of x] nonneg[of x] by (simp add: max_def)
hoelzl@63886
   579
      also have "\<dots> = (SUP i. ?F i x)"
hoelzl@63886
   580
      proof (rule SUP_eq)
hoelzl@63886
   581
        fix i show "\<exists>j\<in>UNIV. F i x \<le> ?F j x"
hoelzl@63886
   582
          using j F(2)
hoelzl@63886
   583
          by (intro bexI[of _ "max i j"])
hoelzl@63886
   584
             (auto split: split_max split_indicator simp: incseq_def le_fun_def box_def)
hoelzl@63886
   585
      qed (auto intro!: F split: split_indicator)
hoelzl@63886
   586
      finally have "ennreal (f x) =  (SUP i. ?F i x)" . }
hoelzl@63886
   587
    then show "(\<integral>\<^sup>+ x. ennreal (f x) \<partial>lborel) = (\<integral>\<^sup>+ x. (SUP i. ?F i x) \<partial>lborel)"
hoelzl@63886
   588
      by simp
hoelzl@63886
   589
  qed (insert F, auto simp: incseq_def le_fun_def box_def split: split_indicator)
hoelzl@63886
   590
  also have "\<dots> \<le> ennreal I"
hoelzl@63886
   591
  proof (rule SUP_least)
hoelzl@63886
   592
    fix i :: nat
hoelzl@63886
   593
    have finite_F: "(\<integral>\<^sup>+ x. ennreal (enn2real (F i x) * indicator (?B i) x) \<partial>lborel) < \<infinity>"
hoelzl@63886
   594
    proof (rule nn_integral_bound_simple_function)
hoelzl@63886
   595
      have "emeasure lborel {x \<in> space lborel. ennreal (enn2real (F i x) * indicator (?B i) x) \<noteq> 0} \<le>
hoelzl@63886
   596
        emeasure lborel (?B i)"
hoelzl@63886
   597
        by (intro emeasure_mono)  (auto split: split_indicator)
hoelzl@63886
   598
      then show "emeasure lborel {x \<in> space lborel. ennreal (enn2real (F i x) * indicator (?B i) x) \<noteq> 0} < \<infinity>"
hoelzl@63886
   599
        by (auto simp: less_top[symmetric] top_unique)
hoelzl@63886
   600
    qed (auto split: split_indicator
hoelzl@63886
   601
              intro!: F simple_function_compose1[where g="enn2real"] simple_function_ennreal)
hoelzl@63886
   602
hoelzl@63886
   603
    have int_F: "(\<lambda>x. enn2real (F i x) * indicator (?B i) x) integrable_on UNIV"
hoelzl@63886
   604
      using F(4) finite_F
hoelzl@63886
   605
      by (intro nn_integral_integrable_on) (auto split: split_indicator simp: enn2real_nonneg)
hoelzl@63886
   606
hoelzl@63886
   607
    have "(\<integral>\<^sup>+ x. F i x * indicator (?B i) x \<partial>lborel) =
hoelzl@63886
   608
      (\<integral>\<^sup>+ x. ennreal (enn2real (F i x) * indicator (?B i) x) \<partial>lborel)"
hoelzl@63886
   609
      using F(3,4)
hoelzl@63886
   610
      by (intro nn_integral_cong) (auto simp: image_iff eq_commute split: split_indicator)
hoelzl@63886
   611
    also have "\<dots> = ennreal (integral UNIV (\<lambda>x. enn2real (F i x) * indicator (?B i) x))"
hoelzl@63886
   612
      using F
hoelzl@63886
   613
      by (intro nn_integral_lborel_eq_integral[OF _ _ finite_F])
hoelzl@63886
   614
         (auto split: split_indicator intro: enn2real_nonneg)
hoelzl@63886
   615
    also have "\<dots> \<le> ennreal I"
hoelzl@63886
   616
      by (auto intro!: has_integral_le[OF integrable_integral[OF int_F] I] nonneg F_le_f
hoelzl@63886
   617
               simp: \<open>0 \<le> I\<close> split: split_indicator )
hoelzl@63886
   618
    finally show "(\<integral>\<^sup>+ x. F i x * indicator (?B i) x \<partial>lborel) \<le> ennreal I" .
hoelzl@63886
   619
  qed
hoelzl@63886
   620
  finally have "(\<integral>\<^sup>+ x. ennreal (f x) \<partial>lborel) < \<infinity>"
hoelzl@63886
   621
    by (auto simp: less_top[symmetric] top_unique)
hoelzl@63886
   622
  from nn_integral_lborel_eq_integral[OF assms(1,2) this] I show ?thesis
hoelzl@63886
   623
    by (simp add: integral_unique)
hoelzl@63886
   624
qed
hoelzl@63886
   625
hoelzl@63886
   626
lemma has_integral_iff_emeasure_lborel:
hoelzl@63886
   627
  fixes A :: "'a::euclidean_space set"
hoelzl@63886
   628
  assumes A[measurable]: "A \<in> sets borel" and [simp]: "0 \<le> r"
hoelzl@63886
   629
  shows "((\<lambda>x. 1) has_integral r) A \<longleftrightarrow> emeasure lborel A = ennreal r"
hoelzl@63886
   630
proof (cases "emeasure lborel A = \<infinity>")
hoelzl@63886
   631
  case emeasure_A: True
hoelzl@63886
   632
  have "\<not> (\<lambda>x. 1::real) integrable_on A"
hoelzl@63886
   633
  proof
hoelzl@63886
   634
    assume int: "(\<lambda>x. 1::real) integrable_on A"
hoelzl@63886
   635
    then have "(indicator A::'a \<Rightarrow> real) integrable_on UNIV"
hoelzl@63886
   636
      unfolding indicator_def[abs_def] integrable_restrict_univ .
hoelzl@63886
   637
    then obtain r where "((indicator A::'a\<Rightarrow>real) has_integral r) UNIV"
hoelzl@63886
   638
      by auto
hoelzl@63886
   639
    from nn_integral_has_integral_lborel[OF _ _ this] emeasure_A show False
hoelzl@63886
   640
      by (simp add: ennreal_indicator)
hoelzl@63886
   641
  qed
hoelzl@63886
   642
  with emeasure_A show ?thesis
hoelzl@63886
   643
    by auto
hoelzl@63886
   644
next
hoelzl@63886
   645
  case False
hoelzl@63886
   646
  then have "((\<lambda>x. 1) has_integral measure lborel A) A"
hoelzl@63886
   647
    by (simp add: has_integral_measure_lborel less_top)
hoelzl@63886
   648
  with False show ?thesis
hoelzl@63886
   649
    by (auto simp: emeasure_eq_ennreal_measure has_integral_unique)
hoelzl@63886
   650
qed
hoelzl@63886
   651
hoelzl@63941
   652
lemma ennreal_max_0: "ennreal (max 0 x) = ennreal x"
hoelzl@63941
   653
  by (auto simp: max_def ennreal_neg)
hoelzl@63941
   654
hoelzl@63886
   655
lemma has_integral_integral_real:
hoelzl@63886
   656
  fixes f::"'a::euclidean_space \<Rightarrow> real"
hoelzl@63886
   657
  assumes f: "integrable lborel f"
hoelzl@63886
   658
  shows "(f has_integral (integral\<^sup>L lborel f)) UNIV"
hoelzl@63941
   659
proof -
hoelzl@63941
   660
  from integrableE[OF f] obtain r q
hoelzl@63941
   661
    where "0 \<le> r" "0 \<le> q"
hoelzl@63941
   662
      and r: "(\<integral>\<^sup>+ x. ennreal (max 0 (f x)) \<partial>lborel) = ennreal r"
hoelzl@63941
   663
      and q: "(\<integral>\<^sup>+ x. ennreal (max 0 (- f x)) \<partial>lborel) = ennreal q"
hoelzl@63941
   664
      and f: "f \<in> borel_measurable lborel" and eq: "integral\<^sup>L lborel f = r - q"
hoelzl@63941
   665
    unfolding ennreal_max_0 by auto
hoelzl@63941
   666
  then have "((\<lambda>x. max 0 (f x)) has_integral r) UNIV" "((\<lambda>x. max 0 (- f x)) has_integral q) UNIV"
hoelzl@63941
   667
    using nn_integral_has_integral[OF _ _ r] nn_integral_has_integral[OF _ _ q] by auto
hoelzl@63941
   668
  note has_integral_sub[OF this]
hoelzl@63941
   669
  moreover have "(\<lambda>x. max 0 (f x) - max 0 (- f x)) = f"
hoelzl@63941
   670
    by auto
hoelzl@63941
   671
  ultimately show ?thesis
hoelzl@63941
   672
    by (simp add: eq)
hoelzl@63886
   673
qed
hoelzl@63886
   674
hoelzl@63940
   675
lemma has_integral_AE:
hoelzl@63940
   676
  assumes ae: "AE x in lborel. x \<in> \<Omega> \<longrightarrow> f x = g x"
hoelzl@63940
   677
  shows "(f has_integral x) \<Omega> = (g has_integral x) \<Omega>"
hoelzl@63940
   678
proof -
hoelzl@63940
   679
  from ae obtain N
hoelzl@63940
   680
    where N: "N \<in> sets borel" "emeasure lborel N = 0" "{x. \<not> (x \<in> \<Omega> \<longrightarrow> f x = g x)} \<subseteq> N"
hoelzl@63940
   681
    by (auto elim!: AE_E)
hoelzl@63940
   682
  then have not_N: "AE x in lborel. x \<notin> N"
hoelzl@63940
   683
    by (simp add: AE_iff_measurable)
hoelzl@63940
   684
  show ?thesis
hoelzl@63940
   685
  proof (rule has_integral_spike_eq[symmetric])
hoelzl@63940
   686
    show "\<forall>x\<in>\<Omega> - N. f x = g x" using N(3) by auto
hoelzl@63940
   687
    show "negligible N"
hoelzl@63940
   688
      unfolding negligible_def
hoelzl@63940
   689
    proof (intro allI)
hoelzl@63940
   690
      fix a b :: "'a"
hoelzl@63940
   691
      let ?F = "\<lambda>x::'a. if x \<in> cbox a b then indicator N x else 0 :: real"
hoelzl@63940
   692
      have "integrable lborel ?F = integrable lborel (\<lambda>x::'a. 0::real)"
hoelzl@63940
   693
        using not_N N(1) by (intro integrable_cong_AE) auto
hoelzl@63940
   694
      moreover have "(LINT x|lborel. ?F x) = (LINT x::'a|lborel. 0::real)"
hoelzl@63940
   695
        using not_N N(1) by (intro integral_cong_AE) auto
hoelzl@63940
   696
      ultimately have "(?F has_integral 0) UNIV"
hoelzl@63940
   697
        using has_integral_integral_real[of ?F] by simp
hoelzl@63940
   698
      then show "(indicator N has_integral (0::real)) (cbox a b)"
hoelzl@63940
   699
        unfolding has_integral_restrict_univ .
hoelzl@63940
   700
    qed
hoelzl@63940
   701
  qed
hoelzl@63940
   702
qed
hoelzl@63940
   703
hoelzl@63940
   704
lemma nn_integral_has_integral_lebesgue:
hoelzl@63940
   705
  fixes f :: "'a::euclidean_space \<Rightarrow> real"
hoelzl@63940
   706
  assumes nonneg: "\<And>x. 0 \<le> f x" and I: "(f has_integral I) \<Omega>"
hoelzl@63940
   707
  shows "integral\<^sup>N lborel (\<lambda>x. indicator \<Omega> x * f x) = I"
hoelzl@63940
   708
proof -
hoelzl@63940
   709
  from I have "(\<lambda>x. indicator \<Omega> x *\<^sub>R f x) \<in> lebesgue \<rightarrow>\<^sub>M borel"
hoelzl@63940
   710
    by (rule has_integral_implies_lebesgue_measurable)
hoelzl@63940
   711
  then obtain f' :: "'a \<Rightarrow> real"
hoelzl@63940
   712
    where [measurable]: "f' \<in> borel \<rightarrow>\<^sub>M borel" and eq: "AE x in lborel. indicator \<Omega> x * f x = f' x"
hoelzl@63940
   713
    by (auto dest: completion_ex_borel_measurable_real)
hoelzl@63940
   714
hoelzl@63940
   715
  from I have "((\<lambda>x. abs (indicator \<Omega> x * f x)) has_integral I) UNIV"
hoelzl@63940
   716
    using nonneg by (simp add: indicator_def if_distrib[of "\<lambda>x. x * f y" for y] cong: if_cong)
hoelzl@63940
   717
  also have "((\<lambda>x. abs (indicator \<Omega> x * f x)) has_integral I) UNIV \<longleftrightarrow> ((\<lambda>x. abs (f' x)) has_integral I) UNIV"
hoelzl@63940
   718
    using eq by (intro has_integral_AE) auto
hoelzl@63940
   719
  finally have "integral\<^sup>N lborel (\<lambda>x. abs (f' x)) = I"
hoelzl@63940
   720
    by (rule nn_integral_has_integral_lborel[rotated 2]) auto
hoelzl@63940
   721
  also have "integral\<^sup>N lborel (\<lambda>x. abs (f' x)) = integral\<^sup>N lborel (\<lambda>x. abs (indicator \<Omega> x * f x))"
hoelzl@63940
   722
    using eq by (intro nn_integral_cong_AE) auto
hoelzl@63940
   723
  finally show ?thesis
hoelzl@63940
   724
    using nonneg by auto
hoelzl@63940
   725
qed
hoelzl@63940
   726
hoelzl@63940
   727
lemma has_integral_iff_nn_integral_lebesgue:
hoelzl@63940
   728
  assumes f: "\<And>x. 0 \<le> f x"
hoelzl@63940
   729
  shows "(f has_integral r) UNIV \<longleftrightarrow> (f \<in> lebesgue \<rightarrow>\<^sub>M borel \<and> integral\<^sup>N lebesgue f = r \<and> 0 \<le> r)" (is "?I = ?N")
hoelzl@63940
   730
proof
hoelzl@63940
   731
  assume ?I
hoelzl@63940
   732
  have "0 \<le> r"
hoelzl@63940
   733
    using has_integral_nonneg[OF \<open>?I\<close>] f by auto
hoelzl@63940
   734
  then show ?N
hoelzl@63940
   735
    using nn_integral_has_integral_lebesgue[OF f \<open>?I\<close>]
hoelzl@63940
   736
      has_integral_implies_lebesgue_measurable[OF \<open>?I\<close>]
hoelzl@63940
   737
    by (auto simp: nn_integral_completion)
hoelzl@63940
   738
next
hoelzl@63940
   739
  assume ?N
hoelzl@63940
   740
  then obtain f' where f': "f' \<in> borel \<rightarrow>\<^sub>M borel" "AE x in lborel. f x = f' x"
hoelzl@63940
   741
    by (auto dest: completion_ex_borel_measurable_real)
hoelzl@63940
   742
  moreover have "(\<integral>\<^sup>+ x. ennreal \<bar>f' x\<bar> \<partial>lborel) = (\<integral>\<^sup>+ x. ennreal \<bar>f x\<bar> \<partial>lborel)"
hoelzl@63940
   743
    using f' by (intro nn_integral_cong_AE) auto
hoelzl@63940
   744
  moreover have "((\<lambda>x. \<bar>f' x\<bar>) has_integral r) UNIV \<longleftrightarrow> ((\<lambda>x. \<bar>f x\<bar>) has_integral r) UNIV"
hoelzl@63940
   745
    using f' by (intro has_integral_AE) auto
hoelzl@63940
   746
  moreover note nn_integral_has_integral[of "\<lambda>x. \<bar>f' x\<bar>" r] \<open>?N\<close>
hoelzl@63940
   747
  ultimately show ?I
hoelzl@63940
   748
    using f by (auto simp: nn_integral_completion)
hoelzl@63940
   749
qed
hoelzl@63940
   750
hoelzl@63886
   751
context
hoelzl@63886
   752
  fixes f::"'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
hoelzl@63886
   753
begin
hoelzl@63886
   754
hoelzl@63886
   755
lemma has_integral_integral_lborel:
hoelzl@63886
   756
  assumes f: "integrable lborel f"
hoelzl@63886
   757
  shows "(f has_integral (integral\<^sup>L lborel f)) UNIV"
hoelzl@63886
   758
proof -
hoelzl@63886
   759
  have "((\<lambda>x. \<Sum>b\<in>Basis. (f x \<bullet> b) *\<^sub>R b) has_integral (\<Sum>b\<in>Basis. integral\<^sup>L lborel (\<lambda>x. f x \<bullet> b) *\<^sub>R b)) UNIV"
nipkow@64267
   760
    using f by (intro has_integral_sum finite_Basis ballI has_integral_scaleR_left has_integral_integral_real) auto
hoelzl@63886
   761
  also have eq_f: "(\<lambda>x. \<Sum>b\<in>Basis. (f x \<bullet> b) *\<^sub>R b) = f"
hoelzl@63886
   762
    by (simp add: fun_eq_iff euclidean_representation)
hoelzl@63886
   763
  also have "(\<Sum>b\<in>Basis. integral\<^sup>L lborel (\<lambda>x. f x \<bullet> b) *\<^sub>R b) = integral\<^sup>L lborel f"
hoelzl@63886
   764
    using f by (subst (2) eq_f[symmetric]) simp
hoelzl@63886
   765
  finally show ?thesis .
hoelzl@63886
   766
qed
hoelzl@63886
   767
hoelzl@63886
   768
lemma integrable_on_lborel: "integrable lborel f \<Longrightarrow> f integrable_on UNIV"
hoelzl@63886
   769
  using has_integral_integral_lborel by auto
hoelzl@63886
   770
hoelzl@63886
   771
lemma integral_lborel: "integrable lborel f \<Longrightarrow> integral UNIV f = (\<integral>x. f x \<partial>lborel)"
hoelzl@63886
   772
  using has_integral_integral_lborel by auto
hoelzl@63886
   773
hoelzl@63886
   774
end
hoelzl@63886
   775
hoelzl@63941
   776
context
hoelzl@63941
   777
begin
hoelzl@63941
   778
hoelzl@63941
   779
private lemma has_integral_integral_lebesgue_real:
hoelzl@63941
   780
  fixes f :: "'a::euclidean_space \<Rightarrow> real"
hoelzl@63941
   781
  assumes f: "integrable lebesgue f"
hoelzl@63941
   782
  shows "(f has_integral (integral\<^sup>L lebesgue f)) UNIV"
hoelzl@63941
   783
proof -
hoelzl@63941
   784
  obtain f' where f': "f' \<in> borel \<rightarrow>\<^sub>M borel" "AE x in lborel. f x = f' x"
hoelzl@63941
   785
    using completion_ex_borel_measurable_real[OF borel_measurable_integrable[OF f]] by auto
hoelzl@63941
   786
  moreover have "(\<integral>\<^sup>+ x. ennreal (norm (f x)) \<partial>lborel) = (\<integral>\<^sup>+ x. ennreal (norm (f' x)) \<partial>lborel)"
hoelzl@63941
   787
    using f' by (intro nn_integral_cong_AE) auto
hoelzl@63941
   788
  ultimately have "integrable lborel f'"
hoelzl@63941
   789
    using f by (auto simp: integrable_iff_bounded nn_integral_completion cong: nn_integral_cong_AE)
hoelzl@63941
   790
  note has_integral_integral_real[OF this]
hoelzl@63941
   791
  moreover have "integral\<^sup>L lebesgue f = integral\<^sup>L lebesgue f'"
hoelzl@63941
   792
    using f' f by (intro integral_cong_AE) (auto intro: AE_completion measurable_completion)
hoelzl@63941
   793
  moreover have "integral\<^sup>L lebesgue f' = integral\<^sup>L lborel f'"
hoelzl@63941
   794
    using f' by (simp add: integral_completion)
hoelzl@63941
   795
  moreover have "(f' has_integral integral\<^sup>L lborel f') UNIV \<longleftrightarrow> (f has_integral integral\<^sup>L lborel f') UNIV"
hoelzl@63941
   796
    using f' by (intro has_integral_AE) auto
hoelzl@63941
   797
  ultimately show ?thesis
hoelzl@63941
   798
    by auto
hoelzl@63941
   799
qed
hoelzl@63941
   800
hoelzl@63941
   801
lemma has_integral_integral_lebesgue:
hoelzl@63941
   802
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
hoelzl@63941
   803
  assumes f: "integrable lebesgue f"
hoelzl@63941
   804
  shows "(f has_integral (integral\<^sup>L lebesgue f)) UNIV"
hoelzl@63941
   805
proof -
hoelzl@63941
   806
  have "((\<lambda>x. \<Sum>b\<in>Basis. (f x \<bullet> b) *\<^sub>R b) has_integral (\<Sum>b\<in>Basis. integral\<^sup>L lebesgue (\<lambda>x. f x \<bullet> b) *\<^sub>R b)) UNIV"
nipkow@64267
   807
    using f by (intro has_integral_sum finite_Basis ballI has_integral_scaleR_left has_integral_integral_lebesgue_real) auto
hoelzl@63941
   808
  also have eq_f: "(\<lambda>x. \<Sum>b\<in>Basis. (f x \<bullet> b) *\<^sub>R b) = f"
hoelzl@63941
   809
    by (simp add: fun_eq_iff euclidean_representation)
hoelzl@63941
   810
  also have "(\<Sum>b\<in>Basis. integral\<^sup>L lebesgue (\<lambda>x. f x \<bullet> b) *\<^sub>R b) = integral\<^sup>L lebesgue f"
hoelzl@63941
   811
    using f by (subst (2) eq_f[symmetric]) simp
hoelzl@63941
   812
  finally show ?thesis .
hoelzl@63941
   813
qed
hoelzl@63941
   814
hoelzl@63941
   815
lemma integrable_on_lebesgue:
hoelzl@63941
   816
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
hoelzl@63941
   817
  shows "integrable lebesgue f \<Longrightarrow> f integrable_on UNIV"
hoelzl@63941
   818
  using has_integral_integral_lebesgue by auto
hoelzl@63941
   819
hoelzl@63941
   820
lemma integral_lebesgue:
hoelzl@63941
   821
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
hoelzl@63941
   822
  shows "integrable lebesgue f \<Longrightarrow> integral UNIV f = (\<integral>x. f x \<partial>lebesgue)"
hoelzl@63941
   823
  using has_integral_integral_lebesgue by auto
hoelzl@63941
   824
hoelzl@63941
   825
end
hoelzl@63941
   826
hoelzl@63941
   827
subsection \<open>Absolute integrability (this is the same as Lebesgue integrability)\<close>
hoelzl@63941
   828
hoelzl@63941
   829
translations
hoelzl@63941
   830
"LBINT x. f" == "CONST lebesgue_integral CONST lborel (\<lambda>x. f)"
hoelzl@63941
   831
hoelzl@63941
   832
translations
hoelzl@63941
   833
"LBINT x:A. f" == "CONST set_lebesgue_integral CONST lborel A (\<lambda>x. f)"
hoelzl@63941
   834
hoelzl@63941
   835
lemma set_integral_reflect:
hoelzl@63941
   836
  fixes S and f :: "real \<Rightarrow> 'a :: {banach, second_countable_topology}"
hoelzl@63941
   837
  shows "(LBINT x : S. f x) = (LBINT x : {x. - x \<in> S}. f (- x))"
hoelzl@63941
   838
  by (subst lborel_integral_real_affine[where c="-1" and t=0])
hoelzl@63941
   839
     (auto intro!: Bochner_Integration.integral_cong split: split_indicator)
hoelzl@63941
   840
hoelzl@63941
   841
lemma borel_integrable_atLeastAtMost':
hoelzl@63941
   842
  fixes f :: "real \<Rightarrow> 'a::{banach, second_countable_topology}"
hoelzl@63941
   843
  assumes f: "continuous_on {a..b} f"
hoelzl@63941
   844
  shows "set_integrable lborel {a..b} f" (is "integrable _ ?f")
hoelzl@63941
   845
  by (intro borel_integrable_compact compact_Icc f)
hoelzl@63941
   846
hoelzl@63941
   847
lemma integral_FTC_atLeastAtMost:
hoelzl@63941
   848
  fixes f :: "real \<Rightarrow> 'a :: euclidean_space"
hoelzl@63941
   849
  assumes "a \<le> b"
hoelzl@63941
   850
    and F: "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> (F has_vector_derivative f x) (at x within {a .. b})"
hoelzl@63941
   851
    and f: "continuous_on {a .. b} f"
hoelzl@63941
   852
  shows "integral\<^sup>L lborel (\<lambda>x. indicator {a .. b} x *\<^sub>R f x) = F b - F a"
hoelzl@63941
   853
proof -
hoelzl@63941
   854
  let ?f = "\<lambda>x. indicator {a .. b} x *\<^sub>R f x"
hoelzl@63941
   855
  have "(?f has_integral (\<integral>x. ?f x \<partial>lborel)) UNIV"
hoelzl@63941
   856
    using borel_integrable_atLeastAtMost'[OF f] by (rule has_integral_integral_lborel)
hoelzl@63941
   857
  moreover
hoelzl@63941
   858
  have "(f has_integral F b - F a) {a .. b}"
hoelzl@63941
   859
    by (intro fundamental_theorem_of_calculus ballI assms) auto
hoelzl@63941
   860
  then have "(?f has_integral F b - F a) {a .. b}"
hoelzl@63941
   861
    by (subst has_integral_cong[where g=f]) auto
hoelzl@63941
   862
  then have "(?f has_integral F b - F a) UNIV"
hoelzl@63941
   863
    by (intro has_integral_on_superset[where t=UNIV and s="{a..b}"]) auto
hoelzl@63941
   864
  ultimately show "integral\<^sup>L lborel ?f = F b - F a"
hoelzl@63941
   865
    by (rule has_integral_unique)
hoelzl@63941
   866
qed
hoelzl@63941
   867
hoelzl@63941
   868
lemma set_borel_integral_eq_integral:
hoelzl@63941
   869
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
hoelzl@63941
   870
  assumes "set_integrable lborel S f"
hoelzl@63941
   871
  shows "f integrable_on S" "LINT x : S | lborel. f x = integral S f"
hoelzl@63941
   872
proof -
hoelzl@63941
   873
  let ?f = "\<lambda>x. indicator S x *\<^sub>R f x"
hoelzl@63941
   874
  have "(?f has_integral LINT x : S | lborel. f x) UNIV"
hoelzl@63941
   875
    by (rule has_integral_integral_lborel) fact
hoelzl@63941
   876
  hence 1: "(f has_integral (set_lebesgue_integral lborel S f)) S"
hoelzl@63941
   877
    apply (subst has_integral_restrict_univ [symmetric])
hoelzl@63941
   878
    apply (rule has_integral_eq)
hoelzl@63941
   879
    by auto
hoelzl@63941
   880
  thus "f integrable_on S"
hoelzl@63941
   881
    by (auto simp add: integrable_on_def)
hoelzl@63941
   882
  with 1 have "(f has_integral (integral S f)) S"
hoelzl@63941
   883
    by (intro integrable_integral, auto simp add: integrable_on_def)
hoelzl@63941
   884
  thus "LINT x : S | lborel. f x = integral S f"
hoelzl@63941
   885
    by (intro has_integral_unique [OF 1])
hoelzl@63941
   886
qed
hoelzl@63941
   887
hoelzl@63941
   888
lemma has_integral_set_lebesgue:
hoelzl@63941
   889
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
hoelzl@63941
   890
  assumes f: "set_integrable lebesgue S f"
hoelzl@63941
   891
  shows "(f has_integral (LINT x:S|lebesgue. f x)) S"
hoelzl@63941
   892
  using has_integral_integral_lebesgue[OF f]
hoelzl@63941
   893
  by (simp_all add: indicator_def if_distrib[of "\<lambda>x. x *\<^sub>R f _"] has_integral_restrict_univ cong: if_cong)
hoelzl@63941
   894
hoelzl@63941
   895
lemma set_lebesgue_integral_eq_integral:
hoelzl@63941
   896
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
hoelzl@63941
   897
  assumes f: "set_integrable lebesgue S f"
hoelzl@63941
   898
  shows "f integrable_on S" "LINT x:S | lebesgue. f x = integral S f"
hoelzl@63941
   899
  using has_integral_set_lebesgue[OF f] by (auto simp: integral_unique integrable_on_def)
hoelzl@63941
   900
hoelzl@63958
   901
lemma lmeasurable_iff_has_integral:
hoelzl@63958
   902
  "S \<in> lmeasurable \<longleftrightarrow> ((indicator S) has_integral measure lebesgue S) UNIV"
hoelzl@63958
   903
  by (subst has_integral_iff_nn_integral_lebesgue)
hoelzl@63958
   904
     (auto simp: ennreal_indicator emeasure_eq_measure2 borel_measurable_indicator_iff intro!: fmeasurableI)
hoelzl@63958
   905
hoelzl@63941
   906
abbreviation
hoelzl@63941
   907
  absolutely_integrable_on :: "('a::euclidean_space \<Rightarrow> 'b::{banach, second_countable_topology}) \<Rightarrow> 'a set \<Rightarrow> bool"
hoelzl@63941
   908
  (infixr "absolutely'_integrable'_on" 46)
hoelzl@63941
   909
  where "f absolutely_integrable_on s \<equiv> set_integrable lebesgue s f"
hoelzl@63941
   910
hoelzl@63941
   911
lemma absolutely_integrable_on_def:
hoelzl@63941
   912
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
hoelzl@63941
   913
  shows "f absolutely_integrable_on s \<longleftrightarrow> f integrable_on s \<and> (\<lambda>x. norm (f x)) integrable_on s"
hoelzl@63941
   914
proof safe
hoelzl@63941
   915
  assume f: "f absolutely_integrable_on s"
hoelzl@63941
   916
  then have nf: "integrable lebesgue (\<lambda>x. norm (indicator s x *\<^sub>R f x))"
hoelzl@63941
   917
    by (intro integrable_norm)
hoelzl@63941
   918
  note integrable_on_lebesgue[OF f] integrable_on_lebesgue[OF nf]
hoelzl@63941
   919
  moreover have
hoelzl@63941
   920
    "(\<lambda>x. indicator s x *\<^sub>R f x) = (\<lambda>x. if x \<in> s then f x else 0)"
hoelzl@63941
   921
    "(\<lambda>x. norm (indicator s x *\<^sub>R f x)) = (\<lambda>x. if x \<in> s then norm (f x) else 0)"
hoelzl@63941
   922
    by auto
hoelzl@63941
   923
  ultimately show "f integrable_on s" "(\<lambda>x. norm (f x)) integrable_on s"
hoelzl@63941
   924
    by (simp_all add: integrable_restrict_univ)
hoelzl@63941
   925
next
hoelzl@63941
   926
  assume f: "f integrable_on s" and nf: "(\<lambda>x. norm (f x)) integrable_on s"
hoelzl@63941
   927
  show "f absolutely_integrable_on s"
hoelzl@63941
   928
  proof (rule integrableI_bounded)
hoelzl@63941
   929
    show "(\<lambda>x. indicator s x *\<^sub>R f x) \<in> borel_measurable lebesgue"
hoelzl@63941
   930
      using f has_integral_implies_lebesgue_measurable[of f _ s] by (auto simp: integrable_on_def)
hoelzl@63941
   931
    show "(\<integral>\<^sup>+ x. ennreal (norm (indicator s x *\<^sub>R f x)) \<partial>lebesgue) < \<infinity>"
hoelzl@63941
   932
      using nf nn_integral_has_integral_lebesgue[of "\<lambda>x. norm (f x)" _ s]
hoelzl@63941
   933
      by (auto simp: integrable_on_def nn_integral_completion)
hoelzl@63941
   934
  qed
hoelzl@63941
   935
qed
hoelzl@63941
   936
hoelzl@63958
   937
lemma absolutely_integrable_on_iff_nonneg:
hoelzl@63958
   938
  fixes f :: "'a :: euclidean_space \<Rightarrow> real"
hoelzl@63958
   939
  assumes "\<And>x. 0 \<le> f x" shows "f absolutely_integrable_on s \<longleftrightarrow> f integrable_on s"
hoelzl@63958
   940
proof -
hoelzl@63958
   941
  from assms have "(\<lambda>x. \<bar>f x\<bar>) = f"
hoelzl@63958
   942
    by (intro ext) auto
hoelzl@63958
   943
  then show ?thesis
hoelzl@63958
   944
    unfolding absolutely_integrable_on_def by simp
hoelzl@63958
   945
qed
hoelzl@63958
   946
hoelzl@63941
   947
lemma absolutely_integrable_onI:
hoelzl@63941
   948
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
hoelzl@63941
   949
  shows "f integrable_on s \<Longrightarrow> (\<lambda>x. norm (f x)) integrable_on s \<Longrightarrow> f absolutely_integrable_on s"
hoelzl@63941
   950
  unfolding absolutely_integrable_on_def by auto
hoelzl@63941
   951
hoelzl@63958
   952
lemma lmeasurable_iff_integrable_on: "S \<in> lmeasurable \<longleftrightarrow> (\<lambda>x. 1::real) integrable_on S"
hoelzl@63958
   953
  by (subst absolutely_integrable_on_iff_nonneg[symmetric])
hoelzl@63958
   954
     (simp_all add: lmeasurable_iff_integrable)
hoelzl@63958
   955
hoelzl@63958
   956
lemma lmeasure_integral_UNIV: "S \<in> lmeasurable \<Longrightarrow> measure lebesgue S = integral UNIV (indicator S)"
hoelzl@63958
   957
  by (simp add: lmeasurable_iff_has_integral integral_unique)
hoelzl@63958
   958
hoelzl@63958
   959
lemma lmeasure_integral: "S \<in> lmeasurable \<Longrightarrow> measure lebesgue S = integral S (\<lambda>x. 1::real)"
hoelzl@63958
   960
  by (auto simp add: lmeasure_integral_UNIV indicator_def[abs_def] lmeasurable_iff_integrable_on)
hoelzl@63958
   961
hoelzl@63959
   962
lemma
hoelzl@63959
   963
  assumes \<D>: "\<D> division_of S"
hoelzl@63959
   964
  shows lmeasurable_division: "S \<in> lmeasurable" (is ?l)
hoelzl@63968
   965
    and content_division: "(\<Sum>k\<in>\<D>. measure lebesgue k) = measure lebesgue S" (is ?m)
hoelzl@63959
   966
proof -
hoelzl@63959
   967
  { fix d1 d2 assume *: "d1 \<in> \<D>" "d2 \<in> \<D>" "d1 \<noteq> d2"
hoelzl@63959
   968
    then obtain a b c d where "d1 = cbox a b" "d2 = cbox c d"
hoelzl@63959
   969
      using division_ofD(4)[OF \<D>] by blast
hoelzl@63959
   970
    with division_ofD(5)[OF \<D> *]
hoelzl@63959
   971
    have "d1 \<in> sets lborel" "d2 \<in> sets lborel" "d1 \<inter> d2 \<subseteq> (cbox a b - box a b) \<union> (cbox c d - box c d)"
hoelzl@63959
   972
      by auto
hoelzl@63959
   973
    moreover have "(cbox a b - box a b) \<union> (cbox c d - box c d) \<in> null_sets lborel"
hoelzl@63959
   974
      by (intro null_sets.Un null_sets_cbox_Diff_box)
hoelzl@63959
   975
    ultimately have "d1 \<inter> d2 \<in> null_sets lborel"
hoelzl@63959
   976
      by (blast intro: null_sets_subset) }
hoelzl@63959
   977
  then show ?l ?m
hoelzl@63959
   978
    unfolding division_ofD(6)[OF \<D>, symmetric]
hoelzl@63959
   979
    using division_ofD(1,4)[OF \<D>]
hoelzl@63959
   980
    by (auto intro!: measure_Union_AE[symmetric] simp: completion.AE_iff_null_sets Int_def[symmetric] pairwise_def null_sets_def)
hoelzl@63959
   981
qed
hoelzl@63959
   982
hoelzl@63958
   983
text \<open>This should be an abbreviation for negligible.\<close>
hoelzl@63958
   984
lemma negligible_iff_null_sets: "negligible S \<longleftrightarrow> S \<in> null_sets lebesgue"
hoelzl@63958
   985
proof
hoelzl@63958
   986
  assume "negligible S"
hoelzl@63958
   987
  then have "(indicator S has_integral (0::real)) UNIV"
hoelzl@63958
   988
    by (auto simp: negligible)
hoelzl@63958
   989
  then show "S \<in> null_sets lebesgue"
hoelzl@63958
   990
    by (subst (asm) has_integral_iff_nn_integral_lebesgue)
hoelzl@63958
   991
        (auto simp: borel_measurable_indicator_iff nn_integral_0_iff_AE AE_iff_null_sets indicator_eq_0_iff)
hoelzl@63958
   992
next
hoelzl@63958
   993
  assume S: "S \<in> null_sets lebesgue"
hoelzl@63958
   994
  show "negligible S"
hoelzl@63958
   995
    unfolding negligible_def
hoelzl@63958
   996
  proof (safe intro!: has_integral_iff_nn_integral_lebesgue[THEN iffD2]
hoelzl@63958
   997
                      has_integral_restrict_univ[where s="cbox _ _", THEN iffD1])
hoelzl@63958
   998
    fix a b
hoelzl@63958
   999
    show "(\<lambda>x. if x \<in> cbox a b then indicator S x else 0) \<in> lebesgue \<rightarrow>\<^sub>M borel"
hoelzl@63958
  1000
      using S by (auto intro!: measurable_If)
hoelzl@63958
  1001
    then show "(\<integral>\<^sup>+ x. ennreal (if x \<in> cbox a b then indicator S x else 0) \<partial>lebesgue) = ennreal 0"
hoelzl@63958
  1002
      using S[THEN AE_not_in] by (auto intro!: nn_integral_0_iff_AE[THEN iffD2])
hoelzl@63958
  1003
  qed auto
hoelzl@63958
  1004
qed
hoelzl@63958
  1005
hoelzl@63959
  1006
lemma starlike_negligible:
hoelzl@63959
  1007
  assumes "closed S"
hoelzl@63959
  1008
      and eq1: "\<And>c x. \<lbrakk>(a + c *\<^sub>R x) \<in> S; 0 \<le> c; a + x \<in> S\<rbrakk> \<Longrightarrow> c = 1"
hoelzl@63959
  1009
    shows "negligible S"
hoelzl@63959
  1010
proof -
hoelzl@63959
  1011
  have "negligible (op + (-a) ` S)"
hoelzl@63959
  1012
  proof (subst negligible_on_intervals, intro allI)
hoelzl@63959
  1013
    fix u v
hoelzl@63959
  1014
    show "negligible (op + (- a) ` S \<inter> cbox u v)"
hoelzl@63959
  1015
      unfolding negligible_iff_null_sets
hoelzl@63959
  1016
      apply (rule starlike_negligible_compact)
hoelzl@63959
  1017
       apply (simp add: assms closed_translation closed_Int_compact, clarify)
hoelzl@63959
  1018
      by (metis eq1 minus_add_cancel)
hoelzl@63959
  1019
  qed
hoelzl@63959
  1020
  then show ?thesis
hoelzl@63959
  1021
    by (rule negligible_translation_rev)
hoelzl@63959
  1022
qed
hoelzl@63959
  1023
hoelzl@63959
  1024
lemma starlike_negligible_strong:
hoelzl@63959
  1025
  assumes "closed S"
hoelzl@63959
  1026
      and star: "\<And>c x. \<lbrakk>0 \<le> c; c < 1; a+x \<in> S\<rbrakk> \<Longrightarrow> a + c *\<^sub>R x \<notin> S"
hoelzl@63959
  1027
    shows "negligible S"
hoelzl@63959
  1028
proof -
hoelzl@63959
  1029
  show ?thesis
hoelzl@63959
  1030
  proof (rule starlike_negligible [OF \<open>closed S\<close>, of a])
hoelzl@63959
  1031
    fix c x
hoelzl@63959
  1032
    assume cx: "a + c *\<^sub>R x \<in> S" "0 \<le> c" "a + x \<in> S"
hoelzl@63959
  1033
    with star have "~ (c < 1)" by auto
hoelzl@63959
  1034
    moreover have "~ (c > 1)"
hoelzl@63959
  1035
      using star [of "1/c" "c *\<^sub>R x"] cx by force
hoelzl@63959
  1036
    ultimately show "c = 1" by arith
hoelzl@63959
  1037
  qed
hoelzl@63959
  1038
qed
hoelzl@63959
  1039
hoelzl@63959
  1040
subsection\<open>Applications\<close>
hoelzl@63959
  1041
hoelzl@63959
  1042
lemma negligible_hyperplane:
hoelzl@63959
  1043
  assumes "a \<noteq> 0 \<or> b \<noteq> 0" shows "negligible {x. a \<bullet> x = b}"
hoelzl@63959
  1044
proof -
hoelzl@63959
  1045
  obtain x where x: "a \<bullet> x \<noteq> b"
hoelzl@63959
  1046
    using assms
hoelzl@63959
  1047
    apply auto
hoelzl@63959
  1048
     apply (metis inner_eq_zero_iff inner_zero_right)
hoelzl@63959
  1049
    using inner_zero_right by fastforce
hoelzl@63959
  1050
  show ?thesis
hoelzl@63959
  1051
    apply (rule starlike_negligible [OF closed_hyperplane, of x])
hoelzl@63959
  1052
    using x apply (auto simp: algebra_simps)
hoelzl@63959
  1053
    done
hoelzl@63959
  1054
qed
hoelzl@63959
  1055
hoelzl@63959
  1056
lemma negligible_lowdim:
hoelzl@63959
  1057
  fixes S :: "'N :: euclidean_space set"
hoelzl@63959
  1058
  assumes "dim S < DIM('N)"
hoelzl@63959
  1059
    shows "negligible S"
hoelzl@63959
  1060
proof -
hoelzl@63959
  1061
  obtain a where "a \<noteq> 0" and a: "span S \<subseteq> {x. a \<bullet> x = 0}"
hoelzl@63959
  1062
    using lowdim_subset_hyperplane [OF assms] by blast
hoelzl@63959
  1063
  have "negligible (span S)"
hoelzl@63959
  1064
    using \<open>a \<noteq> 0\<close> a negligible_hyperplane by (blast intro: negligible_subset)
hoelzl@63959
  1065
  then show ?thesis
hoelzl@63959
  1066
    using span_inc by (blast intro: negligible_subset)
hoelzl@63959
  1067
qed
hoelzl@63959
  1068
hoelzl@63959
  1069
proposition negligible_convex_frontier:
hoelzl@63959
  1070
  fixes S :: "'N :: euclidean_space set"
hoelzl@63959
  1071
  assumes "convex S"
hoelzl@63959
  1072
    shows "negligible(frontier S)"
hoelzl@63959
  1073
proof -
hoelzl@63959
  1074
  have nf: "negligible(frontier S)" if "convex S" "0 \<in> S" for S :: "'N set"
hoelzl@63959
  1075
  proof -
hoelzl@63959
  1076
    obtain B where "B \<subseteq> S" and indB: "independent B"
hoelzl@63959
  1077
               and spanB: "S \<subseteq> span B" and cardB: "card B = dim S"
hoelzl@63959
  1078
      by (metis basis_exists)
hoelzl@63959
  1079
    consider "dim S < DIM('N)" | "dim S = DIM('N)"
hoelzl@63959
  1080
      using dim_subset_UNIV le_eq_less_or_eq by blast
hoelzl@63959
  1081
    then show ?thesis
hoelzl@63959
  1082
    proof cases
hoelzl@63959
  1083
      case 1
hoelzl@63959
  1084
      show ?thesis
hoelzl@63959
  1085
        by (rule negligible_subset [of "closure S"])
hoelzl@63959
  1086
           (simp_all add: Diff_subset frontier_def negligible_lowdim 1)
hoelzl@63959
  1087
    next
hoelzl@63959
  1088
      case 2
hoelzl@63959
  1089
      obtain a where a: "a \<in> interior S"
hoelzl@63959
  1090
        apply (rule interior_simplex_nonempty [OF indB])
hoelzl@63959
  1091
          apply (simp add: indB independent_finite)
hoelzl@63959
  1092
         apply (simp add: cardB 2)
hoelzl@63959
  1093
        apply (metis \<open>B \<subseteq> S\<close> \<open>0 \<in> S\<close> \<open>convex S\<close> insert_absorb insert_subset interior_mono subset_hull)
hoelzl@63959
  1094
        done
hoelzl@63959
  1095
      show ?thesis
hoelzl@63959
  1096
      proof (rule starlike_negligible_strong [where a=a])
hoelzl@63959
  1097
        fix c::real and x
hoelzl@63959
  1098
        have eq: "a + c *\<^sub>R x = (a + x) - (1 - c) *\<^sub>R ((a + x) - a)"
hoelzl@63959
  1099
          by (simp add: algebra_simps)
hoelzl@63959
  1100
        assume "0 \<le> c" "c < 1" "a + x \<in> frontier S"
hoelzl@63959
  1101
        then show "a + c *\<^sub>R x \<notin> frontier S"
hoelzl@63959
  1102
          apply (clarsimp simp: frontier_def)
hoelzl@63959
  1103
          apply (subst eq)
hoelzl@63959
  1104
          apply (rule mem_interior_closure_convex_shrink [OF \<open>convex S\<close> a, of _ "1-c"], auto)
hoelzl@63959
  1105
          done
hoelzl@63959
  1106
      qed auto
hoelzl@63959
  1107
    qed
hoelzl@63959
  1108
  qed
hoelzl@63959
  1109
  show ?thesis
hoelzl@63959
  1110
  proof (cases "S = {}")
hoelzl@63959
  1111
    case True then show ?thesis by auto
hoelzl@63959
  1112
  next
hoelzl@63959
  1113
    case False
hoelzl@63959
  1114
    then obtain a where "a \<in> S" by auto
hoelzl@63959
  1115
    show ?thesis
hoelzl@63959
  1116
      using nf [of "(\<lambda>x. -a + x) ` S"]
hoelzl@63959
  1117
      by (metis \<open>a \<in> S\<close> add.left_inverse assms convex_translation_eq frontier_translation
hoelzl@63959
  1118
                image_eqI negligible_translation_rev)
hoelzl@63959
  1119
  qed
hoelzl@63959
  1120
qed
hoelzl@63959
  1121
hoelzl@63959
  1122
corollary negligible_sphere: "negligible (sphere a e)"
hoelzl@63959
  1123
  using frontier_cball negligible_convex_frontier convex_cball
hoelzl@63959
  1124
  by (blast intro: negligible_subset)
hoelzl@63959
  1125
hoelzl@63959
  1126
hoelzl@63958
  1127
lemma non_negligible_UNIV [simp]: "\<not> negligible UNIV"
hoelzl@63958
  1128
  unfolding negligible_iff_null_sets by (auto simp: null_sets_def emeasure_lborel_UNIV)
hoelzl@63958
  1129
hoelzl@63958
  1130
lemma negligible_interval:
hoelzl@63958
  1131
  "negligible (cbox a b) \<longleftrightarrow> box a b = {}" "negligible (box a b) \<longleftrightarrow> box a b = {}"
nipkow@64272
  1132
   by (auto simp: negligible_iff_null_sets null_sets_def prod_nonneg inner_diff_left box_eq_empty
hoelzl@63958
  1133
                  not_le emeasure_lborel_cbox_eq emeasure_lborel_box_eq
hoelzl@63958
  1134
            intro: eq_refl antisym less_imp_le)
hoelzl@63958
  1135
hoelzl@63968
  1136
subsection \<open>Negligibility of a Lipschitz image of a negligible set\<close>
hoelzl@63968
  1137
hoelzl@63968
  1138
lemma measure_eq_0_null_sets: "S \<in> null_sets M \<Longrightarrow> measure M S = 0"
hoelzl@63968
  1139
  by (auto simp: measure_def null_sets_def)
hoelzl@63968
  1140
hoelzl@63968
  1141
text\<open>The bound will be eliminated by a sort of onion argument\<close>
hoelzl@63968
  1142
lemma locally_Lipschitz_negl_bounded:
hoelzl@63968
  1143
  fixes f :: "'M::euclidean_space \<Rightarrow> 'N::euclidean_space"
hoelzl@63968
  1144
  assumes MleN: "DIM('M) \<le> DIM('N)" "0 < B" "bounded S" "negligible S"
hoelzl@63968
  1145
      and lips: "\<And>x. x \<in> S
hoelzl@63968
  1146
                      \<Longrightarrow> \<exists>T. open T \<and> x \<in> T \<and>
hoelzl@63968
  1147
                              (\<forall>y \<in> S \<inter> T. norm(f y - f x) \<le> B * norm(y - x))"
hoelzl@63968
  1148
  shows "negligible (f ` S)"
hoelzl@63968
  1149
  unfolding negligible_iff_null_sets
hoelzl@63968
  1150
proof (clarsimp simp: completion.null_sets_outer)
hoelzl@63968
  1151
  fix e::real
hoelzl@63968
  1152
  assume "0 < e"
hoelzl@63968
  1153
  have "S \<in> lmeasurable"
hoelzl@63968
  1154
    using \<open>negligible S\<close> by (simp add: negligible_iff_null_sets fmeasurableI_null_sets)
hoelzl@63968
  1155
  have e22: "0 < e / 2 / (2 * B * real DIM('M)) ^ DIM('N)"
hoelzl@63968
  1156
    using \<open>0 < e\<close> \<open>0 < B\<close> by (simp add: divide_simps)
hoelzl@63968
  1157
  obtain T
hoelzl@63968
  1158
    where "open T" "S \<subseteq> T" "T \<in> lmeasurable"
hoelzl@63968
  1159
      and "measure lebesgue T \<le> measure lebesgue S + e / 2 / (2 * B * DIM('M)) ^ DIM('N)"
hoelzl@63968
  1160
    by (rule lmeasurable_outer_open [OF \<open>S \<in> lmeasurable\<close> e22])
hoelzl@63968
  1161
  then have T: "measure lebesgue T \<le> e / 2 / (2 * B * DIM('M)) ^ DIM('N)"
hoelzl@63968
  1162
    using \<open>negligible S\<close> by (simp add: negligible_iff_null_sets measure_eq_0_null_sets)
hoelzl@63968
  1163
  have "\<exists>r. 0 < r \<and> r \<le> 1/2 \<and>
hoelzl@63968
  1164
            (x \<in> S \<longrightarrow> (\<forall>y. norm(y - x) < r
hoelzl@63968
  1165
                       \<longrightarrow> y \<in> T \<and> (y \<in> S \<longrightarrow> norm(f y - f x) \<le> B * norm(y - x))))"
hoelzl@63968
  1166
        for x
hoelzl@63968
  1167
  proof (cases "x \<in> S")
hoelzl@63968
  1168
    case True
hoelzl@63968
  1169
    obtain U where "open U" "x \<in> U" and U: "\<And>y. y \<in> S \<inter> U \<Longrightarrow> norm(f y - f x) \<le> B * norm(y - x)"
hoelzl@63968
  1170
      using lips [OF \<open>x \<in> S\<close>] by auto
hoelzl@63968
  1171
    have "x \<in> T \<inter> U"
hoelzl@63968
  1172
      using \<open>S \<subseteq> T\<close> \<open>x \<in> U\<close> \<open>x \<in> S\<close> by auto
hoelzl@63968
  1173
    then obtain \<epsilon> where "0 < \<epsilon>" "ball x \<epsilon> \<subseteq> T \<inter> U"
hoelzl@63968
  1174
      by (metis \<open>open T\<close> \<open>open U\<close> openE open_Int)
hoelzl@63968
  1175
    then show ?thesis
hoelzl@63968
  1176
      apply (rule_tac x="min (1/2) \<epsilon>" in exI)
hoelzl@63968
  1177
      apply (simp del: divide_const_simps)
hoelzl@63968
  1178
      apply (intro allI impI conjI)
hoelzl@63968
  1179
       apply (metis dist_commute dist_norm mem_ball subsetCE)
hoelzl@63968
  1180
      by (metis Int_iff subsetCE U dist_norm mem_ball norm_minus_commute)
hoelzl@63968
  1181
  next
hoelzl@63968
  1182
    case False
hoelzl@63968
  1183
    then show ?thesis
hoelzl@63968
  1184
      by (rule_tac x="1/4" in exI) auto
hoelzl@63968
  1185
  qed
hoelzl@63968
  1186
  then obtain R where R12: "\<And>x. 0 < R x \<and> R x \<le> 1/2"
hoelzl@63968
  1187
                and RT: "\<And>x y. \<lbrakk>x \<in> S; norm(y - x) < R x\<rbrakk> \<Longrightarrow> y \<in> T"
hoelzl@63968
  1188
                and RB: "\<And>x y. \<lbrakk>x \<in> S; y \<in> S; norm(y - x) < R x\<rbrakk> \<Longrightarrow> norm(f y - f x) \<le> B * norm(y - x)"
hoelzl@63968
  1189
    by metis+
hoelzl@63968
  1190
  then have gaugeR: "gauge (\<lambda>x. ball x (R x))"
hoelzl@63968
  1191
    by (simp add: gauge_def)
hoelzl@63968
  1192
  obtain c where c: "S \<subseteq> cbox (-c *\<^sub>R One) (c *\<^sub>R One)" "box (-c *\<^sub>R One:: 'M) (c *\<^sub>R One) \<noteq> {}"
hoelzl@63968
  1193
  proof -
hoelzl@63968
  1194
    obtain B where B: "\<And>x. x \<in> S \<Longrightarrow> norm x \<le> B"
hoelzl@63968
  1195
      using \<open>bounded S\<close> bounded_iff by blast
hoelzl@63968
  1196
    show ?thesis
hoelzl@63968
  1197
      apply (rule_tac c = "abs B + 1" in that)
hoelzl@63968
  1198
      using norm_bound_Basis_le Basis_le_norm
hoelzl@63968
  1199
       apply (fastforce simp: box_eq_empty mem_box dest!: B intro: order_trans)+
hoelzl@63968
  1200
      done
hoelzl@63968
  1201
  qed
hoelzl@63968
  1202
  obtain \<D> where "countable \<D>"
hoelzl@63968
  1203
     and Dsub: "\<Union>\<D> \<subseteq> cbox (-c *\<^sub>R One) (c *\<^sub>R One)"
hoelzl@63968
  1204
     and cbox: "\<And>K. K \<in> \<D> \<Longrightarrow> interior K \<noteq> {} \<and> (\<exists>c d. K = cbox c d)"
hoelzl@63968
  1205
     and pw:   "pairwise (\<lambda>A B. interior A \<inter> interior B = {}) \<D>"
hoelzl@63968
  1206
     and Ksub: "\<And>K. K \<in> \<D> \<Longrightarrow> \<exists>x \<in> S \<inter> K. K \<subseteq> (\<lambda>x. ball x (R x)) x"
hoelzl@63968
  1207
     and exN:  "\<And>u v. cbox u v \<in> \<D> \<Longrightarrow> \<exists>n. \<forall>i \<in> Basis. v \<bullet> i - u \<bullet> i = (2*c) / 2^n"
hoelzl@63968
  1208
     and "S \<subseteq> \<Union>\<D>"
hoelzl@63968
  1209
    using covering_lemma [OF c gaugeR]  by force
hoelzl@63968
  1210
  have "\<exists>u v z. K = cbox u v \<and> box u v \<noteq> {} \<and> z \<in> S \<and> z \<in> cbox u v \<and>
hoelzl@63968
  1211
                cbox u v \<subseteq> ball z (R z)" if "K \<in> \<D>" for K
hoelzl@63968
  1212
  proof -
hoelzl@63968
  1213
    obtain u v where "K = cbox u v"
hoelzl@63968
  1214
      using \<open>K \<in> \<D>\<close> cbox by blast
hoelzl@63968
  1215
    with that show ?thesis
hoelzl@63968
  1216
      apply (rule_tac x=u in exI)
hoelzl@63968
  1217
      apply (rule_tac x=v in exI)
hoelzl@63968
  1218
      apply (metis Int_iff interior_cbox cbox Ksub)
hoelzl@63968
  1219
      done
hoelzl@63968
  1220
  qed
hoelzl@63968
  1221
  then obtain uf vf zf
hoelzl@63968
  1222
    where uvz: "\<And>K. K \<in> \<D> \<Longrightarrow>
hoelzl@63968
  1223
                K = cbox (uf K) (vf K) \<and> box (uf K) (vf K) \<noteq> {} \<and> zf K \<in> S \<and>
hoelzl@63968
  1224
                zf K \<in> cbox (uf K) (vf K) \<and> cbox (uf K) (vf K) \<subseteq> ball (zf K) (R (zf K))"
hoelzl@63968
  1225
    by metis
hoelzl@63968
  1226
  define prj1 where "prj1 \<equiv> \<lambda>x::'M. x \<bullet> (SOME i. i \<in> Basis)"
hoelzl@63968
  1227
  define fbx where "fbx \<equiv> \<lambda>D. cbox (f(zf D) - (B * DIM('M) * (prj1(vf D - uf D))) *\<^sub>R One::'N)
hoelzl@63968
  1228
                                    (f(zf D) + (B * DIM('M) * prj1(vf D - uf D)) *\<^sub>R One)"
hoelzl@63968
  1229
  have vu_pos: "0 < prj1 (vf X - uf X)" if "X \<in> \<D>" for X
hoelzl@63968
  1230
    using uvz [OF that] by (simp add: prj1_def box_ne_empty SOME_Basis inner_diff_left)
hoelzl@63968
  1231
  have prj1_idem: "prj1 (vf X - uf X) = (vf X - uf X) \<bullet> i" if  "X \<in> \<D>" "i \<in> Basis" for X i
hoelzl@63968
  1232
  proof -
hoelzl@63968
  1233
    have "cbox (uf X) (vf X) \<in> \<D>"
hoelzl@63968
  1234
      using uvz \<open>X \<in> \<D>\<close> by auto
hoelzl@63968
  1235
    with exN obtain n where "\<And>i. i \<in> Basis \<Longrightarrow> vf X \<bullet> i - uf X \<bullet> i = (2*c) / 2^n"
hoelzl@63968
  1236
      by blast
hoelzl@63968
  1237
    then show ?thesis
hoelzl@63968
  1238
      by (simp add: \<open>i \<in> Basis\<close> SOME_Basis inner_diff prj1_def)
hoelzl@63968
  1239
  qed
hoelzl@63968
  1240
  have countbl: "countable (fbx ` \<D>)"
hoelzl@63968
  1241
    using \<open>countable \<D>\<close> by blast
hoelzl@63968
  1242
  have "(\<Sum>k\<in>fbx`\<D>'. measure lebesgue k) \<le> e / 2" if "\<D>' \<subseteq> \<D>" "finite \<D>'" for \<D>'
hoelzl@63968
  1243
  proof -
hoelzl@63968
  1244
    have BM_ge0: "0 \<le> B * (DIM('M) * prj1 (vf X - uf X))" if "X \<in> \<D>'" for X
hoelzl@63968
  1245
      using \<open>0 < B\<close> \<open>\<D>' \<subseteq> \<D>\<close> that vu_pos by fastforce
hoelzl@63968
  1246
    have "{} \<notin> \<D>'"
hoelzl@63968
  1247
      using cbox \<open>\<D>' \<subseteq> \<D>\<close> interior_empty by blast
nipkow@64267
  1248
    have "(\<Sum>k\<in>fbx`\<D>'. measure lebesgue k) \<le> sum (measure lebesgue o fbx) \<D>'"
nipkow@64267
  1249
      by (rule sum_image_le [OF \<open>finite \<D>'\<close>]) (force simp: fbx_def)
hoelzl@63968
  1250
    also have "\<dots> \<le> (\<Sum>X\<in>\<D>'. (2 * B * DIM('M)) ^ DIM('N) * measure lebesgue X)"
nipkow@64267
  1251
    proof (rule sum_mono)
hoelzl@63968
  1252
      fix X assume "X \<in> \<D>'"
hoelzl@63968
  1253
      then have "X \<in> \<D>" using \<open>\<D>' \<subseteq> \<D>\<close> by blast
hoelzl@63968
  1254
      then have ufvf: "cbox (uf X) (vf X) = X"
hoelzl@63968
  1255
        using uvz by blast
hoelzl@63968
  1256
      have "prj1 (vf X - uf X) ^ DIM('M) = (\<Prod>i::'M \<in> Basis. prj1 (vf X - uf X))"
nipkow@64272
  1257
        by (rule prod_constant [symmetric])
hoelzl@63968
  1258
      also have "\<dots> = (\<Prod>i\<in>Basis. vf X \<bullet> i - uf X \<bullet> i)"
nipkow@64272
  1259
        using prj1_idem [OF \<open>X \<in> \<D>\<close>] by (auto simp: algebra_simps intro: prod.cong)
hoelzl@63968
  1260
      finally have prj1_eq: "prj1 (vf X - uf X) ^ DIM('M) = (\<Prod>i\<in>Basis. vf X \<bullet> i - uf X \<bullet> i)" .
hoelzl@63968
  1261
      have "uf X \<in> cbox (uf X) (vf X)" "vf X \<in> cbox (uf X) (vf X)"
hoelzl@63968
  1262
        using uvz [OF \<open>X \<in> \<D>\<close>] by (force simp: mem_box)+
hoelzl@63968
  1263
      moreover have "cbox (uf X) (vf X) \<subseteq> ball (zf X) (1/2)"
hoelzl@63968
  1264
        by (meson R12 order_trans subset_ball uvz [OF \<open>X \<in> \<D>\<close>])
hoelzl@63968
  1265
      ultimately have "uf X \<in> ball (zf X) (1/2)"  "vf X \<in> ball (zf X) (1/2)"
hoelzl@63968
  1266
        by auto
hoelzl@63968
  1267
      then have "dist (vf X) (uf X) \<le> 1"
hoelzl@63968
  1268
        unfolding mem_ball
hoelzl@63968
  1269
        by (metis dist_commute dist_triangle_half_l dual_order.order_iff_strict)
hoelzl@63968
  1270
      then have 1: "prj1 (vf X - uf X) \<le> 1"
hoelzl@63968
  1271
        unfolding prj1_def dist_norm using Basis_le_norm SOME_Basis order_trans by fastforce
hoelzl@63968
  1272
      have 0: "0 \<le> prj1 (vf X - uf X)"
hoelzl@63968
  1273
        using \<open>X \<in> \<D>\<close> prj1_def vu_pos by fastforce
hoelzl@63968
  1274
      have "(measure lebesgue \<circ> fbx) X \<le> (2 * B * DIM('M)) ^ DIM('N) * content (cbox (uf X) (vf X))"
nipkow@64272
  1275
        apply (simp add: fbx_def content_cbox_cases algebra_simps BM_ge0 \<open>X \<in> \<D>'\<close> prod_constant)
hoelzl@63968
  1276
        apply (simp add: power_mult_distrib \<open>0 < B\<close> prj1_eq [symmetric])
hoelzl@63968
  1277
        using MleN 0 1 uvz \<open>X \<in> \<D>\<close>
hoelzl@63968
  1278
        apply (fastforce simp add: box_ne_empty power_decreasing)
hoelzl@63968
  1279
        done
hoelzl@63968
  1280
      also have "\<dots> = (2 * B * DIM('M)) ^ DIM('N) * measure lebesgue X"
hoelzl@63968
  1281
        by (subst (3) ufvf[symmetric]) simp
hoelzl@63968
  1282
      finally show "(measure lebesgue \<circ> fbx) X \<le> (2 * B * DIM('M)) ^ DIM('N) * measure lebesgue X" .
hoelzl@63968
  1283
    qed
nipkow@64267
  1284
    also have "\<dots> = (2 * B * DIM('M)) ^ DIM('N) * sum (measure lebesgue) \<D>'"
nipkow@64267
  1285
      by (simp add: sum_distrib_left)
hoelzl@63968
  1286
    also have "\<dots> \<le> e / 2"
hoelzl@63968
  1287
    proof -
hoelzl@63968
  1288
      have div: "\<D>' division_of \<Union>\<D>'"
hoelzl@63968
  1289
        apply (auto simp: \<open>finite \<D>'\<close> \<open>{} \<notin> \<D>'\<close> division_of_def)
hoelzl@63968
  1290
        using cbox that apply blast
hoelzl@63968
  1291
        using pairwise_subset [OF pw \<open>\<D>' \<subseteq> \<D>\<close>] unfolding pairwise_def apply force+
hoelzl@63968
  1292
        done
hoelzl@63968
  1293
      have le_meaT: "measure lebesgue (\<Union>\<D>') \<le> measure lebesgue T"
hoelzl@63968
  1294
      proof (rule measure_mono_fmeasurable [OF _ _ \<open>T : lmeasurable\<close>])
hoelzl@63968
  1295
        show "(\<Union>\<D>') \<in> sets lebesgue"
hoelzl@63968
  1296
          using div lmeasurable_division by auto
hoelzl@63968
  1297
        have "\<Union>\<D>' \<subseteq> \<Union>\<D>"
hoelzl@63968
  1298
          using \<open>\<D>' \<subseteq> \<D>\<close> by blast
hoelzl@63968
  1299
        also have "... \<subseteq> T"
hoelzl@63968
  1300
        proof (clarify)
hoelzl@63968
  1301
          fix x D
hoelzl@63968
  1302
          assume "x \<in> D" "D \<in> \<D>"
hoelzl@63968
  1303
          show "x \<in> T"
hoelzl@63968
  1304
            using Ksub [OF \<open>D \<in> \<D>\<close>]
hoelzl@63968
  1305
            by (metis \<open>x \<in> D\<close> Int_iff dist_norm mem_ball norm_minus_commute subsetD RT)
hoelzl@63968
  1306
        qed
hoelzl@63968
  1307
        finally show "\<Union>\<D>' \<subseteq> T" .
hoelzl@63968
  1308
      qed
nipkow@64267
  1309
      have "sum (measure lebesgue) \<D>' = sum content \<D>'"
nipkow@64267
  1310
        using  \<open>\<D>' \<subseteq> \<D>\<close> cbox by (force intro: sum.cong)
nipkow@64267
  1311
      then have "(2 * B * DIM('M)) ^ DIM('N) * sum (measure lebesgue) \<D>' =
hoelzl@63968
  1312
                 (2 * B * real DIM('M)) ^ DIM('N) * measure lebesgue (\<Union>\<D>')"
hoelzl@63968
  1313
        using content_division [OF div] by auto
hoelzl@63968
  1314
      also have "\<dots> \<le> (2 * B * real DIM('M)) ^ DIM('N) * measure lebesgue T"
hoelzl@63968
  1315
        apply (rule mult_left_mono [OF le_meaT])
hoelzl@63968
  1316
        using \<open>0 < B\<close>
hoelzl@63968
  1317
        apply (simp add: algebra_simps)
hoelzl@63968
  1318
        done
hoelzl@63968
  1319
      also have "\<dots> \<le> e / 2"
hoelzl@63968
  1320
        using T \<open>0 < B\<close> by (simp add: field_simps)
hoelzl@63968
  1321
      finally show ?thesis .
hoelzl@63968
  1322
    qed
hoelzl@63968
  1323
    finally show ?thesis .
hoelzl@63968
  1324
  qed
nipkow@64267
  1325
  then have e2: "sum (measure lebesgue) \<G> \<le> e / 2" if "\<G> \<subseteq> fbx ` \<D>" "finite \<G>" for \<G>
hoelzl@63968
  1326
    by (metis finite_subset_image that)
hoelzl@63968
  1327
  show "\<exists>W\<in>lmeasurable. f ` S \<subseteq> W \<and> measure lebesgue W < e"
hoelzl@63968
  1328
  proof (intro bexI conjI)
hoelzl@63968
  1329
    have "\<exists>X\<in>\<D>. f y \<in> fbx X" if "y \<in> S" for y
hoelzl@63968
  1330
    proof -
hoelzl@63968
  1331
      obtain X where "y \<in> X" "X \<in> \<D>"
hoelzl@63968
  1332
        using \<open>S \<subseteq> \<Union>\<D>\<close> \<open>y \<in> S\<close> by auto
hoelzl@63968
  1333
      then have y: "y \<in> ball(zf X) (R(zf X))"
hoelzl@63968
  1334
        using uvz by fastforce
hoelzl@63968
  1335
      have conj_le_eq: "z - b \<le> y \<and> y \<le> z + b \<longleftrightarrow> abs(y - z) \<le> b" for z y b::real
hoelzl@63968
  1336
        by auto
hoelzl@63968
  1337
      have yin: "y \<in> cbox (uf X) (vf X)" and zin: "(zf X) \<in> cbox (uf X) (vf X)"
hoelzl@63968
  1338
        using uvz \<open>X \<in> \<D>\<close> \<open>y \<in> X\<close> by auto
hoelzl@63968
  1339
      have "norm (y - zf X) \<le> (\<Sum>i\<in>Basis. \<bar>(y - zf X) \<bullet> i\<bar>)"
hoelzl@63968
  1340
        by (rule norm_le_l1)
hoelzl@63968
  1341
      also have "\<dots> \<le> real DIM('M) * prj1 (vf X - uf X)"
nipkow@64267
  1342
      proof (rule sum_bounded_above)
hoelzl@63968
  1343
        fix j::'M assume j: "j \<in> Basis"
hoelzl@63968
  1344
        show "\<bar>(y - zf X) \<bullet> j\<bar> \<le> prj1 (vf X - uf X)"
hoelzl@63968
  1345
          using yin zin j
hoelzl@63968
  1346
          by (fastforce simp add: mem_box prj1_idem [OF \<open>X \<in> \<D>\<close> j] inner_diff_left)
hoelzl@63968
  1347
      qed
hoelzl@63968
  1348
      finally have nole: "norm (y - zf X) \<le> DIM('M) * prj1 (vf X - uf X)"
hoelzl@63968
  1349
        by simp
hoelzl@63968
  1350
      have fle: "\<bar>f y \<bullet> i - f(zf X) \<bullet> i\<bar> \<le> B * DIM('M) * prj1 (vf X - uf X)" if "i \<in> Basis" for i
hoelzl@63968
  1351
      proof -
hoelzl@63968
  1352
        have "\<bar>f y \<bullet> i - f (zf X) \<bullet> i\<bar> = \<bar>(f y - f (zf X)) \<bullet> i\<bar>"
hoelzl@63968
  1353
          by (simp add: algebra_simps)
hoelzl@63968
  1354
        also have "\<dots> \<le> norm (f y - f (zf X))"
hoelzl@63968
  1355
          by (simp add: Basis_le_norm that)
hoelzl@63968
  1356
        also have "\<dots> \<le> B * norm(y - zf X)"
hoelzl@63968
  1357
          by (metis uvz RB \<open>X \<in> \<D>\<close> dist_commute dist_norm mem_ball \<open>y \<in> S\<close> y)
hoelzl@63968
  1358
        also have "\<dots> \<le> B * real DIM('M) * prj1 (vf X - uf X)"
hoelzl@63968
  1359
          using \<open>0 < B\<close> by (simp add: nole)
hoelzl@63968
  1360
        finally show ?thesis .
hoelzl@63968
  1361
      qed
hoelzl@63968
  1362
      show ?thesis
hoelzl@63968
  1363
        by (rule_tac x=X in bexI)
hoelzl@63968
  1364
           (auto simp: fbx_def prj1_idem mem_box conj_le_eq inner_add inner_diff fle \<open>X \<in> \<D>\<close>)
hoelzl@63968
  1365
    qed
hoelzl@63968
  1366
    then show "f ` S \<subseteq> (\<Union>D\<in>\<D>. fbx D)" by auto
hoelzl@63968
  1367
  next
hoelzl@63968
  1368
    have 1: "\<And>D. D \<in> \<D> \<Longrightarrow> fbx D \<in> lmeasurable"
hoelzl@63968
  1369
      by (auto simp: fbx_def)
hoelzl@63968
  1370
    have 2: "I' \<subseteq> \<D> \<Longrightarrow> finite I' \<Longrightarrow> measure lebesgue (\<Union>D\<in>I'. fbx D) \<le> e/2" for I'
hoelzl@63968
  1371
      by (rule order_trans[OF measure_Union_le e2]) (auto simp: fbx_def)
hoelzl@63968
  1372
    have 3: "0 \<le> e/2"
hoelzl@63968
  1373
      using \<open>0<e\<close> by auto
hoelzl@63968
  1374
    show "(\<Union>D\<in>\<D>. fbx D) \<in> lmeasurable"
hoelzl@63968
  1375
      by (intro fmeasurable_UN_bound[OF \<open>countable \<D>\<close> 1 2 3])
hoelzl@63968
  1376
    have "measure lebesgue (\<Union>D\<in>\<D>. fbx D) \<le> e/2"
hoelzl@63968
  1377
      by (intro measure_UN_bound[OF \<open>countable \<D>\<close> 1 2 3])
hoelzl@63968
  1378
    then show "measure lebesgue (\<Union>D\<in>\<D>. fbx D) < e"
hoelzl@63968
  1379
      using \<open>0 < e\<close> by linarith
hoelzl@63968
  1380
  qed
hoelzl@63968
  1381
qed
hoelzl@63968
  1382
hoelzl@63968
  1383
proposition negligible_locally_Lipschitz_image:
hoelzl@63968
  1384
  fixes f :: "'M::euclidean_space \<Rightarrow> 'N::euclidean_space"
hoelzl@63968
  1385
  assumes MleN: "DIM('M) \<le> DIM('N)" "negligible S"
hoelzl@63968
  1386
      and lips: "\<And>x. x \<in> S
hoelzl@63968
  1387
                      \<Longrightarrow> \<exists>T B. open T \<and> x \<in> T \<and>
hoelzl@63968
  1388
                              (\<forall>y \<in> S \<inter> T. norm(f y - f x) \<le> B * norm(y - x))"
hoelzl@63968
  1389
    shows "negligible (f ` S)"
hoelzl@63968
  1390
proof -
hoelzl@63968
  1391
  let ?S = "\<lambda>n. ({x \<in> S. norm x \<le> n \<and>
hoelzl@63968
  1392
                          (\<exists>T. open T \<and> x \<in> T \<and>
hoelzl@63968
  1393
                               (\<forall>y\<in>S \<inter> T. norm (f y - f x) \<le> (real n + 1) * norm (y - x)))})"
hoelzl@63968
  1394
  have negfn: "f ` ?S n \<in> null_sets lebesgue" for n::nat
hoelzl@63968
  1395
    unfolding negligible_iff_null_sets[symmetric]
hoelzl@63968
  1396
    apply (rule_tac B = "real n + 1" in locally_Lipschitz_negl_bounded)
hoelzl@63968
  1397
    by (auto simp: MleN bounded_iff intro: negligible_subset [OF \<open>negligible S\<close>])
hoelzl@63968
  1398
  have "S = (\<Union>n. ?S n)"
hoelzl@63968
  1399
  proof (intro set_eqI iffI)
hoelzl@63968
  1400
    fix x assume "x \<in> S"
hoelzl@63968
  1401
    with lips obtain T B where T: "open T" "x \<in> T"
hoelzl@63968
  1402
                           and B: "\<And>y. y \<in> S \<inter> T \<Longrightarrow> norm(f y - f x) \<le> B * norm(y - x)"
hoelzl@63968
  1403
      by metis+
hoelzl@63968
  1404
    have no: "norm (f y - f x) \<le> (nat \<lceil>max B (norm x)\<rceil> + 1) * norm (y - x)" if "y \<in> S \<inter> T" for y
hoelzl@63968
  1405
    proof -
hoelzl@63968
  1406
      have "B * norm(y - x) \<le> (nat \<lceil>max B (norm x)\<rceil> + 1) * norm (y - x)"
hoelzl@63968
  1407
        by (meson max.cobounded1 mult_right_mono nat_ceiling_le_eq nat_le_iff_add norm_ge_zero order_trans)
hoelzl@63968
  1408
      then show ?thesis
hoelzl@63968
  1409
        using B order_trans that by blast
hoelzl@63968
  1410
    qed
hoelzl@63968
  1411
    have "x \<in> ?S (nat (ceiling (max B (norm x))))"
hoelzl@63968
  1412
      apply (simp add: \<open>x \<in> S \<close>, rule)
hoelzl@63968
  1413
      using real_nat_ceiling_ge max.bounded_iff apply blast
hoelzl@63968
  1414
      using T no
hoelzl@63968
  1415
      apply (force simp: algebra_simps)
hoelzl@63968
  1416
      done
hoelzl@63968
  1417
    then show "x \<in> (\<Union>n. ?S n)" by force
hoelzl@63968
  1418
  qed auto
hoelzl@63968
  1419
  then show ?thesis
hoelzl@63968
  1420
    by (rule ssubst) (auto simp: image_Union negligible_iff_null_sets intro: negfn)
hoelzl@63968
  1421
qed
hoelzl@63968
  1422
hoelzl@63968
  1423
corollary negligible_differentiable_image_negligible:
hoelzl@63968
  1424
  fixes f :: "'M::euclidean_space \<Rightarrow> 'N::euclidean_space"
hoelzl@63968
  1425
  assumes MleN: "DIM('M) \<le> DIM('N)" "negligible S"
hoelzl@63968
  1426
      and diff_f: "f differentiable_on S"
hoelzl@63968
  1427
    shows "negligible (f ` S)"
hoelzl@63968
  1428
proof -
hoelzl@63968
  1429
  have "\<exists>T B. open T \<and> x \<in> T \<and> (\<forall>y \<in> S \<inter> T. norm(f y - f x) \<le> B * norm(y - x))"
hoelzl@63968
  1430
        if "x \<in> S" for x
hoelzl@63968
  1431
  proof -
hoelzl@63968
  1432
    obtain f' where "linear f'"
hoelzl@63968
  1433
      and f': "\<And>e. e>0 \<Longrightarrow>
hoelzl@63968
  1434
                  \<exists>d>0. \<forall>y\<in>S. norm (y - x) < d \<longrightarrow>
hoelzl@63968
  1435
                              norm (f y - f x - f' (y - x)) \<le> e * norm (y - x)"
hoelzl@63968
  1436
      using diff_f \<open>x \<in> S\<close>
hoelzl@63968
  1437
      by (auto simp: linear_linear differentiable_on_def differentiable_def has_derivative_within_alt)
hoelzl@63968
  1438
    obtain B where "B > 0" and B: "\<forall>x. norm (f' x) \<le> B * norm x"
hoelzl@63968
  1439
      using linear_bounded_pos \<open>linear f'\<close> by blast
hoelzl@63968
  1440
    obtain d where "d>0"
hoelzl@63968
  1441
              and d: "\<And>y. \<lbrakk>y \<in> S; norm (y - x) < d\<rbrakk> \<Longrightarrow>
hoelzl@63968
  1442
                          norm (f y - f x - f' (y - x)) \<le> norm (y - x)"
hoelzl@63968
  1443
      using f' [of 1] by (force simp:)
hoelzl@63968
  1444
    have *: "norm (f y - f x) \<le> (B + 1) * norm (y - x)"
hoelzl@63968
  1445
              if "y \<in> S" "norm (y - x) < d" for y
hoelzl@63968
  1446
    proof -
hoelzl@63968
  1447
      have "norm (f y - f x) -B *  norm (y - x) \<le> norm (f y - f x) - norm (f' (y - x))"
hoelzl@63968
  1448
        by (simp add: B)
hoelzl@63968
  1449
      also have "\<dots> \<le> norm (f y - f x - f' (y - x))"
hoelzl@63968
  1450
        by (rule norm_triangle_ineq2)
hoelzl@63968
  1451
      also have "... \<le> norm (y - x)"
hoelzl@63968
  1452
        by (rule d [OF that])
hoelzl@63968
  1453
      finally show ?thesis
hoelzl@63968
  1454
        by (simp add: algebra_simps)
hoelzl@63968
  1455
    qed
hoelzl@63968
  1456
    show ?thesis
hoelzl@63968
  1457
      apply (rule_tac x="ball x d" in exI)
hoelzl@63968
  1458
      apply (rule_tac x="B+1" in exI)
hoelzl@63968
  1459
      using \<open>d>0\<close>
hoelzl@63968
  1460
      apply (auto simp: dist_norm norm_minus_commute intro!: *)
hoelzl@63968
  1461
      done
hoelzl@63968
  1462
  qed
hoelzl@63968
  1463
  with negligible_locally_Lipschitz_image assms show ?thesis by metis
hoelzl@63968
  1464
qed
hoelzl@63968
  1465
hoelzl@63968
  1466
corollary negligible_differentiable_image_lowdim:
hoelzl@63968
  1467
  fixes f :: "'M::euclidean_space \<Rightarrow> 'N::euclidean_space"
hoelzl@63968
  1468
  assumes MlessN: "DIM('M) < DIM('N)" and diff_f: "f differentiable_on S"
hoelzl@63968
  1469
    shows "negligible (f ` S)"
hoelzl@63968
  1470
proof -
hoelzl@63968
  1471
  have "x \<le> DIM('M) \<Longrightarrow> x \<le> DIM('N)" for x
hoelzl@63968
  1472
    using MlessN by linarith
hoelzl@63968
  1473
  obtain lift :: "'M * real \<Rightarrow> 'N" and drop :: "'N \<Rightarrow> 'M * real" and j :: 'N
hoelzl@63968
  1474
    where "linear lift" "linear drop" and dropl [simp]: "\<And>z. drop (lift z) = z"
hoelzl@63968
  1475
      and "j \<in> Basis" and j: "\<And>x. lift(x,0) \<bullet> j = 0"
hoelzl@63968
  1476
    using lowerdim_embeddings [OF MlessN] by metis
hoelzl@63968
  1477
  have "negligible {x. x\<bullet>j = 0}"
hoelzl@63968
  1478
    by (metis \<open>j \<in> Basis\<close> negligible_standard_hyperplane)
hoelzl@63968
  1479
  then have neg0S: "negligible ((\<lambda>x. lift (x, 0)) ` S)"
hoelzl@63968
  1480
    apply (rule negligible_subset)
hoelzl@63968
  1481
    by (simp add: image_subsetI j)
hoelzl@63968
  1482
  have diff_f': "f \<circ> fst \<circ> drop differentiable_on (\<lambda>x. lift (x, 0)) ` S"
hoelzl@63968
  1483
    using diff_f
hoelzl@63968
  1484
    apply (clarsimp simp add: differentiable_on_def)
hoelzl@63968
  1485
    apply (intro differentiable_chain_within linear_imp_differentiable [OF \<open>linear drop\<close>]
hoelzl@63968
  1486
             linear_imp_differentiable [OF fst_linear])
hoelzl@63968
  1487
    apply (force simp: image_comp o_def)
hoelzl@63968
  1488
    done
hoelzl@63968
  1489
  have "f = (f o fst o drop o (\<lambda>x. lift (x, 0)))"
hoelzl@63968
  1490
    by (simp add: o_def)
hoelzl@63968
  1491
  then show ?thesis
hoelzl@63968
  1492
    apply (rule ssubst)
hoelzl@63968
  1493
    apply (subst image_comp [symmetric])
hoelzl@63968
  1494
    apply (metis negligible_differentiable_image_negligible order_refl diff_f' neg0S)
hoelzl@63968
  1495
    done
hoelzl@63968
  1496
qed
hoelzl@63968
  1497
hoelzl@63941
  1498
lemma set_integral_norm_bound:
hoelzl@63941
  1499
  fixes f :: "_ \<Rightarrow> 'a :: {banach, second_countable_topology}"
hoelzl@63941
  1500
  shows "set_integrable M k f \<Longrightarrow> norm (LINT x:k|M. f x) \<le> LINT x:k|M. norm (f x)"
hoelzl@63941
  1501
  using integral_norm_bound[of M "\<lambda>x. indicator k x *\<^sub>R f x"] by simp
hoelzl@63941
  1502
hoelzl@63941
  1503
lemma set_integral_finite_UN_AE:
hoelzl@63941
  1504
  fixes f :: "_ \<Rightarrow> _ :: {banach, second_countable_topology}"
hoelzl@63941
  1505
  assumes "finite I"
hoelzl@63941
  1506
    and ae: "\<And>i j. i \<in> I \<Longrightarrow> j \<in> I \<Longrightarrow> AE x in M. (x \<in> A i \<and> x \<in> A j) \<longrightarrow> i = j"
hoelzl@63941
  1507
    and [measurable]: "\<And>i. i \<in> I \<Longrightarrow> A i \<in> sets M"
hoelzl@63941
  1508
    and f: "\<And>i. i \<in> I \<Longrightarrow> set_integrable M (A i) f"
hoelzl@63941
  1509
  shows "LINT x:(\<Union>i\<in>I. A i)|M. f x = (\<Sum>i\<in>I. LINT x:A i|M. f x)"
hoelzl@63941
  1510
  using \<open>finite I\<close> order_refl[of I]
hoelzl@63941
  1511
proof (induction I rule: finite_subset_induct')
hoelzl@63941
  1512
  case (insert i I')
hoelzl@63941
  1513
  have "AE x in M. (\<forall>j\<in>I'. x \<in> A i \<longrightarrow> x \<notin> A j)"
hoelzl@63941
  1514
  proof (intro AE_ball_countable[THEN iffD2] ballI)
hoelzl@63941
  1515
    fix j assume "j \<in> I'"
hoelzl@63941
  1516
    with \<open>I' \<subseteq> I\<close> \<open>i \<notin> I'\<close> have "i \<noteq> j" "j \<in> I"
hoelzl@63941
  1517
      by auto
hoelzl@63941
  1518
    then show "AE x in M. x \<in> A i \<longrightarrow> x \<notin> A j"
hoelzl@63941
  1519
      using ae[of i j] \<open>i \<in> I\<close> by auto
hoelzl@63941
  1520
  qed (use \<open>finite I'\<close> in \<open>rule countable_finite\<close>)
hoelzl@63941
  1521
  then have "AE x\<in>A i in M. \<forall>xa\<in>I'. x \<notin> A xa "
hoelzl@63941
  1522
    by auto
hoelzl@63941
  1523
  with insert.hyps insert.IH[symmetric]
hoelzl@63941
  1524
  show ?case
hoelzl@63941
  1525
    by (auto intro!: set_integral_Un_AE sets.finite_UN f set_integrable_UN)
hoelzl@63941
  1526
qed simp
hoelzl@63941
  1527
hoelzl@63941
  1528
lemma set_integrable_norm:
hoelzl@63941
  1529
  fixes f :: "'a \<Rightarrow> 'b::{banach, second_countable_topology}"
hoelzl@63941
  1530
  assumes f: "set_integrable M k f" shows "set_integrable M k (\<lambda>x. norm (f x))"
hoelzl@63941
  1531
  using integrable_norm[OF f] by simp
hoelzl@63941
  1532
hoelzl@63941
  1533
lemma absolutely_integrable_bounded_variation:
hoelzl@63941
  1534
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
hoelzl@63941
  1535
  assumes f: "f absolutely_integrable_on UNIV"
nipkow@64267
  1536
  obtains B where "\<forall>d. d division_of (\<Union>d) \<longrightarrow> sum (\<lambda>k. norm (integral k f)) d \<le> B"
hoelzl@63941
  1537
proof (rule that[of "integral UNIV (\<lambda>x. norm (f x))"]; safe)
hoelzl@63941
  1538
  fix d :: "'a set set" assume d: "d division_of \<Union>d"
hoelzl@63941
  1539
  have *: "k \<in> d \<Longrightarrow> f absolutely_integrable_on k" for k
hoelzl@63941
  1540
    using f[THEN set_integrable_subset, of k] division_ofD(2,4)[OF d, of k] by auto
hoelzl@63941
  1541
  note d' = division_ofD[OF d]
hoelzl@63941
  1542
hoelzl@63941
  1543
  have "(\<Sum>k\<in>d. norm (integral k f)) = (\<Sum>k\<in>d. norm (LINT x:k|lebesgue. f x))"
nipkow@64267
  1544
    by (intro sum.cong refl arg_cong[where f=norm] set_lebesgue_integral_eq_integral(2)[symmetric] *)
hoelzl@63941
  1545
  also have "\<dots> \<le> (\<Sum>k\<in>d. LINT x:k|lebesgue. norm (f x))"
nipkow@64267
  1546
    by (intro sum_mono set_integral_norm_bound *)
hoelzl@63941
  1547
  also have "\<dots> = (\<Sum>k\<in>d. integral k (\<lambda>x. norm (f x)))"
nipkow@64267
  1548
    by (intro sum.cong refl set_lebesgue_integral_eq_integral(2) set_integrable_norm *)
hoelzl@63941
  1549
  also have "\<dots> \<le> integral (\<Union>d) (\<lambda>x. norm (f x))"
hoelzl@63941
  1550
    using integrable_on_subdivision[OF d] assms f unfolding absolutely_integrable_on_def
hoelzl@63941
  1551
    by (subst integral_combine_division_topdown[OF _ d]) auto
hoelzl@63941
  1552
  also have "\<dots> \<le> integral UNIV (\<lambda>x. norm (f x))"
hoelzl@63941
  1553
    using integrable_on_subdivision[OF d] assms unfolding absolutely_integrable_on_def
hoelzl@63941
  1554
    by (intro integral_subset_le) auto
hoelzl@63941
  1555
  finally show "(\<Sum>k\<in>d. norm (integral k f)) \<le> integral UNIV (\<lambda>x. norm (f x))" .
hoelzl@63941
  1556
qed
hoelzl@63941
  1557
hoelzl@63941
  1558
lemma helplemma:
nipkow@64267
  1559
  assumes "sum (\<lambda>x. norm (f x - g x)) s < e"
hoelzl@63941
  1560
    and "finite s"
nipkow@64267
  1561
  shows "\<bar>sum (\<lambda>x. norm(f x)) s - sum (\<lambda>x. norm(g x)) s\<bar> < e"
nipkow@64267
  1562
  unfolding sum_subtractf[symmetric]
nipkow@64267
  1563
  apply (rule le_less_trans[OF sum_abs])
hoelzl@63941
  1564
  apply (rule le_less_trans[OF _ assms(1)])
nipkow@64267
  1565
  apply (rule sum_mono)
hoelzl@63941
  1566
  apply (rule norm_triangle_ineq3)
hoelzl@63941
  1567
  done
hoelzl@63941
  1568
hoelzl@63941
  1569
lemma bounded_variation_absolutely_integrable_interval:
hoelzl@63941
  1570
  fixes f :: "'n::euclidean_space \<Rightarrow> 'm::euclidean_space"
hoelzl@63941
  1571
  assumes f: "f integrable_on cbox a b"
nipkow@64267
  1572
    and *: "\<forall>d. d division_of (cbox a b) \<longrightarrow> sum (\<lambda>k. norm(integral k f)) d \<le> B"
hoelzl@63941
  1573
  shows "f absolutely_integrable_on cbox a b"
hoelzl@63941
  1574
proof -
hoelzl@63941
  1575
  let ?f = "\<lambda>d. \<Sum>k\<in>d. norm (integral k f)" and ?D = "{d. d division_of (cbox a b)}"
hoelzl@63941
  1576
  have D_1: "?D \<noteq> {}"
hoelzl@63941
  1577
    by (rule elementary_interval[of a b]) auto
hoelzl@63941
  1578
  have D_2: "bdd_above (?f`?D)"
hoelzl@63941
  1579
    by (metis * mem_Collect_eq bdd_aboveI2)
hoelzl@63941
  1580
  note D = D_1 D_2
hoelzl@63941
  1581
  let ?S = "SUP x:?D. ?f x"
hoelzl@63941
  1582
  show ?thesis
hoelzl@63941
  1583
    apply (rule absolutely_integrable_onI [OF f has_integral_integrable])
hoelzl@63941
  1584
    apply (subst has_integral[of _ ?S])
hoelzl@63941
  1585
    apply safe
hoelzl@63941
  1586
  proof goal_cases
hoelzl@63941
  1587
    case e: (1 e)
hoelzl@63941
  1588
    then have "?S - e / 2 < ?S" by simp
hoelzl@63941
  1589
    then obtain d where d: "d division_of (cbox a b)" "?S - e / 2 < (\<Sum>k\<in>d. norm (integral k f))"
hoelzl@63941
  1590
      unfolding less_cSUP_iff[OF D] by auto
hoelzl@63941
  1591
    note d' = division_ofD[OF this(1)]
hoelzl@63941
  1592
hoelzl@63941
  1593
    have "\<forall>x. \<exists>e>0. \<forall>i\<in>d. x \<notin> i \<longrightarrow> ball x e \<inter> i = {}"
hoelzl@63941
  1594
    proof
hoelzl@63941
  1595
      fix x
hoelzl@63941
  1596
      have "\<exists>da>0. \<forall>xa\<in>\<Union>{i \<in> d. x \<notin> i}. da \<le> dist x xa"
hoelzl@63941
  1597
        apply (rule separate_point_closed)
hoelzl@63941
  1598
        apply (rule closed_Union)
hoelzl@63941
  1599
        apply (rule finite_subset[OF _ d'(1)])
hoelzl@63941
  1600
        using d'(4)
hoelzl@63941
  1601
        apply auto
hoelzl@63941
  1602
        done
hoelzl@63941
  1603
      then show "\<exists>e>0. \<forall>i\<in>d. x \<notin> i \<longrightarrow> ball x e \<inter> i = {}"
hoelzl@63941
  1604
        by force
hoelzl@63941
  1605
    qed
hoelzl@63941
  1606
    from choice[OF this] guess k .. note k=conjunctD2[OF this[rule_format],rule_format]
hoelzl@63941
  1607
hoelzl@63941
  1608
    have "e/2 > 0"
hoelzl@63941
  1609
      using e by auto
hoelzl@63941
  1610
    from henstock_lemma[OF assms(1) this] guess g . note g=this[rule_format]
hoelzl@63941
  1611
    let ?g = "\<lambda>x. g x \<inter> ball x (k x)"
hoelzl@63941
  1612
    show ?case
hoelzl@63941
  1613
      apply (rule_tac x="?g" in exI)
hoelzl@63941
  1614
      apply safe
hoelzl@63941
  1615
    proof -
hoelzl@63941
  1616
      show "gauge ?g"
hoelzl@63941
  1617
        using g(1) k(1)
hoelzl@63941
  1618
        unfolding gauge_def
hoelzl@63941
  1619
        by auto
hoelzl@63941
  1620
      fix p
hoelzl@63941
  1621
      assume "p tagged_division_of (cbox a b)" and "?g fine p"
hoelzl@63941
  1622
      note p = this(1) conjunctD2[OF this(2)[unfolded fine_inter]]
hoelzl@63941
  1623
      note p' = tagged_division_ofD[OF p(1)]
hoelzl@63941
  1624
      define p' where "p' = {(x,k) | x k. \<exists>i l. x \<in> i \<and> i \<in> d \<and> (x,l) \<in> p \<and> k = i \<inter> l}"
hoelzl@63941
  1625
      have gp': "g fine p'"
hoelzl@63941
  1626
        using p(2)
hoelzl@63941
  1627
        unfolding p'_def fine_def
hoelzl@63941
  1628
        by auto
hoelzl@63941
  1629
      have p'': "p' tagged_division_of (cbox a b)"
hoelzl@63941
  1630
        apply (rule tagged_division_ofI)
hoelzl@63941
  1631
      proof -
hoelzl@63941
  1632
        show "finite p'"
hoelzl@63941
  1633
          apply (rule finite_subset[of _ "(\<lambda>(k,(x,l)). (x,k \<inter> l)) `
hoelzl@63941
  1634
            {(k,xl) | k xl. k \<in> d \<and> xl \<in> p}"])
hoelzl@63941
  1635
          unfolding p'_def
hoelzl@63941
  1636
          defer
hoelzl@63941
  1637
          apply (rule finite_imageI,rule finite_product_dependent[OF d'(1) p'(1)])
hoelzl@63941
  1638
          apply safe
hoelzl@63941
  1639
          unfolding image_iff
hoelzl@63941
  1640
          apply (rule_tac x="(i,x,l)" in bexI)
hoelzl@63941
  1641
          apply auto
hoelzl@63941
  1642
          done
hoelzl@63941
  1643
        fix x k
hoelzl@63941
  1644
        assume "(x, k) \<in> p'"
hoelzl@63941
  1645
        then have "\<exists>i l. x \<in> i \<and> i \<in> d \<and> (x, l) \<in> p \<and> k = i \<inter> l"
hoelzl@63941
  1646
          unfolding p'_def by auto
hoelzl@63941
  1647
        then guess i l by (elim exE) note il=conjunctD4[OF this]
hoelzl@63941
  1648
        show "x \<in> k" and "k \<subseteq> cbox a b"
hoelzl@63941
  1649
          using p'(2-3)[OF il(3)] il by auto
hoelzl@63941
  1650
        show "\<exists>a b. k = cbox a b"
hoelzl@63941
  1651
          unfolding il using p'(4)[OF il(3)] d'(4)[OF il(2)]
hoelzl@63941
  1652
          apply safe
lp15@63945
  1653
          unfolding Int_interval
hoelzl@63941
  1654
          apply auto
hoelzl@63941
  1655
          done
hoelzl@63941
  1656
      next
hoelzl@63941
  1657
        fix x1 k1
hoelzl@63941
  1658
        assume "(x1, k1) \<in> p'"
hoelzl@63941
  1659
        then have "\<exists>i l. x1 \<in> i \<and> i \<in> d \<and> (x1, l) \<in> p \<and> k1 = i \<inter> l"
hoelzl@63941
  1660
          unfolding p'_def by auto
hoelzl@63941
  1661
        then guess i1 l1 by (elim exE) note il1=conjunctD4[OF this]
hoelzl@63941
  1662
        fix x2 k2
hoelzl@63941
  1663
        assume "(x2,k2)\<in>p'"
hoelzl@63941
  1664
        then have "\<exists>i l. x2 \<in> i \<and> i \<in> d \<and> (x2, l) \<in> p \<and> k2 = i \<inter> l"
hoelzl@63941
  1665
          unfolding p'_def by auto
hoelzl@63941
  1666
        then guess i2 l2 by (elim exE) note il2=conjunctD4[OF this]
hoelzl@63941
  1667
        assume "(x1, k1) \<noteq> (x2, k2)"
hoelzl@63941
  1668
        then have "interior i1 \<inter> interior i2 = {} \<or> interior l1 \<inter> interior l2 = {}"
hoelzl@63941
  1669
          using d'(5)[OF il1(2) il2(2)] p'(5)[OF il1(3) il2(3)]
hoelzl@63941
  1670
          unfolding il1 il2
hoelzl@63941
  1671
          by auto
hoelzl@63941
  1672
        then show "interior k1 \<inter> interior k2 = {}"
hoelzl@63941
  1673
          unfolding il1 il2 by auto
hoelzl@63941
  1674
      next
hoelzl@63941
  1675
        have *: "\<forall>(x, X) \<in> p'. X \<subseteq> cbox a b"
hoelzl@63941
  1676
          unfolding p'_def using d' by auto
hoelzl@63941
  1677
        show "\<Union>{k. \<exists>x. (x, k) \<in> p'} = cbox a b"
hoelzl@63941
  1678
          apply rule
hoelzl@63941
  1679
          apply (rule Union_least)
hoelzl@63941
  1680
          unfolding mem_Collect_eq
hoelzl@63941
  1681
          apply (erule exE)
hoelzl@63941
  1682
          apply (drule *[rule_format])
hoelzl@63941
  1683
          apply safe
hoelzl@63941
  1684
        proof -
hoelzl@63941
  1685
          fix y
hoelzl@63941
  1686
          assume y: "y \<in> cbox a b"
hoelzl@63941
  1687
          then have "\<exists>x l. (x, l) \<in> p \<and> y\<in>l"
hoelzl@63941
  1688
            unfolding p'(6)[symmetric] by auto
hoelzl@63941
  1689
          then guess x l by (elim exE) note xl=conjunctD2[OF this]
hoelzl@63941
  1690
          then have "\<exists>k. k \<in> d \<and> y \<in> k"
hoelzl@63941
  1691
            using y unfolding d'(6)[symmetric] by auto
hoelzl@63941
  1692
          then guess i .. note i = conjunctD2[OF this]
hoelzl@63941
  1693
          have "x \<in> i"
hoelzl@63941
  1694
            using fineD[OF p(3) xl(1)]
hoelzl@63941
  1695
            using k(2)[OF i(1), of x]
hoelzl@63941
  1696
            using i(2) xl(2)
hoelzl@63941
  1697
            by auto
hoelzl@63941
  1698
          then show "y \<in> \<Union>{k. \<exists>x. (x, k) \<in> p'}"
hoelzl@63941
  1699
            unfolding p'_def Union_iff
hoelzl@63941
  1700
            apply (rule_tac x="i \<inter> l" in bexI)
hoelzl@63941
  1701
            using i xl
hoelzl@63941
  1702
            apply auto
hoelzl@63941
  1703
            done
hoelzl@63941
  1704
        qed
hoelzl@63941
  1705
      qed
hoelzl@63941
  1706
hoelzl@63941
  1707
      then have "(\<Sum>(x, k)\<in>p'. norm (content k *\<^sub>R f x - integral k f)) < e / 2"
hoelzl@63941
  1708
        apply -
hoelzl@63941
  1709
        apply (rule g(2)[rule_format])
hoelzl@63941
  1710
        unfolding tagged_division_of_def
hoelzl@63941
  1711
        apply safe
hoelzl@63941
  1712
        apply (rule gp')
hoelzl@63941
  1713
        done
hoelzl@63941
  1714
      then have **: "\<bar>(\<Sum>(x,k)\<in>p'. norm (content k *\<^sub>R f x)) - (\<Sum>(x,k)\<in>p'. norm (integral k f))\<bar> < e / 2"
hoelzl@63941
  1715
        unfolding split_def
hoelzl@63941
  1716
        using p''
hoelzl@63941
  1717
        by (force intro!: helplemma)
hoelzl@63941
  1718
hoelzl@63941
  1719
      have p'alt: "p' = {(x,(i \<inter> l)) | x i l. (x,l) \<in> p \<and> i \<in> d \<and> i \<inter> l \<noteq> {}}"
hoelzl@63941
  1720
      proof (safe, goal_cases)
hoelzl@63941
  1721
        case prems: (2 _ _ x i l)
hoelzl@63941
  1722
        have "x \<in> i"
hoelzl@63941
  1723
          using fineD[OF p(3) prems(1)] k(2)[OF prems(2), of x] prems(4-)
hoelzl@63941
  1724
          by auto
hoelzl@63941
  1725
        then have "(x, i \<inter> l) \<in> p'"
hoelzl@63941
  1726
          unfolding p'_def
hoelzl@63941
  1727
          using prems
hoelzl@63941
  1728
          apply safe
hoelzl@63941
  1729
          apply (rule_tac x=x in exI)
hoelzl@63941
  1730
          apply (rule_tac x="i \<inter> l" in exI)
hoelzl@63941
  1731
          apply safe
hoelzl@63941
  1732
          using prems
hoelzl@63941
  1733
          apply auto
hoelzl@63941
  1734
          done
hoelzl@63941
  1735
        then show ?case
hoelzl@63941
  1736
          using prems(3) by auto
hoelzl@63941
  1737
      next
hoelzl@63941
  1738
        fix x k
hoelzl@63941
  1739
        assume "(x, k) \<in> p'"
hoelzl@63941
  1740
        then have "\<exists>i l. x \<in> i \<and> i \<in> d \<and> (x, l) \<in> p \<and> k = i \<inter> l"
hoelzl@63941
  1741
          unfolding p'_def by auto
hoelzl@63941
  1742
        then guess i l by (elim exE) note il=conjunctD4[OF this]
hoelzl@63941
  1743
        then show "\<exists>y i l. (x, k) = (y, i \<inter> l) \<and> (y, l) \<in> p \<and> i \<in> d \<and> i \<inter> l \<noteq> {}"
hoelzl@63941
  1744
          apply (rule_tac x=x in exI)
hoelzl@63941
  1745
          apply (rule_tac x=i in exI)
hoelzl@63941
  1746
          apply (rule_tac x=l in exI)
hoelzl@63941
  1747
          using p'(2)[OF il(3)]
hoelzl@63941
  1748
          apply auto
hoelzl@63941
  1749
          done
hoelzl@63941
  1750
      qed
hoelzl@63941
  1751
      have sum_p': "(\<Sum>(x, k)\<in>p'. norm (integral k f)) = (\<Sum>k\<in>snd ` p'. norm (integral k f))"
nipkow@64267
  1752
        apply (subst sum.over_tagged_division_lemma[OF p'',of "\<lambda>k. norm (integral k f)"])
hoelzl@63941
  1753
        unfolding norm_eq_zero
hoelzl@63957
  1754
         apply (rule integral_null)
hoelzl@63957
  1755
        apply (simp add: content_eq_0_interior)
hoelzl@63941
  1756
        apply rule
hoelzl@63941
  1757
        done
hoelzl@63941
  1758
      note snd_p = division_ofD[OF division_of_tagged_division[OF p(1)]]
hoelzl@63941
  1759
hoelzl@63941
  1760
      have *: "\<And>sni sni' sf sf'. \<bar>sf' - sni'\<bar> < e / 2 \<longrightarrow> ?S - e / 2 < sni \<and> sni' \<le> ?S \<and>
hoelzl@63941
  1761
        sni \<le> sni' \<and> sf' = sf \<longrightarrow> \<bar>sf - ?S\<bar> < e"
hoelzl@63941
  1762
        by arith
hoelzl@63941
  1763
      show "norm ((\<Sum>(x, k)\<in>p. content k *\<^sub>R norm (f x)) - ?S) < e"
hoelzl@63941
  1764
        unfolding real_norm_def
hoelzl@63941
  1765
        apply (rule *[rule_format,OF **])
hoelzl@63941
  1766
        apply safe
hoelzl@63941
  1767
        apply(rule d(2))
hoelzl@63941
  1768
      proof goal_cases
hoelzl@63941
  1769
        case 1
hoelzl@63941
  1770
        show ?case
hoelzl@63941
  1771
          by (auto simp: sum_p' division_of_tagged_division[OF p''] D intro!: cSUP_upper)
hoelzl@63941
  1772
      next
hoelzl@63941
  1773
        case 2
hoelzl@63941
  1774
        have *: "{k \<inter> l | k l. k \<in> d \<and> l \<in> snd ` p} =
hoelzl@63941
  1775
          (\<lambda>(k,l). k \<inter> l) ` {(k,l)|k l. k \<in> d \<and> l \<in> snd ` p}"
hoelzl@63941
  1776
          by auto
hoelzl@63941
  1777
        have "(\<Sum>k\<in>d. norm (integral k f)) \<le> (\<Sum>i\<in>d. \<Sum>l\<in>snd ` p. norm (integral (i \<inter> l) f))"
nipkow@64267
  1778
        proof (rule sum_mono, goal_cases)
hoelzl@63941
  1779
          case k: (1 k)
hoelzl@63941
  1780
          from d'(4)[OF this] guess u v by (elim exE) note uv=this
hoelzl@63941
  1781
          define d' where "d' = {cbox u v \<inter> l |l. l \<in> snd ` p \<and>  cbox u v \<inter> l \<noteq> {}}"
hoelzl@63941
  1782
          note uvab = d'(2)[OF k[unfolded uv]]
hoelzl@63941
  1783
          have "d' division_of cbox u v"
hoelzl@63941
  1784
            apply (subst d'_def)
hoelzl@63941
  1785
            apply (rule division_inter_1)
hoelzl@63941
  1786
            apply (rule division_of_tagged_division[OF p(1)])
hoelzl@63941
  1787
            apply (rule uvab)
hoelzl@63941
  1788
            done
nipkow@64267
  1789
          then have "norm (integral k f) \<le> sum (\<lambda>k. norm (integral k f)) d'"
hoelzl@63941
  1790
            unfolding uv
hoelzl@63941
  1791
            apply (subst integral_combine_division_topdown[of _ _ d'])
hoelzl@63941
  1792
            apply (rule integrable_on_subcbox[OF assms(1) uvab])
hoelzl@63941
  1793
            apply assumption
nipkow@64267
  1794
            apply (rule sum_norm_le)
hoelzl@63941
  1795
            apply auto
hoelzl@63941
  1796
            done
hoelzl@63941
  1797
          also have "\<dots> = (\<Sum>k\<in>{k \<inter> l |l. l \<in> snd ` p}. norm (integral k f))"
nipkow@64267
  1798
            apply (rule sum.mono_neutral_left)
hoelzl@63941
  1799
            apply (subst Setcompr_eq_image)
hoelzl@63941
  1800
            apply (rule finite_imageI)+
hoelzl@63941
  1801
            apply fact
hoelzl@63941
  1802
            unfolding d'_def uv
hoelzl@63941
  1803
            apply blast
hoelzl@63941
  1804
          proof (rule, goal_cases)
hoelzl@63941
  1805
            case prems: (1 i)
hoelzl@63941
  1806
            then have "i \<in> {cbox u v \<inter> l |l. l \<in> snd ` p}"
hoelzl@63941
  1807
              by auto
hoelzl@63941
  1808
            from this[unfolded mem_Collect_eq] guess l .. note l=this
hoelzl@63941
  1809
            then have "cbox u v \<inter> l = {}"
hoelzl@63941
  1810
              using prems by auto
hoelzl@63941
  1811
            then show ?case
hoelzl@63941
  1812
              using l by auto
hoelzl@63941
  1813
          qed
hoelzl@63941
  1814
          also have "\<dots> = (\<Sum>l\<in>snd ` p. norm (integral (k \<inter> l) f))"
hoelzl@63941
  1815
            unfolding Setcompr_eq_image
nipkow@64267
  1816
            apply (rule sum.reindex_nontrivial [unfolded o_def])
hoelzl@63941
  1817
            apply (rule finite_imageI)
hoelzl@63941
  1818
            apply (rule p')
hoelzl@63941
  1819
          proof goal_cases
hoelzl@63941
  1820
            case prems: (1 l y)
hoelzl@63941
  1821
            have "interior (k \<inter> l) \<subseteq> interior (l \<inter> y)"
hoelzl@63941
  1822
              apply (subst(2) interior_Int)
hoelzl@63941
  1823
              apply (rule Int_greatest)
hoelzl@63941
  1824
              defer
hoelzl@63941
  1825
              apply (subst prems(4))
hoelzl@63941
  1826
              apply auto
hoelzl@63941
  1827
              done
hoelzl@63941
  1828
            then have *: "interior (k \<inter> l) = {}"
hoelzl@63941
  1829
              using snd_p(5)[OF prems(1-3)] by auto
hoelzl@63941
  1830
            from d'(4)[OF k] snd_p(4)[OF prems(1)] guess u1 v1 u2 v2 by (elim exE) note uv=this
hoelzl@63941
  1831
            show ?case
hoelzl@63941
  1832
              using *
lp15@63945
  1833
              unfolding uv Int_interval content_eq_0_interior[symmetric]
hoelzl@63941
  1834
              by auto
hoelzl@63941
  1835
          qed
hoelzl@63941
  1836
          finally show ?case .
hoelzl@63941
  1837
        qed
hoelzl@63941
  1838
        also have "\<dots> = (\<Sum>(i,l)\<in>{(i, l) |i l. i \<in> d \<and> l \<in> snd ` p}. norm (integral (i\<inter>l) f))"
hoelzl@63941
  1839
          apply (subst sum_sum_product[symmetric])
hoelzl@63941
  1840
          apply fact
hoelzl@63941
  1841
          using p'(1)
hoelzl@63941
  1842
          apply auto
hoelzl@63941
  1843
          done
hoelzl@63941
  1844
        also have "\<dots> = (\<Sum>x\<in>{(i, l) |i l. i \<in> d \<and> l \<in> snd ` p}. norm (integral (case_prod op \<inter> x) f))"
hoelzl@63941
  1845
          unfolding split_def ..
hoelzl@63941
  1846
        also have "\<dots> = (\<Sum>k\<in>{i \<inter> l |i l. i \<in> d \<and> l \<in> snd ` p}. norm (integral k f))"
hoelzl@63941
  1847
          unfolding *
nipkow@64267
  1848
          apply (rule sum.reindex_nontrivial [symmetric, unfolded o_def])
hoelzl@63941
  1849
          apply (rule finite_product_dependent)
hoelzl@63941
  1850
          apply fact
hoelzl@63941
  1851
          apply (rule finite_imageI)
hoelzl@63941
  1852
          apply (rule p')
hoelzl@63941
  1853
          unfolding split_paired_all mem_Collect_eq split_conv o_def
hoelzl@63941
  1854
        proof -
hoelzl@63941
  1855
          note * = division_ofD(4,5)[OF division_of_tagged_division,OF p(1)]
hoelzl@63941
  1856
          fix l1 l2 k1 k2
hoelzl@63941
  1857
          assume as:
hoelzl@63941
  1858
            "(l1, k1) \<noteq> (l2, k2)"
hoelzl@63941
  1859
            "l1 \<inter> k1 = l2 \<inter> k2"
hoelzl@63941
  1860
            "\<exists>i l. (l1, k1) = (i, l) \<and> i \<in> d \<and> l \<in> snd ` p"
hoelzl@63941
  1861
            "\<exists>i l. (l2, k2) = (i, l) \<and> i \<in> d \<and> l \<in> snd ` p"
hoelzl@63941
  1862
          then have "l1 \<in> d" and "k1 \<in> snd ` p"
hoelzl@63941
  1863
            by auto from d'(4)[OF this(1)] *(1)[OF this(2)]
hoelzl@63941
  1864
          guess u1 v1 u2 v2 by (elim exE) note uv=this
hoelzl@63941
  1865
          have "l1 \<noteq> l2 \<or> k1 \<noteq> k2"
hoelzl@63941
  1866
            using as by auto
hoelzl@63941
  1867
          then have "interior k1 \<inter> interior k2 = {} \<or> interior l1 \<inter> interior l2 = {}"
hoelzl@63941
  1868
            apply -
hoelzl@63941
  1869
            apply (erule disjE)
hoelzl@63941
  1870
            apply (rule disjI2)
hoelzl@63941
  1871
            apply (rule d'(5))
hoelzl@63941
  1872
            prefer 4
hoelzl@63941
  1873
            apply (rule disjI1)
hoelzl@63941
  1874
            apply (rule *)
hoelzl@63941
  1875
            using as
hoelzl@63941
  1876
            apply auto
hoelzl@63941
  1877
            done
hoelzl@63941
  1878
          moreover have "interior (l1 \<inter> k1) = interior (l2 \<inter> k2)"
hoelzl@63941
  1879
            using as(2) by auto
hoelzl@63941
  1880
          ultimately have "interior(l1 \<inter> k1) = {}"
hoelzl@63941
  1881
            by auto
hoelzl@63941
  1882
          then show "norm (integral (l1 \<inter> k1) f) = 0"
lp15@63945
  1883
            unfolding uv Int_interval
hoelzl@63941
  1884
            unfolding content_eq_0_interior[symmetric]
hoelzl@63941
  1885
            by auto
hoelzl@63941
  1886
        qed
hoelzl@63941
  1887
        also have "\<dots> = (\<Sum>(x, k)\<in>p'. norm (integral k f))"
hoelzl@63941
  1888
          unfolding sum_p'
nipkow@64267
  1889
          apply (rule sum.mono_neutral_right)
hoelzl@63941
  1890
          apply (subst *)
hoelzl@63941
  1891
          apply (rule finite_imageI[OF finite_product_dependent])
hoelzl@63941
  1892
          apply fact
hoelzl@63941
  1893
          apply (rule finite_imageI[OF p'(1)])
hoelzl@63941
  1894
          apply safe
hoelzl@63941
  1895
        proof goal_cases
hoelzl@63941
  1896
          case (2 i ia l a b)
hoelzl@63941
  1897
          then have "ia \<inter> b = {}"
hoelzl@63941
  1898
            unfolding p'alt image_iff Bex_def not_ex
hoelzl@63941
  1899
            apply (erule_tac x="(a, ia \<inter> b)" in allE)
hoelzl@63941
  1900
            apply auto
hoelzl@63941
  1901
            done
hoelzl@63941
  1902
          then show ?case
hoelzl@63941
  1903
            by auto
hoelzl@63941
  1904
        next
hoelzl@63941
  1905
          case (1 x a b)
hoelzl@63941
  1906
          then show ?case
hoelzl@63941
  1907
            unfolding p'_def
hoelzl@63941
  1908
            apply safe
hoelzl@63941
  1909
            apply (rule_tac x=i in exI)
hoelzl@63941
  1910
            apply (rule_tac x=l in exI)
hoelzl@63941
  1911
            unfolding snd_conv image_iff
hoelzl@63941
  1912
            apply safe
hoelzl@63941
  1913
            apply (rule_tac x="(a,l)" in bexI)
hoelzl@63941
  1914
            apply auto
hoelzl@63941
  1915
            done
hoelzl@63941
  1916
        qed
hoelzl@63941
  1917
        finally show ?case .
hoelzl@63941
  1918
      next
hoelzl@63941
  1919
        case 3
hoelzl@63941
  1920
        let ?S = "{(x, i \<inter> l) |x i l. (x, l) \<in> p \<and> i \<in> d}"
hoelzl@63941
  1921
        have Sigma_alt: "\<And>s t. s \<times> t = {(i, j) |i j. i \<in> s \<and> j \<in> t}"
hoelzl@63941
  1922
          by auto
hoelzl@63941
  1923
        have *: "?S = (\<lambda>(xl,i). (fst xl, snd xl \<inter> i)) ` (p \<times> d)"
hoelzl@63941
  1924
          apply safe
hoelzl@63941
  1925
          unfolding image_iff
hoelzl@63941
  1926
          apply (rule_tac x="((x,l),i)" in bexI)
hoelzl@63941
  1927
          apply auto
hoelzl@63941
  1928
          done
hoelzl@63941
  1929
        note pdfin = finite_cartesian_product[OF p'(1) d'(1)]
hoelzl@63941
  1930
        have "(\<Sum>(x, k)\<in>p'. norm (content k *\<^sub>R f x)) = (\<Sum>(x, k)\<in>?S. \<bar>content k\<bar> * norm (f x))"
hoelzl@63941
  1931
          unfolding norm_scaleR
nipkow@64267
  1932
          apply (rule sum.mono_neutral_left)
hoelzl@63941
  1933
          apply (subst *)
hoelzl@63941
  1934
          apply (rule finite_imageI)
hoelzl@63941
  1935
          apply fact
hoelzl@63941
  1936
          unfolding p'alt
hoelzl@63941
  1937
          apply blast
hoelzl@63941
  1938
          apply safe
hoelzl@63941
  1939
          apply (rule_tac x=x in exI)
hoelzl@63941
  1940
          apply (rule_tac x=i in exI)
hoelzl@63941
  1941
          apply (rule_tac x=l in exI)
hoelzl@63941
  1942
          apply auto
hoelzl@63941
  1943
          done
hoelzl@63941
  1944
        also have "\<dots> = (\<Sum>((x,l),i)\<in>p \<times> d. \<bar>content (l \<inter> i)\<bar> * norm (f x))"
hoelzl@63941
  1945
          unfolding *
nipkow@64267
  1946
          apply (subst sum.reindex_nontrivial)
hoelzl@63941
  1947
          apply fact
hoelzl@63941
  1948
          unfolding split_paired_all
hoelzl@63941
  1949
          unfolding o_def split_def snd_conv fst_conv mem_Sigma_iff prod.inject
hoelzl@63941
  1950
          apply (elim conjE)
hoelzl@63941
  1951
        proof -
hoelzl@63941
  1952
          fix x1 l1 k1 x2 l2 k2
hoelzl@63941
  1953
          assume as: "(x1, l1) \<in> p" "(x2, l2) \<in> p" "k1 \<in> d" "k2 \<in> d"
hoelzl@63941
  1954
            "x1 = x2" "l1 \<inter> k1 = l2 \<inter> k2" "\<not> ((x1 = x2 \<and> l1 = l2) \<and> k1 = k2)"
hoelzl@63941</