src/HOL/Probability/Lebesgue_Integration.thy
author hoelzl
Tue May 13 11:35:47 2014 +0200 (2014-05-13)
changeset 56949 d1a937cbf858
parent 56571 f4635657d66f
permissions -rw-r--r--
clean up Lebesgue integration
hoelzl@42067
     1
(*  Title:      HOL/Probability/Lebesgue_Integration.thy
hoelzl@42067
     2
    Author:     Johannes Hölzl, TU München
hoelzl@42067
     3
    Author:     Armin Heller, TU München
hoelzl@42067
     4
*)
hoelzl@38656
     5
hoelzl@35582
     6
header {*Lebesgue Integration*}
hoelzl@35582
     7
hoelzl@38656
     8
theory Lebesgue_Integration
hoelzl@47694
     9
  imports Measure_Space Borel_Space
hoelzl@35582
    10
begin
hoelzl@35582
    11
hoelzl@56949
    12
lemma indicator_less_ereal[simp]:
hoelzl@56949
    13
  "indicator A x \<le> (indicator B x::ereal) \<longleftrightarrow> (x \<in> A \<longrightarrow> x \<in> B)"
hoelzl@56949
    14
  by (simp add: indicator_def not_le)
hoelzl@41981
    15
hoelzl@38656
    16
section "Simple function"
hoelzl@35582
    17
hoelzl@38656
    18
text {*
hoelzl@38656
    19
hoelzl@38656
    20
Our simple functions are not restricted to positive real numbers. Instead
hoelzl@38656
    21
they are just functions with a finite range and are measurable when singleton
hoelzl@38656
    22
sets are measurable.
hoelzl@35582
    23
hoelzl@38656
    24
*}
hoelzl@38656
    25
hoelzl@41689
    26
definition "simple_function M g \<longleftrightarrow>
hoelzl@38656
    27
    finite (g ` space M) \<and>
hoelzl@38656
    28
    (\<forall>x \<in> g ` space M. g -` {x} \<inter> space M \<in> sets M)"
hoelzl@36624
    29
hoelzl@47694
    30
lemma simple_functionD:
hoelzl@41689
    31
  assumes "simple_function M g"
hoelzl@40875
    32
  shows "finite (g ` space M)" and "g -` X \<inter> space M \<in> sets M"
hoelzl@40871
    33
proof -
hoelzl@40871
    34
  show "finite (g ` space M)"
hoelzl@40871
    35
    using assms unfolding simple_function_def by auto
hoelzl@40875
    36
  have "g -` X \<inter> space M = g -` (X \<inter> g`space M) \<inter> space M" by auto
hoelzl@40875
    37
  also have "\<dots> = (\<Union>x\<in>X \<inter> g`space M. g-`{x} \<inter> space M)" by auto
hoelzl@40875
    38
  finally show "g -` X \<inter> space M \<in> sets M" using assms
hoelzl@50002
    39
    by (auto simp del: UN_simps simp: simple_function_def)
hoelzl@40871
    40
qed
hoelzl@36624
    41
hoelzl@56949
    42
lemma measurable_simple_function[measurable_dest]:
hoelzl@56949
    43
  "simple_function M f \<Longrightarrow> f \<in> measurable M (count_space UNIV)"
hoelzl@56949
    44
  unfolding simple_function_def measurable_def
hoelzl@56949
    45
proof safe
hoelzl@56949
    46
  fix A assume "finite (f ` space M)" "\<forall>x\<in>f ` space M. f -` {x} \<inter> space M \<in> sets M"
hoelzl@56949
    47
  then have "(\<Union>x\<in>f ` space M. if x \<in> A then f -` {x} \<inter> space M else {}) \<in> sets M"
hoelzl@56949
    48
    by (intro sets.finite_UN) auto
hoelzl@56949
    49
  also have "(\<Union>x\<in>f ` space M. if x \<in> A then f -` {x} \<inter> space M else {}) = f -` A \<inter> space M"
hoelzl@56949
    50
    by (auto split: split_if_asm)
hoelzl@56949
    51
  finally show "f -` A \<inter> space M \<in> sets M" .
hoelzl@56949
    52
qed simp
hoelzl@56949
    53
hoelzl@56949
    54
lemma borel_measurable_simple_function:
hoelzl@56949
    55
  "simple_function M f \<Longrightarrow> f \<in> borel_measurable M"
hoelzl@56949
    56
  by (auto dest!: measurable_simple_function simp: measurable_def)
hoelzl@56949
    57
hoelzl@47694
    58
lemma simple_function_measurable2[intro]:
hoelzl@41981
    59
  assumes "simple_function M f" "simple_function M g"
hoelzl@41981
    60
  shows "f -` A \<inter> g -` B \<inter> space M \<in> sets M"
hoelzl@41981
    61
proof -
hoelzl@41981
    62
  have "f -` A \<inter> g -` B \<inter> space M = (f -` A \<inter> space M) \<inter> (g -` B \<inter> space M)"
hoelzl@41981
    63
    by auto
hoelzl@41981
    64
  then show ?thesis using assms[THEN simple_functionD(2)] by auto
hoelzl@41981
    65
qed
hoelzl@41981
    66
hoelzl@47694
    67
lemma simple_function_indicator_representation:
hoelzl@43920
    68
  fixes f ::"'a \<Rightarrow> ereal"
hoelzl@41689
    69
  assumes f: "simple_function M f" and x: "x \<in> space M"
hoelzl@38656
    70
  shows "f x = (\<Sum>y \<in> f ` space M. y * indicator (f -` {y} \<inter> space M) x)"
hoelzl@38656
    71
  (is "?l = ?r")
hoelzl@38656
    72
proof -
hoelzl@38705
    73
  have "?r = (\<Sum>y \<in> f ` space M.
hoelzl@38656
    74
    (if y = f x then y * indicator (f -` {y} \<inter> space M) x else 0))"
hoelzl@38656
    75
    by (auto intro!: setsum_cong2)
hoelzl@38656
    76
  also have "... =  f x *  indicator (f -` {f x} \<inter> space M) x"
hoelzl@38656
    77
    using assms by (auto dest: simple_functionD simp: setsum_delta)
hoelzl@38656
    78
  also have "... = f x" using x by (auto simp: indicator_def)
hoelzl@38656
    79
  finally show ?thesis by auto
hoelzl@38656
    80
qed
hoelzl@36624
    81
hoelzl@47694
    82
lemma simple_function_notspace:
hoelzl@43920
    83
  "simple_function M (\<lambda>x. h x * indicator (- space M) x::ereal)" (is "simple_function M ?h")
hoelzl@35692
    84
proof -
hoelzl@38656
    85
  have "?h ` space M \<subseteq> {0}" unfolding indicator_def by auto
hoelzl@38656
    86
  hence [simp, intro]: "finite (?h ` space M)" by (auto intro: finite_subset)
hoelzl@38656
    87
  have "?h -` {0} \<inter> space M = space M" by auto
hoelzl@38656
    88
  thus ?thesis unfolding simple_function_def by auto
hoelzl@38656
    89
qed
hoelzl@38656
    90
hoelzl@47694
    91
lemma simple_function_cong:
hoelzl@38656
    92
  assumes "\<And>t. t \<in> space M \<Longrightarrow> f t = g t"
hoelzl@41689
    93
  shows "simple_function M f \<longleftrightarrow> simple_function M g"
hoelzl@38656
    94
proof -
hoelzl@38656
    95
  have "f ` space M = g ` space M"
hoelzl@38656
    96
    "\<And>x. f -` {x} \<inter> space M = g -` {x} \<inter> space M"
hoelzl@38656
    97
    using assms by (auto intro!: image_eqI)
hoelzl@38656
    98
  thus ?thesis unfolding simple_function_def using assms by simp
hoelzl@38656
    99
qed
hoelzl@38656
   100
hoelzl@47694
   101
lemma simple_function_cong_algebra:
hoelzl@41689
   102
  assumes "sets N = sets M" "space N = space M"
hoelzl@41689
   103
  shows "simple_function M f \<longleftrightarrow> simple_function N f"
hoelzl@41689
   104
  unfolding simple_function_def assms ..
hoelzl@41689
   105
hoelzl@47694
   106
lemma simple_function_borel_measurable:
hoelzl@41981
   107
  fixes f :: "'a \<Rightarrow> 'x::{t2_space}"
hoelzl@38656
   108
  assumes "f \<in> borel_measurable M" and "finite (f ` space M)"
hoelzl@41689
   109
  shows "simple_function M f"
hoelzl@38656
   110
  using assms unfolding simple_function_def
hoelzl@38656
   111
  by (auto intro: borel_measurable_vimage)
hoelzl@38656
   112
hoelzl@56949
   113
lemma simple_function_eq_measurable:
hoelzl@43920
   114
  fixes f :: "'a \<Rightarrow> ereal"
hoelzl@56949
   115
  shows "simple_function M f \<longleftrightarrow> finite (f`space M) \<and> f \<in> measurable M (count_space UNIV)"
hoelzl@56949
   116
  using simple_function_borel_measurable[of f] measurable_simple_function[of M f]
nipkow@44890
   117
  by (fastforce simp: simple_function_def)
hoelzl@41981
   118
hoelzl@47694
   119
lemma simple_function_const[intro, simp]:
hoelzl@41689
   120
  "simple_function M (\<lambda>x. c)"
hoelzl@38656
   121
  by (auto intro: finite_subset simp: simple_function_def)
hoelzl@47694
   122
lemma simple_function_compose[intro, simp]:
hoelzl@41689
   123
  assumes "simple_function M f"
hoelzl@41689
   124
  shows "simple_function M (g \<circ> f)"
hoelzl@38656
   125
  unfolding simple_function_def
hoelzl@38656
   126
proof safe
hoelzl@38656
   127
  show "finite ((g \<circ> f) ` space M)"
haftmann@56154
   128
    using assms unfolding simple_function_def by (auto simp: image_comp [symmetric])
hoelzl@38656
   129
next
hoelzl@38656
   130
  fix x assume "x \<in> space M"
hoelzl@38656
   131
  let ?G = "g -` {g (f x)} \<inter> (f`space M)"
hoelzl@38656
   132
  have *: "(g \<circ> f) -` {(g \<circ> f) x} \<inter> space M =
hoelzl@38656
   133
    (\<Union>x\<in>?G. f -` {x} \<inter> space M)" by auto
hoelzl@38656
   134
  show "(g \<circ> f) -` {(g \<circ> f) x} \<inter> space M \<in> sets M"
hoelzl@38656
   135
    using assms unfolding simple_function_def *
immler@50244
   136
    by (rule_tac sets.finite_UN) auto
hoelzl@38656
   137
qed
hoelzl@38656
   138
hoelzl@47694
   139
lemma simple_function_indicator[intro, simp]:
hoelzl@38656
   140
  assumes "A \<in> sets M"
hoelzl@41689
   141
  shows "simple_function M (indicator A)"
hoelzl@35692
   142
proof -
hoelzl@38656
   143
  have "indicator A ` space M \<subseteq> {0, 1}" (is "?S \<subseteq> _")
hoelzl@38656
   144
    by (auto simp: indicator_def)
hoelzl@38656
   145
  hence "finite ?S" by (rule finite_subset) simp
hoelzl@38656
   146
  moreover have "- A \<inter> space M = space M - A" by auto
hoelzl@38656
   147
  ultimately show ?thesis unfolding simple_function_def
wenzelm@46905
   148
    using assms by (auto simp: indicator_def [abs_def])
hoelzl@35692
   149
qed
hoelzl@35692
   150
hoelzl@47694
   151
lemma simple_function_Pair[intro, simp]:
hoelzl@41689
   152
  assumes "simple_function M f"
hoelzl@41689
   153
  assumes "simple_function M g"
hoelzl@41689
   154
  shows "simple_function M (\<lambda>x. (f x, g x))" (is "simple_function M ?p")
hoelzl@38656
   155
  unfolding simple_function_def
hoelzl@38656
   156
proof safe
hoelzl@38656
   157
  show "finite (?p ` space M)"
hoelzl@38656
   158
    using assms unfolding simple_function_def
hoelzl@38656
   159
    by (rule_tac finite_subset[of _ "f`space M \<times> g`space M"]) auto
hoelzl@38656
   160
next
hoelzl@38656
   161
  fix x assume "x \<in> space M"
hoelzl@38656
   162
  have "(\<lambda>x. (f x, g x)) -` {(f x, g x)} \<inter> space M =
hoelzl@38656
   163
      (f -` {f x} \<inter> space M) \<inter> (g -` {g x} \<inter> space M)"
hoelzl@38656
   164
    by auto
hoelzl@38656
   165
  with `x \<in> space M` show "(\<lambda>x. (f x, g x)) -` {(f x, g x)} \<inter> space M \<in> sets M"
hoelzl@38656
   166
    using assms unfolding simple_function_def by auto
hoelzl@38656
   167
qed
hoelzl@35692
   168
hoelzl@47694
   169
lemma simple_function_compose1:
hoelzl@41689
   170
  assumes "simple_function M f"
hoelzl@41689
   171
  shows "simple_function M (\<lambda>x. g (f x))"
hoelzl@38656
   172
  using simple_function_compose[OF assms, of g]
hoelzl@38656
   173
  by (simp add: comp_def)
hoelzl@35582
   174
hoelzl@47694
   175
lemma simple_function_compose2:
hoelzl@41689
   176
  assumes "simple_function M f" and "simple_function M g"
hoelzl@41689
   177
  shows "simple_function M (\<lambda>x. h (f x) (g x))"
hoelzl@38656
   178
proof -
hoelzl@41689
   179
  have "simple_function M ((\<lambda>(x, y). h x y) \<circ> (\<lambda>x. (f x, g x)))"
hoelzl@38656
   180
    using assms by auto
hoelzl@38656
   181
  thus ?thesis by (simp_all add: comp_def)
hoelzl@38656
   182
qed
hoelzl@35582
   183
hoelzl@47694
   184
lemmas simple_function_add[intro, simp] = simple_function_compose2[where h="op +"]
hoelzl@38656
   185
  and simple_function_diff[intro, simp] = simple_function_compose2[where h="op -"]
hoelzl@38656
   186
  and simple_function_uminus[intro, simp] = simple_function_compose[where g="uminus"]
hoelzl@38656
   187
  and simple_function_mult[intro, simp] = simple_function_compose2[where h="op *"]
hoelzl@38656
   188
  and simple_function_div[intro, simp] = simple_function_compose2[where h="op /"]
hoelzl@38656
   189
  and simple_function_inverse[intro, simp] = simple_function_compose[where g="inverse"]
hoelzl@41981
   190
  and simple_function_max[intro, simp] = simple_function_compose2[where h=max]
hoelzl@38656
   191
hoelzl@47694
   192
lemma simple_function_setsum[intro, simp]:
hoelzl@41689
   193
  assumes "\<And>i. i \<in> P \<Longrightarrow> simple_function M (f i)"
hoelzl@41689
   194
  shows "simple_function M (\<lambda>x. \<Sum>i\<in>P. f i x)"
hoelzl@38656
   195
proof cases
hoelzl@38656
   196
  assume "finite P" from this assms show ?thesis by induct auto
hoelzl@38656
   197
qed auto
hoelzl@35582
   198
hoelzl@56949
   199
lemma simple_function_ereal[intro, simp]: 
hoelzl@41981
   200
  fixes f g :: "'a \<Rightarrow> real" assumes sf: "simple_function M f"
hoelzl@56949
   201
  shows "simple_function M (\<lambda>x. ereal (f x))"
hoelzl@41981
   202
  by (auto intro!: simple_function_compose1[OF sf])
hoelzl@41981
   203
hoelzl@56949
   204
lemma simple_function_real_of_nat[intro, simp]: 
hoelzl@41981
   205
  fixes f g :: "'a \<Rightarrow> nat" assumes sf: "simple_function M f"
hoelzl@56949
   206
  shows "simple_function M (\<lambda>x. real (f x))"
hoelzl@41981
   207
  by (auto intro!: simple_function_compose1[OF sf])
hoelzl@35582
   208
hoelzl@47694
   209
lemma borel_measurable_implies_simple_function_sequence:
hoelzl@43920
   210
  fixes u :: "'a \<Rightarrow> ereal"
hoelzl@38656
   211
  assumes u: "u \<in> borel_measurable M"
hoelzl@41981
   212
  shows "\<exists>f. incseq f \<and> (\<forall>i. \<infinity> \<notin> range (f i) \<and> simple_function M (f i)) \<and>
hoelzl@41981
   213
             (\<forall>x. (SUP i. f i x) = max 0 (u x)) \<and> (\<forall>i x. 0 \<le> f i x)"
hoelzl@35582
   214
proof -
hoelzl@41981
   215
  def f \<equiv> "\<lambda>x i. if real i \<le> u x then i * 2 ^ i else natfloor (real (u x) * 2 ^ i)"
hoelzl@41981
   216
  { fix x j have "f x j \<le> j * 2 ^ j" unfolding f_def
hoelzl@41981
   217
    proof (split split_if, intro conjI impI)
hoelzl@41981
   218
      assume "\<not> real j \<le> u x"
hoelzl@41981
   219
      then have "natfloor (real (u x) * 2 ^ j) \<le> natfloor (j * 2 ^ j)"
nipkow@56536
   220
         by (cases "u x") (auto intro!: natfloor_mono)
hoelzl@41981
   221
      moreover have "real (natfloor (j * 2 ^ j)) \<le> j * 2^j"
nipkow@56536
   222
        by (intro real_natfloor_le) auto
hoelzl@41981
   223
      ultimately show "natfloor (real (u x) * 2 ^ j) \<le> j * 2 ^ j"
hoelzl@41981
   224
        unfolding real_of_nat_le_iff by auto
hoelzl@41981
   225
    qed auto }
hoelzl@38656
   226
  note f_upper = this
hoelzl@35582
   227
hoelzl@41981
   228
  have real_f:
hoelzl@41981
   229
    "\<And>i x. real (f x i) = (if real i \<le> u x then i * 2 ^ i else real (natfloor (real (u x) * 2 ^ i)))"
hoelzl@41981
   230
    unfolding f_def by auto
hoelzl@35582
   231
wenzelm@46731
   232
  let ?g = "\<lambda>j x. real (f x j) / 2^j :: ereal"
hoelzl@41981
   233
  show ?thesis
hoelzl@41981
   234
  proof (intro exI[of _ ?g] conjI allI ballI)
hoelzl@41981
   235
    fix i
hoelzl@41981
   236
    have "simple_function M (\<lambda>x. real (f x i))"
hoelzl@41981
   237
    proof (intro simple_function_borel_measurable)
hoelzl@41981
   238
      show "(\<lambda>x. real (f x i)) \<in> borel_measurable M"
hoelzl@50021
   239
        using u by (auto simp: real_f)
hoelzl@41981
   240
      have "(\<lambda>x. real (f x i))`space M \<subseteq> real`{..i*2^i}"
hoelzl@41981
   241
        using f_upper[of _ i] by auto
hoelzl@41981
   242
      then show "finite ((\<lambda>x. real (f x i))`space M)"
hoelzl@41981
   243
        by (rule finite_subset) auto
hoelzl@41981
   244
    qed
hoelzl@41981
   245
    then show "simple_function M (?g i)"
hoelzl@43920
   246
      by (auto intro: simple_function_ereal simple_function_div)
hoelzl@41981
   247
  next
hoelzl@41981
   248
    show "incseq ?g"
hoelzl@43920
   249
    proof (intro incseq_ereal incseq_SucI le_funI)
hoelzl@41981
   250
      fix x and i :: nat
hoelzl@41981
   251
      have "f x i * 2 \<le> f x (Suc i)" unfolding f_def
hoelzl@41981
   252
      proof ((split split_if)+, intro conjI impI)
hoelzl@43920
   253
        assume "ereal (real i) \<le> u x" "\<not> ereal (real (Suc i)) \<le> u x"
hoelzl@41981
   254
        then show "i * 2 ^ i * 2 \<le> natfloor (real (u x) * 2 ^ Suc i)"
hoelzl@41981
   255
          by (cases "u x") (auto intro!: le_natfloor)
hoelzl@38656
   256
      next
hoelzl@43920
   257
        assume "\<not> ereal (real i) \<le> u x" "ereal (real (Suc i)) \<le> u x"
hoelzl@41981
   258
        then show "natfloor (real (u x) * 2 ^ i) * 2 \<le> Suc i * 2 ^ Suc i"
hoelzl@41981
   259
          by (cases "u x") auto
hoelzl@41981
   260
      next
hoelzl@43920
   261
        assume "\<not> ereal (real i) \<le> u x" "\<not> ereal (real (Suc i)) \<le> u x"
hoelzl@41981
   262
        have "natfloor (real (u x) * 2 ^ i) * 2 = natfloor (real (u x) * 2 ^ i) * natfloor 2"
hoelzl@41981
   263
          by simp
hoelzl@41981
   264
        also have "\<dots> \<le> natfloor (real (u x) * 2 ^ i * 2)"
hoelzl@41981
   265
        proof cases
hoelzl@41981
   266
          assume "0 \<le> u x" then show ?thesis
bulwahn@46671
   267
            by (intro le_mult_natfloor) 
hoelzl@41981
   268
        next
hoelzl@41981
   269
          assume "\<not> 0 \<le> u x" then show ?thesis
hoelzl@41981
   270
            by (cases "u x") (auto simp: natfloor_neg mult_nonpos_nonneg)
hoelzl@38656
   271
        qed
hoelzl@41981
   272
        also have "\<dots> = natfloor (real (u x) * 2 ^ Suc i)"
hoelzl@41981
   273
          by (simp add: ac_simps)
hoelzl@41981
   274
        finally show "natfloor (real (u x) * 2 ^ i) * 2 \<le> natfloor (real (u x) * 2 ^ Suc i)" .
hoelzl@41981
   275
      qed simp
hoelzl@41981
   276
      then show "?g i x \<le> ?g (Suc i) x"
hoelzl@41981
   277
        by (auto simp: field_simps)
hoelzl@35582
   278
    qed
hoelzl@38656
   279
  next
hoelzl@41981
   280
    fix x show "(SUP i. ?g i x) = max 0 (u x)"
hoelzl@51000
   281
    proof (rule SUP_eqI)
hoelzl@41981
   282
      fix i show "?g i x \<le> max 0 (u x)" unfolding max_def f_def
hoelzl@41981
   283
        by (cases "u x") (auto simp: field_simps real_natfloor_le natfloor_neg
nipkow@56536
   284
                                     mult_nonpos_nonneg)
hoelzl@41981
   285
    next
hoelzl@41981
   286
      fix y assume *: "\<And>i. i \<in> UNIV \<Longrightarrow> ?g i x \<le> y"
hoelzl@56571
   287
      have "\<And>i. 0 \<le> ?g i x" by auto
hoelzl@41981
   288
      from order_trans[OF this *] have "0 \<le> y" by simp
hoelzl@41981
   289
      show "max 0 (u x) \<le> y"
hoelzl@41981
   290
      proof (cases y)
hoelzl@41981
   291
        case (real r)
hoelzl@41981
   292
        with * have *: "\<And>i. f x i \<le> r * 2^i" by (auto simp: divide_le_eq)
huffman@44666
   293
        from reals_Archimedean2[of r] * have "u x \<noteq> \<infinity>" by (auto simp: f_def) (metis less_le_not_le)
hoelzl@43920
   294
        then have "\<exists>p. max 0 (u x) = ereal p \<and> 0 \<le> p" by (cases "u x") (auto simp: max_def)
hoelzl@41981
   295
        then guess p .. note ux = this
huffman@44666
   296
        obtain m :: nat where m: "p < real m" using reals_Archimedean2 ..
hoelzl@41981
   297
        have "p \<le> r"
hoelzl@41981
   298
        proof (rule ccontr)
hoelzl@41981
   299
          assume "\<not> p \<le> r"
hoelzl@41981
   300
          with LIMSEQ_inverse_realpow_zero[unfolded LIMSEQ_iff, rule_format, of 2 "p - r"]
nipkow@56536
   301
          obtain N where "\<forall>n\<ge>N. r * 2^n < p * 2^n - 1" by (auto simp: field_simps)
hoelzl@41981
   302
          then have "r * 2^max N m < p * 2^max N m - 1" by simp
hoelzl@41981
   303
          moreover
hoelzl@41981
   304
          have "real (natfloor (p * 2 ^ max N m)) \<le> r * 2 ^ max N m"
hoelzl@41981
   305
            using *[of "max N m"] m unfolding real_f using ux
nipkow@56536
   306
            by (cases "0 \<le> u x") (simp_all add: max_def split: split_if_asm)
hoelzl@41981
   307
          then have "p * 2 ^ max N m - 1 < r * 2 ^ max N m"
hoelzl@41981
   308
            by (metis real_natfloor_gt_diff_one less_le_trans)
hoelzl@41981
   309
          ultimately show False by auto
hoelzl@38656
   310
        qed
hoelzl@41981
   311
        then show "max 0 (u x) \<le> y" using real ux by simp
hoelzl@41981
   312
      qed (insert `0 \<le> y`, auto)
hoelzl@41981
   313
    qed
hoelzl@56571
   314
  qed auto
hoelzl@41981
   315
qed
hoelzl@35582
   316
hoelzl@47694
   317
lemma borel_measurable_implies_simple_function_sequence':
hoelzl@43920
   318
  fixes u :: "'a \<Rightarrow> ereal"
hoelzl@41981
   319
  assumes u: "u \<in> borel_measurable M"
hoelzl@41981
   320
  obtains f where "\<And>i. simple_function M (f i)" "incseq f" "\<And>i. \<infinity> \<notin> range (f i)"
hoelzl@41981
   321
    "\<And>x. (SUP i. f i x) = max 0 (u x)" "\<And>i x. 0 \<le> f i x"
hoelzl@41981
   322
  using borel_measurable_implies_simple_function_sequence[OF u] by auto
hoelzl@41981
   323
hoelzl@49796
   324
lemma simple_function_induct[consumes 1, case_names cong set mult add, induct set: simple_function]:
hoelzl@49796
   325
  fixes u :: "'a \<Rightarrow> ereal"
hoelzl@49796
   326
  assumes u: "simple_function M u"
hoelzl@49796
   327
  assumes cong: "\<And>f g. simple_function M f \<Longrightarrow> simple_function M g \<Longrightarrow> (AE x in M. f x = g x) \<Longrightarrow> P f \<Longrightarrow> P g"
hoelzl@49796
   328
  assumes set: "\<And>A. A \<in> sets M \<Longrightarrow> P (indicator A)"
hoelzl@49796
   329
  assumes mult: "\<And>u c. P u \<Longrightarrow> P (\<lambda>x. c * u x)"
hoelzl@49796
   330
  assumes add: "\<And>u v. P u \<Longrightarrow> P v \<Longrightarrow> P (\<lambda>x. v x + u x)"
hoelzl@49796
   331
  shows "P u"
hoelzl@49796
   332
proof (rule cong)
hoelzl@49796
   333
  from AE_space show "AE x in M. (\<Sum>y\<in>u ` space M. y * indicator (u -` {y} \<inter> space M) x) = u x"
hoelzl@49796
   334
  proof eventually_elim
hoelzl@49796
   335
    fix x assume x: "x \<in> space M"
hoelzl@49796
   336
    from simple_function_indicator_representation[OF u x]
hoelzl@49796
   337
    show "(\<Sum>y\<in>u ` space M. y * indicator (u -` {y} \<inter> space M) x) = u x" ..
hoelzl@49796
   338
  qed
hoelzl@49796
   339
next
hoelzl@49796
   340
  from u have "finite (u ` space M)"
hoelzl@49796
   341
    unfolding simple_function_def by auto
hoelzl@49796
   342
  then show "P (\<lambda>x. \<Sum>y\<in>u ` space M. y * indicator (u -` {y} \<inter> space M) x)"
hoelzl@49796
   343
  proof induct
hoelzl@49796
   344
    case empty show ?case
hoelzl@49796
   345
      using set[of "{}"] by (simp add: indicator_def[abs_def])
hoelzl@49796
   346
  qed (auto intro!: add mult set simple_functionD u)
hoelzl@49796
   347
next
hoelzl@49796
   348
  show "simple_function M (\<lambda>x. (\<Sum>y\<in>u ` space M. y * indicator (u -` {y} \<inter> space M) x))"
hoelzl@49796
   349
    apply (subst simple_function_cong)
hoelzl@49796
   350
    apply (rule simple_function_indicator_representation[symmetric])
hoelzl@49796
   351
    apply (auto intro: u)
hoelzl@49796
   352
    done
hoelzl@49796
   353
qed fact
hoelzl@49796
   354
hoelzl@49796
   355
lemma simple_function_induct_nn[consumes 2, case_names cong set mult add]:
hoelzl@49796
   356
  fixes u :: "'a \<Rightarrow> ereal"
hoelzl@49799
   357
  assumes u: "simple_function M u" and nn: "\<And>x. 0 \<le> u x"
hoelzl@49799
   358
  assumes cong: "\<And>f g. simple_function M f \<Longrightarrow> simple_function M g \<Longrightarrow> (\<And>x. x \<in> space M \<Longrightarrow> f x = g x) \<Longrightarrow> P f \<Longrightarrow> P g"
hoelzl@49796
   359
  assumes set: "\<And>A. A \<in> sets M \<Longrightarrow> P (indicator A)"
hoelzl@49797
   360
  assumes mult: "\<And>u c. 0 \<le> c \<Longrightarrow> simple_function M u \<Longrightarrow> (\<And>x. 0 \<le> u x) \<Longrightarrow> P u \<Longrightarrow> P (\<lambda>x. c * u x)"
hoelzl@49797
   361
  assumes add: "\<And>u v. simple_function M u \<Longrightarrow> (\<And>x. 0 \<le> u x) \<Longrightarrow> P u \<Longrightarrow> simple_function M v \<Longrightarrow> (\<And>x. 0 \<le> v x) \<Longrightarrow> P v \<Longrightarrow> P (\<lambda>x. v x + u x)"
hoelzl@49796
   362
  shows "P u"
hoelzl@49796
   363
proof -
hoelzl@49796
   364
  show ?thesis
hoelzl@49796
   365
  proof (rule cong)
hoelzl@49799
   366
    fix x assume x: "x \<in> space M"
hoelzl@49799
   367
    from simple_function_indicator_representation[OF u x]
hoelzl@49799
   368
    show "(\<Sum>y\<in>u ` space M. y * indicator (u -` {y} \<inter> space M) x) = u x" ..
hoelzl@49796
   369
  next
hoelzl@49799
   370
    show "simple_function M (\<lambda>x. (\<Sum>y\<in>u ` space M. y * indicator (u -` {y} \<inter> space M) x))"
hoelzl@49796
   371
      apply (subst simple_function_cong)
hoelzl@49796
   372
      apply (rule simple_function_indicator_representation[symmetric])
hoelzl@49799
   373
      apply (auto intro: u)
hoelzl@49796
   374
      done
hoelzl@49796
   375
  next
hoelzl@49799
   376
    from u nn have "finite (u ` space M)" "\<And>x. x \<in> u ` space M \<Longrightarrow> 0 \<le> x"
hoelzl@49796
   377
      unfolding simple_function_def by auto
hoelzl@49799
   378
    then show "P (\<lambda>x. \<Sum>y\<in>u ` space M. y * indicator (u -` {y} \<inter> space M) x)"
hoelzl@49796
   379
    proof induct
hoelzl@49796
   380
      case empty show ?case
hoelzl@49796
   381
        using set[of "{}"] by (simp add: indicator_def[abs_def])
hoelzl@49799
   382
    qed (auto intro!: add mult set simple_functionD u setsum_nonneg
hoelzl@49797
   383
       simple_function_setsum)
hoelzl@49796
   384
  qed fact
hoelzl@49796
   385
qed
hoelzl@49796
   386
hoelzl@49796
   387
lemma borel_measurable_induct[consumes 2, case_names cong set mult add seq, induct set: borel_measurable]:
hoelzl@49796
   388
  fixes u :: "'a \<Rightarrow> ereal"
hoelzl@49799
   389
  assumes u: "u \<in> borel_measurable M" "\<And>x. 0 \<le> u x"
hoelzl@49799
   390
  assumes cong: "\<And>f g. f \<in> borel_measurable M \<Longrightarrow> g \<in> borel_measurable M \<Longrightarrow> (\<And>x. x \<in> space M \<Longrightarrow> f x = g x) \<Longrightarrow> P g \<Longrightarrow> P f"
hoelzl@49796
   391
  assumes set: "\<And>A. A \<in> sets M \<Longrightarrow> P (indicator A)"
hoelzl@49797
   392
  assumes mult: "\<And>u c. 0 \<le> c \<Longrightarrow> u \<in> borel_measurable M \<Longrightarrow> (\<And>x. 0 \<le> u x) \<Longrightarrow> P u \<Longrightarrow> P (\<lambda>x. c * u x)"
hoelzl@49797
   393
  assumes add: "\<And>u v. u \<in> borel_measurable M \<Longrightarrow> (\<And>x. 0 \<le> u x) \<Longrightarrow> P u \<Longrightarrow> v \<in> borel_measurable M \<Longrightarrow> (\<And>x. 0 \<le> v x) \<Longrightarrow> P v \<Longrightarrow> P (\<lambda>x. v x + u x)"
hoelzl@49797
   394
  assumes seq: "\<And>U. (\<And>i. U i \<in> borel_measurable M) \<Longrightarrow>  (\<And>i x. 0 \<le> U i x) \<Longrightarrow>  (\<And>i. P (U i)) \<Longrightarrow> incseq U \<Longrightarrow> P (SUP i. U i)"
hoelzl@49796
   395
  shows "P u"
hoelzl@49796
   396
  using u
hoelzl@49796
   397
proof (induct rule: borel_measurable_implies_simple_function_sequence')
hoelzl@49797
   398
  fix U assume U: "\<And>i. simple_function M (U i)" "incseq U" "\<And>i. \<infinity> \<notin> range (U i)" and
hoelzl@49796
   399
    sup: "\<And>x. (SUP i. U i x) = max 0 (u x)" and nn: "\<And>i x. 0 \<le> U i x"
hoelzl@49799
   400
  have u_eq: "u = (SUP i. U i)"
hoelzl@49796
   401
    using nn u sup by (auto simp: max_def)
hoelzl@49796
   402
  
hoelzl@49797
   403
  from U have "\<And>i. U i \<in> borel_measurable M"
hoelzl@49797
   404
    by (simp add: borel_measurable_simple_function)
hoelzl@49797
   405
hoelzl@49799
   406
  show "P u"
hoelzl@49796
   407
    unfolding u_eq
hoelzl@49796
   408
  proof (rule seq)
hoelzl@49796
   409
    fix i show "P (U i)"
hoelzl@49799
   410
      using `simple_function M (U i)` nn
hoelzl@49796
   411
      by (induct rule: simple_function_induct_nn)
hoelzl@49796
   412
         (auto intro: set mult add cong dest!: borel_measurable_simple_function)
hoelzl@49797
   413
  qed fact+
hoelzl@49796
   414
qed
hoelzl@49796
   415
hoelzl@47694
   416
lemma simple_function_If_set:
hoelzl@41981
   417
  assumes sf: "simple_function M f" "simple_function M g" and A: "A \<inter> space M \<in> sets M"
hoelzl@41981
   418
  shows "simple_function M (\<lambda>x. if x \<in> A then f x else g x)" (is "simple_function M ?IF")
hoelzl@41981
   419
proof -
hoelzl@41981
   420
  def F \<equiv> "\<lambda>x. f -` {x} \<inter> space M" and G \<equiv> "\<lambda>x. g -` {x} \<inter> space M"
hoelzl@41981
   421
  show ?thesis unfolding simple_function_def
hoelzl@41981
   422
  proof safe
hoelzl@41981
   423
    have "?IF ` space M \<subseteq> f ` space M \<union> g ` space M" by auto
hoelzl@41981
   424
    from finite_subset[OF this] assms
hoelzl@41981
   425
    show "finite (?IF ` space M)" unfolding simple_function_def by auto
hoelzl@41981
   426
  next
hoelzl@41981
   427
    fix x assume "x \<in> space M"
hoelzl@41981
   428
    then have *: "?IF -` {?IF x} \<inter> space M = (if x \<in> A
hoelzl@41981
   429
      then ((F (f x) \<inter> (A \<inter> space M)) \<union> (G (f x) - (G (f x) \<inter> (A \<inter> space M))))
hoelzl@41981
   430
      else ((F (g x) \<inter> (A \<inter> space M)) \<union> (G (g x) - (G (g x) \<inter> (A \<inter> space M)))))"
immler@50244
   431
      using sets.sets_into_space[OF A] by (auto split: split_if_asm simp: G_def F_def)
hoelzl@41981
   432
    have [intro]: "\<And>x. F x \<in> sets M" "\<And>x. G x \<in> sets M"
hoelzl@41981
   433
      unfolding F_def G_def using sf[THEN simple_functionD(2)] by auto
hoelzl@41981
   434
    show "?IF -` {?IF x} \<inter> space M \<in> sets M" unfolding * using A by auto
hoelzl@35582
   435
  qed
hoelzl@35582
   436
qed
hoelzl@35582
   437
hoelzl@47694
   438
lemma simple_function_If:
hoelzl@41981
   439
  assumes sf: "simple_function M f" "simple_function M g" and P: "{x\<in>space M. P x} \<in> sets M"
hoelzl@41981
   440
  shows "simple_function M (\<lambda>x. if P x then f x else g x)"
hoelzl@35582
   441
proof -
hoelzl@41981
   442
  have "{x\<in>space M. P x} = {x. P x} \<inter> space M" by auto
hoelzl@41981
   443
  with simple_function_If_set[OF sf, of "{x. P x}"] P show ?thesis by simp
hoelzl@38656
   444
qed
hoelzl@38656
   445
hoelzl@47694
   446
lemma simple_function_subalgebra:
hoelzl@41689
   447
  assumes "simple_function N f"
hoelzl@41689
   448
  and N_subalgebra: "sets N \<subseteq> sets M" "space N = space M"
hoelzl@41689
   449
  shows "simple_function M f"
hoelzl@41689
   450
  using assms unfolding simple_function_def by auto
hoelzl@39092
   451
hoelzl@47694
   452
lemma simple_function_comp:
hoelzl@47694
   453
  assumes T: "T \<in> measurable M M'"
hoelzl@41689
   454
    and f: "simple_function M' f"
hoelzl@41689
   455
  shows "simple_function M (\<lambda>x. f (T x))"
hoelzl@41661
   456
proof (intro simple_function_def[THEN iffD2] conjI ballI)
hoelzl@41661
   457
  have "(\<lambda>x. f (T x)) ` space M \<subseteq> f ` space M'"
hoelzl@41661
   458
    using T unfolding measurable_def by auto
hoelzl@41661
   459
  then show "finite ((\<lambda>x. f (T x)) ` space M)"
hoelzl@41689
   460
    using f unfolding simple_function_def by (auto intro: finite_subset)
hoelzl@41661
   461
  fix i assume i: "i \<in> (\<lambda>x. f (T x)) ` space M"
hoelzl@41661
   462
  then have "i \<in> f ` space M'"
hoelzl@41661
   463
    using T unfolding measurable_def by auto
hoelzl@41661
   464
  then have "f -` {i} \<inter> space M' \<in> sets M'"
hoelzl@41689
   465
    using f unfolding simple_function_def by auto
hoelzl@41661
   466
  then have "T -` (f -` {i} \<inter> space M') \<inter> space M \<in> sets M"
hoelzl@41661
   467
    using T unfolding measurable_def by auto
hoelzl@41661
   468
  also have "T -` (f -` {i} \<inter> space M') \<inter> space M = (\<lambda>x. f (T x)) -` {i} \<inter> space M"
hoelzl@41661
   469
    using T unfolding measurable_def by auto
hoelzl@41661
   470
  finally show "(\<lambda>x. f (T x)) -` {i} \<inter> space M \<in> sets M" .
hoelzl@40859
   471
qed
hoelzl@40859
   472
hoelzl@38656
   473
section "Simple integral"
hoelzl@38656
   474
wenzelm@53015
   475
definition simple_integral :: "'a measure \<Rightarrow> ('a \<Rightarrow> ereal) \<Rightarrow> ereal" ("integral\<^sup>S") where
wenzelm@53015
   476
  "integral\<^sup>S M f = (\<Sum>x \<in> f ` space M. x * emeasure M (f -` {x} \<inter> space M))"
hoelzl@41689
   477
hoelzl@41689
   478
syntax
wenzelm@53015
   479
  "_simple_integral" :: "pttrn \<Rightarrow> ereal \<Rightarrow> 'a measure \<Rightarrow> ereal" ("\<integral>\<^sup>S _. _ \<partial>_" [60,61] 110)
hoelzl@41689
   480
hoelzl@41689
   481
translations
wenzelm@53015
   482
  "\<integral>\<^sup>S x. f \<partial>M" == "CONST simple_integral M (%x. f)"
hoelzl@35582
   483
hoelzl@47694
   484
lemma simple_integral_cong:
hoelzl@38656
   485
  assumes "\<And>t. t \<in> space M \<Longrightarrow> f t = g t"
wenzelm@53015
   486
  shows "integral\<^sup>S M f = integral\<^sup>S M g"
hoelzl@38656
   487
proof -
hoelzl@38656
   488
  have "f ` space M = g ` space M"
hoelzl@38656
   489
    "\<And>x. f -` {x} \<inter> space M = g -` {x} \<inter> space M"
hoelzl@38656
   490
    using assms by (auto intro!: image_eqI)
hoelzl@38656
   491
  thus ?thesis unfolding simple_integral_def by simp
hoelzl@38656
   492
qed
hoelzl@38656
   493
hoelzl@47694
   494
lemma simple_integral_const[simp]:
wenzelm@53015
   495
  "(\<integral>\<^sup>Sx. c \<partial>M) = c * (emeasure M) (space M)"
hoelzl@38656
   496
proof (cases "space M = {}")
hoelzl@38656
   497
  case True thus ?thesis unfolding simple_integral_def by simp
hoelzl@38656
   498
next
hoelzl@38656
   499
  case False hence "(\<lambda>x. c) ` space M = {c}" by auto
hoelzl@38656
   500
  thus ?thesis unfolding simple_integral_def by simp
hoelzl@35582
   501
qed
hoelzl@35582
   502
hoelzl@47694
   503
lemma simple_function_partition:
hoelzl@41981
   504
  assumes f: "simple_function M f" and g: "simple_function M g"
hoelzl@56949
   505
  assumes sub: "\<And>x y. x \<in> space M \<Longrightarrow> y \<in> space M \<Longrightarrow> g x = g y \<Longrightarrow> f x = f y"
hoelzl@56949
   506
  assumes v: "\<And>x. x \<in> space M \<Longrightarrow> f x = v (g x)"
hoelzl@56949
   507
  shows "integral\<^sup>S M f = (\<Sum>y\<in>g ` space M. v y * emeasure M {x\<in>space M. g x = y})"
hoelzl@56949
   508
    (is "_ = ?r")
hoelzl@56949
   509
proof -
hoelzl@56949
   510
  from f g have [simp]: "finite (f`space M)" "finite (g`space M)"
hoelzl@56949
   511
    by (auto simp: simple_function_def)
hoelzl@56949
   512
  from f g have [measurable]: "f \<in> measurable M (count_space UNIV)" "g \<in> measurable M (count_space UNIV)"
hoelzl@56949
   513
    by (auto intro: measurable_simple_function)
hoelzl@35582
   514
hoelzl@56949
   515
  { fix y assume "y \<in> space M"
hoelzl@56949
   516
    then have "f ` space M \<inter> {i. \<exists>x\<in>space M. i = f x \<and> g y = g x} = {v (g y)}"
hoelzl@56949
   517
      by (auto cong: sub simp: v[symmetric]) }
hoelzl@56949
   518
  note eq = this
hoelzl@35582
   519
hoelzl@56949
   520
  have "integral\<^sup>S M f =
hoelzl@56949
   521
    (\<Sum>y\<in>f`space M. y * (\<Sum>z\<in>g`space M. 
hoelzl@56949
   522
      if \<exists>x\<in>space M. y = f x \<and> z = g x then emeasure M {x\<in>space M. g x = z} else 0))"
hoelzl@56949
   523
    unfolding simple_integral_def
hoelzl@56949
   524
  proof (safe intro!: setsum_cong ereal_left_mult_cong)
hoelzl@56949
   525
    fix y assume y: "y \<in> space M" "f y \<noteq> 0"
hoelzl@56949
   526
    have [simp]: "g ` space M \<inter> {z. \<exists>x\<in>space M. f y = f x \<and> z = g x} = 
hoelzl@56949
   527
        {z. \<exists>x\<in>space M. f y = f x \<and> z = g x}"
hoelzl@56949
   528
      by auto
hoelzl@56949
   529
    have eq:"(\<Union>i\<in>{z. \<exists>x\<in>space M. f y = f x \<and> z = g x}. {x \<in> space M. g x = i}) =
hoelzl@56949
   530
        f -` {f y} \<inter> space M"
hoelzl@56949
   531
      by (auto simp: eq_commute cong: sub rev_conj_cong)
hoelzl@56949
   532
    have "finite (g`space M)" by simp
hoelzl@56949
   533
    then have "finite {z. \<exists>x\<in>space M. f y = f x \<and> z = g x}"
hoelzl@56949
   534
      by (rule rev_finite_subset) auto
hoelzl@56949
   535
    then show "emeasure M (f -` {f y} \<inter> space M) =
hoelzl@56949
   536
      (\<Sum>z\<in>g ` space M. if \<exists>x\<in>space M. f y = f x \<and> z = g x then emeasure M {x \<in> space M. g x = z} else 0)"
hoelzl@56949
   537
      apply (simp add: setsum_cases)
hoelzl@56949
   538
      apply (subst setsum_emeasure)
hoelzl@56949
   539
      apply (auto simp: disjoint_family_on_def eq)
hoelzl@56949
   540
      done
hoelzl@38656
   541
  qed
hoelzl@56949
   542
  also have "\<dots> = (\<Sum>y\<in>f`space M. (\<Sum>z\<in>g`space M. 
hoelzl@56949
   543
      if \<exists>x\<in>space M. y = f x \<and> z = g x then y * emeasure M {x\<in>space M. g x = z} else 0))"
hoelzl@56949
   544
    by (auto intro!: setsum_cong simp: setsum_ereal_right_distrib emeasure_nonneg)
hoelzl@56949
   545
  also have "\<dots> = ?r"
hoelzl@56949
   546
    by (subst setsum_commute)
hoelzl@56949
   547
       (auto intro!: setsum_cong simp: setsum_cases scaleR_setsum_right[symmetric] eq)
hoelzl@56949
   548
  finally show "integral\<^sup>S M f = ?r" .
hoelzl@35582
   549
qed
hoelzl@35582
   550
hoelzl@47694
   551
lemma simple_integral_add[simp]:
hoelzl@41981
   552
  assumes f: "simple_function M f" and "\<And>x. 0 \<le> f x" and g: "simple_function M g" and "\<And>x. 0 \<le> g x"
wenzelm@53015
   553
  shows "(\<integral>\<^sup>Sx. f x + g x \<partial>M) = integral\<^sup>S M f + integral\<^sup>S M g"
hoelzl@35582
   554
proof -
hoelzl@56949
   555
  have "(\<integral>\<^sup>Sx. f x + g x \<partial>M) =
hoelzl@56949
   556
    (\<Sum>y\<in>(\<lambda>x. (f x, g x))`space M. (fst y + snd y) * emeasure M {x\<in>space M. (f x, g x) = y})"
hoelzl@56949
   557
    by (intro simple_function_partition) (auto intro: f g)
hoelzl@56949
   558
  also have "\<dots> = (\<Sum>y\<in>(\<lambda>x. (f x, g x))`space M. fst y * emeasure M {x\<in>space M. (f x, g x) = y}) +
hoelzl@56949
   559
    (\<Sum>y\<in>(\<lambda>x. (f x, g x))`space M. snd y * emeasure M {x\<in>space M. (f x, g x) = y})"
hoelzl@56949
   560
    using assms(2,4) by (auto intro!: setsum_cong ereal_left_distrib simp: setsum_addf[symmetric])
hoelzl@56949
   561
  also have "(\<Sum>y\<in>(\<lambda>x. (f x, g x))`space M. fst y * emeasure M {x\<in>space M. (f x, g x) = y}) = (\<integral>\<^sup>Sx. f x \<partial>M)"
hoelzl@56949
   562
    by (intro simple_function_partition[symmetric]) (auto intro: f g)
hoelzl@56949
   563
  also have "(\<Sum>y\<in>(\<lambda>x. (f x, g x))`space M. snd y * emeasure M {x\<in>space M. (f x, g x) = y}) = (\<integral>\<^sup>Sx. g x \<partial>M)"
hoelzl@56949
   564
    by (intro simple_function_partition[symmetric]) (auto intro: f g)
hoelzl@56949
   565
  finally show ?thesis .
hoelzl@35582
   566
qed
hoelzl@35582
   567
hoelzl@47694
   568
lemma simple_integral_setsum[simp]:
hoelzl@41981
   569
  assumes "\<And>i x. i \<in> P \<Longrightarrow> 0 \<le> f i x"
hoelzl@41689
   570
  assumes "\<And>i. i \<in> P \<Longrightarrow> simple_function M (f i)"
wenzelm@53015
   571
  shows "(\<integral>\<^sup>Sx. (\<Sum>i\<in>P. f i x) \<partial>M) = (\<Sum>i\<in>P. integral\<^sup>S M (f i))"
hoelzl@38656
   572
proof cases
hoelzl@38656
   573
  assume "finite P"
hoelzl@38656
   574
  from this assms show ?thesis
hoelzl@41981
   575
    by induct (auto simp: simple_function_setsum simple_integral_add setsum_nonneg)
hoelzl@38656
   576
qed auto
hoelzl@38656
   577
hoelzl@47694
   578
lemma simple_integral_mult[simp]:
hoelzl@41981
   579
  assumes f: "simple_function M f" "\<And>x. 0 \<le> f x"
wenzelm@53015
   580
  shows "(\<integral>\<^sup>Sx. c * f x \<partial>M) = c * integral\<^sup>S M f"
hoelzl@38656
   581
proof -
hoelzl@56949
   582
  have "(\<integral>\<^sup>Sx. c * f x \<partial>M) = (\<Sum>y\<in>f ` space M. (c * y) * emeasure M {x\<in>space M. f x = y})"
hoelzl@56949
   583
    using f by (intro simple_function_partition) auto
hoelzl@56949
   584
  also have "\<dots> = c * integral\<^sup>S M f"
hoelzl@56949
   585
    using f unfolding simple_integral_def
hoelzl@56949
   586
    by (subst setsum_ereal_right_distrib) (auto simp: emeasure_nonneg mult_assoc Int_def conj_commute)
hoelzl@56949
   587
  finally show ?thesis .
hoelzl@40871
   588
qed
hoelzl@40871
   589
hoelzl@47694
   590
lemma simple_integral_mono_AE:
hoelzl@56949
   591
  assumes f[measurable]: "simple_function M f" and g[measurable]: "simple_function M g"
hoelzl@47694
   592
  and mono: "AE x in M. f x \<le> g x"
wenzelm@53015
   593
  shows "integral\<^sup>S M f \<le> integral\<^sup>S M g"
hoelzl@40859
   594
proof -
hoelzl@56949
   595
  let ?\<mu> = "\<lambda>P. emeasure M {x\<in>space M. P x}"
hoelzl@56949
   596
  have "integral\<^sup>S M f = (\<Sum>y\<in>(\<lambda>x. (f x, g x))`space M. fst y * ?\<mu> (\<lambda>x. (f x, g x) = y))"
hoelzl@56949
   597
    using f g by (intro simple_function_partition) auto
hoelzl@56949
   598
  also have "\<dots> \<le> (\<Sum>y\<in>(\<lambda>x. (f x, g x))`space M. snd y * ?\<mu> (\<lambda>x. (f x, g x) = y))"
hoelzl@56949
   599
  proof (clarsimp intro!: setsum_mono)
hoelzl@40859
   600
    fix x assume "x \<in> space M"
hoelzl@56949
   601
    let ?M = "?\<mu> (\<lambda>y. f y = f x \<and> g y = g x)"
hoelzl@56949
   602
    show "f x * ?M \<le> g x * ?M"
hoelzl@56949
   603
    proof cases
hoelzl@56949
   604
      assume "?M \<noteq> 0"
hoelzl@56949
   605
      then have "0 < ?M"
hoelzl@56949
   606
        by (simp add: less_le emeasure_nonneg)
hoelzl@56949
   607
      also have "\<dots> \<le> ?\<mu> (\<lambda>y. f x \<le> g x)"
hoelzl@56949
   608
        using mono by (intro emeasure_mono_AE) auto
hoelzl@56949
   609
      finally have "\<not> \<not> f x \<le> g x"
hoelzl@56949
   610
        by (intro notI) auto
hoelzl@56949
   611
      then show ?thesis
hoelzl@56949
   612
        by (intro ereal_mult_right_mono) auto
hoelzl@56949
   613
    qed simp
hoelzl@40859
   614
  qed
hoelzl@56949
   615
  also have "\<dots> = integral\<^sup>S M g"
hoelzl@56949
   616
    using f g by (intro simple_function_partition[symmetric]) auto
hoelzl@56949
   617
  finally show ?thesis .
hoelzl@40859
   618
qed
hoelzl@40859
   619
hoelzl@47694
   620
lemma simple_integral_mono:
hoelzl@41689
   621
  assumes "simple_function M f" and "simple_function M g"
hoelzl@38656
   622
  and mono: "\<And> x. x \<in> space M \<Longrightarrow> f x \<le> g x"
wenzelm@53015
   623
  shows "integral\<^sup>S M f \<le> integral\<^sup>S M g"
hoelzl@41705
   624
  using assms by (intro simple_integral_mono_AE) auto
hoelzl@35582
   625
hoelzl@47694
   626
lemma simple_integral_cong_AE:
hoelzl@41981
   627
  assumes "simple_function M f" and "simple_function M g"
hoelzl@47694
   628
  and "AE x in M. f x = g x"
wenzelm@53015
   629
  shows "integral\<^sup>S M f = integral\<^sup>S M g"
hoelzl@40859
   630
  using assms by (auto simp: eq_iff intro!: simple_integral_mono_AE)
hoelzl@40859
   631
hoelzl@47694
   632
lemma simple_integral_cong':
hoelzl@41689
   633
  assumes sf: "simple_function M f" "simple_function M g"
hoelzl@47694
   634
  and mea: "(emeasure M) {x\<in>space M. f x \<noteq> g x} = 0"
wenzelm@53015
   635
  shows "integral\<^sup>S M f = integral\<^sup>S M g"
hoelzl@40859
   636
proof (intro simple_integral_cong_AE sf AE_I)
hoelzl@47694
   637
  show "(emeasure M) {x\<in>space M. f x \<noteq> g x} = 0" by fact
hoelzl@40859
   638
  show "{x \<in> space M. f x \<noteq> g x} \<in> sets M"
hoelzl@40859
   639
    using sf[THEN borel_measurable_simple_function] by auto
hoelzl@40859
   640
qed simp
hoelzl@40859
   641
hoelzl@47694
   642
lemma simple_integral_indicator:
hoelzl@56949
   643
  assumes A: "A \<in> sets M"
hoelzl@49796
   644
  assumes f: "simple_function M f"
wenzelm@53015
   645
  shows "(\<integral>\<^sup>Sx. f x * indicator A x \<partial>M) =
hoelzl@56949
   646
    (\<Sum>x \<in> f ` space M. x * emeasure M (f -` {x} \<inter> space M \<inter> A))"
hoelzl@56949
   647
proof -
hoelzl@56949
   648
  have eq: "(\<lambda>x. (f x, indicator A x)) ` space M \<inter> {x. snd x = 1} = (\<lambda>x. (f x, 1::ereal))`A"
hoelzl@56949
   649
    using A[THEN sets.sets_into_space] by (auto simp: indicator_def image_iff split: split_if_asm)
hoelzl@56949
   650
  have eq2: "\<And>x. f x \<notin> f ` A \<Longrightarrow> f -` {f x} \<inter> space M \<inter> A = {}"
hoelzl@56949
   651
    by (auto simp: image_iff)
hoelzl@56949
   652
hoelzl@56949
   653
  have "(\<integral>\<^sup>Sx. f x * indicator A x \<partial>M) =
hoelzl@56949
   654
    (\<Sum>y\<in>(\<lambda>x. (f x, indicator A x))`space M. (fst y * snd y) * emeasure M {x\<in>space M. (f x, indicator A x) = y})"
hoelzl@56949
   655
    using assms by (intro simple_function_partition) auto
hoelzl@56949
   656
  also have "\<dots> = (\<Sum>y\<in>(\<lambda>x. (f x, indicator A x::ereal))`space M.
hoelzl@56949
   657
    if snd y = 1 then fst y * emeasure M (f -` {fst y} \<inter> space M \<inter> A) else 0)"
hoelzl@56949
   658
    by (auto simp: indicator_def split: split_if_asm intro!: arg_cong2[where f="op *"] arg_cong2[where f=emeasure] setsum_cong)
hoelzl@56949
   659
  also have "\<dots> = (\<Sum>y\<in>(\<lambda>x. (f x, 1::ereal))`A. fst y * emeasure M (f -` {fst y} \<inter> space M \<inter> A))"
hoelzl@56949
   660
    using assms by (subst setsum_cases) (auto intro!: simple_functionD(1) simp: eq)
hoelzl@56949
   661
  also have "\<dots> = (\<Sum>y\<in>fst`(\<lambda>x. (f x, 1::ereal))`A. y * emeasure M (f -` {y} \<inter> space M \<inter> A))"
hoelzl@56949
   662
    by (subst setsum_reindex[where f=fst]) (auto simp: inj_on_def)
hoelzl@56949
   663
  also have "\<dots> = (\<Sum>x \<in> f ` space M. x * emeasure M (f -` {x} \<inter> space M \<inter> A))"
hoelzl@56949
   664
    using A[THEN sets.sets_into_space]
hoelzl@56949
   665
    by (intro setsum_mono_zero_cong_left simple_functionD f) (auto simp: image_comp comp_def eq2)
hoelzl@56949
   666
  finally show ?thesis .
hoelzl@38656
   667
qed
hoelzl@35582
   668
hoelzl@47694
   669
lemma simple_integral_indicator_only[simp]:
hoelzl@38656
   670
  assumes "A \<in> sets M"
wenzelm@53015
   671
  shows "integral\<^sup>S M (indicator A) = emeasure M A"
hoelzl@56949
   672
  using simple_integral_indicator[OF assms, of "\<lambda>x. 1"] sets.sets_into_space[OF assms]
hoelzl@56949
   673
  by (simp_all add: image_constant_conv Int_absorb1 split: split_if_asm)
hoelzl@35582
   674
hoelzl@47694
   675
lemma simple_integral_null_set:
hoelzl@47694
   676
  assumes "simple_function M u" "\<And>x. 0 \<le> u x" and "N \<in> null_sets M"
wenzelm@53015
   677
  shows "(\<integral>\<^sup>Sx. u x * indicator N x \<partial>M) = 0"
hoelzl@38656
   678
proof -
hoelzl@47694
   679
  have "AE x in M. indicator N x = (0 :: ereal)"
hoelzl@47694
   680
    using `N \<in> null_sets M` by (auto simp: indicator_def intro!: AE_I[of _ _ N])
wenzelm@53015
   681
  then have "(\<integral>\<^sup>Sx. u x * indicator N x \<partial>M) = (\<integral>\<^sup>Sx. 0 \<partial>M)"
hoelzl@41981
   682
    using assms apply (intro simple_integral_cong_AE) by auto
hoelzl@40859
   683
  then show ?thesis by simp
hoelzl@38656
   684
qed
hoelzl@35582
   685
hoelzl@47694
   686
lemma simple_integral_cong_AE_mult_indicator:
hoelzl@47694
   687
  assumes sf: "simple_function M f" and eq: "AE x in M. x \<in> S" and "S \<in> sets M"
wenzelm@53015
   688
  shows "integral\<^sup>S M f = (\<integral>\<^sup>Sx. f x * indicator S x \<partial>M)"
hoelzl@41705
   689
  using assms by (intro simple_integral_cong_AE) auto
hoelzl@35582
   690
hoelzl@47694
   691
lemma simple_integral_cmult_indicator:
hoelzl@41981
   692
  assumes A: "A \<in> sets M"
hoelzl@56949
   693
  shows "(\<integral>\<^sup>Sx. c * indicator A x \<partial>M) = c * emeasure M A"
hoelzl@41981
   694
  using simple_integral_mult[OF simple_function_indicator[OF A]]
hoelzl@41981
   695
  unfolding simple_integral_indicator_only[OF A] by simp
hoelzl@41981
   696
hoelzl@47694
   697
lemma simple_integral_positive:
hoelzl@47694
   698
  assumes f: "simple_function M f" and ae: "AE x in M. 0 \<le> f x"
wenzelm@53015
   699
  shows "0 \<le> integral\<^sup>S M f"
hoelzl@41981
   700
proof -
wenzelm@53015
   701
  have "integral\<^sup>S M (\<lambda>x. 0) \<le> integral\<^sup>S M f"
hoelzl@41981
   702
    using simple_integral_mono_AE[OF _ f ae] by auto
hoelzl@41981
   703
  then show ?thesis by simp
hoelzl@41981
   704
qed
hoelzl@41981
   705
hoelzl@41689
   706
section "Continuous positive integration"
hoelzl@41689
   707
wenzelm@53015
   708
definition positive_integral :: "'a measure \<Rightarrow> ('a \<Rightarrow> ereal) \<Rightarrow> ereal" ("integral\<^sup>P") where
wenzelm@53015
   709
  "integral\<^sup>P M f = (SUP g : {g. simple_function M g \<and> g \<le> max 0 \<circ> f}. integral\<^sup>S M g)"
hoelzl@35692
   710
hoelzl@41689
   711
syntax
wenzelm@53015
   712
  "_positive_integral" :: "pttrn \<Rightarrow> ereal \<Rightarrow> 'a measure \<Rightarrow> ereal" ("\<integral>\<^sup>+ _. _ \<partial>_" [60,61] 110)
hoelzl@41689
   713
hoelzl@41689
   714
translations
wenzelm@53015
   715
  "\<integral>\<^sup>+ x. f \<partial>M" == "CONST positive_integral M (%x. f)"
hoelzl@40872
   716
hoelzl@47694
   717
lemma positive_integral_positive:
wenzelm@53015
   718
  "0 \<le> integral\<^sup>P M f"
hoelzl@44928
   719
  by (auto intro!: SUP_upper2[of "\<lambda>x. 0"] simp: positive_integral_def le_fun_def)
hoelzl@40873
   720
wenzelm@53015
   721
lemma positive_integral_not_MInfty[simp]: "integral\<^sup>P M f \<noteq> -\<infinity>"
hoelzl@47694
   722
  using positive_integral_positive[of M f] by auto
hoelzl@47694
   723
hoelzl@47694
   724
lemma positive_integral_def_finite:
wenzelm@53015
   725
  "integral\<^sup>P M f = (SUP g : {g. simple_function M g \<and> g \<le> max 0 \<circ> f \<and> range g \<subseteq> {0 ..< \<infinity>}}. integral\<^sup>S M g)"
haftmann@56218
   726
    (is "_ = SUPREMUM ?A ?f")
hoelzl@41981
   727
  unfolding positive_integral_def
hoelzl@44928
   728
proof (safe intro!: antisym SUP_least)
hoelzl@41981
   729
  fix g assume g: "simple_function M g" "g \<le> max 0 \<circ> f"
hoelzl@41981
   730
  let ?G = "{x \<in> space M. \<not> g x \<noteq> \<infinity>}"
hoelzl@41981
   731
  note gM = g(1)[THEN borel_measurable_simple_function]
wenzelm@50252
   732
  have \<mu>_G_pos: "0 \<le> (emeasure M) ?G" using gM by auto
wenzelm@46731
   733
  let ?g = "\<lambda>y x. if g x = \<infinity> then y else max 0 (g x)"
hoelzl@41981
   734
  from g gM have g_in_A: "\<And>y. 0 \<le> y \<Longrightarrow> y \<noteq> \<infinity> \<Longrightarrow> ?g y \<in> ?A"
hoelzl@41981
   735
    apply (safe intro!: simple_function_max simple_function_If)
hoelzl@41981
   736
    apply (force simp: max_def le_fun_def split: split_if_asm)+
hoelzl@41981
   737
    done
haftmann@56218
   738
  show "integral\<^sup>S M g \<le> SUPREMUM ?A ?f"
hoelzl@41981
   739
  proof cases
hoelzl@41981
   740
    have g0: "?g 0 \<in> ?A" by (intro g_in_A) auto
hoelzl@47694
   741
    assume "(emeasure M) ?G = 0"
hoelzl@47694
   742
    with gM have "AE x in M. x \<notin> ?G"
hoelzl@47694
   743
      by (auto simp add: AE_iff_null intro!: null_setsI)
hoelzl@41981
   744
    with gM g show ?thesis
hoelzl@44928
   745
      by (intro SUP_upper2[OF g0] simple_integral_mono_AE)
hoelzl@41981
   746
         (auto simp: max_def intro!: simple_function_If)
hoelzl@41981
   747
  next
wenzelm@50252
   748
    assume \<mu>_G: "(emeasure M) ?G \<noteq> 0"
haftmann@56218
   749
    have "SUPREMUM ?A (integral\<^sup>S M) = \<infinity>"
hoelzl@41981
   750
    proof (intro SUP_PInfty)
hoelzl@41981
   751
      fix n :: nat
hoelzl@47694
   752
      let ?y = "ereal (real n) / (if (emeasure M) ?G = \<infinity> then 1 else (emeasure M) ?G)"
wenzelm@50252
   753
      have "0 \<le> ?y" "?y \<noteq> \<infinity>" using \<mu>_G \<mu>_G_pos by (auto simp: ereal_divide_eq)
hoelzl@41981
   754
      then have "?g ?y \<in> ?A" by (rule g_in_A)
hoelzl@47694
   755
      have "real n \<le> ?y * (emeasure M) ?G"
wenzelm@50252
   756
        using \<mu>_G \<mu>_G_pos by (cases "(emeasure M) ?G") (auto simp: field_simps)
wenzelm@53015
   757
      also have "\<dots> = (\<integral>\<^sup>Sx. ?y * indicator ?G x \<partial>M)"
hoelzl@41981
   758
        using `0 \<le> ?y` `?g ?y \<in> ?A` gM
hoelzl@41981
   759
        by (subst simple_integral_cmult_indicator) auto
wenzelm@53015
   760
      also have "\<dots> \<le> integral\<^sup>S M (?g ?y)" using `?g ?y \<in> ?A` gM
hoelzl@41981
   761
        by (intro simple_integral_mono) auto
wenzelm@53015
   762
      finally show "\<exists>i\<in>?A. real n \<le> integral\<^sup>S M i"
hoelzl@41981
   763
        using `?g ?y \<in> ?A` by blast
hoelzl@41981
   764
    qed
hoelzl@41981
   765
    then show ?thesis by simp
hoelzl@41981
   766
  qed
hoelzl@44928
   767
qed (auto intro: SUP_upper)
hoelzl@40873
   768
hoelzl@47694
   769
lemma positive_integral_mono_AE:
wenzelm@53015
   770
  assumes ae: "AE x in M. u x \<le> v x" shows "integral\<^sup>P M u \<le> integral\<^sup>P M v"
hoelzl@41981
   771
  unfolding positive_integral_def
hoelzl@41981
   772
proof (safe intro!: SUP_mono)
hoelzl@41981
   773
  fix n assume n: "simple_function M n" "n \<le> max 0 \<circ> u"
hoelzl@41981
   774
  from ae[THEN AE_E] guess N . note N = this
hoelzl@47694
   775
  then have ae_N: "AE x in M. x \<notin> N" by (auto intro: AE_not_in)
wenzelm@46731
   776
  let ?n = "\<lambda>x. n x * indicator (space M - N) x"
hoelzl@47694
   777
  have "AE x in M. n x \<le> ?n x" "simple_function M ?n"
hoelzl@41981
   778
    using n N ae_N by auto
hoelzl@41981
   779
  moreover
hoelzl@41981
   780
  { fix x have "?n x \<le> max 0 (v x)"
hoelzl@41981
   781
    proof cases
hoelzl@41981
   782
      assume x: "x \<in> space M - N"
hoelzl@41981
   783
      with N have "u x \<le> v x" by auto
hoelzl@41981
   784
      with n(2)[THEN le_funD, of x] x show ?thesis
hoelzl@41981
   785
        by (auto simp: max_def split: split_if_asm)
hoelzl@41981
   786
    qed simp }
hoelzl@41981
   787
  then have "?n \<le> max 0 \<circ> v" by (auto simp: le_funI)
wenzelm@53015
   788
  moreover have "integral\<^sup>S M n \<le> integral\<^sup>S M ?n"
hoelzl@41981
   789
    using ae_N N n by (auto intro!: simple_integral_mono_AE)
wenzelm@53015
   790
  ultimately show "\<exists>m\<in>{g. simple_function M g \<and> g \<le> max 0 \<circ> v}. integral\<^sup>S M n \<le> integral\<^sup>S M m"
hoelzl@41981
   791
    by force
hoelzl@38656
   792
qed
hoelzl@38656
   793
hoelzl@47694
   794
lemma positive_integral_mono:
wenzelm@53015
   795
  "(\<And>x. x \<in> space M \<Longrightarrow> u x \<le> v x) \<Longrightarrow> integral\<^sup>P M u \<le> integral\<^sup>P M v"
hoelzl@41981
   796
  by (auto intro: positive_integral_mono_AE)
hoelzl@40859
   797
hoelzl@47694
   798
lemma positive_integral_cong_AE:
wenzelm@53015
   799
  "AE x in M. u x = v x \<Longrightarrow> integral\<^sup>P M u = integral\<^sup>P M v"
hoelzl@40859
   800
  by (auto simp: eq_iff intro!: positive_integral_mono_AE)
hoelzl@40859
   801
hoelzl@47694
   802
lemma positive_integral_cong:
wenzelm@53015
   803
  "(\<And>x. x \<in> space M \<Longrightarrow> u x = v x) \<Longrightarrow> integral\<^sup>P M u = integral\<^sup>P M v"
hoelzl@41981
   804
  by (auto intro: positive_integral_cong_AE)
hoelzl@40859
   805
hoelzl@47694
   806
lemma positive_integral_eq_simple_integral:
wenzelm@53015
   807
  assumes f: "simple_function M f" "\<And>x. 0 \<le> f x" shows "integral\<^sup>P M f = integral\<^sup>S M f"
hoelzl@41981
   808
proof -
wenzelm@46731
   809
  let ?f = "\<lambda>x. f x * indicator (space M) x"
hoelzl@41981
   810
  have f': "simple_function M ?f" using f by auto
hoelzl@41981
   811
  with f(2) have [simp]: "max 0 \<circ> ?f = ?f"
hoelzl@41981
   812
    by (auto simp: fun_eq_iff max_def split: split_indicator)
wenzelm@53015
   813
  have "integral\<^sup>P M ?f \<le> integral\<^sup>S M ?f" using f'
hoelzl@44928
   814
    by (force intro!: SUP_least simple_integral_mono simp: le_fun_def positive_integral_def)
wenzelm@53015
   815
  moreover have "integral\<^sup>S M ?f \<le> integral\<^sup>P M ?f"
hoelzl@41981
   816
    unfolding positive_integral_def
hoelzl@44928
   817
    using f' by (auto intro!: SUP_upper)
hoelzl@41981
   818
  ultimately show ?thesis
hoelzl@41981
   819
    by (simp cong: positive_integral_cong simple_integral_cong)
hoelzl@41981
   820
qed
hoelzl@41981
   821
hoelzl@47694
   822
lemma positive_integral_eq_simple_integral_AE:
wenzelm@53015
   823
  assumes f: "simple_function M f" "AE x in M. 0 \<le> f x" shows "integral\<^sup>P M f = integral\<^sup>S M f"
hoelzl@41981
   824
proof -
hoelzl@47694
   825
  have "AE x in M. f x = max 0 (f x)" using f by (auto split: split_max)
wenzelm@53015
   826
  with f have "integral\<^sup>P M f = integral\<^sup>S M (\<lambda>x. max 0 (f x))"
hoelzl@41981
   827
    by (simp cong: positive_integral_cong_AE simple_integral_cong_AE
hoelzl@41981
   828
             add: positive_integral_eq_simple_integral)
hoelzl@41981
   829
  with assms show ?thesis
hoelzl@41981
   830
    by (auto intro!: simple_integral_cong_AE split: split_max)
hoelzl@41981
   831
qed
hoelzl@40873
   832
hoelzl@47694
   833
lemma positive_integral_SUP_approx:
hoelzl@41981
   834
  assumes f: "incseq f" "\<And>i. f i \<in> borel_measurable M" "\<And>i x. 0 \<le> f i x"
hoelzl@41981
   835
  and u: "simple_function M u" "u \<le> (SUP i. f i)" "u`space M \<subseteq> {0..<\<infinity>}"
wenzelm@53015
   836
  shows "integral\<^sup>S M u \<le> (SUP i. integral\<^sup>P M (f i))" (is "_ \<le> ?S")
hoelzl@43920
   837
proof (rule ereal_le_mult_one_interval)
wenzelm@53015
   838
  have "0 \<le> (SUP i. integral\<^sup>P M (f i))"
hoelzl@44928
   839
    using f(3) by (auto intro!: SUP_upper2 positive_integral_positive)
wenzelm@53015
   840
  then show "(SUP i. integral\<^sup>P M (f i)) \<noteq> -\<infinity>" by auto
hoelzl@41981
   841
  have u_range: "\<And>x. x \<in> space M \<Longrightarrow> 0 \<le> u x \<and> u x \<noteq> \<infinity>"
hoelzl@41981
   842
    using u(3) by auto
hoelzl@43920
   843
  fix a :: ereal assume "0 < a" "a < 1"
hoelzl@38656
   844
  hence "a \<noteq> 0" by auto
wenzelm@46731
   845
  let ?B = "\<lambda>i. {x \<in> space M. a * u x \<le> f i x}"
hoelzl@38656
   846
  have B: "\<And>i. ?B i \<in> sets M"
hoelzl@56949
   847
    using f `simple_function M u`[THEN borel_measurable_simple_function] by auto
hoelzl@38656
   848
wenzelm@46731
   849
  let ?uB = "\<lambda>i x. u x * indicator (?B i) x"
hoelzl@38656
   850
hoelzl@38656
   851
  { fix i have "?B i \<subseteq> ?B (Suc i)"
hoelzl@38656
   852
    proof safe
hoelzl@38656
   853
      fix i x assume "a * u x \<le> f i x"
hoelzl@38656
   854
      also have "\<dots> \<le> f (Suc i) x"
hoelzl@41981
   855
        using `incseq f`[THEN incseq_SucD] unfolding le_fun_def by auto
hoelzl@38656
   856
      finally show "a * u x \<le> f (Suc i) x" .
hoelzl@38656
   857
    qed }
hoelzl@38656
   858
  note B_mono = this
hoelzl@35582
   859
immler@50244
   860
  note B_u = sets.Int[OF u(1)[THEN simple_functionD(2)] B]
hoelzl@38656
   861
wenzelm@46731
   862
  let ?B' = "\<lambda>i n. (u -` {i} \<inter> space M) \<inter> ?B n"
hoelzl@47694
   863
  have measure_conv: "\<And>i. (emeasure M) (u -` {i} \<inter> space M) = (SUP n. (emeasure M) (?B' i n))"
hoelzl@41981
   864
  proof -
hoelzl@41981
   865
    fix i
hoelzl@41981
   866
    have 1: "range (?B' i) \<subseteq> sets M" using B_u by auto
hoelzl@41981
   867
    have 2: "incseq (?B' i)" using B_mono by (auto intro!: incseq_SucI)
hoelzl@41981
   868
    have "(\<Union>n. ?B' i n) = u -` {i} \<inter> space M"
hoelzl@41981
   869
    proof safe
hoelzl@41981
   870
      fix x i assume x: "x \<in> space M"
hoelzl@41981
   871
      show "x \<in> (\<Union>i. ?B' (u x) i)"
hoelzl@41981
   872
      proof cases
hoelzl@41981
   873
        assume "u x = 0" thus ?thesis using `x \<in> space M` f(3) by simp
hoelzl@41981
   874
      next
hoelzl@41981
   875
        assume "u x \<noteq> 0"
hoelzl@41981
   876
        with `a < 1` u_range[OF `x \<in> space M`]
hoelzl@41981
   877
        have "a * u x < 1 * u x"
hoelzl@43920
   878
          by (intro ereal_mult_strict_right_mono) (auto simp: image_iff)
noschinl@46884
   879
        also have "\<dots> \<le> (SUP i. f i x)" using u(2) by (auto simp: le_fun_def)
hoelzl@44928
   880
        finally obtain i where "a * u x < f i x" unfolding SUP_def
haftmann@56166
   881
          by (auto simp add: less_SUP_iff)
hoelzl@41981
   882
        hence "a * u x \<le> f i x" by auto
hoelzl@41981
   883
        thus ?thesis using `x \<in> space M` by auto
hoelzl@41981
   884
      qed
hoelzl@40859
   885
    qed
hoelzl@47694
   886
    then show "?thesis i" using SUP_emeasure_incseq[OF 1 2] by simp
hoelzl@41981
   887
  qed
hoelzl@38656
   888
wenzelm@53015
   889
  have "integral\<^sup>S M u = (SUP i. integral\<^sup>S M (?uB i))"
hoelzl@41689
   890
    unfolding simple_integral_indicator[OF B `simple_function M u`]
haftmann@56212
   891
  proof (subst SUP_ereal_setsum, safe)
hoelzl@38656
   892
    fix x n assume "x \<in> space M"
hoelzl@47694
   893
    with u_range show "incseq (\<lambda>i. u x * (emeasure M) (?B' (u x) i))" "\<And>i. 0 \<le> u x * (emeasure M) (?B' (u x) i)"
hoelzl@47694
   894
      using B_mono B_u by (auto intro!: emeasure_mono ereal_mult_left_mono incseq_SucI simp: ereal_zero_le_0_iff)
hoelzl@38656
   895
  next
wenzelm@53015
   896
    show "integral\<^sup>S M u = (\<Sum>i\<in>u ` space M. SUP n. i * (emeasure M) (?B' i n))"
hoelzl@41981
   897
      using measure_conv u_range B_u unfolding simple_integral_def
haftmann@56212
   898
      by (auto intro!: setsum_cong SUP_ereal_cmult [symmetric])
hoelzl@38656
   899
  qed
hoelzl@38656
   900
  moreover
wenzelm@53015
   901
  have "a * (SUP i. integral\<^sup>S M (?uB i)) \<le> ?S"
haftmann@56212
   902
    apply (subst SUP_ereal_cmult [symmetric])
hoelzl@38705
   903
  proof (safe intro!: SUP_mono bexI)
hoelzl@38656
   904
    fix i
wenzelm@53015
   905
    have "a * integral\<^sup>S M (?uB i) = (\<integral>\<^sup>Sx. a * ?uB i x \<partial>M)"
hoelzl@41981
   906
      using B `simple_function M u` u_range
hoelzl@41981
   907
      by (subst simple_integral_mult) (auto split: split_indicator)
wenzelm@53015
   908
    also have "\<dots> \<le> integral\<^sup>P M (f i)"
hoelzl@38656
   909
    proof -
hoelzl@41981
   910
      have *: "simple_function M (\<lambda>x. a * ?uB i x)" using B `0 < a` u(1) by auto
hoelzl@41981
   911
      show ?thesis using f(3) * u_range `0 < a`
hoelzl@41981
   912
        by (subst positive_integral_eq_simple_integral[symmetric])
hoelzl@41981
   913
           (auto intro!: positive_integral_mono split: split_indicator)
hoelzl@38656
   914
    qed
wenzelm@53015
   915
    finally show "a * integral\<^sup>S M (?uB i) \<le> integral\<^sup>P M (f i)"
hoelzl@38656
   916
      by auto
hoelzl@41981
   917
  next
wenzelm@53015
   918
    fix i show "0 \<le> \<integral>\<^sup>S x. ?uB i x \<partial>M" using B `0 < a` u(1) u_range
hoelzl@41981
   919
      by (intro simple_integral_positive) (auto split: split_indicator)
hoelzl@41981
   920
  qed (insert `0 < a`, auto)
wenzelm@53015
   921
  ultimately show "a * integral\<^sup>S M u \<le> ?S" by simp
hoelzl@35582
   922
qed
hoelzl@35582
   923
hoelzl@47694
   924
lemma incseq_positive_integral:
wenzelm@53015
   925
  assumes "incseq f" shows "incseq (\<lambda>i. integral\<^sup>P M (f i))"
hoelzl@41981
   926
proof -
hoelzl@41981
   927
  have "\<And>i x. f i x \<le> f (Suc i) x"
hoelzl@41981
   928
    using assms by (auto dest!: incseq_SucD simp: le_fun_def)
hoelzl@41981
   929
  then show ?thesis
hoelzl@41981
   930
    by (auto intro!: incseq_SucI positive_integral_mono)
hoelzl@41981
   931
qed
hoelzl@41981
   932
hoelzl@35582
   933
text {* Beppo-Levi monotone convergence theorem *}
hoelzl@47694
   934
lemma positive_integral_monotone_convergence_SUP:
hoelzl@41981
   935
  assumes f: "incseq f" "\<And>i. f i \<in> borel_measurable M" "\<And>i x. 0 \<le> f i x"
wenzelm@53015
   936
  shows "(\<integral>\<^sup>+ x. (SUP i. f i x) \<partial>M) = (SUP i. integral\<^sup>P M (f i))"
hoelzl@41981
   937
proof (rule antisym)
wenzelm@53015
   938
  show "(SUP j. integral\<^sup>P M (f j)) \<le> (\<integral>\<^sup>+ x. (SUP i. f i x) \<partial>M)"
hoelzl@44928
   939
    by (auto intro!: SUP_least SUP_upper positive_integral_mono)
hoelzl@38656
   940
next
wenzelm@53015
   941
  show "(\<integral>\<^sup>+ x. (SUP i. f i x) \<partial>M) \<le> (SUP j. integral\<^sup>P M (f j))"
hoelzl@47694
   942
    unfolding positive_integral_def_finite[of _ "\<lambda>x. SUP i. f i x"]
hoelzl@44928
   943
  proof (safe intro!: SUP_least)
hoelzl@41981
   944
    fix g assume g: "simple_function M g"
wenzelm@53374
   945
      and *: "g \<le> max 0 \<circ> (\<lambda>x. SUP i. f i x)" "range g \<subseteq> {0..<\<infinity>}"
wenzelm@53374
   946
    then have "\<And>x. 0 \<le> (SUP i. f i x)" and g': "g`space M \<subseteq> {0..<\<infinity>}"
hoelzl@44928
   947
      using f by (auto intro!: SUP_upper2)
wenzelm@53374
   948
    with * show "integral\<^sup>S M g \<le> (SUP j. integral\<^sup>P M (f j))"
hoelzl@41981
   949
      by (intro  positive_integral_SUP_approx[OF f g _ g'])
noschinl@46884
   950
         (auto simp: le_fun_def max_def)
hoelzl@35582
   951
  qed
hoelzl@35582
   952
qed
hoelzl@35582
   953
hoelzl@47694
   954
lemma positive_integral_monotone_convergence_SUP_AE:
hoelzl@47694
   955
  assumes f: "\<And>i. AE x in M. f i x \<le> f (Suc i) x \<and> 0 \<le> f i x" "\<And>i. f i \<in> borel_measurable M"
wenzelm@53015
   956
  shows "(\<integral>\<^sup>+ x. (SUP i. f i x) \<partial>M) = (SUP i. integral\<^sup>P M (f i))"
hoelzl@40859
   957
proof -
hoelzl@47694
   958
  from f have "AE x in M. \<forall>i. f i x \<le> f (Suc i) x \<and> 0 \<le> f i x"
hoelzl@41981
   959
    by (simp add: AE_all_countable)
hoelzl@41981
   960
  from this[THEN AE_E] guess N . note N = this
wenzelm@46731
   961
  let ?f = "\<lambda>i x. if x \<in> space M - N then f i x else 0"
hoelzl@47694
   962
  have f_eq: "AE x in M. \<forall>i. ?f i x = f i x" using N by (auto intro!: AE_I[of _ _ N])
wenzelm@53015
   963
  then have "(\<integral>\<^sup>+ x. (SUP i. f i x) \<partial>M) = (\<integral>\<^sup>+ x. (SUP i. ?f i x) \<partial>M)"
hoelzl@41981
   964
    by (auto intro!: positive_integral_cong_AE)
wenzelm@53015
   965
  also have "\<dots> = (SUP i. (\<integral>\<^sup>+ x. ?f i x \<partial>M))"
hoelzl@41981
   966
  proof (rule positive_integral_monotone_convergence_SUP)
hoelzl@41981
   967
    show "incseq ?f" using N(1) by (force intro!: incseq_SucI le_funI)
hoelzl@41981
   968
    { fix i show "(\<lambda>x. if x \<in> space M - N then f i x else 0) \<in> borel_measurable M"
hoelzl@41981
   969
        using f N(3) by (intro measurable_If_set) auto
hoelzl@41981
   970
      fix x show "0 \<le> ?f i x"
hoelzl@41981
   971
        using N(1) by auto }
hoelzl@40859
   972
  qed
wenzelm@53015
   973
  also have "\<dots> = (SUP i. (\<integral>\<^sup>+ x. f i x \<partial>M))"
haftmann@56218
   974
    using f_eq by (force intro!: arg_cong[where f="SUPREMUM UNIV"] positive_integral_cong_AE ext)
hoelzl@41981
   975
  finally show ?thesis .
hoelzl@41981
   976
qed
hoelzl@41981
   977
hoelzl@47694
   978
lemma positive_integral_monotone_convergence_SUP_AE_incseq:
hoelzl@47694
   979
  assumes f: "incseq f" "\<And>i. AE x in M. 0 \<le> f i x" and borel: "\<And>i. f i \<in> borel_measurable M"
wenzelm@53015
   980
  shows "(\<integral>\<^sup>+ x. (SUP i. f i x) \<partial>M) = (SUP i. integral\<^sup>P M (f i))"
hoelzl@41981
   981
  using f[unfolded incseq_Suc_iff le_fun_def]
hoelzl@41981
   982
  by (intro positive_integral_monotone_convergence_SUP_AE[OF _ borel])
hoelzl@41981
   983
     auto
hoelzl@41981
   984
hoelzl@47694
   985
lemma positive_integral_monotone_convergence_simple:
hoelzl@41981
   986
  assumes f: "incseq f" "\<And>i x. 0 \<le> f i x" "\<And>i. simple_function M (f i)"
wenzelm@53015
   987
  shows "(SUP i. integral\<^sup>S M (f i)) = (\<integral>\<^sup>+x. (SUP i. f i x) \<partial>M)"
hoelzl@41981
   988
  using assms unfolding positive_integral_monotone_convergence_SUP[OF f(1)
hoelzl@41981
   989
    f(3)[THEN borel_measurable_simple_function] f(2)]
haftmann@56218
   990
  by (auto intro!: positive_integral_eq_simple_integral[symmetric] arg_cong[where f="SUPREMUM UNIV"] ext)
hoelzl@41981
   991
hoelzl@41981
   992
lemma positive_integral_max_0:
wenzelm@53015
   993
  "(\<integral>\<^sup>+x. max 0 (f x) \<partial>M) = integral\<^sup>P M f"
hoelzl@41981
   994
  by (simp add: le_fun_def positive_integral_def)
hoelzl@41981
   995
hoelzl@47694
   996
lemma positive_integral_cong_pos:
hoelzl@41981
   997
  assumes "\<And>x. x \<in> space M \<Longrightarrow> f x \<le> 0 \<and> g x \<le> 0 \<or> f x = g x"
wenzelm@53015
   998
  shows "integral\<^sup>P M f = integral\<^sup>P M g"
hoelzl@41981
   999
proof -
wenzelm@53015
  1000
  have "integral\<^sup>P M (\<lambda>x. max 0 (f x)) = integral\<^sup>P M (\<lambda>x. max 0 (g x))"
hoelzl@41981
  1001
  proof (intro positive_integral_cong)
hoelzl@41981
  1002
    fix x assume "x \<in> space M"
hoelzl@41981
  1003
    from assms[OF this] show "max 0 (f x) = max 0 (g x)"
hoelzl@41981
  1004
      by (auto split: split_max)
hoelzl@41981
  1005
  qed
hoelzl@41981
  1006
  then show ?thesis by (simp add: positive_integral_max_0)
hoelzl@40859
  1007
qed
hoelzl@40859
  1008
hoelzl@47694
  1009
lemma SUP_simple_integral_sequences:
hoelzl@41981
  1010
  assumes f: "incseq f" "\<And>i x. 0 \<le> f i x" "\<And>i. simple_function M (f i)"
hoelzl@41981
  1011
  and g: "incseq g" "\<And>i x. 0 \<le> g i x" "\<And>i. simple_function M (g i)"
hoelzl@47694
  1012
  and eq: "AE x in M. (SUP i. f i x) = (SUP i. g i x)"
wenzelm@53015
  1013
  shows "(SUP i. integral\<^sup>S M (f i)) = (SUP i. integral\<^sup>S M (g i))"
haftmann@56218
  1014
    (is "SUPREMUM _ ?F = SUPREMUM _ ?G")
hoelzl@38656
  1015
proof -
wenzelm@53015
  1016
  have "(SUP i. integral\<^sup>S M (f i)) = (\<integral>\<^sup>+x. (SUP i. f i x) \<partial>M)"
hoelzl@41981
  1017
    using f by (rule positive_integral_monotone_convergence_simple)
wenzelm@53015
  1018
  also have "\<dots> = (\<integral>\<^sup>+x. (SUP i. g i x) \<partial>M)"
hoelzl@41981
  1019
    unfolding eq[THEN positive_integral_cong_AE] ..
hoelzl@38656
  1020
  also have "\<dots> = (SUP i. ?G i)"
hoelzl@41981
  1021
    using g by (rule positive_integral_monotone_convergence_simple[symmetric])
hoelzl@41981
  1022
  finally show ?thesis by simp
hoelzl@38656
  1023
qed
hoelzl@38656
  1024
hoelzl@47694
  1025
lemma positive_integral_const[simp]:
wenzelm@53015
  1026
  "0 \<le> c \<Longrightarrow> (\<integral>\<^sup>+ x. c \<partial>M) = c * (emeasure M) (space M)"
hoelzl@38656
  1027
  by (subst positive_integral_eq_simple_integral) auto
hoelzl@38656
  1028
hoelzl@47694
  1029
lemma positive_integral_linear:
hoelzl@41981
  1030
  assumes f: "f \<in> borel_measurable M" "\<And>x. 0 \<le> f x" and "0 \<le> a"
hoelzl@41981
  1031
  and g: "g \<in> borel_measurable M" "\<And>x. 0 \<le> g x"
wenzelm@53015
  1032
  shows "(\<integral>\<^sup>+ x. a * f x + g x \<partial>M) = a * integral\<^sup>P M f + integral\<^sup>P M g"
wenzelm@53015
  1033
    (is "integral\<^sup>P M ?L = _")
hoelzl@35582
  1034
proof -
hoelzl@41981
  1035
  from borel_measurable_implies_simple_function_sequence'[OF f(1)] guess u .
hoelzl@41981
  1036
  note u = positive_integral_monotone_convergence_simple[OF this(2,5,1)] this
hoelzl@41981
  1037
  from borel_measurable_implies_simple_function_sequence'[OF g(1)] guess v .
hoelzl@41981
  1038
  note v = positive_integral_monotone_convergence_simple[OF this(2,5,1)] this
wenzelm@46731
  1039
  let ?L' = "\<lambda>i x. a * u i x + v i x"
hoelzl@38656
  1040
hoelzl@41981
  1041
  have "?L \<in> borel_measurable M" using assms by auto
hoelzl@38656
  1042
  from borel_measurable_implies_simple_function_sequence'[OF this] guess l .
hoelzl@41981
  1043
  note l = positive_integral_monotone_convergence_simple[OF this(2,5,1)] this
hoelzl@41981
  1044
wenzelm@53015
  1045
  have inc: "incseq (\<lambda>i. a * integral\<^sup>S M (u i))" "incseq (\<lambda>i. integral\<^sup>S M (v i))"
hoelzl@41981
  1046
    using u v `0 \<le> a`
hoelzl@41981
  1047
    by (auto simp: incseq_Suc_iff le_fun_def
hoelzl@43920
  1048
             intro!: add_mono ereal_mult_left_mono simple_integral_mono)
wenzelm@53015
  1049
  have pos: "\<And>i. 0 \<le> integral\<^sup>S M (u i)" "\<And>i. 0 \<le> integral\<^sup>S M (v i)" "\<And>i. 0 \<le> a * integral\<^sup>S M (u i)"
hoelzl@41981
  1050
    using u v `0 \<le> a` by (auto simp: simple_integral_positive)
wenzelm@53015
  1051
  { fix i from pos[of i] have "a * integral\<^sup>S M (u i) \<noteq> -\<infinity>" "integral\<^sup>S M (v i) \<noteq> -\<infinity>"
hoelzl@41981
  1052
      by (auto split: split_if_asm) }
hoelzl@41981
  1053
  note not_MInf = this
hoelzl@41981
  1054
wenzelm@53015
  1055
  have l': "(SUP i. integral\<^sup>S M (l i)) = (SUP i. integral\<^sup>S M (?L' i))"
hoelzl@41981
  1056
  proof (rule SUP_simple_integral_sequences[OF l(3,6,2)])
hoelzl@41981
  1057
    show "incseq ?L'" "\<And>i x. 0 \<le> ?L' i x" "\<And>i. simple_function M (?L' i)"
hoelzl@41981
  1058
      using u v  `0 \<le> a` unfolding incseq_Suc_iff le_fun_def
nipkow@56537
  1059
      by (auto intro!: add_mono ereal_mult_left_mono)
hoelzl@41981
  1060
    { fix x
hoelzl@41981
  1061
      { fix i have "a * u i x \<noteq> -\<infinity>" "v i x \<noteq> -\<infinity>" "u i x \<noteq> -\<infinity>" using `0 \<le> a` u(6)[of i x] v(6)[of i x]
hoelzl@41981
  1062
          by auto }
hoelzl@41981
  1063
      then have "(SUP i. a * u i x + v i x) = a * (SUP i. u i x) + (SUP i. v i x)"
hoelzl@41981
  1064
        using `0 \<le> a` u(3) v(3) u(6)[of _ x] v(6)[of _ x]
haftmann@56212
  1065
        by (subst SUP_ereal_cmult [symmetric, OF u(6) `0 \<le> a`])
haftmann@56212
  1066
           (auto intro!: SUP_ereal_add
nipkow@56537
  1067
                 simp: incseq_Suc_iff le_fun_def add_mono ereal_mult_left_mono) }
hoelzl@47694
  1068
    then show "AE x in M. (SUP i. l i x) = (SUP i. ?L' i x)"
hoelzl@41981
  1069
      unfolding l(5) using `0 \<le> a` u(5) v(5) l(5) f(2) g(2)
nipkow@56537
  1070
      by (intro AE_I2) (auto split: split_max)
hoelzl@38656
  1071
  qed
wenzelm@53015
  1072
  also have "\<dots> = (SUP i. a * integral\<^sup>S M (u i) + integral\<^sup>S M (v i))"
haftmann@56218
  1073
    using u(2, 6) v(2, 6) `0 \<le> a` by (auto intro!: arg_cong[where f="SUPREMUM UNIV"] ext)
wenzelm@53015
  1074
  finally have "(\<integral>\<^sup>+ x. max 0 (a * f x + g x) \<partial>M) = a * (\<integral>\<^sup>+x. max 0 (f x) \<partial>M) + (\<integral>\<^sup>+x. max 0 (g x) \<partial>M)"
hoelzl@41981
  1075
    unfolding l(5)[symmetric] u(5)[symmetric] v(5)[symmetric]
hoelzl@41981
  1076
    unfolding l(1)[symmetric] u(1)[symmetric] v(1)[symmetric]
haftmann@56212
  1077
    apply (subst SUP_ereal_cmult [symmetric, OF pos(1) `0 \<le> a`])
haftmann@56212
  1078
    apply (subst SUP_ereal_add [symmetric, OF inc not_MInf]) .
hoelzl@41981
  1079
  then show ?thesis by (simp add: positive_integral_max_0)
hoelzl@38656
  1080
qed
hoelzl@38656
  1081
hoelzl@47694
  1082
lemma positive_integral_cmult:
hoelzl@49775
  1083
  assumes f: "f \<in> borel_measurable M" "0 \<le> c"
wenzelm@53015
  1084
  shows "(\<integral>\<^sup>+ x. c * f x \<partial>M) = c * integral\<^sup>P M f"
hoelzl@41981
  1085
proof -
hoelzl@41981
  1086
  have [simp]: "\<And>x. c * max 0 (f x) = max 0 (c * f x)" using `0 \<le> c`
hoelzl@43920
  1087
    by (auto split: split_max simp: ereal_zero_le_0_iff)
wenzelm@53015
  1088
  have "(\<integral>\<^sup>+ x. c * f x \<partial>M) = (\<integral>\<^sup>+ x. c * max 0 (f x) \<partial>M)"
hoelzl@41981
  1089
    by (simp add: positive_integral_max_0)
hoelzl@41981
  1090
  then show ?thesis
hoelzl@47694
  1091
    using positive_integral_linear[OF _ _ `0 \<le> c`, of "\<lambda>x. max 0 (f x)" _ "\<lambda>x. 0"] f
hoelzl@41981
  1092
    by (auto simp: positive_integral_max_0)
hoelzl@41981
  1093
qed
hoelzl@38656
  1094
hoelzl@47694
  1095
lemma positive_integral_multc:
hoelzl@49775
  1096
  assumes "f \<in> borel_measurable M" "0 \<le> c"
wenzelm@53015
  1097
  shows "(\<integral>\<^sup>+ x. f x * c \<partial>M) = integral\<^sup>P M f * c"
hoelzl@41096
  1098
  unfolding mult_commute[of _ c] positive_integral_cmult[OF assms] by simp
hoelzl@41096
  1099
hoelzl@47694
  1100
lemma positive_integral_indicator[simp]:
wenzelm@53015
  1101
  "A \<in> sets M \<Longrightarrow> (\<integral>\<^sup>+ x. indicator A x\<partial>M) = (emeasure M) A"
hoelzl@41544
  1102
  by (subst positive_integral_eq_simple_integral)
hoelzl@49775
  1103
     (auto simp: simple_integral_indicator)
hoelzl@38656
  1104
hoelzl@47694
  1105
lemma positive_integral_cmult_indicator:
wenzelm@53015
  1106
  "0 \<le> c \<Longrightarrow> A \<in> sets M \<Longrightarrow> (\<integral>\<^sup>+ x. c * indicator A x \<partial>M) = c * (emeasure M) A"
hoelzl@41544
  1107
  by (subst positive_integral_eq_simple_integral)
hoelzl@41544
  1108
     (auto simp: simple_function_indicator simple_integral_indicator)
hoelzl@38656
  1109
hoelzl@50097
  1110
lemma positive_integral_indicator':
hoelzl@50097
  1111
  assumes [measurable]: "A \<inter> space M \<in> sets M"
wenzelm@53015
  1112
  shows "(\<integral>\<^sup>+ x. indicator A x \<partial>M) = emeasure M (A \<inter> space M)"
hoelzl@50097
  1113
proof -
wenzelm@53015
  1114
  have "(\<integral>\<^sup>+ x. indicator A x \<partial>M) = (\<integral>\<^sup>+ x. indicator (A \<inter> space M) x \<partial>M)"
hoelzl@50097
  1115
    by (intro positive_integral_cong) (simp split: split_indicator)
hoelzl@50097
  1116
  also have "\<dots> = emeasure M (A \<inter> space M)"
hoelzl@50097
  1117
    by simp
hoelzl@50097
  1118
  finally show ?thesis .
hoelzl@50097
  1119
qed
hoelzl@50097
  1120
hoelzl@47694
  1121
lemma positive_integral_add:
hoelzl@47694
  1122
  assumes f: "f \<in> borel_measurable M" "AE x in M. 0 \<le> f x"
hoelzl@47694
  1123
  and g: "g \<in> borel_measurable M" "AE x in M. 0 \<le> g x"
wenzelm@53015
  1124
  shows "(\<integral>\<^sup>+ x. f x + g x \<partial>M) = integral\<^sup>P M f + integral\<^sup>P M g"
hoelzl@41981
  1125
proof -
hoelzl@47694
  1126
  have ae: "AE x in M. max 0 (f x) + max 0 (g x) = max 0 (f x + g x)"
nipkow@56537
  1127
    using assms by (auto split: split_max)
wenzelm@53015
  1128
  have "(\<integral>\<^sup>+ x. f x + g x \<partial>M) = (\<integral>\<^sup>+ x. max 0 (f x + g x) \<partial>M)"
hoelzl@41981
  1129
    by (simp add: positive_integral_max_0)
wenzelm@53015
  1130
  also have "\<dots> = (\<integral>\<^sup>+ x. max 0 (f x) + max 0 (g x) \<partial>M)"
hoelzl@41981
  1131
    unfolding ae[THEN positive_integral_cong_AE] ..
wenzelm@53015
  1132
  also have "\<dots> = (\<integral>\<^sup>+ x. max 0 (f x) \<partial>M) + (\<integral>\<^sup>+ x. max 0 (g x) \<partial>M)"
hoelzl@47694
  1133
    using positive_integral_linear[of "\<lambda>x. max 0 (f x)" _ 1 "\<lambda>x. max 0 (g x)"] f g
hoelzl@41981
  1134
    by auto
hoelzl@41981
  1135
  finally show ?thesis
hoelzl@41981
  1136
    by (simp add: positive_integral_max_0)
hoelzl@41981
  1137
qed
hoelzl@38656
  1138
hoelzl@47694
  1139
lemma positive_integral_setsum:
hoelzl@47694
  1140
  assumes "\<And>i. i\<in>P \<Longrightarrow> f i \<in> borel_measurable M" "\<And>i. i\<in>P \<Longrightarrow> AE x in M. 0 \<le> f i x"
wenzelm@53015
  1141
  shows "(\<integral>\<^sup>+ x. (\<Sum>i\<in>P. f i x) \<partial>M) = (\<Sum>i\<in>P. integral\<^sup>P M (f i))"
hoelzl@38656
  1142
proof cases
hoelzl@41981
  1143
  assume f: "finite P"
hoelzl@47694
  1144
  from assms have "AE x in M. \<forall>i\<in>P. 0 \<le> f i x" unfolding AE_finite_all[OF f] by auto
hoelzl@41981
  1145
  from f this assms(1) show ?thesis
hoelzl@38656
  1146
  proof induct
hoelzl@38656
  1147
    case (insert i P)
hoelzl@47694
  1148
    then have "f i \<in> borel_measurable M" "AE x in M. 0 \<le> f i x"
hoelzl@47694
  1149
      "(\<lambda>x. \<Sum>i\<in>P. f i x) \<in> borel_measurable M" "AE x in M. 0 \<le> (\<Sum>i\<in>P. f i x)"
hoelzl@50002
  1150
      by (auto intro!: setsum_nonneg)
hoelzl@38656
  1151
    from positive_integral_add[OF this]
hoelzl@38656
  1152
    show ?case using insert by auto
hoelzl@38656
  1153
  qed simp
hoelzl@38656
  1154
qed simp
hoelzl@38656
  1155
hoelzl@47694
  1156
lemma positive_integral_Markov_inequality:
hoelzl@49775
  1157
  assumes u: "u \<in> borel_measurable M" "AE x in M. 0 \<le> u x" and "A \<in> sets M" and c: "0 \<le> c"
wenzelm@53015
  1158
  shows "(emeasure M) ({x\<in>space M. 1 \<le> c * u x} \<inter> A) \<le> c * (\<integral>\<^sup>+ x. u x * indicator A x \<partial>M)"
hoelzl@47694
  1159
    (is "(emeasure M) ?A \<le> _ * ?PI")
hoelzl@41981
  1160
proof -
hoelzl@41981
  1161
  have "?A \<in> sets M"
hoelzl@41981
  1162
    using `A \<in> sets M` u by auto
wenzelm@53015
  1163
  hence "(emeasure M) ?A = (\<integral>\<^sup>+ x. indicator ?A x \<partial>M)"
hoelzl@41981
  1164
    using positive_integral_indicator by simp
wenzelm@53015
  1165
  also have "\<dots> \<le> (\<integral>\<^sup>+ x. c * (u x * indicator A x) \<partial>M)" using u c
hoelzl@41981
  1166
    by (auto intro!: positive_integral_mono_AE
hoelzl@43920
  1167
      simp: indicator_def ereal_zero_le_0_iff)
wenzelm@53015
  1168
  also have "\<dots> = c * (\<integral>\<^sup>+ x. u x * indicator A x \<partial>M)"
hoelzl@41981
  1169
    using assms
hoelzl@50002
  1170
    by (auto intro!: positive_integral_cmult simp: ereal_zero_le_0_iff)
hoelzl@41981
  1171
  finally show ?thesis .
hoelzl@41981
  1172
qed
hoelzl@41981
  1173
hoelzl@47694
  1174
lemma positive_integral_noteq_infinite:
hoelzl@47694
  1175
  assumes g: "g \<in> borel_measurable M" "AE x in M. 0 \<le> g x"
wenzelm@53015
  1176
  and "integral\<^sup>P M g \<noteq> \<infinity>"
hoelzl@47694
  1177
  shows "AE x in M. g x \<noteq> \<infinity>"
hoelzl@41981
  1178
proof (rule ccontr)
hoelzl@47694
  1179
  assume c: "\<not> (AE x in M. g x \<noteq> \<infinity>)"
hoelzl@47694
  1180
  have "(emeasure M) {x\<in>space M. g x = \<infinity>} \<noteq> 0"
hoelzl@47694
  1181
    using c g by (auto simp add: AE_iff_null)
hoelzl@47694
  1182
  moreover have "0 \<le> (emeasure M) {x\<in>space M. g x = \<infinity>}" using g by (auto intro: measurable_sets)
hoelzl@47694
  1183
  ultimately have "0 < (emeasure M) {x\<in>space M. g x = \<infinity>}" by auto
hoelzl@47694
  1184
  then have "\<infinity> = \<infinity> * (emeasure M) {x\<in>space M. g x = \<infinity>}" by auto
wenzelm@53015
  1185
  also have "\<dots> \<le> (\<integral>\<^sup>+x. \<infinity> * indicator {x\<in>space M. g x = \<infinity>} x \<partial>M)"
hoelzl@41981
  1186
    using g by (subst positive_integral_cmult_indicator) auto
wenzelm@53015
  1187
  also have "\<dots> \<le> integral\<^sup>P M g"
hoelzl@41981
  1188
    using assms by (auto intro!: positive_integral_mono_AE simp: indicator_def)
wenzelm@53015
  1189
  finally show False using `integral\<^sup>P M g \<noteq> \<infinity>` by auto
hoelzl@41981
  1190
qed
hoelzl@41981
  1191
hoelzl@56949
  1192
lemma positive_integral_PInf:
hoelzl@56949
  1193
  assumes f: "f \<in> borel_measurable M"
hoelzl@56949
  1194
  and not_Inf: "integral\<^sup>P M f \<noteq> \<infinity>"
hoelzl@56949
  1195
  shows "(emeasure M) (f -` {\<infinity>} \<inter> space M) = 0"
hoelzl@56949
  1196
proof -
hoelzl@56949
  1197
  have "\<infinity> * (emeasure M) (f -` {\<infinity>} \<inter> space M) = (\<integral>\<^sup>+ x. \<infinity> * indicator (f -` {\<infinity>} \<inter> space M) x \<partial>M)"
hoelzl@56949
  1198
    using f by (subst positive_integral_cmult_indicator) (auto simp: measurable_sets)
hoelzl@56949
  1199
  also have "\<dots> \<le> integral\<^sup>P M (\<lambda>x. max 0 (f x))"
hoelzl@56949
  1200
    by (auto intro!: positive_integral_mono simp: indicator_def max_def)
hoelzl@56949
  1201
  finally have "\<infinity> * (emeasure M) (f -` {\<infinity>} \<inter> space M) \<le> integral\<^sup>P M f"
hoelzl@56949
  1202
    by (simp add: positive_integral_max_0)
hoelzl@56949
  1203
  moreover have "0 \<le> (emeasure M) (f -` {\<infinity>} \<inter> space M)"
hoelzl@56949
  1204
    by (rule emeasure_nonneg)
hoelzl@56949
  1205
  ultimately show ?thesis
hoelzl@56949
  1206
    using assms by (auto split: split_if_asm)
hoelzl@56949
  1207
qed
hoelzl@56949
  1208
hoelzl@56949
  1209
lemma positive_integral_PInf_AE:
hoelzl@56949
  1210
  assumes "f \<in> borel_measurable M" "integral\<^sup>P M f \<noteq> \<infinity>" shows "AE x in M. f x \<noteq> \<infinity>"
hoelzl@56949
  1211
proof (rule AE_I)
hoelzl@56949
  1212
  show "(emeasure M) (f -` {\<infinity>} \<inter> space M) = 0"
hoelzl@56949
  1213
    by (rule positive_integral_PInf[OF assms])
hoelzl@56949
  1214
  show "f -` {\<infinity>} \<inter> space M \<in> sets M"
hoelzl@56949
  1215
    using assms by (auto intro: borel_measurable_vimage)
hoelzl@56949
  1216
qed auto
hoelzl@56949
  1217
hoelzl@56949
  1218
lemma simple_integral_PInf:
hoelzl@56949
  1219
  assumes "simple_function M f" "\<And>x. 0 \<le> f x"
hoelzl@56949
  1220
  and "integral\<^sup>S M f \<noteq> \<infinity>"
hoelzl@56949
  1221
  shows "(emeasure M) (f -` {\<infinity>} \<inter> space M) = 0"
hoelzl@56949
  1222
proof (rule positive_integral_PInf)
hoelzl@56949
  1223
  show "f \<in> borel_measurable M" using assms by (auto intro: borel_measurable_simple_function)
hoelzl@56949
  1224
  show "integral\<^sup>P M f \<noteq> \<infinity>"
hoelzl@56949
  1225
    using assms by (simp add: positive_integral_eq_simple_integral)
hoelzl@56949
  1226
qed
hoelzl@56949
  1227
hoelzl@47694
  1228
lemma positive_integral_diff:
hoelzl@41981
  1229
  assumes f: "f \<in> borel_measurable M"
hoelzl@47694
  1230
  and g: "g \<in> borel_measurable M" "AE x in M. 0 \<le> g x"
wenzelm@53015
  1231
  and fin: "integral\<^sup>P M g \<noteq> \<infinity>"
hoelzl@47694
  1232
  and mono: "AE x in M. g x \<le> f x"
wenzelm@53015
  1233
  shows "(\<integral>\<^sup>+ x. f x - g x \<partial>M) = integral\<^sup>P M f - integral\<^sup>P M g"
hoelzl@38656
  1234
proof -
hoelzl@47694
  1235
  have diff: "(\<lambda>x. f x - g x) \<in> borel_measurable M" "AE x in M. 0 \<le> f x - g x"
hoelzl@43920
  1236
    using assms by (auto intro: ereal_diff_positive)
hoelzl@47694
  1237
  have pos_f: "AE x in M. 0 \<le> f x" using mono g by auto
hoelzl@43920
  1238
  { fix a b :: ereal assume "0 \<le> a" "a \<noteq> \<infinity>" "0 \<le> b" "a \<le> b" then have "b - a + a = b"
hoelzl@43920
  1239
      by (cases rule: ereal2_cases[of a b]) auto }
hoelzl@41981
  1240
  note * = this
hoelzl@47694
  1241
  then have "AE x in M. f x = f x - g x + g x"
hoelzl@41981
  1242
    using mono positive_integral_noteq_infinite[OF g fin] assms by auto
wenzelm@53015
  1243
  then have **: "integral\<^sup>P M f = (\<integral>\<^sup>+x. f x - g x \<partial>M) + integral\<^sup>P M g"
hoelzl@41981
  1244
    unfolding positive_integral_add[OF diff g, symmetric]
hoelzl@41981
  1245
    by (rule positive_integral_cong_AE)
hoelzl@41981
  1246
  show ?thesis unfolding **
hoelzl@47694
  1247
    using fin positive_integral_positive[of M g]
wenzelm@53015
  1248
    by (cases rule: ereal2_cases[of "\<integral>\<^sup>+ x. f x - g x \<partial>M" "integral\<^sup>P M g"]) auto
hoelzl@38656
  1249
qed
hoelzl@38656
  1250
hoelzl@47694
  1251
lemma positive_integral_suminf:
hoelzl@47694
  1252
  assumes f: "\<And>i. f i \<in> borel_measurable M" "\<And>i. AE x in M. 0 \<le> f i x"
wenzelm@53015
  1253
  shows "(\<integral>\<^sup>+ x. (\<Sum>i. f i x) \<partial>M) = (\<Sum>i. integral\<^sup>P M (f i))"
hoelzl@38656
  1254
proof -
hoelzl@47694
  1255
  have all_pos: "AE x in M. \<forall>i. 0 \<le> f i x"
hoelzl@41981
  1256
    using assms by (auto simp: AE_all_countable)
wenzelm@53015
  1257
  have "(\<Sum>i. integral\<^sup>P M (f i)) = (SUP n. \<Sum>i<n. integral\<^sup>P M (f i))"
haftmann@56212
  1258
    using positive_integral_positive by (rule suminf_ereal_eq_SUP)
wenzelm@53015
  1259
  also have "\<dots> = (SUP n. \<integral>\<^sup>+x. (\<Sum>i<n. f i x) \<partial>M)"
hoelzl@41981
  1260
    unfolding positive_integral_setsum[OF f] ..
wenzelm@53015
  1261
  also have "\<dots> = \<integral>\<^sup>+x. (SUP n. \<Sum>i<n. f i x) \<partial>M" using f all_pos
hoelzl@41981
  1262
    by (intro positive_integral_monotone_convergence_SUP_AE[symmetric])
hoelzl@41981
  1263
       (elim AE_mp, auto simp: setsum_nonneg simp del: setsum_lessThan_Suc intro!: AE_I2 setsum_mono3)
wenzelm@53015
  1264
  also have "\<dots> = \<integral>\<^sup>+x. (\<Sum>i. f i x) \<partial>M" using all_pos
haftmann@56212
  1265
    by (intro positive_integral_cong_AE) (auto simp: suminf_ereal_eq_SUP)
hoelzl@41981
  1266
  finally show ?thesis by simp
hoelzl@38656
  1267
qed
hoelzl@38656
  1268
hoelzl@38656
  1269
text {* Fatou's lemma: convergence theorem on limes inferior *}
hoelzl@47694
  1270
lemma positive_integral_lim_INF:
hoelzl@43920
  1271
  fixes u :: "nat \<Rightarrow> 'a \<Rightarrow> ereal"
hoelzl@47694
  1272
  assumes u: "\<And>i. u i \<in> borel_measurable M" "\<And>i. AE x in M. 0 \<le> u i x"
wenzelm@53015
  1273
  shows "(\<integral>\<^sup>+ x. liminf (\<lambda>n. u n x) \<partial>M) \<le> liminf (\<lambda>n. integral\<^sup>P M (u n))"
hoelzl@38656
  1274
proof -
hoelzl@47694
  1275
  have pos: "AE x in M. \<forall>i. 0 \<le> u i x" using u by (auto simp: AE_all_countable)
wenzelm@53015
  1276
  have "(\<integral>\<^sup>+ x. liminf (\<lambda>n. u n x) \<partial>M) =
wenzelm@53015
  1277
    (SUP n. \<integral>\<^sup>+ x. (INF i:{n..}. u i x) \<partial>M)"
haftmann@56212
  1278
    unfolding liminf_SUP_INF using pos u
hoelzl@41981
  1279
    by (intro positive_integral_monotone_convergence_SUP_AE)
hoelzl@44937
  1280
       (elim AE_mp, auto intro!: AE_I2 intro: INF_greatest INF_superset_mono)
wenzelm@53015
  1281
  also have "\<dots> \<le> liminf (\<lambda>n. integral\<^sup>P M (u n))"
haftmann@56212
  1282
    unfolding liminf_SUP_INF
hoelzl@44928
  1283
    by (auto intro!: SUP_mono exI INF_greatest positive_integral_mono INF_lower)
hoelzl@38656
  1284
  finally show ?thesis .
hoelzl@35582
  1285
qed
hoelzl@35582
  1286
hoelzl@47694
  1287
lemma positive_integral_null_set:
wenzelm@53015
  1288
  assumes "N \<in> null_sets M" shows "(\<integral>\<^sup>+ x. u x * indicator N x \<partial>M) = 0"
hoelzl@38656
  1289
proof -
wenzelm@53015
  1290
  have "(\<integral>\<^sup>+ x. u x * indicator N x \<partial>M) = (\<integral>\<^sup>+ x. 0 \<partial>M)"
hoelzl@40859
  1291
  proof (intro positive_integral_cong_AE AE_I)
hoelzl@40859
  1292
    show "{x \<in> space M. u x * indicator N x \<noteq> 0} \<subseteq> N"
hoelzl@40859
  1293
      by (auto simp: indicator_def)
hoelzl@47694
  1294
    show "(emeasure M) N = 0" "N \<in> sets M"
hoelzl@40859
  1295
      using assms by auto
hoelzl@35582
  1296
  qed
hoelzl@40859
  1297
  then show ?thesis by simp
hoelzl@38656
  1298
qed
hoelzl@35582
  1299
hoelzl@47694
  1300
lemma positive_integral_0_iff:
hoelzl@47694
  1301
  assumes u: "u \<in> borel_measurable M" and pos: "AE x in M. 0 \<le> u x"
wenzelm@53015
  1302
  shows "integral\<^sup>P M u = 0 \<longleftrightarrow> emeasure M {x\<in>space M. u x \<noteq> 0} = 0"
hoelzl@47694
  1303
    (is "_ \<longleftrightarrow> (emeasure M) ?A = 0")
hoelzl@35582
  1304
proof -
wenzelm@53015
  1305
  have u_eq: "(\<integral>\<^sup>+ x. u x * indicator ?A x \<partial>M) = integral\<^sup>P M u"
hoelzl@38656
  1306
    by (auto intro!: positive_integral_cong simp: indicator_def)
hoelzl@38656
  1307
  show ?thesis
hoelzl@38656
  1308
  proof
hoelzl@47694
  1309
    assume "(emeasure M) ?A = 0"
hoelzl@47694
  1310
    with positive_integral_null_set[of ?A M u] u
wenzelm@53015
  1311
    show "integral\<^sup>P M u = 0" by (simp add: u_eq null_sets_def)
hoelzl@38656
  1312
  next
hoelzl@43920
  1313
    { fix r :: ereal and n :: nat assume gt_1: "1 \<le> real n * r"
hoelzl@43920
  1314
      then have "0 < real n * r" by (cases r) (auto split: split_if_asm simp: one_ereal_def)
hoelzl@43920
  1315
      then have "0 \<le> r" by (auto simp add: ereal_zero_less_0_iff) }
hoelzl@41981
  1316
    note gt_1 = this
wenzelm@53015
  1317
    assume *: "integral\<^sup>P M u = 0"
wenzelm@46731
  1318
    let ?M = "\<lambda>n. {x \<in> space M. 1 \<le> real (n::nat) * u x}"
hoelzl@47694
  1319
    have "0 = (SUP n. (emeasure M) (?M n \<inter> ?A))"
hoelzl@38656
  1320
    proof -
hoelzl@41981
  1321
      { fix n :: nat
hoelzl@43920
  1322
        from positive_integral_Markov_inequality[OF u pos, of ?A "ereal (real n)"]
hoelzl@47694
  1323
        have "(emeasure M) (?M n \<inter> ?A) \<le> 0" unfolding u_eq * using u by simp
hoelzl@47694
  1324
        moreover have "0 \<le> (emeasure M) (?M n \<inter> ?A)" using u by auto
hoelzl@47694
  1325
        ultimately have "(emeasure M) (?M n \<inter> ?A) = 0" by auto }
hoelzl@38656
  1326
      thus ?thesis by simp
hoelzl@35582
  1327
    qed
hoelzl@47694
  1328
    also have "\<dots> = (emeasure M) (\<Union>n. ?M n \<inter> ?A)"
hoelzl@47694
  1329
    proof (safe intro!: SUP_emeasure_incseq)
hoelzl@38656
  1330
      fix n show "?M n \<inter> ?A \<in> sets M"
immler@50244
  1331
        using u by (auto intro!: sets.Int)
hoelzl@38656
  1332
    next
hoelzl@41981
  1333
      show "incseq (\<lambda>n. {x \<in> space M. 1 \<le> real n * u x} \<inter> {x \<in> space M. u x \<noteq> 0})"
hoelzl@41981
  1334
      proof (safe intro!: incseq_SucI)
hoelzl@41981
  1335
        fix n :: nat and x
hoelzl@41981
  1336
        assume *: "1 \<le> real n * u x"
wenzelm@53374
  1337
        also from gt_1[OF *] have "real n * u x \<le> real (Suc n) * u x"
hoelzl@43920
  1338
          using `0 \<le> u x` by (auto intro!: ereal_mult_right_mono)
hoelzl@41981
  1339
        finally show "1 \<le> real (Suc n) * u x" by auto
hoelzl@41981
  1340
      qed
hoelzl@38656
  1341
    qed
hoelzl@47694
  1342
    also have "\<dots> = (emeasure M) {x\<in>space M. 0 < u x}"
hoelzl@47694
  1343
    proof (safe intro!: arg_cong[where f="(emeasure M)"] dest!: gt_1)
hoelzl@41981
  1344
      fix x assume "0 < u x" and [simp, intro]: "x \<in> space M"
hoelzl@38656
  1345
      show "x \<in> (\<Union>n. ?M n \<inter> ?A)"
hoelzl@38656
  1346
      proof (cases "u x")
hoelzl@41981
  1347
        case (real r) with `0 < u x` have "0 < r" by auto
hoelzl@41981
  1348
        obtain j :: nat where "1 / r \<le> real j" using real_arch_simple ..
hoelzl@41981
  1349
        hence "1 / r * r \<le> real j * r" unfolding mult_le_cancel_right using `0 < r` by auto
hoelzl@41981
  1350
        hence "1 \<le> real j * r" using real `0 < r` by auto
hoelzl@43920
  1351
        thus ?thesis using `0 < r` real by (auto simp: one_ereal_def)
hoelzl@41981
  1352
      qed (insert `0 < u x`, auto)
hoelzl@41981
  1353
    qed auto
hoelzl@47694
  1354
    finally have "(emeasure M) {x\<in>space M. 0 < u x} = 0" by simp
hoelzl@41981
  1355
    moreover
hoelzl@47694
  1356
    from pos have "AE x in M. \<not> (u x < 0)" by auto
hoelzl@47694
  1357
    then have "(emeasure M) {x\<in>space M. u x < 0} = 0"
hoelzl@47694
  1358
      using AE_iff_null[of M] u by auto
hoelzl@47694
  1359
    moreover have "(emeasure M) {x\<in>space M. u x \<noteq> 0} = (emeasure M) {x\<in>space M. u x < 0} + (emeasure M) {x\<in>space M. 0 < u x}"
hoelzl@47694
  1360
      using u by (subst plus_emeasure) (auto intro!: arg_cong[where f="emeasure M"])
hoelzl@47694
  1361
    ultimately show "(emeasure M) ?A = 0" by simp
hoelzl@35582
  1362
  qed
hoelzl@35582
  1363
qed
hoelzl@35582
  1364
hoelzl@47694
  1365
lemma positive_integral_0_iff_AE:
hoelzl@41705
  1366
  assumes u: "u \<in> borel_measurable M"
wenzelm@53015
  1367
  shows "integral\<^sup>P M u = 0 \<longleftrightarrow> (AE x in M. u x \<le> 0)"
hoelzl@41705
  1368
proof -
hoelzl@41981
  1369
  have sets: "{x\<in>space M. max 0 (u x) \<noteq> 0} \<in> sets M"
hoelzl@41705
  1370
    using u by auto
hoelzl@41981
  1371
  from positive_integral_0_iff[of "\<lambda>x. max 0 (u x)"]
wenzelm@53015
  1372
  have "integral\<^sup>P M u = 0 \<longleftrightarrow> (AE x in M. max 0 (u x) = 0)"
hoelzl@41981
  1373
    unfolding positive_integral_max_0
hoelzl@47694
  1374
    using AE_iff_null[OF sets] u by auto
hoelzl@47694
  1375
  also have "\<dots> \<longleftrightarrow> (AE x in M. u x \<le> 0)" by (auto split: split_max)
hoelzl@41981
  1376
  finally show ?thesis .
hoelzl@41705
  1377
qed
hoelzl@41705
  1378
hoelzl@50001
  1379
lemma AE_iff_positive_integral: 
wenzelm@53015
  1380
  "{x\<in>space M. P x} \<in> sets M \<Longrightarrow> (AE x in M. P x) \<longleftrightarrow> integral\<^sup>P M (indicator {x. \<not> P x}) = 0"
immler@50244
  1381
  by (subst positive_integral_0_iff_AE) (auto simp: one_ereal_def zero_ereal_def
immler@50244
  1382
    sets.sets_Collect_neg indicator_def[abs_def] measurable_If)
hoelzl@50001
  1383
hoelzl@47694
  1384
lemma positive_integral_const_If:
wenzelm@53015
  1385
  "(\<integral>\<^sup>+x. a \<partial>M) = (if 0 \<le> a then a * (emeasure M) (space M) else 0)"
hoelzl@42991
  1386
  by (auto intro!: positive_integral_0_iff_AE[THEN iffD2])
hoelzl@42991
  1387
hoelzl@47694
  1388
lemma positive_integral_subalgebra:
hoelzl@49799
  1389
  assumes f: "f \<in> borel_measurable N" "\<And>x. 0 \<le> f x"
hoelzl@47694
  1390
  and N: "sets N \<subseteq> sets M" "space N = space M" "\<And>A. A \<in> sets N \<Longrightarrow> emeasure N A = emeasure M A"
wenzelm@53015
  1391
  shows "integral\<^sup>P N f = integral\<^sup>P M f"
hoelzl@39092
  1392
proof -
hoelzl@49799
  1393
  have [simp]: "\<And>f :: 'a \<Rightarrow> ereal. f \<in> borel_measurable N \<Longrightarrow> f \<in> borel_measurable M"
hoelzl@49799
  1394
    using N by (auto simp: measurable_def)
hoelzl@49799
  1395
  have [simp]: "\<And>P. (AE x in N. P x) \<Longrightarrow> (AE x in M. P x)"
hoelzl@49799
  1396
    using N by (auto simp add: eventually_ae_filter null_sets_def)
hoelzl@49799
  1397
  have [simp]: "\<And>A. A \<in> sets N \<Longrightarrow> A \<in> sets M"
hoelzl@49799
  1398
    using N by auto
hoelzl@49799
  1399
  from f show ?thesis
hoelzl@49799
  1400
    apply induct
hoelzl@49799
  1401
    apply (simp_all add: positive_integral_add positive_integral_cmult positive_integral_monotone_convergence_SUP N)
hoelzl@49799
  1402
    apply (auto intro!: positive_integral_cong cong: positive_integral_cong simp: N(2)[symmetric])
hoelzl@49799
  1403
    done
hoelzl@39092
  1404
qed
hoelzl@39092
  1405
hoelzl@50097
  1406
lemma positive_integral_nat_function:
hoelzl@50097
  1407
  fixes f :: "'a \<Rightarrow> nat"
hoelzl@50097
  1408
  assumes "f \<in> measurable M (count_space UNIV)"
wenzelm@53015
  1409
  shows "(\<integral>\<^sup>+x. ereal (of_nat (f x)) \<partial>M) = (\<Sum>t. emeasure M {x\<in>space M. t < f x})"
hoelzl@50097
  1410
proof -
hoelzl@50097
  1411
  def F \<equiv> "\<lambda>i. {x\<in>space M. i < f x}"
hoelzl@50097
  1412
  with assms have [measurable]: "\<And>i. F i \<in> sets M"
hoelzl@50097
  1413
    by auto
hoelzl@50097
  1414
hoelzl@50097
  1415
  { fix x assume "x \<in> space M"
hoelzl@50097
  1416
    have "(\<lambda>i. if i < f x then 1 else 0) sums (of_nat (f x)::real)"
hoelzl@50097
  1417
      using sums_If_finite[of "\<lambda>i. i < f x" "\<lambda>_. 1::real"] by simp
hoelzl@50097
  1418
    then have "(\<lambda>i. ereal(if i < f x then 1 else 0)) sums (ereal(of_nat(f x)))"
hoelzl@50097
  1419
      unfolding sums_ereal .
hoelzl@50097
  1420
    moreover have "\<And>i. ereal (if i < f x then 1 else 0) = indicator (F i) x"
hoelzl@50097
  1421
      using `x \<in> space M` by (simp add: one_ereal_def F_def)
hoelzl@50097
  1422
    ultimately have "ereal(of_nat(f x)) = (\<Sum>i. indicator (F i) x)"
hoelzl@50097
  1423
      by (simp add: sums_iff) }
wenzelm@53015
  1424
  then have "(\<integral>\<^sup>+x. ereal (of_nat (f x)) \<partial>M) = (\<integral>\<^sup>+x. (\<Sum>i. indicator (F i) x) \<partial>M)"
hoelzl@50097
  1425
    by (simp cong: positive_integral_cong)
hoelzl@50097
  1426
  also have "\<dots> = (\<Sum>i. emeasure M (F i))"
hoelzl@50097
  1427
    by (simp add: positive_integral_suminf)
hoelzl@50097
  1428
  finally show ?thesis
hoelzl@50097
  1429
    by (simp add: F_def)
hoelzl@50097
  1430
qed
hoelzl@50097
  1431
hoelzl@35692
  1432
section "Lebesgue Integral"
hoelzl@35692
  1433
hoelzl@47694
  1434
definition integrable :: "'a measure \<Rightarrow> ('a \<Rightarrow> real) \<Rightarrow> bool" where
hoelzl@41689
  1435
  "integrable M f \<longleftrightarrow> f \<in> borel_measurable M \<and>
wenzelm@53015
  1436
    (\<integral>\<^sup>+ x. ereal (f x) \<partial>M) \<noteq> \<infinity> \<and> (\<integral>\<^sup>+ x. ereal (- f x) \<partial>M) \<noteq> \<infinity>"
hoelzl@35692
  1437
hoelzl@50003
  1438
lemma borel_measurable_integrable[measurable_dest]:
hoelzl@50003
  1439
  "integrable M f \<Longrightarrow> f \<in> borel_measurable M"
hoelzl@50003
  1440
  by (auto simp: integrable_def)
hoelzl@50003
  1441
hoelzl@41689
  1442
lemma integrableD[dest]:
hoelzl@41689
  1443
  assumes "integrable M f"
wenzelm@53015
  1444
  shows "f \<in> borel_measurable M" "(\<integral>\<^sup>+ x. ereal (f x) \<partial>M) \<noteq> \<infinity>" "(\<integral>\<^sup>+ x. ereal (- f x) \<partial>M) \<noteq> \<infinity>"
hoelzl@38656
  1445
  using assms unfolding integrable_def by auto
hoelzl@35692
  1446
wenzelm@53015
  1447
definition lebesgue_integral :: "'a measure \<Rightarrow> ('a \<Rightarrow> real) \<Rightarrow> real" ("integral\<^sup>L") where
wenzelm@53015
  1448
  "integral\<^sup>L M f = real ((\<integral>\<^sup>+ x. ereal (f x) \<partial>M)) - real ((\<integral>\<^sup>+ x. ereal (- f x) \<partial>M))"
hoelzl@41689
  1449
hoelzl@41689
  1450
syntax
hoelzl@47694
  1451
  "_lebesgue_integral" :: "pttrn \<Rightarrow> real \<Rightarrow> 'a measure \<Rightarrow> real" ("\<integral> _. _ \<partial>_" [60,61] 110)
hoelzl@41689
  1452
hoelzl@41689
  1453
translations
hoelzl@47694
  1454
  "\<integral> x. f \<partial>M" == "CONST lebesgue_integral M (%x. f)"
hoelzl@38656
  1455
hoelzl@47694
  1456
lemma integrableE:
hoelzl@41981
  1457
  assumes "integrable M f"
hoelzl@41981
  1458
  obtains r q where
wenzelm@53015
  1459
    "(\<integral>\<^sup>+x. ereal (f x)\<partial>M) = ereal r"
wenzelm@53015
  1460
    "(\<integral>\<^sup>+x. ereal (-f x)\<partial>M) = ereal q"
wenzelm@53015
  1461
    "f \<in> borel_measurable M" "integral\<^sup>L M f = r - q"
hoelzl@41981
  1462
  using assms unfolding integrable_def lebesgue_integral_def
hoelzl@47694
  1463
  using positive_integral_positive[of M "\<lambda>x. ereal (f x)"]
hoelzl@47694
  1464
  using positive_integral_positive[of M "\<lambda>x. ereal (-f x)"]
wenzelm@53015
  1465
  by (cases rule: ereal2_cases[of "(\<integral>\<^sup>+x. ereal (-f x)\<partial>M)" "(\<integral>\<^sup>+x. ereal (f x)\<partial>M)"]) auto
hoelzl@41981
  1466
hoelzl@47694
  1467
lemma integral_cong:
hoelzl@41689
  1468
  assumes "\<And>x. x \<in> space M \<Longrightarrow> f x = g x"
wenzelm@53015
  1469
  shows "integral\<^sup>L M f = integral\<^sup>L M g"
hoelzl@41689
  1470
  using assms by (simp cong: positive_integral_cong add: lebesgue_integral_def)
hoelzl@35582
  1471
hoelzl@47694
  1472
lemma integral_cong_AE:
hoelzl@47694
  1473
  assumes cong: "AE x in M. f x = g x"
wenzelm@53015
  1474
  shows "integral\<^sup>L M f = integral\<^sup>L M g"
hoelzl@40859
  1475
proof -
hoelzl@47694
  1476
  have *: "AE x in M. ereal (f x) = ereal (g x)"
hoelzl@47694
  1477
    "AE x in M. ereal (- f x) = ereal (- g x)" using cong by auto
hoelzl@41981
  1478
  show ?thesis
hoelzl@41981
  1479
    unfolding *[THEN positive_integral_cong_AE] lebesgue_integral_def ..
hoelzl@40859
  1480
qed
hoelzl@40859
  1481
hoelzl@47694
  1482
lemma integrable_cong_AE:
hoelzl@43339
  1483
  assumes borel: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
hoelzl@47694
  1484
  assumes "AE x in M. f x = g x"
hoelzl@43339
  1485
  shows "integrable M f = integrable M g"
hoelzl@43339
  1486
proof -
wenzelm@53015
  1487
  have "(\<integral>\<^sup>+ x. ereal (f x) \<partial>M) = (\<integral>\<^sup>+ x. ereal (g x) \<partial>M)"
wenzelm@53015
  1488
    "(\<integral>\<^sup>+ x. ereal (- f x) \<partial>M) = (\<integral>\<^sup>+ x. ereal (- g x) \<partial>M)"
hoelzl@43339
  1489
    using assms by (auto intro!: positive_integral_cong_AE)
hoelzl@43339
  1490
  with assms show ?thesis
hoelzl@43339
  1491
    by (auto simp: integrable_def)
hoelzl@43339
  1492
qed
hoelzl@43339
  1493
hoelzl@47694
  1494
lemma integrable_cong:
hoelzl@41689
  1495
  "(\<And>x. x \<in> space M \<Longrightarrow> f x = g x) \<Longrightarrow> integrable M f \<longleftrightarrow> integrable M g"
hoelzl@38656
  1496
  by (simp cong: positive_integral_cong measurable_cong add: integrable_def)
hoelzl@38656
  1497
hoelzl@49775
  1498
lemma integral_mono_AE:
hoelzl@49775
  1499
  assumes fg: "integrable M f" "integrable M g"
hoelzl@49775
  1500
  and mono: "AE t in M. f t \<le> g t"
wenzelm@53015
  1501
  shows "integral\<^sup>L M f \<le> integral\<^sup>L M g"
hoelzl@49775
  1502
proof -
hoelzl@49775
  1503
  have "AE x in M. ereal (f x) \<le> ereal (g x)"
hoelzl@49775
  1504
    using mono by auto
hoelzl@49775
  1505
  moreover have "AE x in M. ereal (- g x) \<le> ereal (- f x)"
hoelzl@49775
  1506
    using mono by auto
hoelzl@49775
  1507
  ultimately show ?thesis using fg
hoelzl@49775
  1508
    by (auto intro!: add_mono positive_integral_mono_AE real_of_ereal_positive_mono
haftmann@54230
  1509
             simp: positive_integral_positive lebesgue_integral_def algebra_simps)
hoelzl@49775
  1510
qed
hoelzl@49775
  1511
hoelzl@49775
  1512
lemma integral_mono:
hoelzl@49775
  1513
  assumes "integrable M f" "integrable M g" "\<And>t. t \<in> space M \<Longrightarrow> f t \<le> g t"
wenzelm@53015
  1514
  shows "integral\<^sup>L M f \<le> integral\<^sup>L M g"
hoelzl@49775
  1515
  using assms by (auto intro: integral_mono_AE)
hoelzl@49775
  1516
hoelzl@47694
  1517
lemma positive_integral_eq_integral:
hoelzl@47694
  1518
  assumes f: "integrable M f"
hoelzl@47694
  1519
  assumes nonneg: "AE x in M. 0 \<le> f x" 
wenzelm@53015
  1520
  shows "(\<integral>\<^sup>+ x. ereal (f x) \<partial>M) = integral\<^sup>L M f"
hoelzl@47694
  1521
proof -
wenzelm@53015
  1522
  have "(\<integral>\<^sup>+ x. max 0 (ereal (- f x)) \<partial>M) = (\<integral>\<^sup>+ x. 0 \<partial>M)"
hoelzl@47694
  1523
    using nonneg by (intro positive_integral_cong_AE) (auto split: split_max)
hoelzl@47694
  1524
  with f positive_integral_positive show ?thesis
wenzelm@53015
  1525
    by (cases "\<integral>\<^sup>+ x. ereal (f x) \<partial>M")
hoelzl@47694
  1526
       (auto simp add: lebesgue_integral_def positive_integral_max_0 integrable_def)
hoelzl@47694
  1527
qed
hoelzl@47694
  1528
  
hoelzl@47694
  1529
lemma integral_eq_positive_integral:
hoelzl@41981
  1530
  assumes f: "\<And>x. 0 \<le> f x"
wenzelm@53015
  1531
  shows "integral\<^sup>L M f = real (\<integral>\<^sup>+ x. ereal (f x) \<partial>M)"
hoelzl@35582
  1532
proof -
hoelzl@43920
  1533
  { fix x have "max 0 (ereal (- f x)) = 0" using f[of x] by (simp split: split_max) }
wenzelm@53015
  1534
  then have "0 = (\<integral>\<^sup>+ x. max 0 (ereal (- f x)) \<partial>M)" by simp
wenzelm@53015
  1535
  also have "\<dots> = (\<integral>\<^sup>+ x. ereal (- f x) \<partial>M)" unfolding positive_integral_max_0 ..
hoelzl@41981
  1536
  finally show ?thesis
hoelzl@41981
  1537
    unfolding lebesgue_integral_def by simp
hoelzl@35582
  1538
qed
hoelzl@35582
  1539
hoelzl@47694
  1540
lemma integral_minus[intro, simp]:
hoelzl@41689
  1541
  assumes "integrable M f"
wenzelm@53015
  1542
  shows "integrable M (\<lambda>x. - f x)" "(\<integral>x. - f x \<partial>M) = - integral\<^sup>L M f"
hoelzl@41689
  1543
  using assms by (auto simp: integrable_def lebesgue_integral_def)
hoelzl@38656
  1544
hoelzl@47694
  1545
lemma integral_minus_iff[simp]:
hoelzl@42991
  1546
  "integrable M (\<lambda>x. - f x) \<longleftrightarrow> integrable M f"
hoelzl@42991
  1547
proof
hoelzl@42991
  1548
  assume "integrable M (\<lambda>x. - f x)"
hoelzl@42991
  1549
  then have "integrable M (\<lambda>x. - (- f x))"
hoelzl@42991
  1550
    by (rule integral_minus)
hoelzl@42991
  1551
  then show "integrable M f" by simp
hoelzl@42991
  1552
qed (rule integral_minus)
hoelzl@42991
  1553
hoelzl@47694
  1554
lemma integral_of_positive_diff:
hoelzl@41689
  1555
  assumes integrable: "integrable M u" "integrable M v"
hoelzl@38656
  1556
  and f_def: "\<And>x. f x = u x - v x" and pos: "\<And>x. 0 \<le> u x" "\<And>x. 0 \<le> v x"
wenzelm@53015
  1557
  shows "integrable M f" and "integral\<^sup>L M f = integral\<^sup>L M u - integral\<^sup>L M v"
hoelzl@35582
  1558
proof -
wenzelm@46731
  1559
  let ?f = "\<lambda>x. max 0 (ereal (f x))"
wenzelm@46731
  1560
  let ?mf = "\<lambda>x. max 0 (ereal (- f x))"
wenzelm@46731
  1561
  let ?u = "\<lambda>x. max 0 (ereal (u x))"
wenzelm@46731
  1562
  let ?v = "\<lambda>x. max 0 (ereal (v x))"
hoelzl@38656
  1563
hoelzl@47694
  1564
  from borel_measurable_diff[of u M v] integrable
hoelzl@38656
  1565
  have f_borel: "?f \<in> borel_measurable M" and
hoelzl@38656
  1566
    mf_borel: "?mf \<in> borel_measurable M" and
hoelzl@38656
  1567
    v_borel: "?v \<in> borel_measurable M" and
hoelzl@38656
  1568
    u_borel: "?u \<in> borel_measurable M" and
hoelzl@38656
  1569
    "f \<in> borel_measurable M"
hoelzl@38656
  1570
    by (auto simp: f_def[symmetric] integrable_def)
hoelzl@35582
  1571
wenzelm@53015
  1572
  have "(\<integral>\<^sup>+ x. ereal (u x - v x) \<partial>M) \<le> integral\<^sup>P M ?u"
hoelzl@41981
  1573
    using pos by (auto intro!: positive_integral_mono simp: positive_integral_max_0)
wenzelm@53015
  1574
  moreover have "(\<integral>\<^sup>+ x. ereal (v x - u x) \<partial>M) \<le> integral\<^sup>P M ?v"
hoelzl@41981
  1575
    using pos by (auto intro!: positive_integral_mono simp: positive_integral_max_0)
hoelzl@41689
  1576
  ultimately show f: "integrable M f"
hoelzl@41689
  1577
    using `integrable M u` `integrable M v` `f \<in> borel_measurable M`
hoelzl@41981
  1578
    by (auto simp: integrable_def f_def positive_integral_max_0)
hoelzl@35582
  1579
hoelzl@38656
  1580
  have "\<And>x. ?u x + ?mf x = ?v x + ?f x"
hoelzl@41981
  1581
    unfolding f_def using pos by (simp split: split_max)
wenzelm@53015
  1582
  then have "(\<integral>\<^sup>+ x. ?u x + ?mf x \<partial>M) = (\<integral>\<^sup>+ x. ?v x + ?f x \<partial>M)" by simp
wenzelm@53015
  1583
  then have "real (integral\<^sup>P M ?u + integral\<^sup>P M ?mf) =
wenzelm@53015
  1584
      real (integral\<^sup>P M ?v + integral\<^sup>P M ?f)"
hoelzl@41981
  1585
    using positive_integral_add[OF u_borel _ mf_borel]
hoelzl@41981
  1586
    using positive_integral_add[OF v_borel _ f_borel]
hoelzl@38656
  1587
    by auto
wenzelm@53015
  1588
  then show "integral\<^sup>L M f = integral\<^sup>L M u - integral\<^sup>L M v"
hoelzl@41981
  1589
    unfolding positive_integral_max_0
hoelzl@41981
  1590
    unfolding pos[THEN integral_eq_positive_integral]
hoelzl@41981
  1591
    using integrable f by (auto elim!: integrableE)
hoelzl@35582
  1592
qed
hoelzl@35582
  1593
hoelzl@47694
  1594
lemma integral_linear:
hoelzl@41689
  1595
  assumes "integrable M f" "integrable M g" and "0 \<le> a"
hoelzl@41689
  1596
  shows "integrable M (\<lambda>t. a * f t + g t)"
wenzelm@53015
  1597
  and "(\<integral> t. a * f t + g t \<partial>M) = a * integral\<^sup>L M f + integral\<^sup>L M g" (is ?EQ)
hoelzl@38656
  1598
proof -
wenzelm@46731
  1599
  let ?f = "\<lambda>x. max 0 (ereal (f x))"
wenzelm@46731
  1600
  let ?g = "\<lambda>x. max 0 (ereal (g x))"
wenzelm@46731
  1601
  let ?mf = "\<lambda>x. max 0 (ereal (- f x))"
wenzelm@46731
  1602
  let ?mg = "\<lambda>x. max 0 (ereal (- g x))"
wenzelm@46731
  1603
  let ?p = "\<lambda>t. max 0 (a * f t) + max 0 (g t)"
wenzelm@46731
  1604
  let ?n = "\<lambda>t. max 0 (- (a * f t)) + max 0 (- g t)"
hoelzl@38656
  1605
hoelzl@41981
  1606
  from assms have linear:
wenzelm@53015
  1607
    "(\<integral>\<^sup>+ x. ereal a * ?f x + ?g x \<partial>M) = ereal a * integral\<^sup>P M ?f + integral\<^sup>P M ?g"
wenzelm@53015
  1608
    "(\<integral>\<^sup>+ x. ereal a * ?mf x + ?mg x \<partial>M) = ereal a * integral\<^sup>P M ?mf + integral\<^sup>P M ?mg"
hoelzl@41981
  1609
    by (auto intro!: positive_integral_linear simp: integrable_def)
hoelzl@35582
  1610
wenzelm@53015
  1611
  have *: "(\<integral>\<^sup>+x. ereal (- ?p x) \<partial>M) = 0" "(\<integral>\<^sup>+x. ereal (- ?n x) \<partial>M) = 0"
hoelzl@41981
  1612
    using `0 \<le> a` assms by (auto simp: positive_integral_0_iff_AE integrable_def)
hoelzl@43920
  1613
  have **: "\<And>x. ereal a * ?f x + ?g x = max 0 (ereal (?p x))"
hoelzl@43920
  1614
           "\<And>x. ereal a * ?mf x + ?mg x = max 0 (ereal (?n x))"
hoelzl@41981
  1615
    using `0 \<le> a` by (auto split: split_max simp: zero_le_mult_iff mult_le_0_iff)
hoelzl@35582
  1616
hoelzl@41689
  1617
  have "integrable M ?p" "integrable M ?n"
hoelzl@38656
  1618
      "\<And>t. a * f t + g t = ?p t - ?n t" "\<And>t. 0 \<le> ?p t" "\<And>t. 0 \<le> ?n t"
hoelzl@41981
  1619
    using linear assms unfolding integrable_def ** *
hoelzl@41981
  1620
    by (auto simp: positive_integral_max_0)
hoelzl@38656
  1621
  note diff = integral_of_positive_diff[OF this]
hoelzl@38656
  1622
hoelzl@41689
  1623
  show "integrable M (\<lambda>t. a * f t + g t)" by (rule diff)
hoelzl@41981
  1624
  from assms linear show ?EQ
hoelzl@41981
  1625
    unfolding diff(2) ** positive_integral_max_0
hoelzl@41981
  1626
    unfolding lebesgue_integral_def *
hoelzl@41981
  1627
    by (auto elim!: integrableE simp: field_simps)
hoelzl@38656
  1628
qed
hoelzl@38656
  1629
hoelzl@47694
  1630
lemma integral_add[simp, intro]:
hoelzl@41689
  1631
  assumes "integrable M f" "integrable M g"
hoelzl@41689
  1632
  shows "integrable M (\<lambda>t. f t + g t)"
wenzelm@53015
  1633
  and "(\<integral> t. f t + g t \<partial>M) = integral\<^sup>L M f + integral\<^sup>L M g"
hoelzl@38656
  1634
  using assms integral_linear[where a=1] by auto
hoelzl@38656
  1635
hoelzl@47694
  1636
lemma integral_zero[simp, intro]:
hoelzl@41689
  1637
  shows "integrable M (\<lambda>x. 0)" "(\<integral> x.0 \<partial>M) = 0"
hoelzl@41689
  1638
  unfolding integrable_def lebesgue_integral_def
hoelzl@50002
  1639
  by auto
hoelzl@35582
  1640
hoelzl@50097
  1641
lemma lebesgue_integral_uminus:
wenzelm@53015
  1642
    "(\<integral>x. - f x \<partial>M) = - integral\<^sup>L M f"
hoelzl@50097
  1643
  unfolding lebesgue_integral_def by simp
hoelzl@35582
  1644
hoelzl@47694
  1645
lemma lebesgue_integral_cmult_nonneg:
hoelzl@47694
  1646
  assumes f: "f \<in> borel_measurable M" and "0 \<le> c"
wenzelm@53015
  1647
  shows "(\<integral>x. c * f x \<partial>M) = c * integral\<^sup>L M f"
hoelzl@47694
  1648
proof -
wenzelm@53015
  1649
  { have "real (ereal c * integral\<^sup>P M (\<lambda>x. max 0 (ereal (f x)))) =
wenzelm@53015
  1650
      real (integral\<^sup>P M (\<lambda>x. ereal c * max 0 (ereal (f x))))"
hoelzl@47694
  1651
      using f `0 \<le> c` by (subst positive_integral_cmult) auto
wenzelm@53015
  1652
    also have "\<dots> = real (integral\<^sup>P M (\<lambda>x. max 0 (ereal (c * f x))))"
hoelzl@47694
  1653
      using `0 \<le> c` by (auto intro!: arg_cong[where f=real] positive_integral_cong simp: max_def zero_le_mult_iff)
wenzelm@53015
  1654
    finally have "real (integral\<^sup>P M (\<lambda>x. ereal (c * f x))) = c * real (integral\<^sup>P M (\<lambda>x. ereal (f x)))"
hoelzl@47694
  1655
      by (simp add: positive_integral_max_0) }
hoelzl@47694
  1656
  moreover
wenzelm@53015
  1657
  { have "real (ereal c * integral\<^sup>P M (\<lambda>x. max 0 (ereal (- f x)))) =
wenzelm@53015
  1658
      real (integral\<^sup>P M (\<lambda>x. ereal c * max 0 (ereal (- f x))))"
hoelzl@47694
  1659
      using f `0 \<le> c` by (subst positive_integral_cmult) auto
wenzelm@53015
  1660
    also have "\<dots> = real (integral\<^sup>P M (\<lambda>x. max 0 (ereal (- c * f x))))"
hoelzl@47694
  1661
      using `0 \<le> c` by (auto intro!: arg_cong[where f=real] positive_integral_cong simp: max_def mult_le_0_iff)
wenzelm@53015
  1662
    finally have "real (integral\<^sup>P M (\<lambda>x. ereal (- c * f x))) = c * real (integral\<^sup>P M (\<lambda>x. ereal (- f x)))"
hoelzl@47694
  1663
      by (simp add: positive_integral_max_0) }
hoelzl@47694
  1664
  ultimately show ?thesis
hoelzl@47694
  1665
    by (simp add: lebesgue_integral_def field_simps)
hoelzl@47694
  1666
qed
hoelzl@47694
  1667
hoelzl@47694
  1668
lemma lebesgue_integral_cmult:
hoelzl@47694
  1669
  assumes f: "f \<in> borel_measurable M"
wenzelm@53015
  1670
  shows "(\<integral>x. c * f x \<partial>M) = c * integral\<^sup>L M f"
hoelzl@47694
  1671
proof (cases rule: linorder_le_cases)
hoelzl@47694
  1672
  assume "0 \<le> c" with f show ?thesis by (rule lebesgue_integral_cmult_nonneg)
hoelzl@47694
  1673
next
hoelzl@47694
  1674
  assume "c \<le> 0"
hoelzl@47694
  1675
  with lebesgue_integral_cmult_nonneg[OF f, of "-c"]
hoelzl@47694
  1676
  show ?thesis
hoelzl@47694
  1677
    by (simp add: lebesgue_integral_def)
hoelzl@47694
  1678
qed
hoelzl@47694
  1679
hoelzl@50097
  1680
lemma lebesgue_integral_multc:
wenzelm@53015
  1681
  "f \<in> borel_measurable M \<Longrightarrow> (\<integral>x. f x * c \<partial>M) = integral\<^sup>L M f * c"
hoelzl@50097
  1682
  using lebesgue_integral_cmult[of f M c] by (simp add: ac_simps)
hoelzl@50097
  1683
hoelzl@47694
  1684
lemma integral_multc:
wenzelm@53015
  1685
  "integrable M f \<Longrightarrow> (\<integral> x. f x * c \<partial>M) = integral\<^sup>L M f * c"
hoelzl@50097
  1686
  by (simp add: lebesgue_integral_multc)
hoelzl@50097
  1687
hoelzl@50097
  1688
lemma integral_cmult[simp, intro]:
hoelzl@41689
  1689
  assumes "integrable M f"
hoelzl@50097
  1690
  shows "integrable M (\<lambda>t. a * f t)" (is ?P)
wenzelm@53015
  1691
  and "(\<integral> t. a * f t \<partial>M) = a * integral\<^sup>L M f" (is ?I)
hoelzl@50097
  1692
proof -
wenzelm@53015
  1693
  have "integrable M (\<lambda>t. a * f t) \<and> (\<integral> t. a * f t \<partial>M) = a * integral\<^sup>L M f"
hoelzl@50097
  1694
  proof (cases rule: le_cases)
hoelzl@50097
  1695
    assume "0 \<le> a" show ?thesis
hoelzl@50097
  1696
      using integral_linear[OF assms integral_zero(1) `0 \<le> a`]
hoelzl@50097
  1697
      by simp
hoelzl@50097
  1698
  next
hoelzl@50097
  1699
    assume "a \<le> 0" hence "0 \<le> - a" by auto
hoelzl@50097
  1700
    have *: "\<And>t. - a * t + 0 = (-a) * t" by simp
hoelzl@50097
  1701
    show ?thesis using integral_linear[OF assms integral_zero(1) `0 \<le> - a`]
hoelzl@50097
  1702
        integral_minus(1)[of M "\<lambda>t. - a * f t"]
hoelzl@50097
  1703
      unfolding * integral_zero by simp
hoelzl@50097
  1704
  qed
hoelzl@50097
  1705
  thus ?P ?I by auto
hoelzl@50097
  1706
qed
hoelzl@41096
  1707
hoelzl@47694
  1708
lemma integral_diff[simp, intro]:
hoelzl@41689
  1709
  assumes f: "integrable M f" and g: "integrable M g"
hoelzl@41689
  1710
  shows "integrable M (\<lambda>t. f t - g t)"
wenzelm@53015
  1711
  and "(\<integral> t. f t - g t \<partial>M) = integral\<^sup>L M f - integral\<^sup>L M g"
hoelzl@38656
  1712
  using integral_add[OF f integral_minus(1)[OF g]]
haftmann@54230
  1713
  unfolding integral_minus(2)[OF g]
hoelzl@38656
  1714
  by auto
hoelzl@38656
  1715
hoelzl@47694
  1716
lemma integral_indicator[simp, intro]:
hoelzl@47694
  1717
  assumes "A \<in> sets M" and "(emeasure M) A \<noteq> \<infinity>"
wenzelm@53015
  1718
  shows "integral\<^sup>L M (indicator A) = real (emeasure M A)" (is ?int)
hoelzl@41981
  1719
  and "integrable M (indicator A)" (is ?able)
hoelzl@35582
  1720
proof -
hoelzl@41981
  1721
  from `A \<in> sets M` have *:
hoelzl@43920
  1722
    "\<And>x. ereal (indicator A x) = indicator A x"
wenzelm@53015
  1723
    "(\<integral>\<^sup>+x. ereal (- indicator A x) \<partial>M) = 0"
hoelzl@43920
  1724
    by (auto split: split_indicator simp: positive_integral_0_iff_AE one_ereal_def)
hoelzl@38656
  1725
  show ?int ?able
hoelzl@41689
  1726
    using assms unfolding lebesgue_integral_def integrable_def
hoelzl@50002
  1727
    by (auto simp: *)
hoelzl@35582
  1728
qed
hoelzl@35582
  1729
hoelzl@47694
  1730
lemma integral_cmul_indicator:
hoelzl@47694
  1731
  assumes "A \<in> sets M" and "c \<noteq> 0 \<Longrightarrow> (emeasure M) A \<noteq> \<infinity>"
hoelzl@41689
  1732
  shows "integrable M (\<lambda>x. c * indicator A x)" (is ?P)
hoelzl@47694
  1733
  and "(\<integral>x. c * indicator A x \<partial>M) = c * real ((emeasure M) A)" (is ?I)
hoelzl@38656
  1734
proof -
hoelzl@38656
  1735
  show ?P
hoelzl@38656
  1736
  proof (cases "c = 0")
hoelzl@38656
  1737
    case False with assms show ?thesis by simp
hoelzl@38656
  1738
  qed simp
hoelzl@35582
  1739
hoelzl@38656
  1740
  show ?I
hoelzl@38656
  1741
  proof (cases "c = 0")
hoelzl@38656
  1742
    case False with assms show ?thesis by simp
hoelzl@38656
  1743
  qed simp
hoelzl@38656
  1744
qed
hoelzl@35582
  1745
hoelzl@47694
  1746
lemma integral_setsum[simp, intro]:
hoelzl@41689
  1747
  assumes "\<And>n. n \<in> S \<Longrightarrow> integrable M (f n)"
wenzelm@53015
  1748
  shows "(\<integral>x. (\<Sum> i \<in> S. f i x) \<partial>M) = (\<Sum> i \<in> S. integral\<^sup>L M (f i))" (is "?int S")
hoelzl@41689
  1749
    and "integrable M (\<lambda>x. \<Sum> i \<in> S. f i x)" (is "?I S")
hoelzl@35582
  1750
proof -
hoelzl@38656
  1751
  have "?int S \<and> ?I S"
hoelzl@38656
  1752
  proof (cases "finite S")
hoelzl@38656
  1753
    assume "finite S"
hoelzl@38656
  1754
    from this assms show ?thesis by (induct S) simp_all
hoelzl@38656
  1755
  qed simp
hoelzl@35582
  1756
  thus "?int S" and "?I S" by auto
hoelzl@35582
  1757
qed
hoelzl@35582
  1758
hoelzl@49775
  1759
lemma integrable_bound:
hoelzl@49775
  1760
  assumes "integrable M f" and f: "AE x in M. \<bar>g x\<bar> \<le> f x"
hoelzl@49775
  1761
  assumes borel: "g \<in> borel_measurable M"
hoelzl@49775
  1762
  shows "integrable M g"
hoelzl@49775
  1763
proof -
wenzelm@53015
  1764
  have "(\<integral>\<^sup>+ x. ereal (g x) \<partial>M) \<le> (\<integral>\<^sup>+ x. ereal \<bar>g x\<bar> \<partial>M)"
hoelzl@49775
  1765
    by (auto intro!: positive_integral_mono)
wenzelm@53015
  1766
  also have "\<dots> \<le> (\<integral>\<^sup>+ x. ereal (f x) \<partial>M)"
hoelzl@49775
  1767
    using f by (auto intro!: positive_integral_mono_AE)
hoelzl@49775
  1768
  also have "\<dots> < \<infinity>"
hoelzl@49775
  1769
    using `integrable M f` unfolding integrable_def by auto
wenzelm@53015
  1770
  finally have pos: "(\<integral>\<^sup>+ x. ereal (g x) \<partial>M) < \<infinity>" .
hoelzl@49775
  1771
wenzelm@53015
  1772
  have "(\<integral>\<^sup>+ x. ereal (- g x) \<partial>M) \<le> (\<integral>\<^sup>+ x. ereal (\<bar>g x\<bar>) \<partial>M)"
hoelzl@49775
  1773
    by (auto intro!: positive_integral_mono)
wenzelm@53015
  1774
  also have "\<dots> \<le> (\<integral>\<^sup>+ x. ereal (f x) \<partial>M)"
hoelzl@49775
  1775
    using f by (auto intro!: positive_integral_mono_AE)
hoelzl@49775
  1776
  also have "\<dots> < \<infinity>"
hoelzl@49775
  1777
    using `integrable M f` unfolding integrable_def by auto
wenzelm@53015
  1778
  finally have neg: "(\<integral>\<^sup>+ x. ereal (- g x) \<partial>M) < \<infinity>" .
hoelzl@49775
  1779
hoelzl@49775
  1780
  from neg pos borel show ?thesis
hoelzl@49775
  1781
    unfolding integrable_def by auto
hoelzl@49775
  1782
qed
hoelzl@49775
  1783
hoelzl@47694
  1784
lemma integrable_abs:
hoelzl@50003
  1785
  assumes f[measurable]: "integrable M f"
hoelzl@41689
  1786
  shows "integrable M (\<lambda> x. \<bar>f x\<bar>)"
hoelzl@36624
  1787
proof -
wenzelm@53015
  1788
  from assms have *: "(\<integral>\<^sup>+x. ereal (- \<bar>f x\<bar>)\<partial>M) = 0"
hoelzl@43920
  1789
    "\<And>x. ereal \<bar>f x\<bar> = max 0 (ereal (f x)) + max 0 (ereal (- f x))"
hoelzl@41981
  1790
    by (auto simp: integrable_def positive_integral_0_iff_AE split: split_max)
hoelzl@41981
  1791
  with assms show ?thesis
hoelzl@41981
  1792
    by (simp add: positive_integral_add positive_integral_max_0 integrable_def)
hoelzl@38656
  1793
qed
hoelzl@38656
  1794
hoelzl@47694
  1795
lemma integral_subalgebra:
hoelzl@41545
  1796
  assumes borel: "f \<in> borel_measurable N"
hoelzl@47694
  1797
  and N: "sets N \<subseteq> sets M" "space N = space M" "\<And>A. A \<in> sets N \<Longrightarrow> emeasure N A = emeasure M A"
hoelzl@41689
  1798
  shows "integrable N f \<longleftrightarrow> integrable M f" (is ?P)
wenzelm@53015
  1799
    and "integral\<^sup>L N f = integral\<^sup>L M f" (is ?I)
hoelzl@41545
  1800
proof -
wenzelm@53015
  1801
  have "(\<integral>\<^sup>+ x. max 0 (ereal (f x)) \<partial>N) = (\<integral>\<^sup>+ x. max 0 (ereal (f x)) \<partial>M)"
wenzelm@53015
  1802
       "(\<integral>\<^sup>+ x. max 0 (ereal (- f x)) \<partial>N) = (\<integral>\<^sup>+ x. max 0 (ereal (- f x)) \<partial>M)"
hoelzl@47694
  1803
    using borel by (auto intro!: positive_integral_subalgebra N)
hoelzl@41981
  1804
  moreover have "f \<in> borel_measurable M \<longleftrightarrow> f \<in> borel_measurable N"
hoelzl@41545
  1805
    using assms unfolding measurable_def by auto
hoelzl@41981
  1806
  ultimately show ?P ?I
hoelzl@41981
  1807
    by (auto simp: integrable_def lebesgue_integral_def positive_integral_max_0)
hoelzl@41545
  1808
qed
hoelzl@41545
  1809
hoelzl@47694
  1810
lemma lebesgue_integral_nonneg:
wenzelm@53015
  1811
  assumes ae: "(AE x in M. 0 \<le> f x)" shows "0 \<le> integral\<^sup>L M f"
hoelzl@47694
  1812
proof -
wenzelm@53015
  1813
  have "(\<integral>\<^sup>+x. max 0 (ereal (- f x)) \<partial>M) = (\<integral>\<^sup>+x. 0 \<partial>M)"
hoelzl@47694
  1814
    using ae by (intro positive_integral_cong_AE) (auto simp: max_def)
hoelzl@47694
  1815
  then show ?thesis
hoelzl@47694
  1816
    by (auto simp: lebesgue_integral_def positive_integral_max_0
hoelzl@47694
  1817
             intro!: real_of_ereal_pos positive_integral_positive)
hoelzl@47694
  1818
qed
hoelzl@47694
  1819
hoelzl@47694
  1820
lemma integrable_abs_iff:
hoelzl@41689
  1821
  "f \<in> borel_measurable M \<Longrightarrow> integrable M (\<lambda> x. \<bar>f x\<bar>) \<longleftrightarrow> integrable M f"
hoelzl@38656
  1822
  by (auto intro!: integrable_bound[where g=f] integrable_abs)
hoelzl@38656
  1823
hoelzl@47694
  1824
lemma integrable_max:
hoelzl@41689
  1825
  assumes int: "integrable M f" "integrable M g"
hoelzl@41689
  1826
  shows "integrable M (\<lambda> x. max (f x) (g x))"
hoelzl@38656
  1827
proof (rule integrable_bound)
hoelzl@41689
  1828
  show "integrable M (\<lambda>x. \<bar>f x\<bar> + \<bar>g x\<bar>)"
hoelzl@38656
  1829
    using int by (simp add: integrable_abs)
hoelzl@38656
  1830
  show "(\<lambda>x. max (f x) (g x)) \<in> borel_measurable M"
hoelzl@38656
  1831
    using int unfolding integrable_def by auto
hoelzl@49775
  1832
qed auto
hoelzl@38656
  1833
hoelzl@47694
  1834
lemma integrable_min:
hoelzl@41689
  1835
  assumes int: "integrable M f" "integrable M g"
hoelzl@41689
  1836
  shows "integrable M (\<lambda> x. min (f x) (g x))"
hoelzl@38656
  1837
proof (rule integrable_bound)
hoelzl@41689
  1838
  show "integrable M (\<lambda>x. \<bar>f x\<bar> + \<bar>g x\<bar>)"
hoelzl@38656
  1839
    using int by (simp add: integrable_abs)
hoelzl@38656
  1840
  show "(\<lambda>x. min (f x) (g x)) \<in> borel_measurable M"
hoelzl@38656
  1841
    using int unfolding integrable_def by auto
hoelzl@49775
  1842
qed auto
hoelzl@38656
  1843
hoelzl@47694
  1844
lemma integral_triangle_inequality:
hoelzl@41689
  1845
  assumes "integrable M f"
wenzelm@53015
  1846
  shows "\<bar>integral\<^sup>L M f\<bar> \<le> (\<integral>x. \<bar>f x\<bar> \<partial>M)"
hoelzl@38656
  1847
proof -
wenzelm@53015
  1848
  have "\<bar>integral\<^sup>L M f\<bar> = max (integral\<^sup>L M f) (- integral\<^sup>L M f)" by auto
hoelzl@41689
  1849
  also have "\<dots> \<le> (\<integral>x. \<bar>f x\<bar> \<partial>M)"
hoelzl@47694
  1850
      using assms integral_minus(2)[of M f, symmetric]
hoelzl@38656
  1851
      by (auto intro!: integral_mono integrable_abs simp del: integral_minus)
hoelzl@38656
  1852
  finally show ?thesis .
hoelzl@36624
  1853
qed
hoelzl@36624
  1854
hoelzl@50097
  1855
lemma integrable_nonneg:
wenzelm@53015
  1856
  assumes f: "f \<in> borel_measurable M" "AE x in M. 0 \<le> f x" "(\<integral>\<^sup>+ x. f x \<partial>M) \<noteq> \<infinity>"
hoelzl@50097
  1857
  shows "integrable M f"
hoelzl@50097
  1858
  unfolding integrable_def
hoelzl@50097
  1859
proof (intro conjI f)
wenzelm@53015
  1860
  have "(\<integral>\<^sup>+ x. ereal (- f x) \<partial>M) = 0"
hoelzl@50097
  1861
    using f by (subst positive_integral_0_iff_AE) auto
wenzelm@53015
  1862
  then show "(\<integral>\<^sup>+ x. ereal (- f x) \<partial>M) \<noteq> \<infinity>" by simp
hoelzl@50097
  1863
qed
hoelzl@50097
  1864
hoelzl@47694
  1865
lemma integral_positive:
hoelzl@41689
  1866
  assumes "integrable M f" "\<And>x. x \<in> space M \<Longrightarrow> 0 \<le> f x"
wenzelm@53015
  1867
  shows "0 \<le> integral\<^sup>L M f"
hoelzl@38656
  1868
proof -
hoelzl@50002
  1869
  have "0 = (\<integral>x. 0 \<partial>M)" by auto
wenzelm@53015
  1870
  also have "\<dots> \<le> integral\<^sup>L M f"
hoelzl@38656
  1871
    using assms by (rule integral_mono[OF integral_zero(1)])
hoelzl@38656
  1872
  finally show ?thesis .
hoelzl@38656
  1873
qed
hoelzl@38656
  1874
hoelzl@47694
  1875
lemma integral_monotone_convergence_pos:
hoelzl@49775
  1876
  assumes i: "\<And>i. integrable M (f i)" and mono: "AE x in M. mono (\<lambda>n. f n x)"
hoelzl@49775
  1877
    and pos: "\<And>i. AE x in M. 0 \<le> f i x"
hoelzl@49775
  1878
    and lim: "AE x in M. (\<lambda>i. f i x) ----> u x"
wenzelm@53015
  1879
    and ilim: "(\<lambda>i. integral\<^sup>L M (f i)) ----> x"
hoelzl@49775
  1880
    and u: "u \<in> borel_measurable M"
hoelzl@41689
  1881
  shows "integrable M u"
wenzelm@53015
  1882
  and "integral\<^sup>L M u = x"
hoelzl@35582
  1883
proof -
wenzelm@53015
  1884
  have "(\<integral>\<^sup>+ x. ereal (u x) \<partial>M) = (SUP n. (\<integral>\<^sup>+ x. ereal (f n x) \<partial>M))"
hoelzl@49775
  1885
  proof (subst positive_integral_monotone_convergence_SUP_AE[symmetric])
hoelzl@49775
  1886
    fix i
hoelzl@49775
  1887
    from mono pos show "AE x in M. ereal (f i x) \<le> ereal (f (Suc i) x) \<and> 0 \<le> ereal (f i x)"
hoelzl@49775
  1888
      by eventually_elim (auto simp: mono_def)
hoelzl@49775
  1889
    show "(\<lambda>x. ereal (f i x)) \<in> borel_measurable M"
hoelzl@50003
  1890
      using i by auto
hoelzl@49775
  1891
  next
wenzelm@53015
  1892
    show "(\<integral>\<^sup>+ x. ereal (u x) \<partial>M) = \<integral>\<^sup>+ x. (SUP i. ereal (f i x)) \<partial>M"
hoelzl@49775
  1893
      apply (rule positive_integral_cong_AE)
hoelzl@49775
  1894
      using lim mono
hoelzl@49775
  1895
      by eventually_elim (simp add: SUP_eq_LIMSEQ[THEN iffD2])
hoelzl@38656
  1896
  qed
hoelzl@49775
  1897
  also have "\<dots> = ereal x"
hoelzl@49775
  1898
    using mono i unfolding positive_integral_eq_integral[OF i pos]
hoelzl@49775
  1899
    by (subst SUP_eq_LIMSEQ) (auto simp: mono_def intro!: integral_mono_AE ilim)
wenzelm@53015
  1900
  finally have "(\<integral>\<^sup>+ x. ereal (u x) \<partial>M) = ereal x" .
wenzelm@53015
  1901
  moreover have "(\<integral>\<^sup>+ x. ereal (- u x) \<partial>M) = 0"
hoelzl@49775
  1902
  proof (subst positive_integral_0_iff_AE)
hoelzl@49775
  1903
    show "(\<lambda>x. ereal (- u x)) \<in> borel_measurable M"
hoelzl@49775
  1904
      using u by auto
hoelzl@49775
  1905
    from mono pos[of 0] lim show "AE x in M. ereal (- u x) \<le> 0"
hoelzl@49775
  1906
    proof eventually_elim
hoelzl@49775
  1907
      fix x assume "mono (\<lambda>n. f n x)" "0 \<le> f 0 x" "(\<lambda>i. f i x) ----> u x"
hoelzl@49775
  1908
      then show "ereal (- u x) \<le> 0"
hoelzl@49775
  1909
        using incseq_le[of "\<lambda>n. f n x" "u x" 0] by (simp add: mono_def incseq_def)
hoelzl@49775
  1910
    qed
hoelzl@49775
  1911
  qed
wenzelm@53015
  1912
  ultimately show "integrable M u" "integral\<^sup>L M u = x"
hoelzl@49775
  1913
    by (auto simp: integrable_def lebesgue_integral_def u)
hoelzl@38656
  1914
qed
hoelzl@38656
  1915
hoelzl@47694
  1916
lemma integral_monotone_convergence:
hoelzl@49775
  1917
  assumes f: "\<And>i. integrable M (f i)" and mono: "AE x in M. mono (\<lambda>n. f n x)"
hoelzl@49775
  1918
  and lim: "AE x in M. (\<lambda>i. f i x) ----> u x"
wenzelm@53015
  1919
  and ilim: "(\<lambda>i. integral\<^sup>L M (f i)) ----> x"
hoelzl@49775
  1920
  and u: "u \<in> borel_measurable M"
hoelzl@41689
  1921
  shows "integrable M u"
wenzelm@53015
  1922
  and "integral\<^sup>L M u = x"
hoelzl@38656
  1923
proof -
hoelzl@41689
  1924
  have 1: "\<And>i. integrable M (\<lambda>x. f i x - f 0 x)"
hoelzl@49775
  1925
    using f by auto
hoelzl@49775
  1926
  have 2: "AE x in M. mono (\<lambda>n. f n x - f 0 x)"
hoelzl@49775
  1927
    using mono by (auto simp: mono_def le_fun_def)
hoelzl@49775
  1928
  have 3: "\<And>n. AE x in M. 0 \<le> f n x - f 0 x"
hoelzl@49775
  1929
    using mono by (auto simp: field_simps mono_def le_fun_def)
hoelzl@49775
  1930
  have 4: "AE x in M. (\<lambda>i. f i x - f 0 x) ----> u x - f 0 x"
huffman@44568
  1931
    using lim by (auto intro!: tendsto_diff)
wenzelm@53015
  1932
  have 5: "(\<lambda>i. (\<integral>x. f i x - f 0 x \<partial>M)) ----> x - integral\<^sup>L M (f 0)"
hoelzl@49775
  1933
    using f ilim by (auto intro!: tendsto_diff)
hoelzl@49775
  1934
  have 6: "(\<lambda>x. u x - f 0 x) \<in> borel_measurable M"
hoelzl@49775
  1935
    using f[of 0] u by auto
hoelzl@49775
  1936
  note diff = integral_monotone_convergence_pos[OF 1 2 3 4 5 6]
hoelzl@41689
  1937
  have "integrable M (\<lambda>x. (u x - f 0 x) + f 0 x)"
hoelzl@38656
  1938
    using diff(1) f by (rule integral_add(1))
wenzelm@53015
  1939
  with diff(2) f show "integrable M u" "integral\<^sup>L M u = x"
hoelzl@49775
  1940
    by auto
hoelzl@38656
  1941
qed
hoelzl@38656
  1942
hoelzl@47694
  1943
lemma integral_0_iff:
hoelzl@41689
  1944
  assumes "integrable M f"
hoelzl@47694
  1945
  shows "(\<integral>x. \<bar>f x\<bar> \<partial>M) = 0 \<longleftrightarrow> (emeasure M) {x\<in>space M. f x \<noteq> 0} = 0"
hoelzl@38656
  1946
proof -
wenzelm@53015
  1947
  have *: "(\<integral>\<^sup>+x. ereal (- \<bar>f x\<bar>) \<partial>M) = 0"
hoelzl@41981
  1948
    using assms by (auto simp: positive_integral_0_iff_AE integrable_def)
hoelzl@41689
  1949
  have "integrable M (\<lambda>x. \<bar>f x\<bar>)" using assms by (rule integrable_abs)
hoelzl@43920
  1950
  hence "(\<lambda>x. ereal (\<bar>f x\<bar>)) \<in> borel_measurable M"
wenzelm@53015
  1951
    "(\<integral>\<^sup>+ x. ereal \<bar>f x\<bar> \<partial>M) \<noteq> \<infinity>" unfolding integrable_def by auto
hoelzl@38656
  1952
  from positive_integral_0_iff[OF this(1)] this(2)
hoelzl@41689
  1953
  show ?thesis unfolding lebesgue_integral_def *
hoelzl@47694
  1954
    using positive_integral_positive[of M "\<lambda>x. ereal \<bar>f x\<bar>"]
hoelzl@43920
  1955
    by (auto simp add: real_of_ereal_eq_0)
hoelzl@35582
  1956
qed
hoelzl@35582
  1957
hoelzl@47694
  1958
lemma integral_real:
wenzelm@53015
  1959
  "AE x in M. \<bar>f x\<bar> \<noteq> \<infinity> \<Longrightarrow> (\<integral>x. real (f x) \<partial>M) = real (integral\<^sup>P M f) - real (integral\<^sup>P M (\<lambda>x. - f x))"
hoelzl@41981
  1960
  using assms unfolding lebesgue_integral_def
hoelzl@43920
  1961
  by (subst (1 2) positive_integral_cong_AE) (auto simp add: ereal_real)
hoelzl@41981
  1962
hoelzl@42991
  1963
lemma (in finite_measure) lebesgue_integral_const[simp]:
hoelzl@42991
  1964
  shows "integrable M (\<lambda>x. a)"
hoelzl@50097
  1965
  and  "(\<integral>x. a \<partial>M) = a * measure M (space M)"
hoelzl@42991
  1966
proof -
hoelzl@42991
  1967
  { fix a :: real assume "0 \<le> a"
wenzelm@53015
  1968
    then have "(\<integral>\<^sup>+ x. ereal a \<partial>M) = ereal a * (emeasure M) (space M)"
hoelzl@42991
  1969
      by (subst positive_integral_const) auto
hoelzl@42991
  1970
    moreover
wenzelm@53015
  1971
    from `0 \<le> a` have "(\<integral>\<^sup>+ x. ereal (-a) \<partial>M) = 0"
hoelzl@42991
  1972
      by (subst positive_integral_0_iff_AE) auto
hoelzl@42991
  1973
    ultimately have "integrable M (\<lambda>x. a)" by (auto simp: integrable_def) }
hoelzl@42991
  1974
  note * = this
hoelzl@42991
  1975
  show "integrable M (\<lambda>x. a)"
hoelzl@42991
  1976
  proof cases
hoelzl@42991
  1977
    assume "0 \<le> a" with * show ?thesis .
hoelzl@42991
  1978
  next
hoelzl@42991
  1979
    assume "\<not> 0 \<le> a"
hoelzl@42991
  1980
    then have "0 \<le> -a" by auto
hoelzl@42991
  1981
    from *[OF this] show ?thesis by simp
hoelzl@42991
  1982
  qed
hoelzl@47694
  1983
  show "(\<integral>x. a \<partial>M) = a * measure M (space M)"
hoelzl@47694
  1984
    by (simp add: lebesgue_integral_def positive_integral_const_If emeasure_eq_measure)
hoelzl@42991
  1985
qed
hoelzl@42991
  1986
hoelzl@50097
  1987
lemma (in finite_measure) integrable_const_bound:
hoelzl@50097
  1988
  assumes "AE x in M. \<bar>f x\<bar> \<le> B" and "f \<in> borel_measurable M" shows "integrable M f"
hoelzl@50097
  1989
  by (auto intro: integrable_bound[where f="\<lambda>x. B"] lebesgue_integral_const assms)
hoelzl@50097
  1990
hoelzl@42991
  1991
lemma (in finite_measure) integral_less_AE:
hoelzl@42991
  1992
  assumes int: "integrable M X" "integrable M Y"
hoelzl@47694
  1993
  assumes A: "(emeasure M) A \<noteq> 0" "A \<in> sets M" "AE x in M. x \<in> A \<longrightarrow> X x \<noteq> Y x"
hoelzl@47694
  1994
  assumes gt: "AE x in M. X x \<le> Y x"
wenzelm@53015
  1995
  shows "integral\<^sup>L M X < integral\<^sup>L M Y"
hoelzl@42991
  1996
proof -
wenzelm@53015
  1997
  have "integral\<^sup>L M X \<le> integral\<^sup>L M Y"
hoelzl@42991
  1998
    using gt int by (intro integral_mono_AE) auto
hoelzl@42991
  1999
  moreover
wenzelm@53015
  2000
  have "integral\<^sup>L M X \<noteq> integral\<^sup>L M Y"
hoelzl@42991
  2001
  proof
wenzelm@53015
  2002
    assume eq: "integral\<^sup>L M X = integral\<^sup>L M Y"
wenzelm@53015
  2003
    have "integral\<^sup>L M (\<lambda>x. \<bar>Y x - X x\<bar>) = integral\<^sup>L M (\<lambda>x. Y x - X x)"
hoelzl@42991
  2004
      using gt by (intro integral_cong_AE) auto
hoelzl@42991
  2005
    also have "\<dots> = 0"
hoelzl@42991
  2006
      using eq int by simp
hoelzl@47694
  2007
    finally have "(emeasure M) {x \<in> space M. Y x - X x \<noteq> 0} = 0"
hoelzl@43339
  2008
      using int by (simp add: integral_0_iff)
hoelzl@43339
  2009
    moreover
wenzelm@53015
  2010
    have "(\<integral>\<^sup>+x. indicator A x \<partial>M) \<le> (\<integral>\<^sup>+x. indicator {x \<in> space M. Y x - X x \<noteq> 0} x \<partial>M)"
hoelzl@43339
  2011
      using A by (intro positive_integral_mono_AE) auto
hoelzl@47694
  2012
    then have "(emeasure M) A \<le> (emeasure M) {x \<in> space M. Y x - X x \<noteq> 0}"
hoelzl@43339
  2013
      using int A by (simp add: integrable_def)
hoelzl@47694
  2014
    ultimately have "emeasure M A = 0"
hoelzl@47694
  2015
      using emeasure_nonneg[of M A] by simp
hoelzl@47694
  2016
    with `(emeasure M) A \<noteq> 0` show False by auto
hoelzl@42991
  2017
  qed
hoelzl@42991
  2018
  ultimately show ?thesis by auto
hoelzl@42991
  2019
qed
hoelzl@42991
  2020
hoelzl@43339
  2021
lemma (in finite_measure) integral_less_AE_space:
hoelzl@43339
  2022
  assumes int: "integrable M X" "integrable M Y"
hoelzl@47694
  2023
  assumes gt: "AE x in M. X x < Y x" "(emeasure M) (space M) \<noteq> 0"
wenzelm@53015
  2024
  shows "integral\<^sup>L M X < integral\<^sup>L M Y"
hoelzl@43339
  2025
  using gt by (intro integral_less_AE[OF int, where A="space M"]) auto
hoelzl@43339
  2026
hoelzl@47694
  2027
lemma integral_dominated_convergence:
hoelzl@50003
  2028
  assumes u[measurable]: "\<And>i. integrable M (u i)" and bound: "\<And>j. AE x in M. \<bar>u j x\<bar> \<le> w x"
hoelzl@50003
  2029
  and w[measurable]: "integrable M w"
hoelzl@49775
  2030
  and u': "AE x in M. (\<lambda>i. u i x) ----> u' x"
hoelzl@50003
  2031
  and [measurable]: "u' \<in> borel_measurable M"
hoelzl@41689
  2032
  shows "integrable M u'"
hoelzl@41689
  2033
  and "(\<lambda>i. (\<integral>x. \<bar>u i x - u' x\<bar> \<partial>M)) ----> 0" (is "?lim_diff")
wenzelm@53015
  2034
  and "(\<lambda>i. integral\<^sup>L M (u i)) ----> integral\<^sup>L M u'" (is ?lim)
hoelzl@36624
  2035
proof -
hoelzl@49775
  2036
  have all_bound: "AE x in M. \<forall>j. \<bar>u j x\<bar> \<le> w x"