# HG changeset patch # User hoelzl # Date 1452079133 -3600 # Node ID 7582b39f51ed7999db08cff12b4971889ee3b2dc # Parent 614ef6d7a6b635c1573e7041ec42619be9bc481f add the proof of the central limit theorem diff -r 614ef6d7a6b6 -r 7582b39f51ed CONTRIBUTORS --- a/CONTRIBUTORS Wed Jan 06 13:04:31 2016 +0100 +++ b/CONTRIBUTORS Wed Jan 06 12:18:53 2016 +0100 @@ -6,6 +6,10 @@ Contributions to Isabelle2016 ----------------------------- +* Summer 2014: Jeremy Avigad, Luke Serafin, CMU, and Johannes Hölzl, TUM + Proof of the central limit theorem: includes weak convergence, characteristic + functions, and Levy's uniqueness and continuity theorem. + * Winter 2015: Manuel Eberl, TUM The radius of convergence of power series and various summability tests. Harmonic numbers and the Euler-Mascheroni constant. diff -r 614ef6d7a6b6 -r 7582b39f51ed NEWS --- a/NEWS Wed Jan 06 13:04:31 2016 +0100 +++ b/NEWS Wed Jan 06 12:18:53 2016 +0100 @@ -660,6 +660,9 @@ Gamma/log-Gamma/Digamma/ Polygamma functions and their most important properties. +* Probability: The central limit theorem based on Levy's uniqueness and +continuity theorems, weak convergence, and characterisitc functions. + * Data_Structures: new and growing session of standard data structures. * Imperative_HOL: obsolete theory Legacy_Mrec has been removed. diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Library/ContNotDenum.thy --- a/src/HOL/Library/ContNotDenum.thy Wed Jan 06 13:04:31 2016 +0100 +++ b/src/HOL/Library/ContNotDenum.thy Wed Jan 06 12:18:53 2016 +0100 @@ -159,4 +159,21 @@ thus ?thesis by auto qed +lemma open_minus_countable: + fixes S A :: "real set" assumes "countable A" "S \ {}" "open S" + shows "\x\S. x \ A" +proof - + obtain x where "x \ S" + using \S \ {}\ by auto + then obtain e where "0 < e" "{y. dist y x < e} \ S" + using \open S\ by (auto simp: open_dist subset_eq) + moreover have "{y. dist y x < e} = {x - e <..< x + e}" + by (auto simp: dist_real_def) + ultimately have "uncountable (S - A)" + using uncountable_open_interval[of "x - e" "x + e"] \countable A\ + by (intro uncountable_minus_countable) (auto dest: countable_subset) + then show ?thesis + unfolding uncountable_def by auto +qed + end diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Library/Extended_Real.thy --- a/src/HOL/Library/Extended_Real.thy Wed Jan 06 13:04:31 2016 +0100 +++ b/src/HOL/Library/Extended_Real.thy Wed Jan 06 12:18:53 2016 +0100 @@ -1882,6 +1882,18 @@ by (auto intro!: INF_lower bdd_belowI[of _ r] simp add: ereal_less_eq(3)[symmetric] simp del: ereal_less_eq) qed (auto simp: mono_def continuous_at_imp_continuous_at_within continuous_at_ereal) +lemma ereal_Inf': + assumes *: "bdd_below A" "A \ {}" + shows "ereal (Inf A) = (INF a:A. ereal a)" +proof (rule ereal_Inf) + from * obtain l u where "\x. x \ A \ l \ x" "u \ A" + by (auto simp: bdd_below_def) + then have "l \ (INF x:A. ereal x)" "(INF x:A. ereal x) \ u" + by (auto intro!: INF_greatest INF_lower) + then show "\INF a:A. ereal a\ \ \" + by auto +qed + lemma ereal_INF: "\INF a:A. ereal (f a)\ \ \ \ ereal (INF a:A. f a) = (INF a:A. ereal (f a))" using ereal_Inf[of "f`A"] by auto diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Multivariate_Analysis/Topology_Euclidean_Space.thy --- a/src/HOL/Multivariate_Analysis/Topology_Euclidean_Space.thy Wed Jan 06 13:04:31 2016 +0100 +++ b/src/HOL/Multivariate_Analysis/Topology_Euclidean_Space.thy Wed Jan 06 12:18:53 2016 +0100 @@ -1851,6 +1851,16 @@ "closed s \ (closedin (subtopology euclidean s) t \ closed t \ t \ s)" by (meson closed_in_limpt closed_subset closedin_closed_trans) +lemma bdd_below_closure: + fixes A :: "real set" + assumes "bdd_below A" + shows "bdd_below (closure A)" +proof - + from assms obtain m where "\x. x \ A \ m \ x" unfolding bdd_below_def by auto + hence "A \ {m..}" by auto + hence "closure A \ {m..}" using closed_real_atLeast by (rule closure_minimal) + thus ?thesis unfolding bdd_below_def by auto +qed subsection\Connected components, considered as a connectedness relation or a set\ @@ -2649,6 +2659,17 @@ shows "S \ {} \ bdd_below S \ closed S \ Inf S \ S" by (metis closure_contains_Inf closure_closed assms) +lemma closed_subset_contains_Inf: + fixes A C :: "real set" + shows "closed C \ A \ C \ A \ {} \ bdd_below A \ Inf A \ C" + by (metis closure_contains_Inf closure_minimal subset_eq) + +lemma atLeastAtMost_subset_contains_Inf: + fixes A :: "real set" and a b :: real + shows "A \ {} \ a \ b \ A \ {a..b} \ Inf A \ {a..b}" + by (rule closed_subset_contains_Inf) + (auto intro: closed_real_atLeastAtMost intro!: bdd_belowI[of A a]) + lemma not_trivial_limit_within_ball: "\ trivial_limit (at x within S) \ (\e>0. S \ ball x e - {x} \ {})" (is "?lhs \ ?rhs") diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Parity.thy --- a/src/HOL/Parity.thy Wed Jan 06 13:04:31 2016 +0100 +++ b/src/HOL/Parity.thy Wed Jan 06 12:18:53 2016 +0100 @@ -321,7 +321,10 @@ with \a \ b\ show ?thesis using power_mono by auto qed qed - + +lemma (in comm_ring_1) uminus_power_if: "(- x) ^ n = (if even n then x^n else - (x ^ n))" + by auto + text \Simplify, when the exponent is a numeral\ lemma zero_le_power_eq_numeral [simp]: diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Power.thy --- a/src/HOL/Power.thy Wed Jan 06 13:04:31 2016 +0100 +++ b/src/HOL/Power.thy Wed Jan 06 12:18:53 2016 +0100 @@ -755,7 +755,6 @@ "(x - y)\<^sup>2 = (y - x)\<^sup>2" by (simp add: algebra_simps power2_eq_square) - text \Simprules for comparisons where common factors can be cancelled.\ lemmas zero_compare_simps = diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Probability/Binary_Product_Measure.thy --- a/src/HOL/Probability/Binary_Product_Measure.thy Wed Jan 06 13:04:31 2016 +0100 +++ b/src/HOL/Probability/Binary_Product_Measure.thy Wed Jan 06 12:18:53 2016 +0100 @@ -1012,7 +1012,7 @@ also have "\ = (\\<^sup>+ y. ereal (1 / Suc n) * indicator C' (x, y) \count_space UNIV)" by(rule nn_integral_cong)(force split: split_indicator intro: rev_image_eqI simp add: C') also have "\ = (\\<^sup>+ x'. (\\<^sup>+ y. ereal (1 / Suc n) * indicator C' (x, y) \count_space UNIV) * indicator {x} x' \count_space UNIV)" - by(simp add: one_ereal_def[symmetric] nn_integral_nonneg nn_integral_cmult_indicator) + by(simp add: one_ereal_def[symmetric] nn_integral_nonneg max_def) also have "\ \ (\\<^sup>+ x. \\<^sup>+ y. ereal (1 / Suc n) * indicator C' (x, y) \count_space UNIV \count_space UNIV)" by(rule nn_integral_mono)(simp split: split_indicator add: nn_integral_nonneg) also have "\ \ ?lhs" using ** @@ -1024,7 +1024,7 @@ have "\ = \\<^sup>+ x. ereal (1 / Suc n) * indicator C' x \count_space UNIV" using C'_def False by(simp add: nn_integral_cmult) also have "\ = \\<^sup>+ x. \\<^sup>+ y. ereal (1 / Suc n) * indicator C' x * indicator {SOME y. (x, y) \ C} y \count_space UNIV \count_space UNIV" - by(auto simp add: one_ereal_def[symmetric] nn_integral_cmult_indicator intro: nn_integral_cong) + by(auto simp add: one_ereal_def[symmetric] max_def intro: nn_integral_cong) also have "\ \ \\<^sup>+ x. \\<^sup>+ y. ereal (1 / Suc n) * indicator C (x, y) \count_space UNIV \count_space UNIV" by(intro nn_integral_mono)(auto simp add: C'_def split: split_indicator intro: someI) also have "\ \ ?lhs" using C @@ -1121,4 +1121,4 @@ by (auto simp: space_pair_measure M.emeasure_pair_measure_Times) qed -end \ No newline at end of file +end diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Probability/Bochner_Integration.thy --- a/src/HOL/Probability/Bochner_Integration.thy Wed Jan 06 13:04:31 2016 +0100 +++ b/src/HOL/Probability/Bochner_Integration.thy Wed Jan 06 12:18:53 2016 +0100 @@ -1042,10 +1042,14 @@ integral\<^sup>L M (\x. f x - g x) = integral\<^sup>L M f - integral\<^sup>L M g" by (intro has_bochner_integral_integral_eq has_bochner_integral_diff has_bochner_integral_integrable) -lemma integral_setsum[simp]: "(\i. i \ I \ integrable M (f i)) \ +lemma integral_setsum: "(\i. i \ I \ integrable M (f i)) \ integral\<^sup>L M (\x. \i\I. f i x) = (\i\I. integral\<^sup>L M (f i))" by (intro has_bochner_integral_integral_eq has_bochner_integral_setsum has_bochner_integral_integrable) +lemma integral_setsum'[simp]: "(\i. i \ I =simp=> integrable M (f i)) \ + integral\<^sup>L M (\x. \i\I. f i x) = (\i\I. integral\<^sup>L M (f i))" + unfolding simp_implies_def by (rule integral_setsum) + lemma integral_bounded_linear: "bounded_linear T \ integrable M f \ integral\<^sup>L M (\x. T (f x)) = T (integral\<^sup>L M f)" by (metis has_bochner_integral_bounded_linear has_bochner_integral_integrable has_bochner_integral_integral_eq) diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Probability/Borel_Space.thy --- a/src/HOL/Probability/Borel_Space.thy Wed Jan 06 13:04:31 2016 +0100 +++ b/src/HOL/Probability/Borel_Space.thy Wed Jan 06 12:18:53 2016 +0100 @@ -22,6 +22,272 @@ by (auto intro: topological_basis_prod topological_basis_trivial topological_basis_imp_subbasis) qed +definition "mono_on f A \ \r s. r \ A \ s \ A \ r \ s \ f r \ f s" + +lemma mono_onI: + "(\r s. r \ A \ s \ A \ r \ s \ f r \ f s) \ mono_on f A" + unfolding mono_on_def by simp + +lemma mono_onD: + "\mono_on f A; r \ A; s \ A; r \ s\ \ f r \ f s" + unfolding mono_on_def by simp + +lemma mono_imp_mono_on: "mono f \ mono_on f A" + unfolding mono_def mono_on_def by auto + +lemma mono_on_subset: "mono_on f A \ B \ A \ mono_on f B" + unfolding mono_on_def by auto + +definition "strict_mono_on f A \ \r s. r \ A \ s \ A \ r < s \ f r < f s" + +lemma strict_mono_onI: + "(\r s. r \ A \ s \ A \ r < s \ f r < f s) \ strict_mono_on f A" + unfolding strict_mono_on_def by simp + +lemma strict_mono_onD: + "\strict_mono_on f A; r \ A; s \ A; r < s\ \ f r < f s" + unfolding strict_mono_on_def by simp + +lemma mono_on_greaterD: + assumes "mono_on g A" "x \ A" "y \ A" "g x > (g (y::_::linorder) :: _ :: linorder)" + shows "x > y" +proof (rule ccontr) + assume "\x > y" + hence "x \ y" by (simp add: not_less) + from assms(1-3) and this have "g x \ g y" by (rule mono_onD) + with assms(4) show False by simp +qed + +lemma strict_mono_inv: + fixes f :: "('a::linorder) \ ('b::linorder)" + assumes "strict_mono f" and "surj f" and inv: "\x. g (f x) = x" + shows "strict_mono g" +proof + fix x y :: 'b assume "x < y" + from \surj f\ obtain x' y' where [simp]: "x = f x'" "y = f y'" by blast + with \x < y\ and \strict_mono f\ have "x' < y'" by (simp add: strict_mono_less) + with inv show "g x < g y" by simp +qed + +lemma strict_mono_on_imp_inj_on: + assumes "strict_mono_on (f :: (_ :: linorder) \ (_ :: preorder)) A" + shows "inj_on f A" +proof (rule inj_onI) + fix x y assume "x \ A" "y \ A" "f x = f y" + thus "x = y" + by (cases x y rule: linorder_cases) + (auto dest: strict_mono_onD[OF assms, of x y] strict_mono_onD[OF assms, of y x]) +qed + +lemma strict_mono_on_leD: + assumes "strict_mono_on (f :: (_ :: linorder) \ _ :: preorder) A" "x \ A" "y \ A" "x \ y" + shows "f x \ f y" +proof (insert le_less_linear[of y x], elim disjE) + assume "x < y" + with assms have "f x < f y" by (rule_tac strict_mono_onD[OF assms(1)]) simp_all + thus ?thesis by (rule less_imp_le) +qed (insert assms, simp) + +lemma strict_mono_on_eqD: + fixes f :: "(_ :: linorder) \ (_ :: preorder)" + assumes "strict_mono_on f A" "f x = f y" "x \ A" "y \ A" + shows "y = x" + using assms by (rule_tac linorder_cases[of x y]) (auto dest: strict_mono_onD) + +lemma mono_on_imp_deriv_nonneg: + assumes mono: "mono_on f A" and deriv: "(f has_real_derivative D) (at x)" + assumes "x \ interior A" + shows "D \ 0" +proof (rule tendsto_le_const) + let ?A' = "(\y. y - x) ` interior A" + from deriv show "((\h. (f (x + h) - f x) / h) \ D) (at 0)" + by (simp add: field_has_derivative_at has_field_derivative_def) + from mono have mono': "mono_on f (interior A)" by (rule mono_on_subset) (rule interior_subset) + + show "eventually (\h. (f (x + h) - f x) / h \ 0) (at 0)" + proof (subst eventually_at_topological, intro exI conjI ballI impI) + have "open (interior A)" by simp + hence "open (op + (-x) ` interior A)" by (rule open_translation) + also have "(op + (-x) ` interior A) = ?A'" by auto + finally show "open ?A'" . + next + from \x \ interior A\ show "0 \ ?A'" by auto + next + fix h assume "h \ ?A'" + hence "x + h \ interior A" by auto + with mono' and \x \ interior A\ show "(f (x + h) - f x) / h \ 0" + by (cases h rule: linorder_cases[of _ 0]) + (simp_all add: divide_nonpos_neg divide_nonneg_pos mono_onD field_simps) + qed +qed simp + +lemma strict_mono_on_imp_mono_on: + "strict_mono_on (f :: (_ :: linorder) \ _ :: preorder) A \ mono_on f A" + by (rule mono_onI, rule strict_mono_on_leD) + +lemma mono_on_ctble_discont: + fixes f :: "real \ real" + fixes A :: "real set" + assumes "mono_on f A" + shows "countable {a\A. \ continuous (at a within A) f}" +proof - + have mono: "\x y. x \ A \ y \ A \ x \ y \ f x \ f y" + using `mono_on f A` by (simp add: mono_on_def) + have "\a \ {a\A. \ continuous (at a within A) f}. \q :: nat \ rat. + (fst q = 0 \ of_rat (snd q) < f a \ (\x \ A. x < a \ f x < of_rat (snd q))) \ + (fst q = 1 \ of_rat (snd q) > f a \ (\x \ A. x > a \ f x > of_rat (snd q)))" + proof (clarsimp simp del: One_nat_def) + fix a assume "a \ A" assume "\ continuous (at a within A) f" + thus "\q1 q2. + q1 = 0 \ real_of_rat q2 < f a \ (\x\A. x < a \ f x < real_of_rat q2) \ + q1 = 1 \ f a < real_of_rat q2 \ (\x\A. a < x \ real_of_rat q2 < f x)" + proof (auto simp add: continuous_within order_tendsto_iff eventually_at) + fix l assume "l < f a" + then obtain q2 where q2: "l < of_rat q2" "of_rat q2 < f a" + using of_rat_dense by blast + assume * [rule_format]: "\d>0. \x\A. x \ a \ dist x a < d \ \ l < f x" + from q2 have "real_of_rat q2 < f a \ (\x\A. x < a \ f x < real_of_rat q2)" + proof auto + fix x assume "x \ A" "x < a" + with q2 *[of "a - x"] show "f x < real_of_rat q2" + apply (auto simp add: dist_real_def not_less) + apply (subgoal_tac "f x \ f xa") + by (auto intro: mono) + qed + thus ?thesis by auto + next + fix u assume "u > f a" + then obtain q2 where q2: "f a < of_rat q2" "of_rat q2 < u" + using of_rat_dense by blast + assume *[rule_format]: "\d>0. \x\A. x \ a \ dist x a < d \ \ u > f x" + from q2 have "real_of_rat q2 > f a \ (\x\A. x > a \ f x > real_of_rat q2)" + proof auto + fix x assume "x \ A" "x > a" + with q2 *[of "x - a"] show "f x > real_of_rat q2" + apply (auto simp add: dist_real_def) + apply (subgoal_tac "f x \ f xa") + by (auto intro: mono) + qed + thus ?thesis by auto + qed + qed + hence "\g :: real \ nat \ rat . \a \ {a\A. \ continuous (at a within A) f}. + (fst (g a) = 0 \ of_rat (snd (g a)) < f a \ (\x \ A. x < a \ f x < of_rat (snd (g a)))) | + (fst (g a) = 1 \ of_rat (snd (g a)) > f a \ (\x \ A. x > a \ f x > of_rat (snd (g a))))" + by (rule bchoice) + then guess g .. + hence g: "\a x. a \ A \ \ continuous (at a within A) f \ x \ A \ + (fst (g a) = 0 \ of_rat (snd (g a)) < f a \ (x < a \ f x < of_rat (snd (g a)))) | + (fst (g a) = 1 \ of_rat (snd (g a)) > f a \ (x > a \ f x > of_rat (snd (g a))))" + by auto + have "inj_on g {a\A. \ continuous (at a within A) f}" + proof (auto simp add: inj_on_def) + fix w z + assume 1: "w \ A" and 2: "\ continuous (at w within A) f" and + 3: "z \ A" and 4: "\ continuous (at z within A) f" and + 5: "g w = g z" + from g [OF 1 2 3] g [OF 3 4 1] 5 + show "w = z" by auto + qed + thus ?thesis + by (rule countableI') +qed + +lemma mono_on_ctble_discont_open: + fixes f :: "real \ real" + fixes A :: "real set" + assumes "open A" "mono_on f A" + shows "countable {a\A. \isCont f a}" +proof - + have "{a\A. \isCont f a} = {a\A. \(continuous (at a within A) f)}" + by (auto simp add: continuous_within_open [OF _ `open A`]) + thus ?thesis + apply (elim ssubst) + by (rule mono_on_ctble_discont, rule assms) +qed + +lemma mono_ctble_discont: + fixes f :: "real \ real" + assumes "mono f" + shows "countable {a. \ isCont f a}" +using assms mono_on_ctble_discont [of f UNIV] unfolding mono_on_def mono_def by auto + +lemma has_real_derivative_imp_continuous_on: + assumes "\x. x \ A \ (f has_real_derivative f' x) (at x)" + shows "continuous_on A f" + apply (intro differentiable_imp_continuous_on, unfold differentiable_on_def) + apply (intro ballI Deriv.differentiableI) + apply (rule has_field_derivative_subset[OF assms]) + apply simp_all + done + +lemma closure_contains_Sup: + fixes S :: "real set" + assumes "S \ {}" "bdd_above S" + shows "Sup S \ closure S" +proof- + have "Inf (uminus ` S) \ closure (uminus ` S)" + using assms by (intro closure_contains_Inf) auto + also have "Inf (uminus ` S) = -Sup S" by (simp add: Inf_real_def) + also have "closure (uminus ` S) = uminus ` closure S" + by (rule sym, intro closure_injective_linear_image) (auto intro: linearI) + finally show ?thesis by auto +qed + +lemma closed_contains_Sup: + fixes S :: "real set" + shows "S \ {} \ bdd_above S \ closed S \ Sup S \ S" + by (subst closure_closed[symmetric], assumption, rule closure_contains_Sup) + +lemma deriv_nonneg_imp_mono: + assumes deriv: "\x. x \ {a..b} \ (g has_real_derivative g' x) (at x)" + assumes nonneg: "\x. x \ {a..b} \ g' x \ 0" + assumes ab: "a \ b" + shows "g a \ g b" +proof (cases "a < b") + assume "a < b" + from deriv have "\x. x \ a \ x \ b \ (g has_real_derivative g' x) (at x)" by simp + from MVT2[OF \a < b\ this] and deriv + obtain \ where \_ab: "\ > a" "\ < b" and g_ab: "g b - g a = (b - a) * g' \" by blast + from \_ab ab nonneg have "(b - a) * g' \ \ 0" by simp + with g_ab show ?thesis by simp +qed (insert ab, simp) + +lemma continuous_interval_vimage_Int: + assumes "continuous_on {a::real..b} g" and mono: "\x y. a \ x \ x \ y \ y \ b \ g x \ g y" + assumes "a \ b" "(c::real) \ d" "{c..d} \ {g a..g b}" + obtains c' d' where "{a..b} \ g -` {c..d} = {c'..d'}" "c' \ d'" "g c' = c" "g d' = d" +proof- + let ?A = "{a..b} \ g -` {c..d}" + from IVT'[of g a c b, OF _ _ \a \ b\ assms(1)] assms(4,5) + obtain c'' where c'': "c'' \ ?A" "g c'' = c" by auto + from IVT'[of g a d b, OF _ _ \a \ b\ assms(1)] assms(4,5) + obtain d'' where d'': "d'' \ ?A" "g d'' = d" by auto + hence [simp]: "?A \ {}" by blast + + def c' \ "Inf ?A" and d' \ "Sup ?A" + have "?A \ {c'..d'}" unfolding c'_def d'_def + by (intro subsetI) (auto intro: cInf_lower cSup_upper) + moreover from assms have "closed ?A" + using continuous_on_closed_vimage[of "{a..b}" g] by (subst Int_commute) simp + hence c'd'_in_set: "c' \ ?A" "d' \ ?A" unfolding c'_def d'_def + by ((intro closed_contains_Inf closed_contains_Sup, simp_all)[])+ + hence "{c'..d'} \ ?A" using assms + by (intro subsetI) + (auto intro!: order_trans[of c "g c'" "g x" for x] order_trans[of "g x" "g d'" d for x] + intro!: mono) + moreover have "c' \ d'" using c'd'_in_set(2) unfolding c'_def by (intro cInf_lower) auto + moreover have "g c' \ c" "g d' \ d" + apply (insert c'' d'' c'd'_in_set) + apply (subst c''(2)[symmetric]) + apply (auto simp: c'_def intro!: mono cInf_lower c'') [] + apply (subst d''(2)[symmetric]) + apply (auto simp: d'_def intro!: mono cSup_upper d'') [] + done + with c'd'_in_set have "g c' = c" "g d' = d" by auto + ultimately show ?thesis using that by blast +qed + subsection \Generic Borel spaces\ definition borel :: "'a::topological_space measure" where @@ -49,6 +315,10 @@ lemma sets_borel: "sets borel = sigma_sets UNIV {S. open S}" unfolding borel_def by (rule sets_measure_of) simp +lemma measurable_sets_borel: + "\f \ measurable borel M; A \ sets M\ \ f -` A \ sets borel" + by (drule (1) measurable_sets) simp + lemma pred_Collect_borel[measurable (raw)]: "Measurable.pred borel P \ {x. P x} \ sets borel" unfolding borel_def pred_def by auto @@ -888,6 +1158,28 @@ by (subst borel_measurable_iff_halfspace_le) auto qed auto +lemma borel_set_induct[consumes 1, case_names empty interval compl union]: + assumes "A \ sets borel" + assumes empty: "P {}" and int: "\a b. a \ b \ P {a..b}" and compl: "\A. A \ sets borel \ P A \ P (-A)" and + un: "\f. disjoint_family f \ (\i. f i \ sets borel) \ (\i. P (f i)) \ P (\i::nat. f i)" + shows "P (A::real set)" +proof- + let ?G = "range (\(a,b). {a..b::real})" + have "Int_stable ?G" "?G \ Pow UNIV" "A \ sigma_sets UNIV ?G" + using assms(1) by (auto simp add: borel_eq_atLeastAtMost Int_stable_def) + thus ?thesis + proof (induction rule: sigma_sets_induct_disjoint) + case (union f) + from union.hyps(2) have "\i. f i \ sets borel" by (auto simp: borel_eq_atLeastAtMost) + with union show ?case by (auto intro: un) + next + case (basic A) + then obtain a b where "A = {a .. b}" by auto + then show ?case + by (cases "a \ b") (auto intro: int empty) + qed (auto intro: empty compl simp: Compl_eq_Diff_UNIV[symmetric] borel_eq_atLeastAtMost) +qed + subsection "Borel measurable operators" lemma borel_measurable_norm[measurable]: "norm \ borel_measurable borel" @@ -1467,6 +1759,11 @@ by simp qed +lemma isCont_borel_pred[measurable]: + fixes f :: "'b::metric_space \ 'a::metric_space" + shows "Measurable.pred borel (isCont f)" + unfolding pred_def by (simp add: isCont_borel) + lemma is_real_interval: assumes S: "is_interval S" shows "\a b::real. S = {} \ S = UNIV \ S = {.. S = {..b} \ S = {a<..} \ S = {a..} \ @@ -1485,16 +1782,21 @@ by auto qed +lemma borel_measurable_mono_on_fnc: + fixes f :: "real \ real" and A :: "real set" + assumes "mono_on f A" + shows "f \ borel_measurable (restrict_space borel A)" + apply (rule measurable_restrict_countable[OF mono_on_ctble_discont[OF assms]]) + apply (auto intro!: image_eqI[where x="{x}" for x] simp: sets_restrict_space) + apply (auto simp add: sets_restrict_restrict_space continuous_on_eq_continuous_within + cong: measurable_cong_sets + intro!: borel_measurable_continuous_on_restrict intro: continuous_within_subset) + done + lemma borel_measurable_mono: fixes f :: "real \ real" - assumes "mono f" - shows "f \ borel_measurable borel" -proof (subst borel_measurable_iff_ge, auto simp add:) - fix a :: real - have "is_interval {w. a \ f w}" - unfolding is_interval_1 using assms by (auto dest: monoD intro: order.trans) - thus "{w. a \ f w} \ sets borel" using real_interval_borel_measurable by auto -qed + shows "mono f \ f \ borel_measurable borel" + using borel_measurable_mono_on_fnc[of f UNIV] by (simp add: mono_def mono_on_def) no_notation eucl_less (infix "The Central Limit Theorem\ + +theory Central_Limit_Theorem + imports Levy +begin + +theorem (in prob_space) central_limit_theorem: + fixes X :: "nat \ 'a \ real" + and \ :: "real measure" + and \ :: real + and S :: "nat \ 'a \ real" + assumes X_indep: "indep_vars (\i. borel) X UNIV" + and X_integrable: "\n. integrable M (X n)" + and X_mean_0: "\n. expectation (X n) = 0" + and \_pos: "\ > 0" + and X_square_integrable: "\n. integrable M (\x. (X n x)\<^sup>2)" + and X_variance: "\n. variance (X n) = \\<^sup>2" + and X_distrib: "\n. distr M borel (X n) = \" + defines "S n \ \x. \in. distr M borel (\x. S n x / sqrt (n * \\<^sup>2))) std_normal_distribution" +proof - + let ?S' = "\n x. S n x / sqrt (real n * \\<^sup>2)" + def \ \ "\n. char (distr M borel (?S' n))" + def \ \ "\n t. char \ (t / sqrt (\\<^sup>2 * n))" + + have X_rv [simp, measurable]: "\n. random_variable borel (X n)" + using X_indep unfolding indep_vars_def2 by simp + interpret \: real_distribution \ + by (subst X_distrib [symmetric, of 0], rule real_distribution_distr, simp) + + (* these are equivalent to the hypotheses on X, given X_distr *) + have \_integrable [simp]: "integrable \ (\x. x)" + and \_mean_integrable [simp]: "\.expectation (\x. x) = 0" + and \_square_integrable [simp]: "integrable \ (\x. x^2)" + and \_variance [simp]: "\.expectation (\x. x^2) = \\<^sup>2" + using assms by (simp_all add: X_distrib [symmetric, of 0] integrable_distr_eq integral_distr) + + have main: "\\<^sub>F n in sequentially. + cmod (\ n t - (1 + (-(t^2) / 2) / n)^n) \ + t\<^sup>2 / (6 * \\<^sup>2) * (LINT x|\. min (6 * x\<^sup>2) (\t / sqrt (\\<^sup>2 * n)\ * \x\ ^ 3))" for t + proof (rule eventually_sequentiallyI) + fix n :: nat + assume "n \ nat (ceiling (t^2 / 4))" + hence n: "n \ t^2 / 4" by (subst nat_ceiling_le_eq [symmetric]) + let ?t = "t / sqrt (\\<^sup>2 * n)" + + def \' \ "\n i. char (distr M borel (\x. X i x / sqrt (\\<^sup>2 * n)))" + have *: "\n i t. \' n i t = \ n t" + unfolding \_def \'_def char_def + by (subst X_distrib [symmetric]) (auto simp: integral_distr) + + have "\ n t = char (distr M borel (\x. \i\<^sup>2 * real n))) t" + by (auto simp: \_def S_def setsum_divide_distrib ac_simps) + also have "\ = (\ i < n. \' n i t)" + unfolding \'_def + apply (rule char_distr_setsum) + apply (rule indep_vars_compose2[where X=X]) + apply (rule indep_vars_subset) + apply (rule X_indep) + apply auto + done + also have "\ = (\ n t)^n" + by (auto simp add: * setprod_constant) + finally have \_eq: "\ n t =(\ n t)^n" . + + have "norm (\ n t - (1 - ?t^2 * \\<^sup>2 / 2)) \ ?t\<^sup>2 / 6 * (LINT x|\. min (6 * x\<^sup>2) (\?t\ * \x\ ^ 3))" + unfolding \_def by (rule \.char_approx3, auto) + also have "?t^2 * \\<^sup>2 = t^2 / n" + using \_pos by (simp add: power_divide) + also have "t^2 / n / 2 = (t^2 / 2) / n" + by simp + finally have **: "norm (\ n t - (1 + (-(t^2) / 2) / n)) \ + ?t\<^sup>2 / 6 * (LINT x|\. min (6 * x\<^sup>2) (\?t\ * \x\ ^ 3))" by simp + + have "norm (\ n t - (complex_of_real (1 + (-(t^2) / 2) / n))^n) \ + n * norm (\ n t - (complex_of_real (1 + (-(t^2) / 2) / n)))" + using n + by (auto intro!: norm_power_diff \.cmod_char_le_1 abs_leI + simp del: of_real_diff simp: of_real_diff[symmetric] divide_le_eq \_eq \_def) + also have "\ \ n * (?t\<^sup>2 / 6 * (LINT x|\. min (6 * x\<^sup>2) (\?t\ * \x\ ^ 3)))" + by (rule mult_left_mono [OF **], simp) + also have "\ = (t\<^sup>2 / (6 * \\<^sup>2) * (LINT x|\. min (6 * x\<^sup>2) (\?t\ * \x\ ^ 3)))" + using \_pos by (simp add: field_simps min_absorb2) + finally show "norm (\ n t - (1 + (-(t^2) / 2) / n)^n) \ + (t\<^sup>2 / (6 * \\<^sup>2) * (LINT x|\. min (6 * x\<^sup>2) (\?t\ * \x\ ^ 3)))" + by simp + qed + + show ?thesis + proof (rule levy_continuity) + fix t + let ?t = "\n. t / sqrt (\\<^sup>2 * n)" + have "\x. (\n. min (6 * x\<^sup>2) (\t\ * \x\ ^ 3 / \sqrt (\\<^sup>2 * real n)\)) \ 0" + using \_pos + by (auto simp: real_sqrt_mult min_absorb2 + intro!: tendsto_min[THEN tendsto_eq_rhs] sqrt_at_top[THEN filterlim_compose] + filterlim_tendsto_pos_mult_at_top filterlim_at_top_imp_at_infinity + tendsto_divide_0 filterlim_real_sequentially) + then have "(\n. LINT x|\. min (6 * x\<^sup>2) (\?t n\ * \x\ ^ 3)) \ (LINT x|\. 0)" + by (intro integral_dominated_convergence [where w = "\x. 6 * x^2"]) auto + then have *: "(\n. t\<^sup>2 / (6 * \\<^sup>2) * (LINT x|\. min (6 * x\<^sup>2) (\?t n\ * \x\ ^ 3))) \ 0" + by (simp only: integral_zero tendsto_mult_right_zero) + + have "(\n. complex_of_real ((1 + (-(t^2) / 2) / n)^n)) \ complex_of_real (exp (-(t^2) / 2))" + by (rule isCont_tendsto_compose [OF _ tendsto_exp_limit_sequentially]) auto + then have "(\n. \ n t) \ complex_of_real (exp (-(t^2) / 2))" + by (rule Lim_transform) (rule Lim_null_comparison [OF main *]) + then show "(\n. char (distr M borel (?S' n)) t) \ char std_normal_distribution t" + by (simp add: \_def char_std_normal_distribution) + qed (auto intro!: real_dist_normal_dist simp: S_def) +qed + +end diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Probability/Characteristic_Functions.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Probability/Characteristic_Functions.thy Wed Jan 06 12:18:53 2016 +0100 @@ -0,0 +1,554 @@ +(* + Theory: Characteristic_Functions.thy + Authors: Jeremy Avigad, Luke Serafin +*) + +section \Characteristic Functions\ + +theory Characteristic_Functions + imports Weak_Convergence Interval_Integral Independent_Family Distributions +begin + +lemma mult_min_right: "a \ 0 \ (a :: real) * min b c = min (a * b) (a * c)" + by (metis min.absorb_iff2 min_def mult_left_mono) + +lemma sequentially_even_odd: + assumes E: "eventually (\n. P (2 * n)) sequentially" and O: "eventually (\n. P (2 * n + 1)) sequentially" + shows "eventually P sequentially" +proof - + from E obtain n_e where [intro]: "\n. n \ n_e \ P (2 * n)" + by (auto simp: eventually_sequentially) + moreover + from O obtain n_o where [intro]: "\n. n \ n_o \ P (Suc (2 * n))" + by (auto simp: eventually_sequentially) + show ?thesis + unfolding eventually_sequentially + proof (intro exI allI impI) + fix n assume "max (2 * n_e) (2 * n_o + 1) \ n" then show "P n" + by (cases "even n") (auto elim!: evenE oddE ) + qed +qed + +lemma limseq_even_odd: + assumes "(\n. f (2 * n)) \ (l :: 'a :: topological_space)" + and "(\n. f (2 * n + 1)) \ l" + shows "f \ l" + using assms by (auto simp: filterlim_iff intro: sequentially_even_odd) + +subsection \Application of the FTC: integrating $e^ix$\ + +abbreviation iexp :: "real \ complex" where + "iexp \ (\x. exp (\ * complex_of_real x))" + +lemma isCont_iexp [simp]: "isCont iexp x" + by (intro continuous_intros) + +lemma has_vector_derivative_iexp[derivative_intros]: + "(iexp has_vector_derivative \ * iexp x) (at x within s)" + by (auto intro!: derivative_eq_intros simp: Re_exp Im_exp has_vector_derivative_complex_iff) + +lemma interval_integral_iexp: + fixes a b :: real + shows "(CLBINT x=a..b. iexp x) = ii * iexp a - ii * iexp b" + by (subst interval_integral_FTC_finite [where F = "\x. -ii * iexp x"]) + (auto intro!: derivative_eq_intros continuous_intros) + +subsection \The Characteristic Function of a Real Measure.\ + +definition + char :: "real measure \ real \ complex" +where + "char M t = CLINT x|M. iexp (t * x)" + +lemma (in real_distribution) char_zero: "char M 0 = 1" + unfolding char_def by (simp del: space_eq_univ add: prob_space) + +lemma (in prob_space) integrable_iexp: + assumes f: "f \ borel_measurable M" "\x. Im (f x) = 0" + shows "integrable M (\x. exp (ii * (f x)))" +proof (intro integrable_const_bound [of _ 1]) + from f have "\x. of_real (Re (f x)) = f x" + by (simp add: complex_eq_iff) + then show "AE x in M. cmod (exp (\ * f x)) \ 1" + using norm_exp_ii_times[of "Re (f x)" for x] by simp +qed (insert f, simp) + +lemma (in real_distribution) cmod_char_le_1: "norm (char M t) \ 1" +proof - + have "norm (char M t) \ (\x. norm (iexp (t * x)) \M)" + unfolding char_def by (intro integral_norm_bound integrable_iexp) auto + also have "\ \ 1" + by (simp del: of_real_mult) + finally show ?thesis . +qed + +lemma (in real_distribution) isCont_char: "isCont (char M) t" + unfolding continuous_at_sequentially +proof safe + fix X assume X: "X \ t" + show "(char M \ X) \ char M t" + unfolding comp_def char_def + by (rule integral_dominated_convergence[where w="\_. 1"]) (auto intro!: tendsto_intros X) +qed + +lemma (in real_distribution) char_measurable [measurable]: "char M \ borel_measurable borel" + by (auto intro!: borel_measurable_continuous_on1 continuous_at_imp_continuous_on isCont_char) + +subsection \Independence\ + +(* the automation can probably be improved *) +lemma (in prob_space) char_distr_sum: + fixes X1 X2 :: "'a \ real" and t :: real + assumes "indep_var borel X1 borel X2" + shows "char (distr M borel (\\. X1 \ + X2 \)) t = + char (distr M borel X1) t * char (distr M borel X2) t" +proof - + from assms have [measurable]: "random_variable borel X1" by (elim indep_var_rv1) + from assms have [measurable]: "random_variable borel X2" by (elim indep_var_rv2) + + have "char (distr M borel (\\. X1 \ + X2 \)) t = (CLINT x|M. iexp (t * (X1 x + X2 x)))" + by (simp add: char_def integral_distr) + also have "\ = (CLINT x|M. iexp (t * (X1 x)) * iexp (t * (X2 x))) " + by (simp add: field_simps exp_add) + also have "\ = (CLINT x|M. iexp (t * (X1 x))) * (CLINT x|M. iexp (t * (X2 x)))" + by (intro indep_var_lebesgue_integral indep_var_compose[unfolded comp_def, OF assms]) + (auto intro!: integrable_iexp) + also have "\ = char (distr M borel X1) t * char (distr M borel X2) t" + by (simp add: char_def integral_distr) + finally show ?thesis . +qed + +lemma (in prob_space) char_distr_setsum: + "indep_vars (\i. borel) X A \ + char (distr M borel (\\. \i\A. X i \)) t = (\i\A. char (distr M borel (X i)) t)" +proof (induct A rule: infinite_finite_induct) + case (insert x F) with indep_vars_subset[of "\_. borel" X "insert x F" F] show ?case + by (auto simp add: char_distr_sum indep_vars_setsum) +qed (simp_all add: char_def integral_distr prob_space del: distr_const) + +subsection \Approximations to $e^{ix}$\ + +text \Proofs from Billingsley, page 343.\ + +lemma CLBINT_I0c_power_mirror_iexp: + fixes x :: real and n :: nat + defines "f s m \ complex_of_real ((x - s) ^ m)" + shows "(CLBINT s=0..x. f s n * iexp s) = + x^Suc n / Suc n + (ii / Suc n) * (CLBINT s=0..x. f s (Suc n) * iexp s)" +proof - + have 1: + "((\s. complex_of_real(-((x - s) ^ (Suc n) / (Suc n))) * iexp s) + has_vector_derivative complex_of_real((x - s)^n) * iexp s + (ii * iexp s) * complex_of_real(-((x - s) ^ (Suc n) / (Suc n)))) + (at s within A)" for s A + by (intro derivative_eq_intros) auto + + let ?F = "\s. complex_of_real(-((x - s) ^ (Suc n) / (Suc n))) * iexp s" + have "x^(Suc n) / (Suc n) = (CLBINT s=0..x. (f s n * iexp s + (ii * iexp s) * -(f s (Suc n) / (Suc n))))" (is "?LHS = ?RHS") + proof - + have "?RHS = (CLBINT s=0..x. (f s n * iexp s + (ii * iexp s) * + complex_of_real(-((x - s) ^ (Suc n) / (Suc n)))))" + by (cases "0 \ x") (auto intro!: simp: f_def[abs_def]) + also have "... = ?F x - ?F 0" + unfolding zero_ereal_def using 1 + by (intro interval_integral_FTC_finite) + (auto simp: f_def add_nonneg_eq_0_iff complex_eq_iff + intro!: continuous_at_imp_continuous_on continuous_intros) + finally show ?thesis + by auto + qed + show ?thesis + unfolding \?LHS = ?RHS\ f_def interval_lebesgue_integral_mult_right [symmetric] + by (subst interval_lebesgue_integral_add(2) [symmetric]) + (auto intro!: interval_integrable_isCont continuous_intros simp: zero_ereal_def complex_eq_iff) +qed + +lemma iexp_eq1: + fixes x :: real + defines "f s m \ complex_of_real ((x - s) ^ m)" + shows "iexp x = + (\k \ n. (ii * x)^k / (fact k)) + ((ii ^ (Suc n)) / (fact n)) * (CLBINT s=0..x. (f s n) * (iexp s))" (is "?P n") +proof (induction n) + show "?P 0" + by (auto simp add: field_simps interval_integral_iexp f_def zero_ereal_def) +next + fix n assume ih: "?P n" + have **: "\a b :: real. a = -b \ a + b = 0" + by linarith + have *: "of_nat n * of_nat (fact n) \ - (of_nat (fact n)::complex)" + unfolding of_nat_mult[symmetric] + by (simp add: complex_eq_iff ** of_nat_add[symmetric] del: of_nat_mult of_nat_fact of_nat_add) + show "?P (Suc n)" + unfolding setsum_atMost_Suc ih f_def CLBINT_I0c_power_mirror_iexp[of _ n] + by (simp add: divide_simps add_eq_0_iff *) (simp add: field_simps) +qed + +lemma iexp_eq2: + fixes x :: real + defines "f s m \ complex_of_real ((x - s) ^ m)" + shows "iexp x = (\k\Suc n. (ii*x)^k/fact k) + ii^Suc n/fact n * (CLBINT s=0..x. f s n*(iexp s - 1))" +proof - + have isCont_f: "isCont (\s. f s n) x" for n x + by (auto simp: f_def) + let ?F = "\s. complex_of_real (-((x - s) ^ (Suc n) / real (Suc n)))" + have calc1: "(CLBINT s=0..x. f s n * (iexp s - 1)) = + (CLBINT s=0..x. f s n * iexp s) - (CLBINT s=0..x. f s n)" + unfolding zero_ereal_def + by (subst interval_lebesgue_integral_diff(2) [symmetric]) + (simp_all add: interval_integrable_isCont isCont_f field_simps) + + have calc2: "(CLBINT s=0..x. f s n) = x^Suc n / Suc n" + unfolding zero_ereal_def + proof (subst interval_integral_FTC_finite [where a = 0 and b = x and f = "\s. f s n" and F = ?F]) + show "(?F has_vector_derivative f y n) (at y within {min 0 x..max 0 x})" for y + unfolding f_def + by (intro has_vector_derivative_of_real) + (auto intro!: derivative_eq_intros simp del: power_Suc simp add: add_nonneg_eq_0_iff) + qed (auto intro: continuous_at_imp_continuous_on isCont_f) + + have calc3: "ii ^ (Suc (Suc n)) / (fact (Suc n)) = (ii ^ (Suc n) / (fact n)) * (ii / (Suc n))" + by (simp add: field_simps) + + show ?thesis + unfolding iexp_eq1 [where n = "Suc n" and x=x] calc1 calc2 calc3 unfolding f_def + by (subst CLBINT_I0c_power_mirror_iexp [where n = n]) auto +qed + +lemma abs_LBINT_I0c_abs_power_diff: + "\LBINT s=0..x. \(x - s)^n\\ = \x ^ (Suc n) / (Suc n)\" +proof - + have "\LBINT s=0..x. \(x - s)^n\\ = \LBINT s=0..x. (x - s)^n\" + proof cases + assume "0 \ x \ even n" + then have "(LBINT s=0..x. \(x - s)^n\) = LBINT s=0..x. (x - s)^n" + by (auto simp add: zero_ereal_def power_even_abs power_abs min_absorb1 max_absorb2 + intro!: interval_integral_cong) + then show ?thesis by simp + next + assume "\ (0 \ x \ even n)" + then have "(LBINT s=0..x. \(x - s)^n\) = LBINT s=0..x. -((x - s)^n)" + by (auto simp add: zero_ereal_def power_abs min_absorb1 max_absorb2 + ereal_min[symmetric] ereal_max[symmetric] power_minus_odd[symmetric] + simp del: ereal_min ereal_max intro!: interval_integral_cong) + also have "\ = - (LBINT s=0..x. (x - s)^n)" + by (subst interval_lebesgue_integral_uminus, rule refl) + finally show ?thesis by simp + qed + also have "LBINT s=0..x. (x - s)^n = x^Suc n / Suc n" + proof - + let ?F = "\t. - ((x - t)^(Suc n) / Suc n)" + have "LBINT s=0..x. (x - s)^n = ?F x - ?F 0" + unfolding zero_ereal_def + by (intro interval_integral_FTC_finite continuous_at_imp_continuous_on + has_field_derivative_iff_has_vector_derivative[THEN iffD1]) + (auto simp del: power_Suc intro!: derivative_eq_intros simp add: add_nonneg_eq_0_iff) + also have "\ = x ^ (Suc n) / (Suc n)" by simp + finally show ?thesis . + qed + finally show ?thesis . +qed + +lemma iexp_approx1: "cmod (iexp x - (\k \ n. (ii * x)^k / fact k)) \ \x\^(Suc n) / fact (Suc n)" +proof - + have "iexp x - (\k \ n. (ii * x)^k / fact k) = + ((ii ^ (Suc n)) / (fact n)) * (CLBINT s=0..x. (x - s)^n * (iexp s))" (is "?t1 = ?t2") + by (subst iexp_eq1 [of _ n], simp add: field_simps) + then have "cmod (?t1) = cmod (?t2)" + by simp + also have "\ = (1 / of_nat (fact n)) * cmod (CLBINT s=0..x. (x - s)^n * (iexp s))" + by (simp add: norm_mult norm_divide norm_power) + also have "\ \ (1 / of_nat (fact n)) * \LBINT s=0..x. cmod ((x - s)^n * (iexp s))\" + by (intro mult_left_mono interval_integral_norm2) + (auto simp: zero_ereal_def intro: interval_integrable_isCont) + also have "\ \ (1 / of_nat (fact n)) * \LBINT s=0..x. \(x - s)^n\\" + by (simp add: norm_mult del: of_real_diff of_real_power) + also have "\ \ (1 / of_nat (fact n)) * \x ^ (Suc n) / (Suc n)\" + by (simp add: abs_LBINT_I0c_abs_power_diff) + also have "1 / real_of_nat (fact n::nat) * \x ^ Suc n / real (Suc n)\ = + \x\ ^ Suc n / fact (Suc n)" + by (simp add: abs_mult power_abs) + finally show ?thesis . +qed + +lemma iexp_approx2: "cmod (iexp x - (\k \ n. (ii * x)^k / fact k)) \ 2 * \x\^n / fact n" +proof (induction n) -- \really cases\ + case (Suc n) + have *: "\a b. interval_lebesgue_integrable lborel a b f \ interval_lebesgue_integrable lborel a b g \ + \LBINT s=a..b. f s\ \ \LBINT s=a..b. g s\" + if f: "\s. 0 \ f s" and g: "\s. f s \ g s" for f g :: "_ \ real" + using order_trans[OF f g] f g unfolding interval_lebesgue_integral_def interval_lebesgue_integrable_def + by (auto simp: integral_nonneg_AE[OF AE_I2] intro!: integral_mono mult_mono) + + have "iexp x - (\k \ Suc n. (ii * x)^k / fact k) = + ((ii ^ (Suc n)) / (fact n)) * (CLBINT s=0..x. (x - s)^n * (iexp s - 1))" (is "?t1 = ?t2") + unfolding iexp_eq2 [of x n] by (simp add: field_simps) + then have "cmod (?t1) = cmod (?t2)" + by simp + also have "\ = (1 / (fact n)) * cmod (CLBINT s=0..x. (x - s)^n * (iexp s - 1))" + by (simp add: norm_mult norm_divide norm_power) + also have "\ \ (1 / (fact n)) * \LBINT s=0..x. cmod ((x - s)^n * (iexp s - 1))\" + by (intro mult_left_mono interval_integral_norm2) + (auto intro!: interval_integrable_isCont simp: zero_ereal_def) + also have "\ = (1 / (fact n)) * \LBINT s=0..x. abs ((x - s)^n) * cmod((iexp s - 1))\" + by (simp add: norm_mult del: of_real_diff of_real_power) + also have "\ \ (1 / (fact n)) * \LBINT s=0..x. abs ((x - s)^n) * 2\" + by (intro mult_left_mono * order_trans [OF norm_triangle_ineq4]) + (auto simp: mult_ac zero_ereal_def intro!: interval_integrable_isCont) + also have "\ = (2 / (fact n)) * \x ^ (Suc n) / (Suc n)\" + by (simp add: abs_LBINT_I0c_abs_power_diff abs_mult) + also have "2 / fact n * \x ^ Suc n / real (Suc n)\ = 2 * \x\ ^ Suc n / (fact (Suc n))" + by (simp add: abs_mult power_abs) + finally show ?case . +qed (insert norm_triangle_ineq4[of "iexp x" 1], simp) + +lemma (in real_distribution) char_approx1: + assumes integrable_moments: "\k. k \ n \ integrable M (\x. x^k)" + shows "cmod (char M t - (\k \ n. ((ii * t)^k / fact k) * expectation (\x. x^k))) \ + (2*\t\^n / fact n) * expectation (\x. \x\^n)" (is "cmod (char M t - ?t1) \ _") +proof - + have integ_iexp: "integrable M (\x. iexp (t * x))" + by (intro integrable_const_bound) auto + + def c \ "\k x. (ii * t)^k / fact k * complex_of_real (x^k)" + have integ_c: "\k. k \ n \ integrable M (\x. c k x)" + unfolding c_def by (intro integrable_mult_right integrable_of_real integrable_moments) + + have "k \ n \ expectation (c k) = (\*t) ^ k * (expectation (\x. x ^ k)) / fact k" for k + unfolding c_def integral_mult_right_zero integral_complex_of_real by simp + then have "norm (char M t - ?t1) = norm (char M t - (CLINT x | M. (\k \ n. c k x)))" + by (simp add: integ_c) + also have "\ = norm ((CLINT x | M. iexp (t * x) - (\k \ n. c k x)))" + unfolding char_def by (subst integral_diff[OF integ_iexp]) (auto intro!: integ_c) + also have "\ \ expectation (\x. cmod (iexp (t * x) - (\k \ n. c k x)))" + by (intro integral_norm_bound integrable_diff integ_iexp integrable_setsum integ_c) simp + also have "\ \ expectation (\x. 2 * \t\ ^ n / fact n * \x\ ^ n)" + proof (rule integral_mono) + show "integrable M (\x. cmod (iexp (t * x) - (\k\n. c k x)))" + by (intro integrable_norm integrable_diff integ_iexp integrable_setsum integ_c) simp + show "integrable M (\x. 2 * \t\ ^ n / fact n * \x\ ^ n)" + unfolding power_abs[symmetric] + by (intro integrable_mult_right integrable_abs integrable_moments) simp + show "cmod (iexp (t * x) - (\k\n. c k x)) \ 2 * \t\ ^ n / fact n * \x\ ^ n" for x + using iexp_approx2[of "t * x" n] by (auto simp add: abs_mult field_simps c_def) + qed + finally show ?thesis + unfolding integral_mult_right_zero . +qed + +lemma (in real_distribution) char_approx2: + assumes integrable_moments: "\k. k \ n \ integrable M (\x. x ^ k)" + shows "cmod (char M t - (\k \ n. ((ii * t)^k / fact k) * expectation (\x. x^k))) \ + (\t\^n / fact (Suc n)) * expectation (\x. min (2 * \x\^n * Suc n) (\t\ * \x\^Suc n))" + (is "cmod (char M t - ?t1) \ _") +proof - + have integ_iexp: "integrable M (\x. iexp (t * x))" + by (intro integrable_const_bound) auto + + def c \ "\k x. (ii * t)^k / fact k * complex_of_real (x^k)" + have integ_c: "\k. k \ n \ integrable M (\x. c k x)" + unfolding c_def by (intro integrable_mult_right integrable_of_real integrable_moments) + + have *: "min (2 * \t * x\^n / fact n) (\t * x\^Suc n / fact (Suc n)) = + \t\^n / fact (Suc n) * min (2 * \x\^n * real (Suc n)) (\t\ * \x\^(Suc n))" for x + apply (subst mult_min_right) + apply simp + apply (rule arg_cong2[where f=min]) + apply (simp_all add: field_simps abs_mult del: fact_Suc) + apply (simp_all add: field_simps) + done + + have "k \ n \ expectation (c k) = (\*t) ^ k * (expectation (\x. x ^ k)) / fact k" for k + unfolding c_def integral_mult_right_zero integral_complex_of_real by simp + then have "norm (char M t - ?t1) = norm (char M t - (CLINT x | M. (\k \ n. c k x)))" + by (simp add: integ_c) + also have "\ = norm ((CLINT x | M. iexp (t * x) - (\k \ n. c k x)))" + unfolding char_def by (subst integral_diff[OF integ_iexp]) (auto intro!: integ_c) + also have "\ \ expectation (\x. cmod (iexp (t * x) - (\k \ n. c k x)))" + by (intro integral_norm_bound integrable_diff integ_iexp integrable_setsum integ_c) simp + also have "\ \ expectation (\x. min (2 * \t * x\^n / fact n) (\t * x\^(Suc n) / fact (Suc n)))" + (is "_ \ expectation ?f") + proof (rule integral_mono) + show "integrable M (\x. cmod (iexp (t * x) - (\k\n. c k x)))" + by (intro integrable_norm integrable_diff integ_iexp integrable_setsum integ_c) simp + show "integrable M ?f" + by (rule integrable_bound[where f="\x. 2 * \t * x\ ^ n / fact n"]) + (auto simp: integrable_moments power_abs[symmetric] power_mult_distrib) + show "cmod (iexp (t * x) - (\k\n. c k x)) \ ?f x" for x + using iexp_approx1[of "t * x" n] iexp_approx2[of "t * x" n] + by (auto simp add: abs_mult field_simps c_def intro!: min.boundedI) + qed + also have "\ = (\t\^n / fact (Suc n)) * expectation (\x. min (2 * \x\^n * Suc n) (\t\ * \x\^Suc n))" + unfolding * + proof (rule integral_mult_right) + show "integrable M (\x. min (2 * \x\ ^ n * real (Suc n)) (\t\ * \x\ ^ Suc n))" + by (rule integrable_bound[where f="\x. 2 * \x\ ^ n * real (Suc n)"]) + (auto simp: integrable_moments power_abs[symmetric] power_mult_distrib) + qed + finally show ?thesis + unfolding integral_mult_right_zero . +qed + +lemma (in real_distribution) char_approx3: + fixes t + assumes + integrable_1: "integrable M (\x. x)" and + integral_1: "expectation (\x. x) = 0" and + integrable_2: "integrable M (\x. x^2)" and + integral_2: "variance (\x. x) = \2" + shows "cmod (char M t - (1 - t^2 * \2 / 2)) \ + (t^2 / 6) * expectation (\x. min (6 * x^2) (abs t * (abs x)^3) )" +proof - + note real_distribution.char_approx2 [of M 2 t, simplified] + have [simp]: "prob UNIV = 1" by (metis prob_space space_eq_univ) + from integral_2 have [simp]: "expectation (\x. x * x) = \2" + by (simp add: integral_1 numeral_eq_Suc) + have 1: "k \ 2 \ integrable M (\x. x^k)" for k + using assms by (auto simp: eval_nat_numeral le_Suc_eq) + note char_approx1 + note 2 = char_approx1 [of 2 t, OF 1, simplified] + have "cmod (char M t - (\k\2. (\ * t) ^ k * (expectation (\x. x ^ k)) / (fact k))) \ + t\<^sup>2 * expectation (\x. min (6 * x\<^sup>2) (\t\ * \x\ ^ 3)) / fact (3::nat)" + using char_approx2 [of 2 t, OF 1] by simp + also have "(\k\2. (\ * t) ^ k * expectation (\x. x ^ k) / (fact k)) = 1 - t^2 * \2 / 2" + by (simp add: complex_eq_iff numeral_eq_Suc integral_1 Re_divide Im_divide) + also have "fact 3 = 6" by (simp add: eval_nat_numeral) + also have "t\<^sup>2 * expectation (\x. min (6 * x\<^sup>2) (\t\ * \x\ ^ 3)) / 6 = + t\<^sup>2 / 6 * expectation (\x. min (6 * x\<^sup>2) (\t\ * \x\ ^ 3))" by (simp add: field_simps) + finally show ?thesis . +qed + +text \ + This is a more familiar textbook formulation in terms of random variables, but + we will use the previous version for the CLT. +\ + +lemma (in prob_space) char_approx3': + fixes \ :: "real measure" and X + assumes rv_X [simp]: "random_variable borel X" + and [simp]: "integrable M X" "integrable M (\x. (X x)^2)" "expectation X = 0" + and var_X: "variance X = \2" + and \_def: "\ = distr M borel X" + shows "cmod (char \ t - (1 - t^2 * \2 / 2)) \ + (t^2 / 6) * expectation (\x. min (6 * (X x)^2) (\t\ * \X x\^3))" + using var_X unfolding \_def + apply (subst integral_distr [symmetric, OF rv_X], simp) + apply (intro real_distribution.char_approx3) + apply (auto simp add: integrable_distr_eq integral_distr) + done + +text \ + this is the formulation in the book -- in terms of a random variable *with* the distribution, + rather the distribution itself. I don't know which is more useful, though in principal we can + go back and forth between them. +\ + +lemma (in prob_space) char_approx1': + fixes \ :: "real measure" and X + assumes integrable_moments : "\k. k \ n \ integrable M (\x. X x ^ k)" + and rv_X[measurable]: "random_variable borel X" + and \_distr : "distr M borel X = \" + shows "cmod (char \ t - (\k \ n. ((ii * t)^k / fact k) * expectation (\x. (X x)^k))) \ + (2 * \t\^n / fact n) * expectation (\x. \X x\^n)" + unfolding \_distr[symmetric] + apply (subst (1 2) integral_distr [symmetric, OF rv_X], simp, simp) + apply (intro real_distribution.char_approx1[of "distr M borel X" n t] real_distribution_distr rv_X) + apply (auto simp: integrable_distr_eq integrable_moments) + done + +subsection \Calculation of the Characteristic Function of the Standard Distribution\ + +abbreviation + "std_normal_distribution \ density lborel std_normal_density" + +(* TODO: should this be an instance statement? *) +lemma real_dist_normal_dist: "real_distribution std_normal_distribution" + using prob_space_normal_density by (auto simp: real_distribution_def real_distribution_axioms_def) + +lemma std_normal_distribution_even_moments: + fixes k :: nat + shows "(LINT x|std_normal_distribution. x^(2 * k)) = fact (2 * k) / (2^k * fact k)" + and "integrable std_normal_distribution (\x. x^(2 * k))" + using integral_std_normal_moment_even[of k] + by (subst integral_density) + (auto simp: normal_density_nonneg integrable_density + intro: integrable.intros std_normal_moment_even) + +lemma integrable_std_normal_distribution_moment: "integrable std_normal_distribution (\x. x^k)" + by (auto simp: normal_density_nonneg integrable_std_normal_moment integrable_density) + +lemma integral_std_normal_distribution_moment_odd: + "odd k \ integral\<^sup>L std_normal_distribution (\x. x^k) = 0" + using integral_std_normal_moment_odd[of "(k - 1) div 2"] + by (auto simp: integral_density normal_density_nonneg elim: oddE) + +lemma std_normal_distribution_even_moments_abs: + fixes k :: nat + shows "(LINT x|std_normal_distribution. \x\^(2 * k)) = fact (2 * k) / (2^k * fact k)" + using integral_std_normal_moment_even[of k] + by (subst integral_density) (auto simp: normal_density_nonneg power_even_abs) + +lemma std_normal_distribution_odd_moments_abs: + fixes k :: nat + shows "(LINT x|std_normal_distribution. \x\^(2 * k + 1)) = sqrt (2 / pi) * 2 ^ k * fact k" + using integral_std_normal_moment_abs_odd[of k] + by (subst integral_density) (auto simp: normal_density_nonneg) + +theorem char_std_normal_distribution: + "char std_normal_distribution = (\t. complex_of_real (exp (- (t^2) / 2)))" +proof (intro ext LIMSEQ_unique) + fix t :: real + let ?f' = "\k. (ii * t)^k / fact k * (LINT x | std_normal_distribution. x^k)" + let ?f = "\n. (\k \ n. ?f' k)" + show "?f \ exp (-(t^2) / 2)" + proof (rule limseq_even_odd) + have "(\ * complex_of_real t) ^ (2 * a) / (2 ^ a * fact a) = (- ((complex_of_real t)\<^sup>2 / 2)) ^ a / fact a" for a + by (subst power_mult) (simp add: field_simps uminus_power_if power_mult) + then have *: "?f (2 * n) = complex_of_real (\k < Suc n. (1 / fact k) * (- (t^2) / 2)^k)" for n :: nat + unfolding of_real_setsum + by (intro setsum.reindex_bij_witness_not_neutral[symmetric, where + i="\n. n div 2" and j="\n. 2 * n" and T'="{i. i \ 2 * n \ odd i}" and S'="{}"]) + (auto simp: integral_std_normal_distribution_moment_odd std_normal_distribution_even_moments) + show "(\n. ?f (2 * n)) \ exp (-(t^2) / 2)" + unfolding * using exp_converges[where 'a=real] + by (intro tendsto_of_real LIMSEQ_Suc) (auto simp: inverse_eq_divide sums_def [symmetric]) + have **: "?f (2 * n + 1) = ?f (2 * n)" for n + proof - + have "?f (2 * n + 1) = ?f (2 * n) + ?f' (2 * n + 1)" + by simp + also have "?f' (2 * n + 1) = 0" + by (subst integral_std_normal_distribution_moment_odd) simp_all + finally show "?f (2 * n + 1) = ?f (2 * n)" + by simp + qed + show "(\n. ?f (2 * n + 1)) \ exp (-(t^2) / 2)" + unfolding ** by fact + qed + + have **: "(\n. x ^ n / fact n) \ 0" for x :: real + using summable_LIMSEQ_zero [OF summable_exp] by (auto simp add: inverse_eq_divide) + + let ?F = "\n. 2 * \t\ ^ n / fact n * (LINT x|std_normal_distribution. \x\ ^ n)" + + show "?f \ char std_normal_distribution t" + proof (rule metric_tendsto_imp_tendsto[OF limseq_even_odd]) + show "(\n. ?F (2 * n)) \ 0" + proof (rule Lim_transform_eventually) + show "\\<^sub>F n in sequentially. 2 * ((t^2 / 2)^n / fact n) = ?F (2 * n)" + unfolding std_normal_distribution_even_moments_abs by (simp add: power_mult power_divide) + qed (intro tendsto_mult_right_zero **) + + have *: "?F (2 * n + 1) = (2 * \t\ * sqrt (2 / pi)) * ((2 * t^2)^n * fact n / fact (2 * n + 1))" for n + unfolding std_normal_distribution_odd_moments_abs + by (simp add: field_simps power_mult[symmetric] power_even_abs) + have "norm ((2 * t\<^sup>2) ^ n * fact n / fact (2 * n + 1)) \ (2 * t\<^sup>2) ^ n / fact n" for n + using mult_mono[OF _ square_fact_le_2_fact, of 1 "1 + 2 * real n" n] + by (auto simp add: divide_simps intro!: mult_left_mono) + then show "(\n. ?F (2 * n + 1)) \ 0" + unfolding * by (intro tendsto_mult_right_zero Lim_null_comparison [OF _ ** [of "2 * t\<^sup>2"]]) auto + + show "\\<^sub>F n in sequentially. dist (?f n) (char std_normal_distribution t) \ dist (?F n) 0" + using real_distribution.char_approx1[OF real_dist_normal_dist integrable_std_normal_distribution_moment] + by (auto simp: dist_norm integral_nonneg_AE norm_minus_commute) + qed +qed + +end diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Probability/Distribution_Functions.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Probability/Distribution_Functions.thy Wed Jan 06 12:18:53 2016 +0100 @@ -0,0 +1,259 @@ +(* + Title : Distribution_Functions.thy + Authors : Jeremy Avigad and Luke Serafin +*) + +section \Distribution Functions\ + +text \ +Shows that the cumulative distribution function (cdf) of a distribution (a measure on the reals) is +nondecreasing and right continuous, which tends to 0 and 1 in either direction. + +Conversely, every such function is the cdf of a unique distribution. This direction defines the +measure in the obvious way on half-open intervals, and then applies the Caratheodory extension +theorem. +\ + +(* TODO: the locales "finite_borel_measure" and "real_distribution" are defined here, but maybe they + should be somewhere else. *) + +theory Distribution_Functions + imports Probability_Measure "~~/src/HOL/Library/ContNotDenum" +begin + +lemma UN_Ioc_eq_UNIV: "(\n. { -real n <.. real n}) = UNIV" + by auto + (metis le_less_trans minus_minus neg_less_iff_less not_le real_arch_simple + of_nat_0_le_iff reals_Archimedean2) + +subsection {* Properties of cdf's *} + +definition + cdf :: "real measure \ real \ real" +where + "cdf M \ \x. measure M {..x}" + +lemma cdf_def2: "cdf M x = measure M {..x}" + by (simp add: cdf_def) + +locale finite_borel_measure = finite_measure M for M :: "real measure" + + assumes M_super_borel: "sets borel \ sets M" +begin + +lemma sets_M[intro]: "a \ sets borel \ a \ sets M" + using M_super_borel by auto + +lemma cdf_diff_eq: + assumes "x < y" + shows "cdf M y - cdf M x = measure M {x<..y}" +proof - + from assms have *: "{..x} \ {x<..y} = {..y}" by auto + have "measure M {..y} = measure M {..x} + measure M {x<..y}" + by (subst finite_measure_Union [symmetric], auto simp add: *) + thus ?thesis + unfolding cdf_def by auto +qed + +lemma cdf_nondecreasing: "x \ y \ cdf M x \ cdf M y" + unfolding cdf_def by (auto intro!: finite_measure_mono) + +lemma borel_UNIV: "space M = UNIV" + by (metis in_mono sets.sets_into_space space_in_borel top_le M_super_borel) + +lemma cdf_nonneg: "cdf M x \ 0" + unfolding cdf_def by (rule measure_nonneg) + +lemma cdf_bounded: "cdf M x \ measure M (space M)" + unfolding cdf_def using assms by (intro bounded_measure) + +lemma cdf_lim_infty: + "((\i. cdf M (real i)) \ measure M (space M))" +proof - + have "(\i. cdf M (real i)) \ measure M (\ i::nat. {..real i})" + unfolding cdf_def by (rule finite_Lim_measure_incseq) (auto simp: incseq_def) + also have "(\ i::nat. {..real i}) = space M" + by (auto simp: borel_UNIV intro: real_arch_simple) + finally show ?thesis . +qed + +lemma cdf_lim_at_top: "(cdf M \ measure M (space M)) at_top" + by (rule tendsto_at_topI_sequentially_real) + (simp_all add: mono_def cdf_nondecreasing cdf_lim_infty) + +lemma cdf_lim_neg_infty: "((\i. cdf M (- real i)) \ 0)" +proof - + have "(\i. cdf M (- real i)) \ measure M (\ i::nat. {.. - real i })" + unfolding cdf_def by (rule finite_Lim_measure_decseq) (auto simp: decseq_def) + also have "(\ i::nat. {..- real i}) = {}" + by auto (metis leD le_minus_iff reals_Archimedean2) + finally show ?thesis + by simp +qed + +lemma cdf_lim_at_bot: "(cdf M \ 0) at_bot" +proof - + have *: "((\x :: real. - cdf M (- x)) \ 0) at_top" + by (intro tendsto_at_topI_sequentially_real monoI) + (auto simp: cdf_nondecreasing cdf_lim_neg_infty tendsto_minus_cancel_left[symmetric]) + from filterlim_compose [OF *, OF filterlim_uminus_at_top_at_bot] + show ?thesis + unfolding tendsto_minus_cancel_left[symmetric] by simp +qed + +lemma cdf_is_right_cont: "continuous (at_right a) (cdf M)" + unfolding continuous_within +proof (rule tendsto_at_right_sequentially[where b="a + 1"]) + fix f :: "nat \ real" and x assume f: "decseq f" "f \ a" + then have "(\n. cdf M (f n)) \ measure M (\i. {.. f i})" + using `decseq f` unfolding cdf_def + by (intro finite_Lim_measure_decseq) (auto simp: decseq_def) + also have "(\i. {.. f i}) = {.. a}" + using decseq_le[OF f] by (auto intro: order_trans LIMSEQ_le_const[OF f(2)]) + finally show "(\n. cdf M (f n)) \ cdf M a" + by (simp add: cdf_def) +qed simp + +lemma cdf_at_left: "(cdf M \ measure M {.. real" and x assume f: "incseq f" "f \ a" "\x. f x < a" "\x. a - 1 < f x" + then have "(\n. cdf M (f n)) \ measure M (\i. {.. f i})" + using `incseq f` unfolding cdf_def + by (intro finite_Lim_measure_incseq) (auto simp: incseq_def) + also have "(\i. {.. f i}) = {..n. cdf M (f n)) \ measure M {.. measure M {x} = 0" +proof - + have "isCont (cdf M) x \ cdf M x = measure M {.. measure M {x} = 0" + unfolding cdf_def ivl_disj_un(2)[symmetric] + by (subst finite_measure_Union) auto + finally show ?thesis . +qed + +lemma countable_atoms: "countable {x. measure M {x} > 0}" + using countable_support unfolding zero_less_measure_iff . + +end + +locale real_distribution = prob_space M for M :: "real measure" + + assumes events_eq_borel [simp, measurable_cong]: "sets M = sets borel" and space_eq_univ [simp]: "space M = UNIV" +begin + +sublocale finite_borel_measure M + by standard auto + +lemma cdf_bounded_prob: "\x. cdf M x \ 1" + by (subst prob_space [symmetric], rule cdf_bounded) + +lemma cdf_lim_infty_prob: "(\i. cdf M (real i)) \ 1" + by (subst prob_space [symmetric], rule cdf_lim_infty) + +lemma cdf_lim_at_top_prob: "(cdf M \ 1) at_top" + by (subst prob_space [symmetric], rule cdf_lim_at_top) + +lemma measurable_finite_borel [simp]: + "f \ borel_measurable borel \ f \ borel_measurable M" + by (rule borel_measurable_subalgebra[where N=borel]) auto + +end + +lemma (in prob_space) real_distribution_distr [intro, simp]: + "random_variable borel X \ real_distribution (distr M borel X)" + unfolding real_distribution_def real_distribution_axioms_def by (auto intro!: prob_space_distr) + +subsection {* uniqueness *} + +lemma (in real_distribution) emeasure_Ioc: + assumes "a \ b" shows "emeasure M {a <.. b} = cdf M b - cdf M a" +proof - + have "{a <.. b} = {..b} - {..a}" + by auto + with `a \ b` show ?thesis + by (simp add: emeasure_eq_measure finite_measure_Diff cdf_def) +qed + +lemma cdf_unique: + fixes M1 M2 + assumes "real_distribution M1" and "real_distribution M2" + assumes "cdf M1 = cdf M2" + shows "M1 = M2" +proof (rule measure_eqI_generator_eq[where \=UNIV]) + fix X assume "X \ range (\(a, b). {a<..b::real})" + then obtain a b where Xeq: "X = {a<..b}" by auto + then show "emeasure M1 X = emeasure M2 X" + by (cases "a \ b") + (simp_all add: assms(1,2)[THEN real_distribution.emeasure_Ioc] assms(3)) +next + show "(\i. {- real (i::nat)<..real i}) = UNIV" + by (rule UN_Ioc_eq_UNIV) +qed (auto simp: real_distribution.emeasure_Ioc[OF assms(1)] + assms(1,2)[THEN real_distribution.events_eq_borel] borel_sigma_sets_Ioc + Int_stable_def) + +lemma real_distribution_interval_measure: + fixes F :: "real \ real" + assumes nondecF : "\ x y. x \ y \ F x \ F y" and + right_cont_F : "\a. continuous (at_right a) F" and + lim_F_at_bot : "(F \ 0) at_bot" and + lim_F_at_top : "(F \ 1) at_top" + shows "real_distribution (interval_measure F)" +proof - + let ?F = "interval_measure F" + interpret prob_space ?F + proof + have "ereal (1 - 0) = (SUP i::nat. ereal (F (real i) - F (- real i)))" + by (intro LIMSEQ_unique[OF _ LIMSEQ_SUP] lim_ereal[THEN iffD2] tendsto_intros + lim_F_at_bot[THEN filterlim_compose] lim_F_at_top[THEN filterlim_compose] + lim_F_at_bot[THEN filterlim_compose] filterlim_real_sequentially + filterlim_uminus_at_top[THEN iffD1]) + (auto simp: incseq_def intro!: diff_mono nondecF) + also have "\ = (SUP i::nat. emeasure ?F {- real i<..real i})" + by (subst emeasure_interval_measure_Ioc) (simp_all add: nondecF right_cont_F) + also have "\ = emeasure ?F (\i::nat. {- real i<..real i})" + by (rule SUP_emeasure_incseq) (auto simp: incseq_def) + also have "(\i. {- real (i::nat)<..real i}) = space ?F" + by (simp add: UN_Ioc_eq_UNIV) + finally show "emeasure ?F (space ?F) = 1" + by (simp add: one_ereal_def) + qed + show ?thesis + proof qed simp_all +qed + +lemma cdf_interval_measure: + fixes F :: "real \ real" + assumes nondecF : "\ x y. x \ y \ F x \ F y" and + right_cont_F : "\a. continuous (at_right a) F" and + lim_F_at_bot : "(F \ 0) at_bot" and + lim_F_at_top : "(F \ 1) at_top" + shows "cdf (interval_measure F) = F" + unfolding cdf_def +proof (intro ext) + interpret real_distribution "interval_measure F" + by (rule real_distribution_interval_measure) fact+ + fix x + have "F x - 0 = measure (interval_measure F) (\i::nat. {-real i <.. x})" + proof (intro LIMSEQ_unique[OF _ finite_Lim_measure_incseq]) + have "(\i. F x - F (- real i)) \ F x - 0" + by (intro tendsto_intros lim_F_at_bot[THEN filterlim_compose] filterlim_real_sequentially + filterlim_uminus_at_top[THEN iffD1]) + then show "(\i. measure (interval_measure F) {- real i<..x}) \ F x - 0" + apply (rule filterlim_cong[OF refl refl, THEN iffD1, rotated]) + apply (rule eventually_sequentiallyI[where c="nat (ceiling (- x))"]) + apply (simp add: measure_interval_measure_Ioc right_cont_F nondecF) + done + qed (auto simp: incseq_def) + also have "(\i::nat. {-real i <.. x}) = {..x}" + by auto (metis minus_minus neg_less_iff_less reals_Archimedean2) + finally show "measure (interval_measure F) {..x} = F x" + by simp +qed + +end diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Probability/Helly_Selection.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Probability/Helly_Selection.thy Wed Jan 06 12:18:53 2016 +0100 @@ -0,0 +1,297 @@ +(* + Theory: Helly_Selection.thy + Authors: Jeremy Avigad, Luke Serafin +*) + +section \Helly's selection theorem\ + +text \The set of bounded, monotone, right continuous functions is sequentially compact\ + +theory Helly_Selection + imports "~~/src/HOL/Library/Diagonal_Subsequence" Weak_Convergence +begin + +lemma minus_one_less: "x - 1 < (x::real)" + by simp + +theorem Helly_selection: + fixes f :: "nat \ real \ real" + assumes rcont: "\n x. continuous (at_right x) (f n)" + assumes mono: "\n. mono (f n)" + assumes bdd: "\n x. \f n x\ \ M" + shows "\s. subseq s \ (\F. (\x. continuous (at_right x) F) \ mono F \ (\x. \F x\ \ M) \ + (\x. continuous (at x) F \ (\n. f (s n) x) \ F x))" +proof - + obtain m :: "real \ nat" where "bij_betw m \ UNIV" + using countable_rat Rats_infinite by (erule countableE_infinite) + then obtain r :: "nat \ real" where bij: "bij_betw r UNIV \" + using bij_betw_inv by blast + + have dense_r: "\x y. x < y \ \n. x < r n \ r n < y" + by (metis Rats_dense_in_real bij f_the_inv_into_f bij_betw_def) + + let ?P = "\n. \s. convergent (\k. f (s k) (r n))" + interpret nat: subseqs ?P + proof (unfold convergent_def, unfold subseqs_def, auto) + fix n :: nat and s :: "nat \ nat" assume s: "subseq s" + have "bounded {-M..M}" + using bounded_closed_interval by auto + moreover have "\k. f (s k) (r n) \ {-M..M}" + using bdd by (simp add: abs_le_iff minus_le_iff) + ultimately have "\l s'. subseq s' \ ((\k. f (s k) (r n)) \ s') \ l" + using compact_Icc compact_imp_seq_compact seq_compactE by metis + thus "\s'. subseq s' \ (\l. (\k. f (s (s' k)) (r n)) \ l)" + by (auto simp: comp_def) + qed + def d \ "nat.diagseq" + have subseq: "subseq d" + unfolding d_def using nat.subseq_diagseq by auto + have rat_cnv: "?P n d" for n + proof - + have Pn_seqseq: "?P n (nat.seqseq (Suc n))" + by (rule nat.seqseq_holds) + have 1: "(\k. f ((nat.seqseq (Suc n) \ (\k. nat.fold_reduce (Suc n) k + (Suc n + k))) k) (r n)) = (\k. f (nat.seqseq (Suc n) k) (r n)) \ + (\k. nat.fold_reduce (Suc n) k (Suc n + k))" + by auto + have 2: "?P n (d \ (op + (Suc n)))" + unfolding d_def nat.diagseq_seqseq 1 + by (intro convergent_subseq_convergent Pn_seqseq nat.subseq_diagonal_rest) + then obtain L where 3: "(\na. f (d (na + Suc n)) (r n)) \ L" + by (auto simp: add.commute dest: convergentD) + then have "(\k. f (d k) (r n)) \ L" + by (rule LIMSEQ_offset) + then show ?thesis + by (auto simp: convergent_def) + qed + let ?f = "\n. \k. f (d k) (r n)" + have lim_f: "?f n \ lim (?f n)" for n + using rat_cnv convergent_LIMSEQ_iff by auto + have lim_bdd: "lim (?f n) \ {-M..M}" for n + proof - + have "closed {-M..M}" using closed_real_atLeastAtMost by auto + hence "(\i. ?f n i \ {-M..M}) \ ?f n \ lim (?f n) \ lim (?f n) \ {-M..M}" + unfolding closed_sequential_limits by (drule_tac x = "\k. f (d k) (r n)" in spec) blast + moreover have "\i. ?f n i \ {-M..M}" + using bdd by (simp add: abs_le_iff minus_le_iff) + ultimately show "lim (?f n) \ {-M..M}" + using lim_f by auto + qed + then have limset_bdd: "\x. {lim (?f n) |n. x < r n} \ {-M..M}" + by auto + then have bdd_below: "bdd_below {lim (?f n) |n. x < r n}" for x + by (metis (mono_tags) bdd_below_Icc bdd_below_mono) + have r_unbdd: "\n. x < r n" for x + using dense_r[OF less_add_one, of x] by auto + then have nonempty: "{lim (?f n) |n. x < r n} \ {}" for x + by auto + + def F \ "\x. Inf {lim (?f n) |n. x < r n}" + have F_eq: "ereal (F x) = (INF n:{n. x < r n}. ereal (lim (?f n)))" for x + unfolding F_def by (subst ereal_Inf'[OF bdd_below nonempty]) (simp add: setcompr_eq_image) + have mono_F: "mono F" + using nonempty by (auto intro!: cInf_superset_mono simp: F_def bdd_below mono_def) + moreover have "\x. continuous (at_right x) F" + unfolding continuous_within order_tendsto_iff eventually_at_right[OF less_add_one] + proof safe + show "F x < u \ \b>x. \y>x. y < b \ F y < u" for x u + unfolding F_def cInf_less_iff[OF nonempty bdd_below] by auto + next + show "\b>x. \y>x. y < b \ l < F y" if l: "l < F x" for x l + using less_le_trans[OF l mono_F[THEN monoD, of x]] by (auto intro: less_add_one) + qed + moreover + { fix x + have "F x \ {-M..M}" + unfolding F_def using limset_bdd bdd_below r_unbdd by (intro closed_subset_contains_Inf) auto + then have "\F x\ \ M" by auto } + moreover have "(\n. f (d n) x) \ F x" if cts: "continuous (at x) F" for x + proof (rule limsup_le_liminf_real) + show "limsup (\n. f (d n) x) \ F x" + proof (rule tendsto_le_const) + show "(F \ ereal (F x)) (at_right x)" + using cts unfolding continuous_at_split by (auto simp: continuous_within) + show "\\<^sub>F i in at_right x. limsup (\n. f (d n) x) \ F i" + unfolding eventually_at_right[OF less_add_one] + proof (rule, rule, rule less_add_one, safe) + fix y assume y: "x < y" + with dense_r obtain N where "x < r N" "r N < y" by auto + have *: "y < r n' \ lim (?f N) \ lim (?f n')" for n' + using \r N < y\ by (intro LIMSEQ_le[OF lim_f lim_f]) (auto intro!: mono[THEN monoD]) + have "limsup (\n. f (d n) x) \ limsup (?f N)" + using \x < r N\ by (auto intro!: Limsup_mono always_eventually mono[THEN monoD]) + also have "\ = lim (\n. ereal (?f N n))" + using rat_cnv[of N] by (force intro!: convergent_limsup_cl simp: convergent_def) + also have "\ \ F y" + by (auto intro!: INF_greatest * simp: convergent_real_imp_convergent_ereal rat_cnv F_eq) + finally show "limsup (\n. f (d n) x) \ F y" . + qed + qed simp + show "F x \ liminf (\n. f (d n) x)" + proof (rule tendsto_ge_const) + show "(F \ ereal (F x)) (at_left x)" + using cts unfolding continuous_at_split by (auto simp: continuous_within) + show "\\<^sub>F i in at_left x. F i \ liminf (\n. f (d n) x)" + unfolding eventually_at_left[OF minus_one_less] + proof (rule, rule, rule minus_one_less, safe) + fix y assume y: "y < x" + with dense_r obtain N where "y < r N" "r N < x" by auto + have "F y \ liminf (?f N)" + using \y < r N\ by (auto simp: F_eq convergent_real_imp_convergent_ereal + rat_cnv convergent_liminf_cl intro!: INF_lower2) + also have "\ \ liminf (\n. f (d n) x)" + using \r N < x\ by (auto intro!: Liminf_mono monoD[OF mono] always_eventually) + finally show "F y \ liminf (\n. f (d n) x)" . + qed + qed simp + qed + ultimately show ?thesis using subseq by auto +qed + +(** Weak convergence corollaries to Helly's theorem. **) + +definition + tight :: "(nat \ real measure) \ bool" +where + "tight \ \ (\n. real_distribution (\ n)) \ (\(\::real)>0. \a b::real. a < b \ (\n. measure (\ n) {a<..b} > 1 - \))" + +(* Can strengthen to equivalence. *) +theorem tight_imp_convergent_subsubsequence: + assumes \: "tight \" "subseq s" + shows "\r M. subseq r \ real_distribution M \ weak_conv_m (\ \ s \ r) M" +proof - + def f \ "\k. cdf (\ (s k))" + interpret \: real_distribution "\ k" for k + using \ unfolding tight_def by auto + + have rcont: "\x. continuous (at_right x) (f k)" + and mono: "mono (f k)" + and top: "(f k \ 1) at_top" + and bot: "(f k \ 0) at_bot" for k + unfolding f_def mono_def + using \.cdf_nondecreasing \.cdf_is_right_cont \.cdf_lim_at_top_prob \.cdf_lim_at_bot by auto + have bdd: "\f k x\ \ 1" for k x + by (auto simp add: abs_le_iff minus_le_iff f_def \.cdf_nonneg \.cdf_bounded_prob) + + from Helly_selection[OF rcont mono bdd, of "\x. x"] obtain r F + where F: "subseq r" "\x. continuous (at_right x) F" "mono F" "\x. \F x\ \ 1" + and lim_F: "\x. continuous (at x) F \ (\n. f (r n) x) \ F x" + by blast + + have "0 \ f n x" for n x + unfolding f_def by (rule \.cdf_nonneg) + have F_nonneg: "0 \ F x" for x + proof - + obtain y where "y < x" "isCont F y" + using open_minus_countable[OF mono_ctble_discont[OF \mono F\], of "{..< x}"] by auto + then have "0 \ F y" + by (intro LIMSEQ_le_const[OF lim_F]) (auto simp: f_def \.cdf_nonneg) + also have "\ \ F x" + using \y < x\ by (auto intro!: monoD[OF \mono F\]) + finally show "0 \ F x" . + qed + + have Fab: "\a b. (\x\b. F x \ 1 - \) \ (\x\a. F x \ \)" if \: "0 < \" for \ + proof auto + obtain a' b' where a'b': "a' < b'" "\k. measure (\ k) {a'<..b'} > 1 - \" + using \ \ by (auto simp: tight_def) + obtain a where a: "a < a'" "isCont F a" + using open_minus_countable[OF mono_ctble_discont[OF \mono F\], of "{..< a'}"] by auto + obtain b where b: "b' < b" "isCont F b" + using open_minus_countable[OF mono_ctble_discont[OF \mono F\], of "{b' <..}"] by auto + have "a < b" + using a b a'b' by simp + + let ?\ = "\k. measure (\ (s (r k)))" + have ab: "?\ k {a<..b} > 1 - \" for k + proof - + have "?\ k {a'<..b'} \ ?\ k {a<..b}" + using a b by (intro \.finite_measure_mono) auto + then show ?thesis + using a'b'(2) by (metis less_eq_real_def less_trans) + qed + + have "(\k. ?\ k {..b}) \ F b" + using b(2) lim_F unfolding f_def cdf_def o_def by auto + then have "1 - \ \ F b" + proof (rule tendsto_le_const[OF sequentially_bot], intro always_eventually allI) + fix k + have "1 - \ < ?\ k {a<..b}" + using ab by auto + also have "\ \ ?\ k {..b}" + by (auto intro!: \.finite_measure_mono) + finally show "1 - \ \ ?\ k {..b}" + by (rule less_imp_le) + qed + then show "\b. \x\b. 1 - \ \ F x" + using F unfolding mono_def by (metis order.trans) + + have "(\k. ?\ k {..a}) \ F a" + using a(2) lim_F unfolding f_def cdf_def o_def by auto + then have Fa: "F a \ \" + proof (rule tendsto_ge_const[OF sequentially_bot], intro always_eventually allI) + fix k + have "?\ k {..a} + ?\ k {a<..b} \ 1" + by (subst \.finite_measure_Union[symmetric]) auto + then show "?\ k {..a} \ \" + using ab[of k] by simp + qed + then show "\a. \x\a. F x \ \" + using F unfolding mono_def by (metis order.trans) + qed + + have "(F \ 1) at_top" + proof (rule order_tendstoI) + show "1 < y \ \\<^sub>F x in at_top. F x < y" for y + using \\x. \F x\ \ 1\ \\x. 0 \ F x\ by (auto intro: le_less_trans always_eventually) + fix y :: real assume "y < 1" + then obtain z where "y < z" "z < 1" + using dense[of y 1] by auto + with Fab[of "1 - z"] show "\\<^sub>F x in at_top. y < F x" + by (auto simp: eventually_at_top_linorder intro: less_le_trans) + qed + moreover + have "(F \ 0) at_bot" + proof (rule order_tendstoI) + show "y < 0 \ \\<^sub>F x in at_bot. y < F x" for y + using \\x. 0 \ F x\ by (auto intro: less_le_trans always_eventually) + fix y :: real assume "0 < y" + then obtain z where "0 < z" "z < y" + using dense[of 0 y] by auto + with Fab[of z] show "\\<^sub>F x in at_bot. F x < y" + by (auto simp: eventually_at_bot_linorder intro: le_less_trans) + qed + ultimately have M: "real_distribution (interval_measure F)" "cdf (interval_measure F) = F" + using F by (auto intro!: real_distribution_interval_measure cdf_interval_measure simp: mono_def) + with lim_F lim_subseq M have "weak_conv_m (\ \ s \ r) (interval_measure F)" + by (auto simp: weak_conv_def weak_conv_m_def f_def comp_def) + then show "\r M. subseq r \ (real_distribution M \ weak_conv_m (\ \ s \ r) M)" + using F M by auto +qed + +corollary tight_subseq_weak_converge: + fixes \ :: "nat \ real measure" and M :: "real measure" + assumes "\n. real_distribution (\ n)" "real_distribution M" and tight: "tight \" and + subseq: "\s \. subseq s \ real_distribution \ \ weak_conv_m (\ \ s) \ \ weak_conv_m (\ \ s) M" + shows "weak_conv_m \ M" +proof (rule ccontr) + def f \ "\n. cdf (\ n)" and F \ "cdf M" + + assume "\ weak_conv_m \ M" + then obtain x where x: "isCont F x" "\ (\n. f n x) \ F x" + by (auto simp: weak_conv_m_def weak_conv_def f_def F_def) + then obtain \ where "\ > 0" and "infinite {n. \ dist (f n x) (F x) < \}" + by (auto simp: tendsto_iff not_eventually INFM_iff_infinite cofinite_eq_sequentially[symmetric]) + then obtain s where s: "\n. \ dist (f (s n) x) (F x) < \" and "subseq s" + using enumerate_in_set enumerate_mono by (fastforce simp: subseq_def) + then obtain r \ where r: "subseq r" "real_distribution \" "weak_conv_m (\ \ s \ r) \" + using tight_imp_convergent_subsubsequence[OF tight] by blast + then have "weak_conv_m (\ \ (s \ r)) M" + using \subseq s\ r by (intro subseq subseq_o) (auto simp: comp_assoc) + then have "(\n. f (s (r n)) x) \ F x" + using x by (auto simp: weak_conv_m_def weak_conv_def F_def f_def) + then show False + using s \\ > 0\ by (auto dest: tendstoD) +qed + +end diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Probability/Interval_Integral.thy --- a/src/HOL/Probability/Interval_Integral.thy Wed Jan 06 13:04:31 2016 +0100 +++ b/src/HOL/Probability/Interval_Integral.thy Wed Jan 06 12:18:53 2016 +0100 @@ -190,6 +190,19 @@ interval_lebesgue_integral M a b f = interval_lebesgue_integral M a b g" by (auto intro: set_lebesgue_integral_cong_AE simp: interval_lebesgue_integral_def) +lemma interval_integrable_mirror: + shows "interval_lebesgue_integrable lborel a b (\x. f (-x)) \ + interval_lebesgue_integrable lborel (-b) (-a) f" +proof - + have *: "indicator (einterval a b) (- x) = (indicator (einterval (-b) (-a)) x :: real)" + for a b :: ereal and x :: real + by (cases a b rule: ereal2_cases) (auto simp: einterval_def split: split_indicator) + show ?thesis + unfolding interval_lebesgue_integrable_def + using lborel_integrable_real_affine_iff[symmetric, of "-1" "\x. indicator (einterval _ _) x *\<^sub>R f x" 0] + by (simp add: *) +qed + lemma interval_lebesgue_integral_add [intro, simp]: fixes M a b f assumes "interval_lebesgue_integrable M a b f" "interval_lebesgue_integrable M a b g" diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Probability/Lebesgue_Integral_Substitution.thy --- a/src/HOL/Probability/Lebesgue_Integral_Substitution.thy Wed Jan 06 13:04:31 2016 +0100 +++ b/src/HOL/Probability/Lebesgue_Integral_Substitution.thy Wed Jan 06 12:18:53 2016 +0100 @@ -12,243 +12,6 @@ imports Interval_Integral begin -lemma measurable_sets_borel: - "\f \ measurable borel M; A \ sets M\ \ f -` A \ sets borel" - by (drule (1) measurable_sets) simp - -lemma nn_integral_indicator_singleton[simp]: - assumes [measurable]: "{y} \ sets M" - shows "(\\<^sup>+x. f x * indicator {y} x \M) = max 0 (f y) * emeasure M {y}" -proof- - have "(\\<^sup>+x. f x * indicator {y} x \M) = (\\<^sup>+x. max 0 (f y) * indicator {y} x \M)" - by (subst nn_integral_max_0[symmetric]) (auto intro!: nn_integral_cong split: split_indicator) - then show ?thesis - by (simp add: nn_integral_cmult) -qed - -lemma nn_integral_set_ereal: - "(\\<^sup>+x. ereal (f x) * indicator A x \M) = (\\<^sup>+x. ereal (f x * indicator A x) \M)" - by (rule nn_integral_cong) (simp split: split_indicator) - -lemma nn_integral_indicator_singleton'[simp]: - assumes [measurable]: "{y} \ sets M" - shows "(\\<^sup>+x. ereal (f x * indicator {y} x) \M) = max 0 (f y) * emeasure M {y}" - by (subst nn_integral_set_ereal[symmetric]) simp - -lemma set_borel_measurable_sets: - fixes f :: "_ \ _::real_normed_vector" - assumes "set_borel_measurable M X f" "B \ sets borel" "X \ sets M" - shows "f -` B \ X \ sets M" -proof - - have "f \ borel_measurable (restrict_space M X)" - using assms by (subst borel_measurable_restrict_space_iff) auto - then have "f -` B \ space (restrict_space M X) \ sets (restrict_space M X)" - by (rule measurable_sets) fact - with \X \ sets M\ show ?thesis - by (subst (asm) sets_restrict_space_iff) (auto simp: space_restrict_space) -qed - -lemma borel_set_induct[consumes 1, case_names empty interval compl union]: - assumes "A \ sets borel" - assumes empty: "P {}" and int: "\a b. a \ b \ P {a..b}" and compl: "\A. A \ sets borel \ P A \ P (-A)" and - un: "\f. disjoint_family f \ (\i. f i \ sets borel) \ (\i. P (f i)) \ P (\i::nat. f i)" - shows "P (A::real set)" -proof- - let ?G = "range (\(a,b). {a..b::real})" - have "Int_stable ?G" "?G \ Pow UNIV" "A \ sigma_sets UNIV ?G" - using assms(1) by (auto simp add: borel_eq_atLeastAtMost Int_stable_def) - thus ?thesis - proof (induction rule: sigma_sets_induct_disjoint) - case (union f) - from union.hyps(2) have "\i. f i \ sets borel" by (auto simp: borel_eq_atLeastAtMost) - with union show ?case by (auto intro: un) - next - case (basic A) - then obtain a b where "A = {a .. b}" by auto - then show ?case - by (cases "a \ b") (auto intro: int empty) - qed (auto intro: empty compl simp: Compl_eq_Diff_UNIV[symmetric] borel_eq_atLeastAtMost) -qed - -definition "mono_on f A \ \r s. r \ A \ s \ A \ r \ s \ f r \ f s" - -lemma mono_onI: - "(\r s. r \ A \ s \ A \ r \ s \ f r \ f s) \ mono_on f A" - unfolding mono_on_def by simp - -lemma mono_onD: - "\mono_on f A; r \ A; s \ A; r \ s\ \ f r \ f s" - unfolding mono_on_def by simp - -lemma mono_imp_mono_on: "mono f \ mono_on f A" - unfolding mono_def mono_on_def by auto - -lemma mono_on_subset: "mono_on f A \ B \ A \ mono_on f B" - unfolding mono_on_def by auto - -definition "strict_mono_on f A \ \r s. r \ A \ s \ A \ r < s \ f r < f s" - -lemma strict_mono_onI: - "(\r s. r \ A \ s \ A \ r < s \ f r < f s) \ strict_mono_on f A" - unfolding strict_mono_on_def by simp - -lemma strict_mono_onD: - "\strict_mono_on f A; r \ A; s \ A; r < s\ \ f r < f s" - unfolding strict_mono_on_def by simp - -lemma mono_on_greaterD: - assumes "mono_on g A" "x \ A" "y \ A" "g x > (g (y::_::linorder) :: _ :: linorder)" - shows "x > y" -proof (rule ccontr) - assume "\x > y" - hence "x \ y" by (simp add: not_less) - from assms(1-3) and this have "g x \ g y" by (rule mono_onD) - with assms(4) show False by simp -qed - -lemma strict_mono_inv: - fixes f :: "('a::linorder) \ ('b::linorder)" - assumes "strict_mono f" and "surj f" and inv: "\x. g (f x) = x" - shows "strict_mono g" -proof - fix x y :: 'b assume "x < y" - from \surj f\ obtain x' y' where [simp]: "x = f x'" "y = f y'" by blast - with \x < y\ and \strict_mono f\ have "x' < y'" by (simp add: strict_mono_less) - with inv show "g x < g y" by simp -qed - -lemma strict_mono_on_imp_inj_on: - assumes "strict_mono_on (f :: (_ :: linorder) \ (_ :: preorder)) A" - shows "inj_on f A" -proof (rule inj_onI) - fix x y assume "x \ A" "y \ A" "f x = f y" - thus "x = y" - by (cases x y rule: linorder_cases) - (auto dest: strict_mono_onD[OF assms, of x y] strict_mono_onD[OF assms, of y x]) -qed - -lemma strict_mono_on_leD: - assumes "strict_mono_on (f :: (_ :: linorder) \ _ :: preorder) A" "x \ A" "y \ A" "x \ y" - shows "f x \ f y" -proof (insert le_less_linear[of y x], elim disjE) - assume "x < y" - with assms have "f x < f y" by (rule_tac strict_mono_onD[OF assms(1)]) simp_all - thus ?thesis by (rule less_imp_le) -qed (insert assms, simp) - -lemma strict_mono_on_eqD: - fixes f :: "(_ :: linorder) \ (_ :: preorder)" - assumes "strict_mono_on f A" "f x = f y" "x \ A" "y \ A" - shows "y = x" - using assms by (rule_tac linorder_cases[of x y]) (auto dest: strict_mono_onD) - -lemma mono_on_imp_deriv_nonneg: - assumes mono: "mono_on f A" and deriv: "(f has_real_derivative D) (at x)" - assumes "x \ interior A" - shows "D \ 0" -proof (rule tendsto_le_const) - let ?A' = "(\y. y - x) ` interior A" - from deriv show "((\h. (f (x + h) - f x) / h) \ D) (at 0)" - by (simp add: field_has_derivative_at has_field_derivative_def) - from mono have mono': "mono_on f (interior A)" by (rule mono_on_subset) (rule interior_subset) - - show "eventually (\h. (f (x + h) - f x) / h \ 0) (at 0)" - proof (subst eventually_at_topological, intro exI conjI ballI impI) - have "open (interior A)" by simp - hence "open (op + (-x) ` interior A)" by (rule open_translation) - also have "(op + (-x) ` interior A) = ?A'" by auto - finally show "open ?A'" . - next - from \x \ interior A\ show "0 \ ?A'" by auto - next - fix h assume "h \ ?A'" - hence "x + h \ interior A" by auto - with mono' and \x \ interior A\ show "(f (x + h) - f x) / h \ 0" - by (cases h rule: linorder_cases[of _ 0]) - (simp_all add: divide_nonpos_neg divide_nonneg_pos mono_onD field_simps) - qed -qed simp - -lemma strict_mono_on_imp_mono_on: - "strict_mono_on (f :: (_ :: linorder) \ _ :: preorder) A \ mono_on f A" - by (rule mono_onI, rule strict_mono_on_leD) - -lemma has_real_derivative_imp_continuous_on: - assumes "\x. x \ A \ (f has_real_derivative f' x) (at x)" - shows "continuous_on A f" - apply (intro differentiable_imp_continuous_on, unfold differentiable_on_def) - apply (intro ballI Deriv.differentiableI) - apply (rule has_field_derivative_subset[OF assms]) - apply simp_all - done - -lemma closure_contains_Sup: - fixes S :: "real set" - assumes "S \ {}" "bdd_above S" - shows "Sup S \ closure S" -proof- - have "Inf (uminus ` S) \ closure (uminus ` S)" - using assms by (intro closure_contains_Inf) auto - also have "Inf (uminus ` S) = -Sup S" by (simp add: Inf_real_def) - also have "closure (uminus ` S) = uminus ` closure S" - by (rule sym, intro closure_injective_linear_image) (auto intro: linearI) - finally show ?thesis by auto -qed - -lemma closed_contains_Sup: - fixes S :: "real set" - shows "S \ {} \ bdd_above S \ closed S \ Sup S \ S" - by (subst closure_closed[symmetric], assumption, rule closure_contains_Sup) - -lemma deriv_nonneg_imp_mono: - assumes deriv: "\x. x \ {a..b} \ (g has_real_derivative g' x) (at x)" - assumes nonneg: "\x. x \ {a..b} \ g' x \ 0" - assumes ab: "a \ b" - shows "g a \ g b" -proof (cases "a < b") - assume "a < b" - from deriv have "\x. x \ a \ x \ b \ (g has_real_derivative g' x) (at x)" by simp - from MVT2[OF \a < b\ this] and deriv - obtain \ where \_ab: "\ > a" "\ < b" and g_ab: "g b - g a = (b - a) * g' \" by blast - from \_ab ab nonneg have "(b - a) * g' \ \ 0" by simp - with g_ab show ?thesis by simp -qed (insert ab, simp) - -lemma continuous_interval_vimage_Int: - assumes "continuous_on {a::real..b} g" and mono: "\x y. a \ x \ x \ y \ y \ b \ g x \ g y" - assumes "a \ b" "(c::real) \ d" "{c..d} \ {g a..g b}" - obtains c' d' where "{a..b} \ g -` {c..d} = {c'..d'}" "c' \ d'" "g c' = c" "g d' = d" -proof- - let ?A = "{a..b} \ g -` {c..d}" - from IVT'[of g a c b, OF _ _ \a \ b\ assms(1)] assms(4,5) - obtain c'' where c'': "c'' \ ?A" "g c'' = c" by auto - from IVT'[of g a d b, OF _ _ \a \ b\ assms(1)] assms(4,5) - obtain d'' where d'': "d'' \ ?A" "g d'' = d" by auto - hence [simp]: "?A \ {}" by blast - - def c' \ "Inf ?A" and d' \ "Sup ?A" - have "?A \ {c'..d'}" unfolding c'_def d'_def - by (intro subsetI) (auto intro: cInf_lower cSup_upper) - moreover from assms have "closed ?A" - using continuous_on_closed_vimage[of "{a..b}" g] by (subst Int_commute) simp - hence c'd'_in_set: "c' \ ?A" "d' \ ?A" unfolding c'_def d'_def - by ((intro closed_contains_Inf closed_contains_Sup, simp_all)[])+ - hence "{c'..d'} \ ?A" using assms - by (intro subsetI) - (auto intro!: order_trans[of c "g c'" "g x" for x] order_trans[of "g x" "g d'" d for x] - intro!: mono) - moreover have "c' \ d'" using c'd'_in_set(2) unfolding c'_def by (intro cInf_lower) auto - moreover have "g c' \ c" "g d' \ d" - apply (insert c'' d'' c'd'_in_set) - apply (subst c''(2)[symmetric]) - apply (auto simp: c'_def intro!: mono cInf_lower c'') [] - apply (subst d''(2)[symmetric]) - apply (auto simp: d'_def intro!: mono cSup_upper d'') [] - done - with c'd'_in_set have "g c' = c" "g d' = d" by auto - ultimately show ?thesis using that by blast -qed - lemma nn_integral_substitution_aux: fixes f :: "real \ ereal" assumes Mf: "f \ borel_measurable borel" diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Probability/Levy.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Probability/Levy.thy Wed Jan 06 12:18:53 2016 +0100 @@ -0,0 +1,539 @@ +(* Theory: Levy.thy + Author: Jeremy Avigad +*) + +section \The Levy inversion theorem, and the Levy continuity theorem.\ + +theory Levy + imports Characteristic_Functions Helly_Selection Sinc_Integral +begin + +lemma LIM_zero_cancel: + fixes f :: "_ \ 'b::real_normed_vector" + shows "((\x. f x - l) \ 0) F \ (f \ l) F" +unfolding tendsto_iff dist_norm by simp + +subsection \The Levy inversion theorem\ + +(* Actually, this is not needed for us -- but it is useful for other purposes. (See Billingsley.) *) +lemma Levy_Inversion_aux1: + fixes a b :: real + assumes "a \ b" + shows "((\t. (iexp (-(t * a)) - iexp (-(t * b))) / (ii * t)) \ b - a) (at 0)" + (is "(?F \ _) (at _)") +proof - + have 1: "cmod (?F t - (b - a)) \ a^2 / 2 * abs t + b^2 / 2 * abs t" if "t \ 0" for t + proof - + have "cmod (?F t - (b - a)) = cmod ( + (iexp (-(t * a)) - (1 + ii * -(t * a))) / (ii * t) - + (iexp (-(t * b)) - (1 + ii * -(t * b))) / (ii * t))" + (is "_ = cmod (?one / (ii * t) - ?two / (ii * t))") + using `t \ 0` by (intro arg_cong[where f=norm]) (simp add: field_simps) + also have "\ \ cmod (?one / (ii * t)) + cmod (?two / (ii * t))" + by (rule norm_triangle_ineq4) + also have "cmod (?one / (ii * t)) = cmod ?one / abs t" + by (simp add: norm_divide norm_mult) + also have "cmod (?two / (ii * t)) = cmod ?two / abs t" + by (simp add: norm_divide norm_mult) + also have "cmod ?one / abs t + cmod ?two / abs t \ + ((- (a * t))^2 / 2) / abs t + ((- (b * t))^2 / 2) / abs t" + apply (rule add_mono) + apply (rule divide_right_mono) + using iexp_approx1 [of "-(t * a)" 1] apply (simp add: field_simps eval_nat_numeral) + apply force + apply (rule divide_right_mono) + using iexp_approx1 [of "-(t * b)" 1] apply (simp add: field_simps eval_nat_numeral) + by force + also have "\ = a^2 / 2 * abs t + b^2 / 2 * abs t" + using `t \ 0` apply (case_tac "t \ 0", simp add: field_simps power2_eq_square) + using `t \ 0` by (subst (1 2) abs_of_neg, auto simp add: field_simps power2_eq_square) + finally show "cmod (?F t - (b - a)) \ a^2 / 2 * abs t + b^2 / 2 * abs t" . + qed + show ?thesis + apply (rule LIM_zero_cancel) + apply (rule tendsto_norm_zero_cancel) + apply (rule real_LIM_sandwich_zero [OF _ _ 1]) + apply (auto intro!: tendsto_eq_intros) + done +qed + +lemma Levy_Inversion_aux2: + fixes a b t :: real + assumes "a \ b" and "t \ 0" + shows "cmod ((iexp (t * b) - iexp (t * a)) / (ii * t)) \ b - a" (is "?F \ _") +proof - + have "?F = cmod (iexp (t * a) * (iexp (t * (b - a)) - 1) / (ii * t))" + using `t \ 0` by (intro arg_cong[where f=norm]) (simp add: field_simps exp_diff exp_minus) + also have "\ = cmod (iexp (t * (b - a)) - 1) / abs t" + unfolding norm_divide norm_mult norm_exp_ii_times using `t \ 0` + by (simp add: complex_eq_iff norm_mult) + also have "\ \ abs (t * (b - a)) / abs t" + using iexp_approx1 [of "t * (b - a)" 0] + by (intro divide_right_mono) (auto simp add: field_simps eval_nat_numeral) + also have "\ = b - a" + using assms by (auto simp add: abs_mult) + finally show ?thesis . +qed + +(* TODO: refactor! *) +theorem (in real_distribution) Levy_Inversion: + fixes a b :: real + assumes "a \ b" + defines "\ \ measure M" and "\ \ char M" + assumes "\ {a} = 0" and "\ {b} = 0" + shows "(\T. 1 / (2 * pi) * (CLBINT t=-T..T. (iexp (-(t * a)) - iexp (-(t * b))) / (ii * t) * \ t)) + \ \ {a<..b}" + (is "(\T. 1 / (2 * pi) * (CLBINT t=-T..T. ?F t * \ t)) \ of_real (\ {a<..b})") +proof - + interpret P: pair_sigma_finite lborel M .. + from bounded_Si obtain B where Bprop: "\T. abs (Si T) \ B" by auto + from Bprop [of 0] have [simp]: "B \ 0" by auto + let ?f = "\t x :: real. (iexp (t * (x - a)) - iexp(t * (x - b))) / (ii * t)" + { fix T :: real + assume "T \ 0" + let ?f' = "\(t, x). indicator {-T<..R ?f t x" + { fix x + have 1: "complex_interval_lebesgue_integrable lborel u v (\t. ?f t x)" for u v :: real + using Levy_Inversion_aux2[of "x - b" "x - a"] + apply (simp add: interval_lebesgue_integrable_def del: times_divide_eq_left) + apply (intro integrableI_bounded_set_indicator[where B="b - a"] conjI impI) + apply (auto intro!: AE_I [of _ _ "{0}"] simp: assms) + done + have "(CLBINT t. ?f' (t, x)) = (CLBINT t=-T..T. ?f t x)" + using `T \ 0` by (simp add: interval_lebesgue_integral_def) + also have "\ = (CLBINT t=-T..(0 :: real). ?f t x) + (CLBINT t=(0 :: real)..T. ?f t x)" + (is "_ = _ + ?t") + using 1 by (intro interval_integral_sum[symmetric]) (simp add: min_absorb1 max_absorb2 \T \ 0\) + also have "(CLBINT t=-T..(0 :: real). ?f t x) = (CLBINT t=(0::real)..T. ?f (-t) x)" + by (subst interval_integral_reflect) auto + also have "\ + ?t = (CLBINT t=(0::real)..T. ?f (-t) x + ?f t x)" + using 1 + by (intro interval_lebesgue_integral_add(2) [symmetric] interval_integrable_mirror[THEN iffD2]) simp_all + also have "\ = (CLBINT t=(0::real)..T. ((iexp(t * (x - a)) - iexp (-(t * (x - a)))) - + (iexp(t * (x - b)) - iexp (-(t * (x - b))))) / (ii * t))" + using `T \ 0` by (intro interval_integral_cong) (auto simp add: divide_simps) + also have "\ = (CLBINT t=(0::real)..T. complex_of_real( + 2 * (sin (t * (x - a)) / t) - 2 * (sin (t * (x - b)) / t)))" + using `T \ 0` + apply (intro interval_integral_cong) + apply (simp add: field_simps cis.ctr Im_divide Re_divide Im_exp Re_exp complex_eq_iff) + unfolding minus_diff_eq[symmetric, of "y * x" "y * a" for y a] sin_minus cos_minus + apply (simp add: field_simps power2_eq_square) + done + also have "\ = complex_of_real (LBINT t=(0::real)..T. + 2 * (sin (t * (x - a)) / t) - 2 * (sin (t * (x - b)) / t))" + by (rule interval_lebesgue_integral_of_real) + also have "\ = complex_of_real (2 * (sgn (x - a) * Si (T * abs (x - a)) - + sgn (x - b) * Si (T * abs (x - b))))" + apply (subst interval_lebesgue_integral_diff) + apply (rule interval_lebesgue_integrable_mult_right, rule integrable_sinc')+ + apply (subst interval_lebesgue_integral_mult_right)+ + apply (simp add: zero_ereal_def[symmetric] LBINT_I0c_sin_scale_divide[OF `T \ 0`]) + done + finally have "(CLBINT t. ?f' (t, x)) = + 2 * (sgn (x - a) * Si (T * abs (x - a)) - sgn (x - b) * Si (T * abs (x - b)))" . + } note main_eq = this + have "(CLBINT t=-T..T. ?F t * \ t) = + (CLBINT t. (CLINT x | M. ?F t * iexp (t * x) * indicator {-T<.. 0` unfolding \_def char_def interval_lebesgue_integral_def + by (auto split: split_indicator intro!: integral_cong) + also have "\ = (CLBINT t. (CLINT x | M. ?f' (t, x)))" + by (auto intro!: integral_cong simp: field_simps exp_diff exp_minus split: split_indicator) + also have "\ = (CLINT x | M. (CLBINT t. ?f' (t, x)))" + proof (intro P.Fubini_integral [symmetric] integrableI_bounded_set [where B="b - a"]) + show "emeasure (lborel \\<^sub>M M) ({- T<.. space M) < \" + using \T \ 0\ by (subst emeasure_pair_measure_Times) auto + show "AE x\{- T<.. space M in lborel \\<^sub>M M. cmod (case x of (t, x) \ ?f' (t, x)) \ b - a" + using Levy_Inversion_aux2[of "x - b" "x - a" for x] `a \ b` + by (intro AE_I [of _ _ "{0} \ UNIV"]) (force simp: emeasure_pair_measure_Times)+ + qed (auto split: split_indicator split_indicator_asm) + also have "\ = (CLINT x | M. (complex_of_real (2 * (sgn (x - a) * + Si (T * abs (x - a)) - sgn (x - b) * Si (T * abs (x - b))))))" + using main_eq by (intro integral_cong, auto) + also have "\ = complex_of_real (LINT x | M. (2 * (sgn (x - a) * + Si (T * abs (x - a)) - sgn (x - b) * Si (T * abs (x - b)))))" + by (rule integral_complex_of_real) + finally have "(CLBINT t=-T..T. ?F t * \ t) = + complex_of_real (LINT x | M. (2 * (sgn (x - a) * + Si (T * abs (x - a)) - sgn (x - b) * Si (T * abs (x - b)))))" . + } note main_eq2 = this + + have "(\T :: nat. LINT x | M. (2 * (sgn (x - a) * + Si (T * abs (x - a)) - sgn (x - b) * Si (T * abs (x - b))))) \ + (LINT x | M. 2 * pi * indicator {a<..b} x)" + proof (rule integral_dominated_convergence [where w="\x. 4 * B"]) + show "integrable M (\x. 4 * B)" + by (rule integrable_const_bound [of _ "4 * B"]) auto + next + let ?S = "\n::nat. \x. sgn (x - a) * Si (n * \x - a\) - sgn (x - b) * Si (n * \x - b\)" + { fix n x + have "norm (?S n x) \ norm (sgn (x - a) * Si (n * \x - a\)) + norm (sgn (x - b) * Si (n * \x - b\))" + by (rule norm_triangle_ineq4) + also have "\ \ B + B" + using Bprop by (intro add_mono) (auto simp: abs_mult abs_sgn_eq) + finally have "norm (2 * ?S n x) \ 4 * B" + by simp } + then show "\n. AE x in M. norm (2 * ?S n x) \ 4 * B" + by auto + have "AE x in M. x \ a" "AE x in M. x \ b" + using prob_eq_0[of "{a}"] prob_eq_0[of "{b}"] `\ {a} = 0` `\ {b} = 0` by (auto simp: \_def) + then show "AE x in M. (\n. 2 * ?S n x) \ 2 * pi * indicator {a<..b} x" + proof eventually_elim + fix x assume x: "x \ a" "x \ b" + then have "(\n. 2 * (sgn (x - a) * Si (\x - a\ * n) - sgn (x - b) * Si (\x - b\ * n))) + \ 2 * (sgn (x - a) * (pi / 2) - sgn (x - b) * (pi / 2))" + by (intro tendsto_intros filterlim_compose[OF Si_at_top] + filterlim_tendsto_pos_mult_at_top[OF tendsto_const] filterlim_real_sequentially) + auto + also have "(\n. 2 * (sgn (x - a) * Si (\x - a\ * n) - sgn (x - b) * Si (\x - b\ * n))) = (\n. 2 * ?S n x)" + by (auto simp: ac_simps) + also have "2 * (sgn (x - a) * (pi / 2) - sgn (x - b) * (pi / 2)) = 2 * pi * indicator {a<..b} x" + using x `a \ b` by (auto split: split_indicator) + finally show "(\n. 2 * ?S n x) \ 2 * pi * indicator {a<..b} x" . + qed + qed simp_all + also have "(LINT x | M. 2 * pi * indicator {a<..b} x) = 2 * pi * \ {a<..b}" + by (simp add: \_def) + finally have "(\T. LINT x | M. (2 * (sgn (x - a) * + Si (T * abs (x - a)) - sgn (x - b) * Si (T * abs (x - b))))) \ + 2 * pi * \ {a<..b}" . + with main_eq2 show ?thesis + by (auto intro!: tendsto_eq_intros) +qed + +theorem Levy_uniqueness: + fixes M1 M2 :: "real measure" + assumes "real_distribution M1" "real_distribution M2" and + "char M1 = char M2" + shows "M1 = M2" +proof - + interpret M1: real_distribution M1 by (rule assms) + interpret M2: real_distribution M2 by (rule assms) + have "countable ({x. measure M1 {x} \ 0} \ {x. measure M2 {x} \ 0})" + by (intro countable_Un M2.countable_support M1.countable_support) + then have count: "countable {x. measure M1 {x} \ 0 \ measure M2 {x} \ 0}" + by (simp add: Un_def) + + have "cdf M1 = cdf M2" + proof (rule ext) + fix x + from M1.cdf_is_right_cont [of x] have "(cdf M1 \ cdf M1 x) (at_right x)" + by (simp add: continuous_within) + from M2.cdf_is_right_cont [of x] have "(cdf M2 \ cdf M2 x) (at_right x)" + by (simp add: continuous_within) + + { fix \ :: real + assume "\ > 0" + from `\ > 0` `(cdf M1 \ 0) at_bot` `(cdf M2 \ 0) at_bot` + have "eventually (\y. \cdf M1 y\ < \ / 4 \ \cdf M2 y\ < \ / 4 \ y \ x) at_bot" + by (simp only: tendsto_iff dist_real_def diff_0_right eventually_conj eventually_le_at_bot) + then obtain M where "\y. y \ M \ \cdf M1 y\ < \ / 4" "\y. y \ M \ \cdf M2 y\ < \ / 4" "M \ x" + unfolding eventually_at_bot_linorder by auto + with open_minus_countable[OF count, of "{..< M}"] obtain a where + "measure M1 {a} = 0" "measure M2 {a} = 0" "a < M" "a \ x" "\cdf M1 a\ < \ / 4" "\cdf M2 a\ < \ / 4" + by auto + + from `\ > 0` `(cdf M1 \ cdf M1 x) (at_right x)` `(cdf M2 \ cdf M2 x) (at_right x)` + have "eventually (\y. \cdf M1 y - cdf M1 x\ < \ / 4 \ \cdf M2 y - cdf M2 x\ < \ / 4 \ x < y) (at_right x)" + by (simp only: tendsto_iff dist_real_def eventually_conj eventually_at_right_less) + then obtain N where "N > x" "\y. x < y \ y < N \ \cdf M1 y - cdf M1 x\ < \ / 4" + "\y. x < y \ y < N \ \cdf M2 y - cdf M2 x\ < \ / 4" "\y. x < y \ y < N \ x < y" + by (auto simp add: eventually_at_right[OF less_add_one]) + with open_minus_countable[OF count, of "{x <..< N}"] obtain b where "x < b" "b < N" + "measure M1 {b} = 0" "measure M2 {b} = 0" "\cdf M2 x - cdf M2 b\ < \ / 4" "\cdf M1 x - cdf M1 b\ < \ / 4" + by (auto simp: abs_minus_commute) + from `a \ x` `x < b` have "a < b" "a \ b" by auto + + from `char M1 = char M2` + M1.Levy_Inversion [OF `a \ b` `measure M1 {a} = 0` `measure M1 {b} = 0`] + M2.Levy_Inversion [OF `a \ b` `measure M2 {a} = 0` `measure M2 {b} = 0`] + have "complex_of_real (measure M1 {a<..b}) = complex_of_real (measure M2 {a<..b})" + by (intro LIMSEQ_unique) auto + then have "measure M1 {a<..b} = measure M2 {a<..b}" by auto + then have *: "cdf M1 b - cdf M1 a = cdf M2 b - cdf M2 a" + unfolding M1.cdf_diff_eq [OF `a < b`] M2.cdf_diff_eq [OF `a < b`] . + + have "abs (cdf M1 x - (cdf M1 b - cdf M1 a)) = abs (cdf M1 x - cdf M1 b + cdf M1 a)" + by simp + also have "\ \ abs (cdf M1 x - cdf M1 b) + abs (cdf M1 a)" + by (rule abs_triangle_ineq) + also have "\ \ \ / 4 + \ / 4" + by (intro add_mono less_imp_le \\cdf M1 a\ < \ / 4\ \\cdf M1 x - cdf M1 b\ < \ / 4\) + finally have 1: "abs (cdf M1 x - (cdf M1 b - cdf M1 a)) \ \ / 2" by simp + + have "abs (cdf M2 x - (cdf M2 b - cdf M2 a)) = abs (cdf M2 x - cdf M2 b + cdf M2 a)" + by simp + also have "\ \ abs (cdf M2 x - cdf M2 b) + abs (cdf M2 a)" + by (rule abs_triangle_ineq) + also have "\ \ \ / 4 + \ / 4" + by (intro add_mono less_imp_le \\cdf M2 x - cdf M2 b\ < \ / 4\ \\cdf M2 a\ < \ / 4\) + finally have 2: "abs (cdf M2 x - (cdf M2 b - cdf M2 a)) \ \ / 2" by simp + + have "abs (cdf M1 x - cdf M2 x) = abs ((cdf M1 x - (cdf M1 b - cdf M1 a)) - + (cdf M2 x - (cdf M2 b - cdf M2 a)))" by (subst *, simp) + also have "\ \ abs (cdf M1 x - (cdf M1 b - cdf M1 a)) + + abs (cdf M2 x - (cdf M2 b - cdf M2 a))" by (rule abs_triangle_ineq4) + also have "\ \ \ / 2 + \ / 2" by (rule add_mono [OF 1 2]) + finally have "abs (cdf M1 x - cdf M2 x) \ \" by simp } + then show "cdf M1 x = cdf M2 x" + by (metis abs_le_zero_iff dense_ge eq_iff_diff_eq_0) + qed + thus ?thesis + by (rule cdf_unique [OF `real_distribution M1` `real_distribution M2`]) +qed + + +subsection \The Levy continuity theorem\ + +theorem levy_continuity1: + fixes M :: "nat \ real measure" and M' :: "real measure" + assumes "\n. real_distribution (M n)" "real_distribution M'" "weak_conv_m M M'" + shows "(\n. char (M n) t) \ char M' t" + unfolding char_def using assms by (rule weak_conv_imp_integral_bdd_continuous_conv) auto + +theorem levy_continuity: + fixes M :: "nat \ real measure" and M' :: "real measure" + assumes real_distr_M : "\n. real_distribution (M n)" + and real_distr_M': "real_distribution M'" + and char_conv: "\t. (\n. char (M n) t) \ char M' t" + shows "weak_conv_m M M'" +proof - + interpret Mn: real_distribution "M n" for n by fact + interpret M': real_distribution M' by fact + + have *: "\u x. u > 0 \ x \ 0 \ (CLBINT t:{-u..u}. 1 - iexp (t * x)) = + 2 * (u - sin (u * x) / x)" + proof - + fix u :: real and x :: real + assume "u > 0" and "x \ 0" + hence "(CLBINT t:{-u..u}. 1 - iexp (t * x)) = (CLBINT t=-u..u. 1 - iexp (t * x))" + by (subst interval_integral_Icc, auto) + also have "\ = (CLBINT t=-u..0. 1 - iexp (t * x)) + (CLBINT t=0..u. 1 - iexp (t * x))" + using `u > 0` + apply (subst interval_integral_sum) + apply (simp add: min_absorb1 min_absorb2 max_absorb1 max_absorb2) + apply (rule interval_integrable_isCont) + apply auto + done + also have "\ = (CLBINT t=ereal 0..u. 1 - iexp (t * -x)) + (CLBINT t=ereal 0..u. 1 - iexp (t * x))" + apply (subgoal_tac "0 = ereal 0", erule ssubst) + by (subst interval_integral_reflect, auto) + also have "\ = (LBINT t=ereal 0..u. 2 - 2 * cos (t * x))" + apply (subst interval_lebesgue_integral_add (2) [symmetric]) + apply ((rule interval_integrable_isCont, auto)+) [2] + unfolding exp_Euler cos_of_real + apply (simp add: of_real_mult interval_lebesgue_integral_of_real[symmetric]) + done + also have "\ = 2 * u - 2 * sin (u * x) / x" + by (subst interval_lebesgue_integral_diff) + (auto intro!: interval_integrable_isCont + simp: interval_lebesgue_integral_of_real integral_cos [OF `x \ 0`] mult.commute[of _ x]) + finally show "(CLBINT t:{-u..u}. 1 - iexp (t * x)) = 2 * (u - sin (u * x) / x)" + by (simp add: field_simps) + qed + have main_bound: "\u n. u > 0 \ Re (CLBINT t:{-u..u}. 1 - char (M n) t) \ + u * measure (M n) {x. abs x \ 2 / u}" + proof - + fix u :: real and n + assume "u > 0" + interpret P: pair_sigma_finite "M n" lborel .. + (* TODO: put this in the real_distribution locale as a simp rule? *) + have Mn1 [simp]: "measure (M n) UNIV = 1" by (metis Mn.prob_space Mn.space_eq_univ) + (* TODO: make this automatic somehow? *) + have Mn2 [simp]: "\x. complex_integrable (M n) (\t. exp (\ * complex_of_real (x * t)))" + by (rule Mn.integrable_const_bound [where B = 1], auto) + have Mn3: "set_integrable (M n \\<^sub>M lborel) (UNIV \ {- u..u}) (\a. 1 - exp (\ * complex_of_real (snd a * fst a)))" + using `0 < u` + by (intro integrableI_bounded_set_indicator [where B="2"]) + (auto simp: lborel.emeasure_pair_measure_Times split: split_indicator + intro!: order_trans [OF norm_triangle_ineq4]) + have "(CLBINT t:{-u..u}. 1 - char (M n) t) = + (CLBINT t:{-u..u}. (CLINT x | M n. 1 - iexp (t * x)))" + unfolding char_def by (rule set_lebesgue_integral_cong, auto simp del: of_real_mult) + also have "\ = (CLBINT t. (CLINT x | M n. indicator {-u..u} t *\<^sub>R (1 - iexp (t * x))))" + by (rule integral_cong) (auto split: split_indicator) + also have "\ = (CLINT x | M n. (CLBINT t:{-u..u}. 1 - iexp (t * x)))" + using Mn3 by (subst P.Fubini_integral) (auto simp: indicator_times split_beta') + also have "\ = (CLINT x | M n. (if x = 0 then 0 else 2 * (u - sin (u * x) / x)))" + using `u > 0` by (intro integral_cong, auto simp add: * simp del: of_real_mult) + also have "\ = (LINT x | M n. (if x = 0 then 0 else 2 * (u - sin (u * x) / x)))" + by (rule integral_complex_of_real) + finally have "Re (CLBINT t:{-u..u}. 1 - char (M n) t) = + (LINT x | M n. (if x = 0 then 0 else 2 * (u - sin (u * x) / x)))" by simp + also have "\ \ (LINT x : {x. abs x \ 2 / u} | M n. u)" + proof - + have "complex_integrable (M n) (\x. CLBINT t:{-u..u}. 1 - iexp (snd (x, t) * fst (x, t)))" + using Mn3 by (intro P.integrable_fst) (simp add: indicator_times split_beta') + hence "complex_integrable (M n) (\x. if x = 0 then 0 else 2 * (u - sin (u * x) / x))" + using `u > 0` by (subst integrable_cong) (auto simp add: * simp del: of_real_mult) + hence **: "integrable (M n) (\x. if x = 0 then 0 else 2 * (u - sin (u * x) / x))" + unfolding complex_of_real_integrable_eq . + have "2 * sin x \ x" if "2 \ x" for x :: real + by (rule order_trans[OF _ \2 \ x\]) auto + moreover have "x \ 2 * sin x" if "x \ - 2" for x :: real + by (rule order_trans[OF \x \ - 2\]) auto + moreover have "x < 0 \ x \ sin x" for x :: real + using sin_x_le_x[of "-x"] by simp + ultimately show ?thesis + using `u > 0` + by (intro integral_mono [OF _ **]) + (auto simp: divide_simps sin_x_le_x mult.commute[of u] mult_neg_pos split: split_indicator) + qed + also (xtrans) have "(LINT x : {x. abs x \ 2 / u} | M n. u) = + u * measure (M n) {x. abs x \ 2 / u}" + by (simp add: Mn.emeasure_eq_measure) + finally show "Re (CLBINT t:{-u..u}. 1 - char (M n) t) \ u * measure (M n) {x. abs x \ 2 / u}" . + qed + + have tight_aux: "\\. \ > 0 \ \a b. a < b \ (\n. 1 - \ < measure (M n) {a<..b})" + proof - + fix \ :: real + assume "\ > 0" + note M'.isCont_char [of 0] + hence "\d>0. \t. abs t < d \ cmod (char M' t - 1) < \ / 4" + apply (subst (asm) continuous_at_eps_delta) + apply (drule_tac x = "\ / 4" in spec) + using `\ > 0` by (auto simp add: dist_real_def dist_complex_def M'.char_zero) + then obtain d where "d > 0 \ (\t. (abs t < d \ cmod (char M' t - 1) < \ / 4))" .. + hence d0: "d > 0" and d1: "\t. abs t < d \ cmod (char M' t - 1) < \ / 4" by auto + have 1: "\x. cmod (1 - char M' x) \ 2" + by (rule order_trans [OF norm_triangle_ineq4], auto simp add: M'.cmod_char_le_1) + then have 2: "\u v. complex_set_integrable lborel {u..v} (\x. 1 - char M' x)" + by (intro integrableI_bounded_set_indicator[where B=2]) (auto simp: emeasure_lborel_Icc_eq) + have 3: "\u v. set_integrable lborel {u..v} (\x. cmod (1 - char M' x))" + by (intro borel_integrable_compact[OF compact_Icc] continuous_at_imp_continuous_on + continuous_intros ballI M'.isCont_char continuous_intros) + have "cmod (CLBINT t:{-d/2..d/2}. 1 - char M' t) \ LBINT t:{-d/2..d/2}. cmod (1 - char M' t)" + using integral_norm_bound[OF 2] by simp + also have "\ \ LBINT t:{-d/2..d/2}. \ / 4" + apply (rule integral_mono [OF 3]) + apply (simp add: emeasure_lborel_Icc_eq) + apply (case_tac "x \ {-d/2..d/2}", auto) + apply (subst norm_minus_commute) + apply (rule less_imp_le) + apply (rule d1 [simplified]) + using d0 by auto + also with d0 have "\ = d * \ / 4" + by simp + finally have bound: "cmod (CLBINT t:{-d/2..d/2}. 1 - char M' t) \ d * \ / 4" . + { fix n x + have "cmod (1 - char (M n) x) \ 2" + by (rule order_trans [OF norm_triangle_ineq4], auto simp add: Mn.cmod_char_le_1) + } note bd1 = this + have "(\n. CLBINT t:{-d/2..d/2}. 1 - char (M n) t) \ (CLBINT t:{-d/2..d/2}. 1 - char M' t)" + using bd1 + apply (intro integral_dominated_convergence[where w="\x. indicator {-d/2..d/2} x *\<^sub>R 2"]) + apply (auto intro!: char_conv tendsto_intros + simp: emeasure_lborel_Icc_eq + split: split_indicator) + done + hence "eventually (\n. cmod ((CLBINT t:{-d/2..d/2}. 1 - char (M n) t) - + (CLBINT t:{-d/2..d/2}. 1 - char M' t)) < d * \ / 4) sequentially" + using d0 `\ > 0` apply (subst (asm) tendsto_iff) + by (subst (asm) dist_complex_def, drule spec, erule mp, auto) + hence "\N. \n \ N. cmod ((CLBINT t:{-d/2..d/2}. 1 - char (M n) t) - + (CLBINT t:{-d/2..d/2}. 1 - char M' t)) < d * \ / 4" by (simp add: eventually_sequentially) + then guess N .. + hence N: "\n. n \ N \ cmod ((CLBINT t:{-d/2..d/2}. 1 - char (M n) t) - + (CLBINT t:{-d/2..d/2}. 1 - char M' t)) < d * \ / 4" by auto + { fix n + assume "n \ N" + have "cmod (CLBINT t:{-d/2..d/2}. 1 - char (M n) t) = + cmod ((CLBINT t:{-d/2..d/2}. 1 - char (M n) t) - (CLBINT t:{-d/2..d/2}. 1 - char M' t) + + (CLBINT t:{-d/2..d/2}. 1 - char M' t))" by simp + also have "\ \ cmod ((CLBINT t:{-d/2..d/2}. 1 - char (M n) t) - + (CLBINT t:{-d/2..d/2}. 1 - char M' t)) + cmod(CLBINT t:{-d/2..d/2}. 1 - char M' t)" + by (rule norm_triangle_ineq) + also have "\ < d * \ / 4 + d * \ / 4" + by (rule add_less_le_mono [OF N [OF `n \ N`] bound]) + also have "\ = d * \ / 2" by auto + finally have "cmod (CLBINT t:{-d/2..d/2}. 1 - char (M n) t) < d * \ / 2" . + hence "d * \ / 2 > Re (CLBINT t:{-d/2..d/2}. 1 - char (M n) t)" + by (rule order_le_less_trans [OF complex_Re_le_cmod]) + hence "d * \ / 2 > Re (CLBINT t:{-(d/2)..d/2}. 1 - char (M n) t)" (is "_ > ?lhs") by simp + also have "?lhs \ (d / 2) * measure (M n) {x. abs x \ 2 / (d / 2)}" + using d0 by (intro main_bound, simp) + finally (xtrans) have "d * \ / 2 > (d / 2) * measure (M n) {x. abs x \ 2 / (d / 2)}" . + with d0 `\ > 0` have "\ > measure (M n) {x. abs x \ 2 / (d / 2)}" by (simp add: field_simps) + hence "\ > 1 - measure (M n) (UNIV - {x. abs x \ 2 / (d / 2)})" + apply (subst Mn.borel_UNIV [symmetric]) + by (subst Mn.prob_compl, auto) + also have "UNIV - {x. abs x \ 2 / (d / 2)} = {x. -(4 / d) < x \ x < (4 / d)}" + using d0 apply (auto simp add: field_simps) + (* very annoying -- this should be automatic *) + apply (case_tac "x \ 0", auto simp add: field_simps) + apply (subgoal_tac "0 \ x * d", arith, rule mult_nonneg_nonneg, auto) + apply (case_tac "x \ 0", auto simp add: field_simps) + apply (subgoal_tac "x * d \ 0", arith) + apply (rule mult_nonpos_nonneg, auto) + by (case_tac "x \ 0", auto simp add: field_simps) + finally have "measure (M n) {x. -(4 / d) < x \ x < (4 / d)} > 1 - \" + by auto + } note 6 = this + { fix n :: nat + have *: "(UN (k :: nat). {- real k<..real k}) = UNIV" + by (auto, metis leI le_less_trans less_imp_le minus_less_iff reals_Archimedean2) + have "(\k. measure (M n) {- real k<..real k}) \ + measure (M n) (UN (k :: nat). {- real k<..real k})" + by (rule Mn.finite_Lim_measure_incseq, auto simp add: incseq_def) + hence "(\k. measure (M n) {- real k<..real k}) \ 1" + using Mn.prob_space unfolding * Mn.borel_UNIV by simp + hence "eventually (\k. measure (M n) {- real k<..real k} > 1 - \) sequentially" + apply (elim order_tendstoD (1)) + using `\ > 0` by auto + } note 7 = this + { fix n :: nat + have "eventually (\k. \m < n. measure (M m) {- real k<..real k} > 1 - \) sequentially" + (is "?P n") + proof (induct n) + case (Suc n) with 7[of n] show ?case + by eventually_elim (auto simp add: less_Suc_eq) + qed simp + } note 8 = this + from 8 [of N] have "\K :: nat. \k \ K. \m < + Sigma_Algebra.measure (M m) {- real k<..real k}" + by (auto simp add: eventually_sequentially) + hence "\K :: nat. \m < Sigma_Algebra.measure (M m) {- real K<..real K}" by auto + then obtain K :: nat where + "\m < Sigma_Algebra.measure (M m) {- real K<..real K}" .. + hence K: "\m. m < N \ 1 - \ < Sigma_Algebra.measure (M m) {- real K<..real K}" + by auto + let ?K' = "max K (4 / d)" + have "-?K' < ?K' \ (\n. 1 - \ < measure (M n) {-?K'<..?K'})" + using d0 apply auto + apply (rule max.strict_coboundedI2, auto) + proof - + fix n + show " 1 - \ < measure (M n) {- max (real K) (4 / d)<..max (real K) (4 / d)}" + apply (case_tac "n < N") + apply (rule order_less_le_trans) + apply (erule K) + apply (rule Mn.finite_measure_mono, auto) + apply (rule order_less_le_trans) + apply (rule 6, erule leI) + by (rule Mn.finite_measure_mono, auto) + qed + thus "\a b. a < b \ (\n. 1 - \ < measure (M n) {a<..b})" by (intro exI) + qed + have tight: "tight M" + by (auto simp: tight_def intro: assms tight_aux) + show ?thesis + proof (rule tight_subseq_weak_converge [OF real_distr_M real_distr_M' tight]) + fix s \ + assume s: "subseq s" + assume nu: "weak_conv_m (M \ s) \" + assume *: "real_distribution \" + have 2: "\n. real_distribution ((M \ s) n)" unfolding comp_def by (rule assms) + have 3: "\t. (\n. char ((M \ s) n) t) \ char \ t" by (intro levy_continuity1 [OF 2 * nu]) + have 4: "\t. (\n. char ((M \ s) n) t) = ((\n. char (M n) t) \ s)" by (rule ext, simp) + have 5: "\t. (\n. char ((M \ s) n) t) \ char M' t" + by (subst 4, rule lim_subseq [OF s], rule assms) + hence "char \ = char M'" by (intro ext, intro LIMSEQ_unique [OF 3 5]) + hence "\ = M'" by (rule Levy_uniqueness [OF * `real_distribution M'`]) + thus "weak_conv_m (M \ s) M'" + apply (elim subst) + by (rule nu) + qed +qed + +end diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Probability/Nonnegative_Lebesgue_Integration.thy --- a/src/HOL/Probability/Nonnegative_Lebesgue_Integration.thy Wed Jan 06 13:04:31 2016 +0100 +++ b/src/HOL/Probability/Nonnegative_Lebesgue_Integration.thy Wed Jan 06 12:18:53 2016 +0100 @@ -1186,6 +1186,25 @@ finally show ?thesis . qed +lemma nn_integral_indicator_singleton[simp]: + assumes [measurable]: "{y} \ sets M" + shows "(\\<^sup>+x. f x * indicator {y} x \M) = max 0 (f y) * emeasure M {y}" +proof- + have "(\\<^sup>+x. f x * indicator {y} x \M) = (\\<^sup>+x. max 0 (f y) * indicator {y} x \M)" + by (subst nn_integral_max_0[symmetric]) (auto intro!: nn_integral_cong split: split_indicator) + then show ?thesis + by (simp add: nn_integral_cmult) +qed + +lemma nn_integral_set_ereal: + "(\\<^sup>+x. ereal (f x) * indicator A x \M) = (\\<^sup>+x. ereal (f x * indicator A x) \M)" + by (rule nn_integral_cong) (simp split: split_indicator) + +lemma nn_integral_indicator_singleton'[simp]: + assumes [measurable]: "{y} \ sets M" + shows "(\\<^sup>+x. ereal (f x * indicator {y} x) \M) = max 0 (f y) * emeasure M {y}" + by (subst nn_integral_set_ereal[symmetric]) (simp add: nn_integral_indicator_singleton) + lemma nn_integral_add: assumes f: "f \ borel_measurable M" "AE x in M. 0 \ f x" and g: "g \ borel_measurable M" "AE x in M. 0 \ g x" @@ -1854,7 +1873,7 @@ by (subst nn_integral_setsum) (simp_all add: AE_count_space ereal_zero_le_0_iff less_imp_le) also have "\ = (\a|a\A \ 0 < f a. f a)" - by (auto intro!: setsum.cong simp: nn_integral_cmult_indicator one_ereal_def[symmetric]) + by (auto intro!: setsum.cong simp: one_ereal_def[symmetric] max_def) finally show ?thesis by (simp add: nn_integral_max_0) qed @@ -1890,7 +1909,7 @@ from f have "(\\<^sup>+x. f x * indicator A x \M) = (\\<^sup>+x. (\a\A. f a * indicator {a} x) \M)" by (intro nn_integral_cong) (auto simp: indicator_def if_distrib[where f="\a. x * a" for x] setsum.If_cases) also have "\ = (\a\A. f a * emeasure M {a})" - using nn by (subst nn_integral_setsum) (auto simp: nn_integral_cmult_indicator) + using nn by (subst nn_integral_setsum) (auto simp: max_def) finally show ?thesis . qed @@ -1912,7 +1931,7 @@ also have "\ = (\j. (\\<^sup>+i. f j * indicator {j} i \count_space UNIV))" by (rule nn_integral_suminf) (auto simp: nonneg) also have "\ = (\j. f j)" - by (simp add: nonneg nn_integral_cmult_indicator one_ereal_def[symmetric]) + by (simp add: nonneg one_ereal_def[symmetric] max_def) finally show ?thesis . qed diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Probability/Probability.thy --- a/src/HOL/Probability/Probability.thy Wed Jan 06 13:04:31 2016 +0100 +++ b/src/HOL/Probability/Probability.thy Wed Jan 06 12:18:53 2016 +0100 @@ -7,12 +7,10 @@ Discrete_Topology Complete_Measure Projective_Limit - Independent_Family - Distributions Probability_Mass_Function Stream_Space Embed_Measure + Central_Limit_Theorem begin end - diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Probability/Probability_Mass_Function.thy --- a/src/HOL/Probability/Probability_Mass_Function.thy Wed Jan 06 13:04:31 2016 +0100 +++ b/src/HOL/Probability/Probability_Mass_Function.thy Wed Jan 06 12:18:53 2016 +0100 @@ -32,48 +32,6 @@ lemma ereal_divide': "b \ 0 \ ereal (a / b) = ereal a / ereal b" using ereal_divide[of a b] by simp -lemma (in finite_measure) countable_support: - "countable {x. measure M {x} \ 0}" -proof cases - assume "measure M (space M) = 0" - with bounded_measure measure_le_0_iff have "{x. measure M {x} \ 0} = {}" - by auto - then show ?thesis - by simp -next - let ?M = "measure M (space M)" and ?m = "\x. measure M {x}" - assume "?M \ 0" - then have *: "{x. ?m x \ 0} = (\n. {x. ?M / Suc n < ?m x})" - using reals_Archimedean[of "?m x / ?M" for x] - by (auto simp: field_simps not_le[symmetric] measure_nonneg divide_le_0_iff measure_le_0_iff) - have **: "\n. finite {x. ?M / Suc n < ?m x}" - proof (rule ccontr) - fix n assume "infinite {x. ?M / Suc n < ?m x}" (is "infinite ?X") - then obtain X where "finite X" "card X = Suc (Suc n)" "X \ ?X" - by (metis infinite_arbitrarily_large) - from this(3) have *: "\x. x \ X \ ?M / Suc n \ ?m x" - by auto - { fix x assume "x \ X" - from \?M \ 0\ *[OF this] have "?m x \ 0" by (auto simp: field_simps measure_le_0_iff) - then have "{x} \ sets M" by (auto dest: measure_notin_sets) } - note singleton_sets = this - have "?M < (\x\X. ?M / Suc n)" - using \?M \ 0\ - by (simp add: \card X = Suc (Suc n)\ of_nat_Suc field_simps less_le measure_nonneg) - also have "\ \ (\x\X. ?m x)" - by (rule setsum_mono) fact - also have "\ = measure M (\x\X. {x})" - using singleton_sets \finite X\ - by (intro finite_measure_finite_Union[symmetric]) (auto simp: disjoint_family_on_def) - finally have "?M < measure M (\x\X. {x})" . - moreover have "measure M (\x\X. {x}) \ ?M" - using singleton_sets[THEN sets.sets_into_space] by (intro finite_measure_mono) auto - ultimately show False by simp - qed - show ?thesis - unfolding * by (intro countable_UN countableI_type countable_finite[OF **]) -qed - lemma (in finite_measure) AE_support_countable: assumes [simp]: "sets M = UNIV" shows "(AE x in M. measure M {x} \ 0) \ (\S. countable S \ (AE x in M. x \ S))" diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Probability/Probability_Measure.thy --- a/src/HOL/Probability/Probability_Measure.thy Wed Jan 06 13:04:31 2016 +0100 +++ b/src/HOL/Probability/Probability_Measure.thy Wed Jan 06 12:18:53 2016 +0100 @@ -9,6 +9,48 @@ imports Lebesgue_Measure Radon_Nikodym begin +lemma (in finite_measure) countable_support: + "countable {x. measure M {x} \ 0}" +proof cases + assume "measure M (space M) = 0" + with bounded_measure measure_le_0_iff have "{x. measure M {x} \ 0} = {}" + by auto + then show ?thesis + by simp +next + let ?M = "measure M (space M)" and ?m = "\x. measure M {x}" + assume "?M \ 0" + then have *: "{x. ?m x \ 0} = (\n. {x. ?M / Suc n < ?m x})" + using reals_Archimedean[of "?m x / ?M" for x] + by (auto simp: field_simps not_le[symmetric] measure_nonneg divide_le_0_iff measure_le_0_iff) + have **: "\n. finite {x. ?M / Suc n < ?m x}" + proof (rule ccontr) + fix n assume "infinite {x. ?M / Suc n < ?m x}" (is "infinite ?X") + then obtain X where "finite X" "card X = Suc (Suc n)" "X \ ?X" + by (metis infinite_arbitrarily_large) + from this(3) have *: "\x. x \ X \ ?M / Suc n \ ?m x" + by auto + { fix x assume "x \ X" + from \?M \ 0\ *[OF this] have "?m x \ 0" by (auto simp: field_simps measure_le_0_iff) + then have "{x} \ sets M" by (auto dest: measure_notin_sets) } + note singleton_sets = this + have "?M < (\x\X. ?M / Suc n)" + using \?M \ 0\ + by (simp add: \card X = Suc (Suc n)\ of_nat_Suc field_simps less_le measure_nonneg) + also have "\ \ (\x\X. ?m x)" + by (rule setsum_mono) fact + also have "\ = measure M (\x\X. {x})" + using singleton_sets \finite X\ + by (intro finite_measure_finite_Union[symmetric]) (auto simp: disjoint_family_on_def) + finally have "?M < measure M (\x\X. {x})" . + moreover have "measure M (\x\X. {x}) \ ?M" + using singleton_sets[THEN sets.sets_into_space] by (intro finite_measure_mono) auto + ultimately show False by simp + qed + show ?thesis + unfolding * by (intro countable_UN countableI_type countable_finite[OF **]) +qed + locale prob_space = finite_measure + assumes emeasure_space_1: "emeasure M (space M) = 1" diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Probability/Radon_Nikodym.thy --- a/src/HOL/Probability/Radon_Nikodym.thy Wed Jan 06 13:04:31 2016 +0100 +++ b/src/HOL/Probability/Radon_Nikodym.thy Wed Jan 06 12:18:53 2016 +0100 @@ -1295,7 +1295,7 @@ have "density M (RN_deriv M N) {x} = (\\<^sup>+w. RN_deriv M N x * indicator {x} w \M)" by (auto simp: indicator_def emeasure_density intro!: nn_integral_cong) with x density_RN_deriv[OF ac] RN_deriv_nonneg[of M N] show ?thesis - by (auto simp: nn_integral_cmult_indicator) + by (auto simp: max_def) qed end diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Probability/Set_Integral.thy --- a/src/HOL/Probability/Set_Integral.thy Wed Jan 06 13:04:31 2016 +0100 +++ b/src/HOL/Probability/Set_Integral.thy Wed Jan 06 12:18:53 2016 +0100 @@ -69,6 +69,19 @@ by (auto simp add: indicator_def) *) +lemma set_borel_measurable_sets: + fixes f :: "_ \ _::real_normed_vector" + assumes "set_borel_measurable M X f" "B \ sets borel" "X \ sets M" + shows "f -` B \ X \ sets M" +proof - + have "f \ borel_measurable (restrict_space M X)" + using assms by (subst borel_measurable_restrict_space_iff) auto + then have "f -` B \ space (restrict_space M X) \ sets (restrict_space M X)" + by (rule measurable_sets) fact + with \X \ sets M\ show ?thesis + by (subst (asm) sets_restrict_space_iff) (auto simp: space_restrict_space) +qed + lemma set_lebesgue_integral_cong: assumes "A \ sets M" and "\x. x \ A \ f x = g x" shows "(LINT x:A|M. f x) = (LINT x:A|M. g x)" diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Probability/Sigma_Algebra.thy --- a/src/HOL/Probability/Sigma_Algebra.thy Wed Jan 06 13:04:31 2016 +0100 +++ b/src/HOL/Probability/Sigma_Algebra.thy Wed Jan 06 12:18:53 2016 +0100 @@ -2206,6 +2206,10 @@ by simp qed +lemma restrict_space_sets_cong: + "A = B \ sets M = sets N \ sets (restrict_space M A) = sets (restrict_space N B)" + by (auto simp: sets_restrict_space) + lemma sets_restrict_space_count_space : "sets (restrict_space (count_space A) B) = sets (count_space (A \ B))" by(auto simp add: sets_restrict_space) diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Probability/Sinc_Integral.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Probability/Sinc_Integral.thy Wed Jan 06 12:18:53 2016 +0100 @@ -0,0 +1,403 @@ +(* + Theory: Sinc_Integral.thy + Authors: Jeremy Avigad, Luke Serafin, Johannes Hölzl +*) + +section \Integral of sinc\ + +theory Sinc_Integral + imports Distributions +begin + +subsection \Various preparatory integrals\ + +text \ Naming convention +The theorem name consists of the following parts: + \<^item> Kind of integral: @{text has_bochner_integral} / @{text integrable} / @{text LBINT} + \<^item> Interval: Interval (0 / infinity / open / closed) (infinity / open / closed) + \<^item> Name of the occurring constants: power, exp, m (for minus), scale, sin, $\ldots$ +\ + +lemma has_bochner_integral_I0i_power_exp_m': + "has_bochner_integral lborel (\x. x^k * exp (-x) * indicator {0 ..} x::real) (fact k)" + using nn_intergal_power_times_exp_Ici[of k] + by (intro has_bochner_integral_nn_integral) + (auto simp: ereal_indicator[symmetric] split: split_indicator) + +lemma has_bochner_integral_I0i_power_exp_m: + "has_bochner_integral lborel (\x. x^k * exp (-x) * indicator {0 <..} x::real) (fact k)" + using AE_lborel_singleton[of 0] + by (intro has_bochner_integral_cong_AE[THEN iffD1, OF _ _ _ has_bochner_integral_I0i_power_exp_m']) + (auto split: split_indicator) + +lemma integrable_I0i_exp_mscale: "0 < (u::real) \ set_integrable lborel {0 <..} (\x. exp (-(x * u)))" + using lborel_integrable_real_affine_iff[of u "\x. indicator {0 <..} x *\<^sub>R exp (- x)" 0] + has_bochner_integral_I0i_power_exp_m[of 0] + by (simp add: indicator_def zero_less_mult_iff mult_ac integrable.intros) + +lemma LBINT_I0i_exp_mscale: "0 < (u::real) \ LBINT x=0..\. exp (-(x * u)) = 1 / u" + using lborel_integral_real_affine[of u "\x. indicator {0<..} x *\<^sub>R exp (- x)" 0] + has_bochner_integral_I0i_power_exp_m[of 0] + by (auto simp: indicator_def zero_less_mult_iff interval_lebesgue_integral_0_infty field_simps + dest!: has_bochner_integral_integral_eq) + +lemma LBINT_I0c_exp_mscale_sin: + "LBINT x=0..t. exp (-(u * x)) * sin x = + (1 / (1 + u^2)) * (1 - exp (-(u * t)) * (u * sin t + cos t))" (is "_ = ?F t") + unfolding zero_ereal_def +proof (subst interval_integral_FTC_finite) + show "(?F has_vector_derivative exp (- (u * x)) * sin x) (at x within {min 0 t..max 0 t})" for x + by (auto intro!: derivative_eq_intros + simp: has_field_derivative_iff_has_vector_derivative[symmetric] power2_eq_square) + (simp_all add: field_simps add_nonneg_eq_0_iff) +qed (auto intro: continuous_at_imp_continuous_on) + +lemma LBINT_I0i_exp_mscale_sin: + assumes "0 < x" + shows "LBINT u=0..\. \exp (-u * x) * sin x\ = \sin x\ / x" +proof (subst interval_integral_FTC_nonneg) + let ?F = "\u. 1 / x * (1 - exp (- u * x)) * \sin x\" + show "\t. (?F has_real_derivative \exp (- t * x) * sin x\) (at t)" + using \0 < x\ by (auto intro!: derivative_eq_intros simp: abs_mult) + show "((?F \ real_of_ereal) \ 0) (at_right 0)" + using \0 < x\ by (auto simp: zero_ereal_def ereal_tendsto_simps intro!: tendsto_eq_intros) + have *: "((\t. exp (- t * x)) \ 0) at_top" + using \0 < x\ + by (auto intro!: exp_at_bot[THEN filterlim_compose] filterlim_tendsto_pos_mult_at_top filterlim_ident + simp: filterlim_uminus_at_bot mult.commute[of _ x]) + show "((?F \ real_of_ereal) \ \sin x\ / x) (at_left \)" + using \0 < x\ unfolding ereal_tendsto_simps + by (intro filterlim_compose[OF _ *]) (auto intro!: tendsto_eq_intros filterlim_ident) +qed auto + +lemma + shows integrable_inverse_1_plus_square: + "set_integrable lborel (einterval (-\) \) (\x. inverse (1 + x^2))" + and LBINT_inverse_1_plus_square: + "LBINT x=-\..\. inverse (1 + x^2) = pi" +proof - + have 1: "- (pi / 2) < x \ x * 2 < pi \ (tan has_real_derivative 1 + (tan x)\<^sup>2) (at x)" for x + using cos_gt_zero_pi[of x] by (subst tan_sec) (auto intro!: DERIV_tan simp: power_inverse) + have 2: "- (pi / 2) < x \ x * 2 < pi \ isCont (\x. 1 + (tan x)\<^sup>2) x" for x + using cos_gt_zero_pi[of x] by auto + show "LBINT x=-\..\. inverse (1 + x^2) = pi" + by (subst interval_integral_substitution_nonneg[of "-pi/2" "pi/2" tan "\x. 1 + (tan x)^2"]) + (auto intro: derivative_eq_intros 1 2 filterlim_tan_at_right + simp add: ereal_tendsto_simps filterlim_tan_at_left add_nonneg_eq_0_iff) + show "set_integrable lborel (einterval (-\) \) (\x. inverse (1 + x^2))" + by (subst interval_integral_substitution_nonneg[of "-pi/2" "pi/2" tan "\x. 1 + (tan x)^2"]) + (auto intro: derivative_eq_intros 1 2 filterlim_tan_at_right + simp add: ereal_tendsto_simps filterlim_tan_at_left add_nonneg_eq_0_iff) +qed + +lemma + shows integrable_I0i_1_div_plus_square: + "interval_lebesgue_integrable lborel 0 \ (\x. 1 / (1 + x^2))" + and LBINT_I0i_1_div_plus_square: + "LBINT x=0..\. 1 / (1 + x^2) = pi / 2" +proof - + have 1: "0 < x \ x * 2 < pi \ (tan has_real_derivative 1 + (tan x)\<^sup>2) (at x)" for x + using cos_gt_zero_pi[of x] by (subst tan_sec) (auto intro!: DERIV_tan simp: power_inverse) + have 2: "0 < x \ x * 2 < pi \ isCont (\x. 1 + (tan x)\<^sup>2) x" for x + using cos_gt_zero_pi[of x] by auto + show "LBINT x=0..\. 1 / (1 + x^2) = pi / 2" + by (subst interval_integral_substitution_nonneg[of "0" "pi/2" tan "\x. 1 + (tan x)^2"]) + (auto intro: derivative_eq_intros 1 2 tendsto_eq_intros + simp add: ereal_tendsto_simps filterlim_tan_at_left zero_ereal_def add_nonneg_eq_0_iff) + show "interval_lebesgue_integrable lborel 0 \ (\x. 1 / (1 + x^2))" + unfolding interval_lebesgue_integrable_def + by (subst interval_integral_substitution_nonneg[of "0" "pi/2" tan "\x. 1 + (tan x)^2"]) + (auto intro: derivative_eq_intros 1 2 tendsto_eq_intros + simp add: ereal_tendsto_simps filterlim_tan_at_left zero_ereal_def add_nonneg_eq_0_iff) +qed + +section \The sinc function, and the sine integral (Si)\ + +abbreviation sinc :: "real \ real" where + "sinc \ (\x. if x = 0 then 1 else sin x / x)" + +lemma sinc_at_0: "((\x. sin x / x::real) \ 1) (at 0)" + using DERIV_sin [of 0] by (auto simp add: has_field_derivative_def field_has_derivative_at) + +lemma isCont_sinc: "isCont sinc x" +proof cases + assume "x = 0" then show ?thesis + using LIM_equal [where g = "\x. sin x / x" and a=0 and f=sinc and l=1] + by (auto simp: isCont_def sinc_at_0) +next + assume "x \ 0" show ?thesis + by (rule continuous_transform_at [where d = "abs x" and f = "\x. sin x / x"]) + (auto simp add: dist_real_def \x \ 0\) +qed + +lemma continuous_on_sinc[continuous_intros]: + "continuous_on S f \ continuous_on S (\x. sinc (f x))" + using continuous_on_compose[of S f sinc, OF _ continuous_at_imp_continuous_on] + by (auto simp: isCont_sinc) + +lemma borel_measurable_sinc[measurable]: "sinc \ borel_measurable borel" + by (intro borel_measurable_continuous_on1 continuous_at_imp_continuous_on ballI isCont_sinc) + +lemma sinc_AE: "AE x in lborel. sin x / x = sinc x" + by (rule AE_I [where N = "{0}"], auto) + +definition Si :: "real \ real" where "Si t \ LBINT x=0..t. sin x / x" + +lemma sinc_neg [simp]: "sinc (- x) = sinc x" + by auto + +(* TODO: Determine whether this can reasonably be eliminated by redefining Si. *) +lemma Si_alt_def : "Si t = LBINT x=0..t. sinc x" +proof cases + assume "0 \ t" then show ?thesis + using AE_lborel_singleton[of 0] + by (auto simp: Si_def intro!: interval_lebesgue_integral_cong_AE) +next + assume "\ 0 \ t" then show ?thesis + unfolding Si_def using AE_lborel_singleton[of 0] + by (subst (1 2) interval_integral_endpoints_reverse) + (auto simp: Si_def intro!: interval_lebesgue_integral_cong_AE) +qed + +lemma Si_neg: + assumes "T \ 0" shows "Si (- T) = - Si T" +proof - + have "LBINT x=ereal 0..T. -1 *\<^sub>R sinc (- x) = LBINT y= ereal (- 0)..ereal (- T). sinc y" + by (rule interval_integral_substitution_finite [OF assms]) + (auto intro: derivative_intros continuous_at_imp_continuous_on isCont_sinc) + also have "(LBINT x=ereal 0..T. -1 *\<^sub>R sinc (- x)) = -(LBINT x=ereal 0..T. sinc x)" + by (subst sinc_neg) (simp_all add: interval_lebesgue_integral_uminus) + finally have *: "-(LBINT x=ereal 0..T. sinc x) = LBINT y= ereal 0..ereal (- T). sinc y" + by simp + show ?thesis + using assms unfolding Si_alt_def + by (subst zero_ereal_def)+ (auto simp add: * [symmetric]) +qed + +lemma integrable_sinc': + "interval_lebesgue_integrable lborel (ereal 0) (ereal T) (\t. sin (t * \) / t)" +proof - + have *: "interval_lebesgue_integrable lborel (ereal 0) (ereal T) (\t. \ * sinc (t * \))" + by (intro interval_lebesgue_integrable_mult_right interval_integrable_isCont continuous_within_compose3 [OF isCont_sinc]) + auto + show ?thesis + by (rule interval_lebesgue_integrable_cong_AE[THEN iffD1, OF _ _ _ *]) + (insert AE_lborel_singleton[of 0], auto) +qed + +(* TODO: need a better version of FTC2 *) +lemma DERIV_Si: "(Si has_real_derivative sinc x) (at x)" +proof - + have "(at x within {min 0 (x - 1)..max 0 (x + 1)}) = at x" + by (intro at_within_interior) auto + moreover have "min 0 (x - 1) \ x" "x \ max 0 (x + 1)" + by auto + ultimately show ?thesis + using interval_integral_FTC2[of "min 0 (x - 1)" 0 "max 0 (x + 1)" sinc x] + by (auto simp: continuous_at_imp_continuous_on isCont_sinc Si_alt_def[abs_def] zero_ereal_def + has_field_derivative_iff_has_vector_derivative + split del: split_if) +qed + +lemma isCont_Si: "isCont Si x" + using DERIV_Si by (rule DERIV_isCont) + +lemma borel_measurable_Si[measurable]: "Si \ borel_measurable borel" + by (auto intro: isCont_Si continuous_at_imp_continuous_on borel_measurable_continuous_on1) + +lemma Si_at_top_LBINT: + "((\t. (LBINT x=0..\. exp (-(x * t)) * (x * sin t + cos t) / (1 + x^2))) \ 0) at_top" +proof - + let ?F = "\x t. exp (- (x * t)) * (x * sin t + cos t) / (1 + x\<^sup>2) :: real" + have int: "set_integrable lborel {0<..} (\x. exp (- x) * (x + 1) :: real)" + unfolding distrib_left + using has_bochner_integral_I0i_power_exp_m[of 0] has_bochner_integral_I0i_power_exp_m[of 1] + by (intro set_integral_add) (auto dest!: integrable.intros simp: ac_simps) + + have "((\t::real. LBINT x:{0<..}. ?F x t) \ LBINT x::real:{0<..}. 0) at_top" + proof (rule integral_dominated_convergence_at_top[OF _ _ int], simp_all del: abs_divide split: split_indicator) + have *: "0 < x \ \x * sin t + cos t\ / (1 + x\<^sup>2) \ (x * 1 + 1) / 1" for x t :: real + by (intro frac_le abs_triangle_ineq[THEN order_trans] add_mono) + (auto simp add: abs_mult simp del: mult_1_right intro!: mult_mono) + then have **: "1 \ t \ 0 < x \ \?F x t\ \ exp (- x) * (x + 1)" for x t :: real + by (auto simp add: abs_mult times_divide_eq_right[symmetric] simp del: times_divide_eq_right + intro!: mult_mono) + + show "\\<^sub>F i in at_top. AE x in lborel. 0 < x \ \?F x i\ \ exp (- x) * (x + 1)" + using eventually_ge_at_top[of "1::real"] ** by (auto elim: eventually_mono) + show "AE x in lborel. 0 < x \ (?F x \ 0) at_top" + proof (intro always_eventually impI allI) + fix x :: real assume "0 < x" + show "((\t. exp (- (x * t)) * (x * sin t + cos t) / (1 + x\<^sup>2)) \ 0) at_top" + proof (rule Lim_null_comparison) + show "\\<^sub>F t in at_top. norm (?F x t) \ exp (- (x * t)) * (x + 1)" + using eventually_ge_at_top[of "1::real"] * \0 < x\ + by (auto simp add: abs_mult times_divide_eq_right[symmetric] simp del: times_divide_eq_right + intro!: mult_mono elim: eventually_mono) + show "((\t. exp (- (x * t)) * (x + 1)) \ 0) at_top" + by (auto simp: filterlim_uminus_at_top [symmetric] + intro!: filterlim_tendsto_pos_mult_at_top[OF tendsto_const] \0 filterlim_ident + tendsto_mult_left_zero filterlim_compose[OF exp_at_bot]) + qed + qed + qed + then show "((\t. (LBINT x=0..\. exp (-(x * t)) * (x * sin t + cos t) / (1 + x^2))) \ 0) at_top" + by (simp add: interval_lebesgue_integral_0_infty) +qed + +lemma Si_at_top_integrable: + assumes "t \ 0" + shows "interval_lebesgue_integrable lborel 0 \ (\x. exp (- (x * t)) * (x * sin t + cos t) / (1 + x\<^sup>2))" + using \0 \ t\ unfolding le_less +proof + assume "0 = t" then show ?thesis + using integrable_I0i_1_div_plus_square by simp +next + assume [arith]: "0 < t" + have *: "0 \ a \ 0 < x \ a / (1 + x\<^sup>2) \ a" for a x :: real + using zero_le_power2[of x, arith] using divide_left_mono[of 1 "1+x\<^sup>2" a] by auto + have "set_integrable lborel {0<..} (\x. (exp (- x) * x) * (sin t/t) + exp (- x) * cos t)" + using has_bochner_integral_I0i_power_exp_m[of 0] has_bochner_integral_I0i_power_exp_m[of 1] + by (intro set_integral_add set_integrable_mult_left) + (auto dest!: integrable.intros simp: ac_simps) + from lborel_integrable_real_affine[OF this, of t 0] + show ?thesis + unfolding interval_lebesgue_integral_0_infty + by (rule integrable_bound) (auto simp: field_simps * split: split_indicator) +qed + +lemma Si_at_top: "(Si \ pi / 2) at_top" +proof - + have "\\<^sub>F t in at_top. pi / 2 - (LBINT u=0..\. exp (-(u * t)) * (u * sin t + cos t) / (1 + u^2)) = Si t" + using eventually_ge_at_top[of 0] + proof eventually_elim + fix t :: real assume "t \ 0" + have "Si t = LBINT x=0..t. sin x * (LBINT u=0..\. exp (-(u * x)))" + unfolding Si_def using `0 \ t` + by (intro interval_integral_discrete_difference[where X="{0}"]) (auto simp: LBINT_I0i_exp_mscale) + also have "\ = LBINT x. (LBINT u=ereal 0..\. indicator {0 <..< t} x *\<^sub>R sin x * exp (-(u * x)))" + using \0\t\ by (simp add: zero_ereal_def interval_lebesgue_integral_le_eq mult_ac) + also have "\ = LBINT x. (LBINT u. indicator ({0<..} \ {0 <..< t}) (u, x) *\<^sub>R (sin x * exp (-(u * x))))" + by (subst interval_integral_Ioi) (simp_all add: indicator_times ac_simps) + also have "\ = LBINT u. (LBINT x. indicator ({0<..} \ {0 <..< t}) (u, x) *\<^sub>R (sin x * exp (-(u * x))))" + proof (intro lborel_pair.Fubini_integral[symmetric] lborel_pair.Fubini_integrable) + show "(\(x, y). indicator ({0<..} \ {0<..R (sin x * exp (- (y * x)))) + \ borel_measurable (lborel \\<^sub>M lborel)" (is "?f \ borel_measurable _") + by measurable + + have "AE x in lborel. indicator {0..t} x *\<^sub>R abs (sinc x) = LBINT y. norm (?f (x, y))" + using AE_lborel_singleton[of 0] AE_lborel_singleton[of t] + proof eventually_elim + fix x :: real assume x: "x \ 0" "x \ t" + have "LBINT y. \indicator ({0<..} \ {0<..R (sin x * exp (- (y * x)))\ = + LBINT y. \sin x\ * exp (- (y * x)) * indicator {0<..} y * indicator {0<.. = \sin x\ * indicator {0<... exp (- (y * x)))" + by (cases "x > 0") + (auto simp: field_simps interval_lebesgue_integral_0_infty split: split_indicator) + also have "\ = \sin x\ * indicator {0<.. 0") (auto simp add: LBINT_I0i_exp_mscale) + also have "\ = indicator {0..t} x *\<^sub>R \sinc x\" + using x by (simp add: field_simps split: split_indicator) + finally show "indicator {0..t} x *\<^sub>R abs (sinc x) = LBINT y. norm (?f (x, y))" + by simp + qed + moreover have "set_integrable lborel {0 .. t} (\x. abs (sinc x))" + by (auto intro!: borel_integrable_compact continuous_intros simp del: real_scaleR_def) + ultimately show "integrable lborel (\x. LBINT y. norm (?f (x, y)))" + by (rule integrable_cong_AE_imp[rotated 2]) simp + + have "0 < x \ set_integrable lborel {0<..} (\y. sin x * exp (- (y * x)))" for x :: real + by (intro set_integrable_mult_right integrable_I0i_exp_mscale) + then show "AE x in lborel. integrable lborel (\y. ?f (x, y))" + by (intro AE_I2) (auto simp: indicator_times split: split_indicator) + qed + also have "... = LBINT u=0..\. (LBINT x=0..t. exp (-(u * x)) * sin x)" + using \0\t\ + by (auto simp: interval_lebesgue_integral_def zero_ereal_def ac_simps + split: split_indicator intro!: integral_cong) + also have "\ = LBINT u=0..\. 1 / (1 + u\<^sup>2) - 1 / (1 + u\<^sup>2) * (exp (- (u * t)) * (u * sin t + cos t))" + by (auto simp: divide_simps LBINT_I0c_exp_mscale_sin intro!: interval_integral_cong) + also have "... = pi / 2 - (LBINT u=0..\. exp (- (u * t)) * (u * sin t + cos t) / (1 + u^2))" + using Si_at_top_integrable[OF \0\t\] by (simp add: integrable_I0i_1_div_plus_square LBINT_I0i_1_div_plus_square) + finally show "pi / 2 - (LBINT u=0..\. exp (-(u * t)) * (u * sin t + cos t) / (1 + u^2)) = Si t" .. + qed + then show ?thesis + by (rule Lim_transform_eventually) + (auto intro!: tendsto_eq_intros Si_at_top_LBINT) +qed + +subsection \The final theorems: boundedness and scalability\ + +lemma bounded_Si: "\B. \T. \Si T\ \ B" +proof - + have *: "0 \ y \ dist x y < z \ abs x \ y + z" for x y z :: real + by (simp add: dist_real_def) + + have "eventually (\T. dist (Si T) (pi / 2) < 1) at_top" + using Si_at_top by (elim tendstoD) simp + then have "eventually (\T. 0 \ T \ \Si T\ \ pi / 2 + 1) at_top" + using eventually_ge_at_top[of 0] by eventually_elim (insert *[of "pi/2" "Si _" 1], auto) + then have "\T. 0 \ T \ (\t \ T. \Si t\ \ pi / 2 + 1)" + by (auto simp add: eventually_at_top_linorder) + then obtain T where T: "0 \ T" "\t. t \ T \ \Si t\ \ pi / 2 + 1" + by auto + moreover have "t \ - T \ \Si t\ \ pi / 2 + 1" for t + using T(1) T(2)[of "-t"] Si_neg[of "- t"] by simp + moreover have "\M. \t. -T \ t \ t \ T \ \Si t\ \ M" + by (rule isCont_bounded) (auto intro!: isCont_Si continuous_intros \0 \ T\) + then obtain M where M: "\t. -T \ t \ t \ T \ \Si t\ \ M" + by auto + ultimately show ?thesis + by (intro exI[of _ "max M (pi/2 + 1)"]) (meson le_max_iff_disj linorder_not_le order_le_less) +qed + +lemma LBINT_I0c_sin_scale_divide: + assumes "T \ 0" + shows "LBINT t=0..T. sin (t * \) / t = sgn \ * Si (T * \\\)" +proof - + { assume "0 < \" + have "(LBINT t=ereal 0..T. sin (t * \) / t) = (LBINT t=ereal 0..T. \ *\<^sub>R sinc (t * \))" + by (rule interval_integral_discrete_difference[of "{0}"]) auto + also have "\ = (LBINT t=ereal (0 * \)..T * \. sinc t)" + apply (rule interval_integral_substitution_finite [OF assms]) + apply (subst mult.commute, rule DERIV_subset) + by (auto intro!: derivative_intros continuous_at_imp_continuous_on isCont_sinc) + also have "\ = (LBINT t=ereal (0 * \)..T * \. sin t / t)" + by (rule interval_integral_discrete_difference[of "{0}"]) auto + finally have "(LBINT t=ereal 0..T. sin (t * \) / t) = (LBINT t=ereal 0..T * \. sin t / t)" + by simp + hence "LBINT x. indicator {0<..) / x = + LBINT x. indicator {0<..} x * sin x / x" + using assms `0 < \` unfolding interval_lebesgue_integral_def einterval_eq zero_ereal_def + by (auto simp: ac_simps) + } note aux1 = this + { assume "0 > \" + have [simp]: "integrable lborel (\x. sin (x * \) * indicator {0<..] assms + by (simp add: interval_lebesgue_integrable_def ac_simps) + have "(LBINT t=ereal 0..T. sin (t * -\) / t) = (LBINT t=ereal 0..T. -\ *\<^sub>R sinc (t * -\))" + by (rule interval_integral_discrete_difference[of "{0}"]) auto + also have "\ = (LBINT t=ereal (0 * -\)..T * -\. sinc t)" + apply (rule interval_integral_substitution_finite [OF assms]) + apply (subst mult.commute, rule DERIV_subset) + by (auto intro!: derivative_intros continuous_at_imp_continuous_on isCont_sinc) + also have "\ = (LBINT t=ereal (0 * -\)..T * -\. sin t / t)" + by (rule interval_integral_discrete_difference[of "{0}"]) auto + finally have "(LBINT t=ereal 0..T. sin (t * -\) / t) = (LBINT t=ereal 0..T * -\. sin t / t)" + by simp + hence "LBINT x. indicator {0<..) / x = + - (LBINT x. indicator {0<..<- (T * \)} x * sin x / x)" + using assms `0 > \` unfolding interval_lebesgue_integral_def einterval_eq zero_ereal_def + by (auto simp add: field_simps mult_le_0_iff split: split_if_asm) + } note aux2 = this + show ?thesis + using assms unfolding Si_def interval_lebesgue_integral_def sgn_real_def einterval_eq zero_ereal_def + apply auto + apply (erule aux1) + apply (rule aux2) + apply auto + done +qed + +end diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Probability/Weak_Convergence.thy --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/HOL/Probability/Weak_Convergence.thy Wed Jan 06 12:18:53 2016 +0100 @@ -0,0 +1,420 @@ +(* + Theory: Weak_Convergence.thy + Authors: Jeremy Avigad, Luke Serafin +*) + +section \Weak Convergence of Functions and Distributions\ + +text \Properties of weak convergence of functions and measures, including the portmanteau theorem.\ + +theory Weak_Convergence + imports Distribution_Functions +begin + +section \Weak Convergence of Functions\ + +definition + weak_conv :: "(nat \ (real \ real)) \ (real \ real) \ bool" +where + "weak_conv F_seq F \ \x. isCont F x \ (\n. F_seq n x) \ F x" + +section \Weak Convergence of Distributions\ + +definition + weak_conv_m :: "(nat \ real measure) \ real measure \ bool" +where + "weak_conv_m M_seq M \ weak_conv (\n. cdf (M_seq n)) (cdf M)" + +section \Skorohod's theorem\ + +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 top: "(f \ b) at_top" +begin + +abbreviation I :: "real \ real" where + "I \ \ Inf {x. \ \ f x}" + +lemma pseudoinverse: assumes "a < \" "\ < b" shows "\ \ f x \ I \ \ x" +proof + let ?F = "{x. \ \ f x}" + obtain y where "f y < \" + by (metis eventually_happens' trivial_limit_at_bot_linorder order_tendstoD(2) bot \a < \\) + with mono have bdd: "bdd_below ?F" + by (auto intro!: bdd_belowI[of _ y] elim: mono_invE[OF _ less_le_trans]) + + have ne: "?F \ {}" + 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" + by (auto intro!: cInf_lower bdd) + + { assume *: "I \ \ x" + have "\ \ (INF s:{x. \ \ f x}. f s)" + by (rule cINF_greatest[OF ne]) auto + also have "\ = f (I \)" + using continuous_at_Inf_mono[OF mono cont ne bdd] .. + also have "\ \ f x" + using * by (rule monoD[OF \mono f\]) + finally show "\ \ f x" . } +qed + +lemma pseudoinverse': "\\\{a<..x. \ \ f x \ I \ \ x" + by (intro ballI allI impI pseudoinverse) auto + +lemma mono_I: "mono_on I {a <..< b}" + unfolding mono_on_def by (metis order.trans order.refl pseudoinverse') + +end + +locale cdf_distribution = real_distribution +begin + +abbreviation "C \ cdf M" + +sublocale right_continuous_mono C 0 1 + by standard + (auto intro: cdf_nondecreasing cdf_is_right_cont cdf_lim_at_top_prob cdf_lim_at_bot monoI) + +lemma measurable_C[measurable]: "C \ borel_measurable borel" + by (intro borel_measurable_mono mono) + +lemma measurable_CI[measurable]: "I \ borel_measurable (restrict_space borel {0<..<1})" + by (intro borel_measurable_mono_on_fnc mono_I) + +lemma emeasure_distr_I: "emeasure (distr (restrict_space lborel {0<..<1::real}) borel I) UNIV = 1" + by (simp add: emeasure_distr space_restrict_space emeasure_restrict_space ) + +lemma distr_I_eq_M: "distr (restrict_space lborel {0<..<1::real}) borel I = M" (is "?I = _") +proof (intro cdf_unique ext) + let ?\ = "restrict_space lborel {0<..<1}::real measure" + interpret \: prob_space ?\ + by (auto simp add: emeasure_restrict_space space_restrict_space intro!: prob_spaceI) + show "real_distribution ?I" + by auto + + fix x + have "cdf ?I x = measure lborel {\\{0<..<1}. \ \ C x}" + by (subst cdf_def) + (auto simp: pseudoinverse[symmetric] measure_distr space_restrict_space measure_restrict_space + intro!: arg_cong2[where f="measure"]) + also have "\ = measure lborel {0 <..< C x}" + using cdf_bounded_prob[of x] AE_lborel_singleton[of "C x"] + by (auto intro!: arg_cong[where f=real_of_ereal] emeasure_eq_AE simp: measure_def) + also have "\ = C x" + by (simp add: cdf_nonneg) + finally show "cdf (distr ?\ borel I) x = C x" . +qed standard + +end + +context + fixes \ :: "nat \ real measure" + and M :: "real measure" + assumes \: "\n. real_distribution (\ n)" + assumes M: "real_distribution M" + assumes \_to_M: "weak_conv_m \ M" +begin + +(* state using obtains? *) +theorem Skorohod: + "\ (\ :: 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) \ + Y \ measurable \ lborel \ + distr \ borel Y = M \ + (\x \ space \. (\n. Y_seq n x) \ Y x)" +proof - + interpret \: cdf_distribution "\ n" for n + unfolding cdf_distribution_def by (rule \) + interpret M: cdf_distribution M + unfolding cdf_distribution_def by (rule M) + + have conv: "measure M {x} = 0 \ (\n. \.C n x) \ M.C x" for x + using \_to_M M.isCont_cdf by (auto simp: weak_conv_m_def weak_conv_def) + + let ?\ = "restrict_space lborel {0<..<1} :: real measure" + have "prob_space ?\" + by (auto simp: space_restrict_space emeasure_restrict_space intro!: prob_spaceI) + interpret \: prob_space ?\ + by fact + + have Y_distr: "distr ?\ borel M.I = M" + by (rule M.distr_I_eq_M) + + 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 \" + unfolding le_Liminf_iff + proof safe + fix B :: ereal assume B: "B < M.I \" + then show "\\<^sub>F n in sequentially. B < \.I n \" + proof (cases B) + case (real r) + with B have r: "r < M.I \" + by simp + then obtain x where x: "r < x" "x < M.I \" "measure M {x} = 0" + using open_minus_countable[OF M.countable_support, of "{r<..}"] by auto + then have Fx_less: "M.C x < \" + using M.pseudoinverse' \ not_less by blast + + have "\\<^sub>F n in sequentially. \.C n x < \" + using order_tendstoD(2)[OF conv[OF x(3)] Fx_less] . + then have "\\<^sub>F n in sequentially. x < \.I n \" + by eventually_elim (insert \ \.pseudoinverse[symmetric], simp add: not_le[symmetric]) + then show ?thesis + by eventually_elim (insert x(1), simp add: real) + qed auto + qed + + have *: "limsup (\n. \.I n \) \ M.I \'" + if \': "0 < \'" "\' < 1" "\ < \'" for \' :: real + proof (rule dense_ge_bounded) + fix B' assume "ereal (M.I \') < B'" "B' < ereal (M.I \' + 1)" + then obtain B where "M.I \' < B" and [simp]: "B' = ereal B" + by (cases B') auto + then obtain y where y: "M.I \' < y" "y < B" "measure M {y} = 0" + using open_minus_countable[OF M.countable_support, of "{M.I \'<..' \ M.C (M.I \')" + using M.pseudoinverse' \' by (metis greaterThanLessThan_iff order_refl) + also have "... \ M.C y" + using M.mono y unfolding mono_def by auto + finally have Fy_gt: "\ < M.C y" + using \'(3) by simp + + have "\\<^sub>F n in sequentially. \ \ \.C n y" + using order_tendstoD(1)[OF conv[OF y(3)] Fy_gt] by eventually_elim (rule less_imp_le) + then have 2: "\\<^sub>F n in sequentially. \.I n \ \ ereal y" + by simp (subst \.pseudoinverse'[rule_format, OF \(1), symmetric]) + then show "limsup (\n. \.I n \) \ B'" + 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 \" + using \ + by (intro tendsto_le_const[OF trivial_limit_at_right_real **]) + (auto intro!: exI[of _ 1] * simp: eventually_at_right[of _ 1]) + qed + + let ?D = "{\\{0<..<1}. \ isCont M.I \}" + have D_countable: "countable ?D" + using mono_on_ctble_discont[OF M.mono_I] by (simp add: at_within_open[of _ "{0 <..< 1}"] cong: conj_cong) + hence D: "emeasure ?\ ?D = 0" + using emeasure_lborel_countable[OF D_countable] + by (subst emeasure_restrict_space) auto + + def Y' \ "\\. if \ \ ?D then 0 else M.I \" + have Y'_AE: "AE \ in ?\. Y' \ = M.I \" + by (rule AE_I [OF _ D]) (auto simp: space_restrict_space sets_restrict_space_iff Y'_def) + + def Y_seq' \ "\n \. if \ \ ?D then 0 else \.I n \" + have Y_seq'_AE: "\n. AE \ in ?\. Y_seq' n \ = \.I n \" + by (rule AE_I [OF _ D]) (auto simp: space_restrict_space sets_restrict_space_iff Y_seq'_def) + + have Y'_cnv: "\\\{0<..<1}. (\n. Y_seq' n \) \ Y' \" + by (auto simp: Y'_def Y_seq'_def Y_cts_cnv) + + have [simp]: "Y_seq' n \ borel_measurable ?\" for n + by (rule measurable_discrete_difference[of "\.I n" _ _ ?D]) + (insert \.measurable_CI[of n] D_countable, auto simp: sets_restrict_space Y_seq'_def) + moreover have "distr ?\ borel (Y_seq' n) = \ n" for n + using \.distr_I_eq_M [of n] Y_seq'_AE [of n] + by (subst distr_cong_AE[where f = "Y_seq' n" and g = "\.I n"], auto) + moreover have [simp]: "Y' \ borel_measurable ?\" + by (rule measurable_discrete_difference[of M.I _ _ ?D]) + (insert M.measurable_CI D_countable, auto simp: sets_restrict_space Y'_def) + moreover have "distr ?\ borel Y' = M" + using M.distr_I_eq_M Y'_AE + by (subst distr_cong_AE[where f = Y' and g = M.I], auto) + ultimately have "prob_space ?\ \ (\n. Y_seq' n \ borel_measurable ?\) \ + (\n. distr ?\ borel (Y_seq' n) = \ n) \ Y' \ measurable ?\ lborel \ distr ?\ borel Y' = M \ + (\x\space ?\. (\n. Y_seq' n x) \ Y' x)" + using Y'_cnv \prob_space ?\\ by (auto simp: space_restrict_space) + thus ?thesis by metis +qed + +text \ + The Portmanteau theorem, that is, the equivalence of various definitions of weak convergence. +\ + +theorem weak_conv_imp_bdd_ae_continuous_conv: + fixes + f :: "real \ 'a::{banach, second_countable_topology}" + assumes + discont_null: "M ({x. \ isCont f x}) = 0" and + f_bdd: "\x. norm (f x) \ B" and + [measurable]: "f \ borel_measurable borel" + shows + "(\ n. integral\<^sup>L (\ n) f) \ integral\<^sup>L M f" +proof - + have "0 \ B" + using norm_ge_zero f_bdd by (rule order_trans) + note Skorohod + then obtain Omega Y_seq Y where + ps_Omega [simp]: "prob_space Omega" and + Y_seq_measurable [measurable]: "\n. Y_seq n \ borel_measurable Omega" and + distr_Y_seq: "\n. distr Omega borel (Y_seq n) = \ n" and + Y_measurable [measurable]: "Y \ borel_measurable Omega" and + distr_Y: "distr Omega borel Y = M" and + YnY: "\x :: real. x \ space Omega \ (\n. Y_seq n x) \ Y x" by force + interpret prob_space Omega by fact + have *: "emeasure Omega (Y -` {x. \ isCont f x} \ space Omega) = 0" + by (subst emeasure_distr [symmetric, where N=borel]) (auto simp: distr_Y discont_null) + have *: "AE x in Omega. (\n. f (Y_seq n x)) \ f (Y x)" + by (rule AE_I [OF _ *]) (auto intro: isCont_tendsto_compose YnY) + show ?thesis + by (auto intro!: integral_dominated_convergence[where w="\x. B"] + simp: f_bdd * integral_distr distr_Y_seq [symmetric] distr_Y [symmetric]) +qed + +theorem weak_conv_imp_integral_bdd_continuous_conv: + fixes f :: "real \ 'a::{banach, second_countable_topology}" + assumes + "\x. isCont f x" and + "\x. norm (f x) \ B" + shows + "(\ n. integral\<^sup>L (\ n) f) \ integral\<^sup>L M f" + using assms + by (intro weak_conv_imp_bdd_ae_continuous_conv) + (auto intro!: borel_measurable_continuous_on1 continuous_at_imp_continuous_on) + +theorem weak_conv_imp_continuity_set_conv: + fixes f :: "real \ real" + assumes [measurable]: "A \ sets borel" and "M (frontier A) = 0" + shows "(\n. measure (\ n) A) \ measure M A" +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) + then show ?thesis + by simp +qed + +end + +definition + cts_step :: "real \ real \ real \ real" +where + "cts_step a b x \ if x \ a then 1 else if x \ b then 0 else (b - x) / (b - a)" + +lemma cts_step_uniformly_continuous: + assumes [arith]: "a < b" + shows "uniformly_continuous_on UNIV (cts_step a b)" + unfolding uniformly_continuous_on_def +proof clarsimp + fix e :: real assume [arith]: "0 < e" + let ?d = "min (e * (b - a)) (b - a)" + have "?d > 0" + by (auto simp add: field_simps) + moreover have "dist x' x < ?d \ dist (cts_step a b x') (cts_step a b x) < e" for x x' + by (auto simp: dist_real_def divide_simps cts_step_def) + ultimately show "\d > 0. \x x'. dist x' x < d \ dist (cts_step a b x') (cts_step a b x) < e" + by blast +qed + +lemma (in real_distribution) integrable_cts_step: "a < b \ integrable M (cts_step a b)" + by (rule integrable_const_bound [of _ 1]) (auto simp: cts_step_def[abs_def]) + +lemma (in real_distribution) cdf_cts_step: + assumes [arith]: "x < y" + shows "cdf M x \ integral\<^sup>L M (cts_step x y)" and "integral\<^sup>L M (cts_step x y) \ cdf M y" +proof - + have "cdf M x = integral\<^sup>L M (indicator {..x})" + by (simp add: cdf_def) + also have "\ \ expectation (cts_step x y)" + by (intro integral_mono integrable_cts_step) (auto simp: cts_step_def split: split_indicator) + finally show "cdf M x \ expectation (cts_step x y)" . +next + have "expectation (cts_step x y) \ integral\<^sup>L M (indicator {..y})" + by (intro integral_mono integrable_cts_step) (auto simp: cts_step_def split: split_indicator) + also have "\ = cdf M y" + by (simp add: cdf_def) + finally show "expectation (cts_step x y) \ cdf M y" . +qed + +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 [simp]: "real_distribution M" +begin + +theorem continuity_set_conv_imp_weak_conv: + fixes f :: "real \ real" + assumes *: "\A. A \ sets borel \ M (frontier A) = 0 \ (\ n. (measure (M_seq n) A)) \ measure M A" + shows "weak_conv_m M_seq M" +proof - + interpret real_distribution M by simp + show ?thesis + by (auto intro!: * simp: frontier_real_Iic isCont_cdf emeasure_eq_measure weak_conv_m_def weak_conv_def cdf_def2) +qed + +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 +proof (clarsimp) + 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 .. + { fix y :: real assume [arith]: "x < y" + have "limsup (\n. cdf (M_seq n) x) \ limsup (\n. integral\<^sup>L (M_seq n) (cts_step x y))" + by (auto intro!: Limsup_mono always_eventually real_distribution.cdf_cts_step) + also have "\ = integral\<^sup>L M (cts_step x y)" + by (intro lim_imp_Limsup) (auto intro: integral_conv) + also have "\ \ cdf M y" + by (simp add: cdf_cts_step) + finally have "limsup (\n. cdf (M_seq n) x) \ cdf M y" . + } note * = this + { fix y :: real assume [arith]: "x > y" + have "cdf M y \ ereal (integral\<^sup>L M (cts_step y x))" + by (simp add: cdf_cts_step) + also have "\ = liminf (\n. integral\<^sup>L (M_seq n) (cts_step y x))" + by (intro lim_imp_Liminf[symmetric]) (auto intro: integral_conv) + also have "\ \ liminf (\n. cdf (M_seq n) x)" + by (auto intro!: Liminf_mono always_eventually real_distribution.cdf_cts_step) + finally have "liminf (\n. cdf (M_seq n) x) \ cdf M y" . + } note ** = this + + have "limsup (\n. cdf (M_seq n) x) \ cdf M x" + proof (rule tendsto_le_const) + show "\\<^sub>F i in at_right x. limsup (\xa. ereal (cdf (M_seq xa) x)) \ ereal (cdf M i)" + by (subst eventually_at_right[of _ "x + 1"]) (auto simp: * intro: exI [of _ "x+1"]) + qed (insert cdf_is_right_cont, auto simp: continuous_within) + moreover have "cdf M x \ liminf (\n. cdf (M_seq n) x)" + proof (rule tendsto_ge_const) + show "\\<^sub>F i in at_left x. ereal (cdf M i) \ liminf (\xa. ereal (cdf (M_seq xa) x))" + 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) +qed + +theorem integral_bdd_continuous_conv_imp_weak_conv: + 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 + "weak_conv_m M_seq M" + apply (rule integral_cts_step_conv_imp_weak_conv [OF assms]) + apply (rule continuous_on_interior) + apply (rule uniformly_continuous_imp_continuous) + apply (rule cts_step_uniformly_continuous) + apply (auto simp: cts_step_def) + done + +end + +end diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Real.thy --- a/src/HOL/Real.thy Wed Jan 06 13:04:31 2016 +0100 +++ b/src/HOL/Real.thy Wed Jan 06 12:18:53 2016 +0100 @@ -1583,7 +1583,6 @@ "\numeral x ^ n\ = numeral x ^ n" by (metis ceiling_of_int of_int_numeral of_int_power) - subsection \Implementation of rational real numbers\ text \Formal constructor\ diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Set.thy --- a/src/HOL/Set.thy Wed Jan 06 13:04:31 2016 +0100 +++ b/src/HOL/Set.thy Wed Jan 06 12:18:53 2016 +0100 @@ -989,6 +989,9 @@ lemma Setcompr_eq_image: "{f x | x. x \ A} = f ` A" by blast +lemma setcompr_eq_image: "{f x |x. P x} = f ` {x. P x}" + by auto + lemma ball_imageD: assumes "\x\f ` A. P x" shows "\x\A. P (f x)" diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Topological_Spaces.thy --- a/src/HOL/Topological_Spaces.thy Wed Jan 06 13:04:31 2016 +0100 +++ b/src/HOL/Topological_Spaces.thy Wed Jan 06 12:18:53 2016 +0100 @@ -453,6 +453,9 @@ "x < y \ eventually P (at_right x) \ (\b>x. \y>x. y < b \ P y)" unfolding at_right_eq by (subst eventually_INF_base) (auto simp: eventually_principal Ball_def) +lemma eventually_at_right_less: "\\<^sub>F y in at_right (x::'a::{linorder_topology, no_top}). x < y" + using gt_ex[of x] eventually_at_right[of x] by auto + lemma trivial_limit_at_right_top: "at_right (top::_::{order_top, linorder_topology}) = bot" unfolding filter_eq_iff eventually_at_topological by auto @@ -1610,6 +1613,9 @@ lemma continuous_on_eq_continuous_at: "open s \ continuous_on s f \ (\x\s. isCont f x)" by (simp add: continuous_on_def continuous_at at_within_open[of _ s]) +lemma continuous_within_open: "a \ A \ open A \ continuous (at a within A) f \ isCont f a" + by (simp add: at_within_open_NO_MATCH) + lemma continuous_at_imp_continuous_on: "\x\s. isCont f x \ continuous_on s f" by (auto intro: continuous_at_imp_continuous_at_within simp: continuous_on_eq_continuous_within) diff -r 614ef6d7a6b6 -r 7582b39f51ed src/HOL/Transcendental.thy --- a/src/HOL/Transcendental.thy Wed Jan 06 13:04:31 2016 +0100 +++ b/src/HOL/Transcendental.thy Wed Jan 06 12:18:53 2016 +0100 @@ -10,6 +10,25 @@ imports Binomial Series Deriv NthRoot begin +text \A fact theorem on reals.\ + +lemma square_fact_le_2_fact: + shows "fact n * fact n \ (fact (2 * n) :: real)" +proof (induct n) + case 0 then show ?case by simp +next + case (Suc n) + have "(fact (Suc n)) * (fact (Suc n)) = of_nat (Suc n) * of_nat (Suc n) * (fact n * fact n :: real)" + by (simp add: field_simps) + also have "\ \ of_nat (Suc n) * of_nat (Suc n) * fact (2 * n)" + by (rule mult_left_mono [OF Suc]) simp + also have "\ \ of_nat (Suc (Suc (2 * n))) * of_nat (Suc (2 * n)) * fact (2 * n)" + by (rule mult_right_mono)+ (auto simp: field_simps) + also have "\ = fact (2 * Suc n)" by (simp add: field_simps) + finally show ?case . +qed + + lemma of_int_leD: fixes x :: "'a :: linordered_idom" shows "\of_int n\ \ x \ n=0 \ x\1"