# Solutions to Second Midterm Exam, Spring 2013

#### 10 April 2013

Question text is in black, solutions in blue.

### Directions:

• Answer the problems on the exam pages.
• There are eight problems for 120 total points plus 15 extra credit. Actual scale was A = 105, C = 69.
• If you need extra space use the back of a page.
• No books, notes, calculators, or collaboration.
• The first five questions are statements -- in each case say whether the statement is true or false and give a convincing justification of your answer -- a proof, counterexample, quotation from the book or from lecture, etc. You get five points for the correct boolean answer (so there is no reason not to guess if you don't know) and up to five for the justification.

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

Correction in orange added 20 March 2015.

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)}
• REGC = {(M): M is a computer in C and L(M) is a regular language}
• COMPC = {(M, N): M and N are computers in C and L(M) is the complement of L(N)}

The language DECIDER is the set {(M): M halts (either accepts or rejects) on every input}.

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.

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.

A stupid Turing machine (STM) has one tape which "wraps around" -- moving left from its leftmost cell takes you to its rightmost cell, and moving right from its leftmost cell takes you to its leftmost cell. It begins with the input string filling the entire tape.

A very stupid Turing machine (VSTM) is like an STM except that for some of its state-letter pairs it may replace the current cell with two cells, writing to both of them, instead of just writing to the current cell. Thus its transition function is δ (Q × Σ) ↔ (Q × (Σ ∪ (Σ × Σ)) × {L, R}).

The function S from N × N to N is defined as follows. Consider all the k-state Turing machines with tape alphabet {0, 1, blank} and consider all input strings in {0, 1}n. S(k, n) is the number of steps taken by the longest of any of the halting computations of any of these machines on any of these inputs. (This is similar to the "busy beaver function" but is not exactly the same thing.)

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

TRUE. The size of the tape never changes. On input w of length n, if the STM runs for more than |Q||Σ|n + 1 steps, it must have repeated a configuration and (since it is deterministic) it must be in a loop. So an ordinary TM can simulate the STM for that many steps and reject if it hasn't halted at the end of them.

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

FALSE.. ATMm AVSTM. We convert an arbitrary one-tape TM M into an equivalent VSTM M' by having it use the two-cell write to add a blank cell to the right end of the tape when needed. We also put markers on M' so that it will never use its wraparound. Then the reduction has (M, w) ∈ ATM if and only if (M', w) ∈ AVSTM.

• Question 3 (10): True or false with justification: Any regular language is the language of some STM.

TRUE. An STM can simulate a DFA by marking the first cell of its tape, simulating the DFA until it sees the first square again, then accepting if and only if the DFA is in a final state.

• Question 4 (10): True or false with justification: It is not true that REGCFGm REGTM.

FALSE. It is true that REGCFLm REGTM. Given a CFG G, our reduction function just needs to output a Turing machine MG that has the same language as G. On input w, MG can run the CKY algorithm, or the slower decision procedure for ACFG given in Sipser, to test whether w is in L(G). Thus (G) ∈ REGCFG ⇔ (MG) ∈ REGTM.

• Question 5 (10): True or false with justification: The set of all TR languages is countably infinite.

TRUE. Every TR language is L(M) for some Turing machine M. Every TM M is represented by a finite string (M) over {0, 1}. The set of strings over any finite alphabet is in bijection with N and thus is countably infinite. The (M) strings are a subset of this countably infinite set and are thus countable. It remains to show that the set of TR languages is infinite -- this follows, for example, from the fact that every singleton language {w} is TR.

• Question 6 (25): These questions use the definition of the language COMPC above.

• (a, 10) Prove that the language COMPNFA is Turing decidable.

COMPNFA = {(N, N'): L(N) = Σ* ∖ L(N')}. We need an always-halting TM that will decide whether the languages of N and N' are complements, given input (N, N'). It will first construct DFA's D and D' with L(D) = L(N) and L(D') = L(N') by the subset construction. Then it builds another DFA D'' such that L(D'') is the symmetric difference of L(D) and L(D') -- the set of strings that are in both L(D) and L(D'), or are in neither. Finally it searches the graph of D'' to see whether there is a path from its start state, with any labels, to any final state. If so it rejects, if not it accepts.

• (b, 15) Is the language COMPCFG Turing decidable? Prove your answer.

It is NOT Turing decidable. Let G be a fixed grammar with no rules, so that L(G) = ∅. Given any grammar G, define f(G) to be the pair (G, G). Then G ∈ ALLCFG ⇔ (G, G) ∈ COMPCFG. This reduction proves that ALLCFGm COMPCFG. Since ALLCFG is not TD, neither is COMPCFG.

• Question 7 (15): Prove that the function S from N × N to N, defined above, is not Turing computable. (Hint: Assume that it is, and from this assumption prove the statement "ATM is Turing decidable", which we know to be false.)

Here is a decider for ATM, given the assumption that the function S exists. On input (M, w), recode M and w if necessary so that M's tape alphabet is {0, 1, blank} and w is in {0, 1}*. Then let k be the number of states in M and let n = |w|. Simulate M on w for at most S(k, n) steps. If it halts, accept or reject as it does. If it runs out of time, reject.

If M halts on w, by the definition of S it must do so within S(k, n) steps. So this decider accepts (M, w) if and only if M accepts w, and thus it decides the undecidable language ATM.

• Question 8 (30+15): These questions use the definitions of the languages DECIDER and COMPC from above.

• (a, 10): Prove, by any valid method, that DECIDER is not Turing decidable.

We reduce ATM to DECIDER. Given a pair (M, w), let f(M, w) be the TM N that ignores its input and then runs M on w, accepting if M accepts w and going into an infinite loop if M rejects w. If (M, w) ∈ ATM, N halts on any input and thus (N) ∈ DECIDER. But if (M, w) ∉ ATM, then N never halts on any input and thus N ∉ DECIDER. This f is the desired reduction, and thus DECIDER must be undecidable because ATM is.

• (b, 5XC): Prove, using the Recursion Theorem, that DECIDER is not Turing decidable. (Hint: Assume that there is a decider for DECIDER and that you can design a machine to obtain its own description, and derive a contradiction.)

Define the following machine D. On input w, D obtains its own description (D). If w and (D) are not the same string, D accepts w. Otherwise, D uses the assumption to decide whether (D) ∈ DECIDER. If it is, D runs forever, and if it is not, D accepts.

Thus D halts on all inputs if and only if (D) ∉ DECIDER, which is a contradiction.

Many people wanted to allow the DECIDER-decider to obtain its own description, but the Recursion Theorem only says that you can design a new machine to obtain its own description and then do something with it.

• (c, 10): Prove that DECIDER is not Turing recognizable. (Hint: You could show that the complement of ATM is ≤m DECIDER, but it may be easier to show that ALLTMm DECIDER. You may assume without proof that ALLTM is not TR.

We show ALLTMm DECIDER. Let f((M)) be (M'), so that M' is a machine that runs forever on input w if M rejects w, and accepts w if M accepts w. (It does not halt on w if M does not halt on w.) Then (M) ∈ ALLTM ⇔ (M') ∈ DECIDER.

• (d, 10): Prove that DECIDER ≤mCOMPTM. What can you conclude about COMPTM from this result?

Given any Turing machine M, let f(M) = (M, M') where M' is a machine that accepts a string w if and only if M halts and rejects it. If (M) ∈ DECIDER, (M, M') is in COMPTM because every string is either accepted or rejected by M, but not both, so that L(M) and L(M') are complements. If (M) ∉ DECIDER, then there exists a string w such that M does not halt on w, and this w is in neither L(M) nor L(M'), so that L(M) and L(M') are not complements.

Together with (c), this proves that COMPTM is not TR. Together with (e), it proves that COMPTM is Π2 hard.

• (e, 10XC): Recall that a language A is in the class Π2 if there is some Turing decidable language B such that for any string w, w ∈ A if and only if ∀x:∃y: (w, x, y) ∈ B. Prove that if A is any language in Π2, then A ≤m DECIDER.

Let A satisfy the statement ∀w: [w ∈ A ⇔ ∀x:∃y: (w, x, y) ∈ B] for some TD language B.

Given any string w, let M be a TM that on input x, looks for a y such that (w, x, y) is in B, by trying all y's in parallel by dovetailing. (For example, for each n in succession it could run the test for each of the first n y's, for n steps each.)

Now w ∈ A ⇔ ∀x:∃y: (w, x, y) ∈ B ⇔ ∀x: halts on input x ⇔ (M) ∈ DECIDER.

(An alternate proof is to observe that we proved A ≤m ALLTM on the homework, and then use part (d) and the transitivity of ≤m.)

Last modifie 20 March 2015