1. Currying (Currying)
Currying a function is to be converted to a single multi-parameter argument function method. Similar to the composite function.
Now we have two input values xy corresponds to a function f (x, y), how to make a function F begun to accept only a value of it?
We can define a F1 = λx.F2, then make F2 = λy.f (x, y) to complete currying.
2. The encoding (Encoding)
With so many algorithms specific to what use it? Then we can use some programming language code to indicate the basic data and statements, to achieve functional programming.
TRUE := λxy.x
FALSE := λxy.y
NOT := λfxy.fyx
OR := λxy.xxy
AND := λxy.xyx
IFELSE := λfxy.fxy
We all know that in the computer world binary 0 is NOT, 1 is TRUE. The same is true in the λ calculus:
ZERO := λxy.y
And we have an addend, based on each zero plus one can get all the natural numbers, we have opposite subtrahend each time minus one.
SUCCESSOR := λxyz.y(xyz)
PRED := λnfx.n(λgh.h(gf)) (λy.x) (λu.u)
We can get through this formula for a natural number of items:
n = λfx. f^n (x)
We have some other algorithms:
ADD := λxypq.xp(ypq)
MULT := λxyz.x(yz)
EXP := λxy.yx
Let's try!
NOT TRUE
= (λfxy.fyx) (λxy.x)
= (λfxy.fyx) (λab.a)
= λxy.(λab.a) yx
= λxy.(λb.y) x
= λxy.y
= FALSE
ONE
= SUCCESSOR ZERO
= (λxyz.y(xyz)) (λxy.y)
= (λxyz.y(xyz)) (λab.b)
= λyz.y((λab.b) yz)
= λyz.y((λb.b) z)
= λyz.yz
= ONE
ADD ZERO ONE
= (λxypq.xp(ypq)) (λxy.y) (λxy.xy)
= (λxypq.xp(ypq)) (λab.b) (λcd.cd))
= (λypq. (λab.b) p(ypq)) (λcd.cd))
= (λypq. (λb.b) (ypq)) (λcd.cd))
= (λypq. (ypq)) (λcd.cd))
= (λpq. ((λcd.cd)pq))
= (λpq. ((λd.pd)q))
= (λpq.pq))
= (λxy.xy)
= ONE