# HG changeset patch # User hoelzl # Date 1455006070 -3600 # Node ID 670063003ad33ef27ecc55ee29490ece38fdde56 # Parent cb27a55d868a1e36f56cc8254ac5512e82fa2f15 add extended nonnegative real numbers diff -r cb27a55d868a -r 670063003ad3 src/HOL/Library/Extended_Nonnegative_Real.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Library/Extended_Nonnegative_Real.thy Tue Feb 09 09:21:10 2016 +0100 @@ -0,0 +1,184 @@ +(* Title: HOL/Library/Extended_Nonnegative_Real.thy + Author: Johannes Hölzl +*) + +subsection \The type of non-negative extended real numbers\ + +theory Extended_Nonnegative_Real + imports Extended_Real +begin + +typedef ennreal = "{x :: ereal. 0 \ x}" + morphisms enn2ereal e2ennreal + by auto + +setup_lifting type_definition_ennreal + + +lift_definition ennreal :: "real \ ennreal" is "max 0 \ ereal" + by simp + +declare [[coercion ennreal]] +declare [[coercion e2ennreal]] + +instantiation ennreal :: semiring_1_no_zero_divisors +begin + +lift_definition one_ennreal :: ennreal is 1 by simp +lift_definition zero_ennreal :: ennreal is 0 by simp +lift_definition plus_ennreal :: "ennreal \ ennreal \ ennreal" is "op +" by simp +lift_definition times_ennreal :: "ennreal \ ennreal \ ennreal" is "op *" by simp + +instance + by standard (transfer; auto simp: field_simps ereal_right_distrib)+ + +end + +instance ennreal :: numeral .. + +instantiation ennreal :: inverse +begin + +lift_definition inverse_ennreal :: "ennreal \ ennreal" is inverse + by (rule inverse_ereal_ge0I) + +definition divide_ennreal :: "ennreal \ ennreal \ ennreal" + where "x div y = x * inverse (y :: ennreal)" + +instance .. + +end + + +instantiation ennreal :: complete_linorder +begin + +lift_definition top_ennreal :: ennreal is top by simp +lift_definition bot_ennreal :: ennreal is 0 by simp +lift_definition sup_ennreal :: "ennreal \ ennreal \ ennreal" is sup by (simp add: max.coboundedI1) +lift_definition inf_ennreal :: "ennreal \ ennreal \ ennreal" is inf by (simp add: min.boundedI) + +lift_definition Inf_ennreal :: "ennreal set \ ennreal" is "Inf" + by (auto intro: Inf_greatest) + +lift_definition Sup_ennreal :: "ennreal set \ ennreal" is "sup 0 \ Sup" + by auto + +lift_definition less_eq_ennreal :: "ennreal \ ennreal \ bool" is "op \" . +lift_definition less_ennreal :: "ennreal \ ennreal \ bool" is "op <" . + +instance + by standard + (transfer ; auto simp: Inf_lower Inf_greatest Sup_upper Sup_least le_max_iff_disj max.absorb1)+ + +end + + + +lemma ennreal_zero_less_one: "0 < (1::ennreal)" + by transfer auto + +instance ennreal :: ordered_comm_semiring + by standard + (transfer ; auto intro: add_mono mult_mono mult_ac ereal_left_distrib ereal_mult_left_mono)+ + +instantiation ennreal :: linear_continuum_topology +begin + +definition open_ennreal :: "ennreal set \ bool" + where "(open :: ennreal set \ bool) = generate_topology (range lessThan \ range greaterThan)" + +instance +proof + show "\a b::ennreal. a \ b" + using ennreal_zero_less_one by (auto dest: order.strict_implies_not_eq) + show "\x y::ennreal. x < y \ \z>x. z < y" + proof transfer + fix x y :: ereal assume "0 \ x" "x < y" + moreover from dense[OF this(2)] guess z .. + ultimately show "\z\Collect (op \ 0). x < z \ z < y" + by (intro bexI[of _ z]) auto + qed +qed (rule open_ennreal_def) + +end + +lemma ennreal_rat_dense: + fixes x y :: ennreal + shows "x < y \ \r::rat. x < real_of_rat r \ real_of_rat r < y" +proof transfer + fix x y :: ereal assume xy: "0 \ x" "0 \ y" "x < y" + moreover + from ereal_dense3[OF \x < y\] + obtain r where "x < ereal (real_of_rat r)" "ereal (real_of_rat r) < y" + by auto + moreover then have "0 \ r" + using le_less_trans[OF \0 \ x\ \x < ereal (real_of_rat r)\] by auto + ultimately show "\r. x < (max 0 \ ereal) (real_of_rat r) \ (max 0 \ ereal) (real_of_rat r) < y" + by (intro exI[of _ r]) (auto simp: max_absorb2) +qed + +lemma enn2ereal_range: "e2ennreal ` {0..} = UNIV" +proof - + have "\y\0. x = e2ennreal y" for x + by (cases x) auto + then show ?thesis + by (auto simp: image_iff Bex_def) +qed + +lemma enn2ereal_nonneg: "0 \ enn2ereal x" + using ennreal.enn2ereal[of x] by simp + +lemma ereal_ennreal_cases: + obtains b where "0 \ a" "a = enn2ereal b" | "a < 0" + using e2ennreal_inverse[of a, symmetric] by (cases "0 \ a") (auto intro: enn2ereal_nonneg) + +lemma enn2ereal_Iio: "enn2ereal -` {.. a then {..< e2ennreal a} else {})" + using enn2ereal_nonneg + by (cases a rule: ereal_ennreal_cases) + (auto simp add: vimage_def set_eq_iff ennreal.enn2ereal_inverse less_ennreal.rep_eq + intro: le_less_trans less_imp_le) + +lemma enn2ereal_Ioi: "enn2ereal -` {a <..} = (if 0 \ a then {e2ennreal a <..} else UNIV)" + using enn2ereal_nonneg + by (cases a rule: ereal_ennreal_cases) + (auto simp add: vimage_def set_eq_iff ennreal.enn2ereal_inverse less_ennreal.rep_eq + intro: less_le_trans) + +lemma continuous_e2ennreal: "continuous_on {0 ..} e2ennreal" + by (rule continuous_onI_mono) + (auto simp add: less_eq_ennreal.abs_eq eq_onp_def enn2ereal_range) + +lemma continuous_enn2ereal: "continuous_on UNIV enn2ereal" + by (rule continuous_on_generate_topology[OF open_generated_order]) + (auto simp add: enn2ereal_Iio enn2ereal_Ioi) + +lemma transfer_enn2ereal_continuous_on [transfer_rule]: + "rel_fun (op =) (rel_fun (rel_fun op = pcr_ennreal) op =) continuous_on continuous_on" +proof - + have "continuous_on A f" if "continuous_on A (\x. enn2ereal (f x))" for A and f :: "'a \ ennreal" + using continuous_on_compose2[OF continuous_e2ennreal that] + by (auto simp: ennreal.enn2ereal_inverse subset_eq enn2ereal_nonneg) + moreover + have "continuous_on A (\x. enn2ereal (f x))" if "continuous_on A f" for A and f :: "'a \ ennreal" + using continuous_on_compose2[OF continuous_enn2ereal that] by auto + ultimately + show ?thesis + by (auto simp add: rel_fun_def ennreal.pcr_cr_eq cr_ennreal_def) +qed + +lemma continuous_on_add_ennreal[continuous_intros]: + fixes f g :: "'a::topological_space \ ennreal" + shows "continuous_on A f \ continuous_on A g \ continuous_on A (\x. f x + g x)" + by (transfer fixing: A) (auto intro!: tendsto_add_ereal_nonneg simp: continuous_on_def) + +lemma continuous_on_inverse_ennreal[continuous_intros]: + fixes f :: "_ \ ennreal" + shows "continuous_on A f \ continuous_on A (\x. inverse (f x))" +proof (transfer fixing: A) + show "pred_fun (op \ 0) f \ continuous_on A (\x. inverse (f x))" if "continuous_on A f" + for f :: "_ \ ereal" + using continuous_on_compose2[OF continuous_on_inverse_ereal that] by (auto simp: subset_eq) +qed + +end diff -r cb27a55d868a -r 670063003ad3 src/HOL/Library/Library.thy --- a/src/HOL/Library/Library.thy Fri Feb 19 12:25:57 2016 +0100 +++ b/src/HOL/Library/Library.thy Tue Feb 09 09:21:10 2016 +0100 @@ -20,6 +20,7 @@ Dlist Extended Extended_Nat + Extended_Nonnegative_Real Extended_Real FinFun Float diff -r cb27a55d868a -r 670063003ad3 src/HOL/Multivariate_Analysis/Extended_Real_Limits.thy --- a/src/HOL/Multivariate_Analysis/Extended_Real_Limits.thy Fri Feb 19 12:25:57 2016 +0100 +++ b/src/HOL/Multivariate_Analysis/Extended_Real_Limits.thy Tue Feb 09 09:21:10 2016 +0100 @@ -11,6 +11,7 @@ imports Topology_Euclidean_Space "~~/src/HOL/Library/Extended_Real" + "~~/src/HOL/Library/Extended_Nonnegative_Real" "~~/src/HOL/Library/Indicator_Function" begin @@ -85,6 +86,38 @@ qed qed +text \This is a copy from \ereal :: second_countable_topology\. Maybe find a common super class of +topological spaces where the rational numbers are densely embedded ?\ +instance ennreal :: second_countable_topology +proof (standard, intro exI conjI) + let ?B = "(\r\\. {{..< r}, {r <..}} :: ennreal set set)" + show "countable ?B" + by (auto intro: countable_rat) + show "open = generate_topology ?B" + proof (intro ext iffI) + fix S :: "ennreal set" + assume "open S" + then show "generate_topology ?B S" + unfolding open_generated_order + proof induct + case (Basis b) + then obtain e where "b = {.. b = {e<..}" + by auto + moreover have "{..{{.. \ \ x < e}" "{e<..} = \{{x<..}|x. x \ \ \ e < x}" + by (auto dest: ennreal_rat_dense + simp del: ex_simps + simp add: ex_simps[symmetric] conj_commute Rats_def image_iff) + ultimately show ?case + by (auto intro: generate_topology.intros) + qed (auto intro: generate_topology.intros) + next + fix S + assume "generate_topology ?B S" + then show "open S" + by induct auto + qed +qed + lemma ereal_open_closed_aux: fixes S :: "ereal set" assumes "open S" @@ -94,7 +127,7 @@ proof (rule ccontr) assume "\ ?thesis" then have *: "Inf S \ S" - + by (metis assms(2) closed_contains_Inf_cl) { assume "Inf S = -\" diff -r cb27a55d868a -r 670063003ad3 src/HOL/Probability/Weak_Convergence.thy --- a/src/HOL/Probability/Weak_Convergence.thy Fri Feb 19 12:25:57 2016 +0100 +++ b/src/HOL/Probability/Weak_Convergence.thy Tue Feb 09 09:21:10 2016 +0100 @@ -27,11 +27,11 @@ section \Skorohod's theorem\ -locale right_continuous_mono = +locale right_continuous_mono = fixes f :: "real \ real" and a b :: real assumes cont: "\x. continuous (at_right x) f" assumes mono: "mono f" - assumes bot: "(f \ a) at_bot" + assumes bot: "(f \ a) at_bot" assumes top: "(f \ b) at_top" begin @@ -47,7 +47,7 @@ by (auto intro!: bdd_belowI[of _ y] elim: mono_invE[OF _ less_le_trans]) have ne: "?F \ {}" - using order_tendstoD(1)[OF top \\ < b\] + using order_tendstoD(1)[OF top \\ < b\] by (auto dest!: eventually_happens'[OF trivial_limit_at_top_linorder] intro: less_imp_le) show "\ \ f x \ I \ \ x" @@ -115,14 +115,14 @@ context fixes \ :: "nat \ real measure" and M :: "real measure" - assumes \: "\n. real_distribution (\ n)" + assumes \: "\n. real_distribution (\ n)" assumes M: "real_distribution M" assumes \_to_M: "weak_conv_m \ M" -begin +begin (* state using obtains? *) theorem Skorohod: - "\ (\ :: real measure) (Y_seq :: nat \ real \ real) (Y :: real \ real). + "\ (\ :: real measure) (Y_seq :: nat \ real \ real) (Y :: real \ real). prob_space \ \ (\n. Y_seq n \ measurable \ borel) \ (\n. distr \ borel (Y_seq n) = \ n) \ @@ -147,7 +147,7 @@ have Y_distr: "distr ?\ borel M.I = M" by (rule M.distr_I_eq_M) - have Y_cts_cnv: "(\n. \.I n \) \ M.I \" + have Y_cts_cnv: "(\n. \.I n \) \ M.I \" if \: "\ \ {0<..<1}" "isCont M.I \" for \ :: real proof (intro limsup_le_liminf_real) show "liminf (\n. \.I n \) \ M.I \" @@ -196,7 +196,7 @@ using \y < B\ by (intro Limsup_bounded[rotated]) (auto intro: le_less_trans elim: eventually_mono) qed simp - + have **: "(M.I \ ereal (M.I \)) (at_right \)" using \(2) by (auto intro: tendsto_within_subset simp: continuous_at) show "limsup (\n. \.I n \) \ M.I \" @@ -247,13 +247,13 @@ \ theorem weak_conv_imp_bdd_ae_continuous_conv: - fixes + fixes f :: "real \ 'a::{banach, second_countable_topology}" - assumes + assumes discont_null: "M ({x. \ isCont f x}) = 0" and f_bdd: "\x. norm (f x) \ B" and [measurable]: "f \ borel_measurable borel" - shows + shows "(\ n. integral\<^sup>L (\ n) f) \ integral\<^sup>L M f" proof - have "0 \ B" @@ -278,10 +278,10 @@ theorem weak_conv_imp_integral_bdd_continuous_conv: fixes f :: "real \ 'a::{banach, second_countable_topology}" - assumes + assumes "\x. isCont f x" and "\x. norm (f x) \ B" - shows + shows "(\ n. integral\<^sup>L (\ n) f) \ integral\<^sup>L M f" using assms by (intro weak_conv_imp_bdd_ae_continuous_conv) @@ -294,7 +294,7 @@ proof - interpret M: real_distribution M by fact interpret \: real_distribution "\ n" for n by fact - + have "(\n. (\x. indicator A x \\ n) :: real) \ (\x. indicator A x \M)" by (intro weak_conv_imp_bdd_ae_continuous_conv[where B=1]) (auto intro: assms simp: isCont_indicator) @@ -347,9 +347,9 @@ context fixes M_seq :: "nat \ real measure" and M :: "real measure" - assumes distr_M_seq [simp]: "\n. real_distribution (M_seq n)" + assumes distr_M_seq [simp]: "\n. real_distribution (M_seq n)" assumes distr_M [simp]: "real_distribution M" -begin +begin theorem continuity_set_conv_imp_weak_conv: fixes f :: "real \ real" @@ -364,9 +364,9 @@ theorem integral_cts_step_conv_imp_weak_conv: assumes integral_conv: "\x y. x < y \ (\n. integral\<^sup>L (M_seq n) (cts_step x y)) \ integral\<^sup>L M (cts_step x y)" shows "weak_conv_m M_seq M" - unfolding weak_conv_m_def weak_conv_def + unfolding weak_conv_m_def weak_conv_def proof (clarsimp) - interpret real_distribution M by (rule distr_M) + interpret real_distribution M by (rule distr_M) fix x assume "isCont (cdf M) x" hence left_cont: "continuous (at_left x) (cdf M)" unfolding continuous_at_split .. @@ -400,13 +400,13 @@ by (subst eventually_at_left[of "x - 1"]) (auto simp: ** intro: exI [of _ "x-1"]) qed (insert left_cont, auto simp: continuous_within) ultimately show "(\n. cdf (M_seq n) x) \ cdf M x" - by (elim limsup_le_liminf_real) + by (elim limsup_le_liminf_real) qed theorem integral_bdd_continuous_conv_imp_weak_conv: - assumes + assumes "\f. (\x. isCont f x) \ (\x. abs (f x) \ 1) \ (\n. integral\<^sup>L (M_seq n) f::real) \ integral\<^sup>L M f" - shows + shows "weak_conv_m M_seq M" apply (rule integral_cts_step_conv_imp_weak_conv [OF assms]) apply (rule continuous_on_interior)