Expression Schema
The canonical JSON Schema for the Modellus expression language — the LaTeX-based mathematical notation used inside Expression shapes. Covers statement types, operator precedence, built-in functions, and AST node definitions.
View the full Expression Schema JSON — JSON Schema (Draft-07), 1331 lines.
Overview
The expression field of each ExpressionShape stores a \displaylines{} LaTeX block. Lines are separated by \\. Each line is parsed as one statement by the LatexMath grammar.
Statement Types
| Kind | Pattern | Term Type Produced |
|---|---|---|
differential | \frac{dx}{dt} = expr | DIFFERENTIAL — requires initial value |
function | name = expr | PARAMETER (constant RHS) or FUNCTION (depends on other terms) |
functionSubscript | x_{n} = f(x_{n-1}) | RECURRENCE — discrete-time iteration |
functionSubscriptDigit | x_0 = value | PARAMETER — initial/reference value |
functionIndependent | f(t) = expr | FUNCTION — explicit argument form |
conditional | name = \begin{cases}...\end{cases} | FUNCTION — piecewise definition (≥ 2 rows) |
display | expr (no assignment) | None — visual display only |
Expression Nodes (AST)
The right-hand side of any statement is a MathExpr — a tree of these node types:
| Node | Description | Example LaTeX |
|---|---|---|
| BinaryOp | Two operands with operator (+, -, ·, /) | a + b |
| UnaryMinus | Negation prefix | -x |
| Power | Exponentiation | x^{2} |
| Fraction | Division as \frac{}{} | \frac{a}{b} |
| Sqrt | Square root | \sqrt{x} |
| FunctionCall | Built-in function application | \sin\left(x\right) |
| Comparison | Relational operator | x > 0 |
| Logical | \lor or \land | a \lor b |
| TermReference | Reference to a named term | v, \omega |
| NumberLiteral | Numeric constant | 9.8 |
| Constant | \pi or e | \pi |
| Delta | Finite difference operator | \Delta x |
| SubscriptRef | Subscript term access | x_{n-1} |
| Absolute | Absolute value bars | |x| |
Built-in Functions
| Category | Functions |
|---|---|
| Trigonometric | \sin, \cos, \tan, \cot, \sec, \csc |
| Inverse Trig | \arcsin, \arccos, \arctan |
| Hyperbolic | \sinh, \cosh, \tanh |
| Logarithmic | \ln, \log |
| Two-argument | \max(a,b), \min(a,b), \mod(a,b) |
| Utility | sign(x), rnd(x), irnd(x), int(x), round(x) |
| Other | \det(x), \sqrt{x} |
Operators & Precedence
| Precedence | Operators | Associativity |
|---|---|---|
| 1 (lowest) | \lor, \land | Left |
| 2 | =, >, <, \ge, \le, \neq | Left |
| 3 | +, - | Left |
| 4 | \cdot, /, implicit multiplication | Left |
| 5 (highest) | ^{}, \sqrt{} | Right |
LaTeX Templates
The schema includes a latexTemplates section providing ready-to-use LaTeX strings for common patterns that agents can emit directly into expression fields.
Name Tokens
Term names follow two patterns:
- ID — alphanumeric identifiers:
x,v0,mass,kB - SPECIAL — Greek letters and symbols:
\omega,\alpha,\beta,\theta,\lambda