This is the first of a multi-part post about
-Calculus. I’m going to start with a description of the Untyped
-Calculus. Future articles will include Church Numerals and Typed
-Calculus.
Why?
-Calculus is important because it has a close tie with functional programming. In fact most functional languages compile to some form of
-Calculus. You could say that
-Calculus is to functional programming what the Turing machine is to imperative programming.
The very basics
Everything is a function in
-Calculus but for the purposes of this post we will extend the core calculus with integers and basic integer operations. In a future post we will go into how integers can be represented as functions (for those unwilling to wait, check out Church Numerals).
Lets start with a sample expression:

This is called an abstraction. In this expression we call the x variable bound and the y variable free. There is one other operation called application. Application takes the form of:
![\lambda x . x+y [x := 3] \lambda x . x+y [x := 3]](http://l.wordpress.com/latex.php?latex=%5Clambda+x+.+x%2By+%5Bx+%3A%3D+3%5D&bg=ffffff&fg=000000&s=0)
-Calculus evaluates expressions by simple substitution so the above expression simplifies to
. One thing to note about this is that in the term
where
is another term, only free occurences of
get replaced.
therefore simplifies to
.
All functions are functions of one variable
-Calculus does not allow abstractions that take multiple arguments. Instead you write functions that return functions which take the next variable.

simplifying this with
we get:
![\lambda x . \lambda y . x + y [x := 3][y := 4] \lambda x . \lambda y . x + y [x := 3][y := 4]](http://l.wordpress.com/latex.php?latex=%5Clambda+x+.+%5Clambda+y+.+x+%2B+y+%5Bx+%3A%3D+3%5D%5By+%3A%3D+4%5D&bg=ffffff&fg=000000&s=0)
![\lambda y . 3 + y [y := 4] \lambda y . 3 + y [y := 4]](http://l.wordpress.com/latex.php?latex=%5Clambda+y+.+3+%2B+y+%5By+%3A%3D+4%5D&bg=ffffff&fg=000000&s=0)


For conciseness,
can be written as
but it is important to remember that this is a function that takes the value for x and returns a new function.
The Y combinator
It may have occured to you that recursion cannot be implemented with a simple substitution model and there are no looping constructs. How can this be Turing Complete? Recursion can be simulated by using a function
such that
(ie. a fixed-point function), assume for the moment that such a function
exists.
If you wanted to represent the factorial function with recursion you could do it as:

Since terms are not named, and recursion is impossible, we have to write a function that takes (Yf) as a parameter.

we’ll call this expression
for brevity.
Since: 
and f is bound to
giving us recursion!
Now to show the (not-so-magical) fixed point function
:

Proof


![Y g = g [ ( \lambda x . g(xx)) ( \lambda x . g(xx))] Y g = g [ ( \lambda x . g(xx)) ( \lambda x . g(xx))]](http://l.wordpress.com/latex.php?latex=Y+g+%3D+g+%5B+%28+%5Clambda+x+.+g%28xx%29%29+%28+%5Clambda+x+.+g%28xx%29%29%5D&bg=ffffff&fg=000000&s=0)
