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