Lambda Calculus (Computer Science)
Lambda Calculus is a formal definition for expressing functional computational operations based on variable binding and substitution.
It was introduced by Alonzo Church resulting from his studies on the foundation of mathematics and computation.
Notation
Term
The set of -calculus terms is defined by
A term can be a variable (e.g., ), the application of one term to another term , and an abstraction of a variable from a term . Furthermore, the -calculus allows for using parentheses for structuring terms.
Application
is an application. It is the application of the term to an argument .
Abstraction
is an abstraction and represents a bound function with the parameter and the function body . is bound in .
is also called an anonymous function. It has no name and is simply defined through the formal parameter x
, prefixed with the -symbol. A dot .
separates the formal parameter from the function body . If contains an , this is bound to the formal parameter .
Sequences of formal parameters may be collapsed:
The anonymous function from above can be implemented in Haskell:
\x -> x + 1
The leading backslash ought to remind one of the Lambda-symbol: "In Haskell source code, the Greek letter lambda is replaced by a backslash character ('\') instead [...]" [Haskell Wiki]
In JavaScript, the anonymous function can be implemented like this:
// traditional
(function(x) {return x + 1;})
// arrow function
x => x + 1
Bound Variables
In a Lambda term we call the formal parameter the binder, and say that the subterm is in the scope of the binder: Occurrences of in are bound.
In an informal sense, is a local variable in the function-body .
The set of Bound Variables in a Lambda Calculus-term are defined by:
In mathematics, bound variables are also known:
Free Variables
The set of Free Variables in a Lambda Calculus-term are defined by:
: x is a free variable.
: The free variables in the application are the union of all free variables of all sub-terms.
: The free variables in the abstraction are the free variables of the body of the abstraction, minus any variable bound by the parameters of the abstraction.
A free variable is a variable that is not bound in a term . The following would implement an anonymous function where the variable is bound in the function body, and is a free variable:
const y = 1;
(x => x + y)(5);
let y = 1
(\x -> x + y)(5)
β-Reduction
Lambda calculus-terms can be brought into -normal-form by applying -reduction - that is, informal, evaluating a term by applying arguments to it.
Here, is a term that gets applied to another term , and is called the -redex. It gets reduced to , the reduct: All occurrences of in are replaced with .
Examples
- The -normal-form of is
- The -normal-form of is
References: