Lambda Calculus · v1.1.1
2026-10-26 12:21:16
select_first, select_second and make_pair become truth values, conditionals and numbersEvery definition below expands to pure λ terms.
condnot, and, orzero, succ, iszero, predtrue is select_first; false is select_secondmake_pairzero, or a succ wrapping another numberUnit 1 claimed data needs no separate mechanism. This unit makes it good.
TRUE selects the first expression, FALSE the secondselect_first and select_second do exactly that\[((\mathrm{cond}\ E_1)\ E_2) \Rightarrow \lambda c.((c\ E_1)\ E_2)\]
make_pair whose last argument is the condition\[ \begin{align} &(\lambda c.((c\ E_1)\ E_2)\ \mathrm{select\_first}) \Rightarrow ((\mathrm{select\_first}\ E_1)\ E_2) \Rightarrow E_1 \\[8pt] &(\lambda c.((c\ E_1)\ E_2)\ \mathrm{select\_second}) \Rightarrow ((\mathrm{select\_second}\ E_1)\ E_2) \Rightarrow E_2 \end{align} \]
\(E_1\) and \(E_2\) stand for any two expressions. Selection is the whole of the conditional.
if is a control structure elsewhere, and booleans a primitive type; here both are ordinary functionsX ? A : B is (((cond A) B) X)((X A) B) — the condition applied straight to the branchesThat simplified form is what every operator below uses.
| X | NOT X |
|---|---|
| FALSE | TRUE |
| TRUE | FALSE |
X ? FALSE : TRUEλx.(((cond false) true) x)\[(\mathrm{not}\ \mathrm{true}) \Rightarrow ((\mathrm{true}\ \mathrm{false})\ \mathrm{true}) \Rightarrow \mathrm{false}\]
| X | Y | X AND Y |
|---|---|---|
| FALSE | FALSE | FALSE |
| FALSE | TRUE | FALSE |
| TRUE | FALSE | FALSE |
| TRUE | TRUE | TRUE |
TRUE: the value is the right operandFALSE: the value is FALSEX ? Y : FALSE\[((\mathrm{and}\ \mathrm{true})\ \mathrm{false}) \Rightarrow ((\mathrm{true}\ \mathrm{false})\ \mathrm{false}) \Rightarrow \mathrm{false}\]
| X | Y | X OR Y |
|---|---|---|
| FALSE | FALSE | FALSE |
| FALSE | TRUE | TRUE |
| TRUE | FALSE | TRUE |
| TRUE | TRUE | TRUE |
TRUE: the value is TRUEX ? TRUE : Y\[((\mathrm{or}\ \mathrm{false})\ \mathrm{true}) \Rightarrow ((\mathrm{false}\ \mathrm{true})\ \mathrm{true}) \Rightarrow \mathrm{true}\]
false first operand selects falseElsewhere short-circuiting is a rule written into the language definition; here it follows from the encoding.
zerosucc n builds a pair: false first, n second\[ \begin{align} \mathrm{one} \equiv (\mathrm{succ}\ \mathrm{zero}) &\Rightarrow \lambda s.((s\ \mathrm{false})\ \mathrm{zero}) \\[6pt] \mathrm{two} \equiv (\mathrm{succ}\ \mathrm{one}) &\Rightarrow \lambda s.((s\ \mathrm{false})\ \lambda s.((s\ \mathrm{false})\ \mathrm{zero})) \end{align} \]
three is one layer deeper againzero is a function taking a selector\[ \begin{align} &(\lambda s.((s\ \mathrm{false})\ N)\ \mathrm{select\_first}) \Rightarrow ((\mathrm{select\_first}\ \mathrm{false})\ N) \Rightarrow \mathrm{false} \\[6pt] &(\mathrm{zero}\ \mathrm{select\_first}) \Rightarrow \mathrm{select\_first} \equiv \mathrm{true} \end{align} \]
zero is identity, so it returns the selector unchanged\[ \begin{align} &(\lambda s.((s\ \mathrm{false})\ N)\ \mathrm{select\_second}) \Rightarrow N \\[6pt] &(\mathrm{pred1}\ \mathrm{zero}) \Rightarrow \mathrm{select\_second} \equiv \mathrm{false} \quad {\color{#c0392b}\boldsymbol{\times}} \end{align} \]
select_second strips one layer of nestingfalse is not a number, so pred tests for zero and returns zero thereUsing pred requires checking for a zero argument.
\[ \begin{align} &(\ldots((f\ a_1)\ a_2)\ \ldots\ a_N) \\ \text{may be written}\quad &f\ a_1\ a_2\ \ldots\ a_N \end{align} \]
n replaces zero in that branch: it is reached only when iszero n holds.
The sugar is always removable: expand back to pure terms when a derivation confuses.
def cond = λe1.λe2.λc.((c e1) e2)
def true = select_first
def false = select_second
def not = λx.((x false) true)
def and = λx.λy.((x y) false)
def or = λx.λy.((x true) y)
def zero = identity
def succ = λn.λs.((s false) n)
def iszero = λn.(n select_first)
def pred = λn.(((iszero n) zero) (n select_second))Booleans and integers, built from three productions and three conversions.
succ and pred step by onecondzero is identityRecursion and Arithmetic — the next unit in this module.