Discrete MathematicsLanguages, Automata and Computability5 of 6
Languages, Automata and Computability · 5

Turing Machines and the Halting Problem

Finite automata can only read an input string once from left to right using a fixed number of states, so we need a machine that can write down scratch work and move back and forth to follow any step-by-step mathematical recipe.

1

Tape, Head, and States

A Turing machine strips computation down to three mechanical parts: an infinite one-dimensional tape of boxes that each hold one symbol, a head that reads, writes, and shifts one box left (L\text{L}), right (R\text{R}), or stays put (S\text{S}), and a finite rulebook of states that tracks which step of the recipe the machine is on.

Tape\text{Tape}
_\text{\_}
11
00
11
11
_\text{\_}
Head\htmlClass{lc-pink}{\text{Head}}
Read\text{Read}
Write\text{Write}
Move L/R/S\text{Move L/R/S}
WALK_RIGHT\text{WALK\_RIGHT}
State\text{State}
Rulebook\textbf{Rulebook}
WALK_RIGHT\text{WALK\_RIGHT}
ADD_ONE\text{ADD\_ONE}
HALT\htmlClass{lc-green}{\text{HALT}}

To add 11 to a binary number like 1011\given{1011} when the head starts on the leftmost digit, the machine first walks to the right end of the number in WALK_RIGHT\text{WALK\_RIGHT} and then carries leftward in ADD_ONE\text{ADD\_ONE}.

Tape, Head, and States
22
77
99
++
44
55
88
Text solution
Walk to the ones placeStarting on the leftmost 11 of 1011\given{1011} in WALK_RIGHT\text{WALK\_RIGHT}, the head leaves 00s and 11s unchanged and steps right until it hits the blank _\_ past the right end, then steps left onto the last digit and switches to ADD_ONE\text{ADD\_ONE}:
_ 1↑WALK_RIGHT 0 1 1 _⟶_ 1 0 1 1 _↑WALK_RIGHT⟶_ 1 0 1 1↑ADD_ONE _\displaystyle \begin{aligned} &\text{\_ }\underset{\substack{\head{\uparrow} \\ \text{WALK\_RIGHT}}}{1}\text{ }0\text{ }1\text{ }1\text{ \_} \\[2pt] \longrightarrow\quad &\text{\_ }1\text{ }0\text{ }1\text{ }1\text{ }\underset{\substack{\head{\uparrow} \\ \text{WALK\_RIGHT}}}{\text{\_}} \\[2pt] \longrightarrow\quad &\text{\_ }1\text{ }0\text{ }1\text{ }\underset{\substack{\head{\uparrow} \\ \text{ADD\_ONE}}}{1}\text{ \_} \end{aligned}
Carry leftward through trailing 11sIn ADD_ONE\text{ADD\_ONE}, each 11 turns into 00 and the head steps left in ADD_ONE\text{ADD\_ONE} to carry the 11 to the next column:
_ 1 0 1 1↑ADD_ONE _⟶_ 1 0 1↑ADD_ONE 0 _⟶_ 1 0↑ADD_ONE 0 0 _\displaystyle \begin{aligned} &\text{\_ }1\text{ }0\text{ }1\text{ }\underset{\substack{\head{\uparrow} \\ \text{ADD\_ONE}}}{1}\text{ \_} \\[2pt] \longrightarrow\quad &\text{\_ }1\text{ }0\text{ }\underset{\substack{\head{\uparrow} \\ \text{ADD\_ONE}}}{1}\text{ }0\text{ \_} \\[2pt] \longrightarrow\quad &\text{\_ }1\text{ }\underset{\substack{\head{\uparrow} \\ \text{ADD\_ONE}}}{0}\text{ }0\text{ }0\text{ \_} \end{aligned}
Write the carry and haltWhen the head reads 00 (or a left blank _\_), it overwrites it with 1\result{1}, stays put (S\text{S}), and switches to HALT\halts{\text{HALT}}:
_ 1 0↑ADD_ONE 0 0 _⟶_ 1 1↑HALT 0 0 _\displaystyle \begin{aligned} &\text{\_ }1\text{ }\underset{\substack{\head{\uparrow} \\ \text{ADD\_ONE}}}{0}\text{ }0\text{ }0\text{ \_} \\[2pt] \longrightarrow\quad &\text{\_ }1\text{ }\underset{\substack{\head{\uparrow} \\ \halts{\text{HALT}}}}{\result{1}}\text{ }0\text{ }0\text{ \_} \end{aligned}

So 10112\given{1011_2} (11\given{11}) becomes 11002\result{1100_2} (12\result{12}), and the machine stops without ever walking back over the leftmost digit.

2

Five-Tuples and Transition Tables

Instead of writing rules in full sentences, we write each instruction as a five-tuple or organize the rules into a transition table with current states down the rows and the symbol read across the columns:

(Current State⏟where I am,  Read⏟box symbol,  Write⏟new symbol,  Move⏟L, R, or S,  Next State⏟where I go)\displaystyle \begin{aligned} &(\underbrace{\text{Current State}}_{\text{where I am}},\; \underbrace{\text{Read}}_{\text{box symbol}},\; \\ &\quad \underbrace{\text{Write}}_{\text{new symbol}},\; \underbrace{\text{Move}}_{\text{L, R, or S}},\; \underbrace{\text{Next State}}_{\text{where I go}}) \end{aligned}

You might also see Next State\text{Next State} listed right after Read\text{Read}, and you can always spot which order is being used because the L,R,S\text{L}, \text{R}, \text{S} move direction is unmistakable. Let's trace the Add-One\text{Add-One} transition table on the binary input 11\given{11}, where the carry travels all the way to the blank at the left end.

Five-Tuples and Transition Tables
Rulebook\text{Rulebook}
WALKRIGHT\begin{gathered}\text{WALK}\\[-6pt]\text{RIGHT}\end{gathered}
see 0→write 0, R, stay\text{see } 0 \to \text{write } 0,\ \text{R},\ \text{stay}
see 1→write 1, R, stay\text{see } 1 \to \text{write } 1,\ \text{R},\ \text{stay}
see _→write _, L, ADD_ONE\text{see } \text{\_} \to \text{write } \text{\_},\ \text{L},\ \text{ADD\_ONE}
ADDONE\begin{gathered}\text{ADD}\\[-6pt]\text{ONE}\end{gathered}
see 1→write 0, L, stay\text{see } 1 \to \text{write } 0,\ \text{L},\ \text{stay}
see 0→write 1, S, HALT\text{see } 0 \to \text{write } 1,\ \text{S},\ \htmlClass{lc-green}{\text{HALT}}
see _→write 1, S, HALT\text{see } \text{\_} \to \text{write } 1,\ \text{S},\ \htmlClass{lc-green}{\text{HALT}}
CurrentState\begin{gathered}\text{Current}\\[-6pt]\text{State}\end{gathered}
Read\text{Read}
Write\text{Write}
Move\text{Move}
NextState\begin{gathered}\text{Next}\\[-6pt]\text{State}\end{gathered}
Text solution
Reach the right endStarting on the first 11 of _ 1 1 _\text{\_ }1\text{ }1\text{ \_}, row WALK_RIGHT\text{WALK\_RIGHT} steps right across both 11s onto the right blank _\_, then steps left onto the second 11 in ADD_ONE\text{ADD\_ONE}:
_ 1↑WALK_RIGHT 1 _⟶_ 1 1 _↑WALK_RIGHT⟶_ 1 1↑ADD_ONE _\displaystyle \begin{aligned} &\text{\_ }\underset{\substack{\head{\uparrow} \\ \text{WALK\_RIGHT}}}{1}\text{ }1\text{ \_} \\[2pt] \longrightarrow\quad &\text{\_ }1\text{ }1\text{ }\underset{\substack{\head{\uparrow} \\ \text{WALK\_RIGHT}}}{\text{\_}} \\[2pt] \longrightarrow\quad &\text{\_ }1\text{ }\underset{\substack{\head{\uparrow} \\ \text{ADD\_ONE}}}{1}\text{ \_} \end{aligned}
Carry onto the left blankRow ADD_ONE\text{ADD\_ONE} turns both 11s into 00s as the head steps left onto the blank _\_, where rule (ADD_ONE,_,1,S,HALT)(\text{ADD\_ONE}, \text{\_}, 1, \text{S}, \halts{\text{HALT}}) writes the leading 11 and halts:
_ 1 1↑ADD_ONE _⟶_ 1↑ADD_ONE 0 _⟶_↑ADD_ONE 0 0 _⟶1↑HALT 0 0 _\displaystyle \begin{aligned} &\text{\_ }1\text{ }\underset{\substack{\head{\uparrow} \\ \text{ADD\_ONE}}}{1}\text{ \_} \\[2pt] \longrightarrow\quad &\text{\_ }\underset{\substack{\head{\uparrow} \\ \text{ADD\_ONE}}}{1}\text{ }0\text{ \_} \\[2pt] \longrightarrow\quad &\underset{\substack{\head{\uparrow} \\ \text{ADD\_ONE}}}{\text{\_}}\text{ }0\text{ }0\text{ \_} \\[2pt] \longrightarrow\quad &\underset{\substack{\head{\uparrow} \\ \halts{\text{HALT}}}}{\result{1}}\text{ }0\text{ }0\text{ \_} \end{aligned}

So 112\given{11_2} (3\given{3}) becomes 1002\result{100_2} (4\result{4}) in six steps. When you are given a transition table, don't stare at the whole grid to guess what it does. Trace three or four steps on a tiny example tape and the pattern will jump right out.

In this machine, a run of trailing 11s keeps ADD_ONE\text{ADD\_ONE} stepping left and turning each 11 into 00 until the very first 00 or the left blank _\_ becomes 1\result{1} and halts.

After `WALK_RIGHT` bounces off the right blank, `ADD_ONE` steps left through each trailing `1`, turning it into `0`, until the first `0` or the left blank turns into `1` and the machine halts.
3

Deciding 0n1n0^n1^n on a Tape

A Turing machine decides a language when it is guaranteed to eventually stop in ACCEPT\halts{\text{ACCEPT}} (yes) or REJECT\rejects{\text{REJECT}} (no) on every possible input without ever getting stuck in an infinite loop. Even though a Turing machine has only a fixed, finite number of states just like a finite automaton, it can decide L={0n1n∣n≥0}L = \{0^n1^n \mid n \ge 0\} by zig-zagging across the tape and crossing off one 00 with an XX for each 11 it crosses off with a YY.

Deciding 0ⁿ1ⁿ on a Tape
L={ 0n1n∣n≥0 }L = \{\, 0^n 1^n \mid n \ge 0 \,\}
01001100011101 \qquad 0011 \qquad 000111
_\text{\_}
00
00
00
11
11
11
_\text{\_}
START\text{START}
Text solution
Cross off matching pairs on 0011\given{0011}Starting in START\text{START}, each round overwrites the leftmost remaining 00 with XX, walks right in FIND_1\text{FIND\_1} to overwrite the first unmatched 11 with YY, and walks left in RETURN_LEFT\text{RETURN\_LEFT} back to XX:
_ 0↑START 0 1 1 _⟶_ X 0↑START Y 1 _⟶_ X X Y↑START Y _\displaystyle \begin{aligned} &\text{\_ }\underset{\substack{\head{\uparrow} \\ \text{START}}}{0}\text{ }0\text{ }1\text{ }1\text{ \_} \\[2pt] \longrightarrow\quad &\text{\_ }X\text{ }\underset{\substack{\head{\uparrow} \\ \text{START}}}{0}\text{ }Y\text{ }1\text{ \_} \\[2pt] \longrightarrow\quad &\text{\_ }X\text{ }X\text{ }\underset{\substack{\head{\uparrow} \\ \text{START}}}{Y}\text{ }Y\text{ \_} \end{aligned}
Verify no unmatched symbols remain on 0011\given{0011}Seeing YY in START\text{START} tells the head all 00s are matched, so it switches to CHECK_REST\text{CHECK\_REST}, scans past every YY to the right blank _\_, and halts in ACCEPT\halts{\text{ACCEPT}}:
_ X X Y↑START Y _⟶_ X X Y Y↑CHECK_REST _⟶_ X X Y Y _↑ACCEPT\displaystyle \begin{aligned} &\text{\_ }X\text{ }X\text{ }\underset{\substack{\head{\uparrow} \\ \text{START}}}{Y}\text{ }Y\text{ \_} \\[2pt] \longrightarrow\quad &\text{\_ }X\text{ }X\text{ }Y\text{ }\underset{\substack{\head{\uparrow} \\ \text{CHECK\_REST}}}{Y}\text{ \_} \\[2pt] \longrightarrow\quad &\text{\_ }X\text{ }X\text{ }Y\text{ }Y\text{ }\underset{\substack{\head{\uparrow} \\ \halts{\text{ACCEPT}}}}{\text{\_}} \end{aligned}
Catch an unmatched 1\leftover{1} on 011\given{011}After pairing the single 00 with the first 11, START\text{START} sees YY and enters CHECK_REST\text{CHECK\_REST}, which immediately hits the leftover 1\leftover{1} and halts in REJECT\rejects{\text{REJECT}}:
_ 0↑START 1 1 _⟶_ X Y↑START 1 _⟶_ X Y 1↑CHECK_REST _⟶_ X Y 1↑REJECT _\displaystyle \begin{aligned} &\text{\_ }\underset{\substack{\head{\uparrow} \\ \text{START}}}{0}\text{ }1\text{ }1\text{ \_} \\[2pt] \longrightarrow\quad &\text{\_ }X\text{ }\underset{\substack{\head{\uparrow} \\ \text{START}}}{Y}\text{ }1\text{ \_} \\[2pt] \longrightarrow\quad &\text{\_ }X\text{ }Y\text{ }\underset{\substack{\head{\uparrow} \\ \text{CHECK\_REST}}}{\leftover{1}}\text{ \_} \\[2pt] \longrightarrow\quad &\text{\_ }X\text{ }Y\text{ }\underset{\substack{\head{\uparrow} \\ \rejects{\text{REJECT}}}}{\leftover{1}}\text{ \_} \end{aligned}

So 0011\given{0011} is accepted and 011\given{011} is rejected using only four working states, no matter how large nn grows.

Any mismatch, like hitting the blank in FIND_1\text{FIND\_1} or seeing an unmatched 1\leftover{1} or out-of-order 0\leftover{0} in CHECK_REST\text{CHECK\_REST}, immediately sends the machine to REJECT\rejects{\text{REJECT}}.

The four states stay fixed while X and Y on the tape keep the count, and any mismatch lands directly on a REJECT cell.
4

The Church-Turing Thesis and Universal Machines

The Church-Turing Thesis states that every step-by-step algorithm that can be carried out by a human or physical computer can be carried out by a Turing machine. Because any rulebook of five-tuples is just text that can be encoded as a string of 00s and 11s (a machine's blueprint), one master Universal Turing Machine can read the blueprint of any machine MM and an input II on its tape and simulate MM running on II.

The Church-Turing Thesis and Universal Machines
Church-Turing Thesis\textbf{Church-Turing Thesis}
every step-by-step algorithm\text{every step-by-step algorithm}
a Turing machine\text{a Turing machine}
_\text{\_}
11
00
11
11
_\text{\_}
WALK_RIGHT\text{WALK\_RIGHT}
5

The Halting Problem Is Undecidable

The Halting Problem asks whether we can build a single decider, HaltChecker\text{HaltChecker}, that takes any blueprint MM and any input II and always finishes in finite time with HALTS\halts{\text{HALTS}} or LOOPS\loops{\text{LOOPS}}. To prove that no such machine can exist, we assume HaltChecker\assumed{\text{HaltChecker}} exists and wire it inside a new machine called Rebel\built{\text{Rebel}} that feeds a blueprint into itself and does the opposite of whatever HaltChecker\assumed{\text{HaltChecker}} predicts.

Rebel\htmlClass{lc-pink}{\text{Rebel}}
Blueprint X\text{Blueprint }X
101101\htmlClass{lc-mute}{101101}
Copier\htmlClass{lc-violet}{\text{Copier}}
Blueprint M\text{Blueprint }M
Input I\text{Input }I
HaltChecker\htmlClass{lc-blue}{\text{HaltChecker}}
HALTS\htmlClass{lc-green}{\text{HALTS}}
LOOPS\htmlClass{lc-orange}{\text{LOOPS}}
HALT!\htmlClass{lc-green}{\text{HALT!}}
LOOP FOREVER\htmlClass{lc-orange}{\text{LOOP FOREVER}}
The Halting Problem Is Undecidable
Blueprint M\text{Blueprint }M
1011010\htmlClass{lc-mute}{1011010}
Input I\text{Input }I
HaltChecker ?\text{HaltChecker}\,?
IT HALTS!\htmlClass{lc-green}{\text{IT HALTS!}}
IT LOOPS!\htmlClass{lc-orange}{\text{IT LOOPS!}}
always answers, in finite time\text{always answers, in finite time}
Text solution
Wire the opposite-day machineOn any input blueprint XX, Rebel\built{\text{Rebel}} copies XX into both slots of HaltChecker\assumed{\text{HaltChecker}} and flips the outcome:
Rebel(X)={loop foreverif HaltChecker(X,X)=HALTShalt immediatelyif HaltChecker(X,X)=LOOPS\displaystyle \begin{aligned} &\built{\text{Rebel}}(X) = \\ &\begin{cases} \loops{\text{loop forever}} \\ \quad \text{if } \assumed{\text{HaltChecker}}(X, X) \\ \qquad = \halts{\text{HALTS}} \\[6pt] \halts{\text{halt immediately}} \\ \quad \text{if } \assumed{\text{HaltChecker}}(X, X) \\ \qquad = \loops{\text{LOOPS}} \end{cases} \end{aligned}
Feed Rebel\built{\text{Rebel}} its own blueprint [Rebel][\built{\text{Rebel}}]Substituting X=[Rebel]X = [\built{\text{Rebel}}] forces HaltChecker\assumed{\text{HaltChecker}}'s prediction to contradict what Rebel\built{\text{Rebel}} actually does in both cases:
HaltChecker([Rebel],[Rebel])=HALTS  ⟹  Rebel([Rebel]) loops foreverHaltChecker([Rebel],[Rebel])=LOOPS  ⟹  Rebel([Rebel]) halts\displaystyle \begin{aligned} &\assumed{\text{HaltChecker}}([\built{\text{Rebel}}], [\built{\text{Rebel}}]) \\ &= \halts{\text{HALTS}} \\ &\implies \built{\text{Rebel}}([\built{\text{Rebel}}])\text{ }\loops{\text{loops forever}} \\[6pt] &\assumed{\text{HaltChecker}}([\built{\text{Rebel}}], [\built{\text{Rebel}}]) \\ &= \loops{\text{LOOPS}} \\ &\implies \built{\text{Rebel}}([\built{\text{Rebel}}])\text{ }\halts{\text{halts}} \end{aligned}

Since both cases contradict HaltChecker\assumed{\text{HaltChecker}}'s prediction and the copier and two-step loop are easy to build, HaltChecker\assumed{\text{HaltChecker}} itself cannot exist.

Now let's test this diagonal contradiction by placing Rebel on each row of the table.

Because Rebel is wired to do the opposite of every square on the diagonal, placing it on any row of HaltChecker's table always clashes at that row's diagonal square.
6

Undecidability by Reduction

A reduction proves that a new analyzer Tool X\assumed{\text{Tool } X} cannot exist by showing that if Tool X\assumed{\text{Tool } X} worked, we could wire it up with a simple text-editing adapter to build a working HaltChecker\built{\text{HaltChecker}}. Let's use a reduction to prove that BlankHaltChecker\assumed{\text{BlankHaltChecker}}, a machine that takes only a single blueprint M′M' and decides whether M′M' halts when started on a blank tape, is also impossible.

HaltChecker\htmlClass{lc-pink}{\text{HaltChecker}}
Blueprint M\text{Blueprint }M
Input I\text{Input }I
110100\htmlClass{lc-mute}{110100}
Blueprint Builder\htmlClass{lc-violet}{\text{Blueprint Builder}}
Blueprint M′\text{Blueprint }M'
Stage 1: write I on blank tape\text{Stage 1: write }I\text{ on blank tape}
Stage 2: run M\text{Stage 2: run }M
BlankHaltChecker\htmlClass{lc-blue}{\text{BlankHaltChecker}}
HALTS!\htmlClass{lc-green}{\text{HALTS!}}
LOOPS!\htmlClass{lc-orange}{\text{LOOPS!}}
Undecidability by Reduction
Blueprint M\text{Blueprint }M
1101001\htmlClass{lc-mute}{1101001}
Input I\text{Input }I
??
Blueprint M′\text{Blueprint }M'
BlankHaltChecker\htmlClass{lc-blue}{\text{BlankHaltChecker}}
HALTS ON BLANK!\htmlClass{lc-green}{\text{HALTS ON BLANK!}}
LOOPS ON BLANK!\htmlClass{lc-orange}{\text{LOOPS ON BLANK!}}
Text solution
Edit the rulebook without running MMGiven any blueprint MM and input II, the Blueprint Builder\builder{\text{Blueprint Builder}} pastes two stages of five-tuples together to write the blueprint of a new machine M′M':
M′ on a blank tape _:Stage 1: write Iand return head to start⏟always takes finite steps  ⟶  Stage 2: run rules of M⏟runs M on I\displaystyle \begin{aligned} &M' \text{ on a blank tape } \text{\_}: \\ &\quad \underbrace{\begin{aligned} &\text{Stage 1: write } I \\ &\text{and return head to start} \end{aligned}}_{\halts{\text{always takes finite steps}}} \\ &\quad \;\longrightarrow\; \underbrace{\text{Stage 2: run rules of } M}_{\text{runs } M \text{ on } I} \end{aligned}
Match both outcomesStarted on a blank tape, M′M' writes II and then does on that tape whatever MM does on II:
M halts on I  ⟺  M′ halts on _  ⟺  BlankHaltChecker(M′)=HALTS!M loops on I  ⟺  M′ loops on _  ⟺  BlankHaltChecker(M′)=LOOPS!\displaystyle \begin{aligned} &M\text{ }\halts{\text{halts}}\text{ on } I \\ &\iff M'\text{ }\halts{\text{halts}}\text{ on } \text{\_} \\ &\iff \assumed{\text{BlankHaltChecker}}(M') \\ &\qquad = \halts{\text{HALTS!}} \\[8pt] &M\text{ }\loops{\text{loops}}\text{ on } I \\ &\iff M'\text{ }\loops{\text{loops}}\text{ on } \text{\_} \\ &\iff \assumed{\text{BlankHaltChecker}}(M') \\ &\qquad = \loops{\text{LOOPS!}} \end{aligned}

Because pasting Stage 1 onto MM's rulebook is pure text editing that always finishes, a working BlankHaltChecker\assumed{\text{BlankHaltChecker}} would give a working HaltChecker\built{\text{HaltChecker}}, so BlankHaltChecker\assumed{\text{BlankHaltChecker}} cannot exist.

Key concepts

A Turing machine adds an infinite tape to a finite state table, where the head can read, write, and move L\text{L}, R\text{R}, or S\text{S} according to five-tuples (Current State,Read,(\text{Current State}, \text{Read}, Write,Move,\text{Write}, \text{Move}, Next State)\text{Next State}). When you build or trace a machine, let the tape do the counting while the states handle the small repeatable jobs: in the Add-One\text{Add-One} machine, ADD_ONE\text{ADD\_ONE} steps left turning 11s into 00s until a 00 or _\_ becomes 1\result{1}; in the 0n1n0^n1^n decider, four states zig-zag between XX and YY tally marks on the tape. To decide a language, a machine must halt in ACCEPT\halts{\text{ACCEPT}} or REJECT\rejects{\text{REJECT}} on every input. If it gets stuck in an infinite loop like (GO,0,0,R,GO)(\text{GO}, 0, 0, \text{R}, \text{GO}) and (GO,1,1,L,GO)(\text{GO}, 1, 1, \text{L}, \text{GO}) on even a single input, it is not a decider.

Because a rulebook is just text, any machine MM can be encoded as a binary blueprint [M][M] and simulated by a Universal Turing Machine, which also means a machine can be fed its own blueprint. That self-reference powers our two ways of proving a problem is undecidable:

Diagonalization (Rebel\built{\text{Rebel}})

To prove HaltChecker\assumed{\text{HaltChecker}} cannot exist, copy an input blueprint XX into both slots of HaltChecker\assumed{\text{HaltChecker}} and flip its prediction (HALTS→loop\halts{\text{HALTS}} \to \loops{\text{loop}}, LOOPS→halt\loops{\text{LOOPS}} \to \halts{\text{halt}}), so Rebel\built{\text{Rebel}} disagrees with every row kk of the machine-versus-blueprint table at box (k,k)(k, k), and feeding [Rebel][\built{\text{Rebel}}] into Rebel\built{\text{Rebel}} contradicts HaltChecker\assumed{\text{HaltChecker}}'s prediction. Note that undecidability only rules out a single universal algorithm for all programs; you can still decide halting for specific machines like Add-One\text{Add-One} or GO\text{GO} by inspecting their rules directly.

Reduction (Blueprint Builder\builder{\text{Blueprint Builder}})

When a problem asks you to prove a new analyzer Tool X\assumed{\text{Tool } X} is impossible, don't build a new diagonal table and never try to build Tool X\built{\text{Tool } X} out of HaltChecker\assumed{\text{HaltChecker}} (wiring it backwards proves the vacuous statement "if HaltChecker\assumed{\text{HaltChecker}} exists, then Tool X\built{\text{Tool } X} exists"). Instead, assume Tool X\assumed{\text{Tool } X} exists and build HaltChecker\built{\text{HaltChecker}} out of it by having a Blueprint Builder\builder{\text{Blueprint Builder}} write a modified rulebook M′M' (such as Stage 1 writing II on a blank tape and Stage 2 running MM) so that Tool X(M′)\assumed{\text{Tool } X}(M') answers whether MM halts on II.

7

Practice

1

A Turing machine that adds 11 to a binary number is given by the six five-tuples (Current State,Read,(\text{Current State}, \text{Read}, Write,Move,\text{Write}, \text{Move}, Next State)\text{Next State}):

(WALK_RIGHT,0,0,R,WALK_RIGHT)(WALK_RIGHT,1,1,R,WALK_RIGHT)(WALK_RIGHT,_,_,L,ADD_ONE)(ADD_ONE,1,0,L,ADD_ONE)(ADD_ONE,0,1,S,HALT)(ADD_ONE,_,1,S,HALT)\displaystyle \begin{aligned} &(\text{WALK\_RIGHT}, 0, 0, \\ &\qquad \text{R}, \text{WALK\_RIGHT}) \\[6pt] &(\text{WALK\_RIGHT}, 1, 1, \\ &\qquad \text{R}, \text{WALK\_RIGHT}) \\[6pt] &(\text{WALK\_RIGHT}, \text{\_}, \text{\_}, \\ &\qquad \text{L}, \text{ADD\_ONE}) \\[6pt] &(\text{ADD\_ONE}, 1, 0, \\ &\qquad \text{L}, \text{ADD\_ONE}) \\[6pt] &(\text{ADD\_ONE}, 0, 1, \\ &\qquad \text{S}, \halts{\text{HALT}}) \\[6pt] &(\text{ADD\_ONE}, \text{\_}, 1, \\ &\qquad \text{S}, \halts{\text{HALT}}) \end{aligned}

Trace this machine step-by-step on the input tape _ 1 0 1 _\text{\_ }1\text{ }0\text{ }1\text{ \_}, starting in state WALK_RIGHT\text{WALK\_RIGHT} with the head on the leftmost 11. For each step, give the tape contents, the head position, and the current state until the machine halts.

Keep the head in WALK_RIGHT\text{WALK\_RIGHT} until it actually steps onto the right blank _\_; only then does it step left and switch into ADD_ONE\text{ADD\_ONE}.

Using brackets [ ]\head{[}~\head{]} to mark the square under the head:
Start: _ [1] 0 1 _\text{\_ }\head{[}1\head{]}\text{ }0\text{ }1\text{ \_}, state WALK_RIGHT\text{WALK\_RIGHT}.
Step 1 (read 1→write 1\text{read } 1 \to \text{write } 1, R\text{R}, WALK_RIGHT\text{WALK\_RIGHT}): _ 1 [0] 1 _\text{\_ }1\text{ }\head{[}0\head{]}\text{ }1\text{ \_}, state WALK_RIGHT\text{WALK\_RIGHT}.
Step 2 (read 0→write 0\text{read } 0 \to \text{write } 0, R\text{R}, WALK_RIGHT\text{WALK\_RIGHT}): _ 1 0 [1] _\text{\_ }1\text{ }0\text{ }\head{[}1\head{]}\text{ \_}, state WALK_RIGHT\text{WALK\_RIGHT}.
Step 3 (read 1→write 1\text{read } 1 \to \text{write } 1, R\text{R}, WALK_RIGHT\text{WALK\_RIGHT}): _ 1 0 1 [_]\text{\_ }1\text{ }0\text{ }1\text{ }\head{[}\text{\_}\head{]}, state WALK_RIGHT\text{WALK\_RIGHT}. (Watch out: a common slip is switching to ADD_ONE\text{ADD\_ONE} on Step 3 as soon as the head reaches the rightmost 11, which gives a 4-step trace; the machine doesn't know it has reached the end until it steps onto _\_.)
Step 4 (read _→write _\text{read } \text{\_} \to \text{write } \text{\_}, L\text{L}, ADD_ONE\text{ADD\_ONE}): _ 1 0 [1] _\text{\_ }1\text{ }0\text{ }\head{[}1\head{]}\text{ \_}, state ADD_ONE\text{ADD\_ONE}.
Step 5 (read 1→write 0\text{read } 1 \to \text{write } 0, L\text{L}, ADD_ONE\text{ADD\_ONE}): _ 1 [0] 0 _\text{\_ }1\text{ }\head{[}0\head{]}\text{ }0\text{ \_}, state ADD_ONE\text{ADD\_ONE}.
Step 6 (read 0→write 1\text{read } 0 \to \text{write } \result{1}, S\text{S}, HALT\halts{\text{HALT}}): _ 1 [1] 0 _\text{\_ }1\text{ }\head{[}\result{1}\head{]}\text{ }0\text{ \_}, state HALT\halts{\text{HALT}}.
The machine halts after 66 steps with _ 1 [1] 0 _\text{\_ }1\text{ }\head{[}\result{1}\head{]}\text{ }0\text{ \_} in state HALT\halts{\text{HALT}}.
2

Trace the 0n1n0^n1^n decider on the two rejected inputs (a) 001\given{001} and (b) 010\given{010}, starting in state START\text{START} on the leftmost symbol. For each input, find the step number, the state, the symbol read, and the tape contents at the exact moment the machine enters REJECT\rejects{\text{REJECT}}.

After RETURN_LEFT\text{RETURN\_LEFT} hits an XX and steps right into START\text{START}, check carefully whether the symbol under the head is 00 (starting another FIND_1\text{FIND\_1} round) or YY (switching into CHECK_REST\text{CHECK\_REST}).

(a) On input 001\given{001}:
Start: _ [0] 0 1 _\text{\_ }\head{[}0\head{]}\text{ }0\text{ }1\text{ \_}, state START\text{START}.
Step 1: _ X [0] 1 _\text{\_ }X\text{ }\head{[}0\head{]}\text{ }1\text{ \_}, state FIND_1\text{FIND\_1}.
Step 2: _ X 0 [1] _\text{\_ }X\text{ }0\text{ }\head{[}1\head{]}\text{ \_}, state FIND_1\text{FIND\_1}.
Step 3: _ X [0] Y _\text{\_ }X\text{ }\head{[}0\head{]}\text{ }Y\text{ \_}, state RETURN_LEFT\text{RETURN\_LEFT}.
Step 4: _ [X] 0 Y _\text{\_ }\head{[}X\head{]}\text{ }0\text{ }Y\text{ \_}, state RETURN_LEFT\text{RETURN\_LEFT}.
Step 5: _ X [0] Y _\text{\_ }X\text{ }\head{[}0\head{]}\text{ }Y\text{ \_}, state START\text{START}.
Step 6: _ X X [Y] _\text{\_ }X\text{ }X\text{ }\head{[}Y\head{]}\text{ \_}, state FIND_1\text{FIND\_1}. (Don't confuse reading YY in FIND_1\text{FIND\_1} with reading YY in START\text{START}: in FIND_1\text{FIND\_1} the head is still looking for a 11 to match the second XX, so it steps right over YY and stays in FIND_1\text{FIND\_1} instead of switching to CHECK_REST\text{CHECK\_REST}.)
Step 7: _ X X Y [_]\text{\_ }X\text{ }X\text{ }Y\text{ }\head{[}\text{\_}\head{]}, state FIND_1\text{FIND\_1}.
Step 8: In state FIND_1\text{FIND\_1}, the head reads _\_ and transitions via (_,S,REJECT)(\text{\_}, \text{S}, \rejects{\text{REJECT}}) to state REJECT\rejects{\text{REJECT}} with tape _ X X Y [_]\text{\_ }X\text{ }\leftover{X}\text{ }Y\text{ }\head{[}\text{\_}\head{]}.
(b) On input 010\given{010}:
Start: _ [0] 1 0 _\text{\_ }\head{[}0\head{]}\text{ }1\text{ }0\text{ \_}, state START\text{START}.
Step 1: _ X [1] 0 _\text{\_ }X\text{ }\head{[}1\head{]}\text{ }0\text{ \_}, state FIND_1\text{FIND\_1}.
Step 2: _ [X] Y 0 _\text{\_ }\head{[}X\head{]}\text{ }Y\text{ }0\text{ \_}, state RETURN_LEFT\text{RETURN\_LEFT}.
Step 3: _ X [Y] 0 _\text{\_ }X\text{ }\head{[}Y\head{]}\text{ }0\text{ \_}, state START\text{START}.
Step 4: _ X Y [0] _\text{\_ }X\text{ }Y\text{ }\head{[}\leftover{0}\head{]}\text{ \_}, state CHECK_REST\text{CHECK\_REST}. (Because START\text{START} saw YY, it switched to CHECK_REST\text{CHECK\_REST} rather than staying in START\text{START} to cross off the second 00.)
Step 5: In state CHECK_REST\text{CHECK\_REST}, the head reads 00 and transitions via (0,S,REJECT)(0, \text{S}, \rejects{\text{REJECT}}) to state REJECT\rejects{\text{REJECT}} with tape _ X Y [0] _\text{\_ }X\text{ }Y\text{ }\head{[}\leftover{0}\head{]}\text{ \_}.
3

Write the rulebook as a list of five-tuples (Current State,Read,(\text{Current State}, \text{Read}, Write,Move,\text{Write}, \text{Move}, Next State)\text{Next State}) for a Turing machine that starts on the leftmost digit of a non-empty binary string (surrounded by blanks _\_), flips every bit (00 becomes 11 and 11 becomes 00), and returns the head to the leftmost digit of the string before halting in state HALT\halts{\text{HALT}}.

Use one state FLIP\text{FLIP} to walk right while flipping bits until it hits the right blank _\_, and a second state RETURN\text{RETURN} to walk left past the flipped bits until it hits the left blank _\_.

Using working states FLIP\text{FLIP} and RETURN\text{RETURN}:
1.  (FLIP,0,1,R,FLIP)2.  (FLIP,1,0,R,FLIP)3.  (FLIP,_,_,L,RETURN)4.  (RETURN,0,0,L,RETURN)5.  (RETURN,1,1,L,RETURN)6.  (RETURN,_,_,R,HALT)\displaystyle \begin{aligned} 1.\;&(\text{FLIP}, 0, 1, \text{R}, \text{FLIP}) \\ 2.\;&(\text{FLIP}, 1, 0, \text{R}, \text{FLIP}) \\ 3.\;&(\text{FLIP}, \text{\_}, \text{\_}, \text{L}, \text{RETURN}) \\ 4.\;&(\text{RETURN}, 0, 0, \text{L}, \text{RETURN}) \\ 5.\;&(\text{RETURN}, 1, 1, \text{L}, \text{RETURN}) \\ 6.\;&(\text{RETURN}, \text{\_}, \text{\_}, \text{R}, \halts{\text{HALT}}) \end{aligned}
(Be careful on rule 6: writing (RETURN,_,_,S,HALT)(\text{RETURN}, \text{\_}, \text{\_}, \text{S}, \halts{\text{HALT}}) leaves the head stopped on the blank _\_ to the left of the string instead of stepping R\text{R} back onto the leftmost digit.)
4

Consider the Turing machine with start state AA, working state BB, halting states ACCEPT\halts{\text{ACCEPT}} and REJECT\rejects{\text{REJECT}}, and the following transition table:

  • Row AA: Read 0→(0,R,B)\text{Read } 0 \to (0, \text{R}, B) | Read 1→(1,S,ACCEPT)\text{Read } 1 \to (1, \text{S}, \halts{\text{ACCEPT}}) | Read _→(_,S,REJECT)\text{Read } \text{\_} \to (\text{\_}, \text{S}, \rejects{\text{REJECT}})
  • Row BB: Read 0→(0,L,A)\text{Read } 0 \to (0, \text{L}, A) | Read 1→(1,R,A)\text{Read } 1 \to (1, \text{R}, A) | Read _→(_,S,REJECT)\text{Read } \text{\_} \to (\text{\_}, \text{S}, \rejects{\text{REJECT}})

Determine what this machine does when started on the leftmost symbol of (a) 11\given{11}, (b) 01\given{01}, and (c) 00\given{00}. Does this machine decide a language? Explain why or why not.

After tracing all three two-bit strings, check the definition of a decider: is halting on some inputs enough?

(a) On 11\given{11}: Starts in AA on the first 11; rule (A,1)→(1,S,ACCEPT)(A, 1) \to (1, \text{S}, \halts{\text{ACCEPT}}) immediately halts in ACCEPT\halts{\text{ACCEPT}} after 11 step.
(b) On 01\given{01}: Starts in AA on 00 →\to moves right onto 11 in state BB →\to rule (B,1)(B, 1) moves right onto _\_ in state AA →\to rule (A,_)(A, \text{\_}) halts in REJECT\rejects{\text{REJECT}} after 33 steps.
(c) On 00\given{00}: Starts in AA on the first 00 →\to moves right onto the second 00 in state BB →\to rule (B,0)(B, 0) moves left back onto the first 00 in state AA →\to repeats forever in an infinite loop.
It is tempting to say yes because the machine accepts strings like 11\given{11} and rejects strings like 01\given{01}, but to decide a language a Turing machine must halt in ACCEPT\halts{\text{ACCEPT}} or REJECT\rejects{\text{REJECT}} on every possible input; because it loops forever on 00\given{00}, this machine does not decide a language.
5

In the proof that HaltChecker\assumed{\text{HaltChecker}} cannot exist, the Rebel\built{\text{Rebel}} machine wires an opposite-day attachment onto HaltChecker\assumed{\text{HaltChecker}}. Suppose instead we build a machine called Copycat\built{\text{Copycat}} that wires a matching attachment onto HaltChecker\assumed{\text{HaltChecker}}: on input Blueprint XX, Copycat\built{\text{Copycat}} copies XX into both slots of HaltChecker\assumed{\text{HaltChecker}}, and if HaltChecker\assumed{\text{HaltChecker}} outputs HALTS\halts{\text{HALTS}}, Copycat\built{\text{Copycat}} immediately halts; if HaltChecker\assumed{\text{HaltChecker}} outputs LOOPS\loops{\text{LOOPS}}, Copycat\built{\text{Copycat}} jumps into an infinite loop. (a) What happens if we feed the Blueprint of Copycat\built{\text{Copycat}} into Copycat\built{\text{Copycat}}? Why doesn't this prove HaltChecker\assumed{\text{HaltChecker}} is impossible? (b) Explain the difference between Copycat\built{\text{Copycat}} and Rebel\built{\text{Rebel}} in terms of Cantor's diagonal table of machines M1,M2,M3,…M_1, M_2, M_3, \dots and inputs [M1][M_1], [M2][M_2], [M3][M_3], …\dots.

Check whether HaltChecker\assumed{\text{HaltChecker}}'s prediction matches or clashes with what Copycat([Copycat])\built{\text{Copycat}}([\built{\text{Copycat}}]) actually does in box (k,k)(k, k).

(a) When we feed [Copycat][\built{\text{Copycat}}] into Copycat\built{\text{Copycat}}, both cases are completely consistent: if HaltChecker\assumed{\text{HaltChecker}} predicts HALTS\halts{\text{HALTS}}, Copycat\built{\text{Copycat}} halts, matching the prediction; if HaltChecker\assumed{\text{HaltChecker}} predicts LOOPS\loops{\text{LOOPS}}, Copycat\built{\text{Copycat}} enters the infinite loop and loops forever, also matching the prediction. (Don't assume self-reference alone creates a paradox. Without flipping the output, neither case produces a contradiction, so Copycat\built{\text{Copycat}} cannot rule out HaltChecker\assumed{\text{HaltChecker}}.) (b) On the infinite table where row kk is Copycat\built{\text{Copycat}}, the diagonal box (k,k)(k, k) represents Copycat\built{\text{Copycat}} running on [Copycat][\built{\text{Copycat}}]. Because Copycat\built{\text{Copycat}} matches whatever HaltChecker\assumed{\text{HaltChecker}} puts in box (k,k)(k, k), it can sit on row kk without contradiction whether box (k,k)(k, k) says HALTS\halts{\text{HALTS}} or LOOPS\loops{\text{LOOPS}}, whereas Rebel\built{\text{Rebel}} flips every diagonal entry so its behavior at (k,k)(k, k) is the exact opposite of box (k,k)(k, k), making it impossible for Rebel\built{\text{Rebel}} to exist on any row kk of the table.
6

Suppose someone claims to have built a Turing machine called Print$Checker\text{Print\$Checker} that takes a single blueprint M′M' as input and always halts with YES\halts{\text{YES}} if M′M' ever writes the symbol $\$ when started on a blank tape, and NO\loops{\text{NO}} if M′M' never writes $\$ when started on a blank tape. (a) Prove that Print$Checker\text{Print\$Checker} cannot exist by reducing HaltChecker\text{HaltChecker} to it. Specify how the Blueprint Builder\builder{\text{Blueprint Builder}} constructs M′M' from a blueprint MM and input II, and verify both cases. (b) A classmate attempts the reduction by saying: "Assume HaltChecker\text{HaltChecker} exists. Given M′M', run HaltChecker\text{HaltChecker} on M′M' and a blank tape, and see if $\$ is on the tape when it finishes." Explain why this reduction is wired backwards and proves nothing about Print$Checker\text{Print\$Checker}.

For (a), make sure MM cannot accidentally print $\$ on its own while running on II, and wire M′M' so that $\$ is written if and only if MM reaches a halting state on II.

(a) Assume for contradiction that a working Print$Checker\assumed{\text{Print\$Checker}} exists. We build HaltChecker\built{\text{HaltChecker}} on any input blueprint MM and input II as follows:
First, if MM or II uses the symbol $\$, rename $\$ everywhere in MM's rulebook and in II to a fresh symbol so MM never writes $\$ on its own. (Skipping this renaming step is a classic slip: if MM printed $\$ partway through an infinite loop, Print$Checker\text{Print\$Checker} would output YES\text{YES} even though MM never halted.)
Pass MM and II into a Blueprint Builder\builder{\text{Blueprint Builder}} that writes the five-tuples of a new machine M′M' with three stages on a blank tape:
Stage 1: Write II onto the blank tape and return the head to the leftmost symbol of II.
Stage 2: Run the rules of MM.
Stage 3: Replace every halting transition of MM with a transition to a new state WRITE_$\text{WRITE\_\$} that writes $\$ on the tape and then halts.
Feed M′M' into Print$Checker\assumed{\text{Print\$Checker}} and output HALTS!\halts{\text{HALTS!}} if it says YES\halts{\text{YES}}, or LOOPS!\loops{\text{LOOPS!}} if it says NO\loops{\text{NO}}.
Verify both cases:
If MM halts on II, then M′M' started on a blank tape writes II, runs MM until MM finishes, enters WRITE_$\text{WRITE\_\$}, and writes $\$, so Print$Checker(M′)=YES\assumed{\text{Print\$Checker}}(M') = \halts{\text{YES}} and our outer box outputs HALTS!\halts{\text{HALTS!}}.
If MM loops forever on II, then M′M' writes II in finite time and loops forever inside Stage 2 without ever reaching WRITE_$\text{WRITE\_\$} or writing $\$, so Print$Checker(M′)=NO\assumed{\text{Print\$Checker}}(M') = \loops{\text{NO}} and our outer box outputs LOOPS!\loops{\text{LOOPS!}}.
Since the Blueprint Builder\builder{\text{Blueprint Builder}} only edits text and always finishes in finite time, a working Print$Checker\assumed{\text{Print\$Checker}} would give a working HaltChecker\built{\text{HaltChecker}}; because HaltChecker\built{\text{HaltChecker}} cannot exist, Print$Checker\assumed{\text{Print\$Checker}} cannot exist.
(b) A reduction must prove the conditional Print$Checker exists\assumed{\text{Print\$Checker}}\text{ exists}   ⟹  \implies HaltChecker exists\built{\text{HaltChecker}}\text{ exists}, whose contrapositive proves Print$Checker\assumed{\text{Print\$Checker}} cannot exist. Assuming HaltChecker\assumed{\text{HaltChecker}} exists and trying to build Print$Checker\built{\text{Print\$Checker}} out of it argues the converse (HaltChecker exists\assumed{\text{HaltChecker}}\text{ exists}   ⟹  \implies Print$Checker exists\built{\text{Print\$Checker}}\text{ exists}), which is vacuous because HaltChecker\assumed{\text{HaltChecker}} does not exist (and fails anyway because a machine M′M' that loops forever could still write $\$ before entering its loop).