HOME

TheInfoList



OR:

In
mathematical logic Mathematical logic is the study of Logic#Formal logic, formal logic within mathematics. Major subareas include model theory, proof theory, set theory, and recursion theory (also known as computability theory). Research in mathematical logic com ...
, the lambda calculus (also written as ''λ''-calculus) is a
formal system A formal system is an abstract structure and formalization of an axiomatic system used for deducing, using rules of inference, theorems from axioms. In 1921, David Hilbert proposed to use formal systems as the foundation of knowledge in ma ...
for expressing
computation A computation is any type of arithmetic or non-arithmetic calculation that is well-defined. Common examples of computation are mathematical equation solving and the execution of computer algorithms. Mechanical or electronic devices (or, hist ...
based on function
abstraction Abstraction is a process where general rules and concepts are derived from the use and classifying of specific examples, literal (reality, real or Abstract and concrete, concrete) signifiers, first principles, or other methods. "An abstraction" ...
and application using variable binding and substitution. Untyped lambda calculus, the topic of this article, is a universal machine, a
model of computation In computer science, and more specifically in computability theory and computational complexity theory, a model of computation is a model which describes how an output of a mathematical function is computed given an input. A model describes how ...
that can be used to simulate any
Turing machine A Turing machine is a mathematical model of computation describing an abstract machine that manipulates symbols on a strip of tape according to a table of rules. Despite the model's simplicity, it is capable of implementing any computer algori ...
(and vice versa). It was introduced by the mathematician
Alonzo Church Alonzo Church (June 14, 1903 – August 11, 1995) was an American computer scientist, mathematician, logician, and philosopher who made major contributions to mathematical logic and the foundations of theoretical computer science. He is bes ...
in the 1930s as part of his research into the
foundations of mathematics Foundations of mathematics are the mathematical logic, logical and mathematics, mathematical framework that allows the development of mathematics without generating consistency, self-contradictory theories, and to have reliable concepts of theo ...
. In 1936, Church found a formulation which was logically consistent, and documented it in 1940. Lambda calculus consists of constructing lambda terms and performing reduction operations on them. A term is defined as any valid lambda calculus expression. In the simplest form of lambda calculus, terms are built using only the following rules: # x: A variable is a character or string representing a parameter. # (\lambda x.M): A lambda abstraction is a function definition, taking as input the bound variable x (between the λ and the punctum/dot .) and returning the body M. # (M\ N): An application, applying a function M to an argument N. Both M and N are lambda terms. The reduction operations include: * (\lambda x.M \rightarrow(\lambda y.M :
α-conversion In mathematical logic, the lambda calculus (also written as ''λ''-calculus) is a formal system for expressing computation based on function abstraction and application using variable binding and substitution. Untyped lambda calculus, the topic ...
, renaming the bound variables in the expression. Used to avoid
name collision In computer programming, a name collision is the nomenclature problem that occurs when the same variable name is used for different things in two separate areas that are joined, merged, or otherwise go from occupying separate namespaces to shari ...
s. * ((\lambda x.M)\ N)\rightarrow (M :=N :
β-reduction In mathematical logic, the lambda calculus (also written as ''λ''-calculus) is a formal system for expressing computation based on function abstraction and application using variable binding and substitution. Untyped lambda calculus, the topic ...
, replacing the bound variables with the argument expression in the body of the abstraction. If
De Bruijn index In mathematical logic, the de Bruijn index is a tool invented by the Dutch mathematician Nicolaas Govert de Bruijn for representing terms of lambda calculus without naming the bound variables. Terms written using these indices are invariant with ...
ing is used, then α-conversion is no longer required as there will be no name collisions. If repeated application of the reduction steps eventually terminates, then by the
Church–Rosser theorem In lambda calculus, the Church–Rosser theorem states that, when applying reduction rules to terms, the ordering in which the reductions are chosen does not make a difference to the eventual result. More precisely, if there are two distinct r ...
it will produce a β-normal form. Variable names are not needed if using a universal lambda function, such as
Iota and Jot In formal language theory and computer science, Iota and Jot (from Greek iota ι, Hebrew yodh י, the smallest letters in those two alphabets) are languages, extremely minimalist formal systems, designed to be even simpler than other more popula ...
, which can create any function behavior by calling it on itself in various combinations.


Explanation and applications

Lambda calculus is
Turing complete Alan Mathison Turing (; 23 June 1912 – 7 June 1954) was an English mathematician, computer scientist, logician, cryptanalyst, philosopher and theoretical biologist. He was highly influential in the development of theoretical comput ...
, that is, it is a universal
model of computation In computer science, and more specifically in computability theory and computational complexity theory, a model of computation is a model which describes how an output of a mathematical function is computed given an input. A model describes how ...
that can be used to simulate any
Turing machine A Turing machine is a mathematical model of computation describing an abstract machine that manipulates symbols on a strip of tape according to a table of rules. Despite the model's simplicity, it is capable of implementing any computer algori ...
. Its namesake, the Greek letter lambda (λ), is used in lambda expressions and lambda terms to denote binding a variable in a function. Lambda calculus may be ''untyped'' or ''typed''. In typed lambda calculus, functions can be applied only if they are capable of accepting the given input's "type" of data. Typed lambda calculi are strictly ''weaker'' than the untyped lambda calculus, which is the primary subject of this article, in the sense that ''typed lambda calculi can express less'' than the untyped calculus can. On the other hand, more things can be proven with typed lambda calculi. For example, in
simply typed lambda calculus The simply typed lambda calculus (), a form of type theory, is a typed interpretation of the lambda calculus with only one type constructor () that builds function types. It is the canonical and simplest example of a typed lambda calculus. The ...
, it is a theorem that every evaluation strategy terminates for every simply typed lambda-term, whereas evaluation of untyped lambda-terms need not terminate (see below). One reason there are many different typed lambda calculi has been the desire to do more (of what the untyped calculus can do) without giving up on being able to prove strong theorems about the calculus. Lambda calculus has applications in many different areas in
mathematics Mathematics is a field of study that discovers and organizes methods, Mathematical theory, theories and theorems that are developed and Mathematical proof, proved for the needs of empirical sciences and mathematics itself. There are many ar ...
,
philosophy Philosophy ('love of wisdom' in Ancient Greek) is a systematic study of general and fundamental questions concerning topics like existence, reason, knowledge, Value (ethics and social sciences), value, mind, and language. It is a rational an ...
,
linguistics Linguistics is the scientific study of language. The areas of linguistic analysis are syntax (rules governing the structure of sentences), semantics (meaning), Morphology (linguistics), morphology (structure of words), phonetics (speech sounds ...
, and
computer science Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
. Lambda calculus has played an important role in the development of the
theory A theory is a systematic and rational form of abstract thinking about a phenomenon, or the conclusions derived from such thinking. It involves contemplative and logical reasoning, often supported by processes such as observation, experimentation, ...
of
programming language A programming language is a system of notation for writing computer programs. Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
s.
Functional programming In computer science, functional programming is a programming paradigm where programs are constructed by Function application, applying and Function composition (computer science), composing Function (computer science), functions. It is a declarat ...
languages implement lambda calculus. Lambda calculus is also a current research topic in
category theory Category theory is a general theory of mathematical structures and their relations. It was introduced by Samuel Eilenberg and Saunders Mac Lane in the middle of the 20th century in their foundational work on algebraic topology. Category theory ...
.


History

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


Origin of the ''λ'' symbol

There is some uncertainty over the reason for Church's use of the Greek letter
lambda Lambda (; uppercase , lowercase ; , ''lám(b)da'') is the eleventh letter of the Greek alphabet, representing the voiced alveolar lateral approximant . In the system of Greek numerals, lambda has a value of 30. Lambda is derived from the Phoen ...
(λ) as the notation for function-abstraction in the lambda calculus, perhaps in part due to conflicting explanations by Church himself. According to Cardone and Hindley (2006):
By the way, why did Church choose the notation "λ"? In n unpublished 1964 letter to Harald Dicksonhe stated clearly that it came from the notation "\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, C ...
has also addressed this question in various public lectures. Scott recounts that he once posed a question about the origin of the lambda symbol to Church's former student and son-in-law John W. Addison Jr., who then wrote his father-in-law a postcard:
Dear Professor Church, Russell had the iota operator, Hilbert had the epsilon operator. Why did you choose lambda for your operator?
According to Scott, Church's entire response consisted of returning the postcard with the following annotation: " eeny, meeny, miny, moe".


Informal description


Motivation

Computable function Computable functions are the basic objects of study in computability theory. Informally, a function is ''computable'' if there is an algorithm that computes the value of the function for every value of its argument. Because of the lack of a precis ...
s are a fundamental concept within computer science and mathematics. The lambda calculus provides simple
semantics Semantics is the study of linguistic Meaning (philosophy), meaning. It examines what meaning is, how words get their meaning, and how the meaning of a complex expression depends on its parts. Part of this process involves the distinction betwee ...
for computation which are useful for formally studying properties of computation. The lambda calculus incorporates two simplifications that make its semantics simple. The first simplification is that the lambda calculus treats functions "anonymously"; it does not give them explicit names. For example, the function : \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 sequence or ''ordered list'' of numbers or, more generally, mathematical objects, which are called the ''elements'' of the tuple. An -tuple is a tuple of elements, where is a non-negative integer. There is o ...
of and is mapped to x^2 + y^2"). Similarly, the function : \operatorname(x) = x can be rewritten in anonymous form as : x \mapsto x where the input is simply mapped to itself. The second simplification is that the lambda calculus only uses functions of a single input. An ordinary function that requires two inputs, for instance the \operatorname function, can be reworked into an equivalent function that accepts a single input, and as output returns ''another'' function, that in turn accepts a single input. For example, : (x, y) \mapsto x^2 + y^2 can be reworked into : x \mapsto (y \mapsto x^2 + y^2) This method, known as
currying In mathematics and computer science, currying is the technique of translating a function that takes multiple arguments into a sequence of families of functions, each taking a single argument. In the prototypical example, one begins with a functi ...
, transforms a function that takes multiple arguments into a chain of functions each with a single argument.
Function application In mathematics, function application is the act of applying a function to an argument from its domain so as to obtain the corresponding value from its range. In this sense, function application can be thought of as the opposite of function abs ...
of the \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 or as an
operational definition An operational definition specifies concrete, replicable procedures designed to represent a construct. In the words of American psychologist S.S. Stevens (1935), "An operation is the performance which we execute in order to make known a concept." F ...
. As described above, having no names, all functions in the lambda calculus are anonymous functions. They only accept one input variable, so
currying In mathematics and computer science, currying is the technique of translating a function that takes multiple arguments into a sequence of families of functions, each taking a single argument. In the prototypical example, one begins with a functi ...
is used to implement functions of several variables.


Lambda terms

The syntax of the lambda calculus defines some expressions as valid lambda calculus expressions and some as invalid, just as some strings of characters are valid computer programs and some are not. A valid lambda calculus expression is called a "lambda term". The following three rules give an
inductive definition In mathematics and computer science, a recursive definition, or inductive definition, is used to define the elements in a set in terms of other elements in the set ( Aczel 1977:740ff). Some examples of recursively definable objects include fact ...
that can be applied to build all syntactically valid lambda terms: * variable is itself a valid lambda term. *if is a lambda term, and is a variable, then (\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. That is, a lambda term is valid if and only if it can be obtained by repeated application of these three rules. For convenience, some parentheses can be omitted when writing a lambda term. For example, the outermost parentheses are usually not written. See § Notation, below, for an explicit description of which parentheses are optional. It is also common to extend the syntax presented here with additional operations, which allows making sense of terms such as \lambda x.x^2. The focus of this article is the pure lambda calculus without extensions, but lambda terms extended with arithmetic operations are used for explanatory purposes. An ''abstraction'' \lambda x.t denotes an § anonymous function that takes a single input and returns . For example, \lambda x.(x^2+2) is an abstraction representing the function f defined by f(x) = x^2 + 2, using the term x^2+2 for . The name f is superfluous when using abstraction. The syntax (\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). A lambda term may refer to a variable that has not been bound, such as the term \lambda x.(x+y) (which represents the function definition f(x) = x + y). In this term, the variable has not been defined and is considered an unknown. The abstraction \lambda x.(x+y) is a syntactically valid term and represents a function that adds its input to the yet-unknown . Parentheses may be used and might be needed to disambiguate terms. For example, #\lambda x.((\lambda x.x)x) is of form \lambda x.B and is therefore an abstraction, while #(\lambda x.(\lambda x.x)) x is of form M N and is therefore an application. The examples 1 and 2 denote different terms, differing only in where the parentheses are placed. They have different meanings: example 1 is a function definition, while example 2 is a function application. The lambda variable is a placeholder in both examples. Here, example 1 ''defines'' a function \lambda x.B, where B is (\lambda x.x)x, an anonymous function (\lambda x.x), with input x; while example 2, M  N, is M applied to N, where M is the lambda term (\lambda x.(\lambda x.x)) being applied to the input N which is x. Both examples 1 and 2 would evaluate to the
identity function Graph of the identity function on the real numbers In mathematics, an identity function, also called an identity relation, identity map or identity transformation, is a function that always returns the value that was used as its argument, unc ...
\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, the lambda term \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, unc ...
, x \mapsto x. Further, \lambda x.y represents the ''constant function'' x \mapsto y, the function that always returns y, no matter the input. As an example of a function operating on functions, the
function composition In mathematics, the composition operator \circ takes two function (mathematics), functions, f and g, and returns a new function h(x) := (g \circ f) (x) = g(f(x)). Thus, the function is function application, applied after applying to . (g \c ...
can be defined as \lambda f. \lambda g. \lambda x. (f ( g x)). There are several notions of "equivalence" and "reduction" that make it possible to "reduce" lambda terms to "equivalent" lambda terms.


Alpha equivalence

A basic form of equivalence, definable on lambda terms, is ''alpha equivalence''. It captures the intuition that the particular choice of a bound variable, in an abstraction, does not (usually) matter. For instance, \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

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 ; with r substituted for x, x becomes r * y := r= y if x \neq y ; with r substituted for x, y (which is not x) remains y * (t s) := r= (t := r(s := r ; substitution distributes to both sides of an application * (\lambda x.t) := r= \lambda x.t ; a variable bound by an abstraction is not subject to substitution; substituting such variable leaves the abstraction unchanged * (\lambda y.t) := r= \lambda y.(t := r if x \neq y and y does not appear among the free variables of r (y is said to be " fresh" for r) ; substituting a variable which is not bound by an abstraction proceeds in the abstraction's body, provided that the abstracted variable y is "fresh" for the substitution term 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 In mathematics, and in other disciplines involving formal languages, including mathematical logic and computer science, a variable may be said to be either free or bound. Some older books use the terms real variable and apparent variable for f ...
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 could lead to errors: (\lambda x.y) := x= \lambda x.(y := x = \lambda x.x. This erroneous substitution would turn the constant function \lambda x.y into the identity \lambda x.x. In general, failure to meet the freshness condition can be remedied by alpha-renaming first, 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 pioneered several programming language ...
or
Standard ML Standard ML (SML) is a General-purpose programming language, general-purpose, High-level programming language, high-level, Modular programming, modular, Functional programming, functional programming language with compile-time type checking and t ...
. 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''). Truth values are used in ...
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''. ''See § reducible expression'' This set of rules may be written in
Backus–Naur form In computer science, Backus–Naur form (BNF, pronounced ), also known as Backus normal form, is a notation system for defining the Syntax (programming languages), syntax of Programming language, programming languages and other Formal language, for ...
as: ::= , , ::= λ . ::= ( ) ::= v1 , v2 , ...


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 prepending λ''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: # , where ''x'' is a variable. # . # An expression that contains no free variables is said to be ''closed''. Closed lambda expressions are also known as ''combinators'' and are equivalent to terms in
combinatory logic Combinatory logic is a notation to eliminate the need for quantified variables in mathematical logic. It was introduced by Moses Schönfinkel and Haskell Curry, and has more recently been used in computer science as a theoretical model of com ...
.


Reduction

The meaning of lambda expressions is defined by how expressions can be reduced. There are three kinds of reduction: * ''α-conversion'': changing bound variables; * ''β-reduction'': applying functions to their arguments; * ''η-conversion'': expressing 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 (
alpha Alpha (uppercase , lowercase ) is the first letter of the Greek alphabet. In the system of Greek numerals, it has a value of one. Alpha is derived from the Phoenician letter ''aleph'' , whose name comes from the West Semitic word for ' ...
-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 th ...
. 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 employed for rituals and rites. Masks have been used since antiquity for both ceremonial and practical purposes, ...
a name in a containing scope (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 Two Mathematical object, mathematical objects and are called "equal up to an equivalence relation " * if and are related by , that is, * if holds, that is, * if the equivalence classes of and with respect to are equal. This figure of speech ...
α-equivalence. Substitution is defined uniquely up to α-equivalence. ''See Capture-avoiding substitutions above''.


β-reduction

β-reduction (
beta Beta (, ; uppercase , lowercase , or cursive ; or ) is the second letter of the Greek alphabet. In the system of Greek numerals, it has a value of 2. In Ancient Greek, beta represented the voiced bilabial plosive . In Modern Greek, it represe ...
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 ...
, via the Curry–Howard isomorphism.


η-conversion

η-conversion (
eta Eta ( ; uppercase , lowercase ; ''ē̂ta'' or ''ita'' ) is the seventh letter of the Greek alphabet, representing the close front unrounded vowel, . Originally denoting the voiceless glottal fricative, , in most dialects of Ancient Greek, it ...
conversion) expresses the idea of
extensionality In logic, extensionality, or extensional equality, refers to principles that judge objects to be equality (mathematics), equal if they have the same external properties. It stands in contrast to the concept of intensionality, which is concerned wi ...
,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" (often shortened as "iff") is paraphrased by the biconditional, a logical connective between statements. The biconditional is true in two cases, where either bo ...
they give the same result for all arguments. η-conversion converts between λ''x''.''f'' ''x'' and ''f'' whenever ''x'' does not appear free in ''f''. η-reduction changes λ''x''.''f'' ''x'' to ''f'', and η-expansion changes ''f'' to λ''x''.''f'' ''x'', under the same requirement that ''x'' does not appear free in ''f''. η-conversion 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 ...
, 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. However, it can be shown that β-reduction is confluent 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
arithmetic Arithmetic is an elementary branch of mathematics that deals with numerical operations like addition, subtraction, multiplication, and division. In a wider sense, it also includes exponentiation, extraction of roots, and taking logarithms. ...
, Booleans, data structures, and recursion, as illustrated in the following sub-sections '' i'', '' ii'', '' iii'', and '' § iv''.


Arithmetic in lambda calculus

There are several possible ways to define the
natural number In mathematics, the natural numbers are the numbers 0, 1, 2, 3, and so on, possibly excluding 0. Some start counting with 0, defining the natural numbers as the non-negative integers , while others start with 1, defining them as the positive in ...
s in lambda calculus, but by far the most common are the Church numerals, which can be defined as follows: : : : : and so on. Or using the alternative syntax presented above in ''
Notation In linguistics and semiotics, a notation system is a system of graphics or symbols, Character_(symbol), characters and abbreviated Expression (language), expressions, used (for example) in Artistic disciplines, artistic and scientific disciplines ...
'': : : : : A Church numeral is a
higher-order function In mathematics and computer science, a higher-order function (HOF) is a function that does at least one of the following: * takes one or more functions as arguments (i.e. a procedural parameter, which is a parameter of a procedure that is itself ...
—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 Composition or Compositions may refer to: Arts and literature *Composition (dance), practice and teaching of choreography * Composition (language), in literature and rhetoric, producing a work in spoken tradition and written discourse, to include ...
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. Functional composition is
associative In mathematics, the associative property is a property of some binary operations that rearranging the parentheses in an expression will not change the result. In propositional logic, associativity is a valid rule of replacement for express ...
, and so, such repeated compositions of a single function obey two laws of exponents, and , 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 analyzing 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 A list is a Set (mathematics), set of discrete items of information collected and set forth in some format for utility, entertainment, or other purposes. A list may be memorialized in any number of ways, including existing only in the mind of t ...
of ''n'' elements all equal to ''x'' by repeating 'prepend another ''x'' element' ''n'' times, starting from an empty list. The lambda term : creates, given a Church numeral and some , a sequence of ''n'' applications : By varying what is being repeated, and what argument(s) 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 its successor by performing one additional application of the function it is supplied with, where means "''n'' applications of ''f'' starting from ''x''": : Because the -th composition of composed with the -th composition of gives the -th composition of , , addition can be defined as : 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 beta-equivalent lambda expressions. Since adding to a number can be accomplished by repeating the successor operation times, an alternative definition is: : Similarly, following , multiplication can be defined as : Thus multiplication of Church numerals is simply their composition as functions. Alternatively : since multiplying and is the same as adding repeatedly, times, starting from zero. Exponentiation, being the repeated multiplication of a number with itself, translates as a repeated composition of a Church numeral with itself, as a function. And repeated composition is what Church numerals ''are'': : Alternatively here as well, : Simplifying, it becomes : but that is just an eta-expanded version of we already have, above. The ''predecessor'' function, specified by two equations and , is considerably more involved. 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 *Conditional proof, in logic: a proof that asserts a conditional, a ...
and the other using pairs. 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 could be 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 , but if its argument were 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 idioms 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. It is closely related to, and ofte ...
, 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, memory or underlying physical hardware; commands or functions in the ...
. 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 Book, books, and possibly other Document, materials and Media (communication), media, that is accessible for use by its members and members of allied institutions. Libraries provide physical (hard copies) or electron ...
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 may not be referenced in ''N'', for ''N'' is outside the scope of the abstraction binding , which is ''M''; this means a recursive function definition cannot be written with . The construction would allow writing recursive function definitions, where the scope of the abstraction binding includes ''N'' as well as ''M''. Or self-application a-la that which leads to combinator could be used.


Recursion and fixed points

Recursion Recursion occurs when the definition of a concept or process depends on a simpler or previous version of itself. Recursion is used in a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in m ...
is when a function invokes itself. What would a value be which were to represent such a function? It has to refer to itself somehow inside itself, just as the definition refers to itself inside itself. If this value were to contain itself by value, it would have to be of infinite size, which is impossible. Other notations, which support recursion natively, overcome this by referring to the function ''by name'' inside its definition. Lambda calculus cannot express this, since in it there simply are no names for terms to begin with, only arguments' names, i.e. parameters in abstractions. Thus, a lambda expression can receive itself as its argument and refer to (a copy of) itself via the corresponding parameter's name. This will work fine in case it was indeed called with itself as an argument. For example, will express recursion when ''E'' is an abstraction which is applying its parameter to itself inside its body to express a recursive call. Since this parameter receives ''E'' as its value, its self-application will be the same again. As a concrete example, consider the
factorial In mathematics, the factorial of a non-negative denoted is the Product (mathematics), product of all positive integers less than or equal The factorial also equals the product of n with the next smaller factorial: \begin n! &= n \times ...
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 with itself as its first argument will amount to the recursive call. Thus to achieve recursion, the intended-as-self-referencing argument (called here, reminiscent of "self", or "self-applying") must always be passed to itself within the function body at a recursive call point: : ::: with to hold, so and : and we have : Here becomes ''the same'' inside the result of the application , and using the same function for a call is the definition of what recursion is. 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 there by the parameter name to be called via the self-application , again and again as needed, each time ''re-creating'' the lambda-term . The application is an additional step just as the name lookup would be. It has the same delaying effect. Instead of having inside itself as a whole ''up-front'', delaying its re-creation until the next call makes its existence possible by having two ''finite'' lambda-terms inside it re-create it on the fly ''later'' as needed. This self-applicational approach solves it, but requires re-writing each recursive call as a self-application. We would like to have a generic solution, without the need for any re-writes: : ::: with to hold, so and : where ::: so that Given a lambda term with first argument representing recursive call (e.g. here), the ''fixed-point'' combinator will return a self-replicating lambda expression representing the recursive function (here, ). The function does not need to be explicitly passed to itself at any point, for the self-replication is arranged in advance, when it is created, to be done each time it is called. Thus the original lambda expression is re-created inside itself, at call-point, achieving
self-reference Self-reference is a concept that involves referring to oneself or one's own attributes, characteristics, or actions. It can occur in language, logic, mathematics, philosophy, and other fields. In natural or formal languages, 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 the recursive call to the factorial function for an argument ''n'', we would simply call . Given ''n'' = 4, for example, this gives: Every recursively defined function can be seen as a fixed point of some suitably defined higher order function (also known as functional) closing over the recursive call with an extra argument. Therefore, using , every recursive function can be expressed as a lambda expression. In particular, we can now cleanly define the subtraction, multiplication, and comparison predicates of natural numbers, using recursion. When
Y combinator Y Combinator, LLC (YC) is an American technology startup accelerator and venture capital firm launched in March 2005 which has been used to launch more than 5,000 companies. The accelerator program started in Boston and Mountain View, Californi ...
is coded directly in a strict programming language, the applicative order of evaluation used in such languages will cause an attempt to fully expand the internal self-application (x x) prematurely, causing
stack overflow In software, a stack overflow occurs if the call stack pointer exceeds the stack bound. The call stack may consist of a limited amount of address space, often determined at the start of the program. The size of the call stack depends on many fa ...
or, in case of tail call optimization, indefinite looping. A delayed variant of Y, the Z combinator, can be used in such languages. It has the internal self-application hidden behind an extra abstraction through eta-expansion, as (\lambda v.x x v), thus preventing its premature expansion: : Z = \lambda f.(\lambda x.f (\lambda v.x x v)) \ (\lambda x.f (\lambda v.x x v))\ .


Standard terms

Certain terms have commonly accepted names: : : : : : : : : is the identity function. and form complete combinator calculus systems that can express any lambda term - see the next section. is , the smallest term that has no normal form. is another such term. is standard and defined above, and can also be defined as , so that . 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 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 that uses the lambda-symbol (\lambda) to denote anonymous function abstraction. In this context, types are usually objects of a syntactic nature that are assigned to lambda terms; the exact nature of a type depends on the calculus considered (see Kinds of typed lambda calculi). From a certain point of view, typed lambda calculi can be seen as refinements of the untyped lambda calculus but from another point of view, they can also be considered the more fundamental theory and ''untyped lambda calculus'' a special case with only one type. Typed lambda calculi are foundational programming languages and are the base of typed functional programming languages such as ML and Haskell and, more indirectly, typed
imperative programming In computer science, imperative programming is a programming paradigm of software that uses Statement (computer science), statements that change a program's state (computer science), state. In much the same way that the imperative mood in natural ...
languages. Typed lambda calculi play an important role in the design of
type system In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a ''type'' (for example, integer, floating point, string) to every '' term'' (a word, phrase, or other set of symbols). Usu ...
s 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, formal logic within mathematics. Major subareas include model theory, proof theory, set theory, and recursion theory (also known as computability theory). Research in mathematical logic com ...
and
proof theory Proof theory is a major branchAccording to , proof theory is one of four domains mathematical logic, together with model theory, axiomatic set theory, and recursion theory. consists of four corresponding parts, with part D being about "Proof The ...
via the Curry–Howard isomorphism and they can be considered as the internal language of classes of categories, e.g., the simply typed lambda calculus is the language of a
Cartesian closed category In category theory, a Category (mathematics), category is Cartesian closed if, roughly speaking, any morphism defined on a product (category theory), product of two Object (category theory), objects can be naturally identified with a morphism defin ...
(CCC).


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 reduced first. That is, whenever possible, arguments are substituted into the body of an abstraction before the arguments are reduced. If a term has a beta-normal form, normal order reduction will always reach that normal form. ; Applicative order: The leftmost innermost redex is reduced first. As a consequence, a function's arguments are always reduced before they are substituted into the function. Unlike normal order reduction, applicative order reduction may fail to find the beta-normal form of an expression, even if such a normal form exists. For example, the term ( \; \lambda x.y \;\; (\lambda z. (z z) \; \lambda z. (z z)) \; ) is reduced to itself by applicative order, while normal order reduces it to its beta-normal form y. ; 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: Like applicative order, but no reductions are performed inside abstractions. This is similar to the evaluation order of strict languages like C: the arguments to a function are evaluated before calling the function, and function bodies are not even partially evaluated until the arguments are substituted in. ; Call by name: Like 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. The argument may be evaluated "when needed", at which point the name binding is updated with the reduced value. This can save time compared to normal order evaluation.


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. Informally, a function is ''computable'' if there is an algorithm that computes the value of the function for every value of its argument. Because of the lack of a precis ...
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. He was highly influential in the development of theoretical comput ...
. 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 corresponding to ''x'' and ''y'', respectively and =β meaning equivalence with β-reduction. See the
Church–Turing thesis In Computability theory (computation), computability theory, the Church–Turing thesis (also known as computability thesis, the Turing–Church thesis, the Church–Turing conjecture, Church's thesis, Church's conjecture, and Turing's thesis) ...
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. Kurt Gödel developed the concept for the proof of his incom ...
for lambda expressions, he constructs a lambda expression that closely follows the proof of Gödel's first incompleteness theorem. If is applied to its own Gödel number, a contradiction results.


Complexity

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


Lambda calculus and programming languages

As pointed out by Peter Landin's 1965 paper "''A Correspondence between
ALGOL 60 ALGOL 60 (short for ''Algorithmic Language 1960'') is a member of the ALGOL family of computer programming languages. It followed on from ALGOL 58 which had introduced code blocks and the begin and end pairs for delimiting them, representing a ...
and Church's Lambda-notation''", sequential
procedural programming Procedural programming is a programming paradigm, classified as imperative programming, that involves implementing the behavior of a computer program as Function (computer programming), procedures (a.k.a. functions, subroutines) that call each o ...
languages can be understood in terms of the lambda calculus, which provides the basic mechanisms for procedural abstraction and procedure (subprogram) application.


Anonymous functions

For example, in Python the "square" function can be expressed as a lambda expression as follows: (lambda x: x**2) The above example is an expression that evaluates to a first-class function. The symbol lambda creates an anonymous function, given a list of parameter names, x – just a single argument in this case, and an expression that is evaluated as the body of the function, x**2. Anonymous functions are sometimes called lambda expressions. For example, Pascal and many other imperative languages have long supported passing subprograms as
arguments An argument is a series of sentences, statements, or propositions some of which are called premises and one is the conclusion. The purpose of an argument is to give reasons for one's conclusion via justification, explanation, and/or persua ...
to other subprograms through the mechanism of
function pointer A function pointer, also called a subroutine pointer or procedure pointer, is a pointer referencing executable code, rather than data. Dereferencing the function pointer yields the referenced function, which can be invoked and passed arguments ...
s. However, function pointers are an insufficient 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 runtime. Such runtime creation of functions is supported in
Smalltalk Smalltalk is a purely object oriented programming language (OOP) that was originally created in the 1970s for educational use, specifically for constructionist learning, but later found use in business. It was created at Xerox PARC by Learni ...
,
JavaScript JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior. Web browsers have ...
,
Wolfram Language The Wolfram Language ( ) is a proprietary, very high-level multi-paradigm programming language developed by Wolfram Research. It emphasizes symbolic computation, functional programming, and rule-based programming and can employ arbitrary stru ...
, and more recently in Scala, Eiffel (as agents), C# (as delegates) and
C++11 C++11 is a version of a joint technical standard, ISO/IEC 14882, by the International Organization for Standardization (ISO) and International Electrotechnical Commission (IEC), for the C++ programming language. C++11 replaced the prior vers ...
, 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 to the lambda calculus. Other process calculi 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 The thumb is the first digit of the hand, next to the index finger. When a person is standing in the medical anatomical position (where the palm is facing to the front), the thumb is the outermost digit. The Medical Latin English noun for thum ...
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 a ...
. 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, C ...
showed that if only
continuous functions In mathematics, a continuous function is a function such that a small variation of the argument induces a small variation of the value of the function. This implies there are no abrupt changes in value, known as '' discontinuities''. More preci ...
were considered, a set or domain ''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 , . Models can be divided in ...
for the lambda calculus. This work also formed the basis for the
denotational semantics In computer science, denotational semantics (initially known as mathematical semantics or Scott–Strachey semantics) is an approach of formalizing the meanings of programming languages by constructing mathematical objects (called ''denotations'' ...
of programming languages.


Variations and extensions

These extensions are in the lambda cube: *
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 reaso ...
– A typed lambda calculus with types as first-class values These
formal system A formal system is an abstract structure and formalization of an axiomatic system used for deducing, using rules of inference, theorems from axioms. In 1921, David Hilbert proposed to use formal systems as the foundation of knowledge in ma ...
s are extensions of lambda calculus that are not in the lambda cube: * Binary lambda calculus – A version of lambda calculus with binary
input/output In computing, input/output (I/O, i/o, or informally io or IO) is the communication between an information processing system, such as a computer, and the outside world, such as another computer system, peripherals, or a human operator. Inputs a ...
(I/O), a binary encoding of terms, and a designated universal machine. * Lambda-mu calculus – An extension of the lambda calculus for treating
classical logic Classical logic (or standard logic) or Frege–Russell logic is the intensively studied and most widely used class of deductive logic. Classical logic has had much influence on analytic philosophy. Characteristics Each logical system in this c ...
These formal systems are variations of lambda calculus: * Kappa calculus – A first-order analogue of lambda calculus These formal systems are related to lambda calculus: *
Combinatory logic Combinatory logic is a notation to eliminate the need for quantified variables in mathematical logic. It was introduced by Moses Schönfinkel and Haskell Curry, and has more recently been used in computer science as a theoretical model of com ...
– A notation for mathematical logic without variables *
SKI combinator calculus 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 – Treatment of objects in the style of the lambda calculus *
Cartesian closed category In category theory, a Category (mathematics), category is Cartesian closed if, roughly speaking, any morphism defined on a product (category theory), product of two Object (category theory), objects can be naturally identified with a morphism defin ...
– A setting for lambda calculus in
category theory Category theory is a general theory of mathematical structures and their relations. It was introduced by Samuel Eilenberg and Saunders Mac Lane in the middle of the 20th century in their foundational work on algebraic topology. Category theory ...
* 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 *
Clojure Clojure (, like ''closure'') is a dynamic programming language, dynamic and functional programming, functional dialect (computing), dialect of the programming language Lisp (programming language), Lisp on the Java (software platform), Java platfo ...
, programming language * Curry–Howard isomorphism – The formal correspondence between programs and proofs *
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 – notation using postfix modification functions *
Domain theory Domain theory is a branch of mathematics that studies special kinds of partially ordered sets (posets) commonly called domains. Consequently, domain theory can be considered as a branch of order theory. The field has major applications in computer ...
– Study of certain posets giving
denotational semantics In computer science, denotational semantics (initially known as mathematical semantics or Scott–Strachey semantics) is an approach of formalizing the meanings of programming languages by constructing mathematical objects (called ''denotations'' ...
for lambda calculus *
Evaluation strategy In a programming language, an evaluation strategy is a set of rules for evaluating expressions. The term is often used to refer to the more specific notion of a ''parameter-passing strategy'' that defines the kind of value that is passed to the ...
– Rules for the evaluation of expressions in
programming language A programming language is a system of notation for writing computer programs. Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
s * Explicit substitution – The theory of substitution, as used in
β-reduction In mathematical logic, the lambda calculus (also written as ''λ''-calculus) is a formal system for expressing computation based on function abstraction and application using variable binding and substitution. Untyped lambda calculus, the topic ...
* Harrop formula – A kind of constructive logical formula such that proofs are lambda terms * Interaction nets *
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 ...
– A demonstration that some form of lambda calculus is inconsistent * Knights of the Lambda Calculus – A semi-fictional organization of LISP and Scheme hackers * Krivine machine – An abstract machine to interpret call-by-name in lambda calculus * Lambda calculus definition – Formal definition of the lambda calculus. *
Let expression In computer science, a "let" expression associates a function definition with a restricted scope. The "let" expression may also be defined in mathematics, where it associates a Boolean condition with a restricted scope. The "let" expression may ...
– 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 ...
*
Rewriting In mathematics, computer science, and logic, rewriting covers a wide range of methods of replacing subterms of a formula with other terms. Such methods may be achieved by rewriting systems (also known as rewrite systems, rewrite engines, or reduc ...
– Transformation of formulæ in formal systems * SECD machine – A
virtual machine In computing, a virtual machine (VM) is the virtualization or emulator, emulation of a computer system. Virtual machines are based on computer architectures and provide the functionality of a physical computer. Their implementations may involve ...
designed for the lambda calculus * Scott–Curry theorem – A theorem about sets of lambda terms * '' To Mock a Mockingbird'' – An introduction to
combinatory logic Combinatory logic is a notation to eliminate the need for quantified variables in mathematical logic. It was introduced by Moses Schönfinkel and Haskell Curry, and has more recently been used in computer science as a theoretical model of com ...
*
Universal Turing machine In computer science, a universal Turing machine (UTM) is a Turing machine capable of computing any computable sequence, as described by Alan Turing in his seminal paper "On Computable Numbers, with an Application to the Entscheidungsproblem". Co ...
– A formal computing machine equivalent to lambda calculus * Unlambda – A functional
esoteric programming language An esoteric programming language (sometimes shortened to esolang) is a programming language designed to test the boundaries of computer programming language design, as a proof of concept, as software art, as a hacking interface to another language ...
based on combinatory logic


Further reading

* Abelson, Harold & Gerald Jay Sussman. Structure and Interpretation of Computer Programs.
The MIT Press The MIT Press is the university press of the Massachusetts Institute of Technology (MIT), a private research university in Cambridge, Massachusetts. The MIT Press publishes a number of academic journals and has been a pioneer in the Open Ac ...
. . * Barendregt, Hendrik Pieterbr>''Introduction to Lambda Calculus''
* Barendregt, Hendrik Pieter
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 (1977) * Cardone, Felice and Hindley, J. Roger, 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'' (''CACM'') is the monthly journal of the Association for Computing Machinery (ACM). History It was established in 1958, with Saul Rosen as its first managing editor. It is sent to all ACM members. Articles are i ...
, 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: * Sørensen, Morten Heine and Urzyczyn, Paweł (2006), ''Lectures on the Curry–Howard isomorphism'', Elsevier, 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 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 Structure (mathematic ...
s and the lambda cube. It does not cover
subtyping In programming language theory, subtyping (also called subtype polymorphism or inclusion polymorphism) is a form of type polymorphism. A ''subtype'' is a datatype that is related to another datatype (the ''supertype'') by some notion of substi ...
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 *
A Short Introduction to the Lambda Calculus
'-(
PDF Portable document format (PDF), standardized as ISO 32000, is a file format developed by Adobe Inc., Adobe in 1992 to present documents, including text formatting and images, in a manner independent of application software, computer hardware, ...
) by Achim Jung *
A timeline of lambda calculus
'-(
PDF Portable document format (PDF), standardized as ISO 32000, is a file format developed by Adobe Inc., Adobe in 1992 to present documents, including text formatting and images, in a manner independent of application software, computer hardware, ...
) by Dana Scott *
A Tutorial Introduction to the Lambda Calculus
'-(
PDF Portable document format (PDF), standardized as ISO 32000, is a file format developed by Adobe Inc., Adobe in 1992 to present documents, including text formatting and images, in a manner independent of application software, computer hardware, ...
) by Raúl Rojas *
Lecture Notes on the Lambda Calculus
'-(
PDF Portable document format (PDF), standardized as ISO 32000, is a file format developed by Adobe Inc., Adobe in 1992 to present documents, including text formatting and images, in a manner independent of application software, computer hardware, ...
) by Peter Selinger
''Graphic lambda calculus''
by Marius Buliga
''Lambda Calculus as a Workflow Model''
by Peter Kelly, Paul Coddington, and Andrew Wendelborn; mentions graph reduction as a common means of evaluating lambda expressions and discusses the applicability of lambda calculus for
distributed computing Distributed computing is a field of computer science that studies distributed systems, defined as computer systems whose inter-communicating components are located on different networked computers. The components of a distributed system commu ...
(due to the Church–Rosser property, which enables parallel graph reduction for lambda expressions).


Notes


References

''Some parts of this article are based on material from FOLDOC, used with permission.''


External links

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

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

LCI Lambda Interpreter
a simple yet powerful pure calculus interpreter

* Mike Thyer
Lambda Animator
a graphical Java applet demonstrating alternative reduction strategies.
Implementing the Lambda calculus
using C++ Templates * Shane Steinert-Threlkeld
"Lambda Calculi"
''
Internet Encyclopedia of Philosophy The ''Internet Encyclopedia of Philosophy'' (''IEP'') is a scholarly online encyclopedia with around 900 articles about philosophy, philosophers, and related topics. The IEP publishes only peer review, peer-reviewed and blind-refereed original p ...
'' * Anton Salikhmetov
''Macro Lambda Calculus''
{{Functions navbox 1936 in computing Computability theory Formal methods Models of computation Theoretical computer science Programming language comparisons Articles with example Lisp (programming language) code Articles with example Python (programming language) code