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 form ...
in
mathematical logic Mathematical logic is the study of logic, formal logic within mathematics. Major subareas include model theory, proof theory, set theory, and recursion theory. Research in mathematical logic commonly addresses the mathematical properties of for ...
for expressing
computation Computation is any type of arithmetic or non-arithmetic calculation that follows a well-defined model (e.g., an algorithm). Mechanical or electronic devices (or, historically, people) that perform computations are known as ''computers''. An es ...
based on function
abstraction Abstraction in its main sense is a conceptual process wherein general rules and concepts are derived from the usage and classification of specific examples, literal ("real" or "concrete") signifiers, first principles, or other methods. "An abstr ...
and application using variable binding and substitution. It is a universal
model of computation In computer science, and more specifically in computability theory and computational complexity theory, a model of computation is a model which describes how an output of a mathematical function is computed given an input. A model describes how ...
that can be used to simulate any
Turing machine A Turing machine is a mathematical model of computation describing an abstract machine that manipulates symbols on a strip of tape according to a table of rules. Despite the model's simplicity, it is capable of implementing any computer algori ...
. It was introduced by the mathematician
Alonzo Church Alonzo Church (June 14, 1903 – August 11, 1995) was an American mathematician, computer scientist, logician, philosopher, professor and editor who made major contributions to mathematical logic and the foundations of theoretical computer scien ...
in the 1930s as part of his research into the
foundations of mathematics Foundations of mathematics is the study of the philosophical and logical and/or algorithmic basis of mathematics, or, in a broader sense, the mathematical investigation of what underlies the philosophical theories concerning the nature of mathe ...
. Lambda calculus consists of constructing § lambda terms and performing § reduction operations on them. In the simplest form of lambda calculus, terms are built using only the following rules: * 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 Bound or bounds may refer to: Mathematics * Bound variable * Upper and lower bounds, observed limits of mathematical functions Physics * Bound state, a particle that has a tendency to remain localized in one or more regions of space Geography *B ...
in the expression. * (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 collision In computer programming, a name collision is the nomenclature problem that occurs when the same variable name is used for different things in two separate areas that are joined, merged, or otherwise go from occupying separate namespaces to shari ...
s. * ((\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 ...
ing is used, then α-conversion is no longer required as there will be no name collisions. If repeated application of the reduction steps eventually terminates, then by the
Church–Rosser theorem In lambda calculus, the Church–Rosser theorem states that, when applying reduction rules to terms, the ordering in which the reductions are chosen does not make a difference to the eventual result. More precisely, if there are two distinct red ...
it will produce a β-normal form. Variable names are not needed if using a universal lambda function, such as Iota and Jot, which can create any function behavior by calling it on itself in various combinations.


Explanation and applications

Lambda calculus is
Turing complete Alan Mathison Turing (; 23 June 1912 – 7 June 1954) was an English mathematician, computer scientist, logician, cryptanalyst, philosopher, and theoretical biologist. Turing was highly influential in the development of theoretical co ...
, that is, it is a universal
model of computation In computer science, and more specifically in computability theory and computational complexity theory, a model of computation is a model which describes how an output of a mathematical function is computed given an input. A model describes how ...
that can be used to simulate any
Turing machine A Turing machine is a mathematical model of computation describing an abstract machine that manipulates symbols on a strip of tape according to a table of rules. Despite the model's simplicity, it is capable of implementing any computer algori ...
. Its namesake, the Greek letter lambda (λ), is used in lambda expressions and lambda terms to denote binding a variable in a
function Function or functionality may refer to: Computing * Function key, a type of key on computer keyboards * Function model, a structured representation of processes in a system * Function object or functor or functionoid, a concept of object-oriente ...
. Lambda calculus may be ''untyped'' or ''typed''. In typed lambda calculus, functions can be applied only if they are capable of accepting the given input's "type" of data. Typed lambda calculi are ''weaker'' than the untyped lambda calculus, which is the primary subject of this article, in the sense that ''typed lambda calculi can express less'' than the untyped calculus can, but on the other hand typed lambda calculi allow more things to be proven; in the
simply typed lambda calculus The simply typed lambda calculus (\lambda^\to), a form of type theory, is a typed interpretation of the lambda calculus with only one type constructor (\to) that builds function types. It is the canonical and simplest example of a typed lambda c ...
it is, for example, a theorem that every evaluation strategy terminates for every simply typed lambda-term, whereas evaluation of untyped lambda-terms §need not terminate. One reason there are many different typed lambda calculi has been the desire to do more (of what the untyped calculus can do) without giving up on being able to prove strong theorems about the calculus. Lambda calculus has applications in many different areas in
mathematics Mathematics is an area of knowledge that includes the topics of numbers, formulas and related structures, shapes and the spaces in which they are contained, and quantities and their changes. These topics are represented in modern mathematics ...
,
philosophy Philosophy (from , ) is the systematized study of general and fundamental questions, such as those about existence, reason, knowledge, values, mind, and language. Such questions are often posed as problems to be studied or resolved. Some ...
,
linguistics Linguistics is the scientific study of human language. It is called a scientific study because it entails a comprehensive, systematic, objective, and precise analysis of all aspects of language, particularly its nature and structure. Linguis ...
, and
computer science Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
. Lambda calculus has played an important role in the development of the theory of programming languages.
Functional programming language In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that ...
s implement lambda calculus. Lambda calculus is also a current research topic in category theory.


History

The lambda calculus was introduced by mathematician
Alonzo Church Alonzo Church (June 14, 1903 – August 11, 1995) was an American mathematician, computer scientist, logician, philosopher, professor and editor who made major contributions to mathematical logic and the foundations of theoretical computer scien ...
in the 1930s as part of an investigation into the
foundations of mathematics Foundations of mathematics is the study of the philosophical and logical and/or algorithmic basis of mathematics, or, in a broader sense, the mathematical investigation of what underlies the philosophical theories concerning the nature of mathe ...
. The original system was shown to be logically inconsistent in 1935 when
Stephen Kleene Stephen Cole Kleene ( ; January 5, 1909 – January 25, 1994) was an American mathematician. One of the students of Alonzo Church, Kleene, along with Rózsa Péter, Alan Turing, Emil Post, and others, is best known as a founder of the branch of ...
and J. B. Rosser developed the
Kleene–Rosser paradox In mathematics, the Kleene–Rosser paradox is a paradox that shows that certain systems of formal logic are inconsistent, in particular the version of Haskell Curry's combinatory logic introduced in 1930, and Alonzo Church's original lambda ca ...
. Subsequently, in 1936 Church isolated and published just the portion relevant to computation, what is now called the untyped lambda calculus. In 1940, he also introduced a computationally weaker, but logically consistent system, known as the
simply typed lambda calculus The simply typed lambda calculus (\lambda^\to), a form of type theory, is a typed interpretation of the lambda calculus with only one type constructor (\to) that builds function types. It is the canonical and simplest example of a typed lambda c ...
. Until the 1960s when its relation to programming languages was clarified, the lambda calculus was only a formalism. Thanks to
Richard Montague Richard Merritt Montague (September 20, 1930 – March 7, 1971) was an American mathematician and philosopher who made contributions to mathematical logic and the philosophy of language. He is known for proposing Montague grammar to formalize ...
and other linguists' applications in the semantics of natural language, the lambda calculus has begun to enjoy a respectable place in both linguistics and computer science.


Origin of the lambda symbol

There is some uncertainty over the reason for Church's use of the Greek letter
lambda Lambda (}, ''lám(b)da'') is the 11th letter of the Greek alphabet, representing the voiced alveolar lateral approximant . In the system of Greek numerals, lambda has a value of 30. Lambda is derived from the Phoenician Lamed . Lambda gave rise ...
(λ) as the notation for function-abstraction in the lambda calculus, perhaps in part due to conflicting explanations by Church himself. According to Cardone and Hindley (2006):
By the way, why did Church choose the notation “λ”? In
n unpublished 1964 letter to Harald Dickson N, or n, is the fourteenth letter in the Latin alphabet, used in the modern English alphabet, the alphabets of other western European languages and others worldwide. Its name in English is ''en'' (pronounced ), plural ''ens''. History ...
he stated clearly that it came from the notation “\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 In formal semantics and philosophy of language, a definite description is a denoting phrase in the form of "the X" where X is a noun-phrase or a singular common noun. The definite description is ''proper'' if X applies to a unique individual or o ...
, Hilbert had the
epsilon operator Hilbert's epsilon calculus is an extension of a formal language by the epsilon operator, where the epsilon operator substitutes for quantifiers in that language as a method leading to a proof of consistency for the extended formal language. The ' ...
. Why did you choose lambda for your operator?
According to Scott, Church's entire response consisted of returning the postcard with the following annotation: "
eeny, meeny, miny, moe "Eeny, meeny, miny, moe"—which can be spelled a number of ways—is a children's counting-out rhyme, used to select a person in games such as tag, or for selecting various other things. It is one of a large group of similar rhymes in which the ...
".


Informal description


Motivation

Computable function Computable functions are the basic objects of study in computability theory. Computable functions are the formalized analogue of the intuitive notion of algorithms, in the sense that a function is computable if there exists an algorithm that can do ...
s are a fundamental concept within computer science and mathematics. The lambda calculus provides simple
semantics Semantics (from grc, σημαντικός ''sēmantikós'', "significant") is the study of reference, meaning, or truth. The term can be used to refer to subfields of several distinct disciplines, including philosophy Philosophy (f ...
for computation which are useful for formally studying properties of computation. The lambda calculus incorporates two simplifications that make its semantics simple. The first simplification is that the lambda calculus treats functions "anonymously;" it does not give them explicit names. For example, the function : \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, transforms a function that takes multiple arguments into a chain of functions each with a single argument. Function application 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 stud ...
or as an
operational definition An operational definition specifies concrete, replicable procedures designed to represent a construct. In the words of American psychologist S.S. Stevens (1935), "An operation is the performance which we execute in order to make known a concept." F ...
. As described above, having no names, all functions in the lambda calculus are anonymous functions. They only accept one input variable, so currying is used to implement functions of several variables.


Lambda terms

The syntax of the lambda calculus defines some expressions as valid lambda calculus expressions and some as invalid, just as some strings of characters are valid C programs and some are not. A valid lambda calculus expression is called a "lambda term". The following three rules give an
inductive definition In mathematics and computer science, a recursive definition, or inductive definition, is used to define the elements in a set in terms of other elements in the set ( Aczel 1977:740ff). Some examples of recursively-definable objects include fact ...
that can be applied to build all syntactically valid lambda terms: * variable is itself a valid lambda term. *if is a lambda term, and is a variable, then (\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 In programming language theory, the associativity of an operator is a property that determines how operators of the same precedence are grouped in the absence of parentheses. If an operand is both preceded and followed by operators (for exampl ...
, so that 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. 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 progr ...
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 comput ...
.


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 practi ...
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 * Cinem ...
(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 ...
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 α-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 b ...
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 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 n ...
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 ...
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—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 mathematics, mathematical operation (mathematics), operation, written as , involving two numbers, the ''Base (exponentiation), base'' and the ''exponent'' or ''power'' , and pronounced as " (raised) to the (power of) ". W ...
, 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 In programming language theory, semantics is the rigorous mathematical study of the meaning of programming languages. Semantics assigns computational meaning to valid strings in a programming language syntax. Semantics describes the processe ...
, 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 vir ...
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 mathemati ...
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 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. 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 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 comput ...
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 The SKI combinator calculus is a combinatory logic system and a computational system. It can be thought of as a computer programming language, though it is not convenient for writing software. Instead, it is important in the mathematical theory o ...
.


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) * Scie ...
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 Lambda calculus (also written as ''λ''-calculus) is a formal system in mathematical logic for expressing computation based on function abstraction and application using variable binding and substitution. It is a universal model of computation tha ...
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 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 m ...
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 c ...
languages. Typed lambda calculi play an important role in the design of
type systems In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a type (computer science), type to every "term" (a word, phrase, or other set of symbols). Usually the terms are various constru ...
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 logic, formal logic within mathematics. Major subareas include model theory, proof theory, set theory, and recursion theory. Research in mathematical logic commonly addresses the mathematical properties of for ...
and proof theory via the Curry–Howard isomorphism and they can be considered as the
internal language __NOTOC__ Categorical logic is the branch of mathematics in which tools and concepts from category theory are applied to the study of mathematical logic. It is also notable for its connections to theoretical computer science. In broad terms, categ ...
of classes of
categories Category, plural categories, may refer to: Philosophy and general uses *Categorization, categories in cognitive science, information science and generally *Category of being * ''Categories'' (Aristotle) *Category (Kant) * Categories (Peirce) * ...
, 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 ma ...
(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 co ...
. 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 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 his ...
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 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 term. Loosely speaking, they can be understood as a kind of memoization for free variable ...
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 computer science, lambda calculus, lambda calculi are said to have explicit substitutions if they pay special attention to the formalization of the process of substitution of variables, substitution. This is in contrast to the standard lambda cal ...
. 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 Peter John Landin (5 June 1930 – 3 June 2009) was a British computer scientist. He was one of the first to realise that the lambda calculus could be used to model a programming language, an insight that is essential to the development of bo ...
'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 Python may refer to: Snakes * Pythonidae, a family of nonvenomous snakes found in Africa, Asia, and Australia ** ''Python'' (genus), a genus of Pythonidae found in Africa and Asia * Python (mythology), a mythical serpent Computing * Python (pro ...
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 and many other imperative languages have long supported passing
subprograms In computer programming, a function or subroutine is a sequence of Instruction (computer science), program instructions that performs a specific task, packaged as a unit. This unit can then be used in programs wherever that particular task shou ...
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. 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,
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 Website, websites use JavaScript on the Client (computing), client side ...
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 Eiffel may refer to: Places * Eiffel Peak, a summit in Alberta, Canada * Champ de Mars – Tour Eiffel station, Paris, France; a transit station Structures * Eiffel Tower, in Paris, France, designed by Gustave Eiffel * Eiffel Bridge, Ungheni, M ...
("agents"), C# ("delegates") and
C++11 C++11 is a version of the ISO/ IEC 14882 standard for the C++ programming language. C++11 replaced the prior version of the C++ standard, called C++03, and was later replaced by C++14. The name follows the tradition of naming language versions b ...
, 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 * Do ...
''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 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 form ...
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 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. Unlike lambda calculus, kappa calculus has no higher-order functions; its functions are not first class objects ...
– 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 comput ...
– A notation for mathematical logic without variables *
SKI combinator calculus The SKI combinator calculus is a combinatory logic system and a computational system. It can be thought of as a computer programming language, though it is not convenient for writing software. Instead, it is important in the mathematical theory o ...
– 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 Applicative computing systems, or ACS are the systems of object calculi founded on combinatory logic and lambda calculus. The only essential notion which is under consideration in these systems is the representation of object. In combinatory log ...
– 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 ...
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 * 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 ...
– 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 ex ...
– 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 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 In computer science, lambda calculus, lambda calculi are said to have explicit substitutions if they pay special attention to the formalization of the process of substitution of variables, substitution. This is in contrast to the standard lambda cal ...
– The theory of substitution, as used in
β-reduction Lambda calculus (also written as ''λ''-calculus) is a formal system in mathematical logic for expressing computation based on function abstraction and application using variable binding and substitution. It is a universal model of computation ...
*
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 that ...
*
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 Harr ...
– 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. Intera ...
*
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 The Knights of the Lambda Calculus is a semi-fictional organization of expert Lisp (programming language), Lisp and Scheme (programming language), Scheme Hacker (programmer subculture), hackers. The name refers to the lambda calculus, a mathematic ...
– 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 A hacker is a person skilled in information technology who uses their technical knowledge to achieve a goal or overcome an obstacle, within a computerized system by non-standard means. Though the term ''hacker'' has become associated in popu ...
*
Krivine machine In theoretical computer science, the Krivine machine is an ''abstract machine'' (sometimes called ''virtual machine''). As an abstract machine, it shares features with Turing machines and the SECD machine. The Krivine machine explains how to com ...
– An abstract machine to interpret call-by-name in lambda calculus *
Lambda calculus definition Lambda calculus is a formal mathematical system based on lambda abstraction and function application. Two definitions of the language are given here: a standard definition, and a definition using mathematical formulas. Standard definition Th ...
– 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 ...
– 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 well-formed formula, formula with other terms. Such methods may be achieved by rewriting systems (also known as rewrite systems, rewr ...
– Transformation of formulæ in formal systems *
SECD machine The SECD machine is a highly influential (''see: '') virtual machine and abstract machine intended as a target for functional programming language compilers. The letters stand for Stack, Environment, Control, Dump—the internal registers of the mac ...
– 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 hardw ...
designed for the lambda calculus * Scott–Curry theorem – 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 comput ...
*
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 a ...
functional programming language based on combinatory logic


Further reading

* Abelson, Harold & Gerald Jay Sussman.
Structure and Interpretation of Computer Programs ''Structure and Interpretation of Computer Programs'' (''SICP'') is a computer science textbook by Massachusetts Institute of Technology professors Harold Abelson and Gerald Jay Sussman with Julie Sussman. It is known as the "Wizard Book" in ha ...
.
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 with ...
, 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) * Dana Scott,
A timeline of lambda calculus
'-( PDF) * Raúl Rojas,
A Tutorial Introduction to the Lambda Calculus
'-( PDF) * Peter Selinger,
Lecture Notes on the Lambda Calculus
'-( PDF) * Marius Buliga
''Graphic lambda calculus''

''Lambda Calculus as a Workflow Model''
by Peter Kelly, Paul Coddington, and Andrew Wendelborn; mentions
graph reduction In computer science, graph reduction implements an efficient version of non-strict evaluation, an evaluation strategy where the arguments to a function are not immediately evaluated. This form of non-strict evaluation is also known as lazy evaluati ...
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 computer network, networked computers, which communicate and coordinate their actions by message passing, passing messages to one another from any system. Distributed com ...
(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 of ...
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 C, or c, is the third Letter (alphabet), letter in the Latin alphabet, used in the English alphabet, modern English alphabet, the alphabets of other western European languages and others worldwide. Its name in English is English alphabet#Le ...
* 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 pape ...
'' * 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