4.6.18 · D3Theory of Computation

Worked examples — Halting problem — undecidability proof by diagonalization

2,130 words10 min readBack to topic

This page is the exhaustive drill room for the Halting Problem — Undecidability by Diagonalization. The parent proved one result: no total program decides . Here we walk every kind of situation that idea can appear in — the self-referential core, the "just simulate it" trap, degenerate programs, reductions, and exam twists — so you never meet a case you haven't already seen.

Before we start, three plain-word reminders (every symbol earned):

We write for "the pair (program , input ) packaged as one string," and . Prerequisites live at Turing Machines, Decidable vs Recognizable Languages, and Cantor's Diagonal Argument.


The scenario matrix

Every halting-problem situation you can be asked about falls into one of these cells. The examples below hit all of them.

Cell Scenario class What makes it tricky Example
C1 Concrete program that obviously halts Shows "some" cases are trivially decidable Ex 1
C2 Concrete program that obviously loops Same, opposite sign Ex 1
C3 "Just simulate and watch" attempt Fails only in the loop case → semi-decidable Ex 2
C4 The self-referential diagonal Both branches contradict Ex 3
C5 Degenerate decider: always says HALT A "trivial" is wrong on a looper Ex 4
C6 Degenerate decider: always says LOOP Wrong on a halter Ex 4
C7 Reduction: empty-input halting Transfers undecidability Ex 5
C8 Reduction: does ever print 7? Rice-flavoured property Ex 6
C9 Word problem (real-world "will it end?") Translating English → Ex 7
C10 Exam twist: "recognizable but not decidable?" Sign of asymmetry between YES and NO Ex 8

Worked examples


Recall Quick self-test across the matrix

Which cell: "H that outputs HALT for everything"? ::: C5 — a degenerate always-YES decider, wrong on any looper. Why is "simulate and report" not a decider? ::: C3 — on a looping input the simulation never halts, so it never outputs LOOP. What does building (hardcode , ignore input) achieve? ::: C7 — reduces to empty-input halting, transferring undecidability. Is recognizable? ::: C10 — yes; the simulator accepts all halting instances, so recognizable but not decidable. In , which cell of the program×input table does flip? ::: C4 — the diagonal cell (D, D), forcing .