Decidable and Undecidable Problems
Decidable and Undecidable Problems
9. UNDECIDABILITY
9.1 Introduction
9.2 Decision Problems
9.3 Recursive and Recursively Enumerable Languages
9.3.1 Recursive languages
9.3.2 Recursively enumerable languages
9.4 Properties of Recursive Languages
9.5 The Diagonalization Language : A Non-RE Language
9.6 Universal Turing Machine (U) and Universal Language (LU)
9.6.1 Universal turing machine (U)
9.6.2 The universal language (LU)
9.7 Undecidable Problems
9.7.1 Reduction technique
9.7.2 Rice's theorem
9.7.3 Halting problem
9.8 Relation between Recursive, RE and Non-RE Languages
9.9 Post’s Correspondence Problem
9.9.1 Modified post’s correspondence problem
9.10 P and NP Problems
9.2 Theory of Computation
Undecidability 9.3
CHAPTER - 9
UNDECIDABILITY
9.1 INTRODUCTION
Example 9.1
That is an algorithm is exist for the problem to decide the answer as yes or no.
a) Halting Problem of TM. That is, given any TM M and any input string w, does
M halt on w?
We want to write a program which will correctly output an answer to the question
about termination (halting) of any given program.
This is called halting problem and since we can't develop an algorithm to solve
this problem, this problem is an undecidable problem.
b) Can you develop an algorithm which will correctly tell us when a person will
die? whatever you want may be taken as input.
Example 9.4
L = {aibjck : i x j = k and i, j, k > 1}.
An informal description of the idea behind a TM program:
(i) Preprocess the input string from left to right to ensure that it is a string of the
form a*b*c*. If it is not of this form, then reject.
(ii) Return to the left end of the input string.
(iii) Check an a and scan to the right until it meets a b. Move back and forth between
the b’s and the c’s, each time checking off one b and one c until all b’s are
checked.
(iv) Uncheck the checked b’s and repeat 3 if there is another a to check. If all a’s are
check, determine whether all c’s are also checked. If they are, then accept;
otherwise, reject.
9.3.2 Recursively Enumerable Languages
Definition : L is Recursively Enumerable (RE) if and only if there is a TM that semidecides L.
Let M = (Q, ∑, δ, S, H) be a Turing Machine
l Let ∑0 ⊆ ∑ – {g, } be an alphabet
b,→
l
h
Let L ⊆ ∑0* be a language
a,a
s l M semidecides L if, for all strings w ∈ ∑0*:
- either w ∈ L, in which case M halts on input w. (Starting the TM with
g, g configuration (S, w) causes the machine to halt)
g, g - or w ∉ L, in which case M does not halt (of course, it may stop or loop)
2
g, g
Example 9.5
g, g
L: {w ∈ {a,b}* : w contains at least one a}. The first TM semidecides L. (If w does not
contain an a, then M does not stop) Thus, L is RE.
9.8 Theory of Computation
The second TM decides L.
w
Yes No
M2
Theorem 4
Proof
Idea : Since L is recursive, there is a TM M that decides it. Make the rejected state of M a
nonhalting state.
Question:
Solution :
No.
Question :
Solution :
No.
Undecidability 9.11
Using previous encoding, we encoded the “i-th Turing machine” Mi as integer i, with code wi,
the i-th binary string. For invalid codes a TM halts immediately on any input, i.e., L(Mi)=φ.
The diagonalization language, Ld, is the set of strings wi such that wi∈L(Mi). That is,
Ld consists of all strings w such that the TM M whose code is w does not accept when given
w as input.
(iii). table contents, so-called the characteristic vector for the language L(M i); that is,
1 means that the word is accepted by Mi, and 0 means that it doesn’t.
wj = j →
1 2 3 4 …
1 0 1 1 0 …
2 1 1 0 0 …
Mi = i ↓
3 0 0 1 1 …
4 0 1 0 1 …
. . . . . . diagonal
The diagonal values tell whether M i accepts wj. To construct Ld, we complement the
diagonal. For example, for the table, the complemental diagonal would begin with string
1000…. Thus, Ld would contain w1=ε, not contain w2 through w 4, which are 0, 1, and 00, and
so on.
The complemental diagonal represents the characteristic vector of some language,
namely Ld, but not characteristic vector of any L(Mi) (it differs at least on 1 position with any
possible row in the table).
Thus, the complement of the diagonal cannot be the characteristic vector of any Turing
machine, i.e., wi∉L(Mi), thus it belongs to L d according to its definition.
Theorem
The diagonalization language Ld, is not a recursively enumerable language. That is, there is
not Turing machine that accepts Ld.
9.12 Theory of Computation
Proof
Suppose Ld is RE. Then Ld=H(M) for some TM M.
Since the input alphabet of M is Σ={0,1}, i.e. M would be on the list of TM’s we have
constructed, since it includes all TM’s with input alphabet {0,1}. Thus M is Mi for at least
one value of i. Let w i be the i-th string, i.e., wi is i in binary (and on diagonal). Question: is wi
in Ld?
(i) If w i is in Ld, then Mi accepts wi. But then, by definition of Ld, wi is not in Ld,
because L d contains only those wj (has value 1 in the table for Ld‘s row) such that
Mj does not accept wj (has value 0 in the table - negated diagonal 1).
(ii) If w i is not in Ld, then M i does not accept w i. Thus by definition of Ld, wi is in Ld.
Since wi cannot be at the same time in L d and not to be in Ld, we conclude that there is
a contradiction of our assumption that M exist. That is Ld is not RE.
9.6 UNIVERSAL TURING MACHINE (U) AND UNIVERSAL LANGUAGE (LU)
Each Turing machine appears to be specialized at solving one particular problem.
We know that we can ‘program’ computers to solve many different problems-they are
general-purpose programmable machines
Can we also ‘program’ a Turing machine?
Yes!
We will show that there are TM’s, universal TM’s, that can be programmed to solve
any problem that can be solved by any Turing machine.
9.6.1 Universal Turing Machine U:
Input to U: The encoding “M” of a TM M and the encoding “w” of a string w ∈ ∑*.
Behavior : U halts on input “M” “w” if and only if M halts on input w (U emulates M with
input w). How do we encode a Turing machine as a string?
Crucial assumptions: We require that there are no transitions from any of the halt states of
any given TM. Apart from the halt state, a given TM is total.
Encoding of TM’s and their input strings
Let M = (Q, {0, 1}, {0, 1, B}, δ, q1, B,{qn})
Where ∑ = {0, 1} - input alphabet
Γ = {0, 1, B} - tape symbol
Q = {q1, q2...... qn} - set of states
Undecidability 9.13
q1 = start state
qn = final state
Generic Move :
1. We call symbols 0, 1, B by X1, X 2, X3 respectively.
(i.e.,) 0 = X1
1 = X2
B = X3
2. The directions L and R are called by synonyms D1, D2 respectively.
(i.e.,) L = D 1
R = D2
3. The generic move.
δ(qi, Xj) = (qk, Xl, Dm) is encoded by the binary string has
0i 10j 10k 10l 10m ................ 1
The binary code of Turing Machine M is :
111 code 1 11 code211.... 11 coder 111 ................ 2
where each codei is of the form 1 .
4. Any such code of M is denoted by <M>
Note :
(i) Each decoding is unique, (because no string of the form 1. has two 1’s in a row, so
code is found directly.
(ii) If a string fails to begin and end with exactly three 1’s, the string represents no TM.
(iii) The pair M and w is represented by a string of the form 2 followed by w. It is denoted
as <M, w>
Example 9.6
Obtain the code for <M, 1011> where M = ({q1, q2, q3}, {0,1}, {0, 1, B}, δ, q, B, {q2})
have moves
δ(q1, 1) = (q3, 0, R)
δ(q3, 0) = (q1, 1, R)
δ(q3, 1) = (q2, 0, R)
δ(q3, B) = (q3, 1, L) (Nov/Dec 2003)
9.14 Theory of Computation
Solution :
1. We call tape symbols 0, 1, B by synonyms X1, X2, X 3 respectively.
i.e., 0 = X1
1 = X2
B = X3
2. We give directions L and R by synonyms D1, D 2 respectively.
L = D1
R = D2
3. Generic move δ(qi, Xj) = (qk, Xr, Dm) is encoded by binary string
0i 10j 10k 10l 10m
Separator
∴ for the given moves the binary coding is as follows:
δ(q1, 1) = (q3, 0, R) it is of the form
δ(q1, X2) = (q3, X1, D2) (because of synonyms)
∴ binary code is 01 102 103 101 102
Similarly for δ(q3, 0) = (q1, 1, R) is of form
δ(q3, X1) = (q1, X 2, D2)
binary code = 03101101102102
Similarly for δ(q3, 1) = (q2,0,R) is of form
δ(q3,X2) = (q2,X1, D2)
binary code is 03102102101102
Similarly for δ(q3,B) = (q3, 1, L) is of form
δ(q3, X3) = (q3, X 2, D1)
binary code is 0 3103103102101
∴ binary code of TM is
111 code1 11 code 2 11 code3 11 code 4 111
∴ <M, w> is represented as
111 code1 11 code2 11 code 3 11 code4 111w
Undecidability 9.15
M (encoded moves of M)
w
q
Finite control
of U
P1 Yes Yes P2
No No
Theorem
Proof
By simulation of the UTM by a multitape TM we showed that Lu is RE. Suppose that Lu were
recursive. Then by definition, its complement Lud would also be recursive. We prove by
reduction from Ld to Lud that Lud is not recursive.
Nonexisting M for Ld
Yes, the UTM U semidecides it. (since U halts on input “M” “w” whenever M halts on w).
Theorem
The halting problem is undecidable; that is
H={“M” “w” : TM M halts on string w} is not recursive.
Proof Idea
l Assume that H is recursive.
l By the definition of recursive languages, there is a TM MH that decides H
l Design a new TM that uses MH as a submachine to decide H1
l But this construction contradicts that nonrecursiveness of H1! Hence, H is not
recursive
l We say H1 is reduced to H
Proof
l Assume that H is recursive
l Then, there is a TM (or algorithm) MH that decides H; that is either MH (“M”
“w”) halts in state y, if M halts on w or MH (“M” “w”) halts in state n, if M does
not halt on w.
l We construct the following TM MH that decides H1. MH has the following
1 1
behavior.
(i) If an input string x is not the encoding of a TM, then it halts in state n.
(ii) If an input string x is the encoding of a TM M (x= “M”), then apply MH to
the input string x “x” (MH(x “x”))
If MH halts in state y, then M H halts in state y.
1
- x = “M”, for some TM M, and M does not halt on “M”. Then, M H(x “x”) halts
in state n.
By the construction of MH , MH also halts in state n
1 1
From the 9 possible ways to place a language L and its complement Ld in the above
diagram only 4 are possible:
Undecidability 9.21
(i). For recursive languages: both L and Ld are recursive, i.e., in the inner ring. Both
L and Ld are decidable.
(ii). For RE languages: L is RE but not recursive, and L d is not RE, i.e., one is in the
middle ring (L) and the other is in the outer ring (Ld). L is decidable and Ld is
undecidable.
(iii). For RE languages: L d is RE but not recursive, and L is not RE, i.e., one is in the
middle ring (Ld) and the other is in the outer ring (L). Ld is decidable and L is
undecidable.
(iv). For not RE languages: both L and L d are in the outer ring. Both L and Ld are
undecidable.
9.9 POST'S CORRESPONDENCE PROBLEM
An instance of Post's Correspondence Problem (PCP) consists of two lists A = w1, w2., ......,
wk and B = x1, x2,...... xk of strings over some alphabets ∑. This instance of PCP has a solution
if there is any sequence of integers i1, i2, ...... im, with m ≥ 1, such that
wi1, wi2, ......, w im = xi1, xi2, ........ xim.
The sequence i1, i2, ........ im is a solution to this instance of PCP.
Example 9.7
Let ∑ = {0, 1}. Let A and B be lists of three strings each, defined below in the Fig.PCP has
a solution 2,1,1,3.
List A List B
i wi xi
1 1 111
2 10111 10
3 10 0
Fig. An instance of PCP
Let m = 4, i1 = 2, i2 = 1, i3 = 1, i4 = 3. Now
w 2w1w1w3 = 101111110
x2x1x1x3 = 101111110
Represent the string wi on the top half and the string xi on the bottom half as:
10111 1 1 0
10 111 111 0
9.22 Theory of Computation
It is easy to verify the solution sequence beginning
10111 ...
10 .......
(v) Finally, once the accepting state has consumed all tape symbols, it stands alone as the
last ID on the B string. That is, the remainder of the two strings (the suffix of the B string that
must be appended to the A string to match the B string) is q#. We use the final pair:
List A List B
q## #
to complete the solution.
Example 9.8
Consider the Turing Machine M and w = 01, where M = ({q1, q2, q3}, {0,1}, {0,1,B}, δ, q1, B,
{q3}) and δ is given by
q3 – – –
Reduce the above problem to Post’s Correspondence Problem and find whether that PCP has
a solution or not.
Solution :
An instance of MPCP with lists A and B as follows with w = 01.
First pair → List A List B
# # q1 01 #
Note: # indicates blank in list A, #q1 01# indicates start state followed by w and blank.
Group I List A List B
0 0
1 1
# #
Note: Group I represents, each symbol belongs to Γ. ( i.e., ) X ∈ Γ .
Undecidability 9.25
0q1# q2 01
∵ δ ( q1 ,B ) = ( q2 ,1,L )
1q1# q211#
0q2 0 q3 00
∵δ ( q2 ,0 ) = ( q3 ,0,L )
1q2 0 q310
If the transition is δ ( q1 ,1) = ( q2 ,0,L ) , that is the head is moved to the left side of the tape,
then 2 steps are constructed . In list A symbol of ∑-state-input (i.e) [ 0q1 1, 1q11 where
∑={0,1} and in list B state - symbol of ∑-symbol written (i.e) [q200, q2 10 where ∑={0,1}
If the transition is δ ( q2 ,B ) = ( q2 ,0,R ) , that is on blank , an # symbol is added at the end
of list A and list B instances.
( q1 ,0IV
δGroup ) =table.
( qSimilarly
2 ,1,R )
List A other instances
List B of list A and list B are constructed from the given transition
q3 ## #
Group III List A List B
0q3 0 q3
0q31 q3
1q3 0 q3
1q31 q3
0q3 q3
1q3 q3
q3 0 q3
q31 q3
q1 01
1 q2 1
10 q1 B
1 q2 01
q3 101
q3 01 q3 1 q3
Since q3 is a final state, a solution to the instance of MPCP is written from list A and list
B of follows:
i
P = ∪ DTIME(n )
i ≥1
i
NP = ∪ NTIME( n )
i ≥1
PSPACE = i∪ DSPACE( ni )
≥1
i
NPSPACE = ∪ USPACE( n )
i ≥1
Definition
A language L′ is said to be polynomial time reducible to L if there is a polynomial time
bounded TM that for each input x produces an output y that is in L if and only if x is in L′.
Undecidability 9.27
Lemma
Let L′ be polynomial-time reducible to L. Then
a) L′ is in NP if L is in NP,
b) L′ is in P if L is in P.
Proof
Assume that the reduction is p1(n) time bounded and that L is recogniazable in time
p2(n), where p1 and p2 are polynomials. Then L′ can be recognized in polynomial time as
follows. Given input x of length n, produce y using the polynomial-time reduction. As the
reduction is p1(n) time bounded, and at most one symbol can be printed per move, if follows
that |y| ≤ p1(n). Then, we can test if y is in L′ in time (p2(p1(n)). Thus the total time to tell
whether x is in L is p1(n) + p2(p1(n)), which is polynomial in n. Therefore, L is in P.
NP-complete and NP-hard Problems
It is obvious the P⊆NP. It is not known that whether there exists some language L in NP,
which is also accepted by deterministic TM.
A language L is said to be NP-hard if L1 ≤ PL for every L1⊆NP. The language L is NP-
complete if L⊆NP and L is NP-hard.
Examples for NP-complete problems
(i) Lvc, the vertex cover problem.
(ii) Ldh, the directed Hamilton circuit problem.
(iii) Lh, the Hamilton circuit problem for undirected graph.
Example for NP-hard problem
(i) Integer linear programming.