src/HOL/Probability/Lebesgue_Measure.thy
changeset 56993 e5366291d6aa
parent 56218 1c3f1f2431f9
child 56996 891e992e510f
equal deleted inserted replaced
56992:d0e5225601d3 56993:e5366291d6aa
     4 *)
     4 *)
     5 
     5 
     6 header {* Lebsegue measure *}
     6 header {* Lebsegue measure *}
     7 
     7 
     8 theory Lebesgue_Measure
     8 theory Lebesgue_Measure
     9   imports Finite_Product_Measure
     9   imports Finite_Product_Measure Bochner_Integration
    10 begin
    10 begin
    11 
    11 
    12 lemma absolutely_integrable_on_indicator[simp]:
    12 lemma absolutely_integrable_on_indicator[simp]:
    13   fixes A :: "'a::ordered_euclidean_space set"
    13   fixes A :: "'a::ordered_euclidean_space set"
    14   shows "((indicator A :: _ \<Rightarrow> real) absolutely_integrable_on X) \<longleftrightarrow>
    14   shows "((indicator A :: _ \<Rightarrow> real) absolutely_integrable_on X) \<longleftrightarrow>
   481   and measurable_lborel1[simp]: "measurable lborel = measurable borel"
   481   and measurable_lborel1[simp]: "measurable lborel = measurable borel"
   482   and measurable_lborel2[simp]: "measurable A lborel = measurable A borel"
   482   and measurable_lborel2[simp]: "measurable A lborel = measurable A borel"
   483   using sets.sigma_sets_eq[of borel]
   483   using sets.sigma_sets_eq[of borel]
   484   by (auto simp add: lborel_def measurable_def[abs_def])
   484   by (auto simp add: lborel_def measurable_def[abs_def])
   485 
   485 
       
   486 (* TODO: switch these rules! *)
   486 lemma emeasure_lborel[simp]: "A \<in> sets borel \<Longrightarrow> emeasure lborel A = emeasure lebesgue A"
   487 lemma emeasure_lborel[simp]: "A \<in> sets borel \<Longrightarrow> emeasure lborel A = emeasure lebesgue A"
   487   by (rule emeasure_measure_of[OF lborel_def])
   488   by (rule emeasure_measure_of[OF lborel_def])
   488      (auto simp: positive_def emeasure_nonneg countably_additive_def intro!: suminf_emeasure)
   489      (auto simp: positive_def emeasure_nonneg countably_additive_def intro!: suminf_emeasure)
       
   490 
       
   491 lemma measure_lborel[simp]: "A \<in> sets borel \<Longrightarrow> measure lborel A = measure lebesgue A"
       
   492   unfolding measure_def by simp
   489 
   493 
   490 interpretation lborel: sigma_finite_measure lborel
   494 interpretation lborel: sigma_finite_measure lborel
   491 proof (default, intro conjI exI[of _ "\<lambda>n. cube n"])
   495 proof (default, intro conjI exI[of _ "\<lambda>n. cube n"])
   492   show "range cube \<subseteq> sets lborel" by (auto intro: borel_closed)
   496   show "range cube \<subseteq> sets lborel" by (auto intro: borel_closed)
   493   { fix x :: 'a have "\<exists>n. x\<in>cube n" using mem_big_cube by auto }
   497   { fix x :: 'a have "\<exists>n. x\<in>cube n" using mem_big_cube by auto }
   525   { fix i show "emeasure lborel (cube i) \<noteq> \<infinity>" unfolding cube_def by auto }
   529   { fix i show "emeasure lborel (cube i) \<noteq> \<infinity>" unfolding cube_def by auto }
   526   { fix X assume "X \<in> ?E" then show "emeasure lborel X = emeasure M X"
   530   { fix X assume "X \<in> ?E" then show "emeasure lborel X = emeasure M X"
   527       by (auto simp: emeasure_eq) }
   531       by (auto simp: emeasure_eq) }
   528 qed
   532 qed
   529 
   533 
   530 lemma lebesgue_real_affine:
   534 
       
   535 (* GENEREALIZE to euclidean_spaces *)
       
   536 lemma lborel_real_affine:
   531   fixes c :: real assumes "c \<noteq> 0"
   537   fixes c :: real assumes "c \<noteq> 0"
   532   shows "lborel = density (distr lborel borel (\<lambda>x. t + c * x)) (\<lambda>_. \<bar>c\<bar>)" (is "_ = ?D")
   538   shows "lborel = density (distr lborel borel (\<lambda>x. t + c * x)) (\<lambda>_. \<bar>c\<bar>)" (is "_ = ?D")
   533 proof (rule lborel_eqI)
   539 proof (rule lborel_eqI)
   534   fix a b show "emeasure ?D {a..b} = content {a .. b}"
   540   fix a b show "emeasure ?D {a..b} = content {a .. b}"
   535   proof cases
   541   proof cases
   549          (auto simp: field_simps emeasure_density positive_integral_distr
   555          (auto simp: field_simps emeasure_density positive_integral_distr
   550                      positive_integral_cmult borel_measurable_indicator' emeasure_distr)
   556                      positive_integral_cmult borel_measurable_indicator' emeasure_distr)
   551   qed
   557   qed
   552 qed simp
   558 qed simp
   553 
   559 
   554 lemma lebesgue_integral_real_affine:
   560 lemma positive_integral_real_affine:
   555   fixes c :: real assumes c: "c \<noteq> 0" and f: "f \<in> borel_measurable borel"
   561   fixes c :: real assumes [measurable]: "f \<in> borel_measurable borel" and c: "c \<noteq> 0"
   556   shows "(\<integral> x. f x \<partial> lborel) = \<bar>c\<bar> * (\<integral> x. f (t + c * x) \<partial>lborel)"
   562   shows "(\<integral>\<^sup>+x. f x \<partial>lborel) = \<bar>c\<bar> * (\<integral>\<^sup>+x. f (t + c * x) \<partial>lborel)"
   557   by (subst lebesgue_real_affine[OF c, of t])
   563   by (subst lborel_real_affine[OF c, of t])
   558      (simp add: f integral_density integral_distr lebesgue_integral_cmult)
   564      (simp add: positive_integral_density positive_integral_distr positive_integral_cmult)
       
   565 
       
   566 lemma lborel_integrable_real_affine:
       
   567   fixes f :: "real \<Rightarrow> _ :: {banach, second_countable_topology}"
       
   568   assumes f: "integrable lborel f"
       
   569   shows "c \<noteq> 0 \<Longrightarrow> integrable lborel (\<lambda>x. f (t + c * x))"
       
   570   using f f[THEN borel_measurable_integrable] unfolding integrable_iff_bounded
       
   571   by (subst (asm) positive_integral_real_affine[where c=c and t=t]) auto
       
   572 
       
   573 lemma lborel_integrable_real_affine_iff:
       
   574   fixes f :: "real \<Rightarrow> 'a :: {banach, second_countable_topology}"
       
   575   shows "c \<noteq> 0 \<Longrightarrow> integrable lborel (\<lambda>x. f (t + c * x)) \<longleftrightarrow> integrable lborel f"
       
   576   using
       
   577     lborel_integrable_real_affine[of f c t]
       
   578     lborel_integrable_real_affine[of "\<lambda>x. f (t + c * x)" "1/c" "-t/c"]
       
   579   by (auto simp add: field_simps)
       
   580 
       
   581 lemma lborel_integral_real_affine:
       
   582   fixes f :: "real \<Rightarrow> 'a :: {banach, second_countable_topology}" and c :: real
       
   583   assumes c: "c \<noteq> 0" and f[measurable]: "integrable lborel f"
       
   584   shows "(\<integral>x. f x \<partial> lborel) = \<bar>c\<bar> *\<^sub>R (\<integral>x. f (t + c * x) \<partial>lborel)"
       
   585   using c f f[THEN borel_measurable_integrable] f[THEN lborel_integrable_real_affine, of c t]
       
   586   by (subst lborel_real_affine[OF c, of t]) (simp add: integral_density integral_distr)
       
   587 
       
   588 lemma divideR_right: 
       
   589   fixes x y :: "'a::real_normed_vector"
       
   590   shows "r \<noteq> 0 \<Longrightarrow> y = x /\<^sub>R r \<longleftrightarrow> r *\<^sub>R y = x"
       
   591   using scaleR_cancel_left[of r y "x /\<^sub>R r"] by simp
       
   592 
       
   593 lemma integrable_on_cmult_iff2:
       
   594   fixes c :: real
       
   595   shows "(\<lambda>x. c * f x) integrable_on s \<longleftrightarrow> c = 0 \<or> f integrable_on s"
       
   596   using integrable_cmul[of "\<lambda>x. c * f x" s "1 / c"] integrable_cmul[of f s c]
       
   597   by (cases "c = 0") auto
       
   598 
       
   599 lemma lborel_has_bochner_integral_real_affine_iff:
       
   600   fixes x :: "'a :: {banach, second_countable_topology}"
       
   601   shows "c \<noteq> 0 \<Longrightarrow>
       
   602     has_bochner_integral lborel f x \<longleftrightarrow>
       
   603     has_bochner_integral lborel (\<lambda>x. f (t + c * x)) (x /\<^sub>R \<bar>c\<bar>)"
       
   604   unfolding has_bochner_integral_iff lborel_integrable_real_affine_iff
       
   605   by (simp_all add: lborel_integral_real_affine[symmetric] divideR_right cong: conj_cong)
   559 
   606 
   560 subsection {* Lebesgue integrable implies Gauge integrable *}
   607 subsection {* Lebesgue integrable implies Gauge integrable *}
   561 
   608 
   562 lemma simple_function_has_integral:
   609 lemma has_integral_scaleR_left: 
   563   fixes f::"'a::ordered_euclidean_space \<Rightarrow> ereal"
   610   "(f has_integral y) s \<Longrightarrow> ((\<lambda>x. f x *\<^sub>R c) has_integral (y *\<^sub>R c)) s"
   564   assumes f:"simple_function lebesgue f"
   611   using has_integral_linear[OF _ bounded_linear_scaleR_left] by (simp add: comp_def)
   565   and f':"range f \<subseteq> {0..<\<infinity>}"
   612 
   566   and om:"\<And>x. x \<in> range f \<Longrightarrow> emeasure lebesgue (f -` {x} \<inter> UNIV) = \<infinity> \<Longrightarrow> x = 0"
   613 lemma has_integral_mult_left:
   567   shows "((\<lambda>x. real (f x)) has_integral (real (integral\<^sup>S lebesgue f))) UNIV"
   614   fixes c :: "_ :: {real_normed_algebra}"
   568   unfolding simple_integral_def space_lebesgue
   615   shows "(f has_integral y) s \<Longrightarrow> ((\<lambda>x. f x * c) has_integral (y * c)) s"
   569 proof (subst lebesgue_simple_function_indicator)
   616   using has_integral_linear[OF _ bounded_linear_mult_left] by (simp add: comp_def)
   570   let ?M = "\<lambda>x. emeasure lebesgue (f -` {x} \<inter> UNIV)"
   617 
   571   let ?F = "\<lambda>x. indicator (f -` {x})"
   618 (* GENERALIZE Integration.dominated_convergence, then generalize the following theorems *)
   572   { fix x y assume "y \<in> range f"
   619 lemma has_integral_dominated_convergence:
   573     from subsetD[OF f' this] have "y * ?F y x = ereal (real y * ?F y x)"
   620   fixes f :: "nat \<Rightarrow> 'n::ordered_euclidean_space \<Rightarrow> real"
   574       by (cases rule: ereal2_cases[of y "?F y x"])
   621   assumes "\<And>k. (f k has_integral y k) s" "h integrable_on s"
   575          (auto simp: indicator_def one_ereal_def split: split_if_asm) }
   622     "\<And>k. \<forall>x\<in>s. norm (f k x) \<le> h x" "\<forall>x\<in>s. (\<lambda>k. f k x) ----> g x"
       
   623     and x: "y ----> x"
       
   624   shows "(g has_integral x) s"
       
   625 proof -
       
   626   have int_f: "\<And>k. (f k) integrable_on s"
       
   627     using assms by (auto simp: integrable_on_def)
       
   628   have "(g has_integral (integral s g)) s"
       
   629     by (intro integrable_integral dominated_convergence[OF int_f assms(2)]) fact+
       
   630   moreover have "integral s g = x"
       
   631   proof (rule LIMSEQ_unique)
       
   632     show "(\<lambda>i. integral s (f i)) ----> x"
       
   633       using integral_unique[OF assms(1)] x by simp
       
   634     show "(\<lambda>i. integral s (f i)) ----> integral s g"
       
   635       by (intro dominated_convergence[OF int_f assms(2)]) fact+
       
   636   qed
       
   637   ultimately show ?thesis
       
   638     by simp
       
   639 qed
       
   640 
       
   641 lemma positive_integral_has_integral:
       
   642   fixes f::"'a::ordered_euclidean_space \<Rightarrow> real"
       
   643   assumes f: "f \<in> borel_measurable lebesgue" "\<And>x. 0 \<le> f x" "(\<integral>\<^sup>+x. f x \<partial>lebesgue) = ereal r"
       
   644   shows "(f has_integral r) UNIV"
       
   645 using f proof (induct arbitrary: r rule: borel_measurable_induct_real)
       
   646   case (set A) then show ?case
       
   647     by (auto simp add: ereal_indicator has_integral_iff_lmeasure)
       
   648 next
       
   649   case (mult g c)
       
   650   then have "ereal c * (\<integral>\<^sup>+ x. g x \<partial>lebesgue) = ereal r"
       
   651     by (subst positive_integral_cmult[symmetric]) auto
       
   652   then obtain r' where "(c = 0 \<and> r = 0) \<or> ((\<integral>\<^sup>+ x. ereal (g x) \<partial>lebesgue) = ereal r' \<and> r = c * r')"
       
   653     by (cases "\<integral>\<^sup>+ x. ereal (g x) \<partial>lebesgue") (auto split: split_if_asm)
       
   654   with mult show ?case
       
   655     by (auto intro!: has_integral_cmult_real)
       
   656 next
       
   657   case (add g h)
   576   moreover
   658   moreover
   577   { fix x assume x: "x\<in>range f"
   659   then have "(\<integral>\<^sup>+ x. h x + g x \<partial>lebesgue) = (\<integral>\<^sup>+ x. h x \<partial>lebesgue) + (\<integral>\<^sup>+ x. g x \<partial>lebesgue)"
   578     have "x * ?M x = real x * real (?M x)"
   660     unfolding plus_ereal.simps[symmetric] by (subst positive_integral_add) auto
   579     proof cases
   661   with add obtain a b where "(\<integral>\<^sup>+ x. h x \<partial>lebesgue) = ereal a" "(\<integral>\<^sup>+ x. g x \<partial>lebesgue) = ereal b" "r = a + b"
   580       assume "x \<noteq> 0" with om[OF x] have "?M x \<noteq> \<infinity>" by auto
   662     by (cases "\<integral>\<^sup>+ x. h x \<partial>lebesgue" "\<integral>\<^sup>+ x. g x \<partial>lebesgue" rule: ereal2_cases) auto
   581       with subsetD[OF f' x] f[THEN simple_functionD(2)] show ?thesis
   663   ultimately show ?case
   582         by (cases rule: ereal2_cases[of x "?M x"]) auto
   664     by (auto intro!: has_integral_add)
   583     qed simp }
   665 next
   584   ultimately
   666   case (seq U)
   585   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>
   667   note seq(1)[measurable] and f[measurable]
   586     ((\<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"
   668 
   587     by simp
   669   { fix i x 
   588   also have \<dots>
   670     have "U i x \<le> f x"
   589   proof (intro has_integral_setsum has_integral_cmult_real lmeasure_finite_has_integral
   671       using seq(5)
   590                real_of_ereal_pos emeasure_nonneg ballI)
   672       apply (rule LIMSEQ_le_const)
   591     show *: "finite (range f)" "\<And>y. f -` {y} \<in> sets lebesgue"
   673       using seq(4)
   592       using simple_functionD[OF f] by auto
   674       apply (auto intro!: exI[of _ i] simp: incseq_def le_fun_def)
   593     fix y assume "real y \<noteq> 0" "y \<in> range f"
   675       done }
   594     with * om[OF this(2)] show "emeasure lebesgue (f -` {y}) = ereal (real (?M y))"
   676   note U_le_f = this
   595       by (auto simp: ereal_real)
   677   
   596   qed
       
   597   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" .
       
   598 qed fact
       
   599 
       
   600 lemma simple_function_has_integral':
       
   601   fixes f::"'a::ordered_euclidean_space \<Rightarrow> ereal"
       
   602   assumes f: "simple_function lebesgue f" "\<And>x. 0 \<le> f x"
       
   603   and i: "integral\<^sup>S lebesgue f \<noteq> \<infinity>"
       
   604   shows "((\<lambda>x. real (f x)) has_integral (real (integral\<^sup>S lebesgue f))) UNIV"
       
   605 proof -
       
   606   let ?f = "\<lambda>x. if x \<in> f -` {\<infinity>} then 0 else f x"
       
   607   note f(1)[THEN simple_functionD(2)]
       
   608   then have [simp, intro]: "\<And>X. f -` X \<in> sets lebesgue" by auto
       
   609   have f': "simple_function lebesgue ?f"
       
   610     using f by (intro simple_function_If_set) auto
       
   611   have rng: "range ?f \<subseteq> {0..<\<infinity>}" using f by auto
       
   612   have "AE x in lebesgue. f x = ?f x"
       
   613     using simple_integral_PInf[OF f i]
       
   614     by (intro AE_I[where N="f -` {\<infinity>} \<inter> space lebesgue"]) auto
       
   615   from f(1) f' this have eq: "integral\<^sup>S lebesgue f = integral\<^sup>S lebesgue ?f"
       
   616     by (rule simple_integral_cong_AE)
       
   617   have real_eq: "\<And>x. real (f x) = real (?f x)" by auto
       
   618 
       
   619   show ?thesis
       
   620     unfolding eq real_eq
       
   621   proof (rule simple_function_has_integral[OF f' rng])
       
   622     fix x assume x: "x \<in> range ?f" and inf: "emeasure lebesgue (?f -` {x} \<inter> UNIV) = \<infinity>"
       
   623     have "x * emeasure lebesgue (?f -` {x} \<inter> UNIV) = (\<integral>\<^sup>S y. x * indicator (?f -` {x}) y \<partial>lebesgue)"
       
   624       using f'[THEN simple_functionD(2)]
       
   625       by (simp add: simple_integral_cmult_indicator)
       
   626     also have "\<dots> \<le> integral\<^sup>S lebesgue f"
       
   627       using f'[THEN simple_functionD(2)] f
       
   628       by (intro simple_integral_mono simple_function_mult simple_function_indicator)
       
   629          (auto split: split_indicator)
       
   630     finally show "x = 0" unfolding inf using i subsetD[OF rng x] by (auto split: split_if_asm)
       
   631   qed
       
   632 qed
       
   633 
       
   634 lemma positive_integral_has_integral:
       
   635   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> ereal"
       
   636   assumes f: "f \<in> borel_measurable lebesgue" "range f \<subseteq> {0..<\<infinity>}" "integral\<^sup>P lebesgue f \<noteq> \<infinity>"
       
   637   shows "((\<lambda>x. real (f x)) has_integral (real (integral\<^sup>P lebesgue f))) UNIV"
       
   638 proof -
       
   639   from borel_measurable_implies_simple_function_sequence'[OF f(1)]
       
   640   guess u . note u = this
       
   641   have SUP_eq: "\<And>x. (SUP i. u i x) = f x"
       
   642     using u(4) f(2)[THEN subsetD] by (auto split: split_max)
       
   643   let ?u = "\<lambda>i x. real (u i x)"
       
   644   note u_eq = positive_integral_eq_simple_integral[OF u(1,5), symmetric]
       
   645   { fix i
   678   { fix i
   646     note u_eq
   679     have "(\<integral>\<^sup>+x. ereal (U i x) \<partial>lebesgue) \<le> (\<integral>\<^sup>+x. ereal (f x) \<partial>lebesgue)"
   647     also have "integral\<^sup>P lebesgue (u i) \<le> (\<integral>\<^sup>+x. max 0 (f x) \<partial>lebesgue)"
   680       using U_le_f by (intro positive_integral_mono) simp
   648       by (intro positive_integral_mono) (auto intro: SUP_upper simp: u(4)[symmetric])
   681     then obtain p where "(\<integral>\<^sup>+x. U i x \<partial>lebesgue) = ereal p" "p \<le> r"
   649     finally have "integral\<^sup>S lebesgue (u i) \<noteq> \<infinity>"
   682       using seq(6) by (cases "\<integral>\<^sup>+x. U i x \<partial>lebesgue") auto
   650       unfolding positive_integral_max_0 using f by auto }
   683     moreover then have "0 \<le> p"
   651   note u_fin = this
   684       by (metis ereal_less_eq(5) positive_integral_positive)
   652   then have u_int: "\<And>i. (?u i has_integral real (integral\<^sup>S lebesgue (u i))) UNIV"
   685     moreover note seq
   653     by (rule simple_function_has_integral'[OF u(1,5)])
   686     ultimately have "\<exists>p. (\<integral>\<^sup>+x. U i x \<partial>lebesgue) = ereal p \<and> 0 \<le> p \<and> p \<le> r \<and> (U i has_integral p) UNIV"
   654   have "\<forall>x. \<exists>r\<ge>0. f x = ereal r"
   687       by auto }
   655   proof
   688   then obtain p where p: "\<And>i. (\<integral>\<^sup>+x. ereal (U i x) \<partial>lebesgue) = ereal (p i)"
   656     fix x from f(2) have "0 \<le> f x" "f x \<noteq> \<infinity>" by (auto simp: subset_eq)
   689     and bnd: "\<And>i. p i \<le> r" "\<And>i. 0 \<le> p i"
   657     then show "\<exists>r\<ge>0. f x = ereal r" by (cases "f x") auto
   690     and U_int: "\<And>i.(U i has_integral (p i)) UNIV" by metis
   658   qed
   691 
   659   from choice[OF this] obtain f' where f': "f = (\<lambda>x. ereal (f' x))" "\<And>x. 0 \<le> f' x" by auto
   692   have int_eq: "\<And>i. integral UNIV (U i) = p i" using U_int by (rule integral_unique)
   660 
   693 
   661   have "\<forall>i. \<exists>r. \<forall>x. 0 \<le> r x \<and> u i x = ereal (r x)"
   694   have *: "f integrable_on UNIV \<and> (\<lambda>k. integral UNIV (U k)) ----> integral UNIV f"
   662   proof
   695   proof (rule monotone_convergence_increasing)
   663     fix i show "\<exists>r. \<forall>x. 0 \<le> r x \<and> u i x = ereal (r x)"
   696     show "\<forall>k. U k integrable_on UNIV" using U_int by auto
   664     proof (intro choice allI)
   697     show "\<forall>k. \<forall>x\<in>UNIV. U k x \<le> U (Suc k) x" using `incseq U` by (auto simp: incseq_def le_fun_def)
   665       fix i x have "u i x \<noteq> \<infinity>" using u(3)[of i] by (auto simp: image_iff) metis
   698     then show "bounded {integral UNIV (U k) |k. True}"
   666       then show "\<exists>r\<ge>0. u i x = ereal r" using u(5)[of i x] by (cases "u i x") auto
   699       using bnd int_eq by (auto simp: bounded_real intro!: exI[of _ r])
   667     qed
   700     show "\<forall>x\<in>UNIV. (\<lambda>k. U k x) ----> f x"
   668   qed
   701       using seq by auto
   669   from choice[OF this] obtain u' where
   702   qed
   670       u': "u = (\<lambda>i x. ereal (u' i x))" "\<And>i x. 0 \<le> u' i x" by (auto simp: fun_eq_iff)
   703   moreover have "(\<lambda>i. (\<integral>\<^sup>+x. U i x \<partial>lebesgue)) ----> (\<integral>\<^sup>+x. f x \<partial>lebesgue)"
   671 
   704     using seq U_le_f by (intro positive_integral_dominated_convergence[where w=f]) auto
   672   have convergent: "f' integrable_on UNIV \<and>
   705   ultimately have "integral UNIV f = r"
   673     (\<lambda>k. integral UNIV (u' k)) ----> integral UNIV f'"
   706     by (auto simp add: int_eq p seq intro: LIMSEQ_unique)
   674   proof (intro monotone_convergence_increasing allI ballI)
   707   with * show ?case
   675     show int: "\<And>k. (u' k) integrable_on UNIV"
   708     by (simp add: has_integral_integral)
   676       using u_int unfolding integrable_on_def u' by auto
   709 qed
   677     show "\<And>k x. u' k x \<le> u' (Suc k) x" using u(2,3,5)
   710 
   678       by (auto simp: incseq_Suc_iff le_fun_def image_iff u' intro!: real_of_ereal_positive_mono)
   711 lemma has_integral_integrable_lebesgue_nonneg:
   679     show "\<And>x. (\<lambda>k. u' k x) ----> f' x"
   712   fixes f::"'a::ordered_euclidean_space \<Rightarrow> real"
   680       using SUP_eq u(2)
   713   assumes f: "integrable lebesgue f" "\<And>x. 0 \<le> f x"
   681       by (intro SUP_eq_LIMSEQ[THEN iffD1]) (auto simp: u' f' incseq_Suc_iff le_fun_def)
   714   shows "(f has_integral integral\<^sup>L lebesgue f) UNIV"
   682     show "bounded {integral UNIV (u' k)|k. True}"
   715 proof (rule positive_integral_has_integral)
   683     proof (safe intro!: bounded_realI)
   716   show "(\<integral>\<^sup>+ x. ereal (f x) \<partial>lebesgue) = ereal (integral\<^sup>L lebesgue f)"
   684       fix k
   717     using f by (intro positive_integral_eq_integral) auto
   685       have "\<bar>integral UNIV (u' k)\<bar> = integral UNIV (u' k)"
   718 qed (insert f, auto)
   686         by (intro abs_of_nonneg integral_nonneg int ballI u')
   719 
   687       also have "\<dots> = real (integral\<^sup>S lebesgue (u k))"
   720 lemma has_integral_lebesgue_integral_lebesgue:
   688         using u_int[THEN integral_unique] by (simp add: u')
   721   fixes f::"'a::ordered_euclidean_space \<Rightarrow> real"
   689       also have "\<dots> = real (integral\<^sup>P lebesgue (u k))"
       
   690         using positive_integral_eq_simple_integral[OF u(1,5)] by simp
       
   691       also have "\<dots> \<le> real (integral\<^sup>P lebesgue f)" using f
       
   692         by (auto intro!: real_of_ereal_positive_mono positive_integral_positive
       
   693              positive_integral_mono SUP_upper simp: SUP_eq[symmetric])
       
   694       finally show "\<bar>integral UNIV (u' k)\<bar> \<le> real (integral\<^sup>P lebesgue f)" .
       
   695     qed
       
   696   qed
       
   697 
       
   698   have "integral\<^sup>P lebesgue f = ereal (integral UNIV f')"
       
   699   proof (rule tendsto_unique[OF trivial_limit_sequentially])
       
   700     have "(\<lambda>i. integral\<^sup>S lebesgue (u i)) ----> (SUP i. integral\<^sup>P lebesgue (u i))"
       
   701       unfolding u_eq by (intro LIMSEQ_SUP incseq_positive_integral u)
       
   702     also note positive_integral_monotone_convergence_SUP
       
   703       [OF u(2)  borel_measurable_simple_function[OF u(1)] u(5), symmetric]
       
   704     finally show "(\<lambda>k. integral\<^sup>S lebesgue (u k)) ----> integral\<^sup>P lebesgue f"
       
   705       unfolding SUP_eq .
       
   706 
       
   707     { fix k
       
   708       have "0 \<le> integral\<^sup>S lebesgue (u k)"
       
   709         using u by (auto intro!: simple_integral_positive)
       
   710       then have "integral\<^sup>S lebesgue (u k) = ereal (real (integral\<^sup>S lebesgue (u k)))"
       
   711         using u_fin by (auto simp: ereal_real) }
       
   712     note * = this
       
   713     show "(\<lambda>k. integral\<^sup>S lebesgue (u k)) ----> ereal (integral UNIV f')"
       
   714       using convergent using u_int[THEN integral_unique, symmetric]
       
   715       by (subst *) (simp add: u')
       
   716   qed
       
   717   then show ?thesis using convergent by (simp add: f' integrable_integral)
       
   718 qed
       
   719 
       
   720 lemma lebesgue_integral_has_integral:
       
   721   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
       
   722   assumes f: "integrable lebesgue f"
   722   assumes f: "integrable lebesgue f"
   723   shows "(f has_integral (integral\<^sup>L lebesgue f)) UNIV"
   723   shows "(f has_integral (integral\<^sup>L lebesgue f)) UNIV"
   724 proof -
   724 using f proof induct
   725   let ?n = "\<lambda>x. real (ereal (max 0 (- f x)))" and ?p = "\<lambda>x. real (ereal (max 0 (f x)))"
   725   case (base A c) then show ?case
   726   have *: "f = (\<lambda>x. ?p x - ?n x)" by (auto simp del: ereal_max)
   726     by (auto intro!: has_integral_mult_left simp: has_integral_iff_lmeasure)
   727   { fix f :: "'a \<Rightarrow> real" have "(\<integral>\<^sup>+ x. ereal (f x) \<partial>lebesgue) = (\<integral>\<^sup>+ x. ereal (max 0 (f x)) \<partial>lebesgue)"
   727        (simp add: emeasure_eq_ereal_measure)
   728       by (intro positive_integral_cong_pos) (auto split: split_max) }
   728 next
   729   note eq = this
   729   case (add f g) then show ?case
   730   show ?thesis
   730     by (auto intro!: has_integral_add)
   731     unfolding lebesgue_integral_def
   731 next
   732     apply (subst *)
   732   case (lim f s)
   733     apply (rule has_integral_sub)
   733   show ?case
   734     unfolding eq[of f] eq[of "\<lambda>x. - f x"]
   734   proof (rule has_integral_dominated_convergence)
   735     apply (safe intro!: positive_integral_has_integral)
   735     show "\<And>i. (s i has_integral integral\<^sup>L lebesgue (s i)) UNIV" by fact
   736     using integrableD[OF f]
   736     show "(\<lambda>x. norm (2 * f x)) integrable_on UNIV"
   737     by (auto simp: zero_ereal_def[symmetric] positive_integral_max_0  split: split_max
   737       using lim by (intro has_integral_integrable[OF has_integral_integrable_lebesgue_nonneg]) auto
   738              intro!: measurable_If)
   738     show "\<And>k. \<forall>x\<in>UNIV. norm (s k x) \<le> norm (2 * f x)"
   739 qed
   739       using lim by (auto simp add: abs_mult)
   740 
   740     show "\<forall>x\<in>UNIV. (\<lambda>k. s k x) ----> f x"
   741 lemma lebesgue_simple_integral_eq_borel:
   741       using lim by auto
   742   assumes f: "f \<in> borel_measurable borel"
   742     show "(\<lambda>k. integral\<^sup>L lebesgue (s k)) ----> integral\<^sup>L lebesgue f"
   743   shows "integral\<^sup>S lebesgue f = integral\<^sup>S lborel f"
   743       using lim by (intro integral_dominated_convergence(3)[where w="\<lambda>x. 2 * norm (f x)"]) auto
   744   using f[THEN measurable_sets]
   744   qed
   745   by (auto intro!: setsum_cong arg_cong2[where f="op *"] emeasure_lborel[symmetric]
   745 qed
   746            simp: simple_integral_def)
       
   747 
   746 
   748 lemma lebesgue_positive_integral_eq_borel:
   747 lemma lebesgue_positive_integral_eq_borel:
   749   assumes f: "f \<in> borel_measurable borel"
   748   assumes f: "f \<in> borel_measurable borel"
   750   shows "integral\<^sup>P lebesgue f = integral\<^sup>P lborel f"
   749   shows "integral\<^sup>P lebesgue f = integral\<^sup>P lborel f"
   751 proof -
   750 proof -
   753     by (auto intro!: positive_integral_subalgebra[symmetric])
   752     by (auto intro!: positive_integral_subalgebra[symmetric])
   754   then show ?thesis unfolding positive_integral_max_0 .
   753   then show ?thesis unfolding positive_integral_max_0 .
   755 qed
   754 qed
   756 
   755 
   757 lemma lebesgue_integral_eq_borel:
   756 lemma lebesgue_integral_eq_borel:
       
   757   fixes f :: "_ \<Rightarrow> _::{banach, second_countable_topology}"
   758   assumes "f \<in> borel_measurable borel"
   758   assumes "f \<in> borel_measurable borel"
   759   shows "integrable lebesgue f \<longleftrightarrow> integrable lborel f" (is ?P)
   759   shows "integrable lebesgue f \<longleftrightarrow> integrable lborel f" (is ?P)
   760     and "integral\<^sup>L lebesgue f = integral\<^sup>L lborel f" (is ?I)
   760     and "integral\<^sup>L lebesgue f = integral\<^sup>L lborel f" (is ?I)
   761 proof -
   761 proof -
   762   have "sets lborel \<subseteq> sets lebesgue" by auto
   762   have "sets lborel \<subseteq> sets lebesgue" by auto
   763   from integral_subalgebra[of f lborel, OF _ this _ _] assms
   763   from integral_subalgebra[of f lborel, OF _ this _ _]
       
   764        integrable_subalgebra[of f lborel, OF _ this _ _] assms
   764   show ?P ?I by auto
   765   show ?P ?I by auto
   765 qed
   766 qed
   766 
   767 
   767 lemma borel_integral_has_integral:
   768 lemma has_integral_lebesgue_integral:
   768   fixes f::"'a::ordered_euclidean_space => real"
   769   fixes f::"'a::ordered_euclidean_space => real"
   769   assumes f:"integrable lborel f"
   770   assumes f:"integrable lborel f"
   770   shows "(f has_integral (integral\<^sup>L lborel f)) UNIV"
   771   shows "(f has_integral (integral\<^sup>L lborel f)) UNIV"
   771 proof -
   772 proof -
   772   have borel: "f \<in> borel_measurable borel"
   773   have borel: "f \<in> borel_measurable borel"
   773     using f unfolding integrable_def by auto
   774     using f unfolding integrable_iff_bounded by auto
   774   from f show ?thesis
   775   from f show ?thesis
   775     using lebesgue_integral_has_integral[of f]
   776     using has_integral_lebesgue_integral_lebesgue[of f]
   776     unfolding lebesgue_integral_eq_borel[OF borel] by simp
   777     unfolding lebesgue_integral_eq_borel[OF borel] by simp
   777 qed
   778 qed
   778 
   779 
   779 lemma positive_integral_lebesgue_has_integral:
   780 lemma positive_integral_bound_simple_function:
       
   781   assumes bnd: "\<And>x. x \<in> space M \<Longrightarrow> 0 \<le> f x" "\<And>x. x \<in> space M \<Longrightarrow> f x < \<infinity>"
       
   782   assumes f[measurable]: "simple_function M f"
       
   783   assumes supp: "emeasure M {x\<in>space M. f x \<noteq> 0} < \<infinity>"
       
   784   shows "positive_integral M f < \<infinity>"
       
   785 proof cases
       
   786   assume "space M = {}"
       
   787   then have "positive_integral M f = (\<integral>\<^sup>+x. 0 \<partial>M)"
       
   788     by (intro positive_integral_cong) auto
       
   789   then show ?thesis by simp
       
   790 next
       
   791   assume "space M \<noteq> {}"
       
   792   with simple_functionD(1)[OF f] bnd have bnd: "0 \<le> Max (f`space M) \<and> Max (f`space M) < \<infinity>"
       
   793     by (subst Max_less_iff) (auto simp: Max_ge_iff)
       
   794   
       
   795   have "positive_integral M f \<le> (\<integral>\<^sup>+x. Max (f`space M) * indicator {x\<in>space M. f x \<noteq> 0} x \<partial>M)"
       
   796   proof (rule positive_integral_mono)
       
   797     fix x assume "x \<in> space M"
       
   798     with f show "f x \<le> Max (f ` space M) * indicator {x \<in> space M. f x \<noteq> 0} x"
       
   799       by (auto split: split_indicator intro!: Max_ge simple_functionD)
       
   800   qed
       
   801   also have "\<dots> < \<infinity>"
       
   802     using bnd supp by (subst positive_integral_cmult) auto
       
   803   finally show ?thesis .
       
   804 qed
       
   805 
       
   806 
       
   807 lemma
   780   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
   808   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
   781   assumes f_borel: "f \<in> borel_measurable lebesgue" and nonneg: "\<And>x. 0 \<le> f x"
   809   assumes f_borel: "f \<in> borel_measurable lebesgue" and nonneg: "\<And>x. 0 \<le> f x"
   782   assumes I: "(f has_integral I) UNIV"
   810   assumes I: "(f has_integral I) UNIV"
   783   shows "(\<integral>\<^sup>+x. f x \<partial>lebesgue) = I"
   811   shows integrable_has_integral_lebesgue_nonneg: "integrable lebesgue f"
       
   812     and integral_has_integral_lebesgue_nonneg: "integral\<^sup>L lebesgue f = I"
   784 proof -
   813 proof -
   785   from f_borel have "(\<lambda>x. ereal (f x)) \<in> borel_measurable lebesgue" by auto
   814   from f_borel have "(\<lambda>x. ereal (f x)) \<in> borel_measurable lebesgue" by auto
   786   from borel_measurable_implies_simple_function_sequence'[OF this] guess F . note F = this
   815   from borel_measurable_implies_simple_function_sequence'[OF this] guess F . note F = this
   787 
   816 
   788   have "(\<integral>\<^sup>+ x. ereal (f x) \<partial>lebesgue) = (SUP i. integral\<^sup>S lebesgue (F i))"
   817   have "(\<integral>\<^sup>+ x. ereal (f x) \<partial>lebesgue) = (SUP i. integral\<^sup>P lebesgue (F i))"
   789     using F
   818     using F
   790     by (subst positive_integral_monotone_convergence_simple)
   819     by (subst positive_integral_monotone_convergence_SUP[symmetric])
   791        (simp_all add: positive_integral_max_0 simple_function_def)
   820        (simp_all add: positive_integral_max_0 borel_measurable_simple_function)
   792   also have "\<dots> \<le> ereal I"
   821   also have "\<dots> \<le> ereal I"
   793   proof (rule SUP_least)
   822   proof (rule SUP_least)
   794     fix i :: nat
   823     fix i :: nat
   795 
   824 
   796     { fix z
   825     { fix z
   833       qed
   862       qed
   834       then have "(indicator (F i -` {x}) :: 'a \<Rightarrow> real) integrable_on UNIV"
   863       then have "(indicator (F i -` {x}) :: 'a \<Rightarrow> real) integrable_on UNIV"
   835         by (simp add: integrable_on_cmult_iff) }
   864         by (simp add: integrable_on_cmult_iff) }
   836     note F_finite = lmeasure_finite[OF this]
   865     note F_finite = lmeasure_finite[OF this]
   837 
   866 
   838     have "((\<lambda>x. real (F i x)) has_integral real (integral\<^sup>S lebesgue (F i))) UNIV"
   867     have F_eq: "\<And>x. F i x = ereal (norm (real (F i x)))"
   839     proof (rule simple_function_has_integral[of "F i"])
   868       using F(3,5) by (auto simp: fun_eq_iff ereal_real image_iff eq_commute)
   840       show "simple_function lebesgue (F i)"
   869     have F_eq2: "\<And>x. F i x = ereal (real (F i x))"
   841         using F(1) by (simp add: simple_function_def)
   870       using F(3,5) by (auto simp: fun_eq_iff ereal_real image_iff eq_commute)
   842       show "range (F i) \<subseteq> {0..<\<infinity>}"
   871 
   843         using F(3,5)[of i] by (auto simp: image_iff) metis
   872     have int: "integrable lebesgue (\<lambda>x. real (F i x))"
   844     next
   873       unfolding integrable_iff_bounded
   845       fix x assume "x \<in> range (F i)" "emeasure lebesgue (F i -` {x} \<inter> UNIV) = \<infinity>"
   874     proof
   846       with F_finite[of x] show "x = 0" by auto
   875       have "(\<integral>\<^sup>+x. F i x \<partial>lebesgue) < \<infinity>"
   847     qed
   876       proof (rule positive_integral_bound_simple_function)
   848     from this I have "real (integral\<^sup>S lebesgue (F i)) \<le> I"
   877         fix x::'a assume "x \<in> space lebesgue" then show "0 \<le> F i x" "F i x < \<infinity>"
       
   878           using F by (auto simp: image_iff eq_commute)
       
   879       next
       
   880         have eq: "{x \<in> space lebesgue. F i x \<noteq> 0} = (\<Union>x\<in>F i ` space lebesgue - {0}. F i -` {x} \<inter> space lebesgue)"
       
   881           by auto
       
   882         show "emeasure lebesgue {x \<in> space lebesgue. F i x \<noteq> 0} < \<infinity>"
       
   883           unfolding eq using simple_functionD[OF F(1)]
       
   884           by (subst setsum_emeasure[symmetric])
       
   885              (auto simp: disjoint_family_on_def setsum_Pinfty F_finite)
       
   886       qed fact
       
   887       with F_eq show "(\<integral>\<^sup>+x. norm (real (F i x)) \<partial>lebesgue) < \<infinity>" by simp
       
   888     qed (insert F(1), auto intro!: borel_measurable_real_of_ereal dest: borel_measurable_simple_function)
       
   889     then have "((\<lambda>x. real (F i x)) has_integral integral\<^sup>L lebesgue (\<lambda>x. real (F i x))) UNIV"
       
   890       by (rule has_integral_lebesgue_integral_lebesgue)
       
   891     from this I have "integral\<^sup>L lebesgue (\<lambda>x. real (F i x)) \<le> I"
   849       by (rule has_integral_le) (intro ballI F_bound)
   892       by (rule has_integral_le) (intro ballI F_bound)
   850     moreover
   893     moreover have "integral\<^sup>P lebesgue (F i) = integral\<^sup>L lebesgue (\<lambda>x. real (F i x))"
   851     { fix x assume x: "x \<in> range (F i)"
   894       using int F by (subst positive_integral_eq_integral[symmetric])  (auto simp: F_eq2[symmetric] real_of_ereal_pos)
   852       with F(3,5)[of i] have "x = 0 \<or> (0 < x \<and> x \<noteq> \<infinity>)"
   895     ultimately show "integral\<^sup>P lebesgue (F i) \<le> ereal I"
   853         by (auto  simp: image_iff le_less) metis
   896       by simp
   854       with F_finite[OF _ x] x have "x * emeasure lebesgue (F i -` {x} \<inter> UNIV) \<noteq> \<infinity>"
   897   qed
   855         by auto }
   898   finally show "integrable lebesgue f"
   856     then have "integral\<^sup>S lebesgue (F i) \<noteq> \<infinity>"
   899     using f_borel by (auto simp: integrable_iff_bounded nonneg)
   857       unfolding simple_integral_def setsum_Pinfty space_lebesgue by blast
   900   from has_integral_lebesgue_integral_lebesgue[OF this] I
   858     moreover have "0 \<le> integral\<^sup>S lebesgue (F i)"
   901   show "integral\<^sup>L lebesgue f = I"
   859       using F(1,5) by (intro simple_integral_positive) (auto simp: simple_function_def)
   902     by (metis has_integral_unique)
   860     ultimately show "integral\<^sup>S lebesgue (F i) \<le> ereal I"
   903 qed
   861       by (cases "integral\<^sup>S lebesgue (F i)") auto
   904 
   862   qed
   905 lemma has_integral_iff_has_bochner_integral_lebesgue_nonneg:
   863   also have "\<dots> < \<infinity>" by simp
       
   864   finally have finite: "(\<integral>\<^sup>+ x. ereal (f x) \<partial>lebesgue) \<noteq> \<infinity>" by simp
       
   865   have borel: "(\<lambda>x. ereal (f x)) \<in> borel_measurable lebesgue"
       
   866     using f_borel by (auto intro: borel_measurable_lebesgueI)
       
   867   from positive_integral_has_integral[OF borel _ finite]
       
   868   have "(f has_integral real (\<integral>\<^sup>+ x. ereal (f x) \<partial>lebesgue)) UNIV"
       
   869     using nonneg by (simp add: subset_eq)
       
   870   with I have "I = real (\<integral>\<^sup>+ x. ereal (f x) \<partial>lebesgue)"
       
   871     by (rule has_integral_unique)
       
   872   with finite positive_integral_positive[of _ "\<lambda>x. ereal (f x)"] show ?thesis
       
   873     by (cases "\<integral>\<^sup>+ x. ereal (f x) \<partial>lebesgue") auto
       
   874 qed
       
   875 
       
   876 lemma has_integral_iff_positive_integral_lebesgue:
       
   877   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
   906   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
   878   assumes f: "f \<in> borel_measurable lebesgue" "\<And>x. 0 \<le> f x"
   907   shows "f \<in> borel_measurable lebesgue \<Longrightarrow> (\<And>x. 0 \<le> f x) \<Longrightarrow>
   879   shows "(f has_integral I) UNIV \<longleftrightarrow> integral\<^sup>P lebesgue f = I"
   908     (f has_integral I) UNIV \<longleftrightarrow> has_bochner_integral lebesgue f I"
   880   using f positive_integral_lebesgue_has_integral[of f I] positive_integral_has_integral[of f]
   909   by (metis has_bochner_integral_iff has_integral_unique has_integral_lebesgue_integral_lebesgue
   881   by (auto simp: subset_eq)
   910             integrable_has_integral_lebesgue_nonneg)
   882 
   911 
   883 lemma has_integral_iff_positive_integral_lborel:
   912 lemma
   884   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
   913   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
   885   assumes f: "f \<in> borel_measurable borel" "\<And>x. 0 \<le> f x"
   914   assumes "f \<in> borel_measurable borel" "\<And>x. 0 \<le> f x" "(f has_integral I) UNIV"
   886   shows "(f has_integral I) UNIV \<longleftrightarrow> integral\<^sup>P lborel f = I"
   915   shows integrable_has_integral_nonneg: "integrable lborel f"
   887   using assms
   916     and integral_has_integral_nonneg: "integral\<^sup>L lborel f = I"
   888   by (subst has_integral_iff_positive_integral_lebesgue)
   917   by (metis assms borel_measurable_lebesgueI integrable_has_integral_lebesgue_nonneg lebesgue_integral_eq_borel(1))
   889      (auto simp: borel_measurable_lebesgueI lebesgue_positive_integral_eq_borel)
   918      (metis assms borel_measurable_lebesgueI has_integral_lebesgue_integral has_integral_unique integrable_has_integral_lebesgue_nonneg lebesgue_integral_eq_borel(1))
   890 
   919 
   891 subsection {* Equivalence between product spaces and euclidean spaces *}
   920 subsection {* Equivalence between product spaces and euclidean spaces *}
   892 
   921 
   893 definition e2p :: "'a::ordered_euclidean_space \<Rightarrow> ('a \<Rightarrow> real)" where
   922 definition e2p :: "'a::ordered_euclidean_space \<Rightarrow> ('a \<Rightarrow> real)" where
   894   "e2p x = (\<lambda>i\<in>Basis. x \<bullet> i)"
   923   "e2p x = (\<lambda>i\<in>Basis. x \<bullet> i)"
   976   assumes f: "f \<in> borel_measurable borel"
  1005   assumes f: "f \<in> borel_measurable borel"
   977   shows "integral\<^sup>P lborel f = \<integral>\<^sup>+x. f (p2e x) \<partial>(\<Pi>\<^sub>M (i::'a)\<in>Basis. lborel)"
  1006   shows "integral\<^sup>P lborel f = \<integral>\<^sup>+x. f (p2e x) \<partial>(\<Pi>\<^sub>M (i::'a)\<in>Basis. lborel)"
   978   by (subst lborel_eq_lborel_space) (simp add: positive_integral_distr measurable_p2e f)
  1007   by (subst lborel_eq_lborel_space) (simp add: positive_integral_distr measurable_p2e f)
   979 
  1008 
   980 lemma borel_fubini_integrable:
  1009 lemma borel_fubini_integrable:
   981   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
  1010   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> _::{banach, second_countable_topology}"
   982   shows "integrable lborel f \<longleftrightarrow> integrable (\<Pi>\<^sub>M (i::'a)\<in>Basis. lborel) (\<lambda>x. f (p2e x))"
  1011   shows "integrable lborel f \<longleftrightarrow> integrable (\<Pi>\<^sub>M (i::'a)\<in>Basis. lborel) (\<lambda>x. f (p2e x))"
   983     (is "_ \<longleftrightarrow> integrable ?B ?f")
  1012   unfolding integrable_iff_bounded
   984 proof
  1013 proof (intro conj_cong[symmetric])
   985   assume *: "integrable lborel f"
  1014   show "((\<lambda>x. f (p2e x)) \<in> borel_measurable (Pi\<^sub>M Basis (\<lambda>i. lborel))) = (f \<in> borel_measurable lborel)"
   986   then have f: "f \<in> borel_measurable borel"
  1015   proof
   987     by auto
  1016     assume "((\<lambda>x. f (p2e x)) \<in> borel_measurable (Pi\<^sub>M Basis (\<lambda>i. lborel)))"
   988   with measurable_p2e have "f \<circ> p2e \<in> borel_measurable ?B"
  1017     then have "(\<lambda>x. f (p2e (e2p x))) \<in> borel_measurable borel"
   989     by (rule measurable_comp)
  1018       by measurable
   990   with * f show "integrable ?B ?f"
  1019     then show "f \<in> borel_measurable lborel"
   991     by (simp add: comp_def borel_fubini_positiv_integral integrable_def)
  1020       by simp
   992 next
  1021   qed simp
   993   assume *: "integrable ?B ?f"
  1022 qed (simp add: borel_fubini_positiv_integral)
   994   then have "?f \<circ> e2p \<in> borel_measurable (borel::'a measure)"
       
   995     by (auto intro!: measurable_e2p)
       
   996   then have "f \<in> borel_measurable borel"
       
   997     by (simp cong: measurable_cong)
       
   998   with * show "integrable lborel f"
       
   999     by (simp add: borel_fubini_positiv_integral integrable_def)
       
  1000 qed
       
  1001 
  1023 
  1002 lemma borel_fubini:
  1024 lemma borel_fubini:
  1003   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
  1025   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> _::{banach, second_countable_topology}"
  1004   assumes f: "f \<in> borel_measurable borel"
  1026   shows "f \<in> borel_measurable borel \<Longrightarrow>
  1005   shows "integral\<^sup>L lborel f = \<integral>x. f (p2e x) \<partial>((\<Pi>\<^sub>M (i::'a)\<in>Basis. lborel))"
  1027     integral\<^sup>L lborel f = \<integral>x. f (p2e x) \<partial>((\<Pi>\<^sub>M (i::'a)\<in>Basis. lborel))"
  1006   using f by (simp add: borel_fubini_positiv_integral lebesgue_integral_def)
  1028   by (subst lborel_eq_lborel_space) (simp add: integral_distr)
  1007 
  1029 
  1008 lemma integrable_on_borel_integrable:
  1030 lemma integrable_on_borel_integrable:
  1009   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
  1031   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
  1010   assumes f_borel: "f \<in> borel_measurable borel" and nonneg: "\<And>x. 0 \<le> f x"
  1032   shows "f \<in> borel_measurable borel \<Longrightarrow> (\<And>x. 0 \<le> f x) \<Longrightarrow> f integrable_on UNIV \<Longrightarrow> integrable lborel f"
  1011   assumes f: "f integrable_on UNIV" 
  1033   by (metis borel_measurable_lebesgueI integrable_has_integral_nonneg integrable_on_def
  1012   shows "integrable lborel f"
  1034             lebesgue_integral_eq_borel(1))
  1013 proof -
       
  1014   have "(\<integral>\<^sup>+ x. ereal (f x) \<partial>lborel) \<noteq> \<infinity>" 
       
  1015     using has_integral_iff_positive_integral_lborel[OF f_borel nonneg] f
       
  1016     by (auto simp: integrable_on_def)
       
  1017   moreover have "(\<integral>\<^sup>+ x. ereal (- f x) \<partial>lborel) = 0"
       
  1018     using f_borel nonneg by (subst positive_integral_0_iff_AE) auto
       
  1019   ultimately show ?thesis
       
  1020     using f_borel by (auto simp: integrable_def)
       
  1021 qed
       
  1022 
  1035 
  1023 subsection {* Fundamental Theorem of Calculus for the Lebesgue integral *}
  1036 subsection {* Fundamental Theorem of Calculus for the Lebesgue integral *}
  1024 
  1037 
  1025 lemma borel_integrable_atLeastAtMost:
  1038 lemma borel_integrable_atLeastAtMost:
  1026   fixes a b :: real
  1039   fixes f :: "real \<Rightarrow> real"
  1027   assumes f: "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> isCont f x"
  1040   assumes f: "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> isCont f x"
  1028   shows "integrable lborel (\<lambda>x. f x * indicator {a .. b} x)" (is "integrable _ ?f")
  1041   shows "integrable lborel (\<lambda>x. f x * indicator {a .. b} x)" (is "integrable _ ?f")
  1029 proof cases
  1042 proof cases
  1030   assume "a \<le> b"
  1043   assume "a \<le> b"
  1031 
  1044 
  1035     by metis
  1048     by metis
  1036 
  1049 
  1037   show ?thesis
  1050   show ?thesis
  1038   proof (rule integrable_bound)
  1051   proof (rule integrable_bound)
  1039     show "integrable lborel (\<lambda>x. max \<bar>M\<bar> \<bar>L\<bar> * indicator {a..b} x)"
  1052     show "integrable lborel (\<lambda>x. max \<bar>M\<bar> \<bar>L\<bar> * indicator {a..b} x)"
  1040       by (rule integral_cmul_indicator) simp_all
  1053       by (intro integrable_mult_right integrable_real_indicator) simp_all
  1041     show "AE x in lborel. \<bar>?f x\<bar> \<le> max \<bar>M\<bar> \<bar>L\<bar> * indicator {a..b} x"
  1054     show "AE x in lborel. norm (?f x) \<le> norm (max \<bar>M\<bar> \<bar>L\<bar> * indicator {a..b} x)"
  1042     proof (rule AE_I2)
  1055     proof (rule AE_I2)
  1043       fix x show "\<bar>?f x\<bar> \<le> max \<bar>M\<bar> \<bar>L\<bar> * indicator {a..b} x"
  1056       fix x show "norm (?f x) \<le> norm (max \<bar>M\<bar> \<bar>L\<bar> * indicator {a..b} x)"
  1044         using bounds[of x] by (auto split: split_indicator)
  1057         using bounds[of x] by (auto split: split_indicator)
  1045     qed
  1058     qed
  1046 
  1059 
  1047     let ?g = "\<lambda>x. if x = a then f a else if x = b then f b else if x \<in> {a <..< b} then f x else 0"
  1060     let ?g = "\<lambda>x. if x = a then f a else if x = b then f b else if x \<in> {a <..< b} then f x else 0"
  1048     from f have "continuous_on {a <..< b} f"
  1061     from f have "continuous_on {a <..< b} f"
  1069   shows "integral\<^sup>L lborel (\<lambda>x. f x * indicator {a .. b} x) = F b - F a"
  1082   shows "integral\<^sup>L lborel (\<lambda>x. f x * indicator {a .. b} x) = F b - F a"
  1070 proof -
  1083 proof -
  1071   let ?f = "\<lambda>x. f x * indicator {a .. b} x"
  1084   let ?f = "\<lambda>x. f x * indicator {a .. b} x"
  1072   have "(?f has_integral (\<integral>x. ?f x \<partial>lborel)) UNIV"
  1085   have "(?f has_integral (\<integral>x. ?f x \<partial>lborel)) UNIV"
  1073     using borel_integrable_atLeastAtMost[OF f]
  1086     using borel_integrable_atLeastAtMost[OF f]
  1074     by (rule borel_integral_has_integral)
  1087     by (rule has_integral_lebesgue_integral)
  1075   moreover
  1088   moreover
  1076   have "(f has_integral F b - F a) {a .. b}"
  1089   have "(f has_integral F b - F a) {a .. b}"
  1077     by (intro fundamental_theorem_of_calculus)
  1090     by (intro fundamental_theorem_of_calculus)
  1078        (auto simp: has_field_derivative_iff_has_vector_derivative[symmetric]
  1091        (auto simp: has_field_derivative_iff_has_vector_derivative[symmetric]
  1079              intro: has_field_derivative_subset[OF F] assms(1))
  1092              intro: has_field_derivative_subset[OF F] assms(1))
  1089 
  1102 
  1090 For the positive integral we replace continuity with Borel-measurability. 
  1103 For the positive integral we replace continuity with Borel-measurability. 
  1091 
  1104 
  1092 *}
  1105 *}
  1093 
  1106 
  1094 lemma positive_integral_FTC_atLeastAtMost:
  1107 lemma
       
  1108   fixes f :: "real \<Rightarrow> real"
  1095   assumes f_borel: "f \<in> borel_measurable borel"
  1109   assumes f_borel: "f \<in> borel_measurable borel"
  1096   assumes f: "\<And>x. x \<in> {a..b} \<Longrightarrow> DERIV F x :> f x" "\<And>x. x \<in> {a..b} \<Longrightarrow> 0 \<le> f x" and "a \<le> b"
  1110   assumes f: "\<And>x. x \<in> {a..b} \<Longrightarrow> DERIV F x :> f x" "\<And>x. x \<in> {a..b} \<Longrightarrow> 0 \<le> f x" and "a \<le> b"
  1097   shows "(\<integral>\<^sup>+x. f x * indicator {a .. b} x \<partial>lborel) = F b - F a"
  1111   shows integral_FTC_Icc_nonneg: "(\<integral>x. f x * indicator {a .. b} x \<partial>lborel) = F b - F a" (is ?eq)
       
  1112     and integrable_FTC_Icc_nonneg: "integrable lborel (\<lambda>x. f x * indicator {a .. b} x)" (is ?int)
  1098 proof -
  1113 proof -
  1099   have i: "(f has_integral F b - F a) {a..b}"
  1114   have i: "(f has_integral F b - F a) {a..b}"
  1100     by (intro fundamental_theorem_of_calculus)
  1115     by (intro fundamental_theorem_of_calculus)
  1101        (auto simp: has_field_derivative_iff_has_vector_derivative[symmetric]
  1116        (auto simp: has_field_derivative_iff_has_vector_derivative[symmetric]
  1102              intro: has_field_derivative_subset[OF f(1)] `a \<le> b`)
  1117              intro: has_field_derivative_subset[OF f(1)] `a \<le> b`)
  1103   have i: "((\<lambda>x. f x * indicator {a..b} x) has_integral F b - F a) {a..b}"
  1118   have i: "((\<lambda>x. f x * indicator {a..b} x) has_integral F b - F a) {a..b}"
  1104     by (rule has_integral_eq[OF _ i]) auto
  1119     by (rule has_integral_eq[OF _ i]) auto
  1105   have i: "((\<lambda>x. f x * indicator {a..b} x) has_integral F b - F a) UNIV"
  1120   have i: "((\<lambda>x. f x * indicator {a..b} x) has_integral F b - F a) UNIV"
  1106     by (rule has_integral_on_superset[OF _ _ i]) auto
  1121     by (rule has_integral_on_superset[OF _ _ i]) auto
  1107   then have "(\<integral>\<^sup>+x. ereal (f x * indicator {a .. b} x) \<partial>lborel) = F b - F a"
  1122   from i f f_borel show ?eq
  1108     using f f_borel
  1123     by (intro integral_has_integral_nonneg) (auto split: split_indicator)
  1109     by (subst has_integral_iff_positive_integral_lborel[symmetric]) (auto split: split_indicator)
  1124   from i f f_borel show ?int
  1110   also have "(\<integral>\<^sup>+x. ereal (f x * indicator {a .. b} x) \<partial>lborel) = (\<integral>\<^sup>+x. ereal (f x) * indicator {a .. b} x \<partial>lborel)"
  1125     by (intro integrable_has_integral_nonneg) (auto split: split_indicator)
  1111     by (auto intro!: positive_integral_cong simp: indicator_def)
  1126 qed
  1112   finally show ?thesis by simp
  1127 
       
  1128 lemma positive_integral_FTC_atLeastAtMost:
       
  1129   assumes "f \<in> borel_measurable borel" "\<And>x. x \<in> {a..b} \<Longrightarrow> DERIV F x :> f x" "\<And>x. x \<in> {a..b} \<Longrightarrow> 0 \<le> f x" "a \<le> b"
       
  1130   shows "(\<integral>\<^sup>+x. f x * indicator {a .. b} x \<partial>lborel) = F b - F a"
       
  1131 proof -
       
  1132   have "integrable lborel (\<lambda>x. f x * indicator {a .. b} x)"
       
  1133     by (rule integrable_FTC_Icc_nonneg) fact+
       
  1134   then have "(\<integral>\<^sup>+x. f x * indicator {a .. b} x \<partial>lborel) = (\<integral>x. f x * indicator {a .. b} x \<partial>lborel)"
       
  1135     using assms by (intro positive_integral_eq_integral) (auto simp: indicator_def)
       
  1136   also have "(\<integral>x. f x * indicator {a .. b} x \<partial>lborel) = F b - F a"
       
  1137     by (rule integral_FTC_Icc_nonneg) fact+
       
  1138   finally show ?thesis
       
  1139     unfolding ereal_indicator[symmetric] by simp
  1113 qed
  1140 qed
  1114 
  1141 
  1115 lemma positive_integral_FTC_atLeast:
  1142 lemma positive_integral_FTC_atLeast:
  1116   fixes f :: "real \<Rightarrow> real"
  1143   fixes f :: "real \<Rightarrow> real"
  1117   assumes f_borel: "f \<in> borel_measurable borel"
  1144   assumes f_borel: "f \<in> borel_measurable borel"