src/HOL/Probability/Lebesgue_Integration.thy
author hoelzl
Thu Dec 02 14:34:58 2010 +0100 (2010-12-02)
changeset 40872 7c556a9240de
parent 40871 688f6ff859e1
child 40873 1ef85f4e7097
permissions -rw-r--r--
Move SUP_commute, SUP_less_iff to HOL image;
Cleanup generic complete_lattice lemmas in Positive_Infinite_Real;
Cleanup lemma positive_integral_alt;
hoelzl@38656
     1
(* Author: Armin Heller, Johannes Hoelzl, TU Muenchen *)
hoelzl@38656
     2
hoelzl@35582
     3
header {*Lebesgue Integration*}
hoelzl@35582
     4
hoelzl@38656
     5
theory Lebesgue_Integration
hoelzl@40859
     6
imports Measure Borel_Space
hoelzl@35582
     7
begin
hoelzl@35582
     8
hoelzl@38656
     9
lemma sums_If_finite:
hoelzl@38656
    10
  assumes finite: "finite {r. P r}"
hoelzl@38656
    11
  shows "(\<lambda>r. if P r then f r else 0) sums (\<Sum>r\<in>{r. P r}. f r)" (is "?F sums _")
hoelzl@38656
    12
proof cases
hoelzl@38656
    13
  assume "{r. P r} = {}" hence "\<And>r. \<not> P r" by auto
hoelzl@38656
    14
  thus ?thesis by (simp add: sums_zero)
hoelzl@38656
    15
next
hoelzl@38656
    16
  assume not_empty: "{r. P r} \<noteq> {}"
hoelzl@38656
    17
  have "?F sums (\<Sum>r = 0..< Suc (Max {r. P r}). ?F r)"
hoelzl@38656
    18
    by (rule series_zero)
hoelzl@38656
    19
       (auto simp add: Max_less_iff[OF finite not_empty] less_eq_Suc_le[symmetric])
hoelzl@38656
    20
  also have "(\<Sum>r = 0..< Suc (Max {r. P r}). ?F r) = (\<Sum>r\<in>{r. P r}. f r)"
hoelzl@38656
    21
    by (subst setsum_cases)
hoelzl@38656
    22
       (auto intro!: setsum_cong simp: Max_ge_iff[OF finite not_empty] less_Suc_eq_le)
hoelzl@38656
    23
  finally show ?thesis .
hoelzl@38656
    24
qed
hoelzl@35582
    25
hoelzl@38656
    26
lemma sums_single:
hoelzl@38656
    27
  "(\<lambda>r. if r = i then f r else 0) sums f i"
hoelzl@38656
    28
  using sums_If_finite[of "\<lambda>r. r = i" f] by simp
hoelzl@38656
    29
hoelzl@38656
    30
section "Simple function"
hoelzl@35582
    31
hoelzl@38656
    32
text {*
hoelzl@38656
    33
hoelzl@38656
    34
Our simple functions are not restricted to positive real numbers. Instead
hoelzl@38656
    35
they are just functions with a finite range and are measurable when singleton
hoelzl@38656
    36
sets are measurable.
hoelzl@35582
    37
hoelzl@38656
    38
*}
hoelzl@38656
    39
hoelzl@38656
    40
definition (in sigma_algebra) "simple_function g \<longleftrightarrow>
hoelzl@38656
    41
    finite (g ` space M) \<and>
hoelzl@38656
    42
    (\<forall>x \<in> g ` space M. g -` {x} \<inter> space M \<in> sets M)"
hoelzl@36624
    43
hoelzl@38656
    44
lemma (in sigma_algebra) simple_functionD:
hoelzl@38656
    45
  assumes "simple_function g"
hoelzl@40871
    46
  shows "finite (g ` space M)" and "g -` {x} \<inter> space M \<in> sets M"
hoelzl@40871
    47
proof -
hoelzl@40871
    48
  show "finite (g ` space M)"
hoelzl@40871
    49
    using assms unfolding simple_function_def by auto
hoelzl@40871
    50
  show "g -` {x} \<inter> space M \<in> sets M"
hoelzl@40871
    51
  proof cases
hoelzl@40871
    52
    assume "x \<in> g`space M" then show ?thesis
hoelzl@40871
    53
      using assms unfolding simple_function_def by auto
hoelzl@40871
    54
  next
hoelzl@40871
    55
    assume "x \<notin> g`space M"
hoelzl@40871
    56
    then have "g -` {x} \<inter> space M = {}" by auto
hoelzl@40871
    57
    then show ?thesis by auto
hoelzl@40871
    58
  qed
hoelzl@40871
    59
qed
hoelzl@36624
    60
hoelzl@38656
    61
lemma (in sigma_algebra) simple_function_indicator_representation:
hoelzl@38656
    62
  fixes f ::"'a \<Rightarrow> pinfreal"
hoelzl@38656
    63
  assumes f: "simple_function f" and x: "x \<in> space M"
hoelzl@38656
    64
  shows "f x = (\<Sum>y \<in> f ` space M. y * indicator (f -` {y} \<inter> space M) x)"
hoelzl@38656
    65
  (is "?l = ?r")
hoelzl@38656
    66
proof -
hoelzl@38705
    67
  have "?r = (\<Sum>y \<in> f ` space M.
hoelzl@38656
    68
    (if y = f x then y * indicator (f -` {y} \<inter> space M) x else 0))"
hoelzl@38656
    69
    by (auto intro!: setsum_cong2)
hoelzl@38656
    70
  also have "... =  f x *  indicator (f -` {f x} \<inter> space M) x"
hoelzl@38656
    71
    using assms by (auto dest: simple_functionD simp: setsum_delta)
hoelzl@38656
    72
  also have "... = f x" using x by (auto simp: indicator_def)
hoelzl@38656
    73
  finally show ?thesis by auto
hoelzl@38656
    74
qed
hoelzl@36624
    75
hoelzl@38656
    76
lemma (in measure_space) simple_function_notspace:
hoelzl@38656
    77
  "simple_function (\<lambda>x. h x * indicator (- space M) x::pinfreal)" (is "simple_function ?h")
hoelzl@35692
    78
proof -
hoelzl@38656
    79
  have "?h ` space M \<subseteq> {0}" unfolding indicator_def by auto
hoelzl@38656
    80
  hence [simp, intro]: "finite (?h ` space M)" by (auto intro: finite_subset)
hoelzl@38656
    81
  have "?h -` {0} \<inter> space M = space M" by auto
hoelzl@38656
    82
  thus ?thesis unfolding simple_function_def by auto
hoelzl@38656
    83
qed
hoelzl@38656
    84
hoelzl@38656
    85
lemma (in sigma_algebra) simple_function_cong:
hoelzl@38656
    86
  assumes "\<And>t. t \<in> space M \<Longrightarrow> f t = g t"
hoelzl@38656
    87
  shows "simple_function f \<longleftrightarrow> simple_function g"
hoelzl@38656
    88
proof -
hoelzl@38656
    89
  have "f ` space M = g ` space M"
hoelzl@38656
    90
    "\<And>x. f -` {x} \<inter> space M = g -` {x} \<inter> space M"
hoelzl@38656
    91
    using assms by (auto intro!: image_eqI)
hoelzl@38656
    92
  thus ?thesis unfolding simple_function_def using assms by simp
hoelzl@38656
    93
qed
hoelzl@38656
    94
hoelzl@38656
    95
lemma (in sigma_algebra) borel_measurable_simple_function:
hoelzl@38656
    96
  assumes "simple_function f"
hoelzl@38656
    97
  shows "f \<in> borel_measurable M"
hoelzl@38656
    98
proof (rule borel_measurableI)
hoelzl@38656
    99
  fix S
hoelzl@38656
   100
  let ?I = "f ` (f -` S \<inter> space M)"
hoelzl@38656
   101
  have *: "(\<Union>x\<in>?I. f -` {x} \<inter> space M) = f -` S \<inter> space M" (is "?U = _") by auto
hoelzl@38656
   102
  have "finite ?I"
hoelzl@38656
   103
    using assms unfolding simple_function_def by (auto intro: finite_subset)
hoelzl@38656
   104
  hence "?U \<in> sets M"
hoelzl@38656
   105
    apply (rule finite_UN)
hoelzl@38656
   106
    using assms unfolding simple_function_def by auto
hoelzl@38656
   107
  thus "f -` S \<inter> space M \<in> sets M" unfolding * .
hoelzl@35692
   108
qed
hoelzl@35692
   109
hoelzl@38656
   110
lemma (in sigma_algebra) simple_function_borel_measurable:
hoelzl@38656
   111
  fixes f :: "'a \<Rightarrow> 'x::t2_space"
hoelzl@38656
   112
  assumes "f \<in> borel_measurable M" and "finite (f ` space M)"
hoelzl@38656
   113
  shows "simple_function f"
hoelzl@38656
   114
  using assms unfolding simple_function_def
hoelzl@38656
   115
  by (auto intro: borel_measurable_vimage)
hoelzl@38656
   116
hoelzl@38656
   117
lemma (in sigma_algebra) simple_function_const[intro, simp]:
hoelzl@38656
   118
  "simple_function (\<lambda>x. c)"
hoelzl@38656
   119
  by (auto intro: finite_subset simp: simple_function_def)
hoelzl@38656
   120
hoelzl@38656
   121
lemma (in sigma_algebra) simple_function_compose[intro, simp]:
hoelzl@38656
   122
  assumes "simple_function f"
hoelzl@38656
   123
  shows "simple_function (g \<circ> f)"
hoelzl@38656
   124
  unfolding simple_function_def
hoelzl@38656
   125
proof safe
hoelzl@38656
   126
  show "finite ((g \<circ> f) ` space M)"
hoelzl@38656
   127
    using assms unfolding simple_function_def by (auto simp: image_compose)
hoelzl@38656
   128
next
hoelzl@38656
   129
  fix x assume "x \<in> space M"
hoelzl@38656
   130
  let ?G = "g -` {g (f x)} \<inter> (f`space M)"
hoelzl@38656
   131
  have *: "(g \<circ> f) -` {(g \<circ> f) x} \<inter> space M =
hoelzl@38656
   132
    (\<Union>x\<in>?G. f -` {x} \<inter> space M)" by auto
hoelzl@38656
   133
  show "(g \<circ> f) -` {(g \<circ> f) x} \<inter> space M \<in> sets M"
hoelzl@38656
   134
    using assms unfolding simple_function_def *
hoelzl@38656
   135
    by (rule_tac finite_UN) (auto intro!: finite_UN)
hoelzl@38656
   136
qed
hoelzl@38656
   137
hoelzl@38656
   138
lemma (in sigma_algebra) simple_function_indicator[intro, simp]:
hoelzl@38656
   139
  assumes "A \<in> sets M"
hoelzl@38656
   140
  shows "simple_function (indicator A)"
hoelzl@35692
   141
proof -
hoelzl@38656
   142
  have "indicator A ` space M \<subseteq> {0, 1}" (is "?S \<subseteq> _")
hoelzl@38656
   143
    by (auto simp: indicator_def)
hoelzl@38656
   144
  hence "finite ?S" by (rule finite_subset) simp
hoelzl@38656
   145
  moreover have "- A \<inter> space M = space M - A" by auto
hoelzl@38656
   146
  ultimately show ?thesis unfolding simple_function_def
hoelzl@38656
   147
    using assms by (auto simp: indicator_def_raw)
hoelzl@35692
   148
qed
hoelzl@35692
   149
hoelzl@38656
   150
lemma (in sigma_algebra) simple_function_Pair[intro, simp]:
hoelzl@38656
   151
  assumes "simple_function f"
hoelzl@38656
   152
  assumes "simple_function g"
hoelzl@38656
   153
  shows "simple_function (\<lambda>x. (f x, g x))" (is "simple_function ?p")
hoelzl@38656
   154
  unfolding simple_function_def
hoelzl@38656
   155
proof safe
hoelzl@38656
   156
  show "finite (?p ` space M)"
hoelzl@38656
   157
    using assms unfolding simple_function_def
hoelzl@38656
   158
    by (rule_tac finite_subset[of _ "f`space M \<times> g`space M"]) auto
hoelzl@38656
   159
next
hoelzl@38656
   160
  fix x assume "x \<in> space M"
hoelzl@38656
   161
  have "(\<lambda>x. (f x, g x)) -` {(f x, g x)} \<inter> space M =
hoelzl@38656
   162
      (f -` {f x} \<inter> space M) \<inter> (g -` {g x} \<inter> space M)"
hoelzl@38656
   163
    by auto
hoelzl@38656
   164
  with `x \<in> space M` show "(\<lambda>x. (f x, g x)) -` {(f x, g x)} \<inter> space M \<in> sets M"
hoelzl@38656
   165
    using assms unfolding simple_function_def by auto
hoelzl@38656
   166
qed
hoelzl@35692
   167
hoelzl@38656
   168
lemma (in sigma_algebra) simple_function_compose1:
hoelzl@38656
   169
  assumes "simple_function f"
hoelzl@38656
   170
  shows "simple_function (\<lambda>x. g (f x))"
hoelzl@38656
   171
  using simple_function_compose[OF assms, of g]
hoelzl@38656
   172
  by (simp add: comp_def)
hoelzl@35582
   173
hoelzl@38656
   174
lemma (in sigma_algebra) simple_function_compose2:
hoelzl@38656
   175
  assumes "simple_function f" and "simple_function g"
hoelzl@38656
   176
  shows "simple_function (\<lambda>x. h (f x) (g x))"
hoelzl@38656
   177
proof -
hoelzl@38656
   178
  have "simple_function ((\<lambda>(x, y). h x y) \<circ> (\<lambda>x. (f x, g x)))"
hoelzl@38656
   179
    using assms by auto
hoelzl@38656
   180
  thus ?thesis by (simp_all add: comp_def)
hoelzl@38656
   181
qed
hoelzl@35582
   182
hoelzl@38656
   183
lemmas (in sigma_algebra) simple_function_add[intro, simp] = simple_function_compose2[where h="op +"]
hoelzl@38656
   184
  and simple_function_diff[intro, simp] = simple_function_compose2[where h="op -"]
hoelzl@38656
   185
  and simple_function_uminus[intro, simp] = simple_function_compose[where g="uminus"]
hoelzl@38656
   186
  and simple_function_mult[intro, simp] = simple_function_compose2[where h="op *"]
hoelzl@38656
   187
  and simple_function_div[intro, simp] = simple_function_compose2[where h="op /"]
hoelzl@38656
   188
  and simple_function_inverse[intro, simp] = simple_function_compose[where g="inverse"]
hoelzl@38656
   189
hoelzl@38656
   190
lemma (in sigma_algebra) simple_function_setsum[intro, simp]:
hoelzl@38656
   191
  assumes "\<And>i. i \<in> P \<Longrightarrow> simple_function (f i)"
hoelzl@38656
   192
  shows "simple_function (\<lambda>x. \<Sum>i\<in>P. f i x)"
hoelzl@38656
   193
proof cases
hoelzl@38656
   194
  assume "finite P" from this assms show ?thesis by induct auto
hoelzl@38656
   195
qed auto
hoelzl@35582
   196
hoelzl@38656
   197
lemma (in sigma_algebra) simple_function_le_measurable:
hoelzl@38656
   198
  assumes "simple_function f" "simple_function g"
hoelzl@38656
   199
  shows "{x \<in> space M. f x \<le> g x} \<in> sets M"
hoelzl@38656
   200
proof -
hoelzl@38656
   201
  have *: "{x \<in> space M. f x \<le> g x} =
hoelzl@38656
   202
    (\<Union>(F, G)\<in>f`space M \<times> g`space M.
hoelzl@38656
   203
      if F \<le> G then (f -` {F} \<inter> space M) \<inter> (g -` {G} \<inter> space M) else {})"
hoelzl@38656
   204
    apply (auto split: split_if_asm)
hoelzl@38656
   205
    apply (rule_tac x=x in bexI)
hoelzl@38656
   206
    apply (rule_tac x=x in bexI)
hoelzl@38656
   207
    by simp_all
hoelzl@38656
   208
  have **: "\<And>x y. x \<in> space M \<Longrightarrow> y \<in> space M \<Longrightarrow>
hoelzl@38656
   209
    (f -` {f x} \<inter> space M) \<inter> (g -` {g y} \<inter> space M) \<in> sets M"
hoelzl@38656
   210
    using assms unfolding simple_function_def by auto
hoelzl@38656
   211
  have "finite (f`space M \<times> g`space M)"
hoelzl@38656
   212
    using assms unfolding simple_function_def by auto
hoelzl@38656
   213
  thus ?thesis unfolding *
hoelzl@38656
   214
    apply (rule finite_UN)
hoelzl@38656
   215
    using assms unfolding simple_function_def
hoelzl@38656
   216
    by (auto intro!: **)
hoelzl@35582
   217
qed
hoelzl@35582
   218
hoelzl@38656
   219
lemma (in sigma_algebra) borel_measurable_implies_simple_function_sequence:
hoelzl@38656
   220
  fixes u :: "'a \<Rightarrow> pinfreal"
hoelzl@38656
   221
  assumes u: "u \<in> borel_measurable M"
hoelzl@38656
   222
  shows "\<exists>f. (\<forall>i. simple_function (f i) \<and> (\<forall>x\<in>space M. f i x \<noteq> \<omega>)) \<and> f \<up> u"
hoelzl@35582
   223
proof -
hoelzl@38656
   224
  have "\<exists>f. \<forall>x j. (of_nat j \<le> u x \<longrightarrow> f x j = j*2^j) \<and>
hoelzl@38656
   225
    (u x < of_nat j \<longrightarrow> of_nat (f x j) \<le> u x * 2^j \<and> u x * 2^j < of_nat (Suc (f x j)))"
hoelzl@38656
   226
    (is "\<exists>f. \<forall>x j. ?P x j (f x j)")
hoelzl@38656
   227
  proof(rule choice, rule, rule choice, rule)
hoelzl@38656
   228
    fix x j show "\<exists>n. ?P x j n"
hoelzl@38656
   229
    proof cases
hoelzl@38656
   230
      assume *: "u x < of_nat j"
hoelzl@38656
   231
      then obtain r where r: "u x = Real r" "0 \<le> r" by (cases "u x") auto
hoelzl@38656
   232
      from reals_Archimedean6a[of "r * 2^j"]
hoelzl@38656
   233
      obtain n :: nat where "real n \<le> r * 2 ^ j" "r * 2 ^ j < real (Suc n)"
hoelzl@38656
   234
        using `0 \<le> r` by (auto simp: zero_le_power zero_le_mult_iff)
hoelzl@38656
   235
      thus ?thesis using r * by (auto intro!: exI[of _ n])
hoelzl@38656
   236
    qed auto
hoelzl@35582
   237
  qed
hoelzl@38656
   238
  then obtain f where top: "\<And>j x. of_nat j \<le> u x \<Longrightarrow> f x j = j*2^j" and
hoelzl@38656
   239
    upper: "\<And>j x. u x < of_nat j \<Longrightarrow> of_nat (f x j) \<le> u x * 2^j" and
hoelzl@38656
   240
    lower: "\<And>j x. u x < of_nat j \<Longrightarrow> u x * 2^j < of_nat (Suc (f x j))" by blast
hoelzl@35582
   241
hoelzl@38656
   242
  { fix j x P
hoelzl@38656
   243
    assume 1: "of_nat j \<le> u x \<Longrightarrow> P (j * 2^j)"
hoelzl@38656
   244
    assume 2: "\<And>k. \<lbrakk> u x < of_nat j ; of_nat k \<le> u x * 2^j ; u x * 2^j < of_nat (Suc k) \<rbrakk> \<Longrightarrow> P k"
hoelzl@38656
   245
    have "P (f x j)"
hoelzl@38656
   246
    proof cases
hoelzl@38656
   247
      assume "of_nat j \<le> u x" thus "P (f x j)"
hoelzl@38656
   248
        using top[of j x] 1 by auto
hoelzl@38656
   249
    next
hoelzl@38656
   250
      assume "\<not> of_nat j \<le> u x"
hoelzl@38656
   251
      hence "u x < of_nat j" "of_nat (f x j) \<le> u x * 2^j" "u x * 2^j < of_nat (Suc (f x j))"
hoelzl@38656
   252
        using upper lower by auto
hoelzl@38656
   253
      from 2[OF this] show "P (f x j)" .
hoelzl@38656
   254
    qed }
hoelzl@38656
   255
  note fI = this
hoelzl@38656
   256
hoelzl@38656
   257
  { fix j x
hoelzl@38656
   258
    have "f x j = j * 2 ^ j \<longleftrightarrow> of_nat j \<le> u x"
hoelzl@38656
   259
      by (rule fI, simp, cases "u x") (auto split: split_if_asm) }
hoelzl@38656
   260
  note f_eq = this
hoelzl@35582
   261
hoelzl@38656
   262
  { fix j x
hoelzl@38656
   263
    have "f x j \<le> j * 2 ^ j"
hoelzl@38656
   264
    proof (rule fI)
hoelzl@38656
   265
      fix k assume *: "u x < of_nat j"
hoelzl@38656
   266
      assume "of_nat k \<le> u x * 2 ^ j"
hoelzl@38656
   267
      also have "\<dots> \<le> of_nat (j * 2^j)"
hoelzl@38656
   268
        using * by (cases "u x") (auto simp: zero_le_mult_iff)
hoelzl@38656
   269
      finally show "k \<le> j*2^j" by (auto simp del: real_of_nat_mult)
hoelzl@38656
   270
    qed simp }
hoelzl@38656
   271
  note f_upper = this
hoelzl@35582
   272
hoelzl@38656
   273
  let "?g j x" = "of_nat (f x j) / 2^j :: pinfreal"
hoelzl@38656
   274
  show ?thesis unfolding simple_function_def isoton_fun_expand unfolding isoton_def
hoelzl@38656
   275
  proof (safe intro!: exI[of _ ?g])
hoelzl@38656
   276
    fix j
hoelzl@38656
   277
    have *: "?g j ` space M \<subseteq> (\<lambda>x. of_nat x / 2^j) ` {..j * 2^j}"
hoelzl@38656
   278
      using f_upper by auto
hoelzl@38656
   279
    thus "finite (?g j ` space M)" by (rule finite_subset) auto
hoelzl@38656
   280
  next
hoelzl@38656
   281
    fix j t assume "t \<in> space M"
hoelzl@38656
   282
    have **: "?g j -` {?g j t} \<inter> space M = {x \<in> space M. f t j = f x j}"
hoelzl@38656
   283
      by (auto simp: power_le_zero_eq Real_eq_Real mult_le_0_iff)
hoelzl@35582
   284
hoelzl@38656
   285
    show "?g j -` {?g j t} \<inter> space M \<in> sets M"
hoelzl@38656
   286
    proof cases
hoelzl@38656
   287
      assume "of_nat j \<le> u t"
hoelzl@38656
   288
      hence "?g j -` {?g j t} \<inter> space M = {x\<in>space M. of_nat j \<le> u x}"
hoelzl@38656
   289
        unfolding ** f_eq[symmetric] by auto
hoelzl@38656
   290
      thus "?g j -` {?g j t} \<inter> space M \<in> sets M"
hoelzl@38656
   291
        using u by auto
hoelzl@35582
   292
    next
hoelzl@38656
   293
      assume not_t: "\<not> of_nat j \<le> u t"
hoelzl@38656
   294
      hence less: "f t j < j*2^j" using f_eq[symmetric] `f t j \<le> j*2^j` by auto
hoelzl@38656
   295
      have split_vimage: "?g j -` {?g j t} \<inter> space M =
hoelzl@38656
   296
          {x\<in>space M. of_nat (f t j)/2^j \<le> u x} \<inter> {x\<in>space M. u x < of_nat (Suc (f t j))/2^j}"
hoelzl@38656
   297
        unfolding **
hoelzl@38656
   298
      proof safe
hoelzl@38656
   299
        fix x assume [simp]: "f t j = f x j"
hoelzl@38656
   300
        have *: "\<not> of_nat j \<le> u x" using not_t f_eq[symmetric] by simp
hoelzl@38656
   301
        hence "of_nat (f t j) \<le> u x * 2^j \<and> u x * 2^j < of_nat (Suc (f t j))"
hoelzl@38656
   302
          using upper lower by auto
hoelzl@38656
   303
        hence "of_nat (f t j) / 2^j \<le> u x \<and> u x < of_nat (Suc (f t j))/2^j" using *
hoelzl@38656
   304
          by (cases "u x") (auto simp: zero_le_mult_iff power_le_zero_eq divide_real_def[symmetric] field_simps)
hoelzl@38656
   305
        thus "of_nat (f t j) / 2^j \<le> u x" "u x < of_nat (Suc (f t j))/2^j" by auto
hoelzl@38656
   306
      next
hoelzl@38656
   307
        fix x
hoelzl@38656
   308
        assume "of_nat (f t j) / 2^j \<le> u x" "u x < of_nat (Suc (f t j))/2^j"
hoelzl@38656
   309
        hence "of_nat (f t j) \<le> u x * 2 ^ j \<and> u x * 2 ^ j < of_nat (Suc (f t j))"
hoelzl@38656
   310
          by (cases "u x") (auto simp: zero_le_mult_iff power_le_zero_eq divide_real_def[symmetric] field_simps)
hoelzl@38656
   311
        hence 1: "of_nat (f t j) \<le> u x * 2 ^ j" and 2: "u x * 2 ^ j < of_nat (Suc (f t j))" by auto
hoelzl@38656
   312
        note 2
hoelzl@38656
   313
        also have "\<dots> \<le> of_nat (j*2^j)"
hoelzl@38656
   314
          using less by (auto simp: zero_le_mult_iff simp del: real_of_nat_mult)
hoelzl@38656
   315
        finally have bound_ux: "u x < of_nat j"
hoelzl@38656
   316
          by (cases "u x") (auto simp: zero_le_mult_iff power_le_zero_eq)
hoelzl@38656
   317
        show "f t j = f x j"
hoelzl@38656
   318
        proof (rule antisym)
hoelzl@38656
   319
          from 1 lower[OF bound_ux]
hoelzl@38656
   320
          show "f t j \<le> f x j" by (cases "u x") (auto split: split_if_asm)
hoelzl@38656
   321
          from upper[OF bound_ux] 2
hoelzl@38656
   322
          show "f x j \<le> f t j" by (cases "u x") (auto split: split_if_asm)
hoelzl@38656
   323
        qed
hoelzl@38656
   324
      qed
hoelzl@38656
   325
      show ?thesis unfolding split_vimage using u by auto
hoelzl@35582
   326
    qed
hoelzl@38656
   327
  next
hoelzl@38656
   328
    fix j t assume "?g j t = \<omega>" thus False by (auto simp: power_le_zero_eq)
hoelzl@38656
   329
  next
hoelzl@38656
   330
    fix t
hoelzl@38656
   331
    { fix i
hoelzl@38656
   332
      have "f t i * 2 \<le> f t (Suc i)"
hoelzl@38656
   333
      proof (rule fI)
hoelzl@38656
   334
        assume "of_nat (Suc i) \<le> u t"
hoelzl@38656
   335
        hence "of_nat i \<le> u t" by (cases "u t") auto
hoelzl@38656
   336
        thus "f t i * 2 \<le> Suc i * 2 ^ Suc i" unfolding f_eq[symmetric] by simp
hoelzl@38656
   337
      next
hoelzl@38656
   338
        fix k
hoelzl@38656
   339
        assume *: "u t * 2 ^ Suc i < of_nat (Suc k)"
hoelzl@38656
   340
        show "f t i * 2 \<le> k"
hoelzl@38656
   341
        proof (rule fI)
hoelzl@38656
   342
          assume "of_nat i \<le> u t"
hoelzl@38656
   343
          hence "of_nat (i * 2^Suc i) \<le> u t * 2^Suc i"
hoelzl@38656
   344
            by (cases "u t") (auto simp: zero_le_mult_iff power_le_zero_eq)
hoelzl@38656
   345
          also have "\<dots> < of_nat (Suc k)" using * by auto
hoelzl@38656
   346
          finally show "i * 2 ^ i * 2 \<le> k"
hoelzl@38656
   347
            by (auto simp del: real_of_nat_mult)
hoelzl@38656
   348
        next
hoelzl@38656
   349
          fix j assume "of_nat j \<le> u t * 2 ^ i"
hoelzl@38656
   350
          with * show "j * 2 \<le> k" by (cases "u t") (auto simp: zero_le_mult_iff power_le_zero_eq)
hoelzl@38656
   351
        qed
hoelzl@38656
   352
      qed
hoelzl@38656
   353
      thus "?g i t \<le> ?g (Suc i) t"
hoelzl@38656
   354
        by (auto simp: zero_le_mult_iff power_le_zero_eq divide_real_def[symmetric] field_simps) }
hoelzl@38656
   355
    hence mono: "mono (\<lambda>i. ?g i t)" unfolding mono_iff_le_Suc by auto
hoelzl@35582
   356
hoelzl@38656
   357
    show "(SUP j. of_nat (f t j) / 2 ^ j) = u t"
hoelzl@38656
   358
    proof (rule pinfreal_SUPI)
hoelzl@38656
   359
      fix j show "of_nat (f t j) / 2 ^ j \<le> u t"
hoelzl@38656
   360
      proof (rule fI)
hoelzl@38656
   361
        assume "of_nat j \<le> u t" thus "of_nat (j * 2 ^ j) / 2 ^ j \<le> u t"
hoelzl@38656
   362
          by (cases "u t") (auto simp: power_le_zero_eq divide_real_def[symmetric] field_simps)
hoelzl@38656
   363
      next
hoelzl@38656
   364
        fix k assume "of_nat k \<le> u t * 2 ^ j"
hoelzl@38656
   365
        thus "of_nat k / 2 ^ j \<le> u t"
hoelzl@38656
   366
          by (cases "u t")
hoelzl@38656
   367
             (auto simp: power_le_zero_eq divide_real_def[symmetric] field_simps zero_le_mult_iff)
hoelzl@38656
   368
      qed
hoelzl@38656
   369
    next
hoelzl@38656
   370
      fix y :: pinfreal assume *: "\<And>j. j \<in> UNIV \<Longrightarrow> of_nat (f t j) / 2 ^ j \<le> y"
hoelzl@38656
   371
      show "u t \<le> y"
hoelzl@38656
   372
      proof (cases "u t")
hoelzl@38656
   373
        case (preal r)
hoelzl@38656
   374
        show ?thesis
hoelzl@38656
   375
        proof (rule ccontr)
hoelzl@38656
   376
          assume "\<not> u t \<le> y"
hoelzl@38656
   377
          then obtain p where p: "y = Real p" "0 \<le> p" "p < r" using preal by (cases y) auto
hoelzl@38656
   378
          with LIMSEQ_inverse_realpow_zero[of 2, unfolded LIMSEQ_iff, rule_format, of "r - p"]
hoelzl@38656
   379
          obtain n where n: "\<And>N. n \<le> N \<Longrightarrow> inverse (2^N) < r - p" by auto
hoelzl@38656
   380
          let ?N = "max n (natfloor r + 1)"
hoelzl@38656
   381
          have "u t < of_nat ?N" "n \<le> ?N"
hoelzl@38656
   382
            using ge_natfloor_plus_one_imp_gt[of r n] preal
hoelzl@38705
   383
            using real_natfloor_add_one_gt
hoelzl@38705
   384
            by (auto simp: max_def real_of_nat_Suc)
hoelzl@38656
   385
          from lower[OF this(1)]
hoelzl@38656
   386
          have "r < (real (f t ?N) + 1) / 2 ^ ?N" unfolding less_divide_eq
hoelzl@38656
   387
            using preal by (auto simp add: power_le_zero_eq zero_le_mult_iff real_of_nat_Suc split: split_if_asm)
hoelzl@38656
   388
          hence "u t < of_nat (f t ?N) / 2 ^ ?N + 1 / 2 ^ ?N"
hoelzl@38656
   389
            using preal by (auto simp: field_simps divide_real_def[symmetric])
hoelzl@38656
   390
          with n[OF `n \<le> ?N`] p preal *[of ?N]
hoelzl@38656
   391
          show False
hoelzl@38656
   392
            by (cases "f t ?N") (auto simp: power_le_zero_eq split: split_if_asm)
hoelzl@38656
   393
        qed
hoelzl@38656
   394
      next
hoelzl@38656
   395
        case infinite
hoelzl@38656
   396
        { fix j have "f t j = j*2^j" using top[of j t] infinite by simp
hoelzl@38656
   397
          hence "of_nat j \<le> y" using *[of j]
hoelzl@38656
   398
            by (cases y) (auto simp: power_le_zero_eq zero_le_mult_iff field_simps) }
hoelzl@38656
   399
        note all_less_y = this
hoelzl@38656
   400
        show ?thesis unfolding infinite
hoelzl@38656
   401
        proof (rule ccontr)
hoelzl@38656
   402
          assume "\<not> \<omega> \<le> y" then obtain r where r: "y = Real r" "0 \<le> r" by (cases y) auto
hoelzl@38656
   403
          moreover obtain n ::nat where "r < real n" using ex_less_of_nat by (auto simp: real_eq_of_nat)
hoelzl@38656
   404
          with all_less_y[of n] r show False by auto
hoelzl@38656
   405
        qed
hoelzl@38656
   406
      qed
hoelzl@38656
   407
    qed
hoelzl@35582
   408
  qed
hoelzl@35582
   409
qed
hoelzl@35582
   410
hoelzl@38656
   411
lemma (in sigma_algebra) borel_measurable_implies_simple_function_sequence':
hoelzl@38656
   412
  fixes u :: "'a \<Rightarrow> pinfreal"
hoelzl@38656
   413
  assumes "u \<in> borel_measurable M"
hoelzl@38656
   414
  obtains (x) f where "f \<up> u" "\<And>i. simple_function (f i)" "\<And>i. \<omega>\<notin>f i`space M"
hoelzl@35582
   415
proof -
hoelzl@38656
   416
  from borel_measurable_implies_simple_function_sequence[OF assms]
hoelzl@38656
   417
  obtain f where x: "\<And>i. simple_function (f i)" "f \<up> u"
hoelzl@38656
   418
    and fin: "\<And>i. \<And>x. x\<in>space M \<Longrightarrow> f i x \<noteq> \<omega>" by auto
hoelzl@38656
   419
  { fix i from fin[of _ i] have "\<omega> \<notin> f i`space M" by fastsimp }
hoelzl@38656
   420
  with x show thesis by (auto intro!: that[of f])
hoelzl@38656
   421
qed
hoelzl@38656
   422
hoelzl@39092
   423
lemma (in sigma_algebra) simple_function_eq_borel_measurable:
hoelzl@39092
   424
  fixes f :: "'a \<Rightarrow> pinfreal"
hoelzl@39092
   425
  shows "simple_function f \<longleftrightarrow>
hoelzl@39092
   426
    finite (f`space M) \<and> f \<in> borel_measurable M"
hoelzl@39092
   427
  using simple_function_borel_measurable[of f]
hoelzl@39092
   428
    borel_measurable_simple_function[of f]
hoelzl@39092
   429
  by (fastsimp simp: simple_function_def)
hoelzl@39092
   430
hoelzl@39092
   431
lemma (in measure_space) simple_function_restricted:
hoelzl@39092
   432
  fixes f :: "'a \<Rightarrow> pinfreal" assumes "A \<in> sets M"
hoelzl@39092
   433
  shows "sigma_algebra.simple_function (restricted_space A) f \<longleftrightarrow> simple_function (\<lambda>x. f x * indicator A x)"
hoelzl@39092
   434
    (is "sigma_algebra.simple_function ?R f \<longleftrightarrow> simple_function ?f")
hoelzl@39092
   435
proof -
hoelzl@39092
   436
  interpret R: sigma_algebra ?R by (rule restricted_sigma_algebra[OF `A \<in> sets M`])
hoelzl@39092
   437
  have "finite (f`A) \<longleftrightarrow> finite (?f`space M)"
hoelzl@39092
   438
  proof cases
hoelzl@39092
   439
    assume "A = space M"
hoelzl@39092
   440
    then have "f`A = ?f`space M" by (fastsimp simp: image_iff)
hoelzl@39092
   441
    then show ?thesis by simp
hoelzl@39092
   442
  next
hoelzl@39092
   443
    assume "A \<noteq> space M"
hoelzl@39092
   444
    then obtain x where x: "x \<in> space M" "x \<notin> A"
hoelzl@39092
   445
      using sets_into_space `A \<in> sets M` by auto
hoelzl@39092
   446
    have *: "?f`space M = f`A \<union> {0}"
hoelzl@39092
   447
    proof (auto simp add: image_iff)
hoelzl@39092
   448
      show "\<exists>x\<in>space M. f x = 0 \<or> indicator A x = 0"
hoelzl@39092
   449
        using x by (auto intro!: bexI[of _ x])
hoelzl@39092
   450
    next
hoelzl@39092
   451
      fix x assume "x \<in> A"
hoelzl@39092
   452
      then show "\<exists>y\<in>space M. f x = f y * indicator A y"
hoelzl@39092
   453
        using `A \<in> sets M` sets_into_space by (auto intro!: bexI[of _ x])
hoelzl@39092
   454
    next
hoelzl@39092
   455
      fix x
hoelzl@39092
   456
      assume "indicator A x \<noteq> (0::pinfreal)"
hoelzl@39092
   457
      then have "x \<in> A" by (auto simp: indicator_def split: split_if_asm)
hoelzl@39092
   458
      moreover assume "x \<in> space M" "\<forall>y\<in>A. ?f x \<noteq> f y"
hoelzl@39092
   459
      ultimately show "f x = 0" by auto
hoelzl@39092
   460
    qed
hoelzl@39092
   461
    then show ?thesis by auto
hoelzl@39092
   462
  qed
hoelzl@39092
   463
  then show ?thesis
hoelzl@39092
   464
    unfolding simple_function_eq_borel_measurable
hoelzl@39092
   465
      R.simple_function_eq_borel_measurable
hoelzl@39092
   466
    unfolding borel_measurable_restricted[OF `A \<in> sets M`]
hoelzl@39092
   467
    by auto
hoelzl@39092
   468
qed
hoelzl@39092
   469
hoelzl@39092
   470
lemma (in sigma_algebra) simple_function_subalgebra:
hoelzl@39092
   471
  assumes "sigma_algebra.simple_function (M\<lparr>sets:=N\<rparr>) f"
hoelzl@39092
   472
  and N_subalgebra: "N \<subseteq> sets M" "sigma_algebra (M\<lparr>sets:=N\<rparr>)"
hoelzl@39092
   473
  shows "simple_function f"
hoelzl@39092
   474
  using assms
hoelzl@39092
   475
  unfolding simple_function_def
hoelzl@39092
   476
  unfolding sigma_algebra.simple_function_def[OF N_subalgebra(2)]
hoelzl@39092
   477
  by auto
hoelzl@39092
   478
hoelzl@40859
   479
lemma (in sigma_algebra) simple_function_vimage:
hoelzl@40859
   480
  fixes g :: "'a \<Rightarrow> pinfreal" and f :: "'d \<Rightarrow> 'a"
hoelzl@40859
   481
  assumes g: "simple_function g" and f: "f \<in> S \<rightarrow> space M"
hoelzl@40859
   482
  shows "sigma_algebra.simple_function (vimage_algebra S f) (\<lambda>x. g (f x))"
hoelzl@40859
   483
proof -
hoelzl@40859
   484
  have subset: "(\<lambda>x. g (f x)) ` S \<subseteq> g ` space M"
hoelzl@40859
   485
    using f by auto
hoelzl@40859
   486
  interpret V: sigma_algebra "vimage_algebra S f"
hoelzl@40859
   487
    using f by (rule sigma_algebra_vimage)
hoelzl@40859
   488
  show ?thesis using g
hoelzl@40859
   489
    unfolding simple_function_eq_borel_measurable
hoelzl@40859
   490
    unfolding V.simple_function_eq_borel_measurable
hoelzl@40859
   491
    using measurable_vimage[OF _ f, of g borel]
hoelzl@40859
   492
    using finite_subset[OF subset] by auto
hoelzl@40859
   493
qed
hoelzl@40859
   494
hoelzl@38656
   495
section "Simple integral"
hoelzl@38656
   496
hoelzl@38656
   497
definition (in measure_space)
hoelzl@38656
   498
  "simple_integral f = (\<Sum>x \<in> f ` space M. x * \<mu> (f -` {x} \<inter> space M))"
hoelzl@35582
   499
hoelzl@38656
   500
lemma (in measure_space) simple_integral_cong:
hoelzl@38656
   501
  assumes "\<And>t. t \<in> space M \<Longrightarrow> f t = g t"
hoelzl@38656
   502
  shows "simple_integral f = simple_integral g"
hoelzl@38656
   503
proof -
hoelzl@38656
   504
  have "f ` space M = g ` space M"
hoelzl@38656
   505
    "\<And>x. f -` {x} \<inter> space M = g -` {x} \<inter> space M"
hoelzl@38656
   506
    using assms by (auto intro!: image_eqI)
hoelzl@38656
   507
  thus ?thesis unfolding simple_integral_def by simp
hoelzl@38656
   508
qed
hoelzl@38656
   509
hoelzl@40859
   510
lemma (in measure_space) simple_integral_cong_measure:
hoelzl@40859
   511
  assumes "\<And>A. A \<in> sets M \<Longrightarrow> \<nu> A = \<mu> A" and "simple_function f"
hoelzl@40859
   512
  shows "measure_space.simple_integral M \<nu> f = simple_integral f"
hoelzl@40859
   513
proof -
hoelzl@40859
   514
  interpret v: measure_space M \<nu>
hoelzl@40859
   515
    by (rule measure_space_cong) fact
hoelzl@40871
   516
  from simple_functionD[OF `simple_function f`] assms show ?thesis
hoelzl@40859
   517
    unfolding simple_integral_def v.simple_integral_def
hoelzl@40859
   518
    by (auto intro!: setsum_cong)
hoelzl@40859
   519
qed
hoelzl@40859
   520
hoelzl@38656
   521
lemma (in measure_space) simple_integral_const[simp]:
hoelzl@38656
   522
  "simple_integral (\<lambda>x. c) = c * \<mu> (space M)"
hoelzl@38656
   523
proof (cases "space M = {}")
hoelzl@38656
   524
  case True thus ?thesis unfolding simple_integral_def by simp
hoelzl@38656
   525
next
hoelzl@38656
   526
  case False hence "(\<lambda>x. c) ` space M = {c}" by auto
hoelzl@38656
   527
  thus ?thesis unfolding simple_integral_def by simp
hoelzl@35582
   528
qed
hoelzl@35582
   529
hoelzl@38656
   530
lemma (in measure_space) simple_function_partition:
hoelzl@38656
   531
  assumes "simple_function f" and "simple_function g"
haftmann@39910
   532
  shows "simple_integral f = (\<Sum>A\<in>(\<lambda>x. f -` {f x} \<inter> g -` {g x} \<inter> space M) ` space M. the_elem (f`A) * \<mu> A)"
hoelzl@38656
   533
    (is "_ = setsum _ (?p ` space M)")
hoelzl@38656
   534
proof-
hoelzl@38656
   535
  let "?sub x" = "?p ` (f -` {x} \<inter> space M)"
hoelzl@38656
   536
  let ?SIGMA = "Sigma (f`space M) ?sub"
hoelzl@35582
   537
hoelzl@38656
   538
  have [intro]:
hoelzl@38656
   539
    "finite (f ` space M)"
hoelzl@38656
   540
    "finite (g ` space M)"
hoelzl@38656
   541
    using assms unfolding simple_function_def by simp_all
hoelzl@38656
   542
hoelzl@38656
   543
  { fix A
hoelzl@38656
   544
    have "?p ` (A \<inter> space M) \<subseteq>
hoelzl@38656
   545
      (\<lambda>(x,y). f -` {x} \<inter> g -` {y} \<inter> space M) ` (f`space M \<times> g`space M)"
hoelzl@38656
   546
      by auto
hoelzl@38656
   547
    hence "finite (?p ` (A \<inter> space M))"
nipkow@40786
   548
      by (rule finite_subset) auto }
hoelzl@38656
   549
  note this[intro, simp]
hoelzl@35582
   550
hoelzl@38656
   551
  { fix x assume "x \<in> space M"
hoelzl@38656
   552
    have "\<Union>(?sub (f x)) = (f -` {f x} \<inter> space M)" by auto
hoelzl@38656
   553
    moreover {
hoelzl@38656
   554
      fix x y
hoelzl@38656
   555
      have *: "f -` {f x} \<inter> g -` {g x} \<inter> space M
hoelzl@38656
   556
          = (f -` {f x} \<inter> space M) \<inter> (g -` {g x} \<inter> space M)" by auto
hoelzl@38656
   557
      assume "x \<in> space M" "y \<in> space M"
hoelzl@38656
   558
      hence "f -` {f x} \<inter> g -` {g x} \<inter> space M \<in> sets M"
hoelzl@38656
   559
        using assms unfolding simple_function_def * by auto }
hoelzl@38656
   560
    ultimately
hoelzl@38656
   561
    have "\<mu> (f -` {f x} \<inter> space M) = setsum (\<mu>) (?sub (f x))"
hoelzl@38656
   562
      by (subst measure_finitely_additive) auto }
hoelzl@38656
   563
  hence "simple_integral f = (\<Sum>(x,A)\<in>?SIGMA. x * \<mu> A)"
hoelzl@38656
   564
    unfolding simple_integral_def
hoelzl@38656
   565
    by (subst setsum_Sigma[symmetric],
hoelzl@38656
   566
       auto intro!: setsum_cong simp: setsum_right_distrib[symmetric])
haftmann@39910
   567
  also have "\<dots> = (\<Sum>A\<in>?p ` space M. the_elem (f`A) * \<mu> 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@38656
   585
lemma (in measure_space) simple_integral_add[simp]:
hoelzl@38656
   586
  assumes "simple_function f" and "simple_function g"
hoelzl@38656
   587
  shows "simple_integral (\<lambda>x. f x + g x) = simple_integral f + simple_integral 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@38656
   594
  thus ?thesis
hoelzl@38656
   595
    unfolding
hoelzl@38656
   596
      simple_function_partition[OF simple_function_add[OF assms] simple_function_Pair[OF assms]]
hoelzl@38656
   597
      simple_function_partition[OF `simple_function f` `simple_function g`]
hoelzl@38656
   598
      simple_function_partition[OF `simple_function g` `simple_function f`]
hoelzl@38656
   599
    apply (subst (3) Int_commute)
hoelzl@38656
   600
    by (auto simp add: field_simps setsum_addf[symmetric] intro!: setsum_cong)
hoelzl@35582
   601
qed
hoelzl@35582
   602
hoelzl@38656
   603
lemma (in measure_space) simple_integral_setsum[simp]:
hoelzl@38656
   604
  assumes "\<And>i. i \<in> P \<Longrightarrow> simple_function (f i)"
hoelzl@38656
   605
  shows "simple_integral (\<lambda>x. \<Sum>i\<in>P. f i x) = (\<Sum>i\<in>P. simple_integral (f i))"
hoelzl@38656
   606
proof cases
hoelzl@38656
   607
  assume "finite P"
hoelzl@38656
   608
  from this assms show ?thesis
hoelzl@38656
   609
    by induct (auto simp: simple_function_setsum simple_integral_add)
hoelzl@38656
   610
qed auto
hoelzl@38656
   611
hoelzl@38656
   612
lemma (in measure_space) simple_integral_mult[simp]:
hoelzl@38656
   613
  assumes "simple_function f"
hoelzl@38656
   614
  shows "simple_integral (\<lambda>x. c * f x) = c * simple_integral f"
hoelzl@38656
   615
proof -
hoelzl@38656
   616
  note mult = simple_function_mult[OF simple_function_const[of c] assms]
hoelzl@38656
   617
  { fix x let ?S = "f -` {f x} \<inter> (\<lambda>x. c * f x) -` {c * f x} \<inter> space M"
hoelzl@38656
   618
    assume "x \<in> space M"
hoelzl@38656
   619
    hence "(\<lambda>x. c * f x) ` ?S = {c * f x}" "f ` ?S = {f x}"
hoelzl@38656
   620
      by auto }
hoelzl@38656
   621
  thus ?thesis
hoelzl@38656
   622
    unfolding simple_function_partition[OF mult assms]
hoelzl@38656
   623
      simple_function_partition[OF assms mult]
hoelzl@38656
   624
    by (auto simp: setsum_right_distrib field_simps intro!: setsum_cong)
hoelzl@35582
   625
qed
hoelzl@35582
   626
hoelzl@40871
   627
lemma (in sigma_algebra) simple_function_If:
hoelzl@40871
   628
  assumes sf: "simple_function f" "simple_function g" and A: "A \<in> sets M"
hoelzl@40871
   629
  shows "simple_function (\<lambda>x. if x \<in> A then f x else g x)" (is "simple_function ?IF")
hoelzl@40871
   630
proof -
hoelzl@40871
   631
  def F \<equiv> "\<lambda>x. f -` {x} \<inter> space M" and G \<equiv> "\<lambda>x. g -` {x} \<inter> space M"
hoelzl@40871
   632
  show ?thesis unfolding simple_function_def
hoelzl@40871
   633
  proof safe
hoelzl@40871
   634
    have "?IF ` space M \<subseteq> f ` space M \<union> g ` space M" by auto
hoelzl@40871
   635
    from finite_subset[OF this] assms
hoelzl@40871
   636
    show "finite (?IF ` space M)" unfolding simple_function_def by auto
hoelzl@40871
   637
  next
hoelzl@40871
   638
    fix x assume "x \<in> space M"
hoelzl@40871
   639
    then have *: "?IF -` {?IF x} \<inter> space M = (if x \<in> A
hoelzl@40871
   640
      then ((F (f x) \<inter> A) \<union> (G (f x) - (G (f x) \<inter> A)))
hoelzl@40871
   641
      else ((F (g x) \<inter> A) \<union> (G (g x) - (G (g x) \<inter> A))))"
hoelzl@40871
   642
      using sets_into_space[OF A] by (auto split: split_if_asm simp: G_def F_def)
hoelzl@40871
   643
    have [intro]: "\<And>x. F x \<in> sets M" "\<And>x. G x \<in> sets M"
hoelzl@40871
   644
      unfolding F_def G_def using sf[THEN simple_functionD(2)] by auto
hoelzl@40871
   645
    show "?IF -` {?IF x} \<inter> space M \<in> sets M" unfolding * using A by auto
hoelzl@40871
   646
  qed
hoelzl@40871
   647
qed
hoelzl@40871
   648
hoelzl@40859
   649
lemma (in measure_space) simple_integral_mono_AE:
hoelzl@40859
   650
  assumes "simple_function f" and "simple_function g"
hoelzl@40859
   651
  and mono: "AE x. f x \<le> g x"
hoelzl@40859
   652
  shows "simple_integral f \<le> simple_integral g"
hoelzl@40859
   653
proof -
hoelzl@40859
   654
  let "?S x" = "(g -` {g x} \<inter> space M) \<inter> (f -` {f x} \<inter> space M)"
hoelzl@40859
   655
  have *: "\<And>x. g -` {g x} \<inter> f -` {f x} \<inter> space M = ?S x"
hoelzl@40859
   656
    "\<And>x. f -` {f x} \<inter> g -` {g x} \<inter> space M = ?S x" by auto
hoelzl@40859
   657
  show ?thesis
hoelzl@40859
   658
    unfolding *
hoelzl@40859
   659
      simple_function_partition[OF `simple_function f` `simple_function g`]
hoelzl@40859
   660
      simple_function_partition[OF `simple_function g` `simple_function f`]
hoelzl@40859
   661
  proof (safe intro!: setsum_mono)
hoelzl@40859
   662
    fix x assume "x \<in> space M"
hoelzl@40859
   663
    then have *: "f ` ?S x = {f x}" "g ` ?S x = {g x}" by auto
hoelzl@40859
   664
    show "the_elem (f`?S x) * \<mu> (?S x) \<le> the_elem (g`?S x) * \<mu> (?S x)"
hoelzl@40859
   665
    proof (cases "f x \<le> g x")
hoelzl@40859
   666
      case True then show ?thesis using * by (auto intro!: mult_right_mono)
hoelzl@40859
   667
    next
hoelzl@40859
   668
      case False
hoelzl@40859
   669
      obtain N where N: "{x\<in>space M. \<not> f x \<le> g x} \<subseteq> N" "N \<in> sets M" "\<mu> N = 0"
hoelzl@40859
   670
        using mono by (auto elim!: AE_E)
hoelzl@40859
   671
      have "?S x \<subseteq> N" using N `x \<in> space M` False by auto
hoelzl@40871
   672
      moreover have "?S x \<in> sets M" using assms
hoelzl@40871
   673
        by (rule_tac Int) (auto intro!: simple_functionD)
hoelzl@40859
   674
      ultimately have "\<mu> (?S x) \<le> \<mu> N"
hoelzl@40859
   675
        using `N \<in> sets M` by (auto intro!: measure_mono)
hoelzl@40859
   676
      then show ?thesis using `\<mu> N = 0` by auto
hoelzl@40859
   677
    qed
hoelzl@40859
   678
  qed
hoelzl@40859
   679
qed
hoelzl@40859
   680
hoelzl@38656
   681
lemma (in measure_space) simple_integral_mono:
hoelzl@38656
   682
  assumes "simple_function f" and "simple_function g"
hoelzl@38656
   683
  and mono: "\<And> x. x \<in> space M \<Longrightarrow> f x \<le> g x"
hoelzl@38656
   684
  shows "simple_integral f \<le> simple_integral g"
hoelzl@40859
   685
proof (rule simple_integral_mono_AE[OF assms(1, 2)])
hoelzl@40859
   686
  show "AE x. f x \<le> g x"
hoelzl@40859
   687
    using mono by (rule AE_cong) auto
hoelzl@35582
   688
qed
hoelzl@35582
   689
hoelzl@40859
   690
lemma (in measure_space) simple_integral_cong_AE:
hoelzl@40859
   691
  assumes "simple_function f" "simple_function g" and "AE x. f x = g x"
hoelzl@40859
   692
  shows "simple_integral f = simple_integral g"
hoelzl@40859
   693
  using assms by (auto simp: eq_iff intro!: simple_integral_mono_AE)
hoelzl@40859
   694
hoelzl@40859
   695
lemma (in measure_space) simple_integral_cong':
hoelzl@40859
   696
  assumes sf: "simple_function f" "simple_function g"
hoelzl@40859
   697
  and mea: "\<mu> {x\<in>space M. f x \<noteq> g x} = 0"
hoelzl@40859
   698
  shows "simple_integral f = simple_integral g"
hoelzl@40859
   699
proof (intro simple_integral_cong_AE sf AE_I)
hoelzl@40859
   700
  show "\<mu> {x\<in>space M. f x \<noteq> g x} = 0" by fact
hoelzl@40859
   701
  show "{x \<in> space M. f x \<noteq> g x} \<in> sets M"
hoelzl@40859
   702
    using sf[THEN borel_measurable_simple_function] by auto
hoelzl@40859
   703
qed simp
hoelzl@40859
   704
hoelzl@38656
   705
lemma (in measure_space) simple_integral_indicator:
hoelzl@38656
   706
  assumes "A \<in> sets M"
hoelzl@38656
   707
  assumes "simple_function f"
hoelzl@38656
   708
  shows "simple_integral (\<lambda>x. f x * indicator A x) =
hoelzl@38656
   709
    (\<Sum>x \<in> f ` space M. x * \<mu> (f -` {x} \<inter> space M \<inter> A))"
hoelzl@38656
   710
proof cases
hoelzl@38656
   711
  assume "A = space M"
hoelzl@38656
   712
  moreover hence "simple_integral (\<lambda>x. f x * indicator A x) = simple_integral f"
hoelzl@38656
   713
    by (auto intro!: simple_integral_cong)
hoelzl@38656
   714
  moreover have "\<And>X. X \<inter> space M \<inter> space M = X \<inter> space M" by auto
hoelzl@38656
   715
  ultimately show ?thesis by (simp add: simple_integral_def)
hoelzl@38656
   716
next
hoelzl@38656
   717
  assume "A \<noteq> space M"
hoelzl@38656
   718
  then obtain x where x: "x \<in> space M" "x \<notin> A" using sets_into_space[OF assms(1)] by auto
hoelzl@38656
   719
  have I: "(\<lambda>x. f x * indicator A x) ` space M = f ` A \<union> {0}" (is "?I ` _ = _")
hoelzl@35582
   720
  proof safe
hoelzl@38656
   721
    fix y assume "?I y \<notin> f ` A" hence "y \<notin> A" by auto thus "?I y = 0" by auto
hoelzl@38656
   722
  next
hoelzl@38656
   723
    fix y assume "y \<in> A" thus "f y \<in> ?I ` space M"
hoelzl@38656
   724
      using sets_into_space[OF assms(1)] by (auto intro!: image_eqI[of _ _ y])
hoelzl@38656
   725
  next
hoelzl@38656
   726
    show "0 \<in> ?I ` space M" using x by (auto intro!: image_eqI[of _ _ x])
hoelzl@35582
   727
  qed
hoelzl@38656
   728
  have *: "simple_integral (\<lambda>x. f x * indicator A x) =
hoelzl@38656
   729
    (\<Sum>x \<in> f ` space M \<union> {0}. x * \<mu> (f -` {x} \<inter> space M \<inter> A))"
hoelzl@38656
   730
    unfolding simple_integral_def I
hoelzl@38656
   731
  proof (rule setsum_mono_zero_cong_left)
hoelzl@38656
   732
    show "finite (f ` space M \<union> {0})"
hoelzl@38656
   733
      using assms(2) unfolding simple_function_def by auto
hoelzl@38656
   734
    show "f ` A \<union> {0} \<subseteq> f`space M \<union> {0}"
hoelzl@38656
   735
      using sets_into_space[OF assms(1)] by auto
hoelzl@40859
   736
    have "\<And>x. f x \<notin> f ` A \<Longrightarrow> f -` {f x} \<inter> space M \<inter> A = {}"
hoelzl@40859
   737
      by (auto simp: image_iff)
hoelzl@38656
   738
    thus "\<forall>i\<in>f ` space M \<union> {0} - (f ` A \<union> {0}).
hoelzl@38656
   739
      i * \<mu> (f -` {i} \<inter> space M \<inter> A) = 0" by auto
hoelzl@38656
   740
  next
hoelzl@38656
   741
    fix x assume "x \<in> f`A \<union> {0}"
hoelzl@38656
   742
    hence "x \<noteq> 0 \<Longrightarrow> ?I -` {x} \<inter> space M = f -` {x} \<inter> space M \<inter> A"
hoelzl@38656
   743
      by (auto simp: indicator_def split: split_if_asm)
hoelzl@38656
   744
    thus "x * \<mu> (?I -` {x} \<inter> space M) =
hoelzl@38656
   745
      x * \<mu> (f -` {x} \<inter> space M \<inter> A)" by (cases "x = 0") simp_all
hoelzl@38656
   746
  qed
hoelzl@38656
   747
  show ?thesis unfolding *
hoelzl@38656
   748
    using assms(2) unfolding simple_function_def
hoelzl@38656
   749
    by (auto intro!: setsum_mono_zero_cong_right)
hoelzl@38656
   750
qed
hoelzl@35582
   751
hoelzl@38656
   752
lemma (in measure_space) simple_integral_indicator_only[simp]:
hoelzl@38656
   753
  assumes "A \<in> sets M"
hoelzl@38656
   754
  shows "simple_integral (indicator A) = \<mu> A"
hoelzl@38656
   755
proof cases
hoelzl@38656
   756
  assume "space M = {}" hence "A = {}" using sets_into_space[OF assms] by auto
hoelzl@38656
   757
  thus ?thesis unfolding simple_integral_def using `space M = {}` by auto
hoelzl@38656
   758
next
hoelzl@38656
   759
  assume "space M \<noteq> {}" hence "(\<lambda>x. 1) ` space M = {1::pinfreal}" by auto
hoelzl@38656
   760
  thus ?thesis
hoelzl@38656
   761
    using simple_integral_indicator[OF assms simple_function_const[of 1]]
hoelzl@38656
   762
    using sets_into_space[OF assms]
hoelzl@38656
   763
    by (auto intro!: arg_cong[where f="\<mu>"])
hoelzl@38656
   764
qed
hoelzl@35582
   765
hoelzl@38656
   766
lemma (in measure_space) simple_integral_null_set:
hoelzl@38656
   767
  assumes "simple_function u" "N \<in> null_sets"
hoelzl@38656
   768
  shows "simple_integral (\<lambda>x. u x * indicator N x) = 0"
hoelzl@38656
   769
proof -
hoelzl@40859
   770
  have "AE x. indicator N x = (0 :: pinfreal)"
hoelzl@40859
   771
    using `N \<in> null_sets` by (auto simp: indicator_def intro!: AE_I[of _ N])
hoelzl@40859
   772
  then have "simple_integral (\<lambda>x. u x * indicator N x) = simple_integral (\<lambda>x. 0)"
hoelzl@40859
   773
    using assms by (intro simple_integral_cong_AE) (auto intro!: AE_disjI2)
hoelzl@40859
   774
  then show ?thesis by simp
hoelzl@38656
   775
qed
hoelzl@35582
   776
hoelzl@40859
   777
lemma (in measure_space) simple_integral_cong_AE_mult_indicator:
hoelzl@40859
   778
  assumes sf: "simple_function f" and eq: "AE x. x \<in> S" and "S \<in> sets M"
hoelzl@40859
   779
  shows "simple_integral f = simple_integral (\<lambda>x. f x * indicator S x)"
hoelzl@40859
   780
proof (rule simple_integral_cong_AE)
hoelzl@40859
   781
  show "simple_function f" by fact
hoelzl@40859
   782
  show "simple_function (\<lambda>x. f x * indicator S x)"
hoelzl@40859
   783
    using sf `S \<in> sets M` by auto
hoelzl@40859
   784
  from eq show "AE x. f x = f x * indicator S x"
hoelzl@40859
   785
    by (rule AE_mp) simp
hoelzl@35582
   786
qed
hoelzl@35582
   787
hoelzl@39092
   788
lemma (in measure_space) simple_integral_restricted:
hoelzl@39092
   789
  assumes "A \<in> sets M"
hoelzl@39092
   790
  assumes sf: "simple_function (\<lambda>x. f x * indicator A x)"
hoelzl@39092
   791
  shows "measure_space.simple_integral (restricted_space A) \<mu> f = simple_integral (\<lambda>x. f x * indicator A x)"
hoelzl@39092
   792
    (is "_ = simple_integral ?f")
hoelzl@39092
   793
  unfolding measure_space.simple_integral_def[OF restricted_measure_space[OF `A \<in> sets M`]]
hoelzl@39092
   794
  unfolding simple_integral_def
hoelzl@39092
   795
proof (simp, safe intro!: setsum_mono_zero_cong_left)
hoelzl@39092
   796
  from sf show "finite (?f ` space M)"
hoelzl@39092
   797
    unfolding simple_function_def by auto
hoelzl@39092
   798
next
hoelzl@39092
   799
  fix x assume "x \<in> A"
hoelzl@39092
   800
  then show "f x \<in> ?f ` space M"
hoelzl@39092
   801
    using sets_into_space `A \<in> sets M` by (auto intro!: image_eqI[of _ _ x])
hoelzl@39092
   802
next
hoelzl@39092
   803
  fix x assume "x \<in> space M" "?f x \<notin> f`A"
hoelzl@39092
   804
  then have "x \<notin> A" by (auto simp: image_iff)
hoelzl@39092
   805
  then show "?f x * \<mu> (?f -` {?f x} \<inter> space M) = 0" by simp
hoelzl@39092
   806
next
hoelzl@39092
   807
  fix x assume "x \<in> A"
hoelzl@39092
   808
  then have "f x \<noteq> 0 \<Longrightarrow>
hoelzl@39092
   809
    f -` {f x} \<inter> A = ?f -` {f x} \<inter> space M"
hoelzl@39092
   810
    using `A \<in> sets M` sets_into_space
hoelzl@39092
   811
    by (auto simp: indicator_def split: split_if_asm)
hoelzl@39092
   812
  then show "f x * \<mu> (f -` {f x} \<inter> A) =
hoelzl@39092
   813
    f x * \<mu> (?f -` {f x} \<inter> space M)"
hoelzl@39092
   814
    unfolding pinfreal_mult_cancel_left by auto
hoelzl@39092
   815
qed
hoelzl@39092
   816
hoelzl@39092
   817
lemma (in measure_space) simple_integral_subalgebra[simp]:
hoelzl@39092
   818
  assumes "measure_space (M\<lparr>sets := N\<rparr>) \<mu>"
hoelzl@39092
   819
  shows "measure_space.simple_integral (M\<lparr>sets := N\<rparr>) \<mu> = simple_integral"
hoelzl@39092
   820
  unfolding simple_integral_def_raw
hoelzl@39092
   821
  unfolding measure_space.simple_integral_def_raw[OF assms] by simp
hoelzl@39092
   822
hoelzl@40859
   823
lemma (in measure_space) simple_integral_vimage:
hoelzl@40859
   824
  fixes g :: "'a \<Rightarrow> pinfreal" and f :: "'d \<Rightarrow> 'a"
hoelzl@40859
   825
  assumes f: "bij_betw f S (space M)"
hoelzl@40859
   826
  shows "simple_integral g =
hoelzl@40859
   827
         measure_space.simple_integral (vimage_algebra S f) (\<lambda>A. \<mu> (f ` A)) (\<lambda>x. g (f x))"
hoelzl@40859
   828
    (is "_ = measure_space.simple_integral ?T ?\<mu> _")
hoelzl@40859
   829
proof -
hoelzl@40859
   830
  from f interpret T: measure_space ?T ?\<mu> by (rule measure_space_isomorphic)
hoelzl@40859
   831
  have surj: "f`S = space M"
hoelzl@40859
   832
    using f unfolding bij_betw_def by simp
hoelzl@40859
   833
  have *: "(\<lambda>x. g (f x)) ` S = g ` f ` S" by auto
hoelzl@40859
   834
  have **: "f`S = space M" using f unfolding bij_betw_def by auto
hoelzl@40859
   835
  { fix x assume "x \<in> space M"
hoelzl@40859
   836
    have "(f ` ((\<lambda>x. g (f x)) -` {g x} \<inter> S)) =
hoelzl@40859
   837
      (f ` (f -` (g -` {g x}) \<inter> S))" by auto
hoelzl@40859
   838
    also have "f -` (g -` {g x}) \<inter> S = f -` (g -` {g x} \<inter> space M) \<inter> S"
hoelzl@40859
   839
      using f unfolding bij_betw_def by auto
hoelzl@40859
   840
    also have "(f ` (f -` (g -` {g x} \<inter> space M) \<inter> S)) = g -` {g x} \<inter> space M"
hoelzl@40859
   841
      using ** by (intro image_vimage_inter_eq) auto
hoelzl@40859
   842
    finally have "(f ` ((\<lambda>x. g (f x)) -` {g x} \<inter> S)) = g -` {g x} \<inter> space M" by auto }
hoelzl@40859
   843
  then show ?thesis using assms
hoelzl@40859
   844
    unfolding simple_integral_def T.simple_integral_def bij_betw_def
hoelzl@40859
   845
    by (auto simp add: * intro!: setsum_cong)
hoelzl@40859
   846
qed
hoelzl@40859
   847
hoelzl@35692
   848
section "Continuous posititve integration"
hoelzl@35692
   849
hoelzl@38656
   850
definition (in measure_space)
hoelzl@38656
   851
  "positive_integral f =
hoelzl@40872
   852
    SUPR {g. simple_function g \<and> g \<le> f \<and> \<omega> \<notin> g`space M} simple_integral"
hoelzl@35582
   853
hoelzl@40859
   854
lemma (in measure_space) positive_integral_cong_measure:
hoelzl@40859
   855
  assumes "\<And>A. A \<in> sets M \<Longrightarrow> \<nu> A = \<mu> A"
hoelzl@40859
   856
  shows "measure_space.positive_integral M \<nu> f = positive_integral f"
hoelzl@40859
   857
proof -
hoelzl@40859
   858
  interpret v: measure_space M \<nu>
hoelzl@40859
   859
    by (rule measure_space_cong) fact
hoelzl@40859
   860
  with assms show ?thesis
hoelzl@40859
   861
    unfolding positive_integral_def v.positive_integral_def SUPR_def
hoelzl@40859
   862
    by (auto intro!: arg_cong[where f=Sup] image_cong
hoelzl@40859
   863
             simp: simple_integral_cong_measure[of \<nu>])
hoelzl@40859
   864
qed
hoelzl@40859
   865
hoelzl@38656
   866
lemma (in measure_space) positive_integral_alt1:
hoelzl@38656
   867
  "positive_integral f =
hoelzl@38656
   868
    (SUP g : {g. simple_function g \<and> (\<forall>x\<in>space M. g x \<le> f x \<and> g x \<noteq> \<omega>)}. simple_integral g)"
hoelzl@38656
   869
  unfolding positive_integral_def SUPR_def
hoelzl@38656
   870
proof (safe intro!: arg_cong[where f=Sup])
hoelzl@38656
   871
  fix g let ?g = "\<lambda>x. if x \<in> space M then g x else f x"
hoelzl@38656
   872
  assume "simple_function g" "\<forall>x\<in>space M. g x \<le> f x \<and> g x \<noteq> \<omega>"
hoelzl@38656
   873
  hence "?g \<le> f" "simple_function ?g" "simple_integral g = simple_integral ?g"
hoelzl@38656
   874
    "\<omega> \<notin> g`space M"
hoelzl@38656
   875
    unfolding le_fun_def by (auto cong: simple_function_cong simple_integral_cong)
hoelzl@38656
   876
  thus "simple_integral g \<in> simple_integral ` {g. simple_function g \<and> g \<le> f \<and> \<omega> \<notin> g`space M}"
hoelzl@38656
   877
    by auto
hoelzl@38656
   878
next
hoelzl@38656
   879
  fix g assume "simple_function g" "g \<le> f" "\<omega> \<notin> g`space M"
hoelzl@38656
   880
  hence "simple_function g" "\<forall>x\<in>space M. g x \<le> f x \<and> g x \<noteq> \<omega>"
hoelzl@38656
   881
    by (auto simp add: le_fun_def image_iff)
hoelzl@38656
   882
  thus "simple_integral g \<in> simple_integral ` {g. simple_function g \<and> (\<forall>x\<in>space M. g x \<le> f x \<and> g x \<noteq> \<omega>)}"
hoelzl@38656
   883
    by auto
hoelzl@35582
   884
qed
hoelzl@35582
   885
hoelzl@40872
   886
lemma image_set_cong:
hoelzl@40872
   887
  assumes A: "\<And>x. x \<in> A \<Longrightarrow> \<exists>y\<in>B. f x = g y"
hoelzl@40872
   888
  assumes B: "\<And>y. y \<in> B \<Longrightarrow> \<exists>x\<in>A. g y = f x"
hoelzl@40872
   889
  shows "f ` A = g ` B"
hoelzl@40872
   890
  using assms by blast
hoelzl@40872
   891
hoelzl@38656
   892
lemma (in measure_space) positive_integral_alt:
hoelzl@38656
   893
  "positive_integral f =
hoelzl@40872
   894
    (SUP g : {g. simple_function g \<and> g \<le> f}. simple_integral g)" (is "_ = ?alt")
hoelzl@40872
   895
proof (rule antisym SUP_leI)
hoelzl@40872
   896
  show "?alt \<le> positive_integral f" unfolding positive_integral_def
hoelzl@40872
   897
  proof (safe intro!: SUP_leI)
hoelzl@40872
   898
    fix g assume g: "simple_function g" "g \<le> f"
hoelzl@40872
   899
    let ?G = "g -` {\<omega>} \<inter> space M"
hoelzl@40872
   900
    show "simple_integral g \<le>
hoelzl@40872
   901
      SUPR {g. simple_function g \<and> g \<le> f \<and> \<omega> \<notin> g ` space M} simple_integral"
hoelzl@40872
   902
      (is "simple_integral g \<le> SUPR ?A simple_integral")
hoelzl@40872
   903
    proof cases
hoelzl@40872
   904
      let ?g = "\<lambda>x. indicator (space M - ?G) x * g x"
hoelzl@40872
   905
      have g': "simple_function ?g"
hoelzl@40872
   906
        using g by (auto intro: simple_functionD)
hoelzl@40872
   907
      moreover
hoelzl@40872
   908
      assume "\<mu> ?G = 0"
hoelzl@40872
   909
      then have "AE x. g x = ?g x" using g
hoelzl@40872
   910
        by (intro AE_I[where N="?G"])
hoelzl@40872
   911
           (auto intro: simple_functionD simp: indicator_def)
hoelzl@40872
   912
      with g(1) g' have "simple_integral g = simple_integral ?g"
hoelzl@40872
   913
        by (rule simple_integral_cong_AE)
hoelzl@40872
   914
      moreover have "?g \<le> g" by (auto simp: le_fun_def indicator_def)
hoelzl@40872
   915
      from this `g \<le> f` have "?g \<le> f" by (rule order_trans)
hoelzl@40872
   916
      moreover have "\<omega> \<notin> ?g ` space M"
hoelzl@40872
   917
        by (auto simp: indicator_def split: split_if_asm)
hoelzl@40872
   918
      ultimately show ?thesis by (auto intro!: le_SUPI)
hoelzl@40872
   919
    next
hoelzl@40872
   920
      assume "\<mu> ?G \<noteq> 0"
hoelzl@40872
   921
      then have "?G \<noteq> {}" by auto
hoelzl@40872
   922
      then have "\<omega> \<in> g`space M" by force
hoelzl@40872
   923
      then have "space M \<noteq> {}" by auto
hoelzl@40872
   924
      have "SUPR ?A simple_integral = \<omega>"
hoelzl@40872
   925
      proof (intro SUP_\<omega>[THEN iffD2] allI impI)
hoelzl@40872
   926
        fix x assume "x < \<omega>"
hoelzl@40872
   927
        then guess n unfolding less_\<omega>_Ex_of_nat .. note n = this
hoelzl@40872
   928
        then have "0 < n" by (intro neq0_conv[THEN iffD1] notI) simp
hoelzl@40872
   929
        let ?g = "\<lambda>x. (of_nat n / (if \<mu> ?G = \<omega> then 1 else \<mu> ?G)) * indicator ?G x"
hoelzl@40872
   930
        show "\<exists>i\<in>?A. x < simple_integral i"
hoelzl@40872
   931
        proof (intro bexI impI CollectI conjI)
hoelzl@40872
   932
          show "simple_function ?g" using g
hoelzl@40872
   933
            by (auto intro!: simple_functionD simple_function_add)
hoelzl@40872
   934
          have "?g \<le> g" by (auto simp: le_fun_def indicator_def)
hoelzl@40872
   935
          from this g(2) show "?g \<le> f" by (rule order_trans)
hoelzl@40872
   936
          show "\<omega> \<notin> ?g ` space M"
hoelzl@40872
   937
            using `\<mu> ?G \<noteq> 0` by (auto simp: indicator_def split: split_if_asm)
hoelzl@40872
   938
          have "x < (of_nat n / (if \<mu> ?G = \<omega> then 1 else \<mu> ?G)) * \<mu> ?G"
hoelzl@40872
   939
            using n `\<mu> ?G \<noteq> 0` `0 < n`
hoelzl@40872
   940
            by (auto simp: pinfreal_noteq_omega_Ex field_simps)
hoelzl@40872
   941
          also have "\<dots> = simple_integral ?g" using g `space M \<noteq> {}`
hoelzl@40872
   942
            by (subst simple_integral_indicator)
hoelzl@40872
   943
               (auto simp: image_constant ac_simps dest: simple_functionD)
hoelzl@40872
   944
          finally show "x < simple_integral ?g" .
hoelzl@40872
   945
        qed
hoelzl@40872
   946
      qed
hoelzl@40872
   947
      then show ?thesis by simp
hoelzl@40872
   948
    qed
hoelzl@35582
   949
  qed
hoelzl@40872
   950
qed (auto intro!: SUP_subset simp: positive_integral_def)
hoelzl@35582
   951
hoelzl@38656
   952
lemma (in measure_space) positive_integral_cong:
hoelzl@38656
   953
  assumes "\<And>x. x \<in> space M \<Longrightarrow> f x = g x"
hoelzl@38656
   954
  shows "positive_integral f = positive_integral g"
hoelzl@38656
   955
proof -
hoelzl@38656
   956
  have "\<And>h. (\<forall>x\<in>space M. h x \<le> f x \<and> h x \<noteq> \<omega>) = (\<forall>x\<in>space M. h x \<le> g x \<and> h x \<noteq> \<omega>)"
hoelzl@38656
   957
    using assms by auto
hoelzl@38656
   958
  thus ?thesis unfolding positive_integral_alt1 by auto
hoelzl@38656
   959
qed
hoelzl@38656
   960
hoelzl@38656
   961
lemma (in measure_space) positive_integral_eq_simple_integral:
hoelzl@38656
   962
  assumes "simple_function f"
hoelzl@38656
   963
  shows "positive_integral f = simple_integral f"
hoelzl@38656
   964
  unfolding positive_integral_alt
hoelzl@38656
   965
proof (safe intro!: pinfreal_SUPI)
hoelzl@38656
   966
  fix g assume "simple_function g" "g \<le> f"
hoelzl@38656
   967
  with assms show "simple_integral g \<le> simple_integral f"
hoelzl@38656
   968
    by (auto intro!: simple_integral_mono simp: le_fun_def)
hoelzl@38656
   969
next
hoelzl@38656
   970
  fix y assume "\<forall>x. x\<in>{g. simple_function g \<and> g \<le> f} \<longrightarrow> simple_integral x \<le> y"
hoelzl@38656
   971
  with assms show "simple_integral f \<le> y" by auto
hoelzl@38656
   972
qed
hoelzl@35582
   973
hoelzl@40859
   974
lemma (in measure_space) positive_integral_mono_AE:
hoelzl@40859
   975
  assumes ae: "AE x. u x \<le> v x"
hoelzl@38656
   976
  shows "positive_integral u \<le> positive_integral v"
hoelzl@38656
   977
  unfolding positive_integral_alt1
hoelzl@38656
   978
proof (safe intro!: SUPR_mono)
hoelzl@40859
   979
  fix a assume a: "simple_function a" and mono: "\<forall>x\<in>space M. a x \<le> u x \<and> a x \<noteq> \<omega>"
hoelzl@40859
   980
  from ae obtain N where N: "{x\<in>space M. \<not> u x \<le> v x} \<subseteq> N" "N \<in> sets M" "\<mu> N = 0"
hoelzl@40859
   981
    by (auto elim!: AE_E)
hoelzl@40859
   982
  have "simple_function (\<lambda>x. a x * indicator (space M - N) x)"
hoelzl@40859
   983
    using `N \<in> sets M` a by auto
hoelzl@40859
   984
  with a show "\<exists>b\<in>{g. simple_function g \<and> (\<forall>x\<in>space M. g x \<le> v x \<and> g x \<noteq> \<omega>)}.
hoelzl@40859
   985
    simple_integral a \<le> simple_integral b"
hoelzl@40859
   986
  proof (safe intro!: bexI[of _ "\<lambda>x. a x * indicator (space M - N) x"]
hoelzl@40859
   987
                      simple_integral_mono_AE)
hoelzl@40859
   988
    show "AE x. a x \<le> a x * indicator (space M - N) x"
hoelzl@40859
   989
    proof (rule AE_I, rule subset_refl)
hoelzl@40859
   990
      have *: "{x \<in> space M. \<not> a x \<le> a x * indicator (space M - N) x} =
hoelzl@40859
   991
        N \<inter> {x \<in> space M. a x \<noteq> 0}" (is "?N = _")
hoelzl@40859
   992
        using `N \<in> sets M`[THEN sets_into_space] by (auto simp: indicator_def)
hoelzl@40859
   993
      then show "?N \<in> sets M" 
hoelzl@40859
   994
        using `N \<in> sets M` `simple_function a`[THEN borel_measurable_simple_function]
hoelzl@40859
   995
        by (auto intro!: measure_mono Int)
hoelzl@40859
   996
      then have "\<mu> ?N \<le> \<mu> N"
hoelzl@40859
   997
        unfolding * using `N \<in> sets M` by (auto intro!: measure_mono)
hoelzl@40859
   998
      then show "\<mu> ?N = 0" using `\<mu> N = 0` by auto
hoelzl@40859
   999
    qed
hoelzl@40859
  1000
  next
hoelzl@40859
  1001
    fix x assume "x \<in> space M"
hoelzl@40859
  1002
    show "a x * indicator (space M - N) x \<le> v x"
hoelzl@40859
  1003
    proof (cases "x \<in> N")
hoelzl@40859
  1004
      case True then show ?thesis by simp
hoelzl@40859
  1005
    next
hoelzl@40859
  1006
      case False
hoelzl@40859
  1007
      with N mono have "a x \<le> u x" "u x \<le> v x" using `x \<in> space M` by auto
hoelzl@40859
  1008
      with False `x \<in> space M` show "a x * indicator (space M - N) x \<le> v x" by auto
hoelzl@40859
  1009
    qed
hoelzl@40859
  1010
    assume "a x * indicator (space M - N) x = \<omega>"
hoelzl@40859
  1011
    with mono `x \<in> space M` show False
hoelzl@40859
  1012
      by (simp split: split_if_asm add: indicator_def)
hoelzl@40859
  1013
  qed
hoelzl@40859
  1014
qed
hoelzl@40859
  1015
hoelzl@40859
  1016
lemma (in measure_space) positive_integral_cong_AE:
hoelzl@40859
  1017
  "AE x. u x = v x \<Longrightarrow> positive_integral u = positive_integral v"
hoelzl@40859
  1018
  by (auto simp: eq_iff intro!: positive_integral_mono_AE)
hoelzl@40859
  1019
hoelzl@40859
  1020
lemma (in measure_space) positive_integral_mono:
hoelzl@40859
  1021
  assumes mono: "\<And>x. x \<in> space M \<Longrightarrow> u x \<le> v x"
hoelzl@40859
  1022
  shows "positive_integral u \<le> positive_integral v"
hoelzl@40859
  1023
  using mono by (auto intro!: AE_cong positive_integral_mono_AE)
hoelzl@40859
  1024
hoelzl@40859
  1025
lemma (in measure_space) positive_integral_vimage:
hoelzl@40859
  1026
  fixes g :: "'a \<Rightarrow> pinfreal" and f :: "'d \<Rightarrow> 'a"
hoelzl@40859
  1027
  assumes f: "bij_betw f S (space M)"
hoelzl@40859
  1028
  shows "positive_integral g =
hoelzl@40859
  1029
         measure_space.positive_integral (vimage_algebra S f) (\<lambda>A. \<mu> (f ` A)) (\<lambda>x. g (f x))"
hoelzl@40859
  1030
    (is "_ = measure_space.positive_integral ?T ?\<mu> _")
hoelzl@40859
  1031
proof -
hoelzl@40859
  1032
  from f interpret T: measure_space ?T ?\<mu> by (rule measure_space_isomorphic)
hoelzl@40859
  1033
  have f_fun: "f \<in> S \<rightarrow> space M" using assms unfolding bij_betw_def by auto
hoelzl@40859
  1034
  from assms have inv: "bij_betw (the_inv_into S f) (space M) S"
hoelzl@40859
  1035
    by (rule bij_betw_the_inv_into)
hoelzl@40859
  1036
  then have inv_fun: "the_inv_into S f \<in> space M \<rightarrow> S" unfolding bij_betw_def by auto
hoelzl@40859
  1037
hoelzl@40859
  1038
  have surj: "f`S = space M"
hoelzl@40859
  1039
    using f unfolding bij_betw_def by simp
hoelzl@40859
  1040
  have inj: "inj_on f S"
hoelzl@40859
  1041
    using f unfolding bij_betw_def by simp
hoelzl@40859
  1042
  have inv_f: "\<And>x. x \<in> space M \<Longrightarrow> f (the_inv_into S f x) = x"
hoelzl@40859
  1043
    using f_the_inv_into_f[of f S] f unfolding bij_betw_def by auto
hoelzl@40859
  1044
hoelzl@40859
  1045
  from simple_integral_vimage[OF assms, symmetric]
hoelzl@40859
  1046
  have *: "simple_integral = T.simple_integral \<circ> (\<lambda>g. g \<circ> f)" by (simp add: comp_def)
hoelzl@40871
  1047
hoelzl@40859
  1048
  show ?thesis
hoelzl@40859
  1049
    unfolding positive_integral_alt1 T.positive_integral_alt1 SUPR_def * image_compose
hoelzl@40859
  1050
  proof (safe intro!: arg_cong[where f=Sup] image_set_cong, simp_all add: comp_def)
hoelzl@40859
  1051
    fix g' :: "'a \<Rightarrow> pinfreal" assume "simple_function g'" "\<forall>x\<in>space M. g' x \<le> g x \<and> g' x \<noteq> \<omega>"
hoelzl@40859
  1052
    then show "\<exists>h. T.simple_function h \<and> (\<forall>x\<in>S. h x \<le> g (f x) \<and> h x \<noteq> \<omega>) \<and>
hoelzl@40859
  1053
                   T.simple_integral (\<lambda>x. g' (f x)) = T.simple_integral h"
hoelzl@40859
  1054
      using f unfolding bij_betw_def
hoelzl@40859
  1055
      by (auto intro!: exI[of _ "\<lambda>x. g' (f x)"]
hoelzl@40859
  1056
               simp add: le_fun_def simple_function_vimage[OF _ f_fun])
hoelzl@40859
  1057
  next
hoelzl@40859
  1058
    fix g' :: "'d \<Rightarrow> pinfreal" assume g': "T.simple_function g'" "\<forall>x\<in>S. g' x \<le> g (f x) \<and> g' x \<noteq> \<omega>"
hoelzl@40859
  1059
    let ?g = "\<lambda>x. g' (the_inv_into S f x)"
hoelzl@40859
  1060
    show "\<exists>h. simple_function h \<and> (\<forall>x\<in>space M. h x \<le> g x \<and> h x \<noteq> \<omega>) \<and>
hoelzl@40859
  1061
              T.simple_integral g' = T.simple_integral (\<lambda>x. h (f x))"
hoelzl@40859
  1062
    proof (intro exI[of _ ?g] conjI ballI)
hoelzl@40859
  1063
      { fix x assume x: "x \<in> space M"
hoelzl@40859
  1064
        then have "the_inv_into S f x \<in> S" using inv_fun by auto
hoelzl@40859
  1065
        with g' have "g' (the_inv_into S f x) \<le> g (f (the_inv_into S f x)) \<and> g' (the_inv_into S f x) \<noteq> \<omega>"
hoelzl@40859
  1066
          by auto
hoelzl@40859
  1067
        then show "g' (the_inv_into S f x) \<le> g x" "g' (the_inv_into S f x) \<noteq> \<omega>"
hoelzl@40859
  1068
          using f_the_inv_into_f[of f S x] x f unfolding bij_betw_def by auto }
hoelzl@40859
  1069
      note vimage_vimage_inv[OF f inv_f inv_fun, simp]
hoelzl@40859
  1070
      from T.simple_function_vimage[OF g'(1), unfolded space_vimage_algebra, OF inv_fun]
hoelzl@40859
  1071
      show "simple_function (\<lambda>x. g' (the_inv_into S f x))"
hoelzl@40859
  1072
        unfolding simple_function_def by (simp add: simple_function_def)
hoelzl@40859
  1073
      show "T.simple_integral g' = T.simple_integral (\<lambda>x. ?g (f x))"
hoelzl@40859
  1074
        using the_inv_into_f_f[OF inj] by (auto intro!: T.simple_integral_cong)
hoelzl@40859
  1075
    qed
hoelzl@40859
  1076
  qed
hoelzl@40859
  1077
qed
hoelzl@40859
  1078
hoelzl@40859
  1079
lemma (in measure_space) positive_integral_vimage_inv:
hoelzl@40859
  1080
  fixes g :: "'d \<Rightarrow> pinfreal" and f :: "'d \<Rightarrow> 'a"
hoelzl@40859
  1081
  assumes f: "bij_betw f S (space M)"
hoelzl@40859
  1082
  shows "measure_space.positive_integral (vimage_algebra S f) (\<lambda>A. \<mu> (f ` A)) g =
hoelzl@40859
  1083
      positive_integral (\<lambda>x. g (the_inv_into S f x))"
hoelzl@40859
  1084
proof -
hoelzl@40859
  1085
  interpret v: measure_space "vimage_algebra S f" "\<lambda>A. \<mu> (f ` A)"
hoelzl@40859
  1086
    using f by (rule measure_space_isomorphic)
hoelzl@40859
  1087
  show ?thesis
hoelzl@40859
  1088
    unfolding positive_integral_vimage[OF f, of "\<lambda>x. g (the_inv_into S f x)"]
hoelzl@40859
  1089
    using f[unfolded bij_betw_def]
hoelzl@40859
  1090
    by (auto intro!: v.positive_integral_cong simp: the_inv_into_f_f)
hoelzl@38656
  1091
qed
hoelzl@38656
  1092
hoelzl@38656
  1093
lemma (in measure_space) positive_integral_SUP_approx:
hoelzl@38656
  1094
  assumes "f \<up> s"
hoelzl@38656
  1095
  and f: "\<And>i. f i \<in> borel_measurable M"
hoelzl@38656
  1096
  and "simple_function u"
hoelzl@38656
  1097
  and le: "u \<le> s" and real: "\<omega> \<notin> u`space M"
hoelzl@38656
  1098
  shows "simple_integral u \<le> (SUP i. positive_integral (f i))" (is "_ \<le> ?S")
hoelzl@38656
  1099
proof (rule pinfreal_le_mult_one_interval)
hoelzl@38656
  1100
  fix a :: pinfreal assume "0 < a" "a < 1"
hoelzl@38656
  1101
  hence "a \<noteq> 0" by auto
hoelzl@38656
  1102
  let "?B i" = "{x \<in> space M. a * u x \<le> f i x}"
hoelzl@38656
  1103
  have B: "\<And>i. ?B i \<in> sets M"
hoelzl@38656
  1104
    using f `simple_function u` by (auto simp: borel_measurable_simple_function)
hoelzl@38656
  1105
hoelzl@38656
  1106
  let "?uB i x" = "u x * indicator (?B i) x"
hoelzl@38656
  1107
hoelzl@38656
  1108
  { fix i have "?B i \<subseteq> ?B (Suc i)"
hoelzl@38656
  1109
    proof safe
hoelzl@38656
  1110
      fix i x assume "a * u x \<le> f i x"
hoelzl@38656
  1111
      also have "\<dots> \<le> f (Suc i) x"
hoelzl@38656
  1112
        using `f \<up> s` unfolding isoton_def le_fun_def by auto
hoelzl@38656
  1113
      finally show "a * u x \<le> f (Suc i) x" .
hoelzl@38656
  1114
    qed }
hoelzl@38656
  1115
  note B_mono = this
hoelzl@35582
  1116
hoelzl@38656
  1117
  have u: "\<And>x. x \<in> space M \<Longrightarrow> u -` {u x} \<inter> space M \<in> sets M"
hoelzl@38656
  1118
    using `simple_function u` by (auto simp add: simple_function_def)
hoelzl@38656
  1119
hoelzl@40859
  1120
  have "\<And>i. (\<lambda>n. (u -` {i} \<inter> space M) \<inter> ?B n) \<up> (u -` {i} \<inter> space M)" using B_mono unfolding isoton_def
hoelzl@40859
  1121
  proof safe
hoelzl@40859
  1122
    fix x i assume "x \<in> space M"
hoelzl@40859
  1123
    show "x \<in> (\<Union>i. (u -` {u x} \<inter> space M) \<inter> ?B i)"
hoelzl@40859
  1124
    proof cases
hoelzl@40859
  1125
      assume "u x = 0" thus ?thesis using `x \<in> space M` by simp
hoelzl@40859
  1126
    next
hoelzl@40859
  1127
      assume "u x \<noteq> 0"
hoelzl@40859
  1128
      with `a < 1` real `x \<in> space M`
hoelzl@40859
  1129
      have "a * u x < 1 * u x" by (rule_tac pinfreal_mult_strict_right_mono) (auto simp: image_iff)
hoelzl@40859
  1130
      also have "\<dots> \<le> (SUP i. f i x)" using le `f \<up> s`
hoelzl@40859
  1131
        unfolding isoton_fun_expand by (auto simp: isoton_def le_fun_def)
hoelzl@40859
  1132
      finally obtain i where "a * u x < f i x" unfolding SUPR_def
hoelzl@40859
  1133
        by (auto simp add: less_Sup_iff)
hoelzl@40859
  1134
      hence "a * u x \<le> f i x" by auto
hoelzl@40859
  1135
      thus ?thesis using `x \<in> space M` by auto
hoelzl@40859
  1136
    qed
hoelzl@40859
  1137
  qed auto
hoelzl@40859
  1138
  note measure_conv = measure_up[OF Int[OF u B] this]
hoelzl@38656
  1139
hoelzl@38656
  1140
  have "simple_integral u = (SUP i. simple_integral (?uB i))"
hoelzl@38656
  1141
    unfolding simple_integral_indicator[OF B `simple_function u`]
hoelzl@38656
  1142
  proof (subst SUPR_pinfreal_setsum, safe)
hoelzl@38656
  1143
    fix x n assume "x \<in> space M"
hoelzl@38656
  1144
    have "\<mu> (u -` {u x} \<inter> space M \<inter> {x \<in> space M. a * u x \<le> f n x})
hoelzl@38656
  1145
      \<le> \<mu> (u -` {u x} \<inter> space M \<inter> {x \<in> space M. a * u x \<le> f (Suc n) x})"
hoelzl@38656
  1146
      using B_mono Int[OF u[OF `x \<in> space M`] B] by (auto intro!: measure_mono)
hoelzl@38656
  1147
    thus "u x * \<mu> (u -` {u x} \<inter> space M \<inter> ?B n)
hoelzl@38656
  1148
            \<le> u x * \<mu> (u -` {u x} \<inter> space M \<inter> ?B (Suc n))"
hoelzl@38656
  1149
      by (auto intro: mult_left_mono)
hoelzl@38656
  1150
  next
hoelzl@38656
  1151
    show "simple_integral u =
hoelzl@38656
  1152
      (\<Sum>i\<in>u ` space M. SUP n. i * \<mu> (u -` {i} \<inter> space M \<inter> ?B n))"
hoelzl@38656
  1153
      using measure_conv unfolding simple_integral_def isoton_def
hoelzl@38656
  1154
      by (auto intro!: setsum_cong simp: pinfreal_SUP_cmult)
hoelzl@38656
  1155
  qed
hoelzl@38656
  1156
  moreover
hoelzl@38656
  1157
  have "a * (SUP i. simple_integral (?uB i)) \<le> ?S"
hoelzl@38656
  1158
    unfolding pinfreal_SUP_cmult[symmetric]
hoelzl@38705
  1159
  proof (safe intro!: SUP_mono bexI)
hoelzl@38656
  1160
    fix i
hoelzl@38656
  1161
    have "a * simple_integral (?uB i) = simple_integral (\<lambda>x. a * ?uB i x)"
hoelzl@38656
  1162
      using B `simple_function u`
hoelzl@38656
  1163
      by (subst simple_integral_mult[symmetric]) (auto simp: field_simps)
hoelzl@38656
  1164
    also have "\<dots> \<le> positive_integral (f i)"
hoelzl@38656
  1165
    proof -
hoelzl@38656
  1166
      have "\<And>x. a * ?uB i x \<le> f i x" unfolding indicator_def by auto
hoelzl@38656
  1167
      hence *: "simple_function (\<lambda>x. a * ?uB i x)" using B assms(3)
hoelzl@38656
  1168
        by (auto intro!: simple_integral_mono)
hoelzl@38656
  1169
      show ?thesis unfolding positive_integral_eq_simple_integral[OF *, symmetric]
hoelzl@38656
  1170
        by (auto intro!: positive_integral_mono simp: indicator_def)
hoelzl@38656
  1171
    qed
hoelzl@38656
  1172
    finally show "a * simple_integral (?uB i) \<le> positive_integral (f i)"
hoelzl@38656
  1173
      by auto
hoelzl@38705
  1174
  qed simp
hoelzl@38656
  1175
  ultimately show "a * simple_integral u \<le> ?S" by simp
hoelzl@35582
  1176
qed
hoelzl@35582
  1177
hoelzl@35582
  1178
text {* Beppo-Levi monotone convergence theorem *}
hoelzl@38656
  1179
lemma (in measure_space) positive_integral_isoton:
hoelzl@38656
  1180
  assumes "f \<up> u" "\<And>i. f i \<in> borel_measurable M"
hoelzl@38656
  1181
  shows "(\<lambda>i. positive_integral (f i)) \<up> positive_integral u"
hoelzl@38656
  1182
  unfolding isoton_def
hoelzl@38656
  1183
proof safe
hoelzl@38656
  1184
  fix i show "positive_integral (f i) \<le> positive_integral (f (Suc i))"
hoelzl@38656
  1185
    apply (rule positive_integral_mono)
hoelzl@38656
  1186
    using `f \<up> u` unfolding isoton_def le_fun_def by auto
hoelzl@38656
  1187
next
hoelzl@38656
  1188
  have "u \<in> borel_measurable M"
hoelzl@38656
  1189
    using borel_measurable_SUP[of UNIV f] assms by (auto simp: isoton_def)
hoelzl@38656
  1190
  have u: "u = (SUP i. f i)" using `f \<up> u` unfolding isoton_def by auto
hoelzl@35582
  1191
hoelzl@38656
  1192
  show "(SUP i. positive_integral (f i)) = positive_integral u"
hoelzl@38656
  1193
  proof (rule antisym)
hoelzl@38656
  1194
    from `f \<up> u`[THEN isoton_Sup, unfolded le_fun_def]
hoelzl@38656
  1195
    show "(SUP j. positive_integral (f j)) \<le> positive_integral u"
hoelzl@38656
  1196
      by (auto intro!: SUP_leI positive_integral_mono)
hoelzl@38656
  1197
  next
hoelzl@38656
  1198
    show "positive_integral u \<le> (SUP i. positive_integral (f i))"
hoelzl@38656
  1199
      unfolding positive_integral_def[of u]
hoelzl@38656
  1200
      by (auto intro!: SUP_leI positive_integral_SUP_approx[OF assms])
hoelzl@35582
  1201
  qed
hoelzl@35582
  1202
qed
hoelzl@35582
  1203
hoelzl@40859
  1204
lemma (in measure_space) positive_integral_monotone_convergence_SUP:
hoelzl@40859
  1205
  assumes "\<And>i x. x \<in> space M \<Longrightarrow> f i x \<le> f (Suc i) x"
hoelzl@40859
  1206
  assumes "\<And>i. f i \<in> borel_measurable M"
hoelzl@40859
  1207
  shows "(SUP i. positive_integral (f i)) = positive_integral (\<lambda>x. SUP i. f i x)"
hoelzl@40859
  1208
    (is "_ = positive_integral ?u")
hoelzl@40859
  1209
proof -
hoelzl@40859
  1210
  have "?u \<in> borel_measurable M"
hoelzl@40859
  1211
    using borel_measurable_SUP[of _ f] assms by (simp add: SUPR_fun_expand)
hoelzl@40859
  1212
hoelzl@40859
  1213
  show ?thesis
hoelzl@40859
  1214
  proof (rule antisym)
hoelzl@40859
  1215
    show "(SUP j. positive_integral (f j)) \<le> positive_integral ?u"
hoelzl@40859
  1216
      by (auto intro!: SUP_leI positive_integral_mono le_SUPI)
hoelzl@40859
  1217
  next
hoelzl@40859
  1218
    def rf \<equiv> "\<lambda>i. \<lambda>x\<in>space M. f i x" and ru \<equiv> "\<lambda>x\<in>space M. ?u x"
hoelzl@40859
  1219
    have "\<And>i. rf i \<in> borel_measurable M" unfolding rf_def
hoelzl@40859
  1220
      using assms by (simp cong: measurable_cong)
hoelzl@40859
  1221
    moreover have iso: "rf \<up> ru" using assms unfolding rf_def ru_def
hoelzl@40859
  1222
      unfolding isoton_def SUPR_fun_expand le_fun_def fun_eq_iff
hoelzl@40872
  1223
      using SUP_const[OF UNIV_not_empty]
hoelzl@40859
  1224
      by (auto simp: restrict_def le_fun_def SUPR_fun_expand fun_eq_iff)
hoelzl@40859
  1225
    ultimately have "positive_integral ru \<le> (SUP i. positive_integral (rf i))"
hoelzl@40859
  1226
      unfolding positive_integral_def[of ru]
hoelzl@40859
  1227
      by (auto simp: le_fun_def intro!: SUP_leI positive_integral_SUP_approx)
hoelzl@40859
  1228
    then show "positive_integral ?u \<le> (SUP i. positive_integral (f i))"
hoelzl@40859
  1229
      unfolding ru_def rf_def by (simp cong: positive_integral_cong)
hoelzl@40859
  1230
  qed
hoelzl@40859
  1231
qed
hoelzl@40859
  1232
hoelzl@38656
  1233
lemma (in measure_space) SUP_simple_integral_sequences:
hoelzl@38656
  1234
  assumes f: "f \<up> u" "\<And>i. simple_function (f i)"
hoelzl@38656
  1235
  and g: "g \<up> u" "\<And>i. simple_function (g i)"
hoelzl@38656
  1236
  shows "(SUP i. simple_integral (f i)) = (SUP i. simple_integral (g i))"
hoelzl@38656
  1237
    (is "SUPR _ ?F = SUPR _ ?G")
hoelzl@38656
  1238
proof -
hoelzl@38656
  1239
  have "(SUP i. ?F i) = (SUP i. positive_integral (f i))"
hoelzl@38656
  1240
    using assms by (simp add: positive_integral_eq_simple_integral)
hoelzl@38656
  1241
  also have "\<dots> = positive_integral u"
hoelzl@38656
  1242
    using positive_integral_isoton[OF f(1) borel_measurable_simple_function[OF f(2)]]
hoelzl@38656
  1243
    unfolding isoton_def by simp
hoelzl@38656
  1244
  also have "\<dots> = (SUP i. positive_integral (g i))"
hoelzl@38656
  1245
    using positive_integral_isoton[OF g(1) borel_measurable_simple_function[OF g(2)]]
hoelzl@38656
  1246
    unfolding isoton_def by simp
hoelzl@38656
  1247
  also have "\<dots> = (SUP i. ?G i)"
hoelzl@38656
  1248
    using assms by (simp add: positive_integral_eq_simple_integral)
hoelzl@38656
  1249
  finally show ?thesis .
hoelzl@38656
  1250
qed
hoelzl@38656
  1251
hoelzl@38656
  1252
lemma (in measure_space) positive_integral_const[simp]:
hoelzl@38656
  1253
  "positive_integral (\<lambda>x. c) = c * \<mu> (space M)"
hoelzl@38656
  1254
  by (subst positive_integral_eq_simple_integral) auto
hoelzl@38656
  1255
hoelzl@38656
  1256
lemma (in measure_space) positive_integral_isoton_simple:
hoelzl@38656
  1257
  assumes "f \<up> u" and e: "\<And>i. simple_function (f i)"
hoelzl@38656
  1258
  shows "(\<lambda>i. simple_integral (f i)) \<up> positive_integral u"
hoelzl@38656
  1259
  using positive_integral_isoton[OF `f \<up> u` e(1)[THEN borel_measurable_simple_function]]
hoelzl@38656
  1260
  unfolding positive_integral_eq_simple_integral[OF e] .
hoelzl@38656
  1261
hoelzl@38656
  1262
lemma (in measure_space) positive_integral_linear:
hoelzl@38656
  1263
  assumes f: "f \<in> borel_measurable M"
hoelzl@38656
  1264
  and g: "g \<in> borel_measurable M"
hoelzl@38656
  1265
  shows "positive_integral (\<lambda>x. a * f x + g x) =
hoelzl@38656
  1266
      a * positive_integral f + positive_integral g"
hoelzl@38656
  1267
    (is "positive_integral ?L = _")
hoelzl@35582
  1268
proof -
hoelzl@38656
  1269
  from borel_measurable_implies_simple_function_sequence'[OF f] guess u .
hoelzl@38656
  1270
  note u = this positive_integral_isoton_simple[OF this(1-2)]
hoelzl@38656
  1271
  from borel_measurable_implies_simple_function_sequence'[OF g] guess v .
hoelzl@38656
  1272
  note v = this positive_integral_isoton_simple[OF this(1-2)]
hoelzl@38656
  1273
  let "?L' i x" = "a * u i x + v i x"
hoelzl@38656
  1274
hoelzl@38656
  1275
  have "?L \<in> borel_measurable M"
hoelzl@38656
  1276
    using assms by simp
hoelzl@38656
  1277
  from borel_measurable_implies_simple_function_sequence'[OF this] guess l .
hoelzl@38656
  1278
  note positive_integral_isoton_simple[OF this(1-2)] and l = this
hoelzl@38656
  1279
  moreover have
hoelzl@38656
  1280
      "(SUP i. simple_integral (l i)) = (SUP i. simple_integral (?L' i))"
hoelzl@38656
  1281
  proof (rule SUP_simple_integral_sequences[OF l(1-2)])
hoelzl@38656
  1282
    show "?L' \<up> ?L" "\<And>i. simple_function (?L' i)"
hoelzl@38656
  1283
      using u v by (auto simp: isoton_fun_expand isoton_add isoton_cmult_right)
hoelzl@38656
  1284
  qed
hoelzl@38656
  1285
  moreover from u v have L'_isoton:
hoelzl@38656
  1286
      "(\<lambda>i. simple_integral (?L' i)) \<up> a * positive_integral f + positive_integral g"
hoelzl@38656
  1287
    by (simp add: isoton_add isoton_cmult_right)
hoelzl@38656
  1288
  ultimately show ?thesis by (simp add: isoton_def)
hoelzl@38656
  1289
qed
hoelzl@38656
  1290
hoelzl@38656
  1291
lemma (in measure_space) positive_integral_cmult:
hoelzl@38656
  1292
  assumes "f \<in> borel_measurable M"
hoelzl@38656
  1293
  shows "positive_integral (\<lambda>x. c * f x) = c * positive_integral f"
hoelzl@38656
  1294
  using positive_integral_linear[OF assms, of "\<lambda>x. 0" c] by auto
hoelzl@38656
  1295
hoelzl@38656
  1296
lemma (in measure_space) positive_integral_indicator[simp]:
hoelzl@38656
  1297
  "A \<in> sets M \<Longrightarrow> positive_integral (\<lambda>x. indicator A x) = \<mu> A"
hoelzl@38656
  1298
by (subst positive_integral_eq_simple_integral) (auto simp: simple_function_indicator simple_integral_indicator)
hoelzl@38656
  1299
hoelzl@38656
  1300
lemma (in measure_space) positive_integral_cmult_indicator:
hoelzl@38656
  1301
  "A \<in> sets M \<Longrightarrow> positive_integral (\<lambda>x. c * indicator A x) = c * \<mu> A"
hoelzl@38656
  1302
by (subst positive_integral_eq_simple_integral) (auto simp: simple_function_indicator simple_integral_indicator)
hoelzl@38656
  1303
hoelzl@38656
  1304
lemma (in measure_space) positive_integral_add:
hoelzl@38656
  1305
  assumes "f \<in> borel_measurable M" "g \<in> borel_measurable M"
hoelzl@38656
  1306
  shows "positive_integral (\<lambda>x. f x + g x) = positive_integral f + positive_integral g"
hoelzl@38656
  1307
  using positive_integral_linear[OF assms, of 1] by simp
hoelzl@38656
  1308
hoelzl@38656
  1309
lemma (in measure_space) positive_integral_setsum:
hoelzl@38656
  1310
  assumes "\<And>i. i\<in>P \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@38656
  1311
  shows "positive_integral (\<lambda>x. \<Sum>i\<in>P. f i x) = (\<Sum>i\<in>P. positive_integral (f i))"
hoelzl@38656
  1312
proof cases
hoelzl@38656
  1313
  assume "finite P"
hoelzl@38656
  1314
  from this assms show ?thesis
hoelzl@38656
  1315
  proof induct
hoelzl@38656
  1316
    case (insert i P)
hoelzl@38656
  1317
    have "f i \<in> borel_measurable M"
hoelzl@38656
  1318
      "(\<lambda>x. \<Sum>i\<in>P. f i x) \<in> borel_measurable M"
hoelzl@38656
  1319
      using insert by (auto intro!: borel_measurable_pinfreal_setsum)
hoelzl@38656
  1320
    from positive_integral_add[OF this]
hoelzl@38656
  1321
    show ?case using insert by auto
hoelzl@38656
  1322
  qed simp
hoelzl@38656
  1323
qed simp
hoelzl@38656
  1324
hoelzl@38656
  1325
lemma (in measure_space) positive_integral_diff:
hoelzl@38656
  1326
  assumes f: "f \<in> borel_measurable M" and g: "g \<in> borel_measurable M"
hoelzl@38656
  1327
  and fin: "positive_integral g \<noteq> \<omega>"
hoelzl@38656
  1328
  and mono: "\<And>x. x \<in> space M \<Longrightarrow> g x \<le> f x"
hoelzl@38656
  1329
  shows "positive_integral (\<lambda>x. f x - g x) = positive_integral f - positive_integral g"
hoelzl@38656
  1330
proof -
hoelzl@38656
  1331
  have borel: "(\<lambda>x. f x - g x) \<in> borel_measurable M"
hoelzl@38656
  1332
    using f g by (rule borel_measurable_pinfreal_diff)
hoelzl@38656
  1333
  have "positive_integral (\<lambda>x. f x - g x) + positive_integral g =
hoelzl@38656
  1334
    positive_integral f"
hoelzl@38656
  1335
    unfolding positive_integral_add[OF borel g, symmetric]
hoelzl@38656
  1336
  proof (rule positive_integral_cong)
hoelzl@38656
  1337
    fix x assume "x \<in> space M"
hoelzl@38656
  1338
    from mono[OF this] show "f x - g x + g x = f x"
hoelzl@38656
  1339
      by (cases "f x", cases "g x", simp, simp, cases "g x", auto)
hoelzl@38656
  1340
  qed
hoelzl@38656
  1341
  with mono show ?thesis
hoelzl@38656
  1342
    by (subst minus_pinfreal_eq2[OF _ fin]) (auto intro!: positive_integral_mono)
hoelzl@38656
  1343
qed
hoelzl@38656
  1344
hoelzl@38656
  1345
lemma (in measure_space) positive_integral_psuminf:
hoelzl@38656
  1346
  assumes "\<And>i. f i \<in> borel_measurable M"
hoelzl@38656
  1347
  shows "positive_integral (\<lambda>x. \<Sum>\<^isub>\<infinity> i. f i x) = (\<Sum>\<^isub>\<infinity> i. positive_integral (f i))"
hoelzl@38656
  1348
proof -
hoelzl@38656
  1349
  have "(\<lambda>i. positive_integral (\<lambda>x. \<Sum>i<i. f i x)) \<up> positive_integral (\<lambda>x. \<Sum>\<^isub>\<infinity>i. f i x)"
hoelzl@38656
  1350
    by (rule positive_integral_isoton)
hoelzl@38656
  1351
       (auto intro!: borel_measurable_pinfreal_setsum assms positive_integral_mono
hoelzl@38656
  1352
                     arg_cong[where f=Sup]
nipkow@39302
  1353
             simp: isoton_def le_fun_def psuminf_def fun_eq_iff SUPR_def Sup_fun_def)
hoelzl@38656
  1354
  thus ?thesis
hoelzl@38656
  1355
    by (auto simp: isoton_def psuminf_def positive_integral_setsum[OF assms])
hoelzl@38656
  1356
qed
hoelzl@38656
  1357
hoelzl@38656
  1358
text {* Fatou's lemma: convergence theorem on limes inferior *}
hoelzl@38656
  1359
lemma (in measure_space) positive_integral_lim_INF:
hoelzl@38656
  1360
  fixes u :: "nat \<Rightarrow> 'a \<Rightarrow> pinfreal"
hoelzl@38656
  1361
  assumes "\<And>i. u i \<in> borel_measurable M"
hoelzl@38656
  1362
  shows "positive_integral (SUP n. INF m. u (m + n)) \<le>
hoelzl@38656
  1363
    (SUP n. INF m. positive_integral (u (m + n)))"
hoelzl@38656
  1364
proof -
hoelzl@38656
  1365
  have "(SUP n. INF m. u (m + n)) \<in> borel_measurable M"
hoelzl@38656
  1366
    by (auto intro!: borel_measurable_SUP borel_measurable_INF assms)
hoelzl@38656
  1367
hoelzl@38656
  1368
  have "(\<lambda>n. INF m. u (m + n)) \<up> (SUP n. INF m. u (m + n))"
hoelzl@38705
  1369
  proof (unfold isoton_def, safe intro!: INF_mono bexI)
hoelzl@38705
  1370
    fix i m show "u (Suc m + i) \<le> u (m + Suc i)" by simp
hoelzl@38705
  1371
  qed simp
hoelzl@38656
  1372
  from positive_integral_isoton[OF this] assms
hoelzl@38656
  1373
  have "positive_integral (SUP n. INF m. u (m + n)) =
hoelzl@38656
  1374
    (SUP n. positive_integral (INF m. u (m + n)))"
hoelzl@38656
  1375
    unfolding isoton_def by (simp add: borel_measurable_INF)
hoelzl@38656
  1376
  also have "\<dots> \<le> (SUP n. INF m. positive_integral (u (m + n)))"
hoelzl@38705
  1377
    apply (rule SUP_mono)
hoelzl@38705
  1378
    apply (rule_tac x=n in bexI)
hoelzl@38705
  1379
    by (auto intro!: positive_integral_mono INFI_bound INF_leI exI simp: INFI_fun_expand)
hoelzl@38656
  1380
  finally show ?thesis .
hoelzl@35582
  1381
qed
hoelzl@35582
  1382
hoelzl@38656
  1383
lemma (in measure_space) measure_space_density:
hoelzl@38656
  1384
  assumes borel: "u \<in> borel_measurable M"
hoelzl@38656
  1385
  shows "measure_space M (\<lambda>A. positive_integral (\<lambda>x. u x * indicator A x))" (is "measure_space M ?v")
hoelzl@38656
  1386
proof
hoelzl@38656
  1387
  show "?v {} = 0" by simp
hoelzl@38656
  1388
  show "countably_additive M ?v"
hoelzl@38656
  1389
    unfolding countably_additive_def
hoelzl@38656
  1390
  proof safe
hoelzl@38656
  1391
    fix A :: "nat \<Rightarrow> 'a set"
hoelzl@38656
  1392
    assume "range A \<subseteq> sets M"
hoelzl@38656
  1393
    hence "\<And>i. (\<lambda>x. u x * indicator (A i) x) \<in> borel_measurable M"
hoelzl@38656
  1394
      using borel by (auto intro: borel_measurable_indicator)
hoelzl@38656
  1395
    moreover assume "disjoint_family A"
hoelzl@38656
  1396
    note psuminf_indicator[OF this]
hoelzl@38656
  1397
    ultimately show "(\<Sum>\<^isub>\<infinity>n. ?v (A n)) = ?v (\<Union>x. A x)"
hoelzl@38656
  1398
      by (simp add: positive_integral_psuminf[symmetric])
hoelzl@38656
  1399
  qed
hoelzl@38656
  1400
qed
hoelzl@35582
  1401
hoelzl@39092
  1402
lemma (in measure_space) positive_integral_translated_density:
hoelzl@39092
  1403
  assumes "f \<in> borel_measurable M" "g \<in> borel_measurable M"
hoelzl@39092
  1404
  shows "measure_space.positive_integral M (\<lambda>A. positive_integral (\<lambda>x. f x * indicator A x)) g =
hoelzl@39092
  1405
    positive_integral (\<lambda>x. f x * g x)" (is "measure_space.positive_integral M ?T _ = _")
hoelzl@39092
  1406
proof -
hoelzl@39092
  1407
  from measure_space_density[OF assms(1)]
hoelzl@39092
  1408
  interpret T: measure_space M ?T .
hoelzl@39092
  1409
  from borel_measurable_implies_simple_function_sequence[OF assms(2)]
hoelzl@39092
  1410
  obtain G where G: "\<And>i. simple_function (G i)" "G \<up> g" by blast
hoelzl@39092
  1411
  note G_borel = borel_measurable_simple_function[OF this(1)]
hoelzl@39092
  1412
  from T.positive_integral_isoton[OF `G \<up> g` G_borel]
hoelzl@39092
  1413
  have *: "(\<lambda>i. T.positive_integral (G i)) \<up> T.positive_integral g" .
hoelzl@39092
  1414
  { fix i
hoelzl@39092
  1415
    have [simp]: "finite (G i ` space M)"
hoelzl@39092
  1416
      using G(1) unfolding simple_function_def by auto
hoelzl@39092
  1417
    have "T.positive_integral (G i) = T.simple_integral (G i)"
hoelzl@39092
  1418
      using G T.positive_integral_eq_simple_integral by simp
hoelzl@39092
  1419
    also have "\<dots> = positive_integral (\<lambda>x. f x * (\<Sum>y\<in>G i`space M. y * indicator (G i -` {y} \<inter> space M) x))"
hoelzl@39092
  1420
      apply (simp add: T.simple_integral_def)
hoelzl@39092
  1421
      apply (subst positive_integral_cmult[symmetric])
hoelzl@39092
  1422
      using G_borel assms(1) apply (fastsimp intro: borel_measurable_indicator borel_measurable_vimage)
hoelzl@39092
  1423
      apply (subst positive_integral_setsum[symmetric])
hoelzl@39092
  1424
      using G_borel assms(1) apply (fastsimp intro: borel_measurable_indicator borel_measurable_vimage)
hoelzl@39092
  1425
      by (simp add: setsum_right_distrib field_simps)
hoelzl@39092
  1426
    also have "\<dots> = positive_integral (\<lambda>x. f x * G i x)"
hoelzl@39092
  1427
      by (auto intro!: positive_integral_cong
hoelzl@39092
  1428
               simp: indicator_def if_distrib setsum_cases)
hoelzl@39092
  1429
    finally have "T.positive_integral (G i) = positive_integral (\<lambda>x. f x * G i x)" . }
hoelzl@39092
  1430
  with * have eq_Tg: "(\<lambda>i. positive_integral (\<lambda>x. f x * G i x)) \<up> T.positive_integral g" by simp
hoelzl@39092
  1431
  from G(2) have "(\<lambda>i x. f x * G i x) \<up> (\<lambda>x. f x * g x)"
hoelzl@39092
  1432
    unfolding isoton_fun_expand by (auto intro!: isoton_cmult_right)
hoelzl@39092
  1433
  then have "(\<lambda>i. positive_integral (\<lambda>x. f x * G i x)) \<up> positive_integral (\<lambda>x. f x * g x)"
hoelzl@39092
  1434
    using assms(1) G_borel by (auto intro!: positive_integral_isoton borel_measurable_pinfreal_times)
hoelzl@39092
  1435
  with eq_Tg show "T.positive_integral g = positive_integral (\<lambda>x. f x * g x)"
hoelzl@39092
  1436
    unfolding isoton_def by simp
hoelzl@39092
  1437
qed
hoelzl@39092
  1438
hoelzl@38656
  1439
lemma (in measure_space) positive_integral_null_set:
hoelzl@40859
  1440
  assumes "N \<in> null_sets" shows "positive_integral (\<lambda>x. u x * indicator N x) = 0"
hoelzl@38656
  1441
proof -
hoelzl@40859
  1442
  have "positive_integral (\<lambda>x. u x * indicator N x) = positive_integral (\<lambda>x. 0)"
hoelzl@40859
  1443
  proof (intro positive_integral_cong_AE AE_I)
hoelzl@40859
  1444
    show "{x \<in> space M. u x * indicator N x \<noteq> 0} \<subseteq> N"
hoelzl@40859
  1445
      by (auto simp: indicator_def)
hoelzl@40859
  1446
    show "\<mu> N = 0" "N \<in> sets M"
hoelzl@40859
  1447
      using assms by auto
hoelzl@35582
  1448
  qed
hoelzl@40859
  1449
  then show ?thesis by simp
hoelzl@38656
  1450
qed
hoelzl@35582
  1451
hoelzl@38656
  1452
lemma (in measure_space) positive_integral_Markov_inequality:
hoelzl@38656
  1453
  assumes borel: "u \<in> borel_measurable M" and "A \<in> sets M" and c: "c \<noteq> \<omega>"
hoelzl@38656
  1454
  shows "\<mu> ({x\<in>space M. 1 \<le> c * u x} \<inter> A) \<le> c * positive_integral (\<lambda>x. u x * indicator A x)"
hoelzl@38656
  1455
    (is "\<mu> ?A \<le> _ * ?PI")
hoelzl@38656
  1456
proof -
hoelzl@38656
  1457
  have "?A \<in> sets M"
hoelzl@38656
  1458
    using `A \<in> sets M` borel by auto
hoelzl@38656
  1459
  hence "\<mu> ?A = positive_integral (\<lambda>x. indicator ?A x)"
hoelzl@38656
  1460
    using positive_integral_indicator by simp
hoelzl@38656
  1461
  also have "\<dots> \<le> positive_integral (\<lambda>x. c * (u x * indicator A x))"
hoelzl@38656
  1462
  proof (rule positive_integral_mono)
hoelzl@38656
  1463
    fix x assume "x \<in> space M"
hoelzl@38656
  1464
    show "indicator ?A x \<le> c * (u x * indicator A x)"
hoelzl@38656
  1465
      by (cases "x \<in> ?A") auto
hoelzl@38656
  1466
  qed
hoelzl@38656
  1467
  also have "\<dots> = c * positive_integral (\<lambda>x. u x * indicator A x)"
hoelzl@38656
  1468
    using assms
hoelzl@38656
  1469
    by (auto intro!: positive_integral_cmult borel_measurable_indicator)
hoelzl@38656
  1470
  finally show ?thesis .
hoelzl@35582
  1471
qed
hoelzl@35582
  1472
hoelzl@38656
  1473
lemma (in measure_space) positive_integral_0_iff:
hoelzl@38656
  1474
  assumes borel: "u \<in> borel_measurable M"
hoelzl@38656
  1475
  shows "positive_integral u = 0 \<longleftrightarrow> \<mu> {x\<in>space M. u x \<noteq> 0} = 0"
hoelzl@38656
  1476
    (is "_ \<longleftrightarrow> \<mu> ?A = 0")
hoelzl@35582
  1477
proof -
hoelzl@38656
  1478
  have A: "?A \<in> sets M" using borel by auto
hoelzl@38656
  1479
  have u: "positive_integral (\<lambda>x. u x * indicator ?A x) = positive_integral u"
hoelzl@38656
  1480
    by (auto intro!: positive_integral_cong simp: indicator_def)
hoelzl@35582
  1481
hoelzl@38656
  1482
  show ?thesis
hoelzl@38656
  1483
  proof
hoelzl@38656
  1484
    assume "\<mu> ?A = 0"
hoelzl@38656
  1485
    hence "?A \<in> null_sets" using `?A \<in> sets M` by auto
hoelzl@40859
  1486
    from positive_integral_null_set[OF this]
hoelzl@38656
  1487
    have "0 = positive_integral (\<lambda>x. u x * indicator ?A x)" by simp
hoelzl@38656
  1488
    thus "positive_integral u = 0" unfolding u by simp
hoelzl@38656
  1489
  next
hoelzl@38656
  1490
    assume *: "positive_integral u = 0"
hoelzl@38656
  1491
    let "?M n" = "{x \<in> space M. 1 \<le> of_nat n * u x}"
hoelzl@38656
  1492
    have "0 = (SUP n. \<mu> (?M n \<inter> ?A))"
hoelzl@38656
  1493
    proof -
hoelzl@38656
  1494
      { fix n
hoelzl@38656
  1495
        from positive_integral_Markov_inequality[OF borel `?A \<in> sets M`, of "of_nat n"]
hoelzl@38656
  1496
        have "\<mu> (?M n \<inter> ?A) = 0" unfolding * u by simp }
hoelzl@38656
  1497
      thus ?thesis by simp
hoelzl@35582
  1498
    qed
hoelzl@38656
  1499
    also have "\<dots> = \<mu> (\<Union>n. ?M n \<inter> ?A)"
hoelzl@38656
  1500
    proof (safe intro!: continuity_from_below)
hoelzl@38656
  1501
      fix n show "?M n \<inter> ?A \<in> sets M"
hoelzl@38656
  1502
        using borel by (auto intro!: Int)
hoelzl@38656
  1503
    next
hoelzl@38656
  1504
      fix n x assume "1 \<le> of_nat n * u x"
hoelzl@38656
  1505
      also have "\<dots> \<le> of_nat (Suc n) * u x"
hoelzl@38656
  1506
        by (subst (1 2) mult_commute) (auto intro!: pinfreal_mult_cancel)
hoelzl@38656