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