← Student tools · Problem 2 · Lecture 5 · Round 1 (30 pts)

The universal Turing machine

One TM that simulates every other TM — the reason ATM is Turing-recognizable.

CLO-1 · Diagonalization (recognizable side) Round 1 · 30 pts Lecture 5
🔊 Listen

A universal Turing machine is the theoretical ancestor of every general-purpose computer you have ever used. It says: one fixed program can run any other program. Your laptop's CPU is a (fast, finite-memory) universal machine; an interpreter like Python is a universal machine written in software; even a browser running JavaScript is yet another universal machine on top.

The mathematical version was given by Turing in 1936 — a decade before the first stored-program computer was built. It is the single most important idea connecting computability theory to real machines.

The big consequence we care about today

Because a universal TM exists, the language ATM = {⟨M, w⟩ : M accepts w} is Turing-recognizable. Combined with Problem 3 (ATM is not decidable), this gives the cleanest example of the gap between "recognize" and "decide" — the gap on which all of undecidability rests.

Chain of consequences: Universal TM exists ⇒ ATM is recognizable ⇒ recognizable ≠ decidable ⇒ a recognizable language whose complement is also recognizable must be decidable ⇒ co-ATM is not recognizable ⇒ a concrete non-recognizable language exists.

🔊 Listen

Recall a Turing machine M is a tuple (Q, Σ, Γ, δ, q0, qa, qr). The only infinite ingredient is the tape — everything else (states, alphabet, transitions) is a finite table.

So M can be written down as a finite string ⟨M⟩. We pick an encoding — for example, list every transition (state, read) → (state, write, dir) on one line. That string is just data.

Vocabulary refresher
  • ⟨M⟩ · the encoding of TM M as a binary (or text) string.
  • ⟨M, w⟩ · the encoded pair: M's description followed by input w, separated by a delimiter.
  • Universal TM (U) · a single fixed TM that takes ⟨M, w⟩ and behaves the same as M on w.
  • Recognizer · halts and accepts on yes-inputs. May loop on no-inputs.
  • Decider · halts on every input. Accepts yes, rejects no — always.

The job of U is to simulate. Given ⟨M, w⟩ on its tape, U keeps three regions on its (multi-track / multi-tape) working tape:

  1. Program region: the encoded transitions of M, used as a lookup table.
  2. Tape region: M's current tape contents, evolving as the simulation proceeds.
  3. State region: a small scratch area holding M's current state and head position.
🔊 Listen

The simulation loop is a fixed program — the heart of U:

  1. Read M's current state q and the symbol s under M's head (both stored on U's tape).
  2. Scan the program region for a line matching (q, s) → (q', s', d).
  3. If none found: M is stuck. U halts with whatever verdict M would give (typically reject).
  4. If found: write s' onto M's tape, update M's state to q', move M's simulated head one cell in direction d.
  5. If q' = qaccept: U accepts. If q' = qreject: U rejects.
  6. Otherwise, go back to step 1.
Theorem · ATM is Turing-recognizable

Proof. Define recognizer R = "on input ⟨M, w⟩: run U on ⟨M, w⟩; accept if U accepts; reject if U rejects." If M accepts w, then U accepts (after finitely many steps), so R accepts. If M rejects w, R rejects. If M loops on w, U loops, R loops — but R is allowed to loop on no-inputs, since R is only required to recognize.

This is the precise spot where recognizability and decidability separate. A recognizer is allowed the luxury of looping forever on rejected inputs. A decider is not. We do not yet know whether a clever decider for ATM might exist — Problem 3 will prove it cannot.

🔊 Listen
Universal TM running a small machine Auto-plays
TM description format · one transition per line:
state, symbol_read → next_state, write, L|R
_ = blank · q0 = start · qa / qr = accept / reject.

Tape

State q0
Steps 0
Verdict running…
🔊 Listen

Let's hand-trace the "accept" preset on input 0000 so the simulation is no longer mysterious. The machine M has two non-halting states: q0 ("seen even") and q1 ("seen odd").

Step Tape State Rule used
0[0]000_q0
10[0]00_q1(q0,0)→(q1,0,R)
200[0]0_q0(q1,0)→(q0,0,R)
3000[0]_q1(q0,0)→(q1,0,R)
40000[_]_q0(q1,0)→(q0,0,R)
50000_[_]qa(q0,_)→(qa,_,R)

Four 0s → even → q0 at blank → accept. The universal TM has simply walked through the table above, doing exactly the same five state changes. That is all "simulation" means.

🔊 Listen
🔊 Listen
  1. "U decides ATM." No. U recognizes it. The distinction matters because a decider must halt on every input — and on looping M, U loops.
  2. "Each M needs its own simulator." No. U is one fixed machine; ⟨M⟩ is just input data to U.
  3. Confusing M's state with U's state. U has its own (constant-size) state set; M's current state is written on U's tape as data.
  4. "Universal means efficient." No. Simulation overhead is real (polynomial in M's description, sometimes logarithmic in time). U is universal, not free.
  5. Forgetting the alphabet. M might use symbols U has never seen. The standard trick: encode all M-symbols in binary on U's tape, with a fixed delimiter.
🔊 Listen
🔊 Listen

Total time: 10 minutes.