src/HOL/Probability/Lebesgue_Measure.thy
author hoelzl
Wed Feb 23 11:40:12 2011 +0100 (2011-02-23)
changeset 41831 91a2b435dd7a
parent 41706 a207a858d1f6
child 41981 cdf7693bbe08
permissions -rw-r--r--
use measure_preserving in ..._vimage lemmas
hoelzl@40859
     1
(*  Author: Robert Himmelmann, TU Muenchen *)
hoelzl@38656
     2
header {* Lebsegue measure *}
hoelzl@38656
     3
theory Lebesgue_Measure
hoelzl@41689
     4
  imports Product_Measure
hoelzl@38656
     5
begin
hoelzl@38656
     6
hoelzl@38656
     7
subsection {* Standard Cubes *}
hoelzl@38656
     8
hoelzl@40859
     9
definition cube :: "nat \<Rightarrow> 'a::ordered_euclidean_space set" where
hoelzl@40859
    10
  "cube n \<equiv> {\<chi>\<chi> i. - real n .. \<chi>\<chi> i. real n}"
hoelzl@40859
    11
hoelzl@40859
    12
lemma cube_closed[intro]: "closed (cube n)"
hoelzl@40859
    13
  unfolding cube_def by auto
hoelzl@40859
    14
hoelzl@40859
    15
lemma cube_subset[intro]: "n \<le> N \<Longrightarrow> cube n \<subseteq> cube N"
hoelzl@40859
    16
  by (fastsimp simp: eucl_le[where 'a='a] cube_def)
hoelzl@38656
    17
hoelzl@40859
    18
lemma cube_subset_iff:
hoelzl@40859
    19
  "cube n \<subseteq> cube N \<longleftrightarrow> n \<le> N"
hoelzl@40859
    20
proof
hoelzl@40859
    21
  assume subset: "cube n \<subseteq> (cube N::'a set)"
hoelzl@40859
    22
  then have "((\<chi>\<chi> i. real n)::'a) \<in> cube N"
hoelzl@40859
    23
    using DIM_positive[where 'a='a]
hoelzl@40859
    24
    by (fastsimp simp: cube_def eucl_le[where 'a='a])
hoelzl@40859
    25
  then show "n \<le> N"
hoelzl@40859
    26
    by (fastsimp simp: cube_def eucl_le[where 'a='a])
hoelzl@40859
    27
next
hoelzl@40859
    28
  assume "n \<le> N" then show "cube n \<subseteq> (cube N::'a set)" by (rule cube_subset)
hoelzl@40859
    29
qed
hoelzl@38656
    30
hoelzl@38656
    31
lemma ball_subset_cube:"ball (0::'a::ordered_euclidean_space) (real n) \<subseteq> cube n"
hoelzl@38656
    32
  unfolding cube_def subset_eq mem_interval apply safe unfolding euclidean_lambda_beta'
hoelzl@38656
    33
proof- fix x::'a and i assume as:"x\<in>ball 0 (real n)" "i<DIM('a)"
hoelzl@38656
    34
  thus "- real n \<le> x $$ i" "real n \<ge> x $$ i"
hoelzl@38656
    35
    using component_le_norm[of x i] by(auto simp: dist_norm)
hoelzl@38656
    36
qed
hoelzl@38656
    37
hoelzl@38656
    38
lemma mem_big_cube: obtains n where "x \<in> cube n"
hoelzl@38656
    39
proof- from real_arch_lt[of "norm x"] guess n ..
hoelzl@38656
    40
  thus ?thesis apply-apply(rule that[where n=n])
hoelzl@38656
    41
    apply(rule ball_subset_cube[unfolded subset_eq,rule_format])
hoelzl@38656
    42
    by (auto simp add:dist_norm)
hoelzl@38656
    43
qed
hoelzl@38656
    44
hoelzl@41689
    45
lemma cube_subset_Suc[intro]: "cube n \<subseteq> cube (Suc n)"
hoelzl@41689
    46
  unfolding cube_def_raw subset_eq apply safe unfolding mem_interval by auto
hoelzl@41654
    47
hoelzl@41689
    48
lemma Pi_iff: "f \<in> Pi I X \<longleftrightarrow> (\<forall>i\<in>I. f i \<in> X i)"
hoelzl@41689
    49
  unfolding Pi_def by auto
hoelzl@41689
    50
hoelzl@41706
    51
subsection {* Lebesgue measure *}
hoelzl@41706
    52
hoelzl@41689
    53
definition lebesgue :: "'a::ordered_euclidean_space measure_space" where
hoelzl@41689
    54
  "lebesgue = \<lparr> space = UNIV,
hoelzl@41689
    55
    sets = {A. \<forall>n. (indicator A :: 'a \<Rightarrow> real) integrable_on cube n},
hoelzl@41689
    56
    measure = \<lambda>A. SUP n. Real (integral (cube n) (indicator A)) \<rparr>"
hoelzl@41661
    57
hoelzl@41654
    58
lemma space_lebesgue[simp]: "space lebesgue = UNIV"
hoelzl@41654
    59
  unfolding lebesgue_def by simp
hoelzl@41654
    60
hoelzl@41654
    61
lemma lebesgueD: "A \<in> sets lebesgue \<Longrightarrow> (indicator A :: _ \<Rightarrow> real) integrable_on cube n"
hoelzl@41654
    62
  unfolding lebesgue_def by simp
hoelzl@41654
    63
hoelzl@41654
    64
lemma lebesgueI: "(\<And>n. (indicator A :: _ \<Rightarrow> real) integrable_on cube n) \<Longrightarrow> A \<in> sets lebesgue"
hoelzl@41654
    65
  unfolding lebesgue_def by simp
hoelzl@41654
    66
hoelzl@41654
    67
lemma absolutely_integrable_on_indicator[simp]:
hoelzl@41654
    68
  fixes A :: "'a::ordered_euclidean_space set"
hoelzl@41654
    69
  shows "((indicator A :: _ \<Rightarrow> real) absolutely_integrable_on X) \<longleftrightarrow>
hoelzl@41654
    70
    (indicator A :: _ \<Rightarrow> real) integrable_on X"
hoelzl@41654
    71
  unfolding absolutely_integrable_on_def by simp
hoelzl@41654
    72
hoelzl@41654
    73
lemma LIMSEQ_indicator_UN:
hoelzl@41654
    74
  "(\<lambda>k. indicator (\<Union> i<k. A i) x) ----> (indicator (\<Union>i. A i) x :: real)"
hoelzl@41654
    75
proof cases
hoelzl@41654
    76
  assume "\<exists>i. x \<in> A i" then guess i .. note i = this
hoelzl@41654
    77
  then have *: "\<And>n. (indicator (\<Union> i<n + Suc i. A i) x :: real) = 1"
hoelzl@41654
    78
    "(indicator (\<Union> i. A i) x :: real) = 1" by (auto simp: indicator_def)
hoelzl@41654
    79
  show ?thesis
hoelzl@41654
    80
    apply (rule LIMSEQ_offset[of _ "Suc i"]) unfolding * by auto
hoelzl@41654
    81
qed (auto simp: indicator_def)
hoelzl@38656
    82
hoelzl@41654
    83
lemma indicator_add:
hoelzl@41654
    84
  "A \<inter> B = {} \<Longrightarrow> (indicator A x::_::monoid_add) + indicator B x = indicator (A \<union> B) x"
hoelzl@41654
    85
  unfolding indicator_def by auto
hoelzl@38656
    86
hoelzl@41654
    87
interpretation lebesgue: sigma_algebra lebesgue
hoelzl@41654
    88
proof (intro sigma_algebra_iff2[THEN iffD2] conjI allI ballI impI lebesgueI)
hoelzl@41654
    89
  fix A n assume A: "A \<in> sets lebesgue"
hoelzl@41654
    90
  have "indicator (space lebesgue - A) = (\<lambda>x. 1 - indicator A x :: real)"
hoelzl@41654
    91
    by (auto simp: fun_eq_iff indicator_def)
hoelzl@41654
    92
  then show "(indicator (space lebesgue - A) :: _ \<Rightarrow> real) integrable_on cube n"
hoelzl@41654
    93
    using A by (auto intro!: integrable_sub dest: lebesgueD simp: cube_def)
hoelzl@41654
    94
next
hoelzl@41654
    95
  fix n show "(indicator {} :: _\<Rightarrow>real) integrable_on cube n"
hoelzl@41654
    96
    by (auto simp: cube_def indicator_def_raw)
hoelzl@41654
    97
next
hoelzl@41654
    98
  fix A :: "nat \<Rightarrow> 'a set" and n ::nat assume "range A \<subseteq> sets lebesgue"
hoelzl@41654
    99
  then have A: "\<And>i. (indicator (A i) :: _ \<Rightarrow> real) integrable_on cube n"
hoelzl@41654
   100
    by (auto dest: lebesgueD)
hoelzl@41654
   101
  show "(indicator (\<Union>i. A i) :: _ \<Rightarrow> real) integrable_on cube n" (is "?g integrable_on _")
hoelzl@41654
   102
  proof (intro dominated_convergence[where g="?g"] ballI)
hoelzl@41654
   103
    fix k show "(indicator (\<Union>i<k. A i) :: _ \<Rightarrow> real) integrable_on cube n"
hoelzl@41654
   104
    proof (induct k)
hoelzl@41654
   105
      case (Suc k)
hoelzl@41654
   106
      have *: "(\<Union> i<Suc k. A i) = (\<Union> i<k. A i) \<union> A k"
hoelzl@41654
   107
        unfolding lessThan_Suc UN_insert by auto
hoelzl@41654
   108
      have *: "(\<lambda>x. max (indicator (\<Union> i<k. A i) x) (indicator (A k) x) :: real) =
hoelzl@41654
   109
          indicator (\<Union> i<Suc k. A i)" (is "(\<lambda>x. max (?f x) (?g x)) = _")
hoelzl@41654
   110
        by (auto simp: fun_eq_iff * indicator_def)
hoelzl@41654
   111
      show ?case
hoelzl@41654
   112
        using absolutely_integrable_max[of ?f "cube n" ?g] A Suc by (simp add: *)
hoelzl@41654
   113
    qed auto
hoelzl@41654
   114
  qed (auto intro: LIMSEQ_indicator_UN simp: cube_def)
hoelzl@41654
   115
qed simp
hoelzl@38656
   116
hoelzl@41689
   117
interpretation lebesgue: measure_space lebesgue
hoelzl@41654
   118
proof
hoelzl@41654
   119
  have *: "indicator {} = (\<lambda>x. 0 :: real)" by (simp add: fun_eq_iff)
hoelzl@41689
   120
  show "measure lebesgue {} = 0" by (simp add: integral_0 * lebesgue_def)
hoelzl@40859
   121
next
hoelzl@41689
   122
  show "countably_additive lebesgue (measure lebesgue)"
hoelzl@41654
   123
  proof (intro countably_additive_def[THEN iffD2] allI impI)
hoelzl@41654
   124
    fix A :: "nat \<Rightarrow> 'b set" assume rA: "range A \<subseteq> sets lebesgue" "disjoint_family A"
hoelzl@41654
   125
    then have A[simp, intro]: "\<And>i n. (indicator (A i) :: _ \<Rightarrow> real) integrable_on cube n"
hoelzl@41654
   126
      by (auto dest: lebesgueD)
hoelzl@41654
   127
    let "?m n i" = "integral (cube n) (indicator (A i) :: _\<Rightarrow>real)"
hoelzl@41654
   128
    let "?M n I" = "integral (cube n) (indicator (\<Union>i\<in>I. A i) :: _\<Rightarrow>real)"
hoelzl@41654
   129
    have nn[simp, intro]: "\<And>i n. 0 \<le> ?m n i" by (auto intro!: integral_nonneg)
hoelzl@41654
   130
    assume "(\<Union>i. A i) \<in> sets lebesgue"
hoelzl@41654
   131
    then have UN_A[simp, intro]: "\<And>i n. (indicator (\<Union>i. A i) :: _ \<Rightarrow> real) integrable_on cube n"
hoelzl@41654
   132
      by (auto dest: lebesgueD)
hoelzl@41689
   133
    show "(\<Sum>\<^isub>\<infinity>n. measure lebesgue (A n)) = measure lebesgue (\<Union>i. A i)"
hoelzl@41689
   134
    proof (simp add: lebesgue_def, subst psuminf_SUP_eq)
hoelzl@41654
   135
      fix n i show "Real (?m n i) \<le> Real (?m (Suc n) i)"
hoelzl@41654
   136
        using cube_subset[of n "Suc n"] by (auto intro!: integral_subset_le)
hoelzl@41654
   137
    next
hoelzl@41654
   138
      show "(SUP n. \<Sum>\<^isub>\<infinity>i. Real (?m n i)) = (SUP n. Real (?M n UNIV))"
hoelzl@41654
   139
        unfolding psuminf_def
hoelzl@41654
   140
      proof (subst setsum_Real, (intro arg_cong[where f="SUPR UNIV"] ext ballI nn SUP_eq_LIMSEQ[THEN iffD2])+)
hoelzl@41654
   141
        fix n :: nat show "mono (\<lambda>m. \<Sum>x<m. ?m n x)"
hoelzl@41654
   142
        proof (intro mono_iff_le_Suc[THEN iffD2] allI)
hoelzl@41654
   143
          fix m show "(\<Sum>x<m. ?m n x) \<le> (\<Sum>x<Suc m. ?m n x)"
hoelzl@41654
   144
            using nn[of n m] by auto
hoelzl@41654
   145
        qed
hoelzl@41654
   146
        show "0 \<le> ?M n UNIV"
hoelzl@41654
   147
          using UN_A by (auto intro!: integral_nonneg)
hoelzl@41654
   148
        fix m show "0 \<le> (\<Sum>x<m. ?m n x)" by (auto intro!: setsum_nonneg)
hoelzl@41654
   149
      next
hoelzl@41654
   150
        fix n
hoelzl@41654
   151
        have "\<And>m. (UNION {..<m} A) \<in> sets lebesgue" using rA by auto
hoelzl@41654
   152
        from lebesgueD[OF this]
hoelzl@41654
   153
        have "(\<lambda>m. ?M n {..< m}) ----> ?M n UNIV"
hoelzl@41654
   154
          (is "(\<lambda>m. integral _ (?A m)) ----> ?I")
hoelzl@41654
   155
          by (intro dominated_convergence(2)[where f="?A" and h="\<lambda>x. 1::real"])
hoelzl@41654
   156
             (auto intro: LIMSEQ_indicator_UN simp: cube_def)
hoelzl@41654
   157
        moreover
hoelzl@41654
   158
        { fix m have *: "(\<Sum>x<m. ?m n x) = ?M n {..< m}"
hoelzl@41654
   159
          proof (induct m)
hoelzl@41654
   160
            case (Suc m)
hoelzl@41654
   161
            have "(\<Union>i<m. A i) \<in> sets lebesgue" using rA by auto
hoelzl@41654
   162
            then have "(indicator (\<Union>i<m. A i) :: _\<Rightarrow>real) integrable_on (cube n)"
hoelzl@41654
   163
              by (auto dest!: lebesgueD)
hoelzl@41654
   164
            moreover
hoelzl@41654
   165
            have "(\<Union>i<m. A i) \<inter> A m = {}"
hoelzl@41654
   166
              using rA(2)[unfolded disjoint_family_on_def, THEN bspec, of m]
hoelzl@41654
   167
              by auto
hoelzl@41654
   168
            then have "\<And>x. indicator (\<Union>i<Suc m. A i) x =
hoelzl@41654
   169
              indicator (\<Union>i<m. A i) x + (indicator (A m) x :: real)"
hoelzl@41654
   170
              by (auto simp: indicator_add lessThan_Suc ac_simps)
hoelzl@41654
   171
            ultimately show ?case
hoelzl@41654
   172
              using Suc A by (simp add: integral_add[symmetric])
hoelzl@41654
   173
          qed auto }
hoelzl@41654
   174
        ultimately show "(\<lambda>m. \<Sum>x<m. ?m n x) ----> ?M n UNIV"
hoelzl@41654
   175
          by simp
hoelzl@41654
   176
      qed
hoelzl@41654
   177
    qed
hoelzl@41654
   178
  qed
hoelzl@40859
   179
qed
hoelzl@40859
   180
hoelzl@41654
   181
lemma has_integral_interval_cube:
hoelzl@41654
   182
  fixes a b :: "'a::ordered_euclidean_space"
hoelzl@41654
   183
  shows "(indicator {a .. b} has_integral
hoelzl@41654
   184
    content ({\<chi>\<chi> i. max (- real n) (a $$ i) .. \<chi>\<chi> i. min (real n) (b $$ i)} :: 'a set)) (cube n)"
hoelzl@41654
   185
    (is "(?I has_integral content ?R) (cube n)")
hoelzl@40859
   186
proof -
hoelzl@41654
   187
  let "{?N .. ?P}" = ?R
hoelzl@41654
   188
  have [simp]: "(\<lambda>x. if x \<in> cube n then ?I x else 0) = indicator ?R"
hoelzl@41654
   189
    by (auto simp: indicator_def cube_def fun_eq_iff eucl_le[where 'a='a])
hoelzl@41654
   190
  have "(?I has_integral content ?R) (cube n) \<longleftrightarrow> (indicator ?R has_integral content ?R) UNIV"
hoelzl@41654
   191
    unfolding has_integral_restrict_univ[where s="cube n", symmetric] by simp
hoelzl@41654
   192
  also have "\<dots> \<longleftrightarrow> ((\<lambda>x. 1) has_integral content ?R) ?R"
hoelzl@41654
   193
    unfolding indicator_def_raw has_integral_restrict_univ ..
hoelzl@41654
   194
  finally show ?thesis
hoelzl@41654
   195
    using has_integral_const[of "1::real" "?N" "?P"] by simp
hoelzl@40859
   196
qed
hoelzl@38656
   197
hoelzl@41654
   198
lemma lebesgueI_borel[intro, simp]:
hoelzl@41654
   199
  fixes s::"'a::ordered_euclidean_space set"
hoelzl@40859
   200
  assumes "s \<in> sets borel" shows "s \<in> sets lebesgue"
hoelzl@41654
   201
proof -
hoelzl@41654
   202
  let ?S = "range (\<lambda>(a, b). {a .. (b :: 'a\<Colon>ordered_euclidean_space)})"
hoelzl@41654
   203
  have *:"?S \<subseteq> sets lebesgue"
hoelzl@41654
   204
  proof (safe intro!: lebesgueI)
hoelzl@41654
   205
    fix n :: nat and a b :: 'a
hoelzl@41654
   206
    let ?N = "\<chi>\<chi> i. max (- real n) (a $$ i)"
hoelzl@41654
   207
    let ?P = "\<chi>\<chi> i. min (real n) (b $$ i)"
hoelzl@41654
   208
    show "(indicator {a..b} :: 'a\<Rightarrow>real) integrable_on cube n"
hoelzl@41654
   209
      unfolding integrable_on_def
hoelzl@41654
   210
      using has_integral_interval_cube[of a b] by auto
hoelzl@41654
   211
  qed
hoelzl@40859
   212
  have "s \<in> sigma_sets UNIV ?S" using assms
hoelzl@40859
   213
    unfolding borel_eq_atLeastAtMost by (simp add: sigma_def)
hoelzl@40859
   214
  thus ?thesis
hoelzl@40859
   215
    using lebesgue.sigma_subset[of "\<lparr> space = UNIV, sets = ?S\<rparr>", simplified, OF *]
hoelzl@40859
   216
    by (auto simp: sigma_def)
hoelzl@38656
   217
qed
hoelzl@38656
   218
hoelzl@40859
   219
lemma lebesgueI_negligible[dest]: fixes s::"'a::ordered_euclidean_space set"
hoelzl@40859
   220
  assumes "negligible s" shows "s \<in> sets lebesgue"
hoelzl@41654
   221
  using assms by (force simp: cube_def integrable_on_def negligible_def intro!: lebesgueI)
hoelzl@38656
   222
hoelzl@41654
   223
lemma lmeasure_eq_0:
hoelzl@41689
   224
  fixes S :: "'a::ordered_euclidean_space set" assumes "negligible S" shows "lebesgue.\<mu> S = 0"
hoelzl@40859
   225
proof -
hoelzl@41654
   226
  have "\<And>n. integral (cube n) (indicator S :: 'a\<Rightarrow>real) = 0"
hoelzl@41689
   227
    unfolding lebesgue_integral_def using assms
hoelzl@41689
   228
    by (intro integral_unique some1_equality ex_ex1I)
hoelzl@41689
   229
       (auto simp: cube_def negligible_def)
hoelzl@41689
   230
  then show ?thesis by (auto simp: lebesgue_def)
hoelzl@40859
   231
qed
hoelzl@40859
   232
hoelzl@40859
   233
lemma lmeasure_iff_LIMSEQ:
hoelzl@40859
   234
  assumes "A \<in> sets lebesgue" "0 \<le> m"
hoelzl@41689
   235
  shows "lebesgue.\<mu> A = Real m \<longleftrightarrow> (\<lambda>n. integral (cube n) (indicator A :: _ \<Rightarrow> real)) ----> m"
hoelzl@41689
   236
proof (simp add: lebesgue_def, intro SUP_eq_LIMSEQ)
hoelzl@41654
   237
  show "mono (\<lambda>n. integral (cube n) (indicator A::_=>real))"
hoelzl@41654
   238
    using cube_subset assms by (intro monoI integral_subset_le) (auto dest!: lebesgueD)
hoelzl@41654
   239
  fix n show "0 \<le> integral (cube n) (indicator A::_=>real)"
hoelzl@41654
   240
    using assms by (auto dest!: lebesgueD intro!: integral_nonneg)
hoelzl@41654
   241
qed fact
hoelzl@38656
   242
hoelzl@41654
   243
lemma has_integral_indicator_UNIV:
hoelzl@41654
   244
  fixes s A :: "'a::ordered_euclidean_space set" and x :: real
hoelzl@41654
   245
  shows "((indicator (s \<inter> A) :: 'a\<Rightarrow>real) has_integral x) UNIV = ((indicator s :: _\<Rightarrow>real) has_integral x) A"
hoelzl@41654
   246
proof -
hoelzl@41654
   247
  have "(\<lambda>x. if x \<in> A then indicator s x else 0) = (indicator (s \<inter> A) :: _\<Rightarrow>real)"
hoelzl@41654
   248
    by (auto simp: fun_eq_iff indicator_def)
hoelzl@41654
   249
  then show ?thesis
hoelzl@41654
   250
    unfolding has_integral_restrict_univ[where s=A, symmetric] by simp
hoelzl@40859
   251
qed
hoelzl@38656
   252
hoelzl@41654
   253
lemma
hoelzl@41654
   254
  fixes s a :: "'a::ordered_euclidean_space set"
hoelzl@41654
   255
  shows integral_indicator_UNIV:
hoelzl@41654
   256
    "integral UNIV (indicator (s \<inter> A) :: 'a\<Rightarrow>real) = integral A (indicator s :: _\<Rightarrow>real)"
hoelzl@41654
   257
  and integrable_indicator_UNIV:
hoelzl@41654
   258
    "(indicator (s \<inter> A) :: 'a\<Rightarrow>real) integrable_on UNIV \<longleftrightarrow> (indicator s :: 'a\<Rightarrow>real) integrable_on A"
hoelzl@41654
   259
  unfolding integral_def integrable_on_def has_integral_indicator_UNIV by auto
hoelzl@41654
   260
hoelzl@41654
   261
lemma lmeasure_finite_has_integral:
hoelzl@41654
   262
  fixes s :: "'a::ordered_euclidean_space set"
hoelzl@41689
   263
  assumes "s \<in> sets lebesgue" "lebesgue.\<mu> s = Real m" "0 \<le> m"
hoelzl@41654
   264
  shows "(indicator s has_integral m) UNIV"
hoelzl@41654
   265
proof -
hoelzl@41654
   266
  let ?I = "indicator :: 'a set \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@41654
   267
  have **: "(?I s) integrable_on UNIV \<and> (\<lambda>k. integral UNIV (?I (s \<inter> cube k))) ----> integral UNIV (?I s)"
hoelzl@41654
   268
  proof (intro monotone_convergence_increasing allI ballI)
hoelzl@41654
   269
    have LIMSEQ: "(\<lambda>n. integral (cube n) (?I s)) ----> m"
hoelzl@41654
   270
      using assms(2) unfolding lmeasure_iff_LIMSEQ[OF assms(1, 3)] .
hoelzl@41654
   271
    { fix n have "integral (cube n) (?I s) \<le> m"
hoelzl@41654
   272
        using cube_subset assms
hoelzl@41654
   273
        by (intro incseq_le[where L=m] LIMSEQ incseq_def[THEN iffD2] integral_subset_le allI impI)
hoelzl@41654
   274
           (auto dest!: lebesgueD) }
hoelzl@41654
   275
    moreover
hoelzl@41654
   276
    { fix n have "0 \<le> integral (cube n) (?I s)"
hoelzl@41654
   277
      using assms by (auto dest!: lebesgueD intro!: integral_nonneg) }
hoelzl@41654
   278
    ultimately
hoelzl@41654
   279
    show "bounded {integral UNIV (?I (s \<inter> cube k)) |k. True}"
hoelzl@41654
   280
      unfolding bounded_def
hoelzl@41654
   281
      apply (rule_tac exI[of _ 0])
hoelzl@41654
   282
      apply (rule_tac exI[of _ m])
hoelzl@41654
   283
      by (auto simp: dist_real_def integral_indicator_UNIV)
hoelzl@41654
   284
    fix k show "?I (s \<inter> cube k) integrable_on UNIV"
hoelzl@41654
   285
      unfolding integrable_indicator_UNIV using assms by (auto dest!: lebesgueD)
hoelzl@41654
   286
    fix x show "?I (s \<inter> cube k) x \<le> ?I (s \<inter> cube (Suc k)) x"
hoelzl@41654
   287
      using cube_subset[of k "Suc k"] by (auto simp: indicator_def)
hoelzl@41654
   288
  next
hoelzl@41654
   289
    fix x :: 'a
hoelzl@41654
   290
    from mem_big_cube obtain k where k: "x \<in> cube k" .
hoelzl@41654
   291
    { fix n have "?I (s \<inter> cube (n + k)) x = ?I s x"
hoelzl@41654
   292
      using k cube_subset[of k "n + k"] by (auto simp: indicator_def) }
hoelzl@41654
   293
    note * = this
hoelzl@41654
   294
    show "(\<lambda>k. ?I (s \<inter> cube k) x) ----> ?I s x"
hoelzl@41654
   295
      by (rule LIMSEQ_offset[where k=k]) (auto simp: *)
hoelzl@41654
   296
  qed
hoelzl@41654
   297
  note ** = conjunctD2[OF this]
hoelzl@41654
   298
  have m: "m = integral UNIV (?I s)"
hoelzl@41654
   299
    apply (intro LIMSEQ_unique[OF _ **(2)])
hoelzl@41654
   300
    using assms(2) unfolding lmeasure_iff_LIMSEQ[OF assms(1,3)] integral_indicator_UNIV .
hoelzl@41654
   301
  show ?thesis
hoelzl@41654
   302
    unfolding m by (intro integrable_integral **)
hoelzl@38656
   303
qed
hoelzl@38656
   304
hoelzl@41689
   305
lemma lmeasure_finite_integrable: assumes "s \<in> sets lebesgue" "lebesgue.\<mu> s \<noteq> \<omega>"
hoelzl@41654
   306
  shows "(indicator s :: _ \<Rightarrow> real) integrable_on UNIV"
hoelzl@41689
   307
proof (cases "lebesgue.\<mu> s")
hoelzl@41654
   308
  case (preal m) from lmeasure_finite_has_integral[OF `s \<in> sets lebesgue` this]
hoelzl@41654
   309
  show ?thesis unfolding integrable_on_def by auto
hoelzl@40859
   310
qed (insert assms, auto)
hoelzl@38656
   311
hoelzl@41654
   312
lemma has_integral_lebesgue: assumes "((indicator s :: _\<Rightarrow>real) has_integral m) UNIV"
hoelzl@41654
   313
  shows "s \<in> sets lebesgue"
hoelzl@41654
   314
proof (intro lebesgueI)
hoelzl@41654
   315
  let ?I = "indicator :: 'a set \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@41654
   316
  fix n show "(?I s) integrable_on cube n" unfolding cube_def
hoelzl@41654
   317
  proof (intro integrable_on_subinterval)
hoelzl@41654
   318
    show "(?I s) integrable_on UNIV"
hoelzl@41654
   319
      unfolding integrable_on_def using assms by auto
hoelzl@41654
   320
  qed auto
hoelzl@38656
   321
qed
hoelzl@38656
   322
hoelzl@41654
   323
lemma has_integral_lmeasure: assumes "((indicator s :: _\<Rightarrow>real) has_integral m) UNIV"
hoelzl@41689
   324
  shows "lebesgue.\<mu> s = Real m"
hoelzl@41654
   325
proof (intro lmeasure_iff_LIMSEQ[THEN iffD2])
hoelzl@41654
   326
  let ?I = "indicator :: 'a set \<Rightarrow> 'a \<Rightarrow> real"
hoelzl@41654
   327
  show "s \<in> sets lebesgue" using has_integral_lebesgue[OF assms] .
hoelzl@41654
   328
  show "0 \<le> m" using assms by (rule has_integral_nonneg) auto
hoelzl@41654
   329
  have "(\<lambda>n. integral UNIV (?I (s \<inter> cube n))) ----> integral UNIV (?I s)"
hoelzl@41654
   330
  proof (intro dominated_convergence(2) ballI)
hoelzl@41654
   331
    show "(?I s) integrable_on UNIV" unfolding integrable_on_def using assms by auto
hoelzl@41654
   332
    fix n show "?I (s \<inter> cube n) integrable_on UNIV"
hoelzl@41654
   333
      unfolding integrable_indicator_UNIV using `s \<in> sets lebesgue` by (auto dest: lebesgueD)
hoelzl@41654
   334
    fix x show "norm (?I (s \<inter> cube n) x) \<le> ?I s x" by (auto simp: indicator_def)
hoelzl@41654
   335
  next
hoelzl@41654
   336
    fix x :: 'a
hoelzl@41654
   337
    from mem_big_cube obtain k where k: "x \<in> cube k" .
hoelzl@41654
   338
    { fix n have "?I (s \<inter> cube (n + k)) x = ?I s x"
hoelzl@41654
   339
      using k cube_subset[of k "n + k"] by (auto simp: indicator_def) }
hoelzl@41654
   340
    note * = this
hoelzl@41654
   341
    show "(\<lambda>k. ?I (s \<inter> cube k) x) ----> ?I s x"
hoelzl@41654
   342
      by (rule LIMSEQ_offset[where k=k]) (auto simp: *)
hoelzl@41654
   343
  qed
hoelzl@41654
   344
  then show "(\<lambda>n. integral (cube n) (?I s)) ----> m"
hoelzl@41654
   345
    unfolding integral_unique[OF assms] integral_indicator_UNIV by simp
hoelzl@41654
   346
qed
hoelzl@41654
   347
hoelzl@41654
   348
lemma has_integral_iff_lmeasure:
hoelzl@41689
   349
  "(indicator A has_integral m) UNIV \<longleftrightarrow> (A \<in> sets lebesgue \<and> 0 \<le> m \<and> lebesgue.\<mu> A = Real m)"
hoelzl@40859
   350
proof
hoelzl@41654
   351
  assume "(indicator A has_integral m) UNIV"
hoelzl@41654
   352
  with has_integral_lmeasure[OF this] has_integral_lebesgue[OF this]
hoelzl@41689
   353
  show "A \<in> sets lebesgue \<and> 0 \<le> m \<and> lebesgue.\<mu> A = Real m"
hoelzl@41654
   354
    by (auto intro: has_integral_nonneg)
hoelzl@40859
   355
next
hoelzl@41689
   356
  assume "A \<in> sets lebesgue \<and> 0 \<le> m \<and> lebesgue.\<mu> A = Real m"
hoelzl@41654
   357
  then show "(indicator A has_integral m) UNIV" by (intro lmeasure_finite_has_integral) auto
hoelzl@38656
   358
qed
hoelzl@38656
   359
hoelzl@41654
   360
lemma lmeasure_eq_integral: assumes "(indicator s::_\<Rightarrow>real) integrable_on UNIV"
hoelzl@41689
   361
  shows "lebesgue.\<mu> s = Real (integral UNIV (indicator s))"
hoelzl@41654
   362
  using assms unfolding integrable_on_def
hoelzl@41654
   363
proof safe
hoelzl@41654
   364
  fix y :: real assume "(indicator s has_integral y) UNIV"
hoelzl@41654
   365
  from this[unfolded has_integral_iff_lmeasure] integral_unique[OF this]
hoelzl@41689
   366
  show "lebesgue.\<mu> s = Real (integral UNIV (indicator s))" by simp
hoelzl@40859
   367
qed
hoelzl@38656
   368
hoelzl@38656
   369
lemma lebesgue_simple_function_indicator:
hoelzl@41023
   370
  fixes f::"'a::ordered_euclidean_space \<Rightarrow> pextreal"
hoelzl@41689
   371
  assumes f:"simple_function lebesgue f"
hoelzl@38656
   372
  shows "f = (\<lambda>x. (\<Sum>y \<in> f ` UNIV. y * indicator (f -` {y}) x))"
hoelzl@41689
   373
  by (rule, subst lebesgue.simple_function_indicator_representation[OF f]) auto
hoelzl@38656
   374
hoelzl@41654
   375
lemma integral_eq_lmeasure:
hoelzl@41689
   376
  "(indicator s::_\<Rightarrow>real) integrable_on UNIV \<Longrightarrow> integral UNIV (indicator s) = real (lebesgue.\<mu> s)"
hoelzl@41654
   377
  by (subst lmeasure_eq_integral) (auto intro!: integral_nonneg)
hoelzl@38656
   378
hoelzl@41689
   379
lemma lmeasure_finite: assumes "(indicator s::_\<Rightarrow>real) integrable_on UNIV" shows "lebesgue.\<mu> s \<noteq> \<omega>"
hoelzl@41654
   380
  using lmeasure_eq_integral[OF assms] by auto
hoelzl@38656
   381
hoelzl@40859
   382
lemma negligible_iff_lebesgue_null_sets:
hoelzl@40859
   383
  "negligible A \<longleftrightarrow> A \<in> lebesgue.null_sets"
hoelzl@40859
   384
proof
hoelzl@40859
   385
  assume "negligible A"
hoelzl@40859
   386
  from this[THEN lebesgueI_negligible] this[THEN lmeasure_eq_0]
hoelzl@40859
   387
  show "A \<in> lebesgue.null_sets" by auto
hoelzl@40859
   388
next
hoelzl@40859
   389
  assume A: "A \<in> lebesgue.null_sets"
hoelzl@41654
   390
  then have *:"((indicator A) has_integral (0::real)) UNIV" using lmeasure_finite_has_integral[of A] by auto
hoelzl@41654
   391
  show "negligible A" unfolding negligible_def
hoelzl@41654
   392
  proof (intro allI)
hoelzl@41654
   393
    fix a b :: 'a
hoelzl@41654
   394
    have integrable: "(indicator A :: _\<Rightarrow>real) integrable_on {a..b}"
hoelzl@41654
   395
      by (intro integrable_on_subinterval has_integral_integrable) (auto intro: *)
hoelzl@41654
   396
    then have "integral {a..b} (indicator A) \<le> (integral UNIV (indicator A) :: real)"
hoelzl@41654
   397
      using * by (auto intro!: integral_subset_le has_integral_integrable)
hoelzl@41654
   398
    moreover have "(0::real) \<le> integral {a..b} (indicator A)"
hoelzl@41654
   399
      using integrable by (auto intro!: integral_nonneg)
hoelzl@41654
   400
    ultimately have "integral {a..b} (indicator A) = (0::real)"
hoelzl@41654
   401
      using integral_unique[OF *] by auto
hoelzl@41654
   402
    then show "(indicator A has_integral (0::real)) {a..b}"
hoelzl@41654
   403
      using integrable_integral[OF integrable] by simp
hoelzl@41654
   404
  qed
hoelzl@41654
   405
qed
hoelzl@41654
   406
hoelzl@41654
   407
lemma integral_const[simp]:
hoelzl@41654
   408
  fixes a b :: "'a::ordered_euclidean_space"
hoelzl@41654
   409
  shows "integral {a .. b} (\<lambda>x. c) = content {a .. b} *\<^sub>R c"
hoelzl@41654
   410
  by (rule integral_unique) (rule has_integral_const)
hoelzl@41654
   411
hoelzl@41689
   412
lemma lmeasure_UNIV[intro]: "lebesgue.\<mu> (UNIV::'a::ordered_euclidean_space set) = \<omega>"
hoelzl@41689
   413
proof (simp add: lebesgue_def SUP_\<omega>, intro allI impI)
hoelzl@41654
   414
  fix x assume "x < \<omega>"
hoelzl@41654
   415
  then obtain r where r: "x = Real r" "0 \<le> r" by (cases x) auto
hoelzl@41654
   416
  then obtain n where n: "r < of_nat n" using ex_less_of_nat by auto
hoelzl@41689
   417
  show "\<exists>i. x < Real (integral (cube i) (indicator UNIV::'a\<Rightarrow>real))"
hoelzl@41689
   418
  proof (intro exI[of _ n])
hoelzl@41654
   419
    have [simp]: "indicator UNIV = (\<lambda>x. 1)" by (auto simp: fun_eq_iff)
hoelzl@41654
   420
    { fix m :: nat assume "0 < m" then have "real n \<le> (\<Prod>x<m. 2 * real n)"
hoelzl@41654
   421
      proof (induct m)
hoelzl@41654
   422
        case (Suc m)
hoelzl@41654
   423
        show ?case
hoelzl@41654
   424
        proof cases
hoelzl@41654
   425
          assume "m = 0" then show ?thesis by (simp add: lessThan_Suc)
hoelzl@41654
   426
        next
hoelzl@41654
   427
          assume "m \<noteq> 0" then have "real n \<le> (\<Prod>x<m. 2 * real n)" using Suc by auto
hoelzl@41654
   428
          then show ?thesis
hoelzl@41654
   429
            by (auto simp: lessThan_Suc field_simps mult_le_cancel_left1)
hoelzl@41654
   430
        qed
hoelzl@41654
   431
      qed auto } note this[OF DIM_positive[where 'a='a], simp]
hoelzl@41654
   432
    then have [simp]: "0 \<le> (\<Prod>x<DIM('a). 2 * real n)" using real_of_nat_ge_zero by arith
hoelzl@41654
   433
    have "x < Real (of_nat n)" using n r by auto
hoelzl@41654
   434
    also have "Real (of_nat n) \<le> Real (integral (cube n) (indicator UNIV::'a\<Rightarrow>real))"
hoelzl@41654
   435
      by (auto simp: real_eq_of_nat[symmetric] cube_def content_closed_interval_cases)
hoelzl@41654
   436
    finally show "x < Real (integral (cube n) (indicator UNIV::'a\<Rightarrow>real))" .
hoelzl@41689
   437
  qed
hoelzl@40859
   438
qed
hoelzl@40859
   439
hoelzl@40859
   440
lemma
hoelzl@40859
   441
  fixes a b ::"'a::ordered_euclidean_space"
hoelzl@41689
   442
  shows lmeasure_atLeastAtMost[simp]: "lebesgue.\<mu> {a..b} = Real (content {a..b})"
hoelzl@41654
   443
proof -
hoelzl@41654
   444
  have "(indicator (UNIV \<inter> {a..b})::_\<Rightarrow>real) integrable_on UNIV"
hoelzl@41654
   445
    unfolding integrable_indicator_UNIV by (simp add: integrable_const indicator_def_raw)
hoelzl@41654
   446
  from lmeasure_eq_integral[OF this] show ?thesis unfolding integral_indicator_UNIV
hoelzl@41654
   447
    by (simp add: indicator_def_raw)
hoelzl@40859
   448
qed
hoelzl@40859
   449
hoelzl@40859
   450
lemma atLeastAtMost_singleton_euclidean[simp]:
hoelzl@40859
   451
  fixes a :: "'a::ordered_euclidean_space" shows "{a .. a} = {a}"
hoelzl@40859
   452
  by (force simp: eucl_le[where 'a='a] euclidean_eq[where 'a='a])
hoelzl@40859
   453
hoelzl@40859
   454
lemma content_singleton[simp]: "content {a} = 0"
hoelzl@40859
   455
proof -
hoelzl@40859
   456
  have "content {a .. a} = 0"
hoelzl@40859
   457
    by (subst content_closed_interval) auto
hoelzl@40859
   458
  then show ?thesis by simp
hoelzl@40859
   459
qed
hoelzl@40859
   460
hoelzl@40859
   461
lemma lmeasure_singleton[simp]:
hoelzl@41689
   462
  fixes a :: "'a::ordered_euclidean_space" shows "lebesgue.\<mu> {a} = 0"
hoelzl@41654
   463
  using lmeasure_atLeastAtMost[of a a] by simp
hoelzl@40859
   464
hoelzl@40859
   465
declare content_real[simp]
hoelzl@40859
   466
hoelzl@40859
   467
lemma
hoelzl@40859
   468
  fixes a b :: real
hoelzl@40859
   469
  shows lmeasure_real_greaterThanAtMost[simp]:
hoelzl@41689
   470
    "lebesgue.\<mu> {a <.. b} = Real (if a \<le> b then b - a else 0)"
hoelzl@40859
   471
proof cases
hoelzl@40859
   472
  assume "a < b"
hoelzl@41689
   473
  then have "lebesgue.\<mu> {a <.. b} = lebesgue.\<mu> {a .. b} - lebesgue.\<mu> {a}"
hoelzl@41654
   474
    by (subst lebesgue.measure_Diff[symmetric])
hoelzl@41689
   475
       (auto intro!: arg_cong[where f=lebesgue.\<mu>])
hoelzl@40859
   476
  then show ?thesis by auto
hoelzl@40859
   477
qed auto
hoelzl@40859
   478
hoelzl@40859
   479
lemma
hoelzl@40859
   480
  fixes a b :: real
hoelzl@40859
   481
  shows lmeasure_real_atLeastLessThan[simp]:
hoelzl@41689
   482
    "lebesgue.\<mu> {a ..< b} = Real (if a \<le> b then b - a else 0)"
hoelzl@40859
   483
proof cases
hoelzl@40859
   484
  assume "a < b"
hoelzl@41689
   485
  then have "lebesgue.\<mu> {a ..< b} = lebesgue.\<mu> {a .. b} - lebesgue.\<mu> {b}"
hoelzl@41654
   486
    by (subst lebesgue.measure_Diff[symmetric])
hoelzl@41689
   487
       (auto intro!: arg_cong[where f=lebesgue.\<mu>])
hoelzl@41654
   488
  then show ?thesis by auto
hoelzl@41654
   489
qed auto
hoelzl@41654
   490
hoelzl@41654
   491
lemma
hoelzl@41654
   492
  fixes a b :: real
hoelzl@41654
   493
  shows lmeasure_real_greaterThanLessThan[simp]:
hoelzl@41689
   494
    "lebesgue.\<mu> {a <..< b} = Real (if a \<le> b then b - a else 0)"
hoelzl@41654
   495
proof cases
hoelzl@41654
   496
  assume "a < b"
hoelzl@41689
   497
  then have "lebesgue.\<mu> {a <..< b} = lebesgue.\<mu> {a <.. b} - lebesgue.\<mu> {b}"
hoelzl@41654
   498
    by (subst lebesgue.measure_Diff[symmetric])
hoelzl@41689
   499
       (auto intro!: arg_cong[where f=lebesgue.\<mu>])
hoelzl@40859
   500
  then show ?thesis by auto
hoelzl@40859
   501
qed auto
hoelzl@40859
   502
hoelzl@41706
   503
subsection {* Lebesgue-Borel measure *}
hoelzl@41706
   504
hoelzl@41689
   505
definition "lborel = lebesgue \<lparr> sets := sets borel \<rparr>"
hoelzl@41689
   506
hoelzl@41689
   507
lemma
hoelzl@41689
   508
  shows space_lborel[simp]: "space lborel = UNIV"
hoelzl@41689
   509
  and sets_lborel[simp]: "sets lborel = sets borel"
hoelzl@41689
   510
  and measure_lborel[simp]: "measure lborel = lebesgue.\<mu>"
hoelzl@41689
   511
  and measurable_lborel[simp]: "measurable lborel = measurable borel"
hoelzl@41689
   512
  by (simp_all add: measurable_def_raw lborel_def)
hoelzl@40859
   513
hoelzl@41689
   514
interpretation lborel: measure_space lborel
hoelzl@41689
   515
  where "space lborel = UNIV"
hoelzl@41689
   516
  and "sets lborel = sets borel"
hoelzl@41689
   517
  and "measure lborel = lebesgue.\<mu>"
hoelzl@41689
   518
  and "measurable lborel = measurable borel"
hoelzl@41689
   519
proof -
hoelzl@41689
   520
  show "measure_space lborel"
hoelzl@41689
   521
  proof
hoelzl@41689
   522
    show "countably_additive lborel (measure lborel)"
hoelzl@41689
   523
      using lebesgue.ca unfolding countably_additive_def lborel_def
hoelzl@41689
   524
      apply safe apply (erule_tac x=A in allE) by auto
hoelzl@41689
   525
  qed (auto simp: lborel_def)
hoelzl@41689
   526
qed simp_all
hoelzl@40859
   527
hoelzl@41689
   528
interpretation lborel: sigma_finite_measure lborel
hoelzl@41689
   529
  where "space lborel = UNIV"
hoelzl@41689
   530
  and "sets lborel = sets borel"
hoelzl@41689
   531
  and "measure lborel = lebesgue.\<mu>"
hoelzl@41689
   532
  and "measurable lborel = measurable borel"
hoelzl@41689
   533
proof -
hoelzl@41689
   534
  show "sigma_finite_measure lborel"
hoelzl@41689
   535
  proof (default, intro conjI exI[of _ "\<lambda>n. cube n"])
hoelzl@41689
   536
    show "range cube \<subseteq> sets lborel" by (auto intro: borel_closed)
hoelzl@41689
   537
    { fix x have "\<exists>n. x\<in>cube n" using mem_big_cube by auto }
hoelzl@41689
   538
    thus "(\<Union>i. cube i) = space lborel" by auto
hoelzl@41689
   539
    show "\<forall>i. measure lborel (cube i) \<noteq> \<omega>" by (simp add: cube_def)
hoelzl@41689
   540
  qed
hoelzl@41689
   541
qed simp_all
hoelzl@41689
   542
hoelzl@41689
   543
interpretation lebesgue: sigma_finite_measure lebesgue
hoelzl@40859
   544
proof
hoelzl@41689
   545
  from lborel.sigma_finite guess A ..
hoelzl@40859
   546
  moreover then have "range A \<subseteq> sets lebesgue" using lebesgueI_borel by blast
hoelzl@41689
   547
  ultimately show "\<exists>A::nat \<Rightarrow> 'b set. range A \<subseteq> sets lebesgue \<and> (\<Union>i. A i) = space lebesgue \<and> (\<forall>i. lebesgue.\<mu> (A i) \<noteq> \<omega>)"
hoelzl@40859
   548
    by auto
hoelzl@40859
   549
qed
hoelzl@40859
   550
hoelzl@41706
   551
subsection {* Lebesgue integrable implies Gauge integrable *}
hoelzl@41706
   552
hoelzl@40859
   553
lemma simple_function_has_integral:
hoelzl@41023
   554
  fixes f::"'a::ordered_euclidean_space \<Rightarrow> pextreal"
hoelzl@41689
   555
  assumes f:"simple_function lebesgue f"
hoelzl@40859
   556
  and f':"\<forall>x. f x \<noteq> \<omega>"
hoelzl@41689
   557
  and om:"\<forall>x\<in>range f. lebesgue.\<mu> (f -` {x} \<inter> UNIV) = \<omega> \<longrightarrow> x = 0"
hoelzl@41689
   558
  shows "((\<lambda>x. real (f x)) has_integral (real (integral\<^isup>S lebesgue f))) UNIV"
hoelzl@41689
   559
  unfolding simple_integral_def
hoelzl@40859
   560
  apply(subst lebesgue_simple_function_indicator[OF f])
hoelzl@41654
   561
proof -
hoelzl@41654
   562
  case goal1
hoelzl@40859
   563
  have *:"\<And>x. \<forall>y\<in>range f. y * indicator (f -` {y}) x \<noteq> \<omega>"
hoelzl@41689
   564
    "\<forall>x\<in>range f. x * lebesgue.\<mu> (f -` {x} \<inter> UNIV) \<noteq> \<omega>"
hoelzl@40859
   565
    using f' om unfolding indicator_def by auto
hoelzl@41023
   566
  show ?case unfolding space_lebesgue real_of_pextreal_setsum'[OF *(1),THEN sym]
hoelzl@41023
   567
    unfolding real_of_pextreal_setsum'[OF *(2),THEN sym]
hoelzl@41023
   568
    unfolding real_of_pextreal_setsum space_lebesgue
hoelzl@40859
   569
    apply(rule has_integral_setsum)
hoelzl@40859
   570
  proof safe show "finite (range f)" using f by (auto dest: lebesgue.simple_functionD)
hoelzl@40859
   571
    fix y::'a show "((\<lambda>x. real (f y * indicator (f -` {f y}) x)) has_integral
hoelzl@41689
   572
      real (f y * lebesgue.\<mu> (f -` {f y} \<inter> UNIV))) UNIV"
hoelzl@40859
   573
    proof(cases "f y = 0") case False
hoelzl@41654
   574
      have mea:"(indicator (f -` {f y}) ::_\<Rightarrow>real) integrable_on UNIV"
hoelzl@41654
   575
        apply(rule lmeasure_finite_integrable)
hoelzl@41689
   576
        using assms unfolding simple_function_def using False by auto
hoelzl@41654
   577
      have *:"\<And>x. real (indicator (f -` {f y}) x::pextreal) = (indicator (f -` {f y}) x)"
hoelzl@41654
   578
        by (auto simp: indicator_def)
hoelzl@41023
   579
      show ?thesis unfolding real_of_pextreal_mult[THEN sym]
hoelzl@40859
   580
        apply(rule has_integral_cmul[where 'b=real, unfolded real_scaleR_def])
hoelzl@41654
   581
        unfolding Int_UNIV_right lmeasure_eq_integral[OF mea,THEN sym]
hoelzl@41654
   582
        unfolding integral_eq_lmeasure[OF mea, symmetric] *
hoelzl@41654
   583
        apply(rule integrable_integral) using mea .
hoelzl@40859
   584
    qed auto
hoelzl@41654
   585
  qed
hoelzl@41654
   586
qed
hoelzl@40859
   587
hoelzl@40859
   588
lemma bounded_realI: assumes "\<forall>x\<in>s. abs (x::real) \<le> B" shows "bounded s"
hoelzl@40859
   589
  unfolding bounded_def dist_real_def apply(rule_tac x=0 in exI)
hoelzl@40859
   590
  using assms by auto
hoelzl@40859
   591
hoelzl@40859
   592
lemma simple_function_has_integral':
hoelzl@41023
   593
  fixes f::"'a::ordered_euclidean_space \<Rightarrow> pextreal"
hoelzl@41689
   594
  assumes f:"simple_function lebesgue f"
hoelzl@41689
   595
  and i: "integral\<^isup>S lebesgue f \<noteq> \<omega>"
hoelzl@41689
   596
  shows "((\<lambda>x. real (f x)) has_integral (real (integral\<^isup>S lebesgue f))) UNIV"
hoelzl@40859
   597
proof- let ?f = "\<lambda>x. if f x = \<omega> then 0 else f x"
hoelzl@40859
   598
  { fix x have "real (f x) = real (?f x)" by (cases "f x") auto } note * = this
hoelzl@40859
   599
  have **:"{x. f x \<noteq> ?f x} = f -` {\<omega>}" by auto
hoelzl@41689
   600
  have **:"lebesgue.\<mu> {x\<in>space lebesgue. f x \<noteq> ?f x} = 0"
hoelzl@40859
   601
    using lebesgue.simple_integral_omega[OF assms] by(auto simp add:**)
hoelzl@40859
   602
  show ?thesis apply(subst lebesgue.simple_integral_cong'[OF f _ **])
hoelzl@40859
   603
    apply(rule lebesgue.simple_function_compose1[OF f])
hoelzl@40859
   604
    unfolding * defer apply(rule simple_function_has_integral)
hoelzl@40859
   605
  proof-
hoelzl@41689
   606
    show "simple_function lebesgue ?f"
hoelzl@40859
   607
      using lebesgue.simple_function_compose1[OF f] .
hoelzl@40859
   608
    show "\<forall>x. ?f x \<noteq> \<omega>" by auto
hoelzl@41689
   609
    show "\<forall>x\<in>range ?f. lebesgue.\<mu> (?f -` {x} \<inter> UNIV) = \<omega> \<longrightarrow> x = 0"
hoelzl@40859
   610
    proof (safe, simp, safe, rule ccontr)
hoelzl@40859
   611
      fix y assume "f y \<noteq> \<omega>" "f y \<noteq> 0"
hoelzl@40859
   612
      hence "(\<lambda>x. if f x = \<omega> then 0 else f x) -` {if f y = \<omega> then 0 else f y} = f -` {f y}"
hoelzl@40859
   613
        by (auto split: split_if_asm)
hoelzl@41689
   614
      moreover assume "lebesgue.\<mu> ((\<lambda>x. if f x = \<omega> then 0 else f x) -` {if f y = \<omega> then 0 else f y}) = \<omega>"
hoelzl@41689
   615
      ultimately have "lebesgue.\<mu> (f -` {f y}) = \<omega>" by simp
hoelzl@40859
   616
      moreover
hoelzl@41689
   617
      have "f y * lebesgue.\<mu> (f -` {f y}) \<noteq> \<omega>" using i f
hoelzl@41689
   618
        unfolding simple_integral_def setsum_\<omega> simple_function_def
hoelzl@40859
   619
        by auto
hoelzl@40859
   620
      ultimately have "f y = 0" by (auto split: split_if_asm)
hoelzl@40859
   621
      then show False using `f y \<noteq> 0` by simp
hoelzl@40859
   622
    qed
hoelzl@40859
   623
  qed
hoelzl@40859
   624
qed
hoelzl@40859
   625
hoelzl@40859
   626
lemma (in measure_space) positive_integral_monotone_convergence:
hoelzl@41023
   627
  fixes f::"nat \<Rightarrow> 'a \<Rightarrow> pextreal"
hoelzl@40859
   628
  assumes i: "\<And>i. f i \<in> borel_measurable M" and mono: "\<And>x. mono (\<lambda>n. f n x)"
hoelzl@40859
   629
  and lim: "\<And>x. (\<lambda>i. f i x) ----> u x"
hoelzl@40859
   630
  shows "u \<in> borel_measurable M"
hoelzl@41689
   631
  and "(\<lambda>i. integral\<^isup>P M (f i)) ----> integral\<^isup>P M u" (is ?ilim)
hoelzl@40859
   632
proof -
hoelzl@40859
   633
  from positive_integral_isoton[unfolded isoton_fun_expand isoton_iff_Lim_mono, of f u]
hoelzl@40859
   634
  show ?ilim using mono lim i by auto
hoelzl@41097
   635
  have "\<And>x. (SUP i. f i x) = u x" using mono lim SUP_Lim_pextreal
hoelzl@41097
   636
    unfolding fun_eq_iff mono_def by auto
hoelzl@41097
   637
  moreover have "(\<lambda>x. SUP i. f i x) \<in> borel_measurable M"
hoelzl@41097
   638
    using i by auto
hoelzl@40859
   639
  ultimately show "u \<in> borel_measurable M" by simp
hoelzl@40859
   640
qed
hoelzl@40859
   641
hoelzl@40859
   642
lemma positive_integral_has_integral:
hoelzl@41023
   643
  fixes f::"'a::ordered_euclidean_space => pextreal"
hoelzl@40859
   644
  assumes f:"f \<in> borel_measurable lebesgue"
hoelzl@41689
   645
  and int_om:"integral\<^isup>P lebesgue f \<noteq> \<omega>"
hoelzl@40859
   646
  and f_om:"\<forall>x. f x \<noteq> \<omega>" (* TODO: remove this *)
hoelzl@41689
   647
  shows "((\<lambda>x. real (f x)) has_integral (real (integral\<^isup>P lebesgue f))) UNIV"
hoelzl@41689
   648
proof- let ?i = "integral\<^isup>P lebesgue f"
hoelzl@40859
   649
  from lebesgue.borel_measurable_implies_simple_function_sequence[OF f]
hoelzl@40859
   650
  guess u .. note conjunctD2[OF this,rule_format] note u = conjunctD2[OF this(1)] this(2)
hoelzl@40859
   651
  let ?u = "\<lambda>i x. real (u i x)" and ?f = "\<lambda>x. real (f x)"
hoelzl@41689
   652
  have u_simple:"\<And>k. integral\<^isup>S lebesgue (u k) = integral\<^isup>P lebesgue (u k)"
hoelzl@40859
   653
    apply(subst lebesgue.positive_integral_eq_simple_integral[THEN sym,OF u(1)]) ..
hoelzl@41689
   654
  have int_u_le:"\<And>k. integral\<^isup>S lebesgue (u k) \<le> integral\<^isup>P lebesgue f"
hoelzl@40859
   655
    unfolding u_simple apply(rule lebesgue.positive_integral_mono)
hoelzl@40859
   656
    using isoton_Sup[OF u(3)] unfolding le_fun_def by auto
hoelzl@41689
   657
  have u_int_om:"\<And>i. integral\<^isup>S lebesgue (u i) \<noteq> \<omega>"
hoelzl@40859
   658
  proof- case goal1 thus ?case using int_u_le[of i] int_om by auto qed
hoelzl@40859
   659
hoelzl@40859
   660
  note u_int = simple_function_has_integral'[OF u(1) this]
hoelzl@40859
   661
  have "(\<lambda>x. real (f x)) integrable_on UNIV \<and>
hoelzl@40859
   662
    (\<lambda>k. Integration.integral UNIV (\<lambda>x. real (u k x))) ----> Integration.integral UNIV (\<lambda>x. real (f x))"
hoelzl@40859
   663
    apply(rule monotone_convergence_increasing) apply(rule,rule,rule u_int)
hoelzl@41023
   664
  proof safe case goal1 show ?case apply(rule real_of_pextreal_mono) using u(2,3) by auto
hoelzl@40859
   665
  next case goal2 show ?case using u(3) apply(subst lim_Real[THEN sym])
hoelzl@40859
   666
      prefer 3 apply(subst Real_real') defer apply(subst Real_real')
hoelzl@40859
   667
      using isotone_Lim[OF u(3)[unfolded isoton_fun_expand, THEN spec]] using f_om u by auto
hoelzl@40859
   668
  next case goal3
hoelzl@41689
   669
    show ?case apply(rule bounded_realI[where B="real (integral\<^isup>P lebesgue f)"])
hoelzl@40859
   670
      apply safe apply(subst abs_of_nonneg) apply(rule integral_nonneg,rule) apply(rule u_int)
hoelzl@41023
   671
      unfolding integral_unique[OF u_int] defer apply(rule real_of_pextreal_mono[OF _ int_u_le])
hoelzl@40859
   672
      using u int_om by auto
hoelzl@40859
   673
  qed note int = conjunctD2[OF this]
hoelzl@40859
   674
hoelzl@41689
   675
  have "(\<lambda>i. integral\<^isup>S lebesgue (u i)) ----> ?i" unfolding u_simple
hoelzl@40859
   676
    apply(rule lebesgue.positive_integral_monotone_convergence(2))
hoelzl@40859
   677
    apply(rule lebesgue.borel_measurable_simple_function[OF u(1)])
hoelzl@40859
   678
    using isotone_Lim[OF u(3)[unfolded isoton_fun_expand, THEN spec]] by auto
hoelzl@41689
   679
  hence "(\<lambda>i. real (integral\<^isup>S lebesgue (u i))) ----> real ?i" apply-
hoelzl@40859
   680
    apply(subst lim_Real[THEN sym]) prefer 3
hoelzl@40859
   681
    apply(subst Real_real') defer apply(subst Real_real')
hoelzl@40859
   682
    using u f_om int_om u_int_om by auto
hoelzl@40859
   683
  note * = LIMSEQ_unique[OF this int(2)[unfolded integral_unique[OF u_int]]]
hoelzl@40859
   684
  show ?thesis unfolding * by(rule integrable_integral[OF int(1)])
hoelzl@40859
   685
qed
hoelzl@40859
   686
hoelzl@40859
   687
lemma lebesgue_integral_has_integral:
hoelzl@40859
   688
  fixes f::"'a::ordered_euclidean_space => real"
hoelzl@41689
   689
  assumes f:"integrable lebesgue f"
hoelzl@41689
   690
  shows "(f has_integral (integral\<^isup>L lebesgue f)) UNIV"
hoelzl@40859
   691
proof- let ?n = "\<lambda>x. - min (f x) 0" and ?p = "\<lambda>x. max (f x) 0"
hoelzl@40859
   692
  have *:"f = (\<lambda>x. ?p x - ?n x)" apply rule by auto
hoelzl@41689
   693
  note f = integrableD[OF f]
hoelzl@41689
   694
  show ?thesis unfolding lebesgue_integral_def apply(subst *)
hoelzl@40859
   695
  proof(rule has_integral_sub) case goal1
hoelzl@40859
   696
    have *:"\<forall>x. Real (f x) \<noteq> \<omega>" by auto
hoelzl@40859
   697
    note lebesgue.borel_measurable_Real[OF f(1)]
hoelzl@40859
   698
    from positive_integral_has_integral[OF this f(2) *]
hoelzl@40859
   699
    show ?case unfolding real_Real_max .
hoelzl@40859
   700
  next case goal2
hoelzl@40859
   701
    have *:"\<forall>x. Real (- f x) \<noteq> \<omega>" by auto
hoelzl@40859
   702
    note lebesgue.borel_measurable_uminus[OF f(1)]
hoelzl@40859
   703
    note lebesgue.borel_measurable_Real[OF this]
hoelzl@40859
   704
    from positive_integral_has_integral[OF this f(3) *]
hoelzl@40859
   705
    show ?case unfolding real_Real_max minus_min_eq_max by auto
hoelzl@40859
   706
  qed
hoelzl@40859
   707
qed
hoelzl@40859
   708
hoelzl@41546
   709
lemma lebesgue_positive_integral_eq_borel:
hoelzl@41689
   710
  "f \<in> borel_measurable borel \<Longrightarrow> integral\<^isup>P lebesgue f = integral\<^isup>P lborel f"
hoelzl@41546
   711
  by (auto intro!: lebesgue.positive_integral_subalgebra[symmetric]) default
hoelzl@41546
   712
hoelzl@41546
   713
lemma lebesgue_integral_eq_borel:
hoelzl@41546
   714
  assumes "f \<in> borel_measurable borel"
hoelzl@41689
   715
  shows "integrable lebesgue f \<longleftrightarrow> integrable lborel f" (is ?P)
hoelzl@41689
   716
    and "integral\<^isup>L lebesgue f = integral\<^isup>L lborel f" (is ?I)
hoelzl@41546
   717
proof -
hoelzl@41689
   718
  have *: "sigma_algebra lborel" by default
hoelzl@41689
   719
  have "sets lborel \<subseteq> sets lebesgue" by auto
hoelzl@41689
   720
  from lebesgue.integral_subalgebra[of f lborel, OF _ this _ _ *] assms
hoelzl@41546
   721
  show ?P ?I by auto
hoelzl@41546
   722
qed
hoelzl@41546
   723
hoelzl@41546
   724
lemma borel_integral_has_integral:
hoelzl@41546
   725
  fixes f::"'a::ordered_euclidean_space => real"
hoelzl@41689
   726
  assumes f:"integrable lborel f"
hoelzl@41689
   727
  shows "(f has_integral (integral\<^isup>L lborel f)) UNIV"
hoelzl@41546
   728
proof -
hoelzl@41546
   729
  have borel: "f \<in> borel_measurable borel"
hoelzl@41689
   730
    using f unfolding integrable_def by auto
hoelzl@41546
   731
  from f show ?thesis
hoelzl@41546
   732
    using lebesgue_integral_has_integral[of f]
hoelzl@41546
   733
    unfolding lebesgue_integral_eq_borel[OF borel] by simp
hoelzl@41546
   734
qed
hoelzl@41546
   735
hoelzl@41706
   736
subsection {* Equivalence between product spaces and euclidean spaces *}
hoelzl@40859
   737
hoelzl@40859
   738
definition e2p :: "'a::ordered_euclidean_space \<Rightarrow> (nat \<Rightarrow> real)" where
hoelzl@40859
   739
  "e2p x = (\<lambda>i\<in>{..<DIM('a)}. x$$i)"
hoelzl@40859
   740
hoelzl@40859
   741
definition p2e :: "(nat \<Rightarrow> real) \<Rightarrow> 'a::ordered_euclidean_space" where
hoelzl@40859
   742
  "p2e x = (\<chi>\<chi> i. x i)"
hoelzl@40859
   743
hoelzl@41095
   744
lemma e2p_p2e[simp]:
hoelzl@41095
   745
  "x \<in> extensional {..<DIM('a)} \<Longrightarrow> e2p (p2e x::'a::ordered_euclidean_space) = x"
hoelzl@41095
   746
  by (auto simp: fun_eq_iff extensional_def p2e_def e2p_def)
hoelzl@40859
   747
hoelzl@41095
   748
lemma p2e_e2p[simp]:
hoelzl@41095
   749
  "p2e (e2p x) = (x::'a::ordered_euclidean_space)"
hoelzl@41095
   750
  by (auto simp: euclidean_eq[where 'a='a] p2e_def e2p_def)
hoelzl@40859
   751
hoelzl@41689
   752
interpretation lborel_product: product_sigma_finite "\<lambda>x. lborel::real measure_space"
hoelzl@40859
   753
  by default
hoelzl@40859
   754
hoelzl@41831
   755
interpretation lborel_space: finite_product_sigma_finite "\<lambda>x. lborel::real measure_space" "{..<n}" for n :: nat
hoelzl@41689
   756
  where "space lborel = UNIV"
hoelzl@41689
   757
  and "sets lborel = sets borel"
hoelzl@41689
   758
  and "measure lborel = lebesgue.\<mu>"
hoelzl@41689
   759
  and "measurable lborel = measurable borel"
hoelzl@41689
   760
proof -
hoelzl@41831
   761
  show "finite_product_sigma_finite (\<lambda>x. lborel::real measure_space) {..<n}"
hoelzl@41689
   762
    by default simp
hoelzl@41689
   763
qed simp_all
hoelzl@40859
   764
hoelzl@41689
   765
lemma sets_product_borel:
hoelzl@41689
   766
  assumes [intro]: "finite I"
hoelzl@41689
   767
  shows "sets (\<Pi>\<^isub>M i\<in>I.
hoelzl@41689
   768
     \<lparr> space = UNIV::real set, sets = range lessThan, measure = lebesgue.\<mu> \<rparr>) =
hoelzl@41689
   769
   sets (\<Pi>\<^isub>M i\<in>I. lborel)" (is "sets ?G = _")
hoelzl@41689
   770
proof -
hoelzl@41689
   771
  have "sets ?G = sets (\<Pi>\<^isub>M i\<in>I.
hoelzl@41689
   772
       sigma \<lparr> space = UNIV::real set, sets = range lessThan, measure = lebesgue.\<mu> \<rparr>)"
hoelzl@41689
   773
    by (subst sigma_product_algebra_sigma_eq[of I "\<lambda>_ i. {..<real i}" ])
hoelzl@41689
   774
       (auto intro!: measurable_sigma_sigma isotoneI real_arch_lt
hoelzl@41689
   775
             simp: product_algebra_def)
hoelzl@41689
   776
  then show ?thesis
hoelzl@41689
   777
    unfolding lborel_def borel_eq_lessThan lebesgue_def sigma_def by simp
hoelzl@40859
   778
qed
hoelzl@40859
   779
hoelzl@41661
   780
lemma measurable_e2p:
hoelzl@41689
   781
  "e2p \<in> measurable (borel::'a::ordered_euclidean_space algebra)
hoelzl@41689
   782
                    (\<Pi>\<^isub>M i\<in>{..<DIM('a)}. (lborel :: real measure_space))"
hoelzl@41689
   783
    (is "_ \<in> measurable ?E ?P")
hoelzl@41689
   784
proof -
hoelzl@41689
   785
  let ?B = "\<lparr> space = UNIV::real set, sets = range lessThan, measure = lebesgue.\<mu> \<rparr>"
hoelzl@41689
   786
  let ?G = "product_algebra_generator {..<DIM('a)} (\<lambda>_. ?B)"
hoelzl@41689
   787
  have "e2p \<in> measurable ?E (sigma ?G)"
hoelzl@41689
   788
  proof (rule borel.measurable_sigma)
hoelzl@41689
   789
    show "e2p \<in> space ?E \<rightarrow> space ?G" by (auto simp: e2p_def)
hoelzl@41689
   790
    fix A assume "A \<in> sets ?G"
hoelzl@41689
   791
    then obtain E where A: "A = (\<Pi>\<^isub>E i\<in>{..<DIM('a)}. E i)"
hoelzl@41689
   792
      and "E \<in> {..<DIM('a)} \<rightarrow> (range lessThan)"
hoelzl@41689
   793
      by (auto elim!: product_algebraE simp: )
hoelzl@41689
   794
    then have "\<forall>i\<in>{..<DIM('a)}. \<exists>xs. E i = {..< xs}" by auto
hoelzl@41689
   795
    from this[THEN bchoice] guess xs ..
hoelzl@41689
   796
    then have A_eq: "A = (\<Pi>\<^isub>E i\<in>{..<DIM('a)}. {..< xs i})"
hoelzl@41689
   797
      using A by auto
hoelzl@41689
   798
    have "e2p -` A = {..< (\<chi>\<chi> i. xs i) :: 'a}"
hoelzl@41689
   799
      using DIM_positive by (auto simp add: Pi_iff set_eq_iff e2p_def A_eq
hoelzl@41689
   800
        euclidean_eq[where 'a='a] eucl_less[where 'a='a])
hoelzl@41689
   801
    then show "e2p -` A \<inter> space ?E \<in> sets ?E" by simp
hoelzl@41689
   802
  qed (auto simp: product_algebra_generator_def)
hoelzl@41689
   803
  with sets_product_borel[of "{..<DIM('a)}"] show ?thesis
hoelzl@41689
   804
    unfolding measurable_def product_algebra_def by simp
hoelzl@41689
   805
qed
hoelzl@41661
   806
hoelzl@41689
   807
lemma measurable_p2e:
hoelzl@41689
   808
  "p2e \<in> measurable (\<Pi>\<^isub>M i\<in>{..<DIM('a)}. (lborel :: real measure_space))
hoelzl@41689
   809
    (borel :: 'a::ordered_euclidean_space algebra)"
hoelzl@41689
   810
  (is "p2e \<in> measurable ?P _")
hoelzl@41689
   811
  unfolding borel_eq_lessThan
hoelzl@41689
   812
proof (intro lborel_space.measurable_sigma)
hoelzl@41689
   813
  let ?E = "\<lparr> space = UNIV :: 'a set, sets = range lessThan \<rparr>"
hoelzl@41095
   814
  show "p2e \<in> space ?P \<rightarrow> space ?E" by simp
hoelzl@41095
   815
  fix A assume "A \<in> sets ?E"
hoelzl@41095
   816
  then obtain x where "A = {..<x}" by auto
hoelzl@41095
   817
  then have "p2e -` A \<inter> space ?P = (\<Pi>\<^isub>E i\<in>{..<DIM('a)}. {..< x $$ i})"
hoelzl@41095
   818
    using DIM_positive
hoelzl@41095
   819
    by (auto simp: Pi_iff set_eq_iff p2e_def
hoelzl@41095
   820
                   euclidean_eq[where 'a='a] eucl_less[where 'a='a])
hoelzl@41095
   821
  then show "p2e -` A \<inter> space ?P \<in> sets ?P" by auto
hoelzl@41689
   822
qed simp
hoelzl@41095
   823
hoelzl@41706
   824
lemma Int_stable_cuboids:
hoelzl@41706
   825
  fixes x::"'a::ordered_euclidean_space"
hoelzl@41706
   826
  shows "Int_stable \<lparr>space = UNIV, sets = range (\<lambda>(a, b::'a). {a..b})\<rparr>"
hoelzl@41706
   827
  by (auto simp: inter_interval Int_stable_def)
hoelzl@40859
   828
hoelzl@41706
   829
lemma lborel_eq_lborel_space:
hoelzl@40859
   830
  fixes A :: "('a::ordered_euclidean_space) set"
hoelzl@40859
   831
  assumes "A \<in> sets borel"
hoelzl@41831
   832
  shows "lborel.\<mu> A = lborel_space.\<mu> DIM('a) (p2e -` A \<inter> (space (lborel_space.P DIM('a))))"
hoelzl@41706
   833
    (is "_ = measure ?P (?T A)")
hoelzl@41706
   834
proof (rule measure_unique_Int_stable_vimage)
hoelzl@41706
   835
  show "measure_space ?P" by default
hoelzl@41706
   836
  show "measure_space lborel" by default
hoelzl@41706
   837
hoelzl@41706
   838
  let ?E = "\<lparr> space = UNIV :: 'a set, sets = range (\<lambda>(a,b). {a..b}) \<rparr>"
hoelzl@41706
   839
  show "Int_stable ?E" using Int_stable_cuboids .
hoelzl@41706
   840
  show "range cube \<subseteq> sets ?E" unfolding cube_def_raw by auto
hoelzl@41706
   841
  { fix x have "\<exists>n. x \<in> cube n" using mem_big_cube[of x] by fastsimp }
hoelzl@41706
   842
  then show "cube \<up> space ?E" by (intro isotoneI cube_subset_Suc) auto
hoelzl@41706
   843
  { fix i show "lborel.\<mu> (cube i) \<noteq> \<omega>" unfolding cube_def by auto }
hoelzl@41706
   844
  show "A \<in> sets (sigma ?E)" "sets (sigma ?E) = sets lborel" "space ?E = space lborel"
hoelzl@41706
   845
    using assms by (simp_all add: borel_eq_atLeastAtMost)
hoelzl@40859
   846
hoelzl@41706
   847
  show "p2e \<in> measurable ?P (lborel :: 'a measure_space)"
hoelzl@41706
   848
    using measurable_p2e unfolding measurable_def by simp
hoelzl@41706
   849
  { fix X assume "X \<in> sets ?E"
hoelzl@41706
   850
    then obtain a b where X[simp]: "X = {a .. b}" by auto
hoelzl@41706
   851
    have *: "?T X = (\<Pi>\<^isub>E i\<in>{..<DIM('a)}. {a $$ i .. b $$ i})"
hoelzl@41706
   852
      by (auto simp: Pi_iff eucl_le[where 'a='a] p2e_def)
hoelzl@41706
   853
    show "lborel.\<mu> X = measure ?P (?T X)"
hoelzl@41706
   854
    proof cases
hoelzl@41706
   855
      assume "X \<noteq> {}"
hoelzl@41706
   856
      then have "a \<le> b"
hoelzl@41706
   857
        by (simp add: interval_ne_empty eucl_le[where 'a='a])
hoelzl@41706
   858
      then have "lborel.\<mu> X = (\<Prod>x<DIM('a). lborel.\<mu> {a $$ x .. b $$ x})"
hoelzl@41706
   859
        by (auto simp: content_closed_interval eucl_le[where 'a='a]
hoelzl@41706
   860
                 intro!: Real_setprod )
hoelzl@41706
   861
      also have "\<dots> = measure ?P (?T X)"
hoelzl@41706
   862
        unfolding * by (subst lborel_space.measure_times) auto
hoelzl@41706
   863
      finally show ?thesis .
hoelzl@41706
   864
    qed simp }
hoelzl@41706
   865
qed
hoelzl@40859
   866
hoelzl@41831
   867
lemma measure_preserving_p2e:
hoelzl@41831
   868
  "p2e \<in> measure_preserving (\<Pi>\<^isub>M i\<in>{..<DIM('a)}. (lborel :: real measure_space))
hoelzl@41831
   869
    (lborel::'a::ordered_euclidean_space measure_space)" (is "_ \<in> measure_preserving ?P ?E")
hoelzl@41831
   870
proof
hoelzl@41831
   871
  show "p2e \<in> measurable ?P ?E"
hoelzl@41831
   872
    using measurable_p2e by (simp add: measurable_def)
hoelzl@41831
   873
  fix A :: "'a set" assume "A \<in> sets lborel"
hoelzl@41831
   874
  then show "lborel_space.\<mu> DIM('a) (p2e -` A \<inter> (space (lborel_space.P DIM('a)))) = lborel.\<mu> A"
hoelzl@41831
   875
    by (intro lborel_eq_lborel_space[symmetric]) simp
hoelzl@41831
   876
qed
hoelzl@41831
   877
hoelzl@41706
   878
lemma lebesgue_eq_lborel_space_in_borel:
hoelzl@41706
   879
  fixes A :: "('a::ordered_euclidean_space) set"
hoelzl@41706
   880
  assumes A: "A \<in> sets borel"
hoelzl@41831
   881
  shows "lebesgue.\<mu> A = lborel_space.\<mu> DIM('a) (p2e -` A \<inter> (space (lborel_space.P DIM('a))))"
hoelzl@41706
   882
  using lborel_eq_lborel_space[OF A] by simp
hoelzl@40859
   883
hoelzl@40859
   884
lemma borel_fubini_positiv_integral:
hoelzl@41023
   885
  fixes f :: "'a::ordered_euclidean_space \<Rightarrow> pextreal"
hoelzl@40859
   886
  assumes f: "f \<in> borel_measurable borel"
hoelzl@41831
   887
  shows "integral\<^isup>P lborel f = \<integral>\<^isup>+x. f (p2e x) \<partial>(lborel_space.P DIM('a))"
hoelzl@41831
   888
proof (rule lborel_space.positive_integral_vimage[OF _ measure_preserving_p2e _])
hoelzl@41831
   889
  show "f \<in> borel_measurable lborel"
hoelzl@41831
   890
    using f by (simp_all add: measurable_def)
hoelzl@41831
   891
qed default
hoelzl@40859
   892
hoelzl@41704
   893
lemma borel_fubini_integrable:
hoelzl@41704
   894
  fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
hoelzl@41704
   895
  shows "integrable lborel f \<longleftrightarrow>
hoelzl@41831
   896
    integrable (lborel_space.P DIM('a)) (\<lambda>x. f (p2e x))"
hoelzl@41704
   897
    (is "_ \<longleftrightarrow> integrable ?B ?f")
hoelzl@41704
   898
proof
hoelzl@41704
   899
  assume "integrable lborel f"
hoelzl@41704
   900
  moreover then have f: "f \<in> borel_measurable borel"
hoelzl@41704
   901
    by auto
hoelzl@41704
   902
  moreover with measurable_p2e
hoelzl@41704
   903
  have "f \<circ> p2e \<in> borel_measurable ?B"
hoelzl@41704
   904
    by (rule measurable_comp)
hoelzl@41704
   905
  ultimately show "integrable ?B ?f"
hoelzl@41704
   906
    by (simp add: comp_def borel_fubini_positiv_integral integrable_def)
hoelzl@41704
   907
next
hoelzl@41704
   908
  assume "integrable ?B ?f"
hoelzl@41704
   909
  moreover then
hoelzl@41704
   910
  have "?f \<circ> e2p \<in> borel_measurable (borel::'a algebra)"
hoelzl@41704
   911
    by (auto intro!: measurable_e2p measurable_comp)
hoelzl@41704
   912
  then have "f \<in> borel_measurable borel"
hoelzl@41704
   913
    by (simp cong: measurable_cong)
hoelzl@41704
   914
  ultimately show "integrable lborel f"
hoelzl@41706
   915
    by (simp add: borel_fubini_positiv_integral integrable_def)
hoelzl@41704
   916
qed
hoelzl@41704
   917
hoelzl@40859
   918
lemma borel_fubini:
hoelzl@40859
   919
  fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
hoelzl@40859
   920
  assumes f: "f \<in> borel_measurable borel"
hoelzl@41831
   921
  shows "integral\<^isup>L lborel f = \<integral>x. f (p2e x) \<partial>(lborel_space.P DIM('a))"
hoelzl@41706
   922
  using f by (simp add: borel_fubini_positiv_integral lebesgue_integral_def)
hoelzl@38656
   923
hoelzl@38656
   924
end