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