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