7 Undecidability: 7.1 Acceptable Versus Decidable
7 Undecidability: 7.1 Acceptable Versus Decidable
7 Undecidability: 7.1 Acceptable Versus Decidable
7 Undecidability
Perhaps the single most important result in Turing’s remarkable 1936 paper that introduces Turing
machines is his observation that there are problems that cannot be solved by any algorithm.
Turing’s canonical example of an undecidable problem was the halting problem, which asks
whether a given Turing machine halts when given a particular input string. Among other
consequences, Turing’s undecidability result provided an elegant negative solution to Hilbert’s
Entscheidungsproblem, which asked for an algorithm to decide whether a given statement of
first-order logic is true—no such algorithm exists.
For any language L, the sentence “M accepts L” means Accept(M ) = L, and the sentence “M
decides L” means Accept(M ) = L and Diverge(M ) = ∅.
Now let L be an arbitrary language. We say that L is acceptable (or semi-computable, or
semi-decidable, or recognizable, or listable, or recursively enumerable) if some Turing machine
accepts L, and unacceptable otherwise. Similarly, L is decidable (or computable, or recursive) if
some Turing machine decides L, and undecidable otherwise.
1
Models of Computation Lecture 7: Undecidability [Fa’16]
• Suppose there is an integer N such that the binary expansion of π contains the substring
1N but does not contain the substring 1N +1 . Let MN be the Turing machine with N + 3
states {0, 1, . . . , N , accept, reject}, start state 0, and the following transition function:
accept
if a =
δ(q, a) = reject if a 6= and q = n
(q + 1, a, +1) otherwise
• Suppose the binary expansion of π contains arbitrarily long substrings of 1s. Then any
Turing machine that accepts all inputs correctly decides Π.
We have no idea which of these machines correctly decides Π, but one of them does, and that’s
enough!
The decidable languages have several fairly obvious useful closure properties.
Proof: Let M and M 0 be Turing machines that decide L and L 0 , respectively. We can build a
Turing machine M∪ that decides L ∪ L 0 as follows. First, M∪ copies its input string w onto a
second tape. Then M∪ runs M on input w (on the first tape), and then runs M 0 on input w (on
the second tape). If either M or M 0 accepts, then M∪ accepts; if both M and M 0 reject, then M∪
rejects.
The other three languages are similar.
2
Models of Computation Lecture 7: Undecidability [Fa’16]
Lemma 4. For all acceptable languages L and L 0 , the languages L∪L 0 and L∩L 0 are also acceptable.
Proof: Let M and M 0 be Turing machines that decide L and L 0 , respectively. We can build a
Turing machine M∩ that decides L ∩ L 0 as follows. First, M∩ copies its input string w onto a
second tape. Then M∩ runs M on input w using the first tape, and then runs M 0 on input w using
the second tape. If both M and M 0 accept, then M∩ accepts; if either M or M 0 reject, then M∩
rejects; if either M or M 0 diverge, then M∩ diverges (automatically).
The construction for L ∪ L 0 is more subtle; instead of running M and M 0 in series, we must
run them in parallel. Like M∩ , the new machine M∪ starts by copying its input string w onto
a second tape. But then M∪ runs M and M 0 simultaneously; with each step of M∪ simulating
both one step of M on the first tape and one step of M 0 on the second. Ignoring the states and
transitions needed for initialization, the state set of M∪ is the product of the state sets of M
and M 0 , and the transition function is
accept∪
if q = accept or q0 = accept0
δ∪ (q, a, q0 , a0 ) = reject∪ if q = reject and q0 = reject0
(δ(q, a), δ0 (q0 , a0 )) otherwise
Thus, M∪ accepts as soon as either M or M 0 accepts, and rejects only after both M or M 0
reject.
Proof: Let M and M be Turing machines that accept L and Σ∗ \ L, respectively. Following the
previous proof, we construct a new Turing machine M ∗ that copies its input onto a second tape,
and then simulates M and M 0 in parallel on the two tapes. If M accepts, then M ∗ accepts; if M
accepts, then M ∗ rejects. Since every string is accepted by either M or M , we conclude that M ∗
decides L.
The other direction follows immediately from Lemma 1.
3
Models of Computation Lecture 7: Undecidability [Fa’16]
• Modifiable: We can algorithmically modify any Turing machine M , given the encoding
of M as input. For example, there are algorithms to swap the accept and reject states of any
Turing machine, or to add new states and transitions representing pre- and post-processing
phases, or to build a new machine that calls M as a subroutine, or to build a new machine
that runs several copies of M in parallel.
• Executable: There is a fixed universal Turing machine U that can simulate the behavior
of an arbitrary Turing machine M , given the encodings of M and w as input. For example,
if we decided to encode Turing machines as Python programs, then U would be a Python
interpreter.
The precise details of the encoding are unimportant, but for the sake of concreteness, let
me describe a natural encoding of Turing machines as strings over the six-character alphabet
{0, 1, {, •, }}. Let M = (Γ , , Σ, Q, start, accept, reject, δ) be an arbitrary Turing machine, with
a single half-infinite tape and a single read-write head. (I will consistently indicate the states
and tape symbols of M in slanted green to distinguish them from the upright red symbols in the
encoding alphabet.)
• We encode each symbol a ∈ Γ as a unique string |a| of dlg(|Γ |)e bits. For example, if
Γ = {0, 1, $, x, }, we might use the following encoding:
〈0〉 = 001, 〈1〉 = 010, 〈$〉 = 011, 〈x〉 = 100, 〈〉 = 000.
• Similarly, we encode each state q ∈ Q as a distinct string 〈q〉 of dlg|Q|e bits. Without
loss of generality, we encode the start state with all 1s and the reject state with all 0s.
For example, if Q = {start, seek1, seek0, reset, verify, accept, reject}, we might use the
following encoding:
• Finally, we encode the machine M itself as the string 〈M 〉 = {〈reject〉•〈〉}〈δ〉, where 〈δ〉
is the concatenation of substrings {〈p〉•〈a〉•〈q〉•〈b〉•〈∆〉} encoding each transition
δ(p, a) = (q, b, ∆) such that q 6= reject. We encode the actions ∆ = ±1 by defining
〈−1〉 := 0 and 〈+1〉 := 1. Conveniently, every transition string has exactly the same
length. For example, with the symbol and state encodings described above, the transition
δ(reset, $) = (start, $, +1) would be encoded as the string
{100•011•001•011•1}.
Our first example Turing machine for recognizing {0n 1n 0n | n ≥ 0} would be represented
by the following string (broken into multiple lines for readability):
{000•000}{{001•001•010•011•1}{001•100•101•011•1}{010•001•010•001•1}
{010•100•010•100•1}{010•010•011•100•1}{011•010•011•010•1}
{011•100•011•100•1}{011•001•100•100•1}{100•001•100•001•0}
{100•010•100•010•0}{100•100•100•100•0}{100•011•001•011•1}
{101•100•101•011•1}{101•000•110•000•0}}
4
Models of Computation Lecture 7: Undecidability [Fa’16]
Building a universal Turing machine U that uses this encoding is more a matter of careful
bookkeeping than real insight. We can encode any configuration of M on U’s work tape by
encoding each cell of M ’s tape as a string {〈q〉•〈a〉} indicating that (1) the cell contains symbol a;
(2) if q 6= reject, then M ’s head is located at this cell, and M is in state q; and (3) if q = reject,
then M ’s head is located somewhere else. We also surround the entire tape encoding with
brackets { and }. For example, the initial configuration (start, 00110
Î
, 0) for our example Turing
machine would be encoded as follows.
〈start, 00110
Î
, 0〉 = {{111•001}{000•001}{000•010}{000•010}{000•001}}
| {z }| {z }| {z }| {z }| {z }
start 0 reject 0 reject 1 reject 1 reject 0
To simulate one step of M ’s execution, we (1) find the location of the head (or reject if the head
has vanished), (2) look up the transition for the state-symbol pair at the head, and (3) update
the current cell and one of its neighbors to reflect the transition. The remaining grungy details
are left as an exercise.
Turing used this observation about self-reference to derive his first undecidable language as
follows. Let’s say that a Turing machine M is self-rejecting if it rejects its own encoding 〈M 〉.
Let SelfReject be the set of all encodings of self-rejecting Turing machines:
SelfReject := 〈M 〉 M rejects 〈M 〉
Proof: Suppose to the contrary that there is a Turing machine SR that decides SelfReject.
Then by definition, Accept(SR) = SelfReject and Diverge(SR) = ∅. More explicitly, for any
Turing machine M ,
In particular, these equivalences must hold when M is the machine SR. Thus,
In short, SR accepts 〈SR〉 if and only if SR rejects 〈SR〉, which is impossible! The only logical
conclusion is that the Turing machine SR does not exist.
5
Models of Computation Lecture 7: Undecidability [Fa’16]
Cantor’s Theorem. Let f : X → 2X be an arbitrary function from an arbitrary set X to its power
set. This function f is not a surjection.
Proof: Fix an arbitrary function f : X → 2X . Call an element x ∈ X happy if x ∈ f (x) and sad
if x 6∈ f (x). Let Y be the set of all sad elements of X ; that is, for every element x ∈ X , we have
x ∈ Y ⇐⇒ x 6∈ f (x).
For the sake of argument, suppose f is a surjection. Then (by definition of surjection) there must
be an element y ∈ X such that f ( y) = Y . Then for every element x ∈ X , we have
x ∈ f ( y) ⇐⇒ x 6∈ f (x).
y ∈ f ( y) ⇐⇒ y 6∈ f ( y).
Cantor’s theorem immediately implies that not all languages are acceptable.
Alternatively, let X be the set of all Turing machines that halt on all inputs. For any Turing
machine M ∈ X , let f (M ) be the set of all Turing machines N ∈ X such that M accepts the
encoding 〈N 〉. Then a Turing machine M is sad if it rejects its own encoding 〈M 〉; thus, Y is
essentially the set SelfReject. Cantor’s argument now immediately implies that no Turing
machine decides the language SelfReject.
The core of Cantor’s diagonalization argument also appears in the “barber paradox” popular-
ized by Bertrand Russell in the 1910s. In a certain small town, every resident has a haircut on
Haircut Day. Some residents cut their own hair; others have their hair cut by another resident of
the same town. To obtain an official barber’s license, a resident must cut the hair of all residents
who don’t cut their own hair, and no one else. Given these assumptions, we can immediately
conclude that there are no licensed barbers. After all, who would cut the barber’s hair?
To map Russell’s barber paradox back to Cantor’s theorem, let X be the set of residents, and
let f (x) be the set of residents who have their hair cut by x; then a resident is sad if they do not
cut their own hair. To prove that SelfReject is undecidable, replace “resident” with “a Turing
machine that halts on all inputs”, and replace “A cuts B’s hair” with “A accepts 〈B〉”.
¹more commonly, flouting all reasonable standards of grammatical English, “an onto function”
6
Models of Computation Lecture 7: Undecidability [Fa’16]
The proofs for these three languages are not quite as direct as the proof for SelfReject; each
fictional deciding machine requires a small modification to create the contradiction.
Proof: For the sake of argument, suppose there is a Turing machine SA such that Accept(SA) =
SelfAccept and Diverge(M ) = ∅. Let SAR be the Turing machine obtained from SA by
swapping its accept and reject states (as in the proof of Lemma 1). Then Reject(SAR ) =
SelfAccept and Diverge(SAR ) = ∅. It follows that SAR rejects 〈SAR 〉 if and only if SAR accepts
〈SAR 〉, which is impossible.
Proof: Suppose to the contrary that there is a Turing machine SH such that Accept(SH) =
SelfHalt and Diverge(SH) = ∅. Let SH X be the Turing machine obtained from SH by
redirecting every transition to accept to a new hanging state hang, and then redirecting every
transition to reject to accept. Then Accept(SH X ) = Σ∗ \ SelfHalt and Reject(SH X ) = ∅.
It follows that SH X accepts 〈SH X 〉 if and only if SH X does not halt on 〈SH X 〉, and we have a
contradiction.
Proof: Suppose to the contrary that there is a Turing machine S D such that Accept(M ) =
SelfDiverge. Let S DA be the Turing machine obtained from M by redirecting every transition
to reject to a new hanging state hang such that δ(hang, a) = (hang, a, +1) for every symbol a.
Then Accept(S DA) = SelfDiverge and Reject(S DA) = ∅. It follows that S DA accepts 〈S DA〉 if
and only if S DA does not halt on 〈S DA〉, which is impossible.
?
7.8 Nevertheless, Acceptable
Our undecidability argument for SelfDiverge actually implies the stronger result that SelfDi-
verge is unacceptable; we never assumed that the hypothetical accepting machine S D halts on
all inputs. However, we can use or modify our universal Turing machine U to accept the other
three self-referential languages.
Proof: We describe a Turing machine SA that accepts the language SelfAccept. Given any
string w as input, SA first verifies that w is the encoding of a Turing machine. If w is not
the encoding of a Turing machine, then SA diverges. Otherwise, w = 〈M 〉 for some Turing
machine M ; in this case, SA writes the string ww = 〈M 〉〈M 〉 onto its tape and passes control to
the universal Turing machine U. U then simulates M (the machine encoded by the first half of
7
Models of Computation Lecture 7: Undecidability [Fa’16]
its input) on the string 〈M 〉 (the second half of its input).² In particular, U accepts 〈M , M 〉 if and
only if M accepts 〈M 〉. We conclude that SR accepts 〈M 〉 if and only if M accepts 〈M 〉.
Proof: Let U R be the Turing machine obtained from our universal machine U by swapping the
accept and reject states. We describe a Turing machine SR that accepts the language SelfReject
as follows. SR first verifies that its input string w is the encoding of a Turing machine and
diverges if not. Otherwise, SR writes the string ww = 〈M , M 〉 onto its tape and passes control to
the reversed universal Turing machine U R . Then U R accepts 〈M , M 〉 if and only if M rejects 〈M 〉.
We conclude that SR accepts 〈M 〉 if and only if M rejects 〈M 〉.
Finally, because SelfHalt is the union of two acceptable languages, SelfHalt is also
acceptable.
Deciding the language Halt is usually called the halting problem: Given a program M and an
input w to that program, does the program halt? This problem may seem trivial; why not just run
the program and see? More formally, why not just pass the input string 〈M , x〉 to our universal
Turing machine U? That strategy works perfectly if we just want to accept Halt, but we actually
want to decide Halt; if M is not going to halt on w, we still want an answer in a finite amount of
time. Sadly, we can’t always get what we want.
Proof: Suppose to the contrary that there is a Turing machine H that decides Halt. Then we
can use H to build another Turing machine SH that decides the language SelfHalt. Given any
string w, the machine SH first verifies that w = 〈M 〉 for some Turing machine M (rejecting if
not), then writes the string ww = 〈M , M 〉 onto the tape, and finally passes control to H. But
SelfHalt is undecidable, so no such machine SH exists. We conclude that H does not exist
either.
Nearly identical arguments imply that the languages Accept, Reject, and Diverge are
undecidable.
²To simplify the presentation, I am implicitly assuming here that 〈M 〉 = 〈〈M 〉〉. Without this assumption, we need
a Turing machine that transforms an arbitrary string w ∈ Σ∗M into its encoding 〈w〉 ∈ Σ∗U ; building such a Turing
machine is straightforward.
³Many sources including Sipser and Wikipedia uses the shorter name A T M instead of Accept, but uses HALTT M
instead of Halt. I have no idea why Sipser thought four-letter names are okay, but six-letter names are not. The
subscript TM is just a reminder that these are languages of Turing machine encodings, as opposed to encodings of
DFAs or some other machine model.
8
Models of Computation Lecture 7: Undecidability [Fa’16]
Perhaps the most confusing aspect of reduction arguments is that the languages we want to
prove undecidable nearly (but not quite) always involve encodings of Turing machines, while at
the same time, the programs that we build to prove them undecidable are also Turing machines.
Our proof that Halt is undecidable involved three different machines:
• The hypothetical Turing machine H that decides Halt.
• The new Turing machine SH that decides SelfHalt, using H as a subroutine.
• The Turing machine M whose encoding is the input to H.
It is incredibly easy to get confused about which machines are playing each in the proof. Therefore,
it is absolutely vital that we give each machine in a reduction proof a unique and mnemonic
name, and then always refer to each machine by name. Never write, say, or even think “the
Turing machine” or “the state” or “the tape” or “the input” or (gods forbid) “it”. You also may
find it useful to think of the working programs we are trying to construct (H and SH in this
proof) as being written in a different language than the arbitrary source code that we want those
programs to analyze (〈M 〉 in this proof).
Proof: Suppose to the contrary that there is a Turing machine N A that decides NeverAccept.
Then by swapping the accept and reject states, we obtain a Turing machine N AR that decides
the complementary language Σ∗ \ NeverAccept.
To reach a contradiction, we construct a Turing machine A that decides Accept as follows.
Given the encoding 〈M , w〉 of an arbitrary machine M and an arbitrary string w as input, A writes
the encoding 〈Mw 〉 of a new Turing machine Mw that ignores its input, writes w onto the tape,
and then passes control to M . Finally, A passes the new encoding 〈Mw 〉 as input to N AR . The
following cartoon tries to illustrate the overall construction.
Before going any further, it may be helpful to list the various Turing machines that appear in
this construction.
9
Models of Computation Lecture 7: Undecidability [Fa’16]
Mw accept
x w M
reject
hang
A
NAR accept
NA
<M,w> Build <Mw>
<Mw>
reject
Now let M be an arbitrary Turing machine and w be an arbitrary string, and suppose we run
our new Turing machine A on the encoding 〈M , w〉. To complete the proof, we need to consider
two cases: Either M accepts w or M does not accept w.
• On the other hand, suppose M does not accept w, either rejecting or diverging instead.
10
Models of Computation Lecture 7: Undecidability [Fa’16]
In short, A decides the language Accept, which is impossible. We conclude that N A does not
exist.
Again, similar arguments imply that the languages NeverReject, NeverHalt, and Never-
Diverge are undecidable. In each case, the core of the argument is describing how to transform
the incoming machine-and-input encoding 〈M , w〉 into the encoding of an appropriate new
Turing machine 〈Mw 〉.
Now that we know that NeverAccept and its relatives are undecidable, we can use them as
the basis of further reduction proofs. Here is a typical example:
Theorem 14. The language DivergeSame := 〈M1 〉 〈M2 〉 Diverge(M1 ) = Diverge(M2 ) is unde-
cidable.
Proof: Suppose for the sake of argument that there is a Turing machine DS that decides
DivergeSame. Then we can build a Turing machine N D that decides NeverDiverge as follows.
Fix a Turing machine Y that accepts Σ∗ (for example, by defining δ(start, a) = (accept, ·, ·) for
all a ∈ Γ ). Given an arbitrary Turing machine encoding 〈M 〉 as input, N D writes the string
〈M 〉〈Y 〉 onto the tape and then passes control to DS. There are two cases to consider:
ÆÆÆ The following formulation is closer to the proof and may be (slightly) easier to use:
Rice’s Theorem. Let L be any set of languages that satisfies the following conditions:
• There is a Turing machine Y such that Accept(Y ) ∈ L.
• There is a Turing machine N such that Accept(N ) 6∈ L.
The language AcceptIn(L) := 〈M 〉 Accept(M ) ∈ L is undecidable.
Proof: Without loss of generality, suppose ∅ 6∈ L. (A symmetric argument establishes the theorem
in the opposite case ∅ ∈ L.) Fix an arbitrary Turing machine Y such that Accept(Y ) ∈ L.
Suppose to the contrary that there is a Turing machine AL that decides AcceptIn(L). To
derive a contradiction, we describe a Turing machine H that decides the halting language Halt,
using AL as a black-box subroutine. Given the encoding 〈M , w〉 of an arbitrary Turing machine M
and an arbitrary string w as input, H writes the encoding 〈WTF〉 of a new Turing machine WTF
that executes the following algorithm:
11
Models of Computation Lecture 7: Undecidability [Fa’16]
WTF(x):
run M on input w (and discard the result)
run Y on input x
– Then for all strings x, the machine WTF accepts x if and only if Y accepts x.
– So Accept(WTF) = Accept(Y ), by definition of Accept( · ).
– So Accept(WTF) ∈ L, by definition of Y .
– So AL accepts 〈WTF〉, because AL decides AcceptIn(L).
– So H accepts 〈M , w〉, by definition of H.
– Then for all strings x, the machine WTF does not halt on input x, and therefore does
not accept x.
– So Accept(WTF) = ∅, by definition of Accept(WTF).
– So Accept(WTF) 6∈ L, by our assumption that ∅ 6∈ L.
– So AL rejects 〈WTF〉, because AL decides AcceptIn(L).
– So H rejects 〈M , w〉, by definition of H.
In short, H decides the language Halt, which is impossible. We conclude that AL does not
exist.
The set L in the statement of Rice’s Theorem is often called a property of languages, rather
than a set, to avoid the inevitable confusion about sets of sets of finite sequences of characters. We
can also think of L as a decision problem about languages, where the languages are represented
by Turing machines that accept or decide them. Rice’s theorem states that the only properties
of languages that are decidable are the trivial properties “Does this Turing machine accept an
acceptable language?” (Answer: Yes, by definition.) and “Does this Turing machine accept
Discover?” (Answer: No, because Discover is a credit card, not a language.)
Rice’s Theorem makes it incredibly easy to prove that language properties are undecidable;
we only need to exhibit one acceptable language that has the property and another acceptable
language that does not. In fact, every proof using Rice’s theorem can use at least one of the
following Turing machines:
• MAccept accepts every string, by defining δ(start, a) = accept for every tape symbol a.
• MReject rejects every string, by defining δ(start, a) = reject for every tape symbol a.
• MDiverge diverges on every string, by defining δ(start, a) = (start, a, +1) for every tape
symbol a.
12
Models of Computation Lecture 7: Undecidability [Fa’16]
(a) Let L be the set of all languages that contain the empty string. Then AcceptIn(L) = {〈M 〉 |
M accepts given an empty initial tape}.
We can also use Rice’s theorem as a component in more complex undecidability proofs, where
the target language consists of more than just a single Turing machine encoding.
Theorem 16. The language L := 〈M , w〉 M accepts wk for every integer k ≥ 0 is undecidable.
Proof: Fix an arbitrary string w, and let L be the set of all languages that contain wk for all k.
Then Accept(MAccept ) = Σ∗ ∈ L and Accept(MReject ) = ∅ 6∈ L. Thus, even if the string w is
fixed in advance, no Turing machine can decide L.
Nearly identical reduction arguments imply the following variants of Rice’s theorem. (The
names of these theorems are not standard.)
⁴Yes, parts (e) and (f) have exactly the same proof.
13
Models of Computation Lecture 7: Undecidability [Fa’16]
Rice’s Rejection Theorem. Let L be any set of languages that satisfies the following conditions:
• There is a Turing machine Y such that Reject(Y ) ∈ L
• There is a Turing machine N such that Reject(N ) 6∈ L.
The language RejectIn(L) := 〈M 〉 Reject(M ) ∈ L is undecidable.
Rice’s Halting Theorem. Let L be any set of languages that satisfies the following conditions:
• There is a Turing machine Y such that Halt(Y ) ∈ L
• There is a Turing machine N such that Halt(N ) 6∈ L.
The language HaltIn(L) := 〈M 〉 Halt(M ) ∈ L is undecidable.
Rice’s Divergence Theorem. Let L be any set of languages that satisfies the following conditions:
• There is a Turing machine Y such that Diverge(Y ) ∈ L
• There is a Turing machine N such that Diverge(N ) 6∈ L.
The language DivergeIn(L) := 〈M 〉 Diverge(M ) ∈ L is undecidable.
Rice’s Decision Theorem. Let L be any set of languages that satisfies the following conditions:
• There is a Turing machine Y such that decides an language in L.
• There is a Turing machine N such that decides an language not in L.
The language DecideIn(L) := 〈M 〉 M decides a language in L is undecidable.
As easy as it is to use Rice’s theorem and its variants, they cannot be used for all un-
decidability proofs; these theorems only apply to properties of languages. For example, the
language ThisIsSparta := {〈M 〉 | M accepts the string SPARTA after exactly 300 steps} is de-
cidable, even though there are Turing machines that accept the string SPARTA after exactly 300
steps and there are other Turing machines that do not.
More subtly, Rice’s theorem cannot be applied to self-referential languages like RevAccept :=
{〈M 〉 | M accepts 〈M 〉R }, because membership depends on details of the encoded machine and
not just the language that the encoded machine accepts. To be clear: RevAccept is undecidable;
you just can’t use Rice’s theorem to prove that fact.
?
7.12 The Rice-McNaughton-Myhill-Shapiro Theorem
The following subtle generalization of Rice’s theorem precisely characterizes which properties
of acceptable languages are acceptable. This result was partially proved by Henry Rice in 1953,
in the same paper that proved Rice’s Theorem; Robert McNaughton, John Myhill, and Norman
Shapiro completed the proof a few years later, each independently from the other two.⁵
14
Models of Computation Lecture 7: Undecidability [Fa’16]
I won’t give a complete proof of this theorem (in part because it requires techniques I haven’t
introduced), but the following lemma is arguably the most interesting component:
Lemma 17. Let L be a set of acceptable languages. If L is not monotone, then AcceptIn(L) is
unacceptable.
Proof: Suppose to the contrary that there is a Turing machine AIL that accepts AcceptIn(L).
Using this Turing machine as a black box, we describe a Turing machine S D that accepts the
unacceptable language SelfDiverge. Fix two Turing machines Y and N such that
Accept(Y ) ∈ L,
Accept(N ) 6∈ L,
and Accept(Y ) ⊆ Accept(N ).
Let w be the input to S D. After verifying that w = 〈M 〉 for some Turing machine M
(and rejecting otherwise), S D writes the encoding 〈WTF〉 or a new Turing machine WTF that
implements the following algorithm:
WTF(x):
write x to second tape
write 〈M 〉 to third tape
in parallel:
run Y on the first tape
run N on the second tape
run M on the third tape
if Y accepts x
accept
if N accepts x and M halts on 〈M 〉
accept
Finally, S D passes the new encoding 〈WTF〉 to AIL . There are two cases to consider:
In short, S D accepts SelfDiverge, which is impossible. We conclude that S D does not exist.
15
Models of Computation Lecture 7: Undecidability [Fa’16]
Proof: (a) The set of finite languages is not monotone: ∅ is finite; Σ∗ is not finite; both ∅
and Σ∗ are acceptable (in fact decidable); and ∅ ⊂ Σ∗ .
(b) The set of infinite acceptable languages is not compact: No finite subset of the infinite
acceptable language Σ∗ is infinite!
(c) The set of regular languages is not monotone: Consider the languages ∅ and {0n 1n | n ≥ 0}.
(d) The set of non-regular acceptable languages is not monotone: Consider the languages
{0n 1n | n ≥ 0} and Σ∗ .
(e) The set of decidable languages is not monotone: Consider the languages ∅ and SelfReject.
(f) The set of undecidable acceptable languages is not monotone: Consider the languages
SelfReject and Σ∗ .
(g) The set L = {L | L ∩ SelfDiverge 6= ∅} is not finitely acceptable. For any string w, deciding
whether {w} ∈ L is equivalent to deciding whether w ∈ SelfDiverge, which is impossible.
(h) If Accept(N ) 6= Σ∗ , then the set {Accept(N )} is not monotone. On the other hand, if
Accept(N ) = Σ∗ , then the set {Accept(N )} is not compact: No finite subset of Σ∗ is equal
to Σ∗ !
Theorem 19. The language NeverLeft := {〈M , w〉 | Given w as input, M never moves left} is de-
cidable.
Proof: Given the encoding 〈M , w〉, we simulate M with input w using our universal Turing
machine U, but with the following termination conditions. If M ever moves its head to the left,
then we reject. If M halts without moving its head to the left, then we accept. Finally, if M reads
more than |Q| blanks, where Q is the state set of M , then we accept. If the first two cases do not
apply, M only moves to the right; moreover, after reading the entire input string, M only reads
blanks. Thus, after reading |Q| blanks, it must repeat some state, and therefore loop forever
without moving to the left. The three cases are exhaustive.
Theorem 20. The language LeftThree := {〈M , w〉 | Given w as input, M eventually moves left
three times in a row} is undecidable.
Proof: Given 〈M 〉, we build a new Turing machine M 0 that accepts the same language as M and
moves left three times in a row if and only if it accepts, as follows. For each non-accepting state p
16
Models of Computation Lecture 7: Undecidability [Fa’16]
of M , the new machine M 0 has three states p1 , p2 , p3 , with the following transitions:
In other words, after each non-accepting transition, M 0 moves once to the right and then once to
the left. For each transition to accept, M 0 has a sequence of seven transitions: three steps to the
right, then three steps to the left, and then finally accept0 , all without modifying the tape. (The
three steps to the right ensure that M 0 does not fall off the left end of the tape.)
Finally, M 0 moves left three times in a row if and only if M accepts w. Thus, if we could
decide LeftThree, we could also decide Accept, which is impossible.
There is no hard and fast rule like Rice’s theorem to distinguish decidable behaviors from
undecidable behaviors, but I can offer two rules of thumb.
• If it is possible to simulate an arbitrary Turing machine while avoiding the target behavior,
then the behavior is not decidable. For example, there is no algorithm to determine whether
a given Turing machine reenters its start state, or revisits the left end of the tape, or writes
a blank.
• If a Turing machine with the target behavior is limited to a finite number of configurations,
or is guaranteed to force an infinite loop after a finite number of transitions, then the
behavior is likely to be decidable. For example, there are algorithms to determine whether
a given Turing machine ever leaves its start state, or reads its entire input string, or writes
a non-blank symbol over a blank.
Exercises
1. Let M be an arbitrary Turing machine.
(a) Describe a Turing machine M R such that
17
Models of Computation Lecture 7: Undecidability [Fa’16]
5. Let L be a non-empty proper subset of the set of acceptable languages. Prove that the
following languages are undecidable:
(a) RejectIn(L) := 〈M 〉 Reject(M ) ∈ L
(b) HaltIn(L) := 〈M 〉 Halt(M ) ∈ L
(c) DivergeIn(L) := 〈M 〉 Diverge(M ) ∈ L
6. For each of the following decision problems, either sketch an algorithm or prove that the
problem is undecidable. Recall that wR denotes the reversal of string w. For each problem,
the input is the encoding 〈M 〉 of a Turing machine M .
7. For each of the following decision problems, either sketch an algorithm or prove that the
problem is undecidable. Recall that wR denotes the reversal of string w. For each problem,
the input is an encoding 〈M , w〉 of a Turing machine M and its input string w.
18
Models of Computation Lecture 7: Undecidability [Fa’16]
8. Let M be a Turing machine, let w be an arbitrary input string, and let s and t be positive
integers integer. We say that M accepts w in space s if M accepts w after accessing at
most the first s cells on the tape, and M accepts w in time t if M accepts w after at most t
transitions.
9. Let L0 be an arbitrary language. For any integer i > 0, define the language
L i := 〈M 〉 M decides L i−1 .
For which integers i > 0 is L i decidable? Obviously the answer depends on the initial
language L0 ; give a complete characterization of all possible cases. Prove your answer is
correct. [Hint: This question is a lot easier than it looks!]
10. Argue that each of the following decision problems about programs in your favorite
programming language are undecidable.
19
Models of Computation Lecture 7: Undecidability [Fa’16]
? 11. Call a Turing machine conservative if it never writes over its input string. More formally, a
Turing machine is conservative if for every transition δ(p, a) = (q, b, ∆) where a ∈ Σ, we
have b = a; and for every transition δ(p, a) = (q, b, ∆) where a 6∈ Σ, we have b 6= Σ.
Together, these two results imply that every conservative Turing machine accepts the same
language as some DFA, but it is impossible to determine which DFA.
Æ
12. (a) Prove that it is undecidable whether a given C++ program is syntactically correct.
[Hint: Use templates!]
(b) Prove that it is undecidable whether a given ANSI C program is syntactically correct.
[Hint: Use the preprocessor!]
(c) Prove that it is undecidable whether a given Perl program is syntactically correct.
[Hint: Does that slash character / delimit a regular expression or represent division?]