Download data/lean/OAI/Combinatorics/EditApproximation/Numerics/Numerics.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 65.5 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditApproximation/Numerics/Numerics.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/EditApproximation/Numerics/Numerics.lean
-
curl -L -o Numerics.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/EditApproximation/Numerics/Numerics.lean
65.5 kB
import OAI.Combinatorics.EditApproximation.Geometry.Regret
import OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
/-!
# Finite numerical optimizer for edit-distance refinement
These are the explicit fixed-step recurrence and rational mixture
calculations from Section 9 of *An Almost-Linear Approximation Scheme
for Edit Distance* (September 24, 2026). The recurrence is an internal
analytic obligation of the manuscript, not an assumed published theorem.
-/
namespace EditApproximation
open Finset
/-- The conditional-gradient step size in the finite entropy optimizer. -/
noncomputable def frankWolfeStep (j : β) : β := 2 / ((j : β) + 2)
theorem frankWolfeStep_nonnegative (j : β) : 0 β€ frankWolfeStep j := by
unfold frankWolfeStep
positivity
theorem frankWolfeStep_le_one (j : β) : frankWolfeStep j β€ 1 := by
unfold frankWolfeStep
apply (div_le_oneβ (by positivity)).mpr
have := Nat.cast_nonneg (Ξ± := β) j
linarith
/-- The scalar induction step giving the optimizer's `8/(Ο(j+1))`
error term. -/
theorem frank_wolfe_scalar_step (Ο error x : β) (hΟ : 0 < Ο) (hx : 0 β€ x) :
(1 - 2 / (x + 3)) * (2 * error + 8 / (Ο * (x + 2))) +
2 * error * (2 / (x + 3)) + 2 * (2 / (x + 3)) ^ 2 / Ο β€
2 * error + 8 / (Ο * (x + 3)) := by
have h2 : 0 < x + 2 := by linarith
have h3 : 0 < x + 3 := by linarith
have hid :
(2 * error + 8 / (Ο * (x + 3))) -
((1 - 2 / (x + 3)) * (2 * error + 8 / (Ο * (x + 2))) +
2 * error * (2 / (x + 3)) + 2 * (2 / (x + 3)) ^ 2 / Ο) =
8 / (Ο * (x + 2) * (x + 3) ^ 2) := by
field_simp [hΟ.ne', h2.ne', h3.ne']
ring
have hnonneg : 0 β€ 8 / (Ο * (x + 2) * (x + 3) ^ 2) := by positivity
linarith
/-- The first update removes dependence on the initial objective gap.
The conclusion corresponds to manuscript indices `j β₯ 1`. -/
theorem frank_wolfe_gap_bound (Ο error : β) (gap : β β β)
(hΟ : 0 < Ο)
(hrecurrence : β j,
gap (j + 1) β€ (1 - frankWolfeStep j) * gap j +
2 * error * frankWolfeStep j + 2 * (frankWolfeStep j) ^ 2 / Ο) :
β j : β, gap (j + 1) β€ 2 * error + 8 / (Ο * ((j : β) + 2)) := by
intro j
induction j with
| zero =>
have hfirst : gap 1 β€ 2 * error + 2 / Ο := by
simpa [frankWolfeStep] using hrecurrence 0
have hratio : 8 / (Ο * (0 + 2)) = 4 / Ο := by ring
rw [Nat.cast_zero, hratio]
have hnonneg : 0 β€ 2 / Ο := by positivity
have hratio' : 4 / Ο = 2 * (2 / Ο) := by ring
rw [hratio']
norm_num only [Nat.zero_add]
linarith
| succ j ih =>
have hstep : frankWolfeStep (j + 1) = 2 / ((j : β) + 3) := by
norm_num [frankWolfeStep, Nat.cast_add, add_assoc]
have hcoef : 0 β€ 1 - frankWolfeStep (j + 1) :=
sub_nonneg.mpr (frankWolfeStep_le_one _)
have hmono := mul_le_mul_of_nonneg_left ih hcoef
have hrec := hrecurrence (j + 1)
rw [hstep] at hmono hrec
have hscalar := frank_wolfe_scalar_step Ο error (j : β) hΟ (Nat.cast_nonneg _)
have hbound : gap (j + 1 + 1) β€ 2 * error + 8 / (Ο * ((j : β) + 3)) := by
linarith
convert hbound using 1
norm_num [Nat.cast_add, add_assoc]
/-- Exact rational weight of the vertex selected at step `j`, after
`K` steps. -/
def optimizerMixtureWeight (K j : β) : β :=
2 * ((j : β) + 1) / ((K : β) * ((K : β) + 1))
theorem sum_optimizer_numerators (K : β) :
(β j β range K, 2 * ((j : β) + 1)) = (K : β) * ((K : β) + 1) := by
induction K with
| zero => simp
| succ K ih =>
rw [sum_range_succ, ih]
push_cast
ring
theorem optimizerMixtureWeight_positive (K j : β) (hK : 0 < K) :
0 < optimizerMixtureWeight K j := by
unfold optimizerMixtureWeight
have hK' : 0 < (K : β) := Nat.cast_pos.mpr hK
positivity
theorem sum_optimizerMixtureWeight (K : β) (hK : 0 < K) :
(β j β range K, optimizerMixtureWeight K j) = 1 := by
unfold optimizerMixtureWeight
rw [β sum_div, sum_optimizer_numerators]
apply div_self
have hK' : 0 < (K : β) := Nat.cast_pos.mpr hK
positivity
theorem optimizerMixtureWeight_update_old (K j : β) (hK : 0 < K) :
(1 - 2 / ((K : β) + 2)) * optimizerMixtureWeight K j =
optimizerMixtureWeight (K + 1) j := by
have hK' : 0 < (K : β) := Nat.cast_pos.mpr hK
unfold optimizerMixtureWeight
push_cast
field_simp
ring
theorem optimizerMixtureWeight_update_new (K : β) :
2 / ((K : β) + 2) = optimizerMixtureWeight (K + 1) K := by
unfold optimizerMixtureWeight
push_cast
field_simp
ring
/-- Exact rational conditional-gradient iterates. -/
def rationalOptimizerIterate {ΞΉ : Type*} (initial : ΞΉ β β) (selected : β β ΞΉ β β) :
β β ΞΉ β β
| 0 => initial
| j + 1 => fun i =>
(1 - 2 / ((j : β) + 2)) * rationalOptimizerIterate initial selected j i +
(2 / ((j : β) + 2)) * selected j i
/-- After the first update, the initial vertex has weight zero. The
remaining iterates are exactly the explicit rational triangular mixture
used by the fair-bit sampler in Section 9. -/
theorem rationalOptimizerIterate_eq_mixture {ΞΉ : Type*}
(initial : ΞΉ β β) (selected : β β ΞΉ β β) (K : β) (i : ΞΉ) :
rationalOptimizerIterate initial selected (K + 1) i =
β j β range (K + 1), optimizerMixtureWeight (K + 1) j * selected j i := by
induction K with
| zero => norm_num [rationalOptimizerIterate, optimizerMixtureWeight]
| succ K ih =>
rw [rationalOptimizerIterate]
dsimp only
rw [ih, mul_sum]
conv_rhs => rw [sum_range_succ]
congr 1
Β· apply sum_congr rfl
intro j hj
rw [β mul_assoc, optimizerMixtureWeight_update_old (K + 1) j (by omega)]
Β· rw [optimizerMixtureWeight_update_new]
/-- Cumulative integer mass for the triangular exact sampler. -/
theorem optimizerTriangularMass_succ (K : β) :
optimizerTriangularMass (K + 1) = optimizerTriangularMass K + (K + 1) := by
unfold optimizerTriangularMass
rw [sum_range_succ]
theorem optimizerTriangularMass_twice (K : β) :
2 * optimizerTriangularMass K = K * (K + 1) := by
induction K with
| zero => simp [optimizerTriangularMass]
| succ K ih =>
rw [optimizerTriangularMass_succ]
nlinarith
/-- The integers assigned to selection index `j` form a block of
exactly `j+1` points. -/
theorem optimizerSampler_block_card (j : β) :
(Icc (optimizerTriangularMass j + 1) (optimizerTriangularMass (j + 1))).card = j + 1 := by
rw [Nat.card_Icc, optimizerTriangularMass_succ]
omega
/-- Counting the fair uniform integer sampler gives exactly the stored
mixture weights, including repeated selected vertices. -/
theorem optimizerSampler_block_weight (K j : β) (hK : 0 < K) :
((j + 1 : β) : β) / optimizerTriangularMass K = optimizerMixtureWeight K j := by
have hK' : 0 < (K : β) := Nat.cast_pos.mpr hK
have hmass : 2 * (optimizerTriangularMass K : β) = (K : β) * ((K : β) + 1) := by
exact_mod_cast optimizerTriangularMass_twice K
have hmasspos : 0 < (optimizerTriangularMass K : β) := by nlinarith
unfold optimizerMixtureWeight
push_cast
field_simp
nlinarith
/-- The increase of `-x log x` after adding a positive smoothing
parameter is bounded by that parameter's own entropy. -/
theorem entropy_smoothing_upper (x Ο : β) (hx : 0 β€ x) (hΟ : 0 < Ο) :
Real.negMulLog (x + Ο) - Real.negMulLog x β€ Real.negMulLog Ο := by
by_cases hxzero : x = 0
Β· simp [hxzero]
Β· have hxpos : 0 < x := lt_of_le_of_ne hx (Ne.symm hxzero)
have hlogΟ : 0 β€ Real.log (x + Ο) - Real.log Ο :=
sub_nonneg.mpr (Real.log_le_log hΟ (by linarith))
have hlogx : 0 β€ Real.log (x + Ο) - Real.log x :=
sub_nonneg.mpr (Real.log_le_log hxpos (by linarith))
have hprodΟ := mul_nonneg hΟ.le hlogΟ
have hprodx := mul_nonneg hx hlogx
simp only [Real.negMulLog]
nlinarith
/-- The negative change in the smoothed entropy coordinate is linear
in the smoothing parameter on the relevant interval `[0,2]`. -/
theorem entropy_smoothing_lower (x Ο : β) (hx : 0 β€ x) (hΟ : 0 < Ο)
(hupper : x + Ο β€ 2) :
Real.negMulLog x - Real.negMulLog (x + Ο) β€ 2 * Ο := by
have hxs : 0 < x + Ο := by linarith
have hlog : Real.log (x + Ο) β€ 1 := by
exact (Real.log_le_log hxs hupper).trans (by
have := Real.log_le_sub_one_of_pos (show (0 : β) < 2 by norm_num)
linarith)
have hΟlog := mul_le_mul_of_nonneg_left hlog hΟ.le
by_cases hxzero : x = 0
Β· rw [hxzero, zero_add] at hΟlog
simp only [hxzero, Real.negMulLog, zero_add, neg_zero, zero_mul, zero_sub]
nlinarith
Β· have hxpos : 0 < x := lt_of_le_of_ne hx (Ne.symm hxzero)
have hratio := Real.log_le_sub_one_of_pos (div_pos hxs hxpos)
rw [Real.log_div hxs.ne' hxpos.ne'] at hratio
have hratio' := mul_le_mul_of_nonneg_left hratio hx
have hcancel : x * ((x + Ο) / x - 1) = Ο := by
field_simp
ring
rw [hcancel] at hratio'
simp only [Real.negMulLog]
nlinarith
theorem negMulLog_le_two_sqrt (Ο : β) (hΟ : 0 < Ο) :
Real.negMulLog Ο β€ 2 * Real.sqrt Ο := by
have hroot : 0 < Real.sqrt Ο := Real.sqrt_pos.mpr hΟ
have hsq : (Real.sqrt Ο) ^ 2 = Ο := Real.sq_sqrt hΟ.le
have hdiv : Ο / Real.sqrt Ο = Real.sqrt Ο := by
apply (div_eq_iff hroot.ne').mpr
nlinarith
have hmul : Ο * (Real.sqrt Ο)β»ΒΉ = Real.sqrt Ο := by
simpa only [div_eq_mul_inv] using hdiv
have hlog := Real.log_le_sub_one_of_pos (inv_pos.mpr hroot)
rw [Real.log_inv, Real.log_sqrt hΟ.le] at hlog
have hscaled := mul_le_mul_of_nonneg_left hlog (show 0 β€ 2 * Ο by positivity)
simp only [Real.negMulLog]
nlinarith
/-- A uniform coordinate modulus for entropy smoothing, valid including
zero coordinates. -/
theorem entropy_smoothing_coordinate (x Ο : β)
(hx : 0 β€ x) (hx1 : x β€ 1) (hΟ : 0 < Ο) (hΟ1 : Ο β€ 1) :
|Real.negMulLog (x + Ο) - Real.negMulLog x| β€ 2 * Real.sqrt Ο := by
have hupper := (entropy_smoothing_upper x Ο hx hΟ).trans (negMulLog_le_two_sqrt Ο hΟ)
have hlower := entropy_smoothing_lower x Ο hx hΟ (by linarith)
have hΟroot : Ο β€ Real.sqrt Ο := by
have hsq : (Real.sqrt Ο) ^ 2 = Ο := Real.sq_sqrt hΟ.le
have hroot := Real.sqrt_nonneg Ο
have hΟsq : Ο ^ 2 β€ Ο := by nlinarith
nlinarith
exact abs_le.mpr β¨by linarith, hupperβ©
/-- Manuscript Equation `eq:entropy-smoothing`, with a slightly stronger
constant from the coordinate estimate. The linear coefficient vector
cancels, so the bound is independent of its magnitude. -/
theorem finite_entropy_smoothing_bound {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(p objective : ΞΉ β β) (Ο Ξ· : β)
(hp : β i β coordinates, 0 β€ p i)
(hpsum : β i β coordinates, p i = 1)
(hΟ : 0 < Ο) (hΟ1 : Ο β€ 1) :
|((β i β coordinates, Real.negMulLog (p i + Ο)) +
Ξ· * β i β coordinates, objective i * p i) -
entropyValue coordinates Ξ· objective p| β€ 4 * coordinates.card * Real.sqrt Ο := by
rw [entropyValue_eq]
have hcancel :
((β i β coordinates, Real.negMulLog (p i + Ο)) +
Ξ· * β i β coordinates, objective i * p i) -
((β i β coordinates, Real.negMulLog (p i)) +
Ξ· * β i β coordinates, objective i * p i) =
β i β coordinates, (Real.negMulLog (p i + Ο) - Real.negMulLog (p i)) := by
rw [sum_sub_distrib]
ring
rw [hcancel]
calc
_ β€ β i β coordinates, |Real.negMulLog (p i + Ο) - Real.negMulLog (p i)| :=
abs_sum_le_sum_abs _ _
_ β€ β i β coordinates, 2 * Real.sqrt Ο := sum_le_sum fun i hi =>
entropy_smoothing_coordinate (p i) Ο (hp i hi)
((single_le_sum hp hi).trans hpsum.le) hΟ hΟ1
_ β€ 4 * coordinates.card * Real.sqrt Ο := by
simp only [sum_const, nsmul_eq_mul]
have hc : 0 β€ (coordinates.card : β) := Nat.cast_nonneg _
have hroot := Real.sqrt_nonneg Ο
nlinarith
private theorem entropy_quadratic_hasDerivAt (x : β) (hx : 0 < x) :
HasDerivAt (fun z : β => z * Real.log z - z ^ 2 / 2)
(Real.log x + 1 - x) x := by
convert! (Real.hasDerivAt_mul_log hx.ne').sub
(((hasDerivAt_id x).pow 2).div_const 2) using 1
simp only [id_eq]
ring
/-- Negative entropy minus half the square is convex on the probability
coordinate interval. This is the exact curvature bound used for the
objective-gap estimate in the finite optimizer. -/
theorem entropy_quadratic_convex :
ConvexOn β (Set.Icc (0 : β) 1) (fun z : β => z * Real.log z - z ^ 2 / 2) := by
apply MonotoneOn.convexOn_of_deriv (convex_Icc (0 : β) 1)
Β· exact (Real.continuous_mul_log.sub (by fun_prop)).continuousOn
Β· intro x hx
simp only [interior_Icc, Set.mem_Ioo] at hx
exact (entropy_quadratic_hasDerivAt x hx.1).differentiableAt.differentiableWithinAt
Β· intro x hx y hy hxy
simp only [interior_Icc, Set.mem_Ioo] at hx hy
rw [(entropy_quadratic_hasDerivAt x hx.1).deriv,
(entropy_quadratic_hasDerivAt y hy.1).deriv]
have hratio := Real.one_sub_inv_le_log_of_pos (div_pos hy.1 hx.1)
have hinv : (y / x)β»ΒΉ = x / y := by field_simp
rw [hinv, Real.log_div hy.1.ne' hx.1.ne'] at hratio
have hscaled := mul_le_mul_of_nonneg_left hratio hy.1.le
have hcancel : y * (1 - x / y) = y - x := by field_simp [hy.1.ne']
rw [hcancel] at hscaled
have hlog : 0 β€ Real.log y - Real.log x :=
sub_nonneg.mpr (Real.log_le_log hx.1 hxy)
have hcorrection := mul_nonneg (show 0 β€ 1 - y by linarith) hlog
nlinarith
/-- The entropy coordinate gap is at least half the squared coordinate
distance, including the competitor value zero by continuity. -/
theorem entropy_coordinate_strong_gap (x y : β)
(hx : 0 β€ x) (hx1 : x β€ 1) (hy : 0 < y) (hy1 : y β€ 1) :
(x - y) ^ 2 / 2 β€
x * Real.log x - y * Real.log y - (Real.log y + 1) * (x - y) := by
have hderiv := entropy_quadratic_hasDerivAt y hy
rcases lt_trichotomy x y with hxy | rfl | hyx
Β· have hslope := entropy_quadratic_convex.slope_le_of_hasDerivAt
β¨hx, hx1β© β¨hy.le, hy1β© hxy hderiv
rw [slope_def_field] at hslope
have hmul := (div_le_iffβ (sub_pos.mpr hxy)).mp hslope
nlinarith
Β· simp
Β· have hslope := entropy_quadratic_convex.le_slope_of_hasDerivAt
β¨hy.le, hy1β© β¨hx, hx1β© hyx hderiv
rw [slope_def_field] at hslope
have hmul := (le_div_iffβ (sub_pos.mpr hyx)).mp hslope
nlinarith
/-- Relative entropy dominates half the squared Euclidean distance on
the finite probability simplex. -/
theorem finite_relative_entropy_sq_gap {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(p q : ΞΉ β β)
(hp : β i β coordinates, 0 < p i)
(hq : β i β coordinates, 0 β€ q i)
(hpsum : β i β coordinates, p i = 1)
(hqsum : β i β coordinates, q i = 1) :
(β i β coordinates, (q i - p i) ^ 2) / 2 β€
β i β coordinates, q i * Real.log (q i / p i) := by
have hcoord (i : ΞΉ) (hi : i β coordinates) :
(q i - p i) ^ 2 / 2 β€ q i * Real.log (q i / p i) - q i + p i := by
have hstrong := entropy_coordinate_strong_gap (q i) (p i) (hq i hi)
((single_le_sum hq hi).trans hqsum.le) (hp i hi)
((single_le_sum (fun j hj => (hp j hj).le) hi).trans hpsum.le)
by_cases hqzero : q i = 0
Β· simp only [hqzero, zero_mul, sub_zero, zero_sub] at hstrong β’
nlinarith
Β· rw [Real.log_div hqzero (hp i hi).ne']
nlinarith
have hsum := sum_le_sum hcoord
rw [β sum_div, sum_add_distrib, sum_sub_distrib, hqsum, hpsum] at hsum
linarith
/-- A true entropy-objective gap controls the `ββ` error of a feasible
mixture, with the manuscript's exact factor `sqrt (2d gap)`. -/
theorem entropy_gap_to_l1 {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(Q : Set (ΞΉ β β)) (Ξ· : β) (objective maximizer mixture : ΞΉ β β)
(hconvex : Convex β Q) (hmaxQ : maximizer β Q) (hmixQ : mixture β Q)
(hmax : β i β coordinates, 0 < maximizer i)
(hmix : β i β coordinates, 0 β€ mixture i)
(hmaxsum : β i β coordinates, maximizer i = 1)
(hmixsum : β i β coordinates, mixture i = 1)
(hmaximize : IsMaxOn (entropyValue coordinates Ξ· objective) Q maximizer) :
(β i β coordinates, |mixture i - maximizer i|) β€
Real.sqrt (2 * coordinates.card *
(entropyValue coordinates Ξ· objective maximizer -
entropyValue coordinates Ξ· objective mixture)) := by
have hpenalty := entropy_hull_penalty coordinates Q Ξ· objective maximizer mixture
hconvex hmaxQ hmixQ hmax hmaxsum hmixsum hmaximize
have hsq := finite_relative_entropy_sq_gap coordinates maximizer mixture hmax hmix hmaxsum hmixsum
have hcs := sum_sq_le_sum_mul_sum_of_sq_le_mul coordinates
(fun _ _ => (show (0 : β) β€ 1 by norm_num))
(fun i _ => sq_nonneg (mixture i - maximizer i))
(fun i _ => (show |mixture i - maximizer i| ^ 2 β€ 1 * (mixture i - maximizer i) ^ 2 by
rw [one_mul, sq_abs]))
simp only [sum_const, nsmul_eq_mul, mul_one] at hcs
apply Real.le_sqrt_of_sq_le
have hc : 0 β€ (coordinates.card : β) := Nat.cast_nonneg _
have hscaled := mul_le_mul_of_nonneg_left (show
(β i β coordinates, (mixture i - maximizer i) ^ 2) β€
2 * (entropyValue coordinates Ξ· objective maximizer -
entropyValue coordinates Ξ· objective mixture) by linarith) hc
nlinarith
/-- Converting a uniform smoothing error and a smoothed objective gap
to a gap for the true entropy objective. -/
theorem smoothing_gap_transfer (trueBest trueValue smoothBest smoothValue error gap : β)
(hbest : trueBest β€ smoothBest + error)
(hvalue : smoothValue β€ trueValue + error)
(hgap : smoothBest - smoothValue β€ gap) :
trueBest - trueValue β€ gap + 2 * error := by linarith
theorem optimizer_work_budget_gap (G : β) (hG : 0 < G) :
8 / ((1 / G ^ 50) * (G ^ 80 + 1)) β€ 8 / G ^ 30 := by
have hpow : G ^ 80 = G ^ 50 * G ^ 30 := by rw [β pow_add]
have hcancel : (1 / G ^ 50) * G ^ 80 = G ^ 30 := by
rw [hpow]
field_simp
have hdenom : G ^ 30 β€ (1 / G ^ 50) * (G ^ 80 + 1) := by
rw [β hcancel]
exact mul_le_mul_of_nonneg_left (by linarith) (by positivity)
exact div_le_div_of_nonneg_left (by norm_num) (pow_pos hG _) hdenom
theorem optimizer_smoothing_root (G : β) (hG : 0 < G) :
Real.sqrt (1 / G ^ 50) = 1 / G ^ 25 := by
have hpow : G ^ 50 = (G ^ 25) ^ 2 := by rw [β pow_mul]
rw [hpow, Real.sqrt_div (by positivity), Real.sqrt_one, Real.sqrt_sq_eq_abs,
abs_of_pos (pow_pos hG _)]
/-- The explicit total objective-gap bound after the prescribed
number of fixed-step updates. -/
theorem optimizer_explicit_gap_budget (G d : β) (hG : 4 β€ G) (hd : d β€ G) :
2 / G ^ 20 + 8 / G ^ 30 + 8 * d / G ^ 25 β€ 12 / G ^ 20 := by
have hGpos : 0 < G := by linarith
have hG1 : 1 β€ G := by linarith
have hG10 : 4 β€ G ^ 10 := hG.trans (by
simpa using pow_le_pow_rightβ hG1 (by norm_num : 1 β€ 10))
have hG5 : d β€ G ^ 5 := hd.trans (by
simpa using pow_le_pow_rightβ hG1 (by norm_num : 1 β€ 5))
have hsmall : 8 / G ^ 30 β€ 2 / G ^ 20 := by
apply (div_le_div_iffβ (pow_pos hGpos _) (pow_pos hGpos _)).mpr
have hscale := mul_le_mul_of_nonneg_left hG10 (show 0 β€ 2 * G ^ 20 by positivity)
have hpow : G ^ 30 = G ^ 20 * G ^ 10 := by rw [β pow_add]
rw [hpow]
nlinarith
have hsmooth : 8 * d / G ^ 25 β€ 8 / G ^ 20 := by
apply (div_le_div_iffβ (pow_pos hGpos _) (pow_pos hGpos _)).mpr
have hscale := mul_le_mul_of_nonneg_left hG5 (show 0 β€ 8 * G ^ 20 by positivity)
have hpow : G ^ 25 = G ^ 20 * G ^ 5 := by rw [β pow_add]
rw [hpow]
nlinarith
have hsum : 2 / G ^ 20 + 2 / G ^ 20 + 8 / G ^ 20 = 12 / G ^ 20 := by ring
linarith
/-- The quantitative final `H^(-3)` precision calculation. The squared
distance premise is supplied by the proved entropy/KL curvature bound. -/
theorem optimizer_final_l1_precision (H G d distance gap : β)
(hH : 4 β€ H) (hHG : H β€ G) (hd : 0 β€ d) (hdG : d β€ G)
(hsquared : distance ^ 2 β€ 2 * d * gap) (hgap : gap β€ 12 / G ^ 20) :
distance β€ 1 / H ^ 3 := by
have hHpos : 0 < H := by linarith
have hGpos : 0 < G := lt_of_lt_of_le hHpos hHG
have hG4 : 4 β€ G := hH.trans hHG
have hG1 : 1 β€ G := by linarith
have hG3 : 64 β€ G ^ 3 := by
have h := pow_le_pow_leftβ (by norm_num : (0 : β) β€ 4) hG4 3
norm_num at h
exact h
have hG13 : 24 β€ G ^ 13 := by
have hmono := pow_le_pow_rightβ hG1 (by norm_num : 3 β€ 13)
linarith
have hratio : 24 / G ^ 19 β€ 1 / G ^ 6 := by
apply (div_le_div_iffβ (pow_pos hGpos _) (pow_pos hGpos _)).mpr
have hscale := mul_le_mul_of_nonneg_right hG13 (pow_nonneg hGpos.le 6)
have hpow : G ^ 19 = G ^ 13 * G ^ 6 := by rw [β pow_add]
rw [hpow]
nlinarith
have hHratio : 1 / G ^ 6 β€ 1 / H ^ 6 :=
div_le_div_of_nonneg_left zero_le_one (pow_pos hHpos _)
(pow_le_pow_leftβ hHpos.le hHG 6)
have hscale := mul_le_mul_of_nonneg_left hgap (show 0 β€ 2 * d by positivity)
have hdimension := div_le_div_of_nonneg_right
(mul_le_mul_of_nonneg_left hdG (by norm_num : (0 : β) β€ 24))
(pow_nonneg hGpos.le 20)
have hcancel : 24 * G / G ^ 20 = 24 / G ^ 19 := by
have hpow : G ^ 20 = G ^ 19 * G := by rw [β pow_succ]
rw [hpow]
field_simp
have hsquare : distance ^ 2 β€ 1 / H ^ 6 := by
rw [hcancel] at hdimension
have hcombined := hdimension.trans (hratio.trans hHratio)
have hscaledGap : 2 * d * (12 / G ^ 20) = 24 * d / G ^ 20 := by ring
rw [hscaledGap] at hscale
exact hsquared.trans (hscale.trans hcombined)
have htarget : (1 / H ^ 3) ^ 2 = 1 / H ^ 6 := by
rw [div_pow, one_pow, β pow_mul]
have hpositive : 0 < 1 / H ^ 3 := by positivity
rw [β htarget] at hsquare
nlinarith
/-- Rational truncated logarithm used for the entropy-gradient
calculation. Its evaluation uses only rational arithmetic. -/
theorem rationalLogApproximation_cast (r : β) (K : β) :
(rationalLogApproximation r K : β) =
2 * β k β range K,
((((r : β) - 1) / ((r : β) + 1)) ^ (2 * k + 1) / (2 * k + 1)) := by
unfold rationalLogApproximation
push_cast
rfl
theorem logarithm_symmetric_parameter_bound (r Ο : β)
(hΟ : 0 < Ο) (hΟhalf : Ο β€ 1 / 2)
(hr : Ο β€ r) (hrupper : r β€ 1 + Ο) :
|(r - 1) / (r + 1)| β€ 1 - Ο := by
have hrpos : 0 < r := hΟ.trans_le hr
have hrden : 0 < r + 1 := by linarith
apply abs_le.mpr
constructor
Β· apply (le_div_iffβ hrden).mpr
have hprod := mul_nonneg hrpos.le (show 0 β€ 1 - Ο by linarith)
nlinarith
Β· apply (div_le_iffβ hrden).mpr
have hmul := mul_le_mul_of_nonneg_left hrupper hΟ.le
have hΟsquare : Ο ^ 2 β€ Ο / 2 := by
have h := mul_le_mul_of_nonneg_left hΟhalf hΟ.le
nlinarith
nlinarith
/-- Explicit logarithm-series remainder for the rational gradient
routine. Mathlib's logarithm remainder is specialized to the bounded
smoothed-coordinate interval. Its bound suffices for the prescribed
polynomial truncation length. -/
theorem logarithm_series_error (r Ο : β) (K : β)
(hΟ : 0 < Ο) (hΟhalf : Ο β€ 1 / 2)
(hr : Ο β€ r) (hrupper : r β€ 1 + Ο) :
|Real.log r - 2 * β k β range K,
(((r - 1) / (r + 1)) ^ (2 * k + 1) / (2 * k + 1))| β€
2 * Real.exp (-2 * K * Ο) / Ο := by
let b := (r - 1) / (r + 1)
have hrpos : 0 < r := hΟ.trans_le hr
have hrden : 0 < r + 1 := by linarith
have hb : |b| β€ 1 - Ο := logarithm_symmetric_parameter_bound r Ο hΟ hΟhalf hr hrupper
have hb1 : |b| < 1 := by linarith
have htransform : (1 + b) / (1 - b) = r := by
dsimp only [b]
field_simp
ring
have hseries := Real.sum_range_sub_log_div_le hb1 K
rw [htransform] at hseries
have htwice := mul_le_mul_of_nonneg_left hseries (show (0 : β) β€ 2 by norm_num)
have hleft :
|Real.log r - 2 * β k β range K, b ^ (2 * k + 1) / (2 * k + 1)| =
2 * |1 / 2 * Real.log r - β k β range K, b ^ (2 * k + 1) / (2 * k + 1)| := by
rw [β abs_of_nonneg (show (0 : β) β€ 2 by norm_num), β abs_mul]
congr 1
ring
rw [β hleft, β mul_div_assoc] at htwice
have hdenom : Ο β€ 1 - b ^ 2 := by
have hsq := pow_le_pow_leftβ (abs_nonneg b) hb 2
rw [sq_abs] at hsq
have hΟsq : Ο ^ 2 β€ Ο := by nlinarith
nlinarith
have hnum : |b| ^ (2 * K + 1) β€ Real.exp (-2 * K * Ο) := by
calc
_ β€ (1 - Ο) ^ (2 * K + 1) := pow_le_pow_leftβ (abs_nonneg b) hb _
_ β€ Real.exp (-Ο) ^ (2 * K + 1) := pow_le_pow_leftβ
(show 0 β€ 1 - Ο by linarith) (Real.one_sub_le_exp_neg Ο) _
_ = Real.exp ((2 * K + 1 : β) * (-Ο)) := (Real.exp_nat_mul (-Ο) _).symm
_ β€ Real.exp (-2 * K * Ο) := Real.exp_le_exp.mpr (by push_cast; nlinarith)
calc
_ β€ 2 * |b| ^ (2 * K + 1) / (1 - b ^ 2) := htwice
_ β€ 2 * Real.exp (-2 * K * Ο) / (1 - b ^ 2) :=
div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left hnum (by norm_num))
(hΟ.le.trans hdenom)
_ β€ _ := div_le_div_of_nonneg_left (by positivity) hΟ hdenom
theorem rationalLogApproximation_error (r : β) (Ο : β) (K : β)
(hΟ : 0 < Ο) (hΟhalf : Ο β€ 1 / 2)
(hr : Ο β€ (r : β)) (hrupper : (r : β) β€ 1 + Ο) :
|Real.log (r : β) - (rationalLogApproximation r K : β)| β€
2 * Real.exp (-2 * K * Ο) / Ο := by
rw [rationalLogApproximation_cast]
exact logarithm_series_error (r : β) Ο K hΟ hΟhalf hr hrupper
theorem logarithm_truncation_exponential_budget (G : β) (hG : 4 β€ G) :
2 * Real.exp (-2 * G ^ 10) / (1 / G ^ 50) β€ 1 / G ^ 20 := by
have hGpos : 0 < G := by linarith
have hG1 : 1 β€ G := by linarith
have hG5 : 1024 β€ G ^ 5 := by
have h := pow_le_pow_leftβ (by norm_num : (0 : β) β€ 4) hG 5
norm_num at h
exact h
have hG10 : 315 β€ G ^ 10 := by
have hmono := pow_le_pow_rightβ hG1 (by norm_num : 5 β€ 10)
linarith
have hpoly : 2 * G ^ 70 β€ (2 * G ^ 10) ^ 8 / (8 : β).factorial := by
norm_num
apply (le_div_iffβ (by norm_num : (0 : β) < 40320)).mpr
rw [mul_pow, β pow_mul]
have hpow : G ^ 80 = G ^ 70 * G ^ 10 := by rw [β pow_add]
norm_num
rw [hpow]
have hscale := mul_le_mul_of_nonneg_left hG10 (show 0 β€ 256 * G ^ 70 by positivity)
nlinarith
have hexp : 2 * G ^ 70 β€ Real.exp (2 * G ^ 10) :=
hpoly.trans (Real.pow_div_factorial_le_exp (x := 2 * G ^ 10) (n := 8) (by positivity))
have heq : 2 * Real.exp (-2 * G ^ 10) / (1 / G ^ 50) =
2 * G ^ 50 / Real.exp (2 * G ^ 10) := by
rw [show -2 * G ^ 10 = -(2 * G ^ 10) by ring, Real.exp_neg]
field_simp [hGpos.ne']
rw [heq]
apply (div_le_div_iffβ (Real.exp_pos _) (pow_pos hGpos _)).mpr
have hpow : G ^ 50 * G ^ 20 = G ^ 70 := by rw [β pow_add]
nlinarith
/-- The prescribed rational logarithm computation has the required
absolute gradient precision `G^(-20)` after `G^60` rational terms. -/
theorem rationalLogApproximation_prescribed_precision (r : β) (G : β)
(hG : 4 β€ G)
(hr : 1 / (G : β) ^ 50 β€ (r : β))
(hrupper : (r : β) β€ 1 + 1 / (G : β) ^ 50) :
|Real.log (r : β) - (rationalLogApproximation r (G ^ 60) : β)| β€
1 / (G : β) ^ 20 := by
have hG4 : (4 : β) β€ G := by exact_mod_cast hG
have hGpos : (0 : β) < G := by linarith
have hG1 : (1 : β) β€ G := by linarith
have hG50 : (2 : β) β€ (G : β) ^ 50 := by
have hmono := pow_le_pow_rightβ hG1 (by norm_num : 1 β€ 50)
norm_num only [pow_one] at hmono
linarith
have hΟpos : 0 < 1 / (G : β) ^ 50 := by positivity
have hΟhalf : 1 / (G : β) ^ 50 β€ 1 / 2 := by
exact div_le_div_of_nonneg_left zero_le_one (by norm_num) hG50
have herror := rationalLogApproximation_error r (1 / (G : β) ^ 50) (G ^ 60)
hΟpos hΟhalf hr hrupper
have hprod : ((G ^ 60 : β) : β) * (1 / (G : β) ^ 50) = (G : β) ^ 10 := by
push_cast
have hpow : (G : β) ^ 60 = (G : β) ^ 10 * (G : β) ^ 50 := by rw [β pow_add]
rw [hpow]
field_simp
have hexponent : -2 * ((G ^ 60 : β) : β) * (1 / (G : β) ^ 50) =
-2 * (G : β) ^ 10 := by nlinarith [hprod]
rw [hexponent] at herror
exact herror.trans (logarithm_truncation_exponential_budget (G : β) hG4)
theorem finite_gradient_error {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(gradient approximateGradient p : ΞΉ β β) (error : β)
(hp : β i β coordinates, 0 β€ p i)
(hpsum : β i β coordinates, p i = 1)
(herror : β i β coordinates, |approximateGradient i - gradient i| β€ error) :
|β i β coordinates, (approximateGradient i - gradient i) * p i| β€ error := by
calc
_ β€ β i β coordinates, |(approximateGradient i - gradient i) * p i| :=
abs_sum_le_sum_abs _ _
_ β€ β i β coordinates, error * p i := by
apply sum_le_sum
intro i hi
rw [abs_mul, abs_of_nonneg (hp i hi)]
exact mul_le_mul_of_nonneg_right (herror i hi) (hp i hi)
_ = error := by rw [β mul_sum, hpsum, mul_one]
/-- Enumerating the vertices with an approximate gradient loses at
most `2eβ` in the true linearization, even against an arbitrary feasible
mixture. -/
theorem approximate_gradient_linearization_loss {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(gradient approximateGradient selected competitor : ΞΉ β β) (error : β)
(hselected : β i β coordinates, 0 β€ selected i)
(hcompetitor : β i β coordinates, 0 β€ competitor i)
(hselectedSum : β i β coordinates, selected i = 1)
(hcompetitorSum : β i β coordinates, competitor i = 1)
(herror : β i β coordinates, |approximateGradient i - gradient i| β€ error)
(hchoose : (β i β coordinates, approximateGradient i * competitor i) β€
β i β coordinates, approximateGradient i * selected i) :
(β i β coordinates, gradient i * competitor i) -
(β i β coordinates, gradient i * selected i) β€ 2 * error := by
have hsel := finite_gradient_error coordinates gradient approximateGradient selected
error hselected hselectedSum herror
have hcomp := finite_gradient_error coordinates gradient approximateGradient competitor
error hcompetitor hcompetitorSum herror
simp only [sub_mul, sum_sub_distrib] at hsel hcomp
have hselBounds := abs_le.mp hsel
have hcompBounds := abs_le.mp hcomp
linarith
noncomputable def smoothedEntropyValue {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(Ο : β) (linear p : ΞΉ β β) : β :=
β i β coordinates, (Real.negMulLog (p i + Ο) + linear i * p i)
noncomputable def smoothedEntropyGradient {ΞΉ : Type*}
(Ο : β) (linear p : ΞΉ β β) (i : ΞΉ) : β :=
-Real.log (p i + Ο) - 1 + linear i
/-- Tangent upper bound for a single smoothed entropy coordinate. -/
theorem smoothed_entropy_coordinate_upper (x y Ο linear : β)
(hx : 0 β€ x) (hy : 0 β€ y) (hΟ : 0 < Ο) :
(Real.negMulLog (y + Ο) + linear * y) -
(Real.negMulLog (x + Ο) + linear * x) β€
(-Real.log (x + Ο) - 1 + linear) * (y - x) := by
have hxs : 0 < x + Ο := by linarith
have hys : 0 < y + Ο := by linarith
have hlog := Real.log_le_sub_one_of_pos (div_pos hxs hys)
rw [Real.log_div hxs.ne' hys.ne'] at hlog
have hscaled := mul_le_mul_of_nonneg_left hlog hys.le
have hcancel : (y + Ο) * ((x + Ο) / (y + Ο) - 1) = x - y := by
field_simp
ring
rw [hcancel] at hscaled
simp only [Real.negMulLog]
nlinarith
/-- A scalar smoothness bound obtained directly from `log u β€ u-1`.
The coefficient `1/Ο` combines with the sharper simplex diameter below
to give the manuscript's exact `2 ΞΎΒ²/Ο` remainder. -/
theorem smoothed_entropy_coordinate_lower (x y Ο linear : β)
(hx : 0 β€ x) (hy : 0 β€ y) (hΟ : 0 < Ο) :
(-Real.log (x + Ο) - 1 + linear) * (y - x) - (y - x) ^ 2 / Ο β€
(Real.negMulLog (y + Ο) + linear * y) -
(Real.negMulLog (x + Ο) + linear * x) := by
have hxs : 0 < x + Ο := by linarith
have hys : 0 < y + Ο := by linarith
have hlog := Real.log_le_sub_one_of_pos (div_pos hys hxs)
rw [Real.log_div hys.ne' hxs.ne'] at hlog
have hscaled := mul_le_mul_of_nonneg_left hlog hys.le
have hcancel : (y + Ο) * ((y + Ο) / (x + Ο) - 1) - y + x =
(y - x) ^ 2 / (x + Ο) := by
field_simp
ring
have hratio : (y - x) ^ 2 / (x + Ο) β€ (y - x) ^ 2 / Ο :=
div_le_div_of_nonneg_left (sq_nonneg _) hΟ (by linarith)
have hbound : (y + Ο) * (Real.log (y + Ο) - Real.log (x + Ο)) - y + x β€
(y - x) ^ 2 / (x + Ο) := by linarith
have hbound' := hbound.trans hratio
simp only [Real.negMulLog]
nlinarith
theorem probability_vectors_sq_distance_le_two {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(p q : ΞΉ β β)
(hp : β i β coordinates, 0 β€ p i)
(hq : β i β coordinates, 0 β€ q i)
(hpsum : β i β coordinates, p i = 1)
(hqsum : β i β coordinates, q i = 1) :
β i β coordinates, (q i - p i) ^ 2 β€ 2 := by
have hcoord (i : ΞΉ) (hi : i β coordinates) : (q i - p i) ^ 2 β€ q i + p i := by
have hp1 := (single_le_sum hp hi).trans hpsum.le
have hq1 := (single_le_sum hq hi).trans hqsum.le
have hpprod := mul_nonneg (hp i hi) (sub_nonneg.mpr hp1)
have hqprod := mul_nonneg (hq i hi) (sub_nonneg.mpr hq1)
have hpq := mul_nonneg (hp i hi) (hq i hi)
nlinarith
calc
_ β€ β i β coordinates, (q i + p i) := sum_le_sum hcoord
_ = 2 := by rw [sum_add_distrib, hqsum, hpsum]; norm_num
theorem smoothed_entropy_tangent_upper {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(Ο : β) (linear p q : ΞΉ β β)
(hp : β i β coordinates, 0 β€ p i)
(hq : β i β coordinates, 0 β€ q i) (hΟ : 0 < Ο) :
smoothedEntropyValue coordinates Ο linear q - smoothedEntropyValue coordinates Ο linear p β€
β i β coordinates, smoothedEntropyGradient Ο linear p i * (q i - p i) := by
rw [smoothedEntropyValue, smoothedEntropyValue, β sum_sub_distrib]
exact sum_le_sum fun i hi => smoothed_entropy_coordinate_upper (p i) (q i) Ο
(linear i) (hp i hi) (hq i hi) hΟ
theorem smoothed_entropy_mixture_lower {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(Ο ΞΎ : β) (linear p selected : ΞΉ β β)
(hp : β i β coordinates, 0 β€ p i)
(hselected : β i β coordinates, 0 β€ selected i)
(hpsum : β i β coordinates, p i = 1)
(hselectedSum : β i β coordinates, selected i = 1)
(hΟ : 0 < Ο) (hΞΎ : 0 β€ ΞΎ) (hΞΎ1 : ΞΎ β€ 1) :
ΞΎ * (β i β coordinates, smoothedEntropyGradient Ο linear p i * (selected i - p i)) -
2 * ΞΎ ^ 2 / Ο β€
smoothedEntropyValue coordinates Ο linear
(fun i => (1 - ΞΎ) * p i + ΞΎ * selected i) - smoothedEntropyValue coordinates Ο linear p := by
let updated : ΞΉ β β := fun i => (1 - ΞΎ) * p i + ΞΎ * selected i
have hupdated (i : ΞΉ) (hi : i β coordinates) : 0 β€ updated i :=
add_nonneg (mul_nonneg (sub_nonneg.mpr hΞΎ1) (hp i hi))
(mul_nonneg hΞΎ (hselected i hi))
have hcoordinate (i : ΞΉ) (hi : i β coordinates) :=
smoothed_entropy_coordinate_lower (p i) (updated i) Ο (linear i) (hp i hi) (hupdated i hi) hΟ
have hsum := sum_le_sum hcoordinate
have hterm (i : ΞΉ) : updated i - p i = ΞΎ * (selected i - p i) := by
dsimp only [updated]
ring
simp only [smoothedEntropyGradient] at hsum β’
simp_rw [hterm, mul_pow, div_eq_mul_inv] at hsum
rw [sum_sub_distrib] at hsum
have hlinear :
(β i β coordinates, (-Real.log (p i + Ο) - 1 + linear i) * (ΞΎ * (selected i - p i))) =
ΞΎ * β i β coordinates, (-Real.log (p i + Ο) - 1 + linear i) * (selected i - p i) := by
rw [mul_sum]
apply sum_congr rfl
intro i hi
ring
have hquadratic : (β i β coordinates, ΞΎ ^ 2 * (selected i - p i) ^ 2 * Οβ»ΒΉ) =
(ΞΎ ^ 2 / Ο) * β i β coordinates, (selected i - p i) ^ 2 := by
rw [mul_sum]
apply sum_congr rfl
intro i hi
ring
rw [hlinear, hquadratic, sum_sub_distrib] at hsum
have hdiameter := probability_vectors_sq_distance_le_two coordinates p selected hp hselected hpsum hselectedSum
have hscale := mul_le_mul_of_nonneg_left hdiameter (show 0 β€ ΞΎ ^ 2 / Ο by positivity)
change _ β€ smoothedEntropyValue coordinates Ο linear updated -
smoothedEntropyValue coordinates Ο linear p at hsum
change _ β€ smoothedEntropyValue coordinates Ο linear updated -
smoothedEntropyValue coordinates Ο linear p
have htwo : ΞΎ ^ 2 / Ο * 2 = 2 * ΞΎ ^ 2 / Ο := by ring
rw [htwo] at hscale
linarith
/-- The manuscript's fixed-step optimizer recurrence follows from the
actual smoothed entropy objective and approximate gradient selection. -/
theorem smoothed_frank_wolfe_recurrence {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(Ο ΞΎ error : β) (linear p selected best approximateGradient : ΞΉ β β)
(hp : β i β coordinates, 0 β€ p i)
(hselected : β i β coordinates, 0 β€ selected i)
(hbest : β i β coordinates, 0 β€ best i)
(hpsum : β i β coordinates, p i = 1)
(hselectedSum : β i β coordinates, selected i = 1)
(hbestSum : β i β coordinates, best i = 1)
(hΟ : 0 < Ο) (hΞΎ : 0 β€ ΞΎ) (hΞΎ1 : ΞΎ β€ 1)
(hgradient : β i β coordinates,
|approximateGradient i - smoothedEntropyGradient Ο linear p i| β€ error)
(hchoose : (β i β coordinates, approximateGradient i * best i) β€
β i β coordinates, approximateGradient i * selected i) :
smoothedEntropyValue coordinates Ο linear best -
smoothedEntropyValue coordinates Ο linear (fun i => (1 - ΞΎ) * p i + ΞΎ * selected i) β€
(1 - ΞΎ) * (smoothedEntropyValue coordinates Ο linear best - smoothedEntropyValue coordinates Ο linear p) +
2 * error * ΞΎ + 2 * ΞΎ ^ 2 / Ο := by
have htangent := smoothed_entropy_tangent_upper coordinates Ο linear p best hp hbest hΟ
have hlinear := approximate_gradient_linearization_loss coordinates
(smoothedEntropyGradient Ο linear p) approximateGradient selected best error
hselected hbest hselectedSum hbestSum hgradient hchoose
have hlower := smoothed_entropy_mixture_lower coordinates Ο ΞΎ linear p selected
hp hselected hpsum hselectedSum hΟ hΞΎ hΞΎ1
have hsumBest : (β i β coordinates, smoothedEntropyGradient Ο linear p i * (best i - p i)) =
(β i β coordinates, smoothedEntropyGradient Ο linear p i * best i) -
β i β coordinates, smoothedEntropyGradient Ο linear p i * p i := by
simp only [mul_sub, sum_sub_distrib]
have hsumSelected : (β i β coordinates, smoothedEntropyGradient Ο linear p i * (selected i - p i)) =
(β i β coordinates, smoothedEntropyGradient Ο linear p i * selected i) -
β i β coordinates, smoothedEntropyGradient Ο linear p i * p i := by
simp only [mul_sub, sum_sub_distrib]
rw [hsumBest] at htangent
rw [hsumSelected] at hlower
have hgain : smoothedEntropyValue coordinates Ο linear best - smoothedEntropyValue coordinates Ο linear p -
2 * error β€ (β i β coordinates, smoothedEntropyGradient Ο linear p i * selected i) -
β i β coordinates, smoothedEntropyGradient Ο linear p i * p i := by linarith
have hscale := mul_le_mul_of_nonneg_left hgain hΞΎ
nlinarith
/-- Casting the exact rational update gives precisely the analytic step. -/
theorem rationalOptimizerIterate_cast_step {ΞΉ : Type*}
(initial : ΞΉ β β) (selected : β β ΞΉ β β) (j : β) :
(fun i => (rationalOptimizerIterate initial selected (j + 1) i : β)) =
(fun i => (1 - frankWolfeStep j) * (rationalOptimizerIterate initial selected j i : β) +
frankWolfeStep j * (selected j i : β)) := by
funext i
simp [rationalOptimizerIterate, frankWolfeStep]
/-- All exact rational iterates are probability vectors. -/
theorem rationalOptimizerIterate_probability {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(initial : ΞΉ β β) (selected : β β ΞΉ β β)
(hinitial : β i β coordinates, (0 : β) β€ initial i)
(hinitialSum : β i β coordinates, (initial i : β) = 1)
(hselected : β j i, i β coordinates β (0 : β) β€ selected j i)
(hselectedSum : β j, β i β coordinates, (selected j i : β) = 1) :
β j, (β i β coordinates, (0 : β) β€ rationalOptimizerIterate initial selected j i) β§
(β i β coordinates, (rationalOptimizerIterate initial selected j i : β)) = 1 := by
intro j
induction j with
| zero => exact β¨hinitial, hinitialSumβ©
| succ j ih =>
have hstep := congr_fun (rationalOptimizerIterate_cast_step initial selected j)
constructor
Β· intro i hi
rw [hstep i]
exact add_nonneg
(mul_nonneg (sub_nonneg.mpr (frankWolfeStep_le_one j)) (ih.1 i hi))
(mul_nonneg (frankWolfeStep_nonnegative j) (hselected j i hi))
Β· simp_rw [hstep]
rw [sum_add_distrib, β mul_sum, β mul_sum, ih.2, hselectedSum]
ring
/-- Convex feasibility is preserved by the actual rational iterates. -/
theorem rationalOptimizerIterate_mem {ΞΉ : Type*}
(Q : Set (ΞΉ β β)) (initial : ΞΉ β β) (selected : β β ΞΉ β β)
(hconvex : Convex β Q) (hinitial : (fun i => (initial i : β)) β Q)
(hselected : β j, (fun i => (selected j i : β)) β Q) :
β j, (fun i => (rationalOptimizerIterate initial selected j i : β)) β Q := by
intro j
induction j with
| zero => exact hinitial
| succ j ih =>
rw [rationalOptimizerIterate_cast_step]
exact hconvex ih (hselected j) (sub_nonneg.mpr (frankWolfeStep_le_one j))
(frankWolfeStep_nonnegative j) (by ring)
/-- Objective convergence of the exact rational implementation follows
from the proved smoothness and rational approximate-gradient choices. -/
theorem rational_optimizer_smoothed_gap_bound {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(Ο error : β) (linear best : ΞΉ β β) (initial : ΞΉ β β)
(selected : β β ΞΉ β β) (approximateGradient : β β ΞΉ β β)
(hinitial : β i β coordinates, (0 : β) β€ initial i)
(hinitialSum : β i β coordinates, (initial i : β) = 1)
(hselected : β j i, i β coordinates β (0 : β) β€ selected j i)
(hselectedSum : β j, β i β coordinates, (selected j i : β) = 1)
(hbest : β i β coordinates, 0 β€ best i)
(hbestSum : β i β coordinates, best i = 1) (hΟ : 0 < Ο)
(hgradient : β j i, i β coordinates β
|approximateGradient j i - smoothedEntropyGradient Ο linear
(fun i => (rationalOptimizerIterate initial selected j i : β)) i| β€ error)
(hchoose : β j, (β i β coordinates, approximateGradient j i * best i) β€
β i β coordinates, approximateGradient j i * (selected j i : β)) :
β j, smoothedEntropyValue coordinates Ο linear best - smoothedEntropyValue coordinates Ο linear
(fun i => (rationalOptimizerIterate initial selected (j + 1) i : β)) β€
2 * error + 8 / (Ο * ((j : β) + 2)) := by
have hprobability := rationalOptimizerIterate_probability coordinates initial selected
hinitial hinitialSum hselected hselectedSum
apply frank_wolfe_gap_bound Ο error
(fun j => smoothedEntropyValue coordinates Ο linear best - smoothedEntropyValue coordinates Ο linear
(fun i => (rationalOptimizerIterate initial selected j i : β))) hΟ
intro j
rw [rationalOptimizerIterate_cast_step]
exact smoothed_frank_wolfe_recurrence coordinates Ο (frankWolfeStep j) error linear
(fun i => (rationalOptimizerIterate initial selected j i : β))
(fun i => (selected j i : β)) best (approximateGradient j)
(hprobability j).1 (hselected j) hbest (hprobability j).2 (hselectedSum j) hbestSum hΟ
(frankWolfeStep_nonnegative j) (frankWolfeStep_le_one j) (hgradient j) (hchoose j)
/-- The actual rational gradient routine, including exact linear terms. -/
theorem rationalSmoothedGradient_precision {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(G : β) (linear p : ΞΉ β β) (hG : 4 β€ G)
(hp : β i β coordinates, (0 : β) β€ p i)
(hpsum : β i β coordinates, (p i : β) = 1) :
β i β coordinates,
|(rationalSmoothedGradient G linear p i : β) -
smoothedEntropyGradient (1 / (G : β) ^ 50)
(fun i => (linear i : β)) (fun i => (p i : β)) i| β€ 1 / (G : β) ^ 20 := by
intro i hi
have hinput : (1 / (G : β) ^ 50) β€ (p i + 1 / (G : β) ^ 50 : β) := by
push_cast
linarith [hp i hi]
have hupper : ((p i + 1 / (G : β) ^ 50 : β) : β) β€ 1 + 1 / (G : β) ^ 50 := by
push_cast
linarith [(single_le_sum hp hi).trans hpsum.le]
have hlog := rationalLogApproximation_prescribed_precision
(p i + 1 / (G : β) ^ 50) G hG hinput hupper
convert hlog using 1
congr 1
simp only [rationalSmoothedGradient, smoothedEntropyGradient]
push_cast
ring
/-- The prescribed number of exact rational updates reaches the true
entropy-objective precision, with no assumed analytic recurrence. -/
theorem rational_optimizer_true_gap_precision {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(G : β) (linear initial : ΞΉ β β) (selected : β β ΞΉ β β) (best : ΞΉ β β)
(hG : 4 β€ G) (hdG : coordinates.card β€ G)
(hinitial : β i β coordinates, (0 : β) β€ initial i)
(hinitialSum : β i β coordinates, (initial i : β) = 1)
(hselected : β j i, i β coordinates β (0 : β) β€ selected j i)
(hselectedSum : β j, β i β coordinates, (selected j i : β) = 1)
(hbest : β i β coordinates, 0 β€ best i)
(hbestSum : β i β coordinates, best i = 1)
(hchoose : β j,
(β i β coordinates, (rationalSmoothedGradient G linear
(rationalOptimizerIterate initial selected j) i : β) * best i) β€
β i β coordinates, (rationalSmoothedGradient G linear
(rationalOptimizerIterate initial selected j) i : β) * (selected j i : β)) :
entropyValue coordinates 1 (fun i => (linear i : β)) best -
entropyValue coordinates 1 (fun i => (linear i : β))
(fun i => (rationalOptimizerIterate initial selected (G ^ 80) i : β)) β€
12 / (G : β) ^ 20 := by
let Ο : β := 1 / (G : β) ^ 50
have hG4 : (4 : β) β€ G := by exact_mod_cast hG
have hGpos : (0 : β) < G := by linarith
have hΟ : 0 < Ο := by dsimp [Ο]; positivity
have hΟ1 : Ο β€ 1 := by
dsimp [Ο]
apply (div_le_oneβ (pow_pos hGpos _)).mpr
exact one_le_powβ (by linarith : (1 : β) β€ G)
have hprobability := rationalOptimizerIterate_probability coordinates initial selected
hinitial hinitialSum hselected hselectedSum
have hgradient j := rationalSmoothedGradient_precision coordinates G linear
(rationalOptimizerIterate initial selected j) hG (hprobability j).1 (hprobability j).2
have hgap := rational_optimizer_smoothed_gap_bound coordinates Ο (1 / (G : β) ^ 20)
(fun i => (linear i : β)) best initial selected
(fun j i => (rationalSmoothedGradient G linear (rationalOptimizerIterate initial selected j) i : β))
hinitial hinitialSum hselected hselectedSum hbest hbestSum hΟ hgradient hchoose (G ^ 80 - 1)
have hK : 1 β€ G ^ 80 := by
have hGnat : 0 < G := by omega
exact Nat.one_le_iff_ne_zero.mpr (pow_ne_zero 80 (Nat.ne_of_gt hGnat))
rw [Nat.sub_add_cancel hK] at hgap
have hindex : ((G ^ 80 - 1 : β) : β) + 2 = (G : β) ^ 80 + 1 := by
rw [Nat.cast_sub hK, Nat.cast_one, Nat.cast_pow]
ring
rw [hindex] at hgap
have hbudget := optimizer_work_budget_gap (G : β) hGpos
have hsmoothed : smoothedEntropyValue coordinates Ο (fun i => (linear i : β)) best -
smoothedEntropyValue coordinates Ο (fun i => (linear i : β))
(fun i => (rationalOptimizerIterate initial selected (G ^ 80) i : β)) β€
2 / (G : β) ^ 20 + 8 / (G : β) ^ 30 := by
dsimp only [Ο] at hgap β’
have htwo : (2 : β) * (1 / (G : β) ^ 20) = 2 / (G : β) ^ 20 := by ring
rw [htwo] at hgap
linarith
have hbestSmoothing := finite_entropy_smoothing_bound coordinates best
(fun i => (linear i : β)) Ο 1 hbest hbestSum hΟ hΟ1
have hvalueSmoothing := finite_entropy_smoothing_bound coordinates
(fun i => (rationalOptimizerIterate initial selected (G ^ 80) i : β))
(fun i => (linear i : β)) Ο 1 (hprobability _).1 (hprobability _).2 hΟ hΟ1
have hbestSmooth : |smoothedEntropyValue coordinates Ο (fun i => (linear i : β)) best -
entropyValue coordinates 1 (fun i => (linear i : β)) best| β€
4 * coordinates.card * Real.sqrt Ο := by
simpa [smoothedEntropyValue, sum_add_distrib] using hbestSmoothing
have hvalueSmooth : |smoothedEntropyValue coordinates Ο (fun i => (linear i : β))
(fun i => (rationalOptimizerIterate initial selected (G ^ 80) i : β)) -
entropyValue coordinates 1 (fun i => (linear i : β))
(fun i => (rationalOptimizerIterate initial selected (G ^ 80) i : β))| β€
4 * coordinates.card * Real.sqrt Ο := by
simpa [smoothedEntropyValue, sum_add_distrib] using hvalueSmoothing
have htrue : entropyValue coordinates 1 (fun i => (linear i : β)) best -
entropyValue coordinates 1 (fun i => (linear i : β))
(fun i => (rationalOptimizerIterate initial selected (G ^ 80) i : β)) β€
2 / (G : β) ^ 20 + 8 / (G : β) ^ 30 + 8 * coordinates.card * Real.sqrt Ο := by
have hb := abs_le.mp hbestSmooth
have hv := abs_le.mp hvalueSmooth
linarith
have hroot : Real.sqrt Ο = 1 / (G : β) ^ 25 := optimizer_smoothing_root _ hGpos
rw [hroot] at htrue
have hdimension : (coordinates.card : β) β€ G := by exact_mod_cast hdG
have hfinal := optimizer_explicit_gap_budget (G : β) coordinates.card hG4 hdimension
have hnorm : (8 : β) * coordinates.card * (1 / (G : β) ^ 25) =
8 * coordinates.card / (G : β) ^ 25 := by ring
rw [hnorm] at htrue
exact htrue.trans hfinal
/-- The final distance guarantee for the prescribed rational updates.
Only their concrete finite linearization choices remain as input. -/
theorem rational_optimizer_l1_precision {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(Q : Set (ΞΉ β β)) (H G : β) (linear initial : ΞΉ β β)
(selected : β β ΞΉ β β) (maximizer : ΞΉ β β)
(hH : 4 β€ H) (hHG : H β€ G) (hdG : coordinates.card β€ G)
(hconvex : Convex β Q) (hinitialQ : (fun i => (initial i : β)) β Q)
(hselectedQ : β j, (fun i => (selected j i : β)) β Q)
(hmaxQ : maximizer β Q)
(hinitial : β i β coordinates, (0 : β) β€ initial i)
(hinitialSum : β i β coordinates, (initial i : β) = 1)
(hselected : β j i, i β coordinates β (0 : β) β€ selected j i)
(hselectedSum : β j, β i β coordinates, (selected j i : β) = 1)
(hmax : β i β coordinates, 0 < maximizer i)
(hmaxSum : β i β coordinates, maximizer i = 1)
(hmaximize : IsMaxOn (entropyValue coordinates 1 (fun i => (linear i : β))) Q maximizer)
(hchoose : β j,
(β i β coordinates, (rationalSmoothedGradient G linear
(rationalOptimizerIterate initial selected j) i : β) * maximizer i) β€
β i β coordinates, (rationalSmoothedGradient G linear
(rationalOptimizerIterate initial selected j) i : β) * (selected j i : β)) :
(β i β coordinates,
|(rationalOptimizerIterate initial selected (G ^ 80) i : β) - maximizer i|) β€
1 / (H : β) ^ 3 := by
have hG : 4 β€ G := hH.trans hHG
have hprobability := rationalOptimizerIterate_probability coordinates initial selected
hinitial hinitialSum hselected hselectedSum (G ^ 80)
have hmixture := rationalOptimizerIterate_mem Q initial selected
hconvex hinitialQ hselectedQ (G ^ 80)
have hgap := rational_optimizer_true_gap_precision coordinates G linear initial selected maximizer
hG hdG hinitial hinitialSum hselected hselectedSum (fun i hi => (hmax i hi).le) hmaxSum hchoose
have hdistance := entropy_gap_to_l1 coordinates Q 1 (fun i => (linear i : β)) maximizer
(fun i => (rationalOptimizerIterate initial selected (G ^ 80) i : β)) hconvex
hmaxQ hmixture hmax hprobability.1 hmaxSum hprobability.2 hmaximize
have hmaxbound := hmaximize hmixture
change entropyValue coordinates 1 (fun i => (linear i : β))
(fun i => (rationalOptimizerIterate initial selected (G ^ 80) i : β)) β€
entropyValue coordinates 1 (fun i => (linear i : β)) maximizer at hmaxbound
have hnonnegative : 0 β€ 2 * (coordinates.card : β) *
(entropyValue coordinates 1 (fun i => (linear i : β)) maximizer -
entropyValue coordinates 1 (fun i => (linear i : β))
(fun i => (rationalOptimizerIterate initial selected (G ^ 80) i : β))) := by positivity
have hsquared := pow_le_pow_leftβ (sum_nonneg (fun _ _ => abs_nonneg _)) hdistance 2
rw [Real.sq_sqrt hnonnegative] at hsquared
apply optimizer_final_l1_precision (H : β) G coordinates.card _ _
(by exact_mod_cast hH) (by exact_mod_cast hHG) (Nat.cast_nonneg _)
(by exact_mod_cast hdG) hsquared hgap
/-- Maximizing a finite list's linearization also maximizes it on the
real convex hull. -/
theorem finite_linearization_maximizes_convexHull {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(vertices : Set (ΞΉ β β)) (gradient selected : ΞΉ β β)
(hchoose : β p β vertices,
(β i β coordinates, gradient i * p i) β€ β i β coordinates, gradient i * selected i) :
β p β convexHull β vertices,
(β i β coordinates, gradient i * p i) β€ β i β coordinates, gradient i * selected i := by
let bound := β i β coordinates, gradient i * selected i
have hconvex : Convex β {p : ΞΉ β β | (β i β coordinates, gradient i * p i) β€ bound} := by
intro p hp q hq a b ha hb hab
change (β i β coordinates, gradient i * (a * p i + b * q i)) β€ bound
have hlinear : (β i β coordinates, gradient i * (a * p i + b * q i)) =
a * (β i β coordinates, gradient i * p i) +
b * (β i β coordinates, gradient i * q i) := by
rw [mul_sum, mul_sum, β sum_add_distrib]
apply sum_congr rfl
intro i hi
ring
rw [hlinear]
have hp' := mul_le_mul_of_nonneg_left hp ha
have hq' := mul_le_mul_of_nonneg_left hq hb
have hbound : a * bound + b * bound = bound := by rw [β add_mul, hab, one_mul]
linarith
exact convexHull_min hchoose hconvex
/-- Executable finite rational comparisons, with the first listed
maximizer selected in a tie. The fallback only applies to an empty list. -/
theorem rationalLinearizationMaximizer_spec {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(vertices : List (ΞΉ β β)) (gradient : ΞΉ β β) (hvertices : vertices β []) :
rationalLinearizationMaximizer coordinates vertices gradient β vertices β§
β p β vertices, (β i β coordinates, gradient i * p i) β€
β i β coordinates, gradient i * rationalLinearizationMaximizer coordinates vertices gradient i := by
unfold rationalLinearizationMaximizer
cases harg : vertices.argmax (fun p => β i β coordinates, gradient i * p i) with
| none => exact False.elim (hvertices (List.argmax_eq_none.mp harg))
| some selected =>
simp only [Option.getD_some]
have hmem : selected β vertices.argmax (fun p => β i β coordinates, gradient i * p i) := by
rw [harg]
simp
exact β¨List.argmax_mem hmem, fun p hp => List.le_of_mem_argmax
(f := fun p : ΞΉ β β => β i β coordinates, gradient i * p i) hp hmemβ©
/-- The finite rational optimizer: every operation here is rational
arithmetic, finite enumeration, or the prescribed finite logarithm sum. -/
def finiteOptimizerSelection {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(vertices : List (ΞΉ β β)) (linear : ΞΉ β β) (G j : β) : ΞΉ β β :=
rationalLinearizationMaximizer coordinates vertices
(rationalSmoothedGradient G linear (finiteRationalOptimizer coordinates vertices linear G j))
theorem finiteRationalOptimizer_eq_iterate {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(vertices : List (ΞΉ β β)) (linear : ΞΉ β β) (G j : β) :
finiteRationalOptimizer coordinates vertices linear G j =
rationalOptimizerIterate (vertices.headD (fun _ => 0))
(finiteOptimizerSelection coordinates vertices linear G) j := by
induction j with
| zero => rfl
| succ j ih =>
funext i
simp only [finiteRationalOptimizer, rationalOptimizerIterate]
change (1 - 2 / ((j : β) + 2)) * finiteRationalOptimizer coordinates vertices linear G j i +
2 / ((j : β) + 2) * finiteOptimizerSelection coordinates vertices linear G j i = _
rw [ih]
def rationalVertexSet {ΞΉ : Type*} (vertices : List (ΞΉ β β)) : Set (ΞΉ β β) :=
(fun p : ΞΉ β β => fun i => (p i : β)) '' {p | p β vertices}
/-- Every vector in the listed real convex hull is a probability vector. -/
theorem rationalVertexHull_probability {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(vertices : List (ΞΉ β β))
(hvertices : β p β vertices,
(β i β coordinates, (0 : β) β€ p i) β§ (β i β coordinates, (p i : β)) = 1) :
β p β convexHull β (rationalVertexSet vertices),
(β i β coordinates, 0 β€ p i) β§ (β i β coordinates, p i) = 1 := by
have hconvex : Convex β {p : ΞΉ β β |
(β i β coordinates, 0 β€ p i) β§ (β i β coordinates, p i) = 1} := by
intro p hp q hq a b ha hb hab
constructor
Β· intro i hi
exact add_nonneg (mul_nonneg ha (hp.1 i hi)) (mul_nonneg hb (hq.1 i hi))
Β· change (β i β coordinates, (a * p i + b * q i)) = 1
rw [sum_add_distrib, β mul_sum, β mul_sum, hp.2, hq.2, mul_one, mul_one]
exact hab
apply convexHull_min _ hconvex
rintro _ β¨p, hp, rflβ©
exact hvertices p hp
/-- Concrete finite vertex selection satisfies the required
linearization inequality against every real feasible mixture. -/
theorem finiteOptimizerSelection_maximizes {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(vertices : List (ΞΉ β β)) (linear : ΞΉ β β) (G j : β)
(hvertices : vertices β []) :
β best β convexHull β (rationalVertexSet vertices),
(β i β coordinates, (rationalSmoothedGradient G linear
(finiteRationalOptimizer coordinates vertices linear G j) i : β) * best i) β€
β i β coordinates, (rationalSmoothedGradient G linear
(finiteRationalOptimizer coordinates vertices linear G j) i : β) *
(finiteOptimizerSelection coordinates vertices linear G j i : β) := by
apply finite_linearization_maximizes_convexHull
rintro _ β¨p, hp, rflβ©
have hspec := (rationalLinearizationMaximizer_spec coordinates vertices
(rationalSmoothedGradient G linear (finiteRationalOptimizer coordinates vertices linear G j))
hvertices).2 p hp
dsimp only [finiteOptimizerSelection]
exact_mod_cast hspec
/-- Accuracy of the executable rational optimizer at every positive
entropy maximizer of its listed action hull. -/
theorem finiteRationalOptimizer_l1_precision {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(vertices : List (ΞΉ β β)) (linear : ΞΉ β β) (H : β) (maximizer : ΞΉ β β)
(hvertices : vertices β []) (hH : 4 β€ H)
(hprobability : β p β vertices,
(β i β coordinates, (0 : β) β€ p i) β§ (β i β coordinates, (p i : β)) = 1)
(hmaxQ : maximizer β convexHull β (rationalVertexSet vertices))
(hmax : β i β coordinates, 0 < maximizer i)
(hmaximize : IsMaxOn (entropyValue coordinates 1 (fun i => (linear i : β)))
(convexHull β (rationalVertexSet vertices)) maximizer) :
(β i β coordinates, |(finiteRationalOptimizer coordinates vertices linear
(H + coordinates.card + 2) ((H + coordinates.card + 2) ^ 80) i : β) - maximizer i|) β€
1 / (H : β) ^ 3 := by
let G := H + coordinates.card + 2
let initial : ΞΉ β β := vertices.headD (fun _ => 0)
let selected := finiteOptimizerSelection coordinates vertices linear G
have hinitialMem : initial β vertices := by
cases vertices with
| nil => exact False.elim (hvertices rfl)
| cons p tail => exact List.mem_cons_self
have hselectedMem j : selected j β vertices :=
(rationalLinearizationMaximizer_spec coordinates vertices
(rationalSmoothedGradient G linear (finiteRationalOptimizer coordinates vertices linear G j))
hvertices).1
have hinitialQ : (fun i => (initial i : β)) β convexHull β (rationalVertexSet vertices) :=
subset_convexHull β _ β¨initial, hinitialMem, rflβ©
have hselectedQ j : (fun i => (selected j i : β)) β convexHull β (rationalVertexSet vertices) :=
subset_convexHull β _ β¨selected j, hselectedMem j, rflβ©
have hmaxProbability := rationalVertexHull_probability coordinates vertices hprobability maximizer hmaxQ
have hchoose j := finiteOptimizerSelection_maximizes coordinates vertices linear G j
hvertices maximizer hmaxQ
simp_rw [finiteRationalOptimizer_eq_iterate] at hchoose β’
exact rational_optimizer_l1_precision coordinates (convexHull β (rationalVertexSet vertices)) H G
linear initial selected maximizer hH (by dsimp [G]; omega) (by dsimp [G]; omega)
(convex_convexHull β _) hinitialQ hselectedQ hmaxQ
(hprobability initial hinitialMem).1 (hprobability initial hinitialMem).2
(fun j => (hprobability (selected j) (hselectedMem j)).1)
(fun j => (hprobability (selected j) (hselectedMem j)).2)
hmax hmaxProbability.2 hmaximize hchoose
/-- Averaging the finite action list gives a feasible vector positive
at every covered coordinate, including lists with repeated actions. -/
theorem rationalVertexHull_positive_witness {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(vertices : List (ΞΉ β β)) (hvertices : vertices β [])
(hnonnegative : β p β vertices, β i β coordinates, (0 : β) β€ p i)
(hcovered : β i β coordinates, β p β vertices, (0 : β) < p i) :
β witness β convexHull β (rationalVertexSet vertices),
β i β coordinates, 0 < witness i := by
classical
let listed := vertices.toFinset
have hlisted : listed.Nonempty := (List.toFinset_nonempty_iff vertices).mpr hvertices
have hcard : 0 < (listed.card : β) := Nat.cast_pos.mpr (card_pos.mpr hlisted)
let weight : β := 1 / listed.card
have hweight : 0 < weight := by dsimp [weight]; positivity
have hweightSum : (β _ β listed, weight) = 1 := by
simp only [sum_const, nsmul_eq_mul]
dsimp only [weight]
field_simp
let witness : ΞΉ β β := β p β listed, weight β’ (fun i => (p i : β))
refine β¨witness, ?_, ?_β©
Β· exact (convex_convexHull β (rationalVertexSet vertices)).sum_mem
(fun _ _ => hweight.le) hweightSum (fun p hp =>
subset_convexHull β _ β¨p, List.mem_toFinset.mp hp, rflβ©)
Β· intro i hi
dsimp only [witness]
simp only [Finset.sum_apply, Pi.smul_apply, smul_eq_mul]
obtain β¨p, hp, hpiβ© := hcovered i hi
exact sum_pos' (fun q hq => mul_nonneg hweight.le
(hnonnegative q (List.mem_toFinset.mp hq) i hi))
β¨p, List.mem_toFinset.mpr hp, mul_pos hweight hpiβ©
/-- The finite optimizer accuracy theorem with exactly the manuscript's
probability and coordinate-coverage assumptions. The returned point is
the executable rational construction defined above. -/
theorem finite_entropy_optimizer {ΞΉ : Type*} (coordinates : Finset ΞΉ)
(vertices : List (ΞΉ β β)) (linear : ΞΉ β β) (H : β)
(hvertices : vertices β []) (hH : 4 β€ H)
(hprobability : β p β vertices,
(β i β coordinates, (0 : β) β€ p i) β§ (β i β coordinates, (p i : β)) = 1)
(hcovered : β i β coordinates, β p β vertices, (0 : β) < p i) :
β maximizer β convexHull β (rationalVertexSet vertices),
IsMaxOn (entropyValue coordinates 1 (fun i => (linear i : β)))
(convexHull β (rationalVertexSet vertices)) maximizer β§
(β i β coordinates, |(finiteRationalOptimizer coordinates vertices linear
(H + coordinates.card + 2) ((H + coordinates.card + 2) ^ 80) i : β) - maximizer i|) β€
1 / (H : β) ^ 3 := by
classical
have hfinite : ({p : ΞΉ β β | p β vertices} : Set (ΞΉ β β)).Finite := by
simp
have hcompact := (hfinite.image (fun p : ΞΉ β β => fun i => (p i : β))).isCompact_convexHull β
obtain β¨witness, hwitnessQ, hwitnessβ© := rationalVertexHull_positive_witness coordinates vertices
hvertices (fun p hp => (hprobability p hp).1) hcovered
obtain β¨maximizer, hmaxQ, hmaximizeβ© := exists_entropy_maximizer coordinates
(convexHull β (rationalVertexSet vertices)) 1 (fun i => (linear i : β)) hcompact β¨witness, hwitnessQβ©
have hmaxProbability := rationalVertexHull_probability coordinates vertices hprobability maximizer hmaxQ
have hmax := entropy_hull_maximizer_positive coordinates (convexHull β (rationalVertexSet vertices))
1 (fun i => (linear i : β)) maximizer witness (convex_convexHull β _) hmaxQ hwitnessQ
hmaxProbability.1 hwitness hmaximize
exact β¨maximizer, hmaxQ, hmaximize, finiteRationalOptimizer_l1_precision coordinates vertices linear H
maximizer hvertices hH hprobability hmaxQ hmax hmaximizeβ©
end EditApproximation
end OAI
import OAI.Combinatorics.EditApproximation.Geometry.Regret
import OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
/-!
# Finite numerical optimizer for edit-distance refinement
These are the explicit fixed-step recurrence and rational mixture
calculations from Section 9 of *An Almost-Linear Approximation Scheme
for Edit Distance* (September 24, 2026). The recurrence is an internal
analytic obligation of the manuscript, not an assumed published theorem.
-/
namespace EditApproximation
open Finset
/-- The conditional-gradient step size in the finite entropy optimizer. -/
noncomputable def frankWolfeStep (j : β) : β := 2 / ((j : β) + 2)
theorem frankWolfeStep_nonnegative (j : β) : 0 β€ frankWolfeStep j := by
unfold frankWolfeStep
positivity
theorem frankWolfeStep_le_one (j : β) : frankWolfeStep j β€ 1 := by
unfold frankWolfeStep
apply (div_le_oneβ (by positivity)).mpr
have := Nat.cast_nonneg (Ξ± := β) j
linarith
/-- The scalar induction step giving the optimizer's `8/(Ο(j+1))`
error term. -/
theorem frank_wolfe_scalar_step (Ο error x : β) (hΟ : 0 < Ο) (hx : 0 β€ x) :
(1 - 2 / (x + 3)) * (2 * error + 8 / (Ο * (x + 2))) +
2 * error * (2 / (x + 3)) + 2 * (2 / (x + 3)) ^ 2 / Ο β€
2 * error + 8 / (Ο * (x + 3)) := by
have h2 : 0 < x + 2 := by linarith
have h3 : 0 < x + 3 := by linarith
have hid :
(2 * error + 8 / (Ο * (x + 3))) -
((1 - 2 / (x + 3)) * (2 * error + 8 / (Ο * (x + 2))) +
2 * error * (2 / (x + 3)) + 2 * (2 / (x + 3)) ^ 2 / Ο) =
8 / (Ο * (x + 2) * (x + 3) ^ 2) := by
field_simp [hΟ.ne', h2.ne', h3.ne']
ring
have hnonneg : 0 β€ 8 / (Ο * (x + 2) * (x + 3) ^ 2) := by positivity
linarith
/-- The first update removes dependence on the initial objective gap.
The conclusion corresponds to manuscript indices `j β₯ 1`. -/
theorem frank_wolfe_gap_bound (Ο error : β) (gap : β β β)
(hΟ : 0 < Ο)
(hrecurrence : β j,
gap (j + 1) β€ (1 - frankWolfeStep j) * gap j +
2 * error * frankWolfeStep j + 2 * (frankWolfeStep j) ^ 2 / Ο) :
β j : β, gap (j + 1) β€ 2 * error + 8 / (Ο * ((j : β) + 2)) := by
intro j
induction j with
| zero =>
have hfirst : gap 1 β€ 2 * error + 2 / Ο := by
simpa [frankWolfeStep] using hrecurrence 0
have hratio : 8 / (Ο * (0 + 2)) = 4 / Ο := by ring
rw [Nat.cast_zero, hratio]
have hnonneg : 0 β€ 2 / Ο := by positivity
have hratio' : 4 / Ο = 2 * (2 / Ο) := by ring
rw [hratio']
norm_num only [Nat.zero_add]
linarith
| succ j ih =>
have hstep : frankWolfeStep (j + 1) = 2 / ((j : β) + 3) := by
norm_num [frankWolfeStep, Nat.cast_add, add_assoc]
have hcoef : 0 β€ 1 - frankWolfeStep (j + 1) :=
sub_nonneg.mpr (frankWolfeStep_le_one _)
have hmono := mul_le_mul_of_nonneg_left ih hcoef
have hrec := hrecurrence (j + 1)
rw [hstep] at hmono hrec
have hscalar := frank_wolfe_scalar_step Ο error (j : β) hΟ (Nat.cast_nonneg _)
have hbound : gap (j + 1 + 1) β€ 2 * error + 8 / (Ο * ((j : β) + 3)) := by
linarith
convert hbound using 1
norm_num [Nat.cast_add, add_assoc]
/-- Exact rational weight of the vertex selected at step `j`, after
`K` steps. -/
def optimizerMixtureWeight (K j : β) : β :=
2 * ((j : β) + 1) / ((K : β) * ((K : β) + 1))
theorem sum_optimizer_numerators (K : β) :
(β j β range K, 2 * ((j : β) + 1)) = (K : β) * ((K : β) + 1) := by
induction K with
| zero => simp
| succ K ih =>
rw [sum_range_succ, ih]
push_cast
ring
theorem optimizerMixtureWeight_positive (K j : β) (hK : 0 < K) :
0 < optimizerMixtureWeight K j := by