Download data/lean/OAI/Probability/RandomSAT/Transfer.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 18.2 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/RandomSAT/Transfer.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/RandomSAT/Transfer.lean
-
curl -L -o Transfer.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/RandomSAT/Transfer.lean
18.2 kB
| import OAI.Probability.RandomSAT.Interpolation | |
| namespace OAI | |
| /-! | |
| The exact probability of distinct variables, birthday bounds, and deletion and | |
| thinning comparisons transfer auxiliary probabilities to the proper-clause law. | |
| -/ | |
| namespace FixedClauseThreshold | |
| open Finset | |
| noncomputable section | |
| attribute [local instance] Classical.propDecidable | |
| def properFraction (n k : β) : β := (n.descFactorial k : β) / (n : β)^k | |
| theorem card_injective_lists (n k : β) : | |
| Fintype.card {f : Fin k β Fin n // Function.Injective f} = n.descFactorial k := by | |
| rw [Fintype.card_congr (Equiv.subtypeInjectiveEquivEmbedding (Fin k) (Fin n)), | |
| Fintype.card_embedding_eq, Fintype.card_fin, Fintype.card_fin] | |
| theorem properFraction_probability (n k : β) : | |
| properFraction n k = uniformProbability (fun f : Fin k β Fin n => Function.Injective f) := by | |
| unfold properFraction uniformProbability | |
| simp only [β Nat.card_eq_fintype_card] | |
| simp only [Nat.card_eq_fintype_card, card_injective_lists, Fintype.card_fun, | |
| Fintype.card_fin, Nat.cast_pow] | |
| theorem properFraction_nonneg (n k : β) : 0 β€ properFraction n k := by | |
| unfold properFraction | |
| positivity | |
| theorem properFraction_le_one (n k : β) : properFraction n k β€ 1 := by | |
| rw [properFraction_probability] | |
| exact uniformProbability_le_one _ | |
| theorem repetition_count_mono {b n k : β} (hbn : b β€ n) : | |
| (b : β)^k - b.descFactorial k β€ (n : β)^k - n.descFactorial k := by | |
| let e : {f : Fin k β Fin b // Β¬ Function.Injective f} βͺ | |
| {f : Fin k β Fin n // Β¬ Function.Injective f} := { | |
| toFun := fun f => β¨fun i => Fin.castLE hbn (f.val i), by | |
| intro hinj | |
| apply f.property | |
| intro i j hij | |
| apply hinj | |
| exact congrArg (Fin.castLE hbn) hijβ© | |
| inj' := by | |
| intro f g h | |
| apply Subtype.ext | |
| funext i | |
| apply Fin.castLE_injective hbn | |
| exact congrFun (congrArg Subtype.val h) i } | |
| have h := Fintype.card_le_of_embedding e | |
| have hf (v : β) : Fintype.card {f : Fin k β Fin v // Β¬ Function.Injective f} = | |
| v^k - v.descFactorial k := by | |
| simp only [Fintype.card_subtype_compl, card_injective_lists, Fintype.card_fun, Fintype.card_fin] | |
| have hd (v : β) : v.descFactorial k β€ v^k := by | |
| have h := Fintype.card_subtype_le (fun f : Fin k β Fin v => Function.Injective f) | |
| simpa only [card_injective_lists, Fintype.card_fun, Fintype.card_fin] using h | |
| rw [hf, hf] at h | |
| have h' := (Nat.cast_le (Ξ± := β)).mpr h | |
| simpa only [Nat.cast_sub (hd _), Nat.cast_pow] using h' | |
| theorem properFraction_mul_kill {b n k : β} (hkn : k β€ n) (hn : 0 < n) : | |
| properFraction n k * killFraction b n k = | |
| (b.descFactorial k : β) / ((2 : β)^k * (n : β)^k) := by | |
| have hc : (n.choose k : β) β 0 := by exact_mod_cast Nat.ne_of_gt (Nat.choose_pos hkn) | |
| have hn' : (n : β) β 0 := by exact_mod_cast Nat.ne_of_gt hn | |
| unfold properFraction killFraction | |
| rw [Nat.descFactorial_eq_factorial_mul_choose n k, Nat.descFactorial_eq_factorial_mul_choose b k] | |
| push_cast | |
| field_simp | |
| theorem auxiliary_kill_le_repetition {b n k : β} (hbn : b β€ n) (hkn : k β€ n) | |
| (hn : 0 < n) : | |
| ((b : β) / (2 * n))^k β€ 1 - properFraction n k + | |
| properFraction n k * killFraction b n k := by | |
| have hn' : (0 : β) < n := by exact_mod_cast hn | |
| have hcount := repetition_count_mono (k := k) hbn | |
| have hq := properFraction_le_one n k | |
| have hden : (0 : β) < (2 : β)^k * (n : β)^k := by positivity | |
| have hp : (1 : β) β€ 2^k := one_le_powβ (by norm_num) | |
| rw [properFraction_mul_kill hkn hn] | |
| unfold properFraction at hq β’ | |
| rw [div_le_one (by positivity)] at hq | |
| rw [div_pow, mul_pow] | |
| have hnonneg : 0 β€ (n : β)^k - n.descFactorial k := sub_nonneg.mpr hq | |
| have hm := mul_le_mul_of_nonneg_right hp hnonneg | |
| have hd : (b : β)^k - b.descFactorial k β€ | |
| (2 : β)^k * ((n : β)^k - n.descFactorial k) := by nlinarith | |
| have hdiv := div_le_div_of_nonneg_right hd hden.le | |
| have he : (2 : β)^k * ((n : β)^k - n.descFactorial k) / | |
| ((2 : β)^k * (n : β)^k) = 1 - (n.descFactorial k : β) / (n : β)^k := by | |
| field_simp | |
| rw [he, sub_div] at hdiv | |
| linarith | |
| theorem clauseAverage_alive {n k : β} (hkn : k β€ n) (S : Finset (Assignment n)) : | |
| clauseAverage k alive S = alive S * (1 - killFraction (forcedVariables S).card n k) := by | |
| by_cases hS : S.Nonempty | |
| Β· have h := singleUNSAT_eq hkn S | |
| have he : (uniformProbability (fun C : ProperClause n k => KillsSolutions S C)) = | |
| killingProbability k S := by | |
| apply uniformProbability_congr | |
| exact fun _ => (and_iff_right hS).symm | |
| rw [he, killingProbability_of_nonempty S hS] at h | |
| change killFraction _ _ _ = 1 - clauseAverage k alive S at h | |
| simp only [alive, ite_eq_left hS, one_mul] | |
| linarith | |
| Β· have he : S = β := Finset.not_nonempty_iff_eq_empty.mp hS | |
| subst S | |
| simp [clauseAverage, addClause, alive_empty, uniformMean_zero] | |
| theorem auxiliaryAverage_le_proper {n k : β} (hn : 0 < n) (hkn : k β€ n) : | |
| auxiliaryAverage k alive β€ clauseAverage (n := n) k alive := by | |
| intro S | |
| rw [auxiliaryAverage_alive hn, clauseAverage_alive hkn] | |
| apply mul_le_mul_of_nonneg_left _ (alive_nonneg S) | |
| apply sub_le_sub_left | |
| have hb : (forcedVariables S).card β€ n := by simpa using Finset.card_le_univ (forcedVariables S) | |
| have h := killFraction_le_pow hb hkn hn | |
| simpa only [forcedFraction, div_mul_eq_div_div_swap] using h | |
| theorem scaled_proper_le_auxiliaryAverage {n k : β} (hn : 0 < n) (hkn : k β€ n) : | |
| (fun S => properFraction n k * clauseAverage k alive S) β€ auxiliaryAverage (n := n) k alive := by | |
| intro S | |
| change properFraction n k * clauseAverage k alive S β€ auxiliaryAverage k alive S | |
| rw [auxiliaryAverage_alive hn, clauseAverage_alive hkn] | |
| have hb : (forcedVariables S).card β€ n := by simpa using Finset.card_le_univ (forcedVariables S) | |
| have h := auxiliary_kill_le_repetition hb hkn hn | |
| have hh : properFraction n k * (1 - killFraction (forcedVariables S).card n k) β€ | |
| 1 - (forcedFraction S / 2)^k := by | |
| unfold forcedFraction | |
| rw [div_div] | |
| rw [mul_comm (n : β) 2] | |
| linarith | |
| have hmul := mul_le_mul_of_nonneg_left hh (alive_nonneg S) | |
| nlinarith | |
| theorem auxiliaryProbability_le_proper {n k : β} (hn : 0 < n) (hkn : k β€ n) (m : β) : | |
| auxiliaryProbability n k m β€ properSATProbability n k m := by | |
| rw [properSATProbability_eq_survival] | |
| exact iterate_compare_of_commute (clauseAverage k) (auxiliaryAverage k) | |
| (fun _ _ h => finiteClauseAverage_mono _ h) (fun _ _ h => finiteClauseAverage_mono _ h) | |
| (finiteClauseAverage_commute _ _) (auxiliaryAverage_le_proper hn hkn) m Finset.univ | |
| theorem proper_scaled_le_auxiliaryProbability {n k : β} (hn : 0 < n) (hkn : k β€ n) (m : β) : | |
| (properFraction n k)^m * properSATProbability n k m β€ auxiliaryProbability n k m := by | |
| have hstep := scaled_proper_le_auxiliaryAverage hn hkn | |
| let B : (Finset (Assignment n) β β) β (Finset (Assignment n) β β) := | |
| fun f S => properFraction n k * clauseAverage k f S | |
| have hB : Monotone B := by | |
| intro f g h S | |
| exact mul_le_mul_of_nonneg_left (finiteClauseAverage_mono _ h S) (properFraction_nonneg n k) | |
| have hcomm : Function.Commute (auxiliaryAverage (n := n) k) B := by | |
| intro f | |
| unfold B auxiliaryAverage embeddedAverage | |
| rw [finiteClauseAverage_const_mul] | |
| funext S | |
| congr 1 | |
| exact congrFun (finiteClauseAverage_commute | |
| (fun C : AuxiliaryClause n k => fun Ο => auxiliarySatisfies Ο (embedAuxiliaryClause id C)) | |
| (fun C : ProperClause n k => fun Ο => SatisfiesClause Ο C) f) S | |
| have hit (j : β) (f : Finset (Assignment n) β β) : | |
| B^[j] f = (fun S => (properFraction n k)^j * (clauseAverage k)^[j] f S) := by | |
| induction j with | |
| | zero => funext S; simp | |
| | succ j ih => | |
| rw [Function.iterate_succ_apply', ih] | |
| unfold B clauseAverage | |
| funext S | |
| rw [uniformMean_const_mul] | |
| rw [Function.iterate_succ_apply', pow_succ] | |
| ring | |
| have h := iterate_compare_of_commute (auxiliaryAverage k) B | |
| (fun _ _ h => finiteClauseAverage_mono _ h) hB hcomm hstep m Finset.univ | |
| rw [hit] at h | |
| rw [properSATProbability_eq_survival] | |
| exact h | |
| def repeatPairs (k : β) : β := (k.choose 2 : β) | |
| @[simp] theorem repeatPairs_zero : repeatPairs 0 = 0 := by norm_num [repeatPairs] | |
| theorem repeatPairs_succ (k : β) : repeatPairs (k + 1) = repeatPairs k + k := by | |
| simp only [repeatPairs, Nat.choose_succ_succ, Nat.choose_one_right, Nat.cast_add] | |
| ring | |
| theorem repeatPairs_nonneg (k : β) : 0 β€ repeatPairs k := Nat.cast_nonneg _ | |
| theorem properFraction_succ {n k : β} (hn : 0 < n) (hkn : k β€ n) : | |
| properFraction n (k + 1) = properFraction n k * (1 - (k : β) / n) := by | |
| have hn' : (n : β) β 0 := by exact_mod_cast Nat.ne_of_gt hn | |
| unfold properFraction | |
| rw [Nat.descFactorial_succ, Nat.cast_mul, Nat.cast_sub hkn, pow_succ] | |
| field_simp | |
| theorem properFraction_lower {n k : β} (hn : 0 < n) (hkn : k β€ n) : | |
| 1 - repeatPairs k / n β€ properFraction n k := by | |
| induction k with | |
| | zero => simp [properFraction] | |
| | succ k ih => | |
| have hkn' : k β€ n := by omega | |
| have hi := ih hkn' | |
| have hle := properFraction_le_one n k | |
| have hprod := mul_le_mul_of_nonneg_right hle (show 0 β€ (k : β) / n by positivity) | |
| rw [properFraction_succ hn hkn', repeatPairs_succ, add_div] | |
| nlinarith | |
| theorem auxiliarySurvival_nonneg {n k : β} (m : β) (S : Finset (Assignment n)) : | |
| 0 β€ auxiliarySurvival k m S := by | |
| induction m generalizing S with | |
| | zero => exact alive_nonneg S | |
| | succ m ih => rw [auxiliarySurvival_succ]; exact uniformMean_nonneg (fun _ => ih _) | |
| theorem auxiliarySurvival_le_one {n k : β} (hn : 0 < n) (m : β) (S : Finset (Assignment n)) : | |
| auxiliarySurvival k m S β€ 1 := by | |
| let : NeZero n := β¨Nat.ne_of_gt hnβ© | |
| induction m generalizing S with | |
| | zero => exact alive_le_one S | |
| | succ m ih => | |
| rw [auxiliarySurvival_succ, β uniformMean_const (Ξ± := AuxiliaryClause n k) (1 : β)] | |
| exact uniformMean_mono (fun _ => ih _) | |
| theorem auxiliaryProbability_nonneg (n k m : β) : 0 β€ auxiliaryProbability n k m := | |
| auxiliarySurvival_nonneg _ _ | |
| theorem auxiliaryProbability_le_one {n : β} (hn : 0 < n) (k m : β) : | |
| auxiliaryProbability n k m β€ 1 := auxiliarySurvival_le_one hn _ _ | |
| theorem finite_model_sandwich {n k : β} (hn : 0 < n) (hkn : k β€ n) (m : β) : | |
| (properFraction n k)^m * properSATProbability n k m β€ auxiliaryProbability n k m β§ | |
| auxiliaryProbability n k m β€ | |
| binomialMean (properFraction n k) m (properSATProbability n k) := by | |
| refine β¨proper_scaled_le_auxiliaryProbability hn hkn m, ?_β© | |
| apply (auxiliaryProbability_le_proper hn hkn m).trans | |
| rw [β binomialMean_const (properFraction n k) (properSATProbability n k m) m] | |
| apply binomialMean_mono (properFraction_nonneg n k) (properFraction_le_one n k) | |
| intro d hd | |
| exact properSATProbability_antitone hkn hd | |
| theorem thinned_count_mean_bounds {n k m : β} {L : β} (hn : 0 < n) (hkn : k β€ n) | |
| (hm : (m : β) β€ L * n) : | |
| (m : β) - L * repeatPairs k β€ binomialMean (properFraction n k) m (fun j => (j : β)) β§ | |
| binomialMean (properFraction n k) m (fun j => (j : β)) β€ m := by | |
| rw [binomialMean_id] | |
| have hn' : (0 : β) < n := by exact_mod_cast hn | |
| have hl := properFraction_lower hn hkn | |
| have hu := properFraction_le_one n k | |
| have h1 := mul_le_mul_of_nonneg_left hl (Nat.cast_nonneg m : (0 : β) β€ m) | |
| have h2 := mul_le_mul_of_nonneg_right hm (show 0 β€ repeatPairs k / n by | |
| exact div_nonneg (repeatPairs_nonneg k) hn'.le) | |
| have he : L * n * (repeatPairs k / n) = L * repeatPairs k := by field_simp | |
| rw [he] at h2 | |
| constructor | |
| Β· nlinarith | |
| Β· nlinarith | |
| theorem exp_neg_two_le_one_sub {x : β} (hx0 : 0 β€ x) (hx : x β€ 1 / 2) : | |
| Real.exp (-2 * x) β€ 1 - x := by | |
| have h := Real.add_one_le_exp (2 * x) | |
| have hm := mul_le_mul_of_nonneg_right h (show 0 β€ 1 - x by linarith) | |
| have hh : 1 β€ Real.exp (2 * x) * (1 - x) := by nlinarith | |
| apply (mul_le_mul_iff_rightβ (Real.exp_pos (2 * x))).mp | |
| rw [β Real.exp_add, show 2 * x + -2 * x = 0 by ring, Real.exp_zero] | |
| simpa only [mul_comm] using hh | |
| def transferFactor (k : β) : β := Real.exp (-2 * (capMultiplier k : β) * repeatPairs k) | |
| def transferLower (k : β) : β := transferFactor k / 2 | |
| theorem transferFactor_pos (k : β) : 0 < transferFactor k := Real.exp_pos _ | |
| theorem transferLower_pos (k : β) : 0 < transferLower k := div_pos (transferFactor_pos k) (by norm_num) | |
| theorem properFraction_pow_lower {n k m : β} (hn : 0 < n) (hkn : k β€ n) | |
| (hnrep : 2 * repeatPairs k β€ n) (hm : m β€ mainCap n k) : | |
| transferFactor k β€ (properFraction n k)^m := by | |
| have hn' : (0 : β) < n := by exact_mod_cast hn | |
| have hx0 : 0 β€ repeatPairs k / n := div_nonneg (repeatPairs_nonneg k) hn'.le | |
| have hx : repeatPairs k / n β€ 1 / 2 := (div_le_iffβ hn').mpr (by linarith) | |
| have hbase := (exp_neg_two_le_one_sub hx0 hx).trans (properFraction_lower hn hkn) | |
| have hpow := pow_le_pow_leftβ (Real.exp_pos _).le hbase m | |
| rw [β Real.exp_nat_mul] at hpow | |
| apply le_trans _ hpow | |
| apply Real.exp_le_exp.mpr | |
| have hm' : (m : β) β€ (capMultiplier k : β) * n := by exact_mod_cast hm | |
| have hh := mul_le_mul_of_nonneg_right hm' hx0 | |
| have he : ((capMultiplier k : β) * n) * (repeatPairs k / n) = | |
| (capMultiplier k : β) * repeatPairs k := by field_simp | |
| rw [he] at hh | |
| nlinarith | |
| theorem auxiliaryProbability_center_lower {n k m : β} (hk : 3 β€ k) (hn : k + 1 β€ n) | |
| (hnrep : 2 * repeatPairs k β€ n) (herror : concentrationError n k β€ 1 / 2) | |
| (hgap : (m : β) + fluctuationWindow n k β€ (n : β) * center n k) : | |
| transferLower k β€ auxiliaryProbability n k m := by | |
| have hn0 : 0 < n := by omega | |
| have hn' : (0 : β) < n := by exact_mod_cast hn0 | |
| have hcenter := center_le_capMultiplier (by omega : k β€ n) hn0 | |
| have hm : m β€ mainCap n k := by | |
| have hw := (fluctuationWindow_pos (k := k) hn0).le | |
| have h := mul_le_mul_of_nonneg_left hcenter hn'.le | |
| have : (m : β) β€ (mainCap n k : β) := by | |
| simp only [mainCap, Nat.cast_mul] | |
| nlinarith | |
| exact_mod_cast this | |
| have hprob := properSATProbability_center_lower hk hn hm hgap | |
| have hhalf : (1 / 2 : β) β€ properSATProbability n k m := by linarith | |
| have hmul := mul_le_mul (properFraction_pow_lower hn0 (by omega) hnrep hm) hhalf | |
| (by norm_num : (0 : β) β€ 1 / 2) (properFraction_nonneg n k |> fun h => pow_nonneg h m) | |
| apply le_trans _ (proper_scaled_le_auxiliaryProbability hn0 (by omega) m) | |
| simpa only [transferLower, div_eq_mul_inv, one_mul] using hmul | |
| theorem auxiliaryProbability_center_upper {n k m : β} (hk : 3 β€ k) (hn : k + 1 β€ n) | |
| (hm : m β€ mainCap n k) | |
| (hgap : (n : β) * center n k + fluctuationWindow n k β€ m) : | |
| auxiliaryProbability n k m β€ concentrationError n k := | |
| (auxiliaryProbability_le_proper (by omega) (by omega) m).trans | |
| (properSATProbability_center_upper hk hn hm hgap) | |
| theorem binomialMean_square (p : β) (m : β) : | |
| binomialMean p m (fun j => (j : β)^2) = m * p * (1 - p) + ((m : β) * p)^2 := by | |
| induction m with | |
| | zero => simp [binomialMean] | |
| | succ m ih => | |
| rw [binomialMean] | |
| have he : binomialMean p m (fun j => ((j + 1 : β) : β)^2) = | |
| binomialMean p m (fun j => (j : β)^2) + 2 * ((m : β) * p) + 1 := by | |
| calc | |
| _ = binomialMean p m (fun j => (j : β)^2 + 2 * j + 1) := by | |
| apply binomialMean_congr | |
| intro j _ | |
| push_cast | |
| ring | |
| _ = _ := by | |
| rw [binomialMean_add, binomialMean_add, binomialMean_const_mul, | |
| binomialMean_id, binomialMean_const] | |
| rw [he, ih, Nat.cast_add, Nat.cast_one] | |
| ring | |
| theorem binomialMean_centered_square (p : β) (m : β) : | |
| binomialMean p m (fun j => ((j : β) - (m : β) * p)^2) = (m : β) * p * (1 - p) := by | |
| calc | |
| _ = binomialMean p m (fun j => (j : β)^2 - 2 * ((m : β) * p) * j + ((m : β) * p)^2) := by | |
| apply binomialMean_congr | |
| intro j _ | |
| ring | |
| _ = _ := by | |
| rw [binomialMean_add, binomialMean_sub, binomialMean_const_mul, | |
| binomialMean_const, binomialMean_square, binomialMean_id] | |
| ring | |
| theorem binomialMean_div_const (p c : β) (m : β) (f : β β β) : | |
| binomialMean p m (fun j => f j / c) = binomialMean p m f / c := by | |
| simp only [div_eq_mul_inv, binomialMean_mul_const] | |
| theorem binomialMean_all_success {p : β} (hp0 : 0 β€ p) (hp1 : p β€ 1) | |
| (m : β) (f : β β β) (hf : β j β€ m, 0 β€ f j) : | |
| p^m * f m β€ binomialMean p m f := by | |
| induction m generalizing f with | |
| | zero => simp [binomialMean] | |
| | succ m ih => | |
| rw [binomialMean, pow_succ] | |
| have h0 := binomialMean_nonneg hp0 hp1 (m := m) (f := f) (fun j hj => hf j (by omega)) | |
| have h1 := ih (fun j => f (j + 1)) (fun j hj => hf (j + 1) (by omega)) | |
| have hm := mul_le_mul_of_nonneg_left h1 hp0 | |
| nlinarith [mul_nonneg (sub_nonneg.mpr hp1) h0] | |
| theorem product_lower_two_deviations {ΞΊ x y a b : β} (hΞΊ : 0 β€ ΞΊ) | |
| (hx : 0 β€ x) (hy : 0 β€ y) (ha : 0 β€ a) (hb : 0 β€ b) | |
| (hax : x < 1 β ΞΊ β€ a) (hby : y < 1 β ΞΊ β€ b) : | |
| ΞΊ^2 * (1 - x - y) β€ a * b := by | |
| by_cases hx1 : x < 1 | |
| Β· by_cases hy1 : y < 1 | |
| Β· have hprod := mul_le_mul (hax hx1) (hby hy1) hΞΊ ha | |
| have hle : ΞΊ^2 * (1 - x - y) β€ ΞΊ^2 := | |
| by | |
| have hh : 1 - x - y β€ 1 := by linarith | |
| simpa only [mul_one] using mul_le_mul_of_nonneg_left hh (sq_nonneg ΞΊ) | |
| nlinarith | |
| Β· have hle : ΞΊ^2 * (1 - x - y) β€ 0 := | |
| mul_nonpos_of_nonneg_of_nonpos (sq_nonneg ΞΊ) (by linarith) | |
| exact hle.trans (mul_nonneg ha hb) | |
| Β· have hle : ΞΊ^2 * (1 - x - y) β€ 0 := | |
| mul_nonpos_of_nonneg_of_nonpos (sq_nonneg ΞΊ) (by linarith) | |
| exact hle.trans (mul_nonneg ha hb) | |
| def samplingError (n k : β) : β := | |
| (capMultiplier k : β) * n / (fluctuationWindow n k)^2 | |
| theorem samplingError_nonneg (n k : β) : 0 β€ samplingError n k := by | |
| unfold samplingError | |
| positivity | |
| end | |
| end FixedClauseThreshold | |
| end OAI | |