Operators
The expression vocabulary: what each operator does, its arguments, and its result.
An expression is one of four things:
| Form | JSON | Meaning |
|---|---|---|
| Number | 2, 1.5e-9 | A literal. Integer and float tokens are distinguished. |
| Variable | "O3" | A reference to a variable, parameter, species, or index. |
| Operator node | {"op": …, "args": […]} | An application. |
| Scoped reference | "Chem.O3" | A dotted path into a subsystem. |
An operator node always has op and args. Some operators take extra named
fields — wrt on D, output_idx/ranges on faq, regions/values
on makearray — which are listed on each operator’s page.
Text
k * A * B
JSON
{ "op": "*", "args": ["k", "A", "B"] }
Two tiers
Evaluable core (closed). The operators in the index below have a defined evaluator in every binding. The set is closed: adding one is a specification change. That closure is what lets a conforming reader in any language evaluate any document without executing author-supplied code.
Rewrite-target (open). grad, div, laplacian, integral, a D with a
spatial wrt, and any operator you invent have no evaluator. They must be
eliminated by a template rewrite
before evaluation. A document
may load with them present; one that reaches evaluation still carrying them is
rejected with unlowered_operator.
A rewrite-target operator gets no privileges: its result dimension is unknown
until it is lowered, and no binding may special-case its name. A custom op
carries its scheme parameters in attrs rather than in dedicated fields.
Text form
Every example on these pages is one expression shown two ways: a block labelled
Text, the notation an author writes, followed by a block labelled JSON,
the node it denotes. They are not two different examples, and they are not
independent — each pair is checked with the shipped parse_expression and
to_ascii, which are inverses, so the text parses to exactly the JSON shown and
the JSON prints back to exactly the text.
Multiplication is always explicit (k * A, never kA), because identifiers are
multi-letter.
A JSON block with no Text partner is a form the text notation cannot spell
today. broadcast and enum have no surface of their own — the first prints as
the operator it applies, the second as a dotted name that re-parses as a scoped
variable reference. neg shares the surface of unary -. And a few forms lose
a field on the way out: a D carrying trailing boundary operands, a grad
carrying dim, and an overlap join. Whole .esm documents are shown as JSON
throughout; the text notation covers expressions and equations, not files.
Index
Arity structural means the operator’s operands live in dedicated fields rather
than in args, and are described on its own page.
The operators esm 2.0.0 removed (fn, table_lookup, skolem, rank, the
argmin/argmax operator forms, the two polygon operators, and aggregate, the
old spelling of faq) are rejected at load with removed_op; removed operators
lists the
standard-library template that replaces each, and geometry
covers
polygon overlap areas.
Rewrite-target sugar — grad, div, laplacian, integral, and a spatial
D — is covered on the calculus
page. It is not part of the set
above.
Dimensional rules
Dimensional analysis follows the operator, and findings are warnings: a dimensional problem never makes a document invalid.
| Class | Operators | Rule |
|---|---|---|
| transcendental | exp, log, log10, sinh, cosh, tanh, asinh, acosh, atanh | argument must be dimensionless; result dimensionless |
| circular | sin, cos, tan | argument must be an angle; result dimensionless |
| inverse circular | asin, acos, atan, atan2 | argument dimensionless; result an angle |
| comparison | <, <=, >, >=, ==, != | operands must share a dimension; result dimensionless |
| boolean | and, or, not | operands dimensionless; result dimensionless |
Everything else either propagates its operands’ dimension (+, -, min,
max, ifelse) or combines them (*, /, ^). A rewrite-target operator has
no rule, so a checker reports unknown and skips the enclosing check.
- Aggregation
faq, its relational surface, and arg-witnesses, keys and ranks from the relational templates.
- Arithmetic, comparison, logic
+ - * / ^ neg and the relational and boolean operators.
- Arrays
index, makearray, reshape, transpose, concat, broadcast.
- Calculus
D, ic, and the rewrite-target sugar grad / div / laplacian / integral.
- Constants and conditionals
ifelse, Pre, const, true, enum, and the niladic constants.
- Elementary functions
The 23 scalar mathematical functions.
- Geometry
Polygon overlap areas for conservative regridding, written with the standard-library geometry templates.
- Removed operators
The operators esm 2.0.0 removed, the error a document using one gets, and the standard-library template that replaces each.