Page 71
Page 71
Recursive Sets
For this section, a set means a subset of Nn , where usually n = 1. Thus formally a set is the
same thing as a relation, which is the same as a total 0-1 valued function. Thus if A ⊆ Nn ,
then we write
0 if ~x ∈ A
A(~x) =
1 otherwise
NOTE: The terms “recursive” and “computable” are interchangeable in this section, whether
they are applied to functions or sets. This makes sense, since we proved that the computable
functions are the same as the recursive functions (see the theorem on page 61 and the
corollary to the Kleene Normal Form Theorem on page 69).
By Church’s thesis, a set A is recursive iff there is an algorithm which, given ~x, determines
whether ~x ∈ A. (The algorithm must halt on all inputs.)
Proof: This is the same as saying that the class of recursive n-ary relations is closed under
the Boolean operations ∧, ∨, ¬ (see Lemma, page 62).
Note that the assumption that f is total is necessary in the above proposition, since by
definition a recursive relation must be a total 0-1 valued function.
We are interested in proving that certain sets are not recursive. The standard example is
the diagonal halting set K.
Recall that {x}1 is the unary function computed by the program (coded by) x (see page 68).
Thus
0 (true) if program x halts on input x
K(x) =
1 (false) otherwise
71
Note that K is a version of the famous “halting problem”, originally formulated by Alan
Turing in the context of Turing machines.
Proof: The proof is a combination of a “diagonal argument” and a reduction. First the
diagonal argument.
Recall (page 69) that φn (x) = {n}1 (x) for n = 0, 1, 2, ... That is, φn is the (partial) function of
one variable computed by program {n}. Thus φ0 , φ1 , ... is an enumeration of all computable
functions of one variable. We can list all values of all these functions in an infinite table,
whose n-th row is a list of the successive values φn (0), φn (1), ... of the function φn . We now
define a “diagonal function” D(x) by making D(n) defined iff φn (n) is undefined. That is,
0 if x 6∈ K
D(x) =
∞ if x ∈ K
The list of values of D(0), D(1), ... can be obtained by going down the main diagonal of the
above table and changing each ∞ to 0 and changing each defined value to ∞. Thus it is
clear that this list of values cannot coincide completely with any row in the table, because
the n-th value in the list disagrees with the n-th row at position n. It follows that D is not
a computable function.
i.e. {e}1 (e) is defined iff {e}1 (e) is not defined, a contradiction. Hence D is not computable.
Now comes the reduction: We can reduce the computation of D to the computation of K, so
that if K is computable then D is computable. But we just showed that D is not computable,
so K is not computable.
Corollary: Let f (x) = µyT (x, x, y). Then f is a (partial) computable function which has
no extension to a total computable function. That is, there is no total computable function
g(x) such that g(x) = f (x) for each x such that f (x) 6= ∞.
Reducibility
Definition: Suppose A, B ⊆ N. Then A ≤m B (A is many-one reducible to B) iff there is
a total recursive function f : N → N, such that x ∈ A ⇔ f (x) ∈ B, for all x ∈ N.
72
Note that ≤m is similar to the notion of ≤p of polynomial time reducibility. The difference
is that for the latter we require that the function f be polynomial time computable.
Example: Let H = {x | {x}1 (0) 6= ∞} Thus x ∈ H iff program {x} halts when all registers
are initially 0.
What is the program {f (x)}? Program {f (x)} on any input y simulates program {x} on
input x.
From the point of view of the program {f (x)}, x is a constant; say x = x0 . The program
{f (x0 )} is simply
R1 ← x0 , {x0 }0
where the first command is an abbreviation for the sequence of x0 + 1 commands
R1 ← 0, R1 ← R1 + 1, · · · , R1 ← R1 + 1
Thus program {f (x0 )} initializes R1 to x0 , and then acts like program {x0 }. Here {x0 }0
is a modified version of program {x0 }, in which every jump instruction Jijk is changed to
Ji,j,k+x0 +1 , because x0 + 1 commands have been inserted in the front of program {x0 }.
Since there is an easy algorithm that transforms x0 to the program {f (x0 )} described above,
it follows from Church’s thesis that the function f is computable (i.e. recursive).
Exercise 3 Show that f above is in fact primitive recursive. Do this by giving an explicit
definition of f (x), and use the techniques on pages 61-66.
It turns out that reductions such as the one above can be made easier by using a special
case of the so-called S-m-n theorem.
73
Intuitively this theorem tells us that if g(x, y) is computable, then for each fixed value x = x0
of the first argument, g(x0 , y) becomes a computable function gx0 (y) of y alone. The function
f (x0 ) tells us the code for the program which computes this function gx0 .
Let P be a program which computes g. Then the program {f (x0 )} expects its argument y
in register R1 , so it first copies y into R2 , and then puts the constant x0 in R1 , and executes
P . That is, the program {f (x0 )} is
R2 ← R1 , R1 ← x0 , P 0
where P 0 is P with all its jump instructions incremented by the number of commands we’ve
placed in front of it (namely by x0 + 5, since the copy macro requires 4 commands). (See
the argument above.)
We will now state the (general) so-called S-m-n (or index) theorem, even though in practice
we will only use the above special case.
S-m-n Theorem: For any m, n ≥ 0 there is a total computable (m + 1)-ary function Snm
such that
{Snm (z, y1 , ..., ym )}n (x1 , ..., xn ) = {z}m+n (x1 , ..., xn , y1 , ..., ym )
Exercise 5 Prove the S-m-n theorem for the case m = 1 using the special case above and
the Kleene Normal Form Theorem. Now use this to prove it for arbitrary m.
Application: We can use this form of S-m-n to give a slick argument that K ≤m H, where
H = {x | {x}1 (0) 6= ∞} is as in the example above. Recall that Φ(x, y) = {x}1 (y) is
the universal function for unary computable functions, and Φ is computable, by the Kleene
Normal Form Theorem (KNFT). Let
Hence {f (x)}1 (0) = {x}1 (x), and in particular {f (x)}1 (0) 6= ∞ iff {x}1 (x) 6= ∞. Thus
x ∈ K iff f (x) ∈ H.
74
Exercise 6 Show that the following sets are not computable, using the S-m-n theorem as
above. Note that it suffices to show that the complementary set is not computable, since a
set A is computable iff Ac is computable.
A1 = {x | {x}1 (5) = ∞}
A2 = {x | ran({x}1 ) = N}, where ran(f ) = f (N) = range of f
A3 = {x | dom({x}1 ) is finite}, where dom(f ) = {x | f (x) 6= ∞} is the domain of f .
Rice’s Theorem
It turns out that the noncomputability of all of the above examples, and many more, follow
from a single result, known as Rice’s Theorem. We say that A ⊆ N is a function index set
if for all e ∈ A, if {e}1 = {e0 }1 then e0 ∈ A. Thus if A contains a code for a program that
computes a unary function φ, then A must contain codes for all programs that compute φ.
We can think of a function index set as a set of computable functions rather than a set of
numbers.
Note that each of the three sets A1 , A2 , A3 in the above exercise is a function index set.
Exercise 7 Prove Rice’s Theorem. Use the same techniques that you used to prove A1 , A2 , A3
are not computable. (Hint: First consider the case in which no code for the empty function
Empt (which has empty domain) is in A.)
Exercise 8 You may use Church’s Thesis in answering the following questions. That is, to
justify that a particular function is computable is suffices to give an algorithm for computing
it.
(a) Define the relation R(x, y) by the condition R(x, y) holds iff at some time during the
computation of program {x} (where all registers are initialized to 0) register R1 obtains the
value y. Prove that R(x, y) is not recursive.
(b) Define the relation S(x, y) by the condition S(x, y) holds iff at some time during the
computation of program {x} (where all registers are initialized to 0) some register obtains
the value y. Prove that S(x, y) is recursive.
75
Intuition: Let n = 1. A is r.e. iff there is an algorithm for enumerating members of A in
some order. The following Lemma justifies this intuition.
If A = ran(f ), then A = {f (0), f (1), f (2) · · · }. Hence there is an algorithm for enumerating
A, namely compute f (0), f (1), f (2) · · · . It is important that f be total in order for this
algorithm to work. Notice that this does not necessarily enumerate A in order, and there
may be repetitions.
Then A = ran(F ). To convert F to a unary function f with the same range, we fix things so
that f (2x 3y ) = F (x, y). Explicitly, define f (z) = F ((z)0 , (z)1 ), where (z)x is the exponent of
prime px in the prime decomposition of z (see Notes page 66). Thus f is a total computable
unary function whose range is A.
The technique used in the first half of the above proof of enumerating A by, in effect,
enumerating all pairs (x, y) is called dovetailing.
Remark: Every recursive set is r.e. Given a recursive set A, simply define the relation R
by R(x, y) ⇔ x ∈ A. Then x ∈ A ⇔ ∃yR(x, y), so A is r.e.
Analogy: P is to NP as the recursive sets are to the r.e. sets. In fact, one way to define
NP is to modify our definition of r.e. by requiring the relation R(x, y) be polynomial time
computable (instead of just recursive), and by putting a suitable bound on the quantifier
∃yR(x, y). Then P is a subset of NP just as every recursive set is r.e. However, unlike P vs
NP we can prove that not all r.e. sets are recursive.
76
Proof: Recall that K = {x | {x}1 (x) 6= ∞}. We have already shown that K is not recursive,
so it suffices to show that K is r.e. By the KNFT (page 68), {x}1 (x) = U (µyT (x, x, y)),
where T ≡ T1 is the Kleene T predicate. Therefore
x ∈ K ⇔ ∃yT (x, x, y)
Prove that a set A ⊆ N is recursive iff A = ∅ or A is the range of some total computable
unary nondecreasing function f . Give a careful proof, without using Church’s thesis. Hint:
For the ⇐= direction, consider separately the case in which A is finite.
Pairing Functions
Exercise 10 Show that J, K, L are each primitive recursive. (In fact, they are polynomial
time computable.)
Recall that by definition, if A ⊆ N, then A is r.e. iff there is a recursive relation R(x, y) such
that x ∈ A ⇔ ∃yR(x, y).
Theorem: Suppose A ⊆ N. Then the following are equivalent (where dom stands for
domain and ran stands for range):
i) A is r.e.
ii) A = dom(f ) for some recursive f .
iii) A = {x | ∃yR(x, y)} for some primitive recursive relation R.
77
iv) A = ∅ or A = ran(f ) for some primitive recursive unary function f .
v) A = ran(f ) for some recursive unary function f (f not necessarily total).
ii) → iii): Assume A = dom(f ), where f is computable. We find a primitive recursive relation
R such that A = {x | ∃yR(x, y)}. The idea is to use the KNFT. Since f is computable, some
program {e} computes f . Thus
Then f (x) is defined iff ∃yT (e, x, y), so x ∈ A ⇔ ∃yT (e, x, y). Let R(x, y) = T (e, x, y).
To turn F into a function of one variable, we could use the technique used in the proof of the
Lemma two pages ago, but we choose to use the inverse pairing functions K and L (defined
above).
K(z) if R(K(z), L(z))
f (z) =
a otherwise
Then f is a unary primitive recursive function whose range is A.
iv) ⇒ v): Assume A is ∅ or A = ran(f ) where f is prim rec. Observe that the empty
function is recursive, and its range is the empty set.
Remember that by definition of the T -predicate, T (e, x, y) holds iff y codes a halting com-
putation of program {e} on input x. Note that by definition of the T predicate (page 68),
for each fixed e and x, if there is a computation code y satisfying T (e, x, y) then y is unique.
Thus
z ∈ ran(f ) ⇔ ∃x(f (x) = z) ⇔ ∃x∃y(T (e, x, y) ∧ U (y) = z)
We are not quite done because there are two existential quantifiers in front of the relation.
We could combine the two variable x and y using a pairing function. Alternatively, we can
78
simply note that if T (e, x, y) holds then x ≤ y (since the computation coded by y includes
the initial state, which has x in register R1 ). Thus
z ∈ ran(f ) ⇔ ∃y [∃x ≤ y(T (e, x, y) ∧ U (y) = z)]
| {z }
R(z,y)
Remark: The above theorem remains true if in (iii), “primitive recursive” is replaced by
“polynomial time computable”. The same holds for (iv). However we will not need these
facts.
Application of the Theorem: We can use the above theorem to give easy proofs that
various sets are r.e. For example, recall K = {x | {x}1 (x) 6= ∞}. Let f (x) = Φ(x, x) =
{x}1 (x). Then f is computable, and K = dom(f ). Thus K is r.e. by part ii) of the above
theorem.
Although graph(f ) is not always recursive for computable functions f , it is r.e. In fact, there
is a converse:
Exercise 11 Prove the above theorem. To show the if direction, first give an informal
algorithm for computing f from an enumeration of the tuples in graph(f ). Then formalize
the argument by showing that f is recursive, using the least number operator µ.
Proof: ⇒: Recursive sets are r.e., and complements of recursive sets are recursive.
⇐: Assume A and Ac are both r.e. Then there are recursive relations R and S such that
x ∈ A iff ∃yR(x, y) and x ∈ Ac iff ∃yS(x, y).
79
for y : 0 · · · ∞
If R(x, y) then output yes (x ∈ A) exit
end if
If S(x, y) then output no (x 6∈ A) exit
end if
end for
Application: K is r.e. but not recursive. Therefore by the above theorem, K c is not r.e.
Proof: Use ii) in the theorem on page 77 characterizing r.e. sets. Since B is r.e., B = dom(f )
for some computable f . Since A ≤m B, there is a total computable g such that
x ∈ A ⇔ g(x) ∈ B ⇔ f (g(x)) 6= ∞
then A = dom(f ◦ g). Thus A is r.e.
Exercise 12 Show that the following sets are not r.e. Note that
A ≤m B ⇔ Ac ≤m B c
A1 = {x | {x}1 (5) = ∞}
A2 = {x | ran({x}1 ) = N}
A3 = {x | dom({x}1 ) is finite}
Also show that Ac2 and Ac3 are not r.e. In fact, it is easier to show Ac2 is not r.e. than to
show A2 is not r.e. To show A2 and Ac3 are not r.e. use the method suggested above (reduce
K c to them), but use the KNFT in an interesting way.
It turns out that every “natural” r.e. set A ⊆ N that has been shown to be not recursive is
in fact r.e. complete.
80
Effective enumeration of functions
Recall that φe (x) = {e}1 (x), so φe is the unary function computed by program {e}. Thus
φ0 , φ1 , φ2 , ... is an effective enumeration of all unary computable functions. However, it
follows from the theorem on page 69 that there is no such effective enumeration of all total
unary computable functions. Since the unary primitive recursive functions can be effectively
enumerated, this is another way of showing that not all total computable functions are
primitive recursive.
Exercise 14 What goes wrong with the proof of the theorem on page 69 if we replace the
list f0 , f1 , ... of total computable functions by the list φ0 , φ1 , ... of computable functions?
So far all of our examples of nonrecursive sets have referred directly or indirectly to programs,
as for example the set K. However there are many known nonrecursive sets which arrive from
combinatorial problems which on the surface appear to have nothing to do with computation.
An example is the set T G of all context-free grammars G over some alphabet Σ such that
L(G) = Σ∗ . (Technically T G consists of all numerical codes for such grammars G, where we
assign a numerical code to a grammar in the same way as we assigned codes to RM programs.)
The method for proving that T G is nonrecursive is the same as for examples above; namely
reduce K c to T G. See for example “Elements of the Theory of Computation” by H. R. Lewis
and C. H. Papadimitriou or “Formal Languages and their Relation to Automata” by J. E.
Hopcroft and J. D. Ullman for this and other examples.
The crowning achievement for showing sets are not recursive is the following.
Definition: A Diophantine equation is one of the form p(~x) = q(~x), where p and q are
multivariate polynomials with natural number coefficients.
Examples are 3x3 yz 5 + 2y 4 + 5 = 0, and (x + 1)n + (y + 1)n = z n , for any fixed positive
integer n.
81
Corollary: There is no algorithm for Hilbert’s 10th problem.
Proof of Corollary: Choose any set, say K, which is r.e. but not recursive. Since K is
r.e., it follows from the MRDP Theorem that K has a representation of the form
If there were an algorithm for Hilbert’s 10th, then we could determine membership in K.
The proof of the MRDP Theorem is beyond the scope of this course. For a readable proof,
see “Proof of recursive unsolvability of Hilbert’s Tenth Problem” by Jones and Matiyasevich,
Amer. Math. Monthly vol. 98 (1991) 689-709.
82