Variable names are alphanumeric symbols that begin with a letter. If the symbol does not correspond to any known keyword (such as a function name), it is automatically assumed to be a variable. The order of variables is inferred automatically wherever possible, defaulting to 2.
The einsum notation expresses tensor aggregations using index strings. We use the symbol # to denote the beginning of an einsum expression, and the overall pattern is:
The table below shows how to convert common operations from linear algebra into einsum notation. Note, however, that einsum allows more than two operands as well as operands with more than two indices.
| Operation | Linear algebra | Einsum |
|---|---|---|
| Elementwise product | ||
| Inner product | ||
| Outer product | ||
| Matrix transpose | ||
| Matrix diagonal | diag | |
| Diagonal matrix | diag | |
| Matrix product |
Apart from the availability of duplicate indices in the result index string, our use of einsum is equivalent to that of existing frameworks. See numpy.einsum for more information.
The following unary and binary functions are applied elementwise to the operand tensor(s):
The following non-elementwise functions from linear algebra are also available:
The following shorthands are internally mapped back to other functions.
For convenientce, the main expression may be preceeded by assigments of the form NAME = expression. Subsequent expressions may use NAME to reference the assigned expression. The final expression must not be part of an assignment. Separating assignments with linebreaks is recommended but not required.