

\documentstyle[11pt,twoside,psfig]{article}
\input{defs-6045}
\begin{document}
\newcommand{\mless}{\leq_m}

\handout{quiz2solns}{Solutions to Quiz 2}{April 17, 1992}


\begin{enumerate}


\item {\bf Problem:} 
Suppose $f : \{ 0,1 \}^* \rightarrow \{ 0,1 \}^*$ and
$A \subseteq \{ 0,1 \}^*$.
We let $f(A) = \{ f(x): x \in A \}$.
For each of the following statements, decide whether it is true -- in
which case you must provide a proof,
or false -- in which case you must exhibit a counterexample.
\begin{enumerate}
\item (6 points) If $A$ is a Turing-acceptable (r.e.) language 
and $f$ is a total recursive function then $f(A)$ is a
Turing-acceptable language.

\item (6 points)
  If $A$ is a recursive language and $f$ is a total recursive
function then $f(A)$ is a recursive language. (Hint: This is false.)

\item (6 points) If $f(A)$ is a recursive language and $f$ is a total recursive
function then $A$ is a recursive language.
\end{enumerate}

{\bf Answer:} 

\begin{enumerate}
\item True.  We know that a language is r.e.\ iff there exists some Turing machine
$M$ that enumerates it.  Given a Turing machine $M$ to enumerate $A$,
and a TM $M_f$ that computes $f(x)$, we will produce a TM $M'$ that
enumerates $f(A)$.  Our TM $M'$ runs the enumerator for $A$.  For each
string $x$ enumerated by the machine, $M'$ runs $M_f$ on $x$ to obtain
$f(x)$.  It then writes $f(x)$ on its output tape.  Since $M$
enumerates all the $x \in A$, $M'$ will enumerate all the $f(x) \in
f(A)$.  Hence $f(A)$ is r.e.

A common mistake here was to try to assert that $f(A)$ is the range
of a partial recursive function $f$, so that a theorem from the
handouts applies to prove that $f(A)$ is r.e.  In fact, since $f$ is
total recursive, its range is $f(\Sigma^*)$, not $f(A)$; that is,
there may be strings not in $A$ that $f$ maps to strings outside of $f(A)$.

\item False.  Using 0s and 1s, we can encode TMs and their input strings, as we
showed for universal Turing Machines.  Hence consider the set $A =
\{<M,x,k> | M$ halts on $x$ in $k$ steps$\}$.  The set $A$ is
recursive: given an input $<M,x,k>$ we can simulate $M$ on $x$ for $k$
steps and detect whether $M$ halts or not.  Let $f(<M,x,k>) = <M,x>$.
Then $f(A) = K_0 = \{<M,x> | M$ halts on $x\}$, since for any $<M,x>$
such that $M$ halts on $x$, there exists a $k$ such that $M$ halts on
$x$ in $k$ steps.  We know that $K_0$ is not recursive, so we have
that $A$ is recursive and $f(A)$ is not recursive, which contradicts
the statement.

\item False.  Suppose $A = K_0$ and $f(x) = 1$ for all $x \in \Sigma^*$.
Then $A$ is not recursive, but $f(A) = \{1\}$ is recursive.

A common mistake here was to assume that the definition of $f$ implied
that $A \mless f(A)$.  It would be true if $x \in
A$ iff $f(x) \in f(A)$.  It is true that $x \in A$ implies $f(x) \in
f(A)$, but it is not necessarily true that $x \not\in A$ implies $f(x)
\not\in f(A)$ (in the solution above, even when $x \not\in A$, $f(x) =
1$, and so $f(x) \in f(A)$).  Hence our theorems about reducibility do
not apply to this problem.
\end{enumerate}

\item {\bf Problem:} This is a short-answer question.  NO proofs or explanations are
required.  There is no penalty for guessing.

Classify each of the following languages as follows:
\begin{tabbing}
   REC  \mbox{~~~~~~} \=    The language is recursive.\\
   UND  \>   The language is undecidable.
\end{tabbing}
\noindent If the language is undecidable, classify it further as either:
\begin{tabbing}
   R.E. \mbox{~~~~~~~} \=    The language is recursively enumerable but not recursive.\\
   co-R.E. \>  The complement of the language is recursively enumerable,
         but the language is \\
        \> not recursive. \\
   NONE \>    Neither the language nor its complement is recursively enumerable.
\end{tabbing}
Half-credit will be given to problems correctly marked ``UND'' without
further classification.

\begin{enumerate}

\item $\{ M$ (a Turing machine) : $L(M) = \emptyset \}$

\item $\{ 0^i 1^i : i \geq 0 \}$

\item $\{ M$ (a Turing machine) : $L(M) = \{ 0^i 1^i: i \geq 0 \} \}$

\item    $\{ x$ (a string): $x$ is the smallest word in $L(M)$, for some TM $M\}$
(Note:  ``Smallest'' refers to the canonical order, defined in the appendix below.)

\item    $\{ M $(a Turing machine): $M$, on blank input tape, outputs $e(M)$
         and halts. $\}$

\item     $\{ M$ (a Turing machine) : $L(M)$ is infinite $\}$

\item $\{ M$ (a Turing machine): M halts on all inputs within 5 steps $\}$

\end{enumerate}

{\bf Answer:}
\begin{enumerate}
\item CO-R.E.  The language is certainly not recursive, by Rice's Theorem.
Its complement is r.e.: Given a TM $M$, we run an infinite dovetail
simulating $M$ on all possible input strings.  If $M$ halts on some
string, then we halt and accept $M$.  This procedure halts exactly
when $L(M) \neq \emptyset$.

\item REC.  This language is context-free.  In our section on
context-free languages we saw that there is a decision procedure to
test whether a string is a member of a particular CFL; hence any CFL
is recursive.

\item NONE. We can reduce $\overline{K}_2$ to this language $L$ and the
complement of $L$ .  For the first part, we map a TM $M$ from
$\overline{K}_2$ to a TM $N_M$ that first checks if its input is $0^i
1^i$.  If it is, $N_M$ halts, otherwise it simulates $M$ on blank
tape.  Hence if $M \in \overline{K}_2$, then $L(M) = \{ 0^i 1^i: i
\geq 0 \}$, else $L(M) = \Sigma^*$, which proves that $\overline{K}_2 \mless
L$, and that $L$ is not r.e.  To show that $\bar L$ is not r.e.\ we
map $M \in \overline{K}_2$ to a TM $N_M$ that halts on all inputs of
the form $0^i 1^i$ EXCEPT $\Lambda$, and loops everywhere else.  On
input $\Lambda$, $N_M$ simulates $M$ on blank tape.  Hence $M \in
\overline{K}_2$ iff $L(M) \neq \{ 0^i 1^i: i \geq 0 \}$.  This proves
$\overline{K}_2 \mless \bar L$.

\item REC.  For any string $x$, one can always construct a TM $M$ such
that $L(M) = \{x\}$ (i.e.\ the TM accepts only $x$ and nothing else).
Hence {\it any} string $x$ is the smallest word in $L(M)$ for some TM
$M$.  The TM for the language in this problem simply halts on all inputs.

\item R.E.  The language $L$ is r.e.\ because given input machine $M$ we
can simply simulate it on blank tape and, if it halts, check if its
output is $e(M)$.  To prove that this is not recursive, we first
suppose that it is.  We then construct a total recursive function $f$
that on input $M$ checks if $M \in L$.  If so, it outputs a TM $N_M$
that on blank tape halts with blank tape.  If not, it outputs a TM
$N_M$ that on blank tape outputs $e(M)$ and halts.  Now by using the
Recursion Theorem we know that there exists a TM $M'$ that computes
the same function as that of $f(M')$.  If $M' \in L$, then the
function computed by $M'$ on blank tape outputs $e(M')$ while the function
computed by $f(M')$ outputs $\Lambda$.  If $M' \not\in L$, then the
function computed by $M'$ on blank tape outputs anything except
$e(M')$ while the function computed by $f(M')$ outputs $e(M')$.  Hence
we have reached a contradiction, and $L$ must not be recursive.

\item NONE.  A problem from the quiz review was to show that $TOT \equiv_m \{M : L(M)$ is infinite $\}$.  Since $TOT$ is neither r.e.\ nor co-r.e., this
implies that this language is also neither r.e.\ nor co-r.e.

\item REC. Note that if a TM halts on all inputs within 5 steps, it
will never see the sixth character (or beyond) of its input.  So given
a TM as input, a decision procedure for this problem would simply
simulate $M$ for five steps on each possible string of length 5.  If
$M$ fails to halt on any of these strings within five steps, the
decision procedure outputs ``0'', otherwise it outputs ``1''.
\end{enumerate}

\item {\bf Problem:}
A Turing machine is said to be {\em non-erasing} if it never changes
the content of a non-blank tape square.  (It may, as usual, write in
any blank tape square, but, having once done so, it will never
thereafter change the contents of that square.)  A {\it two-headed}
Turing machine has two read-write heads on its one-way infinite tape
(See Figure \ref{fig:thtm}).  SKETCH a proof that the ``halting
problem for two-headed, non-erasing Turing machines'' is undecidable.

(Hint: Give a reduction from the ordinary blank-tape halting problem,
where the machine produced by the reduction records successive
configurations without ever erasing anything.)

\begin{figure}[h]
\centerline{\mbox{\psfig{figure=head.ps,height=1in}}}
\caption{A Two-Headed Turing Machine}
\label{fig:thtm}
\end{figure}

{\bf Answer:} As suggested in the hint, we reduce the ordinary
blank-tape halting problem to the halting problem for two-headed
non-erasing TMs (THNETMs).  This means that for any given ordinary TM
$M$, we must construct a THNETM $M'$ that halts on blank tape iff $M$
does.  On blank tape, the first thing that $M'$ will do is to write
down the initial configuration of $M$: namely,
$(q_0,\underline{\Delta})$.  Then we write down the next configuration
of $M$ right next to the first configuration on the tape: we do this
by using one head to read the initial configuration and the other head
to write the next configuration.  Since the next configuration differs
from the first in only a few places (the state and the head position),
we can do this by essentially copying the configuration, except for
these two modifications.  We continue this process of reading the
current configuration with one head and writing the next with the
other until we write a configuration containing the halt state $h$.
If this ever occurs, the THNETM halts.  Hence $M'$ will halt on blank
tape iff $M$ does, and the reduction is complete.  Clearly there are a
lot of details to be worked out, but we only wanted a sketch of the
proof.

Common errors included failing to explain how to keep track of the TM
head position in the THNETM and how to copy blocks of text with the
THNETM without keeping track of where the THNETM was in the copy
(especially since the THNETM can't write on non-blanks!).  Another
mistake was misreading the problem to mean that the halting problem
was unsolvable BY THNETM's, not that the halting problem FOR
(i.e. about) THNETM's was unsolvable.


\item {\bf Problem:}
Let $L = \{ M$ (a Turing machine with input alphabet $\Sigma$) : $M$ halts on
input $\Lambda$, and takes more than 100 steps to do so $\}$.
\begin{enumerate}
\item  Show that Rice's Theorem does not apply to $L$.
\item  Show that $L$ is nevertheless undecidable.
\end{enumerate}

{\bf Answer:} 
\begin{enumerate}
\item Rice's Theorem does not apply to $L$ because ``$M$ halts on
$\Lambda$ and takes more than 100 steps to do so'' is not a language
property.  To prove this, consider a machine $M$ that checks to see if
its input is $\Lambda$, halts if it is, and doesn't halt otherwise.
So $L(M) = \{ \Lambda \}$, but $M$ doesn't halt on $\Lambda$ in more
than 100 steps, so it doesn't satisfy the property.  We can also
create a machine $M'$ that does the same thing as $M$, except that it
wastes 100 steps before checking its input.  Then $L(M') = \{ \Lambda
\}$, and $M'$ does satisfy the property.  Since we have $M$ and $M'$
such that $L(M) = L(M')$, but $M'$ satisfies the property and $M$ does
not, the property is not a language property.

\item We can show that $K_2 \mless L$.  Our reduction function $f$, on
input $M$ produces a machine $N_M$ that on input $x$ wastes 101 steps, then
simulates $M$ on $x$.  Hence if $M$ halts on $\Lambda$, then $N_M$
will halt on $\Lambda$ in more than 100 steps; if $M$ does not halt on
$\Lambda$, neither will $N_M$.  Thus $M \in K_2$ iff $f(M) = N_M \in
L$, which proves that $K_2 \mless L$.  Since $K_2$ is undecidable, we
conclude that $L$ must also be undecidable.
\end{enumerate}

\item {\bf Problem:}
Prove the the Post Correspondence Problem over a one-letter alphabet
is decidable.
That is, show that the problem is decidable in case all the strings
$\alpha_i$ and $\beta_i$ appearing in all the pairs of all instances
of the problem are elements of $\Sigma^*$, where $|{\Sigma}| = 1$. (Hint:
No complicated Number Theory is needed!)

{\bf Answer:}  Note that since we are only dealing with a single
character alphabet, all we have to do is decide whether we can find
some $i_1, i_2, \ldots, i_k$ such that the length of $\alpha_{i_1} \ldots
\alpha_{i_k}$ is equal to the length of $\beta_{i_1} \ldots \beta_{i_k}$.
For each pair $(\alpha_i, \beta_i)$, let $x_i = |\alpha_i| - |\beta_i|$.
Clearly if $x_i = 0$ for some $i$, we have an answer to the PCP: then
$\alpha_i = \beta_i$.  We now claim that if there exists some $i, j$
such that $x_i > 0$ and $x_j < 0$, there is a solution to the PCP,
otherwise there is not.  Suppose that some such $i$ and $j$ exist.
Consider the solution formed by $-x_j$ copies of pair $i$ and $x_i$
copies of pair $j$.  Then the string of $\alpha$'s would have length
$-x_j |\alpha_i| + x_i |\alpha_j|$.  But then
\begin{eqnarray}
-x_j |\alpha_i| + x_i |\alpha_j| & = & (|\beta_j| - |\alpha_j|) |\alpha_i| + (|\alpha_i| - |\beta_i|) |\alpha_j| \nonumber \\
& = & |\beta_j| |\alpha_i| - |\beta_i| |\alpha_j| \nonumber\\
& = & |\beta_j| |\beta_i| -  |\beta_i| |\alpha_j| +  |\beta_j| |\alpha_i| - |\beta_j| |\beta_i| \nonumber \\
& = & -x_j |\beta_i| + x_i |\beta_j|. \nonumber
\end{eqnarray}
So the length of the string of $\beta$'s has the same length as the string of $\alpha$'s, and the PCP has a solution.

Now suppose no such $i$ and $j$ exist.  Then either all the $x_i > 0$ or all
the $x_i < 0$.  In the former case, for any $i_1, \ldots, i_k$,
$|\alpha_{i_1} \ldots \alpha_{i_k}| > |\beta_{i_1} \ldots \beta_{i_k}|$, so there
can be no solution to the PCP.  The latter case is similar.

\item {\bf Problem:}
Use the Recursion Theorem to prove the following rather strange claim.
There is some Turing machine $M$ that accepts exactly one string:
$e(M)$, the encoding of $M$.

{\bf Answer:} Construct a total recursive function $f$ that given a TM
$M$ produces another TM $N_M$.  The TM $N_M$ will check whether its
input is $e(M)$ or not; if so, it will halt, otherwise it loops
forever.  Hence $L(N_M) = \{e(M)\}$.  The Recursion Theorem tells us
that for any total recursive function $f$ mapping Turing Machines to
Turing Machines, there exists some $M$ such that $L(M) = L(f(M))$.
Therefore, for this particular function $f$, there must exist some $M$
such that $L(M) = L(f(M)) = L(N_M) = \{e(M)\}$.

Some students misstated the Recursion Theorem.  When we said that the
Recursion Theorem implied a fixed point, we did not mean that there
exists some $M$ such that $M = f(M)$ (i.e.\ the TM given as input
equals the TM output).  The fixed point is in terms of the languages
accepted by the TMs, not the TMs themselves.
\end{enumerate}



\end{document}





  
