4.6.20Theory of Computation

Rice's theorem

2,119 words10 min readdifficulty · medium3 backlinks

WHY does this theorem even exist?

WHAT is "behavior" vs "structure"?

  • Behavioral (semantic) property = a property of the language L(M)L(M) — the set of strings the machine accepts. Example: "does MM accept the empty string?", "is L(M)L(M) infinite?", "is L(M)=L(M)=\emptyset?".
  • Structural (syntactic) property = a property of the machine description itself, not of what it computes. Example: "does MM have 7 states?", "does MM ever write a blank?". These are often decidable and Rice says nothing about them.

The Statement

The two excluded trivial cases (which are decidable):

  • P=P = \varnothing (no language has it) → always answer "no".
  • P=all r.e. languagesP = \text{all r.e. languages} → always answer "yes".

DERIVATION from first principles (reduction from Halting / ATMA_{TM})

Setup. Let PP be non-trivial. We use the undecidable language ATM={M,w:M accepts w}A_{TM} = \{\langle M,w\rangle : M \text{ accepts } w\}.

Step 1 — Pick a baseline. WLOG assume P\varnothing \notin P (the empty language does not have the property). Why this step? If P\varnothing \in P instead, just prove undecidability for the complement property Pˉ\bar P; deciding PP would decide Pˉ\bar P, so it's symmetric. So we lose nothing.

Step 2 — Grab a witness. Since PP is non-trivial and P\varnothing\notin P, there exists some language L(MP)PL(M_P) \in P with a machine MPM_P recognizing it. Why this step? Non-triviality guarantees at least one "yes" example. We need a target language that does have the property to switch into.

Step 3 — The gadget. Given input M,w\langle M,w\rangle, build a new machine GM,wG_{M,w} that on input xx does:

  1. Ignore xx for now. First run MM on ww (simulate).
  2. If MM accepts ww, then run MPM_P on xx and accept iff MPM_P accepts xx.

Why this step? This is the heart. Trace the two worlds:

  • If MM accepts ww: step 1 finishes, so GM,wG_{M,w} behaves exactly like MPM_P, hence L(GM,w)=L(MP)PL(G_{M,w}) = L(M_P) \in P.
  • If MM does not accept ww: step 1 never finishes, GM,wG_{M,w} never reaches step 2, accepts nothing, so L(GM,w)=PL(G_{M,w}) = \varnothing \notin P.

So: L(GM,w)P    M accepts w.L(G_{M,w}) \in P \iff M \text{ accepts } w.

Step 4 — Contradiction. Suppose a decider RR for LPL_P exists. Feed it GM,w\langle G_{M,w}\rangle: RR says "yes"     L(GM,w)P    M\iff L(G_{M,w})\in P \iff M accepts ww. That decides ATMA_{TM} — impossible. Therefore LPL_P is undecidable. \blacksquare

Figure — Rice's theorem

Worked Examples


Common Mistakes (Steel-manned)


Recall Feynman: explain to a 12-year-old

Imagine you have a magic box that runs other little robot-programs. You want a checker-machine that reads a robot's instruction sheet and tells you "this robot will eventually say the word cat." Rice's theorem says: no such perfect checker can exist for any interesting "what will it eventually do" question. The only questions you can always answer are the boring ones where the answer is the same for every robot ("yes, always" or "no, never"). The reason: to check the robot, your checker would secretly have to know whether the robot ever stops — and we already proved nobody can know that in general.


Connections

  • Halting Problem — the seed; Rice generalizes it.
  • A_TM and undecidability — the language we reduce from.
  • Mapping reductions — the proof technique (build a gadget machine).
  • Recursive vs Recursively Enumerable languages — undecidable ≠ non-r.e.
  • Rice-Shapiro theorem — refines Rice to decide recognizability.
  • Turing Machines — the underlying model.

Flashcards

What does Rice's theorem state?
Every non-trivial semantic property of the language r.e. by a TM is undecidable.
What is a "semantic"/behavioral property?
A property of L(M)L(M) (what the machine accepts), independent of the machine's encoding.
What is a "non-trivial" property?
One that is true for at least one r.e. language and false for at least one r.e. language.
Which two property types are EXCLUDED by Rice?
Trivial properties (always-true or always-false) and syntactic properties (about the machine description).
Why is non-triviality required in the proof?
The reduction needs a YES-witness language and a NO-witness (\varnothing) to flip between; trivial properties can't flip.
What language is reduced FROM in the proof?
ATM={M,w:M accepts w}A_{TM}=\{\langle M,w\rangle : M \text{ accepts } w\} (equivalently the Halting Problem).
In the gadget GM,wG_{M,w}, what is L(GM,w)L(G_{M,w}) when MM rejects/loops on ww?
\varnothing (it never finishes simulating MM on ww, so accepts nothing).
In the gadget, what is L(GM,w)L(G_{M,w}) when MM accepts ww?
L(MP)L(M_P), the witness language that HAS property PP.
Is "does MM have 5 states?" covered by Rice?
No — it's a syntactic property of the description; it's decidable.
Does Rice say LPL_P is non-r.e.?
No, only that it's undecidable (not recursive). It may still be r.e.
Is "L(M)L(M) is regular?" decidable?
No — non-trivial semantic property → undecidable by Rice.
Is "L(M)=L(M)=\varnothing?" decidable?
No — non-trivial (\varnothing has it, Σ\Sigma^* doesn't) → undecidable.

Concept Map

generalized by

reduces to

applies to

says nothing about

requires

encoded as

makes

is

is

built into

proves

gives yes and no machines

Halting Problem undecidable

A_TM machine accepts w

Rice's Theorem

Behavioral property of L of M

Structural property of machine

Non-trivial property

L_P set of machine codes

Undecidable

Often decidable

Gadget machine flips property

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, Rice's theorem ka core idea bahut simple hai: agar koi property language ke baare mein hai — yaani "machine M kya kya strings accept karti hai" ke baare mein — aur woh property non-trivial hai (matlab kuch languages mein woh hoti hai aur kuch mein nahi), toh us property ko decide karna impossible hai. Sirf trivial questions ("har machine ke liye haan" ya "har machine ke liye naa") decidable hote hain, baaki sab undecidable.

Yeh kyu important hai? Kyunki yeh Halting Problem ka bada bhai hai. Halting ek single behavioral question tha; Rice bolta hai ki saare interesting behavioral questions utne hi mushkil hain. Toh exam mein agar poochha jaye "kya L(M)L(M) regular hai?" ya "kya L(M)L(M) empty hai?" — aap turant bol sakte ho undecidable, bas non-triviality check karke (ek YES example, ek NO example dikhao). Pura reduction dobara likhne ki zaroorat nahi.

Proof ka jugaad samajh lo: hum ek naya gadget machine GM,wG_{M,w} banate hain jo pehle MM ko ww par chalata hai, aur tabhi aage badhta hai jab MM accept kare. Agar MM accept karta hai toh GG ki language witness wali language ban jaati hai (property hai); agar nahi toh GG kuch accept hi nahi karta, language khali ho jaati hai (property nahi). Isse property ka answer Halting ka answer ban jaata hai — aur Halting decide nahi ho sakta, toh property bhi nahi.

Ek important warning: Rice sirf semantic (language wali) properties par lagta hai. "Machine mein kitne states hain?" jaise syntactic sawaal decidable hote hain — wahan Rice mat lagao, warna galat ho jaoge.

Go deeper — visual, from zero

Test yourself — Theory of Computation

Connections