# CMPSCI 601: Theory of Computation

### David Mix Barrington

#### Solutions posted Wed 2 July 2003

Problem text in black, solution text in blue.

• Question 1 (10): Define EQNFA to be the set of pairs (N1,N2) such that N1 and N2 are NFA's such that L(N1)=L(N2). Argue that EQNFA is decidable. Estimate the running time of your algorithm on input of size n.

The following algorithm decides EQNFA:

• Construct DFA's D1 and D2 such that L(N1) = L(D1) and L(N2) = L(D2) respectively.
• Answer the EQDFA question for D1 and D2 by constructing a new DFA that decides the symmetric difference of L(D1) and L(D2) and testing this DFA for emptiness.

If the original NFA's have n states each then the DFA's might have as many as 2n states after the subset construction. The symmetric difference DFA might have as many as 22n states, and testing it for emptiness would be a REACH question on a graph of this size, solvable in 2O(n) steps.

• Question 2 (40): This question concerns primitive recursion. You may assume any of the results about the programming language Bloop proved on homeworks #2 and #3 from the Spring 2003 course.

• (a,20) Let f(n) be any primitive recursive function. Prove that every function in FDTIME(f(n)) (that is, every function computable by a TM in time O(f(n))) is primitive recursive.

Let h(n) be a function in FDTIME(f(n)), so that h(n) is computable by a Turing machine M in O(f(n)) steps -- for definiteness we'll say cf(n) steps for some fixed number c. We know that a Bloop program, with a variable x representing a configuration of M, can compute the function nextConfig(x) that returns a number representing the configuration representing M after running one step from configuration x. It's also easy in Bloop to test a configuration to see whether it has halted (and if so to extract its output), and to create a start configuration for a given input. So we may have a program:

``````        program runM(n) {
x = startConfig(n);
loop cf(n) times {
x = nextConfig(x);
if halted(x) return output(x);}
return 0;}
``````

This Bloop program will return h(n) -- we'll never reach the return(0) at the end because M is guaranteed to halt in cf(n) steps but it might make our compiler happier.

• (b,20) Let f be any primitive recursive function from Nk to N. Prove that there is a primitive recursive function g(n) such that f is in FDTIME(g(n)).

There's a simple way to do this from a Bloop program P that computes f. We alter P as follows:

• Declare a new variable "time"
• Set "time" to 0 at the start of the program
• Add a statement "time++" after every statement of P
• Output "time" at the end of P

This computes the number of Bloop steps rather than the number of Turing machine steps, of course. But if we translate the Bloop program into a TM and back again, we'll get a Bloop program that takes at least as many Bloop steps as does the TM that simulates the original Bloop program. If we let this be P and carry out the conversion above, we'll get a "time" program that bounds the time of the original Bloop program.

• Question 3 (30): Each of the following languages is either recursive, r.e.-complete, or not r.e. at all. Determine which it is and justify your answer. In each case the Turing machines should be considered to be one-tape machines, that indicate their output only by their state when they halt. (Clarification made 30 June 2003.)

• (a,10) The set of one-tape Turing machines M such that M never writes a 1 on the tape when started on any valid input.

This is not r.e. as K-bar can be reduced to it. Given an input machine N, we want to create M so that N is in K-bar iff M never writes a 1 on the tape. To do this we have M erase its own input and then simulate N on input "N", with the following change -- we replace any "1" in N's alphabet by some other letter, and then have M write a 1 iff it finds that N has accepted. Then M will write a 1 iff N accepts "N" (no matter what the input is to M), and so M will be in the given language iff N is in K-bar. The function f taking M to N is clearly recursive, and reduces K-bar to the given language, so that language is not r.e. at all.

• (b,10) The set of one-tape Turing machines M such that M never changes any character on the tape when started on any valid input.

This language is recursive. Consider a machine M' that simulates M until or unless M wants to change a character on the tape, and rejects if it does. M is in the given language iff M' either halts or enters an infinite loop before rejecting, on any valid input. But M' is a two-way DFA, and following the analysis on HW#1 we can determine the language of inputs on which it rejects and then decide whether this language is empty. If it is, then M is in the given language, and if not, it isn't.

• (c,10) The set of one-tape Turing machines M such that there exists a string w such that M eventually writes a 1 when started on input w.

This language is r.e. but not recursive. It is r.e. because we can construct a nondeterministic Turing machine N that guesses a string w and then simulates M until or unless it writes a 1, accepting iff it does. Then L(N) is the given language, and we know that the language of an NDTM is always r.e. because the NDTM could be simulated by an ordinary TM.

We prove that the given language is not recursive by reducing K to it. Given a TM N, we let f(N) be a TM that erases its input, simulates N on input "N", and writes a 1 iff this computation accepts. (If "1" is in the alphabet of N, we replace it by a new letter in f(N).) Then N is in K iff f(N) writes a 1 on any input iff f(n) writes a 1 on all input, and we have reduced K to the given language.

• Question 4 (20): Prove the following variant of the Rice-Myhill-Shapiro Theorem from Lecture 8 (See also [P] Theorem 3.2 or Sipser Exercise 5.22.):

Suppose that A is a set of numbers such that if L(Mi) = L(Mj), then i and j are either both in A or both not in A. Also suppose that there is a recursive function f such that f is 1-1 and onto and for any string w, w is in A iff f(w) is not in A. Prove that A is neither r.e. nor co-r.e., that is, that neither A nor A-bar is recursively enumerable. (Correction made 26 June 2003.) Simply quoting from the proof of the RMS theorem, we know that if A is not equal to N or to the empty set, then (since it meets the other condition of the theorem) either K or K-bar must reduce to it.

Is it possible for A to be N or to be empty? No, because then the reduction from A to A-bar could not exist. If A were N then "w in A" would always be true, so "f(w) in A-bar" would have to always be true, which is impossible because A-bar would be empty. And if A were empty, then "w in A" would never be true, so "f(w) in A-bar" could also never be true, but it is true if f(w) exists.

So we know that either K reduces to A or that K-bar reduces to A. The given condition also tells us that A reduces to A-bar, and also that A-bar reduces to A because the function f is invertible and its inverse reduces A-bar to A. So we just check the two cases:

• If K reduces to A then A is not co-r.e. by the Halting Theorem. But then K-bar reduces to A-bar by the same function that reduces K to A. Since A-bar reduces to A and reduction is transitive, it follows that K-bar reduces to A, so that A is not r.e. either.
• If K-bar reduces to A, then A is not r.e. by the Halting Theorem. But then K reduces to A-bar, and since A-bar reduces to A it follows that K reduces to A and so A is not co-r.e. either.

In each case we have shown that A is neither r.e. nor co-r.e., and one of these two cases must hold by the proof of the RMS theorem.