Discrete MathematicsLanguages, Automata and Computability6 of 6
Languages, Automata and Computability · 6

Decidable and Recognizable Languages, and P versus NP

Now that we know there is a problem no computer can ever solve (the Halting Problem), we need a way to sort any yes-or-no problem by whether a program can always answer it, only confirm the "yes" cases, or solve it fast.

1

Decision Problems as Languages and Deciders

A language is the set of all input strings for which a yes-or-no question has the answer YES, and a Decider is a program box guaranteed to stop on every input with YES or NO. Because a computer encodes numbers, maps, and code as strings of characters or 0s0\text{s} and 1s1\text{s}, answering any yes-or-no question is the same as testing whether an input string belongs to the language of that problem.

Decision Problems as Languages and Deciders
Turing machine /\text{Turing machine /}
program\text{program}
Route Boston  ⁣→ ⁣ New York?\text{Route Boston }\!\to\!\text{ New York?}
BOS\text{BOS}
NYC\text{NYC}
Is it prime?\text{Is it prime?}
9797
Syntax error?\text{Syntax error?}
print(2 + 3\texttt{print(2 + 3}

A language is Decidable when we can build a Decider box that never gets stuck in an infinite loop on any input:

Input string⏟number, map, or code⟶Decider Box⟶{stops with YES (Accept)if inside the languagestops with NO (Reject)if outside the language\displaystyle \begin{aligned} &\underbrace{\text{Input string}}_{\text{number, map, or code}} \longrightarrow \boxed{\text{Decider Box}} \\ \longrightarrow &\begin{cases} \text{stops with }\yes{\text{YES (Accept)}} \\ \quad\text{if inside the language} \\[4pt] \text{stops with }\no{\text{NO (Reject)}} \\ \quad\text{if outside the language} \end{cases} \end{aligned}

Here are the key steps for testing whether 9191 is prime.

Text solution
Set a hard ceiling on the searchBecause no divisor of 9191 can be larger than 9191 itself, the list of trial divisors is finite and the program cannot loop forever:
Trial divisors∈{2,3,4,…,90}\displaystyle \text{Trial divisors} \in \{2, 3, 4, \dots, 90\}
Test divisors in order until one divides evenly or the ceiling is reachedDividing 9191 by 2,3,4,5,6,72, 3, 4, 5, 6, \found{7} in turn hits an exact factor at 7\found{7}, so the box stops immediately and turns on the red NO light:
91\displaystyle 91 =7×13  ⟹  stops with NO (not prime)\displaystyle = \found{7} \times 13 \implies \text{stops with }\no{\text{NO (not prime)}}
2

Recognizable Languages, Dovetailing, and the Halting Problem

When a search has no upper bound, a machine can stop and light up YES the moment it finds a solution, but it may keep searching forever when no solution exists; a language with a box like this is called Recognizable (or Turing-recognizable). Let's see how an unbounded search works on x3+y3+z3=42x^3 + y^3 + z^3 = 42, how to run multiple Recognizer boxes without getting trapped in an infinite loop, and why the Halting Problem (`Stops?`) lives inside the Recognizable circle.

Recognizable Languages, Dovetailing, and the Halting Problem
x3+y3+z3=42x^3 + y^3 + z^3 = 42
Integers x,y,z ?\text{Integers } x, y, z\,?
Turing machine\text{Turing machine}
YES\htmlClass{lc-mute}{\text{YES}}
NO\htmlClass{lc-mute}{\text{NO}}
∞\htmlClass{lc-mute}{\infty}

Unlike a Decider, a Recognizer only promises to stop when the answer is YES:

Input string⟶Recognizer Box⟶{always stops with YESon a YES inputstops with NO or loops ∞on a NO input\displaystyle \begin{aligned} &\text{Input string} \longrightarrow \boxed{\text{Recognizer Box}} \\ \longrightarrow &\begin{cases} \text{always stops with }\yes{\text{YES}} \\ \quad\text{on a }\yes{\text{YES}}\text{ input} \\[4pt] \text{stops with }\no{\text{NO}}\text{ or }\loops{\text{loops }\infty} \\ \quad\text{on a }\no{\text{NO}}\text{ input} \end{cases} \end{aligned}

Running one Recognizer box to completion before starting the next can trap us in an infinite loop on the first box while a halting box waits its turn. Instead, we alternate between the boxes one tick at a time (dovetailing) so a looping box never blocks a halting one.

When Box A loops forever, waiting for it to finish traps the machine before Box B ever starts, while alternating one step at a time still reaches Box B's YES.

Using dovetailing and direct simulation, we can connect Recognizers to Deciders and place the Halting Problem (`Stops?`) on our map.

Text solution
Interleave a YES-recognizer and a NO-recognizer to build a DeciderAlternating one tick of a YES-recognizer with one tick of a NO-recognizer⏟co-recognizable\underbrace{\no{\text{NO}}\text{-recognizer}}_{\text{co-recognizable}} inside one outer box guarantees that one of the two inner boxes eventually halts on every input:
Tick 1: step 1 of YES-box,Tick 2: step 1 of NO-box,Tick 3: step 2 of YES-box,…  ⟹  Decider\displaystyle \begin{aligned} &\text{Tick } 1\text{: step } 1 \text{ of }\yes{\text{YES}}\text{-box}, \\ &\text{Tick } 2\text{: step } 1 \text{ of }\no{\text{NO}}\text{-box}, \\ &\text{Tick } 3\text{: step } 2 \text{ of }\yes{\text{YES}}\text{-box}, \dots \\ \implies &\boxed{\text{Decider}} \end{aligned}
Simulate the input program directly to recognize `Stops?`Running `Program` on `Input` inside a box stops and lights up YES the moment `Program` halts, and runs forever if `Program` loops forever:
Run Program(Input)⟶{halts at some finite step  ⟹  stop and light up YESloops forever  ⟹  simulation loops ∞(allowed on NO)\displaystyle \begin{aligned} &\text{Run }\text{Program}(\text{Input}) \longrightarrow \\ &\begin{cases} \text{halts at some finite step} \\ \quad\begin{aligned} \implies &\text{stop and light up }\yes{\text{YES}} \end{aligned} \\[4pt] \loops{\text{loops forever}} \\ \quad\begin{aligned} \implies &\text{simulation }\loops{\text{loops }\infty} \\ &\text{(allowed on }\no{\text{NO}}\text{)} \end{aligned} \end{cases} \end{aligned}
3

Proving Undecidability by Reduction Wiring

A reduction proves a new problem is Undecidable by wiring a hypothetical Decider box for the new problem inside an empty outer shell for a problem we already know is impossible (`Stops?`). Let's use this wiring to prove that `PrintsZero?` ("Given a program and an input, will that program ever print `'0'`?") is Undecidable.

Proving Undecidability by Reduction Wiring
PrintsZero? Undecidable?\text{PrintsZero? Undecidable?}
Given a program and an input,\text{Given a program and an input,}
will it ever print 0?\text{will it ever print 0?}
Stops? known impossible\text{Stops? }\htmlClass{lc-orange}{\text{known impossible}}
PrintsZero?\text{PrintsZero?}
(genie)\htmlClass{lc-blue}{\text{(genie)}}
?\htmlClass{lc-mute}{?}
YES\htmlClass{lc-mute}{\text{YES}}
NO\htmlClass{lc-mute}{\text{NO}}

If the input program prints `'0'` early on and then enters an infinite loop, leaving its printer connected would make `PrintsZero?` light up YES, a false YES for `Stops?`. Instead, we disconnect the printer during the run and reconnect it to print `"0"` only after the program halts.

The inner `PrintsZero?` box tells us whether a program halts only when the wrapper throws away everything the program prints while it runs.

Here is the three-step reduction wiring from `Stops?` to `PrintsZero?`.

Text solution
Place the known impossible problem on the outside and the new problem on the insideStart with an empty outer shell for `Stops?` and place the genie's hypothetical `PrintsZero?` Decider box inside it:
Outer shell: Stops?⏟known Undecidable⊃Inner genie box: PrintsZero?⏟testing if Decidable\displaystyle \underbrace{\text{Outer shell: }\text{Stops?}}_{\impossible{\text{known Undecidable}}} \supset \underbrace{\text{Inner }\given{\text{genie box}}\text{: }\text{PrintsZero?}}_{\text{testing if Decidable}}
Modify the input into a wrapper program that can only print `'0'` after haltingBefore feeding `Program` and `Input` into `PrintsZero?`, pass them through a modifier that disconnects the printer during the run and prints `'0'` only after `Program` finishes:
Wrapper=[run Program(Input)with output → trash;after it halts,reconnect printer andprint("0")]\displaystyle \begin{aligned} &\modifier{\text{Wrapper}} = \\ \Big[&\text{run }\text{Program}(\text{Input}) \\ &\text{with output }\to\text{ trash}; \\ &\text{after it halts,} \\ &\text{reconnect printer and} \\ &\text{print("0")}\Big] \end{aligned}
Check both outcomes to confirm the outer `Stops?` shell worksWiring the inner box's YES and NO lights straight to the outer shell builds an impossible `Stops?` Decider, proving no `PrintsZero?` Decider can exist:
Program stops on Input(YES for Stops?)  ⟹  Wrapper reaches print("0")  ⟹  PrintsZero? lights up YESProgram loops on Input(NO for Stops?)  ⟹  Wrapper stays silent forever  ⟹  PrintsZero? lights up NO\displaystyle \begin{aligned} &\text{Program stops on Input} \\ &\text{(}\yes{\text{YES}}\text{ for Stops?)} \\ \implies &\modifier{\text{Wrapper}}\text{ reaches }\text{print("0")} \\ \implies &\text{PrintsZero? lights up }\yes{\text{YES}} \\[8pt] &\text{Program }\loops{\text{loops}}\text{ on Input} \\ &\text{(}\no{\text{NO}}\text{ for Stops?)} \\ \implies &\modifier{\text{Wrapper}}\text{ stays silent forever} \\ \implies &\text{PrintsZero? lights up }\no{\text{NO}} \end{aligned}
4

Unrecognizable Languages and Loops

An Unrecognizable language lies completely outside the Recognizable circle, meaning no machine can even guarantee stopping with YES on the YES inputs. Let's test `Loops?` ("Given a `Program` and an `Input`, does `Program` run forever on `Input`?") by pairing it with the Recognizer we already built for `Stops?`.

Unrecognizable Languages and Loops
Loops?\text{Loops?}
Given a Program and an Input, does\text{Given a Program and an Input, does}
Program run forever on Input?\text{Program run forever on Input?}
Unrecognizable\textbf{Unrecognizable}
??
Recognizable\textbf{Recognizable}
Stops?\text{Stops?}
Loops?\text{Loops?}
Decidable\textbf{Decidable}

Here is how dovetailing proves that `Loops?` is Unrecognizable.

Text solution
Match a YES for `Loops?` to a NO for `Stops?`Because looping forever is the exact opposite of halting, a working YES-recognizer for `Loops?` is automatically a NO-recognizer (co-recognizer) for `Stops?`:
YES for Loops?(runs forever)  ⟺  NO for Stops?(never stops)\displaystyle \begin{aligned} &\yes{\text{YES}}\text{ for }\text{Loops?} \\ &\text{(}\loops{\text{runs forever}}\text{)} \\ \iff &\no{\text{NO}}\text{ for }\text{Stops?} \\ &\text{(}\loops{\text{never stops}}\text{)} \end{aligned}
Dovetail the two Recognizers inside an outer `Stops?` Decider shellAlternating our working YES-recognizer for `Stops?` (Box 1) with a hypothetical YES-recognizer for `Loops?` (Box 2) one tick at a time guarantees that one of the two boxes halts on every input:
AlternateBox 1(YES-recognizer for Stops?)⏟built by simulationandBox 2(YES-recognizer for Loops?)⏟hypothetical genie box  ⟹  Decider for Stops?\displaystyle \begin{aligned} &\text{Alternate} \\ &\underbrace{\begin{gathered}\text{Box 1} \\ \text{(}\yes{\text{YES}}\text{-recognizer for Stops?)}\end{gathered}}_{\text{built by simulation}} \\ &\text{and} \\ &\underbrace{\begin{gathered}\text{Box 2} \\ \text{(}\yes{\text{YES}}\text{-recognizer for Loops?)}\end{gathered}}_{\given{\text{hypothetical genie box}}} \\ &\implies \text{Decider for }\text{Stops?} \end{aligned}
Rule out Box 2 by contradictionSince a `Stops?` Decider cannot exist and Box 1 already exists, Box 2 cannot exist, placing `Loops?` outside the Recognizable circle:
Stops? is Undecidable  ⟹  no YES-recognizerfor Loops? exists\displaystyle \begin{aligned} &\text{Stops? is }\impossible{\text{Undecidable}} \\ \implies &\text{no }\yes{\text{YES}}\text{-recognizer} \\ &\text{for }\text{Loops?}\text{ exists} \end{aligned}
5

Polynomial Time, Class P, and Class NP Verifiers

Inside the Decidable circle, Class P\text{P} is the collection of problems a Decider can solve from scratch in polynomial time, O(nk)\poly{O(n^k)}, while Class NP\text{NP} is the collection of problems where a YES answer can be verified in polynomial time with the help of a short Hint (also called a Certificate or Witness). Both `Shortest Path` and `Traveling Salesperson` on an nn-city map are Decidable because the number of possible routes is finite, yet their step counts grow at completely different rates.

Polynomial Time, Class P, and Class NP Verifiers
n cities\text{n cities}
A\text{A}
B\text{B}
Problem 1 (Shortest Path)\textbf{Problem 1 (Shortest Path)}
Drive from A to B in under 500 miles?\text{Drive from A to B in under 500 miles?}
Problem 2 (Traveling Salesperson)\textbf{Problem 2 (Traveling Salesperson)}
Start at A, visit every city,\text{Start at A, visit every city,}
back to A in under 500 miles?\text{back to A in under 500 miles?}

Comparing the step counts on n=100n = 100 cities shows why polynomial time separates practical algorithms from brute-force explosions:

Shortest Path (Dijkstra’s algorithm):O(n2) steps  ⟹  1002=10,000 operations(in P)Traveling Salesperson (every ordering,or best known methods):n! steps, or about 2n steps  ⟹  2100≈1.3×1030 operations\displaystyle \begin{aligned} &\text{Shortest Path (Dijkstra's algorithm):} \\ &\quad \poly{O(n^2)} \text{ steps} \\ &\quad\begin{aligned} \implies &100^2 = \howmany{10{,}000} \text{ operations} \\ &\text{(in P)} \end{aligned} \\[8pt] &\text{Traveling Salesperson (every ordering,} \\ &\text{or best known methods):} \\ &\quad \expo{n!} \text{ steps, or about } \expo{2^n} \text{ steps} \\ &\quad\begin{aligned} \implies &\expo{2^{100} \approx 1.3 \times 10^{30}} \text{ operations} \end{aligned} \end{aligned}

A problem belongs to Class NP\text{NP} if a Verifier Box can check a proposed YES hint in polynomial time (while never being tricked into saying YES when the answer is NO):

Problem Input (size n)+Hint⏟Certificate / Witness⟶Verifier Box runs inO(nk) time⟶verifies YES\displaystyle \begin{aligned} &\text{Problem Input (size }n\text{)} \\ &+ \underbrace{\given{\text{Hint}}}_{\given{\text{Certificate / Witness}}} \\ &\longrightarrow \boxed{\begin{gathered}\text{Verifier Box runs in} \\ \poly{O(n^k)}\text{ time}\end{gathered}} \\ &\longrightarrow \yes{\text{verifies YES}} \end{aligned}

Because any problem we can solve from scratch in O(nk)\poly{O(n^k)} time can be verified in O(nk)\poly{O(n^k)} time by simply ignoring the Hint and solving the problem directly, Class P\text{P} sits completely inside Class NP\text{NP}:

Class P (solvable alone in O(nk))  ⟹  Verifier ignores Hintand solves in O(nk)  ⟹  P⊆NP\displaystyle \begin{aligned} &\text{Class P (solvable alone in }\poly{O(n^k)}\text{)} \\ \implies &\text{Verifier ignores }\given{\text{Hint}} \\ &\text{and solves in }\poly{O(n^k)} \\ \implies &\text{P} \subseteq \text{NP} \end{aligned}

Remember that NP\text{NP} stands for Nondeterministic Polynomial, never "Not Polynomial", and every problem in P\text{P} is automatically in NP\text{NP} too.

6

Reducing 3-SAT to Independent Set and NP-Completeness

The NP\text{NP}-Complete problems sit at the top edge of the NP\text{NP} circle: they live inside NP\text{NP}, and every problem in NP\text{NP} can be translated (fast-wired) into them in polynomial time. Let's build a polynomial-time reduction from `3-SAT` (making every 3-item logic clause True without contradictions) to `Independent Set` (choosing kk dots in a graph with no line between any two of them), and see how all of these language classes fit together.

Reducing 3-SAT to Independent Set and NP-Completeness
modifier\htmlClass{lc-violet}{\text{modifier}}
must run in polynomial time\htmlClass{lc-violet}{\text{must run in polynomial time}}
YES\htmlClass{lc-mute}{\text{YES}}
NO\htmlClass{lc-mute}{\text{NO}}
3-SAT\textbf{3-SAT}
x,y,z,w ⁣: T or Fx, y, z, w\!:\ \htmlClass{lc-green}{\text{T}}\text{ or }\htmlClass{lc-orange}{\text{F}}
(x∨y∨¬z)∧(¬x∨w∨z)(x \vee y \vee \neg z) \wedge (\neg x \vee w \vee z)
∧ (¬y∨¬w∨z)satisfiable?\wedge\, (\neg y \vee \neg w \vee z)\quad \text{satisfiable?}
Independent Set\textbf{Independent Set}
k dots, no line between any two?k \text{ dots, no line between any two?}

In the graph built from a kk-clause `3-SAT` formula, triangle lines keep us from picking two dots in the same clause, and conflict lines keep us from picking both a variable (like xx) and its negation (¬x\neg x). Picking one dot per triangle with no conflict lines between them corresponds directly to a True/False assignment that makes every clause True.

In the graph for a 3-SAT formula, picking one dot per triangle with no lines between them makes every clause true without any contradictions.

Here are the key steps that fast-wire an outer `3-SAT` shell into an inner `Independent Set` box.

Text solution
Turn each 3-item clause into a triangle of 3 dotsFor a `3-SAT` formula with kk clauses, draw kk triangles (3k3k dots in total) so that the triangle lines forbid picking more than 11 dot from the same clause:
k clauses of 3 items⟶k triangles (3k dots,at most 1 chosen dotper triangle)\displaystyle \begin{aligned} &k \text{ clauses of } 3 \text{ items} \\ \longrightarrow &k \text{ triangles } (3k \text{ dots,} \\ &\text{at most } \picked{1 \text{ chosen dot}} \\ &\text{per triangle}) \end{aligned}
Draw conflict lines between every variable and its negationConnect every dot labeled with a variable (like xx) to every dot labeled with its opposite (¬x\neg x) so contradictory items can never both be picked:
Add conflict lines x — ¬x,  y — ¬y,  z — ¬zin polynomial time O(nk)\displaystyle \begin{aligned} &\text{Add }\conflict{\text{conflict lines}}\text{ } \\ &x \conflict{\text{ --- }} \neg x, \; y \conflict{\text{ --- }} \neg y, \; z \conflict{\text{ --- }} \neg z \\ &\text{in polynomial time } \poly{O(n^k)} \end{aligned}
Verify both directions between the outer `3-SAT` shell and the inner `Independent Set` boxChoosing 11 True dot per clause gives kk dots with no shared triangle or conflict lines, and conversely any kk independent dots must place 11 dot in each of the kk triangles without contradictions, setting their labels to True to satisfy all kk clauses:
3-SAT formula issatisfiable (YES)  ⟺  Graph has an independentset of k dots (YES)\displaystyle \begin{aligned} &\text{3-SAT formula is} \\ &\text{satisfiable (}\yes{\text{YES}}\text{)} \\ \iff &\text{Graph has an independent} \\ &\text{set of } k \text{ dots (}\yes{\text{YES}}\text{)} \end{aligned}

This map brings together every language class from the outside in.

Unrecognizable\textbf{Unrecognizable}
Loops?\text{Loops?}
Recognizable\textbf{Recognizable}
Stops?\text{Stops?}
PrintsZero?\text{PrintsZero?}
Decidable\textbf{Decidable}
NP-Complete\textbf{NP-Complete}
3-SAT\text{3-SAT}
Independent Set\text{Independent Set}
Traveling Salesperson\text{Traveling Salesperson}
NP\textbf{NP}
P\textbf{P}
Shortest Path\text{Shortest Path}
(Dijkstra)\text{(Dijkstra)}

Key concepts

Every yes-or-no question is a language (the set of all YES input strings), and where that language lives on the map comes down to how a program box behaves on its inputs and how you wire boxes together:

Decidable vs. Recognizable (look for a hard ceiling on the search)

If a brute-force search has a finite upper bound (like testing divisors up to nn to check whether nn is prime), the box is guaranteed to finish and say YES or NO, making the language Decidable. Only when the search space has no upper bound (like searching all integers for x3+y3+z3=42x^3 + y^3 + z^3 = 42 or simulating `Program(Input)` in `Stops?`) does brute force give merely a Recognizer (stops with YES on a YES, may loop forever on a NO). Whenever you run multiple Recognizer boxes (or pair a YES-recognizer with a NO-recognizer to build a Decider), never run one to completion before starting the next; dovetail them one tick at a time (A1,B1,A2,B2,…\text{A}_1, \text{B}_1, \text{A}_2, \text{B}_2, \dots).

Undecidable vs. Unrecognizable (wire the known impossible problem on the outside)

To prove a new problem like `PrintsZero?` is Undecidable, place `Stops?` as the outer shell and the new problem as the inner genie box, wrapping the input program so it triggers the inner YES if and only if it halts (never put `Stops?` on the inside). To prove a problem like `Loops?` is Unrecognizable (outside the Recognizable circle entirely), notice that a YES for `Loops?` is a NO for `Stops?`: if a YES-recognizer for `Loops?` existed, dovetailing it with the YES-recognizer for `Stops?` would build an impossible `Stops?` Decider.

Class P\text{P}, Class NP\text{NP}, and NP\text{NP}-Complete (solving from scratch vs. checking a Hint in O(nk)\poly{O(n^k)} time)

Inside the Decidable circle, a problem is in P\text{P} if a Decider solves it from scratch in polynomial time O(nk)\poly{O(n^k)} (like Dijkstra's O(n2)\poly{O(n^2)} `Shortest Path`), and in NP\text{NP} if a Verifier Box checks a YES Hint in O(nk)\poly{O(n^k)} time (so P⊆NP\text{P} \subseteq \text{NP} automatically). To prove a problem is NP\text{NP}-Complete, verify that it is in NP\text{NP} and fast-wire a known NP\text{NP}-Complete problem like `3-SAT` as the outer shell into your new problem on the inside using an O(nk)\poly{O(n^k)} modifier, checking both directions (YES  ⟺  YES\yes{\text{YES}} \iff \yes{\text{YES}}). If any one NP\text{NP}-Complete problem gets a polynomial-time algorithm, all of NP\text{NP} collapses into P\text{P} (P=NP\text{P} = \text{NP}), while Undecidable problems like `Stops?` stay Undecidable.

7

Practice

1

Explain why every yes-or-no question can be viewed as a language, and compare the following two problems:

Count how many triples (x,y,z)(x, y, z) exist when each variable is between −n-n and nn: does that search have a hard ceiling where the box can stop and light up NO?

Any input (a number, a map, or a program) is encoded as a string of characters or 0s0\text{s} and 1s1\text{s}, and the language of a yes-or-no problem is the set of all input strings for which the answer is YES.
Problem (A) is Decidable because the search space is finite: between −n-n and nn there are (2n+1)(2n + 1) choices for each variable, giving (2n+1)3\howmany{(2n + 1)^3} triples (x,y,z)(x, y, z) in total. (Watch out: don't count 2n2n choices per variable and get 8n38n^3 by forgetting 00, and don't claim Problem (B) can also stop at ±n\pm n, because solutions to x3+y3+z3=nx^3 + y^3 + z^3 = n can require numbers much larger in size than nn.) That finite count gives a hard ceiling where the machine is guaranteed to finish checking every triple and stop with YES if one works or NO if none do.
Problem (B) has no upper bound on how large x,y,x, y, and zz might be: spiraling outward through all triples of integers is guaranteed to stop and light up YES if a solution exists, which proves (B) is Recognizable, but when the answer is NO the search never reaches a point where it can rule out larger numbers and stop with NO.
2

Suppose you have a working Recognizer box RR for a Recognizable language LL. You want to build a new Recognizer box that takes three inputs A,B,A, B, and CC and lights up YES if at least one of A,B,A, B, or CC is in LL. Explain why running RR on AA until it finishes, then on BB, then on CC fails, and give the exact schedule that fixes it.

What happens to BB and CC if AA is a NO input that makes RR loop forever? How can you share clock ticks across all three inputs?

Because RR is only a Recognizer, it is allowed to loop forever on a NO input. If AA is a NO input that makes RR loop forever and CC is a YES input, running AA to completion first traps the machine in AA's infinite loop so it never reaches BB or CC and fails to light up YES.
To fix this, dovetail (interleave) the three runs step by step: run step 11 of RR on AA, then step 11 of RR on BB, then step 11 of RR on CC, then step 22 on AA, step 22 on BB, step 22 on CC, and so on, stopping and lighting up YES the moment any of the three runs lights up YES. (Watch out: don't dovetail AA and BB first and wait for them to finish before starting CC, because if both AA and BB loop forever while CC is a YES input, a two-way alternation never starts CC.) Even if two of the inputs loop forever, the third still advances every third tick and reaches its YES in a finite number of steps.
3

Consider the problem `PrintsDone?`: "Given a `Program` and an `Input`, will `Program` ever print the string `'DONE'` when run on `Input`?" (a) A student attempts to prove `PrintsDone?` is undecidable by placing a `Stops?` Decider box inside an outer `PrintsDone?` shell. Why does this direction prove nothing? (b) Prove that `PrintsDone?` is Undecidable using a reduction from `Stops?`: state which box is the outer shell and which is the inner genie box, describe the wrapper program, and verify both cases (when `Program` stops on `Input` and when `Program` loops forever on `Input`).

Which problem do we already know is impossible to build (`Stops?` or `PrintsDone?`), and how do you prevent `Program` from printing `'DONE'` on its own before it halts?

(a) Putting `Stops?` on the inside only shows "If I had an impossible `Stops?` Decider, I could build a `PrintsDone?` Decider," which proves nothing about whether `PrintsDone?` can exist. The known impossible problem (`Stops?`) must always be the outer shell, and the new problem (`PrintsDone?`) must be the inner genie box.
(b) Place an empty `Stops?` Decider shell on the outside and put a hypothetical `PrintsDone?` Decider box on the inside. Given `Program` and `Input` entering the outer `Stops?` shell, pass them through a modifier that builds a wrapper program: the wrapper runs `Program` on `Input` with its printer disconnected (redirecting all output to the trash), and only after `Program` halts does the wrapper reconnect the printer and execute `print("DONE")`. (Watch out: don't try to simply delete `print("DONE")` lines from the source code of `Program`, because a looping program can compute and print the letters `'D'`, `'O'`, `'N'`, `'E'` in other ways unless its printer is disconnected during the run.) Feed this wrapper into the inner `PrintsDone?` box and wire its YES and NO lights directly to the outer YES and NO lights.
Case 1If `Program` stops on `Input` (YES for `Stops?`), the wrapper finishes running `Program`, reconnects the printer, and prints `"DONE"`, so `PrintsDone?` lights up YES.
Case 2If `Program` loops forever on `Input` (NO for `Stops?`), the wrapper stays stuck running `Program` with the printer disconnected and never prints `"DONE"`, so `PrintsDone?` lights up NO.
Because this wiring would build an impossible `Stops?` Decider, no `PrintsDone?` Decider can exist.
4

Consider the problem `NeverPrintsZero?`: "Given a `Program` and an `Input`, is it true that `Program` never prints `'0'` at any point during its run on `Input`?" Given that `PrintsZero?` is undecidable, first explain why `PrintsZero?` is Recognizable, and then prove that `NeverPrintsZero?` is Unrecognizable (lives completely outside the Recognizable circle).

A YES for `NeverPrintsZero?` is what outcome for `PrintsZero?`? Recall what happens when you dovetail a YES-recognizer and a NO-recognizer for the same undecidable problem.

`PrintsZero?` is Recognizable because we can build a box that simulates `Program` on `Input` step by step and watches its output: if `Program` ever prints `'0'`, it does so at some finite step, at which moment our box stops and lights up YES (and if `Program` never prints `'0'`, our box either halts without lighting up YES or loops forever, which is allowed for a Recognizer). (Watch out: don't claim `NeverPrintsZero?` is also Recognizable by "running `Program` until it stops and checking that no `'0'` appeared", because when `Program` loops forever without printing `'0'`, the answer to `NeverPrintsZero?` is YES, yet the simulation runs forever and never lights up YES.)
Now suppose for contradiction that a genie hands us a YES-recognizer for `NeverPrintsZero?`. Because a YES for `NeverPrintsZero?` is the exact same thing as a NO for `PrintsZero?`, the genie's box is a NO-recognizer (co-recognizer) for `PrintsZero?`. We can place both our YES-recognizer for `PrintsZero?` and the genie's YES-recognizer for `NeverPrintsZero?` inside an outer `PrintsZero?` Decider shell and alternate them one step at a time (dovetailing). On every input `(Program, Input)`, `Program` either eventually prints `'0'` or never prints `'0'`, so one of the two inner boxes is guaranteed to stop and light up YES, letting the outer shell stop and light up YES or NO accordingly. That would give a full Decider for `PrintsZero?`, contradicting that `PrintsZero?` is undecidable; therefore no Recognizer for `NeverPrintsZero?` can exist.
5

Apply the polynomial-time reduction from `3-SAT` to `Independent Set` to the 33-clause formula (x OR y OR ¬z) AND (¬x OR ¬y OR z) AND (x OR ¬y OR ¬z)(x \text{ OR } y \text{ OR } \neg z) \text{ AND } (\neg x \text{ OR } \neg y \text{ OR } z) \text{ AND } (x \text{ OR } \neg y \text{ OR } \neg z). (a) How many dots (vertices), how many triangle lines, and how many conflict lines does the constructed graph have, and what target number kk of dots is passed to the `Independent Set` box? (b) Using the satisfying assignment x=Truex = \truth{\text{True}}, y=Falsey = \falsity{\text{False}}, z=Falsez = \falsity{\text{False}}, pick a valid set of kk dots (one from each clause triangle) and explain why no two chosen dots share a triangle line or a conflict line.

Each of the k=3k = 3 clauses forms a triangle of 33 dots. For the conflict lines, count how many dots are labeled with each variable (x,y,zx, y, z) and multiply by how many dots are labeled with its negation (¬x,¬y,¬z\neg x, \neg y, \neg z).

(a) With k=3k = 3 clauses, the graph has 3k=93k = \howmany{9} dots arranged in 33 triangles. Each triangle has 33 lines, giving 3×3=93 \times 3 = \howmany{9} triangle lines. For the conflict lines:
xx (in clauses 1 and 3, so 22 dots) connects to ¬x\neg x (in clause 2, so 11 dot) for 2×1=22 \times 1 = 2 lines;
yy (in clause 1, so 11 dot) connects to ¬y\neg y (in clauses 2 and 3, so 22 dots) for 1×2=21 \times 2 = 2 lines;
zz (in clause 2, so 11 dot) connects to ¬z\neg z (in clauses 1 and 3, so 22 dots) for 1×2=21 \times 2 = 2 lines.
(Watch out: don't count just 11 conflict line per variable to get 33 conflict lines and 1212 total lines, because every occurrence of a variable must connect to every occurrence of its negation.) Adding these gives 2+2+2=62 + 2 + 2 = \howmany{6} conflict lines (15\howmany{15} lines in total), and the target passed to `Independent Set` is k=3k = 3 dots.
(b) Under x=Truex = \truth{\text{True}}, y=Falsey = \falsity{\text{False}}, z=Falsez = \falsity{\text{False}}, the literals that evaluate to True are x,¬y,\truth{x}, \truth{\neg y}, and ¬z\truth{\neg z}. (Watch out: don't pick yy from Triangle 1 or zz from Triangle 2, which evaluate to False under this assignment and would share a conflict line with ¬y\truth{\neg y} or ¬z\truth{\neg z}.) We can pick x\truth{x} from Triangle 1 (where x\truth{x} and ¬z\truth{\neg z} are True), ¬y\truth{\neg y} from Triangle 2 (where only ¬y\truth{\neg y} is True), and ¬z\truth{\neg z} (or x\truth{x} or ¬y\truth{\neg y}) from Triangle 3 (where all three are True). These 33 dots share no triangle lines because we picked 11 dot from each triangle, and they share no conflict lines because all three chosen labels (x,¬y,¬z\truth{x}, \truth{\neg y}, \truth{\neg z}) are simultaneously True under a single assignment, so no variable and its negation are both picked.
6

Suppose you want to prove that a new decision problem, `TeamSchedule?`, is NP\text{NP}-Complete using the known NP\text{NP}-Complete problem `3-SAT`. (a) State the two conditions you must prove, including for the reduction which problem is the outer shell, which is the inner helper box, what speed requirement the modifier must meet, and both logical directions you must verify. (b) If someone later discovers an O(n3)\poly{O(n^3)} algorithm that solves `TeamSchedule?` from scratch, what happens to the complexity or decidability of `3-SAT`, `Traveling Salesperson`, and the Halting Problem (`Stops?`)?

Check both parts of the definition of NP\text{NP}-Complete (NP\text{NP} membership and NP\text{NP}-Hardness). Which box must go on the outside so that a fast box for `TeamSchedule?` solves `3-SAT`?

(a) First, prove `TeamSchedule?` is in NP\text{NP} by building a Verifier Box that takes a problem input and a short Hint (Certificate/Witness) and checks whether the hint is valid in polynomial time, O(nk)\poly{O(n^k)}, such that a valid hint exists if and only if the answer is YES. Second, prove `TeamSchedule?` is NP\text{NP}-Hard by wiring `3-SAT` as the outer shell around a hypothetical `TeamSchedule?` box as the inner helper box, using a modifier that translates any `3-SAT` formula into a `TeamSchedule?` input in polynomial time, O(nk)\poly{O(n^k)}, and verifying both directions: (1) if the `3-SAT` formula is satisfiable (YES), then the translated `TeamSchedule?` input is a YES, and (2) if the translated `TeamSchedule?` input is a YES, then the `3-SAT` formula is satisfiable (YES). (Watch out: don't put `TeamSchedule?` on the outside and `3-SAT` on the inside, because that direction only shows `TeamSchedule?` can be solved using `3-SAT`, not that `TeamSchedule?` is at least as hard as `3-SAT`.)
(b) Because `3-SAT` (and every problem in NP\text{NP}) fast-wires into `TeamSchedule?` in polynomial time, an O(n3)\poly{O(n^3)} algorithm for `TeamSchedule?` immediately gives a polynomial-time algorithm for `3-SAT`, `Traveling Salesperson`, and every other problem in NP\text{NP}, collapsing the entire NP\text{NP} circle into P\text{P} (so P=NP\text{P} = \text{NP}). (Watch out: don't say that P=NP\text{P} = \text{NP} makes `Stops?` solvable too, because the Halting Problem lies outside the Decidable circle altogether, so it remains Undecidable.)