HOME

TheInfoList



OR:

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 fo ...
in
mathematical logic Mathematical logic is the study of 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 forma ...
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 esp ...
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 abst ...
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 Pic ...
. 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 alg ...
. 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: * x – variable, a character or string representing a parameter or mathematical/logical value. * (\lambda x.M) – abstraction, function definition (M is a lambda term). The variable x becomes bound in the expression. * (M\ N) – application, applying a function M to an argument N. M and N are lambda terms. The reduction operations include: * (\lambda x.M \rightarrow(\lambda y.M – α-conversion, renaming the bound variables in the expression. Used to avoid name collisions. * ((\lambda x.M)\ E)\rightarrow (M :=E – β-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 r ...
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 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 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 ...
, 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 alg ...
. 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. ...
,
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. Ling ...
, 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 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, ca ...
.


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 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 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 formaliz ...
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 ri ...
(λ) 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 “\hat” used for class-abstraction by Whitehead and Russell, by first modifying “\hat” to “\land x” to distinguish function-abstraction from class-abstraction, and then changing “\land” 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, 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 "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, linguistics and comput ...
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 : \operatorname(x, y) = x^2 + y^2 can be rewritten in ''anonymous form'' as : (x, y) \mapsto x^2 + y^2 (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 x^2 + y^2"). Similarly, the function : \operatorname(x) = x can be rewritten in anonymous form as : x \mapsto x 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 \operatorname 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, : (x, y) \mapsto x^2 + y^2 can be reworked into : x \mapsto (y \mapsto x^2 + y^2) 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 tha ...
, 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 \operatorname function to the arguments (5, 2), yields at once : ((x, y) \mapsto x^2 + y^2)(5, 2) : = 5^2 + 2^2 : = 29, whereas evaluation of the curried version requires one more step : \Bigl(\bigl(x \mapsto (y \mapsto x^2 + y^2)\bigr)(5)\Bigr)(2) : = (y \mapsto 5^2 + y^2)(2) // the definition of x has been used with 5 in the inner expression. This is like β-reduction. : = 5^2 + 2^2 // the definition of y has been used with 2. Again, similar to β-reduction. : = 29 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 study ...
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 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 tha ...
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 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 (\lambda x.t) is a lambda term (called an abstraction); *if and are lambda terms, then (t   s) 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 \lambda x.t denotes an § anonymous function that takes a single input and returns . For example, \lambda x.x^2+2 is an abstraction for the function f(x) = x^2 + 2 using the term x^2+2 for . The name f(x) is superfluous when using abstraction. (\lambda x.t) 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 t   s represents the application of a function to an input , that is, it represents the act of calling function on input to produce t(s). There is no concept in lambda calculus of variable declaration. In a definition such as \lambda x.x+y (i.e. f(x) = x + y), in lambda calculus is a variable that is not yet defined. The abstraction \lambda x.x+y 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, #\lambda x.((\lambda x.x)x) which is of form \lambda x.B —an abstraction, and #((\lambda x.x)x) which is of form M N —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 \lambda x.B, where B is ((\lambda x.x)x), the result of applying (\lambda x.x) to x, while example 2 is M N; M is the lambda term (\lambda x.x) 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 ...
\lambda x.x.


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, \lambda x.x 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 ...
, x \mapsto x, and (\lambda x.x)y represents the identity function applied to y. Further, (\lambda x.y) represents the constant function x \mapsto y, the function that always returns y, no matter the input. In lambda calculus, function application is regarded as left-associative, so that stx means (st)x. 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, \lambda x.x and \lambda y.y are alpha-equivalent lambda terms, and they both represent the same function (the identity function). The terms x and y 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 x are just x * 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 \lambda x.t is the set of free variables of t, but with x 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 t s is the union of the set of free variables of t and the set of free variables of s. For example, the lambda term representing the identity \lambda x.x has no free variables, but the function \lambda x. y x has a single free variable, y.


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 t, s and r are lambda terms and x and y are variables. The notation t := r/math> indicates substitution of r for x in t in a ''capture-avoiding'' manner. This is defined so that: * x := r= r; x substituted for r is just r * y := r= y if x \neq y; x substituted for r when dealing with y is just y * (t s) := r= (t := r(s := r; substitution distributes to further application of the variable * (\lambda x.t) := r= \lambda x.t; although x has been mapped to r, subsequently mapping all x to t will not change the lambda function (\lambda x.t) * (\lambda y.t) := r= \lambda y.(t := r if x \neq y and y is not in the free variables of r. The variable y is said to be "fresh" for r. For example, (\lambda x.x) := y= \lambda x.(x := y = \lambda x.x, and ((\lambda x.y)x) := y= ((\lambda x.y) := y(x := y = (\lambda x.y)y. The freshness condition (requiring that y is not in the free variables of r) is crucial in order to ensure that substitution does not change the meaning of functions. For example, a substitution that ignores the freshness condition can lead to errors: (\lambda x.y) := x= \lambda x.(y := x = \lambda x.x. This substitution turns the constant function \lambda x.y into the identity \lambda x.x by substitution. In general, failure to meet the freshness condition can be remedied by alpha-renaming with a suitable fresh variable. For example, switching back to our correct notion of substitution, in (\lambda x.y) := x/math> the abstraction can be renamed with a fresh variable z, to obtain (\lambda z.y) := x= \lambda z.(y := x = \lambda z.x, and the meaning of the function is preserved by substitution.


β-reduction

The β-reduction rule states that an application of the form ( \lambda x . t) s reduces to the term t x := s/math>. The notation ( \lambda x . t ) s \to t x := s is used to indicate that ( \lambda x .t ) s β-reduces to t x := s . For example, for every s, ( \lambda x . x ) s \to x x := s = s . This demonstrates that \lambda x . x really is the identity. Similarly, ( \lambda x . y ) s \to y x := s = y , which demonstrates that \lambda x . y is a constant function. The lambda calculus may be seen as an idealized version of a functional programming language, like
Haskell Haskell () is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research and industrial applications, Haskell has pioneered a number of programming lan ...
or
Standard ML Standard ML (SML) is a general-purpose, modular, functional programming language with compile-time type checking and type inference. It is popular among compiler writers and programming language researchers, as well as in the development of ...
. Under this view, β-reduction corresponds to a computational step. This step can be repeated by additional β-reductions until there are no more applications left to reduce. In the untyped lambda calculus, as presented here, this reduction process may not terminate. For instance, consider the term \Omega = (\lambda x . xx)( \lambda x . xx ). Here ( \lambda x . xx)( \lambda x . xx) \to ( xx ) x := \lambda x . xx = ( x x := \lambda x . xx )( x x := \lambda x . xx ) = ( \lambda x . xx)( \lambda x . xx ). That is, the term reduces to itself in a single β-reduction, and therefore the reduction process will never terminate. Another aspect of the untyped lambda calculus is that it does not distinguish between different kinds of data. For instance, it may be desirable to write a function that only operates on numbers. However, in the untyped lambda calculus, there is no way to prevent a function from being applied to
truth value In logic and mathematics, a truth value, sometimes called a logical value, is a value indicating the relation of a proposition to truth, which in classical logic has only two possible values ('' true'' or '' false''). Computing In some pro ...
s, strings, or other non-number objects.


Formal definition


Definition

Lambda expressions are composed of: * variables ''v''1, ''v''2, ...; * the abstraction symbols λ (lambda) and . (dot); * parentheses (). The set of lambda expressions, , can be defined inductively: # If ''x'' is a variable, then # If ''x'' is a variable and then # If then 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''). * When all variables are single-letter, the space in applications may be omitted: ''MNP'' instead of ''M'' ''N'' ''P''. * The body of an abstraction extends as far right as possible: λ''x''.''M N'' means λ''x''.(''M N'') and not (λ''x''.''M'') ''N''. * A sequence of abstractions is contracted: λ''x''.λ''y''.λ''z''.''N'' is abbreviated as λ''xyz''.''N''.


Free and bound variables

The abstraction operator, λ, 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''. In an expression λ''x''.''M'', the part λ''x'' is often called ''binder'', as a hint that the variable ''x'' is getting bound by appending λ''x'' to ''M''. All other variables are called ''free''. For example, in the expression λ''y''.''x x y'', ''y'' is a bound variable and ''x'' is a free variable. Also 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: λ''x''.''y'' (λ''x''.''z x''). The set of ''free variables'' of a lambda expression, ''M'', is denoted as FV(''M'') and is defined by recursion on the structure of the terms, as follows: # FV(''x'') = , where ''x'' is a variable. # FV(λ''x''.''M'') = FV(''M'') \ . # 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 Combinatory logic is a notation to eliminate the need for quantified variables in mathematical logic. It was introduced by Moses Schönfinkel and Haskell Curry, and has more recently been used in computer science as a theoretical model of com ...
.


Reduction

The meaning of lambda expressions is defined by how expressions can be reduced. There are three kinds of reduction: * α-conversion: changing bound variables; * β-reduction: applying functions to their arguments; * η-reduction: which captures a notion of extensionality. We also speak of the resulting equivalences: two expressions are ''α-equivalent'', if they can be α-converted into the same expression. β-equivalence 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, (λ''x''.''M'') ''N'' is a β-redex in expressing the substitution of ''N'' for ''x'' in ''M''. The expression to which a redex reduces is called its ''reduct''; the reduct of (λ''x''.''M'') ''N'' is ''M'' 'x'' := ''N'' If ''x'' is not free in ''M'', λ''x''.''M x'' is also an η-redex, with a reduct of ''M''.


α-conversion

α-conversion, sometimes known as α-renaming, allows bound variable names to be changed. For example, α-conversion of λ''x''.''x'' might yield λ''y''.''y''. Terms that differ only by α-conversion are called ''α-equivalent''. Frequently, in uses of lambda calculus, α-equivalent terms are considered to be equivalent. The precise rules for α-conversion are not completely trivial. First, when α-converting an abstraction, the only variable occurrences that are renamed are those that are bound to the same abstraction. For example, an α-conversion of λ''x''.λ''x''.''x'' could result in λ''y''.λ''x''.''x'', but it could ''not'' result in λ''y''.λ''x''.''y''. The latter has a different meaning from the original. This is analogous to the programming notion of
variable shadowing In computer programming, variable shadowing occurs when a variable declared within a certain scope (decision block, method, or inner class) has the same name as a variable declared in an outer scope. At the level of identifiers (names, rather tha ...
. Second, α-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 λ''x''.λ''y''.''x'', we get λ''y''.λ''y''.''y'', which is not at all the same. In programming languages with static scope, α-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 pract ...
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 * Cinema ...
(see α-renaming to make name resolution trivial). In the
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 r ...
notation, any two α-equivalent terms are syntactically identical.


Substitution

Substitution, written ''M'' 'x'' := ''N'' is the process of replacing all ''free'' occurrences of the variable ''x'' in the expression ''M'' with expression ''N''. 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 lambda expression): : ''x'' 'x'' := ''N''= ''N'' : ''y'' 'x'' := ''N''= ''y'', if ''x'' ≠ ''y'' : (''M''1 ''M''2) 'x'' := ''N''= ''M''1 'x'' := ''N''''M''2 'x'' := ''N'': (λ''x''.''M'') 'x'' := ''N''= λ''x''.''M'' : (λ''y''.''M'') 'x'' := ''N''= λ''y''.(''M'' 'x'' := ''N'', if ''x'' ≠ ''y'' and ''y'' ∉ FV(''N'') ''See above for the FV'' To substitute into an abstraction, it is sometimes necessary to α-convert the expression. For example, it is not correct for (λ''x''.''y'') 'y'' := ''x''to result in λ''x''.''x'', because the substituted ''x'' was supposed to be free but ended up being bound. The correct substitution in this case is λ''z''.''x'',
up to Two mathematical objects ''a'' and ''b'' are called equal up to an equivalence relation ''R'' * if ''a'' and ''b'' are related by ''R'', that is, * if ''aRb'' holds, that is, * if the equivalence classes of ''a'' and ''b'' with respect to ''R'' ...
α-equivalence. 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 (λ''x''.''M'') ''N'' is ''M'' 'x'' := ''N'' For example, assuming some encoding of 2, 7, ×, we have the following β-reduction: (λ''n''.''n'' × 2) 7 → 7 × 2. β-reduction can be seen to be the same as the concept of ''local reducibility'' in
natural deduction In logic and proof theory, natural deduction is a kind of proof calculus in which logical reasoning is expressed by inference rules closely related to the "natural" way of reasoning. This contrasts with Hilbert-style systems, which instead use ax ...
, via the Curry–Howard isomorphism.


η-reduction

η-reduction (eta 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 ...
,Luke Palme
(29 Dec 2010) Haskell-cafe: What's the motivation for η rules?
/ref> 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 bic ...
they give the same result for all arguments. η-reduction converts between λ''x''.''f'' ''x'' and ''f'' whenever ''x'' does not appear free in ''f''. η-reduction can be seen to be the same as the concept of ''local completeness'' in
natural deduction In logic and proof theory, natural deduction is a kind of proof calculus in which logical reasoning is expressed by inference rules closely related to the "natural" way of reasoning. This contrasts with Hilbert-style systems, which instead use ax ...
, via the Curry–Howard isomorphism.


Normal forms and confluence

For the untyped lambda calculus, β-reduction as a rewriting rule is neither
strongly normalising In abstract rewriting, an object is in normal form if it cannot be rewritten any further, i.e. it is irreducible. Depending on the rewriting system, an object may rewrite to several normal forms or none at all. Many properties of rewriting systems ...
nor
weakly normalising In abstract rewriting, an object is in normal form if it cannot be rewritten any further, i.e. it is irreducible. Depending on the rewriting system, an object may rewrite to several normal forms or none at all. Many properties of rewriting systems ...
. However, it can be shown that β-reduction is
confluent In geography, a confluence (also: ''conflux'') occurs where two or more flowing bodies of water join to form a single channel. A confluence can occur in several configurations: at the point where a tributary joins a larger river (main stem); o ...
when working up to α-conversion (i.e. we consider two normal forms to be equal if it is possible to α-convert one into the other). Therefore, both strongly normalising terms and weakly normalising terms have a unique normal form. For strongly normalising terms, any reduction strategy is guaranteed to yield the normal form, whereas for weakly normalising terms, some reduction strategies may fail to find it.


Encoding datatypes

The basic lambda calculus may be used to model booleans,
arithmetic Arithmetic () is an elementary part of mathematics that consists of the study of the properties of the traditional operations on numbers— addition, subtraction, multiplication, division, exponentiation, and extraction of roots. In the 19th ...
, data structures and recursion, as illustrated in the following sub-sections.


Arithmetic in lambda calculus

There are several possible ways to define the
natural number In mathematics, the natural numbers are those numbers used for counting (as in "there are ''six'' coins on the table") and ordering (as in "this is the ''third'' largest city in the country"). Numbers used for counting are called '' cardinal ...
s in lambda calculus, but by far the most common are the
Church numeral In mathematics, Church encoding is a means of representing data and operators in the lambda calculus. The Church numerals are a representation of the natural numbers using lambda notation. The method is named for Alonzo Church, who first encoded d ...
s, which can be defined as follows: : : : : and so on. Or using the alternative syntax presented above in ''
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, ...
'': : : : : A Church numeral is a
higher-order function In mathematics and computer science, a higher-order function (HOF) is a function that does at least one of the following: * takes one or more functions as arguments (i.e. a procedural parameter, which is a parameter of a procedure that is itse ...
—it takes a single-argument function , and returns another single-argument function. The Church numeral is a function that takes a function as argument and returns the -th composition of , i.e. the function composed with itself times. This is denoted and is in fact the -th power of (considered as an operator); is defined to be the identity function. Such repeated compositions (of a single function ) obey the
laws of exponents Exponentiation is a mathematical operation, written as , involving two numbers, the '' base'' and the ''exponent'' or ''power'' , and pronounced as " (raised) to the (power of) ". When is a positive integer, exponentiation corresponds to re ...
, which is why these numerals can be used for arithmetic. (In Church's original lambda calculus, the formal parameter of a lambda expression was required to occur at least once in the function body, which made the above definition of impossible.) One way of thinking about the Church numeral , which is often useful when analysing programs, is as an instruction 'repeat ''n'' times'. For example, using the and functions defined below, one can define a function that constructs a (linked) list of ''n'' elements all equal to ''x'' by repeating 'prepend another ''x'' element' ''n'' times, starting from an empty list. The lambda term is : By varying what is being repeated, and varying what argument that function being repeated is applied to, a great many different effects can be achieved. We can define a successor function, which takes a Church numeral and returns by adding another application of , where '(mf)x' means the function 'f' is applied 'm' times on 'x': : Because the -th composition of composed with the -th composition of gives the -th composition of , addition can be defined as follows: : can be thought of as a function taking two natural numbers as arguments and returning a natural number; it can be verified that : and : are β-equivalent lambda expressions. Since adding to a number can be accomplished by adding 1 times, an alternative definition is: : Similarly, multiplication can be defined as : Alternatively : since multiplying and is the same as repeating the add function times and then applying it to zero. Exponentiation has a rather simple rendering in Church numerals, namely : The predecessor function defined by for a positive integer and is considerably more difficult. The formula : can be validated by showing inductively that if ''T'' denotes , then for . Two other definitions of are given below, one using
conditionals Conditional (if then) may refer to: *Causal conditional, if X then Y, where X is a cause of Y *Conditional probability, the probability of an event A given that another event B has occurred *Conditional proof, in logic: a proof that asserts a co ...
and the other using
pairs Concentration, also known as Memory, Shinkei-suijaku (Japanese meaning "nervous breakdown"), Matching Pairs, Match Match, Match Up, Pelmanism, Pexeso or simply Pairs, is a card game in which all of the cards are laid face down on a surface and tw ...
. With the predecessor function, subtraction is straightforward. Defining : , yields when and otherwise.


Logic and predicates

By convention, the following two definitions (known as Church booleans) are used for the boolean values and : : : Then, with these two lambda terms, we can define some logic operators (these are just possible formulations; other expressions are equally correct): : : : : We are now able to compute some logic functions, for example: : :: :: and we see that is equivalent to . A ''predicate'' is a function that returns a boolean value. The most fundamental predicate is , which returns if its argument is the Church numeral , and if its argument is any other Church numeral: : The following predicate tests whether the first argument is less-than-or-equal-to the second: : , and since , if and , it is straightforward to build a predicate for numerical equality. The availability of predicates and the above definition of and make it convenient to write "if-then-else" expressions in lambda calculus. For example, the predecessor function can be defined as: : which can be verified by showing inductively that is the add − 1 function for > 0.


Pairs

A pair (2-tuple) can be defined in terms of and , by using the Church encoding for pairs. For example, encapsulates the pair (,), returns the first element of the pair, and returns the second. : : : : : A linked list can be defined as either NIL for the empty list, or the of an element and a smaller list. The predicate tests for the value . (Alternatively, with , the construct obviates the need for an explicit NULL test). As an example of the use of pairs, the shift-and-increment function that maps to can be defined as : which allows us to give perhaps the most transparent version of the predecessor function: :


Additional programming techniques

There is a considerable body of
programming idiom In computer programming, a programming idiom or code idiom is a group of code fragments sharing an equivalent semantic role, which recurs frequently across software projects often expressing a special feature of a recurring construct in one or ...
s for lambda calculus. Many of these were originally developed in the context of using lambda calculus as a foundation for programming language semantics, effectively using lambda calculus as a
low-level programming language A low-level programming language is a programming language that provides little or no Abstraction (computer science), abstraction from a computer's instruction set architecture—commands or functions in the language map that are structurally sim ...
. Because several programming languages include the lambda calculus (or something very similar) as a fragment, these techniques also see use in practical programming, but may then be perceived as obscure or foreign.


Named constants

In lambda calculus, a
library A library is a collection of materials, books or media that are accessible for use and not just for display purposes. A library provides physical (hard copies) or digital access (soft copies) materials, and may be a physical location or a vi ...
would take the form of a collection of previously defined functions, which as lambda-terms are merely particular constants. The pure lambda calculus does not have a concept of named constants since all atomic lambda-terms are variables, but one can emulate having named constants by setting aside a variable as the name of the constant, using abstraction to bind that variable in the main body, and apply that abstraction to the intended definition. Thus to use to mean ''N'' (some explicit lambda-term) in ''M'' (another lambda-term, the "main program"), one can say : ''M'' ''N'' Authors often introduce
syntactic sugar In computer science, syntactic sugar is syntax within a programming language that is designed to make things easier to read or to express. It makes the language "sweeter" for human use: things can be expressed more clearly, more concisely, or in an ...
, such as , to permit writing the above in the more intuitive order : ''N'M'' By chaining such definitions, one can write a lambda calculus "program" as zero or more function definitions, followed by one lambda-term using those functions that constitutes the main body of the program. A notable restriction of this is that the name be not defined in ''N'', for ''N'' to be outside the scope of the abstraction binding ; this means a recursive function definition cannot be used as the ''N'' with . The construction would allow writing recursive function definitions.


Recursion and fixed points

Recursion Recursion (adjective: ''recursive'') occurs when a thing is defined in terms of itself or of its type. Recursion is used in a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in mathematic ...
is the definition of a function using the function itself. Lambda calculus cannot express this as directly as some other notations: all functions are anonymous in lambda calculus, so we can't refer to a value which is yet to be defined, inside the lambda term defining that same value. However, recursion can still be achieved by arranging for a lambda expression to receive itself as its argument value, for example in  . Consider the
factorial In mathematics, the factorial of a non-negative denoted is the product of all positive integers less than or equal The factorial also equals the product of n with the next smaller factorial: \begin n! &= n \times (n-1) \times (n-2) \ ...
function recursively defined by : . In the lambda expression which is to represent this function, a ''parameter'' (typically the first one) will be assumed to receive the lambda expression itself as its value, so that calling it – applying it to an argument – will amount to recursion. Thus to achieve recursion, the intended-as-self-referencing argument (called here) must always be passed to itself within the function body, at a call point: : ::: with   to hold, so   and : The self-application achieves replication here, passing the function's lambda expression on to the next invocation as an argument value, making it available to be referenced and called there. This solves it but requires re-writing each recursive call as self-application. We would like to have a generic solution, without a need for any re-writes: : ::: with   to hold, so   and :  where  ::: so that  Given a lambda term with first argument representing recursive call (e.g. here), the ''fixed-point'' combinator will return a self-replicating lambda expression representing the recursive function (here, ). The function does not need to be explicitly passed to itself at any point, for the self-replication is arranged in advance, when it is created, to be done each time it is called. Thus the original lambda expression is re-created inside itself, at call-point, achieving
self-reference Self-reference occurs in natural or formal languages when a sentence, idea or formula refers to itself. The reference may be expressed either directly—through some intermediate sentence or formula—or by means of some encoding. In philoso ...
. In fact, there are many possible definitions for this operator, the simplest of them being: : In the lambda calculus,   is a fixed-point of , as it expands to: : : : : : Now, to perform our recursive call to the factorial function, we would simply call ,  where ''n'' is the number we are calculating the factorial of. Given ''n'' = 4, for example, this gives: : : : : : : : : : : : : : : : : : : : Every recursively defined function can be seen as a fixed point of some suitably defined function closing over the recursive call with an extra argument, and therefore, using , every recursively defined function can be expressed as a lambda expression. In particular, we can now cleanly define the subtraction, multiplication and comparison predicate of natural numbers recursively.


Standard terms

Certain terms have commonly accepted names: : : : : : : : : is the identity function. and form complete combinator calculus systems that can express any lambda term - see the next section. is , the smallest term that has no normal form. is standard and defined above, and can also be defined as Y = BU(CBU). and defined above are commonly abbreviated as and .


Abstraction elimination

If ''N'' is a lambda-term without abstraction, but possibly containing named constants ( combinators), then there exists a lambda-term ''T''(,''N'') which is equivalent to ''N'' but lacks abstraction (except as part of the named constants, if these are considered non-atomic). This can also be viewed as anonymising variables, as ''T''(,''N'') removes all occurrences of from ''N'', while still allowing argument values to be substituted into the positions where ''N'' contains an . The conversion function ''T'' can be defined by: : ''T''(, ) := I : ''T''(, ''N'') := K ''N'' if is not free in ''N''. : ''T''(, ''M'' ''N'') := S ''T''(, ''M'') ''T''(, ''N'') In either case, a term of the form ''T''(,''N'') ''P'' can reduce by having the initial combinator I, K, or S grab the argument ''P'', just like β-reduction of ''N'' ''P'' would do. I returns that argument. K throws the argument away, just like ''N'' would do if has no free occurrence in ''N''. S passes the argument on to both subterms of the application, and then applies the result of the first to the result of the second. The combinators B and C are similar to S, but pass the argument on to only one subterm of an application (B to the "argument" subterm and C to the "function" subterm), thus saving a subsequent K if there is no occurrence of in one subterm. In comparison to B and C, the S combinator actually conflates two functionalities: rearranging arguments, and duplicating an argument so that it may be used in two places. The W combinator does only the latter, yielding the
B, C, K, W system The B, C, K, W system is a variant of combinatory logic that takes as primitive the combinators B, C, K, and W. This system was discovered by Haskell Curry in his doctoral thesis ''Grundlagen der kombinatorischen Logik'', whose results are set out ...
as an alternative to SKI combinator calculus.


Typed lambda calculus

A typed lambda calculus is a typed
formalism Formalism may refer to: * Form (disambiguation) * Formal (disambiguation) * Legal formalism, legal positivist view that the substantive justice of a law is a question for the legislature rather than the judiciary * Formalism (linguistics) * Scien ...
that uses the lambda-symbol (\lambda) to denote anonymous function abstraction. In this context, types are usually objects of a syntactic nature that are assigned to lambda terms; the exact nature of a type depends on the calculus considered (see Kinds of typed lambda calculi). From a certain point of view, typed lambda calculi can be seen as refinements of the untyped lambda calculus but from another point of view, they can also be considered the more fundamental theory and ''untyped lambda calculus'' a special case with only one type. Typed lambda calculi are foundational
programming languages A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
and are the base of typed functional programming languages such as ML and
Haskell Haskell () is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research and industrial applications, Haskell has pioneered a number of programming lan ...
and, more indirectly, typed
imperative programming In computer science, imperative programming is a programming paradigm of software that uses statements that change a program's state. In much the same way that the imperative mood in natural languages expresses commands, an imperative program ...
languages. Typed lambda calculi play an important role in the design of type systems for programming languages; here typability usually captures desirable properties of the program, e.g. the program will not cause a memory access violation. Typed lambda calculi are closely related to
mathematical logic Mathematical logic is the study of 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 forma ...
and
proof theory Proof theory is a major branchAccording to Wang (1981), pp. 3–4, proof theory is one of four domains mathematical logic, together with model theory, axiomatic set theory, and recursion theory. Barwise (1978) consists of four corresponding part ...
via the Curry–Howard isomorphism and they can be considered as the internal language of classes of categories, e.g. the simply typed lambda calculus is the language of
Cartesian closed categories In category theory, a category is Cartesian closed if, roughly speaking, any morphism defined on a product of two objects can be naturally identified with a morphism defined on one of the factors. These categories are particularly important in mat ...
(CCCs).


Reduction strategies

Whether a term is normalising or not, and how much work needs to be done in normalising it if it is, depends to a large extent on the reduction strategy used. Common lambda calculus reduction strategies include: ; Normal order: The leftmost, outermost redex is always reduced first. That is, whenever possible the arguments are substituted into the body of an abstraction before the arguments are reduced. ; Applicative order: The leftmost, innermost redex is always reduced first. Intuitively this means a function's arguments are always reduced before the function itself. Applicative order always attempts to apply functions to normal forms, even when this is not possible. ; Full β-reductions: Any redex can be reduced at any time. This means essentially the lack of any particular reduction strategy—with regard to reducibility, "all bets are off". Weak reduction strategies do not reduce under lambda abstractions: ; Call by value: A redex is reduced only when its right hand side has reduced to a value (variable or abstraction). Only the outermost redexes are reduced. ; Call by name: As normal order, but no reductions are performed inside abstractions. For example, is in normal form according to this strategy, although it contains the redex . Strategies with sharing reduce computations that are "the same" in parallel: ; Optimal reduction: As normal order, but computations that have the same label are reduced simultaneously. ; Call by need: As call by name (hence weak), but function applications that would duplicate terms instead name the argument, which is then reduced only "when it is needed".


Computability

There is no algorithm that takes as input any two lambda expressions and outputs or depending on whether one expression reduces to the other. More precisely, no
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 ...
can decide the question. This was historically the first problem for which undecidability could be proven. As usual for such a proof, ''computable'' means computable by any
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 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 ...
. In fact computability can itself be defined via the lambda calculus: a function ''F'': N → N of natural numbers is a computable function if and only if there exists a lambda expression ''f'' such that for every pair of ''x'', ''y'' in N, ''F''(''x'')=''y'' if and only if ''f''  =β ,  where and are the
Church numerals In mathematics, Church encoding is a means of representing data and operators in the lambda calculus. The Church numerals are a representation of the natural numbers using lambda notation. The method is named for Alonzo Church, who first encoded ...
corresponding to ''x'' and ''y'', respectively and =β meaning equivalence with β-reduction. See the
Church–Turing thesis In computability theory, the Church–Turing thesis (also known as computability thesis, the Turing–Church thesis, the Church–Turing conjecture, Church's thesis, Church's conjecture, and Turing's thesis) is a thesis about the nature of co ...
for other approaches to defining computability and their equivalence. Church's proof of uncomputability first reduces the problem to determining whether a given lambda expression has a normal form. Then he assumes that this predicate is computable, and can hence be expressed in lambda calculus. Building on earlier work by Kleene and constructing a
Gödel numbering In mathematical logic, a Gödel numbering is a function that assigns to each symbol and well-formed formula of some formal language a unique natural number, called its Gödel number. The concept was developed by Kurt Gödel for the proof of h ...
for lambda expressions, he constructs a lambda expression that closely follows the proof of Gödel's first incompleteness theorem. If is applied to its own Gödel number, a contradiction results.


Complexity

The notion of
computational complexity In computer science, the computational complexity or simply complexity of an algorithm is the amount of resources required to run it. Particular focus is given to computation time (generally measured by the number of needed elementary operations) ...
for the lambda calculus is a bit tricky, because the cost of a β-reduction may vary depending on how it is implemented. To be precise, one must somehow find the location of all of the occurrences of the bound variable in the expression , implying a time cost, or one must keep track of the locations of free variables in some way, implying a space cost. A naïve search for the locations of in is ''O''(''n'') in the length ''n'' of .
Director string In mathematics, in the area of lambda calculus and computation, directors or director strings are a mechanism for keeping track of the free variables in a Expression (mathematics), term. Loosely speaking, they can be understood as a kind of memoiza ...
s were an early approach that traded this time cost for a quadratic space usage. More generally this has led to the study of systems that use explicit substitution. In 2014 it was shown that the number of β-reduction steps taken by normal order reduction to reduce a term is a ''reasonable'' time cost model, that is, the reduction can be simulated on a Turing machine in time polynomially proportional to the number of steps. This was a long-standing open problem, due to ''size explosion'', the existence of lambda terms which grow exponentially in size for each β-reduction. The result gets around this by working with a compact shared representation. The result makes clear that the amount of space needed to evaluate a lambda term is not proportional to the size of the term during reduction. It is not currently known what a good measure of space complexity would be. An unreasonable model does not necessarily mean inefficient. Optimal reduction reduces all computations with the same label in one step, avoiding duplicated work, but the number of parallel β-reduction steps to reduce a given term to normal form is approximately linear in the size of the term. This is far too small to be a reasonable cost measure, as any Turing machine may be encoded in the lambda calculus in size linearly proportional to the size of the Turing machine. The true cost of reducing lambda terms is not due to β-reduction per se but rather the handling of the duplication of redexes during β-reduction. It is not known if optimal reduction implementations are reasonable when measured with respect to a reasonable cost model such as the number of leftmost-outermost steps to normal form, but it has been shown for fragments of the lambda calculus that the optimal reduction algorithm is efficient and has at most a quadratic overhead compared to leftmost-outermost. In addition the BOHM prototype implementation of optimal reduction outperformed both
Caml Light Caml (originally an acronym for Categorical Abstract Machine Language) is a multi-paradigm, general-purpose programming language which is a dialect of the ML programming language family. Caml was developed in France at INRIA and ENS. Caml is ...
and
Haskell Haskell () is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research and industrial applications, Haskell has pioneered a number of programming lan ...
on pure lambda terms.


Lambda calculus and programming languages

As pointed out by Peter Landin's 1965 paper "A Correspondence between ALGOL 60 and Church's Lambda-notation", sequential
procedural programming Procedural programming is a programming paradigm, derived from imperative programming, based on the concept of the '' procedure call''. Procedures (a type of routine or subroutine) simply contain a series of computational steps to be carrie ...
languages can be understood in terms of the lambda calculus, which provides the basic mechanisms for procedural abstraction and procedure (subprogram) application.


Anonymous functions

For example, in Python the "square" function can be expressed as a lambda expression as follows: (lambda x: x**2) The above example is an expression that evaluates to a first-class function. The symbol lambda creates an anonymous function, given a list of parameter names, x – just a single argument in this case, and an expression that is evaluated as the body of the function, x**2. Anonymous functions are sometimes called lambda expressions. For example,
Pascal Pascal, Pascal's or PASCAL may refer to: People and fictional characters * Pascal (given name), including a list of people with the name * Pascal (surname), including a list of people and fictional characters with the name ** Blaise Pascal, Frenc ...
and many other imperative languages have long supported passing subprograms as
arguments An argument is a statement or group of statements called premises intended to determine the degree of truth or acceptability of another statement called conclusion. Arguments can be studied from three main perspectives: the logical, the dialectic ...
to other subprograms through the mechanism of
function pointers A function pointer, also called a subroutine pointer or procedure pointer, is a pointer that points to a function. As opposed to referencing a data value, a function pointer points to executable code within memory. Dereferencing the function poi ...
. However, function pointers are not a sufficient condition for functions to be first class datatypes, because a function is a first class datatype if and only if new instances of the function can be created at run-time. And this run-time creation of functions is supported in
Smalltalk Smalltalk is an object-oriented, dynamically typed reflective programming language. It was designed and created in part for educational use, specifically for constructionist learning, at the Learning Research Group (LRG) of Xerox PARC by Alan ...
,
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of websites use JavaScript on the client side for webpage behavior, of ...
and
Wolfram Language The Wolfram Language ( ) is a general multi-paradigm programming language developed by Wolfram Research. It emphasizes symbolic computation, functional programming, and rule-based programming and can employ arbitrary structures and data. It ...
, and more recently in Scala, Eiffel ("agents"), C# ("delegates") and
C++11 C11, C.XI, C-11 or C.11 may refer to: Transport * C-11 Fleetster, a 1920s American light transport aircraft for use of the United States Assistant Secretary of War * Fokker C.XI, a 1935 Dutch reconnaissance seaplane * LET C-11, a license-build ...
, among others.


Parallelism and concurrency

The Church–Rosser property of the lambda calculus means that evaluation (β-reduction) can be carried out in ''any order'', even in parallel. This means that various nondeterministic evaluation strategies are relevant. However, the lambda calculus does not offer any explicit constructs for parallelism. One can add constructs such as
Futures Futures may mean: Finance *Futures contract, a tradable financial derivatives contract *Futures exchange, a financial market where futures contracts are traded * ''Futures'' (magazine), an American finance magazine Music * ''Futures'' (album), a ...
to the lambda calculus. Other
process calculi In computer science, the process calculi (or process algebras) are a diverse family of related approaches for formally modelling concurrent systems. Process calculi provide a tool for the high-level description of interactions, communications, and ...
have been developed for describing communication and concurrency.


Semantics

The fact that lambda calculus terms act as functions on other lambda calculus terms, and even on themselves, led to questions about the semantics of the lambda calculus. Could a sensible meaning be assigned to lambda calculus terms? The natural semantics was to find a set ''D'' isomorphic to the function space ''D'' → ''D'', of functions on itself. However, no nontrivial such ''D'' can exist, by
cardinality In mathematics, the cardinality of a set is a measure of the number of elements of the set. For example, the set A = \ contains 3 elements, and therefore A has a cardinality of 3. Beginning in the late 19th century, this concept was generalized ...
constraints because the set of all functions from ''D'' to ''D'' has greater cardinality than ''D'', unless ''D'' is a
singleton set In mathematics, a singleton, also known as a unit set or one-point set, is a set with exactly one element. For example, the set \ is a singleton whose single element is 0. Properties Within the framework of Zermelo–Fraenkel set theory, the ...
. In the 1970s,
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 ...
showed that if only
continuous functions In mathematics, a continuous function is a function such that a continuous variation (that is a change without jump) of the argument induces a continuous variation of the value of the function. This means that there are no abrupt changes in valu ...
were considered, a set or
domain Domain may refer to: Mathematics *Domain of a function, the set of input values for which the (total) function is defined ** Domain of definition of a partial function ** Natural domain of a partial function **Domain of holomorphy of a function * ...
''D'' with the required property could be found, thus providing a
model A model is an informative representation of an object, person or system. The term originally denoted the plans of a building in late 16th-century English, and derived via French and Italian ultimately from Latin ''modulus'', a measure. Models c ...
for the lambda calculus. This work also formed the basis for the
denotational semantics In computer science, denotational semantics (initially known as mathematical semantics or Scott–Strachey semantics) is an approach of formalizing the meanings of programming languages by constructing mathematical objects (called ''denotations' ...
of programming languages.


Variations and extensions

These extensions are in the
lambda cube In mathematical logic and type theory, the λ-cube (also written lambda cube) is a framework introduced by Henk Barendregt to investigate the different dimensions in which the calculus of constructions is a generalization of the simply typed ...
: *
Typed lambda calculus A typed lambda calculus is a typed formalism that uses the lambda-symbol (\lambda) to denote anonymous function abstraction. In this context, types are usually objects of a syntactic nature that are assigned to lambda terms; the exact nature of a ...
– Lambda calculus with typed variables (and functions) *
System F System F (also polymorphic lambda calculus or second-order lambda calculus) is a typed lambda calculus that introduces, to simply typed lambda calculus, a mechanism of universal quantification over types. System F formalizes parametric polymorph ...
– A typed lambda calculus with type-variables *
Calculus of constructions In mathematical logic and computer science, the calculus of constructions (CoC) is a type theory created by Thierry Coquand. It can serve as both a typed programming language and as constructive foundation for mathematics. For this second reason, ...
– A typed lambda calculus with
types Type may refer to: Science and technology Computing * Typing, producing text via a keyboard, typewriter, etc. * Data type In computer science and computer programming, a data type (or simply type) is a set of possible values and a set of allo ...
as first-class values These
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 fo ...
s are extensions of lambda calculus that are not in the lambda cube: * Binary lambda calculus – A version of lambda calculus with binary I/O, a binary encoding of terms, and a designated universal machine. *
Lambda-mu calculus In mathematical logic and computer science, the lambda-mu calculus is an extension of the lambda calculus introduced by M. Parigot. It introduces two new operators: the μ operator (which is completely different both from the μ operator found in co ...
– An extension of the lambda calculus for treating
classical logic Classical logic (or standard logic or Frege-Russell logic) is the intensively studied and most widely used class of deductive logic. Classical logic has had much influence on analytic philosophy. Characteristics Each logical system in this class ...
These formal systems are variations of lambda calculus: *
Kappa calculus In mathematical logic, category theory, and computer science, kappa calculus is a formal system for defining First order functions, first-order function (mathematics), functions. Unlike lambda calculus, kappa calculus has no higher-order functions; ...
– A first-order analogue of lambda calculus These formal systems are related to lambda calculus: *
Combinatory logic Combinatory logic is a notation to eliminate the need for quantified variables in mathematical logic. It was introduced by Moses Schönfinkel and Haskell Curry, and has more recently been used in computer science as a theoretical model of com ...
– A notation for mathematical logic without variables * SKI combinator calculus – A computational system based on the S, K and I combinators, equivalent to lambda calculus, but reducible without variable substitutions


See also

* Applicative computing systems – Treatment of
objects Object may refer to: General meanings * Object (philosophy), a thing, being, or concept ** Object (abstract), an object which does not exist at any particular time or place ** Physical object, an identifiable collection of matter * Goal, an ai ...
in the style of the lambda calculus *
Cartesian closed category In category theory, a category is Cartesian closed if, roughly speaking, any morphism defined on a product of two objects can be naturally identified with a morphism defined on one of the factors. These categories are particularly important in math ...
– A setting for lambda calculus 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, ca ...
* Categorical abstract 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 ...
applicable to lambda calculus * Curry–Howard isomorphism – The formal correspondence between programs and
proofs Proof most often refers to: * Proof (truth), argument or sufficient evidence for the truth of a proposition * Alcohol proof, a measure of an alcoholic drink's strength Proof may also refer to: Mathematics and formal logic * Formal proof, a co ...
*
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 r ...
– notation disambiguating alpha conversions *
De Bruijn notation In mathematical logic, the De Bruijn notation is a syntax for terms in the λ calculus invented by the Dutch mathematician Nicolaas Govert de Bruijn. It can be seen as a reversal of the usual syntax for the λ calculus where the argument in an ap ...
– notation using postfix modification functions *
Deductive lambda calculus Deductive lambda calculus considers what happens when lambda terms are regarded as mathematical expressions. One interpretation of the untyped lambda calculus is as a programming language where evaluation proceeds by performing reductions on an expr ...
– The consideration of the problems associated with considering lambda calculus as a
Deductive 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 for ...
. *
Domain theory Domain theory is a branch of mathematics that studies special kinds of partially ordered sets (posets) commonly called domains. Consequently, domain theory can be considered as a branch of order theory. The field has major applications in computer ...
– Study of certain posets giving
denotational semantics In computer science, denotational semantics (initially known as mathematical semantics or Scott–Strachey semantics) is an approach of formalizing the meanings of programming languages by constructing mathematical objects (called ''denotations' ...
for lambda calculus *
Evaluation strategy In a programming language, an evaluation strategy is a set of rules for evaluating expressions. The term is often used to refer to the more specific notion of a ''parameter-passing strategy'' that defines the kind of value that is passed to the f ...
– Rules for the evaluation of expressions in
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
s * Explicit substitution – The theory of substitution, as used in β-reduction *
Functional programming 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 tha ...
*
Harrop formula In intuitionistic logic, the Harrop formulae, named after Ronald Harrop, are the class of formulae inductively defined as follows: * Atomic formulae are Harrop, including falsity (⊥); * A \wedge B is Harrop provided A and B are; * \neg F is Har ...
– A kind of constructive logical formula such that proofs are lambda terms *
Interaction nets Interaction nets are a graphical model of computation devised by Yves Lafont in 1990 as a generalisation of the proof structures of linear logic. An interaction net system is specified by a set of agent types and a set of interaction rules. Interac ...
*
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 ...
– A demonstration that some form of lambda calculus is inconsistent * Knights of the Lambda Calculus – A semi-fictional organization of LISP and
Scheme A scheme is a systematic plan for the implementation of a certain idea. Scheme or schemer may refer to: Arts and entertainment * ''The Scheme'' (TV series), a BBC Scotland documentary series * The Scheme (band), an English pop band * ''The Schem ...
hackers * Krivine machine – An abstract machine to interpret call-by-name in lambda calculus * Lambda calculus definition – Formal definition of the lambda calculus. *
Let expression In computer science, a "let" expression associates a function definition with a restricted scope. The "let" expression may also be defined in mathematics, where it associates a Boolean condition with a restricted scope. The "let" expression may b ...
– An expression closely related to an abstraction. *
Minimalism (computing) In computing, minimalism refers to the application of minimalist philosophies and principles in the design and use of hardware and software. Minimalism, in this sense, means designing systems that use the least hardware and software resources p ...
*
Rewriting In mathematics, computer science, and logic, rewriting covers a wide range of methods of replacing subterms of a formula with other terms. Such methods may be achieved by rewriting systems (also known as rewrite systems, rewrite engines, or reduc ...
– Transformation of formulæ in formal systems * SECD machine – A
virtual machine In computing, a virtual machine (VM) is the virtualization/ emulation of a computer system. Virtual machines are based on computer architectures and provide functionality of a physical computer. Their implementations may involve specialized h ...
designed for the lambda calculus *
Scott–Curry theorem In mathematical logic, the Scott–Curry theorem is a result in lambda calculus stating that if two non-empty sets of lambda terms ''A'' and ''B'' are closed under beta-convertibility then they are recursively inseparable. Explanation A set ''A'' ...
– A theorem about sets of lambda terms * ''
To Mock a Mockingbird ''To Mock a Mockingbird and Other Logic Puzzles: Including an Amazing Adventure in Combinatory Logic'' (1985, {{isbn, 0-19-280142-2) is a book by the mathematician and logician Raymond Smullyan. It contains many nontrivial recreational puzzles ...
'' – An introduction to
combinatory logic Combinatory logic is a notation to eliminate the need for quantified variables in mathematical logic. It was introduced by Moses Schönfinkel and Haskell Curry, and has more recently been used in computer science as a theoretical model of com ...
*
Universal Turing machine In computer science, a universal Turing machine (UTM) is a Turing machine that can simulate an arbitrary Turing machine on arbitrary input. The universal machine essentially achieves this by reading both the description of the machine to be simu ...
– A formal computing machine that is equivalent to lambda calculus *
Unlambda Unlambda is a minimal, "nearly Purely functional language, pure" functional programming language invented by David Madore. It is based on combinatory logic, an expression system without the Lambda calculus, lambda operator or free variables. It r ...
– An
esoteric Western esotericism, also known as esotericism, esoterism, and sometimes the Western mystery tradition, is a term scholars use to categorise a wide range of loosely related ideas and movements that developed within Western society. These ideas ...
functional programming language based on combinatory logic


Further reading

* Abelson, Harold & Gerald Jay Sussman. Structure and Interpretation of Computer Programs.
The MIT Press The MIT Press is a university press affiliated with the Massachusetts Institute of Technology (MIT) in Cambridge, Massachusetts (United States). It was established in 1962. History The MIT Press traces its origins back to 1926 when MIT publish ...
. . * Hendrik Pieter Barendregtbr>''Introduction to Lambda Calculus''
*
Henk Barendregt Hendrik Pieter (Henk) Barendregt (born 18 December 1947, Amsterdam) is a Dutch logician, known for his work in lambda calculus and type theory. Life and work Barendregt studied mathematical logic at Utrecht University, obtaining his master's de ...

The Impact of the Lambda Calculus in Logic and Computer Science
The Bulletin of Symbolic Logic, Volume 3, Number 2, June 1997. * Barendregt, Hendrik Pieter, ''The Type Free Lambda Calculus'' pp1091–1132 of ''Handbook of Mathematical Logic'',
North-Holland North Holland ( nl, Noord-Holland, ) is a province of the Netherlands in the northwestern part of the country. It is located on the North Sea, north of South Holland and Utrecht, and west of Friesland and Flevoland. In November 2019, it had a p ...
(1977) * Cardone and Hindley, 2006
History of Lambda-calculus and Combinatory Logic
In Gabbay and Woods (eds.), ''Handbook of the History of Logic'', vol. 5. Elsevier. * Church, Alonzo, ''An unsolvable problem of elementary number theory'',
American Journal of Mathematics The ''American Journal of Mathematics'' is a bimonthly mathematics journal published by the Johns Hopkins University Press. History The ''American Journal of Mathematics'' is the oldest continuously published mathematical journal in the United S ...
, 58 (1936), pp. 345–363. This paper contains the proof that the equivalence of lambda expressions is in general not decidable. * () * * Kleene, Stephen, ''A theory of positive integers in formal logic'',
American Journal of Mathematics The ''American Journal of Mathematics'' is a bimonthly mathematics journal published by the Johns Hopkins University Press. History The ''American Journal of Mathematics'' is the oldest continuously published mathematical journal in the United S ...
, 57 (1935), pp. 153–173 and 219–244. Contains the lambda calculus definitions of several familiar functions. * Landin, Peter, ''A Correspondence Between ALGOL 60 and Church's Lambda-Notation'',
Communications of the ACM ''Communications of the ACM'' is the monthly journal of the Association for Computing Machinery (ACM). It was established in 1958, with Saul Rosen as its first managing editor. It is sent to all ACM members. Articles are intended for readers wi ...
, vol. 8, no. 2 (1965), pages 89–101. Available from th
ACM site
A classic paper highlighting the importance of lambda calculus as a basis for programming languages. * Larson, Jim

A gentle introduction for programmers. * * Schalk, A. and Simmons, H. (2005)
An introduction to λ-calculi and arithmetic with a decent selection of exercises
Notes for a course in the Mathematical Logic MSc at Manchester University. * A paper giving a formal underpinning to the idea of 'meaning-is-use' which, even if based on proofs, it is different from proof-theoretic semantics as in the Dummett–Prawitz tradition since it takes reduction as the rules giving meaning. * Hankin, Chris, ''An Introduction to Lambda Calculi for Computer Scientists,'' ;Monographs/textbooks for graduate students: * Morten Heine Sørensen, Paweł Urzyczyn, ''Lectures on the Curry–Howard isomorphism'', Elsevier, 2006, is a recent monograph that covers the main topics of lambda calculus from the type-free variety, to most typed lambda calculi, including more recent developments like
pure type system __NOTOC__ In the branches of mathematical logic known as proof theory and type theory, a pure type system (PTS), previously known as a generalized type system (GTS), is a form of typed lambda calculus that allows an arbitrary number of sorts and d ...
s and the
lambda cube In mathematical logic and type theory, the λ-cube (also written lambda cube) is a framework introduced by Henk Barendregt to investigate the different dimensions in which the calculus of constructions is a generalization of the simply typed ...
. It does not cover
subtyping In programming language theory, subtyping (also subtype polymorphism or inclusion polymorphism) is a form of type polymorphism in which a subtype is a datatype that is related to another datatype (the supertype) by some notion of substitutability, ...
extensions. * covers lambda calculi from a practical type system perspective; some topics like dependent types are only mentioned, but subtyping is an important topic. ;Documents * Achim Jung,
A Short Introduction to the Lambda Calculus
'-(
PDF Portable Document Format (PDF), standardized as ISO 32000, is a file format developed by Adobe in 1992 to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems. ...
) * Dana Scott,
A timeline of lambda calculus
'-(
PDF Portable Document Format (PDF), standardized as ISO 32000, is a file format developed by Adobe in 1992 to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems. ...
) * Raúl Rojas,
A Tutorial Introduction to the Lambda Calculus
'-(
PDF Portable Document Format (PDF), standardized as ISO 32000, is a file format developed by Adobe in 1992 to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems. ...
) * Peter Selinger,
Lecture Notes on the Lambda Calculus
'-(
PDF Portable Document Format (PDF), standardized as ISO 32000, is a file format developed by Adobe in 1992 to present documents, including text formatting and images, in a manner independent of application software, hardware, and operating systems. ...
) * Marius Buliga
''Graphic lambda calculus''

''Lambda Calculus as a Workflow Model''
by Peter Kelly, Paul Coddington, and Andrew Wendelborn; mentions graph reduction as a common means of evaluating lambda expressions and discusses the applicability of lambda calculus for
distributed computing A distributed system is a system whose components are located on different networked computers, which communicate and coordinate their actions by passing messages to one another from any system. Distributed computing is a field of computer sci ...
(due to the Church–Rosser property, which enables
parallel Parallel is a geometric term of location which may refer to: Computing * Parallel algorithm * Parallel computing * Parallel metaheuristic * Parallel (software), a UNIX utility for running programs in parallel * Parallel Sysplex, a cluster o ...
graph reduction for lambda expressions).


Notes


References

''Some parts of this article are based on material from
FOLDOC The Free On-line Dictionary of Computing (FOLDOC) is an online, searchable, encyclopedic dictionary of computing subjects. History FOLDOC was founded in 1985 by Denis Howe and was hosted by Imperial College London. In May 2015, the site was up ...
, used with permission.''


External links

* Graham Hutton
Lambda Calculus
a short (12 minutes) Computerphile video on the Lambda Calculus * Helmut Brandl,
Step by Step Introduction to Lambda Calculus
' * * David C. Keenan,
To Dissect a Mockingbird: A Graphical Notation for the Lambda Calculus with Animated Reduction
' * L. Allison,
Some executable λ-calculus examples
' * Georg P. Loczewski

* Bret Victor,
Alligator Eggs: A Puzzle Game Based on Lambda Calculus
' *
Lambda Calculus
'' o
Safalra's Website

LCI Lambda Interpreter
a simple yet powerful pure calculus interpreter

* Mike Thyer
Lambda Animator
a graphical Java applet demonstrating alternative reduction strategies.
Implementing the Lambda calculus
using C++ Templates * Shane Steinert-Threlkeld
"Lambda Calculi"
''
Internet Encyclopedia of Philosophy The ''Internet Encyclopedia of Philosophy'' (''IEP'') is a scholarly online encyclopedia, dealing with philosophy, philosophical topics, and philosophers. The IEP combines open access publication with peer reviewed publication of original p ...
'' * Anton Salikhmetov
''Macro Lambda Calculus''
{{Formal semantics 1936 in computing Articles with example Lisp (programming language) code Computability theory Formal methods Models of computation Theoretical computer science