Quiz 2

Decidability — Undecidable Problems, Halting Problem

698 words
3 min read
Python Week 1: the first filter for runtime behavior
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

ProblemStatusReason
DFA acceptance (given DFA M and string w, does M accept w?)DecidableSimulate M on w
CFG emptiness (does CFG generate any string?)DecidableCheck reachable non-terminals
TM acceptance (given TM M and string w, does M accept w?)UndecidableHalting problem
TM halting (does TM M halt on w?)UndecidableClassic problem
Equivalence of CFGsUndecidableRice's theorem

2. The Halting Problem

2.1 Statement

HALTTM={M,wM is a TM and M halts on input w}HALT_{TM} = \{\langle M, w \rangle \mid M \text{ is a TM and } M \text{ halts on input } w\}
Theorem: HALTTMHALT_{TM} is undecidable.

2.2 Proof by Contradiction

Assume HALTTMHALT_{TM} is decidable. Then there exists a TM HH that decides it:
H(M,w)={acceptif M halts on wrejectif M loops on wH(\langle M, w \rangle) = \begin{cases} \text{accept} & \text{if } M \text{ halts on } w \\ \text{reject} & \text{if } M \text{ loops on } w \end{cases}
Construct a new TM DD that uses HH as a subroutine:
python
def 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 DD on input D\langle D \rangle:
  • If DD halts on D\langle D \rangle, then H(D,D)H(D, D) says "accept" → DD loops forever (contradiction)
  • If DD loops on D\langle D \rangle, then H(D,D)H(D, D) says "reject" → DD halts (contradiction) Neither case is possible → our assumption that HH exists is false → HALTTMHALT_{TM} 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
Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.