src/HOL/Analysis/Equivalence_Lebesgue_Henstock_Integration.thy
author wenzelm
Sun Sep 18 20:33:48 2016 +0200 (2016-09-18)
changeset 63915 bab633745c7f
parent 63886 685fb01256af
child 63940 0d82c4c94014
permissions -rw-r--r--
tuned proofs;
     1 theory Equivalence_Lebesgue_Henstock_Integration
     2   imports Lebesgue_Measure Henstock_Kurzweil_Integration
     3 begin
     4 
     5 subsection \<open>Equivalence Lebesgue integral on @{const lborel} and HK-integral\<close>
     6 
     7 lemma has_integral_measure_lborel:
     8   fixes A :: "'a::euclidean_space set"
     9   assumes A[measurable]: "A \<in> sets borel" and finite: "emeasure lborel A < \<infinity>"
    10   shows "((\<lambda>x. 1) has_integral measure lborel A) A"
    11 proof -
    12   { fix l u :: 'a
    13     have "((\<lambda>x. 1) has_integral measure lborel (box l u)) (box l u)"
    14     proof cases
    15       assume "\<forall>b\<in>Basis. l \<bullet> b \<le> u \<bullet> b"
    16       then show ?thesis
    17         apply simp
    18         apply (subst has_integral_restrict[symmetric, OF box_subset_cbox])
    19         apply (subst has_integral_spike_interior_eq[where g="\<lambda>_. 1"])
    20         using has_integral_const[of "1::real" l u]
    21         apply (simp_all add: inner_diff_left[symmetric] content_cbox_cases)
    22         done
    23     next
    24       assume "\<not> (\<forall>b\<in>Basis. l \<bullet> b \<le> u \<bullet> b)"
    25       then have "box l u = {}"
    26         unfolding box_eq_empty by (auto simp: not_le intro: less_imp_le)
    27       then show ?thesis
    28         by simp
    29     qed }
    30   note has_integral_box = this
    31 
    32   { fix a b :: 'a let ?M = "\<lambda>A. measure lborel (A \<inter> box a b)"
    33     have "Int_stable  (range (\<lambda>(a, b). box a b))"
    34       by (auto simp: Int_stable_def box_Int_box)
    35     moreover have "(range (\<lambda>(a, b). box a b)) \<subseteq> Pow UNIV"
    36       by auto
    37     moreover have "A \<in> sigma_sets UNIV (range (\<lambda>(a, b). box a b))"
    38        using A unfolding borel_eq_box by simp
    39     ultimately have "((\<lambda>x. 1) has_integral ?M A) (A \<inter> box a b)"
    40     proof (induction rule: sigma_sets_induct_disjoint)
    41       case (basic A) then show ?case
    42         by (auto simp: box_Int_box has_integral_box)
    43     next
    44       case empty then show ?case
    45         by simp
    46     next
    47       case (compl A)
    48       then have [measurable]: "A \<in> sets borel"
    49         by (simp add: borel_eq_box)
    50 
    51       have "((\<lambda>x. 1) has_integral ?M (box a b)) (box a b)"
    52         by (simp add: has_integral_box)
    53       moreover have "((\<lambda>x. if x \<in> A \<inter> box a b then 1 else 0) has_integral ?M A) (box a b)"
    54         by (subst has_integral_restrict) (auto intro: compl)
    55       ultimately have "((\<lambda>x. 1 - (if x \<in> A \<inter> box a b then 1 else 0)) has_integral ?M (box a b) - ?M A) (box a b)"
    56         by (rule has_integral_sub)
    57       then have "((\<lambda>x. (if x \<in> (UNIV - A) \<inter> box a b then 1 else 0)) has_integral ?M (box a b) - ?M A) (box a b)"
    58         by (rule has_integral_cong[THEN iffD1, rotated 1]) auto
    59       then have "((\<lambda>x. 1) has_integral ?M (box a b) - ?M A) ((UNIV - A) \<inter> box a b)"
    60         by (subst (asm) has_integral_restrict) auto
    61       also have "?M (box a b) - ?M A = ?M (UNIV - A)"
    62         by (subst measure_Diff[symmetric]) (auto simp: emeasure_lborel_box_eq Diff_Int_distrib2)
    63       finally show ?case .
    64     next
    65       case (union F)
    66       then have [measurable]: "\<And>i. F i \<in> sets borel"
    67         by (simp add: borel_eq_box subset_eq)
    68       have "((\<lambda>x. if x \<in> UNION UNIV F \<inter> box a b then 1 else 0) has_integral ?M (\<Union>i. F i)) (box a b)"
    69       proof (rule has_integral_monotone_convergence_increasing)
    70         let ?f = "\<lambda>k x. \<Sum>i<k. if x \<in> F i \<inter> box a b then 1 else 0 :: real"
    71         show "\<And>k. (?f k has_integral (\<Sum>i<k. ?M (F i))) (box a b)"
    72           using union.IH by (auto intro!: has_integral_setsum simp del: Int_iff)
    73         show "\<And>k x. ?f k x \<le> ?f (Suc k) x"
    74           by (intro setsum_mono2) auto
    75         from union(1) have *: "\<And>x i j. x \<in> F i \<Longrightarrow> x \<in> F j \<longleftrightarrow> j = i"
    76           by (auto simp add: disjoint_family_on_def)
    77         show "\<And>x. (\<lambda>k. ?f k x) \<longlonglongrightarrow> (if x \<in> UNION UNIV F \<inter> box a b then 1 else 0)"
    78           apply (auto simp: * setsum.If_cases Iio_Int_singleton)
    79           apply (rule_tac k="Suc xa" in LIMSEQ_offset)
    80           apply simp
    81           done
    82         have *: "emeasure lborel ((\<Union>x. F x) \<inter> box a b) \<le> emeasure lborel (box a b)"
    83           by (intro emeasure_mono) auto
    84 
    85         with union(1) show "(\<lambda>k. \<Sum>i<k. ?M (F i)) \<longlonglongrightarrow> ?M (\<Union>i. F i)"
    86           unfolding sums_def[symmetric] UN_extend_simps
    87           by (intro measure_UNION) (auto simp: disjoint_family_on_def emeasure_lborel_box_eq top_unique)
    88       qed
    89       then show ?case
    90         by (subst (asm) has_integral_restrict) auto
    91     qed }
    92   note * = this
    93 
    94   show ?thesis
    95   proof (rule has_integral_monotone_convergence_increasing)
    96     let ?B = "\<lambda>n::nat. box (- real n *\<^sub>R One) (real n *\<^sub>R One) :: 'a set"
    97     let ?f = "\<lambda>n::nat. \<lambda>x. if x \<in> A \<inter> ?B n then 1 else 0 :: real"
    98     let ?M = "\<lambda>n. measure lborel (A \<inter> ?B n)"
    99 
   100     show "\<And>n::nat. (?f n has_integral ?M n) A"
   101       using * by (subst has_integral_restrict) simp_all
   102     show "\<And>k x. ?f k x \<le> ?f (Suc k) x"
   103       by (auto simp: box_def)
   104     { fix x assume "x \<in> A"
   105       moreover have "(\<lambda>k. indicator (A \<inter> ?B k) x :: real) \<longlonglongrightarrow> indicator (\<Union>k::nat. A \<inter> ?B k) x"
   106         by (intro LIMSEQ_indicator_incseq) (auto simp: incseq_def box_def)
   107       ultimately show "(\<lambda>k. if x \<in> A \<inter> ?B k then 1 else 0::real) \<longlonglongrightarrow> 1"
   108         by (simp add: indicator_def UN_box_eq_UNIV) }
   109 
   110     have "(\<lambda>n. emeasure lborel (A \<inter> ?B n)) \<longlonglongrightarrow> emeasure lborel (\<Union>n::nat. A \<inter> ?B n)"
   111       by (intro Lim_emeasure_incseq) (auto simp: incseq_def box_def)
   112     also have "(\<lambda>n. emeasure lborel (A \<inter> ?B n)) = (\<lambda>n. measure lborel (A \<inter> ?B n))"
   113     proof (intro ext emeasure_eq_ennreal_measure)
   114       fix n have "emeasure lborel (A \<inter> ?B n) \<le> emeasure lborel (?B n)"
   115         by (intro emeasure_mono) auto
   116       then show "emeasure lborel (A \<inter> ?B n) \<noteq> top"
   117         by (auto simp: top_unique)
   118     qed
   119     finally show "(\<lambda>n. measure lborel (A \<inter> ?B n)) \<longlonglongrightarrow> measure lborel A"
   120       using emeasure_eq_ennreal_measure[of lborel A] finite
   121       by (simp add: UN_box_eq_UNIV less_top)
   122   qed
   123 qed
   124 
   125 lemma nn_integral_has_integral:
   126   fixes f::"'a::euclidean_space \<Rightarrow> real"
   127   assumes f: "f \<in> borel_measurable borel" "\<And>x. 0 \<le> f x" "(\<integral>\<^sup>+x. f x \<partial>lborel) = ennreal r" "0 \<le> r"
   128   shows "(f has_integral r) UNIV"
   129 using f proof (induct f arbitrary: r rule: borel_measurable_induct_real)
   130   case (set A)
   131   then have "((\<lambda>x. 1) has_integral measure lborel A) A"
   132     by (intro has_integral_measure_lborel) (auto simp: ennreal_indicator)
   133   with set show ?case
   134     by (simp add: ennreal_indicator measure_def) (simp add: indicator_def)
   135 next
   136   case (mult g c)
   137   then have "ennreal c * (\<integral>\<^sup>+ x. g x \<partial>lborel) = ennreal r"
   138     by (subst nn_integral_cmult[symmetric]) (auto simp: ennreal_mult)
   139   with \<open>0 \<le> r\<close> \<open>0 \<le> c\<close>
   140   obtain r' where "(c = 0 \<and> r = 0) \<or> (0 \<le> r' \<and> (\<integral>\<^sup>+ x. ennreal (g x) \<partial>lborel) = ennreal r' \<and> r = c * r')"
   141     by (cases "\<integral>\<^sup>+ x. ennreal (g x) \<partial>lborel" rule: ennreal_cases)
   142        (auto split: if_split_asm simp: ennreal_mult_top ennreal_mult[symmetric])
   143   with mult show ?case
   144     by (auto intro!: has_integral_cmult_real)
   145 next
   146   case (add g h)
   147   then have "(\<integral>\<^sup>+ x. h x + g x \<partial>lborel) = (\<integral>\<^sup>+ x. h x \<partial>lborel) + (\<integral>\<^sup>+ x. g x \<partial>lborel)"
   148     by (simp add: nn_integral_add)
   149   with add obtain a b where "0 \<le> a" "0 \<le> b" "(\<integral>\<^sup>+ x. h x \<partial>lborel) = ennreal a" "(\<integral>\<^sup>+ x. g x \<partial>lborel) = ennreal b" "r = a + b"
   150     by (cases "\<integral>\<^sup>+ x. h x \<partial>lborel" "\<integral>\<^sup>+ x. g x \<partial>lborel" rule: ennreal2_cases)
   151        (auto simp: add_top nn_integral_add top_add ennreal_plus[symmetric] simp del: ennreal_plus)
   152   with add show ?case
   153     by (auto intro!: has_integral_add)
   154 next
   155   case (seq U)
   156   note seq(1)[measurable] and f[measurable]
   157 
   158   { fix i x
   159     have "U i x \<le> f x"
   160       using seq(5)
   161       apply (rule LIMSEQ_le_const)
   162       using seq(4)
   163       apply (auto intro!: exI[of _ i] simp: incseq_def le_fun_def)
   164       done }
   165   note U_le_f = this
   166 
   167   { fix i
   168     have "(\<integral>\<^sup>+x. U i x \<partial>lborel) \<le> (\<integral>\<^sup>+x. f x \<partial>lborel)"
   169       using seq(2) f(2) U_le_f by (intro nn_integral_mono) simp
   170     then obtain p where "(\<integral>\<^sup>+x. U i x \<partial>lborel) = ennreal p" "p \<le> r" "0 \<le> p"
   171       using seq(6) \<open>0\<le>r\<close> by (cases "\<integral>\<^sup>+x. U i x \<partial>lborel" rule: ennreal_cases) (auto simp: top_unique)
   172     moreover note seq
   173     ultimately have "\<exists>p. (\<integral>\<^sup>+x. U i x \<partial>lborel) = ennreal p \<and> 0 \<le> p \<and> p \<le> r \<and> (U i has_integral p) UNIV"
   174       by auto }
   175   then obtain p where p: "\<And>i. (\<integral>\<^sup>+x. ennreal (U i x) \<partial>lborel) = ennreal (p i)"
   176     and bnd: "\<And>i. p i \<le> r" "\<And>i. 0 \<le> p i"
   177     and U_int: "\<And>i.(U i has_integral (p i)) UNIV" by metis
   178 
   179   have int_eq: "\<And>i. integral UNIV (U i) = p i" using U_int by (rule integral_unique)
   180 
   181   have *: "f integrable_on UNIV \<and> (\<lambda>k. integral UNIV (U k)) \<longlonglongrightarrow> integral UNIV f"
   182   proof (rule monotone_convergence_increasing)
   183     show "\<forall>k. U k integrable_on UNIV" using U_int by auto
   184     show "\<forall>k. \<forall>x\<in>UNIV. U k x \<le> U (Suc k) x" using \<open>incseq U\<close> by (auto simp: incseq_def le_fun_def)
   185     then show "bounded {integral UNIV (U k) |k. True}"
   186       using bnd int_eq by (auto simp: bounded_real intro!: exI[of _ r])
   187     show "\<forall>x\<in>UNIV. (\<lambda>k. U k x) \<longlonglongrightarrow> f x"
   188       using seq by auto
   189   qed
   190   moreover have "(\<lambda>i. (\<integral>\<^sup>+x. U i x \<partial>lborel)) \<longlonglongrightarrow> (\<integral>\<^sup>+x. f x \<partial>lborel)"
   191     using seq f(2) U_le_f by (intro nn_integral_dominated_convergence[where w=f]) auto
   192   ultimately have "integral UNIV f = r"
   193     by (auto simp add: bnd int_eq p seq intro: LIMSEQ_unique)
   194   with * show ?case
   195     by (simp add: has_integral_integral)
   196 qed
   197 
   198 lemma nn_integral_lborel_eq_integral:
   199   fixes f::"'a::euclidean_space \<Rightarrow> real"
   200   assumes f: "f \<in> borel_measurable borel" "\<And>x. 0 \<le> f x" "(\<integral>\<^sup>+x. f x \<partial>lborel) < \<infinity>"
   201   shows "(\<integral>\<^sup>+x. f x \<partial>lborel) = integral UNIV f"
   202 proof -
   203   from f(3) obtain r where r: "(\<integral>\<^sup>+x. f x \<partial>lborel) = ennreal r" "0 \<le> r"
   204     by (cases "\<integral>\<^sup>+x. f x \<partial>lborel" rule: ennreal_cases) auto
   205   then show ?thesis
   206     using nn_integral_has_integral[OF f(1,2) r] by (simp add: integral_unique)
   207 qed
   208 
   209 lemma nn_integral_integrable_on:
   210   fixes f::"'a::euclidean_space \<Rightarrow> real"
   211   assumes f: "f \<in> borel_measurable borel" "\<And>x. 0 \<le> f x" "(\<integral>\<^sup>+x. f x \<partial>lborel) < \<infinity>"
   212   shows "f integrable_on UNIV"
   213 proof -
   214   from f(3) obtain r where r: "(\<integral>\<^sup>+x. f x \<partial>lborel) = ennreal r" "0 \<le> r"
   215     by (cases "\<integral>\<^sup>+x. f x \<partial>lborel" rule: ennreal_cases) auto
   216   then show ?thesis
   217     by (intro has_integral_integrable[where i=r] nn_integral_has_integral[where r=r] f)
   218 qed
   219 
   220 lemma nn_integral_has_integral_lborel:
   221   fixes f :: "'a::euclidean_space \<Rightarrow> real"
   222   assumes f_borel: "f \<in> borel_measurable borel" and nonneg: "\<And>x. 0 \<le> f x"
   223   assumes I: "(f has_integral I) UNIV"
   224   shows "integral\<^sup>N lborel f = I"
   225 proof -
   226   from f_borel have "(\<lambda>x. ennreal (f x)) \<in> borel_measurable lborel" by auto
   227   from borel_measurable_implies_simple_function_sequence'[OF this] guess F . note F = this
   228   let ?B = "\<lambda>i::nat. box (- (real i *\<^sub>R One)) (real i *\<^sub>R One) :: 'a set"
   229 
   230   note F(1)[THEN borel_measurable_simple_function, measurable]
   231 
   232   have "0 \<le> I"
   233     using I by (rule has_integral_nonneg) (simp add: nonneg)
   234 
   235   have F_le_f: "enn2real (F i x) \<le> f x" for i x
   236     using F(3,4)[where x=x] nonneg SUP_upper[of i UNIV "\<lambda>i. F i x"]
   237     by (cases "F i x" rule: ennreal_cases) auto
   238   let ?F = "\<lambda>i x. F i x * indicator (?B i) x"
   239   have "(\<integral>\<^sup>+ x. ennreal (f x) \<partial>lborel) = (SUP i. integral\<^sup>N lborel (\<lambda>x. ?F i x))"
   240   proof (subst nn_integral_monotone_convergence_SUP[symmetric])
   241     { fix x
   242       obtain j where j: "x \<in> ?B j"
   243         using UN_box_eq_UNIV by auto
   244 
   245       have "ennreal (f x) = (SUP i. F i x)"
   246         using F(4)[of x] nonneg[of x] by (simp add: max_def)
   247       also have "\<dots> = (SUP i. ?F i x)"
   248       proof (rule SUP_eq)
   249         fix i show "\<exists>j\<in>UNIV. F i x \<le> ?F j x"
   250           using j F(2)
   251           by (intro bexI[of _ "max i j"])
   252              (auto split: split_max split_indicator simp: incseq_def le_fun_def box_def)
   253       qed (auto intro!: F split: split_indicator)
   254       finally have "ennreal (f x) =  (SUP i. ?F i x)" . }
   255     then show "(\<integral>\<^sup>+ x. ennreal (f x) \<partial>lborel) = (\<integral>\<^sup>+ x. (SUP i. ?F i x) \<partial>lborel)"
   256       by simp
   257   qed (insert F, auto simp: incseq_def le_fun_def box_def split: split_indicator)
   258   also have "\<dots> \<le> ennreal I"
   259   proof (rule SUP_least)
   260     fix i :: nat
   261     have finite_F: "(\<integral>\<^sup>+ x. ennreal (enn2real (F i x) * indicator (?B i) x) \<partial>lborel) < \<infinity>"
   262     proof (rule nn_integral_bound_simple_function)
   263       have "emeasure lborel {x \<in> space lborel. ennreal (enn2real (F i x) * indicator (?B i) x) \<noteq> 0} \<le>
   264         emeasure lborel (?B i)"
   265         by (intro emeasure_mono)  (auto split: split_indicator)
   266       then show "emeasure lborel {x \<in> space lborel. ennreal (enn2real (F i x) * indicator (?B i) x) \<noteq> 0} < \<infinity>"
   267         by (auto simp: less_top[symmetric] top_unique)
   268     qed (auto split: split_indicator
   269               intro!: F simple_function_compose1[where g="enn2real"] simple_function_ennreal)
   270 
   271     have int_F: "(\<lambda>x. enn2real (F i x) * indicator (?B i) x) integrable_on UNIV"
   272       using F(4) finite_F
   273       by (intro nn_integral_integrable_on) (auto split: split_indicator simp: enn2real_nonneg)
   274 
   275     have "(\<integral>\<^sup>+ x. F i x * indicator (?B i) x \<partial>lborel) =
   276       (\<integral>\<^sup>+ x. ennreal (enn2real (F i x) * indicator (?B i) x) \<partial>lborel)"
   277       using F(3,4)
   278       by (intro nn_integral_cong) (auto simp: image_iff eq_commute split: split_indicator)
   279     also have "\<dots> = ennreal (integral UNIV (\<lambda>x. enn2real (F i x) * indicator (?B i) x))"
   280       using F
   281       by (intro nn_integral_lborel_eq_integral[OF _ _ finite_F])
   282          (auto split: split_indicator intro: enn2real_nonneg)
   283     also have "\<dots> \<le> ennreal I"
   284       by (auto intro!: has_integral_le[OF integrable_integral[OF int_F] I] nonneg F_le_f
   285                simp: \<open>0 \<le> I\<close> split: split_indicator )
   286     finally show "(\<integral>\<^sup>+ x. F i x * indicator (?B i) x \<partial>lborel) \<le> ennreal I" .
   287   qed
   288   finally have "(\<integral>\<^sup>+ x. ennreal (f x) \<partial>lborel) < \<infinity>"
   289     by (auto simp: less_top[symmetric] top_unique)
   290   from nn_integral_lborel_eq_integral[OF assms(1,2) this] I show ?thesis
   291     by (simp add: integral_unique)
   292 qed
   293 
   294 lemma has_integral_iff_emeasure_lborel:
   295   fixes A :: "'a::euclidean_space set"
   296   assumes A[measurable]: "A \<in> sets borel" and [simp]: "0 \<le> r"
   297   shows "((\<lambda>x. 1) has_integral r) A \<longleftrightarrow> emeasure lborel A = ennreal r"
   298 proof (cases "emeasure lborel A = \<infinity>")
   299   case emeasure_A: True
   300   have "\<not> (\<lambda>x. 1::real) integrable_on A"
   301   proof
   302     assume int: "(\<lambda>x. 1::real) integrable_on A"
   303     then have "(indicator A::'a \<Rightarrow> real) integrable_on UNIV"
   304       unfolding indicator_def[abs_def] integrable_restrict_univ .
   305     then obtain r where "((indicator A::'a\<Rightarrow>real) has_integral r) UNIV"
   306       by auto
   307     from nn_integral_has_integral_lborel[OF _ _ this] emeasure_A show False
   308       by (simp add: ennreal_indicator)
   309   qed
   310   with emeasure_A show ?thesis
   311     by auto
   312 next
   313   case False
   314   then have "((\<lambda>x. 1) has_integral measure lborel A) A"
   315     by (simp add: has_integral_measure_lborel less_top)
   316   with False show ?thesis
   317     by (auto simp: emeasure_eq_ennreal_measure has_integral_unique)
   318 qed
   319 
   320 lemma has_integral_integral_real:
   321   fixes f::"'a::euclidean_space \<Rightarrow> real"
   322   assumes f: "integrable lborel f"
   323   shows "(f has_integral (integral\<^sup>L lborel f)) UNIV"
   324 using f proof induct
   325   case (base A c) then show ?case
   326     by (auto intro!: has_integral_mult_left simp: )
   327        (simp add: emeasure_eq_ennreal_measure indicator_def has_integral_measure_lborel)
   328 next
   329   case (add f g) then show ?case
   330     by (auto intro!: has_integral_add)
   331 next
   332   case (lim f s)
   333   show ?case
   334   proof (rule has_integral_dominated_convergence)
   335     show "\<And>i. (s i has_integral integral\<^sup>L lborel (s i)) UNIV" by fact
   336     show "(\<lambda>x. norm (2 * f x)) integrable_on UNIV"
   337       using \<open>integrable lborel f\<close>
   338       by (intro nn_integral_integrable_on)
   339          (auto simp: integrable_iff_bounded abs_mult  nn_integral_cmult ennreal_mult ennreal_mult_less_top)
   340     show "\<And>k. \<forall>x\<in>UNIV. norm (s k x) \<le> norm (2 * f x)"
   341       using lim by (auto simp add: abs_mult)
   342     show "\<forall>x\<in>UNIV. (\<lambda>k. s k x) \<longlonglongrightarrow> f x"
   343       using lim by auto
   344     show "(\<lambda>k. integral\<^sup>L lborel (s k)) \<longlonglongrightarrow> integral\<^sup>L lborel f"
   345       using lim lim(1)[THEN borel_measurable_integrable]
   346       by (intro integral_dominated_convergence[where w="\<lambda>x. 2 * norm (f x)"]) auto
   347   qed
   348 qed
   349 
   350 context
   351   fixes f::"'a::euclidean_space \<Rightarrow> 'b::euclidean_space"
   352 begin
   353 
   354 lemma has_integral_integral_lborel:
   355   assumes f: "integrable lborel f"
   356   shows "(f has_integral (integral\<^sup>L lborel f)) UNIV"
   357 proof -
   358   have "((\<lambda>x. \<Sum>b\<in>Basis. (f x \<bullet> b) *\<^sub>R b) has_integral (\<Sum>b\<in>Basis. integral\<^sup>L lborel (\<lambda>x. f x \<bullet> b) *\<^sub>R b)) UNIV"
   359     using f by (intro has_integral_setsum finite_Basis ballI has_integral_scaleR_left has_integral_integral_real) auto
   360   also have eq_f: "(\<lambda>x. \<Sum>b\<in>Basis. (f x \<bullet> b) *\<^sub>R b) = f"
   361     by (simp add: fun_eq_iff euclidean_representation)
   362   also have "(\<Sum>b\<in>Basis. integral\<^sup>L lborel (\<lambda>x. f x \<bullet> b) *\<^sub>R b) = integral\<^sup>L lborel f"
   363     using f by (subst (2) eq_f[symmetric]) simp
   364   finally show ?thesis .
   365 qed
   366 
   367 lemma integrable_on_lborel: "integrable lborel f \<Longrightarrow> f integrable_on UNIV"
   368   using has_integral_integral_lborel by auto
   369 
   370 lemma integral_lborel: "integrable lborel f \<Longrightarrow> integral UNIV f = (\<integral>x. f x \<partial>lborel)"
   371   using has_integral_integral_lborel by auto
   372 
   373 end
   374 
   375 subsection \<open>Fundamental Theorem of Calculus for the Lebesgue integral\<close>
   376 
   377 text \<open>
   378 
   379 For the positive integral we replace continuity with Borel-measurability.
   380 
   381 \<close>
   382 
   383 lemma
   384   fixes f :: "real \<Rightarrow> real"
   385   assumes [measurable]: "f \<in> borel_measurable borel"
   386   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"
   387   shows nn_integral_FTC_Icc: "(\<integral>\<^sup>+x. ennreal (f x) * indicator {a .. b} x \<partial>lborel) = F b - F a" (is ?nn)
   388     and has_bochner_integral_FTC_Icc_nonneg:
   389       "has_bochner_integral lborel (\<lambda>x. f x * indicator {a .. b} x) (F b - F a)" (is ?has)
   390     and integral_FTC_Icc_nonneg: "(\<integral>x. f x * indicator {a .. b} x \<partial>lborel) = F b - F a" (is ?eq)
   391     and integrable_FTC_Icc_nonneg: "integrable lborel (\<lambda>x. f x * indicator {a .. b} x)" (is ?int)
   392 proof -
   393   have *: "(\<lambda>x. f x * indicator {a..b} x) \<in> borel_measurable borel" "\<And>x. 0 \<le> f x * indicator {a..b} x"
   394     using f(2) by (auto split: split_indicator)
   395 
   396   have F_mono: "a \<le> x \<Longrightarrow> x \<le> y \<Longrightarrow> y \<le> b\<Longrightarrow> F x \<le> F y" for x y
   397     using f by (intro DERIV_nonneg_imp_nondecreasing[of x y F]) (auto intro: order_trans)
   398 
   399   have "(f has_integral F b - F a) {a..b}"
   400     by (intro fundamental_theorem_of_calculus)
   401        (auto simp: has_field_derivative_iff_has_vector_derivative[symmetric]
   402              intro: has_field_derivative_subset[OF f(1)] \<open>a \<le> b\<close>)
   403   then have i: "((\<lambda>x. f x * indicator {a .. b} x) has_integral F b - F a) UNIV"
   404     unfolding indicator_def if_distrib[where f="\<lambda>x. a * x" for a]
   405     by (simp cong del: if_weak_cong del: atLeastAtMost_iff)
   406   then have nn: "(\<integral>\<^sup>+x. f x * indicator {a .. b} x \<partial>lborel) = F b - F a"
   407     by (rule nn_integral_has_integral_lborel[OF *])
   408   then show ?has
   409     by (rule has_bochner_integral_nn_integral[rotated 3]) (simp_all add: * F_mono \<open>a \<le> b\<close>)
   410   then show ?eq ?int
   411     unfolding has_bochner_integral_iff by auto
   412   show ?nn
   413     by (subst nn[symmetric])
   414        (auto intro!: nn_integral_cong simp add: ennreal_mult f split: split_indicator)
   415 qed
   416 
   417 lemma
   418   fixes f :: "real \<Rightarrow> 'a :: euclidean_space"
   419   assumes "a \<le> b"
   420   assumes "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> (F has_vector_derivative f x) (at x within {a .. b})"
   421   assumes cont: "continuous_on {a .. b} f"
   422   shows has_bochner_integral_FTC_Icc:
   423       "has_bochner_integral lborel (\<lambda>x. indicator {a .. b} x *\<^sub>R f x) (F b - F a)" (is ?has)
   424     and integral_FTC_Icc: "(\<integral>x. indicator {a .. b} x *\<^sub>R f x \<partial>lborel) = F b - F a" (is ?eq)
   425 proof -
   426   let ?f = "\<lambda>x. indicator {a .. b} x *\<^sub>R f x"
   427   have int: "integrable lborel ?f"
   428     using borel_integrable_compact[OF _ cont] by auto
   429   have "(f has_integral F b - F a) {a..b}"
   430     using assms(1,2) by (intro fundamental_theorem_of_calculus) auto
   431   moreover
   432   have "(f has_integral integral\<^sup>L lborel ?f) {a..b}"
   433     using has_integral_integral_lborel[OF int]
   434     unfolding indicator_def if_distrib[where f="\<lambda>x. x *\<^sub>R a" for a]
   435     by (simp cong del: if_weak_cong del: atLeastAtMost_iff)
   436   ultimately show ?eq
   437     by (auto dest: has_integral_unique)
   438   then show ?has
   439     using int by (auto simp: has_bochner_integral_iff)
   440 qed
   441 
   442 lemma
   443   fixes f :: "real \<Rightarrow> real"
   444   assumes "a \<le> b"
   445   assumes deriv: "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> DERIV F x :> f x"
   446   assumes cont: "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> isCont f x"
   447   shows has_bochner_integral_FTC_Icc_real:
   448       "has_bochner_integral lborel (\<lambda>x. f x * indicator {a .. b} x) (F b - F a)" (is ?has)
   449     and integral_FTC_Icc_real: "(\<integral>x. f x * indicator {a .. b} x \<partial>lborel) = F b - F a" (is ?eq)
   450 proof -
   451   have 1: "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> (F has_vector_derivative f x) (at x within {a .. b})"
   452     unfolding has_field_derivative_iff_has_vector_derivative[symmetric]
   453     using deriv by (auto intro: DERIV_subset)
   454   have 2: "continuous_on {a .. b} f"
   455     using cont by (intro continuous_at_imp_continuous_on) auto
   456   show ?has ?eq
   457     using has_bochner_integral_FTC_Icc[OF \<open>a \<le> b\<close> 1 2] integral_FTC_Icc[OF \<open>a \<le> b\<close> 1 2]
   458     by (auto simp: mult.commute)
   459 qed
   460 
   461 lemma nn_integral_FTC_atLeast:
   462   fixes f :: "real \<Rightarrow> real"
   463   assumes f_borel: "f \<in> borel_measurable borel"
   464   assumes f: "\<And>x. a \<le> x \<Longrightarrow> DERIV F x :> f x"
   465   assumes nonneg: "\<And>x. a \<le> x \<Longrightarrow> 0 \<le> f x"
   466   assumes lim: "(F \<longlongrightarrow> T) at_top"
   467   shows "(\<integral>\<^sup>+x. ennreal (f x) * indicator {a ..} x \<partial>lborel) = T - F a"
   468 proof -
   469   let ?f = "\<lambda>(i::nat) (x::real). ennreal (f x) * indicator {a..a + real i} x"
   470   let ?fR = "\<lambda>x. ennreal (f x) * indicator {a ..} x"
   471 
   472   have F_mono: "a \<le> x \<Longrightarrow> x \<le> y \<Longrightarrow> F x \<le> F y" for x y
   473     using f nonneg by (intro DERIV_nonneg_imp_nondecreasing[of x y F]) (auto intro: order_trans)
   474   then have F_le_T: "a \<le> x \<Longrightarrow> F x \<le> T" for x
   475     by (intro tendsto_le_const[OF _ lim])
   476        (auto simp: trivial_limit_at_top_linorder eventually_at_top_linorder)
   477 
   478   have "(SUP i::nat. ?f i x) = ?fR x" for x
   479   proof (rule LIMSEQ_unique[OF LIMSEQ_SUP])
   480     from reals_Archimedean2[of "x - a"] guess n ..
   481     then have "eventually (\<lambda>n. ?f n x = ?fR x) sequentially"
   482       by (auto intro!: eventually_sequentiallyI[where c=n] split: split_indicator)
   483     then show "(\<lambda>n. ?f n x) \<longlonglongrightarrow> ?fR x"
   484       by (rule Lim_eventually)
   485   qed (auto simp: nonneg incseq_def le_fun_def split: split_indicator)
   486   then have "integral\<^sup>N lborel ?fR = (\<integral>\<^sup>+ x. (SUP i::nat. ?f i x) \<partial>lborel)"
   487     by simp
   488   also have "\<dots> = (SUP i::nat. (\<integral>\<^sup>+ x. ?f i x \<partial>lborel))"
   489   proof (rule nn_integral_monotone_convergence_SUP)
   490     show "incseq ?f"
   491       using nonneg by (auto simp: incseq_def le_fun_def split: split_indicator)
   492     show "\<And>i. (?f i) \<in> borel_measurable lborel"
   493       using f_borel by auto
   494   qed
   495   also have "\<dots> = (SUP i::nat. ennreal (F (a + real i) - F a))"
   496     by (subst nn_integral_FTC_Icc[OF f_borel f nonneg]) auto
   497   also have "\<dots> = T - F a"
   498   proof (rule LIMSEQ_unique[OF LIMSEQ_SUP])
   499     have "(\<lambda>x. F (a + real x)) \<longlonglongrightarrow> T"
   500       apply (rule filterlim_compose[OF lim filterlim_tendsto_add_at_top])
   501       apply (rule LIMSEQ_const_iff[THEN iffD2, OF refl])
   502       apply (rule filterlim_real_sequentially)
   503       done
   504     then show "(\<lambda>n. ennreal (F (a + real n) - F a)) \<longlonglongrightarrow> ennreal (T - F a)"
   505       by (simp add: F_mono F_le_T tendsto_diff)
   506   qed (auto simp: incseq_def intro!: ennreal_le_iff[THEN iffD2] F_mono)
   507   finally show ?thesis .
   508 qed
   509 
   510 lemma integral_power:
   511   "a \<le> b \<Longrightarrow> (\<integral>x. x^k * indicator {a..b} x \<partial>lborel) = (b^Suc k - a^Suc k) / Suc k"
   512 proof (subst integral_FTC_Icc_real)
   513   fix x show "DERIV (\<lambda>x. x^Suc k / Suc k) x :> x^k"
   514     by (intro derivative_eq_intros) auto
   515 qed (auto simp: field_simps simp del: of_nat_Suc)
   516 
   517 subsection \<open>Integration by parts\<close>
   518 
   519 lemma integral_by_parts_integrable:
   520   fixes f g F G::"real \<Rightarrow> real"
   521   assumes "a \<le> b"
   522   assumes cont_f[intro]: "!!x. a \<le>x \<Longrightarrow> x\<le>b \<Longrightarrow> isCont f x"
   523   assumes cont_g[intro]: "!!x. a \<le>x \<Longrightarrow> x\<le>b \<Longrightarrow> isCont g x"
   524   assumes [intro]: "!!x. DERIV F x :> f x"
   525   assumes [intro]: "!!x. DERIV G x :> g x"
   526   shows  "integrable lborel (\<lambda>x.((F x) * (g x) + (f x) * (G x)) * indicator {a .. b} x)"
   527   by (auto intro!: borel_integrable_atLeastAtMost continuous_intros) (auto intro!: DERIV_isCont)
   528 
   529 lemma integral_by_parts:
   530   fixes f g F G::"real \<Rightarrow> real"
   531   assumes [arith]: "a \<le> b"
   532   assumes cont_f[intro]: "!!x. a \<le>x \<Longrightarrow> x\<le>b \<Longrightarrow> isCont f x"
   533   assumes cont_g[intro]: "!!x. a \<le>x \<Longrightarrow> x\<le>b \<Longrightarrow> isCont g x"
   534   assumes [intro]: "!!x. DERIV F x :> f x"
   535   assumes [intro]: "!!x. DERIV G x :> g x"
   536   shows "(\<integral>x. (F x * g x) * indicator {a .. b} x \<partial>lborel)
   537             =  F b * G b - F a * G a - \<integral>x. (f x * G x) * indicator {a .. b} x \<partial>lborel"
   538 proof-
   539   have 0: "(\<integral>x. (F x * g x + f x * G x) * indicator {a .. b} x \<partial>lborel) = F b * G b - F a * G a"
   540     by (rule integral_FTC_Icc_real, auto intro!: derivative_eq_intros continuous_intros)
   541       (auto intro!: DERIV_isCont)
   542 
   543   have "(\<integral>x. (F x * g x + f x * G x) * indicator {a .. b} x \<partial>lborel) =
   544     (\<integral>x. (F x * g x) * indicator {a .. b} x \<partial>lborel) + \<integral>x. (f x * G x) * indicator {a .. b} x \<partial>lborel"
   545     apply (subst Bochner_Integration.integral_add[symmetric])
   546     apply (auto intro!: borel_integrable_atLeastAtMost continuous_intros)
   547     by (auto intro!: DERIV_isCont Bochner_Integration.integral_cong split: split_indicator)
   548 
   549   thus ?thesis using 0 by auto
   550 qed
   551 
   552 lemma integral_by_parts':
   553   fixes f g F G::"real \<Rightarrow> real"
   554   assumes "a \<le> b"
   555   assumes "!!x. a \<le>x \<Longrightarrow> x\<le>b \<Longrightarrow> isCont f x"
   556   assumes "!!x. a \<le>x \<Longrightarrow> x\<le>b \<Longrightarrow> isCont g x"
   557   assumes "!!x. DERIV F x :> f x"
   558   assumes "!!x. DERIV G x :> g x"
   559   shows "(\<integral>x. indicator {a .. b} x *\<^sub>R (F x * g x) \<partial>lborel)
   560             =  F b * G b - F a * G a - \<integral>x. indicator {a .. b} x *\<^sub>R (f x * G x) \<partial>lborel"
   561   using integral_by_parts[OF assms] by (simp add: ac_simps)
   562 
   563 lemma has_bochner_integral_even_function:
   564   fixes f :: "real \<Rightarrow> 'a :: {banach, second_countable_topology}"
   565   assumes f: "has_bochner_integral lborel (\<lambda>x. indicator {0..} x *\<^sub>R f x) x"
   566   assumes even: "\<And>x. f (- x) = f x"
   567   shows "has_bochner_integral lborel f (2 *\<^sub>R x)"
   568 proof -
   569   have indicator: "\<And>x::real. indicator {..0} (- x) = indicator {0..} x"
   570     by (auto split: split_indicator)
   571   have "has_bochner_integral lborel (\<lambda>x. indicator {.. 0} x *\<^sub>R f x) x"
   572     by (subst lborel_has_bochner_integral_real_affine_iff[where c="-1" and t=0])
   573        (auto simp: indicator even f)
   574   with f have "has_bochner_integral lborel (\<lambda>x. indicator {0..} x *\<^sub>R f x + indicator {.. 0} x *\<^sub>R f x) (x + x)"
   575     by (rule has_bochner_integral_add)
   576   then have "has_bochner_integral lborel f (x + x)"
   577     by (rule has_bochner_integral_discrete_difference[where X="{0}", THEN iffD1, rotated 4])
   578        (auto split: split_indicator)
   579   then show ?thesis
   580     by (simp add: scaleR_2)
   581 qed
   582 
   583 lemma has_bochner_integral_odd_function:
   584   fixes f :: "real \<Rightarrow> 'a :: {banach, second_countable_topology}"
   585   assumes f: "has_bochner_integral lborel (\<lambda>x. indicator {0..} x *\<^sub>R f x) x"
   586   assumes odd: "\<And>x. f (- x) = - f x"
   587   shows "has_bochner_integral lborel f 0"
   588 proof -
   589   have indicator: "\<And>x::real. indicator {..0} (- x) = indicator {0..} x"
   590     by (auto split: split_indicator)
   591   have "has_bochner_integral lborel (\<lambda>x. - indicator {.. 0} x *\<^sub>R f x) x"
   592     by (subst lborel_has_bochner_integral_real_affine_iff[where c="-1" and t=0])
   593        (auto simp: indicator odd f)
   594   from has_bochner_integral_minus[OF this]
   595   have "has_bochner_integral lborel (\<lambda>x. indicator {.. 0} x *\<^sub>R f x) (- x)"
   596     by simp
   597   with f have "has_bochner_integral lborel (\<lambda>x. indicator {0..} x *\<^sub>R f x + indicator {.. 0} x *\<^sub>R f x) (x + - x)"
   598     by (rule has_bochner_integral_add)
   599   then have "has_bochner_integral lborel f (x + - x)"
   600     by (rule has_bochner_integral_discrete_difference[where X="{0}", THEN iffD1, rotated 4])
   601        (auto split: split_indicator)
   602   then show ?thesis
   603     by simp
   604 qed
   605 
   606 end