Decidability — Undecidable Problems, Halting Problem
698 words
3 min read
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
# Decidability — Undecidable Problems, Halting Problem ## 🎯 Learning Objectives - Define decidable and undecidable languages - Prove the halting problem is undecidable - Reduce known undecidable problems to prove new ones - Understand Rice's theorem * * * ## 1. Decidable vs Undecidable ### 1.1 Intuition A problem i...

Decidability — Undecidable Problems, Halting Problem
🎯 Learning Objectives
- Define decidable and undecidable languages
- Prove the halting problem is undecidable
- Reduce known undecidable problems to prove new ones
- Understand Rice's theorem
1. Decidable vs Undecidable
1.1 Intuition
A problem is decidable if there exists a Turing machine (algorithm) that always gives the correct yes/no answer. A problem is undecidable if no such TM exists — no matter how clever we are, there is no algorithm that always works.
1.2 Key Examples
| Problem | Status | Reason |
|---|---|---|
| DFA acceptance (given DFA M and string w, does M accept w?) | Decidable | Simulate M on w |
| CFG emptiness (does CFG generate any string?) | Decidable | Check reachable non-terminals |
| TM acceptance (given TM M and string w, does M accept w?) | Undecidable | Halting problem |
| TM halting (does TM M halt on w?) | Undecidable | Classic problem |
| Equivalence of CFGs | Undecidable | Rice's theorem |
2. The Halting Problem
2.1 Statement
HALTTM={⟨M,w⟩∣M is a TM and M halts on input w}Theorem: HALTTM is undecidable.
2.2 Proof by Contradiction
Assume HALTTM is decidable. Then there exists a TM H that decides it:
Construct a new TM D that uses H as a subroutine:
pythondef D(M): if H(M, M) == "accept": # If M halts on input M... loop_forever() # ...then D loops forever else: # If M loops on input M... return "accept" # ...then D halts
Now run D on input ⟨D⟩:
- If D halts on ⟨D⟩, then H(D,D) says "accept" → D loops forever (contradiction)
- If D loops on ⟨D⟩, then H(D,D) says "reject" → D halts (contradiction) Neither case is possible → our assumption that H exists is false → HALTTM is undecidable.
3. Rice's Theorem
Theorem: Any non-trivial property of TM languages is undecidable.
A property is:
- Non-trivial: Some TMs have it, some don't
- About the language, not the machine itself Examples of undecidable properties:
- Does a TM accept any string? (Emptiness)
- Does a TM accept all strings? (Universality)
- Does a TM accept a finite language?
4. 📝 Practice Questions
Q1: What is the halting problem?Answer: The halting problem asks: given a Turing machine M and input w, does M halt on w? It's undecidable — no algorithm can determine this for all TMs. This was proven by Alan Turing in 1936 and is the foundational undecidable problem. Q2: Prove that the emptiness problem for TMs is undecidable.Answer: Reduce from halting problem. Given (M, w), construct M' that: (1) ignores its input, (2) simulates M on w, (3) accepts if M halts. Then M' accepts some input (any input) iff M halts on w. If we could decide emptiness of M', we could decide halting. Contradiction. Q3: What does Rice's theorem state?Answer: Rice's theorem states that any non-trivial property of the language of a Turing machine is undecidable. "Non-trivial" means there exists at least one TM with the property and at least one without it. This means almost all interesting questions about program behavior are undecidable. Q4: Is the problem "Does a TM accept any even-length string?" decidable?Answer: No. This is a non-trivial property of the language (some TMs accept even-length strings, some don't). By Rice's theorem, it's undecidable. Q5: What is the difference between undecidable and non-computable?Answer: These terms are equivalent for decision problems. An undecidable problem has no algorithm that always answers yes/no correctly. Undecidable is the standard term in recursion theory and automata theory; non-computable is more general (includes non-decision problems).
5. 🔗 Cross-References
- Week 9 - Reductions: Using reductions to prove undecidability
- Week 6 - Turing Machines: Model of computation for undecidability
- BSCS3021 - Week 12 - NP-Completeness: Decidability vs complexity Join Discord PreviousTM VariantsNextReductions