Toc
Toc
The input to a Turing machine is a string. Turing machines themselves can be written as
strings. Since these strings can be used as input to other Turing machines. A “Universal Turing
machine” is one whose input consists of a description M of some arbitrary Turing machine, and
some input w to which machine M is to be applied, we write this combined input as M + w. This
produces the same output that would be produced by M. This is written as
Universal Turing Machine (M + w) = M (w).
As a Turing machine can be represented as a string, it is fully possible to supply a Turing
machine as input to itself, for example M (M). This is not even a particularly bizarre thing to do for
example, suppose you have written a C pretty printer in C, then used the Pretty printer on itself.
Another common usage is Bootstrapping—where some convenient languages used to write a
minimal compiler for some new language L, then used this minimal compiler for L to write a new,
improved compiler for language L. Each time a new feature is added to language L, you can
recompile and use this new feature in the next version of the compiler. Turing machines sometimes
halt, and sometimes they enter an infinite loop.
A Turing machine might halt for one input string, but go into an infinite loop when given
some other string. The halting problem asks: “It is possible to tell, in general, whether a given
machine will halt for some given input?” If it is possible, then there is an effective procedure to look
at a Turing machine and its input and determine whether the machine will halt with that input. If
there is an effective procedure, then we can build a Turing machine to implement it. Suppose we
have a Turing machine “WillHalt” which, given an input string M + w, will halt and accept the string
if Turing machine M halts on input w and will halt and reject the string if Turing machine M does not
halt on input w. When viewed as a Boolean function, “WillHalt (M, w)” halts and returns “TRUE” in
the first case, and (halts and) returns “FALSE” in the second.
Theorem
Turing Machine “WillHalt (M, w)” does not exist.
Proof: This theorem is proved by contradiction. Suppose we could build a machine “WillHalt”.
Then we can certainly build a second machine, “LoopIfHalts”, that will go into an infinite loop if
and only if “WillHalt” accepts its input:
Function LoopIfHalts (M, w):
if WillHalt (M, w) then
while true do { }
else
return false;
We will also define a machine “LoopIfHaltOnItSelf” that, for any given input M, representing a
Turing machine, will determine what will happen if M is applied to itself, and loops if M will halt in
this case.
Function LoopIfHaltsOnItself (M):
return LoopIfHalts (M, M):
Finally, we ask what happens if we try:
Func tion Impos sible:
return LoopIfHaltsOnItself (LoopIfHaltsOnItself):
This machine, when applied to itself, goes into an infinite loop if and only if it halts when
applied to itself. This is impossible. Hence the theorem is proved.
Implications of Halting Problem
Programming
The Theorem of “Halting Problem” does not say that we can never determine whether or not
a given program halts on a given input. Most of the times, for practical reasons, we could eliminate
infinite loops from programs. Sometimes a “meta-program” is used to check another program for
potential infinite loops, and get this meta-program to work most of the time.
The theorem says that we cannot ever write such a meta-program and have it work all of the
time. This result is also used to demonstrate that certain other programs are also impossible.
The basic outline is as follows:
(i) If we could solve a problem X, we could solve the Halting problem
(ii) We cannot solve the Halting Problem
(iii) Therefore, we cannot solve problem X
3. Subroutines
Y
UNDECIDABILITY
Recursive Languages:
Universal
Language:
Undecidability of Universal Language:
Problem -Reduction :
If P1 reduced to P2,
Then P2 is at least as hard as P1.
Theorem: If P1 reduces to P2 then,
• If P1 is undecidable the so is P2.
• If P1 is Non-RE then so is P2.
Post's Correspondence Problem (PCP)
Because
i xi yi
1
2
3
i xi yi
1
2
This can be proved as follows. cannot be chosen at the start, since than the LHS and RHS would
differ in the first symbol ( in LHS and in RHS). So, we must start with . The next pair must be
so that the 3 rd symbol in the RHS becomes identical to that of the LHS, which is a . After this
step, LHS and RHS are not matching. If is selected next, then would be mismatched in the 7 th symbol
( in LHS and in RHS). If is selected, instead, there will not be any choice to match the both side in
the next step.
i xi yi
1 1 101
2 10 00
3 011 11
Proposition Any PCP instance over an alphabet with is equivalent to a PCP instance over an
alphabet with
Proof : Let
Consider We can now encode every as any PCP instance over will now
have only two symbols, 0 and 1 and, hence, is equivalent to a PCP instance over
Theorem : PCP is undecidable. That is, there is no algorithm that determines whether an arbitrary Post
Correspondence System has a solution.
Proof: The halting problem of turning machine can be reduced to PCP to show the undecidability of PCP. Since
halting problem of TM is undecidable (already proved), This reduction shows that PCP is also undecidable. The
proof is little bit lengthy and left as an exercise.
We can use the undecidability of PCP to show that many problem concerning the context-free languages are
undecidable. To prove this we reduce the PCP to each of these problem. The following discussion makes it
clear how PCP can be used to serve this purpose.
Let be a Post Correspondence System over the alphabet . We construct
two CFG's Gx and Gy from the ordered pairs x,y respectively as follows.
and
where
and
it is clear that the grammar generates the strings that can appear in the LHS of a sequence while solving
the PCP followed by a sequence of numbers. The sequence of number at the end records the sequence of
strings from the PCP instance (in reverse order) that generates the string. Similarly, generates the strings
that can be obtained from the RHS of a sequence and the corresponding sequence of numbers (in reverse
order).
Now, if the Post Correspondence System has a solution, then there must be a sequence
In this case
Hence , and implying
Conversely, let
Hence, w must be in the form w1w2 where and w2 in a sequence (since, only that kind of
It is interesting to note that we have here reduced PCP to the language of pairs of CFG,s whose intersection is
nonempty. The following result is a direct conclusion of the above.
Theorem : Given any two CFG's G1 and G2 the question "Is " is undecidable.
Proof: Assume for contradiction that there exists an algorithm A to decide this question. This would imply that
PCP is decidable as shown below.
For any Post Correspondence System, P construct grammars and by using the constructions
elaborated already. We can now use the algorithm A to decide whether and
Thus, PCP is decidable, a contradiction. So, such an algorithm does not exist.
If and are CFG's constructed from any arbitrary Post Correspondence System, than it is not difficult to
show that and are also context-free, even though the class of context-free languages are not
closed under complementation.
and their complements can be used in various ways to show that many other questions
related to CFL's are undecidable. We prove here some of those.
Theorem : Foe any two arbitrary CFG's the following questions are undecidable
i. Is
ii. Is
iii. Is
Proof :
i. If then,
Since, and are CFl's and CFL's are closed under union, is also context-
ii.
Let P be any arbitrary Post correspondence system and and are CFg's constructed from the pairs of
strings.
PCP. Hence, contains all but those strings representing the solution to the PCP.
It is now obvious that if and only if the PCP has no solutions, which is already proved to be
iii.
Let be a CFG generating the language and G2 be a CFG generating
where and are CFG.s constructed from same arbitrary instance of PCP.
iff
i.e. iff the PCP instance has no solutions as discussed in part (ii).
Proof : Consider an arbitrary instance of PCP and construct the CFG's and from the ordered pairs of
strings.
where
This constructions gives a reduction of PCP to the -------- of whether a CFG is ambiguous, thus leading to the
undecidability of the given problem. That is, we will now show that the PCP has a solution if and only if G is
ambiguous. (where G is constructed from an arbitrary instance of PCP).
is a solution to the PCP. Hence the same string of terminals has two derivations. Both these
derivations are, clearly, leftmost. Hence G is ambiguous.
If It is important to note that any string of terminals cannot have more than one derivation in and
Because, every terminal string which are derivable under these grammars ends with a sequence of integers
This sequence uniquely determines which productions must be used at every step of the derivation.
Hence, if a terminal string, , has two leftmost derivations, then one of them must begin with the
step.
In both derivations the resulting string must end with a sequence for same The reverse of
this sequence must be a solution to the PCP, because the string that precede in one case is
and in the other case. Since the string derived in both cases are identical, the
sequence