Programs have semantic and syntactic properties. For example, a syntactic property of a certain program could be that it contains a loop, while a semantic property could be that it halts. A trivial property is satisfied by all programs or none. For example, the property "halts" is non-trivial, as it is satisfied by some programs and not by others. The property "domain has zero or more elements" is trivial, as it is satisfied by all programs. According to Rice's theorem, non-trivial semantic properties of a program are undecidable. The theorem is named after Henry Gordon Rice, who proved it in his doctoral dissertation of 1951 at Syracuse University.
Suppose that we have a set of all programs with a particular non-trivial semantic property. We know that there exists a program
and a program
. Hence, if
were decidable, there would be a function
which yields
if
and
if
. Per Kleene's recursion theorem, given a function
, a fixed point of
is an index
(in an admissable numbering
) such that
. Roger's fixed point theorem states that if
is a total computable function, then it has a fixed point. Now consider the program
. If
, then
, and per the fixed point theorem
. However,
, but
- a contradiction. On the contrary, if
, then
, and per the fixed point theorem
. However,
, but
- a contradiction again. Therefore,
is undecidable.
A more general version of this claim is the Rice-Shapiro theorem. While Rice's theorem proves that all non-trivial semantic property is undecidable (i.e. there is no algorithm that can decide whether a program has a certain non-trivial semantic property and halt), the Rice-Shapiro demonstrates that finitary properties are recursively enumerable (i.e. there is an algorithm which decides if a program has a property which depends on a finite number of inputs by either accepting or diverging). Formally speaking, the The Rice-Shapiro theorem states that given a recursively enumerable set which contains the indices of programs with a certain property, then for any program
,
if and only if there exists a finite function
such that
.
A more elementary variant of this theorem states that if the set is recursively enumerable, then for every
, there is an
with
and
is finite. The proof of this theorem is more elementary: Suppose there is a function
such that
if
and diverges otherwise. Then, by applying the recursion theorem, there is a program
such that
computes
if
takes more than
steps to halt. Then, if
, then then
diverges and
for all
, but
- contradiction. On the other hand, if
, then
and
is defined for finitely many
, hence
is finite. If
is defined, then
, and
is a finite subset of
.
A corollary of this result is that if is an always-diverging program, then
implies that
, and further if
, then
, where
is the set of tuples of programs and inputs on which they halt.
