\documentstyle[12pt,twoside,amssymb]{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{lecture17}{Notes on Lecture 17}{March 13, 1992}

\reading{Martin 18.1, 18.2}

\section{Examples of Turing-Acceptable and Recursive Languages}

\begin{newexamp}[Any regular language is recursive]
\label{expl-1}
To see this, let $L$ be a regular language and
consider a DFA, $M$, that accepts $L$.
Let Turing machine $M'$, on any input $x$, simulate the operation of
$M$ on $x$.  
It can do this, for example, by keeping the state of $M$ in its own
finite state control.
If the simulated machine $M$ ends up in an accepting state, then $M'$
halts and outputs $1$; otherwise, $M'$ halts and outputs $0$.
\end{newexamp}

\begin{newexamp}[Any context-free language is Turing-acceptable]
\label{expl-2}
Let $L$ be a context-free language, and let $G$ be any context-free
grammar that generates $L$.
On input $x$,
let Turing machine $M$ try all the derivations of $G$ in some order.
(Lots of bookkeeping will be needed.)  If it ever finds a derivation
for $x$, then $M$ halts; otherwise, $M$ just keeps searching.
Note that the grammar $G$ is ``hard-wired'' into the Turing machine
$M$, not provided as input.
This could mean, for example, that $M$ is designed so that the first
thing it does is write out the description of $G$ on the tape, so it
can use the description in constructing the various derivations.
No special encoding should be needed here, since there is only one
grammar $G$ to be manipulated, 
and the Turing machine can be designed with a big enough tape
alphabet to allow direct representation of all the grammar symbols in $G$.

An alternative approach is to design a nondeterministic Turing machine
to simulate a given NPDA that accepts the language $L$.
\end{newexamp}

\begin{newexamp}[In fact, any context-free language is recursive]
\label{expl-3}
Recall that we have already studied an informal procedure for deciding
whether any string $x$ is in a particular context-free language.
It was based on a Chomsky form grammar $G$, and used the fact that if
$x$ is in the language, it has a derivation in $G$ of bounded length.
So it's only necessary to try all of those derivations.
This procedure can be programmed on a Turing machine.
Again, the (Chomsky form) grammar is hard-wired in.
This procedure gives an answer of yes or no, as appropriate, which can
be converted by the Turing machine to output $1$ or $0$.
\end{newexamp}

\section{Turing-Acceptability, Recursiveness, Etc., for Domains Other
Than Strings}

In the literature, you will often find discussion about recursiveness,
Turing-acceptability, partial recursiveness, etc., for domains other
than just strings.
These terms are given meanings via {\em encodings} of the elements of
the various domains into strings.

The most common case is the set of natural numbers, $\nat = \{0,1,2,\ldots\}$.
Natural numbers can be represented as strings, for example, in unary
or in binary.
A unary representation might just encode each natural number as a
string in ${1}^*$, i.e., over a one-symbol alphabet.
In this case, a natural encoding would probably be a bijective mapping
between $\nat$ and ${1}^*$.
On the other hand, the usual binary representation does not yield a
bijective mapping:  via leading zeroes, there are infinitely many
strings that are normally taken as representing the same natural
number.
It is not convenient for us to use multiple encodings for the same
number;
therefore, we choose a standard encoding for each number, e.g., one
having no leading zeroes.  This means that the set of encodings is not
the entire set $\{0,1\}^*$, but only a proper subset.
(Note that it is a recursive subset, however.)

Given this encoding, we define a set $S \subseteq \nat$ to be {\em
Turing-acceptable} (resp., {\em recursive}) provided that the set of
encodings of elements of $S$ into strings is 
Turing-acceptable (resp., recursive).
Also, a function $f: S \subseteq \nat \rightarrow \nat$ is {\em
partial recursive} provided that the corresponding encoded function
from the set $e(S)$ of encodings of $S$ elements to the set $e(\nat)$
of encodings of natural numbers is partial recursive.
We take the total recursive functions over the natural numbers to be
those that are partial recursive and total; but note that here we
don't want totality for all strings, but just for all (encodings of)
natural numbers.

\begin{newexamp}
\label{expl-4}
The function $f(n) = n + 1$ is a total recursive function from $\nat$
to $\nat$.
Also, extending the definitions to multi-argument functions in the
natural way, the usual arithmetic addition and multiplication
functions are also total recursive.
Subtraction and division are not total recursive functions from $\nat
\cross \nat$ to $\nat$, however, because they can take us outside this
domain.  But subtraction is a total recursive function on the larger
domain of positive and negative integers ${\Bbb Z}$.
(This needs an encoding.)
Also, division is a total recursive function on the domain of positive
rational numbers, again via an encoding (based on reduced form of fractions, 
e.g., so the encoding is unique).
The division function is partial recursive on the domain ${\Bbb Q}-\{0\}$
of non zero rational numbers
(division by 0 is not a legal operation).
\end{newexamp}

\begin{newexamp}[An open problem]
\label{expl-5}
Let $X$ be the set of natural numbers greater than or equal to $1$ for
which the following procedure terminates:

``while $x \neq 1$ do \\
      if $x$ is odd then $x := 3x + 1$ \\
      if $x$ is even then $x := x/2$
  halt''

Is the set $X$ recursive?
Certainly $X$ is Turing-acceptable, because a Turing machine can be
designed to run exactly the procedure above, and halt if it
terminates.
But how can a Turing machine tell if the procedure is not going to
halt for a particular input?

In fact, it is not currently known whether or not this set $X$ is
recursive; it is even possible that $X = \nat - \{ 0 \}$.
\end{newexamp}

Other common domains for considering recursiveness of languages and
functions are various kinds of {\em machines} and also {\em grammars}.
For example, we can discuss recursive sets of DFA's.
This involves an encoding of DFA's as strings over some alphabet
$\Sigma^*$.  The ideas are similar to those used in the encoding for
the universal Turing machine $T_U$: a fixed alphabet is used to encode
symbols from arbitrary alphabets, and also arbitrary states.  As for
the encoding of the natural numbers, DFA's are typically encoded by
only a subset of all the strings over $\Sigma$.
(Again, it's a recursive subset -- check this as an exercise.
It involves checking for various well-formedness conditions, plus
checking for determinism, etc.)
The definitions of Turing-acceptability, recursiveness, etc., are then
made analogously to the way they are made for $\nat$.

The same general approach is used for other kinds of machines like
PDA's and Turing machines, and also for context-free grammars.

\begin{newexamp}[Emptiness problem for DFA's]
\label{expl-6}
Consider $\{ M : M \mbox{ is a DFA and } L(M) = \emptyset \}$.
This is a recursive set of DFA's since given an encoding of a DFA, a
Turing machine can, by a searching algorithm, answer $1$ if nothing is
accepted and $0$ if something is.
\end{newexamp}

\begin{newexamp}[Equivalence problem for DFA's]
\label{expl-7}
Consider 
$\{ < M_1, M_2 > : $  $M_1$ and $M_2$ are  DFA's with the same alphabet
$\Sigma$ such that $L(M_1) = L(M_2) \}$.
(A technicality:
Here, we are writing the pair of DFA's within braces to indicate that
they comprise a single argument for a 1-argument Turing machine, where
the domain of the argument is a pair (here, of DFA's with the same
alphabet).  We might like to think of these as two arguments for a
2-argument Turing machine, but then we have to specify a domain for
each argument.  We would probably say that the domain is just DFA's,
but then the language we are recognizing would be the set of pairs of
DFA's with the same alphabet and also the same language.  This seems a
little bit messier.)
A Turing machine can do state minimization on both arguments, and then
check isomorphism of the results.
\end{newexamp}

\begin{newexamp}
\label{expl-8}
There exists a total recursive function $F:$ NFA's $\rightarrow$ DFA's
yielding the same accepted language.
This function can be computed by a Turing machine that carries out the
subset construction, based on a natural encoding of NFA's and DFA's.
\end{newexamp}

\begin{newexamp}[Emptiness for context-free languages]
\label{expl-9}
$\{ G : $  $ G$ is a context-free grammar such that $L(G) = \emptyset \}$ is a recursive
set.
The procedure involves considering ``small'' derivation trees, as done
in the CFL section of the course.  But now (unlike earlier, when we
were showing that all CFL's are recursive), we can't assume that $G$
is in Chomsky form.
The Turing machine needs first to translate $G$ into Chomsky form,
using procedures such as those done two weeks ago in class.
Then it examines small derivation trees in the new grammar.
\end{newexamp}

\begin{newexamp}
\label{expl-10}
There is a total recursive function $f : $ CFG's $\rightarrow$ NPDA's,
which gives an NPDA accepting the same language that the grammar
generates.
This function can be computed by a Turing machine $M$
using either the top-down or bottom-up parsing procedures studied in class.
This Turing machine works in terms of encodings of the grammar
and the machine.
\end{newexamp}

A slightly more complicated example is the following:

\begin{newexamp}[The uniform membership problem for DFA's is recursive]
\label{expl-11}
Recall that Example \ref{expl-1} did the membership problem for any
{\em particular} regular language.
Now we want something more general:
$\{ <M, x>  : $ $M$ is a  DFA and $x$ is a string over the alphabet of $M$ such that $ x \in L(M) \}$.
The Turing machine gets an encoding of the pair, i.e., an encoding of
both the machine and the string into a single alphabet.  It simulates
the running of $M$ on $x$, in a way that is analogous to the operation
of the universal Turing machine.
If the simulation reaches an accepting state, the Turing machine
halts and outputs $1$; otherwise (if it reaches a non-accepting state),
the Turing machine halts and outputs $0$.

Note the crucial difference between this an Example \ref{expl-1}.  In this
case, the DFA isn't hard-wired in, but must be interpreted from the
encoding.
\end{newexamp}

\begin{newexamp}[The uniform membership problem for CFG's is recursive]
\label{expl-12}
Given an arbitrary pair $<G,x>$, consisting of a context-free grammar
and a string over its terminal alphabet,
a Turing machine can put the grammar in Chomsky form and then examine
short derivations as in Example~\ref{expl-2}.
\end{newexamp}

Other examples of recursive problems are the totality and subset
problem for DFA's.
Totality is undecidable for CFG's, however; we have not yet developed
proof methods to show this.
Likewise, the emptiness problem and the uniform membership problem for
Turing machines are undecidable.

\section{Basic Properties of Turing-Acceptable and Recursive Sets,
Recursive and Partial Recursive Functions}
\label{sec:R.E.}

Now we go back to considering just strings, and study some general and
basic relationships between the concepts of Turing-acceptability,
recursiveness, etc.
(Note that the same results also hold for other domains besides strings.)
The only relationship we have shown so far is that all recursive
languages are Turing-acceptable.

\begin{theorem}
\label{thm:rec-comp}
The set of recursive languages is closed under complement.  
(That is, if $L$ is recursive, then $\complement L$ is recursive.)
\end{theorem}

\begin{proof}
If $M$ decides $L$, let $M'$ simulate $M$, reversing outputs 0 and 1.
Then $M'$ decides $\complement L$.
\end{proof}

Also note that the recursive languages are closed under union and
intersection, by a similar argument.
Given $M_1$ and $M_2$, Turing machines deciding two languages,
a new Turing machine can simulate both, one after the other, and
output the correct Boolean function of the two answers.
Alternatively, the simulating machine could simulate them in parallel.
This parallel simulation is not as simple as the corresponding
simulation for regular languages (where we just kept pairs of states,
updating them together), because the heads of the two machines can
move in different patterns.
Therefore, we need to do a more complicated, {\em dovetailing}
simulation, simulating alternate steps of the two machines, and
carrying out a lot of bookkeeping to keep the two computations
straight.

\begin{theorem}
\label{thm:re-co-re}
$L$ is recursive iff both $L$ and $\complement L$ are Turing-acceptable.
\end{theorem}

\begin{proof}
First suppose $L$ is recursive.  Then $L$ is Turing-acceptable by
Theorem~1 of Handout~20.  Also, by Theorem~\ref{thm:rec-comp}, $\complement L$
is recursive, so (again by Theorem~1 of Handout~20) $L$ is
Turing-acceptable.

Conversely, suppose that both $L$ and $\complement L$ are
Turing-acceptable.
Then we have machines $M_1$ and $M_2$, accepting $L$ and $\complement
L$, respectively.
That is, $L = \{ x : M_1 \mbox{ halts on } x \}$,
and $\complement L = \{ x : M_2 \mbox{ halts on } x \}$.
A simulating Turing machine, on input $x$,
can run $M_1$ and $M_2$ in dovetailed fashion,
both on input $x$.  Exactly one will halt.
Return 1 if $M_1$ halts, 0 if $M_2$ halts.

Note that we must dovetail the two machines.
Unlike in the case for union and intersection, we are not free
here to run the two machines sequentially.  This is because neither is
guaranteed to terminate.
\end{proof}

\end{document}
