diff --git a/thys/Distributed_Distinct_Elements/Distributed_Distinct_Elements_Preliminary.thy b/thys/Distributed_Distinct_Elements/Distributed_Distinct_Elements_Preliminary.thy --- a/thys/Distributed_Distinct_Elements/Distributed_Distinct_Elements_Preliminary.thy +++ b/thys/Distributed_Distinct_Elements/Distributed_Distinct_Elements_Preliminary.thy @@ -1,336 +1,326 @@ section \Preliminary Results\ text \This section contains various short preliminary results used in the sections below.\ theory Distributed_Distinct_Elements_Preliminary imports Frequency_Moments.Frequency_Moments_Preliminary_Results Universal_Hash_Families.Universal_Hash_Families_More_Product_PMF Median_Method.Median Expander_Graphs.Extra_Congruence_Method Expander_Graphs.Constructive_Chernoff_Bound Frequency_Moments.Landau_Ext Stirling_Formula.Stirling_Formula begin unbundle intro_cong_syntax text \The following aliases are here to prevent possible merge-conflicts. The lemmas have been moved to @{theory "Universal_Hash_Families.Universal_Hash_Families_More_Product_PMF"}.\ lemmas measure_pmf_cong = measure_pmf_cong lemmas pmf_mono = pmf_mono +lemmas pmf_add = pmf_add lemma pmf_rev_mono: assumes "\x. x \ set_pmf p \ x \ Q \ x \ P" shows "measure p P \ measure p Q" using assms by (intro pmf_mono) blast lemma pmf_exp_mono: fixes f g :: "'a \ real" assumes "integrable (measure_pmf p) f" "integrable (measure_pmf p) g" assumes "\x. x \ set_pmf p \ f x \ g x" shows "integral\<^sup>L (measure_pmf p) f \ integral\<^sup>L (measure_pmf p) g" using assms by (intro integral_mono_AE AE_pmfI) auto lemma pmf_markov: assumes "integrable (measure_pmf p) f" "c > 0" assumes "\x. x \ set_pmf p \ f x \ 0" shows "measure p {\. f \ \ c} \ (\\. f \ \p)/ c" (is "?L \ ?R") proof - have a:"AE \ in (measure_pmf p). 0 \ f \" by (intro AE_pmfI assms(3)) have b:"{} \ measure_pmf.events p" unfolding assms(1) by simp have "?L = \

(\ in (measure_pmf p). f \ \ c)" using assms(1) by simp also have "... \ ?R" by (intro integral_Markov_inequality_measure[OF _ b] assms a) finally show ?thesis by simp qed -lemma pmf_add: - assumes "\x. x \ P \ x \ set_pmf p \ x \ Q \ x \ R" - shows "measure p P \ measure p Q + measure p R" -proof - - have "measure p P \ measure p (Q \ R)" - using assms by (intro pmf_mono) blast - also have "... \ measure p Q + measure p R" - by (rule measure_subadditive, auto) - finally show ?thesis by simp -qed - lemma pair_pmf_prob_left: "measure_pmf.prob (pair_pmf A B) {\. P (fst \)} = measure_pmf.prob A {\. P \}" (is "?L = ?R") proof - have "?L = measure_pmf.prob (map_pmf fst (pair_pmf A B)) {\. P \}" by (subst measure_map_pmf) simp also have "... = ?R" by (subst map_fst_pair_pmf) simp finally show ?thesis by simp qed lemma pmf_exp_of_fin_function: assumes "finite A" "g ` set_pmf p \ A" shows "(\\. f (g \) \p) = (\y \ A. f y * measure p {\. g \ = y})" (is "?L = ?R") proof - have "?L = integral\<^sup>L (map_pmf g p) f" using integral_map_pmf assms by simp also have "... = (\a\A. f a * pmf (map_pmf g p) a)" using assms by (intro integral_measure_pmf_real) auto also have " ... = (\y \ A. f y * measure p (g -` {y}))" unfolding assms(1) by (intro_cong "[\\<^sub>2 (*)]" more:sum.cong pmf_map) also have "... = ?R" by (intro sum.cong) (auto simp add: vimage_def) finally show ?thesis by simp qed text \Cardinality rules for distinct/ordered pairs of a set without the finiteness constraint - to use in simplification:\ lemma card_distinct_pairs: "card {x \ B \ B. fst x \ snd x} = card B^2 - card B" (is "card ?L = ?R") proof (cases "finite B") case True include intro_cong_syntax have "card ?L = card (B \ B - (\x. (x,x)) ` B)" by (intro arg_cong[where f="card"]) auto also have "... = card (B \ B) - card ((\x. (x,x)) ` B)" by (intro card_Diff_subset finite_imageI True image_subsetI) auto also have "... = ?R" using True by (intro_cong "[\\<^sub>2 (-)]" more: card_image) (auto simp add:power2_eq_square inj_on_def) finally show ?thesis by simp next case False then obtain p where p_in: "p \ B" by fastforce have "False" if "finite ?L" proof - have "(\x. (p,x)) ` (B - {p}) \ ?L" using p_in by (intro image_subsetI) auto hence "finite ((\x. (p,x)) ` (B - {p}))" using finite_subset that by auto hence "finite (B - {p})" by (rule finite_imageD) (simp add:inj_on_def) hence "finite B" by simp thus "False" using False by simp qed hence "infinite ?L" by auto hence "card ?L = 0" by simp also have "... = ?R" using False by simp finally show ?thesis by simp qed lemma card_ordered_pairs': fixes M :: "('a ::linorder) set" shows "card {(x,y) \ M \ M. x < y} = card M * (card M - 1) / 2" proof (cases "finite M") case True show ?thesis using card_ordered_pairs[OF True] by linarith next case False then obtain p where p_in: "p \ M" by fastforce let ?f= "(\x. if x < p then (x,p) else (p,x))" have "False" if "finite {(x,y) \ M \ M. x < y}" (is "finite ?X") proof - have "?f ` (M-{p}) \ ?X" using p_in by (intro image_subsetI) auto hence "finite (?f ` (M-{p}))" using that finite_subset by auto moreover have "inj_on ?f (M-{p})" by (intro inj_onI) (metis Pair_inject) ultimately have "finite (M - {p})" using finite_imageD by blast hence "finite M" using finite_insert[where a="p" and A="M-{p}"] by simp thus "False" using False by simp qed hence "infinite ?X" by auto then show ?thesis using False by simp qed text \The following are versions of the mean value theorem, where the interval endpoints may be reversed.\ lemma MVT_symmetric: assumes "\x. \min a b \ x; x \ max a b\ \ DERIV f x :> f' x" shows "\z::real. min a b \ z \ z \ max a b \ (f b - f a = (b - a) * f' z)" proof - consider (a) "a < b" | (b) "a = b" | (c) "a > b" by argo then show ?thesis proof (cases) case a then obtain z :: real where r: "a < z" "z < b" "f b - f a = (b - a) * f' z" using assms MVT2[where a="a" and b="b" and f="f" and f'="f'"] by auto have "a \ z" "z \ b" using r(1,2) by auto thus ?thesis using a r(3) by auto next case b then show ?thesis by auto next case c then obtain z :: real where r: "b < z" "z < a" "f a - f b = (a - b) * f' z" using assms MVT2[where a="b" and b="a" and f="f" and f'="f'"] by auto have "f b - f a = (b-a) * f' z" using r by argo moreover have "b \ z" "z \ a" using r(1,2) by auto ultimately show ?thesis using c by auto qed qed lemma MVT_interval: fixes I :: "real set" assumes "interval I" "a \ I" "b \ I" assumes "\x. x \ I \ DERIV f x :> f' x" shows "\z. z \ I \ (f b - f a = (b - a) * f' z)" proof - have a:"min a b \ I" using assms(2,3) by (cases "a < b") auto have b:"max a b \ I" using assms(2,3) by (cases "a < b") auto have c:"x \ {min a b..max a b} \ x \ I" for x using interval_def assms(1) a b by auto have "\min a b \ x; x \ max a b\ \ DERIV f x :> f' x" for x using c assms(4) by auto then obtain z where z:"z \ min a b" "z \ max a b" "f b - f a = (b-a) * f' z" using MVT_symmetric by blast have "z \ I" using c z(1,2) by auto thus ?thesis using z(3) by auto qed text \Ln is monotone on the positive numbers and thus commutes with min and max:\ lemma ln_min_swap: "x > (0::real) \ (y > 0) \ ln (min x y) = min (ln x) (ln y)" using ln_less_cancel_iff by fastforce lemma ln_max_swap: "x > (0::real) \ (y > 0) \ ln (max x y) = max (ln x) (ln y)" using ln_le_cancel_iff by fastforce text \Loose lower bounds for the factorial fuction:.\ lemma fact_lower_bound: "sqrt(2*pi*n)*(n/exp(1))^n \ fact n" (is "?L \ ?R") proof (cases "n > 0") case True have "ln ?L = ln (2*pi*n)/2 + n * ln n - n" using True by (simp add: ln_mult ln_sqrt ln_realpow ln_div algebra_simps) also have "... \ ln ?R" by (intro Stirling_Formula.ln_fact_bounds True) finally show ?thesis using iffD1[OF ln_le_cancel_iff] True by simp next case False then show ?thesis by simp qed lemma fact_lower_bound_1: assumes "n > 0" shows "(n/exp 1)^n \ fact n" (is "?L \ ?R") proof - have "2 * pi \ 1" using pi_ge_two by auto moreover have "n \ 1" using assms by simp ultimately have "2 * pi * n \ 1*1" by (intro mult_mono) auto hence a:"2 * pi * n \ 1" by simp have "?L = 1 * ?L" by simp also have "... \ sqrt(2 * pi * n) * ?L" using a by (intro mult_right_mono) auto also have "... \ ?R" using fact_lower_bound by simp finally show ?thesis by simp qed text \Rules to handle O-notation with multiple variables, where some filters may be towards zero:\ lemma real_inv_at_right_0_inf: "\\<^sub>F x in at_right (0::real). c \ 1 / x" proof - have "c \ 1 / x" if b:" x \ {0<..<1 / (max c 1)}" for x proof - have "c * x \ (max c 1) * x" using b by (intro mult_right_mono, linarith, auto) also have "... \ (max c 1) * (1 / (max c 1))" using b by (intro mult_left_mono) auto also have "... \ 1" by (simp add:of_rat_divide) finally have "c * x \ 1" by simp moreover have "0 < x" using b by simp ultimately show ?thesis by (subst pos_le_divide_eq, auto) qed thus ?thesis by (intro eventually_at_rightI[where b="1/(max c 1)"], simp_all) qed lemma bigo_prod_1: assumes "(\x. f x) \ O[F](\x. g x)" "G \ bot" shows "(\x. f (fst x)) \ O[F \\<^sub>F G](\x. g (fst x))" proof - obtain c where a: "\\<^sub>F x in F. norm (f x) \ c * norm (g x)" and c_gt_0: "c > 0" using assms unfolding bigo_def by auto have "\c>0. \\<^sub>F x in F \\<^sub>F G. norm (f (fst x)) \ c * norm (g (fst x))" by (intro exI[where x="c"] conjI c_gt_0 eventually_prod1' a assms(2)) thus ?thesis unfolding bigo_def by simp qed lemma bigo_prod_2: assumes "(\x. f x) \ O[G](\x. g x)" "F \ bot" shows "(\x. f (snd x)) \ O[F \\<^sub>F G](\x. g (snd x))" proof - obtain c where a: "\\<^sub>F x in G. norm (f x) \ c * norm (g x)" and c_gt_0: "c > 0" using assms unfolding bigo_def by auto have "\c>0. \\<^sub>F x in F \\<^sub>F G. norm (f (snd x)) \ c * norm (g (snd x))" by (intro exI[where x="c"] conjI c_gt_0 eventually_prod2' a assms(2)) thus ?thesis unfolding bigo_def by simp qed lemma eventually_inv: fixes P :: "real \ bool" assumes "eventually (\x. P (1/x)) at_top " shows "eventually (\x. P x) (at_right 0)" proof - obtain N where c:"n \ N \ P (1/n)" for n using assms unfolding eventually_at_top_linorder by auto define q where "q = max 1 N" have d: "0 < 1 / q" "q > 0" unfolding q_def by auto have "P x" if "x \ {0<..<1 / q}" for x proof - define n where "n = 1/x" have x_eq: "x = 1 / n" unfolding n_def using that by simp have "N \ q" unfolding q_def by simp also have "... \ n" unfolding n_def using that d by (simp add:divide_simps ac_simps) finally have "N \ n" by simp thus ?thesis unfolding x_eq by (intro c) qed thus ?thesis by (intro eventually_at_rightI[where b="1/q"] d) qed lemma bigo_inv: fixes f g :: "real \ real" assumes "(\x. f (1/x)) \ O(\x. g (1/x))" shows "f \ O[at_right 0](g)" using assms eventually_inv unfolding bigo_def by auto unbundle no_intro_cong_syntax end \ No newline at end of file diff --git a/thys/Expander_Graphs/Constructive_Chernoff_Bound.thy b/thys/Expander_Graphs/Constructive_Chernoff_Bound.thy --- a/thys/Expander_Graphs/Constructive_Chernoff_Bound.thy +++ b/thys/Expander_Graphs/Constructive_Chernoff_Bound.thy @@ -1,539 +1,548 @@ subsection \Constructive Chernoff Bound\label{sec:constructive_chernoff_bound}\ text \This section formalizes Theorem~5 by Impagliazzo and Kabanets~\cite{impagliazzo2010}. It is a general result with which Chernoff-type tail bounds for various kinds of weakly dependent random variables can be obtained. The results here are general and will be applied in Section~\ref{sec:random_walks} to random walks in expander graphs.\ theory Constructive_Chernoff_Bound imports "HOL-Probability.Probability_Measure" Universal_Hash_Families.Universal_Hash_Families_More_Product_PMF Weighted_Arithmetic_Geometric_Mean.Weighted_Arithmetic_Geometric_Mean begin lemma powr_mono_rev: fixes x :: real assumes "a \ b" and "x > 0" "x \ 1" shows "x powr b \ x powr a" proof - have "x powr b = (1/x) powr (-b)" using assms by (simp add: powr_divide powr_minus_divide) also have "... \ (1/x) powr (-a)" using assms by (intro powr_mono) auto also have "... = x powr a" using assms by (simp add: powr_divide powr_minus_divide) finally show ?thesis by simp qed lemma exp_powr: "(exp x) powr y = exp (x*y)" for x :: real unfolding powr_def by simp lemma integrable_pmf_iff_bounded: fixes f :: "'a \ real" assumes "\x. x \ set_pmf p \ abs (f x) \ C" shows "integrable (measure_pmf p) f" proof - obtain x where "x \ set_pmf p" using set_pmf_not_empty by fast hence "C \ 0" using assms(1) by fastforce hence " (\\<^sup>+ x. ennreal (abs (f x)) \measure_pmf p) \ (\\<^sup>+ x. C \measure_pmf p)" using assms ennreal_le_iff by (intro nn_integral_mono_AE AE_pmfI) auto also have "... = C" by simp also have "... < Orderings.top" by simp finally have "(\\<^sup>+ x. ennreal (abs (f x)) \measure_pmf p) < Orderings.top" by simp thus ?thesis by (intro iffD2[OF integrable_iff_bounded]) auto qed lemma split_pair_pmf: "measure_pmf.prob (pair_pmf A B) S = integral\<^sup>L A (\a. measure_pmf.prob B {b. (a,b) \ S})" (is "?L = ?R") proof - have a:"integrable (measure_pmf A) (\x. measure_pmf.prob B {b. (x, b) \ S})" by (intro integrable_pmf_iff_bounded[where C="1"]) simp have "?L = (\\<^sup>+x. indicator S x \(measure_pmf (pair_pmf A B)))" by (simp add: measure_pmf.emeasure_eq_measure) also have "... = (\\<^sup>+x. (\\<^sup>+y. indicator S (x,y) \B) \A)" by (simp add: nn_integral_pair_pmf') also have "... = (\\<^sup>+x. (\\<^sup>+y. indicator {b. (x,b) \ S} y \B) \A)" by (simp add:indicator_def) also have "... = (\\<^sup>+x. (measure_pmf.prob B {b. (x,b) \ S}) \A)" by (simp add: measure_pmf.emeasure_eq_measure) also have "... = ?R" using a by (subst nn_integral_eq_integral) auto finally show ?thesis by simp qed lemma split_pair_pmf_2: "measure(pair_pmf A B) S = integral\<^sup>L B (\a. measure_pmf.prob A {b. (b,a) \ S})" (is "?L = ?R") proof - have "?L = measure (pair_pmf B A) {\. (snd \, fst \) \ S}" by (subst pair_commute_pmf) (simp add:vimage_def case_prod_beta) also have "... = ?R" unfolding split_pair_pmf by simp finally show ?thesis by simp qed definition KL_div :: "real \ real \ real" where "KL_div p q = p * ln (p/q) + (1-p) * ln ((1-p)/(1-q))" theorem impagliazzo_kabanets_pmf: fixes Y :: "nat \ 'a \ bool" fixes p :: "'a pmf" assumes "n > 0" assumes "\i. i \ {.. \ i \ {0..1}" assumes "\S. S \ {.. measure p {\. (\i \ S. Y i \)} \ (\i \ S. \ i)" defines "\_avg \ (\i\ {.. i)/n" assumes "\ \ {\_avg..1}" assumes "\_avg > 0" shows "measure p {\. real (card {i \ {..}) \ \ * n} \ exp (-real n * KL_div \ \_avg)" (is "?L \ ?R") proof - let ?n = "real n" define q :: real where "q = (if \ = 1 then 1 else (\-\_avg)/(\*(1-\_avg)))" define g where "g \ = card {i. i < n \ \Y i \}" for \ let ?E = "(\\. real (card {i. i < n \ Y i \}) \ \ * n)" let ?\ = "prod_pmf {.._. bernoulli_pmf q)" have q_range:"q \{0..1}" proof (cases "\ < 1") case True then show ?thesis using assms(5,6) unfolding q_def by (auto intro!:divide_nonneg_pos simp add:algebra_simps) next case False hence "\ = 1" using assms(5) by simp then show ?thesis unfolding q_def by simp qed have abs_pos_le_1I: "abs x \ 1" if "x \ 0" "x \ 1" for x :: real using that by auto have \_n_nonneg: "\*?n \ 0" using assms(1,5,6) by simp define r where "r = n - nat \\*n\" have 2:"(1-q) ^ r \ (1-q)^ g \" if "?E \" for \ proof - have "g \ = card ({i. i < n} - {i. i < n \ Y i \})" unfolding g_def by (intro arg_cong[where f="\x. card x"]) auto also have "... = card {i. i < n} - card {i. i < n \ Y i \}" by (subst card_Diff_subset, auto) also have "... \ card {i. i < n} - nat \\*n\" using that \_n_nonneg by (intro diff_le_mono2) simp also have "... = r" unfolding r_def by simp finally have "g \ \ r" by simp thus "(1-q) ^ r \ (1-q) ^ (g \)" using q_range by (intro power_decreasing) auto qed have \_gt_0: "\ > 0" using assms(5,6) by simp have q_lt_1: "q < 1" if "\ < 1" proof - have "\_avg < 1" using assms(5) that by simp hence "(\ - \_avg) / (\ * (1 - \_avg)) < 1" using \_gt_0 assms(6) that by (subst pos_divide_less_eq) (auto simp add:algebra_simps) thus "q < 1" unfolding q_def using that by simp qed have 5: "(\_avg * q + (1-q)) / (1-q) powr (1-\) = exp (- KL_div \ \_avg)" (is "?L1 = ?R1") if "\ < 1" proof - have \_avg_range: "\_avg \ {0<..<1}" using that assms(5,6) by simp have "?L1 = (1 - (1-\_avg) * q) / (1-q) powr (1-\)" by (simp add:algebra_simps) also have "... = (1 - (\-\_avg) / \ ) / (1-q) powr (1-\)" unfolding q_def using that \_gt_0 \_avg_range by simp also have "... = (\_avg / \) / (1-q) powr (1-\)" using \_gt_0 by (simp add:divide_simps) also have "... = (\_avg / \) * (1/(1-q)) powr (1-\)" using q_lt_1[OF that] by (subst powr_divide, simp_all) also have "... = (\_avg / \) * (1/((\*(1-\_avg)-(\-\_avg))/(\*(1-\_avg)))) powr (1-\)" using \_gt_0 \_avg_range unfolding q_def by (simp add:divide_simps) also have "... = (\_avg / \) * ((\ / \_avg) *((1-\_avg)/(1-\))) powr (1-\)" by (simp add:algebra_simps) also have "... = (\_avg / \) * (\ / \_avg) powr (1-\) *((1-\_avg)/(1-\)) powr (1-\)" using \_gt_0 \_avg_range that by (subst powr_mult, auto) also have "... = (\_avg / \) powr 1 * (\_avg / \) powr -(1-\) *((1-\_avg)/(1-\)) powr (1-\)" using \_gt_0 \_avg_range that unfolding powr_minus_divide by (simp add:powr_divide) also have "... = (\_avg / \) powr \ *((1-\_avg)/(1-\)) powr (1-\)" by (subst powr_add[symmetric]) simp also have "... = exp ( ln ((\_avg / \) powr \ *((1-\_avg)/(1-\)) powr (1-\)))" using \_gt_0 \_avg_range that by (intro exp_ln[symmetric] mult_pos_pos) auto also have "... = exp ((ln ((\_avg / \) powr \) + ln (((1 - \_avg) / (1 - \)) powr (1-\))))" using \_gt_0 \_avg_range that by (subst ln_mult) auto also have "... = exp ((\ * ln (\_avg / \) + (1 - \) * ln ((1 - \_avg) / (1 - \))))" using \_gt_0 \_avg_range that by (simp add:ln_powr algebra_simps) also have "... = exp (- (\ * ln (\ / \_avg) + (1 - \) * ln ((1 - \) / (1 - \_avg))))" using \_gt_0 \_avg_range that by (simp add: ln_div algebra_simps) also have "... = ?R1" unfolding KL_div_def by simp finally show ?thesis by simp qed have 3: "(\_avg * q + (1-q)) ^ n / (1-q) ^ r \ exp (- ?n* KL_div \ \_avg)" (is "?L1 \ ?R1") proof (cases "\ < 1") case True have "\ * real n \ 1 * real n" using True by (intro mult_right_mono) auto hence "r = real n - real (nat \\ * real n\)" unfolding r_def by (subst of_nat_diff) auto also have "... = real n - \\ * real n\" using \_n_nonneg by (subst of_nat_nat, auto) also have "... \ ?n - \ * ?n" by (intro diff_mono) auto also have "... = (1-\) *?n" by (simp add:algebra_simps) finally have r_bound: "r \ (1-\)*n" by simp have "?L1 = (\_avg * q + (1-q)) ^ n / (1-q) powr r" using q_lt_1[OF True] assms(1) by (simp add: powr_realpow) also have "... = (\_avg * q + (1-q)) powr n / (1-q) powr r" using q_lt_1[OF True] assms(6) q_range by (subst powr_realpow[symmetric], auto intro!:add_nonneg_pos) also have "... \ (\_avg * q + (1-q)) powr n / (1-q) powr ((1-\)*n)" using q_range q_lt_1[OF True] by (intro divide_left_mono powr_mono_rev r_bound) auto also have "... = (\_avg * q + (1-q)) powr n / ((1-q) powr (1-\)) powr n" unfolding powr_powr by simp also have "... = ((\_avg * q + (1-q)) / (1-q) powr (1-\)) powr n" using assms(6) q_range by (subst powr_divide) auto also have "... = exp (- KL_div \ \_avg) powr real n" unfolding 5[OF True] by simp also have "... = ?R1" unfolding exp_powr by simp finally show ?thesis by simp next case False hence \_eq_1: "\=1" using assms(5) by simp have "?L1 = \_avg ^ n" using \_eq_1 r_def q_def by simp also have "... = exp( - KL_div 1 \_avg) ^ n" unfolding KL_div_def using assms(6) by (simp add:ln_div) also have "... = ?R1" using \_eq_1 by (simp add: powr_realpow[symmetric] exp_powr) finally show ?thesis by simp qed have 4: "(1 - q) ^ r > 0" proof (cases "\ < 1") case True then show ?thesis using q_lt_1[OF True] by simp next case False hence "\=1" using assms(5) by simp hence "r=0" unfolding r_def by simp then show ?thesis by simp qed have "(1-q) ^ r * ?L = (\\. indicator {\. ?E \} \ * (1-q) ^ r \p)" by simp also have "... \ (\\. indicator {\. ?E \} \ * (1-q) ^ g \ \p)" using q_range 2 by (intro integral_mono_AE integrable_pmf_iff_bounded[where C="1"] abs_pos_le_1I mult_le_one power_le_one AE_pmfI) (simp_all split:split_indicator) also have "... = (\\. indicator {\. ?E \} \ * (\i \ {i. i < n \ \Y i \}. (1-q)) \p)" unfolding g_def using q_range by (intro integral_cong_AE AE_pmfI, simp_all add:powr_realpow) also have "... = (\\. indicator {\. ?E \} \ * measure ?\ ({j. j < n \ \Y j \} \ {False}) \p)" using q_range by (subst prob_prod_pmf') (auto simp add:measure_pmf_single) also have "... = (\\. measure ?\ {\. ?E \ \ (\i\{j. j < n \ \Y j \}. \\ i)} \p)" by (intro integral_cong_AE AE_pmfI, simp_all add:Pi_def split:split_indicator) also have "... = (\\. measure ?\ {\. ?E \ \ (\i\{.. i \ Y i \)} \p)" by (intro integral_cong_AE AE_pmfI measure_eq_AE) auto also have "... = measure (pair_pmf p ?\) {\.?E (fst \)\(\i \ {.. i \ Y i (fst \))}" unfolding split_pair_pmf by simp also have "... \ measure (pair_pmf p ?\) {\. (\i \ {j. j < n \ snd \ j}. Y i (fst \))}" by (intro pmf_mono, auto) also have "... = (\\. measure p {\. \i\{j. j< n \ \ j}. Y i \} \ ?\)" unfolding split_pair_pmf_2 by simp also have "... \ (\a. (\i \ {j. j < n \ a j}. \ i) \ ?\)" using assms(2) by (intro integral_mono_AE AE_pmfI assms(3) subsetI prod_le_1 prod_nonneg integrable_pmf_iff_bounded[where C="1"] abs_pos_le_1I) auto also have "... = (\a. (\i \ {.. i^ of_bool(a i)) \ ?\)" unfolding of_bool_def by (intro integral_cong_AE AE_pmfI) (auto simp add:if_distrib prod.If_cases Int_def) also have "... = (\ia. (\ i ^ of_bool a) \(bernoulli_pmf q)))" using assms(2) by (intro expectation_prod_Pi_pmf integrable_pmf_iff_bounded[where C="1"]) auto also have "... = (\i i * q + (1-q))" using q_range by simp also have "... = (root (card {..i i * q + (1-q))) ^ (card {.. ((\i i * q + (1-q))/card{..i i * q)/n + (1-q))^n" using assms(1) by (simp add:sum.distrib divide_simps mult.commute) also have "... = (\_avg * q + (1-q))^n" unfolding \_avg_def by (simp add: sum_distrib_right[symmetric]) finally have "(1-q) ^ r * ?L \ (\_avg * q + (1-q)) ^ n" by simp hence "?L \ (\_avg * q + (1-q)) ^ n / (1-q) ^ r" using 4 by (subst pos_le_divide_eq) (auto simp add:algebra_simps) also have "... \ ?R" by (intro 3) finally show ?thesis by simp qed text \The distribution of a random variable with a countable range is a discrete probability space, i.e., induces a PMF. Using this it is possible to generalize the previous result to arbitrary probability spaces.\ lemma (in prob_space) establish_pmf: fixes f :: "'a \ 'b" assumes rv: "random_variable discrete f" assumes "countable (f ` space M)" shows "distr M discrete f \ {M. prob_space M \ sets M = UNIV \ (AE x in M. measure M {x} \ 0)}" proof - define N where "N = {x \ space M.\ prob (f -` {f x} \ space M) \ 0}" define I where "I = {z \ (f ` space M). prob (f -` {z} \ space M) = 0}" have countable_I: " countable I" unfolding I_def by (intro countable_subset[OF _ assms(2)]) auto have disj: "disjoint_family_on (\y. f -` {y} \ space M) I" unfolding disjoint_family_on_def by auto have N_alt_def: "N = (\y \ I. f -` {y} \ space M)" unfolding N_def I_def by (auto simp add:set_eq_iff) have "emeasure M N = \\<^sup>+ y. emeasure M (f -` {y} \ space M) \count_space I" using rv countable_I unfolding N_alt_def by (subst emeasure_UN_countable) (auto simp add:disjoint_family_on_def) also have "... = \\<^sup>+ y. 0 \count_space I" unfolding I_def using emeasure_eq_measure ennreal_0 by (intro nn_integral_cong) auto also have "... = 0" by simp finally have 0:"emeasure M N = 0" by simp have 1:"N \ events" unfolding N_alt_def using rv by (intro sets.countable_UN'' countable_I) simp have " AE x in M. prob (f -` {f x} \ space M) \ 0" using 0 1 by (subst AE_iff_measurable[OF _ N_def[symmetric]]) hence " AE x in M. measure (distr M discrete f) {f x} \ 0" by (subst measure_distr[OF rv], auto) hence "AE x in distr M discrete f. measure (distr M discrete f) {x} \ 0" by (subst AE_distr_iff[OF rv], auto) thus ?thesis using prob_space_distr rv by auto qed lemma singletons_image_eq: "(\x. {x}) ` T \ Pow T" by auto theorem (in prob_space) impagliazzo_kabanets: fixes Y :: "nat \ 'a \ bool" assumes "n > 0" assumes "\i. i \ {.. random_variable discrete (Y i)" assumes "\i. i \ {.. \ i \ {0..1}" assumes "\S. S \ {.. \

(\ in M. (\i \ S. Y i \)) \ (\i \ S. \ i)" defines "\_avg \ (\i\ {.. i)/n" assumes "\ \ {\_avg..1}" "\_avg > 0" shows "\

(\ in M. real (card {i \ {..}) \ \ * n) \ exp (-real n * KL_div \ \_avg)" (is "?L \ ?R") proof - define f where "f = (\\ i. if i < n then Y i \ else False)" define g where "g = (\\ i. if i < n then \ i else False)" define T where "T = {\. (\i. \ i \ i < n)}" have g_idem: "g \ f = f" unfolding f_def g_def by (simp add:comp_def) have f_range: " f \ space M \ T" unfolding T_def f_def by simp have "T = PiE_dflt {.._. UNIV)" unfolding T_def PiE_dflt_def by auto hence "finite T" using finite_PiE_dflt by auto hence countable_T: "countable T" by (intro countable_finite) moreover have "f ` space M \ T" using f_range by auto ultimately have countable_f: "countable (f ` space M)" using countable_subset by auto have "f -` y \ space M \ events" if t:"y \ (\x. {x}) ` T" for y proof - obtain t where "y = {t}" and t_range: "t \ T" using t by auto hence "f -` y \ space M = {\ \ space M. f \ = t}" by (auto simp add:vimage_def) also have "... = {\ \ space M. (\i < n. Y i \ = t i)}" using t_range unfolding f_def T_def by auto also have "... = (\i \ {.. \ space M. Y i \ = t i})" using assms(1) by auto also have "... \ events" using assms(1,2) by (intro sets.countable_INT) auto finally show ?thesis by simp qed hence "random_variable (count_space T) f" using sigma_sets_singletons[OF countable_T] singletons_image_eq f_range by (intro measurable_sigma_sets[where \="T" and A=" (\x. {x}) ` T"]) simp_all moreover have "g \ measurable discrete (count_space T)" unfolding g_def T_def by simp ultimately have "random_variable discrete (g \ f)" by simp hence rv:"random_variable discrete f" unfolding g_idem by simp define M' :: "(nat \ bool) measure" where "M' = distr M discrete f" define \ where "\ = Abs_pmf M'" have a:"measure_pmf (Abs_pmf M') = M'" unfolding M'_def by (intro Abs_pmf_inverse[OF establish_pmf] rv countable_f) have b:"{i. (i < n \ Y i x) \ i < n} = {i. i < n \ Y i x}" for x by auto have c: "measure \ {\. \i\S. \ i} \ prod \ S" (is "?L1 \ ?R1") if "S \ {.. S \ i < n" for i using that by auto have "?L1 = measure M' {\. \i\S. \ i}" unfolding \_def a by simp also have "... = \

(\ in M. (\i \ S. Y i \))" unfolding M'_def using that d by (subst measure_distr[OF rv]) (auto simp add:f_def Int_commute Int_def) also have "... \ ?R1" using that assms(4) by simp finally show ?thesis by simp qed have "?L = measure M' {\. real (card {i. i < n \ \ i}) \ \ * n}" unfolding M'_def by (subst measure_distr[OF rv]) (auto simp add:f_def algebra_simps Int_commute Int_def b) also have "... = measure_pmf.prob \ {\. real (card {i \ {.. i}) \ \ * n}" unfolding \_def a by simp also have "... \ ?R" using assms(1,3,6,7) c unfolding \_avg_def by (intro impagliazzo_kabanets_pmf) auto finally show ?thesis by simp qed text \Bounds and properties of @{term "KL_div"}\ lemma KL_div_mono_right_aux_1: assumes "0 \ p" "p \ q" "q \ q'" "q' < 1" shows "KL_div p q-2*(p-q)^2 \ KL_div p q'-2*(p-q')^2" proof (cases "p = 0") case True define f' :: "real \ real" where "f' = (\x. 1/(1-x) - 4 * x)" have deriv: "((\q. ln (1/(1-q)) - 2*q^2) has_real_derivative (f' x)) (at x)" if "x \ {q..q'}" for x proof - have "x \ {0..<1}" using assms that by auto thus ?thesis unfolding f'_def by (auto intro!: derivative_eq_intros) qed have deriv_nonneg: "f' x \ 0" if "x \ {q..q'}" for x proof - have 0:"x \ {0..<1}" using assms that by auto have "4 * x*(1-x) = 1 - 4*(x-1/2)^2" by (simp add:power2_eq_square field_simps) also have "... \ 1" by simp finally have "4*x*(1-x) \ 1" by simp hence "1/(1-x) \ 4*x" using 0 by (simp add: pos_le_divide_eq) thus ?thesis unfolding f'_def by auto qed have "ln (1 / (1 - q)) - 2 * q^2 \ ln (1 / (1 - q')) - 2 * q'^2" using deriv deriv_nonneg by (intro DERIV_nonneg_imp_nondecreasing[OF assms(3)]) auto thus ?thesis using True unfolding KL_div_def by simp next case False hence p_gt_0: "p > 0" using assms by auto define f' :: "real \ real" where "f' = (\x. (1-p)/(1-x) - p/x + 4 * (p-x))" have deriv: "((\q. KL_div p q - 2*(p-q)^2) has_real_derivative (f' x)) (at x)" if "x \ {q..q'}" for x proof - have "0 < p /x" " 0 < (1 - p) / (1 - x)" using that assms p_gt_0 by auto thus ?thesis unfolding KL_div_def f'_def by (auto intro!: derivative_eq_intros) qed have f'_part_nonneg: "(1/(x*(1-x)) - 4) \ 0" if "x \ {0<..<1}" for x :: real proof - have "4 * x * (1-x) = 1 - 4 * (x-1/2)^2" by (simp add:power2_eq_square algebra_simps) also have "... \ 1" by simp finally have "4 * x * (1-x) \ 1" by simp hence "1/(x*(1-x)) \ 4" using that by (subst pos_le_divide_eq) auto thus ?thesis by simp qed have f'_alt: "f' x = (x-p)*(1/(x*(1-x)) - 4)" if "x \ {0<..<1}" for x proof - have "f' x = (x-p)/(x*(1-x)) + 4 * (p-x)" using that unfolding f'_def by (simp add:field_simps) also have "... = (x-p)*(1/(x*(1-x)) - 4)" by (simp add:algebra_simps) finally show ?thesis by simp qed have deriv_nonneg: "f' x \ 0" if "x \ {q..q'}" for x proof - have "x \ {0<..<1}" using assms that p_gt_0 by auto have "f' x =(x-p)*(1/(x*(1-x)) - 4)" using that assms p_gt_0 by (subst f'_alt) auto also have "... \ 0" using that f'_part_nonneg assms p_gt_0 by (intro mult_nonneg_nonneg) auto finally show ?thesis by simp qed show ?thesis using deriv deriv_nonneg by (intro DERIV_nonneg_imp_nondecreasing[OF assms(3)]) auto qed lemma KL_div_swap: "KL_div (1-p) (1-q) = KL_div p q" unfolding KL_div_def by auto lemma KL_div_mono_right_aux_2: assumes "0 < q'" "q' \ q" "q \ p" "p \ 1" shows "KL_div p q-2*(p-q)^2 \ KL_div p q'-2*(p-q')^2" proof - have "KL_div (1-p) (1-q)-2*((1-p)-(1-q))^2 \ KL_div (1-p) (1-q')-2*((1-p)-(1-q'))^2" using assms by (intro KL_div_mono_right_aux_1) auto thus ?thesis unfolding KL_div_swap by (auto simp:algebra_simps power2_commute) qed lemma KL_div_mono_right_aux: assumes "(0 \ p \ p \ q \ q \ q' \ q' < 1) \ (0 < q' \ q' \ q \ q \ p \ p \ 1)" shows "KL_div p q-2*(p-q)^2 \ KL_div p q'-2*(p-q')^2" using KL_div_mono_right_aux_1 KL_div_mono_right_aux_2 assms by auto lemma KL_div_mono_right: assumes "(0 \ p \ p \ q \ q \ q' \ q' < 1) \ (0 < q' \ q' \ q \ q \ p \ p \ 1)" shows "KL_div p q \ KL_div p q'" (is "?L \ ?R") proof - consider (a) "0 \ p" "p \ q" "q \ q'" "q' < 1" | (b) "0 < q'" "q' \ q" "q \ p" "p \ 1" using assms by auto hence 0: "(p - q)\<^sup>2 \ (p - q')\<^sup>2" proof (cases) case a hence "(q-p)^2 \ (q' - p)^2" by auto thus ?thesis by (simp add: power2_commute) next case b thus ?thesis by simp qed have "?L = (KL_div p q - 2*(p-q)^2) + 2 * (p-q)^2" by simp also have "... \ (KL_div p q' - 2*(p-q')^2) + 2 * (p-q')^2" by (intro add_mono KL_div_mono_right_aux assms mult_left_mono 0) auto also have "... = ?R" by simp finally show ?thesis by simp qed +lemma KL_div_lower_bound: + assumes "p \ {0..1}" "q \ {0<..<1}" + shows "2*(p-q)^2 \ KL_div p q" +proof - + have "0 \ KL_div p p - 2 * (p-p)^2" unfolding KL_div_def by simp + also have "... \ KL_div p q - 2 * (p-q)^2" using assms by (intro KL_div_mono_right_aux) auto + finally show ?thesis by simp +qed + end \ No newline at end of file diff --git a/thys/Expander_Graphs/Pseudorandom_Objects_Expander_Walks.thy b/thys/Expander_Graphs/Pseudorandom_Objects_Expander_Walks.thy --- a/thys/Expander_Graphs/Pseudorandom_Objects_Expander_Walks.thy +++ b/thys/Expander_Graphs/Pseudorandom_Objects_Expander_Walks.thy @@ -1,210 +1,312 @@ section \Expander Walks as Pseudorandom Objects\ theory Pseudorandom_Objects_Expander_Walks imports Universal_Hash_Families.Pseudorandom_Objects Expander_Graphs.Expander_Graphs_Strongly_Explicit begin +unbundle intro_cong_syntax hide_const (open) Quantum.T +hide_fact (open) SN_Orders.of_nat_mono +hide_fact Missing_Ring.mult_pos_pos definition expander_pro :: "nat \ real \ ('a,'b) pseudorandom_object_scheme \ (nat \ 'a) pseudorandom_object" where "expander_pro l \ S = ( let e = see_standard (pro_size S) \ in \ pro_last = see_size e * see_degree e^(l-1) - 1, pro_select = (\i j. pro_select S (see_sample_walk e (l-1) i ! j mod pro_size S)) \ )" context fixes l :: nat fixes \ :: real fixes S :: "('a,'b) pseudorandom_object_scheme" assumes l_gt_0: "l > 0" assumes \_gt_0: "\ > 0" begin private definition e where "e = see_standard (pro_size S) \" private lemma expander_pro_alt: "expander_pro l \ S = \ pro_last = see_size e * see_degree e^(l-1) - 1, pro_select = (\i j. pro_select S (see_sample_walk e (l-1) i ! j mod pro_size S)) \" unfolding expander_pro_def e_def[symmetric] by (auto simp:Let_def) private lemmas see_standard = see_standard [OF pro_size_gt_0[where S="S"] \_gt_0] interpretation E: regular_graph "graph_of e" using see_standard(1) unfolding is_expander_def e_def by auto private lemma e_deg_gt_0: "see_degree e > 0" unfolding e_def see_standard by simp private lemma e_size_gt_0: "see_size e > 0" unfolding e_def using see_standard pro_size_gt_0 by simp private lemma expander_sample_size: "pro_size (expander_pro l \ S) = see_size e * see_degree e^(l-1)" using e_deg_gt_0 e_size_gt_0 unfolding expander_pro_alt pro_size_def by simp private lemma sample_pro_expander_walks: defines "R \ map_pmf (\xs i. pro_select S (xs ! i mod pro_size S)) (pmf_of_multiset (walks (graph_of e) l))" shows "sample_pro (expander_pro l \ S) = R" proof - let ?S = "{.. ?S" using e_size_gt_0 e_deg_gt_0 by auto hence "?S \ {}" by blast hence "?T = pmf_of_multiset {#see_sample_walk e (l-1) i. i \# mset_set ?S#}" by (subst map_pmf_of_set) simp_all also have "... = pmf_of_multiset (walks' (graph_of e) (l-1))" by (subst see_sample_walk) auto also have "... = pmf_of_multiset (walks (graph_of e) l)" unfolding walks_def using l_gt_0 by (cases l, simp_all) finally have 0:"?T = pmf_of_multiset (walks (graph_of e) l)" by simp have "sample_pro (expander_pro l \ S) = map_pmf (\xs j. pro_select S (xs ! j mod pro_size S)) ?T" unfolding expander_sample_size sample_pro_alt unfolding map_pmf_comp expander_pro_alt by simp also have "... = R" unfolding 0 R_def by simp finally show ?thesis by simp qed +lemma expander_pro_range: "pro_select (expander_pro l \ S) i j \ pro_set S" + unfolding expander_pro_alt by (simp add:pro_select_in_set) + lemma expander_uniform_property: assumes "i < l" shows "map_pmf (\w. w i) (sample_pro (expander_pro l \ S)) = sample_pro S" (is "?L = ?R") proof - have "?L = map_pmf (\x. pro_select S (x mod pro_size S)) (map_pmf (\xs. (xs ! i)) (pmf_of_multiset (walks (graph_of e) l)))" unfolding sample_pro_expander_walks by (simp add: map_pmf_comp) also have "... = map_pmf (\x. pro_select S (x mod pro_size S)) (pmf_of_set (verts (graph_of e)))" unfolding E.uniform_property[OF assms] by simp also have "... = ?R" using pro_size_gt_0 unfolding sample_pro_alt by (intro map_pmf_cong) (simp_all add:e_def graph_of_def see_standard select_def) finally show ?thesis by simp qed lemma expander_kl_chernoff_bound: assumes "measure (sample_pro S) {w. T w} \ \" assumes "\ \ 1" "\ + \ * (1-\) \ \" "\ \ 1" shows "measure (sample_pro (expander_pro l \ S)) {w. real (card {i \ {.. \*l} \ exp (- real l * KL_div \ (\ + \*(1-\)))" (is "?L \ ?R") proof (cases "measure (sample_pro S) {w. T w} > 0") case True let ?w = "pmf_of_multiset (walks (graph_of e) l)" define V where "V = {v\ verts (graph_of e). T (pro_select S v)} " define \ where "\ = measure (sample_pro S) {w. T w}" have \_gt_0: "\ > 0" unfolding \_def using True by simp have \_le_1: "\ \ 1" unfolding \_def by simp have \_le_\: "\ \ \" unfolding \_def using assms(1) by simp have 0: "card {i \ {.. {.. V}" if "w \ set_pmf (pmf_of_multiset (walks (graph_of e) l))" for w proof - have a0: "w \# walks (graph_of e) l" using that E.walks_nonempty by simp have a1:"w ! i \ verts (graph_of e)" if "i < l" for i using that E.set_walks_3[OF a0] by auto moreover have "w ! i mod pro_size S = w ! i" if "i < l" for i using a1[OF that] see_standard(2) e_def by (simp add:graph_of_def) ultimately show ?thesis unfolding V_def by (intro arg_cong[where f="card"] restr_Collect_cong) auto qed have 1:"E.\\<^sub>a \ \" using see_standard(1) unfolding is_expander_def e_def by simp have 2: "V \ verts (graph_of e)" unfolding V_def by simp have "\ = measure (pmf_of_set {.._def sample_pro_alt by simp also have "... = real (card ({v\{.._eq: "\ = real (card V) / card (verts (graph_of e))" by simp have 3: "0 < \ + E.\\<^sub>a * (1 - \)" using \_le_1 by (intro add_pos_nonneg \_gt_0 mult_nonneg_nonneg E.\_ge_0) auto have "\ + E.\\<^sub>a * (1 - \) = \ * (1 - E.\\<^sub>a) + E.\\<^sub>a" by (simp add:algebra_simps) also have "... \ \ * (1- E.\\<^sub>a) + E.\\<^sub>a" using E.\_le_1 by (intro add_mono mult_right_mono \_le_\) auto also have "... = \ + E.\\<^sub>a * (1 - \)" by (simp add:algebra_simps) also have "... \ \ + \ * (1 - \)" using assms(4) by (intro add_mono mult_right_mono 1) auto finally have 4: "\ + E.\\<^sub>a * (1 - \) \ \ + \ * (1 - \)" by simp have 5: "\ + E.\\<^sub>a*(1-\) \ \" using 4 assms(3) by simp have "?L = measure ?w {y. \ * real l \ real (card {i \ {.. * real l \ real (card {i \ {.. V})}" using 0 by (intro measure_pmf_cong) (simp) also have "... \ exp (- real l * KL_div \ (\ + E.\\<^sub>a*(1-\)) )" using assms(2) 3 5 unfolding \_eq by (intro E.kl_chernoff_property l_gt_0 2) auto also have "... \ exp (- real l * KL_div \ (\ + \*(1-\)))" using l_gt_0 by (intro iffD2[OF exp_le_cancel_iff] iffD2[OF mult_le_cancel_left_neg] KL_div_mono_right[OF disjI2] conjI 3 4 assms(2,3)) auto finally show ?thesis by simp next case False hence 0:"measure (sample_pro S) {w. T w} = 0" using zero_less_measure_iff by blast hence 1:"T w = False" if "w \ pro_set S" for w using that measure_pmf_posI by force have "\ + \ * (1-\) > 0" proof (cases "\ = 0") case True then show ?thesis using \_gt_0 by auto next case False then show ?thesis using assms(1,4) 0 \_gt_0 by (intro add_pos_nonneg mult_nonneg_nonneg) simp_all qed hence "\ > 0" using assms(3) by auto hence 2:"\*real l > 0" using l_gt_0 by simp let ?w = "pmf_of_multiset (walks (graph_of e) l)" have "?L = measure ?w {y. \*real l\ card {i \ {.. ?R" by simp finally show ?thesis by simp qed +lemma expander_chernoff_bound_one_sided: + assumes "AE x in sample_pro S. f x \ {0,1::real}" + assumes "(\x. f x \sample_pro S) \ \" "l > 0" "\ \ 0" + shows "measure (expander_pro l \ S) {w. (\i\\+\} \ exp (- 2 * real l * \^2)" + (is "?L \ ?R") +proof - + let ?w = "sample_pro (expander_pro l \ S)" + define T where "T x = (f x=1)" for x + + have 1: "indicator {w. T w} x = f x" if "x \ pro_set S" for x + proof - + have "f x \ {0,1}" using assms(1) that unfolding AE_measure_pmf_iff by simp + thus ?thesis unfolding T_def by auto + qed + + have "measure S {w. T w} = (\x. indicator {w. T w} x \S)" by simp + also have "... = (\x. f x \S)" using 1 by (intro integral_cong_AE AE_pmfI) auto + also have "... \ \" using assms(2) by simp + finally have 0: "measure S {w. T w} \ \" by simp + + hence \_ge_0: "\ \ 0" using measure_nonneg order.trans by blast + + have cases: "(\=0 \ p) \ (\+\+\ > 1 \ p) \ (\+\+\ \ 1 \ \ > 0 \ p) \ p" for p + using assms(4) by argo + + have "?L = measure ?w {w. (\+\+\)*l \ (\i+\+\)*l \ card {i \ {.. + assume "\ \ pro_set (expander_pro l \ S)" + hence "\ x \ pro_set S" for x using expander_pro_range set_sample_pro by (metis image_iff) + hence "(\i i)) = (\i i))" using 1 by (intro sum.cong) auto + also have "... = card {i \ {.. i)}" unfolding indicator_def by (auto simp:Int_def) + finally have "(\i i)) = (card {i \ {.. i)})" by simp + thus "(\ \ {w. (\+\+\)*l \ (\i \ {w. (\+\+\)*l\card {i \ {.. ?R" (is "?L1 \ _") + proof (rule cases) + assume "\ = 0" thus "?thesis" by simp + next + assume a:"\ + \ + \ \ 1 \ 0 < \" + hence \_lt_1: "\ < 1" using assms(4) \_gt_0 by simp + hence \_le_1: "\ \ 1" by simp + have "\ + \ * (1 - \) \ \ + \ * 1" using \_ge_0 \_gt_0 by (intro add_mono mult_left_mono) auto + also have "... < \+\+\" using assms(4) a by simp + finally have b:"\ + \ * (1 - \) < \ +\ +\" by simp + hence "\ + \ * (1 - \) < 1" using a by simp + moreover have "\ + \ * (1 - \) > 0" using \_lt_1 + by (intro add_nonneg_pos \_ge_0 mult_pos_pos \_gt_0) simp + ultimately have c: "\ + \ * (1 - \) \ {0<..<1}" by simp + have d: " \ + \ + \ \ {0..1}" using a b c by simp + have "?L1 \ exp (- real l * KL_div (\+\+\) (\ + \*(1-\)))" + using a b by (intro expander_kl_chernoff_bound \_le_1 0) auto + also have "... \ exp (- real l * (2 * ((\+\+\)- (\ + \*(1-\)))^2))" + by (intro iffD2[OF exp_le_cancel_iff] mult_left_mono_neg KL_div_lower_bound c d) simp + also have "... \ exp (- real l * (2 * (\^2)))" + using assms(4) \_lt_1 \_gt_0 \_ge_0 + by (intro iffD2[OF exp_le_cancel_iff] mult_left_mono_neg[where c="-real l"] mult_left_mono + power_mono) simp_all + also have "... = ?R" by simp + finally show "?L1 \ ?R" by simp + next + assume a:"1 < \ + \ + \" + have "(\+\+\)* real l > real (card {i \ {.. {.. card {..+\+\)* real l" using assms(3) a by simp + finally show ?thesis by simp + qed + hence "?L1 = 0" unfolding not_le[symmetric] by auto + also have "... \ ?R" by simp + finally show "?L1 \ ?R" by simp + qed + finally show ?thesis by simp +qed + +lemma expander_chernoff_bound: + assumes "AE x in sample_pro S. f x \ {0,1::real}" "l > 0" "\ \ 0" + defines "\ \ (\x. f x \sample_pro S)" + shows "measure (expander_pro l \ S) {w. \(\i\\\+\} \ 2*exp (- 2 * real l * \^2)" + (is "?L \ ?R") +proof - + let ?w = "sample_pro (expander_pro l \ S)" + have "?L \ measure ?w {w. (\i\\+\} + measure ?w {w. (\i\-(\+\)}" + by (intro pmf_add) auto + also have "... \ exp (-2*real l*\^2) + measure ?w {w. -((\i)\(\+\)}" + using assms by (intro add_mono expander_chernoff_bound_one_sided) (auto simp:algebra_simps) + also have "... \ exp (-2*real l*\^2) + measure ?w {w. ((\i))\(\+\)}" + using assms(2) by (auto simp: sum_subtractf field_simps) + also have "... \ exp (-2*real l*\^2) + exp (-2*real l*\^2)" + using assms by (intro add_mono expander_chernoff_bound_one_sided) auto + also have "... = ?R" by simp + finally show ?thesis by simp +qed + lemma expander_pro_size: "pro_size (expander_pro l \ S) = pro_size S * (16 ^ ((l-1) * nat \ln \ / ln (19 / 20)\))" (is "?L = ?R") proof - have "?L = see_size e * see_degree e ^ (l - 1)" unfolding expander_sample_size by simp also have "... = pro_size S * (16 ^ nat \ln \ / ln (19 / 20)\) ^ (l - 1)" using see_standard unfolding e_def by simp also have "... = pro_size S * (16 ^ ((l-1) * nat \ln \ / ln (19 / 20)\))" unfolding power_mult[symmetric] by (simp add:ac_simps) finally show ?thesis by simp qed -lemma expander_pro_range: "pro_select (expander_pro l \ S) i j \ pro_set S" - unfolding expander_pro_alt by (simp add:pro_select_in_set) - end bundle expander_pseudorandom_object_notation begin notation expander_pro ("\") end bundle no_expander_pseudorandom_object_notation begin no_notation expander_pro ("\") end unbundle expander_pseudorandom_object_notation +unbundle no_intro_cong_syntax end \ No newline at end of file diff --git a/thys/Universal_Hash_Families/Universal_Hash_Families_More_Product_PMF.thy b/thys/Universal_Hash_Families/Universal_Hash_Families_More_Product_PMF.thy --- a/thys/Universal_Hash_Families/Universal_Hash_Families_More_Product_PMF.thy +++ b/thys/Universal_Hash_Families/Universal_Hash_Families_More_Product_PMF.thy @@ -1,257 +1,268 @@ section \Indexed Products of Probability Mass Functions\ theory Universal_Hash_Families_More_Product_PMF imports "HOL-Probability.Product_PMF" Concentration_Inequalities.Concentration_Inequalities_Preliminary Finite_Fields.Finite_Fields_More_Bijections Universal_Hash_Families_More_Independent_Families begin hide_const (open) Isolated.discrete text \This section introduces a restricted version of @{term "Pi_pmf"} where the default value is @{term "undefined"} and contains some additional results about that case in addition to @{theory "HOL-Probability.Product_PMF"}\ abbreviation prod_pmf where "prod_pmf I M \ Pi_pmf I undefined M" lemma measure_pmf_cong: assumes "\x. x \ set_pmf p \ x \ P \ x \ Q" shows "measure (measure_pmf p) P = measure (measure_pmf p) Q" using assms by (intro finite_measure.finite_measure_eq_AE AE_pmfI) auto lemma pmf_mono: assumes "\x. x \ set_pmf p \ x \ P \ x \ Q" shows "measure (measure_pmf p) P \ measure (measure_pmf p) Q" proof - have "measure (measure_pmf p) P = measure (measure_pmf p) (P \ (set_pmf p))" by (intro measure_pmf_cong) auto also have "... \ measure (measure_pmf p) Q" using assms by (intro finite_measure.finite_measure_mono) auto finally show ?thesis by simp qed +lemma pmf_add: + assumes "\x. x \ P \ x \ set_pmf p \ x \ Q \ x \ R" + shows "measure p P \ measure p Q + measure p R" +proof - + have "measure p P \ measure p (Q \ R)" + using assms by (intro pmf_mono) blast + also have "... \ measure p Q + measure p R" + by (rule measure_subadditive, auto) + finally show ?thesis by simp +qed + lemma pmf_prod_pmf: assumes "finite I" shows "pmf (prod_pmf I M) x = (if x \ extensional I then \i \ I. (pmf (M i)) (x i) else 0)" by (simp add: pmf_Pi[OF assms(1)] extensional_def) lemma PiE_defaut_undefined_eq: "PiE_dflt I undefined M = PiE I M" by (simp add:PiE_dflt_def PiE_def extensional_def Pi_def set_eq_iff) blast lemma set_prod_pmf: assumes "finite I" shows "set_pmf (prod_pmf I M) = PiE I (set_pmf \ M)" by (simp add:set_Pi_pmf[OF assms] PiE_defaut_undefined_eq) text \A more general version of @{thm [source] "measure_Pi_pmf_Pi"}.\ lemma prob_prod_pmf': assumes "finite I" assumes "J \ I" shows "measure (measure_pmf (Pi_pmf I d M)) (Pi J A) = (\ i \ J. measure (M i) (A i))" proof - have a:"Pi J A = Pi I (\i. if i \ J then A i else UNIV)" using assms by (simp add:Pi_def set_eq_iff, blast) show ?thesis using assms by (simp add:if_distrib a measure_Pi_pmf_Pi[OF assms(1)] prod.If_cases[OF assms(1)] Int_absorb1) qed lemma prob_prod_pmf_slice: assumes "finite I" assumes "i \ I" shows "measure (measure_pmf (prod_pmf I M)) {\. P (\ i)} = measure (M i) {\. P \}" using prob_prod_pmf'[OF assms(1), where J="{i}" and M="M" and A="\_. Collect P"] by (simp add:assms Pi_def) definition restrict_dfl where "restrict_dfl f A d = (\x. if x \ A then f x else d)" lemma pi_pmf_decompose: assumes "finite I" shows "Pi_pmf I d M = map_pmf (\\. restrict_dfl (\i. \ (f i) i) I d) (Pi_pmf (f ` I) (\_. d) (\j. Pi_pmf (f -` {j} \ I) d M))" proof - have fin_F_I:"finite (f ` I)" using assms by blast have "finite I \ ?thesis" using fin_F_I proof (induction "f ` I" arbitrary: I rule:finite_induct) case empty then show ?case by (simp add:restrict_dfl_def) next case (insert x F) have a: "(f -` {x} \ I) \ (f -` F \ I) = I" using insert(4) by blast have b: "F = f ` (f -` F \ I) " using insert(2,4) by (auto simp add:set_eq_iff image_def vimage_def) have c: "finite (f -` F \ I)" using insert by blast have d: "\j. j \ F \ (f -` {j} \ (f -` F \ I)) = (f -` {j} \ I)" using insert(4) by blast have " Pi_pmf I d M = Pi_pmf ((f -` {x} \ I) \ (f -` F \ I)) d M" by (simp add:a) also have "... = map_pmf (\(g, h) i. if i \ f -` {x} \ I then g i else h i) (pair_pmf (Pi_pmf (f -` {x} \ I) d M) (Pi_pmf (f -` F \ I) d M))" using insert by (subst Pi_pmf_union) auto also have "... = map_pmf (\(g,h) i. if f i = x \ i \ I then g i else if f i \ F \ i \ I then h (f i) i else d) (pair_pmf (Pi_pmf (f -` {x} \ I) d M) (Pi_pmf F (\_. d) (\j. Pi_pmf (f -` {j} \ (f -` F \ I)) d M)))" by (simp add:insert(3)[OF b c] map_pmf_comp case_prod_beta' apsnd_def map_prod_def pair_map_pmf2 b[symmetric] restrict_dfl_def) (metis fst_conv snd_conv) also have "... = map_pmf (\(g,h) i. if i \ I then (h(x := g)) (f i) i else d) (pair_pmf (Pi_pmf (f -` {x} \ I) d M) (Pi_pmf F (\_. d) (\j. Pi_pmf (f -` {j} \ I) d M)))" using insert(4) d by (intro arg_cong2[where f="map_pmf"] ext) (auto simp add:case_prod_beta' cong:Pi_pmf_cong) also have "... = map_pmf (\\ i. if i \ I then \ (f i) i else d) (Pi_pmf (insert x F) (\_. d) (\j. Pi_pmf (f -` {j} \ I) d M))" by (simp add:Pi_pmf_insert[OF insert(1,2)] map_pmf_comp case_prod_beta') finally show ?case by (simp add:insert(4) restrict_dfl_def) qed thus ?thesis using assms by blast qed lemma restrict_dfl_iter: "restrict_dfl (restrict_dfl f I d) J d = restrict_dfl f (I \ J) d" by (rule ext, simp add:restrict_dfl_def) lemma indep_vars_restrict': assumes "finite I" shows "prob_space.indep_vars (Pi_pmf I d M) (\_. discrete) (\i \. restrict_dfl \ (f -` {i} \ I) d) (f ` I)" proof - let ?Q = "(Pi_pmf (f ` I) (\_. d) (\i. Pi_pmf (I \ f -` {i}) d M))" have a:"prob_space.indep_vars ?Q (\_. discrete) (\i \. \ i) (f ` I)" using assms by (intro indep_vars_Pi_pmf, blast) have b: "AE x in measure_pmf ?Q. \i\f ` I. x i = restrict_dfl (\i. x (f i) i) (I \ f -` {i}) d" using assms by (auto simp add:PiE_dflt_def restrict_dfl_def AE_measure_pmf_iff set_Pi_pmf comp_def Int_commute) have "prob_space.indep_vars ?Q (\_. discrete) (\i x. restrict_dfl (\i. x (f i) i) (I \ f -` {i}) d) (f ` I)" by (rule prob_space.indep_vars_cong_AE[OF prob_space_measure_pmf b a], simp) thus ?thesis using prob_space_measure_pmf by (auto intro!:prob_space.indep_vars_distr simp:pi_pmf_decompose[OF assms, where f="f"] map_pmf_rep_eq comp_def restrict_dfl_iter Int_commute) qed lemma indep_vars_restrict_intro': assumes "finite I" assumes "\i \. i \ J \ X' i \ = X' i (restrict_dfl \ (f -` {i} \ I) d)" assumes "J = f ` I" assumes "\\ i. i \ J \ X' i \ \ space (M' i)" shows "prob_space.indep_vars (measure_pmf (Pi_pmf I d p)) M' (\i \. X' i \) J" proof - define M where "M \ measure_pmf (Pi_pmf I d p)" interpret prob_space "M" using M_def prob_space_measure_pmf by blast have "indep_vars (\_. discrete) (\i x. restrict_dfl x (f -` {i} \ I) d) (f ` I)" unfolding M_def by (rule indep_vars_restrict'[OF assms(1)]) hence "indep_vars M' (\i \. X' i (restrict_dfl \ ( f -` {i} \ I) d)) (f ` I)" using assms(4) by (intro indep_vars_compose2[where Y="X'" and N="M'" and M'="\_. discrete"]) (auto simp:assms(3)) hence "indep_vars M' (\i \. X' i \) (f ` I)" using assms(2)[symmetric] by (simp add:assms(3) cong:indep_vars_cong) thus ?thesis unfolding M_def using assms(3) by simp qed lemma fixes f :: "'b \ ('c :: {second_countable_topology,banach,real_normed_field})" assumes "finite I" assumes "i \ I" assumes "integrable (measure_pmf (M i)) f" shows integrable_Pi_pmf_slice: "integrable (Pi_pmf I d M) (\x. f (x i))" and expectation_Pi_pmf_slice: "integral\<^sup>L (Pi_pmf I d M) (\x. f (x i)) = integral\<^sup>L (M i) f" proof - have a:"distr (Pi_pmf I d M) (M i) (\\. \ i) = distr (Pi_pmf I d M) discrete (\\. \ i)" by (rule distr_cong, auto) have b: "measure_pmf.random_variable (M i) borel f" using assms(3) by simp have c:"integrable (distr (Pi_pmf I d M) (M i) (\\. \ i)) f" using assms(1,2,3) by (subst a, subst map_pmf_rep_eq[symmetric], subst Pi_pmf_component, auto) show "integrable (Pi_pmf I d M) (\x. f (x i))" by (rule integrable_distr[where f="f" and M'="M i"]) (auto intro: c) have "integral\<^sup>L (Pi_pmf I d M) (\x. f (x i)) = integral\<^sup>L (distr (Pi_pmf I d M) (M i) (\\. \ i)) f" using b by (intro integral_distr[symmetric], auto) also have "... = integral\<^sup>L (map_pmf (\\. \ i) (Pi_pmf I d M)) f" by (subst a, subst map_pmf_rep_eq[symmetric], simp) also have "... = integral\<^sup>L (M i) f" using assms(1,2) by (simp add: Pi_pmf_component) finally show "integral\<^sup>L (Pi_pmf I d M) (\x. f (x i)) = integral\<^sup>L (M i) f" by simp qed text \This is an improved version of @{thm [source] "expectation_prod_Pi_pmf"}. It works for general normed fields instead of non-negative real functions .\ lemma expectation_prod_Pi_pmf: fixes f :: "'a \ 'b \ ('c :: {second_countable_topology,banach,real_normed_field})" assumes "finite I" assumes "\i. i \ I \ integrable (measure_pmf (M i)) (f i)" shows "integral\<^sup>L (Pi_pmf I d M) (\x. (\i \ I. f i (x i))) = (\ i \ I. integral\<^sup>L (M i) (f i))" proof - have a: "prob_space.indep_vars (measure_pmf (Pi_pmf I d M)) (\_. borel) (\i \. f i (\ i)) I" by (intro prob_space.indep_vars_compose2[where Y="f" and M'="\_. discrete"] prob_space_measure_pmf indep_vars_Pi_pmf assms(1)) auto have "integral\<^sup>L (Pi_pmf I d M) (\x. (\i \ I. f i (x i))) = (\ i \ I. integral\<^sup>L (Pi_pmf I d M) (\x. f i (x i)))" by (intro prob_space.indep_vars_lebesgue_integral prob_space_measure_pmf assms(1,2) a integrable_Pi_pmf_slice) auto also have "... = (\ i \ I. integral\<^sup>L (M i) (f i))" by (intro prod.cong expectation_Pi_pmf_slice assms(1,2)) auto finally show ?thesis by simp qed lemma variance_prod_pmf_slice: fixes f :: "'a \ real" assumes "i \ I" "finite I" assumes "integrable (measure_pmf (M i)) (\\. f \^2)" shows "prob_space.variance (Pi_pmf I d M) (\\. f (\ i)) = prob_space.variance (M i) f" proof - have a:"integrable (measure_pmf (M i)) f" using assms(3) measure_pmf.square_integrable_imp_integrable by auto have b:" integrable (measure_pmf (Pi_pmf I d M)) (\x. (f (x i))\<^sup>2)" by (rule integrable_Pi_pmf_slice[OF assms(2) assms(1)], metis assms(3)) have c:" integrable (measure_pmf (Pi_pmf I d M)) (\x. (f (x i)))" by (rule integrable_Pi_pmf_slice[OF assms(2) assms(1)], metis a) have "measure_pmf.expectation (Pi_pmf I d M) (\x. (f (x i))\<^sup>2) - (measure_pmf.expectation (Pi_pmf I d M) (\x. f (x i)))\<^sup>2 = measure_pmf.expectation (M i) (\x. (f x)\<^sup>2) - (measure_pmf.expectation (M i) f)\<^sup>2" using assms a b c by ((subst expectation_Pi_pmf_slice[OF assms(2,1)])?, simp)+ thus ?thesis using assms a b c by (simp add: measure_pmf.variance_eq) qed lemma Pi_pmf_bind_return: assumes "finite I" shows "Pi_pmf I d (\i. M i \ (\x. return_pmf (f i x))) = Pi_pmf I d' M \ (\x. return_pmf (\i. if i \ I then f i (x i) else d))" using assms by (simp add: Pi_pmf_bind[where d'="d'"]) lemma pmf_of_set_prod_eq: assumes "A \ {}" "finite A" assumes "B \ {}" "finite B" shows "pmf_of_set (A \ B) = pair_pmf (pmf_of_set A) (pmf_of_set B)" proof - have "indicat_real (A \ B) (i, j) = indicat_real A i * indicat_real B j" for i j by (cases "i \ A"; cases "j \ B") auto hence "pmf (pmf_of_set (A \ B)) (i,j) = pmf (pair_pmf (pmf_of_set A) (pmf_of_set B)) (i,j)" for i j using assms by (simp add:pmf_pair) thus ?thesis by (intro pmf_eqI) auto qed lemma split_pmf_mod_div': assumes "a > (0::nat)" assumes "b > 0" shows "map_pmf (\x. (x mod a, x div a)) (pmf_of_set {.. {.. (0::nat)" assumes "b > 0" shows "map_pmf (\x. (x mod a, x div a)) (pmf_of_set {..