Lambda calculus (also written as ''λ''-calculus) is a
formal system
A formal system is an abstract structure used for inferring theorems from axioms according to a set of rules. These rules, which are used for carrying out the inference of theorems from axioms, are the logical calculus of the formal system.
A form ...
in
mathematical logic
Mathematical logic is the study of logic, formal logic within mathematics. Major subareas include model theory, proof theory, set theory, and recursion theory. Research in mathematical logic commonly addresses the mathematical properties of for ...
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
Abstraction in its main sense is a conceptual process wherein general rules and concepts are derived from the usage and classification of specific examples, literal ("real" or "concrete") signifiers, first principles, or other methods.
"An abstr ...
and
application using variable
binding and
substitution. 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 ...
. It was introduced by the mathematician
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 ...
in the 1930s as part of his research into the
foundations of mathematics
Foundations of mathematics is the study of the philosophical and logical and/or algorithmic basis of mathematics, or, in a broader sense, the mathematical investigation of what underlies the philosophical theories concerning the nature of mathe ...
.
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
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 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 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, 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 red ...
it will produce a
β-normal form.
Variable names are not needed if using a universal lambda function, such as
Iota and Jot, 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. Turing was highly influential in the development of theoretical co ...
, 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
Function or functionality may refer to:
Computing
* Function key, a type of key on computer keyboards
* Function model, a structured representation of processes in a system
* Function object or functor or functionoid, a concept of object-oriente ...
.
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
The simply typed lambda calculus (\lambda^\to), a form
of type theory, is a typed interpretation of the lambda calculus with only one type constructor (\to) that builds function types. It is the canonical and simplest example of a typed lambda c ...
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
Linguistics is the scientific study of human language. It is called a scientific study because it entails a comprehensive, systematic, objective, and precise analysis of all aspects of language, particularly its nature and structure. Linguis ...
, and
computer science
Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
. Lambda calculus has played an important role in the development of the
theory of programming languages.
Functional programming language
In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that ...
s implement lambda calculus. Lambda calculus is also a current research topic in
category theory.
History
The lambda calculus was introduced by mathematician
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 ...
in the 1930s as part of an investigation into the
foundations of mathematics
Foundations of mathematics is the study of the philosophical and logical and/or algorithmic basis of mathematics, or, in a broader sense, the mathematical investigation of what underlies the philosophical theories concerning the nature of mathe ...
. 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 ca ...
.
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 (\lambda^\to), a form
of type theory, is a typed interpretation of the lambda calculus with only one type constructor (\to) that builds function types. It is the canonical and simplest example of a typed lambda c ...
.
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 ...
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
Lambda (}, ''lám(b)da'') is the 11th 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 Phoenician Lamed . Lambda gave rise ...
(λ) 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 Dickson
N, or n, is the fourteenth letter in the Latin alphabet, used in the modern English alphabet, the alphabets of other western European languages and others worldwide. Its name in English is ''en'' (pronounced ), plural ''ens''.
History
...
he 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, Ca ...
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
In formal semantics and philosophy of language, a definite description is a denoting phrase in the form of "the X" where X is a noun-phrase or a singular common noun. The definite description is ''proper'' if X applies to a unique individual or o ...
, Hilbert had the epsilon operator Hilbert's epsilon calculus is an extension of a formal language by the epsilon operator, where the epsilon operator substitutes for quantifiers in that language as a method leading to a proof of consistency for the extended formal language. The ' ...
. 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
"Eeny, meeny, miny, moe"—which can be spelled a number of ways—is a children's counting-out rhyme, used to select a person in games such as tag, or for selecting various other things. It is one of a large group of similar rhymes in which the ...
".
Informal description
Motivation
Computable function
Computable functions are the basic objects of study in computability theory. Computable functions are the formalized analogue of the intuitive notion of algorithms, in the sense that a function is computable if there exists an algorithm that can do ...
s are a fundamental concept within computer science and mathematics. The lambda calculus provides simple
semantics
Semantics (from grc, σημαντικός ''sēmantikós'', "significant") is the study of reference, meaning, or truth. The term can be used to refer to subfields of several distinct disciplines, including philosophy
Philosophy (f ...
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 ordered list (sequence) of elements. An -tuple is a sequence (or ordered list) of elements, where is a non-negative integer. There is only one 0-tuple, referred to as ''the empty tuple''. An -tuple is defi ...
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, transforms a function that takes multiple arguments into a chain of functions each with a single argument.
Function application 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
Universal algebra (sometimes called general algebra) is the field of mathematics that studies algebraic structures themselves, not examples ("models") of algebraic structures.
For instance, rather than take particular groups as the object of stud ...
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 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
In linguistics and semiotics, a notation is a system of graphics or symbols, characters and abbreviated expressions, used (for example) in artistic and scientific disciplines to represent technical facts and quantities by convention. Therefore, ...
'', 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
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, un ...
.
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
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, un ...
,
, 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
In programming language theory, the associativity of an operator is a property that determines how operators of the same precedence are grouped in the absence of parentheses. If an operand is both preceded and followed by operators (for exampl ...
, 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
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
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