\documentstyle[11pt,twoside,amssymb,psfig]{article}
\input{defs-6045}
\def\implies{\mbox{ implies }}
\renewcommand{\mid}{:}
\def\Ic{\mathify{\{c,I\}}}
\def\Kt{K_{\rm tot}}
\def\jump#1{^{(#1)}}
\newcommand{\nat}{{\Bbb N}}

\begin{document}

\handout{lecture18}{Notes on Lecture 18}{March 16, 1992}

\reading{Martin 18.2, 18.4, 20.1, 20.2}

\section{Relationships Between Partial Recursive Functions and Recursive and T-Acceptable Sets}

We begin with a theorem relating partial recursive functions to T-acceptable
sets.

\begin{theorem}
The function $f$ is partial recursive if and only if graph($f$) = $\{(x,y): y = f(x) \}$ is T-acceptable.
\end{theorem}

\begin{proof}
$(\Rightarrow)$.  Assume $f$ is partial recursive.  Then there is a TM
$M$ which on input $x$ produces $f(x)$ if the function is defined on
$x$.  Otherwise $M$ fails to halt.  We want to construct a machine
$M'$ which on input $(x,y)$ will halt if $y = f(x)$, or fail to halt
(or {\it diverge}) if $f$ is not defined for $x$, or if $y \neq x$.
We build a machine $M'$ that on input $(x,y)$ simulates $M$ on $x$.
If $M$ ever halts, then we check if the answer $M$ outputs is the same
as $y$.  If so, then $M'$ halts, otherwise we put $M'$ into an
infinite loop.  Hence we have constructed a machine $M'$ that accepts
exactly graph($f$).

$(\Leftarrow)$.  Assume graph($f$) is T-acceptable.  Then there is a
TM $M$ which on input $(x,y)$ halts if and only if $y = f(x)$.  We
want to construct a machine $M'$ which on input $x$ will output $f(x)$
if the function $f$ is defined on $x$, and which will diverge
otherwise.  The basic idea here is that we want $M'$ to simulate $M$
``in parallel'' on $(x,y_1), (x,y_2), \ldots, (x,y_i), \ldots$, where
$y_i$ is the $i$th possible string that $y$ could be.  When one of
these computations halts for $(x,y_j)$, then $M'$ will halt and output
$y_j$.  We need to simulate the computations ``in parallel'', rather
than sequentially, since $M$ is going to halt for only one of the $(x,y_i)$.

Before we say how we can run all of these computations in parallel, we
say a bit about how we know which string is the $i$th possible string
that $y$ could be. Given an alphabet $\Sigma$ and some ordering on the
characters of $\Sigma$ (i.e. which character is ``first'', ``second'',
etc.), then we can define an ordering on the strings in which $x$ is
ordered before $y$ if either $|x| < |y|$, or if $|x| = |y|$ and $x$
precedes $y$ in ``alphabetical'' order, given the ordering of the
characters.  This ordering is called the {\it canonical ordering of strings}.  
For example, if $\Sigma = \{0,1\}$, where ``0'' is the ``first'' character,
then the canonical ordering is $\Lambda$, 0,1,00,01,10,11,000,$\ldots$.

To run simulations of $M$ on $(x,y_1), (x,y_2), \ldots$ in parallel,
we must again use a ``dovetailing'' argument.  Notice that we can't
simply simulate $M$ on $(x,y_1)$ for one step, then on $(x,y_2)$ for
one step, then $(x,y_3)$ for one step, etc.  Because there are an
infinite number of $y_i$ we would never get to the second step of any
computation!  Hence we simulate $M$ on $(x,y_1)$ for one step.  We
then simulate on $(x,y_1)$ for another step, and $(x,y_2)$ for one
step.  Then we simulate on $(x,y_1)$ for another step, $(x,y_2)$ for
another step, and $(x,y_3)$ for one step, and continue in this fashion
(See Figure \ref{Fig-1}).  Simulating $M$ on the $(x,y_i)$ in this
fashion guarantees us that we will eventually find the $y_i$ for which
$M$ halts, if it exists.
\end{proof}


\begin{figure}
\centerline{\mbox{\psfig{figure=/u/dpwmson/6.045/handouts/handout23-fig.ps,height=2in}}}
\caption{Infinite dovetailing of $M$ on all the $y_i$}
\label{Fig-1}
\end{figure}



It was pointed out by the students in class that instead of using an
infinite dovetailing argument, we could have simply guessed $y_i$
nondeterministically, then simulated $M$ on $(x,y_i)$.  

Here is another infinite dovetailing theorem.

\begin{theorem} 
The language $\{M | L(M) \mbox{ is non-empty}\}$ is T-acceptable.
\end{theorem}

\begin{proof}
We can design a TM $M$ which when given an encoding of a machine $M'$
will perform the same infinite dovetailing procedure as above on all
the possible strings $x_1, x_2, \ldots$ of $M'$.  If any of the simulations
of $M'$ halts for any $x_i$, then $L(M')$ is non-empty, so we have $M$ halt.
\end{proof}

Again, we could simply have $M$ guess non-deterministically a string 
$x$, and simulate $M'$ on $x$ to be sure that $x \in L(M')$.

\begin{theorem}
The following are all equivalent for a language $L$:
\begin{enumerate}
\item $L$ is T-acceptable.
\item $L$ is the domain of a partial recursive function.
\item $L$ is the range of a partial recursive function.
\item Either $L = \emptyset$ or $L$ is the range of a total recursive function.
\end{enumerate}
\end{theorem}

\begin{proof}
We will show that $4 \Rightarrow 3 \Rightarrow 2 \Rightarrow 1 \Rightarrow 4$.

($4 \Rightarrow 3$).  If $L = \emptyset$, then $L$ is the range of a
partial recursive function, namely the function that diverges on all
inputs.  If $L$ is the range of a total recursive function, then it is
obviously the range of a partial recursive function, since a total
recursive function is just a kind of partial recursive function.

($3 \Rightarrow 2$).  Suppose that $L$ is the range of a partial
recursive function $f$ computer by TM $M$.  We want to define a new TM
$M'$ that halts only on the elements of $L$.  To do this, on input $x$
we have $M'$ perform an infinite dovetail on all the possible inputs
$y_i$ to $M$.  If, for some $y_j$, $M$ outputs $x$, then we halt $M'$.

($2 \Rightarrow 1$).  Assume that $L$ is the domain of a partial
recursive function $f$, where $f$ is computed by the TM $M$.  The TM
$M$ halts exactly on $x \in L$.  Hence $M$ proves that $L$ is also
T-acceptable.

($1 \Rightarrow$ 4).  Assume that $L$ is T-acceptable.  If $L =
\emptyset$, then we are done, so assume that $L \neq \emptyset$.  Let
$M$ be the TM that accepts $L$.  We must define a TM $M'$ that
computes a total function, such that the range of the function is
exactly the strings that $M$ halts on. Let $y_1, y_2, \ldots$ be the
possible input strings for $M'$, and let $x_1, x_2, \ldots$ be the
possible input strings for $M$.  We define $M'$ as follows:

\begin{itemize}
\item On input $y_1$, $M'$ will perform an infinite dovetail,
simulating $M$ on all the $x_i$ until $M$ halts on some $x_j$ (it will
halt since we have assume that $L = L(M) \neq \emptyset$).  Then $M'$
will output $x_j$.

\item On input $y_2$, $M'$ will perform an infinite dovetail,
simulating $M$ on all the $x_i$ until $M$ halts on some $x_j$.  $M'$
then performs one more step of the dovetail (i.e. it simulates $M$ for
one more step on whatever string $x_l$ would come next in the dovetail).
$M'$ outputs $x_l$ if $M$ halted on $x_l$, or $x_j$ otherwise.

\item In general, on input $y_k$, $M'$ will perform an infinite
dovetail, simulating $M$ on all the $x_i$ until $M$ halts on some
$x_j$. $M'$ then performs $k-1$ more steps of the dovetail, and
outputs the most recent $x_l$ for which $M$ has been observed to halt.
\end{itemize}

Hence $M'$ computes a total function, since it halts on all inputs,
and will output each $x \in L$ for some particular $y_i$.
\end{proof}


\section{Undecidability}

We now turn to proofs that certain sets are not recursive and not
T-acceptable, and proofs that functions are not partial recursive.  In
the next few lectures we will develop methods of proving these
results, and give many examples.  In proving languages to be
non-regular or non-context-free, we used the pumping lemma; when
proving languages to be non-recursive or non-T-acceptable, the main
techniques we will use are called {\it diagonalization} and {\it
reducibility}.  A basic problem, called the {\it Halting Problem for
TMs}, will be shown to be undecidable using a diagonalization proof.
Then we will be able to show other problems to be undecidable by
showing that a procedure to decide them would yield a procedure to
decide the Halting Problem.

\begin{definition}[The Halting Problem] Define $K_0 = \{<M,x> | M \mbox{
halts on input } x\}$, where $M$ is a TM and $x$ is a string over
$M$'s alphabet.
\end{definition}

\begin{theorem}
$K_0$ is not recursive.
\end{theorem}

\begin{proof}
To prove this, we will show that a related language $K_1$ is not
recursive. We let $K_1 = \{M | M \mbox{ halts on } e(M) \}$, where $M$
is a TM whose input alphabet includes the two characters used in the
encoding $e(M)$ of $M$.  The language $K_1$ is the artificial language
of machines that halt on the input of their own description.  Note
that $K_1$ is a special case of $K_0$.  To prove that $K_1$ is not
recursive, we will show that $\overline{K}_1$ is not T-acceptable.
The language $\overline{K}_1 = \{M : M \mbox{ does not halt on } e(M)
\}$. Suppose that $\overline{K}_1$ is T-acceptable.  Then by the
definition of T-acceptability there exists a TM $M_0$ (with input
alphabet containing the encoding alphabet) that halts exactly on the
elements of $\overline{K}_1$.  More precisely, $M_0$ halts on
encodings of elements of $\overline{K}_1$.  Therefore, $M_0$ halts on
$e(M)$ exactly if $M \in \overline{K}_1$; that is, exactly if $M$ does
not halt on $e(M)$.  To get a contradiction, consider what $M_0$ does
on its own encoding: $M_0$ halts on $e(M_0)$ exactly if $M_0$ does not
halt on $e(M_0)$.  This is obviously nonsense, so no such machine
$M_0$ can exist.  Thus $\overline{K}_1$ is not T-acceptable, which
implies that $K_1$ is not recursive.  

To see that $K_0$ is not recursive, suppose that it were, and that
some TM exists that decides $K_0$.  Then we could decide if $M \in
K_1$ by running the TM that decides $K_0$ on input $<M, e(M)>$.  Since
we can't decide $K_1$, this argument proves that we can't decide
$K_0$, either.  Hence $K_0$ is not recursive.  Intuitively, $K_1$ asks
about halting on special arguments, whereas $K_0$ asks about arbitrary
$M$ halting on arbitrary arguments: $K_1$ is just a special case of
$K_0$.  Since we can't decide the special case, we can't decide the
more general case, either.
\end{proof}

The argument used to prove that $\overline{K}_1$ is not recursive is
called a {\it diagonalization} becuase we can imagine forming a table 
out of all TMs that contain the characters of the encoding alphabet,
and their encodings.  At an entry $(i,j)$ of the table, we put $H$ if
the machine $M_i$ halts on encoding $e(M_j)$, or $NH$ otherwise.

\begin{center}
\begin{tabular}{l|cccc}
& $e(M_1)$ & $e(M_2)$ & $e(M_3)$ & $\cdots$ \\ \hline
$M_1$ & $H$ & $NH$ & $NH$ & $\cdots$ \\
$M_2$ & $NH$ & $NH$ & $H$  & $\cdots$ \\
$M_3$ & $H$  & $H$  & $H$  & $\cdots$ \\
$\vdots$ & $\vdots$ & $\vdots$ & $\vdots$ & $\ddots$ \\
\end{tabular}
\end{center}

\noindent Then the machine $M_0$ is defined so that $M_0(e(M_i))$ halts exactly
if $M_i(e(M_i))$ doesn't; i.e. it differs from the $i$th TM at the
$(i,i)$th entry in the table.  Hence $M_0$ can't be any TM in the
table.  But since we listed all the possible TMs in the table, this
must imply that no TM $M_0$ can exist.

For those of you who have seen some analysis (18.100), this is very similar to
Cantor's proof that the real numbers do not form a countable set.

\end{document}


