src/HOL/Analysis/Lebesgue_Measure.thy
author nipkow
Wed Jan 10 15:25:09 2018 +0100 (16 months ago)
changeset 67399 eab6ce8368fa
parent 67135 1a94352812f4
child 67673 c8caefb20564
permissions -rw-r--r--
ran isabelle update_op on all sources
hoelzl@63627
     1
(*  Title:      HOL/Analysis/Lebesgue_Measure.thy
hoelzl@42067
     2
    Author:     Johannes Hölzl, TU München
hoelzl@42067
     3
    Author:     Robert Himmelmann, TU München
hoelzl@57447
     4
    Author:     Jeremy Avigad
hoelzl@57447
     5
    Author:     Luke Serafin
hoelzl@42067
     6
*)
hoelzl@42067
     7
wenzelm@61808
     8
section \<open>Lebesgue measure\<close>
hoelzl@42067
     9
hoelzl@38656
    10
theory Lebesgue_Measure
hoelzl@63968
    11
  imports Finite_Product_Measure Bochner_Integration Caratheodory Complete_Measure Summation_Tests Regularity
hoelzl@38656
    12
begin
hoelzl@38656
    13
hoelzl@64008
    14
lemma measure_eqI_lessThan:
hoelzl@64008
    15
  fixes M N :: "real measure"
hoelzl@64008
    16
  assumes sets: "sets M = sets borel" "sets N = sets borel"
hoelzl@64008
    17
  assumes fin: "\<And>x. emeasure M {x <..} < \<infinity>"
hoelzl@64008
    18
  assumes "\<And>x. emeasure M {x <..} = emeasure N {x <..}"
hoelzl@64008
    19
  shows "M = N"
hoelzl@64008
    20
proof (rule measure_eqI_generator_eq_countable)
hoelzl@64008
    21
  let ?LT = "\<lambda>a::real. {a <..}" let ?E = "range ?LT"
hoelzl@64008
    22
  show "Int_stable ?E"
hoelzl@64008
    23
    by (auto simp: Int_stable_def lessThan_Int_lessThan)
hoelzl@64008
    24
hoelzl@64008
    25
  show "?E \<subseteq> Pow UNIV" "sets M = sigma_sets UNIV ?E" "sets N = sigma_sets UNIV ?E"
hoelzl@64008
    26
    unfolding sets borel_Ioi by auto
hoelzl@64008
    27
hoelzl@64008
    28
  show "?LT`Rats \<subseteq> ?E" "(\<Union>i\<in>Rats. ?LT i) = UNIV" "\<And>a. a \<in> ?LT`Rats \<Longrightarrow> emeasure M a \<noteq> \<infinity>"
hoelzl@64008
    29
    using fin by (auto intro: Rats_no_bot_less simp: less_top)
hoelzl@64008
    30
qed (auto intro: assms countable_rat)
hoelzl@64008
    31
wenzelm@61808
    32
subsection \<open>Every right continuous and nondecreasing function gives rise to a measure\<close>
hoelzl@57447
    33
hoelzl@57447
    34
definition interval_measure :: "(real \<Rightarrow> real) \<Rightarrow> real measure" where
hoelzl@62975
    35
  "interval_measure F = extend_measure UNIV {(a, b). a \<le> b} (\<lambda>(a, b). {a <.. b}) (\<lambda>(a, b). ennreal (F b - F a))"
hoelzl@49777
    36
hoelzl@57447
    37
lemma emeasure_interval_measure_Ioc:
hoelzl@57447
    38
  assumes "a \<le> b"
hoelzl@57447
    39
  assumes mono_F: "\<And>x y. x \<le> y \<Longrightarrow> F x \<le> F y"
lp15@60615
    40
  assumes right_cont_F : "\<And>a. continuous (at_right a) F"
hoelzl@57447
    41
  shows "emeasure (interval_measure F) {a <.. b} = F b - F a"
wenzelm@61808
    42
proof (rule extend_measure_caratheodory_pair[OF interval_measure_def \<open>a \<le> b\<close>])
hoelzl@57447
    43
  show "semiring_of_sets UNIV {{a<..b} |a b :: real. a \<le> b}"
hoelzl@57447
    44
  proof (unfold_locales, safe)
hoelzl@57447
    45
    fix a b c d :: real assume *: "a \<le> b" "c \<le> d"
hoelzl@57447
    46
    then show "\<exists>C\<subseteq>{{a<..b} |a b. a \<le> b}. finite C \<and> disjoint C \<and> {a<..b} - {c<..d} = \<Union>C"
hoelzl@57447
    47
    proof cases
hoelzl@57447
    48
      let ?C = "{{a<..b}}"
hoelzl@57447
    49
      assume "b < c \<or> d \<le> a \<or> d \<le> c"
hoelzl@57447
    50
      with * have "?C \<subseteq> {{a<..b} |a b. a \<le> b} \<and> finite ?C \<and> disjoint ?C \<and> {a<..b} - {c<..d} = \<Union>?C"
hoelzl@57447
    51
        by (auto simp add: disjoint_def)
hoelzl@57447
    52
      thus ?thesis ..
hoelzl@57447
    53
    next
hoelzl@57447
    54
      let ?C = "{{a<..c}, {d<..b}}"
hoelzl@57447
    55
      assume "\<not> (b < c \<or> d \<le> a \<or> d \<le> c)"
hoelzl@57447
    56
      with * have "?C \<subseteq> {{a<..b} |a b. a \<le> b} \<and> finite ?C \<and> disjoint ?C \<and> {a<..b} - {c<..d} = \<Union>?C"
hoelzl@57447
    57
        by (auto simp add: disjoint_def Ioc_inj) (metis linear)+
hoelzl@57447
    58
      thus ?thesis ..
hoelzl@57447
    59
    qed
hoelzl@57447
    60
  qed (auto simp: Ioc_inj, metis linear)
hoelzl@57447
    61
next
hoelzl@57447
    62
  fix l r :: "nat \<Rightarrow> real" and a b :: real
lp15@60615
    63
  assume l_r[simp]: "\<And>n. l n \<le> r n" and "a \<le> b" and disj: "disjoint_family (\<lambda>n. {l n<..r n})"
hoelzl@57447
    64
  assume lr_eq_ab: "(\<Union>i. {l i<..r i}) = {a<..b}"
hoelzl@57447
    65
lp15@61762
    66
  have [intro, simp]: "\<And>a b. a \<le> b \<Longrightarrow> F a \<le> F b"
lp15@61762
    67
    by (auto intro!: l_r mono_F)
hoelzl@57447
    68
hoelzl@57447
    69
  { fix S :: "nat set" assume "finite S"
wenzelm@61808
    70
    moreover note \<open>a \<le> b\<close>
hoelzl@57447
    71
    moreover have "\<And>i. i \<in> S \<Longrightarrow> {l i <.. r i} \<subseteq> {a <.. b}"
hoelzl@57447
    72
      unfolding lr_eq_ab[symmetric] by auto
hoelzl@57447
    73
    ultimately have "(\<Sum>i\<in>S. F (r i) - F (l i)) \<le> F b - F a"
hoelzl@57447
    74
    proof (induction S arbitrary: a rule: finite_psubset_induct)
hoelzl@57447
    75
      case (psubset S)
hoelzl@57447
    76
      show ?case
hoelzl@57447
    77
      proof cases
hoelzl@57447
    78
        assume "\<exists>i\<in>S. l i < r i"
wenzelm@61808
    79
        with \<open>finite S\<close> have "Min (l ` {i\<in>S. l i < r i}) \<in> l ` {i\<in>S. l i < r i}"
hoelzl@57447
    80
          by (intro Min_in) auto
hoelzl@57447
    81
        then obtain m where m: "m \<in> S" "l m < r m" "l m = Min (l ` {i\<in>S. l i < r i})"
hoelzl@57447
    82
          by fastforce
hoelzl@50104
    83
hoelzl@57447
    84
        have "(\<Sum>i\<in>S. F (r i) - F (l i)) = (F (r m) - F (l m)) + (\<Sum>i\<in>S - {m}. F (r i) - F (l i))"
nipkow@64267
    85
          using m psubset by (intro sum.remove) auto
hoelzl@57447
    86
        also have "(\<Sum>i\<in>S - {m}. F (r i) - F (l i)) \<le> F b - F (r m)"
hoelzl@57447
    87
        proof (intro psubset.IH)
hoelzl@57447
    88
          show "S - {m} \<subset> S"
wenzelm@61808
    89
            using \<open>m\<in>S\<close> by auto
hoelzl@57447
    90
          show "r m \<le> b"
wenzelm@61808
    91
            using psubset.prems(2)[OF \<open>m\<in>S\<close>] \<open>l m < r m\<close> by auto
hoelzl@57447
    92
        next
hoelzl@57447
    93
          fix i assume "i \<in> S - {m}"
hoelzl@57447
    94
          then have i: "i \<in> S" "i \<noteq> m" by auto
hoelzl@57447
    95
          { assume i': "l i < r i" "l i < r m"
wenzelm@63540
    96
            with \<open>finite S\<close> i m have "l m \<le> l i"
hoelzl@57447
    97
              by auto
wenzelm@63540
    98
            with i' have "{l i <.. r i} \<inter> {l m <.. r m} \<noteq> {}"
hoelzl@57447
    99
              by auto
hoelzl@57447
   100
            then have False
hoelzl@57447
   101
              using disjoint_family_onD[OF disj, of i m] i by auto }
hoelzl@57447
   102
          then have "l i \<noteq> r i \<Longrightarrow> r m \<le> l i"
hoelzl@57447
   103
            unfolding not_less[symmetric] using l_r[of i] by auto
hoelzl@57447
   104
          then show "{l i <.. r i} \<subseteq> {r m <.. b}"
wenzelm@61808
   105
            using psubset.prems(2)[OF \<open>i\<in>S\<close>] by auto
hoelzl@57447
   106
        qed
hoelzl@57447
   107
        also have "F (r m) - F (l m) \<le> F (r m) - F a"
wenzelm@61808
   108
          using psubset.prems(2)[OF \<open>m \<in> S\<close>] \<open>l m < r m\<close>
hoelzl@57447
   109
          by (auto simp add: Ioc_subset_iff intro!: mono_F)
hoelzl@57447
   110
        finally show ?case
hoelzl@57447
   111
          by (auto intro: add_mono)
wenzelm@61808
   112
      qed (auto simp add: \<open>a \<le> b\<close> less_le)
hoelzl@57447
   113
    qed }
hoelzl@57447
   114
  note claim1 = this
hoelzl@57447
   115
hoelzl@57447
   116
  (* second key induction: a lower bound on the measures of any finite collection of Ai's
hoelzl@57447
   117
     that cover an interval {u..v} *)
hoelzl@57447
   118
hoelzl@57447
   119
  { fix S u v and l r :: "nat \<Rightarrow> real"
hoelzl@57447
   120
    assume "finite S" "\<And>i. i\<in>S \<Longrightarrow> l i < r i" "{u..v} \<subseteq> (\<Union>i\<in>S. {l i<..< r i})"
hoelzl@57447
   121
    then have "F v - F u \<le> (\<Sum>i\<in>S. F (r i) - F (l i))"
hoelzl@57447
   122
    proof (induction arbitrary: v u rule: finite_psubset_induct)
hoelzl@57447
   123
      case (psubset S)
hoelzl@57447
   124
      show ?case
hoelzl@57447
   125
      proof cases
hoelzl@57447
   126
        assume "S = {}" then show ?case
hoelzl@57447
   127
          using psubset by (simp add: mono_F)
hoelzl@57447
   128
      next
hoelzl@57447
   129
        assume "S \<noteq> {}"
hoelzl@57447
   130
        then obtain j where "j \<in> S"
hoelzl@57447
   131
          by auto
hoelzl@47694
   132
hoelzl@57447
   133
        let ?R = "r j < u \<or> l j > v \<or> (\<exists>i\<in>S-{j}. l i \<le> l j \<and> r j \<le> r i)"
hoelzl@57447
   134
        show ?case
hoelzl@57447
   135
        proof cases
hoelzl@57447
   136
          assume "?R"
wenzelm@61808
   137
          with \<open>j \<in> S\<close> psubset.prems have "{u..v} \<subseteq> (\<Union>i\<in>S-{j}. {l i<..< r i})"
hoelzl@57447
   138
            apply (auto simp: subset_eq Ball_def)
hoelzl@57447
   139
            apply (metis Diff_iff less_le_trans leD linear singletonD)
hoelzl@57447
   140
            apply (metis Diff_iff less_le_trans leD linear singletonD)
hoelzl@57447
   141
            apply (metis order_trans less_le_not_le linear)
hoelzl@57447
   142
            done
wenzelm@61808
   143
          with \<open>j \<in> S\<close> have "F v - F u \<le> (\<Sum>i\<in>S - {j}. F (r i) - F (l i))"
hoelzl@57447
   144
            by (intro psubset) auto
hoelzl@57447
   145
          also have "\<dots> \<le> (\<Sum>i\<in>S. F (r i) - F (l i))"
hoelzl@57447
   146
            using psubset.prems
nipkow@64267
   147
            by (intro sum_mono2 psubset) (auto intro: less_imp_le)
hoelzl@57447
   148
          finally show ?thesis .
hoelzl@57447
   149
        next
hoelzl@57447
   150
          assume "\<not> ?R"
hoelzl@57447
   151
          then have j: "u \<le> r j" "l j \<le> v" "\<And>i. i \<in> S - {j} \<Longrightarrow> r i < r j \<or> l i > l j"
hoelzl@57447
   152
            by (auto simp: not_less)
hoelzl@57447
   153
          let ?S1 = "{i \<in> S. l i < l j}"
hoelzl@57447
   154
          let ?S2 = "{i \<in> S. r i > r j}"
hoelzl@40859
   155
hoelzl@57447
   156
          have "(\<Sum>i\<in>S. F (r i) - F (l i)) \<ge> (\<Sum>i\<in>?S1 \<union> ?S2 \<union> {j}. F (r i) - F (l i))"
wenzelm@61808
   157
            using \<open>j \<in> S\<close> \<open>finite S\<close> psubset.prems j
nipkow@64267
   158
            by (intro sum_mono2) (auto intro: less_imp_le)
hoelzl@57447
   159
          also have "(\<Sum>i\<in>?S1 \<union> ?S2 \<union> {j}. F (r i) - F (l i)) =
hoelzl@57447
   160
            (\<Sum>i\<in>?S1. F (r i) - F (l i)) + (\<Sum>i\<in>?S2 . F (r i) - F (l i)) + (F (r j) - F (l j))"
hoelzl@57447
   161
            using psubset(1) psubset.prems(1) j
nipkow@64267
   162
            apply (subst sum.union_disjoint)
hoelzl@57447
   163
            apply simp_all
nipkow@64267
   164
            apply (subst sum.union_disjoint)
hoelzl@57447
   165
            apply auto
hoelzl@57447
   166
            apply (metis less_le_not_le)
hoelzl@57447
   167
            done
hoelzl@57447
   168
          also (xtrans) have "(\<Sum>i\<in>?S1. F (r i) - F (l i)) \<ge> F (l j) - F u"
wenzelm@61808
   169
            using \<open>j \<in> S\<close> \<open>finite S\<close> psubset.prems j
hoelzl@57447
   170
            apply (intro psubset.IH psubset)
hoelzl@57447
   171
            apply (auto simp: subset_eq Ball_def)
hoelzl@57447
   172
            apply (metis less_le_trans not_le)
hoelzl@57447
   173
            done
hoelzl@57447
   174
          also (xtrans) have "(\<Sum>i\<in>?S2. F (r i) - F (l i)) \<ge> F v - F (r j)"
wenzelm@61808
   175
            using \<open>j \<in> S\<close> \<open>finite S\<close> psubset.prems j
hoelzl@57447
   176
            apply (intro psubset.IH psubset)
hoelzl@57447
   177
            apply (auto simp: subset_eq Ball_def)
hoelzl@57447
   178
            apply (metis le_less_trans not_le)
hoelzl@57447
   179
            done
hoelzl@57447
   180
          finally (xtrans) show ?case
hoelzl@57447
   181
            by (auto simp: add_mono)
hoelzl@57447
   182
        qed
hoelzl@57447
   183
      qed
hoelzl@57447
   184
    qed }
hoelzl@57447
   185
  note claim2 = this
hoelzl@49777
   186
hoelzl@57447
   187
  (* now prove the inequality going the other way *)
hoelzl@62975
   188
  have "ennreal (F b - F a) \<le> (\<Sum>i. ennreal (F (r i) - F (l i)))"
hoelzl@62975
   189
  proof (rule ennreal_le_epsilon)
hoelzl@62975
   190
    fix epsilon :: real assume egt0: "epsilon > 0"
hoelzl@62975
   191
    have "\<forall>i. \<exists>d>0. F (r i + d) < F (r i) + epsilon / 2^(i+2)"
lp15@60615
   192
    proof
hoelzl@57447
   193
      fix i
hoelzl@57447
   194
      note right_cont_F [of "r i"]
hoelzl@62975
   195
      thus "\<exists>d>0. F (r i + d) < F (r i) + epsilon / 2^(i+2)"
hoelzl@57447
   196
        apply -
hoelzl@57447
   197
        apply (subst (asm) continuous_at_right_real_increasing)
hoelzl@57447
   198
        apply (rule mono_F, assumption)
hoelzl@57447
   199
        apply (drule_tac x = "epsilon / 2 ^ (i + 2)" in spec)
hoelzl@57447
   200
        apply (erule impE)
hoelzl@57447
   201
        using egt0 by (auto simp add: field_simps)
hoelzl@57447
   202
    qed
lp15@60615
   203
    then obtain delta where
hoelzl@57447
   204
        deltai_gt0: "\<And>i. delta i > 0" and
hoelzl@57447
   205
        deltai_prop: "\<And>i. F (r i + delta i) < F (r i) + epsilon / 2^(i+2)"
hoelzl@57447
   206
      by metis
hoelzl@57447
   207
    have "\<exists>a' > a. F a' - F a < epsilon / 2"
hoelzl@57447
   208
      apply (insert right_cont_F [of a])
hoelzl@57447
   209
      apply (subst (asm) continuous_at_right_real_increasing)
hoelzl@57447
   210
      using mono_F apply force
hoelzl@57447
   211
      apply (drule_tac x = "epsilon / 2" in spec)
haftmann@59554
   212
      using egt0 unfolding mult.commute [of 2] by force
lp15@60615
   213
    then obtain a' where a'lea [arith]: "a' > a" and
hoelzl@57447
   214
      a_prop: "F a' - F a < epsilon / 2"
hoelzl@57447
   215
      by auto
wenzelm@63040
   216
    define S' where "S' = {i. l i < r i}"
lp15@60615
   217
    obtain S :: "nat set" where
lp15@60615
   218
      "S \<subseteq> S'" and finS: "finite S" and
hoelzl@57447
   219
      Sprop: "{a'..b} \<subseteq> (\<Union>i \<in> S. {l i<..<r i + delta i})"
hoelzl@57447
   220
    proof (rule compactE_image)
hoelzl@57447
   221
      show "compact {a'..b}"
hoelzl@57447
   222
        by (rule compact_Icc)
lp15@65585
   223
      show "\<And>i. i \<in> S' \<Longrightarrow> open ({l i<..<r i + delta i})" by auto
hoelzl@57447
   224
      have "{a'..b} \<subseteq> {a <.. b}"
hoelzl@57447
   225
        by auto
hoelzl@57447
   226
      also have "{a <.. b} = (\<Union>i\<in>S'. {l i<..r i})"
hoelzl@57447
   227
        unfolding lr_eq_ab[symmetric] by (fastforce simp add: S'_def intro: less_le_trans)
hoelzl@57447
   228
      also have "\<dots> \<subseteq> (\<Union>i \<in> S'. {l i<..<r i + delta i})"
hoelzl@57447
   229
        apply (intro UN_mono)
hoelzl@57447
   230
        apply (auto simp: S'_def)
hoelzl@57447
   231
        apply (cut_tac i=i in deltai_gt0)
hoelzl@57447
   232
        apply simp
hoelzl@57447
   233
        done
hoelzl@57447
   234
      finally show "{a'..b} \<subseteq> (\<Union>i \<in> S'. {l i<..<r i + delta i})" .
hoelzl@57447
   235
    qed
hoelzl@57447
   236
    with S'_def have Sprop2: "\<And>i. i \<in> S \<Longrightarrow> l i < r i" by auto
lp15@60615
   237
    from finS have "\<exists>n. \<forall>i \<in> S. i \<le> n"
hoelzl@57447
   238
      by (subst finite_nat_set_iff_bounded_le [symmetric])
hoelzl@57447
   239
    then obtain n where Sbound [rule_format]: "\<forall>i \<in> S. i \<le> n" ..
hoelzl@57447
   240
    have "F b - F a' \<le> (\<Sum>i\<in>S. F (r i + delta i) - F (l i))"
hoelzl@57447
   241
      apply (rule claim2 [rule_format])
hoelzl@57447
   242
      using finS Sprop apply auto
hoelzl@57447
   243
      apply (frule Sprop2)
hoelzl@57447
   244
      apply (subgoal_tac "delta i > 0")
hoelzl@57447
   245
      apply arith
hoelzl@57447
   246
      by (rule deltai_gt0)
wenzelm@61954
   247
    also have "... \<le> (\<Sum>i \<in> S. F(r i) - F(l i) + epsilon / 2^(i+2))"
nipkow@64267
   248
      apply (rule sum_mono)
hoelzl@57447
   249
      apply simp
hoelzl@57447
   250
      apply (rule order_trans)
hoelzl@57447
   251
      apply (rule less_imp_le)
hoelzl@57447
   252
      apply (rule deltai_prop)
hoelzl@57447
   253
      by auto
wenzelm@61954
   254
    also have "... = (\<Sum>i \<in> S. F(r i) - F(l i)) +
wenzelm@61954
   255
        (epsilon / 4) * (\<Sum>i \<in> S. (1 / 2)^i)" (is "_ = ?t + _")
nipkow@64267
   256
      by (subst sum.distrib) (simp add: field_simps sum_distrib_left)
hoelzl@57447
   257
    also have "... \<le> ?t + (epsilon / 4) * (\<Sum> i < Suc n. (1 / 2)^i)"
hoelzl@57447
   258
      apply (rule add_left_mono)
hoelzl@57447
   259
      apply (rule mult_left_mono)
nipkow@64267
   260
      apply (rule sum_mono2)
lp15@60615
   261
      using egt0 apply auto
hoelzl@57447
   262
      by (frule Sbound, auto)
hoelzl@57447
   263
    also have "... \<le> ?t + (epsilon / 2)"
hoelzl@57447
   264
      apply (rule add_left_mono)
hoelzl@57447
   265
      apply (subst geometric_sum)
hoelzl@57447
   266
      apply auto
hoelzl@57447
   267
      apply (rule mult_left_mono)
hoelzl@57447
   268
      using egt0 apply auto
hoelzl@57447
   269
      done
hoelzl@57447
   270
    finally have aux2: "F b - F a' \<le> (\<Sum>i\<in>S. F (r i) - F (l i)) + epsilon / 2"
hoelzl@57447
   271
      by simp
hoelzl@50526
   272
hoelzl@57447
   273
    have "F b - F a = (F b - F a') + (F a' - F a)"
hoelzl@57447
   274
      by auto
hoelzl@57447
   275
    also have "... \<le> (F b - F a') + epsilon / 2"
hoelzl@57447
   276
      using a_prop by (intro add_left_mono) simp
hoelzl@57447
   277
    also have "... \<le> (\<Sum>i\<in>S. F (r i) - F (l i)) + epsilon / 2 + epsilon / 2"
hoelzl@57447
   278
      apply (intro add_right_mono)
hoelzl@57447
   279
      apply (rule aux2)
hoelzl@57447
   280
      done
hoelzl@57447
   281
    also have "... = (\<Sum>i\<in>S. F (r i) - F (l i)) + epsilon"
hoelzl@57447
   282
      by auto
hoelzl@57447
   283
    also have "... \<le> (\<Sum>i\<le>n. F (r i) - F (l i)) + epsilon"
lp15@65680
   284
      using finS Sbound Sprop by (auto intro!: add_right_mono sum_mono2)
hoelzl@62975
   285
    finally have "ennreal (F b - F a) \<le> (\<Sum>i\<le>n. ennreal (F (r i) - F (l i))) + epsilon"
nipkow@64267
   286
      using egt0 by (simp add: ennreal_plus[symmetric] sum_nonneg del: ennreal_plus)
hoelzl@62975
   287
    then show "ennreal (F b - F a) \<le> (\<Sum>i. ennreal (F (r i) - F (l i))) + (epsilon :: real)"
nipkow@64267
   288
      by (rule order_trans) (auto intro!: add_mono sum_le_suminf simp del: sum_ennreal)
hoelzl@62975
   289
  qed
hoelzl@62975
   290
  moreover have "(\<Sum>i. ennreal (F (r i) - F (l i))) \<le> ennreal (F b - F a)"
hoelzl@62975
   291
    using \<open>a \<le> b\<close> by (auto intro!: suminf_le_const ennreal_le_iff[THEN iffD2] claim1)
hoelzl@62975
   292
  ultimately show "(\<Sum>n. ennreal (F (r n) - F (l n))) = ennreal (F b - F a)"
hoelzl@62975
   293
    by (rule antisym[rotated])
lp15@61762
   294
qed (auto simp: Ioc_inj mono_F)
hoelzl@38656
   295
hoelzl@57447
   296
lemma measure_interval_measure_Ioc:
hoelzl@57447
   297
  assumes "a \<le> b"
hoelzl@57447
   298
  assumes mono_F: "\<And>x y. x \<le> y \<Longrightarrow> F x \<le> F y"
lp15@60615
   299
  assumes right_cont_F : "\<And>a. continuous (at_right a) F"
hoelzl@57447
   300
  shows "measure (interval_measure F) {a <.. b} = F b - F a"
hoelzl@57447
   301
  unfolding measure_def
hoelzl@57447
   302
  apply (subst emeasure_interval_measure_Ioc)
hoelzl@57447
   303
  apply fact+
hoelzl@62975
   304
  apply (simp add: assms)
hoelzl@57447
   305
  done
hoelzl@57447
   306
hoelzl@57447
   307
lemma emeasure_interval_measure_Ioc_eq:
hoelzl@57447
   308
  "(\<And>x y. x \<le> y \<Longrightarrow> F x \<le> F y) \<Longrightarrow> (\<And>a. continuous (at_right a) F) \<Longrightarrow>
hoelzl@57447
   309
    emeasure (interval_measure F) {a <.. b} = (if a \<le> b then F b - F a else 0)"
hoelzl@57447
   310
  using emeasure_interval_measure_Ioc[of a b F] by auto
hoelzl@57447
   311
hoelzl@59048
   312
lemma sets_interval_measure [simp, measurable_cong]: "sets (interval_measure F) = sets borel"
hoelzl@57447
   313
  apply (simp add: sets_extend_measure interval_measure_def borel_sigma_sets_Ioc)
hoelzl@57447
   314
  apply (rule sigma_sets_eqI)
hoelzl@57447
   315
  apply auto
hoelzl@57447
   316
  apply (case_tac "a \<le> ba")
hoelzl@57447
   317
  apply (auto intro: sigma_sets.Empty)
hoelzl@57447
   318
  done
hoelzl@57447
   319
hoelzl@57447
   320
lemma space_interval_measure [simp]: "space (interval_measure F) = UNIV"
hoelzl@57447
   321
  by (simp add: interval_measure_def space_extend_measure)
hoelzl@57447
   322
hoelzl@57447
   323
lemma emeasure_interval_measure_Icc:
hoelzl@57447
   324
  assumes "a \<le> b"
hoelzl@57447
   325
  assumes mono_F: "\<And>x y. x \<le> y \<Longrightarrow> F x \<le> F y"
lp15@60615
   326
  assumes cont_F : "continuous_on UNIV F"
hoelzl@57447
   327
  shows "emeasure (interval_measure F) {a .. b} = F b - F a"
hoelzl@57447
   328
proof (rule tendsto_unique)
hoelzl@57447
   329
  { fix a b :: real assume "a \<le> b" then have "emeasure (interval_measure F) {a <.. b} = F b - F a"
hoelzl@57447
   330
      using cont_F
hoelzl@57447
   331
      by (subst emeasure_interval_measure_Ioc)
hoelzl@57447
   332
         (auto intro: mono_F continuous_within_subset simp: continuous_on_eq_continuous_within) }
hoelzl@57447
   333
  note * = this
hoelzl@38656
   334
hoelzl@57447
   335
  let ?F = "interval_measure F"
wenzelm@61973
   336
  show "((\<lambda>a. F b - F a) \<longlongrightarrow> emeasure ?F {a..b}) (at_left a)"
hoelzl@57447
   337
  proof (rule tendsto_at_left_sequentially)
hoelzl@57447
   338
    show "a - 1 < a" by simp
wenzelm@61969
   339
    fix X assume "\<And>n. X n < a" "incseq X" "X \<longlonglongrightarrow> a"
wenzelm@61969
   340
    with \<open>a \<le> b\<close> have "(\<lambda>n. emeasure ?F {X n<..b}) \<longlonglongrightarrow> emeasure ?F (\<Inter>n. {X n <..b})"
hoelzl@57447
   341
      apply (intro Lim_emeasure_decseq)
hoelzl@57447
   342
      apply (auto simp: decseq_def incseq_def emeasure_interval_measure_Ioc *)
hoelzl@57447
   343
      apply force
hoelzl@57447
   344
      apply (subst (asm ) *)
hoelzl@57447
   345
      apply (auto intro: less_le_trans less_imp_le)
hoelzl@57447
   346
      done
hoelzl@57447
   347
    also have "(\<Inter>n. {X n <..b}) = {a..b}"
wenzelm@61808
   348
      using \<open>\<And>n. X n < a\<close>
hoelzl@57447
   349
      apply auto
wenzelm@61969
   350
      apply (rule LIMSEQ_le_const2[OF \<open>X \<longlonglongrightarrow> a\<close>])
hoelzl@57447
   351
      apply (auto intro: less_imp_le)
hoelzl@57447
   352
      apply (auto intro: less_le_trans)
hoelzl@57447
   353
      done
hoelzl@57447
   354
    also have "(\<lambda>n. emeasure ?F {X n<..b}) = (\<lambda>n. F b - F (X n))"
wenzelm@61808
   355
      using \<open>\<And>n. X n < a\<close> \<open>a \<le> b\<close> by (subst *) (auto intro: less_imp_le less_le_trans)
wenzelm@61969
   356
    finally show "(\<lambda>n. F b - F (X n)) \<longlonglongrightarrow> emeasure ?F {a..b}" .
hoelzl@57447
   357
  qed
hoelzl@62975
   358
  show "((\<lambda>a. ennreal (F b - F a)) \<longlongrightarrow> F b - F a) (at_left a)"
hoelzl@62975
   359
    by (rule continuous_on_tendsto_compose[where g="\<lambda>x. x" and s=UNIV])
hoelzl@62975
   360
       (auto simp: continuous_on_ennreal continuous_on_diff cont_F continuous_on_const)
hoelzl@57447
   361
qed (rule trivial_limit_at_left_real)
lp15@60615
   362
hoelzl@57447
   363
lemma sigma_finite_interval_measure:
hoelzl@57447
   364
  assumes mono_F: "\<And>x y. x \<le> y \<Longrightarrow> F x \<le> F y"
lp15@60615
   365
  assumes right_cont_F : "\<And>a. continuous (at_right a) F"
hoelzl@57447
   366
  shows "sigma_finite_measure (interval_measure F)"
hoelzl@57447
   367
  apply unfold_locales
hoelzl@57447
   368
  apply (intro exI[of _ "(\<lambda>(a, b). {a <.. b}) ` (\<rat> \<times> \<rat>)"])
hoelzl@57447
   369
  apply (auto intro!: Rats_no_top_le Rats_no_bot_less countable_rat simp: emeasure_interval_measure_Ioc_eq[OF assms])
hoelzl@57447
   370
  done
hoelzl@57447
   371
wenzelm@61808
   372
subsection \<open>Lebesgue-Borel measure\<close>
hoelzl@57447
   373
hoelzl@57447
   374
definition lborel :: "('a :: euclidean_space) measure" where
hoelzl@57447
   375
  "lborel = distr (\<Pi>\<^sub>M b\<in>Basis. interval_measure (\<lambda>x. x)) borel (\<lambda>f. \<Sum>b\<in>Basis. f b *\<^sub>R b)"
hoelzl@57447
   376
hoelzl@63958
   377
abbreviation lebesgue :: "'a::euclidean_space measure"
hoelzl@63958
   378
  where "lebesgue \<equiv> completion lborel"
hoelzl@63958
   379
hoelzl@63958
   380
abbreviation lebesgue_on :: "'a set \<Rightarrow> 'a::euclidean_space measure"
hoelzl@63958
   381
  where "lebesgue_on \<Omega> \<equiv> restrict_space (completion lborel) \<Omega>"
hoelzl@63958
   382
lp15@60615
   383
lemma
hoelzl@59048
   384
  shows sets_lborel[simp, measurable_cong]: "sets lborel = sets borel"
hoelzl@57447
   385
    and space_lborel[simp]: "space lborel = space borel"
hoelzl@57447
   386
    and measurable_lborel1[simp]: "measurable M lborel = measurable M borel"
hoelzl@57447
   387
    and measurable_lborel2[simp]: "measurable lborel M = measurable borel M"
hoelzl@57447
   388
  by (simp_all add: lborel_def)
hoelzl@57447
   389
lp15@66164
   390
lemma sets_lebesgue_on_refl [iff]: "S \<in> sets (lebesgue_on S)"
lp15@66164
   391
    by (metis inf_top.right_neutral sets.top space_borel space_completion space_lborel space_restrict_space)
lp15@66164
   392
lp15@66164
   393
lemma Compl_in_sets_lebesgue: "-A \<in> sets lebesgue \<longleftrightarrow> A  \<in> sets lebesgue"
lp15@66164
   394
  by (metis Compl_eq_Diff_UNIV double_compl space_borel space_completion space_lborel Sigma_Algebra.sets.compl_sets)
lp15@66164
   395
hoelzl@57447
   396
context
hoelzl@57447
   397
begin
hoelzl@57447
   398
hoelzl@57447
   399
interpretation sigma_finite_measure "interval_measure (\<lambda>x. x)"
hoelzl@57447
   400
  by (rule sigma_finite_interval_measure) auto
hoelzl@57447
   401
interpretation finite_product_sigma_finite "\<lambda>_. interval_measure (\<lambda>x. x)" Basis
hoelzl@57447
   402
  proof qed simp
hoelzl@57447
   403
hoelzl@57447
   404
lemma lborel_eq_real: "lborel = interval_measure (\<lambda>x. x)"
hoelzl@57447
   405
  unfolding lborel_def Basis_real_def
hoelzl@57447
   406
  using distr_id[of "interval_measure (\<lambda>x. x)"]
hoelzl@57447
   407
  by (subst distr_component[symmetric])
hoelzl@57447
   408
     (simp_all add: distr_distr comp_def del: distr_id cong: distr_cong)
hoelzl@57447
   409
hoelzl@57447
   410
lemma lborel_eq: "lborel = distr (\<Pi>\<^sub>M b\<in>Basis. lborel) borel (\<lambda>f. \<Sum>b\<in>Basis. f b *\<^sub>R b)"
hoelzl@57447
   411
  by (subst lborel_def) (simp add: lborel_eq_real)
hoelzl@57447
   412
nipkow@64272
   413
lemma nn_integral_lborel_prod:
hoelzl@57447
   414
  assumes [measurable]: "\<And>b. b \<in> Basis \<Longrightarrow> f b \<in> borel_measurable borel"
hoelzl@57447
   415
  assumes nn[simp]: "\<And>b x. b \<in> Basis \<Longrightarrow> 0 \<le> f b x"
hoelzl@57447
   416
  shows "(\<integral>\<^sup>+x. (\<Prod>b\<in>Basis. f b (x \<bullet> b)) \<partial>lborel) = (\<Prod>b\<in>Basis. (\<integral>\<^sup>+x. f b x \<partial>lborel))"
nipkow@64272
   417
  by (simp add: lborel_def nn_integral_distr product_nn_integral_prod
hoelzl@57447
   418
                product_nn_integral_singleton)
hoelzl@57447
   419
lp15@60615
   420
lemma emeasure_lborel_Icc[simp]:
hoelzl@57447
   421
  fixes l u :: real
hoelzl@57447
   422
  assumes [simp]: "l \<le> u"
hoelzl@57447
   423
  shows "emeasure lborel {l .. u} = u - l"
hoelzl@50526
   424
proof -
hoelzl@57447
   425
  have "((\<lambda>f. f 1) -` {l..u} \<inter> space (Pi\<^sub>M {1} (\<lambda>b. interval_measure (\<lambda>x. x)))) = {1::real} \<rightarrow>\<^sub>E {l..u}"
hoelzl@57447
   426
    by (auto simp: space_PiM)
hoelzl@57447
   427
  then show ?thesis
hoelzl@57447
   428
    by (simp add: lborel_def emeasure_distr emeasure_PiM emeasure_interval_measure_Icc continuous_on_id)
hoelzl@50104
   429
qed
hoelzl@50104
   430
hoelzl@62975
   431
lemma emeasure_lborel_Icc_eq: "emeasure lborel {l .. u} = ennreal (if l \<le> u then u - l else 0)"
hoelzl@57447
   432
  by simp
hoelzl@47694
   433
hoelzl@57447
   434
lemma emeasure_lborel_cbox[simp]:
hoelzl@57447
   435
  assumes [simp]: "\<And>b. b \<in> Basis \<Longrightarrow> l \<bullet> b \<le> u \<bullet> b"
hoelzl@57447
   436
  shows "emeasure lborel (cbox l u) = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@41654
   437
proof -
hoelzl@62975
   438
  have "(\<lambda>x. \<Prod>b\<in>Basis. indicator {l\<bullet>b .. u\<bullet>b} (x \<bullet> b) :: ennreal) = indicator (cbox l u)"
hoelzl@62975
   439
    by (auto simp: fun_eq_iff cbox_def split: split_indicator)
hoelzl@57447
   440
  then have "emeasure lborel (cbox l u) = (\<integral>\<^sup>+x. (\<Prod>b\<in>Basis. indicator {l\<bullet>b .. u\<bullet>b} (x \<bullet> b)) \<partial>lborel)"
hoelzl@57447
   441
    by simp
hoelzl@57447
   442
  also have "\<dots> = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
nipkow@64272
   443
    by (subst nn_integral_lborel_prod) (simp_all add: prod_ennreal inner_diff_left)
hoelzl@47694
   444
  finally show ?thesis .
hoelzl@38656
   445
qed
hoelzl@38656
   446
hoelzl@57447
   447
lemma AE_lborel_singleton: "AE x in lborel::'a::euclidean_space measure. x \<noteq> c"
hoelzl@62975
   448
  using SOME_Basis AE_discrete_difference [of "{c}" lborel] emeasure_lborel_cbox [of c c]
nipkow@64272
   449
  by (auto simp add: cbox_sing prod_constant power_0_left)
hoelzl@47757
   450
hoelzl@57447
   451
lemma emeasure_lborel_Ioo[simp]:
hoelzl@57447
   452
  assumes [simp]: "l \<le> u"
hoelzl@62975
   453
  shows "emeasure lborel {l <..< u} = ennreal (u - l)"
hoelzl@40859
   454
proof -
hoelzl@57447
   455
  have "emeasure lborel {l <..< u} = emeasure lborel {l .. u}"
hoelzl@57447
   456
    using AE_lborel_singleton[of u] AE_lborel_singleton[of l] by (intro emeasure_eq_AE) auto
hoelzl@47694
   457
  then show ?thesis
hoelzl@57447
   458
    by simp
hoelzl@41981
   459
qed
hoelzl@38656
   460
hoelzl@57447
   461
lemma emeasure_lborel_Ioc[simp]:
hoelzl@57447
   462
  assumes [simp]: "l \<le> u"
hoelzl@62975
   463
  shows "emeasure lborel {l <.. u} = ennreal (u - l)"
hoelzl@41654
   464
proof -
hoelzl@57447
   465
  have "emeasure lborel {l <.. u} = emeasure lborel {l .. u}"
hoelzl@57447
   466
    using AE_lborel_singleton[of u] AE_lborel_singleton[of l] by (intro emeasure_eq_AE) auto
hoelzl@57447
   467
  then show ?thesis
hoelzl@57447
   468
    by simp
hoelzl@38656
   469
qed
hoelzl@38656
   470
hoelzl@57447
   471
lemma emeasure_lborel_Ico[simp]:
hoelzl@57447
   472
  assumes [simp]: "l \<le> u"
hoelzl@62975
   473
  shows "emeasure lborel {l ..< u} = ennreal (u - l)"
hoelzl@57447
   474
proof -
hoelzl@57447
   475
  have "emeasure lborel {l ..< u} = emeasure lborel {l .. u}"
hoelzl@57447
   476
    using AE_lborel_singleton[of u] AE_lborel_singleton[of l] by (intro emeasure_eq_AE) auto
hoelzl@57447
   477
  then show ?thesis
hoelzl@57447
   478
    by simp
hoelzl@38656
   479
qed
hoelzl@38656
   480
hoelzl@57447
   481
lemma emeasure_lborel_box[simp]:
hoelzl@57447
   482
  assumes [simp]: "\<And>b. b \<in> Basis \<Longrightarrow> l \<bullet> b \<le> u \<bullet> b"
hoelzl@57447
   483
  shows "emeasure lborel (box l u) = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@57447
   484
proof -
hoelzl@62975
   485
  have "(\<lambda>x. \<Prod>b\<in>Basis. indicator {l\<bullet>b <..< u\<bullet>b} (x \<bullet> b) :: ennreal) = indicator (box l u)"
hoelzl@62975
   486
    by (auto simp: fun_eq_iff box_def split: split_indicator)
hoelzl@57447
   487
  then have "emeasure lborel (box l u) = (\<integral>\<^sup>+x. (\<Prod>b\<in>Basis. indicator {l\<bullet>b <..< u\<bullet>b} (x \<bullet> b)) \<partial>lborel)"
hoelzl@57447
   488
    by simp
hoelzl@57447
   489
  also have "\<dots> = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
nipkow@64272
   490
    by (subst nn_integral_lborel_prod) (simp_all add: prod_ennreal inner_diff_left)
hoelzl@57447
   491
  finally show ?thesis .
hoelzl@40859
   492
qed
hoelzl@38656
   493
hoelzl@57447
   494
lemma emeasure_lborel_cbox_eq:
hoelzl@57447
   495
  "emeasure lborel (cbox l u) = (if \<forall>b\<in>Basis. l \<bullet> b \<le> u \<bullet> b then \<Prod>b\<in>Basis. (u - l) \<bullet> b else 0)"
hoelzl@57447
   496
  using box_eq_empty(2)[THEN iffD2, of u l] by (auto simp: not_le)
hoelzl@41654
   497
hoelzl@57447
   498
lemma emeasure_lborel_box_eq:
hoelzl@57447
   499
  "emeasure lborel (box l u) = (if \<forall>b\<in>Basis. l \<bullet> b \<le> u \<bullet> b then \<Prod>b\<in>Basis. (u - l) \<bullet> b else 0)"
hoelzl@57447
   500
  using box_eq_empty(1)[THEN iffD2, of u l] by (auto simp: not_le dest!: less_imp_le) force
hoelzl@40859
   501
hoelzl@63886
   502
lemma emeasure_lborel_singleton[simp]: "emeasure lborel {x} = 0"
hoelzl@63886
   503
  using emeasure_lborel_cbox[of x x] nonempty_Basis
lp15@66164
   504
  by (auto simp del: emeasure_lborel_cbox nonempty_Basis simp add: prod_constant)
lp15@66164
   505
lp15@66164
   506
lemma fmeasurable_cbox [iff]: "cbox a b \<in> fmeasurable lborel"
lp15@66164
   507
  and fmeasurable_box [iff]: "box a b \<in> fmeasurable lborel"
lp15@66164
   508
  by (auto simp: fmeasurable_def emeasure_lborel_box_eq emeasure_lborel_cbox_eq)
hoelzl@63886
   509
hoelzl@40859
   510
lemma
hoelzl@57447
   511
  fixes l u :: real
hoelzl@57447
   512
  assumes [simp]: "l \<le> u"
hoelzl@57447
   513
  shows measure_lborel_Icc[simp]: "measure lborel {l .. u} = u - l"
hoelzl@57447
   514
    and measure_lborel_Ico[simp]: "measure lborel {l ..< u} = u - l"
hoelzl@57447
   515
    and measure_lborel_Ioc[simp]: "measure lborel {l <.. u} = u - l"
hoelzl@57447
   516
    and measure_lborel_Ioo[simp]: "measure lborel {l <..< u} = u - l"
hoelzl@57447
   517
  by (simp_all add: measure_def)
hoelzl@40859
   518
lp15@60615
   519
lemma
hoelzl@57447
   520
  assumes [simp]: "\<And>b. b \<in> Basis \<Longrightarrow> l \<bullet> b \<le> u \<bullet> b"
hoelzl@57447
   521
  shows measure_lborel_box[simp]: "measure lborel (box l u) = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@57447
   522
    and measure_lborel_cbox[simp]: "measure lborel (cbox l u) = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
nipkow@64272
   523
  by (simp_all add: measure_def inner_diff_left prod_nonneg)
hoelzl@41654
   524
hoelzl@63886
   525
lemma measure_lborel_cbox_eq:
hoelzl@63886
   526
  "measure lborel (cbox l u) = (if \<forall>b\<in>Basis. l \<bullet> b \<le> u \<bullet> b then \<Prod>b\<in>Basis. (u - l) \<bullet> b else 0)"
hoelzl@63886
   527
  using box_eq_empty(2)[THEN iffD2, of u l] by (auto simp: not_le)
hoelzl@63886
   528
hoelzl@63886
   529
lemma measure_lborel_box_eq:
hoelzl@63886
   530
  "measure lborel (box l u) = (if \<forall>b\<in>Basis. l \<bullet> b \<le> u \<bullet> b then \<Prod>b\<in>Basis. (u - l) \<bullet> b else 0)"
hoelzl@63886
   531
  using box_eq_empty(1)[THEN iffD2, of u l] by (auto simp: not_le dest!: less_imp_le) force
hoelzl@63886
   532
hoelzl@63886
   533
lemma measure_lborel_singleton[simp]: "measure lborel {x} = 0"
hoelzl@63886
   534
  by (simp add: measure_def)
hoelzl@63886
   535
hoelzl@57447
   536
lemma sigma_finite_lborel: "sigma_finite_measure lborel"
hoelzl@57447
   537
proof
hoelzl@57447
   538
  show "\<exists>A::'a set set. countable A \<and> A \<subseteq> sets lborel \<and> \<Union>A = space lborel \<and> (\<forall>a\<in>A. emeasure lborel a \<noteq> \<infinity>)"
hoelzl@57447
   539
    by (intro exI[of _ "range (\<lambda>n::nat. box (- real n *\<^sub>R One) (real n *\<^sub>R One))"])
hoelzl@57447
   540
       (auto simp: emeasure_lborel_cbox_eq UN_box_eq_UNIV)
hoelzl@49777
   541
qed
hoelzl@40859
   542
hoelzl@57447
   543
end
hoelzl@41689
   544
hoelzl@57447
   545
lemma emeasure_lborel_UNIV: "emeasure lborel (UNIV::'a::euclidean_space set) = \<infinity>"
lp15@59741
   546
proof -
lp15@59741
   547
  { fix n::nat
lp15@59741
   548
    let ?Ba = "Basis :: 'a set"
lp15@59741
   549
    have "real n \<le> (2::real) ^ card ?Ba * real n"
lp15@59741
   550
      by (simp add: mult_le_cancel_right1)
lp15@60615
   551
    also
lp15@59741
   552
    have "... \<le> (2::real) ^ card ?Ba * real (Suc n) ^ card ?Ba"
lp15@59741
   553
      apply (rule mult_left_mono)
lp15@61609
   554
      apply (metis DIM_positive One_nat_def less_eq_Suc_le less_imp_le of_nat_le_iff of_nat_power self_le_power zero_less_Suc)
lp15@59741
   555
      apply (simp add: DIM_positive)
lp15@59741
   556
      done
lp15@59741
   557
    finally have "real n \<le> (2::real) ^ card ?Ba * real (Suc n) ^ card ?Ba" .
lp15@59741
   558
  } note [intro!] = this
lp15@59741
   559
  show ?thesis
lp15@59741
   560
    unfolding UN_box_eq_UNIV[symmetric]
lp15@59741
   561
    apply (subst SUP_emeasure_incseq[symmetric])
nipkow@64272
   562
    apply (auto simp: incseq_def subset_box inner_add_left prod_constant
hoelzl@62975
   563
      simp del: Sup_eq_top_iff SUP_eq_top_iff
hoelzl@62975
   564
      intro!: ennreal_SUP_eq_top)
lp15@60615
   565
    done
lp15@59741
   566
qed
hoelzl@40859
   567
hoelzl@57447
   568
lemma emeasure_lborel_countable:
hoelzl@57447
   569
  fixes A :: "'a::euclidean_space set"
hoelzl@57447
   570
  assumes "countable A"
hoelzl@57447
   571
  shows "emeasure lborel A = 0"
hoelzl@57447
   572
proof -
hoelzl@57447
   573
  have "A \<subseteq> (\<Union>i. {from_nat_into A i})" using from_nat_into_surj assms by force
hoelzl@63262
   574
  then have "emeasure lborel A \<le> emeasure lborel (\<Union>i. {from_nat_into A i})"
hoelzl@63262
   575
    by (intro emeasure_mono) auto
hoelzl@63262
   576
  also have "emeasure lborel (\<Union>i. {from_nat_into A i}) = 0"
hoelzl@57447
   577
    by (rule emeasure_UN_eq_0) auto
hoelzl@63262
   578
  finally show ?thesis
hoelzl@63262
   579
    by (auto simp add: )
hoelzl@40859
   580
qed
hoelzl@40859
   581
hoelzl@59425
   582
lemma countable_imp_null_set_lborel: "countable A \<Longrightarrow> A \<in> null_sets lborel"
hoelzl@59425
   583
  by (simp add: null_sets_def emeasure_lborel_countable sets.countable)
hoelzl@59425
   584
hoelzl@59425
   585
lemma finite_imp_null_set_lborel: "finite A \<Longrightarrow> A \<in> null_sets lborel"
hoelzl@59425
   586
  by (intro countable_imp_null_set_lborel countable_finite)
hoelzl@59425
   587
hoelzl@59425
   588
lemma lborel_neq_count_space[simp]: "lborel \<noteq> count_space (A::('a::ordered_euclidean_space) set)"
hoelzl@59425
   589
proof
hoelzl@59425
   590
  assume asm: "lborel = count_space A"
hoelzl@59425
   591
  have "space lborel = UNIV" by simp
hoelzl@59425
   592
  hence [simp]: "A = UNIV" by (subst (asm) asm) (simp only: space_count_space)
lp15@60615
   593
  have "emeasure lborel {undefined::'a} = 1"
hoelzl@59425
   594
      by (subst asm, subst emeasure_count_space_finite) auto
hoelzl@59425
   595
  moreover have "emeasure lborel {undefined} \<noteq> 1" by simp
hoelzl@59425
   596
  ultimately show False by contradiction
hoelzl@59425
   597
qed
hoelzl@59425
   598
immler@65204
   599
lemma mem_closed_if_AE_lebesgue_open:
immler@65204
   600
  assumes "open S" "closed C"
immler@65204
   601
  assumes "AE x \<in> S in lebesgue. x \<in> C"
immler@65204
   602
  assumes "x \<in> S"
immler@65204
   603
  shows "x \<in> C"
immler@65204
   604
proof (rule ccontr)
immler@65204
   605
  assume xC: "x \<notin> C"
immler@65204
   606
  with openE[of "S - C"] assms
immler@65204
   607
  obtain e where e: "0 < e" "ball x e \<subseteq> S - C"
immler@65204
   608
    by blast
immler@65204
   609
  then obtain a b where box: "x \<in> box a b" "box a b \<subseteq> S - C"
immler@65204
   610
    by (metis rational_boxes order_trans)
immler@65204
   611
  then have "0 < emeasure lebesgue (box a b)"
immler@65204
   612
    by (auto simp: emeasure_lborel_box_eq mem_box algebra_simps intro!: prod_pos)
immler@65204
   613
  also have "\<dots> \<le> emeasure lebesgue (S - C)"
immler@65204
   614
    using assms box
immler@65204
   615
    by (auto intro!: emeasure_mono)
immler@65204
   616
  also have "\<dots> = 0"
immler@65204
   617
    using assms
immler@65204
   618
    by (auto simp: eventually_ae_filter completion.complete2 set_diff_eq null_setsD1)
immler@65204
   619
  finally show False by simp
immler@65204
   620
qed
immler@65204
   621
immler@65204
   622
lemma mem_closed_if_AE_lebesgue: "closed C \<Longrightarrow> (AE x in lebesgue. x \<in> C) \<Longrightarrow> x \<in> C"
immler@65204
   623
  using mem_closed_if_AE_lebesgue_open[OF open_UNIV] by simp
immler@65204
   624
immler@65204
   625
wenzelm@61808
   626
subsection \<open>Affine transformation on the Lebesgue-Borel\<close>
hoelzl@49777
   627
hoelzl@49777
   628
lemma lborel_eqI:
hoelzl@57447
   629
  fixes M :: "'a::euclidean_space measure"
hoelzl@57447
   630
  assumes emeasure_eq: "\<And>l u. (\<And>b. b \<in> Basis \<Longrightarrow> l \<bullet> b \<le> u \<bullet> b) \<Longrightarrow> emeasure M (box l u) = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@49777
   631
  assumes sets_eq: "sets M = sets borel"
hoelzl@49777
   632
  shows "lborel = M"
hoelzl@57447
   633
proof (rule measure_eqI_generator_eq)
hoelzl@57447
   634
  let ?E = "range (\<lambda>(a, b). box a b::'a set)"
hoelzl@57447
   635
  show "Int_stable ?E"
hoelzl@57447
   636
    by (auto simp: Int_stable_def box_Int_box)
hoelzl@57447
   637
hoelzl@49777
   638
  show "?E \<subseteq> Pow UNIV" "sets lborel = sigma_sets UNIV ?E" "sets M = sigma_sets UNIV ?E"
hoelzl@57447
   639
    by (simp_all add: borel_eq_box sets_eq)
hoelzl@49777
   640
hoelzl@57447
   641
  let ?A = "\<lambda>n::nat. box (- (real n *\<^sub>R One)) (real n *\<^sub>R One) :: 'a set"
hoelzl@57447
   642
  show "range ?A \<subseteq> ?E" "(\<Union>i. ?A i) = UNIV"
hoelzl@57447
   643
    unfolding UN_box_eq_UNIV by auto
hoelzl@49777
   644
hoelzl@57447
   645
  { fix i show "emeasure lborel (?A i) \<noteq> \<infinity>" by auto }
hoelzl@49777
   646
  { fix X assume "X \<in> ?E" then show "emeasure lborel X = emeasure M X"
hoelzl@63886
   647
      apply (auto simp: emeasure_eq emeasure_lborel_box_eq)
hoelzl@57447
   648
      apply (subst box_eq_empty(1)[THEN iffD2])
hoelzl@57447
   649
      apply (auto intro: less_imp_le simp: not_le)
hoelzl@57447
   650
      done }
hoelzl@49777
   651
qed
hoelzl@49777
   652
hoelzl@63886
   653
lemma lborel_affine_euclidean:
hoelzl@63886
   654
  fixes c :: "'a::euclidean_space \<Rightarrow> real" and t
hoelzl@63886
   655
  defines "T x \<equiv> t + (\<Sum>j\<in>Basis. (c j * (x \<bullet> j)) *\<^sub>R j)"
hoelzl@63886
   656
  assumes c: "\<And>j. j \<in> Basis \<Longrightarrow> c j \<noteq> 0"
hoelzl@63886
   657
  shows "lborel = density (distr lborel borel T) (\<lambda>_. (\<Prod>j\<in>Basis. \<bar>c j\<bar>))" (is "_ = ?D")
hoelzl@49777
   658
proof (rule lborel_eqI)
hoelzl@57447
   659
  let ?B = "Basis :: 'a set"
hoelzl@57447
   660
  fix l u assume le: "\<And>b. b \<in> ?B \<Longrightarrow> l \<bullet> b \<le> u \<bullet> b"
hoelzl@63886
   661
  have [measurable]: "T \<in> borel \<rightarrow>\<^sub>M borel"
hoelzl@63886
   662
    by (simp add: T_def[abs_def])
hoelzl@63886
   663
  have eq: "T -` box l u = box
hoelzl@63886
   664
    (\<Sum>j\<in>Basis. (((if 0 < c j then l - t else u - t) \<bullet> j) / c j) *\<^sub>R j)
hoelzl@63886
   665
    (\<Sum>j\<in>Basis. (((if 0 < c j then u - t else l - t) \<bullet> j) / c j) *\<^sub>R j)"
hoelzl@63886
   666
    using c by (auto simp: box_def T_def field_simps inner_simps divide_less_eq)
hoelzl@63886
   667
  with le c show "emeasure ?D (box l u) = (\<Prod>b\<in>?B. (u - l) \<bullet> b)"
hoelzl@63886
   668
    by (auto simp: emeasure_density emeasure_distr nn_integral_multc emeasure_lborel_box_eq inner_simps
nipkow@64272
   669
                   field_simps divide_simps ennreal_mult'[symmetric] prod_nonneg prod.distrib[symmetric]
nipkow@64272
   670
             intro!: prod.cong)
hoelzl@49777
   671
qed simp
hoelzl@49777
   672
hoelzl@63886
   673
lemma lborel_affine:
hoelzl@63886
   674
  fixes t :: "'a::euclidean_space"
hoelzl@63886
   675
  shows "c \<noteq> 0 \<Longrightarrow> lborel = density (distr lborel borel (\<lambda>x. t + c *\<^sub>R x)) (\<lambda>_. \<bar>c\<bar>^DIM('a))"
hoelzl@63886
   676
  using lborel_affine_euclidean[where c="\<lambda>_::'a. c" and t=t]
nipkow@64272
   677
  unfolding scaleR_scaleR[symmetric] scaleR_sum_right[symmetric] euclidean_representation prod_constant by simp
hoelzl@63886
   678
hoelzl@57447
   679
lemma lborel_real_affine:
hoelzl@62975
   680
  "c \<noteq> 0 \<Longrightarrow> lborel = density (distr lborel borel (\<lambda>x. t + c * x)) (\<lambda>_. ennreal (abs c))"
hoelzl@57447
   681
  using lborel_affine[of c t] by simp
hoelzl@57447
   682
lp15@60615
   683
lemma AE_borel_affine:
hoelzl@57447
   684
  fixes P :: "real \<Rightarrow> bool"
hoelzl@57447
   685
  shows "c \<noteq> 0 \<Longrightarrow> Measurable.pred borel P \<Longrightarrow> AE x in lborel. P x \<Longrightarrow> AE x in lborel. P (t + c * x)"
hoelzl@57447
   686
  by (subst lborel_real_affine[where t="- t / c" and c="1 / c"])
hoelzl@57447
   687
     (simp_all add: AE_density AE_distr_iff field_simps)
hoelzl@57447
   688
hoelzl@56996
   689
lemma nn_integral_real_affine:
hoelzl@56993
   690
  fixes c :: real assumes [measurable]: "f \<in> borel_measurable borel" and c: "c \<noteq> 0"
hoelzl@56993
   691
  shows "(\<integral>\<^sup>+x. f x \<partial>lborel) = \<bar>c\<bar> * (\<integral>\<^sup>+x. f (t + c * x) \<partial>lborel)"
hoelzl@56993
   692
  by (subst lborel_real_affine[OF c, of t])
hoelzl@56996
   693
     (simp add: nn_integral_density nn_integral_distr nn_integral_cmult)
hoelzl@56993
   694
hoelzl@56993
   695
lemma lborel_integrable_real_affine:
hoelzl@57447
   696
  fixes f :: "real \<Rightarrow> 'a :: {banach, second_countable_topology}"
hoelzl@56993
   697
  assumes f: "integrable lborel f"
hoelzl@56993
   698
  shows "c \<noteq> 0 \<Longrightarrow> integrable lborel (\<lambda>x. f (t + c * x))"
hoelzl@56993
   699
  using f f[THEN borel_measurable_integrable] unfolding integrable_iff_bounded
hoelzl@62975
   700
  by (subst (asm) nn_integral_real_affine[where c=c and t=t]) (auto simp: ennreal_mult_less_top)
hoelzl@56993
   701
hoelzl@56993
   702
lemma lborel_integrable_real_affine_iff:
hoelzl@56993
   703
  fixes f :: "real \<Rightarrow> 'a :: {banach, second_countable_topology}"
hoelzl@56993
   704
  shows "c \<noteq> 0 \<Longrightarrow> integrable lborel (\<lambda>x. f (t + c * x)) \<longleftrightarrow> integrable lborel f"
hoelzl@56993
   705
  using
hoelzl@56993
   706
    lborel_integrable_real_affine[of f c t]
hoelzl@56993
   707
    lborel_integrable_real_affine[of "\<lambda>x. f (t + c * x)" "1/c" "-t/c"]
hoelzl@56993
   708
  by (auto simp add: field_simps)
hoelzl@56993
   709
hoelzl@56993
   710
lemma lborel_integral_real_affine:
hoelzl@56993
   711
  fixes f :: "real \<Rightarrow> 'a :: {banach, second_countable_topology}" and c :: real
hoelzl@57166
   712
  assumes c: "c \<noteq> 0" shows "(\<integral>x. f x \<partial> lborel) = \<bar>c\<bar> *\<^sub>R (\<integral>x. f (t + c * x) \<partial>lborel)"
hoelzl@57166
   713
proof cases
hoelzl@57166
   714
  assume f[measurable]: "integrable lborel f" then show ?thesis
hoelzl@57166
   715
    using c f f[THEN borel_measurable_integrable] f[THEN lborel_integrable_real_affine, of c t]
hoelzl@57447
   716
    by (subst lborel_real_affine[OF c, of t])
hoelzl@57447
   717
       (simp add: integral_density integral_distr)
hoelzl@57166
   718
next
hoelzl@57166
   719
  assume "\<not> integrable lborel f" with c show ?thesis
hoelzl@57166
   720
    by (simp add: lborel_integrable_real_affine_iff not_integrable_integral_eq)
hoelzl@57166
   721
qed
hoelzl@56993
   722
hoelzl@63958
   723
lemma
hoelzl@63958
   724
  fixes c :: "'a::euclidean_space \<Rightarrow> real" and t
hoelzl@63958
   725
  assumes c: "\<And>j. j \<in> Basis \<Longrightarrow> c j \<noteq> 0"
hoelzl@63958
   726
  defines "T == (\<lambda>x. t + (\<Sum>j\<in>Basis. (c j * (x \<bullet> j)) *\<^sub>R j))"
hoelzl@63958
   727
  shows lebesgue_affine_euclidean: "lebesgue = density (distr lebesgue lebesgue T) (\<lambda>_. (\<Prod>j\<in>Basis. \<bar>c j\<bar>))" (is "_ = ?D")
hoelzl@63958
   728
    and lebesgue_affine_measurable: "T \<in> lebesgue \<rightarrow>\<^sub>M lebesgue"
hoelzl@63958
   729
proof -
hoelzl@63958
   730
  have T_borel[measurable]: "T \<in> borel \<rightarrow>\<^sub>M borel"
hoelzl@63958
   731
    by (auto simp: T_def[abs_def])
hoelzl@63958
   732
  { fix A :: "'a set" assume A: "A \<in> sets borel"
hoelzl@63958
   733
    then have "emeasure lborel A = 0 \<longleftrightarrow> emeasure (density (distr lborel borel T) (\<lambda>_. (\<Prod>j\<in>Basis. \<bar>c j\<bar>))) A = 0"
hoelzl@63958
   734
      unfolding T_def using c by (subst lborel_affine_euclidean[symmetric]) auto
hoelzl@63958
   735
    also have "\<dots> \<longleftrightarrow> emeasure (distr lebesgue lborel T) A = 0"
nipkow@64272
   736
      using A c by (simp add: distr_completion emeasure_density nn_integral_cmult prod_nonneg cong: distr_cong)
hoelzl@63958
   737
    finally have "emeasure lborel A = 0 \<longleftrightarrow> emeasure (distr lebesgue lborel T) A = 0" . }
hoelzl@63958
   738
  then have eq: "null_sets lborel = null_sets (distr lebesgue lborel T)"
hoelzl@63958
   739
    by (auto simp: null_sets_def)
hoelzl@63958
   740
hoelzl@63958
   741
  show "T \<in> lebesgue \<rightarrow>\<^sub>M lebesgue"
hoelzl@63958
   742
    by (rule completion.measurable_completion2) (auto simp: eq measurable_completion)
hoelzl@63958
   743
hoelzl@63958
   744
  have "lebesgue = completion (density (distr lborel borel T) (\<lambda>_. (\<Prod>j\<in>Basis. \<bar>c j\<bar>)))"
hoelzl@63958
   745
    using c by (subst lborel_affine_euclidean[of c t]) (simp_all add: T_def[abs_def])
hoelzl@63958
   746
  also have "\<dots> = density (completion (distr lebesgue lborel T)) (\<lambda>_. (\<Prod>j\<in>Basis. \<bar>c j\<bar>))"
nipkow@64272
   747
    using c by (auto intro!: always_eventually prod_pos completion_density_eq simp: distr_completion cong: distr_cong)
hoelzl@63958
   748
  also have "\<dots> = density (distr lebesgue lebesgue T) (\<lambda>_. (\<Prod>j\<in>Basis. \<bar>c j\<bar>))"
hoelzl@63958
   749
    by (subst completion.completion_distr_eq) (auto simp: eq measurable_completion)
hoelzl@63958
   750
  finally show "lebesgue = density (distr lebesgue lebesgue T) (\<lambda>_. (\<Prod>j\<in>Basis. \<bar>c j\<bar>))" .
hoelzl@63958
   751
qed
hoelzl@63958
   752
nipkow@67399
   753
lemma lebesgue_measurable_scaling[measurable]: "( *\<^sub>R) x \<in> lebesgue \<rightarrow>\<^sub>M lebesgue"
hoelzl@63959
   754
proof cases
hoelzl@63959
   755
  assume "x = 0"
nipkow@67399
   756
  then have "( *\<^sub>R) x = (\<lambda>x. 0::'a)"
hoelzl@63959
   757
    by (auto simp: fun_eq_iff)
hoelzl@63959
   758
  then show ?thesis by auto
hoelzl@63959
   759
next
hoelzl@63959
   760
  assume "x \<noteq> 0" then show ?thesis
hoelzl@63959
   761
    using lebesgue_affine_measurable[of "\<lambda>_. x" 0]
nipkow@64267
   762
    unfolding scaleR_scaleR[symmetric] scaleR_sum_right[symmetric] euclidean_representation
hoelzl@63959
   763
    by (auto simp add: ac_simps)
hoelzl@63959
   764
qed
hoelzl@63959
   765
hoelzl@63958
   766
lemma
hoelzl@63958
   767
  fixes m :: real and \<delta> :: "'a::euclidean_space"
hoelzl@63958
   768
  defines "T r d x \<equiv> r *\<^sub>R x + d"
hoelzl@63958
   769
  shows emeasure_lebesgue_affine: "emeasure lebesgue (T m \<delta> ` S) = \<bar>m\<bar> ^ DIM('a) * emeasure lebesgue S" (is ?e)
hoelzl@63958
   770
    and measure_lebesgue_affine: "measure lebesgue (T m \<delta> ` S) = \<bar>m\<bar> ^ DIM('a) * measure lebesgue S" (is ?m)
hoelzl@63958
   771
proof -
hoelzl@63958
   772
  show ?e
hoelzl@63958
   773
  proof cases
hoelzl@63958
   774
    assume "m = 0" then show ?thesis
hoelzl@63958
   775
      by (simp add: image_constant_conv T_def[abs_def])
hoelzl@63958
   776
  next
hoelzl@63958
   777
    let ?T = "T m \<delta>" and ?T' = "T (1 / m) (- ((1/m) *\<^sub>R \<delta>))"
hoelzl@63958
   778
    assume "m \<noteq> 0"
hoelzl@63958
   779
    then have s_comp_s: "?T' \<circ> ?T = id" "?T \<circ> ?T' = id"
hoelzl@63958
   780
      by (auto simp: T_def[abs_def] fun_eq_iff scaleR_add_right scaleR_diff_right)
hoelzl@63958
   781
    then have "inv ?T' = ?T" "bij ?T'"
hoelzl@63958
   782
      by (auto intro: inv_unique_comp o_bij)
hoelzl@63958
   783
    then have eq: "T m \<delta> ` S = T (1 / m) ((-1/m) *\<^sub>R \<delta>) -` S \<inter> space lebesgue"
hoelzl@63958
   784
      using bij_vimage_eq_inv_image[OF \<open>bij ?T'\<close>, of S] by auto
hoelzl@63958
   785
hoelzl@63958
   786
    have trans_eq_T: "(\<lambda>x. \<delta> + (\<Sum>j\<in>Basis. (m * (x \<bullet> j)) *\<^sub>R j)) = T m \<delta>" for m \<delta>
nipkow@64267
   787
      unfolding T_def[abs_def] scaleR_scaleR[symmetric] scaleR_sum_right[symmetric]
hoelzl@63958
   788
      by (auto simp add: euclidean_representation ac_simps)
hoelzl@63958
   789
hoelzl@63958
   790
    have T[measurable]: "T r d \<in> lebesgue \<rightarrow>\<^sub>M lebesgue" for r d
hoelzl@63958
   791
      using lebesgue_affine_measurable[of "\<lambda>_. r" d]
hoelzl@63958
   792
      by (cases "r = 0") (auto simp: trans_eq_T T_def[abs_def])
hoelzl@63958
   793
hoelzl@63958
   794
    show ?thesis
hoelzl@63958
   795
    proof cases
hoelzl@63958
   796
      assume "S \<in> sets lebesgue" with \<open>m \<noteq> 0\<close> show ?thesis
hoelzl@63958
   797
        unfolding eq
hoelzl@63958
   798
        apply (subst lebesgue_affine_euclidean[of "\<lambda>_. m" \<delta>])
hoelzl@63958
   799
        apply (simp_all add: emeasure_density trans_eq_T nn_integral_cmult emeasure_distr
hoelzl@63958
   800
                        del: space_completion emeasure_completion)
nipkow@64272
   801
        apply (simp add: vimage_comp s_comp_s prod_constant)
hoelzl@63958
   802
        done
hoelzl@63958
   803
    next
hoelzl@63958
   804
      assume "S \<notin> sets lebesgue"
hoelzl@63958
   805
      moreover have "?T ` S \<notin> sets lebesgue"
hoelzl@63958
   806
      proof
hoelzl@63958
   807
        assume "?T ` S \<in> sets lebesgue"
hoelzl@63958
   808
        then have "?T -` (?T ` S) \<inter> space lebesgue \<in> sets lebesgue"
hoelzl@63958
   809
          by (rule measurable_sets[OF T])
hoelzl@63958
   810
        also have "?T -` (?T ` S) \<inter> space lebesgue = S"
hoelzl@63958
   811
          by (simp add: vimage_comp s_comp_s eq)
hoelzl@63958
   812
        finally show False using \<open>S \<notin> sets lebesgue\<close> by auto
hoelzl@63958
   813
      qed
hoelzl@63958
   814
      ultimately show ?thesis
hoelzl@63958
   815
        by (simp add: emeasure_notin_sets)
hoelzl@63958
   816
    qed
hoelzl@63958
   817
  qed
hoelzl@63958
   818
  show ?m
nipkow@64272
   819
    unfolding measure_def \<open>?e\<close> by (simp add: enn2real_mult prod_nonneg)
hoelzl@63958
   820
qed
hoelzl@63958
   821
eberlm@67135
   822
lemma lebesgue_real_scale:
eberlm@67135
   823
  assumes "c \<noteq> 0"
eberlm@67135
   824
  shows   "lebesgue = density (distr lebesgue lebesgue (\<lambda>x. c * x)) (\<lambda>x. ennreal \<bar>c\<bar>)"
eberlm@67135
   825
  using assms by (subst lebesgue_affine_euclidean[of "\<lambda>_. c" 0]) simp_all
eberlm@67135
   826
lp15@60615
   827
lemma divideR_right:
hoelzl@56993
   828
  fixes x y :: "'a::real_normed_vector"
hoelzl@56993
   829
  shows "r \<noteq> 0 \<Longrightarrow> y = x /\<^sub>R r \<longleftrightarrow> r *\<^sub>R y = x"
hoelzl@56993
   830
  using scaleR_cancel_left[of r y "x /\<^sub>R r"] by simp
hoelzl@56993
   831
hoelzl@56993
   832
lemma lborel_has_bochner_integral_real_affine_iff:
hoelzl@56993
   833
  fixes x :: "'a :: {banach, second_countable_topology}"
hoelzl@56993
   834
  shows "c \<noteq> 0 \<Longrightarrow>
hoelzl@56993
   835
    has_bochner_integral lborel f x \<longleftrightarrow>
hoelzl@56993
   836
    has_bochner_integral lborel (\<lambda>x. f (t + c * x)) (x /\<^sub>R \<bar>c\<bar>)"
hoelzl@56993
   837
  unfolding has_bochner_integral_iff lborel_integrable_real_affine_iff
hoelzl@56993
   838
  by (simp_all add: lborel_integral_real_affine[symmetric] divideR_right cong: conj_cong)
hoelzl@49777
   839
hoelzl@59425
   840
lemma lborel_distr_uminus: "distr lborel borel uminus = (lborel :: real measure)"
lp15@60615
   841
  by (subst lborel_real_affine[of "-1" 0])
hoelzl@62975
   842
     (auto simp: density_1 one_ennreal_def[symmetric])
hoelzl@59425
   843
lp15@60615
   844
lemma lborel_distr_mult:
hoelzl@59425
   845
  assumes "(c::real) \<noteq> 0"
nipkow@67399
   846
  shows "distr lborel borel (( * ) c) = density lborel (\<lambda>_. inverse \<bar>c\<bar>)"
hoelzl@59425
   847
proof-
nipkow@67399
   848
  have "distr lborel borel (( * ) c) = distr lborel lborel (( * ) c)" by (simp cong: distr_cong)
hoelzl@59425
   849
  also from assms have "... = density lborel (\<lambda>_. inverse \<bar>c\<bar>)"
hoelzl@59425
   850
    by (subst lborel_real_affine[of "inverse c" 0]) (auto simp: o_def distr_density_distr)
hoelzl@59425
   851
  finally show ?thesis .
hoelzl@59425
   852
qed
hoelzl@59425
   853
lp15@60615
   854
lemma lborel_distr_mult':
hoelzl@59425
   855
  assumes "(c::real) \<noteq> 0"
nipkow@67399
   856
  shows "lborel = density (distr lborel borel (( * ) c)) (\<lambda>_. \<bar>c\<bar>)"
hoelzl@59425
   857
proof-
hoelzl@59425
   858
  have "lborel = density lborel (\<lambda>_. 1)" by (rule density_1[symmetric])
hoelzl@62975
   859
  also from assms have "(\<lambda>_. 1 :: ennreal) = (\<lambda>_. inverse \<bar>c\<bar> * \<bar>c\<bar>)" by (intro ext) simp
wenzelm@61945
   860
  also have "density lborel ... = density (density lborel (\<lambda>_. inverse \<bar>c\<bar>)) (\<lambda>_. \<bar>c\<bar>)"
hoelzl@62975
   861
    by (subst density_density_eq) (auto simp: ennreal_mult)
nipkow@67399
   862
  also from assms have "density lborel (\<lambda>_. inverse \<bar>c\<bar>) = distr lborel borel (( * ) c)"
hoelzl@59425
   863
    by (rule lborel_distr_mult[symmetric])
hoelzl@59425
   864
  finally show ?thesis .
hoelzl@59425
   865
qed
hoelzl@59425
   866
nipkow@67399
   867
lemma lborel_distr_plus: "distr lborel borel ((+) c) = (lborel :: real measure)"
hoelzl@62975
   868
  by (subst lborel_real_affine[of 1 c]) (auto simp: density_1 one_ennreal_def[symmetric])
hoelzl@59425
   869
wenzelm@61605
   870
interpretation lborel: sigma_finite_measure lborel
hoelzl@57447
   871
  by (rule sigma_finite_lborel)
hoelzl@57447
   872
hoelzl@57447
   873
interpretation lborel_pair: pair_sigma_finite lborel lborel ..
hoelzl@57447
   874
hoelzl@59425
   875
lemma lborel_prod:
hoelzl@59425
   876
  "lborel \<Otimes>\<^sub>M lborel = (lborel :: ('a::euclidean_space \<times> 'b::euclidean_space) measure)"
hoelzl@59425
   877
proof (rule lborel_eqI[symmetric], clarify)
hoelzl@59425
   878
  fix la ua :: 'a and lb ub :: 'b
hoelzl@59425
   879
  assume lu: "\<And>a b. (a, b) \<in> Basis \<Longrightarrow> (la, lb) \<bullet> (a, b) \<le> (ua, ub) \<bullet> (a, b)"
hoelzl@59425
   880
  have [simp]:
hoelzl@59425
   881
    "\<And>b. b \<in> Basis \<Longrightarrow> la \<bullet> b \<le> ua \<bullet> b"
hoelzl@59425
   882
    "\<And>b. b \<in> Basis \<Longrightarrow> lb \<bullet> b \<le> ub \<bullet> b"
hoelzl@59425
   883
    "inj_on (\<lambda>u. (u, 0)) Basis" "inj_on (\<lambda>u. (0, u)) Basis"
hoelzl@59425
   884
    "(\<lambda>u. (u, 0)) ` Basis \<inter> (\<lambda>u. (0, u)) ` Basis = {}"
hoelzl@59425
   885
    "box (la, lb) (ua, ub) = box la ua \<times> box lb ub"
hoelzl@59425
   886
    using lu[of _ 0] lu[of 0] by (auto intro!: inj_onI simp add: Basis_prod_def ball_Un box_def)
hoelzl@59425
   887
  show "emeasure (lborel \<Otimes>\<^sub>M lborel) (box (la, lb) (ua, ub)) =
nipkow@67399
   888
      ennreal (prod ((\<bullet>) ((ua, ub) - (la, lb))) Basis)"
nipkow@64272
   889
    by (simp add: lborel.emeasure_pair_measure_Times Basis_prod_def prod.union_disjoint
nipkow@64272
   890
                  prod.reindex ennreal_mult inner_diff_left prod_nonneg)
hoelzl@59425
   891
qed (simp add: borel_prod[symmetric])
hoelzl@59425
   892
hoelzl@57447
   893
(* FIXME: conversion in measurable prover *)
hoelzl@57447
   894
lemma lborelD_Collect[measurable (raw)]: "{x\<in>space borel. P x} \<in> sets borel \<Longrightarrow> {x\<in>space lborel. P x} \<in> sets lborel" by simp
hoelzl@57447
   895
lemma lborelD[measurable (raw)]: "A \<in> sets borel \<Longrightarrow> A \<in> sets lborel" by simp
hoelzl@57447
   896
hoelzl@57138
   897
lemma emeasure_bounded_finite:
hoelzl@57138
   898
  assumes "bounded A" shows "emeasure lborel A < \<infinity>"
hoelzl@57138
   899
proof -
wenzelm@61808
   900
  from bounded_subset_cbox[OF \<open>bounded A\<close>] obtain a b where "A \<subseteq> cbox a b"
hoelzl@57138
   901
    by auto
hoelzl@57138
   902
  then have "emeasure lborel A \<le> emeasure lborel (cbox a b)"
hoelzl@57138
   903
    by (intro emeasure_mono) auto
hoelzl@57138
   904
  then show ?thesis
nipkow@64272
   905
    by (auto simp: emeasure_lborel_cbox_eq prod_nonneg less_top[symmetric] top_unique split: if_split_asm)
hoelzl@57138
   906
qed
hoelzl@57138
   907
hoelzl@57138
   908
lemma emeasure_compact_finite: "compact A \<Longrightarrow> emeasure lborel A < \<infinity>"
hoelzl@57138
   909
  using emeasure_bounded_finite[of A] by (auto intro: compact_imp_bounded)
hoelzl@57138
   910
hoelzl@57138
   911
lemma borel_integrable_compact:
hoelzl@57447
   912
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::{banach, second_countable_topology}"
hoelzl@57138
   913
  assumes "compact S" "continuous_on S f"
hoelzl@57138
   914
  shows "integrable lborel (\<lambda>x. indicator S x *\<^sub>R f x)"
hoelzl@57138
   915
proof cases
hoelzl@57138
   916
  assume "S \<noteq> {}"
hoelzl@57138
   917
  have "continuous_on S (\<lambda>x. norm (f x))"
hoelzl@57138
   918
    using assms by (intro continuous_intros)
wenzelm@61808
   919
  from continuous_attains_sup[OF \<open>compact S\<close> \<open>S \<noteq> {}\<close> this]
hoelzl@57138
   920
  obtain M where M: "\<And>x. x \<in> S \<Longrightarrow> norm (f x) \<le> M"
hoelzl@57138
   921
    by auto
hoelzl@57138
   922
hoelzl@57138
   923
  show ?thesis
hoelzl@57138
   924
  proof (rule integrable_bound)
hoelzl@57138
   925
    show "integrable lborel (\<lambda>x. indicator S x * M)"
hoelzl@57138
   926
      using assms by (auto intro!: emeasure_compact_finite borel_compact integrable_mult_left)
hoelzl@57138
   927
    show "(\<lambda>x. indicator S x *\<^sub>R f x) \<in> borel_measurable lborel"
hoelzl@57138
   928
      using assms by (auto intro!: borel_measurable_continuous_on_indicator borel_compact)
hoelzl@57138
   929
    show "AE x in lborel. norm (indicator S x *\<^sub>R f x) \<le> norm (indicator S x * M)"
hoelzl@57138
   930
      by (auto split: split_indicator simp: abs_real_def dest!: M)
hoelzl@57138
   931
  qed
hoelzl@57138
   932
qed simp
hoelzl@57138
   933
hoelzl@50418
   934
lemma borel_integrable_atLeastAtMost:
hoelzl@56993
   935
  fixes f :: "real \<Rightarrow> real"
hoelzl@50418
   936
  assumes f: "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> isCont f x"
hoelzl@50418
   937
  shows "integrable lborel (\<lambda>x. f x * indicator {a .. b} x)" (is "integrable _ ?f")
hoelzl@57138
   938
proof -
hoelzl@57138
   939
  have "integrable lborel (\<lambda>x. indicator {a .. b} x *\<^sub>R f x)"
hoelzl@57138
   940
  proof (rule borel_integrable_compact)
hoelzl@57138
   941
    from f show "continuous_on {a..b} f"
hoelzl@57138
   942
      by (auto intro: continuous_at_imp_continuous_on)
hoelzl@57138
   943
  qed simp
hoelzl@57138
   944
  then show ?thesis
haftmann@57512
   945
    by (auto simp: mult.commute)
hoelzl@57138
   946
qed
hoelzl@50418
   947
hoelzl@63958
   948
abbreviation lmeasurable :: "'a::euclidean_space set set"
hoelzl@63958
   949
where
hoelzl@63958
   950
  "lmeasurable \<equiv> fmeasurable lebesgue"
hoelzl@63958
   951
hoelzl@63958
   952
lemma lmeasurable_iff_integrable:
hoelzl@63958
   953
  "S \<in> lmeasurable \<longleftrightarrow> integrable lebesgue (indicator S :: 'a::euclidean_space \<Rightarrow> real)"
hoelzl@63958
   954
  by (auto simp: fmeasurable_def integrable_iff_bounded borel_measurable_indicator_iff ennreal_indicator)
hoelzl@63958
   955
hoelzl@63958
   956
lemma lmeasurable_cbox [iff]: "cbox a b \<in> lmeasurable"
hoelzl@63958
   957
  and lmeasurable_box [iff]: "box a b \<in> lmeasurable"
hoelzl@63958
   958
  by (auto simp: fmeasurable_def emeasure_lborel_box_eq emeasure_lborel_cbox_eq)
hoelzl@63958
   959
hoelzl@63959
   960
lemma lmeasurable_compact: "compact S \<Longrightarrow> S \<in> lmeasurable"
hoelzl@63959
   961
  using emeasure_compact_finite[of S] by (intro fmeasurableI) (auto simp: borel_compact)
hoelzl@63959
   962
hoelzl@63959
   963
lemma lmeasurable_open: "bounded S \<Longrightarrow> open S \<Longrightarrow> S \<in> lmeasurable"
hoelzl@63959
   964
  using emeasure_bounded_finite[of S] by (intro fmeasurableI) (auto simp: borel_open)
hoelzl@63959
   965
hoelzl@63959
   966
lemma lmeasurable_ball: "ball a r \<in> lmeasurable"
hoelzl@63959
   967
  by (simp add: lmeasurable_open)
hoelzl@63959
   968
hoelzl@63959
   969
lemma lmeasurable_interior: "bounded S \<Longrightarrow> interior S \<in> lmeasurable"
hoelzl@63959
   970
  by (simp add: bounded_interior lmeasurable_open)
hoelzl@63959
   971
hoelzl@63959
   972
lemma null_sets_cbox_Diff_box: "cbox a b - box a b \<in> null_sets lborel"
hoelzl@63959
   973
proof -
hoelzl@63959
   974
  have "emeasure lborel (cbox a b - box a b) = 0"
hoelzl@63959
   975
    by (subst emeasure_Diff) (auto simp: emeasure_lborel_cbox_eq emeasure_lborel_box_eq box_subset_cbox)
hoelzl@63959
   976
  then have "cbox a b - box a b \<in> null_sets lborel"
hoelzl@63959
   977
    by (auto simp: null_sets_def)
hoelzl@63959
   978
  then show ?thesis
hoelzl@63959
   979
    by (auto dest!: AE_not_in)
hoelzl@63959
   980
qed
hoelzl@63959
   981
subsection\<open> A nice lemma for negligibility proofs.\<close>
hoelzl@63959
   982
hoelzl@63959
   983
lemma summable_iff_suminf_neq_top: "(\<And>n. f n \<ge> 0) \<Longrightarrow> \<not> summable f \<Longrightarrow> (\<Sum>i. ennreal (f i)) = top"
hoelzl@63959
   984
  by (metis summable_suminf_not_top)
hoelzl@63959
   985
hoelzl@63959
   986
proposition starlike_negligible_bounded_gmeasurable:
hoelzl@63959
   987
  fixes S :: "'a :: euclidean_space set"
hoelzl@63959
   988
  assumes S: "S \<in> sets lebesgue" and "bounded S"
hoelzl@63959
   989
      and eq1: "\<And>c x. \<lbrakk>(c *\<^sub>R x) \<in> S; 0 \<le> c; x \<in> S\<rbrakk> \<Longrightarrow> c = 1"
hoelzl@63959
   990
    shows "S \<in> null_sets lebesgue"
hoelzl@63959
   991
proof -
hoelzl@63959
   992
  obtain M where "0 < M" "S \<subseteq> ball 0 M"
hoelzl@63959
   993
    using \<open>bounded S\<close> by (auto dest: bounded_subset_ballD)
hoelzl@63959
   994
hoelzl@63959
   995
  let ?f = "\<lambda>n. root DIM('a) (Suc n)"
hoelzl@63959
   996
nipkow@67399
   997
  have vimage_eq_image: "( *\<^sub>R) (?f n) -` S = ( *\<^sub>R) (1 / ?f n) ` S" for n
hoelzl@63959
   998
    apply safe
hoelzl@63959
   999
    subgoal for x by (rule image_eqI[of _ _ "?f n *\<^sub>R x"]) auto
hoelzl@63959
  1000
    subgoal by auto
hoelzl@63959
  1001
    done
hoelzl@63959
  1002
hoelzl@63959
  1003
  have eq: "(1 / ?f n) ^ DIM('a) = 1 / Suc n" for n
hoelzl@63959
  1004
    by (simp add: field_simps)
hoelzl@63959
  1005
hoelzl@63959
  1006
  { fix n x assume x: "root DIM('a) (1 + real n) *\<^sub>R x \<in> S"
hoelzl@63959
  1007
    have "1 * norm x \<le> root DIM('a) (1 + real n) * norm x"
hoelzl@63959
  1008
      by (rule mult_mono) auto
hoelzl@63959
  1009
    also have "\<dots> < M"
hoelzl@63959
  1010
      using x \<open>S \<subseteq> ball 0 M\<close> by auto
hoelzl@63959
  1011
    finally have "norm x < M" by simp }
hoelzl@63959
  1012
  note less_M = this
hoelzl@63959
  1013
hoelzl@63959
  1014
  have "(\<Sum>n. ennreal (1 / Suc n)) = top"
hoelzl@63959
  1015
    using not_summable_harmonic[where 'a=real] summable_Suc_iff[where f="\<lambda>n. 1 / (real n)"]
hoelzl@63959
  1016
    by (intro summable_iff_suminf_neq_top) (auto simp add: inverse_eq_divide)
hoelzl@63959
  1017
  then have "top * emeasure lebesgue S = (\<Sum>n. (1 / ?f n)^DIM('a) * emeasure lebesgue S)"
hoelzl@63959
  1018
    unfolding ennreal_suminf_multc eq by simp
nipkow@67399
  1019
  also have "\<dots> = (\<Sum>n. emeasure lebesgue (( *\<^sub>R) (?f n) -` S))"
hoelzl@63959
  1020
    unfolding vimage_eq_image using emeasure_lebesgue_affine[of "1 / ?f n" 0 S for n] by simp
nipkow@67399
  1021
  also have "\<dots> = emeasure lebesgue (\<Union>n. ( *\<^sub>R) (?f n) -` S)"
hoelzl@63959
  1022
  proof (intro suminf_emeasure)
nipkow@67399
  1023
    show "disjoint_family (\<lambda>n. ( *\<^sub>R) (?f n) -` S)"
hoelzl@63959
  1024
      unfolding disjoint_family_on_def
hoelzl@63959
  1025
    proof safe
hoelzl@63959
  1026
      fix m n :: nat and x assume "m \<noteq> n" "?f m *\<^sub>R x \<in> S" "?f n *\<^sub>R x \<in> S"
hoelzl@63959
  1027
      with eq1[of "?f m / ?f n" "?f n *\<^sub>R x"] show "x \<in> {}"
hoelzl@63959
  1028
        by auto
hoelzl@63959
  1029
    qed
nipkow@67399
  1030
    have "( *\<^sub>R) (?f i) -` S \<in> sets lebesgue" for i
hoelzl@63959
  1031
      using measurable_sets[OF lebesgue_measurable_scaling[of "?f i"] S] by auto
nipkow@67399
  1032
    then show "range (\<lambda>i. ( *\<^sub>R) (?f i) -` S) \<subseteq> sets lebesgue"
hoelzl@63959
  1033
      by auto
hoelzl@63959
  1034
  qed
hoelzl@63959
  1035
  also have "\<dots> \<le> emeasure lebesgue (ball 0 M :: 'a set)"
hoelzl@63959
  1036
    using less_M by (intro emeasure_mono) auto
hoelzl@63959
  1037
  also have "\<dots> < top"
hoelzl@63959
  1038
    using lmeasurable_ball by (auto simp: fmeasurable_def)
hoelzl@63959
  1039
  finally have "emeasure lebesgue S = 0"
hoelzl@63959
  1040
    by (simp add: ennreal_top_mult split: if_split_asm)
hoelzl@63959
  1041
  then show "S \<in> null_sets lebesgue"
hoelzl@63959
  1042
    unfolding null_sets_def using \<open>S \<in> sets lebesgue\<close> by auto
hoelzl@63959
  1043
qed
hoelzl@63959
  1044
hoelzl@63959
  1045
corollary starlike_negligible_compact:
hoelzl@63959
  1046
  "compact S \<Longrightarrow> (\<And>c x. \<lbrakk>(c *\<^sub>R x) \<in> S; 0 \<le> c; x \<in> S\<rbrakk> \<Longrightarrow> c = 1) \<Longrightarrow> S \<in> null_sets lebesgue"
hoelzl@63959
  1047
  using starlike_negligible_bounded_gmeasurable[of S] by (auto simp: compact_eq_bounded_closed)
hoelzl@63959
  1048
hoelzl@63968
  1049
lemma outer_regular_lborel:
hoelzl@63968
  1050
  assumes B: "B \<in> fmeasurable lborel" "0 < (e::real)"
hoelzl@63968
  1051
  shows "\<exists>U. open U \<and> B \<subseteq> U \<and> emeasure lborel U \<le> emeasure lborel B + e"
hoelzl@63968
  1052
proof -
hoelzl@63968
  1053
  let ?\<mu> = "emeasure lborel"
hoelzl@63968
  1054
  let ?B = "\<lambda>n::nat. ball 0 n :: 'a set"
hoelzl@63968
  1055
  have B[measurable]: "B \<in> sets borel"
hoelzl@63968
  1056
    using B by auto
hoelzl@63968
  1057
  let ?e = "\<lambda>n. e*((1/2)^Suc n)"
hoelzl@63968
  1058
  have "\<forall>n. \<exists>U. open U \<and> ?B n \<inter> B \<subseteq> U \<and> ?\<mu> (U - B) < ?e n"
hoelzl@63968
  1059
  proof
hoelzl@63968
  1060
    fix n :: nat
hoelzl@63968
  1061
    let ?A = "density lborel (indicator (?B n))"
hoelzl@63968
  1062
    have emeasure_A: "X \<in> sets borel \<Longrightarrow> emeasure ?A X = ?\<mu> (?B n \<inter> X)" for X
hoelzl@63968
  1063
      by (auto simp add: emeasure_density borel_measurable_indicator indicator_inter_arith[symmetric])
hoelzl@63968
  1064
hoelzl@63968
  1065
    have finite_A: "emeasure ?A (space ?A) \<noteq> \<infinity>"
hoelzl@63968
  1066
      using emeasure_bounded_finite[of "?B n"] by (auto simp add: emeasure_A)
hoelzl@63968
  1067
    interpret A: finite_measure ?A
hoelzl@63968
  1068
      by rule fact
hoelzl@63968
  1069
    have "emeasure ?A B + ?e n > (INF U:{U. B \<subseteq> U \<and> open U}. emeasure ?A U)"
hoelzl@63968
  1070
      using \<open>0<e\<close> by (auto simp: outer_regular[OF _ finite_A B, symmetric])
hoelzl@63968
  1071
    then obtain U where U: "B \<subseteq> U" "open U" "?\<mu> (?B n \<inter> B) + ?e n > ?\<mu> (?B n \<inter> U)"
hoelzl@63968
  1072
      unfolding INF_less_iff by (auto simp: emeasure_A)
hoelzl@63968
  1073
    moreover
hoelzl@63968
  1074
    { have "?\<mu> ((?B n \<inter> U) - B) = ?\<mu> ((?B n \<inter> U) - (?B n \<inter> B))"
hoelzl@63968
  1075
        using U by (intro arg_cong[where f="?\<mu>"]) auto
hoelzl@63968
  1076
      also have "\<dots> = ?\<mu> (?B n \<inter> U) - ?\<mu> (?B n \<inter> B)"
hoelzl@63968
  1077
        using U A.emeasure_finite[of B]
hoelzl@63968
  1078
        by (intro emeasure_Diff) (auto simp del: A.emeasure_finite simp: emeasure_A)
hoelzl@63968
  1079
      also have "\<dots> < ?e n"
hoelzl@63968
  1080
        using U(1,2,3) A.emeasure_finite[of B]
hoelzl@63968
  1081
        by (subst minus_less_iff_ennreal)
hoelzl@63968
  1082
          (auto simp del: A.emeasure_finite simp: emeasure_A less_top ac_simps intro!: emeasure_mono)
hoelzl@63968
  1083
      finally have "?\<mu> ((?B n \<inter> U) - B) < ?e n" . }
hoelzl@63968
  1084
    ultimately show "\<exists>U. open U \<and> ?B n \<inter> B \<subseteq> U \<and> ?\<mu> (U - B) < ?e n"
hoelzl@63968
  1085
      by (intro exI[of _ "?B n \<inter> U"]) auto
hoelzl@63968
  1086
  qed
hoelzl@63968
  1087
  then obtain U
hoelzl@63968
  1088
    where U: "\<And>n. open (U n)" "\<And>n. ?B n \<inter> B \<subseteq> U n" "\<And>n. ?\<mu> (U n - B) < ?e n"
hoelzl@63968
  1089
    by metis
hoelzl@63968
  1090
  then show ?thesis
hoelzl@63968
  1091
  proof (intro exI conjI)
hoelzl@63968
  1092
    { fix x assume "x \<in> B"
hoelzl@63968
  1093
      moreover
hoelzl@63968
  1094
      have "\<exists>n. norm x < real n"
hoelzl@63968
  1095
        by (simp add: reals_Archimedean2)
hoelzl@63968
  1096
      then guess n ..
hoelzl@63968
  1097
      ultimately have "x \<in> (\<Union>n. U n)"
hoelzl@63968
  1098
        using U(2)[of n] by auto }
hoelzl@63968
  1099
    note * = this
hoelzl@63968
  1100
    then show "open (\<Union>n. U n)" "B \<subseteq> (\<Union>n. U n)"
hoelzl@63968
  1101
      using U(1,2) by auto
hoelzl@63968
  1102
    have "?\<mu> (\<Union>n. U n) = ?\<mu> (B \<union> (\<Union>n. U n - B))"
hoelzl@63968
  1103
      using * U(2) by (intro arg_cong[where ?f="?\<mu>"]) auto
hoelzl@63968
  1104
    also have "\<dots> = ?\<mu> B + ?\<mu> (\<Union>n. U n - B)"
hoelzl@63968
  1105
      using U(1) by (intro plus_emeasure[symmetric]) auto
hoelzl@63968
  1106
    also have "\<dots> \<le> ?\<mu> B + (\<Sum>n. ?\<mu> (U n - B))"
hoelzl@63968
  1107
      using U(1) by (intro add_mono emeasure_subadditive_countably) auto
hoelzl@63968
  1108
    also have "\<dots> \<le> ?\<mu> B + (\<Sum>n. ennreal (?e n))"
hoelzl@63968
  1109
      using U(3) by (intro add_mono suminf_le) (auto intro: less_imp_le)
hoelzl@63968
  1110
    also have "(\<Sum>n. ennreal (?e n)) = ennreal (e * 1)"
hoelzl@63968
  1111
      using \<open>0<e\<close> by (intro suminf_ennreal_eq sums_mult power_half_series) auto
hoelzl@63968
  1112
    finally show "emeasure lborel (\<Union>n. U n) \<le> emeasure lborel B + ennreal e"
hoelzl@63968
  1113
      by simp
hoelzl@63968
  1114
  qed
hoelzl@63968
  1115
qed
hoelzl@63968
  1116
hoelzl@63968
  1117
lemma lmeasurable_outer_open:
hoelzl@63968
  1118
  assumes S: "S \<in> lmeasurable" and "0 < e"
hoelzl@63968
  1119
  obtains T where "open T" "S \<subseteq> T" "T \<in> lmeasurable" "measure lebesgue T \<le> measure lebesgue S + e"
hoelzl@63968
  1120
proof -
hoelzl@63968
  1121
  obtain S' where S': "S \<subseteq> S'" "S' \<in> sets borel" "emeasure lborel S' = emeasure lebesgue S"
hoelzl@63968
  1122
    using completion_upper[of S lborel] S by auto
hoelzl@63968
  1123
  then have f_S': "S' \<in> fmeasurable lborel"
hoelzl@63968
  1124
    using S by (auto simp: fmeasurable_def)
hoelzl@63968
  1125
  from outer_regular_lborel[OF this \<open>0<e\<close>] guess U .. note U = this
hoelzl@63968
  1126
  show thesis
hoelzl@63968
  1127
  proof (rule that)
hoelzl@63968
  1128
    show "open U" "S \<subseteq> U" "U \<in> lmeasurable"
hoelzl@63968
  1129
      using f_S' U S' by (auto simp: fmeasurable_def less_top[symmetric] top_unique)
hoelzl@63968
  1130
    then have "U \<in> fmeasurable lborel"
hoelzl@63968
  1131
      by (auto simp: fmeasurable_def)
hoelzl@63968
  1132
    with S U \<open>0<e\<close> show "measure lebesgue U \<le> measure lebesgue S + e"
hoelzl@63968
  1133
      unfolding S'(3) by (simp add: emeasure_eq_measure2 ennreal_plus[symmetric] del: ennreal_plus)
hoelzl@63968
  1134
  qed
hoelzl@63968
  1135
qed
hoelzl@63968
  1136
hoelzl@38656
  1137
end