The Lambda Calculus is Algebraic

PETER SELINGER

Department of Mathematics and Statistics University of Ottawa, Ottawa, Ontario K1N 6N5, Canada

                       (e-mail: selinger@mathstat.uottawa.ca)

Abstract

This paper serves as a self-contained, tutorial introduction to combinatory models of the untyped lambda calculus. We focus particularly on the interpretation of free variables. We argue that free variables should not be interpreted as elements in a model, as is usually done, but as indeterminates. We claim that the resulting interpretation is more natural and leads to a closer correspondence between models and theories. In particular, it solves the problem of the notorious ξ-rule, which asserts that equations should be preserved under binders, and which fails to be sound for the usual interpretation.

Introduction

The correspondence between Curry’s type-free lambda calculus and Schönfinkel’s combinatory algebras is among the oldest known and the most aesthetically pleasing facts about the lambda calculus. However, the combinatory interpretation of the lambda calculus is also known to be somewhat imperfect, because it does not satisfy the ξ-rule: under the interpretation, M = N does not necessarily imply λx.M = λx.N (Barendregt, 1984). Thus, the class of lambda algebras is not sound for lambda theories, and one is forced to consider the non-equational class of lambda models instead. It seems to follow that the lambda calculus does not correspond to an equationally definable class of algebras.

A similar problem arises whenever one tries to model languages that contain binders. Recall that the terms of universal algebra are constructed from variables and n-ary operations from some signature. On the other hand, the terms of most programming languages also contain bound variables. The question arises whether languages with binders are fundamentally more expressive than languages without them, or whether binders are, at least in principle, a dispensable convenience.

There are good reasons for dealing with algebraic languages, rather than languages with binders, under certain circumstances; particularly in connection with equational reasoning. Algebraic languages have simple and well-understood model theories, and the models allow standard constructions such as cartesian products, subalgebras, quotients, and the construction of free algebras.

The above-mentioned problem with the ξ-rule seems to suggest that the lambda calculus is not quite equivalent to an algebraic theory, and thus, that languages with binders are fundamentally more powerful than algebraic languages. In this paper, we take a different point of view. We suggest another way of looking at the problem, which yields a sense in which the lambda calculus is equivalent to an algebraic theory.

The basic observation is that the failure of the ξ-rule is not a deficiency of the lambda calculus itself, nor of combinatory algebras, but rather it is an artifact of the way free variables are interpreted in a model. Under the usual interpretation, free variables are interpreted as elements of a lambda algebra A. Thus, an equation M = N between terms is said to be satisfied if it holds whenever the free variables of M and N are replaced by elements of A. We call this the local interpretation. We suggest a different interpretation, called the absolute interpretation, under which free variables are interpreted as indeterminates. Let A[x_{1} … x_{n}] be the lambda algebra obtained from A by freely adjoining elements x_{1} … x_{n}. Under the absolute interpretation, an equation M = N is said to be satisfied if it holds in A[x_{1} … x_{n}].

The fundamental observation of this paper is that the two interpretations do not coincide, and that the absolute interpretation satisfies all rules of the lambda calculus, including the notorious ξ-rule. It follows that the absolute interpretation is sound and complete with respect to arbitrary lambda theories. Further, we show that the categories of lambda theories and of lambda algebras are equivalent. This, to some extent, justifies the slogan “the lambda calculus is algebraic”.

To researchers who specialize in the lambda calculus, the results of this paper are probably well-known, or at least they can be easily derived from “folklore” results. However, to researchers outside this immediate field, these results are not as well-known as they might deserve, and they usually appear only implicitly, if at all, in the published literature. There is still widespread confusion about models of the untyped lambda calculus, particularly about the issues of the ξ-rule, lambda algebras, lambda models, and extensionality. Thus, the main purpose of this paper is to bring these results together in one place, and to present them in a self-contained and accessible way. Where we present background material, Barendregt’s monograph usually serves as the standard reference (Barendregt, 1984).

The paper is organized as follows. In Section 1, we summarize the basic theory of combinatory logic and the lambda calculus. In Section 2, we introduce the notion of indeterminates and the absolute interpretation of lambda terms. In Section 3 we consider the βη-case, and in Section 4 we explore analogies with cartesian closed categories.

1 Combinatory models of the lambda calculus

1.1 The lambda calculus and combinatory logic

Definition. Fix a countable set V of variables. Let C be a set of constants. The sets of lambda terms M, N, … and of combinatory terms A, B, … are given by the following abstract syntax:

\begin{aligned}M, N & ::= & x c MN λx.M \\ A, B & ::= & x c AB K S \end{aligned}

Here, x ranges over variables and c ranges over constants. The set of lambda terms thus defined is denoted Λ_{C}, and the set of combinatory terms is ℭ_{C}.

We follow the usual syntactic conventions for lambda terms and combinatory terms Table 1. The axioms and rules of the lambda calculus

(α) M =_{α} N ⇒ M = N
(β) (λx.M)N = M[N/x]
(refl) M = M
(symm) M = N ⇒ N = M
(trans) M = N, N = P ⇒ M = P
(cong) M = M′, N = N′ ⇒ MN = M′N′
(ξ) M = N ⇒ λx.M = λx.N

Table 2. The axioms and rules of combinatory logic

(k) KAB = A
(s) SABC = AC(BC)
(refl) A = A
(symm) A = B ⇒ B = A
(trans) A = B, B = C ⇒ A = C
(cong) A = A′, B = B′ ⇒ AB = A′B′
(subst) A = A′ ⇒ A[B/x] = A′[B/x]

(Barendregt, 1984). In particular, application associates to the left and the body of an abstraction extends as far to the right as possible. Thus, we write MNP for (MN)P, and λx.MN for λx.(MN).

Free and bound variables are defined as usual, and we write M =_{α} N if M and N are equal up to renaming of bound variables. Note that a combinatory term never has bound variables; of course it may have free ones. We write M[N/x] for the capture-avoiding substitution of N for x in M. A term with no free variables is called closed. We write Λ_{C}^{0} and ℭ_{C}^{0} for the sets of closed lambda terms and closed combinatory terms, respectively.

Definition. The axioms and rules for deriving equations between lambda terms are shown in Table 1. If T is a set of equations, we write T ⊢ M = N if M = N is derivable from T by using these rules. A lambda theory is a set of closed equations that is closed under derivability. The unique smallest lambda theory is denoted λβ, and is called the pure lambda theory. We write M =_{β} N if λβ ⊢ M = N.

Similarly, the axioms and rules of combinatory logic are shown in Table 2. Entailment and theories are defined in the same way as for the lambda calculus. The minimal theory of combinatory logic is denoted CL, and we write A =_{CL} B if CL ⊢ A = B.

Note that combinatory logic is an algebraic theory in the sense of universal algebra: it is given by an algebraic signature and equations, together with the standard rules of equational reasoning. On the other hand, the lambda calculus is not a priori algebraic in this sense, because of the λ-binder and its corresponding ξ-rule. However, we will show in Section 2 that the lambda calculus is equivalent to an algebraic theory in a suitable sense.

Also note that we did not state the equivalent of the rule (subst) for the lambda calculus. There was no need to do so, since (subst) is derivable from (β), (ξ), (cong), and (refl).

In this section and the next one, we consider only the lambda-β-calculus; the η-rule will not be considered until Section 3.

1.2 Combinatory algebras

Definition. An applicative structure (A, ·) is a set A together with a binary operation “·”. A combinatory algebra (A, ·, k, s) is an applicative structure with distinguished elements k, s satisfying

kxy = x  and sxyz = xz(yz),  for all x, y, z ∈ A.

A homomorphism of combinatory algebras is f: A → B such that fk = k, fs = s and f(x · y) = fx · fy, for all x, y ∈ A.

Example. Let T be a set of equations between lambda terms. The open term algebra Λ_{C}/T has as its elements the T -equivalence classes of lambda terms, i.e., two terms M, N are considered equal if T ⊢ M = N. The operations are defined by M · N = MN, k = λxy.x, and s = λxyz.xz(yz). The closed term algebra Λ_{C}^{0}/T is defined analogously.

A more trivial example is given by the open and closed term algebras of combinatory logic: here one can take k = K and s = S.

Combinatory algebras form an algebraic variety, i.e., they allow the usual algebraic constructions of subalgebras, quotient algebras, free algebras and polynomial algebras A[z]. For instance, A[z] is standardly constructed as the closed term algebra Λ_{A∪{z}}^{0}/T , where T is the set of equations a · b = c which hold in A, for a, b, c ∈ A. The elements of A[z] are often called polynomials (in one variable) over A.

Definition (Local interpretation of combinatory terms). The terms of combinatory logic can be naturally interpreted in a combinatory algebra. Recall that ℭ_{A} is the set of combinatory terms with one constant symbol for each element of A. The local interpretation [[A]]_{ρ} of such a term is defined with respect to a valuation of variables ρ: V → A:

[[x]]_{ρ} = ρx, [[c]]_{ρ} = c, [[K]]_{ρ} = k, [[S]]_{ρ} = s, [[AB]]_{ρ} = [[A]]_{ρ} · [[B]]_{ρ}.

We call this the local interpretation to distinguish it from the absolute interpretation discussed later. For terms A, B ∈ ℭ_{A}, we say that the equation A = B holds locally in A, notation A ⊧_{loc} A = B, if for all valuations ρ in A, [[A]]_{ρ} = [[B]]_{ρ}. If T is a set of equations, we write A ⊧_{loc} T if every equation in T holds locally in A. The following soundness and completeness theorem holds for general reasons of universal algebra:

Proposition 1 (Soundness and completeness for combinatory logic). Let T be a set of equations between combinatory terms. For constant-free combinatory terms A and B,

T ⊢ A = B iff

A ⊧_{loc} A = B for all combinatory algebras A such that A ⊧_{loc} T .

1.3 The derived lambda abstractor

The significance of the two combinators K and S of combinatory logic lies in the fact that they can be used to simulate lambda abstraction. Define I = SKK. Notice that Ix =_{CL} x, for all x. For a combinatory term A and a variable x, define the term λ^{∗}x.A inductively:

λ^{∗}x.x = I
λ^{∗}x.B = KB  if x ∉ FV(B),
λ^{∗}x.BC = S(λ^{∗}x.B)(λ^{∗}x.C) otherwise.

Note by induction that (λ^{∗}x.A)x =_{CL} A holds for any term A. Also, FV(λ^{∗}x.A) = FV(A) \ {x}. The operation λ^{∗} is called the derived lambda abstractor of combinatory logic. It is important to remark here that, in general, the operator λ^{∗} is well-defined only on terms, and not on equivalence classes of terms. For this reason, the λ^{∗} operator does not, in general, yield an operator λ^{∗}: A[x] → A, for a combinatory algebra A. We will see in Section 2.2 that we do get such an operator when A is a lambda algebra.

A consequence of the derived lambda abstractor is combinatory completeness: For every combinatory term A with variables in x_{1}, …, x_{n}, there exists a closed term f such that A =_{CL} fx_{1} ⋯ x_{n}. This is achieved by letting f = λ^{∗}x_{1} … x_{n}.A.

1.4 Interpretation of lambda terms

Using the derived lambda abstractor λ^{∗} of combinatory logic, we can define translations cl : Λ_{C} → ℭ_{C} and λ: ℭ_{C} → Λ_{C} from lambda terms to combinatory terms and vice versa:

x_{cl} = x
c_{cl} = c
(MN)_{cl} = M_{cl}N_{cl}
(λx.M)_{cl} = λ^{∗}x.M_{cl}

x_{λ} = x_{c_{λ} = c}_{(AB)_{λ} = A_{λ}B_{λ}}_{K_{λ} = λxy.x}_{S_{λ} = λxyz.xz(yz)}

Notice that again, these translations are defined on terms, rather than equivalence classes of terms. For example, (λz.(λx.x)z)_{cl} = S(KI)I and (λz.z)_{cl} = I are not equivalent in combinatory logic. Thus, M =_{β} N does not imply M_{cl} =_{CL} N_{cl}. The following lemma summarizes the properties that do hold. Note that the last part of the lemma follows from the first two parts. Lemma 2. For any lambda term M, we have M_{cl,λ} =_{β} M. For combinatory terms A, B, if A =_{CL} B then A_{λ} =_{β} B_{λ}. For lambda terms M, N, if M_{cl} =_{CL} N_{cl}, then M =_{β} N.

We can now interpret lambda terms in any combinatory algebra, by first translating them into combinatory logic via cl: Definition (Local interpretation of lambda terms). Let A be a combinatory algebra. For lambda terms M, N ∈ Λ_{A} and a valuation ρ: V → A, define

[[M]]_{ρ} = [[M_{cl}]]_{ρ},
A ⊧_{loc} M = N iff A ⊧_{loc} M_{cl} = N_{cl}.

We define Th(A) to be the set of all closed equations M = N such that A ⊧_{loc} M = N. Here, by a closed equation we mean, of course, an equation between closed terms.

This interpretation is not sound for the lambda calculus, since there are derivable equations, such as λz.(λx.x)z = λz.z, that do not hold in all combinatory algebras. In particular, Th(A) need not be a lambda theory!

This leads one to consider the class of lambda algebras, which are precisely those combinatory algebras in which the equations of the λβ-calculus are satisfied.

1.5 Lambda Algebras

Definition. (See (Barendregt, 1984)). A combinatory algebra A is called a lambda algebra if for all combinatory terms A, B ∈ ℭ_{A},

A_{λ} =_{β} B_{λ}  ⇒  A ⊧_{loc} A = B.

A homomorphism of lambda algebras is a homomorphism of combinatory algebras.

Note that a lambda algebra is a particular kind of combinatory algebra. This is not to be confused with the concept of a “syntactical lambda algebra” of (Hindley & Longo, 1980); see also (Barendregt 1984, p. 101).

Example 3. Let T be a set of equations between lambda terms. The open term algebra Λ_{C}/T and the closed term algebra Λ_{C}^{0}/T are lambda algebras. In the open terms algebra, Λ_{C}/T ⊧_{loc} A = B iff T ⊢ A_{λ} = B_{λ}.

Proposition 4. The class of lambda algebras can be defined, relative to the class of combinatory algebras, by a set of closed, constant-free equations. In particular, lambda algebras form an algebraic variety.

Proof By definition, A is a lambda algebra if and only if it satisfies all equations A = B where A, B ∈ ℭ_{A} and A_{λ} =_{β} B_{λ}. To prove the claim, notice that we can first remove the constant symbols from A and B by replacing them with fresh variables. We can then eliminate the free variables by applying the derived lambda abstractor. The resulting equations are still valid, and they imply the original ones.

It is less obvious that the set of equations can be taken to be finite.

Proposition 5 (Curry). The class of lambda algebras is axiomatized by the equations of combinatory logic and the following five closed equations due to Curry:

1. k = s(s(ks)(s(kk)k))(k(skk))

2. s = s(s(ks)(s(k(s(ks)))(s(k(s(kk)))s)))(k(k(skk)))

3. s(kk) = s(s(ks)(s(kk)(s(ks)k)))(kk)

4. s(ks)(s(kk)) = s(kk)(s(s(ks)(s(kk)(skk)))(k(skk)))

5. s(k(s(ks)))(s(ks)(s(ks))) = s(s(ks)(s(kk)(s(ks)(s(k(s(ks)))s))))(ks)

Proof See (Barendregt, 1984), Thm. 5.2.5.

The Curry axioms are compact, but not particularly intuitive. We will give another finite axiomatization of lambda algebras in Section 2.4 below.

Remark 6 (Failure of the ξ-rule). By definition, the local interpretation of the lambda calculus in a lambda algebra validates all the equations of the pure lambda calculus. However, this interpretation does not necessarily respect equational consequences. In particular, the local interpretation does not in general satisfy the ξ-rule from Table 1: there exist terms M, N and a lambda algebra A such that A ⊧_{loc} M = N but A |̸=_{loc} λx.M = λx.N.

One such example, due to Plotkin, arises when A is the closed term algebra of the lambda-βη-calculus. By an ingenious construction, Plotkin showed that there exist closed terms M and N such that MP =_{βη} NP for all closed terms P (thus A ⊧_{loc} Mx = Nx), but Mx ≠_{βη} Nx (thus A |̸=_{loc} λx.Mx = λx.Nx). The details of Plotkin’s construction are out of the scope of this tutorial; the interested reader may look them up in (Plotkin, 1974) or (Barendregt, 1984, Thm. 20.1.1).

The failure of the ξ-rule implies that the local interpretation is not sound with respect to equational consequences. For this reason, we only get a soundness and completeness theorem for the pure lambda calculus, i.e., the theory λβ. Note that it is soundness, and not completeness, which is problematic in the general case. We prove a better soundness and completeness theorem in Section 2.3 with respect to a different interpretation of lambda terms.

Theorem 7 (Soundness and completeness for the pure lambda calculus). For constantfree lambda terms M, N,

λβ ⊢ M = N iff A ⊧_{loc} M = N for all lambda algebras A.

Proof “⇒”: By definition of lambda algebras. “⇐”: By Example 3 and Lemma 2, the open term algebra Λ/λβ of the lambda beta calculus is a lambda algebra in which M = N iff M =_{β} N.

2 Lambda algebras and indeterminates

2.1 A characterization of A[z] for lambda algebras

Recall that A[z] is the combinatory algebra obtained from A by freely adjoining an indeterminate z (in the variety of combinatory algebras). We gave a concrete description of A[z] in Section 1.2. More abstractly, A[z] is characterized by the following universal property: A ⊆ A[z], and whenever f: A → B is a homomorphism of combinatory algebras, and i ∈ B is an element, then there exists a unique homomorphism h : A[z] → B which extends f and maps z to i.

If A is a lambda algebra then so is A[z]. More generally, if A is a lambda algebra and f: A → B is a homomorphism of combinatory algebras, then B is a lambda algebra. This is because lambda algebras are defined by closed equations (Proposition 4), and closed equations are always preserved by homomorphisms.

For lambda algebras, A[z] has an interesting explicit description. The following construction is similar to constructions given by Krivine (1993) and, in the case of Curry algebras, by Freyd (1989). Let A = (A, ·, k, s) be a lambda algebra, and define B = (B, •, K, S), where

B = {a ∈ A | a = 1a}, where 1 = s(ki) and i = skk,
a • b = sab,
K = kk,
S = ks.

Note that ab denotes application in A, and a • b denotes application in B. Also note that 1ab =_{CL} ab, and 1_{λ} =_{β} λxy.xy. The construction is motivated by considering the elements of A[z] as given by functions with one additional argument. Application is defined by threading through the extra element, and the constants throw it away:

\begin{aligned}(a • b)z & = & (az)(bz), \\ Kz & = & k, \\ Sz & = & s. \end{aligned}

Proposition 8. 1. B is a well-defined combinatory algebra.

2. The map ι: A → B with ι(a) = ka is a well-defined homomorphism.

3. For every homomorphism f: A → C and every z ∈ C, there is a unique homomorphism g: B → C such that f = g ∘ ι and g(i) = z. Consequently, B ≅ A[z].

For the proof of Proposition 8, we need a lemma:

Lemma 9. The following hold in any lambda algebra, for elements a, b, c:

(a)  1k = k,
(b)  1s = s,
(c)  1(ka) = ka,
(d)  1(sa) = sa,
(e)  1(sab) = sab,
(f )  s(s(kk)a)b = 1a,
(g) s(s(s(ks)a)b)c = s(sac)(sbc),
(h)  k(ab) = s(ka)(kb),
(i)  s(ka)i = 1a.

Proof One easily checks that (1k)_{λ} =_{β} k_{λ}, and similarly for the other equations.

Proof of Proposition 8 1.: It follows by Lemma 9(a)–(e) that all of k, s, K, S, a • b, i and 1 are elements of B, for any a, b ∈ B. In particular, the operations on B are well-defined. Moreover, Lemma 9(f ) and (g) imply that for all a, b, c ∈ B,

\begin{matrix}K • a • b = s(s(kk)a)b = 1a = a, \\ S • a • b • c = s(s(s(ks)a)b)c = s(sac)(sbc) = a • c • (b • c). \end{matrix}

2.: Using Lemma 9(h), we have ι(ab) = k(ab) = s(ka)(kb) = ι(a) • ι(b). Also, clearly ιk = K and ιs = S.

3.: Define g(a) = f(a)·z, and check that this has the desired properties. For uniqueness, take any homomorphism h: B → C such that f = h ∘ ι and h(i) = z. Then for all a ∈ B,

h(a) = h(1a) = h(s(ka)i)  by Lemma 9(i)
= h((ka) • i) = h(ka) · h(i) = h(ιa) · h(i) = f(a) · z = g(a).

Corollary 10. Let A be a lambda algebra, and let a, b ∈ A. Then az = bz holds in A[z] if and only if 1a = 1b holds in A.

Proof “⇒”: By definition of A[z], there is a unique map h: A[z] → B extending ι and sending z to i. Using Lemma 9(i) twice, we get

1a = s(ka)i = (ka) • i = h(az) = h(bz) = (kb) • i = s(kb)i = 1b.

“⇐”: If 1a = 1b holds in A, then also in A[z], thus az = 1az = 1bz = bz in A[z].

2.2 Absolute interpretation

Let M(x̄) be a lambda term with free variables among x_{1}, …, x_{n} = x̄. The local interpretation [[M]]_{ρ}, defined in Section 1.2, depends on a valuation ρ: V → A. Since, in fact, it depends only on the values of ρ at x_{1}, …, x_{n}, the local interpretation can be viewed as a function [[M]]x̄ ; loc : A^{n} → A, sending an n-tuple ā ∈ A^{n} to [[M]]_{(x̄:=ā)}. In these terms, an equation M = N holds locally in A if M and N define the same function A^{n} → A.

We will now consider a different interpretation of terms, where variables are interpreted as indeterminates, rather than as elements. Specifically, we interpret a term M(x̄) as an element in A[x̄], i.e., as a polynomial, rather than a function. We call this the absolute interpretation of M. The absolute interpretation distinguishes more terms than the local one, since, in general, two different polynomials may define the same function.

Definition (Absolute interpretation). The absolute interpretation [[A]]x̄ ; abs of a combinatory term A ∈ ℭ_{A} with variables among x̄ = x_{1}, …, x_{n} is an element of A[x̄], defined as follows:

[[x_{i}]]x̄ ; abs = x_{i}, [[c]]x̄ ; abs = c, [[K]]x̄ ; abs = k, [[S]]x̄ ; abs = s, [[AB]]x̄ ; abs = [[A]]x̄ ; abs · [[B]]x̄ ; abs.

Notice that this is the same as the local interpretation [[A]]_{δ} under the valuation δ: {x̄} → A[x̄] that maps each variable x_{i} to itself. An equation A = B between combinatory terms A, B ∈ ℭ_{A} is said to hold absolutely in A, written as

A ⊧_{abs} A = B,

if [[A]]x̄ ; abs = [[B]]x̄ ; abs, where F V (A, B) ⊆ x̄. Notice that, since the canonical homomorphism A[x̄] → A[ȳ] is one-to-one for x̄ ⊆ ȳ, this notion is invariant under the addition of dummy variables to x̄. For lambda terms M, N ∈ Λ_{A}, we define

[[M]]x̄ ; abs = [[M_{cl}]]x̄ ; abs,
A ⊧_{abs} M = N iff A ⊧_{abs} M_{cl} = N_{cl}.

Note that for closed terms, the absolute and the local interpretations coincide. In particular, Th(A), which was defined to be a set of closed equations, is the same for the local and the absolute interpretations. However, the two interpretations yield different equations between open terms.

The terminology “an equation holds absolutely” is motivated by the following lemma. The idea is that a property is “absolute” if it is preserved under homomorphisms.

Lemma 11. Let A be a combinatory algebra, and let A, B ∈ ℭ_{A} be terms with FV(A, B) ⊆ x̄. The following are equivalent:

1. A ⊧_{abs} A = B,

2. A[x̄] ⊧_{loc} A = B,

3. For all homomorphisms f: A → B, B ⊧_{loc} A = B.

Here, B ⊧_{loc} A = B is meant in the obvious sense, namely by interpreting constants as their images under f.

Proof

1. ⇒ 3.: Consider f: A → B and some valuation ρ: V → B. Define g: A[x̄] → B to be the unique map extending f such that g(x_{i}) = ρ(x_{i}) for all i. Then [[A]]_{ρ} = g[[A]]_{δ} = g[[B]]_{δ} = [[B]]_{ρ}, which proves B ⊧_{loc} A = B. 3. ⇒ 2. ⇒ 1.: Trivial.

Corollary 12. Absolute validity implies local validity, i.e., A ⊧_{abs} A = B implies A ⊧_{loc} A = B.

Proof Lemma 11(3) with f the identity function.

Lemma 13. In any lambda algebra, 1(λ^{∗}x.A) = λ^{∗}x.A.

Proof By definition of λ^{∗} and Lemma 9(e) and (c).

The next lemma shows that the ξ-rule, which failed for the local interpretation, is valid for the absolute interpretation.

Lemma 14. Let A be a lambda algebra. Let A, B ∈ ℭ_{A} be combinatory terms. Then

A ⊧_{abs} A = B  ⟺  A ⊧_{abs} λ^{∗}x.A = λ^{∗}x.B

Proof Suppose the variables of A and B are among x, y_{1}, …, y_{n}. “⇒”: Suppose A[x, ȳ] ⊧_{loc} A = B. Then A[x, ȳ] ⊧_{loc} (λ^{∗}x.A)x = A = B = (λ^{∗}x.B)x, hence by Corollary 10, A[ȳ] ⊧_{loc} 1(λ^{∗}x.A) = 1(λ^{∗}x.B). The claim follows by Lemma 13. “⇐”: Suppose A[x, ȳ] ⊧_{loc} λ^{∗}x.A = λ^{∗}x.B. Then A[x, ȳ] ⊧_{loc} A = (λ^{∗}x.A)x = (λ^{∗}x.B)x = B.

It follows from this lemma that the derived lambda abstractor λ^{∗}x is a well-defined operator λ^{∗}x: A[x] → A if A is a lambda algebra. When A[x] is explicitly constructed as (B, •, K, S) as in Section 2.1, then λ^{∗}x: B → A turns out to be the map that sends every element a to itself. Using this λ^{∗} operator, the absolute interpretation of a lambda term can be defined directly, i.e., without relying on a translation into combinatory logic:

[[c]]x̄ ; abs = c, [[x_{i}]]x̄ ; abs = x_{i}, [[MN]]x̄ ; abs = [[M]]x̄ ; abs·[[N]]x̄ ; abs, [[λx.M]]x̄ ; abs = λ^{∗}x.[[M]]_{abs}^{x,x̄}.

2.3 Soundness and completeness of the absolute interpretation

Proposition 15 (Soundness). The set of equations that hold absolutely in a lambda algebra A is closed under the axioms and rules of the lambda calculus. As a consequence, Th(A) is a lambda theory for any lambda algebra A.

Proof Consider each axiom and rule of the lambda calculus from Table 1. (α) and (β) hold in any combinatory algebra, the latter being a simple consequence of the syntactic fact that (λ^{∗}x.A)B =_{CL} A[B/x], for combinatory terms A and B. The rules (refl), (symm), (trans) or (cong) are trivially satisfied. Finally, the rule (ξ) is satisfied by Lemma 14.

Theorem 16 (Soundness and completeness for lambda theories). Let T be a set of equations between lambda terms. For constant-free lambda terms M and N,

T ⊢ M = N iff

A ⊧_{abs} M = N for all lambda algebras A such that A ⊧_{abs} T .

Proof “⇒”: By Proposition 15. “⇐”: The open term algebra Λ/T associated with T is a lambda algebra satisfying M = N iff T ⊢ M = N.

2.4 An alternative axiomatization of lambda algebras

The proofs of Corollary 10, Lemmas 13 and 14, and Proposition 15 do not use the definition of a lambda algebra directly; they only assume that the nine properties of Lemma 9 hold in A and A[ȳ]. In fact, these nine properties already axiomatize the class of lambda algebras.

Lemma 17. Suppose A absolutely satisfies the nine properties of Lemma 9. Then for all combinatory terms, A ⊧_{abs} A_{λ,cl} = A.

Proof This is an easy induction; the only interesting cases are the base cases A = k and A = s. We first note that for any a, 1a = s(ka)i = λ^{∗}x.ax, by property (i) and the definition of λ^{∗}. For A = k, we have k_{λ,cl} = λ^{∗}x.λ^{∗}y.x = λ^{∗}x.kx = 1k = k by (a). For A = s, we have s_{λ,cl} = λ^{∗}xyz.xz(yz) = λ^{∗}xyz.sxyz = λ^{∗}xy.1(sxy) = λ^{∗}xy.sxy = λ^{∗}x.1(sx) = λ^{∗}x.sx = 1s = s; here, we have used (b), (d), (e), and Lemma 14.

Theorem 18. Let A be a combinatory algebra. Then A is a lambda algebra if and only if it absolutely satisfies the nine properties of Lemma 9.

Proof The left-to-right implication is essentially Lemma 9; note that, since the equations hold in all lambda algebras, they therefore hold absolutely. For the converse, if A absolutely satisfies the nine properties, then the proofs of Corollary 10, Lemmas 13 and 14, and Proposition 15 apply to A. To show that A is a lambda algebra, assume A_{λ} =_{β} B_{λ}. By Proposition 15, A ⊧_{abs} A_{λ} = B_{λ}, hence, by definition, A ⊧_{abs} A_{λ,cl} = B_{λ,cl}. By Lemma 17, A ⊧_{abs} A = B.

On their face, the axioms of Lemma 9 appear to be more succinct and more elegant than the Curry axioms of Proposition 5. However, note that our axioms contain free variables, and we require the axioms to hold absolutely. One can eliminate the free variables by applying the derived lambda abstractor to each axiom, but this blows up their size enormously. Thus, we do not beat Curry at his own game, which is to find the most succinct set of closed axioms for lambda algebras.

It is worth remarking that the axioms presented in Lemma 9 are not independent; notably,

(c) follows from (h), because 1(ka) = s(ki)(ka) = k(ia) = ka. Still, we included (c) in the list for aesthetic reasons. The author does not know whether the remaining axioms are independent.

2.5 Lambda theories and lambda algebras form equivalent categories

In this section, we define the category of lambda theories, and we show that it is equivalent to the category of lambda algebras.

Definition. The category \underline{LT} of lambda theories is defined as follows: An object is a pair ⟨C, T ⟩, where C is a set of constants and T a lambda theory in the language Λ_{C}^{0}. A translation from C to C′ is a function φ: C → Λ_{C′}^{0}. Any such φ extends canonically to a function φ̃: Λ_{C}^{0} → Λ_{C′}^{0}, defined by φ̃M(c_{1}, …, c_{n}) = M(φc_{1}, …, φc_{n}), where c_{1}, …, c_{n} are the constants that appear in M. A morphism from ⟨C, T ⟩ to ⟨C′, T′⟩ is named by a translation from C to C′ such that T ⊢ M = N implies T′ ⊢ φ̃M = φ̃N for all M, N ∈ Λ_{C}^{0}. φ and ψ name the same morphism if T′ ⊢ φ̃M = ψ̃M for all M ∈ Λ_{C}^{0}. Composition is defined by φ ∘ ψ := φ̃ ∘ ψ.

Theorem 19. The category \underline{LT} of lambda theories is equivalent to the category \underline{LA} of lambda algebras.

Proof We define a pair of functors F: \underline{LT} → \underline{LA} and G: \underline{LA} → \underline{LT}. F maps a lambda theory ⟨C, T ⟩ to its closed term algebra Λ_{C}^{0}/T , which is always a lambda algebra. F maps a morphism φ: ⟨C, T ⟩ → ⟨C′, T′⟩ to the homomorphism f: Λ_{C}^{0}/T → Λ_{C′}^{0}/T′ induced by φ̃: Λ_{C}^{0} → Λ_{C′}^{0}. G maps a lambda algebra A to ⟨A, Th(A)⟩; note that Th(A) is a lambda theory by Proposition 15. G maps a homomorphism f: A → B to the translation φ: A → Λ_{B}^{0} with φa = fa.

Next, we describe a natural isomorphism η: id\underline{LA} → F ∘ G. For every lambda algebra A, define η_{A} : A → F ∘ G(A) = Λ_{A}^{0}/Th(A) by η_{A}(a) = a. This is clearly a homomorphism, and it is natural in A. To see that it is an isomorphism, notice that for every M ∈ Λ_{A}^{0} there is a unique a ∈ A with Th(A) ⊢ M = a, namely, a = [[M]].

In order to show the desired equivalence of categories, it now suffices to show that F is full and faithful. F is one-to-one on hom-sets by definition of morphisms in \underline{LT}. F is also full: if f: Λ_{C}^{0}/T → Λ_{C′}^{0}/T′ is any homomorphism, then f maps a closed lambda term M(c_{1}, …, c_{n}) to M(fc_{1}, …, fc_{n}), where c_{1}, …, c_{n} are the constants that appear in M. This is because M is equivalent to an applicative term made up from c_{1}, …, c_{n} and the combinators k and s, which are preserved by f. It follows that f = F φ, where φ: C → Λ_{C′}^{0} is defined by choosing a representative φ(c) of f(c), for every c ∈ C.

2.6 Lambda models

The notion of lambda model arises, as in (Barendregt, 1984), if one wishes to prove Proposition 15 with respect to the equations that hold locally. To do this, one needs the “local” equivalent of Lemma 14:

A ⊧_{loc} A = B  ⇒  A ⊧_{loc} λ^{∗}x.A = λ^{∗}x.B.

This property is called weak extensionality. As we have seen in Remark 6, it does not hold in general. Hence one defines a lambda model to be a weakly extensional lambda algebra.

From our point of view, the lambda models are those lambda algebras which are intrinsically local: in a lambda model, an equation holds absolutely if and only if it holds locally.

Or in other words: in a lambda model, every polynomial is determined by its behavior as a function. This property might also be called “well-pointedness”, by analogy with categorytheoretic language (see Section 4). It characterizes the class of lambda models, as shown in the following proposition. The equivalence of 1. and 2. is due to Meyer and Scott.

Proposition 20. The following are equivalent for a lambda algebra A:

1. A is weakly extensional.

2. A satisfies the so-called Meyer-Scott axiom: for all a, b ∈ A,

\frac{∀x ∈ A.ax = bx}{1a = 1b}, where 1 = S(KI).

3. A is “well-pointed”, i.e., every equation that holds locally in A already holds absolutely.

Proof

1. ⇒ 3.:Let A be weakly extensional and A ⊧_{loc} A = B. Let x̄ be the list of free variables of A and B. By weak extensionality, A ⊧_{loc} λ^{∗}x̄.A = λ^{∗}x̄.B. This is a closed equation, hence A ⊧_{abs} λ^{∗}x̄.A = λ^{∗}x̄.B, and finally A ⊧_{abs} A = B by Lemma 14.

3. ⇒ 2.:Suppose for all x ∈ A, ax = bx. Then A ⊧_{abs} ax = bx by 3., i.e., ax = bx ∈ A[x]. Hence 1a = 1b by Corollary 10.

2. ⇒ 1.:To show weak extensionality, suppose A ⊧_{loc} A = B. Then A ⊧_{loc} (λ^{∗}x.A)x = (λ^{∗}x.B)x, hence by 2., A ⊧_{loc} 1(λ^{∗}x.A) = 1(λ^{∗}x.B), hence by Lemma 13, A ⊧_{loc} λ^{∗}x.A = λ^{∗}x.B.

Lambda models are less natural than lambda algebras, because they do not form an algebraic variety. Traditionally, they were used for getting by with the local interpretation in proving soundness and completeness theorems, see e.g. (Barendregt, 1984), Thm. 5.2.18. In light of Theorem 16, it is more natural to work with the absolute interpretation. Thus, lambda models are not really needed for interpreting the lambda calculus; they are only interesting as “well-pointed” lambda algebras.

3 The lambda-βη calculus

Definition. The lambda-βη calculus is the lambda calculus with the additional axiom

(η) λx.Mx = M, where x ∉ FV(M).

We write M =_{βη} N if M = N follows from the axioms in Table 1 and (η). If a lambda theory T is closed under (η) then it is called a lambda-βη theory.

3.1 Curry algebras

Definition. A Curry algebra is a lambda algebra with 1 = I (Lambek, 1980).

Note that Curry algebras form an equational variety.

Proposition 21. A lambda algebra A is a Curry algebra if and only if Th(A) is a lambdaβη theory.

Proof If x ∉ FV(M), then λx.Mx =_{β} (λxy.xy)M = 1_{λ}M. Hence in any Curry algebra, λx.Mx = 1M = M. Conversely, if Th(A) is a lambda-βη theory, then A ⊧ 1 = λxy.xy = λx.x = I.

Thus, Curry algebras are to the lambda-βη calculus what lambda algebras are to the lambda-β calculus.

3.2 Extensional models

An applicative structure is extensional if for all a, b ∈ A,

\frac{∀x ∈ A.ax = bx}{a = b}.

Extensional combinatory algebras are Curry algebras, and hence models of the lambda-βη-calculus. Extensionality is an intuitive property. However, extensional models do not form an algebraic variety: e.g., the open term algebra of the lambda-βη calculus is extensional, but the subalgebra of closed terms is not (cf. Remark 6 and (Plotkin, 1974)). In fact, a Curry algebra is extensional iff it is a lambda model, since extensionality is equivalent to the Meyer-Scott axiom in this case.

4 Analogies with cartesian closed categories

Cartesian-closed categories (ccc’s) are to the simply-typed lambda calculus what lambda algebras are to the untyped lambda calculus. However, the ξ-rule does not pose any particular problem for interpretations in a ccc. Lambda-abstraction is always a well-defined operation. Why is it that the troublesome ξ-rule is not an issue for the ccc interpretation?

The reason is that the standard interpretation of indeterminates in a ccc corresponds to the absolute, and not the local, interpretation in lambda algebras. A morphism U^{n} → U in the category-theoretic interpretation corresponds more closely to an element of A[x_{1}, …, x_{n}] than to a function A^{n} → A in the algebraic interpretation.

4.1 Ccc models and simply typed lambda calculus

Consider a simply-typed lambda calculus over a fixed set of basic types. In a cartesian closed category C, a simply-typed term x : σ ⊳ M : τ is interpreted as a morphism f: A → B, where A and B are the interpretations of the types σ and τ, respectively. If |A| = (1, A) denotes the set of morphisms h : 1 → A, then f: A → B gives rise to a function f̂ : |A| → |B| in a natural way. Using our terminology, we will say that an equation M = N holds locally if the corresponding morphisms f, g satisfy f̂ = ĝ, i.e., if for all points h: 1 → A, f ∘ h = g ∘ h. It holds absolutely simply if f = g.

In the context of cartesian closed categories, the absolute interpretation is the standard one, whereas the local interpretation is a bit contrived. As in the combinatory case, the local interpretation is not sound; again it is the ξ-rule that is violated. Lambda models are analogous to well-pointed ccc’s, i.e., those ccc’s in which f̂ = ĝ implies f = g. It is precisely the well-pointed ccc’s in which the local and absolute interpretations coincide. However, the class of well-pointed ccc’s, just like the class of lambda models, is not algebraic.

The treatment of indeterminates in cartesian closed categories corresponds very closely to our treatment of indeterminates in combinatory algebras. An exponential object B^{A} can indeed be regarded as a kind of polynomial object B[x], where x is of type A. More precisely, a morphism D → B^{A} can be identified with a morphism D → B in the category C[x : A] obtained from C by adding an indeterminate arrow x : 1 → A. For a detailed account of such indeterminate morphisms, see Lambek and Scott (1986).

4.2 Reflexive ccc models

One way of making precise the relationship between lambda algebras and cartesian closed categories is by constructing the former from the latter. This idea is not new; it goes back to Lambek (1980). See also the discussion of C-monoids in (Lambek & Scott, 1986).

Let U be a reflexive object in a cartesian closed category, i.e., U is equipped with morphisms e: U^{U} → U and p: U → U^{U} such that p ∘ e = id_{U^{U}}. An untyped lambda term M with free variables x_{1}, …, x_{n} is interpreted in the standard way as a morphism U^{n} → U. Define A = (1, U) and a·b = p_{∗}∘⟨a, b⟩, where p_{∗} : U ×U → U is obtained by uncurrying p.

We say that the object U is locally well-pointed if f ≠ g : U → U implies that f ∘ x ≠ g ∘ x for some x : 1 → U.

Proposition 22. 1. A = (A, ·) is a lambda algebra.

2. A is a lambda model iff U is locally well-pointed.

3. A is a Curry algebra iff e ∘ p = id_{U}.

4. A[x] ≅ (1, U^{U}) ≅ (U, U).

5. A[x_{1}, …, x_{n}] ≅ (U^{n}, U).

6. A ⊧_{loc} M = N iff M, N define the same map (1, U)^{n} → (1, U).

7. A ⊧_{abs} M = N iff M, N define the same element in (U^{n}, U).

Proof 1.: One proves by an easy induction on combinatory terms A that

[[A]]_{ρ} = 1 ⟶^{⟨ρx_{1},...,ρx_{n}⟩} U^{n} ⟶^{[[A_{λ}]]_{x_{1},...,xn}} U,

where [[A]]_{ρ} is the interpretation in A, and [[A_{λ}]]_{x_{1},...,x_{n}} is the usual categorical interpretation of A_{λ}. The result then follows by soundness of the categorical interpretation.

2.–7.: These are straightforward calculations. For 4., use the fact from Section 2.1 that the elements of A[x] can be identified with those a ∈ A such that 1a = a. On the other hand, arrows 1 → U^{U} can be identified with those a : 1 → U such that e∘p∘a = a, which is equivalent to 1a = a in A. Moreover, the correspondence respects the natural lambda algebra structure on (U, U). 5. is similar.

Summary

Algebra is about polynomials and indeterminates as much as it is about signatures and equations. Thus, when looking for algebraic models of a language with variables, it seems natural to interpret the variables as indeterminates, rather than as elements. In this tutorial, we have examined the issues surrounding the interpretation of free variables in the context of the untyped lambda calculus. We found that the two interpretations do not coincide. Moreover, the interpretation of variables as indeterminates is superior in the sense that it validates the ξ-rule without the need for additional non-algebraic requirements on the model. We conclude that the lambda calculus is algebraic, in the sense that its canonical class of models is the class of lambda algebras.

While we have concentrated on models of the untyped lambda calculus, similar considerations apply to the algebraic modeling of any language with variables and binders. In particular, the same ideas also apply to typed languages. A well-known example is the interpretation of the simply-typed lambda calculus in cartesian-closed categories. In the categorical setting, too, variables are most naturally interpreted as indeterminates. This phenomenon was first described by Lambek and is now considered a standard construction in category theory. However, as we have seen, these ideas are not unique to category theory, or to typed languages, but they apply to algebraic settings in general.

Acknowledgments

I would like to thank the three anonymous referees for their valuable suggestions.

References

Barendregt, H. P. (1984). The lambda calculus, its syntax and semantics. 2nd edn. North-Holland. Freyd, P. J. (1989). Combinators. Pages 63–68 of: Proceedings of categories in computer science

and logic. Contemporary Mathematics 92. American Mathematical Society. Hindley, J. R., & Longo, G. (1980). Lambda calculus models and extensionality. Zeitschrift für

Mathematische Logik und Grundlagen der Mathematik, 26, 289–310. Koymans, C. P. J. (1982). Models of the lambda calculus. Information and control, 52, 306–332. Krivine, J.-L. (1993). Lambda-calculus, types and models. Masson. Lambek, J. (1980). From λ-calculus to cartesian closed categories. Pages 375–402 of: (Seldin &

Hindley, 1980). Lambek, J., & Scott, P. J. (1986). An introduction to higher order categorical logic. Cambridge

Studies in Advanced Mathematics 7. Cambridge University Press, New York. Meyer, A. R. (1982). What is a model of the lambda calculus? Information and control, 52, 87–122. Plotkin, G. D. (1974). The λ-calculus is ω-incomplete. Journal of symbolic logic, 39, 313–317. Seldin, J. P., & Hindley, J. R. (eds). (1980). To H. B. Curry: Essays on combinatory logic, lambda

calculus and formalism. Academic Press, London, New York.