Sub topic 12
Rice's theorem and non-trivial properties
This chapter assumes you know the halting problem, A_TM, and many-one reductions from the previous chapters. It also assumes you can read a Turing machine (TM) as a program and that you know the difference between recursive (decidable) and recursively enumerable (RE) languages.
What the theorem says
Many undecidability results share one pattern: you ask a question about what a machine does, not how it is written. Rice's theorem covers all such questions at once.
A property of RE languages is a set P of RE languages. A TM M "has" the property when L(M) is in P. The decision problem is:
L_P = { ⟨M⟩ : L(M) ∈ P }
A property is trivial if every RE language has it, or no RE language has it. Otherwise it is non-trivial: at least one TM has it and at least one TM does not.
Rice's theorem. For every non-trivial property P of RE languages, L_P is undecidable.
The theorem is about the language L(M), the set of strings M accepts. It says nothing about properties of the machine's structure or its running behaviour.
The two conditions to check
Before applying the theorem, check both conditions.
- The property is about L(M). If two machines accept the same language, they must give the same answer. Changing the machine without changing its language cannot change the answer.
- The property is non-trivial. You can name one machine whose language has it and another whose language does not.
If both hold, the problem is undecidable. If either fails, Rice's theorem gives no verdict, and you must reason directly.
Examples
| Question about ⟨M⟩ | About L(M)? | Non-trivial? | Verdict |
|---|---|---|---|
| Is L(M) empty? | Yes | Yes | Undecidable |
| Is L(M) regular? | Yes | Yes | Undecidable |
| Is L(M) finite? | Yes | Yes | Undecidable |
| Is L(M) = Σ*? | Yes | Yes | Undecidable |
| Does M accept the string "101"? | Yes | Yes | Undecidable |
| Is L(M) context-free? | Yes | Yes | Undecidable |
| Is L(M) RE? | Yes | No, every L(M) is RE | Trivial, decidable (always yes) |
| Does M have more than 10 states? | No, structural | Not applicable | Decidable by counting |
| Does M halt on ε within 100 steps? | No, behavioural | Not applicable | Decidable by simulation |
| Does M ever write a blank symbol? | No, behavioural | Not applicable | Not covered by Rice. It is undecidable, but needs a direct reduction |
| Is L(M) = L(M)? | Yes | No, always true | Trivial, decidable |
The last row shows that a trivial property is decidable, since the answer never changes. The "10 states" and "100 steps" rows are decidable because they can be checked in a bounded number of steps.
Why the theorem holds
The proof is a reduction from A_TM. This section gives the idea for a property P with ∅ ∉ P. The case ∅ ∈ P is handled by swapping P with its complement, because a language is decidable exactly when its complement is.
Since P is non-trivial, pick a TM MP with L(MP) ∈ P. Given an instance ⟨M, w⟩ of A_TM, build a new machine M' that works as follows on input x:
- Ignore x and run M on w.
- If M accepts w, run M_P on x and give its answer.
- If M rejects or loops, reject or loop.
Now there are two cases.
- If M accepts w, then L(M') = L(M_P), which is in P.
- If M does not accept w, then L(M') = ∅, which is not in P.
So ⟨M, w⟩ ∈ ATM exactly when ⟨M'⟩ ∈ LP. The map ⟨M, w⟩ ↦ ⟨M'⟩ is computable, because it only writes out a new machine description. A decider for LP would therefore decide ATM, which is impossible.
A concrete sketch in code
The construction in step 2 is a program transformation. The sketch below shows it in Python. The function make_m_prime returns a new program from M, w, and a fixed machine M_P. Here M and M_P are Python functions that return True to accept.
def make_m_prime(M, w, M_P):
def m_prime(x):
if M(w): # may loop forever, which is intended
return M_P(x) # behave like M_P
return False # reject: language is empty
return m_prime
# Example: M_P accepts strings of even length
def M_P(x):
return len(x) % 2 == 0
def M_accepts(w):
return True
m1 = make_m_prime(M_accepts, "abc", M_P)
print(m1("ab"), m1("abc")) # True FalseWhen M(w) returns True, m_prime computes exactly what M_P computes. The construction itself never runs M. It only builds m_prime. That is why the mapping is computable even when M loops.
Common errors
- Applying Rice's theorem to machine structure. "Does M have an even number of states?" is not about L(M). It is decidable.
- Applying it to behaviour instead of language. "Does M halt on every input?" and "Does M ever enter state q5?" depend on how M runs. Rice does not apply directly. Both are undecidable, but you prove it by reduction.
- Forgetting that two machines can share a language. If M1 and M2 accept the same language and a question gives different answers for them, the question is not about L(M).
- Treating "undecidable" as "not RE". Rice's theorem says undecidable only. Some of these languages are RE and some are not, as the next section shows.
- Missing the trivial case. A question that every machine answers the same way is decidable. "Is L(M) a subset of Σ*?" always holds.
Which side of RE does the problem fall on?
Rice's theorem says a property is undecidable. It does not say whether L_P is RE. A second result, often called the Rice–Shapiro theorem, settles this for RE-ness, but GATE usually only needs the working rule below, which you can check by thinking about what a machine can verify by running.
- If the property can be confirmed by seeing M accept finitely many strings, then L_P is usually RE. Example: "L(M) is non-empty" is RE. Dovetail M on all inputs, and accept when any run accepts.
- If the property needs a claim about all strings or about the absence of strings, then L_P is usually not RE. Example: "L(M) is empty" is not RE, because the set of non-empty-language machines is RE and the empty-language problem is its complement. If both were RE, the problem would be decidable.
| Problem | RE? | Co-RE? |
|---|---|---|
| L(M) ≠ ∅ | Yes | No |
| L(M) = ∅ | No | Yes |
| L(M) = Σ* | No | No |
| L(M) is finite | No | No |
| M accepts "101" | Yes | No |
Dovetailing means running M on all inputs a few steps at a time, so that no single looping run blocks the others.
Using Rice's theorem on GATE questions
A reliable routine for a statement "Is it decidable whether ...":
- Rewrite the question in the form "Given ⟨M⟩, does M ... ?".
- Ask whether the answer depends only on L(M). If it depends on states, transitions, tape usage, or step counts, Rice does not apply.
- Ask whether some machines say yes and some say no. If not, the problem is trivial and decidable.
- If both checks pass, answer "undecidable".
- If the question asks about RE-ness, ask whether a yes answer can be confirmed by one accepted string.
Exercises
Exercise
Decide whether each problem is decidable, and say why. (a) Given ⟨M⟩, does L(M) contain at least 5 strings? (b) Given ⟨M⟩, does M have at least 5 states? (c) Given ⟨M⟩, is L(M) = L(M)^R, where R is string reversal?
Show answer
(a) Undecidable. It is about L(M), and it is non-trivial (some languages have 5 strings, some do not), so Rice's theorem applies. (b) Decidable. It is a property of the machine's structure, so read the description and count states. (c) Undecidable. It is about L(M), and it is non-trivial (a palindromic language like {a} has it, {ab} does not), so Rice's theorem applies.
Exercise
A student argues: "Whether M halts on input ε is a property of M, and some machines halt and some do not, so by Rice's theorem it is undecidable." Is the conclusion right, and is the argument valid?
Show answer
The conclusion is right, because this is the halting problem on ε, which is undecidable. The argument is not valid. Halting on ε is a property of how M runs, not of L(M). Two machines can accept the same language while one halts on ε and the other loops there. Rice's theorem does not apply, and the proof needs a direct reduction from A_TM or the halting problem.
Exercise
Is "L(M) = ∅" undecidable, and is it RE? Justify using the complement.
Show answer
It is undecidable by Rice's theorem, because it is about L(M) and non-trivial. It is not RE. The complement, "L(M) ≠ ∅", is RE, since dovetailing M on all strings finds an accepted one if it exists. If "L(M) = ∅" were also RE, then both a language and its complement would be RE, which makes it recursive. That contradicts undecidability.