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