Formalizing $\mathsf{einsum}$ with Named Tensor Notation
Yafei Yang, Chung-chieh Shan
Key points
From the paper's conclusion- We formalize the denotational semantics of a language of tensors (multi-dimensional arrays) that supports $\mathsf{einsum}$ and repeated tensors ($\mathsf{expand}$).
Abstract
Einstein notation ($\mathsf{einsum}$) is a widely adopted tensor operation that has proven useful in areas such as machine learning and quantum computing. But it had no formal semantics until recently, and its properties had no mechanized verification. We formalize the denotational semantics of a language of tensors (multi-dimensional arrays) that supports $\mathsf{einsum}$ and repeated tensors ($\mathsf{expand}$). With this semantics, we verify equational rewriting rules about $\mathsf{einsum}$ and $\mathsf{expand}$ that improve the performance of tensor computation. Whereas typical languages use unnamed tensors, whose shape is a sequence of natural numbers, we found it advantageous for mechanization to use named tensors, whose shape is a finite map from names to natural numbers. To our knowledge, this is the first time that the semantics and rewriting rules of $\mathsf{einsum}$ are mechanized in a proof assistant. Our solution is agnostic to proof assistants; we have implemented it in Lean and partially in Agda.
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- Representing Tensors as Compositions for Efficient Computation on Sparse and Structured DataarXiv · 2026
- Semidirect sums of tensors and the matrix multiplication exponentarXiv · 2026
- How to prove equations using diagrams: A categorical and operational semantics for e-graphsarXiv · 2026
- Higher rewriting for strong linearly distributive coherencearXiv · 2026
- TensorRocq: Enabling Diagrammatic Reasoning in RocqProceedings of the ACM on Programming Languages · 2026
- Grassmann: The Coordinate-Independent Linear Algebra Programming LanguagearXiv · 2026