\documentstyle[12pt,twoside]{article}
\setlength\itemindent{0.1in}
%\setlength\topmargin{0in}
\setlength{\itemsep}{0in}
%\setlength{\oddsidemargin}{0.4in}
%\setlength{\evensidemargin}{-0.2in}


\setlength{\topmargin}{-.2in}
\setlength\oddsidemargin{0.1in}
\setlength\evensidemargin{-0.1in}
\setlength\parindent{0.0in} 
\setlength\textwidth{6.3in}
\setlength\textheight{8.4in}
\setlength{\parskip}{\medskipamount}

\newenvironment{newmath}{\begin{displaymath}%
\setlength{\abovedisplayskip}{4pt}%
\setlength{\belowdisplayskip}{4pt}%
\setlength{\abovedisplayshortskip}{3pt}%
\setlength{\belowdisplayshortskip}{3pt} }{\end{displaymath}}

\begin{document}


{\bf Question:} Show that $TOT \equiv_m \{M : M$ halts on infinitely many arguments $\}$
(Recall that $A \equiv_m B$ if $A \leq_m B$ and $B \leq_m A$).

{\bf Answer:} 
We saw in class what the canonical order was.
For instance in $\{0,1\}^*$ all the inputs are ordered as:
	$0, 1, 01, 10, 11, 001, 010, 011, \ldots$
For a general alphabet $\Sigma$ we can similarly order all the strings
	so that $\Sigma^*$ consists of  $s_1 < s_2 < s_3 < \ldots$
For simplicity let $L$ denote the set 
	$\{M : M$ halts on infinitely many arguments $\}$.
Recall also that by definition 
	TOT $ = \{ M : L(M)=\Sigma^*\}$. 
Recall also that for any string $x$, $|x|$ is the length of $x$
   so that for instance $ |001| = 3 $.

We have to prove the two directions:
	$TOT \leq_m L$ and $L \leq_m TOT$.

\begin{itemize}
\item {\bf $TOT \leq_m L$:}. \\
Let $M$ be {\em any} Turing machine. We need to construct
a Turing machine $M'$ such that:
	$M \in$ TOT iff $M' \in L$.

\begin{itemize}
\item {\bf Construction of $M'$:}\\
The idea of the construction of $f(M) = M'$ will be
	 ``$M'$ runs $M$ sequentially (i.e. in series) over all inputs''
Here is how $M'$ works:
	
``On input $x$ run the following simulation for a exactly $|x|$ steps:	
  Run $M$ on $s_1$. 
     As soon as (and only if) $M$ halts on $s_1$, proceed and
  run $M$ on $s_2$. 
     As soon as (and only if) $M$ halts on $s_2$, proceed and
  run $M$ on $s_3$. 
     As soon as (and only if) $M$ halts on $s_3$, proceed and ...

After having followed this protocol for $|x|$ steps $M'$ halts 
  if, in this simulation, $M$ just halted on the $s_i$ it was currently working on;
  else, $M'$ loops forever (i.e. does not halt).''
  
Let me emphasize that the previous simulation is run for exactly $|x|$ steps:
in particular if $M$ does not halt on $s_1$ $M'$ never halts!!

Also it is clear that the construction $M\rightarrow M'$ is totally recursive: 
we just defined this construction for all $M$ !!

\item {\bf Proof of $M \in $ TOT iff $M' \in L$:}
A notation first: Foe all $i\geq 1$ let $n_i$ denote the number of steps
that $M$ runs on input $s_i$ before halting. ($n_i= \infty$ if $M$ does not halt on $s_i$.)
 \begin{itemize}
 \item Assume that $M \in $ TOT. 
   Then $M$ halts On $s_1$ in a finite
    number  $n_1$ of steps
   In the same way it halts on $s_2$ in a finite
    number  $n_2$ of steps. Generally speaking it halts
    on $s_i$ in a finite number $n_i$ of steps.
  
  We then check that for all $i\geq 1$ the string $1^{n_1 +\ldots+ n_i}$ is in $M'$.
  Hence $L(M')$ is infinite which means that $M'$ is in $L$.

 \item Assume that $M \not \in $ TOT. 
  By hypothesis $M$ does not halt on all inputs. Let $i$ be the smallest index
  for which $M$ does not halt on $s_i$ (i.e. the first $i$ for which $n_i$ is infinite).
  We then see that, for all inputs $x$ of length
  bigger then $n_1 + n_2 + \ldots + n_{i-1}$,
  $M'$ does not halt on $x$. (Because at this point $M'$ is engaged in the simulation
   of $M$ on $s_i$ which never terminates!) Hence $M'$ halts only for finitely many
  inputs i.e. $M'\not \in L$.
 \end{itemize}

\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\item {\bf $L \leq_m TOT$:}. \\
Let $M$ be {\em any} Turing machine. We need to construct
a Turing machine $M'$ such that:
	$M \in L$ iff $M' \in $ TOT.

\begin{itemize}
\item {\bf Construction of $M'$:}\\
The idea of the construction of $f(M) = M'$ will be
	 ``$M'$ runs $M$  in parallel  over all inputs''.

I assume fixed a given way to dovetail through all inputs (For instance 
12 123 1234 12345 123456 ... which means that we simulate one step
of the machine $M$ on input $s_1$, then one step on input $s_2$, then back one step
on $s_1$, ...)

Here is how $M'$ works:
	
``On input $s_i$ run $M$ on parallel on all inputs (i.e. dovetail), and wait
for the $i$th time at which $M$ halts in this parallel simulation.

$M'$ halts as soon as (if it ever happens!) this $i$th time happens.''

We see that the construction $M\rightarrow M'$ is totally recursive: 
we just defined this construction for all $M$.

\item {\bf Proof of $M \in L$ iff $M' \in $ TOT:}

 \begin{itemize}
 \item Assume that $M \in L$.
   Then, in the unstopped parallel simulation of  $M$ on all inputs, $M$ 
   will stop an infinite number of times. Hence, when running on $s_i$,
   $M'$ will eventually halt. Hence $\forall i, s_i \in L(M')$ i.e.,
   $M' \in $ TOT.

\item  Assume that $M \not \in L$.
   This means that $M$ halts on only a finite number of inputs, say $i$.
   But then on input $s_{i+1}$ $M'$ does not halt so that $M' \not \in$ TOT.
 \end{itemize}

\end{itemize}
\end{itemize}

\end{document}
