src/HOL/Analysis/Lebesgue_Measure.thy
author hoelzl
Thu Sep 29 13:54:57 2016 +0200 (2016-09-29)
changeset 63958 02de4a58e210
parent 63918 6bf55e6e0b75
child 63959 f77dca1abf1b
permissions -rw-r--r--
HOL-Analysis: add measurable sets with finite measures, prove affine transformation rule for the Lebesgue measure
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@63958
    11
  imports Finite_Product_Measure Bochner_Integration Caratheodory Complete_Measure
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 + _")
Mathias@63918
   238
      by (subst setsum.distrib) (simp add: field_simps setsum_distrib_left)
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
hoelzl@63958
   359
abbreviation lebesgue :: "'a::euclidean_space measure"
hoelzl@63958
   360
  where "lebesgue \<equiv> completion lborel"
hoelzl@63958
   361
hoelzl@63958
   362
abbreviation lebesgue_on :: "'a set \<Rightarrow> 'a::euclidean_space measure"
hoelzl@63958
   363
  where "lebesgue_on \<Omega> \<equiv> restrict_space (completion lborel) \<Omega>"
hoelzl@63958
   364
lp15@60615
   365
lemma
hoelzl@59048
   366
  shows sets_lborel[simp, measurable_cong]: "sets lborel = sets borel"
hoelzl@57447
   367
    and space_lborel[simp]: "space lborel = space borel"
hoelzl@57447
   368
    and measurable_lborel1[simp]: "measurable M lborel = measurable M borel"
hoelzl@57447
   369
    and measurable_lborel2[simp]: "measurable lborel M = measurable borel M"
hoelzl@57447
   370
  by (simp_all add: lborel_def)
hoelzl@57447
   371
hoelzl@57447
   372
context
hoelzl@57447
   373
begin
hoelzl@57447
   374
hoelzl@57447
   375
interpretation sigma_finite_measure "interval_measure (\<lambda>x. x)"
hoelzl@57447
   376
  by (rule sigma_finite_interval_measure) auto
hoelzl@57447
   377
interpretation finite_product_sigma_finite "\<lambda>_. interval_measure (\<lambda>x. x)" Basis
hoelzl@57447
   378
  proof qed simp
hoelzl@57447
   379
hoelzl@57447
   380
lemma lborel_eq_real: "lborel = interval_measure (\<lambda>x. x)"
hoelzl@57447
   381
  unfolding lborel_def Basis_real_def
hoelzl@57447
   382
  using distr_id[of "interval_measure (\<lambda>x. x)"]
hoelzl@57447
   383
  by (subst distr_component[symmetric])
hoelzl@57447
   384
     (simp_all add: distr_distr comp_def del: distr_id cong: distr_cong)
hoelzl@57447
   385
hoelzl@57447
   386
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
   387
  by (subst lborel_def) (simp add: lborel_eq_real)
hoelzl@57447
   388
hoelzl@57447
   389
lemma nn_integral_lborel_setprod:
hoelzl@57447
   390
  assumes [measurable]: "\<And>b. b \<in> Basis \<Longrightarrow> f b \<in> borel_measurable borel"
hoelzl@57447
   391
  assumes nn[simp]: "\<And>b x. b \<in> Basis \<Longrightarrow> 0 \<le> f b x"
hoelzl@57447
   392
  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
   393
  by (simp add: lborel_def nn_integral_distr product_nn_integral_setprod
hoelzl@57447
   394
                product_nn_integral_singleton)
hoelzl@57447
   395
lp15@60615
   396
lemma emeasure_lborel_Icc[simp]:
hoelzl@57447
   397
  fixes l u :: real
hoelzl@57447
   398
  assumes [simp]: "l \<le> u"
hoelzl@57447
   399
  shows "emeasure lborel {l .. u} = u - l"
hoelzl@50526
   400
proof -
hoelzl@57447
   401
  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
   402
    by (auto simp: space_PiM)
hoelzl@57447
   403
  then show ?thesis
hoelzl@57447
   404
    by (simp add: lborel_def emeasure_distr emeasure_PiM emeasure_interval_measure_Icc continuous_on_id)
hoelzl@50104
   405
qed
hoelzl@50104
   406
hoelzl@62975
   407
lemma emeasure_lborel_Icc_eq: "emeasure lborel {l .. u} = ennreal (if l \<le> u then u - l else 0)"
hoelzl@57447
   408
  by simp
hoelzl@47694
   409
hoelzl@57447
   410
lemma emeasure_lborel_cbox[simp]:
hoelzl@57447
   411
  assumes [simp]: "\<And>b. b \<in> Basis \<Longrightarrow> l \<bullet> b \<le> u \<bullet> b"
hoelzl@57447
   412
  shows "emeasure lborel (cbox l u) = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@41654
   413
proof -
hoelzl@62975
   414
  have "(\<lambda>x. \<Prod>b\<in>Basis. indicator {l\<bullet>b .. u\<bullet>b} (x \<bullet> b) :: ennreal) = indicator (cbox l u)"
hoelzl@62975
   415
    by (auto simp: fun_eq_iff cbox_def split: split_indicator)
hoelzl@57447
   416
  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
   417
    by simp
hoelzl@57447
   418
  also have "\<dots> = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@62975
   419
    by (subst nn_integral_lborel_setprod) (simp_all add: setprod_ennreal inner_diff_left)
hoelzl@47694
   420
  finally show ?thesis .
hoelzl@38656
   421
qed
hoelzl@38656
   422
hoelzl@57447
   423
lemma AE_lborel_singleton: "AE x in lborel::'a::euclidean_space measure. x \<noteq> c"
hoelzl@62975
   424
  using SOME_Basis AE_discrete_difference [of "{c}" lborel] emeasure_lborel_cbox [of c c]
hoelzl@62975
   425
  by (auto simp add: cbox_sing setprod_constant power_0_left)
hoelzl@47757
   426
hoelzl@57447
   427
lemma emeasure_lborel_Ioo[simp]:
hoelzl@57447
   428
  assumes [simp]: "l \<le> u"
hoelzl@62975
   429
  shows "emeasure lborel {l <..< u} = ennreal (u - l)"
hoelzl@40859
   430
proof -
hoelzl@57447
   431
  have "emeasure lborel {l <..< u} = emeasure lborel {l .. u}"
hoelzl@57447
   432
    using AE_lborel_singleton[of u] AE_lborel_singleton[of l] by (intro emeasure_eq_AE) auto
hoelzl@47694
   433
  then show ?thesis
hoelzl@57447
   434
    by simp
hoelzl@41981
   435
qed
hoelzl@38656
   436
hoelzl@57447
   437
lemma emeasure_lborel_Ioc[simp]:
hoelzl@57447
   438
  assumes [simp]: "l \<le> u"
hoelzl@62975
   439
  shows "emeasure lborel {l <.. u} = ennreal (u - l)"
hoelzl@41654
   440
proof -
hoelzl@57447
   441
  have "emeasure lborel {l <.. u} = emeasure lborel {l .. u}"
hoelzl@57447
   442
    using AE_lborel_singleton[of u] AE_lborel_singleton[of l] by (intro emeasure_eq_AE) auto
hoelzl@57447
   443
  then show ?thesis
hoelzl@57447
   444
    by simp
hoelzl@38656
   445
qed
hoelzl@38656
   446
hoelzl@57447
   447
lemma emeasure_lborel_Ico[simp]:
hoelzl@57447
   448
  assumes [simp]: "l \<le> u"
hoelzl@62975
   449
  shows "emeasure lborel {l ..< u} = ennreal (u - l)"
hoelzl@57447
   450
proof -
hoelzl@57447
   451
  have "emeasure lborel {l ..< u} = emeasure lborel {l .. u}"
hoelzl@57447
   452
    using AE_lborel_singleton[of u] AE_lborel_singleton[of l] by (intro emeasure_eq_AE) auto
hoelzl@57447
   453
  then show ?thesis
hoelzl@57447
   454
    by simp
hoelzl@38656
   455
qed
hoelzl@38656
   456
hoelzl@57447
   457
lemma emeasure_lborel_box[simp]:
hoelzl@57447
   458
  assumes [simp]: "\<And>b. b \<in> Basis \<Longrightarrow> l \<bullet> b \<le> u \<bullet> b"
hoelzl@57447
   459
  shows "emeasure lborel (box l u) = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@57447
   460
proof -
hoelzl@62975
   461
  have "(\<lambda>x. \<Prod>b\<in>Basis. indicator {l\<bullet>b <..< u\<bullet>b} (x \<bullet> b) :: ennreal) = indicator (box l u)"
hoelzl@62975
   462
    by (auto simp: fun_eq_iff box_def split: split_indicator)
hoelzl@57447
   463
  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
   464
    by simp
hoelzl@57447
   465
  also have "\<dots> = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@62975
   466
    by (subst nn_integral_lborel_setprod) (simp_all add: setprod_ennreal inner_diff_left)
hoelzl@57447
   467
  finally show ?thesis .
hoelzl@40859
   468
qed
hoelzl@38656
   469
hoelzl@57447
   470
lemma emeasure_lborel_cbox_eq:
hoelzl@57447
   471
  "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
   472
  using box_eq_empty(2)[THEN iffD2, of u l] by (auto simp: not_le)
hoelzl@41654
   473
hoelzl@57447
   474
lemma emeasure_lborel_box_eq:
hoelzl@57447
   475
  "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
   476
  using box_eq_empty(1)[THEN iffD2, of u l] by (auto simp: not_le dest!: less_imp_le) force
hoelzl@40859
   477
hoelzl@63886
   478
lemma emeasure_lborel_singleton[simp]: "emeasure lborel {x} = 0"
hoelzl@63886
   479
  using emeasure_lborel_cbox[of x x] nonempty_Basis
hoelzl@63886
   480
  by (auto simp del: emeasure_lborel_cbox nonempty_Basis simp add: cbox_sing setprod_constant)
hoelzl@63886
   481
hoelzl@40859
   482
lemma
hoelzl@57447
   483
  fixes l u :: real
hoelzl@57447
   484
  assumes [simp]: "l \<le> u"
hoelzl@57447
   485
  shows measure_lborel_Icc[simp]: "measure lborel {l .. u} = u - l"
hoelzl@57447
   486
    and measure_lborel_Ico[simp]: "measure lborel {l ..< u} = u - l"
hoelzl@57447
   487
    and measure_lborel_Ioc[simp]: "measure lborel {l <.. u} = u - l"
hoelzl@57447
   488
    and measure_lborel_Ioo[simp]: "measure lborel {l <..< u} = u - l"
hoelzl@57447
   489
  by (simp_all add: measure_def)
hoelzl@40859
   490
lp15@60615
   491
lemma
hoelzl@57447
   492
  assumes [simp]: "\<And>b. b \<in> Basis \<Longrightarrow> l \<bullet> b \<le> u \<bullet> b"
hoelzl@57447
   493
  shows measure_lborel_box[simp]: "measure lborel (box l u) = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@57447
   494
    and measure_lborel_cbox[simp]: "measure lborel (cbox l u) = (\<Prod>b\<in>Basis. (u - l) \<bullet> b)"
hoelzl@62975
   495
  by (simp_all add: measure_def inner_diff_left setprod_nonneg)
hoelzl@41654
   496
hoelzl@63886
   497
lemma measure_lborel_cbox_eq:
hoelzl@63886
   498
  "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
   499
  using box_eq_empty(2)[THEN iffD2, of u l] by (auto simp: not_le)
hoelzl@63886
   500
hoelzl@63886
   501
lemma measure_lborel_box_eq:
hoelzl@63886
   502
  "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
   503
  using box_eq_empty(1)[THEN iffD2, of u l] by (auto simp: not_le dest!: less_imp_le) force
hoelzl@63886
   504
hoelzl@63886
   505
lemma measure_lborel_singleton[simp]: "measure lborel {x} = 0"
hoelzl@63886
   506
  by (simp add: measure_def)
hoelzl@63886
   507
hoelzl@57447
   508
lemma sigma_finite_lborel: "sigma_finite_measure lborel"
hoelzl@57447
   509
proof
hoelzl@57447
   510
  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
   511
    by (intro exI[of _ "range (\<lambda>n::nat. box (- real n *\<^sub>R One) (real n *\<^sub>R One))"])
hoelzl@57447
   512
       (auto simp: emeasure_lborel_cbox_eq UN_box_eq_UNIV)
hoelzl@49777
   513
qed
hoelzl@40859
   514
hoelzl@57447
   515
end
hoelzl@41689
   516
hoelzl@57447
   517
lemma emeasure_lborel_UNIV: "emeasure lborel (UNIV::'a::euclidean_space set) = \<infinity>"
lp15@59741
   518
proof -
lp15@59741
   519
  { fix n::nat
lp15@59741
   520
    let ?Ba = "Basis :: 'a set"
lp15@59741
   521
    have "real n \<le> (2::real) ^ card ?Ba * real n"
lp15@59741
   522
      by (simp add: mult_le_cancel_right1)
lp15@60615
   523
    also
lp15@59741
   524
    have "... \<le> (2::real) ^ card ?Ba * real (Suc n) ^ card ?Ba"
lp15@59741
   525
      apply (rule mult_left_mono)
lp15@61609
   526
      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
   527
      apply (simp add: DIM_positive)
lp15@59741
   528
      done
lp15@59741
   529
    finally have "real n \<le> (2::real) ^ card ?Ba * real (Suc n) ^ card ?Ba" .
lp15@59741
   530
  } note [intro!] = this
lp15@59741
   531
  show ?thesis
lp15@59741
   532
    unfolding UN_box_eq_UNIV[symmetric]
lp15@59741
   533
    apply (subst SUP_emeasure_incseq[symmetric])
lp15@60615
   534
    apply (auto simp: incseq_def subset_box inner_add_left setprod_constant
hoelzl@62975
   535
      simp del: Sup_eq_top_iff SUP_eq_top_iff
hoelzl@62975
   536
      intro!: ennreal_SUP_eq_top)
lp15@60615
   537
    done
lp15@59741
   538
qed
hoelzl@40859
   539
hoelzl@57447
   540
lemma emeasure_lborel_countable:
hoelzl@57447
   541
  fixes A :: "'a::euclidean_space set"
hoelzl@57447
   542
  assumes "countable A"
hoelzl@57447
   543
  shows "emeasure lborel A = 0"
hoelzl@57447
   544
proof -
hoelzl@57447
   545
  have "A \<subseteq> (\<Union>i. {from_nat_into A i})" using from_nat_into_surj assms by force
hoelzl@63262
   546
  then have "emeasure lborel A \<le> emeasure lborel (\<Union>i. {from_nat_into A i})"
hoelzl@63262
   547
    by (intro emeasure_mono) auto
hoelzl@63262
   548
  also have "emeasure lborel (\<Union>i. {from_nat_into A i}) = 0"
hoelzl@57447
   549
    by (rule emeasure_UN_eq_0) auto
hoelzl@63262
   550
  finally show ?thesis
hoelzl@63262
   551
    by (auto simp add: )
hoelzl@40859
   552
qed
hoelzl@40859
   553
hoelzl@59425
   554
lemma countable_imp_null_set_lborel: "countable A \<Longrightarrow> A \<in> null_sets lborel"
hoelzl@59425
   555
  by (simp add: null_sets_def emeasure_lborel_countable sets.countable)
hoelzl@59425
   556
hoelzl@59425
   557
lemma finite_imp_null_set_lborel: "finite A \<Longrightarrow> A \<in> null_sets lborel"
hoelzl@59425
   558
  by (intro countable_imp_null_set_lborel countable_finite)
hoelzl@59425
   559
hoelzl@59425
   560
lemma lborel_neq_count_space[simp]: "lborel \<noteq> count_space (A::('a::ordered_euclidean_space) set)"
hoelzl@59425
   561
proof
hoelzl@59425
   562
  assume asm: "lborel = count_space A"
hoelzl@59425
   563
  have "space lborel = UNIV" by simp
hoelzl@59425
   564
  hence [simp]: "A = UNIV" by (subst (asm) asm) (simp only: space_count_space)
lp15@60615
   565
  have "emeasure lborel {undefined::'a} = 1"
hoelzl@59425
   566
      by (subst asm, subst emeasure_count_space_finite) auto
hoelzl@59425
   567
  moreover have "emeasure lborel {undefined} \<noteq> 1" by simp
hoelzl@59425
   568
  ultimately show False by contradiction
hoelzl@59425
   569
qed
hoelzl@59425
   570
wenzelm@61808
   571
subsection \<open>Affine transformation on the Lebesgue-Borel\<close>
hoelzl@49777
   572
hoelzl@49777
   573
lemma lborel_eqI:
hoelzl@57447
   574
  fixes M :: "'a::euclidean_space measure"
hoelzl@57447
   575
  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
   576
  assumes sets_eq: "sets M = sets borel"
hoelzl@49777
   577
  shows "lborel = M"
hoelzl@57447
   578
proof (rule measure_eqI_generator_eq)
hoelzl@57447
   579
  let ?E = "range (\<lambda>(a, b). box a b::'a set)"
hoelzl@57447
   580
  show "Int_stable ?E"
hoelzl@57447
   581
    by (auto simp: Int_stable_def box_Int_box)
hoelzl@57447
   582
hoelzl@49777
   583
  show "?E \<subseteq> Pow UNIV" "sets lborel = sigma_sets UNIV ?E" "sets M = sigma_sets UNIV ?E"
hoelzl@57447
   584
    by (simp_all add: borel_eq_box sets_eq)
hoelzl@49777
   585
hoelzl@57447
   586
  let ?A = "\<lambda>n::nat. box (- (real n *\<^sub>R One)) (real n *\<^sub>R One) :: 'a set"
hoelzl@57447
   587
  show "range ?A \<subseteq> ?E" "(\<Union>i. ?A i) = UNIV"
hoelzl@57447
   588
    unfolding UN_box_eq_UNIV by auto
hoelzl@49777
   589
hoelzl@57447
   590
  { fix i show "emeasure lborel (?A i) \<noteq> \<infinity>" by auto }
hoelzl@49777
   591
  { fix X assume "X \<in> ?E" then show "emeasure lborel X = emeasure M X"
hoelzl@63886
   592
      apply (auto simp: emeasure_eq emeasure_lborel_box_eq)
hoelzl@57447
   593
      apply (subst box_eq_empty(1)[THEN iffD2])
hoelzl@57447
   594
      apply (auto intro: less_imp_le simp: not_le)
hoelzl@57447
   595
      done }
hoelzl@49777
   596
qed
hoelzl@49777
   597
hoelzl@63886
   598
lemma lborel_affine_euclidean:
hoelzl@63886
   599
  fixes c :: "'a::euclidean_space \<Rightarrow> real" and t
hoelzl@63886
   600
  defines "T x \<equiv> t + (\<Sum>j\<in>Basis. (c j * (x \<bullet> j)) *\<^sub>R j)"
hoelzl@63886
   601
  assumes c: "\<And>j. j \<in> Basis \<Longrightarrow> c j \<noteq> 0"
hoelzl@63886
   602
  shows "lborel = density (distr lborel borel T) (\<lambda>_. (\<Prod>j\<in>Basis. \<bar>c j\<bar>))" (is "_ = ?D")
hoelzl@49777
   603
proof (rule lborel_eqI)
hoelzl@57447
   604
  let ?B = "Basis :: 'a set"
hoelzl@57447
   605
  fix l u assume le: "\<And>b. b \<in> ?B \<Longrightarrow> l \<bullet> b \<le> u \<bullet> b"
hoelzl@63886
   606
  have [measurable]: "T \<in> borel \<rightarrow>\<^sub>M borel"
hoelzl@63886
   607
    by (simp add: T_def[abs_def])
hoelzl@63886
   608
  have eq: "T -` box l u = box
hoelzl@63886
   609
    (\<Sum>j\<in>Basis. (((if 0 < c j then l - t else u - t) \<bullet> j) / c j) *\<^sub>R j)
hoelzl@63886
   610
    (\<Sum>j\<in>Basis. (((if 0 < c j then u - t else l - t) \<bullet> j) / c j) *\<^sub>R j)"
hoelzl@63886
   611
    using c by (auto simp: box_def T_def field_simps inner_simps divide_less_eq)
hoelzl@63886
   612
  with le c show "emeasure ?D (box l u) = (\<Prod>b\<in>?B. (u - l) \<bullet> b)"
hoelzl@63886
   613
    by (auto simp: emeasure_density emeasure_distr nn_integral_multc emeasure_lborel_box_eq inner_simps
hoelzl@63886
   614
                   field_simps divide_simps ennreal_mult'[symmetric] setprod_nonneg setprod.distrib[symmetric]
hoelzl@63886
   615
             intro!: setprod.cong)
hoelzl@49777
   616
qed simp
hoelzl@49777
   617
hoelzl@63886
   618
lemma lborel_affine:
hoelzl@63886
   619
  fixes t :: "'a::euclidean_space"
hoelzl@63886
   620
  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
   621
  using lborel_affine_euclidean[where c="\<lambda>_::'a. c" and t=t]
hoelzl@63886
   622
  unfolding scaleR_scaleR[symmetric] scaleR_setsum_right[symmetric] euclidean_representation setprod_constant by simp
hoelzl@63886
   623
hoelzl@57447
   624
lemma lborel_real_affine:
hoelzl@62975
   625
  "c \<noteq> 0 \<Longrightarrow> lborel = density (distr lborel borel (\<lambda>x. t + c * x)) (\<lambda>_. ennreal (abs c))"
hoelzl@57447
   626
  using lborel_affine[of c t] by simp
hoelzl@57447
   627
lp15@60615
   628
lemma AE_borel_affine:
hoelzl@57447
   629
  fixes P :: "real \<Rightarrow> bool"
hoelzl@57447
   630
  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
   631
  by (subst lborel_real_affine[where t="- t / c" and c="1 / c"])
hoelzl@57447
   632
     (simp_all add: AE_density AE_distr_iff field_simps)
hoelzl@57447
   633
hoelzl@56996
   634
lemma nn_integral_real_affine:
hoelzl@56993
   635
  fixes c :: real assumes [measurable]: "f \<in> borel_measurable borel" and c: "c \<noteq> 0"
hoelzl@56993
   636
  shows "(\<integral>\<^sup>+x. f x \<partial>lborel) = \<bar>c\<bar> * (\<integral>\<^sup>+x. f (t + c * x) \<partial>lborel)"
hoelzl@56993
   637
  by (subst lborel_real_affine[OF c, of t])
hoelzl@56996
   638
     (simp add: nn_integral_density nn_integral_distr nn_integral_cmult)
hoelzl@56993
   639
hoelzl@56993
   640
lemma lborel_integrable_real_affine:
hoelzl@57447
   641
  fixes f :: "real \<Rightarrow> 'a :: {banach, second_countable_topology}"
hoelzl@56993
   642
  assumes f: "integrable lborel f"
hoelzl@56993
   643
  shows "c \<noteq> 0 \<Longrightarrow> integrable lborel (\<lambda>x. f (t + c * x))"
hoelzl@56993
   644
  using f f[THEN borel_measurable_integrable] unfolding integrable_iff_bounded
hoelzl@62975
   645
  by (subst (asm) nn_integral_real_affine[where c=c and t=t]) (auto simp: ennreal_mult_less_top)
hoelzl@56993
   646
hoelzl@56993
   647
lemma lborel_integrable_real_affine_iff:
hoelzl@56993
   648
  fixes f :: "real \<Rightarrow> 'a :: {banach, second_countable_topology}"
hoelzl@56993
   649
  shows "c \<noteq> 0 \<Longrightarrow> integrable lborel (\<lambda>x. f (t + c * x)) \<longleftrightarrow> integrable lborel f"
hoelzl@56993
   650
  using
hoelzl@56993
   651
    lborel_integrable_real_affine[of f c t]
hoelzl@56993
   652
    lborel_integrable_real_affine[of "\<lambda>x. f (t + c * x)" "1/c" "-t/c"]
hoelzl@56993
   653
  by (auto simp add: field_simps)
hoelzl@56993
   654
hoelzl@56993
   655
lemma lborel_integral_real_affine:
hoelzl@56993
   656
  fixes f :: "real \<Rightarrow> 'a :: {banach, second_countable_topology}" and c :: real
hoelzl@57166
   657
  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
   658
proof cases
hoelzl@57166
   659
  assume f[measurable]: "integrable lborel f" then show ?thesis
hoelzl@57166
   660
    using c f f[THEN borel_measurable_integrable] f[THEN lborel_integrable_real_affine, of c t]
hoelzl@57447
   661
    by (subst lborel_real_affine[OF c, of t])
hoelzl@57447
   662
       (simp add: integral_density integral_distr)
hoelzl@57166
   663
next
hoelzl@57166
   664
  assume "\<not> integrable lborel f" with c show ?thesis
hoelzl@57166
   665
    by (simp add: lborel_integrable_real_affine_iff not_integrable_integral_eq)
hoelzl@57166
   666
qed
hoelzl@56993
   667
hoelzl@63958
   668
lemma
hoelzl@63958
   669
  fixes c :: "'a::euclidean_space \<Rightarrow> real" and t
hoelzl@63958
   670
  assumes c: "\<And>j. j \<in> Basis \<Longrightarrow> c j \<noteq> 0"
hoelzl@63958
   671
  defines "T == (\<lambda>x. t + (\<Sum>j\<in>Basis. (c j * (x \<bullet> j)) *\<^sub>R j))"
hoelzl@63958
   672
  shows lebesgue_affine_euclidean: "lebesgue = density (distr lebesgue lebesgue T) (\<lambda>_. (\<Prod>j\<in>Basis. \<bar>c j\<bar>))" (is "_ = ?D")
hoelzl@63958
   673
    and lebesgue_affine_measurable: "T \<in> lebesgue \<rightarrow>\<^sub>M lebesgue"
hoelzl@63958
   674
proof -
hoelzl@63958
   675
  have T_borel[measurable]: "T \<in> borel \<rightarrow>\<^sub>M borel"
hoelzl@63958
   676
    by (auto simp: T_def[abs_def])
hoelzl@63958
   677
  { fix A :: "'a set" assume A: "A \<in> sets borel"
hoelzl@63958
   678
    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
   679
      unfolding T_def using c by (subst lborel_affine_euclidean[symmetric]) auto
hoelzl@63958
   680
    also have "\<dots> \<longleftrightarrow> emeasure (distr lebesgue lborel T) A = 0"
hoelzl@63958
   681
      using A c by (simp add: distr_completion emeasure_density nn_integral_cmult setprod_nonneg cong: distr_cong)
hoelzl@63958
   682
    finally have "emeasure lborel A = 0 \<longleftrightarrow> emeasure (distr lebesgue lborel T) A = 0" . }
hoelzl@63958
   683
  then have eq: "null_sets lborel = null_sets (distr lebesgue lborel T)"
hoelzl@63958
   684
    by (auto simp: null_sets_def)
hoelzl@63958
   685
hoelzl@63958
   686
  show "T \<in> lebesgue \<rightarrow>\<^sub>M lebesgue"
hoelzl@63958
   687
    by (rule completion.measurable_completion2) (auto simp: eq measurable_completion)
hoelzl@63958
   688
hoelzl@63958
   689
  have "lebesgue = completion (density (distr lborel borel T) (\<lambda>_. (\<Prod>j\<in>Basis. \<bar>c j\<bar>)))"
hoelzl@63958
   690
    using c by (subst lborel_affine_euclidean[of c t]) (simp_all add: T_def[abs_def])
hoelzl@63958
   691
  also have "\<dots> = density (completion (distr lebesgue lborel T)) (\<lambda>_. (\<Prod>j\<in>Basis. \<bar>c j\<bar>))"
hoelzl@63958
   692
    using c by (auto intro!: always_eventually setprod_pos completion_density_eq simp: distr_completion cong: distr_cong)
hoelzl@63958
   693
  also have "\<dots> = density (distr lebesgue lebesgue T) (\<lambda>_. (\<Prod>j\<in>Basis. \<bar>c j\<bar>))"
hoelzl@63958
   694
    by (subst completion.completion_distr_eq) (auto simp: eq measurable_completion)
hoelzl@63958
   695
  finally show "lebesgue = density (distr lebesgue lebesgue T) (\<lambda>_. (\<Prod>j\<in>Basis. \<bar>c j\<bar>))" .
hoelzl@63958
   696
qed
hoelzl@63958
   697
hoelzl@63958
   698
lemma
hoelzl@63958
   699
  fixes m :: real and \<delta> :: "'a::euclidean_space"
hoelzl@63958
   700
  defines "T r d x \<equiv> r *\<^sub>R x + d"
hoelzl@63958
   701
  shows emeasure_lebesgue_affine: "emeasure lebesgue (T m \<delta> ` S) = \<bar>m\<bar> ^ DIM('a) * emeasure lebesgue S" (is ?e)
hoelzl@63958
   702
    and measure_lebesgue_affine: "measure lebesgue (T m \<delta> ` S) = \<bar>m\<bar> ^ DIM('a) * measure lebesgue S" (is ?m)
hoelzl@63958
   703
proof -
hoelzl@63958
   704
  show ?e
hoelzl@63958
   705
  proof cases
hoelzl@63958
   706
    assume "m = 0" then show ?thesis
hoelzl@63958
   707
      by (simp add: image_constant_conv T_def[abs_def])
hoelzl@63958
   708
  next
hoelzl@63958
   709
    let ?T = "T m \<delta>" and ?T' = "T (1 / m) (- ((1/m) *\<^sub>R \<delta>))"
hoelzl@63958
   710
    assume "m \<noteq> 0"
hoelzl@63958
   711
    then have s_comp_s: "?T' \<circ> ?T = id" "?T \<circ> ?T' = id"
hoelzl@63958
   712
      by (auto simp: T_def[abs_def] fun_eq_iff scaleR_add_right scaleR_diff_right)
hoelzl@63958
   713
    then have "inv ?T' = ?T" "bij ?T'"
hoelzl@63958
   714
      by (auto intro: inv_unique_comp o_bij)
hoelzl@63958
   715
    then have eq: "T m \<delta> ` S = T (1 / m) ((-1/m) *\<^sub>R \<delta>) -` S \<inter> space lebesgue"
hoelzl@63958
   716
      using bij_vimage_eq_inv_image[OF \<open>bij ?T'\<close>, of S] by auto
hoelzl@63958
   717
hoelzl@63958
   718
    have trans_eq_T: "(\<lambda>x. \<delta> + (\<Sum>j\<in>Basis. (m * (x \<bullet> j)) *\<^sub>R j)) = T m \<delta>" for m \<delta>
hoelzl@63958
   719
      unfolding T_def[abs_def] scaleR_scaleR[symmetric] scaleR_setsum_right[symmetric]
hoelzl@63958
   720
      by (auto simp add: euclidean_representation ac_simps)
hoelzl@63958
   721
hoelzl@63958
   722
    have T[measurable]: "T r d \<in> lebesgue \<rightarrow>\<^sub>M lebesgue" for r d
hoelzl@63958
   723
      using lebesgue_affine_measurable[of "\<lambda>_. r" d]
hoelzl@63958
   724
      by (cases "r = 0") (auto simp: trans_eq_T T_def[abs_def])
hoelzl@63958
   725
hoelzl@63958
   726
    show ?thesis
hoelzl@63958
   727
    proof cases
hoelzl@63958
   728
      assume "S \<in> sets lebesgue" with \<open>m \<noteq> 0\<close> show ?thesis
hoelzl@63958
   729
        unfolding eq
hoelzl@63958
   730
        apply (subst lebesgue_affine_euclidean[of "\<lambda>_. m" \<delta>])
hoelzl@63958
   731
        apply (simp_all add: emeasure_density trans_eq_T nn_integral_cmult emeasure_distr
hoelzl@63958
   732
                        del: space_completion emeasure_completion)
hoelzl@63958
   733
        apply (simp add: vimage_comp s_comp_s setprod_constant)
hoelzl@63958
   734
        done
hoelzl@63958
   735
    next
hoelzl@63958
   736
      assume "S \<notin> sets lebesgue"
hoelzl@63958
   737
      moreover have "?T ` S \<notin> sets lebesgue"
hoelzl@63958
   738
      proof
hoelzl@63958
   739
        assume "?T ` S \<in> sets lebesgue"
hoelzl@63958
   740
        then have "?T -` (?T ` S) \<inter> space lebesgue \<in> sets lebesgue"
hoelzl@63958
   741
          by (rule measurable_sets[OF T])
hoelzl@63958
   742
        also have "?T -` (?T ` S) \<inter> space lebesgue = S"
hoelzl@63958
   743
          by (simp add: vimage_comp s_comp_s eq)
hoelzl@63958
   744
        finally show False using \<open>S \<notin> sets lebesgue\<close> by auto
hoelzl@63958
   745
      qed
hoelzl@63958
   746
      ultimately show ?thesis
hoelzl@63958
   747
        by (simp add: emeasure_notin_sets)
hoelzl@63958
   748
    qed
hoelzl@63958
   749
  qed
hoelzl@63958
   750
  show ?m
hoelzl@63958
   751
    unfolding measure_def \<open>?e\<close> by (simp add: enn2real_mult setprod_nonneg)
hoelzl@63958
   752
qed
hoelzl@63958
   753
lp15@60615
   754
lemma divideR_right:
hoelzl@56993
   755
  fixes x y :: "'a::real_normed_vector"
hoelzl@56993
   756
  shows "r \<noteq> 0 \<Longrightarrow> y = x /\<^sub>R r \<longleftrightarrow> r *\<^sub>R y = x"
hoelzl@56993
   757
  using scaleR_cancel_left[of r y "x /\<^sub>R r"] by simp
hoelzl@56993
   758
hoelzl@56993
   759
lemma lborel_has_bochner_integral_real_affine_iff:
hoelzl@56993
   760
  fixes x :: "'a :: {banach, second_countable_topology}"
hoelzl@56993
   761
  shows "c \<noteq> 0 \<Longrightarrow>
hoelzl@56993
   762
    has_bochner_integral lborel f x \<longleftrightarrow>
hoelzl@56993
   763
    has_bochner_integral lborel (\<lambda>x. f (t + c * x)) (x /\<^sub>R \<bar>c\<bar>)"
hoelzl@56993
   764
  unfolding has_bochner_integral_iff lborel_integrable_real_affine_iff
hoelzl@56993
   765
  by (simp_all add: lborel_integral_real_affine[symmetric] divideR_right cong: conj_cong)
hoelzl@49777
   766
hoelzl@59425
   767
lemma lborel_distr_uminus: "distr lborel borel uminus = (lborel :: real measure)"
lp15@60615
   768
  by (subst lborel_real_affine[of "-1" 0])
hoelzl@62975
   769
     (auto simp: density_1 one_ennreal_def[symmetric])
hoelzl@59425
   770
lp15@60615
   771
lemma lborel_distr_mult:
hoelzl@59425
   772
  assumes "(c::real) \<noteq> 0"
hoelzl@59425
   773
  shows "distr lborel borel (op * c) = density lborel (\<lambda>_. inverse \<bar>c\<bar>)"
hoelzl@59425
   774
proof-
hoelzl@59425
   775
  have "distr lborel borel (op * c) = distr lborel lborel (op * c)" by (simp cong: distr_cong)
hoelzl@59425
   776
  also from assms have "... = density lborel (\<lambda>_. inverse \<bar>c\<bar>)"
hoelzl@59425
   777
    by (subst lborel_real_affine[of "inverse c" 0]) (auto simp: o_def distr_density_distr)
hoelzl@59425
   778
  finally show ?thesis .
hoelzl@59425
   779
qed
hoelzl@59425
   780
lp15@60615
   781
lemma lborel_distr_mult':
hoelzl@59425
   782
  assumes "(c::real) \<noteq> 0"
wenzelm@61945
   783
  shows "lborel = density (distr lborel borel (op * c)) (\<lambda>_. \<bar>c\<bar>)"
hoelzl@59425
   784
proof-
hoelzl@59425
   785
  have "lborel = density lborel (\<lambda>_. 1)" by (rule density_1[symmetric])
hoelzl@62975
   786
  also from assms have "(\<lambda>_. 1 :: ennreal) = (\<lambda>_. inverse \<bar>c\<bar> * \<bar>c\<bar>)" by (intro ext) simp
wenzelm@61945
   787
  also have "density lborel ... = density (density lborel (\<lambda>_. inverse \<bar>c\<bar>)) (\<lambda>_. \<bar>c\<bar>)"
hoelzl@62975
   788
    by (subst density_density_eq) (auto simp: ennreal_mult)
wenzelm@61945
   789
  also from assms have "density lborel (\<lambda>_. inverse \<bar>c\<bar>) = distr lborel borel (op * c)"
hoelzl@59425
   790
    by (rule lborel_distr_mult[symmetric])
hoelzl@59425
   791
  finally show ?thesis .
hoelzl@59425
   792
qed
hoelzl@59425
   793
hoelzl@59425
   794
lemma lborel_distr_plus: "distr lborel borel (op + c) = (lborel :: real measure)"
hoelzl@62975
   795
  by (subst lborel_real_affine[of 1 c]) (auto simp: density_1 one_ennreal_def[symmetric])
hoelzl@59425
   796
wenzelm@61605
   797
interpretation lborel: sigma_finite_measure lborel
hoelzl@57447
   798
  by (rule sigma_finite_lborel)
hoelzl@57447
   799
hoelzl@57447
   800
interpretation lborel_pair: pair_sigma_finite lborel lborel ..
hoelzl@57447
   801
hoelzl@59425
   802
lemma lborel_prod:
hoelzl@59425
   803
  "lborel \<Otimes>\<^sub>M lborel = (lborel :: ('a::euclidean_space \<times> 'b::euclidean_space) measure)"
hoelzl@59425
   804
proof (rule lborel_eqI[symmetric], clarify)
hoelzl@59425
   805
  fix la ua :: 'a and lb ub :: 'b
hoelzl@59425
   806
  assume lu: "\<And>a b. (a, b) \<in> Basis \<Longrightarrow> (la, lb) \<bullet> (a, b) \<le> (ua, ub) \<bullet> (a, b)"
hoelzl@59425
   807
  have [simp]:
hoelzl@59425
   808
    "\<And>b. b \<in> Basis \<Longrightarrow> la \<bullet> b \<le> ua \<bullet> b"
hoelzl@59425
   809
    "\<And>b. b \<in> Basis \<Longrightarrow> lb \<bullet> b \<le> ub \<bullet> b"
hoelzl@59425
   810
    "inj_on (\<lambda>u. (u, 0)) Basis" "inj_on (\<lambda>u. (0, u)) Basis"
hoelzl@59425
   811
    "(\<lambda>u. (u, 0)) ` Basis \<inter> (\<lambda>u. (0, u)) ` Basis = {}"
hoelzl@59425
   812
    "box (la, lb) (ua, ub) = box la ua \<times> box lb ub"
hoelzl@59425
   813
    using lu[of _ 0] lu[of 0] by (auto intro!: inj_onI simp add: Basis_prod_def ball_Un box_def)
hoelzl@59425
   814
  show "emeasure (lborel \<Otimes>\<^sub>M lborel) (box (la, lb) (ua, ub)) =
hoelzl@62975
   815
      ennreal (setprod (op \<bullet> ((ua, ub) - (la, lb))) Basis)"
hoelzl@59425
   816
    by (simp add: lborel.emeasure_pair_measure_Times Basis_prod_def setprod.union_disjoint
hoelzl@62975
   817
                  setprod.reindex ennreal_mult inner_diff_left setprod_nonneg)
hoelzl@59425
   818
qed (simp add: borel_prod[symmetric])
hoelzl@59425
   819
hoelzl@57447
   820
(* FIXME: conversion in measurable prover *)
hoelzl@57447
   821
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
   822
lemma lborelD[measurable (raw)]: "A \<in> sets borel \<Longrightarrow> A \<in> sets lborel" by simp
hoelzl@57447
   823
hoelzl@57138
   824
lemma emeasure_bounded_finite:
hoelzl@57138
   825
  assumes "bounded A" shows "emeasure lborel A < \<infinity>"
hoelzl@57138
   826
proof -
wenzelm@61808
   827
  from bounded_subset_cbox[OF \<open>bounded A\<close>] obtain a b where "A \<subseteq> cbox a b"
hoelzl@57138
   828
    by auto
hoelzl@57138
   829
  then have "emeasure lborel A \<le> emeasure lborel (cbox a b)"
hoelzl@57138
   830
    by (intro emeasure_mono) auto
hoelzl@57138
   831
  then show ?thesis
hoelzl@62975
   832
    by (auto simp: emeasure_lborel_cbox_eq setprod_nonneg less_top[symmetric] top_unique split: if_split_asm)
hoelzl@57138
   833
qed
hoelzl@57138
   834
hoelzl@57138
   835
lemma emeasure_compact_finite: "compact A \<Longrightarrow> emeasure lborel A < \<infinity>"
hoelzl@57138
   836
  using emeasure_bounded_finite[of A] by (auto intro: compact_imp_bounded)
hoelzl@57138
   837
hoelzl@57138
   838
lemma borel_integrable_compact:
hoelzl@57447
   839
  fixes f :: "'a::euclidean_space \<Rightarrow> 'b::{banach, second_countable_topology}"
hoelzl@57138
   840
  assumes "compact S" "continuous_on S f"
hoelzl@57138
   841
  shows "integrable lborel (\<lambda>x. indicator S x *\<^sub>R f x)"
hoelzl@57138
   842
proof cases
hoelzl@57138
   843
  assume "S \<noteq> {}"
hoelzl@57138
   844
  have "continuous_on S (\<lambda>x. norm (f x))"
hoelzl@57138
   845
    using assms by (intro continuous_intros)
wenzelm@61808
   846
  from continuous_attains_sup[OF \<open>compact S\<close> \<open>S \<noteq> {}\<close> this]
hoelzl@57138
   847
  obtain M where M: "\<And>x. x \<in> S \<Longrightarrow> norm (f x) \<le> M"
hoelzl@57138
   848
    by auto
hoelzl@57138
   849
hoelzl@57138
   850
  show ?thesis
hoelzl@57138
   851
  proof (rule integrable_bound)
hoelzl@57138
   852
    show "integrable lborel (\<lambda>x. indicator S x * M)"
hoelzl@57138
   853
      using assms by (auto intro!: emeasure_compact_finite borel_compact integrable_mult_left)
hoelzl@57138
   854
    show "(\<lambda>x. indicator S x *\<^sub>R f x) \<in> borel_measurable lborel"
hoelzl@57138
   855
      using assms by (auto intro!: borel_measurable_continuous_on_indicator borel_compact)
hoelzl@57138
   856
    show "AE x in lborel. norm (indicator S x *\<^sub>R f x) \<le> norm (indicator S x * M)"
hoelzl@57138
   857
      by (auto split: split_indicator simp: abs_real_def dest!: M)
hoelzl@57138
   858
  qed
hoelzl@57138
   859
qed simp
hoelzl@57138
   860
hoelzl@50418
   861
lemma borel_integrable_atLeastAtMost:
hoelzl@56993
   862
  fixes f :: "real \<Rightarrow> real"
hoelzl@50418
   863
  assumes f: "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> isCont f x"
hoelzl@50418
   864
  shows "integrable lborel (\<lambda>x. f x * indicator {a .. b} x)" (is "integrable _ ?f")
hoelzl@57138
   865
proof -
hoelzl@57138
   866
  have "integrable lborel (\<lambda>x. indicator {a .. b} x *\<^sub>R f x)"
hoelzl@57138
   867
  proof (rule borel_integrable_compact)
hoelzl@57138
   868
    from f show "continuous_on {a..b} f"
hoelzl@57138
   869
      by (auto intro: continuous_at_imp_continuous_on)
hoelzl@57138
   870
  qed simp
hoelzl@57138
   871
  then show ?thesis
haftmann@57512
   872
    by (auto simp: mult.commute)
hoelzl@57138
   873
qed
hoelzl@50418
   874
hoelzl@63958
   875
abbreviation lmeasurable :: "'a::euclidean_space set set"
hoelzl@63958
   876
where
hoelzl@63958
   877
  "lmeasurable \<equiv> fmeasurable lebesgue"
hoelzl@63958
   878
hoelzl@63958
   879
lemma lmeasurable_iff_integrable:
hoelzl@63958
   880
  "S \<in> lmeasurable \<longleftrightarrow> integrable lebesgue (indicator S :: 'a::euclidean_space \<Rightarrow> real)"
hoelzl@63958
   881
  by (auto simp: fmeasurable_def integrable_iff_bounded borel_measurable_indicator_iff ennreal_indicator)
hoelzl@63958
   882
hoelzl@63958
   883
lemma lmeasurable_cbox [iff]: "cbox a b \<in> lmeasurable"
hoelzl@63958
   884
  and lmeasurable_box [iff]: "box a b \<in> lmeasurable"
hoelzl@63958
   885
  by (auto simp: fmeasurable_def emeasure_lborel_box_eq emeasure_lborel_cbox_eq)
hoelzl@63958
   886
hoelzl@38656
   887
end