Download data/lean/OAI/Probability/SATVariance/HallSatisfiability.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 10.6 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/SATVariance/HallSatisfiability.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/SATVariance/HallSatisfiability.lean
-
curl -L -o HallSatisfiability.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/SATVariance/HallSatisfiability.lean
10.6 kB
| import OAI.Probability.SATVariance.CapBridge | |
| namespace OAI | |
| noncomputable section | |
| open MeasureTheory ProbabilityTheory | |
| namespace RandomKSAT | |
| open scoped Classical ENNReal | |
| lemma finiteSAT_of_hall {n k m : β} (w : Fin m β Clause n k) | |
| (hh : β I : Finset (Fin m), I.card β€ (I.biUnion (fun j => (w j).1.1)).card) : | |
| finiteSAT w m := by | |
| obtain β¨f,hf,hmβ© := (Finset.all_card_le_biUnion_card_iff_exists_injective | |
| (fun j => (w j).1.1)).mp hh | |
| let a : Assignment n := Function.extend f (fun j => (w j).2 β¨f j,hm jβ©) (fun _ => false) | |
| refine β¨a,fun j _ => β¨β¨f j,hm jβ©,?_β©β© | |
| exact hf.extend_apply _ _ j | |
| lemma deficient_witness {n k m : β} (w : Fin m β Clause n k) (hw : Β¬finiteSAT w m) : | |
| β W : Finset (Fin n), β I : Finset (Fin m), I.card = W.card+1 β§ | |
| β j β I, (w j).1.1 β W := by | |
| have hh : Β¬β I : Finset (Fin m), I.card β€ (I.biUnion (fun j => (w j).1.1)).card := | |
| fun h => hw (finiteSAT_of_hall w h) | |
| push Not at hh | |
| obtain β¨J,hJβ© := hh | |
| obtain β¨I,hIJ,hIβ© := Finset.exists_subset_card_eq (Nat.succ_le_of_lt hJ) | |
| refine β¨J.biUnion (fun j => (w j).1.1),I,hI,fun j hj v hv => ?_β© | |
| exact Finset.mem_biUnion.mpr β¨j,hIJ hj,hvβ© | |
| lemma favg_support {n k : β} (f : {s : Finset (Fin n) // s.card = k} β β) : | |
| favg (fun c : Clause n k => f c.1) = favg f := by | |
| unfold favg | |
| change (β c : (s : {s : Finset (Fin n) // s.card = k}) Γ (s.1 β Bool), f c.1) / | |
| Fintype.card (Clause n k) = _ | |
| rw [Fintype.sum_sigma, clause_card, support_card] | |
| have he (s : {s : Finset (Fin n) // s.card = k}) : (β _ : s.1 β Bool, f s) = 2^k*f s := by | |
| simp [s.property] | |
| simp only [he, β Finset.mul_sum, Nat.cast_mul, Nat.cast_pow, Nat.cast_ofNat] | |
| have hp : (2:β)^k β 0 := by positivity | |
| field_simp | |
| lemma containing_support_probability {n k : β} (W : Finset (Fin n)) : | |
| favg (fun c : Clause n k => if c.1.1 β W then (1:β) else 0) = | |
| (W.card.choose k : β)/(n.choose k) := by | |
| have he0 := favg_support (fun s : {s : Finset (Fin n) // s.card = k} => | |
| if s.val β W then (1:β) else 0) | |
| rw [he0] | |
| unfold favg | |
| rw [support_card, Finset.sum_boole] | |
| congr 1 | |
| have he : {s : {s : Finset (Fin n) // s.card = k} // s.1 β W} β | |
| {s : Finset (Fin n) // s β W β§ s.card = k} := | |
| { toFun := fun s => β¨s.1.1,s.2,s.1.2β© | |
| invFun := fun s => β¨β¨s.1,s.2.2β©,s.2.1β© | |
| left_inv := fun _ => rfl | |
| right_inv := fun _ => rfl } | |
| have hc := Fintype.card_congr he | |
| rw [Fintype.card_of_subtype (W.powersetCard k) (by intro s; simp)] at hc | |
| simpa only [Fintype.card_subtype, Finset.card_powersetCard] using congrArg (fun x : β => (x:β)) hc | |
| lemma containing_support_bound {n k : β} (hkn : k β€ n) (W : Finset (Fin n)) : | |
| favg (fun c : Clause n k => if c.1.1 β W then (1:β) else 0) β€ | |
| ((W.card : β)/n)^k := by | |
| rw [containing_support_probability] | |
| have hb : W.card β€ n := (Finset.card_le_univ W).trans_eq (Fintype.card_fin n) | |
| have hh := mul_le_mul_of_nonneg_left (killRatio_le_density_pow hb hkn) | |
| (show (0:β) β€ 2^k by positivity) | |
| have he1 : (2:β)^k*killRatio n W.card k = (W.card.choose k : β)/(n.choose k) := by | |
| unfold killRatio | |
| field_simp | |
| have he2 : (2:β)^k*((W.card:β)/(2*n))^k = ((W.card:β)/n)^k := by | |
| rw [β mul_pow] | |
| congr 1 | |
| field_simp | |
| rw [he1,he2] at hh | |
| exact hh | |
| lemma favg_pi_on.{u_1, u_2} {ΞΉ : Type u_1} {Ξ± : Type u_2} [Fintype ΞΉ] [DecidableEq ΞΉ] [Fintype Ξ±] [Nonempty Ξ±] | |
| (I : Finset ΞΉ) (f : Ξ± β β) : | |
| favg (fun w : ΞΉ β Ξ± => β i β I, f (w i)) = (favg f)^I.card := by | |
| have he (w : ΞΉ β Ξ±) : (β i β I, f (w i)) = β i, if i β I then f (w i) else 1 := by | |
| symm | |
| rw [β Finset.prod_filter] | |
| congr 1 | |
| ext i | |
| simp | |
| simp only [he] | |
| change favg (fun w : ΞΉ β Ξ± => β i, (fun i a => if i β I then f a else 1) i (w i)) = _ | |
| rw [favg_pi_product (fun i a => if i β I then f a else 1)] | |
| have hh (i : ΞΉ) : favg (fun a => if i β I then f a else 1) = if i β I then favg f else 1 := by | |
| split_ifs <;> simp [favg_const] | |
| simp only [hh] | |
| rw [β Finset.prod_filter] | |
| have he' : Finset.univ.filter (fun i => i β I) = I := by ext i; simp | |
| rw [he', Finset.prod_const] | |
| lemma hall_union_pointwise {n k m : β} (w : Fin m β Clause n k) : | |
| (if Β¬finiteSAT w m then (1:β) else 0) β€ | |
| β W : Finset (Fin n), β I β (Finset.univ : Finset (Fin m)).powersetCard (W.card+1), | |
| β i β I, if (w i).1.1 β W then (1:β) else 0 := by | |
| have hn (W : Finset (Fin n)) (I : Finset (Fin m)) : | |
| 0 β€ β i β I, if (w i).1.1 β W then (1:β) else 0 := by positivity | |
| by_cases hw : finiteSAT w m | |
| Β· rw [ite_eq_right (not_not.mpr hw)] | |
| exact Finset.sum_nonneg (fun W _ => Finset.sum_nonneg (fun I _ => hn W I)) | |
| Β· rw [ite_eq_left hw] | |
| obtain β¨W,I,hI,hwIβ© := deficient_witness w hw | |
| have hi : I β (Finset.univ : Finset (Fin m)).powersetCard (W.card+1) := by simp [hI] | |
| calc | |
| 1 = β i β I, if (w i).1.1 β W then (1:β) else 0 := by | |
| symm | |
| apply Finset.prod_eq_one | |
| intro i hi | |
| simp [hwI i hi] | |
| _ β€ β J β (Finset.univ : Finset (Fin m)).powersetCard (W.card+1), | |
| β i β J, if (w i).1.1 β W then (1:β) else 0 := | |
| Finset.single_le_sum (fun J _ => hn W J) hi | |
| _ β€ _ := Finset.single_le_sum | |
| (f := fun W : Finset (Fin n) => β I β (Finset.univ : Finset (Fin m)).powersetCard (W.card+1), | |
| β i β I, if (w i).1.1 β W then (1:β) else 0) | |
| (fun W _ => Finset.sum_nonneg (fun I _ => hn W I)) (Finset.mem_univ W) | |
| lemma hall_term_bound {n m t : β} (hn : 0 < n) (htn : t β€ n) {a : β} | |
| (ha : 0 β€ a) (hm : (m:β) β€ a*n) : | |
| (n.choose t : β)*(m.choose (t+1) : β)*((t:β)/n)^(2*(t+1)) β€ | |
| a*(Real.exp 2*a)^t := by | |
| have hn' : (0:β) < n := by exact_mod_cast hn | |
| have hn0 : (n:β) β 0 := ne_of_gt hn' | |
| have ht : (0:β) β€ t := by positivity | |
| have htn' : (t:β)/n β€ 1 := (div_le_one hn').mpr (by exact_mod_cast htn) | |
| have hmn : (m:β)/n β€ a := (div_le_iffβ hn').mpr hm | |
| have hfac : (0:β) < t.factorial := by positivity | |
| have hfac' : (0:β) < (t+1).factorial := by positivity | |
| calc | |
| _ β€ ((n:β)^t/t.factorial)*((m:β)^(t+1)/(t+1).factorial)*((t:β)/n)^(2*(t+1)) := by | |
| gcongr | |
| Β· exact Nat.choose_le_pow_div t n | |
| Β· exact Nat.choose_le_pow_div (t+1) m | |
| _ = ((m:β)/n)^(t+1)*((t:β)/n)* | |
| ((t:β)^t/t.factorial)*((t:β)^(t+1)/(t+1).factorial) := by | |
| rw [show 2*(t+1) = t+t+2 by omega] | |
| simp only [pow_add, pow_succ, div_pow] | |
| field_simp | |
| _ β€ a^(t+1)*1*(Real.exp t)*(Real.exp t) := by | |
| gcongr | |
| Β· exact Real.pow_div_factorial_le_exp t ht t | |
| Β· exact Real.pow_div_factorial_le_exp t ht (t+1) | |
| _ = a*(Real.exp 2*a)^t := by | |
| rw [mul_one, mul_assoc, β Real.exp_add, | |
| show (t:β)+(t:β) = (t:β)*2 by ring, Real.exp_nat_mul, mul_pow, pow_succ] | |
| ring | |
| lemma finite_geometric_half {r : β} (hr : 0 β€ r) (hr1 : r β€ 1/2) (N : β) : | |
| (β t β Finset.range N, r^t) β€ 2 := by | |
| have hn : βrβ < 1 := by rw [Real.norm_eq_abs, abs_of_nonneg hr]; linarith | |
| calc | |
| _ β€ β' t : β, r^t := (summable_geometric_of_norm_lt_one hn).sum_le_tsum _ | |
| (fun t _ => pow_nonneg hr t) | |
| _ = (1-r)β»ΒΉ := tsum_geometric_of_norm_lt_one hn | |
| _ β€ 2 := by | |
| rw [inv_eq_one_div] | |
| apply (div_le_iffβ (by linarith)).mpr | |
| linarith | |
| lemma hall_sum_bound {n m : β} (hn : 0 < n) {a : β} (ha : 0 β€ a) | |
| (ha' : Real.exp 2*a β€ 1/2) (hm : (m:β) β€ a*n) : | |
| (β t β Finset.range (n+1), (n.choose t : β)*(m.choose (t+1) : β)* | |
| ((t:β)/n)^(2*(t+1))) β€ 2*a := by | |
| calc | |
| _ β€ β t β Finset.range (n+1), a*(Real.exp 2*a)^t := by | |
| apply Finset.sum_le_sum | |
| intro t ht | |
| exact hall_term_bound hn (by have := Finset.mem_range.mp ht; omega) ha hm | |
| _ = a*(β t β Finset.range (n+1), (Real.exp 2*a)^t) := by rw [Finset.mul_sum] | |
| _ β€ a*2 := mul_le_mul_of_nonneg_left (finite_geometric_half (by positivity) ha' _) ha | |
| _ = _ := by ring | |
| lemma hall_probability_bound {n k m : β} (hk : 2 β€ k) (hkn : k β€ n) | |
| {a : β} (ha : 0 β€ a) (ha' : Real.exp 2*a β€ 1/2) (hm : (m:β) β€ a*n) : | |
| favg (fun w : Fin m β Clause n k => if Β¬finiteSAT w m then (1:β) else 0) β€ 2*a := by | |
| let := clause_nonempty n k hkn | |
| have hn : 0 < n := by omega | |
| have hn' : (0:β) < n := by exact_mod_cast hn | |
| have hi (W : Finset (Fin n)) (I : Finset (Fin m)) | |
| (hI : I β (Finset.univ : Finset (Fin m)).powersetCard (W.card+1)) : | |
| favg (fun w : Fin m β Clause n k => β i β I, | |
| if (w i).1.1 β W then (1:β) else 0) β€ ((W.card:β)/n)^(2*(W.card+1)) := by | |
| rw [favg_pi_on I (fun c : Clause n k => if c.1.1 β W then (1:β) else 0)] | |
| have hic := (Finset.mem_powersetCard.mp hI).2 | |
| rw [hic, pow_mul] | |
| apply pow_le_pow_leftβ (favg_nonneg (fun _ => by positivity)) | |
| apply (containing_support_bound hkn W).trans | |
| have hr : (W.card:β)/n β€ 1 := (div_le_one hn').mpr (by exact_mod_cast (show W.card β€ n by simpa using Finset.card_le_univ W)) | |
| exact pow_le_pow_of_le_one (by positivity) hr hk | |
| calc | |
| _ β€ favg (fun w : Fin m β Clause n k => | |
| β W : Finset (Fin n), β I β (Finset.univ : Finset (Fin m)).powersetCard (W.card+1), | |
| β i β I, if (w i).1.1 β W then (1:β) else 0) := favg_mono hall_union_pointwise | |
| _ = β W : Finset (Fin n), β I β (Finset.univ : Finset (Fin m)).powersetCard (W.card+1), | |
| favg (fun w : Fin m β Clause n k => | |
| β i β I, if (w i).1.1 β W then (1:β) else 0) := by | |
| rw [favg_sum] | |
| apply Finset.sum_congr rfl | |
| intro W _ | |
| exact favg_sum _ _ | |
| _ β€ β W : Finset (Fin n), | |
| (m.choose (W.card+1):β)*((W.card:β)/n)^(2*(W.card+1)) := by | |
| apply Finset.sum_le_sum | |
| intro W _ | |
| calc | |
| _ β€ β I β (Finset.univ : Finset (Fin m)).powersetCard (W.card+1), | |
| ((W.card:β)/n)^(2*(W.card+1)) := Finset.sum_le_sum (hi W) | |
| _ = _ := by simp | |
| _ = β t β Finset.range (n+1), (n.choose t:β)*(m.choose (t+1):β)* | |
| ((t:β)/n)^(2*(t+1)) := by | |
| have he : (Finset.univ : Finset (Finset (Fin n))) = | |
| (Finset.univ : Finset (Fin n)).powerset := by ext W; simp | |
| rw [he,Finset.sum_powerset_apply_card (fun t : β => | |
| (m.choose (t+1):β)*((t:β)/n)^(2*(t+1)))] | |
| simp only [Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_assoc] | |
| _ β€ 2*a := hall_sum_bound hn ha ha' hm | |
| end RandomKSAT | |
| end | |
| end OAI | |