Untyped Lambda
Untyped Lambda
Helmut Brandl
(firstname dot lastname at gmx dot net)
Abstract
This little text gives a step by step introduction into untyped
lambda calculus. All needed theory is explained and no special know
how is assumed. Although elementary, all important theorems about
untyped lambda calculus including some undecidability theorems are
given and proved within this text.
It has been tried to use a notation which is easy to understand
with a lot of graphic notation to support a good intuition about the
presented material.
Contents
1 Motivation 3
3 Lambda Terms 17
3.1 Basic Definitions . . . . . . . . . . . . . . . . . . . . . 17
3.2 Simple Computation with Combinators . . . . . . . . 22
3.3 Confluence - Church Rosser Theorem . . . . . . . . . . 25
4 Computable Functions 32
4.1 Boolean Functions . . . . . . . . . . . . . . . . . . . . 32
4.2 Composition of Decomposition of Pairs . . . . . . . . . 33
4.3 Numeric Functions . . . . . . . . . . . . . . . . . . . . 34
4.4 Primitive Recursion . . . . . . . . . . . . . . . . . . . 36
1
4.5 Some Primitive Recursive Functions . . . . . . . . . . 37
4.6 General Recursion . . . . . . . . . . . . . . . . . . . . 41
5 Undecidability 43
2
1 Motivation
Why study lambda calculus?
Let us put the question in some historical context. At the be-
ginning of the 20th century the famous mathematician David Hilbert
challenged the mathematical community by the statement that math-
ematical problems must be decidable. At the 1930 annual meeting of
the Society of German Scientists and Physicians he made his famous
quote “We must know, we will know”.
“Entscheidungsproblem” (Decision
Problem). Mathematics must be
Challenge decidable. “We must know, we will
know!”
David Hilbert
3
Church invented the lambda calculus and Alan Turing his automatic
machine (today called Turing machine) which are both equivalent in
expressiveness.
Although Church’s lambda calculus has been published slightly be-
fore Alan Turing published his paper on automatic machines usually
Turing machines are used define computability and decidability. Tur-
ing machines resemble more the structure of modern computers than
lambda calculus. A programming language is called Turing complete
if all possible algorithms can be coded within the language. Nobody
talks about lambda complete.
However lambda calculus is a quite fascinating model of computa-
tion. The lambda calculus invented by Alonzo Church is remarkably
simple. It consists just of variables, function applications and lambda
abstractions. But the calculus is sufficiently powerful to express all
computable functions and decision procedures.
Beside its expressive power lambda calculus is used as the theoret-
ical base of functional languages like Haskell, ML, F#.
In this paper we explain the lambda calculus in its purest form as
untyped lambda calculus.
4
2 Inductive Sets and Relations
2.1 Inductive Sets
Set Notation A set is an unordered collection of objects. If the
object a is an element of the set A we write a ∈ A.
A set A is a subset of set B if all elements of the set A are also
elements of the set B. The symbol ⊆ is used to express the subset
relation. The operator := is used to express that something is valid
by definition. Therefore the subset relation is defined symbolically by
A ⊆ B := ∀a . a ∈ A ⇒ a ∈ B. The statement A ⊆ B can always be
replaced by its definition ∀a . a ∈ A ⇒ a ∈ B and vice versa.
The double arrow ⇒ is used to express implication. p ⇒ q states
the assertion that having a proof of p we can conclude q. The assertion
p ⇒ q is proved by assuming p and deriving the validity of q.
5
Rule Induction If we have the fact that an object is an element
of some inductively defined set then we can be sure that it is in the
set because of one of the rules which define the set.
This can be used to prove facts by rule induction. Suppose we want
to prove that some property p is shared by all even numbers. We can
n∈E
express this statement by the rule . Note that variables in
p(n)
rules are implicitly universally quantified, i.e. the rule expresses the
statement ∀n . n ∈ E ⇒ p(n).
It is possible to prove this statement by induction on n ∈ E. Such
a proof consists of a proof of the statement for each rule. In the case
of even numbers there are two rules.
For the first rule we have to prove the the number 0 satisfies the
property p(0).
For the second rule we assume that n ∈ E because there is some
other number m already in the set of even numbers E and n = m + 2.
I.e. we have to prove the goal p(m + 2) under the premise m ∈ E.
Because of the premise m ∈ E we can assume the induction hypothesis
p(m). I.e. we can assume m ∈ E and p(m) and derive the validity of
p(m + 2).
If the proof succeeds for both rules we are allowed to conclude that
the property p is satisfied by all even numbers.
6
terms n generated by the grammar
n ::= 0 | n0
i.e. we can use the corresponding induction law to prove that all terms
generated by the grammar satisfy a certain property.
This definition is just a special form of the definition of the set of
natural numbers N by the rules
1. 0 ∈ N
n∈N
2.
n0 ∈ N
r ⊆ A × B.
r r+ r
a b a b c
We called r+
the transitive closure of r, but the fact that r+ is
transitive needs a proof.
7
Theorem 2.2. The transitive closure r+ of the relation r is transitive
a →+ +
r b, b →r c
i.e. + is valid.
a →r c
Proof. Assume a →+ +
r b and prove the goal a →r c by induction on
+
b →r c.
1. Goal a →+ + +
r c assuming b →r c and that b →r c is valid by rule
1 of the transitive closure.
Premise b →r c.
The goal is valid by the assumption a →+
r b, the premise b →r c
and rule 2 of the transitive closure.
2. Goal a →+ + +
r d assuming b →r d and that b →r d is valid by rule
2 of the transitive closure.
Premises b →+ r c and c →r d.
Induction hypothesis a →+ r c.
The goal is valid by the induction hypothesis a →+
r c, the premise
c →r d and rule 2 of the transitive closure.
8
r∼ (a, b), r(c, b)
3.
r∼ (a, c)
Again a graphical representation of the rules:
r∼ r∼
r∼
r∼ r r∼ r
a a b c a b c
9
Theorem 2.8. All closures are increasing r ⊆ rc , monotonic r ⊆ s ⇒
rc ⊆ sc and idempotent rcc = rc (where the superscript c stands for
+, ∗ or ∼).
Proof. We give a proof for the reflexive transitive closure. The proofs
for the other closures are similar.
• Increasing: Goal r(a, b) ⇒ r∗ (a, b). By rule 1 we get r∗ (a, a).
The assumption r(a, b) and rule 2 imply r∗ (a, b).
r ⊆ s, r∗ (a, b)
• Monotonic: Goal . Prove by induction on r∗ (a, b).
s∗ (a, b)
1. Case a = b. Goal s∗ (a, a). Trivial by reflexivity of s∗ .
2. Goal s∗ (a, c) assuming r ⊆ s and r∗ (a, c) is valid because of
rule 2. Premises r∗ (a, b) and r(b, c). Induction hypothesis
s∗ (a, b).
a →r∗ b →r c
⇓1 ⇓2 .
a →s∗ b →s c
⇓1 is valid by the induction hypothesis. ⇓2 is valid by r ⊆ s.
From the last line and the rule 2 of the reflexive transitive
closure we can conclude s∗ (a, c).
• Idempotent: The equality of the relations r∗∗ = r∗ needs a proof
of r∗∗ ⊆ r∗ and a proof of r∗ ⊆ r∗∗ .
– r∗ ⊆ r∗∗ is valid because the closure is increasing.
r∗∗ (a, b)
– Goal ∗ . Proof by induction on r∗∗ (a, b).
r (a, b)
1. Case a = b. Goal r∗ (a, a). Trivial by reflexivity.
2. Goal r∗ (a, c) assuming r∗∗ (a, c) is valid because of rule
2. Premises r∗∗ (a, b) and r∗ (b, c). Induction hypothesis
a →r∗∗ b →r∗ c
r∗ (a, b). ⇓1 ⇓2 . ⇓1 is valid by the induc-
a →r∗ b →r∗ c
tion hypothesis. ⇓2 is trivial. r∗ is transitive. Therefore
the last line implies r∗ (a, c).
10
• sc ⊆ rc : sc ⊆ rcc by monotonicity and then use idempotence to
conclude sc ⊆ rc .
Terminal Elements
Definition 2.10. The set of terminal elements Tr of the relation r is
defined by the rule
a→b
⊥
a ∈ Tr
where ⊥ is used to denote a contradiction and the square brackets [
and ] around the rule above the line indicate that the variables not
used outside the bracketed rule are universally quantified in the inner
rule. I.e. in order to establish a ∈ Tr we have to prove ∀b . ¬ (a →r b)
or ∀b . a →r b ⇒⊥. Note that the scope of the universal quantification
of the variable a spans the whole rule while the scope of the universal
quantification of the variable b is just the premise of the rule (i.e. the
part above the line).
11
Strongly Terminating Elements
Definition 2.13. An object a is strongly terminating with respect to
the relation r if all paths from a end at some terminal element of r.
We define the set of strongly terminating elements STr of the relation
r by the rule
a →r b
b ∈ STr
a ∈ STr
This definition might need some explanation to be understood cor-
rectly. Since the premise of the rule is within brackets, all variables
not occuring outside the brackets are universally quantified within the
brackets (here the variable b).
The rule says that all objects a where all successors b with respect
to the relation are strongly terminating are strongly terminating as
well. The rule is trivially satisfied by all objects which have no succes-
sors i.e. all terminal objects. If the relation r has no terminal objects
then there are no initial objects which are strongly terminating.
If there are terminal elements then step by step strongly terminat-
ing objects can be constructed by the rule that all successors of them
must be strongly terminating (or already terminal). For each con-
structed strongly terminating object it is guaranteed that all paths
starting from it must end within a finite number of steps at some
terminal object of the relation.
An object a without successors with respect to the relation r i.e. if
there are no b with a →r b satisfy the rule, because the premise is sat-
ified vacuously. An object a without successors is a terminal element
by definition. I.e. all terminal elements are strongly terminating.
12
• all equivalent elements meet at some point
• all paths to terminal elements end up at the same terminal ele-
ment (i.e. terminal elements are unique)
A diamond relation is a superset of a confluent relation which has
already the essential part of confluence. It turns out that a diamond
relation is confluent.
First we define formally the diamond property of a relation. The
diamond property is intuitively a one step confluence.
Definition 2.14. A relation r is a diamond if for all a, b and c there
a →r b
exists a d such that ↓r ↓r holds.
c →r ∃d
Note that we use the picture
a →r b
↓r ↓r
c →r ∃d
to express the statement
a →r b, a →r c
.
∃d . b →r d ∧ c →r d
The picture notation is more intuitive but not less precise because it
can be translated into the corresponding rule notation which can be
translated uniquely into a statement of predicate logic.
Definition 2.15. A relation r is confluent if r∗ is a diamond.
Theorem 2.16. In a confluent relation r all two r-equivalent elements
a →∼ r b
meet at some common element in zero or more steps &∗r ↓∗r .
∃c
Proof. By induction on a →∼
r b.
1. a = b. Trivial. Take c = a.
a →∼ r c
2. Goal &∗r ↓∗r where a →∼ r c is valid by rule 2. Premises
∃e
a →∼ r b
∼
a →r b and b →r c. Induction hypothesis ∗
&r ↓∗ .
∃d
13
a →∼
r b →r c
Proof &∗r ↓∗r ↓∗r . d exists by induction hypothesis, e
∗
∃d →r ∃e
exists by confluence.
a →∼
r c
3. Goal &∗r ↓∗r where a →∼ r c is valid by rule 3. Premises
∃d
a →∼ r b
∼
a →r b and b ←r c. Induction hypothesis &∗r ↓∗r .
∃d
a →∼r b ← r c
Proof &∗r ↓∗r .∗r . d exists by induction hypothesis.
∃d
Theorem 2.17. In a confluent relation all paths from the same object
ending at some terminal object end at the same terminal object, i.e.
a →∗r b, a →∗r c, b ∈ Tr , c ∈ Tr
b=c
.
Proof. Suppose there are two terminal elements b and c with paths
starting from the object a. By definition of confluence there must be
a →∗r b
a d such that ↓∗r ↓∗r is valid. Since b and c are terminal objects
∗
c →r d
by theorem 2.11 there are only trivial outgoing paths from b and c
which implies that b = c = d must be valid.
14
a →∗r c
2. Goal ↓r ↓r where a →∗r c is valid because of rule
d →r ∃f∗
The last theorem stating that diamonds are confluent gives a way
to prove that a relation r is confluent. If r is already a diamond we
are ready since a diamond is confluent. If r is not a diamond we try to
find a diamond relation s between r and its reflexive transitive closure
r∗ i.e. a relation s which satisfies r ⊆ s ⊆ r∗ . From the theorem 2.9
we know that s and r have the same reflexive transitive closure i.e.
r∗ = s∗ . Since s is a diamond, s∗ is a diamond as well and therefore
r is confluent.
15
In order to find a diamond relation s we can search for rules which
are satisfied by r∗ and are intuitively the reason which let us assume
that r is confluent. Then we can define s inductively as the least
relation satisfying the rules and hope that we can prove that s is a
diamond with r ⊆ s. Note that s ⊆ r∗ is satisfied implicitly by this
approach since r∗ satisfies the rules and s is the least relation satisfying
the rules.
16
3 Lambda Terms
3.1 Basic Definitions
Imagine a mathematical function with one argument which triplicates
the argument and adds five to the result. How would you write such
a function. In mathematics the most straightforward notation is
x 7→ 3 × x + 5.
(x 7→ 3 × x + 5)(2) → (3 × x + 5)[x := 2] = 3 × 2 + 5.
(λx.3 × x + 5)2
which reduces to
17
represent data by functions as we shall see later. Data are represented
by functions which capture the essence of what can be done by the
data.
E.g. boolean values can be used to decide between two alterna-
tives. Therefore a boolean value is represented in lambda calculus
by a function with two arguments which chooses the first or second
argument depending on its value.
Numbers are represented by functions which take two arguments,
a function and a start value and the lambda term representing the
number iterates the function n-times on the start value.
18
Definition 3.3. A lambda term without free variables is called a
closed lambda term.
Evidently bound variables can be renamed without changing the
meaning of the term. E.g. the two lamda terms
λx.x
λy.y
are considered as the same term which represents the identity function.
Traditionally the terms are called α-equivalent because you transform
one into the other by just renaming bound variables.
We write t = u only if u and t are exactly the same term or α-
equivalent terms.
Renaming of bound variables must be done in a way which does
not change the structure of the term. The following two rules must
be obeyed.
1. Keep different bound variables distinct.
legal: λxy.x y rename to λab.a b
illegal: λxy.y rename to λxx.x
Variable Substitution
Definition 3.4. The variable substitution a[x := t] is defined by
x[x := t] := t
y[x := t] := y for x 6= y
a[x := t] :=
(ab)[x := t] := a[x := t] b[x := t]
(λy.a)[x := t] := λy.a[x := t] for x 6= y ∧ y ∈ / F V (t)
19
Substitution Swap Lemma The expression
a[x := b][y := c]
a[y := c][x := b]
20
with appropriate renaming of the bound variable z in order to
avoid variable capture (i.e. z must be different from x and y and
must not occur free neither in a nor in b).
Normal Forms
Definition 3.7. A λ-term is in normal form if it is a terminal element
of the β-reduction relation.
A λ-term is normalizing if it is a weakly terminating element of
the β-reduction relation.
A λ-term is strongly normalizing if it is a strongly terminating
element of the β-reduction relation.
21
In other words
• A λ-term is in normal form if it contains no reducible expression.
• A λ-term t is normalizing if there is a reduction path of zero or
more steps t →∗β u where u is in normal form.
• A λ-term t is strongly normalizing if all reduction paths end up,
after zero or more steps, in some normal form.
Clearly all terms in normal form are trivially normalizing and
strongly normalizing.
I := λx.x
where I is just an abbreviation for the term on the right hand side
of the definition. The lambda calculus does not know the term I, it
just knows terms like λx.x. We use I for us to formulate the calculus
more readable for humans.
The identity function takes one argument and returns exactly the
same argument which can be proved by application of the rules for
β-reduction
Ia = (λx.x)a definition of I
→β x[x := a] rule 1 of β-reduction .
= a definition of substitution
M := λx.xx.
Birdnames are used in this text as the names for combinators to honor
Haskell Curry who is one of the inventors of combinatorial logic and
who loved to watch birds and to honor Raymond Smullyan who wrote
the book To Mock a Mockingbird [4] using birds and forests and puz-
zles about them to teach combinatorial logic in an entertaining and
amusing way.
22
The mockingbird combinator receives one argument and applies
it to itself. The term M M has the interesting property to reduce to
itself
MM = (λx.xx)M definition of M
→β (xx)[x := M ] rule 1 of β-reduction
= MM definition of substitution
so that we have
M M →β M M →β M M . . .
which represents the simplest form of an endless loop in lambda cal-
culus.
A very important combinator is the kestrel
K := λxy.x
which receives two arguments and returns the first, easily proved by
The kestrel shows that λ-terms can in some way store values. If
we apply the kestrel K only to one argument a we get λy.a. This term
stores the value a within the abstraction. If later the term receives
its second argument it spits out the stored value a ignoring its second
argument.
The companion of the kestrel is the kite with the definition
KI := λxy.y
which receives two arguments and returns always the second i.e.
KI ab →+
β b
KI
23
where
KI →β λy.I
so that we get
KIab →β (λy.I)ab →β Ib →β b.
T := λxf.f x.
The trush stores its first argument and waits until it receives its second
argument. After receiving its second argument it uses the second
argument as a function and applies it to the first argument.
Even more interesting in its storage behaviour is the vireo, defined
as
V := λxyf.f xy.
The vireo applied to two arguments stores the arguments (i.e. it
stores a pair of values). After receiving its third argument it applies
the third argument as a function to the two stored values. Com-
bining the vireo, the kestrel and the kite we can encode pairs. V ab
stores the pair (a, b) and V abK returns the first element of the pair
and V abKI returns the second element of the pair i.e. V abK →+ β a
+
and V abKI →β b which can be proved by using the definitions and
applying β-reduction and substitution.
K := λxy.x,
the concrete definition is usually not necessery once the crucial prop-
erty of the kestrel
Kab →+ β a
24
has been proved to be valid.
In this text we don’t use complicated λ-terms. We always use
combinators with their corresponding properties to express compactly
our claims and proves of these claims.
In the following table the most important combinators together
with their specifications and implementations are summarized.
Name Abbreviation Specification Implementation
+
Bluebird B Bf gx →β f (gx) λf gx.f (gx)
Identity I Ix →β x λx.x
Kestrel K Kxy →+ β x λxy.x
+
Kite KI KI xy →β y λxy.y
+
Mockingbird M M x →β x x λx.x x
+
Starling S Sf gx →β f x(gx) λf gx.f x(gx)
Trush T T xf →+β fx λxf.f x
+
Turing U U xf →β f (xxf ) λxf.f (xxf )
Vireo V V xyf →+ β f xy λxyf.f xy
a →∗β b
↓∗β ↓∗β
c →∗β ∃d
is valid.
25
The core of the reduction relation is (λx.a)b →β a[x := b] where
(λx.a)b is the reducible expression. Both subterms a and b might
contain further reducible expressions. Since the variable x might be
contained in the expression a zero, one or more times all reducible
expressions of b can be contained in a[x := b] zero, one or more times.
If b contains a reducible expression a reduction step b →β c is
possible for some c. We have the situation that two reduction paths
are possible
(λx.a)b →β a[x := b]
↓β .
(λx.a)c →β a[x := c]
There are 3 cases:
• Case variable x does not occur in a: Then a[x := b] and a[x := c]
are the same expression and since →β is not reflexive there is no
way to complete the diagram.
• Case variable x does occur once in a: Then a[x := b] →β a[x := c]
is a valid reduction step and the diagram can be completed.
• Case variable x does occur 2 or more times in a: Then a[x := b]
cannot be reduced to a[x := c] in one step. 2 or more steps are
necessary.
26
a →∗β b c →∗β d
Theorem 3.8. →∗β satisfies .
ac →∗β bd
Proof by induction on a →∗β b.
1. Goal ac →∗β ad assuming c →∗β d. Proof by subinduction on
c →∗β d
(a) Case c = d. Trivial by reflexivity.
(b) Goal ac →∗β ae. Premises c →∗β d and d →β e. Induction
hypothesis ac →∗β ad.
c →∗β d →β e
⇓1 ⇓2
∗
ac → ad →β ae
β
⇓3
ac →∗β ae
⇓1 by induction hypothesis. ⇓2 by rule 3 of β-reduction. ⇓3
by rule 2 of reflexive transitive closures.
2. Goal ac →∗β ed. Premises a →∗β b and b →β e. Induction hy-
pothesis ac →∗β bd.
a →∗β b →β e
⇓1 ⇓2
ac →∗ bd →β ed.
β
⇓3
ac →β∗ ed
⇓1 by induction hypothesis. ⇓2 by rule 2 of β-reduction. ⇓3 by
rule 2 of reflexive transitive closures.
a →∗β b c →∗β d
Theorem 3.9. →∗β satisfies .
(λx.a)c →∗β b[x := d]
Proof in the same manner as the previous theorem with induction on
a →∗β b and then a subinduction on c →∗β d for the reflexive case.
a →∗β b
Theorem 3.10. →∗β satisfies .
λx.a →∗β λx.b
Proof in the same manner as the previous theorems without the need
of a subinduction because there is only one premise.
27
Definition 3.11. Parallel beta reduction →p is a relation defined over
lambda terms by the rules
1. a →p a
a →p b
2.
λx.a →p λx.b
a →p c
3. b →p d
ab →β cd
a →p c
4. b →p d
(λx.a)b →p c[x := d]
Obviously β-reduction is a subset of parallel β-reduction.
28
2. a is an application b c. Goal (bc)[x := t] →p (bc)[x := u]
((λy.a)c)[x := b] = (λy.a[x :=
b]) c[x := b] definition substitution
→p e[x := d] y := f [x := d] induction hypo + rule 4
= e[y := f ] [x := d] substitution swap lemma
29
a →p b
Theorem 3.16. Parallel reduction →p is a diamond i.e. ↓p ↓p .
c →p ∃d
Proof by induction on a →p b.
a →p a
1. Trivial reflexive case. ↓p ↓p
c →p c
λx.a →p λx.b
2. Goal ↓p ↓p . Parallel reduction preserves abstraction.
λx.c →p ?
Therefore the specific λx.c instead of the more general c. The
premises a →p b, a →p c and the induction hypothesis guarantee
the existence of a d such that λx.d is the element to fill the gap.
ae →p bf
3. Goal ↓p ↓p . Premises a →p b, e →p f . Proof by subinduc-
c →p ?
tion on ae →p c.
(a) Trivial reflexive case.
(b) Syntactically impossible
ae →p bf
(c) Goal ↓p ↓p .
gh →p ?
The premises a →p b, a →p g, e →p f, e →p h with the
corresponding induction hypotheses guarantee the existence
of two element k and m so that km can fill the missing
element in the goal.
(λx.a)e →p (λx.b)f
(d) Goal ↓p ↓p . Parallel reduction preserves
c[x := g] →p ?
abstraction. Therefore the specific λx.b in the upper right
corner. The premises a →p b, a →p c, e →p f, e →p g and
the corresponding induction hypotheses guarantee the ex-
istence of two elements d and h so that d[x := h] fills the
missing element in the goal.
(λx.a)e →p b[x := f ]
4. Goal ↓p ↓p . Premises a →p b, e →p f . Proof
c →p ?
by subinduction on (λx.a)e →p c.
30
(a) Trivial reflexive case.
(b) Syntactically impossible
(c) Mirror image of case 3d, just flipped at the northwest-southeast
diagonal.
(λx.a)e →p b[x := f ]
(d) Goal ↓p ↓p The premises a →p b, a →p
c[x := g] →p ?
c, e →p f, e →p g and the corresponding induction hypothe-
ses guarantee the existence of two elements d and h so that
d[x := h] fills the missing element in the goal.
β-Reduction is Confluent
Theorem 3.17. Beta reduction is confluent. Proof: With the paral-
lel beta reduction→p we have found a diamond relation between beta
reduction →β and its transitive closure →∗β . According to the conflu-
ence theorems of the chapter “Inductive Sets and Relations” this is
sufficient to prove the confluence of beta reduction.
31
4 Computable Functions
4.1 Boolean Functions
Boolean Values In lambda calculus there are no primitive data
types. All lambda terms are functions. If we want to represent boolean
values in lambda calculus we have to ask What can be done with a
boolean value?
Evidently boolean values can be used to decide between alterna-
tives. We can make the convention that the boolean value true always
decides for the first alternative and the boolean value false always de-
cides for the second alternative.
In the section Lambda Terms 3 we have already seen the combi-
nator kestrel K which always returns the first argument of two argu-
ments and the kite KI which always returns the second argument of
two arguments. Therefore we use the definitions
true := K
false := KI
Boolean Functions
Definition 4.2. A lambda term t represents an n-ary boolean func-
tion if given n arguments b1 , b2 , . . . bn reduces to a boolean value i.e.
if (
true
tb1 b2 . . . bn →∗β
false
is valid.
32
false. This is exactly the specifaction of boolean negation. Therefore
we define
(¬) := V false true.
Note that we use the logical symbol ¬ to represent the lambda term
for boolean negation and we use the same symbol to denote negation
on a logical level. It should be clear from the context wheather the
lambda term or the logical symbol is meant.
33
In the same manner the validity of snd (pair a b) →+
β b can be
verified.
Church Numeral
Definition 4.4. The church numeral cn defined as
cn := λf a.f n a
is the lambda term representing the natural number n.
Definition 4.5. The lambda term t represents a number if it reduces
in zero or more steps to a church numeral i.e. if
t →∗β cn
is valid for some n.
Definition 4.6. The term t represents an n-ary numeric function
if given n arguments a1 , a2 , . . . , an each one representing a number
reduces in zero or more steps to a church numeral i.e. if
ta1 a2 . . . an →∗β cm
is valid for some number m.
Definition 4.7. The term t represents an n-ary numeric predicate
if given n arguments a1 , a2 , . . . , an each one representing a number
reduces in zero or more steps to a boolean value i.e. if
(
∗ true
ta1 a2 . . . an →β
false
is valid.
34
Zero Tester A zero tester is a unary predicate on church numerals.
It should return true if the number is the church numeral c0 and false
for all other church numerals.
Remember that church numerals are functions with a function ar-
gument f and a start value argument a which iterate the function n
times starting at a. Therefore c0 f a always returns a regardless of the
function f . So our zero tester can have the shape
λx.xf true
Proof:
0? c0 = (λx.x(K false) true)c0
→β (x(K false) true)[x := c0 ]
= c0 (K false) true
→+β true
35
We know that the term xf a where x represents a church numeral
already does n iterations of f on n. The successor function just has
to do one more iteration
succ := λxf a.f (xf a).
We prove the desired property succ cn →∗β cn0 by
36
Suppose we have a lambda term g representing an n-ary numeric
function and a lambda term h representing an n00 -ary numeric func-
tion. Then in order to define an n0 -ary function f we can write
(
f c0 x := gx
f :=
f cn0 x := h(f cn x)cn0 x
s := λp.pair i(hjix)
f := λyx.y s p0
Addition (
c0 + m := m
(+) :=
cn0 + m := succ (cn + m)
37
Multiplication
(
c0 × m := c0
(×) :=
cn0 × m := m + cn × m
Exponentiation
(
• ac0 := c1
• :=
acn0 := a × acn
Factorial (
c0 ! := c1
(!) :=
cn0 ! := cn0 × cn !
Predecessor (
pred c0 := c0
pred :=
pred cn0 := cn
Difference
(−) := λab.b pred a
The term cn − cm applies the predecessor function m times to cn .
The result is the difference if n > m or c0 if n ≤ m.
Comparison
(≤) := λab. 0? (a − b)
Strict Comparison
Numeric Equality
(≡) := λab. a ≤ b ∧ b ≤ a
38
Bounded Minimization Let g be a lambda term representing an
n0 -ary predicate over church numerals. Then it makes sense to ask, if
there is a least number y which makes gyx true. The expression µy gx
should return this least number or y in case that there is no number
strictly below y such that gyx is satisfied.
(
µc0 gx := c0
µ :=
µcn0 gx := λz. (gzx)z(succ z) (µcn gx)
Division
(÷) := λab. µa (λx.a < succ x × b)
This function only works correctly if the divisor b is not zero. It
computes the least church numeral x such that succ x × b is greater
than the church numeral a. In that case the church numeral x × b is
exactly a or leaves some remainder less than b.
(|) := λab. ¬ a ≡ c0 ∧ (b ÷ a) × a ≡ b
39
i-th Prime Number We need a function Pr such that Pr c0 com-
putes c2 , Pr c1 computes c3 , Pr c2 computes c5 . . .
If z is a prime number then there is a prime number between z
and z!0 . We can use this fact to define Pr recursively.
(
Pr c0 := c2
Pr :=
Pr cn0 := λz. µsucc z! (λy. Pr y ∧ z < y) (Pr cn )
2n (2m + 1) − 1.
It is not too difficult to see that both numbers n and m can be recov-
ered from a number k to which the pair has been mapped i.e. that
the mapping is bijective. The number n is the exponent of the prime
factor of 2 in z + 1. Then the number m can be found in an obvious
way from z+12n .
We have already defined all functions to compute the mapping σ2
and its two inverses σ21 and σ22 as lambda terms.
σ2 := λab. c2 a × (c2 × b + c1 ) − c1
σ21 := λx. Prexp c0 (succ x)
σ22 := λx. (pred (succ x ÷ c2 σ21 x )) ÷ c2
40
4.6 General Recursion
The Problem Suppose we have a lambda term g representing an
n0 -ary predicate and we know that for all arrays of church numerals x
there exists a church numeral y such that gyx is satisfied.
If we had the ability to program a loop in lambda calculus we could
start an unbounded iteration at the church numeral c0 and stepwise
increase the number by one until the predicate g is satisfied.
Unfortunately we just know that a number exists, but we are not
able to specify any bound in order to use the bounded µ operator as
done in the previous chapter.
U af →+
β f (aaf ).
U U f y →+ + +
β f (U U f )y →β f (f (U U f ))y →β · · ·
Now let’s see what happens if we use sgx for f and cm for y:
U U f cm →+
β sgx(U U f )cm
+
.
→β (gcm x)cm U U f (succ cm )
41
Unbounded Minimization Having all this, we can define the
unbouded µ operator which receives an n0 -ary predicate g, an n array
of church numerals x such that the µ operator returns the least church
numeral y which satisfies the predicate gyx if such a term exists
µ := λgx. U U (sgx)c0
42
5 Undecidability
In the section Computable Functions 4 we have defined a class of nu-
meric functions and predicates which can be computed in lambda cal-
culus. We call this class of functions/predicates lambda-computable.
Now the question arises: Are there functions or predicates which
are not lambda computable? The answer to this question is yes. This
section of the paper proves that there are undecidable predicates.
In order to prove the existence of undecidable predicates we use
sets of lambda terms A which are closed and nontrivial. We make this
precise by the following definitions.
43
Self Application Since lambda calculus does not have any restric-
tions on functions and arguments (they only have to be valid lambda
terms) we can apply any lambda term t to its description ptq i.e. the
term
tptq
is a legal lambda term.
Therefore we can define for all sets of lambda terms A a set BA by
BA := {b | bpbq ∈ A}.
λx. pA (self x)
44
3. Assuming g ∈ BA leads to a contradition
4. Assuming g ∈
/ BA leads to a contradition
/ B ⇒ gpgq →+
g∈ β m0 definition of g
⇒ gpgq ∈ A A is closed
⇒ g ∈ BA definition of BA
45
Undecidability of the Halting Problem Like the halting
problem for Turing machines there is a halting problem for lambda
calculus. The halting problem is solvable if there is a lambda term
which determines if another lambda term is normalizing.
Theorem 5.6. It is undecidable whether a lambda term a is normal-
izing.
Proof. Assume that there is a lambda term p such that ppaq returns
true if a is normalizing and false if a is not normalizing.
1. Let A be the set which contains all lambda terms in normal form
and all α- and β-equivalent terms. By definition A is closed and
it is nontrivial (it contains all variables and it does not contain
M M .)
2. The lambda term p would be a decider for A, because a term a
must be in this set if it is normalizing.
3. The set A however being closed and nontrivial cannot be decid-
able which contradicts the assumption that being normalizing is
decidable.
46
With the step function
the term
cn spx0 q
computes px1 n x0 q and the function f defined by
computes the church numberal pλx1 x0 .x1 n x0 q. The term self can be
defined by
self := λx. σ2 c1 (σ2 x(f (f (xspx0 q))))
47
References
[1] Turing A.M. On computable numbers, with application to the
entscheidungsproblem. Proceedings of the London Mathematical
Society, 42:230–265, 1936/7.
[2] Alonzo Church. An unsolvable problem of elementary number
theory. Journal of Mathematics, 58:354–363, 1936.
[3] Kurt Gödel. Über formal unentscheidbare Sätze der Principia
Mathematica und verwandter Systeme. Monatshefte für Mathe-
matik und Physik, 38:173–198, 1931.
[4] Raymond Smullyan. To Mock a Mockingbird and Other Logic Puz-
zles. Knopf, 1985.
48