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