# Solutions to Second Midterm Exam, Spring 2012

### Directions:

• Answer the problems on the exam pages.
• There are eight problems for 120 total points plus 10 extra credit. Actual scale was A = 98, C = 62.
• If you need extra space use the back of a page.
• No books, notes, calculators, or collaboration.
• The first six questions are true/false, with five points for the correct boolean answer and up to five for a correct justification of your answer -- a proof, counterexample, quotation from the book or from lecture, etc. -- note that there is no reason not to guess if you don't know.

Question text is in black, solutions in blue.

```  Q1: 10 points
Q2: 10 points
Q3: 10 points
Q4: 10 points
Q5: 10 points
Q6: 10 points
Q7: 30+10 points
Q8: 30 points
Total: 120+10 points
```

If C is any class of computers, such as DFA's, CFG's, LBA's TM, strange variant TM's, etc.:

• AC = {(M, w): M is a computer in C and w ∈ L(M)}
• EC = {(M): M is a computer in C and L(M) = ∅}
• ALLC = {(M): M is a computer in C and L(M) = Σ*}
• EQC = {(M, N): M and N are computers in C and L(M) = L(N)}
• A function f: Σ* → Σ* is a C-complementer if for any computer M in C, f((M)) is a representation (M') of a computer M' in C such that L(M') is the complement of L(M), that is, L(M') = Σ* ∖ L(M).
• If D is another class of computers, then SUBC,D = {(M, N): M is a computer in C, N is a computer in D, and L(M) ⊆ L(N)}. So, for example, SUBNFA,TM = {(M, N): M is an NFA, N is a TM, and L(M) ⊆ L(N)}.

A queue machine (QM) is a deterministic machine with a finite state set and one additional memory organized as a queue. At any time step the QM sees the next input character and the character at the front of the queue. Its move is to dequeue that character, move to the next input character (if any), enqueue zero or more characters, and change its state. It has and accepting and a rejecting final state, and it may continue computing after finishing its input.

A right-end Turing machine (RETM) has one or more tapes, each of which has a \$ as its leftmost character. The first tape has the input after the \$, and the others (if any) have blanks. The head of each tape starts on the leftmost blank on its tape. The RETM must satisfy the following rule -- on each tape the head must always be either on the rightmost nonblank character of its tape or on the leftmost blank character of its tape.

Recall that if A and B are two languages, A is mapping reducible to B, written A ≤m B, if there exists a function f: Σ* → Σ* such that for any string w, w ∈ A ↔ f(w) ∈ B. The languages A and B are mapping equivalent, written A ≡m B, if both A ≤m B and B ≤m A are true.

A language A is Turing recognizable (TR) if it equals L(M) for some Turing machine M. A is Turing decidable if A = L(M) for some Turing machine M that always halts. A function f is Turing computable if there exists a Turing machine M such that for any string w, M when started on w halts with f(w) on its tape.

• Question 1 (10): True or false with justification: The language SUBDFA,DFA is Turing decidable.

TRUE. (M, N) ∈ SUBDFA,DFA means ∀w: w ∈ L(M) → w ∈ L(N), or ¬∃w: w ∈ L(M) ∧ w ∉ L(N).

Build a DFA whose language is L(M) ∩ L(N)-bar, using the product construction. This machine is in EDFA (proven to be decidable in the book) if and only if (M, N) ∈ SUBDFA,DFA.

• Question 2 (10): True or false with justification: The language SUBCFG,DFA is Turing decidable.

TRUE: Similarly to the Question 1 solution, (G, D) ∈ SUBCFG,DFA if and only if the language L(G) ∩ L(D)-bar is empty. It is shown in the solved exercise 2.18(a) of Sipser that the intersection of a CFL and a regular language is a CFL. Since L(D)-bar is regular, L(G) ∩ L(D)-bar is a CFL and we can construct its CFG. (We can run a PDA in parallel with a DFA, using a PDA, and the constructions of Chapter 2 can give us a CFG for this language. We can thus decide SUBCFG,DFA using a decider for ECFG.

This was a hard question -- I don't remember whether I mentioned that particular closure result in lecture.

• Question 3 (10): True or false with justification: The language SUBTM,DFA is Turing decidable.

FALSE. ETM is shown undecidable in the book. We can prove that ETMm SUBTM,DFA. Our reduction function f takes (M) to (M, N), where N is a DFA that always rejects. With this f, (M) ∈ ETM ↔ L(M) = ∅ ↔ L(M) ⊆ ∅ ↔ (M, N) ∈ SUBTM,DFA ↔ f((M)) ∈ SUBTM,DFA.

• Question 4 (10): True or false with justification: The language SUBTM,DFA is Turing recognizable.

FALSE. We reduce the non-TR language ATM-bar to SUBTM,DFA. Given a Turing machine M and a string w, let f((M, w)) = (M', N, where again N is a DFA that always rejects, and M' is a TM that on input x, ignores x and runs M on w. With this f, (M, w) ∈ ATM-bar ↔ w ∉ L(M) ↔ L(M') = ∅ ↔ L(M) ⊆ ∅ ↔ (M', N) ∈ SUBTM,DFA ↔ f((M, w)) ∈ SUBTM,DFA.

• Question 5 (10): True or false with justification: The language AQM is Turing decidable.

FALSE. A QM can simulate an ordinary one-tape TM. Thus we can reduce the non-TD language ATM to AQM, proving that the latter is not TD.

If c and c' are two consecutive configurations of an ordinary one-tape TM, we want our QM to read c\$ off of the queue and simultaneously write c'\$ to the queue. It does this by copying characters that are away from the head and making small adjustments to the three-letter string around the head, as in the proof that the Post Correspondence Problem is undecidable. It must remember the last character it dequeued before it enqueues it, in case the following character is the head position.

The QM begins its simulation by enqueueing the character for the start state, reading in the input and enqueueing it, and enqueuing a \$. Now the initial configuration of the TM is on the queue. The QM now successively changes the queue to each succeeding configuration of the TM, until or unless the TM accepts or rejects.

• Question 6 (10): True or false with justification: The language ALLCFG and the complement of the language ATM are mapping equivalent.

TRUE. ALLCFGm ATM-bar using the following function f. Given any CFG G, f((G)) = (M, ε), where M, on any input, checks all strings in Σ* for membership in L(G) (using the decider for ACFG), accepting if it finds a string that is not in L(G). Thus (G) ∈ ALLCFG ↔ L(G) = Σ* ↔ ∀w: w ∈ L(G) ↔ ¬∃w: w ∉ L(G) ↔ M does not accept ε ↔ (M, ε) ∈ ATM-bar.

ATM-bar ≤m ALLCFG using the construction in Sipser that takes a Turing machine M and a string w, and builds a grammar G such that L(G) is the set of all strings that are not accepting computation histories of M on w. Then (M, w) ∉ ATM ↔ w ∉ L(M) ↔ ¬∃c: ACH(M, w, c) ↔ L(G) = Σ* ↔ (G) ∈ ALLCFG.

• Question 7 (30): These questions all deal with the definition of a C-complementer above.

• (a, 5): Demonstrate that a Turing computable NFA-complementer exists by explaining informally how it would work.

On input (N), create a DFA D with L(D) = L(N) using the Subset Construction. Then create a DFA D' with L(D') = L(D)-bar by changing all final states in D to nonfinal and vice versa. Then type-cast D' to an NFA N' and we have L(N') = L(N)-bar as desired.

Some people said that switching final and non-final states in the NFA gave you an NFA for the complement -- it doesn't.

• (b, 10): Assume that a Turing computable TM-complementer exists. Using this assumption (which we will prove to be false below), prove that every Turing recognizable language is Turing decidable.

Let M be an arbitrary TM. The TM-complementer f, by assumption, would map (M) to a TM description (M'), where L(M') = L(M)-bar. We can build a decider M'' for L(M) using this assumption. On input w, M'' creates M' and then runs M and M' in parallel on w, accepting if M accepts and rejecting if M' accepts. Since L(M) ∪ L(M') = Σ*, M'' always halts and is a decider.

We don't need the assuption that f is Turing computable, because if f just exists, then f((M)) = (M') exists for any M, and thus the M'' we defined exists and L(M) = L(M'') is a TD language.

• (c, 5): Explain why the existence of a Turing computable TM-complementer would contradict the Recursion Theorem.

The "fixed point version" of the Recursion Theorem says that if f is Turing computable, there exists a TM M such that f((M)) = (M') and L(M') = L(M). Since no language is its own complement, this f cannot be a TM-complementer.

The ordinary version of the Recursion Theorem says that if this Turing computable f existed, you could create a Turing machine M as follows: On input w, obtain own description (M) by the Recursion Theorem, compute (M') using f, and run M' on w. This forces L(M) = L(M') and contradicts f being a TM-complementer.

• (d, 5): Prove that no TM-complementer can exist, whether Turing computable or not.

Let U be the universal Turing machine, such that L(U) = ATM. If f were a TM-complementer, f((U)) would be the description of a TM M' such that L(M') would be ATM-bar. But ATM-bar is not Turing-recognizable and thus not the language of any TM.

• (e, 5): Does a Turing computable CFG-complementer exist? Justify your answer.

The simple answer is that no CFG-complementer can exist, Turing computable or not, because there are CFL's whose complements are not CFL's. For example, there is a grammar G whose language is the complement of {anbncn: n ≥ 0}, and f((G)) would have to be a CFG for this language, which we have proved not to exist.

A somewhat cuter answer is that with a Turing computable CFG-complementer and a decider for ECFG (which does exist), we could easily build a decider for ALLCFG. But ALLCFG is proven to not be TD in Sipser.

• (f, 10XC): Does a Turing computable LBA-complementer exist? Justify your answer carefully. (Recall that an LBA is a one-tape TM that never moves right of the area originally holding its input.)

It does exist, though no one proved this on the exam. We observed in lecture (following Sipser's proof that ALBA is TD) that given an LBA M with q states, a tape alphabet Γ of size k, and an input w of length n, there are only qnkn possible configurations of M. If M runs longer than this many steps, therefore, it will never accept. Clearly an ordinary TM can simulate M for that many steps on input w, rejecting w if M accepts and otherwise accepting w. But we need to show that an LBA can carry out this simulation. To do this, our simulating LBA N needs to simultaneously use its tape to simulate M on w and to maintain a counter that can go higher than qnkn. This is possible if N has a much larger tape alphabet, say size (q + k)(k + 1). For sufficiently large n, (k + 1)n is larger than qnkn. We interpret the tape of N as coding the configuration of M (using extra letters to record the head position) and a sequence of n "digits" in base k + 1. To simulate one step of M, N does the appropriate steps at the head position, then goes to the right of its tape and increments the counter, taking care of carries as necessary. If the counter gets back to all zeros before the simulated M accepts, then N accepts.

The LBA-complementer must take any LBA M and produce a desciption of the corresponding N.

• Question 8 (30): This question deals with the definition of right-end TM's above.

• (a, 10): Explain how to determine, from the state table (the δ function) of an ordinary Turing machine, whether it obeys the RETM restriction. Assume that your ordinary TM will start with the first tape's head to the right of the input, as is defined to be the case for an RETM.

The machine must never print a blank and move right, or print a non-blank and move left. Otherwise it obeys the rules, even if it stays put. Before its move, it has a non-blank to the left and a blank to the right. So if it stays put, it is still following the rule whatever it prints. If it prints a blank and moves left, it is on the left-most non-blank. And if it prints a non-black and moves right, it is on the leftmost blank.

• (b, 10): Explain why the language of any one-tape RETM is Turing decidable.

Each tape of an RETM operates like a stack, since changes to its content can occur only at the right end. A move left (after printing a blank) corresponds to a pop, and a move right (after printing a non-blank) corresponds to a push.

A PDA can thus be built to simulate an arbitrary one-tape RETM, though there are a couple of complications. The PDA must begin by reading its input an putting it on the stack, whereupon it is now written backward. It can then simulate the rest of the computation of the RETM. The language of the PDA is thus the reversal of the language of the language of the RETM. The language of the PDA is decidable, and so the language of the RETM is decidable as well.

• (c, 10): Explain why the language ARETM, where the RETM's are allowed to have more than one tape, is not Turing decidable.

As on HW#3, we can simulate an arbitrary one-tape TM using a machine with two stacks, passing characters from one stack to the other as the head goes past them. Given M, an arbitrary one-tape TM, we can create M', a two-tape RETM with L(M') = L(M), using the simulation of a stack by the tape of an RETM. The function taking (M) to (M') reduces ATM to ARETM, proving that the latter language is not TD.