1 · Why this matters · the BIG picture
"Can my program's language be described by a regex?" is a natural classification question. It would be useful to know — regular languages have linear-time matchers, predictable behavior, no need for stack or tape. Sadly, the question is undecidable in general. This is the simplest example of a structural language property that Rice's theorem will later unify.
What we prove
REGULARTM = {⟨M⟩ : L(M) is a regular language} is undecidable.
2 · Setup · the gadget trick
Reduce ATM to REGULARTM. Given ⟨M, w⟩, build M' with two branches:
Construction
M' = "on input x:
1. if x has form 0n1n: accept;
2. else: simulate M on w; accept x iff M accepts w."
Why 0n1n? Because it's the canonical non-regular decidable language. The construction needs a "non-regular base case" that M' can recognize on its own; {0n1n} is the simplest.
3 · The proof · case analysis
- If M does NOT accept w · branch 2 never accepts. So L(M') = {0n1n} — not regular (pumping lemma).
- If M accepts w · branch 2 accepts every x. So L(M') = Σ* (everything from branch 1 ∪ branch 2) — regular.
So ⟨M, w⟩ ∈ ATM ⇔ ⟨M'⟩ ∈ REGULARTM. A decider for REGULARTM ⇒ decider for ATM. Contradiction ⇒ REGULARTM undecidable. ∎
4 · Animated demo · auto-plays · loops
5 · Worked example · concrete M and w
Take M = "always halts and rejects" (so M(w) = reject for every w). Then for every choice of w:
- M does not accept w.
- Branch 2 never accepts.
- L(M') = {0n1n}, non-regular.
- ⟨M'⟩ ∉ REGULARTM.
Take M' = "always halts and accepts everything", w = anything. M accepts w. Branch 2 always accepts. L(M') = Σ*, regular. ⟨M'⟩ ∈ REGULARTM.
6 · Connections · the family of language-property reductions
- ETM (P6) · same trick, gadget = ∅ vs Σ*.
- CFLTM · "is L(M) context-free?" — replace {0n1n} with a non-CF language like {0n1n2n}.
- FINTM · "is L(M) finite?" — gadget = {ε} vs Σ*.
- Rice's theorem (P14) · the master pattern: every nontrivial semantic property is undecidable.
7 · Common pitfalls · what students miss
- Forgetting branch 1. Without the unconditional accept of 0n1n, L(M') = ∅ when M doesn't accept w — and ∅ is regular. The construction fails.
- Confusing "regular" with "decidable". {0n1n} is decidable but not regular. The gadget needs decidable + non-regular.
- "M' must be deterministic." Not required. The TM model here is the standard deterministic TM; M' just uses a polynomial gadget on its input.
- Mixing up the direction. ⟨M, w⟩ ∈ ATM ⇔ L(M') regular. Don't flip it.
8 · Q&A defence notes
Q1. Why {0n1n}?
Because it's not regular (pumping lemma) but is decidable. Any non-regular decidable language would work; this is the canonical choice.
Q2. What if M loops on w?
Then for x ∉ {0n1n}, M' loops. But L(M') = {0n1n} still — those are exactly the strings M' accepts. Looping on other strings doesn't add them to the language.
Q3. Why doesn't this prove REGULARTM is not even recognizable?
It only shows undecidability. To prove non-recognizability you'd argue: if REGULARTM were recognizable, by symmetric construction so would be ¬REGULARTM, contradicting the bridge theorem.
Q4. Generalize: which other properties of L(M) is this proof template good for?
Any nontrivial semantic property — that's Rice's theorem (Problem 14). Pick any pair of languages, one with property P and one without; build a similar gadget.
9 · How to present this in class
Total time: 8 minutes.
- (1 min) Motivate: "Can I tell if my program's language is regular?"
- (2 min) Construction of M' on the board with two branches.
- (2 min) Run the visualization. Pause between the two cases.
- (2 min) Two-case analysis: L(M') = {0n1n} or Σ*.
- (1 min) Tease Rice's theorem: this is one of many.