# COMS W3261 CS Theory Lecture 15: The Diagonalization Language

## 1. Reducing One Problem to Another

• Suppose we have an algorithm A to transform instances of one problem P1 to instances of another problem P2 in such a way that a string w is in P1 if and only if the transformed string A(w) is in P2. What this implies is that we can solve instances of problem P1 by converting them to instances of problem P2 and then using the solution to problem P2 to answer the original question. If we can do this, then we will say that A is a reduction of P1 to P2.
• Note that a reduction from P1 to P2 must turn every instance of P1 with a yes answer to an instance of P2 with a yes answer, and every instance of P1 with a no answer to an instance of P2 with a no answer.
• We will frequently use this technique to show that problem P2 is as hard as problem P1.
• The direction of the reduction is important.
• For example, if there is a reduction from P1 to P2 and if P1 is not recursive, then P2 cannot be recursive. (Why?)
• Similarly, if there is a reduction from P1 to P2 and if P1 is not recursively enumerable, then P2 cannot be recursively enumerable. (Why?)

## 2. Enumerating the Binary Strings

• In many proofs involving Turing machines, we need to enumerate the binary strings and encode Turing machines so that we can refer to the ith binary string as wi and the ith Turing machine as Mi.
• The binary strings are easy to enumerate. If w is a binary string, we shall treat 1w as the binary integer i so we can call w the ith string.
• Using this encoding, the empty string is the first string, 0 the second, 1 the third, 00 the fourth, 01 the fifth, and so on. Henceforth we will refer to the ith string as wi.

## 3. Codes for Turing machines

• We will now define a binary code for all Turing machines with the input alphabet {0, 1} so that each Turing machine can be represented by a binary string. This will allow us to talk about the ith Turing machine as Mi. We will adopt the following conventions:
• We assume the states are q1, q2, . . . , qr for some r. We assume q1 will always be the start state. We assume q2 will be the only accepting state. We need only one accepting state if we assume the Turing machine halts whenever it enters an accepting state.
• We assume the tape symbols are X1, X2, . . . , Xs for some s. We assume X1 is 0, X2 is 1, and X3 is the blank.
• Now we can encode a transition rule δ(qi, Xj) = (qk, Xl, Dm) as a binary string C of the form
• 0i10j10k 10l10m
• Suppose there are n transition rules. The binary code for the entire Turing machine will be the concatenation of the codes for all of the transitions (in some order) separated by pairs of 1's:
• C111C211 … Cn-111Cn
• Note that there can be many encodings for the same Turing machine.
• We can encode a pair (Mi, w) consisting of a Turing machine and a string by appending 111 to the encoding of the Turing machine and then appending the string w.

## 4. The Diagonalization Language Ld is not Recursively Enumerable

• We define Ld, the diagonalization language, as follows:
1. Let w1, w2, w3, . . . be an enumeration of all binary strings.
2. Let M1, M2, M3, . . . be an enumeration of all Turing machines.
3. Let Ld = { wi | wi is not in L(Mi) }.
• Theorem: Ld is not a recursively enumerable language.
Proof:
• Suppose Ld = L(Mi) for some TM Mi.
• This gives rise to a contradiction. Consider what Mi will do on an input string wi.
• If Mi accepts wi, then by definition wi cannot be in Ld.
• If Mi does not accepts wi, then by definition wi is in Ld.
• Since wi can neither be in Ld nor not be in Ld, we must conclude there is no Turing machine that can define Ld.

## 5. Complements of Recursive and Recursively Enumerable Languages

• A recursive language is one that is accepted by a TM that halts on all inputs.
• The complement of a recursive language is recursive.
• If a language L and its complement are RE, then L is recursive.
• A language can be RE but its complement need not be RE.

## 6. Practice Problems

1. Prove that if there is a reduction from problem P1 to problem P2 and if P1 is not recursive, then P2 is not recursive.
2. Prove that if there is a reduction from P1 to P2 and if P1 is not recursively enumerable, then P2 is not recursively enumerable.
3. Show that the language L = { wi | wi is not accepted by M2i } is not recursively enumerable.
4. Show that the language L = { wi | w2i is not accepted by Mi } is not recursively enumerable.