src/HOL/Analysis/Nonnegative_Lebesgue_Integration.thy
author nipkow
Sat Dec 29 15:43:53 2018 +0100 (6 months ago)
changeset 69529 4ab9657b3257
parent 69457 bea49e443909
child 69546 27dae626822b
permissions -rw-r--r--
capitalize proper names in lemma names
hoelzl@63627
     1
(*  Title:      HOL/Analysis/Nonnegative_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
wenzelm@61808
     6
section \<open>Lebesgue Integration for Nonnegative Functions\<close>
hoelzl@35582
     7
hoelzl@56993
     8
theory Nonnegative_Lebesgue_Integration
hoelzl@47694
     9
  imports Measure_Space Borel_Space
hoelzl@35582
    10
begin
hoelzl@35582
    11
eberlm@69457
    12
subsection%unimportant \<open>Approximating functions\<close>
hoelzl@64283
    13
hoelzl@64283
    14
lemma AE_upper_bound_inf_ennreal:
hoelzl@64283
    15
  fixes F G::"'a \<Rightarrow> ennreal"
hoelzl@64283
    16
  assumes "\<And>e. (e::real) > 0 \<Longrightarrow> AE x in M. F x \<le> G x + e"
hoelzl@64283
    17
  shows "AE x in M. F x \<le> G x"
hoelzl@64283
    18
proof -
hoelzl@64283
    19
  have "AE x in M. \<forall>n::nat. F x \<le> G x + ennreal (1 / Suc n)"
hoelzl@64283
    20
    using assms by (auto simp: AE_all_countable)
hoelzl@64283
    21
  then show ?thesis
hoelzl@64283
    22
  proof (eventually_elim)
hoelzl@64283
    23
    fix x assume x: "\<forall>n::nat. F x \<le> G x + ennreal (1 / Suc n)"
hoelzl@64283
    24
    show "F x \<le> G x"
hoelzl@64283
    25
    proof (rule ennreal_le_epsilon)
hoelzl@64283
    26
      fix e :: real assume "0 < e"
hoelzl@64283
    27
      then obtain n where n: "1 / Suc n < e"
hoelzl@64283
    28
        by (blast elim: nat_approx_posE)
hoelzl@64283
    29
      have "F x \<le> G x + 1 / Suc n"
hoelzl@64283
    30
        using x by simp
hoelzl@64283
    31
      also have "\<dots> \<le> G x + e"
hoelzl@64283
    32
        using n by (intro add_mono ennreal_leI) auto
hoelzl@64283
    33
      finally show "F x \<le> G x + ennreal e" .
hoelzl@64283
    34
    qed
hoelzl@64283
    35
  qed
hoelzl@64283
    36
qed
hoelzl@64283
    37
hoelzl@64283
    38
lemma AE_upper_bound_inf:
hoelzl@64283
    39
  fixes F G::"'a \<Rightarrow> real"
hoelzl@64283
    40
  assumes "\<And>e. e > 0 \<Longrightarrow> AE x in M. F x \<le> G x + e"
hoelzl@64283
    41
  shows "AE x in M. F x \<le> G x"
hoelzl@64283
    42
proof -
hoelzl@64283
    43
  have "AE x in M. F x \<le> G x + 1/real (n+1)" for n::nat
hoelzl@64283
    44
    by (rule assms, auto)
hoelzl@64283
    45
  then have "AE x in M. \<forall>n::nat \<in> UNIV. F x \<le> G x + 1/real (n+1)"
hoelzl@64283
    46
    by (rule AE_ball_countable', auto)
hoelzl@64283
    47
  moreover
hoelzl@64283
    48
  {
hoelzl@64283
    49
    fix x assume i: "\<forall>n::nat \<in> UNIV. F x \<le> G x + 1/real (n+1)"
hoelzl@64283
    50
    have "(\<lambda>n. G x + 1/real (n+1)) \<longlonglongrightarrow> G x + 0"
hoelzl@64283
    51
      by (rule tendsto_add, simp, rule LIMSEQ_ignore_initial_segment[OF lim_1_over_n, of 1])
hoelzl@64283
    52
    then have "F x \<le> G x" using i LIMSEQ_le_const by fastforce
hoelzl@64283
    53
  }
hoelzl@64283
    54
  ultimately show ?thesis by auto
hoelzl@64283
    55
qed
hoelzl@64283
    56
hoelzl@64283
    57
lemma not_AE_zero_ennreal_E:
hoelzl@64283
    58
  fixes f::"'a \<Rightarrow> ennreal"
hoelzl@64283
    59
  assumes "\<not> (AE x in M. f x = 0)" and [measurable]: "f \<in> borel_measurable M"
hoelzl@64283
    60
  shows "\<exists>A\<in>sets M. \<exists>e::real>0. emeasure M A > 0 \<and> (\<forall>x \<in> A. f x \<ge> e)"
hoelzl@64283
    61
proof -
hoelzl@64283
    62
  { assume "\<not> (\<exists>e::real>0. {x \<in> space M. f x \<ge> e} \<notin> null_sets M)"
hoelzl@64283
    63
    then have "0 < e \<Longrightarrow> AE x in M. f x \<le> e" for e :: real
hoelzl@64283
    64
      by (auto simp: not_le less_imp_le dest!: AE_not_in)
hoelzl@64283
    65
    then have "AE x in M. f x \<le> 0"
hoelzl@64283
    66
      by (intro AE_upper_bound_inf_ennreal[where G="\<lambda>_. 0"]) simp
hoelzl@64283
    67
    then have False
hoelzl@64283
    68
      using assms by auto }
hoelzl@64283
    69
  then obtain e::real where e: "e > 0" "{x \<in> space M. f x \<ge> e} \<notin> null_sets M" by auto
hoelzl@64283
    70
  define A where "A = {x \<in> space M. f x \<ge> e}"
hoelzl@64283
    71
  have 1 [measurable]: "A \<in> sets M" unfolding A_def by auto
hoelzl@64283
    72
  have 2: "emeasure M A > 0"
hoelzl@64283
    73
    using e(2) A_def \<open>A \<in> sets M\<close> by auto
hoelzl@64283
    74
  have 3: "\<And>x. x \<in> A \<Longrightarrow> f x \<ge> e" unfolding A_def by auto
hoelzl@64283
    75
  show ?thesis using e(1) 1 2 3 by blast
hoelzl@64283
    76
qed
hoelzl@64283
    77
hoelzl@64283
    78
lemma not_AE_zero_E:
hoelzl@64283
    79
  fixes f::"'a \<Rightarrow> real"
hoelzl@64283
    80
  assumes "AE x in M. f x \<ge> 0"
hoelzl@64283
    81
          "\<not>(AE x in M. f x = 0)"
hoelzl@64283
    82
      and [measurable]: "f \<in> borel_measurable M"
hoelzl@64283
    83
  shows "\<exists>A e. A \<in> sets M \<and> e>0 \<and> emeasure M A > 0 \<and> (\<forall>x \<in> A. f x \<ge> e)"
hoelzl@64283
    84
proof -
hoelzl@64283
    85
  have "\<exists>e. e > 0 \<and> {x \<in> space M. f x \<ge> e} \<notin> null_sets M"
hoelzl@64283
    86
  proof (rule ccontr)
hoelzl@64283
    87
    assume *: "\<not>(\<exists>e. e > 0 \<and> {x \<in> space M. f x \<ge> e} \<notin> null_sets M)"
hoelzl@64283
    88
    {
hoelzl@64283
    89
      fix e::real assume "e > 0"
hoelzl@64283
    90
      then have "{x \<in> space M. f x \<ge> e} \<in> null_sets M" using * by blast
hoelzl@64283
    91
      then have "AE x in M. x \<notin> {x \<in> space M. f x \<ge> e}" using AE_not_in by blast
hoelzl@64283
    92
      then have "AE x in M. f x \<le> e" by auto
hoelzl@64283
    93
    }
hoelzl@64283
    94
    then have "AE x in M. f x \<le> 0" by (rule AE_upper_bound_inf, auto)
hoelzl@64283
    95
    then have "AE x in M. f x = 0" using assms(1) by auto
hoelzl@64283
    96
    then show False using assms(2) by auto
hoelzl@64283
    97
  qed
hoelzl@64283
    98
  then obtain e where e: "e>0" "{x \<in> space M. f x \<ge> e} \<notin> null_sets M" by auto
hoelzl@64283
    99
  define A where "A = {x \<in> space M. f x \<ge> e}"
hoelzl@64283
   100
  have 1 [measurable]: "A \<in> sets M" unfolding A_def by auto
hoelzl@64283
   101
  have 2: "emeasure M A > 0"
hoelzl@64283
   102
    using e(2) A_def \<open>A \<in> sets M\<close> by auto
hoelzl@64283
   103
  have 3: "\<And>x. x \<in> A \<Longrightarrow> f x \<ge> e" unfolding A_def by auto
hoelzl@64283
   104
  show ?thesis
hoelzl@64283
   105
    using e(1) 1 2 3 by blast
hoelzl@64283
   106
qed
hoelzl@64283
   107
hoelzl@56994
   108
subsection "Simple function"
hoelzl@35582
   109
wenzelm@61808
   110
text \<open>
hoelzl@38656
   111
hoelzl@56996
   112
Our simple functions are not restricted to nonnegative real numbers. Instead
hoelzl@38656
   113
they are just functions with a finite range and are measurable when singleton
hoelzl@38656
   114
sets are measurable.
hoelzl@35582
   115
wenzelm@61808
   116
\<close>
hoelzl@38656
   117
eberlm@69457
   118
definition%important "simple_function M g \<longleftrightarrow>
hoelzl@38656
   119
    finite (g ` space M) \<and>
hoelzl@38656
   120
    (\<forall>x \<in> g ` space M. g -` {x} \<inter> space M \<in> sets M)"
hoelzl@36624
   121
hoelzl@47694
   122
lemma simple_functionD:
hoelzl@41689
   123
  assumes "simple_function M g"
hoelzl@40875
   124
  shows "finite (g ` space M)" and "g -` X \<inter> space M \<in> sets M"
hoelzl@40871
   125
proof -
hoelzl@40871
   126
  show "finite (g ` space M)"
hoelzl@40871
   127
    using assms unfolding simple_function_def by auto
hoelzl@40875
   128
  have "g -` X \<inter> space M = g -` (X \<inter> g`space M) \<inter> space M" by auto
hoelzl@40875
   129
  also have "\<dots> = (\<Union>x\<in>X \<inter> g`space M. g-`{x} \<inter> space M)" by auto
hoelzl@40875
   130
  finally show "g -` X \<inter> space M \<in> sets M" using assms
hoelzl@50002
   131
    by (auto simp del: UN_simps simp: simple_function_def)
hoelzl@40871
   132
qed
hoelzl@36624
   133
hoelzl@56949
   134
lemma measurable_simple_function[measurable_dest]:
hoelzl@56949
   135
  "simple_function M f \<Longrightarrow> f \<in> measurable M (count_space UNIV)"
hoelzl@56949
   136
  unfolding simple_function_def measurable_def
hoelzl@56949
   137
proof safe
hoelzl@56949
   138
  fix A assume "finite (f ` space M)" "\<forall>x\<in>f ` space M. f -` {x} \<inter> space M \<in> sets M"
hoelzl@56949
   139
  then have "(\<Union>x\<in>f ` space M. if x \<in> A then f -` {x} \<inter> space M else {}) \<in> sets M"
hoelzl@56949
   140
    by (intro sets.finite_UN) auto
hoelzl@56949
   141
  also have "(\<Union>x\<in>f ` space M. if x \<in> A then f -` {x} \<inter> space M else {}) = f -` A \<inter> space M"
nipkow@62390
   142
    by (auto split: if_split_asm)
hoelzl@56949
   143
  finally show "f -` A \<inter> space M \<in> sets M" .
hoelzl@56949
   144
qed simp
hoelzl@56949
   145
hoelzl@56949
   146
lemma borel_measurable_simple_function:
hoelzl@56949
   147
  "simple_function M f \<Longrightarrow> f \<in> borel_measurable M"
hoelzl@56949
   148
  by (auto dest!: measurable_simple_function simp: measurable_def)
hoelzl@56949
   149
hoelzl@47694
   150
lemma simple_function_measurable2[intro]:
hoelzl@41981
   151
  assumes "simple_function M f" "simple_function M g"
hoelzl@41981
   152
  shows "f -` A \<inter> g -` B \<inter> space M \<in> sets M"
hoelzl@41981
   153
proof -
hoelzl@41981
   154
  have "f -` A \<inter> g -` B \<inter> space M = (f -` A \<inter> space M) \<inter> (g -` B \<inter> space M)"
hoelzl@41981
   155
    by auto
hoelzl@41981
   156
  then show ?thesis using assms[THEN simple_functionD(2)] by auto
hoelzl@41981
   157
qed
hoelzl@41981
   158
hoelzl@47694
   159
lemma simple_function_indicator_representation:
hoelzl@62975
   160
  fixes f ::"'a \<Rightarrow> ennreal"
hoelzl@41689
   161
  assumes f: "simple_function M f" and x: "x \<in> space M"
hoelzl@38656
   162
  shows "f x = (\<Sum>y \<in> f ` space M. y * indicator (f -` {y} \<inter> space M) x)"
hoelzl@38656
   163
  (is "?l = ?r")
hoelzl@38656
   164
proof -
hoelzl@38705
   165
  have "?r = (\<Sum>y \<in> f ` space M.
hoelzl@38656
   166
    (if y = f x then y * indicator (f -` {y} \<inter> space M) x else 0))"
nipkow@64267
   167
    by (auto intro!: sum.cong)
hoelzl@38656
   168
  also have "... =  f x *  indicator (f -` {f x} \<inter> space M) x"
nipkow@64267
   169
    using assms by (auto dest: simple_functionD simp: sum.delta)
hoelzl@38656
   170
  also have "... = f x" using x by (auto simp: indicator_def)
hoelzl@38656
   171
  finally show ?thesis by auto
hoelzl@38656
   172
qed
hoelzl@36624
   173
hoelzl@47694
   174
lemma simple_function_notspace:
hoelzl@62975
   175
  "simple_function M (\<lambda>x. h x * indicator (- space M) x::ennreal)" (is "simple_function M ?h")
hoelzl@35692
   176
proof -
hoelzl@38656
   177
  have "?h ` space M \<subseteq> {0}" unfolding indicator_def by auto
hoelzl@38656
   178
  hence [simp, intro]: "finite (?h ` space M)" by (auto intro: finite_subset)
hoelzl@38656
   179
  have "?h -` {0} \<inter> space M = space M" by auto
hoelzl@38656
   180
  thus ?thesis unfolding simple_function_def by auto
hoelzl@38656
   181
qed
hoelzl@38656
   182
hoelzl@47694
   183
lemma simple_function_cong:
hoelzl@38656
   184
  assumes "\<And>t. t \<in> space M \<Longrightarrow> f t = g t"
hoelzl@41689
   185
  shows "simple_function M f \<longleftrightarrow> simple_function M g"
hoelzl@38656
   186
proof -
hoelzl@62975
   187
  have "\<And>x. f -` {x} \<inter> space M = g -` {x} \<inter> space M"
hoelzl@62975
   188
    using assms by auto
hoelzl@62975
   189
  with assms show ?thesis
hoelzl@62975
   190
    by (simp add: simple_function_def cong: image_cong)
hoelzl@38656
   191
qed
hoelzl@38656
   192
hoelzl@47694
   193
lemma simple_function_cong_algebra:
hoelzl@41689
   194
  assumes "sets N = sets M" "space N = space M"
hoelzl@41689
   195
  shows "simple_function M f \<longleftrightarrow> simple_function N f"
hoelzl@41689
   196
  unfolding simple_function_def assms ..
hoelzl@41689
   197
hoelzl@47694
   198
lemma simple_function_borel_measurable:
hoelzl@41981
   199
  fixes f :: "'a \<Rightarrow> 'x::{t2_space}"
hoelzl@38656
   200
  assumes "f \<in> borel_measurable M" and "finite (f ` space M)"
hoelzl@41689
   201
  shows "simple_function M f"
hoelzl@38656
   202
  using assms unfolding simple_function_def
hoelzl@38656
   203
  by (auto intro: borel_measurable_vimage)
hoelzl@38656
   204
hoelzl@62975
   205
lemma simple_function_iff_borel_measurable:
hoelzl@62975
   206
  fixes f :: "'a \<Rightarrow> 'x::{t2_space}"
hoelzl@62975
   207
  shows "simple_function M f \<longleftrightarrow> finite (f ` space M) \<and> f \<in> borel_measurable M"
hoelzl@62975
   208
  by (metis borel_measurable_simple_function simple_functionD(1) simple_function_borel_measurable)
hoelzl@62975
   209
hoelzl@56949
   210
lemma simple_function_eq_measurable:
hoelzl@62975
   211
  "simple_function M f \<longleftrightarrow> finite (f`space M) \<and> f \<in> measurable M (count_space UNIV)"
hoelzl@62975
   212
  using measurable_simple_function[of M f] by (fastforce simp: simple_function_def)
hoelzl@41981
   213
hoelzl@47694
   214
lemma simple_function_const[intro, simp]:
hoelzl@41689
   215
  "simple_function M (\<lambda>x. c)"
hoelzl@38656
   216
  by (auto intro: finite_subset simp: simple_function_def)
hoelzl@47694
   217
lemma simple_function_compose[intro, simp]:
hoelzl@41689
   218
  assumes "simple_function M f"
hoelzl@41689
   219
  shows "simple_function M (g \<circ> f)"
hoelzl@38656
   220
  unfolding simple_function_def
hoelzl@38656
   221
proof safe
hoelzl@38656
   222
  show "finite ((g \<circ> f) ` space M)"
haftmann@56154
   223
    using assms unfolding simple_function_def by (auto simp: image_comp [symmetric])
hoelzl@38656
   224
next
hoelzl@38656
   225
  fix x assume "x \<in> space M"
hoelzl@38656
   226
  let ?G = "g -` {g (f x)} \<inter> (f`space M)"
hoelzl@38656
   227
  have *: "(g \<circ> f) -` {(g \<circ> f) x} \<inter> space M =
hoelzl@38656
   228
    (\<Union>x\<in>?G. f -` {x} \<inter> space M)" by auto
hoelzl@38656
   229
  show "(g \<circ> f) -` {(g \<circ> f) x} \<inter> space M \<in> sets M"
hoelzl@38656
   230
    using assms unfolding simple_function_def *
immler@50244
   231
    by (rule_tac sets.finite_UN) auto
hoelzl@38656
   232
qed
hoelzl@38656
   233
hoelzl@47694
   234
lemma simple_function_indicator[intro, simp]:
hoelzl@38656
   235
  assumes "A \<in> sets M"
hoelzl@41689
   236
  shows "simple_function M (indicator A)"
hoelzl@35692
   237
proof -
hoelzl@38656
   238
  have "indicator A ` space M \<subseteq> {0, 1}" (is "?S \<subseteq> _")
hoelzl@38656
   239
    by (auto simp: indicator_def)
hoelzl@38656
   240
  hence "finite ?S" by (rule finite_subset) simp
hoelzl@38656
   241
  moreover have "- A \<inter> space M = space M - A" by auto
hoelzl@38656
   242
  ultimately show ?thesis unfolding simple_function_def
wenzelm@46905
   243
    using assms by (auto simp: indicator_def [abs_def])
hoelzl@35692
   244
qed
hoelzl@35692
   245
hoelzl@47694
   246
lemma simple_function_Pair[intro, simp]:
hoelzl@41689
   247
  assumes "simple_function M f"
hoelzl@41689
   248
  assumes "simple_function M g"
hoelzl@41689
   249
  shows "simple_function M (\<lambda>x. (f x, g x))" (is "simple_function M ?p")
hoelzl@38656
   250
  unfolding simple_function_def
hoelzl@38656
   251
proof safe
hoelzl@38656
   252
  show "finite (?p ` space M)"
hoelzl@38656
   253
    using assms unfolding simple_function_def
hoelzl@38656
   254
    by (rule_tac finite_subset[of _ "f`space M \<times> g`space M"]) auto
hoelzl@38656
   255
next
hoelzl@38656
   256
  fix x assume "x \<in> space M"
hoelzl@38656
   257
  have "(\<lambda>x. (f x, g x)) -` {(f x, g x)} \<inter> space M =
hoelzl@38656
   258
      (f -` {f x} \<inter> space M) \<inter> (g -` {g x} \<inter> space M)"
hoelzl@38656
   259
    by auto
wenzelm@61808
   260
  with \<open>x \<in> space M\<close> show "(\<lambda>x. (f x, g x)) -` {(f x, g x)} \<inter> space M \<in> sets M"
hoelzl@38656
   261
    using assms unfolding simple_function_def by auto
hoelzl@38656
   262
qed
hoelzl@35692
   263
hoelzl@47694
   264
lemma simple_function_compose1:
hoelzl@41689
   265
  assumes "simple_function M f"
hoelzl@41689
   266
  shows "simple_function M (\<lambda>x. g (f x))"
hoelzl@38656
   267
  using simple_function_compose[OF assms, of g]
hoelzl@38656
   268
  by (simp add: comp_def)
hoelzl@35582
   269
hoelzl@47694
   270
lemma simple_function_compose2:
hoelzl@41689
   271
  assumes "simple_function M f" and "simple_function M g"
hoelzl@41689
   272
  shows "simple_function M (\<lambda>x. h (f x) (g x))"
hoelzl@38656
   273
proof -
hoelzl@41689
   274
  have "simple_function M ((\<lambda>(x, y). h x y) \<circ> (\<lambda>x. (f x, g x)))"
hoelzl@38656
   275
    using assms by auto
hoelzl@38656
   276
  thus ?thesis by (simp_all add: comp_def)
hoelzl@38656
   277
qed
hoelzl@35582
   278
nipkow@67399
   279
lemmas simple_function_add[intro, simp] = simple_function_compose2[where h="(+)"]
nipkow@67399
   280
  and simple_function_diff[intro, simp] = simple_function_compose2[where h="(-)"]
hoelzl@38656
   281
  and simple_function_uminus[intro, simp] = simple_function_compose[where g="uminus"]
nipkow@69064
   282
  and simple_function_mult[intro, simp] = simple_function_compose2[where h="(*)"]
nipkow@67399
   283
  and simple_function_div[intro, simp] = simple_function_compose2[where h="(/)"]
hoelzl@38656
   284
  and simple_function_inverse[intro, simp] = simple_function_compose[where g="inverse"]
hoelzl@41981
   285
  and simple_function_max[intro, simp] = simple_function_compose2[where h=max]
hoelzl@38656
   286
nipkow@64267
   287
lemma simple_function_sum[intro, simp]:
hoelzl@41689
   288
  assumes "\<And>i. i \<in> P \<Longrightarrow> simple_function M (f i)"
hoelzl@41689
   289
  shows "simple_function M (\<lambda>x. \<Sum>i\<in>P. f i x)"
hoelzl@38656
   290
proof cases
hoelzl@38656
   291
  assume "finite P" from this assms show ?thesis by induct auto
hoelzl@38656
   292
qed auto
hoelzl@35582
   293
hoelzl@62975
   294
lemma simple_function_ennreal[intro, simp]:
hoelzl@41981
   295
  fixes f g :: "'a \<Rightarrow> real" assumes sf: "simple_function M f"
hoelzl@62975
   296
  shows "simple_function M (\<lambda>x. ennreal (f x))"
nipkow@59587
   297
  by (rule simple_function_compose1[OF sf])
hoelzl@41981
   298
lp15@61609
   299
lemma simple_function_real_of_nat[intro, simp]:
hoelzl@41981
   300
  fixes f g :: "'a \<Rightarrow> nat" assumes sf: "simple_function M f"
hoelzl@56949
   301
  shows "simple_function M (\<lambda>x. real (f x))"
nipkow@59587
   302
  by (rule simple_function_compose1[OF sf])
hoelzl@35582
   303
eberlm@69457
   304
lemma%important borel_measurable_implies_simple_function_sequence:
hoelzl@62975
   305
  fixes u :: "'a \<Rightarrow> ennreal"
hoelzl@62975
   306
  assumes u[measurable]: "u \<in> borel_measurable M"
hoelzl@62975
   307
  shows "\<exists>f. incseq f \<and> (\<forall>i. (\<forall>x. f i x < top) \<and> simple_function M (f i)) \<and> u = (SUP i. f i)"
eberlm@69457
   308
proof%unimportant -
wenzelm@63040
   309
  define f where [abs_def]:
wenzelm@63040
   310
    "f i x = real_of_int (floor (enn2real (min i (u x)) * 2^i)) / 2^i" for i x
hoelzl@62975
   311
hoelzl@62975
   312
  have [simp]: "0 \<le> f i x" for i x
hoelzl@62975
   313
    by (auto simp: f_def intro!: divide_nonneg_nonneg mult_nonneg_nonneg enn2real_nonneg)
hoelzl@35582
   314
hoelzl@62975
   315
  have *: "2^n * real_of_int x = real_of_int (2^n * x)" for n x
hoelzl@62975
   316
    by simp
hoelzl@62975
   317
hoelzl@62975
   318
  have "real_of_int \<lfloor>real i * 2 ^ i\<rfloor> = real_of_int \<lfloor>i * 2 ^ i\<rfloor>" for i
hoelzl@62975
   319
    by (intro arg_cong[where f=real_of_int]) simp
hoelzl@62975
   320
  then have [simp]: "real_of_int \<lfloor>real i * 2 ^ i\<rfloor> = i * 2 ^ i" for i
hoelzl@62975
   321
    unfolding floor_of_nat by simp
hoelzl@35582
   322
hoelzl@62975
   323
  have "incseq f"
hoelzl@62975
   324
  proof (intro monoI le_funI)
hoelzl@62975
   325
    fix m n :: nat and x assume "m \<le> n"
hoelzl@62975
   326
    moreover
hoelzl@62975
   327
    { fix d :: nat
hoelzl@62975
   328
      have "\<lfloor>2^d::real\<rfloor> * \<lfloor>2^m * enn2real (min (of_nat m) (u x))\<rfloor> \<le>
hoelzl@62975
   329
        \<lfloor>2^d * (2^m * enn2real (min (of_nat m) (u x)))\<rfloor>"
hoelzl@62975
   330
        by (rule le_mult_floor) (auto simp: enn2real_nonneg)
hoelzl@62975
   331
      also have "\<dots> \<le> \<lfloor>2^d * (2^m * enn2real (min (of_nat d + of_nat m) (u x)))\<rfloor>"
hoelzl@62975
   332
        by (intro floor_mono mult_mono enn2real_mono min.mono)
hoelzl@62975
   333
           (auto simp: enn2real_nonneg min_less_iff_disj of_nat_less_top)
hoelzl@62975
   334
      finally have "f m x \<le> f (m + d) x"
hoelzl@62975
   335
        unfolding f_def
hoelzl@62975
   336
        by (auto simp: field_simps power_add * simp del: of_int_mult) }
hoelzl@62975
   337
    ultimately show "f m x \<le> f n x"
hoelzl@62975
   338
      by (auto simp add: le_iff_add)
hoelzl@62975
   339
  qed
hoelzl@62975
   340
  then have inc_f: "incseq (\<lambda>i. ennreal (f i x))" for x
hoelzl@62975
   341
    by (auto simp: incseq_def le_fun_def)
hoelzl@62975
   342
  then have "incseq (\<lambda>i x. ennreal (f i x))"
hoelzl@62975
   343
    by (auto simp: incseq_def le_fun_def)
hoelzl@62975
   344
  moreover
hoelzl@62975
   345
  have "simple_function M (f i)" for i
hoelzl@62975
   346
  proof (rule simple_function_borel_measurable)
hoelzl@62975
   347
    have "\<lfloor>enn2real (min (of_nat i) (u x)) * 2 ^ i\<rfloor> \<le> \<lfloor>int i * 2 ^ i\<rfloor>" for x
hoelzl@62975
   348
      by (cases "u x" rule: ennreal_cases)
hoelzl@62975
   349
         (auto split: split_min intro!: floor_mono)
hoelzl@62975
   350
    then have "f i ` space M \<subseteq> (\<lambda>n. real_of_int n / 2^i) ` {0 .. of_nat i * 2^i}"
hoelzl@62975
   351
      unfolding floor_of_int by (auto simp: f_def enn2real_nonneg intro!: imageI)
hoelzl@62975
   352
    then show "finite (f i ` space M)"
hoelzl@62975
   353
      by (rule finite_subset) auto
hoelzl@62975
   354
    show "f i \<in> borel_measurable M"
hoelzl@62975
   355
      unfolding f_def enn2real_def by measurable
hoelzl@62975
   356
  qed
hoelzl@62975
   357
  moreover
hoelzl@62975
   358
  { fix x
hoelzl@62975
   359
    have "(SUP i. ennreal (f i x)) = u x"
hoelzl@62975
   360
    proof (cases "u x" rule: ennreal_cases)
hoelzl@62975
   361
      case top then show ?thesis
hoelzl@62975
   362
        by (simp add: f_def inf_min[symmetric] ennreal_of_nat_eq_real_of_nat[symmetric]
hoelzl@62975
   363
                      ennreal_SUP_of_nat_eq_top)
hoelzl@41981
   364
    next
hoelzl@62975
   365
      case (real r)
hoelzl@62975
   366
      obtain n where "r \<le> of_nat n" using real_arch_simple by auto
hoelzl@62975
   367
      then have min_eq_r: "\<forall>\<^sub>F x in sequentially. min (real x) r = r"
hoelzl@62975
   368
        by (auto simp: eventually_sequentially intro!: exI[of _ n] split: split_min)
hoelzl@62975
   369
hoelzl@62975
   370
      have "(\<lambda>i. real_of_int \<lfloor>min (real i) r * 2^i\<rfloor> / 2^i) \<longlonglongrightarrow> r"
hoelzl@62975
   371
      proof (rule tendsto_sandwich)
hoelzl@62975
   372
        show "(\<lambda>n. r - (1/2)^n) \<longlonglongrightarrow> r"
hoelzl@62975
   373
          by (auto intro!: tendsto_eq_intros LIMSEQ_power_zero)
hoelzl@62975
   374
        show "\<forall>\<^sub>F n in sequentially. real_of_int \<lfloor>min (real n) r * 2 ^ n\<rfloor> / 2 ^ n \<le> r"
hoelzl@62975
   375
          using min_eq_r by eventually_elim (auto simp: field_simps)
hoelzl@62975
   376
        have *: "r * (2 ^ n * 2 ^ n) \<le> 2^n + 2^n * real_of_int \<lfloor>r * 2 ^ n\<rfloor>" for n
hoelzl@62975
   377
          using real_of_int_floor_ge_diff_one[of "r * 2^n", THEN mult_left_mono, of "2^n"]
hoelzl@62975
   378
          by (auto simp: field_simps)
hoelzl@62975
   379
        show "\<forall>\<^sub>F n in sequentially. r - (1/2)^n \<le> real_of_int \<lfloor>min (real n) r * 2 ^ n\<rfloor> / 2 ^ n"
hoelzl@62975
   380
          using min_eq_r by eventually_elim (insert *, auto simp: field_simps)
hoelzl@62975
   381
      qed auto
hoelzl@62975
   382
      then have "(\<lambda>i. ennreal (f i x)) \<longlonglongrightarrow> ennreal r"
hoelzl@62975
   383
        by (simp add: real f_def ennreal_of_nat_eq_real_of_nat min_ennreal)
hoelzl@62975
   384
      from LIMSEQ_unique[OF LIMSEQ_SUP[OF inc_f] this]
hoelzl@62975
   385
      show ?thesis
hoelzl@62975
   386
        by (simp add: real)
hoelzl@62975
   387
    qed }
hoelzl@62975
   388
  ultimately show ?thesis
hoelzl@62975
   389
    by (intro exI[of _ "\<lambda>i x. ennreal (f i x)"]) auto
hoelzl@41981
   390
qed
hoelzl@35582
   391
hoelzl@47694
   392
lemma borel_measurable_implies_simple_function_sequence':
hoelzl@62975
   393
  fixes u :: "'a \<Rightarrow> ennreal"
hoelzl@41981
   394
  assumes u: "u \<in> borel_measurable M"
hoelzl@62975
   395
  obtains f where
hoelzl@62975
   396
    "\<And>i. simple_function M (f i)" "incseq f" "\<And>i x. f i x < top" "\<And>x. (SUP i. f i x) = u x"
hoelzl@62975
   397
  using borel_measurable_implies_simple_function_sequence[OF u] by (auto simp: fun_eq_iff) blast
hoelzl@41981
   398
eberlm@69457
   399
lemma%important simple_function_induct
eberlm@69457
   400
    [consumes 1, case_names cong set mult add, induct set: simple_function]:
hoelzl@62975
   401
  fixes u :: "'a \<Rightarrow> ennreal"
hoelzl@49796
   402
  assumes u: "simple_function M u"
hoelzl@49796
   403
  assumes cong: "\<And>f g. simple_function M f \<Longrightarrow> simple_function M g \<Longrightarrow> (AE x in M. f x = g x) \<Longrightarrow> P f \<Longrightarrow> P g"
hoelzl@49796
   404
  assumes set: "\<And>A. A \<in> sets M \<Longrightarrow> P (indicator A)"
hoelzl@49796
   405
  assumes mult: "\<And>u c. P u \<Longrightarrow> P (\<lambda>x. c * u x)"
hoelzl@49796
   406
  assumes add: "\<And>u v. P u \<Longrightarrow> P v \<Longrightarrow> P (\<lambda>x. v x + u x)"
hoelzl@49796
   407
  shows "P u"
eberlm@69457
   408
proof%unimportant (rule cong)
hoelzl@49796
   409
  from AE_space show "AE x in M. (\<Sum>y\<in>u ` space M. y * indicator (u -` {y} \<inter> space M) x) = u x"
hoelzl@49796
   410
  proof eventually_elim
hoelzl@49796
   411
    fix x assume x: "x \<in> space M"
hoelzl@49796
   412
    from simple_function_indicator_representation[OF u x]
hoelzl@49796
   413
    show "(\<Sum>y\<in>u ` space M. y * indicator (u -` {y} \<inter> space M) x) = u x" ..
hoelzl@49796
   414
  qed
hoelzl@49796
   415
next
hoelzl@49796
   416
  from u have "finite (u ` space M)"
hoelzl@49796
   417
    unfolding simple_function_def by auto
hoelzl@49796
   418
  then show "P (\<lambda>x. \<Sum>y\<in>u ` space M. y * indicator (u -` {y} \<inter> space M) x)"
hoelzl@49796
   419
  proof induct
hoelzl@49796
   420
    case empty show ?case
hoelzl@49796
   421
      using set[of "{}"] by (simp add: indicator_def[abs_def])
hoelzl@49796
   422
  qed (auto intro!: add mult set simple_functionD u)
hoelzl@49796
   423
next
hoelzl@49796
   424
  show "simple_function M (\<lambda>x. (\<Sum>y\<in>u ` space M. y * indicator (u -` {y} \<inter> space M) x))"
hoelzl@49796
   425
    apply (subst simple_function_cong)
hoelzl@49796
   426
    apply (rule simple_function_indicator_representation[symmetric])
hoelzl@49796
   427
    apply (auto intro: u)
hoelzl@49796
   428
    done
hoelzl@49796
   429
qed fact
hoelzl@49796
   430
hoelzl@62975
   431
lemma simple_function_induct_nn[consumes 1, case_names cong set mult add]:
hoelzl@62975
   432
  fixes u :: "'a \<Rightarrow> ennreal"
hoelzl@62975
   433
  assumes u: "simple_function M u"
hoelzl@49799
   434
  assumes cong: "\<And>f g. simple_function M f \<Longrightarrow> simple_function M g \<Longrightarrow> (\<And>x. x \<in> space M \<Longrightarrow> f x = g x) \<Longrightarrow> P f \<Longrightarrow> P g"
hoelzl@49796
   435
  assumes set: "\<And>A. A \<in> sets M \<Longrightarrow> P (indicator A)"
hoelzl@62975
   436
  assumes mult: "\<And>u c. simple_function M u \<Longrightarrow> P u \<Longrightarrow> P (\<lambda>x. c * u x)"
hoelzl@62975
   437
  assumes add: "\<And>u v. simple_function M u \<Longrightarrow> P u \<Longrightarrow> simple_function M v \<Longrightarrow> (\<And>x. x \<in> space M \<Longrightarrow> u x = 0 \<or> v x = 0) \<Longrightarrow> P v \<Longrightarrow> P (\<lambda>x. v x + u x)"
hoelzl@49796
   438
  shows "P u"
hoelzl@49796
   439
proof -
hoelzl@49796
   440
  show ?thesis
hoelzl@49796
   441
  proof (rule cong)
hoelzl@49799
   442
    fix x assume x: "x \<in> space M"
hoelzl@49799
   443
    from simple_function_indicator_representation[OF u x]
hoelzl@49799
   444
    show "(\<Sum>y\<in>u ` space M. y * indicator (u -` {y} \<inter> space M) x) = u x" ..
hoelzl@49796
   445
  next
hoelzl@49799
   446
    show "simple_function M (\<lambda>x. (\<Sum>y\<in>u ` space M. y * indicator (u -` {y} \<inter> space M) x))"
hoelzl@49796
   447
      apply (subst simple_function_cong)
hoelzl@49796
   448
      apply (rule simple_function_indicator_representation[symmetric])
hoelzl@49799
   449
      apply (auto intro: u)
hoelzl@49796
   450
      done
hoelzl@49796
   451
  next
hoelzl@62975
   452
    from u have "finite (u ` space M)"
hoelzl@49796
   453
      unfolding simple_function_def by auto
hoelzl@49799
   454
    then show "P (\<lambda>x. \<Sum>y\<in>u ` space M. y * indicator (u -` {y} \<inter> space M) x)"
hoelzl@49796
   455
    proof induct
hoelzl@49796
   456
      case empty show ?case
hoelzl@49796
   457
        using set[of "{}"] by (simp add: indicator_def[abs_def])
hoelzl@56993
   458
    next
hoelzl@56993
   459
      case (insert x S)
hoelzl@56993
   460
      { fix z have "(\<Sum>y\<in>S. y * indicator (u -` {y} \<inter> space M) z) = 0 \<or>
hoelzl@56993
   461
          x * indicator (u -` {x} \<inter> space M) z = 0"
nipkow@64267
   462
          using insert by (subst sum_eq_0_iff) (auto simp: indicator_def) }
hoelzl@56993
   463
      note disj = this
hoelzl@56993
   464
      from insert show ?case
nipkow@64267
   465
        by (auto intro!: add mult set simple_functionD u simple_function_sum disj)
hoelzl@56993
   466
    qed
hoelzl@49796
   467
  qed fact
hoelzl@49796
   468
qed
hoelzl@49796
   469
eberlm@69457
   470
lemma%important borel_measurable_induct
eberlm@69457
   471
    [consumes 1, case_names cong set mult add seq, induct set: borel_measurable]:
hoelzl@62975
   472
  fixes u :: "'a \<Rightarrow> ennreal"
hoelzl@62975
   473
  assumes u: "u \<in> borel_measurable M"
hoelzl@49799
   474
  assumes cong: "\<And>f g. f \<in> borel_measurable M \<Longrightarrow> g \<in> borel_measurable M \<Longrightarrow> (\<And>x. x \<in> space M \<Longrightarrow> f x = g x) \<Longrightarrow> P g \<Longrightarrow> P f"
hoelzl@49796
   475
  assumes set: "\<And>A. A \<in> sets M \<Longrightarrow> P (indicator A)"
hoelzl@62975
   476
  assumes mult': "\<And>u c. c < top \<Longrightarrow> u \<in> borel_measurable M \<Longrightarrow> (\<And>x. x \<in> space M \<Longrightarrow> u x < top) \<Longrightarrow> P u \<Longrightarrow> P (\<lambda>x. c * u x)"
hoelzl@62975
   477
  assumes add: "\<And>u v. u \<in> borel_measurable M\<Longrightarrow> (\<And>x. x \<in> space M \<Longrightarrow> u x < top) \<Longrightarrow> P u \<Longrightarrow> v \<in> borel_measurable M \<Longrightarrow> (\<And>x. x \<in> space M \<Longrightarrow> v x < top) \<Longrightarrow> (\<And>x. x \<in> space M \<Longrightarrow> u x = 0 \<or> v x = 0) \<Longrightarrow> P v \<Longrightarrow> P (\<lambda>x. v x + u x)"
hoelzl@62975
   478
  assumes seq: "\<And>U. (\<And>i. U i \<in> borel_measurable M) \<Longrightarrow> (\<And>i x. x \<in> space M \<Longrightarrow> U i x < top) \<Longrightarrow> (\<And>i. P (U i)) \<Longrightarrow> incseq U \<Longrightarrow> u = (SUP i. U i) \<Longrightarrow> P (SUP i. U i)"
hoelzl@49796
   479
  shows "P u"
eberlm@69457
   480
  using%unimportant u
eberlm@69457
   481
proof%unimportant (induct rule: borel_measurable_implies_simple_function_sequence')
hoelzl@62975
   482
  fix U assume U: "\<And>i. simple_function M (U i)" "incseq U" "\<And>i x. U i x < top" and sup: "\<And>x. (SUP i. U i x) = u x"
hoelzl@49799
   483
  have u_eq: "u = (SUP i. U i)"
hoelzl@62975
   484
    using u sup by auto
hoelzl@56993
   485
hoelzl@62975
   486
  have not_inf: "\<And>x i. x \<in> space M \<Longrightarrow> U i x < top"
hoelzl@56993
   487
    using U by (auto simp: image_iff eq_commute)
lp15@61609
   488
hoelzl@49797
   489
  from U have "\<And>i. U i \<in> borel_measurable M"
hoelzl@49797
   490
    by (simp add: borel_measurable_simple_function)
hoelzl@49797
   491
hoelzl@49799
   492
  show "P u"
hoelzl@49796
   493
    unfolding u_eq
hoelzl@49796
   494
  proof (rule seq)
hoelzl@49796
   495
    fix i show "P (U i)"
hoelzl@62975
   496
      using \<open>simple_function M (U i)\<close> not_inf[of _ i]
hoelzl@56993
   497
    proof (induct rule: simple_function_induct_nn)
hoelzl@56993
   498
      case (mult u c)
hoelzl@56993
   499
      show ?case
hoelzl@56993
   500
      proof cases
hoelzl@56993
   501
        assume "c = 0 \<or> space M = {} \<or> (\<forall>x\<in>space M. u x = 0)"
hoelzl@62975
   502
        with mult(1) show ?thesis
hoelzl@56993
   503
          by (intro cong[of "\<lambda>x. c * u x" "indicator {}"] set)
hoelzl@56993
   504
             (auto dest!: borel_measurable_simple_function)
hoelzl@56993
   505
      next
hoelzl@56993
   506
        assume "\<not> (c = 0 \<or> space M = {} \<or> (\<forall>x\<in>space M. u x = 0))"
hoelzl@62975
   507
        then obtain x where "space M \<noteq> {}" and x: "x \<in> space M" "u x \<noteq> 0" "c \<noteq> 0"
hoelzl@56993
   508
          by auto
hoelzl@62975
   509
        with mult(3)[of x] have "c < top"
hoelzl@62975
   510
          by (auto simp: ennreal_mult_less_top)
hoelzl@62975
   511
        then have u_fin: "x' \<in> space M \<Longrightarrow> u x' < top" for x'
hoelzl@62975
   512
          using mult(3)[of x'] \<open>c \<noteq> 0\<close> by (auto simp: ennreal_mult_less_top)
hoelzl@62975
   513
        then have "P u"
hoelzl@62975
   514
          by (rule mult)
hoelzl@62975
   515
        with u_fin \<open>c < top\<close> mult(1) show ?thesis
hoelzl@56993
   516
          by (intro mult') (auto dest!: borel_measurable_simple_function)
hoelzl@56993
   517
      qed
hoelzl@56993
   518
    qed (auto intro: cong intro!: set add dest!: borel_measurable_simple_function)
hoelzl@49797
   519
  qed fact+
hoelzl@49796
   520
qed
hoelzl@49796
   521
hoelzl@47694
   522
lemma simple_function_If_set:
hoelzl@41981
   523
  assumes sf: "simple_function M f" "simple_function M g" and A: "A \<inter> space M \<in> sets M"
hoelzl@41981
   524
  shows "simple_function M (\<lambda>x. if x \<in> A then f x else g x)" (is "simple_function M ?IF")
hoelzl@41981
   525
proof -
wenzelm@63040
   526
  define F where "F x = f -` {x} \<inter> space M" for x
wenzelm@63040
   527
  define G where "G x = g -` {x} \<inter> space M" for x
hoelzl@41981
   528
  show ?thesis unfolding simple_function_def
hoelzl@41981
   529
  proof safe
hoelzl@41981
   530
    have "?IF ` space M \<subseteq> f ` space M \<union> g ` space M" by auto
hoelzl@41981
   531
    from finite_subset[OF this] assms
hoelzl@41981
   532
    show "finite (?IF ` space M)" unfolding simple_function_def by auto
hoelzl@41981
   533
  next
hoelzl@41981
   534
    fix x assume "x \<in> space M"
hoelzl@41981
   535
    then have *: "?IF -` {?IF x} \<inter> space M = (if x \<in> A
hoelzl@41981
   536
      then ((F (f x) \<inter> (A \<inter> space M)) \<union> (G (f x) - (G (f x) \<inter> (A \<inter> space M))))
hoelzl@41981
   537
      else ((F (g x) \<inter> (A \<inter> space M)) \<union> (G (g x) - (G (g x) \<inter> (A \<inter> space M)))))"
nipkow@62390
   538
      using sets.sets_into_space[OF A] by (auto split: if_split_asm simp: G_def F_def)
hoelzl@41981
   539
    have [intro]: "\<And>x. F x \<in> sets M" "\<And>x. G x \<in> sets M"
hoelzl@41981
   540
      unfolding F_def G_def using sf[THEN simple_functionD(2)] by auto
hoelzl@41981
   541
    show "?IF -` {?IF x} \<inter> space M \<in> sets M" unfolding * using A by auto
hoelzl@35582
   542
  qed
hoelzl@35582
   543
qed
hoelzl@35582
   544
hoelzl@47694
   545
lemma simple_function_If:
hoelzl@41981
   546
  assumes sf: "simple_function M f" "simple_function M g" and P: "{x\<in>space M. P x} \<in> sets M"
hoelzl@41981
   547
  shows "simple_function M (\<lambda>x. if P x then f x else g x)"
hoelzl@35582
   548
proof -
hoelzl@41981
   549
  have "{x\<in>space M. P x} = {x. P x} \<inter> space M" by auto
hoelzl@41981
   550
  with simple_function_If_set[OF sf, of "{x. P x}"] P show ?thesis by simp
hoelzl@38656
   551
qed
hoelzl@38656
   552
hoelzl@47694
   553
lemma simple_function_subalgebra:
hoelzl@41689
   554
  assumes "simple_function N f"
hoelzl@41689
   555
  and N_subalgebra: "sets N \<subseteq> sets M" "space N = space M"
hoelzl@41689
   556
  shows "simple_function M f"
hoelzl@41689
   557
  using assms unfolding simple_function_def by auto
hoelzl@39092
   558
hoelzl@47694
   559
lemma simple_function_comp:
hoelzl@47694
   560
  assumes T: "T \<in> measurable M M'"
hoelzl@41689
   561
    and f: "simple_function M' f"
hoelzl@41689
   562
  shows "simple_function M (\<lambda>x. f (T x))"
hoelzl@41661
   563
proof (intro simple_function_def[THEN iffD2] conjI ballI)
hoelzl@41661
   564
  have "(\<lambda>x. f (T x)) ` space M \<subseteq> f ` space M'"
hoelzl@41661
   565
    using T unfolding measurable_def by auto
hoelzl@41661
   566
  then show "finite ((\<lambda>x. f (T x)) ` space M)"
hoelzl@41689
   567
    using f unfolding simple_function_def by (auto intro: finite_subset)
hoelzl@41661
   568
  fix i assume i: "i \<in> (\<lambda>x. f (T x)) ` space M"
hoelzl@41661
   569
  then have "i \<in> f ` space M'"
hoelzl@41661
   570
    using T unfolding measurable_def by auto
hoelzl@41661
   571
  then have "f -` {i} \<inter> space M' \<in> sets M'"
hoelzl@41689
   572
    using f unfolding simple_function_def by auto
hoelzl@41661
   573
  then have "T -` (f -` {i} \<inter> space M') \<inter> space M \<in> sets M"
hoelzl@41661
   574
    using T unfolding measurable_def by auto
hoelzl@41661
   575
  also have "T -` (f -` {i} \<inter> space M') \<inter> space M = (\<lambda>x. f (T x)) -` {i} \<inter> space M"
hoelzl@41661
   576
    using T unfolding measurable_def by auto
hoelzl@41661
   577
  finally show "(\<lambda>x. f (T x)) -` {i} \<inter> space M \<in> sets M" .
hoelzl@40859
   578
qed
hoelzl@40859
   579
hoelzl@56994
   580
subsection "Simple integral"
hoelzl@38656
   581
eberlm@69457
   582
definition%important simple_integral :: "'a measure \<Rightarrow> ('a \<Rightarrow> ennreal) \<Rightarrow> ennreal" ("integral\<^sup>S") where
wenzelm@53015
   583
  "integral\<^sup>S M f = (\<Sum>x \<in> f ` space M. x * emeasure M (f -` {x} \<inter> space M))"
hoelzl@41689
   584
hoelzl@41689
   585
syntax
hoelzl@62975
   586
  "_simple_integral" :: "pttrn \<Rightarrow> ennreal \<Rightarrow> 'a measure \<Rightarrow> ennreal" ("\<integral>\<^sup>S _. _ \<partial>_" [60,61] 110)
hoelzl@41689
   587
hoelzl@41689
   588
translations
wenzelm@53015
   589
  "\<integral>\<^sup>S x. f \<partial>M" == "CONST simple_integral M (%x. f)"
hoelzl@35582
   590
hoelzl@47694
   591
lemma simple_integral_cong:
hoelzl@38656
   592
  assumes "\<And>t. t \<in> space M \<Longrightarrow> f t = g t"
wenzelm@53015
   593
  shows "integral\<^sup>S M f = integral\<^sup>S M g"
hoelzl@38656
   594
proof -
hoelzl@38656
   595
  have "f ` space M = g ` space M"
hoelzl@38656
   596
    "\<And>x. f -` {x} \<inter> space M = g -` {x} \<inter> space M"
hoelzl@38656
   597
    using assms by (auto intro!: image_eqI)
hoelzl@38656
   598
  thus ?thesis unfolding simple_integral_def by simp
hoelzl@38656
   599
qed
hoelzl@38656
   600
hoelzl@47694
   601
lemma simple_integral_const[simp]:
wenzelm@53015
   602
  "(\<integral>\<^sup>Sx. c \<partial>M) = c * (emeasure M) (space M)"
hoelzl@38656
   603
proof (cases "space M = {}")
hoelzl@38656
   604
  case True thus ?thesis unfolding simple_integral_def by simp
hoelzl@38656
   605
next
hoelzl@38656
   606
  case False hence "(\<lambda>x. c) ` space M = {c}" by auto
hoelzl@38656
   607
  thus ?thesis unfolding simple_integral_def by simp
hoelzl@35582
   608
qed
hoelzl@35582
   609
hoelzl@47694
   610
lemma simple_function_partition:
hoelzl@41981
   611
  assumes f: "simple_function M f" and g: "simple_function M g"
hoelzl@56949
   612
  assumes sub: "\<And>x y. x \<in> space M \<Longrightarrow> y \<in> space M \<Longrightarrow> g x = g y \<Longrightarrow> f x = f y"
hoelzl@56949
   613
  assumes v: "\<And>x. x \<in> space M \<Longrightarrow> f x = v (g x)"
hoelzl@56949
   614
  shows "integral\<^sup>S M f = (\<Sum>y\<in>g ` space M. v y * emeasure M {x\<in>space M. g x = y})"
hoelzl@56949
   615
    (is "_ = ?r")
hoelzl@56949
   616
proof -
hoelzl@56949
   617
  from f g have [simp]: "finite (f`space M)" "finite (g`space M)"
hoelzl@56949
   618
    by (auto simp: simple_function_def)
hoelzl@56949
   619
  from f g have [measurable]: "f \<in> measurable M (count_space UNIV)" "g \<in> measurable M (count_space UNIV)"
hoelzl@56949
   620
    by (auto intro: measurable_simple_function)
hoelzl@35582
   621
hoelzl@56949
   622
  { fix y assume "y \<in> space M"
hoelzl@56949
   623
    then have "f ` space M \<inter> {i. \<exists>x\<in>space M. i = f x \<and> g y = g x} = {v (g y)}"
hoelzl@56949
   624
      by (auto cong: sub simp: v[symmetric]) }
hoelzl@56949
   625
  note eq = this
hoelzl@35582
   626
hoelzl@56949
   627
  have "integral\<^sup>S M f =
lp15@61609
   628
    (\<Sum>y\<in>f`space M. y * (\<Sum>z\<in>g`space M.
hoelzl@56949
   629
      if \<exists>x\<in>space M. y = f x \<and> z = g x then emeasure M {x\<in>space M. g x = z} else 0))"
hoelzl@56949
   630
    unfolding simple_integral_def
nipkow@64267
   631
  proof (safe intro!: sum.cong ennreal_mult_left_cong)
hoelzl@56949
   632
    fix y assume y: "y \<in> space M" "f y \<noteq> 0"
lp15@61609
   633
    have [simp]: "g ` space M \<inter> {z. \<exists>x\<in>space M. f y = f x \<and> z = g x} =
hoelzl@56949
   634
        {z. \<exists>x\<in>space M. f y = f x \<and> z = g x}"
hoelzl@56949
   635
      by auto
hoelzl@56949
   636
    have eq:"(\<Union>i\<in>{z. \<exists>x\<in>space M. f y = f x \<and> z = g x}. {x \<in> space M. g x = i}) =
hoelzl@56949
   637
        f -` {f y} \<inter> space M"
hoelzl@56949
   638
      by (auto simp: eq_commute cong: sub rev_conj_cong)
hoelzl@56949
   639
    have "finite (g`space M)" by simp
hoelzl@56949
   640
    then have "finite {z. \<exists>x\<in>space M. f y = f x \<and> z = g x}"
hoelzl@56949
   641
      by (rule rev_finite_subset) auto
hoelzl@56949
   642
    then show "emeasure M (f -` {f y} \<inter> space M) =
hoelzl@56949
   643
      (\<Sum>z\<in>g ` space M. if \<exists>x\<in>space M. f y = f x \<and> z = g x then emeasure M {x \<in> space M. g x = z} else 0)"
nipkow@64267
   644
      apply (simp add: sum.If_cases)
nipkow@64267
   645
      apply (subst sum_emeasure)
hoelzl@56949
   646
      apply (auto simp: disjoint_family_on_def eq)
hoelzl@56949
   647
      done
hoelzl@38656
   648
  qed
lp15@61609
   649
  also have "\<dots> = (\<Sum>y\<in>f`space M. (\<Sum>z\<in>g`space M.
hoelzl@56949
   650
      if \<exists>x\<in>space M. y = f x \<and> z = g x then y * emeasure M {x\<in>space M. g x = z} else 0))"
nipkow@64267
   651
    by (auto intro!: sum.cong simp: sum_distrib_left)
hoelzl@56949
   652
  also have "\<dots> = ?r"
haftmann@66804
   653
    by (subst sum.swap)
nipkow@64267
   654
       (auto intro!: sum.cong simp: sum.If_cases scaleR_sum_right[symmetric] eq)
hoelzl@56949
   655
  finally show "integral\<^sup>S M f = ?r" .
hoelzl@35582
   656
qed
hoelzl@35582
   657
hoelzl@47694
   658
lemma simple_integral_add[simp]:
hoelzl@41981
   659
  assumes f: "simple_function M f" and "\<And>x. 0 \<le> f x" and g: "simple_function M g" and "\<And>x. 0 \<le> g x"
wenzelm@53015
   660
  shows "(\<integral>\<^sup>Sx. f x + g x \<partial>M) = integral\<^sup>S M f + integral\<^sup>S M g"
hoelzl@35582
   661
proof -
hoelzl@56949
   662
  have "(\<integral>\<^sup>Sx. f x + g x \<partial>M) =
hoelzl@56949
   663
    (\<Sum>y\<in>(\<lambda>x. (f x, g x))`space M. (fst y + snd y) * emeasure M {x\<in>space M. (f x, g x) = y})"
hoelzl@56949
   664
    by (intro simple_function_partition) (auto intro: f g)
hoelzl@56949
   665
  also have "\<dots> = (\<Sum>y\<in>(\<lambda>x. (f x, g x))`space M. fst y * emeasure M {x\<in>space M. (f x, g x) = y}) +
hoelzl@56949
   666
    (\<Sum>y\<in>(\<lambda>x. (f x, g x))`space M. snd y * emeasure M {x\<in>space M. (f x, g x) = y})"
nipkow@64267
   667
    using assms(2,4) by (auto intro!: sum.cong distrib_right simp: sum.distrib[symmetric])
hoelzl@56949
   668
  also have "(\<Sum>y\<in>(\<lambda>x. (f x, g x))`space M. fst y * emeasure M {x\<in>space M. (f x, g x) = y}) = (\<integral>\<^sup>Sx. f x \<partial>M)"
hoelzl@56949
   669
    by (intro simple_function_partition[symmetric]) (auto intro: f g)
hoelzl@56949
   670
  also have "(\<Sum>y\<in>(\<lambda>x. (f x, g x))`space M. snd y * emeasure M {x\<in>space M. (f x, g x) = y}) = (\<integral>\<^sup>Sx. g x \<partial>M)"
hoelzl@56949
   671
    by (intro simple_function_partition[symmetric]) (auto intro: f g)
hoelzl@56949
   672
  finally show ?thesis .
hoelzl@35582
   673
qed
hoelzl@35582
   674
nipkow@64267
   675
lemma simple_integral_sum[simp]:
hoelzl@41981
   676
  assumes "\<And>i x. i \<in> P \<Longrightarrow> 0 \<le> f i x"
hoelzl@41689
   677
  assumes "\<And>i. i \<in> P \<Longrightarrow> simple_function M (f i)"
wenzelm@53015
   678
  shows "(\<integral>\<^sup>Sx. (\<Sum>i\<in>P. f i x) \<partial>M) = (\<Sum>i\<in>P. integral\<^sup>S M (f i))"
hoelzl@38656
   679
proof cases
hoelzl@38656
   680
  assume "finite P"
hoelzl@38656
   681
  from this assms show ?thesis
nipkow@64267
   682
    by induct (auto simp: simple_function_sum simple_integral_add sum_nonneg)
hoelzl@38656
   683
qed auto
hoelzl@38656
   684
hoelzl@47694
   685
lemma simple_integral_mult[simp]:
hoelzl@62975
   686
  assumes f: "simple_function M f"
wenzelm@53015
   687
  shows "(\<integral>\<^sup>Sx. c * f x \<partial>M) = c * integral\<^sup>S M f"
hoelzl@38656
   688
proof -
hoelzl@56949
   689
  have "(\<integral>\<^sup>Sx. c * f x \<partial>M) = (\<Sum>y\<in>f ` space M. (c * y) * emeasure M {x\<in>space M. f x = y})"
hoelzl@56949
   690
    using f by (intro simple_function_partition) auto
hoelzl@56949
   691
  also have "\<dots> = c * integral\<^sup>S M f"
hoelzl@56949
   692
    using f unfolding simple_integral_def
nipkow@64267
   693
    by (subst sum_distrib_left) (auto simp: mult.assoc Int_def conj_commute)
hoelzl@56949
   694
  finally show ?thesis .
hoelzl@40871
   695
qed
hoelzl@40871
   696
hoelzl@47694
   697
lemma simple_integral_mono_AE:
hoelzl@56949
   698
  assumes f[measurable]: "simple_function M f" and g[measurable]: "simple_function M g"
hoelzl@47694
   699
  and mono: "AE x in M. f x \<le> g x"
wenzelm@53015
   700
  shows "integral\<^sup>S M f \<le> integral\<^sup>S M g"
hoelzl@40859
   701
proof -
hoelzl@56949
   702
  let ?\<mu> = "\<lambda>P. emeasure M {x\<in>space M. P x}"
hoelzl@56949
   703
  have "integral\<^sup>S M f = (\<Sum>y\<in>(\<lambda>x. (f x, g x))`space M. fst y * ?\<mu> (\<lambda>x. (f x, g x) = y))"
hoelzl@56949
   704
    using f g by (intro simple_function_partition) auto
hoelzl@56949
   705
  also have "\<dots> \<le> (\<Sum>y\<in>(\<lambda>x. (f x, g x))`space M. snd y * ?\<mu> (\<lambda>x. (f x, g x) = y))"
nipkow@64267
   706
  proof (clarsimp intro!: sum_mono)
hoelzl@40859
   707
    fix x assume "x \<in> space M"
hoelzl@56949
   708
    let ?M = "?\<mu> (\<lambda>y. f y = f x \<and> g y = g x)"
hoelzl@56949
   709
    show "f x * ?M \<le> g x * ?M"
hoelzl@56949
   710
    proof cases
hoelzl@56949
   711
      assume "?M \<noteq> 0"
hoelzl@56949
   712
      then have "0 < ?M"
hoelzl@62975
   713
        by (simp add: less_le)
hoelzl@56949
   714
      also have "\<dots> \<le> ?\<mu> (\<lambda>y. f x \<le> g x)"
hoelzl@56949
   715
        using mono by (intro emeasure_mono_AE) auto
hoelzl@56949
   716
      finally have "\<not> \<not> f x \<le> g x"
hoelzl@56949
   717
        by (intro notI) auto
hoelzl@56949
   718
      then show ?thesis
hoelzl@62975
   719
        by (intro mult_right_mono) auto
hoelzl@56949
   720
    qed simp
hoelzl@40859
   721
  qed
hoelzl@56949
   722
  also have "\<dots> = integral\<^sup>S M g"
hoelzl@56949
   723
    using f g by (intro simple_function_partition[symmetric]) auto
hoelzl@56949
   724
  finally show ?thesis .
hoelzl@40859
   725
qed
hoelzl@40859
   726
hoelzl@47694
   727
lemma simple_integral_mono:
hoelzl@41689
   728
  assumes "simple_function M f" and "simple_function M g"
hoelzl@38656
   729
  and mono: "\<And> x. x \<in> space M \<Longrightarrow> f x \<le> g x"
wenzelm@53015
   730
  shows "integral\<^sup>S M f \<le> integral\<^sup>S M g"
hoelzl@41705
   731
  using assms by (intro simple_integral_mono_AE) auto
hoelzl@35582
   732
hoelzl@47694
   733
lemma simple_integral_cong_AE:
hoelzl@41981
   734
  assumes "simple_function M f" and "simple_function M g"
hoelzl@47694
   735
  and "AE x in M. f x = g x"
wenzelm@53015
   736
  shows "integral\<^sup>S M f = integral\<^sup>S M g"
hoelzl@40859
   737
  using assms by (auto simp: eq_iff intro!: simple_integral_mono_AE)
hoelzl@40859
   738
hoelzl@47694
   739
lemma simple_integral_cong':
hoelzl@41689
   740
  assumes sf: "simple_function M f" "simple_function M g"
hoelzl@47694
   741
  and mea: "(emeasure M) {x\<in>space M. f x \<noteq> g x} = 0"
wenzelm@53015
   742
  shows "integral\<^sup>S M f = integral\<^sup>S M g"
hoelzl@40859
   743
proof (intro simple_integral_cong_AE sf AE_I)
hoelzl@47694
   744
  show "(emeasure M) {x\<in>space M. f x \<noteq> g x} = 0" by fact
hoelzl@40859
   745
  show "{x \<in> space M. f x \<noteq> g x} \<in> sets M"
hoelzl@40859
   746
    using sf[THEN borel_measurable_simple_function] by auto
hoelzl@40859
   747
qed simp
hoelzl@40859
   748
hoelzl@47694
   749
lemma simple_integral_indicator:
hoelzl@56949
   750
  assumes A: "A \<in> sets M"
hoelzl@49796
   751
  assumes f: "simple_function M f"
wenzelm@53015
   752
  shows "(\<integral>\<^sup>Sx. f x * indicator A x \<partial>M) =
hoelzl@56949
   753
    (\<Sum>x \<in> f ` space M. x * emeasure M (f -` {x} \<inter> space M \<inter> A))"
hoelzl@56949
   754
proof -
hoelzl@62975
   755
  have eq: "(\<lambda>x. (f x, indicator A x)) ` space M \<inter> {x. snd x = 1} = (\<lambda>x. (f x, 1::ennreal))`A"
nipkow@62390
   756
    using A[THEN sets.sets_into_space] by (auto simp: indicator_def image_iff split: if_split_asm)
hoelzl@56949
   757
  have eq2: "\<And>x. f x \<notin> f ` A \<Longrightarrow> f -` {f x} \<inter> space M \<inter> A = {}"
hoelzl@56949
   758
    by (auto simp: image_iff)
hoelzl@56949
   759
hoelzl@56949
   760
  have "(\<integral>\<^sup>Sx. f x * indicator A x \<partial>M) =
hoelzl@56949
   761
    (\<Sum>y\<in>(\<lambda>x. (f x, indicator A x))`space M. (fst y * snd y) * emeasure M {x\<in>space M. (f x, indicator A x) = y})"
hoelzl@56949
   762
    using assms by (intro simple_function_partition) auto
hoelzl@62975
   763
  also have "\<dots> = (\<Sum>y\<in>(\<lambda>x. (f x, indicator A x::ennreal))`space M.
hoelzl@56949
   764
    if snd y = 1 then fst y * emeasure M (f -` {fst y} \<inter> space M \<inter> A) else 0)"
nipkow@69064
   765
    by (auto simp: indicator_def split: if_split_asm intro!: arg_cong2[where f="(*)"] arg_cong2[where f=emeasure] sum.cong)
hoelzl@62975
   766
  also have "\<dots> = (\<Sum>y\<in>(\<lambda>x. (f x, 1::ennreal))`A. fst y * emeasure M (f -` {fst y} \<inter> space M \<inter> A))"
nipkow@64267
   767
    using assms by (subst sum.If_cases) (auto intro!: simple_functionD(1) simp: eq)
hoelzl@62975
   768
  also have "\<dots> = (\<Sum>y\<in>fst`(\<lambda>x. (f x, 1::ennreal))`A. y * emeasure M (f -` {y} \<inter> space M \<inter> A))"
nipkow@64267
   769
    by (subst sum.reindex [of fst]) (auto simp: inj_on_def)
hoelzl@56949
   770
  also have "\<dots> = (\<Sum>x \<in> f ` space M. x * emeasure M (f -` {x} \<inter> space M \<inter> A))"
hoelzl@56949
   771
    using A[THEN sets.sets_into_space]
nipkow@64267
   772
    by (intro sum.mono_neutral_cong_left simple_functionD f) (auto simp: image_comp comp_def eq2)
hoelzl@56949
   773
  finally show ?thesis .
hoelzl@38656
   774
qed
hoelzl@35582
   775
hoelzl@47694
   776
lemma simple_integral_indicator_only[simp]:
hoelzl@38656
   777
  assumes "A \<in> sets M"
wenzelm@53015
   778
  shows "integral\<^sup>S M (indicator A) = emeasure M A"
hoelzl@56949
   779
  using simple_integral_indicator[OF assms, of "\<lambda>x. 1"] sets.sets_into_space[OF assms]
nipkow@62390
   780
  by (simp_all add: image_constant_conv Int_absorb1 split: if_split_asm)
hoelzl@35582
   781
hoelzl@47694
   782
lemma simple_integral_null_set:
hoelzl@47694
   783
  assumes "simple_function M u" "\<And>x. 0 \<le> u x" and "N \<in> null_sets M"
wenzelm@53015
   784
  shows "(\<integral>\<^sup>Sx. u x * indicator N x \<partial>M) = 0"
hoelzl@38656
   785
proof -
hoelzl@62975
   786
  have "AE x in M. indicator N x = (0 :: ennreal)"
wenzelm@61808
   787
    using \<open>N \<in> null_sets M\<close> by (auto simp: indicator_def intro!: AE_I[of _ _ N])
wenzelm@53015
   788
  then have "(\<integral>\<^sup>Sx. u x * indicator N x \<partial>M) = (\<integral>\<^sup>Sx. 0 \<partial>M)"
hoelzl@41981
   789
    using assms apply (intro simple_integral_cong_AE) by auto
hoelzl@40859
   790
  then show ?thesis by simp
hoelzl@38656
   791
qed
hoelzl@35582
   792
hoelzl@47694
   793
lemma simple_integral_cong_AE_mult_indicator:
hoelzl@47694
   794
  assumes sf: "simple_function M f" and eq: "AE x in M. x \<in> S" and "S \<in> sets M"
wenzelm@53015
   795
  shows "integral\<^sup>S M f = (\<integral>\<^sup>Sx. f x * indicator S x \<partial>M)"
hoelzl@41705
   796
  using assms by (intro simple_integral_cong_AE) auto
hoelzl@35582
   797
hoelzl@47694
   798
lemma simple_integral_cmult_indicator:
hoelzl@41981
   799
  assumes A: "A \<in> sets M"
hoelzl@56949
   800
  shows "(\<integral>\<^sup>Sx. c * indicator A x \<partial>M) = c * emeasure M A"
hoelzl@41981
   801
  using simple_integral_mult[OF simple_function_indicator[OF A]]
hoelzl@41981
   802
  unfolding simple_integral_indicator_only[OF A] by simp
hoelzl@41981
   803
hoelzl@56996
   804
lemma simple_integral_nonneg:
hoelzl@47694
   805
  assumes f: "simple_function M f" and ae: "AE x in M. 0 \<le> f x"
wenzelm@53015
   806
  shows "0 \<le> integral\<^sup>S M f"
hoelzl@41981
   807
proof -
wenzelm@53015
   808
  have "integral\<^sup>S M (\<lambda>x. 0) \<le> integral\<^sup>S M f"
hoelzl@41981
   809
    using simple_integral_mono_AE[OF _ f ae] by auto
hoelzl@41981
   810
  then show ?thesis by simp
hoelzl@41981
   811
qed
hoelzl@41981
   812
wenzelm@61808
   813
subsection \<open>Integral on nonnegative functions\<close>
hoelzl@41689
   814
eberlm@69457
   815
definition%important nn_integral :: "'a measure \<Rightarrow> ('a \<Rightarrow> ennreal) \<Rightarrow> ennreal" ("integral\<^sup>N") where
haftmann@69260
   816
  "integral\<^sup>N M f = (SUP g \<in> {g. simple_function M g \<and> g \<le> f}. integral\<^sup>S M g)"
hoelzl@35692
   817
hoelzl@41689
   818
syntax
hoelzl@62975
   819
  "_nn_integral" :: "pttrn \<Rightarrow> ennreal \<Rightarrow> 'a measure \<Rightarrow> ennreal" ("\<integral>\<^sup>+((2 _./ _)/ \<partial>_)" [60,61] 110)
hoelzl@41689
   820
hoelzl@41689
   821
translations
hoelzl@56996
   822
  "\<integral>\<^sup>+x. f \<partial>M" == "CONST nn_integral M (\<lambda>x. f)"
hoelzl@40872
   823
hoelzl@56996
   824
lemma nn_integral_def_finite:
haftmann@69260
   825
  "integral\<^sup>N M f = (SUP g \<in> {g. simple_function M g \<and> g \<le> f \<and> (\<forall>x. g x < top)}. integral\<^sup>S M g)"
haftmann@69313
   826
    (is "_ = Sup (?A ` ?f)")
hoelzl@56996
   827
  unfolding nn_integral_def
hoelzl@44928
   828
proof (safe intro!: antisym SUP_least)
hoelzl@62975
   829
  fix g assume g[measurable]: "simple_function M g" "g \<le> f"
hoelzl@62975
   830
haftmann@69313
   831
  show "integral\<^sup>S M g \<le> Sup (?A ` ?f)"
hoelzl@41981
   832
  proof cases
hoelzl@62975
   833
    assume ae: "AE x in M. g x \<noteq> top"
hoelzl@62975
   834
    let ?G = "{x \<in> space M. g x \<noteq> top}"
hoelzl@62975
   835
    have "integral\<^sup>S M g = integral\<^sup>S M (\<lambda>x. g x * indicator ?G x)"
hoelzl@62975
   836
    proof (rule simple_integral_cong_AE)
hoelzl@62975
   837
      show "AE x in M. g x = g x * indicator ?G x"
hoelzl@62975
   838
        using ae AE_space by eventually_elim auto
hoelzl@62975
   839
    qed (insert g, auto)
haftmann@69313
   840
    also have "\<dots> \<le> Sup (?A ` ?f)"
hoelzl@62975
   841
      using g by (intro SUP_upper) (auto simp: le_fun_def less_top split: split_indicator)
hoelzl@62975
   842
    finally show ?thesis .
hoelzl@41981
   843
  next
hoelzl@62975
   844
    assume nAE: "\<not> (AE x in M. g x \<noteq> top)"
hoelzl@62975
   845
    then have "emeasure M {x\<in>space M. g x = top} \<noteq> 0" (is "emeasure M ?G \<noteq> 0")
hoelzl@62975
   846
      by (subst (asm) AE_iff_measurable[OF _ refl]) auto
hoelzl@62975
   847
    then have "top = (SUP n. (\<integral>\<^sup>Sx. of_nat n * indicator ?G x \<partial>M))"
hoelzl@62975
   848
      by (simp add: ennreal_SUP_of_nat_eq_top ennreal_top_eq_mult_iff SUP_mult_right_ennreal[symmetric])
haftmann@69313
   849
    also have "\<dots> \<le> Sup (?A ` ?f)"
hoelzl@62975
   850
      using g
hoelzl@62975
   851
      by (safe intro!: SUP_least SUP_upper)
hoelzl@62975
   852
         (auto simp: le_fun_def of_nat_less_top top_unique[symmetric] split: split_indicator
hoelzl@62975
   853
               intro: order_trans[of _ "g x" "f x" for x, OF order_trans[of _ top]])
hoelzl@62975
   854
    finally show ?thesis
hoelzl@62975
   855
      by (simp add: top_unique del: SUP_eq_top_iff Sup_eq_top_iff)
hoelzl@41981
   856
  qed
hoelzl@44928
   857
qed (auto intro: SUP_upper)
hoelzl@40873
   858
hoelzl@56996
   859
lemma nn_integral_mono_AE:
hoelzl@56996
   860
  assumes ae: "AE x in M. u x \<le> v x" shows "integral\<^sup>N M u \<le> integral\<^sup>N M v"
hoelzl@56996
   861
  unfolding nn_integral_def
hoelzl@41981
   862
proof (safe intro!: SUP_mono)
hoelzl@62975
   863
  fix n assume n: "simple_function M n" "n \<le> u"
hoelzl@41981
   864
  from ae[THEN AE_E] guess N . note N = this
hoelzl@47694
   865
  then have ae_N: "AE x in M. x \<notin> N" by (auto intro: AE_not_in)
wenzelm@46731
   866
  let ?n = "\<lambda>x. n x * indicator (space M - N) x"
hoelzl@47694
   867
  have "AE x in M. n x \<le> ?n x" "simple_function M ?n"
hoelzl@41981
   868
    using n N ae_N by auto
hoelzl@41981
   869
  moreover
hoelzl@62975
   870
  { fix x have "?n x \<le> v x"
hoelzl@41981
   871
    proof cases
hoelzl@41981
   872
      assume x: "x \<in> space M - N"
hoelzl@41981
   873
      with N have "u x \<le> v x" by auto
hoelzl@41981
   874
      with n(2)[THEN le_funD, of x] x show ?thesis
nipkow@62390
   875
        by (auto simp: max_def split: if_split_asm)
hoelzl@41981
   876
    qed simp }
hoelzl@62975
   877
  then have "?n \<le> v" by (auto simp: le_funI)
wenzelm@53015
   878
  moreover have "integral\<^sup>S M n \<le> integral\<^sup>S M ?n"
hoelzl@41981
   879
    using ae_N N n by (auto intro!: simple_integral_mono_AE)
hoelzl@62975
   880
  ultimately show "\<exists>m\<in>{g. simple_function M g \<and> g \<le> v}. integral\<^sup>S M n \<le> integral\<^sup>S M m"
hoelzl@41981
   881
    by force
hoelzl@38656
   882
qed
hoelzl@38656
   883
hoelzl@56996
   884
lemma nn_integral_mono:
hoelzl@56996
   885
  "(\<And>x. x \<in> space M \<Longrightarrow> u x \<le> v x) \<Longrightarrow> integral\<^sup>N M u \<le> integral\<^sup>N M v"
hoelzl@56996
   886
  by (auto intro: nn_integral_mono_AE)
hoelzl@40859
   887
hoelzl@60175
   888
lemma mono_nn_integral: "mono F \<Longrightarrow> mono (\<lambda>x. integral\<^sup>N M (F x))"
hoelzl@60175
   889
  by (auto simp add: mono_def le_fun_def intro!: nn_integral_mono)
hoelzl@60175
   890
hoelzl@56996
   891
lemma nn_integral_cong_AE:
hoelzl@56996
   892
  "AE x in M. u x = v x \<Longrightarrow> integral\<^sup>N M u = integral\<^sup>N M v"
hoelzl@56996
   893
  by (auto simp: eq_iff intro!: nn_integral_mono_AE)
hoelzl@40859
   894
hoelzl@56996
   895
lemma nn_integral_cong:
hoelzl@56996
   896
  "(\<And>x. x \<in> space M \<Longrightarrow> u x = v x) \<Longrightarrow> integral\<^sup>N M u = integral\<^sup>N M v"
hoelzl@56996
   897
  by (auto intro: nn_integral_cong_AE)
hoelzl@40859
   898
hoelzl@59426
   899
lemma nn_integral_cong_simp:
hoelzl@59426
   900
  "(\<And>x. x \<in> space M =simp=> u x = v x) \<Longrightarrow> integral\<^sup>N M u = integral\<^sup>N M v"
hoelzl@59426
   901
  by (auto intro: nn_integral_cong simp: simp_implies_def)
hoelzl@59426
   902
hoelzl@56996
   903
lemma nn_integral_cong_strong:
hoelzl@56996
   904
  "M = N \<Longrightarrow> (\<And>x. x \<in> space M \<Longrightarrow> u x = v x) \<Longrightarrow> integral\<^sup>N M u = integral\<^sup>N N v"
hoelzl@56996
   905
  by (auto intro: nn_integral_cong)
hoelzl@56993
   906
hoelzl@62975
   907
lemma incseq_nn_integral:
hoelzl@62975
   908
  assumes "incseq f" shows "incseq (\<lambda>i. integral\<^sup>N M (f i))"
hoelzl@62975
   909
proof -
hoelzl@62975
   910
  have "\<And>i x. f i x \<le> f (Suc i) x"
hoelzl@62975
   911
    using assms by (auto dest!: incseq_SucD simp: le_fun_def)
hoelzl@62975
   912
  then show ?thesis
hoelzl@62975
   913
    by (auto intro!: incseq_SucI nn_integral_mono)
hoelzl@62975
   914
qed
hoelzl@62975
   915
hoelzl@56996
   916
lemma nn_integral_eq_simple_integral:
hoelzl@62975
   917
  assumes f: "simple_function M f" shows "integral\<^sup>N M f = integral\<^sup>S M f"
hoelzl@41981
   918
proof -
wenzelm@46731
   919
  let ?f = "\<lambda>x. f x * indicator (space M) x"
hoelzl@41981
   920
  have f': "simple_function M ?f" using f by auto
hoelzl@56996
   921
  have "integral\<^sup>N M ?f \<le> integral\<^sup>S M ?f" using f'
hoelzl@56996
   922
    by (force intro!: SUP_least simple_integral_mono simp: le_fun_def nn_integral_def)
hoelzl@56996
   923
  moreover have "integral\<^sup>S M ?f \<le> integral\<^sup>N M ?f"
hoelzl@56996
   924
    unfolding nn_integral_def
hoelzl@44928
   925
    using f' by (auto intro!: SUP_upper)
hoelzl@41981
   926
  ultimately show ?thesis
hoelzl@56996
   927
    by (simp cong: nn_integral_cong simple_integral_cong)
hoelzl@41981
   928
qed
hoelzl@41981
   929
wenzelm@61808
   930
text \<open>Beppo-Levi monotone convergence theorem\<close>
hoelzl@56996
   931
lemma nn_integral_monotone_convergence_SUP:
hoelzl@62975
   932
  assumes f: "incseq f" and [measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@56996
   933
  shows "(\<integral>\<^sup>+ x. (SUP i. f i x) \<partial>M) = (SUP i. integral\<^sup>N M (f i))"
hoelzl@41981
   934
proof (rule antisym)
hoelzl@62975
   935
  show "(\<integral>\<^sup>+ x. (SUP i. f i x) \<partial>M) \<le> (SUP i. (\<integral>\<^sup>+ x. f i x \<partial>M))"
hoelzl@62975
   936
    unfolding nn_integral_def_finite[of _ "\<lambda>x. SUP i. f i x"]
hoelzl@44928
   937
  proof (safe intro!: SUP_least)
hoelzl@62975
   938
    fix u assume sf_u[simp]: "simple_function M u" and
hoelzl@62975
   939
      u: "u \<le> (\<lambda>x. SUP i. f i x)" and u_range: "\<forall>x. u x < top"
hoelzl@62975
   940
    note sf_u[THEN borel_measurable_simple_function, measurable]
hoelzl@62975
   941
    show "integral\<^sup>S M u \<le> (SUP j. \<integral>\<^sup>+x. f j x \<partial>M)"
hoelzl@62975
   942
    proof (rule ennreal_approx_unit)
hoelzl@62975
   943
      fix a :: ennreal assume "a < 1"
hoelzl@62975
   944
      let ?au = "\<lambda>x. a * u x"
hoelzl@62975
   945
hoelzl@62975
   946
      let ?B = "\<lambda>c i. {x\<in>space M. ?au x = c \<and> c \<le> f i x}"
hoelzl@62975
   947
      have "integral\<^sup>S M ?au = (\<Sum>c\<in>?au`space M. c * (SUP i. emeasure M (?B c i)))"
hoelzl@62975
   948
        unfolding simple_integral_def
nipkow@64267
   949
      proof (intro sum.cong ennreal_mult_left_cong refl)
hoelzl@62975
   950
        fix c assume "c \<in> ?au ` space M" "c \<noteq> 0"
hoelzl@62975
   951
        { fix x' assume x': "x' \<in> space M" "?au x' = c"
hoelzl@62975
   952
          with \<open>c \<noteq> 0\<close> u_range have "?au x' < 1 * u x'"
hoelzl@62975
   953
            by (intro ennreal_mult_strict_right_mono \<open>a < 1\<close>) (auto simp: less_le)
hoelzl@62975
   954
          also have "\<dots> \<le> (SUP i. f i x')"
hoelzl@62975
   955
            using u by (auto simp: le_fun_def)
hoelzl@62975
   956
          finally have "\<exists>i. ?au x' \<le> f i x'"
hoelzl@62975
   957
            by (auto simp: less_SUP_iff intro: less_imp_le) }
hoelzl@62975
   958
        then have *: "?au -` {c} \<inter> space M = (\<Union>i. ?B c i)"
hoelzl@62975
   959
          by auto
hoelzl@62975
   960
        show "emeasure M (?au -` {c} \<inter> space M) = (SUP i. emeasure M (?B c i))"
hoelzl@62975
   961
          unfolding * using f
hoelzl@62975
   962
          by (intro SUP_emeasure_incseq[symmetric])
hoelzl@62975
   963
             (auto simp: incseq_def le_fun_def intro: order_trans)
hoelzl@62975
   964
      qed
hoelzl@62975
   965
      also have "\<dots> = (SUP i. \<Sum>c\<in>?au`space M. c * emeasure M (?B c i))"
hoelzl@62975
   966
        unfolding SUP_mult_left_ennreal using f
nipkow@64267
   967
        by (intro ennreal_SUP_sum[symmetric])
hoelzl@62975
   968
           (auto intro!: mult_mono emeasure_mono simp: incseq_def le_fun_def intro: order_trans)
hoelzl@62975
   969
      also have "\<dots> \<le> (SUP i. integral\<^sup>N M (f i))"
hoelzl@62975
   970
      proof (intro SUP_subset_mono order_refl)
hoelzl@62975
   971
        fix i
hoelzl@62975
   972
        have "(\<Sum>c\<in>?au`space M. c * emeasure M (?B c i)) =
hoelzl@62975
   973
          (\<integral>\<^sup>Sx. (a * u x) * indicator {x\<in>space M. a * u x \<le> f i x} x \<partial>M)"
hoelzl@62975
   974
          by (subst simple_integral_indicator)
nipkow@64267
   975
             (auto intro!: sum.cong ennreal_mult_left_cong arg_cong2[where f=emeasure])
hoelzl@62975
   976
        also have "\<dots> = (\<integral>\<^sup>+x. (a * u x) * indicator {x\<in>space M. a * u x \<le> f i x} x \<partial>M)"
hoelzl@62975
   977
          by (rule nn_integral_eq_simple_integral[symmetric]) simp
hoelzl@62975
   978
        also have "\<dots> \<le> (\<integral>\<^sup>+x. f i x \<partial>M)"
hoelzl@62975
   979
          by (intro nn_integral_mono) (auto split: split_indicator)
hoelzl@62975
   980
        finally show "(\<Sum>c\<in>?au`space M. c * emeasure M (?B c i)) \<le> (\<integral>\<^sup>+x. f i x \<partial>M)" .
hoelzl@62975
   981
      qed
hoelzl@62975
   982
      finally show "a * integral\<^sup>S M u \<le> (SUP i. integral\<^sup>N M (f i))"
hoelzl@62975
   983
        by simp
hoelzl@62975
   984
    qed
hoelzl@35582
   985
  qed
hoelzl@62975
   986
qed (auto intro!: SUP_least SUP_upper nn_integral_mono)
hoelzl@62975
   987
hoelzl@62975
   988
lemma sup_continuous_nn_integral[order_continuous_intros]:
hoelzl@62975
   989
  assumes f: "\<And>y. sup_continuous (f y)"
hoelzl@62975
   990
  assumes [measurable]: "\<And>x. (\<lambda>y. f y x) \<in> borel_measurable M"
hoelzl@62975
   991
  shows "sup_continuous (\<lambda>x. (\<integral>\<^sup>+y. f y x \<partial>M))"
hoelzl@62975
   992
  unfolding sup_continuous_def
hoelzl@62975
   993
proof safe
hoelzl@62975
   994
  fix C :: "nat \<Rightarrow> 'b" assume C: "incseq C"
haftmann@69313
   995
  with sup_continuous_mono[OF f] show "(\<integral>\<^sup>+ y. f y (Sup (C ` UNIV)) \<partial>M) = (SUP i. \<integral>\<^sup>+ y. f y (C i) \<partial>M)"
hoelzl@62975
   996
    unfolding sup_continuousD[OF f C]
hoelzl@62975
   997
    by (subst nn_integral_monotone_convergence_SUP) (auto simp: mono_def le_fun_def)
hoelzl@35582
   998
qed
hoelzl@35582
   999
eberlm@69457
  1000
theorem nn_integral_monotone_convergence_SUP_AE:
hoelzl@62975
  1001
  assumes f: "\<And>i. AE x in M. f i x \<le> f (Suc i) x" "\<And>i. f i \<in> borel_measurable M"
hoelzl@56996
  1002
  shows "(\<integral>\<^sup>+ x. (SUP i. f i x) \<partial>M) = (SUP i. integral\<^sup>N M (f i))"
hoelzl@40859
  1003
proof -
hoelzl@62975
  1004
  from f have "AE x in M. \<forall>i. f i x \<le> f (Suc i) x"
hoelzl@41981
  1005
    by (simp add: AE_all_countable)
hoelzl@41981
  1006
  from this[THEN AE_E] guess N . note N = this
wenzelm@46731
  1007
  let ?f = "\<lambda>i x. if x \<in> space M - N then f i x else 0"
hoelzl@47694
  1008
  have f_eq: "AE x in M. \<forall>i. ?f i x = f i x" using N by (auto intro!: AE_I[of _ _ N])
wenzelm@53015
  1009
  then have "(\<integral>\<^sup>+ x. (SUP i. f i x) \<partial>M) = (\<integral>\<^sup>+ x. (SUP i. ?f i x) \<partial>M)"
hoelzl@56996
  1010
    by (auto intro!: nn_integral_cong_AE)
wenzelm@53015
  1011
  also have "\<dots> = (SUP i. (\<integral>\<^sup>+ x. ?f i x \<partial>M))"
hoelzl@56996
  1012
  proof (rule nn_integral_monotone_convergence_SUP)
hoelzl@41981
  1013
    show "incseq ?f" using N(1) by (force intro!: incseq_SucI le_funI)
hoelzl@41981
  1014
    { fix i show "(\<lambda>x. if x \<in> space M - N then f i x else 0) \<in> borel_measurable M"
hoelzl@59000
  1015
        using f N(3) by (intro measurable_If_set) auto }
hoelzl@40859
  1016
  qed
wenzelm@53015
  1017
  also have "\<dots> = (SUP i. (\<integral>\<^sup>+ x. f i x \<partial>M))"
haftmann@69313
  1018
    using f_eq by (force intro!: arg_cong[where f = "\<lambda>f. Sup (range f)"] nn_integral_cong_AE ext)
hoelzl@41981
  1019
  finally show ?thesis .
hoelzl@41981
  1020
qed
hoelzl@41981
  1021
hoelzl@56996
  1022
lemma nn_integral_monotone_convergence_simple:
hoelzl@62975
  1023
  "incseq f \<Longrightarrow> (\<And>i. simple_function M (f i)) \<Longrightarrow> (SUP i. \<integral>\<^sup>S x. f i x \<partial>M) = (\<integral>\<^sup>+x. (SUP i. f i x) \<partial>M)"
wenzelm@63092
  1024
  using nn_integral_monotone_convergence_SUP[of f M]
hoelzl@62975
  1025
  by (simp add: nn_integral_eq_simple_integral[symmetric] borel_measurable_simple_function)
hoelzl@40859
  1026
hoelzl@47694
  1027
lemma SUP_simple_integral_sequences:
hoelzl@62975
  1028
  assumes f: "incseq f" "\<And>i. simple_function M (f i)"
hoelzl@62975
  1029
  and g: "incseq g" "\<And>i. simple_function M (g i)"
hoelzl@47694
  1030
  and eq: "AE x in M. (SUP i. f i x) = (SUP i. g i x)"
wenzelm@53015
  1031
  shows "(SUP i. integral\<^sup>S M (f i)) = (SUP i. integral\<^sup>S M (g i))"
haftmann@69313
  1032
    (is "Sup (?F ` _) = Sup (?G ` _)")
hoelzl@38656
  1033
proof -
wenzelm@53015
  1034
  have "(SUP i. integral\<^sup>S M (f i)) = (\<integral>\<^sup>+x. (SUP i. f i x) \<partial>M)"
hoelzl@56996
  1035
    using f by (rule nn_integral_monotone_convergence_simple)
wenzelm@53015
  1036
  also have "\<dots> = (\<integral>\<^sup>+x. (SUP i. g i x) \<partial>M)"
hoelzl@56996
  1037
    unfolding eq[THEN nn_integral_cong_AE] ..
hoelzl@38656
  1038
  also have "\<dots> = (SUP i. ?G i)"
hoelzl@56996
  1039
    using g by (rule nn_integral_monotone_convergence_simple[symmetric])
hoelzl@41981
  1040
  finally show ?thesis by simp
hoelzl@38656
  1041
qed
hoelzl@38656
  1042
hoelzl@62975
  1043
lemma nn_integral_const[simp]: "(\<integral>\<^sup>+ x. c \<partial>M) = c * emeasure M (space M)"
hoelzl@56996
  1044
  by (subst nn_integral_eq_simple_integral) auto
hoelzl@38656
  1045
hoelzl@56996
  1046
lemma nn_integral_linear:
hoelzl@62975
  1047
  assumes f: "f \<in> borel_measurable M" and g: "g \<in> borel_measurable M"
hoelzl@56996
  1048
  shows "(\<integral>\<^sup>+ x. a * f x + g x \<partial>M) = a * integral\<^sup>N M f + integral\<^sup>N M g"
hoelzl@56996
  1049
    (is "integral\<^sup>N M ?L = _")
hoelzl@35582
  1050
proof -
hoelzl@41981
  1051
  from borel_measurable_implies_simple_function_sequence'[OF f(1)] guess u .
hoelzl@62975
  1052
  note u = nn_integral_monotone_convergence_simple[OF this(2,1)] this
hoelzl@41981
  1053
  from borel_measurable_implies_simple_function_sequence'[OF g(1)] guess v .
hoelzl@62975
  1054
  note v = nn_integral_monotone_convergence_simple[OF this(2,1)] this
wenzelm@46731
  1055
  let ?L' = "\<lambda>i x. a * u i x + v i x"
hoelzl@38656
  1056
hoelzl@41981
  1057
  have "?L \<in> borel_measurable M" using assms by auto
hoelzl@38656
  1058
  from borel_measurable_implies_simple_function_sequence'[OF this] guess l .
hoelzl@62975
  1059
  note l = nn_integral_monotone_convergence_simple[OF this(2,1)] this
hoelzl@41981
  1060
wenzelm@53015
  1061
  have inc: "incseq (\<lambda>i. a * integral\<^sup>S M (u i))" "incseq (\<lambda>i. integral\<^sup>S M (v i))"
hoelzl@62975
  1062
    using u v by (auto simp: incseq_Suc_iff le_fun_def intro!: add_mono mult_left_mono simple_integral_mono)
hoelzl@41981
  1063
wenzelm@53015
  1064
  have l': "(SUP i. integral\<^sup>S M (l i)) = (SUP i. integral\<^sup>S M (?L' i))"
hoelzl@62975
  1065
  proof (rule SUP_simple_integral_sequences[OF l(3,2)])
hoelzl@62975
  1066
    show "incseq ?L'" "\<And>i. simple_function M (?L' i)"
hoelzl@62975
  1067
      using u v unfolding incseq_Suc_iff le_fun_def
hoelzl@62975
  1068
      by (auto intro!: add_mono mult_left_mono)
hoelzl@41981
  1069
    { fix x
hoelzl@62975
  1070
      have "(SUP i. a * u i x + v i x) = a * (SUP i. u i x) + (SUP i. v i x)"
hoelzl@62975
  1071
        using u(3) v(3) u(4)[of _ x] v(4)[of _ x] unfolding SUP_mult_left_ennreal
hoelzl@62975
  1072
        by (auto intro!: ennreal_SUP_add simp: incseq_Suc_iff le_fun_def add_mono mult_left_mono) }
hoelzl@47694
  1073
    then show "AE x in M. (SUP i. l i x) = (SUP i. ?L' i x)"
hoelzl@62975
  1074
      unfolding l(5) using u(5) v(5) by (intro AE_I2) auto
hoelzl@38656
  1075
  qed
wenzelm@53015
  1076
  also have "\<dots> = (SUP i. a * integral\<^sup>S M (u i) + integral\<^sup>S M (v i))"
hoelzl@62975
  1077
    using u(2) v(2) by auto
hoelzl@62975
  1078
  finally show ?thesis
hoelzl@62975
  1079
    unfolding l(5)[symmetric] l(1)[symmetric]
hoelzl@62975
  1080
    by (simp add: ennreal_SUP_add[OF inc] v u SUP_mult_left_ennreal[symmetric])
hoelzl@38656
  1081
qed
hoelzl@38656
  1082
hoelzl@62975
  1083
lemma nn_integral_cmult: "f \<in> borel_measurable M \<Longrightarrow> (\<integral>\<^sup>+ x. c * f x \<partial>M) = c * integral\<^sup>N M f"
hoelzl@62975
  1084
  using nn_integral_linear[of f M "\<lambda>x. 0" c] by simp
hoelzl@38656
  1085
hoelzl@62975
  1086
lemma nn_integral_multc: "f \<in> borel_measurable M \<Longrightarrow> (\<integral>\<^sup>+ x. f x * c \<partial>M) = integral\<^sup>N M f * c"
wenzelm@63092
  1087
  unfolding mult.commute[of _ c] nn_integral_cmult by simp
hoelzl@41096
  1088
hoelzl@62975
  1089
lemma nn_integral_divide: "f \<in> borel_measurable M \<Longrightarrow> (\<integral>\<^sup>+ x. f x / c \<partial>M) = (\<integral>\<^sup>+ x. f x \<partial>M) / c"
hoelzl@62975
  1090
   unfolding divide_ennreal_def by (rule nn_integral_multc)
hoelzl@59000
  1091
hoelzl@62975
  1092
lemma nn_integral_indicator[simp]: "A \<in> sets M \<Longrightarrow> (\<integral>\<^sup>+ x. indicator A x\<partial>M) = (emeasure M) A"
hoelzl@62975
  1093
  by (subst nn_integral_eq_simple_integral) (auto simp: simple_integral_indicator)
hoelzl@38656
  1094
hoelzl@62975
  1095
lemma nn_integral_cmult_indicator: "A \<in> sets M \<Longrightarrow> (\<integral>\<^sup>+ x. c * indicator A x \<partial>M) = c * emeasure M A"
hoelzl@56996
  1096
  by (subst nn_integral_eq_simple_integral)
hoelzl@41544
  1097
     (auto simp: simple_function_indicator simple_integral_indicator)
hoelzl@38656
  1098
hoelzl@56996
  1099
lemma nn_integral_indicator':
hoelzl@50097
  1100
  assumes [measurable]: "A \<inter> space M \<in> sets M"
wenzelm@53015
  1101
  shows "(\<integral>\<^sup>+ x. indicator A x \<partial>M) = emeasure M (A \<inter> space M)"
hoelzl@50097
  1102
proof -
wenzelm@53015
  1103
  have "(\<integral>\<^sup>+ x. indicator A x \<partial>M) = (\<integral>\<^sup>+ x. indicator (A \<inter> space M) x \<partial>M)"
hoelzl@56996
  1104
    by (intro nn_integral_cong) (simp split: split_indicator)
hoelzl@50097
  1105
  also have "\<dots> = emeasure M (A \<inter> space M)"
hoelzl@50097
  1106
    by simp
hoelzl@50097
  1107
  finally show ?thesis .
hoelzl@50097
  1108
qed
hoelzl@50097
  1109
hoelzl@62083
  1110
lemma nn_integral_indicator_singleton[simp]:
hoelzl@62975
  1111
  assumes [measurable]: "{y} \<in> sets M" shows "(\<integral>\<^sup>+x. f x * indicator {y} x \<partial>M) = f y * emeasure M {y}"
hoelzl@62975
  1112
proof -
hoelzl@62975
  1113
  have "(\<integral>\<^sup>+x. f x * indicator {y} x \<partial>M) = (\<integral>\<^sup>+x. f y * indicator {y} x \<partial>M)"
hoelzl@62975
  1114
    by (auto intro!: nn_integral_cong split: split_indicator)
hoelzl@62083
  1115
  then show ?thesis
hoelzl@62083
  1116
    by (simp add: nn_integral_cmult)
hoelzl@62083
  1117
qed
hoelzl@62083
  1118
hoelzl@62975
  1119
lemma nn_integral_set_ennreal:
hoelzl@62975
  1120
  "(\<integral>\<^sup>+x. ennreal (f x) * indicator A x \<partial>M) = (\<integral>\<^sup>+x. ennreal (f x * indicator A x) \<partial>M)"
hoelzl@62083
  1121
  by (rule nn_integral_cong) (simp split: split_indicator)
hoelzl@62083
  1122
hoelzl@62083
  1123
lemma nn_integral_indicator_singleton'[simp]:
hoelzl@62083
  1124
  assumes [measurable]: "{y} \<in> sets M"
hoelzl@62975
  1125
  shows "(\<integral>\<^sup>+x. ennreal (f x * indicator {y} x) \<partial>M) = f y * emeasure M {y}"
hoelzl@62975
  1126
  by (subst nn_integral_set_ennreal[symmetric]) (simp add: nn_integral_indicator_singleton)
hoelzl@62083
  1127
hoelzl@56996
  1128
lemma nn_integral_add:
hoelzl@62975
  1129
  "f \<in> borel_measurable M \<Longrightarrow> g \<in> borel_measurable M \<Longrightarrow> (\<integral>\<^sup>+ x. f x + g x \<partial>M) = integral\<^sup>N M f + integral\<^sup>N M g"
hoelzl@62975
  1130
  using nn_integral_linear[of f M g 1] by simp
hoelzl@38656
  1131
nipkow@64267
  1132
lemma nn_integral_sum:
hoelzl@62975
  1133
  "(\<And>i. i \<in> P \<Longrightarrow> f i \<in> borel_measurable M) \<Longrightarrow> (\<integral>\<^sup>+ x. (\<Sum>i\<in>P. f i x) \<partial>M) = (\<Sum>i\<in>P. integral\<^sup>N M (f i))"
hoelzl@62975
  1134
  by (induction P rule: infinite_finite_induct) (auto simp: nn_integral_add)
hoelzl@62975
  1135
eberlm@69457
  1136
theorem nn_integral_suminf:
hoelzl@62975
  1137
  assumes f: "\<And>i. f i \<in> borel_measurable M"
hoelzl@62975
  1138
  shows "(\<integral>\<^sup>+ x. (\<Sum>i. f i x) \<partial>M) = (\<Sum>i. integral\<^sup>N M (f i))"
hoelzl@62975
  1139
proof -
hoelzl@62975
  1140
  have all_pos: "AE x in M. \<forall>i. 0 \<le> f i x"
hoelzl@62975
  1141
    using assms by (auto simp: AE_all_countable)
hoelzl@62975
  1142
  have "(\<Sum>i. integral\<^sup>N M (f i)) = (SUP n. \<Sum>i<n. integral\<^sup>N M (f i))"
hoelzl@62975
  1143
    by (rule suminf_eq_SUP)
hoelzl@62975
  1144
  also have "\<dots> = (SUP n. \<integral>\<^sup>+x. (\<Sum>i<n. f i x) \<partial>M)"
nipkow@64267
  1145
    unfolding nn_integral_sum[OF f] ..
hoelzl@62975
  1146
  also have "\<dots> = \<integral>\<^sup>+x. (SUP n. \<Sum>i<n. f i x) \<partial>M" using f all_pos
hoelzl@62975
  1147
    by (intro nn_integral_monotone_convergence_SUP_AE[symmetric])
lp15@65680
  1148
       (elim AE_mp, auto simp: sum_nonneg simp del: sum_lessThan_Suc intro!: AE_I2 sum_mono2)
hoelzl@62975
  1149
  also have "\<dots> = \<integral>\<^sup>+x. (\<Sum>i. f i x) \<partial>M" using all_pos
hoelzl@62975
  1150
    by (intro nn_integral_cong_AE) (auto simp: suminf_eq_SUP)
hoelzl@62975
  1151
  finally show ?thesis by simp
hoelzl@62975
  1152
qed
hoelzl@38656
  1153
hoelzl@57447
  1154
lemma nn_integral_bound_simple_function:
hoelzl@62975
  1155
  assumes bnd: "\<And>x. x \<in> space M \<Longrightarrow> f x < \<infinity>"
hoelzl@57447
  1156
  assumes f[measurable]: "simple_function M f"
hoelzl@57447
  1157
  assumes supp: "emeasure M {x\<in>space M. f x \<noteq> 0} < \<infinity>"
hoelzl@57447
  1158
  shows "nn_integral M f < \<infinity>"
hoelzl@57447
  1159
proof cases
hoelzl@57447
  1160
  assume "space M = {}"
hoelzl@57447
  1161
  then have "nn_integral M f = (\<integral>\<^sup>+x. 0 \<partial>M)"
hoelzl@57447
  1162
    by (intro nn_integral_cong) auto
hoelzl@57447
  1163
  then show ?thesis by simp
hoelzl@57447
  1164
next
hoelzl@57447
  1165
  assume "space M \<noteq> {}"
hoelzl@57447
  1166
  with simple_functionD(1)[OF f] bnd have bnd: "0 \<le> Max (f`space M) \<and> Max (f`space M) < \<infinity>"
hoelzl@57447
  1167
    by (subst Max_less_iff) (auto simp: Max_ge_iff)
lp15@61609
  1168
hoelzl@57447
  1169
  have "nn_integral M f \<le> (\<integral>\<^sup>+x. Max (f`space M) * indicator {x\<in>space M. f x \<noteq> 0} x \<partial>M)"
hoelzl@57447
  1170
  proof (rule nn_integral_mono)
hoelzl@57447
  1171
    fix x assume "x \<in> space M"
hoelzl@57447
  1172
    with f show "f x \<le> Max (f ` space M) * indicator {x \<in> space M. f x \<noteq> 0} x"
hoelzl@57447
  1173
      by (auto split: split_indicator intro!: Max_ge simple_functionD)
hoelzl@57447
  1174
  qed
hoelzl@57447
  1175
  also have "\<dots> < \<infinity>"
hoelzl@62975
  1176
    using bnd supp by (subst nn_integral_cmult) (auto simp: ennreal_mult_less_top)
hoelzl@57447
  1177
  finally show ?thesis .
hoelzl@57447
  1178
qed
hoelzl@57447
  1179
eberlm@69457
  1180
theorem nn_integral_Markov_inequality:
hoelzl@62975
  1181
  assumes u: "u \<in> borel_measurable M" and "A \<in> sets M"
wenzelm@53015
  1182
  shows "(emeasure M) ({x\<in>space M. 1 \<le> c * u x} \<inter> A) \<le> c * (\<integral>\<^sup>+ x. u x * indicator A x \<partial>M)"
hoelzl@47694
  1183
    (is "(emeasure M) ?A \<le> _ * ?PI")
hoelzl@41981
  1184
proof -
hoelzl@41981
  1185
  have "?A \<in> sets M"
wenzelm@61808
  1186
    using \<open>A \<in> sets M\<close> u by auto
wenzelm@53015
  1187
  hence "(emeasure M) ?A = (\<integral>\<^sup>+ x. indicator ?A x \<partial>M)"
hoelzl@56996
  1188
    using nn_integral_indicator by simp
hoelzl@62975
  1189
  also have "\<dots> \<le> (\<integral>\<^sup>+ x. c * (u x * indicator A x) \<partial>M)"
hoelzl@62975
  1190
    using u by (auto intro!: nn_integral_mono_AE simp: indicator_def)
wenzelm@53015
  1191
  also have "\<dots> = c * (\<integral>\<^sup>+ x. u x * indicator A x \<partial>M)"
hoelzl@62975
  1192
    using assms by (auto intro!: nn_integral_cmult)
hoelzl@41981
  1193
  finally show ?thesis .
hoelzl@41981
  1194
qed
hoelzl@41981
  1195
hoelzl@56996
  1196
lemma nn_integral_noteq_infinite:
hoelzl@62975
  1197
  assumes g: "g \<in> borel_measurable M" and "integral\<^sup>N M g \<noteq> \<infinity>"
hoelzl@47694
  1198
  shows "AE x in M. g x \<noteq> \<infinity>"
hoelzl@41981
  1199
proof (rule ccontr)
hoelzl@47694
  1200
  assume c: "\<not> (AE x in M. g x \<noteq> \<infinity>)"
hoelzl@47694
  1201
  have "(emeasure M) {x\<in>space M. g x = \<infinity>} \<noteq> 0"
hoelzl@47694
  1202
    using c g by (auto simp add: AE_iff_null)
hoelzl@62975
  1203
  then have "0 < (emeasure M) {x\<in>space M. g x = \<infinity>}"
hoelzl@62975
  1204
    by (auto simp: zero_less_iff_neq_zero)
hoelzl@62975
  1205
  then have "\<infinity> = \<infinity> * (emeasure M) {x\<in>space M. g x = \<infinity>}"
hoelzl@62975
  1206
    by (auto simp: ennreal_top_eq_mult_iff)
wenzelm@53015
  1207
  also have "\<dots> \<le> (\<integral>\<^sup>+x. \<infinity> * indicator {x\<in>space M. g x = \<infinity>} x \<partial>M)"
hoelzl@56996
  1208
    using g by (subst nn_integral_cmult_indicator) auto
hoelzl@56996
  1209
  also have "\<dots> \<le> integral\<^sup>N M g"
hoelzl@56996
  1210
    using assms by (auto intro!: nn_integral_mono_AE simp: indicator_def)
hoelzl@62975
  1211
  finally show False
hoelzl@62975
  1212
    using \<open>integral\<^sup>N M g \<noteq> \<infinity>\<close> by (auto simp: top_unique)
hoelzl@41981
  1213
qed
hoelzl@41981
  1214
hoelzl@56996
  1215
lemma nn_integral_PInf:
hoelzl@62975
  1216
  assumes f: "f \<in> borel_measurable M" and not_Inf: "integral\<^sup>N M f \<noteq> \<infinity>"
hoelzl@62975
  1217
  shows "emeasure M (f -` {\<infinity>} \<inter> space M) = 0"
hoelzl@56949
  1218
proof -
hoelzl@62975
  1219
  have "\<infinity> * emeasure M (f -` {\<infinity>} \<inter> space M) = (\<integral>\<^sup>+ x. \<infinity> * indicator (f -` {\<infinity>} \<inter> space M) x \<partial>M)"
hoelzl@56996
  1220
    using f by (subst nn_integral_cmult_indicator) (auto simp: measurable_sets)
hoelzl@62975
  1221
  also have "\<dots> \<le> integral\<^sup>N M f"
hoelzl@62975
  1222
    by (auto intro!: nn_integral_mono simp: indicator_def)
hoelzl@56996
  1223
  finally have "\<infinity> * (emeasure M) (f -` {\<infinity>} \<inter> space M) \<le> integral\<^sup>N M f"
hoelzl@62975
  1224
    by simp
hoelzl@62975
  1225
  then show ?thesis
hoelzl@62975
  1226
    using assms by (auto simp: ennreal_top_mult top_unique split: if_split_asm)
hoelzl@56949
  1227
qed
hoelzl@56949
  1228
hoelzl@62975
  1229
lemma simple_integral_PInf:
hoelzl@62975
  1230
  "simple_function M f \<Longrightarrow> integral\<^sup>S M f \<noteq> \<infinity> \<Longrightarrow> emeasure M (f -` {\<infinity>} \<inter> space M) = 0"
hoelzl@62975
  1231
  by (rule nn_integral_PInf) (auto simp: nn_integral_eq_simple_integral borel_measurable_simple_function)
hoelzl@62975
  1232
hoelzl@56996
  1233
lemma nn_integral_PInf_AE:
hoelzl@56996
  1234
  assumes "f \<in> borel_measurable M" "integral\<^sup>N M f \<noteq> \<infinity>" shows "AE x in M. f x \<noteq> \<infinity>"
hoelzl@56949
  1235
proof (rule AE_I)
hoelzl@56949
  1236
  show "(emeasure M) (f -` {\<infinity>} \<inter> space M) = 0"
hoelzl@56996
  1237
    by (rule nn_integral_PInf[OF assms])
hoelzl@56949
  1238
  show "f -` {\<infinity>} \<inter> space M \<in> sets M"
hoelzl@56949
  1239
    using assms by (auto intro: borel_measurable_vimage)
hoelzl@56949
  1240
qed auto
hoelzl@56949
  1241
hoelzl@56996
  1242
lemma nn_integral_diff:
hoelzl@41981
  1243
  assumes f: "f \<in> borel_measurable M"
hoelzl@62975
  1244
  and g: "g \<in> borel_measurable M"
hoelzl@56996
  1245
  and fin: "integral\<^sup>N M g \<noteq> \<infinity>"
hoelzl@47694
  1246
  and mono: "AE x in M. g x \<le> f x"
hoelzl@56996
  1247
  shows "(\<integral>\<^sup>+ x. f x - g x \<partial>M) = integral\<^sup>N M f - integral\<^sup>N M g"
hoelzl@38656
  1248
proof -
hoelzl@62975
  1249
  have diff: "(\<lambda>x. f x - g x) \<in> borel_measurable M"
hoelzl@62975
  1250
    using assms by auto
hoelzl@62975
  1251
  have "AE x in M. f x = f x - g x + g x"
hoelzl@62975
  1252
    using diff_add_cancel_ennreal mono nn_integral_noteq_infinite[OF g fin] assms by auto
hoelzl@56996
  1253
  then have **: "integral\<^sup>N M f = (\<integral>\<^sup>+x. f x - g x \<partial>M) + integral\<^sup>N M g"
hoelzl@56996
  1254
    unfolding nn_integral_add[OF diff g, symmetric]
hoelzl@56996
  1255
    by (rule nn_integral_cong_AE)
hoelzl@41981
  1256
  show ?thesis unfolding **
hoelzl@62975
  1257
    using fin
hoelzl@62975
  1258
    by (cases rule: ennreal2_cases[of "\<integral>\<^sup>+ x. f x - g x \<partial>M" "integral\<^sup>N M g"]) auto
hoelzl@38656
  1259
qed
hoelzl@38656
  1260
hoelzl@56996
  1261
lemma nn_integral_mult_bounded_inf:
hoelzl@62975
  1262
  assumes f: "f \<in> borel_measurable M" "(\<integral>\<^sup>+x. f x \<partial>M) < \<infinity>" and c: "c \<noteq> \<infinity>" and ae: "AE x in M. g x \<le> c * f x"
hoelzl@56993
  1263
  shows "(\<integral>\<^sup>+x. g x \<partial>M) < \<infinity>"
hoelzl@56993
  1264
proof -
hoelzl@56993
  1265
  have "(\<integral>\<^sup>+x. g x \<partial>M) \<le> (\<integral>\<^sup>+x. c * f x \<partial>M)"
hoelzl@56996
  1266
    by (intro nn_integral_mono_AE ae)
hoelzl@56993
  1267
  also have "(\<integral>\<^sup>+x. c * f x \<partial>M) < \<infinity>"
hoelzl@62975
  1268
    using c f by (subst nn_integral_cmult) (auto simp: ennreal_mult_less_top top_unique not_less)
hoelzl@56993
  1269
  finally show ?thesis .
hoelzl@56993
  1270
qed
hoelzl@56993
  1271
wenzelm@61808
  1272
text \<open>Fatou's lemma: convergence theorem on limes inferior\<close>
hoelzl@56993
  1273
hoelzl@62975
  1274
lemma nn_integral_monotone_convergence_INF_AE':
hoelzl@62975
  1275
  assumes f: "\<And>i. AE x in M. f (Suc i) x \<le> f i x" and [measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@62975
  1276
    and *: "(\<integral>\<^sup>+ x. f 0 x \<partial>M) < \<infinity>"
hoelzl@62975
  1277
  shows "(\<integral>\<^sup>+ x. (INF i. f i x) \<partial>M) = (INF i. integral\<^sup>N M (f i))"
hoelzl@62975
  1278
proof (rule ennreal_minus_cancel)
hoelzl@62975
  1279
  have "integral\<^sup>N M (f 0) - (\<integral>\<^sup>+ x. (INF i. f i x) \<partial>M) = (\<integral>\<^sup>+x. f 0 x - (INF i. f i x) \<partial>M)"
hoelzl@62975
  1280
  proof (rule nn_integral_diff[symmetric])
hoelzl@62975
  1281
    have "(\<integral>\<^sup>+ x. (INF i. f i x) \<partial>M) \<le> (\<integral>\<^sup>+ x. f 0 x \<partial>M)"
hoelzl@62975
  1282
      by (intro nn_integral_mono INF_lower) simp
hoelzl@62975
  1283
    with * show "(\<integral>\<^sup>+ x. (INF i. f i x) \<partial>M) \<noteq> \<infinity>"
hoelzl@62975
  1284
      by simp
hoelzl@62975
  1285
  qed (auto intro: INF_lower)
hoelzl@62975
  1286
  also have "\<dots> = (\<integral>\<^sup>+x. (SUP i. f 0 x - f i x) \<partial>M)"
hoelzl@62975
  1287
    by (simp add: ennreal_INF_const_minus)
hoelzl@62975
  1288
  also have "\<dots> = (SUP i. (\<integral>\<^sup>+x. f 0 x - f i x \<partial>M))"
hoelzl@62975
  1289
  proof (intro nn_integral_monotone_convergence_SUP_AE)
hoelzl@62975
  1290
    show "AE x in M. f 0 x - f i x \<le> f 0 x - f (Suc i) x" for i
hoelzl@62975
  1291
      using f[of i] by eventually_elim (auto simp: ennreal_mono_minus)
hoelzl@62975
  1292
  qed simp
hoelzl@62975
  1293
  also have "\<dots> = (SUP i. nn_integral M (f 0) - (\<integral>\<^sup>+x. f i x \<partial>M))"
hoelzl@62975
  1294
  proof (subst nn_integral_diff[symmetric])
hoelzl@62975
  1295
    fix i
hoelzl@62975
  1296
    have dec: "AE x in M. \<forall>i. f (Suc i) x \<le> f i x"
hoelzl@62975
  1297
      unfolding AE_all_countable using f by auto
hoelzl@62975
  1298
    then show "AE x in M. f i x \<le> f 0 x"
hoelzl@62975
  1299
      using dec by eventually_elim (auto intro: lift_Suc_antimono_le[of "\<lambda>i. f i x" 0 i for x])
hoelzl@62975
  1300
    then have "(\<integral>\<^sup>+ x. f i x \<partial>M) \<le> (\<integral>\<^sup>+ x. f 0 x \<partial>M)"
hoelzl@62975
  1301
      by (rule nn_integral_mono_AE)
hoelzl@62975
  1302
    with * show "(\<integral>\<^sup>+ x. f i x \<partial>M) \<noteq> \<infinity>"
hoelzl@62975
  1303
      by simp
hoelzl@62975
  1304
  qed (insert f, auto simp: decseq_def le_fun_def)
hoelzl@62975
  1305
  finally show "integral\<^sup>N M (f 0) - (\<integral>\<^sup>+ x. (INF i. f i x) \<partial>M) =
hoelzl@62975
  1306
    integral\<^sup>N M (f 0) - (INF i. \<integral>\<^sup>+ x. f i x \<partial>M)"
hoelzl@62975
  1307
    by (simp add: ennreal_INF_const_minus)
hoelzl@62975
  1308
qed (insert *, auto intro!: nn_integral_mono intro: INF_lower)
hoelzl@62975
  1309
eberlm@69457
  1310
theorem nn_integral_monotone_convergence_INF_AE:
hoelzl@62975
  1311
  fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> ennreal"
hoelzl@62975
  1312
  assumes f: "\<And>i. AE x in M. f (Suc i) x \<le> f i x"
hoelzl@62975
  1313
    and [measurable]: "\<And>i. f i \<in> borel_measurable M"
hoelzl@62975
  1314
    and fin: "(\<integral>\<^sup>+ x. f i x \<partial>M) < \<infinity>"
hoelzl@62975
  1315
  shows "(\<integral>\<^sup>+ x. (INF i. f i x) \<partial>M) = (INF i. integral\<^sup>N M (f i))"
hoelzl@38656
  1316
proof -
hoelzl@62975
  1317
  { fix f :: "nat \<Rightarrow> ennreal" and j assume "decseq f"
hoelzl@62975
  1318
    then have "(INF i. f i) = (INF i. f (i + j))"
hoelzl@62975
  1319
      apply (intro INF_eq)
hoelzl@62975
  1320
      apply (rule_tac x="i" in bexI)
hoelzl@62975
  1321
      apply (auto simp: decseq_def le_fun_def)
hoelzl@62975
  1322
      done }
hoelzl@62975
  1323
  note INF_shift = this
hoelzl@62975
  1324
  have mono: "AE x in M. \<forall>i. f (Suc i) x \<le> f i x"
hoelzl@62975
  1325
    using f by (auto simp: AE_all_countable)
hoelzl@62975
  1326
  then have "AE x in M. (INF i. f i x) = (INF n. f (n + i) x)"
hoelzl@62975
  1327
    by eventually_elim (auto intro!: decseq_SucI INF_shift)
hoelzl@62975
  1328
  then have "(\<integral>\<^sup>+ x. (INF i. f i x) \<partial>M) = (\<integral>\<^sup>+ x. (INF n. f (n + i) x) \<partial>M)"
hoelzl@62975
  1329
    by (rule nn_integral_cong_AE)
hoelzl@62975
  1330
  also have "\<dots> = (INF n. (\<integral>\<^sup>+ x. f (n + i) x \<partial>M))"
hoelzl@62975
  1331
    by (rule nn_integral_monotone_convergence_INF_AE') (insert assms, auto)
hoelzl@62975
  1332
  also have "\<dots> = (INF n. (\<integral>\<^sup>+ x. f n x \<partial>M))"
hoelzl@62975
  1333
    by (intro INF_shift[symmetric] decseq_SucI nn_integral_mono_AE f)
hoelzl@38656
  1334
  finally show ?thesis .
hoelzl@35582
  1335
qed
hoelzl@35582
  1336
hoelzl@62975
  1337
lemma nn_integral_monotone_convergence_INF_decseq:
hoelzl@62975
  1338
  assumes f: "decseq f" and *: "\<And>i. f i \<in> borel_measurable M" "(\<integral>\<^sup>+ x. f i x \<partial>M) < \<infinity>"
hoelzl@62975
  1339
  shows "(\<integral>\<^sup>+ x. (INF i. f i x) \<partial>M) = (INF i. integral\<^sup>N M (f i))"
hoelzl@62975
  1340
  using nn_integral_monotone_convergence_INF_AE[of f M i, OF _ *] f by (auto simp: decseq_Suc_iff le_fun_def)
hoelzl@56993
  1341
eberlm@69457
  1342
theorem nn_integral_liminf:
hoelzl@62975
  1343
  fixes u :: "nat \<Rightarrow> 'a \<Rightarrow> ennreal"
hoelzl@62975
  1344
  assumes u: "\<And>i. u i \<in> borel_measurable M"
hoelzl@62975
  1345
  shows "(\<integral>\<^sup>+ x. liminf (\<lambda>n. u n x) \<partial>M) \<le> liminf (\<lambda>n. integral\<^sup>N M (u n))"
hoelzl@62975
  1346
proof -
haftmann@69260
  1347
  have "(\<integral>\<^sup>+ x. liminf (\<lambda>n. u n x) \<partial>M) = (SUP n. \<integral>\<^sup>+ x. (INF i\<in>{n..}. u i x) \<partial>M)"
hoelzl@62975
  1348
    unfolding liminf_SUP_INF using u
hoelzl@62975
  1349
    by (intro nn_integral_monotone_convergence_SUP_AE)
hoelzl@62975
  1350
       (auto intro!: AE_I2 intro: INF_greatest INF_superset_mono)
hoelzl@62975
  1351
  also have "\<dots> \<le> liminf (\<lambda>n. integral\<^sup>N M (u n))"
hoelzl@62975
  1352
    by (auto simp: liminf_SUP_INF intro!: SUP_mono INF_greatest nn_integral_mono INF_lower)
hoelzl@62975
  1353
  finally show ?thesis .
hoelzl@62975
  1354
qed
hoelzl@56993
  1355
eberlm@69457
  1356
theorem nn_integral_limsup:
hoelzl@62975
  1357
  fixes u :: "nat \<Rightarrow> 'a \<Rightarrow> ennreal"
hoelzl@56993
  1358
  assumes [measurable]: "\<And>i. u i \<in> borel_measurable M" "w \<in> borel_measurable M"
hoelzl@62975
  1359
  assumes bounds: "\<And>i. AE x in M. u i x \<le> w x" and w: "(\<integral>\<^sup>+x. w x \<partial>M) < \<infinity>"
hoelzl@56996
  1360
  shows "limsup (\<lambda>n. integral\<^sup>N M (u n)) \<le> (\<integral>\<^sup>+ x. limsup (\<lambda>n. u n x) \<partial>M)"
hoelzl@56993
  1361
proof -
hoelzl@62975
  1362
  have bnd: "AE x in M. \<forall>i. u i x \<le> w x"
hoelzl@56993
  1363
    using bounds by (auto simp: AE_all_countable)
hoelzl@62975
  1364
  then have "(\<integral>\<^sup>+ x. (SUP n. u n x) \<partial>M) \<le> (\<integral>\<^sup>+ x. w x \<partial>M)"
hoelzl@62975
  1365
    by (auto intro!: nn_integral_mono_AE elim: eventually_mono intro: SUP_least)
haftmann@69260
  1366
  then have "(\<integral>\<^sup>+ x. limsup (\<lambda>n. u n x) \<partial>M) = (INF n. \<integral>\<^sup>+ x. (SUP i\<in>{n..}. u i x) \<partial>M)"
hoelzl@62975
  1367
    unfolding limsup_INF_SUP using bnd w
hoelzl@62975
  1368
    by (intro nn_integral_monotone_convergence_INF_AE')
hoelzl@62975
  1369
       (auto intro!: AE_I2 intro: SUP_least SUP_subset_mono)
hoelzl@62975
  1370
  also have "\<dots> \<ge> limsup (\<lambda>n. integral\<^sup>N M (u n))"
hoelzl@62975
  1371
    by (auto simp: limsup_INF_SUP intro!: INF_mono SUP_least exI nn_integral_mono SUP_upper)
hoelzl@62975
  1372
  finally (xtrans) show ?thesis .
hoelzl@56993
  1373
qed
hoelzl@56993
  1374
hoelzl@57025
  1375
lemma nn_integral_LIMSEQ:
hoelzl@62975
  1376
  assumes f: "incseq f" "\<And>i. f i \<in> borel_measurable M"
wenzelm@61969
  1377
    and u: "\<And>x. (\<lambda>i. f i x) \<longlonglongrightarrow> u x"
wenzelm@61969
  1378
  shows "(\<lambda>n. integral\<^sup>N M (f n)) \<longlonglongrightarrow> integral\<^sup>N M u"
hoelzl@57025
  1379
proof -
wenzelm@61969
  1380
  have "(\<lambda>n. integral\<^sup>N M (f n)) \<longlonglongrightarrow> (SUP n. integral\<^sup>N M (f n))"
hoelzl@57025
  1381
    using f by (intro LIMSEQ_SUP[of "\<lambda>n. integral\<^sup>N M (f n)"] incseq_nn_integral)
hoelzl@57025
  1382
  also have "(SUP n. integral\<^sup>N M (f n)) = integral\<^sup>N M (\<lambda>x. SUP n. f n x)"
hoelzl@57025
  1383
    using f by (intro nn_integral_monotone_convergence_SUP[symmetric])
hoelzl@57025
  1384
  also have "integral\<^sup>N M (\<lambda>x. SUP n. f n x) = integral\<^sup>N M (\<lambda>x. u x)"
hoelzl@62975
  1385
    using f by (subst LIMSEQ_SUP[THEN LIMSEQ_unique, OF _ u]) (auto simp: incseq_def le_fun_def)
hoelzl@57025
  1386
  finally show ?thesis .
hoelzl@57025
  1387
qed
hoelzl@57025
  1388
eberlm@69457
  1389
theorem nn_integral_dominated_convergence:
hoelzl@56993
  1390
  assumes [measurable]:
hoelzl@56993
  1391
       "\<And>i. u i \<in> borel_measurable M" "u' \<in> borel_measurable M" "w \<in> borel_measurable M"
hoelzl@62975
  1392
    and bound: "\<And>j. AE x in M. u j x \<le> w x"
hoelzl@56993
  1393
    and w: "(\<integral>\<^sup>+x. w x \<partial>M) < \<infinity>"
wenzelm@61969
  1394
    and u': "AE x in M. (\<lambda>i. u i x) \<longlonglongrightarrow> u' x"
wenzelm@61969
  1395
  shows "(\<lambda>i. (\<integral>\<^sup>+x. u i x \<partial>M)) \<longlonglongrightarrow> (\<integral>\<^sup>+x. u' x \<partial>M)"
hoelzl@56993
  1396
proof -
hoelzl@56996
  1397
  have "limsup (\<lambda>n. integral\<^sup>N M (u n)) \<le> (\<integral>\<^sup>+ x. limsup (\<lambda>n. u n x) \<partial>M)"
hoelzl@56996
  1398
    by (intro nn_integral_limsup[OF _ _ bound w]) auto
hoelzl@56993
  1399
  moreover have "(\<integral>\<^sup>+ x. limsup (\<lambda>n. u n x) \<partial>M) = (\<integral>\<^sup>+ x. u' x \<partial>M)"
hoelzl@56996
  1400
    using u' by (intro nn_integral_cong_AE, eventually_elim) (metis tendsto_iff_Liminf_eq_Limsup sequentially_bot)
hoelzl@56993
  1401
  moreover have "(\<integral>\<^sup>+ x. liminf (\<lambda>n. u n x) \<partial>M) = (\<integral>\<^sup>+ x. u' x \<partial>M)"
hoelzl@56996
  1402
    using u' by (intro nn_integral_cong_AE, eventually_elim) (metis tendsto_iff_Liminf_eq_Limsup sequentially_bot)
hoelzl@56996
  1403
  moreover have "(\<integral>\<^sup>+x. liminf (\<lambda>n. u n x) \<partial>M) \<le> liminf (\<lambda>n. integral\<^sup>N M (u n))"
hoelzl@62975
  1404
    by (intro nn_integral_liminf) auto
hoelzl@56996
  1405
  moreover have "liminf (\<lambda>n. integral\<^sup>N M (u n)) \<le> limsup (\<lambda>n. integral\<^sup>N M (u n))"
hoelzl@56993
  1406
    by (intro Liminf_le_Limsup sequentially_bot)
hoelzl@56993
  1407
  ultimately show ?thesis
hoelzl@56993
  1408
    by (intro Liminf_eq_Limsup) auto
hoelzl@56993
  1409
qed
hoelzl@56993
  1410
hoelzl@60636
  1411
lemma inf_continuous_nn_integral[order_continuous_intros]:
hoelzl@60175
  1412
  assumes f: "\<And>y. inf_continuous (f y)"
hoelzl@60614
  1413
  assumes [measurable]: "\<And>x. (\<lambda>y. f y x) \<in> borel_measurable M"
hoelzl@60614
  1414
  assumes bnd: "\<And>x. (\<integral>\<^sup>+ y. f y x \<partial>M) \<noteq> \<infinity>"
hoelzl@60614
  1415
  shows "inf_continuous (\<lambda>x. (\<integral>\<^sup>+y. f y x \<partial>M))"
hoelzl@60175
  1416
  unfolding inf_continuous_def
hoelzl@60175
  1417
proof safe
hoelzl@60614
  1418
  fix C :: "nat \<Rightarrow> 'b" assume C: "decseq C"
haftmann@69313
  1419
  then show "(\<integral>\<^sup>+ y. f y (Inf (C ` UNIV)) \<partial>M) = (INF i. \<integral>\<^sup>+ y. f y (C i) \<partial>M)"
hoelzl@62975
  1420
    using inf_continuous_mono[OF f] bnd
hoelzl@62975
  1421
    by (auto simp add: inf_continuousD[OF f C] fun_eq_iff antimono_def mono_def le_fun_def less_top
hoelzl@62975
  1422
             intro!: nn_integral_monotone_convergence_INF_decseq)
hoelzl@60175
  1423
qed
hoelzl@60175
  1424
hoelzl@56996
  1425
lemma nn_integral_null_set:
wenzelm@53015
  1426
  assumes "N \<in> null_sets M" shows "(\<integral>\<^sup>+ x. u x * indicator N x \<partial>M) = 0"
hoelzl@38656
  1427
proof -
wenzelm@53015
  1428
  have "(\<integral>\<^sup>+ x. u x * indicator N x \<partial>M) = (\<integral>\<^sup>+ x. 0 \<partial>M)"
hoelzl@56996
  1429
  proof (intro nn_integral_cong_AE AE_I)
hoelzl@40859
  1430
    show "{x \<in> space M. u x * indicator N x \<noteq> 0} \<subseteq> N"
hoelzl@40859
  1431
      by (auto simp: indicator_def)
hoelzl@47694
  1432
    show "(emeasure M) N = 0" "N \<in> sets M"
hoelzl@40859
  1433
      using assms by auto
hoelzl@35582
  1434
  qed
hoelzl@40859
  1435
  then show ?thesis by simp
hoelzl@38656
  1436
qed
hoelzl@35582
  1437
hoelzl@56996
  1438
lemma nn_integral_0_iff:
hoelzl@62975
  1439
  assumes u: "u \<in> borel_measurable M"
hoelzl@56996
  1440
  shows "integral\<^sup>N M u = 0 \<longleftrightarrow> emeasure M {x\<in>space M. u x \<noteq> 0} = 0"
hoelzl@47694
  1441
    (is "_ \<longleftrightarrow> (emeasure M) ?A = 0")
hoelzl@35582
  1442
proof -
hoelzl@56996
  1443
  have u_eq: "(\<integral>\<^sup>+ x. u x * indicator ?A x \<partial>M) = integral\<^sup>N M u"
hoelzl@56996
  1444
    by (auto intro!: nn_integral_cong simp: indicator_def)
hoelzl@38656
  1445
  show ?thesis
hoelzl@38656
  1446
  proof
hoelzl@47694
  1447
    assume "(emeasure M) ?A = 0"
hoelzl@56996
  1448
    with nn_integral_null_set[of ?A M u] u
hoelzl@56996
  1449
    show "integral\<^sup>N M u = 0" by (simp add: u_eq null_sets_def)
hoelzl@38656
  1450
  next
hoelzl@56996
  1451
    assume *: "integral\<^sup>N M u = 0"
wenzelm@46731
  1452
    let ?M = "\<lambda>n. {x \<in> space M. 1 \<le> real (n::nat) * u x}"
hoelzl@47694
  1453
    have "0 = (SUP n. (emeasure M) (?M n \<inter> ?A))"
hoelzl@38656
  1454
    proof -
hoelzl@41981
  1455
      { fix n :: nat
hoelzl@62975
  1456
        from nn_integral_Markov_inequality[OF u, of ?A "of_nat n"] u
hoelzl@62975
  1457
        have "(emeasure M) (?M n \<inter> ?A) \<le> 0"
hoelzl@62975
  1458
          by (simp add: ennreal_of_nat_eq_real_of_nat u_eq *)
hoelzl@47694
  1459
        moreover have "0 \<le> (emeasure M) (?M n \<inter> ?A)" using u by auto
hoelzl@47694
  1460
        ultimately have "(emeasure M) (?M n \<inter> ?A) = 0" by auto }
hoelzl@38656
  1461
      thus ?thesis by simp
hoelzl@35582
  1462
    qed
hoelzl@47694
  1463
    also have "\<dots> = (emeasure M) (\<Union>n. ?M n \<inter> ?A)"
hoelzl@47694
  1464
    proof (safe intro!: SUP_emeasure_incseq)
hoelzl@38656
  1465
      fix n show "?M n \<inter> ?A \<in> sets M"
immler@50244
  1466
        using u by (auto intro!: sets.Int)
hoelzl@38656
  1467
    next
hoelzl@41981
  1468
      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
  1469
      proof (safe intro!: incseq_SucI)
hoelzl@41981
  1470
        fix n :: nat and x
hoelzl@41981
  1471
        assume *: "1 \<le> real n * u x"
hoelzl@62975
  1472
        also have "real n * u x \<le> real (Suc n) * u x"
hoelzl@62975
  1473
          by (auto intro!: mult_right_mono)
hoelzl@41981
  1474
        finally show "1 \<le> real (Suc n) * u x" by auto
hoelzl@41981
  1475
      qed
hoelzl@38656
  1476
    qed
hoelzl@47694
  1477
    also have "\<dots> = (emeasure M) {x\<in>space M. 0 < u x}"
hoelzl@62975
  1478
    proof (safe intro!: arg_cong[where f="(emeasure M)"])
hoelzl@41981
  1479
      fix x assume "0 < u x" and [simp, intro]: "x \<in> space M"
hoelzl@38656
  1480
      show "x \<in> (\<Union>n. ?M n \<inter> ?A)"
hoelzl@62975
  1481
      proof (cases "u x" rule: ennreal_cases)
wenzelm@61808
  1482
        case (real r) with \<open>0 < u x\<close> have "0 < r" by auto
hoelzl@41981
  1483
        obtain j :: nat where "1 / r \<le> real j" using real_arch_simple ..
wenzelm@61808
  1484
        hence "1 / r * r \<le> real j * r" unfolding mult_le_cancel_right using \<open>0 < r\<close> by auto
wenzelm@61808
  1485
        hence "1 \<le> real j * r" using real \<open>0 < r\<close> by auto
hoelzl@62975
  1486
        thus ?thesis using \<open>0 < r\<close> real
hoelzl@62975
  1487
          by (auto simp: ennreal_of_nat_eq_real_of_nat ennreal_1[symmetric] ennreal_mult[symmetric]
hoelzl@62975
  1488
                   simp del: ennreal_1)
hoelzl@62975
  1489
      qed (insert \<open>0 < u x\<close>, auto simp: ennreal_mult_top)
hoelzl@62975
  1490
    qed (auto simp: zero_less_iff_neq_zero)
hoelzl@62975
  1491
    finally show "emeasure M ?A = 0"
hoelzl@62975
  1492
      by (simp add: zero_less_iff_neq_zero)
hoelzl@35582
  1493
  qed
hoelzl@35582
  1494
qed
hoelzl@35582
  1495
hoelzl@56996
  1496
lemma nn_integral_0_iff_AE:
hoelzl@41705
  1497
  assumes u: "u \<in> borel_measurable M"
hoelzl@62975
  1498
  shows "integral\<^sup>N M u = 0 \<longleftrightarrow> (AE x in M. u x = 0)"
hoelzl@41705
  1499
proof -
hoelzl@62975
  1500
  have sets: "{x\<in>space M. u x \<noteq> 0} \<in> sets M"
hoelzl@41705
  1501
    using u by auto
hoelzl@62975
  1502
  show "integral\<^sup>N M u = 0 \<longleftrightarrow> (AE x in M. u x = 0)"
hoelzl@62975
  1503
    using nn_integral_0_iff[of u] AE_iff_null[OF sets] u by auto
hoelzl@41705
  1504
qed
hoelzl@41705
  1505
lp15@61609
  1506
lemma AE_iff_nn_integral:
hoelzl@56996
  1507
  "{x\<in>space M. P x} \<in> sets M \<Longrightarrow> (AE x in M. P x) \<longleftrightarrow> integral\<^sup>N M (indicator {x. \<not> P x}) = 0"
hoelzl@62975
  1508
  by (subst nn_integral_0_iff_AE) (auto simp: indicator_def[abs_def])
hoelzl@50001
  1509
hoelzl@59000
  1510
lemma nn_integral_less:
hoelzl@59000
  1511
  assumes [measurable]: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
hoelzl@62975
  1512
  assumes f: "(\<integral>\<^sup>+x. f x \<partial>M) \<noteq> \<infinity>"
hoelzl@59000
  1513
  assumes ord: "AE x in M. f x \<le> g x" "\<not> (AE x in M. g x \<le> f x)"
hoelzl@59000
  1514
  shows "(\<integral>\<^sup>+x. f x \<partial>M) < (\<integral>\<^sup>+x. g x \<partial>M)"
hoelzl@59000
  1515
proof -
hoelzl@59000
  1516
  have "0 < (\<integral>\<^sup>+x. g x - f x \<partial>M)"
hoelzl@62975
  1517
  proof (intro order_le_neq_trans notI)
hoelzl@59000
  1518
    assume "0 = (\<integral>\<^sup>+x. g x - f x \<partial>M)"
hoelzl@62975
  1519
    then have "AE x in M. g x - f x = 0"
hoelzl@59000
  1520
      using nn_integral_0_iff_AE[of "\<lambda>x. g x - f x" M] by simp
hoelzl@62975
  1521
    with ord(1) have "AE x in M. g x \<le> f x"
hoelzl@62975
  1522
      by eventually_elim (auto simp: ennreal_minus_eq_0)
hoelzl@59000
  1523
    with ord show False
hoelzl@59000
  1524
      by simp
hoelzl@62975
  1525
  qed simp
hoelzl@59000
  1526
  also have "\<dots> = (\<integral>\<^sup>+x. g x \<partial>M) - (\<integral>\<^sup>+x. f x \<partial>M)"
hoelzl@62975
  1527
    using f by (subst nn_integral_diff) (auto simp: ord)
hoelzl@59000
  1528
  finally show ?thesis
hoelzl@62975
  1529
    using f by (auto dest!: ennreal_minus_pos_iff[rotated] simp: less_top)
hoelzl@59000
  1530
qed
hoelzl@59000
  1531
hoelzl@56996
  1532
lemma nn_integral_subalgebra:
hoelzl@62975
  1533
  assumes f: "f \<in> borel_measurable N"
hoelzl@47694
  1534
  and N: "sets N \<subseteq> sets M" "space N = space M" "\<And>A. A \<in> sets N \<Longrightarrow> emeasure N A = emeasure M A"
hoelzl@56996
  1535
  shows "integral\<^sup>N N f = integral\<^sup>N M f"
hoelzl@39092
  1536
proof -
hoelzl@62975
  1537
  have [simp]: "\<And>f :: 'a \<Rightarrow> ennreal. f \<in> borel_measurable N \<Longrightarrow> f \<in> borel_measurable M"
hoelzl@49799
  1538
    using N by (auto simp: measurable_def)
hoelzl@49799
  1539
  have [simp]: "\<And>P. (AE x in N. P x) \<Longrightarrow> (AE x in M. P x)"
hoelzl@62975
  1540
    using N by (auto simp add: eventually_ae_filter null_sets_def subset_eq)
hoelzl@49799
  1541
  have [simp]: "\<And>A. A \<in> sets N \<Longrightarrow> A \<in> sets M"
hoelzl@49799
  1542
    using N by auto
hoelzl@49799
  1543
  from f show ?thesis
hoelzl@49799
  1544
    apply induct
hoelzl@56996
  1545
    apply (simp_all add: nn_integral_add nn_integral_cmult nn_integral_monotone_convergence_SUP N)
hoelzl@56996
  1546
    apply (auto intro!: nn_integral_cong cong: nn_integral_cong simp: N(2)[symmetric])
hoelzl@49799
  1547
    done
hoelzl@39092
  1548
qed
hoelzl@39092
  1549
hoelzl@56996
  1550
lemma nn_integral_nat_function:
hoelzl@50097
  1551
  fixes f :: "'a \<Rightarrow> nat"
hoelzl@50097
  1552
  assumes "f \<in> measurable M (count_space UNIV)"
hoelzl@62975
  1553
  shows "(\<integral>\<^sup>+x. of_nat (f x) \<partial>M) = (\<Sum>t. emeasure M {x\<in>space M. t < f x})"
hoelzl@50097
  1554
proof -
wenzelm@63040
  1555
  define F where "F i = {x\<in>space M. i < f x}" for i
hoelzl@50097
  1556
  with assms have [measurable]: "\<And>i. F i \<in> sets M"
hoelzl@50097
  1557
    by auto
hoelzl@50097
  1558
hoelzl@50097
  1559
  { fix x assume "x \<in> space M"
hoelzl@50097
  1560
    have "(\<lambda>i. if i < f x then 1 else 0) sums (of_nat (f x)::real)"
hoelzl@50097
  1561
      using sums_If_finite[of "\<lambda>i. i < f x" "\<lambda>_. 1::real"] by simp
hoelzl@62975
  1562
    then have "(\<lambda>i. ennreal (if i < f x then 1 else 0)) sums of_nat(f x)"
hoelzl@62975
  1563
      unfolding ennreal_of_nat_eq_real_of_nat
hoelzl@62975
  1564
      by (subst sums_ennreal) auto
hoelzl@62975
  1565
    moreover have "\<And>i. ennreal (if i < f x then 1 else 0) = indicator (F i) x"
hoelzl@62975
  1566
      using \<open>x \<in> space M\<close> by (simp add: one_ennreal_def F_def)
hoelzl@62975
  1567
    ultimately have "of_nat (f x) = (\<Sum>i. indicator (F i) x :: ennreal)"
hoelzl@50097
  1568
      by (simp add: sums_iff) }
hoelzl@62975
  1569
  then have "(\<integral>\<^sup>+x. of_nat (f x) \<partial>M) = (\<integral>\<^sup>+x. (\<Sum>i. indicator (F i) x) \<partial>M)"
hoelzl@56996
  1570
    by (simp cong: nn_integral_cong)
hoelzl@50097
  1571
  also have "\<dots> = (\<Sum>i. emeasure M (F i))"
hoelzl@56996
  1572
    by (simp add: nn_integral_suminf)
hoelzl@50097
  1573
  finally show ?thesis
hoelzl@50097
  1574
    by (simp add: F_def)
hoelzl@50097
  1575
qed
hoelzl@50097
  1576
eberlm@69457
  1577
theorem nn_integral_lfp:
hoelzl@60636
  1578
  assumes sets[simp]: "\<And>s. sets (M s) = sets N"
hoelzl@60175
  1579
  assumes f: "sup_continuous f"
hoelzl@60636
  1580
  assumes g: "sup_continuous g"
hoelzl@60175
  1581
  assumes meas: "\<And>F. F \<in> borel_measurable N \<Longrightarrow> f F \<in> borel_measurable N"
hoelzl@60175
  1582
  assumes step: "\<And>F s. F \<in> borel_measurable N \<Longrightarrow> integral\<^sup>N (M s) (f F) = g (\<lambda>s. integral\<^sup>N (M s) F) s"
hoelzl@60175
  1583
  shows "(\<integral>\<^sup>+\<omega>. lfp f \<omega> \<partial>M s) = lfp g s"
hoelzl@60636
  1584
proof (subst lfp_transfer_bounded[where \<alpha>="\<lambda>F s. \<integral>\<^sup>+x. F x \<partial>M s" and g=g and f=f and P="\<lambda>f. f \<in> borel_measurable N", symmetric])
hoelzl@62975
  1585
  fix C :: "nat \<Rightarrow> 'b \<Rightarrow> ennreal" assume "incseq C" "\<And>i. C i \<in> borel_measurable N"
hoelzl@60636
  1586
  then show "(\<lambda>s. \<integral>\<^sup>+x. (SUP i. C i) x \<partial>M s) = (SUP i. (\<lambda>s. \<integral>\<^sup>+x. C i x \<partial>M s))"
hoelzl@60636
  1587
    unfolding SUP_apply[abs_def]
hoelzl@60636
  1588
    by (subst nn_integral_monotone_convergence_SUP)
hoelzl@60636
  1589
       (auto simp: mono_def fun_eq_iff intro!: arg_cong2[where f=emeasure] cong: measurable_cong_sets)
hoelzl@62975
  1590
qed (auto simp add: step le_fun_def SUP_apply[abs_def] bot_fun_def bot_ennreal intro!: meas f g)
hoelzl@60175
  1591
eberlm@69457
  1592
theorem nn_integral_gfp:
hoelzl@60636
  1593
  assumes sets[simp]: "\<And>s. sets (M s) = sets N"
hoelzl@60636
  1594
  assumes f: "inf_continuous f" and g: "inf_continuous g"
hoelzl@60175
  1595
  assumes meas: "\<And>F. F \<in> borel_measurable N \<Longrightarrow> f F \<in> borel_measurable N"
hoelzl@60636
  1596
  assumes bound: "\<And>F s. F \<in> borel_measurable N \<Longrightarrow> (\<integral>\<^sup>+x. f F x \<partial>M s) < \<infinity>"
hoelzl@60175
  1597
  assumes non_zero: "\<And>s. emeasure (M s) (space (M s)) \<noteq> 0"
hoelzl@60175
  1598
  assumes step: "\<And>F s. F \<in> borel_measurable N \<Longrightarrow> integral\<^sup>N (M s) (f F) = g (\<lambda>s. integral\<^sup>N (M s) F) s"
hoelzl@60175
  1599
  shows "(\<integral>\<^sup>+\<omega>. gfp f \<omega> \<partial>M s) = gfp g s"
hoelzl@60636
  1600
proof (subst gfp_transfer_bounded[where \<alpha>="\<lambda>F s. \<integral>\<^sup>+x. F x \<partial>M s" and g=g and f=f
hoelzl@60636
  1601
    and P="\<lambda>F. F \<in> borel_measurable N \<and> (\<forall>s. (\<integral>\<^sup>+x. F x \<partial>M s) < \<infinity>)", symmetric])
hoelzl@62975
  1602
  fix C :: "nat \<Rightarrow> 'b \<Rightarrow> ennreal" assume "decseq C" "\<And>i. C i \<in> borel_measurable N \<and> (\<forall>s. integral\<^sup>N (M s) (C i) < \<infinity>)"
hoelzl@60636
  1603
  then show "(\<lambda>s. \<integral>\<^sup>+x. (INF i. C i) x \<partial>M s) = (INF i. (\<lambda>s. \<integral>\<^sup>+x. C i x \<partial>M s))"
hoelzl@60636
  1604
    unfolding INF_apply[abs_def]
hoelzl@61359
  1605
    by (subst nn_integral_monotone_convergence_INF_decseq)
hoelzl@60636
  1606
       (auto simp: mono_def fun_eq_iff intro!: arg_cong2[where f=emeasure] cong: measurable_cong_sets)
hoelzl@60636
  1607
next
hoelzl@60636
  1608
  show "\<And>x. g x \<le> (\<lambda>s. integral\<^sup>N (M s) (f top))"
hoelzl@60636
  1609
    by (subst step)
hoelzl@62975
  1610
       (auto simp add: top_fun_def less_le non_zero le_fun_def ennreal_top_mult
wenzelm@63566
  1611
             cong del: if_weak_cong intro!: monoD[OF inf_continuous_mono[OF g], THEN le_funD])
hoelzl@60636
  1612
next
hoelzl@60636
  1613
  fix C assume "\<And>i::nat. C i \<in> borel_measurable N \<and> (\<forall>s. integral\<^sup>N (M s) (C i) < \<infinity>)" "decseq C"
haftmann@69313
  1614
  with bound show "Inf (C ` UNIV) \<in> borel_measurable N \<and> (\<forall>s. integral\<^sup>N (M s) (Inf (C ` UNIV)) < \<infinity>)"
hoelzl@60636
  1615
    unfolding INF_apply[abs_def]
hoelzl@61359
  1616
    by (subst nn_integral_monotone_convergence_INF_decseq)
hoelzl@62975
  1617
       (auto simp: INF_less_iff cong: measurable_cong_sets intro!: borel_measurable_INF)
hoelzl@60636
  1618
next
hoelzl@60636
  1619
  show "\<And>x. x \<in> borel_measurable N \<and> (\<forall>s. integral\<^sup>N (M s) x < \<infinity>) \<Longrightarrow>
hoelzl@60636
  1620
         (\<lambda>s. integral\<^sup>N (M s) (f x)) = g (\<lambda>s. integral\<^sup>N (M s) x)"
hoelzl@60636
  1621
    by (subst step) auto
hoelzl@60636
  1622
qed (insert bound, auto simp add: le_fun_def INF_apply[abs_def] top_fun_def intro!: meas f g)
hoelzl@60175
  1623
eberlm@69457
  1624
(* TODO: rename? *)
wenzelm@61808
  1625
subsection \<open>Integral under concrete measures\<close>
hoelzl@56994
  1626
hoelzl@63333
  1627
lemma nn_integral_mono_measure:
hoelzl@63333
  1628
  assumes "sets M = sets N" "M \<le> N" shows "nn_integral M f \<le> nn_integral N f"
hoelzl@63333
  1629
  unfolding nn_integral_def
hoelzl@63333
  1630
proof (intro SUP_subset_mono)
hoelzl@63333
  1631
  note \<open>sets M = sets N\<close>[simp]  \<open>sets M = sets N\<close>[THEN sets_eq_imp_space_eq, simp]
hoelzl@63333
  1632
  show "{g. simple_function M g \<and> g \<le> f} \<subseteq> {g. simple_function N g \<and> g \<le> f}"
hoelzl@63333
  1633
    by (simp add: simple_function_def)
hoelzl@63333
  1634
  show "integral\<^sup>S M x \<le> integral\<^sup>S N x" for x
hoelzl@63333
  1635
    using le_measureD3[OF \<open>M \<le> N\<close>]
nipkow@64267
  1636
    by (auto simp add: simple_integral_def intro!: sum_mono mult_mono)
hoelzl@63333
  1637
qed
hoelzl@63333
  1638
lp15@61609
  1639
lemma nn_integral_empty:
Andreas@60064
  1640
  assumes "space M = {}"
Andreas@60064
  1641
  shows "nn_integral M f = 0"
Andreas@60064
  1642
proof -
Andreas@60064
  1643
  have "(\<integral>\<^sup>+ x. f x \<partial>M) = (\<integral>\<^sup>+ x. 0 \<partial>M)"
Andreas@60064
  1644
    by(rule nn_integral_cong)(simp add: assms)
Andreas@60064
  1645
  thus ?thesis by simp
Andreas@60064
  1646
qed
Andreas@60064
  1647
hoelzl@63333
  1648
lemma nn_integral_bot[simp]: "nn_integral bot f = 0"
hoelzl@63333
  1649
  by (simp add: nn_integral_empty)
hoelzl@63333
  1650
eberlm@69457
  1651
subsubsection%unimportant \<open>Distributions\<close>
hoelzl@47694
  1652
hoelzl@62975
  1653
lemma nn_integral_distr:
hoelzl@62975
  1654
  assumes T: "T \<in> measurable M M'" and f: "f \<in> borel_measurable (distr M M' T)"
hoelzl@56996
  1655
  shows "integral\<^sup>N (distr M M' T) f = (\<integral>\<^sup>+ x. f (T x) \<partial>M)"
lp15@61609
  1656
  using f
hoelzl@49797
  1657
proof induct
hoelzl@49797
  1658
  case (cong f g)
hoelzl@49799
  1659
  with T show ?case
hoelzl@56996
  1660
    apply (subst nn_integral_cong[of _ f g])
hoelzl@49799
  1661
    apply simp
hoelzl@56996
  1662
    apply (subst nn_integral_cong[of _ "\<lambda>x. f (T x)" "\<lambda>x. g (T x)"])
hoelzl@49799
  1663
    apply (simp add: measurable_def Pi_iff)
hoelzl@49799
  1664
    apply simp
hoelzl@49797
  1665
    done
hoelzl@49797
  1666
next
hoelzl@49797
  1667
  case (set A)
hoelzl@49797
  1668
  then have eq: "\<And>x. x \<in> space M \<Longrightarrow> indicator A (T x) = indicator (T -` A \<inter> space M) x"
hoelzl@49797
  1669
    by (auto simp: indicator_def)
hoelzl@49797
  1670
  from set T show ?case
hoelzl@56996
  1671
    by (subst nn_integral_cong[OF eq])
hoelzl@56996
  1672
       (auto simp add: emeasure_distr intro!: nn_integral_indicator[symmetric] measurable_sets)
hoelzl@56996
  1673
qed (simp_all add: measurable_compose[OF T] T nn_integral_cmult nn_integral_add
hoelzl@56996
  1674
                   nn_integral_monotone_convergence_SUP le_fun_def incseq_def)
hoelzl@47694
  1675
eberlm@69457
  1676
subsubsection%unimportant \<open>Counting space\<close>
hoelzl@47694
  1677
hoelzl@47694
  1678
lemma simple_function_count_space[simp]:
hoelzl@47694
  1679
  "simple_function (count_space A) f \<longleftrightarrow> finite (f ` A)"
hoelzl@47694
  1680
  unfolding simple_function_def by simp
hoelzl@47694
  1681
hoelzl@56996
  1682
lemma nn_integral_count_space:
hoelzl@47694
  1683
  assumes A: "finite {a\<in>A. 0 < f a}"
hoelzl@56996
  1684
  shows "integral\<^sup>N (count_space A) f = (\<Sum>a|a\<in>A \<and> 0 < f a. f a)"
hoelzl@35582
  1685
proof -
wenzelm@53015
  1686
  have *: "(\<integral>\<^sup>+x. max 0 (f x) \<partial>count_space A) =
wenzelm@53015
  1687
    (\<integral>\<^sup>+ x. (\<Sum>a|a\<in>A \<and> 0 < f a. f a * indicator {a} x) \<partial>count_space A)"
hoelzl@56996
  1688
    by (auto intro!: nn_integral_cong
nipkow@64267
  1689
             simp add: indicator_def if_distrib sum.If_cases[OF A] max_def le_less)
wenzelm@53015
  1690
  also have "\<dots> = (\<Sum>a|a\<in>A \<and> 0 < f a. \<integral>\<^sup>+ x. f a * indicator {a} x \<partial>count_space A)"
nipkow@64267
  1691
    by (subst nn_integral_sum) (simp_all add: AE_count_space  less_imp_le)
hoelzl@47694
  1692
  also have "\<dots> = (\<Sum>a|a\<in>A \<and> 0 < f a. f a)"
nipkow@64267
  1693
    by (auto intro!: sum.cong simp: one_ennreal_def[symmetric] max_def)
hoelzl@62975
  1694
  finally show ?thesis by (simp add: max.absorb2)
hoelzl@47694
  1695
qed
hoelzl@47694
  1696
hoelzl@56996
  1697
lemma nn_integral_count_space_finite:
hoelzl@62975
  1698
    "finite A \<Longrightarrow> (\<integral>\<^sup>+x. f x \<partial>count_space A) = (\<Sum>a\<in>A. f a)"
nipkow@64267
  1699
  by (auto intro!: sum.mono_neutral_left simp: nn_integral_count_space less_le)
hoelzl@47694
  1700
hoelzl@59000
  1701
lemma nn_integral_count_space':
hoelzl@62975
  1702
  assumes "finite A" "\<And>x. x \<in> B \<Longrightarrow> x \<notin> A \<Longrightarrow> f x = 0" "A \<subseteq> B"
hoelzl@59000
  1703
  shows "(\<integral>\<^sup>+x. f x \<partial>count_space B) = (\<Sum>x\<in>A. f x)"
hoelzl@59000
  1704
proof -
hoelzl@59000
  1705
  have "(\<integral>\<^sup>+x. f x \<partial>count_space B) = (\<Sum>a | a \<in> B \<and> 0 < f a. f a)"
hoelzl@59000
  1706
    using assms(2,3)
wenzelm@61808
  1707
    by (intro nn_integral_count_space finite_subset[OF _ \<open>finite A\<close>]) (auto simp: less_le)
hoelzl@59000
  1708
  also have "\<dots> = (\<Sum>a\<in>A. f a)"
nipkow@64267
  1709
    using assms by (intro sum.mono_neutral_cong_left) (auto simp: less_le)
hoelzl@59000
  1710
  finally show ?thesis .
hoelzl@59000
  1711
qed
hoelzl@59000
  1712
hoelzl@59011
  1713
lemma nn_integral_bij_count_space:
hoelzl@59011
  1714
  assumes g: "bij_betw g A B"
hoelzl@59011
  1715
  shows "(\<integral>\<^sup>+x. f (g x) \<partial>count_space A) = (\<integral>\<^sup>+x. f x \<partial>count_space B)"
hoelzl@59011
  1716
  using g[THEN bij_betw_imp_funcset]
hoelzl@59011
  1717
  by (subst distr_bij_count_space[OF g, symmetric])
hoelzl@59011
  1718
     (auto intro!: nn_integral_distr[symmetric])
hoelzl@59011
  1719
hoelzl@59000
  1720
lemma nn_integral_indicator_finite:
hoelzl@62975
  1721
  fixes f :: "'a \<Rightarrow> ennreal"
hoelzl@62975
  1722
  assumes f: "finite A" and [measurable]: "\<And>a. a \<in> A \<Longrightarrow> {a} \<in> sets M"
hoelzl@59000
  1723
  shows "(\<integral>\<^sup>+x. f x * indicator A x \<partial>M) = (\<Sum>x\<in>A. f x * emeasure M {x})"
hoelzl@59000
  1724
proof -
hoelzl@59000
  1725
  from f have "(\<integral>\<^sup>+x. f x * indicator A x \<partial>M) = (\<integral>\<^sup>+x. (\<Sum>a\<in>A. f a * indicator {a} x) \<partial>M)"
nipkow@64267
  1726
    by (intro nn_integral_cong) (auto simp: indicator_def if_distrib[where f="\<lambda>a. x * a" for x] sum.If_cases)
hoelzl@59000
  1727
  also have "\<dots> = (\<Sum>a\<in>A. f a * emeasure M {a})"
nipkow@64267
  1728
    by (subst nn_integral_sum) auto
hoelzl@59000
  1729
  finally show ?thesis .
hoelzl@59000
  1730
qed
hoelzl@59000
  1731
hoelzl@57025
  1732
lemma nn_integral_count_space_nat:
hoelzl@62975
  1733
  fixes f :: "nat \<Rightarrow> ennreal"
hoelzl@57025
  1734
  shows "(\<integral>\<^sup>+i. f i \<partial>count_space UNIV) = (\<Sum>i. f i)"
hoelzl@57025
  1735
proof -
hoelzl@57025
  1736
  have "(\<integral>\<^sup>+i. f i \<partial>count_space UNIV) =
hoelzl@57025
  1737
    (\<integral>\<^sup>+i. (\<Sum>j. f j * indicator {j} i) \<partial>count_space UNIV)"
hoelzl@57025
  1738
  proof (intro nn_integral_cong)
hoelzl@57025
  1739
    fix i
hoelzl@57025
  1740
    have "f i = (\<Sum>j\<in>{i}. f j * indicator {j} i)"
hoelzl@57025
  1741
      by simp
hoelzl@57025
  1742
    also have "\<dots> = (\<Sum>j. f j * indicator {j} i)"
hoelzl@57025
  1743
      by (rule suminf_finite[symmetric]) auto
hoelzl@57025
  1744
    finally show "f i = (\<Sum>j. f j * indicator {j} i)" .
hoelzl@57025
  1745
  qed
hoelzl@57025
  1746
  also have "\<dots> = (\<Sum>j. (\<integral>\<^sup>+i. f j * indicator {j} i \<partial>count_space UNIV))"
hoelzl@62975
  1747
    by (rule nn_integral_suminf) auto
hoelzl@62975
  1748
  finally show ?thesis
hoelzl@62975
  1749
    by simp
hoelzl@62975
  1750
qed
hoelzl@62975
  1751
hoelzl@62975
  1752
lemma nn_integral_enat_function:
hoelzl@62975
  1753
  assumes f: "f \<in> measurable M (count_space UNIV)"
hoelzl@62975
  1754
  shows "(\<integral>\<^sup>+ x. ennreal_of_enat (f x) \<partial>M) = (\<Sum>t. emeasure M {x \<in> space M. t < f x})"
hoelzl@62975
  1755
proof -
wenzelm@63040
  1756
  define F where "F i = {x\<in>space M. i < f x}" for i :: nat
hoelzl@62975
  1757
  with assms have [measurable]: "\<And>i. F i \<in> sets M"
hoelzl@62975
  1758
    by auto
hoelzl@62975
  1759
hoelzl@62975
  1760
  { fix x assume "x \<in> space M"
hoelzl@62975
  1761
    have "(\<lambda>i::nat. if i < f x then 1 else 0) sums ennreal_of_enat (f x)"
hoelzl@62975
  1762
      using sums_If_finite[of "\<lambda>r. r < f x" "\<lambda>_. 1 :: ennreal"]
hoelzl@62975
  1763
      by (cases "f x") (simp_all add: sums_def of_nat_tendsto_top_ennreal)
hoelzl@62975
  1764
    also have "(\<lambda>i. (if i < f x then 1 else 0)) = (\<lambda>i. indicator (F i) x)"
wenzelm@63167
  1765
      using \<open>x \<in> space M\<close> by (simp add: one_ennreal_def F_def fun_eq_iff)
hoelzl@62975
  1766
    finally have "ennreal_of_enat (f x) = (\<Sum>i. indicator (F i) x)"
hoelzl@62975
  1767
      by (simp add: sums_iff) }
hoelzl@62975
  1768
  then have "(\<integral>\<^sup>+x. ennreal_of_enat (f x) \<partial>M) = (\<integral>\<^sup>+x. (\<Sum>i. indicator (F i) x) \<partial>M)"
hoelzl@62975
  1769
    by (simp cong: nn_integral_cong)
hoelzl@62975
  1770
  also have "\<dots> = (\<Sum>i. emeasure M (F i))"
hoelzl@62975
  1771
    by (simp add: nn_integral_suminf)
hoelzl@62975
  1772
  finally show ?thesis
hoelzl@62975
  1773
    by (simp add: F_def)
hoelzl@57025
  1774
qed
hoelzl@57025
  1775
hoelzl@59426
  1776
lemma nn_integral_count_space_nn_integral:
hoelzl@62975
  1777
  fixes f :: "'i \<Rightarrow> 'a \<Rightarrow> ennreal"
hoelzl@59426
  1778
  assumes "countable I" and [measurable]: "\<And>i. i \<in> I \<Longrightarrow> f i \<in> borel_measurable M"
hoelzl@59426
  1779
  shows "(\<integral>\<^sup>+x. \<integral>\<^sup>+i. f i x \<partial>count_space I \<partial>M) = (\<integral>\<^sup>+i. \<integral>\<^sup>+x. f i x \<partial>M \<partial>count_space I)"
hoelzl@59426
  1780
proof cases
hoelzl@59426
  1781
  assume "finite I" then show ?thesis
nipkow@64267
  1782
    by (simp add: nn_integral_count_space_finite nn_integral_sum)
hoelzl@59426
  1783
next
hoelzl@59426
  1784
  assume "infinite I"
hoelzl@59426
  1785
  then have [simp]: "I \<noteq> {}"
hoelzl@59426
  1786
    by auto
wenzelm@61808
  1787
  note * = bij_betw_from_nat_into[OF \<open>countable I\<close> \<open>infinite I\<close>]
hoelzl@59426
  1788
  have **: "\<And>f. (\<And>i. 0 \<le> f i) \<Longrightarrow> (\<integral>\<^sup>+i. f i \<partial>count_space I) = (\<Sum>n. f (from_nat_into I n))"
hoelzl@59426
  1789
    by (simp add: nn_integral_bij_count_space[symmetric, OF *] nn_integral_count_space_nat)
hoelzl@59426
  1790
  show ?thesis
hoelzl@62975
  1791
    by (simp add: ** nn_integral_suminf from_nat_into)
hoelzl@59426
  1792
qed
hoelzl@59426
  1793
hoelzl@64008
  1794
lemma of_bool_Bex_eq_nn_integral:
hoelzl@64008
  1795
  assumes unique: "\<And>x y. x \<in> X \<Longrightarrow> y \<in> X \<Longrightarrow> P x \<Longrightarrow> P y \<Longrightarrow> x = y"
hoelzl@64008
  1796
  shows "of_bool (\<exists>y\<in>X. P y) = (\<integral>\<^sup>+y. of_bool (P y) \<partial>count_space X)"
hoelzl@64008
  1797
proof cases
hoelzl@64008
  1798
  assume "\<exists>y\<in>X. P y"
hoelzl@64008
  1799
  then obtain y where "P y" "y \<in> X" by auto
hoelzl@64008
  1800
  then show ?thesis
hoelzl@64008
  1801
    by (subst nn_integral_count_space'[where A="{y}"]) (auto dest: unique)
hoelzl@64008
  1802
qed (auto cong: nn_integral_cong_simp)
hoelzl@64008
  1803
hoelzl@59426
  1804
lemma emeasure_UN_countable:
lp15@61609
  1805
  assumes sets[measurable]: "\<And>i. i \<in> I \<Longrightarrow> X i \<in> sets M" and I[simp]: "countable I"
hoelzl@59426
  1806
  assumes disj: "disjoint_family_on X I"
haftmann@69313
  1807
  shows "emeasure M (\<Union>(X ` I)) = (\<integral>\<^sup>+i. emeasure M (X i) \<partial>count_space I)"
hoelzl@59426
  1808
proof -
haftmann@69313
  1809
  have eq: "\<And>x. indicator (\<Union>(X ` I)) x = \<integral>\<^sup>+ i. indicator (X i) x \<partial>count_space I"
lp15@61609
  1810
  proof cases
haftmann@69313
  1811
    fix x assume x: "x \<in> \<Union>(X ` I)"
hoelzl@59426
  1812
    then obtain j where j: "x \<in> X j" "j \<in> I"
hoelzl@59426
  1813
      by auto
hoelzl@62975
  1814
    with disj have "\<And>i. i \<in> I \<Longrightarrow> indicator (X i) x = (indicator {j} i::ennreal)"
hoelzl@59426
  1815
      by (auto simp: disjoint_family_on_def split: split_indicator)
hoelzl@59426
  1816
    with x j show "?thesis x"
hoelzl@59426
  1817
      by (simp cong: nn_integral_cong_simp)
hoelzl@59426
  1818
  qed (auto simp: nn_integral_0_iff_AE)
hoelzl@59426
  1819
hoelzl@59426
  1820
  note sets.countable_UN'[unfolded subset_eq, measurable]
haftmann@69313
  1821
  have "emeasure M (\<Union>(X ` I)) = (\<integral>\<^sup>+x. indicator (\<Union>(X ` I)) x \<partial>M)"
hoelzl@59426
  1822
    by simp
hoelzl@59426
  1823
  also have "\<dots> = (\<integral>\<^sup>+i. \<integral>\<^sup>+x. indicator (X i) x \<partial>M \<partial>count_space I)"
hoelzl@59426
  1824
    by (simp add: eq nn_integral_count_space_nn_integral)
hoelzl@59426
  1825
  finally show ?thesis
hoelzl@59426
  1826
    by (simp cong: nn_integral_cong_simp)
hoelzl@59426
  1827
qed
hoelzl@59426
  1828
hoelzl@57025
  1829
lemma emeasure_countable_singleton:
hoelzl@57025
  1830
  assumes sets: "\<And>x. x \<in> X \<Longrightarrow> {x} \<in> sets M" and X: "countable X"
hoelzl@57025
  1831
  shows "emeasure M X = (\<integral>\<^sup>+x. emeasure M {x} \<partial>count_space X)"
hoelzl@57025
  1832
proof -
hoelzl@57025
  1833
  have "emeasure M (\<Union>i\<in>X. {i}) = (\<integral>\<^sup>+x. emeasure M {x} \<partial>count_space X)"
hoelzl@57025
  1834
    using assms by (intro emeasure_UN_countable) (auto simp: disjoint_family_on_def)
hoelzl@57025
  1835
  also have "(\<Union>i\<in>X. {i}) = X" by auto
hoelzl@57025
  1836
  finally show ?thesis .
hoelzl@57025
  1837
qed
hoelzl@57025
  1838
hoelzl@57025
  1839
lemma measure_eqI_countable:
hoelzl@57025
  1840
  assumes [simp]: "sets M = Pow A" "sets N = Pow A" and A: "countable A"
hoelzl@57025
  1841
  assumes eq: "\<And>a. a \<in> A \<Longrightarrow> emeasure M {a} = emeasure N {a}"
hoelzl@57025
  1842
  shows "M = N"
hoelzl@57025
  1843
proof (rule measure_eqI)
hoelzl@57025
  1844
  fix X assume "X \<in> sets M"
hoelzl@57025
  1845
  then have X: "X \<subseteq> A" by auto
wenzelm@63540
  1846
  moreover from A X have "countable X" by (auto dest: countable_subset)
hoelzl@57025
  1847
  ultimately have
hoelzl@57025
  1848
    "emeasure M X = (\<integral>\<^sup>+a. emeasure M {a} \<partial>count_space X)"
hoelzl@57025
  1849
    "emeasure N X = (\<integral>\<^sup>+a. emeasure N {a} \<partial>count_space X)"
hoelzl@57025
  1850
    by (auto intro!: emeasure_countable_singleton)
hoelzl@57025
  1851
  moreover have "(\<integral>\<^sup>+a. emeasure M {a} \<partial>count_space X) = (\<integral>\<^sup>+a. emeasure N {a} \<partial>count_space X)"
hoelzl@57025
  1852
    using X by (intro nn_integral_cong eq) auto
hoelzl@57025
  1853
  ultimately show "emeasure M X = emeasure N X"
hoelzl@57025
  1854
    by simp
hoelzl@57025
  1855
qed simp
hoelzl@57025
  1856
hoelzl@59000
  1857
lemma measure_eqI_countable_AE:
hoelzl@59000
  1858
  assumes [simp]: "sets M = UNIV" "sets N = UNIV"
hoelzl@59000
  1859
  assumes ae: "AE x in M. x \<in> \<Omega>" "AE x in N. x \<in> \<Omega>" and [simp]: "countable \<Omega>"
hoelzl@59000
  1860
  assumes eq: "\<And>x. x \<in> \<Omega> \<Longrightarrow> emeasure M {x} = emeasure N {x}"
hoelzl@59000
  1861
  shows "M = N"
hoelzl@59000
  1862
proof (rule measure_eqI)
hoelzl@59000
  1863
  fix A
hoelzl@59000
  1864
  have "emeasure N A = emeasure N {x\<in>\<Omega>. x \<in> A}"
hoelzl@59000
  1865
    using ae by (intro emeasure_eq_AE) auto
hoelzl@59000
  1866
  also have "\<dots> = (\<integral>\<^sup>+x. emeasure N {x} \<partial>count_space {x\<in>\<Omega>. x \<in> A})"
hoelzl@59000
  1867
    by (intro emeasure_countable_singleton) auto
hoelzl@59000
  1868
  also have "\<dots> = (\<integral>\<^sup>+x. emeasure M {x} \<partial>count_space {x\<in>\<Omega>. x \<in> A})"
hoelzl@59000
  1869
    by (intro nn_integral_cong eq[symmetric]) auto
hoelzl@59000
  1870
  also have "\<dots> = emeasure M {x\<in>\<Omega>. x \<in> A}"
hoelzl@59000
  1871
    by (intro emeasure_countable_singleton[symmetric]) auto
hoelzl@59000
  1872
  also have "\<dots> = emeasure M A"
hoelzl@59000
  1873
    using ae by (intro emeasure_eq_AE) auto
hoelzl@59000
  1874
  finally show "emeasure M A = emeasure N A" ..
hoelzl@59000
  1875
qed simp
hoelzl@59000
  1876
hoelzl@62975
  1877
lemma nn_integral_monotone_convergence_SUP_nat:
hoelzl@62975
  1878
  fixes f :: "'a \<Rightarrow> nat \<Rightarrow> ennreal"
nipkow@67399
  1879
  assumes chain: "Complete_Partial_Order.chain (\<le>) (f ` Y)"
Andreas@60064
  1880
  and nonempty: "Y \<noteq> {}"
haftmann@69260
  1881
  shows "(\<integral>\<^sup>+ x. (SUP i\<in>Y. f i x) \<partial>count_space UNIV) = (SUP i\<in>Y. (\<integral>\<^sup>+ x. f i x \<partial>count_space UNIV))"
Andreas@60064
  1882
  (is "?lhs = ?rhs" is "integral\<^sup>N ?M _ = _")
Andreas@60064
  1883
proof (rule order_class.order.antisym)
Andreas@60064
  1884
  show "?rhs \<le> ?lhs"
Andreas@60064
  1885
    by (auto intro!: SUP_least SUP_upper nn_integral_mono)
Andreas@60064
  1886
next
haftmann@69260
  1887
  have "\<exists>g. incseq g \<and> range g \<subseteq> (\<lambda>i. f i x) ` Y \<and> (SUP i\<in>Y. f i x) = (SUP i. g i)" for x
hoelzl@62975
  1888
    by (rule ennreal_Sup_countable_SUP) (simp add: nonempty)
Andreas@60064
  1889
  then obtain g where incseq: "\<And>x. incseq (g x)"
Andreas@60064
  1890
    and range: "\<And>x. range (g x) \<subseteq> (\<lambda>i. f i x) ` Y"
haftmann@69260
  1891
    and sup: "\<And>x. (SUP i\<in>Y. f i x) = (SUP i. g x i)" by moura
Andreas@60064
  1892
  from incseq have incseq': "incseq (\<lambda>i x. g x i)"
Andreas@60064
  1893
    by(blast intro: incseq_SucI le_funI dest: incseq_SucD)
Andreas@60064
  1894
Andreas@60064
  1895
  have "?lhs = \<integral>\<^sup>+ x. (SUP i. g x i) \<partial>?M" by(simp add: sup)
Andreas@60064
  1896
  also have "\<dots> = (SUP i. \<integral>\<^sup>+ x. g x i \<partial>?M)" using incseq'
Andreas@60064
  1897
    by(rule nn_integral_monotone_convergence_SUP) simp
haftmann@69260
  1898
  also have "\<dots> \<le> (SUP i\<in>Y. \<integral>\<^sup>+ x. f i x \<partial>?M)"
Andreas@60064
  1899
  proof(rule SUP_least)
Andreas@60064
  1900
    fix n
Andreas@60064
  1901
    have "\<And>x. \<exists>i. g x n = f i x \<and> i \<in> Y" using range by blast
Andreas@60064
  1902
    then obtain I where I: "\<And>x. g x n = f (I x) x" "\<And>x. I x \<in> Y" by moura
Andreas@60064
  1903
hoelzl@62975
  1904
    have "(\<integral>\<^sup>+ x. g x n \<partial>count_space UNIV) = (\<Sum>x. g x n)"
Andreas@60064
  1905
      by(rule nn_integral_count_space_nat)
hoelzl@62975
  1906
    also have "\<dots> = (SUP m. \<Sum>x<m. g x n)"
hoelzl@62975
  1907
      by(rule suminf_eq_SUP)
haftmann@69260
  1908
    also have "\<dots> \<le> (SUP i\<in>Y. \<integral>\<^sup>+ x. f i x \<partial>?M)"
Andreas@60064
  1909
    proof(rule SUP_mono)
Andreas@60064
  1910
      fix m
Andreas@60064
  1911
      show "\<exists>m'\<in>Y. (\<Sum>x<m. g x n) \<le> (\<integral>\<^sup>+ x. f m' x \<partial>?M)"
Andreas@60064
  1912
      proof(cases "m > 0")
Andreas@60064
  1913
        case False
hoelzl@62975
  1914
        thus ?thesis using nonempty by auto
Andreas@60064
  1915
      next
Andreas@60064
  1916
        case True
Andreas@60064
  1917
        let ?Y = "I ` {..<m}"
Andreas@60064
  1918
        have "f ` ?Y \<subseteq> f ` Y" using I by auto
nipkow@67399
  1919
        with chain have chain': "Complete_Partial_Order.chain (\<le>) (f ` ?Y)" by(rule chain_subset)
Andreas@60064
  1920
        hence "Sup (f ` ?Y) \<in> f ` ?Y"
Andreas@60064
  1921
          by(rule ccpo_class.in_chain_finite)(auto simp add: True lessThan_empty_iff)
haftmann@69260
  1922
        then obtain m' where "m' < m" and m': "(SUP i\<in>?Y. f i) = f (I m')" by auto
Andreas@60064
  1923
        have "I m' \<in> Y" using I by blast
Andreas@60064
  1924
        have "(\<Sum>x<m. g x n) \<le> (\<Sum>x<m. f (I m') x)"
nipkow@64267
  1925
        proof(rule sum_mono)
Andreas@60064
  1926
          fix x
Andreas@60064
  1927
          assume "x \<in> {..<m}"
Andreas@60064
  1928
          hence "x < m" by simp
Andreas@60064
  1929
          have "g x n = f (I x) x" by(simp add: I)
haftmann@69260
  1930
          also have "\<dots> \<le> (SUP i\<in>?Y. f i) x" unfolding Sup_fun_def image_image
haftmann@62343
  1931
            using \<open>x \<in> {..<m}\<close> by (rule Sup_upper [OF imageI])
Andreas@60064
  1932
          also have "\<dots> = f (I m') x" unfolding m' by simp
Andreas@60064
  1933
          finally show "g x n \<le> f (I m') x" .
Andreas@60064
  1934
        qed
Andreas@60064
  1935
        also have "\<dots> \<le> (SUP m. (\<Sum>x<m. f (I m') x))"
Andreas@60064
  1936
          by(rule SUP_upper) simp
Andreas@60064
  1937
        also have "\<dots> = (\<Sum>x. f (I m') x)"
hoelzl@62975
  1938
          by(rule suminf_eq_SUP[symmetric])
Andreas@60064
  1939
        also have "\<dots> = (\<integral>\<^sup>+ x. f (I m') x \<partial>?M)"
hoelzl@62975
  1940
          by(rule nn_integral_count_space_nat[symmetric])
Andreas@60064
  1941
        finally show ?thesis using \<open>I m' \<in> Y\<close> by blast
Andreas@60064
  1942
      qed
Andreas@60064
  1943
    qed
Andreas@60064
  1944
    finally show "(\<integral>\<^sup>+ x. g x n \<partial>count_space UNIV) \<le> \<dots>" .
Andreas@60064
  1945
  qed
Andreas@60064
  1946
  finally show "?lhs \<le> ?rhs" .
Andreas@60064
  1947
qed
Andreas@60064
  1948
hoelzl@62975
  1949
lemma power_series_tendsto_at_left:
hoelzl@62975
  1950
  assumes nonneg: "\<And>i. 0 \<le> f i" and summable: "\<And>z. 0 \<le> z \<Longrightarrow> z < 1 \<Longrightarrow> summable (\<lambda>n. f n * z^n)"
hoelzl@62975
  1951
  shows "((\<lambda>z. ennreal (\<Sum>n. f n * z^n)) \<longlongrightarrow> (\<Sum>n. ennreal (f n))) (at_left (1::real))"
hoelzl@62975
  1952
proof (intro tendsto_at_left_sequentially)
hoelzl@62975
  1953
  show "0 < (1::real)" by simp
hoelzl@62975
  1954
  fix S :: "nat \<Rightarrow> real" assume S: "\<And>n. S n < 1" "\<And>n. 0 < S n" "S \<longlonglongrightarrow> 1" "incseq S"
hoelzl@62975
  1955
  then have S_nonneg: "\<And>i. 0 \<le> S i" by (auto intro: less_imp_le)
hoelzl@62975
  1956
hoelzl@62975
  1957
  have "(\<lambda>i. (\<integral>\<^sup>+n. f n * S i^n \<partial>count_space UNIV)) \<longlonglongrightarrow> (\<integral>\<^sup>+n. ennreal (f n) \<partial>count_space UNIV)"
hoelzl@62975
  1958
  proof (rule nn_integral_LIMSEQ)
hoelzl@62975
  1959
    show "incseq (\<lambda>i n. ennreal (f n * S i^n))"
hoelzl@62975
  1960
      using S by (auto intro!: mult_mono power_mono nonneg ennreal_leI
hoelzl@62975
  1961
                       simp: incseq_def le_fun_def less_imp_le)
hoelzl@62975
  1962
    fix n have "(\<lambda>i. ennreal (f n * S i^n)) \<longlonglongrightarrow> ennreal (f n * 1^n)"
hoelzl@62975
  1963
      by (intro tendsto_intros tendsto_ennrealI S)
hoelzl@62975
  1964
    then show "(\<lambda>i. ennreal (f n * S i^n)) \<longlonglongrightarrow> ennreal (f n)"
hoelzl@62975
  1965
      by simp
hoelzl@62975
  1966
  qed (auto simp: S_nonneg intro!: mult_nonneg_nonneg nonneg)
hoelzl@62975
  1967
  also have "(\<lambda>i. (\<integral>\<^sup>+n. f n * S i^n \<partial>count_space UNIV)) = (\<lambda>i. \<Sum>n. f n * S i^n)"
hoelzl@62975
  1968
    by (subst nn_integral_count_space_nat)
hoelzl@62975
  1969
       (intro ext suminf_ennreal2 mult_nonneg_nonneg nonneg S_nonneg
hoelzl@62975
  1970
              zero_le_power summable S)+
hoelzl@62975
  1971
  also have "(\<integral>\<^sup>+n. ennreal (f n) \<partial>count_space UNIV) = (\<Sum>n. ennreal (f n))"
hoelzl@62975
  1972
    by (simp add: nn_integral_count_space_nat nonneg)
hoelzl@62975
  1973
  finally show "(\<lambda>n. ennreal (\<Sum>na. f na * S n ^ na)) \<longlonglongrightarrow> (\<Sum>n. ennreal (f n))" .
Andreas@60064
  1974
qed
Andreas@60064
  1975
wenzelm@61808
  1976
subsubsection \<open>Measures with Restricted Space\<close>
hoelzl@54417
  1977
hoelzl@62975
  1978
lemma simple_function_restrict_space_ennreal:
hoelzl@62975
  1979
  fixes f :: "'a \<Rightarrow> ennreal"
hoelzl@57137
  1980
  assumes "\<Omega> \<inter> space M \<in> sets M"
hoelzl@57137
  1981
  shows "simple_function (restrict_space M \<Omega>) f \<longleftrightarrow> simple_function M (\<lambda>x. f x * indicator \<Omega> x)"
hoelzl@57137
  1982
proof -
hoelzl@57137
  1983
  { assume "finite (f ` space (restrict_space M \<Omega>))"
hoelzl@57137
  1984
    then have "finite (f ` space (restrict_space M \<Omega>) \<union> {0})" by simp
hoelzl@57137
  1985
    then have "finite ((\<lambda>x. f x * indicator \<Omega> x) ` space M)"
hoelzl@57137
  1986
      by (rule rev_finite_subset) (auto split: split_indicator simp: space_restrict_space) }
hoelzl@57137
  1987
  moreover
hoelzl@57137
  1988
  { assume "finite ((\<lambda>x. f x * indicator \<Omega> x) ` space M)"
hoelzl@57137
  1989
    then have "finite (f ` space (restrict_space M \<Omega>))"
hoelzl@57137
  1990
      by (rule rev_finite_subset) (auto split: split_indicator simp: space_restrict_space) }
hoelzl@57137
  1991
  ultimately show ?thesis
hoelzl@62975
  1992
    unfolding
hoelzl@62975
  1993
      simple_function_iff_borel_measurable borel_measurable_restrict_space_iff_ennreal[OF assms]
hoelzl@57137
  1994
    by auto
hoelzl@57137
  1995
qed
hoelzl@57137
  1996
hoelzl@57137
  1997
lemma simple_function_restrict_space:
hoelzl@57137
  1998
  fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
hoelzl@57137
  1999
  assumes "\<Omega> \<inter> space M \<in> sets M"
hoelzl@57137
  2000
  shows "simple_function (restrict_space M \<Omega>) f \<longleftrightarrow> simple_function M (\<lambda>x. indicator \<Omega> x *\<^sub>R f x)"
hoelzl@57137
  2001
proof -
hoelzl@57137
  2002
  { assume "finite (f ` space (restrict_space M \<Omega>))"
hoelzl@57137
  2003
    then have "finite (f ` space (restrict_space M \<Omega>) \<union> {0})" by simp
hoelzl@57137
  2004
    then have "finite ((\<lambda>x. indicator \<Omega> x *\<^sub>R f x) ` space M)"
hoelzl@57137
  2005
      by (rule rev_finite_subset) (auto split: split_indicator simp: space_restrict_space) }
hoelzl@57137
  2006
  moreover
hoelzl@57137
  2007
  { assume "finite ((\<lambda>x. indicator \<Omega> x *\<^sub>R f x) ` space M)"
hoelzl@57137
  2008
    then have "finite (f ` space (restrict_space M \<Omega>))"
hoelzl@57137
  2009
      by (rule rev_finite_subset) (auto split: split_indicator simp: space_restrict_space) }
hoelzl@57137
  2010
  ultimately show ?thesis
hoelzl@57137
  2011
    unfolding simple_function_iff_borel_measurable
hoelzl@57137
  2012
      borel_measurable_restrict_space_iff[OF assms]
hoelzl@57137
  2013
    by auto
hoelzl@57137
  2014
qed
hoelzl@57137
  2015
hoelzl@57137
  2016
lemma simple_integral_restrict_space:
hoelzl@57137
  2017
  assumes \<Omega>: "\<Omega> \<inter> space M \<in> sets M" "simple_function (restrict_space M \<Omega>) f"
hoelzl@57137
  2018
  shows "simple_integral (restrict_space M \<Omega>) f = simple_integral M (\<lambda>x. f x * indicator \<Omega> x)"
hoelzl@62975
  2019
  using simple_function_restrict_space_ennreal[THEN iffD1, OF \<Omega>, THEN simple_functionD(1)]
hoelzl@57137
  2020
  by (auto simp add: space_restrict_space emeasure_restrict_space[OF \<Omega>(1)] le_infI2 simple_integral_def
hoelzl@57137
  2021
           split: split_indicator split_indicator_asm
nipkow@64267
  2022
           intro!: sum.mono_neutral_cong_left ennreal_mult_left_cong arg_cong2[where f=emeasure])
hoelzl@57137
  2023
hoelzl@56996
  2024
lemma nn_integral_restrict_space:
hoelzl@57137
  2025
  assumes \<Omega>[simp]: "\<Omega> \<inter> space M \<in> sets M"
hoelzl@57137
  2026
  shows "nn_integral (restrict_space M \<Omega>) f = nn_integral M (\<lambda>x. f x * indicator \<Omega> x)"
hoelzl@57137
  2027
proof -
hoelzl@62975
  2028
  let ?R = "restrict_space M \<Omega>" and ?X = "\<lambda>M f. {s. simple_function M s \<and> s \<le> f \<and> (\<forall>x. s x < top)}"
hoelzl@57137
  2029
  have "integral\<^sup>S ?R ` ?X ?R f = integral\<^sup>S M ` ?X M (\<lambda>x. f x * indicator \<Omega> x)"
hoelzl@57137
  2030
  proof (safe intro!: image_eqI)
hoelzl@62975
  2031
    fix s assume s: "simple_function ?R s" "s \<le> f" "\<forall>x. s x < top"
hoelzl@57137
  2032
    from s show "integral\<^sup>S (restrict_space M \<Omega>) s = integral\<^sup>S M (\<lambda>x. s x * indicator \<Omega> x)"
hoelzl@57137
  2033
      by (intro simple_integral_restrict_space) auto
hoelzl@57137
  2034
    from s show "simple_function M (\<lambda>x. s x * indicator \<Omega> x)"
hoelzl@62975
  2035
      by (simp add: simple_function_restrict_space_ennreal)
hoelzl@62975
  2036
    from s show "(\<lambda>x. s x * indicator \<Omega> x) \<le> (\<lambda>x. f x * indicator \<Omega> x)"
hoelzl@62975
  2037
      "\<And>x. s x * indicator \<Omega> x < top"
hoelzl@57137
  2038
      by (auto split: split_indicator simp: le_fun_def image_subset_iff)
hoelzl@57137
  2039
  next
hoelzl@62975
  2040
    fix s assume s: "simple_function M s" "s \<le> (\<lambda>x. f x * indicator \<Omega> x)" "\<forall>x. s x < top"
hoelzl@57137
  2041
    then have "simple_function M (\<lambda>x. s x * indicator (\<Omega> \<inter> space M) x)" (is ?s')
hoelzl@57137
  2042
      by (intro simple_function_mult simple_function_indicator) auto
hoelzl@57137
  2043
    also have "?s' \<longleftrightarrow> simple_function M (\<lambda>x. s x * indicator \<Omega> x)"
hoelzl@57137
  2044
      by (rule simple_function_cong) (auto split: split_indicator)
hoelzl@57137
  2045
    finally show sf: "simple_function (restrict_space M \<Omega>) s"
hoelzl@62975
  2046
      by (simp add: simple_function_restrict_space_ennreal)
hoelzl@57137
  2047
hoelzl@57137
  2048
    from s have s_eq: "s = (\<lambda>x. s x * indicator \<Omega> x)"
hoelzl@57137
  2049
      by (auto simp add: fun_eq_iff le_fun_def image_subset_iff
hoelzl@57137
  2050
                  split: split_indicator split_indicator_asm
hoelzl@57137
  2051
                  intro: antisym)
hoelzl@57137
  2052
hoelzl@57137
  2053
    show "integral\<^sup>S M s = integral\<^sup>S (restrict_space M \<Omega>) s"
hoelzl@57137
  2054
      by (subst s_eq) (rule simple_integral_restrict_space[symmetric, OF \<Omega> sf])
hoelzl@62975
  2055
    show "\<And>x. s x < top"
hoelzl@57137
  2056
      using s by (auto simp: image_subset_iff)
hoelzl@62975
  2057
    from s show "s \<le> f"
hoelzl@57137
  2058
      by (subst s_eq) (auto simp: image_subset_iff le_fun_def split: split_indicator split_indicator_asm)
hoelzl@57137
  2059
  qed
hoelzl@57137
  2060
  then show ?thesis
nipkow@69164
  2061
    unfolding nn_integral_def_finite by (simp cong del: SUP_cong_strong)
hoelzl@54417
  2062
qed
hoelzl@54417
  2063
hoelzl@59000
  2064
lemma nn_integral_count_space_indicator:
hoelzl@59779
  2065
  assumes "NO_MATCH (UNIV::'a set) (X::'a set)"
hoelzl@59000
  2066
  shows "(\<integral>\<^sup>+x. f x \<partial>count_space X) = (\<integral>\<^sup>+x. f x * indicator X x \<partial>count_space UNIV)"
hoelzl@59000
  2067
  by (simp add: nn_integral_restrict_space[symmetric] restrict_count_space)
hoelzl@59000
  2068
hoelzl@59425
  2069
lemma nn_integral_count_space_eq:
hoelzl@59425
  2070
  "(\<And>x. x \<in> A - B \<Longrightarrow> f x = 0) \<Longrightarrow> (\<And>x. x \<in> B - A \<Longrightarrow> f x = 0) \<Longrightarrow>
hoelzl@59425
  2071
    (\<integral>\<^sup>+x. f x \<partial>count_space A) = (\<integral>\<^sup>+x. f x \<partial>count_space B)"
hoelzl@59425
  2072
  by (auto simp: nn_integral_count_space_indicator intro!: nn_integral_cong split: split_indicator)
hoelzl@59425
  2073
Andreas@59023
  2074
lemma nn_integral_ge_point:
Andreas@59023
  2075
  assumes "x \<in> A"
Andreas@59023
  2076
  shows "p x \<le> \<integral>\<^sup>+ x. p x \<partial>count_space A"
Andreas@59023
  2077
proof -
Andreas@59023
  2078
  from assms have "p x \<le> \<integral>\<^sup>+ x. p x \<partial>count_space {x}"
Andreas@59023
  2079
    by(auto simp add: nn_integral_count_space_finite max_def)
Andreas@59023
  2080
  also have "\<dots> = \<integral>\<^sup>+ x'. p x' * indicator {x} x' \<partial>count_space A"
Andreas@59023
  2081
    using assms by(auto simp add: nn_integral_count_space_indicator indicator_def intro!: nn_integral_cong)
hoelzl@62975
  2082
  also have "\<dots> \<le> \<integral>\<^sup>+ x. p x \<partial>count_space A"
Andreas@59023
  2083
    by(rule nn_integral_mono)(simp add: indicator_def)
Andreas@59023
  2084
  finally show ?thesis .
Andreas@59023
  2085
qed
Andreas@59023
  2086
wenzelm@61808
  2087
subsubsection \<open>Measure spaces with an associated density\<close>
hoelzl@47694
  2088
eberlm@69457
  2089
definition%important density :: "'a measure \<Rightarrow> ('a \<Rightarrow> ennreal) \<Rightarrow> 'a measure" where
wenzelm@53015
  2090
  "density M f = measure_of (space M) (sets M) (\<lambda>A. \<integral>\<^sup>+ x. f x * indicator A x \<partial>M)"
hoelzl@35582
  2091
lp15@61609
  2092
lemma
hoelzl@59048
  2093
  shows sets_density[simp, measurable_cong]: "sets (density M f) = sets M"
hoelzl@47694
  2094
    and space_density[simp]: "space (density M f) = space M"
hoelzl@47694
  2095
  by (auto simp: density_def)
hoelzl@47694
  2096
hoelzl@50003
  2097
(* FIXME: add conversion to simplify space, sets and measurable *)
hoelzl@50003
  2098
lemma space_density_imp[measurable_dest]:
hoelzl@50003
  2099
  "\<And>x M f. x \<in> space (density M f) \<Longrightarrow> x \<in> space M" by auto
hoelzl@50003
  2100
lp15@61609
  2101
lemma
hoelzl@47694
  2102
  shows measurable_density_eq1[simp]: "g \<in> measurable (density Mg f) Mg' \<longleftrightarrow> g \<in> measurable Mg Mg'"