Docs / Shapes / Expression

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.

Expression shape on the board with equations visible

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.

Use multiple small Expression shapes grouped by theme (parameters, equations, derived quantities) to keep your model organized and readable.

Reading an Expression

When a shape holds two or more equations, they are shown as one block sharing a single equals-sign column: the left-hand sides are right-aligned against the equals sign, the right-hand sides are left-aligned after it, and the block is centred in the card. Only the primary equals sign of each line is aligned — an equals sign inside a condition, a fraction or brackets is left where it is. A shape holding a single equation is shown as before. Alignment is presentation only: the model still stores one plain line per equation.

Three expression shapes showing aligned equations with semantic colours

Every part of an expression is coloured by what it means:

A row the model cannot read is said so on the card itself, not hidden behind a hover. The row is written in red and carries a band across it, the card is bordered in red so it can be picked out from across the board, and a panel at the foot of the card says why, in the language the rest of the editor is written in. Where the row is missing something — a value, a bracket — a dotted slot is drawn in the row at the place it belongs, the way an unfilled slot of a template is drawn; where the missing piece is inside a fraction or a root, that fraction or root is underlined instead, since the place cannot be named more closely than the symbol holding it. A symbol that cannot stand where it was written is underlined where it stands. The panel opens whenever you reach for the card — the pointer over it, the card selected, or the caret in it — and carries the readings alone, with no heading over them and no row named in front of each one: pointing at a reading lights the row it belongs to, and clicking it puts the caret there. Rows are checked as you write rather than only when you step away, except for the row the caret is standing in: a row is half-written for as long as it is being written, so it is left alone until you leave it.

The colours name a family, not a fixed shade. Each one is read from the --math-* theme tokens and then adjusted to the card it is painted on: the hue stays, the lightness moves until the text stands clear of the background, and the colour is deepened at the same time. A card painted white gets deep, saturated colours; a card painted black or dark grey gets bright ones; changing the card colour repaints the expression at once. Every colour keeps at least the contrast the accessibility guidelines ask for, and the operators are held one step quieter than the variables. The caret and the selection highlight follow the same rule, and so does the text colour of the card, which is what draws the brackets, the fraction bars and the root signs: it is left exactly as you chose it and only lifted when the card would otherwise swallow it. None of this reaches the model: an expression saved or copied out never carries a colour.

Toolbar

Expression shape toolbar showing color picker, shortcuts picker, and delete button

The toolbar appears when you select an Expression shape. It provides:

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 multiplication2x2xCoefficient 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
Factorialx!!Postfix factorial for non-negative integers
Square root\sqrt{x}\sqrtSquare root
Negation-x-Unary negation

Factorial note: Factorial uses postfix notation (n!) and is intended for non-negative integer values.

Comparison Operators

Used in conditional (\begin{cases}) branches:

Operator LaTeX Meaning
==Equal to
>>Greater than
<<Less than
\ge or \geqGreater than or equal
\le or \leqLess than or equal
\neqNot 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
TrigonometricSine\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 TrigArc sine\arcsin\left(x\right)1
Arc cosine\arccos\left(x\right)1
Arc tangent\arctan\left(x\right)1
HyperbolicHyperbolic sine\sinh\left(x\right)1
Hyperbolic cosine\cosh\left(x\right)1
Hyperbolic tangent\tanh\left(x\right)1
LogarithmicNatural log\ln\left(x\right)1
Logarithm base 10\log\left(x\right)1
Two-argumentMaximum\max\left(a, b\right)2
Minimum\min\left(a, b\right)2
Modulo\mod\left(a, b\right)2
UtilitySignsign\left(x\right)1 — returns -1, 0, or 1
Randomrnd\left(x\right)1 — random float in [0, x]
Integer randomirnd\left(x\right)1 — random integer in [0, x]
Integer partint\left(x\right)1 — truncate to integer
Roundround\left(x\right)1 — round to nearest integer
OtherDeterminant\det\left(x\right)1
All function calls use \left( and \right) delimiters. Bare parentheses are not valid in function calls. The math field inserts these automatically.

Constants

NameLaTeXValue
Pi\pi3.14159…
Euler's numbere or \E2.71828…
g is not a built-in constant. Define it as a parameter: g = 9.8.

Special Syntax

Finite Difference (Δ)

SyntaxMeaning
\Delta xx(current) − x(previous). For the independent variable: the step size.
\Delta\left(expr\right)Finite difference applied to a sub-expression.

Subscripts (Step References)

SyntaxMeaning
x_{n-1}Value of x from the previous iteration
x_{n}Current iteration (LHS of recurrence)
x_0Initial value of x (bare digit, no braces)
x_{0}Initial value (braces form)

Indexed Terms (Element References)

A term can stand for many values at once — the oscillators of a wave, say — by being defined over an element index instead of over time. The index is bound by the assignment, so it never becomes a variable of the model:

y\left[i\right] = A\cdot\cos\left(k\cdot i - \omega\cdot t\right)
SyntaxMeaning
y\left[i\right] = …Defines y over element indices; the body is evaluated once per element asked for
y\left[3\right]Element 3 of y
y\left[i\right]Element i, where i is any expression
s = y + zSuperposition: s is indexed too, added element by element

This is a third index space beside the two above: y_3 reads y at iteration 3 and y\left(3\right) reads it at independent value 3, while only the square brackets read an element. An indexed term holds no single value, so it is read for its elements rather than shown as a number.

An Oscilloscope object reads them: name the indexed terms in its Waves and each is drawn across its graticule, one trace per row. Two travelling waves added this way — one with -\omega\cdot t, one with +\omega\cdot t — give a standing wave with fixed nodes. A Piano publishes one: the chord it is holding, one element per sample.

A Mechanical wave object works from a plain term instead. Name one the model works out for itself — y=A\cdot\sin\left(\omega\cdot t\right) — in its Wave row and the chain repeats what that term has been doing: every iteration hands the first oscillator the value the term has just taken and moves the one before it along, so the chain holds the last values of the run, oldest at the far end, and the motion travels down it as the run goes. It holds one value per oscillator, so Samples is also how far back it reaches. Write a name the model does not define and the object goes the other way: it works its wave out from its amplitude, frequency, speed and phase and hands the model what its reference oscillator is doing under that name. The name becomes a term of the model — it is in every list of terms, the way a name the model assigns is — so it can be graphed against time, read in a definition (z=2\cdot y) and added to another object's reading (s=forward+back). A name the model does define is the model's own — an assignment, over time or over element indices, is read rather than written over — and an object taken off the board takes its term with it.

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:

ActionShortcutResult
Open template palette . (macOS) · Ctrl+. (Windows/Linux) Choose a mathematical template from the compact palette
Power (superscript) ^ x^2
Subscript (index) _ x_{t-1}
Unary negation ~ -x
Factorial ! n!
Square root # \sqrt{x}
Delta % \Delta x
Absolute value | \left|x\right|
Not equal <> x \ne y
Greater or equal >= x \ge 1
Less or equal <= x \le 1
Condition (piecewise) \ \begin{cases} 1 & t=0 \\ y & t\ge2 \end{cases}
Or v (macOS) · Alt+v (Windows) x>0 \lor x<5
And ^ (macOS) · Alt+^ (Windows) x>0 \land x<5
Differential template / (macOS) · Alt+/ (Windows) \frac{dx}{dt}
Floor _ (macOS) · Alt+_ (Windows) \lfloor x \rfloor
Ceil _ (macOS only) \lceil x \rceil
Fraction / (macOS) · Ctrl+/ (Windows) \frac{a}{b}
Multiplication dot * a \cdot b
New line (new statement) Enter
Navigate out / next placeholder Tab

Shortcuts Picker

Expression shape selected with toolbar visible

While editing, press . on macOS or Ctrl+. on Windows/Linux to open the shortcuts palette. You can also open it with the toolbar button.

Integral Notation

You can enter integral expressions with LaTeX notation such as \int_{a}^{b} f\left(x\right)\,\mathrm{d}x. For integer-part behavior, use the utility function int\left(x\right).

Properties Panel

Expression shape properties panel

When an Expression shape is selected, the properties panel shows:

PropertyDescription
Independent variableThe variable of iteration (default: t)
StepThe increment per iteration (Δt)
Start / EndRange of the independent variable
Initial valuesStarting values for differential equations and recurrences
CasesMultiple 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}