Use this file to discover all available pages before exploring further.
The Cantor Interpreter ships seven built-in functions that are always in scope — no import statement required. They cover the essential building blocks of computation over natural numbers: constants, identity, arithmetic, and pair projection. All seven are defined in src/cantor_stdlib.py and registered in the BUILTIN_FUNCTIONS dictionary, which the interpreter consults when it resolves a name in a Cantor program.
Every Cantor function takes exactly one natural number as its argument. Functions that logically operate on two values — such as add or mul — receive a single Cantor-encoded pair <x, y> instead of two separate arguments. You construct that pair in a program using the pair combinator, which calls π(f(n), g(n)) and passes the result to the next function. See the Cantor Pairing page for how the encoding works.
The five arithmetic and projection functions — add, mul, diff, fst, and snd — each expect their input to be a Cantor-encoded pair. Passing a raw integer that was not produced by π will still run without error, but the result will be the arithmetic on whatever unpi happens to decompose that integer into. Always use pair (or the pi helper in tests) to build the input.
def diff(z: int) -> int: """Return max(0, x - y) from an encoded pair.""" x, y = unpi(z) return max(0, x - y)
diff decodes its argument as a Cantor pair <x, y> and returns truncated subtraction: max(0, x − y). The result is clamped to zero when y > x, preserving the invariant that all values stay within the natural numbers.
Unlike regular integer subtraction, diffnever returns a negative number. Any subtraction that would go below zero yields 0 instead. This is sometimes called monus or proper subtraction in the theory of natural numbers.
Built-in names can appear directly in define bodies alongside the combinators pair, comp, compair, mu, and primrec:
# Compute x + y, then add 1define plus_one comp add pair id k_1main plus_one
The body comp add (pair id k_1) first evaluates pair id k_1 on the input n, producing π(id(n), k_1(n)) = π(n, 1), then passes that encoded pair to add, which returns n + 1. More involved combinations let you compose any n-ary computation out of these seven primitives together with the structural combinators.
Cantor Pairing
Understand how π encodes two naturals into one and how the CLI uses it for multi-value input.
Language Reference
Combinators (pair, comp, compair, mu, primrec) and how to wire built-ins together.