0% found this document useful (0 votes)
30 views12 pages

Halting Problem and Rice Theorem

The document discusses the concepts of decidable, undecidable, partially decidable, recursive, and recursively enumerable languages in the context of decision problems and Turing machines. It explains the properties of these languages, provides examples of decidable and undecidable problems, and introduces the concepts of NP, NP-completeness, and NP-hardness. Additionally, it covers Rice's theorem and provides proofs for the undecidability of certain problems, including the halting problem and the traveling salesman problem.

Uploaded by

venkat Mohan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views12 pages

Halting Problem and Rice Theorem

The document discusses the concepts of decidable, undecidable, partially decidable, recursive, and recursively enumerable languages in the context of decision problems and Turing machines. It explains the properties of these languages, provides examples of decidable and undecidable problems, and introduces the concepts of NP, NP-completeness, and NP-hardness. Additionally, it covers Rice's theorem and provides proofs for the undecidability of certain problems, including the halting problem and the traveling salesman problem.

Uploaded by

venkat Mohan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Decidable language -A decision problem P is said to be decidable (i.e.

,
have an algorithm) if the language L of all yes instances to P is decidable.
Example- (I) (Acceptance problem for DFA) Given a DFA does it accept a
given word? (II) (Emptiness problem for DFA) Given a DFA does it accept
any word? (III) (Equivalence problem for DFA) Given two DFAs, do they
accept the same language?

Undecidable language -– A decision problem P is said to be undecidable if


the language L of all yes instances to P is not decidable or a language is
undecidable if it is not decidable. An undecidable language maybe a partially
decidable language or something else but not decidable. If a language is not
even partially decidable , then there exists no Turing machine for that
language.
Partially decidable or Semi-Decidable Language -– A decision problem P
is said to be semi-decidable (i.e., have a semi-algorithm) if the language L of
all yes instances to P is RE. A language ‘L’ is partially decidable if ‘L’ is a RE
but not REC language.

Recursive language(REC) – A language ‘L’ is said to be recursive if there


exists a Turing machine which will accept all the strings in ‘L’ and reject all
the strings not in ‘L’. The Turing machine will halt every time and give an
answer(accepted or rejected) for each and every string input. A language ‘L’
is decidable if it is a recursive language. All decidable languages are
recursive languages and vice-versa.

Recursively enumerable language(RE) – A language ‘L’ is said to be a


recursively enumerable language if there exists a Turing machine which will
accept (and therefore halt) for all the input strings which are in ‘L’ but may or
may not halt for all input strings which are not in ‘L’. By definition , all REC
languages are also RE languages but not all RE languages are REC
languages.
Language Decidability
A language is called Decidable or Recursive if there is a Turing machine which
accepts and halts on every input string w. Every decidable language is Turing-
Acceptable.
A decision problem P is decidable if the language L of all yes instances
to P is decidable.
For a decidable language, for each input string, the TM halts either at the
accept or the reject state as depicted in the following diagram −

Example 1
Find out whether the following problem is decidable or not −
Is a number ‘m’ prime?

Solution
Prime numbers = {2, 3, 5, 7, 11, 13, …………..}
Divide the number ‘m’ by all the numbers between ‘2’ and ‘√m’ starting
from ‘2’.
If any of these numbers produce a remainder zero, then it goes to the
“Rejected state”, otherwise it goes to the “Accepted state”. So, here the
answer could be made by ‘Yes’ or ‘No’.
Hence, it is a decidable problem.

Example 2
Given a regular language L and string w, how can we check if w ∈ L?

Solution
Take the DFA that accepts L and check if w is accepted
Some more decidable problems are −

 Does DFA accept the empty language?


 Is L1 ∩ L2 = ∅ for regular sets?
Note −
 If a language L is decidable, then its complement L' is also
decidable
 If a language is decidable, then there is an enumerator for it.

Undecidable Languages
For an undecidable language, there is no Turing Machine which accepts
the language and makes a decision for every input string w (TM can make
decision for some input string though). A decision problem P is called
“undecidable” if the language L of all yes instances to P is not decidable.
Undecidable languages are not recursive languages, but sometimes, they
may be recursively enumerable languages.
Example
 The halting problem of Turing machine

 The mortality problem

 The mortal matrix problem

 The Post correspondence problem, etc.

Turing Machine Halting Problem


Input − A Turing machine and an input string w.
Problem − Does the Turing machine finish computing of the string w in a
finite number of steps? The answer must be either yes or no.
Proof − At first, we will assume that such a Turing machine exists to
solve this problem and then we will show it is contradicting itself. We will
call this Turing machine as a Halting machine that produces a ‘yes’ or
‘no’ in a finite amount of time. If the halting machine finishes in a finite
amount of time, the output comes as ‘yes’, otherwise as ‘no’. The
following is the block diagram of a Halting machine −

Now we will design an inverted halting machine (HM)’ as −


 If H returns YES, then loop forever.
 If H returns NO, then halt.
The following is the block diagram of an ‘Inverted halting machine’ −
Further, a machine (HM)2 which input itself is constructed as follows −

 If (HM)2 halts on input, loop forever.


 Else, halt.
Here, we have got a contradiction. Hence, the halting problem
is undecidable.
Proof by Contradiction

Problem statement: Can we design a machine which if given a program can


find out if that program will always halt or not halt on a particular input?

Solution: Let us assume that we can design that kind of machine called as
HM(P, I) where HM is the machine/program, P is the program and I is the
input. On taking input the both arguments the machine HM will tell that the
program P either halts or not.
If we can design such a program this allows us to write another program we
call this program CM(X) where X is any program(taken as argument) and
according to the definition of the program CM(X) shown in the figure.

In the program CM(X) we call the function HM(X), which we have already
defined and to HM() we pass the arguments (X, X), according to the
definition of HM() it can take two arguments i.e one is program and another
is the input.Now in the second program we pass X as a program and X as
input to the function HM().We know that the program HM() gives two output
either “Halt” or “Not Halt”.But in case second program, when HM(X, X) will
halt loop body tells to go in loop and when it doesn’t halt that means loop, it
is asked to return.
Now we take one more situation where the program CM is passed to CM()
function as an argument. Then there would be some impossibility, i.e., a
condition arises which is not possible.

It is impossible for outer function to halt if its code (inner body) is in loop and
also it is impossible for outer non halting function to halt even after its inner
code is halting. So the both condition is non halting for CM machine/program
even we had assumed in the beginning that it would halt.So this is the
contradiction and we can say that our assumption was wrong and this
problem, i.e., halting problem is undecidable.
This is how we proved that halting problem is undecidable.

Rice Theorem
Rice theorem states that any non-trivial semantic property of a language
which is recognized by a Turing machine is undecidable. A property, P, is
the language of all Turing machines that satisfy that property.

Formal Definition

recognized by Turing machine M, then L p = {<M> | L(M) ∈ P} is


If P is a non-trivial property, and the language holding the property, L p , is

undecidable.

Description and Properties


language belongs to P (L ∈ P), it is said that L satisfies the
 Property of languages, P, is simply a set of languages. If any

property P.
 A property is called to be trivial if either it is not satisfied by
any recursively enumerable languages, or if it is satisfied by all
recursively enumerable languages.
 A non-trivial property is satisfied by some recursively

Formally speaking, in a non-trivial property, where L ∈ P, both


enumerable languages and are not satisfied by others.

the following properties hold:


o Property 1 − There exists Turing Machines, M1 and

( <M1>, <M2> ∈ L ) or ( <M1>,<M2> ∉ L )


M2 that recognize the same language, i.e. either

o Property 2 − There exists Turing Machines M1 and

not, i.e. <M1> ∈ L and <M2> ∉ L


M2, where M1 recognizes the language while M2 does

Proof
Suppose, a property P is non-trivial and φ ∈ P.
Since, P is non-trivial, at least one language satisfies P, i.e., L(M 0) ∈ P , ∋
Turing Machine M0.
Let, w be an input in a particular instant and N is a Turing Machine which
follows −
On input x
 Run M on w
 If M does not accept (or doesn't halt), then do not accept x (or do
not halt)
 If M accepts w then run M0 on x. If M0 accepts x, then accept x.
A function that maps an instance ATM = {<M,w>| M accepts input w} to a
N such that

L(M0) ∈ p
 If M accepts w and N accepts the same language as M 0, Then L(M) =

 If M does not accept w and N accepts φ, Then L(N) = φ ∉ p

Since ATM is undecidable and it can be reduced to Lp, Lp is also


undecidable.
P-Class
 The class P consists of those problems that are solvable in
polynomial time, i.e. these problems can be solved in time O(n
k) in the worst-case, where k is constant.
 These types of problems are called tractable and others are
called intractable or super polynomial.
 Generally, an algorithm is a polynomial time algorithm, if there
exists a polynomial p(n) such that the algorithm can solve any
instance of size n in a time O(p(n)).
 Problems requiring Ω(n 50) time to solve are essentially
intractable for large n. Most known polynomial time algorithms
run in time O(n^k) for a fairly low value of k.
 The advantage in the class of polynomial-time algorithms is
that all reasonable deterministic single processor models of
computation can be simulated on each other with at most a
polynomial slow-d.
NP-Class
 The class NP consists of problems that are verifiable in
polynomial time. NP is a class of decision problems for which it
is easy to check the correctness of a given answer, with the
aid of a little extra information. Hence, we are not asking for a
way to find a solution, but only to verify that a solution really is
correct.
 Every problem in the given class can be solved in exponential
time using exhaustive search.
Example
Consider an example to check if a problem is in P class or NP class
Step 1 − If a problem is in class P, it is nothing but we can find a solution
to that type of problem in polynomial time.
Step 2 − If a problem is in class NP, it is nothing but that we can verify a
possible solution in polynomial time.
Step 3 − Consider another way, NP means that a problem is
NondeterministicallyPolynomial. Specifically, that means that if you could
build a machine that had the ability to try all the possible solutions of
your problem at once, it could finish in polynomial time.
We know this to be true because we know that we can verify a possible
solution in polynomial time, and what that machine is basically doing is
trying to verify (test) all of the potential answers to the problem at the
same time.
Step 4 − So, if you can solve a problem in polynomial time, you can
certainly verify that your answer is correct in polynomial time, can't you?
Sure, if you can prove that your algorithm is correct and that it can find
an answer in polynomial time, which it must to be in P.

NP-completeness
The Non-deterministic Polynomial (NP) problems were a little harder
to understand. In terms of solving a NP problem, the run-time is not
polynomial. It would be something like O(n!) or something larger.
However, this class of problems are given a specific solution, and
checking the solution would have a polynomial run-time.
For example, the Sudoku game.

NP-Hard Problems
A problem is said to be NP-Hard when an algorithm for solving NP Hard
can be translated to solve any NP problem. Then we can say, this problem
is at least as hard as any NP problem, but it could be much harder or
more complex.

NP-Complete Problems
NP-Complete (NPC) problems are problems that are present in both the
NP and NP-Hard classes. That is NP-Complete problems can be verified in
polynomial time and any NP problem can be reduced to this problem in
polynomial time.
A problem is in class NPC if it is in NP and is as hard as any problem in NP.
A problem is said to be NP-hard if all problems in NP are polynomial time
reducible to it, even though it may not be in NP itself.
If a polynomial time algorithm exists for any of these types of problems,
all problems in NP can be polynomial time solvable. These problems are
called NP-complete. NPcompleteness is important for both theoretical and
practical reasons.

Definition of NP-Completeness
A language M is NP-complete, if it satisfies the two conditions which are
given below
 M is in NP.
 Every A in NP is polynomial time reducible to M.

Suppose, if a language satisfies the second property, but not necessarily


the first one, the language M is known as NP-Hard.
Informally, a search problem M is NP-Hard if there exists some NP-
Complete problem A that Turing reduces to M.

NP-Complete Problems
Examples of NP-Complete problems where no polynomial time algorithm
is known are as follows −
 Determining whether a graph has a Hamiltonian cycle
 Determining whether a Boolean formula is satisfactory, etc.
NP-Hard Problems
The following problems are NP-Hard
 The circuit-satisfiability problem
 Set Cover
 Vertex Cover
 Travelling Salesman Problem

Prove that the Hamiltonian Path is NP-


Complete
A Hamilton cycle is a round trip path along n edges of graph G which
visits every vertex once and returns to its starting vertex

Example
Given below is an example of the Hamilton cycle path −

Hamilton cycle path: 1,2,8,7,6,5,4,3,1

TSP is NP-Complete
The travelling salesman problem (TSP) is having a salesman and a set of
cities. The salesman needs to visit each one of the cities starting from a
certain one and returning to the same city i.e. back to starting position.
The challenge of this problem is that the travelling salesman wants to
minimise the total length of the trip.

Proof
To prove TSP is NP-Complete, first try to prove TSP belongs to Non-
deterministic Polynomial (NP).
In TSP, we have to find a tour and check that the tour contains each
vertex once.
Then, we calculate the total cost of the edges of the tour. Finally, we
check if the cost is minimum or not. This can be done in polynomial time.
Therefore, TSP belongs to NP.
Next, we have to prove that TSP is NP-hard.
To prove this, one way is to show that the Hamiltonian cycle ≤p TSP (as
we know that the Hamiltonian cycle problem is NP Complete).
Assume G = (V, E) to be an instance of the Hamiltonian cycle.
Hence, an instance of TSP is constructed. We can create the complete
graph G' = (V, E'), where
E′={(i,j):i,j∈Vandi≠j
Thus, the cost function is defined as follows:
t(i,j)= 0 if (i,j) ∈ E
=1 otherwise
Now, assume that a Hamiltonian cycle H exists in G. The cost of each
edge in H is 0 in G' as each edge belongs to E. Therefore, H is having a
cost of 0 in G'. Thus, if graph G has a Hamiltonian cycle, then graph G'
has a tour of 0 cost.
Now let us assume that G' has a tour H’ of cost at most 0. The cost of
edges in E' are 0 and 1 by definition. Hence, each edge must have a cost
of 0 as the cost of H’ is 0. We finally conclude that H' contains only edges
in E.
Finally proved that G has a Hamiltonian cycle, if and only if G' has a tour
of cost at most 0. TSP is NP-complete.

Prove that the vertex cover is NP complete


It is the subset(minimum size) of vertices of a graph G such that every
edge in G incident to at least one vertex in G.

Vertex Cover (VC) Problem


To prove VC is NP-complete we have to prove the following −
VC is Non-deterministic Polynomial (NP).

A NPC problem can be reduced into VC.

To prove VC is NP, find a verifier which is a subset of vertices which is VC
and that can be verified in polynomial time. For a graph of n vertices it
can be proved in O(n2). Thus, VC is NP.
Now consider the “clique” problem which is NPC and reduce it into VC to
prove NPC. Clique of a graph G is a subset of vertices such that these
vertices form a complete subgraph in the given graph G.
The two graphs titles (a) and (b) are given below for the VC problem −
Consider graph (a), here clique is {a,b,c,d}.
Now calculate a graph as shown in (b) which is as follows −
Completed graph of all the vertices in (a) – (a)
For the graph (b), we can say that the vertex cover is {s,t} which covers
all the edges of the (b). This {s,t} = {a,b,c,d,s,t} – {Clique of (a)} Thus
conversely, we can say that we can reduce clique into the VC problem
and conversely can find both VC and clique of a given undirected graph.
This means VC is NP-complete reducible.
Hence proved that VC is an NPC.

You might also like