In computer science, lambda calculus, also spelled λ-calculus, is a formal system designed to investigate function definition, function application, and recursion. It was introduced by Alonzo Church and Stephen Cole Kleene in the 1930s; Church used lambda calculus in 1936 to give a negative answer to the Entscheidungsproblem. Lambda calculus can be used to cleanly define what a computable function is. The question of whether two lambda calculus expressions are equivalent cannot be solved by a general algorithm, and this was the first question, even before the halting problem, for which undecidability could be proved. Lambda calculus has greatly influenced functional programming languages, such as Lisp, ML and Haskell.
Lambda calculus can be called the smallest universal programming language. It consists of a single transformation rule (variable substitution) and a single function definition scheme. Lambda calculus is universal in the sense that any computable function can be expressed and evaluated using this formalism. It is thus equivalent to the Turing machine formalism. However, lambda calculus emphasizes the use of transformation rules, and does not care about the actual machine implementing them. It is an approach more related to software than to hardware.
This article deals with the "untyped lambda calculus" as originally conceived by Church. Since then, some typed lambda calculi have been developed.
Originally, Church had tried to construct a complete formal system for the foundations of mathematics; when the system turned out to be susceptible to the analog of Russell's paradox, he separated out the lambda calculus and used it to study computability, culminating in his negative answer to the Entscheidungsproblem.
The three expressions
Not every lambda expression can be reduced to a definite value like the ones above; consider for instance
While the lambda calculus itself does not contain symbols for integers or addition, these can be defined as abbreviations within the calculus and arithmetic can be expressed as we will see below.
Lambda calculus expressions may contain free variables, i.e. variables not bound by any λ. For example, the variable y is free in the expression (λ x. y) , representing a function which always produces the result y . Occasionally, this necessitates the renaming of formal arguments, for instance in order to reduce
If one only formalizes the notion of function application and does not allow lambda expressions, one obtains combinatory logic.
Lambda expressions such as λ x. (x y) do not define functions because the occurrence of the variable y is free, i.e., it is not bound by any λ in the expression. The binding of occurrences of variables is (with induction upon the structure of the lambda expression) defined by the following rules:
Over the set of lambda expressions an equivalence relation (here denoted as ==) is defined that captures the intuition that two expressions denote the same function. This equivalence relation is defined by the α-conversion rule and the β-reduction rule. Sometimes an alternate equivalence relation, obtained by adopting a third rule called η-conversion, is used.
The alpha-conversion rule states that if V and W are variables, E is a lambda expression, and
E:= W
means the expression E with every free occurrence of V in E replaced with W, then
The relation == is then defined as the smallest equivalence relation that satisfies these two rules.
A more operational definition of the equivalence relation can be given by applying the rules only from left to right. A lambda expression which does not allow any beta reduction, i.e., has no subexpression of the form ((λ V. E) E′), is called a normal form. Not every lambda expression is equivalent to a normal form, but if it is, then the normal form is unique up to naming of the formal arguments. Furthermore, there is an algorithm for computing normal forms: keep replacing the first (left-most) formal argument with its corresponding concrete argument, until no further reduction is possible. This algorithm halts if and only if the lambda expression has a normal form. The Church-Rosser theorem then states that two expressions result in the same normal form up to renaming of the formal arguments if and only if they are equivalent.
If f and g are extensionally equivalent, i.e. if f ag a
for all lambda expressions a, then in particular by taking a to be a variable x not appearing free in f nor g we have f x
g x and hence λ x. f x λ x. g x
, and so by eta-conversion f
g. So if we take eta-conversion to be valid, we find extensionality is valid.
Conversely if extensionality is taken to be valid, then since by beta-reduction for all y we have (λ x. f x) y f y
, we have λ x. f x
f; i.e., eta-conversion is found to be valid.
(Note that in Church's original lambda calculus, the formal parameter of a lambda expression was required to occur at least once in the function body, which made the above definition of 0 impossible.) Given this definition of the Church numerals, we can define a successor function, which takes a number n and returns n + 1:
A predicate is a function which returns a boolean value. The most fundamental predicate is ISZERO which returns TRUE if its argument is the Church numeral 0, and FALSE if its argument is any other Church numeral:
A linked list datatype can be defined as either a reserved value (e.g. FALSE) for the empty list, or the CONS of an element and a smaller list.
In lambda calculus, one cannot define a function which includes itself. To get around this, one may start by defining a function, here called g, which takes a function f as an argument and returns another function that takes n as an argument:
The function that g returns either the constant 1, or n times the application of the function f to n-1. Using the ISZERO predicate, and boolean and algebraic definitions described above, the function g can be defined in lambda calculus.
However, g by itself is still not recursive; in order to use g to create the recursive factorial function, the function passed to g as f must have specific properties. Namely, the function passed as f must expand to the function g called with one argument -- and that argument must be the function that was passed as f again!
In other words, f must expand to g(f). This call to g will then expand to the above factorial function and calculate down to another level of recursion. In that expansion the function f will appear again, and will again expand to g(f) and continue the recursion. This kind of function, where f = g(f), is called a fixed-point of g, and it turns out that it can be implemented in the lambda calculus using what is known as the paradoxical operator or fixed-point operator and is represented as Y -- the Y combinator:
In the lambda calculus, Y g is a fixed-point of g, as it expands to g (Y g). Now, to complete our recursive call to the factorial function, we would simply call g (Y g) n, where n is the number we are calculating the factorial of.
Given n = 5, for example, this expands to:
And so on, evaluating the structure of the algorithm recursively. Every recursively defined function can be seen as a fixed point of some other suitable function, and therefore, using Y, every recursively defined function can be expressed as a lambda expression. In particular, we can now cleanly define the subtraction, multiplication and comparison predicate of natural numbers recursively.
Church's proof first reduces the problem to determining whether a given lambda expression has a normal form. A normal form is an equivalent expression which cannot be reduced any further. Then he assumes that this predicate is computable, and can hence be expressed in lambda calculus. Building on earlier work by Kleene and constructing a Gödel numbering for lambda expressions, he constructs a lambda expression e which closely follows the proof of Gödel's first incompleteness theorem. If e is applied to its own Gödel number, a contradiction results.
Most programming languages are equivalent to the lambda calculus extended with some additional programming language constructs. The classical work where this viewpoint was put forward was Peter Landin's "A Correspondence between ALGOL 60 and Church's Lambda-notation", published in CACM in 1965. The key point is that the lambda calculus expresses the kind of procedural abstraction and application useful for any programming language. Prominently, functional programming languages are basically the lambda calculus with some constants and datatypes added. Lisp uses a variant of lambda notation for defining functions, but only its purely functional subset is really equivalent to lambda calculus.
Actually implementing the lambda calculus on a computer involves treating "functions" as first-class objects, which turns out to be rather difficult to accomplish using stack-based computer languages. This is known as the Funarg problem.
Theory of the lambda calculus says that lambda calculus computations can always be carried out sequentially, not that they must be carried out sequentially. The lambda calculus is suitable for expressing some kinds of parallelism — for example, call by future evaluation. However, the lambda calculus does not in general implement concurrency; related calculi (such as the π calculus) have been designed to overcome this limitation.
Mathematical logic | Computational models | Logic in computer science | Lambda calculus | Theoretical computer science | Formal methods | Recursion theory
Lambda kalkul | Lambda-Kalkül | Cálculo lambda | Lambda-calcul | Lambda calcolo | תחשיב למבדא | Lambda-kalkulus | Lambdacalculus | ラムダ計算 | Rachunek lambda | Cálculo Lambda | Лямбда-исчисление | Lambda kalkul | Lambdakalkyl | Λ演算
This article is licensed under the GNU Free Documentation License.
It uses material from the
"Lambda calculus".
Home Page • arts • business • computers • games • health • hospitals • home • kids & teens • news • physicians • recreation• reference • regional • science • shopping • society • sports • world