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