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 states?”, decidable by inspecting the code — or their behavior. The second kind is captured as follows.
A set is an index set if, for all and , and imply . It is non-trivial if and .
Equivalently, is an index set if there is a class of unary partial computable functions with ; it is non-trivial if contains some but not all partial computable functions.
The following are non-trivial index sets: ; ; ; ; for a fixed . The set is not an index set: it contains , while by the padding lemma the function also has the index , which is not in the set.
6.2 Rice’s theorem
No non-trivial index set is computable.
Let be a non-trivial index set, and suppose it is computable. Fix and , and let if , if . Since is computable, is total computable. By Theorem 5.1, there is with , so that , as is an index set. But by construction . This is a contradiction.
The fixed point proof shows that is not computable, but not how difficult it is. A reduction gives more information.
Let be a non-trivial index set, and let be an index of the nowhere defined function (since is an index set, whether does not depend on the choice of ). If , then . If , then .
Suppose , and fix . By Corollary 2.3, there is a total computable such that
the program first computes , and if this halts, computes . If , then , so . If , then , so . Hence reduces to . If , apply this to the non-trivial index set , which does not contain .
This gives a second proof of Theorem 6.3, since 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 and ; others are not, such as (Corollary 4.13). The following theorem gives two necessary conditions. For partial functions, write if extends , that is, implies .
Let be a class of unary partial computable functions such that is c.e. Then:
- (monotonicity) if and is partial computable with , then ;
- (finiteness) if , then some finite function belongs to .
In both cases, we reduce to , which is impossible since is not c.e. (Theorem 4.9) while is (Proposition 4.10).
- Suppose , , partial computable and . By Corollary 2.3, there is a total computable such that the program , on input , runs the computations of and of in parallel, stage by stage: if converges first (or at the same stage), it outputs ; if converges first, it computes and outputs . If , the second case never occurs and . If , then : on , both cases give ; on , only the second case can occur, and gives . So , and reduces to .
- Suppose and no finite is in . Let be total computable such that if , and is undefined otherwise. If , then . If , let be the least stage with ; then is the restriction of to , a finite function contained in , hence not in . So reduces to .
The converse also holds, with a suitable formulation: is c.e. if and only if 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).
The following index sets are not c.e.: ; ; ; ; for any index of a total function.
For , and with total, finiteness fails: these classes contain an infinite function, total or with infinite domain, but no finite function. For and , monotonicity fails: the nowhere defined function belongs to the class, and its extension the constant function 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 — 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
Show that there is no algorithm which, given and , decides whether .
Solution
Fix an index of the nowhere defined function. If equality were decidable, the set would be computable. It is an index set, non-trivial since it contains and no index of the constant function . This contradicts Theorem 6.3.
Is c.e.?
Solution
No. It is an index set, and monotonicity fails: the function defined only at belongs to the class, and its extension defined at and does not. By Theorem 6.5, the set is not c.e.
Show that is not c.e.
Solution
It is an index set. Monotonicity fails: the nowhere defined function has the computable domain , while its extension if , undefined otherwise, is partial computable with domain , 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.