Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Latent spaces, positive-pair conditionals, cross-entropies and InfoNCE objectives of Zimmermann et al. (2021)

Definition
ContrastiveInverts_Basic

by Xeroth · Nov 23, 2026 · Mathlib 0df444a (Lean v4.33.1)

contrastive-learningidentifiabilityinfoncenonlinear-icavon-mises-fisher

Objects of Section 3, Definition 1 and Appendices A.1.1 and A.2.1 of Zimmermann, Sharma, Schneider, Bethge and Brendel (2021). Observations are x=g(z)x=g(z)x=g(z) for latents zzz, an encoder fff is trained on observations, and every objective depends on fff only through h=f∘gh=f\circ gh=f∘g, so it is written on latents.

  1. Hypersphere. Z=SN−1⊂RNZ=\mathbb{S}^{N-1}\subset\mathbb{R}^NZ=SN−1⊂RN carries its surface measure σ\sigmaσ, of total mass ∣Z∣|Z|∣Z∣. The marginal is uniform, p(z)=∣Z∣−1p(z)=|Z|^{-1}p(z)=∣Z∣−1.
  2. von Mises–Fisher conditional (eq. 2). p(z~∣z)=Cp−1eκz⊤z~p(\tilde z\mid z)=C_p^{-1}e^{\kappa z^\top\tilde z}p(z~∣z)=Cp−1​eκz⊤z~ with Cp=∫Zeκz⊤z~ dσ(z~)C_p=\int_Z e^{\kappa z^\top\tilde z}\,d\sigma(\tilde z)Cp​=∫Z​eκz⊤z~dσ(z~).
  3. Model conditional (eq. 4). For τ>0\tau>0τ>0, qh(z~∣z)=Ch(z)−1eh(z~)⊤h(z)/τq_h(\tilde z\mid z)=C_h(z)^{-1}e^{h(\tilde z)^\top h(z)/\tau}qh​(z~∣z)=Ch​(z)−1eh(z~)⊤h(z)/τ with Ch(z)=∫Zeh(z~)⊤h(z)/τ dσ(z~)C_h(z)=\int_Z e^{h(\tilde z)^\top h(z)/\tau}\,d\sigma(\tilde z)Ch​(z)=∫Z​eh(z~)⊤h(z)/τdσ(z~).
  4. Cross-entropies. H(p(⋅∣z),qh(⋅∣z))=∫Zp(z~∣z) (−log⁡qh(z~∣z)) dσ(z~)H(p(\cdot\mid z),q_h(\cdot\mid z))=\int_Z p(\tilde z\mid z)\,(-\log q_h(\tilde z\mid z))\,d\sigma(\tilde z)H(p(⋅∣z),qh​(⋅∣z))=∫Z​p(z~∣z)(−logqh​(z~∣z))dσ(z~) at a fixed anchor zzz, and its average Ez∼p(z)H(p(⋅∣z),qh(⋅∣z))\mathbb{E}_{z\sim p(z)}H(p(\cdot\mid z),q_h(\cdot\mid z))Ez∼p(z)​H(p(⋅∣z),qh​(⋅∣z)).
  5. InfoNCE (eq. 1). With (z,z~)(z,\tilde z)(z,z~) drawn as z∼p(z)z\sim p(z)z∼p(z), z~∼p(z~∣z)\tilde z\sim p(\tilde z\mid z)z~∼p(z~∣z), and negatives z1−,…,zM−z_1^-,\dots,z_M^-z1−​,…,zM−​ i.i.d. uniform,
Lcontr(f;τ,M)=E[−log⁡eh(z)⊤h(z~)/τeh(z)⊤h(z~)/τ+∑i=1Meh(z)⊤h(zi−)/τ].\mathcal{L}_{\mathsf{contr}}(f;\tau,M)=\mathbb{E}\Big[-\log\frac{e^{h(z)^\top h(\tilde z)/\tau}}{e^{h(z)^\top h(\tilde z)/\tau}+\sum_{i=1}^M e^{h(z)^\top h(z_i^-)/\tau}}\Big].Lcontr​(f;τ,M)=E[−logeh(z)⊤h(z~)/τ+∑i=1M​eh(z)⊤h(zi−​)/τeh(z)⊤h(z~)/τ​].

The objective minimised "for M→∞M\to\inftyM→∞" is lim⁡M→∞(Lcontr(f;τ,M)−log⁡M)\lim_{M\to\infty}(\mathcal{L}_{\mathsf{contr}}(f;\tau,M)-\log M)limM→∞​(Lcontr​(f;τ,M)−logM). 6. Convex bodies. Z⊂RNZ\subset\mathbb{R}^NZ⊂RN is compact and convex with nonempty interior, carries Lebesgue measure, has volume ∣Z∣|Z|∣Z∣ and uniform marginal p(z)=∣Z∣−1p(z)=|Z|^{-1}p(z)=∣Z∣−1. 7. (Semi-)metrics induced by a norm (eq. 5, Lemma 1). δ(a,b)=j(ν(a−b))\delta(a,b)=j(\nu(a-b))δ(a,b)=j(ν(a−b)) for a norm ν\nuν on RN\mathbb{R}^NRN and a continuous bijection jjj of [0,∞)[0,\infty)[0,∞) with j(0)=0j(0)=0j(0)=0 (j=idj=\mathrm{id}j=id is the metric case). The LαL^\alphaLα metric is (∑i∣ai−bi∣α)1/α\big(\sum_i|a_i-b_i|^\alpha\big)^{1/\alpha}(∑i​∣ai​−bi​∣α)1/α. 8. Exponential conditional (eq. 5, Appendix A.2.1). For λ>0\lambda>0λ>0, p(z~∣z)=Cp(z)−1e−λδ(z~,z)p(\tilde z\mid z)=C_p(z)^{-1}e^{-\lambda\delta(\tilde z,z)}p(z~∣z)=Cp​(z)−1e−λδ(z~,z) with Cp(z)=∫Ze−λδ(z,z~) dz~C_p(z)=\int_Z e^{-\lambda\delta(z,\tilde z)}\,d\tilde zCp​(z)=∫Z​e−λδ(z,z~)dz~. Eq. (5) is the case λ=1\lambda=1λ=1. 9. Model conditional (eq. 7). qh(z~∣z)=Ch(z)−1e−δ(h(z~),h(z))/τq_h(\tilde z\mid z)=C_h(z)^{-1}e^{-\delta(h(\tilde z),h(z))/\tau}qh​(z~∣z)=Ch​(z)−1e−δ(h(z~),h(z))/τ with Ch(z)=∫Ze−δ(h(z~),h(z))/τ dz~C_h(z)=\int_Z e^{-\delta(h(\tilde z),h(z))/\tau}\,d\tilde zCh​(z)=∫Z​e−δ(h(z~),h(z))/τdz~. The cross-entropies are defined as in item 4, with Lebesgue measure on ZZZ. 10. General InfoNCE (Definition 1, eq. 6).

Lδ-contr(f;τ,M)=E[−log⁡e−δ(h(z),h(z~))/τe−δ(h(z),h(z~))/τ+∑i=1Me−δ(h(z),h(zi−))/τ],\mathcal{L}_{\delta\text{-contr}}(f;\tau,M)=\mathbb{E}\Big[-\log\frac{e^{-\delta(h(z),h(\tilde z))/\tau}}{e^{-\delta(h(z),h(\tilde z))/\tau}+\sum_{i=1}^M e^{-\delta(h(z),h(z_i^-))/\tau}}\Big],Lδ-contr​(f;τ,M)=E[−loge−δ(h(z),h(z~))/τ+∑i=1M​e−δ(h(z),h(zi−​))/τe−δ(h(z),h(z~))/τ​],

with positive pairs from ppp and i.i.d. uniform negatives. Its alignment and uniformity parts (Proposition 3) are Lδ-align=τ−1Ez,z~ δ(h(z~),h(z))\mathcal{L}_{\delta\text{-align}}=\tau^{-1}\mathbb{E}_{z,\tilde z}\,\delta(h(\tilde z),h(z))Lδ-align​=τ−1Ez,z~​δ(h(z~),h(z)) and Lδ-unif=Ez∼p(z)log⁡Ez~∼p(z~)e−δ(h(z~),h(z))/τ\mathcal{L}_{\delta\text{-unif}}=\mathbb{E}_{z\sim p(z)}\log\mathbb{E}_{\tilde z\sim p(\tilde z)}e^{-\delta(h(\tilde z),h(z))/\tau}Lδ-unif​=Ez∼p(z)​logEz~∼p(z~)​e−δ(h(z~),h(z))/τ, where p(z~)p(\tilde z)p(z~) is the uniform marginal.

Formalization Note The ground-truth distance δp\delta_pδp​ (with λ\lambdaλ) and the model distance δ\deltaδ (with τ\tauτ) are separate arguments of the convex-body objectives, so that Theorem 6 can use a model distance equal to a constant multiple of the ground-truth one. CpC_pCp​ is defined as a function of the anchor zzz; on the sphere this is the paper's constant, by rotation invariance. The objective "for M→∞M\to\inftyM→∞" is Lean's limUnder, which equals the true limit whenever the limit exists; Theorem 1 asserts that it exists for every measurable encoder with values in a sphere SrN−1\mathbb{S}^{N-1}_rSrN−1​ (under the standing assumptions on ggg), and Theorem 3 for every encoder with values in the convex body Z′Z'Z′ that is a.e.-measurable.

Definition code
import Mathlib

/-!
Zimmermann, Sharma, Schneider, Bethge and Brendel, *Contrastive Learning Inverts the Data
Generating Process*, ICML 2021, arXiv:2102.08850v4: the latent spaces, ground-truth and model
conditional distributions, cross-entropies and InfoNCE objectives of Section 3, Definition 1 and
Appendices A.1.1 and A.2.1 (PDF pp. 2-5, 13-18).

Hypersphere setting (Sections 3.1-3.2, Appendix A.1): latents live on the unit sphere
`S^{N-1} ⊂ ℝ^N` with its surface measure, the marginal is uniform and positive pairs follow a
von Mises-Fisher conditional. Convex-body setting (Section 3.3, Appendix A.2): latents live in a
convex body `Z ⊂ ℝ^N` with Lebesgue measure, the marginal is uniform and the conditional is
`∝ exp(-λ δ(z̃, z))` for a (semi-)metric `δ` induced by a norm. Objectives are written in terms of
`h = f ∘ g`, as in the paper, since observations are `x = g(z)`.
-/

open MeasureTheory Filter

noncomputable section

namespace ContrastiveInverts

/-- Section 3: the latent and representation space `ℝ^N`, with its Euclidean inner product. -/
abbrev Vec (N : ℕ) := EuclideanSpace ℝ (Fin N)

/-- Section 3 and Appendix A.1.1: the unit hypersphere `Z = S^{N-1} ⊂ ℝ^N`, as a type. -/
abbrev Sph (N : ℕ) := Metric.sphere (0 : Vec N) 1

/-- Section 3, eq. (2): the surface (Hausdorff) measure on `S^{N-1}`, against which `dz̃` in the
normalising constants is taken. -/
def sphereMeasure (N : ℕ) : Measure (Sph N) := (volume : Measure (Vec N)).toSphere

/-- Section 3, eq. (2) and Theorem 1: `|Z|`, the surface area of `S^{N-1}`. -/
def sphereArea (N : ℕ) : ℝ := (sphereMeasure N Set.univ).toReal

/-- Section 3, eq. (2): the uniform marginal `p(z) = |Z|^{-1}` on `S^{N-1}`. -/
def sphereUnif (N : ℕ) : Measure (Sph N) := (sphereMeasure N Set.univ)⁻¹ • sphereMeasure N

/-- Eq. (2) and Appendix A.1.1: the von Mises-Fisher normalising constant
`C_p = ∫ exp(κ zᵀ z̃) dz̃` (independent of `z` by rotation invariance). -/
def vmfConst (N : ℕ) (κ : ℝ) (z : Vec N) : ℝ :=
  ∫ w : Sph N, Real.exp (κ * inner ℝ z (w : Vec N)) ∂sphereMeasure N

/-- Eq. (2): the von Mises-Fisher conditional of positive pairs,
`p(z̃ | z) = C_p^{-1} exp(κ zᵀ z̃)`, a density with respect to the surface measure. -/
def vmfCond (N : ℕ) (κ : ℝ) (z z' : Vec N) : ℝ :=
  Real.exp (κ * inner ℝ z z') / vmfConst N κ z

/-- Theorem 1, eq. (4): the partition function `C_h(z) = ∫ exp(h(z̃)ᵀ h(z) / τ) dz̃` of the model
conditional. -/
def sphModelConst {N : ℕ} (τ : ℝ) (h : Vec N → Vec N) (z : Vec N) : ℝ :=
  ∫ w : Sph N, Real.exp (inner ℝ (h w) (h z) / τ) ∂sphereMeasure N

/-- Theorem 1, eq. (4): the model conditional `q_h(z̃ | z) = C_h(z)^{-1} exp(h(z̃)ᵀ h(z) / τ)`. -/
def sphModelCond {N : ℕ} (τ : ℝ) (h : Vec N → Vec N) (z z' : Vec N) : ℝ :=
  Real.exp (inner ℝ (h z') (h z) / τ) / sphModelConst τ h z

/-- Proposition 1: the cross-entropy `H(p(· | z), q_h(· | z)) = E_{p(z̃|z)}[-log q_h(z̃ | z)]` at a
fixed anchor `z`. -/
def sphCondCrossEntropy {N : ℕ} (κ τ : ℝ) (h : Vec N → Vec N) (z : Vec N) : ℝ :=
  ∫ w : Sph N, vmfCond N κ z w * -Real.log (sphModelCond τ h z w) ∂sphereMeasure N

/-- Theorem 1, eq. (3): the expected cross-entropy `E_{z ∼ p(z)} H(p(· | z), q_h(· | z))`. -/
def sphCrossEntropy {N : ℕ} (κ τ : ℝ) (h : Vec N → Vec N) : ℝ :=
  ∫ z : Sph N, sphCondCrossEntropy κ τ h z ∂sphereUnif N

/-- Section 3: the law of latent positive pairs `(z, z̃)`, `z ∼ p(z)` uniform and
`z̃ ∼ p(z̃ | z)` von Mises-Fisher; `p_pos` is its image under `g × g`. -/
def sphPosPairLaw (N : ℕ) (κ : ℝ) : Measure (Sph N × Sph N) :=
  ((sphereUnif N).prod (sphereMeasure N)).withDensity
    (fun q => ENNReal.ofReal (vmfCond N κ q.1 q.2))

/-- Eq. (1): the InfoNCE objective `L_contr(f; τ, M)` with `M` negatives, written on latents with
`h = f ∘ g`: `(x, x̃) = (g z, g z̃)` is a positive pair and `x_i^- = g z_i^-` with
`z_i^-` i.i.d. uniform. -/
def infoNCE {N : ℕ} (κ τ : ℝ) (h : Vec N → Vec N) (M : ℕ) : ℝ :=
  ∫ w : (Sph N × Sph N) × (Fin M → Sph N),
    -Real.log (Real.exp (inner ℝ (h w.1.1) (h w.1.2) / τ) /
      (Real.exp (inner ℝ (h w.1.1) (h w.1.2) / τ) +
        ∑ i, Real.exp (inner ℝ (h w.1.1) (h (w.2 i)) / τ)))
    ∂(sphPosPairLaw N κ).prod (Measure.pi fun _ : Fin M => sphereUnif N)

/-- Theorems 1-2: the objective minimised "for `M → ∞`",
`lim_{M → ∞} (L_contr(f; τ, M) - log M)`. -/
def infoNCELimit {N : ℕ} (κ τ : ℝ) (h : Vec N → Vec N) : ℝ :=
  limUnder atTop (fun M : ℕ => infoNCE κ τ h M - Real.log M)

/-- Section 3.3 and Appendix A.2.1: a convex body in `ℝ^N` (compact, convex, nonempty
interior). -/
def IsConvexBody {N : ℕ} (Z : Set (Vec N)) : Prop :=
  Convex ℝ Z ∧ IsCompact Z ∧ (interior Z).Nonempty

/-- Eq. (5): `|Z|`, the Lebesgue volume of the latent space. -/
def bodyVolume {N : ℕ} (Z : Set (Vec N)) : ℝ := (volume Z).toReal

/-- Eq. (5): the uniform marginal `p(z) = |Z|^{-1}` on `Z`, as a measure on `ℝ^N`. -/
def bodyUnif {N : ℕ} (Z : Set (Vec N)) : Measure (Vec N) := (volume Z)⁻¹ • volume.restrict Z

/-- Eq. (5): `ν` is a norm on `ℝ^N` (not necessarily the Euclidean one). -/
structure IsNormFn {N : ℕ} (ν : Vec N → ℝ) : Prop where
  eq_zero_iff : ∀ x, ν x = 0 ↔ x = 0
  smul : ∀ (c : ℝ) (x : Vec N), ν (c • x) = |c| * ν x
  add_le : ∀ x y, ν (x + y) ≤ ν x + ν y

/-- Appendix A.2.1 and Lemma 1: `j : ℝ≥0 → ℝ≥0` is a continuous bijection with `j(0) = 0`
(a "continuously invertible map"); values of `j` off `[0, ∞)` are irrelevant. -/
def IsReparam (j : ℝ → ℝ) : Prop :=
  Set.BijOn j (Set.Ici 0) (Set.Ici 0) ∧ ContinuousOn j (Set.Ici 0) ∧ j 0 = 0

/-- Eq. (5), Appendix A.2.1 and Lemma 1: `δ` is a metric induced by a norm, `δ(a, b) = ν(a - b)`,
or a semi-metric `δ = j ∘ δ'` of such a metric (`j = id` gives the metric case). -/
def IsNormSemimetric {N : ℕ} (δ : Vec N → Vec N → ℝ) : Prop :=
  ∃ (ν : Vec N → ℝ) (j : ℝ → ℝ), IsNormFn ν ∧ IsReparam j ∧ ∀ a b, δ a b = j (ν (a - b))

/-- Theorem 6: the `L^α` metric `δ(a, b) = (∑_i |a_i - b_i|^α)^{1/α}`. -/
def lpDist {N : ℕ} (α : ℝ) (a b : Vec N) : ℝ := (∑ i, |a i - b i| ^ α) ^ (1 / α)

/-- Appendix A.2.1: the normalising constant `C_p(z) = ∫_Z exp(-λ δ(z, z̃)) dz̃`. -/
def expConst {N : ℕ} (lam : ℝ) (δ : Vec N → Vec N → ℝ) (Z : Set (Vec N)) (z : Vec N) : ℝ :=
  ∫ w in Z, Real.exp (-lam * δ z w)

/-- Eq. (5) and Appendix A.2.1: the ground-truth conditional
`p(z̃ | z) = C_p(z)^{-1} exp(-λ δ(z̃, z))` on `Z` (eq. (5) is the case `λ = 1`). -/
def expCond {N : ℕ} (lam : ℝ) (δ : Vec N → Vec N → ℝ) (Z : Set (Vec N)) (z z' : Vec N) : ℝ :=
  Real.exp (-lam * δ z' z) / expConst lam δ Z z

/-- Eq. (7) and Theorem 3: `C_h(z) = ∫_Z exp(-δ(h(z̃), h(z)) / τ) dz̃`. -/
def bodyModelConst {N : ℕ} (τ : ℝ) (δ : Vec N → Vec N → ℝ) (Z : Set (Vec N))
    (h : Vec N → Vec N) (z : Vec N) : ℝ :=
  ∫ w in Z, Real.exp (-δ (h w) (h z) / τ)

/-- Eq. (7) and Theorem 3: the model conditional
`q_h(z̃ | z) = C_h(z)^{-1} exp(-δ(h(z̃), h(z)) / τ)`. -/
def bodyModelCond {N : ℕ} (τ : ℝ) (δ : Vec N → Vec N → ℝ) (Z : Set (Vec N))
    (h : Vec N → Vec N) (z z' : Vec N) : ℝ :=
  Real.exp (-δ (h z') (h z) / τ) / bodyModelConst τ δ Z h z

/-- Proposition 4: `H(p(· | z), q_h(· | z)) = E_{p(z̃|z)}[-log q_h(z̃ | z)]` at a fixed anchor `z`;
`p` uses `(λ, δp)` and `q_h` uses `(τ, δ)`. -/
def bodyCondCrossEntropy {N : ℕ} (lam : ℝ) (δp : Vec N → Vec N → ℝ) (τ : ℝ)
    (δ : Vec N → Vec N → ℝ) (Z : Set (Vec N)) (h : Vec N → Vec N) (z : Vec N) : ℝ :=
  ∫ w in Z, expCond lam δp Z z w * -Real.log (bodyModelCond τ δ Z h z w)

/-- Theorems 3-4: the expected cross-entropy `E_{z ∼ p(z)} H(p(· | z), q_h(· | z))`. -/
def bodyCrossEntropy {N : ℕ} (lam : ℝ) (δp : Vec N → Vec N → ℝ) (τ : ℝ)
    (δ : Vec N → Vec N → ℝ) (Z : Set (Vec N)) (h : Vec N → Vec N) : ℝ :=
  ∫ z, bodyCondCrossEntropy lam δp τ δ Z h z ∂bodyUnif Z

/-- Appendix A.2.1: the law of latent positive pairs `(z, z̃)`, `z ∼ p(z)` uniform on `Z` and
`z̃ ∼ p(z̃ | z)`. -/
def bodyPosPairLaw {N : ℕ} (lam : ℝ) (δp : Vec N → Vec N → ℝ) (Z : Set (Vec N)) :
    Measure (Vec N × Vec N) :=
  ((bodyUnif Z).prod (volume.restrict Z)).withDensity
    (fun q => ENNReal.ofReal (expCond lam δp Z q.1 q.2))

/-- Definition 1, eq. (6): the general InfoNCE objective `L_δ-contr(f; τ, M)` with similarity
measure `δ`, written on latents with `h = f ∘ g`; positive pairs come from `p` with `(λ, δp)` and
the `M` negatives are i.i.d. uniform on `Z`. -/
def deltaInfoNCE {N : ℕ} (lam : ℝ) (δp : Vec N → Vec N → ℝ) (τ : ℝ) (δ : Vec N → Vec N → ℝ)
    (Z : Set (Vec N)) (h : Vec N → Vec N) (M : ℕ) : ℝ :=
  ∫ w : (Vec N × Vec N) × (Fin M → Vec N),
    -Real.log (Real.exp (-δ (h w.1.1) (h w.1.2) / τ) /
      (Real.exp (-δ (h w.1.1) (h w.1.2) / τ) + ∑ i, Real.exp (-δ (h w.1.1) (h (w.2 i)) / τ)))
    ∂(bodyPosPairLaw lam δp Z).prod (Measure.pi fun _ : Fin M => bodyUnif Z)

/-- Theorems 5-6: the objective minimised "for `M → ∞`",
`lim_{M → ∞} (L_δ-contr(f; τ, M) - log M)`. -/
def deltaInfoNCELimit {N : ℕ} (lam : ℝ) (δp : Vec N → Vec N → ℝ) (τ : ℝ)
    (δ : Vec N → Vec N → ℝ) (Z : Set (Vec N)) (h : Vec N → Vec N) : ℝ :=
  limUnder atTop (fun M : ℕ => deltaInfoNCE lam δp τ δ Z h M - Real.log M)

/-- Proposition 3: the alignment loss `L_δ-align(f; τ) = τ^{-1} E_{z ∼ p(z), z̃ ∼ p(z̃|z)}
δ(h(z̃), h(z))`. -/
def deltaAlign {N : ℕ} (lam : ℝ) (δp : Vec N → Vec N → ℝ) (τ : ℝ) (δ : Vec N → Vec N → ℝ)
    (Z : Set (Vec N)) (h : Vec N → Vec N) : ℝ :=
  (1 / τ) * ∫ q, δ (h q.2) (h q.1) ∂bodyPosPairLaw lam δp Z

/-- Proposition 3: the uniformity loss
`L_δ-unif(f; τ) = E_{z ∼ p(z)} log E_{z̃ ∼ p(z̃)} exp(-δ(h(z̃), h(z)) / τ)`, where `p(z̃)` is the
uniform marginal. -/
def deltaUnif {N : ℕ} (τ : ℝ) (δ : Vec N → Vec N → ℝ) (Z : Set (Vec N)) (h : Vec N → Vec N) :
    ℝ :=
  ∫ z, Real.log (∫ w, Real.exp (-δ (h w) (h z) / τ) ∂bodyUnif Z) ∂bodyUnif Z

end ContrastiveInverts
Source
Zimmermann, Sharma, Schneider, Bethge and Brendel, Contrastive Learning Inverts the Data Generating Process, ICML 2021, arXiv:2102.08850v4, Section 3 (eqs. (1)-(7), Definition 1, pp. 2-5), Appendix A.1.1 (p. 13) and Appendix A.2.1 (p. 15)
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

Conventions used in every item below. Unless stated otherwise:

  • NNN is any natural number, including N=0N=0N=0.
  • RN\mathbb{R}^NRN carries its Euclidean inner product ⟨⋅,⋅⟩\langle\cdot,\cdot\rangle⟨⋅,⋅⟩ and Lebesgue measure λN\lambda_NλN​.
  • Every integral is a real-valued (Bochner) integral, which is defined to be 000 whenever the integrand is not integrable. This includes when the integrand is not measurable.
  • log⁡\loglog is the real logarithm extended by log⁡0=0\log 0 = 0log0=0 and log⁡x=log⁡∣x∣\log x = \log|x|logx=log∣x∣ for x<0x<0x<0.
  • Division by zero returns 000, so x/0=0x/0 = 0x/0=0, and in particular 1/0=01/0 = 01/0=0.
  • Measure-valued quantities that are converted to real numbers send +∞+\infty+∞ to 000.
  • Functions written h:RN→RNh:\mathbb{R}^N\to\mathbb{R}^Nh:RN→RN are completely arbitrary. No measurability, continuity or injectivity is assumed.
  • Real parameters κ,τ,λ\kappa,\tau,\lambdaκ,τ,λ are arbitrary real numbers. They may be zero or negative.

Vec. For a natural number NNN, VecN\mathrm{Vec}_NVecN​ is the space RN\mathbb{R}^NRN of real NNN-tuples, equipped with the Euclidean inner product ⟨x,y⟩=∑ixiyi\langle x,y\rangle=\sum_{i} x_i y_i⟨x,y⟩=∑i​xi​yi​, the Euclidean norm, and the standard Lebesgue measure. For N=0N=0N=0 it is the one-point space {0}\{0\}{0}.


Sph. For a natural number NNN, SphN\mathrm{Sph}_NSphN​ is the unit sphere

SN−1={x∈RN:∥x∥=1}S^{N-1}=\{x\in\mathbb{R}^N : \|x\|=1\}SN−1={x∈RN:∥x∥=1}

in Euclidean norm, regarded as a space of its own whose points are unit vectors. For N=0N=0N=0 this set is empty. For N=1N=1N=1 it is the two-point set {−1,1}\{-1,1\}{−1,1}.


sphereMeasure. For a natural number NNN, σN\sigma_NσN​ is the measure on SN−1S^{N-1}SN−1 induced by Lebesgue measure on RN\mathbb{R}^NRN as follows. For a measurable set A⊆SN−1A\subseteq S^{N-1}A⊆SN−1,

σN(A)=N⋅λN({ ra:a∈A, 0<r<1 }),\sigma_N(A)=N\cdot\lambda_N\big(\{\,r a : a\in A,\ 0<r<1\,\}\big),σN​(A)=N⋅λN​({ra:a∈A, 0<r<1}),

that is, NNN times the volume of the open radial cone of radius 111 over AAA.

  • For N≥1N\ge 1N≥1 this coincides with the standard surface-area measure on SN−1S^{N-1}SN−1. For N=1N=1N=1 it is counting measure on {±1}\{\pm1\}{±1}.
  • For N=0N=0N=0 it is the zero measure on the empty sphere.

sphereArea. For a natural number NNN, ∣SN−1∣=σN(SN−1)|S^{N-1}| = \sigma_N(S^{N-1})∣SN−1∣=σN​(SN−1) is the total mass of the measure σN\sigma_NσN​ (defined as NNN times the Lebesgue volume of the radial cone over the set) on the unit sphere, as a real number.

  • It equals the usual surface area for N≥1N\ge1N≥1. For N=1N=1N=1 it equals 222.
  • It equals 000 for N=0N=0N=0.

sphereUnif. For a natural number NNN, uNu_NuN​ is the measure on the unit sphere SN−1⊆RNS^{N-1}\subseteq\mathbb{R}^NSN−1⊆RN given by

uN=σN(SN−1)−1 σN,u_N = \sigma_N(S^{N-1})^{-1}\,\sigma_N,uN​=σN​(SN−1)−1σN​,

where σN(A)=N⋅λN({ra:a∈A,0<r<1})\sigma_N(A)=N\cdot\lambda_N(\{ra: a\in A, 0<r<1\})σN​(A)=N⋅λN​({ra:a∈A,0<r<1}) is the surface measure.

  • For N≥1N\ge1N≥1 this is the uniform probability measure on the sphere.
  • For N=0N=0N=0 the sphere is empty and u0u_0u0​ is the zero measure.

vmfConst. For a natural number NNN, a real number κ\kappaκ (any sign, including 000), and an arbitrary vector z∈RNz\in\mathbb{R}^Nz∈RN (not required to be a unit vector),

Cp(κ,z)=∫SN−1eκ⟨z,w⟩ dσN(w).C_p(\kappa,z)=\int_{S^{N-1}} e^{\kappa\langle z,w\rangle}\,d\sigma_N(w).Cp​(κ,z)=∫SN−1​eκ⟨z,w⟩dσN​(w).

Here σN\sigma_NσN​ is the surface measure on the unit sphere, defined by σN(A)=N⋅λN({ra:a∈A, 0<r<1})\sigma_N(A)=N\cdot\lambda_N(\{ra : a\in A,\ 0<r<1\})σN​(A)=N⋅λN​({ra:a∈A, 0<r<1}).

  • The integrand is continuous and bounded on the compact sphere, so the integral is a genuine positive number for N≥1N\ge1N≥1.
  • For N=0N=0N=0 it is 000.
  • No claim is made that it is independent of zzz.

vmfCond. For a natural number NNN, a real κ\kappaκ, and arbitrary vectors z,z′∈RNz,z'\in\mathbb{R}^Nz,z′∈RN (neither required to lie on the sphere),

pκ(z′∣z)=eκ⟨z,z′⟩Cp(κ,z),Cp(κ,z)=∫SN−1eκ⟨z,w⟩ dσN(w),p_\kappa(z'\mid z)=\frac{e^{\kappa\langle z,z'\rangle}}{C_p(\kappa,z)},\qquad C_p(\kappa,z)=\int_{S^{N-1}} e^{\kappa\langle z,w\rangle}\,d\sigma_N(w),pκ​(z′∣z)=Cp​(κ,z)eκ⟨z,z′⟩​,Cp​(κ,z)=∫SN−1​eκ⟨z,w⟩dσN​(w),

where σN\sigma_NσN​ is the surface measure on the unit sphere SN−1S^{N-1}SN−1.

  • For N=0N=0N=0 the denominator is 000, so the value is 000.
  • For κ=0\kappa=0κ=0 the value is 1/σN(SN−1)1/\sigma_N(S^{N-1})1/σN​(SN−1).

sphModelConst. For a natural number NNN, a real τ\tauτ (any value, including 000 or negative), an arbitrary function h:RN→RNh:\mathbb{R}^N\to\mathbb{R}^Nh:RN→RN, and an arbitrary vector z∈RNz\in\mathbb{R}^Nz∈RN,

Ch(z)=∫SN−1exp⁡ ⁣(⟨h(w),h(z)⟩τ) dσN(w),C_h(z)=\int_{S^{N-1}} \exp\!\Big(\frac{\langle h(w),h(z)\rangle}{\tau}\Big)\,d\sigma_N(w),Ch​(z)=∫SN−1​exp(τ⟨h(w),h(z)⟩​)dσN​(w),

with σN\sigma_NσN​ the surface measure on the unit sphere.

  • hhh is not assumed measurable or bounded. If the integrand is not integrable, the value is 000.
  • If τ=0\tau=0τ=0, the exponent is 000 and Ch(z)=σN(SN−1)C_h(z)=\sigma_N(S^{N-1})Ch​(z)=σN​(SN−1).
  • For N=0N=0N=0 the value is 000.

sphModelCond. For a natural number NNN, a real τ\tauτ, an arbitrary function h:RN→RNh:\mathbb{R}^N\to\mathbb{R}^Nh:RN→RN, and arbitrary vectors z,z′∈RNz,z'\in\mathbb{R}^Nz,z′∈RN,

qh(z′∣z)=exp⁡(⟨h(z′),h(z)⟩/τ)Ch(z),Ch(z)=∫SN−1exp⁡(⟨h(w),h(z)⟩/τ) dσN(w),q_h(z'\mid z)=\frac{\exp\big(\langle h(z'),h(z)\rangle/\tau\big)}{C_h(z)},\qquad C_h(z)=\int_{S^{N-1}}\exp\big(\langle h(w),h(z)\rangle/\tau\big)\,d\sigma_N(w),qh​(z′∣z)=Ch​(z)exp(⟨h(z′),h(z)⟩/τ)​,Ch​(z)=∫SN−1​exp(⟨h(w),h(z)⟩/τ)dσN​(w),

where σN\sigma_NσN​ is the surface measure on the unit sphere.

  • If Ch(z)=0C_h(z)=0Ch​(z)=0, which happens if the integral is non-integrable or N=0N=0N=0, then qh(z′∣z)=0q_h(z'\mid z)=0qh​(z′∣z)=0.
  • If τ=0\tau=0τ=0, then qh(z′∣z)=1/σN(SN−1)q_h(z'\mid z) = 1/\sigma_N(S^{N-1})qh​(z′∣z)=1/σN​(SN−1).

sphCondCrossEntropy. For a natural number NNN, reals κ,τ\kappa,\tauκ,τ, an arbitrary function h:RN→RNh:\mathbb{R}^N\to\mathbb{R}^Nh:RN→RN, and an arbitrary vector z∈RNz\in\mathbb{R}^Nz∈RN,

Hz(κ,τ,h)=∫SN−1pκ(w∣z) (−log⁡qh(w∣z)) dσN(w).H_z(\kappa,\tau,h)=\int_{S^{N-1}} p_\kappa(w\mid z)\,\big(-\log q_h(w\mid z)\big)\,d\sigma_N(w).Hz​(κ,τ,h)=∫SN−1​pκ​(w∣z)(−logqh​(w∣z))dσN​(w).

The ingredients are:

  • σN\sigma_NσN​ is the surface measure on the unit sphere.
  • pκ(w∣z)=eκ⟨z,w⟩/∫SN−1eκ⟨z,v⟩dσN(v)p_\kappa(w\mid z)=e^{\kappa\langle z,w\rangle}/\int_{S^{N-1}}e^{\kappa\langle z,v\rangle}d\sigma_N(v)pκ​(w∣z)=eκ⟨z,w⟩/∫SN−1​eκ⟨z,v⟩dσN​(v).
  • qh(w∣z)=e⟨h(w),h(z)⟩/τ/∫SN−1e⟨h(v),h(z)⟩/τdσN(v)q_h(w\mid z)=e^{\langle h(w),h(z)\rangle/\tau}/\int_{S^{N-1}}e^{\langle h(v),h(z)\rangle/\tau}d\sigma_N(v)qh​(w∣z)=e⟨h(w),h(z)⟩/τ/∫SN−1​e⟨h(v),h(z)⟩/τdσN​(v).

Edge cases:

  • If qh(w∣z)=0q_h(w\mid z)=0qh​(w∣z)=0 (zero denominator), then log⁡0=0\log 0=0log0=0 is used.
  • If the integrand is not integrable, the value is 000.
  • For N=0N=0N=0 the value is 000.

sphCrossEntropy. For a natural number NNN, reals κ,τ\kappa,\tauκ,τ, and an arbitrary function h:RN→RNh:\mathbb{R}^N\to\mathbb{R}^Nh:RN→RN,

H(κ,τ,h)=∫SN−1Hz(κ,τ,h) duN(z),\mathcal H(\kappa,\tau,h)=\int_{S^{N-1}} H_z(\kappa,\tau,h)\,du_N(z),H(κ,τ,h)=∫SN−1​Hz​(κ,τ,h)duN​(z),

where:

  • uN=σN(SN−1)−1σNu_N=\sigma_N(S^{N-1})^{-1}\sigma_NuN​=σN​(SN−1)−1σN​ is the normalized surface measure on the unit sphere.
  • Hz(κ,τ,h)=∫SN−1pκ(w∣z) (−log⁡qh(w∣z)) dσN(w)H_z(\kappa,\tau,h)=\int_{S^{N-1}} p_\kappa(w\mid z)\,(-\log q_h(w\mid z))\,d\sigma_N(w)Hz​(κ,τ,h)=∫SN−1​pκ​(w∣z)(−logqh​(w∣z))dσN​(w).
  • pκ(w∣z)=eκ⟨z,w⟩/∫eκ⟨z,v⟩dσN(v)p_\kappa(w\mid z)=e^{\kappa\langle z,w\rangle}/\int e^{\kappa\langle z,v\rangle}d\sigma_N(v)pκ​(w∣z)=eκ⟨z,w⟩/∫eκ⟨z,v⟩dσN​(v).
  • qh(w∣z)=e⟨h(w),h(z)⟩/τ/∫e⟨h(v),h(z)⟩/τdσN(v)q_h(w\mid z)=e^{\langle h(w),h(z)\rangle/\tau}/\int e^{\langle h(v),h(z)\rangle/\tau}d\sigma_N(v)qh​(w∣z)=e⟨h(w),h(z)⟩/τ/∫e⟨h(v),h(z)⟩/τdσN​(v), with both normalizing integrals taken over the sphere.

Edge cases:

  • If the outer or an inner integrand is not integrable, that integral is 000.
  • For N=0N=0N=0 everything is 000.

sphPosPairLaw. For a natural number NNN and a real κ\kappaκ, PN,κ+P^{+}_{N,\kappa}PN,κ+​ is the measure on pairs (z,z~)∈SN−1×SN−1(z,\tilde z)\in S^{N-1}\times S^{N-1}(z,z~)∈SN−1×SN−1 given by

dPN,κ+(z,z~)=pκ(z~∣z)  duN(z) dσN(z~).dP^{+}_{N,\kappa}(z,\tilde z)=p_\kappa(\tilde z\mid z)\;d u_N(z)\,d\sigma_N(\tilde z).dPN,κ+​(z,z~)=pκ​(z~∣z)duN​(z)dσN​(z~).

In words, it has density (z,z~)↦pκ(z~∣z)(z,\tilde z)\mapsto p_\kappa(\tilde z\mid z)(z,z~)↦pκ​(z~∣z) with respect to the product of:

  • the normalized surface measure uNu_NuN​ in the first coordinate, and
  • the unnormalized surface measure σN\sigma_NσN​ in the second coordinate.

Here pκ(z~∣z)=eκ⟨z,z~⟩/∫SN−1eκ⟨z,w⟩dσN(w)p_\kappa(\tilde z\mid z)=e^{\kappa\langle z,\tilde z\rangle}/\int_{S^{N-1}}e^{\kappa\langle z,w\rangle}d\sigma_N(w)pκ​(z~∣z)=eκ⟨z,z~⟩/∫SN−1​eκ⟨z,w⟩dσN​(w). Negative density values would be truncated to 000, but this density is nonnegative. For N=0N=0N=0 it is the zero measure.


infoNCE. For a natural number NNN, reals κ,τ\kappa,\tauκ,τ, an arbitrary function h:RN→RNh:\mathbb{R}^N\to\mathbb{R}^Nh:RN→RN, and a natural number MMM (including M=0M=0M=0), write s(a,b)=⟨h(a),h(b)⟩/τs(a,b)=\langle h(a),h(b)\rangle/\taus(a,b)=⟨h(a),h(b)⟩/τ. Then

L(κ,τ,h,M)=∫−log⁡es(z,z~)es(z,z~)+∑i=1Mes(z,zi−)  d(PN,κ+⊗uN⊗M)((z,z~),(z1−,…,zM−)).\mathcal L(\kappa,\tau,h,M)=\int -\log\frac{e^{s(z,\tilde z)}}{e^{s(z,\tilde z)}+\sum_{i=1}^{M} e^{s(z,z_i^-)}}\;d\Big(P^{+}_{N,\kappa}\otimes u_N^{\otimes M}\Big)\big((z,\tilde z),(z^-_1,\dots,z^-_M)\big).L(κ,τ,h,M)=∫−loges(z,z~)+∑i=1M​es(z,zi−​)es(z,z~)​d(PN,κ+​⊗uN⊗M​)((z,z~),(z1−​,…,zM−​)).

The measure is as follows:

  • (z,z~)(z,\tilde z)(z,z~) is distributed according to PN,κ+P^{+}_{N,\kappa}PN,κ+​, with density pκ(z~∣z)=eκ⟨z,z~⟩/∫SN−1eκ⟨z,w⟩dσN(w)p_\kappa(\tilde z\mid z)=e^{\kappa\langle z,\tilde z\rangle}/\int_{S^{N-1}}e^{\kappa\langle z,w\rangle}d\sigma_N(w)pκ​(z~∣z)=eκ⟨z,z~⟩/∫SN−1​eκ⟨z,w⟩dσN​(w) with respect to uN⊗σNu_N\otimes\sigma_NuN​⊗σN​.
  • z1−,…,zM−z^-_1,\dots,z^-_Mz1−​,…,zM−​ are independent, each with the normalized surface measure uNu_NuN​ on SN−1S^{N-1}SN−1.

The scores are as follows:

  • The first coordinate zzz of the pair is the anchor: the positive score is ⟨h(z),h(z~)⟩/τ\langle h(z),h(\tilde z)\rangle/\tau⟨h(z),h(z~)⟩/τ, and each negative score is ⟨h(z),h(zi−)⟩/τ\langle h(z),h(z_i^-)\rangle/\tau⟨h(z),h(zi−​)⟩/τ.

Edge cases:

  • If M=0M=0M=0, the sum is empty, the ratio is 111, and the value is 000.
  • If τ=0\tau=0τ=0, every score is 000, and the integrand is log⁡(1+M)\log(1+M)log(1+M).
  • If the integrand is not integrable, the value is 000.

infoNCELimit. For a natural number NNN, reals κ,τ\kappa,\tauκ,τ, and an arbitrary function h:RN→RNh:\mathbb{R}^N\to\mathbb{R}^Nh:RN→RN,

L∞(κ,τ,h)=lim⁡M→∞(L(κ,τ,h,M)−log⁡M),\mathcal L_\infty(\kappa,\tau,h)=\lim_{M\to\infty}\big(\mathcal L(\kappa,\tau,h,M)-\log M\big),L∞​(κ,τ,h)=M→∞lim​(L(κ,τ,h,M)−logM),

where L(κ,τ,h,M)\mathcal L(\kappa,\tau,h,M)L(κ,τ,h,M) is the expectation, over (z,z~)∼PN,κ+(z,\tilde z)\sim P^+_{N,\kappa}(z,z~)∼PN,κ+​ and MMM independent uniform negatives zi−∼uNz_i^-\sim u_Nzi−​∼uN​, of

−log⁡(es(z,z~)/(es(z,z~)+∑ies(z,zi−))),s(a,b)=⟨h(a),h(b)⟩/τ,-\log\Big(e^{s(z,\tilde z)}\big/\big(e^{s(z,\tilde z)}+\textstyle\sum_i e^{s(z,z_i^-)}\big)\Big),\qquad s(a,b)=\langle h(a),h(b)\rangle/\tau,−log(es(z,z~)/(es(z,z~)+∑i​es(z,zi−​))),s(a,b)=⟨h(a),h(b)⟩/τ,

with all conventions of the infoNCE item.

  • The limit is over natural numbers MMM, with the term at M=0M=0M=0 using log⁡0=0\log 0=0log0=0.
  • If the sequence has no finite limit, whether because it oscillates or diverges to ±∞\pm\infty±∞, the value is an unspecified real number about which nothing is asserted.

IsConvexBody. For a natural number NNN and a set Z⊆RNZ\subseteq\mathbb{R}^NZ⊆RN, "ZZZ is a convex body" means all three of the following hold:

  1. ZZZ is convex.
  2. ZZZ is compact.
  3. The interior of ZZZ is nonempty.

For N=0N=0N=0 the only such set is Z={0}Z=\{0\}Z={0}, whose interior in the one-point space is itself.


bodyVolume. For a natural number NNN and an arbitrary set Z⊆RNZ\subseteq\mathbb{R}^NZ⊆RN, ∣Z∣=λN(Z)|Z|=\lambda_N(Z)∣Z∣=λN​(Z) is the Lebesgue (outer) measure of ZZZ as a real number.

  • ZZZ is not required to be a convex body or measurable.
  • If λN(Z)=∞\lambda_N(Z)=\inftyλN​(Z)=∞, the value is 000.

bodyUnif. For a natural number NNN and an arbitrary set Z⊆RNZ\subseteq\mathbb{R}^NZ⊆RN, uZu_ZuZ​ is the measure on all of RN\mathbb{R}^NRN given by

uZ(A)=λN(A∩Z)λN(Z).u_Z(A)=\frac{\lambda_N(A\cap Z)}{\lambda_N(Z)}.uZ​(A)=λN​(Z)λN​(A∩Z)​.

This is Lebesgue measure restricted to ZZZ, scaled by λN(Z)−1\lambda_N(Z)^{-1}λN​(Z)−1.

  • If 0<λN(Z)<∞0<\lambda_N(Z)<\infty0<λN​(Z)<∞, it is the uniform probability measure on ZZZ.
  • If λN(Z)=0\lambda_N(Z)=0λN​(Z)=0 or λN(Z)=∞\lambda_N(Z)=\inftyλN​(Z)=∞, it is the zero measure.
  • ZZZ is not required to be a convex body.

IsNormFn. For a natural number NNN and a function ν:RN→R\nu:\mathbb{R}^N\to\mathbb{R}ν:RN→R, "ν\nuν is a norm" means all three of the following hold:

  1. ν(x)=0\nu(x)=0ν(x)=0 if and only if x=0x=0x=0.
  2. ν(cx)=∣c∣ ν(x)\nu(cx)=|c|\,\nu(x)ν(cx)=∣c∣ν(x) for every real ccc and every xxx.
  3. ν(x+y)≤ν(x)+ν(y)\nu(x+y)\le\nu(x)+\nu(y)ν(x+y)≤ν(x)+ν(y) for all x,yx,yx,y.

Nonnegativity is not stated but follows. The norm need not be the Euclidean one.


IsReparam. For a function j:R→Rj:\mathbb{R}\to\mathbb{R}j:R→R, "jjj is a reparametrization" means all three of the following hold:

  1. jjj maps [0,∞)[0,\infty)[0,∞) into [0,∞)[0,\infty)[0,∞), is injective on [0,∞)[0,\infty)[0,∞), and its image of [0,∞)[0,\infty)[0,∞) is all of [0,∞)[0,\infty)[0,∞).
  2. jjj is continuous on [0,∞)[0,\infty)[0,∞).
  3. j(0)=0j(0)=0j(0)=0.

The values of jjj on negative arguments are unconstrained.


IsNormSemimetric. For a natural number NNN and a function δ:RN×RN→R\delta:\mathbb{R}^N\times\mathbb{R}^N\to\mathbb{R}δ:RN×RN→R, "δ\deltaδ is a norm-induced semimetric" means there exist a function ν:RN→R\nu:\mathbb{R}^N\to\mathbb{R}ν:RN→R and a function j:R→Rj:\mathbb{R}\to\mathbb{R}j:R→R such that all three of the following hold:

  1. ν\nuν is a norm, meaning ν(x)=0  ⟺  x=0\nu(x)=0\iff x=0ν(x)=0⟺x=0, ν(cx)=∣c∣ν(x)\nu(cx)=|c|\nu(x)ν(cx)=∣c∣ν(x), and ν(x+y)≤ν(x)+ν(y)\nu(x+y)\le\nu(x)+\nu(y)ν(x+y)≤ν(x)+ν(y).
  2. jjj maps [0,∞)[0,\infty)[0,∞) bijectively onto [0,∞)[0,\infty)[0,∞), is continuous there, and satisfies j(0)=0j(0)=0j(0)=0.
  3. δ(a,b)=j(ν(a−b))\delta(a,b)=j\big(\nu(a-b)\big)δ(a,b)=j(ν(a−b)) for all a,b∈RNa,b\in\mathbb{R}^Na,b∈RN.

Consequences of this definition:

  • δ\deltaδ is translation-invariant.
  • δ\deltaδ is symmetric.
  • δ(a,b)≥0\delta(a,b)\ge0δ(a,b)≥0, with equality exactly when a=ba=ba=b.
  • Taking jjj to be the identity gives the norm metrics themselves.

lpDist. For a natural number NNN, a real α\alphaα (unconstrained), and vectors a,b∈RNa,b\in\mathbb{R}^Na,b∈RN,

δα(a,b)=(∑i=1N∣ai−bi∣α)1/α,\delta_\alpha(a,b)=\Big(\sum_{i=1}^{N}|a_i-b_i|^{\alpha}\Big)^{1/\alpha},δα​(a,b)=(i=1∑N​∣ai​−bi​∣α)1/α,

using real powers of nonnegative numbers with the conventions 00=10^0=100=1 and 0y=00^{y}=00y=0 for y≠0y\neq0y=0.

  • No restriction such as α≥1\alpha\ge1α≥1 is imposed.
  • For α=0\alpha=0α=0: each term is 111, and the exponent 1/01/01/0 is 000, so δ0(a,b)=1\delta_0(a,b)=1δ0​(a,b)=1 for all a,ba,ba,b, including a=ba=ba=b.
  • For α<0\alpha<0α<0: coordinates where ai=bia_i=b_iai​=bi​ contribute 000.
  • For N=0N=0N=0: the value is 000 when α≠0\alpha\ne0α=0, and 111 when α=0\alpha=0α=0.

expConst. For a natural number NNN, a real λ\lambdaλ (any sign), an arbitrary function δ:RN×RN→R\delta:\mathbb{R}^N\times\mathbb{R}^N\to\mathbb{R}δ:RN×RN→R, an arbitrary set Z⊆RNZ\subseteq\mathbb{R}^NZ⊆RN, and an arbitrary vector z∈RNz\in\mathbb{R}^Nz∈RN (not required to lie in ZZZ),

Cp(z)=∫Ze−λ δ(z,w) dw,C_p(z)=\int_{Z} e^{-\lambda\,\delta(z,w)}\,dw,Cp​(z)=∫Z​e−λδ(z,w)dw,

where the integral is with respect to Lebesgue measure restricted to ZZZ, unnormalized.

  • Note the argument order: δ(z,w)\delta(z,w)δ(z,w), with the anchor first.
  • δ\deltaδ is not assumed to be a semimetric. ZZZ is not assumed to be a convex body.
  • If the integrand is not integrable, the value is 000.

expCond. For a natural number NNN, a real λ\lambdaλ, an arbitrary function δ:RN×RN→R\delta:\mathbb{R}^N\times\mathbb{R}^N\to\mathbb{R}δ:RN×RN→R, an arbitrary set Z⊆RNZ\subseteq\mathbb{R}^NZ⊆RN, and arbitrary vectors z,z′∈RNz,z'\in\mathbb{R}^Nz,z′∈RN,

p(z′∣z)=e−λ δ(z′,z)∫Ze−λ δ(z,w) dw.p(z'\mid z)=\frac{e^{-\lambda\,\delta(z',z)}}{\int_Z e^{-\lambda\,\delta(z,w)}\,dw}.p(z′∣z)=∫Z​e−λδ(z,w)dwe−λδ(z′,z)​.

The integral is with respect to Lebesgue measure on ZZZ.

  • The numerator evaluates δ\deltaδ at (z′,z)(z',z)(z′,z), while the normalizer evaluates it at (z,w)(z,w)(z,w). These orders differ, which matters only when δ\deltaδ is not symmetric.
  • z′z'z′ is not required to lie in ZZZ. The formula is not set to zero outside ZZZ.
  • If the denominator is 000, the value is 000.
  • δ\deltaδ is not assumed to be a semimetric. ZZZ is not assumed to be a convex body.

bodyModelConst. For a natural number NNN, a real τ\tauτ, an arbitrary function δ:RN×RN→R\delta:\mathbb{R}^N\times\mathbb{R}^N\to\mathbb{R}δ:RN×RN→R, an arbitrary set Z⊆RNZ\subseteq\mathbb{R}^NZ⊆RN, an arbitrary function h:RN→RNh:\mathbb{R}^N\to\mathbb{R}^Nh:RN→RN, and a vector z∈RNz\in\mathbb{R}^Nz∈RN,

Ch(z)=∫Zexp⁡ ⁣(−δ(h(w),h(z))τ) dw,C_h(z)=\int_Z \exp\!\Big(-\frac{\delta(h(w),h(z))}{\tau}\Big)\,dw,Ch​(z)=∫Z​exp(−τδ(h(w),h(z))​)dw,

where the integral is with respect to Lebesgue measure on ZZZ.

  • If τ=0\tau=0τ=0, the integrand is 111 and the value is λN(Z)\lambda_N(Z)λN​(Z) when that is finite.
  • If the integrand is not integrable, the value is 000.

bodyModelCond. For a natural number NNN, a real τ\tauτ, an arbitrary function δ:RN×RN→R\delta:\mathbb{R}^N\times\mathbb{R}^N\to\mathbb{R}δ:RN×RN→R, an arbitrary set Z⊆RNZ\subseteq\mathbb{R}^NZ⊆RN, an arbitrary function h:RN→RNh:\mathbb{R}^N\to\mathbb{R}^Nh:RN→RN, and vectors z,z′∈RNz,z'\in\mathbb{R}^Nz,z′∈RN,

qh(z′∣z)=exp⁡(−δ(h(z′),h(z))/τ)∫Zexp⁡(−δ(h(w),h(z))/τ) dw.q_h(z'\mid z)=\frac{\exp\big(-\delta(h(z'),h(z))/\tau\big)}{\int_Z\exp\big(-\delta(h(w),h(z))/\tau\big)\,dw}.qh​(z′∣z)=∫Z​exp(−δ(h(w),h(z))/τ)dwexp(−δ(h(z′),h(z))/τ)​.
  • The integral is with respect to Lebesgue measure on ZZZ.
  • In both places δ\deltaδ is evaluated with the anchor's image h(z)h(z)h(z) second.
  • If the denominator is 000, the value is 000.

bodyCondCrossEntropy. For a natural number NNN, reals λ,τ\lambda,\tauλ,τ, two arbitrary functions δp,δ:RN×RN→R\delta_p,\delta:\mathbb{R}^N\times\mathbb{R}^N\to\mathbb{R}δp​,δ:RN×RN→R, an arbitrary set Z⊆RNZ\subseteq\mathbb{R}^NZ⊆RN, an arbitrary function h:RN→RNh:\mathbb{R}^N\to\mathbb{R}^Nh:RN→RN, and a vector z∈RNz\in\mathbb{R}^Nz∈RN,

Hz=∫Zp(w∣z) (−log⁡qh(w∣z)) dw.H_z=\int_Z p(w\mid z)\,\big(-\log q_h(w\mid z)\big)\,dw.Hz​=∫Z​p(w∣z)(−logqh​(w∣z))dw.

The integral is with respect to Lebesgue measure on ZZZ, with:

  • p(w∣z)=e−λδp(w,z)/∫Ze−λδp(z,v)dvp(w\mid z)=e^{-\lambda\delta_p(w,z)}/\int_Z e^{-\lambda\delta_p(z,v)}dvp(w∣z)=e−λδp​(w,z)/∫Z​e−λδp​(z,v)dv, built from λ\lambdaλ and δp\delta_pδp​.
  • qh(w∣z)=e−δ(h(w),h(z))/τ/∫Ze−δ(h(v),h(z))/τdvq_h(w\mid z)=e^{-\delta(h(w),h(z))/\tau}/\int_Z e^{-\delta(h(v),h(z))/\tau}dvqh​(w∣z)=e−δ(h(w),h(z))/τ/∫Z​e−δ(h(v),h(z))/τdv, built from τ\tauτ and δ\deltaδ.

The two functions δp\delta_pδp​ and δ\deltaδ are independent and not required to be equal or semimetrics.

Edge cases:

  • If qh(w∣z)=0q_h(w\mid z)=0qh​(w∣z)=0, then log⁡0=0\log 0=0log0=0 is used.
  • If the integrand is not integrable, the value is 000.

bodyCrossEntropy. For a natural number NNN, reals λ,τ\lambda,\tauλ,τ, arbitrary functions δp,δ\delta_p,\deltaδp​,δ on RN×RN\mathbb{R}^N\times\mathbb{R}^NRN×RN, an arbitrary set Z⊆RNZ\subseteq\mathbb{R}^NZ⊆RN, and an arbitrary function h:RN→RNh:\mathbb{R}^N\to\mathbb{R}^Nh:RN→RN,

H=∫RNHz duZ(z),\mathcal H=\int_{\mathbb{R}^N} H_z\,du_Z(z),H=∫RN​Hz​duZ​(z),

where:

  • uZ(A)=λN(A∩Z)/λN(Z)u_Z(A)=\lambda_N(A\cap Z)/\lambda_N(Z)uZ​(A)=λN​(A∩Z)/λN​(Z). This is the zero measure if λN(Z)∈{0,∞}\lambda_N(Z)\in\{0,\infty\}λN​(Z)∈{0,∞}.
  • Hz=∫Zp(w∣z) (−log⁡qh(w∣z)) dwH_z=\int_Z p(w\mid z)\,(-\log q_h(w\mid z))\,dwHz​=∫Z​p(w∣z)(−logqh​(w∣z))dw.
  • p(w∣z)=e−λδp(w,z)/∫Ze−λδp(z,v)dvp(w\mid z)=e^{-\lambda\delta_p(w,z)}/\int_Z e^{-\lambda\delta_p(z,v)}dvp(w∣z)=e−λδp​(w,z)/∫Z​e−λδp​(z,v)dv.
  • qh(w∣z)=e−δ(h(w),h(z))/τ/∫Ze−δ(h(v),h(z))/τdvq_h(w\mid z)=e^{-\delta(h(w),h(z))/\tau}/\int_Z e^{-\delta(h(v),h(z))/\tau}dvqh​(w∣z)=e−δ(h(w),h(z))/τ/∫Z​e−δ(h(v),h(z))/τdv.

If the outer or an inner integrand is not integrable, that integral is 000.


bodyPosPairLaw. For a natural number NNN, a real λ\lambdaλ, an arbitrary function δp\delta_pδp​ on RN×RN\mathbb{R}^N\times\mathbb{R}^NRN×RN, and an arbitrary set Z⊆RNZ\subseteq\mathbb{R}^NZ⊆RN, PZ+P^+_ZPZ+​ is the measure on RN×RN\mathbb{R}^N\times\mathbb{R}^NRN×RN defined by

dPZ+(z,z~)=max⁡{p(z~∣z),0}  duZ(z) dλN∣Z(z~),dP^+_Z(z,\tilde z)=\max\{p(\tilde z\mid z),0\}\;du_Z(z)\,d\lambda_N|_Z(\tilde z),dPZ+​(z,z~)=max{p(z~∣z),0}duZ​(z)dλN​∣Z​(z~),

where:

  • uZ=λN(Z)−1λN∣Zu_Z=\lambda_N(Z)^{-1}\lambda_N|_ZuZ​=λN​(Z)−1λN​∣Z​ is the normalized measure on ZZZ, used in the first coordinate.
  • λN∣Z\lambda_N|_ZλN​∣Z​ is unnormalized Lebesgue measure on ZZZ, used in the second coordinate.
  • p(z~∣z)=e−λδp(z~,z)/∫Ze−λδp(z,w)dwp(\tilde z\mid z)=e^{-\lambda\delta_p(\tilde z,z)}/\int_Z e^{-\lambda\delta_p(z,w)}dwp(z~∣z)=e−λδp​(z~,z)/∫Z​e−λδp​(z,w)dw. This is nonnegative, so the truncation at 000 has no effect.

deltaInfoNCE. For a natural number NNN, reals λ,τ\lambda,\tauλ,τ, arbitrary functions δp,δ\delta_p,\deltaδp​,δ on RN×RN\mathbb{R}^N\times\mathbb{R}^NRN×RN, an arbitrary set Z⊆RNZ\subseteq\mathbb{R}^NZ⊆RN, an arbitrary function h:RN→RNh:\mathbb{R}^N\to\mathbb{R}^Nh:RN→RN, and a natural number MMM (including 000), write s(a,b)=−δ(h(a),h(b))/τs(a,b)=-\delta(h(a),h(b))/\taus(a,b)=−δ(h(a),h(b))/τ. Then

Lδ(M)=∫−log⁡es(z,z~)es(z,z~)+∑i=1Mes(z,zi−)  d(PZ+⊗uZ⊗M)((z,z~),(z1−,…,zM−)).\mathcal L_\delta(M)=\int -\log\frac{e^{s(z,\tilde z)}}{e^{s(z,\tilde z)}+\sum_{i=1}^M e^{s(z,z_i^-)}}\;d\Big(P^+_Z\otimes u_Z^{\otimes M}\Big)\big((z,\tilde z),(z_1^-,\dots,z_M^-)\big).Lδ​(M)=∫−loges(z,z~)+∑i=1M​es(z,zi−​)es(z,z~)​d(PZ+​⊗uZ⊗M​)((z,z~),(z1−​,…,zM−​)).

The measure is as follows:

  • (z,z~)(z,\tilde z)(z,z~) is distributed according to PZ+P^+_ZPZ+​, with density p(z~∣z)=e−λδp(z~,z)/∫Ze−λδp(z,w)dwp(\tilde z\mid z)=e^{-\lambda\delta_p(\tilde z,z)}/\int_Z e^{-\lambda\delta_p(z,w)}dwp(z~∣z)=e−λδp​(z~,z)/∫Z​e−λδp​(z,w)dw with respect to uZ⊗λN∣Zu_Z\otimes\lambda_N|_ZuZ​⊗λN​∣Z​.
  • zi−z_i^-zi−​ are independent with law uZ=λN(Z)−1λN∣Zu_Z=\lambda_N(Z)^{-1}\lambda_N|_ZuZ​=λN​(Z)−1λN​∣Z​.

The scores are as follows:

  • The anchor is the first coordinate zzz, and δ\deltaδ is evaluated as δ(h(z),h(z~))\delta(h(z),h(\tilde z))δ(h(z),h(z~)) and δ(h(z),h(zi−))\delta(h(z),h(z_i^-))δ(h(z),h(zi−​)), with the anchor first.
  • This is the opposite order to the model conditional qhq_hqh​ in the bodyModelCond item, which evaluates δ(h(z~),h(z))\delta(h(\tilde z),h(z))δ(h(z~),h(z)).

Edge cases:

  • If M=0M=0M=0, the value is 000.
  • If τ=0\tau=0τ=0, the integrand is log⁡(1+M)\log(1+M)log(1+M).
  • If the integrand is not integrable, the value is 000.
  • If λN(Z)∈{0,∞}\lambda_N(Z)\in\{0,\infty\}λN​(Z)∈{0,∞}, all measures involved are zero and the value is 000.

deltaInfoNCELimit. For a natural number NNN, reals λ,τ\lambda,\tauλ,τ, arbitrary functions δp,δ\delta_p,\deltaδp​,δ, an arbitrary set Z⊆RNZ\subseteq\mathbb{R}^NZ⊆RN, and an arbitrary function h:RN→RNh:\mathbb{R}^N\to\mathbb{R}^Nh:RN→RN,

Lδ,∞=lim⁡M→∞(Lδ(M)−log⁡M),\mathcal L_{\delta,\infty}=\lim_{M\to\infty}\big(\mathcal L_\delta(M)-\log M\big),Lδ,∞​=M→∞lim​(Lδ​(M)−logM),

where Lδ(M)\mathcal L_\delta(M)Lδ​(M) is the expectation, over (z,z~)∼PZ+(z,\tilde z)\sim P^+_Z(z,z~)∼PZ+​ and MMM independent negatives zi−∼uZz_i^-\sim u_Zzi−​∼uZ​, of

−log⁡(es(z,z~)/(es(z,z~)+∑ies(z,zi−))),s(a,b)=−δ(h(a),h(b))/τ,-\log\Big(e^{s(z,\tilde z)}\big/\big(e^{s(z,\tilde z)}+\textstyle\sum_i e^{s(z,z_i^-)}\big)\Big),\qquad s(a,b)=-\delta(h(a),h(b))/\tau,−log(es(z,z~)/(es(z,z~)+∑i​es(z,zi−​))),s(a,b)=−δ(h(a),h(b))/τ,

with all conventions of the deltaInfoNCE item.

  • The limit is along natural numbers MMM, with log⁡0=0\log 0 = 0log0=0 at M=0M=0M=0.
  • If no finite limit exists, the value is an unspecified real number about which nothing is asserted.

deltaAlign. For a natural number NNN, reals λ,τ\lambda,\tauλ,τ, arbitrary functions δp,δ\delta_p,\deltaδp​,δ on RN×RN\mathbb{R}^N\times\mathbb{R}^NRN×RN, an arbitrary set Z⊆RNZ\subseteq\mathbb{R}^NZ⊆RN, and an arbitrary function h:RN→RNh:\mathbb{R}^N\to\mathbb{R}^Nh:RN→RN,

Lalign=1τ∫δ(h(z~),h(z)) dPZ+(z,z~).\mathcal L_{\text{align}}=\frac1\tau\int \delta\big(h(\tilde z),h(z)\big)\,dP^+_Z(z,\tilde z).Lalign​=τ1​∫δ(h(z~),h(z))dPZ+​(z,z~).

Here PZ+P^+_ZPZ+​ has density p(z~∣z)=e−λδp(z~,z)/∫Ze−λδp(z,w)dwp(\tilde z\mid z)=e^{-\lambda\delta_p(\tilde z,z)}/\int_Z e^{-\lambda\delta_p(z,w)}dwp(z~∣z)=e−λδp​(z~,z)/∫Z​e−λδp​(z,w)dw with respect to uZ⊗λN∣Zu_Z\otimes\lambda_N|_ZuZ​⊗λN​∣Z​, where uZu_ZuZ​ is Lebesgue measure on ZZZ normalized by λN(Z)\lambda_N(Z)λN​(Z).

  • If τ=0\tau=0τ=0, the value is 000, because 1/0=01/0=01/0=0.
  • If the integrand is not integrable, the value is 000.

deltaUnif. For a natural number NNN, a real τ\tauτ, an arbitrary function δ\deltaδ on RN×RN\mathbb{R}^N\times\mathbb{R}^NRN×RN, an arbitrary set Z⊆RNZ\subseteq\mathbb{R}^NZ⊆RN, and an arbitrary function h:RN→RNh:\mathbb{R}^N\to\mathbb{R}^Nh:RN→RN,

Lunif=∫log⁡(∫exp⁡ ⁣(−δ(h(w),h(z))/τ) duZ(w)) duZ(z),\mathcal L_{\text{unif}}=\int \log\Big(\int \exp\!\big(-\delta(h(w),h(z))/\tau\big)\,du_Z(w)\Big)\,du_Z(z),Lunif​=∫log(∫exp(−δ(h(w),h(z))/τ)duZ​(w))duZ​(z),

where uZ(A)=λN(A∩Z)/λN(Z)u_Z(A)=\lambda_N(A\cap Z)/\lambda_N(Z)uZ​(A)=λN​(A∩Z)/λN​(Z) is the normalized measure on ZZZ, used for both the inner and outer integrals.

  • This measure is zero if λN(Z)∈{0,∞}\lambda_N(Z)\in\{0,\infty\}λN​(Z)∈{0,∞}, in which case the value is 000.
  • If the inner integral is 000, which includes the case where it is not integrable, then log⁡0=0\log 0=0log0=0 is used.
  • If the outer integrand is not integrable, the value is 000.
Human review
  • Endorsed by Shuze Chen · Nov 23, 2026

    Confirmed by the moderator at approval.

  • Endorsed by Xeroth · Nov 23, 2026

    Confirmed by the mission captain (proposal self-audit).

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 paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me