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