Lambda calculus (also written as ''λ''-calculus) is a
formal system in
mathematical logic for expressing
computation
Computation is any type of arithmetic or non-arithmetic calculation that follows a well-defined model (e.g., an algorithm).
Mechanical or electronic devices (or, historically, people) that perform computations are known as ''computers''. An es ...
based on function
abstraction and
application
Application may refer to:
Mathematics and computing
* Application software, computer software designed to help the user to perform specific tasks
** Application layer, an abstraction layer that specifies protocols and interface methods used in a c ...
using variable
binding and
substitution
Substitution may refer to:
Arts and media
*Chord substitution, in music, swapping one chord for a related one within a chord progression
* Substitution (poetry), a variation in poetic scansion
* "Substitution" (song), a 2009 song by Silversun Pi ...
. It is a universal
model of computation that can be used to simulate any
Turing machine. It was introduced by the mathematician
Alonzo Church in the 1930s as part of his research into the
foundations of mathematics.
Lambda calculus consists of constructing
§ lambda terms and performing
§ reduction operations on them. In the simplest form of lambda calculus, terms are built using only the following rules:
*
– variable, a character or string representing a parameter or mathematical/logical value.
*
– abstraction, function definition (
is a lambda term). The variable
becomes
bound in the expression.
*
– application, applying a function
to an argument
.
and
are lambda terms.
The reduction operations include:
*
– α-conversion, renaming the bound variables in the expression. Used to avoid
name collisions.
*
– β-reduction, replacing the bound variables with the argument expression in the body of the abstraction.
If
De Bruijn indexing is used, then α-conversion is no longer required as there will be no name collisions. If
repeated application of the reduction steps eventually terminates, then by the
Church–Rosser theorem it will produce a
β-normal form.
Variable names are not needed if using a universal lambda function, such as
Iota and Jot
In formal language theory and computer science, Iota and Jot (from Greek iota ι, Hebrew yodh י, the smallest letters in those two alphabets) are languages, extremely minimalist formal systems, designed to be even simpler than other more popular ...
, which can create any function behavior by calling it on itself in various combinations.
Explanation and applications
Lambda calculus is
Turing complete, that is, it is a universal
model of computation that can be used to simulate any
Turing machine. Its namesake, the Greek letter lambda (λ), is used in lambda expressions and lambda terms to denote
binding a variable in a
function.
Lambda calculus may be ''untyped'' or ''typed''. In typed lambda calculus, functions can be applied only if they are capable of accepting the given input's "type" of data. Typed lambda calculi are ''weaker'' than the untyped lambda calculus, which is the primary subject of this article, in the sense that ''typed lambda calculi can express less'' than the untyped calculus can, but on the other hand typed lambda calculi allow more things to be proven; in the
simply typed lambda calculus it is, for example, a theorem that every evaluation strategy terminates for every simply typed lambda-term, whereas evaluation of untyped lambda-terms
§need not terminate. One reason there are many different typed lambda calculi has been the desire to do more (of what the untyped calculus can do) without giving up on being able to prove strong theorems about the calculus.
Lambda calculus has applications in many different areas in
mathematics
Mathematics is an area of knowledge that includes the topics of numbers, formulas and related structures, shapes and the spaces in which they are contained, and quantities and their changes. These topics are represented in modern mathematics ...
,
philosophy
Philosophy (from , ) is the systematized study of general and fundamental questions, such as those about existence, reason, knowledge, values, mind, and language. Such questions are often posed as problems to be studied or resolved. Some ...
,
linguistics, and
computer science. Lambda calculus has played an important role in the development of the
theory of programming languages.
Functional programming languages implement lambda calculus. Lambda calculus is also a current research topic in
category theory
Category theory is a general theory of mathematical structures and their relations that was introduced by Samuel Eilenberg and Saunders Mac Lane in the middle of the 20th century in their foundational work on algebraic topology. Nowadays, cate ...
.
History
The lambda calculus was introduced by mathematician
Alonzo Church in the 1930s as part of an investigation into the
foundations of mathematics. The original system was shown to be
logically inconsistent in 1935 when
Stephen Kleene and
J. B. Rosser
John Barkley Rosser Sr. (December 6, 1907 – September 5, 1989) was an American logician, a student of Alonzo Church, and known for his part in the Church–Rosser theorem, in lambda calculus. He also developed what is now called the " Rosser si ...
developed the
Kleene–Rosser paradox.
Subsequently, in 1936 Church isolated and published just the portion relevant to computation, what is now called the untyped lambda calculus.
In 1940, he also introduced a computationally weaker, but logically consistent system, known as the
simply typed lambda calculus.
Until the 1960s when its relation to programming languages was clarified, the lambda calculus was only a formalism. Thanks to
Richard Montague and other linguists' applications in the semantics of natural language, the lambda calculus has begun to enjoy a respectable place in both linguistics
and computer science.
Origin of the lambda symbol
There is some uncertainty over the reason for Church's use of the Greek letter
lambda (λ) as the notation for function-abstraction in the lambda calculus, perhaps in part due to conflicting explanations by Church himself. According to Cardone and Hindley (2006):
By the way, why did Church choose the notation “λ”? In n unpublished 1964 letter to Harald Dicksonhe stated clearly that it came from the notation “” used for class-abstraction by Whitehead and Russell, by first modifying “” to “” to distinguish function-abstraction from class-abstraction, and then changing “” to “λ” for ease of printing.
This origin was also reported in osser, 1984, p.338 On the other hand, in his later years Church told two enquirers that the choice was more accidental: a symbol was needed and λ just happened to be chosen.
Dana Scott has also addressed this question in various public lectures.
Scott recounts that he once posed a question about the origin of the lambda symbol to Church's former student and son-in-law John W. Addison Jr., who then wrote his father-in-law a postcard:
Dear Professor Church,
Russell had the iota operator, Hilbert had the epsilon operator. Why did you choose lambda for your operator?
According to Scott, Church's entire response consisted of returning the postcard with the following annotation: "
eeny, meeny, miny, moe".
Informal description
Motivation
Computable functions are a fundamental concept within computer science and mathematics. The lambda calculus provides simple
semantics for computation which are useful for formally studying properties of computation. The lambda calculus incorporates two simplifications that make its semantics simple.
The first simplification is that the lambda calculus treats functions "anonymously;" it does not give them explicit names. For example, the function
:
can be rewritten in ''anonymous form'' as
:
(which is read as "a
tuple of and is
mapped to
"). Similarly, the function
:
can be rewritten in anonymous form as
:
where the input is simply mapped to itself.
The second simplification is that the lambda calculus only uses functions of a single input. An ordinary function that requires two inputs, for instance the
function, can be reworked into an equivalent function that accepts a single input, and as output returns ''another'' function, that in turn accepts a single input. For example,
:
can be reworked into
:
This method, known as
currying
In mathematics and computer science, currying is the technique of translating the evaluation of a function that takes multiple arguments into evaluating a sequence of functions, each with a single argument. For example, currying a function f that ...
, transforms a function that takes multiple arguments into a chain of functions each with a single argument.
Function application
In mathematics, function application is the act of applying a function to an argument from its domain so as to obtain the corresponding value from its range. In this sense, function application can be thought of as the opposite of function abst ...
of the
function to the arguments (5, 2), yields at once
:
:
:
,
whereas evaluation of the curried version requires one more step
:
:
// the definition of
has been used with
in the inner expression. This is like β-reduction.
:
// the definition of
has been used with
. Again, similar to β-reduction.
:
to arrive at the same result.
The lambda calculus
The lambda calculus consists of a language of lambda terms, that are defined by a certain formal syntax, and a set of transformation rules for manipulating the lambda terms. These transformation rules can be viewed as an
equational theory or as an
operational definition.
As described above, having no names, all functions in the lambda calculus are anonymous functions. They only accept one input variable, so
currying
In mathematics and computer science, currying is the technique of translating the evaluation of a function that takes multiple arguments into evaluating a sequence of functions, each with a single argument. For example, currying a function f that ...
is used to implement functions of several variables.
Lambda terms
The syntax of the lambda calculus defines some expressions as valid lambda calculus expressions and some as invalid, just as some strings of characters are valid
C programs and some are not. A valid lambda calculus expression is called a "lambda term".
The following three rules give an
inductive definition
In mathematics and computer science, a recursive definition, or inductive definition, is used to define the elements in a set in terms of other elements in the set ( Aczel 1977:740ff). Some examples of recursively-definable objects include fact ...
that can be applied to build all syntactically valid lambda terms:
* variable is itself a valid lambda term.
*if is a lambda term, and is a variable, then
is a lambda term (called an abstraction);
*if and are lambda terms, then
is a lambda term (called an application).
Nothing else is a lambda term. Thus a lambda term is valid if and only if it can be obtained by repeated application of these three rules. However, some parentheses can be omitted according to certain rules. For example, the outermost parentheses are usually not written. See ''
Notation'', below.
An abstraction
denotes an
§ anonymous function that takes a single input and returns . For example,
is an abstraction for the function
using the term
for . The name
is superfluous when using abstraction.
binds the variable in the term . The definition of a function with an abstraction merely "sets up" the function but does not invoke it.
An application
represents the application of a function to an input , that is, it represents the act of calling function on input to produce
.
There is no concept in lambda calculus of variable declaration. In a definition such as
(i.e.
), in lambda calculus is a variable that is not yet defined. The abstraction
is syntactically valid, and represents a function that adds its input to the yet-unknown .
Parentheses may be used and may be needed to disambiguate terms. For example,
#
which is of form
—an abstraction, and
#
which is of form
—an application. The examples 1 and 2 denote different terms; however example 1 is a function definition, while example 2 is an application.
Here, example 1 defines a function
, where
is
, the result of applying
to x, while example 2 is
;
is the lambda term
to be applied to the input N. Both examples 1 and 2 would evaluate to the
identity function .
Functions that operate on functions
In lambda calculus, functions are taken to be '
first class values', so functions may be used as the inputs, or be returned as outputs from other functions.
For example,
represents the
identity function,
, and
represents the identity function applied to
. Further,
represents the constant function
, the function that always returns
, no matter the input. In lambda calculus, function application is regarded as
left-associative, so that
means
.
There are several notions of "equivalence" and "reduction" that allow lambda terms to be "reduced" to "equivalent" lambda terms.
Alpha equivalence
A basic form of equivalence, definable on lambda terms, is alpha equivalence. It captures the intuition that the particular choice of a bound variable, in an abstraction, does not (usually) matter.
For instance,
and
are alpha-equivalent lambda terms, and they both represent the same function (the identity function).
The terms
and
are not alpha-equivalent, because they are not bound in an abstraction.
In many presentations, it is usual to identify alpha-equivalent lambda terms.
The following definitions are necessary in order to be able to define β-reduction:
Free variables
The free variables
of a term are those variables not bound by an abstraction. The set of free variables of an expression is defined inductively:
* The free variables of
are just
* The
set of free variables of
is the set of free variables of
, but with
removed
* The
set of free variables of
is the union of the set of free variables of
and the set of free variables of
.
For example, the lambda term representing the identity
has no free variables, but the function
has a single free variable,
.
Capture-avoiding substitutions
A systematic change in variables to avoid capture of a free variable can introduce error, in a functional programming language where functions are first class citizens.
Suppose
,
and
are lambda terms and
and
are variables.
The notation