author hoelzl Thu Apr 14 15:48:11 2016 +0200 (2016-04-14) changeset 62975 1d066f6ab25d parent 62974 f17602cbf76a child 62976 38906f0e4633
Probability: move emeasure and nn_integral from ereal to ennreal
```     1.1 --- a/NEWS	Thu Apr 14 12:17:44 2016 +0200
1.2 +++ b/NEWS	Thu Apr 14 15:48:11 2016 +0200
1.3 @@ -251,6 +251,10 @@
1.4
1.5  * Session HOL-NSA has been renamed to HOL-Nonstandard_Analysis.
1.6
1.7 +* In HOL-Probability the type of emeasure and nn_integral was changed
1.8 +from ereal to ennreal:
1.9 +  emeasure :: 'a measure => 'a set => ennreal
1.10 +  nn_integral :: 'a measure => ('a => ennreal) => ennreal
1.11
1.12  *** ML ***
1.13
```
```     2.1 --- a/src/HOL/Library/Extended_Nonnegative_Real.thy	Thu Apr 14 12:17:44 2016 +0200
2.2 +++ b/src/HOL/Library/Extended_Nonnegative_Real.thy	Thu Apr 14 15:48:11 2016 +0200
2.3 @@ -8,6 +8,156 @@
2.4    imports Extended_Real Indicator_Function
2.5  begin
2.6
2.8 +  assumes "b \<noteq> (-\<infinity>::ereal)" "a \<ge> b"
2.9 +  shows "a = b + (a-b)"
2.10 +by (metis add.commute assms(1) assms(2) ereal_eq_minus_iff ereal_minus_le_iff ereal_plus_eq_PInfty)
2.11 +
2.14 +  shows "F \<noteq> bot \<Longrightarrow> Limsup F (\<lambda>x. c + f x) = c + Limsup F f"
2.15 +  by (rule Limsup_compose_continuous_mono)
2.17 +
2.20 +  shows "F \<noteq> bot \<Longrightarrow> Liminf F (\<lambda>x. c + f x) = c + Liminf F f"
2.21 +  by (rule Liminf_compose_continuous_mono)
2.23 +
2.26 +  shows "F \<noteq> bot \<Longrightarrow> Liminf F (\<lambda>x. f x + c) = Liminf F f + c"
2.27 +  by (rule Liminf_compose_continuous_mono)
2.29 +
2.30 +lemma sums_offset:
2.31 +  fixes f g :: "nat \<Rightarrow> 'a :: {t2_space, topological_comm_monoid_add}"
2.32 +  assumes "(\<lambda>n. f (n + i)) sums l" shows "f sums (l + (\<Sum>j<i. f j))"
2.33 +proof  -
2.34 +  have "(\<lambda>k. (\<Sum>n<k. f (n + i)) + (\<Sum>j<i. f j)) \<longlonglongrightarrow> l + (\<Sum>j<i. f j)"
2.35 +    using assms by (auto intro!: tendsto_add simp: sums_def)
2.36 +  moreover
2.37 +  { fix k :: nat
2.38 +    have "(\<Sum>j<k + i. f j) = (\<Sum>j=i..<k + i. f j) + (\<Sum>j=0..<i. f j)"
2.39 +      by (subst setsum.union_disjoint[symmetric]) (auto intro!: setsum.cong)
2.40 +    also have "(\<Sum>j=i..<k + i. f j) = (\<Sum>j\<in>(\<lambda>n. n + i)`{0..<k}. f j)"
2.41 +      unfolding image_add_atLeastLessThan by simp
2.42 +    finally have "(\<Sum>j<k + i. f j) = (\<Sum>n<k. f (n + i)) + (\<Sum>j<i. f j)"
2.43 +      by (auto simp: inj_on_def atLeast0LessThan setsum.reindex) }
2.44 +  ultimately have "(\<lambda>k. (\<Sum>n<k + i. f n)) \<longlonglongrightarrow> l + (\<Sum>j<i. f j)"
2.45 +    by simp
2.46 +  then show ?thesis
2.47 +    unfolding sums_def by (rule LIMSEQ_offset)
2.48 +qed
2.49 +
2.50 +lemma suminf_offset:
2.51 +  fixes f g :: "nat \<Rightarrow> 'a :: {t2_space, topological_comm_monoid_add}"
2.52 +  shows "summable (\<lambda>j. f (j + i)) \<Longrightarrow> suminf f = (\<Sum>j. f (j + i)) + (\<Sum>j<i. f j)"
2.53 +  by (intro sums_unique[symmetric] sums_offset summable_sums)
2.54 +
2.55 +lemma eventually_at_left_1: "(\<And>z::real. 0 < z \<Longrightarrow> z < 1 \<Longrightarrow> P z) \<Longrightarrow> eventually P (at_left 1)"
2.56 +  by (subst eventually_at_left[of 0]) (auto intro: exI[of _ 0])
2.57 +
2.58 +lemma mult_eq_1:
2.59 +  fixes a b :: "'a :: {ordered_semiring, comm_monoid_mult}"
2.60 +  shows "0 \<le> a \<Longrightarrow> a \<le> 1 \<Longrightarrow> b \<le> 1 \<Longrightarrow> a * b = 1 \<longleftrightarrow> (a = 1 \<and> b = 1)"
2.61 +  by (metis mult.left_neutral eq_iff mult.commute mult_right_mono)
2.62 +
2.64 +  fixes a b :: ereal
2.65 +  shows "\<bar>b\<bar> \<noteq> \<infinity> \<Longrightarrow> (a + b) - b = a"
2.66 +  by (cases a b rule: ereal2_cases) auto
2.67 +
2.69 +  fixes x :: "'a::{order_top, ordered_comm_monoid_add}"
2.70 +  shows "0 \<le> x \<Longrightarrow> x + top = top"
2.71 +  by (intro top_le add_increasing order_refl)
2.72 +
2.74 +  fixes x :: "'a::{order_top, ordered_comm_monoid_add}"
2.75 +  shows "0 \<le> x \<Longrightarrow> top + x = top"
2.76 +  by (intro top_le add_increasing2 order_refl)
2.77 +
2.78 +lemma le_lfp: "mono f \<Longrightarrow> x \<le> lfp f \<Longrightarrow> f x \<le> lfp f"
2.79 +  by (subst lfp_unfold) (auto dest: monoD)
2.80 +
2.81 +lemma lfp_transfer:
2.82 +  assumes \<alpha>: "sup_continuous \<alpha>" and f: "sup_continuous f" and mg: "mono g"
2.83 +  assumes bot: "\<alpha> bot \<le> lfp g" and eq: "\<And>x. x \<le> lfp f \<Longrightarrow> \<alpha> (f x) = g (\<alpha> x)"
2.84 +  shows "\<alpha> (lfp f) = lfp g"
2.85 +proof (rule antisym)
2.86 +  note mf = sup_continuous_mono[OF f]
2.87 +  have f_le_lfp: "(f ^^ i) bot \<le> lfp f" for i
2.88 +    by (induction i) (auto intro: le_lfp mf)
2.89 +
2.90 +  have "\<alpha> ((f ^^ i) bot) \<le> lfp g" for i
2.91 +    by (induction i) (auto simp: bot eq f_le_lfp intro!: le_lfp mg)
2.92 +  then show "\<alpha> (lfp f) \<le> lfp g"
2.93 +    unfolding sup_continuous_lfp[OF f]
2.94 +    by (subst \<alpha>[THEN sup_continuousD])
2.95 +       (auto intro!: mono_funpow sup_continuous_mono[OF f] SUP_least)
2.96 +
2.97 +  show "lfp g \<le> \<alpha> (lfp f)"
2.98 +    by (rule lfp_lowerbound) (simp add: eq[symmetric] lfp_unfold[OF mf, symmetric])
2.99 +qed
2.100 +
2.101 +lemma sup_continuous_applyD: "sup_continuous f \<Longrightarrow> sup_continuous (\<lambda>x. f x h)"
2.102 +  using sup_continuous_apply[THEN sup_continuous_compose] .
2.103 +
2.104 +lemma sup_continuous_SUP[order_continuous_intros]:
2.105 +  fixes M :: "_ \<Rightarrow> _ \<Rightarrow> 'a::complete_lattice"
2.106 +  assumes M: "\<And>i. i \<in> I \<Longrightarrow> sup_continuous (M i)"
2.107 +  shows  "sup_continuous (SUP i:I. M i)"
2.108 +  unfolding sup_continuous_def by (auto simp add: sup_continuousD[OF M] intro: SUP_commute)
2.109 +
2.110 +lemma sup_continuous_apply_SUP[order_continuous_intros]:
2.111 +  fixes M :: "_ \<Rightarrow> _ \<Rightarrow> 'a::complete_lattice"
2.112 +  shows "(\<And>i. i \<in> I \<Longrightarrow> sup_continuous (M i)) \<Longrightarrow> sup_continuous (\<lambda>x. SUP i:I. M i x)"
2.113 +  unfolding SUP_apply[symmetric] by (rule sup_continuous_SUP)
2.114 +
2.115 +lemma sup_continuous_lfp'[order_continuous_intros]:
2.116 +  assumes 1: "sup_continuous f"
2.117 +  assumes 2: "\<And>g. sup_continuous g \<Longrightarrow> sup_continuous (f g)"
2.118 +  shows "sup_continuous (lfp f)"
2.119 +proof -
2.120 +  have "sup_continuous ((f ^^ i) bot)" for i
2.121 +  proof (induction i)
2.122 +    case (Suc i) then show ?case
2.123 +      by (auto intro!: 2)
2.124 +  qed (simp add: bot_fun_def sup_continuous_const)
2.125 +  then show ?thesis
2.126 +    unfolding sup_continuous_lfp[OF 1] by (intro order_continuous_intros)
2.127 +qed
2.128 +
2.129 +lemma sup_continuous_lfp''[order_continuous_intros]:
2.130 +  assumes 1: "\<And>s. sup_continuous (f s)"
2.131 +  assumes 2: "\<And>g. sup_continuous g \<Longrightarrow> sup_continuous (\<lambda>s. f s (g s))"
2.132 +  shows "sup_continuous (\<lambda>x. lfp (f x))"
2.133 +proof -
2.134 +  have "sup_continuous (\<lambda>x. (f x ^^ i) bot)" for i
2.135 +  proof (induction i)
2.136 +    case (Suc i) then show ?case
2.137 +      by (auto intro!: 2)
2.138 +  qed (simp add: bot_fun_def sup_continuous_const)
2.139 +  then show ?thesis
2.140 +    unfolding sup_continuous_lfp[OF 1] by (intro order_continuous_intros)
2.141 +qed
2.142 +
2.143 +lemma mono_INF_fun:
2.144 +    "(\<And>x y. mono (F x y)) \<Longrightarrow> mono (\<lambda>z x. INF y : X x. F x y z :: 'a :: complete_lattice)"
2.145 +  by (auto intro!: INF_mono[OF bexI] simp: le_fun_def mono_def)
2.146 +
2.147 +lemma continuous_on_max:
2.148 +  fixes f g :: "'a::topological_space \<Rightarrow> 'b::linorder_topology"
2.149 +  shows "continuous_on A f \<Longrightarrow> continuous_on A g \<Longrightarrow> continuous_on A (\<lambda>x. max (f x) (g x))"
2.150 +  by (auto simp: continuous_on_def intro!: tendsto_max)
2.151 +
2.152 +lemma continuous_on_cmult_ereal:
2.153 +  "\<bar>c::ereal\<bar> \<noteq> \<infinity> \<Longrightarrow> continuous_on A f \<Longrightarrow> continuous_on A (\<lambda>x. c * f x)"
2.154 +  using tendsto_cmult_ereal[of c f "f x" "at x within A" for x]
2.155 +  by (auto simp: continuous_on_def simp del: tendsto_cmult_ereal)
2.156 +
2.157  context linordered_nonzero_semiring
2.158  begin
2.159
2.160 @@ -19,6 +169,18 @@
2.161
2.162  end
2.163
2.164 +lemma real_of_nat_Sup:
2.165 +  assumes "A \<noteq> {}" "bdd_above A"
2.166 +  shows "of_nat (Sup A) = (SUP a:A. of_nat a :: real)"
2.167 +proof (intro antisym)
2.168 +  show "(SUP a:A. of_nat a::real) \<le> of_nat (Sup A)"
2.169 +    using assms by (intro cSUP_least of_nat_mono) (auto intro: cSup_upper)
2.170 +  have "Sup A \<in> A"
2.171 +    unfolding Sup_nat_def using assms by (intro Max_in) (auto simp: bdd_above_nat)
2.172 +  then show "of_nat (Sup A) \<le> (SUP a:A. of_nat a::real)"
2.173 +    by (intro cSUP_upper bdd_above_image_mono assms) (auto simp: mono_def)
2.174 +qed
2.175 +
2.176  lemma of_nat_less[simp]:
2.177    "i < j \<Longrightarrow> of_nat i < (of_nat j::'a::{linordered_nonzero_semiring, semiring_char_0})"
2.178    by (auto simp: less_le)
2.179 @@ -58,22 +220,30 @@
2.180    shows "summable f \<Longrightarrow> finite I \<Longrightarrow> \<forall>m\<in>- I. 0 \<le> f m \<Longrightarrow> setsum f I \<le> suminf f"
2.181    by (rule sums_le[OF _ sums_If_finite_set summable_sums]) auto
2.182
2.183 +subsection \<open>Defining the extended non-negative reals\<close>
2.184 +
2.185 +text \<open>Basic definitions and type class setup\<close>
2.186 +
2.187  typedef ennreal = "{x :: ereal. 0 \<le> x}"
2.188    morphisms enn2ereal e2ennreal'
2.189    by auto
2.190
2.191  definition "e2ennreal x = e2ennreal' (max 0 x)"
2.192
2.193 +lemma enn2ereal_range: "e2ennreal ` {0..} = UNIV"
2.194 +proof -
2.195 +  have "\<exists>y\<ge>0. x = e2ennreal y" for x
2.196 +    by (cases x) (auto simp: e2ennreal_def max_absorb2)
2.197 +  then show ?thesis
2.198 +    by (auto simp: image_iff Bex_def)
2.199 +qed
2.200 +
2.201  lemma type_definition_ennreal': "type_definition enn2ereal e2ennreal {x. 0 \<le> x}"
2.202    using type_definition_ennreal
2.203    by (auto simp: type_definition_def e2ennreal_def max_absorb2)
2.204
2.205  setup_lifting type_definition_ennreal'
2.206
2.207 -lift_definition ennreal :: "real \<Rightarrow> ennreal" is "sup 0 \<circ> ereal"
2.208 -  by simp
2.209 -
2.210 -declare [[coercion ennreal]]
2.211  declare [[coercion e2ennreal]]
2.212
2.213  instantiation ennreal :: complete_linorder
2.214 @@ -99,13 +269,11 @@
2.215
2.216  end
2.217
2.218 -lemma ennreal_cases:
2.219 -  fixes x :: ennreal
2.220 -  obtains (real) r :: real where "0 \<le> r" "x = ennreal r" | (top) "x = top"
2.221 -  apply transfer
2.222 -  subgoal for x thesis
2.223 -    by (cases x) (auto simp: max.absorb2 top_ereal_def)
2.224 -  done
2.225 +lemma pcr_ennreal_enn2ereal[simp]: "pcr_ennreal (enn2ereal x) x"
2.226 +  by (simp add: ennreal.pcr_cr_eq cr_ennreal_def)
2.227 +
2.228 +lemma rel_fun_eq_pcr_ennreal: "rel_fun op = pcr_ennreal f g \<longleftrightarrow> f = enn2ereal \<circ> g"
2.229 +  by (auto simp: rel_fun_def ennreal.pcr_cr_eq cr_ennreal_def)
2.230
2.231  instantiation ennreal :: infinity
2.232  begin
2.233 @@ -156,7 +324,7 @@
2.234
2.235  end
2.236
2.237 -lemma ennreal_zero_less_one: "0 < (1::ennreal)"
2.238 +lemma ennreal_zero_less_one: "0 < (1::ennreal)" -- \<open>TODO: remove \<close>
2.239    by transfer auto
2.240
2.241  instance ennreal :: dioid
2.242 @@ -173,6 +341,12 @@
2.243  instance ennreal :: linordered_nonzero_semiring
2.244    proof qed (transfer; simp)
2.245
2.247 +proof
2.248 +  fix a b c d :: ennreal show "a < b \<Longrightarrow> c < d \<Longrightarrow> a + c < b + d"
2.249 +    by transfer (auto intro!: ereal_add_strict_mono)
2.250 +qed
2.251 +
2.252  declare [[coercion "of_nat :: nat \<Rightarrow> ennreal"]]
2.253
2.254  lemma e2ennreal_neg: "x \<le> 0 \<Longrightarrow> e2ennreal x = 0"
2.255 @@ -182,6 +356,58 @@
2.256    by (cases "0 \<le> x" "0 \<le> y" rule: bool.exhaust[case_product bool.exhaust])
2.257       (auto simp: e2ennreal_neg less_eq_ennreal.abs_eq eq_onp_def)
2.258
2.259 +lemma enn2ereal_nonneg[simp]: "0 \<le> enn2ereal x"
2.260 +  using ennreal.enn2ereal[of x] by simp
2.261 +
2.262 +lemma ereal_ennreal_cases:
2.263 +  obtains b where "0 \<le> a" "a = enn2ereal b" | "a < 0"
2.264 +  using e2ennreal'_inverse[of a, symmetric] by (cases "0 \<le> a") (auto intro: enn2ereal_nonneg)
2.265 +
2.266 +lemma rel_fun_liminf[transfer_rule]: "rel_fun (rel_fun op = pcr_ennreal) pcr_ennreal liminf liminf"
2.267 +proof -
2.268 +  have "rel_fun (rel_fun op = pcr_ennreal) pcr_ennreal (\<lambda>x. sup 0 (liminf x)) liminf"
2.269 +    unfolding liminf_SUP_INF[abs_def] by (transfer_prover_start, transfer_step+; simp)
2.270 +  then show ?thesis
2.271 +    apply (subst (asm) (2) rel_fun_def)
2.272 +    apply (subst (2) rel_fun_def)
2.273 +    apply (auto simp: comp_def max.absorb2 Liminf_bounded rel_fun_eq_pcr_ennreal)
2.274 +    done
2.275 +qed
2.276 +
2.277 +lemma rel_fun_limsup[transfer_rule]: "rel_fun (rel_fun op = pcr_ennreal) pcr_ennreal limsup limsup"
2.278 +proof -
2.279 +  have "rel_fun (rel_fun op = pcr_ennreal) pcr_ennreal (\<lambda>x. INF n. sup 0 (SUP i:{n..}. x i)) limsup"
2.280 +    unfolding limsup_INF_SUP[abs_def] by (transfer_prover_start, transfer_step+; simp)
2.281 +  then show ?thesis
2.282 +    unfolding limsup_INF_SUP[abs_def]
2.283 +    apply (subst (asm) (2) rel_fun_def)
2.284 +    apply (subst (2) rel_fun_def)
2.285 +    apply (auto simp: comp_def max.absorb2 Sup_upper2 rel_fun_eq_pcr_ennreal)
2.286 +    apply (subst (asm) max.absorb2)
2.287 +    apply (rule SUP_upper2)
2.288 +    apply auto
2.289 +    done
2.290 +qed
2.291 +
2.292 +lemma setsum_enn2ereal[simp]: "(\<And>i. i \<in> I \<Longrightarrow> 0 \<le> f i) \<Longrightarrow> (\<Sum>i\<in>I. enn2ereal (f i)) = enn2ereal (setsum f I)"
2.293 +  by (induction I rule: infinite_finite_induct) (auto simp: setsum_nonneg zero_ennreal.rep_eq plus_ennreal.rep_eq)
2.294 +
2.295 +lemma transfer_e2ennreal_setsum [transfer_rule]:
2.296 +  "rel_fun (rel_fun op = pcr_ennreal) (rel_fun op = pcr_ennreal) setsum setsum"
2.297 +  by (auto intro!: rel_funI simp: rel_fun_eq_pcr_ennreal comp_def)
2.298 +
2.299 +lemma enn2ereal_of_nat[simp]: "enn2ereal (of_nat n) = ereal n"
2.300 +  by (induction n) (auto simp: zero_ennreal.rep_eq one_ennreal.rep_eq plus_ennreal.rep_eq)
2.301 +
2.302 +lemma enn2ereal_numeral[simp]: "enn2ereal (numeral a) = numeral a"
2.303 +  apply (subst of_nat_numeral[of a, symmetric])
2.304 +  apply (subst enn2ereal_of_nat)
2.305 +  apply simp
2.306 +  done
2.307 +
2.308 +lemma transfer_numeral[transfer_rule]: "pcr_ennreal (numeral a) (numeral a)"
2.309 +  unfolding cr_ennreal_def pcr_ennreal_def by auto
2.310 +
2.311  subsection \<open>Cancellation simprocs\<close>
2.312
2.313  lemma ennreal_add_left_cancel: "a + b = a + c \<longleftrightarrow> a = (\<infinity>::ennreal) \<or> b = c"
2.314 @@ -260,130 +486,8 @@
2.315    ("(l::ennreal) + m < n" | "(l::ennreal) < m + n") =
2.316    \<open>fn phi => fn ctxt => fn ct => Less_Ennreal_Cancel.proc ctxt (Thm.term_of ct)\<close>
2.317
2.318 -instantiation ennreal :: linear_continuum_topology
2.319 -begin
2.320
2.321 -definition open_ennreal :: "ennreal set \<Rightarrow> bool"
2.322 -  where "(open :: ennreal set \<Rightarrow> bool) = generate_topology (range lessThan \<union> range greaterThan)"
2.323 -
2.324 -instance
2.325 -proof
2.326 -  show "\<exists>a b::ennreal. a \<noteq> b"
2.327 -    using zero_neq_one by (intro exI)
2.328 -  show "\<And>x y::ennreal. x < y \<Longrightarrow> \<exists>z>x. z < y"
2.329 -  proof transfer
2.330 -    fix x y :: ereal assume "0 \<le> x" "x < y"
2.331 -    moreover from dense[OF this(2)] guess z ..
2.332 -    ultimately show "\<exists>z\<in>Collect (op \<le> 0). x < z \<and> z < y"
2.333 -      by (intro bexI[of _ z]) auto
2.334 -  qed
2.335 -qed (rule open_ennreal_def)
2.336 -
2.337 -end
2.338 -
2.339 -lemma ennreal_rat_dense:
2.340 -  fixes x y :: ennreal
2.341 -  shows "x < y \<Longrightarrow> \<exists>r::rat. x < real_of_rat r \<and> real_of_rat r < y"
2.342 -proof transfer
2.343 -  fix x y :: ereal assume xy: "0 \<le> x" "0 \<le> y" "x < y"
2.344 -  moreover
2.345 -  from ereal_dense3[OF \<open>x < y\<close>]
2.346 -  obtain r where "x < ereal (real_of_rat r)" "ereal (real_of_rat r) < y"
2.347 -    by auto
2.348 -  moreover then have "0 \<le> r"
2.349 -    using le_less_trans[OF \<open>0 \<le> x\<close> \<open>x < ereal (real_of_rat r)\<close>] by auto
2.350 -  ultimately show "\<exists>r. x < (sup 0 \<circ> ereal) (real_of_rat r) \<and> (sup 0 \<circ> ereal) (real_of_rat r) < y"
2.351 -    by (intro exI[of _ r]) (auto simp: max_absorb2)
2.352 -qed
2.353 -
2.354 -lemma enn2ereal_range: "e2ennreal ` {0..} = UNIV"
2.355 -proof -
2.356 -  have "\<exists>y\<ge>0. x = e2ennreal y" for x
2.357 -    by (cases x) (auto simp: e2ennreal_def max_absorb2)
2.358 -  then show ?thesis
2.359 -    by (auto simp: image_iff Bex_def)
2.360 -qed
2.361 -
2.362 -lemma enn2ereal_nonneg: "0 \<le> enn2ereal x"
2.363 -  using ennreal.enn2ereal[of x] by simp
2.364 -
2.365 -lemma ereal_ennreal_cases:
2.366 -  obtains b where "0 \<le> a" "a = enn2ereal b" | "a < 0"
2.367 -  using e2ennreal'_inverse[of a, symmetric] by (cases "0 \<le> a") (auto intro: enn2ereal_nonneg)
2.368 -
2.369 -lemma enn2ereal_Iio: "enn2ereal -` {..<a} = (if 0 \<le> a then {..< e2ennreal a} else {})"
2.370 -  using enn2ereal_nonneg
2.371 -  by (cases a rule: ereal_ennreal_cases)
2.372 -     (auto simp add: vimage_def set_eq_iff ennreal.enn2ereal_inverse less_ennreal.rep_eq e2ennreal_def max_absorb2
2.373 -           intro: le_less_trans less_imp_le)
2.374 -
2.375 -lemma enn2ereal_Ioi: "enn2ereal -` {a <..} = (if 0 \<le> a then {e2ennreal a <..} else UNIV)"
2.376 -  using enn2ereal_nonneg
2.377 -  by (cases a rule: ereal_ennreal_cases)
2.378 -     (auto simp add: vimage_def set_eq_iff ennreal.enn2ereal_inverse less_ennreal.rep_eq e2ennreal_def max_absorb2
2.379 -           intro: less_le_trans)
2.380 -
2.381 -lemma continuous_on_e2ennreal: "continuous_on A e2ennreal"
2.382 -proof (rule continuous_on_subset)
2.383 -  show "continuous_on ({0..} \<union> {..0}) e2ennreal"
2.384 -  proof (rule continuous_on_closed_Un)
2.385 -    show "continuous_on {0 ..} e2ennreal"
2.386 -      by (rule continuous_onI_mono)
2.387 -         (auto simp add: less_eq_ennreal.abs_eq eq_onp_def enn2ereal_range)
2.388 -    show "continuous_on {.. 0} e2ennreal"
2.389 -      by (subst continuous_on_cong[OF refl, of _ _ "\<lambda>_. 0"])
2.390 -         (auto simp add: e2ennreal_neg continuous_on_const)
2.391 -  qed auto
2.392 -  show "A \<subseteq> {0..} \<union> {..0::ereal}"
2.393 -    by auto
2.394 -qed
2.395 -
2.396 -lemma continuous_at_e2ennreal: "continuous (at x within A) e2ennreal"
2.397 -  by (rule continuous_on_imp_continuous_within[OF continuous_on_e2ennreal, of _ UNIV]) auto
2.398 -
2.399 -lemma continuous_on_enn2ereal: "continuous_on UNIV enn2ereal"
2.400 -  by (rule continuous_on_generate_topology[OF open_generated_order])
2.401 -     (auto simp add: enn2ereal_Iio enn2ereal_Ioi)
2.402 -
2.403 -lemma continuous_at_enn2ereal: "continuous (at x within A) enn2ereal"
2.404 -  by (rule continuous_on_imp_continuous_within[OF continuous_on_enn2ereal]) auto
2.405 -
2.406 -lemma transfer_enn2ereal_continuous_on [transfer_rule]:
2.407 -  "rel_fun (op =) (rel_fun (rel_fun op = pcr_ennreal) op =) continuous_on continuous_on"
2.408 -proof -
2.409 -  have "continuous_on A f" if "continuous_on A (\<lambda>x. enn2ereal (f x))" for A and f :: "'a \<Rightarrow> ennreal"
2.410 -    using continuous_on_compose2[OF continuous_on_e2ennreal[of "{0..}"] that]
2.411 -    by (auto simp: ennreal.enn2ereal_inverse subset_eq enn2ereal_nonneg e2ennreal_def max_absorb2)
2.412 -  moreover
2.413 -  have "continuous_on A (\<lambda>x. enn2ereal (f x))" if "continuous_on A f" for A and f :: "'a \<Rightarrow> ennreal"
2.414 -    using continuous_on_compose2[OF continuous_on_enn2ereal that] by auto
2.415 -  ultimately
2.416 -  show ?thesis
2.417 -    by (auto simp add: rel_fun_def ennreal.pcr_cr_eq cr_ennreal_def)
2.418 -qed
2.419 -
2.421 -  fixes f g :: "'a::topological_space \<Rightarrow> ennreal"
2.422 -  shows "continuous_on A f \<Longrightarrow> continuous_on A g \<Longrightarrow> continuous_on A (\<lambda>x. f x + g x)"
2.423 -  by (transfer fixing: A) (auto intro!: tendsto_add_ereal_nonneg simp: continuous_on_def)
2.424 -
2.425 -lemma continuous_on_inverse_ennreal[continuous_intros]:
2.426 -  fixes f :: "'a::topological_space \<Rightarrow> ennreal"
2.427 -  shows "continuous_on A f \<Longrightarrow> continuous_on A (\<lambda>x. inverse (f x))"
2.428 -proof (transfer fixing: A)
2.429 -  show "pred_fun (\<lambda>_. True)  (op \<le> 0) f \<Longrightarrow> continuous_on A (\<lambda>x. inverse (f x))" if "continuous_on A f"
2.430 -    for f :: "'a \<Rightarrow> ereal"
2.431 -    using continuous_on_compose2[OF continuous_on_inverse_ereal that] by (auto simp: subset_eq)
2.432 -qed
2.433 -
2.435 -proof
2.436 -  show "((\<lambda>x. fst x + snd x) \<longlongrightarrow> a + b) (nhds a \<times>\<^sub>F nhds b)" for a b :: ennreal
2.437 -    using continuous_on_add_ennreal[of UNIV fst snd]
2.438 -    using tendsto_at_iff_tendsto_nhds[symmetric, of "\<lambda>x::(ennreal \<times> ennreal). fst x + snd x"]
2.439 -    by (auto simp: continuous_on_eq_continuous_at)
2.440 -       (simp add: isCont_def nhds_prod[symmetric])
2.441 -qed
2.442 +subsection \<open>Order with top\<close>
2.443
2.444  lemma ennreal_zero_less_top[simp]: "0 < (top::ennreal)"
2.445    by transfer (simp add: top_ereal_def)
2.446 @@ -423,12 +527,90 @@
2.447    shows "finite I \<Longrightarrow> (\<Sum>i\<in>I. f i) = top \<longleftrightarrow> (\<exists>i\<in>I. f i = top)"
2.448    by (induction I rule: finite_induct) auto
2.449
2.450 +lemma ennreal_mult_eq_top_iff:
2.451 +  fixes a b :: ennreal
2.452 +  shows "a * b = top \<longleftrightarrow> (a = top \<and> b \<noteq> 0) \<or> (b = top \<and> a \<noteq> 0)"
2.453 +  by transfer (auto simp: top_ereal_def)
2.454 +
2.455 +lemma ennreal_top_eq_mult_iff:
2.456 +  fixes a b :: ennreal
2.457 +  shows "top = a * b \<longleftrightarrow> (a = top \<and> b \<noteq> 0) \<or> (b = top \<and> a \<noteq> 0)"
2.458 +  using ennreal_mult_eq_top_iff[of a b] by auto
2.459 +
2.460 +lemma ennreal_mult_less_top:
2.461 +  fixes a b :: ennreal
2.462 +  shows "a * b < top \<longleftrightarrow> (a = 0 \<or> b = 0 \<or> (a < top \<and> b < top))"
2.463 +  by transfer (auto simp add: top_ereal_def)
2.464 +
2.465 +lemma top_power_ennreal: "top ^ n = (if n = 0 then 1 else top :: ennreal)"
2.466 +  by (induction n) (simp_all add: ennreal_mult_eq_top_iff)
2.467 +
2.468 +lemma ennreal_setprod_eq_0[simp]:
2.469 +  fixes f :: "'a \<Rightarrow> ennreal"
2.470 +  shows "(setprod f A = 0) = (finite A \<and> (\<exists>i\<in>A. f i = 0))"
2.471 +  by (induction A rule: infinite_finite_induct) auto
2.472 +
2.473 +lemma ennreal_setprod_eq_top:
2.474 +  fixes f :: "'a \<Rightarrow> ennreal"
2.475 +  shows "(\<Prod>i\<in>I. f i) = top \<longleftrightarrow> (finite I \<and> ((\<forall>i\<in>I. f i \<noteq> 0) \<and> (\<exists>i\<in>I. f i = top)))"
2.476 +  by (induction I rule: infinite_finite_induct) (auto simp: ennreal_mult_eq_top_iff)
2.477 +
2.478 +lemma ennreal_top_mult: "top * a = (if a = 0 then 0 else top :: ennreal)"
2.479 +  by (simp add: ennreal_mult_eq_top_iff)
2.480 +
2.481 +lemma ennreal_mult_top: "a * top = (if a = 0 then 0 else top :: ennreal)"
2.482 +  by (simp add: ennreal_mult_eq_top_iff)
2.483 +
2.484  lemma enn2ereal_eq_top_iff[simp]: "enn2ereal x = \<infinity> \<longleftrightarrow> x = top"
2.485    by transfer (simp add: top_ereal_def)
2.486
2.487 -lemma ennreal_top_top: "top - top = (top::ennreal)"
2.488 +lemma enn2ereal_top: "enn2ereal top = \<infinity>"
2.489 +  by transfer (simp add: top_ereal_def)
2.490 +
2.491 +lemma e2ennreal_infty: "e2ennreal \<infinity> = top"
2.492 +  by (simp add: top_ennreal.abs_eq top_ereal_def)
2.493 +
2.494 +lemma ennreal_top_minus[simp]: "top - x = (top::ennreal)"
2.495    by transfer (auto simp: top_ereal_def max_def)
2.496
2.497 +lemma minus_top_ennreal: "x - top = (if x = top then top else 0:: ennreal)"
2.498 +  apply transfer
2.499 +  subgoal for x
2.500 +    by (cases x) (auto simp: top_ereal_def max_def)
2.501 +  done
2.502 +
2.503 +lemma bot_ennreal: "bot = (0::ennreal)"
2.504 +  by transfer rule
2.505 +
2.506 +lemma ennreal_of_nat_neq_top[simp]: "of_nat i \<noteq> (top::ennreal)"
2.507 +  by (induction i) auto
2.508 +
2.509 +lemma numeral_eq_of_nat: "(numeral a::ennreal) = of_nat (numeral a)"
2.510 +  by simp
2.511 +
2.512 +lemma of_nat_less_top: "of_nat i < (top::ennreal)"
2.513 +  using less_le_trans[of "of_nat i" "of_nat (Suc i)" "top::ennreal"]
2.514 +  by simp
2.515 +
2.516 +lemma top_neq_numeral[simp]: "top \<noteq> (numeral i::ennreal)"
2.517 +  using of_nat_less_top[of "numeral i"] by simp
2.518 +
2.519 +lemma ennreal_numeral_less_top[simp]: "numeral i < (top::ennreal)"
2.520 +  using of_nat_less_top[of "numeral i"] by simp
2.521 +
2.522 +lemma ennreal_add_bot[simp]: "bot + x = (x::ennreal)"
2.523 +  by transfer simp
2.524 +
2.525 +instance ennreal :: semiring_char_0
2.526 +proof (standard, safe intro!: linorder_injI)
2.527 +  have *: "1 + of_nat k \<noteq> (0::ennreal)" for k
2.528 +    using add_pos_nonneg[OF zero_less_one, of "of_nat k :: ennreal"] by auto
2.529 +  fix x y :: nat assume "x < y" "of_nat x = (of_nat y::ennreal)" then show False
2.531 +qed
2.532 +
2.533 +subsection \<open>Arithmetic\<close>
2.534 +
2.535  lemma ennreal_minus_zero[simp]: "a - (0::ennreal) = a"
2.536    by transfer (auto simp: max_def)
2.537
2.538 @@ -464,75 +646,6 @@
2.539         (auto simp: top_ereal_def max_def split: if_splits)
2.540    done
2.541
2.542 -lemma enn2ereal_ennreal[simp]: "0 \<le> x \<Longrightarrow> enn2ereal (ennreal x) = x"
2.543 -  by transfer (simp add: max_absorb2)
2.544 -
2.545 -lemma tendsto_ennrealD:
2.546 -  assumes lim: "((\<lambda>x. ennreal (f x)) \<longlongrightarrow> ennreal x) F"
2.547 -  assumes *: "\<forall>\<^sub>F x in F. 0 \<le> f x" and x: "0 \<le> x"
2.548 -  shows "(f \<longlongrightarrow> x) F"
2.549 -  using continuous_on_tendsto_compose[OF continuous_on_enn2ereal lim]
2.550 -  apply simp
2.551 -  apply (subst (asm) tendsto_cong)
2.552 -  using *
2.553 -  apply eventually_elim
2.554 -  apply (auto simp: max_absorb2 \<open>0 \<le> x\<close>)
2.555 -  done
2.556 -
2.557 -lemma tendsto_ennreal_iff[simp]:
2.558 -  "\<forall>\<^sub>F x in F. 0 \<le> f x \<Longrightarrow> 0 \<le> x \<Longrightarrow> ((\<lambda>x. ennreal (f x)) \<longlongrightarrow> ennreal x) F \<longleftrightarrow> (f \<longlongrightarrow> x) F"
2.559 -  by (auto dest: tendsto_ennrealD)
2.560 -     (auto simp: ennreal_def
2.561 -           intro!: continuous_on_tendsto_compose[OF continuous_on_e2ennreal[of UNIV]] tendsto_max)
2.562 -
2.563 -lemma ennreal_zero[simp]: "ennreal 0 = 0"
2.564 -  by (simp add: ennreal_def max.absorb1 zero_ennreal.abs_eq)
2.565 -
2.566 -lemma ennreal_plus[simp]:
2.567 -  "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> ennreal (a + b) = ennreal a + ennreal b"
2.568 -  by (transfer fixing: a b) (auto simp: max_absorb2)
2.569 -
2.570 -lemma ennreal_inj[simp]:
2.571 -  "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> ennreal a = ennreal b \<longleftrightarrow> a = b"
2.572 -  by (transfer fixing: a b) (auto simp: max_absorb2)
2.573 -
2.574 -lemma ennreal_le_iff[simp]: "0 \<le> y \<Longrightarrow> ennreal x \<le> ennreal y \<longleftrightarrow> x \<le> y"
2.575 -  by (auto simp: ennreal_def zero_ereal_def less_eq_ennreal.abs_eq eq_onp_def split: split_max)
2.576 -
2.577 -lemma setsum_ennreal[simp]: "(\<And>i. i \<in> I \<Longrightarrow> 0 \<le> f i) \<Longrightarrow> (\<Sum>i\<in>I. ennreal (f i)) = ennreal (setsum f I)"
2.578 -  by (induction I rule: infinite_finite_induct) (auto simp: setsum_nonneg)
2.579 -
2.580 -lemma sums_ennreal[simp]: "(\<And>i. 0 \<le> f i) \<Longrightarrow> 0 \<le> x \<Longrightarrow> (\<lambda>i. ennreal (f i)) sums ennreal x \<longleftrightarrow> f sums x"
2.581 -  unfolding sums_def by (simp add: always_eventually setsum_nonneg)
2.582 -
2.583 -lemma summable_suminf_not_top: "(\<And>i. 0 \<le> f i) \<Longrightarrow> (\<Sum>i. ennreal (f i)) \<noteq> top \<Longrightarrow> summable f"
2.584 -  using summable_sums[OF summableI, of "\<lambda>i. ennreal (f i)"]
2.585 -  by (cases "\<Sum>i. ennreal (f i)" rule: ennreal_cases)
2.586 -     (auto simp: summable_def)
2.587 -
2.588 -lemma suminf_ennreal[simp]:
2.589 -  "(\<And>i. 0 \<le> f i) \<Longrightarrow> (\<Sum>i. ennreal (f i)) \<noteq> top \<Longrightarrow> (\<Sum>i. ennreal (f i)) = ennreal (\<Sum>i. f i)"
2.590 -  by (rule sums_unique[symmetric]) (simp add: summable_suminf_not_top suminf_nonneg summable_sums)
2.591 -
2.592 -lemma suminf_less_top: "(\<Sum>i. f i :: ennreal) < top \<Longrightarrow> f i < top"
2.593 -  using le_less_trans[OF setsum_le_suminf[OF summableI, of "{i}" f]] by simp
2.594 -
2.596 -  fixes x :: "'a::{order_top, ordered_comm_monoid_add}"
2.597 -  shows "0 \<le> x \<Longrightarrow> x + top = top"
2.598 -  by (intro top_le add_increasing order_refl)
2.599 -
2.601 -  fixes x :: "'a::{order_top, ordered_comm_monoid_add}"
2.602 -  shows "0 \<le> x \<Longrightarrow> top + x = top"
2.603 -  by (intro top_le add_increasing2 order_refl)
2.604 -
2.605 -lemma enn2ereal_top: "enn2ereal top = \<infinity>"
2.606 -  by transfer (simp add: top_ereal_def)
2.607 -
2.608 -lemma e2ennreal_infty: "e2ennreal \<infinity> = top"
2.609 -  by (simp add: top_ennreal.abs_eq top_ereal_def)
2.610 -
2.612    fixes a b c :: "ennreal"
2.613    shows "sup (c + a) (c + b) = c + sup a b"
2.614 @@ -546,337 +659,14 @@
2.615      done
2.616    done
2.617
2.618 -lemma bot_ennreal: "bot = (0::ennreal)"
2.619 -  by transfer rule
2.620 -
2.621 -lemma le_lfp: "mono f \<Longrightarrow> x \<le> lfp f \<Longrightarrow> f x \<le> lfp f"
2.622 -  by (subst lfp_unfold) (auto dest: monoD)
2.623 -
2.624 -lemma lfp_transfer:
2.625 -  assumes \<alpha>: "sup_continuous \<alpha>" and f: "sup_continuous f" and mg: "mono g"
2.626 -  assumes bot: "\<alpha> bot \<le> lfp g" and eq: "\<And>x. x \<le> lfp f \<Longrightarrow> \<alpha> (f x) = g (\<alpha> x)"
2.627 -  shows "\<alpha> (lfp f) = lfp g"
2.628 -proof (rule antisym)
2.629 -  note mf = sup_continuous_mono[OF f]
2.630 -  have f_le_lfp: "(f ^^ i) bot \<le> lfp f" for i
2.631 -    by (induction i) (auto intro: le_lfp mf)
2.632 -
2.633 -  have "\<alpha> ((f ^^ i) bot) \<le> lfp g" for i
2.634 -    by (induction i) (auto simp: bot eq f_le_lfp intro!: le_lfp mg)
2.635 -  then show "\<alpha> (lfp f) \<le> lfp g"
2.636 -    unfolding sup_continuous_lfp[OF f]
2.637 -    by (subst \<alpha>[THEN sup_continuousD])
2.638 -       (auto intro!: mono_funpow sup_continuous_mono[OF f] SUP_least)
2.639 -
2.640 -  show "lfp g \<le> \<alpha> (lfp f)"
2.641 -    by (rule lfp_lowerbound) (simp add: eq[symmetric] lfp_unfold[OF mf, symmetric])
2.642 -qed
2.643 -
2.644 -lemma sup_continuous_applyD: "sup_continuous f \<Longrightarrow> sup_continuous (\<lambda>x. f x h)"
2.645 -  using sup_continuous_apply[THEN sup_continuous_compose] .
2.646 -
2.648 -  fixes f g :: "nat \<Rightarrow> ennreal"
2.649 -  shows "(INF i. f i + c) = (INF i. f i) + c"
2.650 -  using continuous_at_Inf_mono[of "\<lambda>x. x + c" "f`UNIV"]
2.651 -  using continuous_add[of "at_right (Inf (range f))", of "\<lambda>x. x" "\<lambda>x. c"]
2.652 -  by (auto simp: mono_def)
2.653 -
2.655 -  fixes f g :: "nat \<Rightarrow> ennreal"
2.656 -  shows "(INF i. c + f i) = c + (INF i. f i)"
2.658 -
2.659 -lemma sup_continuous_e2ennreal[order_continuous_intros]:
2.660 -  assumes f: "sup_continuous f" shows "sup_continuous (\<lambda>x. e2ennreal (f x))"
2.661 -  apply (rule sup_continuous_compose[OF _ f])
2.662 -  apply (rule continuous_at_left_imp_sup_continuous)
2.663 -  apply (auto simp: mono_def e2ennreal_mono continuous_at_e2ennreal)
2.664 -  done
2.665 -
2.666 -lemma sup_continuous_enn2ereal[order_continuous_intros]:
2.667 -  assumes f: "sup_continuous f" shows "sup_continuous (\<lambda>x. enn2ereal (f x))"
2.668 -  apply (rule sup_continuous_compose[OF _ f])
2.669 -  apply (rule continuous_at_left_imp_sup_continuous)
2.670 -  apply (simp_all add: mono_def less_eq_ennreal.rep_eq continuous_at_enn2ereal)
2.671 -  done
2.672 -
2.673 -lemma ennreal_1[simp]: "ennreal 1 = 1"
2.674 -  by transfer (simp add: max_absorb2)
2.675 -
2.676 -lemma ennreal_of_nat_eq_real_of_nat: "of_nat i = ennreal (of_nat i)"
2.677 -  by (induction i) simp_all
2.678 -
2.679 -lemma ennreal_SUP_of_nat_eq_top: "(SUP x. of_nat x :: ennreal) = top"
2.680 -proof (intro antisym top_greatest le_SUP_iff[THEN iffD2] allI impI)
2.681 -  fix y :: ennreal assume "y < top"
2.682 -  then obtain r where "y = ennreal r"
2.683 -    by (cases y rule: ennreal_cases) auto
2.684 -  then show "\<exists>i\<in>UNIV. y < of_nat i"
2.685 -    using reals_Archimedean2[of "max 1 r"] zero_less_one
2.686 -    by (auto simp: ennreal_of_nat_eq_real_of_nat ennreal_def less_ennreal.abs_eq eq_onp_def max.absorb2
2.687 -             dest!: one_less_of_natD intro: less_trans)
2.688 -qed
2.689 -
2.690 -lemma ennreal_SUP_eq_top:
2.691 -  fixes f :: "'a \<Rightarrow> ennreal"
2.692 -  assumes "\<And>n. \<exists>i\<in>I. of_nat n \<le> f i"
2.693 -  shows "(SUP i : I. f i) = top"
2.694 -proof -
2.695 -  have "(SUP x. of_nat x :: ennreal) \<le> (SUP i : I. f i)"
2.696 -    using assms by (auto intro!: SUP_least intro: SUP_upper2)
2.697 -  then show ?thesis
2.698 -    by (auto simp: ennreal_SUP_of_nat_eq_top top_unique)
2.699 -qed
2.700 -
2.701 -lemma sup_continuous_SUP[order_continuous_intros]:
2.702 -  fixes M :: "_ \<Rightarrow> _ \<Rightarrow> 'a::complete_lattice"
2.703 -  assumes M: "\<And>i. i \<in> I \<Longrightarrow> sup_continuous (M i)"
2.704 -  shows  "sup_continuous (SUP i:I. M i)"
2.705 -  unfolding sup_continuous_def by (auto simp add: sup_continuousD[OF M] intro: SUP_commute)
2.706 -
2.707 -lemma sup_continuous_apply_SUP[order_continuous_intros]:
2.708 -  fixes M :: "_ \<Rightarrow> _ \<Rightarrow> 'a::complete_lattice"
2.709 -  shows "(\<And>i. i \<in> I \<Longrightarrow> sup_continuous (M i)) \<Longrightarrow> sup_continuous (\<lambda>x. SUP i:I. M i x)"
2.710 -  unfolding SUP_apply[symmetric] by (rule sup_continuous_SUP)
2.711 -
2.712 -lemma sup_continuous_lfp'[order_continuous_intros]:
2.713 -  assumes 1: "sup_continuous f"
2.714 -  assumes 2: "\<And>g. sup_continuous g \<Longrightarrow> sup_continuous (f g)"
2.715 -  shows "sup_continuous (lfp f)"
2.716 -proof -
2.717 -  have "sup_continuous ((f ^^ i) bot)" for i
2.718 -  proof (induction i)
2.719 -    case (Suc i) then show ?case
2.720 -      by (auto intro!: 2)
2.721 -  qed (simp add: bot_fun_def sup_continuous_const)
2.722 -  then show ?thesis
2.723 -    unfolding sup_continuous_lfp[OF 1] by (intro order_continuous_intros)
2.724 -qed
2.725 -
2.726 -lemma sup_continuous_lfp''[order_continuous_intros]:
2.727 -  assumes 1: "\<And>s. sup_continuous (f s)"
2.728 -  assumes 2: "\<And>g. sup_continuous g \<Longrightarrow> sup_continuous (\<lambda>s. f s (g s))"
2.729 -  shows "sup_continuous (\<lambda>x. lfp (f x))"
2.730 -proof -
2.731 -  have "sup_continuous (\<lambda>x. (f x ^^ i) bot)" for i
2.732 -  proof (induction i)
2.733 -    case (Suc i) then show ?case
2.734 -      by (auto intro!: 2)
2.735 -  qed (simp add: bot_fun_def sup_continuous_const)
2.736 -  then show ?thesis
2.737 -    unfolding sup_continuous_lfp[OF 1] by (intro order_continuous_intros)
2.738 -qed
2.739 -
2.740 -lemma ennreal_INF_const_minus:
2.741 -  fixes f :: "'a \<Rightarrow> ennreal"
2.742 -  shows "I \<noteq> {} \<Longrightarrow> (SUP x:I. c - f x) = c - (INF x:I. f x)"
2.743 -  by (transfer fixing: I)
2.744 -     (simp add: sup_max[symmetric] SUP_sup_const1 SUP_ereal_minus_right del: sup_ereal_def)
2.745 -
2.747    fixes a b c :: ennreal
2.748    shows "a \<le> b \<Longrightarrow> c + b - a = c + (b - a)"
2.749    apply transfer
2.750    subgoal for a b c
2.751 -    apply (cases a b c rule: ereal3_cases)
2.752 -    apply (auto simp: field_simps max_absorb2)
2.753 -    done
2.754 -  done
2.755 -
2.756 -lemma ennreal_top_minus[simp]:
2.757 -  fixes c :: ennreal
2.758 -  shows "top - c = top"
2.759 -  by transfer (auto simp: top_ereal_def max_absorb2)
2.760 -
2.761 -lemma le_ennreal_iff:
2.762 -  "0 \<le> r \<Longrightarrow> x \<le> ennreal r \<longleftrightarrow> (\<exists>q\<ge>0. x = ennreal q \<and> q \<le> r)"
2.763 -  apply (transfer fixing: r)
2.764 -  subgoal for x
2.765 -    by (cases x) (auto simp: max_absorb2 cong: conj_cong)
2.766 +    by (cases a b c rule: ereal3_cases) (auto simp: field_simps max_absorb2)
2.767    done
2.768
2.769 -lemma ennreal_minus: "0 \<le> q \<Longrightarrow> q \<le> r \<Longrightarrow> ennreal r - ennreal q = ennreal (r - q)"
2.770 -  by transfer (simp add: max_absorb2)
2.771 -
2.772 -lemma ennreal_tendsto_const_minus:
2.773 -  fixes g :: "'a \<Rightarrow> ennreal"
2.774 -  assumes ae: "\<forall>\<^sub>F x in F. g x \<le> c"
2.775 -  assumes g: "((\<lambda>x. c - g x) \<longlongrightarrow> 0) F"
2.776 -  shows "(g \<longlongrightarrow> c) F"
2.777 -proof (cases c rule: ennreal_cases)
2.778 -  case top with tendsto_unique[OF _ g, of "top"] show ?thesis
2.779 -    by (cases "F = bot") auto
2.780 -next
2.781 -  case (real r)
2.782 -  then have "\<forall>x. \<exists>q\<ge>0. g x \<le> c \<longrightarrow> (g x = ennreal q \<and> q \<le> r)"
2.783 -    by (auto simp: le_ennreal_iff)
2.784 -  then obtain f where *: "\<And>x. g x \<le> c \<Longrightarrow> 0 \<le> f x" "\<And>x. g x \<le> c \<Longrightarrow> g x = ennreal (f x)" "\<And>x. g x \<le> c \<Longrightarrow> f x \<le> r"
2.785 -    by metis
2.786 -  from ae have ae2: "\<forall>\<^sub>F x in F. c - g x = ennreal (r - f x) \<and> f x \<le> r \<and> g x = ennreal (f x) \<and> 0 \<le> f x"
2.787 -  proof eventually_elim
2.788 -    fix x assume "g x \<le> c" with *[of x] \<open>0 \<le> r\<close> show "c - g x = ennreal (r - f x) \<and> f x \<le> r \<and> g x = ennreal (f x) \<and> 0 \<le> f x"
2.789 -      by (auto simp: real ennreal_minus)
2.790 -  qed
2.791 -  with g have "((\<lambda>x. ennreal (r - f x)) \<longlongrightarrow> ennreal 0) F"
2.792 -    by (auto simp add: tendsto_cong eventually_conj_iff)
2.793 -  with ae2 have "((\<lambda>x. r - f x) \<longlongrightarrow> 0) F"
2.794 -    by (subst (asm) tendsto_ennreal_iff) (auto elim: eventually_mono)
2.795 -  then have "(f \<longlongrightarrow> r) F"
2.796 -    by (rule Lim_transform2[OF tendsto_const])
2.797 -  with ae2 have "((\<lambda>x. ennreal (f x)) \<longlongrightarrow> ennreal r) F"
2.798 -    by (subst tendsto_ennreal_iff) (auto elim: eventually_mono simp: real)
2.799 -  with ae2 show ?thesis
2.800 -    by (auto simp: real tendsto_cong eventually_conj_iff)
2.801 -qed
2.802 -
2.804 -  fixes a b :: ereal
2.805 -  shows "\<bar>b\<bar> \<noteq> \<infinity> \<Longrightarrow> (a + b) - b = a"
2.806 -  by (cases a b rule: ereal2_cases) auto
2.807 -
2.809 -  fixes a b :: ennreal
2.810 -  shows "b \<noteq> \<infinity> \<Longrightarrow> (a + b) - b = a"
2.811 -  unfolding infinity_ennreal_def
2.813 -
2.814 -lemma ennreal_mult_eq_top_iff:
2.815 -  fixes a b :: ennreal
2.816 -  shows "a * b = top \<longleftrightarrow> (a = top \<and> b \<noteq> 0) \<or> (b = top \<and> a \<noteq> 0)"
2.817 -  by transfer (auto simp: top_ereal_def)
2.818 -
2.819 -lemma ennreal_top_eq_mult_iff:
2.820 -  fixes a b :: ennreal
2.821 -  shows "top = a * b \<longleftrightarrow> (a = top \<and> b \<noteq> 0) \<or> (b = top \<and> a \<noteq> 0)"
2.822 -  using ennreal_mult_eq_top_iff[of a b] by auto
2.823 -
2.824 -lemma ennreal_mult: "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> ennreal (a * b) = ennreal a * ennreal b"
2.825 -  by transfer (simp add: max_absorb2)
2.826 -
2.827 -lemma setsum_enn2ereal[simp]: "(\<And>i. i \<in> I \<Longrightarrow> 0 \<le> f i) \<Longrightarrow> (\<Sum>i\<in>I. enn2ereal (f i)) = enn2ereal (setsum f I)"
2.828 -  by (induction I rule: infinite_finite_induct) (auto simp: setsum_nonneg zero_ennreal.rep_eq plus_ennreal.rep_eq)
2.829 -
2.830 -lemma e2ennreal_enn2ereal[simp]: "e2ennreal (enn2ereal x) = x"
2.831 -  by (simp add: e2ennreal_def max_absorb2 enn2ereal_nonneg ennreal.enn2ereal_inverse)
2.832 -
2.833 -lemma tendsto_enn2ereal_iff[simp]: "((\<lambda>i. enn2ereal (f i)) \<longlongrightarrow> enn2ereal x) F \<longleftrightarrow> (f \<longlongrightarrow> x) F"
2.834 -  using continuous_on_enn2ereal[THEN continuous_on_tendsto_compose, of f x F]
2.835 -    continuous_on_e2ennreal[THEN continuous_on_tendsto_compose, of "\<lambda>x. enn2ereal (f x)" "enn2ereal x" F UNIV]
2.836 -  by auto
2.837 -
2.838 -lemma sums_enn2ereal[simp]: "(\<lambda>i. enn2ereal (f i)) sums enn2ereal x \<longleftrightarrow> f sums x"
2.839 -  unfolding sums_def by (simp add: always_eventually setsum_nonneg setsum_enn2ereal)
2.840 -
2.841 -lemma suminf_enn2real[simp]: "(\<Sum>i. enn2ereal (f i)) = enn2ereal (suminf f)"
2.842 -  by (rule sums_unique[symmetric]) (simp add: summable_sums)
2.843 -
2.844 -lemma pcr_ennreal_enn2ereal[simp]: "pcr_ennreal (enn2ereal x) x"
2.845 -  by (simp add: ennreal.pcr_cr_eq cr_ennreal_def)
2.846 -
2.847 -lemma rel_fun_eq_pcr_ennreal: "rel_fun op = pcr_ennreal f g \<longleftrightarrow> f = enn2ereal \<circ> g"
2.848 -  by (auto simp: rel_fun_def ennreal.pcr_cr_eq cr_ennreal_def)
2.849 -
2.850 -lemma transfer_e2ennreal_suminf [transfer_rule]: "rel_fun (rel_fun op = pcr_ennreal) pcr_ennreal suminf suminf"
2.851 -  by (auto simp: rel_funI rel_fun_eq_pcr_ennreal comp_def)
2.852 -
2.853 -lemma ennreal_suminf_cmult[simp]: "(\<Sum>i. r * f i) = r * (\<Sum>i. f i::ennreal)"
2.854 -  by transfer (auto intro!: suminf_cmult_ereal)
2.855 -
2.856 -lemma ennreal_suminf_SUP_eq_directed:
2.857 -  fixes f :: "'a \<Rightarrow> nat \<Rightarrow> ennreal"
2.858 -  assumes *: "\<And>N i j. i \<in> I \<Longrightarrow> j \<in> I \<Longrightarrow> finite N \<Longrightarrow> \<exists>k\<in>I. \<forall>n\<in>N. f i n \<le> f k n \<and> f j n \<le> f k n"
2.859 -  shows "(\<Sum>n. SUP i:I. f i n) = (SUP i:I. \<Sum>n. f i n)"
2.860 -proof cases
2.861 -  assume "I \<noteq> {}"
2.862 -  then obtain i where "i \<in> I" by auto
2.863 -  from * show ?thesis
2.864 -    by (transfer fixing: I)
2.865 -       (auto simp: max_absorb2 SUP_upper2[OF \<open>i \<in> I\<close>] suminf_nonneg summable_ereal_pos \<open>I \<noteq> {}\<close>
2.866 -             intro!: suminf_SUP_eq_directed)
2.868 -
2.869 -lemma ennreal_eq_zero_iff[simp]: "0 \<le> x \<Longrightarrow> ennreal x = 0 \<longleftrightarrow> x = 0"
2.870 -  by transfer (auto simp: max_absorb2)
2.871 -
2.872 -lemma ennreal_neq_top[simp]: "ennreal r \<noteq> top"
2.873 -  by transfer (simp add: top_ereal_def zero_ereal_def ereal_max[symmetric] del: ereal_max)
2.874 -
2.875 -lemma ennreal_of_nat_neq_top[simp]: "of_nat i \<noteq> (top::ennreal)"
2.876 -  by (induction i) auto
2.877 -
2.878 -lemma ennreal_suminf_neq_top: "summable f \<Longrightarrow> (\<And>i. 0 \<le> f i) \<Longrightarrow> (\<Sum>i. ennreal (f i)) \<noteq> top"
2.879 -  using sums_ennreal[of f "suminf f"]
2.880 -  by (simp add: suminf_nonneg sums_unique[symmetric] summable_sums_iff[symmetric] del: sums_ennreal)
2.881 -
2.882 -instance ennreal :: semiring_char_0
2.883 -proof (standard, safe intro!: linorder_injI)
2.884 -  have *: "1 + of_nat k \<noteq> (0::ennreal)" for k
2.885 -    using add_pos_nonneg[OF zero_less_one, of "of_nat k :: ennreal"] by auto
2.886 -  fix x y :: nat assume "x < y" "of_nat x = (of_nat y::ennreal)" then show False
2.888 -qed
2.889 -
2.890 -lemma ennreal_suminf_lessD: "(\<Sum>i. f i :: ennreal) < x \<Longrightarrow> f i < x"
2.891 -  using le_less_trans[OF setsum_le_suminf[OF summableI, of "{i}" f]] by simp
2.892 -
2.893 -lemma ennreal_less_top[simp]: "ennreal x < top"
2.894 -  by transfer (simp add: top_ereal_def max_def)
2.895 -
2.896 -lemma ennreal_le_epsilon:
2.897 -  "(\<And>e::real. y < top \<Longrightarrow> 0 < e \<Longrightarrow> x \<le> y + ennreal e) \<Longrightarrow> x \<le> y"
2.898 -  apply (cases y rule: ennreal_cases)
2.899 -  apply (cases x rule: ennreal_cases)
2.900 -  apply (auto simp del: ennreal_plus simp add: top_unique ennreal_plus[symmetric]
2.901 -    intro: zero_less_one field_le_epsilon)
2.902 -  done
2.903 -
2.904 -lemma ennreal_less_zero_iff[simp]: "0 < ennreal x \<longleftrightarrow> 0 < x"
2.905 -  by transfer (auto simp: max_def)
2.906 -
2.907 -lemma suminf_ennreal_eq:
2.908 -  "(\<And>i. 0 \<le> f i) \<Longrightarrow> f sums x \<Longrightarrow> (\<Sum>i. ennreal (f i)) = ennreal x"
2.909 -  using suminf_nonneg[of f] sums_unique[of f x]
2.910 -  by (intro sums_unique[symmetric]) (auto simp: summable_sums_iff)
2.911 -
2.912 -lemma transfer_e2ennreal_sumset [transfer_rule]:
2.913 -  "rel_fun (rel_fun op = pcr_ennreal) (rel_fun op = pcr_ennreal) setsum setsum"
2.914 -  by (auto intro!: rel_funI simp: rel_fun_eq_pcr_ennreal comp_def)
2.915 -
2.917 -  fixes f :: "nat \<Rightarrow> ennreal"
2.918 -  shows "(\<And>N. (\<Sum>n<N. f n) + y \<le> x) \<Longrightarrow> suminf f + y \<le> x"
2.919 -  by transfer (auto intro!: suminf_bound_add)
2.920 -
2.921 -lemma divide_right_mono_ennreal:
2.922 -  fixes a b c :: ennreal
2.923 -  shows "a \<le> b \<Longrightarrow> a / c \<le> b / c"
2.924 -  unfolding divide_ennreal_def by (intro mult_mono) auto
2.925 -
2.926 -lemma SUP_mult_left_ennreal: "c * (SUP i:I. f i) = (SUP i:I. c * f i ::ennreal)"
2.927 -proof cases
2.928 -  assume "I \<noteq> {}" then show ?thesis
2.929 -    by transfer (auto simp add: SUP_ereal_mult_left max_absorb2 SUP_upper2)
2.931 -
2.932 -lemma SUP_mult_right_ennreal: "(SUP i:I. f i) * c = (SUP i:I. f i * c ::ennreal)"
2.933 -  using SUP_mult_left_ennreal by (simp add: mult.commute)
2.934 -
2.935 -lemma SUP_divide_ennreal: "(SUP i:I. f i) / c = (SUP i:I. f i / c ::ennreal)"
2.936 -  using SUP_mult_right_ennreal by (simp add: divide_ennreal_def)
2.937 -
2.938 -lemma of_nat_Sup_ennreal:
2.939 -  assumes "A \<noteq> {}" "bdd_above A"
2.940 -  shows "of_nat (Sup A) = (SUP a:A. of_nat a :: ennreal)"
2.941 -proof (intro antisym)
2.942 -  show "(SUP a:A. of_nat a::ennreal) \<le> of_nat (Sup A)"
2.943 -    by (intro SUP_least of_nat_mono) (auto intro: cSup_upper assms)
2.944 -  have "Sup A \<in> A"
2.945 -    unfolding Sup_nat_def using assms by (intro Max_in) (auto simp: bdd_above_nat)
2.946 -  then show "of_nat (Sup A) \<le> (SUP a:A. of_nat a::ennreal)"
2.947 -    by (intro SUP_upper)
2.948 -qed
2.949 -
2.950  lemma mult_divide_eq_ennreal:
2.951    fixes a b :: ennreal
2.952    shows "b \<noteq> 0 \<Longrightarrow> b \<noteq> top \<Longrightarrow> (a * b) / b = a"
2.953 @@ -895,16 +685,6 @@
2.954      done
2.955    done
2.956
2.957 -lemma ennreal_power: "0 \<le> r \<Longrightarrow> ennreal r ^ n = ennreal (r ^ n)"
2.958 -  by (induction n) (auto simp: ennreal_mult)
2.959 -
2.960 -lemma top_power_ennreal: "top ^ n = (if n = 0 then 1 else top :: ennreal)"
2.961 -  by (induction n) (simp_all add: ennreal_mult_eq_top_iff)
2.962 -
2.963 -lemma power_eq_top_ennreal: "x ^ n = top \<longleftrightarrow> (n \<noteq> 0 \<and> (x::ennreal) = top)"
2.964 -  by (cases x rule: ennreal_cases)
2.965 -     (auto simp: ennreal_power top_power_ennreal)
2.966 -
2.967  lemma ennreal_mult_divide_eq:
2.968    fixes a b :: ennreal
2.969    shows "b \<noteq> 0 \<Longrightarrow> b \<noteq> top \<Longrightarrow> (a * b) / b = a"
2.970 @@ -914,69 +694,11 @@
2.971    apply (simp add: top_ereal_def divide_ereal_def[symmetric])
2.972    done
2.973
2.974 -lemma enn2ereal_of_nat[simp]: "enn2ereal (of_nat n) = ereal n"
2.975 -  by (induction n) (auto simp: zero_ennreal.rep_eq one_ennreal.rep_eq plus_ennreal.rep_eq)
2.976 -
2.977 -lemma enn2ereal_numeral[simp]: "enn2ereal (numeral a) = numeral a"
2.978 -  apply (subst of_nat_numeral[of a, symmetric])
2.979 -  apply (subst enn2ereal_of_nat)
2.980 -  apply simp
2.981 -  done
2.982 -
2.983 -lemma transfer_numeral[transfer_rule]: "pcr_ennreal (numeral a) (numeral a)"
2.984 -  unfolding cr_ennreal_def pcr_ennreal_def by auto
2.985 -
2.986 -lemma ennreal_half[simp]: "ennreal (1/2) = inverse 2"
2.987 -  by transfer (simp add: max.absorb2)
2.988 -
2.989 -lemma numeral_eq_of_nat: "(numeral a::ennreal) = of_nat (numeral a)"
2.990 -  by simp
2.991 -
2.992 -lemma of_nat_less_top: "of_nat i < (top::ennreal)"
2.993 -  using less_le_trans[of "of_nat i" "of_nat (Suc i)" "top::ennreal"]
2.994 -  by simp
2.995 -
2.996 -lemma top_neq_numeral[simp]: "top \<noteq> ((numeral i)::ennreal)"
2.997 -  using of_nat_less_top[of "numeral i"] by simp
2.998 -
2.999 -lemma sup_continuous_mult_left_ennreal':
2.1000 -  fixes c :: "ennreal"
2.1001 -  shows "sup_continuous (\<lambda>x. c * x)"
2.1002 -  unfolding sup_continuous_def
2.1003 -  by transfer (auto simp: SUP_ereal_mult_left max.absorb2 SUP_upper2)
2.1004 -
2.1005 -lemma sup_continuous_mult_left_ennreal[order_continuous_intros]:
2.1006 -  "sup_continuous f \<Longrightarrow> sup_continuous (\<lambda>x. c * f x :: ennreal)"
2.1007 -  by (rule sup_continuous_compose[OF sup_continuous_mult_left_ennreal'])
2.1008 -
2.1009 -lemma sup_continuous_mult_right_ennreal[order_continuous_intros]:
2.1010 -  "sup_continuous f \<Longrightarrow> sup_continuous (\<lambda>x. f x * c :: ennreal)"
2.1011 -  using sup_continuous_mult_left_ennreal[of f c] by (simp add: mult.commute)
2.1012 -
2.1013 -lemma sup_continuous_divide_ennreal[order_continuous_intros]:
2.1014 -  fixes f g :: "'a::complete_lattice \<Rightarrow> ennreal"
2.1015 -  shows "sup_continuous f \<Longrightarrow> sup_continuous (\<lambda>x. f x / c)"
2.1016 -  unfolding divide_ennreal_def by (rule sup_continuous_mult_right_ennreal)
2.1017 -
2.1018 -lemma ennreal_add_bot[simp]: "bot + x = (x::ennreal)"
2.1019 -  by transfer simp
2.1020 -
2.1021 -lemma sup_continuous_transfer[transfer_rule]:
2.1022 -  "(rel_fun (rel_fun (op =) pcr_ennreal) op =) sup_continuous sup_continuous"
2.1023 -proof (safe intro!: rel_funI dest!: rel_fun_eq_pcr_ennreal[THEN iffD1])
2.1024 -  show "sup_continuous (enn2ereal \<circ> f) \<Longrightarrow> sup_continuous f" for f :: "'a \<Rightarrow> _"
2.1025 -    using sup_continuous_e2ennreal[of "enn2ereal \<circ> f"] by simp
2.1026 -  show "sup_continuous f \<Longrightarrow> sup_continuous (enn2ereal \<circ> f)" for f :: "'a \<Rightarrow> _"
2.1027 -    using sup_continuous_enn2ereal[of f] by (simp add: comp_def)
2.1028 -qed
2.1029 -
2.1031 -  fixes f g :: "'a::complete_lattice \<Rightarrow> ennreal"
2.1032 -  shows "sup_continuous f \<Longrightarrow> sup_continuous g \<Longrightarrow> sup_continuous (\<lambda>x. f x + g x)"
2.1033 -  by transfer (auto intro!: sup_continuous_add)
2.1034 -
2.1035 -lemmas ennreal2_cases = ennreal_cases[case_product ennreal_cases]
2.1036 -lemmas ennreal3_cases = ennreal_cases[case_product ennreal2_cases]
2.1038 +  fixes a b :: ennreal
2.1039 +  shows "b \<noteq> \<infinity> \<Longrightarrow> (a + b) - b = a"
2.1040 +  unfolding infinity_ennreal_def
2.1042
2.1043  lemma ennreal_minus_eq_0:
2.1044    "a - b = 0 \<Longrightarrow> a \<le> (b::ennreal)"
2.1045 @@ -1011,121 +733,6 @@
2.1046      by (cases a b rule: ereal2_cases) (auto simp: less_max_iff_disj)
2.1047    done
2.1048
2.1050 -  fixes f g :: "nat \<Rightarrow> ennreal"
2.1051 -  shows "incseq f \<Longrightarrow> incseq g \<Longrightarrow> (SUP i. f i + g i) = SUPREMUM UNIV f + SUPREMUM UNIV g"
2.1052 -  unfolding incseq_def le_fun_def
2.1053 -  by transfer
2.1055 -
2.1056 -lemma ennreal_top_mult: "top * a = (if a = 0 then 0 else top :: ennreal)"
2.1057 -  by (simp add: ennreal_mult_eq_top_iff)
2.1058 -
2.1059 -lemma ennreal_mult_top: "a * top = (if a = 0 then 0 else top :: ennreal)"
2.1060 -  by (simp add: ennreal_mult_eq_top_iff)
2.1061 -
2.1062 -lemma ennreal_less: "0 \<le> r \<Longrightarrow> ennreal r < ennreal q \<longleftrightarrow> r < q"
2.1063 -  unfolding not_le[symmetric] by auto
2.1064 -
2.1065 -lemma ennreal_numeral_less_top[simp]: "numeral i < (top::ennreal)"
2.1066 -  using of_nat_less_top[of "numeral i"] by simp
2.1067 -
2.1068 -lemma real_of_nat_Sup:
2.1069 -  assumes "A \<noteq> {}" "bdd_above A"
2.1070 -  shows "of_nat (Sup A) = (SUP a:A. of_nat a :: real)"
2.1071 -proof (intro antisym)
2.1072 -  show "(SUP a:A. of_nat a::real) \<le> of_nat (Sup A)"
2.1073 -    using assms by (intro cSUP_least of_nat_mono) (auto intro: cSup_upper)
2.1074 -  have "Sup A \<in> A"
2.1075 -    unfolding Sup_nat_def using assms by (intro Max_in) (auto simp: bdd_above_nat)
2.1076 -  then show "of_nat (Sup A) \<le> (SUP a:A. of_nat a::real)"
2.1077 -    by (intro cSUP_upper bdd_above_image_mono assms) (auto simp: mono_def)
2.1078 -qed
2.1079 -
2.1080 -definition "enn2real x = real_of_ereal (enn2ereal x)"
2.1081 -
2.1082 -lemma enn2real_nonneg: "0 \<le> enn2real x"
2.1083 -  by (auto simp: enn2real_def intro!: real_of_ereal_pos enn2ereal_nonneg)
2.1084 -
2.1085 -lemma enn2real_mono: "a \<le> b \<Longrightarrow> b < top \<Longrightarrow> enn2real a \<le> enn2real b"
2.1086 -  by (auto simp add: enn2real_def less_eq_ennreal.rep_eq intro!: real_of_ereal_positive_mono enn2ereal_nonneg)
2.1087 -
2.1088 -lemma enn2real_of_nat[simp]: "enn2real (of_nat n) = n"
2.1089 -  by (auto simp: enn2real_def)
2.1090 -
2.1091 -lemma enn2real_ennreal[simp]: "0 \<le> r \<Longrightarrow> enn2real (ennreal r) = r"
2.1092 -  by (simp add: enn2real_def)
2.1093 -
2.1094 -lemma of_nat_le_ennreal_iff[simp]: "0 \<le> r \<Longrightarrow> of_nat i \<le> ennreal r \<longleftrightarrow> of_nat i \<le> r"
2.1095 -  by (simp add: ennreal_of_nat_eq_real_of_nat)
2.1096 -
2.1097 -lemma min_ennreal: "0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> min (ennreal x) (ennreal y) = ennreal (min x y)"
2.1098 -  by (auto split: split_min)
2.1099 -
2.1100 -lemma ennreal_approx_unit:
2.1101 -  "(\<And>a::ennreal. 0 < a \<Longrightarrow> a < 1 \<Longrightarrow> a * z \<le> y) \<Longrightarrow> z \<le> y"
2.1102 -  apply (subst SUP_mult_right_ennreal[of "\<lambda>x. x" "{0 <..< 1}" z, simplified])
2.1103 -  apply (rule SUP_least)
2.1104 -  apply auto
2.1105 -  done
2.1106 -
2.1107 -lemma ennreal_mult_strict_right_mono: "(a::ennreal) < c \<Longrightarrow> 0 < b \<Longrightarrow> b < top \<Longrightarrow> a * b < c * b"
2.1108 -  by transfer (auto intro!: ereal_mult_strict_right_mono)
2.1109 -
2.1110 -lemma ennreal_SUP_setsum:
2.1111 -  fixes f :: "'a \<Rightarrow> nat \<Rightarrow> ennreal"
2.1112 -  shows "(\<And>i. i \<in> I \<Longrightarrow> incseq (f i)) \<Longrightarrow> (SUP n. \<Sum>i\<in>I. f i n) = (\<Sum>i\<in>I. SUP n. f i n)"
2.1113 -  unfolding incseq_def
2.1114 -  by transfer
2.1115 -     (simp add: SUP_ereal_setsum incseq_def SUP_upper2 max_absorb2 setsum_nonneg)
2.1116 -
2.1117 -lemma ennreal_indicator_less[simp]:
2.1118 -  "indicator A x \<le> (indicator B x::ennreal) \<longleftrightarrow> (x \<in> A \<longrightarrow> x \<in> B)"
2.1119 -  by (simp add: indicator_def not_le)
2.1120 -
2.1121 -lemma rel_fun_liminf[transfer_rule]: "rel_fun (rel_fun op = pcr_ennreal) pcr_ennreal liminf liminf"
2.1122 -proof -
2.1123 -  have "rel_fun (rel_fun op = pcr_ennreal) pcr_ennreal (\<lambda>x. sup 0 (liminf x)) liminf"
2.1124 -    unfolding liminf_SUP_INF[abs_def] by (transfer_prover_start, transfer_step+; simp)
2.1125 -  then show ?thesis
2.1126 -    apply (subst (asm) (2) rel_fun_def)
2.1127 -    apply (subst (2) rel_fun_def)
2.1128 -    apply (auto simp: comp_def max.absorb2 Liminf_bounded enn2ereal_nonneg rel_fun_eq_pcr_ennreal)
2.1129 -    done
2.1130 -qed
2.1131 -
2.1132 -lemma rel_fun_limsup[transfer_rule]: "rel_fun (rel_fun op = pcr_ennreal) pcr_ennreal limsup limsup"
2.1133 -proof -
2.1134 -  have "rel_fun (rel_fun op = pcr_ennreal) pcr_ennreal (\<lambda>x. INF n. sup 0 (SUP i:{n..}. x i)) limsup"
2.1135 -    unfolding limsup_INF_SUP[abs_def] by (transfer_prover_start, transfer_step+; simp)
2.1136 -  then show ?thesis
2.1137 -    unfolding limsup_INF_SUP[abs_def]
2.1138 -    apply (subst (asm) (2) rel_fun_def)
2.1139 -    apply (subst (2) rel_fun_def)
2.1140 -    apply (auto simp: comp_def max.absorb2 Sup_upper2 enn2ereal_nonneg rel_fun_eq_pcr_ennreal)
2.1141 -    apply (subst (asm) max.absorb2)
2.1142 -    apply (rule SUP_upper2)
2.1143 -    apply (auto simp: enn2ereal_nonneg)
2.1144 -    done
2.1145 -qed
2.1146 -
2.1147 -lemma ennreal_liminf_minus:
2.1148 -  fixes f :: "nat \<Rightarrow> ennreal"
2.1149 -  shows "(\<And>n. f n \<le> c) \<Longrightarrow> liminf (\<lambda>n. c - f n) = c - limsup f"
2.1150 -  apply transfer
2.1151 -  apply (simp add: ereal_diff_positive max.absorb2 liminf_ereal_cminus)
2.1152 -  apply (subst max.absorb2)
2.1153 -  apply (rule ereal_diff_positive)
2.1154 -  apply (rule Limsup_bounded)
2.1155 -  apply auto
2.1156 -  done
2.1157 -
2.1158 -lemma inverse_ennreal: "0 < r \<Longrightarrow> inverse (ennreal r) = ennreal (inverse r)"
2.1159 -  by transfer (simp add: max.absorb2)
2.1160 -
2.1161 -lemma divide_ennreal: "0 \<le> r \<Longrightarrow> 0 < q \<Longrightarrow> ennreal r / ennreal q = ennreal (r / q)"
2.1162 -  by (simp add: divide_ennreal_def inverse_ennreal ennreal_mult[symmetric] inverse_eq_divide)
2.1163 -
2.1164  lemma ennreal_inverse_top[simp]: "inverse top = (0::ennreal)"
2.1165    by transfer (simp add: top_ereal_def ereal_inverse_eq_0)
2.1166
2.1167 @@ -1153,4 +760,986 @@
2.1168    unfolding divide_ennreal_def
2.1169    by transfer (auto simp: ereal_zero_less_0_iff top_ereal_def ereal_0_gt_inverse)
2.1170
2.1171 +lemma divide_right_mono_ennreal:
2.1172 +  fixes a b c :: ennreal
2.1173 +  shows "a \<le> b \<Longrightarrow> a / c \<le> b / c"
2.1174 +  unfolding divide_ennreal_def by (intro mult_mono) auto
2.1175 +
2.1176 +lemma ennreal_mult_strict_right_mono: "(a::ennreal) < c \<Longrightarrow> 0 < b \<Longrightarrow> b < top \<Longrightarrow> a * b < c * b"
2.1177 +  by transfer (auto intro!: ereal_mult_strict_right_mono)
2.1178 +
2.1179 +lemma ennreal_indicator_less[simp]:
2.1180 +  "indicator A x \<le> (indicator B x::ennreal) \<longleftrightarrow> (x \<in> A \<longrightarrow> x \<in> B)"
2.1181 +  by (simp add: indicator_def not_le)
2.1182 +
2.1183 +lemma ennreal_inverse_positive: "0 < inverse x \<longleftrightarrow> (x::ennreal) \<noteq> top"
2.1184 +  by transfer (simp add: ereal_0_gt_inverse top_ereal_def)
2.1185 +
2.1186 +lemma ennreal_inverse_mult': "((0 < b \<or> a < top) \<and> (0 < a \<or> b < top)) \<Longrightarrow> inverse (a * b::ennreal) = inverse a * inverse b"
2.1187 +  apply transfer
2.1188 +  subgoal for a b
2.1189 +    by (cases a b rule: ereal2_cases) (auto simp: top_ereal_def)
2.1190 +  done
2.1191 +
2.1192 +lemma ennreal_inverse_mult: "a < top \<Longrightarrow> b < top \<Longrightarrow> inverse (a * b::ennreal) = inverse a * inverse b"
2.1193 +  apply transfer
2.1194 +  subgoal for a b
2.1195 +    by (cases a b rule: ereal2_cases) (auto simp: top_ereal_def)
2.1196 +  done
2.1197 +
2.1198 +lemma ennreal_inverse_1[simp]: "inverse (1::ennreal) = 1"
2.1199 +  by transfer simp
2.1200 +
2.1201 +lemma ennreal_inverse_eq_0_iff[simp]: "inverse (a::ennreal) = 0 \<longleftrightarrow> a = top"
2.1202 +  by transfer (simp add: ereal_inverse_eq_0 top_ereal_def)
2.1203 +
2.1204 +lemma ennreal_inverse_eq_top_iff[simp]: "inverse (a::ennreal) = top \<longleftrightarrow> a = 0"
2.1205 +  by transfer (simp add: top_ereal_def)
2.1206 +
2.1207 +lemma ennreal_divide_eq_0_iff[simp]: "(a::ennreal) / b = 0 \<longleftrightarrow> (a = 0 \<or> b = top)"
2.1208 +  by (simp add: divide_ennreal_def)
2.1209 +
2.1210 +lemma ennreal_divide_eq_top_iff: "(a::ennreal) / b = top \<longleftrightarrow> ((a \<noteq> 0 \<and> b = 0) \<or> (a = top \<and> b \<noteq> top))"
2.1211 +  by (auto simp add: divide_ennreal_def ennreal_mult_eq_top_iff)
2.1212 +
2.1213 +lemma one_divide_one_divide_ennreal[simp]: "1 / (1 / c) = (c::ennreal)"
2.1214 +  including ennreal.lifting
2.1215 +  unfolding divide_ennreal_def
2.1216 +  by transfer auto
2.1217 +
2.1218 +lemma ennreal_mult_left_cong:
2.1219 +  "((a::ennreal) \<noteq> 0 \<Longrightarrow> b = c) \<Longrightarrow> a * b = a * c"
2.1220 +  by (cases "a = 0") simp_all
2.1221 +
2.1222 +lemma ennreal_mult_right_cong:
2.1223 +  "((a::ennreal) \<noteq> 0 \<Longrightarrow> b = c) \<Longrightarrow> b * a = c * a"
2.1224 +  by (cases "a = 0") simp_all
2.1225 +
2.1226 +lemma ennreal_zero_less_mult_iff: "0 < a * b \<longleftrightarrow> 0 < a \<and> 0 < (b::ennreal)"
2.1227 +  by transfer (auto simp add: ereal_zero_less_0_iff le_less)
2.1228 +
2.1229 +lemma less_diff_eq_ennreal:
2.1230 +  fixes a b c :: ennreal
2.1231 +  shows "b < top \<or> c < top \<Longrightarrow> a < b - c \<longleftrightarrow> a + c < b"
2.1232 +  apply transfer
2.1233 +  subgoal for a b c
2.1234 +    by (cases a b c rule: ereal3_cases) (auto split: split_max)
2.1235 +  done
2.1236 +
2.1238 +  fixes a b :: ennreal shows "a \<le> b \<Longrightarrow> b - a + a = b"
2.1239 +  unfolding infinity_ennreal_def
2.1240 +  apply transfer
2.1241 +  subgoal for a b
2.1242 +    by (cases a b rule: ereal2_cases) (auto simp: max_absorb2)
2.1243 +  done
2.1244 +
2.1245 +lemma ennreal_diff_self[simp]: "a \<noteq> top \<Longrightarrow> a - a = (0::ennreal)"
2.1246 +  by transfer (simp add: top_ereal_def)
2.1247 +
2.1248 +lemma ennreal_minus_mono:
2.1249 +  fixes a b c :: ennreal
2.1250 +  shows "a \<le> c \<Longrightarrow> d \<le> b \<Longrightarrow> a - b \<le> c - d"
2.1251 +  apply transfer
2.1252 +  apply (rule max.mono)
2.1253 +  apply simp
2.1254 +  subgoal for a b c d
2.1255 +    by (cases a b c d rule: ereal3_cases[case_product ereal_cases]) auto
2.1256 +  done
2.1257 +
2.1258 +lemma ennreal_minus_eq_top[simp]: "a - (b::ennreal) = top \<longleftrightarrow> a = top"
2.1259 +  by transfer (auto simp: top_ereal_def max.absorb2 ereal_minus_eq_PInfty_iff split: split_max)
2.1260 +
2.1261 +lemma ennreal_divide_self[simp]: "a \<noteq> 0 \<Longrightarrow> a < top \<Longrightarrow> a / a = (1::ennreal)"
2.1262 +  unfolding divide_ennreal_def
2.1263 +  apply transfer
2.1264 +  subgoal for a
2.1265 +    by (cases a) (auto simp: top_ereal_def)
2.1266 +  done
2.1267 +
2.1268 +subsection \<open>Coercion from @{typ real} to @{typ ennreal}\<close>
2.1269 +
2.1270 +lift_definition ennreal :: "real \<Rightarrow> ennreal" is "sup 0 \<circ> ereal"
2.1271 +  by simp
2.1272 +
2.1273 +declare [[coercion ennreal]]
2.1274 +
2.1275 +lemma ennreal_cases[cases type: ennreal]:
2.1276 +  fixes x :: ennreal
2.1277 +  obtains (real) r :: real where "0 \<le> r" "x = ennreal r" | (top) "x = top"
2.1278 +  apply transfer
2.1279 +  subgoal for x thesis
2.1280 +    by (cases x) (auto simp: max.absorb2 top_ereal_def)
2.1281 +  done
2.1282 +
2.1283 +lemmas ennreal2_cases = ennreal_cases[case_product ennreal_cases]
2.1284 +lemmas ennreal3_cases = ennreal_cases[case_product ennreal2_cases]
2.1285 +
2.1286 +lemma ennreal_neq_top[simp]: "ennreal r \<noteq> top"
2.1287 +  by transfer (simp add: top_ereal_def zero_ereal_def ereal_max[symmetric] del: ereal_max)
2.1288 +
2.1289 +lemma top_neq_ennreal[simp]: "top \<noteq> ennreal r"
2.1290 +  using ennreal_neq_top[of r] by (auto simp del: ennreal_neq_top)
2.1291 +
2.1292 +lemma ennreal_less_top[simp]: "ennreal x < top"
2.1293 +  by transfer (simp add: top_ereal_def max_def)
2.1294 +
2.1295 +lemma ennreal_neg: "x \<le> 0 \<Longrightarrow> ennreal x = 0"
2.1296 +  by transfer (simp add: max.absorb1)
2.1297 +
2.1298 +lemma ennreal_inj[simp]:
2.1299 +  "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> ennreal a = ennreal b \<longleftrightarrow> a = b"
2.1300 +  by (transfer fixing: a b) (auto simp: max_absorb2)
2.1301 +
2.1302 +lemma ennreal_le_iff[simp]: "0 \<le> y \<Longrightarrow> ennreal x \<le> ennreal y \<longleftrightarrow> x \<le> y"
2.1303 +  by (auto simp: ennreal_def zero_ereal_def less_eq_ennreal.abs_eq eq_onp_def split: split_max)
2.1304 +
2.1305 +lemma le_ennreal_iff: "0 \<le> r \<Longrightarrow> x \<le> ennreal r \<longleftrightarrow> (\<exists>q\<ge>0. x = ennreal q \<and> q \<le> r)"
2.1306 +  by (cases x) (auto simp: top_unique)
2.1307 +
2.1308 +lemma ennreal_less_iff: "0 \<le> r \<Longrightarrow> ennreal r < ennreal q \<longleftrightarrow> r < q"
2.1309 +  unfolding not_le[symmetric] by auto
2.1310 +
2.1311 +lemma ennreal_eq_zero_iff[simp]: "0 \<le> x \<Longrightarrow> ennreal x = 0 \<longleftrightarrow> x = 0"
2.1312 +  by transfer (auto simp: max_absorb2)
2.1313 +
2.1314 +lemma ennreal_less_zero_iff[simp]: "0 < ennreal x \<longleftrightarrow> 0 < x"
2.1315 +  by transfer (auto simp: max_def)
2.1316 +
2.1317 +lemma ennreal_lessI: "0 < q \<Longrightarrow> r < q \<Longrightarrow> ennreal r < ennreal q"
2.1318 +  by (cases "0 \<le> r") (auto simp: ennreal_less_iff ennreal_neg)
2.1319 +
2.1320 +lemma ennreal_leI: "x \<le> y \<Longrightarrow> ennreal x \<le> ennreal y"
2.1321 +  by (cases "0 \<le> y") (auto simp: ennreal_neg)
2.1322 +
2.1323 +lemma enn2ereal_ennreal[simp]: "0 \<le> x \<Longrightarrow> enn2ereal (ennreal x) = x"
2.1324 +  by transfer (simp add: max_absorb2)
2.1325 +
2.1326 +lemma e2ennreal_enn2ereal[simp]: "e2ennreal (enn2ereal x) = x"
2.1327 +  by (simp add: e2ennreal_def max_absorb2 ennreal.enn2ereal_inverse)
2.1328 +
2.1329 +lemma ennreal_0[simp]: "ennreal 0 = 0"
2.1330 +  by (simp add: ennreal_def max.absorb1 zero_ennreal.abs_eq)
2.1331 +
2.1332 +lemma ennreal_1[simp]: "ennreal 1 = 1"
2.1333 +  by transfer (simp add: max_absorb2)
2.1334 +
2.1335 +lemma ennreal_eq_0_iff: "ennreal x = 0 \<longleftrightarrow> x \<le> 0"
2.1336 +  by (cases "0 \<le> x") (auto simp: ennreal_neg)
2.1337 +
2.1338 +lemma ennreal_le_iff2: "ennreal x \<le> ennreal y \<longleftrightarrow> ((0 \<le> y \<and> x \<le> y) \<or> (x \<le> 0 \<and> y \<le> 0))"
2.1339 +  by (cases "0 \<le> y") (auto simp: ennreal_eq_0_iff ennreal_neg)
2.1340 +
2.1341 +lemma ennreal_eq_1[simp]: "ennreal x = 1 \<longleftrightarrow> x = 1"
2.1342 +  by (cases "0 \<le> x")
2.1343 +     (auto simp: ennreal_neg ennreal_1[symmetric] simp del: ennreal_1)
2.1344 +
2.1345 +lemma ennreal_le_1[simp]: "ennreal x \<le> 1 \<longleftrightarrow> x \<le> 1"
2.1346 +  by (cases "0 \<le> x")
2.1347 +     (auto simp: ennreal_neg ennreal_1[symmetric] simp del: ennreal_1)
2.1348 +
2.1349 +lemma ennreal_ge_1[simp]: "ennreal x \<ge> 1 \<longleftrightarrow> x \<ge> 1"
2.1350 +  by (cases "0 \<le> x")
2.1351 +     (auto simp: ennreal_neg ennreal_1[symmetric] simp del: ennreal_1)
2.1352 +
2.1353 +lemma ennreal_plus[simp]:
2.1354 +  "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> ennreal (a + b) = ennreal a + ennreal b"
2.1355 +  by (transfer fixing: a b) (auto simp: max_absorb2)
2.1356 +
2.1357 +lemma setsum_ennreal[simp]: "(\<And>i. i \<in> I \<Longrightarrow> 0 \<le> f i) \<Longrightarrow> (\<Sum>i\<in>I. ennreal (f i)) = ennreal (setsum f I)"
2.1358 +  by (induction I rule: infinite_finite_induct) (auto simp: setsum_nonneg)
2.1359 +
2.1360 +lemma ennreal_of_nat_eq_real_of_nat: "of_nat i = ennreal (of_nat i)"
2.1361 +  by (induction i) simp_all
2.1362 +
2.1363 +lemma of_nat_le_ennreal_iff[simp]: "0 \<le> r \<Longrightarrow> of_nat i \<le> ennreal r \<longleftrightarrow> of_nat i \<le> r"
2.1364 +  by (simp add: ennreal_of_nat_eq_real_of_nat)
2.1365 +
2.1366 +lemma ennreal_le_of_nat_iff[simp]: "ennreal r \<le> of_nat i \<longleftrightarrow> r \<le> of_nat i"
2.1367 +  by (simp add: ennreal_of_nat_eq_real_of_nat)
2.1368 +
2.1369 +lemma ennreal_indicator: "ennreal (indicator A x) = indicator A x"
2.1370 +  by (auto split: split_indicator)
2.1371 +
2.1372 +lemma ennreal_numeral[simp]: "ennreal (numeral n) = numeral n"
2.1373 +  using ennreal_of_nat_eq_real_of_nat[of "numeral n"] by simp
2.1374 +
2.1375 +lemma min_ennreal: "0 \<le> x \<Longrightarrow> 0 \<le> y \<Longrightarrow> min (ennreal x) (ennreal y) = ennreal (min x y)"
2.1376 +  by (auto split: split_min)
2.1377 +
2.1378 +lemma ennreal_half[simp]: "ennreal (1/2) = inverse 2"
2.1379 +  by transfer (simp add: max.absorb2)
2.1380 +
2.1381 +lemma ennreal_minus: "0 \<le> q \<Longrightarrow> ennreal r - ennreal q = ennreal (r - q)"
2.1382 +  by transfer
2.1383 +     (simp add: max.absorb2 zero_ereal_def ereal_max[symmetric] del: ereal_max)
2.1384 +
2.1385 +lemma ennreal_minus_top[simp]: "ennreal a - top = 0"
2.1386 +  by (simp add: minus_top_ennreal)
2.1387 +
2.1388 +lemma ennreal_mult: "0 \<le> a \<Longrightarrow> 0 \<le> b \<Longrightarrow> ennreal (a * b) = ennreal a * ennreal b"
2.1389 +  by transfer (simp add: max_absorb2)
2.1390 +
2.1391 +lemma ennreal_mult': "0 \<le> a \<Longrightarrow> ennreal (a * b) = ennreal a * ennreal b"
2.1392 +  by (cases "0 \<le> b") (auto simp: ennreal_mult ennreal_neg mult_nonneg_nonpos)
2.1393 +
2.1394 +lemma indicator_mult_ennreal: "indicator A x * ennreal r = ennreal (indicator A x * r)"
2.1395 +  by (simp split: split_indicator)
2.1396 +
2.1397 +lemma ennreal_mult'': "0 \<le> b \<Longrightarrow> ennreal (a * b) = ennreal a * ennreal b"
2.1398 +  by (cases "0 \<le> a") (auto simp: ennreal_mult ennreal_neg mult_nonpos_nonneg)
2.1399 +
2.1400 +lemma numeral_mult_ennreal: "0 \<le> x \<Longrightarrow> numeral b * ennreal x = ennreal (numeral b * x)"
2.1401 +  by (simp add: ennreal_mult)
2.1402 +
2.1403 +lemma ennreal_power: "0 \<le> r \<Longrightarrow> ennreal r ^ n = ennreal (r ^ n)"
2.1404 +  by (induction n) (auto simp: ennreal_mult)
2.1405 +
2.1406 +lemma power_eq_top_ennreal: "x ^ n = top \<longleftrightarrow> (n \<noteq> 0 \<and> (x::ennreal) = top)"
2.1407 +  by (cases x rule: ennreal_cases)
2.1408 +     (auto simp: ennreal_power top_power_ennreal)
2.1409 +
2.1410 +lemma inverse_ennreal: "0 < r \<Longrightarrow> inverse (ennreal r) = ennreal (inverse r)"
2.1411 +  by transfer (simp add: max.absorb2)
2.1412 +
2.1413 +lemma divide_ennreal: "0 \<le> r \<Longrightarrow> 0 < q \<Longrightarrow> ennreal r / ennreal q = ennreal (r / q)"
2.1414 +  by (simp add: divide_ennreal_def inverse_ennreal ennreal_mult[symmetric] inverse_eq_divide)
2.1415 +
2.1416 +lemma ennreal_inverse_power: "inverse (x ^ n :: ennreal) = inverse x ^ n"
2.1417 +proof (cases x rule: ennreal_cases)
2.1418 +  case top with power_eq_top_ennreal[of x n] show ?thesis
2.1419 +    by (cases "n = 0") auto
2.1420 +next
2.1421 +  case (real r) then show ?thesis
2.1422 +  proof cases
2.1423 +    assume "x = 0" then show ?thesis
2.1424 +      using power_eq_top_ennreal[of top "n - 1"]
2.1425 +      by (cases n) (auto simp: ennreal_top_mult)
2.1426 +  next
2.1427 +    assume "x \<noteq> 0"
2.1428 +    with real have "0 < r" by auto
2.1429 +    with real show ?thesis
2.1430 +      by (induction n)
2.1431 +         (auto simp add: ennreal_power ennreal_mult[symmetric] inverse_ennreal)
2.1432 +  qed
2.1433 +qed
2.1434 +
2.1435 +lemma ennreal_divide_numeral: "0 \<le> x \<Longrightarrow> ennreal x / numeral b = ennreal (x / numeral b)"
2.1436 +  by (subst divide_ennreal[symmetric]) auto
2.1437 +
2.1438 +lemma setprod_ennreal: "(\<And>i. i \<in> A \<Longrightarrow> 0 \<le> f i) \<Longrightarrow> (\<Prod>i\<in>A. ennreal (f i)) = ennreal (setprod f A)"
2.1439 +  by (induction A rule: infinite_finite_induct)
2.1440 +     (auto simp: ennreal_mult setprod_nonneg)
2.1441 +
2.1442 +lemma mult_right_ennreal_cancel: "a * ennreal c = b * ennreal c \<longleftrightarrow> (a = b \<or> c \<le> 0)"
2.1443 +  apply (cases "0 \<le> c")
2.1444 +  apply (cases a b rule: ennreal2_cases)
2.1445 +  apply (auto simp: ennreal_mult[symmetric] ennreal_neg ennreal_top_mult)
2.1446 +  done
2.1447 +
2.1448 +lemma ennreal_le_epsilon:
2.1449 +  "(\<And>e::real. y < top \<Longrightarrow> 0 < e \<Longrightarrow> x \<le> y + ennreal e) \<Longrightarrow> x \<le> y"
2.1450 +  apply (cases y rule: ennreal_cases)
2.1451 +  apply (cases x rule: ennreal_cases)
2.1452 +  apply (auto simp del: ennreal_plus simp add: top_unique ennreal_plus[symmetric]
2.1453 +    intro: zero_less_one field_le_epsilon)
2.1454 +  done
2.1455 +
2.1456 +lemma ennreal_rat_dense:
2.1457 +  fixes x y :: ennreal
2.1458 +  shows "x < y \<Longrightarrow> \<exists>r::rat. x < real_of_rat r \<and> real_of_rat r < y"
2.1459 +proof transfer
2.1460 +  fix x y :: ereal assume xy: "0 \<le> x" "0 \<le> y" "x < y"
2.1461 +  moreover
2.1462 +  from ereal_dense3[OF \<open>x < y\<close>]
2.1463 +  obtain r where "x < ereal (real_of_rat r)" "ereal (real_of_rat r) < y"
2.1464 +    by auto
2.1465 +  moreover then have "0 \<le> r"
2.1466 +    using le_less_trans[OF \<open>0 \<le> x\<close> \<open>x < ereal (real_of_rat r)\<close>] by auto
2.1467 +  ultimately show "\<exists>r. x < (sup 0 \<circ> ereal) (real_of_rat r) \<and> (sup 0 \<circ> ereal) (real_of_rat r) < y"
2.1468 +    by (intro exI[of _ r]) (auto simp: max_absorb2)
2.1469 +qed
2.1470 +
2.1471 +lemma ennreal_Ex_less_of_nat: "(x::ennreal) < top \<Longrightarrow> \<exists>n. x < of_nat n"
2.1472 +  by (cases x rule: ennreal_cases)
2.1473 +     (auto simp: ennreal_of_nat_eq_real_of_nat ennreal_less_iff reals_Archimedean2)
2.1474 +
2.1475 +subsection \<open>Coercion from @{typ ennreal} to @{typ real}\<close>
2.1476 +
2.1477 +definition "enn2real x = real_of_ereal (enn2ereal x)"
2.1478 +
2.1479 +lemma enn2real_nonneg[simp]: "0 \<le> enn2real x"
2.1480 +  by (auto simp: enn2real_def intro!: real_of_ereal_pos enn2ereal_nonneg)
2.1481 +
2.1482 +lemma enn2real_mono: "a \<le> b \<Longrightarrow> b < top \<Longrightarrow> enn2real a \<le> enn2real b"
2.1483 +  by (auto simp add: enn2real_def less_eq_ennreal.rep_eq intro!: real_of_ereal_positive_mono enn2ereal_nonneg)
2.1484 +
2.1485 +lemma enn2real_of_nat[simp]: "enn2real (of_nat n) = n"
2.1486 +  by (auto simp: enn2real_def)
2.1487 +
2.1488 +lemma enn2real_ennreal[simp]: "0 \<le> r \<Longrightarrow> enn2real (ennreal r) = r"
2.1489 +  by (simp add: enn2real_def)
2.1490 +
2.1491 +lemma ennreal_enn2real[simp]: "r < top \<Longrightarrow> ennreal (enn2real r) = r"
2.1492 +  by (cases r rule: ennreal_cases) auto
2.1493 +
2.1494 +lemma real_of_ereal_enn2ereal[simp]: "real_of_ereal (enn2ereal x) = enn2real x"
2.1495 +  by (simp add: enn2real_def)
2.1496 +
2.1497 +lemma enn2real_top[simp]: "enn2real top = 0"
2.1498 +  unfolding enn2real_def top_ennreal.rep_eq top_ereal_def by simp
2.1499 +
2.1500 +lemma enn2real_0[simp]: "enn2real 0 = 0"
2.1501 +  unfolding enn2real_def zero_ennreal.rep_eq by simp
2.1502 +
2.1503 +lemma enn2real_1[simp]: "enn2real 1 = 1"
2.1504 +  unfolding enn2real_def one_ennreal.rep_eq by simp
2.1505 +
2.1506 +lemma enn2real_numeral[simp]: "enn2real (numeral n) = (numeral n)"
2.1507 +  unfolding enn2real_def by simp
2.1508 +
2.1509 +lemma enn2real_mult: "enn2real (a * b) = enn2real a * enn2real b"
2.1510 +  unfolding enn2real_def
2.1511 +  by (simp del: real_of_ereal_enn2ereal add: times_ennreal.rep_eq)
2.1512 +
2.1513 +lemma enn2real_leI: "0 \<le> B \<Longrightarrow> x \<le> ennreal B \<Longrightarrow> enn2real x \<le> B"
2.1514 +  by (cases x rule: ennreal_cases) (auto simp: top_unique)
2.1515 +
2.1516 +lemma enn2real_positive_iff: "0 < enn2real x \<longleftrightarrow> (0 < x \<and> x < top)"
2.1517 +  by (cases x rule: ennreal_cases) auto
2.1518 +
2.1519 +subsection \<open>Coercion from @{typ enat} to @{typ ennreal}\<close>
2.1520 +
2.1521 +
2.1522 +definition ennreal_of_enat :: "enat \<Rightarrow> ennreal"
2.1523 +where
2.1524 +  "ennreal_of_enat n = (case n of \<infinity> \<Rightarrow> top | enat n \<Rightarrow> of_nat n)"
2.1525 +
2.1526 +declare [[coercion ennreal_of_enat]]
2.1527 +declare [[coercion "of_nat :: nat \<Rightarrow> ennreal"]]
2.1528 +
2.1529 +lemma ennreal_of_enat_infty[simp]: "ennreal_of_enat \<infinity> = \<infinity>"
2.1530 +  by (simp add: ennreal_of_enat_def)
2.1531 +
2.1532 +lemma ennreal_of_enat_enat[simp]: "ennreal_of_enat (enat n) = of_nat n"
2.1533 +  by (simp add: ennreal_of_enat_def)
2.1534 +
2.1535 +lemma ennreal_of_enat_0[simp]: "ennreal_of_enat 0 = 0"
2.1536 +  using ennreal_of_enat_enat[of 0] unfolding enat_0 by simp
2.1537 +
2.1538 +lemma ennreal_of_enat_1[simp]: "ennreal_of_enat 1 = 1"
2.1539 +  using ennreal_of_enat_enat[of 1] unfolding enat_1 by simp
2.1540 +
2.1541 +lemma ennreal_top_neq_of_nat[simp]: "(top::ennreal) \<noteq> of_nat i"
2.1542 +  using ennreal_of_nat_neq_top[of i] by metis
2.1543 +
2.1544 +lemma ennreal_of_enat_inj[simp]: "ennreal_of_enat i = ennreal_of_enat j \<longleftrightarrow> i = j"
2.1545 +  by (cases i j rule: enat.exhaust[case_product enat.exhaust]) auto
2.1546 +
2.1547 +lemma ennreal_of_enat_le_iff[simp]: "ennreal_of_enat m \<le> ennreal_of_enat n \<longleftrightarrow> m \<le> n"
2.1548 +  by (auto simp: ennreal_of_enat_def top_unique split: enat.split)
2.1549 +
2.1550 +lemma of_nat_less_ennreal_of_nat[simp]: "of_nat n \<le> ennreal_of_enat x \<longleftrightarrow> of_nat n \<le> x"
2.1551 +  by (cases x) (auto simp: of_nat_eq_enat)
2.1552 +
2.1553 +lemma ennreal_of_enat_Sup: "ennreal_of_enat (Sup X) = (SUP x:X. ennreal_of_enat x)"
2.1554 +proof -
2.1555 +  have "ennreal_of_enat (Sup X) \<le> (SUP x : X. ennreal_of_enat x)"
2.1556 +    unfolding Sup_enat_def
2.1557 +  proof (clarsimp, intro conjI impI)
2.1558 +    fix x assume "finite X" "X \<noteq> {}"
2.1559 +    then show "ennreal_of_enat (Max X) \<le> (SUP x : X. ennreal_of_enat x)"
2.1560 +      by (intro SUP_upper Max_in)
2.1561 +  next
2.1562 +    assume "infinite X" "X \<noteq> {}"
2.1563 +    have "\<exists>y\<in>X. r < ennreal_of_enat y" if r: "r < top" for r
2.1564 +    proof -
2.1565 +      from ennreal_Ex_less_of_nat[OF r] guess n .. note n = this
2.1566 +      have "\<not> (X \<subseteq> enat ` {.. n})"
2.1567 +        using \<open>infinite X\<close> by (auto dest: finite_subset)
2.1568 +      then obtain x where "x \<in> X" "x \<notin> enat ` {..n}"
2.1569 +        by blast
2.1570 +      moreover then have "of_nat n \<le> x"
2.1571 +        by (cases x) (auto simp: of_nat_eq_enat)
2.1572 +      ultimately show ?thesis
2.1573 +        by (auto intro!: bexI[of _ x] less_le_trans[OF n])
2.1574 +    qed
2.1575 +    then have "(SUP x : X. ennreal_of_enat x) = top"
2.1576 +      by simp
2.1577 +    then show "top \<le> (SUP x : X. ennreal_of_enat x)"
2.1578 +      unfolding top_unique by simp
2.1579 +  qed
2.1580 +  then show ?thesis
2.1581 +    by (auto intro!: antisym Sup_least intro: Sup_upper)
2.1582 +qed
2.1583 +
2.1584 +lemma ennreal_of_enat_eSuc[simp]: "ennreal_of_enat (eSuc x) = 1 + ennreal_of_enat x"
2.1585 +  by (cases x) (auto simp: eSuc_enat)
2.1586 +
2.1587 +subsection \<open>Topology on @{typ ennreal}\<close>
2.1588 +
2.1589 +lemma enn2ereal_Iio: "enn2ereal -` {..<a} = (if 0 \<le> a then {..< e2ennreal a} else {})"
2.1590 +  using enn2ereal_nonneg
2.1591 +  by (cases a rule: ereal_ennreal_cases)
2.1592 +     (auto simp add: vimage_def set_eq_iff ennreal.enn2ereal_inverse less_ennreal.rep_eq e2ennreal_def max_absorb2
2.1593 +           simp del: enn2ereal_nonneg
2.1594 +           intro: le_less_trans less_imp_le)
2.1595 +
2.1596 +lemma enn2ereal_Ioi: "enn2ereal -` {a <..} = (if 0 \<le> a then {e2ennreal a <..} else UNIV)"
2.1597 +  by (cases a rule: ereal_ennreal_cases)
2.1598 +     (auto simp add: vimage_def set_eq_iff ennreal.enn2ereal_inverse less_ennreal.rep_eq e2ennreal_def max_absorb2
2.1599 +           intro: less_le_trans)
2.1600 +
2.1601 +instantiation ennreal :: linear_continuum_topology
2.1602 +begin
2.1603 +
2.1604 +definition open_ennreal :: "ennreal set \<Rightarrow> bool"
2.1605 +  where "(open :: ennreal set \<Rightarrow> bool) = generate_topology (range lessThan \<union> range greaterThan)"
2.1606 +
2.1607 +instance
2.1608 +proof
2.1609 +  show "\<exists>a b::ennreal. a \<noteq> b"
2.1610 +    using zero_neq_one by (intro exI)
2.1611 +  show "\<And>x y::ennreal. x < y \<Longrightarrow> \<exists>z>x. z < y"
2.1612 +  proof transfer
2.1613 +    fix x y :: ereal assume "0 \<le> x" "x < y"
2.1614 +    moreover from dense[OF this(2)] guess z ..
2.1615 +    ultimately show "\<exists>z\<in>Collect (op \<le> 0). x < z \<and> z < y"
2.1616 +      by (intro bexI[of _ z]) auto
2.1617 +  qed
2.1618 +qed (rule open_ennreal_def)
2.1619 +
2.1620  end
2.1621 +
2.1622 +lemma continuous_on_e2ennreal: "continuous_on A e2ennreal"
2.1623 +proof (rule continuous_on_subset)
2.1624 +  show "continuous_on ({0..} \<union> {..0}) e2ennreal"
2.1625 +  proof (rule continuous_on_closed_Un)
2.1626 +    show "continuous_on {0 ..} e2ennreal"
2.1627 +      by (rule continuous_onI_mono)
2.1628 +         (auto simp add: less_eq_ennreal.abs_eq eq_onp_def enn2ereal_range)
2.1629 +    show "continuous_on {.. 0} e2ennreal"
2.1630 +      by (subst continuous_on_cong[OF refl, of _ _ "\<lambda>_. 0"])
2.1631 +         (auto simp add: e2ennreal_neg continuous_on_const)
2.1632 +  qed auto
2.1633 +  show "A \<subseteq> {0..} \<union> {..0::ereal}"
2.1634 +    by auto
2.1635 +qed
2.1636 +
2.1637 +lemma continuous_at_e2ennreal: "continuous (at x within A) e2ennreal"
2.1638 +  by (rule continuous_on_imp_continuous_within[OF continuous_on_e2ennreal, of _ UNIV]) auto
2.1639 +
2.1640 +lemma continuous_on_enn2ereal: "continuous_on UNIV enn2ereal"
2.1641 +  by (rule continuous_on_generate_topology[OF open_generated_order])
2.1642 +     (auto simp add: enn2ereal_Iio enn2ereal_Ioi)
2.1643 +
2.1644 +lemma continuous_at_enn2ereal: "continuous (at x within A) enn2ereal"
2.1645 +  by (rule continuous_on_imp_continuous_within[OF continuous_on_enn2ereal]) auto
2.1646 +
2.1647 +lemma sup_continuous_e2ennreal[order_continuous_intros]:
2.1648 +  assumes f: "sup_continuous f" shows "sup_continuous (\<lambda>x. e2ennreal (f x))"
2.1649 +  apply (rule sup_continuous_compose[OF _ f])
2.1650 +  apply (rule continuous_at_left_imp_sup_continuous)
2.1651 +  apply (auto simp: mono_def e2ennreal_mono continuous_at_e2ennreal)
2.1652 +  done
2.1653 +
2.1654 +lemma sup_continuous_enn2ereal[order_continuous_intros]:
2.1655 +  assumes f: "sup_continuous f" shows "sup_continuous (\<lambda>x. enn2ereal (f x))"
2.1656 +  apply (rule sup_continuous_compose[OF _ f])
2.1657 +  apply (rule continuous_at_left_imp_sup_continuous)
2.1658 +  apply (simp_all add: mono_def less_eq_ennreal.rep_eq continuous_at_enn2ereal)
2.1659 +  done
2.1660 +
2.1661 +lemma sup_continuous_mult_left_ennreal':
2.1662 +  fixes c :: "ennreal"
2.1663 +  shows "sup_continuous (\<lambda>x. c * x)"
2.1664 +  unfolding sup_continuous_def
2.1665 +  by transfer (auto simp: SUP_ereal_mult_left max.absorb2 SUP_upper2)
2.1666 +
2.1667 +lemma sup_continuous_mult_left_ennreal[order_continuous_intros]:
2.1668 +  "sup_continuous f \<Longrightarrow> sup_continuous (\<lambda>x. c * f x :: ennreal)"
2.1669 +  by (rule sup_continuous_compose[OF sup_continuous_mult_left_ennreal'])
2.1670 +
2.1671 +lemma sup_continuous_mult_right_ennreal[order_continuous_intros]:
2.1672 +  "sup_continuous f \<Longrightarrow> sup_continuous (\<lambda>x. f x * c :: ennreal)"
2.1673 +  using sup_continuous_mult_left_ennreal[of f c] by (simp add: mult.commute)
2.1674 +
2.1675 +lemma sup_continuous_divide_ennreal[order_continuous_intros]:
2.1676 +  fixes f g :: "'a::complete_lattice \<Rightarrow> ennreal"
2.1677 +  shows "sup_continuous f \<Longrightarrow> sup_continuous (\<lambda>x. f x / c)"
2.1678 +  unfolding divide_ennreal_def by (rule sup_continuous_mult_right_ennreal)
2.1679 +
2.1680 +lemma transfer_enn2ereal_continuous_on [transfer_rule]:
2.1681 +  "rel_fun (op =) (rel_fun (rel_fun op = pcr_ennreal) op =) continuous_on continuous_on"
2.1682 +proof -
2.1683 +  have "continuous_on A f" if "continuous_on A (\<lambda>x. enn2ereal (f x))" for A and f :: "'a \<Rightarrow> ennreal"
2.1684 +    using continuous_on_compose2[OF continuous_on_e2ennreal[of "{0..}"] that]
2.1685 +    by (auto simp: ennreal.enn2ereal_inverse subset_eq e2ennreal_def max_absorb2)
2.1686 +  moreover
2.1687 +  have "continuous_on A (\<lambda>x. enn2ereal (f x))" if "continuous_on A f" for A and f :: "'a \<Rightarrow> ennreal"
2.1688 +    using continuous_on_compose2[OF continuous_on_enn2ereal that] by auto
2.1689 +  ultimately
2.1690 +  show ?thesis
2.1691 +    by (auto simp add: rel_fun_def ennreal.pcr_cr_eq cr_ennreal_def)
2.1692 +qed
2.1693 +
2.1694 +lemma transfer_sup_continuous[transfer_rule]:
2.1695 +  "(rel_fun (rel_fun (op =) pcr_ennreal) op =) sup_continuous sup_continuous"
2.1696 +proof (safe intro!: rel_funI dest!: rel_fun_eq_pcr_ennreal[THEN iffD1])
2.1697 +  show "sup_continuous (enn2ereal \<circ> f) \<Longrightarrow> sup_continuous f" for f :: "'a \<Rightarrow> _"
2.1698 +    using sup_continuous_e2ennreal[of "enn2ereal \<circ> f"] by simp
2.1699 +  show "sup_continuous f \<Longrightarrow> sup_continuous (enn2ereal \<circ> f)" for f :: "'a \<Rightarrow> _"
2.1700 +    using sup_continuous_enn2ereal[of f] by (simp add: comp_def)
2.1701 +qed
2.1702 +
2.1703 +lemma continuous_on_ennreal[tendsto_intros]:
2.1704 +  "continuous_on A f \<Longrightarrow> continuous_on A (\<lambda>x. ennreal (f x))"
2.1705 +  by transfer (auto intro!: continuous_on_max continuous_on_const continuous_on_ereal)
2.1706 +
2.1707 +lemma tendsto_ennrealD:
2.1708 +  assumes lim: "((\<lambda>x. ennreal (f x)) \<longlongrightarrow> ennreal x) F"
2.1709 +  assumes *: "\<forall>\<^sub>F x in F. 0 \<le> f x" and x: "0 \<le> x"
2.1710 +  shows "(f \<longlongrightarrow> x) F"
2.1711 +  using continuous_on_tendsto_compose[OF continuous_on_enn2ereal lim]
2.1712 +  apply simp
2.1713 +  apply (subst (asm) tendsto_cong)
2.1714 +  using *
2.1715 +  apply eventually_elim
2.1716 +  apply (auto simp: max_absorb2 \<open>0 \<le> x\<close>)
2.1717 +  done
2.1718 +
2.1719 +lemma tendsto_ennreal_iff[simp]:
2.1720 +  "\<forall>\<^sub>F x in F. 0 \<le> f x \<Longrightarrow> 0 \<le> x \<Longrightarrow> ((\<lambda>x. ennreal (f x)) \<longlongrightarrow> ennreal x) F \<longleftrightarrow> (f \<longlongrightarrow> x) F"
2.1721 +  by (auto dest: tendsto_ennrealD)
2.1722 +     (auto simp: ennreal_def
2.1723 +           intro!: continuous_on_tendsto_compose[OF continuous_on_e2ennreal[of UNIV]] tendsto_max)
2.1724 +
2.1725 +lemma tendsto_enn2ereal_iff[simp]: "((\<lambda>i. enn2ereal (f i)) \<longlongrightarrow> enn2ereal x) F \<longleftrightarrow> (f \<longlongrightarrow> x) F"
2.1726 +  using continuous_on_enn2ereal[THEN continuous_on_tendsto_compose, of f x F]
2.1727 +    continuous_on_e2ennreal[THEN continuous_on_tendsto_compose, of "\<lambda>x. enn2ereal (f x)" "enn2ereal x" F UNIV]
2.1728 +  by auto
2.1729 +
2.1731 +  fixes f g :: "'a::topological_space \<Rightarrow> ennreal"
2.1732 +  shows "continuous_on A f \<Longrightarrow> continuous_on A g \<Longrightarrow> continuous_on A (\<lambda>x. f x + g x)"
2.1733 +  by (transfer fixing: A) (auto intro!: tendsto_add_ereal_nonneg simp: continuous_on_def)
2.1734 +
2.1735 +lemma continuous_on_inverse_ennreal[continuous_intros]:
2.1736 +  fixes f :: "'a::topological_space \<Rightarrow> ennreal"
2.1737 +  shows "continuous_on A f \<Longrightarrow> continuous_on A (\<lambda>x. inverse (f x))"
2.1738 +proof (transfer fixing: A)
2.1739 +  show "pred_fun (\<lambda>_. True)  (op \<le> 0) f \<Longrightarrow> continuous_on A (\<lambda>x. inverse (f x))" if "continuous_on A f"
2.1740 +    for f :: "'a \<Rightarrow> ereal"
2.1741 +    using continuous_on_compose2[OF continuous_on_inverse_ereal that] by (auto simp: subset_eq)
2.1742 +qed
2.1743 +
2.1745 +proof
2.1746 +  show "((\<lambda>x. fst x + snd x) \<longlongrightarrow> a + b) (nhds a \<times>\<^sub>F nhds b)" for a b :: ennreal
2.1747 +    using continuous_on_add_ennreal[of UNIV fst snd]
2.1748 +    using tendsto_at_iff_tendsto_nhds[symmetric, of "\<lambda>x::(ennreal \<times> ennreal). fst x + snd x"]
2.1749 +    by (auto simp: continuous_on_eq_continuous_at)
2.1750 +       (simp add: isCont_def nhds_prod[symmetric])
2.1751 +qed
2.1752 +
2.1754 +  fixes f g :: "'a::complete_lattice \<Rightarrow> ennreal"
2.1755 +  shows "sup_continuous f \<Longrightarrow> sup_continuous g \<Longrightarrow> sup_continuous (\<lambda>x. f x + g x)"
2.1756 +  by transfer (auto intro!: sup_continuous_add)
2.1757 +
2.1758 +lemma ennreal_suminf_lessD: "(\<Sum>i. f i :: ennreal) < x \<Longrightarrow> f i < x"
2.1759 +  using le_less_trans[OF setsum_le_suminf[OF summableI, of "{i}" f]] by simp
2.1760 +
2.1761 +lemma sums_ennreal[simp]: "(\<And>i. 0 \<le> f i) \<Longrightarrow> 0 \<le> x \<Longrightarrow> (\<lambda>i. ennreal (f i)) sums ennreal x \<longleftrightarrow> f sums x"
2.1762 +  unfolding sums_def by (simp add: always_eventually setsum_nonneg)
2.1763 +
2.1764 +lemma summable_suminf_not_top: "(\<And>i. 0 \<le> f i) \<Longrightarrow> (\<Sum>i. ennreal (f i)) \<noteq> top \<Longrightarrow> summable f"
2.1765 +  using summable_sums[OF summableI, of "\<lambda>i. ennreal (f i)"]
2.1766 +  by (cases "\<Sum>i. ennreal (f i)" rule: ennreal_cases)
2.1767 +     (auto simp: summable_def)
2.1768 +
2.1769 +lemma suminf_ennreal[simp]:
2.1770 +  "(\<And>i. 0 \<le> f i) \<Longrightarrow> (\<Sum>i. ennreal (f i)) \<noteq> top \<Longrightarrow> (\<Sum>i. ennreal (f i)) = ennreal (\<Sum>i. f i)"
2.1771 +  by (rule sums_unique[symmetric]) (simp add: summable_suminf_not_top suminf_nonneg summable_sums)
2.1772 +
2.1773 +lemma sums_enn2ereal[simp]: "(\<lambda>i. enn2ereal (f i)) sums enn2ereal x \<longleftrightarrow> f sums x"
2.1774 +  unfolding sums_def by (simp add: always_eventually setsum_nonneg)
2.1775 +
2.1776 +lemma suminf_enn2ereal[simp]: "(\<Sum>i. enn2ereal (f i)) = enn2ereal (suminf f)"
2.1777 +  by (rule sums_unique[symmetric]) (simp add: summable_sums)
2.1778 +
2.1779 +lemma transfer_e2ennreal_suminf [transfer_rule]: "rel_fun (rel_fun op = pcr_ennreal) pcr_ennreal suminf suminf"
2.1780 +  by (auto simp: rel_funI rel_fun_eq_pcr_ennreal comp_def)
2.1781 +
2.1782 +lemma ennreal_suminf_cmult[simp]: "(\<Sum>i. r * f i) = r * (\<Sum>i. f i::ennreal)"
2.1783 +  by transfer (auto intro!: suminf_cmult_ereal)
2.1784 +
2.1785 +lemma ennreal_suminf_multc[simp]: "(\<Sum>i. f i * r) = (\<Sum>i. f i::ennreal) * r"
2.1786 +  using ennreal_suminf_cmult[of r f] by (simp add: ac_simps)
2.1787 +
2.1788 +lemma ennreal_suminf_divide[simp]: "(\<Sum>i. f i / r) = (\<Sum>i. f i::ennreal) / r"
2.1789 +  by (simp add: divide_ennreal_def)
2.1790 +
2.1791 +lemma ennreal_suminf_neq_top: "summable f \<Longrightarrow> (\<And>i. 0 \<le> f i) \<Longrightarrow> (\<Sum>i. ennreal (f i)) \<noteq> top"
2.1792 +  using sums_ennreal[of f "suminf f"]
2.1793 +  by (simp add: suminf_nonneg sums_unique[symmetric] summable_sums_iff[symmetric] del: sums_ennreal)
2.1794 +
2.1795 +lemma suminf_ennreal_eq:
2.1796 +  "(\<And>i. 0 \<le> f i) \<Longrightarrow> f sums x \<Longrightarrow> (\<Sum>i. ennreal (f i)) = ennreal x"
2.1797 +  using suminf_nonneg[of f] sums_unique[of f x]
2.1798 +  by (intro sums_unique[symmetric]) (auto simp: summable_sums_iff)
2.1799 +
2.1801 +  fixes f :: "nat \<Rightarrow> ennreal"
2.1802 +  shows "(\<And>N. (\<Sum>n<N. f n) + y \<le> x) \<Longrightarrow> suminf f + y \<le> x"
2.1803 +  by transfer (auto intro!: suminf_bound_add)
2.1804 +
2.1805 +lemma ennreal_suminf_SUP_eq_directed:
2.1806 +  fixes f :: "'a \<Rightarrow> nat \<Rightarrow> ennreal"
2.1807 +  assumes *: "\<And>N i j. i \<in> I \<Longrightarrow> j \<in> I \<Longrightarrow> finite N \<Longrightarrow> \<exists>k\<in>I. \<forall>n\<in>N. f i n \<le> f k n \<and> f j n \<le> f k n"
2.1808 +  shows "(\<Sum>n. SUP i:I. f i n) = (SUP i:I. \<Sum>n. f i n)"
2.1809 +proof cases
2.1810 +  assume "I \<noteq> {}"
2.1811 +  then obtain i where "i \<in> I" by auto
2.1812 +  from * show ?thesis
2.1813 +    by (transfer fixing: I)
2.1814 +       (auto simp: max_absorb2 SUP_upper2[OF \<open>i \<in> I\<close>] suminf_nonneg summable_ereal_pos \<open>I \<noteq> {}\<close>
2.1815 +             intro!: suminf_SUP_eq_directed)
2.1817 +
2.1819 +  fixes f g :: "nat \<Rightarrow> ennreal"
2.1820 +  shows "(INF i. f i + c) = (INF i. f i) + c"
2.1821 +  using continuous_at_Inf_mono[of "\<lambda>x. x + c" "f`UNIV"]
2.1822 +  using continuous_add[of "at_right (Inf (range f))", of "\<lambda>x. x" "\<lambda>x. c"]
2.1823 +  by (auto simp: mono_def)
2.1824 +
2.1826 +  fixes f g :: "nat \<Rightarrow> ennreal"
2.1827 +  shows "(INF i. c + f i) = c + (INF i. f i)"
2.1829 +
2.1830 +lemma SUP_mult_left_ennreal: "c * (SUP i:I. f i) = (SUP i:I. c * f i ::ennreal)"
2.1831 +proof cases
2.1832 +  assume "I \<noteq> {}" then show ?thesis
2.1833 +    by transfer (auto simp add: SUP_ereal_mult_left max_absorb2 SUP_upper2)
2.1835 +
2.1836 +lemma SUP_mult_right_ennreal: "(SUP i:I. f i) * c = (SUP i:I. f i * c ::ennreal)"
2.1837 +  using SUP_mult_left_ennreal by (simp add: mult.commute)
2.1838 +
2.1839 +lemma SUP_divide_ennreal: "(SUP i:I. f i) / c = (SUP i:I. f i / c ::ennreal)"
2.1840 +  using SUP_mult_right_ennreal by (simp add: divide_ennreal_def)
2.1841 +
2.1842 +lemma ennreal_SUP_of_nat_eq_top: "(SUP x. of_nat x :: ennreal) = top"
2.1843 +proof (intro antisym top_greatest le_SUP_iff[THEN iffD2] allI impI)
2.1844 +  fix y :: ennreal assume "y < top"
2.1845 +  then obtain r where "y = ennreal r"
2.1846 +    by (cases y rule: ennreal_cases) auto
2.1847 +  then show "\<exists>i\<in>UNIV. y < of_nat i"
2.1848 +    using reals_Archimedean2[of "max 1 r"] zero_less_one
2.1849 +    by (auto simp: ennreal_of_nat_eq_real_of_nat ennreal_def less_ennreal.abs_eq eq_onp_def max.absorb2
2.1850 +             dest!: one_less_of_natD intro: less_trans)
2.1851 +qed
2.1852 +
2.1853 +lemma ennreal_SUP_eq_top:
2.1854 +  fixes f :: "'a \<Rightarrow> ennreal"
2.1855 +  assumes "\<And>n. \<exists>i\<in>I. of_nat n \<le> f i"
2.1856 +  shows "(SUP i : I. f i) = top"
2.1857 +proof -
2.1858 +  have "(SUP x. of_nat x :: ennreal) \<le> (SUP i : I. f i)"
2.1859 +    using assms by (auto intro!: SUP_least intro: SUP_upper2)
2.1860 +  then show ?thesis
2.1861 +    by (auto simp: ennreal_SUP_of_nat_eq_top top_unique)
2.1862 +qed
2.1863 +
2.1864 +lemma ennreal_INF_const_minus:
2.1865 +  fixes f :: "'a \<Rightarrow> ennreal"
2.1866 +  shows "I \<noteq> {} \<Longrightarrow> (SUP x:I. c - f x) = c - (INF x:I. f x)"
2.1867 +  by (transfer fixing: I)
2.1868 +     (simp add: sup_max[symmetric] SUP_sup_const1 SUP_ereal_minus_right del: sup_ereal_def)
2.1869 +
2.1870 +lemma of_nat_Sup_ennreal:
2.1871 +  assumes "A \<noteq> {}" "bdd_above A"
2.1872 +  shows "of_nat (Sup A) = (SUP a:A. of_nat a :: ennreal)"
2.1873 +proof (intro antisym)
2.1874 +  show "(SUP a:A. of_nat a::ennreal) \<le> of_nat (Sup A)"
2.1875 +    by (intro SUP_least of_nat_mono) (auto intro: cSup_upper assms)
2.1876 +  have "Sup A \<in> A"
2.1877 +    unfolding Sup_nat_def using assms by (intro Max_in) (auto simp: bdd_above_nat)
2.1878 +  then show "of_nat (Sup A) \<le> (SUP a:A. of_nat a::ennreal)"
2.1879 +    by (intro SUP_upper)
2.1880 +qed
2.1881 +
2.1882 +lemma ennreal_tendsto_const_minus:
2.1883 +  fixes g :: "'a \<Rightarrow> ennreal"
2.1884 +  assumes ae: "\<forall>\<^sub>F x in F. g x \<le> c"
2.1885 +  assumes g: "((\<lambda>x. c - g x) \<longlongrightarrow> 0) F"
2.1886 +  shows "(g \<longlongrightarrow> c) F"
2.1887 +proof (cases c rule: ennreal_cases)
2.1888 +  case top with tendsto_unique[OF _ g, of "top"] show ?thesis
2.1889 +    by (cases "F = bot") auto
2.1890 +next
2.1891 +  case (real r)
2.1892 +  then have "\<forall>x. \<exists>q\<ge>0. g x \<le> c \<longrightarrow> (g x = ennreal q \<and> q \<le> r)"
2.1893 +    by (auto simp: le_ennreal_iff)
2.1894 +  then obtain f where *: "\<And>x. g x \<le> c \<Longrightarrow> 0 \<le> f x" "\<And>x. g x \<le> c \<Longrightarrow> g x = ennreal (f x)" "\<And>x. g x \<le> c \<Longrightarrow> f x \<le> r"
2.1895 +    by metis
2.1896 +  from ae have ae2: "\<forall>\<^sub>F x in F. c - g x = ennreal (r - f x) \<and> f x \<le> r \<and> g x = ennreal (f x) \<and> 0 \<le> f x"
2.1897 +  proof eventually_elim
2.1898 +    fix x assume "g x \<le> c" with *[of x] \<open>0 \<le> r\<close> show "c - g x = ennreal (r - f x) \<and> f x \<le> r \<and> g x = ennreal (f x) \<and> 0 \<le> f x"
2.1899 +      by (auto simp: real ennreal_minus)
2.1900 +  qed
2.1901 +  with g have "((\<lambda>x. ennreal (r - f x)) \<longlongrightarrow> ennreal 0) F"
2.1902 +    by (auto simp add: tendsto_cong eventually_conj_iff)
2.1903 +  with ae2 have "((\<lambda>x. r - f x) \<longlongrightarrow> 0) F"
2.1904 +    by (subst (asm) tendsto_ennreal_iff) (auto elim: eventually_mono)
2.1905 +  then have "(f \<longlongrightarrow> r) F"
2.1906 +    by (rule Lim_transform2[OF tendsto_const])
2.1907 +  with ae2 have "((\<lambda>x. ennreal (f x)) \<longlongrightarrow> ennreal r) F"
2.1908 +    by (subst tendsto_ennreal_iff) (auto elim: eventually_mono simp: real)
2.1909 +  with ae2 show ?thesis
2.1910 +    by (auto simp: real tendsto_cong eventually_conj_iff)
2.1911 +qed
2.1912 +
2.1914 +  fixes f g :: "nat \<Rightarrow> ennreal"
2.1915 +  shows "incseq f \<Longrightarrow> incseq g \<Longrightarrow> (SUP i. f i + g i) = SUPREMUM UNIV f + SUPREMUM UNIV g"
2.1916 +  unfolding incseq_def le_fun_def
2.1917 +  by transfer
2.1919 +
2.1920 +lemma ennreal_SUP_setsum:
2.1921 +  fixes f :: "'a \<Rightarrow> nat \<Rightarrow> ennreal"
2.1922 +  shows "(\<And>i. i \<in> I \<Longrightarrow> incseq (f i)) \<Longrightarrow> (SUP n. \<Sum>i\<in>I. f i n) = (\<Sum>i\<in>I. SUP n. f i n)"
2.1923 +  unfolding incseq_def
2.1924 +  by transfer
2.1925 +     (simp add: SUP_ereal_setsum incseq_def SUP_upper2 max_absorb2 setsum_nonneg)
2.1926 +
2.1927 +lemma ennreal_liminf_minus:
2.1928 +  fixes f :: "nat \<Rightarrow> ennreal"
2.1929 +  shows "(\<And>n. f n \<le> c) \<Longrightarrow> liminf (\<lambda>n. c - f n) = c - limsup f"
2.1930 +  apply transfer
2.1931 +  apply (simp add: ereal_diff_positive max.absorb2 liminf_ereal_cminus)
2.1932 +  apply (subst max.absorb2)
2.1933 +  apply (rule ereal_diff_positive)
2.1934 +  apply (rule Limsup_bounded)
2.1935 +  apply auto
2.1936 +  done
2.1937 +
2.1938 +lemma ennreal_continuous_on_cmult:
2.1939 +  "(c::ennreal) < top \<Longrightarrow> continuous_on A f \<Longrightarrow> continuous_on A (\<lambda>x. c * f x)"
2.1940 +  by (transfer fixing: A) (auto intro: continuous_on_cmult_ereal)
2.1941 +
2.1942 +lemma ennreal_tendsto_cmult:
2.1943 +  "(c::ennreal) < top \<Longrightarrow> (f \<longlongrightarrow> x) F \<Longrightarrow> ((\<lambda>x. c * f x) \<longlongrightarrow> c * x) F"
2.1944 +  by (rule continuous_on_tendsto_compose[where g=f, OF ennreal_continuous_on_cmult, where s=UNIV])
2.1945 +     (auto simp: continuous_on_id)
2.1946 +
2.1947 +lemma tendsto_ennrealI[intro, simp]:
2.1948 +  "(f \<longlongrightarrow> x) F \<Longrightarrow> ((\<lambda>x. ennreal (f x)) \<longlongrightarrow> ennreal x) F"
2.1949 +  by (auto simp: ennreal_def
2.1950 +           intro!: continuous_on_tendsto_compose[OF continuous_on_e2ennreal[of UNIV]] tendsto_max)
2.1951 +
2.1952 +lemma ennreal_suminf_minus:
2.1953 +  fixes f g :: "nat \<Rightarrow> ennreal"
2.1954 +  shows "(\<And>i. g i \<le> f i) \<Longrightarrow> suminf f \<noteq> top \<Longrightarrow> suminf g \<noteq> top \<Longrightarrow> (\<Sum>i. f i - g i) = suminf f - suminf g"
2.1955 +  by transfer
2.1956 +     (auto simp add: max.absorb2 ereal_diff_positive suminf_le_pos top_ereal_def intro!: suminf_ereal_minus)
2.1957 +
2.1958 +lemma ennreal_Sup_countable_SUP:
2.1959 +  "A \<noteq> {} \<Longrightarrow> \<exists>f::nat \<Rightarrow> ennreal. incseq f \<and> range f \<subseteq> A \<and> Sup A = (SUP i. f i)"
2.1960 +  unfolding incseq_def
2.1961 +  apply transfer
2.1962 +  subgoal for A
2.1963 +    using Sup_countable_SUP[of A]
2.1964 +    apply (clarsimp simp add: incseq_def[symmetric] SUP_upper2 max.absorb2 image_subset_iff Sup_upper2 cong: conj_cong)
2.1965 +    subgoal for f
2.1966 +      by (intro exI[of _ f]) auto
2.1967 +    done
2.1968 +  done
2.1969 +
2.1970 +lemma ennreal_SUP_countable_SUP:
2.1971 +  "A \<noteq> {} \<Longrightarrow> \<exists>f::nat \<Rightarrow> ennreal. range f \<subseteq> g`A \<and> SUPREMUM A g = SUPREMUM UNIV f"
2.1972 +  using ennreal_Sup_countable_SUP [of "g`A"] by auto
2.1973 +
2.1974 +lemma of_nat_tendsto_top_ennreal: "(\<lambda>n::nat. of_nat n :: ennreal) \<longlonglongrightarrow> top"
2.1975 +  using LIMSEQ_SUP[of "of_nat :: nat \<Rightarrow> ennreal"]
2.1976 +  by (simp add: ennreal_SUP_of_nat_eq_top incseq_def)
2.1977 +
2.1978 +lemma SUP_sup_continuous_ennreal:
2.1979 +  fixes f :: "ennreal \<Rightarrow> 'a::complete_lattice"
2.1980 +  assumes f: "sup_continuous f" and "I \<noteq> {}"
2.1981 +  shows "(SUP i:I. f (g i)) = f (SUP i:I. g i)"
2.1982 +proof (rule antisym)
2.1983 +  show "(SUP i:I. f (g i)) \<le> f (SUP i:I. g i)"
2.1984 +    by (rule mono_SUP[OF sup_continuous_mono[OF f]])
2.1985 +  from ennreal_Sup_countable_SUP[of "g`I"] \<open>I \<noteq> {}\<close>
2.1986 +  obtain M :: "nat \<Rightarrow> ennreal" where "incseq M" and M: "range M \<subseteq> g ` I" and eq: "(SUP i : I. g i) = (SUP i. M i)"
2.1987 +    by auto
2.1988 +  have "f (SUP i : I. g i) = (SUP i : range M. f i)"
2.1989 +    unfolding eq sup_continuousD[OF f \<open>mono M\<close>] by simp
2.1990 +  also have "\<dots> \<le> (SUP i : I. f (g i))"
2.1991 +    by (insert M, drule SUP_subset_mono) auto
2.1992 +  finally show "f (SUP i : I. g i) \<le> (SUP i : I. f (g i))" .
2.1993 +qed
2.1994 +
2.1995 +lemma ennreal_suminf_SUP_eq:
2.1996 +  fixes f :: "nat \<Rightarrow> nat \<Rightarrow> ennreal"
2.1997 +  shows "(\<And>i. incseq (\<lambda>n. f n i)) \<Longrightarrow> (\<Sum>i. SUP n. f n i) = (SUP n. \<Sum>i. f n i)"
2.1998 +  apply (rule ennreal_suminf_SUP_eq_directed)
2.1999 +  subgoal for N n j
2.2000 +    by (auto simp: incseq_def intro!:exI[of _ "max n j"])
2.2001 +  done
2.2002 +
2.2004 +  fixes c :: ennreal
2.2005 +  shows "I \<noteq> {} \<Longrightarrow> (SUP i:I. f i + c) = (SUP i:I. f i) + c"
2.2006 +  apply transfer
2.2008 +  apply (subst (1 2) max.absorb2)
2.2009 +  apply (auto intro: SUP_upper2 ereal_add_nonneg_nonneg)
2.2010 +  done
2.2011 +
2.2012 +lemma ennreal_SUP_const_minus:
2.2013 +  fixes f :: "'a \<Rightarrow> ennreal"
2.2014 +  shows "I \<noteq> {} \<Longrightarrow> c < top \<Longrightarrow> (INF x:I. c - f x) = c - (SUP x:I. f x)"
2.2015 +  apply (transfer fixing: I)
2.2016 +  unfolding ex_in_conv[symmetric]
2.2017 +  apply (auto simp add: sup_max[symmetric] SUP_upper2 sup_absorb2
2.2018 +              simp del: sup_ereal_def)
2.2019 +  apply (subst INF_ereal_minus_right[symmetric])
2.2020 +  apply (auto simp del: sup_ereal_def simp add: sup_INF)
2.2021 +  done
2.2022 +
2.2023 +subsection \<open>Approximation lemmas\<close>
2.2024 +
2.2025 +lemma INF_approx_ennreal:
2.2026 +  fixes x::ennreal and e::real
2.2027 +  assumes "e > 0"
2.2028 +  assumes INF: "x = (INF i : A. f i)"
2.2029 +  assumes "x \<noteq> \<infinity>"
2.2030 +  shows "\<exists>i \<in> A. f i < x + e"
2.2031 +proof -
2.2032 +  have "(INF i : A. f i) < x + e"
2.2033 +    unfolding INF[symmetric] using \<open>0<e\<close> \<open>x \<noteq> \<infinity>\<close> by (cases x) auto
2.2034 +  then show ?thesis
2.2035 +    unfolding INF_less_iff .
2.2036 +qed
2.2037 +
2.2038 +lemma SUP_approx_ennreal:
2.2039 +  fixes x::ennreal and e::real
2.2040 +  assumes "e > 0" "A \<noteq> {}"
2.2041 +  assumes SUP: "x = (SUP i : A. f i)"
2.2042 +  assumes "x \<noteq> \<infinity>"
2.2043 +  shows "\<exists>i \<in> A. x < f i + e"
2.2044 +proof -
2.2045 +  have "x < x + e"
2.2046 +    using \<open>0<e\<close> \<open>x \<noteq> \<infinity>\<close> by (cases x) auto
2.2047 +  also have "x + e = (SUP i : A. f i + e)"
2.2048 +    unfolding SUP ennreal_SUP_add_left[OF \<open>A \<noteq> {}\<close>] ..
2.2049 +  finally show ?thesis
2.2050 +    unfolding less_SUP_iff .
2.2051 +qed
2.2052 +
2.2053 +lemma ennreal_approx_SUP:
2.2054 +  fixes x::ennreal
2.2055 +  assumes f_bound: "\<And>i. i \<in> A \<Longrightarrow> f i \<le> x"
2.2056 +  assumes approx: "\<And>e. (e::real) > 0 \<Longrightarrow> \<exists>i \<in> A. x \<le> f i + e"
2.2057 +  shows "x = (SUP i : A. f i)"
2.2058 +proof (rule antisym)
2.2059 +  show "x \<le> (SUP i:A. f i)"
2.2060 +  proof (rule ennreal_le_epsilon)
2.2061 +    fix e :: real assume "0 < e"
2.2062 +    from approx[OF this] guess i ..
2.2063 +    then have "x \<le> f i + e"
2.2064 +      by simp
2.2065 +    also have "\<dots> \<le> (SUP i:A. f i) + e"
2.2066 +      by (intro add_mono \<open>i \<in> A\<close> SUP_upper order_refl)
2.2067 +    finally show "x \<le> (SUP i:A. f i) + e" .
2.2068 +  qed
2.2069 +qed (intro SUP_least f_bound)
2.2070 +
2.2071 +lemma ennreal_approx_INF:
2.2072 +  fixes x::ennreal
2.2073 +  assumes f_bound: "\<And>i. i \<in> A \<Longrightarrow> x \<le> f i"
2.2074 +  assumes approx: "\<And>e. (e::real) > 0 \<Longrightarrow> \<exists>i \<in> A. f i \<le> x + e"
2.2075 +  shows "x = (INF i : A. f i)"
2.2076 +proof (rule antisym)
2.2077 +  show "(INF i:A. f i) \<le> x"
2.2078 +  proof (rule ennreal_le_epsilon)
2.2079 +    fix e :: real assume "0 < e"
2.2080 +    from approx[OF this] guess i .. note i = this
2.2081 +    then have "(INF i:A. f i) \<le> f i"
2.2082 +      by (intro INF_lower)
2.2083 +    also have "\<dots> \<le> x + e"
2.2084 +      by fact
2.2085 +    finally show "(INF i:A. f i) \<le> x + e" .
2.2086 +  qed
2.2087 +qed (intro INF_greatest f_bound)
2.2088 +
2.2089 +lemma ennreal_approx_unit:
2.2090 +  "(\<And>a::ennreal. 0 < a \<Longrightarrow> a < 1 \<Longrightarrow> a * z \<le> y) \<Longrightarrow> z \<le> y"
2.2091 +  apply (subst SUP_mult_right_ennreal[of "\<lambda>x. x" "{0 <..< 1}" z, simplified])
2.2092 +  apply (rule SUP_least)
2.2093 +  apply auto
2.2094 +  done
2.2095 +
2.2096 +lemma suminf_ennreal2:
2.2097 +  "(\<And>i. 0 \<le> f i) \<Longrightarrow> summable f \<Longrightarrow> (\<Sum>i. ennreal (f i)) = ennreal (\<Sum>i. f i)"
2.2098 +  using suminf_ennreal_eq by blast
2.2099 +
2.2100 +lemma less_top_ennreal: "x < top \<longleftrightarrow> (\<exists>r\<ge>0. x = ennreal r)"
2.2101 +  by (cases x) auto
2.2102 +
2.2103 +lemma tendsto_top_iff_ennreal:
2.2104 +  fixes f :: "'a \<Rightarrow> ennreal"
2.2105 +  shows "(f \<longlongrightarrow> top) F \<longleftrightarrow> (\<forall>l\<ge>0. eventually (\<lambda>x. ennreal l < f x) F)"
2.2106 +  by (auto simp: less_top_ennreal order_tendsto_iff )
2.2107 +
2.2108 +lemma ennreal_tendsto_top_eq_at_top:
2.2109 +  "((\<lambda>z. ennreal (f z)) \<longlongrightarrow> top) F \<longleftrightarrow> (LIM z F. f z :> at_top)"
2.2110 +  unfolding filterlim_at_top_dense tendsto_top_iff_ennreal
2.2111 +  apply (auto simp: ennreal_less_iff)
2.2112 +  subgoal for y
2.2113 +    by (auto elim!: eventually_mono allE[of _ "max 0 y"])
2.2114 +  done
2.2115 +
2.2116 +lemma tendsto_0_if_Limsup_eq_0_ennreal:
2.2117 +  fixes f :: "_ \<Rightarrow> ennreal"
2.2118 +  shows "Limsup F f = 0 \<Longrightarrow> (f \<longlongrightarrow> 0) F"
2.2119 +  using Liminf_le_Limsup[of F f] tendsto_iff_Liminf_eq_Limsup[of F f 0]
2.2120 +  by (cases "F = bot") auto
2.2121 +
2.2122 +lemma diff_le_self_ennreal[simp]: "a - b \<le> (a::ennreal)"
2.2123 +  by (cases a b rule: ennreal2_cases) (auto simp: ennreal_minus)
2.2124 +
2.2125 +lemma ennreal_ineq_diff_add: "b \<le> a \<Longrightarrow> a = b + (a - b::ennreal)"
2.2126 +  by transfer (auto simp: ereal_diff_positive max.absorb2 ereal_ineq_diff_add)
2.2127 +
2.2128 +lemma ennreal_mult_strict_left_mono: "(a::ennreal) < c \<Longrightarrow> 0 < b \<Longrightarrow> b < top \<Longrightarrow> b * a < b * c"
2.2129 +  by transfer (auto intro!: ereal_mult_strict_left_mono)
2.2130 +
2.2131 +lemma ennreal_between: "0 < e \<Longrightarrow> 0 < x \<Longrightarrow> x < top \<Longrightarrow> x - e < (x::ennreal)"
2.2132 +  by transfer (auto intro!: ereal_between)
2.2133 +
2.2134 +lemma minus_less_iff_ennreal: "b < top \<Longrightarrow> b \<le> a \<Longrightarrow> a - b < c \<longleftrightarrow> a < c + (b::ennreal)"
2.2135 +  by transfer
2.2136 +     (auto simp: top_ereal_def ereal_minus_less le_less)
2.2137 +
2.2138 +lemma tendsto_zero_ennreal:
2.2139 +  assumes ev: "\<And>r. 0 < r \<Longrightarrow> \<forall>\<^sub>F x in F. f x < ennreal r"
2.2140 +  shows "(f \<longlongrightarrow> 0) F"
2.2141 +proof (rule order_tendstoI)
2.2142 +  fix e::ennreal assume "e > 0"
2.2143 +  obtain e'::real where "e' > 0" "ennreal e' < e"
2.2144 +    using `0 < e` dense[of 0 "if e = top then 1 else (enn2real e)"]
2.2145 +    by (cases e) (auto simp: ennreal_less_iff)
2.2146 +  from ev[OF \<open>e' > 0\<close>] show "\<forall>\<^sub>F x in F. f x < e"
2.2147 +    by eventually_elim (insert \<open>ennreal e' < e\<close>, auto)
2.2148 +qed simp
2.2149 +
2.2150 +lifting_update ennreal.lifting
2.2151 +lifting_forget ennreal.lifting
2.2152 +
2.2153 +end
```
```     3.1 --- a/src/HOL/Library/Extended_Real.thy	Thu Apr 14 12:17:44 2016 +0200
3.2 +++ b/src/HOL/Library/Extended_Real.thy	Thu Apr 14 15:48:11 2016 +0200
3.3 @@ -3547,7 +3547,7 @@
3.4    using Liminf_le_Limsup[OF assms, of f]
3.5    by auto
3.6
3.7 -lemma convergent_ereal:
3.8 +lemma convergent_ereal: -- \<open>RENAME\<close>
3.9    fixes X :: "nat \<Rightarrow> 'a :: {complete_linorder,linorder_topology}"
3.10    shows "convergent X \<longleftrightarrow> limsup X = liminf X"
3.11    using tendsto_iff_Liminf_eq_Limsup[of sequentially]
```
```     4.1 --- a/src/HOL/Library/Liminf_Limsup.thy	Thu Apr 14 12:17:44 2016 +0200
4.2 +++ b/src/HOL/Library/Liminf_Limsup.thy	Thu Apr 14 15:48:11 2016 +0200
4.3 @@ -555,4 +555,14 @@
4.4      using \<open>subseq r\<close> by auto
4.5  qed
4.6
4.7 +lemma tendsto_Limsup:
4.8 +  fixes f :: "_ \<Rightarrow> 'a :: {complete_linorder,linorder_topology}"
4.9 +  shows "F \<noteq> bot \<Longrightarrow> Limsup F f = Liminf F f \<Longrightarrow> (f \<longlongrightarrow> Limsup F f) F"
4.10 +  by (subst tendsto_iff_Liminf_eq_Limsup) auto
4.11 +
4.12 +lemma tendsto_Liminf:
4.13 +  fixes f :: "_ \<Rightarrow> 'a :: {complete_linorder,linorder_topology}"
4.14 +  shows "F \<noteq> bot \<Longrightarrow> Limsup F f = Liminf F f \<Longrightarrow> (f \<longlongrightarrow> Liminf F f) F"
4.15 +  by (subst tendsto_iff_Liminf_eq_Limsup) auto
4.16 +
4.17  end
```
```     5.1 --- a/src/HOL/Probability/Binary_Product_Measure.thy	Thu Apr 14 12:17:44 2016 +0200
5.2 +++ b/src/HOL/Probability/Binary_Product_Measure.thy	Thu Apr 14 15:48:11 2016 +0200
5.3 @@ -110,8 +110,8 @@
5.4    shows "f \<in> measurable M (M1 \<Otimes>\<^sub>M M2)"
5.5    using measurable_Pair[OF assms] by simp
5.6
5.7 -lemma
5.8 -  assumes f[measurable]: "f \<in> measurable M (N \<Otimes>\<^sub>M P)"
5.9 +lemma
5.10 +  assumes f[measurable]: "f \<in> measurable M (N \<Otimes>\<^sub>M P)"
5.11    shows measurable_fst': "(\<lambda>x. fst (f x)) \<in> measurable M N"
5.12      and measurable_snd': "(\<lambda>x. snd (f x)) \<in> measurable M P"
5.13    by simp_all
5.14 @@ -134,7 +134,7 @@
5.15      finally have "a \<times> b \<in> sets (Sup_sigma {?fst, ?snd})" . }
5.16    moreover have "sets ?fst \<subseteq> sets (A \<Otimes>\<^sub>M B)"
5.17      by (rule sets_image_in_sets) (auto simp: space_pair_measure[symmetric])
5.18 -  moreover have "sets ?snd \<subseteq> sets (A \<Otimes>\<^sub>M B)"
5.19 +  moreover have "sets ?snd \<subseteq> sets (A \<Otimes>\<^sub>M B)"
5.20      by (rule sets_image_in_sets) (auto simp: space_pair_measure)
5.21    ultimately show ?thesis
5.22      by (intro antisym[of "sets A" for A] sets_Sup_in_sets sets_pair_in_sets )
5.23 @@ -143,7 +143,7 @@
5.24
5.25  lemma measurable_pair_iff:
5.26    "f \<in> measurable M (M1 \<Otimes>\<^sub>M M2) \<longleftrightarrow> (fst \<circ> f) \<in> measurable M M1 \<and> (snd \<circ> f) \<in> measurable M M2"
5.27 -  by (auto intro: measurable_pair[of f M M1 M2])
5.28 +  by (auto intro: measurable_pair[of f M M1 M2])
5.29
5.30  lemma measurable_split_conv:
5.31    "(\<lambda>(x, y). f x y) \<in> measurable A B \<longleftrightarrow> (\<lambda>x. f (fst x) (snd x)) \<in> measurable A B"
5.32 @@ -190,7 +190,7 @@
5.33    shows "(\<lambda>y. f (x, y)) \<in> measurable M2 M"
5.34    using measurable_comp[OF measurable_Pair1' f, OF x]
5.36 -
5.37 +
5.38  lemma measurable_Pair1:
5.39    assumes f: "f \<in> measurable (M1 \<Otimes>\<^sub>M M2) M" and y: "y \<in> space M2"
5.40    shows "(\<lambda>x. f (x, y)) \<in> measurable M1 M"
5.41 @@ -279,7 +279,7 @@
5.42    shows "emeasure (N \<Otimes>\<^sub>M M) X = (\<integral>\<^sup>+ x. \<integral>\<^sup>+ y. indicator X (x, y) \<partial>M \<partial>N)" (is "_ = ?\<mu> X")
5.43  proof (rule emeasure_measure_of[OF pair_measure_def])
5.44    show "positive (sets (N \<Otimes>\<^sub>M M)) ?\<mu>"
5.45 -    by (auto simp: positive_def nn_integral_nonneg)
5.46 +    by (auto simp: positive_def)
5.47    have eq[simp]: "\<And>A x y. indicator A (x, y) = indicator (Pair x -` A) y"
5.48      by (auto simp: indicator_def)
5.49    show "countably_additive (sets (N \<Otimes>\<^sub>M M)) ?\<mu>"
5.50 @@ -291,7 +291,7 @@
5.51      moreover have "\<And>x. range (\<lambda>i. Pair x -` F i) \<subseteq> sets M"
5.52        using F by (auto simp: sets_Pair1)
5.53      ultimately show "(\<Sum>n. ?\<mu> (F n)) = ?\<mu> (\<Union>i. F i)"
5.54 -      by (auto simp add: nn_integral_suminf[symmetric] vimage_UN suminf_emeasure emeasure_nonneg
5.55 +      by (auto simp add: nn_integral_suminf[symmetric] vimage_UN suminf_emeasure
5.56                 intro!: nn_integral_cong nn_integral_indicator[symmetric])
5.57    qed
5.58    show "{a \<times> b |a b. a \<in> sets N \<and> b \<in> sets M} \<subseteq> Pow (space N \<times> space M)"
5.59 @@ -315,7 +315,7 @@
5.60    have "emeasure (N \<Otimes>\<^sub>M M) (A \<times> B) = (\<integral>\<^sup>+x. emeasure M B * indicator A x \<partial>N)"
5.61      using A B by (auto intro!: nn_integral_cong simp: emeasure_pair_measure_alt)
5.62    also have "\<dots> = emeasure M B * emeasure N A"
5.63 -    using A by (simp add: emeasure_nonneg nn_integral_cmult_indicator)
5.64 +    using A by (simp add: nn_integral_cmult_indicator)
5.65    finally show ?thesis
5.67  qed
5.68 @@ -373,9 +373,8 @@
5.69    next
5.70      fix i
5.71      from F1 F2 have "F1 i \<in> sets M1" "F2 i \<in> sets M2" by auto
5.72 -    with F1 F2 emeasure_nonneg[of M1 "F1 i"] emeasure_nonneg[of M2 "F2 i"]
5.73 -    show "emeasure (M1 \<Otimes>\<^sub>M M2) (F1 i \<times> F2 i) \<noteq> \<infinity>"
5.74 -      by (auto simp add: emeasure_pair_measure_Times)
5.75 +    with F1 F2 show "emeasure (M1 \<Otimes>\<^sub>M M2) (F1 i \<times> F2 i) \<noteq> \<infinity>"
5.76 +      by (auto simp add: emeasure_pair_measure_Times ennreal_mult_eq_top_iff)
5.77    qed
5.78  qed
5.79
5.80 @@ -386,8 +385,7 @@
5.81    ultimately show
5.82      "\<exists>A. countable A \<and> A \<subseteq> sets (M1 \<Otimes>\<^sub>M M2) \<and> \<Union>A = space (M1 \<Otimes>\<^sub>M M2) \<and> (\<forall>a\<in>A. emeasure (M1 \<Otimes>\<^sub>M M2) a \<noteq> \<infinity>)"
5.83      by (intro exI[of _ "(\<lambda>(a, b). a \<times> b) ` (F1 \<times> F2)"] conjI)
5.84 -       (auto simp: M2.emeasure_pair_measure_Times space_pair_measure set_eq_iff subset_eq
5.85 -             dest: sets.sets_into_space)
5.86 +       (auto simp: M2.emeasure_pair_measure_Times space_pair_measure set_eq_iff subset_eq ennreal_mult_eq_top_iff)
5.87  qed
5.88
5.89  lemma sigma_finite_pair_measure:
5.90 @@ -455,9 +453,9 @@
5.91    proof (rule AE_I)
5.92      from N measurable_emeasure_Pair1[OF \<open>N \<in> sets (M1 \<Otimes>\<^sub>M M2)\<close>]
5.93      show "emeasure M1 {x\<in>space M1. emeasure M2 (Pair x -` N) \<noteq> 0} = 0"
5.94 -      by (auto simp: M2.emeasure_pair_measure_alt nn_integral_0_iff emeasure_nonneg)
5.95 +      by (auto simp: M2.emeasure_pair_measure_alt nn_integral_0_iff)
5.96      show "{x \<in> space M1. emeasure M2 (Pair x -` N) \<noteq> 0} \<in> sets M1"
5.97 -      by (intro borel_measurable_ereal_neq_const measurable_emeasure_Pair1 N)
5.98 +      by (intro borel_measurable_eq measurable_emeasure_Pair1 N sets.sets_Collect_neg N) simp
5.99      { fix x assume "x \<in> space M1" "emeasure M2 (Pair x -` N) = 0"
5.100        have "AE y in M2. Q (x, y)"
5.101        proof (rule AE_I)
5.102 @@ -523,8 +521,8 @@
5.103    "x \<in> space M1 \<Longrightarrow> g \<in> measurable (M1 \<Otimes>\<^sub>M M2) L \<Longrightarrow> (\<lambda>y. g (x, y)) \<in> measurable M2 L"
5.104    by simp
5.105
5.106 -lemma (in sigma_finite_measure) borel_measurable_nn_integral_fst':
5.107 -  assumes f: "f \<in> borel_measurable (M1 \<Otimes>\<^sub>M M)" "\<And>x. 0 \<le> f x"
5.108 +lemma (in sigma_finite_measure) borel_measurable_nn_integral_fst:
5.109 +  assumes f: "f \<in> borel_measurable (M1 \<Otimes>\<^sub>M M)"
5.110    shows "(\<lambda>x. \<integral>\<^sup>+ y. f (x, y) \<partial>M) \<in> borel_measurable M1"
5.111  using f proof induct
5.112    case (cong u v)
5.113 @@ -547,8 +545,8 @@
5.114                     nn_integral_monotone_convergence_SUP incseq_def le_fun_def
5.115                cong: measurable_cong)
5.116
5.117 -lemma (in sigma_finite_measure) nn_integral_fst':
5.118 -  assumes f: "f \<in> borel_measurable (M1 \<Otimes>\<^sub>M M)" "\<And>x. 0 \<le> f x"
5.119 +lemma (in sigma_finite_measure) nn_integral_fst:
5.120 +  assumes f: "f \<in> borel_measurable (M1 \<Otimes>\<^sub>M M)"
5.121    shows "(\<integral>\<^sup>+ x. \<integral>\<^sup>+ y. f (x, y) \<partial>M \<partial>M1) = integral\<^sup>N (M1 \<Otimes>\<^sub>M M) f" (is "?I f = _")
5.122  using f proof induct
5.123    case (cong u v)
5.124 @@ -557,26 +555,16 @@
5.125    with cong show ?case
5.126      by (simp cong: nn_integral_cong)
5.128 -                   nn_integral_monotone_convergence_SUP
5.129 -                   measurable_compose_Pair1 nn_integral_nonneg
5.130 -                   borel_measurable_nn_integral_fst' nn_integral_mono incseq_def le_fun_def
5.131 +                   nn_integral_monotone_convergence_SUP measurable_compose_Pair1
5.132 +                   borel_measurable_nn_integral_fst nn_integral_mono incseq_def le_fun_def
5.133                cong: nn_integral_cong)
5.134
5.135 -lemma (in sigma_finite_measure) nn_integral_fst:
5.136 -  assumes f: "f \<in> borel_measurable (M1 \<Otimes>\<^sub>M M)"
5.137 -  shows "(\<integral>\<^sup>+ x. (\<integral>\<^sup>+ y. f (x, y) \<partial>M) \<partial>M1) = integral\<^sup>N (M1 \<Otimes>\<^sub>M M) f"
5.138 -  using f
5.139 -    borel_measurable_nn_integral_fst'[of "\<lambda>x. max 0 (f x)"]
5.140 -    nn_integral_fst'[of "\<lambda>x. max 0 (f x)"]
5.141 -  unfolding nn_integral_max_0 by auto
5.142 -
5.143  lemma (in sigma_finite_measure) borel_measurable_nn_integral[measurable (raw)]:
5.144    "case_prod f \<in> borel_measurable (N \<Otimes>\<^sub>M M) \<Longrightarrow> (\<lambda>x. \<integral>\<^sup>+ y. f x y \<partial>M) \<in> borel_measurable N"
5.145 -  using borel_measurable_nn_integral_fst'[of "\<lambda>x. max 0 (case_prod f x)" N]
5.146 -  by (simp add: nn_integral_max_0)
5.147 +  using borel_measurable_nn_integral_fst[of "case_prod f" N] by simp
5.148
5.149  lemma (in pair_sigma_finite) nn_integral_snd:
5.150 -  assumes f: "f \<in> borel_measurable (M1 \<Otimes>\<^sub>M M2)"
5.151 +  assumes f[measurable]: "f \<in> borel_measurable (M1 \<Otimes>\<^sub>M M2)"
5.152    shows "(\<integral>\<^sup>+ y. (\<integral>\<^sup>+ x. f (x, y) \<partial>M1) \<partial>M2) = integral\<^sup>N (M1 \<Otimes>\<^sub>M M2) f"
5.153  proof -
5.154    note measurable_pair_swap[OF f]
5.155 @@ -584,8 +572,7 @@
5.156    have "(\<integral>\<^sup>+ y. (\<integral>\<^sup>+ x. f (x, y) \<partial>M1) \<partial>M2) = (\<integral>\<^sup>+ (x, y). f (y, x) \<partial>(M2 \<Otimes>\<^sub>M M1))"
5.157      by simp
5.158    also have "(\<integral>\<^sup>+ (x, y). f (y, x) \<partial>(M2 \<Otimes>\<^sub>M M1)) = integral\<^sup>N (M1 \<Otimes>\<^sub>M M2) f"
5.159 -    by (subst distr_pair_swap)
5.160 -       (auto simp: nn_integral_distr[OF measurable_pair_swap' f] intro!: nn_integral_cong)
5.161 +    by (subst distr_pair_swap) (auto simp add: nn_integral_distr intro!: nn_integral_cong)
5.162    finally show ?thesis .
5.163  qed
5.164
5.165 @@ -610,13 +597,13 @@
5.166    have [simp]: "snd \<in> X \<times> Y \<rightarrow> Y" "fst \<in> X \<times> Y \<rightarrow> X"
5.167      by auto
5.168    let ?XY = "{{fst -` a \<inter> X \<times> Y | a. a \<in> A}, {snd -` b \<inter> X \<times> Y | b. b \<in> B}}"
5.169 -  have "sets ?P =
5.170 +  have "sets ?P =
5.171      sets (\<Squnion>\<^sub>\<sigma> xy\<in>?XY. sigma (X \<times> Y) xy)"
5.172      by (simp add: vimage_algebra_sigma sets_pair_eq_sets_fst_snd A B)
5.173    also have "\<dots> = sets (sigma (X \<times> Y) (\<Union>?XY))"
5.174      by (intro Sup_sigma_sigma arg_cong[where f=sets]) auto
5.175    also have "\<dots> = sets ?S"
5.176 -  proof (intro arg_cong[where f=sets] sigma_eqI sigma_sets_eqI)
5.177 +  proof (intro arg_cong[where f=sets] sigma_eqI sigma_sets_eqI)
5.178      show "\<Union>?XY \<subseteq> Pow (X \<times> Y)" "{a \<times> b |a b. a \<in> A \<and> b \<in> B} \<subseteq> Pow (X \<times> Y)"
5.179        using A B by auto
5.180    next
5.181 @@ -710,20 +697,17 @@
5.182    with A B have fin_Pair: "\<And>x. finite (Pair x -` X)"
5.183      by (intro finite_subset[OF _ B]) auto
5.184    have fin_X: "finite X" using X_subset by (rule finite_subset) (auto simp: A B)
5.185 +  have pos_card: "(0::ennreal) < of_nat (card (Pair x -` X)) \<longleftrightarrow> Pair x -` X \<noteq> {}" for x
5.186 +    by (auto simp: card_eq_0_iff fin_Pair) blast
5.187 +
5.188    show "emeasure ?P X = emeasure ?C X"
5.189 +    using X_subset A fin_Pair fin_X
5.190      apply (subst B.emeasure_pair_measure_alt[OF X])
5.191      apply (subst emeasure_count_space)
5.192 -    using X_subset apply auto []
5.193 -    apply (simp add: fin_Pair emeasure_count_space X_subset fin_X)
5.194 -    apply (subst nn_integral_count_space)
5.195 -    using A apply simp
5.196 -    apply (simp del: of_nat_setsum add: of_nat_setsum[symmetric])
5.197 -    apply (subst card_gt_0_iff)
5.198 -    apply (simp add: fin_Pair)
5.199 -    apply (subst card_SigmaI[symmetric])
5.200 -    using A apply simp
5.201 -    using fin_Pair apply simp
5.202 -    using X_subset apply (auto intro!: arg_cong[where f=card])
5.203 +    apply (auto simp add: emeasure_count_space nn_integral_count_space
5.204 +                          pos_card of_nat_setsum[symmetric] card_SigmaI[symmetric]
5.205 +                simp del: of_nat_setsum card_SigmaI
5.206 +                intro!: arg_cong[where f=card])
5.207      done
5.208  qed
5.209
5.210 @@ -732,16 +716,15 @@
5.211    assumes A: "A \<in> sets (count_space UNIV \<Otimes>\<^sub>M M)" (is "A \<in> sets (?A \<Otimes>\<^sub>M ?B)")
5.212    shows "emeasure (?A \<Otimes>\<^sub>M ?B) A = (\<integral>\<^sup>+ x. \<integral>\<^sup>+ y. indicator A (x, y) \<partial>?B \<partial>?A)"
5.213    by (rule emeasure_measure_of[OF pair_measure_def])
5.214 -     (auto simp: countably_additive_def positive_def suminf_indicator nn_integral_nonneg A
5.215 +     (auto simp: countably_additive_def positive_def suminf_indicator A
5.216                   nn_integral_suminf[symmetric] dest: sets.sets_into_space)
5.217
5.218  lemma emeasure_prod_count_space_single[simp]: "emeasure (count_space UNIV \<Otimes>\<^sub>M count_space UNIV) {x} = 1"
5.219  proof -
5.220 -  have [simp]: "\<And>a b x y. indicator {(a, b)} (x, y) = (indicator {a} x * indicator {b} y::ereal)"
5.221 +  have [simp]: "\<And>a b x y. indicator {(a, b)} (x, y) = (indicator {a} x * indicator {b} y::ennreal)"
5.222      by (auto split: split_indicator)
5.223    show ?thesis
5.224 -    by (cases x)
5.225 -       (auto simp: emeasure_prod_count_space nn_integral_cmult sets_Pair nn_integral_max_0 one_ereal_def[symmetric])
5.226 +    by (cases x) (auto simp: emeasure_prod_count_space nn_integral_cmult sets_Pair)
5.227  qed
5.228
5.229  lemma emeasure_count_space_prod_eq:
5.230 @@ -771,17 +754,16 @@
5.231      also have "emeasure (?A \<Otimes>\<^sub>M ?B) C = emeasure (count_space UNIV) C"
5.232        using \<open>countable C\<close> by (rule *)
5.233      finally show ?thesis
5.234 -      using \<open>infinite C\<close> \<open>infinite A\<close> by simp
5.235 +      using \<open>infinite C\<close> \<open>infinite A\<close> by (simp add: top_unique)
5.236    qed
5.237  qed
5.238
5.239 -lemma nn_intergal_count_space_prod_eq':
5.240 -  assumes [simp]: "\<And>x. 0 \<le> f x"
5.241 -  shows "nn_integral (count_space UNIV \<Otimes>\<^sub>M count_space UNIV) f = nn_integral (count_space UNIV) f"
5.242 +lemma nn_integral_count_space_prod_eq:
5.243 +  "nn_integral (count_space UNIV \<Otimes>\<^sub>M count_space UNIV) f = nn_integral (count_space UNIV) f"
5.244      (is "nn_integral ?P f = _")
5.245  proof cases
5.246    assume cntbl: "countable {x. f x \<noteq> 0}"
5.247 -  have [simp]: "\<And>x. ereal (real (card ({x} \<inter> {x. f x \<noteq> 0}))) = indicator {x. f x \<noteq> 0} x"
5.248 +  have [simp]: "\<And>x. card ({x} \<inter> {x. f x \<noteq> 0}) = (indicator {x. f x \<noteq> 0} x::ennreal)"
5.249      by (auto split: split_indicator)
5.250    have [measurable]: "\<And>y. (\<lambda>x. indicator {y} x) \<in> borel_measurable ?P"
5.251      by (rule measurable_discrete_difference[of "\<lambda>x. 0" _ borel "{y}" "\<lambda>x. indicator {y} x" for y])
5.252 @@ -799,9 +781,9 @@
5.253      by (auto simp add: nn_integral_count_space_indicator intro!: nn_integral_cong split: split_indicator)
5.254  next
5.255    { fix x assume "f x \<noteq> 0"
5.256 -    with \<open>0 \<le> f x\<close> have "(\<exists>r. 0 < r \<and> f x = ereal r) \<or> f x = \<infinity>"
5.257 -      by (cases "f x") (auto simp: less_le)
5.258 -    then have "\<exists>n. ereal (1 / real (Suc n)) \<le> f x"
5.259 +    then have "(\<exists>r\<ge>0. 0 < r \<and> f x = ennreal r) \<or> f x = \<infinity>"
5.260 +      by (cases "f x" rule: ennreal_cases) (auto simp: less_le)
5.261 +    then have "\<exists>n. ennreal (1 / real (Suc n)) \<le> f x"
5.262        by (auto elim!: nat_approx_posE intro!: less_imp_le) }
5.263    note * = this
5.264
5.265 @@ -816,25 +798,21 @@
5.266    have [measurable]: "C \<in> sets ?P"
5.267      using sets.countable[OF _ \<open>countable C\<close>, of ?P] by (auto simp: sets_Pair)
5.268
5.269 -  have "(\<integral>\<^sup>+x. ereal (1/Suc n) * indicator C x \<partial>?P) \<le> nn_integral ?P f"
5.270 +  have "(\<integral>\<^sup>+x. ennreal (1/Suc n) * indicator C x \<partial>?P) \<le> nn_integral ?P f"
5.271      using C by (intro nn_integral_mono) (auto split: split_indicator simp: zero_ereal_def[symmetric])
5.272 -  moreover have "(\<integral>\<^sup>+x. ereal (1/Suc n) * indicator C x \<partial>?P) = \<infinity>"
5.273 -    using \<open>infinite C\<close> by (simp add: nn_integral_cmult emeasure_count_space_prod_eq)
5.274 -  moreover have "(\<integral>\<^sup>+x. ereal (1/Suc n) * indicator C x \<partial>count_space UNIV) \<le> nn_integral (count_space UNIV) f"
5.275 +  moreover have "(\<integral>\<^sup>+x. ennreal (1/Suc n) * indicator C x \<partial>?P) = \<infinity>"
5.276 +    using \<open>infinite C\<close> by (simp add: nn_integral_cmult emeasure_count_space_prod_eq ennreal_mult_top)
5.277 +  moreover have "(\<integral>\<^sup>+x. ennreal (1/Suc n) * indicator C x \<partial>count_space UNIV) \<le> nn_integral (count_space UNIV) f"
5.278      using C by (intro nn_integral_mono) (auto split: split_indicator simp: zero_ereal_def[symmetric])
5.279 -  moreover have "(\<integral>\<^sup>+x. ereal (1/Suc n) * indicator C x \<partial>count_space UNIV) = \<infinity>"
5.280 -    using \<open>infinite C\<close> by (simp add: nn_integral_cmult)
5.281 +  moreover have "(\<integral>\<^sup>+x. ennreal (1/Suc n) * indicator C x \<partial>count_space UNIV) = \<infinity>"
5.282 +    using \<open>infinite C\<close> by (simp add: nn_integral_cmult ennreal_mult_top)
5.283    ultimately show ?thesis
5.284 -    by simp
5.285 +    by (simp add: top_unique)
5.286  qed
5.287
5.288 -lemma nn_intergal_count_space_prod_eq:
5.289 -  "nn_integral (count_space UNIV \<Otimes>\<^sub>M count_space UNIV) f = nn_integral (count_space UNIV) f"
5.290 -  by (subst (1 2) nn_integral_max_0[symmetric]) (auto intro!: nn_intergal_count_space_prod_eq')
5.291 -
5.292  lemma pair_measure_density:
5.293 -  assumes f: "f \<in> borel_measurable M1" "AE x in M1. 0 \<le> f x"
5.294 -  assumes g: "g \<in> borel_measurable M2" "AE x in M2. 0 \<le> g x"
5.295 +  assumes f: "f \<in> borel_measurable M1"
5.296 +  assumes g: "g \<in> borel_measurable M2"
5.297    assumes "sigma_finite_measure M2" "sigma_finite_measure (density M2 g)"
5.298    shows "density M1 f \<Otimes>\<^sub>M density M2 g = density (M1 \<Otimes>\<^sub>M M2) (\<lambda>(x,y). f x * g y)" (is "?L = ?R")
5.299  proof (rule measure_eqI)
5.300 @@ -916,7 +894,7 @@
5.301        by simp
5.302    qed
5.303  qed
5.304 -
5.305 +
5.306  lemma sets_pair_countable:
5.307    assumes "countable S1" "countable S2"
5.308    assumes M: "sets M = Pow S1" and N: "sets N = Pow S2"
5.309 @@ -948,25 +926,22 @@
5.310      by (subst sets_pair_countable[OF assms]) auto
5.311  next
5.312    fix A B assume "A \<in> sets (count_space S1)" "B \<in> sets (count_space S2)"
5.313 -  then show "emeasure (count_space S1) A * emeasure (count_space S2) B =
5.314 +  then show "emeasure (count_space S1) A * emeasure (count_space S2) B =
5.315      emeasure (count_space (S1 \<times> S2)) (A \<times> B)"
5.316 -    by (subst (1 2 3) emeasure_count_space) (auto simp: finite_cartesian_product_iff)
5.317 +    by (subst (1 2 3) emeasure_count_space) (auto simp: finite_cartesian_product_iff ennreal_mult_top ennreal_top_mult)
5.318  qed
5.319
5.320 -lemma nn_integral_fst_count_space':
5.321 -  assumes nonneg: "\<And>xy. 0 \<le> f xy"
5.322 -  shows "(\<integral>\<^sup>+ x. \<integral>\<^sup>+ y. f (x, y) \<partial>count_space UNIV \<partial>count_space UNIV) = integral\<^sup>N (count_space UNIV) f"
5.323 +lemma nn_integral_fst_count_space:
5.324 +  "(\<integral>\<^sup>+ x. \<integral>\<^sup>+ y. f (x, y) \<partial>count_space UNIV \<partial>count_space UNIV) = integral\<^sup>N (count_space UNIV) f"
5.325    (is "?lhs = ?rhs")
5.326  proof(cases)
5.327    assume *: "countable {xy. f xy \<noteq> 0}"
5.328    let ?A = "fst ` {xy. f xy \<noteq> 0}"
5.329    let ?B = "snd ` {xy. f xy \<noteq> 0}"
5.330    from * have [simp]: "countable ?A" "countable ?B" by(rule countable_image)+
5.331 -  from nonneg have f_neq_0: "\<And>xy. f xy \<noteq> 0 \<longleftrightarrow> f xy > 0"
5.332 -    by(auto simp add: order.order_iff_strict)
5.333    have "?lhs = (\<integral>\<^sup>+ x. \<integral>\<^sup>+ y. f (x, y) \<partial>count_space UNIV \<partial>count_space ?A)"
5.334      by(rule nn_integral_count_space_eq)
5.335 -      (auto simp add: f_neq_0 nn_integral_0_iff_AE AE_count_space not_le intro: rev_image_eqI)
5.336 +      (auto simp add: nn_integral_0_iff_AE AE_count_space not_le intro: rev_image_eqI)
5.337    also have "\<dots> = (\<integral>\<^sup>+ x. \<integral>\<^sup>+ y. f (x, y) \<partial>count_space ?B \<partial>count_space ?A)"
5.338      by(intro nn_integral_count_space_eq nn_integral_cong)(auto intro: rev_image_eqI)
5.339    also have "\<dots> = (\<integral>\<^sup>+ xy. f xy \<partial>count_space (?A \<times> ?B))"
5.340 @@ -977,9 +952,9 @@
5.341    finally show ?thesis .
5.342  next
5.343    { fix xy assume "f xy \<noteq> 0"
5.344 -    with \<open>0 \<le> f xy\<close> have "(\<exists>r. 0 < r \<and> f xy = ereal r) \<or> f xy = \<infinity>"
5.345 -      by (cases "f xy") (auto simp: less_le)
5.346 -    then have "\<exists>n. ereal (1 / real (Suc n)) \<le> f xy"
5.347 +    then have "(\<exists>r\<ge>0. 0 < r \<and> f xy = ennreal r) \<or> f xy = \<infinity>"
5.348 +      by (cases "f xy" rule: ennreal_cases) (auto simp: less_le)
5.349 +    then have "\<exists>n. ennreal (1 / real (Suc n)) \<le> f xy"
5.350        by (auto elim!: nat_approx_posE intro!: less_imp_le) }
5.351    note * = this
5.352
5.353 @@ -991,15 +966,15 @@
5.354    then obtain C where C: "C \<subseteq> {xy. 1/Suc n \<le> f xy}" and "countable C" "infinite C"
5.355      by (metis infinite_countable_subset')
5.356
5.357 -  have "\<infinity> = (\<integral>\<^sup>+ xy. ereal (1 / Suc n) * indicator C xy \<partial>count_space UNIV)"
5.358 -    using \<open>infinite C\<close> by(simp add: nn_integral_cmult)
5.359 +  have "\<infinity> = (\<integral>\<^sup>+ xy. ennreal (1 / Suc n) * indicator C xy \<partial>count_space UNIV)"
5.360 +    using \<open>infinite C\<close> by(simp add: nn_integral_cmult ennreal_mult_top)
5.361    also have "\<dots> \<le> ?rhs" using C
5.362 -    by(intro nn_integral_mono)(auto split: split_indicator simp add: nonneg)
5.363 -  finally have "?rhs = \<infinity>" by simp
5.364 +    by(intro nn_integral_mono)(auto split: split_indicator)
5.365 +  finally have "?rhs = \<infinity>" by (simp add: top_unique)
5.366    moreover have "?lhs = \<infinity>"
5.367    proof(cases "finite (fst ` C)")
5.368      case True
5.369 -    then obtain x C' where x: "x \<in> fst ` C"
5.370 +    then obtain x C' where x: "x \<in> fst ` C"
5.371        and C': "C' = fst -` {x} \<inter> C"
5.372        and "infinite C'"
5.373        using \<open>infinite C\<close> by(auto elim!: inf_img_fin_domE')
5.374 @@ -1007,37 +982,33 @@
5.375
5.376      from C' \<open>infinite C'\<close> have "infinite (snd ` C')"
5.377        by(auto dest!: finite_imageD simp add: inj_on_def)
5.378 -    then have "\<infinity> = (\<integral>\<^sup>+ y. ereal (1 / Suc n) * indicator (snd ` C') y \<partial>count_space UNIV)"
5.380 -    also have "\<dots> = (\<integral>\<^sup>+ y. ereal (1 / Suc n) * indicator C' (x, y) \<partial>count_space UNIV)"
5.381 +    then have "\<infinity> = (\<integral>\<^sup>+ y. ennreal (1 / Suc n) * indicator (snd ` C') y \<partial>count_space UNIV)"
5.382 +      by(simp add: nn_integral_cmult ennreal_mult_top)
5.383 +    also have "\<dots> = (\<integral>\<^sup>+ y. ennreal (1 / Suc n) * indicator C' (x, y) \<partial>count_space UNIV)"
5.384        by(rule nn_integral_cong)(force split: split_indicator intro: rev_image_eqI simp add: C')
5.385 -    also have "\<dots> = (\<integral>\<^sup>+ x'. (\<integral>\<^sup>+ y. ereal (1 / Suc n) * indicator C' (x, y) \<partial>count_space UNIV) * indicator {x} x' \<partial>count_space UNIV)"
5.386 -      by(simp add: one_ereal_def[symmetric] nn_integral_nonneg max_def)
5.387 -    also have "\<dots> \<le> (\<integral>\<^sup>+ x. \<integral>\<^sup>+ y. ereal (1 / Suc n) * indicator C' (x, y) \<partial>count_space UNIV \<partial>count_space UNIV)"
5.388 -      by(rule nn_integral_mono)(simp split: split_indicator add: nn_integral_nonneg)
5.389 +    also have "\<dots> = (\<integral>\<^sup>+ x'. (\<integral>\<^sup>+ y. ennreal (1 / Suc n) * indicator C' (x, y) \<partial>count_space UNIV) * indicator {x} x' \<partial>count_space UNIV)"
5.391 +    also have "\<dots> \<le> (\<integral>\<^sup>+ x. \<integral>\<^sup>+ y. ennreal (1 / Suc n) * indicator C' (x, y) \<partial>count_space UNIV \<partial>count_space UNIV)"
5.392 +      by(rule nn_integral_mono)(simp split: split_indicator)
5.393      also have "\<dots> \<le> ?lhs" using **
5.394 -      by(intro nn_integral_mono)(auto split: split_indicator simp add: nonneg)
5.395 -    finally show ?thesis by simp
5.396 +      by(intro nn_integral_mono)(auto split: split_indicator)
5.397 +    finally show ?thesis by (simp add: top_unique)
5.398    next
5.399      case False
5.400      def C' \<equiv> "fst ` C"
5.401 -    have "\<infinity> = \<integral>\<^sup>+ x. ereal (1 / Suc n) * indicator C' x \<partial>count_space UNIV"
5.402 -      using C'_def False by(simp add: nn_integral_cmult)
5.403 -    also have "\<dots> = \<integral>\<^sup>+ x. \<integral>\<^sup>+ y. ereal (1 / Suc n) * indicator C' x * indicator {SOME y. (x, y) \<in> C} y \<partial>count_space UNIV \<partial>count_space UNIV"
5.404 +    have "\<infinity> = \<integral>\<^sup>+ x. ennreal (1 / Suc n) * indicator C' x \<partial>count_space UNIV"
5.405 +      using C'_def False by(simp add: nn_integral_cmult ennreal_mult_top)
5.406 +    also have "\<dots> = \<integral>\<^sup>+ x. \<integral>\<^sup>+ y. ennreal (1 / Suc n) * indicator C' x * indicator {SOME y. (x, y) \<in> C} y \<partial>count_space UNIV \<partial>count_space UNIV"
5.407        by(auto simp add: one_ereal_def[symmetric] max_def intro: nn_integral_cong)
5.408 -    also have "\<dots> \<le> \<integral>\<^sup>+ x. \<integral>\<^sup>+ y. ereal (1 / Suc n) * indicator C (x, y) \<partial>count_space UNIV \<partial>count_space UNIV"
5.409 +    also have "\<dots> \<le> \<integral>\<^sup>+ x. \<integral>\<^sup>+ y. ennreal (1 / Suc n) * indicator C (x, y) \<partial>count_space UNIV \<partial>count_space UNIV"
5.410        by(intro nn_integral_mono)(auto simp add: C'_def split: split_indicator intro: someI)
5.411      also have "\<dots> \<le> ?lhs" using C
5.412 -      by(intro nn_integral_mono)(auto split: split_indicator simp add: nonneg)
5.413 -    finally show ?thesis by simp
5.414 +      by(intro nn_integral_mono)(auto split: split_indicator)
5.415 +    finally show ?thesis by (simp add: top_unique)
5.416    qed
5.417    ultimately show ?thesis by simp
5.418  qed
5.419
5.420 -lemma nn_integral_fst_count_space:
5.421 -  "(\<integral>\<^sup>+ x. \<integral>\<^sup>+ y. f (x, y) \<partial>count_space UNIV \<partial>count_space UNIV) = integral\<^sup>N (count_space UNIV) f"
5.422 -by(subst (2 3) nn_integral_max_0[symmetric])(rule nn_integral_fst_count_space', simp)
5.423 -
5.424  lemma nn_integral_snd_count_space:
5.425    "(\<integral>\<^sup>+ y. \<integral>\<^sup>+ x. f (x, y) \<partial>count_space UNIV \<partial>count_space UNIV) = integral\<^sup>N (count_space UNIV) f"
5.426    (is "?lhs = ?rhs")
5.427 @@ -1118,7 +1089,7 @@
5.428    interpret M: finite_measure M by fact
5.429    interpret N: finite_measure N by fact
5.430    show "emeasure (N  \<Otimes>\<^sub>M M) (space (N  \<Otimes>\<^sub>M M)) \<noteq> \<infinity>"
5.431 -    by (auto simp: space_pair_measure M.emeasure_pair_measure_Times)
5.432 +    by (auto simp: space_pair_measure M.emeasure_pair_measure_Times ennreal_mult_eq_top_iff)
5.433  qed
5.434
5.435  end
```
```     6.1 --- a/src/HOL/Probability/Bochner_Integration.thy	Thu Apr 14 12:17:44 2016 +0200
6.2 +++ b/src/HOL/Probability/Bochner_Integration.thy	Thu Apr 14 15:48:11 2016 +0200
6.3 @@ -36,9 +36,9 @@
6.4
6.5    def A \<equiv> "\<lambda>m n. {x\<in>space M. dist (f x) (e n) < 1 / (Suc m) \<and> 1 / (Suc m) \<le> dist (f x) z}"
6.6    def B \<equiv> "\<lambda>m. disjointed (A m)"
6.7 -
6.8 +
6.9    def m \<equiv> "\<lambda>N x. Max {m::nat. m \<le> N \<and> x \<in> (\<Union>n\<le>N. B m n)}"
6.10 -  def F \<equiv> "\<lambda>N::nat. \<lambda>x. if (\<exists>m\<le>N. x \<in> (\<Union>n\<le>N. B m n)) \<and> (\<exists>n\<le>N. x \<in> B (m N x) n)
6.11 +  def F \<equiv> "\<lambda>N::nat. \<lambda>x. if (\<exists>m\<le>N. x \<in> (\<Union>n\<le>N. B m n)) \<and> (\<exists>n\<le>N. x \<in> B (m N x) n)
6.12      then e (LEAST n. x \<in> B (m N x) n) else z"
6.13
6.14    have B_imp_A[intro, simp]: "\<And>x m n. x \<in> B m n \<Longrightarrow> x \<in> A m n"
6.15 @@ -75,13 +75,13 @@
6.16        { fix n x assume "x \<in> B (m i x) n"
6.17          then have "(LEAST n. x \<in> B (m i x) n) \<le> n"
6.18            by (intro Least_le)
6.19 -        also assume "n \<le> i"
6.20 +        also assume "n \<le> i"
6.21          finally have "(LEAST n. x \<in> B (m i x) n) \<le> i" . }
6.22        then have "F i ` space M \<subseteq> {z} \<union> e ` {.. i}"
6.23          by (auto simp: F_def)
6.24        then show "finite (F i ` space M)"
6.25          by (rule finite_subset) auto }
6.26 -
6.27 +
6.28      { fix N i n x assume "i \<le> N" "n \<le> N" "x \<in> B i n"
6.29        then have 1: "\<exists>m\<le>N. x \<in> (\<Union>n\<le>N. B m n)" by auto
6.30        from m[OF this] obtain n where n: "m N x \<le> N" "n \<le> N" "x \<in> B (m N x) n" by auto
6.31 @@ -137,7 +137,7 @@
6.32          qed
6.33        qed
6.34      qed
6.35 -    fix i
6.36 +    fix i
6.37      { fix n m assume "x \<in> A n m"
6.38        then have "dist (e m) (f x) + dist (f x) z \<le> 2 * dist (f x) z"
6.39          unfolding A_def by (auto simp: dist_commute)
6.40 @@ -153,13 +153,6 @@
6.41    qed
6.42  qed
6.43
6.44 -lemma real_indicator: "real_of_ereal (indicator A x :: ereal) = indicator A x"
6.45 -  unfolding indicator_def by auto
6.46 -
6.47 -lemma split_indicator_asm:
6.48 -  "P (indicator S x) \<longleftrightarrow> \<not> ((x \<in> S \<and> \<not> P 1) \<or> (x \<notin> S \<and> \<not> P 0))"
6.49 -  unfolding indicator_def by auto
6.50 -
6.51  lemma
6.52    fixes f :: "'a \<Rightarrow> 'b::semiring_1" assumes "finite A"
6.53    shows setsum_mult_indicator[simp]: "(\<Sum>x \<in> A. f x * indicator (B x) (g x)) = (\<Sum>x\<in>{x\<in>A. g x \<in> B x}. f x)"
6.54 @@ -176,40 +169,39 @@
6.55    assumes seq: "\<And>U. (\<And>i. U i \<in> borel_measurable M) \<Longrightarrow> (\<And>i x. 0 \<le> U i x) \<Longrightarrow> (\<And>i. P (U i)) \<Longrightarrow> incseq U \<Longrightarrow> (\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. U i x) \<longlonglongrightarrow> u x) \<Longrightarrow> P u"
6.56    shows "P u"
6.57  proof -
6.58 -  have "(\<lambda>x. ereal (u x)) \<in> borel_measurable M" using u by auto
6.59 +  have "(\<lambda>x. ennreal (u x)) \<in> borel_measurable M" using u by auto
6.60    from borel_measurable_implies_simple_function_sequence'[OF this]
6.61 -  obtain U where U: "\<And>i. simple_function M (U i)" "incseq U" "\<And>i. \<infinity> \<notin> range (U i)" and
6.62 -    sup: "\<And>x. (SUP i. U i x) = max 0 (ereal (u x))" and nn: "\<And>i x. 0 \<le> U i x"
6.63 +  obtain U where U: "\<And>i. simple_function M (U i)" "incseq U" "\<And>i x. U i x < top" and
6.64 +    sup: "\<And>x. (SUP i. U i x) = ennreal (u x)"
6.65      by blast
6.66
6.67 -  def U' \<equiv> "\<lambda>i x. indicator (space M) x * real_of_ereal (U i x)"
6.68 +  def U' \<equiv> "\<lambda>i x. indicator (space M) x * enn2real (U i x)"
6.69    then have U'_sf[measurable]: "\<And>i. simple_function M (U' i)"
6.70 -    using U by (auto intro!: simple_function_compose1[where g=real_of_ereal])
6.71 +    using U by (auto intro!: simple_function_compose1[where g=enn2real])
6.72
6.73    show "P u"
6.74    proof (rule seq)
6.75 -    fix i show "U' i \<in> borel_measurable M" "\<And>x. 0 \<le> U' i x"
6.76 -      using U nn by (auto
6.77 -          intro: borel_measurable_simple_function
6.78 -          intro!: borel_measurable_real_of_ereal real_of_ereal_pos borel_measurable_times
6.79 -          simp: U'_def zero_le_mult_iff)
6.80 +    show U': "U' i \<in> borel_measurable M" "\<And>x. 0 \<le> U' i x" for i
6.81 +      using U by (auto
6.82 +          intro: borel_measurable_simple_function
6.83 +          intro!: borel_measurable_enn2real borel_measurable_times
6.84 +          simp: U'_def zero_le_mult_iff enn2real_nonneg)
6.85      show "incseq U'"
6.86 -      using U(2,3) nn
6.87 -      by (auto simp: incseq_def le_fun_def image_iff eq_commute U'_def indicator_def
6.88 -               intro!: real_of_ereal_positive_mono)
6.89 -  next
6.90 +      using U(2,3)
6.91 +      by (auto simp: incseq_def le_fun_def image_iff eq_commute U'_def indicator_def enn2real_mono)
6.92 +
6.93      fix x assume x: "x \<in> space M"
6.94      have "(\<lambda>i. U i x) \<longlonglongrightarrow> (SUP i. U i x)"
6.95        using U(2) by (intro LIMSEQ_SUP) (auto simp: incseq_def le_fun_def)
6.96 -    moreover have "(\<lambda>i. U i x) = (\<lambda>i. ereal (U' i x))"
6.97 -      using x nn U(3) by (auto simp: fun_eq_iff U'_def ereal_real image_iff eq_commute)
6.98 -    moreover have "(SUP i. U i x) = ereal (u x)"
6.99 +    moreover have "(\<lambda>i. U i x) = (\<lambda>i. ennreal (U' i x))"
6.100 +      using x U(3) by (auto simp: fun_eq_iff U'_def image_iff eq_commute)
6.101 +    moreover have "(SUP i. U i x) = ennreal (u x)"
6.102        using sup u(2) by (simp add: max_def)
6.103 -    ultimately show "(\<lambda>i. U' i x) \<longlonglongrightarrow> u x"
6.104 -      by simp
6.105 +    ultimately show "(\<lambda>i. U' i x) \<longlonglongrightarrow> u x"
6.106 +      using u U' by simp
6.107    next
6.108      fix i
6.109 -    have "U' i ` space M \<subseteq> real_of_ereal ` (U i ` space M)" "finite (U i ` space M)"
6.110 +    have "U' i ` space M \<subseteq> enn2real ` (U i ` space M)" "finite (U i ` space M)"
6.111        unfolding U'_def using U(1) by (auto dest: simple_functionD)
6.112      then have fin: "finite (U' i ` space M)"
6.113        by (metis finite_subset finite_imageI)
6.114 @@ -218,7 +210,7 @@
6.115      ultimately have U': "(\<lambda>z. \<Sum>y\<in>U' i`space M. y * indicator {x\<in>space M. U' i x = y} z) = U' i"
6.116        by (simp add: U'_def fun_eq_iff)
6.117      have "\<And>x. x \<in> U' i ` space M \<Longrightarrow> 0 \<le> x"
6.118 -      using nn by (auto simp: U'_def real_of_ereal_pos)
6.119 +      by (auto simp: U'_def enn2real_nonneg)
6.120      with fin have "P (\<lambda>z. \<Sum>y\<in>U' i`space M. y * indicator {x\<in>space M. U' i x = y} z)"
6.121      proof induct
6.122        case empty from set[of "{}"] show ?case
6.123 @@ -227,7 +219,7 @@
6.124        case (insert x F)
6.125        then show ?case
6.126          by (auto intro!: add mult set setsum_nonneg split: split_indicator split_indicator_asm
6.127 -                 simp del: setsum_mult_indicator simp: setsum_nonneg_eq_0_iff )
6.128 +                 simp del: setsum_mult_indicator simp: setsum_nonneg_eq_0_iff)
6.129      qed
6.130      with U' show "P (U' i)" by simp
6.131    qed
6.132 @@ -257,14 +249,14 @@
6.133      by (auto intro: measurable_simple_function)
6.134
6.135    assume fin: "emeasure M {y \<in> space M. f y \<noteq> 0} \<noteq> \<infinity>" "emeasure M {y \<in> space M. g y \<noteq> 0} \<noteq> \<infinity>"
6.136 -
6.137 +
6.138    have "emeasure M {x\<in>space M. p (f x) (g x) \<noteq> 0} \<le>
6.139        emeasure M ({x\<in>space M. f x \<noteq> 0} \<union> {x\<in>space M. g x \<noteq> 0})"
6.140      by (intro emeasure_mono) (auto simp: p_0)
6.141    also have "\<dots> \<le> emeasure M {x\<in>space M. f x \<noteq> 0} + emeasure M {x\<in>space M. g x \<noteq> 0}"
6.143    finally show "emeasure M {y \<in> space M. p (f y) (g y) \<noteq> 0} \<noteq> \<infinity>"
6.144 -    using fin by auto
6.145 +    using fin by (auto simp: top_unique)
6.146  qed
6.147
6.148  lemma simple_function_finite_support:
6.149 @@ -282,7 +274,7 @@
6.150    then have m: "0 < m"
6.151      using nn by (auto simp: less_le)
6.152
6.153 -  from m have "m * emeasure M {x\<in>space M. 0 \<noteq> f x} =
6.154 +  from m have "m * emeasure M {x\<in>space M. 0 \<noteq> f x} =
6.155      (\<integral>\<^sup>+x. m * indicator {x\<in>space M. 0 \<noteq> f x} x \<partial>M)"
6.156      using f by (intro nn_integral_cmult_indicator[symmetric]) auto
6.157    also have "\<dots> \<le> (\<integral>\<^sup>+x. f x \<partial>M)"
6.158 @@ -294,7 +286,7 @@
6.159    qed
6.160    also note \<open>\<dots> < \<infinity>\<close>
6.161    finally show ?thesis
6.162 -    using m by auto
6.163 +    using m by (auto simp: ennreal_mult_less_top)
6.164  next
6.165    assume "\<not> (\<exists>x\<in>space M. f x \<noteq> 0)"
6.166    with nn have *: "{x\<in>space M. f x \<noteq> 0} = {}"
6.167 @@ -306,11 +298,11 @@
6.168    assumes f: "simple_function M f" and fin: "(\<integral>\<^sup>+x. norm (f x) \<partial>M) < \<infinity>"
6.169    shows "simple_bochner_integrable M f"
6.170  proof
6.171 -  have "emeasure M {y \<in> space M. ereal (norm (f y)) \<noteq> 0} \<noteq> \<infinity>"
6.172 +  have "emeasure M {y \<in> space M. ennreal (norm (f y)) \<noteq> 0} \<noteq> \<infinity>"
6.173    proof (rule simple_function_finite_support)
6.174 -    show "simple_function M (\<lambda>x. ereal (norm (f x)))"
6.175 +    show "simple_function M (\<lambda>x. ennreal (norm (f x)))"
6.176        using f by (rule simple_function_compose1)
6.177 -    show "(\<integral>\<^sup>+ y. ereal (norm (f y)) \<partial>M) < \<infinity>" by fact
6.178 +    show "(\<integral>\<^sup>+ y. ennreal (norm (f y)) \<partial>M) < \<infinity>" by fact
6.179    qed simp
6.180    then show "emeasure M {y \<in> space M. f y \<noteq> 0} \<noteq> \<infinity>" by simp
6.181  qed fact
6.182 @@ -340,12 +332,12 @@
6.183    note eq = this
6.184
6.185    have "simple_bochner_integral M f =
6.186 -    (\<Sum>y\<in>f`space M. (\<Sum>z\<in>g`space M.
6.187 +    (\<Sum>y\<in>f`space M. (\<Sum>z\<in>g`space M.
6.188        if \<exists>x\<in>space M. y = f x \<and> z = g x then measure M {x\<in>space M. g x = z} else 0) *\<^sub>R y)"
6.189      unfolding simple_bochner_integral_def
6.190    proof (safe intro!: setsum.cong scaleR_cong_right)
6.191      fix y assume y: "y \<in> space M" "f y \<noteq> 0"
6.192 -    have [simp]: "g ` space M \<inter> {z. \<exists>x\<in>space M. f y = f x \<and> z = g x} =
6.193 +    have [simp]: "g ` space M \<inter> {z. \<exists>x\<in>space M. f y = f x \<and> z = g x} =
6.194          {z. \<exists>x\<in>space M. f y = f x \<and> z = g x}"
6.195        by auto
6.196      have eq:"{x \<in> space M. f x = f y} =
6.197 @@ -361,16 +353,16 @@
6.198        then have "emeasure M {y \<in> space M. g y = g x} \<le> emeasure M {y \<in> space M. f y \<noteq> 0}"
6.199          by (auto intro!: emeasure_mono cong: sub)
6.200        then have "emeasure M {xa \<in> space M. g xa = g x} < \<infinity>"
6.201 -        using f by (auto simp: simple_bochner_integrable.simps) }
6.202 +        using f by (auto simp: simple_bochner_integrable.simps less_top) }
6.203      ultimately
6.204      show "measure M {x \<in> space M. f x = f y} =
6.205        (\<Sum>z\<in>g ` space M. if \<exists>x\<in>space M. f y = f x \<and> z = g x then measure M {x \<in> space M. g x = z} else 0)"
6.206        apply (simp add: setsum.If_cases eq)
6.207        apply (subst measure_finite_Union[symmetric])
6.208 -      apply (auto simp: disjoint_family_on_def)
6.209 +      apply (auto simp: disjoint_family_on_def less_top)
6.210        done
6.211    qed
6.212 -  also have "\<dots> = (\<Sum>y\<in>f`space M. (\<Sum>z\<in>g`space M.
6.213 +  also have "\<dots> = (\<Sum>y\<in>f`space M. (\<Sum>z\<in>g`space M.
6.214        if \<exists>x\<in>space M. y = f x \<and> z = g x then measure M {x\<in>space M. g x = z} *\<^sub>R y else 0))"
6.215      by (auto intro!: setsum.cong simp: scaleR_setsum_left)
6.216    also have "\<dots> = ?r"
6.217 @@ -435,11 +427,11 @@
6.218    assumes f: "simple_bochner_integrable M f"
6.219    shows "norm (simple_bochner_integral M f) \<le> simple_bochner_integral M (\<lambda>x. norm (f x))"
6.220  proof -
6.221 -  have "norm (simple_bochner_integral M f) \<le>
6.222 +  have "norm (simple_bochner_integral M f) \<le>
6.223      (\<Sum>y\<in>f ` space M. norm (measure M {x \<in> space M. f x = y} *\<^sub>R y))"
6.224      unfolding simple_bochner_integral_def by (rule norm_setsum)
6.225    also have "\<dots> = (\<Sum>y\<in>f ` space M. measure M {x \<in> space M. f x = y} *\<^sub>R norm y)"
6.226 -    by (simp add: measure_nonneg)
6.227 +    by simp
6.228    also have "\<dots> = simple_bochner_integral M (\<lambda>x. norm (f x))"
6.229      using f
6.230      by (intro simple_bochner_integral_partition[symmetric])
6.231 @@ -447,36 +439,41 @@
6.232    finally show ?thesis .
6.233  qed
6.234
6.235 +lemma simple_bochner_integral_nonneg[simp]:
6.236 +  fixes f :: "'a \<Rightarrow> real"
6.237 +  shows "(\<And>x. 0 \<le> f x) \<Longrightarrow> 0 \<le> simple_bochner_integral M f"
6.238 +  by (simp add: setsum_nonneg simple_bochner_integral_def)
6.239 +
6.240  lemma simple_bochner_integral_eq_nn_integral:
6.241    assumes f: "simple_bochner_integrable M f" "\<And>x. 0 \<le> f x"
6.242    shows "simple_bochner_integral M f = (\<integral>\<^sup>+x. f x \<partial>M)"
6.243  proof -
6.244 -  { fix x y z have "(x \<noteq> 0 \<Longrightarrow> y = z) \<Longrightarrow> ereal x * y = ereal x * z"
6.245 -      by (cases "x = 0") (auto simp: zero_ereal_def[symmetric]) }
6.246 -  note ereal_cong_mult = this
6.247 +  { fix x y z have "(x \<noteq> 0 \<Longrightarrow> y = z) \<Longrightarrow> ennreal x * y = ennreal x * z"
6.248 +      by (cases "x = 0") (auto simp: zero_ennreal_def[symmetric]) }
6.249 +  note ennreal_cong_mult = this
6.250
6.251    have [measurable]: "f \<in> borel_measurable M"
6.252      using f(1) by (auto intro: borel_measurable_simple_function elim: simple_bochner_integrable.cases)
6.253
6.254    { fix y assume y: "y \<in> space M" "f y \<noteq> 0"
6.255 -    have "ereal (measure M {x \<in> space M. f x = f y}) = emeasure M {x \<in> space M. f x = f y}"
6.256 -    proof (rule emeasure_eq_ereal_measure[symmetric])
6.257 +    have "ennreal (measure M {x \<in> space M. f x = f y}) = emeasure M {x \<in> space M. f x = f y}"
6.258 +    proof (rule emeasure_eq_ennreal_measure[symmetric])
6.259        have "emeasure M {x \<in> space M. f x = f y} \<le> emeasure M {x \<in> space M. f x \<noteq> 0}"
6.260          using y by (intro emeasure_mono) auto
6.261 -      with f show "emeasure M {x \<in> space M. f x = f y} \<noteq> \<infinity>"
6.262 -        by (auto simp: simple_bochner_integrable.simps)
6.263 +      with f show "emeasure M {x \<in> space M. f x = f y} \<noteq> top"
6.264 +        by (auto simp: simple_bochner_integrable.simps top_unique)
6.265      qed
6.266 -    moreover have "{x \<in> space M. f x = f y} = (\<lambda>x. ereal (f x)) -` {ereal (f y)} \<inter> space M"
6.267 -      by auto
6.268 -    ultimately have "ereal (measure M {x \<in> space M. f x = f y}) =
6.269 -          emeasure M ((\<lambda>x. ereal (f x)) -` {ereal (f y)} \<inter> space M)" by simp }
6.270 +    moreover have "{x \<in> space M. f x = f y} = (\<lambda>x. ennreal (f x)) -` {ennreal (f y)} \<inter> space M"
6.271 +      using f by auto
6.272 +    ultimately have "ennreal (measure M {x \<in> space M. f x = f y}) =
6.273 +          emeasure M ((\<lambda>x. ennreal (f x)) -` {ennreal (f y)} \<inter> space M)" by simp }
6.274    with f have "simple_bochner_integral M f = (\<integral>\<^sup>Sx. f x \<partial>M)"
6.275      unfolding simple_integral_def
6.276 -    by (subst simple_bochner_integral_partition[OF f(1), where g="\<lambda>x. ereal (f x)" and v=real_of_ereal])
6.277 +    by (subst simple_bochner_integral_partition[OF f(1), where g="\<lambda>x. ennreal (f x)" and v=enn2real])
6.278         (auto intro: f simple_function_compose1 elim: simple_bochner_integrable.cases
6.279 -             intro!: setsum.cong ereal_cong_mult
6.280 -             simp: setsum_ereal[symmetric] times_ereal.simps(1)[symmetric] ac_simps
6.281 -             simp del: setsum_ereal times_ereal.simps(1))
6.282 +             intro!: setsum.cong ennreal_cong_mult
6.283 +             simp: setsum_ennreal[symmetric] ac_simps ennreal_mult
6.284 +             simp del: setsum_ennreal)
6.285    also have "\<dots> = (\<integral>\<^sup>+x. f x \<partial>M)"
6.286      using f
6.287      by (intro nn_integral_eq_simple_integral[symmetric])
6.288 @@ -488,14 +485,14 @@
6.289    fixes f :: "'a \<Rightarrow> 'b::{real_normed_vector, second_countable_topology}"
6.290    assumes f[measurable]: "f \<in> borel_measurable M"
6.291    assumes s: "simple_bochner_integrable M s" and t: "simple_bochner_integrable M t"
6.292 -  shows "ereal (norm (simple_bochner_integral M s - simple_bochner_integral M t)) \<le>
6.293 +  shows "ennreal (norm (simple_bochner_integral M s - simple_bochner_integral M t)) \<le>
6.294      (\<integral>\<^sup>+ x. norm (f x - s x) \<partial>M) + (\<integral>\<^sup>+ x. norm (f x - t x) \<partial>M)"
6.295 -    (is "ereal (norm (?s - ?t)) \<le> ?S + ?T")
6.296 +    (is "ennreal (norm (?s - ?t)) \<le> ?S + ?T")
6.297  proof -
6.298    have [measurable]: "s \<in> borel_measurable M" "t \<in> borel_measurable M"
6.299      using s t by (auto intro: borel_measurable_simple_function elim: simple_bochner_integrable.cases)
6.300
6.301 -  have "ereal (norm (?s - ?t)) = norm (simple_bochner_integral M (\<lambda>x. s x - t x))"
6.302 +  have "ennreal (norm (?s - ?t)) = norm (simple_bochner_integral M (\<lambda>x. s x - t x))"
6.303      using s t by (subst simple_bochner_integral_diff) auto
6.304    also have "\<dots> \<le> simple_bochner_integral M (\<lambda>x. norm (s x - t x))"
6.305      using simple_bochner_integrable_compose2[of "op -" M "s" "t"] s t
6.306 @@ -503,8 +500,8 @@
6.307    also have "\<dots> = (\<integral>\<^sup>+x. norm (s x - t x) \<partial>M)"
6.308      using simple_bochner_integrable_compose2[of "\<lambda>x y. norm (x - y)" M "s" "t"] s t
6.309      by (auto intro!: simple_bochner_integral_eq_nn_integral)
6.310 -  also have "\<dots> \<le> (\<integral>\<^sup>+x. ereal (norm (f x - s x)) + ereal (norm (f x - t x)) \<partial>M)"
6.311 -    by (auto intro!: nn_integral_mono)
6.312 +  also have "\<dots> \<le> (\<integral>\<^sup>+x. ennreal (norm (f x - s x)) + ennreal (norm (f x - t x)) \<partial>M)"
6.313 +    by (auto intro!: nn_integral_mono simp: ennreal_plus[symmetric] simp del: ennreal_plus)
6.315                norm_minus_commute norm_triangle_ineq4 order_refl)
6.316    also have "\<dots> = ?S + ?T"
6.317 @@ -545,9 +542,9 @@
6.318  lemma has_bochner_integral_simple_bochner_integrable:
6.319    "simple_bochner_integrable M f \<Longrightarrow> has_bochner_integral M f (simple_bochner_integral M f)"
6.320    by (rule has_bochner_integral.intros[where s="\<lambda>_. f"])
6.321 -     (auto intro: borel_measurable_simple_function
6.322 +     (auto intro: borel_measurable_simple_function
6.323             elim: simple_bochner_integrable.cases
6.324 -           simp: zero_ereal_def[symmetric])
6.325 +           simp: zero_ennreal_def[symmetric])
6.326
6.327  lemma has_bochner_integral_real_indicator:
6.328    assumes [measurable]: "A \<in> sets M" and A: "emeasure M A < \<infinity>"
6.329 @@ -562,7 +559,7 @@
6.330    qed (rule simple_function_indicator assms)+
6.331    moreover have "simple_bochner_integral M (indicator A) = measure M A"
6.332      using simple_bochner_integral_eq_nn_integral[OF sbi] A
6.333 -    by (simp add: ereal_indicator emeasure_eq_ereal_measure)
6.334 +    by (simp add: ennreal_indicator emeasure_eq_ennreal_measure)
6.335    ultimately show ?thesis
6.336      by (metis has_bochner_integral_simple_bochner_integrable)
6.337  qed
6.338 @@ -588,18 +585,19 @@
6.339      (is "?f \<longlonglongrightarrow> 0")
6.340    proof (rule tendsto_sandwich)
6.341      show "eventually (\<lambda>n. 0 \<le> ?f n) sequentially" "(\<lambda>_. 0) \<longlonglongrightarrow> 0"
6.342 -      by (auto simp: nn_integral_nonneg)
6.343 +      by auto
6.344      show "eventually (\<lambda>i. ?f i \<le> (\<integral>\<^sup>+ x. (norm (f x - sf i x)) \<partial>M) + \<integral>\<^sup>+ x. (norm (g x - sg i x)) \<partial>M) sequentially"
6.345        (is "eventually (\<lambda>i. ?f i \<le> ?g i) sequentially")
6.346      proof (intro always_eventually allI)
6.347 -      fix i have "?f i \<le> (\<integral>\<^sup>+ x. (norm (f x - sf i x)) + ereal (norm (g x - sg i x)) \<partial>M)"
6.348 -        by (auto intro!: nn_integral_mono norm_diff_triangle_ineq)
6.349 +      fix i have "?f i \<le> (\<integral>\<^sup>+ x. (norm (f x - sf i x)) + ennreal (norm (g x - sg i x)) \<partial>M)"
6.350 +        by (auto intro!: nn_integral_mono norm_diff_triangle_ineq
6.351 +                 simp del: ennreal_plus simp add: ennreal_plus[symmetric])
6.352        also have "\<dots> = ?g i"
6.354        finally show "?f i \<le> ?g i" .
6.355      qed
6.356      show "?g \<longlonglongrightarrow> 0"
6.357 -      using tendsto_add_ereal[OF _ _ f_sf g_sg] by simp
6.358 +      using tendsto_add[OF f_sf g_sg] by simp
6.359    qed
6.361
6.362 @@ -629,19 +627,19 @@
6.363      (is "?f \<longlonglongrightarrow> 0")
6.364    proof (rule tendsto_sandwich)
6.365      show "eventually (\<lambda>n. 0 \<le> ?f n) sequentially" "(\<lambda>_. 0) \<longlonglongrightarrow> 0"
6.366 -      by (auto simp: nn_integral_nonneg)
6.367 +      by auto
6.368
6.369      show "eventually (\<lambda>i. ?f i \<le> K * (\<integral>\<^sup>+ x. norm (f x - s i x) \<partial>M)) sequentially"
6.370        (is "eventually (\<lambda>i. ?f i \<le> ?g i) sequentially")
6.371      proof (intro always_eventually allI)
6.372 -      fix i have "?f i \<le> (\<integral>\<^sup>+ x. ereal K * norm (f x - s i x) \<partial>M)"
6.373 -        using K by (intro nn_integral_mono) (auto simp: ac_simps)
6.374 +      fix i have "?f i \<le> (\<integral>\<^sup>+ x. ennreal K * norm (f x - s i x) \<partial>M)"
6.375 +        using K by (intro nn_integral_mono) (auto simp: ac_simps ennreal_mult[symmetric])
6.376        also have "\<dots> = ?g i"
6.377          using K by (intro nn_integral_cmult) auto
6.378        finally show "?f i \<le> ?g i" .
6.379      qed
6.380      show "?g \<longlonglongrightarrow> 0"
6.381 -      using tendsto_cmult_ereal[OF _ f_s, of "ereal K"] by simp
6.382 +      using ennreal_tendsto_cmult[OF _ f_s] by simp
6.383    qed
6.384
6.385    assume "(\<lambda>i. simple_bochner_integral M (s i)) \<longlonglongrightarrow> x"
6.386 @@ -651,7 +649,7 @@
6.387
6.388  lemma has_bochner_integral_zero[intro]: "has_bochner_integral M (\<lambda>x. 0) 0"
6.389    by (auto intro!: has_bochner_integral.intros[where s="\<lambda>_ _. 0"]
6.390 -           simp: zero_ereal_def[symmetric] simple_bochner_integrable.simps
6.391 +           simp: zero_ennreal_def[symmetric] simple_bochner_integrable.simps
6.392                   simple_bochner_integral_def image_constant_conv)
6.393
6.394  lemma has_bochner_integral_scaleR_left[intro]:
6.395 @@ -672,7 +670,7 @@
6.396    shows "(c \<noteq> 0 \<Longrightarrow> has_bochner_integral M f x) \<Longrightarrow> has_bochner_integral M (\<lambda>x. c * f x) (c * x)"
6.397    by (cases "c = 0") (auto simp add: has_bochner_integral_bounded_linear[OF bounded_linear_mult_right])
6.398
6.399 -lemmas has_bochner_integral_divide =
6.400 +lemmas has_bochner_integral_divide =
6.401    has_bochner_integral_bounded_linear[OF bounded_linear_divide]
6.402
6.403  lemma has_bochner_integral_divide_zero[intro]:
6.404 @@ -724,11 +722,10 @@
6.405  proof (elim has_bochner_integral.cases)
6.406    fix s v
6.407    assume [measurable]: "f \<in> borel_measurable M" and s: "\<And>i. simple_bochner_integrable M (s i)" and
6.408 -    lim_0: "(\<lambda>i. \<integral>\<^sup>+ x. ereal (norm (f x - s i x)) \<partial>M) \<longlonglongrightarrow> 0"
6.409 +    lim_0: "(\<lambda>i. \<integral>\<^sup>+ x. ennreal (norm (f x - s i x)) \<partial>M) \<longlonglongrightarrow> 0"
6.410    from order_tendstoD[OF lim_0, of "\<infinity>"]
6.411 -  obtain i where f_s_fin: "(\<integral>\<^sup>+ x. ereal (norm (f x - s i x)) \<partial>M) < \<infinity>"
6.412 -    by (metis (mono_tags, lifting) eventually_False_sequentially eventually_mono
6.413 -              less_ereal.simps(4) zero_ereal_def)
6.414 +  obtain i where f_s_fin: "(\<integral>\<^sup>+ x. ennreal (norm (f x - s i x)) \<partial>M) < \<infinity>"
6.415 +    by (auto simp: eventually_sequentially)
6.416
6.417    have [measurable]: "\<And>i. s i \<in> borel_measurable M"
6.418      using s by (auto intro: borel_measurable_simple_function elim: simple_bochner_integrable.cases)
6.419 @@ -740,19 +737,20 @@
6.420      by (rule finite_imageI)
6.421    then have "\<And>x. x \<in> space M \<Longrightarrow> norm (s i x) \<le> m" "0 \<le> m"
6.422      by (auto simp: m_def image_comp comp_def Max_ge_iff)
6.423 -  then have "(\<integral>\<^sup>+x. norm (s i x) \<partial>M) \<le> (\<integral>\<^sup>+x. ereal m * indicator {x\<in>space M. s i x \<noteq> 0} x \<partial>M)"
6.424 +  then have "(\<integral>\<^sup>+x. norm (s i x) \<partial>M) \<le> (\<integral>\<^sup>+x. ennreal m * indicator {x\<in>space M. s i x \<noteq> 0} x \<partial>M)"
6.425      by (auto split: split_indicator intro!: Max_ge nn_integral_mono simp:)
6.426    also have "\<dots> < \<infinity>"
6.427 -    using s by (subst nn_integral_cmult_indicator) (auto simp: \<open>0 \<le> m\<close> simple_bochner_integrable.simps)
6.428 +    using s by (subst nn_integral_cmult_indicator) (auto simp: \<open>0 \<le> m\<close> simple_bochner_integrable.simps ennreal_mult_less_top less_top)
6.429    finally have s_fin: "(\<integral>\<^sup>+x. norm (s i x) \<partial>M) < \<infinity>" .
6.430
6.431 -  have "(\<integral>\<^sup>+ x. norm (f x) \<partial>M) \<le> (\<integral>\<^sup>+ x. ereal (norm (f x - s i x)) + ereal (norm (s i x)) \<partial>M)"
6.432 -    by (auto intro!: nn_integral_mono) (metis add.commute norm_triangle_sub)
6.433 +  have "(\<integral>\<^sup>+ x. norm (f x) \<partial>M) \<le> (\<integral>\<^sup>+ x. ennreal (norm (f x - s i x)) + ennreal (norm (s i x)) \<partial>M)"
6.434 +    by (auto intro!: nn_integral_mono simp del: ennreal_plus simp add: ennreal_plus[symmetric])
6.436    also have "\<dots> = (\<integral>\<^sup>+x. norm (f x - s i x) \<partial>M) + (\<integral>\<^sup>+x. norm (s i x) \<partial>M)"
6.438    also have "\<dots> < \<infinity>"
6.439      using s_fin f_s_fin by auto
6.440 -  finally show "(\<integral>\<^sup>+ x. ereal (norm (f x)) \<partial>M) < \<infinity>" .
6.441 +  finally show "(\<integral>\<^sup>+ x. ennreal (norm (f x)) \<partial>M) < \<infinity>" .
6.442  qed
6.443
6.444  lemma has_bochner_integral_norm_bound:
6.445 @@ -762,7 +760,7 @@
6.446    fix s assume
6.447      x: "(\<lambda>i. simple_bochner_integral M (s i)) \<longlonglongrightarrow> x" (is "?s \<longlonglongrightarrow> x") and
6.448      s[simp]: "\<And>i. simple_bochner_integrable M (s i)" and
6.449 -    lim: "(\<lambda>i. \<integral>\<^sup>+ x. ereal (norm (f x - s i x)) \<partial>M) \<longlonglongrightarrow> 0" and
6.450 +    lim: "(\<lambda>i. \<integral>\<^sup>+ x. ennreal (norm (f x - s i x)) \<partial>M) \<longlonglongrightarrow> 0" and
6.451      f[measurable]: "f \<in> borel_measurable M"
6.452
6.453    have [measurable]: "\<And>i. s i \<in> borel_measurable M"
6.454 @@ -770,28 +768,28 @@
6.455
6.456    show "norm x \<le> (\<integral>\<^sup>+x. norm (f x) \<partial>M)"
6.457    proof (rule LIMSEQ_le)
6.458 -    show "(\<lambda>i. ereal (norm (?s i))) \<longlonglongrightarrow> norm x"
6.459 -      using x by (intro tendsto_intros lim_ereal[THEN iffD2])
6.460 +    show "(\<lambda>i. ennreal (norm (?s i))) \<longlonglongrightarrow> norm x"
6.461 +      using x by (auto simp: tendsto_ennreal_iff intro: tendsto_intros)
6.462      show "\<exists>N. \<forall>n\<ge>N. norm (?s n) \<le> (\<integral>\<^sup>+x. norm (f x - s n x) \<partial>M) + (\<integral>\<^sup>+x. norm (f x) \<partial>M)"
6.463        (is "\<exists>N. \<forall>n\<ge>N. _ \<le> ?t n")
6.464      proof (intro exI allI impI)
6.465        fix n
6.466 -      have "ereal (norm (?s n)) \<le> simple_bochner_integral M (\<lambda>x. norm (s n x))"
6.467 +      have "ennreal (norm (?s n)) \<le> simple_bochner_integral M (\<lambda>x. norm (s n x))"
6.468          by (auto intro!: simple_bochner_integral_norm_bound)
6.469        also have "\<dots> = (\<integral>\<^sup>+x. norm (s n x) \<partial>M)"
6.470          by (intro simple_bochner_integral_eq_nn_integral)
6.471             (auto intro: s simple_bochner_integrable_compose2)
6.472 -      also have "\<dots> \<le> (\<integral>\<^sup>+x. ereal (norm (f x - s n x)) + norm (f x) \<partial>M)"
6.473 -        by (auto intro!: nn_integral_mono)
6.474 +      also have "\<dots> \<le> (\<integral>\<^sup>+x. ennreal (norm (f x - s n x)) + norm (f x) \<partial>M)"
6.475 +        by (auto intro!: nn_integral_mono simp del: ennreal_plus simp add: ennreal_plus[symmetric])
6.477 -      also have "\<dots> = ?t n"
6.478 +      also have "\<dots> = ?t n"
6.480        finally show "norm (?s n) \<le> ?t n" .
6.481      qed
6.482 -    have "?t \<longlonglongrightarrow> 0 + (\<integral>\<^sup>+ x. ereal (norm (f x)) \<partial>M)"
6.483 +    have "?t \<longlonglongrightarrow> 0 + (\<integral>\<^sup>+ x. ennreal (norm (f x)) \<partial>M)"
6.484        using has_bochner_integral_implies_finite_norm[OF i]
6.485 -      by (intro tendsto_add_ereal tendsto_const lim) auto
6.486 -    then show "?t \<longlonglongrightarrow> \<integral>\<^sup>+ x. ereal (norm (f x)) \<partial>M"
6.487 +      by (intro tendsto_add tendsto_const lim)
6.488 +    then show "?t \<longlonglongrightarrow> \<integral>\<^sup>+ x. ennreal (norm (f x)) \<partial>M"
6.489        by simp
6.490    qed
6.491  qed
6.492 @@ -816,19 +814,18 @@
6.493    then have "(\<lambda>i. norm (?s i - ?t i)) \<longlonglongrightarrow> norm (x - y)"
6.494      by (intro tendsto_intros)
6.495    moreover
6.496 -  have "(\<lambda>i. ereal (norm (?s i - ?t i))) \<longlonglongrightarrow> ereal 0"
6.497 +  have "(\<lambda>i. ennreal (norm (?s i - ?t i))) \<longlonglongrightarrow> ennreal 0"
6.498    proof (rule tendsto_sandwich)
6.499 -    show "eventually (\<lambda>i. 0 \<le> ereal (norm (?s i - ?t i))) sequentially" "(\<lambda>_. 0) \<longlonglongrightarrow> ereal 0"
6.500 -      by (auto simp: nn_integral_nonneg zero_ereal_def[symmetric])
6.501 +    show "eventually (\<lambda>i. 0 \<le> ennreal (norm (?s i - ?t i))) sequentially" "(\<lambda>_. 0) \<longlonglongrightarrow> ennreal 0"
6.502 +      by auto
6.503
6.504      show "eventually (\<lambda>i. norm (?s i - ?t i) \<le> ?S i + ?T i) sequentially"
6.505        by (intro always_eventually allI simple_bochner_integral_bounded s t f)
6.506 -    show "(\<lambda>i. ?S i + ?T i) \<longlonglongrightarrow> ereal 0"
6.507 -      using tendsto_add_ereal[OF _ _ \<open>?S \<longlonglongrightarrow> 0\<close> \<open>?T \<longlonglongrightarrow> 0\<close>]
6.508 -      by (simp add: zero_ereal_def[symmetric])
6.509 +    show "(\<lambda>i. ?S i + ?T i) \<longlonglongrightarrow> ennreal 0"
6.510 +      using tendsto_add[OF \<open>?S \<longlonglongrightarrow> 0\<close> \<open>?T \<longlonglongrightarrow> 0\<close>] by simp
6.511    qed
6.512    then have "(\<lambda>i. norm (?s i - ?t i)) \<longlonglongrightarrow> 0"
6.513 -    by simp
6.514 +    by (simp add: ennreal_0[symmetric] del: ennreal_0)
6.515    ultimately have "norm (x - y) = 0"
6.516      by (rule LIMSEQ_unique)
6.517    then show "x = y" by simp
6.518 @@ -841,11 +838,11 @@
6.519    shows "has_bochner_integral M g x"
6.520    using f
6.521  proof (safe intro!: has_bochner_integral.intros elim!: has_bochner_integral.cases)
6.522 -  fix s assume "(\<lambda>i. \<integral>\<^sup>+ x. ereal (norm (f x - s i x)) \<partial>M) \<longlonglongrightarrow> 0"
6.523 -  also have "(\<lambda>i. \<integral>\<^sup>+ x. ereal (norm (f x - s i x)) \<partial>M) = (\<lambda>i. \<integral>\<^sup>+ x. ereal (norm (g x - s i x)) \<partial>M)"
6.524 +  fix s assume "(\<lambda>i. \<integral>\<^sup>+ x. ennreal (norm (f x - s i x)) \<partial>M) \<longlonglongrightarrow> 0"
6.525 +  also have "(\<lambda>i. \<integral>\<^sup>+ x. ennreal (norm (f x - s i x)) \<partial>M) = (\<lambda>i. \<integral>\<^sup>+ x. ennreal (norm (g x - s i x)) \<partial>M)"
6.526      using ae
6.527      by (intro ext nn_integral_cong_AE, eventually_elim) simp
6.528 -  finally show "(\<lambda>i. \<integral>\<^sup>+ x. ereal (norm (g x - s i x)) \<partial>M) \<longlonglongrightarrow> 0" .
6.529 +  finally show "(\<lambda>i. \<integral>\<^sup>+ x. ennreal (norm (g x - s i x)) \<partial>M) \<longlonglongrightarrow> 0" .
6.530  qed (auto intro: g)
6.531
6.532  lemma has_bochner_integral_eq_AE:
6.533 @@ -966,14 +963,14 @@
6.534    by (auto simp: integrable.simps)
6.535
6.536  lemma integrable_zero[simp, intro]: "integrable M (\<lambda>x. 0)"
6.537 -  by (metis has_bochner_integral_zero integrable.simps)
6.538 +  by (metis has_bochner_integral_zero integrable.simps)
6.539
6.540  lemma integrable_setsum[simp, intro]: "(\<And>i. i \<in> I \<Longrightarrow> integrable M (f i)) \<Longrightarrow> integrable M (\<lambda>x. \<Sum>i\<in>I. f i x)"
6.541 -  by (metis has_bochner_integral_setsum integrable.simps)
6.542 +  by (metis has_bochner_integral_setsum integrable.simps)
6.543
6.544  lemma integrable_indicator[simp, intro]: "A \<in> sets M \<Longrightarrow> emeasure M A < \<infinity> \<Longrightarrow>
6.545    integrable M (\<lambda>x. indicator A x *\<^sub>R c)"
6.546 -  by (metis has_bochner_integral_indicator integrable.simps)
6.547 +  by (metis has_bochner_integral_indicator integrable.simps)
6.548
6.549  lemma integrable_real_indicator[simp, intro]: "A \<in> sets M \<Longrightarrow> emeasure M A < \<infinity> \<Longrightarrow>
6.550    integrable M (indicator A :: 'a \<Rightarrow> real)"
6.551 @@ -981,7 +978,7 @@
6.552
6.553  lemma integrable_diff[simp, intro]: "integrable M f \<Longrightarrow> integrable M g \<Longrightarrow> integrable M (\<lambda>x. f x - g x)"
6.554    by (auto simp: integrable.simps intro: has_bochner_integral_diff)
6.555 -
6.556 +
6.557  lemma integrable_bounded_linear: "bounded_linear T \<Longrightarrow> integrable M f \<Longrightarrow> integrable M (\<lambda>x. T (f x))"
6.558    by (auto simp: integrable.simps intro: has_bochner_integral_bounded_linear)
6.559
6.560 @@ -1140,7 +1137,7 @@
6.561  lemmas integral_snd[simp] =
6.562    integral_bounded_linear[OF bounded_linear_snd]
6.563
6.564 -lemma integral_norm_bound_ereal:
6.565 +lemma integral_norm_bound_ennreal:
6.566    "integrable M f \<Longrightarrow> norm (integral\<^sup>L M f) \<le> (\<integral>\<^sup>+x. norm (f x) \<partial>M)"
6.567    by (metis has_bochner_integral_integrable has_bochner_integral_norm_bound)
6.568
6.569 @@ -1157,7 +1154,7 @@
6.570      unfolding convergent_eq_cauchy
6.571    proof (rule metric_CauchyI)
6.572      fix e :: real assume "0 < e"
6.573 -    then have "0 < ereal (e / 2)" by auto
6.574 +    then have "0 < ennreal (e / 2)" by auto
6.575      from order_tendstoD(2)[OF lim this]
6.576      obtain M where M: "\<And>n. M \<le> n \<Longrightarrow> ?S n < e / 2"
6.577        by (auto simp: eventually_sequentially)
6.578 @@ -1168,12 +1165,11 @@
6.579          using M[OF n] by auto
6.580        have "norm (?s n - ?s m) \<le> ?S n + ?S m"
6.581          by (intro simple_bochner_integral_bounded s f)
6.582 -      also have "\<dots> < ereal (e / 2) + e / 2"
6.583 -        using ereal_add_strict_mono[OF less_imp_le[OF M[OF n]] _ \<open>?S n \<noteq> \<infinity>\<close> M[OF m]]
6.584 -        by (auto simp: nn_integral_nonneg)
6.585 -      also have "\<dots> = e" by simp
6.586 +      also have "\<dots> < ennreal (e / 2) + e / 2"
6.587 +        by (intro add_strict_mono M n m)
6.588 +      also have "\<dots> = e" using \<open>0<e\<close> by (simp del: ennreal_plus add: ennreal_plus[symmetric])
6.589        finally show "dist (?s n) (?s m) < e"
6.590 -        by (simp add: dist_norm)
6.591 +        using \<open>0<e\<close> by (simp add: dist_norm ennreal_less_iff)
6.592      qed
6.593    qed
6.594    then obtain x where "?s \<longlonglongrightarrow> x" ..
6.595 @@ -1203,20 +1199,22 @@
6.596        by (rule norm_triangle_ineq4)
6.597      finally (xtrans) show "norm (u' x - u i x) \<le> 2 * w x" .
6.598    qed
6.599 -
6.600 +  have w_nonneg: "AE x in M. 0 \<le> w x"
6.601 +    using bound[of 0] by (auto intro: order_trans[OF norm_ge_zero])
6.602 +
6.603    have "(\<lambda>i. (\<integral>\<^sup>+x. norm (u' x - u i x) \<partial>M)) \<longlonglongrightarrow> (\<integral>\<^sup>+x. 0 \<partial>M)"
6.604 -  proof (rule nn_integral_dominated_convergence)
6.605 +  proof (rule nn_integral_dominated_convergence)
6.606      show "(\<integral>\<^sup>+x. 2 * w x \<partial>M) < \<infinity>"
6.607 -      by (rule nn_integral_mult_bounded_inf[OF _ w, of 2]) auto
6.608 -    show "AE x in M. (\<lambda>i. ereal (norm (u' x - u i x))) \<longlonglongrightarrow> 0"
6.609 -      using u'
6.610 +      by (rule nn_integral_mult_bounded_inf[OF _ w, of 2]) (insert w_nonneg, auto simp: ennreal_mult )
6.611 +    show "AE x in M. (\<lambda>i. ennreal (norm (u' x - u i x))) \<longlonglongrightarrow> 0"
6.612 +      using u'
6.613      proof eventually_elim
6.614        fix x assume "(\<lambda>i. u i x) \<longlonglongrightarrow> u' x"
6.615        from tendsto_diff[OF tendsto_const[of "u' x"] this]
6.616 -      show "(\<lambda>i. ereal (norm (u' x - u i x))) \<longlonglongrightarrow> 0"
6.617 -        by (simp add: zero_ereal_def tendsto_norm_zero_iff)
6.618 +      show "(\<lambda>i. ennreal (norm (u' x - u i x))) \<longlonglongrightarrow> 0"
6.619 +        by (simp add: tendsto_norm_zero_iff ennreal_0[symmetric] del: ennreal_0)
6.620      qed
6.621 -  qed (insert bnd, auto)
6.622 +  qed (insert bnd w_nonneg, auto)
6.623    then show ?thesis by simp
6.624  qed
6.625
6.626 @@ -1230,29 +1228,31 @@
6.627      pointwise: "\<And>x. x \<in> space M \<Longrightarrow> (\<lambda>i. s i x) \<longlonglongrightarrow> f x" and
6.628      bound: "\<And>i x. x \<in> space M \<Longrightarrow> norm (s i x) \<le> 2 * norm (f x)"
6.629      by simp metis
6.630 -
6.631 +
6.632    show ?thesis
6.633    proof (rule integrableI_sequence)
6.634      { fix i
6.635 -      have "(\<integral>\<^sup>+x. norm (s i x) \<partial>M) \<le> (\<integral>\<^sup>+x. 2 * ereal (norm (f x)) \<partial>M)"
6.636 +      have "(\<integral>\<^sup>+x. norm (s i x) \<partial>M) \<le> (\<integral>\<^sup>+x. ennreal (2 * norm (f x)) \<partial>M)"
6.637          by (intro nn_integral_mono) (simp add: bound)
6.638 -      also have "\<dots> = 2 * (\<integral>\<^sup>+x. ereal (norm (f x)) \<partial>M)"
6.639 -        by (rule nn_integral_cmult) auto
6.640 +      also have "\<dots> = 2 * (\<integral>\<^sup>+x. ennreal (norm (f x)) \<partial>M)"
6.641 +        by (simp add: ennreal_mult nn_integral_cmult)
6.642 +      also have "\<dots> < top"
6.643 +        using fin by (simp add: ennreal_mult_less_top)
6.644        finally have "(\<integral>\<^sup>+x. norm (s i x) \<partial>M) < \<infinity>"
6.645 -        using fin by auto }
6.646 +        by simp }
6.647      note fin_s = this
6.648
6.649      show "\<And>i. simple_bochner_integrable M (s i)"
6.650        by (rule simple_bochner_integrableI_bounded) fact+
6.651
6.652 -    show "(\<lambda>i. \<integral>\<^sup>+ x. ereal (norm (f x - s i x)) \<partial>M) \<longlonglongrightarrow> 0"
6.653 +    show "(\<lambda>i. \<integral>\<^sup>+ x. ennreal (norm (f x - s i x)) \<partial>M) \<longlonglongrightarrow> 0"
6.654      proof (rule nn_integral_dominated_convergence_norm)
6.655        show "\<And>j. AE x in M. norm (s j x) \<le> 2 * norm (f x)"
6.656          using bound by auto
6.657        show "\<And>i. s i \<in> borel_measurable M" "(\<lambda>x. 2 * norm (f x)) \<in> borel_measurable M"
6.658          using s by (auto intro: borel_measurable_simple_function)
6.659 -      show "(\<integral>\<^sup>+ x. ereal (2 * norm (f x)) \<partial>M) < \<infinity>"
6.660 -        using fin unfolding times_ereal.simps(1)[symmetric] by (subst nn_integral_cmult) auto
6.661 +      show "(\<integral>\<^sup>+ x. ennreal (2 * norm (f x)) \<partial>M) < \<infinity>"
6.662 +        using fin by (simp add: nn_integral_cmult ennreal_mult ennreal_mult_less_top)
6.663        show "AE x in M. (\<lambda>i. s i x) \<longlonglongrightarrow> f x"
6.664          using pointwise by auto
6.665      qed fact
6.666 @@ -1269,11 +1269,11 @@
6.667  proof (rule integrableI_bounded)
6.668    { fix x :: 'b have "norm x \<le> B \<Longrightarrow> 0 \<le> B"
6.669        using norm_ge_zero[of x] by arith }
6.670 -  with bnd null have "(\<integral>\<^sup>+ x. ereal (norm (f x)) \<partial>M) \<le> (\<integral>\<^sup>+ x. ereal (max 0 B) * indicator A x \<partial>M)"
6.671 +  with bnd null have "(\<integral>\<^sup>+ x. ennreal (norm (f x)) \<partial>M) \<le> (\<integral>\<^sup>+ x. ennreal (max 0 B) * indicator A x \<partial>M)"
6.672      by (intro nn_integral_mono_AE) (auto split: split_indicator split_max)
6.673    also have "\<dots> < \<infinity>"
6.674 -    using finite by (subst nn_integral_cmult_indicator) (auto simp: max_def)
6.675 -  finally show "(\<integral>\<^sup>+ x. ereal (norm (f x)) \<partial>M) < \<infinity>" .
6.676 +    using finite by (subst nn_integral_cmult_indicator) (auto simp: ennreal_mult_less_top)
6.677 +  finally show "(\<integral>\<^sup>+ x. ennreal (norm (f x)) \<partial>M) < \<infinity>" .
6.678  qed simp
6.679
6.680  lemma integrableI_bounded_set_indicator:
6.681 @@ -1309,11 +1309,11 @@
6.682  proof safe
6.683    assume "f \<in> borel_measurable M" "g \<in> borel_measurable M"
6.684    assume "AE x in M. norm (g x) \<le> norm (f x)"
6.685 -  then have "(\<integral>\<^sup>+ x. ereal (norm (g x)) \<partial>M) \<le> (\<integral>\<^sup>+ x. ereal (norm (f x)) \<partial>M)"
6.686 +  then have "(\<integral>\<^sup>+ x. ennreal (norm (g x)) \<partial>M) \<le> (\<integral>\<^sup>+ x. ennreal (norm (f x)) \<partial>M)"
6.687      by  (intro nn_integral_mono_AE) auto
6.688 -  also assume "(\<integral>\<^sup>+ x. ereal (norm (f x)) \<partial>M) < \<infinity>"
6.689 -  finally show "(\<integral>\<^sup>+ x. ereal (norm (g x)) \<partial>M) < \<infinity>" .
6.690 -qed
6.691 +  also assume "(\<integral>\<^sup>+ x. ennreal (norm (f x)) \<partial>M) < \<infinity>"
6.692 +  finally show "(\<integral>\<^sup>+ x. ennreal (norm (g x)) \<partial>M) < \<infinity>" .
6.693 +qed
6.694
6.695  lemma integrable_mult_indicator:
6.696    fixes f :: "'a \<Rightarrow> 'b::{banach, second_countable_topology}"
6.697 @@ -1334,7 +1334,7 @@
6.698    fixes f :: "'a \<Rightarrow> 'b::{banach, second_countable_topology}"
6.699    assumes [measurable]: "integrable M f" shows "integrable M (\<lambda>x. norm (f x))"
6.700    using assms by (rule integrable_bound) auto
6.701 -
6.702 +
6.703  lemma integrable_norm_cancel:
6.704    fixes f :: "'a \<Rightarrow> 'b::{banach, second_countable_topology}"
6.705    assumes [measurable]: "integrable M (\<lambda>x. norm (f x))" "f \<in> borel_measurable M" shows "integrable M f"
6.706 @@ -1376,7 +1376,7 @@
6.707
6.708  lemma integrable_indicator_iff:
6.709    "integrable M (indicator A::_ \<Rightarrow> real) \<longleftrightarrow> A \<inter> space M \<in> sets M \<and> emeasure M (A \<inter> space M) < \<infinity>"
6.710 -  by (simp add: integrable_iff_bounded borel_measurable_indicator_iff ereal_indicator nn_integral_indicator'
6.711 +  by (simp add: integrable_iff_bounded borel_measurable_indicator_iff ennreal_indicator nn_integral_indicator'
6.712             cong: conj_cong)
6.713
6.714  lemma integral_indicator[simp]: "integral\<^sup>L M (indicator A) = measure M (A \<inter> space M)"
6.715 @@ -1394,14 +1394,14 @@
6.716    also have "\<dots> = 0"
6.717      using * by (subst not_integrable_integral_eq) (auto simp: integrable_indicator_iff)
6.718    also have "\<dots> = measure M (A \<inter> space M)"
6.719 -    using * by (auto simp: measure_def emeasure_notin_sets)
6.720 +    using * by (auto simp: measure_def emeasure_notin_sets not_less top_unique)
6.721    finally show ?thesis .
6.722  qed
6.723
6.724  lemma integrable_discrete_difference:
6.725    fixes f :: "'a \<Rightarrow> 'b::{banach, second_countable_topology}"
6.726    assumes X: "countable X"
6.727 -  assumes null: "\<And>x. x \<in> X \<Longrightarrow> emeasure M {x} = 0"
6.728 +  assumes null: "\<And>x. x \<in> X \<Longrightarrow> emeasure M {x} = 0"
6.729    assumes sets: "\<And>x. x \<in> X \<Longrightarrow> {x} \<in> sets M"
6.730    assumes eq: "\<And>x. x \<in> space M \<Longrightarrow> x \<notin> X \<Longrightarrow> f x = g x"
6.731    shows "integrable M f \<longleftrightarrow> integrable M g"
6.732 @@ -1425,7 +1425,7 @@
6.733  lemma integral_discrete_difference:
6.734    fixes f :: "'a \<Rightarrow> 'b::{banach, second_countable_topology}"
6.735    assumes X: "countable X"
6.736 -  assumes null: "\<And>x. x \<in> X \<Longrightarrow> emeasure M {x} = 0"
6.737 +  assumes null: "\<And>x. x \<in> X \<Longrightarrow> emeasure M {x} = 0"
6.738    assumes sets: "\<And>x. x \<in> X \<Longrightarrow> {x} \<in> sets M"
6.739    assumes eq: "\<And>x. x \<in> space M \<Longrightarrow> x \<notin> X \<Longrightarrow> f x = g x"
6.740    shows "integral\<^sup>L M f = integral\<^sup>L M g"
6.741 @@ -1449,7 +1449,7 @@
6.742  lemma has_bochner_integral_discrete_difference:
6.743    fixes f :: "'a \<Rightarrow> 'b::{banach, second_countable_topology}"
6.744    assumes X: "countable X"
6.745 -  assumes null: "\<And>x. x \<in> X \<Longrightarrow> emeasure M {x} = 0"
6.746 +  assumes null: "\<And>x. x \<in> X \<Longrightarrow> emeasure M {x} = 0"
6.747    assumes sets: "\<And>x. x \<in> X \<Longrightarrow> {x} \<in> sets M"
6.748    assumes eq: "\<And>x. x \<in> space M \<Longrightarrow> x \<notin> X \<Longrightarrow> f x = g x"
6.749    shows "has_bochner_integral M f x \<longleftrightarrow> has_bochner_integral M g x"
6.750 @@ -1466,7 +1466,7 @@
6.751      and integrable_dominated_convergence2: "\<And>i. integrable M (s i)"
6.752      and integral_dominated_convergence: "(\<lambda>i. integral\<^sup>L M (s i)) \<longlonglongrightarrow> integral\<^sup>L M f"
6.753  proof -
6.754 -  have "AE x in M. 0 \<le> w x"
6.755 +  have w_nonneg: "AE x in M. 0 \<le> w x"
6.756      using bound[of 0] by eventually_elim (auto intro: norm_ge_zero order_trans)
6.757    then have "(\<integral>\<^sup>+x. w x \<partial>M) = (\<integral>\<^sup>+x. norm (w x) \<partial>M)"
6.758      by (intro nn_integral_cong_AE) auto
6.759 @@ -1476,10 +1476,10 @@
6.760    show int_s: "\<And>i. integrable M (s i)"
6.761      unfolding integrable_iff_bounded
6.762    proof
6.763 -    fix i
6.764 -    have "(\<integral>\<^sup>+ x. ereal (norm (s i x)) \<partial>M) \<le> (\<integral>\<^sup>+x. w x \<partial>M)"
6.765 -      using bound by (intro nn_integral_mono_AE) auto
6.766 -    with w show "(\<integral>\<^sup>+ x. ereal (norm (s i x)) \<partial>M) < \<infinity>" by auto
6.767 +    fix i
6.768 +    have "(\<integral>\<^sup>+ x. ennreal (norm (s i x)) \<partial>M) \<le> (\<integral>\<^sup>+x. w x \<partial>M)"
6.769 +      using bound[of i] w_nonneg by (intro nn_integral_mono_AE) auto
6.770 +    with w show "(\<integral>\<^sup>+ x. ennreal (norm (s i x)) \<partial>M) < \<infinity>" by auto
6.771    qed fact
6.772
6.773    have all_bound: "AE x in M. \<forall>i. norm (s i x) \<le> w x"
6.774 @@ -1488,30 +1488,30 @@
6.775    show int_f: "integrable M f"
6.776      unfolding integrable_iff_bounded
6.777    proof
6.778 -    have "(\<integral>\<^sup>+ x. ereal (norm (f x)) \<partial>M) \<le> (\<integral>\<^sup>+x. w x \<partial>M)"
6.779 -      using all_bound lim
6.780 +    have "(\<integral>\<^sup>+ x. ennreal (norm (f x)) \<partial>M) \<le> (\<integral>\<^sup>+x. w x \<partial>M)"
6.781 +      using all_bound lim w_nonneg
6.782      proof (intro nn_integral_mono_AE, eventually_elim)
6.783 -      fix x assume "\<forall>i. norm (s i x) \<le> w x" "(\<lambda>i. s i x) \<longlonglongrightarrow> f x"
6.784 -      then show "ereal (norm (f x)) \<le> ereal (w x)"
6.785 -        by (intro LIMSEQ_le_const2[where X="\<lambda>i. ereal (norm (s i x))"] tendsto_intros lim_ereal[THEN iffD2]) auto
6.786 +      fix x assume "\<forall>i. norm (s i x) \<le> w x" "(\<lambda>i. s i x) \<longlonglongrightarrow> f x" "0 \<le> w x"
6.787 +      then show "ennreal (norm (f x)) \<le> ennreal (w x)"
6.788 +        by (intro LIMSEQ_le_const2[where X="\<lambda>i. ennreal (norm (s i x))"]) (auto intro: tendsto_intros)
6.789      qed
6.790 -    with w show "(\<integral>\<^sup>+ x. ereal (norm (f x)) \<partial>M) < \<infinity>" by auto
6.791 +    with w show "(\<integral>\<^sup>+ x. ennreal (norm (f x)) \<partial>M) < \<infinity>" by auto
6.792    qed fact
6.793
6.794 -  have "(\<lambda>n. ereal (norm (integral\<^sup>L M (s n) - integral\<^sup>L M f))) \<longlonglongrightarrow> ereal 0" (is "?d \<longlonglongrightarrow> ereal 0")
6.795 +  have "(\<lambda>n. ennreal (norm (integral\<^sup>L M (s n) - integral\<^sup>L M f))) \<longlonglongrightarrow> ennreal 0" (is "?d \<longlonglongrightarrow> ennreal 0")
6.796    proof (rule tendsto_sandwich)
6.797 -    show "eventually (\<lambda>n. ereal 0 \<le> ?d n) sequentially" "(\<lambda>_. ereal 0) \<longlonglongrightarrow> ereal 0" by auto
6.798 +    show "eventually (\<lambda>n. ennreal 0 \<le> ?d n) sequentially" "(\<lambda>_. ennreal 0) \<longlonglongrightarrow> ennreal 0" by auto
6.799      show "eventually (\<lambda>n. ?d n \<le> (\<integral>\<^sup>+x. norm (s n x - f x) \<partial>M)) sequentially"
6.800      proof (intro always_eventually allI)
6.801        fix n
6.802        have "?d n = norm (integral\<^sup>L M (\<lambda>x. s n x - f x))"
6.803          using int_f int_s by simp
6.804        also have "\<dots> \<le> (\<integral>\<^sup>+x. norm (s n x - f x) \<partial>M)"
6.805 -        by (intro int_f int_s integrable_diff integral_norm_bound_ereal)
6.806 +        by (intro int_f int_s integrable_diff integral_norm_bound_ennreal)
6.807        finally show "?d n \<le> (\<integral>\<^sup>+x. norm (s n x - f x) \<partial>M)" .
6.808      qed
6.809 -    show "(\<lambda>n. \<integral>\<^sup>+x. norm (s n x - f x) \<partial>M) \<longlonglongrightarrow> ereal 0"
6.810 -      unfolding zero_ereal_def[symmetric]
6.811 +    show "(\<lambda>n. \<integral>\<^sup>+x. norm (s n x - f x) \<partial>M) \<longlonglongrightarrow> ennreal 0"
6.812 +      unfolding ennreal_0
6.813        apply (subst norm_minus_commute)
6.814      proof (rule nn_integral_dominated_convergence_norm[where w=w])
6.815        show "\<And>n. s n \<in> borel_measurable M"
6.816 @@ -1519,7 +1519,7 @@
6.817      qed fact+
6.818    qed
6.819    then have "(\<lambda>n. integral\<^sup>L M (s n) - integral\<^sup>L M f) \<longlonglongrightarrow> 0"
6.820 -    unfolding lim_ereal tendsto_norm_zero_iff .
6.821 +    by (simp add: tendsto_norm_zero_iff del: ennreal_0)
6.822    from tendsto_add[OF this tendsto_const[of "integral\<^sup>L M f"]]
6.823    show "(\<lambda>i. integral\<^sup>L M (s i)) \<longlonglongrightarrow> integral\<^sup>L M f"  by simp
6.824  qed
6.825 @@ -1580,59 +1580,101 @@
6.826    using integrable_mult_left[of c M f] integrable_mult_left[of "1 / c" M "\<lambda>x. c * f x"]
6.827    by (cases "c = 0") auto
6.828
6.829 +lemma integrableI_nn_integral_finite:
6.830 +  assumes [measurable]: "f \<in> borel_measurable M"
6.831 +    and nonneg: "AE x in M. 0 \<le> f x"
6.832 +    and finite: "(\<integral>\<^sup>+x. f x \<partial>M) = ennreal x"
6.833 +  shows "integrable M f"
6.834 +proof (rule integrableI_bounded)
6.835 +  have "(\<integral>\<^sup>+ x. ennreal (norm (f x)) \<partial>M) = (\<integral>\<^sup>+ x. ennreal (f x) \<partial>M)"
6.836 +    using nonneg by (intro nn_integral_cong_AE) auto
6.837 +  with finite show "(\<integral>\<^sup>+ x. ennreal (norm (f x)) \<partial>M) < \<infinity>"
6.838 +    by auto
6.839 +qed simp
6.840 +
6.841 +lemma integral_nonneg_AE:
6.842 +  fixes f :: "'a \<Rightarrow> real"
6.843 +  assumes nonneg: "AE x in M. 0 \<le> f x"
6.844 +  shows "0 \<le> integral\<^sup>L M f"
6.845 +proof cases
6.846 +  assume f: "integrable M f"
6.847 +  then have [measurable]: "f \<in> M \<rightarrow>\<^sub>M borel"
6.848 +    by auto
6.849 +  have "(\<lambda>x. max 0 (f x)) \<in> M \<rightarrow>\<^sub>M borel" "\<And>x. 0 \<le> max 0 (f x)" "integrable M (\<lambda>x. max 0 (f x))"
6.850 +    using f by auto
6.851 +  from this have "0 \<le> integral\<^sup>L M (\<lambda>x. max 0 (f x))"
6.852 +  proof (induction rule: borel_measurable_induct_real)
6.853 +    case (add f g)
6.854 +    then have "integrable M f" "integrable M g"
6.855 +      by (auto intro!: integrable_bound[OF add.prems])
6.856 +    with add show ?case
6.858 +  next
6.859 +    case (seq U)
6.860 +    show ?case
6.861 +    proof (rule LIMSEQ_le_const)
6.862 +      have U_le: "x \<in> space M \<Longrightarrow> U i x \<le> max 0 (f x)" for x i
6.863 +        using seq by (intro incseq_le) (auto simp: incseq_def le_fun_def)
6.864 +      with seq nonneg show "(\<lambda>i. integral\<^sup>L M (U i)) \<longlonglongrightarrow> LINT x|M. max 0 (f x)"
6.865 +        by (intro integral_dominated_convergence) auto
6.866 +      have "integrable M (U i)" for i
6.867 +        using seq.prems by (rule integrable_bound) (insert U_le seq, auto)
6.868 +      with seq show "\<exists>N. \<forall>n\<ge>N. 0 \<le> integral\<^sup>L M (U n)"
6.869 +        by auto
6.870 +    qed
6.871 +  qed (auto simp: measure_nonneg integrable_mult_left_iff)
6.872 +  also have "\<dots> = integral\<^sup>L M f"
6.873 +    using nonneg by (auto intro!: integral_cong_AE)
6.874 +  finally show ?thesis .
6.876 +
6.877 +lemma integral_nonneg[simp]:
6.878 +  fixes f :: "'a \<Rightarrow> real"
6.879 +  shows "(\<And>x. x \<in> space M \<Longrightarrow> 0 \<le> f x) \<Longrightarrow> 0 \<le> integral\<^sup>L M f"
6.880 +  by (intro integral_nonneg_AE) auto
6.881 +
6.882  lemma nn_integral_eq_integral:
6.883    assumes f: "integrable M f"
6.884 -  assumes nonneg: "AE x in M. 0 \<le> f x"
6.885 +  assumes nonneg: "AE x in M. 0 \<le> f x"
6.886    shows "(\<integral>\<^sup>+ x. f x \<partial>M) = integral\<^sup>L M f"
6.887  proof -
6.888    { fix f :: "'a \<Rightarrow> real" assume f: "f \<in> borel_measurable M" "\<And>x. 0 \<le> f x" "integrable M f"
6.889      then have "(\<integral>\<^sup>+ x. f x \<partial>M) = integral\<^sup>L M f"
6.890      proof (induct rule: borel_measurable_induct_real)
6.891        case (set A) then show ?case
6.892 -        by (simp add: integrable_indicator_iff ereal_indicator emeasure_eq_ereal_measure)
6.893 +        by (simp add: integrable_indicator_iff ennreal_indicator emeasure_eq_ennreal_measure)
6.894      next
6.895        case (mult f c) then show ?case
6.896 -        unfolding times_ereal.simps(1)[symmetric]
6.897 -        by (subst nn_integral_cmult)
6.898 -           (auto simp add: integrable_mult_left_iff zero_ereal_def[symmetric])
6.899 +        by (auto simp add: integrable_mult_left_iff nn_integral_cmult ennreal_mult integral_nonneg_AE)
6.900      next
6.902        then have "integrable M f" "integrable M g"
6.903 -        by (auto intro!: integrable_bound[OF add(8)])
6.904 +        by (auto intro!: integrable_bound[OF add.prems])
6.906 -        unfolding plus_ereal.simps(1)[symmetric]
6.907 -        by (subst nn_integral_add) auto
6.909      next
6.910 -      case (seq s)
6.911 -      { fix i x assume "x \<in> space M" with seq(4) have "s i x \<le> f x"
6.912 -          by (intro LIMSEQ_le_const[OF seq(5)] exI[of _ i]) (auto simp: incseq_def le_fun_def) }
6.913 -      note s_le_f = this
6.914 -
6.915 +      case (seq U)
6.916        show ?case
6.917        proof (rule LIMSEQ_unique)
6.918 -        show "(\<lambda>i. ereal (integral\<^sup>L M (s i))) \<longlonglongrightarrow> ereal (integral\<^sup>L M f)"
6.919 -          unfolding lim_ereal
6.920 -        proof (rule integral_dominated_convergence[where w=f])
6.921 -          show "integrable M f" by fact
6.922 -          from s_le_f seq show "\<And>i. AE x in M. norm (s i x) \<le> f x"
6.923 -            by auto
6.924 -        qed (insert seq, auto)
6.925 -        have int_s: "\<And>i. integrable M (s i)"
6.926 -          using seq f s_le_f by (intro integrable_bound[OF f(3)]) auto
6.927 -        have "(\<lambda>i. \<integral>\<^sup>+ x. s i x \<partial>M) \<longlonglongrightarrow> \<integral>\<^sup>+ x. f x \<partial>M"
6.928 -          using seq s_le_f f
6.929 -          by (intro nn_integral_dominated_convergence[where w=f])
6.930 -             (auto simp: integrable_iff_bounded)
6.931 -        also have "(\<lambda>i. \<integral>\<^sup>+x. s i x \<partial>M) = (\<lambda>i. \<integral>x. s i x \<partial>M)"
6.932 -          using seq int_s by simp
6.933 -        finally show "(\<lambda>i. \<integral>x. s i x \<partial>M) \<longlonglongrightarrow> \<integral>\<^sup>+x. f x \<partial>M"
6.934 -          by simp
6.935 +        have U_le_f: "x \<in> space M \<Longrightarrow> U i x \<le> f x" for x i
6.936 +          using seq by (intro incseq_le) (auto simp: incseq_def le_fun_def)
6.937 +        have int_U: "\<And>i. integrable M (U i)"
6.938 +          using seq f U_le_f by (intro integrable_bound[OF f(3)]) auto
6.939 +        from U_le_f seq have "(\<lambda>i. integral\<^sup>L M (U i)) \<longlonglongrightarrow> integral\<^sup>L M f"
6.940 +          by (intro integral_dominated_convergence) auto
6.941 +        then show "(\<lambda>i. ennreal (integral\<^sup>L M (U i))) \<longlonglongrightarrow> ennreal (integral\<^sup>L M f)"
6.942 +          using seq f int_U by (simp add: f integral_nonneg_AE)
6.943 +        have "(\<lambda>i. \<integral>\<^sup>+ x. U i x \<partial>M) \<longlonglongrightarrow> \<integral>\<^sup>+ x. f x \<partial>M"
6.944 +          using seq U_le_f f
6.945 +          by (intro nn_integral_dominated_convergence[where w=f]) (auto simp: integrable_iff_bounded)
6.946 +        then show "(\<lambda>i. \<integral>x. U i x \<partial>M) \<longlonglongrightarrow> \<integral>\<^sup>+x. f x \<partial>M"
6.947 +          using seq int_U by simp
6.948        qed
6.949      qed }
6.950    from this[of "\<lambda>x. max 0 (f x)"] assms have "(\<integral>\<^sup>+ x. max 0 (f x) \<partial>M) = integral\<^sup>L M (\<lambda>x. max 0 (f x))"
6.951      by simp
6.952    also have "\<dots> = integral\<^sup>L M f"
6.953 -    using assms by (auto intro!: integral_cong_AE)
6.954 +    using assms by (auto intro!: integral_cong_AE simp: integral_nonneg_AE)
6.955    also have "(\<integral>\<^sup>+ x. max 0 (f x) \<partial>M) = (\<integral>\<^sup>+ x. f x \<partial>M)"
6.956      using assms by (auto intro!: nn_integral_cong_AE simp: max_def)
6.957    finally show ?thesis .
6.958 @@ -1650,18 +1692,18 @@
6.959  proof -
6.960    have 1: "integrable M (\<lambda>x. \<Sum>i. norm (f i x))"
6.961    proof (rule integrableI_bounded)
6.962 -    have "(\<integral>\<^sup>+ x. ereal (norm (\<Sum>i. norm (f i x))) \<partial>M) = (\<integral>\<^sup>+ x. (\<Sum>i. ereal (norm (f i x))) \<partial>M)"
6.963 -      apply (intro nn_integral_cong_AE)
6.964 +    have "(\<integral>\<^sup>+ x. ennreal (norm (\<Sum>i. norm (f i x))) \<partial>M) = (\<integral>\<^sup>+ x. (\<Sum>i. ennreal (norm (f i x))) \<partial>M)"
6.965 +      apply (intro nn_integral_cong_AE)
6.966        using summable
6.967        apply eventually_elim
6.968 -      apply (simp add: suminf_ereal' suminf_nonneg)
6.969 +      apply (simp add: suminf_nonneg ennreal_suminf_neq_top)
6.970        done
6.971      also have "\<dots> = (\<Sum>i. \<integral>\<^sup>+ x. norm (f i x) \<partial>M)"
6.972        by (intro nn_integral_suminf) auto
6.973 -    also have "\<dots> = (\<Sum>i. ereal (\<integral>x. norm (f i x) \<partial>M))"
6.974 +    also have "\<dots> = (\<Sum>i. ennreal (\<integral>x. norm (f i x) \<partial>M))"
6.975        by (intro arg_cong[where f=suminf] ext nn_integral_eq_integral integrable_norm integrable) auto
6.976 -    finally show "(\<integral>\<^sup>+ x. ereal (norm (\<Sum>i. norm (f i x))) \<partial>M) < \<infinity>"
6.977 -      by (simp add: suminf_ereal' sums)
6.978 +    finally show "(\<integral>\<^sup>+ x. ennreal (norm (\<Sum>i. norm (f i x))) \<partial>M) < \<infinity>"
6.979 +      by (simp add: sums ennreal_suminf_neq_top less_top[symmetric] integral_nonneg_AE)
6.980    qed simp
6.981
6.982    have 2: "AE x in M. (\<lambda>n. \<Sum>i<n. f i x) \<longlonglongrightarrow> (\<Sum>i. f i x)"
6.983 @@ -1693,43 +1735,57 @@
6.984    fixes f :: "_ \<Rightarrow> 'a :: {banach, second_countable_topology}"
6.985    shows "integrable M f \<Longrightarrow> norm (integral\<^sup>L M f) \<le> (\<integral>x. norm (f x) \<partial>M)"
6.986    using nn_integral_eq_integral[of M "\<lambda>x. norm (f x)"]
6.987 -  using integral_norm_bound_ereal[of M f] by simp
6.988 -
6.989 -lemma integrableI_nn_integral_finite:
6.990 -  assumes [measurable]: "f \<in> borel_measurable M"
6.991 -    and nonneg: "AE x in M. 0 \<le> f x"
6.992 -    and finite: "(\<integral>\<^sup>+x. f x \<partial>M) = ereal x"
6.993 -  shows "integrable M f"
6.994 -proof (rule integrableI_bounded)
6.995 -  have "(\<integral>\<^sup>+ x. ereal (norm (f x)) \<partial>M) = (\<integral>\<^sup>+ x. ereal (f x) \<partial>M)"
6.996 -    using nonneg by (intro nn_integral_cong_AE) auto
6.997 -  with finite show "(\<integral>\<^sup>+ x. ereal (norm (f x)) \<partial>M) < \<infinity>"
6.998 -    by auto
6.999 -qed simp
6.1000 +  using integral_norm_bound_ennreal[of M f] by (simp add: integral_nonneg_AE)
6.1001
6.1002  lemma integral_eq_nn_integral:
6.1003    assumes [measurable]: "f \<in> borel_measurable M"
6.1004    assumes nonneg: "AE x in M. 0 \<le> f x"
6.1005 -  shows "integral\<^sup>L M f = real_of_ereal (\<integral>\<^sup>+ x. ereal (f x) \<partial>M)"
6.1006 +  shows "integral\<^sup>L M f = enn2real (\<integral>\<^sup>+ x. ennreal (f x) \<partial>M)"
6.1007  proof cases
6.1008 -  assume *: "(\<integral>\<^sup>+ x. ereal (f x) \<partial>M) = \<infinity>"
6.1009 -  also have "(\<integral>\<^sup>+ x. ereal (f x) \<partial>M) = (\<integral>\<^sup>+ x. ereal (norm (f x)) \<partial>M)"
6.1010 +  assume *: "(\<integral>\<^sup>+ x. ennreal (f x) \<partial>M) = \<infinity>"
6.1011 +  also have "(\<integral>\<^sup>+ x. ennreal (f x) \<partial>M) = (\<integral>\<^sup>+ x. ennreal (norm (f x)) \<partial>M)"
6.1012      using nonneg by (intro nn_integral_cong_AE) auto
6.1013    finally have "\<not> integrable M f"
6.1014      by (auto simp: integrable_iff_bounded)
6.1015    then show ?thesis
6.1016      by (simp add: * not_integrable_integral_eq)
6.1017  next
6.1018 -  assume "(\<integral>\<^sup>+ x. ereal (f x) \<partial>M) \<noteq> \<infinity>"
6.1019 +  assume "(\<integral>\<^sup>+ x. ennreal (f x) \<partial>M) \<noteq> \<infinity>"
6.1020    then have "integrable M f"
6.1021 -    by (cases "\<integral>\<^sup>+ x. ereal (f x) \<partial>M") (auto intro!: integrableI_nn_integral_finite assms)
6.1022 -  from nn_integral_eq_integral[OF this nonneg] show ?thesis
6.1023 -    by simp
6.1024 +    by (cases "\<integral>\<^sup>+ x. ennreal (f x) \<partial>M" rule: ennreal_cases)
6.1025 +       (auto intro!: integrableI_nn_integral_finite assms)
6.1026 +  from nn_integral_eq_integral[OF this] nonneg show ?thesis
6.1027 +    by (simp add: integral_nonneg_AE)
6.1028  qed
6.1029 -
6.1030 +
6.1031 +lemma enn2real_nn_integral_eq_integral:
6.1032 +  assumes eq: "AE x in M. f x = ennreal (g x)" and nn: "AE x in M. 0 \<le> g x"
6.1033 +    and fin: "(\<integral>\<^sup>+x. f x \<partial>M) < top"
6.1034 +    and [measurable]: "g \<in> M \<rightarrow>\<^sub>M borel"
6.1035 +  shows "enn2real (\<integral>\<^sup>+x. f x \<partial>M) = (\<integral>x. g x \<partial>M)"
6.1036 +proof -
6.1037 +  have "ennreal (enn2real (\<integral>\<^sup>+x. f x \<partial>M)) = (\<integral>\<^sup>+x. f x \<partial>M)"
6.1038 +    using fin by (intro ennreal_enn2real) auto
6.1039 +  also have "\<dots> = (\<integral>\<^sup>+x. g x \<partial>M)"
6.1040 +    using eq by (rule nn_integral_cong_AE)
6.1041 +  also have "\<dots> = (\<integral>x. g x \<partial>M)"
6.1042 +  proof (rule nn_integral_eq_integral)
6.1043 +    show "integrable M g"
6.1044 +    proof (rule integrableI_bounded)
6.1045 +      have "(\<integral>\<^sup>+ x. ennreal (norm (g x)) \<partial>M) = (\<integral>\<^sup>+ x. f x \<partial>M)"
6.1046 +        using eq nn by (auto intro!: nn_integral_cong_AE elim!: eventually_elim2)
6.1047 +      also note fin
6.1048 +      finally show "(\<integral>\<^sup>+ x. ennreal (norm (g x)) \<partial>M) < \<infinity>"
6.1049 +        by simp
6.1050 +    qed simp
6.1051 +  qed fact
6.1052 +  finally show ?thesis
6.1053 +    using nn by (simp add: integral_nonneg_AE)
6.1054 +qed
6.1055 +
6.1056  lemma has_bochner_integral_nn_integral:
6.1057 -  assumes "f \<in> borel_measurable M" "AE x in M. 0 \<le> f x"
6.1058 -  assumes "(\<integral>\<^sup>+x. f x \<partial>M) = ereal x"
6.1059 +  assumes "f \<in> borel_measurable M" "AE x in M. 0 \<le> f x" "0 \<le> x"
6.1060 +  assumes "(\<integral>\<^sup>+x. f x \<partial>M) = ennreal x"
6.1061    shows "has_bochner_integral M f x"
6.1062    unfolding has_bochner_integral_iff
6.1063    using assms by (auto simp: assms integral_eq_nn_integral intro: integrableI_nn_integral_finite)
6.1064 @@ -1738,7 +1794,7 @@
6.1065    fixes f :: "'a \<Rightarrow> 'b::{banach, second_countable_topology}"
6.1066    shows "simple_bochner_integrable M f \<Longrightarrow> integrable M f"
6.1067    by (intro integrableI_sequence[where s="\<lambda>_. f"] borel_measurable_simple_function)
6.1068 -     (auto simp: zero_ereal_def[symmetric] simple_bochner_integrable.simps)
6.1069 +     (auto simp: zero_ennreal_def[symmetric] simple_bochner_integrable.simps)
6.1070
6.1071  lemma integrable_induct[consumes 1, case_names base add lim, induct pred: integrable]:
6.1072    fixes f :: "'a \<Rightarrow> 'b::{banach, second_countable_topology}"
6.1073 @@ -1757,7 +1813,7 @@
6.1074      "\<And>i x. x \<in> space M \<Longrightarrow> norm (s i x) \<le> 2 * norm (f x)"
6.1075      unfolding norm_conv_dist by metis
6.1076
6.1077 -  { fix f A
6.1078 +  { fix f A
6.1079      have [simp]: "P (\<lambda>x. 0)"
6.1080        using base[of "{}" undefined] by simp
6.1081      have "(\<And>i::'b. i \<in> A \<Longrightarrow> integrable M (f i::'a \<Rightarrow> 'b)) \<Longrightarrow>
6.1082 @@ -1773,7 +1829,7 @@
6.1083      unfolding s'_def using s(1)
6.1084      by (intro simple_function_compose2[where h="op *\<^sub>R"] simple_function_indicator) auto
6.1085
6.1086 -  { fix i
6.1087 +  { fix i
6.1088      have "\<And>z. {y. s' i z = y \<and> y \<in> s' i ` space M \<and> y \<noteq> 0 \<and> z \<in> space M} =
6.1089          (if z \<in> space M \<and> s' i z \<noteq> 0 then {s' i z} else {})"
6.1090        by (auto simp add: s'_def split: split_indicator)
6.1091 @@ -1785,10 +1841,10 @@
6.1092    proof (rule lim)
6.1093      fix i
6.1094
6.1095 -    have "(\<integral>\<^sup>+x. norm (s' i x) \<partial>M) \<le> (\<integral>\<^sup>+x. 2 * ereal (norm (f x)) \<partial>M)"
6.1096 +    have "(\<integral>\<^sup>+x. norm (s' i x) \<partial>M) \<le> (\<integral>\<^sup>+x. ennreal (2 * norm (f x)) \<partial>M)"
6.1097        using s by (intro nn_integral_mono) (auto simp: s'_eq_s)
6.1098      also have "\<dots> < \<infinity>"
6.1099 -      using f by (subst nn_integral_cmult) auto
6.1100 +      using f by (simp add: nn_integral_cmult ennreal_mult_less_top ennreal_mult)
6.1101      finally have sbi: "simple_bochner_integrable M (s' i)"
6.1102        using sf by (intro simple_bochner_integrableI_bounded) auto
6.1103      then show "integrable M (s' i)"
6.1104 @@ -1798,10 +1854,10 @@
6.1105        then have "emeasure M {y \<in> space M. s' i y = s' i x} \<le> emeasure M {y \<in> space M. s' i y \<noteq> 0}"
6.1106          by (intro emeasure_mono) auto
6.1107        also have "\<dots> < \<infinity>"
6.1108 -        using sbi by (auto elim: simple_bochner_integrable.cases)
6.1109 +        using sbi by (auto elim: simple_bochner_integrable.cases simp: less_top)
6.1110        finally have "emeasure M {y \<in> space M. s' i y = s' i x} \<noteq> \<infinity>" by simp }
6.1111      then show "P (s' i)"
6.1112 -      by (subst s'_eq) (auto intro!: setsum base)
6.1113 +      by (subst s'_eq) (auto intro!: setsum base simp: less_top)
6.1114
6.1115      fix x assume "x \<in> space M" with s show "(\<lambda>i. s' i x) \<longlonglongrightarrow> f x"
6.1117 @@ -1810,20 +1866,6 @@
6.1118    qed fact
6.1119  qed
6.1120
6.1121 -lemma integral_nonneg_AE:
6.1122 -  fixes f :: "'a \<Rightarrow> real"
6.1123 -  assumes [measurable]: "AE x in M. 0 \<le> f x"
6.1124 -  shows "0 \<le> integral\<^sup>L M f"
6.1125 -proof cases
6.1126 -  assume [measurable]: "integrable M f"
6.1127 -  then have "0 \<le> ereal (integral\<^sup>L M (\<lambda>x. max 0 (f x)))"
6.1128 -    by (subst integral_eq_nn_integral) (auto intro: real_of_ereal_pos nn_integral_nonneg assms)
6.1129 -  also have "integral\<^sup>L M (\<lambda>x. max 0 (f x)) = integral\<^sup>L M f"
6.1130 -    using assms by (intro integral_cong_AE assms integrable_max) auto
6.1131 -  finally show ?thesis
6.1132 -    by simp
6.1134 -
6.1135  lemma integral_eq_zero_AE:
6.1136    "(AE x in M. f x = 0) \<Longrightarrow> integral\<^sup>L M f = 0"
6.1137    using integral_cong_AE[of f M "\<lambda>_. 0"]
6.1138 @@ -1837,7 +1879,7 @@
6.1139    assume "integral\<^sup>L M f = 0"
6.1140    then have "integral\<^sup>N M f = 0"
6.1141      using nn_integral_eq_integral[OF f nonneg] by simp
6.1142 -  then have "AE x in M. ereal (f x) \<le> 0"
6.1143 +  then have "AE x in M. ennreal (f x) \<le> 0"
6.1145    with nonneg show "AE x in M. f x = 0"
6.1146      by auto
6.1147 @@ -1857,11 +1899,11 @@
6.1148
6.1149  lemma integral_mono:
6.1150    fixes f :: "'a \<Rightarrow> real"
6.1151 -  shows "integrable M f \<Longrightarrow> integrable M g \<Longrightarrow> (\<And>x. x \<in> space M \<Longrightarrow> f x \<le> g x) \<Longrightarrow>
6.1152 +  shows "integrable M f \<Longrightarrow> integrable M g \<Longrightarrow> (\<And>x. x \<in> space M \<Longrightarrow> f x \<le> g x) \<Longrightarrow>
6.1153      integral\<^sup>L M f \<le> integral\<^sup>L M g"
6.1154    by (intro integral_mono_AE) auto
6.1155
6.1156 -lemma (in finite_measure) integrable_measure:
6.1157 +lemma (in finite_measure) integrable_measure:
6.1158    assumes I: "disjoint_family_on X I" "countable I"
6.1159    shows "integrable (count_space I) (\<lambda>i. measure M (X i))"
6.1160  proof -
6.1161 @@ -1871,31 +1913,41 @@
6.1162      using I unfolding emeasure_eq_measure[symmetric]
6.1163      by (subst emeasure_UN_countable) (auto simp: disjoint_family_on_def)
6.1164    finally show ?thesis
6.1165 -    by (auto intro!: integrableI_bounded simp: measure_nonneg)
6.1166 +    by (auto intro!: integrableI_bounded)
6.1167  qed
6.1168
6.1169  lemma integrableI_real_bounded:
6.1170    assumes f: "f \<in> borel_measurable M" and ae: "AE x in M. 0 \<le> f x" and fin: "integral\<^sup>N M f < \<infinity>"
6.1171    shows "integrable M f"
6.1172  proof (rule integrableI_bounded)
6.1173 -  have "(\<integral>\<^sup>+ x. ereal (norm (f x)) \<partial>M) = \<integral>\<^sup>+ x. ereal (f x) \<partial>M"
6.1174 +  have "(\<integral>\<^sup>+ x. ennreal (norm (f x)) \<partial>M) = \<integral>\<^sup>+ x. ennreal (f x) \<partial>M"
6.1175      using ae by (auto intro: nn_integral_cong_AE)
6.1176    also note fin
6.1177 -  finally show "(\<integral>\<^sup>+ x. ereal (norm (f x)) \<partial>M) < \<infinity>" .
6.1178 +  finally show "(\<integral>\<^sup>+ x. ennreal (norm (f x)) \<partial>M) < \<infinity>" .
6.1179  qed fact
6.1180
6.1181  lemma integral_real_bounded:
6.1182 -  assumes "AE x in M. 0 \<le> f x" "integral\<^sup>N M f \<le> ereal r"
6.1183 +  assumes "0 \<le> r" "integral\<^sup>N M f \<le> ennreal r"
6.1184    shows "integral\<^sup>L M f \<le> r"
6.1185  proof cases
6.1186 -  assume "integrable M f" from nn_integral_eq_integral[OF this] assms show ?thesis
6.1187 +  assume [simp]: "integrable M f"
6.1188 +
6.1189 +  have "integral\<^sup>L M (\<lambda>x. max 0 (f x)) = integral\<^sup>N M (\<lambda>x. max 0 (f x))"
6.1190 +    by (intro nn_integral_eq_integral[symmetric]) auto
6.1191 +  also have "\<dots> = integral\<^sup>N M f"
6.1192 +    by (intro nn_integral_cong) (simp add: max_def ennreal_neg)
6.1193 +  also have "\<dots> \<le> r"
6.1194 +    by fact
6.1195 +  finally have "integral\<^sup>L M (\<lambda>x. max 0 (f x)) \<le> r"
6.1196 +    using \<open>0 \<le> r\<close> by simp
6.1197 +
6.1198 +  moreover have "integral\<^sup>L M f \<le> integral\<^sup>L M (\<lambda>x. max 0 (f x))"
6.1199 +    by (rule integral_mono_AE) auto
6.1200 +  ultimately show ?thesis
6.1201      by simp
6.1202  next
6.1203 -  assume "\<not> integrable M f"
6.1204 -  moreover have "0 \<le> ereal r"
6.1205 -    using nn_integral_nonneg assms(2) by (rule order_trans)
6.1206 -  ultimately show ?thesis
6.1207 -    by (simp add: not_integrable_integral_eq)
6.1208 +  assume "\<not> integrable M f" then show ?thesis
6.1209 +    using \<open>0 \<le> r\<close> by (simp add: not_integrable_integral_eq)
6.1210  qed
6.1211
6.1212  subsection \<open>Restricted measure spaces\<close>
6.1213 @@ -1907,7 +1959,7 @@
6.1214    unfolding integrable_iff_bounded
6.1215      borel_measurable_restrict_space_iff[OF \<Omega>]
6.1216      nn_integral_restrict_space[OF \<Omega>]
6.1217 -  by (simp add: ac_simps ereal_indicator times_ereal.simps(1)[symmetric] del: times_ereal.simps)
6.1218 +  by (simp add: ac_simps ennreal_indicator ennreal_mult)
6.1219
6.1220  lemma integral_restrict_space:
6.1221    fixes f :: "'a \<Rightarrow> 'b::{banach, second_countable_topology}"
6.1222 @@ -1929,13 +1981,12 @@
6.1223      proof (rule LIMSEQ_unique)
6.1224        show "(\<lambda>i. integral\<^sup>L (restrict_space M \<Omega>) (s i)) \<longlonglongrightarrow> integral\<^sup>L (restrict_space M \<Omega>) f"
6.1225          using lim by (intro integral_dominated_convergence[where w="\<lambda>x. 2 * norm (f x)"]) simp_all
6.1226 -
6.1227 +
6.1228        show "(\<lambda>i. integral\<^sup>L (restrict_space M \<Omega>) (s i)) \<longlonglongrightarrow> (\<integral> x. indicator \<Omega> x *\<^sub>R f x \<partial>M)"
6.1229          unfolding lim
6.1230          using lim
6.1231          by (intro integral_dominated_convergence[where w="\<lambda>x. 2 * norm (indicator \<Omega> x *\<^sub>R f x)"])
6.1232 -           (auto simp add: space_restrict_space integrable_restrict_space
6.1233 -                 simp del: norm_scaleR
6.1234 +           (auto simp add: space_restrict_space integrable_restrict_space simp del: norm_scaleR
6.1235                   split: split_indicator)
6.1236      qed
6.1237    qed
6.1238 @@ -1958,9 +2009,9 @@
6.1239      and nn: "AE x in M. 0 \<le> g x"
6.1240    shows "integrable (density M g) f \<longleftrightarrow> integrable M (\<lambda>x. g x *\<^sub>R f x)"
6.1241    unfolding integrable_iff_bounded using nn
6.1242 -  apply (simp add: nn_integral_density )
6.1243 +  apply (simp add: nn_integral_density less_top[symmetric])
6.1244    apply (intro arg_cong2[where f="op ="] refl nn_integral_cong_AE)
6.1245 -  apply auto
6.1246 +  apply (auto simp: ennreal_mult)
6.1247    done
6.1248
6.1249  lemma integral_density:
6.1250 @@ -1974,21 +2025,25 @@
6.1251    proof induct
6.1252      case (base A c)
6.1253      then have [measurable]: "A \<in> sets M" by auto
6.1254 -
6.1255 +
6.1256      have int: "integrable M (\<lambda>x. g x * indicator A x)"
6.1257        using g base integrable_density[of "indicator A :: 'a \<Rightarrow> real" M g] by simp
6.1258 -    then have "integral\<^sup>L M (\<lambda>x. g x * indicator A x) = (\<integral>\<^sup>+ x. ereal (g x * indicator A x) \<partial>M)"
6.1259 +    then have "integral\<^sup>L M (\<lambda>x. g x * indicator A x) = (\<integral>\<^sup>+ x. ennreal (g x * indicator A x) \<partial>M)"
6.1260        using g by (subst nn_integral_eq_integral) auto
6.1261 -    also have "\<dots> = (\<integral>\<^sup>+ x. ereal (g x) * indicator A x \<partial>M)"
6.1262 +    also have "\<dots> = (\<integral>\<^sup>+ x. ennreal (g x) * indicator A x \<partial>M)"
6.1263        by (intro nn_integral_cong) (auto split: split_indicator)
6.1264      also have "\<dots> = emeasure (density M g) A"
6.1265        by (rule emeasure_density[symmetric]) auto
6.1266 -    also have "\<dots> = ereal (measure (density M g) A)"
6.1267 -      using base by (auto intro: emeasure_eq_ereal_measure)
6.1268 +    also have "\<dots> = ennreal (measure (density M g) A)"
6.1269 +      using base by (auto intro: emeasure_eq_ennreal_measure)
6.1270      also have "\<dots> = integral\<^sup>L (density M g) (indicator A)"
6.1271        using base by simp
6.1272      finally show ?case
6.1273 -      using base by (simp add: int)
6.1274 +      using base g
6.1275 +      apply (simp add: int integral_nonneg_AE)
6.1276 +      apply (subst (asm) ennreal_inj)
6.1277 +      apply (auto intro!: integral_nonneg_AE)
6.1278 +      done
6.1279    next
6.1281      then have [measurable]: "f \<in> borel_measurable M" "h \<in> borel_measurable M"
6.1282 @@ -1999,7 +2054,7 @@
6.1283      case (lim f s)
6.1284      have [measurable]: "f \<in> borel_measurable M" "\<And>i. s i \<in> borel_measurable M"
6.1285        using lim(1,5)[THEN borel_measurable_integrable] by auto
6.1286 -
6.1287 +
6.1288      show ?case
6.1289      proof (rule LIMSEQ_unique)
6.1290        show "(\<lambda>i. integral\<^sup>L M (\<lambda>x. g x *\<^sub>R s i x)) \<longlonglongrightarrow> integral\<^sup>L M (\<lambda>x. g x *\<^sub>R f x)"
6.1291 @@ -2058,7 +2113,7 @@
6.1292      then have [measurable]: "A \<in> sets N" by auto
6.1293      from base have int: "integrable (distr M N g) (\<lambda>a. indicator A a *\<^sub>R c)"
6.1294        by (intro integrable_indicator)
6.1295 -
6.1296 +
6.1297      have "integral\<^sup>L (distr M N g) (\<lambda>a. indicator A a *\<^sub>R c) = measure (distr M N g) A *\<^sub>R c"
6.1298        using base by auto
6.1299      also have "\<dots> = measure M (g -` A \<inter> space M) *\<^sub>R c"
6.1300 @@ -2078,13 +2133,13 @@
6.1301      case (lim f s)
6.1302      have [measurable]: "f \<in> borel_measurable N" "\<And>i. s i \<in> borel_measurable N"
6.1303        using lim(1,5)[THEN borel_measurable_integrable] by auto
6.1304 -
6.1305 +
6.1306      show ?case
6.1307      proof (rule LIMSEQ_unique)
6.1308        show "(\<lambda>i. integral\<^sup>L M (\<lambda>x. s i (g x))) \<longlonglongrightarrow> integral\<^sup>L M (\<lambda>x. f (g x))"
6.1309        proof (rule integral_dominated_convergence)
6.1310          show "integrable M (\<lambda>x. 2 * norm (f (g x)))"
6.1311 -          using lim by (auto simp: integrable_distr_eq)
6.1312 +          using lim by (auto simp: integrable_distr_eq)
6.1313          show "AE x in M. (\<lambda>i. s i (g x)) \<longlonglongrightarrow> f (g x)"
6.1314            using lim(3) g[THEN measurable_space] by auto
6.1315          show "\<And>i. AE x in M. norm (s i (g x)) \<le> 2 * norm (f (g x))"
6.1316 @@ -2121,7 +2176,7 @@
6.1317  proof -
6.1318    have eq: "\<And>x. x \<in> A \<Longrightarrow> (\<Sum>a | x = a \<and> a \<in> A \<and> f a \<noteq> 0. f a) = (\<Sum>x\<in>{x}. f x)"
6.1319      by (intro setsum.mono_neutral_cong_left) auto
6.1320 -
6.1321 +
6.1322    have "(\<integral>x. f x \<partial>count_space A) = (\<integral>x. (\<Sum>a | a \<in> A \<and> f a \<noteq> 0. indicator {a} x *\<^sub>R f a) \<partial>count_space A)"
6.1323      by (intro integral_cong refl) (simp add: f eq)
6.1324    also have "\<dots> = (\<Sum>a | a \<in> A \<and> f a \<noteq> 0. measure (count_space A) {a} *\<^sub>R f a)"
6.1325 @@ -2137,7 +2192,8 @@
6.1326  lemma integrable_count_space_nat_iff:
6.1327    fixes f :: "nat \<Rightarrow> _::{banach,second_countable_topology}"
6.1328    shows "integrable (count_space UNIV) f \<longleftrightarrow> summable (\<lambda>x. norm (f x))"
6.1329 -  by (auto simp add: integrable_iff_bounded nn_integral_count_space_nat summable_ereal suminf_ereal_finite)
6.1330 +  by (auto simp add: integrable_iff_bounded nn_integral_count_space_nat ennreal_suminf_neq_top
6.1331 +           intro:  summable_suminf_not_top)
6.1332
6.1333  lemma sums_integral_count_space_nat:
6.1334    fixes f :: "nat \<Rightarrow> _::{banach,second_countable_topology}"
6.1335 @@ -2181,7 +2237,8 @@
6.1336    fixes g :: "'a \<Rightarrow> 'b::{banach, second_countable_topology}" and f :: "'a \<Rightarrow> real"
6.1337    shows "finite A \<Longrightarrow> integrable (point_measure A f) g"
6.1338    unfolding point_measure_def
6.1339 -  apply (subst density_ereal_max_0)
6.1340 +  apply (subst density_cong[where f'="\<lambda>x. ennreal (max 0 (f x))"])
6.1341 +  apply (auto split: split_max simp: ennreal_neg)
6.1342    apply (subst integrable_density)
6.1343    apply (auto simp: AE_count_space integrable_count_space)
6.1344    done
6.1345 @@ -2204,67 +2261,60 @@
6.1346
6.1347  lemma real_lebesgue_integral_def:
6.1348    assumes f[measurable]: "integrable M f"
6.1349 -  shows "integral\<^sup>L M f = real_of_ereal (\<integral>\<^sup>+x. f x \<partial>M) - real_of_ereal (\<integral>\<^sup>+x. - f x \<partial>M)"
6.1350 +  shows "integral\<^sup>L M f = enn2real (\<integral>\<^sup>+x. f x \<partial>M) - enn2real (\<integral>\<^sup>+x. ennreal (- f x) \<partial>M)"
6.1351  proof -
6.1352    have "integral\<^sup>L M f = integral\<^sup>L M (\<lambda>x. max 0 (f x) - max 0 (- f x))"
6.1353      by (auto intro!: arg_cong[where f="integral\<^sup>L M"])
6.1354    also have "\<dots> = integral\<^sup>L M (\<lambda>x. max 0 (f x)) - integral\<^sup>L M (\<lambda>x. max 0 (- f x))"
6.1355      by (intro integral_diff integrable_max integrable_minus integrable_zero f)
6.1356 -  also have "integral\<^sup>L M (\<lambda>x. max 0 (f x)) = real_of_ereal (\<integral>\<^sup>+x. max 0 (f x) \<partial>M)"
6.1357 -    by (subst integral_eq_nn_integral[symmetric]) auto
6.1358 -  also have "integral\<^sup>L M (\<lambda>x. max 0 (- f x)) = real_of_ereal (\<integral>\<^sup>+x. max 0 (- f x) \<partial>M)"
6.1359 -    by (subst integral_eq_nn_integral[symmetric]) auto
6.1360 -  also have "(\<lambda>x. ereal (max 0 (f x))) = (\<lambda>x. max 0 (ereal (f x)))"
6.1361 -    by (auto simp: max_def)
6.1362 -  also have "(\<lambda>x. ereal (max 0 (- f x))) = (\<lambda>x. max 0 (- ereal (f x)))"
6.1363 -    by (auto simp: max_def)
6.1364 -  finally show ?thesis
6.1365 -    unfolding nn_integral_max_0 .
6.1366 +  also have "integral\<^sup>L M (\<lambda>x. max 0 (f x)) = enn2real (\<integral>\<^sup>+x. ennreal (f x) \<partial>M)"
6.1367 +    by (subst integral_eq_nn_integral) (auto intro!: arg_cong[where f=enn2real] nn_integral_cong simp: max_def ennreal_neg)
6.1368 +  also have "integral\<^sup>L M (\<lambda>x. max 0 (- f x)) = enn2real (\<integral>\<^sup>+x. ennreal (- f x) \<partial>M)"
6.1369 +    by (subst integral_eq_nn_integral) (auto intro!: arg_cong[where f=enn2real] nn_integral_cong simp: max_def ennreal_neg)
6.1370 +  finally show ?thesis .
6.1371  qed
6.1372
6.1373  lemma real_integrable_def:
6.1374    "integrable M f \<longleftrightarrow> f \<in> borel_measurable M \<and>
6.1375 -    (\<integral>\<^sup>+ x. ereal (f x) \<partial>M) \<noteq> \<infinity> \<and> (\<integral>\<^sup>+ x. ereal (- f x) \<partial>M) \<noteq> \<infinity>"
6.1376 +    (\<integral>\<^sup>+ x. ennreal (f x) \<partial>M) \<noteq> \<infinity> \<and> (\<integral>\<^sup>+ x. ennreal (- f x) \<partial>M) \<noteq> \<infinity>"
6.1377    unfolding integrable_iff_bounded
6.1378  proof (safe del: notI)
6.1379 -  assume *: "(\<integral>\<^sup>+ x. ereal (norm (f x)) \<partial>M) < \<infinity>"
6.1380 -  have "(\<integral>\<^sup>+ x. ereal (f x) \<partial>M) \<le> (\<integral>\<^sup>+ x. ereal (norm (f x)) \<partial>M)"
6.1381 +  assume *: "(\<integral>\<^sup>+ x. ennreal (norm (f x)) \<partial>M) < \<infinity>"
6.1382 +  have "(\<integral>\<^sup>+ x. ennreal (f x) \<partial>M) \<le> (\<integral>\<^sup>+ x. ennreal (norm (f x)) \<partial>M)"
6.1383      by (intro nn_integral_mono) auto
6.1384    also note *
6.1385 -  finally show "(\<integral>\<^sup>+ x. ereal (f x) \<partial>M) \<noteq> \<infinity>"
6.1386 +  finally show "(\<integral>\<^sup>+ x. ennreal (f x) \<partial>M) \<noteq> \<infinity>"
6.1387      by simp
6.1388 -  have "(\<integral>\<^sup>+ x. ereal (- f x) \<partial>M) \<le> (\<integral>\<^sup>+ x. ereal (norm (f x)) \<partial>M)"
6.1389 +  have "(\<integral>\<^sup>+ x. ennreal (- f x) \<partial>M) \<le> (\<integral>\<^sup>+ x. ennreal (norm (f x)) \<partial>M)"
6.1390      by (intro nn_integral_mono) auto
6.1391    also note *
6.1392 -  finally show "(\<integral>\<^sup>+ x. ereal (- f x) \<partial>M) \<noteq> \<infinity>"
6.1393 +  finally show "(\<integral>\<^sup>+ x. ennreal (- f x) \<partial>M) \<noteq> \<infinity>"
6.1394      by simp
6.1395  next
6.1396    assume [measurable]: "f \<in> borel_measurable M"
6.1397 -  assume fin: "(\<integral>\<^sup>+ x. ereal (f x) \<partial>M) \<noteq> \<infinity>" "(\<integral>\<^sup>+ x. ereal (- f x) \<partial>M) \<noteq> \<infinity>"
6.1398 -  have "(\<integral>\<^sup>+ x. norm (f x) \<partial>M) = (\<integral>\<^sup>+ x. max 0 (ereal (f x)) + max 0 (ereal (- f x)) \<partial>M)"
6.1399 -    by (intro nn_integral_cong) (auto simp: max_def)
6.1400 -  also have"\<dots> = (\<integral>\<^sup>+ x. max 0 (ereal (f x)) \<partial>M) + (\<integral>\<^sup>+ x. max 0 (ereal (- f x)) \<partial>M)"
6.1401 +  assume fin: "(\<integral>\<^sup>+ x. ennreal (f x) \<partial>M) \<noteq> \<infinity>" "(\<integral>\<^sup>+ x. ennreal (- f x) \<partial>M) \<noteq> \<infinity>"
6.1402 +  have "(\<integral>\<^sup>+ x. norm (f x) \<partial>M) = (\<integral>\<^sup>+ x. ennreal (f x) + ennreal (- f x) \<partial>M)"
6.1403 +    by (intro nn_integral_cong) (auto simp: abs_real_def ennreal_neg)
6.1404 +  also have"\<dots> = (\<integral>\<^sup>+ x. ennreal (f x) \<partial>M) + (\<integral>\<^sup>+ x. ennreal (- f x) \<partial>M)"
6.1406    also have "\<dots> < \<infinity>"
6.1407 -    using fin by (auto simp: nn_integral_max_0)
6.1408 +    using fin by (auto simp: less_top)
6.1409    finally show "(\<integral>\<^sup>+ x. norm (f x) \<partial>M) < \<infinity>" .
6.1410  qed
6.1411
6.1412  lemma integrableD[dest]:
6.1413    assumes "integrable M f"
6.1414 -  shows "f \<in> borel_measurable M" "(\<integral>\<^sup>+ x. ereal (f x) \<partial>M) \<noteq> \<infinity>" "(\<integral>\<^sup>+ x. ereal (- f x) \<partial>M) \<noteq> \<infinity>"
6.1415 +  shows "f \<in> borel_measurable M" "(\<integral>\<^sup>+ x. ennreal (f x) \<partial>M) \<noteq> \<infinity>" "(\<integral>\<^sup>+ x. ennreal (- f x) \<partial>M) \<noteq> \<infinity>"
6.1416    using assms unfolding real_integrable_def by auto
6.1417
6.1418  lemma integrableE:
6.1419    assumes "integrable M f"
6.1420    obtains r q where
6.1421 -    "(\<integral>\<^sup>+x. ereal (f x)\<partial>M) = ereal r"
6.1422 -    "(\<integral>\<^sup>+x. ereal (-f x)\<partial>M) = ereal q"
6.1423 +    "(\<integral>\<^sup>+x. ennreal (f x)\<partial>M) = ennreal r"
6.1424 +    "(\<integral>\<^sup>+x. ennreal (-f x)\<partial>M) = ennreal q"
6.1425      "f \<in> borel_measurable M" "integral\<^sup>L M f = r - q"
6.1426    using assms unfolding real_integrable_def real_lebesgue_integral_def[OF assms]
6.1427 -  using nn_integral_nonneg[of M "\<lambda>x. ereal (f x)"]
6.1428 -  using nn_integral_nonneg[of M "\<lambda>x. ereal (-f x)"]
6.1429 -  by (cases rule: ereal2_cases[of "(\<integral>\<^sup>+x. ereal (-f x)\<partial>M)" "(\<integral>\<^sup>+x. ereal (f x)\<partial>M)"]) auto
6.1430 +  by (cases rule: ennreal2_cases[of "(\<integral>\<^sup>+x. ennreal (-f x)\<partial>M)" "(\<integral>\<^sup>+x. ennreal (f x)\<partial>M)"]) auto
6.1431
6.1432  lemma integral_monotone_convergence_nonneg:
6.1433    fixes f :: "nat \<Rightarrow> 'a \<Rightarrow> real"
6.1434 @@ -2276,34 +2326,33 @@
6.1435    shows "integrable M u"
6.1436    and "integral\<^sup>L M u = x"
6.1437  proof -
6.1438 -  have "(\<integral>\<^sup>+ x. ereal (u x) \<partial>M) = (SUP n. (\<integral>\<^sup>+ x. ereal (f n x) \<partial>M))"
6.1439 +  have nn: "AE x in M. \<forall>i. 0 \<le> f i x"
6.1440 +    using pos unfolding AE_all_countable by auto
6.1441 +  with lim have u_nn: "AE x in M. 0 \<le> u x"
6.1442 +    by eventually_elim (auto intro: LIMSEQ_le_const)
6.1443 +  have [simp]: "0 \<le> x"
6.1444 +    by (intro LIMSEQ_le_const[OF ilim] allI exI impI integral_nonneg_AE pos)
6.1445 +  have "(\<integral>\<^sup>+ x. ennreal (u x) \<partial>M) = (SUP n. (\<integral>\<^sup>+ x. ennreal (f n x) \<partial>M))"
6.1446    proof (subst nn_integral_monotone_convergence_SUP_AE[symmetric])
6.1447      fix i
6.1448 -    from mono pos show "AE x in M. ereal (f i x) \<le> ereal (f (Suc i) x) \<and> 0 \<le> ereal (f i x)"
6.1449 +    from mono nn show "AE x in M. ennreal (f i x) \<le> ennreal (f (Suc i) x)"
6.1450        by eventually_elim (auto simp: mono_def)
6.1451 -    show "(\<lambda>x. ereal (f i x)) \<in> borel_measurable M"
6.1452 +    show "(\<lambda>x. ennreal (f i x)) \<in> borel_measurable M"
6.1453        using i by auto
6.1454    next
6.1455 -    show "(\<integral>\<^sup>+ x. ereal (u x) \<partial>M) = \<integral>\<^sup>+ x. (SUP i. ereal (f i x)) \<partial>M"
6.1456 +    show "(\<integral>\<^sup>+ x. ennreal (u x) \<partial>M) = \<integral>\<^sup>+ x. (SUP i. ennreal (f i x)) \<partial>M"
6.1457        apply (rule nn_integral_cong_AE)
6.1458 -      using lim mono
6.1459 -      by eventually_elim (simp add: SUP_eq_LIMSEQ[THEN iffD2])
6.1460 +      using lim mono nn u_nn
6.1461 +      apply eventually_elim
6.1462 +      apply (simp add: LIMSEQ_unique[OF _ LIMSEQ_SUP] incseq_def)
6.1463 +      done
6.1464    qed
6.1465 -  also have "\<dots> = ereal x"
6.1466 -    using mono i unfolding nn_integral_eq_integral[OF i pos]
6.1467 -    by (subst SUP_eq_LIMSEQ) (auto simp: mono_def intro!: integral_mono_AE ilim)
6.1468 -  finally have "(\<integral>\<^sup>+ x. ereal (u x) \<partial>M) = ereal x" .
6.1469 -  moreover have "(\<integral>\<^sup>+ x. ereal (- u x) \<partial>M) = 0"
6.1470 -  proof (subst nn_integral_0_iff_AE)
6.1471 -    show "(\<lambda>x. ereal (- u x)) \<in> borel_measurable M"
6.1472 -      using u by auto
6.1473 -    from mono pos[of 0] lim show "AE x in M. ereal (- u x) \<le> 0"
6.1474 -    proof eventually_elim
6.1475 -      fix x assume "mono (\<lambda>n. f n x)" "0 \<le> f 0 x" "(\<lambda>i. f i x) \<longlonglongrightarrow> u x"
6.1476 -      then show "ereal (- u x) \<le> 0"
6.1477 -        using incseq_le[of "\<lambda>n. f n x" "u x" 0] by (simp add: mono_def incseq_def)
6.1478 -    qed
6.1479 -  qed
6.1480 +  also have "\<dots> = ennreal x"
6.1481 +    using mono i nn unfolding nn_integral_eq_integral[OF i pos]
6.1482 +    by (subst LIMSEQ_unique[OF LIMSEQ_SUP]) (auto simp: mono_def integral_nonneg_AE pos intro!: integral_mono_AE ilim)
6.1483 +  finally have "(\<integral>\<^sup>+ x. ennreal (u x) \<partial>M) = ennreal x" .
6.1484 +  moreover have "(\<integral>\<^sup>+ x. ennreal (- u x) \<partial>M) = 0"
6.1485 +    using u u_nn by (subst nn_integral_0_iff_AE) (auto simp add: ennreal_neg)
6.1486    ultimately show "integrable M u" "integral\<^sup>L M u = x"
6.1487      by (auto simp: real_integrable_def real_lebesgue_integral_def u)
6.1488  qed
6.1489 @@ -2348,7 +2397,7 @@
6.1490      using f by (intro nn_integral_eq_integral integrable_norm) auto
6.1491    then have "(\<integral>x. norm (f x) \<partial>M) = 0 \<longleftrightarrow> (\<integral>\<^sup>+x. norm (f x) \<partial>M) = 0"
6.1492      by simp
6.1493 -  also have "\<dots> \<longleftrightarrow> emeasure M {x\<in>space M. ereal (norm (f x)) \<noteq> 0} = 0"
6.1494 +  also have "\<dots> \<longleftrightarrow> emeasure M {x\<in>space M. ennreal (norm (f x)) \<noteq> 0} = 0"
6.1495      by (intro nn_integral_0_iff) auto
6.1496    finally show ?thesis
6.1497      by simp
6.1498 @@ -2360,15 +2409,15 @@
6.1499    using integral_norm_eq_0_iff[of M f] by simp
6.1500
6.1501  lemma (in finite_measure) integrable_const[intro!, simp]: "integrable M (\<lambda>x. a)"
6.1502 -  using integrable_indicator[of "space M" M a] by (simp cong: integrable_cong)
6.1503 +  using integrable_indicator[of "space M" M a] by (simp cong: integrable_cong add: less_top[symmetric])
6.1504
6.1505 -lemma lebesgue_integral_const[simp]:
6.1506 +lemma lebesgue_integral_const[simp]:
6.1507    fixes a :: "'a :: {banach, second_countable_topology}"
6.1508    shows "(\<integral>x. a \<partial>M) = measure M (space M) *\<^sub>R a"
6.1509  proof -
6.1510    { assume "emeasure M (space M) = \<infinity>" "a \<noteq> 0"
6.1511      then have ?thesis
6.1512 -      by (simp add: not_integrable_integral_eq measure_def integrable_iff_bounded) }
6.1513 +      by (auto simp add: not_integrable_integral_eq ennreal_mult_less_top measure_def integrable_iff_bounded) }
6.1514    moreover
6.1515    { assume "a = 0" then have ?thesis by simp }
6.1516    moreover
6.1517 @@ -2378,7 +2427,7 @@
6.1518      have "(\<integral>x. a \<partial>M) = (\<integral>x. indicator (space M) x *\<^sub>R a \<partial>M)"
6.1519        by (intro integral_cong) auto
6.1520      also have "\<dots> = measure M (space M) *\<^sub>R a"
6.1521 -      by simp
6.1522 +      by (simp add: less_top[symmetric])
6.1523      finally have ?thesis . }
6.1524    ultimately show ?thesis by blast
6.1525  qed
6.1526 @@ -2409,18 +2458,16 @@
6.1527    finally show ?thesis .
6.1528  qed
6.1529
6.1530 -lemma (in finite_measure) ereal_integral_real:
6.1531 -  assumes [measurable]: "f \<in> borel_measurable M"
6.1532 -  assumes ae: "AE x in M. 0 \<le> f x" "AE x in M. f x \<le> ereal B"
6.1533 -  shows "ereal (\<integral>x. real_of_ereal (f x) \<partial>M) = (\<integral>\<^sup>+x. f x \<partial>M)"
6.1534 +lemma (in finite_measure) ennreal_integral_real:
6.1535 +  assumes [measurable]: "f \<in> borel_measurable M"
6.1536 +  assumes ae: "AE x in M. f x \<le> ennreal B" "0 \<le> B"
6.1537 +  shows "ennreal (\<integral>x. enn2real (f x) \<partial>M) = (\<integral>\<^sup>+x. f x \<partial>M)"
6.1538  proof (subst nn_integral_eq_integral[symmetric])
6.1539 -  show "integrable M (\<lambda>x. real_of_ereal (f x))"
6.1540 -    using ae by (intro integrable_const_bound[where B=B]) (auto simp: real_le_ereal_iff)
6.1541 -  show "AE x in M. 0 \<le> real_of_ereal (f x)"
6.1542 -    using ae by (auto simp: real_of_ereal_pos)
6.1543 -  show "(\<integral>\<^sup>+ x. ereal (real_of_ereal (f x)) \<partial>M) = integral\<^sup>N M f"
6.1544 -    using ae by (intro nn_integral_cong_AE) (auto simp: ereal_real)
6.1545 -qed
6.1546 +  show "integrable M (\<lambda>x. enn2real (f x))"
6.1547 +    using ae by (intro integrable_const_bound[where B=B]) (auto simp: enn2real_leI enn2real_nonneg)
6.1548 +  show "(\<integral>\<^sup>+ x. ennreal (enn2real (f x)) \<partial>M) = integral\<^sup>N M f"
6.1549 +    using ae by (intro nn_integral_cong_AE) (auto simp: le_less_trans[OF _ ennreal_less_top])
6.1550 +qed (auto simp: enn2real_nonneg)
6.1551
6.1552  lemma (in finite_measure) integral_less_AE:
6.1553    fixes X Y :: "'a \<Rightarrow> real"
6.1554 @@ -2447,7 +2494,7 @@
6.1555      then have "(emeasure M) A \<le> (emeasure M) {x \<in> space M. Y x - X x \<noteq> 0}"
6.1556        using int A by (simp add: integrable_def)
6.1557      ultimately have "emeasure M A = 0"
6.1558 -      using emeasure_nonneg[of M A] by simp
6.1559 +      by simp
6.1560      with \<open>(emeasure M) A \<noteq> 0\<close> show False by auto
6.1561    qed
6.1562    ultimately show ?thesis by auto
6.1563 @@ -2473,7 +2520,7 @@
6.1564      show "AE x in M. (\<lambda>n. indicator {..X n} x *\<^sub>R f x) \<longlonglongrightarrow> f x"
6.1565      proof
6.1566        fix x
6.1567 -      from \<open>filterlim X at_top sequentially\<close>
6.1568 +      from \<open>filterlim X at_top sequentially\<close>
6.1569        have "eventually (\<lambda>n. x \<le> X n) sequentially"
6.1570          unfolding filterlim_at_top_ge[where c=x] by auto
6.1571        then show "(\<lambda>n. indicator {..X n} x *\<^sub>R f x) \<longlonglongrightarrow> f x"
6.1572 @@ -2528,13 +2575,13 @@
6.1573      by (simp cong: measurable_cong)
6.1574  qed
6.1575
6.1576 +lemma Collect_subset [simp]: "{x\<in>A. P x} \<subseteq> A" by auto
6.1577 +
6.1578  lemma (in sigma_finite_measure) measurable_measure[measurable (raw)]:
6.1579    "(\<And>x. x \<in> space N \<Longrightarrow> A x \<subseteq> space M) \<Longrightarrow>
6.1580      {x \<in> space (N \<Otimes>\<^sub>M M). snd x \<in> A (fst x)} \<in> sets (N \<Otimes>\<^sub>M M) \<Longrightarrow>
6.1581      (\<lambda>x. measure M (A x)) \<in> borel_measurable N"
6.1582 -  unfolding measure_def by (intro measurable_emeasure borel_measurable_real_of_ereal)
6.1583 -
6.1584 -lemma Collect_subset [simp]: "{x\<in>A. P x} \<subseteq> A" by auto
6.1585 +  unfolding measure_def by (intro measurable_emeasure borel_measurable_enn2real) auto
6.1586
6.1587  lemma (in sigma_finite_measure) borel_measurable_lebesgue_integral[measurable (raw)]:
6.1588    fixes f :: "_ \<Rightarrow> _ \<Rightarrow> _::{banach, second_countable_topology}"
6.1589 @@ -2593,17 +2640,17 @@
6.1590              using simple_functionD(1)[OF s(1), of i] x
6.1591              by (intro simple_function_borel_measurable)
6.1592                 (auto simp: space_pair_measure dest: finite_subset)
6.1593 -          have "(\<integral>\<^sup>+ y. ereal (norm (s i (x, y))) \<partial>M) \<le> (\<integral>\<^sup>+ y. 2 * norm (f x y) \<partial>M)"
6.1594 +          have "(\<integral>\<^sup>+ y. ennreal (norm (s i (x, y))) \<partial>M) \<le> (\<integral>\<^sup>+ y. 2 * norm (f x y) \<partial>M)"
6.1595              using x s by (intro nn_integral_mono) auto
6.1596            also have "(\<integral>\<^sup>+ y. 2 * norm (f x y) \<partial>M) < \<infinity>"
6.1597              using int_2f by (simp add: integrable_iff_bounded)
6.1598 -          finally show "(\<integral>\<^sup>+ xa. ereal (norm (s i (x, xa))) \<partial>M) < \<infinity>" .
6.1599 +          finally show "(\<integral>\<^sup>+ xa. ennreal (norm (s i (x, xa))) \<partial>M) < \<infinity>" .
6.1600          qed
6.1601          then have "integral\<^sup>L M (\<lambda>y. s i (x, y)) = simple_bochner_integral M (\<lambda>y. s i (x, y))"
6.1602            by (rule simple_bochner_integrable_eq_integral[symmetric]) }
6.1603        ultimately have "(\<lambda>i. simple_bochner_integral M (\<lambda>y. s i (x, y))) \<longlonglongrightarrow> integral\<^sup>L M (f x)"
6.1604          by simp }
6.1605 -    then
6.1606 +    then
6.1607      show "(\<lambda>i. f' i x) \<longlonglongrightarrow> integral\<^sup>L M (f x)"
6.1608        unfolding f'_def
6.1609        by (cases "integrable M (f x)") (simp_all add: not_integrable_integral_eq)
6.1610 @@ -2657,11 +2704,11 @@
6.1611      fix x assume "integrable M2 (\<lambda>y. f (x, y))"
6.1612      then have f: "integrable M2 (\<lambda>y. norm (f (x, y)))"
6.1613        by simp
6.1614 -    then have "(\<integral>\<^sup>+y. ereal (norm (f (x, y))) \<partial>M2) = ereal (LINT y|M2. norm (f (x, y)))"
6.1615 +    then have "(\<integral>\<^sup>+y. ennreal (norm (f (x, y))) \<partial>M2) = ennreal (LINT y|M2. norm (f (x, y)))"
6.1616        by (rule nn_integral_eq_integral) simp
6.1617 -    also have "\<dots> = ereal \<bar>LINT y|M2. norm (f (x, y))\<bar>"
6.1618 -      using f by (auto intro!: abs_of_nonneg[symmetric] integral_nonneg_AE)
6.1619 -    finally show "(\<integral>\<^sup>+y. ereal (norm (f (x, y))) \<partial>M2) = ereal \<bar>LINT y|M2. norm (f (x, y))\<bar>" .
6.1620 +    also have "\<dots> = ennreal \<bar>LINT y|M2. norm (f (x, y))\<bar>"
6.1621 +      using f by simp
6.1622 +    finally show "(\<integral>\<^sup>+y. ennreal (norm (f (x, y))) \<partial>M2) = ennreal \<bar>LINT y|M2. norm (f (x, y))\<bar>" .
6.1623    qed
6.1624    also have "\<dots> < \<infinity>"
6.1625      using integ1 by (simp add: integrable_iff_bounded integral_nonneg_AE)
6.1626 @@ -2679,7 +2726,7 @@
6.1627      by (rule nn_integral_PInf_AE[rotated]) (intro M2.measurable_emeasure_Pair A)
6.1628    moreover have "\<And>x. x \<in> space M1 \<Longrightarrow> Pair x -` A = {y\<in>space M2. (x, y) \<in> A}"
6.1629      using sets.sets_into_space[OF A] by (auto simp: space_pair_measure)
6.1630 -  ultimately show ?thesis by auto
6.1631 +  ultimately show ?thesis by (auto simp: less_top)
6.1632  qed
6.1633
6.1634  lemma (in pair_sigma_finite) AE_integrable_fst':
6.1635 @@ -2696,7 +2743,7 @@
6.1636         (auto simp: measurable_split_conv)
6.1637    with AE_space show ?thesis
6.1638      by eventually_elim
6.1639 -       (auto simp: integrable_iff_bounded measurable_compose[OF _ borel_measurable_integrable[OF f]])
6.1640 +       (auto simp: integrable_iff_bounded measurable_compose[OF _ borel_measurable_integrable[OF f]] less_top)
6.1641  qed
6.1642
6.1643  lemma (in pair_sigma_finite) integrable_fst':
6.1644 @@ -2707,13 +2754,13 @@
6.1645  proof
6.1646    show "(\<lambda>x. \<integral> y. f (x, y) \<partial>M2) \<in> borel_measurable M1"
6.1647      by (rule M2.borel_measurable_lebesgue_integral) simp
6.1648 -  have "(\<integral>\<^sup>+ x. ereal (norm (\<integral> y. f (x, y) \<partial>M2)) \<partial>M1) \<le> (\<integral>\<^sup>+x. (\<integral>\<^sup>+y. norm (f (x, y)) \<partial>M2) \<partial>M1)"
6.1649 -    using AE_integrable_fst'[OF f] by (auto intro!: nn_integral_mono_AE integral_norm_bound_ereal)
6.1650 +  have "(\<integral>\<^sup>+ x. ennreal (norm (\<integral> y. f (x, y) \<partial>M2)) \<partial>M1) \<le> (\<integral>\<^sup>+x. (\<integral>\<^sup>+y. norm (f (x, y)) \<partial>M2) \<partial>M1)"
6.1651 +    using AE_integrable_fst'[OF f] by (auto intro!: nn_integral_mono_AE integral_norm_bound_ennreal)
6.1652    also have "(\<integral>\<^sup>+x. (\<integral>\<^sup>+y. norm (f (x, y)) \<partial>M2) \<partial>M1) = (\<integral>\<^sup>+x. norm (f x) \<partial>(M1 \<Otimes>\<^sub>M M2))"
6.1653      by (rule M2.nn_integral_fst) simp
6.1654    also have "(\<integral>\<^sup>+x. norm (f x) \<partial>(M1 \<Otimes>\<^sub>M M2)) < \<infinity>"
6.1655      using f unfolding integrable_iff_bounded by simp
6.1656 -  finally show "(\<integral>\<^sup>+ x. ereal (norm (\<integral> y. f (x, y) \<partial>M2)) \<partial>M1) < \<infinity>" .
6.1657 +  finally show "(\<integral>\<^sup>+ x. ennreal (norm (\<integral> y. f (x, y) \<partial>M2)) \<partial>M1) < \<infinity>" .
6.1658  qed
6.1659
6.1660  lemma (in pair_sigma_finite) integral_fst':
6.1661 @@ -2738,24 +2785,24 @@
6.1662    qed
6.1663    also have "\<dots> = measure (M1 \<Otimes>\<^sub>M M2) A *\<^sub>R c"
6.1664    proof (subst integral_scaleR_left)
6.1665 -    have "(\<integral>\<^sup>+x. ereal (measure M2 {y \<in> space M2. (x, y) \<in> A}) \<partial>M1) =
6.1666 +    have "(\<integral>\<^sup>+x. ennreal (measure M2 {y \<in> space M2. (x, y) \<in> A}) \<partial>M1) =
6.1667        (\<integral>\<^sup>+x. emeasure M2 {y \<in> space M2. (x, y) \<in> A} \<partial>M1)"
6.1668        using emeasure_pair_measure_finite[OF base]
6.1669 -      by (intro nn_integral_cong_AE, eventually_elim) (simp add: emeasure_eq_ereal_measure)
6.1670 +      by (intro nn_integral_cong_AE, eventually_elim) (simp add: emeasure_eq_ennreal_measure)
6.1671      also have "\<dots> = emeasure (M1 \<Otimes>\<^sub>M M2) A"
6.1672        using sets.sets_into_space[OF A]
6.1673        by (subst M2.emeasure_pair_measure_alt)
6.1674           (auto intro!: nn_integral_cong arg_cong[where f="emeasure M2"] simp: space_pair_measure)
6.1675 -    finally have *: "(\<integral>\<^sup>+x. ereal (measure M2 {y \<in> space M2. (x, y) \<in> A}) \<partial>M1) = emeasure (M1 \<Otimes>\<^sub>M M2) A" .
6.1676 +    finally have *: "(\<integral>\<^sup>+x. ennreal (measure M2 {y \<in> space M2. (x, y) \<in> A}) \<partial>M1) = emeasure (M1 \<Otimes>\<^sub>M M2) A" .
6.1677
6.1678      from base * show "integrable M1 (\<lambda>x. measure M2 {y \<in> space M2. (x, y) \<in> A})"
6.1679 -      by (simp add: measure_nonneg integrable_iff_bounded)
6.1680 -    then have "(\<integral>x. measure M2 {y \<in> space M2. (x, y) \<in> A} \<partial>M1) =
6.1681 -      (\<integral>\<^sup>+x. ereal (measure M2 {y \<in> space M2. (x, y) \<in> A}) \<partial>M1)"
6.1682 -      by (rule nn_integral_eq_integral[symmetric]) (simp add: measure_nonneg)
6.1683 +      by (simp add: integrable_iff_bounded)
6.1684 +    then have "(\<integral>x. measure M2 {y \<in> space M2. (x, y) \<in> A} \<partial>M1) =
6.1685 +      (\<integral>\<^sup>+x. ennreal (measure M2 {y \<in> space M2. (x, y) \<in> A}) \<partial>M1)"
6.1686 +      by (rule nn_integral_eq_integral[symmetric]) simp
6.1687      also note *
6.1688      finally show "(\<integral>x. measure M2 {y \<in> space M2. (x, y) \<in> A} \<partial>M1) *\<^sub>R c = measure (M1 \<Otimes>\<^sub>M M2) A *\<^sub>R c"
6.1689 -      using base by (simp add: emeasure_eq_ereal_measure)
6.1690 +      using base by (simp add: emeasure_eq_ennreal_measure)
6.1691    qed
6.1692    also have "\<dots> = (\<integral> a. indicator A a *\<^sub>R c \<partial>(M1 \<Otimes>\<^sub>M M2))"
6.1693      using base by simp
6.1694 @@ -2764,14 +2811,14 @@
6.1696    then have [measurable]: "f \<in> borel_measurable (M1 \<Otimes>\<^sub>M M2)" "g \<in> borel_measurable (M1 \<Otimes>\<^sub>M M2)"
6.1697      by auto
6.1698 -  have "(\<integral> x. \<integral> y. f (x, y) + g (x, y) \<partial>M2 \<partial>M1) =
6.1699 +  have "(\<integral> x. \<integral> y. f (x, y) + g (x, y) \<partial>M2 \<partial>M1) =
6.1700      (\<integral> x. (\<integral> y. f (x, y) \<partial>M2) + (\<integral> y. g (x, y) \<partial>M2) \<partial>M1)"
6.1701      apply (rule integral_cong_AE)
6.1702      apply simp_all
6.1704      apply eventually_elim
6.1705      apply simp
6.1706 -    done
6.1707 +    done
6.1708    also have "\<dots> = (\<integral> x. f x \<partial>(M1 \<Otimes>\<^sub>M M2)) + (\<integral> x. g x \<partial>(M1 \<Otimes>\<^sub>M M2))"
6.1710    finally show ?case
6.1711 @@ -2780,7 +2827,7 @@
6.1712    case (lim f s)
6.1713    then have [measurable]: "f \<in> borel_measurable (M1 \<Otimes>\<^sub>M M2)" "\<And>i. s i \<in> borel_measurable (M1 \<Otimes>\<^sub>M M2)"
6.1714      by auto
6.1715 -
6.1716 +
6.1717    show ?case
6.1718    proof (rule LIMSEQ_unique)
6.1719      show "(\<lambda>i. integral\<^sup>L (M1 \<Otimes>\<^sub>M M2) (s i)) \<longlonglongrightarrow> integral\<^sup>L (M1 \<Otimes>\<^sub>M M2) f"
6.1720 @@ -2811,11 +2858,11 @@
6.1721          by (intro integrable_mult_right integrable_norm integrable_fst' lim)
6.1722        fix i show "AE x in M1. norm (\<integral> y. s i (x, y) \<partial>M2) \<le> (\<integral> y. 2 * norm (f (x, y)) \<partial>M2)"
6.1723          using AE_space AE_integrable_fst'[OF lim(1), of i] AE_integrable_fst'[OF lim(5)]
6.1724 -      proof eventually_elim
6.1725 +      proof eventually_elim
6.1726          fix x assume x: "x \<in> space M1"
6.1727            and s: "integrable M2 (\<lambda>y. s i (x, y))" and f: "integrable M2 (\<lambda>y. f (x, y))"
6.1728          from s have "norm (\<integral> y. s i (x, y) \<partial>M2) \<le> (\<integral>\<^sup>+y. norm (s i (x, y)) \<partial>M2)"
6.1729 -          by (rule integral_norm_bound_ereal)
6.1730 +          by (rule integral_norm_bound_ennreal)
6.1731          also have "\<dots> \<le> (\<integral>\<^sup>+y. 2 * norm (f (x, y)) \<partial>M2)"
6.1732            using x lim by (auto intro!: nn_integral_mono simp: space_pair_measure)
6.1733          also have "\<dots> = (\<integral>y. 2 * norm (f (x, y)) \<partial>M2)"
6.1734 @@ -2927,14 +2974,14 @@
6.1735
6.1736    show "?f \<in> borel_measurable (Pi\<^sub>M I M)"
6.1737      using assms by simp
6.1738 -  have "(\<integral>\<^sup>+ x. ereal (norm (\<Prod>i\<in>I. f i (x i))) \<partial>Pi\<^sub>M I M) =
6.1739 -      (\<integral>\<^sup>+ x. (\<Prod>i\<in>I. ereal (norm (f i (x i)))) \<partial>Pi\<^sub>M I M)"
6.1740 -    by (simp add: setprod_norm setprod_ereal)
6.1741 -  also have "\<dots> = (\<Prod>i\<in>I. \<integral>\<^sup>+ x. ereal (norm (f i x)) \<partial>M i)"
6.1742 +  have "(\<integral>\<^sup>+ x. ennreal (norm (\<Prod>i\<in>I. f i (x i))) \<partial>Pi\<^sub>M I M) =
6.1743 +      (\<integral>\<^sup>+ x. (\<Prod>i\<in>I. ennreal (norm (f i (x i)))) \<partial>Pi\<^sub>M I M)"
6.1744 +    by (simp add: setprod_norm setprod_ennreal)
6.1745 +  also have "\<dots> = (\<Prod>i\<in>I. \<integral>\<^sup>+ x. ennreal (norm (f i x)) \<partial>M i)"
6.1746      using assms by (intro product_nn_integral_setprod) auto
6.1747    also have "\<dots> < \<infinity>"
6.1748 -    using integrable by (simp add: setprod_PInf nn_integral_nonneg integrable_iff_bounded)
6.1749 -  finally show "(\<integral>\<^sup>+ x. ereal (norm (\<Prod>i\<in>I. f i (x i))) \<partial>Pi\<^sub>M I M) < \<infinity>" .
6.1750 +    using integrable by (simp add: less_top[symmetric] ennreal_setprod_eq_top integrable_iff_bounded)
6.1751 +  finally show "(\<integral>\<^sup>+ x. ennreal (norm (\<Prod>i\<in>I. f i (x i))) \<partial>Pi\<^sub>M I M) < \<infinity>" .
6.1752  qed
6.1753
6.1754  lemma (in product_sigma_finite) product_integral_setprod:
6.1755 @@ -3010,8 +3057,7 @@
6.1756    qed
6.1757  qed (simp add: not_integrable_integral_eq integrable_subalgebra[OF assms])
6.1758
6.1759 -hide_const simple_bochner_integral
6.1760 -hide_const simple_bochner_integrable
6.1761 +hide_const (open) simple_bochner_integral
6.1762 +hide_const (open) simple_bochner_integrable
6.1763
6.1764  end
6.1765 -
```
```     7.1 --- a/src/HOL/Probability/Borel_Space.thy	Thu Apr 14 12:17:44 2016 +0200
7.2 +++ b/src/HOL/Probability/Borel_Space.thy	Thu Apr 14 15:48:11 2016 +0200
7.3 @@ -435,6 +435,14 @@
7.4    by (subst measurable_restrict_space_iff)
7.5       (auto simp: indicator_def if_distrib[where f="\<lambda>x. a * x" for a] cong del: if_cong)
7.6
7.7 +lemma borel_measurable_restrict_space_iff_ennreal:
7.8 +  fixes f :: "'a \<Rightarrow> ennreal"
7.9 +  assumes \<Omega>[measurable, simp]: "\<Omega> \<inter> space M \<in> sets M"
7.10 +  shows "f \<in> borel_measurable (restrict_space M \<Omega>) \<longleftrightarrow>
7.11 +    (\<lambda>x. f x * indicator \<Omega> x) \<in> borel_measurable M"
7.12 +  by (subst measurable_restrict_space_iff)
7.13 +     (auto simp: indicator_def if_distrib[where f="\<lambda>x. a * x" for a] cong del: if_cong)
7.14 +
7.15  lemma borel_measurable_restrict_space_iff:
7.16    fixes f :: "'a \<Rightarrow> 'b::real_normed_vector"
7.17    assumes \<Omega>[measurable, simp]: "\<Omega> \<inter> space M \<in> sets M"
7.18 @@ -1639,12 +1647,6 @@
7.19    from assms show ?thesis unfolding * by simp
7.20  qed
7.21
7.22 -lemma
7.23 -  fixes f :: "'a \<Rightarrow> ereal" assumes f: "f \<in> borel_measurable M"
7.24 -  shows borel_measurable_ereal_eq_const: "{x\<in>space M. f x = c} \<in> sets M"
7.25 -    and borel_measurable_ereal_neq_const: "{x\<in>space M. f x \<noteq> c} \<in> sets M"
7.26 -  using f by auto
7.27 -
7.28  lemma [measurable(raw)]:
7.29    fixes f :: "'a \<Rightarrow> ereal"
7.30    assumes [measurable]: "f \<in> borel_measurable M" "g \<in> borel_measurable M"
7.31 @@ -1689,6 +1691,10 @@
7.32  lemma measurable_e2ennreal[measurable]: "e2ennreal \<in> borel \<rightarrow>\<^sub>M borel"
7.33    by (intro borel_measurable_continuous_on1 continuous_on_e2ennreal)
7.34
7.35 +lemma borel_measurable_enn2real[measurable (raw)]:
7.36 +  "f \<in> M \<rightarrow>\<^sub>M borel \<Longrightarrow> (\<lambda>x. enn2real (f x)) \<in> M \<rightarrow>\<^sub>M borel"
7.37 +  unfolding enn2real_def[abs_def] by measurable
7.38 +
7.39  definition [simp]: "is_borel f M \<longleftrightarrow> f \<in> borel_measurable M"
7.40
7.41  lemma is_borel_transfer[transfer_rule]: "rel_fun (rel_fun op = pcr_ennreal) op = is_borel is_borel"
7.42 @@ -1699,8 +1705,24 @@
7.43      using measurable_compose[OF f measurable_e2ennreal] by simp
7.44  qed simp
7.45
7.46 +context
7.47 +  includes ennreal.lifting
7.48 +begin
7.49 +
7.50  lemma measurable_ennreal[measurable]: "ennreal \<in> borel \<rightarrow>\<^sub>M borel"
7.51 -  unfolding is_borel_def[symmetric] by transfer simp
7.52 +  unfolding is_borel_def[symmetric]
7.53 +  by transfer simp
7.54 +
7.55 +lemma borel_measurable_ennreal_iff[simp]:
7.56 +  assumes [simp]: "\<And>x. x \<in> space M \<Longrightarrow> 0 \<le> f x"
7.57 +  shows "(\<lambda>x. ennreal (f x)) \<in> M \<rightarrow>\<^sub>M borel \<longleftrightarrow> f \<in> M \<rightarrow>\<^sub>M borel"
7.58 +proof safe
7.59 +  assume "(\<lambda>x. ennreal (f x)) \<in> M \<rightarrow>\<^sub>M borel"
7.60 +  then have "(\<lambda>x. enn2real (ennreal (f x))) \<in> M \<rightarrow>\<^sub>M borel"
7.61 +    by measurable
7.62 +  then show "f \<in> M \<rightarrow>\<^sub>M borel"
7.63 +    by (rule measurable_cong[THEN iffD1, rotated]) auto
7.64 +qed measurable
7.65
7.66  lemma borel_measurable_times_ennreal[measurable (raw)]:
7.67    fixes f g :: "'a \<Rightarrow> ennreal"
7.68 @@ -1728,6 +1750,8 @@
7.69    shows "(\<lambda>x. \<Prod>i\<in>S. f i x) \<in> borel_measurable M"
7.70    using assms by (induction S rule: infinite_finite_induct) auto
7.71
7.72 +end
7.73 +
7.74  hide_const (open) is_borel
7.75
7.76  subsection \<open>LIMSEQ is borel measurable\<close>
```
```     8.1 --- a/src/HOL/Probability/Caratheodory.thy	Thu Apr 14 12:17:44 2016 +0200
8.2 +++ b/src/HOL/Probability/Caratheodory.thy	Thu Apr 14 15:48:11 2016 +0200
8.3 @@ -13,9 +13,8 @@
8.4    Originally from the Hurd/Coble measure theory development, translated by Lawrence Paulson.
8.5  \<close>
8.6
8.7 -lemma suminf_ereal_2dimen:
8.8 -  fixes f:: "nat \<times> nat \<Rightarrow> ereal"
8.9 -  assumes pos: "\<And>p. 0 \<le> f p"
8.10 +lemma suminf_ennreal_2dimen:
8.11 +  fixes f:: "nat \<times> nat \<Rightarrow> ennreal"
8.12    assumes "\<And>m. g m = (\<Sum>n. f (m,n))"
8.13    shows "(\<Sum>i. f (prod_decode i)) = suminf g"
8.14  proof -
8.15 @@ -23,46 +22,42 @@
8.16      using assms by (simp add: fun_eq_iff)
8.17    have reindex: "\<And>B. (\<Sum>x\<in>B. f (prod_decode x)) = setsum f (prod_decode ` B)"
8.18      by (simp add: setsum.reindex[OF inj_prod_decode] comp_def)
8.19 -  { fix n
8.20 +  have "(SUP n. \<Sum>i<n. f (prod_decode i)) = (SUP p : UNIV \<times> UNIV. \<Sum>i<fst p. \<Sum>n<snd p. f (i, n))"
8.21 +  proof (intro SUP_eq; clarsimp simp: setsum.cartesian_product reindex)
8.22 +    fix n
8.23      let ?M = "\<lambda>f. Suc (Max (f ` prod_decode ` {..<n}))"
8.24      { fix a b x assume "x < n" and [symmetric]: "(a, b) = prod_decode x"
8.25        then have "a < ?M fst" "b < ?M snd"
8.26          by (auto intro!: Max_ge le_imp_less_Suc image_eqI) }
8.27      then have "setsum f (prod_decode ` {..<n}) \<le> setsum f ({..<?M fst} \<times> {..<?M snd})"
8.28 -      by (auto intro!: setsum_mono3 simp: pos)
8.29 -    then have "\<exists>a b. setsum f (prod_decode ` {..<n}) \<le> setsum f ({..<a} \<times> {..<b})" by auto }
8.30 -  moreover
8.31 -  { fix a b
8.32 +      by (auto intro!: setsum_mono3)
8.33 +    then show "\<exists>a b. setsum f (prod_decode ` {..<n}) \<le> setsum f ({..<a} \<times> {..<b})" by auto
8.34 +  next
8.35 +    fix a b
8.36      let ?M = "prod_decode ` {..<Suc (Max (prod_encode ` ({..<a} \<times> {..<b})))}"
8.37      { fix a' b' assume "a' < a" "b' < b" then have "(a', b') \<in> ?M"
8.38          by (auto intro!: Max_ge le_imp_less_Suc image_eqI[where x="prod_encode (a', b')"]) }
8.39      then have "setsum f ({..<a} \<times> {..<b}) \<le> setsum f ?M"
8.40 -      by (auto intro!: setsum_mono3 simp: pos) }
8.41 -  ultimately
8.42 -  show ?thesis unfolding g_def using pos
8.43 -    by (auto intro!: SUP_eq  simp: setsum.cartesian_product reindex SUP_upper2
8.44 -                     suminf_ereal_eq_SUP SUP_pair
8.45 -                     SUP_ereal_setsum[symmetric] incseq_setsumI setsum_nonneg)
8.46 +      by (auto intro!: setsum_mono3)
8.47 +    then show "\<exists>n. setsum f ({..<a} \<times> {..<b}) \<le> setsum f (prod_decode ` {..<n})"
8.48 +      by auto
8.49 +  qed
8.50 +  also have "\<dots> = (SUP p. \<Sum>i<p. \<Sum>n. f (i, n))"
8.51 +    unfolding suminf_setsum[OF summableI, symmetric]
8.52 +    by (simp add: suminf_eq_SUP SUP_pair setsum.commute[of _ "{..< fst _}"])
8.53 +  finally show ?thesis unfolding g_def
8.54 +    by (simp add: suminf_eq_SUP)
8.55  qed
8.56
8.57  subsection \<open>Characterizations of Measures\<close>
8.58
8.60 -  "subadditive M f \<longleftrightarrow> (\<forall>x\<in>M. \<forall>y\<in>M. x \<inter> y = {} \<longrightarrow> f (x \<union> y) \<le> f x + f y)"
8.61 -
8.63 -  "countably_subadditive M f \<longleftrightarrow>
8.64 -    (\<forall>A. range A \<subseteq> M \<longrightarrow> disjoint_family A \<longrightarrow> (\<Union>i. A i) \<in> M \<longrightarrow> (f (\<Union>i. A i) \<le> (\<Sum>i. f (A i))))"
8.65 -
8.66  definition outer_measure_space where
8.67    "outer_measure_space M f \<longleftrightarrow> positive M f \<and> increasing M f \<and> countably_subadditive M f"
8.68
8.69 -lemma subadditiveD: "subadditive M f \<Longrightarrow> x \<inter> y = {} \<Longrightarrow> x \<in> M \<Longrightarrow> y \<in> M \<Longrightarrow> f (x \<union> y) \<le> f x + f y"
8.71 -
8.72  subsubsection \<open>Lambda Systems\<close>
8.73
8.74 -definition lambda_system where
8.75 +definition lambda_system :: "'a set \<Rightarrow> 'a set set \<Rightarrow> ('a set \<Rightarrow> ennreal) \<Rightarrow> 'a set set"
8.76 +where
8.77    "lambda_system \<Omega> M f = {l \<in> M. \<forall>x \<in> M. f (l \<inter> x) + f ((\<Omega> - l) \<inter> x) = f x}"
8.78
8.79  lemma (in algebra) lambda_system_eq:
8.80 @@ -81,7 +76,7 @@
8.82
8.83  lemma (in algebra) lambda_system_Compl:
8.84 -  fixes f:: "'a set \<Rightarrow> ereal"
8.85 +  fixes f:: "'a set \<Rightarrow> ennreal"
8.86    assumes x: "x \<in> lambda_system \<Omega> M f"
8.87    shows "\<Omega> - x \<in> lambda_system \<Omega> M f"
8.88  proof -
8.89 @@ -94,7 +89,7 @@
8.90  qed
8.91
8.92  lemma (in algebra) lambda_system_Int:
8.93 -  fixes f:: "'a set \<Rightarrow> ereal"
8.94 +  fixes f:: "'a set \<Rightarrow> ennreal"
8.95    assumes xl: "x \<in> lambda_system \<Omega> M f" and yl: "y \<in> lambda_system \<Omega> M f"
8.96    shows "x \<inter> y \<in> lambda_system \<Omega> M f"
8.97  proof -
8.98 @@ -128,7 +123,7 @@
8.99  qed
8.100
8.101  lemma (in algebra) lambda_system_Un:
8.102 -  fixes f:: "'a set \<Rightarrow> ereal"
8.103 +  fixes f:: "'a set \<Rightarrow> ennreal"
8.104    assumes xl: "x \<in> lambda_system \<Omega> M f" and yl: "y \<in> lambda_system \<Omega> M f"
8.105    shows "x \<union> y \<in> lambda_system \<Omega> M f"
8.106  proof -
8.107 @@ -176,25 +171,6 @@
8.109  qed
8.110
8.112 -  assumes f: "positive M f" and cs: "countably_subadditive M f"
8.113 -  shows  "subadditive M f"
8.115 -  fix x y
8.116 -  assume x: "x \<in> M" and y: "y \<in> M" and "x \<inter> y = {}"
8.117 -  hence "disjoint_family (binaryset x y)"
8.118 -    by (auto simp add: disjoint_family_on_def binaryset_def)
8.119 -  hence "range (binaryset x y) \<subseteq> M \<longrightarrow>
8.120 -         (\<Union>i. binaryset x y i) \<in> M \<longrightarrow>
8.121 -         f (\<Union>i. binaryset x y i) \<le> (\<Sum> n. f (binaryset x y n))"
8.123 -  hence "{x,y,{}} \<subseteq> M \<longrightarrow> x \<union> y \<in> M \<longrightarrow>
8.124 -         f (x \<union> y) \<le> (\<Sum> n. f (binaryset x y n))"
8.125 -    by (simp add: range_binaryset_eq UN_binaryset_eq)
8.126 -  thus "f (x \<union> y) \<le>  f x + f y" using f x y
8.127 -    by (auto simp add: Un o_def suminf_binaryset_eq positive_def)
8.128 -qed
8.129 -
8.130  lemma lambda_system_increasing: "increasing M f \<Longrightarrow> increasing (lambda_system \<Omega> M f) f"
8.131    by (simp add: increasing_def lambda_system_def)
8.132
8.133 @@ -202,7 +178,7 @@
8.134    by (simp add: positive_def lambda_system_def)
8.135
8.136  lemma (in algebra) lambda_system_strong_sum:
8.137 -  fixes A:: "nat \<Rightarrow> 'a set" and f :: "'a set \<Rightarrow> ereal"
8.138 +  fixes A:: "nat \<Rightarrow> 'a set" and f :: "'a set \<Rightarrow> ennreal"
8.139    assumes f: "positive M f" and a: "a \<in> M"
8.140        and A: "range A \<subseteq> lambda_system \<Omega> M f"
8.141        and disj: "disjoint_family A"
8.142 @@ -247,11 +223,10 @@
8.143    proof (rule antisym)
8.144      show "f (\<Union>i. A i) \<le> (\<Sum>i. f (A i))"
8.145        using csa[unfolded countably_subadditive_def] A'' disj U_in by auto
8.146 -    have *: "\<And>i. 0 \<le> f (A i)" using pos A'' unfolding positive_def by auto
8.147      have dis: "\<And>N. disjoint_family_on A {..<N}" by (intro disjoint_family_on_mono[OF _ disj]) auto
8.148      show "(\<Sum>i. f (A i)) \<le> f (\<Union>i. A i)"
8.150 -      by (intro suminf_bound[OF _ *]) (auto intro!: increasingD[OF inc] countable_UN)
8.151 +      by (intro suminf_le_const[OF summableI]) (auto intro!: increasingD[OF inc] countable_UN)
8.152    qed
8.153    have "f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i)) = f a"
8.154      if a [iff]: "a \<in> M" for a
8.155 @@ -271,7 +246,7 @@
8.156      hence "f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i)) \<le> (\<Sum>i. f (a \<inter> A i)) + f (a - (\<Union>i. A i))"
8.158      also have "\<dots> \<le> f a"
8.159 -    proof (intro suminf_bound_add allI)
8.161        fix n
8.162        have UNION_in: "(\<Union>i\<in>{0..<n}. A i) \<in> M"
8.163          by (metis A'' UNION_in_sets)
8.164 @@ -285,14 +260,9 @@
8.165          by (blast intro: increasingD [OF inc] UNION_in U_in)
8.166        thus "(\<Sum>i<n. f (a \<inter> A i)) + f (a - (\<Union>i. A i)) \<le> f a"
8.168 -    next
8.169 -      have "\<And>i. a \<inter> A i \<in> M" using A'' by auto
8.170 -      then show "\<And>i. 0 \<le> f (a \<inter> A i)" using pos[unfolded positive_def] by auto
8.171 -      have "\<And>i. a - (\<Union>i. A i) \<in> M" using A'' by auto
8.172 -      then have "\<And>i. 0 \<le> f (a - (\<Union>i. A i))" using pos[unfolded positive_def] by auto
8.173 -      then show "f (a - (\<Union>i. A i)) \<noteq> -\<infinity>" by auto
8.174      qed
8.175 -    finally show "f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i)) \<le> f a" .
8.176 +    finally show "f (a \<inter> (\<Union>i. A i)) + f (a - (\<Union>i. A i)) \<le> f a"
8.177 +      by simp
8.178    next
8.179      have "f a \<le> f (a \<inter> (\<Union>i. A i) \<union> (a - (\<Union>i. A i)))"
8.180        by (blast intro:  increasingD [OF inc] U_in)
8.181 @@ -327,7 +297,7 @@
8.182      using pos by (simp add: measure_space_def)
8.183  qed
8.184
8.185 -definition outer_measure :: "'a set set \<Rightarrow> ('a set \<Rightarrow> ereal) \<Rightarrow> 'a set \<Rightarrow> ereal" where
8.186 +definition outer_measure :: "'a set set \<Rightarrow> ('a set \<Rightarrow> ennreal) \<Rightarrow> 'a set \<Rightarrow> ennreal" where
8.187     "outer_measure M f X =
8.188       (INF A:{A. range A \<subseteq> M \<and> disjoint_family A \<and> X \<subseteq> (\<Union>i. A i)}. \<Sum>i. f (A i))"
8.189
8.190 @@ -346,7 +316,7 @@
8.191      by (intro ca[unfolded countably_additive_def, rule_format, symmetric])
8.192         (auto simp: Int_absorb1 disjoint_family_on_def)
8.193    also have "... \<le> (\<Sum>i. f (A i))"
8.194 -    using A s by (intro suminf_le_pos increasingD[OF inc] positiveD2[OF posf]) auto
8.195 +    using A s by (auto intro!: suminf_le increasingD[OF inc])
8.196    finally show "f s \<le> (\<Sum>i. f (A i))" .
8.197  next
8.198    have "(\<Sum>i. f (if i = 0 then s else {})) \<le> f s"
8.199 @@ -356,20 +326,14 @@
8.200         (auto simp: disjoint_family_on_def)
8.201  qed
8.202
8.203 -lemma outer_measure_nonneg: "positive M f \<Longrightarrow> 0 \<le> outer_measure M f X"
8.204 -  by (auto intro!: INF_greatest suminf_0_le intro: positiveD2 simp: outer_measure_def)
8.205 -
8.206  lemma outer_measure_empty:
8.207 -  assumes posf: "positive M f" and "{} \<in> M"
8.208 -  shows "outer_measure M f {} = 0"
8.209 -proof (rule antisym)
8.210 -  show "outer_measure M f {} \<le> 0"
8.211 -    using assms by (auto intro!: INF_lower2[of "\<lambda>_. {}"] simp: outer_measure_def disjoint_family_on_def positive_def)
8.212 -qed (intro outer_measure_nonneg posf)
8.213 +  "positive M f \<Longrightarrow> {} \<in> M \<Longrightarrow> outer_measure M f {} = 0"
8.214 +  unfolding outer_measure_def
8.215 +  by (intro antisym INF_lower2[of  "\<lambda>_. {}"]) (auto simp: disjoint_family_on_def positive_def)
8.216
8.217  lemma (in ring_of_sets) positive_outer_measure:
8.218    assumes "positive M f" shows "positive (Pow \<Omega>) (outer_measure M f)"
8.219 -  unfolding positive_def by (auto simp: assms outer_measure_empty outer_measure_nonneg)
8.220 +  unfolding positive_def by (auto simp: assms outer_measure_empty)
8.221
8.222  lemma (in ring_of_sets) increasing_outer_measure: "increasing (Pow \<Omega>) (outer_measure M f)"
8.223    by (force simp: increasing_def outer_measure_def intro!: INF_greatest intro: INF_lower)
8.224 @@ -383,22 +347,13 @@
8.225      by (auto intro!: A range_disjointed_sets)
8.226    have "\<forall>n. f (disjointed A n) \<le> f (A n)"
8.227      by (metis increasingD [OF inc] UNIV_I dA image_subset_iff disjointed_subset A)
8.228 -  moreover have "\<forall>i. 0 \<le> f (disjointed A i)"
8.229 -    using pos dA unfolding positive_def by auto
8.230 -  ultimately show "(\<Sum>i. f (disjointed A i)) \<le> (\<Sum>i. f (A i))"
8.231 -    by (blast intro!: suminf_le_pos)
8.232 +  then show "(\<Sum>i. f (disjointed A i)) \<le> (\<Sum>i. f (A i))"
8.233 +    by (blast intro!: suminf_le)
8.234  qed (auto simp: X UN_disjointed_eq disjoint_family_disjointed)
8.235
8.236  lemma (in ring_of_sets) outer_measure_close:
8.237 -  assumes posf: "positive M f" and "0 < e" and "outer_measure M f X \<noteq> \<infinity>"
8.238 -  shows "\<exists>A. range A \<subseteq> M \<and> disjoint_family A \<and> X \<subseteq> (\<Union>i. A i) \<and> (\<Sum>i. f (A i)) \<le> outer_measure M f X + e"
8.239 -proof -
8.240 -  from \<open>outer_measure M f X \<noteq> \<infinity>\<close> have fin: "\<bar>outer_measure M f X\<bar> \<noteq> \<infinity>"
8.241 -    using outer_measure_nonneg[OF posf, of X] by auto
8.242 -  show ?thesis
8.243 -    using Inf_ereal_close [OF fin [unfolded outer_measure_def], OF \<open>0 < e\<close>]
8.244 -    by (auto intro: less_imp_le simp add: outer_measure_def)
8.245 -qed
8.246 +  "outer_measure M f X < e \<Longrightarrow> \<exists>A. range A \<subseteq> M \<and> disjoint_family A \<and> X \<subseteq> (\<Union>i. A i) \<and> (\<Sum>i. f (A i)) < e"
8.247 +  unfolding outer_measure_def INF_less_iff by auto
8.248
8.250    assumes posf: "positive M f" and inc: "increasing M f"
8.251 @@ -406,16 +361,16 @@
8.253    fix A :: "nat \<Rightarrow> _" assume A: "range A \<subseteq> Pow (\<Omega>)" and sb: "(\<Union>i. A i) \<subseteq> \<Omega>"
8.254    let ?O = "outer_measure M f"
8.255 -
8.256 -  { fix e :: ereal assume e: "0 < e" and "\<forall>i. ?O (A i) \<noteq> \<infinity>"
8.257 -    hence "\<exists>B. \<forall>n. range (B n) \<subseteq> M \<and> disjoint_family (B n) \<and> A n \<subseteq> (\<Union>i. B n i) \<and>
8.258 -        (\<Sum>i. f (B n i)) \<le> ?O (A n) + e * (1/2)^(Suc n)"
8.259 -      using e sb by (auto intro!: choice outer_measure_close [of f, OF posf] simp: ereal_zero_less_0_iff one_ereal_def)
8.260 -    then obtain B
8.261 +  show "?O (\<Union>i. A i) \<le> (\<Sum>n. ?O (A n))"
8.262 +  proof (rule ennreal_le_epsilon)
8.263 +    fix b and e :: real assume "0 < e" "(\<Sum>n. outer_measure M f (A n)) < top"
8.264 +    then have *: "\<And>n. outer_measure M f (A n) < outer_measure M f (A n) + e * (1/2)^Suc n"
8.265 +      by (auto simp add: less_top dest!: ennreal_suminf_lessD)
8.266 +    obtain B
8.267        where B: "\<And>n. range (B n) \<subseteq> M"
8.268        and sbB: "\<And>n. A n \<subseteq> (\<Union>i. B n i)"
8.269        and Ble: "\<And>n. (\<Sum>i. f (B n i)) \<le> ?O (A n) + e * (1/2)^(Suc n)"
8.270 -      by auto blast
8.271 +      by (metis less_imp_le outer_measure_close[OF *])
8.272
8.273      def C \<equiv> "case_prod B o prod_decode"
8.274      from B have B_in_M: "\<And>i j. B i j \<in> M"
8.275 @@ -425,26 +380,22 @@
8.276      have A_C: "(\<Union>i. A i) \<subseteq> (\<Union>i. C i)"
8.277        using sbB by (auto simp add: C_def subset_eq) (metis prod.case prod_encode_inverse)
8.278
8.279 -    have "?O (\<Union>i. A i) \<le> ?O (\<Union>i. C i)"
8.280 +    have "?O (\<Union>i. A i) \<le> ?O (\<Union>i. C i)"
8.281        using A_C A C by (intro increasing_outer_measure[THEN increasingD]) (auto dest!: sets_into_space)
8.282      also have "\<dots> \<le> (\<Sum>i. f (C i))"
8.283        using C by (intro outer_measure_le[OF posf inc]) auto
8.284      also have "\<dots> = (\<Sum>n. \<Sum>i. f (B n i))"
8.285 -      using B_in_M unfolding C_def comp_def by (intro suminf_ereal_2dimen positiveD2[OF posf]) auto
8.286 -    also have "\<dots> \<le> (\<Sum>n. ?O (A n) + e*(1/2) ^ Suc n)"
8.287 -      using B_in_M by (intro suminf_le_pos[OF Ble] suminf_0_le posf[THEN positiveD2]) auto
8.288 -    also have "... = (\<Sum>n. ?O (A n)) + (\<Sum>n. e*(1/2) ^ Suc n)"
8.289 -      using e by (subst suminf_add_ereal) (auto simp add: ereal_zero_le_0_iff outer_measure_nonneg posf)
8.290 -    also have "(\<Sum>n. e*(1/2) ^ Suc n) = e"
8.291 -      using suminf_half_series_ereal e by (simp add: ereal_zero_le_0_iff suminf_cmult_ereal)
8.292 -    finally have "?O (\<Union>i. A i) \<le> (\<Sum>n. ?O (A n)) + e" . }
8.293 -  note * = this
8.294 -
8.295 -  show "?O (\<Union>i. A i) \<le> (\<Sum>n. ?O (A n))"
8.296 -  proof cases
8.297 -    assume "\<forall>i. ?O (A i) \<noteq> \<infinity>" with * show ?thesis
8.298 -      by (intro ereal_le_epsilon) auto
8.299 -  qed (metis suminf_PInfty[OF outer_measure_nonneg, OF posf] ereal_less_eq(1))
8.300 +      using B_in_M unfolding C_def comp_def by (intro suminf_ennreal_2dimen) auto
8.301 +    also have "\<dots> \<le> (\<Sum>n. ?O (A n) + e * (1/2) ^ Suc n)"
8.302 +      using B_in_M by (intro suminf_le suminf_nonneg allI Ble) auto
8.303 +    also have "... = (\<Sum>n. ?O (A n)) + (\<Sum>n. ennreal e * ennreal ((1/2) ^ Suc n))"
8.304 +      using \<open>0 < e\<close> by (subst suminf_add[symmetric])
8.305 +                       (auto simp del: ennreal_suminf_cmult simp add: ennreal_mult[symmetric])
8.306 +    also have "\<dots> = (\<Sum>n. ?O (A n)) + e"
8.307 +      unfolding ennreal_suminf_cmult
8.308 +      by (subst suminf_ennreal_eq[OF zero_le_power power_half_series]) auto
8.309 +    finally show "?O (\<Union>i. A i) \<le> (\<Sum>n. ?O (A n)) + e" .
8.310 +  qed
8.311  qed
8.312
8.313  lemma (in ring_of_sets) outer_measure_space_outer_measure:
8.314 @@ -481,7 +432,7 @@
8.315      ultimately have "outer_measure M f (s \<inter> x) + outer_measure M f (s - x) \<le>
8.316          (\<Sum>i. f (A i \<inter> x)) + (\<Sum>i. f (A i - x))" by (rule add_mono)
8.317      also have "\<dots> = (\<Sum>i. f (A i \<inter> x) + f (A i - x))"
8.318 -      using A(2) x posf by (subst suminf_add_ereal) (auto simp: positive_def)
8.319 +      using A(2) x posf by (subst suminf_add) (auto simp: positive_def)
8.320      also have "\<dots> = (\<Sum>i. f (A i))"
8.321        using A x
8.323 @@ -496,7 +447,7 @@
8.324      also have "... \<le> outer_measure M f (s \<inter> x) + outer_measure M f (s - x)"
8.327 -      apply (simp add: positive_def outer_measure_empty[OF posf] outer_measure_nonneg[OF posf])
8.328 +      apply (simp add: positive_def outer_measure_empty[OF posf])
8.330        using s by (auto intro!: posf inc)
8.331      finally show ?thesis .
8.332 @@ -513,7 +464,7 @@
8.333
8.334  theorem (in ring_of_sets) caratheodory':
8.335    assumes posf: "positive M f" and ca: "countably_additive M f"
8.336 -  shows "\<exists>\<mu> :: 'a set \<Rightarrow> ereal. (\<forall>s \<in> M. \<mu> s = f s) \<and> measure_space \<Omega> (sigma_sets \<Omega> M) \<mu>"
8.337 +  shows "\<exists>\<mu> :: 'a set \<Rightarrow> ennreal. (\<forall>s \<in> M. \<mu> s = f s) \<and> measure_space \<Omega> (sigma_sets \<Omega> M) \<mu>"
8.338  proof -
8.339    have inc: "increasing M f"
8.341 @@ -541,14 +492,14 @@
8.342  lemma (in ring_of_sets) caratheodory_empty_continuous:
8.343    assumes f: "positive M f" "additive M f" and fin: "\<And>A. A \<in> M \<Longrightarrow> f A \<noteq> \<infinity>"
8.344    assumes cont: "\<And>A. range A \<subseteq> M \<Longrightarrow> decseq A \<Longrightarrow> (\<Inter>i. A i) = {} \<Longrightarrow> (\<lambda>i. f (A i)) \<longlonglongrightarrow> 0"
8.345 -  shows "\<exists>\<mu> :: 'a set \<Rightarrow> ereal. (\<forall>s \<in> M. \<mu> s = f s) \<and> measure_space \<Omega> (sigma_sets \<Omega> M) \<mu>"
8.346 +  shows "\<exists>\<mu> :: 'a set \<Rightarrow> ennreal. (\<forall>s \<in> M. \<mu> s = f s) \<and> measure_space \<Omega> (sigma_sets \<Omega> M) \<mu>"
8.347  proof (intro caratheodory' empty_continuous_imp_countably_additive f)
8.348    show "\<forall>A\<in>M. f A \<noteq> \<infinity>" using fin by auto
8.349  qed (rule cont)
8.350
8.351  subsection \<open>Volumes\<close>
8.352
8.353 -definition volume :: "'a set set \<Rightarrow> ('a set \<Rightarrow> ereal) \<Rightarrow> bool" where
8.354 +definition volume :: "'a set set \<Rightarrow> ('a set \<Rightarrow> ennreal) \<Rightarrow> bool" where
8.355    "volume M f \<longleftrightarrow>
8.356    (f {} = 0) \<and> (\<forall>a\<in>M. 0 \<le> f a) \<and>
8.357    (\<forall>C\<subseteq>M. disjoint C \<longrightarrow> finite C \<longrightarrow> \<Union>C \<in> M \<longrightarrow> f (\<Union>C) = (\<Sum>c\<in>C. f c))"
8.358 @@ -569,7 +520,7 @@
8.359    by (auto simp: volume_def)
8.360
8.362 -  assumes "volume M f"
8.363 +  assumes "volume M f"
8.364    assumes A: "\<And>i. i \<in> I \<Longrightarrow> A i \<in> M" "disjoint_family_on A I" "finite I" "UNION I A \<in> M"
8.365    shows "f (UNION I A) = (\<Sum>i\<in>I. f (A i))"
8.366  proof -
8.367 @@ -590,7 +541,7 @@
8.368  qed
8.369
8.371 -  assumes pos: "\<And>a. a \<in> M \<Longrightarrow> 0 \<le> \<mu> a"
8.372 +  assumes pos: "\<And>a. a \<in> M \<Longrightarrow> 0 \<le> \<mu> a"
8.373    assumes [simp]: "\<mu> {} = 0"
8.374    assumes add: "\<And>a b. a \<in> M \<Longrightarrow> b \<in> M \<Longrightarrow> a \<inter> b = {} \<Longrightarrow> \<mu> (a \<union> b) = \<mu> a + \<mu> b"
8.375    shows "volume M \<mu>"
8.376 @@ -614,7 +565,7 @@
8.377    have "\<forall>a\<in>?R. \<exists>m. \<exists>C\<subseteq>M. a = \<Union>C \<and> finite C \<and> disjoint C \<and> m = (\<Sum>c\<in>C. \<mu> c)"
8.378      by (auto simp: generated_ring_def)
8.379    from bchoice[OF this] guess \<mu>' .. note \<mu>'_spec = this
8.380 -
8.381 +
8.382    { fix C assume C: "C \<subseteq> M" "finite C" "disjoint C"
8.383      fix D assume D: "D \<subseteq> M" "finite D" "disjoint D"
8.384      assume "\<Union>C = \<Union>D"
8.385 @@ -688,7 +639,7 @@
8.386
8.387  theorem (in semiring_of_sets) caratheodory:
8.388    assumes pos: "positive M \<mu>" and ca: "countably_additive M \<mu>"
8.389 -  shows "\<exists>\<mu>' :: 'a set \<Rightarrow> ereal. (\<forall>s \<in> M. \<mu>' s = \<mu> s) \<and> measure_space \<Omega> (sigma_sets \<Omega> M) \<mu>'"
8.390 +  shows "\<exists>\<mu>' :: 'a set \<Rightarrow> ennreal. (\<forall>s \<in> M. \<mu>' s = \<mu> s) \<and> measure_space \<Omega> (sigma_sets \<Omega> M) \<mu>'"
8.391  proof -
8.392    have "volume M \<mu>"
8.393    proof (rule volumeI)
8.394 @@ -787,7 +738,7 @@
8.395          then have "\<Union>range f = A i"
8.396            using f C Ai unfolding bij_betw_def
8.397              by (auto simp add: f_def cong del: strong_SUP_cong)
8.398 -        moreover
8.399 +        moreover
8.400          { have "(\<Sum>j. \<mu>_r (f j)) = (\<Sum>j. if j \<in> {..< card C} then \<mu>_r (f j) else 0)"
8.401              using volume_empty[OF V(1)] by (auto intro!: arg_cong[where f=suminf] simp: f_def)
8.402            also have "\<dots> = (\<Sum>j<card C. \<mu>_r (f j))"
8.403 @@ -827,7 +778,7 @@
8.404          qed
8.405        qed
8.406        from f have "(\<Sum>n. \<mu>_r (A n)) = (\<Sum>n. \<mu>_r (case_prod f (prod_decode n)))"
8.407 -        by (intro suminf_ereal_2dimen[symmetric] positiveD2[OF pos] generated_ringI_Basic)
8.408 +        by (intro suminf_ennreal_2dimen[symmetric] generated_ringI_Basic)
8.409           (auto split: prod.split)
8.410        also have "\<dots> = (\<Sum>n. \<mu> (case_prod f (prod_decode n)))"
8.411          using f V(2) by (auto intro!: arg_cong[where f=suminf] split: prod.split)
8.412 @@ -847,8 +798,7 @@
8.413                 intro: generated_ringI_Basic)
8.414      also have "\<dots> = (\<Sum>c\<in>C'. \<Sum>n. \<mu>_r (A' n \<inter> c))"
8.415        using C' A'
8.416 -      by (intro suminf_setsum_ereal positiveD2[OF pos] G.Int G.finite_Union)
8.417 -         (auto intro: generated_ringI_Basic)
8.418 +      by (intro suminf_setsum G.Int G.finite_Union) (auto intro: generated_ringI_Basic)
8.419      also have "\<dots> = (\<Sum>c\<in>C'. \<mu>_r c)"
8.420        using eq V C' by (auto intro!: setsum.cong)
8.421      also have "\<dots> = \<mu>_r (\<Union>C')"
8.422 @@ -909,7 +859,7 @@
8.423        using \<mu>' by (simp_all add: M sets_extend_measure measure_space_def)
8.424    qed fact
8.425  qed
8.426 -
8.427 +
8.428  lemma extend_measure_caratheodory_pair:
8.429    fixes G :: "'i \<Rightarrow> 'j \<Rightarrow> 'a set"
8.430    assumes M: "M = extend_measure \<Omega> {(a, b). P a b} (\<lambda>(a, b). G a b) (\<lambda>(a, b). \<mu> a b)"
```
```     9.1 --- a/src/HOL/Probability/Complete_Measure.thy	Thu Apr 14 12:17:44 2016 +0200
9.2 +++ b/src/HOL/Probability/Complete_Measure.thy	Thu Apr 14 15:48:11 2016 +0200
9.3 @@ -174,7 +174,7 @@
9.4    let ?\<mu> = "emeasure M \<circ> main_part M"
9.5    show "S \<in> sets (completion M)" "?\<mu> S = emeasure M (main_part M S) " using S by simp_all
9.6    show "positive (sets (completion M)) ?\<mu>"
9.7 -    by (simp add: positive_def emeasure_nonneg)
9.8 +    by (simp add: positive_def)
9.9    show "countably_additive (sets (completion M)) ?\<mu>"
9.11      fix A :: "nat \<Rightarrow> 'a set" assume A: "range A \<subseteq> sets (completion M)" "disjoint_family A"
9.12 @@ -266,9 +266,9 @@
9.13    qed
9.14  qed
9.15
9.16 -lemma completion_ex_borel_measurable_pos:
9.17 -  fixes g :: "'a \<Rightarrow> ereal"
9.18 -  assumes g: "g \<in> borel_measurable (completion M)" and "\<And>x. 0 \<le> g x"
9.19 +lemma completion_ex_borel_measurable:
9.20 +  fixes g :: "'a \<Rightarrow> ennreal"
9.21 +  assumes g: "g \<in> borel_measurable (completion M)"
9.22    shows "\<exists>g'\<in>borel_measurable M. (AE x in M. g x = g' x)"
9.23  proof -
9.24    from g[THEN borel_measurable_implies_simple_function_sequence'] guess f . note f = this
9.25 @@ -284,7 +284,7 @@
9.26      proof (elim AE_mp, safe intro!: AE_I2)
9.27        fix x assume eq: "\<forall>i. f i x = f' i x"
9.28        moreover have "g x = (SUP i. f i x)"
9.29 -        unfolding f using \<open>0 \<le> g x\<close> by (auto split: split_max)
9.30 +        unfolding f by (auto split: split_max)
9.31        ultimately show "g x = ?f x" by auto
9.32      qed
9.33      show "?f \<in> borel_measurable M"
9.34 @@ -292,28 +292,6 @@
9.35    qed
9.36  qed
9.37
9.38 -lemma completion_ex_borel_measurable:
9.39 -  fixes g :: "'a \<Rightarrow> ereal"
9.40 -  assumes g: "g \<in> borel_measurable (completion M)"
9.41 -  shows "\<exists>g'\<in>borel_measurable M. (AE x in M. g x = g' x)"
9.42 -proof -
9.43 -  have "(\<lambda>x. max 0 (g x)) \<in> borel_measurable (completion M)" "\<And>x. 0 \<le> max 0 (g x)" using g by auto
9.44 -  from completion_ex_borel_measurable_pos[OF this] guess g_pos ..
9.45 -  moreover
9.46 -  have "(\<lambda>x. max 0 (- g x)) \<in> borel_measurable (completion M)" "\<And>x. 0 \<le> max 0 (- g x)" using g by auto
9.47 -  from completion_ex_borel_measurable_pos[OF this] guess g_neg ..
9.48 -  ultimately
9.49 -  show ?thesis
9.50 -  proof (safe intro!: bexI[of _ "\<lambda>x. g_pos x - g_neg x"])
9.51 -    show "AE x in M. max 0 (- g x) = g_neg x \<longrightarrow> max 0 (g x) = g_pos x \<longrightarrow> g x = g_pos x - g_neg x"
9.52 -    proof (intro AE_I2 impI)
9.53 -      fix x assume g: "max 0 (- g x) = g_neg x" "max 0 (g x) = g_pos x"
9.54 -      show "g x = g_pos x - g_neg x" unfolding g[symmetric]
9.55 -        by (cases "g x") (auto split: split_max)
9.56 -    qed
9.57 -  qed auto
9.58 -qed
9.59 -
9.60  lemma (in prob_space) prob_space_completion: "prob_space (completion M)"
9.61    by (rule prob_spaceI) (simp add: emeasure_space_1)
9.62
```
```    10.1 --- a/src/HOL/Probability/Convolution.thy	Thu Apr 14 12:17:44 2016 +0200
10.2 +++ b/src/HOL/Probability/Convolution.thy	Thu Apr 14 15:48:11 2016 +0200
10.3 @@ -40,7 +40,7 @@
10.4    assumes [simp]: "sets N = sets borel" "sets M = sets borel"
10.5    assumes [simp]: "space M = space N" "space N = space borel"
10.6    shows "emeasure (M \<star> N) A = \<integral>\<^sup>+x. (emeasure N {a. a + x \<in> A}) \<partial>M "
10.7 -  using assms by (auto intro!: nn_integral_cong simp del: nn_integral_indicator simp: nn_integral_convolution
10.8 +  using assms by (auto intro!: nn_integral_cong simp del: nn_integral_indicator simp: nn_integral_convolution
10.9      nn_integral_indicator [symmetric] ac_simps split:split_indicator)
10.10
10.11  lemma convolution_emeasure':
10.12 @@ -64,7 +64,7 @@
10.13    assumes [simp]: "sets N = sets borel" "sets M = sets borel" "sets L = sets borel"
10.14    shows "emeasure (L \<star> (M \<star> N )) A = \<integral>\<^sup>+x. \<integral>\<^sup>+y. \<integral>\<^sup>+z. indicator A (x + y + z) \<partial>N \<partial>M \<partial>L"
10.15    apply (subst nn_integral_indicator[symmetric], simp)
10.16 -  apply (subst nn_integral_convolution,
10.17 +  apply (subst nn_integral_convolution,
10.18          auto intro!: borel_measurable_indicator borel_measurable_indicator' convolution_finite)+
10.20
10.21 @@ -84,7 +84,7 @@
10.22    assumes [simp]: "finite_measure M" "finite_measure N"
10.23    assumes [measurable_cong, simp]: "sets N = sets borel" "sets M = sets borel"
10.24    shows "(M \<star> N) = (N \<star> M)"
10.25 -proof (rule measure_eqI)
10.26 +proof (rule measure_eqI)
10.27    interpret M: finite_measure M by fact
10.28    interpret N: finite_measure N by fact
10.29    interpret pair_sigma_finite M N ..
10.30 @@ -117,16 +117,15 @@
10.31  lemma (in prob_space) sum_indep_random_variable_lborel:
10.32    assumes ind: "indep_var borel X borel Y"
10.33    assumes [simp, measurable]: "random_variable lborel X"
10.34 -  assumes [simp, measurable]:"random_variable lborel Y"
10.35 +  assumes [simp, measurable]:"random_variable lborel Y"
10.36    shows "distr M lborel (\<lambda>x. X x + Y x) = convolution (distr M lborel X)  (distr M lborel Y)"
10.37 -  using ind unfolding indep_var_distribution_eq convolution_def
10.38 +  using ind unfolding indep_var_distribution_eq convolution_def
10.39    by (auto simp: distr_distr o_def intro!: arg_cong[where f = "distr M borel"] cong: distr_cong)
10.40
10.41  lemma convolution_density:
10.42 -  fixes f g :: "real \<Rightarrow> ereal"
10.43 +  fixes f g :: "real \<Rightarrow> ennreal"
10.44    assumes [measurable]: "f \<in> borel_measurable borel" "g \<in> borel_measurable borel"
10.45    assumes [simp]:"finite_measure (density lborel f)" "finite_measure (density lborel g)"
10.46 -  assumes gt_0[simp]: "AE x in lborel. 0 \<le> f x" "AE x in lborel. 0 \<le> g x"
10.47    shows "density lborel f \<star> density lborel g = density lborel (\<lambda>x. \<integral>\<^sup>+y. f (x - y) * g y \<partial>lborel)"
10.48      (is "?l = ?r")
10.49  proof (intro measure_eqI)
10.50 @@ -136,10 +135,9 @@
10.51
10.52    have "(\<integral>\<^sup>+x. f x * (\<integral>\<^sup>+y. g y * indicator A (x + y) \<partial>lborel) \<partial>lborel) =
10.53      (\<integral>\<^sup>+x. (\<integral>\<^sup>+y. g y * (f x * indicator A (x + y)) \<partial>lborel) \<partial>lborel)"
10.54 -    using gt_0
10.55    proof (intro nn_integral_cong_AE, eventually_elim)
10.56 -    fix x assume "0 \<le> f x"
10.57 -    then have "f x * (\<integral>\<^sup>+ y. g y * indicator A (x + y) \<partial>lborel) =
10.58 +    fix x
10.59 +    have "f x * (\<integral>\<^sup>+ y. g y * indicator A (x + y) \<partial>lborel) =
10.60        (\<integral>\<^sup>+ y. f x * (g y * indicator A (x + y)) \<partial>lborel)"
10.61        by (intro nn_integral_cmult[symmetric]) auto
10.62      then show "f x * (\<integral>\<^sup>+ y. g y * indicator A (x + y) \<partial>lborel) =
10.63 @@ -149,18 +147,16 @@
10.64    also have "\<dots> = (\<integral>\<^sup>+y. (\<integral>\<^sup>+x. g y * (f x * indicator A (x + y)) \<partial>lborel) \<partial>lborel)"
10.65      by (intro lborel_pair.Fubini') simp
10.66    also have "\<dots> = (\<integral>\<^sup>+y. (\<integral>\<^sup>+x. f (x - y) * g y * indicator A x \<partial>lborel) \<partial>lborel)"
10.67 -    using gt_0
10.68    proof (intro nn_integral_cong_AE, eventually_elim)
10.69 -    fix y assume "0 \<le> g y"
10.70 -    then have "(\<integral>\<^sup>+x. g y * (f x * indicator A (x + y)) \<partial>lborel) =
10.71 +    fix y
10.72 +    have "(\<integral>\<^sup>+x. g y * (f x * indicator A (x + y)) \<partial>lborel) =
10.73        g y * (\<integral>\<^sup>+x. f x * indicator A (x + y) \<partial>lborel)"
10.74        by (intro nn_integral_cmult) auto
10.75      also have "\<dots> = g y * (\<integral>\<^sup>+x. f (x - y) * indicator A x \<partial>lborel)"
10.76 -      using gt_0
10.77        by (subst nn_integral_real_affine[where c=1 and t="-y"])
10.78 -         (auto simp del: gt_0 simp add: one_ereal_def[symmetric])
10.79 +         (auto simp add: one_ennreal_def[symmetric])
10.80      also have "\<dots> = (\<integral>\<^sup>+x. g y * (f (x - y) * indicator A x) \<partial>lborel)"
10.81 -      using \<open>0 \<le> g y\<close> by (intro nn_integral_cmult[symmetric]) auto
10.82 +      by (intro nn_integral_cmult[symmetric]) auto
10.83      finally show "(\<integral>\<^sup>+ x. g y * (f x * indicator A (x + y)) \<partial>lborel) =
10.84        (\<integral>\<^sup>+ x. f (x - y) * g y * indicator A x \<partial>lborel)"
10.86 @@ -175,7 +171,7 @@
10.87  lemma (in prob_space) distributed_finite_measure_density:
10.88    "distributed M N X f \<Longrightarrow> finite_measure (density N f)"
10.89    using finite_measure_distr[of X N] distributed_distr_eq_density[of M N X f] by simp
10.90 -
10.91 +
10.92
10.93  lemma (in prob_space) distributed_convolution:
10.94    fixes f :: "real \<Rightarrow> _"
10.95 @@ -186,13 +182,10 @@
10.96    shows "distributed M lborel (\<lambda>x. X x + Y x) (\<lambda>x. \<integral>\<^sup>+y. f (x - y) * g y \<partial>lborel)"
10.97    unfolding distributed_def
10.98  proof safe
10.99 -  show "AE x in lborel. 0 \<le> \<integral>\<^sup>+ xa. f (x - xa) * g xa \<partial>lborel"
10.100 -    by (auto simp: nn_integral_nonneg)
10.101 -
10.102    have fg[measurable]: "f \<in> borel_measurable borel" "g \<in> borel_measurable borel"
10.103      using distributed_borel_measurable[OF X] distributed_borel_measurable[OF Y] by simp_all
10.104 -
10.105 -  show "(\<lambda>x. \<integral>\<^sup>+ xa. f (x - xa) * g xa \<partial>lborel) \<in> borel_measurable lborel"
10.106 +
10.107 +  show "(\<lambda>x. \<integral>\<^sup>+ xa. f (x - xa) * g xa \<partial>lborel) \<in> borel_measurable lborel"
10.108      by measurable
10.109
10.110    have "distr M borel (\<lambda>x. X x + Y x) = (distr M borel X \<star> distr M borel Y)"
10.111 @@ -207,10 +200,6 @@
10.112        using X by (rule distributed_finite_measure_density)
10.113      show "finite_measure (density lborel g)"
10.114        using Y by (rule distributed_finite_measure_density)
10.115 -    show "AE x in lborel. 0 \<le> f x"
10.116 -      using X by (rule distributed_AE)
10.117 -    show "AE x in lborel. 0 \<le> g x"
10.118 -      using Y by (rule distributed_AE)
10.119    qed fact+
10.120    finally show "distr M lborel (\<lambda>x. X x + Y x) = density lborel (\<lambda>x. \<integral>\<^sup>+ y. f (x - y) * g y \<partial>lborel)"
10.121      by (simp cong: distr_cong)
```
```    11.1 --- a/src/HOL/Probability/Distribution_Functions.thy	Thu Apr 14 12:17:44 2016 +0200
11.2 +++ b/src/HOL/Probability/Distribution_Functions.thy	Thu Apr 14 15:48:11 2016 +0200
11.3 @@ -6,11 +6,11 @@
11.4  section \<open>Distribution Functions\<close>
11.5
11.6  text \<open>
11.7 -Shows that the cumulative distribution function (cdf) of a distribution (a measure on the reals) is
11.8 +Shows that the cumulative distribution function (cdf) of a distribution (a measure on the reals) is
11.9  nondecreasing and right continuous, which tends to 0 and 1 in either direction.
11.10
11.11 -Conversely, every such function is the cdf of a unique distribution. This direction defines the
11.12 -measure in the obvious way on half-open intervals, and then applies the Caratheodory extension
11.13 +Conversely, every such function is the cdf of a unique distribution. This direction defines the
11.14 +measure in the obvious way on half-open intervals, and then applies the Caratheodory extension
11.15  theorem.
11.16  \<close>
11.17
11.18 @@ -43,7 +43,7 @@
11.19  lemma sets_M[intro]: "a \<in> sets borel \<Longrightarrow> a \<in> sets M"
11.20    using M_super_borel by auto
11.21
11.22 -lemma cdf_diff_eq:
11.23 +lemma cdf_diff_eq:
11.24    assumes "x < y"
11.25    shows "cdf M y - cdf M x = measure M {x<..y}"
11.26  proof -
11.27 @@ -59,7 +59,7 @@
11.28
11.29  lemma borel_UNIV: "space M = UNIV"
11.30   by (metis in_mono sets.sets_into_space space_in_borel top_le M_super_borel)
11.31 -
11.32 +
11.33  lemma cdf_nonneg: "cdf M x \<ge> 0"
11.34    unfolding cdf_def by (rule measure_nonneg)
11.35
11.36 @@ -76,11 +76,11 @@
11.37    finally show ?thesis .
11.38  qed
11.39
11.40 -lemma cdf_lim_at_top: "(cdf M \<longlongrightarrow> measure M (space M)) at_top"
11.41 +lemma cdf_lim_at_top: "(cdf M \<longlongrightarrow> measure M (space M)) at_top"
11.42    by (rule tendsto_at_topI_sequentially_real)
11.43       (simp_all add: mono_def cdf_nondecreasing cdf_lim_infty)
11.44
11.45 -lemma cdf_lim_neg_infty: "((\<lambda>i. cdf M (- real i)) \<longlonglongrightarrow> 0)"
11.46 +lemma cdf_lim_neg_infty: "((\<lambda>i. cdf M (- real i)) \<longlonglongrightarrow> 0)"
11.47  proof -
11.48    have "(\<lambda>i. cdf M (- real i)) \<longlonglongrightarrow> measure M (\<Inter> i::nat. {.. - real i })"
11.49      unfolding cdf_def by (rule finite_Lim_measure_decseq) (auto simp: decseq_def)
11.50 @@ -91,7 +91,7 @@
11.51  qed
11.52
11.53  lemma cdf_lim_at_bot: "(cdf M \<longlongrightarrow> 0) at_bot"
11.54 -proof -
11.55 +proof -
11.56    have *: "((\<lambda>x :: real. - cdf M (- x)) \<longlongrightarrow> 0) at_top"
11.57      by (intro tendsto_at_topI_sequentially_real monoI)
11.58         (auto simp: cdf_nondecreasing cdf_lim_neg_infty tendsto_minus_cancel_left[symmetric])
11.59 @@ -105,7 +105,7 @@
11.60  proof (rule tendsto_at_right_sequentially[where b="a + 1"])
11.61    fix f :: "nat \<Rightarrow> real" and x assume f: "decseq f" "f \<longlonglongrightarrow> a"
11.62    then have "(\<lambda>n. cdf M (f n)) \<longlonglongrightarrow> measure M (\<Inter>i. {.. f i})"
11.63 -    using `decseq f` unfolding cdf_def
11.64 +    using `decseq f` unfolding cdf_def
11.65      by (intro finite_Lim_measure_decseq) (auto simp: decseq_def)
11.66    also have "(\<Inter>i. {.. f i}) = {.. a}"
11.67      using decseq_le[OF f] by (auto intro: order_trans LIMSEQ_le_const[OF f(2)])
11.68 @@ -117,7 +117,7 @@
11.69  proof (rule tendsto_at_left_sequentially[of "a - 1"])
11.70    fix f :: "nat \<Rightarrow> real" and x assume f: "incseq f" "f \<longlonglongrightarrow> a" "\<And>x. f x < a" "\<And>x. a - 1 < f x"
11.71    then have "(\<lambda>n. cdf M (f n)) \<longlonglongrightarrow> measure M (\<Union>i. {.. f i})"
11.72 -    using `incseq f` unfolding cdf_def
11.73 +    using `incseq f` unfolding cdf_def
11.74      by (intro finite_Lim_measure_incseq) (auto simp: incseq_def)
11.75    also have "(\<Union>i. {.. f i}) = {..<a}"
11.76      by (auto dest!: order_tendstoD(1)[OF f(2)] eventually_happens'[OF sequentially_bot]
11.77 @@ -139,7 +139,7 @@
11.78
11.79  lemma countable_atoms: "countable {x. measure M {x} > 0}"
11.80    using countable_support unfolding zero_less_measure_iff .
11.81 -
11.82 +
11.83  end
11.84
11.85  locale real_distribution = prob_space M for M :: "real measure" +
11.86 @@ -155,7 +155,7 @@
11.87  lemma cdf_lim_infty_prob: "(\<lambda>i. cdf M (real i)) \<longlonglongrightarrow> 1"
11.88    by (subst prob_space [symmetric], rule cdf_lim_infty)
11.89
11.90 -lemma cdf_lim_at_top_prob: "(cdf M \<longlongrightarrow> 1) at_top"
11.91 +lemma cdf_lim_at_top_prob: "(cdf M \<longlongrightarrow> 1) at_top"
11.92    by (subst prob_space [symmetric], rule cdf_lim_at_top)
11.93
11.94  lemma measurable_finite_borel [simp]:
11.95 @@ -200,7 +200,7 @@
11.96  lemma real_distribution_interval_measure:
11.97    fixes F :: "real \<Rightarrow> real"
11.98    assumes nondecF : "\<And> x y. x \<le> y \<Longrightarrow> F x \<le> F y" and
11.99 -    right_cont_F : "\<And>a. continuous (at_right a) F" and
11.100 +    right_cont_F : "\<And>a. continuous (at_right a) F" and
11.101      lim_F_at_bot : "(F \<longlongrightarrow> 0) at_bot" and
11.102      lim_F_at_top : "(F \<longlongrightarrow> 1) at_top"
11.103    shows "real_distribution (interval_measure F)"
11.104 @@ -208,12 +208,12 @@
11.105    let ?F = "interval_measure F"
11.106    interpret prob_space ?F
11.107    proof
11.108 -    have "ereal (1 - 0) = (SUP i::nat. ereal (F (real i) - F (- real i)))"
11.109 -      by (intro LIMSEQ_unique[OF _ LIMSEQ_SUP] lim_ereal[THEN iffD2] tendsto_intros
11.110 -         lim_F_at_bot[THEN filterlim_compose] lim_F_at_top[THEN filterlim_compose]
11.111 -         lim_F_at_bot[THEN filterlim_compose] filterlim_real_sequentially
11.112 -         filterlim_uminus_at_top[THEN iffD1])
11.113 -         (auto simp: incseq_def intro!: diff_mono nondecF)
11.114 +    have "ennreal (1 - 0) = (SUP i::nat. ennreal (F (real i) - F (- real i)))"
11.115 +      by (intro LIMSEQ_unique[OF _ LIMSEQ_SUP] tendsto_ennrealI tendsto_intros
11.116 +                lim_F_at_bot[THEN filterlim_compose] lim_F_at_top[THEN filterlim_compose]
11.117 +                lim_F_at_bot[THEN filterlim_compose] filterlim_real_sequentially
11.118 +                filterlim_uminus_at_top[THEN iffD1])
11.119 +         (auto simp: incseq_def nondecF intro!: diff_mono)
11.120      also have "\<dots> = (SUP i::nat. emeasure ?F {- real i<..real i})"
11.121        by (subst emeasure_interval_measure_Ioc) (simp_all add: nondecF right_cont_F)
11.122      also have "\<dots> = emeasure ?F (\<Union>i::nat. {- real i<..real i})"
11.123 @@ -230,7 +230,7 @@
11.124  lemma cdf_interval_measure:
11.125    fixes F :: "real \<Rightarrow> real"
11.126    assumes nondecF : "\<And> x y. x \<le> y \<Longrightarrow> F x \<le> F y" and
11.127 -    right_cont_F : "\<And>a. continuous (at_right a) F" and
11.128 +    right_cont_F : "\<And>a. continuous (at_right a) F" and
11.129      lim_F_at_bot : "(F \<longlongrightarrow> 0) at_bot" and
11.130      lim_F_at_top : "(F \<longlongrightarrow> 1) at_top"
11.131    shows "cdf (interval_measure F) = F"
```
```    12.1 --- a/src/HOL/Probability/Distributions.thy	Thu Apr 14 12:17:44 2016 +0200
12.2 +++ b/src/HOL/Probability/Distributions.thy	Thu Apr 14 15:48:11 2016 +0200
12.3 @@ -10,7 +10,7 @@
12.4  begin
12.5
12.6  lemma (in prob_space) distributed_affine:
12.7 -  fixes f :: "real \<Rightarrow> ereal"
12.8 +  fixes f :: "real \<Rightarrow> ennreal"
12.9    assumes f: "distributed M lborel X f"
12.10    assumes c: "c \<noteq> 0"
12.11    shows "distributed M lborel (\<lambda>x. t + c * X x) (\<lambda>x. f ((x - t) / c) / \<bar>c\<bar>)"
12.12 @@ -26,30 +26,26 @@
12.13    show "random_variable lborel (\<lambda>x. t + c * X x)"
12.14      by simp
12.15
12.16 -  have "AE x in lborel. 0 \<le> f x"
12.17 -    using f by (simp add: distributed_def)
12.18 -  from AE_borel_affine[OF _ _ this, where c="1/c" and t="- t / c"] c
12.19 -  show "AE x in lborel. 0 \<le> f ((x - t) / c) / ereal \<bar>c\<bar>"
12.20 -    by (auto simp add: field_simps)
12.21 -
12.22 -  have eq: "\<And>x. ereal \<bar>c\<bar> * (f x / ereal \<bar>c\<bar>) = f x"
12.23 -    using c by (simp add: divide_ereal_def ac_simps one_ereal_def[symmetric])
12.24 +  have eq: "ennreal \<bar>c\<bar> * (f x / ennreal \<bar>c\<bar>) = f x" for x
12.25 +    using c
12.26 +    by (cases "f x")
12.27 +       (auto simp: divide_ennreal ennreal_mult[symmetric] ennreal_top_divide ennreal_mult_top)
12.28
12.29    have "density lborel f = distr M lborel X"
12.30      using f by (simp add: distributed_def)
12.31 -  with c show "distr M lborel (\<lambda>x. t + c * X x) = density lborel (\<lambda>x. f ((x - t) / c) / ereal \<bar>c\<bar>)"
12.32 +  with c show "distr M lborel (\<lambda>x. t + c * X x) = density lborel (\<lambda>x. f ((x - t) / c) / ennreal \<bar>c\<bar>)"
12.33      by (subst (2) lborel_real_affine[where c="c" and t="t"])
12.34         (simp_all add: density_density_eq density_distr distr_distr field_simps eq cong: distr_cong)
12.35  qed
12.36
12.37  lemma (in prob_space) distributed_affineI:
12.38 -  fixes f :: "real \<Rightarrow> ereal"
12.39 +  fixes f :: "real \<Rightarrow> ennreal" and c :: real
12.40    assumes f: "distributed M lborel (\<lambda>x. (X x - t) / c) (\<lambda>x. \<bar>c\<bar> * f (x * c + t))"
12.41    assumes c: "c \<noteq> 0"
12.42    shows "distributed M lborel X f"
12.43  proof -
12.44 -  have eq: "\<And>x. f x * ereal \<bar>c\<bar> / ereal \<bar>c\<bar> = f x"
12.45 -    using c by (simp add: divide_ereal_def ac_simps one_ereal_def[symmetric])
12.46 +  have eq: "f x * ennreal \<bar>c\<bar> / ennreal \<bar>c\<bar> = f x" for x
12.47 +    using c by (simp add: ennreal_times_divide[symmetric])
12.48
12.49    show ?thesis
12.50      using distributed_affine[OF f c, where t=t] c
12.51 @@ -73,19 +69,18 @@
12.52
12.53  lemma nn_intergal_power_times_exp_Icc:
12.54    assumes [arith]: "0 \<le> a"
12.55 -  shows "(\<integral>\<^sup>+x. ereal (x^k * exp (-x)) * indicator {0 .. a} x \<partial>lborel) =
12.56 +  shows "(\<integral>\<^sup>+x. ennreal (x^k * exp (-x)) * indicator {0 .. a} x \<partial>lborel) =
12.57      (1 - (\<Sum>n\<le>k. (a^n * exp (-a)) / fact n)) * fact k" (is "?I = _")
12.58  proof -
12.59    let ?f = "\<lambda>k x. x^k * exp (-x) / fact k"
12.60    let ?F = "\<lambda>k x. - (\<Sum>n\<le>k. (x^n * exp (-x)) / fact n)"
12.61    have "?I * (inverse (real_of_nat (fact k))) =
12.62 -      (\<integral>\<^sup>+x. ereal (x^k * exp (-x)) * indicator {0 .. a} x * (inverse (real_of_nat (fact k))) \<partial>lborel)"
12.63 +      (\<integral>\<^sup>+x. ennreal (x^k * exp (-x)) * indicator {0 .. a} x * (inverse (real_of_nat (fact k))) \<partial>lborel)"
12.64      by (intro nn_integral_multc[symmetric]) auto
12.65 -  also have "\<dots> = (\<integral>\<^sup>+x. ereal (?f k x) * indicator {0 .. a} x \<partial>lborel)"
12.66 -    apply (intro nn_integral_cong)
12.67 -    apply (simp add: field_simps)
12.68 -    by (metis (no_types) divide_inverse mult.commute mult.left_commute mult.left_neutral times_ereal.simps(1))
12.69 -  also have "\<dots> = ereal (?F k a - ?F k 0)"
12.70 +  also have "\<dots> = (\<integral>\<^sup>+x. ennreal (?f k x) * indicator {0 .. a} x \<partial>lborel)"
12.71 +    by (intro nn_integral_cong)
12.72 +       (simp add: field_simps ennreal_mult'[symmetric] indicator_mult_ennreal)
12.73 +  also have "\<dots> = ennreal (?F k a - ?F k 0)"
12.74    proof (rule nn_integral_FTC_Icc)
12.75      fix x assume "x \<in> {0..a}"
12.76      show "DERIV (?F k) x :> ?f k x"
12.77 @@ -106,17 +101,19 @@
12.78        finally show ?case .
12.79      qed
12.80    qed auto
12.81 -  also have "\<dots> = ereal (1 - (\<Sum>n\<le>k. (a^n * exp (-a)) / fact n))"
12.82 +  also have "\<dots> = ennreal (1 - (\<Sum>n\<le>k. (a^n * exp (-a)) / fact n))"
12.83      by (auto simp: power_0_left if_distrib[where f="\<lambda>x. x / a" for a] setsum.If_cases)
12.84 +  also have "\<dots> = ennreal ((1 - (\<Sum>n\<le>k. (a^n * exp (-a)) / fact n)) * fact k) * ennreal (inverse (fact k))"
12.85 +    by (subst ennreal_mult''[symmetric]) (auto intro!: arg_cong[where f=ennreal])
12.86    finally show ?thesis
12.87 -    by (cases "?I") (auto simp: field_simps)
12.88 +    by (auto simp add: mult_right_ennreal_cancel le_less)
12.89  qed
12.90
12.91  lemma nn_intergal_power_times_exp_Ici:
12.92 -  shows "(\<integral>\<^sup>+x. ereal (x^k * exp (-x)) * indicator {0 ..} x \<partial>lborel) = real_of_nat (fact k)"
12.93 +  shows "(\<integral>\<^sup>+x. ennreal (x^k * exp (-x)) * indicator {0 ..} x \<partial>lborel) = real_of_nat (fact k)"
12.94  proof (rule LIMSEQ_unique)
12.95 -  let ?X = "\<lambda>n. \<integral>\<^sup>+ x. ereal (x^k * exp (-x)) * indicator {0 .. real n} x \<partial>lborel"
12.96 -  show "?X \<longlonglongrightarrow> (\<integral>\<^sup>+x. ereal (x^k * exp (-x)) * indicator {0 ..} x \<partial>lborel)"
12.97 +  let ?X = "\<lambda>n. \<integral>\<^sup>+ x. ennreal (x^k * exp (-x)) * indicator {0 .. real n} x \<partial>lborel"
12.98 +  show "?X \<longlonglongrightarrow> (\<integral>\<^sup>+x. ennreal (x^k * exp (-x)) * indicator {0 ..} x \<partial>lborel)"
12.99      apply (intro nn_integral_LIMSEQ)
12.100      apply (auto simp: incseq_def le_fun_def eventually_sequentially
12.101                  split: split_indicator intro!: Lim_eventually)
12.102 @@ -137,7 +134,7 @@
12.103  definition erlang_CDF ::  "nat \<Rightarrow> real \<Rightarrow> real \<Rightarrow> real" where
12.104    "erlang_CDF k l x = (if x < 0 then 0 else 1 - (\<Sum>n\<le>k. ((l * x)^n * exp (- l * x) / fact n)))"
12.105
12.106 -lemma erlang_density_nonneg: "0 \<le> l \<Longrightarrow> 0 \<le> erlang_density k l x"
12.107 +lemma erlang_density_nonneg[simp]: "0 \<le> l \<Longrightarrow> 0 \<le> erlang_density k l x"
12.109
12.110  lemma borel_measurable_erlang_density[measurable]: "erlang_density k l \<in> borel_measurable borel"
12.111 @@ -146,28 +143,47 @@
12.112  lemma erlang_CDF_transform: "0 < l \<Longrightarrow> erlang_CDF k l a = erlang_CDF k 1 (l * a)"
12.113    by (auto simp add: erlang_CDF_def mult_less_0_iff)
12.114
12.115 +lemma erlang_CDF_nonneg[simp]: assumes "0 < l" shows "0 \<le> erlang_CDF k l x"
12.116 + unfolding erlang_CDF_def
12.117 +proof (clarsimp simp: not_less)
12.118 +  assume "0 \<le> x"
12.119 +  have "(\<Sum>n\<le>k. (l * x) ^ n * exp (- (l * x)) / fact n) =
12.120 +    exp (- (l * x)) * (\<Sum>n\<le>k. (l * x) ^ n / fact n)"
12.121 +    unfolding setsum_right_distrib by (intro setsum.cong) (auto simp: field_simps)
12.122 +  also have "\<dots> = (\<Sum>n\<le>k. (l * x) ^ n / fact n) / exp (l * x)"
12.123 +    by (simp add: exp_minus field_simps)
12.124 +  also have "\<dots> \<le> 1"
12.125 +  proof (subst divide_le_eq_1_pos)
12.126 +    show "(\<Sum>n\<le>k. (l * x) ^ n / fact n) \<le> exp (l * x)"
12.127 +      using \<open>0 < l\<close> \<open>0 \<le> x\<close> summable_exp_generic[of "l * x"]
12.128 +      by (auto simp: exp_def divide_inverse ac_simps intro!: setsum_le_suminf)
12.129 +  qed simp
12.130 +  finally show "(\<Sum>n\<le>k. (l * x) ^ n * exp (- (l * x)) / fact n) \<le> 1" .
12.131 +qed
12.132 +
12.133  lemma nn_integral_erlang_density:
12.134    assumes [arith]: "0 < l"
12.135 -  shows "(\<integral>\<^sup>+ x. ereal (erlang_density k l x) * indicator {.. a} x \<partial>lborel) = erlang_CDF k l a"
12.136 +  shows "(\<integral>\<^sup>+ x. ennreal (erlang_density k l x) * indicator {.. a} x \<partial>lborel) = erlang_CDF k l a"
12.137  proof cases
12.138    assume [arith]: "0 \<le> a"
12.139    have eq: "\<And>x. indicator {0..a} (x / l) = indicator {0..a*l} x"
12.140      by (simp add: field_simps split: split_indicator)
12.141 -  have "(\<integral>\<^sup>+x. ereal (erlang_density k l x) * indicator {.. a} x \<partial>lborel) =
12.142 -    (\<integral>\<^sup>+x. (l/fact k) * (ereal ((l*x)^k * exp (- (l*x))) * indicator {0 .. a} x) \<partial>lborel)"
12.143 -    by (intro nn_integral_cong) (auto simp: erlang_density_def power_mult_distrib split: split_indicator)
12.144 -  also have "\<dots> = (l/fact k) * (\<integral>\<^sup>+x. ereal ((l*x)^k * exp (- (l*x))) * indicator {0 .. a} x \<partial>lborel)"
12.145 +  have "(\<integral>\<^sup>+x. ennreal (erlang_density k l x) * indicator {.. a} x \<partial>lborel) =
12.146 +    (\<integral>\<^sup>+x. (l/fact k) * (ennreal ((l*x)^k * exp (- (l*x))) * indicator {0 .. a} x) \<partial>lborel)"
12.147 +    by (intro nn_integral_cong)
12.148 +       (auto simp: erlang_density_def power_mult_distrib ennreal_mult[symmetric] split: split_indicator)
12.149 +  also have "\<dots> = (l/fact k) * (\<integral>\<^sup>+x. ennreal ((l*x)^k * exp (- (l*x))) * indicator {0 .. a} x \<partial>lborel)"
12.150      by (intro nn_integral_cmult) auto
12.151 -  also have "\<dots> = ereal (l/fact k) * ((1/l) * (\<integral>\<^sup>+x. ereal (x^k * exp (- x)) * indicator {0 .. l * a} x \<partial>lborel))"
12.152 +  also have "\<dots> = ennreal (l/fact k) * ((1/l) * (\<integral>\<^sup>+x. ennreal (x^k * exp (- x)) * indicator {0 .. l * a} x \<partial>lborel))"
12.153      by (subst nn_integral_real_affine[where c="1 / l" and t=0]) (auto simp: field_simps eq)
12.154    also have "\<dots> = (1 - (\<Sum>n\<le>k. ((l * a)^n * exp (-(l * a))) / fact n))"
12.155 -    by (subst nn_intergal_power_times_exp_Icc) auto
12.156 +    by (subst nn_intergal_power_times_exp_Icc) (auto simp: ennreal_mult'[symmetric])
12.157    also have "\<dots> = erlang_CDF k l a"
12.158      by (auto simp: erlang_CDF_def)
12.159    finally show ?thesis .
12.160  next
12.161    assume "\<not> 0 \<le> a"
12.162 -  moreover then have "(\<integral>\<^sup>+ x. ereal (erlang_density k l x) * indicator {.. a} x \<partial>lborel) = (\<integral>\<^sup>+x. 0 \<partial>(lborel::real measure))"
12.163 +  moreover then have "(\<integral>\<^sup>+ x. ennreal (erlang_density k l x) * indicator {.. a} x \<partial>lborel) = (\<integral>\<^sup>+x. 0 \<partial>(lborel::real measure))"
12.164      by (intro nn_integral_cong) (auto simp: erlang_density_def)
12.165    ultimately show ?thesis
12.167 @@ -180,19 +196,20 @@
12.168  lemma nn_integral_erlang_ith_moment:
12.169    fixes k i :: nat and l :: real
12.170    assumes [arith]: "0 < l"
12.171 -  shows "(\<integral>\<^sup>+ x. ereal (erlang_density k l x * x ^ i) \<partial>lborel) = fact (k + i) / (fact k * l ^ i)"
12.172 +  shows "(\<integral>\<^sup>+ x. ennreal (erlang_density k l x * x ^ i) \<partial>lborel) = fact (k + i) / (fact k * l ^ i)"
12.173  proof -
12.174    have eq: "\<And>x. indicator {0..} (x / l) = indicator {0..} x"
12.175      by (simp add: field_simps split: split_indicator)
12.176 -  have "(\<integral>\<^sup>+ x. ereal (erlang_density k l x * x^i) \<partial>lborel) =
12.177 -    (\<integral>\<^sup>+x. (l/(fact k * l^i)) * (ereal ((l*x)^(k+i) * exp (- (l*x))) * indicator {0 ..} x) \<partial>lborel)"
12.178 -    by (intro nn_integral_cong) (auto simp: erlang_density_def power_mult_distrib power_add split: split_indicator)
12.179 -  also have "\<dots> = (l/(fact k * l^i)) * (\<integral>\<^sup>+x. ereal ((l*x)^(k+i) * exp (- (l*x))) * indicator {0 ..} x \<partial>lborel)"
12.180 +  have "(\<integral>\<^sup>+ x. ennreal (erlang_density k l x * x^i) \<partial>lborel) =
12.181 +    (\<integral>\<^sup>+x. (l/(fact k * l^i)) * (ennreal ((l*x)^(k+i) * exp (- (l*x))) * indicator {0 ..} x) \<partial>lborel)"
12.182 +    by (intro nn_integral_cong)
12.183 +       (auto simp: erlang_density_def power_mult_distrib power_add ennreal_mult'[symmetric] split: split_indicator)
12.184 +  also have "\<dots> = (l/(fact k * l^i)) * (\<integral>\<^sup>+x. ennreal ((l*x)^(k+i) * exp (- (l*x))) * indicator {0 ..} x \<partial>lborel)"
12.185      by (intro nn_integral_cmult) auto
12.186 -  also have "\<dots> = ereal (l/(fact k * l^i)) * ((1/l) * (\<integral>\<^sup>+x. ereal (x^(k+i) * exp (- x)) * indicator {0 ..} x \<partial>lborel))"
12.187 +  also have "\<dots> = ennreal (l/(fact k * l^i)) * ((1/l) * (\<integral>\<^sup>+x. ennreal (x^(k+i) * exp (- x)) * indicator {0 ..} x \<partial>lborel))"
12.188      by (subst nn_integral_real_affine[where c="1 / l" and t=0]) (auto simp: field_simps eq)
12.189    also have "\<dots> = fact (k + i) / (fact k * l ^ i)"
12.190 -    by (subst nn_intergal_power_times_exp_Ici) auto
12.191 +    by (subst nn_intergal_power_times_exp_Ici) (auto simp: ennreal_mult'[symmetric])
12.192    finally show ?thesis .
12.193  qed
12.194
12.195 @@ -217,7 +234,7 @@
12.196    also have "\<dots> = erlang_CDF k l a"
12.197      by (auto intro!: emeasure_erlang_density)
12.198    finally show ?thesis
12.199 -    by (auto simp: measure_def)
12.200 +    by (auto simp: emeasure_eq_measure measure_nonneg)
12.201  qed
12.202
12.203  lemma (in prob_space) erlang_distributed_gt:
12.204 @@ -246,17 +263,17 @@
12.205        by (intro emeasure_mono) auto
12.206      also have "... = 0"  by (auto intro!: erlang_CDF_at0 simp: X_distr[of 0])
12.207      finally have "emeasure M {x\<in>space M. X x \<le> a} \<le> 0" by simp
12.208 -    then have "emeasure M {x\<in>space M. X x \<le> a} = 0" by (simp add:emeasure_le_0_iff)
12.209 +    then have "emeasure M {x\<in>space M. X x \<le> a} = 0" by simp
12.210    }
12.211    note eq_0 = this
12.212
12.213 -  show "(\<integral>\<^sup>+ x. erlang_density k l x * indicator {..a} x \<partial>lborel) = ereal (erlang_CDF k l a)"
12.214 +  show "(\<integral>\<^sup>+ x. erlang_density k l x * indicator {..a} x \<partial>lborel) = ennreal (erlang_CDF k l a)"
12.215      using nn_integral_erlang_density[of l k a]
12.216 -    by (simp add: times_ereal.simps(1)[symmetric] ereal_indicator del: times_ereal.simps)
12.217 +    by (simp add: ennreal_indicator ennreal_mult)
12.218
12.219 -  show "emeasure M {x\<in>space M. X x \<le> a} = ereal (erlang_CDF k l a)"
12.220 -    using X_distr[of a] eq_0 by (auto simp: one_ereal_def erlang_CDF_def)
12.222 +  show "emeasure M {x\<in>space M. X x \<le> a} = ennreal (erlang_CDF k l a)"
12.223 +    using X_distr[of a] eq_0 by (auto simp: one_ennreal_def erlang_CDF_def)
12.224 +qed simp_all
12.225
12.226  lemma (in prob_space) erlang_distributed_iff:
12.227    assumes [arith]: "0<l"
12.228 @@ -266,7 +283,7 @@
12.229      distributed_measurable[of M lborel X "erlang_density k l"]
12.230      emeasure_erlang_density[of l]
12.231      erlang_distributed_le[of X k l]
12.232 -  by (auto intro!: erlang_distributedI simp: one_ereal_def emeasure_eq_measure)
12.233 +  by (auto intro!: erlang_distributedI simp: one_ennreal_def emeasure_eq_measure)
12.234
12.235  lemma (in prob_space) erlang_distributed_mult_const:
12.236    assumes erlX: "distributed M lborel X (erlang_density k l)"
12.237 @@ -300,10 +317,10 @@
12.238  proof (rule has_bochner_integral_nn_integral)
12.239    show "AE x in M. 0 \<le> X x ^ i"
12.240      by (subst distributed_AE2[OF D]) (auto simp: erlang_density_def)
12.241 -  show "(\<integral>\<^sup>+ x. ereal (X x ^ i) \<partial>M) = ereal (fact (k + i) / (fact k * l ^ i))"
12.242 +  show "(\<integral>\<^sup>+ x. ennreal (X x ^ i) \<partial>M) = ennreal (fact (k + i) / (fact k * l ^ i))"
12.243      using nn_integral_erlang_ith_moment[of l k i]
12.244 -    by (subst distributed_nn_integral[symmetric, OF D]) auto
12.245 -qed (insert distributed_measurable[OF D], simp)
12.246 +    by (subst distributed_nn_integral[symmetric, OF D]) (auto simp: ennreal_mult')
12.247 +qed (insert distributed_measurable[OF D], auto)
12.248
12.249  lemma (in prob_space) erlang_ith_moment_integrable:
12.250    "0 < l \<Longrightarrow> distributed M lborel X (erlang_density k l) \<Longrightarrow> integrable M (\<lambda>x. X x ^ i)"
12.251 @@ -339,65 +356,31 @@
12.252  lemma erlang_CDF_0: "erlang_CDF 0 l a = (if 0 \<le> a then 1 - exp (- l * a) else 0)"
12.254
12.255 -lemma (in prob_space) exponential_distributed_params:
12.256 -  assumes D: "distributed M lborel X (exponential_density l)"
12.257 -  shows "0 < l"
12.258 -proof (cases l "0 :: real" rule: linorder_cases)
12.259 -  assume "l < 0"
12.260 -  have "emeasure lborel {0 <.. 1::real} \<le>
12.261 -    emeasure lborel {x :: real \<in> space lborel. 0 < x}"
12.262 -    by (rule emeasure_mono) (auto simp: greaterThan_def[symmetric])
12.263 -  also have "emeasure lborel {x :: real \<in> space lborel. 0 < x} = 0"
12.264 -  proof -
12.265 -    have "AE x in lborel. 0 \<le> exponential_density l x"
12.266 -      using assms by (auto simp: distributed_real_AE)
12.267 -    then have "AE x in lborel. x \<le> (0::real)"
12.268 -      apply eventually_elim
12.269 -      using \<open>l < 0\<close>
12.270 -      apply (auto simp: exponential_density_def zero_le_mult_iff split: if_split_asm)
12.271 -      done
12.272 -    then show "emeasure lborel {x :: real \<in> space lborel. 0 < x} = 0"
12.273 -      by (subst (asm) AE_iff_measurable[OF _ refl]) (auto simp: not_le greaterThan_def[symmetric])
12.274 -  qed
12.275 -  finally show "0 < l" by simp
12.276 -next
12.277 -  assume "l = 0"
12.278 -  then have [simp]: "\<And>x. ereal (exponential_density l x) = 0"
12.279 -    by (simp add: exponential_density_def)
12.280 -  interpret X: prob_space "distr M lborel X"
12.281 -    using distributed_measurable[OF D] by (rule prob_space_distr)
12.282 -  from X.emeasure_space_1
12.283 -  show "0 < l"
12.284 -    by (simp add: emeasure_density distributed_distr_eq_density[OF D])
12.285 -qed assumption
12.286 -
12.287  lemma prob_space_exponential_density: "0 < l \<Longrightarrow> prob_space (density lborel (exponential_density l))"
12.288    by (rule prob_space_erlang_density)
12.289
12.290  lemma (in prob_space) exponential_distributedD_le:
12.291 -  assumes D: "distributed M lborel X (exponential_density l)" and a: "0 \<le> a"
12.292 +  assumes D: "distributed M lborel X (exponential_density l)" and a: "0 \<le> a" and l: "0 < l"
12.293    shows "\<P>(x in M. X x \<le> a) = 1 - exp (- a * l)"
12.294 -  using erlang_distributed_le[OF D exponential_distributed_params[OF D] a] a
12.295 -  by (simp add: erlang_CDF_def)
12.296 +  using erlang_distributed_le[OF D l a] a by (simp add: erlang_CDF_def)
12.297
12.298  lemma (in prob_space) exponential_distributedD_gt:
12.299 -  assumes D: "distributed M lborel X (exponential_density l)" and a: "0 \<le> a"
12.300 +  assumes D: "distributed M lborel X (exponential_density l)" and a: "0 \<le> a" and l: "0 < l"
12.301    shows "\<P>(x in M. a < X x ) = exp (- a * l)"
12.302 -  using erlang_distributed_gt[OF D exponential_distributed_params[OF D] a] a
12.303 -  by (simp add: erlang_CDF_def)
12.304 +  using erlang_distributed_gt[OF D l a] a by (simp add: erlang_CDF_def)
12.305
12.306  lemma (in prob_space) exponential_distributed_memoryless:
12.307 -  assumes D: "distributed M lborel X (exponential_density l)" and a: "0 \<le> a"and t: "0 \<le> t"
12.308 +  assumes D: "distributed M lborel X (exponential_density l)" and a: "0 \<le> a" and l: "0 < l" and t: "0 \<le> t"
12.309    shows "\<P>(x in M. a + t < X x \<bar> a < X x) = \<P>(x in M. t < X x)"
12.310  proof -
12.311    have "\<P>(x in M. a + t < X x \<bar> a < X x) = \<P>(x in M. a + t < X x) / \<P>(x in M. a < X x)"
12.312      using \<open>0 \<le> t\<close> by (auto simp: cond_prob_def intro!: arg_cong[where f=prob] arg_cong2[where f="op /"])
12.313    also have "\<dots> = exp (- (a + t) * l) / exp (- a * l)"
12.314 -    using a t by (simp add: exponential_distributedD_gt[OF D])
12.315 +    using a t by (simp add: exponential_distributedD_gt[OF D _ l])
12.316    also have "\<dots> = exp (- t * l)"
12.317 -    using exponential_distributed_params[OF D] by (auto simp: field_simps exp_add[symmetric])
12.318 +    using l by (auto simp: field_simps exp_add[symmetric])
12.319    finally show ?thesis
12.320 -    using t by (simp add: exponential_distributedD_gt[OF D])
12.321 +    using t by (simp add: exponential_distributedD_gt[OF D _ l])
12.322  qed
12.323
12.324  lemma exponential_distributedI:
12.325 @@ -405,40 +388,45 @@
12.326      and X_distr: "\<And>a. 0 \<le> a \<Longrightarrow> emeasure M {x\<in>space M. X x \<le> a} = 1 - exp (- a * l)"
12.327    shows "distributed M lborel X (exponential_density l)"
12.328  proof (rule erlang_distributedI)
12.329 -  fix a :: real assume "0 \<le> a" then show "emeasure M {x \<in> space M. X x \<le> a} = ereal (erlang_CDF 0 l a)"
12.330 -    using X_distr[of a] by (simp add: erlang_CDF_def one_ereal_def)
12.331 +  fix a :: real assume "0 \<le> a" then show "emeasure M {x \<in> space M. X x \<le> a} = ennreal (erlang_CDF 0 l a)"
12.332 +    using X_distr[of a] by (simp add: erlang_CDF_def ennreal_minus ennreal_1[symmetric] del: ennreal_1)
12.333  qed fact+
12.334
12.335  lemma (in prob_space) exponential_distributed_iff:
12.336 -  "distributed M lborel X (exponential_density l) \<longleftrightarrow>
12.337 -    (X \<in> borel_measurable M \<and> 0 < l \<and> (\<forall>a\<ge>0. \<P>(x in M. X x \<le> a) = 1 - exp (- a * l)))"
12.338 -  using exponential_distributed_params[of X l] erlang_distributed_iff[of l X 0] by (auto simp: erlang_CDF_0)
12.339 +  assumes "0 < l"
12.340 +  shows "distributed M lborel X (exponential_density l) \<longleftrightarrow>
12.341 +    (X \<in> borel_measurable M \<and> (\<forall>a\<ge>0. \<P>(x in M. X x \<le> a) = 1 - exp (- a * l)))"
12.342 +  using assms erlang_distributed_iff[of l X 0] by (auto simp: erlang_CDF_0)
12.343
12.344
12.345  lemma (in prob_space) exponential_distributed_expectation:
12.346 -  "distributed M lborel X (exponential_density l) \<Longrightarrow> expectation X = 1 / l"
12.347 -  using erlang_ith_moment[OF exponential_distributed_params, of X l X 0 1] by simp
12.348 +  "0 < l \<Longrightarrow> distributed M lborel X (exponential_density l) \<Longrightarrow> expectation X = 1 / l"
12.349 +  using erlang_ith_moment[of l X 0 1] by simp
12.350
12.351  lemma exponential_density_nonneg: "0 < l \<Longrightarrow> 0 \<le> exponential_density l x"
12.352    by (auto simp: exponential_density_def)
12.353
12.354  lemma (in prob_space) exponential_distributed_min:
12.355 +  assumes "0 < l" "0 < u"
12.356    assumes expX: "distributed M lborel X (exponential_density l)"
12.357    assumes expY: "distributed M lborel Y (exponential_density u)"
12.358    assumes ind: "indep_var borel X borel Y"
12.359    shows "distributed M lborel (\<lambda>x. min (X x) (Y x)) (exponential_density (l + u))"
12.360  proof (subst exponential_distributed_iff, safe)
12.361 -  have randX: "random_variable borel X" using expX by (simp add: exponential_distributed_iff)
12.362 -  moreover have randY: "random_variable borel Y" using expY by (simp add: exponential_distributed_iff)
12.363 +  have randX: "random_variable borel X"
12.364 +    using expX \<open>0 < l\<close> by (simp add: exponential_distributed_iff)
12.365 +  moreover have randY: "random_variable borel Y"
12.366 +    using expY \<open>0 < u\<close> by (simp add: exponential_distributed_iff)
12.367    ultimately show "random_variable borel (\<lambda>x. min (X x) (Y x))" by auto
12.368
12.369 -  have "0 < l" by (rule exponential_distributed_params) fact
12.370 -  moreover have "0 < u" by (rule exponential_distributed_params) fact
12.371 -  ultimately  show " 0 < l + u" by force
12.372 +  show " 0 < l + u"
12.373 +    using \<open>0 < l\<close> \<open>0 < u\<close> by auto
12.374
12.375    fix a::real assume a[arith]: "0 \<le> a"
12.376 -  have gt1[simp]: "\<P>(x in M. a < X x ) = exp (- a * l)" by (rule exponential_distributedD_gt[OF expX a])
12.377 -  have gt2[simp]: "\<P>(x in M. a < Y x ) = exp (- a * u)" by (rule exponential_distributedD_gt[OF expY a])
12.378 +  have gt1[simp]: "\<P>(x in M. a < X x ) = exp (- a * l)"
12.379 +    by (rule exponential_distributedD_gt[OF expX a]) fact
12.380 +  have gt2[simp]: "\<P>(x in M. a < Y x ) = exp (- a * u)"
12.381 +    by (rule exponential_distributedD_gt[OF expY a]) fact
12.382
12.383    have "\<P>(x in M. a < (min (X x) (Y x)) ) =  \<P>(x in M. a < (X x) \<and> a < (Y x))" by (auto intro!:arg_cong[where f=prob])
12.384
12.385 @@ -458,6 +446,7 @@
12.386  lemma (in prob_space) exponential_distributed_Min:
12.387    assumes finI: "finite I"
12.388    assumes A: "I \<noteq> {}"
12.389 +  assumes l: "\<And>i. i \<in> I \<Longrightarrow> 0 < l i"
12.390    assumes expX: "\<And>i. i \<in> I \<Longrightarrow> distributed M lborel (X i) (exponential_density (l i))"
12.391    assumes ind: "indep_vars (\<lambda>i. borel) X I"
12.392    shows "distributed M lborel (\<lambda>x. Min ((\<lambda>i. X i x)`I)) (exponential_density (\<Sum>i\<in>I. l i))"
12.393 @@ -468,14 +457,14 @@
12.394    case (insert i I)
12.395    then have "distributed M lborel (\<lambda>x. min (X i x) (Min ((\<lambda>i. X i x)`I))) (exponential_density (l i + (\<Sum>i\<in>I. l i)))"
12.396        by (intro exponential_distributed_min indep_vars_Min insert)
12.397 -         (auto intro: indep_vars_subset)
12.398 +         (auto intro: indep_vars_subset setsum_pos)
12.399    then show ?case
12.400      using insert by simp
12.401  qed
12.402
12.403  lemma (in prob_space) exponential_distributed_variance:
12.404 -  "distributed M lborel X (exponential_density l) \<Longrightarrow> variance X = 1 / l\<^sup>2"
12.405 -  using erlang_distributed_variance[OF exponential_distributed_params, of X l X 0] by simp
12.406 +  "0 < l \<Longrightarrow> distributed M lborel X (exponential_density l) \<Longrightarrow> variance X = 1 / l\<^sup>2"
12.407 +  using erlang_distributed_variance[of l X 0] by simp
12.408
12.409  lemma nn_integral_zero': "AE x in M. f x = 0 \<Longrightarrow> (\<integral>\<^sup>+x. f x \<partial>M) = 0"
12.410    by (simp cong: nn_integral_cong_AE)
12.411 @@ -483,7 +472,7 @@
12.412  lemma convolution_erlang_density:
12.413    fixes k\<^sub>1 k\<^sub>2 :: nat
12.414    assumes [simp, arith]: "0 < l"
12.415 -  shows "(\<lambda>x. \<integral>\<^sup>+y. ereal (erlang_density k\<^sub>1 l (x - y)) * ereal (erlang_density k\<^sub>2 l y) \<partial>lborel) =
12.416 +  shows "(\<lambda>x. \<integral>\<^sup>+y. ennreal (erlang_density k\<^sub>1 l (x - y)) * ennreal (erlang_density k\<^sub>2 l y) \<partial>lborel) =
12.417      (erlang_density (Suc k\<^sub>1 + Suc k\<^sub>2 - 1) l)"
12.418        (is "?LHS = ?RHS")
12.419  proof
12.420 @@ -503,22 +492,21 @@
12.421      have I_eq1: "integral\<^sup>N lborel (erlang_density (Suc k\<^sub>1 + Suc k\<^sub>2 - 1) l) = 1"
12.422        using nn_integral_erlang_ith_moment[of l "Suc k\<^sub>1 + Suc k\<^sub>2 - 1" 0] by (simp del: fact_Suc)
12.423
12.424 -    have 1: "(\<integral>\<^sup>+ x. ereal (erlang_density (Suc k\<^sub>1 + Suc k\<^sub>2 - 1) l x * indicator {0<..} x) \<partial>lborel) = 1"
12.425 +    have 1: "(\<integral>\<^sup>+ x. ennreal (erlang_density (Suc k\<^sub>1 + Suc k\<^sub>2 - 1) l x * indicator {0<..} x) \<partial>lborel) = 1"
12.426        apply (subst I_eq1[symmetric])
12.427        unfolding erlang_density_def
12.428        by (auto intro!: nn_integral_cong split:split_indicator)
12.429
12.430      have "prob_space (density lborel ?LHS)"
12.431 -      unfolding times_ereal.simps[symmetric]
12.432        by (intro prob_space_convolution_density)
12.433           (auto intro!: prob_space_erlang_density erlang_density_nonneg)
12.434      then have 2: "integral\<^sup>N lborel ?LHS = 1"
12.435        by (auto dest!: prob_space.emeasure_space_1 simp: emeasure_density)
12.436
12.437 -    let ?I = "(integral\<^sup>N lborel (\<lambda>y. ereal ((1 - y)^ k\<^sub>1 * y^k\<^sub>2 * indicator {0..1} y)))"
12.438 +    let ?I = "(integral\<^sup>N lborel (\<lambda>y. ennreal ((1 - y)^ k\<^sub>1 * y^k\<^sub>2 * indicator {0..1} y)))"
12.439      let ?C = "(fact (Suc (k\<^sub>1 + k\<^sub>2))) / ((fact k\<^sub>1) * (fact k\<^sub>2))"
12.440      let ?s = "Suc k\<^sub>1 + Suc k\<^sub>2 - 1"
12.441 -    let ?L = "(\<lambda>x. \<integral>\<^sup>+y. ereal (erlang_density k\<^sub>1 l (x- y) * erlang_density k\<^sub>2 l y * indicator {0..x} y) \<partial>lborel)"
12.442 +    let ?L = "(\<lambda>x. \<integral>\<^sup>+y. ennreal (erlang_density k\<^sub>1 l (x- y) * erlang_density k\<^sub>2 l y * indicator {0..x} y) \<partial>lborel)"
12.443
12.444      { fix x :: real assume [arith]: "0 < x"
12.445        have *: "\<And>x y n. (x - y * x::real)^n = x^n * (1 - y)^n"
12.446 @@ -526,17 +514,18 @@
12.447
12.448        have "?LHS x = ?L x"
12.449          unfolding erlang_density_def
12.450 -        by (auto intro!: nn_integral_cong split:split_indicator)
12.451 -      also have "... = (\<lambda>x. ereal ?C * ?I * erlang_density ?s l x) x"
12.452 +        by (auto intro!: nn_integral_cong simp: ennreal_mult split:split_indicator)
12.453 +      also have "... = (\<lambda>x. ennreal ?C * ?I * erlang_density ?s l x) x"
12.454          apply (subst nn_integral_real_affine[where c=x and t = 0])
12.455 -        apply (simp_all add: nn_integral_cmult[symmetric] nn_integral_multc[symmetric] erlang_density_nonneg del: fact_Suc)
12.456 +        apply (simp_all add: nn_integral_cmult[symmetric] nn_integral_multc[symmetric] del: fact_Suc)
12.457          apply (intro nn_integral_cong)
12.458          apply (auto simp add: erlang_density_def mult_less_0_iff exp_minus field_simps exp_diff power_add *
12.459 +                              ennreal_mult[symmetric]
12.460                      simp del: fact_Suc split: split_indicator)
12.461          done
12.462 -      finally have "(\<integral>\<^sup>+y. ereal (erlang_density k\<^sub>1 l (x - y) * erlang_density k\<^sub>2 l y) \<partial>lborel) =
12.463 -        (\<lambda>x. ereal ?C * ?I * erlang_density ?s l x) x"
12.464 -        by simp }
12.465 +      finally have "(\<integral>\<^sup>+y. ennreal (erlang_density k\<^sub>1 l (x - y) * erlang_density k\<^sub>2 l y) \<partial>lborel) =
12.466 +        (\<lambda>x. ennreal ?C * ?I * erlang_density ?s l x) x"
12.467 +        by (simp add: ennreal_mult) }
12.468      note * = this
12.469
12.470      assume [arith]: "0 < x"
12.471 @@ -544,15 +533,15 @@
12.472        by (subst 2[symmetric])
12.473           (auto intro!: nn_integral_cong_AE AE_I[where N="{0}"]
12.474                 simp: erlang_density_def  nn_integral_multc[symmetric] indicator_def split: if_split_asm)
12.475 -    also have "... = integral\<^sup>N lborel (\<lambda>x. (ereal (?C) * ?I) * ((erlang_density ?s l x) * indicator {0<..} x))"
12.476 -      by (auto intro!: nn_integral_cong simp: * split: split_indicator)
12.477 -    also have "... = ereal (?C) * ?I"
12.478 +    also have "... = integral\<^sup>N lborel (\<lambda>x. (ennreal (?C) * ?I) * ((erlang_density ?s l x) * indicator {0<..} x))"
12.479 +      by (auto intro!: nn_integral_cong simp: ennreal_mult[symmetric] * split: split_indicator)
12.480 +    also have "... = ennreal (?C) * ?I"
12.481        using 1
12.482 -      by (auto simp: nn_integral_nonneg nn_integral_cmult)
12.483 -    finally have " ereal (?C) * ?I = 1" by presburger
12.484 +      by (auto simp: nn_integral_cmult)
12.485 +    finally have " ennreal (?C) * ?I = 1" by presburger
12.486
12.487      then show ?thesis
12.488 -      using * by simp
12.489 +      using * by (simp add: ennreal_mult)
12.490    qed
12.491  qed
12.492
12.493 @@ -592,21 +581,17 @@
12.494  lemma (in prob_space) exponential_distributed_setsum:
12.495    assumes finI: "finite I"
12.496    assumes A: "I \<noteq> {}"
12.497 +  assumes l: "0 < l"
12.498    assumes expX: "\<And>i. i \<in> I \<Longrightarrow> distributed M lborel (X i) (exponential_density l)"
12.499    assumes ind: "indep_vars (\<lambda>i. borel) X I"
12.500    shows "distributed M lborel (\<lambda>x. \<Sum>i\<in>I. X i x) (erlang_density ((card I) - 1) l)"
12.501 -proof -
12.502 -  obtain i where "i \<in> I" using assms by auto
12.503 -  note exponential_distributed_params[OF expX[OF this]]
12.504 -  from erlang_distributed_setsum[OF assms(1,2) this assms(3,4)] show ?thesis by simp
12.505 -qed
12.506 +  using erlang_distributed_setsum[OF assms] by simp
12.507
12.508  lemma (in information_space) entropy_exponential:
12.509 +  assumes l[simp, arith]: "0 < l"
12.510    assumes D: "distributed M lborel X (exponential_density l)"
12.511    shows "entropy b lborel X = log b (exp 1 / l)"
12.512  proof -
12.513 -  have l[simp, arith]: "0 < l" by (rule exponential_distributed_params[OF D])
12.514 -
12.515    have [simp]: "integrable lborel (exponential_density l)"
12.516      using distributed_integrable[OF D, of "\<lambda>_. 1"] by simp
12.517
12.518 @@ -620,7 +605,7 @@
12.519      using erlang_ith_moment[OF l D, of 1] distributed_integral[OF D, of "\<lambda>x. x"] by simp
12.520
12.521    have "entropy b lborel X = - (\<integral> x. exponential_density l x * log b (exponential_density l x) \<partial>lborel)"
12.522 -    using D by (rule entropy_distr)
12.523 +    using D by (rule entropy_distr) simp
12.524    also have "(\<integral> x. exponential_density l x * log b (exponential_density l x) \<partial>lborel) =
12.525      (\<integral> x. (ln l * exponential_density l x - l * (exponential_density l x * x)) / ln b \<partial>lborel)"
12.526      by (intro integral_cong) (auto simp: log_def ln_mult exponential_density_def field_simps)
12.527 @@ -644,10 +629,10 @@
12.528    with X have "emeasure M (X -` B \<inter> space M) = emeasure M' (A \<inter> B) / emeasure M' A"
12.529      by (simp add: distr[of B] measurable_sets)
12.530    also have "\<dots> = (1 / emeasure M' A) * emeasure M' (A \<inter> B)"
12.531 -     by simp
12.532 +     by (simp add: divide_ennreal_def ac_simps)
12.533    also have "\<dots> = (\<integral>\<^sup>+ x. (1 / emeasure M' A) * indicator (A \<inter> B) x \<partial>M')"
12.534      using A B
12.535 -    by (intro nn_integral_cmult_indicator[symmetric]) (auto intro!: zero_le_divide_ereal)
12.536 +    by (intro nn_integral_cmult_indicator[symmetric]) (auto intro!: )
12.537    also have "\<dots> = (\<integral>\<^sup>+ x. ?f x * indicator B x \<partial>M')"
12.538      by (rule nn_integral_cong) (auto split: split_indicator)
12.539    finally show "emeasure (distr M M' X) B = emeasure (density M' ?f) B"
12.540 @@ -656,7 +641,7 @@
12.541
12.542  lemma uniform_distrI_borel:
12.543    fixes A :: "real set"
12.544 -  assumes X[measurable]: "X \<in> borel_measurable M" and A: "emeasure lborel A = ereal r" "0 < r"
12.545 +  assumes X[measurable]: "X \<in> borel_measurable M" and A: "emeasure lborel A = ennreal r" "0 < r"
12.546      and [measurable]: "A \<in> sets borel"
12.547    assumes distr: "\<And>a. emeasure M {x\<in>space M. X x \<le> a} = emeasure lborel (A \<inter> {.. a}) / r"
12.548    shows "distributed M lborel X (\<lambda>x. indicator A x / measure lborel A)"
12.549 @@ -667,24 +652,25 @@
12.550      using A by (intro emeasure_mono) auto
12.551    also have "\<dots> < \<infinity>"
12.552      using A by simp
12.553 -  finally have fin: "emeasure lborel (A \<inter> {..a}) \<noteq> \<infinity>"
12.554 +  finally have fin: "emeasure lborel (A \<inter> {..a}) \<noteq> top"
12.555      by simp
12.556 -  from emeasure_eq_ereal_measure[OF this]
12.557 -  have fin_eq: "emeasure lborel (A \<inter> {..a}) / r = ereal (measure lborel (A \<inter> {..a}) / r)"
12.558 -    using A by simp
12.559 -  then show "emeasure M {x\<in>space M. X x \<le> a} = ereal (measure lborel (A \<inter> {..a}) / r)"
12.560 +  from emeasure_eq_ennreal_measure[OF this]
12.561 +  have fin_eq: "emeasure lborel (A \<inter> {..a}) / r = ennreal (measure lborel (A \<inter> {..a}) / r)"
12.562 +    using A by (simp add: divide_ennreal measure_nonneg)
12.563 +  then show "emeasure M {x\<in>space M. X x \<le> a} = ennreal (measure lborel (A \<inter> {..a}) / r)"
12.564      using distr by simp
12.565
12.566 -  have "(\<integral>\<^sup>+ x. ereal (indicator A x / measure lborel A * indicator {..a} x) \<partial>lborel) =
12.567 -    (\<integral>\<^sup>+ x. ereal (1 / measure lborel A) * indicator (A \<inter> {..a}) x \<partial>lborel)"
12.568 +  have "(\<integral>\<^sup>+ x. ennreal (indicator A x / measure lborel A * indicator {..a} x) \<partial>lborel) =
12.569 +    (\<integral>\<^sup>+ x. ennreal (1 / measure lborel A) * indicator (A \<inter> {..a}) x \<partial>lborel)"
12.570      by (auto intro!: nn_integral_cong split: split_indicator)
12.571 -  also have "\<dots> = ereal (1 / measure lborel A) * emeasure lborel (A \<inter> {..a})"
12.572 +  also have "\<dots> = ennreal (1 / measure lborel A) * emeasure lborel (A \<inter> {..a})"
12.573      using \<open>A \<in> sets borel\<close>
12.574      by (intro nn_integral_cmult_indicator) (auto simp: measure_nonneg)
12.575 -  also have "\<dots> = ereal (measure lborel (A \<inter> {..a}) / r)"
12.576 -    unfolding emeasure_eq_ereal_measure[OF fin] using A by (simp add: measure_def)
12.577 -  finally show "(\<integral>\<^sup>+ x. ereal (indicator A x / measure lborel A * indicator {..a} x) \<partial>lborel) =
12.578 -    ereal (measure lborel (A \<inter> {..a}) / r)" .
12.579 +  also have "\<dots> = ennreal (measure lborel (A \<inter> {..a}) / r)"
12.580 +    unfolding emeasure_eq_ennreal_measure[OF fin] using A
12.581 +    by (simp add: measure_def ennreal_mult'[symmetric])
12.582 +  finally show "(\<integral>\<^sup>+ x. ennreal (indicator A x / measure lborel A * indicator {..a} x) \<partial>lborel) =
12.583 +    ennreal (measure lborel (A \<inter> {..a}) / r)" .
12.584  qed (auto simp: measure_nonneg)
12.585
12.586  lemma (in prob_space) uniform_distrI_borel_atLeastAtMost:
12.587 @@ -704,45 +690,45 @@
12.588      also have "\<dots> = 0"
12.589        using distr[of a] \<open>a < b\<close> by (simp add: emeasure_eq_measure)
12.590      finally have "emeasure M {x\<in>space M. X x \<le> t} = 0"
12.591 -      by (simp add: antisym measure_nonneg emeasure_le_0_iff)
12.592 +      by (simp add: antisym measure_nonneg)
12.593      with \<open>t < a\<close> show ?thesis by simp
12.594    next
12.595      assume bnds: "a \<le> t" "t \<le> b"
12.596      have "{a..b} \<inter> {..t} = {a..t}"
12.597        using bnds by auto
12.598      then show ?thesis using \<open>a \<le> t\<close> \<open>a < b\<close>
12.599 -      using distr[OF bnds] by (simp add: emeasure_eq_measure)
12.600 +      using distr[OF bnds] by (simp add: emeasure_eq_measure divide_ennreal)
12.601    next
12.602      assume "b < t"
12.603      have "1 = emeasure M {x\<in>space M. X x \<le> b}"
12.604 -      using distr[of b] \<open>a < b\<close> by (simp add: one_ereal_def emeasure_eq_measure)
12.605 +      using distr[of b] \<open>a < b\<close> by (simp add: one_ennreal_def emeasure_eq_measure)
12.606      also have "\<dots> \<le> emeasure M {x\<in>space M. X x \<le> t}"
12.607        using X \<open>b < t\<close> by (auto intro!: emeasure_mono measurable_sets)
12.608      finally have "emeasure M {x\<in>space M. X x \<le> t} = 1"
12.609 -       by (simp add: antisym emeasure_eq_measure one_ereal_def)
12.610 -    with \<open>b < t\<close> \<open>a < b\<close> show ?thesis by (simp add: measure_def one_ereal_def)
12.611 +       by (simp add: antisym emeasure_eq_measure)
12.612 +    with \<open>b < t\<close> \<open>a < b\<close> show ?thesis by (simp add: measure_def divide_ennreal)
12.613    qed
12.614  qed (insert X \<open>a < b\<close>, auto)
12.615
12.616  lemma (in prob_space) uniform_distributed_measure:
12.617    fixes a b :: real
12.618    assumes D: "distributed M lborel X (\<lambda>x. indicator {a .. b} x / measure lborel {a .. b})"
12.619 -  assumes " a \<le> t" "t \<le> b"
12.620 +  assumes t: "a \<le> t" "t \<le> b"
12.621    shows "\<P>(x in M. X x \<le> t) = (t - a) / (b - a)"
12.622  proof -
12.623    have "emeasure M {x \<in> space M. X x \<le> t} = emeasure (distr M lborel X) {.. t}"
12.624      using distributed_measurable[OF D]
12.625      by (subst emeasure_distr) (auto intro!: arg_cong2[where f=emeasure])
12.626 -  also have "\<dots> = (\<integral>\<^sup>+x. ereal (1 / (b - a)) * indicator {a .. t} x \<partial>lborel)"
12.627 +  also have "\<dots> = (\<integral>\<^sup>+x. ennreal (1 / (b - a)) * indicator {a .. t} x \<partial>lborel)"
12.628      using distributed_borel_measurable[OF D] \<open>a \<le> t\<close> \<open>t \<le> b\<close>
12.629      unfolding distributed_distr_eq_density[OF D]
12.630      by (subst emeasure_density)
12.631         (auto intro!: nn_integral_cong simp: measure_def split: split_indicator)
12.632 -  also have "\<dots> = ereal (1 / (b - a)) * (t - a)"
12.633 +  also have "\<dots> = ennreal (1 / (b - a)) * (t - a)"
12.634      using \<open>a \<le> t\<close> \<open>t \<le> b\<close>
12.635      by (subst nn_integral_cmult_indicator) auto
12.636    finally show ?thesis
12.637 -    by (simp add: measure_def)
12.638 +    using t by (simp add: emeasure_eq_measure ennreal_mult''[symmetric] measure_nonneg)
12.639  qed
12.640
12.641  lemma (in prob_space) uniform_distributed_bounds:
12.642 @@ -795,7 +781,7 @@
12.643        unfolding * square_diff_square_factored by (auto simp: field_simps)
12.644    qed (insert \<open>a < b\<close>, simp)
12.645    finally show "(\<integral> x. indicator {a .. b} x / measure lborel {a .. b} * x \<partial>lborel) = (a + b) / 2" .
12.646 -qed auto
12.647 +qed (auto simp: measure_nonneg)
12.648
12.649  lemma (in prob_space) uniform_distributed_variance:
12.650    fixes a b :: real
12.651 @@ -810,7 +796,7 @@
12.652      by (simp add: integral_power uniform_distributed_expectation[OF D])
12.653         (simp add: eval_nat_numeral field_simps )
12.654    finally show "(\<integral>x. x\<^sup>2 * ?D x \<partial>lborel) = (b - a)\<^sup>2 / 12" .
12.655 -qed fact
12.656 +qed (auto intro: D simp: measure_nonneg)
12.657
12.658  subsection \<open>Normal distribution\<close>
12.659
12.660 @@ -824,7 +810,7 @@
12.661  lemma std_normal_density_def: "std_normal_density x = (1 / sqrt (2 * pi)) * exp (- x\<^sup>2 / 2)"
12.662    unfolding normal_density_def by simp
12.663
12.664 -lemma normal_density_nonneg: "0 \<le> normal_density \<mu> \<sigma> x"
12.665 +lemma normal_density_nonneg[simp]: "0 \<le> normal_density \<mu> \<sigma> x"
12.666    by (auto simp: normal_density_def)
12.667
12.668  lemma normal_density_pos: "0 < \<sigma> \<Longrightarrow> 0 < normal_density \<mu> \<sigma> x"
12.669 @@ -846,14 +832,14 @@
12.670      by (intro nn_integral_cong_AE AE_I[where N="{0}"]) (auto split: split_indicator)
12.671
12.672    have "?pI ?gauss * ?pI ?gauss = (\<integral>\<^sup>+x. \<integral>\<^sup>+s. ?gauss x * ?gauss s * ?I s * ?I x \<partial>lborel \<partial>lborel)"
12.673 -    by (auto simp: nn_integral_nonneg nn_integral_cmult[symmetric] nn_integral_multc[symmetric] *
12.674 +    by (auto simp: nn_integral_cmult[symmetric] nn_integral_multc[symmetric] * ennreal_mult[symmetric]
12.675               intro!: nn_integral_cong split: split_indicator)
12.676    also have "\<dots> = (\<integral>\<^sup>+x. \<integral>\<^sup>+s. ?ff x s * ?I s * ?I x \<partial>lborel \<partial>lborel)"
12.677    proof (rule nn_integral_cong, cases)
12.678      fix x :: real assume "x \<noteq> 0"
12.679      then show "(\<integral>\<^sup>+s. ?gauss x * ?gauss s * ?I s * ?I x \<partial>lborel) = (\<integral>\<^sup>+s. ?ff x s * ?I s * ?I x \<partial>lborel)"
12.680        by (subst nn_integral_real_affine[where t="0" and c="x"])
12.681 -         (auto simp: mult_exp_exp nn_integral_cmult[symmetric] field_simps zero_less_mult_iff
12.682 +         (auto simp: mult_exp_exp nn_integral_cmult[symmetric] field_simps zero_less_mult_iff ennreal_mult[symmetric]
12.683                 intro!: nn_integral_cong split: split_indicator)
12.684    qed simp
12.685    also have "... = \<integral>\<^sup>+s. \<integral>\<^sup>+x. ?ff x s * ?I s * ?I x \<partial>lborel \<partial>lborel"
12.686 @@ -861,9 +847,9 @@
12.687    also have "... = ?pI (\<lambda>s. ?pI (\<lambda>x. ?ff x s))"
12.688      by (rule nn_integral_cong_AE)
12.689         (auto intro!: nn_integral_cong_AE AE_I[where N="{0}"] split: split_indicator_asm)
12.690 -  also have "\<dots> = ?pI (\<lambda>s. ereal (1 / (2 * (1 + s\<^sup>2))))"
12.691 -  proof (intro nn_integral_cong ereal_right_mult_cong)
12.692 -    fix s :: real show "?pI (\<lambda>x. ?ff x s) = ereal (1 / (2 * (1 + s\<^sup>2)))"
12.693 +  also have "\<dots> = ?pI (\<lambda>s. ennreal (1 / (2 * (1 + s\<^sup>2))))"
12.694 +  proof (intro nn_integral_cong ennreal_mult_right_cong)
12.695 +    fix s :: real show "?pI (\<lambda>x. ?ff x s) = ennreal (1 / (2 * (1 + s\<^sup>2)))"
12.696      proof (subst nn_integral_FTC_atLeast)
12.697        have "((\<lambda>a. - (exp (- (a\<^sup>2 * (1 + s\<^sup>2))) / (2 + 2 * s\<^sup>2))) \<longlongrightarrow> (- (0 / (2 + 2 * s\<^sup>2)))) at_top"
12.698          apply (intro tendsto_intros filterlim_compose[OF exp_at_bot] filterlim_compose[OF filterlim_uminus_at_bot_at_top])
12.699 @@ -875,8 +861,8 @@
12.700        then show "((\<lambda>a. - (exp (- a\<^sup>2 - s\<^sup>2 * a\<^sup>2) / (2 + 2 * s\<^sup>2))) \<longlongrightarrow> 0) at_top"
12.702      qed (auto intro!: derivative_eq_intros simp: field_simps add_nonneg_eq_0_iff)
12.703 -  qed rule
12.704 -  also have "... = ereal (pi / 4)"
12.705 +  qed
12.706 +  also have "... = ennreal (pi / 4)"
12.707    proof (subst nn_integral_FTC_atLeast)
12.708      show "((\<lambda>a. arctan a / 2) \<longlongrightarrow> (pi / 2) / 2 ) at_top"
12.709        by (intro tendsto_intros) (simp_all add: tendsto_arctan_at_top)
12.710 @@ -884,25 +870,25 @@
12.711    finally have "?pI ?gauss^2 = pi / 4"
12.713    then have "?pI ?gauss = sqrt (pi / 4)"
12.714 -    using power_eq_iff_eq_base[of 2 "real_of_ereal (?pI ?gauss)" "sqrt (pi / 4)"]
12.715 -          nn_integral_nonneg[of lborel "\<lambda>x. ?gauss x * indicator {0..} x"]
12.716 -    by (cases "?pI ?gauss") auto
12.717 +    using power_eq_iff_eq_base[of 2 "enn2real (?pI ?gauss)" "sqrt (pi / 4)"]
12.718 +    by (cases "?pI ?gauss") (auto simp: power2_eq_square ennreal_mult[symmetric] ennreal_top_mult)
12.719    also have "?pI ?gauss = (\<integral>\<^sup>+x. indicator {0..} x *\<^sub>R exp (- x\<^sup>2) \<partial>lborel)"
12.720      by (intro nn_integral_cong) (simp split: split_indicator)
12.721    also have "sqrt (pi / 4) = sqrt pi / 2"
12.723    finally show ?thesis
12.724 -    by (rule has_bochner_integral_nn_integral[rotated 2]) auto
12.725 +    by (rule has_bochner_integral_nn_integral[rotated 3])
12.726 +       auto
12.727  qed
12.728
12.729  lemma gaussian_moment_1:
12.730    "has_bochner_integral lborel (\<lambda>x::real. indicator {0..} x *\<^sub>R (exp (- x\<^sup>2) * x)) (1 / 2)"
12.731  proof -
12.732    have "(\<integral>\<^sup>+x. indicator {0..} x *\<^sub>R (exp (- x\<^sup>2) * x) \<partial>lborel) =
12.733 -    (\<integral>\<^sup>+x. ereal (x * exp (- x\<^sup>2)) * indicator {0..} x \<partial>lborel)"
12.734 +    (\<integral>\<^sup>+x. ennreal (x * exp (- x\<^sup>2)) * indicator {0..} x \<partial>lborel)"
12.735      by (intro nn_integral_cong)
12.736 -       (auto simp: ac_simps times_ereal.simps(1)[symmetric] ereal_indicator simp del: times_ereal.simps)
12.737 -  also have "\<dots> = ereal (0 - (- exp (- 0\<^sup>2) / 2))"
12.738 +       (auto simp: ac_simps split: split_indicator)
12.739 +  also have "\<dots> = ennreal (0 - (- exp (- 0\<^sup>2) / 2))"
12.740    proof (rule nn_integral_FTC_atLeast)
12.741      have "((\<lambda>x::real. - exp (- x\<^sup>2) / 2) \<longlongrightarrow> - 0 / 2) at_top"
12.742        by (intro tendsto_divide tendsto_minus filterlim_compose[OF exp_at_bot]
12.743 @@ -912,10 +898,11 @@
12.744      then show "((\<lambda>a::real. - exp (- a\<^sup>2) / 2) \<longlongrightarrow> 0) at_top"
12.745        by simp
12.746    qed (auto intro!: derivative_eq_intros)
12.747 -  also have "\<dots> = ereal (1 / 2)"
12.748 +  also have "\<dots> = ennreal (1 / 2)"
12.749      by simp
12.750    finally show ?thesis
12.751 -    by (rule has_bochner_integral_nn_integral[rotated 2]) (auto split: split_indicator)
12.752 +    by (rule has_bochner_integral_nn_integral[rotated 3])
12.753 +        (auto split: split_indicator)
12.754  qed
12.755
12.756  lemma
12.757 @@ -1203,29 +1190,30 @@
12.758      by (simp add: normal_density_def real_sqrt_mult field_simps)
12.760    show ?thesis
12.761 -    by (rule distributed_affineI[OF _ \<open>\<alpha> \<noteq> 0\<close>, where t=\<beta>]) (simp_all add: eq X)
12.762 +    by (rule distributed_affineI[OF _ \<open>\<alpha> \<noteq> 0\<close>, where t=\<beta>])
12.763 +       (simp_all add: eq X ennreal_mult'[symmetric])
12.764  qed
12.765
12.766  lemma (in prob_space) normal_standard_normal_convert:
12.767    assumes pos_var[simp, arith]: "0 < \<sigma>"
12.768    shows "distributed M lborel X (normal_density  \<mu> \<sigma>) = distributed M lborel (\<lambda>x. (X x - \<mu>) / \<sigma>) std_normal_density"
12.769  proof auto
12.770 -  assume "distributed M lborel X (\<lambda>x. ereal (normal_density \<mu> \<sigma> x))"
12.771 -  then have "distributed M lborel (\<lambda>x. -\<mu> / \<sigma> + (1/\<sigma>) * X x) (\<lambda>x. ereal (normal_density (-\<mu> / \<sigma> + (1/\<sigma>)* \<mu>) (\<bar>1/\<sigma>\<bar> * \<sigma>) x))"
12.772 +  assume "distributed M lborel X (\<lambda>x. ennreal (normal_density \<mu> \<sigma> x))"
12.773 +  then have "distributed M lborel (\<lambda>x. -\<mu> / \<sigma> + (1/\<sigma>) * X x) (\<lambda>x. ennreal (normal_density (-\<mu> / \<sigma> + (1/\<sigma>)* \<mu>) (\<bar>1/\<sigma>\<bar> * \<sigma>) x))"
12.774      by(rule normal_density_affine) auto
12.775
12.776 -  then show "distributed M lborel (\<lambda>x. (X x - \<mu>) / \<sigma>) (\<lambda>x. ereal (std_normal_density x))"
12.777 +  then show "distributed M lborel (\<lambda>x. (X x - \<mu>) / \<sigma>) (\<lambda>x. ennreal (std_normal_density x))"
12.778      by (simp add: diff_divide_distrib[symmetric] field_simps)
12.779  next
12.780 -  assume *: "distributed M lborel (\<lambda>x. (X x - \<mu>) / \<sigma>) (\<lambda>x. ereal (std_normal_density x))"
12.781 -  have "distributed M lborel (\<lambda>x. \<mu> + \<sigma> * ((X x - \<mu>) / \<sigma>)) (\<lambda>x. ereal (normal_density \<mu> \<bar>\<sigma>\<bar> x))"
12.782 +  assume *: "distributed M lborel (\<lambda>x. (X x - \<mu>) / \<sigma>) (\<lambda>x. ennreal (std_normal_density x))"
12.783 +  have "distributed M lborel (\<lambda>x. \<mu> + \<sigma> * ((X x - \<mu>) / \<sigma>)) (\<lambda>x. ennreal (normal_density \<mu> \<bar>\<sigma>\<bar> x))"
12.784      using normal_density_affine[OF *, of \<sigma> \<mu>] by simp
12.785 -  then show "distributed M lborel X (\<lambda>x. ereal (normal_density \<mu> \<sigma> x))" by simp
12.786 +  then show "distributed M lborel X (\<lambda>x. ennreal (normal_density \<mu> \<sigma> x))" by simp
12.787  qed
12.788
12.789  lemma conv_normal_density_zero_mean:
12.790    assumes [simp, arith]: "0 < \<sigma>" "0 < \<tau>"
12.791 -  shows "(\<lambda>x. \<integral>\<^sup>+y. ereal (normal_density 0 \<sigma> (x - y) * normal_density 0 \<tau> y) \<partial>lborel) =
12.792 +  shows "(\<lambda>x. \<integral>\<^sup>+y. ennreal (normal_density 0 \<sigma> (x - y) * normal_density 0 \<tau> y) \<partial>lborel) =
12.793      normal_density 0 (sqrt (\<sigma>\<^sup>2 + \<tau>\<^sup>2))"  (is "?LHS = ?RHS")
12.794  proof -
12.795    def \<sigma>' \<equiv> "\<sigma>\<^sup>2" and \<tau>' \<equiv> "\<tau>\<^sup>2"
12.796 @@ -1237,7 +1225,7 @@
12.797      by (subst power_eq_iff_eq_base[symmetric, where n=2])
12.799    have "?LHS =
12.800 -    (\<lambda>x. \<integral>\<^sup>+y. ereal((normal_density 0 (sqrt (\<sigma>' + \<tau>')) x) * normal_density (\<tau>' * x / (\<sigma>' + \<tau>')) ?\<sigma> y) \<partial>lborel)"
12.801 +    (\<lambda>x. \<integral>\<^sup>+y. ennreal((normal_density 0 (sqrt (\<sigma>' + \<tau>')) x) * normal_density (\<tau>' * x / (\<sigma>' + \<tau>')) ?\<sigma> y) \<partial>lborel)"
12.802      apply (intro ext nn_integral_cong)
12.803      apply (simp add: normal_density_def \<sigma>'_def[symmetric] \<tau>'_def[symmetric] sqrt mult_exp_exp)
12.804      apply (simp add: divide_simps power2_eq_square)
12.805 @@ -1245,8 +1233,9 @@
12.806      done
12.807
12.808    also have "... =
12.809 -    (\<lambda>x. (normal_density 0 (sqrt (\<sigma>\<^sup>2 + \<tau>\<^sup>2)) x) * \<integral>\<^sup>+y. ereal( normal_density (\<tau>\<^sup>2* x / (\<sigma>\<^sup>2 + \<tau>\<^sup>2)) ?\<sigma> y) \<partial>lborel)"
12.810 -    by (subst nn_integral_cmult[symmetric]) (auto simp: \<sigma>'_def \<tau>'_def normal_density_def)
12.811 +    (\<lambda>x. (normal_density 0 (sqrt (\<sigma>\<^sup>2 + \<tau>\<^sup>2)) x) * \<integral>\<^sup>+y. ennreal( normal_density (\<tau>\<^sup>2* x / (\<sigma>\<^sup>2 + \<tau>\<^sup>2)) ?\<sigma> y) \<partial>lborel)"
12.812 +    by (subst nn_integral_cmult[symmetric])
12.813 +       (auto simp: \<sigma>'_def \<tau>'_def normal_density_def ennreal_mult'[symmetric])
12.814
12.815    also have "... = (\<lambda>x. (normal_density 0 (sqrt (\<sigma>\<^sup>2 + \<tau>\<^sup>2)) x))"
12.816      by (subst nn_integral_eq_integral) (auto simp: normal_density_nonneg)
12.817 @@ -1255,7 +1244,7 @@
12.818  qed
12.819
12.820  lemma conv_std_normal_density:
12.821 -  "(\<lambda>x. \<integral>\<^sup>+y. ereal (std_normal_density (x - y) * std_normal_density y) \<partial>lborel) =
12.822 +  "(\<lambda>x. \<integral>\<^sup>+y. ennreal (std_normal_density (x - y) * std_normal_density y) \<partial>lborel) =
12.823    (normal_density 0 (sqrt 2))"
12.824    by (subst conv_normal_density_zero_mean) simp_all
12.825
12.826 @@ -1281,11 +1270,12 @@
12.827      by(rule normal_density_affine[OF normalY pos_var(2), of 1 "-\<nu>"]) simp
12.828    then have 2[simp]: "distributed M lborel (\<lambda>x. - \<nu> +  Y x) (normal_density 0 \<tau>)" by simp
12.829
12.830 -  have *: "distributed M lborel (\<lambda>x. (- \<mu> + X x) + (- \<nu> + Y x)) (\<lambda>x. ereal (normal_density 0 (sqrt (\<sigma>\<^sup>2 + \<tau>\<^sup>2)) x))"
12.831 -    using distributed_convolution[OF ind 1 2] conv_normal_density_zero_mean[OF pos_var] by simp
12.832 +  have *: "distributed M lborel (\<lambda>x. (- \<mu> + X x) + (- \<nu> + Y x)) (\<lambda>x. ennreal (normal_density 0 (sqrt (\<sigma>\<^sup>2 + \<tau>\<^sup>2)) x))"
12.833 +    using distributed_convolution[OF ind 1 2] conv_normal_density_zero_mean[OF pos_var]
12.834 +    by (simp add: ennreal_mult'[symmetric] normal_density_nonneg)
12.835
12.836    have "distributed M lborel (\<lambda>x. \<mu> + \<nu> + 1 * (- \<mu> + X x + (- \<nu> + Y x)))
12.837 -        (\<lambda>x. ereal (normal_density (\<mu> + \<nu> + 1 * 0) (\<bar>1\<bar> * sqrt (\<sigma>\<^sup>2 + \<tau>\<^sup>2)) x))"
12.838 +        (\<lambda>x. ennreal (normal_density (\<mu> + \<nu> + 1 * 0) (\<bar>1\<bar> * sqrt (\<sigma>\<^sup>2 + \<tau>\<^sup>2)) x))"
12.839      by (rule normal_density_affine[OF *, of 1 "\<mu> + \<nu>"]) (auto simp: add_pos_pos)
12.840
12.841    then show ?thesis by auto
12.842 @@ -1298,9 +1288,9 @@
12.843    assumes normalY[simp]: "distributed M lborel Y (normal_density \<nu> \<tau>)"
12.844    shows "distributed M lborel (\<lambda>x. X x - Y x) (normal_density (\<mu> - \<nu>) (sqrt (\<sigma>\<^sup>2 + \<tau>\<^sup>2)))"
12.845  proof -
12.846 -  have "distributed M lborel (\<lambda>x. 0 + - 1 * Y x) (\<lambda>x. ereal (normal_density (0 + - 1 * \<nu>) (\<bar>- 1\<bar> * \<tau>) x))"
12.847 +  have "distributed M lborel (\<lambda>x. 0 + - 1 * Y x) (\<lambda>x. ennreal (normal_density (0 + - 1 * \<nu>) (\<bar>- 1\<bar> * \<tau>) x))"
12.848      by(rule normal_density_affine, auto)
12.849 -  then have [simp]:"distributed M lborel (\<lambda>x. - Y x) (\<lambda>x. ereal (normal_density (- \<nu>) \<tau> x))" by simp
12.850 +  then have [simp]:"distributed M lborel (\<lambda>x. - Y x) (\<lambda>x. ennreal (normal_density (- \<nu>) \<tau> x))" by simp
12.851
12.852    have "distributed M lborel (\<lambda>x. X x + (- Y x)) (normal_density (\<mu> + - \<nu>) (sqrt (\<sigma>\<^sup>2 + \<tau>\<^sup>2)))"
12.853      apply (rule sum_indep_normal)
12.854 @@ -1340,7 +1330,8 @@
12.855    assumes D: "distributed M lborel X std_normal_density"
12.856    shows "expectation X = 0"
12.857    using integral_std_normal_moment_odd[of 0]
12.858 -  by (auto simp: distributed_integral[OF D, of "\<lambda>x. x", symmetric])
12.859 +    distributed_integral[OF D, of "\<lambda>x. x", symmetric]
12.860 +  by (auto simp: )
12.861
12.862  lemma (in prob_space) normal_distributed_expectation:
12.863    assumes \<sigma>[arith]: "0 < \<sigma>"
12.864 @@ -1368,7 +1359,7 @@
12.865    shows "entropy b lborel X = log b (2 * pi * exp 1 * \<sigma>\<^sup>2) / 2"
12.866  proof -
12.867    have "entropy b lborel X = - (\<integral> x. normal_density \<mu> \<sigma> x * log b (normal_density \<mu> \<sigma> x) \<partial>lborel)"
12.868 -    using D by (rule entropy_distr)
12.869 +    using D by (rule entropy_distr) simp
12.870    also have "\<dots> = - (\<integral> x. normal_density \<mu> \<sigma> x * (- ln (2 * pi * \<sigma>\<^sup>2) - (x - \<mu>)\<^sup>2 / \<sigma>\<^sup>2) / (2 * ln b) \<partial>lborel)"
12.871      by (intro arg_cong[where f="uminus"] integral_cong)
12.872         (auto simp: normal_density_def field_simps ln_mult log_def ln_div ln_sqrt)
```
```    13.1 --- a/src/HOL/Probability/Embed_Measure.thy	Thu Apr 14 12:17:44 2016 +0200
13.2 +++ b/src/HOL/Probability/Embed_Measure.thy	Thu Apr 14 15:48:11 2016 +0200
13.3 @@ -1,8 +1,8 @@
13.4  (*  Title:      HOL/Probability/Embed_Measure.thy
13.5      Author:     Manuel Eberl, TU MÃ¼nchen
13.6
13.7 -    Defines measure embeddings with injective functions, i.e. lifting a measure on some values
13.8 -    to a measure on "tagged" values (e.g. embed_measure M Inl lifts a measure on values 'a to a
13.9 +    Defines measure embeddings with injective functions, i.e. lifting a measure on some values
13.10 +    to a measure on "tagged" values (e.g. embed_measure M Inl lifts a measure on values 'a to a
13.11      measure on the left part of the sum type 'a + 'b)
13.12  *)
13.13
13.14 @@ -13,15 +13,15 @@
13.15  begin
13.16
13.17  definition embed_measure :: "'a measure \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> 'b measure" where
13.18 -  "embed_measure M f = measure_of (f ` space M) {f ` A |A. A \<in> sets M}
13.19 +  "embed_measure M f = measure_of (f ` space M) {f ` A |A. A \<in> sets M}
13.20                             (\<lambda>A. emeasure M (f -` A \<inter> space M))"
13.21
13.22  lemma space_embed_measure: "space (embed_measure M f) = f ` space M"
13.23 -  unfolding embed_measure_def
13.24 +  unfolding embed_measure_def
13.25    by (subst space_measure_of) (auto dest: sets.sets_into_space)
13.26
13.27  lemma sets_embed_measure':
13.28 -  assumes inj: "inj_on f (space M)"
13.29 +  assumes inj: "inj_on f (space M)"
13.30    shows "sets (embed_measure M f) = {f ` A |A. A \<in> sets M}"
13.31    unfolding embed_measure_def
13.32  proof (intro sigma_algebra.sets_measure_of_eq sigma_algebra_iff2[THEN iffD2] conjI allI ballI impI)
13.33 @@ -52,7 +52,7 @@
13.34             intro!: image_cong the_inv_into_vimage[symmetric])
13.35
13.36  lemma sets_embed_measure:
13.37 -  assumes inj: "inj f"
13.38 +  assumes inj: "inj f"
13.39    shows "sets (embed_measure M f) = {f ` A |A. A \<in> sets M}"
13.40    using assms by (subst sets_embed_measure') (auto intro!: inj_onI dest: injD)
13.41
13.42 @@ -61,7 +61,7 @@
13.43    by (intro in_measure_of) (auto dest: sets.sets_into_space)
13.44
13.45  lemma measurable_embed_measure1:
13.46 -  assumes g: "(\<lambda>x. g (f x)) \<in> measurable M N"
13.47 +  assumes g: "(\<lambda>x. g (f x)) \<in> measurable M N"
13.48    shows "g \<in> measurable (embed_measure M f) N"
13.49    unfolding measurable_def
13.50  proof safe
13.51 @@ -76,7 +76,7 @@
13.52  qed (insert measurable_space[OF assms], auto simp: space_embed_measure)
13.53
13.54  lemma measurable_embed_measure2':
13.55 -  assumes "inj_on f (space M)"
13.56 +  assumes "inj_on f (space M)"
13.57    shows "f \<in> measurable M (embed_measure M f)"
13.58  proof-
13.59    {
13.60 @@ -99,7 +99,7 @@
13.61    assumes "inj_on f (space M)"
13.62    shows "embed_measure M f = distr M (embed_measure M f) f"
13.63  proof-
13.64 -  have "distr M (embed_measure M f) f =
13.65 +  have "distr M (embed_measure M f) f =
13.66              measure_of (f ` space M) {f ` A |A. A \<in> sets M}
13.67                         (\<lambda>A. emeasure M (f -` A \<inter> space M))" unfolding distr_def
13.68        by (simp add: space_embed_measure sets_embed_measure'[OF assms])
13.69 @@ -135,19 +135,19 @@
13.70      shows "emeasure (embed_measure M f) A = emeasure M (f -` A \<inter> space M)"
13.71   using assms by (intro emeasure_embed_measure') (auto intro!: inj_onI dest: injD)
13.72
13.73 -lemma embed_measure_comp:
13.74 +lemma embed_measure_comp:
13.75    assumes [simp]: "inj f" "inj g"
13.76    shows "embed_measure (embed_measure M f) g = embed_measure M (g \<circ> f)"
13.77  proof-
13.78    have [simp]: "inj (\<lambda>x. g (f x))" by (subst o_def[symmetric]) (auto intro: inj_comp)
13.79    note measurable_embed_measure2[measurable]
13.80 -  have "embed_measure (embed_measure M f) g =
13.81 +  have "embed_measure (embed_measure M f) g =
13.82              distr M (embed_measure (embed_measure M f) g) (g \<circ> f)"
13.83 -      by (subst (1 2) embed_measure_eq_distr)
13.84 +      by (subst (1 2) embed_measure_eq_distr)
13.85           (simp_all add: distr_distr sets_embed_measure cong: distr_cong)
13.86    also have "... = embed_measure M (g \<circ> f)"
13.87        by (subst (3) embed_measure_eq_distr, simp add: o_def, rule distr_cong)
13.88 -         (auto simp: sets_embed_measure o_def image_image[symmetric]
13.89 +         (auto simp: sets_embed_measure o_def image_image[symmetric]
13.90                 intro: inj_comp cong: distr_cong)
13.91    finally show ?thesis .
13.92  qed
13.93 @@ -161,7 +161,7 @@
13.94        A_props: "countable A" "A \<subseteq> sets M" "\<Union>A = space M" "\<And>X. X\<in>A \<Longrightarrow> emeasure M X \<noteq> \<infinity>" by blast
13.95    from A_props have "countable (op ` f`A)" by auto
13.96    moreover
13.97 -  from inj and A_props have "op ` f`A \<subseteq> sets (embed_measure M f)"
13.98 +  from inj and A_props have "op ` f`A \<subseteq> sets (embed_measure M f)"
13.99      by (auto simp: sets_embed_measure)
13.100    moreover
13.101    from A_props and inj have "\<Union>(op ` f`A) = space (embed_measure M f)"
13.102 @@ -184,7 +184,7 @@
13.103    apply (auto simp: space_embed_measure sets_embed_measure')
13.104    done
13.105
13.106 -lemma embed_measure_count_space:
13.107 +lemma embed_measure_count_space:
13.108      "inj f \<Longrightarrow> embed_measure (count_space A) f = count_space (f`A)"
13.109    by(rule embed_measure_count_space')(erule subset_inj_on, simp)
13.110
13.111 @@ -217,7 +217,7 @@
13.112    moreover {
13.113      fix X assume "X \<in> sets A"
13.114      from asm have "emeasure ?M (f`X) = emeasure ?N (f`X)" by simp
13.115 -    with \<open>X \<in> sets A\<close> and \<open>sets A = sets B\<close> and assms
13.116 +    with \<open>X \<in> sets A\<close> and \<open>sets A = sets B\<close> and assms
13.117          have "emeasure A X = emeasure B X" by (simp add: emeasure_embed_measure_image)
13.118    }
13.119    ultimately show "A = B" by (rule measure_eqI)
13.120 @@ -240,7 +240,7 @@
13.121  proof (rule pair_measure_eqI)
13.122    have fg[simp]: "\<And>A. inj_on (map_prod f g) A" "\<And>A. inj_on f A" "\<And>A. inj_on g A"
13.123      using f g by (auto simp: inj_on_def)
13.124 -
13.125 +
13.126    show sets: "sets ?L = sets (embed_measure (M \<Otimes>\<^sub>M N) (map_prod f g))"
13.127      unfolding map_prod_def[symmetric]
13.128      apply (simp add: sets_pair_eq_sets_fst_snd sets_embed_eq_vimage_algebra
13.129 @@ -275,18 +275,17 @@
13.130    shows "density (embed_measure M f) g = embed_measure (density M (g \<circ> f)) f" (is "?M1 = ?M2")
13.131  proof (rule measure_eqI)
13.132    fix X assume X: "X \<in> sets ?M1"
13.133 -  from inj have Mf[measurable]: "f \<in> measurable M (embed_measure M f)"
13.134 +  from inj have Mf[measurable]: "f \<in> measurable M (embed_measure M f)"
13.135      by (rule measurable_embed_measure2)
13.136 -  from Mg and X have "emeasure ?M1 X = \<integral>\<^sup>+ x. g x * indicator X x \<partial>embed_measure M f"
13.137 +  from Mg and X have "emeasure ?M1 X = \<integral>\<^sup>+ x. g x * indicator X x \<partial>embed_measure M f"
13.138      by (subst emeasure_density) simp_all
13.139    also from X have "... = \<integral>\<^sup>+ x. g (f x) * indicator X (f x) \<partial>M"
13.140 -    by (subst embed_measure_eq_distr[OF inj], subst nn_integral_distr)
13.141 -       (auto intro!: borel_measurable_ereal_times borel_measurable_indicator)
13.142 +    by (subst embed_measure_eq_distr[OF inj], subst nn_integral_distr) auto
13.143    also have "... = \<integral>\<^sup>+ x. g (f x) * indicator (f -` X \<inter> space M) x \<partial>M"
13.144      by (intro nn_integral_cong) (auto split: split_indicator)
13.145    also from X have "... = emeasure (density M (g \<circ> f)) (f -` X \<inter> space M)"
13.146      by (subst emeasure_density) (simp_all add: measurable_comp[OF Mf Mg] measurable_sets[OF Mf])
13.147 -  also from X and inj have "... = emeasure ?M2 X"
13.148 +  also from X and inj have "... = emeasure ?M2 X"
13.149      by (subst emeasure_embed_measure) (simp_all add: sets_embed_measure)
13.150    finally show "emeasure ?M1 X = emeasure ?M2 X" .
13.151  qed (simp_all add: sets_embed_measure inj)
13.152 @@ -297,7 +296,7 @@
13.153  proof-
13.154    have "density (embed_measure M f) (g \<circ> f') = embed_measure (density M (g \<circ> f' \<circ> f)) f"
13.155      by (rule density_embed_measure[OF inj])
13.156 -       (rule measurable_comp, rule measurable_embed_measure1, subst measurable_cong,
13.157 +       (rule measurable_comp, rule measurable_embed_measure1, subst measurable_cong,
13.158          rule inv, rule measurable_ident_sets, simp, rule Mg)
13.159    also have "density M (g \<circ> f' \<circ> f) = density M g"
13.160      by (intro density_cong) (subst measurable_cong, simp add: o_def inv, simp_all add: Mg inv)
13.161 @@ -315,7 +314,7 @@
13.162    with assms and B have "x = y" by (auto dest: inj_onD)
13.163    with \<open>y \<in> B\<close> show "x \<in> B" by simp
13.164  qed auto
13.165 -
13.166 +
13.167
13.168  lemma AE_embed_measure':
13.169    assumes inj: "inj_on f (space M)"
13.170 @@ -326,7 +325,7 @@
13.171    then obtain A where A_props: "A \<in> sets ?M" "emeasure ?M A = 0" "{x\<in>space ?M. \<not>P x} \<subseteq> A"
13.172      by (force elim: AE_E)
13.173    then obtain A' where A'_props: "A = f ` A'" "A' \<in> sets M" by (auto simp: sets_embed_measure' inj)
13.174 -  moreover have B: "{x\<in>space ?M. \<not>P x} = f ` {x\<in>space M. \<not>P (f x)}"
13.175 +  moreover have B: "{x\<in>space ?M. \<not>P x} = f ` {x\<in>space M. \<not>P (f x)}"
13.176      by (auto simp: inj space_embed_measure)
13.177    from A_props(3) have "{x\<in>space M. \<not>P (f x)} \<subseteq> A'"
13.178      by (subst (asm) B, subst (asm) A'_props, subst (asm) inj_on_image_subset_iff[OF inj])
13.179 @@ -350,7 +349,7 @@
13.180    using assms by (intro AE_embed_measure') (auto intro!: inj_onI dest: injD)
13.181
13.182  lemma nn_integral_monotone_convergence_SUP_countable:
13.183 -  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> ereal"
13.184 +  fixes f :: "'a \<Rightarrow> 'b \<Rightarrow> ennreal"
13.185    assumes nonempty: "Y \<noteq> {}"
13.186    and chain: "Complete_Partial_Order.chain op \<le> (f ` Y)"
13.187    and countable: "countable B"
13.188 @@ -363,17 +362,17 @@
13.189    also have "\<dots> = \<integral>\<^sup>+ x. (SUP i:Y. f i (from_nat_into B x)) \<partial>count_space (to_nat_on B ` B)"
13.190      by(simp add: embed_measure_count_space'[symmetric] inj_on_to_nat_on countable nn_integral_embed_measure' measurable_embed_measure1)
13.191    also have "\<dots> = \<integral>\<^sup>+ x. (SUP i:Y. ?f i x) \<partial>count_space UNIV"
13.192 -    by(simp add: nn_integral_count_space_indicator ereal_indicator[symmetric] Sup_ereal_mult_right' nonempty)
13.193 -  also have "\<dots> = (SUP i:Y. \<integral>\<^sup>+ x. ?f i x \<partial>count_space UNIV)" using nonempty
13.194 +    by(simp add: nn_integral_count_space_indicator ennreal_indicator[symmetric] SUP_mult_right_ennreal nonempty)
13.195 +  also have "\<dots> = (SUP i:Y. \<integral>\<^sup>+ x. ?f i x \<partial>count_space UNIV)"
13.196    proof(rule nn_integral_monotone_convergence_SUP_nat)
13.197      show "Complete_Partial_Order.chain op \<le> (?f ` Y)"
13.198        by(rule chain_imageI[OF chain, unfolded image_image])(auto intro!: le_funI split: split_indicator dest: le_funD)
13.199 -  qed
13.200 +  qed fact
13.201    also have "\<dots> = (SUP i:Y. \<integral>\<^sup>+ x. f i (from_nat_into B x) \<partial>count_space (to_nat_on B ` B))"
13.203    also have "\<dots> = (SUP i:Y. \<integral>\<^sup>+ x. f i (from_nat_into B (to_nat_on B x)) \<partial>count_space B)"
13.204      by(simp add: embed_measure_count_space'[symmetric] inj_on_to_nat_on countable nn_integral_embed_measure' measurable_embed_measure1)
13.205 -  also have "\<dots> = ?rhs"
13.206 +  also have "\<dots> = ?rhs"
13.207      by(intro arg_cong2[where f="SUPREMUM"] ext nn_integral_cong_AE)(simp_all add: AE_count_space countable)
13.208    finally show ?thesis .
13.209  qed
```
```    14.1 --- a/src/HOL/Probability/Finite_Product_Measure.thy	Thu Apr 14 12:17:44 2016 +0200
14.2 +++ b/src/HOL/Probability/Finite_Product_Measure.thy	Thu Apr 14 15:48:11 2016 +0200
14.3 @@ -116,7 +116,7 @@
14.4  definition prod_emb where
14.5    "prod_emb I M K X = (\<lambda>x. restrict x K) -` X \<inter> (PIE i:I. space (M i))"
14.6
14.7 -lemma prod_emb_iff:
14.8 +lemma prod_emb_iff:
14.9    "f \<in> prod_emb I M K X \<longleftrightarrow> f \<in> extensional I \<and> (restrict f K \<in> X) \<and> (\<forall>i\<in>I. f i \<in> space (M i))"
14.10    unfolding prod_emb_def PiE_def by auto
14.11
14.12 @@ -180,7 +180,7 @@
14.13
14.14  lemma Pi_cong_sets:
14.15      "\<lbrakk>I = J; \<And>x. x \<in> I \<Longrightarrow> M x = N x\<rbrakk> \<Longrightarrow> Pi I M = Pi J N"
14.16 -  unfolding Pi_def by auto
14.17 +  unfolding Pi_def by auto
14.18
14.19  lemma PiM_cong:
14.20    assumes "I = J" "\<And>x. x \<in> I \<Longrightarrow> M x = N x"
14.21 @@ -197,11 +197,11 @@
14.22    thus ?case by (auto simp: assms)
14.23  next
14.24    case 3
14.25 -  show ?case using assms
14.26 +  show ?case using assms
14.27      by (intro ext) (auto simp: prod_emb_def dest: PiE_mem)
14.28  next
14.29    case (4 x)
14.30 -  thus ?case using assms
14.31 +  thus ?case using assms
14.32      by (auto intro!: setprod.cong split: if_split_asm)
14.33  qed
14.34
14.35 @@ -251,7 +251,7 @@
14.36  lemma prod_algebraE:
14.37    assumes A: "A \<in> prod_algebra I M"
14.38    obtains J E where "A = prod_emb I M J (PIE j:J. E j)"
14.39 -    "finite J" "J \<noteq> {} \<or> I = {}" "J \<subseteq> I" "\<And>i. i \<in> J \<Longrightarrow> E i \<in> sets (M i)"
14.40 +    "finite J" "J \<noteq> {} \<or> I = {}" "J \<subseteq> I" "\<And>i. i \<in> J \<Longrightarrow> E i \<in> sets (M i)"
14.41    using A by (auto simp: prod_algebra_def)
14.42
14.43  lemma prod_algebraE_all:
14.44 @@ -276,7 +276,7 @@
14.45    from prod_algebraE[OF this] guess J E . note A = this
14.46    fix B assume "B \<in> prod_algebra I M"
14.47    from prod_algebraE[OF this] guess K F . note B = this
14.48 -  have "A \<inter> B = prod_emb I M (J \<union> K) (\<Pi>\<^sub>E i\<in>J \<union> K. (if i \<in> J then E i else space (M i)) \<inter>
14.49 +  have "A \<inter> B = prod_emb I M (J \<union> K) (\<Pi>\<^sub>E i\<in>J \<union> K. (if i \<in> J then E i else space (M i)) \<inter>
14.50        (if i \<in> K then F i else space (M i)))"
14.51      unfolding A B using A(2,3,4) A(5)[THEN sets.sets_into_space] B(2,3,4)
14.52        B(5)[THEN sets.sets_into_space]
14.53 @@ -379,7 +379,7 @@
14.54    qed
14.55  next
14.56    fix A assume "A \<in> ?R"
14.57 -  then obtain i B where A: "A = {f\<in>\<Pi>\<^sub>E i\<in>I. space (M i). f i \<in> B}" "i \<in> I" "B \<in> sets (M i)"
14.58 +  then obtain i B where A: "A = {f\<in>\<Pi>\<^sub>E i\<in>I. space (M i). f i \<in> B}" "i \<in> I" "B \<in> sets (M i)"
14.59      by auto
14.60    then have "A = prod_emb I M {i} (\<Pi>\<^sub>E i\<in>{i}. B)"
14.61       by (auto simp: prod_emb_def)
14.62 @@ -409,7 +409,7 @@
14.63    defines "P \<equiv> {{f\<in>(\<Pi>\<^sub>E i\<in>I. \<Omega> i). \<forall>i\<in>j. f i \<in> A i} | A j. j \<in> J \<and> A \<in> Pi j E}"
14.64    shows "sets (\<Pi>\<^sub>M i\<in>I. sigma (\<Omega> i) (E i)) = sets (sigma (\<Pi>\<^sub>E i\<in>I. \<Omega> i) P)"
14.65  proof cases
14.66 -  assume "I = {}"
14.67 +  assume "I = {}"
14.68    with \<open>\<Union>J = I\<close> have "P = {{\<lambda>_. undefined}} \<or> P = {}"
14.69      by (auto simp: P_def)
14.70    with \<open>I = {}\<close> show ?thesis
14.71 @@ -417,7 +417,7 @@
14.72  next
14.73    let ?F = "\<lambda>i. {(\<lambda>x. x i) -` A \<inter> Pi\<^sub>E I \<Omega> |A. A \<in> E i}"
14.74    assume "I \<noteq> {}"
14.75 -  then have "sets (Pi\<^sub>M I (\<lambda>i. sigma (\<Omega> i) (E i))) =
14.76 +  then have "sets (Pi\<^sub>M I (\<lambda>i. sigma (\<Omega> i) (E i))) =
14.77        sets (\<Squnion>\<^sub>\<sigma> i\<in>I. vimage_algebra (\<Pi>\<^sub>E i\<in>I. \<Omega> i) (\<lambda>x. x i) (sigma (\<Omega> i) (E i)))"
14.78      by (subst sets_PiM_eq_proj) (auto simp: space_measure_of_conv)
14.79    also have "\<dots> = sets (\<Squnion>\<^sub>\<sigma> i\<in>I. sigma (Pi\<^sub>E I \<Omega>) (?F i))"
14.80 @@ -520,7 +520,7 @@
14.81  lemma measurable_PiM:
14.82    assumes space: "f \<in> space N \<rightarrow> (\<Pi>\<^sub>E i\<in>I. space (M i))"
14.83    assumes sets: "\<And>X J. J \<noteq> {} \<or> I = {} \<Longrightarrow> finite J \<Longrightarrow> J \<subseteq> I \<Longrightarrow> (\<And>i. i \<in> J \<Longrightarrow> X i \<in> sets (M i)) \<Longrightarrow>
14.84 -    f -` prod_emb I M J (Pi\<^sub>E J X) \<inter> space N \<in> sets N"
14.85 +    f -` prod_emb I M J (Pi\<^sub>E J X) \<inter> space N \<in> sets N"
14.86    shows "f \<in> measurable N (PiM I M)"
14.87    using sets_PiM prod_algebra_sets_into_space space
14.88  proof (rule measurable_sigma_sets)
14.89 @@ -532,7 +532,7 @@
14.90  lemma measurable_PiM_Collect:
14.91    assumes space: "f \<in> space N \<rightarrow> (\<Pi>\<^sub>E i\<in>I. space (M i))"
14.92    assumes sets: "\<And>X J. J \<noteq> {} \<or> I = {} \<Longrightarrow> finite J \<Longrightarrow> J \<subseteq> I \<Longrightarrow> (\<And>i. i \<in> J \<Longrightarrow> X i \<in> sets (M i)) \<Longrightarrow>
14.93 -    {\<omega>\<in>space N. \<forall>i\<in>J. f \<omega> i \<in> X i} \<in> sets N"
14.94 +    {\<omega>\<in>space N. \<forall>i\<in>J. f \<omega> i \<in> X i} \<in> sets N"
14.95    shows "f \<in> measurable N (PiM I M)"
14.96    using sets_PiM prod_algebra_sets_into_space space
14.97  proof (rule measurable_sigma_sets)
14.98 @@ -546,7 +546,7 @@
14.99
14.100  lemma measurable_PiM_single:
14.101    assumes space: "f \<in> space N \<rightarrow> (\<Pi>\<^sub>E i\<in>I. space (M i))"
14.102 -  assumes sets: "\<And>A i. i \<in> I \<Longrightarrow> A \<in> sets (M i) \<Longrightarrow> {\<omega> \<in> space N. f \<omega> i \<in> A} \<in> sets N"
14.103 +  assumes sets: "\<And>A i. i \<in> I \<Longrightarrow> A \<in> sets (M i) \<Longrightarrow> {\<omega> \<in> space N. f \<omega> i \<in> A} \<in> sets N"
14.104    shows "f \<in> measurable N (PiM I M)"
14.105    using sets_PiM_single
14.106  proof (rule measurable_sigma_sets)
14.107 @@ -602,7 +602,7 @@
14.108      "\<And>j. i = Suc j \<Longrightarrow> (\<lambda>x. g x j) \<in> measurable M N"
14.109    shows "(\<lambda>x. case_nat (f x) (g x) i) \<in> measurable M N"
14.110    by (cases i) simp_all
14.111 -
14.112 +
14.113  lemma measurable_case_nat'[measurable (raw)]:
14.114    assumes fg[measurable]: "f \<in> measurable N M" "g \<in> measurable N (\<Pi>\<^sub>M i\<in>UNIV. M)"
14.115    shows "(\<lambda>x. case_nat (f x) (g x)) \<in> measurable N (\<Pi>\<^sub>M i\<in>UNIV. M)"
14.116 @@ -666,7 +666,7 @@
14.117      using A X by (auto intro!: measurable_sets)
14.118  qed (insert X, auto simp add: PiE_def dest: measurable_space)
14.119
14.120 -lemma measurable_abs_UNIV:
14.121 +lemma measurable_abs_UNIV:
14.122    "(\<And>n. (\<lambda>\<omega>. f n \<omega>) \<in> measurable M (N n)) \<Longrightarrow> (\<lambda>\<omega> n. f n \<omega>) \<in> measurable M (PiM UNIV N)"
14.123    by (intro measurable_PiM_single) (auto dest: measurable_space)
14.124
14.125 @@ -705,7 +705,7 @@
14.126    fix x assume "x \<in> X"
14.127    obtain \<omega> where "\<omega> \<in> space (PiM I M)"
14.128      using ne by blast
14.129 -  from merge_in_prod_emb[OF this \<open>x\<in>X\<close> X J] * show "x \<in> {}" by auto
14.130 +  from merge_in_prod_emb[OF this \<open>x\<in>X\<close> X J] * show "x \<in> {}" by auto
14.131  qed
14.132
14.133  lemma sets_in_Pi_aux:
14.134 @@ -775,7 +775,7 @@
14.135    show ?case
14.136    proof (intro exI[of _ "\<Union>i. J i"] bexI[of _ "\<Union>i. prod_emb (\<Union>i. J i) M (J i) (X i)"] conjI)
14.137      show "(\<Union>i. J i) \<subseteq> I" "countable (\<Union>i. J i)" using J by auto
14.138 -    with J show "UNION UNIV K = prod_emb I M (\<Union>i. J i) (\<Union>i. prod_emb (\<Union>i. J i) M (J i) (X i))"
14.139 +    with J show "UNION UNIV K = prod_emb I M (\<Union>i. J i) (\<Union>i. prod_emb (\<Union>i. J i) M (J i) (X i))"
14.140        by (simp add: K[abs_def] SUP_upper)
14.141    qed(auto intro: X)
14.142  qed
14.143 @@ -867,7 +867,7 @@
14.144
14.145  lemma emeasure_PiM_empty[simp]: "emeasure (PiM {} M) {\<lambda>_. undefined} = 1"
14.146  proof -
14.147 -  let ?\<mu> = "\<lambda>A. if A = {} then 0 else (1::ereal)"
14.148 +  let ?\<mu> = "\<lambda>A. if A = {} then 0 else (1::ennreal)"
14.149    have "emeasure (Pi\<^sub>M {} M) (prod_emb {} M {} (\<Pi>\<^sub>E i\<in>{}. {})) = 1"
14.150    proof (subst emeasure_extend_measure_Pair[OF PiM_def])
14.151      show "positive (PiM {} M) ?\<mu>"
14.152 @@ -883,7 +883,7 @@
14.153  qed
14.154
14.155  lemma PiM_empty: "PiM {} M = count_space {\<lambda>_. undefined}"
14.156 -  by (rule measure_eqI) (auto simp add: sets_PiM_empty one_ereal_def)
14.157 +  by (rule measure_eqI) (auto simp add: sets_PiM_empty)
14.158
14.159  lemma (in product_sigma_finite) emeasure_PiM:
14.160    "finite I \<Longrightarrow> (\<And>i. i\<in>I \<Longrightarrow> A i \<in> sets (M i)) \<Longrightarrow> emeasure (PiM I M) (Pi\<^sub>E I A) = (\<Prod>i\<in>I. emeasure (M i) (A i))"
14.161 @@ -956,11 +956,11 @@
14.162        by (simp add: eq emeasure_PiM)
14.163      def A \<equiv> "\<lambda>n. \<Pi>\<^sub>E i\<in>I. C i n"
14.164      with C show "range A \<subseteq> prod_algebra I M" "\<And>i. emeasure (Pi\<^sub>M I M) (A i) \<noteq> \<infinity>" "(\<Union>i. A i) = space (PiM I M)"
14.165 -      by (auto intro!: prod_algebraI_finite simp: emeasure_PiM subset_eq setprod_PInf emeasure_nonneg)
14.166 +      by (auto intro!: prod_algebraI_finite simp: emeasure_PiM subset_eq ennreal_setprod_eq_top)
14.167    qed
14.168  qed
14.169
14.170 -lemma (in product_sigma_finite) sigma_finite:
14.171 +lemma (in product_sigma_finite) sigma_finite:
14.172    assumes "finite I"
14.173    shows "sigma_finite_measure (PiM I M)"
14.174  proof
14.175 @@ -975,7 +975,7 @@
14.176    ultimately show "\<exists>A. countable A \<and> A \<subseteq> sets (Pi\<^sub>M I M) \<and> \<Union>A = space (Pi\<^sub>M I M) \<and> (\<forall>a\<in>A. emeasure (Pi\<^sub>M I M) a \<noteq> \<infinity>)"
14.177      by (intro exI[of _ "PiE I ` PiE I F"])
14.178         (auto intro!: countable_PiE sets_PiM_I_finite
14.179 -             simp: PiE_iff emeasure_PiM finite_index setprod_PInf emeasure_nonneg)
14.180 +             simp: PiE_iff emeasure_PiM finite_index ennreal_setprod_eq_top)
14.181  qed
14.182
14.183  sublocale finite_product_sigma_finite \<subseteq> sigma_finite_measure "Pi\<^sub>M I M"
14.184 @@ -1007,7 +1007,7 @@
14.185
14.186  lemma (in product_sigma_finite) product_nn_integral_fold:
14.187    assumes IJ: "I \<inter> J = {}" "finite I" "finite J"
14.188 -  and f: "f \<in> borel_measurable (Pi\<^sub>M (I \<union> J) M)"
14.189 +  and f[measurable]: "f \<in> borel_measurable (Pi\<^sub>M (I \<union> J) M)"
14.190    shows "integral\<^sup>N (Pi\<^sub>M (I \<union> J) M) f =
14.191      (\<integral>\<^sup>+ x. (\<integral>\<^sup>+ y. f (merge I J (x, y)) \<partial>(Pi\<^sub>M J M)) \<partial>(Pi\<^sub>M I M))"
14.192  proof -
14.193 @@ -1018,7 +1018,8 @@
14.194      using measurable_comp[OF measurable_merge f] by (simp add: comp_def)
14.195    show ?thesis
14.196      apply (subst distr_merge[OF IJ, symmetric])
14.197 -    apply (subst nn_integral_distr[OF measurable_merge f])
14.198 +    apply (subst nn_integral_distr[OF measurable_merge])
14.199 +    apply measurable []
14.200      apply (subst J.nn_integral_fst[symmetric, OF P_borel])
14.201      apply simp
14.202      done
14.203 @@ -1084,26 +1085,25 @@
14.204    done
14.205
14.206  lemma (in product_sigma_finite) product_nn_integral_setprod:
14.207 -  fixes f :: "'i \<Rightarrow> 'a \<Rightarrow> ereal"
14.208 -  assumes "finite I" and borel: "\<And>i. i \<in> I \<Longrightarrow> f i \<in> borel_measurable (M i)"
14.209 -  and pos: "\<And>i x. i \<in> I \<Longrightarrow> 0 \<le> f i x"
14.210 +  assumes "finite I" "\<And>i. i \<in> I \<Longrightarrow> f i \<in> borel_measurable (M i)"
14.211    shows "(\<integral>\<^sup>+ x. (\<Prod>i\<in>I. f i (x i)) \<partial>Pi\<^sub>M I M) = (\<Prod>i\<in>I. integral\<^sup>N (M i) (f i))"
14.212 -using assms proof induct
14.213 +using assms proof (induction I)
14.214    case (insert i I)
14.215 +  note insert.prems[measurable]
14.216    note \<open>finite I\<close>[intro, simp]
14.217    interpret I: finite_product_sigma_finite M I by standard auto
14.218    have *: "\<And>x y. (\<Prod>j\<in>I. f j (if j = i then y else x j)) = (\<Prod>j\<in>I. f j (x j))"
14.219      using insert by (auto intro!: setprod.cong)
14.220    have prod: "\<And>J. J \<subseteq> insert i I \<Longrightarrow> (\<lambda>x. (\<Prod>i\<in>J. f i (x i))) \<in> borel_measurable (Pi\<^sub>M J M)"
14.221      using sets.sets_into_space insert
14.222 -    by (intro borel_measurable_ereal_setprod
14.223 +    by (intro borel_measurable_setprod_ennreal
14.224                measurable_comp[OF measurable_component_singleton, unfolded comp_def])
14.225         auto
14.226    then show ?case
14.227 -    apply (simp add: product_nn_integral_insert[OF insert(1,2) prod])
14.228 -    apply (simp add: insert(2-) * pos borel setprod_ereal_pos nn_integral_multc)
14.229 +    apply (simp add: product_nn_integral_insert[OF insert(1,2)])
14.230 +    apply (simp add: insert(2-) * nn_integral_multc)
14.231      apply (subst nn_integral_cmult)
14.232 -    apply (auto simp add: pos borel insert(2-) setprod_ereal_pos nn_integral_nonneg)
14.233 +    apply (auto simp add: insert(2-))
14.234      done
14.236
```
```    15.1 --- a/src/HOL/Probability/Giry_Monad.thy	Thu Apr 14 12:17:44 2016 +0200
15.2 +++ b/src/HOL/Probability/Giry_Monad.thy	Thu Apr 14 15:48:11 2016 +0200
15.3 @@ -7,7 +7,7 @@
15.4  *)
15.5
15.7 -  imports Probability_Measure Lebesgue_Integral_Substitution "~~/src/HOL/Library/Monad_Syntax"
15.8 +  imports Probability_Measure Lebesgue_Integral_Substitution "~~/src/HOL/Library/Monad_Syntax"
15.9  begin
15.10
15.11  section \<open>Sub-probability spaces\<close>
15.12 @@ -23,7 +23,7 @@
15.13  proof -
15.14    interpret finite_measure M
15.15    proof
15.16 -    show "emeasure M (space M) \<noteq> \<infinity>" using * by auto
15.17 +    show "emeasure M (space M) \<noteq> \<infinity>" using * by (auto simp: top_unique)
15.18    qed
15.19    show "subprob_space M" by standard fact+
15.20  qed
15.21 @@ -66,8 +66,8 @@
15.22    have "(\<integral>\<^sup>+ x. f x \<partial>M) \<le> (\<integral>\<^sup>+ x. c \<partial>M)"
15.23      by(rule nn_integral_mono_AE) fact
15.24    also have "\<dots> \<le> c * emeasure M (space M)"
15.25 -    using \<open>0 \<le> c\<close> by(simp add: nn_integral_const_If)
15.26 -  also have "\<dots> \<le> c * 1" using emeasure_space_le_1 \<open>0 \<le> c\<close> by(rule ereal_mult_left_mono)
15.27 +    using \<open>0 \<le> c\<close> by simp
15.28 +  also have "\<dots> \<le> c * 1" using emeasure_space_le_1 \<open>0 \<le> c\<close> by(rule mult_left_mono)
15.29    finally show ?thesis by simp
15.30  qed
15.31
15.32 @@ -84,7 +84,7 @@
15.33    assumes contg': "continuous_on {a..b} g'"
15.34    assumes mono: "strict_mono_on g {a..b}" and inv: "\<And>x. h x \<in> {a..b} \<Longrightarrow> g (h x) = x"
15.35    assumes range: "{a..b} \<subseteq> range h"
15.36 -  shows "emeasure (distr (density lborel f) lborel h) {a..b} =
15.37 +  shows "emeasure (distr (density lborel f) lborel h) {a..b} =
15.38               emeasure (density lborel (\<lambda>x. f (g x) * g' x)) {a..b}"
15.39  proof (cases "a < b")
15.40    assume "a < b"
15.41 @@ -109,18 +109,18 @@
15.42
15.43    have prob': "subprob_space (distr (density lborel f) lborel h)"
15.44      by (rule subprob_space.subprob_space_distr[OF prob]) (simp_all add: Mh)
15.45 -  have B: "emeasure (distr (density lborel f) lborel h) {a..b} =
15.46 +  have B: "emeasure (distr (density lborel f) lborel h) {a..b} =
15.47              \<integral>\<^sup>+x. f x * indicator (h -` {a..b}) x \<partial>lborel"
15.48      by (subst emeasure_distr) (simp_all add: emeasure_density Mf Mh measurable_sets_borel[OF Mh])
15.49    also note A
15.50    also have "emeasure (distr (density lborel f) lborel h) {a..b} \<le> 1"
15.51      by (rule subprob_space.subprob_emeasure_le_1) (rule prob')
15.52 -  hence "emeasure (distr (density lborel f) lborel h) {a..b} \<noteq> \<infinity>" by auto
15.53 -  with assms have "(\<integral>\<^sup>+x. f x * indicator {g a..g b} x \<partial>lborel) =
15.54 +  hence "emeasure (distr (density lborel f) lborel h) {a..b} \<noteq> \<infinity>" by (auto simp: top_unique)
15.55 +  with assms have "(\<integral>\<^sup>+x. f x * indicator {g a..g b} x \<partial>lborel) =
15.56                        (\<integral>\<^sup>+x. f (g x) * g' x * indicator {a..b} x \<partial>lborel)"
15.57      by (intro nn_integral_substitution_aux)
15.58         (auto simp: derivg_nonneg A B emeasure_density mult.commute \<open>a < b\<close>)
15.59 -  also have "... = emeasure (density lborel (\<lambda>x. f (g x) * g' x)) {a..b}"
15.60 +  also have "... = emeasure (density lborel (\<lambda>x. f (g x) * g' x)) {a..b}"
15.62    finally show ?thesis .
15.63  next
15.64 @@ -130,16 +130,14 @@
15.65    thus ?thesis by (simp_all add: emeasure_distr emeasure_density measurable_sets_borel[OF Mh])
15.66  qed
15.67
15.68 -locale pair_subprob_space =
15.69 +locale pair_subprob_space =
15.70    pair_sigma_finite M1 M2 + M1: subprob_space M1 + M2: subprob_space M2 for M1 M2
15.71
15.72  sublocale pair_subprob_space \<subseteq> P?: subprob_space "M1 \<Otimes>\<^sub>M M2"
15.73  proof
15.74 -  have "\<And>a b. \<lbrakk>a \<ge> 0; b \<ge> 0; a \<le> 1; b \<le> 1\<rbrakk> \<Longrightarrow> a * b \<le> (1::ereal)"
15.75 -    by (metis monoid_mult_class.mult.left_neutral dual_order.trans ereal_mult_right_mono)
15.76 -  from this[OF _ _ M1.emeasure_space_le_1 M2.emeasure_space_le_1]
15.77 -    show "emeasure (M1 \<Otimes>\<^sub>M M2) (space (M1 \<Otimes>\<^sub>M M2)) \<le> 1"
15.78 -    by (simp add: M2.emeasure_pair_measure_Times space_pair_measure emeasure_nonneg)
15.79 +  from mult_le_one[OF M1.emeasure_space_le_1 _ M2.emeasure_space_le_1]
15.80 +  show "emeasure (M1 \<Otimes>\<^sub>M M2) (space (M1 \<Otimes>\<^sub>M M2)) \<le> 1"
15.81 +    by (simp add: M2.emeasure_pair_measure_Times space_pair_measure)
15.82    from M1.subprob_not_empty and M2.subprob_not_empty show "space (M1 \<Otimes>\<^sub>M M2) \<noteq> {}"
15.84  qed
15.85 @@ -172,10 +170,14 @@
15.86  lemma subprob_algebra_cong: "sets M = sets N \<Longrightarrow> subprob_algebra M = subprob_algebra N"
15.88
15.89 -lemma measurable_emeasure_subprob_algebra[measurable]:
15.90 +lemma measurable_emeasure_subprob_algebra[measurable]:
15.91    "a \<in> sets A \<Longrightarrow> (\<lambda>M. emeasure M a) \<in> borel_measurable (subprob_algebra A)"
15.92    by (auto intro!: measurable_Sup_sigma1 measurable_vimage_algebra1 simp: subprob_algebra_def)
15.93
15.94 +lemma measurable_measure_subprob_algebra[measurable]:
15.95 +  "a \<in> sets A \<Longrightarrow> (\<lambda>M. measure M a) \<in> borel_measurable (subprob_algebra A)"
15.96 +  unfolding measure_def by measurable
15.97 +
15.98  lemma subprob_measurableD:
15.99    assumes N: "N \<in> measurable M (subprob_algebra S)" and x: "x \<in> space M"
15.100    shows "space (N x) = space S"
15.101 @@ -214,7 +216,7 @@
15.102  lemma sets_kernel: "a \<in> space M \<Longrightarrow> sets (K a) = sets N"
15.103    using measurable_space[OF K] by (simp add: space_subprob_algebra)
15.104
15.105 -lemma measurable_emeasure_kernel[measurable]:
15.106 +lemma measurable_emeasure_kernel[measurable]:
15.107      "A \<in> sets N \<Longrightarrow> (\<lambda>a. emeasure (K a) A) \<in> borel_measurable M"
15.108    using measurable_compose[OF K measurable_emeasure_subprob_algebra] .
15.109
15.110 @@ -258,8 +260,8 @@
15.111    ultimately show "space (subprob_algebra N) = {}" by (auto simp: space_subprob_algebra)
15.112  qed
15.113
15.114 -lemma nn_integral_measurable_subprob_algebra':
15.115 -  assumes f: "f \<in> borel_measurable N" "\<And>x. 0 \<le> f x"
15.116 +lemma nn_integral_measurable_subprob_algebra[measurable]:
15.117 +  assumes f: "f \<in> borel_measurable N"
15.118    shows "(\<lambda>M. integral\<^sup>N M f) \<in> borel_measurable (subprob_algebra N)" (is "_ \<in> ?B")
15.119    using f
15.120  proof induct
15.121 @@ -295,11 +297,6 @@
15.123  qed
15.124
15.125 -lemma nn_integral_measurable_subprob_algebra:
15.126 -  "f \<in> borel_measurable N \<Longrightarrow> (\<lambda>M. integral\<^sup>N M f) \<in> borel_measurable (subprob_algebra N)"
15.127 -  by (subst nn_integral_max_0[symmetric])
15.128 -     (auto intro!: nn_integral_measurable_subprob_algebra')
15.129 -
15.130  lemma measurable_distr:
15.131    assumes [measurable]: "f \<in> measurable M N"
15.132    shows "(\<lambda>M'. distr M' N f) \<in> measurable (subprob_algebra M) (subprob_algebra N)"
15.133 @@ -329,33 +326,56 @@
15.134    finally show ?thesis .
15.135  qed
15.136
15.137 -lemma integral_measurable_subprob_algebra:
15.138 -  fixes f :: "_ \<Rightarrow> real"
15.139 -  assumes f_measurable [measurable]: "f \<in> borel_measurable N"
15.140 -  and f_bounded: "\<And>x. x \<in> space N \<Longrightarrow> \<bar>f x\<bar> \<le> B"
15.141 -  shows "(\<lambda>M. integral\<^sup>L M f) \<in> borel_measurable (subprob_algebra N)"
15.142 +lemma integrable_measurable_subprob_algebra[measurable]:
15.143 +  fixes f :: "'a \<Rightarrow> 'b::{banach, second_countable_topology}"
15.144 +  assumes [measurable]: "f \<in> borel_measurable N"
15.145 +  shows "Measurable.pred (subprob_algebra N) (\<lambda>M. integrable M f)"
15.146 +proof (rule measurable_cong[THEN iffD2])
15.147 +  show "M \<in> space (subprob_algebra N) \<Longrightarrow> integrable M f \<longleftrightarrow> (\<integral>\<^sup>+x. norm (f x) \<partial>M) < \<infinity>" for M
15.148 +    by (auto simp: space_subprob_algebra integrable_iff_bounded)
15.149 +qed measurable
15.150 +
15.151 +lemma integral_measurable_subprob_algebra[measurable]:
15.152 +  fixes f :: "'a \<Rightarrow> 'b::{banach, second_countable_topology}"
15.153 +  assumes f [measurable]: "f \<in> borel_measurable N"
15.154 +  shows "(\<lambda>M. integral\<^sup>L M f) \<in> subprob_algebra N \<rightarrow>\<^sub>M borel"
15.155  proof -
15.156 -  note [measurable] = nn_integral_measurable_subprob_algebra
15.157 -  have "?thesis \<longleftrightarrow> (\<lambda>M. real_of_ereal (\<integral>\<^sup>+ x. f x \<partial>M) - real_of_ereal (\<integral>\<^sup>+ x. - f x \<partial>M)) \<in> borel_measurable (subprob_algebra N)"
15.158 -  proof(rule measurable_cong)
15.159 -    fix M
15.160 -    assume "M \<in> space (subprob_algebra N)"
15.161 -    hence "subprob_space M" and M [measurable_cong]: "sets M = sets N"
15.163 +  from borel_measurable_implies_sequence_metric[OF f, of 0]
15.164 +  obtain F where F: "\<And>i. simple_function N (F i)"
15.165 +    "\<And>x. x \<in> space N \<Longrightarrow> (\<lambda>i. F i x) \<longlonglongrightarrow> f x"
15.166 +    "\<And>i x. x \<in> space N \<Longrightarrow> norm (F i x) \<le> 2 * norm (f x)"
15.167 +    unfolding norm_conv_dist by blast
15.168 +
15.169 +  have [measurable]: "F i \<in> N \<rightarrow>\<^sub>M count_space UNIV" for i
15.170 +    using F(1) by (rule measurable_simple_function)
15.171 +
15.172 +  def F' \<equiv> "\<lambda>M i. if integrable M f then integral\<^sup>L M (F i) else 0"
15.173 +
15.174 +  have "(\<lambda>M. F' M i) \<in> subprob_algebra N \<rightarrow>\<^sub>M borel" for i
15.175 +  proof (rule measurable_cong[THEN iffD2])
15.176 +    fix M assume "M \<in> space (subprob_algebra N)"
15.177 +    then have [simp]: "sets M = sets N" "space M = space N" "subprob_space M"
15.178 +      by (auto simp: space_subprob_algebra intro!: sets_eq_imp_space_eq)
15.179      interpret subprob_space M by fact
15.180 -    have "(\<integral>\<^sup>+ x. ereal \<bar>f x\<bar> \<partial>M) \<le> (\<integral>\<^sup>+ x. ereal B \<partial>M)"
15.181 -      by(rule nn_integral_mono)(simp add: sets_eq_imp_space_eq[OF M] f_bounded)
15.182 -    also have "\<dots> = max B 0 * emeasure M (space M)" by(simp add: nn_integral_const_If max_def)
15.183 -    also have "\<dots> \<le> ereal (max B 0) * 1"
15.184 -      by(rule ereal_mult_left_mono)(simp_all add: emeasure_space_le_1 zero_ereal_def)
15.185 -    finally have "(\<integral>\<^sup>+ x. ereal \<bar>f x\<bar> \<partial>M) \<noteq> \<infinity>" by(auto simp add: max_def)
15.186 -    then have "integrable M f" using f_measurable
15.187 -      by(auto intro: integrableI_bounded)
15.188 -    thus "(\<integral> x. f x \<partial>M) = real_of_ereal (\<integral>\<^sup>+ x. f x \<partial>M) - real_of_ereal (\<integral>\<^sup>+ x. - f x \<partial>M)"
15.190 -  qed
15.191 -  also have "\<dots>" by measurable
15.192 -  finally show ?thesis .
15.193 +    have "F' M i = (if integrable M f then Bochner_Integration.simple_bochner_integral M (F i) else 0)"
15.194 +      using F(1)
15.195 +      by (subst simple_bochner_integrable_eq_integral)
15.196 +         (auto simp: simple_bochner_integrable.simps simple_function_def F'_def)
15.197 +    then show "F' M i = (if integrable M f then \<Sum>y\<in>F i ` space N. measure M {x\<in>space N. F i x = y} *\<^sub>R y else 0)"
15.198 +      unfolding simple_bochner_integral_def by simp
15.199 +  qed measurable
15.200 +  moreover
15.201 +  have "F' M \<longlonglongrightarrow> integral\<^sup>L M f" if M: "M \<in> space (subprob_algebra N)" for M
15.202 +  proof cases
15.203 +    from M have [simp]: "sets M = sets N" "space M = space N"
15.204 +      by (auto simp: space_subprob_algebra intro!: sets_eq_imp_space_eq)
15.205 +    assume "integrable M f" then show ?thesis
15.206 +      unfolding F'_def using F(1)[THEN borel_measurable_simple_function] F
15.207 +      by (auto intro!: integral_dominated_convergence[where w="\<lambda>x. 2 * norm (f x)"]
15.208 +               cong: measurable_cong_sets)
15.209 +  qed (auto simp: F'_def not_integrable_integral_eq)
15.210 +  ultimately show ?thesis
15.211 +    by (rule borel_measurable_LIMSEQ_metric)
15.212  qed
15.213
15.214  (* TODO: Rename. This name is too general -- Manuel *)
15.215 @@ -379,13 +399,13 @@
15.216        using fx gx by (simp add: space_subprob_algebra)
15.217
15.218      have 1: "\<And>A B. A \<in> sets N \<Longrightarrow> B \<in> sets L \<Longrightarrow> emeasure (f x \<Otimes>\<^sub>M g x) (A \<times> B) = emeasure (f x) A * emeasure (g x) B"
15.219 -      using fx gx by (intro G.emeasure_pair_measure_Times) (auto simp: space_subprob_algebra)
15.220 -    have "emeasure (f x \<Otimes>\<^sub>M g x) (space (f x \<Otimes>\<^sub>M g x)) =
15.221 +      using fx gx by (intro G.emeasure_pair_measure_Times) (auto simp: space_subprob_algebra)
15.222 +    have "emeasure (f x \<Otimes>\<^sub>M g x) (space (f x \<Otimes>\<^sub>M g x)) =
15.223                emeasure (f x) (space (f x)) * emeasure (g x) (space (g x))"
15.224        by (subst G.emeasure_pair_measure_Times[symmetric]) (simp_all add: space_pair_measure)
15.225      hence 2: "\<And>A. A \<in> sets (N \<Otimes>\<^sub>M L) \<Longrightarrow> emeasure (f x \<Otimes>\<^sub>M g x) (space N \<times> space L - A) =
15.226                                               ... - emeasure (f x \<Otimes>\<^sub>M g x) A"
15.227 -      using emeasure_compl[OF _ P.emeasure_finite]
15.228 +      using emeasure_compl[simplified, OF _ P.emeasure_finite]
15.229        unfolding sets_eq
15.230        unfolding sets_eq_imp_space_eq[OF sets_eq]
15.231        by (simp add: space_pair_measure G.emeasure_pair_measure_Times)
15.232 @@ -398,13 +418,13 @@
15.233      unfolding sets_pair_measure
15.234    proof (induct A rule: sigma_sets_induct_disjoint)
15.235      case (basic A) then show ?case
15.236 -      by (auto intro!: borel_measurable_ereal_times simp: Times cong: measurable_cong)
15.237 +      by (auto intro!: borel_measurable_times_ennreal simp: Times cong: measurable_cong)
15.238           (auto intro!: measurable_emeasure_kernel f g)
15.239    next
15.240      case (compl A)
15.241      then have A: "A \<in> sets (N \<Otimes>\<^sub>M L)"
15.242        by (auto simp: sets_pair_measure)
15.243 -    have "(\<lambda>x. emeasure (f x) (space (f x)) * emeasure (g x) (space (g x)) -
15.244 +    have "(\<lambda>x. emeasure (f x) (space (f x)) * emeasure (g x) (space (g x)) -
15.245                     emeasure (f x \<Otimes>\<^sub>M g x) A) \<in> borel_measurable M" (is "?f \<in> ?M")
15.246        using compl(2) f g by measurable
15.247      thus ?case by (simp add: Compl A cong: measurable_cong)
15.248 @@ -472,10 +492,10 @@
15.250
15.251  lemma measurable_return1[simp]: "measurable (return N x) L = measurable N L"
15.252 -  by (simp cong: measurable_cong_sets)
15.253 +  by (simp cong: measurable_cong_sets)
15.254
15.255  lemma measurable_return2[simp]: "measurable L (return N x) = measurable L N"
15.256 -  by (simp cong: measurable_cong_sets)
15.257 +  by (simp cong: measurable_cong_sets)
15.258
15.259  lemma return_sets_cong: "sets M = sets N \<Longrightarrow> return M = return N"
15.260    by (auto dest: sets_eq_imp_space_eq simp: fun_eq_iff return_def)
15.261 @@ -491,7 +511,7 @@
15.262    show "positive (sets (return M x)) (\<lambda>A. indicator A x)" by (simp add: positive_def)
15.263    from assms show "A \<in> sets (return M x)" unfolding return_def by simp
15.264    show "countably_additive (sets (return M x)) (\<lambda>A. indicator A x)"
15.265 -    by (auto intro: countably_additiveI simp: suminf_indicator)
15.266 +    by (auto intro!: countably_additiveI suminf_indicator)
15.267  qed
15.268
15.269  lemma prob_space_return: "x \<in> space M \<Longrightarrow> prob_space (return M x)"
15.270 @@ -500,7 +520,7 @@
15.271  lemma subprob_space_return: "x \<in> space M \<Longrightarrow> subprob_space (return M x)"
15.272    by (intro prob_space_return prob_space_imp_subprob_space)
15.273
15.274 -lemma subprob_space_return_ne:
15.275 +lemma subprob_space_return_ne:
15.276    assumes "space M \<noteq> {}" shows "subprob_space (return M x)"
15.277  proof
15.278    show "emeasure (return M x) (space (return M x)) \<le> 1"
15.279 @@ -520,16 +540,16 @@
15.280      by (rule AE_cong) auto
15.281    finally show ?thesis .
15.282  qed
15.283 -
15.284 +
15.285  lemma nn_integral_return:
15.286 -  assumes "g x \<ge> 0" "x \<in> space M" "g \<in> borel_measurable M"
15.287 +  assumes "x \<in> space M" "g \<in> borel_measurable M"
15.288    shows "(\<integral>\<^sup>+ a. g a \<partial>return M x) = g x"
15.289  proof-
15.290    interpret prob_space "return M x" by (rule prob_space_return[OF \<open>x \<in> space M\<close>])
15.291    have "(\<integral>\<^sup>+ a. g a \<partial>return M x) = (\<integral>\<^sup>+ a. g x \<partial>return M x)" using assms
15.292      by (intro nn_integral_cong_AE) (auto simp: AE_return)
15.293    also have "... = g x"
15.294 -    using nn_integral_const[OF \<open>g x \<ge> 0\<close>, of "return M x"] emeasure_space_1 by simp
15.295 +    using nn_integral_const[of "return M x"] emeasure_space_1 by simp
15.296    finally show ?thesis .
15.297  qed
15.298
15.299 @@ -640,14 +660,14 @@
15.300
15.301    have *: "\<And>x. fst x \<in> space M \<Longrightarrow> snd x \<in> A (fst x) \<longleftrightarrow> x \<in> (SIGMA x:space M. A x)"
15.302      by (auto simp: fun_eq_iff)
15.303 -  have "(\<lambda>(x, y). indicator (A x) y::ereal) \<in> borel_measurable (M \<Otimes>\<^sub>M N)"
15.304 +  have "(\<lambda>(x, y). indicator (A x) y::ennreal) \<in> borel_measurable (M \<Otimes>\<^sub>M N)"
15.305      apply measurable
15.306      apply (subst measurable_cong)
15.307      apply (rule *)
15.308      apply (auto simp: space_pair_measure)
15.309      done
15.310    then have "(\<lambda>x. integral\<^sup>N (L x) (indicator (A x))) \<in> borel_measurable M"
15.311 -    by (intro nn_integral_measurable_subprob_algebra2[where N=N] ereal_indicator_nonneg L)
15.312 +    by (intro nn_integral_measurable_subprob_algebra2[where N=N] L)
15.313    then show "(\<lambda>x. emeasure (L x) (A x)) \<in> borel_measurable M"
15.314      apply (rule measurable_cong[THEN iffD1, rotated])
15.315      apply (rule nn_integral_indicator)
15.316 @@ -660,7 +680,7 @@
15.317    assumes L[measurable]: "L \<in> measurable M (subprob_algebra N)"
15.318    shows "(\<lambda>x. measure (L x) (A x)) \<in> borel_measurable M"
15.319    unfolding measure_def
15.320 -  by (intro borel_measurable_real_of_ereal emeasure_measurable_subprob_algebra2[OF assms])
15.321 +  by (intro borel_measurable_enn2real emeasure_measurable_subprob_algebra2[OF assms])
15.322
15.323  definition "select_sets M = (SOME N. sets M = sets (subprob_algebra N))"
15.324
15.325 @@ -723,7 +743,7 @@
15.326      qed
15.327      finally show "(\<Sum>i. \<integral>\<^sup>+M'. emeasure M' (A i) \<partial>M) = (\<integral>\<^sup>+M'. emeasure M' (\<Union>i. A i) \<partial>M)" .
15.328    qed
15.329 -qed (auto simp: A sets.space_closed positive_def nn_integral_nonneg)
15.330 +qed (auto simp: A sets.space_closed positive_def)
15.331
15.332  lemma measurable_join:
15.333    "join \<in> measurable (subprob_algebra (subprob_algebra N)) (subprob_algebra N)"
15.334 @@ -745,7 +765,7 @@
15.335    fix M assume M: "M \<in> space (subprob_algebra (subprob_algebra N))"
15.336    then have "(\<integral>\<^sup>+M'. emeasure M' (space N) \<partial>M) \<le> (\<integral>\<^sup>+M'. 1 \<partial>M)"
15.337      apply (intro nn_integral_mono)
15.338 -    apply (auto simp: space_subprob_algebra
15.339 +    apply (auto simp: space_subprob_algebra
15.340                   dest!: sets_eq_imp_space_eq subprob_space.emeasure_space_le_1)
15.341      done
15.342    with M show "subprob_space (join M)"
15.343 @@ -756,8 +776,8 @@
15.344    thus ?thesis by (simp add: measurable_empty_iff space_subprob_algebra_empty_iff)
15.345  qed (auto simp: space_subprob_algebra)
15.346
15.347 -lemma nn_integral_join':
15.348 -  assumes f: "f \<in> borel_measurable N" "\<And>x. 0 \<le> f x"
15.349 +lemma nn_integral_join:
15.350 +  assumes f: "f \<in> borel_measurable N"
15.351      and M[measurable_cong]: "sets M = sets (subprob_algebra N)"
15.352    shows "(\<integral>\<^sup>+x. f x \<partial>join M) = (\<integral>\<^sup>+M'. \<integral>\<^sup>+x. f x \<partial>M' \<partial>M)"
15.353    using f
15.354 @@ -772,7 +792,7 @@
15.355      by simp
15.356  next
15.357    case (set A)
15.358 -  moreover with M have "(\<integral>\<^sup>+ M'. integral\<^sup>N M' (indicator A) \<partial>M) = (\<integral>\<^sup>+ M'. emeasure M' A \<partial>M)"
15.359 +  moreover with M have "(\<integral>\<^sup>+ M'. integral\<^sup>N M' (indicator A) \<partial>M) = (\<integral>\<^sup>+ M'. emeasure M' A \<partial>M)"
15.360      by (intro nn_integral_cong nn_integral_indicator)
15.361         (auto simp: space_subprob_algebra dest!: sets_eq_imp_space_eq)
15.362    ultimately show ?case
```