Download data/lean/OAI/Probability/SATVariance/BlockKilling.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 13.5 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/SATVariance/BlockKilling.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/SATVariance/BlockKilling.lean
-
curl -L -o BlockKilling.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/SATVariance/BlockKilling.lean
13.5 kB
| import OAI.Probability.SATVariance.FrozenReplacement | |
| namespace OAI | |
| noncomputable section | |
| open MeasureTheory ProbabilityTheory | |
| namespace RandomKSAT | |
| open scoped Classical ENNReal | |
| def SetSAT {u s : β} (S : Finset (Assignment u)) (Ο : Stream u s) (g : β) : Prop := | |
| β a β S, β i < g, Satisfies (Ο i) a | |
| def blockKill (u s : β) (S : Finset (Assignment u)) (g : β) : β := | |
| (streamLaw u s {Ο | Β¬ SetSAT S Ο g}).toReal | |
| lemma setSAT_univ {u s : β} (Ο : Stream u s) (g : β) : | |
| SetSAT Finset.univ Ο g β PrefixSAT Ο g := by | |
| simp [SetSAT, PrefixSAT] | |
| lemma measurableSet_setSAT (u s : β) (S : Finset (Assignment u)) (g : β) : | |
| MeasurableSet {Ο : Stream u s | SetSAT S Ο g} := by | |
| simp only [SetSAT, Set.ofPred_exists] | |
| apply MeasurableSet.iUnion | |
| intro a | |
| by_cases ha : a β S | |
| Β· simp only [ha, true_and, Set.ofPred_forall] | |
| apply MeasurableSet.iInter | |
| intro i | |
| apply MeasurableSet.iInter | |
| intro _ | |
| exact (Set.toFinite {c : Clause u s | Satisfies c a}).measurableSet.preimage | |
| (measurable_pi_apply i) | |
| Β· simp only [ha, false_and, Set.ofPred_false] | |
| exact MeasurableSet.empty | |
| lemma blockKill_nonneg (u s : β) (S : Finset (Assignment u)) (g : β) : | |
| 0 β€ blockKill u s S g := ENNReal.toReal_nonneg | |
| lemma blockKill_le_one {u s : β} (hsu : s β€ u) (S : Finset (Assignment u)) (g : β) : | |
| blockKill u s S g β€ 1 := by | |
| let := streamLaw_probability u s hsu | |
| exact measureReal_le_one (ΞΌ := streamLaw u s) | |
| lemma blockKill_empty {u s : β} (hsu : s β€ u) (g : β) : | |
| blockKill u s β g = 1 := by | |
| let := streamLaw_probability u s hsu | |
| simp [blockKill, SetSAT] | |
| lemma blockKill_compl {u s : β} (hsu : s β€ u) (S : Finset (Assignment u)) (g : β) : | |
| blockKill u s S g = 1 - (streamLaw u s {Ο | SetSAT S Ο g}).toReal := by | |
| let := streamLaw_probability u s hsu | |
| have he : {Ο : Stream u s | Β¬ SetSAT S Ο g} = {Ο | SetSAT S Ο g}αΆ := rfl | |
| rw [blockKill, he, measure_compl (measurableSet_setSAT u s S g) (measure_ne_top _ _), | |
| measure_univ, ENNReal.toReal_sub_of_le prob_le_one (by simp), ENNReal.toReal_one] | |
| lemma clauseLaw_kills_toReal {u s : β} {S : Finset (Assignment u)} (hS : S.Nonempty) : | |
| (clauseLaw u s {c | Kills S c}).toReal = killRatio u (frozen S).card s := by | |
| rw [clauseLaw_kills hS] | |
| simp [killRatio, ENNReal.toReal_div, ENNReal.toReal_mul, ENNReal.toReal_pow, mul_comm] | |
| lemma blockKill_one {u s : β} (hsu : s β€ u) {S : Finset (Assignment u)} (hS : S.Nonempty) : | |
| blockKill u s S 1 = killRatio u (frozen S).card s := by | |
| let := clauseLaw_probability u s hsu | |
| have he : {Ο : Stream u s | Β¬ SetSAT S Ο 1} = | |
| Set.pi ({0} : Finset β) (fun _ => {c : Clause u s | Kills S c}) := by | |
| ext Ο | |
| simp [SetSAT, Kills] | |
| rw [blockKill, he, streamLaw, Measure.infinitePi_pi] | |
| Β· simpa using clauseLaw_kills_toReal hS | |
| Β· intro _ _ | |
| exact (Set.toFinite _).measurableSet | |
| lemma blockKill_individual {u s : β} (hsu : s β€ u) {S : Finset (Assignment u)} | |
| (hS : S.Nonempty) (g : β) : | |
| 1 - (1 - killRatio u (frozen S).card s)^g β€ blockKill u s S g := by | |
| let := clauseLaw_probability u s hsu | |
| let := streamLaw_probability u s hsu | |
| have hsub : {Ο : Stream u s | SetSAT S Ο g} β | |
| Set.pi (Finset.range g) (fun _ => {c : Clause u s | Β¬ Kills S c}) := by | |
| rintro Ο β¨a, ha, hΟβ© i hi hk | |
| exact hk a ha (hΟ i (Finset.mem_range.mp hi)) | |
| have ht := measure_mono (ΞΌ := streamLaw u s) hsub | |
| rw [streamLaw, Measure.infinitePi_pi _ (fun _ _ => (Set.toFinite _).measurableSet)] at ht | |
| have he : clauseLaw u s {c | Β¬ Kills S c} = 1-clauseLaw u s {c | Kills S c} := by | |
| exact (measure_compl (Set.toFinite _).measurableSet (measure_ne_top _ _)).trans | |
| (by rw [measure_univ]; rfl) | |
| simp only [he, Finset.prod_const, Finset.card_range] at ht | |
| have ht' := ENNReal.toReal_mono (by finiteness) ht | |
| rw [ENNReal.toReal_pow, ENNReal.toReal_sub_of_le prob_le_one (by simp), | |
| ENNReal.toReal_one, clauseLaw_kills_toReal hS] at ht' | |
| rw [blockKill_compl hsu] | |
| change ((streamLaw u s) {Ο | SetSAT S Ο g}).toReal β€ _ at ht' | |
| linarith | |
| lemma set_survival_le {u s : β} (hsu : s β€ u) (S : Finset (Assignment u)) (g : β) : | |
| streamLaw u s {Ο | SetSAT S Ο g} β€ | |
| (S.card : ββ₯0β) * (1-((2 : ββ₯0β)^s)β»ΒΉ)^g := by | |
| have he : {Ο : Stream u s | SetSAT S Ο g} = | |
| β a : S, {Ο | β i < g, Satisfies (Ο i) a} := by | |
| ext Ο | |
| simp [SetSAT] | |
| rw [he] | |
| apply (measure_iUnion_fintype_le _ _).trans_eq | |
| simp [assignment_survival hsu] | |
| lemma frozen_card_le {u : β} (S : Finset (Assignment u)) : (frozen S).card β€ u := by | |
| simpa using Finset.card_le_univ (frozen S) | |
| lemma rate_toReal (s : β) : | |
| (1-((2 : ββ₯0β)^s)β»ΒΉ).toReal = 1-((2 : β)^s)β»ΒΉ := by | |
| rw [ENNReal.toReal_sub_of_le (ENNReal.inv_le_one.mpr (one_le_powβ (by norm_num))) | |
| (by simp)] | |
| simp | |
| lemma real_rate_nonneg (s : β) : 0 β€ 1-((2 : β)^s)β»ΒΉ := by | |
| exact sub_nonneg.mpr ((inv_le_oneβ (by positivity)).mpr (one_le_powβ (by norm_num))) | |
| lemma survival_exp_bound {u s : β} (hsu : s β€ u) (S : Finset (Assignment u)) (g : β) : | |
| (streamLaw u s {Ο | SetSAT S Ο g}).toReal β€ | |
| (S.card : β) * Real.exp (-((2 : β)^s)β»ΒΉ * g) := by | |
| have ht := ENNReal.toReal_mono (by finiteness) (set_survival_le hsu S g) | |
| rw [ENNReal.toReal_mul, ENNReal.toReal_natCast, ENNReal.toReal_pow, rate_toReal] at ht | |
| apply ht.trans | |
| apply mul_le_mul_of_nonneg_left _ (by positivity) | |
| have he : 1-((2 : β)^s)β»ΒΉ β€ Real.exp (-((2 : β)^s)β»ΒΉ) := by | |
| linarith [Real.add_one_le_exp (-((2 : β)^s)β»ΒΉ)] | |
| calc | |
| _ β€ (Real.exp (-((2 : β)^s)β»ΒΉ))^g := pow_le_pow_leftβ (real_rate_nonneg s) he g | |
| _ = _ := by rw [β Real.exp_nat_mul]; congr 1; ring | |
| lemma blockKill_exp_full {u s : β} (hsu : s β€ u) (S : Finset (Assignment u)) (g : β) : | |
| 1 - (2 : β)^u * Real.exp (-((2 : β)^s)β»ΒΉ * g) β€ blockKill u s S g := by | |
| have hScard : (S.card : β) β€ (2 : β)^u := by | |
| exact_mod_cast (by simpa using Finset.card_le_univ S : S.card β€ 2^u) | |
| have ht := (survival_exp_bound hsu S g).trans | |
| (mul_le_mul_of_nonneg_right hScard (Real.exp_nonneg _)) | |
| rw [blockKill_compl hsu] | |
| linarith | |
| lemma blockKill_exp_individual {u s : β} (hu : 0 < u) (hsu : s β€ u) | |
| {S : Finset (Assignment u)} (hS : S.Nonempty) (g : β) : | |
| 1 - Real.exp (-(g : β)*killRatio u (frozen S).card s) β€ blockKill u s S g := by | |
| have hk : killRatio u (frozen S).card s β€ 1 := | |
| (killRatio_le_half_pow hu (frozen_card_le S) hsu).trans | |
| (pow_le_oneβ (by norm_num) (by norm_num)) | |
| have he : 1-killRatio u (frozen S).card s β€ | |
| Real.exp (-killRatio u (frozen S).card s) := by | |
| linarith [Real.add_one_le_exp (-killRatio u (frozen S).card s)] | |
| have ht := pow_le_pow_leftβ (sub_nonneg.mpr hk) he g | |
| rw [β Real.exp_nat_mul] at ht | |
| have hm := blockKill_individual hsu hS g | |
| have hx : (g : β) * (-killRatio u (frozen S).card s) = | |
| -(g : β) * killRatio u (frozen S).card s := by ring | |
| rw [hx] at ht | |
| exact le_trans (sub_le_sub_left ht 1) hm | |
| lemma one_sub_exp_neg_two_mul_ge {h : β} (hβ : 0 β€ h) (hβ : h β€ 1/2) : | |
| h β€ 1-Real.exp (-2*h) := by | |
| have hre : Real.exp (-2*h) β€ (1+2*h)β»ΒΉ := by | |
| have he := Real.add_one_le_exp (2*h) | |
| rw [show -2*h = -(2*h) by ring, Real.exp_neg] | |
| exact inv_antiβ (by positivity) (by linarith) | |
| have hi : (1+2*h)β»ΒΉ β€ 1-h := by | |
| rw [inv_eq_one_div] | |
| apply (div_le_iffβ (by positivity : (0 : β) < 1+2*h)).2 | |
| nlinarith | |
| linarith | |
| lemma blockKill_long {u s g : β} (hu : 0 < u) (hsu : s β€ u) | |
| (hg : (2 : β)^(s+1)*u β€ g) (S : Finset (Assignment u)) : | |
| (1 : β)/3 β€ blockKill u s S g := by | |
| have he : -((2 : β)^s)β»ΒΉ * g β€ -2*u := by | |
| have h2 : (0 : β) < (2 : β)^s := by positivity | |
| rw [pow_succ] at hg | |
| have h := mul_le_mul_of_nonneg_left hg (le_of_lt (inv_pos.mpr h2)) | |
| have hc : ((2 : β)^s)β»ΒΉ * ((2:β)^s*2*u) = 2*u := by field_simp | |
| rw [hc] at h | |
| linarith | |
| have hexp : (2 : β)*Real.exp (-2) β€ 2/3 := by | |
| have ht : (3 : β) β€ Real.exp 2 := by linarith [Real.add_one_le_exp 2] | |
| have hi := inv_antiβ (by norm_num : (0 : β)<3) ht | |
| rw [Real.exp_neg] | |
| linarith | |
| have hh : (2 : β)^u * Real.exp (-2*u) β€ 2/3 := by | |
| have hi : (1 : β) β€ u := hu | |
| calc | |
| _ = (2*Real.exp (-2))^u := by rw [mul_pow, β Real.exp_nat_mul]; congr 2; ring | |
| _ β€ ((2 : β)/3)^u := pow_le_pow_leftβ (by positivity) hexp u | |
| _ β€ ((2 : β)/3)^1 := pow_le_pow_of_le_one (by norm_num) (by norm_num) hi | |
| _ = _ := by norm_num | |
| have hb := blockKill_exp_full hsu S g | |
| have ht := mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr he) | |
| (by positivity : (0 : β) β€ (2:β)^u) | |
| linarith | |
| def replacementK (k : β) : β := ((2 : β)^k * ((k-1 : β) : β))^(k-1) | |
| lemma replacementK_succ (r : β) : replacementK (r+1) = ((2 : β)^(r+1)*r)^r := by | |
| simp [replacementK] | |
| lemma replacement_numeric {u b r g : β} (hr : 2 β€ r) (hbu : b β€ u) | |
| (hru : r+1 β€ u) (hg : 1 β€ g) {R : β} (hR : 0 β€ R) | |
| (hind : 1-Real.exp (-(g : β)*killRatio u b (r+1)) β€ R) | |
| (hlong : (2 : β)^(r+2)*u β€ g β (1 : β)/3 β€ R) : | |
| killRatio u b r - replacementK (r+1)/(g : β)^r β€ R := by | |
| have hrβ : (0 : β) < r := by exact_mod_cast (by omega : 0 < r) | |
| have hgβ : (0 : β) < g := by exact_mod_cast hg | |
| have huβ : (0 : β) < u := by exact_mod_cast (by omega : 0 < u) | |
| have hquarter : killRatio u b r β€ 1/4 := by | |
| apply (killRatio_le_half_pow (by omega) hbu (by omega)).trans | |
| have h := pow_le_pow_of_le_one (by norm_num : (0 : β) β€ 1/2) (by norm_num) hr | |
| norm_num at h β’ | |
| exact h | |
| have hK : (2 : β)*(r+1) β€ (2 : β)^(r+1)*r := by | |
| have h2 : (4 : β) β€ (2 : β)^(r+1) := by | |
| calc | |
| _ = (2 : β)^2 := by norm_num | |
| _ β€ _ := pow_le_pow_rightβ (by norm_num) (by omega) | |
| have hrβ : (1 : β) β€ r := by exact_mod_cast (by omega : 1 β€ r) | |
| nlinarith | |
| rw [replacementK_succ, β div_pow] | |
| by_cases hrb : r+1 β€ b | |
| Β· by_cases hlarge : 2 β€ (g : β)/(r+1) * (killRatio u b r)^((r : β)β»ΒΉ) | |
| Β· have hp := frozen_power (by omega : 1 β€ r) hbu hrb | |
| have hex : ((r : β)+1)/r = 1+(r : β)β»ΒΉ := by field_simp | |
| rw [hex, Real.rpow_add_of_nonneg (killRatio_nonneg u b r) zero_le_one | |
| (by positivity), Real.rpow_one] at hp | |
| have hs : 2*killRatio u b r β€ (g : β)*killRatio u b (r+1) := by | |
| have hβ := mul_le_mul_of_nonneg_left hlarge (killRatio_nonneg u b r) | |
| have hβ := mul_le_mul_of_nonneg_left hp hgβ.le | |
| calc | |
| 2*killRatio u b r = killRatio u b r*2 := by ring | |
| _ β€ killRatio u b r * ((g : β)/(r+1) * (killRatio u b r)^((r : β)β»ΒΉ)) := hβ | |
| _ = (g : β) * (killRatio u b r * (killRatio u b r)^((r : β)β»ΒΉ)/(r+1)) := by ring | |
| _ β€ _ := hβ | |
| have ht := Real.exp_le_exp.mpr (neg_le_neg hs) | |
| simp only [β neg_mul] at ht | |
| have hh := one_sub_exp_neg_two_mul_ge (killRatio_nonneg u b r) (by linarith : | |
| killRatio u b r β€ 1/2) | |
| have herr : 0 β€ ((2:β)^(r+1)*r/g)^r := by positivity | |
| linarith | |
| Β· have hroot : (killRatio u b r)^((r : β)β»ΒΉ) β€ 2*(r+1)/(g : β) := by | |
| apply (le_div_iffβ hgβ).2 | |
| have hh := (not_le.mp hlarge).le | |
| rw [div_mul_eq_mul_div] at hh | |
| have hh' := (div_le_iffβ (by positivity : (0:β)<r+1)).mp hh | |
| linarith | |
| have hbound : killRatio u b r β€ ((2:β)^(r+1)*r/g)^r := by | |
| calc | |
| killRatio u b r = ((killRatio u b r)^((r : β)β»ΒΉ))^r := | |
| (Real.rpow_inv_natCast_pow (killRatio_nonneg u b r) (by omega : r β 0)).symm | |
| _ β€ _ := pow_le_pow_leftβ (Real.rpow_nonneg (killRatio_nonneg u b r) _) | |
| (hroot.trans (div_le_div_of_nonneg_right hK hgβ.le)) r | |
| linarith | |
| Β· by_cases hbr : b < r | |
| Β· rw [killRatio_eq_zero hbr] | |
| have herr : 0 β€ ((2:β)^(r+1)*r/g)^r := by positivity | |
| linarith | |
| Β· have hbr : b = r := by omega | |
| subst b | |
| by_cases hlong' : (2 : β)^(r+2)*u β€ g | |
| Β· have hh := hlong hlong' | |
| have herr : 0 β€ ((2:β)^(r+1)*r/g)^r := by positivity | |
| linarith | |
| Β· have hg' : (g : β) β€ (2 : β)^(r+2)*u := (not_le.mp hlong').le | |
| have hd : (r : β)/(2*u) β€ (2 : β)^(r+1)*r/g := by | |
| apply (div_le_div_iffβ (by positivity) hgβ).2 | |
| rw [show r+2 = (r+1)+1 by omega, pow_succ] at hg' | |
| nlinarith [mul_le_mul_of_nonneg_left hg' hrβ.le] | |
| have hh := (killRatio_le_density_pow hbu (by omega : r β€ u)).trans | |
| (pow_le_pow_leftβ (by positivity) hd r) | |
| linarith | |
| lemma one_replacement {u r g : β} (hr : 2 β€ r) (hru : r+1 β€ u) (hg : 1 β€ g) | |
| (S : Finset (Assignment u)) : | |
| blockKill u r S 1 - replacementK (r+1)/(g : β)^r β€ blockKill u (r+1) S g := by | |
| by_cases hS : S.Nonempty | |
| Β· rw [blockKill_one (by omega) hS] | |
| apply replacement_numeric hr (frozen_card_le S) hru hg (blockKill_nonneg _ _ _ _) | |
| Β· exact blockKill_exp_individual (by omega) hru hS g | |
| Β· intro hlong | |
| apply blockKill_long (by omega) hru _ S | |
| simpa [Nat.add_assoc] using hlong | |
| Β· have he : S = β := Finset.not_nonempty_iff_eq_empty.mp hS | |
| subst S | |
| rw [blockKill_empty (by omega), blockKill_empty hru] | |
| have hK : 0 β€ replacementK (r+1)/(g : β)^r := by | |
| rw [replacementK_succ] | |
| positivity | |
| linarith | |
| end RandomKSAT | |
| end | |
| end OAI | |