Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Chapter AttentionOutputVariance

Definition
ChapterAttentionOutputVariance

by leonardopedro · Oct 6, 2026 · Mathlib 0df444a (Lean v4.33.1)

definitionsformalizationtimepiece

Formal definitions for the timepiece Lean 4 formalization (source chapter BookProof/ChapterAttentionOutputVariance.lean): generated def bundle for ChapterAttentionOutputVariance. See BookProof/ChapterAttentionOutputVariance.lean for full context.

Definition code
import Definitions.Def_ChapterAttentionOutput
import Definitions.Def_ChapterObservableExpectation
import Definitions.Def_ChapterSoftmaxSharpness
import Mathlib


/-!
# Chapter "The Coherent State of Attention": the uncertainty of the output

The attention output is the expectation value of the contextual observable, so it
carries the second moment of a measurement as well as the first.  This module
proves the elementary facts about that spread.

* `sum_dist_sq_eq` — the **bias–variance decomposition**: for any reference point
  `c`, `∑ⱼ pⱼ‖vⱼ − c‖² = Var(p,v) + ‖o − c‖²`, where `o` is the attention output.
* `observableExpectation_minimizes` — hence the head output is the *least-squares
  summary* of the values it is reading: no other vector is closer to the values in
  the attention-weighted mean-square sense.
* `outputVariance_eq_sub` (König–Huygens) and `norm_observableExpectation_sq_le` —
  `Var = ∑ pⱼ‖vⱼ‖² − ‖o‖² ≥ 0`, the Jensen inequality for the output norm.
* `outputVariance_eq_zero_iff_of_pos` — at a finite temperature every weight is
  positive, so the output carries *no* uncertainty exactly when all the values
  agree; `outputVariance_scoreSoftmax_eq_zero_iff` states this for the head.

Everything here is `sorry`-free and `axiom`-free (only `propext`,
`Classical.choice`, `Quot.sound`).
-/

open scoped BigOperators RealInnerProductSpace

noncomputable section

namespace BookProof.ChapterAttentionOutputVariance

open BookProof.ChapterObservableExpectation BookProof.ChapterSoftmaxSharpness
  BookProof.ChapterSoftmaxOrder BookProof.ChapterAttentionOutput

variable {m : ℕ} {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E]

/-- The attention-weighted variance of the values around the output. -/
def outputVariance (p : Fin m → ℝ) (v : Fin m → E) : ℝ :=
  ∑ j, p j * ‖v j - observableExpectation p v‖ ^ 2

















/-! ## The attention head -/







end BookProof.ChapterAttentionOutputVariance

end
Source
https://github.com/leonardopedro/timepiece/blob/61595bc/BookProof/ChapterAttentionOutputVariance.lean

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me