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