Chapter 3: Church Numerals: Increment
Church Numerals
The most important data in computer programs are integers.
Let's define natural integers.
0=λs.λz.z1=λs.λz.s(z)2=λs.λz.s(s(z))3=λs.λz.s(s(s(z)))⋮n=λs.λz.sn(z)
Why should we define integers like this? What does s and z mean here?
Let's take 2 for example to watch how church numerals could be converted back to normal ones. let s=λx.(x+1),z=0, then:
2sz======(λs.λz.s(s(z)))szs(s(z))s(s(0))s(0+1)1+12
It is clear now: s stands for succussor and z stands for zero. It is built base on recursion. And yes, it is exactly how natural numbers are defined mathematically.
Successor
To get the successor of a church numeral, just simply wrap an s around it.
S=λn.λs.λz.(s(nsz))Sn=n+1
Proof:
Sn======(λn.λs.λz.(s(nsz)))(λs.λz.sn(z))(λs′.λz′.(s′((λs.λz.sn(z))s