Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Chapter AttentionCollision

Definition
ChapterAttentionCollision

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

definitionsformalizationtimepiece

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

Definition code
import Definitions.Def_ChapterAttentionEntropy
import Definitions.Def_ChapterSoftmaxOrder
import Definitions.Def_ChapterSoftmaxSharpness
import Mathlib


/-!
# Chapter "The Coherent State of Attention": how many keys is the head actually reading?

The Shannon entropy of `ChapterAttentionEntropy` measures the uncertainty of the
Born measurement in nats.  Practitioners usually want the same information as a
*count*: how many keys does a head effectively attend to?  The standard answer is
the **participation ratio** — the reciprocal of the collision probability

`P₂(p) = ∑ⱼ pⱼ²`,  `N_eff(p) = 1 / P₂(p)`,

which is the exponential of the Rényi-2 (collision) entropy `H₂ = −log P₂`.  This
module proves that this count behaves exactly as a count should.

* `collisionProb_le_one`, `inv_card_le_collisionProb` (Cauchy–Schwarz) —
  `1/m ≤ P₂ ≤ 1`, hence `one_le_effectiveSupport` and
  `effectiveSupport_le_card`: a head reads at least one and at most `m` keys.
* `collisionProb_uniform`, `effectiveSupport_uniform` — at infinite temperature
  the count is exactly `m`, and `effectiveSupport_scoreSoftmax_zero` says the same
  for the attention distribution at `β = 0`.
* `renyi2_le_shannonEntropy` — the Rényi-2 entropy never exceeds the Shannon
  entropy (a tangent-line/Jensen argument for `log`), so the participation ratio
  is a *conservative* count: `N_eff ≤ exp H`.

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

open scoped BigOperators

noncomputable section

namespace BookProof.ChapterAttentionCollision

open BookProof.ChapterSoftmaxSharpness BookProof.ChapterSoftmaxOrder
  BookProof.ChapterAttentionEntropy

variable {m : ℕ}

/-! ## The collision probability and the participation ratio -/

/-- The **collision probability** `P₂(p) = ∑ pⱼ²`: the chance that two independent
Born measurements return the same key. -/
def collisionProb (p : Fin m → ℝ) : ℝ := ∑ j, (p j) ^ 2

/-- The **participation ratio** `N_eff = 1/P₂`: the effective number of keys the
head is reading. -/
def effectiveSupport (p : Fin m → ℝ) : ℝ := 1 / collisionProb p

/-- The **Rényi-2 (collision) entropy** `H₂ = −log P₂`. -/
def renyi2 (p : Fin m → ℝ) : ℝ := -Real.log (collisionProb p)

















/-! ## Rényi-2 versus Shannon -/







/-! ## The attention distribution -/









end BookProof.ChapterAttentionCollision

end
Source
https://github.com/leonardopedro/timepiece/blob/61595bc/BookProof/ChapterAttentionCollision.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