Recursion in Lambda Calculus
Theorem About Recursion
Recursion is the process of defining a function in terms of itself. However, in lambda calculus, functions cannot reference themselves directly, as there are no variable bindings for function names. This is where the Y-combinator and fixed-point theory come into play.
The recursion theorem states:
It means that for every function
Breaking it Down
-
means "replace with in ". - In simpler terms, if
is some function with an unknown part , we replace with .
- In simpler terms, if
-
satisfies the equation . - This means that applying
to just gives back . is a fixed point of , which makes it self-referential.
- This means that applying
-
In Lambda Calculus, we can write this stuff like this:
Example to Make It Clear
Suppose we define a function
According to the theorem, we need to find
This means that
If we solve for
Thus,
which is the same as
What This Means in Lambda Calculus
- In lambda calculus, we don’t have numbers like
, but we can still define functions that refer to themselves. - The theorem says we can find an
that satisfies , meaning is self-referential. - This is how recursion is possible—it allows a function to call itself without explicitly having a name.
By using the Y-combinator, we can construct
This allows recursion without naming the function explicitly.
Example: Recursive Addition with the Y-Combinator
Now that we understand how the Y-combinator enables recursion in lambda calculus, let’s go through a step-by-step example of addition using the Y-combinator.
Step 1: Defining Addition Recursively
We define addition as a recursive function in an imperative style:
def add(x, y):
if isZero(y):
return x
else:
return add(increment(x), decrement(y))
This function works by:
- Returning
if (base case). - Otherwise, increasing
and decreasing until reaches .
Step 2: Transforming to a Lambda Expression
Since lambda calculus does not allow direct recursion, we rewrite add by introducing a placeholder function f:
def add(f, x, y):
if isZero(y):
return x
else:
return f(increment(x), decrement(y)) # Indirect recursive call (magic!)
In lambda calculus, this becomes:
Since f is meant to call add recursively, we apply the Y-combinator to define recursion:
Now, add can call itself indirectly through Y add!
We already know that add.
Step 3: Evaluating 1 + 1 Step by Step
We now evaluate:
First expansion
Substituting values:
Since isZero(1) = False, we continue:
Second expansion
Expanding again:
Substituting values:
Since isZero(0) = True, we return 2.
✅ Final result:
Why Does This Work?
- We define addition recursively by reducing
while incrementing . - The Y-combinator enables recursion by ensuring
addcan call itself. - The evaluation follows a structured reduction process, stopping when
y = 0.
🚀 This method allows us to express recursion in pure lambda calculus, without explicitly naming functions!