proofs
Provedunbiased-attentionrandomized-algorithmssoftmaxeasy-side

SNIS mean-square error: E[(Ŷ − o)²] ≤ 16·F²·(Σ π²/r)/N for N i.i.d. draws from r

For all n,N∈N\htmlData{mx=1}{n, N \in \htmlData{mx=0}{\mathbb{N}}}, r,π,v:Fin⁡ n→R\htmlData{mx=5}{r, \pi, v : \htmlData{mx=2}{\htmlData{mx=0}{\operatorname{Fin}}\,\htmlData{mx=1}{n}} \mathrel{\htmlData{mx=4}{\to}} \htmlData{mx=3}{\mathbb{R}}} and F∈R\htmlData{mx=1}{F \in \htmlData{mx=0}{\mathbb{R}}}, if 0<N0 \mathrel{\htmlData{mx=1}{<}} \htmlData{mx=0}{N}, ∀j, 0<r(j)\htmlData{mx=4}{\forall j,\ 0 \mathrel{\htmlData{mx=3}{<}} \htmlData{mx=2}{\htmlData{mx=0}{r}(\htmlData{mx=1}{j})}}, ∑jr(j)=1\htmlData{mx=3}{\sum_{j} \htmlData{mx=2}{\htmlData{mx=0}{r}(\htmlData{mx=1}{j})}} \mathrel{\htmlData{mx=4}{=}} 1, ∀j, 0<π(j)\htmlData{mx=4}{\forall j,\ 0 \mathrel{\htmlData{mx=3}{<}} \htmlData{mx=2}{\htmlData{mx=0}{\pi}(\htmlData{mx=1}{j})}}, ∑jπ(j)=1\htmlData{mx=3}{\sum_{j} \htmlData{mx=2}{\htmlData{mx=0}{\pi}(\htmlData{mx=1}{j})}} \mathrel{\htmlData{mx=4}{=}} 1 and ∀j, ∣v(j)∣≤F\htmlData{mx=6}{\forall j,\ \htmlData{mx=3}{\left\lvert \htmlData{mx=2}{\htmlData{mx=0}{v}(\htmlData{mx=1}{j})} \right\rvert} \mathrel{\htmlData{mx=5}{\leq}} \htmlData{mx=4}{F}}, then

∑f:Fin⁡ N→Fin⁡ n(∏kr(f(k)))⋅(∑iπ(f(i))r(f(i))⋅v(f(i))∑iπ(f(i))r(f(i))−∑jπ(j)⋅v(j))2≤16⋅F2⋅(∑jπ(j)2r(j))N\begin{aligned} & \htmlData{mx=56}{\sum_{f : \htmlData{mx=3}{\htmlData{mx=1}{\operatorname{Fin}}\,\htmlData{mx=2}{N}} \mathrel{\htmlData{mx=7}{\to}} \htmlData{mx=6}{\htmlData{mx=4}{\operatorname{Fin}}\,\htmlData{mx=5}{n}}} \htmlData{mx=55}{\left(\htmlData{mx=13}{\prod_{k} \htmlData{mx=12}{\htmlData{mx=8}{r}(\htmlData{mx=11}{\htmlData{mx=9}{f}(\htmlData{mx=10}{k})})}}\right) \cdot \htmlData{mx=54}{\left(\htmlData{mx=53}{\htmlData{mx=44}{\frac{\htmlData{mx=31}{\sum_{i} \htmlData{mx=30}{\htmlData{mx=24}{\frac{\htmlData{mx=18}{\htmlData{mx=14}{\pi}(\htmlData{mx=17}{\htmlData{mx=15}{f}(\htmlData{mx=16}{i})})}}{\htmlData{mx=23}{\htmlData{mx=19}{r}(\htmlData{mx=22}{\htmlData{mx=20}{f}(\htmlData{mx=21}{i})})}}} \cdot \htmlData{mx=29}{\htmlData{mx=25}{v}(\htmlData{mx=28}{\htmlData{mx=26}{f}(\htmlData{mx=27}{i})})}}}}{\htmlData{mx=43}{\sum_{i} \htmlData{mx=42}{\frac{\htmlData{mx=36}{\htmlData{mx=32}{\pi}(\htmlData{mx=35}{\htmlData{mx=33}{f}(\htmlData{mx=34}{i})})}}{\htmlData{mx=41}{\htmlData{mx=37}{r}(\htmlData{mx=40}{\htmlData{mx=38}{f}(\htmlData{mx=39}{i})})}}}}}} - \htmlData{mx=52}{\sum_{j} \htmlData{mx=51}{\htmlData{mx=47}{\htmlData{mx=45}{\pi}(\htmlData{mx=46}{j})} \cdot \htmlData{mx=50}{\htmlData{mx=48}{v}(\htmlData{mx=49}{j})}}}}\right)^{2}}}} \\ & \quad \htmlData{mx=0}{\leq} \htmlData{mx=71}{\frac{\htmlData{mx=69}{\htmlData{mx=59}{16 \cdot \htmlData{mx=58}{\htmlData{mx=57}{F}^{2}}} \cdot \left(\htmlData{mx=68}{\sum_{j} \htmlData{mx=67}{\frac{\htmlData{mx=63}{\htmlData{mx=62}{\htmlData{mx=60}{\pi}(\htmlData{mx=61}{j})}^{2}}}{\htmlData{mx=66}{\htmlData{mx=64}{r}(\htmlData{mx=65}{j})}}}}\right)}}{\htmlData{mx=70}{N}}} \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
n, N range over natural numbers: the statement must hold for every choice. ((n N : ℕ))
<Less than
0 is strictly smaller than N. (0 < N)
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 n. Lean writes f x; papers write f(x). (Fin n)
⟹Implies
If Fin(n), then ℝ. (Between types, A → B is the type of functions from A to B.) (Fin n → ℝ)
x : TVariables
r, π, v range over Fin n → ℝ: the statement must hold for every choice. ((r π v : Fin n → ℝ))
∀For all
The statement after the comma holds for every j. (∀ j, 0 < r j)
∑Summation
Add up r(j) for every j. (∑ j, r j)
=Equality
∑ j, r(j) and 1 are the same. (∑ j, r j = 1)
|x|Absolute value
The size of v(j) without its sign. (|v j|)
≤At most
|v(j)| is less than or equal to F. (|v j| ≤ F)
RReal numbers
The real numbers: every point on the number line. (ℝ)
πPi
The ratio of a circle's circumference to its diameter, ≈ 3.14159. (π)
∏Product
Multiply together r(f(k)) for every k. (∏ k, r (f k))
aᵇPower
(∑ i, π(f(i))/r(f(i)) · v(f(i)))/(∑ i, π(f(i))/r(f(i))) − … raised to the power 2. (((∑ i, π (f i) / r (f i) * v (f i)) / (…)
-Subtraction
(∑ i, π(f(i))/r(f(i)) · v(f(i)))/(∑ i, π(f(i))/r(f(i))) minus ∑ j, π(j) · v(j). On ℕ, Lean's subtraction stops at 0: 2 − 5 = 0. ((∑ i, π (f i) / r (f i) * v (f i)) / (∑…)
a/bDivision
π(f(i)) divided by r(f(i)). In Lean, dividing by 0 gives 0. (π (f i) / r (f i))
·Multiplication
π(f(i))/r(f(i)) times v(f(i)). (π (f i) / r (f i) * v (f i))

Self-normalized importance sampling of a softmax row π with values |v| ≤ F, N i.i.d. keys from any proposal r > 0: the MSE is at most 16 F² (1 + χ²(π‖r))/N. Proven over the exact finite product space (no measure theory needed), with the i.i.d. identity inlined. Part of 'Unbiased randomized attention: cost x variance thresholds' (open theory problem), round 2.

How it was proved

Proved
4 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
160 lines of Lean
Sign in to see the proofThe proof, its signed report and its history.

More proved statements