Universal Turing Machines
& Undecidability

CS305 — Formal Language Theory

Use ← → arrows to navigate • Press S for step-through reveals

The Big Picture

We've climbed the Chomsky hierarchy. Now we hit the ceiling.

The Chomsky Hierarchy of Power: Regular → Context-Free → Context-Sensitive → RE (DFA) (PDA) (LBA) (TM) | | | | v v v v Least More Even more MOST POWERFUL powerful powerful powerful machine possible | v But is it ALL-powerful? Can it solve EVERYTHING?

Key Question

Turing machines are the most powerful computational model we know. But are there problems that even TMs cannot solve? The shocking answer is yes — and most problems are unsolvable.

Where We're Going

  1. Encoding TMs as strings — programs are data
  2. The Universal TM — one machine to rule them all
  3. Diagonalization — more problems than programs
  4. The Halting Problem — a specific unsolvable problem
  5. Reductions — spreading undecidability
  6. Rice's Theorem — the nuclear option
  7. The language hierarchy — Decidable vs RE vs co-RE

Analogy

Think of it like exploring a mountain range. We've been climbing higher (more powerful machines). Now we discover there's a hard ceiling — a boundary even infinite time and memory can't cross.

Encoding Turing Machines as Strings

Any TM can be written as a finite binary string ⟨M⟩.

The Idea

A Turing machine M is defined by finite components:

  • States: q0, q1, ..., qn
  • Tape alphabet: 0, 1, B
  • Transitions: (state, symbol) → (state, symbol, direction)
  • Start, accept, reject states

All of this is finite, so we can encode it as a binary string ⟨M⟩.

Analogy

A Python program is just a text file — a string of characters. Similarly, a Turing machine is just a string of bits. Programs are data. This is the insight that changes everything.

Click Step to walk through encoding

The Universal Turing Machine

One machine to simulate them all.

Watch the UTM process an input

Key Idea

The UTM U takes two inputs: the code of a TM ⟨M⟩ and an input string w. It simulates M running on w. Whatever M would do, U does the same. It is a universal simulator.

Analogy

The UTM is an interpreter. Just like Python reads a .py file and executes it, the UTM reads the encoding of a TM and executes it. Or think of it as an emulator — like running a Game Boy game on your PC.

How the UTM Simulates

Three-tape simulation, step by step.

Step 0 / 4
Ready to simulate M on "011"

Simulation Loop

  1. Read current state from Tape 3
  2. Read current symbol from Tape 1 (at head)
  3. Look up (state, symbol) in Tape 2
  4. Write new symbol, move head, update state
  5. If accept/reject, halt. Otherwise repeat.

Important Detail

The UTM uses 3 tapes for clarity, but any multi-tape TM can be converted to single-tape. A UTM can be a single-tape machine — just slower.

Key Idea

The UTM is itself a TM with a finite number of states. The "program" it runs is on its tape, not in its states.

Diagonalization: The Counting Argument

There are more problems than programs. We prove this by constructing a language no TM can handle.

Step 1: Build the Table

List all TMs down the rows (M1, M2, ...) and all strings across the columns (w1, w2, ...).

Each cell says whether Mi accepts (A) or rejects (R) string wj.

Why a Table?

If we could list every TM, then every possible language is a row in this table. The question is: does every row correspond to some TM?

Click Random Fill to populate the table →

The Language Ld

A specific language that NO Turing machine can recognize. Not even RE.

Ld = { wi | Mi does NOT accept wi }

The "diagonal" language: wi is in Ld exactly when the i-th TM rejects or loops on wi

Step 1 / 4

What This Means

Ld is not just undecidable — it's not even recognizable (RE). No TM of any kind can recognize it, even one allowed to loop forever on non-members. This is strictly worse than the Halting Problem.

The Halting Problem

The most famous undecidable problem in computer science.

Definition

HALT = { ⟨M, w⟩ | M is a TM and M halts on input w }
Given a program and an input, does the program eventually stop?

Theorem: HALT is Undecidable

There is no TM that can correctly decide, for every ⟨M, w⟩, whether M halts on w. We prove this by contradiction.

Analogy: The Barber Paradox

"A barber shaves everyone who doesn't shave themselves." Who shaves the barber? The proof uses the same trick: self-reference + negation = paradox.

If HALT Were Decidable...

We could solve problems no one has been able to solve:

  • Build a perfect debugger that tells you if your code will crash
  • Verify that any program terminates (no infinite loops, ever)
  • Build a perfect virus scanner that detects all malicious code
  • Settle Goldbach's Conjecture and other open math problems

What is Goldbach's Conjecture?

"Every even number > 2 is the sum of two primes."
(e.g., 4=2+2, 6=3+3, 8=3+5, 28=11+17)
Unproven since 1742! But if HALT were decidable, we could write a program that searches for a counterexample, then use H to check if it halts. If it halts → conjecture is false. If it loops → conjecture is true. Instant answer to a 280-year-old mystery.

Proof: HALT is Undecidable

We build a paradox machine that breaks any assumed halting decider.

Step 1 / 5

The Conclusion

No TM H can decide the Halting Problem. This is a fundamental mathematical impossibility, not a limitation of current technology. No faster computer, better algorithm, or AI will ever solve it.

Halting Proof: The Full Paradox

What happens when we feed D its own encoding?

D(⟨D⟩): 1. Run H(⟨D, ⟨D⟩⟩) 2. If H says "accept": D loops forever 3. If H says "reject": D halts and accepts

The Two Cases

The Conclusion

No TM H can decide the Halting Problem. This is a fundamental mathematical impossibility, not a limitation of current technology.

The Language Hierarchy

Where do Ld and HALT fit? Let's formalize the three classes we've seen.

Decidable (Recursive)

A TM always halts with the correct YES or NO.

Machine: Decider

Examples:
{anbncn}, primes, {connected graphs}

RE (Recognizable)

A TM accepts strings in L, but may loop forever on strings not in L.

Machine: Recognizer

Examples:
HALT, ATM

Not RE

No TM at all — not even one that loops. Completely unrecognizable.

Machine: None exists

Examples:
Ld, complement of HALT

Key Theorem

L is decidable if and only if both L and its complement L are RE.
Decidable = RE ∩ co-RE

Strict Containment

Decidable ⊊ RE ⊊ All Languages.
Each level is strictly larger. Most languages are not even RE.

Reducibility

How to prove new problems undecidable without building a new paradox each time.

The Core Idea

"If you could solve Problem B, you could use that solution to also solve Problem A."

If A is undecidable, then B must be undecidable too — otherwise we'd have a way to solve A.

5-Step Proof Pattern

  1. Goal: Prove B is undecidable
  2. Assume (for contradiction) B has a decider DB
  3. Build a new TM that uses DB to decide HALT
  4. But HALT is undecidable — contradiction!
  5. Conclude: DB cannot exist → B is undecidable

Analogy

Imagine you can't solve a maze (Problem A). Someone claims they can solve a different puzzle (Problem B). You show: "If I could solve your puzzle, I could use it to solve my maze." Since your maze is unsolvable, their puzzle must be unsolvable too.

Direction Matters!

We reduce FROM the known-hard problem TO the new one. Reducing HALT → B means "HALT is no harder than B" — so B is at least as hard as HALT.

More Undecidable Problems

Undecidability spreads through reductions.

Reduction Example: ETM

ETM = { ⟨M⟩ | L(M) = ∅ } — Is the language empty?

  1. Assume decider R for ETM
  2. Given ⟨M, w⟩, build M' that ignores its input, runs M on w, accepts if M does
  3. If M accepts w: L(M') = Σ* (not empty)
  4. If M doesn't accept w: L(M') = ∅ (empty)
  5. R(⟨M'⟩) decides whether M accepts w — that's the Halting Problem!

Other Undecidable Problems

ProblemQuestionIn plain English
ETMIs L(M) = ∅?Does M reject everything? (never accepts any string)
EQTMIs L(M1) = L(M2)?Do two TMs accept exactly the same strings?
ALLTMIs L(M) = Σ*?Does M accept everything? (never rejects)
REGTMIs L(M) regular?Could a simple DFA do M's job?

Rice's Theorem (Preview)

Any non-trivial property of the language of a TM is undecidable. "Is L(M) finite?", "Is L(M) context-free?", etc. — all undecidable!

Step 0 / 6
E_TM reduction step-through

Challenge: Is It Decidable?

For each problem, decide: Decidable, RE (but not decidable), or Neither?

Classify These Problems

Rice's Theorem

The nuclear weapon of undecidability results.

Rice's Theorem (1953)

Every non-trivial property of the language recognized by a Turing machine is undecidable.

What does "non-trivial" mean?

  • At least one TM has a language satisfying P
  • At least one TM has a language NOT satisfying P

Not always-true or always-false.

What does "property of L(M)" mean?

Depends only on what M computes, not how it computes.

Rice's Theorem Quick Checker

Is L(M) empty?
Is L(M) finite?
Does M have 5 states?
Is L(M) = {0n1n}?
Does M ever move left?
Is L(M) context-free?

Analogy

"You can never determine ANY interesting fact about what a program outputs, just by looking at the program." You can ask about the code's structure (how many lines? what variables?), but not its behavior.

Decidable vs RE vs co-RE

Not all unsolvable problems are equally unsolvable.

anbn All CFLs HALT Compl(HALT) Ld {ww} ETM EQTM
Click a language to place it in the hierarchy

Key Insight

A language is decidable iff it is both RE and co-RE. The decidable languages sit at the intersection.

ClassDescriptionExample
DecidableTM always haltsanbn
RE (not dec.)TM halts on "yes", may loop on "no"HALT
co-RE (not dec.)TM halts on "no", may loop on "yes"Compl(HALT)
NeitherNot RE, not co-RELd, EQTM

Key Theorem

L is decidable ⇔ L is RE AND co-RE. If HALT's complement were RE, then HALT would be decidable. But it's not.

Challenge: Fix the Reduction

The reduction below has a mistake. Can you find it?

Broken Proof: "HALT is decidable"

"Proof" that HALT is decidable: 1. Given ⟨M, w⟩, simulate M on w. 2. If M halts, output "yes". 3. If M doesn't halt, output "no". Therefore HALT is decidable.

What's wrong? Select the error:

The Chomsky Hierarchy Complete

The full picture of computational power.

TypeLanguageRecognizerClosure
3RegularDFA/NFA∪ ∩ * comp
2Context-FreePDA∪ * (not ∩)
1Context-SensitiveLBA∪ ∩ comp
0RETM∪ ∩ (not comp)
Not RENone

Key Insight

Each level strictly contains the one below it. The jump from decidable to undecidable is not about "not enough power" — it's a provable impossibility that no amount of computation can overcome.

What Undecidability Means

It's not that we haven't found the right algorithm yet. It's that no algorithm can possibly exist. This is proven mathematically, not just observed empirically.

Practical Implications of Undecidability

What we can NEVER build, no matter how smart we get.

Impossible Programs

  • Perfect Debugger: No tool can detect all infinite loops
  • Perfect Virus Scanner: Cannot determine if arbitrary code is malicious
  • Perfect Optimizer: Cannot determine if two programs compute the same function
  • Perfect Verifier: Cannot determine if a program meets an arbitrary spec
  • Perfect Type Checker: Cannot catch all type errors in a sufficiently expressive language
Real-world impact: Compiler: "Will this loop terminate?" Answer: "Undecidable." Antivirus: "Is this program malicious?" Answer: "Undecidable in general." Verifier: "Does this code match spec?" Answer: "Undecidable in general."

But We Still Write Debuggers!

We can't solve these in general, but CAN solve them for specific cases. Real tools use heuristics, approximations, and restricted inputs. They work most of the time but can never be perfect.

Turing-Complete Systems

Anything as powerful as a TM inherits all the same limitations.

Surprisingly Turing-Complete

SystemTuring-Complete?
Python, Java, C++Yes
HTML + CSSYes (with user interaction)
Conway's Game of LifeYes
Magic: The GatheringYes
PowerPointYes (with animations)
Regular ExpressionsNo (just regular langs)
SQL (basic)No (relational algebra)

Church-Turing Thesis

Any "reasonable" model of computation is equivalent in power to a Turing machine. No physical device can compute more than a TM.

Implication

Every Turing-complete system has the same ceiling. No programming language, no matter how advanced, can solve the Halting Problem. Quantum computers can't either — they're faster, but not more powerful in terms of what's computable.

Open Questions & Connections

Where undecidability meets the rest of computer science.

Connections to Other Fields

  • P vs NP: Even among decidable problems, some may be intractable. Undecidability is the "hardest" layer above this.
  • Logic: Gödel's Incompleteness Theorem (1931) is the logical analogue. Some true statements can't be proven.
  • AI: Can AI "solve" undecidable problems? No — AI runs on Turing-complete hardware. But AI can use heuristics effectively.

The Hierarchy of Difficulty

Easy Hard Impossible |---------|---------| O(n) NP-hard Undecidable O(n log n) Not even RE Polynomial

Open Questions

  • Is there a natural problem that is RE but not decidable, other than HALT variants?
  • How fine-grained is the undecidability hierarchy? (Turing degrees)
  • Are there "levels of unsolvability" beyond RE?

What About Hypercomputation?

Some theorists propose machines more powerful than TMs (oracle machines, infinite time TMs). These are mathematical abstractions — no physical device is known to exceed TM power.

Challenge: Classify the Language

Use Rice's Theorem or reduction arguments to classify each language.

Quick Classification

Summary & Cheat Sheet

Everything you need to know, on one slide.

Big Results

ConceptKey Point
TM EncodingEvery TM is a finite binary string
UTMOne TM simulates all others (= interpreter)
CountingCountable TMs vs uncountable languages
LdDiagonal language, not even RE
HALTRE but not decidable
ReductionsProve B undecidable via A ≤ B
Rice's ThmAll non-trivial props of L(M) undecidable

The Halting Proof in 4 Lines

1. Assume decider H for HALT exists
2. Build D: run H(⟨M,⟨M⟩⟩); do opposite
3. Run D(⟨D⟩): contradiction either way
4. Therefore H cannot exist

PROOF STRATEGY CHEAT SHEET: To prove L is undecidable: +---------------------------------+ | 1. "Assume L is decidable" | | 2. Show how to reduce HALT to L | | 3. "But HALT is undecidable!" | | 4. "Contradiction. QED." | +---------------------------------+ Or just use Rice's Theorem: +---------------------------------+ | 1. Is it a property of L(M)? | | 2. Is it non-trivial? | | 3. If both YES: UNDECIDABLE. | +---------------------------------+

Exam Tip

When asked "is X decidable?", first check: is it a non-trivial property of L(M)? If yes, cite Rice's Theorem. Only do a full reduction if Rice's doesn't apply.

Quiz 1: UTM Fundamentals

Test your understanding.

Quiz 2: Halting Problem

The key proof technique.

Quiz 3: Rice's Theorem

The nuclear option.

Congratulations!

You've completed the UTM & Undecidability enhanced slide deck. Key takeaways: (1) TMs can be encoded as strings, enabling the UTM. (2) Diagonalization proves most languages are unrecognizable. (3) The Halting Problem is undecidable via self-reference + negation. (4) Rice's Theorem generalizes undecidability to all non-trivial properties of L(M).