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