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