math / data /lean /OAI /Probability /SATVariance /FirstFailure.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
6.16 kB
import OAI.Probability.SATVariance.ClauseCombinatorics
namespace OAI
noncomputable section
open MeasureTheory ProbabilityTheory
namespace RandomKSAT
open scoped Classical ENNReal
lemma prefixSAT_zero {n k : β„•} (Ο‰ : Stream n k) : PrefixSAT Ο‰ 0 :=
⟨fun _ => false, fun _ hi => False.elim (Nat.not_lt_zero _ hi)⟩
lemma prefixSAT_mono {n k : β„•} {Ο‰ : Stream n k} {m t : β„•}
(h : m ≀ t) : PrefixSAT Ο‰ t β†’ PrefixSAT Ο‰ m := by
rintro ⟨a, ha⟩
exact ⟨a, fun i hi => ha i (hi.trans_le h)⟩
lemma lt_firstFailure_iff {n k : β„•} (Ο‰ : Stream n k) (m : β„•) :
(m : β„•βˆž) < firstFailure Ο‰ ↔ PrefixSAT Ο‰ m := by
constructor
Β· intro hm
by_contra hn
exact (not_le_of_gt hm) (sInf_le ⟨m, hn, rfl⟩)
Β· intro hm
have hle : ((m + 1 : β„•) : β„•βˆž) ≀ firstFailure Ο‰ := by
apply le_sInf
rintro _ ⟨t, ht, rfl⟩
have hmt : m < t := by
by_contra h
exact ht (prefixSAT_mono (Nat.le_of_not_gt h) hm)
exact ENat.natCast_le_natCast.mpr (Nat.succ_le_of_lt hmt)
exact lt_of_lt_of_le (by exact_mod_cast Nat.lt_succ_self m) hle
lemma firstFailure_le_iff {n k : β„•} (Ο‰ : Stream n k) (m : β„•) :
firstFailure Ο‰ ≀ m ↔ Β¬ PrefixSAT Ο‰ m := by
rw [← not_lt, lt_firstFailure_iff]
lemma firstFailure_pos {n k : β„•} (Ο‰ : Stream n k) : 0 < firstFailure Ο‰ := by
exact (lt_firstFailure_iff Ο‰ 0).mpr (prefixSAT_zero Ο‰)
lemma assignment_survival {n k : β„•} (hkn : k ≀ n) (a : Assignment n) (m : β„•) :
streamLaw n k {Ο‰ | βˆ€ i < m, Satisfies (Ο‰ i) a} =
(1 - ((2 : ℝβ‰₯0∞) ^ k)⁻¹) ^ m := by
let := clauseLaw_probability n k hkn
have he : {Ο‰ : Stream n k | βˆ€ i < m, Satisfies (Ο‰ i) a} =
Set.pi (Finset.range m) (fun _ => {c : Clause n k | Satisfies c a}) := by
ext Ο‰
simp
rw [he, streamLaw, Measure.infinitePi_pi]
Β· simp [clauseLaw_satisfies hkn]
Β· intro i _
exact (Set.toFinite _).measurableSet
lemma first_moment_tail {n k : β„•} (hkn : k ≀ n) (m : β„•) :
streamLaw n k {Ο‰ | (m : β„•βˆž) < firstFailure Ο‰} ≀
(2 : ℝβ‰₯0∞) ^ n * (1 - ((2 : ℝβ‰₯0∞) ^ k)⁻¹) ^ m := by
have he : {Ο‰ : Stream n k | (m : β„•βˆž) < firstFailure Ο‰} =
⋃ a : Assignment n, {Ο‰ | βˆ€ i < m, Satisfies (Ο‰ i) a} := by
ext Ο‰
simp [lt_firstFailure_iff, PrefixSAT]
rw [he]
calc
_ ≀ βˆ‘ a : Assignment n, streamLaw n k {Ο‰ | βˆ€ i < m, Satisfies (Ο‰ i) a} :=
measure_iUnion_fintype_le _ _
_ = _ := by simp [assignment_survival hkn]
lemma measurableSet_prefixSAT (n k m : β„•) :
MeasurableSet {Ο‰ : Stream n k | PrefixSAT Ο‰ m} := by
simp only [PrefixSAT, Set.ofPred_exists, Set.ofPred_forall]
apply MeasurableSet.iUnion
intro a
apply MeasurableSet.iInter
intro i
apply MeasurableSet.iInter
intro _
exact (Set.toFinite {c : Clause n k | Satisfies c a}).measurableSet.preimage
(measurable_pi_apply i)
lemma firstFailure_eq_succ_iff {n k : β„•} (Ο‰ : Stream n k) (m : β„•) :
firstFailure Ο‰ = (m + 1 : β„•) ↔ PrefixSAT Ο‰ m ∧ Β¬ PrefixSAT Ο‰ (m + 1) := by
rw [← lt_firstFailure_iff, ← firstFailure_le_iff]
constructor
Β· intro h
rw [h]
exact ⟨ENat.natCast_lt_natCast.mpr (Nat.lt_succ_self m), le_rfl⟩
Β· rintro ⟨h₁, hβ‚‚βŸ©
apply le_antisymm hβ‚‚
exact (ENat.natCast_add_one_le_iff).mpr h₁
lemma measurable_firstFailure (n k : β„•) :
Measurable (firstFailure : Stream n k β†’ β„•βˆž) := by
apply ENat.measurable_iff.mpr
intro m
cases m with
| zero =>
have he : (firstFailure : Stream n k β†’ β„•βˆž) ⁻¹' {0} = βˆ… := by
ext Ο‰
simp only [Set.mem_preimage, Set.mem_singleton_iff, Set.mem_empty_iff_false, iff_false]
exact ne_of_gt (firstFailure_pos Ο‰)
simpa only [Nat.cast_zero, he] using MeasurableSet.empty
| succ m =>
have he : (firstFailure : Stream n k β†’ β„•βˆž) ⁻¹' {↑(m + 1)} =
{Ο‰ | PrefixSAT Ο‰ m} ∩ {Ο‰ | PrefixSAT Ο‰ (m + 1)}ᢜ := by
ext Ο‰
exact firstFailure_eq_succ_iff Ο‰ m
rw [he]
exact (measurableSet_prefixSAT n k m).inter (measurableSet_prefixSAT n k (m+1)).compl
lemma measurable_H (n k : β„•) : Measurable (H : Stream n k β†’ ℝ) :=
(measurable_of_countable (fun x : β„•βˆž => (x.toNat : ℝ))).comp (measurable_firstFailure n k)
lemma measurable_T (n k : β„•) (B : ℝ) : Measurable (T B : Stream n k β†’ ℝ) :=
(measurable_of_countable (fun x : β„•βˆž => ((min x (cap n B : β„•βˆž)).toNat : ℝ))).comp
(measurable_firstFailure n k)
lemma survival_rate_lt_one (k : β„•) : (1 - ((2 : ℝβ‰₯0∞) ^ k)⁻¹) < 1 := by
apply ENNReal.sub_lt_self (by simp) (by simp)
exact ne_of_gt (ENNReal.inv_pos.mpr (by finiteness))
lemma firstFailure_finite_ae {n k : β„•} (hkn : k ≀ n) :
βˆ€α΅ Ο‰ βˆ‚streamLaw n k, firstFailure Ο‰ < ⊀ := by
have ht : Filter.Tendsto (fun m : β„• =>
(2 : ℝβ‰₯0∞) ^ n * (1 - ((2 : ℝβ‰₯0∞) ^ k)⁻¹) ^ m) Filter.atTop (nhds 0) := by
simpa using ENNReal.Tendsto.const_mul
(ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one (survival_rate_lt_one k))
(Or.inr (by finiteness : (2 : ℝβ‰₯0∞) ^ n β‰  ⊀))
rw [ae_iff]
apply le_antisymm _ bot_le
apply ge_of_tendsto ht
apply Filter.Eventually.of_forall
intro m
apply le_trans (measure_mono ?_) (first_moment_tail hkn m)
intro ω hω
have htop : firstFailure Ο‰ = ⊀ := top_unique (not_lt.mp hΟ‰)
change (m : β„•βˆž) < firstFailure Ο‰
rw [htop]
exact ENat.natCast_lt_top m
lemma T_nonneg {n k : β„•} (B : ℝ) (Ο‰ : Stream n k) : 0 ≀ T B Ο‰ := by
unfold T
positivity
lemma T_le_cap {n k : β„•} (B : ℝ) (Ο‰ : Stream n k) : T B Ο‰ ≀ cap n B := by
unfold T
exact_mod_cast ENat.toNat_le_of_le_natCast (min_le_right (firstFailure Ο‰) (cap n B : β„•βˆž))
lemma T_memLp {n k : β„•} (hkn : k ≀ n) (B : ℝ) (p : ℝβ‰₯0∞) :
MemLp (T B : Stream n k β†’ ℝ) p (streamLaw n k) := by
let := streamLaw_probability n k hkn
apply MemLp.of_bound (measurable_T n k B).aestronglyMeasurable (cap n B)
filter_upwards [] with Ο‰
rw [Real.norm_eq_abs, abs_of_nonneg (T_nonneg B Ο‰)]
exact T_le_cap B Ο‰
end RandomKSAT
end
end OAI