Toc Unit V
Toc Unit V
Toc Unit V
COURSE CODE:CS332
COURSE NAME:THEORY OF COMPUTATION
DEPT :CSE
ACADEMIC YEAR:2005-2006 SEMESTER/YEAR:V/3
UNIT – V
UNDECIDABILITY
CONTENTS
§ PROPERTIES OF RECURSIVE AND RECURSIVELY ENUMERABLE
LANGUAGES
§ UNIVERSAL TURING MACHINE AS AN UNDESIDABLE
PROBLEM
§ UNIVERSAL LANGUAGES
§ RICE’S THEOREM
v PROPERTIES OF RECURSIVE AND RECURSIVELY ENUMERABLE
LANGUAGES
Ø After having an introduction about recursive and recursively enumerable languages, this unit
will further deal with properties of recursive and recursively enumerable languages, and relate
the concept of un decidability with them.
q PROBLEMS
Ø We usually associate problems with questions such as “Does there exist a solution for this?”
etc. but we have seen that Turing Machines are capable of solving only the membership problem
i.e. “Given a word w and a language L, does w belong to L?”.
Ø It is important to understand that almost all instances of problems can be expressed as a
membership problem of some language.
Ø For e.g. the question “How many primes exist below a given number n” can be modified as
“Is x a member of L” where 1<=x<=n and L represents the language of primes.
Thus decision problems are those problems which either “yes” or “no” as the answer.
Ø Recursively enumerable (r.e.) languages are those languages whose Turing machines may or
may not halt on all inputs i.e. they may enter into an infinite loop.
Ø This suggests the fact that there does not exist a general algorithm for all instances of the
problem, which clearly distinguishes between the “yes” and the “no” instances of the problem.
Ø Thus problems represented by recursive languages are the only decidable problems i.e. there
exists a Turing machine which will always answer a yes or no to the decision problem.
Ø All the other problems do not have an algorithm and hence a Turing machine which can
accept all instances of the problem and clearly answer yes or no.
Ø It is important to distinguish between a particular instance of a problem and all instances of
the problem.
Ø For e.g. it is a well known fact that halting problem is un decidable, that is, there does not
exist a Turing machine which when given the encoding of any Turing machine and its input
(you’ll subsequently learn how to encode a Turing machine as a string) can always answer a
“yes” or “no”. but it is possible to construct a Turing machine which can accept a particular
Ø Turing machine as input and decide whether it halts on a given input or not. As logic follows,
it can be understood that you cannot write a program which when given any other program and
its input, can state if it enters an infinite loop or not; but it is possible to write a program to
accept a specific type of program and state if it halts on given inputs.
Ø The following theorems will prove certain properties of recursive and recursively enumerable
languages.
ü THEOREM
The complement of a recursive language is recursive.
§ Proof:
Ø Let M be the Turing Machine that accepts the recursive language L, and in order to prove the
theorem, we shall construct another Turing Machine M’ which shall accept L’.
Ø Since the languages they accept are complementary, the behavior of these Turing Machines
will also be the reverse of each other.
Ø Since L is a recursive language, the Turing Machine M will halt on all inputs, whether or not
it accepts the input.
Ø The construction of the machine M’ will be such that when a common input string is given to
both M and M’, M’ will reject the input and halt whenever M accepts it, and will accept the input
and halt whenever M rejects it. Thus we see that the machine M’ halts on both “yes” and “no”
instances of the problem i.e. on all inputs.
q THEOREM
The union of two recursive languages is recursive. The union of two recursively enumerable
languages is recursively enumerable.
§ Proof:
Ø Let L1 and L2 be the two recursive languages accepted by the Turing Machines M1 and M2.
We construct M, which first simulates M1.
Ø If M1 accepts, then M accepts. If M1 rejects, then M simulates M2 accepts if and only if M2
accepts. Since both M1 and M2 are recursive languages, and each of them will halt on any input
string, M is guaranteed to halt.
Ø This shows that the language corresponding to the Turing Machine M which is L1 L2 is
recursive. If we adopt a similar method for recursively enumerable languages, the Turing
Machine M cannot be guaranteed to halt, since both M1 and M2 may or may not halt. Hence our
construction of M consists of 2-tapes, and in the 1st tape the Turing Machine M1 is simulated
and on the second tape M2 is simulated.
Ø Though there is a possibility that either of them, if not both of them, may enter into an
infinite loop, the Turing Machine M as a whole reaches the halting state if and only if at least one
of them reach their halting states.
Ø Thus we see that this machine accepts L1 L2 where L1 and L2 are recursively enumerable
languages.
q THEOREM
If a language L and its complement L’ are both recursively enumerable, then L (and hence L’) is
recursive.
§ Proof:
Ø We shall consider two Turing machines M1 and M2 constructed to recognize the languages
L and L . We shall construct a new Turing Machine M which does the following:
o Simulate both M1 and M2 simultaneously for any input string.
o M accepts the input string if M1 accepts the same input string.
o M rejects the input string if M2 accepts the same input string and vice-versa. This is done
because M2 corresponds to the complementary language of L.
Exactly one of the Turing Machines M1 or M2 will answer a “yes” and never both. This gives
the guarantee that M will definitely come to a halt.
Ø We can observe that the Turing Machine will surely come to a halt in atleast one of the cases,
even if the head of the other tape has entered into an infinite loop because of non-acceptance.
Since we now have a Turing Machine M which will surely come to a halt, one of the languages
is recursive, and hence by the previous theorem, its complementary language is also recursive.
• Encode the Turing Machine M’ using a standard method to convert it into a string which can
be fed as input into the tape of the Universal Turing Machine.
• Provide the input string w which would have been read by the TM M’ along with the
encoding of M’.
M = ( Q,{0,1},{0,1,B}, , q1 ,B ,{q2})
Ø Be a turning machine with input alphabet {0,1} and the blank as the only additional tape
symbol. We further assume that Q = {q1,q2 …….,qn } is the set of states, and that q2 is the only
final state. Also, there is no need for more than one final state in any TM, since once it accepts it
may as well halt.
Ø It is convenient to call symbols 0,1, and B by the synonyms X1, X2, X3 respectively. We
also give directions L and R the synonym D1 and D2 , resp.
Ø Then a generic move (qI , Xj ) = (qk ,Xl , Dm) is encoded by the binary string.
0i 1 0j 1 0k 1 0l 1 0m
Ø Where each codei is a string of the above form and each move of M is encoded by one of the
codei ‘s. The moves need not be in any particular order, so each TM actually has many codes.
Any such code for M will be denoted <M>.
Ø Every binary string can be interpreted as the code for at most one TM; many binary strings
are not the code of any TM.
Ø To see that decoding is unique, note that no string has two 1’s in a row, so the codei ‘s can be
found directly. If a string fails to begin and end with exactly three 1’s, has three 1’s other than at
the end, or has two pair of 1’s with other than five blocks of 0’s in between, then the string
represents no TM.
Hence <M,w> will be a string denoting the encoding of the Turing Machine M along with its
input string w.
• If the j,jth entry is a 0 it means that the wj th is not accepted by Ld by virtue of construction
of the table. But by definition of Ld, the j,jth entry should have been 1 if wj th is not accepted.
• If the j,jth entry is a 1 it means that the wj th is accepted by Ld by virtue of construction of
the table. But by definition of Ld, the j,jth entry should have been 0 if wj
th is accepted.
This argument gives rise to a contradiction and hence we see that the problem of deciding
whether a given string can be accepted by a given Turing Machine is unacceptable.
• Proof:
Ø We shall prove that Lu is recursively enumerable by constructing a Turing Machine which
accepts strings of the form <M,w>, and the proof following the detailed construction of the
Turing Machine will prove that the language Lu is recursively enumerable.
Our construction of a TM M1 for recognizing Lu is as follows:
It consists of 3 tapes each one performing a different function.
The first tape is used to store the encoding of M which is <M> and this decodes the functions
of M. It initially reads the string enclosed between the three 1’s, which mark the beginning and
end of the encoding of the Turing Machine.
The second tape initially contains the input to the TM M, which is w. The head on the second
tape performs the same function as that of the head of M.
The third tape of M1 stores the current state of M, during simulation, in the unary format. For
e.g. state qj is stored as 0j.
2) Initialize tape 2 to contain w, the portion of the input beyond the second block of three 1 's.
Initialize tape 3 to hold a single 0, representing q1. All three tape heads are positioned on the
leftmost symbols. These symbols may be marked so the heads can find their way back.
3) If tape 3 holds 00, the code for the final state, halt and accept.
4) Let X j be the symbol currently scanned by tape head 2 and let 0j be the current contents of
tape 3. Scan tape 1 from the left end to the second 111, looking for a substring beginning
110i10i1. If no such string is found, halt and reject; M has no next move and has not accepted. If
such a code is found, let it be 0i10I 10k 10l10m. Then put 0k on tape 3, print XI on the tape cell
scanned by head 2 and move that head in direction Dm , Note that we have checked in (1) that
1 l 3 and 1 m
2. Go to step (3).
Ø It is straightforward to check that M1 accepts <M, w> if and only if M accepts w. It is also
true that if M runs forever on w, M 1 will run forever on <M, w> and if halts on w without
accepting, M1 does the same on (M, w).
Ø Hence, the above construction is sufficient to prove that there exists a Turing Machine for Lu
In order to prove that Lu is recursive enumerable we make use of our previous result where we
proved that Ld is not recursive enumerable.
Ø Since Ld is not recursively enumerable, its complement d L is not recursive. Note that d L =
{wi | Mi accepts wI}. We can prove the universal language d L = {<M, w> I M accepts w} not to
be recursive by reducing d L to Lu. Thus Lu is an example of a language that is recursively
enumerable but not recursive. Also d L is another example of such a language.
• Proof
Ø Suppose there existed a Turing Machine M for recognizing Lu, then we could recognize d L
as follows. Given string w in (0 + l)*, determine by an easy calculation the value of i such that w
= wi. Integer i in binary is the code for some TM Mi.
Ø Now we could feed the string <Mi,wI> to the TM M and it will accept the string iff Mi
would accept the input string wI. This is simply the membership problem of Ld, which was
proved to be un decidable and hence no algorithm/ Turing Machine exists to recognise Ld. Thus
our assumption of Lu being a recursive language is false and it is a recursively enumerable
language.
• Proof:
Ø In order to prove that non-trivial properties are undecidable let us consider a specific property
which does not contain (otherwise rename the complement of as ).
Ø Since is nontrivial, there exists a language L which satisfies the property . Let ML be a
TM accepting L. Suppose were decidable, then there exists an algorithm M accepting L . We
use ML and M to construct an algorithm for Lu as follows.
Ø First construct an algorithm A that takes <M, w> as input and produces <M' > as output,
where L(M') is' in if and only if M accepts w <M, w> is in Lu) .
Ø We may use the Turing Machine M to determine if L(M') is in . Since L(M') is in if and
only if <M , w> is in Lu, we have an algorithm for recognizing Lu, a contradiction .Thus must
be un decidable.
Examples of Undecidable properties:
1. Is a given language empty?
2. Is a given language finite?
3. Is a given language regular?
4. Is a given language context-free?
q Rice Theorem for recursively enumerable index sets
The condition under which a set L is r.e. is far more complicated. We shall show r .e. if and
only if satisfies the following three conditions.
1) If L is in and L L’, for some r.e. L’, then L’ is in (the containment property).
2) If L is an infinite language in , then there is a finite subset of L in ,
3) The set of finite languages in is enumerable, in the sense that there is a Turing machine that
generates the (possibly) infinite string code1#code2# ..., where codej is a code for the ith finite
language in (in any order). The code for the finite language {w1,w2, …..,wn} is just w1,
w2,……,wn.
1. If does not have the containment property, then L is not recursively enumerable.
2. If has an infinite language L such that no finite subset of L is in , then L , is not
recursively enumerable.
3. If L is recursively enumerable then the list of binary codes for the finite sets in is
enumerable.
§ Proof:
Ø We construct a TM M1 that recognizes <M> if and only if L(M) is in as follows. M1
generates pairs (i, j) using the pair generator. In response to (i, j), M1 simulates M2, which is an
enumerator of the finite sets in , for i steps.
Ø We know M2 exists by third condition. Let L1 be the last set completely printed out by M2.
Then simulate M for j steps on each word in L1. If M accepts all words in L1, then M1 accepts
<M>. If not, M1 generates the next (i,j)-pair.
Ø We shall next use the conditions (1) and (2) to show that L(M1) = L . If L is in L and let M
be any TM with L(M) = L. By the second condition there is a finite L’ L in . Let L’ be
generated after i steps of M2, and let j be the maximum number of steps taken by M to accept a
word in L’. Then when M1 generates (i, j), if not sooner, M1 will accept <M>
Conversely, suppose M1 accepts <M>. Then there is some (i, j) such that within j steps M
accepts every word in some finite language L’ such that M2 generates L’ within its first i steps.
Then L’ is in , and L’ L(M).