Provedunbiased-attentionrandomized-algorithmssoftmaxeasy-side
The softmax score-gradient is a covariance: Σ π_j (u_j − E_π u) k_j = E_π[u k] − E_π[u] E_π[k]
For all and , if , then
What the notation means · or point at any symbol
- NNatural numbers
- The natural numbers 0, 1, 2, …. In Lean they start at 0. (
ℕ) - 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
- π, u, k range over Fin n → ℝ: the statement must hold for every choice. (
(π u k : Fin n → ℝ)) - ∑Summation
- Add up π(j) for every j. (
∑ j, π j) - =Equality
- ∑ j, π(j) and 1 are the same. (
∑ j, π j = 1) - πPi
- The ratio of a circle's circumference to its diameter, ≈ 3.14159. (
π) - RReal numbers
- The real numbers: every point on the number line. (
ℝ) - -Subtraction
- u(j) minus ∑ i, π(i) · u(i). On ℕ, Lean's subtraction stops at 0: 2 − 5 = 0. (
u j - ∑ i, π i * u i) - ·Multiplication
- π(i) times u(i). (
π i * u i)
theorem ua-gradient-is-covariance {n : ℕ} (π u k : Fin n → ℝ) (hπ : ∑ j, π j = 1) :
∑ j, π j * (u j - ∑ i, π i * u i) * k j = ∑ j, π j * (u j * k j) - (∑ j, π j * u j) * (∑ j, π j * k j)With u_j = g·v_j (upstream gradient times value), the attention gradient with respect to the query is Σ_j π_j (u_j − E u) k_j, a covariance under the softmax row. It is a product of softmax expectations, so the forward estimators extend to gradients. Part of 'Unbiased randomized attention: cost x variance thresholds', round 6 (gradients).
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
- 12 lines of Lean
Sign in to see the proofThe proof, its signed report and its history.