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