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