Platonic Representation Theorem for JEPAs: world, positive pairs, spectral objective, nuisance, views and next-token loss
DefinitionArxiv2610_39302_BasicObjects of Section 2 and Appendix A of Balestriero and LeCun (2026), and of the subsample interval of Appendix C.
- World and positive pairs (Section 2.1). A world is a finite set of states with probabilities , . A positive-pair law is a symmetric law on pairs of states whose two marginals equal . The same notion is used for a law on pairs of observations with marginal .
- Embeddings and rotations. An embedding is , with ; an orthogonal matrix acts by . The law of the embeddings is .
- JEPA objective (eq. 1). For a prediction term and an anti-collapse term that is a function of the law of the embeddings, , and a modality with rendering and encoder has . The standing assumptions are that , that rotating every embedding leaves unchanged, and that takes values in . The minimisers of an objective are unique up to rotation if any two of them satisfy for some .
- Spectral objective (Proposition 1). , and is if the law of the embeddings has mean and second moment , and otherwise. An embedding on a finite set with law is centred and whitened if and .
- Spectrum. with , ; its eigenvalues with multiplicity are , with for . The Markov operator is . A spectral embedding is for orthonormal eigenvectors of , orthogonal to , with eigenvalues . and are the spectral and Frobenius norms, , and the right side of eq. (3) is , read as when .
- Observations and nuisance (Section 2.3). An observation of a finite set with law is of the state ; its state marginal is . is the conditional mean, , and the scene-explained fraction is . With nuisance independent of , the observations are pairs with law and .
- Good and bad views (Proposition 3). A good-view JEPA has positive-pair law . For row-stochastic , with stationary laws , , the bad-view law is the law of two corruptions , drawn independently given one clean observation , with . The (resp. ) are the eigenvalues of on (resp. on ), i.e. those of the normalised kernel of . The are the products , , with multiplicity, and is the number of pairs with and .
- Formal Theorem 4 (Appendix A.4). For a law on pairs of observations: the induced world kernel ; the conditional expectation onto functions of the state in ; ( if there is no such ); and , the operator and Hilbert–Schmidt norms of on ; for the eigenvalues of ; ( if ). A paired coupling is a law on with marginals that only pairs observations of the same state. Merging observations by sums and over the groups.
- Next-token prediction (eq. 6). , the loss is , and the expected loss over finitely many contexts with weights and conditionals is .
- Subsample spread (Appendix C). For scores : , the subset mean , , and the spread over uniformly random -subsets.
Formalization Note The eigenvalues are the roots of the characteristic polynomial of in decreasing order. The convention appears either as a hypothesis that applies only when or through an extended-real eigenvalue equal to beyond . is the sum of the square roots of the eigenvalues of . Operators on are written as matrices acting on functions ; their norms are taken in the metric.
import Mathlib
/-!
Balestriero and LeCun, *Proving and Improving the Platonic Representation Hypothesis with JEPAs*,
arXiv:2610.39302v1 (2026). Objects of Section 2 (Sections 2.1-2.4) and Appendix A (A.1-A.5): the
finite world, positive-pair laws, the JEPA objective of eq. (1), the normalised adjacency and its
spectrum, spectral embeddings, observations with nuisance, good-view and bad-view positive laws,
the operators of the formal Theorem 4, and the next-token loss of eq. (6); and the subsample
spread of Appendix C ("Uncertainty on WIT").
-/
open MeasureTheory
noncomputable section
namespace Arxiv2610_39302
/-! ### Section 2.1: world, embeddings, JEPA objective -/
/-- Section 2.1: squared Euclidean norm `‖a‖² = ∑ᵢ aᵢ²` of an embedding `a ∈ ℝ^k`. -/
def sqNorm {k : ℕ} (a : Fin k → ℝ) : ℝ := ∑ i, a i ^ 2
/-- Proposition 1 (Section 2.1): the prediction term `ℓ(a, b) = ‖a - b‖²`. -/
def sqDist {k : ℕ} (a b : Fin k → ℝ) : ℝ := sqNorm (a - b)
/-- Section 2.1: the action `a ↦ Q a` of an orthogonal matrix `Q ∈ O(k)` on an embedding. -/
def rot {k : ℕ} (Q : Matrix.orthogonalGroup (Fin k) ℝ) (a : Fin k → ℝ) : Fin k → ℝ :=
(Q : Matrix (Fin k) (Fin k) ℝ).mulVec a
/-- Section 2.1: `p` is a law on the finite set `Z` with `p(z) > 0`, and `π` is a symmetric law on
pairs whose two marginals equal `p` (a positive-pair distribution). Used verbatim for laws `W` on
pairs of observations with marginal `ω` (Appendix A.4, formal Theorem 4). -/
def IsPairLaw {Z : Type*} [Fintype Z] (p : Z → ℝ) (π : Z → Z → ℝ) : Prop :=
(∀ z, 0 < p z) ∧ (∑ z, p z = 1) ∧ (∀ z z', 0 ≤ π z z') ∧ (∀ z z', π z z' = π z' z) ∧
(∀ z, ∑ z', π z z' = p z)
/-- Section 2.1: the distribution of the embeddings `h(z)`, `z ∼ p`, namely `∑_z p(z) δ_{h(z)}`. -/
def embLaw {Z : Type*} [Fintype Z] {k : ℕ} (p : Z → ℝ) (h : Z → Fin k → ℝ) :
Measure (Fin k → ℝ) :=
∑ z, ENNReal.ofReal (p z) • Measure.dirac (h z)
/-- Section 2.1, standing assumptions on eq. (1): the prediction term is rotation invariant,
`ℓ(Qa, Qb) = ℓ(a, b)`; rotating every embedding leaves the anti-collapse term unchanged; and the
anti-collapse term takes values in `ℝ ∪ {+∞}` (a hard constraint is `Ω ∈ {0, ∞}`). The
anti-collapse term is a function of the law of the embeddings, as the paper requires. -/
def IsJEPAObjective {Z : Type*} [Fintype Z] {k : ℕ} (p : Z → ℝ)
(ℓ : (Fin k → ℝ) → (Fin k → ℝ) → ℝ) (Om : Measure (Fin k → ℝ) → EReal) : Prop :=
(∀ (Q : Matrix.orthogonalGroup (Fin k) ℝ) (a b : Fin k → ℝ), ℓ (rot Q a) (rot Q b) = ℓ a b) ∧
(∀ (h : Z → Fin k → ℝ) (Q : Matrix.orthogonalGroup (Fin k) ℝ),
Om (embLaw p (fun z => rot Q (h z))) = Om (embLaw p h)) ∧
(∀ μ, Om μ ≠ ⊥)
/-- Section 2.1: the objective written on world states,
`L_π(h) = E_{(z,z')∼π} ℓ(h(z), h(z')) + Ω(h)`, for `h : Z → ℝ^k`. -/
def worldLoss {Z : Type*} [Fintype Z] {k : ℕ} (p : Z → ℝ) (π : Z → Z → ℝ)
(ℓ : (Fin k → ℝ) → (Fin k → ℝ) → ℝ) (Om : Measure (Fin k → ℝ) → EReal)
(h : Z → Fin k → ℝ) : EReal :=
((∑ z, ∑ z', π z z' * ℓ (h z) (h z') : ℝ) : EReal) + Om (embLaw p h)
/-- Eq. (1), Section 2.1: the objective `L_m(f) = E_{(z,z')∼π} ℓ(f(g(z)), f(g(z'))) + Ω(f)` of a
JEPA of a modality with rendering `g : Z → X` and encoder `f : X → ℝ^k`; `Ω` sees the law of the
embeddings `f(g(z))`, `z ∼ p`. -/
def modalityLoss {Z X : Type*} [Fintype Z] {k : ℕ} (p : Z → ℝ) (π : Z → Z → ℝ)
(ℓ : (Fin k → ℝ) → (Fin k → ℝ) → ℝ) (Om : Measure (Fin k → ℝ) → EReal) (g : Z → X)
(f : X → Fin k → ℝ) : EReal :=
((∑ z, ∑ z', π z z' * ℓ (f (g z)) (f (g z')) : ℝ) : EReal) + Om (embLaw p (fun z => f (g z)))
/-- Theorem 1 (Section 2.1): the minimisers of an objective `L` on embeddings `h : Z → ℝ^k` are
unique up to rotation: any two minimisers `h, h'` satisfy `h' = Q h` for some `Q ∈ O(k)`. -/
def UniqueUpToRotation {Z : Type*} {k : ℕ} (L : (Z → Fin k → ℝ) → EReal) : Prop :=
∀ h h' : Z → Fin k → ℝ, (∀ h'', L h ≤ L h'') → (∀ h'', L h' ≤ L h'') →
∃ Q : Matrix.orthogonalGroup (Fin k) ℝ, ∀ z, h' z = rot Q (h z)
open Classical in
/-- Proposition 1 (Section 2.1): the anti-collapse term that whitens the embeddings as a hard
constraint: `0` if the law `μ` of the embeddings has mean `0` and second moment `I_k`, `+∞`
otherwise. -/
def whiteningReg {k : ℕ} (μ : Measure (Fin k → ℝ)) : EReal :=
if (∀ i, ∫ v, v i ∂μ = 0) ∧ (∀ i j, ∫ v, v i * v j ∂μ = if i = j then 1 else 0) then 0 else ⊤
/-- Proposition 1 (Section 2.1): the spectral objective, eq. (1) on world states with
`ℓ(a, b) = ‖a - b‖²` and the whitening constraint as anti-collapse term. -/
def spectralLoss {Z : Type*} [Fintype Z] {k : ℕ} (p : Z → ℝ) (π : Z → Z → ℝ)
(h : Z → Fin k → ℝ) : EReal :=
worldLoss p π sqDist whiteningReg h
/-- Proposition 1 and Section 2.3: `f : X → ℝ^k` is centred and whitened under the law `ω` on the
finite set `X`: `E_ω f = 0` and `E_ω f fᵀ = I_k`. -/
def IsWhitened {X : Type*} [Fintype X] {k : ℕ} (ω : X → ℝ) (f : X → Fin k → ℝ) : Prop :=
(∀ i, ∑ x, ω x * f x i = 0) ∧ (∀ i j, ∑ x, ω x * f x i * f x j = if i = j then 1 else 0)
/-! ### Section 2.1 and Appendix A.1: spectrum -/
/-- Section 2.1: the normalised adjacency `K_π = D^{-1/2} Π D^{-1/2}`, `D = diag(p)`,
`Π_{zz'} = π(z, z')`. -/
def kerMat {Z : Type*} (p : Z → ℝ) (π : Z → Z → ℝ) : Matrix Z Z ℝ :=
fun z z' => π z z' / Real.sqrt (p z * p z')
/-- Section 2.1: the eigenvalues `1 = μ₀ ≥ μ₁ ≥ ⋯` of `K_π` with multiplicity, as the roots of its
characteristic polynomial in decreasing order (`μ_i := 0` for `i ≥ |Z|`; statements never use
those values, see `extEig`). -/
def eigs {Z : Type*} [Fintype Z] [DecidableEq Z] (p : Z → ℝ) (π : Z → Z → ℝ) (i : ℕ) : ℝ :=
((kerMat p π).charpoly.roots.sort (· ≥ ·)).getD i 0
/-- Proposition 1 and Appendix A.4: `μ_i` with the paper's convention `μ_i := -∞` for
`i ≥ |Z|`, as an extended real. -/
def extEig {Z : Type*} [Fintype Z] [DecidableEq Z] (p : Z → ℝ) (π : Z → Z → ℝ) (i : ℕ) : EReal :=
if i < Fintype.card Z then (eigs p π i : EReal) else ⊥
/-- Appendix A.1: the Markov operator `T_π = D^{-1} Π`, `(T_π h)(z) = E_π[h(z') | z]`, as a matrix
acting on functions `h : Z → ℝ`. -/
def markovOp {Z : Type*} (p : Z → ℝ) (π : Z → Z → ℝ) : Matrix Z Z ℝ :=
fun z z' => π z z' / p z
/-- Proposition 1 (Section 2.1): `Φ` is a spectral embedding of `π`,
`Φ(z) = (v₁(z), …, v_k(z)) / √p(z)`, for orthonormal eigenvectors `v₁, …, v_k` of `K_π`, orthogonal
to `v₀ = D^{1/2} 1`, with eigenvalues `μ₁, …, μ_k` (any such choice when `K_π` has ties). -/
def IsSpectralEmbedding {Z : Type*} [Fintype Z] [DecidableEq Z] {k : ℕ} (p : Z → ℝ)
(π : Z → Z → ℝ) (Phi : Z → Fin k → ℝ) : Prop :=
∃ v : Fin k → Z → ℝ, (∀ i j, ∑ z, v i z * v j z = if i = j then 1 else 0) ∧
(∀ i, ∑ z, Real.sqrt (p z) * v i z = 0) ∧
(∀ i : Fin k, (kerMat p π).mulVec (v i) = eigs p π (i.val + 1) • v i) ∧
∀ z i, Phi z i = v i z / Real.sqrt (p z)
/-- Theorem 2 (Section 2.2): the spectral (operator) norm `‖A‖₂` of a real matrix. -/
def specNorm {Z : Type*} [Fintype Z] (A : Matrix Z Z ℝ) : ℝ :=
sSup ((fun v : Z → ℝ => Real.sqrt (∑ z, (A.mulVec v z) ^ 2)) '' {v | ∑ z, v z ^ 2 ≤ 1})
/-- Theorem 2 (Section 2.2): the Frobenius norm `‖A‖_F` of a real matrix. -/
def frobNorm {Z : Type*} [Fintype Z] (A : Matrix Z Z ℝ) : ℝ :=
Real.sqrt (∑ z, ∑ z', A z z' ^ 2)
/-- Theorem 2 (Section 2.2) and formal Theorem 4: the `L²(ω)` distance
`(E_ω ‖f(x) - g(x)‖²)^{1/2}` of two embeddings. -/
def l2Dist {X : Type*} [Fintype X] {k : ℕ} (ω : X → ℝ) (f g : X → Fin k → ℝ) : ℝ :=
Real.sqrt (∑ x, ω x * sqNorm (f x - g x))
/-- Eq. (3), Theorem 2 (Section 2.2): the bound
`(2√2 / δ) min(√k ‖K_{π₁} - K_{π₂}‖₂, ‖K_{π₁} - K_{π₂}‖_F)` with `δ = μ_k - μ_{k+1}` of `K_{π₂}`;
when `k + 1 = |Z|`, `μ_{k+1} = -∞` and the bound is `0`. -/
def kahanBound {Z : Type*} [Fintype Z] [DecidableEq Z] (p : Z → ℝ) (π₁ π₂ : Z → Z → ℝ)
(k : ℕ) : ℝ :=
if k + 1 < Fintype.card Z then
2 * Real.sqrt 2 / (eigs p π₂ k - eigs p π₂ (k + 1)) *
min (Real.sqrt k * specNorm (kerMat p π₁ - kerMat p π₂)) (frobNorm (kerMat p π₁ - kerMat p π₂))
else 0
/-! ### Section 2.3 and Appendix A.4: observations, nuisance, good and bad views -/
/-- Section 2.3 and formal Theorem 4: the state marginal `z ↦ ∑_{x : s(x) = z} ω(x)` of a law `ω`
on observations, each observation `x` being of the world state `s(x)`. -/
def stateMarg {X Z : Type*} [Fintype X] [DecidableEq Z] (ω : X → ℝ) (s : X → Z) (z : Z) : ℝ :=
∑ x, if s x = z then ω x else 0
/-- Section 2.3: `E[f(x) | z]`, the conditional mean of the embedding given the world state. -/
def condMean {X Z : Type*} [Fintype X] [DecidableEq Z] {k : ℕ} (ω : X → ℝ) (s : X → Z)
(f : X → Fin k → ℝ) (z : Z) : Fin k → ℝ :=
fun i => (∑ x, if s x = z then ω x * f x i else 0) / stateMarg ω s z
/-- Section 2.3: `E_ω f`, the mean of the embedding. -/
def meanVec {X : Type*} [Fintype X] {k : ℕ} (ω : X → ℝ) (f : X → Fin k → ℝ) : Fin k → ℝ :=
fun i => ∑ x, ω x * f x i
/-- Section 2.3: `C_f = Cov(E[f(x) | z])`, the covariance of the part of the embedding that the
world state explains. -/
def stateCov {X Z : Type*} [Fintype X] [Fintype Z] [DecidableEq Z] {k : ℕ} (ω : X → ℝ)
(s : X → Z) (f : X → Fin k → ℝ) : Matrix (Fin k) (Fin k) ℝ :=
fun i j => ∑ z, stateMarg ω s z * (condMean ω s f z i - meanVec ω f i) *
(condMean ω s f z j - meanVec ω f j)
/-- Section 2.3: the scene-explained fraction `ρ(f) = tr C_f^{1/2} / k`, with `tr C_f^{1/2}` the sum
of the square roots of the eigenvalues of `C_f` (roots of its characteristic polynomial, with
multiplicity). -/
def rho {X Z : Type*} [Fintype X] [Fintype Z] [DecidableEq Z] {k : ℕ} (ω : X → ℝ) (s : X → Z)
(f : X → Fin k → ℝ) : ℝ :=
((stateCov ω s f).charpoly.roots.map Real.sqrt).sum / k
/-- Section 2.3 and Appendix A.4: the law `p(z) q(ν)` of an observation `(z, ν)` of state `z` with
nuisance `ν ∼ q` drawn independently of `z`. -/
def prodLaw {Z N : Type*} (p : Z → ℝ) (q : N → ℝ) (x : Z × N) : ℝ := p x.1 * q x.2
/-- Proposition 3 (i), Appendix A.4: the positive-pair law of a good-view JEPA on observations
`(z, ν)`: `(z, z') ∼ π` and independent nuisances `ν, ν' ∼ q`, i.e. the kernel `Π ⊗ q qᵀ`. -/
def goodViewLaw {Z N : Type*} (π : Z → Z → ℝ) (q : N → ℝ) (x y : Z × N) : ℝ :=
π x.1 y.1 * q x.2 * q y.2
/-- Proposition 3 (ii), Appendix A.4: `A` is row-stochastic with stationary law `p`
(`A ≥ 0`, `A 1 = 1`, `pᵀ A = pᵀ`). -/
def IsStationaryStochastic {Z : Type*} [Fintype Z] (p : Z → ℝ) (A : Matrix Z Z ℝ) : Prop :=
(∀ z z', 0 ≤ A z z') ∧ (∀ z, ∑ z', A z z' = 1) ∧ (∀ z', ∑ z, p z * A z z' = p z')
/-- Proposition 3 (ii), Appendix A.4: the positive-pair law of a bad-view JEPA: two corruptions
`x̃, x̃' ∼ Γ(· | x)` of one clean observation `x ∼ p ⊗ q`, drawn independently given `x`, for the
product corruption `Γ = A ⊗ B`. -/
def badViewLaw {Z N : Type*} [Fintype Z] [Fintype N] (p : Z → ℝ) (q : N → ℝ) (A : Matrix Z Z ℝ)
(B : Matrix N N ℝ) (x x' : Z × N) : ℝ :=
∑ y : Z × N, prodLaw p q y * (A y.1 x.1 * B y.2 x.2) * (A y.1 x'.1 * B y.2 x'.2)
/-- Proposition 3 (ii), Appendix A.4: the law `Aᵀ D_p A` of two corruptions of one state, whose
Markov operator on `L²(p)` is `A* A`. -/
def twoCorruptLaw {Z : Type*} [Fintype Z] (p : Z → ℝ) (A : Matrix Z Z ℝ) (z z' : Z) : ℝ :=
∑ y, p y * A y z * A y z'
/-- Proposition 3 (ii), Appendix A.4: the eigenvalues `1 = α₀ ≥ α₁ ≥ ⋯` of `A* A` on `L²(p)`
(for `B` and `q`: the `β_j`), i.e. the eigenvalues of the normalised kernel of `Aᵀ D_p A`. -/
def corrEig {Z : Type*} [Fintype Z] [DecidableEq Z] (p : Z → ℝ) (A : Matrix Z Z ℝ) (i : ℕ) : ℝ :=
eigs p (twoCorruptLaw p A) i
/-- Proposition 3 (ii), Appendix A.4: the index pairs `(i, j) ≠ (0, 0)`, `i < |Z|`, `j < |N|`. -/
def badPairs (nZ nN : ℕ) : Finset (ℕ × ℕ) :=
(Finset.range nZ ×ˢ Finset.range nN).erase (0, 0)
/-- Proposition 3 (ii), Appendix A.4: the eigenvalue `α_i β_j` of the bad-view kernel. -/
def badEig {Z N : Type*} [Fintype Z] [DecidableEq Z] [Fintype N] [DecidableEq N] (p : Z → ℝ)
(q : N → ℝ) (A : Matrix Z Z ℝ) (B : Matrix N N ℝ) (ij : ℕ × ℕ) : ℝ :=
corrEig p A ij.1 * corrEig q B ij.2
/-- Proposition 3 (ii), Appendix A.4: `ξ₁ ≥ ξ₂ ≥ ⋯`, the values `α_i β_j` with `(i, j) ≠ (0, 0)`,
with multiplicity, in decreasing order (`ξ_l` for `l ≥ 1`). -/
def xi {Z N : Type*} [Fintype Z] [DecidableEq Z] [Fintype N] [DecidableEq N] (p : Z → ℝ)
(q : N → ℝ) (A : Matrix Z Z ℝ) (B : Matrix N N ℝ) (l : ℕ) : ℝ :=
(((badPairs (Fintype.card Z) (Fintype.card N)).val.map (badEig p q A B)).sort (· ≥ ·)).getD
(l - 1) 0
/-- Proposition 3 (ii), Appendix A.4: `r`, the number of the top `k` pairs `(i, j)` (those with
`α_i β_j ≥ ξ_k`; exactly `k` of them when `ξ_k > ξ_{k+1}`) that have `j ≥ 1`. -/
def nuisanceCount {Z N : Type*} [Fintype Z] [DecidableEq Z] [Fintype N] [DecidableEq N]
(p : Z → ℝ) (q : N → ℝ) (A : Matrix Z Z ℝ) (B : Matrix N N ℝ) (k : ℕ) : ℕ :=
((badPairs (Fintype.card Z) (Fintype.card N)).filter
(fun ij => 1 ≤ ij.2 ∧ xi p q A B k ≤ badEig p q A B ij)).card
/-! ### Appendix A.4: formal Theorem 4 -/
/-- Formal Theorem 4 (Appendix A.4): the induced world kernel `π_W(z, z')`, the probability that a
positive pair `(x, x') ∼ W` joins an observation of `z` to one of `z'`. -/
def inducedKernel {X Z : Type*} [Fintype X] [DecidableEq Z] (s : X → Z) (W : X → X → ℝ) (z z' : Z) : ℝ :=
∑ x, ∑ x', if s x = z ∧ s x' = z' then W x x' else 0
/-- Formal Theorem 4 (Appendix A.4): the conditional expectation `P` onto functions of the state
in `L²(ω)`, `(P h)(x) = E_ω[h | s = s(x)]`, as a matrix. -/
def condExpMat {X Z : Type*} [Fintype X] [DecidableEq Z] (ω : X → ℝ) (s : X → Z) :
Matrix X X ℝ :=
fun x x' => if s x' = s x then ω x' / stateMarg ω s (s x) else 0
/-- Appendix A.1: the inner product `⟨h, h'⟩_ω = ∑ₓ ω(x) h(x) h'(x)` of `L²(ω)`. -/
def l2Inner {X : Type*} [Fintype X] (ω : X → ℝ) (h h' : X → ℝ) : ℝ :=
∑ x, ω x * h x * h' x
/-- Formal Theorem 4 (Appendix A.4): `η`, the largest eigenvalue of the compression
`(I - P) T_W (I - P)` to nuisance functions (`P h = 0`), i.e. the largest value of `⟨h, T_W h⟩_ω`
over nuisance functions of unit norm; `η = -∞` (the supremum of the empty set) if every state has
one observation. -/
def nuisanceTop {X Z : Type*} [Fintype X] [DecidableEq Z] (ω : X → ℝ) (s : X → Z)
(W : X → X → ℝ) : EReal :=
sSup ((fun h : X → ℝ => ((l2Inner ω h ((markovOp ω W).mulVec h) : ℝ) : EReal)) ''
{h | (condExpMat ω s).mulVec h = 0 ∧ l2Inner ω h h = 1})
/-- Formal Theorem 4 (Appendix A.4): the mixing operator `(I - P) T_W P`. -/
def mixOp {X Z : Type*} [Fintype X] [DecidableEq X] [DecidableEq Z] (ω : X → ℝ) (s : X → Z)
(W : X → X → ℝ) : Matrix X X ℝ :=
(1 - condExpMat ω s) * markovOp ω W * condExpMat ω s
/-- Formal Theorem 4 (Appendix A.4): the operator norm of a matrix `M` acting on `L²(ω)`. -/
def opNormL2 {X : Type*} [Fintype X] (ω : X → ℝ) (M : Matrix X X ℝ) : ℝ :=
sSup ((fun h : X → ℝ => Real.sqrt (l2Inner ω (M.mulVec h) (M.mulVec h))) ''
{h | l2Inner ω h h ≤ 1})
/-- Formal Theorem 4 (Appendix A.4): the Hilbert-Schmidt norm of a matrix `M` acting on `L²(ω)`,
`(∑_{x,x'} ω(x) M(x,x')² / ω(x'))^{1/2}`. -/
def hsNormL2 {X : Type*} [Fintype X] (ω : X → ℝ) (M : Matrix X X ℝ) : ℝ :=
Real.sqrt (∑ x, ∑ x', ω x * M x x' ^ 2 / ω x')
/-- Formal Theorem 4 (Appendix A.4): `ε`, the operator norm of `(I - P) T_W P` on `L²(ω)`. -/
def mixNorm {X Z : Type*} [Fintype X] [DecidableEq X] [DecidableEq Z] (ω : X → ℝ) (s : X → Z)
(W : X → X → ℝ) : ℝ :=
opNormL2 ω (mixOp ω s W)
/-- Formal Theorem 4 (Appendix A.4): `ε^{HS}`, the Hilbert-Schmidt norm of `(I - P) T_W P` on
`L²(ω)`. -/
def mixHSNorm {X Z : Type*} [Fintype X] [DecidableEq X] [DecidableEq Z] (ω : X → ℝ) (s : X → Z)
(W : X → X → ℝ) : ℝ :=
hsNormL2 ω (mixOp ω s W)
/-- Formal Theorem 4 (Appendix A.4): `δ = μ_k - max(μ_{k+1}, η)`, with `μ_i` the eigenvalues of
the induced world kernel (`μ_{|Z|} := -∞`), as an extended real (`+∞` when `μ_{k+1} = η = -∞`). -/
def worldGap {X Z : Type*} [Fintype X] [Fintype Z] [DecidableEq Z] (ω : X → ℝ) (s : X → Z)
(W : X → X → ℝ) (k : ℕ) : EReal :=
(eigs (stateMarg ω s) (inducedKernel s W) k : EReal) -
max (extEig (stateMarg ω s) (inducedKernel s W) (k + 1)) (nuisanceTop ω s W)
/-- Formal Theorem 4 (i) (Appendix A.4): `τ = (2√2 / δ) min(√k ε, √2 ε^{HS})`, read as `0` when
`δ = +∞`. -/
def tau {X Z : Type*} [Fintype X] [DecidableEq X] [Fintype Z] [DecidableEq Z] (ω : X → ℝ)
(s : X → Z) (W : X → X → ℝ) (k : ℕ) : ℝ :=
if worldGap ω s W k = ⊤ then 0 else
2 * Real.sqrt 2 / (worldGap ω s W k).toReal *
min (Real.sqrt k * mixNorm ω s W) (Real.sqrt 2 * mixHSNorm ω s W)
/-- Formal Theorem 4 (ii) (Appendix A.4): `γ` is a law of paired observations `(x₁, x₂)` of one
world state with `x_m ∼ ω_m`: `z ∼ p` and `x_m | z ∼ ω_m(· | z)`, under any coupling. -/
def IsPairedCoupling {X₁ X₂ Z : Type*} [Fintype X₁] [Fintype X₂] (ω₁ : X₁ → ℝ) (s₁ : X₁ → Z)
(ω₂ : X₂ → ℝ) (s₂ : X₂ → Z) (γ : X₁ → X₂ → ℝ) : Prop :=
(∀ x₁ x₂, 0 ≤ γ x₁ x₂) ∧ (∀ x₁, ∑ x₂, γ x₁ x₂ = ω₁ x₁) ∧ (∀ x₂, ∑ x₁, γ x₁ x₂ = ω₂ x₂) ∧
∀ x₁ x₂, γ x₁ x₂ ≠ 0 → s₁ x₁ = s₂ x₂
/-- Formal Theorem 4 (ii) (Appendix A.4): `(E_γ ‖f₁(x₁) - Q f₂(x₂)‖²)^{1/2}`. -/
def pairedRMS {X₁ X₂ : Type*} [Fintype X₁] [Fintype X₂] {k : ℕ} (γ : X₁ → X₂ → ℝ)
(f₁ : X₁ → Fin k → ℝ) (f₂ : X₂ → Fin k → ℝ) (Q : Matrix.orthogonalGroup (Fin k) ℝ) : ℝ :=
Real.sqrt (∑ x₁, ∑ x₂, γ x₁ x₂ * sqNorm (f₁ x₁ - rot Q (f₂ x₂)))
/-- Appendix A.4, "Special cases and scope": the law of the merged observations when the
observations are grouped by `c : X → Y`. -/
def mergeWeights {X Y : Type*} [Fintype X] [DecidableEq Y] (c : X → Y) (ω : X → ℝ) (y : Y) : ℝ :=
∑ x, if c x = y then ω x else 0
/-- Appendix A.4, "Special cases and scope": the positive-pair law on merged observations,
`W'(y, y') = ∑_{c(x) = y, c(x') = y'} W(x, x')`. -/
def mergeLaw {X Y : Type*} [Fintype X] [DecidableEq Y] (c : X → Y) (W : X → X → ℝ) (y y' : Y) :
ℝ :=
∑ x, ∑ x', if c x = y ∧ c x' = y' then W x x' else 0
/-! ### Section 2.4: next-token prediction -/
/-- Eq. (6), Proposition 4 (Section 2.4): the anti-collapse term `A(h) = log ∑_v exp ⟨h, w_v⟩`. -/
def ntpAntiCollapse {V : Type*} [Fintype V] {k : ℕ} (w : V → Fin k → ℝ) (h : Fin k → ℝ) : ℝ :=
Real.log (∑ v, Real.exp (h ⬝ᵥ w v))
/-- Eq. (6), Proposition 4 (Section 2.4): the next-token loss with a linear softmax head,
`-log (e^{⟨h, w_y⟩} / ∑_v e^{⟨h, w_v⟩})`. -/
def ntpLoss {V : Type*} [Fintype V] {k : ℕ} (w : V → Fin k → ℝ) (h : Fin k → ℝ) (y : V) : ℝ :=
-Real.log (Real.exp (h ⬝ᵥ w y) / ∑ v, Real.exp (h ⬝ᵥ w v))
/-- Proposition 4 (iii) and its proof (Appendix A.5): the expected next-token loss
`∑_c P(c) ∑_v p(v | c) · (-log softmax(W h(c))_v)` over finitely many contexts. -/
def ntpRisk {C V : Type*} [Fintype C] [Fintype V] {k : ℕ} (P : C → ℝ) (cond : C → V → ℝ)
(h : C → Fin k → ℝ) (w : V → Fin k → ℝ) : ℝ :=
∑ c, P c * ∑ v, cond c v * ntpLoss w (h c) v
/-! ### Appendix C: subsample intervals -/
/-- Appendix C ("Uncertainty on WIT"): the mean `(1/N) ∑ᵢ xᵢ` of a score over the full set of `N`
pairs. -/
def popMean {N : ℕ} (x : Fin N → ℝ) : ℝ := (∑ i, x i) / N
/-- Appendix C ("Uncertainty on WIT"): the mean of the score over a subset `S` of the pairs. -/
def subMean {N : ℕ} (x : Fin N → ℝ) (S : Finset (Fin N)) : ℝ := (∑ i ∈ S, x i) / S.card
/-- Appendix C ("Uncertainty on WIT"): the sample variance `s² = ∑ᵢ (xᵢ - x̄)² / (N - 1)`, so that
the standard error of the full score is `s / √N`. -/
def sampleVar {N : ℕ} (x : Fin N → ℝ) : ℝ := (∑ i, (x i - popMean x) ^ 2) / ((N : ℝ) - 1)
/-- Appendix C ("Uncertainty on WIT"): the spread of the score over uniformly random `n`-subsets
drawn without replacement around the full score,
`(E_S (x̄_S - x̄)²)^{1/2}`. -/
def subsampleSpread {N : ℕ} (x : Fin N → ℝ) (n : ℕ) : ℝ :=
Real.sqrt ((∑ S ∈ (Finset.univ : Finset (Fin N)).powersetCard n, (subMean x S - popMean x) ^ 2) /
(N.choose n))
end Arxiv2610_39302
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
Throughout, means vectors with coordinates indexed by ; is allowed, in which case is a single point. All finite sets may be empty unless a hypothesis rules it out. The following junk conventions apply everywhere:
- division by zero returns ;
- the square root of a negative number returns ;
- ;
- natural-number subtraction truncates at .
sqNorm. For , it is the number
For it equals .
sqDist. For , it is the number .
rot. Let be a real orthogonal matrix, meaning . For , rot is the matrix–vector product .
IsPairLaw. Let be a finite set, , and . The predicate holds exactly when all of the following are true:
- for every ;
- , which forces ;
- for all ;
- for all ;
- for every .
By symmetry the column sums also equal , and the total mass of is .
embLaw. Let be finite, , and . embLaw is the measure on
where is the unit point mass at . Negative weights are replaced by . The measure is a probability measure only if the clipped weights sum to .
IsJEPAObjective. Fix a finite , , a function , and a function from measures on to . The predicate holds exactly when:
- for every orthogonal and all ;
- for every and every orthogonal , , where and embLaw is as above (weights );
- for every measure . The value is allowed.
Nothing else is assumed about : not nonnegativity, not symmetry, not . The invariance of is only required on measures of the form embLaw.
worldLoss. For as above, , and , it is the extended real
The first term is a finite real number. The total is therefore or exactly when is.
modalityLoss. Let be any set, , and . It is the worldLoss above applied to the composite :
UniqueUpToRotation. Let be any set (not necessarily finite) and a function from maps to extended reals. The predicate says: whenever and are both global minimisers, meaning and for all , there is an orthogonal with for all .
Edge cases:
- It holds vacuously if has no minimiser.
- If , every is a minimiser, so the predicate demands that any two maps be rotations of each other.
whiteningReg. For a measure on , it is
- is not required to be a probability measure.
- Any non-integrable integrand is assigned integral .
- For the conditions are empty, so the value is always .
spectralLoss. For finite, , , and , it is worldLoss with and . Explicitly, the value is
if both of the following hold, and otherwise:
- for all ;
- for all .
IsWhitened. Let be finite, (no sign or normalisation assumed), and . The predicate holds exactly when:
- for all ;
- for all .
kerMat. For and , it is the matrix
The entry is whenever , by the square-root and division conventions.
eigs. For finite , () is defined as follows:
- Take the real roots of the characteristic polynomial of , counted with multiplicity.
- Sort them in non-increasing order.
- is the entry at position , counting from . If there are at most real roots, .
- Non-real roots are simply dropped, and nothing in the definition forces .
- If , every .
extEig. It is the extended real equal to (from eigs) if , and if . If fewer than real roots exist, some indices get the junk value .
markovOp. It is the matrix . Rows with are .
IsSpectralEmbedding. Let be finite, and given, and . The predicate says there exist vectors such that:
- , i.e. they are orthonormal for the standard dot product;
- for each , where of a negative number is ;
- for each , with as in eigs. So the -th coordinate uses exactly the -th entry of the sorted list ;
- for all , which is where .
Edge cases:
- If is the junk value , condition 3 just says .
- Orthonormality forces .
- For the predicate is trivially true.
specNorm. For a real matrix , it is the supremum of over all with . This is the usual operator 2-norm.
frobNorm. It is .
l2Dist. For finite , , and , it is
It is if the inner sum is negative, which is possible only for signed .
kahanBound. Fix finite , one , two pair functions , and . Write , where both matrices use the same , and let be the eigs of .
- If , the value is
- If , the value is .
When the denominator is , so the value is . The gap could be negative only through the junk- padding of eigs.
stateMarg. For finite , , , and , it is . This equals for states with no observation.
condMean. It is the vector in with -th coordinate
The whole vector is when .
meanVec. It is the vector with -th coordinate . It is not normalised by .
stateCov. It is the matrix
where is condMean and is meanVec.
rho. It is
where the sum runs over the real roots of the characteristic polynomial of , with multiplicity.
- Non-real roots are omitted.
- for negative .
- when .
prodLaw. It is the function on given by .
goodViewLaw. It is the function on pairs given by .
IsStationaryStochastic. For a matrix , it holds exactly when:
- for all ;
- for every ;
- for every .
No condition is placed on .
badViewLaw. For finite and , , , a matrix , and an matrix , it is
twoCorruptLaw. It is .
corrEig. is the -th eigs value of the pair . That is, it is the -th largest real root (with multiplicity, if absent) of the characteristic polynomial of the matrix
The same construction with gives .
badPairs. It is the finite set
badEig. For , it is . Here comes from and from .
xi. Take the multiset of the values over badPairs and sort it in non-increasing order. Then is the entry at position , counting from , and if that position does not exist.
- Because , .
nuisanceCount. is the number of pairs badPairs with and .
- With ties at , this can count pairs beyond the first .
- For the threshold is .
- If exceeds the number of pairs, the threshold is .
inducedKernel. For and , it is
condExpMat. It is the matrix
with the state marginal as in stateMarg. The entry is if .
l2Inner. It is . It need not be positive definite when has signs.
nuisanceTop. is the supremum in of
over all with and . Here (markovOp with ) and is condExpMat.
- if no such exists.
- if the values are unbounded above.
mixOp. It is the matrix product .
opNormL2. For an matrix , it is the real supremum of over all with .
- If this set of values is unbounded, the real supremum convention returns . This can happen, e.g., when some .
hsNormL2. It is
Terms with contribute .
mixNorm. is opNormL2 of .
mixHSNorm. is hsNormL2 of .
worldGap. The extended real
- The 's are eigenvalues of the matrix , built from (inducedKernel) and (stateMarg).
- The first term is the plain eigs value: it is never , and it is the junk if is at least the number of real roots.
- The second term uses extEig, so when .
- is nuisanceTop.
- Subtraction is in the extended reals: if the max is , and if .
tau. It is if . Otherwise it is
where is converted to a real. If it converts to , and if , then by division by zero.
IsPairedCoupling. For finite , , , and , the predicate holds exactly when:
- ;
- for every ;
- for every ;
- implies .
No condition on itself is imposed beyond what these force.
pairedRMS. It is
for orthogonal , with value if the sum is negative.
mergeWeights. For , it is .
mergeLaw. It is
ntpAntiCollapse. For finite , , and , it is
with the standard dot product. It equals if .
ntpLoss. It is
This always equals , since the denominator is positive because .
ntpRisk. For finite and , , , , and , it is
and are not required to be probabilities.
popMean. It is , which is when .
subMean. For , it is , which is when .
sampleVar. It is
with the denominator computed as a real. It is for (division by zero) and for (empty sum).
subsampleSpread. It is
- If there are no such and , so the value is .
- If the only is with , so the value is .
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.