Computability

Computability Theory

Reading preferences

Optional display controls need JavaScript. All reading content and navigation work without it.

Source file content/computability/computability-theory/computability-theory.tex

Editorial

Material in this chapter should be reviewed and expanded. In particular, there are no exercises yet.

Source file content/computability/computability-theory/introduction.tex

Introduction

The branch of logic known as computability theory deals with issues having to do with the computability, or relative computability, of functions and sets. It is evidence of Kleene's influence that the subject used to be known as recursion theory, and today, both names are commonly used.

Let us call a function f:f\colon \Nat \pto \Natsource partial computable if it can be computed in some model of computation. If ffsource is total we will simply say that ffsource is computable. A relation RRsource with computable characteristic function χR\Char{R}source is also called computable. If ffsource and ggsource are partial functions, we will write f(x)f(x) \fdefinedsource to mean that ffsource is defined at xxsource, i.e., xxsource is in the domain of ffsource; and f(x)f(x) \fundefinedsource to mean the opposite, i.e., that ffsource is not defined at xxsource. We will use f(x)g(x)f(x) \simeq g(x)source to mean that either f(x)f(x)source and g(x)g(x)source are both undefined, or they are both defined and equal.

One can explore the theory of computability without having to refer to a specific model of computation. To do this, one shows that there is a universal partial computable function Un(k,x)\fn{Un}(k, x)source. This allows us to enumerate the partial computable functions. We will adopt the notation φk\cfind{k}source to denote the kksource-th unary partial computable function, defined by φk(x)Un(k,x)\cfind{k}(x) \simeq \fn{Un}(k, x)source. (Kleene used {k}\{ k \}source for this purpose, but this notation has not been used as much recently.) Slightly more generally, we can uniformly enumerate the partial computable functions of arbitrary arities, and we will use φk[n]\cfind{k}[n]source to denote the kksource-th nnsource-ary partial recursive function.

If f(x,y)f(\vec x, y)source is a total or partial function, then μyf(x,y)\umin{y}{f (\vec x, y)}source is the function of x\vec xsource that returns the least yysource such that f(x,y)=0f(\vec x, y) = 0source, assuming that all of f(x,0)f(\vec x, 0)source, dots, f(x,y1)f(\vec x, y-1)source are defined; if there is no such yysource, μyf(x,y)\umin{y}{f (\vec x, y)}source is undefined. If R(x,y)R(\vec x, y)source is a relation, μyR(x,y)\umin{y}{R(\vec x, y)}source is defined to be the least yysource such that R(x,y)R(\vec x, y)source is true; in other words, the least yysource such that 1χR(x,y)=01 \tsub \Char{R}(\vec x, y) = 0source.

To show that a function is computable, there are two ways one can proceed:

  1. Rigorously: describe a Turing machine or partial recursive function explicitly, and show that it computes the function you have in mind;

  2. Informally: describe an algorithm that computes it, and appeal to Church's thesis.

There is no fine line between the two; a detailed description of an algorithm should provide enough information so that it is relatively clear how one could, in principle, design the right Turing machine or sequence of partial recursive definitions. Fully rigorous definitions are unlikely to be informative, and we will try to find a happy medium between these two approaches; in short, we will try to find intuitive yet rigorous proofs that the precise definitions could be obtained.

Source file content/computability/computability-theory/coding-computations.tex

Coding Computations

In every model of computation, it is possible to do the following:

  1. Describe the definitions of computable functions in a systematic way. For instance, you can think of Turing machine specifications, recursive definitions, or programs in a programming language as providing these definitions.

  2. Describe the complete record of the computation of a function given by some definition for a given input. For instance, a Turing machine computation can be described by the sequence of configurations (state of the machine, contents of the tape) for each step of computation.

  3. Test whether a putative record of a computation is in fact the record of how a computable function with a given definition would be computed for a given input (on which the function is defined, i.e., the computation halts).

  4. Extract from such a description of the complete record of a computation the value of the function for a given input. For instance, the contents of the tape in the very last step of a halting Turing machine computation is the value.

Using coding, it is possible to assign to each description of a computable function a numerical index in such a way that the instructions can be recovered from the index in a computable way. Similarly, the complete record of a computation can be coded by a single number as well. The resulting arithmetical relation “sssource codes the record of computation of the function with index eesource for input xxsource” and the function “output of computation sequence with code sssource” are then computable; in fact, they are primitive recursive.

This fundamental fact is very powerful, and allows us to prove a number of striking and important results about computability, independently of the model of computation chosen.

Source file content/computability/computability-theory/normal-form.tex

The Normal Form Theorem

Suppose we can describe definitions of computable functions, and test if some putative description of the complete record of the computation of that function on some input is correct. Then it stands to reason that independently of the model of computation, we can determine the value of any computable function ffsource on any input xxsource as follows:

  1. Search through all possible descriptions of records of computation.

  2. Test if a given record is the record of a computation of f(x)f(x)source.

  3. Extract the value of f(x)f(x)source from the correct record if we have found it.

That this is in fact true is the content of Kleene's normal form theorem.

Kleene normal form theorem

[Kleene's Normal Form Theorem] There is a primitive recursive relation T(e,x,s)T(e, x, s)source and a primitive recursive function U(s)U(s)source, with the following property: if ffsource is any partial computable function, then for some eesource,

f(x)U(μsT(e,x,s))f(x) \simeq U(\umin{s}{T(e, x, s)})source

for every xxsource.

Proof

[Proof Sketch] For any model of computation one can rigorously define a description of the computable function ffsource and code such description using a natural number eesource. One can also rigorously define a notion of “computation sequence” which records the process of computing the function with index eesource for input xxsource. Such a computation sequence can likewise be coded as a number sssource. This can be done in such a way that

  1. the relation T(e,x,s)T(e, x, s)source, which holds iff a number sssource codes the computation sequence of the function with index eesource on input xxsource, and

  2. the function U(s)U(s)source which maps a computation sequence coded by sssource to the end result of that computation

are both computable. In fact, the relation TTsource and the function UUsource are primitive recursive.

Explain

In order to give a rigorous proof of the Normal Form Theorem, we would have to fix a model of computation and carry out the coding of descriptions of computable functions and of computation sequences in detail, and verify that the relation TTsource and function UUsource are primitive recursive. For most applications, it suffices that TTsource and UUsource are computable and that UUsource is total.

It is probably best to remember the proof of the normal form theorem in slogan form: μsT(e,x,s)\umin{s}{T(e, x, s)}source searches for a computation sequence of the function with index eesource on input xxsource, and UUsource returns the output of the computation sequence if one can be found.

If the model of computation is the partial recursive functions (which is what Kleene originally used), it shows that only a single use of unbounded search, i.e., a single μyf(x,y)\umin{y}{f(\vec x, y)}source operator is necessary for the definition of any function. In this sense it shows that any partial recursive function has a normal form.

TTsource and UUsource can be used to define the enumeration φ0\cfind{0}source, φ1\cfind{1}source, φ2\cfind{2}source, dots. From now on, we will assume that we have fixed a suitable choice of TTsource and UUsource, and take the equation

φe(x)U(μsT(e,x,s))\cfind{e}(x) \simeq U(\umin{s}{T(e,x,s)})source

to be the definition of φe\cfind{e}source.

Here is another useful fact:

Infinitely many indices theorem

Every partial computable function has infinitely many indices.

Again, this is intuitively clear. Given any (description of) a computable function, one can come up with a different description which computes the same function (input-output pair) but does so, e.g., by first doing something that has no effect on the computation (say, test if 0=00 = 0source, or count to 55source, etc.). The index of the altered description will always be different from the original index. Both are indices of the same function, just computed slightly differently.

Source file content/computability/computability-theory/s-m-n.tex

The sssource-mmsource-nnsource Theorem

Explain

The next theorem is known as the “sssource-mmsource-nnsource theorem,” for a reason that will be clear in a moment. The hard part is understanding just what the theorem says; once you understand the statement, it will seem fairly obvious.

Parameterization theorem

For each pair of natural numbers nnsource and mmsource, there is a primitive recursive function smns^m_nsource such that for every sequence eesource, a0a_0source, dots, am1a_{m-1}source, y0y_0source ,dots, yn1y_{n-1}source, we have

φsmn(e,a0,,am1)[n](y0,,yn1)φe[m+n](a0,,am1,y0,,yn1).\cfind{s^m_n(e, a_0, \dots, a_{m-1})}[n](y_0, \dots, y_{n-1}) \simeq \cfind{e}[m+n](a_0, \dots, a_{m-1}, y_0, \dots, y_{n-1}).source

Explain

It is helpful to think of smns^m_nsource as acting on programs. That is, smns^m_nsource takes a program eesource for an (m+n)(m+n)source-ary function, as well as fixed inputs a0a_0source, dots, am1a_{m-1}source; and it returns a program smn(e,a0,,am1)s^m_n(e, a_0, \dots, a_{m-1})source for the nnsource-ary function of the remaining arguments. It you think of eesource as the description of a Turing machine, then smn(e,a0,,am1)s^m_n(e, a_0, \dots, a_{m-1})source is the Turing machine that, on input y0y_0source, dots, yn1y_{n-1}source, prepends a0a_0source, dots, am1a_{m-1}source to the input string, and runs eesource. Each smns^m_nsource is then just a primitive recursive function that finds a code for the appropriate Turing machine.

Source file content/computability/computability-theory/universal-part-function.tex

The Universal Partial Computable Function

Universal partial computable function theorem

There is a universal partial computable function Un(e,x)\fn{Un}(e,x)source. In other words, there is a function Un(e,x)\fn{Un}(e,x)source such that:

  1. Un(e,x)\fn{Un}(e,x)source is partial computable.

  2. If f(x)f(x)source is any partial computable function, then there is a natural number eesource such that f(x)Un(e,x)f(x) \simeq \fn{Un}(e,x)source for every xxsource.

Proof

Let Un(e,x)U(μsT(e,x,s))\fn{Un}(e,x) \simeq U(\umin{s}{T(e,x,s)})source, where UUsource and TTsource are as in Kleene's normal form theorem (Universal function proof reference to normal form).

Explain

This is just a precise way of saying that we have an effective enumeration of the partial computable functions; the idea is that if we write fef_esource for the function defined by fe(x)=Un(e,x)f_e(x) = \fn{Un}(e,x)source, then the sequence f0f_0source, f1f_1source, f2f_2source, dots includes all the partial computable functions, with the property that fe(x)f_e(x)source can be computed “uniformly” in eesource and xxsource. For simplicity, we are using a binary function that is universal for unary functions, but by coding sequences of numbers we can easily generalize this to more arguments. For example, note that if f(x,y,z)f(x,y,z)source is a 33source-place partial recursive function, then the function g(x)f((x)0,(x)1,(x)2)g(x) \simeq f((x)_0, (x)_1, (x)_2)source is a unary recursive function.

Source file content/computability/computability-theory/no-universal-function.tex

No Universal Computable Function

Although there is a partial computable function that is total for the partial computable functions, there is no total computable function that is universal for the total computable functions.

No universal total computable function theorem

There is no universal computable function. In other words, any function Un(k,x)\fn{Un}'(k, x)source which is such that if f(x)f(x)source is a total computable function, then there is a natural number kksource such that f(x)=Un(k,x)f(x) = \fn{Un}'(k,x)source for every xxsource, is not computable.

Proof

The proof is a simple diagonalization: if Un(k,x)\fn{Un}'(k,x)source were total and computable, then

d(x)=Un(x,x)+1d(x) = \fn{Un}'(x, x) + 1source

would also be total and computable. However, by definition, d(k)d(k)source is not equal to Un(k,k)\fn{Un}'(k,k)source. Hence, for every kksource, the values of d(x)d(x)source and Un(k,x)\fn{Un}'(k, x)source differ for at least one xxsource, namely x=kx = ksource.

Explain

Diagonalization explanation reference to universality above shows that we can get around this diagonalization argument, but only at the expense of allowing the universal function to be partial. That is, Un\fn{Un}source is universal for the total computable functions, it just isn't total. The diagonalization argument doesn't work in the partial case.

Partial diagonalization exercise

To understand why the diagonalization argument in the proof of Partial diagonalization exercise reference does not work in the partial case, consider the function f(x)Un(x,x)+1f(x) \simeq \fn{Un}(x,x)+1source. Is it partial computable? If so, it has an index eesource, i.e., f(x)Un(e,x)f(x) \simeq \fn{Un}(e,x)source. What can you say about f(e)f(e)source?

Source file content/computability/computability-theory/halting-problem.tex

The Halting Problem

By construction, the universal partial computable function Un(e,x)\fn{Un}(e,x)source is defined if and only if the computation of the function coded by eesource produces a value for input xxsource. It is natural to ask if we can decide whether this is the case. In fact, it is not. For the Turing machine model of computation, this means that whether a given Turing machine halts on a given input is computationally undecidable. The following theorem is therefore known as the “undecidability of the halting problem.” We will provide two proofs below. The first continues the thread of our previous discussion, while the second is more direct.

Halting function theorem

Let

h(e,x)={1if Un(e,x) is defined0otherwise.h(e, x) = \begin{cases} 1 & \text{if\/ $\fn{Un}(e, x)$ is defined} \\ 0 & \text{otherwise.} \end{cases}source

Then hhsource is not computable.

Proof

Suppose hhsource is computable. We show that this would let us define a universal computable function. Define

Un(e,x)={Un(e,x)if h(e,x)=10otherwise.\fn{Un'}(e,x) = \begin{cases} \fn{Un}(e,x) & \text{if $h(e,x) = 1$} \\ 0 & \text{otherwise.} \end{cases}source

But now Un(e,x)\fn{Un'}(e, x)source is a total function, and is computable if hhsource is. For instance, we could define ggsource using primitive recursion, by

g(0,e,x)0g(y+1,e,x)Un(e,x);g(0, e, x) & \simeq 0 \\ g(y+1, e, x) & \simeq \fn{Un}(e,x);source

then

Un(e,x)g(h(e,x),e,x).\fn{Un'}(e,x) \simeq g(h(e,x),e,x).source

Since Un(e,x)\fn{Un'}(e,x)source agrees with Un(e,x)\fn{Un}(e,x)source wherever the latter is defined, Un\fn{Un'}source is universal for those partial computable functions that happen to be total. But this contradicts Halting proof contradiction reference.

Proof

Suppose h(e,x)h(e,x)source were computable. Define the function ggsource by

g(x)={0if h(x,x)=0otherwise.g(x) = \begin{cases} 0 & \text{if $h(x,x) = 0$} \\ \fundefined & \text{otherwise.} \end{cases}source

The function ggsource is partial computable. For example, one can define it as μyh(x,x)=0\umin{y}{h(x,x) = 0}source. So, for some eesource, g(x)Un(e,x)g(x) \simeq \fn{Un}(e, x)source for every xxsource. Is ggsource defined at eesource? If it is, then, by the definition of ggsource, h(e,e)=0h(e,e) = 0source (hhsource can only take the value 00source if it is defined). By the definition of hhsource, this means that Un(e,e)\fn{Un}(e, e)source is undefined. By our assumption that g(x)Un(e,x)g(x) \simeq \fn{Un}(e, x)source for every xxsource, we have that g(e)g(e)source is undefined, a contradiction. On the other hand, if g(e)g(e)source is undefined, then h(e,e)0h(e,e) \neq 0source, and so h(e,e)=1h(e,e) = 1source. It follows that Un(e,e)\fn{Un}(e, e)source is defined. But since g(x)Un(e,x)g(x) \simeq \fn{Un}(e, x)source, then g(e)g(e)source would also be defined. Again, a contradiction.

Explain

We can describe this argument in terms of Turing machines. Suppose there were a Turing machine HHsource that takes as input a description of a Turing machine EEsource and an input xxsource, and decides whether or not EEsource halts on input xxsource. Then we could build another Turing machine GGsource which takes a single input xxsource, runs HHsource to decide if the machine MxM_xsource with index xxsource halts on input xxsource, and does the opposite. In other words, if HHsource reports that MxM_xsource halts on input xxsource, GGsource goes into an infinite loop, and if HHsource reports that MxM_xsource doesn't halt on input xxsource, then GGsource just halts. Does GGsource halt on its own index as input? The argument above shows that it does if and only if it doesn't---a contradiction. So our supposition that there is a such Turing machine HHsource must be false.

Source file content/computability/computability-theory/russells-paradox.tex

Comparison with Russell's Paradox

It is instructive to compare and contrast the arguments in this section with Russell's paradox:

  1. Russell's paradox: let S={x:xx}S = \Setabs{x}{x \notin x}source. Then SSS \in Ssource if and only if SSS \notin Ssource, a contradiction.

    Conclusion: There is no such set SSsource. Assuming the existence of a “set of all sets” is inconsistent with the other axioms of set theory.

  2. A modification of Russell's paradox: let FFsource be the “function” from the set of all functions to {0,1}\{ 0, 1 \}source, defined by

    F(f)={1if f is in the domain of f, and f(f)=00otherwiseF(f) = \begin{cases} 1 & \text{if $f$ is in the domain of $f$, and $f(f) = 0$} \\ 0 & \text{otherwise} \end{cases}source

    A similar argument shows that F(F)=0F(F) = 0source if and only if F(F)=1F(F) = 1source, a contradiction.

    Conclusion: FFsource is not a function. The “set of all functions” is too big to be the domain of a function.

  3. The diagonalization argument: let f0f_0source, f1f_1source, dots be the enumeration of the partial computable functions, and let G:{0,1}G \colon \Nat \to \{ 0, 1 \}source be defined by

    G(x)={1if fx(x)=00otherwiseG(x) = \begin{cases} 1 & \text{if $f_x(x)\downarrow = 0$} \\ 0 & \text{otherwise} \end{cases}source

    If GGsource is computable, then it is the function fkf_ksource for some kksource. But then G(k)=1G(k) = 1source if and only if G(k)=0G(k) = 0source, a contradiction.

    Conclusion: GGsource is not computable. Note that according to the axioms of set theory, GGsource is still a function; there is no paradox here, just a clarification.

That talk of partial functions, computable functions, partial computable functions, and so on can be confusing. The set of all partial functions from \Natsource to \Natsource is a big collection of objects. Some of them are total, some of them are computable, some are both total and computable, and some are neither. Keep in mind that when we say “function,” by default, we mean a total function. Thus we have:

  1. computable functions

  2. partial computable functions that are not total

  3. functions that are not computable

  4. partial functions that are neither total nor computable

To sort this out, it might help to draw a big square representing all the partial functions from \Natsource to \Natsource, and then mark off two overlapping regions, corresponding to the total functions and the computable partial functions, respectively. It is a good exercise to see if you can describe an object in each of the resulting regions in the diagram.

Source file content/computability/computability-theory/computable-sets.tex

Computable Sets

We can extend the notion of computability from computable functions to computable sets:

Definition of computable sets and relations

Let SSsource be a set of natural numbers. Then SSsource is computable iff its characteristic function χS\Char{S}source is. In other words, SSsource is computable iff the function

χS(x)={1if xS0otherwise\Char{S}(x) = \begin{cases} 1 & \text{if $x \in S$} \\ 0 & \text{otherwise} \end{cases}source

is computable. Similarly, a relation R(x0,,xk1)R(x_0, \dots, x_{k-1})source is computable if and only if its characteristic function is.

Computable sets and relations are also called decidable.

Explain

Notice that we now have a number of notions of computability: for partial functions, for functions, and for sets. Do not get them confused! The Turing machine computing a partial function returns the output of the function, for input values at which the function is defined; the Turing machine computing a set returns either 11source or 00source, after deciding whether or not the input value is in the set or not.

Source file content/computability/computability-theory/ce-sets.tex

Computably Enumerable Sets

Definition of computably enumerable sets

A set is computably enumerable if it is empty or the range of a computable function.

History

Computably enumerable sets are also called recursively enumerable instead. This is the original terminology, and today both are commonly used, as well as the abbreviations “c.e.” and “r.e.”

Explain

You should think about what the definition means, and why the terminology is appropriate. The idea is that if SSsource is the range of the computable function ffsource, then

S={f(0),f(1),f(2),},S = \{ f(0), f(1), f(2), \dots \},source

and so ffsource can be seen as “enumerating” the elements of SSsource. Note that according to the definition, ffsource need not be an increasing function, i.e., the enumeration need not be in increasing order. In fact, ffsource need not even be injective, i.e., repetitions in the enumeration f(0)f(0)source, f(1)f(1)source, f(2)f(2)source, dots of SSsource are allowed. For instance, the constant function f(x)=0f(x) = 0source enumerates the set {0}\{ 0 \}source.

Any computable set is computably enumerable. To see this, suppose SSsource is computable. If SSsource is empty, then by definition it is computably enumerable. Otherwise, let aasource be any element of SSsource. Define ffsource by

f(x)={xif χS(x)=1aotherwise.f(x) = \begin{cases} x & \text{if $\Char{S}(x) = 1$} \\ a & \text{otherwise.} \end{cases}source

Then ffsource is a computable function, and SSsource is the range of ffsource.

Source file content/computability/computability-theory/equiv-ce-defs.tex

Equivalent Defininitions of Computably Enumerable Sets

The following gives a number of important equivalent statements of what it means to be computably enumerable.

Equivalent definitions of computably enumerable sets theorem

Let SSsource be a set of natural numbers. Then the following are equivalent:

  1. SSsource is computably enumerable.

  2. SSsource is the range of a partial computable function.

  3. SSsource is empty or the range of a primitive recursive function.

  4. SSsource is the domain of a partial computable function.

Explain

The first three clauses say that we can equivalently take any non-empty computably enumerable set to be enumerated by either a computable function, a partial computable function, or a primitive recursive function. The fourth clause tells us that if SSsource is computably enumerable, then for some index eesource,

S={x:φe(x)}.S = \Setabs{x}{\cfind{e}(x) \fdefined}.source

In other words, SSsource is the set of inputs on for which the computation of φe\cfind{e}source halts. For that reason, computably enumerable sets are sometimes called semi-decidable: if a number is in the set, you eventually get a “yes,” but if it isn't, you never get a “no”!

Proof

Since every primitive recursive function is computable and every computable function is partial computable, Primitive range clause implication source implies Primitive range implication destination and Partial range implication source implies Partial range implication destination. (Note that if SSsource is empty, SSsource is the range of the partial computable function that is nowhere defined.) If we show that Primitive range return implication source implies Primitive range return implication destination, we will have shown the first three clauses equivalent.

So, suppose SSsource is the range of the partial computable function φe\cfind{e}source. If SSsource is empty, we are done. Otherwise, let aasource be any element of SSsource. By Kleene's normal form theorem, we can write

φe(x)U(μsT(e,x,s)).\cfind{e}(x) \simeq U(\umin{s}{T(e, x, s)}).source

In particular, φe(x)\cfind{e}(x) \fdefinedsource and =y= ysource if and only if there is an sssource such that T(e,x,s)T(e, x, s)source and U(s)=yU(s) = ysource. Define f(z)f(z)source by

f(z)={U((z)1)if T(e,(z)0,(z)1)aotherwise.f(z) = \begin{cases} U((z)_1) & \text{if $T(e, (z)_0, (z)_1)$} \\ a & \text{otherwise.} \end{cases}source

Then ffsource is primitive recursive, because TTsource and UUsource are. Expressed in terms of Turing machines, if zzsource codes a pair (z)0,(z)1\tuple{(z)_0, (z)_1}source such that (z)1(z)_1source is a halting computation of machine MeM_esource on input (z)0(z)_0source, then ffsource returns the output of the computation; otherwise, it returns aasource.

We need to show that SSsource is the range of ffsource, i.e., for any natural number yysource, ySy \in Ssource if and only if it is in the range of ffsource. In the forwards direction, suppose ySy \in Ssource. Then yysource is in the range of φe\cfind{e}source, so for some xxsource and sssource, T(e,x,s)T(e,x,s)source holds and U(s)=yU(s) = ysource. But then y=f(x,s)y = f(\tuple{x,s})source. Conversely, suppose yysource is in the range of ffsource. Then either y=ay = asource, or for some zzsource, T(e,(z)0,(z)1)T(e,(z)_0,(z)_1)source and U((z)1)=yU((z)_1) = ysource. Since, in the latter case, φe((z)0)=y\cfind{e}((z)_0) \fdefined = ysource, either way, yysource is in SSsource.

(The notation φe(x)=y\cfind{e}(x) \fdefined = ysource means “φe(x)\cfind{e}(x)source is defined and equal to yysource.” We could just as well use φe(x)=y\cfind{e}(x) = ysource, but the extra arrow is sometimes helpful in reminding us that we are dealing with a partial function.)

To finish up the proof of Equivalent definitions proof resumption reference, it suffices to show that Range and domain equivalence first clause reference and Range and domain equivalence second clause reference are equivalent. First, let us show that Range to domain implication source implies Range to domain implication destination. Suppose SSsource is the range of a computable function ffsource, i.e.,

S={y:for some x, f(x)=y}.S = \Setabs{y}{\text{for some $x$, } f(x) = y}.source

Let

g(y)=μx(f(x)=y).g(y) = \umin{x}{(f(x) = y)}.source

Then ggsource is a partial computable function, and g(y)g(y)source is defined if and only if for some xxsource, f(x)=yf(x) = ysource. In other words, the domain of ggsource is the range of ffsource. Expressed in terms of Turing machines: given a Turing machine FFsource that enumerates the elements of SSsource, let GGsource be the Turing machine that semi-decides SSsource by searching through the outputs of FFsource to see if a given element is in the set, halts if it is and keeps searching forever if it isn't.

Finally, to show Domain to range implication source implies Domain to range implication destination, suppose that SSsource is the domain of the partial computable function φe\cfind{e}source, i.e.,

S={x:φe(x)}.S = \Setabs{x}{\cfind{e}(x) \fdefined}.source

If SSsource is empty, we are done; otherwise, let aasource be any element of SSsource. Define ffsource by

f(z)={(z)0if T(e,(z)0,(z)1)aotherwise.f(z) = \begin{cases} (z)_0 & \text{if $T(e,(z)_0,(z)_1)$} \\ a & \text{otherwise.} \end{cases}source

Then, as above, a number xxsource is in the range of ffsource if and only if φe(x)\cfind{e}(x) \fdefinedsource, i.e., if and only if xSx \in Ssource. Expressed in terms of Turing machines: given a machine MeM_esource that semi-decides SSsource, enumerate the elements of SSsource by running through all possible Turing machine computations, and returning the inputs that correspond to halting computations.

Clause Domain clause enumeration reference of Enumeration consequence theorem reference provides us with a convenient way of enumerating the computably enumerable sets: for each eesource, let WeW_esource denote the domain of φe\cfind{e}source, i.e.,

We={x:φe(x)}.W_e = \Setabs{x}{\cfind{e}(x) \fdefined}.source

Then if AAsource is any computably enumerable set, A=WeA = W_esource, for some eesource.

The following provides yet another characterization of the computably enumerable sets.

Existential characterization theorem

A set SSsource is computably enumerable if and only if there is a computable relation R(x,y)R(x,y)source such that

S={x:yR(x,y)}.S = \Setabs{ x }{ \lexists[y][R(x,y)] }.source

Proof

In the forward direction, suppose SSsource is computably enumerable. Then for some eesource, S=WeS = W_esource. For this value of eesource we can write SSsource as

S={x:yT(e,x,y)}.S = \Setabs{ x }{ \lexists[y][T(e, x, y)] }.source

In the reverse direction, suppose S={x:yR(x,y)}S = \Setabs{ x }{ \lexists[y][R(x, y)] }source. Define ffsource by

f(x)μyR(x,y).f(x) \simeq \umin{y}{R(x, y)}.source

Then ffsource is partial computable, and SSsource is the domain of ffsource.

Source file content/computability/computability-theory/non-comp-set.tex

There Are Non-Computable Sets

We saw above that every computable set is computably enumerable. Is the converse true? The following shows that, in general, it is not.

Paired halting set theorem

Let K0K_0source be the set {e,x:φe(x)}\Setabs{\tuple{e, x}}{\cfind{e}(x) \fdefined}source. Then K0K_0source is computably enumerable but not computable.

Proof

To see that K0K_0source is computably enumerable, note that it is the domain of the function ffsource defined by

f(z)=μy(len(z)=2T((z)0,(z)1,y)).f(z) = \umin{y}{(\len{z} = 2 \land T((z)_0, (z)_1, y))}.source

For, if φe(x)\cfind{e}(x)source is defined, f(e,x)f(\tuple{e, x})source finds a halting computation sequence; if φe(x)\cfind{e}(x)source is undefined, so is f(e,x)f(\tuple{e, x})source; and if zzsource doesn't even code a pair, then f(z)f(z)source is also undefined.

The fact that K0K_0source is not computable is just the undecidability of the halting problem, Paired halting set undecidability reference.

The set K0K_0source is the set of pairs e,x\tuple{e,x}source such that φe(x)\cfind{e}(x) \fdefinedsource, i.e., e,xK0\tuple{e,x} \in K_0source iff φe\cfind{e}source is defined (halts) on input xxsource, so it is also called the “halting set.” The set K={e:φe(e)}K = \Setabs{e}{\cfind{e}(e) \fdefined}source is the “self-halting set.” It is often used as a canonical undecidable set.

Self halting set theorem

The self-halting set K={e:φe(e)}K = \Setabs{e}{\cfind{e}(e) \fdefined}source is c.e. but not decidable.

Proof

Suppose KKsource is decidable, i.e., its characteristic function χK\Char{K}source is computable. Let

d(e)={1if χK(e)=0otherwise.d(e) = \begin{cases} 1 & \text{if\/ $\Char{K}(e) = 0$}\\ \fundefined & \text{otherwise.} \end{cases}source

Let kksource be the index of ddsource, i.e., dφkd \simeq \cfind{k}source. Then d(k)φk(k)d(k) \simeq \cfind{k}(k)source. This contradicts the fact that d(k)d(k) \fdefinedsource iff φk(k)\cfind{k}(k) \fundefinedsource, which follows from the definition of ddsource.

KKsource is the domain of f(x)=μyT(x,x,y)f(x) = \umin{y}{T(x,x,y)}source and so is c.e.

Source file content/computability/computability-theory/ce-closed-cup-cap.tex

Computably Enumerable Sets are Closed under Union and Intersection

The following theorem gives some closure properties on the set of computably enumerable sets.

Closure under union and intersection theorem

Suppose AAsource and BBsource are computably enumerable. Then so are ABA \cap Bsource and ABA \cup Bsource.

Proof

Closure proof characterization reference allows us to use various characterizations of the computably enumerable sets. By way of illustration, we will provide a few different proofs.

For the first proof, suppose AAsource is enumerated by a computable function ffsource, and BBsource is enumerated by a computable function ggsource. Let

h(x)=μy(f(y)=xg(y)=x) andj(x)=μy(f((y)0)=xg((y)1)=x).h(x) & = \umin{y}{(f(y) = x \lor g(y) = x)} \text{ and}\\ j(x) & = \umin{y}{(f((y)_0) = x \land g((y)_1) = x)}.source

Then ABA \cup Bsource is the domain of hhsource, and ABA \cap Bsource is the domain of jjsource.

Explain

Here is what is going on, in computational terms: given procedures that enumerate AAsource and BBsource, we can semi-decide if an element xxsource is in ABA \cup Bsource by looking for xxsource in either enumeration; and we can semi-decide if an element xxsource is in ABA \cap Bsource for looking for xxsource in both enumerations at the same time.

For the second proof, suppose again that AAsource is enumerated by ffsource and BBsource is enumerated by ggsource. Let

k(x)={f(x/2)if x is eveng((x1)/2)if x is odd.k(x) = \begin{cases} f(x/2) & \text{if $x$ is even} \\ g((x-1)/2) & \text{if $x$ is odd.} \end{cases}source

Then kksource enumerates ABA \cup Bsource; the idea is that kksource just alternates between the enumerations offered by ffsource and ggsource. Enumerating ABA \cap Bsource is tricker. If ABA \cap Bsource is empty, it is trivially computably enumerable. Otherwise, let ccsource be any element of ABA \cap Bsource, and define llsource by

l(x)={f((x)0)if f((x)0)=g((x)1)cotherwise.l(x) = \begin{cases} f((x)_0) & \text{if $f((x)_0) = g((x)_1)$} \\ c & \text{otherwise.} \end{cases}source

In computational terms, llsource runs through pairs of elements in the enumerations of ffsource and ggsource, and outputs every match it finds; otherwise, it just stalls by outputting ccsource.

For the last proof, suppose AAsource is the domain of the partial function m(x)m(x)source and BBsource is the domain of the partial function n(x)n(x)source. Then ABA \cap Bsource is the domain of the partial function m(x)+n(x)m(x) + n(x)source.

Explain

In computational terms, if AAsource is the set of values for which mmsource halts and BBsource is the set of values for which nnsource halts, ABA \cap Bsource is the set of values for which both procedures halt.

Expressing ABA \cup Bsource as a set of halting values is more difficult, because one has to simulate mmsource and nnsource in parallel. Let ddsource be an index for mmsource and let eesource be an index for nnsource; in other words, m=φdm = \cfind{d}source and n=φen = \cfind{e}source. Then ABA \cup Bsource is the domain of the function

p(x)=μy(T(d,x,y)T(e,x,y)).p(x) = \umin{y}{(T(d,x,y) \lor T(e,x,y))}.source

Explain

In computational terms, on input xxsource, ppsource searches for either a halting computation for mmsource or a halting computation for nnsource, and halts if it finds either one.

Source file content/computability/computability-theory/complement-ce.tex

Computably Enumerable Sets not Closed under Complement

Suppose AAsource is computably enumerable. Is the complement of AAsource, A¯=A\Complement{A} = \Nat \setminus Asource, always computably enumerable as well? The following theorem and corollary show that the answer is “no.”

Complement characterization theorem

Let AAsource be any set of natural numbers. Then AAsource is computable if and only if both AAsource and A¯\Complement{A}source are computably enumerable.

Proof

The forwards direction is easy: if AAsource is computable, then A¯\Complement{A}source is computable as well (χA=1χA¯\Char{A} = 1 \tsub \Char{\Complement{A}}source), and so both are computably enumerable.

In the other direction, suppose AAsource and A¯\Complement{A}source are both computably enumerable. Let AAsource be the domain of φd\cfind{d}source, and let A¯\Complement{A}source be the domain of φe\cfind{e}source. Define hhsource by

h(x)=μs(T(d,x,s)T(e,x,s)).h(x) = \umin{s}{(T(d,x,s) \lor T(e,x,s))}.source

In other words, on input xxsource, hhsource searches for either a halting computation of φd\cfind{d}source or a halting computation of φe\cfind{e}source. Now, if xAx \in Asource, it will succeed in the first case, and if xA¯x \in \Complement{A}source, it will succeed in the second case. So, hhsource is a total computable function. But now we have that for every xxsource, xAx \in Asource if and only if T(d,x,h(x))T(d, x, h(x))source, i.e., if φd\cfind{d}source is the one that is defined. Since T(d,x,h(x))T(d, x, h(x))source is a computable relation, AAsource is computable.

Explain

It is easier to understand what is going on in informal computational terms: to decide AAsource, on input xxsource search for halting computations of φd\cfind{d}source and φe\cfind{e}source. One of them is bound to halt; if it is φd\cfind{d}source, then xxsource is in AAsource, and otherwise, xxsource is in A¯\Complement{A}source.

Complement of paired halting set corollary

K0¯\Complement{K_0}source is not computably enumerable.

Proof

We know that K0K_0source is computably enumerable, but not computable. If K0¯\Complement{K_0}source were computably enumerable, then K0K_0source would be computable by Complement corollary characterization reference, contradicting Complement corollary halting set reference.

Source file content/computability/computability-theory/reducibility.tex

Reducibility

Explain

We now know that there is at least one set, K0K_0source, that is computably enumerable but not computable. It should be clear that there are others. The method of reducibility provides a powerful method of showing that other sets have these properties, without constantly having to return to first principles.

Generally speaking, a “reduction” of a set AAsource to a set BBsource is a method of transforming answers to whether or not elements are in BBsource into answers as to whether or not elements are in AAsource. We will focus on a notion called “many-one reducibility,” but there are many other notions of reducibility available, with varying properties. Notions of reducibility are also central to the study of computational complexity, where efficiency issues have to be considered as well. For example, a set is said to be “NP-complete” if it is in NP and every NP problem can be reduced to it, using a notion of reduction that is similar to the one described below, only with the added requirement that the reduction can be computed in polynomial time.

We have already used the notion of reduction notion implicitly. Define the set KKsource by

K={x:φx(x)},K = \Setabs{x}{\cfind{x}(x) \fdefined},source

i.e., K={x:xWx}K = \Setabs{x}{x \in W_x}source. Our proof that the halting problem in unsolvable (Reducibility introduction halting reference) shows most directly that KKsource is not computable. Recall that K0K_0source is the set

K0={e,x:φe(x)},K_0 = \Setabs{\tuple{e, x}}{\cfind{e}(x) \fdefined },source

i.e., K0={e,x:xWe}K_0 = \Setabs{\tuple{e,x}}{x \in W_e}source. It is easy to extend any proof of the uncomputability of KKsource to the uncomputability of K0K_0source: if K0K_0source were computable, we could decide whether or not an element xxsource is in KKsource simply by asking whether or not the pair x,x\tuple{x, x}source is in K0K_0source. The function ffsource which maps xxsource to x,x\tuple{x, x}source is an example of a reduction of KKsource to K0K_0source.

Definition of many one reducibility

Let AAsource and BBsource be sets of natural numbers. A computable function f:f\colon \Nat \to \Natsource is a many-one reduction of AAsource to BBsource iff, for every natural number xxsource,

xAif and only iff(x)B.x \in A \quad \text{if and only if} \quad f(x) \in B.source

If such a reduction ffsource exists, we say that AAsource is many-one reducible to BBsource, written AmBA \leq_m Bsource. If AAsource is many-one reducible to BBsource and vice-versa, then AAsource and BBsource are said to be many-one equivalent, written AmBA \equiv_m Bsource.

If the function ffsource in the definition above happens to be injective, AAsource is said to be one-one reducible to BBsource. Most of the reductions described below meet this stronger requirement, but we will not use this fact.

Digress

It is true, but by no means obvious, that one-one reducibility really is a stronger requirement than many-one reducibility. In other words, there are infinite sets AAsource and BBsource such that AAsource is many-one reducible to BBsource but not one-one reducible to BBsource.

Source file content/computability/computability-theory/prop-reduce.tex

Properties of Reducibility

We write AmBA \leq_m Bsource if AAsource reduces to BBsource, and this notation suggests that if AmBA \leq_m Bsource, then AAsource is “no harder than” BBsource and that BBsource is “as hard or harder than” AAsource, and that m\le_msource, like the usual \lesource on numbers, orders sets (or decision problems) by their complexity. The following two propositions support this intuition. The first one say taht m\le_msource is transitive.

Transitivity of many one reducibility proposition

If AmBA \leq_m Bsource and BmCB \leq_m Csource, then AmCA \leq_m Csource.

Proof

Composing a reduction of AAsource to BBsource with a reduction of BBsource to CCsource yields a reduction of AAsource to CCsource.

Transitivity proof exercise

Prove Transitivity exercise proposition reference by showing that if ffsource and ggsource are many-one reductions of AAsource to BBsource and BBsource to CCsource, respectively, then gf\comp{f}{g}source is a many-one reduction of AAsource to CCsource.

Reduction preservation proposition

Let AAsource and BBsource be any sets, and suppose AmBA \leq_m Bsource.

  1. If BBsource is computably enumerable, so is AAsource.

  2. If BBsource is computable, so is AAsource.

Proof

Let ffsource be a many-one reduction from AAsource to BBsource. For the first claim, just check that if BBsource is the domain of a partial function ggsource, then AAsource is the domain of gf\comp{f}{g}source:

xA iff f(x)B iff g(f(x)).x \in A & \text{ iff } f(x) \in B \\ & \text{ iff } g(f(x)) \fdefined.source

For the second claim, remember that if BBsource is computable then BBsource and B¯\Complement{B}source are computably enumerable (Reduction proof complement premise reference). It is not hard to check that ffsource is also a many-one reduction of A¯\Complement{A}source to B¯\Complement{B}source, so, by the first part of this proof, AAsource and A¯\Complement{A}source are computably enumerable. So AAsource is computable as well by Reduction proof complement conclusion reference. (Alternatively, you can check that χA=χBf\Char{A} = \comp{f}{\Char{B}}source; so if χB\Char{B}source is computable, then so is χA\Char{A}source.)

Complement reduction exercise

Suppose ffsource is a many-one reduction of AAsource to BBsource. Show that ffsource is also a many-one reduction of A¯\Complement{A}source to B¯\Complement{B}source.

Characteristic function composition exercise

Show that if f:ABf\colon A \to Bsource is a many-one reduction, then χA=χBf\Char{A} = \comp{f}{\Char{B}}source.

Digress

A more general notion of reducibility called Turing reducibility is useful in other contexts, especially for proving undecidability results. Note that by Complement nonreducibility corollary reference, the complement of K0K_0source is not reducible to K0K_0source, since it is not computably enumerable. But, intuitively, if you knew the answers to questions about K0K_0source, you would know the answer to questions about its complement as well. A set AAsource is said to be Turing reducible to BBsource if one can determine answers to questions in AAsource using a computable procedure that can ask questions about BBsource. This is more liberal than many-one reducibility, in which (1) you are only allowed to ask one question about BBsource, and (2) a “yes” answer has to translate to a “yes” answer to the question about AAsource, and similarly for “no.” It is still the case that if AAsource is Turing reducible to BBsource and BBsource is computable then AAsource is computable as well (though, as we have seen, the analogous statement does not hold for computable enumerability).

You should think about the various notions of reducibility we have discussed, and understand the distinctions between them. We will, however, only deal with many-one reducibility in this chapter. Incidentally, both types of reducibility discussed in the last paragraph have analogues in computational complexity, with the added requirement that the Turing machines run in polynomial time: the complexity version of many-one reducibility is known as Karp reducibility, while the complexity version of Turing reducibility is known as Cook reducibility.

Source file content/computability/computability-theory/complete-ce-sets.tex

Complete Computably Enumerable Sets

Definition of complete computably enumerable sets

A set AAsource is a complete computably enumerable set (under many-one reducibility) if

  1. AAsource is computably enumerable, and

  2. for any other computably enumerable set BBsource, BmAB \leq_m Asource.

In other words, complete computably enumerable sets are the “hardest” computably enumerable sets possible. They allow one to answer questions about any computably enumerable set.

Completeness of the canonical halting sets theorem

KKsource, K0K_0source, and K1K_1source are all complete computably enumerable sets.

Proof

To see that K0K_0source is complete, let BBsource be any computably enumerable set. Then for some index eesource,

B=We={x:φe(x)}.B = W_e = \Setabs{x}{\cfind{e}(x) \fdefined}.source

Let ffsource be the function f(x)=e,xf(x) = \tuple{e, x}source. Then for every natural number xxsource, xBx \in Bsource if and only if f(x)K0f(x) \in K_0source. In other words, ffsource reduces BBsource to K0K_0source.

To see that K1K_1source is complete, note that in the proof of Completeness proof zero input set reference we reduced K0K_0source to it. So, by Completeness proof transitivity reference, any computably enumerable set can be reduced to K1K_1source as well.

KKsource can be reduced to K0K_0source in much the same way.

Reduction from self halting to paired halting exercise

Give a reduction of KKsource to K0K_0source.

Digress

So, it turns out that all the examples of computably enumerable sets that we have considered so far are either computable, or complete. This should seem strange! Are there any examples of computably enumerable sets that are neither computable nor complete? The answer is yes, but it wasn't until the middle of the 1950s that this was established by Friedberg and Muchnik, independently.

Source file content/computability/computability-theory/k-1.tex

An Example of Reducibility

Let us consider an application of Zero input set reduction proposition reference.

Zero input halting set proposition

Let

K1={e:φe(0)}.K_1 = \Setabs{e}{\cfind{e}(0) \fdefined}.source

Then K1K_1source is computably enumerable but not computable.

Proof

Since K1={e:sT(e,0,s)}K_1 = \Setabs{e}{\lexists[s][T(e,0,s)]}source, K1K_1source is computably enumerable by Zero input set existential characterization reference.

To show that K1K_1source is not computable, let us show that K0K_0source is reducible to it.

Explain

This is a little bit tricky, since using K1K_1source we can only ask questions about computations that start with a particular input, 00source. Suppose you have a smart friend who can answer questions of this type (friends like this are known as “oracles”). Then suppose someone comes up to you and asks you whether or not e,x\tuple{e, x}source is in K0K_0source, that is, whether or not machine eesource halts on input xxsource. One thing you can do is build another machine, exe_xsource, that, for any input, ignores that input and instead runs eesource on input xxsource. Then clearly the question as to whether machine eesource halts on input xxsource is equivalent to the question as to whether machine exe_xsource halts on input 00source (or any other input). So, then you ask your friend whether this new machine, exe_xsource, halts on input 00source; your friend's answer to the modified question provides the answer to the original one. This provides the desired reduction of K0K_0source to K1K_1source.

Using the universal partial computable function, let ffsource be the 3-ary function defined by

f(x,y,z)φx(y).f(x,y,z) \simeq \cfind{x}(y).source

Note that ffsource ignores its third input entirely. Pick an index eesource such that f=φe[3]f = \cfind{e}[3]source; so we have

φe[3](x,y,z)φx(y).\cfind{e}[3](x,y,z) \simeq \cfind{x}(y).source

By the sssource-mmsource-nnsource theorem, there is a function s(e,x,y)s(e,x,y)source such that, for every zzsource,

φs(e,x,y)(z)φe[3](x,y,z)φx(y).\cfind{s(e,x,y)}(z) & \simeq \cfind{e}[3](x,y,z) \\ & \simeq \cfind{x}(y).source

Explain

In terms of the informal argument above, s(e,x,y)s(e,x,y)source is an index for the machine that, for any input zzsource, ignores that input and computes φx(y)\cfind{x}(y)source.

In particular, we have

φs(e,x,y)(0)if and only ifφx(y).\cfind{s(e,x,y)}(0) \fdefined \quad \text{if and only if} \quad \cfind{x}(y) \fdefined.source

In other words, x,yK0\tuple{x, y} \in K_0source if and only if s(e,x,y)K1s(e,x,y) \in K_1source. So the function ggsource defined by

g(w)=s(e,(w)0,(w)1)g(w) = s(e,(w)_0,(w)_1)source

is a reduction of K0K_0source to K1K_1source.

Source file content/computability/computability-theory/total.tex

Totality is Undecidable

Let us consider one more example of using the sssource-mmsource-nnsource theorem to show that something is noncomputable. Let Tot\fn{Tot}source be the set of indices of total computable functions, i.e.

Tot={x:for every y, φx(y)}.\fn{Tot} = \Setabs{x}{\text{for every $y$, $\cfind{x}(y)\fdefined$}}.source

Undecidability of totality proposition

Tot\fn{Tot}source is not computable.

Proof

To see that Tot\fn{Tot}source is not computable, it suffices to show that KKsource is reducible to it. Let h(x,y)h(x,y)source be defined by

h(x,y){0if xKotherwiseh(x,y) \simeq \begin{cases} 0 & \text{if $x \in K$} \\ \fundefined & \text{otherwise} \end{cases}source

Note that h(x,y)h(x,y)source does not depend on yysource at all. It should not be hard to see that hhsource is partial computable: on input x,yx, ysource, the we compute hhsource by first simulating the function φx\cfind{x}source on input xxsource; if this computation halts, h(x,y)h(x,y)source outputs 00source and halts. So h(x,y)h(x,y)source is just zero(μsT(x,x,s))\Zero(\umin{s}{T(x,x,s)})source, where zero\Zerosource is the constant zero function.

Using the sssource-mmsource-nnsource theorem, there is a primitive recursive function k(x)k(x)source such that for every xxsource and yysource,

φk(x)(y){0if xKotherwise\cfind{k(x)}(y) \simeq \begin{cases}0 & \text{if $x \in K$} \\ \fundefined & \text{otherwise}\end{cases}source

So φk(x)\cfind{k(x)}source is total if xKx \in Ksource, and undefined otherwise. Thus, kksource is a reduction of KKsource to Tot\fn{Tot}source.

Digress

It turns out that Tot\fn{Tot}source is not even computably enumerable---its complexity lies further up on the “arithmetical hierarchy.” But we will not worry about this strengthening here.

Source file content/computability/computability-theory/rice-theorem.tex

Rice's Theorem

If you think about it, you will see that the specifics of Tot\fn{Tot}source do not play into the proof of Rice theorem motivation totality reference. We designed h(x,y)h(x,y)source to act like the constant function j(y)=0j(y) = 0source exactly when xxsource is in KKsource; but we could just as well have made it act like any other partial computable function under those circumstances. This observation lets us state a more general theorem, which says, roughly, that no nontrivial property of computable functions is decidable.

Keep in mind that φ0\cfind{0}source, φ1\cfind{1}source, φ2\cfind{2}source, dots is our standard enumeration of the partial computable functions.

Rice theorem

[Rice's Theorem] Let CCsource be any set of partial computable functions, and let A={n:φnC}A = \Setabs{n}{\cfind{n} \in C}source. If AAsource is computable, then either CCsource is empty or CCsource is the set of all the partial computable functions.

An em index set is a set AAsource with the property that if nnsource and mmsource are indices which “compute” the same function, then either both nnsource and mmsource are in AAsource, or neither is. It is not hard to see that the set AAsource in the theorem has this property. Conversely, if AAsource is an index set and CCsource is the set of functions computed by these indices, then A={n:φnC}A = \Setabs{n}{\cfind{n} \in C}source.

Explain

With this terminology, Rice's theorem is equivalent to saying that no nontrivial index set is decidable. To understand what the theorem says, it is helpful to emphasize the distinction between programs (say, in your favorite programming language) and the functions they compute. There are certainly questions about programs (indices), which are syntactic objects, that are computable: does this program have more than 150 symbols? Does it have more than 22 lines? Does it have a “while” statement? Does the string “hello world” ever appear as the argument to a “print” statement? Rice's theorem says that no nontrivial question about the program's behavior is computable. This includes questions like these: does the program halt on input 00source? Does it ever halt? Does it ever output an even number?

Proof

[Proof of Rice's theorem] Suppose CCsource is neither empty nor the set of all the partial computable functions, and let AAsource be the set of indices of functions in CCsource. We will show that if AAsource were computable, we could solve the halting problem; so AAsource is not computable.

Without loss of generality, we can assume that the function ffsource which is nowhere defined is not in CCsource (otherwise, switch CCsource and its complement in the argument below). Let ggsource be any function in CCsource. The idea is that if we could decide AAsource, we could tell the difference between indices computing ffsource, and indices computing ggsource; and then we could use that capability to solve the halting problem.

Here's how. Using the universal partial computable functions, we can define a function

h(x,y){undefinedif φx(x)g(y)otherwise.h(x,y) \simeq \begin{cases} \text{undefined} & \text{if $\cfind{x}(x) \fundefined$} \\ g(y) & \text{otherwise.} \end{cases}source

To compute hhsource, first we try to compute φx(x)\cfind{x}(x)source; if that computation halts, we go on to compute g(y)g(y)source; and if em that computation halts, we return the output. More formally, we can write

h(x,y)P02(g(y),Un(x,x)).h(x,y) \simeq \Proj{2}{0}(g(y),\fn{Un}(x,x)).source

where P02(z0,z1)=z0\Proj{2}{0}(z_0, z_1) = z_0source is the 22source-place projection function returning the 00source-th argument, which is computable.

Then hhsource is a composition of partial computable functions, and the right side is defined and equal to g(y)g(y)source just when Un(x,x)\fn{Un}(x,x)source and g(y)g(y)source are both defined.

Notice that for a fixed xxsource, if φx(x)\cfind{x}(x)source is undefined, then h(x,y)h(x,y)source is undefined for every yysource; and if φx(x)\cfind{x}(x)source is defined, then h(x,y)g(y)h(x,y) \simeq g(y)source. So, for any fixed value of xxsource, either h(x,y)h(x,y)source acts just like ffsource or it acts just like ggsource, and deciding whether or not φx(x)\cfind{x}(x)source is defined amounts to deciding which of these two cases holds. But this amounts to deciding whether or not hx(y)h(x,y)h_x(y) \simeq h(x,y)source is in CCsource or not, and if AAsource were computable, we could do just that.

More formally, since hhsource is partial computable, it is equal to the function φe\cfind{e}source for some index eesource. By the sssource-mmsource-nnsource theorem there is a primitive recursive function sssource such that for each xxsource, φs(e,x)(y)hx(y)\cfind{s(e,x)}(y) \simeq h_x(y)source. Now we have that for each xxsource, if φx(x)\cfind{x}(x) \fdefinedsource, then φs(e,x)\cfind{s(e,x)}source is the same function as ggsource, and so s(e,x)s(e,x)source is in AAsource. On the other hand, if φx(x)\cfind{x}(x) \uparrowsource, then φs(e,x)\cfind{s(e,x)}source is the same function as ffsource, and so s(e,x)s(e,x)source is not in AAsource. In other words, we have that for every xxsource, xKx \in Ksource if and only if s(e,x)As(e,x) \in Asource. If AAsource were computable, KKsource would be also, which is a contradiction. So AAsource is not computable.

Rice's theorem is very powerful. The following immediate corollary shows some sample applications.

Rice theorem examples corollary

The following sets are undecidable.

  1. {x:17range(φx)}\Setabs{x}{17 \in \fn{range}(\cfind{x})}source17isintherangeofis in the range ofsourcecfindxsource closing delimiter fragment}}source

  2. {x:Constant(φx)}\Setabs{x}{\fn{Constant}(\cfind{x})}sourcecfindxsource fragment saying is constant followed by closing delimitersis constant}}source

  3. {x:Total(φx)}\Setabs{x}{\fn{Total}(\cfind{x})}sourcecfindxsource fragment saying is total followed by closing delimitersis total}}source

  4. {x:yy((y<yφx(y))(φx(y)φx(y)<φx(y)))}\Setabs{x}{\lforall[y][\lforall[y'][((y<y' \land \cfind{x}(y)\fdefined) \land (\cfind{x}(y')\fdefined \lif \cfind{x}(y)<\cfind{x}(y')))]]}sourcey < y',,sourcecfindx(y) fdefined,andif, and ifsourcecfindx(y') fdefined,then, thensourcecfindx(y) < cfindx(y')source closing delimiter fragment}}source

Proof

These are all nontrivial index sets.

Source file content/computability/computability-theory/fixed-point-thm.tex

The Fixed-Point Theorem

Let's consider the halting problem again. As temporary notation, let us write φx(y)\gn{\cfind{x}(y)}source for x,y\tuple{x, y}source; think of this as representing a “name” for the value φx(y)\cfind{x}(y)source. With this notation, we can reword one of our proofs that the halting problem is undecidable.

Question: is there a computable function hhsource, with the following property? For every xxsource and yysource,

h(φx(y))={1if φx(y)0otherwise.h(\gn{\cfind{x}(y)}) = \begin{cases} 1 & \text{if $\cfind{x}(y) \fdefined$} \\ 0 & \text{otherwise.} \end{cases}source

Answer: No; otherwise, the partial function

g(x){0if h(φx(x))=0undefinedotherwiseg(x) \simeq \begin{cases} 0 & \text{if $h(\gn{\cfind{x}(x)}) = 0$} \\ \text{undefined} & \text{otherwise} \end{cases}source

would be computable, and so have some index eesource. But then we have

φe(e){0if h(φe(e))=0undefinedotherwise,\cfind{e}(e) \simeq \begin{cases} 0 & \text{if $h(\gn{\cfind{e}(e)}) = 0$} \\ \text{undefined} & \text{otherwise,} \end{cases}source

in which case φe(e)\cfind{e}(e)source is defined if and only if it isn't, a contradiction.

Now, take a look at the equation with φe\cfind{e}source. There is an instance of self-reference there, in a sense: we have arranged for the value of φe(e)\cfind{e}(e)source to depend on φe(e)\gn{\cfind{e}(e)}source, in a certain way. The fixed-point theorem says that we em can do this, in general---not just for the sake of proving contradictions.

Fixed point equivalence discussion reference gives two equivalent ways of stating the fixed-point theorem. Logically speaking, the fact that the statements are equivalent follows from the fact that they are both true; but what we really mean is that each one follows straightforwardly from the other, so that they can be taken as alternative statements of the same theorem.

Fixed point equivalence lemma

The following statements are equivalent:

  1. For every partial computable function g(x,y)g(x,y)source, there is an index eesource such that for every yysource,

    φe(y)g(e,y).\cfind{e}(y) \simeq g(e,y).source
  2. For every computable function f(x)f(x)source, there is an index eesource such that for every yysource,

    φe(y)φf(e)(y).\cfind{e}(y) \simeq \cfind{f(e)}(y).source

Proof

(1)(2)(1) \Rightarrow (2)source: Given ffsource, define ggsource by g(x,y)Un(f(x),y)g(x,y) \simeq \fn{Un}(f(x),y)source. Use (1) to get an index eesource such that for every yysource,

φe(y)Un(f(e),y)φf(e)(y).\cfind{e}(y) & \simeq \fn{Un}(f(e),y) \\ & \simeq \cfind{f(e)}(y).source

(2)(1)(2) \Rightarrow (1)source: Given ggsource, use the sssource-mmsource-nnsource theorem to get ffsource such that for every xxsource and yysource, φf(x)(y)g(x,y)\cfind{f(x)}(y) \simeq g(x,y)source. Use (2) to get an index eesource such that

φe(y)φf(e)(y)g(e,y).\cfind{e}(y) & \simeq \cfind{f(e)}(y) \\ & \simeq g(e,y).source

This concludes the proof.

Explain

Before showing that statement (1) is true (and hence (2) as well), consider how bizarre it is. Think of eesource as being a computer program; statement (1) says that given any partial computable g(x,y)g(x,y)source, you can find a computer program eesource that computes ge(y)g(e,y)g_e(y) \simeq g(e,y)source. In other words, you can find a computer program that computes a function that references the program itself.

Computability fixed point theorem

The two statements in Fixed point theorem statement reference are true. Specifically, for every partial computable function g(x,y)g(x,y)source, there is an index eesource such that for every yysource,

φe(y)g(e,y).\cfind{e}(y) \simeq g(e,y).source

Proof

The ingredients are already implicit in the discussion of the halting problem above. Let diag(x)\fn{diag}(x)source be a computable function which for each xxsource returns an index for the function fx(y)φx(x,y)f_x(y) \simeq \cfind{x}(x,y)source, i.e.

φdiag(x)(y)φx(x,y).\cfind{\fn{diag}(x)}(y) \simeq \cfind{x}(x,y).source

Think of diag\fn{diag}source as a function that transforms a program for a 2-ary function into a program for a 1-ary function, obtained by fixing the original program as its first argument. The function diag\fn{diag}source can be defined formally as follows: first define sssource by

s(x,y)Un2(x,x,y),s(x,y) \simeq \fn{Un}^2(x,x,y),source

where Un2\fn{Un}^2source is a 3-ary function that is universal for partial computable 2-ary functions. Then, by the sssource-mmsource-nnsource theorem, we can find a primitive recursive function diag\fn{diag}source satisfying

φdiag(x)(y)s(x,y).\cfind{\fn{diag}(x)}(y) \simeq s(x,y).source

Now, define the function llsource by

l(x,y)g(diag(x),y).l(x,y) \simeq g(\fn{diag}(x),y).source

and let l\gn{l}source be an index for llsource. Finally, let e=diag(l)e = \fn{diag}(\gn{l})source. Then for every yysource, we have

φe(y)φdiag(l)(y)φl(l,y)l(l,y)g(diag(l),y)g(e,y),\cfind{e}(y) & \simeq \cfind{\fn{diag}(\gn{l})}(y) \\ & \simeq \cfind{\gn{l}}(\gn{l}, y) \\ & \simeq l(\gn{l}, y) \\ & \simeq g(\fn{diag}(\gn{l}),y) \\ & \simeq g(e, y),source

as required.

Explain

What's going on? Suppose you are given the task of writing a computer program that prints itself out. Suppose further, however, that you are working with a programming language with a rich and bizarre library of string functions. In particular, suppose your programming language has a function diag\fn{diag}source which works as follows: given an input string sssource, diag\fn{diag}source locates each instance of the symbol `x' occurring in sssource, and replaces it by a quoted version of the original string. For example, given the string

Verbatim

hello x world

as input, the function returns

Verbatim

hello 'hello x world' world

as output. In that case, it is easy to write the desired program; you can check that

Verbatim

print(diag('print(diag(x))'))

does the trick. For more common programming languages like C++ and Java, the same idea (with a more involved implementation) still works.

We are only a couple of steps away from the proof of the fixed-point theorem. Suppose a variant of the print function print(x,y)\fn{print}(x,y)source accepts a string xxsource and another numeric argument yysource, and prints the string xxsource repeatedly, yysource times. Then the “program”

Verbatim

getinput(y); print(diag('getinput(y); print(diag(x), y)'), y)

prints itself out yysource times, on input yysource. Replacing the getinput\fn{getinput}source---print\fn{print}source---diag\fn{diag}source skeleton by an arbitrary function g(x,y)g(x,y)source yields

Verbatim

g(diag('g(diag(x), y)'), y)

which is a program that, on input yysource, runs ggsource on the program itself and yysource. Thinking of “quoting” with “using an index for,” we have the proof above.

For now, it is o.k.\ if you want to think of the proof as formal trickery, or black magic. But you should be able to reconstruct the details of the argument given above. When we prove the incompleteness theorems (and the related “fixed-point theorem”) we will discuss other ways of understanding why it works.

Digress

The same idea can be used to get a “fixed point” combinator. Suppose you have a lambda term ggsource, and you want another term kksource with the property that kksource is β\betasource-equivalent to gkgksource. Define terms

diag(x)=xx\fn{diag}(x) = xxsource

and

l(x)=g(diag(x))l(x) = g(\fn{diag}(x))source

using our notational conventions; in other words, llsource is the term λx.g(xx)\lambd[x][g(xx)]source. Let kksource be the term llllsource. Then we have

k=(λx.g(xx))(λx.g(xx))→βg((λx.g(xx))(λx.g(xx)))=gk.k & = (\lambd[x][g(xx)])(\lambd[x][g(xx)]) \\ & \red g((\lambd[x][g(xx)])(\lambd[x][g(xx)])) \\ & = gk.source

If one takes

Y=λg.((λx.g(xx))(λx.g(xx)))Y = \lambd[g][((\lambd[x][g(xx)])(\lambd[x][g(xx)]))]source

then YgYgsource and g(Yg)g(Yg)source reduce to a common term; so Ygβg(Yg)Yg \equiv_\beta g(Yg)source. This is known as “Curry's combinator.” If instead one takes

Y=(λxg.g(xxg))(λxg.g(xxg))Y = (\lambd[xg][g(xxg)])(\lambd[xg][g(xxg)])source

then in fact YgYgsource reduces to g(Yg)g(Yg)source, which is a stronger statement. This latter version of YYsource is known as “Turing's combinator.”

Source file content/computability/computability-theory/application-fixed-point.tex

Applying the Fixed-Point Theorem

The fixed-point theorem essentially lets us define partial computable functions in terms of their indices. For example, we can find an index eesource such that for every yysource,

φe(y)=e+y.\cfind{e}(y) = e + y.source

As another example, one can use the proof of the fixed-point theorem to design a program in Java or C++ that prints itself out.

Remember that if for each eesource, we let WeW_esource be the domain of φe\cfind{e}source, then the sequence W0W_0source, W1W_1source, W2W_2source, dots enumerates the computably enumerable sets. Some of these sets are computable. One can ask if there is an algorithm which takes as input a value xxsource, and, if WxW_xsource happens to be computable, returns an index for its characteristic function. The answer is “no,” there is no such algorithm:

No uniform characteristic index selector theorem

There is no partial computable function ffsource with the following property: whenever WeW_esource is computable, then f(e)f(e)source is defined and φf(e)\cfind{f(e)}source is its characteristic function.

Proof

Let ffsource be any computable function; we will construct an eesource such that WeW_esource is computable, but φf(e)\cfind{f(e)}source is not its characteristic function. Using the fixed point theorem, we can find an index eesource such that

φe(y){0if y=0 and φf(e)(0)=0undefinedotherwise.\cfind{e}(y) \simeq \begin{cases} 0 & \text{if $y=0$ and $\cfind{f(e)}(0) \fdefined = 0$} \\ \text{undefined} & \text{otherwise.} \end{cases}source

That is, eesource is obtained by applying the fixed-point theorem to the function defined by

g(x,y){0if y=0 and φf(x)(0)=0undefinedotherwise.g(x,y) \simeq \begin{cases} 0 & \text{if $y=0$ and $\cfind{f(x)}(0) \fdefined = 0$} \\ \text{undefined} & \text{otherwise.} \end{cases}source

Informally, we can see that ggsource is partial computable, as follows: on input xxsource and yysource, the algorithm first checks to see if yysource is equal to 00source. If it is, the algorithm computes f(x)f(x)source, and then uses the universal machine to compute φf(x)(0)\cfind{f(x)}(0)source. If this last computation halts and returns 00source, the algorithm returns 00source; otherwise, the algorithm doesn't halt.

But now notice that if φf(e)(0)\cfind{f(e)}(0)source is defined and equal to 00source, then φe(y)\cfind{e}(y)source is defined exactly when yysource is equal to 00source, so We={0}W_e = \{ 0 \}source. If φf(e)(0)\cfind{f(e)}(0)source is not defined, or is defined but not equal to 00source, then We=W_e = \emptysetsource. Either way, φf(e)\cfind{f(e)}source is not the characteristic function of WeW_esource, since it gives the wrong answer on input 00source.

Source file content/computability/computability-theory/def-functions-self-reference.tex

Defining Functions using Self-Reference

It is generally useful to be able to define functions in terms of themselves. For example, given computable functions kksource, llsource, and mmsource, the fixed-point lemma tells us that there is a partial computable function ffsource satisfying the following equation for every yysource:

f(y){k(y)if l(y)=0f(m(y))otherwise.f(y) \simeq \begin{cases} k(y) & \text{if $l(y) = 0$} \\ f(m(y)) & \text{otherwise.} \end{cases}source

Again, more specifically, ffsource is obtained by letting

g(x,y){k(y)if l(y)=0φx(m(y))otherwiseg(x,y) \simeq \begin{cases} k(y) & \text{if $l(y) = 0$} \\ \cfind{x}(m(y)) & \text{otherwise} \end{cases}source

and then using the fixed-point lemma to find an index eesource such that φe(y)g(e,y)\cfind{e}(y) \simeq g(e,y)source.

For a concrete example, the “greatest common divisor” function gcd(u,v)\fn{gcd}(u,v)source can be defined by

gcd(u,v){vif u=0gcd(mod(v,u),u)otherwise\fn{gcd}(u,v) \simeq \begin{cases} v & \text{if $u = 0$} \\ \fn{gcd}(\fn{mod}(v, u), u) & \text{otherwise} \end{cases}source

where mod(v,u)\fn{mod}(v, u)source denotes the remainder of dividing vvsource by uusource. An appeal to the fixed-point lemma shows that gcd\fn{gcd}source is partial computable. (In fact, this can be put in the format above, letting yysource code the pair u,v\tuple{u, v}source.) A subsequent induction on uusource then shows that, in fact, gcd\fn{gcd}source is total.

Of course, one can cook up self-referential definitions that are much fancier than the examples just discussed. Most programming languages support definitions of functions in terms of themselves, one way or another. Note that this is a little bit less dramatic than being able to define a function in terms of an index for an algorithm computing the functions, which is what, in full generality, the fixed-point theorem lets you do.

Source disclosures