Chapter 4: Church Numerals: Decrement
Predecessor
The implementation of the predecessor function is much harder than previous ones. In fact, Church thought for a long time that it might not be possible, until his student Kleene found it. In fact, there is a legend that Kleene conceived the idea while visiting his dentist, which is why the trick is called the wisdom tooth trick.
Wisdom Tooth Trick
Let's define a helper function Φ:
Φ=λp.π(S(π1p))(π1p)
Initially, we have:
Φ(π0 0)=(π1 0)
By means of mathematical induction, we get:
Φn(π0 0)=(πn (n−1))
With the help of ordered pair, predecessor function could be defined as:
pred=λn.π2(nΦ(π0 0))pred n=n−1
Note that pred 0=0. It is a limit of church numerals. Is it possible to define negative numbers or even rational numbers? Of course! Remember what I mentioned in Data Abstraction part? Build one if it doesn't exist yet!
Subtraction
Subtraction compared to predecessor is similar to addition compared to successuor.
sub=λmn.n pred msub mn=m−n
It reads as if "evaluating nth predecessor of m".
Proof is similar to the addition operation.
Note: if m<n, sub mn=0 according to the definition of predecessor function.
Zero Predicate
Let's review the definitions of false and zero:
F=λxy.y0=λs.λz.z
With α reduction, it is clear that:
F=0=λx.I
where I=λx.x, called identity function, which returns its parameter unchanged.
Then, 0 predicate could be defined as:
is-zero=λn.nF not F
Proof:
For n=0:
is-zero 0=====is-zero F(λn.nF not F)FFF not Fnot FT
For n>0:
is-zero n========(λn.nF not F)nnF not FFn(not)F(λx.I)n(not)F(λx.I)n−1(I)F⋯IFF
Comparison
Subtraction is a fundamental approach to compare two numbers. With the help of the fact that if m≤n, sub mn=0, less-equal function could be defined as:
≤:le=λmn.is-zero(sub mn)
Since:
x≤y∧y≤x→x=y
Equality function could be defined as:
=:eq=λmn.(and(le mn)(le nm))
Rest part of work should be easy now.
≥:>:<:=:gegtltne====λmn.le nmλmn.not(le mn)λmn.gt nmλmn.not(eq mn)