M =def= Y (\m n p. p m (p n m))For explanation, and for a similar exercise, see Lecture Notes 6 and 8 (Section "The fixpoint operators in lambda calculus")
is_even(0) = true is_even(n+1) = if is_even(n) then false else truehence we can define
[is_even] =def= Y (\f x. [if_then_else] ([is_zero] x) [true] ([if_then_else] (f ([Predecessor] x)) [false] [true]) )
Another solution, more interesting, can be given by using the iteration capability of Church numeralas:
[is_even] = \x. x [not][true]where [not] is the encoding of the logical negation:
[not] = \b. [if_then_else] b [false] [true]
Y F ->> (\f. f...f (\x. f (x x))(\x. f (x x))) F -> F...F (\x. F (x x))(\x. F (x x))) ->> F...F...F (\x. F (x x))(\x. F (x x))) ...and none of these terms are alpha equivalent to F(Y F)
M M F -> (\x. M (x x M)) F -> M (F F M) -> \x. (F F M) (x x (F F M))In order to reduce it to a normal form, define F =def= [true] = \x y. x. We have:
M M [true] ->> \x. ([true] [true] M) (x x ([true] [true] M)) ->> \x. [true] (x x [true]) -> \x y. x x [true] (normal form)On the other hand, we have
[true] (M M [true]) -> \z. M M [true] ->> \z x y. x x [true] (normal form)Since the normal forms are different, by the Church-Rosser theorem, the two terms are not lambda convertible.
n = 0 and n = 1 are special cases. We have [0] : A -> B -> B, and [1] : (A -> B) -> A -> B.
val rec iterate = fn f => fn n => fn x => if n=0 then x else f (iterate f (n-1) x);
val Church_num = swap iterate;where swap is the function that inverts the arguments of a function (swap g x y = g y x), see Exercise 4.3 in Assignment 3.