Cite

This course has no released version yet: the text at this address may change. Cite a released version when one exists.

/courses/fundamentals/rice-theorem
@misc{fundamentals-rice-theorem,
  title = {{Rice's theorem}},
  howpublished = {Lesson 6 of \emph{Fundamentals of computability}, Computability Theory course notes},
  url = {/courses/fundamentals/rice-theorem},
  note = {Unreleased working version}
}

To cite a single statement, use the # link that appears next to its heading.

Lesson 6 of 6

Rice's theorem

Non-trivial index sets are not computable; the halting set reduces to them; c.e. index sets are monotone and determined by finite information.

40 min6 questions
Fundamentals of computability · lesson 6 of 6
  1. Programs as numbers
  2. The universal function and the SMN theorem
  3. The halting problem
  4. Computably enumerable sets
  5. Kleene's fixed point theorem
  6. Rice's theorem

The halting problem is one undecidable question about programs. Rice’s theorem shows that it is typical: no question about the function computed by a program can be decided from its index, except the trivial ones. This lesson proves the theorem twice, by the fixed point theorem and by a reduction from the halting set, and then determines which questions about the function computed can at least be confirmed, that is, which index sets are computably enumerable.

6.1 Index sets

A property of programs may concern their text — “does the program have fewer than 100100 states?”, decidable by inspecting the code — or their behavior. The second kind is captured as follows.

Definition 6.1.#

A set P⊆NP \subseteq \nat is an index set if, for all aa and bb, Φa=Φb\Phi_a = \Phi_b and a∈Pa \in P imply b∈Pb \in P. It is non-trivial if P≠∅P \neq \emptyset and P≠NP \neq \nat.

Equivalently, PP is an index set if there is a class C\mathcal C of unary partial computable functions with P={e:Φe∈C}P = \{ e : \Phi_e \in \mathcal C \}; it is non-trivial if C\mathcal C contains some but not all partial computable functions.

Example 6.2.#

The following are non-trivial index sets: Tot={e:Φe is total}\mathrm{Tot} = \{ e : \Phi_e \text{ is total} \}; {e:Φe(0) ⁣ ⁣↓=42}\{ e : \Phi_e(0)\converge = 42 \}; {e:We=∅}\{ e : W_e = \emptyset \}; {e:We is finite}\{ e : W_e \text{ is finite} \}; {e:Φe=Φa}\{ e : \Phi_e = \Phi_a \} for a fixed aa. The set {e:e<100}\{ e : e < 100 \} is not an index set: it contains 00, while by the padding lemma the function Φ0\Phi_0 also has the index p(0,100)≥100p(0, 100) \geq 100, which is not in the set.

6.2 Rice’s theorem

Theorem 6.3 (Rice).#

No non-trivial index set is computable.

Proof of Theorem 6.3.

Let PP be a non-trivial index set, and suppose it is computable. Fix a∈Pa \in P and b∉Pb \notin P, and let f(x)=bf(x) = b if x∈Px \in P, f(x)=af(x) = a if x∉Px \notin P. Since PP is computable, ff is total computable. By Theorem 5.1, there is ee with Φf(e)=Φe\Phi_{f(e)} = \Phi_e, so that e∈P  ⟺  f(e)∈Pe \in P \iff f(e) \in P, as PP is an index set. But by construction f(e)∈P  ⟺  e∉Pf(e) \in P \iff e \notin P. This is a contradiction.

The fixed point proof shows that PP is not computable, but not how difficult it is. A reduction gives more information.

Proposition 6.4.#

Let PP be a non-trivial index set, and let zz be an index of the nowhere defined function (since PP is an index set, whether z∈Pz \in P does not depend on the choice of zz). If z∉Pz \notin P, then ∅′≤mP\emptyset' \leq_m P. If z∈Pz \in P, then ∅′≤mN∖P\emptyset' \leq_m \nat \setminus P.

Proof of Proposition 6.4.

Suppose z∉Pz \notin P, and fix a∈Pa \in P. By Corollary 2.3, there is a total computable gg such that

Φg(e)(x)≃{Φa(x)if Φe(e) ⁣ ⁣↓,undefinedotherwise,\Phi_{g(e)}(x) \simeq \begin{cases} \Phi_a(x) & \text{if } \Phi_e(e)\converge,\\ \text{undefined} & \text{otherwise,} \end{cases}

the program g(e)g(e) first computes Φe(e)\Phi_e(e), and if this halts, computes Φa(x)\Phi_a(x). If e∈∅′e \in \emptyset', then Φg(e)=Φa\Phi_{g(e)} = \Phi_a, so g(e)∈Pg(e) \in P. If e∉∅′e \notin \emptyset', then Φg(e)=Φz\Phi_{g(e)} = \Phi_z, so g(e)∉Pg(e) \notin P. Hence gg reduces ∅′\emptyset' to PP. If z∈Pz \in P, apply this to the non-trivial index set N∖P\nat \setminus P, which does not contain zz.

This gives a second proof of Theorem 6.3, since ∅′\emptyset' is not computable. It also shows that every non-trivial index set not containing the indices of the nowhere defined function is at least as hard as the halting set; if it is c.e., it is m-complete.

6.3 Which index sets are c.e.

Some non-trivial index sets are c.e., for instance {e:Φe(3) ⁣ ⁣↓}\{ e : \Phi_e(3)\converge \} and {e:We≠∅}\{ e : W_e \neq \emptyset \}; others are not, such as Tot\mathrm{Tot} (Corollary 4.13). The following theorem gives two necessary conditions. For partial functions, write θ⊆f\theta \subseteq f if ff extends θ\theta, that is, θ(x) ⁣ ⁣↓=y\theta(x)\converge = y implies f(x) ⁣ ⁣↓=yf(x)\converge = y.

Theorem 6.5 (Rice–Shapiro, necessity).#

Let C\mathcal C be a class of unary partial computable functions such that P={e:Φe∈C}P = \{ e : \Phi_e \in \mathcal C \} is c.e. Then:

  1. (monotonicity) if f∈Cf \in \mathcal C and gg is partial computable with f⊆gf \subseteq g, then g∈Cg \in \mathcal C;
  2. (finiteness) if f∈Cf \in \mathcal C, then some finite function θ⊆f\theta \subseteq f belongs to C\mathcal C.
Proof of Theorem 6.5.

In both cases, we reduce N∖∅′\nat \setminus \emptyset' to PP, which is impossible since N∖∅′\nat \setminus \emptyset' is not c.e. (Theorem 4.9) while PP is (Proposition 4.10).

  1. Suppose f∈Cf \in \mathcal C, f⊆gf \subseteq g, gg partial computable and g∉Cg \notin \mathcal C. By Corollary 2.3, there is a total computable hh such that the program h(e)h(e), on input xx, runs the computations of f(x)f(x) and of Φe(e)\Phi_e(e) in parallel, stage by stage: if f(x)f(x) converges first (or at the same stage), it outputs f(x)f(x); if Φe(e)\Phi_e(e) converges first, it computes and outputs g(x)g(x). If e∉∅′e \notin \emptyset', the second case never occurs and Φh(e)=f∈C\Phi_{h(e)} = f \in \mathcal C. If e∈∅′e \in \emptyset', then Φh(e)=g\Phi_{h(e)} = g: on x∈dom(f)x \in \mathrm{dom}(f), both cases give f(x)=g(x)f(x) = g(x); on x∉dom(f)x \notin \mathrm{dom}(f), only the second case can occur, and gives g(x)g(x). So Φh(e)∉C\Phi_{h(e)} \notin \mathcal C, and hh reduces N∖∅′\nat \setminus \emptyset' to PP.
  2. Suppose f∈Cf \in \mathcal C and no finite θ⊆f\theta \subseteq f is in C\mathcal C. Let hh be total computable such that Φh(e)(x)≃f(x)\Phi_{h(e)}(x) \simeq f(x) if Φe(e)[x] ⁣ ⁣↑\Phi_e(e)[x]\diverge, and Φh(e)(x)\Phi_{h(e)}(x) is undefined otherwise. If e∉∅′e \notin \emptyset', then Φh(e)=f∈C\Phi_{h(e)} = f \in \mathcal C. If e∈∅′e \in \emptyset', let ss be the least stage with Φe(e)[s] ⁣ ⁣↓\Phi_e(e)[s]\converge; then Φh(e)\Phi_{h(e)} is the restriction of ff to {0,…,s−1}\{0, \dots, s - 1\}, a finite function contained in ff, hence not in C\mathcal C. So hh reduces N∖∅′\nat \setminus \emptyset' to PP.

The converse also holds, with a suitable formulation: PP is c.e. if and only if C\mathcal C is the class of partial computable functions extending some member of a c.e. list of finite functions (given by canonical codes). We admit this sufficiency part, which is proved in Rogers’ and Odifreddi’s books (in the sections on index sets and the Rice–Shapiro theorem).

Corollary 6.6.#

The following index sets are not c.e.: Tot\mathrm{Tot}; {e:We is infinite}\{ e : W_e \text{ is infinite} \}; {e:We is finite}\{ e : W_e \text{ is finite} \}; {e:We=∅}\{ e : W_e = \emptyset \}; {e:Φe=Φa}\{ e : \Phi_e = \Phi_a \} for any index aa of a total function.

Proof of Corollary 6.6.

For Tot\mathrm{Tot}, {e:We infinite}\{ e : W_e \text{ infinite} \} and {e:Φe=Φa}\{ e : \Phi_e = \Phi_a \} with Φa\Phi_a total, finiteness fails: these classes contain an infinite function, total or with infinite domain, but no finite function. For {e:We finite}\{ e : W_e \text{ finite} \} and {e:We=∅}\{ e : W_e = \emptyset \}, monotonicity fails: the nowhere defined function belongs to the class, and its extension the constant function 00 does not.

6.4 Consequences

Rice’s theorem is a limitation on the automatic analysis of programs. Whether a program meets a behavioral specification — computes a given function, halts on all inputs, never outputs 00 — is undecidable in general. In practice, program analysis tools either restrict the programs considered, or accept answers that may be inconclusive. The theorem is about decidability only. Questions of the form “does the program ever do this?” are often c.e., while questions about all inputs, such as totality, are typically not even c.e. Measuring their exact difficulty is the purpose of the arithmetic hierarchy, the subject of a later course.

6.5 Exercises

Exercise 6.7 ★.

Show that there is no algorithm which, given aa and bb, decides whether Φa=Φb\Phi_a = \Phi_b.

Solution

Fix an index zz of the nowhere defined function. If equality were decidable, the set {e:Φe=Φz}\{ e : \Phi_e = \Phi_z \} would be computable. It is an index set, non-trivial since it contains zz and no index of the constant function 00. This contradicts Theorem 6.3.

Exercise 6.8 ★.

Is {e:Φe(0) ⁣ ⁣↓ and Φe(1) ⁣ ⁣↑}\{ e : \Phi_e(0)\converge \text{ and } \Phi_e(1)\diverge \} c.e.?

Solution

No. It is an index set, and monotonicity fails: the function defined only at 00 belongs to the class, and its extension defined at 00 and 11 does not. By Theorem 6.5, the set is not c.e.

Exercise 6.9 ★★.

Show that {e:We is computable}\{ e : W_e \text{ is computable} \} is not c.e.

Solution

It is an index set. Monotonicity fails: the nowhere defined function has the computable domain ∅\emptyset, while its extension g(x)≃0g(x) \simeq 0 if x∈∅′x \in \emptyset', undefined otherwise, is partial computable with domain ∅′\emptyset', which is not computable. By Theorem 6.5, the set is not c.e.

6.6 Notes and references

Rice’s theorem appeared in 1953, in a paper on classes of c.e. sets; Rice and Shapiro characterized independently, in 1956, the classes of c.e. sets whose index sets are c.e. The analogous result for partial computable functions is the Myhill–Shepherdson theorem (1955), which states that effective operations on partial computable functions are continuous, in the sense that their values depend on finite information.

  • H. G. Rice, Classes of recursively enumerable sets and their decision problems, Transactions of the American Mathematical Society 74 (1953), 358–366.
  • H. G. Rice, On completely recursively enumerable classes and their key arrays, Journal of Symbolic Logic 21 (1956), 304–308.
  • N. Shapiro, Degrees of computability, Transactions of the American Mathematical Society 82 (1956), 281–299.
  • J. Myhill and J. C. Shepherdson, Effective operations on partial recursive functions, Zeitschrift für mathematische Logik und Grundlagen der Mathematik 1 (1955), 310–317.
  • H. Rogers, Theory of Recursive Functions and Effective Computability, McGraw-Hill, 1967.
  • P. Odifreddi, Classical Recursion Theory, North-Holland, 1989.