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