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