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