src/HOL/Analysis/Lebesgue_Measure.thy
author hoelzl
Fri Sep 16 13:56:51 2016 +0200 (2016-09-16)
changeset 63886 685fb01256af
parent 63627 6ddb43c6b711
child 63918 6bf55e6e0b75
permissions -rw-r--r--
move Henstock-Kurzweil integration after Lebesgue_Measure; replace content by abbreviation measure lborel
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@57447
    11
  imports Finite_Product_Measure Bochner_Integration Caratheodory
hoelzl@38656
    12
begin
hoelzl@38656
    13
wenzelm@61808
    14
subsection \<open>Every right continuous and nondecreasing function gives rise to a measure\<close>
hoelzl@57447
    15
hoelzl@57447
    16
definition interval_measure :: "(real \<Rightarrow> real) \<Rightarrow> real measure" where
hoelzl@62975
    17
  "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
    18
hoelzl@57447
    19
lemma emeasure_interval_measure_Ioc:
hoelzl@57447
    20
  assumes "a \<le> b"
hoelzl@57447
    21
  assumes mono_F: "\<And>x y. x \<le> y \<Longrightarrow> F x \<le> F y"
lp15@60615
    22
  assumes right_cont_F : "\<And>a. continuous (at_right a) F"
hoelzl@57447
    23
  shows "emeasure (interval_measure F) {a <.. b} = F b - F a"
wenzelm@61808
    24
proof (rule extend_measure_caratheodory_pair[OF interval_measure_def \<open>a \<le> b\<close>])
hoelzl@57447
    25
  show "semiring_of_sets UNIV {{a<..b} |a b :: real. a \<le> b}"
hoelzl@57447
    26
  proof (unfold_locales, safe)
hoelzl@57447
    27
    fix a b c d :: real assume *: "a \<le> b" "c \<le> d"
hoelzl@57447
    28
    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
    29
    proof cases
hoelzl@57447
    30
      let ?C = "{{a<..b}}"
hoelzl@57447
    31
      assume "b < c \<or> d \<le> a \<or> d \<le> c"
hoelzl@57447
    32
      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
    33
        by (auto simp add: disjoint_def)
hoelzl@57447
    34
      thus ?thesis ..
hoelzl@57447
    35
    next
hoelzl@57447
    36
      let ?C = "{{a<..c}, {d<..b}}"
hoelzl@57447
    37
      assume "\<not> (b < c \<or> d \<le> a \<or> d \<le> c)"
hoelzl@57447
    38
      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
    39
        by (auto simp add: disjoint_def Ioc_inj) (metis linear)+
hoelzl@57447
    40
      thus ?thesis ..
hoelzl@57447
    41
    qed
hoelzl@57447
    42
  qed (auto simp: Ioc_inj, metis linear)
hoelzl@57447
    43
next
hoelzl@57447
    44
  fix l r :: "nat \<Rightarrow> real" and a b :: real
lp15@60615
    45
  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
    46
  assume lr_eq_ab: "(\<Union>i. {l i<..r i}) = {a<..b}"
hoelzl@57447
    47
lp15@61762
    48
  have [intro, simp]: "\<And>a b. a \<le> b \<Longrightarrow> F a \<le> F b"
lp15@61762
    49
    by (auto intro!: l_r mono_F)
hoelzl@57447
    50
hoelzl@57447
    51
  { fix S :: "nat set" assume "finite S"
wenzelm@61808
    52
    moreover note \<open>a \<le> b\<close>
hoelzl@57447
    53
    moreover have "\<And>i. i \<in> S \<Longrightarrow> {l i <.. r i} \<subseteq> {a <.. b}"
hoelzl@57447
    54
      unfolding lr_eq_ab[symmetric] by auto
hoelzl@57447
    55
    ultimately have "(\<Sum>i\<in>S. F (r i) - F (l i)) \<le> F b - F a"
hoelzl@57447
    56
    proof (induction S arbitrary: a rule: finite_psubset_induct)
hoelzl@57447
    57
      case (psubset S)
hoelzl@57447
    58
      show ?case
hoelzl@57447
    59
      proof cases
hoelzl@57447
    60
        assume "\<exists>i\<in>S. l i < r i"
wenzelm@61808
    61
        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
    62
          by (intro Min_in) auto
hoelzl@57447
    63
        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
    64
          by fastforce
hoelzl@50104
    65
hoelzl@57447
    66
        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))"
hoelzl@57447
    67
          using m psubset by (intro setsum.remove) auto
hoelzl@57447
    68
        also have "(\<Sum>i\<in>S - {m}. F (r i) - F (l i)) \<le> F b - F (r m)"
hoelzl@57447
    69
        proof (intro psubset.IH)
hoelzl@57447
    70
          show "S - {m} \<subset> S"
wenzelm@61808
    71
            using \<open>m\<in>S\<close> by auto
hoelzl@57447
    72
          show "r m \<le> b"
wenzelm@61808
    73
            using psubset.prems(2)[OF \<open>m\<in>S\<close>] \<open>l m < r m\<close> by auto
hoelzl@57447
    74
        next
hoelzl@57447
    75
          fix i assume "i \<in> S - {m}"
hoelzl@57447
    76
          then have i: "i \<in> S" "i \<noteq> m" by auto
hoelzl@57447
    77
          { assume i': "l i < r i" "l i < r m"
wenzelm@63540
    78
            with \<open>finite S\<close> i m have "l m \<le> l i"
hoelzl@57447
    79
              by auto
wenzelm@63540
    80
            with i' have "{l i <.. r i} \<inter> {l m <.. r m} \<noteq> {}"
hoelzl@57447
    81
              by auto
hoelzl@57447
    82
            then have False
hoelzl@57447
    83
              using disjoint_family_onD[OF disj, of i m] i by auto }
hoelzl@57447
    84
          then have "l i \<noteq> r i \<Longrightarrow> r m \<le> l i"
hoelzl@57447
    85
            unfolding not_less[symmetric] using l_r[of i] by auto
hoelzl@57447
    86
          then show "{l i <.. r i} \<subseteq> {r m <.. b}"
wenzelm@61808
    87
            using psubset.prems(2)[OF \<open>i\<in>S\<close>] by auto
hoelzl@57447
    88
        qed
hoelzl@57447
    89
        also have "F (r m) - F (l m) \<le> F (r m) - F a"
wenzelm@61808
    90
          using psubset.prems(2)[OF \<open>m \<in> S\<close>] \<open>l m < r m\<close>
hoelzl@57447
    91
          by (auto simp add: Ioc_subset_iff intro!: mono_F)
hoelzl@57447
    92
        finally show ?case
hoelzl@57447
    93
          by (auto intro: add_mono)
wenzelm@61808
    94
      qed (auto simp add: \<open>a \<le> b\<close> less_le)
hoelzl@57447
    95
    qed }
hoelzl@57447
    96
  note claim1 = this
hoelzl@57447
    97
hoelzl@57447
    98
  (* second key induction: a lower bound on the measures of any finite collection of Ai's
hoelzl@57447
    99
     that cover an interval {u..v} *)
hoelzl@57447
   100
hoelzl@57447
   101
  { fix S u v and l r :: "nat \<Rightarrow> real"
hoelzl@57447
   102
    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
   103
    then have "F v - F u \<le> (\<Sum>i\<in>S. F (r i) - F (l i))"
hoelzl@57447
   104
    proof (induction arbitrary: v u rule: finite_psubset_induct)
hoelzl@57447
   105
      case (psubset S)
hoelzl@57447
   106
      show ?case
hoelzl@57447
   107
      proof cases
hoelzl@57447
   108
        assume "S = {}" then show ?case
hoelzl@57447
   109
          using psubset by (simp add: mono_F)
hoelzl@57447
   110
      next
hoelzl@57447
   111
        assume "S \<noteq> {}"
hoelzl@57447
   112
        then obtain j where "j \<in> S"
hoelzl@57447
   113
          by auto
hoelzl@47694
   114
hoelzl@57447
   115
        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
   116
        show ?case
hoelzl@57447
   117
        proof cases
hoelzl@57447
   118
          assume "?R"
wenzelm@61808
   119
          with \<open>j \<in> S\<close> psubset.prems have "{u..v} \<subseteq> (\<Union>i\<in>S-{j}. {l i<..< r i})"
hoelzl@57447
   120
            apply (auto simp: subset_eq Ball_def)
hoelzl@57447
   121
            apply (metis Diff_iff less_le_trans leD linear singletonD)
hoelzl@57447
   122
            apply (metis Diff_iff less_le_trans leD linear singletonD)
hoelzl@57447
   123
            apply (metis order_trans less_le_not_le linear)
hoelzl@57447
   124
            done
wenzelm@61808
   125
          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
   126
            by (intro psubset) auto
hoelzl@57447
   127
          also have "\<dots> \<le> (\<Sum>i\<in>S. F (r i) - F (l i))"
hoelzl@57447
   128
            using psubset.prems
hoelzl@57447
   129
            by (intro setsum_mono2 psubset) (auto intro: less_imp_le)
hoelzl@57447
   130
          finally show ?thesis .
hoelzl@57447
   131
        next
hoelzl@57447
   132
          assume "\<not> ?R"
hoelzl@57447
   133
          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
   134
            by (auto simp: not_less)
hoelzl@57447
   135
          let ?S1 = "{i \<in> S. l i < l j}"
hoelzl@57447
   136
          let ?S2 = "{i \<in> S. r i > r j}"
hoelzl@40859
   137
hoelzl@57447
   138
          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
   139
            using \<open>j \<in> S\<close> \<open>finite S\<close> psubset.prems j
hoelzl@57447
   140
            by (intro setsum_mono2) (auto intro: less_imp_le)
hoelzl@57447
   141
          also have "(\<Sum>i\<in>?S1 \<union> ?S2 \<union> {j}. F (r i) - F (l i)) =
hoelzl@57447
   142
            (\<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
   143
            using psubset(1) psubset.prems(1) j
hoelzl@57447
   144
            apply (subst setsum.union_disjoint)
hoelzl@57447
   145
            apply simp_all
hoelzl@57447
   146
            apply (subst setsum.union_disjoint)
hoelzl@57447
   147
            apply auto
hoelzl@57447
   148
            apply (metis less_le_not_le)
hoelzl@57447
   149
            done
hoelzl@57447
   150
          also (xtrans) have "(\<Sum>i\<in>?S1. F (r i) - F (l i)) \<ge> F (l j) - F u"
wenzelm@61808
   151
            using \<open>j \<in> S\<close> \<open>finite S\<close> psubset.prems j
hoelzl@57447
   152
            apply (intro psubset.IH psubset)
hoelzl@57447
   153
            apply (auto simp: subset_eq Ball_def)
hoelzl@57447
   154
            apply (metis less_le_trans not_le)
hoelzl@57447
   155
            done
hoelzl@57447
   156
          also (xtrans) have "(\<Sum>i\<in>?S2. F (r i) - F (l i)) \<ge> F v - F (r j)"
wenzelm@61808
   157
            using \<open>j \<in> S\<close> \<open>finite S\<close> psubset.prems j
hoelzl@57447
   158
            apply (intro psubset.IH psubset)
hoelzl@57447
   159
            apply (auto simp: subset_eq Ball_def)
hoelzl@57447
   160
            apply (metis le_less_trans not_le)
hoelzl@57447
   161
            done
hoelzl@57447
   162
          finally (xtrans) show ?case
hoelzl@57447
   163
            by (auto simp: add_mono)
hoelzl@57447
   164
        qed
hoelzl@57447
   165
      qed
hoelzl@57447
   166
    qed }
hoelzl@57447
   167
  note claim2 = this
hoelzl@49777
   168
hoelzl@57447
   169
  (* now prove the inequality going the other way *)
hoelzl@62975
   170
  have "ennreal (F b - F a) \<le> (\<Sum>i. ennreal (F (r i) - F (l i)))"
hoelzl@62975
   171
  proof (rule ennreal_le_epsilon)
hoelzl@62975
   172
    fix epsilon :: real assume egt0: "epsilon > 0"
hoelzl@62975
   173
    have "\<forall>i. \<exists>d>0. F (r i + d) < F (r i) + epsilon / 2^(i+2)"
lp15@60615
   174
    proof
hoelzl@57447
   175
      fix i
hoelzl@57447
   176
      note right_cont_F [of "r i"]
hoelzl@62975
   177
      thus "\<exists>d>0. F (r i + d) < F (r i) + epsilon / 2^(i+2)"
hoelzl@57447
   178
        apply -
hoelzl@57447
   179
        apply (subst (asm) continuous_at_right_real_increasing)
hoelzl@57447
   180
        apply (rule mono_F, assumption)
hoelzl@57447
   181
        apply (drule_tac x = "epsilon / 2 ^ (i + 2)" in spec)
hoelzl@57447
   182
        apply (erule impE)
hoelzl@57447
   183
        using egt0 by (auto simp add: field_simps)
hoelzl@57447
   184
    qed
lp15@60615
   185
    then obtain delta where
hoelzl@57447
   186
        deltai_gt0: "\<And>i. delta i > 0" and
hoelzl@57447
   187
        deltai_prop: "\<And>i. F (r i + delta i) < F (r i) + epsilon / 2^(i+2)"
hoelzl@57447
   188
      by metis
hoelzl@57447
   189
    have "\<exists>a' > a. F a' - F a < epsilon / 2"
hoelzl@57447
   190
      apply (insert right_cont_F [of a])
hoelzl@57447
   191
      apply (subst (asm) continuous_at_right_real_increasing)
hoelzl@57447
   192
      using mono_F apply force
hoelzl@57447
   193
      apply (drule_tac x = "epsilon / 2" in spec)
haftmann@59554
   194
      using egt0 unfolding mult.commute [of 2] by force
lp15@60615
   195
    then obtain a' where a'lea [arith]: "a' > a" and
hoelzl@57447
   196
      a_prop: "F a' - F a < epsilon / 2"
hoelzl@57447
   197
      by auto
wenzelm@63040
   198
    define S' where "S' = {i. l i < r i}"
lp15@60615
   199
    obtain S :: "nat set" where
lp15@60615
   200
      "S \<subseteq> S'" and finS: "finite S" and
hoelzl@57447
   201
      Sprop: "{a'..b} \<subseteq> (\<Union>i \<in> S. {l i<..<r i + delta i})"
hoelzl@57447
   202
    proof (rule compactE_image)
hoelzl@57447
   203
      show "compact {a'..b}"
hoelzl@57447
   204
        by (rule compact_Icc)
hoelzl@57447
   205
      show "\<forall>i \<in> S'. open ({l i<..<r i + delta i})" by auto
hoelzl@57447
   206
      have "{a'..b} \<subseteq> {a <.. b}"
hoelzl@57447
   207
        by auto
hoelzl@57447
   208
      also have "{a <.. b} = (\<Union>i\<in>S'. {l i<..r i})"
hoelzl@57447
   209
        unfolding lr_eq_ab[symmetric] by (fastforce simp add: S'_def intro: less_le_trans)
hoelzl@57447
   210
      also have "\<dots> \<subseteq> (\<Union>i \<in> S'. {l i<..<r i + delta i})"
hoelzl@57447
   211
        apply (intro UN_mono)
hoelzl@57447
   212
        apply (auto simp: S'_def)
hoelzl@57447
   213
        apply (cut_tac i=i in deltai_gt0)
hoelzl@57447
   214
        apply simp
hoelzl@57447
   215
        done
hoelzl@57447
   216
      finally show "{a'..b} \<subseteq> (\<Union>i \<in> S'. {l i<..<r i + delta i})" .
hoelzl@57447
   217
    qed
hoelzl@57447
   218
    with S'_def have Sprop2: "\<And>i. i \<in> S \<Longrightarrow> l i < r i" by auto
lp15@60615
   219
    from finS have "\<exists>n. \<forall>i \<in> S. i \<le> n"
hoelzl@57447
   220
      by (subst finite_nat_set_iff_bounded_le [symmetric])
hoelzl@57447
   221
    then obtain n where Sbound [rule_format]: "\<forall>i \<in> S. i \<le> n" ..
hoelzl@57447
   222
    have "F b - F a' \<le> (\<Sum>i\<in>S. F (r i + delta i) - F (l i))"
hoelzl@57447
   223
      apply (rule claim2 [rule_format])
hoelzl@57447
   224
      using finS Sprop apply auto
hoelzl@57447
   225
      apply (frule Sprop2)
hoelzl@57447
   226
      apply (subgoal_tac "delta i > 0")
hoelzl@57447
   227
      apply arith
hoelzl@57447
   228
      by (rule deltai_gt0)
wenzelm@61954
   229
    also have "... \<le> (\<Sum>i \<in> S. F(r i) - F(l i) + epsilon / 2^(i+2))"
hoelzl@57447
   230
      apply (rule setsum_mono)
hoelzl@57447
   231
      apply simp
hoelzl@57447
   232
      apply (rule order_trans)
hoelzl@57447
   233
      apply (rule less_imp_le)
hoelzl@57447
   234
      apply (rule deltai_prop)
hoelzl@57447
   235
      by auto
wenzelm@61954
   236
    also have "... = (\<Sum>i \<in> S. F(r i) - F(l i)) +
wenzelm@61954
   237
        (epsilon / 4) * (\<Sum>i \<in> S. (1 / 2)^i)" (is "_ = ?t + _")
hoelzl@57447
   238
      by (subst setsum.distrib) (simp add: field_simps setsum_right_distrib)
hoelzl@57447
   239
    also have "... \<le> ?t + (epsilon / 4) * (\<Sum> i < Suc n. (1 / 2)^i)"
hoelzl@57447
   240
      apply (rule add_left_mono)
hoelzl@57447
   241
      apply (rule mult_left_mono)
hoelzl@57447
   242
      apply (rule setsum_mono2)
lp15@60615
   243
      using egt0 apply auto
hoelzl@57447
   244
      by (frule Sbound, auto)
hoelzl@57447
   245
    also have "... \<le> ?t + (epsilon / 2)"
hoelzl@57447
   246
      apply (rule add_left_mono)
hoelzl@57447
   247
      apply (subst geometric_sum)
hoelzl@57447
   248
      apply auto
hoelzl@57447
   249
      apply (rule mult_left_mono)
hoelzl@57447
   250
      using egt0 apply auto
hoelzl@57447
   251
      done
hoelzl@57447
   252
    finally have aux2: "F b - F a' \<le> (\<Sum>i\<in>S. F (r i) - F (l i)) + epsilon / 2"
hoelzl@57447
   253
      by simp
hoelzl@50526
   254
hoelzl@57447
   255
    have "F b - F a = (F b - F a') + (F a' - F a)"
hoelzl@57447
   256
      by auto
hoelzl@57447
   257
    also have "... \<le> (F b - F a') + epsilon / 2"
hoelzl@57447
   258
      using a_prop by (intro add_left_mono) simp
hoelzl@57447
   259
    also have "... \<le> (\<Sum>i\<in>S. F (r i) - F (l i)) + epsilon / 2 + epsilon / 2"
hoelzl@57447
   260
      apply (intro add_right_mono)
hoelzl@57447
   261
      apply (rule aux2)
hoelzl@57447
   262
      done
hoelzl@57447
   263
    also have "... = (\<Sum>i\<in>S. F (r i) - F (l i)) + epsilon"
hoelzl@57447
   264
      by auto
hoelzl@57447
   265
    also have "... \<le> (\<Sum>i\<le>n. F (r i) - F (l i)) + epsilon"
hoelzl@57447
   266
      using finS Sbound Sprop by (auto intro!: add_right_mono setsum_mono3)
hoelzl@62975
   267
    finally have "ennreal (F b - F a) \<le> (\<Sum>i\<le>n. ennreal (F (r i) - F (l i))) + epsilon"
hoelzl@62975
   268
      using egt0 by (simp add: ennreal_plus[symmetric] setsum_nonneg del: ennreal_plus)
hoelzl@62975
   269
    then show "ennreal (F b - F a) \<le> (\<Sum>i. ennreal (F (r i) - F (l i))) + (epsilon :: real)"
hoelzl@62975
   270
      by (rule order_trans) (auto intro!: add_mono setsum_le_suminf simp del: setsum_ennreal)
hoelzl@62975
   271
  qed
hoelzl@62975
   272
  moreover have "(\<Sum>i. ennreal (F (r i) - F (l i))) \<le> ennreal (F b - F a)"
hoelzl@62975
   273
    using \<open>a \<le> b\<close> by (auto intro!: suminf_le_const ennreal_le_iff[THEN iffD2] claim1)
hoelzl@62975
   274
  ultimately show "(\<Sum>n. ennreal (F (r n) - F (l n))) = ennreal (F b - F a)"
hoelzl@62975
   275
    by (rule antisym[rotated])
lp15@61762
   276
qed (auto simp: Ioc_inj mono_F)
hoelzl@38656
   277
hoelzl@57447
   278
lemma measure_interval_measure_Ioc:
hoelzl@57447
   279
  assumes "a \<le> b"
hoelzl@57447
   280
  assumes mono_F: "\<And>x y. x \<le> y \<Longrightarrow> F x \<le> F y"
lp15@60615
   281
  assumes right_cont_F : "\<And>a. continuous (at_right a) F"
hoelzl@57447
   282
  shows "measure (interval_measure F) {a <.. b} = F b - F a"
hoelzl@57447
   283
  unfolding measure_def
hoelzl@57447
   284
  apply (subst emeasure_interval_measure_Ioc)
hoelzl@57447
   285
  apply fact+
hoelzl@62975
   286
  apply (simp add: assms)
hoelzl@57447
   287
  done
hoelzl@57447
   288
hoelzl@57447
   289
lemma emeasure_interval_measure_Ioc_eq:
hoelzl@57447
   290
  "(\<And>x y. x \<le> y \<Longrightarrow> F x \<le> F y) \<Longrightarrow> (\<And>a. continuous (at_right a) F) \<Longrightarrow>
hoelzl@57447
   291
    emeasure (interval_measure F) {a <.. b} = (if a \<le> b then F b - F a else 0)"
hoelzl@57447
   292
  using emeasure_interval_measure_Ioc[of a b F] by auto
hoelzl@57447
   293
hoelzl@59048
   294
lemma sets_interval_measure [simp, measurable_cong]: "sets (interval_measure F) = sets borel"
hoelzl@57447
   295
  apply (simp add: sets_extend_measure interval_measure_def borel_sigma_sets_Ioc)
hoelzl@57447
   296
  apply (rule sigma_sets_eqI)
hoelzl@57447
   297
  apply auto
hoelzl@57447
   298
  apply (case_tac "a \<le> ba")
hoelzl@57447
   299
  apply (auto intro: sigma_sets.Empty)
hoelzl@57447
   300
  done
hoelzl@57447
   301
hoelzl@57447
   302
lemma space_interval_measure [simp]: "space (interval_measure F) = UNIV"
hoelzl@57447
   303
  by (simp add: interval_measure_def space_extend_measure)
hoelzl@57447
   304
hoelzl@57447
   305
lemma emeasure_interval_measure_Icc:
hoelzl@57447
   306
  assumes "a \<le> b"
hoelzl@57447
   307
  assumes mono_F: "\<And>x y. x \<le> y \<Longrightarrow> F x \<le> F y"
lp15@60615
   308
  assumes cont_F : "continuous_on UNIV F"
hoelzl@57447
   309
  shows "emeasure (interval_measure F) {a .. b} = F b - F a"
hoelzl@57447
   310
proof (rule tendsto_unique)
hoelzl@57447
   311
  { fix a b :: real assume "a \<le> b" then have "emeasure (interval_measure F) {a <.. b} = F b - F a"
hoelzl@57447
   312
      using cont_F
hoelzl@57447
   313
      by (subst emeasure_interval_measure_Ioc)
hoelzl@57447
   314
         (auto intro: mono_F continuous_within_subset simp: continuous_on_eq_continuous_within) }
hoelzl@57447
   315
  note * = this
hoelzl@38656
   316
hoelzl@57447
   317
  let ?F = "interval_measure F"
wenzelm@61973
   318
  show "((\<lambda>a. F b - F a) \<longlongrightarrow> emeasure ?F {a..b}) (at_left a)"
hoelzl@57447
   319
  proof (rule tendsto_at_left_sequentially)
hoelzl@57447
   320
    show "a - 1 < a" by simp
wenzelm@61969
   321
    fix X assume "\<And>n. X n < a" "incseq X" "X \<longlonglongrightarrow> a"
wenzelm@61969
   322
    with \<open>a \<le> b\<close> have "(\<lambda>n. emeasure ?F {X n<..b}) \<longlonglongrightarrow> emeasure ?F (\<Inter>n. {X n <..b})"
hoelzl@57447
   323
      apply (intro Lim_emeasure_decseq)
hoelzl@57447
   324
      apply (auto simp: decseq_def incseq_def emeasure_interval_measure_Ioc *)
hoelzl@57447
   325
      apply force
hoelzl@57447
   326
      apply (subst (asm ) *)
hoelzl@57447
   327
      apply (auto intro: less_le_trans less_imp_le)
hoelzl@57447
   328
      done
hoelzl@57447
   329
    also have "(\<Inter>n. {X n <..b}) = {a..b}"
wenzelm@61808
   330
      using \<open>\<And>n. X n < a\<close>
hoelzl@57447
   331
      apply auto
wenzelm@61969
   332
      apply (rule LIMSEQ_le_const2[OF \<open>X \<longlonglongrightarrow> a\<close>])
hoelzl@57447
   333
      apply (auto intro: less_imp_le)
hoelzl@57447
   334
      apply (auto intro: less_le_trans)
hoelzl@57447
   335
      done
hoelzl@57447
   336
    also have "(\<lambda>n. emeasure ?F {X n<..b}) = (\<lambda>n. F b - F (X n))"
wenzelm@61808
   337
      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
   338
    finally show "(\<lambda>n. F b - F (X n)) \<longlonglongrightarrow> emeasure ?F {a..b}" .
hoelzl@57447
   339
  qed
hoelzl@62975
   340
  show "((\<lambda>a. ennreal (F b - F a)) \<longlongrightarrow> F b - F a) (at_left a)"
hoelzl@62975
   341
    by (rule continuous_on_tendsto_compose[where g="\<lambda>x. x" and s=UNIV])
hoelzl@62975
   342
       (auto simp: continuous_on_ennreal continuous_on_diff cont_F continuous_on_const)
hoelzl@57447
   343
qed (rule trivial_limit_at_left_real)
lp15@60615
   344
hoelzl@57447
   345
lemma sigma_finite_interval_measure:
hoelzl@57447
   346
  assumes mono_F: "\<And>x y. x \<le> y \<Longrightarrow> F x \<le> F y"
lp15@60615
   347
  assumes right_cont_F : "\<And>a. continuous (at_right a) F"
hoelzl@57447
   348
  shows "sigma_finite_measure (interval_measure F)"
hoelzl@57447
   349
  apply unfold_locales
hoelzl@57447
   350
  apply (intro exI[of _ "(\<lambda>(a, b). {a <.. b}) ` (\<rat> \<times> \<rat>)"])
hoelzl@57447
   351
  apply (auto intro!: Rats_no_top_le Rats_no_bot_less countable_rat simp: emeasure_interval_measure_Ioc_eq[OF assms])
hoelzl@57447
   352
  done
hoelzl@57447
   353
wenzelm@61808
   354
subsection \<open>Lebesgue-Borel measure\<close>
hoelzl@57447
   355
hoelzl@57447
   356
definition lborel :: "('a :: euclidean_space) measure" where
hoelzl@57447
   357
  "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
   358
lp15@60615
   359
lemma
hoelzl@59048
   360
  shows sets_lborel[simp, measurable_cong]: "sets lborel = sets borel"
hoelzl@57447
   361
    and space_lborel[simp]: "space lborel = space borel"
hoelzl@57447
   362
    and measurable_lborel1[simp]: "measurable M lborel = measurable M borel"
hoelzl@57447
   363
    and measurable_lborel2[simp]: "measurable lborel M = measurable borel M"
hoelzl@57447
   364
  by (simp_all add: lborel_def)
hoelzl@57447
   365
hoelzl@57447
   366
context
hoelzl@57447
   367
begin
hoelzl@57447
   368
hoelzl@57447
   369
interpretation sigma_finite_measure "interval_measure (\<lambda>x. x)"
hoelzl@57447
   370
  by (rule sigma_finite_interval_measure) auto
hoelzl@57447
   371
interpretation finite_product_sigma_finite "\<lambda>_. interval_measure (\<lambda>x. x)" Basis
hoelzl@57447
   372
  proof qed simp
hoelzl@57447
   373
hoelzl@57447
   374
lemma lborel_eq_real: "lborel = interval_measure (\<lambda>x. x)"
hoelzl@57447
   375
  unfolding lborel_def Basis_real_def
hoelzl@57447
   376
  using distr_id[of "interval_measure (\<lambda>x. x)"]
hoelzl@57447
   377
  by (subst distr_component[symmetric])
hoelzl@57447
   378
     (simp_all add: distr_distr comp_def del: distr_id cong: distr_cong)
hoelzl@57447
   379
hoelzl@57447
   380
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
   381
  by (subst lborel_def) (simp add: lborel_eq_real)
hoelzl@57447
   382
hoelzl@57447
   383
lemma nn_integral_lborel_setprod:
hoelzl@57447
   384
  assumes [measurable]: "\<And>b. b \<in> Basis \<Longrightarrow> f b \<in> borel_measurable borel"
hoelzl@57447
   385
  assumes nn[simp]: "\<And>b x. b \<in> Basis \<Longrightarrow> 0 \<le> f b x"
hoelzl@57447
   386
  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))"
hoelzl@57447
   387
  by (simp add: lborel_def nn_integral_distr product_nn_integral_setprod
hoelzl@57447
   388
                product_nn_integral_singleton)
hoelzl@57447
   389
lp15@60615
   390
lemma emeasure_lborel_Icc[simp]:
hoelzl@57447
   391
  fixes l u :: real
hoelzl@57447
   392
  assumes [simp]: "l \<le> u"
hoelzl@57447
   393
  shows "emeasure lborel {l .. u} = u - l"
hoelzl@50526
   394
proof -
hoelzl@57447
   395
  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
   396
    by (auto simp: space_PiM)
hoelzl@57447
   397
  then show ?thesis
hoelzl@57447
   398
    by (simp add: lborel_def emeasure_distr emeasure_PiM emeasure_interval_measure_Icc continuous_on_id)
hoelzl@50104
   399
qed
hoelzl@50104
   400
hoelzl@62975
   401
lemma emeasure_lborel_Icc_eq: "emeasure lborel {l .. u} = ennreal (if l \<le> u then u - l else 0)"
hoelzl@57447
   402
  by simp
hoelzl@47694
   403
hoelzl@57447
   404
lemma emeasure_lborel_cbox[simp]:
hoelzl@57447
   405
  assumes [simp]: "\<And>b. b \<in> Basis \<Longrightarrow> l \<bullet> b \<le> u \<bullet> b"
hoelzl@57447
   406
  shows "emeasure lborel (cbox l u) = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@41654
   407
proof -
hoelzl@62975
   408
  have "(\<lambda>x. \<Prod>b\<in>Basis. indicator {l\<bullet>b .. u\<bullet>b} (x \<bullet> b) :: ennreal) = indicator (cbox l u)"
hoelzl@62975
   409
    by (auto simp: fun_eq_iff cbox_def split: split_indicator)
hoelzl@57447
   410
  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
   411
    by simp
hoelzl@57447
   412
  also have "\<dots> = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@62975
   413
    by (subst nn_integral_lborel_setprod) (simp_all add: setprod_ennreal inner_diff_left)
hoelzl@47694
   414
  finally show ?thesis .
hoelzl@38656
   415
qed
hoelzl@38656
   416
hoelzl@57447
   417
lemma AE_lborel_singleton: "AE x in lborel::'a::euclidean_space measure. x \<noteq> c"
hoelzl@62975
   418
  using SOME_Basis AE_discrete_difference [of "{c}" lborel] emeasure_lborel_cbox [of c c]
hoelzl@62975
   419
  by (auto simp add: cbox_sing setprod_constant power_0_left)
hoelzl@47757
   420
hoelzl@57447
   421
lemma emeasure_lborel_Ioo[simp]:
hoelzl@57447
   422
  assumes [simp]: "l \<le> u"
hoelzl@62975
   423
  shows "emeasure lborel {l <..< u} = ennreal (u - l)"
hoelzl@40859
   424
proof -
hoelzl@57447
   425
  have "emeasure lborel {l <..< u} = emeasure lborel {l .. u}"
hoelzl@57447
   426
    using AE_lborel_singleton[of u] AE_lborel_singleton[of l] by (intro emeasure_eq_AE) auto
hoelzl@47694
   427
  then show ?thesis
hoelzl@57447
   428
    by simp
hoelzl@41981
   429
qed
hoelzl@38656
   430
hoelzl@57447
   431
lemma emeasure_lborel_Ioc[simp]:
hoelzl@57447
   432
  assumes [simp]: "l \<le> u"
hoelzl@62975
   433
  shows "emeasure lborel {l <.. u} = ennreal (u - l)"
hoelzl@41654
   434
proof -
hoelzl@57447
   435
  have "emeasure lborel {l <.. u} = emeasure lborel {l .. u}"
hoelzl@57447
   436
    using AE_lborel_singleton[of u] AE_lborel_singleton[of l] by (intro emeasure_eq_AE) auto
hoelzl@57447
   437
  then show ?thesis
hoelzl@57447
   438
    by simp
hoelzl@38656
   439
qed
hoelzl@38656
   440
hoelzl@57447
   441
lemma emeasure_lborel_Ico[simp]:
hoelzl@57447
   442
  assumes [simp]: "l \<le> u"
hoelzl@62975
   443
  shows "emeasure lborel {l ..< u} = ennreal (u - l)"
hoelzl@57447
   444
proof -
hoelzl@57447
   445
  have "emeasure lborel {l ..< u} = emeasure lborel {l .. u}"
hoelzl@57447
   446
    using AE_lborel_singleton[of u] AE_lborel_singleton[of l] by (intro emeasure_eq_AE) auto
hoelzl@57447
   447
  then show ?thesis
hoelzl@57447
   448
    by simp
hoelzl@38656
   449
qed
hoelzl@38656
   450
hoelzl@57447
   451
lemma emeasure_lborel_box[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 (box l u) = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@57447
   454
proof -
hoelzl@62975
   455
  have "(\<lambda>x. \<Prod>b\<in>Basis. indicator {l\<bullet>b <..< u\<bullet>b} (x \<bullet> b) :: ennreal) = indicator (box l u)"
hoelzl@62975
   456
    by (auto simp: fun_eq_iff box_def split: split_indicator)
hoelzl@57447
   457
  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
   458
    by simp
hoelzl@57447
   459
  also have "\<dots> = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@62975
   460
    by (subst nn_integral_lborel_setprod) (simp_all add: setprod_ennreal inner_diff_left)
hoelzl@57447
   461
  finally show ?thesis .
hoelzl@40859
   462
qed
hoelzl@38656
   463
hoelzl@57447
   464
lemma emeasure_lborel_cbox_eq:
hoelzl@57447
   465
  "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
   466
  using box_eq_empty(2)[THEN iffD2, of u l] by (auto simp: not_le)
hoelzl@41654
   467
hoelzl@57447
   468
lemma emeasure_lborel_box_eq:
hoelzl@57447
   469
  "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
   470
  using box_eq_empty(1)[THEN iffD2, of u l] by (auto simp: not_le dest!: less_imp_le) force
hoelzl@40859
   471
hoelzl@63886
   472
lemma emeasure_lborel_singleton[simp]: "emeasure lborel {x} = 0"
hoelzl@63886
   473
  using emeasure_lborel_cbox[of x x] nonempty_Basis
hoelzl@63886
   474
  by (auto simp del: emeasure_lborel_cbox nonempty_Basis simp add: cbox_sing setprod_constant)
hoelzl@63886
   475
hoelzl@40859
   476
lemma
hoelzl@57447
   477
  fixes l u :: real
hoelzl@57447
   478
  assumes [simp]: "l \<le> u"
hoelzl@57447
   479
  shows measure_lborel_Icc[simp]: "measure lborel {l .. u} = u - l"
hoelzl@57447
   480
    and measure_lborel_Ico[simp]: "measure lborel {l ..< u} = u - l"
hoelzl@57447
   481
    and measure_lborel_Ioc[simp]: "measure lborel {l <.. u} = u - l"
hoelzl@57447
   482
    and measure_lborel_Ioo[simp]: "measure lborel {l <..< u} = u - l"
hoelzl@57447
   483
  by (simp_all add: measure_def)
hoelzl@40859
   484
lp15@60615
   485
lemma
hoelzl@57447
   486
  assumes [simp]: "\<And>b. b \<in> Basis \<Longrightarrow> l \<bullet> b \<le> u \<bullet> b"
hoelzl@57447
   487
  shows measure_lborel_box[simp]: "measure lborel (box l u) = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@57447
   488
    and measure_lborel_cbox[simp]: "measure lborel (cbox l u) = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@62975
   489
  by (simp_all add: measure_def inner_diff_left setprod_nonneg)
hoelzl@41654
   490
hoelzl@63886
   491
lemma measure_lborel_cbox_eq:
hoelzl@63886
   492
  "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
   493
  using box_eq_empty(2)[THEN iffD2, of u l] by (auto simp: not_le)
hoelzl@63886
   494
hoelzl@63886
   495
lemma measure_lborel_box_eq:
hoelzl@63886
   496
  "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
   497
  using box_eq_empty(1)[THEN iffD2, of u l] by (auto simp: not_le dest!: less_imp_le) force
hoelzl@63886
   498
hoelzl@63886
   499
lemma measure_lborel_singleton[simp]: "measure lborel {x} = 0"
hoelzl@63886
   500
  by (simp add: measure_def)
hoelzl@63886
   501
hoelzl@57447
   502
lemma sigma_finite_lborel: "sigma_finite_measure lborel"
hoelzl@57447
   503
proof
hoelzl@57447
   504
  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
   505
    by (intro exI[of _ "range (\<lambda>n::nat. box (- real n *\<^sub>R One) (real n *\<^sub>R One))"])
hoelzl@57447
   506
       (auto simp: emeasure_lborel_cbox_eq UN_box_eq_UNIV)
hoelzl@49777
   507
qed
hoelzl@40859
   508
hoelzl@57447
   509
end
hoelzl@41689
   510
hoelzl@57447
   511
lemma emeasure_lborel_UNIV: "emeasure lborel (UNIV::'a::euclidean_space set) = \<infinity>"
lp15@59741
   512
proof -
lp15@59741
   513
  { fix n::nat
lp15@59741
   514
    let ?Ba = "Basis :: 'a set"
lp15@59741
   515
    have "real n \<le> (2::real) ^ card ?Ba * real n"
lp15@59741
   516
      by (simp add: mult_le_cancel_right1)
lp15@60615
   517
    also
lp15@59741
   518
    have "... \<le> (2::real) ^ card ?Ba * real (Suc n) ^ card ?Ba"
lp15@59741
   519
      apply (rule mult_left_mono)
lp15@61609
   520
      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
   521
      apply (simp add: DIM_positive)
lp15@59741
   522
      done
lp15@59741
   523
    finally have "real n \<le> (2::real) ^ card ?Ba * real (Suc n) ^ card ?Ba" .
lp15@59741
   524
  } note [intro!] = this
lp15@59741
   525
  show ?thesis
lp15@59741
   526
    unfolding UN_box_eq_UNIV[symmetric]
lp15@59741
   527
    apply (subst SUP_emeasure_incseq[symmetric])
lp15@60615
   528
    apply (auto simp: incseq_def subset_box inner_add_left setprod_constant
hoelzl@62975
   529
      simp del: Sup_eq_top_iff SUP_eq_top_iff
hoelzl@62975
   530
      intro!: ennreal_SUP_eq_top)
lp15@60615
   531
    done
lp15@59741
   532
qed
hoelzl@40859
   533
hoelzl@57447
   534
lemma emeasure_lborel_countable:
hoelzl@57447
   535
  fixes A :: "'a::euclidean_space set"
hoelzl@57447
   536
  assumes "countable A"
hoelzl@57447
   537
  shows "emeasure lborel A = 0"
hoelzl@57447
   538
proof -
hoelzl@57447
   539
  have "A \<subseteq> (\<Union>i. {from_nat_into A i})" using from_nat_into_surj assms by force
hoelzl@63262
   540
  then have "emeasure lborel A \<le> emeasure lborel (\<Union>i. {from_nat_into A i})"
hoelzl@63262
   541
    by (intro emeasure_mono) auto
hoelzl@63262
   542
  also have "emeasure lborel (\<Union>i. {from_nat_into A i}) = 0"
hoelzl@57447
   543
    by (rule emeasure_UN_eq_0) auto
hoelzl@63262
   544
  finally show ?thesis
hoelzl@63262
   545
    by (auto simp add: )
hoelzl@40859
   546
qed
hoelzl@40859
   547
hoelzl@59425
   548
lemma countable_imp_null_set_lborel: "countable A \<Longrightarrow> A \<in> null_sets lborel"
hoelzl@59425
   549
  by (simp add: null_sets_def emeasure_lborel_countable sets.countable)
hoelzl@59425
   550
hoelzl@59425
   551
lemma finite_imp_null_set_lborel: "finite A \<Longrightarrow> A \<in> null_sets lborel"
hoelzl@59425
   552
  by (intro countable_imp_null_set_lborel countable_finite)
hoelzl@59425
   553
hoelzl@59425
   554
lemma lborel_neq_count_space[simp]: "lborel \<noteq> count_space (A::('a::ordered_euclidean_space) set)"
hoelzl@59425
   555
proof
hoelzl@59425
   556
  assume asm: "lborel = count_space A"
hoelzl@59425
   557
  have "space lborel = UNIV" by simp
hoelzl@59425
   558
  hence [simp]: "A = UNIV" by (subst (asm) asm) (simp only: space_count_space)
lp15@60615
   559
  have "emeasure lborel {undefined::'a} = 1"
hoelzl@59425
   560
      by (subst asm, subst emeasure_count_space_finite) auto
hoelzl@59425
   561
  moreover have "emeasure lborel {undefined} \<noteq> 1" by simp
hoelzl@59425
   562
  ultimately show False by contradiction
hoelzl@59425
   563
qed
hoelzl@59425
   564
wenzelm@61808
   565
subsection \<open>Affine transformation on the Lebesgue-Borel\<close>
hoelzl@49777
   566
hoelzl@49777
   567
lemma lborel_eqI:
hoelzl@57447
   568
  fixes M :: "'a::euclidean_space measure"
hoelzl@57447
   569
  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
   570
  assumes sets_eq: "sets M = sets borel"
hoelzl@49777
   571
  shows "lborel = M"
hoelzl@57447
   572
proof (rule measure_eqI_generator_eq)
hoelzl@57447
   573
  let ?E = "range (\<lambda>(a, b). box a b::'a set)"
hoelzl@57447
   574
  show "Int_stable ?E"
hoelzl@57447
   575
    by (auto simp: Int_stable_def box_Int_box)
hoelzl@57447
   576
hoelzl@49777
   577
  show "?E \<subseteq> Pow UNIV" "sets lborel = sigma_sets UNIV ?E" "sets M = sigma_sets UNIV ?E"
hoelzl@57447
   578
    by (simp_all add: borel_eq_box sets_eq)
hoelzl@49777
   579
hoelzl@57447
   580
  let ?A = "\<lambda>n::nat. box (- (real n *\<^sub>R One)) (real n *\<^sub>R One) :: 'a set"
hoelzl@57447
   581
  show "range ?A \<subseteq> ?E" "(\<Union>i. ?A i) = UNIV"
hoelzl@57447
   582
    unfolding UN_box_eq_UNIV by auto
hoelzl@49777
   583
hoelzl@57447
   584
  { fix i show "emeasure lborel (?A i) \<noteq> \<infinity>" by auto }
hoelzl@49777
   585
  { fix X assume "X \<in> ?E" then show "emeasure lborel X = emeasure M X"
hoelzl@63886
   586
      apply (auto simp: emeasure_eq emeasure_lborel_box_eq)
hoelzl@57447
   587
      apply (subst box_eq_empty(1)[THEN iffD2])
hoelzl@57447
   588
      apply (auto intro: less_imp_le simp: not_le)
hoelzl@57447
   589
      done }
hoelzl@49777
   590
qed
hoelzl@49777
   591
hoelzl@63886
   592
lemma lborel_affine_euclidean:
hoelzl@63886
   593
  fixes c :: "'a::euclidean_space \<Rightarrow> real" and t
hoelzl@63886
   594
  defines "T x \<equiv> t + (\<Sum>j\<in>Basis. (c j * (x \<bullet> j)) *\<^sub>R j)"
hoelzl@63886
   595
  assumes c: "\<And>j. j \<in> Basis \<Longrightarrow> c j \<noteq> 0"
hoelzl@63886
   596
  shows "lborel = density (distr lborel borel T) (\<lambda>_. (\<Prod>j\<in>Basis. \<bar>c j\<bar>))" (is "_ = ?D")
hoelzl@49777
   597
proof (rule lborel_eqI)
hoelzl@57447
   598
  let ?B = "Basis :: 'a set"
hoelzl@57447
   599
  fix l u assume le: "\<And>b. b \<in> ?B \<Longrightarrow> l \<bullet> b \<le> u \<bullet> b"
hoelzl@63886
   600
  have [measurable]: "T \<in> borel \<rightarrow>\<^sub>M borel"
hoelzl@63886
   601
    by (simp add: T_def[abs_def])
hoelzl@63886
   602
  have eq: "T -` box l u = box
hoelzl@63886
   603
    (\<Sum>j\<in>Basis. (((if 0 < c j then l - t else u - t) \<bullet> j) / c j) *\<^sub>R j)
hoelzl@63886
   604
    (\<Sum>j\<in>Basis. (((if 0 < c j then u - t else l - t) \<bullet> j) / c j) *\<^sub>R j)"
hoelzl@63886
   605
    using c by (auto simp: box_def T_def field_simps inner_simps divide_less_eq)
hoelzl@63886
   606
  with le c show "emeasure ?D (box l u) = (\<Prod>b\<in>?B. (u - l) \<bullet> b)"
hoelzl@63886
   607
    by (auto simp: emeasure_density emeasure_distr nn_integral_multc emeasure_lborel_box_eq inner_simps
hoelzl@63886
   608
                   field_simps divide_simps ennreal_mult'[symmetric] setprod_nonneg setprod.distrib[symmetric]
hoelzl@63886
   609
             intro!: setprod.cong)
hoelzl@49777
   610
qed simp
hoelzl@49777
   611
hoelzl@63886
   612
lemma lborel_affine:
hoelzl@63886
   613
  fixes t :: "'a::euclidean_space"
hoelzl@63886
   614
  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
   615
  using lborel_affine_euclidean[where c="\<lambda>_::'a. c" and t=t]
hoelzl@63886
   616
  unfolding scaleR_scaleR[symmetric] scaleR_setsum_right[symmetric] euclidean_representation setprod_constant by simp
hoelzl@63886
   617
hoelzl@57447
   618
lemma lborel_real_affine:
hoelzl@62975
   619
  "c \<noteq> 0 \<Longrightarrow> lborel = density (distr lborel borel (\<lambda>x. t + c * x)) (\<lambda>_. ennreal (abs c))"
hoelzl@57447
   620
  using lborel_affine[of c t] by simp
hoelzl@57447
   621
lp15@60615
   622
lemma AE_borel_affine:
hoelzl@57447
   623
  fixes P :: "real \<Rightarrow> bool"
hoelzl@57447
   624
  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
   625
  by (subst lborel_real_affine[where t="- t / c" and c="1 / c"])
hoelzl@57447
   626
     (simp_all add: AE_density AE_distr_iff field_simps)
hoelzl@57447
   627
hoelzl@56996
   628
lemma nn_integral_real_affine:
hoelzl@56993
   629
  fixes c :: real assumes [measurable]: "f \<in> borel_measurable borel" and c: "c \<noteq> 0"
hoelzl@56993
   630
  shows "(\<integral>\<^sup>+x. f x \<partial>lborel) = \<bar>c\<bar> * (\<integral>\<^sup>+x. f (t + c * x) \<partial>lborel)"
hoelzl@56993
   631
  by (subst lborel_real_affine[OF c, of t])
hoelzl@56996
   632
     (simp add: nn_integral_density nn_integral_distr nn_integral_cmult)
hoelzl@56993
   633
hoelzl@56993
   634
lemma lborel_integrable_real_affine:
hoelzl@57447
   635
  fixes f :: "real \<Rightarrow> 'a :: {banach, second_countable_topology}"
hoelzl@56993
   636
  assumes f: "integrable lborel f"
hoelzl@56993
   637
  shows "c \<noteq> 0 \<Longrightarrow> integrable lborel (\<lambda>x. f (t + c * x))"
hoelzl@56993
   638
  using f f[THEN borel_measurable_integrable] unfolding integrable_iff_bounded
hoelzl@62975
   639
  by (subst (asm) nn_integral_real_affine[where c=c and t=t]) (auto simp: ennreal_mult_less_top)
hoelzl@56993
   640
hoelzl@56993
   641
lemma lborel_integrable_real_affine_iff:
hoelzl@56993
   642
  fixes f :: "real \<Rightarrow> 'a :: {banach, second_countable_topology}"
hoelzl@56993
   643
  shows "c \<noteq> 0 \<Longrightarrow> integrable lborel (\<lambda>x. f (t + c * x)) \<longleftrightarrow> integrable lborel f"
hoelzl@56993
   644
  using
hoelzl@56993
   645
    lborel_integrable_real_affine[of f c t]
hoelzl@56993
   646
    lborel_integrable_real_affine[of "\<lambda>x. f (t + c * x)" "1/c" "-t/c"]
hoelzl@56993
   647
  by (auto simp add: field_simps)
hoelzl@56993
   648
hoelzl@56993
   649
lemma lborel_integral_real_affine:
hoelzl@56993
   650
  fixes f :: "real \<Rightarrow> 'a :: {banach, second_countable_topology}" and c :: real
hoelzl@57166
   651
  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
   652
proof cases
hoelzl@57166
   653
  assume f[measurable]: "integrable lborel f" then show ?thesis
hoelzl@57166
   654
    using c f f[THEN borel_measurable_integrable] f[THEN lborel_integrable_real_affine, of c t]
hoelzl@57447
   655
    by (subst lborel_real_affine[OF c, of t])
hoelzl@57447
   656
       (simp add: integral_density integral_distr)
hoelzl@57166
   657
next
hoelzl@57166
   658
  assume "\<not> integrable lborel f" with c show ?thesis
hoelzl@57166
   659
    by (simp add: lborel_integrable_real_affine_iff not_integrable_integral_eq)
hoelzl@57166
   660
qed
hoelzl@56993
   661
lp15@60615
   662
lemma divideR_right:
hoelzl@56993
   663
  fixes x y :: "'a::real_normed_vector"
hoelzl@56993
   664
  shows "r \<noteq> 0 \<Longrightarrow> y = x /\<^sub>R r \<longleftrightarrow> r *\<^sub>R y = x"
hoelzl@56993
   665
  using scaleR_cancel_left[of r y "x /\<^sub>R r"] by simp
hoelzl@56993
   666
hoelzl@56993
   667
lemma lborel_has_bochner_integral_real_affine_iff:
hoelzl@56993
   668
  fixes x :: "'a :: {banach, second_countable_topology}"
hoelzl@56993
   669
  shows "c \<noteq> 0 \<Longrightarrow>
hoelzl@56993
   670
    has_bochner_integral lborel f x \<longleftrightarrow>
hoelzl@56993
   671
    has_bochner_integral lborel (\<lambda>x. f (t + c * x)) (x /\<^sub>R \<bar>c\<bar>)"
hoelzl@56993
   672
  unfolding has_bochner_integral_iff lborel_integrable_real_affine_iff
hoelzl@56993
   673
  by (simp_all add: lborel_integral_real_affine[symmetric] divideR_right cong: conj_cong)
hoelzl@49777
   674
hoelzl@59425
   675
lemma lborel_distr_uminus: "distr lborel borel uminus = (lborel :: real measure)"
lp15@60615
   676
  by (subst lborel_real_affine[of "-1" 0])
hoelzl@62975
   677
     (auto simp: density_1 one_ennreal_def[symmetric])
hoelzl@59425
   678
lp15@60615
   679
lemma lborel_distr_mult:
hoelzl@59425
   680
  assumes "(c::real) \<noteq> 0"
hoelzl@59425
   681
  shows "distr lborel borel (op * c) = density lborel (\<lambda>_. inverse \<bar>c\<bar>)"
hoelzl@59425
   682
proof-
hoelzl@59425
   683
  have "distr lborel borel (op * c) = distr lborel lborel (op * c)" by (simp cong: distr_cong)
hoelzl@59425
   684
  also from assms have "... = density lborel (\<lambda>_. inverse \<bar>c\<bar>)"
hoelzl@59425
   685
    by (subst lborel_real_affine[of "inverse c" 0]) (auto simp: o_def distr_density_distr)
hoelzl@59425
   686
  finally show ?thesis .
hoelzl@59425
   687
qed
hoelzl@59425
   688
lp15@60615
   689
lemma lborel_distr_mult':
hoelzl@59425
   690
  assumes "(c::real) \<noteq> 0"
wenzelm@61945
   691
  shows "lborel = density (distr lborel borel (op * c)) (\<lambda>_. \<bar>c\<bar>)"
hoelzl@59425
   692
proof-
hoelzl@59425
   693
  have "lborel = density lborel (\<lambda>_. 1)" by (rule density_1[symmetric])
hoelzl@62975
   694
  also from assms have "(\<lambda>_. 1 :: ennreal) = (\<lambda>_. inverse \<bar>c\<bar> * \<bar>c\<bar>)" by (intro ext) simp
wenzelm@61945
   695
  also have "density lborel ... = density (density lborel (\<lambda>_. inverse \<bar>c\<bar>)) (\<lambda>_. \<bar>c\<bar>)"
hoelzl@62975
   696
    by (subst density_density_eq) (auto simp: ennreal_mult)
wenzelm@61945
   697
  also from assms have "density lborel (\<lambda>_. inverse \<bar>c\<bar>) = distr lborel borel (op * c)"
hoelzl@59425
   698
    by (rule lborel_distr_mult[symmetric])
hoelzl@59425
   699
  finally show ?thesis .
hoelzl@59425
   700
qed
hoelzl@59425
   701
hoelzl@59425
   702
lemma lborel_distr_plus: "distr lborel borel (op + c) = (lborel :: real measure)"
hoelzl@62975
   703
  by (subst lborel_real_affine[of 1 c]) (auto simp: density_1 one_ennreal_def[symmetric])
hoelzl@59425
   704
wenzelm@61605
   705
interpretation lborel: sigma_finite_measure lborel
hoelzl@57447
   706
  by (rule sigma_finite_lborel)
hoelzl@57447
   707
hoelzl@57447
   708
interpretation lborel_pair: pair_sigma_finite lborel lborel ..
hoelzl@57447
   709
hoelzl@59425
   710
lemma lborel_prod:
hoelzl@59425
   711
  "lborel \<Otimes>\<^sub>M lborel = (lborel :: ('a::euclidean_space \<times> 'b::euclidean_space) measure)"
hoelzl@59425
   712
proof (rule lborel_eqI[symmetric], clarify)
hoelzl@59425
   713
  fix la ua :: 'a and lb ub :: 'b
hoelzl@59425
   714
  assume lu: "\<And>a b. (a, b) \<in> Basis \<Longrightarrow> (la, lb) \<bullet> (a, b) \<le> (ua, ub) \<bullet> (a, b)"
hoelzl@59425
   715
  have [simp]:
hoelzl@59425
   716
    "\<And>b. b \<in> Basis \<Longrightarrow> la \<bullet> b \<le> ua \<bullet> b"
hoelzl@59425
   717
    "\<And>b. b \<in> Basis \<Longrightarrow> lb \<bullet> b \<le> ub \<bullet> b"
hoelzl@59425
   718
    "inj_on (\<lambda>u. (u, 0)) Basis" "inj_on (\<lambda>u. (0, u)) Basis"
hoelzl@59425
   719
    "(\<lambda>u. (u, 0)) ` Basis \<inter> (\<lambda>u. (0, u)) ` Basis = {}"
hoelzl@59425
   720
    "box (la, lb) (ua, ub) = box la ua \<times> box lb ub"
hoelzl@59425
   721
    using lu[of _ 0] lu[of 0] by (auto intro!: inj_onI simp add: Basis_prod_def ball_Un box_def)
hoelzl@59425
   722
  show "emeasure (lborel \<Otimes>\<^sub>M lborel) (box (la, lb) (ua, ub)) =
hoelzl@62975
   723
      ennreal (setprod (op \<bullet> ((ua, ub) - (la, lb))) Basis)"
hoelzl@59425
   724
    by (simp add: lborel.emeasure_pair_measure_Times Basis_prod_def setprod.union_disjoint
hoelzl@62975
   725
                  setprod.reindex ennreal_mult inner_diff_left setprod_nonneg)
hoelzl@59425
   726
qed (simp add: borel_prod[symmetric])
hoelzl@59425
   727
hoelzl@57447
   728
(* FIXME: conversion in measurable prover *)
hoelzl@57447
   729
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
   730
lemma lborelD[measurable (raw)]: "A \<in> sets borel \<Longrightarrow> A \<in> sets lborel" by simp
hoelzl@57447
   731
hoelzl@57138
   732
lemma emeasure_bounded_finite:
hoelzl@57138
   733
  assumes "bounded A" shows "emeasure lborel A < \<infinity>"
hoelzl@57138
   734
proof -
wenzelm@61808
   735
  from bounded_subset_cbox[OF \<open>bounded A\<close>] obtain a b where "A \<subseteq> cbox a b"
hoelzl@57138
   736
    by auto
hoelzl@57138
   737
  then have "emeasure lborel A \<le> emeasure lborel (cbox a b)"
hoelzl@57138
   738
    by (intro emeasure_mono) auto
hoelzl@57138
   739
  then show ?thesis
hoelzl@62975
   740
    by (auto simp: emeasure_lborel_cbox_eq setprod_nonneg less_top[symmetric] top_unique split: if_split_asm)
hoelzl@57138
   741
qed
hoelzl@57138
   742
hoelzl@57138
   743
lemma emeasure_compact_finite: "compact A \<Longrightarrow> emeasure lborel A < \<infinity>"
hoelzl@57138
   744
  using emeasure_bounded_finite[of A] by (auto intro: compact_imp_bounded)
hoelzl@57138
   745
hoelzl@57138
   746
lemma borel_integrable_compact:
hoelzl@57447
   747
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::{banach, second_countable_topology}"
hoelzl@57138
   748
  assumes "compact S" "continuous_on S f"
hoelzl@57138
   749
  shows "integrable lborel (\<lambda>x. indicator S x *\<^sub>R f x)"
hoelzl@57138
   750
proof cases
hoelzl@57138
   751
  assume "S \<noteq> {}"
hoelzl@57138
   752
  have "continuous_on S (\<lambda>x. norm (f x))"
hoelzl@57138
   753
    using assms by (intro continuous_intros)
wenzelm@61808
   754
  from continuous_attains_sup[OF \<open>compact S\<close> \<open>S \<noteq> {}\<close> this]
hoelzl@57138
   755
  obtain M where M: "\<And>x. x \<in> S \<Longrightarrow> norm (f x) \<le> M"
hoelzl@57138
   756
    by auto
hoelzl@57138
   757
hoelzl@57138
   758
  show ?thesis
hoelzl@57138
   759
  proof (rule integrable_bound)
hoelzl@57138
   760
    show "integrable lborel (\<lambda>x. indicator S x * M)"
hoelzl@57138
   761
      using assms by (auto intro!: emeasure_compact_finite borel_compact integrable_mult_left)
hoelzl@57138
   762
    show "(\<lambda>x. indicator S x *\<^sub>R f x) \<in> borel_measurable lborel"
hoelzl@57138
   763
      using assms by (auto intro!: borel_measurable_continuous_on_indicator borel_compact)
hoelzl@57138
   764
    show "AE x in lborel. norm (indicator S x *\<^sub>R f x) \<le> norm (indicator S x * M)"
hoelzl@57138
   765
      by (auto split: split_indicator simp: abs_real_def dest!: M)
hoelzl@57138
   766
  qed
hoelzl@57138
   767
qed simp
hoelzl@57138
   768
hoelzl@50418
   769
lemma borel_integrable_atLeastAtMost:
hoelzl@56993
   770
  fixes f :: "real \<Rightarrow> real"
hoelzl@50418
   771
  assumes f: "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> isCont f x"
hoelzl@50418
   772
  shows "integrable lborel (\<lambda>x. f x * indicator {a .. b} x)" (is "integrable _ ?f")
hoelzl@57138
   773
proof -
hoelzl@57138
   774
  have "integrable lborel (\<lambda>x. indicator {a .. b} x *\<^sub>R f x)"
hoelzl@57138
   775
  proof (rule borel_integrable_compact)
hoelzl@57138
   776
    from f show "continuous_on {a..b} f"
hoelzl@57138
   777
      by (auto intro: continuous_at_imp_continuous_on)
hoelzl@57138
   778
  qed simp
hoelzl@57138
   779
  then show ?thesis
haftmann@57512
   780
    by (auto simp: mult.commute)
hoelzl@57138
   781
qed
hoelzl@50418
   782
hoelzl@38656
   783
end