src/HOL/Probability/Lebesgue_Measure.thy
changeset 53015 a1119cf551e8
parent 51478 270b21f3ae0a
child 53374 a14d2a854c02
equal deleted inserted replaced
53009:bb18eed53ed6 53015:a1119cf551e8
   511   fixes M :: "'a::ordered_euclidean_space measure"
   511   fixes M :: "'a::ordered_euclidean_space measure"
   512   assumes emeasure_eq: "\<And>a b. emeasure M {a .. b} = content {a .. b}"
   512   assumes emeasure_eq: "\<And>a b. emeasure M {a .. b} = content {a .. b}"
   513   assumes sets_eq: "sets M = sets borel"
   513   assumes sets_eq: "sets M = sets borel"
   514   shows "lborel = M"
   514   shows "lborel = M"
   515 proof (rule measure_eqI_generator_eq[OF Int_stable_atLeastAtMost])
   515 proof (rule measure_eqI_generator_eq[OF Int_stable_atLeastAtMost])
   516   let ?P = "\<Pi>\<^isub>M i\<in>{..<DIM('a::ordered_euclidean_space)}. lborel"
   516   let ?P = "\<Pi>\<^sub>M i\<in>{..<DIM('a::ordered_euclidean_space)}. lborel"
   517   let ?E = "range (\<lambda>(a, b). {a..b} :: 'a set)"
   517   let ?E = "range (\<lambda>(a, b). {a..b} :: 'a set)"
   518   show "?E \<subseteq> Pow UNIV" "sets lborel = sigma_sets UNIV ?E" "sets M = sigma_sets UNIV ?E"
   518   show "?E \<subseteq> Pow UNIV" "sets lborel = sigma_sets UNIV ?E" "sets M = sigma_sets UNIV ?E"
   519     by (simp_all add: borel_eq_atLeastAtMost sets_eq)
   519     by (simp_all add: borel_eq_atLeastAtMost sets_eq)
   520 
   520 
   521   show "range cube \<subseteq> ?E" unfolding cube_def [abs_def] by auto
   521   show "range cube \<subseteq> ?E" unfolding cube_def [abs_def] by auto
   562 lemma simple_function_has_integral:
   562 lemma simple_function_has_integral:
   563   fixes f::"'a::ordered_euclidean_space \<Rightarrow> ereal"
   563   fixes f::"'a::ordered_euclidean_space \<Rightarrow> ereal"
   564   assumes f:"simple_function lebesgue f"
   564   assumes f:"simple_function lebesgue f"
   565   and f':"range f \<subseteq> {0..<\<infinity>}"
   565   and f':"range f \<subseteq> {0..<\<infinity>}"
   566   and om:"\<And>x. x \<in> range f \<Longrightarrow> emeasure lebesgue (f -` {x} \<inter> UNIV) = \<infinity> \<Longrightarrow> x = 0"
   566   and om:"\<And>x. x \<in> range f \<Longrightarrow> emeasure lebesgue (f -` {x} \<inter> UNIV) = \<infinity> \<Longrightarrow> x = 0"
   567   shows "((\<lambda>x. real (f x)) has_integral (real (integral\<^isup>S lebesgue f))) UNIV"
   567   shows "((\<lambda>x. real (f x)) has_integral (real (integral\<^sup>S lebesgue f))) UNIV"
   568   unfolding simple_integral_def space_lebesgue
   568   unfolding simple_integral_def space_lebesgue
   569 proof (subst lebesgue_simple_function_indicator)
   569 proof (subst lebesgue_simple_function_indicator)
   570   let ?M = "\<lambda>x. emeasure lebesgue (f -` {x} \<inter> UNIV)"
   570   let ?M = "\<lambda>x. emeasure lebesgue (f -` {x} \<inter> UNIV)"
   571   let ?F = "\<lambda>x. indicator (f -` {x})"
   571   let ?F = "\<lambda>x. indicator (f -` {x})"
   572   { fix x y assume "y \<in> range f"
   572   { fix x y assume "y \<in> range f"
   598 qed fact
   598 qed fact
   599 
   599 
   600 lemma simple_function_has_integral':
   600 lemma simple_function_has_integral':
   601   fixes f::"'a::ordered_euclidean_space \<Rightarrow> ereal"
   601   fixes f::"'a::ordered_euclidean_space \<Rightarrow> ereal"
   602   assumes f: "simple_function lebesgue f" "\<And>x. 0 \<le> f x"
   602   assumes f: "simple_function lebesgue f" "\<And>x. 0 \<le> f x"
   603   and i: "integral\<^isup>S lebesgue f \<noteq> \<infinity>"
   603   and i: "integral\<^sup>S lebesgue f \<noteq> \<infinity>"
   604   shows "((\<lambda>x. real (f x)) has_integral (real (integral\<^isup>S lebesgue f))) UNIV"
   604   shows "((\<lambda>x. real (f x)) has_integral (real (integral\<^sup>S lebesgue f))) UNIV"
   605 proof -
   605 proof -
   606   let ?f = "\<lambda>x. if x \<in> f -` {\<infinity>} then 0 else f x"
   606   let ?f = "\<lambda>x. if x \<in> f -` {\<infinity>} then 0 else f x"
   607   note f(1)[THEN simple_functionD(2)]
   607   note f(1)[THEN simple_functionD(2)]
   608   then have [simp, intro]: "\<And>X. f -` X \<in> sets lebesgue" by auto
   608   then have [simp, intro]: "\<And>X. f -` X \<in> sets lebesgue" by auto
   609   have f': "simple_function lebesgue ?f"
   609   have f': "simple_function lebesgue ?f"
   610     using f by (intro simple_function_If_set) auto
   610     using f by (intro simple_function_If_set) auto
   611   have rng: "range ?f \<subseteq> {0..<\<infinity>}" using f by auto
   611   have rng: "range ?f \<subseteq> {0..<\<infinity>}" using f by auto
   612   have "AE x in lebesgue. f x = ?f x"
   612   have "AE x in lebesgue. f x = ?f x"
   613     using simple_integral_PInf[OF f i]
   613     using simple_integral_PInf[OF f i]
   614     by (intro AE_I[where N="f -` {\<infinity>} \<inter> space lebesgue"]) auto
   614     by (intro AE_I[where N="f -` {\<infinity>} \<inter> space lebesgue"]) auto
   615   from f(1) f' this have eq: "integral\<^isup>S lebesgue f = integral\<^isup>S lebesgue ?f"
   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)
   616     by (rule simple_integral_cong_AE)
   617   have real_eq: "\<And>x. real (f x) = real (?f x)" by auto
   617   have real_eq: "\<And>x. real (f x) = real (?f x)" by auto
   618 
   618 
   619   show ?thesis
   619   show ?thesis
   620     unfolding eq real_eq
   620     unfolding eq real_eq
   621   proof (rule simple_function_has_integral[OF f' rng])
   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>"
   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>\<^isup>S y. x * indicator (?f -` {x}) y \<partial>lebesgue)"
   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)]
   624       using f'[THEN simple_functionD(2)]
   625       by (simp add: simple_integral_cmult_indicator)
   625       by (simp add: simple_integral_cmult_indicator)
   626     also have "\<dots> \<le> integral\<^isup>S lebesgue f"
   626     also have "\<dots> \<le> integral\<^sup>S lebesgue f"
   627       using f'[THEN simple_functionD(2)] f
   627       using f'[THEN simple_functionD(2)] f
   628       by (intro simple_integral_mono simple_function_mult simple_function_indicator)
   628       by (intro simple_integral_mono simple_function_mult simple_function_indicator)
   629          (auto split: split_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)
   630     finally show "x = 0" unfolding inf using i subsetD[OF rng x] by (auto split: split_if_asm)
   631   qed
   631   qed
   632 qed
   632 qed
   633 
   633 
   634 lemma positive_integral_has_integral:
   634 lemma positive_integral_has_integral:
   635   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> ereal"
   635   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> ereal"
   636   assumes f: "f \<in> borel_measurable lebesgue" "range f \<subseteq> {0..<\<infinity>}" "integral\<^isup>P lebesgue f \<noteq> \<infinity>"
   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\<^isup>P lebesgue f))) UNIV"
   637   shows "((\<lambda>x. real (f x)) has_integral (real (integral\<^sup>P lebesgue f))) UNIV"
   638 proof -
   638 proof -
   639   from borel_measurable_implies_simple_function_sequence'[OF f(1)]
   639   from borel_measurable_implies_simple_function_sequence'[OF f(1)]
   640   guess u . note u = this
   640   guess u . note u = this
   641   have SUP_eq: "\<And>x. (SUP i. u i x) = f x"
   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)
   642     using u(4) f(2)[THEN subsetD] by (auto split: split_max)
   643   let ?u = "\<lambda>i x. real (u i x)"
   643   let ?u = "\<lambda>i x. real (u i x)"
   644   note u_eq = positive_integral_eq_simple_integral[OF u(1,5), symmetric]
   644   note u_eq = positive_integral_eq_simple_integral[OF u(1,5), symmetric]
   645   { fix i
   645   { fix i
   646     note u_eq
   646     note u_eq
   647     also have "integral\<^isup>P lebesgue (u i) \<le> (\<integral>\<^isup>+x. max 0 (f x) \<partial>lebesgue)"
   647     also have "integral\<^sup>P lebesgue (u i) \<le> (\<integral>\<^sup>+x. max 0 (f x) \<partial>lebesgue)"
   648       by (intro positive_integral_mono) (auto intro: SUP_upper simp: u(4)[symmetric])
   648       by (intro positive_integral_mono) (auto intro: SUP_upper simp: u(4)[symmetric])
   649     finally have "integral\<^isup>S lebesgue (u i) \<noteq> \<infinity>"
   649     finally have "integral\<^sup>S lebesgue (u i) \<noteq> \<infinity>"
   650       unfolding positive_integral_max_0 using f by auto }
   650       unfolding positive_integral_max_0 using f by auto }
   651   note u_fin = this
   651   note u_fin = this
   652   then have u_int: "\<And>i. (?u i has_integral real (integral\<^isup>S lebesgue (u i))) UNIV"
   652   then have u_int: "\<And>i. (?u i has_integral real (integral\<^sup>S lebesgue (u i))) UNIV"
   653     by (rule simple_function_has_integral'[OF u(1,5)])
   653     by (rule simple_function_has_integral'[OF u(1,5)])
   654   have "\<forall>x. \<exists>r\<ge>0. f x = ereal r"
   654   have "\<forall>x. \<exists>r\<ge>0. f x = ereal r"
   655   proof
   655   proof
   656     fix x from f(2) have "0 \<le> f x" "f x \<noteq> \<infinity>" by (auto simp: subset_eq)
   656     fix x from f(2) have "0 \<le> f x" "f x \<noteq> \<infinity>" by (auto simp: subset_eq)
   657     then show "\<exists>r\<ge>0. f x = ereal r" by (cases "f x") auto
   657     then show "\<exists>r\<ge>0. f x = ereal r" by (cases "f x") auto
   682     show "bounded {integral UNIV (u' k)|k. True}"
   682     show "bounded {integral UNIV (u' k)|k. True}"
   683     proof (safe intro!: bounded_realI)
   683     proof (safe intro!: bounded_realI)
   684       fix k
   684       fix k
   685       have "\<bar>integral UNIV (u' k)\<bar> = integral UNIV (u' k)"
   685       have "\<bar>integral UNIV (u' k)\<bar> = integral UNIV (u' k)"
   686         by (intro abs_of_nonneg integral_nonneg int ballI u')
   686         by (intro abs_of_nonneg integral_nonneg int ballI u')
   687       also have "\<dots> = real (integral\<^isup>S lebesgue (u k))"
   687       also have "\<dots> = real (integral\<^sup>S lebesgue (u k))"
   688         using u_int[THEN integral_unique] by (simp add: u')
   688         using u_int[THEN integral_unique] by (simp add: u')
   689       also have "\<dots> = real (integral\<^isup>P lebesgue (u k))"
   689       also have "\<dots> = real (integral\<^sup>P lebesgue (u k))"
   690         using positive_integral_eq_simple_integral[OF u(1,5)] by simp
   690         using positive_integral_eq_simple_integral[OF u(1,5)] by simp
   691       also have "\<dots> \<le> real (integral\<^isup>P lebesgue f)" using f
   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
   692         by (auto intro!: real_of_ereal_positive_mono positive_integral_positive
   693              positive_integral_mono SUP_upper simp: SUP_eq[symmetric])
   693              positive_integral_mono SUP_upper simp: SUP_eq[symmetric])
   694       finally show "\<bar>integral UNIV (u' k)\<bar> \<le> real (integral\<^isup>P lebesgue f)" .
   694       finally show "\<bar>integral UNIV (u' k)\<bar> \<le> real (integral\<^sup>P lebesgue f)" .
   695     qed
   695     qed
   696   qed
   696   qed
   697 
   697 
   698   have "integral\<^isup>P lebesgue f = ereal (integral UNIV f')"
   698   have "integral\<^sup>P lebesgue f = ereal (integral UNIV f')"
   699   proof (rule tendsto_unique[OF trivial_limit_sequentially])
   699   proof (rule tendsto_unique[OF trivial_limit_sequentially])
   700     have "(\<lambda>i. integral\<^isup>S lebesgue (u i)) ----> (SUP i. integral\<^isup>P lebesgue (u i))"
   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)
   701       unfolding u_eq by (intro LIMSEQ_SUP incseq_positive_integral u)
   702     also note positive_integral_monotone_convergence_SUP
   702     also note positive_integral_monotone_convergence_SUP
   703       [OF u(2)  borel_measurable_simple_function[OF u(1)] u(5), symmetric]
   703       [OF u(2)  borel_measurable_simple_function[OF u(1)] u(5), symmetric]
   704     finally show "(\<lambda>k. integral\<^isup>S lebesgue (u k)) ----> integral\<^isup>P lebesgue f"
   704     finally show "(\<lambda>k. integral\<^sup>S lebesgue (u k)) ----> integral\<^sup>P lebesgue f"
   705       unfolding SUP_eq .
   705       unfolding SUP_eq .
   706 
   706 
   707     { fix k
   707     { fix k
   708       have "0 \<le> integral\<^isup>S lebesgue (u k)"
   708       have "0 \<le> integral\<^sup>S lebesgue (u k)"
   709         using u by (auto intro!: simple_integral_positive)
   709         using u by (auto intro!: simple_integral_positive)
   710       then have "integral\<^isup>S lebesgue (u k) = ereal (real (integral\<^isup>S lebesgue (u k)))"
   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) }
   711         using u_fin by (auto simp: ereal_real) }
   712     note * = this
   712     note * = this
   713     show "(\<lambda>k. integral\<^isup>S lebesgue (u k)) ----> ereal (integral UNIV f')"
   713     show "(\<lambda>k. integral\<^sup>S lebesgue (u k)) ----> ereal (integral UNIV f')"
   714       using convergent using u_int[THEN integral_unique, symmetric]
   714       using convergent using u_int[THEN integral_unique, symmetric]
   715       by (subst *) (simp add: u')
   715       by (subst *) (simp add: u')
   716   qed
   716   qed
   717   then show ?thesis using convergent by (simp add: f' integrable_integral)
   717   then show ?thesis using convergent by (simp add: f' integrable_integral)
   718 qed
   718 qed
   719 
   719 
   720 lemma lebesgue_integral_has_integral:
   720 lemma lebesgue_integral_has_integral:
   721   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
   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\<^isup>L lebesgue f)) UNIV"
   723   shows "(f has_integral (integral\<^sup>L lebesgue f)) UNIV"
   724 proof -
   724 proof -
   725   let ?n = "\<lambda>x. real (ereal (max 0 (- f x)))" and ?p = "\<lambda>x. real (ereal (max 0 (f x)))"
   725   let ?n = "\<lambda>x. real (ereal (max 0 (- f x)))" and ?p = "\<lambda>x. real (ereal (max 0 (f x)))"
   726   have *: "f = (\<lambda>x. ?p x - ?n x)" by (auto simp del: ereal_max)
   726   have *: "f = (\<lambda>x. ?p x - ?n x)" by (auto simp del: ereal_max)
   727   { fix f :: "'a \<Rightarrow> real" have "(\<integral>\<^isup>+ x. ereal (f x) \<partial>lebesgue) = (\<integral>\<^isup>+ x. ereal (max 0 (f x)) \<partial>lebesgue)"
   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)"
   728       by (intro positive_integral_cong_pos) (auto split: split_max) }
   728       by (intro positive_integral_cong_pos) (auto split: split_max) }
   729   note eq = this
   729   note eq = this
   730   show ?thesis
   730   show ?thesis
   731     unfolding lebesgue_integral_def
   731     unfolding lebesgue_integral_def
   732     apply (subst *)
   732     apply (subst *)
   738              intro!: measurable_If)
   738              intro!: measurable_If)
   739 qed
   739 qed
   740 
   740 
   741 lemma lebesgue_simple_integral_eq_borel:
   741 lemma lebesgue_simple_integral_eq_borel:
   742   assumes f: "f \<in> borel_measurable borel"
   742   assumes f: "f \<in> borel_measurable borel"
   743   shows "integral\<^isup>S lebesgue f = integral\<^isup>S lborel f"
   743   shows "integral\<^sup>S lebesgue f = integral\<^sup>S lborel f"
   744   using f[THEN measurable_sets]
   744   using f[THEN measurable_sets]
   745   by (auto intro!: setsum_cong arg_cong2[where f="op *"] emeasure_lborel[symmetric]
   745   by (auto intro!: setsum_cong arg_cong2[where f="op *"] emeasure_lborel[symmetric]
   746            simp: simple_integral_def)
   746            simp: simple_integral_def)
   747 
   747 
   748 lemma lebesgue_positive_integral_eq_borel:
   748 lemma lebesgue_positive_integral_eq_borel:
   749   assumes f: "f \<in> borel_measurable borel"
   749   assumes f: "f \<in> borel_measurable borel"
   750   shows "integral\<^isup>P lebesgue f = integral\<^isup>P lborel f"
   750   shows "integral\<^sup>P lebesgue f = integral\<^sup>P lborel f"
   751 proof -
   751 proof -
   752   from f have "integral\<^isup>P lebesgue (\<lambda>x. max 0 (f x)) = integral\<^isup>P lborel (\<lambda>x. max 0 (f x))"
   752   from f have "integral\<^sup>P lebesgue (\<lambda>x. max 0 (f x)) = integral\<^sup>P lborel (\<lambda>x. max 0 (f x))"
   753     by (auto intro!: positive_integral_subalgebra[symmetric])
   753     by (auto intro!: positive_integral_subalgebra[symmetric])
   754   then show ?thesis unfolding positive_integral_max_0 .
   754   then show ?thesis unfolding positive_integral_max_0 .
   755 qed
   755 qed
   756 
   756 
   757 lemma lebesgue_integral_eq_borel:
   757 lemma lebesgue_integral_eq_borel:
   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\<^isup>L lebesgue f = integral\<^isup>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 _ _] assms
   764   show ?P ?I by auto
   764   show ?P ?I by auto
   765 qed
   765 qed
   766 
   766 
   767 lemma borel_integral_has_integral:
   767 lemma borel_integral_has_integral:
   768   fixes f::"'a::ordered_euclidean_space => real"
   768   fixes f::"'a::ordered_euclidean_space => real"
   769   assumes f:"integrable lborel f"
   769   assumes f:"integrable lborel f"
   770   shows "(f has_integral (integral\<^isup>L lborel f)) UNIV"
   770   shows "(f has_integral (integral\<^sup>L lborel f)) UNIV"
   771 proof -
   771 proof -
   772   have borel: "f \<in> borel_measurable borel"
   772   have borel: "f \<in> borel_measurable borel"
   773     using f unfolding integrable_def by auto
   773     using f unfolding integrable_def by auto
   774   from f show ?thesis
   774   from f show ?thesis
   775     using lebesgue_integral_has_integral[of f]
   775     using lebesgue_integral_has_integral[of f]
   778 
   778 
   779 lemma positive_integral_lebesgue_has_integral:
   779 lemma positive_integral_lebesgue_has_integral:
   780   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
   780   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"
   781   assumes f_borel: "f \<in> borel_measurable lebesgue" and nonneg: "\<And>x. 0 \<le> f x"
   782   assumes I: "(f has_integral I) UNIV"
   782   assumes I: "(f has_integral I) UNIV"
   783   shows "(\<integral>\<^isup>+x. f x \<partial>lebesgue) = I"
   783   shows "(\<integral>\<^sup>+x. f x \<partial>lebesgue) = I"
   784 proof -
   784 proof -
   785   from f_borel have "(\<lambda>x. ereal (f x)) \<in> borel_measurable lebesgue" by auto
   785   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
   786   from borel_measurable_implies_simple_function_sequence'[OF this] guess F . note F = this
   787 
   787 
   788   have "(\<integral>\<^isup>+ x. ereal (f x) \<partial>lebesgue) = (SUP i. integral\<^isup>S lebesgue (F i))"
   788   have "(\<integral>\<^sup>+ x. ereal (f x) \<partial>lebesgue) = (SUP i. integral\<^sup>S lebesgue (F i))"
   789     using F
   789     using F
   790     by (subst positive_integral_monotone_convergence_simple)
   790     by (subst positive_integral_monotone_convergence_simple)
   791        (simp_all add: positive_integral_max_0 simple_function_def)
   791        (simp_all add: positive_integral_max_0 simple_function_def)
   792   also have "\<dots> \<le> ereal I"
   792   also have "\<dots> \<le> ereal I"
   793   proof (rule SUP_least)
   793   proof (rule SUP_least)
   833       qed
   833       qed
   834       then have "(indicator (F i -` {x}) :: 'a \<Rightarrow> real) integrable_on UNIV"
   834       then have "(indicator (F i -` {x}) :: 'a \<Rightarrow> real) integrable_on UNIV"
   835         by (simp add: integrable_on_cmult_iff) }
   835         by (simp add: integrable_on_cmult_iff) }
   836     note F_finite = lmeasure_finite[OF this]
   836     note F_finite = lmeasure_finite[OF this]
   837 
   837 
   838     have "((\<lambda>x. real (F i x)) has_integral real (integral\<^isup>S lebesgue (F i))) UNIV"
   838     have "((\<lambda>x. real (F i x)) has_integral real (integral\<^sup>S lebesgue (F i))) UNIV"
   839     proof (rule simple_function_has_integral[of "F i"])
   839     proof (rule simple_function_has_integral[of "F i"])
   840       show "simple_function lebesgue (F i)"
   840       show "simple_function lebesgue (F i)"
   841         using F(1) by (simp add: simple_function_def)
   841         using F(1) by (simp add: simple_function_def)
   842       show "range (F i) \<subseteq> {0..<\<infinity>}"
   842       show "range (F i) \<subseteq> {0..<\<infinity>}"
   843         using F(3,5)[of i] by (auto simp: image_iff) metis
   843         using F(3,5)[of i] by (auto simp: image_iff) metis
   844     next
   844     next
   845       fix x assume "x \<in> range (F i)" "emeasure lebesgue (F i -` {x} \<inter> UNIV) = \<infinity>"
   845       fix x assume "x \<in> range (F i)" "emeasure lebesgue (F i -` {x} \<inter> UNIV) = \<infinity>"
   846       with F_finite[of x] show "x = 0" by auto
   846       with F_finite[of x] show "x = 0" by auto
   847     qed
   847     qed
   848     from this I have "real (integral\<^isup>S lebesgue (F i)) \<le> I"
   848     from this I have "real (integral\<^sup>S lebesgue (F i)) \<le> I"
   849       by (rule has_integral_le) (intro ballI F_bound)
   849       by (rule has_integral_le) (intro ballI F_bound)
   850     moreover
   850     moreover
   851     { fix x assume x: "x \<in> range (F i)"
   851     { fix x assume x: "x \<in> range (F i)"
   852       with F(3,5)[of i] have "x = 0 \<or> (0 < x \<and> x \<noteq> \<infinity>)"
   852       with F(3,5)[of i] have "x = 0 \<or> (0 < x \<and> x \<noteq> \<infinity>)"
   853         by (auto  simp: image_iff le_less) metis
   853         by (auto  simp: image_iff le_less) metis
   854       with F_finite[OF _ x] x have "x * emeasure lebesgue (F i -` {x} \<inter> UNIV) \<noteq> \<infinity>"
   854       with F_finite[OF _ x] x have "x * emeasure lebesgue (F i -` {x} \<inter> UNIV) \<noteq> \<infinity>"
   855         by auto }
   855         by auto }
   856     then have "integral\<^isup>S lebesgue (F i) \<noteq> \<infinity>"
   856     then have "integral\<^sup>S lebesgue (F i) \<noteq> \<infinity>"
   857       unfolding simple_integral_def setsum_Pinfty space_lebesgue by blast
   857       unfolding simple_integral_def setsum_Pinfty space_lebesgue by blast
   858     moreover have "0 \<le> integral\<^isup>S lebesgue (F i)"
   858     moreover have "0 \<le> integral\<^sup>S lebesgue (F i)"
   859       using F(1,5) by (intro simple_integral_positive) (auto simp: simple_function_def)
   859       using F(1,5) by (intro simple_integral_positive) (auto simp: simple_function_def)
   860     ultimately show "integral\<^isup>S lebesgue (F i) \<le> ereal I"
   860     ultimately show "integral\<^sup>S lebesgue (F i) \<le> ereal I"
   861       by (cases "integral\<^isup>S lebesgue (F i)") auto
   861       by (cases "integral\<^sup>S lebesgue (F i)") auto
   862   qed
   862   qed
   863   also have "\<dots> < \<infinity>" by simp
   863   also have "\<dots> < \<infinity>" by simp
   864   finally have finite: "(\<integral>\<^isup>+ x. ereal (f x) \<partial>lebesgue) \<noteq> \<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"
   865   have borel: "(\<lambda>x. ereal (f x)) \<in> borel_measurable lebesgue"
   866     using f_borel by (auto intro: borel_measurable_lebesgueI)
   866     using f_borel by (auto intro: borel_measurable_lebesgueI)
   867   from positive_integral_has_integral[OF borel _ finite]
   867   from positive_integral_has_integral[OF borel _ finite]
   868   have "(f has_integral real (\<integral>\<^isup>+ x. ereal (f x) \<partial>lebesgue)) UNIV"
   868   have "(f has_integral real (\<integral>\<^sup>+ x. ereal (f x) \<partial>lebesgue)) UNIV"
   869     using nonneg by (simp add: subset_eq)
   869     using nonneg by (simp add: subset_eq)
   870   with I have "I = real (\<integral>\<^isup>+ x. ereal (f x) \<partial>lebesgue)"
   870   with I have "I = real (\<integral>\<^sup>+ x. ereal (f x) \<partial>lebesgue)"
   871     by (rule has_integral_unique)
   871     by (rule has_integral_unique)
   872   with finite positive_integral_positive[of _ "\<lambda>x. ereal (f x)"] show ?thesis
   872   with finite positive_integral_positive[of _ "\<lambda>x. ereal (f x)"] show ?thesis
   873     by (cases "\<integral>\<^isup>+ x. ereal (f x) \<partial>lebesgue") auto
   873     by (cases "\<integral>\<^sup>+ x. ereal (f x) \<partial>lebesgue") auto
   874 qed
   874 qed
   875 
   875 
   876 lemma has_integral_iff_positive_integral_lebesgue:
   876 lemma has_integral_iff_positive_integral_lebesgue:
   877   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
   877   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
   878   assumes f: "f \<in> borel_measurable lebesgue" "\<And>x. 0 \<le> f x"
   878   assumes f: "f \<in> borel_measurable lebesgue" "\<And>x. 0 \<le> f x"
   879   shows "(f has_integral I) UNIV \<longleftrightarrow> integral\<^isup>P lebesgue f = I"
   879   shows "(f has_integral I) UNIV \<longleftrightarrow> integral\<^sup>P lebesgue f = I"
   880   using f positive_integral_lebesgue_has_integral[of f I] positive_integral_has_integral[of f]
   880   using f positive_integral_lebesgue_has_integral[of f I] positive_integral_has_integral[of f]
   881   by (auto simp: subset_eq)
   881   by (auto simp: subset_eq)
   882 
   882 
   883 lemma has_integral_iff_positive_integral_lborel:
   883 lemma has_integral_iff_positive_integral_lborel:
   884   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
   884   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
   885   assumes f: "f \<in> borel_measurable borel" "\<And>x. 0 \<le> f x"
   885   assumes f: "f \<in> borel_measurable borel" "\<And>x. 0 \<le> f x"
   886   shows "(f has_integral I) UNIV \<longleftrightarrow> integral\<^isup>P lborel f = I"
   886   shows "(f has_integral I) UNIV \<longleftrightarrow> integral\<^sup>P lborel f = I"
   887   using assms
   887   using assms
   888   by (subst has_integral_iff_positive_integral_lebesgue)
   888   by (subst has_integral_iff_positive_integral_lebesgue)
   889      (auto simp: borel_measurable_lebesgueI lebesgue_positive_integral_eq_borel)
   889      (auto simp: borel_measurable_lebesgueI lebesgue_positive_integral_eq_borel)
   890 
   890 
   891 subsection {* Equivalence between product spaces and euclidean spaces *}
   891 subsection {* Equivalence between product spaces and euclidean spaces *}
   910 interpretation lborel_space: finite_product_sigma_finite "\<lambda>x. lborel::real measure" "Basis"
   910 interpretation lborel_space: finite_product_sigma_finite "\<lambda>x. lborel::real measure" "Basis"
   911   by default auto
   911   by default auto
   912 
   912 
   913 lemma sets_product_borel:
   913 lemma sets_product_borel:
   914   assumes I: "finite I"
   914   assumes I: "finite I"
   915   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")
   915   shows "sets (\<Pi>\<^sub>M i\<in>I. lborel) = sigma_sets (\<Pi>\<^sub>E i\<in>I. UNIV) { \<Pi>\<^sub>E i\<in>I. {..< x i :: real} | x. True}" (is "_ = ?G")
   916 proof (subst sigma_prod_algebra_sigma_eq[where S="\<lambda>_ i::nat. {..<real i}" and E="\<lambda>_. range lessThan", OF I])
   916 proof (subst sigma_prod_algebra_sigma_eq[where S="\<lambda>_ i::nat. {..<real i}" and E="\<lambda>_. range lessThan", OF I])
   917   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"
   917   show "sigma_sets (space (Pi\<^sub>M I (\<lambda>i. lborel))) {Pi\<^sub>E I F |F. \<forall>i\<in>I. F i \<in> range lessThan} = ?G"
   918     by (intro arg_cong2[where f=sigma_sets]) (auto simp: space_PiM image_iff bchoice_iff)
   918     by (intro arg_cong2[where f=sigma_sets]) (auto simp: space_PiM image_iff bchoice_iff)
   919 qed (auto simp: borel_eq_lessThan reals_Archimedean2)
   919 qed (auto simp: borel_eq_lessThan reals_Archimedean2)
   920 
   920 
   921 lemma measurable_e2p[measurable]:
   921 lemma measurable_e2p[measurable]:
   922   "e2p \<in> measurable (borel::'a::ordered_euclidean_space measure) (\<Pi>\<^isub>M (i::'a)\<in>Basis. (lborel :: real measure))"
   922   "e2p \<in> measurable (borel::'a::ordered_euclidean_space measure) (\<Pi>\<^sub>M (i::'a)\<in>Basis. (lborel :: real measure))"
   923 proof (rule measurable_sigma_sets[OF sets_product_borel])
   923 proof (rule measurable_sigma_sets[OF sets_product_borel])
   924   fix A :: "('a \<Rightarrow> real) set" assume "A \<in> {\<Pi>\<^isub>E (i::'a)\<in>Basis. {..<x i} |x. True} "
   924   fix A :: "('a \<Rightarrow> real) set" assume "A \<in> {\<Pi>\<^sub>E (i::'a)\<in>Basis. {..<x i} |x. True} "
   925   then obtain x where  "A = (\<Pi>\<^isub>E (i::'a)\<in>Basis. {..<x i})" by auto
   925   then obtain x where  "A = (\<Pi>\<^sub>E (i::'a)\<in>Basis. {..<x i})" by auto
   926   then have "e2p -` A = {..< (\<Sum>i\<in>Basis. x i *\<^sub>R i) :: 'a}"
   926   then have "e2p -` A = {..< (\<Sum>i\<in>Basis. x i *\<^sub>R i) :: 'a}"
   927     using DIM_positive by (auto simp add: set_eq_iff e2p_def
   927     using DIM_positive by (auto simp add: set_eq_iff e2p_def
   928       euclidean_eq_iff[where 'a='a] eucl_less[where 'a='a])
   928       euclidean_eq_iff[where 'a='a] eucl_less[where 'a='a])
   929   then show "e2p -` A \<inter> space (borel::'a measure) \<in> sets borel" by simp
   929   then show "e2p -` A \<inter> space (borel::'a measure) \<in> sets borel" by simp
   930 qed (auto simp: e2p_def)
   930 qed (auto simp: e2p_def)
   932 (* FIXME: conversion in measurable prover *)
   932 (* FIXME: conversion in measurable prover *)
   933 lemma lborelD_Collect[measurable (raw)]: "{x\<in>space borel. P x} \<in> sets borel \<Longrightarrow> {x\<in>space lborel. P x} \<in> sets lborel" by simp
   933 lemma lborelD_Collect[measurable (raw)]: "{x\<in>space borel. P x} \<in> sets borel \<Longrightarrow> {x\<in>space lborel. P x} \<in> sets lborel" by simp
   934 lemma lborelD[measurable (raw)]: "A \<in> sets borel \<Longrightarrow> A \<in> sets lborel" by simp
   934 lemma lborelD[measurable (raw)]: "A \<in> sets borel \<Longrightarrow> A \<in> sets lborel" by simp
   935 
   935 
   936 lemma measurable_p2e[measurable]:
   936 lemma measurable_p2e[measurable]:
   937   "p2e \<in> measurable (\<Pi>\<^isub>M (i::'a)\<in>Basis. (lborel :: real measure))
   937   "p2e \<in> measurable (\<Pi>\<^sub>M (i::'a)\<in>Basis. (lborel :: real measure))
   938     (borel :: 'a::ordered_euclidean_space measure)"
   938     (borel :: 'a::ordered_euclidean_space measure)"
   939   (is "p2e \<in> measurable ?P _")
   939   (is "p2e \<in> measurable ?P _")
   940 proof (safe intro!: borel_measurable_iff_halfspace_le[THEN iffD2])
   940 proof (safe intro!: borel_measurable_iff_halfspace_le[THEN iffD2])
   941   fix x and i :: 'a
   941   fix x and i :: 'a
   942   let ?A = "{w \<in> space ?P. (p2e w :: 'a) \<bullet> i \<le> x}"
   942   let ?A = "{w \<in> space ?P. (p2e w :: 'a) \<bullet> i \<le> x}"
   943   assume "i \<in> Basis"
   943   assume "i \<in> Basis"
   944   then have "?A = (\<Pi>\<^isub>E j\<in>Basis. if i = j then {.. x} else UNIV)"
   944   then have "?A = (\<Pi>\<^sub>E j\<in>Basis. if i = j then {.. x} else UNIV)"
   945     using DIM_positive by (auto simp: space_PiM p2e_def PiE_def split: split_if_asm)
   945     using DIM_positive by (auto simp: space_PiM p2e_def PiE_def split: split_if_asm)
   946   then show "?A \<in> sets ?P"
   946   then show "?A \<in> sets ?P"
   947     by auto
   947     by auto
   948 qed
   948 qed
   949 
   949 
   950 lemma lborel_eq_lborel_space:
   950 lemma lborel_eq_lborel_space:
   951   "(lborel :: 'a measure) = distr (\<Pi>\<^isub>M (i::'a::ordered_euclidean_space)\<in>Basis. lborel) borel p2e"
   951   "(lborel :: 'a measure) = distr (\<Pi>\<^sub>M (i::'a::ordered_euclidean_space)\<in>Basis. lborel) borel p2e"
   952   (is "?B = ?D")
   952   (is "?B = ?D")
   953 proof (rule lborel_eqI)
   953 proof (rule lborel_eqI)
   954   show "sets ?D = sets borel" by simp
   954   show "sets ?D = sets borel" by simp
   955   let ?P = "(\<Pi>\<^isub>M (i::'a)\<in>Basis. lborel)"
   955   let ?P = "(\<Pi>\<^sub>M (i::'a)\<in>Basis. lborel)"
   956   fix a b :: 'a
   956   fix a b :: 'a
   957   have *: "p2e -` {a .. b} \<inter> space ?P = (\<Pi>\<^isub>E i\<in>Basis. {a \<bullet> i .. b \<bullet> i})"
   957   have *: "p2e -` {a .. b} \<inter> space ?P = (\<Pi>\<^sub>E i\<in>Basis. {a \<bullet> i .. b \<bullet> i})"
   958     by (auto simp: eucl_le[where 'a='a] p2e_def space_PiM PiE_def Pi_iff)
   958     by (auto simp: eucl_le[where 'a='a] p2e_def space_PiM PiE_def Pi_iff)
   959   have "emeasure ?P (p2e -` {a..b} \<inter> space ?P) = content {a..b}"
   959   have "emeasure ?P (p2e -` {a..b} \<inter> space ?P) = content {a..b}"
   960   proof cases
   960   proof cases
   961     assume "{a..b} \<noteq> {}"
   961     assume "{a..b} \<noteq> {}"
   962     then have "a \<le> b"
   962     then have "a \<le> b"
   973 qed
   973 qed
   974 
   974 
   975 lemma borel_fubini_positiv_integral:
   975 lemma borel_fubini_positiv_integral:
   976   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> ereal"
   976   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> ereal"
   977   assumes f: "f \<in> borel_measurable borel"
   977   assumes f: "f \<in> borel_measurable borel"
   978   shows "integral\<^isup>P lborel f = \<integral>\<^isup>+x. f (p2e x) \<partial>(\<Pi>\<^isub>M (i::'a)\<in>Basis. lborel)"
   978   shows "integral\<^sup>P lborel f = \<integral>\<^sup>+x. f (p2e x) \<partial>(\<Pi>\<^sub>M (i::'a)\<in>Basis. lborel)"
   979   by (subst lborel_eq_lborel_space) (simp add: positive_integral_distr measurable_p2e f)
   979   by (subst lborel_eq_lborel_space) (simp add: positive_integral_distr measurable_p2e f)
   980 
   980 
   981 lemma borel_fubini_integrable:
   981 lemma borel_fubini_integrable:
   982   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
   982   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
   983   shows "integrable lborel f \<longleftrightarrow> integrable (\<Pi>\<^isub>M (i::'a)\<in>Basis. lborel) (\<lambda>x. f (p2e x))"
   983   shows "integrable lborel f \<longleftrightarrow> integrable (\<Pi>\<^sub>M (i::'a)\<in>Basis. lborel) (\<lambda>x. f (p2e x))"
   984     (is "_ \<longleftrightarrow> integrable ?B ?f")
   984     (is "_ \<longleftrightarrow> integrable ?B ?f")
   985 proof
   985 proof
   986   assume "integrable lborel f"
   986   assume "integrable lborel f"
   987   moreover then have f: "f \<in> borel_measurable borel"
   987   moreover then have f: "f \<in> borel_measurable borel"
   988     by auto
   988     by auto
  1003 qed
  1003 qed
  1004 
  1004 
  1005 lemma borel_fubini:
  1005 lemma borel_fubini:
  1006   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
  1006   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
  1007   assumes f: "f \<in> borel_measurable borel"
  1007   assumes f: "f \<in> borel_measurable borel"
  1008   shows "integral\<^isup>L lborel f = \<integral>x. f (p2e x) \<partial>((\<Pi>\<^isub>M (i::'a)\<in>Basis. lborel))"
  1008   shows "integral\<^sup>L lborel f = \<integral>x. f (p2e x) \<partial>((\<Pi>\<^sub>M (i::'a)\<in>Basis. lborel))"
  1009   using f by (simp add: borel_fubini_positiv_integral lebesgue_integral_def)
  1009   using f by (simp add: borel_fubini_positiv_integral lebesgue_integral_def)
  1010 
  1010 
  1011 lemma integrable_on_borel_integrable:
  1011 lemma integrable_on_borel_integrable:
  1012   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
  1012   fixes f :: "'a::ordered_euclidean_space \<Rightarrow> real"
  1013   assumes f_borel: "f \<in> borel_measurable borel" and nonneg: "\<And>x. 0 \<le> f x"
  1013   assumes f_borel: "f \<in> borel_measurable borel" and nonneg: "\<And>x. 0 \<le> f x"
  1014   assumes f: "f integrable_on UNIV" 
  1014   assumes f: "f integrable_on UNIV" 
  1015   shows "integrable lborel f"
  1015   shows "integrable lborel f"
  1016 proof -
  1016 proof -
  1017   have "(\<integral>\<^isup>+ x. ereal (f x) \<partial>lborel) \<noteq> \<infinity>" 
  1017   have "(\<integral>\<^sup>+ x. ereal (f x) \<partial>lborel) \<noteq> \<infinity>" 
  1018     using has_integral_iff_positive_integral_lborel[OF f_borel nonneg] f
  1018     using has_integral_iff_positive_integral_lborel[OF f_borel nonneg] f
  1019     by (auto simp: integrable_on_def)
  1019     by (auto simp: integrable_on_def)
  1020   moreover have "(\<integral>\<^isup>+ x. ereal (- f x) \<partial>lborel) = 0"
  1020   moreover have "(\<integral>\<^sup>+ x. ereal (- f x) \<partial>lborel) = 0"
  1021     using f_borel nonneg by (subst positive_integral_0_iff_AE) auto
  1021     using f_borel nonneg by (subst positive_integral_0_iff_AE) auto
  1022   ultimately show ?thesis
  1022   ultimately show ?thesis
  1023     using f_borel by (auto simp: integrable_def)
  1023     using f_borel by (auto simp: integrable_def)
  1024 qed
  1024 qed
  1025 
  1025 
  1063 lemma integral_FTC_atLeastAtMost:
  1063 lemma integral_FTC_atLeastAtMost:
  1064   fixes a b :: real
  1064   fixes a b :: real
  1065   assumes "a \<le> b"
  1065   assumes "a \<le> b"
  1066     and F: "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> DERIV F x :> f x"
  1066     and F: "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> DERIV F x :> f x"
  1067     and f: "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> isCont f x"
  1067     and f: "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> isCont f x"
  1068   shows "integral\<^isup>L lborel (\<lambda>x. f x * indicator {a .. b} x) = F b - F a"
  1068   shows "integral\<^sup>L lborel (\<lambda>x. f x * indicator {a .. b} x) = F b - F a"
  1069 proof -
  1069 proof -
  1070   let ?f = "\<lambda>x. f x * indicator {a .. b} x"
  1070   let ?f = "\<lambda>x. f x * indicator {a .. b} x"
  1071   have "(?f has_integral (\<integral>x. ?f x \<partial>lborel)) UNIV"
  1071   have "(?f has_integral (\<integral>x. ?f x \<partial>lborel)) UNIV"
  1072     using borel_integrable_atLeastAtMost[OF f]
  1072     using borel_integrable_atLeastAtMost[OF f]
  1073     by (rule borel_integral_has_integral)
  1073     by (rule borel_integral_has_integral)
  1076     by (intro fundamental_theorem_of_calculus has_vector_derivative_withinI_DERIV ballI assms) auto
  1076     by (intro fundamental_theorem_of_calculus has_vector_derivative_withinI_DERIV ballI assms) auto
  1077   then have "(?f has_integral F b - F a) {a .. b}"
  1077   then have "(?f has_integral F b - F a) {a .. b}"
  1078     by (subst has_integral_eq_eq[where g=f]) auto
  1078     by (subst has_integral_eq_eq[where g=f]) auto
  1079   then have "(?f has_integral F b - F a) UNIV"
  1079   then have "(?f has_integral F b - F a) UNIV"
  1080     by (intro has_integral_on_superset[where t=UNIV and s="{a..b}"]) auto
  1080     by (intro has_integral_on_superset[where t=UNIV and s="{a..b}"]) auto
  1081   ultimately show "integral\<^isup>L lborel ?f = F b - F a"
  1081   ultimately show "integral\<^sup>L lborel ?f = F b - F a"
  1082     by (rule has_integral_unique)
  1082     by (rule has_integral_unique)
  1083 qed
  1083 qed
  1084 
  1084 
  1085 text {*
  1085 text {*
  1086 
  1086 
  1089 *}
  1089 *}
  1090 
  1090 
  1091 lemma positive_integral_FTC_atLeastAtMost:
  1091 lemma positive_integral_FTC_atLeastAtMost:
  1092   assumes f_borel: "f \<in> borel_measurable borel"
  1092   assumes f_borel: "f \<in> borel_measurable borel"
  1093   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"
  1093   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"
  1094   shows "(\<integral>\<^isup>+x. f x * indicator {a .. b} x \<partial>lborel) = F b - F a"
  1094   shows "(\<integral>\<^sup>+x. f x * indicator {a .. b} x \<partial>lborel) = F b - F a"
  1095 proof -
  1095 proof -
  1096   have i: "(f has_integral F b - F a) {a..b}"
  1096   have i: "(f has_integral F b - F a) {a..b}"
  1097     by (intro fundamental_theorem_of_calculus ballI has_vector_derivative_withinI_DERIV assms)
  1097     by (intro fundamental_theorem_of_calculus ballI has_vector_derivative_withinI_DERIV assms)
  1098   have i: "((\<lambda>x. f x * indicator {a..b} x) has_integral F b - F a) {a..b}"
  1098   have i: "((\<lambda>x. f x * indicator {a..b} x) has_integral F b - F a) {a..b}"
  1099     by (rule has_integral_eq[OF _ i]) auto
  1099     by (rule has_integral_eq[OF _ i]) auto
  1100   have i: "((\<lambda>x. f x * indicator {a..b} x) has_integral F b - F a) UNIV"
  1100   have i: "((\<lambda>x. f x * indicator {a..b} x) has_integral F b - F a) UNIV"
  1101     by (rule has_integral_on_superset[OF _ _ i]) auto
  1101     by (rule has_integral_on_superset[OF _ _ i]) auto
  1102   then have "(\<integral>\<^isup>+x. ereal (f x * indicator {a .. b} x) \<partial>lborel) = F b - F a"
  1102   then have "(\<integral>\<^sup>+x. ereal (f x * indicator {a .. b} x) \<partial>lborel) = F b - F a"
  1103     using f f_borel
  1103     using f f_borel
  1104     by (subst has_integral_iff_positive_integral_lborel[symmetric]) (auto split: split_indicator)
  1104     by (subst has_integral_iff_positive_integral_lborel[symmetric]) (auto split: split_indicator)
  1105   also have "(\<integral>\<^isup>+x. ereal (f x * indicator {a .. b} x) \<partial>lborel) = (\<integral>\<^isup>+x. ereal (f x) * indicator {a .. b} x \<partial>lborel)"
  1105   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)"
  1106     by (auto intro!: positive_integral_cong simp: indicator_def)
  1106     by (auto intro!: positive_integral_cong simp: indicator_def)
  1107   finally show ?thesis by simp
  1107   finally show ?thesis by simp
  1108 qed
  1108 qed
  1109 
  1109 
  1110 lemma positive_integral_FTC_atLeast:
  1110 lemma positive_integral_FTC_atLeast:
  1111   fixes f :: "real \<Rightarrow> real"
  1111   fixes f :: "real \<Rightarrow> real"
  1112   assumes f_borel: "f \<in> borel_measurable borel"
  1112   assumes f_borel: "f \<in> borel_measurable borel"
  1113   assumes f: "\<And>x. a \<le> x \<Longrightarrow> DERIV F x :> f x" 
  1113   assumes f: "\<And>x. a \<le> x \<Longrightarrow> DERIV F x :> f x" 
  1114   assumes nonneg: "\<And>x. a \<le> x \<Longrightarrow> 0 \<le> f x"
  1114   assumes nonneg: "\<And>x. a \<le> x \<Longrightarrow> 0 \<le> f x"
  1115   assumes lim: "(F ---> T) at_top"
  1115   assumes lim: "(F ---> T) at_top"
  1116   shows "(\<integral>\<^isup>+x. ereal (f x) * indicator {a ..} x \<partial>lborel) = T - F a"
  1116   shows "(\<integral>\<^sup>+x. ereal (f x) * indicator {a ..} x \<partial>lborel) = T - F a"
  1117 proof -
  1117 proof -
  1118   let ?f = "\<lambda>(i::nat) (x::real). ereal (f x) * indicator {a..a + real i} x"
  1118   let ?f = "\<lambda>(i::nat) (x::real). ereal (f x) * indicator {a..a + real i} x"
  1119   let ?fR = "\<lambda>x. ereal (f x) * indicator {a ..} x"
  1119   let ?fR = "\<lambda>x. ereal (f x) * indicator {a ..} x"
  1120   have "\<And>x. (SUP i::nat. ?f i x) = ?fR x"
  1120   have "\<And>x. (SUP i::nat. ?f i x) = ?fR x"
  1121   proof (rule SUP_Lim_ereal)
  1121   proof (rule SUP_Lim_ereal)
  1127     then have "eventually (\<lambda>n. ?f n x = ?fR x) sequentially"
  1127     then have "eventually (\<lambda>n. ?f n x = ?fR x) sequentially"
  1128       by (auto intro!: eventually_sequentiallyI[where c=n] split: split_indicator)
  1128       by (auto intro!: eventually_sequentiallyI[where c=n] split: split_indicator)
  1129     then show "(\<lambda>n. ?f n x) ----> ?fR x"
  1129     then show "(\<lambda>n. ?f n x) ----> ?fR x"
  1130       by (rule Lim_eventually)
  1130       by (rule Lim_eventually)
  1131   qed
  1131   qed
  1132   then have "integral\<^isup>P lborel ?fR = (\<integral>\<^isup>+ x. (SUP i::nat. ?f i x) \<partial>lborel)"
  1132   then have "integral\<^sup>P lborel ?fR = (\<integral>\<^sup>+ x. (SUP i::nat. ?f i x) \<partial>lborel)"
  1133     by simp
  1133     by simp
  1134   also have "\<dots> = (SUP i::nat. (\<integral>\<^isup>+ x. ?f i x \<partial>lborel))"
  1134   also have "\<dots> = (SUP i::nat. (\<integral>\<^sup>+ x. ?f i x \<partial>lborel))"
  1135   proof (rule positive_integral_monotone_convergence_SUP)
  1135   proof (rule positive_integral_monotone_convergence_SUP)
  1136     show "incseq ?f"
  1136     show "incseq ?f"
  1137       using nonneg by (auto simp: incseq_def le_fun_def split: split_indicator)
  1137       using nonneg by (auto simp: incseq_def le_fun_def split: split_indicator)
  1138     show "\<And>i. (?f i) \<in> borel_measurable lborel"
  1138     show "\<And>i. (?f i) \<in> borel_measurable lborel"
  1139       using f_borel by auto
  1139       using f_borel by auto