• No results found

Recursive and recursively enumerable languages

In document Complexity of Algorithms (Page 42-47)

Let Σ be a finite alphabet that contains the symbol “”. We will allow as input for a Turing machine words that do not contain this special symbol: only letters from Σ0= Σ\ {∗}.

We call a function f : Σ

0Σ0recursive orcomputable if there exists a Turing machine

that for any inputx∈Σ

0 will stop after finite time withf(x) written on its first tape. (We

have seen in the previous section that we can assume without loss of generality that the Turing machine has only one tape.)

The notions of recursive, as well as that of “recursively enumerable” and “partial recur- sive” defined below can be easily extended, in a unique way, to functions and sets over some countable sets different from Σ

0, like the set of natural numbers, the setN∗ of finite strings

of natural numbers, etc. The extension goes with help of some standard coding of, e.g., the set of natural numbers by elements of Σ

0. Therefore even though we define these notions

only over Σ

0, we sometimes use them in connection with function defined over other domains.

3.2. RECURSIVE AND RECURSIVELY ENUMERABLE LANGUAGES 37 We call a language Lrecursiveif its characteristic function

fL(x) =

(

1, ifx∈ L, 0, otherwise,

is recursive. Instead of saying that a language L is recursive, we can also say that the property defining L is decidable. If a Turing machine calculates this function then we say that it decidesthe language. It is obvious that every finite language is recursive. Also if a language is recursive then its complement is also recursive.

Remark 3.2.1 It is obvious that there is a continuum of languages (and so uncountably many) but only countably many Turing machines. So there must exist non-recursive lan- guages. We will see some concrete languages that are non-recursive.

We call the languageLrecursively enumerableifL=or there exists a recursive function

f such that the range of f is L. This means that we can enumerate the elements of L: L={f(w0), f(w1), . . .}, when Σ0={w0, w1, . . .}. Here, the elements ofLdo not necessarily

occur in increasing order and repetition is also allowed.

We give an alternative definiton of recursively enumerable languages through the following lemma.

Lemma 3.2.1 A languageL is recursively enumerable iff there is a Turing machineT such that if we write xon the first tape of T the machine stops iffx∈ L.

Proof. Let L be recursively enumerable. We can assume that it is nonempty. LetL be the range off. We prepare a Turing machine which on inputxcalculatesf(y) in increasing order ofy∈Σ

0 and it stops whenever it finds ay such thatf(y) =x.

On the other hand, let us assume thatLcontains the set of words on which T stops. We can assume that L is not empty anda∈ L. We construct a Turing machineT0 that, when

the natural number iis its input it simulatesT on inputxwhich is the (i− b√ic)2-th word

of Σ

0, fori steps. If the simulated T stops then T0 ouputsx. Since every word of Σ0 will

occur for infinitely many values ofithe range of T0will beL. ¤

There is nothing really tricky about the function (i− b√ic)2; all we need is that for

i= 0,1,2, . . . its value assumes every non-negative integer infinitely many times. The tech- nique used in this proof, that of simulating infinitely many computations by a single one, is sometimes called “dovetailing”.

Now we study the relationship between recursive and recursively enumerable languages. Lemma 3.2.2 Every recursive language is recursively enumerable.

recursive

co-

recursively

enum

recursively

enum

Figure 3.1: The classes of recursive, recursively enumerable and co-recursively enu- merable languages

Proof. This is clear if the language Lis empty. We can change the Turing machine that decidesf to output the input if the intended output is 1, and to output some arbitrary fixed

a∈ Lif the intended output is 0. ¤

The next theorem characterizes the relation of recursively enumerable and recursive lan- guages.

Theorem 3.2.3 A languageLis is recursive iff both languagesL andΣ

0\ Lare recursively

enumerable.

Proof. IfLis recursive then its complement is also recursive, and by the previous lemma, it is recursively enumerable.

On the other hand, let us assume that both L and its complement are recursively enu- merable. We can construct two machines that enumerate them, and a third one simulating both that detects if one of them lists x. Sooner or later this happens and then we know

wherexbelongs. ¤

Let us call a languageco-recursively enumerable if its complement is ecursively enumer- able. Figure 3.1 is worth to remember: it shows the relationship between the classes of recursive, recursively enumerable and co-recursively enumerable. But is this picture correct, i.e., do the four areas shown all contain languages? It is clear that the class of recursively enumerable languages is countable, so there must be languages that are neither recursively enumerable nor co-recursively enumerable (see also exercise 3.4.3. What is much less obvious is that there are recursively enumerable languages that are not recursive, since both classes are countable. The construction of a such a language is our next goal.

3.2. RECURSIVE AND RECURSIVELY ENUMERABLE LANGUAGES 39 LetT be a Turing machine with k tapes, and letLT be the set of those words x∈Σ0

words for whichT stops when we writexonall of its tapes.

Theorem 3.2.4 If T is a universal Turing machine with k+ 1 tapes thenLT is recursively

enumerable, but it is not recursive.

Proof. The first statement follows from Lemma 3.2.2. We prove the second statement, for simplicity, fork= 1.

Let us assume, by way of contradiction, that LT is recursive. Then Σ0\ LT would be

recursively enumerable, so there would exist a 1-tape Turing machine T1 that on input x

would stop iff x6∈ LT. The machineT1 can be simulated on T by writing an appropriate

programpon the second tape of T. Then writingpon both tapes of T, it would stop ifT1

would stop because of the simulation. The machine T1 was defined, on the other hand, to

stop onpif and only ifT does not stop with inputpon both tapes (i.e. whenp6∈ LT). This

is a contradiction. ¤

This proof uses the so calleddiagonalization technique originating from set theory (where it was used by Cantor to show that the set of all real numbers is not countable). The technique forms the basis of many proofs in logic, set-theory and complexity theory. We will see more of these in what follows.

There is a number of variants of the previous result, asserting the undecidability of similar problems.

LetT be a Turing machine. The halting problem forT is the problem to decide, for all possible inputs x, whether T halts on x. Thus, the decidability of the halting problem of

T means the decidability of the set of thosexfor which T halts. We can also speak about the halting problem in general, which means that a pair (T, x) is given whereT is a Turing machine (given by its transition table) and xis an input.

Theorem 3.2.5 There is a 1-tape Turing machine whose halting problem is undecidable.

Proof. Suppose that the halting problem is decidable for all one-tape Turing machines. Let

T be a 2-tape universal Turing machine and let us construct a 1-tape machineT0similarly to

the proof of Theorem (0.2) (withk= 2), with the difference that at the start, we write the

i-th letter of word xnot only in cell 4ibut also in cell 4i−2. Then on an inputx, machine

T0will simulate the work ofT, when the latter starts withxon both of its tapes. Since it is

undecidable whetherT halts for a given input (x, x), it is also undecidable aboutT0 whether

The above proof, however simple it is, is the prototype of a great number of undecidability proofs. These proceed by taking any problem P1 known to be undecidable (in this case,

membership inLT) and showing that it can bereduced to the problem P2 at hand (in this

case, the halting problem ofT0). The reduction shows that ifP2 is decidable then so isP1.

But since we already know that P1 is undecidable, we conclude that P2 is undecidable as

well. The reduction of a problem to some seemingly unrelated problem is, of course, often very tricky.

A description of a Turing machine is the listing of the sets Σ, Γ (where, as before, the elements of Γ are coded by words over the set Σ0), and the table of the functions α, β, γ.

Corollary 3.2.6 It is algorithmically undecidable whether a Turing machine (given by its description) halts on the empty input.

Proof. LetT be a Turing machine whose halting problem is undecidable. We show that its halting problem can be reduced to the general halting problem on the empty input. Indeed, for each inputx, we can construct a Turing machineTx which, when started with an empty

input, writesxon the input tape and then simulatesT. If we could decide whetherTxhalts

then we could decide whetherT halts onx. ¤

Corollary 3.2.7 It is algorithmically undecidable whether for a one-tape Turing machineT

(given by its description), the setLT is empty.

Proof. For a given machineS, let us construct a machineT that does the following: it first erases everything from the tape and then turns into the machine S. The description of T

can obviously be easily constructed from the description ofS. Thus, ifS halts on the empty input in finitely many steps thenT halts on all inputs in finitely many steps, henceLT = Σ0

is not empty. IfS works for infinite time on the empty input then T works infinitely long on all inputs, and thus LT is empty. Therefore if we could decide whetherLT is empty we

could also decide whetherS halts on the empty input, which is undecidable. ¤ Obviously, just as its emptyness, we cannot decide any other propertyP of ofLT either

if the empty language has it and Σ

0 has not, or vice versa. Even a more general negative

result is true. We call a property of a languagetrivialif either all languages have it or none. Theorem 3.2.8 Rice’s Theorem For any non-trivial language-propertyP, it is undecidable whether the languageLT of an arbitrary Turing machineT (given by its description) has this

3.3. OTHER UNDECIDABLE PROBLEMS 41

In document Complexity of Algorithms (Page 42-47)