Chapters

Catena reference

This is the catalog chapter of the Catena sub-series: the complete list of the words the language reserves, the types and formats it understands, every built-in function the calculator can evaluate, the engine settings you can pin to a sequence, and a one-page grammar cheat-sheet. Use it as a lookup, not a tutorial. If you are learning the language, start with the commands and standard library and types and formatting chapters and come back here when you need to confirm a name, an argument count, or an alias.

Two conventions run through the whole chapter:

  • Keywords are case-insensitive. IF, if, and If are the same word. The tables print them in upper case because that is how the app displays them, but you may type any case.
  • Type and format names are case-sensitive. Num, Date, and Money must be written exactly as shown, with their leading capital. This is the one place where case matters outside your own variable names.

Keywords and reserved words

These words are built into the language and cannot be used as variable names. They fall into four groups.

Control flow and structure. The words that build blocks, loops, decisions, and sequences.

Keyword Role Common alias
IF Begin a one-time decision.
OTHERWISE The else branch of an IF. ELSE
OTHERWISE IF An else-if branch. ELSE IF
UNLESS A negated one-time decision ("do this unless…").
END Close a block (IF, REPEAT, FOR EACH, WHEN, SEQUENCE).
REPEAT Begin a loop.
TIMES Counted loop: REPEAT n TIMES.
WITH FROM TO Counter loop: REPEAT WITH i FROM a TO b.
WHILE Loop while a condition holds: REPEAT WHILE ….
UNTIL Loop until a condition holds: REPEAT UNTIL ….
FOR EACH … IN Iterate over the items of a Bag.
CHECKPOINT Mark a named point to return to. CP
JUMP TO Jump to a checkpoint in the same sequence. GOTO
SEQUENCE Define a sequence (a reusable program). SEQ
CALL Run a sequence and capture its result.
RETURN Return a value or value bag from a sequence.
WHEN Begin a reactive rule (must be qualified).
ALWAYS Make a WHEN rule recompute eagerly.
AS RULE Register a WHEN rule for deferred CHECK.
CHECK Evaluate a deferred rule (or all settled rules).
AS Convert or format a value to a type or format.
ESET Set an engine setting for the current scope.

Named operators. Word-form operators used inside expressions and queries.

Keyword Meaning
AND OR NOT Boolean operators.
ALL … IN … WHERE … Query a Bag; ALL and WHERE mark the filter form.

Literals and registers. Built-in values.

Keyword Meaning
TRUE FALSE The two Boolean values.
BAG The empty Bag (same as []).
ANS The answer register; bare Ans is the most recent result.

Command verbs. Words that begin a standard-library statement. Each is covered in commands and standard library; brackets around their arguments are optional.

Keyword Purpose Common alias
PROMPT Ask the user for input. ASK
DISPLAY Show a value in the main output.
PRINT Write a line to the paper tape.
OUT Show and record in one line.
STO Store the last result into a variable.
RCL Recall a stored variable.
CURRENCY Convert an amount between currencies (needs a live rate).
API Call a host-provided data or conversion service.

Types and formats

Catena has a small, disjoint set of types and a small set of display formats. Both are used with the AS operator — expression AS Type enforces or converts a type, expression AS Format presents a value a particular way (see types and formatting). Remember that these names are case-sensitive.

Types.

Type What it holds
Num A number, exact by default.
Real A number treated as an inexact real (decimal).
Int A whole number.
Bool TRUE or FALSE.
Date A calendar date.
Duration A length of time (built from duration units, below).
Text A run of text (for labels and prompts, not string processing).
Bag The one container type: an ordered, heterogeneous collection.

Formats. These affect presentation only; they never change the stored value.

Format Presents a value as
DateLong A long date ("14 June 2026").
DateShort A short date.
DateISO An ISO date (2026-06-14).
Time A time of day.
DateTime A date and time together.
Money A currency amount.
Percent A percentage.

Currency glyphs. A leading glyph marks a money literal: $, , £, ¥. A trailing ISO 4217 code (for example 100 USD) is also recognised.

Duration units. These words after a number make a Duration literal, in both singular and plural: day/days, hour/hours, minute/minutes, second/seconds, week/weeks, month/months, year/years, millisecond/milliseconds. Date arithmetic uses explicit durations, so date + 30 days is well formed while date + 30 is not.


Function reference

Every built-in mathematical function is listed below, grouped by family. Read the tables this way:

  • Name is the canonical form — always lower case (for example sin, sqrt, gcd). This is the primary spelling.
  • Alias(es) are additional spellings that call the same function. Upper-case aliases (SIN-style SQRT, LN, ABS) mirror the classic calculator keys; other aliases mirror Casio-style names (P, C, HCF, Ran#). Any listed alias is interchangeable with the canonical name.
  • Args is the argument count. A single number is a fixed count; 1..2 means one required plus one optional; 1..n means one or more (variadic); 0..1 means the argument is optional.

Function names are case-sensitive, so type the exact spelling shown. Where a family maps to dedicated keypad keys (the trig and log families in School mode), the School calculator and trigonometry chapters show the keys; here we list the typed names that work in every mode.

Elementary and rounding

Name Alias(es) Args What it does
sqrt SQRT 1 Square root.
cbrt 1 Cube root.
nthroot 2 The nth root of a value (the value and the root index).
square 1 The value squared.
cube 1 The value cubed.
reciprocal 1 One divided by the value.
pow 2 The first argument raised to the second.
abs ABS 1 Absolute value (magnitude, sign removed).
sign SGN 1 The sign of the value: -1, 0, or 1.
floor FLOOR 1 Round down to the nearest integer.
ceil CEIL 1 Round up to the nearest integer.
round ROUND 1..2 Round to the nearest integer; an optional second argument sets the number of decimal places.
rndfix 2 Round a value to a fixed number of decimal places.
trunc 1 Discard the fractional part (round toward zero).
frac 1 The fractional part only.
factorial 1 Factorial, n!.
doublefactorial 1 Double factorial, n!!.
clamp 3 Restrict a value to lie between a low and a high bound.
lerp 3 Linear interpolation between two values by a fraction.
min 1..n The smallest of its arguments.
max 1..n The largest of its arguments.

Trigonometry

All trigonometric functions read the active angle mode (DEG / RAD / GRA); the hyperbolic family does not. See trigonometry for the full treatment.

Name Alias(es) Args What it does
sin 1 Sine.
cos 1 Cosine.
tan 1 Tangent.
cot 1 Cotangent (cos/sin).
sec 1 Secant (1/cos).
csc cosec 1 Cosecant (1/sin).
asin 1 Inverse sine; returns an angle in the active mode.
acos 1 Inverse cosine.
atan 1 Inverse tangent.
atan2 2 Two-argument arctangent, atan2(y, x); recovers the full angle of a point.
hypot 2 The hypotenuse length √(x² + y²).
sinh 1 Hyperbolic sine.
cosh 1 Hyperbolic cosine.
tanh 1 Hyperbolic tangent.
asinh 1 Inverse hyperbolic sine.
acosh 1 Inverse hyperbolic cosine.
atanh 1 Inverse hyperbolic tangent.

Logarithms and exponentials

Name Alias(es) Args What it does
log LOG 1 Base-ten logarithm.
ln LN 1 Natural logarithm (base e).
log_a logBase 2 Logarithm of a value to a given base.
exp EXP 1 e raised to the value.
exp10 1 Ten raised to the value.
exp2 1 Two raised to the value.

Angle conversions and coordinates

These always perform the named conversion regardless of the active angle mode.

Name Args What it does
deg2rad 1 Degrees to radians.
rad2deg 1 Radians to degrees.
deg2gra 1 Degrees to gradians.
gra2deg 1 Gradians to degrees.
rad2gra 1 Radians to gradians.
gra2rad 1 Gradians to radians.
dms2deg 3 Degrees, minutes, seconds to decimal degrees.
deg2dms 1 Decimal degrees to degrees-minutes-seconds.
pol 2 Rectangular (x, y) to polar (distance and angle).
rec 2 Polar (r, θ) to rectangular (x, y).

Number theory

Name Alias(es) Args What it does
nPr P 2 Number of permutations of r items from n.
nCr C 2 Number of combinations of r items from n.
gcd HCF 2 Greatest common divisor (highest common factor).
lcm 2 Lowest common multiple.
mod Rmdr 2 Remainder after division.
mod_exp 3 Modular exponentiation, base^exp mod m.
quotrem 2 The quotient and remainder together.
primefactor 1 Prime factorisation of an integer.
isimp ISimp 1..2 Simplify a fraction to lowest terms; an optional second argument simplifies by a chosen factor.
recurring_decimal_detect 1 Detect a repeating (recurring) decimal expansion.

Complex numbers

Name Args What it does
re 1 Real part.
im 1 Imaginary part.
conj 1 Complex conjugate.
arg 1 Argument (angle) of a complex number.
to_polar 1 Convert to polar form.
to_rect 1 Convert to rectangular form.

The magnitude of a complex number shares one name with the vector norm — see mag in the next table.

Vectors

Vectors are held as Bags. See types and formatting for how a Bag stands in for a vector.

Name Alias(es) Args What it does
dot DotP 2 Dot (scalar) product.
cross CrossP 2 Cross product of two 3-D vectors.
cross_2d 2 The scalar 2-D cross product.
mag norm, Norm 1 Euclidean length of a vector, or the modulus of a complex number.
unit UnitV 1 The unit vector in the same direction.
angle_between Angle 2 The angle between two vectors.
project 2 The projection of one vector onto another.
triple_scalar 3 The scalar triple product.
triple_vector 3 The vector triple product.

Random

Name Alias(es) Args What it does
random Ran#, RAND 0..1 A uniform random number in [0, 1).
randint RanInt# 2..3 A random integer between two bounds; an optional final argument requests several at once.
randnorm RanNorm# 2..3 A normally distributed value from a mean and standard deviation; optional count.
randbin RanBin# 2..3 A binomially distributed value from a trial count and probability; optional count.
randlist RanList# 1..2 A list of random values.
randsamp RanSamp# 2..3 A random sample drawn from a Bag.
setseed 1..2 Fix the random seed so a run reproduces exactly.

Engine settings (ESET)

ESET pins a computation setting to a sequence so it travels with the file — an accountant handing a sequence to staff can guarantee how it rounds and converts. The form is:

ESET <SETTING> <VALUE>

A setting applies to the sequence it appears in and to every sequence called from it; a callee may override it for its own scope, and the override reverts when control returns. Defaults come from the app-wide options.

Setting Values (default first) Effect
ROUNDING HALFUP, BANK, DOWN, UP, HALFEVEN Rounding mode for narrowing and money.
DATEINT UNIX, WINDOWS, NONE How Date AS Int is computed (NONE forbids it).
STRONGTYPE OFF, ON Gradual typing versus enforced declarations.
OFFLINE OFF, AUTO, ON Whether to attempt host API calls or prompt instead.
ANSDEPTH engine default, any n ≥ 1 How many recent answers Ans remembers.
MAXLOOP engine default Loop-iteration cap (a runaway loop fails safely).
MAXDEPTH engine default Recursion-depth cap.
LOCALE engine default The display language for keywords and formatting.
ESET ROUNDING BANK        # banker's rounding for this sequence and its callees
ESET MAXDEPTH 256         # cap recursion depth

An unknown setting is a validation error with a suggestion.


Grammar cheat-sheet

A user-readable summary of the language shape. This is not the formal grammar; it is the set of statement forms you actually write. Synonyms and localized keywords normalize to the canonical forms shown here.

A sequence is a list of lines. Each line is one statement, optionally followed by a # comment. Blank lines are fine. A line with a bare expression shows its result and pushes it onto Ans, exactly like pressing =.

Assignment. Compute on the left, store on the right:

price * 1.23 -> total
price * 1.23 -> total AS Money      # store and format/convert on the way in

-> is canonical. total <- price * 1.23 and set total = price * 1.23 are accepted aliases. = is never assignment — it is mathematical equality in a comparison. Store targets may be a plain name or a Bag slot: value -> results[1] (by position, 1-based) or value -> results["grand_total"] (by name).

Expressions. Precedence from tightest to loosest: AS (convert/format), then ^ (power, right-associative), then × ÷ (also * /), then + -, then comparisons (=, <>, <, >, <=, >=), then NOT, then AND, then OR. Grouping uses parentheses ( ) and is never optional. Square brackets [ ] build a Bag literal or index into one — never grouping. Multiplication is only ever inferred at a parenthesis boundary ((2)(3) is 2 × 3); 2x is never split.

Decisions.

IF condition
    …
OTHERWISE IF other
    …
OTHERWISE
    …
END

UNLESS condition
    …
END

Loops. All four repetition forms open with REPEAT and close with END; FOR EACH iterates a Bag:

REPEAT 5 TIMES              …   END
REPEAT WITH i FROM 1 TO 10  …   END
REPEAT WHILE condition      …   END
REPEAT UNTIL condition      …   END
FOR EACH item IN prices     …   END

Checkpoints. For input-validation re-prompts within a sequence:

CHECKPOINT retry
…
JUMP TO retry

Reactive rules. WHEN must always be qualified. ALWAYS recomputes eagerly; AS RULE name waits for a CHECK:

WHEN amount > 5000 ALWAYS
    amount * 1.05 -> amount
END

WHEN amount > 5000 AS RULE surcharge
    amount * 1.05 -> amount
END
CHECK surcharge            # run that rule now; bare CHECK runs all settled rules

Sequences. Define with SEQUENCE … END, call with CALL, hand back with RETURN:

SEQUENCE vatTotal(prices)
    SUM(prices) * 1.23 -> total
    RETURN total
END

CALL vatTotal(prices) -> result

Parameters may carry an optional AS Type. A sequence returns a single value or a value bag; with no RETURN it returns an empty bag. The textual SEQUENCE … END wrapper is optional because the name and parameters also live in the file's metadata.

Commands. Command verbs (DISPLAY, PRINT, PROMPT, CURRENCY, API, …) take their arguments with or without brackets, and may end in -> target:

PROMPT "Net price?" -> price
CURRENCY ("USD", price, "EUR") -> itemPrice
OUT itemPrice

Four short, complete sequences that draw the earlier pieces together.

1 — Quadratic roots (decision, sqrt, RETURN). Given a, b, c, return the two real roots or a message when there are none.

SEQUENCE quadratic(a, b, c)
    b * b - 4 * a * c -> disc
    IF disc < 0
        RETURN "no real roots"
    END
    (-b + sqrt(disc)) / (2 * a) -> root1
    (-b - sqrt(disc)) / (2 * a) -> root2
    RETURN [root1, root2]
END

Calling CALL quadratic(1, -5, 6) -> roots returns the Bag [3, 2].

2 — VAT over a shopping bag (aggregate, element-wise, value bag). Take a bag of net prices, return the per-item gross prices and the grand total.

SEQUENCE vat(prices)
    prices * 1.23 -> gross          # element-wise over the whole bag
    SUM(gross) -> total
    total -> gross["grand_total"]   # augment the bag with a named item
    RETURN gross
END

CALL vat([150, 200, 99.50]) -> invoice returns the grossed-up items plus invoice["grand_total"].

3 — Compound growth (counted loop, Ans, store). Grow a balance at 5% for a fixed number of years.

1000 -> balance
REPEAT WITH year FROM 1 TO 10
    balance * 1.05 -> balance
END
OUT balance                          # show the final balance and record it on the tape

OUT prints the last value to the paper tape and shows it, so the result is both visible and kept.

4 — Validated input (checkpoint, prompt, UNLESS). Re-ask until the user gives a positive price.

CHECKPOINT retry
PROMPT "Net price?" AS Num -> price
UNLESS price > 0
    JUMP TO retry
END
price * 1.23 -> total AS Money
OUT total

PROMPT … AS Num validates the entry as a number and re-prompts on bad input; UNLESS price > 0 sends control back to the checkpoint until the value is positive.