G27
Self-checkedTier 1 9 min readtoc.rice-theorem

Rice's theorem

Rice's theorem: every non-trivial property of the language of a Turing machine is undecidable. The statement (semantic and non-trivial properties), the reduction from A_TM through the machine M_w, how to apply it to properties such as emptiness, finiteness, regularity and universality, which questions are NOT covered (syntactic properties such as the number of states or halting within k moves, and behaviour that is not a property of the language, such as halting on the empty input), and the usual traps.

Why it exists

After ATMA_{TM} and the halting problem one would like a quick way to see that a new question about Turing machines is undecidable, without a new reduction every time. Rice's theorem is that quick way for a large family of questions: anything non-trivial about the language a machine recognises is undecidable. GATE uses it in true/false questions about Turing machines ("is it decidable whether L(M)L(M) is ...?").

Prerequisites

You need ATMA_{TM}, its undecidability and mapping reductions (the halting problem).

Precise definitions

Let P\mathcal{P} be a property of recognisable languages, that is, a set of recognisable languages (for example "the empty language", "languages with at least two strings", "regular languages"). Define the decision problem

LP={⟨M⟩:M is a Turing machine and L(M)∈P}.L_{\mathcal{P}} = \{\langle M \rangle : M \text{ is a Turing machine and } L(M) \in \mathcal{P}\}.

  • P\mathcal{P} is trivial if it contains all recognisable languages or none of them. Otherwise it is non-trivial: at least one recognisable language has the property and at least one does not.
  • The question about ⟨M⟩\langle M \rangle is semantic when it depends only on the language L(M)L(M): if L(M1)=L(M2)L(M_1) = L(M_2) then M1M_1 and M2M_2 answer alike. (This is what the definition of LPL_{\mathcal{P}} expresses.)

Rice's theorem. If P\mathcal{P} is a non-trivial property of recognisable languages, then LPL_{\mathcal{P}} is undecidable.

How it works

The proof

Assume first that the empty language does not have the property P\mathcal{P} (otherwise use the complementary property P‾\overline{\mathcal{P}}, which is non-trivial too, and note that a decider for one gives a decider for the other). Since P\mathcal{P} is non-trivial, pick a machine MPM_P with L(MP)∈PL(M_P) \in \mathcal{P}.

Reduce ATMA_{TM} to LPL_{\mathcal{P}}. Given ⟨M,w⟩\langle M, w \rangle construct the machine MwM_w:

On input xx: first run MM on ww (ignoring xx). If MM accepts ww, run MPM_P on xx and accept if MPM_P accepts. (If MM rejects or loops, MwM_w rejects or loops.)

Then

L(Mw)={L(MP)∈Pif M accepts w,∅∉Potherwise,L(M_w) = \begin{cases} L(M_P) \in \mathcal{P} & \text{if } M \text{ accepts } w, \\ \emptyset \notin \mathcal{P} & \text{otherwise,} \end{cases}

so ⟨Mw⟩∈LP  ⟺  ⟨M,w⟩∈ATM\langle M_w \rangle \in L_{\mathcal{P}} \iff \langle M, w \rangle \in A_{TM}. The map ⟨M,w⟩↦⟨Mw⟩\langle M, w \rangle \mapsto \langle M_w \rangle is computable (it only writes down a machine). A decider for LPL_{\mathcal{P}} would decide ATMA_{TM}, which is impossible. ■\qquad\blacksquare

The table runs the construction for the simplest choice of MPM_P (accept every string). For six real pairs (M,w)(M, w) it shows the behaviour of MwM_w on four inputs xx: either it accepts all of them (when MM accepts ww) or none (when MM rejects or loops on ww):

The machine M_w of Rice's theorem: start

Computed by a script, not typed
(M, w)M_w on εM_w on aM_w on abM_w on bbblanguage of M_w
M2 and w = aabb
M2 and w = aab
M1 and w = ab
M1 and w = aa
M4 and w = a
M3 and w = ε

Step 0

M_w is built from (M, w) in such a way that its language is either everything or nothing, depending only on whether M accepts w. So any non-trivial property of languages that separates 'everything' from 'nothing' would decide A_TM.

0 / 6
computed by script: the machine is simulated or the sets are constructed by scripts/toc_lib.py, one step at a time. python3 scripts/gen-toc5-traces.py

Using the theorem

To show that a question about L(M)L(M) is undecidable: state the property as a set P\mathcal{P} of languages, check that it is a property of the language and that it is non-trivial (give one machine with the property and one without), and conclude.

question about MMproperty of the language?non-trivial?decidable?
L(M)=∅L(M) = \emptysetyesyesno
L(M)=Σ∗L(M) = \Sigma^*yesyesno
L(M)L(M) is finite / infiniteyesyesno
L(M)L(M) is regular / context-free / decidableyesyesno
L(M)L(M) contains a given string ssyesyesno
L(M)L(M) contains at least 55 stringsyesyesno
L(M1)=L(M2)L(M_1) = L(M_2) for two machinesyes (two machines)–no (reduce ETME_{TM})
L(M)L(M) is recognisableyesno (every L(M)L(M) is)yes (the answer is always yes)
MM has an even number of statesno (a property of the machine)–yes
MM halts on input ww within kk movesno (a property of the machine's behaviour)–yes (simulate kk moves)
MM halts on the empty inputno–no, by the halting problem
MM halts on every inputno–no (not by Rice)

What Rice's theorem does not cover

Properties of the machine, not of the language. "Has an even number of states", "has a transition that writes a blank", "halts within kk moves on ww": these depend on the description of MM (or on a bounded part of its behaviour) and are decidable by inspecting or simulating the machine for a bounded time. Simulating for kk moves always terminates; the answer agreed with a second simulator for k≤11k \le 11 on all short inputs of six machines.

Behaviour that two machines with the same language may differ on. "Halts on the empty input" and "halts on every input" are not properties of the language, since a machine can accept the same strings while looping or halting elsewhere. Example: the decider for anbna^n b^n and its halting variant (every halting rejection replaced by an endless loop) accept exactly the same language (checked on all strings up to length 88), but the first halts on the input aa (rejecting) while the second never halts on it. So Rice's theorem does not apply to such questions; they are undecidable by direct reductions from the halting problem instead.

Trivial properties. "L(M)L(M) is a recognisable language" holds for every machine; the question is decidable (the answer is always yes). The same for the property "L(M)L(M) is not recognisable".

The language class matters. The theorem is about recognisable languages. For a different model, results change: all the properties above are decidable for DFAs (EDFAE_{DFA}, EQDFAEQ_{DFA}, finiteness).

Worked examples

EX 1Apply the theorem

Easy

"Is L(M)L(M) infinite?" The property "infinite" is a property of languages, non-trivial (Σ∗\Sigma^* is infinite, ∅\emptyset is not, both are recognisable). Hence the set of machines with an infinite language is undecidable by Rice's theorem.

EX 2Rice does not apply

Easy

"Does MM have more than 1010 states?" This is read off the description of MM, so it is decidable. "Does MM halt within 100100 moves on the input 01010101?" Simulate 100100 moves: decidable. Neither is a question about L(M)L(M).

EX 3The trap with halting

Medium

"Does MM halt on every input?" looks like a question about all of Σ∗\Sigma^* but is not a property of L(M)L(M): L(M)L(M) is only what MM accepts. The set of machines that halt on every input is undecidable, but the proof is a separate reduction (from the halting problem), not Rice's theorem.

EX 4Run the proof for a concrete property

Medium

Property P\mathcal{P} = "the language contains the string aa". ∅∉P\emptyset \notin \mathcal{P}. Take MPM_P = the machine that accepts every string. Given (M,w)(M, w) build MwM_w = "run MM on ww; if it accepts, accept". If MM accepts ww, L(Mw)=Σ∗∋aL(M_w) = \Sigma^* \ni a; otherwise L(Mw)=∅∌aL(M_w) = \emptyset \not\ni a. So ⟨Mw⟩∈LP\langle M_w \rangle \in L_{\mathcal{P}} iff MM accepts ww. The table shows the machines for (M2,aabb)(M2, aabb), (M2,aab)(M2, aab), (M1,ab)(M1, ab), (M1,aa)(M1, aa) and others.

EX 5Typical questions

GATE level

(a) "Which of these is undecidable for a Turing machine MM: (i) L(M)L(M) is empty; (ii) L(M)L(M) is regular; (iii) MM has 33 states; (iv) L(M)L(M) contains a string of length 55?" (i), (ii), (iv) by Rice; (iii) is decidable. (b) "By Rice's theorem, which of the following is decidable?" The one that is not a non-trivial property of L(M)L(M). (c) "The set of Turing machines that accept at least one string is:" recursively enumerable but not recursive. (d) "Is it decidable whether two Turing machines accept the same language?" No. (e) "Does Rice's theorem show that it is undecidable whether a TM halts on all inputs?" No, a separate reduction is needed.

Cheat box

Cheat box

  • Rice: every non-trivial property of L(M)L(M) is undecidable (set of ⟨M⟩\langle M \rangle with L(M)L(M) in a non-trivial class P\mathcal{P} of recognisable languages).
  • Proof: reduce ATMA_{TM}; MwM_w runs MM on ww, then MPM_P on xx; L(Mw)=L(MP)L(M_w) = L(M_P) or ∅\emptyset.
  • Applies to: emptiness, universality, finiteness, regularity, containing a string, equivalence of two machines.
  • Does not apply to: number of states, halting within kk moves, halting on a given or on all inputs (not properties of the language).
  • Trivial properties are decidable.

Traps and GATE patterns

Connections

Rice's theorem generalises the reduction used for ETME_{TM} (halting problem); it uses the machine descriptions and the universal machine (TM variants); the contrast with decidable problems for automata is on the page on decidable languages.

PYQs

6 previous year questions from your book. I re-solved each one myself (0 by running or simulating, 6 by reasoning only); the book's key is shown next to my answer. All PYQs

GATE 2022 · MSQ · 2 marksQ2 · page 241 of the book
Which of the following is/are undecidable?
  • (a)Given two Turing machines M1, and M2, decide if L(M1) = L(M2).
  • (b)Given a Turing machine M, decide if L(M) is regular.
  • (c)Given a Turing machine M, decide if M accepts all strings.
  • (d)Given a Turing machine M, decide if M takes more than 1073 steps on every string.
GATE 2020 · MCQQ5 · page 241 of the book
Which of the following languages are undecidable? Note
that <M> indicates encoding of the Turing machine M.
L1 = <M> | L(M) = φ}
L2 = {<M, w, q>| M on input w reaches state q in exactly
100 steps}
L3 = {<M>|L(M) is not recursive}
L4 = {<M>|L(M) contains at least 21 members}?
  • (a)L2 and L3 only
  • (b)L1 and L3 only
  • (c)L2, L3 and L4 only
  • (d)L1, L3 and L4 only
GATE 2018 · MCQ · 2 marksQ8 · page 242 of the book
Consider the following problems. L(G) denotes the
language generated by a grammar G. L(M) denotes the
language
accepted
by
a
machine
M.
(I) For an unrestricted grammar G and a string w,
whether w∈L(G).
(II) Given a Turing machine M, whether L(M) is
regular.
(III)Given two grammar G1 and G2, whether L(G1) =
L(G2).
(IV) Given an NFA N, whether there is a deterministic
PDA P such that N and P accept the same language.
Which one of the following statement is correct?
  • (a)Only I and II are undecidable
  • (b)Only III is undecidable
  • (c)Only II and IV are undecidable.
  • (d)Only I, II and III are undecidable.
GATE 2016 · Set 2 · MCQ · 2 marksQ12 · page 242 of the book
Consider the following languages.
L1 = { ⟨M⟩ | M takes at least 2016 steps on some input },
L2 = { ⟨M⟩ | M takes at least 2016 steps on all inputs },
and
L3 = { ⟨M⟩ | M accepts ε },
Where for each Turing machine M, ⟨M⟩ denotes a specific
encoding of M.
Which one of the following is TRUE?
  • (a)L1 is recursive and L2, L3 are not recursive
  • (b)L2 is recursive and L1, L3 are not recursive
  • (c)L1, L2 are recursive and L3 is not recursive
  • (d)L1, L2, L3 are recursive
year not read yetQ15 · page 243 of the book
Let <M> be the encoding of a Turing machine as a
string over Σ = {0, 1} Let L = { <M> |M is a Turing
machine that accepts a string of length 2014}. Then, L
is :
  • (a)decidable and recursively enumerable
  • (b)undecidable but recursively enumerable
  • (c)undecidable and not recursively enumerable
  • (d)decidable but not recursively enumerable
year not read yetQ18 · page 243 of the book
Which of the following is/are undecidable?
1. G is a CFG. Is L(G) = φ?
2. G is a CFG. Is L(G) = Σ*?
3. M is a Turing machine. Is L(M) regular?
4. A is a DFA and N is an NFA. Is L(A) = L(N)?
  • (a)3 only
  • (b)3 and 4 only
  • (c)1, 2 and 3 only
  • (d)2 and 3 only

Self-check

Question 1

Is it decidable whether a Turing machine accepts the empty language? Why?

Show answer

No: "the language is empty" is a non-trivial property of the language, so Rice's theorem applies.

Question 2

Is it decidable whether a Turing machine has at least 77 states?

Show answer

Yes: it is a property of the description of the machine, so one just counts.

Question 3

In the proof, what is L(Mw)L(M_w) if MM loops on ww?

Show answer

The empty language: MwM_w never gets past the simulation of MM on ww, so it accepts nothing.

Question 4

Why does Rice's theorem not show that "halts on every input" is undecidable?

Show answer

It is not a property of the language: two machines with the same language can differ in whether they halt everywhere.

Revision card

One-screen revision

  • Non-trivial property of L(M)L(M) ⇒\Rightarrow undecidable.
  • Proof: ATM≤mA_{TM} \le_m property via MwM_w = "run MM on ww, then MPM_P on xx".
  • Not covered: properties of the machine (states, kk moves), halting on inputs.
  • Trivial properties and automata questions are decidable.

References

  • ·Sipser, Introduction to the Theory of Computation (3rd edition), Problem 5.28 (Rice's theorem) and Section 5.1
  • ·Hopcroft, Motwani, Ullman, Introduction to Automata Theory, Languages, and Computation (3rd edition), Section 9.3 (Rice's theorem and properties of recursively enumerable languages)

Verification

scripts/enum-checks/toc_compute.py: the machine M_w of the proof (ignore the input, run M on w, accept if M accepts) was checked on six machines, all strings w up to length 3 and all inputs x up to length 3: M_w accepts x exactly when M accepts w, so L(M_w) is everything or nothing; the machine for a^n b^n and its 'halting variant' (every halting rejection replaced by an endless loop) accept the same language on all strings up to length 8 but the first halts on the input a and the second never halts there, so 'halts on every input' is not a property of the language; 'halts within k moves' agrees with a second simulator for k up to 11 on all short inputs of six machines. The statement and proof of Rice's theorem and the list of undecidable properties are standard textbook results, QUOTED and not machine-proved here (needs verification). The chapter references are from memory; Sipser states the theorem as a problem. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (state counts, derivations, parse-tree and move counts, decomposition counts); tables and animations are machine output and were read, not re-run; No other defect found. Status raised to self-checked; verified needs a textbook or human check.

last verified: never

My notes (saved in this browser)