\documentclass[11pt]{article}
\usepackage{amsfonts}
\usepackage{fullpage}
%\include{commands}
%\include{complexity-classes}
%\include{style/commands}
%\include{header}
\usepackage{graphicx}
\usepackage{graphicx}
%\topmargin .25in
\textheight 9in
\oddsidemargin .25in
\textwidth 6in

\begin{document}

%\begin{center}
\noindent {\bf COMS 3261, Computer Science Theory (Fall 2023): Assignment 3}\\
\noindent {\bf Due on Gradescope 11:59pm, Monday Nov 20, 2023}\\
%\end{center}

\noindent {\bf Instructions}
\begin{itemize}
\item The total number of points is 55 and there are two pages. Submit your solutions in pdf format. Late homeworks will {\bf not} be accepted. 
\item You can discuss with TAs, the prof, and other students, but please acknowledge them at the beginning of each problem. All solutions must be written in your own words. 
\item You should be able to solve questions 1-4a already; the material required to solve questions 4b and 5 will be covered Nov 8 and Nov 13. 
\end{itemize}


\noindent {\bf Problems}


\begin{enumerate}



\item (10 points) Give a {\bf formal} {\bf description} of a one or two tape input-output Turing machine that takes a string $w \in \{0,1\}^*$ 
as input and halts with $w^R$ (the reverse of the string $w$) on the first tape.
For example, if the tape initially contains the input ``11001'' (followed by
blanks), then after halting the tape should be
contain `10011' (followed by blanks).
Include a brief high level description of your TM.

%1. First we scan head 1 right til we hit a blank symbol, replacing the leftmost symbol
%`a' by the symbol `$a' (to mark the left end of the tape). Then when we hit the blank we 
%move head 1 one cell to the left and proceed to step 2.
%2. We loop until we see the symbol `$a' for some $a \in \{0,1\}$ under head 1.
%Write the value pointed to by head 1 to cell pointed to by head 2. Then move
%head 1 one cell to left and head 2 one cell to the right.
%3. Finally if head 1 points to `$0' then we write 0 on the cell pointed to by head 2 and halt; otherwise if head 1 points to `$1' then we write 1 on the cell pointed to by head 2 and halt.


%\bigskip

%If S' subseteq S and S' is uncountable, is S uncountable? Prove your answer

\item (10 points) Prove that for every infinite set $S$, the following are equivalent:
\begin{itemize}
%\item[(i)] There exists $h: S \rightarrow \mathbb{N}$ that is
%one-to-one and onto (i.e., $h$ is bijective).
\item[(i)] There exists a function $g: \mathbb{N} \rightarrow S$ that is onto
(i.e., $g$ is surjective).
\item[(ii)]  There exists a function $f: S \rightarrow \mathbb{N}$ that is one-to-one 
(e.g., $f$ is injective).
\end{itemize}

%Let $S$ be an infinite set. We first prove (iii) implies (ii).
%Let $f$ be a one-to-one map from $S$ to $\mathbb{N}$. Our function $g$ will
 %be a modified version of the inverse of $f$. For each $i \in \mathbb{N}$,
%let $g(i)$ equal $f^{-1}(i)$ if the inverse exists and otherwise map $i$ to
%some canonical element in $S$. Note that $g$ is onto since $f$ mapped every element
%in $S$ to a natural number. 

\item (10 points) Consider the language $L_{\rm DFA}$ which accepts
an input $w$ if $w$ is an encoding of a DFA $A$, where
$A$ accepts at least one input $x \in \{0,1\}^*$.
\begin{itemize}
\item[a.] Prove that $L_{\rm DFA}$ is decidable by giving a {\bf high-level} {\bf description} of a TM that always halts and that accepts exactly the strings in $L_{\rm DFA}$.
\item[b.] In one or two sentences, explain what goes wrong with your algorithm if you were to
apply similar ideas to try to prove that $L_{\rm TM}$ is decidable (where $L_{\rm TM}$ accepts the set of encoding of TMs that accept at least one input).
\end{itemize}

\item (15 points) Let $L_{\rm pair}$ be the set of all encodings of Turing machines ${\rm <}M{\rm >}$
such that there is a pair of consecutive binary numbers
that are both accepted by $M$.
(For example, if a Turing machine $M$ accepts both 100 and 101 then
${\rm <}M{\rm >}$ is in $L_{\rm pair}$.)
\begin{itemize}
\item[a.] Prove that $L_{pair}$ is recognizable (r.e.) by giving a {\bf high-level description} of a Turing Machine that accepts $L_{pair}$.
\item[b.] Prove that $L_{pair}$ is not decidable (not recursive).
\end{itemize}


%\item (10 points) Let $L_{\rm Prime} = \{{\rm <}M{\rm >} ~|~ {\rm the}~{\rm number}~{\rm of}~{\rm strings} ~{\rm accepted}~{\rm by}~M~{\rm is}~{\rm prime}\}.$
%Classify this language as either (i) decidable, (ii) recognizable but not decidable, or (iii) not recognizable. Prove your answer. You may give a {\bf high-level description} of any TM programs used in your proof. (You should not use Rice's theorem.)


\item Classify each of the following languages
as either: (i) recursive, (ii) recursively
enumerable but not recursive, or (iii) not recursively enumerable.
Prove your answers. You may not appeal to Rice's theorem.
\begin{itemize}
\item[a.] Given the encoding of a Turing Machine $M$,
is there a string of every even length for which $M$ halts?
\item[b.] Given the encoding of a Turing Machine, $M$, is the size of the
language accepted by $M$ divisible by 3?
\item[c.] Given the encoding of a Turing Machine $M$, and input $w$,
does $M$ on input $w$ ever move its tape head to the left at least two
times consecutively?
\item[d.] Given the encoding of a Turing Machine $M$,
a state $q$ and a string $w$, does $M$ ever reach state $q$
when run on input $w$?
\item[e.] Given a CFL $L$ (described by a context free grammar),
is the complement of $L$ also a context free language?
\end{itemize}


\end{enumerate}

\newpage

\bigskip

\noindent{\bf Instructions on level of detail required for TM constructions}

\bigskip
Below is a description of the level of detail expected for describing
TMs and programs.
Please read the section in Sipser book on ``Terminology for Describing TMs'' for
more information. 

\begin{itemize}
\item {\bf Formal Level Description:} Unless otherwise mentioned, you should use the standard definition of a TM (with a single tape, and a single head that can move either left or right in each step). Provide all transitions in detail. 
%You can use the convention that any omitted transitions can be assumed to go to $q_{\rm reject}$ state. Any other conventions or abbreviations that you use must be fully explained. 
(Note in the first question you are asked to give a formal level description of an input-output TM, but you are allowed to use either a single-tape TM or a two-tape TM. If you give a two-tape TM, it should again be the standard one, with two tapes, and two heads, each of which can move either left or right at each step. And again you should provide all transitions in detail.)

\item {\bf Implementation Level Description:} You may use any of the equivalent models of TMs discussed in class or in the book (e.g., multitape TMs, nondeterministic TMs). You can use low-level subroutines like the ones you saw in class (e.g., insert a blank symbol and shift rest of the tape content to the right; head can move left or right or stay in place at each step). 

\item {\bf High Level Description:} You do not need to discuss the mechanics of an actual TM (tapes, states, the transition function). Instead you can present your algorithm in pseudocode. Pseudocode is a simpler version of a programming code that is given in plain English which uses short phrases to write code for a program before it is implemented in a specific programming language. Make sure you algorithm is clear and well defined (e.g., what is the input to the program, what are the main subroutines/loops/steps; specify the data structure(s) being used (variables, arrays, etc). 

\end{itemize}

\medskip


\end{document}

