Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Aether Catalog definitions — MachineLearning_Neural_SubQuadraticAttention

Definition
MachineLearning_Neural_SubQuadraticAttention

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

aether-catalogmachinelearning

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

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

/-! # CatalogBuild.MachineLearning.Neural.SubQuadraticAttention

Auto-generated from theorem catalog database.
Domain: MachineLearning/Neural
Declarations: 16
-/


noncomputable section

/-- The block size for sub-quadratic attention: B = max(⌈√N⌉, 1). -/
def blockSize (N : ℕ) : ℕ := max (Nat.sqrt N + 1) 1






/-- The block index of token i. -/
def blockIndex (N : ℕ) (i : ℕ) : ℕ := i / blockSize N


/-- The sparse attention mask: token i attends to token j iff they are
in the same block, or j is in block 0 (the global anchor block). -/
def sparseAttentionMask (N : ℕ) (i j : ℕ) : Bool :=
  (blockIndex N i = blockIndex N j) || (blockIndex N j = 0)


/-- Number of tokens that token i attends to under block-sparse attention. -/
def sparseAttendCount (N : ℕ) (i : ℕ) : ℕ :=
  ((Finset.range N).filter (fun j => sparseAttentionMask N i j = true)).card


/-- The total number of attention pairs in full quadratic attention. -/
def fullAttentionPairs (N : ℕ) : ℕ := N * N


/-- The total number of attention pairs in block-sparse attention. -/
def sparseAttentionPairs (N : ℕ) : ℕ :=
  ∑ i ∈ Finset.range N, sparseAttendCount N i










/-- Frobenius norm squared of a matrix. -/
def frobeniusNormSq (n m : ℕ) (M : Matrix (Fin n) (Fin m) ℝ) : ℝ :=
  ∑ i : Fin n, ∑ j : Fin m, (M i j) ^ 2




/-- The residual (error) matrix from masking. -/
def maskResidual (n : ℕ) (mask : Fin n → Fin n → Bool) (M : Matrix (Fin n) (Fin n) ℝ) :
    Matrix (Fin n) (Fin n) ℝ :=
  Matrix.of (fun i j => if mask i j then 0 else M i j)




end

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