I am getting stuck with the Wikipedia description of the predecessor function in lambda calculus.
What Wikipedia says is the following:
PRED := λn.λf.λx. n (λg.λh. h (g f)) (λu.x) (λu.u)
Can someone explain reduction processes step-by-step?
Thanks.
After Reading the previous answers (good ones), I’d like to give my own vision of the matter in hope it helps someone (corrections are welcomed). I’ll use an example.
First off, I’d like to add some parenthesis to the definition that made everything clearer to me. Let’s redifine the given formula to:
Let’s also define three Church numerals that will help with the example:
In order to understand how this works, let's focus first on this part of the formula:
From here, we can extract this conclusions:
n
is a Church numeral, the function to be applied isλgλh.h (g f)
and the starting data isλu.x
With this in mind, let's try an example:
Let's focus first on the reduction of the numeral (the part we explained before):
Which reduces to:
Ending up with:
So, we have:
Reducing again:
As you can see in the reductions, we end up applying the function one time less thanks to a clever way of using functions.
Using add1 as
f
and 0 asx
, we get:Hope this helps.