These blocks introduce input tensors by name, followed by their order (an integer).
Any alphanumeric symbol that begins with a letter is a valid tensor name, unless it is already used as a function name.
Multiple specifications on the same line should be separated by a comma.
Only variables are subject to the optimization.
Objective function (“min” or “max”):
The expression specified after the “min” or “max” keyword is the optimization target.
Common subexpressions (“cse”; optional):
Specify a (recurring) expression in the form “{name} = {expression}”.
In the following, the specified expression will be substituted whenever {name} appears.
Multiple expressions may be specified.
Constraints (“st”; optional):
Specify one or multiple constraints by combining two expressions with ”==” (or ”=”), ”<”, ”>”, ”<=” or ”>=”.
Example:
Einsum
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.
Elementwise functions
The following unary and binary functions are applied elementwise to the operand tensor(s):
, , ,
, ,
(or ), , , ,
, , ,
, , ,
Non-elementwise functions
The following non-elementwise functions from linear algebra are also available:
, ,
Constant symbols
Constants are fixed (i.e. non-input) tensors.
Two kinds of constants are permitted:
Numbers such as , and are interpreted as tensors with that entry in every position. The order is inferred from context.
Delta tensors are written as , where is an integer. For example, is the unit matrix.
Shorthand notations
The following shorthands are internally mapped back to other functions.
is the sum of all elements in , e.g. for a matrix.
Similarly, sums over the diagonal of .
computes the elementwise product of and , e.g. for matrices. Scalars are also allowed.