src/HOL/Analysis/Lebesgue_Integral_Substitution.thy
author nipkow
Sat Dec 29 15:43:53 2018 +0100 (6 months ago)
changeset 69529 4ab9657b3257
parent 69517 dc20f278e8f3
child 69712 dc85b5b3a532
permissions -rw-r--r--
capitalize proper names in lemma names
hoelzl@63627
     1
(*  Title:      HOL/Analysis/Lebesgue_Integral_Substitution.thy
hoelzl@59092
     2
    Author:     Manuel Eberl
hoelzl@59092
     3
hoelzl@59092
     4
    Provides lemmas for integration by substitution for the basic integral types.
hoelzl@59092
     5
    Note that the substitution function must have a nonnegative derivative.
hoelzl@59092
     6
    This could probably be weakened somehow.
hoelzl@59092
     7
*)
hoelzl@59092
     8
nipkow@69517
     9
section \<open>Integration by Substition for the Lebesgue Integral\<close>
hoelzl@59092
    10
hoelzl@59092
    11
theory Lebesgue_Integral_Substitution
hoelzl@59092
    12
imports Interval_Integral
hoelzl@59092
    13
begin
hoelzl@59092
    14
paulson@66317
    15
hoelzl@59092
    16
lemma nn_integral_substitution_aux:
hoelzl@62975
    17
  fixes f :: "real \<Rightarrow> ennreal"
hoelzl@59092
    18
  assumes Mf: "f \<in> borel_measurable borel"
hoelzl@59092
    19
  assumes nonnegf: "\<And>x. f x \<ge> 0"
hoelzl@59092
    20
  assumes derivg: "\<And>x. x \<in> {a..b} \<Longrightarrow> (g has_real_derivative g' x) (at x)"
hoelzl@62975
    21
  assumes contg': "continuous_on {a..b} g'"
hoelzl@59092
    22
  assumes derivg_nonneg: "\<And>x. x \<in> {a..b} \<Longrightarrow> g' x \<ge> 0"
hoelzl@59092
    23
  assumes "a < b"
hoelzl@62975
    24
  shows "(\<integral>\<^sup>+x. f x * indicator {g a..g b} x \<partial>lborel) =
hoelzl@59092
    25
             (\<integral>\<^sup>+x. f (g x) * g' x * indicator {a..b} x \<partial>lborel)"
hoelzl@59092
    26
proof-
wenzelm@61808
    27
  from \<open>a < b\<close> have [simp]: "a \<le> b" by simp
hoelzl@59092
    28
  from derivg have contg: "continuous_on {a..b} g" by (rule has_real_derivative_imp_continuous_on)
hoelzl@62975
    29
  from this and contg' have Mg: "set_borel_measurable borel {a..b} g" and
hoelzl@62975
    30
                             Mg': "set_borel_measurable borel {a..b} g'"
hoelzl@59092
    31
      by (simp_all only: set_measurable_continuous_on_ivl)
hoelzl@59092
    32
  from derivg have derivg': "\<And>x. x \<in> {a..b} \<Longrightarrow> (g has_vector_derivative g' x) (at x)"
hoelzl@59092
    33
    by (simp only: has_field_derivative_iff_has_vector_derivative)
hoelzl@59092
    34
hoelzl@62975
    35
  have real_ind[simp]: "\<And>A x. enn2real (indicator A x) = indicator A x"
hoelzl@59092
    36
      by (auto split: split_indicator)
hoelzl@62975
    37
  have ennreal_ind[simp]: "\<And>A x. ennreal (indicator A x) = indicator A x"
hoelzl@59092
    38
      by (auto split: split_indicator)
hoelzl@62975
    39
  have [simp]: "\<And>x A. indicator A (g x) = indicator (g -` A) x"
hoelzl@59092
    40
      by (auto split: split_indicator)
hoelzl@59092
    41
hoelzl@59092
    42
  from derivg derivg_nonneg have monog: "\<And>x y. a \<le> x \<Longrightarrow> x \<le> y \<Longrightarrow> y \<le> b \<Longrightarrow> g x \<le> g y"
hoelzl@59092
    43
    by (rule deriv_nonneg_imp_mono) simp_all
hoelzl@59092
    44
  with monog have [simp]: "g a \<le> g b" by (auto intro: mono_onD)
hoelzl@59092
    45
hoelzl@59092
    46
  show ?thesis
hoelzl@62975
    47
  proof (induction rule: borel_measurable_induct[OF Mf, case_names cong set mult add sup])
hoelzl@59092
    48
    case (cong f1 f2)
hoelzl@59092
    49
    from cong.hyps(3) have "f1 = f2" by auto
hoelzl@59092
    50
    with cong show ?case by simp
hoelzl@59092
    51
  next
hoelzl@59092
    52
    case (set A)
hoelzl@59092
    53
    from set.hyps show ?case
hoelzl@59092
    54
    proof (induction rule: borel_set_induct)
hoelzl@59092
    55
      case empty
hoelzl@59092
    56
      thus ?case by simp
hoelzl@59092
    57
    next
hoelzl@59092
    58
      case (interval c d)
hoelzl@59092
    59
      {
hoelzl@59092
    60
        fix u v :: real assume asm: "{u..v} \<subseteq> {g a..g b}" "u \<le> v"
hoelzl@62975
    61
hoelzl@59092
    62
        obtain u' v' where u'v': "{a..b} \<inter> g-`{u..v} = {u'..v'}" "u' \<le> v'" "g u' = u" "g v' = v"
hoelzl@59092
    63
             using asm by (rule_tac continuous_interval_vimage_Int[OF contg monog, of u v]) simp_all
hoelzl@59092
    64
        hence "{u'..v'} \<subseteq> {a..b}" "{u'..v'} \<subseteq> g -` {u..v}" by blast+
hoelzl@59092
    65
        with u'v'(2) have "u' \<in> g -` {u..v}" "v' \<in> g -` {u..v}" by auto
hoelzl@59092
    66
        from u'v'(1) have [simp]: "{a..b} \<inter> g -` {u..v} \<in> sets borel" by simp
hoelzl@62975
    67
hoelzl@59092
    68
        have A: "continuous_on {min u' v'..max u' v'} g'"
hoelzl@62975
    69
            by (simp only: u'v' max_absorb2 min_absorb1)
hoelzl@59092
    70
               (intro continuous_on_subset[OF contg'], insert u'v', auto)
hoelzl@59092
    71
        have "\<And>x. x \<in> {u'..v'} \<Longrightarrow> (g has_real_derivative g' x) (at x within {u'..v'})"
wenzelm@61808
    72
           using asm by (intro has_field_derivative_subset[OF derivg] set_mp[OF \<open>{u'..v'} \<subseteq> {a..b}\<close>]) auto
hoelzl@62975
    73
        hence B: "\<And>x. min u' v' \<le> x \<Longrightarrow> x \<le> max u' v' \<Longrightarrow>
hoelzl@62975
    74
                      (g has_vector_derivative g' x) (at x within {min u' v'..max u' v'})"
hoelzl@62975
    75
            by (simp only: u'v' max_absorb2 min_absorb1)
hoelzl@59092
    76
               (auto simp: has_field_derivative_iff_has_vector_derivative)
lp15@67976
    77
          have "integrable lborel (\<lambda>x. indicator ({a..b} \<inter> g -` {u..v}) x *\<^sub>R g' x)"
lp15@67976
    78
            using set_integrable_subset borel_integrable_atLeastAtMost'[OF contg']
lp15@67976
    79
            by (metis \<open>{u'..v'} \<subseteq> {a..b}\<close> eucl_ivals(5) set_integrable_def sets_lborel u'v'(1))
hoelzl@62975
    80
        hence "(\<integral>\<^sup>+x. ennreal (g' x) * indicator ({a..b} \<inter> g-` {u..v}) x \<partial>lborel) =
hoelzl@62975
    81
                   LBINT x:{a..b} \<inter> g-`{u..v}. g' x"
lp15@67976
    82
          unfolding set_lebesgue_integral_def
hoelzl@62975
    83
          by (subst nn_integral_eq_integral[symmetric])
hoelzl@62975
    84
             (auto intro!: derivg_nonneg nn_integral_cong split: split_indicator)
hoelzl@59092
    85
        also from interval_integral_FTC_finite[OF A B]
hoelzl@59092
    86
            have "LBINT x:{a..b} \<inter> g-`{u..v}. g' x = v - u"
wenzelm@61808
    87
                by (simp add: u'v' interval_integral_Icc \<open>u \<le> v\<close>)
hoelzl@62975
    88
        finally have "(\<integral>\<^sup>+ x. ennreal (g' x) * indicator ({a..b} \<inter> g -` {u..v}) x \<partial>lborel) =
hoelzl@62975
    89
                           ennreal (v - u)" .
hoelzl@59092
    90
      } note A = this
hoelzl@62975
    91
hoelzl@62975
    92
      have "(\<integral>\<^sup>+x. indicator {c..d} (g x) * ennreal (g' x) * indicator {a..b} x \<partial>lborel) =
hoelzl@62975
    93
               (\<integral>\<^sup>+ x. ennreal (g' x) * indicator ({a..b} \<inter> g -` {c..d}) x \<partial>lborel)"
hoelzl@59092
    94
        by (intro nn_integral_cong) (simp split: split_indicator)
hoelzl@62975
    95
      also have "{a..b} \<inter> g-`{c..d} = {a..b} \<inter> g-`{max (g a) c..min (g b) d}"
wenzelm@61808
    96
        using \<open>a \<le> b\<close> \<open>c \<le> d\<close>
hoelzl@59092
    97
        by (auto intro!: monog intro: order.trans)
hoelzl@62975
    98
      also have "(\<integral>\<^sup>+ x. ennreal (g' x) * indicator ... x \<partial>lborel) =
hoelzl@59092
    99
        (if max (g a) c \<le> min (g b) d then min (g b) d - max (g a) c else 0)"
wenzelm@61808
   100
         using \<open>c \<le> d\<close> by (simp add: A)
hoelzl@59092
   101
      also have "... = (\<integral>\<^sup>+ x. indicator ({g a..g b} \<inter> {c..d}) x \<partial>lborel)"
hoelzl@59092
   102
        by (subst nn_integral_indicator) (auto intro!: measurable_sets Mg simp:)
hoelzl@59092
   103
      also have "... = (\<integral>\<^sup>+ x. indicator {c..d} x * indicator {g a..g b} x \<partial>lborel)"
hoelzl@59092
   104
        by (intro nn_integral_cong) (auto split: split_indicator)
hoelzl@59092
   105
      finally show ?case ..
hoelzl@59092
   106
hoelzl@59092
   107
      next
hoelzl@59092
   108
hoelzl@59092
   109
      case (compl A)
wenzelm@61808
   110
      note \<open>A \<in> sets borel\<close>[measurable]
hoelzl@59092
   111
      from emeasure_mono[of "A \<inter> {g a..g b}" "{g a..g b}" lborel]
hoelzl@62975
   112
      have [simp]: "emeasure lborel (A \<inter> {g a..g b}) \<noteq> top" by (auto simp: top_unique)
hoelzl@59092
   113
      have [simp]: "g -` A \<inter> {a..b} \<in> sets borel"
hoelzl@59092
   114
        by (rule set_borel_measurable_sets[OF Mg]) auto
hoelzl@59092
   115
      have [simp]: "g -` (-A) \<inter> {a..b} \<in> sets borel"
hoelzl@59092
   116
        by (rule set_borel_measurable_sets[OF Mg]) auto
hoelzl@59092
   117
hoelzl@62975
   118
      have "(\<integral>\<^sup>+x. indicator (-A) x * indicator {g a..g b} x \<partial>lborel) =
hoelzl@62975
   119
                (\<integral>\<^sup>+x. indicator (-A \<inter> {g a..g b}) x \<partial>lborel)"
hoelzl@59092
   120
        by (rule nn_integral_cong) (simp split: split_indicator)
hoelzl@59092
   121
      also from compl have "... = emeasure lborel ({g a..g b} - A)" using derivg_nonneg
hoelzl@59092
   122
        by (simp add: vimage_Compl diff_eq Int_commute[of "-A"])
hoelzl@59092
   123
      also have "{g a..g b} - A = {g a..g b} - A \<inter> {g a..g b}" by blast
hoelzl@59092
   124
      also have "emeasure lborel ... = g b - g a - emeasure lborel (A \<inter> {g a..g b})"
hoelzl@62975
   125
             using \<open>A \<in> sets borel\<close> by (subst emeasure_Diff) (auto simp: )
hoelzl@62975
   126
     also have "emeasure lborel (A \<inter> {g a..g b}) =
hoelzl@62975
   127
                    \<integral>\<^sup>+x. indicator A x * indicator {g a..g b} x \<partial>lborel"
wenzelm@61808
   128
       using \<open>A \<in> sets borel\<close>
hoelzl@59092
   129
       by (subst nn_integral_indicator[symmetric], simp, intro nn_integral_cong)
hoelzl@59092
   130
          (simp split: split_indicator)
hoelzl@62975
   131
      also have "... = \<integral>\<^sup>+ x. indicator (g-`A \<inter> {a..b}) x * ennreal (g' x * indicator {a..b} x) \<partial>lborel" (is "_ = ?I")
hoelzl@59092
   132
        by (subst compl.IH, intro nn_integral_cong) (simp split: split_indicator)
hoelzl@59092
   133
      also have "g b - g a = LBINT x:{a..b}. g' x" using derivg'
lp15@67976
   134
        unfolding set_lebesgue_integral_def
hoelzl@59092
   135
        by (intro integral_FTC_atLeastAtMost[symmetric])
hoelzl@59092
   136
           (auto intro: continuous_on_subset[OF contg'] has_field_derivative_subset[OF derivg]
hoelzl@59092
   137
                 has_vector_derivative_at_within)
hoelzl@62975
   138
      also have "ennreal ... = \<integral>\<^sup>+ x. g' x * indicator {a..b} x \<partial>lborel"
lp15@67976
   139
        using borel_integrable_atLeastAtMost'[OF contg'] unfolding set_lebesgue_integral_def
hoelzl@59092
   140
        by (subst nn_integral_eq_integral)
lp15@67976
   141
           (simp_all add: mult.commute derivg_nonneg set_integrable_def split: split_indicator)
hoelzl@62975
   142
      also have Mg'': "(\<lambda>x. indicator (g -` A \<inter> {a..b}) x * ennreal (g' x * indicator {a..b} x))
hoelzl@59092
   143
                            \<in> borel_measurable borel" using Mg'
hoelzl@62975
   144
        by (intro borel_measurable_times_ennreal borel_measurable_indicator)
lp15@67976
   145
           (simp_all add: mult.commute set_borel_measurable_def)
hoelzl@62975
   146
      have le: "(\<integral>\<^sup>+x. indicator (g-`A \<inter> {a..b}) x * ennreal (g' x * indicator {a..b} x) \<partial>lborel) \<le>
hoelzl@62975
   147
                        (\<integral>\<^sup>+x. ennreal (g' x) * indicator {a..b} x \<partial>lborel)"
hoelzl@59092
   148
         by (intro nn_integral_mono) (simp split: split_indicator add: derivg_nonneg)
hoelzl@59092
   149
      note integrable = borel_integrable_atLeastAtMost'[OF contg']
hoelzl@62975
   150
      with le have notinf: "(\<integral>\<^sup>+x. indicator (g-`A \<inter> {a..b}) x * ennreal (g' x * indicator {a..b} x) \<partial>lborel) \<noteq> top"
lp15@67976
   151
          by (auto simp: real_integrable_def nn_integral_set_ennreal mult.commute top_unique set_integrable_def)
hoelzl@62975
   152
      have "(\<integral>\<^sup>+ x. g' x * indicator {a..b} x \<partial>lborel) - ?I =
hoelzl@62975
   153
                  \<integral>\<^sup>+ x. ennreal (g' x * indicator {a..b} x) -
hoelzl@62975
   154
                        indicator (g -` A \<inter> {a..b}) x * ennreal (g' x * indicator {a..b} x) \<partial>lborel"
hoelzl@59092
   155
        apply (intro nn_integral_diff[symmetric])
lp15@67976
   156
        apply (insert Mg', simp add: mult.commute set_borel_measurable_def) []
hoelzl@59092
   157
        apply (insert Mg'', simp) []
hoelzl@59092
   158
        apply (simp split: split_indicator add: derivg_nonneg)
hoelzl@59092
   159
        apply (rule notinf)
hoelzl@59092
   160
        apply (simp split: split_indicator add: derivg_nonneg)
hoelzl@59092
   161
        done
hoelzl@62975
   162
      also have "... = \<integral>\<^sup>+ x. indicator (-A) (g x) * ennreal (g' x) * indicator {a..b} x \<partial>lborel"
hoelzl@59092
   163
        by (intro nn_integral_cong) (simp split: split_indicator)
hoelzl@59092
   164
      finally show ?case .
hoelzl@59092
   165
hoelzl@59092
   166
    next
hoelzl@59092
   167
      case (union f)
hoelzl@59092
   168
      then have [simp]: "\<And>i. {a..b} \<inter> g -` f i \<in> sets borel"
hoelzl@59092
   169
        by (subst Int_commute, intro set_borel_measurable_sets[OF Mg]) auto
hoelzl@59092
   170
      have "g -` (\<Union>i. f i) \<inter> {a..b} = (\<Union>i. {a..b} \<inter> g -` f i)" by auto
hoelzl@59092
   171
      hence "g -` (\<Union>i. f i) \<inter> {a..b} \<in> sets borel" by (auto simp del: UN_simps)
hoelzl@59092
   172
hoelzl@62975
   173
      have "(\<integral>\<^sup>+x. indicator (\<Union>i. f i) x * indicator {g a..g b} x \<partial>lborel) =
hoelzl@59092
   174
                \<integral>\<^sup>+x. indicator (\<Union>i. {g a..g b} \<inter> f i) x \<partial>lborel"
hoelzl@59092
   175
          by (intro nn_integral_cong) (simp split: split_indicator)
hoelzl@59092
   176
      also from union have "... = emeasure lborel (\<Union>i. {g a..g b} \<inter> f i)" by simp
hoelzl@59092
   177
      also from union have "... = (\<Sum>i. emeasure lborel ({g a..g b} \<inter> f i))"
hoelzl@59092
   178
        by (intro suminf_emeasure[symmetric]) (auto simp: disjoint_family_on_def)
hoelzl@59092
   179
      also from union have "... = (\<Sum>i. \<integral>\<^sup>+x. indicator ({g a..g b} \<inter> f i) x \<partial>lborel)" by simp
hoelzl@62975
   180
      also have "(\<lambda>i. \<integral>\<^sup>+x. indicator ({g a..g b} \<inter> f i) x \<partial>lborel) =
hoelzl@59092
   181
                           (\<lambda>i. \<integral>\<^sup>+x. indicator (f i) x * indicator {g a..g b} x \<partial>lborel)"
hoelzl@59092
   182
        by (intro ext nn_integral_cong) (simp split: split_indicator)
hoelzl@62975
   183
      also from union.IH have "(\<Sum>i. \<integral>\<^sup>+x. indicator (f i) x * indicator {g a..g b} x \<partial>lborel) =
hoelzl@62975
   184
          (\<Sum>i. \<integral>\<^sup>+ x. indicator (f i) (g x) * ennreal (g' x) * indicator {a..b} x \<partial>lborel)" by simp
hoelzl@62975
   185
      also have "(\<lambda>i. \<integral>\<^sup>+ x. indicator (f i) (g x) * ennreal (g' x) * indicator {a..b} x \<partial>lborel) =
hoelzl@62975
   186
                         (\<lambda>i. \<integral>\<^sup>+ x. ennreal (g' x * indicator {a..b} x) * indicator ({a..b} \<inter> g -` f i) x \<partial>lborel)"
hoelzl@59092
   187
        by (intro ext nn_integral_cong) (simp split: split_indicator)
hoelzl@62975
   188
      also have "(\<Sum>i. ... i) = \<integral>\<^sup>+ x. (\<Sum>i. ennreal (g' x * indicator {a..b} x) * indicator ({a..b} \<inter> g -` f i) x) \<partial>lborel"
hoelzl@59092
   189
        using Mg'
hoelzl@59092
   190
        apply (intro nn_integral_suminf[symmetric])
lp15@67976
   191
        apply (rule borel_measurable_times_ennreal, simp add: mult.commute set_borel_measurable_def)
hoelzl@59092
   192
        apply (rule borel_measurable_indicator, subst sets_lborel)
hoelzl@59092
   193
        apply (simp_all split: split_indicator add: derivg_nonneg)
hoelzl@59092
   194
        done
hoelzl@62975
   195
      also have "(\<lambda>x i. ennreal (g' x * indicator {a..b} x) * indicator ({a..b} \<inter> g -` f i) x) =
hoelzl@62975
   196
                      (\<lambda>x i. ennreal (g' x * indicator {a..b} x) * indicator (g -` f i) x)"
hoelzl@59092
   197
        by (intro ext) (simp split: split_indicator)
hoelzl@62975
   198
      also have "(\<integral>\<^sup>+ x. (\<Sum>i. ennreal (g' x * indicator {a..b} x) * indicator (g -` f i) x) \<partial>lborel) =
hoelzl@62975
   199
                     \<integral>\<^sup>+ x. ennreal (g' x * indicator {a..b} x) * (\<Sum>i. indicator (g -` f i) x) \<partial>lborel"
hoelzl@62975
   200
        by (intro nn_integral_cong) (auto split: split_indicator simp: derivg_nonneg)
hoelzl@62975
   201
      also from union have "(\<lambda>x. \<Sum>i. indicator (g -` f i) x :: ennreal) = (\<lambda>x. indicator (\<Union>i. g -` f i) x)"
hoelzl@59092
   202
        by (intro ext suminf_indicator) (auto simp: disjoint_family_on_def)
hoelzl@62975
   203
      also have "(\<integral>\<^sup>+x. ennreal (g' x * indicator {a..b} x) * ... x \<partial>lborel) =
hoelzl@62975
   204
                    (\<integral>\<^sup>+x. indicator (\<Union>i. f i) (g x) * ennreal (g' x) * indicator {a..b} x \<partial>lborel)"
hoelzl@59092
   205
       by (intro nn_integral_cong) (simp split: split_indicator)
hoelzl@59092
   206
      finally show ?case .
hoelzl@59092
   207
  qed
hoelzl@59092
   208
hoelzl@59092
   209
next
hoelzl@59092
   210
  case (mult f c)
wenzelm@61808
   211
    note Mf[measurable] = \<open>f \<in> borel_measurable borel\<close>
hoelzl@59092
   212
    let ?I = "indicator {a..b}"
hoelzl@62975
   213
    have "(\<lambda>x. f (g x * ?I x) * ennreal (g' x * ?I x)) \<in> borel_measurable borel" using Mg Mg'
hoelzl@62975
   214
      by (intro borel_measurable_times_ennreal measurable_compose[OF _ Mf])
lp15@67976
   215
         (simp_all add: mult.commute set_borel_measurable_def)
hoelzl@62975
   216
    also have "(\<lambda>x. f (g x * ?I x) * ennreal (g' x * ?I x)) = (\<lambda>x. f (g x) * ennreal (g' x) * ?I x)"
hoelzl@59092
   217
      by (intro ext) (simp split: split_indicator)
hoelzl@62975
   218
    finally have Mf': "(\<lambda>x. f (g x) * ennreal (g' x) * ?I x) \<in> borel_measurable borel" .
hoelzl@59092
   219
    with mult show ?case
hoelzl@59092
   220
      by (subst (1 2 3) mult_ac, subst (1 2) nn_integral_cmult) (simp_all add: mult_ac)
hoelzl@62975
   221
hoelzl@59092
   222
next
hoelzl@59092
   223
  case (add f2 f1)
hoelzl@59092
   224
    let ?I = "indicator {a..b}"
hoelzl@59092
   225
    {
hoelzl@62975
   226
      fix f :: "real \<Rightarrow> ennreal" assume Mf: "f \<in> borel_measurable borel"
hoelzl@62975
   227
      have "(\<lambda>x. f (g x * ?I x) * ennreal (g' x * ?I x)) \<in> borel_measurable borel" using Mg Mg'
hoelzl@62975
   228
        by (intro borel_measurable_times_ennreal measurable_compose[OF _ Mf])
lp15@67976
   229
           (simp_all add:  mult.commute set_borel_measurable_def)
hoelzl@62975
   230
      also have "(\<lambda>x. f (g x * ?I x) * ennreal (g' x * ?I x)) = (\<lambda>x. f (g x) * ennreal (g' x) * ?I x)"
hoelzl@59092
   231
        by (intro ext) (simp split: split_indicator)
hoelzl@62975
   232
      finally have "(\<lambda>x. f (g x) * ennreal (g' x) * ?I x) \<in> borel_measurable borel" .
wenzelm@61808
   233
    } note Mf' = this[OF \<open>f1 \<in> borel_measurable borel\<close>] this[OF \<open>f2 \<in> borel_measurable borel\<close>]
hoelzl@59092
   234
hoelzl@59092
   235
    have "(\<integral>\<^sup>+ x. (f1 x + f2 x) * indicator {g a..g b} x \<partial>lborel) =
hoelzl@59092
   236
             (\<integral>\<^sup>+ x. f1 x * indicator {g a..g b} x + f2 x * indicator {g a..g b} x \<partial>lborel)"
hoelzl@59092
   237
      by (intro nn_integral_cong) (simp split: split_indicator)
hoelzl@62975
   238
    also from add have "... = (\<integral>\<^sup>+ x. f1 (g x) * ennreal (g' x) * indicator {a..b} x \<partial>lborel) +
hoelzl@62975
   239
                                (\<integral>\<^sup>+ x. f2 (g x) * ennreal (g' x) * indicator {a..b} x \<partial>lborel)"
hoelzl@59092
   240
      by (simp_all add: nn_integral_add)
hoelzl@62975
   241
    also from add have "... = (\<integral>\<^sup>+ x. f1 (g x) * ennreal (g' x) * indicator {a..b} x +
hoelzl@62975
   242
                                      f2 (g x) * ennreal (g' x) * indicator {a..b} x \<partial>lborel)"
hoelzl@59092
   243
      by (intro nn_integral_add[symmetric])
hoelzl@59092
   244
         (auto simp add: Mf' derivg_nonneg split: split_indicator)
hoelzl@62975
   245
    also have "... = \<integral>\<^sup>+ x. (f1 (g x) + f2 (g x)) * ennreal (g' x) * indicator {a..b} x \<partial>lborel"
hoelzl@62975
   246
      by (intro nn_integral_cong) (simp split: split_indicator add: distrib_right)
hoelzl@59092
   247
    finally show ?case .
hoelzl@59092
   248
hoelzl@59092
   249
next
hoelzl@59092
   250
  case (sup F)
hoelzl@59092
   251
  {
hoelzl@59092
   252
    fix i
hoelzl@59092
   253
    let ?I = "indicator {a..b}"
hoelzl@62975
   254
    have "(\<lambda>x. F i (g x * ?I x) * ennreal (g' x * ?I x)) \<in> borel_measurable borel" using Mg Mg'
hoelzl@62975
   255
      by (rule_tac borel_measurable_times_ennreal, rule_tac measurable_compose[OF _ sup.hyps(1)])
lp15@67976
   256
         (simp_all add: mult.commute set_borel_measurable_def)
hoelzl@62975
   257
    also have "(\<lambda>x. F i (g x * ?I x) * ennreal (g' x * ?I x)) = (\<lambda>x. F i (g x) * ennreal (g' x) * ?I x)"
hoelzl@59092
   258
      by (intro ext) (simp split: split_indicator)
hoelzl@59092
   259
     finally have "... \<in> borel_measurable borel" .
hoelzl@59092
   260
  } note Mf' = this
hoelzl@59092
   261
hoelzl@62975
   262
    have "(\<integral>\<^sup>+x. (SUP i. F i x) * indicator {g a..g b} x \<partial>lborel) =
hoelzl@59092
   263
               \<integral>\<^sup>+x. (SUP i. F i x* indicator {g a..g b} x) \<partial>lborel"
hoelzl@59092
   264
      by (intro nn_integral_cong) (simp split: split_indicator)
hoelzl@59092
   265
    also from sup have "... = (SUP i. \<integral>\<^sup>+x. F i x* indicator {g a..g b} x \<partial>lborel)"
hoelzl@59092
   266
      by (intro nn_integral_monotone_convergence_SUP)
hoelzl@59092
   267
         (auto simp: incseq_def le_fun_def split: split_indicator)
hoelzl@62975
   268
    also from sup have "... = (SUP i. \<integral>\<^sup>+x. F i (g x) * ennreal (g' x) * indicator {a..b} x \<partial>lborel)"
hoelzl@59092
   269
      by simp
hoelzl@62975
   270
    also from sup have "... =  \<integral>\<^sup>+x. (SUP i. F i (g x) * ennreal (g' x) * indicator {a..b} x) \<partial>lborel"
hoelzl@59092
   271
      by (intro nn_integral_monotone_convergence_SUP[symmetric])
hoelzl@59092
   272
         (auto simp: incseq_def le_fun_def derivg_nonneg Mf' split: split_indicator
hoelzl@62975
   273
               intro!: mult_right_mono)
hoelzl@62975
   274
    also from sup have "... = \<integral>\<^sup>+x. (SUP i. F i (g x)) * ennreal (g' x) * indicator {a..b} x \<partial>lborel"
hoelzl@62975
   275
      by (subst mult.assoc, subst mult.commute, subst SUP_mult_left_ennreal)
hoelzl@59092
   276
         (auto split: split_indicator simp: derivg_nonneg mult_ac)
hoelzl@59092
   277
    finally show ?case by simp
hoelzl@59092
   278
  qed
hoelzl@59092
   279
qed
hoelzl@59092
   280
eberlm@69180
   281
theorem nn_integral_substitution:
hoelzl@59092
   282
  fixes f :: "real \<Rightarrow> real"
hoelzl@59092
   283
  assumes Mf[measurable]: "set_borel_measurable borel {g a..g b} f"
hoelzl@59092
   284
  assumes derivg: "\<And>x. x \<in> {a..b} \<Longrightarrow> (g has_real_derivative g' x) (at x)"
hoelzl@62975
   285
  assumes contg': "continuous_on {a..b} g'"
hoelzl@59092
   286
  assumes derivg_nonneg: "\<And>x. x \<in> {a..b} \<Longrightarrow> g' x \<ge> 0"
hoelzl@59092
   287
  assumes "a \<le> b"
hoelzl@62975
   288
  shows "(\<integral>\<^sup>+x. f x * indicator {g a..g b} x \<partial>lborel) =
hoelzl@59092
   289
             (\<integral>\<^sup>+x. f (g x) * g' x * indicator {a..b} x \<partial>lborel)"
hoelzl@59092
   290
proof (cases "a = b")
hoelzl@59092
   291
  assume "a \<noteq> b"
wenzelm@61808
   292
  with \<open>a \<le> b\<close> have "a < b" by auto
hoelzl@62975
   293
  let ?f' = "\<lambda>x. f x * indicator {g a..g b} x"
hoelzl@59092
   294
hoelzl@59092
   295
  from derivg derivg_nonneg have monog: "\<And>x y. a \<le> x \<Longrightarrow> x \<le> y \<Longrightarrow> y \<le> b \<Longrightarrow> g x \<le> g y"
hoelzl@59092
   296
    by (rule deriv_nonneg_imp_mono) simp_all
hoelzl@59092
   297
  have bounds: "\<And>x. x \<ge> a \<Longrightarrow> x \<le> b \<Longrightarrow> g x \<ge> g a" "\<And>x. x \<ge> a \<Longrightarrow> x \<le> b \<Longrightarrow> g x \<le> g b"
hoelzl@59092
   298
    by (auto intro: monog)
hoelzl@59092
   299
hoelzl@62975
   300
  from derivg_nonneg have nonneg:
hoelzl@62975
   301
    "\<And>f x. x \<ge> a \<Longrightarrow> x \<le> b \<Longrightarrow> g' x \<noteq> 0 \<Longrightarrow> f x * ennreal (g' x) \<ge> 0 \<Longrightarrow> f x \<ge> 0"
hoelzl@62975
   302
    by (force simp: field_simps)
hoelzl@59092
   303
  have nonneg': "\<And>x. a \<le> x \<Longrightarrow> x \<le> b \<Longrightarrow> \<not> 0 \<le> f (g x) \<Longrightarrow> 0 \<le> f (g x) * g' x \<Longrightarrow> g' x = 0"
hoelzl@59092
   304
    by (metis atLeastAtMost_iff derivg_nonneg eq_iff mult_eq_0_iff mult_le_0_iff)
hoelzl@59092
   305
hoelzl@62975
   306
  have "(\<integral>\<^sup>+x. f x * indicator {g a..g b} x \<partial>lborel) =
hoelzl@62975
   307
            (\<integral>\<^sup>+x. ennreal (?f' x) * indicator {g a..g b} x \<partial>lborel)"
hoelzl@59092
   308
    by (intro nn_integral_cong)
hoelzl@62975
   309
       (auto split: split_indicator split_max simp: zero_ennreal.rep_eq ennreal_neg)
hoelzl@62975
   310
  also have "... = \<integral>\<^sup>+ x. ?f' (g x) * ennreal (g' x) * indicator {a..b} x \<partial>lborel" using Mf
hoelzl@62975
   311
    by (subst nn_integral_substitution_aux[OF _ _ derivg contg' derivg_nonneg \<open>a < b\<close>])
lp15@67976
   312
       (auto simp add: mult.commute set_borel_measurable_def)
hoelzl@62975
   313
  also have "... = \<integral>\<^sup>+ x. f (g x) * ennreal (g' x) * indicator {a..b} x \<partial>lborel"
hoelzl@62975
   314
    by (intro nn_integral_cong) (auto split: split_indicator simp: max_def dest: bounds)
hoelzl@62975
   315
  also have "... = \<integral>\<^sup>+x. ennreal (f (g x) * g' x * indicator {a..b} x) \<partial>lborel"
hoelzl@62975
   316
    by (intro nn_integral_cong) (auto simp: mult.commute derivg_nonneg ennreal_mult' split: split_indicator)
hoelzl@59092
   317
  finally show ?thesis .
hoelzl@59092
   318
qed auto
hoelzl@59092
   319
eberlm@69180
   320
theorem integral_substitution:
hoelzl@59092
   321
  assumes integrable: "set_integrable lborel {g a..g b} f"
hoelzl@59092
   322
  assumes derivg: "\<And>x. x \<in> {a..b} \<Longrightarrow> (g has_real_derivative g' x) (at x)"
hoelzl@62975
   323
  assumes contg': "continuous_on {a..b} g'"
hoelzl@59092
   324
  assumes derivg_nonneg: "\<And>x. x \<in> {a..b} \<Longrightarrow> g' x \<ge> 0"
hoelzl@59092
   325
  assumes "a \<le> b"
hoelzl@59092
   326
  shows "set_integrable lborel {a..b} (\<lambda>x. f (g x) * g' x)"
hoelzl@59092
   327
    and "(LBINT x. f x * indicator {g a..g b} x) = (LBINT x. f (g x) * g' x * indicator {a..b} x)"
hoelzl@59092
   328
proof-
hoelzl@59092
   329
  from derivg have contg: "continuous_on {a..b} g" by (rule has_real_derivative_imp_continuous_on)
wenzelm@63540
   330
  with contg' have Mg: "set_borel_measurable borel {a..b} g"
wenzelm@63540
   331
    and Mg': "set_borel_measurable borel {a..b} g'"
wenzelm@63540
   332
    by (simp_all only: set_measurable_continuous_on_ivl)
hoelzl@59092
   333
  from derivg derivg_nonneg have monog: "\<And>x y. a \<le> x \<Longrightarrow> x \<le> y \<Longrightarrow> y \<le> b \<Longrightarrow> g x \<le> g y"
hoelzl@59092
   334
    by (rule deriv_nonneg_imp_mono) simp_all
hoelzl@59092
   335
hoelzl@62975
   336
  have "(\<lambda>x. ennreal (f x) * indicator {g a..g b} x) =
hoelzl@62975
   337
           (\<lambda>x. ennreal (f x * indicator {g a..g b} x))"
hoelzl@59092
   338
    by (intro ext) (simp split: split_indicator)
hoelzl@59092
   339
  with integrable have M1: "(\<lambda>x. f x * indicator {g a..g b} x) \<in> borel_measurable borel"
lp15@67976
   340
    by (force simp: mult.commute set_integrable_def)
hoelzl@62975
   341
  from integrable have M2: "(\<lambda>x. -f x * indicator {g a..g b} x) \<in> borel_measurable borel"
lp15@67976
   342
    by (force simp: mult.commute set_integrable_def)
hoelzl@59092
   343
hoelzl@62975
   344
  have "LBINT x. (f x :: real) * indicator {g a..g b} x =
hoelzl@62975
   345
          enn2real (\<integral>\<^sup>+ x. ennreal (f x) * indicator {g a..g b} x \<partial>lborel) -
hoelzl@62975
   346
          enn2real (\<integral>\<^sup>+ x. ennreal (- (f x)) * indicator {g a..g b} x \<partial>lborel)" using integrable
lp15@67976
   347
    unfolding set_integrable_def
hoelzl@62975
   348
    by (subst real_lebesgue_integral_def) (simp_all add: nn_integral_set_ennreal mult.commute)
wenzelm@63540
   349
  also have *: "(\<integral>\<^sup>+x. ennreal (f x) * indicator {g a..g b} x \<partial>lborel) =
wenzelm@63540
   350
      (\<integral>\<^sup>+x. ennreal (f x * indicator {g a..g b} x) \<partial>lborel)"
hoelzl@59092
   351
    by (intro nn_integral_cong) (simp split: split_indicator)
wenzelm@63540
   352
  also from M1 * have A: "(\<integral>\<^sup>+ x. ennreal (f x * indicator {g a..g b} x) \<partial>lborel) =
hoelzl@62975
   353
                            (\<integral>\<^sup>+ x. ennreal (f (g x) * g' x * indicator {a..b} x) \<partial>lborel)"
hoelzl@62975
   354
    by (subst nn_integral_substitution[OF _ derivg contg' derivg_nonneg \<open>a \<le> b\<close>])
lp15@67976
   355
       (auto simp: nn_integral_set_ennreal mult.commute set_borel_measurable_def)
wenzelm@63540
   356
  also have **: "(\<integral>\<^sup>+ x. ennreal (- (f x)) * indicator {g a..g b} x \<partial>lborel) =
wenzelm@63540
   357
      (\<integral>\<^sup>+ x. ennreal (- (f x) * indicator {g a..g b} x) \<partial>lborel)"
hoelzl@59092
   358
    by (intro nn_integral_cong) (simp split: split_indicator)
wenzelm@63540
   359
  also from M2 ** have B: "(\<integral>\<^sup>+ x. ennreal (- (f x) * indicator {g a..g b} x) \<partial>lborel) =
wenzelm@63540
   360
        (\<integral>\<^sup>+ x. ennreal (- (f (g x)) * g' x * indicator {a..b} x) \<partial>lborel)"
wenzelm@61808
   361
    by (subst nn_integral_substitution[OF _ derivg contg' derivg_nonneg \<open>a \<le> b\<close>])
lp15@67976
   362
       (auto simp: nn_integral_set_ennreal mult.commute set_borel_measurable_def)
hoelzl@59092
   363
hoelzl@59092
   364
  also {
hoelzl@62975
   365
    from integrable have Mf: "set_borel_measurable borel {g a..g b} f"
lp15@67976
   366
      unfolding set_borel_measurable_def set_integrable_def by simp
lp15@67976
   367
    from measurable_compose Mg Mf Mg' borel_measurable_times
lp15@67976
   368
    have "(\<lambda>x. f (g x * indicator {a..b} x) * indicator {g a..g b} (g x * indicator {a..b} x) *
hoelzl@62975
   369
                     (g' x * indicator {a..b} x)) \<in> borel_measurable borel"  (is "?f \<in> _")
lp15@67976
   370
      by (simp add: mult.commute set_borel_measurable_def)
hoelzl@59092
   371
    also have "?f = (\<lambda>x. f (g x) * g' x * indicator {a..b} x)"
hoelzl@59092
   372
      using monog by (intro ext) (auto split: split_indicator)
hoelzl@59092
   373
    finally show "set_integrable lborel {a..b} (\<lambda>x. f (g x) * g' x)"
lp15@67976
   374
      using A B integrable unfolding real_integrable_def set_integrable_def
hoelzl@62975
   375
      by (simp_all add: nn_integral_set_ennreal mult.commute)
hoelzl@59092
   376
  } note integrable' = this
hoelzl@59092
   377
hoelzl@62975
   378
  have "enn2real (\<integral>\<^sup>+ x. ennreal (f (g x) * g' x * indicator {a..b} x) \<partial>lborel) -
hoelzl@62975
   379
                  enn2real (\<integral>\<^sup>+ x. ennreal (-f (g x) * g' x * indicator {a..b} x) \<partial>lborel) =
lp15@67976
   380
                (LBINT x. f (g x) * g' x * indicator {a..b} x)" 
lp15@67976
   381
    using integrable' unfolding set_integrable_def
hoelzl@59092
   382
    by (subst real_lebesgue_integral_def) (simp_all add: field_simps)
hoelzl@62975
   383
  finally show "(LBINT x. f x * indicator {g a..g b} x) =
hoelzl@59092
   384
                     (LBINT x. f (g x) * g' x * indicator {a..b} x)" .
hoelzl@59092
   385
qed
hoelzl@59092
   386
eberlm@69180
   387
theorem interval_integral_substitution:
hoelzl@59092
   388
  assumes integrable: "set_integrable lborel {g a..g b} f"
hoelzl@59092
   389
  assumes derivg: "\<And>x. x \<in> {a..b} \<Longrightarrow> (g has_real_derivative g' x) (at x)"
hoelzl@62975
   390
  assumes contg': "continuous_on {a..b} g'"
hoelzl@59092
   391
  assumes derivg_nonneg: "\<And>x. x \<in> {a..b} \<Longrightarrow> g' x \<ge> 0"
hoelzl@59092
   392
  assumes "a \<le> b"
hoelzl@59092
   393
  shows "set_integrable lborel {a..b} (\<lambda>x. f (g x) * g' x)"
hoelzl@59092
   394
    and "(LBINT x=g a..g b. f x) = (LBINT x=a..b. f (g x) * g' x)"
hoelzl@59092
   395
  apply (rule integral_substitution[OF assms], simp, simp)
hoelzl@59092
   396
  apply (subst (1 2) interval_integral_Icc, fact)
hoelzl@59092
   397
  apply (rule deriv_nonneg_imp_mono[OF derivg derivg_nonneg], simp, simp, fact)
hoelzl@59092
   398
  using integral_substitution(2)[OF assms]
lp15@67976
   399
  apply (simp add: mult.commute set_lebesgue_integral_def)
hoelzl@59092
   400
  done
hoelzl@59092
   401
lp15@67976
   402
lemma set_borel_integrable_singleton[simp]: "set_integrable lborel {x} (f :: real \<Rightarrow> real)"
lp15@67976
   403
  unfolding set_integrable_def
hoelzl@59092
   404
  by (subst integrable_discrete_difference[where X="{x}" and g="\<lambda>_. 0"]) auto
hoelzl@59092
   405
hoelzl@59092
   406
end