Lambda calculus

The lambda calculus was invented by Alonzo Church in the 1930s as part of an attempt to construct a formal system for the foundations of mathematics. When that system turned out to be inconsistent, Church isolated and published in 19361 just the portion relevant to computation &mdash; what is now called the lambda calculus &mdash; and this was proved 2 to be consistent that same year.

In lambda calculus a function does not return a result based on its parameters &mdash; instead the function and its parameters are reduced to give an answer, which mathematically is equivalent to the question. Turing3 proved that the lambda-definable functions coincide with the Turing-computable functions (so lambda calculus is Turing-complete), thereby lending credence to the thesis &mdash; now called the Church-Turing thesis &mdash; that it's these functions, and these functions only, that would naturally or intuitively be regarded as "effectively computable."

The following paragraphs give an informal introduction to lambda calculus &mdash; for a formal description of lambda calculus see under "External resources."

A function in lambda calculus is written in the form "&lambda; x.E", where x is the function's parameter and E is a lambda expression constituting the function body. A lambda expression is either a variable (like the x in the above expression), a function in the form above, or an application E1E2.

In the expression "&lambda; x.E", any occurrence of x in E is bound, while any other variable is free (unless bound by another lambda expression, like the y in "&lambda; x.&lambda; y.xy"). A pure lambda expression has no free variables.

Three things can be done with lambda expressions:


 * Alpha conversion renames a bound variable: "&lambda; x.x" can be alpha converted to "&lambda; y.y".
 * Beta reduction allows applications to be reduced: "(&lambda; x.E1)E2" can be beta reduced to E1 with all occurrences of x replaced with E2. If there are name clashes (for example in "(&lambda; x.&lambda; y.xy)y"), alpha conversion may be required first.
 * Eta conversion allows us to say that "f" and "&lambda; x.fx" are equivalent.

Two shorthand notations are used:


 * "&lambda; x1 x2... ...xn.E" means "&lambda; x1. (&lambda; x2. ...(&lambda; xn.E)...)"
 * fab means (fa)b

Examples
It may not be initially clear how lambda calculus can carry out any useful computation. In this section of the document the basics of integer arithmetic in lambda calculus are shown &mdash; see under "External resources" for further examples of recursion, boolean logic and the representation of tuples and lists.

The most common representation of integers in lambda calculus is the idea of Church numerals, where n is represented by the concept nth. In particular:


 * zero = &lambda; fx.x
 * one = &lambda; fx.fx
 * two = &lambda; fx.f(fx)
 * three = &lambda; fx.f(f(fx))

Where the function f is applied n times. We can now represent the concept of increment by the lambda expression:

&lambda; nfx.f(nfx)

To see how this works, we can apply it to the Church numeral for two:

(&lambda; nfx.f(nfx))(&lambda; fx.f(fx))

By alpha conversion and beta reduction this becomes:

&lambda; fx.f((&lambda; gy.g(gy))fx)

Which by further beta reduction becomes:

&lambda; fx.f(f(fx))

Which we can see is the Church numeral for three.

External resources

 * Lambda calculus at Wikipedia
 * Lambda Calculus (at Safalra's Website)
 * Formal Description Of Lambda Calculus