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