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