HOME

TheInfoList



OR:

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.


Standard definition

This formal definition was given by
Alonzo Church Alonzo Church (June 14, 1903 – August 11, 1995) was an American mathematician, computer scientist, logician, philosopher, professor and editor who made major contributions to mathematical logic and the foundations of theoretical computer scien ...
.


Definition

Lambda expressions are composed of * variables v_, v_, ..., v_, ... * the abstraction symbols lambda '\lambda ' and dot '.' * parentheses ( ) The set of lambda expressions, \Lambda , can be defined inductively: #If x is a variable, then x \in \Lambda #If x is a variable and M \in \Lambda , then (\lambda x . M) \in \Lambda #If M, N \in \Lambda , then (M \ N) \in \Lambda Instances of rule 2 are known as abstractions and instances of rule 3 are known as applications.


Notation

To keep the notation of lambda expressions uncluttered, the following conventions are usually applied. * Outermost parentheses are dropped: M \ N instead of (M \ N) * Applications are assumed to be left-associative: M \ N \ P may be written instead of ((M \ N) \ P) * The body of an abstraction extends as far right as possible: \lambda x . M \ N means \lambda x . (M \ N) and not (\lambda x . M) \ N * A sequence of abstractions is contracted: \lambda x . \lambda y . \lambda z . N is abbreviated as \lambda x y z . N


Free and bound variables

The abstraction operator, \lambda , 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 y is a bound variable and x is free: \lambda y . x \ x \ y. Also note that a variable is bound by its "nearest" abstraction. In the following example the single occurrence of x in the expression is bound by the second lambda: \lambda x . y (\lambda x . z \ x) The set of ''free variables'' of a lambda expression, M, is denoted as \operatorname(M) and is defined by recursion on the structure of the terms, as follows: # \operatorname(x) = \, where x is a variable # \operatorname(\lambda x . M) = \operatorname(M) \backslash \ # \operatorname(M \ N) = \operatorname(M) \cup \operatorname(N) 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. 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.
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, (\lambda x . M) \ N is a β-redex in expressing the substitution of N for x in M; if x is not free in M, \lambda x . M \ x 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 M := N/math> and M.


α-conversion

Alpha-conversion, sometimes known as alpha-renaming, allows bound variable names to be changed. For example, alpha-conversion of \lambda x . x might yield \lambda y . y. 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 to the same abstraction. For example, an alpha-conversion of \lambda x . \lambda x . x could result in \lambda y . \lambda x . x, but it could ''not'' result in \lambda y . \lambda x . y. 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 x with y in \lambda x . \lambda y . x, we get \lambda y . \lambda y . y, 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 mask is an object normally worn on the face, typically for protection, disguise, performance, or entertainment and often they have been employed for rituals and rights. Masks have been used since antiquity for both ceremonial and practi ...
a name in a containing
scope Scope or scopes may refer to: People with the surname * Jamie Scope (born 1986), English footballer * John T. Scopes (1900–1970), central figure in the Scopes Trial regarding the teaching of evolution Arts, media, and entertainment * Cinem ...
(see alpha renaming to make name resolution trivial).


= Substitution

= Substitution, written E := R/math>, is the process of replacing all free occurrences of the variable V in the expression E with expression R. 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). : \begin x := N&\equiv N\\ y := N&\equiv y\text x \neq y \end :\begin (M_ \ M_) := N&\equiv (M_ := N \ (M_ := N\\ (\lambda x . M) := N&\equiv \lambda x . M\\ (\lambda y . M) := N&\equiv \lambda y . (M := N\textx \neq y\texty \notin FV(N) \end To substitute into a lambda abstraction, it is sometimes necessary to α-convert the expression. For example, it is not correct for (\lambda x . y) := x/math> to result in (\lambda x . x), because the substituted x was supposed to be free but ended up being bound. The correct substitution in this case is (\lambda z . x), 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 ((\lambda V . E) \ E') is E := E'/math>. For example, assuming some encoding of 2, 7, \times , we have the following β-reduction: ((\lambda n . \ n \times 2) \ 7) \rightarrow 7 \times 2.


η-reduction

η-reduction expresses the idea of
extensionality In logic, extensionality, or extensional equality, refers to principles that judge objects to be equal if they have the same external properties. It stands in contrast to the concept of intensionality, which is concerned with whether the internal ...
, which in this context is that two functions are the same
if and only if In logic and related fields such as mathematics and philosophy, "if and only if" (shortened as "iff") is a biconditional logical connective between statements, where either both statements are true or both are false. The connective is b ...
they give the same result for all arguments. η-reduction converts between \lambda x . (f x) and f whenever x does not appear free in f.


Normalization

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.


Syntax definition in BNF

Lambda Calculus has a simple syntax. A lambda calculus program has the syntax of an expression where, The variable list is defined as, := , , A variable as used by computer scientists has the syntax, ::= ::= ::= ::= , , _ 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; : \lambda x.y\ z = \lambda x.(y\ z) Applications are left associative; : x\ y\ z = (x\ y)\ z An abstraction with multiple parameters is equivalent to multiple abstractions of one parameter. : \lambda x.y.z = \lambda x.\lambda y.z 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, # α-conversion - \operatorname(a) \to \operatorname
, P The comma is a punctuation mark that appears in several variants in different languages. It has the same shape as an apostrophe or single closing quotation mark () in many typefaces, but it differs from them in being placed on the baseline ...
= \operatorname [A_P.html"_;"title=".html"_;"title="[A">[A_P">.html"_;"title="[A">[A_P #_β-reduction_-_\operatorname[\lambda_p.b\_v.html" ;"title="">[A_P.html" ;"title=".html" ;"title="[A">[A P">.html" ;"title="[A">[A P # β-reduction - \operatorname[\lambda p.b\ v">">[A_P.html" ;"title=".html" ;"title="[A">[A P">.html" ;"title="[A">[A P # β-reduction - \operatorname[\lambda p.b\ v= b :=v # η-reduction - x \not \in \operatorname(f) \to \operatorname[\lambda x.(f \ x)] = f where, * #Canonym - Canonical Names, 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, b :=v is the substitution of the name p by the lambda expression v in lambda expression b. * Free Variable Set \operatorname(f) is the set of variables that do not belong to a lambda abstraction in f. 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, : \begin \operatorname
, Q The comma is a punctuation mark that appears in several variants in different languages. It has the same shape as an apostrophe or single closing quotation mark () in many typefaces, but it differs from them in being placed on the baseline o ...
&= \operatorname , O, Q\\ \operatorname lambda p.b, M, Q&= \lambda \operatorname(Q).\operatorname ,_M[p:=Q_Q+N.html"_;"title=":=Q.html"_;"title=",_M[p:=Q">,_M[p:=Q_Q+N">:=Q.html"_;"title=",_M[p:=Q">,_M[p:=Q_Q+N\\ \operatorname[X_\__Y,_x,_Q.html" ;"title=":=Q">,_M[p:=Q_Q+N.html" ;"title=":=Q.html" ;"title=", M[p:=Q">, M[p:=Q Q+N">:=Q.html" ;"title=", M[p:=Q">, M[p:=Q Q+N\\ \operatorname[X \ Y, x, Q">:=Q">,_M[p:=Q_Q+N.html" ;"title=":=Q.html" ;"title=", M[p:=Q">, M[p:=Q Q+N">:=Q.html" ;"title=", M[p:=Q">, M[p:=Q Q+N\\ \operatorname[X \ Y, x, Q&= \operatorname[X, x, Q+F] \ \operatorname[Y, x, E+S] \\ \operatorname[x, M, Q] &= \operatorname(M[x]) \end 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. # O = x # M :=y= y # x \ne z \to M :=yz] = M


Substitution operator

If L is a lambda expression, x is a name, and y is a lambda expression; L :=y/math> means substitute x by y in L. The rules are, # (\lambda p.b) := y= \lambda p.b := y # (X \, Y) := y= X := y\, Y := y # z = x \to (z) := y= y # z \ne x \to (z) := y= z 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. 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, : \operatorname operatorname[L_Q.html" ;"title=".html" ;"title="operatorname[L">operatorname[L Q">.html" ;"title="operatorname[L">operatorname[L Q where ''Q'' is a name prefix possibly an empty string and ''eval'' is defined by, : \begin \operatorname \ y&= \operatorname[\operatorname[\operatorname[x]\ \operatorname[y] \\ \operatorname \lambda x.y)\ z&= \operatorname[\operatorname[(\lambda x.y)\ z], x] \\ \operatorname &= x \text\\ \operatorname lambda x.(f\ x)&= \operatorname operatorname[\lambda_x.(f\_x)_\\ \operatorname[L.html" ;"title="lambda_x.(f\_x).html" ;"title="operatorname[\lambda x.(f\ x)">operatorname[\lambda x.(f\ x) \\ \operatorname[L">lambda_x.(f\_x).html" ;"title="operatorname[\lambda x.(f\ x)">operatorname[\lambda x.(f\ x) \\ \operatorname[L&= L \\ \operatorname[X] &= X \\ \operatorname[X] &= \operatorname[X] \end Then the evaluation strategy may be chosen as either, : \begin \operatorname &= \operatorname \\ \operatorname &= \operatorname \end 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. : \begin \operatorname \lambda x.y)\ z&= \operatorname \\ \operatorname lambda x.(f\ x)&= \operatorname \\ \operatorname \ y&= \operatorname \land \operatorname \end In all other cases, : \operatorname = \operatorname


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. : \begin \operatorname \lambda x.y)\ z&= \operatorname \\ \operatorname \ y&= \operatorname \end In all other cases, : \operatorname = \operatorname


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: \lambda y.x \ x \ y. 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: \lambda x.y \ (\lambda x.z \ x)


Changes to the substitution operator

In the definition of the Substitution Operator the rule, * (\lambda p.b) := y= \lambda p.b := y must be replaced with, # (\lambda x.b) := y= \lambda x.b # z \ne x\ \to (\lambda z.b) := y= \lambda z.b := y 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, :(\lambda x.x \ z) :=y= (\lambda x.y \ z) The new rules block this substitution so that it remains as, :(\lambda x.x \ z) :=y= (\lambda x.x \ z)


Transformation

The meaning of lambda expressions is defined by how expressions can be transformed or reduced. 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, allows bound variable names to be changed. For example, alpha-conversion of \lambda x.x might give \lambda y.y. 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 In mathematics, and in other disciplines involving formal languages, including mathematical logic and computer science, a free variable is a notation (symbol) that specifies places in an expression where substitution may take place and is not ...
. :(y \not \in FV(b) \land a(\lambda x.b) = \lambda y.b :=y \to \operatorname(a) Note that the substitution will not recurse into the body of lambda expressions with formal parameter x because of the change to the substitution operator described above. See example;


β-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 Bound or bounds may refer to: Mathematics * Bound variable * Upper and lower bounds, observed limits of mathematical functions Physics * Bound state, a particle that has a tendency to remain localized in one or more regions of space Geography *B ...
in the body, β-reduction may be performed on the lambda abstraction without canonical renaming. : (\forall z: z \not \in FV(y) \lor z \not \in BV(b)) \to \operatorname lambda x.b \ y= b :=y Alpha renaming may be used on b to rename names that are free in y but bound in b, to meet the pre-condition for this transformation. See example; :\begin ((\lambda x.z \ x)(\lambda y.z \ y)) := (x \ y)\\ ((\lambda a.z \ a)(\lambda b.z \ b)) := (x \ y) \end In this example, # In the β-redex, ## The free variables are, \operatorname(x \ y) = \ ## The bound variables are, \operatorname((\lambda x.z \ x)(\lambda y.z \ y)) = \ # 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. # 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. ## The free variables are, \operatorname(x \ y) = \ ## The bound variables are, \operatorname((\lambda a.z \ a)(\lambda b.z \ b)) = \ # The β-redex then proceeded with the intended meaning.


η-reduction

η-reduction expresses the idea of
extensionality In logic, extensionality, or extensional equality, refers to principles that judge objects to be equal if they have the same external properties. It stands in contrast to the concept of intensionality, which is concerned with whether the internal ...
, which in this context is that two functions are the same
if and only if In logic and related fields such as mathematics and philosophy, "if and only if" (shortened as "iff") is a biconditional logical connective between statements, where either both statements are true or both are false. The connective is b ...
they give the same result for all arguments. η-reduction may be used without change on lambda expressions that are not canonically renamed. : x \not \in \mathrm(f) \to \text lambda x.(f x)= f The problem with using an η-redex when f has free variables is shown in this example, This improper use of η-reduction changes the meaning by leaving in \lambda y.y \, x unsubstituted.


References

{{reflist Lambda calculus