There is a very general formulation of the result of Rice-Shapiro in terms of effective domains, but we will see only the instance which is relevant for this course. We will not see the proof because it involves topological techniques that are beyond the scope of this course.

**Theorem** (Rice-Shapiro)
Let p be a property of recursively enumerable languages,
i.e. p: RE -> {true,false}.
Let X = {e(M) | M is a TM and p(L(M)) holds}.
Then X is RE iff there exists a recursively enumerable set of
indexes I, and a sequence of finite sets indexed on I,
{L_{i} | i in I} such that

{L in RE | p(L) holds} = unionWere UC(L) (upward-closure of L) is the set of all supersets of L, i.e._{i in I}UC(L_{i}).

UC(L) = {L' | L is a subest of L'}.One part of this theorem is the so-called "Lemma of effective discontinuity" (it's called "lemma" because it is used to prove the theorem).

**Lemma** (Effective discontinuity)
Let p: RE -> {true,false}.
Let X = {e(M) | M is a TM and p(L(M)) holds}.
If X is RE then

- p is upward-closed, i.e. if p(L) holds, and L is a subset of L', then p(L') holds too.
- p is finitely provable, i.e. if p(L) holds, then there is a finite subset L' of L such that p(L') holds too.

Again, we will not see a formal proof of thic lemea`since it requires
notions from topology theory.
However the intuitive explanation is the following.
Suppose that X is RE. Then we have a machine M_{X} that,
given as input the (encoding of) another machine M, it is able to
terminate with answer "yes" iff L(M) satisfies p.
Since the decision of saying "yes" is taken after a finite
number of steps, it must be based only on a finite subset of the
set L(M) (because in finite time we can test only a finite number of
strings). This justifies Point 2 in the lemma above.
As for Point 1, note that if the machine says "yes" on M, then it must say
"yes" also on any other machine M' whose language L(M') is a superset of
L(M).
In fact, we have no way to know (in general) that a string does not belong to
L(M) (M might loop on the strings which are not in L(M)).
Hence the strings which are in L(M') and not in L(M) cannot change the
decision of M_{X} of saying "yes".

It should be clear that the Theorem of Rice (Lecture 36) is an immediate consequence of the theorem of Rice-Shapiro. In fact, if the set X defined above is Recursive, then both X and the complement of X are RE. By the lemma of effective discontinuity, both p and the negation of p should then be upward closed. We have two possibilities:

- p holds on the emptyset: then p holds on every language (p is always true).
- p does not hold on the emptyset. Then the negation of p holds on the emptyset, and therefore on every language (p is always false).

- L
_{1}= {e(M) | L(M) is finite} is not RE (contradicts Point 1 in the lemma) - L
_{2}= {e(M) | L(M) is infinite} is not RE (contradicts Point 2 in the lemma) - L
_{3}= {e(M) | L(M) contains x_{0}} (where x_{0}is a given string) is RE. In fact p holds exacly on the set UC({x_{0}}). - L
_{4}= {e(M) | L(M) does not contain x_{0}} is not RE (contradicts Point 1 in the lemma). - L
_{5}= {e(M) | L(M) is recursive} is not RE (contradicts Point 1 in the lemma, because the emptyset is recursive and other languages are not). - L
_{6}= {e(M) | L(M) is context-free} is not RE (same reason as for L_{5}). - L
_{7}= {e(M) | L(M) is regular} is not RE (same reason as for L_{5}). - L
_{8}= {e(M) | L(M) is not recursive} is not RE (contradicts Point 2 in the lemma, because all the finite sets are recursive). - L
_{9}= {e(M) | L(M) is not context-free} is not RE (same reason as for L_{8}). - L
_{10}= {e(M) | L(M) is not regular} is not RE (same reason as for L_{8}).

In general it is not possible to semidecide whether a given language is context-free or not. In other words, there exist no general method to construct a CF grammar for any CF language, and there exist no general method able to prove that a langauge is not CF for any not-CF langauge.The above negative result depends critically, of course, on the fact that we allow here the most general kind of definitions for languages (Turing machines). If we would fix the format of the specification (for instance, if we would allow only certain kinds of recursive definitions) then the problem "is L CF?" might become semidecidable or even decidable.

It should be remarked that these results regard "extensional properties" of programs, (i.e. properties of the input-output relation computed by a program), and not the "intentional properties" (i.e. properties of the code). The latter are in general decidable.

Let us consider in detail two main negative results for programming languages related to the theorem of Rice-Shapiro. In the following, we assume the programming language to be fixed, for intance C.

**Termination**. The problem "given a program P, does P terminate on every input?" is not semidecidable. In fact, this is equivalent to saying that the language {e(P) | L(P) = Sigma^{*}} is not RE. (The proof is left as an exercise.)The problem "given a program P, does P terminate on input x

_{0}?" (where x_{0}is a given string) is semidecidable, but not decidable (Proof: from the results for L_{3}and L_{4}above.) This is the so-called "halting problem".**Correctness**. The problem "given a program P, does P compute the relation r_{0}?" (where r_{0}- the specification - is a given relation on string) is not semidecidable in general. In fact, this is equivalent to saying that the language {e(P) | {x#y| x,y in Sigma^{*}and x r_{0}y } is a subset of L(P)} is not RE. The symbol "#" here is a special symbol not contained in Sigma which serves to separate the input from the output. The proof is left as an exercise.The problem becomes semidecidable (but not decidable) if r

_{0}is finite, i.e. if the correctness has to be tested only on a finite number of inputs.