Natural Numbers and Arithmetic
The Concept of Numbers in Lambda Calculus
Numbers are fundamental in computation, but in lambda calculus, we don't have built-in numbers like 1, 2, or 3. Instead, we must construct them using functions.
This idea comes from Alonzo Church, the inventor of Church numerals — a way to represent natural numbers using functions alone.
At its core, a number n is simply a function that applies another function n times.
For example:
0applies a function 0 times.1applies a function once.2applies a function twice, and so on.
Church numerals
In lambda calculus, natural numbers are represented using Church numerals — a way to encode numbers as functions. The idea is simple:
A number
The general definition is:
So, basically,
Where:
(zero) does nothing: (one) applies fonce:(two) applies ftwice:- And so on…
Addition
Adding two Church numerals means applying one number's function on top of another number’s function:
Looks complex, right? Let's break it down. Keep eyes on colors!
Example
Let's compute
We substitute
First, we apply
Expand
Now, substitute
Applying
Now, substitute
Let
Now, push
Expand
Which is exactly
✅ We have computed
Successor and Predecessor Functions
So, another way to define numbers could be implemented inductively using pairs.
Basically,
In other words:
Successor Function (Increment)
The successor function adds one to a given number:
Where:
is the successor operation: represents a pair:
Thus,
Let's evaluate
So,
It's like incrementing the number by one. 🚀
int x = 2;
x++;
std::cout << x; // 3
Predecessor Function (Decrement)
The predecessor function subtracts one from a given number:
Where:
is the function used to track previous values. - The function applies
while counting up, keeping track of the last valid number.
Let's evaluate
So,
It's like decreasing the number by one. 🚀
int x = 3;
x--;
std::cout << x; // 2
Zero Check Function
To check if a number is zero, we use the function:
This function takes a Church numeral and applies it to
Let's evaluate
Since
✅ Correct!
Special Case: Zero Check on
Since
✅ Success! We can now check if a number is zero in lambda calculus. 🚀
Special Case: Decrement Zero
Let's try to decrement
Thus,