Arithmetic is the natural starting point for exploring Cantor programs. Because every value is a natural number, operations like addition, subtraction (monus), and division emerge entirely from combining built-in functions — no special syntax required. The examples below progress from a one-liner that delegates to a built-in, through a hand-rolled predecessor function, all the way to division and modulo implemented via the mu (minimization) operator.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/felipenugo/cantor-interpreter/llms.txt
Use this file to discover all available pages before exploring further.
Addition
The simplest arithmetic program in Cantor is addition. The built-inadd already accepts a Cantor-encoded pair <x, y> and returns x + y, so the entire program is a single main declaration:
<x, y>, and passes the pair to add.
Predecessor (anterior)
The predecessor function returnsmax(0, x - 1) — it clamps at zero because there are no negative natural numbers. Rather than being a built-in, it is constructed from diff (monus: max(0, a - b)) and the pairing combinators.
aparella_amb_1 — pair x with 1
pair id k_1 takes input x and produces the pair <x, 1>. id passes x through unchanged; k_1 is the constant-1 function.Division (mu-based)
Integer division is implemented using the mu operator (unbounded minimisation).mu f searches for the smallest natural number q such that f(<input, q>) ≠ 0. For division, the predicate test_quotient returns non-zero when y * (q + 1) > x, meaning q is the largest quotient whose next step would overshoot.
Encode the inputs
The program receives
<x, y> where x is the dividend and y is the divisor. mu appends its search variable q to form <<x, y>, q>.Extract components
vx extracts x via fst(fst(...)), vy extracts y via snd(fst(...)), and q1 computes q + 1 via add(snd(...), 1).Build the predicate
yq1 computes y * (q + 1). test_quotient then calls gt(yq1, vx), returning 1 when y * (q + 1) > x.The
div.cantor program requires extended mode (declared with the extended keyword) because it uses compair and imports relacionals. Run it from the project root where the library files are accessible.Modulo
The modulo program builds directly ondiv. Once the quotient q = ⌊x / y⌋ is known, the remainder is x - y * q.
x and y project each component of the input pair. q delegates to the imported div to find the quotient, yq multiplies y by q, and finally mod applies diff to compute x - y * q (clamped at zero, but the subtraction is always exact for a valid modulus).
Even Parity
even chains mod with an equality check to determine whether a number is divisible by 2.
k_0 is synthesised as diff(1, 1) = 0 and k_2 as add(1, 1) = 2. pair_x_2 pairs the input with the constant 2, mod2 feeds that pair to mod, and even compares the result to k_0 with eq — returning 1 if x mod 2 = 0, otherwise 0.