Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Aether Catalog definitions — MachineLearning_SoftmaxAttentionEquivariance

Definition
MachineLearning_SoftmaxAttentionEquivariance

by raver1975 · Sep 12, 2026 · Mathlib c5ea003 (Lean v4.30.0)

aether-catalogmachinelearning

Definition bundle for the Aether Catalog module MachineLearning.SoftmaxAttentionEquivariance, transplanted by skeleton subtraction; supplies the types and constants the catalog's theorems import.

Definition code
-- Def bundle generated from MachineLearning/SoftmaxAttentionEquivariance.lean by skeleton subtraction
import Mathlib

/-!
# Permutation equivariance of scaled dot-product attention

This file formalizes standard row-wise softmax attention
`A(Q,K,V) = softmax(QKᵀ / √d) V` on finite token and feature types.
Its main theorem proves exact equivariance under an arbitrary simultaneous permutation
of the query, key, and value token axes.  Further results establish positivity,
row-stochasticity, preservation of constant values, and closure under stacking.
-/

open scoped BigOperators

namespace SoftmaxAttention

variable {ι κ ν : Type*} [Fintype ι] [Fintype κ]

/-- Scaled dot-product score.  The positive parameter `scale` represents `√d`. -/
noncomputable def scaledScore (scale : ℝ) (q k : κ → ℝ) : ℝ :=
  (∑ a, q a * k a) / scale

/-- The normalizing denominator in one row of softmax attention. -/
noncomputable def softmaxDenom (scale : ℝ) (q : ι → κ → ℝ) (k : ι → κ → ℝ) (i : ι) : ℝ :=
  ∑ j, Real.exp (scaledScore scale (q i) (k j))

/-- A row-wise softmax attention weight. -/
noncomputable def softmaxWeight (scale : ℝ) (q : ι → κ → ℝ) (k : ι → κ → ℝ)
    (i j : ι) : ℝ :=
  Real.exp (scaledScore scale (q i) (k j)) / softmaxDenom scale q k i

/-- Standard scaled dot-product attention applied to a value tensor. -/
noncomputable def attention (scale : ℝ) (q : ι → κ → ℝ) (k : ι → κ → ℝ)
    (v : ι → ν → ℝ) (i : ι) (b : ν) : ℝ :=
  ∑ j, softmaxWeight scale q k i j * v j b

/-- Reindex a token-indexed tensor by a permutation. -/
def permute (σ : Equiv.Perm ι) (x : ι → κ → ℝ) : ι → κ → ℝ :=
  fun i => x (σ.symm i)








end SoftmaxAttention

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