In
mathematical logic
Mathematical logic is the study of Logic#Formal logic, formal logic within mathematics. Major subareas include model theory, proof theory, set theory, and recursion theory (also known as computability theory). Research in mathematical logic com ...
, the lambda calculus (also written as ''λ''-calculus) is a
formal system
A formal system is an abstract structure and formalization of an axiomatic system used for deducing, using rules of inference, theorems from axioms.
In 1921, David Hilbert proposed to use formal systems as the foundation of knowledge in ma ...
for expressing
computation
A computation is any type of arithmetic or non-arithmetic calculation that is well-defined. Common examples of computation are mathematical equation solving and the execution of computer algorithms.
Mechanical or electronic devices (or, hist ...
based on function
abstraction
Abstraction is a process where general rules and concepts are derived from the use and classifying of specific examples, literal (reality, real or Abstract and concrete, concrete) signifiers, first principles, or other methods.
"An abstraction" ...
and
application using variable
binding and
substitution. Untyped lambda calculus, the topic of this article, is a
universal machine, a
model of computation
In computer science, and more specifically in computability theory and computational complexity theory, a model of computation is a model which describes how an output of a mathematical function is computed given an input. A model describes how ...
that can be used to simulate any
Turing machine
A Turing machine is a mathematical model of computation describing an abstract machine that manipulates symbols on a strip of tape according to a table of rules. Despite the model's simplicity, it is capable of implementing any computer algori ...
(and vice versa). It was introduced by the mathematician
Alonzo Church
Alonzo Church (June 14, 1903 – August 11, 1995) was an American computer scientist, mathematician, logician, and philosopher who made major contributions to mathematical logic and the foundations of theoretical computer science. He is bes ...
in the 1930s as part of his research into the
foundations of mathematics
Foundations of mathematics are the mathematical logic, logical and mathematics, mathematical framework that allows the development of mathematics without generating consistency, self-contradictory theories, and to have reliable concepts of theo ...
. In 1936, Church found a formulation which was
logically consistent, and documented it in 1940.
Lambda calculus consists of constructing
lambda terms and performing
reduction operations on them. A term is defined as any valid lambda calculus expression. In the simplest form of lambda calculus, terms are built using only the following rules:
#
: A
variable is a character or string representing a parameter.
#
: A
lambda abstraction is a function definition, taking as input the bound variable
(between the λ and the punctum/dot .) and returning the body
.
#
: An
application, applying a function
to an argument
. Both
and
are lambda terms.
The reduction operations include:
*
:
α-conversion
In mathematical logic, the lambda calculus (also written as ''λ''-calculus) is a formal system for expressing computation based on function abstraction and application using variable binding and substitution. Untyped lambda calculus, the topic ...
, renaming the bound variables in the expression. Used to avoid
name collision
In computer programming, a name collision is the nomenclature problem that occurs when the same variable name is used for different things in two separate areas that are joined, merged, or otherwise go from occupying separate namespaces to shari ...
s.
*
:
β-reduction
In mathematical logic, the lambda calculus (also written as ''λ''-calculus) is a formal system for expressing computation based on function abstraction and application using variable binding and substitution. Untyped lambda calculus, the topic ...
, replacing the bound variables with the argument expression in the body of the abstraction.
If
De Bruijn index
In mathematical logic, the de Bruijn index is a tool invented by the Dutch mathematician Nicolaas Govert de Bruijn for representing terms of lambda calculus without naming the bound variables. Terms written using these indices are invariant with ...
ing 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
In lambda calculus, the Church–Rosser theorem states that, when applying reduction rules to terms, the ordering in which the reductions are chosen does not make a difference to the eventual result.
More precisely, if there are two distinct r ...
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 popula ...
, which can create any function behavior by calling it on itself in various combinations.
Explanation and applications
Lambda calculus is
Turing complete
Alan Mathison Turing (; 23 June 1912 – 7 June 1954) was an English mathematician, computer scientist, logician, cryptanalyst, philosopher and theoretical biologist. He was highly influential in the development of theoretical comput ...
, that is, it is a universal
model of computation
In computer science, and more specifically in computability theory and computational complexity theory, a model of computation is a model which describes how an output of a mathematical function is computed given an input. A model describes how ...
that can be used to simulate any
Turing machine
A Turing machine is a mathematical model of computation describing an abstract machine that manipulates symbols on a strip of tape according to a table of rules. Despite the model's simplicity, it is capable of implementing any computer algori ...
. 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 strictly ''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. On the other hand, more things can be proven with typed lambda calculi. For example, in
simply typed lambda calculus
The simply typed lambda calculus (), a form
of type theory, is a typed interpretation of the lambda calculus with only one type constructor () that builds function types. It is the canonical and simplest example of a typed lambda calculus. The ...
, it is a theorem that every evaluation strategy terminates for every simply typed lambda-term, whereas evaluation of untyped lambda-terms need not terminate (see
below). 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 a field of study that discovers and organizes methods, Mathematical theory, theories and theorems that are developed and Mathematical proof, proved for the needs of empirical sciences and mathematics itself. There are many ar ...
,
philosophy
Philosophy ('love of wisdom' in Ancient Greek) is a systematic study of general and fundamental questions concerning topics like existence, reason, knowledge, Value (ethics and social sciences), value, mind, and language. It is a rational an ...
,
linguistics
Linguistics is the scientific study of language. The areas of linguistic analysis are syntax (rules governing the structure of sentences), semantics (meaning), Morphology (linguistics), morphology (structure of words), phonetics (speech sounds ...
, and
computer science
Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
. Lambda calculus has played an important role in the development of the
theory
A theory is a systematic and rational form of abstract thinking about a phenomenon, or the conclusions derived from such thinking. It involves contemplative and logical reasoning, often supported by processes such as observation, experimentation, ...
of
programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
s.
Functional programming
In computer science, functional programming is a programming paradigm where programs are constructed by Function application, applying and Function composition (computer science), composing Function (computer science), functions. It is a declarat ...
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. It was introduced by Samuel Eilenberg and Saunders Mac Lane in the middle of the 20th century in their foundational work on algebraic topology. Category theory ...
.
History
Lambda calculus was introduced by mathematician
Alonzo Church
Alonzo Church (June 14, 1903 – August 11, 1995) was an American computer scientist, mathematician, logician, and philosopher who made major contributions to mathematical logic and the foundations of theoretical computer science. He is bes ...
in the 1930s as part of an investigation into the
foundations of mathematics
Foundations of mathematics are the mathematical logic, logical and mathematics, mathematical framework that allows the development of mathematics without generating consistency, self-contradictory theories, and to have reliable concepts of theo ...
. The original system was shown to be
logically inconsistent in 1935 when
Stephen Kleene
Stephen Cole Kleene ( ; January 5, 1909 – January 25, 1994) was an American mathematician. One of the students of Alonzo Church, Kleene, along with Rózsa Péter, Alan Turing, Emil Post, and others, is best known as a founder of the branch of ...
and
J. B. Rosser developed the
Kleene–Rosser paradox
In mathematics, the Kleene–Rosser paradox is a paradox that shows that certain systems of formal logic are inconsistent, in particular the version of Haskell Curry's combinatory logic introduced in 1930, and Alonzo Church's original lambda ...
.
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
The simply typed lambda calculus (), a form
of type theory, is a typed interpretation of the lambda calculus with only one type constructor () that builds function types. It is the canonical and simplest example of a typed lambda calculus. The ...
.
Until the 1960s when its relation to programming languages was clarified, the lambda calculus was only a formalism. Thanks to
Richard Montague
Richard Merritt Montague (September 20, 1930 – March 7, 1971) was an American mathematician and philosopher who made contributions to mathematical logic and the philosophy of language. He is known for proposing Montague grammar to formalize th ...
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 ''λ'' symbol
There is some uncertainty over the reason for Church's use of the Greek letter
lambda
Lambda (; uppercase , lowercase ; , ''lám(b)da'') is the eleventh letter of the Greek alphabet, representing the voiced alveolar lateral approximant . In the system of Greek numerals, lambda has a value of 30. Lambda is derived from the Phoen ...
(λ) 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
Dana Stewart Scott (born October 11, 1932) is an American logician who is the emeritus Hillman University Professor of Computer Science, Philosophy, and Mathematical Logic at Carnegie Mellon University; he is now retired and lives in Berkeley, C ...
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 function
Computable functions are the basic objects of study in computability theory. Informally, a function is ''computable'' if there is an algorithm that computes the value of the function for every value of its argument. Because of the lack of a precis ...
s are a fundamental concept within computer science and mathematics. The lambda calculus provides simple
semantics
Semantics is the study of linguistic Meaning (philosophy), meaning. It examines what meaning is, how words get their meaning, and how the meaning of a complex expression depends on its parts. Part of this process involves the distinction betwee ...
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
In mathematics, a tuple is a finite sequence or ''ordered list'' of numbers or, more generally, mathematical objects, which are called the ''elements'' of the tuple. An -tuple is a tuple of elements, where is a non-negative integer. There is o ...
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 a function that takes multiple arguments into a sequence of families of functions, each taking a single argument.
In the prototypical example, one begins with a functi ...
, 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 abs ...
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
An operational definition specifies concrete, replicable procedures designed to represent a construct. In the words of American psychologist S.S. Stevens (1935), "An operation is the performance which we execute in order to make known a concept." F ...
.
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 a function that takes multiple arguments into a sequence of families of functions, each taking a single argument.
In the prototypical example, one begins with a functi ...
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 computer 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. That is, a lambda term is valid if and only if it can be obtained by repeated application of these three rules. For convenience, some parentheses can be omitted when writing a lambda term. For example, the outermost parentheses are usually not written. See
§ Notation, below, for an explicit description of which parentheses are optional. It is also common to extend the syntax presented here with additional operations, which allows making sense of terms such as
The focus of this article is the pure lambda calculus without extensions, but lambda terms extended with arithmetic operations are used for explanatory purposes.
An ''abstraction''
denotes an
§ anonymous function that takes a single input and returns . For example,
is an abstraction representing the function
defined by
using the term
for . The name
is superfluous when using abstraction. The syntax
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
.
A lambda term may refer to a variable that has not been bound, such as the term
(which represents the function definition
). In this term, the variable has not been defined and is considered an unknown. The abstraction
is a syntactically valid term and represents a function that adds its input to the yet-unknown .
Parentheses may be used and might be needed to disambiguate terms. For example,
#
is of form
and is therefore an abstraction, while
#
is of form
and is therefore an application.
The examples 1 and 2 denote different terms, differing only in where the parentheses are placed. They have different meanings: example 1 is a function definition, while example 2 is a function application. The lambda variable is a placeholder in both examples.
Here,
example 1 ''defines'' a function
, where
is
, an anonymous function
, with input
; while example 2,
, is M applied to N, where
is the lambda term
being applied to the input
which is
. Both examples 1 and 2 would evaluate to the
identity function
Graph of the identity function on the real numbers
In mathematics, an identity function, also called an identity relation, identity map or identity transformation, is a function that always returns the value that was used as its argument, unc ...
.
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, the lambda term
represents the
identity function
Graph of the identity function on the real numbers
In mathematics, an identity function, also called an identity relation, identity map or identity transformation, is a function that always returns the value that was used as its argument, unc ...
,
. Further,
represents the ''constant function''
, the function that always returns
, no matter the input. As an example of a function operating on functions, the
function composition
In mathematics, the composition operator \circ takes two function (mathematics), functions, f and g, and returns a new function h(x) := (g \circ f) (x) = g(f(x)). Thus, the function is function application, applied after applying to . (g \c ...
can be defined as
.
There are several notions of "equivalence" and "reduction" that make it possible to "reduce" lambda terms 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
Set, The Set, SET or SETS may refer to:
Science, technology, and mathematics Mathematics
*Set (mathematics), a collection of elements
*Category of sets, the category whose objects and morphisms are sets and total functions, respectively
Electro ...
of free variables of
is the set of free variables of
, but with
removed
* The
set
Set, The Set, SET or SETS may refer to:
Science, technology, and mathematics Mathematics
*Set (mathematics), a collection of elements
*Category of sets, the category whose objects and morphisms are sets and total functions, respectively
Electro ...
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
Suppose
,
and
are lambda terms, and
and
are variables.
The notation