Cantor has no dedicated boolean type — booleans are simply natural numbers, where 0 means false and any non-zero value means true. This convention lets boolean logic be expressed with the same arithmetic combinators used everywhere else in the language. The programs below show how AND, OR, and NOT emerge from multiplication, sign detection, and monus, and how those primitives are combined further into equality and ordered comparisons.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.
AND
Boolean AND is multiplication. For the boolean encoding0 / non-zero, a * b = 0 if and only if at least one operand is 0, and a * b ≠ 0 when both are non-zero. The program is therefore a one-liner:
<a, b>, and mul computes a * b directly.
Inputs beyond
0 and 1 are valid too. mul returns non-zero for any two non-zero inputs, preserving the semantics of “truthy AND truthy = truthy”.NOT
Boolean NOT flips0 to 1 and any non-zero value to 0. The trick is diff(1, x) — monus clamps the subtraction so that 1 - x = 0 whenever x ≥ 1.
par_1_x builds the pair <1, x> by placing the constant k_1 alongside the identity projection. comp diff par_1_x then computes diff(1, x) = max(0, 1 - x), which equals 1 when x = 0 and 0 otherwise.
OR
Boolean OR usessigne — a function that returns 0 for input 0 and 1 for any positive input — applied to the sum a + b:
add first sums the two inputs; the result is positive if and only if at least one of them was non-zero. signe then normalises that positive value to exactly 1.
signe function itself (defined in signe.cantor) computes diff(x, anterior(x)), which is 0 when x = 0 and 1 when x > 0.
Equality
eq.cantor imports the full relacionals library and exposes its eq function as the program entry point:
eq lives in relacionals.cantor. It computes the sum of absolute differences:
diff(x, y) + diff(y, x) equals |x - y|, which is 0 exactly when x = y. eq then computes diff(1, |x - y|) — monus maps 0 to 1 (equal) and anything positive to 0 (unequal).
Less Than and Greater Than
lt and gt are also defined in relacionals.cantor, and each has a thin wrapper program that sets main:
relacionals.cantor use signe and the directional monus functions:
lt(x, y)appliessignetodiff(y, x) = max(0, y - x). That value is positive only wheny > x, sosignereturns1precisely whenx < y.gt(x, y)mirrors the pattern:signe(diff(x, y))is1only whenx > y.
Conditional (if–then–else)
cond.cantor implements a full if–then–else over natural numbers. Its input is a triple encoded as <p, <a, b>>: p is the condition, a is the true-branch value, and b is the false-branch value.
cond = bool_p * a + not_p * b. When p ≠ 0, bool_p = 1 and not_p = 0, so the result is a. When p = 0, bool_p = 0 and not_p = 1, so the result is b. Because both terms are multiplied to zero before being summed, only one branch contributes.
Maximum and Minimum
max and min are compact programs that exploit monus directly, without needing the full cond machinery.
max adds y to the excess of x over y:
diff_xy computes max(0, x - y). Adding that to y gives y + max(0, x - y) = max(x, y).
min subtracts that same excess from x:
x - max(0, x - y) = min(x, y) — when x ≥ y this is x - (x - y) = y; when x < y, diff_xy = 0 so the result is x.