Lably
Skip to content

Lambda calculus

Mathematical-logic system

  • 30 min read
  • 14 chapters

Learn it on Lably

Definition

The lambda calculus consists of a language of lambda terms, which are defined by a formal syntax, and a set of transformation rules for manipulating those terms. In BNF, the syntax is e::=x∣λx.e∣ee, where variables x,y,z range over an infinite set of names. Terms M,N,t,s,e,f range over all lambda terms. This corresponds to the following inductive definition:

  • A variable x is a valid lambda term.
  • An abstraction is a lambda term (λx.t) where t is a lambda term, referred to as the abstraction's body, and x is the abstraction's parameter variable,
  • An application is a lambda term (ts) where t and s are lambda terms.

A lambda term is syntactically valid if it can be obtained by repeated application of these three rules. For convenience, parentheses can often be omitted when writing a lambda term—see Lambda calculus definition § Notation for details.

Within lambda terms, any occurrence of a variable that is not a parameter of some enclosing λ is said to be free. Any free occurrence of x in a term M is bound in λx.M. Any free occurrence of any other variable within M remains free in λx.M.

For example, in the term xy, both x and y occur free. In (λx.xy), y is free, but x in the body (i.e. after the dot) is not free, and is said to be bound (to the parameter). While y is free in (λx.xy), it is bound in (λy.λx.xy). There are two occurrences of x in (λy.(λx.xy)x) – one is bound, and the other is free.

FV⁡(M) is the set of free variables of M, i.e. such variables that occur free in M at least once. It can be defined inductively as follows:

  • FV⁡(x)={x}
  • FV⁡(M1M2)=FV⁡(M1)∪FV⁡(M2)
  • FV⁡(λx.M)=FV⁡(M)∖{x}

The notation M[x:=N] denotes capture-avoiding substitution: substituting N for every free occurrence of x in M, while avoiding variable capture. This operation is defined inductively as follows:

  • x[x:=N]=N; y[x:=N]=y if y≠x.
  • (M1M2)[x:=N]=(M1[x:=N])(M2[x:=N]).
  • (λy.M)[x:=N] has three cases:
    • If y=x, becomes λx.M (x is bound; no change).
    • If y∉FV⁡(N), becomes λy.(M[x:=N]).
    • If y∈FV⁡(N), first α-rename λy.M to λy′.(M[y:=y′]) with y′ fresh to avoid name collisions, then continue as above. It becomes (λy′.(M[y:=y′]))[x:=N] with y′∉FV⁡(M)∪FV⁡(N).

There are several notions of "equivalence" and "reduction" that make it possible to reduce lambda terms to equivalent lambda terms.

  • α-conversion captures the intuition that the particular choice of a bound variable, in an abstraction, does not (usually) matter. If y∉FV⁡(M), then the terms λx.M and λy.M[x:=y] are considered alpha-equivalent, written λx.M≡αλy.M[x:=y]. The equivalence relation is the smallest congruence relation on lambda terms generated by this rule. For instance, λx.x and λy.y are alpha-equivalent lambda terms.
  • The β-reduction rule states that a β-redex, an application of the form (λx.t)s, reduces to the term t[x:=s]. For example, for every s, (λx.x)s→x[x:=s]=s. This demonstrates that λx.x really is the identity. Similarly, (λx.y)s→y[x:=s]=y, which demonstrates that λx.y is a constant function.
  • η-conversion expresses extensionality and converts between λx.fx and f whenever x does not appear free in f. It is often omitted in many treatments of lambda calculus.

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.MN is M[x:=N].

Sign in to keep reading

13 more chapters are free with a Lably account.

More in Foundations