Gaussian world, LeJEPA alignment loss, Hermite basis, and latent planning
DefinitionLeJEPAWorldModel_BasicObjects of Klindt, LeCun and Balestriero (2026), When Does LeJEPA Learn a World Model?
- Gaussian world (Section 2.1.1, eq. 1). The latent is on , the law with independent standard normal coordinates. For a positive pair is with , where is independent of . Its law on is the image of under . Here .
- LeJEPA objective (Section 2.2, eq. 2). For , the alignment loss is .
- Second-order quantities (Theorem 3, Appendix C). , and . The linear part of is the matrix (eq. 36), and the nonlinear energy is (eq. 37).
- Hermite polynomials (Appendix A.2). is the probabilists' Hermite polynomial of degree (eq. 7), , and for a multi-index , (eq. 10).
- Sturm–Liouville generator (Appendix B.1, eq. 30). For a diffusion constant and a density on , .
- Planning (Section 4.4, Appendix D). States lie in and actions in a set . The transition is given by a probability measure for each state and action. The stage cost is and the terminal cost is . The expected cost of a plan from is , computed backwards: and . The value is over plans of length (by convention it is if this set of costs is empty or unbounded below). A plan of length is optimal if its cost is at most the cost of every plan of length . For , the learned-latent transitions are , the image of under .
- Dirichlet-energy setting (Appendix E.1). A diffeomorphism is a bijection of with a inverse. For , the quotient is , where are independent. Its limit as is the loss of Appendix E.
Formalization Note Vectors in are functions , and the squared norm is written out as a sum of squares. The Hermite polynomials are Mathlib's Polynomial.hermite, which Mathlib proves equal to the Rodrigues formula (7). The expected cost of a plan is defined by the backward recursion, which equals the trajectory expectation by the tower property. The Dirichlet quotient is a lower Lebesgue integral with values in , so it is defined for every .
import Mathlib
/-!
Klindt, LeCun and Balestriero, *When Does LeJEPA Learn a World Model?*, arXiv:2605.26379v2
(2026): the Gaussian world and the LeJEPA objective of Section 2, the Hermite basis of
Appendix A.2, the Sturm–Liouville generator of Appendix B.1, the linear part and nonlinear energy
of Appendix C, the planning problem of Section 4.4 and Appendix D, and the Dirichlet-energy
objective of Appendix E.1.
-/
open MeasureTheory ProbabilityTheory
open scoped ENNReal
noncomputable section
namespace LeJEPAWorldModel
/-- Squared Euclidean norm `‖v‖² = ∑ᵢ vᵢ²` of a vector `v ∈ ℝ^N` (Section 2.2). -/
def sqNorm {N : ℕ} (v : Fin N → ℝ) : ℝ := ∑ i, v i ^ 2
/-- Section 2.1.1: the standard Gaussian `γ_N = N(0, I_N)` on `ℝ^N`, the law of the latent `z`
(independent standard normal coordinates). -/
def stdGaussian (N : ℕ) : Measure (Fin N → ℝ) :=
Measure.pi fun _ => gaussianReal 0 1
/-- Eq. (1): the law of a positive pair `(z, z')` of the Gaussian world, where `z ∼ N(0, I_N)`,
`η ∼ N(0, I_N)` is independent of `z`, and `z' = ρ z + √(1 - ρ²) η`. -/
def ouPairLaw (N : ℕ) (ρ : ℝ) : Measure ((Fin N → ℝ) × (Fin N → ℝ)) :=
((stdGaussian N).prod (stdGaussian N)).map
(fun p => (p.1, ρ • p.1 + Real.sqrt (1 - ρ ^ 2) • p.2))
/-- Eq. (2), Section 2.2: the LeJEPA alignment loss `𝓛(h) = E ‖h(z') - h(z)‖²` over positive
pairs of the Gaussian world. -/
def alignLoss (N : ℕ) (ρ : ℝ) (h : (Fin N → ℝ) → Fin N → ℝ) : ℝ :=
∫ p, sqNorm (h p.2 - h p.1) ∂ouPairLaw N ρ
/-- Section 2.2 and Theorem 3: the covariance matrix `Cov(h(z))`, `z ∼ N(0, I_N)`. -/
def covMat (N : ℕ) (h : (Fin N → ℝ) → Fin N → ℝ) : Matrix (Fin N) (Fin N) ℝ :=
fun i j => ∫ z, (h z i - ∫ y, h y i ∂stdGaussian N) * (h z j - ∫ y, h y j ∂stdGaussian N)
∂stdGaussian N
/-- Frobenius norm `‖A‖_F = (∑ᵢⱼ Aᵢⱼ²)^{1/2}` (Theorem 3). -/
def frobNorm {N : ℕ} (A : Matrix (Fin N) (Fin N) ℝ) : ℝ :=
Real.sqrt (∑ i, ∑ j, A i j ^ 2)
/-- Eq. (36), Appendix C: the linear part `M` of `h`, `M_ij = E[h_i(z) z_j]`, `z ∼ N(0, I_N)`. -/
def linearPart (N : ℕ) (h : (Fin N → ℝ) → Fin N → ℝ) : Matrix (Fin N) (Fin N) ℝ :=
fun i j => ∫ z, h z i * z j ∂stdGaussian N
/-- Eq. (37), Appendix C: the nonlinear energy `W_nl = E ‖ν(z)‖²` of the residual
`ν(z) = h(z) - M z`. -/
def nonlinearEnergy (N : ℕ) (h : (Fin N → ℝ) → Fin N → ℝ) : ℝ :=
∫ z, sqNorm (h z - (linearPart N h).mulVec z) ∂stdGaussian N
/-- Eq. (7), Appendix A.2: the probabilists' Hermite polynomial `He_k`, evaluated at `x`
(Mathlib's `Polynomial.hermite`, which equals the Rodrigues formula (7) by
`Polynomial.hermite_eq_deriv_gaussian`). -/
def hermiteHe (k : ℕ) (x : ℝ) : ℝ :=
Polynomial.aeval x (Polynomial.hermite k)
/-- Appendix A.2: the normalized Hermite polynomial `ĥ_k(x) = He_k(x) / √(k!)`. -/
def hermiteNormalized (k : ℕ) (x : ℝ) : ℝ :=
hermiteHe k x / Real.sqrt (k.factorial : ℝ)
/-- Eq. (10), Appendix A.2: the multivariate Hermite function `H_α(z) = ∏ⱼ ĥ_{αⱼ}(zⱼ)` for a
multi-index `α ∈ ℕ^N`. -/
def multiHermite {N : ℕ} (α : Fin N → ℕ) (z : Fin N → ℝ) : ℝ :=
∏ j, hermiteNormalized (α j) (z j)
/-- Eq. (30), Appendix B.1: the Sturm–Liouville generator of a scalar latent with constant
diffusion `K` and stationary density `p`, `𝒟φ = (1/p) d/dz [K p φ']`. -/
def slGenerator (K : ℝ) (p φ : ℝ → ℝ) (x : ℝ) : ℝ :=
(1 / p x) * deriv (fun y => K * p y * deriv φ y) x
section Planning
variable {N : ℕ} {A : Type*}
/-- Section 4.4: the expected cost `E[ℓ_T(z_T) + ∑_{t=1}^T ℓ(z_{t-1}, a_t) | z_0]` of the plan
`[a_1, …, a_T]` started at `z_0`, where `z_t ∼ P(z_{t-1}, a_t)`, computed backwards:
the empty plan costs `ℓ_T(z)` and the plan `a :: as` costs `ℓ(z, a) + ∫ cost(as, z') dP(z, a)(z')`. -/
def planCost (P : (Fin N → ℝ) → A → Measure (Fin N → ℝ)) (c : (Fin N → ℝ) → A → ℝ)
(cT : (Fin N → ℝ) → ℝ) : List A → (Fin N → ℝ) → ℝ
| [], z => cT z
| a :: as, z => c z a + ∫ z', planCost P c cT as z' ∂(P z a)
/-- Section 4.4: the minimal cost `V*(z_0)` over plans `a_{1:T}` of length `T`. -/
def optimalValue (P : (Fin N → ℝ) → A → Measure (Fin N → ℝ)) (c : (Fin N → ℝ) → A → ℝ)
(cT : (Fin N → ℝ) → ℝ) (T : ℕ) (z0 : Fin N → ℝ) : ℝ :=
⨅ as : {l : List A // l.length = T}, planCost P c cT as.1 z0
/-- Section 4.4: `as` is an optimal plan `a*_{1:T}(z_0)`: it has length `T` and its cost is at
most the cost of every plan of length `T`. -/
def IsOptimalPlan (P : (Fin N → ℝ) → A → Measure (Fin N → ℝ)) (c : (Fin N → ℝ) → A → ℝ)
(cT : (Fin N → ℝ) → ℝ) (T : ℕ) (z0 : Fin N → ℝ) (as : List A) : Prop :=
as.length = T ∧ ∀ bs : List A, bs.length = T → planCost P c cT as z0 ≤ planCost P c cT bs z0
/-- Theorem 4 and Appendix D: the transitions `p̂(· | ẑ, a)` of the learned latent `ẑ = h(z) = Q z`,
the pushforward under `h` of `p(· | h⁻¹(ẑ), a)`, with `h⁻¹(ẑ) = Qᵀ ẑ` for orthogonal `Q`. -/
def pushDynamics (Q : Matrix (Fin N) (Fin N) ℝ) (P : (Fin N → ℝ) → A → Measure (Fin N → ℝ)) :
(Fin N → ℝ) → A → Measure (Fin N → ℝ) :=
fun zh a => (P (Q.transpose.mulVec zh) a).map (fun z => Q.mulVec z)
end Planning
/-- Appendix E.1: `h : ℝ^N → ℝ^N` is a `C¹` diffeomorphism (a `C¹` bijection with `C¹` inverse). -/
def IsC1Diffeo {N : ℕ} (h : (Fin N → ℝ) → Fin N → ℝ) : Prop :=
ContDiff ℝ 1 h ∧ ∃ g : (Fin N → ℝ) → Fin N → ℝ,
ContDiff ℝ 1 g ∧ Function.LeftInverse g h ∧ Function.RightInverse g h
/-- Appendix E.1: the quotient `(1/ε) E ‖h(z + √ε η) - h(z)‖²`, `z, η ∼ N(0, I_N)` independent,
whose limit as `ε → 0⁺` is the normalized loss `𝓛(h)`; valued in `[0, ∞]`. -/
def dirichletQuotient (N : ℕ) (h : (Fin N → ℝ) → Fin N → ℝ) (ε : ℝ) : ℝ≥0∞ :=
ENNReal.ofReal (1 / ε) *
∫⁻ p, ENNReal.ofReal (sqNorm (h (p.1 + Real.sqrt ε • p.2) - h p.1))
∂((stdGaussian N).prod (stdGaussian N))
end LeJEPAWorldModel
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
Squared norm (sqNorm). For a natural number and a vector , this is the sum of the squared coordinates:
When the sum is empty and the value is .
Standard Gaussian (stdGaussian). For a natural number , is the product measure on of copies of the one-dimensional normal law with mean and variance :
Equivalently, the coordinates are independent standard normals. When , is a single point and is the unit point mass there.
Positive-pair law (ouPairLaw). For a natural number and an arbitrary real number , is a measure on . It is the image of the product measure under the map
So it is the joint law of , where are independent with law and .
- No restriction is placed on .
- The square root is the real square root with the convention for . Hence when the law is that of , with no noise term.
- When it is also the law of .
Alignment loss (alignLoss). For , a real , and an arbitrary function (no measurability, continuity or integrability is assumed), the loss is the integral against the positive-pair law :
Here is the sum of squared coordinates defined above. The integral is a real-valued (Bochner) integral, and there is no normalising factor. If the integrand is not integrable, including the case where it is not measurable or has infinite integral, the value is by convention .
Covariance matrix (covMat). For and an arbitrary with coordinates , this is the real matrix with entries
Every integral is a real-valued integral against . Any integral whose integrand is not integrable is replaced by . In particular, the "mean" is when is not -integrable, and the whole entry is when the product is not integrable.
Frobenius norm (frobNorm). For an real matrix :
This equals when .
Linear part (linearPart). For and an arbitrary , is the real matrix with entries
An entry is by convention if the integrand is not -integrable.
Nonlinear energy (nonlinearEnergy). For and an arbitrary , let be the matrix just defined. Then
Here is the ordinary matrix–vector product and is the sum of squared coordinates. The value is by convention if the integrand is not integrable.
Hermite polynomial (hermiteHe). For and , is the value at of the -th probabilists' Hermite polynomial. This is the monic integer polynomial determined by
so for example and .
Normalised Hermite polynomial (hermiteNormalized). For and :
Since , the denominator is never zero.
Multivariate Hermite function (multiHermite). For , a multi-index , and :
When this is the empty product, which equals .
Sturm–Liouville generator (slGenerator). The inputs are:
- a real constant ;
- arbitrary functions , with no positivity, differentiability or integrability assumed;
- a point .
The value is
Several conventions apply in degenerate cases:
- Each derivative is the derivative where it exists and is taken to be at any point where the function is not differentiable. This applies both to and to the outer derivative.
- Division by zero gives , so the value is wherever .
- is not required to be a probability density, and may be zero or negative.
Plan cost (planCost). The setting is:
- a natural number and an arbitrary type of actions;
- a family assigning to each state and action a measure on ;
- a stage cost ;
- a terminal cost .
The measures are not required to be probability measures, or even finite, and there is no measurability assumption in . For a finite list of actions and a state , the cost is defined by recursion on the list:
Here is the list with first action followed by the list . The first action in the list is applied first, and the stage cost is evaluated at the state before that action. Each integral is a real-valued integral, set to when the integrand is not integrable with respect to . In particular, it is whenever is the zero measure.
Optimal value (optimalValue). For as above, a horizon , and an initial state :
taken as a real number. Under the real-infimum convention, the value is in two cases:
- the set of costs is unbounded below;
- the set is empty, which happens when is empty and .
The infimum need not be attained. When , the only list is the empty one, and the value is .
Optimal plan (IsOptimalPlan). For as above and a list of actions , the statement " is optimal" means both of the following hold:
- has length exactly ;
- for every list of length , .
The definition makes no reference to . Costs here include the junk value for non-integrable integrands.
Pushed-forward dynamics (pushDynamics). For an arbitrary real matrix and a family as above, this defines a new family . For each and , is the image of the measure under the linear map :
is not required to be orthogonal, invertible or nonzero, and is simply the transpose. It is not an inverse of unless happens to be orthogonal.
diffeomorphism (IsC1Diffeo). For , the property holds when both of the following are true:
- is continuously differentiable ();
- there exists a map with for all and for all .
In other words, is a bijection with inverse. When every satisfies this.
Dirichlet quotient (dirichletQuotient). For , an arbitrary , and a real , the value lies in the extended non-negative reals :
Here , and the integral is the non-negative (lower Lebesgue) integral over independent with law , which may equal . The degenerate cases are:
- The convention applies to the product.
- For , , so the prefactor is and .
- For , , so again .
Only for is this the quotient . No limit in is taken in this definition.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.