Microsoft Store
 

Lambda calculus


 

In computer science, the lambda 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 the lambda calculus in 1936 to give a negative answer to the Entscheidungsproblem. The calculus can be used to cleanly define what is a computable function. 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, especially Lisp.

Formal definition

Formally, we start with a countably infinite set of identifiers, say {a, b, c, ..., x, y, z, x1, x2, ...}. The set of all lambda expressions can then be described by the following context-free grammar in BNF:

Related Topics:
Countably infinite - Set - Context-free grammar - BNF

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

  • <expr> ::= <identifier>
  • <expr> ::= (λ <identifier>. <expr>)
  • <expr> ::= (<expr> <expr>)
  • The first two rules generate functions, while the third describes the application of a function to an argument. Usually the parentheses for lambda abstraction (rule 2) and function application (rule 3) are omitted if there is no ambiguity under the assumptions that (1) function application is left-associative, and (2) a lambda binds to the entire expression following it. For example, the expression  ((λ x. (x x)) (λ y. y))  can be simply written as  (λ x. x x) λ y. y.

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    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:

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

  • In an expression of the form  V,  where V is a variable, this V is the single free occurrence.
  • In an expression of the form  λ V. E,  the free occurrences are the free occurrences in E except those of V. In this case the occurrences of V in E are said to be bound by the λ before V.
  • In an expression of the form  (E E′),  the free occurrences are the free occurrences in E and E′.
  • 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 so-called alpha-conversion rule and the beta-reduction rule.

    ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

α-conversion

The alpha-conversion rule is intended to express the idea that the names of the bound variables are unimportant; for example that  λx.x  and  λy.y  are the same function. However, the rule is not as simple as it first appears. There are a number of restrictions on when one bound variable may be replaced with another.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

The alpha-conversion rule states that if V and W are variables, E is a lambda expression, and E means the expression E with every free occurrence of V in E replaced with W, then

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

: λ V. E  ==  λ W. E

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

if W does not appear freely in E and W is not bound by a λ in E whenever it replaces a V. This rule tells us for example that  λ x. (λ x. x) x  is the same as  λ y. (λ x. x) y.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

β-reduction

The beta-reduction rule expresses the idea of function application. It states that

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

: ((λ V. E) E′) == E

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

if all free occurrences in E′ remain free in E.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

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.

Related Topics:
Up to - Church-Rosser theorem

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

η-conversion

There is a third rule, eta-conversion, which may be added to these two to form a new equivalence relation. Eta-conversion expresses the idea of extensionality, which in this context is that two functions are the same iff they give the same result for all arguments. Eta-conversion converts between  λ x. f x  and  f  whenever x does not appear free in f. This can be seen to be equivalent to extensionality as follows:

Related Topics:
Extensionality - Iff

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

If f and g are extensionally equivalent, i.e. if  f a == g 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.

~ ~ ~ ~ ~ ~ ~ ~ ~ ~