This action might not be possible to undo. Are you sure you want to continue?
S. ArunKumar
February 18, 2009
2
Preface
Students of computer science in IIT Delhi usually take a course on Theory of Computation
as an elective some time after they have ﬁnished courses on programming, data structures,
discrete mathematical structures (whatever that means), computer architecture, programming
languages and sometimes operating systems as well.
Theory of computation is of course a very broad and deep area, and it is anyone’s guess what
really should be taught in such course. For example, Dexter Kozen’s text with the same
name suggests that the course should dwell primarily on complexity classes. Most courses
on Theory of Computation in India follow the classic text by Hopcroft and Ullman [1] on
formal languages and automata which was written at a time when parsing, compiling, code
optimization and complexity theory were pursued as frontier areas of research. As a result, the
exposure to automata theory and formal languages was considered the most important aspect
of the theory, later followed by some exposure to NPcompleteness. Moreover the book was
written for graduate students
1
.
More recently (apparently on the strength of having course web pages on Programming, Logic,
Programming Languages and Complier Design), I have been bombarded by questions from
students and outsiders (some of them managers with computer science degrees who are willing
to pay thousands of dollars if I agreed to sit in on such a project) regarding the feasibility of
designing tools which would take the programs of their (novice?) programmers and transform
them automatically into the most eﬃcient program possible or the shortest program possible
in some language. I have even been asked why these programs cannot be proved automatically
thus saving the company a small fortune in testing time and being able to meet stiﬀ deadlines.
Anyway that’s my story and I am sticking to it.
It is my feeling that at a time when courses on compilers, formal languages, complexity theory
and automatic veriﬁcation are usually electives which students tend to avoid, this has led to
a disconnect between a course primarily devoted to formal languages and automata theory
and the bouquet of courses that students otherwise need to do in a typical computer science
curriculum.
Anyway that’s my story and I am sticking to it.
It is also my feeling that IIT students (who are numerically quite literate) feel most comfortable
when numbers and computations on numbers form the basis for a theory of computation. On
the other hand courses on theory of computation which primarily teach automata and formal
languages usually completely ignore the connections between programming and computability
theory and scant attention is paid to the theory of primitive recursive functions and the design
of data structures or programming language features. As a result students who sit through
a course on automata and formal languages and who have no intention of pursuing either
1
It is a mystery to me how it has come to be taught as a textbook for an undergraduate course. I would assume
that the same natural processes which brought Euclid, Descartes and Newton down to school mathematics are
responsible for it. But nevertheless the transition in the case of formal languages and automata has taken place
in less than 15 years while Newton took about 200 years before being prescribed for high school.
3
compilers or formal veriﬁcation or complexity theory, emerge from the course feeling that the
whole course was useless and unconnected to anything they have learned and anything else
they might learn and of no use whatsoever in their professional life in industry.
Anyway that’s my story and I am sticking to it.
I decided therefore to make computability theory the primary focus of these lecture notes
and gradually introduce Turing machines, ﬁnite automata and formal languages. I have used
the books of Cutland [4] and Martin Davis ([2], [3]) as my primary sources for these lecture
notes. I have tried to introduce the connections between the theory of computability with other
courses such as programming, functional programming, data structures, discrete mathematical
strucutres and operating systems in as elementary a fashion as possible. It has been a source of
wonder to me that this beautiful material seems to be taught mostly only to students of pure or
applied mathematics or logic rather than to computer science students. I am sure students of
engineering can absorb this material and appreciate it equally well, especially since it requires
little more than high school mathematics to understand it (though it might require a more
maturity to appreciate it).
Anyway that’s my story and I am sticking to it.
I have of course borrowed freely from various sources, but in many cases I have made signiﬁcant
departures fromt he original material especially as concerns notation. Not to put too ﬁne a
point on it, I believe that my notation though strange to look at, is an attempt to clean up
(mostly for my own understanding) misleading notation used in various sources.
4
Contents
1 Basics: Prerequisites and Notation 7
1.1 Sets and Operations on Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2 Relations, Functions and Predicates . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.3 Equality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.4 Other Notational Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2 The RAM Model 17
2.1 The Unlimited Register Machine (URM) . . . . . . . . . . . . . . . . . . . . . . 17
2.2 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3 The Primitive Recursive Functions 29
3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.2 Primitive Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
3.3 Primitive Recursive Predicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
3.4 Some Forms of Primitive Recursion . . . . . . . . . . . . . . . . . . . . . . . . . 40
4 The Partial Recursive Functions 45
5 Coding and G¨odelization 49
5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
5.2 Numbering and Coding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
5.3 G¨odel Numbers of URM Instructions . . . . . . . . . . . . . . . . . . . . . . . . 51
5
6 CONTENTS
5.4 G¨odel Numbering of Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
6 The Hierarchy of Primitive Recursive Functions 53
6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
6.2 URM–: A Restricted Machine for Primitive Recursion . . . . . . . . . . . . . . . 54
6.3 A NonPrimitive Recursive Total Partial Recursive function . . . . . . . . . . . 56
6.3.1 A Variant of the Ackermann function . . . . . . . . . . . . . . . . . . . . 56
6.3.2 The Growth of functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
7 Universality and Parametrisation 65
7.1 The Parametrisation theorem (Simpliﬁed form) . . . . . . . . . . . . . . . . . . 66
7.2 Universal functions and Programs . . . . . . . . . . . . . . . . . . . . . . . . . . 68
8 The typefree λcalculus 77
Chapter 1
Basics: Prerequisites and Notation
1.1 Sets and Operations on Sets
We assume the usual notions and notations of set theory including those of relations.
We will generally use the following notation for sets.
N The set of Natural numbers (including 0)
P The set of Positive integers
R The set of Real numbers
Z The set of Integers
∅ The empty set
⊆ The (inﬁx) subset relation between sets
⊂ The (inﬁx) proper subset relation between sets
∪ The inﬁx union operation on sets
∩ The inﬁx intersection operation on sets
∼ The preﬁx complementation operation on sets
− The inﬁx set diﬀerence operation on sets
The inﬁx cartesian product of sets
A
n
The postﬁx nfold cartesian product of A, i.e.A A
. .. .
ntimes
2
A
The powerset of A
The usual notations will be used for arithmetic operations on numbers. This includes the
operation of subtraction (denoted by the inﬁx operator −) which is also the set diﬀerence
operation. Similarly we may use the symbol for both cartesian product and multiplication of
numbers. Usually the context will determine which operation is intended. Some operations such
as multiplication may be denoted by ., or no symbol at all as is usual in mathematics. Further
the usual preﬁx operations for sum (
¸
) and product (
¸
) of sets or sequences of numbers will
be used.
7
8 CHAPTER 1. BASICS: PREREQUISITES AND NOTATION
Convention 1.1.1
• A
0
will be identiﬁed with the empty set ∅.
• A
1
will be identiifed with the set A
• A 1tuple (a) will be identiﬁed with a.
1.2 Relations, Functions and Predicates
Deﬁnition 1.1 A nary relation for n > 0 on sets A
1
, . . . , A
n
is any subset of A
1
A
n
.
Deﬁnition 1.2 Given two sets A and B and a binary relation f ⊆ AB,
• Then f
−1
⊆ B A the converse of f is the relation deﬁned by (b, a) ∈ f
−1
if and only
if (a, b) ∈ f.
• f is called a partial function of type A−→ B, if f satisﬁes the image uniqueness
property viz. that for each element a ∈ A there is at most one element b ∈ B such that
(a, b) ∈ f. b is called the image of a under f.
• f is said to be deﬁned at a ∈ A if a has an image under f.
• f is said to be undeﬁned at a if it has no image under f.
• f is called a total function of type A → B if f is a partial function of type A−→ B and
every element of A has an image under f.
r ⊆ A
1
A
n
A nary (for n > 0) relation on sets A
1
, . . . , A
n
f : A+→ B A partial function from set A to set B
f : A → B A total function from set A to set B
f(a) = b b is the image of a under f
f(a) =⊥ f is undeﬁned at a
Dom(f) The subset of values for which f is deﬁned
Ran(f) The subset of values which are images of elements in Dom(f)
Notes.
1.2. RELATIONS, FUNCTIONS AND PREDICATES 9
1. A constant (e.g. a natural number) will be regarded as a total function from the empty
set to the set that constant belongs to (e.g. N). This is to be regarded as being diﬀerent
from a constant function such as f : R → N deﬁned as f(x) = 5 which is a unary
total function deﬁned on the reals and which yields the natural number 5 for every real
argument.
2. The notation we use for functions may also be used for relations. In fact every relation
r ⊆ A
1
A
n
may be thought of as a total function of type r : A
1
A
k
→
2
A
k+1
×···×An
, for each k with 1 ≤ k < n. Hence for any (a
1
, . . . , a
k
) ∈ A
1
A
k
, where
1 ≤ k < n, then
r(a
1
, . . . , a
k
) = ¦(a
k+1
, . . . , a
n
) [ (a
1
, . . . , a
k
, a
k+1
, . . . , a
n
) ∈ r¦ (1.1)
3. When r(a
1
, . . . , a
k
) is a singleton set we omit the set braces. Further, each such relation
may also be thought of as a partial function of type
r : A
1
A
k
+→ A
k+1
A
n
(1.2)
where (a
1
, . . . , a
k
) ∈ Dom(r) if and only if r(a
1
, . . . , a
k
) = ∅ in 1.1
Facts 1.1
1. Every total function is also a partial function.
2. f : A → B implies Dom(f) = A.
Deﬁnition 1.3 Two partial functions f, g : A+→ B are equal if and only if Dom(f) = Dom(g)
and for each a ∈ Dom(f), f(a) = g(a).
Deﬁnition 1.4 Let f : A+→ B be a partial function.
• f is injective if for each a, a
′
∈ Dom(f), a = a
′
implies f(a) = f(a
′
). f is also said to
be an injection.
• If f is injective then f
−1
: B−→ A the inverse of f, with Dom(f
−1
) = Ran(f) ⊆ B and
for every b ∈ Dom(f
−1
), f
−1
(b) = a iﬀ f(a) = b.
• f is surjective if Ran(f) = B. f is also said to be a surjection.
• f is bijective (or is a bijection) if it is both injective and surjective.
10 CHAPTER 1. BASICS: PREREQUISITES AND NOTATION
Facts 1.2
1. If f : A−→ B is injective then for every a ∈ Dom(f), f
−1
(f(a)) = a.
2. If f : A−→ B is bijective then f
−1
is total (of type B → A) and for every b ∈ B,
f(f
−1
(b)) = b.
Deﬁnition 1.5 Let g : A−→ B and f : B−→ C be partial functions. The composition of g
and f (denoted [g; f] or [f ◦ g]) is the partial function h : A−→ C such that
• Dom(h) = ¦a ∈ Dom(g) [ g(a) ∈ Dom(f)¦ and
• for each a ∈ Dom(h), h(a) = [g; f](a) = [f ◦ g](a) = f(g(a)).
Notation. The notation f ◦ g is preferred by mathematicians generally, though the notation
g; f more closely represents the sequential composition of functions in programming. We will
use either of them.
Note that composition is strict in the sense that for any a, a ∈ Dom(g) or a ∈ Dom(g) but
g(a) ∈ Dom(f) implies a ∈ Dom(h) and hence h(a) =⊥.
If we were to regard f and g as transducers which take an input from its domain and transform
it into an output in its codomain, then h is a composite transducer which transforms an input
from a ∈ A into an output c ∈ C in a two step process by ﬁrst transforming a to b = g(a) and
then transforming b to c = f(b) = f(g(a)). The two step transformation may be pictured as
follows.
E
E
E
a
g
g(a)
f
f(g(a))
Figure 1.1: Composition of unary functions
Notation. We usually abbreviate sequences of values such as a
1
, . . . , a
k
(which are the arguments
of a function) by
⇀
a , where the length of the sequence is either understood or immaterial. Where
the length of the sequence is important we may write it as
⇀
k
a .
We will be interested in a generalised composition as deﬁned below.
Deﬁnition 1.6 Assume f : B
m
−→ C is an mary function and g
1
, , g
m
are kary functions
of the type g
1
, , g
m
: A
k
−→ B. Then the kary function h : A
k
−→ C obtained by composing
the m functions g
1
, . . . , g
m
with f (as shown in the ﬁgure below) is such that
1.2. RELATIONS, FUNCTIONS AND PREDICATES 11
• Dom(h) = ¦
⇀
k
a ∈ A
k
[ (∀i : 1 ≤ i ≤ m :
⇀
k
a ∈ Dom(g
i
)) ∧ (g
1
(
⇀
k
a ), , g
m
(
⇀
k
a )) ∈ Dom(f)¦
and
• h(
⇀
k
a ) = f(g
1
(
⇀
k
a ), , g
m
(
⇀
k
a )).
Notation. The same notation for sequences of values may be extended to sequences of functions
which are themselves arguments of a higherorder function. For example, the tuple of functions
g
1
, , g
m
(which are arguments of the generalised composition operator) may be denoted
⇀
g
.
Extending the notation for the composition of unary functions to generalised composition we
have h =
⇀
g
; f = f◦
⇀
g
. Where the length of the tuple is important we may write the above
tuples as
⇀
k
a and
⇀
m
g
respectively. Then h =
⇀
m
g
; f = f◦
⇀
m
g
.
,
,
,
E
E
,
,
,
E
E
,
,
,
,
,
,
g
g
g
E
E
E
E
E
E
a
1
a
k
a
1
a
k
b
2
b
1
a
1
a
k
f
b
m
c
g
1
g
2
g
k
Figure 1.2: Generalised Composition of functions
Deﬁnition 1.7 Given an nary relation r ⊆ A
1
A
n
, its characteristic function
denoted χ
r
, is the total function χ
r
: A
1
A
n
→ ¦0, 1¦ such that for each
⇀
a ∈ A
1
A
n
,
χ
r
(
⇀
a ) =
1 if
⇀
a ∈ r
0 if
⇀
a ∈ r
12 CHAPTER 1. BASICS: PREREQUISITES AND NOTATION
Deﬁnition 1.8 An atomic predicate is a relation
1
. The class of (ﬁrstorder) predicates
is the smallest class containing the atomic predicates and closed under the following logical
operations.
1. the unary (preﬁx) negation operation (denoted )
2. the binary (inﬁx) operation and (denoted ∧)
3. the binary (inﬁx) operation or (denoted ∨)
4. the unary (preﬁx) universal quantiﬁer (denoted ∀)
5. the unary (preﬁx) existential quantiﬁer (denoted ∃)
The usual notions of free and bound variables apply to the predicates and quantiﬁed formulae.
Further the usual meaning of these predicates is as deﬁned in any text on ﬁrst order logic.
Further the usual rules of scope of variables apply here. To denote the scope of variables in
quantiﬁed predicates we write the body of the quantiﬁed formula within brackets.
Example 1.2.1 Consider the ﬁrst order predicate q(
⇀
y
) deﬁned as q(
⇀
y
) = ∀
⇀
x [p(
⇀
x ,
⇀
y
)]
where p(
⇀
x ,
⇀
y
) is a ﬁrst order predicate in which the variables in
⇀
x and
⇀
y
may occur free.
p(
⇀
x ,
⇀
y
) may itself be a compound predicate deﬁned in terms of other predicates. The quantiﬁer
“∀
⇀
x ” in q(
⇀
y
) however, binds all occurrences of variables in
⇀
x that occur free in p(
⇀
x ,
⇀
y
).
The scope of the binding is indicated by the matching brackets “ [” and “ ]” in the deﬁnition of
q(
⇀
y
). The variables that are free in q are precisely those from
⇀
y
whixh occur free in p(
⇀
x ,
⇀
y
)
and this fact is indicated by the notation “q(
⇀
y
)”.
Deﬁnition 1.9 Let p and q be predicates with free variables drawn from
⇀
x and let
⇀
x = y,
⇀
z .
The characteristic functions of compound predicates is deﬁned in terms of the characteristic
functions of their components as follows.
• χ
¬p
(
⇀
x ) = 1 −χ
p
(
⇀
x )
• χ
p∧q
(
⇀
x ) = χ
p
(
⇀
x ).χ
q
(
⇀
x )
• χ
p∨q
(
⇀
x ) = 1 −(χ
¬p
(
⇀
x ).χ
¬q
(
⇀
x ))
• χ
∀y[p]
(
⇀
z ) =
0 if χ
p
(a,
⇀
z ) = 0 for some a
1 otherwise
1
Hence we use the same notation for atomic predicates as we use for relations
1.3. EQUALITY 13
• χ
∀y[p]
(
⇀
z ) =
1 if χ
p
(a,
⇀
z ) = 1 for some a
0 otherwise
We use some derived operators such as ⇒ and ⇔ deﬁned as follows:
(p ⇒ q) = (p) ∨ q
(p ⇔ q) = (p ⇒ q) ∧ (q ⇒ p)
The usual equational laws of Firstorder logic hold. We will also have occasion to use bounded
quantiﬁcation – operations derived from the quantiﬁers and used in the context of the natu
rals. They are deﬁned as follows.
∀y < z[p(
⇀
x , y)] = ∀y[(0 ≤ y < z) ⇒ p(
⇀
x , y)]
∃y < z[p(
⇀
x , y)] = ∃y[(0 ≤ y < z) ∧ p(
⇀
x , y)]
Note that bounded quantiﬁcation obeys the De Morgan laws making each bounded quantiﬁer
the dual of the other. That is
∀y < z[p(
⇀
x , y)] = (∃y < z[p(
⇀
x , y)])
∃y < z[p(
⇀
x , y)] = (∀y < z[p(
⇀
x , y)])
1.3 Equality
In the course of these notes we shall use various kinds of equality. Most of these notions of
equality share the property of being congruences i.e. they are equivalence (reﬂexive, symmetric
and transitive) relations and the two sides of the equality are mutually replaceable under all
contexts. However, it is necessary to emphasize that there are diﬀerences between the various
kinds of equality. Most mathematics texts often ignore these diﬀerences, (and we may have
been guilty too in the course of writing these notes!) but we feel that they are important for
various logical reasons and the reader should be aware of the diﬀerences. We brieﬂy describe
them below and we hope the diﬀerences that we have made explicit will be useful for the reader
in understanding not just these notes but mathematics texts in general.
Deﬁnitional Equality. This is an equality by deﬁnition, and we use the symbol to denote
this. This is most often used in the following situations.
1. to abbreviate a complex expression by giving it a name,
2. to name a complex expression because it or its form is somehow considered impor
tant.
14 CHAPTER 1. BASICS: PREREQUISITES AND NOTATION
Hence when we write p(x) x
2
−9 or q(x) x
3
+3x
2
+3x+1, we are either abbreviating
or naming the expression on the right hand side by the expression on the left hand side
of . Given another deﬁnition r(x) (x + 1)
3
, even in the context of polynomials over
the reals or integers it is incorrect to write “q(x) r(x)” because the two expressions
q(x) and r(x) deﬁne syntactically distinct expressions.
Instantiated Equality. Continuing with the previous examples we would often write expres
sions like p(4) = 4
2
− 9 = 7. Note here that p(4) is an instance of p(x) deﬁned above.
The equality symbol “=” (between “p(4)” and the expression “4
2
−9”) here is overloaded
to imply that p(4) is a particluar instance of the deﬁnition p(x) x
2
− 9
2
Note that
“p(y) = y
2
−9” is also a form of instantiated equality and so is p(x + 1) = (x + 1)
2
−9.
Syntactic Identity This is a peculiar notion of equality we will use more in the context of
languages or programs rather than in the case of mathematical expressions. Consider
the two expressions r(x) (x + 1)
3
and s(y) y
3
. It is clear that by appropriate
instantiations, we get r(z) = (z +1)
3
and s(z +1) = (z +1)
3
. Therefore r(z) = s(z +1).
However, this equality between r(z) and s(z + 1) is stronger than just provable equality
— they are in fact, syntactically identical as expressions. This syntactic identity depends
only on the form of the original deﬁnitions and is independent of the context or the
interpretation of these expressions in any mathematical domain. We emphasize this aspect
by writing r(z) ≡ s(z + 1). As in the case of deﬁnitional equality, syntactic identity also
implies provably equality. Also deﬁnitional equality implies syntactic identity.
αEquality. Consider the two deﬁnitions p(x) x
2
−9 and p
′
(y) y
2
−9. It is clear that p(y)
may be regarded as an instance of the deﬁnition p(x) x
2
−9 and p(y) ≡ p
′
(y). Equally
well may p
′
(x) be regarded as an instance of the deﬁnition p
′
(y) y
2
−9 yielding p(x) ≡
p
′
(x). However the two deﬁnitions themselves are not syntactically identical because
of the use of diﬀerent
3
names x and y to express each deﬁnition. Hence p(x) ≡ p
′
(y).
However there is a sense in which both the deﬁnitions p
′
(y) y
2
−9 and p(x) x
2
−9 may
be regarded as being the same (or equal) in that the variables x and y used to give the
deﬁnition its form are only “placeholders” whose name is of no consequence whatsover
except when replacement of one name by the other causes a name clash. In the absence
of such name clashes the uniform replacement of one name by the other causes neither
any confusion nor any change in the intended meaning of the deﬁnition. We call this
αequality and we denote this fact by writing p(x) =
α
p
′
(y). As with other equalities,
since αequality is also a reﬂexive relation, it follows that any two syntactically identical
expressions are also αequal. We will come across this later in the λcalculus.
Provable Equality. This is the most commonly used (and abused) equality and is denoted
by the usual “=” symbol. In the foregoing examples even though it is incorrect to write
q(x) r(x), in the context of polynomials over real numbers it is perfectly correct to write
(x + 1)
3
= x
3
+ 3x
2
+ 3x + 1, because the equality of the expressions x
3
+ 3x
2
+ 3x + 1
and (x+1)
3
can be proven using the laws of real number arithmetic. Any two expressions
that are equal by deﬁnition are also provably equal (by invoking the deﬁnition). Hence
2
However the equality symbol “=” between the expressions “4
2
−9” and “7” is provable equality.
3
The fact that we have used two diﬀerent names “p” and “p
′
” does not count!
1.4. OTHER NOTATIONAL DEVICES 15
p(x) = x
2
−9 and we could replace all occurrences of the expression p(x) by the expression
x
2
−9 and viceversa. It is also perfectly correct to write “p(x) = x
2
−9” or “x
2
−9 = p(x)”.
To continue with our examples in the context of polynomials, it follows therefore that
q(x) = r(x) since the expressions they denote are provably equal. But note that even in
the context of polynomials over reals, q(x) =
α
r(x) and q(x) ≡ r(x).
To summarize, we have that for any two (mathematical or formal) expressions E and F
1. E F implies E ≡ F and
2. E ≡ F implies E =
α
F which in turn implies E = F. Hence E F also implies E =
α
F
and E = F.
3. None of the above implications may however, be reversed in general i.e., it is not true in
general that if E = F then E =
α
F or E ≡ F would hold, nor does E ≡ F imply E F
or F E holds.
4. Further while all forms of equality may be instantiated, no form of instantiated equality
may imply any other form of equality unless it can be proven.
1.4 Other Notational Devices
We generally follow the practice of splitting long proofs of theorems into claims and using these
claims. In most cases the proofs of claims are distinguished from the main proof by the use of
the bracketing symbols “⊢” and “⊣” to enclose the proof of the claim and separate it from the
proof of the main theorem.
16 CHAPTER 1. BASICS: PREREQUISITES AND NOTATION
Chapter 2
The RAM Model
2.1 The Unlimited Register Machine (URM)
Assume the following about the machine.
• A countably inﬁnite number of discrete storage elements called registers each of which
can store an arbitrarily large natural number. The registers R
1
, R
2
, R
3
, are indexed
by the set P of positive integers. These registers form the memory.
• The contents of R
i
, i ∈ P are denoted respectively by !R
i
∈ N. Equivalently M : P → N
the memory map may be regarded as a total function from the positive integers to the
natural numbers so that M(i) =!R
i
for each i ∈ P.
• We will usually ensure that only ﬁnitely many registers contain nonzero values i.e. M is
0 almost everywhere.
• A URM program P is a sequence I
1
, I
2
, . . . , I
p
of instructions.
• The instruction set has opcodes 0, 1, 2, 3 respectively, and each instruction I
j
, 1 ≤ j ≤ p,
is typically of one of the following forms where i, m, n ∈ P.
opcode instruction semantics Verbal description
0 Z(n) R
n
:= 0 Clear register R
n
1 S(n) R
n
:=!R
n
+ 1 Increment the contents of register R
n
2 C(m, n) R
n
:=!R
m
Copy the contents of register R
m
into R
n
Jump to instruction i if the contents of the
3 J(m, n, i) !R
m
=!R
n
? i : j + 1 registers R
m
and R
n
are the same.
Otherwise execute the next instruction
17
18 CHAPTER 2. THE RAM MODEL
We have used the syntax of the imperative fragment of SML to describe the eﬀect of each
instruction on the appropriate register. The semantics of the jump instruction mixes
pidgin SML with the notation for conditional expressions used in languages like C and
Perl. The verbal description describes the semantics informally in English.
• Given a URM program P = I
1
, I
2
, . . . , I
p
, register contents r
1
, r
2
, . . . respectively and a
program counter PC ∈ P denoting the next instruction to be executed, a conﬁguration
of the URM is a 3tuple 'P, M, PC` where M(n) = r
n
.
• Given an initial memory M
0
and a program P = I
1
, I
2
, , I
p
, with p ≥ 1, the initial
conﬁguration of the URM is
γ
0
= 'P, M
0
, 1`
• Let γ = 'P, M, j` be any conﬁguration of the URM. The URM is said to halt if j > p.
Such a conﬁguration is also called the halting conﬁguration and the result of the
computation is M(1) the contents of the register R
1
. If 0 < j ≤ p, then a step of the
computation from γ is given by γ → γ
′
where γ
′
= 'P, M
′
, j
′
` and M
′
and j
′
are as given
by the following table:
I
j
= M
′
= j
′
=
Z(n) ¦0/n¦M j + 1
S(n) ¦M(n) + 1/n¦M j + 1
C(m, n) ¦M(m)/n¦ j + 1
J(m, n, i) M i if M(m) = M(n)
M j + 1 if M(m) = M(n)
where M
′
= ¦a/n¦M denotes that M
′
is identical to M for all values other than n and
M
′
(n) = a regardless of whatever M(n) might be.
• Unconditional jumps are described by instructions such as J(n, n, j) since M(n) =
M(n) always. Similarly skip instructions (or noop as they are referred to in hardware)
may be implemented using instructions such as C(n, n) or by jumping unconditionally to
the next instruction.
• The URM executes instructions in sequence (unless it executes a jump instruction, when
the sequence is altered) till the instruction referred to by PC does not exist. Then the
URM is said to halt.
Deﬁnition 2.1 A memory map M of the URM is said to be ﬁnite if there are only a ﬁnite
number of registers containing nonzero values i.e. the set ¦M(n) [ M(n) > 0¦ is ﬁnite.
If the (initial) memory M
0
in the initial conﬁguration is such that ¦M
0
(n) [ M
0
(n) > 0¦ is
ﬁnite, then the result of executing each instruction results in a new memory state M
′
such that
¦M
′
(n) [ M
′
(n) > 0¦ is also ﬁnite. In other words, at no stage of the execution of the program
does the URM require more than a ﬁnite number of registers to be used.
2.1. THE UNLIMITED REGISTER MACHINE (URM) 19
Lemma 2.1
1. Each URM instruction preserves ﬁnite memory maps.
2. The only registers whose contents may modiﬁed by a URM program are those that are
explicitly named in the program.
Every instruction has a deterministic eﬀect on the URM machine. In other words, given a
memory map M each of the instructions Z(n), S(n) and C(m, n) when executed, would yield a
unique memory state M
′
in all programs and under all execution conditions. The instruction
J(m, n, i) too has the eﬀect of uniquely determining the next instruction (if any) to be executed.
Lemma 2.2 .
1. Every nonhalting conﬁguration of the URM has a unique successor. That is, γ → γ
′
and
γ → γ
′′
implies γ
′
= γ
′′
.
2. If Γ is the set of all URM conﬁgurations with ﬁnite memory maps then → is a partial
function from Γ to Γ.
→ is a partial function on the conﬁgurations of the URM because it is undeﬁned for halt
ing conﬁgurations. It suﬃces for us to consider only conﬁgurations with ﬁnite memory maps,
since we are interested in the notion of computability which requires for each task only a ﬁnite
amount of resources such as storage and program length. However, we do need to consider the
availability of unlimited storage. If we did ﬁx storage limits to some ﬁxed number then our
theoretical development suﬀers when technology improves to provide more storage than our
limit. A theory such as ours would have long term applicability only if it does not artiﬁcially
constrain the solutions to problems. Similarly while we consider the executions of URM pro
grams of arbitrary length our fniteness constraints are limited to specifying that the program
may not be of inﬁnite length.
The reader could ask whether the limitation to just four kinds of instructions is not an artiﬁcial
constraint. Our answer to that would be twofold viz.
1. that only the kinds of operations are being ﬁxed and that any reasonable mechanical
device (going by the history of mechanical devices) would be capable of performing only
a ﬁxed ﬁnite set of diﬀerent kinds of operations, and
2. the actual parameters that these operations may take is actually inﬁnite.
Deﬁnition 2.2 Let γ
0
be an initial conﬁguration of the URM. A (ﬁnite or inﬁnite) sequence
of the form γ
0
→ γ
1
→ is called an execution sequence from γ
0
. A computation of the
URM is a maximal execution sequence from an initial conﬁguration.
20 CHAPTER 2. THE RAM MODEL
Lemma 2.3 Let γ
0
→ γ
1
→ γ
2
→ be an execution of the URM with the corresponding
memory maps M
0
, M
1
, M
2
, . . .. If M
0
is a ﬁnite memory map, then so are each of the succeeding
memory maps M
1
, M
2
, etc.
Deﬁnition 2.3
1. A URM program P converges on input (a
1
, a
2
, ..., a
k
) if it begins execution from the initial
memory state M
0
= a
1
, a
2
, ..., a
k
, 0, 0, ... and PC = 1 and halts after a ﬁnite number of
steps of computation.
Notation. P(a
1
, a
2
, ..., a
k
) ↓ denotes that P converges on input (a
1
, a
2
, ..., a
k
)
2. Otherwise P is said to diverge on the input. Notation. P(a
1
, a
2
, ..., a
k
) ↑.
3. P is said to converge to b ∈ N on the input (a
1
, a
2
, ..., a
k
) if it converges on the input
and reaches a conﬁguration in which M(1) = b.
Notation. P(a
1
, a
2
, ..., a
k
) ↓ b denotes that P converges on input (a
1
, a
2
, ..., a
k
) to b.
Deﬁnition 2.4 A URM program P URMcomputes a partial function f : N
k
−→N, if and
only if
• for each (a
1
, ..., a
k
) ∈ Dom(f), P(a
1
, ..., a
k
) ↓ f(a
1
, ..., a
k
) and
• P(a
1
, ..., a
k
) ↑ for all (a
1
, ..., a
k
) ∈ Dom(f)
Deﬁnition 2.5 A partial function f is URMcomputable if and only if there is a URM
program P which computes f. A predicate p is URMdecidable if and only if there is a URM
program which computes its characteristic function χ
p
.
For each k ≥ 0, every URM program P computes a partial function φ
(k)
P
: N
k
+→ N. Given an in
put (a
1
, a
2
, ..., a
k
) it begins execution from the initial memory state M
0
= a
1
, a
2
, . . . , a
k
, 0, 0, . . .
and PC = 1 and if and when it halts φ
(k)
P
(a
1
, ..., a
n
) =!R
1
, i.e. the ﬁnal result is the value
in register R
1
. If it does not halt for the given input then φ
(k)
P
(a
1
, ..., a
n
) =⊥. In the case
decidability however, if p is an mary relation for some m > 0, note that the characteristic
function is always total and hence a URM program that implements it should halt for every
mtuple input. But it is quite possible that the program does not halt on some (m + 1)tuple
input.
2.2. EXAMPLES 21
2.2 Examples
In the following examples we illustrate programming the URM. Since the actual programs can
be quite tedious and confusing to read and understand, we also provide ﬂowcharts to explain
the working of the programs. The language of ﬂow charts consists of boxes, circles, diamonds
and arrows connecting them to form a ﬂowchart program. We follow the usual convention that
boxes denote actions that could change the memory state.
Boxes enclose actions which may change the state of the memory. We use a notation drawn
from pidgin SML for this purpose. The same notation has been used earlier in the
tables deﬁning the semantics of the instruction set. Each box may enclose a sequence of
instructions.
Diamonds indicate decisions to be taken depending on the evaluation of the condition in the
diamond. Each diamond encloses a condition of the form !R
m
?
=!R
n
whose truth in the
memory state requires a diﬀerent ﬂow of control. The letters “Y” and “N” on the arrows
emanating from a diamond indicate the ﬂow of control when the condition is true or false
respectively.
Circles usually enclose the single word “STOP” and indicate that a halting conﬁguration has
been reached and no further execution is possible or necessary.
In each case the initial memory map is also indicated
Example 2.2.1 The addition function x + y.
¨
¨
¨
¨
¨ ¨
3
3
3
3
3
3
r
r
r
r
r
r
c
c
E
E
N
Y
P1
R1 R2 R3
y
. . . .
x 0
1. J ( 2, 3, 5 )
2. S ( 3 )
3. S ( 1 )
4. J ( 1, 1, 1)
R3 :=!R3 + 1
R1 :=!R1 + 1
STOP !R2
?
=!R3
Example 2.2.2 f(x) =
1
2
x if x is even
⊥ otherwise
22 CHAPTER 2. THE RAM MODEL
`
¨
¨
¨
¨
¨
3
3
3
3
3
3
r
r
r
r
r r
c
E
c
c
c
N
Y
P2
R3 :=!R3 + 1
R2 :=!R2 + 1
R2 :=!R2 + 1
R1 R2 R3
x k 0 . . . 2k
R1 :=!R3
1. J( 2,1,6 )
3. S ( 2 )
4. S( 2 )
5. J ( 1, 1, 1)
6. C ( 3, 1 )
2. S ( 3 )
STOP
!R2
?
=!R1
Further notes, notations and terminology
• Every instruction of the URM is deterministic (in the sense that the eﬀect of the instruc
tion on the state of the program is unique). Therefore every URMprogram is computes
partial of the initial state to the ﬁnal state
• Since we are interested only in the contents of R1 when a program P halts, every program
is a partial function whose range is contained in N.
Notation. Given a program P and a tuple of inputs
⇀
a = (a
1
, . . . , a
k
), P(a
1
, . . . , a
k
)
denotes the result of executing P with the input
⇀
a
• The type of the function determined by a program P depends entirely on the vector of
inputs that we consider.
1. The addition program P
1
in the example does not necessarily represent only the
binary operation ofaddition.
2. If there are no inputs it implements the constant function 0.
3. If the initial conﬁguration has only a single input, x then P
1
implements the identity
function f(x) = x.
4. If the initial coﬁguration consists of 3 values then P
1
implements the partial function
f(x, y, z) =
x + y −z if x ≥ 0
⊥ otherwise
Hence for any URM program P and for any k ≥ 0, P implments a unique partial function
φ
k
P
: N
k
+→ N i.e the arity of the function implemented by a program is not predetermined
and is dependent entirely on the length of the input vector.
Deﬁnition 2.6 A URMprogram P implements a function g : N
k
+→ N iﬀ φ
k
P
= g.
2.2. EXAMPLES 23
Example 2.2.3 Consider program P
2
. The following are the functions it implements for for
the arities 1,2 and 3 respectively.
φ
(1)
P
2
(x) =
1
2
x if x is even
⊥ otherwise
φ
(2)
P
2
(x, y) =
1
2
(x −y) if x is even(xy)
⊥ otherwise
φ
(3)
P
2
(x, y, z) =
z +
1
2
(x −y) if x is even
⊥ otherwise
Notes.
1. Each program P implements an inﬁnite number of distinct functions and exactly one
function of each arity.
2. For each function f : N
k
+→ N that has an implementation P, there are an inﬁnite number
of distinct programs that implement the same function.
Example 2.2.4 Add to program P
2
the following instruction
J(1, 1, 8)
This produces a new program P
2
′
, which implements exactly the same function as P. We
could similarly add more instructions and keep getting syntactically distinct programs which all
implement the same function.
URM Decidability
Deﬁnition 2.7 A predicate (or a relation) p ⊆ N
m
is URMdecidable if its characteristic
(total) function χ
p
: N
m
→ ¦0, 1¦ is URMcomputable.
Example 2.2.5 The following predicates are URMdecidable.
1. x = y is implemented by
24 CHAPTER 2. THE RAM MODEL
cmrmn.
c
E
c
'
¨
¨
¨
¨
¨ ¨
r
r
r
r
rr
¨
¨
¨
¨
¨
¨
c
N
R1 := 0
1
2
1. J ( 1, 2, 4)
2. Z ( 1 )
3. J ( 1, 1, 6 )
4. Z ( 1 )
5. S ( 1 )
STOP
! R1
?
=!R2
Y
R1 := 0
R1 :=!R1 + 1
2. odd(x) is implemented by incrementing R
2
and toggling R
3
to reﬂect the evenness or
oddness of R
2
. Let T(3) denote toggle R
3
. Initially !R
2
= 0 and !R
3
= 0. The ﬁnal ﬂow
chart including T(3) looks as follows.
cmrmn.
c
c
cmrmn.
c
E
3
3
3
3
3
3
¨
¨
¨
¨
¨
r
r
r
r
r
c
STOP
Y
R
1
:=!R
3
N
!R
1
?
=!R
2
S(2)
T(3)
The ﬁnal program is then as follows.
2.2. EXAMPLES 25
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
r
r
r
r
r
r
r
r
c
c
c
c
E STOP
S(3)
Z(3)
Y !R
3
?
=!R
4
N
Figure 2.1: Implementing T(3)
1. J (1,2,8)
2. S (2)
3. J (3,4,6)
4. Z (3)
5. J (1,1,1)
6. S (3)
7. J (1,1,1)
8. C (3,1)
Composing URMPrograms
Function composition in URM is simply the catenation of the component programs. However
we cannot catenate two programs to produce a composition unless the termination or halting
of the ﬁrst is tackled in a meaningful fashion – clearly then jump instructions have to be
standardized.
Deﬁnition 2.8 A program P = I
1
, ..., I
r
is in standard form provided every jump instruction
J(m, n, p) is such that 1 ≤ p ≤ r + 1.
Lemma 2.4 For any program P there is a program P
⋆
in standard form such that for all input
vectors
⇀
a , P(
⇀
a ) ↓ b iﬀ P
∗
(
⇀
a ) ↓ b.
26 CHAPTER 2. THE RAM MODEL
Proof: If P consists of p instructions then P
∗
is the program obtained from P by replacing all
jump instructions that go outside the program to jump to p + 1. 2
Deﬁnition 2.9 For any two programs P, Q in standard form with P = I
1
, . . . , I
p
and Q =
I
′
1
, . . . , I
′
q
, the join of P and Q is the program PQ = I
1
, ..., I
p
, I
p+1
, ..., I
p+q
where any jump
instruction I
′
j
= J(m, n, r) is replaced by I
p+j
= J(m, n, r + p) and for all other instructions
I
′
j
= I
p+j
.
Macros: The operation [l
1
, . . . , l
k
→ l]
Our convention of reserving the ﬁrst few registers for input and the ﬁrst register for output
has the disadvantage that it is inconvenient when joining several smaller programs together to
obtain a larger program. While composing programs P and Q together it often happens that
the inputs to some later program in the join may lie scattered in diﬀerent registers. Similarly
the output of some component program may have to be stored in some register other than R
1
in order that the contents of these registers do not aﬀect or interfere with the computations of
the main program.
Let P be a URM program in standard form and k such that φ
(k)
P
: N
k
+→ N is computed
by P. Since P is a ﬁnite sequence of instructions there exists a highest index of register
that P uses. Let ρ(P) denote the index of this register. Further let l
1
, l
2
, ..., l
n
, l be distinct
registers with each index exceeding ρ(P). Then the program P
′
= P[l
1
, ..., l
k
→ l] denotes a
new program whose inputs are in registers R
l
1
, ..., R
l
k
and output (if any) in register R
l
. Let
m = max(ρ(P), l
1
, . . . , l
k
, l). This new program P
′
is depicted in the ﬁgure below
E
E
P[l
1
, ...l
k
→ l] ::
.
.
.
.
.
.
F
P
Transfer input
values to R
1
, ..., R
k
Clear all registers
Join P to I.
Join F to P.
R
k+1
, ..., R
m
Z(m)
C(l
1
, 1)
C(1, l)
C(l
k
, k)
Z(k + 1)
2.2. EXAMPLES 27
URMComputability on other Domains
Deﬁnition 2.10 A coding of a domain D is an explicit and eﬀective injection α : D → N.
A function f : D+→ D is said to be URMcomputable under the coding α if there exists a
URMcomputable function f
∗
: N+→ N such that the following diagram holds. i.e
E
c
T
E
D D
α
−1
f
α
f
⋆
N N
For any d ∈ D, f(d) = α
−1
(f
⋆
(α(d))) In other words f = α ◦ f
⋆
◦ α
−1
Note:
1. α needs to be injective and total.
2. α may not be surjective, so α
−1
is partial in general.
28 CHAPTER 2. THE RAM MODEL
Chapter 3
The Primitive Recursive Functions
3.1 Introduction
Partial recursive functions are a diﬀerent approach to computability. In this and the next
chapter we will see the relation between partial recursive functions and URMcomputability.
However we need to ﬁrst deﬁne the class of primitive recursive functions and then gradually
build up to the partial recursive functions.
Deﬁnition 3.1 The initial functions are
1. the constant 0,
2. the unary successor function s
3. the family ¦π
n
i
[ n ∈ P, 1 ≤ i ≤ n¦ of projection functions, where for each ntuple
(x
1
, . . . , x
n
), and each i, 1 ≤ i ≤ n, π
n
i
(x
1
, . . . , x
n
) = x
i
URM and µrecursive functions
Lemma 3.1 The initial functions are all URMcomputable.
Proof:
• the constant 0 is computed by the program Z(1)
• the unary successor function s is computed by the program S(1)
• For each n ∈ P and i, 1 ≤ i ≤ n, π
n
i
is computed by the program C(i, 1).
29
30 CHAPTER 3. THE PRIMITIVE RECURSIVE FUNCTIONS
2
Lemma 3.2 Composition is URMcomputable. Let f : N
k
+→ N, g
1
, , g
k
: N
m
+→ N
Then the composition of f and
⇀
g
denoted by f◦
⇀
g
is also URMcomputable.
Proof: Let f and g
1
, , g
k
be computed by programs F, G
1
, ..., G
k
respectively and let n =
max(m, k, ρ(F), ρ(G
1
), ..., ρ(G
k
)). The following program computes f◦
⇀
g
C(1, m+ 1)
.
.
.
C(n, m + n)
G
1
[m+ 1, m+ 2, ..., m+ n → m + n + 1]
.
.
.
G
k
[m+ 1, m+ 2, ..., m+ n → m+ n + k]
F[m+ n + 1, ..., m+ n + k → 1]
2
Often we may require to obtain new functions from existing functions by permuting the ar
guments, or by identifying some arguments or by the addition of dummy arguments. Typical
examples of such functions are as follows:
Permuting arguments Consider the “divisor of” relation on numbers expressed in terms of
its characteristic function divisorof : N N → ¦0, 1¦. We may deﬁne the “multiple of”
relation multipleof : N N → ¦0, 1¦ in terms of the divisorof function by permuting
the two arguments, i.e. multipleof(x, y) = divisorof(y, x).
Identiﬁcation of arguments Consider the function double : N → N which is obtained from
addition function by identifying the two operands of addition.
Addition of dummy arguments Any constant k ∈ N may be elevated to the status of a
function such as k
(1)
: N → N deﬁned as k
(1)
(x) = k and further to k
(2)
: N N → N
deﬁned as k
(2)
(x, y) = k.
The following theorem shows that these operations are also URMcomputable and expressed
using only composition and the initial functions.
Theorem 3.3 Let f : N
k
+→ N be a URMcomputable function deﬁned in terms of the variables
x
1
, . . . , x
k
. Let x
i
1
, . . . , x
in
be a sequence of nvariables drawn from the set ¦x
1
, x
2
, ..., x
m
¦ ⊇
¦x
1
, . . . x
k
¦. Then the function h : N
n
+→ N deﬁned by
3.2. PRIMITIVE RECURSION 31
h(x
i
1
, . . . , x
in
) = f(x
j
1
, . . . , x
j
k
)
where ¦x
j
1
, . . . , x
j
k
¦ ⊆ ¦x
1
, x
2
, ..., x
m
¦, is also URM computable.
Proof: Writing
⇀
n
x for (x
i
1
, ..., x
in
) and
⇀
k
π
m
for (π
m
j
1
, , π
m
j
k
) and using composition we have
h(
⇀
n
x ) = [f◦
⇀
k
π
m
](x
1
, . . . , x
m
)
Since composition and projection are both URMcomputable it follows that h is also URM
computable. 2
Notes.
1. The case of the empty sequence () is taken care of by lemma 3.7 which shows that the
naturals are all computable.
2. Since x
i
1
, . . . , x
in
are all drawn from the set ¦x
1
, x
2
, ..., x
m
¦ ⊇ ¦x
1
, . . . x
k
¦, some of the
arguments of h may be identiﬁcations of variables in ¦x
1
, . . . x
k
¦, some may be reorderings
(permutations) of the variables in ¦x
1
, . . . x
k
¦ and some of them may be drawn from
¦x
1
, x
2
, ..., x
m
¦ − ¦x
1
, . . . x
k
¦ (these are the dummy arguments of h). Notice that the
arguments (x
j
1
, . . . , x
j
k
) f in the deﬁnition of h are entirely drwan from ¦x
1
, x
2
, ..., x
m
¦.
3.2 Primitive Recursion
Given total functions f : N
n
→ N and g : N
n
→ N, consider the following relation h ⊆ N
n+2
where h =
¸
i≥0
h
i
and the individual h
i
, i ≥ 0 are deﬁned by induction as follows.
h
0
= ¦(
⇀
x , 0, f(
⇀
x )) [
⇀
x ∈ N
n
¦
h
i+1
= ¦(
⇀
x , i + 1, z
i+1
) [
⇀
x ∈ N
n
, z
i+1
= g(
⇀
x , y, z
i
), (
⇀
x , y, z
i
) ∈ h
i
¦ for i ≥ 0
In fact as the following theorem shows we may express the relation h by a pair of so called
recursion equations which uniquely deﬁne h in terms of the functions f and g.
h(
⇀
x , 0) = f(
⇀
x ) (3.1)
h(
⇀
x , y + 1) = g(
⇀
x , y, h(
⇀
x , y)) (3.2)
Theorem 3.4 Given total functions f : N
n
→ N and g : N
n+2
→ N, there exists a unique total
function h : N
n+1
→ N satisfying the recursion equations (3.1) and (3.2).
32 CHAPTER 3. THE PRIMITIVE RECURSIVE FUNCTIONS
Proof:
Existence. Consider sets of (n+2)tuples of numbers. A set S ⊆ N
n+2
is called satisfactory
with respect to the recursion equations (3.1) and (3.2) if for every choice of
⇀
a ∈ N
n
,
Basis. (
⇀
a , 0, f(
⇀
a )) ∈ S and
Induction. if (
⇀
a , b, c) ∈ S, then (
⇀
a , b + 1, g(
⇀
a , b, c)) ∈ S.
Let o be the set of all satisfactory sets. Clearly o = ∅ since N
n+2
is satisfactory. Con
sider S
0
=
¸
o. S
0
is also nonempty since it contains at least every tuple of the form
(
⇀
a , 0, f(
⇀
a )). Further
Claim 1. S
0
is satisfactory and is contained in every satisfactory set.
Claim 2.
For each choice of
⇀
a and b, there is a unique c such that (
⇀
a , b, c) ∈ S
0
.
⊢ Suppose there is a tuple (
⇀
a , 0, c) ∈ S
0
. If c = f(
⇀
a ) then S
′
0
= S
0
−¦(
⇀
a , 0, c)¦ would be
satisfactory since (
⇀
a , 0, f(
⇀
a )) ∈ S
′
0
but S
0
⊆ S
′
0
. Hence c = f(
⇀
a ). Assume the claim is
true for all 0 ≤ b
′
≤ b. Then for each choice of
⇀
a there exists a unique c ∈ N such that (
⇀
a
, b, c) ∈ S. Since S
0
is satisfactory it follows that (
⇀
a , b+1, g(
⇀
a , b, c)) ∈ S
0
. Suppose there
exists (
⇀
a , b + 1, d) ∈ S
0
such that d = g(
⇀
a , b, c). Then again S
′
0
= S
0
−¦(
⇀
a , b + 1, d)¦
is a satisfactory set and S
0
⊆ S
′
0
which is impossible. ⊣
Uniqueness. Suppose there exist two functions h and h
′
both of which satisfy the recursion
equations (3.1) and (3.2). Then from the fact that f and g are (total) functions we have
∀
⇀
a [h(
⇀
x , 0) = f(
⇀
x ) = h
′
(
⇀
x , 0)]
and assuming that for all
⇀
a and some b ≥ 0,
h(
⇀
a , b) = h
′
(
⇀
a , b)
we have
h(
⇀
a , b + 1) = g(
⇀
a , b, h(
⇀
a , b))
= g(
⇀
a , b, h
′
(
⇀
a , b))
= h
′
(
⇀
a , b + 1)
2
We may extend the above result to partial functions by insisting that functions be strict with
respect to the undeﬁned.
Theorem 3.5 Given partial functions f : N
n
+→ N and g : N
n+2
+→ N, there exists a unique
partial function h : N
n+1
+→ N satisfying the recursion equations (3.1) and (3.2).
3.2. PRIMITIVE RECURSION 33
Proof: We leave the details of the proof of the above theorem to the reader, while simply
noting that if f is the everywhere undeﬁned function then so is h (prove it!). Further in the
inductive deﬁnitions of the relations h
i
, if for any i ≥ 0, h
i
= ∅ then h
j
= ∅ for all j > i. 2
We may regard both function composition and primitive recursion as (higher order) operators
which take functions of appropriate arities as arguments and yield new functions as results. Both
composition and primitive recursion are polymorphic functions. More precisely, our notation
for functions f of type N
k
+→ N simply speciﬁes that f is simply a member of the set N
k
+→ N,
which is exactly the space of all partial functions of the speciﬁed type. That is f is simply
a point in the space N
k
+→ N of functions of arity k which yield natural numbers as values.
Function composition and primitive recursion are therfore merely functions or operators on
such spaces.
In the particular case when a function f of arity k > 0 is composed with k functions
⇀
g
, where
each of the components of
⇀
g
is of arity m > 0, we get a new function h of arity m. In such a
case, the type of composition may be described as follows.
◦ : (N
k
+→ N) (N
m
+→ N)
k
→ (N
m
+→ N)
Similarly primitive recursion may be regarded as a polymorphic operator of type
pr : (N
n
+→ N) (N
n+2
+→ N)+→ (N
n+1
+→ N)
Notation
• The composition of f with
⇀
g
is denoted [
⇀
g
; f] or [f◦
⇀
g
].
• The function deﬁned by primitive recursion on f and g is denoted [f pr g].
Primitive recursion is URMcomputable
Deﬁnition 3.2 A function h : N
n+1
+→ N is said to be deﬁned by primitiverecursion on
functions f : N
n
+→ N and g : N
n+2
+→ N if it satisﬁes the equations
h(
⇀
x , 0) = f(
⇀
x )
h(
⇀
x , y + 1) = g(
⇀
x , y, h(
⇀
x , y))
Theorem 3.6 If f : N
n
+→ N and g : N
n+2
+→ N are URMcomputable then so is h : N
n+1
+→
N with
h(
⇀
x , 0) = f(
⇀
x )
h(
⇀
x , y + 1) = g(
⇀
x , y, h(
⇀
x , y))
34 CHAPTER 3. THE PRIMITIVE RECURSIVE FUNCTIONS
Proof: Let F and G compute f and g resp and let m = max(n +2, ρ(F), ρ(G)) and t = m+n
Then the following program computes h(
⇀
x , y).
Rt+1 Rt+3
Rt+2 Rt Rm Rm+1 R1
y k
. . .
⇀
x h(
⇀
x , k)
C(1, m+ n)
C(n + 1, t + 1)
F[1, 2, ..., n → t + 3]
p. J(t + 2, t + 1, q)
G[m + 1, ..., m+ n, t + 2, t + 3 → t + 3]
S(t + 2)
J(1, 1, p)
q. C(t + 3, 1).
2
Lemma 3.7 Every natural number is URMcomputable
Proof: Each natural number n : ∅ → N is a total function from the empty set to the naturals.
J(1, 1, 2) computes the number 0.
For any n > 0 the following program computes it
1. S(1)
. .
. .
. .
n. S(1)
2
Deﬁnition 3.3 The class PRIMREC of primitive recursive functions is the smallest class
of functions containing the initial functions and which is closed under the operations of function
composition and primitive recursion
That is, the class PRIMREC may be deﬁned by induction as follows
PRIMREC
0
= ¦0¦ ∪ ¦s¦ ∪ ¦π
n
i
[ n > 0, 1 ≤ i ≤ n¦
PRIMREC
j+1
= PRIMREC
j
∪ ¦[f◦
⇀
g
] [ f,
⇀
g
∈ PRIMREC
j
¦
∪¦[f pr g] [ f, g ∈ PRIMREC
j
¦
PRIMREC =
¸
k≥0
PRIMREC
k
3.2. PRIMITIVE RECURSION 35
In the above deﬁnition, we have not explicitly mentioned the type restrictions on composition
and primitive recursion, for the sake of conciseness. However, these restrictions are required.
Hence in order to show that a certain function belongs to the class PRIMREC, we require to
show the construction of the function as belonging to a certain PRIMREC
k
, for some k ≥ 0.
This implies that we need to show an explicit construction of the function using only the initial
functions and the operations of composition and primitive recursion, while still respecting the
type restrictions on composition and primitive recursion.
Lemma 3.8 Every function in PRIMREC is total.
Proof outline: By induction on the induction variable j in deﬁnition 3.3. It follows easily since
the initial functions are total and each application of composition or primitive recursion is on
total functions belonging to a class with a smaller index. 2
Lemma 3.9 Every function deﬁned by composition or by primitive recursion on functions in
PRIMREC is also primitive recursive.
Notice that the proof of theorem 3.3 may be reproduced as the proof of lemma 3.10.
Lemma 3.10 Let f : N
k
→ N be a primitive recursive function deﬁned in terms of the variables
x
1
, . . . , x
k
. Let x
i
1
, . . . , x
in
be a sequence of nvariables drawn from the set ¦x
1
, x
2
, ..., x
m
¦ ⊇
¦x
1
, . . . x
k
¦. Then the function h : N
n
→ N deﬁned by
h(x
i
1
, . . . , x
in
) = f(x
j
1
, . . . , x
j
k
)
where ¦x
j
1
, . . . , x
j
k
¦ ⊆ ¦x
1
, x
2
, ..., x
m
¦, is also primitive recursive.
Theorem 3.11 The following underlined functions are primitive recursive (and hence URM
computable).
Proof outline: In each case we express the function as being obtained by a ﬁnite number of
applications of composition and primitive recursion on the initial functions. Often we simply
express a function in terms of composition or primitive recursion on functions shown earlier
to be in the class PRIMREC. These formulations not only prove that they are primitive
recursive, they show that these functions are URMcomputable as well (since we have shown
that both composition and primitive recursion are URM computable operations. In each case,
the proof is written between the brackets ⊢ ⊣.
36 CHAPTER 3. THE PRIMITIVE RECURSIVE FUNCTIONS
1. k ∈ N.
⊢ 0 is initial. For k > 0 we have k = [s ◦ ◦ s]
. .. .
ktimes
(0) .
⊣
2. id(x) = x.
⊢ Clearly id = π
1
1
. ⊣
.
3. add(x, y) = x + y.
⊢ Using the induction on y we get x + 0 = x = id(x) and x + (y + 1) = (x + y) + 1 =
s(x + y) = s(add(x, y)) = [s ◦ add]. We then have add = [id pr [s ◦ π
3
3
]] . ⊣
4. mult(x, y) = xy.
⊢ Again by induction on y we have x.0 = 0 and x.(y + 1) = xy + x = x + xy =
x + mult(x, y) = add(x, mult(x, y)). By lemma 3.10 we may express the constant 0 also
as a constant function (of any number of arguments). We write it as 0(x) and it is clearly
primitive recursive. The function g(x, y, z) = add(x, z) = add ◦ (π
3
1
, π
3
3
) then yields the
deﬁnition mult = [0 pr [add ◦ (π
3
1
, π
3
3
)]] .
⊣
5. texp(x, y) = x
y
(assuming 0
0
= 1).
⊢ Using the deﬁnitions texp(x, 0) = 1 = s(0) = s(0(x)) and texp(x, y+1) = mult(x, texp(x, y))
we use a reasoning similar to that for multiplication to get texp = [[s ◦ 0] pr [mult ◦ (π
3
1
, π
3
3
)]] .
⊣
6. tpred(x) = x −1 (assuming tpred(0, 1) = 0).
⊢ Here x is the induction variable. So we get tpred = [0 pr π
2
1
] ⊣
7. monus(x, y) = x
.
− y.
⊢ We have x
.
− 0 = x = id(x) and x
.
− (y+1) = tpred(x
.
− y) Hence monus = [id pr [tpred ◦ π
3
3
]]
⊣
8. sg(x) deﬁned as sg(x) =
0 if x=0
1 if x > 0
3.2. PRIMITIVE RECURSION 37
⊢ Clearly sg(0) = 0 and sg(x + 1) = 1. It is easy to see that sg(x) = 1
.
− (1
.
− x) =
monus(1, monus(1, x)). Using 1 as unary constant function we have
sg = [monus ◦ (1, [monus ◦ (1, id)])] ⊣
9. sg(x) deﬁned as sg(x) =
1 if x = 0
0 if x > 0
⊢ sg(x) = 1
.
− sg(x) ⊣
10. sdiff(x, y) = [x −y[.
⊢ [x −y[ = (x
.
− y) + (y
.
− x) = add(monus(x, y), monus(y, x)). Hence
sdiff = [add ◦ ([monus ◦ (π
2
1
, π
2
2
)], [monus ◦ (π
2
2
, π
2
1
)])] . ⊣
11. fact(x) = x!.
⊢ We have 0! = 1 and (x + 1)! = x! (x + 1) = mult(s(x), fact(x)), which yields
fact = [1 pr [mult ◦ ([s ◦ π
2
1
], π
2
2
)]] ⊣
12. min(x, y).
⊢ min(x, y) = x
.
− (x
.
− y) Hence min = [monus ◦ (π
2
1
, [monus ◦ (π
2
1
, π
2
2
)])] ⊣
13. max(x, y).
⊢ max(x, y) = y + (x
.
− y). Hence max = [add ◦ (π
2
1
, [monus ◦ (π
2
1
, π
2
2
)])] ⊣
14. trem(x, y) =
y if x = 0
y mod x otherwise
⊢ We have
trem(x, y + 1) =
0 if trem(x, y) + 1 = x
trem(x, y) + 1 if trem(x, y) + 1 = x
which gives the following recursion equations:
trem(x, 0) = 0
trem(x, y + 1) = mult(trem(x, y) + 1, sg([x −(trem(x, y) + 1)[))
from which we get trem = [0 pr [mult ◦ (s ◦ π
3
3
, [sg ◦ [sdiff ◦ (π
3
1
, [s ◦ π
3
3
])]])]] ⊣
38 CHAPTER 3. THE PRIMITIVE RECURSIVE FUNCTIONS
15. tquot(x, y) =
0 if x = 0
y div x otherwise
⊢ We have
tquot(x, y + 1) =
tquot(x, y) + 1 if trem(x, y) + 1 = x
tquot(x, y) if trem(x, y) + 1 = x
from which we get the following recursion equations.
tquot(x, 0) = 0
tquot(x, y + 1) = add(tquot(x, y), sg([x −(trem(x, y) + 1)[))
Hence tquot = [0 pr [add ◦ (π
3
3
, [sg ◦ [sdiff ◦ (π
3
1
, [s ◦ π
3
3
])]])]] ⊣
2
The deﬁnitions of trem and tquot are total and have been chosen so that for any two numbers
a, b, a = b tquot(b, a) + trem(b, a) with trem(b, a) ≤ a.
We may use part 1 of theorem 3.11 to obtain the following corollary, which extends the use of
lemma 3.10 to instances of functions. For example the doubling function double(x) (which was
previously considered an example of identiﬁcation of arguments of the addition operation) could
be regarded as an instance of the binary multiplication operation in which one argument is
the constant 2. Similarly the function f(n) = 2
n
may be considered an instance of the function
texp in which the ﬁrst argument is the constant 2.
Corollary 3.12 If f : N
k+1
→ N is primitive recursive then so is any instance of it.
Proof: By lemma 3.10 we may reorder the arguments of f so that the argument instantiated
is the ﬁrst one. Hence without loss of generality we assume that the ﬁrst argument of f is
instantiated to obtain the kary function g(
⇀
k
y
) = f(m,
⇀
k
y
) where m is some ﬁxed natural
number m. Then by lemma 3.10 we may treat m as a unary function deﬁned as m
(1)
(x) = m.
Then clearly g = [f ◦ (m
(1)
, π
k+1
2
, , π
k+1
k+1
)]. 2
Claim 1. Let f : N → N be primitive recursive, then f
n
(x), the nfold application of f is also
primitive recursive.
⊢ Deﬁne the nfold application of f to be the function h by the recursion equations.
h(x, 0) = x
h(x, t + 1) = f(h(x, t)) = [f ◦ π
3
3
](x, t, h(x, t)))
Hence h = [id pr [f ◦ π
3
3
]] is a primitive recursive function.
⊣
3.3. PRIMITIVE RECURSIVE PREDICATES 39
3.3 Primitive Recursive Predicates
We have seen several functions that are primitive recursive. We now turn to the question of
designing some primitive recursive predicates on numbers. Note that every predicate yields
a value of 0 or 1 depending upon whether it is true or false respectively. In this sense we
have already deﬁned two such functions sg(x) and sg(x) in theorem 3.11, both of which could
be interpreted as predicates standing for the properties “isnonzero(x)” and “iszero(x)”
respectively.
Theorem 3.13 The following underlined predicates are primitive recursive and hence are also
URMcomputable.
Proof outline: Unlike the case of theorem 3.11 we do not give complete expressions and leave
the formulation of the actual deﬁnition to the reader. We explain only the key ideas that may
be used in formulating the primitive recursive deﬁnition.
1. the equality relation.
⊢ χ
=
(x, y) = sg(sdiff(x, y)) ⊣
2. the lessthan relation
⊢ χ
<
(x, y) = sg(monus(x, y))
⊣
3. the greaterthan relation.
⊢ χ
>
(x, y) = χ
<
(y, x)
⊣
4. the “divisorof” relation.
⊢ Adopting the convention that 0 is a divisor of 0, but 0 is not a divisor of any positive
integer, we get χ

(x, y) = sg(trem(x, y)) ⊣
2
Often in the interest of readability we will use the relational symbols, “=”, “<”, “>” and “[”
for the obvious relations they denote, instead of their characteristic functions.
40 CHAPTER 3. THE PRIMITIVE RECURSIVE FUNCTIONS
3.4 Some Forms of Primitive Recursion
Corollary 3.14 (Deﬁnition by cases). Let f
1
, f
2
, . . . , f
m
: N
k
+→ N be URMcomputable
functions and p
1
, p
2
, . . . , p
m
: N
k
→ ¦0, 1¦ be URMdecidable predicates such that for any
⇀
x ∈ N
k
exactly one of p
1
(
⇀
x ), , p
m
(
⇀
x ) is true. Then the function g : N
k
+→ N
g(
⇀
x ) =
f
1
(
⇀
x ) if p
1
(
⇀
x )
.
.
.
f
m
(
⇀
x ) if p
m
(
⇀
x )
is URMcomputable. Further if f
1
, f
2
, ..., f
m
, p
1
, p
2
, ..., p
m
are each primitive recursive then so
is g.
Proof: g(
⇀
x ) = χ
p
1
(
⇀
x ).f
1
(
⇀
x ) + + χ
pm
(
⇀
x ).f
m
(
⇀
x ). 2
Corollary 3.15 (Algebra of Decidability). If p, q : N
k
→ ¦0, 1¦ are URMdecidable pred
icates then so are the following
(i) p (ii) p ∧ q (ii) p ∨ q
Further if p and q are primitive recursive then so are p, p ∧ q and p ∨ q.
Proof:
(i) χ
¬p
(
⇀
x ) = monus(1, χ
p
(
⇀
x ))
(ii) χ
p∧q
(
⇀
x ) = χ
p
(
⇀
x ).χ
q
(
⇀
x )
(iii) χ
p∨q
(
⇀
x ) = max(χ
p
(
⇀
x ), χ
q
(
⇀
x )) 2
Bounded sums and Products
Theorem 3.16 Let f, g, h : N
k+1
+→ N such that
g(
⇀
x , y) =
¸
z<y
f(
⇀
x , z) =
0 if y = 0
¸
z<w
f(
⇀
x , z) + f(
⇀
x , w) if y = w + 1
h(
⇀
x , y) =
¸
z<y
f(
⇀
x , z) =
1 if y = 0
¸
z<w
f(
⇀
x , z).f(
⇀
x , w) if y = w + 1
Then g and h are URMcomputable if f is total and URMcomputable and g and h are primitive
recursive if f is primitive recursive.
3.4. SOME FORMS OF PRIMITIVE RECURSION 41
Proof: Since the above are deﬁnitions by primitive recursion it follows that g and h are
computable (respectively primitive recursive). More rigorously we have
g = [0 pr [add ◦ (π
k+2
k+2
, [f ◦ (π
k+2
1
, , π
k+1
k+1
)])]]
h = [1 pr [mult ◦ (π
k+2
k+2
, [f ◦ (π
k+2
1
, , π
k+1
k+1
)])]]
2
Corollary 3.17 If f, i : N
k+1
→ N are total computable functions then so are g(
⇀
x , y) =
¸
z<i(
⇀
x ,y)
f(
⇀
x , z) and h(
⇀
x , y) =
¸
z<i(
⇀
x ,y)
f(
⇀
x , y) Further if f and i are primitive recursive then
so are g and h.
Bounded Quantiﬁcation
Theorem 3.18 Let p(
⇀
x , y) be any predicate and let q(
⇀
x , y) = ∀z < y[p(
⇀
x , z)] and r(
⇀
x , y) =
∃z < y[p(
⇀
x , z)].
1. If p is URMcomputable then so are q and r.
2. If p is primitive recursive then so are q and r.
Proof: We have χ
q
(
⇀
x , y) =
¸
0≤z<y
χ
p
(
⇀
x , z) and r(
⇀
x , y) = (∀z < y[p(
⇀
x , z)]) from which the
relevant results follow. 2
Bounded Minimalization
Let p : N
k+1
→ ¦0, 1¦ be a
decidable
. .. .
(total) computable predicate. Then the function
g(
⇀
x , y) = µz < y[p(
⇀
x , z)] =
least z < y : p(
⇀
x , z) if z exists
y otherwise
(3.3)
That is, g(
⇀
x , y) = z
0
⇔ ∀z[0 ≤ z < z
◦
≤ y ⇒ p(
⇀
x , z)]
Theorem 3.19 g in (3.3) above is computable if p is URMcomputable. Further if p is primi
tive recursive then so is g.
42 CHAPTER 3. THE PRIMITIVE RECURSIVE FUNCTIONS
Proof: Consider all the predicates p(
⇀
x , z) for each value of z. For each 0 < v < y we have
f(
⇀
x , v) =
¸
u≤v
p(
⇀
x , u) =
1 if ∀u : 0 ≤ u ≤ v : p(
⇀
x , u) = 1
0 otherwise
For each 0 ≤ w < y we have
¸
0≤w<y
f(
⇀
x , w) =
w if w < z
0
z
0
if w > z
0
Hence g(
⇀
x , y) =
¸
w<y
¸
v≤w
p(
⇀
x , v)
which is a primitive recursive function of p. 2
Corollary 3.20 If p : N
k+1
→ ¦0, 1¦ is decidable and f : N
k+m
→ N is a total computable
function then g(
⇀
x , y) = µz < f(
⇀
x ,
⇀
w)[p(
⇀
x , z)] is a total computable function.
Theorem 3.21 The following functions are primitive recursive.
1. #div(x) = the number of divisors of x (assuming #div(0) = 1)
2. prime(x) = “whether x is a prime”
3. p
x
= the xth prime number (assuming p
0
= 0)
4. (x)
y
= the exponent of p
y
in the prime factorization of x.
Proof:
1. #div(x) =
¸
y≤x
y [ x
2. prime(x) = eq(#div(x), 2)
3. p
0
= 0 and p
y+1
= µz ≤ (p
y
! + 1)[(p
y
< z) ∧ prime(z)]
4. (x)
y
= µz < x[p
z+1
y
∤ x]
2
Theorem 3.22 The set PRIMREC of primitive recursive functions is countably inﬁnite.
3.4. SOME FORMS OF PRIMITIVE RECURSION 43
Proof: It suﬃces to prove the following two claims.
Claim 1. The set PRIMREC is not ﬁnite.
⊢ By contradication . Assume there are only ﬁnitely many primtive recursive functions of
arity n for some n ≥ 0, say f
(n)
1
, , f
m
:
(n)
. Since they are all total we may, construct a
new total function g
(n)
: N
n
→ N such that g
(n)
(
⇀
x ) = max(f
(n)
1
(
⇀
x ), , f
(n)
m
(
⇀
x ) + 1. g
(n)
is
diﬀerent from every one of f
(n),...,f
(n)
m
1
and since max is primitive recursive and + is primitive
recursive it follows that g
(n)
is primitive recursive contradicting the initial assumption. Hence
PRIMREC
(n)
is inﬁnite. ⊣
Claim 2. The set PRIMREC is countably inﬁnite
⊢ From deﬁnition 3.3 it is clear that every primitive recursive function belongs PRIMREC
j
for some j ≥ 0. We may deﬁne the depth of a primitive recursive function f to be the smallest
index j, such that f ∈ PRIMREC
j
. For each j ≥ 0, let PR
j
denote the set of primitive
recursive functions of depth j. Clearly then, we have
¸
j≥0
PR
j
= PRIMREC and for each
i = j, PR
i
∩ PR
j
= ∅. In particular, we have PR
0
= PRIMREC
0
which is countably
inﬁnite and by induction we may show that each PR
j
is also at most countably inﬁnite. Since
PRIMREC is the countable union of at most countable sets, PRIMREC is countably inﬁnite.
⊣
2
44 CHAPTER 3. THE PRIMITIVE RECURSIVE FUNCTIONS
Chapter 4
The Partial Recursive Functions
Unbounded Minimization
Let p : N
k+1
→ ¦0, 1¦ be a decidable predicate. Then g : N
k
−→N deﬁned by
g(
⇀
x ) µ[p(
⇀
x .y)] is computable where
=
least y : p(
⇀
x , y) i.e (∀z < z
◦
[p(
⇀
x , z)]) ∧ p(
⇀
x , z
◦
)
⊥ otherwise ⇔ g(
⇀
x ) = z
◦
Theorem 4.1 Unbounded Minimizationis URMcomputable.
Proof: Let g and p be as deﬁned above and let P be a URM program that computes p.
Let m = max(k + 1, ρ(p))). Then
R1 Rm Rm+1 R
m+k
R
m+k+2
R
m+k+1
. . . . . 1 y
⇀
x
2
45
46 CHAPTER 4. THE PARTIAL RECURSIVE FUNCTIONS
E
E
E
E
E
E
k. C(k, m +k)
k + 1. Z(m, k +k)
k + 2. S(m, k + 2)
k + 3. P(m + 1, ..., m+k + 2 → 1)
k + 4. J(1, m +k + 2, k + 7)
k + 5. S(m +k + 1)
k + 6. J(1, 1, k + 3)
k + 7. C(m +k + 1, 1)
1. C(1, m+ 1)
.
.
.
Copy
⇀
x to R
m+1
to R
m+k
Initialize R
m+k+1
to 0.
Initialize R
m+k+2
to 1 for comparision
run P and have output in R
1
compare R
1
and R
m+k+2
and jump
otherwise increment R
m+k+1
`
3
3
3
3
d
d
d¨
¨
¨
¨
c
c
c
S(m + k + 2)
P[m + 1, ..., m + k + 1 → 1]
S(m + k + 1)
C(m + k + 1, 1)
!R1
?
= 1
Stop
C[1, ..., k → m + 1, ..., m + k]
Z(m + k + 1)
Run P
Set to 1 for comparing truth values
Copy parameters
y : =0
Copy y into R1
Partial Recursive Function
Deﬁnition 4.1 The class PRIMREC of primitive recursive functions is the smallest class
(i) Containing the basic functions —————— (o, s, id
k
i
)
(ii) Closed under composition and —————— ◦[f; g
1
, ..., g
k
]
(iii) Closed under primitive recursion ————– Pr[f, g]
Deﬁnition 4.2 The class PARTREC of partial recursive functions is the smallest class
(i) Containing the basic functions —————— (o, s, id
k
i
)
(ii) Closed under composition and —————— ◦[f; g
1
, ..., g
k
]
47
(iii) Closed under primitive recursion ————– Pr[f, g]
(iv) Closed under (unbounded) minimalization. µy[ρ]
Theorem 4.2 PRIMREC ⊆ PARTREC ⊆ URM
Proof: The foregoing results have shown this. 2
Theorem 4.3 Every URMcomputable function is partial recursive.
Proof: Let f : N
k
+→ N be a URMcomputable function implemented by a program P =
I
1
, . . . , I
s
. A step of the execution of P is the execution of a single instruction.
Now consider the following functions
c
1
(
⇀
x , t)
!R
1
if P has stopped executing in less than t steps
!R
1
after tsteps of execution of P otherwise
j(
⇀
x , t)
0 if P has stopped execution in less than t steps
the number of the next instruction to be executed after tsteps otherwise
Claim 1. c
1
, : N
k+1
→ N are total fuctions.
Claim 2. c
!
, are both URMcomputable. In fact c
1
and are both primitive recursive.
Claim 3. f is a partial recursive function
If for any
⇀
x , N
k
, f(
⇀
x ) ∈ N then P converges after some t
0
steps. where t
0
= µt[(
⇀
x , t) = 0]
and R
1
contains the value f(
⇀
x ) . Hence f(
⇀
x ) = c
1
(
⇀
x , t
0
) = c
1
(
⇀
x , µt[j(
⇀
x , t) = 0]) 2
Corollary 4.4 A function is URMcomputable if and only if it is partial recursive. That is,
PARTREC ⊆ URM .
48 CHAPTER 4. THE PARTIAL RECURSIVE FUNCTIONS
Chapter 5
Coding and G¨odelization
5.1 Introduction
We have discussed the notion of
5.2 Numbering and Coding
Deﬁnition 5.1 A set A is denumerable (or countably inﬁnite) if there exists a bijection
f : A → N.
Deﬁnition 5.2 An enumeration with possible repetitions of a set A is a surjective func
tion g : N → A, and if g is injective too (i.e. g is a bijection) then g is an enumeration
without repetitions. Clearly g
−1
shows that the set is denumerable.
Deﬁnition 5.3 A set A is eﬀectively denumerable if there is a bijection f : X
1−1
−−→
onto
N such
that both f and f
−1
are eﬀectively computable functions.
Theorem 5.1 The following sets are eﬀectively denumerable
1. N N.
2. N
k
for all k > 2.
3. N
∗
.
49
50 CHAPTER 5. CODING AND G
¨
ODELIZATION
Proof:
1. pair : N N → N with pair(m, n) 2
m
(2n + 1) −1) . pair is primitive recursive and
hence eﬀective. The inverse functions fst2, snd2 : N → N which satisfy the equations
pair(fst2(z), snd2(z)) = z (5.1)
fst2(pair(x, y)) = x (5.2)
snd2(pair(x, y)) = y (5.3)
are deﬁned as follows. fst2(z) for any natural z is the exponent of the largest power
of 2 that divides z + 1, which may be equivalently expressed as 1 less than the smallest
power of 2 that does not divide z + 1. Hence fst2(z) = µx < (z + 2)[2
x
∤ (z + 1)] − 1
which is clearly primitive recursive. snd2(z) is simply the largest odd divisor of z + 1.
Equivalently, snd2(z) = tquot(fst2(z), z + 1) which again is primitive recursive.
2. We prove this only for k = 3. triple(x, y, z) = pair(x, pair(y, z)) and its inverses
fst3(u) = fst2(u), snd3(u) = fst2(snd2(u)) and thd3(u) = snd2(snd2(u)). It is clear
that all these functions are primitive recursive and they satisfy the following deﬁning
equations.
triple(fst3(u), snd3(u), thd3(u)) = u (5.4)
fst3(triple(x, y, z)) = x (5.5)
snd3(triple(x, y, z)) = y (5.6)
thd3(triple(x, y, z)) = z (5.7)
3. Consider the function seq : N
∗
→ N, deﬁned as
seq([a
1
, . . . , a
k
]) 2
a
1
+ 2
a
1
+a
2
+1
+ + 2
a
1
+a
2
+a
k
+(k−1)
= 2
a
1
(1 + 2
a
2
+1
(1 + 2
a
3
+1
(... + 2
a
k
+1
)...)))
For the empty sequence ε, we have seq(ε) = 0, whereas for all other sequences s ∈ N,
seq(s) > 0. For instance, the sequence seq([0]) = 1, seq([1]) = 2, and seq([0, 0]) =
2
0
(1 + 2
(0+1)
) = 3. We deﬁne the function hd(z) as the largest power of 2 that divides
z i.e. hd(z) = µx < (z + 1)[2
x
∤ (z + 1)] − 1 and tl(z) = tquot(2, tquot(hd(z), z) − 1) to
ensure that if z = seq([a
1
, a
2
, . . . , a
k
]) then tl(z) = seq([a
2
, . . . , a
k
]). We also deﬁne the
function cons(a, z) = 2
a
(2z +1). It is then clear that the functions seq, hd, and tl satisfy
the following equations.
seq(s) = 0 iﬀ s = ε (5.8)
and whenever s = [a
1
, . . . , a
k
] for k > 0, we have
hd(cons(a, z)) = a (5.9)
tl(cons(a, z)) = z (5.10)
seq([a
1
, . . . , a
k
]) = cons(a
1
, seq([a
2
, . . . , a
k
])) (5.11)
2
5.3. G
¨
ODEL NUMBERS OF URM INSTRUCTIONS 51
5.3 G¨odel Numbers of URM Instructions
Theorem 5.2 The set of instructions of the URM is eﬀectively denumerable.
Proof:
We use the opcodes of the instructions to code them up modulo 4. Consider the function β
such that
β(Z(n)) = 4(n −1) + 0
β(S(n)) = 4(n −1) + 1
β(C(m, n)) = 4.pair(m−1, n −1) + 2
β(J(m, n, p)) = 4.triple(m−1, n −1, p −1) + 3
Hence every instruction I has a unique code given by β(I). Conversely, for any x ∈ N, it
is possible to decode the instruction I primitive recursively by ﬁrst determining the opcode
(x mod 4) and then depending upon the opcode it is possible to determine the parameters.
These operations are all primitive recursive. 2
5.4 G¨odel Numbering of Programs
Theorem 5.3 P=collection of all URM programs is eﬀectively denumerable.
Proof: Any program P = I
1
, ..., I
k
has a G¨odel number given by seq[β(I
1
), . . . , β(I
k
)] , where
all the functions used are bijective and primitive recursive, includeing [P[ = k which can be
determined as follows.
Let i = µx[2
x+1
∤ P + 1] then
i = a
1
+ a
2
+ ...a
k
+ k.
Compute each of the indices and then eﬀectively compute k. 2
Notation. Let PARTREC be partitioned by arity
PARTREC =
¸
n>0
PARTREC
(n)
where each f
(n)
∈ PARTREC
(n)
: N
n
−→N.
We use the superscript
(n)
denote arity.
Since γ is obtained only through the composition of bijective functions(which have inverses)
we have γ
−1
also exists and is primitive recursive
52 CHAPTER 5. CODING AND G
¨
ODELIZATION
Theorem 5.4 The set PARTREC
(n)1
Proof: Consider the enumeration
Q
(n)
0
, Q
(n)
1
, Q
(n)
2
, ....
with repetitions. We now construct an enumeration without repetitions as follows.
f(0) = 0
f(m+ 1) = µz[Q
(n)
z
= Q
(n)
f(0)
∧
Q
(n)
z
= Q
(n)
f(1)
∧
.
.
.
Q
(n)
z
= Q
(n)
f(m)
]
which clearly exists as a function and provides an enumeration since
f(m+ 1) is a function(diﬀerent from each of f(0), ...f(m))
2
1
PARTREC
(n)
is clearly inﬁnite since PRIMREC
(n)
⊆ PARTREC
(n)
is inﬁnite
Chapter 6
The Hierarchy of Primitive Recursive
Functions
6.1 Introduction
So far we have seen that the URM has the power of partial recursive functions. We have already
seen that the primitive recursive functions are total. In many cases such as subtraction and
division we have made them total by adopting conventions which at best may be considered
unconventional. We leave it to the reader as an exercise to deﬁne partial recursive versions
of functions like subtraction and division which conform to normal mathematical convention
(e.g. division by 0 should be undeﬁned, subtraction of a larger number from a smaller number
should be undeﬁned etc.).
This might give the reader the feeling that the diﬀerence between the primitive recursive func
tions and the URM might only be in the question of being able to program undeﬁnedness by
nonterminating programs.
Two questions naturally arise from the material presented so far.
1. Does unbounded minimalization yield genuine computational power that goes beyond
primitive recursion. Put diﬀerently,
Are there partial recursive functions that are total but not primitive recursive?
If so, then unbounded minimalization does yield genuine computational power.
2. If the answer to the above question is negative, then we might ask whether it is possible to
get rid of undeﬁnedness completely by eliminating nontermination from URM programs.
In other words,
Is there a machine that exactly characterises the primitive recursive functions?
53
54 CHAPTER 6. THE HIERARCHY OF PRIMITIVE RECURSIVE FUNCTIONS
The answer to this question has a direct bearing on the relative power of machines and
it might enable us to construct and program machines which yield only total functions.
In the following sections we answer both these questions.
6.2 URM–: A Restricted Machine for Primitive Recur
sion
While we have shown that primitive recursion is URMcomputable, we have not explored the
possibility of restricting the instruction set of the URM so as to characterize the primitive
recursive functions.
One of the instructions of the URM machine which makes it powerful in many ways including
that of leading to nontermination is the jump instruction J(m, n, p). In fact, in the 1970s,
it was recognized that such arbitrary transfers of control in any programming language led
to serious diﬃculty in “debugging” faulty programs, made all programs (except the trivial
ones) completely incomprehensible even to the authors of the programs and more importantly
made reasoning about the behaviours of programs an almost impossible task. In fact, short of
actually manually executing the programs it was impossible to make any except the most trite
statements about what such programs do.
In this section we introduce a more structured construct for URM programs that directly reﬂects
the the nature of primitive recursion. Let the new machine be called URM–. The instruction
set of this machine is summarised in the table below.
opcode instruction semantics Verbal description
0 Z(n) R
n
:= 0 Clear register R
n
1 S(n) R
n
:=!R
n
+ 1 Increment the contents of register R
n
2 C(m, n) R
n
:=!R
m
Copy the contents of register R
m
into R
n
3 L(m) Execute !R
m
times the following instructions upto
the matching E.
4 E End of the code to be repeated
The two instructions L(m) and E (which stand for “Loop” and “End”) satisfy the following
conditions
1. Each occurrence of the L(. . .) instruction in a program is followed by a matching occur
rence of E.
2. The sequence of instructions between L(m) and E (called the loop body) is executed
!R
m
times. The sequence is entirely skipped if R
m
= 0.
6.2. URM–: A RESTRICTED MACHINE FOR PRIMITIVE RECURSION 55
3. The two instructions L(m) and E along with the loop body form the loop, R
m
the loop
counter and the contents of R
m
is the loop bound.
4. There can be no instruction in the loop body which modifes the loop bound.
5. Loops may be nested one within the other i.e. the loop body of one loop may itself contain
a loop. But in the case of nested loops, all the loop counters must be distinct.
6. For any two loops, either the two loops are entirely disjoint or one is entirely contained
in the other.
Notes.
1. Notice that condition 1. clearly prohibits the E instruction preceding any L(. . .) instruc
tion.
2. The reader is encouraged to ponder over why we have put in the condition 4. On the
other hand,
3. condition 6. is redundant if we follow the convention that each E instruction matches the
closest L(. . .) instruction that precedes it.
4. Unlike the case of the URM, instruction numbers are needed only for the purpose of
maintaing the program counter in the execution of the machine. Since there are no jump
instructions, instruction numbers are unnecessary for the purpose of understanding and
reasoning about the program.
Deﬁnition 6.1 The class of loopfree URM– programs is LOOP
0
. LOOP
1
is the class of
programs containing LOOP
0
and all programs with loops such that there are no loops in any of
the loop bodies i.e. LOOP
1
is the class of URM– programs with loops nested at most 1 deep.
For any n > 0, the class LOOP
n
consists of LOOP
n−1
and all those programs which contain
loops nested at most ndeep. LOOP =
¸
n≥0
LOOP
n
is the class of all URM– programs.
Theorem 6.1 Every primitive recursive function can be implemented as a URM– program.
Proof: It is clear that the initial functions are all in LOOP
0
. Hence it suﬃces to show that
generalized composition and primitive recursion may be programmed in URM–. The case of
generalized composition also follows the proof given for the URM. That leaves only primitive
recursion. Assume h = [f pr g]. Assuming that F and G are respectively programs that
implement f and g respectively, we proceed almost exactly as we did in the URM machine
except that the two jump instructions are replaced by L(t + 2) and E respectively. 2
56 CHAPTER 6. THE HIERARCHY OF PRIMITIVE RECURSIVE FUNCTIONS
Theorem 6.2 Every program of URM– implements a primitive recursive function.
Proof outline: First of all notice that each of the following claims is easy to prove and taken
together they prove the theorem.
Claim 1. Every URM– program terminates.
Claim 2. If P and Q are URM– programs that implement primitive recursive functions, their
join PQ also implements a primitive recursive function.
Claim 3. If F implements a primitive recursive function f and R
m
is a register whose contents
are not modiﬁed by F, then L(m), F, E is a program that implements f
r
where !R
m
= r, i.e.
the loop construct implements the rfold application of the body of the loop. 2
So we have shown that the primitive recursive functions are exactly characterised by the class
of functions that may be implemented in the URM–.
In the next section we show that not all total computable functions are primitive recursive.
6.3 A NonPrimitive Recursive Total Partial Recursive
function
An example of a function that is partial recursive and total is the Ackermann function which
is deﬁned as follows.
Ack(0, y) = y + 1
Ack(x + 1, 0) = Ack(x, 1)
Ack(x + 1, y + 1) = Ack(x, Ack(x + 1, y))
6.3.1 A Variant of the Ackermann function
We consider a variation of the Ackermann function (in the sense that recursion is of the same
kind, though the individual cases are diﬀerent).
A(x, 0) = 1 (6.1)
A(0, y) =
y + 1 if y ≤ 1
y + 2 if y > 1
(6.2)
A(x + 1, y + 1) = A(x, A(x + 1, y)) (6.3)
It is easy to show that the above equations do deﬁne a total function and that is partial
recursive.
6.3. A NONPRIMITIVE RECURSIVE TOTAL PARTIAL RECURSIVE FUNCTION 57
Lemma 6.3 The equations 6.16.3 deﬁne a unique total function.
Proof outline: Deﬁne a ﬁnite relation S ⊆ NNN to be suitable if it satisﬁes the following
conditions.
1. (x, 0, z) ∈ S implies z = 1,
2. (0, y, z) ∈ S implies z = y + 1 if y ≤ 1 and z = y + 2 otherwise.
3. (x, y, z) ∈ S for x > 0 and y > 0 implies there exists u such that (x, y − 1, u) ∈ S and
(x −1, u, z) ∈ S.
For each (x, y) let S
(x,y)
denote the smallest suitable set such that there exists a triple of the
form (x, y, z) ∈ S
(x,y)
,
Claim 1. For each (x, y), S
(x,y)
is nonempty and contains a unique triple (x, y, z) ∈ S
(x,y)
.
⊢ Consider the lexicographic ordering <
lex
on ordered pairs (x, y). It is clear from the deﬁnition
of suitable sets that for each ordered pair of the form (x, 0), S
(x,0)
= ¦(x, 0, 1)¦ and for each
ordered pair of the form (0, y), S
(0,y)
= ¦(0, y, z) [ z = y + 1 if y ≤ 1, z = y + 2 otherwise¦.
Consider any ordered pair (x, y) with x > 0 and y > 0. Assume that for each (x
′
, y
′
) <
lex
(x, y)
there exists S
(x
′
,y
′
)
= ∅ and such that there is a unique triple (x
′
, y
′
, z
′
) ∈ S
(x
′
,y
′
)
. Then
S
(x,y)
= S
(x,y−1)
∪ S
(x−1,u)
∪ ¦(x, y, z)¦ where u = S
(x,y−1)
(x, y − 1) and z = S
(x−1,u)
(x − 1, u).
Clearly then S
(x,y)
(x, y) = z uniquely deﬁnes S
(x,y)
as the smallest suitable set containing a
unique triple (x, y, z). ⊣
2
Lemma 6.4 A is a partial recursive function.
Proof: Consider the triples (x, y, z) ∈ A. We may code the triples using some coding mechanism
such as triple1(x, y, z) = pair1(x, pair1(y, z)), where pair1(x, y) = 2
x
(2y + 1).
Claim 1.
1. triple1 is a primitive recursive function.
2. triple1 is a bijective function from N
3
to N.
3. The decoding functions fst, snd, thd which yield respectively, the ﬁrst, second and third
components of a triple are also primitive recursive.
4. For any a, b, c, d ∈ N, the following holds
triple1(a, b, c) = d iﬀ a = fst(d), b = snd(d) and c = thd(d)
58 CHAPTER 6. THE HIERARCHY OF PRIMITIVE RECURSIVE FUNCTIONS
We may also code ﬁnite sets of numbers T = ¦a
1
, . . . , a
m
¦ by the function
fs(T) =
¸
a
i
∈T
p
a
i
+1
where p
k
denotes the kth prime number (with p
1
= 2, p
2
= 3, p
3
= 5 etc.)
for any positive integer k.
Claim 2. fs is a primitive recursive function
⊢ Since multiplication and determining the kth prime are both primitive recursive (the kth
prime can be found by bounded minimalization, since p
k
< 2
2
k
which may be proven from
Euclid’s proof
1
), it follows that fs is also primitive recursive. ⊣
Claim 3. Given any positive integer, the predicate isfs : N → ¦0, 1¦ which determines whether
a given number is the code of a ﬁnite set, is primitive recursive.
⊢ Just check that the number is squarefree. ⊣
Claim 4. Any ﬁnite set T = ¦(a
i
, b
i
, c
i
) [ 1 ≤ i ≤ n¦ of triples of numbers may be encoded as
fs(¦triple1(a
i
, b
i
, c
i
) [ 1 ≤ i ≤ n¦).
Claim 5. For any (x, y, z) ∈ N
3
and a ﬁnite set T ⊆ N we have
(x, y, z) ∈ T iﬀ divisorof(p
triple1(x,y,z)
, fs(T)) .
Claim 6. For any v ∈ N, the predicate isSuitable(v) (which determines whether v is the code
of a suitable set) is primitive recursive.
⊢ We outline a method of checking that is intuitively primitive recursive, because every search
is bounded by the number v. For each prime divisor of v, obtain the triple and check for
membership of the “earlier” triples that may be needed to compute it. Given any triple (x, y, z)
in the set, if x = 0 then it is only necessary to verify that z = y + 1 or z = y + 2 according as
whether y ≤ 1 or y > 1. Similarly, if y = 0, then it is only necessary to verify that z = 1. If on
the other hand both x > 0 and y > 0 then it is clearly necessary to check for the presence of
“earlier” triples. An earlier triple in this case is one of the form (x, y −1, u) where u is unknown
and needs to be determined. But having determined u (since u is unique!), it is only necessary
to verify that the triple (x−1, u, z) belongs to the set (which merely involves checking whether
p
triple1(x−1,u,z)
is a divisor of v. However, if y > 1 then this process needs to be pursued with
(x, y−1, u). Similarly if x > 1, then a similar process needs to be pursued with (x−1, u, z). But
1
By Euclid’s proof of the inﬁnitude of primes, it follows that p
k
≤ 1 +
k−1
¸
i=1
p
i
. Using this very fact and
starting from 2 < 2
2
1
we may prove by induction that p
i
< 2
2
i
for each i < k and then conclude that
p
k
< 1 +
k−1
¸
i=1
2
2
i
= 1 + 2
2
1
+···+2
k−1
≤ 2
2
k
.
6.3. A NONPRIMITIVE RECURSIVE TOTAL PARTIAL RECURSIVE FUNCTION 59
each of these processes is bounded by the value v and the checking involves merely decoding
and checking for prime divisors. Hence these processes are all bounded and intuitively primitive
recursive. ⊣
Claim 7. The predicate R(x, y, v) deﬁned as isSuitable(v) ∧∃z < v[(x, y, z) ∈ S
v
] is primitive
recursive.
Claim 8. A(x, y) = µz[(x, y, z) ∈ S
f(x,y)
] where f(x, y) = µv[R(x, y, v)].
⊢ Firstly of all the suitable sets that contain a triple (x, y, z), S
(x,y)
is the smallest and is con
tained in every other suitable set which contains the triple. This follows from the construction
of the smallest suitable sets required for each pair (x, y). Further our coding mechanisms for
sets ensures that S ⊂ T implies fs(S) < fs(T) and fs(S)[fs(T). Hence f(x, y) yields the code
of the set S
(x,y)
in which there is a unique triple (x, y, z) which satisﬁes the equations 6.3. ⊣
2
We have shown that A(x, y) is total and partial recursive. In order to prove that it is not
primitive recursive it does not suﬃce to simply show that it is partial recursive. Many primitive
recursive functions may be shown to be partial recursive. For example in each case of bounded
minimalization, if the bound is removed we get an equivalent function that “looks” partial
recursive, even though it is not. Hence our question of whether there are total partial recursive
functions that are not primitive recursive has to be answered in some more convincing manner
by showing that the function cannot exist in the class PRIMREC under any circumstances or
by showing that the operations that yield primitive recursive functions are inadequate in some
convincing way to be used to deﬁne the function A.
6.3.2 The Growth of functions
We ﬁrst deﬁne a family F of (interrelated) functions and then show that the function A may
be expressed in terms of this family. The growth properties of A are related to the growth
properties of this family of functions and eventually we will show that it is impossible for any
primitive recursive function to match the growth of the function A.
Deﬁnition 6.2 Let F = ¦f
x
[ x ∈ N, f
x
: N → N¦ be a family of functions deﬁned by the
equations
f
0
(y) =
y + 1 if y ≤ 1
y + 2 if y > 1
f
x+1
(y) = f
y
x
(1)
Lemma 6.5 A(x, y) = f
x
(y)
60 CHAPTER 6. THE HIERARCHY OF PRIMITIVE RECURSIVE FUNCTIONS
Proof outline: By double induction on x and y. 2
Since we are primarily interested in asymptotic growth of functions we deﬁne the notion of
functions being “nearly” equal, a concept that suﬃces for our purposes.
Deﬁnition 6.3 Let f, g : N → N be total unary functions. g majorizes f denoted by f ≺ g
or g ≻ f, if f(x) < g(x) almost everywhere, i.e. there exists x
0
such that for all x > x
0
,
f(x) < g(x). f asymptotically approximates g, denoted f ≍ g, if f(x) = g(x) almost
everywhere. Given a class of functions F, f ∈
≍
F if there exists a function g ∈ F such that
f ≍ g.
Theorem 6.6 The following claims on the properties of f
x
hold.
Proof outline:
Claim 1. The ﬁrst few functions in F are as follows.
1. f
1
(y) = 2y for all y > 0.
2. f
2
(y) = 2
y
for all y > 0.
3. f
3
(y) = 2
2
.
.
.
2
ytimes for all y > 0.
Claim 2. For all n > 0, f
n
∈
≍
LOOP
n
, where LOOP
n
is the class of URM– programs with
depth of nesting at most n.
⊢ By induction on n. Starting with n = 1 we have f
1
(y) ≍ 2y which is in turn implemented
by the following sequence of instructions C(1, 3), C(1, 2), L(2), S(3), E, C(3, 1). Assume for some
k ≥ 1, f
k
∈
≍
LOOP
k
. That is there exists program F
k
∈ LOOP
k
such that f
k
≍ φ
F
k
.
Let ρ(F
k
) = m
k
and let F
′
k
= F
k
[l
1
, . . . , l
m
k
→ l
1
], where l
1
, . . . , l
m
k
are chosen so as not
to interfere with any of the parameters or intermediate registers that may be required. We
have f
k+1
(y) = f
y
k
(1). Now consider the program F
k+1
deﬁned by the sequence of instructions
C(1, m
k
+ 1), S(1), L(m
k
+ 1), F
′
k
, E. Clearly since F
k
∈ LOOP
k
, F
k
has a nested loop depth
of at most k, F
k+1
has a depth of at most k + 1. Further since f
k
≍ F
k
, we may show that
f
k+1
≍ F
k+1
. Hence f
k+1
∈
≍
LOOP
k+1
. ⊣
Claim 3. f
x+1
(y + 1) = f
y+1
x
(1) = f
x
(f
y
x
(1)) = f
x
(f
x+1
(y)).
Claim 4. f
0
is a monotonic function i.e. y ≤ z implies f
0
(y) ≤ f
0
(z).
Claim 5. f
k
0
(y) ≥ k
6.3. A NONPRIMITIVE RECURSIVE TOTAL PARTIAL RECURSIVE FUNCTION 61
⊢ By induction on k. f
0
0
(y) = y ≥ 0 and f
k+1
0
(y) = f
0
(f
k
0
(y)) ≥ f
k
0
(y) + 1 ≥ k + 1. ⊣
Claim 6. f
n
(y) > y i.e. f
n
is an increasing function of y.
⊢ By induction on n. For n = 0 it is obvious since f
0
(y) ≥ y + 1 always. Assume f
k
(y) > y
for some k ≥ 0. Then f
k+1
(y) > y is proven by induction on y. For y = 0 we have f
k+1
(0) =
f
0
k
(1) = 1 > 0 = y. Assuming f
k+1
(m) > m i.e f
k+1
(m) ≥ m + 1 for some m ≥ 0 we have
f
k+1
(m+ 1) = f
k
(f
k+1
(m)) > f
k+1
(m) ≥ m + 1. ⊣
Claim 7. f
n
(y + 1) > f
n
(y) for each n.
⊢ It is easily veriﬁed for n = 0. Assuming the result is true for some k ≥ 0, we have f
k+1
(y+1) =
f
k
(f
k+1
(y)) > f
k+1
(y) ⊣
Claim 8. f
n+1
(y) ≥ f
n
(y) for all n and x.
⊢ The proof is not by induction. However, for y = 0 the claim holds, since both sides of the
inequality yield 1. For y > 0 we have for any n, f
n+1
(y+1) = f
n
(f
n+1
(y)). Since f
n+1
(y) > y we
have f
n+1
(y) ≥ y + 1 and further since f
n
(y + 1) > f
n
(y) we have f
n+1
(y + 1) = f
n
(f
n+1
(y)) ≥
f
n
(y + 1). ⊣
Claim 9. f
k+1
n
(y) > f
k
n
(y)
⊢ f
k+1
n
(y) = f
n
(f
k
n
(y)) > f
k
n
(y). ⊣
Claim 10. f
k+1
n
(y) ≥ 2f
k
n
(y)
⊢ By induction on k. For k = 0 it is clear. For k > 0 we have 2f
k+1
n
(y) = 2f
n
(f
k
n
(y)) ≤
f
k+1
n
(f
n
(y)) = f
k+2
n
(y). ⊣
Claim 11. f
k+1
n
(y) ≥ f
k
n
(y) + x
⊢ By induction on k. f
1
n
(y) ≥ 2f
0
n
(y) = 2y = f
0
n
(y) + y. Similarly f
k+1
n
(y) ≥ 2f
k
n
(y) =
f
k
n
(y) + f
k
n
(y) ≥ f
k
n
(y) + y. ⊣
Claim 12. f
k
1
(y) ≥ 2
k
y.
⊢ For k = 0, f
0
1
(y) = y ≥ 2
0
.y and for k + 1 we have f
k+1
1
(y) = f
1
(f
k
1
(y)) = 2f
k
1
(y) ≥ 2.2
k
x =
2
k+1
x. ⊣
2
62 CHAPTER 6. THE HIERARCHY OF PRIMITIVE RECURSIVE FUNCTIONS
Theorem 6.7 For all n, k, f
n+1
≻ f
k
n
.
Proof outline: By double induction on n, k. For n = 0, we have f
k
0
(y) = y + 2k, for all y ≥ 2
and f
1
(y) = 2y. Clearly for all y > 2k, we have 2y > y + 2k. Hence f
1
≻ f
k
0
. Assume that for
some n > 0 and all k, f
n
≻ f
n−1
. For k = 0, we know f
n+1
(y) > y = f
0
n
(y) for all y. Hence
f
n+1
≻ f
0
n
. Assume 2
Corollary 6.8 For any constant c and all n, k, f
n+1
≻ c.f
k
n
.
Since all URM– programs are terminating, we deﬁne a concept of running time of programs.
Deﬁnition 6.4 For any program URM– program P, its running time on any input
⇀
x is
deﬁned as the total number of executions of atomic instructions
2
in P.
We would like to observe that the running time of any program P may be easily calculated by
a URM– program T
P
by the following procedure.
• Choose a register R
m
with m > max(k, ρ(P)), where k si the length of the input.
• To every atomic instruction, add a new instruction S(m).
• At the end of the program append a new instruction C(m, 1)
Clearly the program T
P
for any input
⇀
x computes the running time of P. Also T
P
has the
same depth of nesting as P. We then have the following important theorem.
Theorem 6.9 (The Bounding theorem) For all n ≥ 0 and P ∈ LOOP
n
, there exists k ≥ 0
such that T
P
(
⇀
x ) ≤ f
k
n
(max(
⇀
x )) for every
⇀
x .
Proof: By induction on n. For n = 0, there are no loops in P and hence P consists of only
a constant number c of atomic instructions. Hence for any input
⇀
x , we have φ
T
P
(
⇀
x ) ≤ c ≤
f
c
0
(max(
⇀
x )).
Assume for some n > 0, for each Q ∈ LOOP
n−1
there exists a constant k
n−1
such that for all
⇀
x , T
Q
(
⇀
x ) ≤ f
k
n−1
n−1
(max(
⇀
x )). Suppose P ∈ LOOP
n
and let max(
⇀
x ) = u. We then have the
following cases.
2
We could equally well have deﬁned the running time as the number of changes in conﬁguration, but as we
shall see it is easier to compute running time in terms of the atomic statements executed. Moreover our theory
of asymptotic growth of functions does not get seriously aﬀected by either deﬁnition.
6.3. A NONPRIMITIVE RECURSIVE TOTAL PARTIAL RECURSIVE FUNCTION 63
Case P ∈ LOOP
n−1
. Then by the induction hypothesis and the previous theorem we have
φ
T
P
(
⇀
x ) ≤ f
k
n−1
n−1
(u) ≤ f
k
n−1
n
(u).
Case P ∈ LOOP
n−1
. We proceed by induction on the structure of P. Since n > 0 there exists
at least one looping construct in P which is of the form L(m), R, E, where R ∈ LOOP
n−1
and
hence φ
T
R
(
⇀
x ) ≤ f
k
R
n−1
(u) for some constant k
R
. For simplicity assume P is made up by joining
the programs Q, L(m), R, E and S, where Q and S are in LOOP
n−1
. Assume !R
m
= v and
since Q and S are in LOOP
n−1
, by the induction hypothesis, there exist constants k
Q
and k
S
such that φ
T
Q
(
⇀
x ) ≤ f
k
Q
n−1
(u). Further
Claim 1. The value in any register after Q has been executed is bounded above by u+f
k
Q
n−1
(u).
⊢ Since each atomic statement increases the maximum of the values contained in all registers
by at most 1, it follows after the execution of Q whose running time is bounded by f
k
Q
n−1
(u), no
register can possibly contain a value greater than the sum of its initial value and the running
time of Q. ⊣
We may argue similarly with the rest of the code in P to conclude that every register has a
value bounded above. This gives us the result that
φ
T
P
(
⇀
x ) ≤ u + f
k
Q
n−1
(u) + v.f
k
R
n−1
(u) + f
k
S
n−1
(u)
≤ f
k
Q
+1
n−1
(u) + v.f
k
R
n−1
(u) + f
k
S
n−1
(u)
≤ u + (v + 2).f
k
n−1
n−1
(u)
≺ f
kn
n
(u)
where k
n−1
> max(k
Q
+ 1, k
R
, k
S
). 2
Hence the value in register R
1
in any URM– program can be a priori bound by the sum of
the initial value in the register and the running time of the program. This implies that values
produced by primitive recursive functions cannot grow faster than the bounds imposed on them
by the bounding theorem. However the function A(x, y) grows faster than f
k
n
(1) for any ﬁxed
n and k. While each of the function f
n
is primitive recursive, since f
n
∈ LOOP
n
, the function
A outstrips them all and hence is not primitive recursive.
64 CHAPTER 6. THE HIERARCHY OF PRIMITIVE RECURSIVE FUNCTIONS
Chapter 7
Universality and Parametrisation
Notation
1. P
a
denotes the URM program with g¨odel number a.
2. For any a ∈ N and n ≥ 1
φ
(n)
a
= the nary function computed by P
a
.
= f
(n)
Pa
D
(n)
a
= the domain of φ
(a)
a
.
R
(n)
a
= the range of φ
(n)
a
.
3. The above are abbreviated to
φ
a
, D
a
, R
a
respectively when n = 1.
4. Since every computable function has an inﬁnite number of programs that implement it,
the enumeration
Q
0
, Q
1
, Q
2
,...
is an enumeration of unary computable functions with repetitions.
Theorem 7.1 There is a total unary function that is not computable.
Proof: Assume Q
(1)
0
, Q
(1)
1
, Q
(1)
2
,... is an enumeration of
PARTREC
(1)
: Consider the total function f : N → N.
f(n) =
Q
(1)
n
(n) + 1 if Q
(1)
n
(n) ↓ .
0 otherwise.
65
66 CHAPTER 7. UNIVERSALITY AND PARAMETRISATION
Claim 1. f(n) is the diﬀerent from every function in the enumeration of computable functions.
Claim 2. f(n) is total. Hence f(n) is not computable 2
The following is the picture of computable functions that we have.
PARTREC
(1)
PRIMREC
(1)
f : N−→N
f : N → N
7.1 The Parametrisation theorem (Simpliﬁed form)
Assume f : NN−→N is computable (∈ PARTREC
(2)
) for each ﬁxed value a ∈ N. We may
deﬁne a unary function g
a
: N−→N such that
∀y ∈ N : g
a
(y) = f(a, y) i.e g
a
≃ λy[f(a, y)]
Then clearly since f is computable g
a
is also computable and in fact there is a program P
a
for
each a ∈ N which computes f(a, y) for any given a
Theorem 7.2 Let f : NN−→N be computable. Then there exists a total computable function
h : N → N such that f(x, y) ≃ Q
(1)
h(x)
(y) .
Proof: We need to construct a program Q
a
for each a which computes
f(a, y) for each y. let F computes f.
2
7.1. THE PARAMETRISATION THEOREM (SIMPLIFIED FORM) 67
C(1, 2)
Z(1)
S(1)
S(1)
.
.
.
.
.
.
F
y y
R
1
R
1
R
2
a 0
Initial state of Qa
Initial state of F
Where F computes f.
eﬀectively computable, k is
eﬀectively computable. Hence
Q
k
(a)
(y) = f(a, y)
a  times
Qa diﬀers from
Q
a
′ only in
this part
For a = a, ,
Let k(a) = Qa = γ(Qa)
Since F is ﬁxed and is
0
. . . . . .
Qa :
Examples
1. Let f(x, y) = y
x
. By the s−m−n theorem there is a total computable function h : N → N
such that for any ﬁxed n ∈ N, h(n) is the Godel number of the program that computes
y
n
.
2. Let f(x, y) =
y if x/y.
⊥ otherwise.
Then f is computable since
f(x, y) = x.
µz[x.z = y]
x = 0, y = 0 ⇒ f(x, y) = 0 = y
x = 0, y = 0 ⇒ f(x, y) = ⊥
x = 0, y = 0 ⇒ f(x, y) = 0 = y
x = 0, y = 0 ⇒ f(x, y) =
y ← x/y
⊥ ← x ∤ y
Then there is a total computable function h : N → N. such that for each ﬁxed n.
Q
h(n)
(y) is deﬁned iﬀ n/y iﬀ y is in the range of Q
h(n)
therefore Dom
(Q
h(n)
(y)
= ¦ni[i ∈ N¦ = nN = Range
Q
h(n)
(y)
The generalized S
mn
theorem
For each m, n ≥ 1 , there is total computable (m + 1)ary function s
m
n
(e,
⇀
x ) such that
68 CHAPTER 7. UNIVERSALITY AND PARAMETRISATION
Q
(m+n)
e
(
⇀
x ,
⇀
y
) = Q
s
m
n
(e,
⇀
x )
(
⇀
y
) for all
⇀
x ,
⇀
y
.
Proof: Let Q(i, x) be the subroutine 2
.
R1
0
to be transformed to
y1
Rn
R1
R1
Rm Rm+1 Rm+n
yn 0 x1 xm y1
yn
Z(i)
S(i)
S(i)
xtimes
for given values of
recursive
function
Given
i and x this is
a primitive
.
.
.
.
. . .
. . .
. . .
. . . . . .
we use the following code
C(n, m + n)
C(2, m + 2)
C(1, m + 1)
Q(1, x1)
Pe
.
.
.
.
.
.
C(m, xm)
eﬀectively computable.
From this deﬁnition and the
recursive
no jumps, it is primitive
Since this code contains
it follows that s
m
n
(e,
⇀
x ) is
eﬀectiveness of and
−1
7.2 Universal functions and Programs
Deﬁnition 7.1 The universal function for nary computable functions is the (n+1)ary func
tion
ψ
(n)
u
(e, x
1
, ..., x
n
) ≃ Q
(n)
e
(x
1
, ..., x
n
)
Question. Is ψ
(n)
u
a computable functions ?
Theorem 7.3 For each n ≥ 1, the universal function ψ
(n)
u
is computable.
7.2. UNIVERSAL FUNCTIONS AND PROGRAMS 69
Proof outline: Assume a ﬁxed n > 0, given a number e, decode the program P
e
and mimic the
computation of P
e
step by step by writing down the conﬁguration of the registers and the next
instruction to be executed. If and when this computation stops, the required value of Q
(n)
e
(
⇀
x )
will be in R
1
.
Conﬁguration: The registers are coded by
c =
¸
i≤1
pi
ri
where !R
i
= r
i
and p
i
is the i − th prime number. The current state of any computation is
given by
σ = π(c, j) with c = π
−1
1
(ρ) j = π
−1
2
(ρ).
where j is the serial number of the next instruction to be executed .
Convention. j = 0 if the computation is to be stopped.
1 n n + 1 n + 2 n + 3 n + 4 n + 5 n + 6 n + 7 n + 8 n + 12 n + 9 . .
e 1 2 3 0
1
Serial number
be executed
of next instr to
conﬁguration of Pe.
current
c◦
length
of Pe + 1
required to check
whether execution
of Pe has to halt.
opcode
opcode + arguments
of the instruction to
be executed
remember to
set redundant
argument to 0.
After decoding the arguments
J(n + 9, n + 7, )
J(n + 9, n + 6, )
J(n + 9, n + 5, )
Same target for Z and S instructions
⇀
x
Initially
Y
i≥1
pi
x
i
e = 2
a
1
(1 + 2
a
2+1
(1 + 2
a
3+1
(...(1 + 2
a
r+1
)...))) −1
a
1
= µz
1
≤ e[2
z
1
+1
∤ e] , τ
−1
−1
(e) = (e + 1)/2
a
1
, tl(e) =
τ
−1
−1
(e)
2
−1
70 CHAPTER 7. UNIVERSALITY AND PARAMETRISATION
a
2
= µz
2
≤ e[2
z
2
+1
∤ tl(e)] hd(e) = µz ≤ e [ 2
2+1
∤ e ]
a
3
= µz
3
≤ e[2
z
3
+1
∤ tl
2
(e)] for 1 ≤ i ≤ r
.
.
.
a
i
= µz
i
≤ e[2
z
i
+1
∤ tl
i−1
(e)] ith (e, i) = hd(tl
i−1
(e))
therefore n −th(e, i) =
ψ
(n)
U
(e,
⇀
x ) = execute(e,
⇀
x ) = c
1
(e,
⇀
x , µt[next(e,
⇀
x , t) = 0])
conf(e,
⇀
x , t) = ¦ conﬁguration ofter t step of execution
finalconf(e,
⇀
x ) = conf(e,
⇀
x , µt[next(e,
⇀
x , t) = 0])
Assume given
⇀
x , e in the registers R
1
, ..., R
n+1
set R
n+2
← 1.
R
n+3
← c(
⇀
x ) =
¸
i≥1
pi
x
i
R
n+4
← len(Pe)
S(n + 4)
J(n + 2, n + 4, 0) to the end of the program if P
e
has to halt.
R
n+5
← decode(n + 2)
. .. .
— decode the instruction whose serial number is stored in R
n+2
and the arguments in R
n+7
, R
n+8
, R
n+9
while decoding, put the opcode in R
n+6
,
R
n+3
← execute(n + 5)
β
−1
— gives various opcodes and registers to
2
Lemma 7.4 Let τ : N
+
→ N be the coding on nonempty sequences. such that
τ[a
1
, ..., a
k
] = 2
a
1
(1 + 2
a
2
+1
(1 + 2
a
3
+1
(...(1 + 2
a
k
+1
)...))) −1 = e.
Then the following functions are primitive recursive
(i) hd(e) = a
1
for the k ≥ 1
(ii) tl(e) = τ[a
2
, . . . , a
k
] for k ≥ 2.
7.2. UNIVERSAL FUNCTIONS AND PROGRAMS 71
(iii) len(e) = k. for k ≥ 1
Proof: (i) Consider e = 2
a
1
(1 +2
a
2
+1
(1 +2
a
3
+1
(...(1 +2
a
k
+1
)...))) −1. Clearly e +1 has at least
one nonzero bit in its representation and e + 1 ≥ 1. we have
hd(e) = νz ≤ e + 1[2
z
[(e + 1)] = a
1
(ii) Since all sequences are nonempty consider the coding τ
◦
: N
⋆
→ N deﬁned also for empty
sequences with τ
◦
[ ] = 0 and τ ◦ [a
k
, ..., a
k
] = τ[a
k
, ..., a
k
] + 1.
for all single element sequences [a]
τ[a] = 2
a
−1 τ
◦
[a] = 2
a
hd[a] = a. Hence for any e ≥ 0 if e + 1 is a power of 2, then is a single element sequence
2
ispwr2(x)=
0 ← x = 0
∃ z ≤ x[2
z
= x]
len(e) = µk ≤ (e + 1)[ispwrof 2(tl
k
(e + 1))]
for all e ≥ 0, e + 1 > 0 and has at least one nonzero bit in its representation.
τ[a
1
, ..., a
k
] =
2
a
1
−1 if k = 1
(2τ[a
2
, ..., a
k
] + 1)2
a
1
−1
) if k > 1.
e = (2 e
′
+ 1)2
a
1
−1
therefore
e + 1
2
a
1
= 2e
′
−1
therefore e
′
=
(e+1)
2
a
1
−1
2
=
(e + 1) −2
a
1
2
a
1
+1
=
(e + 1) −2
hd(e)
2
hd(e)+1
len(e)µk ≤ e + 1 [tl
k
(e) = 0]
72 CHAPTER 7. UNIVERSALITY AND PARAMETRISATION
s =
¸
j≥1
where r
j
=!R
j
c = π(s, i)
e r 0 1 2 3 c s i β(Ii) oi reg1 reg2 reg3
arguments
r(Pe)
opcodes
Length of
conﬁguration
current
current
state serial no
of next
instruction
of Pe to be
executed
opcode of Ii
Pe
trm(β(Ii), 4).
=
β(Ii) −trm(β(Ii), 4)
4
⇀
x
n + 1 n + 2
π
−1
1
(c) π
−1
2
(c)
Depending upon 0i ﬁll up
P
e
= [I
1
, ..., I
r
]
e = τ[I
1
, ...I
r
]
= 2
a
1
(1 + 2
a
2+1
(1 + 2
a
3+1
(...(1 + 2
a
r+1
)...))) −1
τ[0] = 2
0
−1 = 0
e = 2
a
1
(1 + 2
a
2+1
(1 + 2
a
3+1
(...(1 + 2
a
r+1
)...)))
−1
hd(e) = a
1
tl(e) = 2
a
2
(1 + 2
a
3+1
(...(1 + 2
a
r+1
)...))) −1
e + 1
2
a
1
= 1 + 2
a
2
(1 + 2
a
3+1
(...(1 + 2
a
r+1
)...))
e + 1
2
a
1
−1 = 2
a
2
(1 + 2
a
3+1
(...(1 + 2
a
r+1
)...))
(
e+1
2
a
1
−1)
2
= 2
a
2
(1 + 2
a
3+1
(...(1 + 2
a
r+1
)...))
7.2. UNIVERSAL FUNCTIONS AND PROGRAMS 73
e + 1
2
a
1
+1
−
1
2
= 2
a
2
(1 + 2
a
3+1
(...(1 + 2
a
r+1
)...))
2(e + 1) −1
2
a
1
+1
= 2
a
2
(1 + 2
a
3+1
(...(1 + 2
a
r+1
)...))
2(e + 1) −1
2
a
1
+1
−1 = tl(e)
Universal Programs : Summary
Assume for any arguments
⇀
x and G¨odel number e, the program P
e
is in some conﬁguration
c = π(s, j) then we may deﬁne the function
move(
⇀
x , e, c) = c
′
which is primitive recursive
where c
′
=
π(s, 0) if i > len(e) or i = 0
π(s
′
, i
′
) if i ≤ len(e)
where i
′
=
i + 1 if opcode (i) < 3
i
′′
if opcode (i) = 3 and π
−1
2
(i) = i
′′
and s
′
=
s
p
r
j
j
if opcode (i) = 0 and ﬁrst (i) = j
sp
j
if opcode (i) = 1 and ﬁrst (i) = j
sp
r
j
k
p
r
k
k
if opcode (i) = 2 and ﬁrst (i) = j
and second (i) = k
s if opcode (i) = 3
where r
j
= νj ≤ s[p
j
j
[s]
74 CHAPTER 7. UNIVERSALITY AND PARAMETRISATION
r
k
= νk ≤ s[p
k
k
[s]
We may the deﬁne the function
Steps (
⇀
x , e, c, 0) = c
steps (
⇀
x , e, c, t + 1) = move(
⇀
x , e, step(
⇀
x , e, c, t))
and ﬁnally we may deﬁne for any conﬁguration c,
state(c) = π
1
−1
(c)
nextinstr(c) = π
−1
2
(c)
output(c) = νk ≤ c[p
k
1
[state(c)]
7.2. UNIVERSAL FUNCTIONS AND PROGRAMS 75
and
execute(
⇀
x , e) = output(c
f
)
where c
f
= steps(
⇀
x , e, c
0
, µt[nextinstr(steps(
⇀
x , e, c
0
, t)) = 0])
. .. .
This function is not prim.rec
it is however partial recursive
since it is an unbounded
minimization of a prim.rec
function
Corollary 7.5 For any URM program P and inputs
⇀
x with [
⇀
x [ = n ≥ 1 , Q
(n)
r(p)
is a partial
recursive function i.e for any n ≥ 1 , URM
(n)
= PARTREC
(N)
Undecidability : The Hallting Program
Theorem 7.6 The predicate “ programs x halts on input y ” deﬁned by halt(x,y)=
1 if Q
x
(y) ↓
0 otherwise.
is undecidable i.e. its characteristic function halt(x,y) is not URMcomputable.(equivalently
partial recursive)
Proof: By contradication. If halt is computable then so is the function f(x) = halt(x, x)
1
. and
there exists a URM program P
f
which computes f. Now consider he program P
′
f
constructed
as follows.let
P
f
′
::
p + 3. J(1, m+ 1, p + 3)
p + 2. S(m+ 1)
p + 1. Z(m+ 1)
P
f
what does P
′
f
computes ? It computes the
function.
m = ρ(P
f
) and P
f
consist of p instructions
f
′
=
0 if f(x) = 0
⊥ if f(x) = 1
1
whether program x halts on input x
76 CHAPTER 7. UNIVERSALITY AND PARAMETRISATION
Let r(P
′
f
) = y. Then f
′
(y) =
0 if f(y) = 0 ⇔ halt(y, y) = 0
⊥ if f(y) = 1 ⇔ halt(y, y) = 1
PROGRAM y HALTS ON INPUT y IFF PROGRAM y DOES NOT
HALT ON INPUT y.
2
Chapter 8
The typefree λcalculus
In the previous chapters we have studied two models of computability both of which were ﬁrmly
grounded in the concept of numbers. This was deliberate – a notion of computability which
does not involve numbers and operations on numbers would somehow be unsatisfactory. How
ever, throughout our school education in mathematics, numbers have always been conceptual
rather than concrete. In the early years of our education in arithmetic we have dealt mainly
with numerals i.e. sequences of symbols which represent numbers. The interpretation of these
(sequences of) symbols as numbers and operations on numbers leads us to believe that we are
computing with numbers. But in reality, the methods we have learned are really methods for
manipulating representations rather than concepts themselves. However we have internalised
them to such a large extent that we seldom make the distinction between numbers and their
representation. The arithmetic we have learnt includes algorithms and methods of computing
which utilise the representation of numbers instead of numbers themselves. In later years (in
secondary school and high school) we gradually progressed to algebra (the use and manipula
tion of unknown or symbolic quantities) and geometry (requiring spatial reasoning invloving
points, lines, planes and measures associated with spatial objects). High school mathematics
subjects like trigonometry, mensuration, coordinate geometry and the calculus combine spatial
reasoning with algebraic reasoning.
Clearly therefore, the question of using and manipulating pure symbols (or pure symbols in con
junction with quantities) is an important aspect of computing and hence needs to be addressed
for its computational power.
In this chapter we study two calculi — the λcalculus and combinatory logic – that are purely
symbolbased and per se free of interpretations. They may be regarded as pure symbol
processing. The notion of a calculus itself recognizes (uninterpreted) symbol manipulation
and processing as its main feature. These calculi are important for several reasons.
1. These calculi form the basis for modern functional programming languages in both design
and implementation and
2. historically these calculi predate other models of computation.
77
78 CHAPTER 8. THE TYPEFREE λCALCULUS
Syntax. x, y ∈ V , where V is a countably inﬁnite collection of variables.
L ::= x Variable
[ λx[L] λabstraction
[ (L L) λapplication
Precedence and Associativity conventions
1. (L
1
L
2
L
3
) denotes ((L
1
L
2
) L
3
) i.e. application is left associative
2. λxy[L] denotes λx[λy[L]]
Free and bound variables
V (x) = ¦x¦
V (λx[L]) = V (L) ∪ ¦x¦
FV (x) = ¦x¦ FV (λx[L]) = FV (L) ¦x¦ V ((LM)) = V (L) ∪ V (M)
FV ((L M)) = FV (L) ∪ FV (M) BV (L) = V (L) −FV (L)
The metaoperation of substitution(to ensure no “capture of freevariables”)
x¦N/x¦ ≡ N
y¦N/x¦ ≡ y
(L M)¦N/x¦ ≡ (L¦N/x¦ M¦N/x¦)
79
(λx[L])¦N/x¦ ≡ λx[L]
(λy[L])¦N/x¦ ≡ λy[L¦N/x¦] y = x
& y ∈ FV (N)
(λy[L])¦N/x¦ ≡ λz[L¦Z/y¦¦N/x¦] y = x
& y ∈ FV (N)
& z ∈ FV (L) ∪ FV (N)
α, β, η conversion
λx[L] −→
α
λy[L¦y/x¦], y ∈ FV (L) RENAMING BOUND VARIABLES
(λx[L] M) −→
β
L¦M/x¦ FUNCTIONAL CALL
REPLACEMENT OF PARAMETERS(FORMAL)
BY ARGUMENTS (ACTUAL)
λx[(L x)] −→
η
L EXTENSIONALITY
Closure of conversions under any context
−→
λ
denotes −→
α
, −→
β
, −→
η
L −→
λ
L
′
λx[L] −→
λ
λx[L
′
]
L −→
λ
L
′
(L M) −→
λ
(L
′
M)
M −→
λ
M
′
(L M) −→
λ
(L M
′
)
Question. Verify that the above rules do not lead to capture of free variables.
−→
⋆
λ
=
¸
n≥0
−→
η
λ
where L −→
◦
λ
M if L ≡ M
L −→
k+1
λ
M if ∃N : L −→
k
λ
N −→
λ
M
80 CHAPTER 8. THE TYPEFREE λCALCULUS
λEquality =
λ
=
λ
is the least relation such that
L =
λ
M if L →
⋆
λ
M
L =
λ
M if M =
λ
L
L =
λ
M if L =
λ
N and N =
λ
M.
Combinatory logic & λcalculus
Schonﬁnkel 1924
Turing 1937 post 1936
Godel 1931 presented in 1934.
Church 1933,1936,1941
Kleene 1935,1936.
Rosser 1935
Assume an inﬁnite collection of variables symbols x, y, z, f, g
1
...
Assume two distinguished
symbols S and K
The language of CL(combinator) is
expressions generated by the grammar
C ::= S [K[ (C C) [x
↑
application is left associative
A combinator(C
0
::= K[S[C
0
C
0
) is
term containing only S and K and no other variables.
The language of λ is generated by the grammer
L ::= x [ λx[L] [ (L L)
Λ
0
is the collection
of closed λterms are combined
Λ ⊇ Λ
0
is the language.
81
S L M N −→
W
((L N)(M N))
KL M −→
W
L
S stand for stong composition
−→
W
stand for week contracion
K stand for constant
(λx[L]M) −→
β
¦M/x¦L
S
df
= λ x y z [((x z)(y z))]
K
df
= λ x y [x]
¦M/x¦x ≡ M
¦M/x¦(L N) ≡ (¦M/x¦ L ¦M/x¦N)
¦M/x¦x ≡ M
¦M/x¦y ≡ y
¦M/x¦λ x [L] ≡ λ x [L]
¦M/x¦λ y[L] ≡ λ y [¦M/x¦L]
¦M/x¦(L M) ≡ (¦M/x¦ L ¦M/x¦M)
82 CHAPTER 8. THE TYPEFREE λCALCULUS
Example. Consider a new combinator B (for composition) BLMN = (L(MN))
Deﬁne B
df
≡ S(KS)K.
B L M N
≡ S(KS) KL M N
−→
W
KS L(KL) M N
−→
W
S(KL) M N
−→
W
KL N(M N)
−→
W
L (M N)
Example. Deﬁne the commutation operator which commutes two arguments
C X Y Z = X Z Y
Deﬁne C = S(B B S)(KK)
Then C X Y Z
≡ S (B B S) (KK)X Y Z
−→
W
B B S X(KKX)Y Z
−→
W
B B S X KY Z
. .. .
1
−→
W
B (S X) KY Z
1
This is not a relex if you parenthesize it complete
Bibliography
[1] Hopcroft J and Ullman J D. Automata, Languages and Computation. AddisonWesley, New
York, 1983.
[2] Davis M. Computability and Unsolvability. Dover Publications Inc., New York, 1982.
[3] Davis M and Weyukar E. Computability, Complexity and Languages. Academic Press, New
York, 1983.
[4] Cutland N. Computability: An Introduction to Recursive Function Theory. CUP, Cam
bridge, Great Britain, 1980.
83
2
Preface
Students of computer science in IIT Delhi usually take a course on Theory of Computation as an elective some time after they have ﬁnished courses on programming, data structures, discrete mathematical structures (whatever that means), computer architecture, programming languages and sometimes operating systems as well. Theory of computation is of course a very broad and deep area, and it is anyone’s guess what really should be taught in such course. For example, Dexter Kozen’s text with the same name suggests that the course should dwell primarily on complexity classes. Most courses on Theory of Computation in India follow the classic text by Hopcroft and Ullman [1] on formal languages and automata which was written at a time when parsing, compiling, code optimization and complexity theory were pursued as frontier areas of research. As a result, the exposure to automata theory and formal languages was considered the most important aspect of the theory, later followed by some exposure to NPcompleteness. Moreover the book was written for graduate students 1 . More recently (apparently on the strength of having course web pages on Programming, Logic, Programming Languages and Complier Design), I have been bombarded by questions from students and outsiders (some of them managers with computer science degrees who are willing to pay thousands of dollars if I agreed to sit in on such a project) regarding the feasibility of designing tools which would take the programs of their (novice?) programmers and transform them automatically into the most eﬃcient program possible or the shortest program possible in some language. I have even been asked why these programs cannot be proved automatically thus saving the company a small fortune in testing time and being able to meet stiﬀ deadlines. Anyway that’s my story and I am sticking to it. It is my feeling that at a time when courses on compilers, formal languages, complexity theory and automatic veriﬁcation are usually electives which students tend to avoid, this has led to a disconnect between a course primarily devoted to formal languages and automata theory and the bouquet of courses that students otherwise need to do in a typical computer science curriculum. Anyway that’s my story and I am sticking to it. It is also my feeling that IIT students (who are numerically quite literate) feel most comfortable when numbers and computations on numbers form the basis for a theory of computation. On the other hand courses on theory of computation which primarily teach automata and formal languages usually completely ignore the connections between programming and computability theory and scant attention is paid to the theory of primitive recursive functions and the design of data structures or programming language features. As a result students who sit through a course on automata and formal languages and who have no intention of pursuing either
It is a mystery to me how it has come to be taught as a textbook for an undergraduate course. I would assume that the same natural processes which brought Euclid, Descartes and Newton down to school mathematics are responsible for it. But nevertheless the transition in the case of formal languages and automata has taken place in less than 15 years while Newton took about 200 years before being prescribed for high school.
1
3 compilers or formal veriﬁcation or complexity theory, emerge from the course feeling that the whole course was useless and unconnected to anything they have learned and anything else they might learn and of no use whatsoever in their professional life in industry. Anyway that’s my story and I am sticking to it. I decided therefore to make computability theory the primary focus of these lecture notes and gradually introduce Turing machines, ﬁnite automata and formal languages. I have used the books of Cutland [4] and Martin Davis ([2], [3]) as my primary sources for these lecture notes. I have tried to introduce the connections between the theory of computability with other courses such as programming, functional programming, data structures, discrete mathematical strucutres and operating systems in as elementary a fashion as possible. It has been a source of wonder to me that this beautiful material seems to be taught mostly only to students of pure or applied mathematics or logic rather than to computer science students. I am sure students of engineering can absorb this material and appreciate it equally well, especially since it requires little more than high school mathematics to understand it (though it might require a more maturity to appreciate it). Anyway that’s my story and I am sticking to it. I have of course borrowed freely from various sources, but in many cases I have made signiﬁcant departures fromt he original material especially as concerns notation. Not to put too ﬁne a point on it, I believe that my notation though strange to look at, is an attempt to clean up (mostly for my own understanding) misleading notation used in various sources.
4
51 o 5 . . . . . . . . . . . . .4 Sets and Operations on Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 G¨del Numbers of URM Instructions . . . . . . . . . . . . .3 3. . . . . . . . . . . . . . . . . Functions and Predicates . . . . . 31 Primitive Recursive Predicates . . . 15 17 2 The RAM Model 2. 29 Primitive Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 3. . . . . . . . . 17 Examples . . . . . . 21 29 3 The Primitive Recursive Functions 3. . . . . . . . . . . . 39 Some Forms of Primitive Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Relations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 3. . . . .3 Introduction .2 1. . . . .2 The Unlimited Register Machine (URM) . . . . . . . . . . 7 7 8 Equality . . . . . . . . . . . . . . . . . . . . . . . 40 45 49 4 The Partial Recursive Functions 5 Coding and G¨delization o 5. . . . . .1 2. . . . . . . . . . . . . . . . . . . . . .Contents 1 Basics: Prerequisites and Notation 1. . . . . . . . . .1 5. . . . .2 5. . . . . . . . . . . .4 Introduction . . . . . . . . . . .3 1. . . . 49 Numbering and Coding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Other Notational Devices . . . . . . . . . . . . . . . . . . .
. . . . . . . . 59 65 7 Universality and Parametrisation 7. . . .2 A Variant of the Ackermann function . . . .1 6. . . . . . . 56 The Growth of functions . . . . . . . . . . .6 5. . . . . . . . . . . . . . . . . . . . . . . .3. . . .2 The Parametrisation theorem (Simpliﬁed form) . . . . . . . . . . . . . . . . 68 77 8 The typefree λcalculus . . 66 Universal functions and Programs . .1 6. . . .1 7. . . . . . . . . . . . . . . . .4 CONTENTS G¨del Numbering of Programs . . . . . . . . 56 6. . . . . . . . . . . . . . . .2 6. . . . . . .3. . . . 54 A NonPrimitive Recursive Total Partial Recursive function . . . . . . . . . . 51 o 53 6 The Hierarchy of Primitive Recursive Functions 6. . . . . . . . . . .3 Introduction . . . . . . . 53 URM–: A Restricted Machine for Primitive Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . .
We will generally use the following notation for sets. or no symbol at all as is usual in mathematics.e. Usually the context will determine which operation is intended.Chapter 1 Basics: Prerequisites and Notation 1. i. Further the usual preﬁx operations for sum ( ) and product ( ) of sets or sequences of numbers will be used.A × · · · × A ntimes The powerset of A The usual notations will be used for arithmetic operations on numbers. N P R Z ∅ ⊆ ⊂ ∪ ∩ ∼ − × An 2A The The The The The The The The The The The The The set of Natural numbers (including 0) set of Positive integers set of Real numbers set of Integers empty set (inﬁx) subset relation between sets (inﬁx) proper subset relation between sets inﬁx union operation on sets inﬁx intersection operation on sets preﬁx complementation operation on sets inﬁx set diﬀerence operation on sets inﬁx cartesian product of sets postﬁx nfold cartesian product of A.1 Sets and Operations on Sets We assume the usual notions and notations of set theory including those of relations. This includes the operation of subtraction (denoted by the inﬁx operator −) which is also the set diﬀerence operation. Similarly we may use the symbol × for both cartesian product and multiplication of numbers. Some operations such as multiplication may be denoted by . 7 ..
• f is called a partial function of type A−→ B. that for each element a ∈ A there is at most one element b ∈ B such that (a. b) ∈ f .2 Relations.1. . BASICS: PREREQUISITES AND NOTATION • A0 will be identiﬁed with the empty set ∅. . An is any subset of A1 × · · · × An . Functions and Predicates Deﬁnition 1. • f is called a total function of type A → B if f is a partial function of type A− B and → every element of A has an image under f . a) ∈ f −1 if and only if (a. • A1 will be identiifed with the set A • A 1tuple (a) will be identiﬁed with a. . • f is said to be deﬁned at a ∈ A if a has an image under f . if f satisﬁes the image uniqueness property viz. . .8 Convention 1. • f is said to be undeﬁned at a if it has no image under f . An A partial function from set A to set B A total function from set A to set B b is the image of a under f f is undeﬁned at a The subset of values for which f is deﬁned The subset of values which are images of elements in Dom(f ) . b) ∈ f .1 CHAPTER 1. 1. . r ⊆ A1 × · · · × An f : A+ B → f :A→B f (a) = b f (a) =⊥ Dom(f ) Ran(f ) Notes. b is called the image of a under f . A nary (for n > 0) relation on sets A1 . . • Then f −1 ⊆ B × A the converse of f is the relation deﬁned by (b.2 Given two sets A and B and a binary relation f ⊆ A × B.1 A nary relation for n > 0 on sets A1 . Deﬁnition 1. .
. . . each such relation may also be thought of as a partial function of type r : A1 × · · · × Ak + Ak+1 × · · · × An → where (a1 . . for each k with 1 ≤ k < n. . a natural number) will be regarded as a total function from the empty set to the set that constant belongs to (e. ak+1 . . . a′ ∈ Dom(f ). . . • f is bijective (or is a bijection) if it is both injective and surjective.1 (1. This is to be regarded as being diﬀerent from a constant function such as f : R → N deﬁned as f (x) = 5 which is a unary total function deﬁned on the reals and which yields the natural number 5 for every real argument. . f (a) = g(a). ak ) = {(ak+1 . . FUNCTIONS AND PREDICATES 9 1.2. . an )  (a1 .1) 3. The notation we use for functions may also be used for relations. a = a′ implies f (a) = f (a′ ). .1 1. ak . . Deﬁnition 1. . .g. .1. . In fact every relation r ⊆ A1 × · · · × An may be thought of as a total function of type r : A1 × · · · × Ak → 2Ak+1 ×···×An .g. ak ) = ∅ in 1. . f (b) = a iﬀ f (a) = b. where 1 ≤ k < n. . ak ) ∈ Dom(r) if and only if r(a1 . with Dom(f −1 ) = Ran(f ) ⊆ B and → −1 −1 for every b ∈ Dom(f ). • If f is injective then f −1 : B− A the inverse of f . Hence for any (a1 . Every total function is also a partial function. g : A+ B are equal if and only if Dom(f ) = Dom(g) → and for each a ∈ Dom(f ). f is also said to be an injection.2) Facts 1. ak ) ∈ A1 × · · · × Ak . . . then r(a1 . Deﬁnition 1. f : A → B implies Dom(f ) = A. When r(a1 . .3 Two partial functions f. an ) ∈ r} (1. . RELATIONS. . f is also said to be a surjection. . . . A constant (e.4 Let f : A+ B be a partial function. 2. . • f is surjective if Ran(f ) = B. . . N). . . 2. ak ) is a singleton set we omit the set braces. → • f is injective if for each a. Further.
The two step transformation may be pictured as follows. . . . We usually abbreviate sequences of values such as a1 . If we were to regard f and g as transducers which take an input from its domain and transform it into an output in its codomain. f −1 (f (a)) = a. gm with f (as shown in the ﬁgure below) is such that . . Notation. We will use either of them. where the length of the sequence is either understood or immaterial. The composition of g and f (denoted [g. f more closely represents the sequential composition of functions in programming. gm are kary functions → of the type g1 . f ] or [f ◦ g]) is the partial function h : A− C such that → • Dom(h) = {a ∈ Dom(g)  g(a) ∈ Dom(f )} and • for each a ∈ Dom(h). Where ⇀k the length of the sequence is important we may write it as a . a ¨ E g(a) ¨ f (g(a)) E g © E f © Figure 1.5 Let g : A−→ B and f : B−→ C be partial functions. . . → 2. a ∈ Dom(g) or a ∈ Dom(g) but g(a) ∈ Dom(f ) implies a ∈ Dom(h) and hence h(a) =⊥. h(a) = [g. ak (which are the arguments ⇀ of a function) by a . Note that composition is strict in the sense that for any a. gm : Ak − B. The notation f ◦ g is preferred by mathematicians generally. .2 CHAPTER 1. BASICS: PREREQUISITES AND NOTATION 1.1: Composition of unary functions Notation. · · · . f ](a) = [f ◦ g](a) = f (g(a)). Deﬁnition 1. Then the kary function h : Ak − C obtained by composing → → the m functions g1 . . Deﬁnition 1. though the notation g.6 Assume f : B m − C is an mary function and g1 . f (f −1 (b)) = b. · · · . If f : A− B is injective then for every a ∈ Dom(f ). If f : A−→ B is bijective then f −1 is total (of type B → A) and for every b ∈ B. then h is a composite transducer which transforms an input from a ∈ A into an output c ∈ C in a two step process by ﬁrst transforming a to b = g(a) and then transforming b to c = f (b) = f (g(a)). We will be interested in a generalised composition as deﬁned below.10 Facts 1.
RELATIONS.1. 1} such that for each a ∈ A1 ×· · ·×An .7 Given an nary relation r ⊆ A1 × · · · × An . a1 ak a1 u u u E ¨ g1 E E b1 © ¨ ak u u u b2 E E ¨ g2 E w w w ¨ © u u u f E c E © a1 ak u u u E gk E © bm Figure 1. gm ( a )) ∈ Dom(f )} and ⇀k ⇀k ⇀k • h( a ) = f (g1 ( a ). gm (which are arguments of the generalised composition operator) may be denoted g . · · · . gm ( a )). FUNCTIONS AND PREDICATES 11 ⇀k ⇀k ⇀k ⇀k • Dom(h) = { a ∈ Ak  (∀i : 1 ≤ i ≤ m : a ∈ Dom(gi )) ∧ (g1 ( a ). · · · .2: Generalised Composition of functions Deﬁnition 1. the tuple of functions ⇀ g1 . · · · . Extending the notation for the composition of unary functions to generalised composition we ⇀ ⇀ have h = g . f = f ◦ g . The same notation for sequences of values may be extended to sequences of functions which are themselves arguments of a higherorder function.2. f = f ◦ g . its characteristic function ⇀ denoted χr . is the total function χr : A1 ×· · ·×An → {0. For example. Where the length of the tuple is important we may write the above ⇀m ⇀m ⇀m ⇀k tuples as a and g respectively. Notation. Then h = g . ⇀ ⇀ 1 if a ∈ r χr ( a ) = ⇀ 0 if a ∈ r .
BASICS: PREREQUISITES AND NOTATION Deﬁnition 1. y ) ⇀ and this fact is indicated by the notation “q( y )”.8 An atomic predicate is a relation1 . y ) is a ﬁrst order predicate in which the variables in x and y may occur free. ⇀ ⇀ • χ¬p ( x ) = 1 − χp ( x ) ⇀ ⇀ ⇀ • χp∧q ( x ) = χp ( x ). The variables that are free in q are precisely those from y whixh occur free in p( x . ⇀ ⇀ ⇀ Deﬁnition 1. y ).χ¬q ( x )) ⇀ • χ∀y[p] ( z ) = 1 ⇀ 0 if χp (a. Further the usual rules of scope of variables apply here. Further the usual meaning of these predicates is as deﬁned in any text on ﬁrst order logic. the unary (preﬁx) universal quantiﬁer (denoted ∀) 5. y ) may itself be a compound predicate deﬁned in terms of other predicates. 1. binds all occurrences of variables in x that occur free in p( x .χq ( x ) ⇀ ⇀ ⇀ • χp∨q ( x ) = 1 − (χ¬p ( x ). ⇀ ⇀ ⇀ ⇀ ⇀ Example 1. The scope of the binding is indicated by the matching brackets “ [” and “ ]” in the deﬁnition of ⇀ ⇀ ⇀ ⇀ q( y ). z ) = 0 for some a 1 otherwise Hence we use the same notation for atomic predicates as we use for relations . y )] ⇀ ⇀ ⇀ ⇀ where p( x . the binary (inﬁx) operation or (denoted ∨) 4. The characteristic functions of compound predicates is deﬁned in terms of the characteristic functions of their components as follows. the binary (inﬁx) operation and (denoted ∧) 3.2.9 Let p and q be predicates with free variables drawn from x and let x = y. The class of (ﬁrstorder) predicates is the smallest class containing the atomic predicates and closed under the following logical operations. the unary (preﬁx) negation operation (denoted ¬) 2. To denote the scope of variables in quantiﬁed predicates we write the body of the quantiﬁed formula within brackets. ⇀ ⇀ p( x . The quantiﬁer ⇀ ⇀ ⇀ ⇀ ⇀ “∀ x ” in q( y ) however. the unary (preﬁx) existential quantiﬁer (denoted ∃) The usual notions of free and bound variables apply to the predicates and quantiﬁed formulae.1 Consider the ﬁrst order predicate q( y ) deﬁned as q( y ) = ∀ x [p( x .12 CHAPTER 1. z .
(and we may have been guilty too in the course of writing these notes!) but we feel that they are important for various logical reasons and the reader should be aware of the diﬀerences. Deﬁnitional Equality. y)] ⇀ ⇀ ∃y < z[p( x . they are equivalence (reﬂexive. ⇀ ⇀ ∀y < z[p( x . 1. However. Most mathematics texts often ignore these diﬀerences.1. 2. This is most often used in the following situations. y)] = ∀y[(0 ≤ y < z) ⇒ p( x . This is an equality by deﬁnition. to denote . y)] = ∃y[(0 ≤ y < z) ∧ p( x . They are deﬁned as follows. We brieﬂy describe them below and we hope the diﬀerences that we have made explicit will be useful for the reader in understanding not just these notes but mathematics texts in general.3. y)] = ¬(∀y < z[¬p( x . and we use the symbol this.e. y)] Note that bounded quantiﬁcation obeys the De Morgan laws making each bounded quantiﬁer the dual of the other. y)] = ¬(∃y < z[¬p( x . We will also have occasion to use bounded quantiﬁcation – operations derived from the quantiﬁers and used in the context of the naturals. y)]) 1. symmetric and transitive) relations and the two sides of the equality are mutually replaceable under all contexts. Most of these notions of equality share the property of being congruences i. That is ⇀ ⇀ ∀y < z[p( x . it is necessary to emphasize that there are diﬀerences between the various kinds of equality. y)]) ⇀ ⇀ ∃y < z[p( x . z ) = 1 for some a 0 otherwise 13 We use some derived operators such as ⇒ and ⇔ deﬁned as follows: (p ⇒ q) = (¬p) ∨ q (p ⇔ q) = (p ⇒ q) ∧ (q ⇒ p) The usual equational laws of Firstorder logic hold. to name a complex expression because it or its form is somehow considered important. EQUALITY ⇀ • χ∀y[p] ( z ) = ⇀ 1 if χp (a.3 Equality In the course of these notes we shall use various kinds of equality. to abbreviate a complex expression by giving it a name.
Any two expressions that are equal by deﬁnition are also provably equal (by invoking the deﬁnition). In the absence of such name clashes the uniform replacement of one name by the other causes neither any confusion nor any change in the intended meaning of the deﬁnition. However the two deﬁnitions themselves are not syntactically identical because of the use of diﬀerent3 names x and y to express each deﬁnition. We will come across this later in the λcalculus. because the equality of the expressions x3 + 3x2 + 3x + 1 and (x + 1)3 can be proven using the laws of real number arithmetic. As with other equalities. αEquality. Given another deﬁnition r(x) (x + 1)3 . syntactic identity also implies provably equality. Note here that p(4) is an instance of p(x) deﬁned above. we get r(z) = (z + 1)3 and s(z + 1) = (z + 1)3 . Syntactic Identity This is a peculiar notion of equality we will use more in the context of languages or programs rather than in the case of mathematical expressions. since αequality is also a reﬂexive relation. we are either abbreviating or naming the expression on the right hand side by the expression on the left hand side of . This is the most commonly used (and abused) equality and is denoted by the usual “=” symbol. Therefore r(z) = s(z + 1). Consider the two deﬁnitions p(x) x2 − 9 and p′ (y) y 2 − 9. Hence p(x) ≡ p′ (y). in the context of polynomials over real numbers it is perfectly correct to write (x + 1)3 = x3 + 3x2 + 3x + 1. We emphasize this aspect by writing r(z) ≡ s(z + 1). Provable Equality. syntactically identical as expressions. The fact that we have used two diﬀerent names “p” and “p′ ” does not count! .14 CHAPTER 1. Instantiated Equality. However. Continuing with the previous examples we would often write expressions like p(4) = 42 − 9 = 7. In the foregoing examples even though it is incorrect to write q(x) r(x). Consider the two expressions r(x) (x + 1)3 and s(y) y 3 . it follows that any two syntactically identical expressions are also αequal. The equality symbol “=” (between “p(4)” and the expression “42 − 9”) here is overloaded to imply that p(4) is a particluar instance of the deﬁnition p(x) x2 − 92 Note that “p(y) = y 2 − 9” is also a form of instantiated equality and so is p(x + 1) = (x + 1)2 − 9. However there is a sense in which both the deﬁnitions p′ (y) y 2 −9 and p(x) x2 −9 may be regarded as being the same (or equal) in that the variables x and y used to give the deﬁnition its form are only “placeholders” whose name is of no consequence whatsover except when replacement of one name by the other causes a name clash. It is clear that by appropriate instantiations. This syntactic identity depends only on the form of the original deﬁnitions and is independent of the context or the interpretation of these expressions in any mathematical domain. even in the context of polynomials over the reals or integers it is incorrect to write “q(x) r(x)” because the two expressions q(x) and r(x) deﬁne syntactically distinct expressions. Also deﬁnitional equality implies syntactic identity. BASICS: PREREQUISITES AND NOTATION Hence when we write p(x) x2 − 9 or q(x) x3 + 3x2 + 3x + 1. We call this αequality and we denote this fact by writing p(x) =α p′ (y). It is clear that p(y) may be regarded as an instance of the deﬁnition p(x) x2 − 9 and p(y) ≡ p′ (y). this equality between r(z) and s(z + 1) is stronger than just provable equality — they are in fact. As in the case of deﬁnitional equality. Hence 2 3 However the equality symbol “=” between the expressions “42 − 9” and “7” is provable equality. Equally well may p′ (x) be regarded as an instance of the deﬁnition p′ (y) y 2 − 9 yielding p(x) ≡ p′ (x).
. OTHER NOTATIONAL DEVICES 15 p(x) = x2 −9 and we could replace all occurrences of the expression p(x) by the expression x2 −9 and viceversa. we have that for any two (mathematical or formal) expressions E and F 1. To summarize.e. None of the above implications may however. E ≡ F implies E =α F which in turn implies E = F . q(x) =α r(x) and q(x) ≡ r(x). 4. no form of instantiated equality may imply any other form of equality unless it can be proven. To continue with our examples in the context of polynomials. In most cases the proofs of claims are distinguished from the main proof by the use of the bracketing symbols “⊢” and “⊣” to enclose the proof of the claim and separate it from the proof of the main theorem. nor does E ≡ F imply E F or F E holds. Further while all forms of equality may be instantiated. 3. It is also perfectly correct to write “p(x) = x2 −9” or “x2 −9 = p(x)”. But note that even in the context of polynomials over reals. be reversed in general i. it follows therefore that q(x) = r(x) since the expressions they denote are provably equal.4. Hence E and E = F .1. . 1.4 Other Notational Devices We generally follow the practice of splitting long proofs of theorems into claims and using these claims. E F implies E ≡ F and F also implies E =α F 2. it is not true in general that if E = F then E =α F or E ≡ F would hold.
BASICS: PREREQUISITES AND NOTATION .16 CHAPTER 1.
• The instruction set has opcodes 0. R3 . i ∈ P are denoted respectively by !Ri ∈ N. is typically of one of the following forms where i. Otherwise execute the next instruction semantics Rn := 0 Rn :=!Rn + 1 Rn :=!Rm 17 . I2 . m. 1 ≤ j ≤ p. i) Verbal description Clear register Rn Increment the contents of register Rn Copy the contents of register Rm into Rn Jump to instruction i if the contents of the !Rm =!Rn ? i : j + 1 registers Rm and Rn are the same. opcode instruction 0 Z(n) 1 S(n) 2 C(m. • A countably inﬁnite number of discrete storage elements called registers each of which can store an arbitrarily large natural number. R2 .1 The Unlimited Register Machine (URM) Assume the following about the machine. Equivalently M : P → N the memory map may be regarded as a total function from the positive integers to the natural numbers so that M(i) =!Ri for each i ∈ P. . n. 3 respectively. . . 1. · · · are indexed by the set P of positive integers. n) 3 J(m. These registers form the memory. and each instruction Ij . n ∈ P. M is 0 almost everywhere.e. Ip of instructions. • A URM program P is a sequence I1 . The registers R1 .Chapter 2 The RAM Model 2. . 2. • The contents of Ri . • We will usually ensure that only ﬁnitely many registers contain nonzero values i.
Similarly skip instructions (or noop as they are referred to in hardware) may be implemented using instructions such as C(n. n. Ip . n) J(m. Such a conﬁguration is also called the halting conﬁguration and the result of the computation is M(1) the contents of the register R1 .e. . then the result of executing each instruction results in a new memory state M ′ such that {M ′ (n)  M ′ (n) > 0} is also ﬁnite. M. • Given an initial memory M0 and a program P = I1 . . In other words.1 A memory map M of the URM is said to be ﬁnite if there are only a ﬁnite number of registers containing nonzero values i. then a step of the computation from γ is given by γ → γ ′ where γ ′ = P. with p ≥ 1. . I2 . • Unconditional jumps are described by instructions such as J(n. • Given a URM program P = I1 . The verbal description describes the semantics informally in English. respectively and a program counter P C ∈ P denoting the next instruction to be executed. • The URM executes instructions in sequence (unless it executes a jump instruction. i) M′ = {0/n}M {M(n) + 1/n}M {M(m)/n} M M j′ = j+1 j+1 j+1 i if M(m) = M(n) j + 1 if M(m) = M(n) where M ′ = {a/n}M denotes that M ′ is identical to M for all values other than n and M ′ (n) = a regardless of whatever M(n) might be. . . Ip . r2 . n) or by jumping unconditionally to the next instruction. Then the URM is said to halt. The semantics of the jump instruction mixes pidgin SML with the notation for conditional expressions used in languages like C and Perl. Deﬁnition 2. n. · · · . THE RAM MODEL We have used the syntax of the imperative fragment of SML to describe the eﬀect of each instruction on the appropriate register. M ′ .18 CHAPTER 2. j ′ and M ′ and j ′ are as given by the following table: Ij = Z(n) S(n) C(m. j) since M(n) = M(n) always. P C where M(n) = rn . M0 . The URM is said to halt if j > p. the set {M(n)  M(n) > 0} is ﬁnite. I2 . when the sequence is altered) till the instruction referred to by P C does not exist. the initial conﬁguration of the URM is γ0 = P. 1 • Let γ = P. a conﬁguration of the URM is a 3tuple P. j be any conﬁguration of the URM. register contents r1 . . If 0 < j ≤ p. at no stage of the execution of the program does the URM require more than a ﬁnite number of registers to be used. If the (initial) memory M0 in the initial conﬁguration is such that {M0 (n)  M0 (n) > 0} is ﬁnite. M. . .
That is. A computation of the URM is a maximal execution sequence from an initial conﬁguration.1 1. Deﬁnition 2. Lemma 2. since we are interested in the notion of computability which requires for each task only a ﬁnite amount of resources such as storage and program length. 1. i) too has the eﬀect of uniquely determining the next instruction (if any) to be executed. In other words. The instruction J(m. It suﬃces for us to consider only conﬁgurations with ﬁnite memory maps. the actual parameters that these operations may take is actually inﬁnite. 1. and 2. The only registers whose contents may modiﬁed by a URM program are those that are explicitly named in the program. given a memory map M each of the instructions Z(n).2 .2 Let γ0 be an initial conﬁguration of the URM. However. If we did ﬁx storage limits to some ﬁxed number then our theoretical development suﬀers when technology improves to provide more storage than our limit. 19 2. Every instruction has a deterministic eﬀect on the URM machine. would yield a unique memory state M ′ in all programs and under all execution conditions. → is a partial function on the conﬁgurations of the URM because it is undeﬁned for halting conﬁgurations. If Γ is the set of all URM conﬁgurations with ﬁnite memory maps then → is a partial function from Γ to Γ. Every nonhalting conﬁguration of the URM has a unique successor.1. The reader could ask whether the limitation to just four kinds of instructions is not an artiﬁcial constraint. n. Similarly while we consider the executions of URM programs of arbitrary length our fniteness constraints are limited to specifying that the program may not be of inﬁnite length. S(n) and C(m. A (ﬁnite or inﬁnite) sequence of the form γ0 → γ1 → · · · is called an execution sequence from γ0 . Each URM instruction preserves ﬁnite memory maps. that only the kinds of operations are being ﬁxed and that any reasonable mechanical device (going by the history of mechanical devices) would be capable of performing only a ﬁxed ﬁnite set of diﬀerent kinds of operations. 2. Our answer to that would be twofold viz.2. γ → γ ′ and γ → γ ′′ implies γ ′ = γ ′′ . . THE UNLIMITED REGISTER MACHINE (URM) Lemma 2. A theory such as ours would have long term applicability only if it does not artiﬁcially constrain the solutions to problems. n) when executed. we do need to consider the availability of unlimited storage.
a2 . . M2 .. . . and P C = 1 and halts after a ﬁnite number of steps of computation. If it does not halt for the given input then φP (a1 .. Otherwise P is said to diverge on the input. Notation. . (k) . a2 ... ak ) ∈ Dom(f ) Deﬁnition 2.. M2 .e. A predicate p is URMdecidable if and only if there is a URM program which computes its characteristic function χp . . Notation..... If M0 is a ﬁnite memory map... A URM program P converges on input (a1 . ak ) and • P (a1 . ak ) it begins execution from the initial memory state M0 = a1 . ak ) ∈ Dom(f ).. a2 .. P (a1 .3 1. ak ) ↑ for all (a1 . ... . . (k) and P C = 1 and if and when it halts φP (a1 . an ) =⊥. a2 . But it is quite possible that the program does not halt on some (m + 1)tuple input. .. P (a1 . .3 Let γ0 → γ1 → γ2 → · · · be an execution of the URM with the corresponding memory maps M0 . P (a1 . 0.. .. ak ) ↓ b denotes that P converges on input (a1 . etc.... a2 . ak ) if it converges on the input and reaches a conﬁguration in which M(1) = b. .4 A URM program P URMcomputes a partial function f : Nk − →N.. ... ak ) if it begins execution from the initial memory state M0 = a1 . For each k ≥ 0. ak ) ↓ denotes that P converges on input (a1 .. . ak ) ↓ f (a1 . ..... a2 .... In the case decidability however... THE RAM MODEL Lemma 2... ak ) ↑. an ) =!R1 . 3.. . Deﬁnition 2. . note that the characteristic function is always total and hence a URM program that implements it should halt for every mtuple input.. a2 . 0. .. . . P is said to converge to b ∈ N on the input (a1 . a2 . . M1 . Notation. 0. every URM program P computes a partial function φP : Nk + N. . ak ) to b. 0. . . Given an in→ put (a1 ... ak ) 2. .. ak .. if and only if • for each (a1 . . a2 . . then so are each of the succeeding memory maps M1 .. a2 . P (a1 ... the ﬁnal result is the value (k) in register R1 . Deﬁnition 2.5 A partial function f is URMcomputable if and only if there is a URM program P which computes f .20 CHAPTER 2.. ak .. i... if p is an mary relation for some m > 0..
3. Each box may enclose a sequence of instructions. Diamonds indicate decisions to be taken depending on the evaluation of the condition in the ? diamond. J S S J ( 2. R1 x R2 y R3 0 . c r ¨¨ rr r ¨¨ rr ¨ E¨ !R =!R ? 2 3 33 33 33 N Y E 1( STOP 0) 1. we also provide ﬂowcharts to explain the working of the programs.2. diamonds and arrows connecting them to form a ﬂowchart program. Circles usually enclose the single word “STOP” and indicate that a halting conﬁguration has been reached and no further execution is possible or necessary.2. EXAMPLES 21 2.2. . We follow the usual convention that boxes denote actions that could change the memory state. 1. . Each diamond encloses a condition of the form !Rm =!Rn whose truth in the memory state requires a diﬀerent ﬂow of control. . The same notation has been used earlier in the tables deﬁning the semantics of the instruction set. 4. We use a notation drawn from pidgin SML for this purpose. circles. Since the actual programs can be quite tedious and confusing to read and understand.2. The language of ﬂow charts consists of boxes. In each case the initial memory map is also indicated Example 2. The letters “Y” and “N” on the arrows emanating from a diamond indicate the ﬂow of control when the condition is true or false respectively.2 Examples In the following examples we illustrate programming the URM.2 f (x) = 1 x 2 ⊥ if x is even otherwise . 5 ) (3) (1) ( 1. Boxes enclose actions which may change the state of the memory. 3.1 The addition function x + y. 1) P1 c R3 :=!R3 + 1 R1 :=!R1 + 1 Example 2. 2.
2. . 3. y. every program is a partial function whose range is contained in N.e the arity of the function implemented by a program is not predetermined P and is dependent entirely on the length of the input vector. Deﬁnition 2. P (a1 . ⇀ Notation. 3. . . 1 ) P2 c R3 :=!R3 + 1 R2 :=!R2 + 1 R2 :=!R2 + 1 c '$ &% STOP Further notes. 6. 4. ak ). 5. → P .6 ) S(3) S(2) S( 2 ) J ( 1. . The addition program P1 in the example does not necessarily represent only the binary operation ofaddition. THE RAM MODEL . notations and terminology • Every instruction of the URM is deterministic (in the sense that the eﬀect of the instruction on the state of the program is unique). J( 2. z) = x+y−z ⊥ if x ≥ 0 otherwise Hence for any URM program P and for any k ≥ 0. x then P1 implements the identity function f (x) = x. 1. 1.1. . 4.6 A URMprogram P implements a function g : Nk + N iﬀ φk = g. If the initial conﬁguration has only a single input. . . P implments a unique partial function φk : Nk +→ N i. If the initial coﬁguration consists of 3 values then P1 implements the partial function f (x. . . 2. .22 R1 x R2 2k R3 k 0 CHAPTER 2. Given a program P and a tuple of inputs a = (a1 . c r ¨r rr ¨¨ ¨ rr E¨ ? !R2 =!R1 3 33 33 3 N Y c R1 :=!R3 1. ak ) ⇀ denotes the result of executing P with the input a • The type of the function determined by a program P depends entirely on the vector of inputs that we consider. If there are no inputs it implements the constant function 0. 1) C ( 3. Therefore every URMprogram is computes partial of the initial state to the ﬁnal state • Since we are interested only in the contents of R1 when a program P halts.
1 x 2 φP2 (x) = 1 (x 2 (1) ⊥ if x is even otherwise φP2 (x. 1. Example 2. 1} is URMcomputable. 8) This produces a new program P2 ′ .4 Add to program P2 the following instruction J(1. We could similarly add more instructions and keep getting syntactically distinct programs which all implement the same function. For each function f : Nk + N that has an implementation P . x = y is implemented by .3 Consider program P2 . Example 2.2. y. EXAMPLES 23 Example 2.2 and 3 respectively. Each program P implements an inﬁnite number of distinct functions and exactly one function of each arity.2.7 A predicate (or a relation) p ⊆ Nm is URMdecidable if its characteristic (total) function χp : Nm → {0. 2.2. 1. which implements exactly the same function as P . URM Decidability Deﬁnition 2. there are an inﬁnite number → of distinct programs that implement the same function.2. y) = (2) − y) if x is even(xy) ⊥ otherwise 1 z + 2 (x − y) if x is even ⊥ otherwise φP2 (x. z) = (3) Notes. 1.5 The following predicates are URMdecidable. The following are the functions it implements for for the arities 1.2.
1. THE RAM MODEL 1. Let T (3) denote toggle R3 . odd(x) is implemented by incrementing R2 and toggling R3 to reﬂect the evenness or oddness of R2 . 5. r¨¨ N c R1 := 0 R1 :=!R1 + 1 c R1 := 0 2 E 96 87 STOP ' 2. 4. 6 ) Z(1) S(1) Y 1 ¨c ¨¨ ¨ ? ¨ ! R1 =!R2 ¨ r ¨ r rr ¨¨ rcmrmn. 2.24 CHAPTER 2. Initially !R2 = 0 and !R3 = 0. J ( 1. 2. STOP The ﬁnal program is then as follows. c r 33 r r 33 ? rr 3 !R1 =!R2 3 E ¨ ¨¨ ¨ cmrmn. . 3. The ﬁnal ﬂow chart including T (3) looks as follows. 4) Z(1) J ( 1. ¨ N Y c c S(2) T(3) R1 :=!R3 52 c 43 cmrmn.
.4. 5.1: Implementing T(3) 1.1) Composing URMPrograms Function composition in URM is simply the catenation of the component programs. 3. Deﬁnition 2. 7. EXAMPLES r 3c rr 33 3 rr 33 rr 3 ? !R =!R r 4 3 3 33 3 3 333 25 Y c N S(3) c 96 87 c E STOP Z(3) Figure 2. n. 4. .2.2. P ( a ) ↓ b iﬀ P ∗ ( a ) ↓ b.1. p) is such that 1 ≤ p ≤ r + 1. Ir is in standard form provided every jump instruction J(m. . 6.6) Z (3) J (1..8 A program P = I1 . 2.8) S (2) J (3. 8.1) C (3. However we cannot catenate two programs to produce a composition unless the termination or halting of the ﬁrst is tackled in a meaningful fashion – clearly then jump instructions have to be standardized. Lemma 2.4 For any program P there is a program P ⋆ in standard form such that for all input ⇀ ⇀ ⇀ vectors a .. J (1.1) S (3) J (1.2.1.
.. . Let ρ(P ) denote the index of this register. Rm Join P to I. k) Z(k + 1) . . Join F to P . . ... lk . n. .. Then the program P ′ = P [l1 . Let m = max(ρ(P ). C(lk ..... .. ln . Ip+q where any jump ′ instruction Ij = J(m. Z(m) P F C(1.26 CHAPTER 2. ... Further let l1 . . r) is replaced by Ip+j = J(m. 2 Deﬁnition 2... Rk Clear all registers Rk+1 . . . . . Rlk and output (if any) in register Rl . . Ip . This new program P ′ is depicted in the ﬁgure below P [l1 . Since P is a ﬁnite sequence of instructions there exists a highest index of register that P uses. Iq .... l1 . Similarly the output of some component program may have to be stored in some register other than R1 in order that the contents of these registers do not aﬀect or interfere with the computations of the main program. Q in standard form with P = I1 . . . ... Ip+1. l). .lk → l] :: C(l1 . Macros: The operation [l1. . 1) . the join of P and Q is the program P Q = I1 . r + p) and for all other instructions ′ Ij = Ip+j .. l) E E (k) Transfer input values to R1 . . . .. lk → l] denotes a new program whose inputs are in registers Rl1 . While composing programs P and Q together it often happens that the inputs to some later program in the join may lie scattered in diﬀerent registers. THE RAM MODEL Proof: If P consists of p instructions then P ∗ is the program obtained from P by replacing all jump instructions that go outside the program to jump to p + 1. . . .. lk → l] Our convention of reserving the ﬁrst few registers for input and the ﬁrst register for output has the disadvantage that it is inconvenient when joining several smaller programs together to obtain a larger program. l be distinct registers with each index exceeding ρ(P ). Ip and Q = ′ ′ I1 . . . Let P be a URM program in standard form and k such that φP : Nk +→ N is computed by P .9 For any two programs P. .. .. l2 . n.
A function f : D+→ D is said to be URMcomputable under the coding α if there exists a URMcomputable function f ∗ : N+ N such that the following diagram holds. f (d) = α−1 (f ⋆ (α(d))) In other words f = α ◦ f ⋆ ◦ α−1 Note: 1. so α−1 is partial in general.e → D α c f E D T α−1 N E f⋆ N For any d ∈ D. i. .10 A coding of a domain D is an explicit and eﬀective injection α : D → N. α may not be surjective.2. α needs to be injective and total. 2. EXAMPLES 27 URMComputability on other Domains Deﬁnition 2.2.
28
CHAPTER 2. THE RAM MODEL
Chapter 3 The Primitive Recursive Functions
3.1 Introduction
Partial recursive functions are a diﬀerent approach to computability. In this and the next chapter we will see the relation between partial recursive functions and URMcomputability. However we need to ﬁrst deﬁne the class of primitive recursive functions and then gradually build up to the partial recursive functions. Deﬁnition 3.1 The initial functions are 1. the constant 0, 2. the unary successor function s
n 3. the family {πi  n ∈ P, 1 ≤ i ≤ n} of projection functions, where for each ntuple n (x1 , . . . , xn ), and each i, 1 ≤ i ≤ n, πi (x1 , . . . , xn ) = xi
URM and µrecursive functions
Lemma 3.1 The initial functions are all URMcomputable. Proof: • the constant 0 is computed by the program Z(1) • the unary successor function s is computed by the program S(1)
n • For each n ∈ P and i, 1 ≤ i ≤ n, πi is computed by the program C(i, 1).
29
30
CHAPTER 3. THE PRIMITIVE RECURSIVE FUNCTIONS 2
Lemma 3.2 Composition is URMcomputable. Let f : Nk +→ N, g1 , · · · , gk : Nm +→ N ⇀ ⇀ Then the composition of f and g denoted by f ◦ g is also URMcomputable. Proof: Let f and g1 , · · · , gk be computed by programs F, G1 , ..., Gk respectively and let n = ⇀ max(m, k, ρ(F ), ρ(G1 ), ..., ρ(Gk )). The following program computes f ◦ g
C(1, m + 1) . . . C(n, m + n) G1 [m + 1, m + 2, ..., m + n → m + n + 1] . . . Gk [m + 1, m + 2, ..., m + n → m + n + k] F [m + n + 1, ..., m + n + k → 1]
2 Often we may require to obtain new functions from existing functions by permuting the arguments, or by identifying some arguments or by the addition of dummy arguments. Typical examples of such functions are as follows: Permuting arguments Consider the “divisor of” relation on numbers expressed in terms of its characteristic function divisorof : N × N → {0, 1}. We may deﬁne the “multiple of” relation multipleof : N × N → {0, 1} in terms of the divisorof function by permuting the two arguments, i.e. multipleof (x, y) = divisorof (y, x). Identiﬁcation of arguments Consider the function double : N → N which is obtained from addition function by identifying the two operands of addition. Addition of dummy arguments Any constant k ∈ N may be elevated to the status of a function such as k (1) : N → N deﬁned as k (1) (x) = k and further to k (2) : N × N → N deﬁned as k (2) (x, y) = k. The following theorem shows that these operations are also URMcomputable and expressed using only composition and the initial functions. Theorem 3.3 Let f : Nk + N be a URMcomputable function deﬁned in terms of the variables → x1 , . . . , xk . Let xi1 , . . . , xin be a sequence of nvariables drawn from the set {x1 , x2 , ..., xm } ⊇ {x1 , . . . xk }. Then the function h : Nn + N deﬁned by →
3.2. PRIMITIVE RECURSION
31
h(xi1 , . . . , xin ) = f (xj1 , . . . , xjk ) where {xj1 , . . . , xjk } ⊆ {x1 , x2 , ..., xm }, is also URM computable. ⇀k ⇀n m m Proof: Writing x for (xi1 , ..., xin ) and π m for (πj1 , · · · , πjk ) and using composition we have ⇀k ⇀n h( x ) = [f ◦ π m ](x1 , . . . , xm ) Since composition and projection are both URMcomputable it follows that h is also URMcomputable. 2 Notes. 1. The case of the empty sequence () is taken care of by lemma 3.7 which shows that the naturals are all computable. 2. Since xi1 , . . . , xin are all drawn from the set {x1 , x2 , ..., xm } ⊇ {x1 , . . . xk }, some of the arguments of h may be identiﬁcations of variables in {x1 , . . . xk }, some may be reorderings (permutations) of the variables in {x1 , . . . xk } and some of them may be drawn from {x1 , x2 , ..., xm } − {x1 , . . . xk } (these are the dummy arguments of h). Notice that the arguments (xj1 , . . . , xjk ) f in the deﬁnition of h are entirely drwan from {x1 , x2 , ..., xm }.
3.2
Primitive Recursion
Given total functions f : Nn → N and g : Nn → N, consider the following relation h ⊆ Nn+2 hi and the individual hi , i ≥ 0 are deﬁned by induction as follows. where h =
i≥0
⇀ ⇀ ⇀ h0 = {( x , 0, f ( x ))  x ∈ Nn } ⇀ ⇀ ⇀ ⇀ hi+1 = {( x , i + 1, zi+1 )  x ∈ Nn , zi+1 = g( x , y, zi), ( x , y, zi) ∈ hi }
for i ≥ 0
In fact as the following theorem shows we may express the relation h by a pair of so called recursion equations which uniquely deﬁne h in terms of the functions f and g. ⇀ ⇀ h( x , 0) = f ( x ) ⇀ ⇀ ⇀ h( x , y + 1) = g( x , y, h( x , y)) (3.1) (3.2)
Theorem 3.4 Given total functions f : Nn → N and g : Nn+2 → N, there exists a unique total function h : Nn+1 → N satisfying the recursion equations (3.1) and (3.2).
1) and (3. 0. f ( a )) ∈ S and ⇀ ⇀ ⇀ Induction. b.5 Given partial functions f : Nn +→ N and g : Nn+2 +→ N. ⇀ ⇀ ⇀ ′ ⊢ Suppose there is a tuple ( a . b. Hence c = f ( a ). d)} ′ is a satisfactory set and S0 ⊆ S0 which is impossible. g( a . c). 0)] ⇀ and assuming that for all a and some b ≥ 0.32 Proof: CHAPTER 3. If c = f ( a ) then S0 = S0 − {( a . b. 0) = f ( x ) = h′ ( x . h′ ( a . f ( a )) ∈ S0 but S0 ⊆ S0 . Theorem 3.2). ( a . c)) ∈ S. b + 1. Then for each choice of a there exists a unique c ∈ N such that ( a ⇀ ⇀ . b + 1. if ( a . b. Claim 2. Consider sets of (n + 2)tuples of numbers. b. c) ∈ S. Consider S0 = S. Further Claim 1. b)) ⇀ ⇀ = g( a . S0 is also nonempty since it contains at least every tuple of the form ⇀ ⇀ ( a . c)} would be ⇀ ⇀ ⇀ ′ ′ satisfactory since ( a . c) ∈ S0 . → . A set S ⊆ Nn+2 is called satisfactory ⇀ with respect to the recursion equations (3. 0. 0. b + 1) 2 We may extend the above result to partial functions by insisting that functions be strict with respect to the undeﬁned.1) and (3.1) and (3. Suppose there ⇀ ⇀ ⇀ ′ exists ( a . Suppose there exist two functions h and h′ both of which satisfy the recursion equations (3. b. b+1. d) ∈ S0 such that d = g( a . b + 1. ⊣ Uniqueness. there exists a unique partial function h : Nn+1 + N satisfying the recursion equations (3.2). b + 1) = g( a . ⇀ ⇀ h( a . Then again S0 = S0 − {( a . 0.2) if for every choice of a ∈ Nn . h( a . b. 0. g( a . Since S0 is satisfactory it follows that ( a . Assume the claim is ⇀ ⇀ true for all 0 ≤ b′ ≤ b. f ( a )). S0 is satisfactory and is contained in every satisfactory set. Then from the fact that f and g are (total) functions we have ⇀ ⇀ ⇀ ⇀ ∀ a [h( x . c) ∈ S. ⇀ ⇀ Basis. there is a unique c such that ( a . ⇀ ⇀ For each choice of a and b. c) ∈ S0 . THE PRIMITIVE RECURSIVE FUNCTIONS Existence. b) = h′ ( a . Let S be the set of all satisfactory sets. Clearly S = ∅ since Nn+2 is satisfactory. c)) ∈ S0 . b. b) we have ⇀ ⇀ ⇀ h( a . then ( a . b)) ⇀ = h′ ( a .
y + 1) = g( x . 0) = f( x ) ⇀ ⇀ ⇀ h( x . h( x . f ] or [f ◦ g ]. y. our notation for functions f of type Nk + N simply speciﬁes that f is simply a member of the set Nk + N. ⇀ In the particular case when a function f of arity k > 0 is composed with k functions g .3.6 If f : Nn + N and g : Nn+2 + N are URMcomputable then so is h : Nn+1 + → → → N with ⇀ ⇀ h( x . • The function deﬁned by primitive recursion on f and g is denoted [f pr g]. y)) . 2 We may regard both function composition and primitive recursion as (higher order) operators which take functions of appropriate arities as arguments and yield new functions as results. That is f is simply a point in the space Nk +→ N of functions of arity k which yield natural numbers as values. hi = ∅ then hj = ∅ for all j > i. → → which is exactly the space of all partial functions of the speciﬁed type.2 A function h : Nn+1 +→ N is said to be deﬁned by primitiverecursion on functions f : Nn + N and g : Nn+2 + N if it satisﬁes the equations → → ⇀ ⇀ h( x . where ⇀ each of the components of g is of arity m > 0. y. we get a new function h of arity m. Both composition and primitive recursion are polymorphic functions. Primitive recursion is U RMcomputable Deﬁnition 3. ◦ : (Nk + N) × (Nm + N)k → (Nm + N) → → → Similarly primitive recursion may be regarded as a polymorphic operator of type pr : (Nn + N) × (Nn+2 + N)+ (Nn+1 + N) → → → → Notation ⇀ ⇀ ⇀ • The composition of f with g is denoted [ g . More precisely. the type of composition may be described as follows. while simply noting that if f is the everywhere undeﬁned function then so is h (prove it!). Function composition and primitive recursion are therfore merely functions or operators on such spaces. h( x . In such a case. 0) = f( x ) ⇀ ⇀ ⇀ h( x . y + 1) = g( x .2. y)) Theorem 3. PRIMITIVE RECURSION 33 Proof: We leave the details of the proof of the above theorem to the reader. Further in the inductive deﬁnitions of the relations hi . if for any i ≥ 0.
3 The class P RIMREC of primitive recursive functions is the smallest class of functions containing the initial functions and which is closed under the operations of function composition and primitive recursion That is. For any n > 0 the following program computes it 1. n. THE PRIMITIVE RECURSIVE FUNCTIONS Proof: Let F and G compute f and g resp and let m = max(n + 2. p) q. Rm Rm+1 ⇀ x Rt y Rt+1 Rt+2 k ⇀ h( x . J(1. 1 ≤ i ≤ n} ⇀ ⇀ = P RIMRECj ∪ {[f ◦ g ]  f.. t + 1) F [1. 2. t + 1. k) Rt+3 C(1.7 Every natural number is URMcomputable Proof: Each natural number n : ∅ → N is a total function from the empty set to the naturals. .. t + 2. R1 .. y). . . . 1. . J(t + 2. ρ(F ). .. the class P RIMREC may be deﬁned by induction as follows P RIMREC0 P RIMRECj+1 P RIMREC n = {0} ∪ {s} ∪ {πi  n > 0.. g ∈ P RIMRECj } ∪{[f pr g]  f. m + n) C(n + 1. 2 Lemma 3. m + n. .34 CHAPTER 3. t + 3 → t + 3] S(t + 2) J(1.. ρ(G)) and t = m + n ⇀ Then the following program computes h( x . 2) computes the number 0. 1). S(1) . S(1) 2 Deﬁnition 3. q) G[m + 1. g ∈ P RIMRECj } = P RIMRECk k≥0 . n → t + 3] p. . C(t + 3. . 1.
. Proof outline: By induction on the induction variable j in deﬁnition 3. Proof outline: In each case we express the function as being obtained by a ﬁnite number of applications of composition and primitive recursion on the initial functions... These formulations not only prove that they are primitive recursive. . 2 Lemma 3. Often we simply express a function in terms of composition or primitive recursion on functions shown earlier to be in the class P RIMREC. these restrictions are required. xin ) = f (xj1 . . . . . ... is also primitive recursive. x2 .. .3. x2 . However. the proof is written between the brackets ⊢ · · · ⊣. we have not explicitly mentioned the type restrictions on composition and primitive recursion. xjk } ⊆ {x1 .9 Every function deﬁned by composition or by primitive recursion on functions in P RIMREC is also primitive recursive. .11 The following underlined functions are primitive recursive (and hence URMcomputable). . . In each case. xk }. This implies that we need to show an explicit construction of the function using only the initial functions and the operations of composition and primitive recursion. . . Theorem 3. for some k ≥ 0. they show that these functions are URMcomputable as well (since we have shown that both composition and primitive recursion are URM computable operations. xm }. . . It follows easily since the initial functions are total and each application of composition or primitive recursion is on total functions belonging to a class with a smaller index.10 Let f : Nk → N be a primitive recursive function deﬁned in terms of the variables x1 . Let xi1 . . we require to show the construction of the function as belonging to a certain P RIMRECk . .3.. . . xin be a sequence of nvariables drawn from the set {x1 . Then the function h : Nn → N deﬁned by h(xi1 . Notice that the proof of theorem 3.2.8 Every function in P RIMREC is total. Hence in order to show that a certain function belongs to the class P RIMREC. while still respecting the type restrictions on composition and primitive recursion. xm } ⊇ {x1 . . .10. xjk ) where {xj1 . Lemma 3. . PRIMITIVE RECURSION 35 In the above deﬁnition. Lemma 3.3 may be reproduced as the proof of lemma 3. . . xk . . for the sake of conciseness. .
⊣ 3. 7. y) = x + y. So we get tpred = [0 pr π1 ] ⊣ .10 we may express the constant 0 also as a constant function (of any number of arguments). For k > 0 we have k = [s ◦ · · · ◦ s](0) . y) = x − y. 2 ⊢ Here x is the induction variable. π3 )]] . k ∈ N. π3 )]] . π3 ) then yields the 3 3 deﬁnition mult = [0 pr [add ◦ (π1 . k times ⊣ 2. mult(x. y. monus(x. . ⊣ 6. y)) 3 3 we use a reasoning similar to that for multiplication to get texp = [[s ◦ 0] pr [mult ◦ (π1 . add(x. mult(x. THE PRIMITIVE RECURSIVE FUNCTIONS ⊢ 0 is initial. ⊣ 5. y+1) = mult(x. 0) = 1 = s(0) = s(0(x)) and texp(x. tpred(x) = x − 1 (assuming tpred(0. CHAPTER 3. y) = xy (assuming 00 = 1). ⊢ Again by induction on y we have x. ⊢ Using the deﬁnitions texp(x. . 3 ⊢ We have x − 0 = x = id(x) and x − (y+1) = tpred(x − y) Hence monus = [id pr [tpred ◦ π3 ]] ⊣ 0 if x=0 1 if x > 0 8. y)). y) = xy. By lemma 3. 1) = 0). . We then have add = [id pr [s ◦ π3 ]] . z) = add(x. id(x) = x. sg(x) deﬁned as sg(x) = . texp(x. The function g(x. texp(x. ⊣ 4. . y)) = [s ◦ add]. z) = add ◦ (π1 . ⊢ Using the induction on y we get x + 0 = x = id(x) and x + (y + 1) = (x + y) + 1 = 3 s(x + y) = s(add(x. 1 ⊢ Clearly id = π1 . y) = add(x. We write it as 0(x) and it is clearly 3 3 primitive recursive.(y + 1) = xy + x = x + xy = x + mult(x.0 = 0 and x.36 1.
π2 )])] y if x = 0 y mod x otherwise ⊣ ⊣ 14. [sg ◦ [sdif f ◦ (π1 . [monus ◦ (1. ⊢ x − y = (x − y) + (y − x) = add(monus(x. ⊢ We have 0! = 1 and (x + 1)! = x! × (x + 1) = mult(s(x). f act(x)). y). y + 1) = mult(trem(x. id)])] 1 if x = 0 0 if x > 0 ⊣ ⊣ 9.2. sg(x) deﬁned as sg(x) = . Using 1 as unary constant function we have sg = [monus ◦ (1. f act(x) = x!. [s ◦ π3 ])]])]] ⊣ . y) + 1 if trem(x. [monus ◦ (π1 . y) = x − y. x)). ⊢ sg(x) = 1 − sg(x) 10. y) + 1 = x which gives the following recursion equations: trem(x. min(x. . π2 )]] ⊣ 12. π2 )])] 13. y) + 1. ⊢ Clearly sg(0) = 0 and sg(x + 1) = 1. monus(1. y) = x − (x − y) Hence min = [monus ◦ (π1 . . π2 )]. . π1 )])] .3. y) + 1 = x trem(x. y) + 1))) 3 3 3 from which we get trem = [0 pr [mult ◦ (s ◦ π3 . y). [monus ◦ (π1 . x)). [monus ◦ (π2 . It is easy to see that sg(x) = 1 − (1 − x) = monus(1. sg(x − (trem(x. which yields 2 2 f act = [1 pr [mult ◦ ([s ◦ π1 ]. y + 1) = 0 if trem(x. ⊣ 11. . 0) = 0 trem(x. PRIMITIVE RECURSION 37 . 2 2 2 ⊢ min(x. . trem(x. sdif f (x. y) = ⊢ We have trem(x. y). max(x. Hence 2 2 2 2 sdif f = [add ◦ ([monus ◦ (π1 . y) = y + (x − y). monus(y. Hence max = [add ◦ (π1 . 2 2 2 ⊢ max(x. .
Proof: By lemma 3. ⊣ . y). which extends the use of lemma 3.12 If f : Nk+1 → N is primitive recursive then so is any instance of it. a = b × tquot(b. h(x. k+1 k+1 Then clearly g = [f ◦ (m(1) . tquot(x. π2 . 2 Claim 1. Similarly the function f (n) = 2n may be considered an instance of the function texp in which the ﬁrst argument is the constant 2.10 we may reorder the arguments of f so that the argument instantiated is the ﬁrst one. y) + 1 = x tquot(x. πk+1 )]. 0) = 0 tquot(x. the nfold application of f is also primitive recursive. t + 1) = f (h(x.11 to obtain the following corollary. sg(x − (trem(x. y) = ⊢ We have CHAPTER 3. h(x. Let f : N → N be primitive recursive. For example the doubling function double(x) (which was previously considered an example of identiﬁcation of arguments of the addition operation) could be regarded as an instance of the binary multiplication operation in which one argument is the constant 2. a) with trem(b. ⊢ Deﬁne the nfold application of f to be the function h by the recursion equations. We may use part 1 of theorem 3.10 we may treat m as a unary function deﬁned as m(1) (x) = m. y) if trem(x. y) + 1))) 3 3 3 Hence tquot = [0 pr [add ◦ (π3 . a) + trem(b. Then by lemma 3. y + 1) = add(tquot(x. y) + 1 if trem(x. 0) = x 3 h(x. tquot(x. then f n (x). t))) 3 Hence h = [id pr [f ◦ π3 ]] is a primitive recursive function. [sg ◦ [sdif f ◦ (π1 . t. t)) = [f ◦ π3 ](x. THE PRIMITIVE RECURSIVE FUNCTIONS 0 if x = 0 y div x otherwise tquot(x. Corollary 3. y) + 1 = x tquot(x. b. a) ≤ a. · · · .38 15. [s ◦ π3 ])]])]] ⊣ 2 The deﬁnitions of trem and tquot are total and have been chosen so that for any two numbers a.10 to instances of functions. y ) where m is some ﬁxed natural number m. Hence without loss of generality we assume that the ﬁrst argument of f is ⇀k ⇀k instantiated to obtain the kary function g( y ) = f (m. y + 1) = from which we get the following recursion equations.
PRIMITIVE RECURSIVE PREDICATES 39 3. “<”. In this sense we have already deﬁned two such functions sg(x) and sg(x) in theorem 3. instead of their characteristic functions. 1.11.13 The following underlined predicates are primitive recursive and hence are also URMcomputable. but 0 is not a divisor of any positive integer.3. ⊢ χ= (x. the “divisorof” relation. Note that every predicate yields a value of 0 or 1 depending upon whether it is true or false respectively. ⊢ χ> (x. y)) 2. the equality relation. “>” and “” for the obvious relations they denote. We now turn to the question of designing some primitive recursive predicates on numbers. Proof outline: Unlike the case of theorem 3. “=”. y)) ⊣ ⊣ 2 Often in the interest of readability we will use the relational symbols. y) = sg(sdif f (x. both of which could be interpreted as predicates standing for the properties “isnonzero(x)” and “iszero(x)” respectively. y) = χ< (y. We explain only the key ideas that may be used in formulating the primitive recursive deﬁnition. y)) ⊣ 3.3 Primitive Recursive Predicates We have seen several functions that are primitive recursive. y) = sg(trem(x. Theorem 3. x) ⊣ 4. the lessthan relation ⊢ χ< (x. the greaterthan relation.3. ⊢ Adopting the convention that 0 is a divisor of 0.11 we do not give complete expressions and leave the formulation of the actual deﬁnition to the reader. y) = sg(monus(x. . we get χ (x.
14 (Deﬁnition by cases).χq ( x ) ⇀ ⇀ ⇀ (iii) χp∨q ( x ) = max(χp ( x ). Then the function g : Nk + N → ⇀ f1 ( x ) if ⇀ . p1 . w) if y = w + 1 z<w . · · · . . 1} are URMdecidable predicates then so are the following (i) ¬p (ii) p ∧ q (ii) p ∨ q Further if p and q are primitive recursive then so are ¬p.fm ( x ). . Proof: ⇀ ⇀ (i) χ¬p ( x ) = monus(1. z) + f ( x . . ⇀ ⇀ ⇀ ⇀ ⇀ Proof: g( x ) = χp1 ( x ). p ∧ q and p ∨ q. If p. χp ( x )) ⇀ ⇀ ⇀ (ii) χp∧q ( x ) = χp ( x ).. z)..f ( x .15 (Algebra of Decidability). . p2 .4 Some Forms of Primitive Recursion Corollary 3. g.⇀ f ( x ) if m ⇀ p1 ( x ) ⇀ pm ( x ) is URMcomputable. Further if f1 .. z) = f ( x . f2 ..40 CHAPTER 3. pm are each primitive recursive then so is g. fm : Nk +→ N be URMcomputable functions and p1 . pm : Nk → {0. z) = f ( x .16 Let f. g( x ) = . q : Nk → {0. .. . h : Nk+1 + N such that → 0 if y = 0 ⇀ ⇀ ⇀ f ( x . pm ( x ) is true.. χq ( x )) 2 Bounded sums and Products Theorem 3. y) = z<y ⇀ h( x . THE PRIMITIVE RECURSIVE FUNCTIONS 3. . fm . . f2 . w) if y = w + 1 z<w ⇀ g( x . 2 Corollary 3. . y) = z<y Then g and h are URMcomputable if f is total and URMcomputable and g and h are primitive recursive if f is primitive recursive. . 1} be URMdecidable predicates such that for any ⇀ ⇀ ⇀ x ∈ Nk exactly one of p1 ( x ). Let f1 . 1 if y = 0 ⇀ ⇀ ⇀ f ( x .f1 ( x ) + · · · + χpm ( x ). p2 . .
17 If f.3) ⇀ ⇀ That is.19 g in (3. z)] Theorem 3. y) be any predicate and let q( x . If p is URMcomputable then so are q and r. [f ◦ (π1 . 1} be a (total) computable predicate. πk+1 )])]] k+2 k+2 k+1 h = [1 pr [mult ◦ (πk+2 .3) above is computable if p is URMcomputable.y) z<i( x . [f ◦ (π1 . z)] = ⇀ least z < y : p( x . y) = ¬(∀z < y[¬p( x . y) = ⇀ ⇀ ⇀ f ( x . 1. More rigorously we have k+2 k+2 k+1 g = [0 pr [add ◦ (πk+2 . y) Further if f and i are primitive recursive then ⇀ ⇀ z<i( x . y) = f ( x . y) = ⇀ ∃z < y[p( x .3. z) and h( x .4. 2.y) so are g and h.18 Let p( x . y) = µz < y[p( x . z) if z exists y otherwise (3. SOME FORMS OF PRIMITIVE RECURSION 41 Proof: Since the above are deﬁnitions by primitive recursion it follows that g and h are computable (respectively primitive recursive). z) and r( x . . z)] and r( x . · · · . If p is primitive recursive then so are q and r. z)]) from which the 2 relevant results follow. Then the function ⇀ ⇀ g( x . Bounded Minimalization decidable Let p : N k+1 → {0. y) = ∀z < y[p( x . y) = z0 ⇔ ∀z[0 ≤ z < z◦ ≤ y ⇒ ¬p( x . y) = 0≤z<y ⇀ ⇀ ⇀ χp ( x . πk+1 )])]] 2 ⇀ Corollary 3. z)]. Bounded Quantiﬁcation ⇀ ⇀ ⇀ ⇀ Theorem 3. Further if p is primitive recursive then so is g. ⇀ Proof: We have χq ( x . g( x . i : Nk+1 → N are total computable functions then so are g( x . · · · .
THE PRIMITIVE RECURSIVE FUNCTIONS ⇀ Proof: Consider all the predicates ¬p( x . 1. v) = u≤v ⇀ ¬p( x . #div(x) = y≤x yx 2.21 The following functions are primitive recursive. For each 0 < v < y we have ⇀ f ( x . y) = w<y v≤w ⇀ ¬p( x . u) = 1 0 otherwise For each 0 ≤ w < y we have ⇀ f ( x .20 If p : Nk+1 → {0. #div(x) = the number of divisors of x (assuming #div(0) = 1) 2. w )[p( x . Theorem 3. z)] is a total computable function. (x)y = the exponent of py in the prime factorization of x. prime(x) = “whether x is a prime” 3. px = the xth prime number (assuming p0 = 0) 4.42 CHAPTER 3. Corollary 3. (x)y = µz < x[pz+1 ∤ x] y 2 Theorem 3. Proof: 1. 1} is decidable and f : Nk+m → N is a total computable ⇀ ⇀ ⇀ ⇀ function then g( x . v) which is a primitive recursive function of p. p0 = 0 and py+1 = µz ≤ (py ! + 1)[(py < z) ∧ prime(z)] 4. 2) 3. w) = 0≤w<y w if w < z0 z0 if w > z0 2 ⇀ Hence g( x . y) = µz < f ( x . .22 The set P RIMREC of primitive recursive functions is countably inﬁnite. prime(x) = eq(#div(x). u) = ⇀ 1 if ∀u : 0 ≤ u ≤ v : ¬p( x . z) for each value of z.
such that f ∈ P RIMRECj . fm ( x ) + 1. let P Rj denote the set of primitive recursive functions of depth j.. say f1 . The set P RIMREC is not ﬁnite. g (n) is m diﬀerent from every one of f1 and since max is primitive recursive and + is primitive (n) recursive it follows that g is primitive recursive contradicting the initial assumption. Claim 1. P RIMREC is countably inﬁnite. Since P RIMREC is the countable union of at most countable sets.. ⊣ 2 . fm :(n) . we have P R0 = P RIMREC0 which is countably inﬁnite and by induction we may show that each P Rj is also at most countably inﬁnite. we have P Rj = P RIMREC and for each j≥0 i = j. The set P RIMREC is countably inﬁnite ⊢ From deﬁnition 3.f (n) Claim 2.3 it is clear that every primitive recursive function belongs P RIMRECj for some j ≥ 0. Hence P RIMREC (n) is inﬁnite. Clearly then. Assume there are only ﬁnitely many primtive recursive functions of (n) arity n for some n ≥ 0. construct a ⇀ (n) ⇀ (n) ⇀ new total function g (n) : Nn → N such that g (n) ( x ) = max(f1 ( x ). 43 ⊢ By contradication ..3. Since they are all total we may. · · · . In particular.4. ⊣ (n). SOME FORMS OF PRIMITIVE RECURSION Proof: It suﬃces to prove the following two claims. For each j ≥ 0. · · · . P Ri ∩ P Rj = ∅.. We may deﬁne the depth of a primitive recursive function f to be the smallest index j.
44 CHAPTER 3. THE PRIMITIVE RECURSIVE FUNCTIONS .
y)] is computable where ⇀ ⇀ ⇀ least y : p( x . 1} be a decidable predicate.1 Unbounded Minimizationis URMcomputable. . z)]) ∧ p( x . . z◦ ) ⇀ ⊥ otherwise ⇔ g( x ) = z◦ Theorem 4. Rm Rm+1 Rm+k Rm+k+2 y Rm+k+1 1 ⇀ x 2 45 . .Chapter 4 The Partial Recursive Functions Unbounded Minimization Let p : Nk+1 → {0. Let m = max(k + 1.e (∀z < z◦ [¬p( x . ρ(p))). Then R1 . Proof: Let g and p be as deﬁned above and let P be a URM program that computes p. Then g : Nk − →N deﬁned by ⇀ g( x ) = ⇀ µ[p( x . . y) i.
g] Deﬁnition 4. . . m + k) k + 1. J(1. S(m + k + 1) k + 6.. s. k + k) k + 2. . gk ] (iii) Closed under primitive recursion ————– P r[f. m + k] Z(m + k + 1) Set to 1 for comparing truth values Copy parameters y : =0 E compare R1 and Rm+k+2 and jump E otherwise increment Rm+k+1 P [m + 1.. k. idk ) i (ii) Closed under composition and —————— ◦[f . E Initialize Rm+k+2 to 1 for comparision E k + 3.. k → m + 1. C(m + k + 1. 1) Copy y into R1 c Stop Partial Recursive Function Deﬁnition 4.. g1. ... .. . idk ) i (ii) Closed under composition and —————— ◦[f . m + k + 1 → 1] Run P 3 33 3 ? d !R1 = 1 d ¨¨ d¨¨ c S(m + k + 1) c C(m + k + 1.. g1. k + 7) k + 5.1 The class PRIMREC of primitive recursive functions is the smallest class (i) Containing the basic functions —————— (o.2 The class PARTREC of partial recursive functions is the smallest class (i) Containing the basic functions —————— (o.. P (m + 1. k + 2) ECopy ⇀ to R x m+1 to Rm+k E Initialize Rm+k+1 to 0. s. C(1... THE PARTIAL RECURSIVE FUNCTIONS 1. Z(m.46 CHAPTER 4. J(1... m + k + 2 → 1) run P and have output in R1 k + 4.. m + k + 2. k + 3) k + 7... C(k. gk ] . m + 1) . 1... . . 1) S(m + k + 2) C[1. S(m.
steps the number of the next instruction to be executed after tsteps otherwise 2 Claim 1. µy[ρ] Theorem 4. . t0 ) = c1 ( x .4 A function is URMcomputable if and only if it is partial recursive. c! . Is . t) = 0]) 2 Corollary 4. That is. Now consider the following functions ⇀ c1 ( x .2 P RIMREC ⊆ P ART REC ⊆ URM Proof: The foregoing results have shown this. Claim 2. where t0 = µt[( x . Proof: Let f : Nk +→ N be a URMcomputable function implemented by a program P = I1 . Nk . : Nk+1 → N are total fuctions. g] (iv) Closed under (unbounded) minimalization. f is a partial recursive function ⇀ ⇀ ⇀ If for any x . Claim 3. Theorem 4. . µt[j( x . are both URMcomputable.47 (iii) Closed under primitive recursion ————– P r[f. t) = 0] ⇀ ⇀ ⇀ ⇀ ⇀ and R1 contains the value f ( x ) . . P ART REC ⊆ URM . Hence f ( x ) = c1 ( x . In fact c1 and are both primitive recursive. t) !R1 if P has stopped executing in less than t steps !R1 after tsteps of execution of P otherwise 0 if P has stopped execution in less than t.3 Every URMcomputable function is partial recursive. . . A step of the execution of P is the execution of a single instruction. f ( x ) ∈ N then P converges after some t0 steps. c1 . t) ⇀ j( x .
48 CHAPTER 4. THE PARTIAL RECURSIVE FUNCTIONS .
3 A set A is eﬀectively denumerable if there is a bijection f : X − → N such − that both f and f −1 are eﬀectively computable functions.1 A set A is denumerable (or countably inﬁnite) if there exists a bijection f : A → N. Deﬁnition 5.e. N∗ .1 The following sets are eﬀectively denumerable 1. 3. g is a bijection) then g is an enumeration without repetitions.1 Introduction We have discussed the notion of 5. Clearly g −1 shows that the set is denumerable. Nk for all k > 2. and if g is injective too (i.2 Numbering and Coding Deﬁnition 5. N × N.Chapter 5 Coding and G¨delization o 5. 2.2 An enumeration with possible repetitions of a set A is a surjective function g : N → A. 49 . onto 1−1 Theorem 5. Deﬁnition 5.
triple(x. z) = pair(x. n) 2m (2n + 1) − 1) . ak ]) then tl(z) = seq([a2 . . seq([1]) = 2.50 Proof: ¨ CHAPTER 5. deﬁned as seq([a1 . seq(s) = 0 iﬀ s = ε (5. hd. triple(f st3(u).3) are deﬁned as follows. y. . It is then clear that the functions seq. ak ]) 2a1 + 2a1 +a2 +1 + · · · + 2a1 +a2 +ak +(k−1) = 2a1 (1 + 2a2 +1 (1 + 2a3 +1 (. pair is primitive recursive and hence eﬀective.. Consider the function seq : N∗ → N. . . We also deﬁne the function cons(a. y. z + 1) which again is primitive recursive.9) (5.4) f st3(triple(x. 0]) = 20 (1 + 2(0+1) ) = 3. . snd2(z)) = z f st2(pair(x. a2 . snd2(z) is simply the largest odd divisor of z + 1. . We deﬁne the function hd(z) as the largest power of 2 that divides z i.2) (5.1) (5. 2. we have hd(cons(a..))) (5. tquot(hd(z). y)) = y (5. z) − 1) to ensure that if z = seq([a1 . It is clear that all these functions are primitive recursive and they satisfy the following deﬁning equations. seq(s) > 0. z)) = z seq([a1 . seq([a2 . z) = 2a (2z + 1). thd3(u)) = u (5. z)) = z 3. . .. y. For instance. .11) 2 . hd(z) = µx < (z + 1)[2x ∤ (z + 1)] − 1 and tl(z) = tquot(2. Equivalently.5) (5. We prove this only for k = 3. z)) = x snd3(triple(x. and tl satisfy the following equations. . The inverse functions f st2. . CODING AND GODELIZATION 1. . . pair(y. snd3(u) = f st2(snd2(u)) and thd3(u) = snd2(snd2(u)). snd2(z) = tquot(f st2(z). z)) and its inverses f st3(u) = f st2(u).. whereas for all other sequences s ∈ N.8) and whenever s = [a1 . . . . + 2ak +1 ). the sequence seq([0]) = 1. snd3(u). . y)) = x snd2(pair(x. . ak ])) (5.7) For the empty sequence ε. f st2(z) for any natural z is the exponent of the largest power of 2 that divides z + 1.6) (5. and seq([0. ak ]) = cons(a1 . z)) = a tl(cons(a.e. ak ] for k > 0. . y. . z)) = y thd3(triple(x. we have seq(ε) = 0. . . pair : N × N → N with pair(m. ak ]). snd2 : N → N which satisfy the equations pair(f st2(z).10) (5. which may be equivalently expressed as 1 less than the smallest power of 2 that does not divide z + 1. . . Hence f st2(z) = µx < (z + 2)[2x ∤ (z + 1)] − 1 which is clearly primitive recursive.
n)) = β(J(m. .¨ 5. Notation. Proof: Any program P = I1 . includeing P  = k which can be determined as follows. Conversely. Compute each of the indices and then eﬀectively compute k. p)) = to code them up modulo 4. n − 1) + 2 4. We use the superscript (n) denote arity. .4 G¨del Numbering of Programs o Theorem 5. Since γ is obtained only through the composition of bijective functions(which have inverses) we have γ −1 also exists and is primitive recursive . Let i = µx[2x+1 ∤ P + 1] then i = a1 + a2 + . These operations are all primitive recursive. it is possible to decode the instruction I primitive recursively by ﬁrst determining the opcode (x mod 4) and then depending upon the opcode it is possible to determine the parameters.. GODEL NUMBERS OF URM INSTRUCTIONS 51 5.3 P=collection of all URM programs is eﬀectively denumerable.3.ak + k. . Proof: We use the opcodes of the instructions such that β(Z(n)) = β(S(n)) = β(C(m.. 2 5. β(Ik )] . . where o all the functions used are bijective and primitive recursive. for any x ∈ N.. n...3 G¨del Numbers of URM Instructions o Theorem 5.pair(m − 1. n − 1.2 The set of instructions of the URM is eﬀectively denumerable.triple(m − 1. p − 1) + 3 Hence every instruction I has a unique code given by β(I). Let P ART REC be partitioned by arity P ART REC = n>0 2 P ART REC (n) where each f (n) ∈ P ART REC (n) : Nn − →N. Consider the function β 4(n − 1) + 0 4(n − 1) + 1 4. Ik has a G¨del number given by seq[β(I1 ). .
. with repetitions.52 Theorem 5. CODING AND GODELIZATION . ..4 The set P ART REC (n)1 Proof: Consider the enumeration Q0 (n) ¨ CHAPTER 5.. Q2 (n) .f (m)) 2 (n) (n) (n) (n) (n) (n) 1 P ART REC (n) is clearly inﬁnite since P RIM REC (n) ⊆ P ART REC (n) is inﬁnite .. We now construct an enumeration without repetitions as follows. . f (0) = 0 f (m + 1) = µz[Qz = Qf (0) ∧ Qz = Qf (1) ∧ . .. Q1 (n) .. Qz = Qf (m) ] which clearly exists as a function and provides an enumeration since f (m + 1) is a function(diﬀerent from each of f (0).
Are there partial recursive functions that are total but not primitive recursive? If so.g. 1. If the answer to the above question is negative.1 Introduction So far we have seen that the URM has the power of partial recursive functions. Two questions naturally arise from the material presented so far.). In other words. Does unbounded minimalization yield genuine computational power that goes beyond primitive recursion. Is there a machine that exactly characterises the primitive recursive functions? 53 . then we might ask whether it is possible to get rid of undeﬁnedness completely by eliminating nontermination from URM programs. Put diﬀerently.Chapter 6 The Hierarchy of Primitive Recursive Functions 6. subtraction of a larger number from a smaller number should be undeﬁned etc. We leave it to the reader as an exercise to deﬁne partial recursive versions of functions like subtraction and division which conform to normal mathematical convention (e. division by 0 should be undeﬁned. We have already seen that the primitive recursive functions are total. In many cases such as subtraction and division we have made them total by adopting conventions which at best may be considered unconventional. 2. This might give the reader the feeling that the diﬀerence between the primitive recursive functions and the URM might only be in the question of being able to program undeﬁnedness by nonterminating programs. then unbounded minimalization does yield genuine computational power.
The instruction set of this machine is summarised in the table below. In this section we introduce a more structured construct for URM programs that directly reﬂects the the nature of primitive recursion. it was recognized that such arbitrary transfers of control in any programming language led to serious diﬃculty in “debugging” faulty programs. in the 1970s. n) 3 L(m) 4 E semantics Rn := 0 Rn :=!Rn + 1 Rn :=!Rm Verbal description Clear register Rn Increment the contents of register Rn Copy the contents of register Rm into Rn Execute !Rm times the following instructions upto the matching E. 6. n. In the following sections we answer both these questions. . The sequence of instructions between L(m) and E (called the loop body) is executed !Rm times. One of the instructions of the URM machine which makes it powerful in many ways including that of leading to nontermination is the jump instruction J(m. .) instruction in a program is followed by a matching occurrence of E. In fact. made all programs (except the trivial ones) completely incomprehensible even to the authors of the programs and more importantly made reasoning about the behaviours of programs an almost impossible task. opcode instruction 0 Z(n) 1 S(n) 2 C(m. Let the new machine be called URM–. p). 2. THE HIERARCHY OF PRIMITIVE RECURSIVE FUNCTIONS The answer to this question has a direct bearing on the relative power of machines and it might enable us to construct and program machines which yield only total functions.2 URM–: A Restricted Machine for Primitive Recursion While we have shown that primitive recursion is URMcomputable. Each occurrence of the L(. In fact. we have not explored the possibility of restricting the instruction set of the URM so as to characterize the primitive recursive functions. .54 CHAPTER 6. End of the code to be repeated The two instructions L(m) and E (which stand for “Loop” and “End”) satisfy the following conditions 1. short of actually manually executing the programs it was impossible to make any except the most trite statements about what such programs do. The sequence is entirely skipped if Rm = 0.
LOOP1 is the class of programs containing LOOP0 and all programs with loops such that there are no loops in any of the loop bodies i. That leaves only primitive recursion. Notes. 4. On the other hand. 6.1 Every primitive recursive function can be implemented as a URM– program. either the two loops are entirely disjoint or one is entirely contained in the other.1 The class of loopfree URM– programs is LOOP0. Since there are no jump instructions. 4. Unlike the case of the URM. LOOP1 is the class of URM– programs with loops nested at most 1 deep. the class LOOPn consists of LOOPn−1 and all those programs which contain loops nested at most ndeep. The reader is encouraged to ponder over why we have put in the condition 4. 2 . Hence it suﬃces to show that generalized composition and primitive recursion may be programmed in URM–. There can be no instruction in the loop body which modifes the loop bound. 3. is redundant if we follow the convention that each E instruction matches the closest L(. clearly prohibits the E instruction preceding any L(. For any n > 0. Deﬁnition 6. Notice that condition 1.6. URM–: A RESTRICTED MACHINE FOR PRIMITIVE RECURSION 55 3. The case of generalized composition also follows the proof given for the URM. Assuming that F and G are respectively programs that implement f and g respectively. n≥0 Theorem 6. condition 6. instruction numbers are needed only for the purpose of maintaing the program counter in the execution of the machine. But in the case of nested loops. . all the loop counters must be distinct. .) instruction.) instruction that precedes it.2. Rm the loop counter and the contents of Rm is the loop bound. LOOP = LOOPn is the class of all URM– programs. the loop body of one loop may itself contain a loop. Proof: It is clear that the initial functions are all in LOOP0.e. . instruction numbers are unnecessary for the purpose of understanding and reasoning about the program. Assume h = [f pr g]. For any two loops. The two instructions L(m) and E along with the loop body form the loop.e. . Loops may be nested one within the other i. 5. we proceed almost exactly as we did in the URM machine except that the two jump instructions are replaced by L(t + 2) and E respectively. 2. 1.
e. Ack(x + 1. y) = y+1 Ack(x + 1. 2 the loop construct implements the rfold application of the body of the loop. . 1) Ack(x + 1. y)) 6.2) (6. Every URM– program terminates. 0) = 1 y + 1 if y ≤ 1 y + 2 if y > 1 A(x + 1. Ack(0. then L(m).1) (6. 0) = Ack(x.2 Every program of URM– implements a primitive recursive function. A(x + 1. In the next section we show that not all total computable functions are primitive recursive. y + 1) = Ack(x. If P and Q are URM– programs that implement primitive recursive functions. F. though the individual cases are diﬀerent).56 CHAPTER 6. y + 1) = A(x.3 A NonPrimitive Recursive Total Partial Recursive function An example of a function that is partial recursive and total is the Ackermann function which is deﬁned as follows.3. i. Proof outline: First of all notice that each of the following claims is easy to prove and taken together they prove the theorem. A(x. If F implements a primitive recursive function f and Rm is a register whose contents are not modiﬁed by F . Claim 3. THE HIERARCHY OF PRIMITIVE RECURSIVE FUNCTIONS Theorem 6.1 A Variant of the Ackermann function We consider a variation of the Ackermann function (in the sense that recursion is of the same kind. y)) A(0. So we have shown that the primitive recursive functions are exactly characterised by the class of functions that may be implemented in the URM–. y) = (6. their join P Q also implements a primitive recursive function. Claim 1. Claim 2. 6.3) It is easy to show that the above equations do deﬁne a total function and that is partial recursive. E is a program that implements f r where !Rm = r.
z) ∈ A. u. snd.y) .3 The equations 6. y). z)  z = y + 1 if y ≤ 1. Claim 1. thd which yield respectively. z) ∈ S implies z = y + 1 if y ≤ 1 and z = y + 2 otherwise. y. u) ∈ S and (x − 1. Then S(x. A NONPRIMITIVE RECURSIVE TOTAL PARTIAL RECURSIVE FUNCTION Lemma 6.y) = S(x. 4. c) = d iﬀ a = f st(d). the following holds triple1(a.3 deﬁne a unique total function. Assume that for each (x′ . 0. y ′. ⊢ Consider the lexicographic ordering <lex on ordered pairs (x. y. y. Consider any ordered pair (x. z = y + 2 otherwise}. second and third components of a triple are also primitive recursive. z) ∈ S implies z = 1.y) as the smallest suitable set containing a unique triple (x. z)). ⊣ 2 Lemma 6. 1)} and for each ordered pair of the form (0. 3. y) let S(x. the ﬁrst. For each (x.y) (x. y) = 2x (2y + 1). 1.y−1) (x. y.0) = {(x.y) denote the smallest suitable set such that there exists a triple of the form (x. S(0. y − 1.y) = {(0.u) (x − 1. y − 1) and z = S(x−1. z)} where u = S(x. We may code the triples using some coding mechanism such as triple1(x. y). triple1 is a bijective function from N3 to N.6. 0).y) . y ′) <lex (x. y) there exists S(x′ . Claim 1.4 A is a partial recursive function. triple1 is a primitive recursive function. For each (x. c.u) ∪ {(x. (x. z) ∈ S(x. S(x.y′ ) . z ′ ) ∈ S(x′ . S(x. where pair1(x. y) with x > 0 and y > 0. 3. 0. It is clear from the deﬁnition of suitable sets that for each ordered pair of the form (x. 57 Proof outline: Deﬁne a ﬁnite relation S ⊆ N × N × N to be suitable if it satisﬁes the following conditions. u).y′ ) = ∅ and such that there is a unique triple (x′ . For any a. z) = pair1(x.y−1) ∪ S(x−1. Proof: Consider the triples (x. b = snd(d) and c = thd(d) . 2. z) ∈ S(x.y) is nonempty and contains a unique triple (x. (0. (x. d ∈ N. b. The decoding functions f st. y).3. y. y) = z uniquely deﬁnes S(x. 1. Clearly then S(x. z) ∈ S. y. 2. b.16. y. y. pair1(y. z) ∈ S for x > 0 and y > 0 implies there exists u such that (x. z). y.
y −1. ci )  1 ≤ i ≤ n}). then a similar process needs to be pursued with (x−1. Similarly.z) is a divisor of v. y − 1. Using this very fact and starting from 2 < 22 we may prove by induction that pi < 22 for each i < k and then conclude that k−1 pk < 1 + i=1 22 = 1 + 22 i 1 +···+2k−1 ≤ 22 . is primitive recursive. z) in the set.y. ⊣ Claim 3. k . it follows that pk ≤ 1 + i=1 1 i pi . if y > 1 then this process needs to be pursued with (x. An earlier triple in this case is one of the form (x. u. z). z) ∈ T iﬀ divisorof (ptriple1(x. 1} which determines whether a given number is the code of a ﬁnite set. Claim 6. f s is a primitive recursive function ⊢ Since multiplication and determining the kth prime are both primitive recursive (the kth k prime can be found by bounded minimalization. Claim 5. ⊢ Just check that the number is squarefree.58 CHAPTER 6. since pk < 22 which may be proven from Euclid’s proof 1 ). For any v ∈ N. ci )  1 ≤ i ≤ n} of triples of numbers may be encoded as f s({triple1(ai . obtain the triple and check for membership of the “earlier” triples that may be needed to compute it. But having determined u (since u is unique!). . ⊣ Claim 4. z) ∈ N3 and a ﬁnite set T ⊆ N we have (x. z) belongs to the set (which merely involves checking whether ptriple1(x−1. For any (x. it follows that f s is also primitive recursive. if y = 0. For each prime divisor of v. the predicate isf s : N → {0. . p3 = 5 etc. Claim 2.u. Given any triple (x. But k−1 1 By Euclid’s proof of the inﬁnitude of primes. Any ﬁnite set T = {(ai . Similarly if x > 1. If on the other hand both x > 0 and y > 0 then it is clearly necessary to check for the presence of “earlier” triples. y. bi . Given any positive integer. p2 = 3. However.) f s(T ) = ai ∈T pai +1 for any positive integer k. bi . am } by the function where pk denotes the kth prime number (with p1 = 2. because every search is bounded by the number v. the predicate isSuitable(v) (which determines whether v is the code of a suitable set) is primitive recursive. u). u) where u is unknown and needs to be determined. it is only necessary to verify that the triple (x − 1. THE HIERARCHY OF PRIMITIVE RECURSIVE FUNCTIONS We may also code ﬁnite sets of numbers T = {a1 . if x = 0 then it is only necessary to verify that z = y + 1 or z = y + 2 according as whether y ≤ 1 or y > 1. . u. then it is only necessary to verify that z = 1. y. y. . ⊢ We outline a method of checking that is intuitively primitive recursive.z). f s(T )) .
3. Further our coding mechanisms for sets ensures that S ⊂ T implies f s(S) < f s(T ) and f s(S)f s(T ). y. This follows from the construction of the smallest suitable sets required for each pair (x.5 A(x. y. 6. y) = fx (y) . ⊣ 2 We have shown that A(x. y. A(x. ⊣ Claim 7.2 Let F = {fx  x ∈ N. even though it is not. z) which satisﬁes the equations 6. z) ∈ Sf (x. if the bound is removed we get an equivalent function that “looks” partial recursive. y) = µz[(x. Claim 8. v) deﬁned as isSuitable(v) ∧ ∃z < v[(x. y. v)]. y) = µv[R(x. z).2 The Growth of functions We ﬁrst deﬁne a family F of (interrelated) functions and then show that the function A may be expressed in terms of this family. y.3. Hence our question of whether there are total partial recursive functions that are not primitive recursive has to be answered in some more convincing manner by showing that the function cannot exist in the class P RIMREC under any circumstances or by showing that the operations that yield primitive recursive functions are inadequate in some convincing way to be used to deﬁne the function A. The predicate R(x.y) in which there is a unique triple (x.3. Deﬁnition 6. y). Many primitive recursive functions may be shown to be partial recursive. Hence these processes are all bounded and intuitively primitive recursive. In order to prove that it is not primitive recursive it does not suﬃce to simply show that it is partial recursive. y. The growth properties of A are related to the growth properties of this family of functions and eventually we will show that it is impossible for any primitive recursive function to match the growth of the function A. y) yields the code of the set S(x. A NONPRIMITIVE RECURSIVE TOTAL PARTIAL RECURSIVE FUNCTION 59 each of these processes is bounded by the value v and the checking involves merely decoding and checking for prime divisors. y) is total and partial recursive.y) ] where f (x.y) is the smallest and is contained in every other suitable set which contains the triple. Hence f (x.6. S(x. fx : N → N} be a family of functions deﬁned by the equations y + 1 if y ≤ 1 f0 (y) = y + 2 if y > 1 y fx+1 (y) = fx (1) Lemma 6. For example in each case of bounded minimalization. z) ∈ Sv ] is primitive recursive. ⊢ Firstly of all the suitable sets that contain a triple (x.
e. E. denoted f ≍ g. Proof outline: Claim 1. a concept that suﬃces for our purposes. Fk . f (x) < g(x). Theorem 6. 2.. C(1. where l1 . Fk has a nested loop depth of at most k. we may show that fk+1 ≍ Fk+1 . L(2). if f (x) < g(x) almost everywhere. ⊣ y+1 y Claim 3. 1. i. Assume for some k ≥ 1. k Claim 5. Claim 2. Fk+1 has a depth of at most k + 1. Hence fk+1 ∈≍ LOOPk+1. 2). Further since fk ≍ Fk . mk + 1). y ≤ z implies f0 (y) ≤ f0 (z). f ∈≍ F if there exists a function g ∈ F such that f ≍ g. f asymptotically approximates g. C(3. ′ Let ρ(Fk ) = mk and let Fk = Fk [l1 . ⊢ By induction on n. S(1).60 CHAPTER 6. . Clearly since Fk ∈ LOOPk . 1). if f (x) = g(x) almost everywhere. lmk are chosen so as not to interfere with any of the parameters or intermediate registers that may be required. where LOOPn is the class of URM– programs with depth of nesting at most n. there exists x0 such that for all x > x0 . g majorizes f denoted by f ≺ g or g ≻ f . Since we are primarily interested in asymptotic growth of functions we deﬁne the notion of functions being “nearly” equal. . f0 is a monotonic function i. S(3). . Claim 4. fk ∈≍ LOOPk . lmk → l1 ]. . 3. L(mk + 1). f1 (y) = 2y for all y > 0. For all n > 0.6 The following claims on the properties of fx hold. fn ∈≍ LOOPn . . Starting with n = 1 we have f1 (y) ≍ 2y which is in turn implemented by the following sequence of instructions C(1.2 ytimes for all y > 0. Given a class of functions F . Deﬁnition 6. f0 (y) ≥ k .e. fx+1 (y + 1) = fx (1) = fx (fx (1)) = fx (fx+1 (y)). . THE HIERARCHY OF PRIMITIVE RECURSIVE FUNCTIONS 2 Proof outline: By double induction on x and y. . . We y have fk+1 (y) = fk (1). Now consider the program Fk+1 deﬁned by the sequence of instructions ′ C(1. The ﬁrst few functions in F are as follows. f3 (y) = 22 . That is there exists program Fk ∈ LOOPk such that fk ≍ φFk . f2 (y) = 2y for all y > 0. E. g : N → N be total unary functions. 3).3 Let f. .
for y = 0 the claim holds. since both sides of the inequality yield 1. ⊢ The proof is not by induction. For k = 0 it is clear. fn+1 (y +1) = fn (fn+1 (y)).e fk+1 (m) ≥ m + 1 for some m ≥ 0 we have fk+1 (m + 1) = fk (fk+1 (m)) > fk+1 (m) ≥ m + 1. fn (y + 1) > fn (y) for each n. Assuming fk+1 (m) > m i. fn (y) ≥ 2fn (y) = 2y = fn (y) + y. ⊣ Claim 7. Assuming the result is true for some k ≥ 0. Similarly fn (y) ≥ 2fn (y) = k k k fn (y) + fn (y) ≥ fn (y) + y. Then fk+1 (y) > y is proven by induction on y. fn is an increasing function of y. f1 (y) ≥ 2k y. ⊢ It is easily veriﬁed for n = 0.3. 61 ⊣ Claim 6. f1 (y) = y ≥ 20 . fn (y) ≥ fn (y) + x 1 0 0 k+1 k ⊢ By induction on k.2k x = 2k+1 x. For n = 0 it is obvious since f0 (y) ≥ y + 1 always. For k > 0 we have 2fn (y) = 2fn (fn (y)) ≤ k+1 k+2 fn (fn (y)) = fn (y). fn (y) ≥ 2fn (y) k+1 k ⊢ By induction on k. ⊣ 2 . fn+1 (y) ≥ fn (y) for all n and x. ⊣ k+1 k Claim 9. ⊣ k+1 k Claim 11. fn (y) > fn (y) k+1 k k ⊢ fn (y) = fn (fn (y)) > fn (y). fn (y) > y i. we have fk+1 (y+1) = fk (fk+1 (y)) > fk+1 (y) ⊣ Claim 8. For y = 0 we have fk+1 (0) = 0 fk (1) = 1 > 0 = y. For y > 0 we have for any n. ⊣ k+1 k Claim 10. Assume fk (y) > y for some k ≥ 0. ⊣ k Claim 12.e. k+1 0 k k ⊢ For k = 0. However. Since fn+1 (y) > y we have fn+1 (y) ≥ y + 1 and further since fn (y + 1) > fn (y) we have fn+1 (y + 1) = fn (fn+1 (y)) ≥ fn (y + 1).6. f0 (y) = y ≥ 0 and f0 (y) = f0 (f0 (y)) ≥ f0 (y) + 1 ≥ k + 1. ⊢ By induction on n.y and for k + 1 we have f1 (y) = f1 (f1 (y)) = 2f1 (y) ≥ 2. A NONPRIMITIVE RECURSIVE TOTAL PARTIAL RECURSIVE FUNCTION k+1 0 k k ⊢ By induction on k.
Since all URM– programs are terminating. but as we shall see it is easier to compute running time in terms of the atomic statements executed. we have f0 (y) = y + 2k. Hence for any input x . For n = 0. k. k Proof outline: By double induction on n. Assume for some n > 0.8 For any constant c and all n. Moreover our theory of asymptotic growth of functions does not get seriously aﬀected by either deﬁnition. Assume that for 0 some n > 0 and all k. • Choose a register Rm with m > max(k. TQ ( x ) ≤ fn−1 (max( x )). its running time on any input x is deﬁned as the total number of executions of atomic instructions2 in P . we have φTP ( x ) ≤ c ≤ ⇀ c f0 (max( x )). Hence f1 ≻ f0 . fn ≻ fn−1 . THE HIERARCHY OF PRIMITIVE RECURSIVE FUNCTIONS k Theorem 6. 2 We could equally well have deﬁned the running time as the number of changes in conﬁguration. Hence 0 fn+1 ≻ fn . we have 2y > y + 2k. Clearly for all y > 2k. . there exists k ≥ 0 ⇀ ⇀ ⇀ k such that TP ( x ) ≤ fn (max( x )) for every x . k. We then have the following important theorem. fn+1 ≻ fn . fn+1 ≻ c. • To every atomic instruction. Theorem 6. We would like to observe that the running time of any program P may be easily calculated by a URM– program TP by the following procedure. For n = 0. we know fn+1 (y) > y = fn (y) for all y. for all y ≥ 2 k and f1 (y) = 2y.fn .9 (The Bounding theorem) For all n ≥ 0 and P ∈ LOOPn. For k = 0. Proof: By induction on n. Suppose P ∈ LOOPn and let max( x ) = u. ρ(P )). for each Q ∈ LOOPn−1 there exists a constant kn−1 such that for all ⇀ ⇀ ⇀ ⇀ kn−1 x .4 For any program URM– program P .7 For all n. where k si the length of the input. k. Assume 2 k Corollary 6.62 CHAPTER 6. we deﬁne a concept of running time of programs. • At the end of the program append a new instruction C(m. 1) ⇀ Clearly the program TP for any input x computes the running time of P . We then have the following cases. there are no loops in P and hence P consists of only ⇀ ⇀ a constant number c of atomic instructions. ⇀ Deﬁnition 6. Also TP has the same depth of nesting as P . add a new instruction S(m).
it follows after the execution of Q whose running time is bounded by fn−1 (u). L(m). kS ). E. R. where R ∈ LOOPn−1 and ⇀ kR hence φTR ( x ) ≤ fn−1 (u) for some constant kR . While each of the function fn is primitive recursive. . Since n > 0 there exists at least one looping construct in P which is of the form L(m). kR kS Q u + fn−1 (u) + v. by the induction hypothesis. ⊣ We may argue similarly with the rest of the code in P to conclude that every register has a value bounded above. since fn ∈ LOOPn . y) grows faster than fn (1) for any ﬁxed n and k. where Q and S are in LOOPn−1. no register can possibly contain a value greater than the sum of its initial value and the running time of Q. However the function A(x. This gives us the result that ⇀ φTP ( x ) ≤ ≤ ≤ ≺ where kn−1 > max(kQ + 1.fn−1 (u) + fn−1 (u) kQ +1 kR kS fn−1 (u) + v. A NONPRIMITIVE RECURSIVE TOTAL PARTIAL RECURSIVE FUNCTION 63 Case P ∈ LOOPn−1. there exist constants kQ and kS ⇀ kQ such that φTQ ( x ) ≤ fn−1 (u). kR . For simplicity assume P is made up by joining the programs Q. Then by the induction hypothesis and the previous theorem we have ⇀ kn−1 k φTP ( x ) ≤ fn−1 (u) ≤ fn n−1 (u).6. the function A outstrips them all and hence is not primitive recursive. E and S. We proceed by induction on the structure of P . This implies that values produced by primitive recursive functions cannot grow faster than the bounds imposed on them k by the bounding theorem.3.fn−1 (u) + fn−1 (u) kn−1 u + (v + 2). R. The value in any register after Q has been executed is bounded above by u + fn−1(u). Case P ∈ LOOPn−1. Further Q Claim 1. Assume !Rm = v and since Q and S are in LOOPn−1. k ⊢ Since each atomic statement increases the maximum of the values contained in all registers kQ by at most 1.fn−1 (u) k fn n (u) k 2 Hence the value in register R1 in any URM– program can be a priori bound by the sum of the initial value in the register and the running time of the program.
64 CHAPTER 6. THE HIERARCHY OF PRIMITIVE RECURSIVE FUNCTIONS .
is an enumeration of P ART REC (1) : Consider the total function f : N → N. 65 (1) (1) (1) (1) (1) . f (n) = Qn (n) + 1 if Qn (n) ↓ . Since every computable function has an inﬁnite number of programs that implement it. Ra respectively when n = 1. = fPa (n) (n) (n) (a) (n) Da = the domain of φa . 4. Q1 .. is an enumeration of unary computable functions with repetitions. Da . Q2 . the enumeration Q0 ... The above are abbreviated to φa . 0 otherwise. o 2. Q2 .. Q1 .. Proof: Assume Q0 . For any a ∈ N and n ≥ 1 φa = the nary function computed by Pa . Pa denotes the URM program with g¨del number a. (n) Theorem 7. 3.1 There is a total unary function that is not computable..Chapter 7 Universality and Parametrisation Notation 1. Ra = the range of φa .
y) i.e ga ≃ λy[f (a. y)] Then clearly since f is computable ga is also computable and in fact there is a program Pa for each a ∈ N which computes f (a. f : N− →N f :N→N PARTREC(1) PRIMREC(1) 7. y) ≃ Qh(x) (y) .66 CHAPTER 7. let F computes f . f (n) is total. Hence f (n) is not computable 2 The following is the picture of computable functions that we have. 2 . UNIVERSALITY AND PARAMETRISATION Claim 1. Then there exists a total computable function (1) h : N → N such that f (x.2 Let f : N ×N− →N be computable. Claim 2.1 The Parametrisation theorem (Simpliﬁed form) Assume f : N × N− →N is computable (∈ P ART REC (2) ) for each ﬁxed value a ∈ N. We may deﬁne a unary function ga : N− →N such that ∀y ∈ N : ga (y) = f (a. Proof: We need to construct a program Qa for each a which computes f (a. f (n) is the diﬀerent from every function in the enumeration of computable functions. y) for each y. y) for any given a Theorem 7.
. y) . Qh(n) (y) is deﬁned iﬀ n/y iﬀ y is in the range of Qh(n) theref ore Dom (Qh(n) (y) = {nii ∈ N} = nN = Range Qh(n) (y) The generalized Smn theorem ⇀ m For each m. Let f (x. 2) Z(1) S(1) . For a = a.7. Hence Qk(a) (y) = f (a. µz[x. y) = y x . . y) = 0 = y y ← x/y x = 0. Let k(a) = Qa = γ(Qa ) Since F is ﬁxed and is a .z = y] x = 0. y) = ⊥ x = 0.times eﬀectively computable. y = 0 ⇒ f (x. y = 0 ⇒ f (x. such that for each ﬁxed n. y) = 0 = y x = 0. n ≥ 1 . Qa diﬀers from Qa′ only in this part Examples 1. Then f is computable since f (x.1. h(n) is the Godel number of the program that computes y n. ⊥ otherwise. S(1) F Initial state of F Where F computes f . there is total computable (m + 1)ary function sn (e. R1 a R2 y 0 .. Let f (x. . k is eﬀectively computable. By the s−m−n theorem there is a total computable function h : N → N such that for any ﬁxed n ∈ N. y = 0 ⇒ f (x. y) = y if x/y. x ) such that .. 67 Initial state of Qa Qa : C(1. 2. . y = 0 ⇒ f (x.. y) = x.. y) = ⊥←x∤y Then there is a total computable function h : N → N. THE PARAMETRISATION THEOREM (SIMPLIFIED FORM) R1 y 0 .
xn ) ≃ Qe (x1 ... x1 ) ..2 Universal functions and Programs Deﬁnition 7. Is ψu a computable functions ? Theorem 7. y ...1 The universal function for nary computable functions is the (n+1)ary function ψu (e... . xm Rm+1 y1 . Rm . xn ) Question. m + 2) C(1. C(m. . . S(i) Given xtimes y1 R1 to be transformed to .. the universal function ψu (n) (n) (n) (n) is computable.3 For each n ≥ 1. UNIVERSALITY AND PARAMETRISATION ⇀ ⇀ (x.. C(2. . ... .68 Qe (m+n) CHAPTER 7. Since this code contains no jumps. m + n) . x ) is n eﬀectively computable. . we use the following code C(n.. yn Rn 0 . m + 1) Q(1. y ) = Q ⇀ ⇀ ⇀ ⇀) ( y ) for all x . x1 .. Rm+n yn 0 . R1 x1 . . x) be the subroutine for given values of i and x this is a primitive recursive function 2 Z(i) S(i) . x n Proof: Let Q(i.. sm (e.. xm ) Pe From this deﬁnition and the eﬀectiveness of −1 and ⇀ it follows that sm (e. . it is primitive recursive 7.. .
) ) ) Same target for Z and S instructions e = 2a1 (1 + 2a2+1 (1 + 2a3+1 (..7. n + 6. the required value of Qe ( x ) will be in R1 . The current state of any computation is given by σ = π(c. −1 τ−1 (e) = (e + 1)/2a1 . given a number e.))) − 1 a1 = µz1 ≤ e[2z1 +1 ∤ e] . decode the program Pe and mimic the computation of Pe step by step by writing down the conﬁguration of the registers and the next (n) ⇀ instruction to be executed. j) with −1 c = π1 (ρ) −1 j = π2 (ρ). n + 7.(1 + 2ar+1 ). where j is the serial number of the next instruction to be executed . J(n + 9.. 1 j = 0 if the computation is to be stopped. n + 5. tl(e) = −1 τ−1 (e) −1 2 . Conﬁguration: The registers are coded by c= i≤1 piri where !Ri = ri and pi is the i − th prime number. length of Pe + 1 remember to set redundant argument to 0.. If and when this computation stops. . J(n + 9. . After decoding the arguments J(n + 9.. UNIVERSAL FUNCTIONS AND PROGRAMS 69 Proof outline: Assume a ﬁxed n > 0.2. Convention. n + 12 n n+1 n+2 n+3 n+4 n+5 n+6 n+7 n+8 n+9 ⇀ x e 1 c◦ 0 1 2 3 opcode Serial number of next instr to be executed current conﬁguration of Pe . Y x pi i Initially i≥1 opcode + arguments of the instruction to be executed required to check whether execution of Pe has to halt.
i) = CHAPTER 7.70 a2 = µz2 ≤ e[2z2 +1 ∤ tl(e)] a3 = µz3 ≤ e[2z3 +1 ∤ tl2 (e)] .. x ...))) − 1 = e. x ) = c1 (e.. put the opcode in Rn+6 . Rn+5 ← decode(n + 2) — decode the instruction whose serial number is stored in Rn+2 β −1 — gives various opcodes and registers to Rn+3 ← execute(n + 5) while decoding. t) = { conﬁguration ofter t. Rn+1 set Rn+2 ← 1.. i) = hd(tli−1 (e)) ⇀ ⇀ ⇀ ⇀ (n) ψU (e.step of execution ⇀ ⇀ ⇀ f inalconf (e. ak ] for k ≥ 2. 0) to the end of the program if Pe has to halt. e in the registers R1 . t) = 0]) ⇀ conf (e..(1 + 2ak +1 ). x . Rn+9 2 Lemma 7. . UNIVERSALITY AND PARAMETRISATION hd(e) = µz ≤ e [ 22+1 ∤ e ] for 1 ≤ i ≤ r ith (e. ai = µzi ≤ e[2zi +1 ∤ tli−1 (e)] therefore n − th(e. . x .... Then the following functions are primitive recursive (i) hd(e) = a1 for the k ≥ 1 (ii) tl(e) = τ [a2 . . . x ) = execute(e. µt[next(e. x . ⇀ Rn+3 ← c( x ) = i≥1 pixi Rn+4 ← len(P e) S(n + 4) J(n + 2. x ) = conf (e. and the arguments in Rn+7 . such that τ [a1 . Rn+8 . n + 4. . t) = 0]) ⇀ Assume given x . x .4 Let τ : N+ → N be the coding on nonempty sequences. . . µt[next(e.. ak ] = 2a1 (1 + 2a2 +1 (1 + 2a3 +1 (. . .
... ak ] + 1)2a1 −1 ) if k > 1.. for k ≥ 1 71 Proof: (i) Consider e = 2a1 (1 + 2a2 +1 (1 + 2a3 +1 (.. ..(1 + 2ak +1 ). ak ] = (2τ [a2 . then is a single element sequence 2 ispwr2(x)= 0 ← x = 0 len(e) = µk ≤ (e + 1)[ispwrof 2(tlk (e + 1))] for all e ≥ 0.... ak ] = τ [ak . . e + 1 > 0 and has at least one nonzero bit in its representation. for all single element sequences [a] τ [a] = 2a − 1 τ◦ [a] = 2a hd[a] = a. ak ] + 1. Hence for any e ≥ 0 if e + 1 is a power of 2..7.. e = (2 e′ + 1)2a1 − 1 theref ore e+1 = 2e′ − 1 a1 2 (e+1) 2a1 ∃ z ≤ x[2z = x] −1 = theref ore e = ′ 2 (e + 1) − 2a1 (e + 1) − 2hd(e) = 2a1 +1 2hd(e)+1 len(e)µk ≤ e + 1 [tlk (e) = 0] .. .2.... we have hd(e) = νz ≤ e + 1[2z (e + 1)] = a1 (ii) Since all sequences are nonempty consider the coding τ◦ : N⋆ → N deﬁned also for empty sequences with τ◦ [ ] = 0 and τ ◦ [ak . 2a1 − 1 if k = 1 τ [a1 . .. UNIVERSAL FUNCTIONS AND PROGRAMS (iii) len(e) = k.))) − 1. Clearly e + 1 has at least one nonzero bit in its representation and e + 1 ≥ 1.
....)) 2 .(1 + 2ar+1 ).(1 + 2ar+1 ). Ir ] e = τ [I1 .. β(Ii ) − trm(β(Ii ).(1 + 2ar+1 ). 4).))) − 1 e+1 = 1 + 2a2 (1 + 2a3+1 (..)) 2a1 e+1 − 1 = 2a2 (1 + 2a3+1 (........... . UNIVERSALITY AND PARAMETRISATION s= j≥1 where rj =!Rj c = π(s...(1 + 2ar+1 )..(1 + 2ar+1 ).. 4) 4 Depending upon 0i ﬁll up Pe = [I1 ....)))−1 hd(e) = a1 tl(e) = 2a2 (1 + 2a3+1 (....))) − 1 τ [0] = 20 − 1 = 0 e = 2a1 (1 + 2a2+1 (1 + 2a3+1 (.)) 2a1 ( e+1 − 1) 2a1 = 2a2 (1 + 2a3+1 (.72 CHAPTER 7. .. i) Length of Pe current conﬁguration current state serial no of next instruction of Pe to be executed opcode of Ii arguments r(P e) opcodes ⇀ x e r 0 1 2 3 c s i β(Ii ) oi reg1 reg2 reg3 n+1 n+2 −1 π1 (c) −1 π2 (c) = trm(β(Ii )..(1 + 2ar+1 )..Ir ] = 2a1 (1 + 2a2+1 (1 + 2a3+1 (.
7.)) 2a1 +1 2 2(e + 1) − 1 = 2a2 (1 + 2a3+1 (. c) = c′ which is primitive recursive π(s... i′ ) if i ≤ len(e) i + 1 if opcode (i) < 3 where c′ = ′′ −1 i if opcode (i) = 3 and π2 (i) = i′′ s rj if opcode (i) = 0 and ﬁrst (i) = j pj sp if opcode (i) = 1 and ﬁrst (i) = j j rj and s′ = spk if opcode (i) = 2 and ﬁrst (i) = j r k p k and second (i) = k s if opcode (i) = 3 where rj = νj ≤ s[pj s] j . e.(1 + 2ar+1 ). UNIVERSAL FUNCTIONS AND PROGRAMS e+1 1 − = 2a2 (1 + 2a3+1 (. j) then we may deﬁne the function ⇀ move( x . 0) if i > len(e) or i = 0 where i′ = π(s′ ..2.(1 + 2ar+1 ).. the program Pe is in some conﬁguration o c = π(s....)) a1 +1 2 2(e + 1) − 1 − 1 = tl(e) 2a1 +1 73 Universal Programs : Summary ⇀ Assume for any arguments x and G¨del number e..
UNIVERSALITY AND PARAMETRISATION We may the deﬁne the function ⇀ Steps ( x . e. e. e. c. t + 1) = move( x . t)) and ﬁnally we may deﬁne for any conﬁguration c.74 rk = νk ≤ s[pk s] k CHAPTER 7. state(c) = π1 −1 (c) −1 nextinstr(c) = π2 (c) output(c) = νk ≤ c[pk state(c)] 1 . c. 0) = c ⇀ ⇀ ⇀ steps ( x . step( x . e. c.
7. e.e. Qr(p) is a partial recursive function i. e) = output(cf ) ⇀ ⇀ where cf = steps( x . UNIVERSAL FUNCTIONS AND PROGRAMS and ⇀ execute( x . and there exists a URM program Pf which computes f . µt[nextinstr(steps( x . c0 .5 For any URM program P and inputs x with  x  = n ≥ 1 . URM (n) = P ART REC (N ) Undecidability : The Hallting Program 1 if Qx (y) ↓ Theorem 7.rec function ⇀ ⇀ (n) Corollary 7. If halt is computable then so is the function f (x) = halt(x. Z(m + 1) p + 2.let Pf ′ :: Pf p + 1.(equivalently partial recursive) Proof: By contradication. J(1. f′ = 0 if f (x) = 0 ⊥ if f (x) = 1 1 whether program x halts on input x .y) is not URMcomputable. c0 . 0 otherwise. Now consider he program P ′ f constructed as follows.y)= is undecidable i.6 The predicate “ programs x halts on input y ” deﬁned by halt(x. its characteristic function halt(x.2.e for any n ≥ 1 . e. m + 1. S(m + 1) p + 3. x)1 . p + 3) m = ρ(Pf ) and Pf consist of p instructions what does P ′ f computes ? It computes the function. t)) = 0]) 75 This function is not prim.rec it is however partial recursive since it is an unbounded minimization of a prim.
y) = 1 PROGRAM y HALTS ON INPUT y IFF PROGRAM y DOES NOT HALT ON INPUT y. y) = 0 Let r(P ′f ) = y. Then f ′ (y) = ⊥ if f (y) = 1 ⇔ halt(y. 2 .76 CHAPTER 7. UNIVERSALITY AND PARAMETRISATION 0 if f (y) = 0 ⇔ halt(y.
However we have internalised them to such a large extent that we seldom make the distinction between numbers and their representation. But in reality. numbers have always been conceptual rather than concrete. Clearly therefore. The interpretation of these (sequences of) symbols as numbers and operations on numbers leads us to believe that we are computing with numbers. However. lines. mensuration. These calculi are important for several reasons. the question of using and manipulating pure symbols (or pure symbols in conjunction with quantities) is an important aspect of computing and hence needs to be addressed for its computational power. The notion of a calculus itself recognizes (uninterpreted) symbol manipulation and processing as its main feature. 1. 77 .e. High school mathematics subjects like trigonometry. These calculi form the basis for modern functional programming languages in both design and implementation and 2. throughout our school education in mathematics. the methods we have learned are really methods for manipulating representations rather than concepts themselves. In later years (in secondary school and high school) we gradually progressed to algebra (the use and manipulation of unknown or symbolic quantities) and geometry (requiring spatial reasoning invloving points. sequences of symbols which represent numbers.Chapter 8 The typefree λcalculus In the previous chapters we have studied two models of computability both of which were ﬁrmly grounded in the concept of numbers. coordinate geometry and the calculus combine spatial reasoning with algebraic reasoning. In this chapter we study two calculi — the λcalculus and combinatory logic – that are purely symbolbased and per se free of interpretations. planes and measures associated with spatial objects). This was deliberate – a notion of computability which does not involve numbers and operations on numbers would somehow be unsatisfactory. In the early years of our education in arithmetic we have dealt mainly with numerals i. The arithmetic we have learnt includes algorithms and methods of computing which utilise the representation of numbers instead of numbers themselves. They may be regarded as pure symbolprocessing. historically these calculi predate other models of computation.
L ::=   x Variable λx[L] λabstraction (L L) λapplication Precedence and Associativity conventions 1. λxy[L] denotes λx[λy[L]] Free and bound variables V (x) = {x} V (λx[L]) = V (L) ∪ {x} F V (x) = {x} F V (λx[L]) = F V (L) {x} V ((LM)) = V (L) ∪ V (M) F V ((L M)) = F V (L) ∪ F V (M) BV (L) = V (L) − F V (L) The metaoperation of substitution(to ensure no “capture of freevariables”) x{N/x} ≡ N (L M){N/x} ≡ (L{N/x} M{N/x}) y{N/x} ≡ y .e.78 CHAPTER 8. where V is a countably inﬁnite collection of variables. (L1 L2 L3 ) denotes ((L1 L2 ) L3 ) i. y ∈ V . THE TYPEFREE λCALCULUS Syntax. application is left associative 2. x.
79 (λx[L]){N/x} ≡ λx[L] (λy[L]){N/x} ≡ λy[L{N/x}] y=x & y ∈ F V (N) (λy[L]){N/x} ≡ λz[L{Z/y}{N/x}] y=x & y ∈ F V (N) & z ∈ F V (L) ∪ F V (N) α. η conversion λx[L] −→α λy[L{y/x}]. Verify that the above rules do not lead to capture of free variables. y ∈ F V (L) (λx[L] M) −→β L{M/x} RENAMING BOUND VARIABLES FUNCTIONAL CALL REPLACEMENT OF PARAMETERS(FORMAL) BY ARGUMENTS (ACTUAL) λx[(L x)] −→η L EXTENSIONALITY Closure of conversions under any context −→λ denotes −→α . β. −→β . −→η L −→λ L′ (L M) −→λ (L′ M) M −→λ M ′ (L M) −→λ (L M ′ ) L −→λ L′ λx[L] −→λ λx[L′ ] Question. −→⋆ = λ n≥0 −→η λ where L −→◦ M if L ≡ M λ L −→k+1 M if ∃N : L −→k N −→λ M λ λ .
. Assume two distinguished symbols S and K The language of CL(combinator) is expressions generated by the grammar C ::= S K  (C C) x ↑ application is left associative A combinator(C0 ::= KSC0 C0 ) is term containing only S and K and no other variables. THE TYPEFREE λCALCULUS λEquality =λ =λ is the least relation such that L =λ M if L →⋆ M λ L =λ M if M =λ L L =λ M if L =λ N and N =λ M.1941 Kleene 1935. f. The language of λ is generated by the grammer L ::= x  λx[L]  (L L) Λ0 is the collection of closed λterms are combined Λ ⊇ Λ0 is the language. z.1936. g1... Rosser 1935 Assume an inﬁnite collection of variables symbols x.80 CHAPTER 8. Combinatory logic & λcalculus Schonﬁnkel 1924 Turing 1937 post 1936 Godel 1931 presented in 1934. y. Church 1933.1936.
81 S L M N −→W ((L N)(M N)) K L M −→W L S stand for stong composition −→W stand for week contracion K stand for constant {M/x}x ≡ M {M/x}(L N) ≡ ({M/x} L {M/x}N) (λx[L]M) −→β {M/x}L S = λ x y z [((x z)(y z))] K = λ x y [x] df df {M/x}x ≡ M {M/x}y ≡ y {M/x}λ x [L] ≡ λ x [L] {M/x}λ y[L] ≡ λ y [{M/x}L] {M/x}(L M) ≡ ({M/x} L {M/x}M) .
THE TYPEFREE λCALCULUS Example. Consider a new combinator B (for composition) BLMN = (L(MN)) Deﬁne B ≡ S(KS)K. Deﬁne the commutation operator which commutes two arguments CX Y Z = X Z Y Deﬁne C = S(B B S)(KK) Then C X Y Z ≡ S (B B S) (K K)X Y Z −→W B B S X(K K X)Y Z −→W B B S X K Y Z 1 −→W B (S X) K Y Z 1 This is not a relex if you parenthesize it complete .82 CHAPTER 8. BLM N ≡ S(K S) K L M N −→W K S L(K L) M N −→W S(K L) M N −→W K L N(M N) −→W L (M N) df Example.
Great Britain. Academic Press. Languages and Computation. Computability: An Introduction to Recursive Function Theory. 1980. Computability and Unsolvability.. [4] Cutland N. [2] Davis M. Computability. 1982. AddisonWesley. Complexity and Languages. [3] Davis M and Weyukar E. New York. New York. Automata. New York. Cambridge.Bibliography [1] Hopcroft J and Ullman J D. Dover Publications Inc. 1983. 1983. CUP. 83 .
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue reading from where you left off, or restart the preview.