Lambda calculus definition

Short description: Summary of formal definitions of lambda calculus

Lambda calculus is a formal mathematical system based on lambda abstraction and function application. Two definitions of the language are given here: a standard definition, and a definition using mathematical formulas.

## Contents

* 1 Standard definition
* 1.1 Definition
* 1.2 Notation
* 1.3 Free and bound variables
* 1.4 Reduction
* 1.4.1 α-conversion
* 1.4.1.1 Substitution
* 1.4.2 β-reduction
* 1.4.3 η-reduction
* 1.5 Normalization
* 2 Syntax definition in BNF
* 3 Definition as mathematical formulas
* 3.1 Semantics
* 3.2 Canonym - Canonical Names
* 3.3 Map operators
* 3.4 Substitution operator
* 3.5 Free and bound variable sets
* 3.6 Evaluation strategy
* 3.6.1 Normal form
* 3.6.2 Weak head normal form
* 4 Derivation of standard from the math definition
* 4.1 Free and bound variables
* 4.2 Changes to the substitution operator
* 4.3 Transformation
* 4.3.1 α-conversion
* 4.3.2 β-reduction (capture avoiding)
* 4.3.3 η-reduction
* 5 References

## Standard definition

This formal definition was given by Alonzo Church.

### Definition

Lambda expressions are composed of

* variables [math]\displaystyle{ v_{1} }[/math], [math]\displaystyle{ v_{2} }[/math], ..., [math]\displaystyle{ v_{n} }[/math], ...
* the abstraction symbols lambda '[math]\displaystyle{ \lambda }[/math]' and dot '.'
* parentheses ( )

The set of lambda expressions, [math]\displaystyle{ \Lambda }[/math], can be defined inductively:

1. If [math]\displaystyle{ x }[/math] is a variable, then [math]\displaystyle{ x \in \Lambda }[/math]
2. If [math]\displaystyle{ x }[/math] is a variable and [math]\displaystyle{ M \in \Lambda }[/math], then [math]\displaystyle{ (\lambda x . M) \in \Lambda }[/math]
3. If [math]\displaystyle{ M, N \in \Lambda }[/math], then [math]\displaystyle{ (M \ N) \in \Lambda }[/math]

Instances of rule 2 are known as abstractions and instances of rule 3 are known as applications.[1]

### Notation

To keep the notation of lambda expressions uncluttered, the following conventions are usually applied.

* Outermost parentheses are dropped: [math]\displaystyle{ M \ N }[/math] instead of [math]\displaystyle{ (M \ N) }[/math]
* Applications are assumed to be left-associative: [math]\displaystyle{ M \ N \ P }[/math] may be written instead of [math]\displaystyle{ ((M \ N) \ P) }[/math][2]
* The body of an abstraction extends as far right as possible: [math]\displaystyle{ \lambda x . M \ N }[/math] means [math]\displaystyle{ \lambda x . (M \ N) }[/math] and not [math]\displaystyle{ (\lambda x . M) \ N }[/math]
* A sequence of abstractions is contracted: [math]\displaystyle{ \lambda x . \lambda y . \lambda z . N }[/math] is abbreviated as [math]\displaystyle{ \lambda x y z . N }[/math][3][4]

### Free and bound variables

The abstraction operator, [math]\displaystyle{ \lambda }[/math], is said to bind its variable wherever it occurs in the body of the abstraction. Variables that fall within the scope of an abstraction are said to be bound. All other variables are called free. For example, in the following expression [math]\displaystyle{ y }[/math] is a bound variable and [math]\displaystyle{ x }[/math] is free: [math]\displaystyle{ \lambda y . x \ x \ y }[/math]. Also note that a variable is bound by its "nearest" abstraction. In the following example the single occurrence of [math]\displaystyle{ x }[/math] in the expression is bound by the second lambda: [math]\displaystyle{ \lambda x . y (\lambda x . z \ x) }[/math]

The set of free variables of a lambda expression, [math]\displaystyle{ M }[/math], is denoted as [math]\displaystyle{ \operatorname{FV}(M) }[/math] and is defined by recursion on the structure of the terms, as follows:

1. [math]\displaystyle{ \operatorname{FV}(x) = \\{ x \\} }[/math], where [math]\displaystyle{ x }[/math] is a variable
2. [math]\displaystyle{ \operatorname{FV}(\lambda x . M) = \operatorname{FV}(M) \backslash \\{ x \\} }[/math]
3. [math]\displaystyle{ \operatorname{FV}(M \ N) = \operatorname{FV}(M) \cup \operatorname{FV}(N) }[/math][5]

An expression that contains no free variables is said to be closed. Closed lambda expressions are also known as combinators and are equivalent to terms in combinatory logic.

### Reduction

The meaning of lambda expressions is defined by how expressions can be reduced.[6]

There are three kinds of reduction:

* α-conversion: changing bound variables (alpha);
* β-reduction: applying functions to their arguments (beta);
* η-reduction: which captures a notion of extensionality (eta).

We also speak of the resulting equivalences: two expressions are β-equivalent, if they can be β-converted into the same expression, and α/η-equivalence are defined similarly.

The term redex, short for reducible expression, refers to subterms that can be reduced by one of the reduction rules. For example, [math]\displaystyle{ (\lambda x . M) \ N }[/math] is a β-redex in expressing the substitution of [math]\displaystyle{ N }[/math] for [math]\displaystyle{ x }[/math] in [math]\displaystyle{ M }[/math]; if [math]\displaystyle{ x }[/math] is not free in [math]\displaystyle{ M }[/math], [math]\displaystyle{ \lambda x . M \ x }[/math] is an η-redex. The expression to which a redex reduces is called its reduct; using the previous example, the reducts of these expressions are respectively [math]\displaystyle{ M[x := N] }[/math] and [math]\displaystyle{ M }[/math].

#### α-conversion

Alpha-conversion, sometimes known as alpha-renaming,[7] allows bound variable names to be changed. For example, alpha-conversion of [math]\displaystyle{ \lambda x . x }[/math] might yield [math]\displaystyle{ \lambda y . y }[/math]. Terms that differ only by alpha-conversion are called α-equivalent. Frequently in uses of lambda calculus, α-equivalent terms are considered to be equivalent.

The precise rules for alpha-conversion are not completely trivial. First, when alpha-converting an abstraction, the only variable occurrences that are renamed are those that are bound by the same abstraction. For example, an alpha-conversion of [math]\displaystyle{ \lambda x . \lambda x . x }[/math] could result in [math]\displaystyle{ \lambda y . \lambda x . x }[/math], but it could not result in [math]\displaystyle{ \lambda y . \lambda x . y }[/math]. The latter has a different meaning from the original.

Second, alpha-conversion is not possible if it would result in a variable getting captured by a different abstraction. For example, if we replace [math]\displaystyle{ x }[/math] with [math]\displaystyle{ y }[/math] in [math]\displaystyle{ \lambda x . \lambda y . x }[/math], we get [math]\displaystyle{ \lambda y . \lambda y . y }[/math], which is not at all the same.

In programming languages with static scope, alpha-conversion can be used to make name resolution simpler by ensuring that no variable name masks a name in a containing scope (see alpha renaming to make name resolution trivial).

##### Substitution

Substitution, written [math]\displaystyle{ E[V := R] }[/math], is the process of replacing all free occurrences of the variable [math]\displaystyle{ V }[/math] in the expression [math]\displaystyle{ E }[/math] with expression [math]\displaystyle{ R }[/math]. Substitution on terms of the lambda calculus is defined by recursion on the structure of terms, as follows (note: x and y are only variables while M and N are any λ expression).

[math]\displaystyle{ \begin{align} x[x := N] &\equiv N\\\ y[x := N] &\equiv y\text{, if } x \neq y \end{align} }[/math]

[math]\displaystyle{ \begin{align} (M_{1} \ M_{2})[x := N] &\equiv (M_{1}[x := N]) \ (M_{2}[x := N])\\\ (\lambda x . M)[x := N] &\equiv \lambda x . M\\\ (\lambda y . M)[x := N] &\equiv \lambda y . (M[x := N])\text{, if }x \neq y\text{, provided }y \notin FV(N) \end{align} }[/math]

To substitute into a lambda abstraction, it is sometimes necessary to α-convert the expression. For example, it is not correct for [math]\displaystyle{ (\lambda x . y)[y := x] }[/math] to result in [math]\displaystyle{ (\lambda x . x) }[/math], because the substituted [math]\displaystyle{ x }[/math] was supposed to be free but ended up being bound. The correct substitution in this case is [math]\displaystyle{ (\lambda z . x) }[/math], up to α-equivalence. Notice that substitution is defined uniquely up to α-equivalence.

#### β-reduction

β-reduction captures the idea of function application. β-reduction is defined in terms of substitution: the β-reduction of [math]\displaystyle{ ((\lambda V . E) \ E') }[/math] is [math]\displaystyle{ E[V := E'] }[/math].

For example, assuming some encoding of [math]\displaystyle{ 2, 7, \times }[/math], we have the following β-reduction: [math]\displaystyle{ ((\lambda n . \ n \times 2) \ 7) \rightarrow 7 \times 2 }[/math].

#### η-reduction

η-reduction expresses the idea of extensionality, which in this context is that two functions are the same if and only if they give the same result for all arguments. η-reduction converts between [math]\displaystyle{ \lambda x . (f x) }[/math] and [math]\displaystyle{ f }[/math] whenever [math]\displaystyle{ x }[/math] does not appear free in [math]\displaystyle{ f }[/math].

### Normalization

Main page: Beta normal form

The purpose of β-reduction is to calculate a value. A value in lambda calculus is a function. So β-reduction continues until the expression looks like a function abstraction.

A lambda expression that cannot be reduced further, by either β-redex, or η-redex is in normal form. Note that alpha-conversion may convert functions. All normal forms that can be converted into each other by α-conversion are defined to be equal. See the main article on Beta normal form for details.

Normal Form Type | Definition.

|

Normal Form | No β- or η-reductions are possible.
Head Normal Form | In the form of a lambda abstraction whose body is not reducible.
Weak Head Normal Form | In the form of a lambda abstraction.

## Syntax definition in BNF

Lambda Calculus has a simple syntax. A lambda calculus program has the syntax of an expression where,

Name | BNF | Description

|
|

Abstraction |

<expression> ::= λ <variable-list> . <expression>

| Anonymous function definition.
Application term |

<expression> ::= <application-term>

Application |

<application-term> ::= <application-term> <item>

| A function call.
Item |

<application-term> ::= <item>

Variable |

<item> ::= <variable>

| E.g. x, y, fact, sum, ...
Grouping |

<item> ::= ( <expression> )

| Bracketed expression.

The variable list is defined as,

<variable-list> ::= <variable> | <variable>, <variable-list>

A variable as used by computer scientists has the syntax,

<variable> ::= <alpha> <extension>
<extension> ::=
<extension> ::= <extension-char> <extension>
<extension-char> ::= <alpha> | <digit> | _

Mathematicians will sometimes restrict a variable to be a single alphabetic character. When using this convention the comma is omitted from the variable list.

A lambda abstraction has a lower precedence than an application, so;

[math]\displaystyle{ \lambda x.y\ z = \lambda x.(y\ z) }[/math]

Applications are left associative;

[math]\displaystyle{ x\ y\ z = (x\ y)\ z }[/math]

An abstraction with multiple parameters is equivalent to multiple abstractions of one parameter.

[math]\displaystyle{ \lambda x.y.z = \lambda x.\lambda y.z }[/math]

where,

* x is a variable
* y is a variable list
* z is an expression

## Definition as mathematical formulas

The problem of how variables may be renamed is difficult. This definition avoids the problem by substituting all names with canonical names, which are constructed based on the position of the definition of the name in the expression. The approach is analogous to what a compiler does, but has been adapted to work within the constraints of mathematics.

### Semantics

The execution of a lambda expression proceeds using the following reductions and transformations,

1. α-conversion - [math]\displaystyle{ \operatorname{alpha-conv}(a) \to \operatorname{canonym}[A, P] = \operatorname{canonym}[a[A], P] }[/math]
2. β-reduction - [math]\displaystyle{ \operatorname{beta-redex}[\lambda p.b\ v] = b[p:=v] }[/math]
3. η-reduction - [math]\displaystyle{ x \not \in \operatorname{FV}(f) \to \operatorname{eta-redex}[\lambda x.(f \ x)] = f }[/math]

where,

* canonym is a renaming of a lambda expression to give the expression standard names, based on the position of the name in the expression.
* Substitution Operator, [math]\displaystyle{ b[p:=v] }[/math] is the substitution of the name [math]\displaystyle{ p }[/math] by the lambda expression [math]\displaystyle{ v }[/math] in lambda expression [math]\displaystyle{ b }[/math].
* Free Variable Set [math]\displaystyle{ \operatorname{FV}(f) }[/math] is the set of variables that do not belong to a lambda abstraction in [math]\displaystyle{ f }[/math].

Execution is performing β-reductions and η-reductions on subexpressions in the canonym of a lambda expression until the result is a lambda function (abstraction) in the normal form.

All α-conversions of a λ-expression are considered to be equivalent.

### Canonym - Canonical Names

Canonym is a function that takes a lambda expression and renames all names canonically, based on their positions in the expression. This might be implemented as,

[math]\displaystyle{ \begin{align} \operatorname{canonym}[L, Q] &= \operatorname{canonym}[L, O, Q] \\\ \operatorname{canonym}[\lambda p.b, M, Q] &= \lambda \operatorname{name}(Q).\operatorname{canonym}[b, M[p:=Q], Q+N] \\\ \operatorname{canonym}[X \ Y, x, Q] &= \operatorname{canonym}[X, x, Q+F] \ \operatorname{canonym}[Y, x, E+S] \\\ \operatorname{canonym}[x, M, Q] &= \operatorname{name}(M[x]) \end{align} }[/math]

Where, N is the string "N", F is the string "F", S is the string "S", + is concatenation, and "name" converts a string into a name

### Map operators

Map from one value to another if the value is in the map. O is the empty map.

1. [math]\displaystyle{ O[x] = x }[/math]
2. [math]\displaystyle{ M[x:=y][x] = y }[/math]
3. [math]\displaystyle{ x \ne z \to M[x:=y][z] = M[z] }[/math]

### Substitution operator

If L is a lambda expression, x is a name, and y is a lambda expression; [math]\displaystyle{ L[x:=y] }[/math] means substitute x by y in L. The rules are,

1. [math]\displaystyle{ (\lambda p.b)[x := y] = \lambda p.b[x := y] }[/math]
2. [math]\displaystyle{ (X \, Y)[x := y] = X[x := y] \, Y[x := y] }[/math]
3. [math]\displaystyle{ z = x \to (z)[x := y] = y }[/math]
4. [math]\displaystyle{ z \ne x \to (z)[x := y] = z }[/math]

Note that rule 1 must be modified if it is to be used on non canonically renamed lambda expressions. See Changes to the substitution operator.

### Free and bound variable sets

The set of free variables of a lambda expression, M, is denoted as FV(M). This is the set of variable names that have instances not bound (used) in a lambda abstraction, within the lambda expression. They are the variable names that may be bound to formal parameter variables from outside the lambda expression.

The set of bound variables of a lambda expression, M, is denoted as BV(M). This is the set of variable names that have instances bound (used) in a lambda abstraction, within the lambda expression.

The rules for the two sets are given below.[5]

[math]\displaystyle{ \mathrm{FV}(M) }[/math] \- Free Variable Set  | Comment  | [math]\displaystyle{ \mathrm{BV}(M) }[/math] \- Bound Variable Set  | Comment

|
|
|

[math]\displaystyle{ \mathrm{FV}(x) = \\{x\\} }[/math] | where x is a variable  | [math]\displaystyle{ \mathrm{BV}(x) = \emptyset }[/math] | where x is a variable
[math]\displaystyle{ \mathrm{FV}(\lambda x.M) = \mathrm{FV}(M) \setminus \\{x\\} }[/math] | Free variables of M excluding x  | [math]\displaystyle{ \mathrm{BV}(\lambda x.M) = \mathrm{BV}(M) \cup \\{x\\} }[/math] | Bound variables of M plus x.
[math]\displaystyle{ \mathrm{FV}(M \ N) = \mathrm{FV}(M) \cup \mathrm{FV}(N) }[/math] | Combine the free variables from the function and the parameter  | [math]\displaystyle{ \mathrm{BV}(M \ N) = \mathrm{BV}(M) \cup \mathrm{BV}(N) }[/math] | Combine the bound variables from the function and the parameter

Usage;

* The Free Variable Set, FV is used above in the definition of the η-reduction.
* The Bound Variable Set, BV, is used in the rule for β-redex of non canonical lambda expression.

### Evaluation strategy

This mathematical definition is structured so that it represents the result, and not the way it gets calculated. However the result may be different between lazy and eager evaluation. This difference is described in the evaluation formulas.

The definitions given here assume that the first definition that matches the lambda expression will be used. This convention is used to make the definition more readable. Otherwise some if conditions would be required to make the definition precise.

Running or evaluating a lambda expression L is,

[math]\displaystyle{ \operatorname{eval}[\operatorname{canonym}[L, Q]] }[/math]

where Q is a name prefix possibly an empty string and eval is defined by,

[math]\displaystyle{ \begin{align} \operatorname{eval}[x\ y] &= \operatorname{eval}[\operatorname{apply}[\operatorname{eval}[x]\ \operatorname{strategy}[y]]] \\\ \operatorname{apply}[(\lambda x.y)\ z] &= \operatorname{canonym}[\operatorname{beta-redex}[(\lambda x.y)\ z], x] \\\ \operatorname{apply}[x] &= x \text{ if x does match the above.}\\\ \operatorname{eval}[\lambda x.(f\ x)] &= \operatorname{eval}[\operatorname{eta-redex}[\lambda x.(f\ x)]] \\\ \operatorname{eval}[L] &= L \\\ \operatorname{lazy}[X] &= X \\\ \operatorname{eager}[X] &= \operatorname{eval}[X] \end{align} }[/math]

Then the evaluation strategy may be chosen as either,

[math]\displaystyle{ \begin{align} \operatorname{strategy} &= \operatorname{lazy} \\\ \operatorname{strategy} &= \operatorname{eager} \end{align} }[/math]

The result may be different depending on the strategy used. Eager evaluation will apply all reductions possible, leaving the result in normal form, while lazy evaluation will omit some reductions in parameters, leaving the result in "weak head normal form".

#### Normal form

All reductions that can be applied have been applied. This is the result obtained from applying eager evaluation.

[math]\displaystyle{ \begin{align} \operatorname{normal}[(\lambda x.y)\ z] &= \operatorname{false} \\\ \operatorname{normal}[\lambda x.(f\ x)] &= \operatorname{false} \\\ \operatorname{normal}[x\ y] &= \operatorname{normal}[x] \land \operatorname{normal}[y] \end{align} }[/math]

In all other cases,

[math]\displaystyle{ \operatorname{normal}[x] = \operatorname{true} }[/math]

#### Weak head normal form

Reductions to the function (the head) have been applied, but not all reductions to the parameter have been applied. This is the result obtained from applying lazy evaluation.

[math]\displaystyle{ \begin{align} \operatorname{whnf}[(\lambda x.y)\ z] &= \operatorname{false} \\\ \operatorname{whnf}[\lambda x.(f\ x)] &= \operatorname{false} \\\ \operatorname{whnf}[x\ y] &= \operatorname{whnf}[x] \end{align} }[/math]

In all other cases,

[math]\displaystyle{ \operatorname{whnf}[x] = \operatorname{true} }[/math]

## Derivation of standard from the math definition

The standard definition of lambda calculus uses some definitions which may be considered as theorems, which can be proved based on the definition as mathematical formulas.

The canonical naming definition deals with the problem of variable identity by constructing a unique name for each variable based on the position of the lambda abstraction for the variable name in the expression.

This definition introduces the rules used in the standard definition and relates explains them in terms of the canonical renaming definition.

### Free and bound variables

The lambda abstraction operator, λ, takes a formal parameter variable and a body expression. When evaluated the formal parameter variable is identified with the value of the actual parameter.

Variables in a lambda expression may either be "bound" or "free". Bound variables are variable names that are already attached to formal parameter variables in the expression.

The formal parameter variable is said to bind the variable name wherever it occurs free in the body. Variable (names) that have already been matched to formal parameter variable are said to be bound. All other variables in the expression are called free.

For example, in the following expression y is a bound variable and x is free: [math]\displaystyle{ \lambda y.x \ x \ y }[/math]. Also note that a variable is bound by its "nearest" lambda abstraction. In the following example the single occurrence of x in the expression is bound by the second lambda: [math]\displaystyle{ \lambda x.y \ (\lambda x.z \ x) }[/math]

### Changes to the substitution operator

In the definition of the Substitution Operator the rule,

* [math]\displaystyle{ (\lambda p.b)[x := y] = \lambda p.b[x := y] }[/math]

must be replaced with,

1. [math]\displaystyle{ (\lambda x.b)[x := y] = \lambda x.b }[/math]
2. [math]\displaystyle{ z \ne x\ \to (\lambda z.b)[x := y] = \lambda z.b[x := y] }[/math]

This is to stop bound variables with the same name being substituted. This would not have occurred in a canonically renamed lambda expression.

For example the previous rules would have wrongly translated,

[math]\displaystyle{ (\lambda x.x \ z)[x:=y] = (\lambda x.y \ z) }[/math]

The new rules block this substitution so that it remains as,

[math]\displaystyle{ (\lambda x.x \ z)[x:=y] = (\lambda x.x \ z) }[/math]

### Transformation

The meaning of lambda expressions is defined by how expressions can be transformed or reduced.[6]

There are three kinds of transformation:

* α-conversion: changing bound variables (alpha);
* β-reduction: applying functions to their arguments (beta), calling functions;
* η-reduction: which captures a notion of extensionality (eta).

We also speak of the resulting equivalences: two expressions are β-equivalent, if they can be β-converted into the same expression, and α/η-equivalence are defined similarly.

The term redex, short for reducible expression, refers to subterms that can be reduced by one of the reduction rules.

#### α-conversion

Alpha-conversion, sometimes known as alpha-renaming,[7] allows bound variable names to be changed. For example, alpha-conversion of [math]\displaystyle{ \lambda x.x }[/math] might give [math]\displaystyle{ \lambda y.y }[/math]. Terms that differ only by alpha-conversion are called α-equivalent.

In an α-conversion, names may be substituted for new names if the new name is not free in the body, as this would lead to the capture of free variables.

[math]\displaystyle{ (y \not \in FV(b) \land a(\lambda x.b) = \lambda y.b[x:=y]) \to \operatorname{alpha-con}(a) }[/math]

Note that the substitution will not recurse into the body of lambda expressions with formal parameter [math]\displaystyle{ x }[/math] because of the change to the substitution operator described above.

See example;

α-conversion  | λ-expression  | Canonically named  | Comment

|
|
|

| [math]\displaystyle{ \lambda z. \lambda y.(z \ y) }[/math] | [math]\displaystyle{ \lambda \operatorname{P}. \lambda \operatorname{PN}.(\operatorname{P} \operatorname{PN}) }[/math] | Original expressions.
correctly rename y to k, (because k is not used in the body)  | [math]\displaystyle{ \lambda z. \lambda k.(z \ k) }[/math] | [math]\displaystyle{ \lambda \operatorname{P}. \lambda \operatorname{PN}.(\operatorname{P} \operatorname{PN}) }[/math] | No change to canonical renamed expression.
naively rename y to z, (wrong because z free in [math]\displaystyle{ \lambda y.(z \ y) }[/math])  | [math]\displaystyle{ \lambda z. \lambda z.(z \ z) }[/math] | [math]\displaystyle{ \lambda \operatorname{P}. \lambda \operatorname{PN}.({\color{Red}\operatorname{PN}} \operatorname{PN}) }[/math] | [math]\displaystyle{ z }[/math] is captured.

#### β-reduction (capture avoiding)

β-reduction captures the idea of function application (also called a function call), and implements the substitution of the actual parameter expression for the formal parameter variable. β-reduction is defined in terms of substitution.

If no variable names are free in the actual parameter and bound in the body, β-reduction may be performed on the lambda abstraction without canonical renaming.

[math]\displaystyle{ (\forall z: z \not \in FV(y) \lor z \not \in BV(b)) \to \operatorname{beta-redex}[\lambda x.b \ y] = b[x:=y] }[/math]

Alpha renaming may be used on [math]\displaystyle{ b }[/math] to rename names that are free in [math]\displaystyle{ y }[/math] but bound in [math]\displaystyle{ b }[/math], to meet the pre-condition for this transformation.

See example;

β-reduction  | λ-expression  | Canonically named  | Comment

|
|
|

| [math]\displaystyle{ (\lambda x.\lambda y.(\lambda z.(\lambda x.z \ x)(\lambda y.z \ y)) (x \ y)) }[/math] | [math]\displaystyle{ (\lambda \operatorname{P}.\lambda \operatorname{PN}.(\lambda \operatorname{PNF}.(\lambda \operatorname{PNFNF}.\operatorname{PNF} \operatorname{PNFNF})(\lambda \operatorname{PNFNS}.\operatorname{PNF} \operatorname{PNFNS})) (\operatorname{P} \operatorname{PN})) }[/math] | Original expressions.
Naive beta 1,  | [math]\displaystyle{ (\lambda x.\lambda y.((\lambda x.(x \ y) x)(\lambda y.(x \ y) y))) }[/math] |  | Canonical  | [math]\displaystyle{ (\lambda \operatorname{P}.\lambda \operatorname{PN}.((\lambda \operatorname{PNF}.({\color{Blue}\operatorname{P}} \operatorname{PN}) \operatorname{PNF})(\lambda \operatorname{PNS}.(\operatorname{P} {\color{Blue}\operatorname{PN}}) \operatorname{PNS}))) }[/math]

|

Natural  | [math]\displaystyle{ (\lambda \operatorname{P}.\lambda \operatorname{PN}.((\lambda \operatorname{PNF}.({\color{Red}\operatorname{PNF}} \operatorname{PN}) \operatorname{PNF})(\lambda \operatorname{PNS}.(\operatorname{P} {\color{Red}\operatorname{PNS})} \operatorname{PNS}))) }[/math]
x (P) and y (PN) have been captured in the substitution.

Alpha rename inner, x -> a, y -> b

| [math]\displaystyle{ (\lambda x.\lambda y.(\lambda z.(\lambda a.z \ a)(\lambda b.z \ b)) (x \ y)) }[/math] | [math]\displaystyle{ (\lambda \operatorname{P}.\lambda \operatorname{PN}.(\lambda \operatorname{PNF}.(\lambda \operatorname{PNFNF}.\operatorname{PNF} \operatorname{PNFNF})(\lambda \operatorname{PNFNS}.\operatorname{PNF} \operatorname{PNFNS})) (\operatorname{P} \operatorname{PN})) }[/math] |
Beta 2,  | [math]\displaystyle{ (\lambda x.\lambda y.((\lambda a.(x \ y) a)(\lambda b.(x \ y) b))) }[/math] |  | Canonical  | [math]\displaystyle{ (\lambda \operatorname{P}.\lambda \operatorname{PN}.((\lambda \operatorname{PNF}.(\operatorname{P} \operatorname{PN}) \operatorname{PNF})(\lambda \operatorname{PNS}.(\operatorname{P} \operatorname{PN}) \operatorname{PNS}))) }[/math]

|

Natural  | [math]\displaystyle{ (\lambda \operatorname{P}.\lambda \operatorname{PN}.((\lambda \operatorname{PNF}.(\operatorname{P} \operatorname{PN}) \operatorname{PNF})(\lambda \operatorname{PNS}.(\operatorname{P} \operatorname{PN}) \operatorname{PNS}))) }[/math]
x and y not captured.

[math]\displaystyle{ \begin{array}{r} ((\lambda x.z \ x)(\lambda y.z \ y))[z := (x \ y)] \\\ ((\lambda a.z \ a)(\lambda b.z \ b))[z := (x \ y)] \end{array} }[/math]

In this example,

1. In the β-redex,
1. The free variables are, [math]\displaystyle{ \operatorname{FV}(x \ y) = \\{x, y\\} }[/math]
2. The bound variables are, [math]\displaystyle{ \operatorname{BV}((\lambda x.z \ x)(\lambda y.z \ y)) = \\{x, y\\} }[/math]
2. The naive β-redex changed the meaning of the expression because x and y from the actual parameter became captured when the expressions were substituted in the inner abstractions.
3. The alpha renaming removed the problem by changing the names of x and y in the inner abstraction so that they are distinct from the names of x and y in the actual parameter.
1. The free variables are, [math]\displaystyle{ \operatorname{FV}(x \ y) = \\{x, y\\} }[/math]
2. The bound variables are, [math]\displaystyle{ \operatorname{BV}((\lambda a.z \ a)(\lambda b.z \ b)) = \\{a, b\\} }[/math]
4. The β-redex then proceeded with the intended meaning.

#### η-reduction

η-reduction expresses the idea of extensionality, which in this context is that two functions are the same if and only if they give the same result for all arguments.

η-reduction may be used without change on lambda expressions that are not canonically renamed.

[math]\displaystyle{ x \not \in \mathrm{FV}(f) \to \text{η-redex}[\lambda x.(f x)] = f }[/math]

The problem with using an η-redex when f has free variables is shown in this example,

Reduction | Lambda expression | β-reduction

|
|

| [math]\displaystyle{ (\lambda x.(\lambda y.y \, x) \, x) \, a }[/math] | [math]\displaystyle{ \lambda a.a \, a }[/math]
Naive η-reduction  | [math]\displaystyle{ (\lambda y.y \, x) \, a }[/math] | [math]\displaystyle{ \lambda a.a \, x }[/math]

This improper use of η-reduction changes the meaning by leaving x in [math]\displaystyle{ \lambda y.y \, x }[/math] unsubstituted.

## References

1. ↑ Barendregt, Hendrik Pieter (1984), The Lambda Calculus: Its Syntax and Semantics, Studies in Logic and the Foundations of Mathematics, 103 (Revised ed.), North Holland, Amsterdam., ISBN 978-0-444-87508-2, http://www.elsevier.com/wps/find/bookdescription.cws_home/501727/description -- Corrections
2. ↑ "Example for Rules of Associativity". Lambda-bound.com. http://www.lambda-bound.com/book/lambdacalc/node27.html.
3. ↑ Selinger, Peter (2008), Lecture Notes on the Lambda Calculus, 0804, Department of Mathematics and Statistics, University of Ottawa, p. 9, Bibcode: 2008arXiv0804.3434S, http://www.mathstat.dal.ca/~selinger/papers/lambdanotes.pdf
4. ↑ "Example for Rule of Associativity". Lambda-bound.com. http://www.lambda-bound.com/book/lambdacalc/node25.html.
5. ↑ 5.0 5.1 Barendregt, Henk; Barendsen, Erik (March 2000), Introduction to Lambda Calculus, ftp://ftp.cs.ru.nl/pub/CompMath.Found/lambda.pdf
6. ↑ 6.0 6.1 de Queiroz, Ruy J.G.B. "A Proof-Theoretic Account of Programming and the Role of Reduction Rules." Dialectica 42(4), pages 265-282, 1988.
7. ↑ 7.0 7.1 Turbak, Franklyn; Gifford, David (2008), Design concepts in programming languages, MIT press, p. 251, ISBN 978-0-262-20175-9

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Lambda calculus definition. Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Lambda_calculus_definition&oldid=3378911"