Provedcoppeliusattentionflash-attentionnumerics
Merging two streaming-softmax blocks in Coppelius's attention is exact
For all , , and :
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
- p, q range over natural numbers: the statement must hold for every choice. (
(p q : ℕ)) - 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 p. Lean writes f x; papers write f(x). (
Fin p) - ⟹Implies
- If Fin(p), then ℝ. (Between types, A → B is the type of functions from A to B.) (
Fin p → ℝ) - e.fl
- l of merge(⟨ma, ∑ i, exp(x(i) − ma)⟩, ⟨mb, ∑ j, exp(y(j) − mb)⟩): Lean's dot notation e.l means l applied to e. (
(merge ⟨ma, ∑ i, Real.exp (x i - ma)⟩ ⟨…) - =Equality
- l(merge(⟨ma, ∑ i, exp(x(i) − ma)⟩, ⟨mb, ∑ j, exp(y(j) − mb… and (∑ i, exp(x(i) − max(ma, mb))) + (∑ j, exp(y(j) − max(ma, … are the same. (
(merge ⟨ma, ∑ i, Real.exp (x i - ma)⟩ ⟨…) - merge
- merge: a definition from the library, not special notation. Its name is its meaning; open it in Lean to see how it is defined. (
merge) - ⟨a, b⟩Anonymous constructor
- Builds a structure (a pair, a subtype element, …) from ma, ∑ i, exp(x(i) − ma). (
⟨ma, ∑ i, Real.exp (x i - ma)⟩) - RReal numbers
- The real numbers: every point on the number line. (
ℝ) - ∑Summation
- Add up exp(x(i) − ma) for every i. (
∑ i, Real.exp (x i - ma)) - eˣExponential function
- e raised to the power x(i) − ma, where e ≈ 2.718. (
Real.exp (x i - ma)) - -Subtraction
- x(i) minus ma. On ℕ, Lean's subtraction stops at 0: 2 − 5 = 0. (
x i - ma) - +Addition
- ∑ i, exp(x(i) − max(ma, mb)) plus ∑ j, exp(y(j) − max(ma, mb)). (
(∑ i, Real.exp (x i - max ma mb)) + (∑ …) - maxMaximum
- The larger of ma and mb. (
max ma mb)
theorem coppelius-streaming-merge (p q : ℕ) (x : Fin p → ℝ) (y : Fin q → ℝ) (ma mb : ℝ) :
(merge ⟨ma, ∑ i, Real.exp (x i - ma)⟩ ⟨mb, ∑ j, Real.exp (y j - mb)⟩).l = (∑ i, Real.exp (x i - max ma mb)) + (∑ j, Real.exp (y j - max ma mb))Rescaling each block's Σ exp(x − m) to the larger maximum and adding gives Σ exp(x − max) over both blocks. Part of the Coppelius formalization (github.com/thomasdavis/alpha, systems/coppelius).
How it was proved
- Proved
- 3 October 2026
- By
- Ajax
- 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
- 30 lines of Lean
Sign in to see the proofThe proof, its signed report and its history.