Algebraic semantics for einsum #
A checked einsum ranges over one finite assignment of every logical axis. Each operand reads that assignment through three coordinate operations:
- select the labels used by the operand, retaining repeated labels;
- use the same selected coordinate at every occurrence of a repeated label, which implements diagonal indexing; and
- project resolved dimensions to the operand's physical dimensions, mapping singleton dimensions to their unique coordinate.
The operand values are multiplied in source order and contracted coordinates
are accumulated in row-major order. These ordered semantics require only
Mul, Add, and scalar zero and one, so the same denotation applies to IEEE
floating-point values without asserting false associativity or commutativity
instances. When the scalar operations do form additive and multiplicative
monoids, a theorem identifies the ordered denotation with the usual
Rep.push fiber sum. Distributivity enters only in multilinearity
theorems, and commutative multiplication only in the selected-operand
adjoint.
Missing leading ellipsis slots need no special case: an operand simply omits those logical axes, so its value is constant while the omitted coordinates vary. This is exactly singleton broadcasting under right-aligned ellipses.
The heterogeneous family of input tensors accepted by a checked einsum.
Instances For
The output tensor type inferred by a checked einsum.
Instances For
Expanded operand-axis lists and input shapes have the same count.
Expanded logical labels used by one input operand.
Instances For
Every logical label used by an operand belongs to the global assignment.
The physical shape of an operand broadcasts to its resolved logical shape.
This theorem is the proof-level bridge from the checker's per-dimension certificate to the coordinate map used by the denotation.
Convert a global assignment coordinate to its named logical coordinates.
Instances For
Convert an output tensor coordinate to its named logical coordinates.
Instances For
Retain the requested output labels from a complete logical-axis assignment.
Instances For
Read one operand coordinate from a complete logical-axis assignment.
Repeated labels select one shared coordinate before singleton broadcasting, so this single map covers ordinary indexing, diagonals, and broadcasting.
Instances For
Every contracted logical axis belongs to the complete global-axis assignment.
One einsum contraction-fiber coordinate is exactly one assignment of every global logical axis absent from the output.
The equivalence is independent of operand count, tensor rank, repeated labels, broadcasting, and axis lengths. It therefore also covers scalar outputs, contractions of no axes, and empty fibers caused by zero-length dimensions.
Instances For
The contraction-fiber equivalence reads the contracted axes from the complete global logical-axis assignment.
Every output coordinate has one complete assignment for each setting of the contracted logical axes.
The fiber cardinality is therefore the product of the contracted lengths. The formula includes scalar outputs, contractions of no axes, and empty fibers caused by a zero-length contracted axis.
Reconstruct a complete logical coordinate from retained output coordinates and one row-major assignment of every contracted axis.
The output axes come first only in this intermediate tuple. Selection restores the checked global-axis order before converting back to a tensor coordinate.
Instances For
Reconstructing a global coordinate preserves its supplied output coordinate.
Selecting contracted axes from a reconstructed coordinate recovers their values.
Add values over a multidimensional coordinate space in row-major order.
The initial accumulator is explicit because generated kernels may continue a partially computed contraction. No associativity or commutativity law is assumed; the nesting order is part of the denotation.
The fused lowering in Lowering.Einsum runs this very function rather than a
private copy of it, so the executable kernel and the denotation can never drift
apart in their traversal order.
Instances For
Nested row-major coordinate addition equals the finite sum for lawful addition.
This is the only place the library crosses from the ordered loop to a big operator; the lowering module reuses it instead of reproving it.
The tensor of ordered operand products over complete logical assignments.
List.ofFn enumerates operand indices from left to right, and List.foldl
records that exact multiplication order without assuming monoid laws.
Instances For
Reading the product tensor exposes the source-ordered multiplicative fold.
For a lawful monoid, the source-ordered fold is the usual list product.
The ordered-product tensor is additive in any selected input operand.
All other operands remain fixed through Function.update. This statement
covers operands of different ranks, repeated labels, singleton broadcasting,
and any position in a positive-arity einsum. In particular, it does not move
the selected operand through its neighbors, so a noncommutative semiring is
sufficient.
Independent einsum denotation: sum ordered operand products over contraction coordinates while retaining the output labels in the user's requested order.
Both operand multiplication and contraction addition have explicit left-to-right orders. This is the semantic contract used for scalar types, such as IEEE floats, whose operations do not satisfy the algebraic laws required by unordered finite products and sums.
Instances For
Evaluate an einsum using any explicit reconstruction of the complete global coordinate from the retained output coordinate and contracted-axis coordinates.
The premises state exactly that the reconstruction remains in the requested output fiber and recovers every supplied contracted-axis tuple. This theorem is independent of rank and operand count, making it suitable for relating symbolic einsum expressions to established finite-sum operations.
For lawful additive and multiplicative monoids, the ordered denotation is the usual fiber sum of source-ordered operand products.
Pull an output cotangent back to one selected einsum operand.
For each complete logical-axis assignment, the selected operand factor is replaced by one, leaving the product of all other operands. That product is multiplied by the output cotangent at the retained output coordinate, then all contributions are pushed back to the selected operand's physical coordinate. The push accounts uniformly for contraction, singleton broadcasting, omitted ellipsis slots, and repeated-label diagonal scatter.
The value stored in inputTensors operand is deliberately ignored: an einsum
is multilinear, so its partial derivative with respect to one operand depends
only on the other operands. Commutative multiplication is required to express
the result using the standard tensor pairing with the selected tangent as its
left factor.
Instances For
Einsum is additive in every individual operand over an arbitrary semiring.
The selected operand may have any checked shape and may occur anywhere in the heterogeneous input family. The result follows by distributing its ordered product at each complete logical assignment and then distributing the finite sum over every contraction fiber.
The selected-operand einsum VJP is adjoint to replacing that operand by an arbitrary tangent tensor.
The statement quantifies over an arbitrary checked operand position and its dependent physical shape. It therefore covers any operand count, heterogeneous ranks, repeated-label diagonals, right-aligned ellipses, singleton broadcasting, scalar outputs, and zero-length axes without operation-specific cases.
Einsum partitions complete logical assignments by their output coordinate, so summing the output recovers the sum of all ordered operand products.