# Second Midterm Exam Solutions, Spring 2009

#### 15 April 2009

Question text is in black, solutions in blue.

### Directions:

• Answer the problems on the exam pages.
• There are seven problems for 120 total points. Probable scale is around A=100, C=70 but will be determined after I grade the exam.
• If you need extra space use the back of a page.
• No books, notes, calculators, or collaboration.
• The first five 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.

Q1: 10 points
Q2: 10 points
Q3: 10 points
Q4: 10 points
Q5: 10 points
Q6: 30 points
Q7: 40 points

Total: 120 points

• Question 1 (10): True or false with justification: Define a bizarro Turing machine to be like an ordinary deterministic one-tape Turing machine except that the tape alphabet Γ is countably infinite, so that Γ = {a1, a2, a3,...}. The input alphabet Σ is still finite. The transition function δ from (Q × Γ) to (Q × Γ × {L, R}) can no longer be given by a finite lookup table, but it is computable by an ordinary Turing machine (that always halts).

Given this definition, there exists a bizarro Turing machine B whose language L(B) = {w ∈ Σ*: B halts in its accepting state on input w} is not TR.

FALSE. You can simulate a bizarro TM (BTM) with an ordinary TM. Store the tape contents of the BTM as a string, for example, aiajak can be stored as aibajbak or \$(i in binary)\$(j in binary)\$(k in binary)\$. Implement each step of the BTM by locating the head, calculating the next move, overwriting the string corresponding to the BTM character to be changed, and shifting the part of the ordinary TM's tape to the right as much as necessary to fit the string for the new BTM character. The computation of the correct move given the BTM's state and character seen can be done on another tape and is guaranteed to halt by the assumption. So any finite number of BTM steps can be simulated by the ordinary TM in finite time. The simulator must convert the BTM's input into the new format before starting -- this can clearly be done by an ordinary TM.

So w is in L(B) if and only if B halts on input w, if and only if the simulator halts on input w. Thus L(B) is the language of the simulator and must be a TR language.

• Question 2 (10): True or false with justification: It is possible to have a countably infinite family S1, S2, S3,... of countably infinite sets, such that for any positive integers i and j where i ≠ j, the intersection Si ∩ Sj is a nonempty finite set. (Recall that a set is countably infinite if and only if it can be put into one-to-one correspondence with the positive integers.)

TRUE. Let S1 be {a11, a12, a13,...}, S2 be {a11, a21, a22, a23,...}, S3 be {a11, a21, a31, a32, a33,...}, and in general Si = {a11,..., a(i-1)1, ai1, ai2, ai3,...}. Then if i < j, the intersection Si ∩ Sj is just {a11,..., ai1} which is clearly nonempty and finite.

• Question 3 (10): True or false with justification: For every ordinary Turing machine M with input alphabet Σ and every string w in Σ*, the set of accepting computation histories of M on w is a regular language.

TRUE. There are two cases. If M accepts w, there is exactly one accepting computation history, and any one-element language is regular. If M does not accept w, there are no accepting computation histories, and the empty language is regular. It is undecidable which regular language we have, but either way we have a regular language.

• Question 4 (10): True or false with justification: If f is a one-to-one function from {0, 1}* to {0, 1}*, and n is a positive integer, then there must exist a string w of length n such that the length of f(w) is at least n.

TRUE. This came up in Section 6.4 of Sipser. There are 2n binary strings of length n, but only 1 + 2 + ... + 2n-1 = 2n - 1 binary strings of length strictly less than n. By the Pigeonhole Principle, we cannot map a larger finite set one-to-one to a smaller set. If the range of the function does not consist entire of strings shorter than n, there must be an element of the range with length n or greater.

• Question 5 (10): True or false with justification: Recall that an LBA is a deterministic one-tape Turing machine that never leaves the portion of its tape that originally contained its input. Define ALLLBA to be the set {<M>: M is an LBA with input alphabet Σ and L(M) = Σ*}. Then the language ALLLBA is not TD.

TRUE. We know that ELBA = {<M>: M is an LBA and L(M) = ∅} is not TD. We show that ELBAm ALLLBA.

Given an LBA M, we want an LBA f(M) such that L(f(M)) = Σ* - L(M). This will mean that <M> is in ELBA if and only if <f(M)> is in ALLLBA, and thus that f is the desired reduction.

Let Q be the state set of M and let q be the size of Q. Let Γ be the tape alphabet of M and let k be the size of Γ. On input w of size n, f(M) will simulate M for at least qnkn steps or until it halts. If it runs for that many steps without halting, it is in a loop because that is the number of possible configurations of M -- there are q different states, n different head positions, and kn different possible contents of the tape. So we have f(M) accept if the simulated M rejects or runs for that long, and have f(M) reject if the simulated M accepts.

We are left with the technical problem of implementing f(M) as an LBA, which means keeping a "clock" on the same portion of the tape that contains the computation of M. We do this by expanding the tape alphabet of f(M) to 2(k2 + k) characters, so each square of f(M)'s tape contains an element of Γ, an element of {0, 1,..., k}, and a bit to mark where the head of one computation is while the other computation is going on. We use the elements of {0,..., k} to count up to (k+1)n in base k+1. We assume that n is large enough so that (k+1)n ≥ qnkn, otherwise we implement f(M) with a big lookup table. So f(M) alternates between implementing a step of M and incrementing the counter.

• Question 6 (30): A Latin square is a d by d matrix of numbers, each in the set {1, 2, 3,..., d}, such that each row and each column has each possible number exactly once. (For example, a solution to a standard Sudoku puzzle is a 9 by 9 Latin square that also has an additional property.) Let LS be the following language: A string in {a, b}* is in LS if it is of the form ai1bai2bai3b... ainb where n is equal to d2 for some positive integer d, each ij is in the set {1, 2, 3,..., d}, and the numbers i1, i2,..., in form a Latin square if arranged into a d by d matrix in row-major order. Describe a deterministic k-tape Turing machine deciding the language LS, where k is a fixed positive integer of your choice.

We first outline the steps of the computation and then give some detail for each:

1. Read the entire input (which is kept on read-only tape 1) and count the b's to put the number n in unary on tape 2.
2. Compute the first d so that d2 ≥ n and put d in unary on tape 3. If d2 > n, reject.
3. Check that each block of a's in the input has size in {1,..., d}, reject if any does not.
4. Verify for each i and j in {1,..., d} that one of the numbers in row j is an i, that is, that one of the blocks in position (j-1)d + 1, (j-1)d + 2,..., or jd of the input has size exactly i.
5. Verify for each i and j in {1,..., d} that one of the numbers in column j is an i, that is, that one of the blocks in position j, d + j, 2d + j,..., (d-1)d + j of the input has size exactly i.

We keep the variable i on tape 4 and the variable j on tape 5. On tape 6 we can keep the successive position numbers to be tested for size i. Now for some details:

1. Add a b to tape 2 each time you see a b on tape 1 on a single left-to-right pass over the input.
2. Implement the loop while (d*d < n) d++;, using two markers on tape 3 to count off d2 steps while moving right on tape 2 once each step. If you exactly count off the n b's on tape 2, go on to step 3. If you go past the b's, reject, if you come short, increase d by 1 and start over.
3. Measure each block of a's in the input against the string on tape 3, and reject if the block of a's is longer (or if there are two b's in a row in the input).
4. For each i and j, initialize k on tape 6 to (j-1)d + 1, find the k'th block of the input, and check whether any of the next d blocks has size exactly i. If you find one, move on to the (i,j) pair -- if you don't find one, reject.
5. For each i and j, initialize k to j, and check the size of that block and every d'th block thereafter to see if it has size exactly i. If you find one, move on to the next (i,j) pair -- if you reach the end of the input without finding one, reject.

If you complete all the checks in steps 1-5 without rejecting, then accept.

• Question 7 (40): Let Z be the language {<M1, M2>: M1 and M2 are Turing machines and there exists a string w such that M1 and M2 both accept w and M1 does so in fewer steps than does M2}. Here are four questions concerning Z. Your answers to some may imply answers to others --- it is fine to quote your solutions to other problems, but beware of circular reasoning!

• (a, 10) Is the language Z a TR language? Prove your answer.

YES, Z is TR. Define a machine N which will, on input <M1, M2>, in parallel for all strings w, run both M1 and M2 on w. (This is by dovetailing, for example, for each positive integer m it can run the machines for m steps each on the first m strings in Σ*.) If for any w, both machines halt and M1 takes fewer steps, accept. Now Z is L(N), so Z is TR.

• (b, 10) Is the language Z a TD language? Prove your answer.

NO, Z is not TD. This follows from the reduction ATMm Z in part (c). You could also mapping-reduce or Turing-reduce any undecidable language to Z.

• (c, 10) Is it true that ATMm Z? Prove your answer by either describing a mapping reduction or proving that it cannot exist.

YES, this mapping exists. Given a pair <M, w>, let f(M,w) be a pair of machines <M1, M2>, where:

• M1 erases its input and then runs M on w, and
• M2 erases its input, moves right, moves left, and then runs M on w.

If M accepts w, both machines halt and M1 halts first, so f(M, w) is in Z. If M does not accept w, then neither machine halts so f(M, w) is not in Z. So f is a mapping reduction from ATM to Z.

• (d, 10) Is it true that ATMm Z? Prove your answer by either describing a mapping reduction or proving that it cannot exist.

NO, this mapping does not exist. We know from (a) that Z is TR, but we know that ATM-bar is not TR. The TR languages are closed downward under ≤m, so there cannot be a mapping reduction from a non-TR language to a TR language.