Expression Shape
The Expression shape is the mathematical heart of every Modellus model. It is where you define equations, parameters, differential equations, recurrences, and conditional logic that drive the simulation.
Overview
An Expression shape contains one or more mathematical statements written in LaTeX-like syntax using a MathLive math field. Each statement occupies one line. All Expression shapes in a model share a single calculator system — term names must be globally unique across shapes.
Toolbar
The toolbar appears when you select an Expression shape. It provides:
- Color picker — Change the shape accent color
- Shortcuts picker — Quick insertion of common mathematical templates
- Delete — Remove the shape from the board
Statement Types
Each line in an Expression shape is parsed as one of these statement types:
| Type | Syntax | Example | Description |
|---|---|---|---|
| Parameter | name = value |
g = 9.8 |
A constant value. No dependency on other terms or the independent variable. |
| Function | name = expression |
E = ½·m·v² |
A computed value depending on other terms or the independent variable. |
| Differential | dx/dt = expression |
dx/dt = v |
First-order ODE. Requires an initial value in shape properties. |
| Recurrence | x_{n} = expression |
x_{n} = x_{n-1} + v·Δt |
Iterative step definition. Subscript determines step offset. |
| Conditional | name = \begin{cases}...\end{cases} |
v = { 0 & t=0 \\ a·t & otherwise } |
Piecewise definition. At least two branches required. |
| Function with argument | f(t) = expression |
h(t) = v₀·t - ½·g·t² |
Explicit argument notation (cosmetic; behavior same as Function). |
| Display | expression |
F = ma |
Visual label only. Not computed by the calculator. |
Arithmetic Operators
| Operator | LaTeX | Keystroke | Description |
|---|---|---|---|
| Addition | + | + | Sum of two expressions |
| Subtraction | - | - | Difference of two expressions |
| Multiplication | \cdot | * | Explicit multiplication (· symbol) |
| Implicit multiplication | 2x | 2x | Coefficient followed by name or parenthesis |
| Inline division | / | / | a/b inline notation |
| Fraction | \frac{a}{b} | / (in numerator position) | Display-quality vertical fraction |
| Power | ^{n} | ^ | Exponentiation |
| Square root | \sqrt{x} | \sqrt | Square root |
| Negation | -x | - | Unary negation |
Comparison Operators
Used in conditional (\begin{cases}) branches:
| Operator | LaTeX | Meaning |
|---|---|---|
| = | = | Equal to |
| > | > | Greater than |
| < | < | Less than |
| ≥ | \ge or \geq | Greater than or equal |
| ≤ | \le or \leq | Less than or equal |
| ≠ | \neq | Not equal to |
Conditions can be chained (e.g., 0 < x < 1) or combined with \lor (OR) and \land (AND). The \text{otherwise} keyword acts as an else branch.
Built-in Functions
| Category | Function | LaTeX | Arguments |
|---|---|---|---|
| Trigonometric | Sine | \sin\left(x\right) | 1 |
| Cosine | \cos\left(x\right) | 1 | |
| Tangent | \tan\left(x\right) | 1 | |
| Cotangent | \cot\left(x\right) | 1 | |
| Secant | \sec\left(x\right) | 1 | |
| Cosecant | \csc\left(x\right) | 1 | |
| Inverse Trig | Arc sine | \arcsin\left(x\right) | 1 |
| Arc cosine | \arccos\left(x\right) | 1 | |
| Arc tangent | \arctan\left(x\right) | 1 | |
| Hyperbolic | Hyperbolic sine | \sinh\left(x\right) | 1 |
| Hyperbolic cosine | \cosh\left(x\right) | 1 | |
| Hyperbolic tangent | \tanh\left(x\right) | 1 | |
| Logarithmic | Natural log | \ln\left(x\right) | 1 |
| Logarithm base 10 | \log\left(x\right) | 1 | |
| Two-argument | Maximum | \max\left(a, b\right) | 2 |
| Minimum | \min\left(a, b\right) | 2 | |
| Modulo | \mod\left(a, b\right) | 2 | |
| Utility | Sign | sign\left(x\right) | 1 — returns -1, 0, or 1 |
| Random | rnd\left(x\right) | 1 — random float in [0, x] | |
| Integer random | irnd\left(x\right) | 1 — random integer in [0, x] | |
| Integer part | int\left(x\right) | 1 — truncate to integer | |
| Round | round\left(x\right) | 1 — round to nearest integer | |
| Other | Determinant | \det\left(x\right) | 1 |
\left( and \right) delimiters. Bare parentheses are not valid in function calls. The math field inserts these automatically.
Constants
| Name | LaTeX | Value |
|---|---|---|
| Pi | \pi | 3.14159… |
| Euler's number | e or \E | 2.71828… |
g is not a built-in constant. Define it as a parameter: g = 9.8.
Special Syntax
Finite Difference (Δ)
| Syntax | Meaning |
|---|---|
\Delta x | x(current) − x(previous). For the independent variable: the step size. |
\Delta\left(expr\right) | Finite difference applied to a sub-expression. |
Subscripts (Step References)
| Syntax | Meaning |
|---|---|
x_{n-1} | Value of x from the previous iteration |
x_{n} | Current iteration (LHS of recurrence) |
x_0 | Initial value of x (bare digit, no braces) |
x_{0} | Initial value (braces form) |
Units Annotation
Append display-only units after any statement:
v = 10 \quad\textcolor{gray}{\mathrm{m/s}}
Units are cosmetic — the engine does not validate or convert them.
Dotted Names (Child References)
Reference terms from child shapes inside a Referential: body.x, particle.velocity.
Keyboard Shortcuts
The MathLive math field supports these keyboard shortcuts for fast input:
| Action | macOS | Windows |
|---|---|---|
| Fraction | ⌘ + / | Ctrl + / |
| Superscript (power) | ^ | ^ |
| Subscript | _ | _ |
| Square root | ⌘ + Shift + R | Ctrl + Shift + R |
| Greek letter | Type \ + name (e.g., \alpha) | Same |
| Multiplication dot | * | * |
| Greater or equal | Type \ge | Same |
| Less or equal | Type \le | Same |
| Not equal | Type \neq | Same |
| Delta | Type \Delta | Same |
| Pi | Type \pi | Same |
| New line (new statement) | Enter | Enter |
| Navigate out of fraction | Tab | Tab |
| Navigate into next placeholder | Tab | Tab |
Shortcuts Picker
Click the button in the toolbar to open the shortcuts picker. It provides pre-built templates for common expressions including:
- Differential equations (dx/dt = ...)
- Recurrences (x_n = x_{n-1} + ...)
- Piecewise functions
- Common physics formulas
- Trigonometric identities
Properties Panel
When an Expression shape is selected, the properties panel shows:
| Property | Description |
|---|---|
| Independent variable | The variable of iteration (default: t) |
| Step | The increment per iteration (Δt) |
| Start / End | Range of the independent variable |
| Initial values | Starting values for differential equations and recurrences |
| Cases | Multiple sets of initial values for parameter studies |
Examples
Simple Kinematics
g = 9.8
v₀ = 20
θ = 45
vx = v₀·\cos\left(θ\right)
vy = v₀·\sin\left(θ\right) - g·t
\frac{dx}{dt} = vx
\frac{dy}{dt} = vy
Population Growth (Recurrence)
r = 0.05
P_{n} = P_{n-1}·\left(1 + r\right)
Piecewise Velocity
v = \begin{cases} 0 & t = 0 \\ a·t & 0 < t < 5 \\ a·5 & \text{otherwise} \end{cases}