proofs
Provedsampleability-lawself-certifying-proposalfinite-sampleconversion-theorem

Certificate for the descent proposal: with an ε-accurate node oracle, N draws certify the cost factor within (1±δ) factors except w.p. ≤ ((1+2ε)^L + (1+2ε)^{3L})/(Nδ²)

For all L,N∈N\htmlData{mx=1}{L, N \in \htmlData{mx=0}{\mathbb{N}}}, s:(Fin⁡ L→Bool⁡)→R\htmlData{mx=7}{s : (\htmlData{mx=2}{\htmlData{mx=0}{\operatorname{Fin}}\,\htmlData{mx=1}{L}} \mathrel{\htmlData{mx=4}{\to}} \htmlData{mx=3}{\operatorname{Bool}}) \mathrel{\htmlData{mx=6}{\to}} \htmlData{mx=5}{\mathbb{R}}}, Z,ε,δ∈R\htmlData{mx=1}{Z, \varepsilon, \delta \in \htmlData{mx=0}{\mathbb{R}}}, m:N→(Fin⁡ L→Bool⁡)→R\htmlData{mx=9}{m : \htmlData{mx=0}{\mathbb{N}} \mathrel{\htmlData{mx=8}{\to}} (\htmlData{mx=3}{\htmlData{mx=1}{\operatorname{Fin}}\,\htmlData{mx=2}{L}} \mathrel{\htmlData{mx=5}{\to}} \htmlData{mx=4}{\operatorname{Bool}}) \mathrel{\htmlData{mx=7}{\to}} \htmlData{mx=6}{\mathbb{R}}}, phat:N→(Fin⁡ L→Bool⁡)→R\htmlData{mx=9}{\mathit{phat} : \htmlData{mx=0}{\mathbb{N}} \mathrel{\htmlData{mx=8}{\to}} (\htmlData{mx=3}{\htmlData{mx=1}{\operatorname{Fin}}\,\htmlData{mx=2}{L}} \mathrel{\htmlData{mx=5}{\to}} \htmlData{mx=4}{\operatorname{Bool}}) \mathrel{\htmlData{mx=7}{\to}} \htmlData{mx=6}{\mathbb{R}}}, pt,Q:N→(Fin⁡ L→Bool⁡)→R\htmlData{mx=9}{\mathit{pt}, Q : \htmlData{mx=0}{\mathbb{N}} \mathrel{\htmlData{mx=8}{\to}} (\htmlData{mx=3}{\htmlData{mx=1}{\operatorname{Fin}}\,\htmlData{mx=2}{L}} \mathrel{\htmlData{mx=5}{\to}} \htmlData{mx=4}{\operatorname{Bool}}) \mathrel{\htmlData{mx=7}{\to}} \htmlData{mx=6}{\mathbb{R}}} and hQ∈∀ℓ,b, Q(ℓ,b)={:(ℓ)<Lif hthen⁡({pt(ℓ,b)if b(⟨ℓ,h⟩)1−pt(ℓ,b)otherwise)otherwise else 1\htmlData{mx=30}{\mathit{hQ} \in \htmlData{mx=29}{\htmlData{mx=28}{\forall \ell, b,\ \htmlData{mx=3}{\htmlData{mx=0}{Q}(\htmlData{mx=1}{\ell}, \htmlData{mx=2}{b})} \mathrel{\htmlData{mx=27}{=}} \htmlData{mx=26}{\begin{cases} \htmlData{mx=5}{\mathtt{:}(\htmlData{mx=4}{\ell})} \mathrel{\htmlData{mx=7}{<}} \htmlData{mx=6}{L} & \text{if } \htmlData{mx=8}{h} \\ \htmlData{mx=25}{\htmlData{mx=9}{\operatorname{then}}\left(\htmlData{mx=24}{\begin{cases} \htmlData{mx=13}{\htmlData{mx=10}{\mathit{pt}}(\htmlData{mx=11}{\ell}, \htmlData{mx=12}{b})} & \text{if } \htmlData{mx=18}{\htmlData{mx=14}{b}(\htmlData{mx=17}{\left\langle \htmlData{mx=15}{\ell}, \htmlData{mx=16}{h} \right\rangle})} \\ \htmlData{mx=23}{1 - \htmlData{mx=22}{\htmlData{mx=19}{\mathit{pt}}(\htmlData{mx=20}{\ell}, \htmlData{mx=21}{b})}} & \text{otherwise} \end{cases}}\right)} & \text{otherwise} \end{cases}}}\,\mathtt{else\ 1}}}, if Z=∑bes(b)\htmlData{mx=0}{Z} \mathrel{\htmlData{mx=6}{=}} \htmlData{mx=5}{\sum_{b} \htmlData{mx=4}{e^{\htmlData{mx=3}{\htmlData{mx=1}{s}(\htmlData{mx=2}{b})}}}}, 0<ε0 \mathrel{\htmlData{mx=1}{<}} \htmlData{mx=0}{\varepsilon}, ∀ℓ,b, m(ℓ,b)=∑b′:Fin⁡ L→Bool⁡({es(b′)Zif (∀i:Fin⁡ L, i<ℓ  ⟹  b′(i)=b(i))0otherwise)\htmlData{mx=34}{\forall \ell, b,\ \htmlData{mx=3}{\htmlData{mx=0}{m}(\htmlData{mx=1}{\ell}, \htmlData{mx=2}{b})} \mathrel{\htmlData{mx=33}{=}} \htmlData{mx=32}{\sum_{b' : \htmlData{mx=6}{\htmlData{mx=4}{\operatorname{Fin}}\,\htmlData{mx=5}{L}} \mathrel{\htmlData{mx=8}{\to}} \htmlData{mx=7}{\operatorname{Bool}}} \left(\htmlData{mx=31}{\begin{cases} \htmlData{mx=14}{\frac{\htmlData{mx=12}{e^{\htmlData{mx=11}{\htmlData{mx=9}{s}(\htmlData{mx=10}{b'})}}}}{\htmlData{mx=13}{Z}}} & \text{if } (\htmlData{mx=30}{\forall i : \htmlData{mx=29}{\htmlData{mx=27}{\operatorname{Fin}}\,\htmlData{mx=28}{L}},\ \htmlData{mx=16}{\htmlData{mx=15}{i}} \mathrel{\htmlData{mx=18}{<}} \htmlData{mx=17}{\ell} \mathrel{\htmlData{mx=26}{\implies}} \htmlData{mx=21}{\htmlData{mx=19}{b'}(\htmlData{mx=20}{i})} \mathrel{\htmlData{mx=25}{=}} \htmlData{mx=24}{\htmlData{mx=22}{b}(\htmlData{mx=23}{i})}}) \\ 0 & \text{otherwise} \end{cases}}\right)}}, ∀ℓ, b,b′:Fin⁡ L→Bool⁡, (∀i:Fin⁡ L, i<ℓ  ⟹  b(i)=b′(i))  ⟹  phat(ℓ,b)=phat(ℓ,b′)\htmlData{mx=31}{\forall \ell,\ b, b' : \htmlData{mx=28}{\htmlData{mx=26}{\operatorname{Fin}}\,\htmlData{mx=27}{L}} \mathrel{\htmlData{mx=30}{\to}} \htmlData{mx=29}{\operatorname{Bool}},\ (\htmlData{mx=15}{\forall i : \htmlData{mx=14}{\htmlData{mx=12}{\operatorname{Fin}}\,\htmlData{mx=13}{L}},\ \htmlData{mx=1}{\htmlData{mx=0}{i}} \mathrel{\htmlData{mx=3}{<}} \htmlData{mx=2}{\ell} \mathrel{\htmlData{mx=11}{\implies}} \htmlData{mx=6}{\htmlData{mx=4}{b}(\htmlData{mx=5}{i})} \mathrel{\htmlData{mx=10}{=}} \htmlData{mx=9}{\htmlData{mx=7}{b'}(\htmlData{mx=8}{i})}}) \mathrel{\htmlData{mx=25}{\implies}} \htmlData{mx=19}{\htmlData{mx=16}{\mathit{phat}}(\htmlData{mx=17}{\ell}, \htmlData{mx=18}{b})} \mathrel{\htmlData{mx=24}{=}} \htmlData{mx=23}{\htmlData{mx=20}{\mathit{phat}}(\htmlData{mx=21}{\ell}, \htmlData{mx=22}{b'})}}, ∀ℓ, h:ℓ<L, b, 0<m(ℓ,b)  ⟹  ∣phat(ℓ,b)−m(ℓ+1,update⁡(b,⟨ℓ,h⟩,true⁡))m(ℓ,b)∣≤ε\htmlData{mx=33}{\forall \ell,\ h : \htmlData{mx=30}{\ell} \mathrel{\htmlData{mx=32}{<}} \htmlData{mx=31}{L},\ b,\ 0 \mathrel{\htmlData{mx=4}{<}} \htmlData{mx=3}{\htmlData{mx=0}{m}(\htmlData{mx=1}{\ell}, \htmlData{mx=2}{b})} \mathrel{\htmlData{mx=29}{\implies}} \htmlData{mx=26}{\left\lvert \htmlData{mx=25}{\htmlData{mx=8}{\htmlData{mx=5}{\mathit{phat}}(\htmlData{mx=6}{\ell}, \htmlData{mx=7}{b})} - \htmlData{mx=24}{\frac{\htmlData{mx=19}{\htmlData{mx=9}{m}(\htmlData{mx=11}{\htmlData{mx=10}{\ell} + 1}, \htmlData{mx=18}{\htmlData{mx=12}{\operatorname{update}}(\htmlData{mx=13}{b}, \htmlData{mx=16}{\left\langle \htmlData{mx=14}{\ell}, \htmlData{mx=15}{h} \right\rangle}, \htmlData{mx=17}{\operatorname{true}})})}}{\htmlData{mx=23}{\htmlData{mx=20}{m}(\htmlData{mx=21}{\ell}, \htmlData{mx=22}{b})}}}} \right\rvert} \mathrel{\htmlData{mx=28}{\leq}} \htmlData{mx=27}{\varepsilon}}, ∀ℓ,b, pt(ℓ,b)=max⁡(0,min⁡(1,phat(ℓ,b)))+ε1+2ε\htmlData{mx=17}{\forall \ell, b,\ \htmlData{mx=3}{\htmlData{mx=0}{\mathit{pt}}(\htmlData{mx=1}{\ell}, \htmlData{mx=2}{b})} \mathrel{\htmlData{mx=16}{=}} \htmlData{mx=15}{\frac{\htmlData{mx=11}{\htmlData{mx=9}{\max(0, \htmlData{mx=8}{\min(1, \htmlData{mx=7}{\htmlData{mx=4}{\mathit{phat}}(\htmlData{mx=5}{\ell}, \htmlData{mx=6}{b})})})} + \htmlData{mx=10}{\varepsilon}}}{\htmlData{mx=14}{1 + \htmlData{mx=13}{2\htmlData{mx=12}{\varepsilon}}}}}}, 0<N0 \mathrel{\htmlData{mx=1}{<}} \htmlData{mx=0}{N}, 0<δ0 \mathrel{\htmlData{mx=1}{<}} \htmlData{mx=0}{\delta} and δ<1\htmlData{mx=0}{\delta} \mathrel{\htmlData{mx=1}{<}} 1, then

∑f∈filter⁡(f↦¬((1−δ)⋅(∑b(es(b)Z)2∏ℓ=0L−1Q(ℓ,b))(1+δ)2<∑i(es(f(i))∏ℓ=0L−1Q(ℓ,f(i)))2N(∑ies(f(i))∏ℓ=0L−1Q(ℓ,f(i))N)2∧∑i(es(f(i))∏ℓ=0L−1Q(ℓ,f(i)))2N(∑ies(f(i))∏ℓ=0L−1Q(ℓ,f(i))N)2<(1+δ)⋅(∑b(es(b)Z)2∏ℓ=0L−1Q(ℓ,b))(1−δ)2))∏i(∏ℓ=0L−1Q(ℓ,f(i)))≤(1+2ε)L+((1+2ε)L)3N⋅δ2\begin{aligned} & \htmlData{mx=148}{\sum_{f \in \htmlData{mx=138}{\htmlData{mx=1}{\operatorname{filter}}\left(\htmlData{mx=137}{f \mapsto \htmlData{mx=127}{\lnot \left(\htmlData{mx=23}{\frac{\htmlData{mx=19}{(\htmlData{mx=3}{1 - \htmlData{mx=2}{\delta}}) \cdot \left(\htmlData{mx=18}{\sum_{b} \htmlData{mx=17}{\frac{\htmlData{mx=10}{\left(\htmlData{mx=9}{\frac{\htmlData{mx=7}{e^{\htmlData{mx=6}{\htmlData{mx=4}{s}(\htmlData{mx=5}{b})}}}}{\htmlData{mx=8}{Z}}}\right)^{2}}}{\htmlData{mx=16}{\prod_{\ell=0}^{\htmlData{mx=11}{L} - 1} \htmlData{mx=15}{\htmlData{mx=12}{Q}(\htmlData{mx=13}{\ell}, \htmlData{mx=14}{b})}}}}}\right)}}{\htmlData{mx=22}{(\htmlData{mx=21}{1 + \htmlData{mx=20}{\delta}})^{2}}}} \mathrel{\htmlData{mx=63}{<}} \htmlData{mx=62}{\frac{\htmlData{mx=42}{\frac{\htmlData{mx=40}{\sum_{i} \htmlData{mx=39}{\left(\htmlData{mx=38}{\frac{\htmlData{mx=29}{e^{\htmlData{mx=28}{\htmlData{mx=24}{s}(\htmlData{mx=27}{\htmlData{mx=25}{f}(\htmlData{mx=26}{i})})}}}}{\htmlData{mx=37}{\prod_{\ell=0}^{\htmlData{mx=30}{L} - 1} \htmlData{mx=36}{\htmlData{mx=31}{Q}(\htmlData{mx=32}{\ell}, \htmlData{mx=35}{\htmlData{mx=33}{f}(\htmlData{mx=34}{i})})}}}}\right)^{2}}}}{\htmlData{mx=41}{N}}}}{\htmlData{mx=61}{\left(\htmlData{mx=60}{\frac{\htmlData{mx=58}{\sum_{i} \htmlData{mx=57}{\frac{\htmlData{mx=48}{e^{\htmlData{mx=47}{\htmlData{mx=43}{s}(\htmlData{mx=46}{\htmlData{mx=44}{f}(\htmlData{mx=45}{i})})}}}}{\htmlData{mx=56}{\prod_{\ell=0}^{\htmlData{mx=49}{L} - 1} \htmlData{mx=55}{\htmlData{mx=50}{Q}(\htmlData{mx=51}{\ell}, \htmlData{mx=54}{\htmlData{mx=52}{f}(\htmlData{mx=53}{i})})}}}}}}{\htmlData{mx=59}{N}}}\right)^{2}}}} \mathbin{\htmlData{mx=126}{\land}} \htmlData{mx=102}{\frac{\htmlData{mx=82}{\frac{\htmlData{mx=80}{\sum_{i} \htmlData{mx=79}{\left(\htmlData{mx=78}{\frac{\htmlData{mx=69}{e^{\htmlData{mx=68}{\htmlData{mx=64}{s}(\htmlData{mx=67}{\htmlData{mx=65}{f}(\htmlData{mx=66}{i})})}}}}{\htmlData{mx=77}{\prod_{\ell=0}^{\htmlData{mx=70}{L} - 1} \htmlData{mx=76}{\htmlData{mx=71}{Q}(\htmlData{mx=72}{\ell}, \htmlData{mx=75}{\htmlData{mx=73}{f}(\htmlData{mx=74}{i})})}}}}\right)^{2}}}}{\htmlData{mx=81}{N}}}}{\htmlData{mx=101}{\left(\htmlData{mx=100}{\frac{\htmlData{mx=98}{\sum_{i} \htmlData{mx=97}{\frac{\htmlData{mx=88}{e^{\htmlData{mx=87}{\htmlData{mx=83}{s}(\htmlData{mx=86}{\htmlData{mx=84}{f}(\htmlData{mx=85}{i})})}}}}{\htmlData{mx=96}{\prod_{\ell=0}^{\htmlData{mx=89}{L} - 1} \htmlData{mx=95}{\htmlData{mx=90}{Q}(\htmlData{mx=91}{\ell}, \htmlData{mx=94}{\htmlData{mx=92}{f}(\htmlData{mx=93}{i})})}}}}}}{\htmlData{mx=99}{N}}}\right)^{2}}}} \mathrel{\htmlData{mx=125}{<}} \htmlData{mx=124}{\frac{\htmlData{mx=120}{(\htmlData{mx=104}{1 + \htmlData{mx=103}{\delta}}) \cdot \left(\htmlData{mx=119}{\sum_{b} \htmlData{mx=118}{\frac{\htmlData{mx=111}{\left(\htmlData{mx=110}{\frac{\htmlData{mx=108}{e^{\htmlData{mx=107}{\htmlData{mx=105}{s}(\htmlData{mx=106}{b})}}}}{\htmlData{mx=109}{Z}}}\right)^{2}}}{\htmlData{mx=117}{\prod_{\ell=0}^{\htmlData{mx=112}{L} - 1} \htmlData{mx=116}{\htmlData{mx=113}{Q}(\htmlData{mx=114}{\ell}, \htmlData{mx=115}{b})}}}}}\right)}}{\htmlData{mx=123}{(\htmlData{mx=122}{1 - \htmlData{mx=121}{\delta}})^{2}}}}\right)}}\right)}} \htmlData{mx=147}{\prod_{i} \left(\htmlData{mx=146}{\prod_{\ell=0}^{\htmlData{mx=139}{L} - 1} \htmlData{mx=145}{\htmlData{mx=140}{Q}(\htmlData{mx=141}{\ell}, \htmlData{mx=144}{\htmlData{mx=142}{f}(\htmlData{mx=143}{i})})}}\right)}} \\ & \quad \htmlData{mx=0}{\leq} \htmlData{mx=165}{\frac{\htmlData{mx=160}{\htmlData{mx=153}{(\htmlData{mx=151}{1 + \htmlData{mx=150}{2\htmlData{mx=149}{\varepsilon}}})^{\htmlData{mx=152}{L}}} + \htmlData{mx=159}{(\htmlData{mx=158}{(\htmlData{mx=156}{1 + \htmlData{mx=155}{2\htmlData{mx=154}{\varepsilon}}})^{\htmlData{mx=157}{L}}})^{3}}}}{\htmlData{mx=164}{\htmlData{mx=161}{N} \cdot \htmlData{mx=163}{\htmlData{mx=162}{\delta}^{2}}}}} \end{aligned}
What the notation means · or point at any symbol
NNatural numbers
The natural numbers 0, 1, 2, …. In Lean they start at 0. (ℕ)
x ∈ TVariables
L, N range over natural numbers: the statement must hold for every choice. ((L N : ℕ))
=Equality
Z and ∑ b, exp(s(b)) are the same. (Z = ∑ b, Real.exp (s b))
<Less than
0 is strictly smaller than ε. (0 < ε)
x : TVariables
pt, Q range over ℕ → (Fin L → Bool) → ℝ: the statement must hold for every choice. ((pt Q : ℕ → (Fin L → Bool) → ℝ))
Fin
Fin: a definition from the library, not special notation. Its name is its meaning; open it in Lean to see how it is defined. (Fin)
f(x)Function application
Fin applied to L. Lean writes f x; papers write f(x). (Fin L)
⟹Implies
If Fin(L), then Bool. (Between types, A → B is the type of functions from A to B.) (Fin L → Bool)
∑Summation
Add up exp(s(b)) for every b. (∑ b, Real.exp (s b))
filter
Finset.univ.filter: a definition from the library, not special notation. Its name is its meaning; open it in Lean to see how it is defined. (Finset.univ.filter)
Bool
Bool: a definition from the library, not special notation. Its name is its meaning; open it in Lean to see how it is defined. (Bool)
eˣExponential function
e raised to the power s(b), where e ≈ 2.718. (Real.exp (s b))
RReal numbers
The real numbers: every point on the number line. (ℝ)
maxMaximum
The larger of 0 and min(1, phat(ℓ, b)). (max 0 (min 1 (phat ℓ b)))
minMinimum
The smaller of 1 and phat(ℓ, b). (min 1 (phat ℓ b))
x ↦ f(x)Function (λ-abstraction)
The function sending f to ¬((1 − δ) · (∑ b, (exp(s(b))/Z)^2/(∏ ℓ, Q(ℓ, b)))/(1 + δ)^…. Lean writes fun x => …; papers write x ↦ …. (fun f : Fin N → (Fin L → Bool) => ¬ ((1…)
then
then: a definition from the library, not special notation. Its name is its meaning; open it in Lean to see how it is defined. (then)
|x|Absolute value
The size of phat(ℓ, b) − m(ℓ + 1, update(b, ⟨ℓ, h⟩, true))/m(ℓ, b) without its sign. (|phat ℓ b - m (ℓ + 1) (Function.update …)
≤At most
|phat(ℓ, b) − m(ℓ + 1, update(b, ⟨ℓ, h⟩, true))/m(ℓ, b)| is less than or equal to ε. (|phat ℓ b - m (ℓ + 1) (Function.update …)
-Subtraction
phat(ℓ, b) minus m(ℓ + 1, update(b, ⟨ℓ, h⟩, true))/m(ℓ, b). On ℕ, Lean's subtraction stops at 0: 2 − 5 = 0. (phat ℓ b - m (ℓ + 1) (Function.update b…)
{ a if c; b otherwiseCases (if … then … else)
exp(s(b'))/Z when ∀ i, i < ℓ → b'(i) = b(i), and 0 otherwise. (if (∀ i : Fin L, (i : ℕ) < ℓ → b' i = b…)
∀For all
The statement after the comma holds for every i. (∀ i : Fin L, (i : ℕ) < ℓ → b' i = b i)
+Addition
ℓ plus 1. (ℓ + 1)
(x : T)As natural numbers
i read as an element of natural numbers. Mathematicians leave this implicit; Lean needs it to know which kind of number is meant. ((i : ℕ))
update
Function.update: a definition from the library, not special notation. Its name is its meaning; open it in Lean to see how it is defined. (Function.update)
·Multiplication
2 times ε. (2 * ε)
¬Not
It is not the case that (1 − δ) · (∑ b, (exp(s(b))/Z)^2/(∏ ℓ, Q(ℓ, b)))/(1 + δ)^2 …. (¬ ((1 - δ) * (∑ b, (Real.exp (s b) / Z)…)
∧And
Both hold: (1 − δ) · (∑ b, (exp(s(b))/Z)^2/(∏ ℓ, Q(ℓ, b)))/(1 + δ)^2 …, and (∑ i, (exp(s(f(i)))/(∏ ℓ, Q(ℓ, f(i))))^2)/N/((∑ i, exp(s(f…. ((1 - δ) * (∑ b, (Real.exp (s b) / Z) ^ …)
⟨a, b⟩Anonymous constructor
Builds a structure (a pair, a subtype element, …) from ℓ, h. (⟨ℓ, h⟩)
true
true: a definition from the library, not special notation. Its name is its meaning; open it in Lean to see how it is defined. (true)
aᵇPower
exp(s(b))/Z raised to the power 2. ((Real.exp (s b) / Z) ^ 2)
a/bDivision
exp(s(b')) divided by Z. In Lean, dividing by 0 gives 0. (Real.exp (s b') / Z)
∏Product
Multiply together Q(ℓ, b) for ℓ = 0, 1, …, L − 1. (∏ ℓ ∈ Finset.range L, Q ℓ b)

Answers review round 2 (codex): the finite-sample certificate's ratio bound K is derived, not assumed. For attention scores s over 2^L keys and the smoothed descent proposal r = Π_ℓ Q_ℓ built from any prefix-dependent ε-accurate node oracle, the Conversion Theorem (cv-conversion-theorem, embedded) gives r a distribution with π ≤ (1+2ε)^L·r; the finite-sample certificate (sc-finite-sample-certificate, embedded) then applies with K = (1+2ε)^L. So N i.i.d. draws from the proposal yield the normaliser-free statistic mean(w²)/mean(w)² within [(1−δ)C/(1+δ)², (1+δ)C/(1−δ)²] of the true cost factor C except with probability ≤ (K + K³)/(Nδ²). At ε = 1/L, K ≤ e², so a constant number of draws per δ² certifies the cost. One statement, no assumed K.

How it was proved

Proved
5 October 2026
By
Ajax, with the agent “Baguette math & proofs (Claude Code, 2026-10-03)”
Checked by
Lean's kernel (Lean 4.33.1, with Mathlib); the proof is signed and replays offline
Axioms
Classical.choice, Quot.sound, propext
Proof
476 lines of Lean
Sign in to see the proofThe proof, its signed report and its history.

More proved statements