File size: 8,034 Bytes
f0f05de | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | import Mathlib
namespace OAI
/-!
Finite union-bound lemmas for the independent random binary codebook argument
in polynomial-code.tex, Lemma `lem:random-segments`.
-/
namespace TreeEdit.BinaryLower
namespace CodeUnionBound
open scoped BigOperators
/-- A finite family whose total cardinality is smaller than the ambient type
cannot cover that type. No probability-space assumptions are required. -/
theorem exists_avoiding_of_sum_card_lt
{Ω I : Type*} [Fintype Ω] [Fintype I]
(bad : I → Finset Ω)
(h : (∑ i, (bad i).card) < Fintype.card Ω) :
∃ ω : Ω, ∀ i : I, ω ∉ bad i := by
classical
by_contra hn
push Not at hn
have hcover : (Finset.univ : Finset Ω) ⊆ Finset.univ.biUnion bad := by
intro ω _
obtain ⟨i, hi⟩ := hn ω
exact Finset.mem_biUnion.mpr ⟨i, Finset.mem_univ _, hi⟩
have hc : Fintype.card Ω ≤ ∑ i, (bad i).card := by
calc
Fintype.card Ω = (Finset.univ : Finset Ω).card := by simp
_ ≤ (Finset.univ.biUnion bad).card := Finset.card_le_card hcover
_ ≤ ∑ i, (bad i).card := Finset.card_biUnion_le
exact (not_lt_of_ge hc) h
/-- The same existence statement in terms of real-valued probability bounds
for the uniform distribution on a nonempty finite ambient type. -/
theorem exists_avoiding_of_probability_bounds
{Ω I : Type*} [Fintype Ω] [Nonempty Ω] [Fintype I]
(bad : I → Finset Ω) (p : I → ℝ)
(hbound : ∀ i, ((bad i).card : ℝ) / Fintype.card Ω ≤ p i)
(hsum : (∑ i, p i) < 1) :
∃ ω : Ω, ∀ i : I, ω ∉ bad i := by
apply exists_avoiding_of_sum_card_lt bad
have hpos : (0 : ℝ) < Fintype.card Ω := by
exact_mod_cast Fintype.card_pos
have hsum' : (∑ i, ((bad i).card : ℝ)) / Fintype.card Ω < 1 := by
rw [Finset.sum_div]
exact (Finset.sum_le_sum fun i _ => hbound i).trans_lt hsum
have hc : (∑ i, ((bad i).card : ℝ)) < Fintype.card Ω := by
simpa using (div_lt_iff₀ hpos).mp hsum'
exact_mod_cast hc
/-- A uniform bad-event estimate needs only a bound on the number of events. -/
theorem exists_avoiding_of_uniform_probability_bound
{Ω I : Type*} [Fintype Ω] [Nonempty Ω] [Fintype I]
(bad : I → Finset Ω) (ε : ℝ)
(hbound : ∀ i, ((bad i).card : ℝ) / Fintype.card Ω ≤ ε)
(hsum : (Fintype.card I : ℝ) * ε < 1) :
∃ ω : Ω, ∀ i : I, ω ∉ bad i := by
apply exists_avoiding_of_probability_bounds bad (fun _ => ε) hbound
simpa using hsum
/-- The uniform criterion with a possibly loose real-valued upper bound on
the number of comparisons. This permits endpoints represented by `Fin (P+1)`
without changing the union-bound argument. -/
theorem exists_avoiding_of_event_count_bound
{Ω I : Type*} [Fintype Ω] [Nonempty Ω] [Fintype I]
(bad : I → Finset Ω) (ε N : ℝ) (hε : 0 ≤ ε)
(hcount : (Fintype.card I : ℝ) ≤ N)
(hbound : ∀ i, ((bad i).card : ℝ) / Fintype.card Ω ≤ ε)
(hsum : N * ε < 1) :
∃ ω : Ω, ∀ i : I, ω ∉ bad i := by
apply exists_avoiding_of_uniform_probability_bound bad ε hbound
exact (mul_le_mul_of_nonneg_right hcount hε).trans_lt hsum
/-- There are at most `K² P³` ordered choices of two codeword labels,
a positive segment length at most `P`, and two starting positions. The
validity conditions only remove comparisons from this ambient index type. -/
abbrev SegmentComparison (K P : ℕ) :=
Fin K × Fin K × Fin P × Fin P × Fin P
theorem card_segmentComparison (K P : ℕ) :
Fintype.card (SegmentComparison K P) = K ^ 2 * P ^ 3 := by
simp only [SegmentComparison, Fintype.card_prod, Fintype.card_fin]
ring
/-- The polynomial number of comparisons is dominated by the twentieth
power appearing after the source's logarithmic segment cutoff. -/
theorem comparison_frequency_lt_one {m p : ℝ}
(hm : 2 ≤ m) (hp : 1 ≤ p) :
m ^ 2 * p ^ 3 / (m * p) ^ 20 < 1 := by
have hm0 : 0 ≤ m := by linarith
have hp0 : 0 ≤ p := by linarith
have hmp : 1 < m * p := by nlinarith
apply (div_lt_one (pow_pos (by linarith : 0 < m * p) 20)).2
calc
m ^ 2 * p ^ 3 ≤ m ^ 3 * p ^ 3 :=
mul_le_mul_of_nonneg_right (pow_le_pow_right₀ (by linarith) (by decide))
(pow_nonneg hp0 3)
_ = (m * p) ^ 3 := (mul_pow m p 3).symm
_ < (m * p) ^ 20 := pow_lt_pow_right₀ hmp (by decide)
/-- A uniform matching-event bound produces one codebook satisfying
every segment comparison simultaneously. -/
theorem exists_codebook_avoiding
{M K P : ℕ} (hM : 2 ≤ M) (hK : K ≤ M) (hP : 1 ≤ P)
(bad : SegmentComparison K P → Finset ((Fin K × Fin P) → Bool))
(hbound : ∀ i,
((bad i).card : ℝ) / (2 : ℝ) ^ (K * P) ≤
1 / ((M : ℝ) * P) ^ 20) :
∃ c : (Fin K × Fin P) → Bool, ∀ i, c ∉ bad i := by
classical
apply exists_avoiding_of_uniform_probability_bound bad
(1 / ((M : ℝ) * P) ^ 20)
· intro i
simpa only [Fintype.card_fun, Fintype.card_prod, Fintype.card_fin,
Fintype.card_bool, Nat.cast_pow, Nat.cast_ofNat] using hbound i
· rw [card_segmentComparison]
push_cast
have hKreal : (K : ℝ) ≤ M := by exact_mod_cast hK
have hMreal : (2 : ℝ) ≤ M := by exact_mod_cast hM
have hPreal : (1 : ℝ) ≤ P := by exact_mod_cast hP
have hden : 0 ≤ 1 / ((M : ℝ) * P) ^ 20 := by positivity
calc
(K : ℝ) ^ 2 * P ^ 3 * (1 / ((M : ℝ) * P) ^ 20) ≤
(M : ℝ) ^ 2 * P ^ 3 * (1 / ((M : ℝ) * P) ^ 20) := by
gcongr
_ = (M : ℝ) ^ 2 * P ^ 3 / ((M : ℝ) * P) ^ 20 := by ring
_ < 1 := comparison_frequency_lt_one hMreal hPreal
/-- The source cutoff converts each `2^(-a/2)` segment-failure estimate
into an inverse sixtieth power of the input length. -/
theorem exponential_bound_of_source_cutoff {m a : ℝ}
(hm : 0 < m) (ha : 120 * Real.logb 2 m ≤ a) :
Real.exp (-a * Real.log 2 / 2) ≤ 1 / m ^ 60 := by
have hlog2 : 0 < Real.log 2 := Real.log_pos (by norm_num)
have hscale : 120 * Real.log m ≤ a * Real.log 2 := by
have h := (mul_le_mul_of_nonneg_right ha hlog2.le)
simpa [Real.logb, div_mul_cancel₀ _ (ne_of_gt hlog2),
mul_assoc] using h
calc
Real.exp (-a * Real.log 2 / 2) ≤ Real.exp (-(60 * Real.log m)) := by
apply Real.exp_le_exp.mpr
linarith
_ = 1 / m ^ 60 := by
have hlog : Real.log (m ^ 60) = 60 * Real.log m := by
simp [Real.log_pow]
rw [← hlog]
rw [Real.exp_neg, Real.exp_log (pow_pos hm 60)]
simp only [one_div]
/-- The slightly larger `(P+1)^3` comparison index used by endpoint-based
formalizations still has total bad probability strictly below one. -/
theorem endpoint_comparison_frequency_lt_one {m : ℝ} (hm : 2 ≤ m) :
m ^ 2 * (m ^ 2 + 1) ^ 3 / m ^ 60 < 1 := by
have hm0 : 0 < m := by linarith
have hm21 : 1 ≤ m ^ 2 := by nlinarith
have h8 : (8 : ℝ) ≤ m ^ 3 := by
have h := pow_le_pow_left₀ (by norm_num : (0 : ℝ) ≤ 2) hm 3
norm_num at h ⊢
exact h
apply (div_lt_one (pow_pos hm0 60)).2
calc
m ^ 2 * (m ^ 2 + 1) ^ 3 ≤ m ^ 2 * (2 * m ^ 2) ^ 3 := by
gcongr
linarith
_ = 8 * m ^ 8 := by ring
_ ≤ m ^ 3 * m ^ 8 := mul_le_mul_of_nonneg_right h8 (pow_nonneg hm0.le 8)
_ = m ^ 11 := by ring
_ < m ^ 60 := pow_lt_pow_right₀ (by linarith) (by decide)
/-- Final numerical union-bound estimate at the exact logarithmic cutoff,
with endpoint-based comparison indexing and `P=M²`. -/
theorem source_cutoff_total_probability_lt_one {m a : ℝ}
(hm : 2 ≤ m) (ha : 120 * Real.logb 2 m ≤ a) :
m ^ 2 * (m ^ 2 + 1) ^ 3 * Real.exp (-a * Real.log 2 / 2) < 1 := by
calc
m ^ 2 * (m ^ 2 + 1) ^ 3 * Real.exp (-a * Real.log 2 / 2) ≤
m ^ 2 * (m ^ 2 + 1) ^ 3 * (1 / m ^ 60) := by
apply mul_le_mul_of_nonneg_left
(exponential_bound_of_source_cutoff (by linarith) ha)
positivity
_ = m ^ 2 * (m ^ 2 + 1) ^ 3 / m ^ 60 := by ring
_ < 1 := endpoint_comparison_frequency_lt_one hm
end CodeUnionBound
end TreeEdit.BinaryLower
end OAI
|