I have a few exercises for my study subject computability theory. One of this is:
Please, write term for function $f(n) = n!$
I don't know how start doing it. Maybe someone can help with this example or maybe someone can send me where in net I can find material for this topic.
If we exploit the iteration that we get for free from the Church numerals, we don't need to do our own fixpoints, so we can get through a lot easier than DanielV's solution.
If we create a function $F$ such that $$ \underbrace{F(F(\cdots(F}_n (1,1))\cdots)) = (n+1,n!) $$ then the factorial of $k$ is the second element of the pair that results from $k\; F\; (1,1)$
The standard representation of the ordered pair $(A,B)$ is $\lambda g.g A B$, so this means that $$ ! = \lambda k. k\;F\;(\lambda g.g\,1\,1)\;(\lambda ab.b) $$ So we need to define $F$. It must satisfy the definition (in ordinary arithmetic notation) $$ F(a,b) = (a+1, a\times b) $$ which we can translate directly to lambda notation using known successor and multiplication constructions for Church numerals as $$ F = \lambda p.p (\lambda a b g. g \; (\lambda f x.f(afx))\; (\lambda f.a(bf))) $$ Now all there is left is to expand the definitions of $F$ and $1$, and we get $$ ! = \lambda k. k \; \Bigl(\lambda p.p\bigl(\lambda abg.g\;\bigl(\lambda fx.f(afx)\bigr)\;\bigl(\lambda f.a(bf)\bigr)\bigr)\Bigr) \; \bigl(\lambda g.g\, (\lambda h.h)\, (\lambda h.h)\bigr) \; \bigl(\lambda ab.b\bigr) $$
Using this technique we can write any primitive recursive function -- or, in programming terms, every FOR program -- in a quite natural way without ever using an explicit fixpoint combinator. In contrast to the recursion schema DanielV uses, the results will be typable in System F.