Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

BCSE304L

Theory of Computation
Lecture 30
Dr. Saritha Murali
(SCOPE, VIT Vellore)
05-04-2023
Encoding of Turing machine
M = (Q, Σ, Γ, d, q1, B, F) where
Q = {q1 , q2 , q3 , . . . , qn } q1 – initial state
Γ = { 0, 1, B} Σ = { 0, 1}
d(qi , Xj ) = (qk , Xl , Dm ) X1 = 0 , X2 = 1 , X3 = B
L=1 ,R=2
1 ≤ i, k ≤ n , 1 ≤ j, l ≤ 3 , 1 ≤ m ≤ 2

• encode the transition function d : 0i 1 0j 1 0k 1 0l 1 0m

• no occurrences of two or more consecutive 1's within the code for a


single transition.
Encoding of Turing machine
A code for the entire TM M consists of all the codes for the transitions, in
some order, separated by pairs of 1’s:

where each of the C's is the code for one transition of M.


0i 1 0j 1 0k 1 0l 1 0m 11 0i 1 0j 1 0k 1 0l 1 0m 11 . . . 11 . . . 11 . . .
Consider the following Turing machine with alphabet { 0, 1, B} and
state set {q1 , q2 , q3 , q4 , q5 }, q1 is the initial state, q5 is the final state
and the transitions are
d(q1 , 0 ) = (q2 , 0 , R ) d(q3 , B ) = (q4 , 1 , R )
d(q2 , 0 ) = (q3 , 0 , R ) d(q4 , 0 ) = (q3 , 1 , L )
d(q3 , 0 ) = (q4 , 1 , R ) d(q4 , 1 ) = (q5 , 1 , R )
d(q3 , 1 ) = (q4 , 1 , L) d(q4 , B ) = (q3 , 1 , L)

01 1 01 1 02 1 01 1 02 1102 1 01 1 03 1 01 1 02 11 03 1 01 1 04 1 02 1 02 11
03 1 02 1 04 1 02 1 01 11 03 1 03 1 04 1 02 1 02 11 04 1 01 1 03 1 02 1 01 11
04 1 02 1 05 1 02 1 02 11 04 1 03 1 03 1 02 1 01
Enumeration of Turing machine
111m111m2 11 m3 11 m411 m5 11 m611m711m8111
Each mi is of the form 0i 1 0j 1 0k 1 0l 1 0m
ith integer in binary represents ith Turing machine, say Ti
1 - T1
10 - T2 If the binary integer is not proper encoding, then the
11 - T3 respective TM will have no moves.
100 - T4
101 - T5
110 - T6
111 - T7
.....
Enumeration of Turing machine
• ith integer in binary represents ith TM

Many integers do not correspond to any TM at all


• 11001 does not begin with 0
• 0010111010010100 is not valid because it has three consecutive 1’s

• If wi is not a valid TM code, we shall take Mi to be the TM with one


state and no transitions. That is, for these values of i, Mi is a Turing
machine that immediately halts on any input.
• L(Mi) is ∅ if wi fails to be a valid TM code.
Universal Turing machine (U)
• Lu (universal language): the set of binary strings that encode a pair
(M,w), where
• M is a TM with the binary input alphabet
• w is a string in (0+ 1)*, such that w is in L(M).
• Lu is the set of strings representing a TM and an input accepted by
that TM
• Universal Turing Machine(UTM): Lu = L(U)
Universal Turing machine (U)
• Universal TM is a TM which can
simulate any TM
• U has three tapes.
• Tape 1: has the encoding of TM, M and the
input to T (i.e., w)
• Tape 2: contain the input w, in its encoded
form.
• Tape 3: Encoded state qi as 0i
Universal Turing machine (U)
1. Examine the input to make sure that the code for M is a legitimate code for some
TM. If not, U halts without accepting.
2. the second tape to contain the input w, in its encoded form.
3. To simulate a move of M, U searches on its first tape for a transition 0i 1 0j 1 0k 1
0l 1 0m such that 0i is the state on tape 3, and Oj is the tape symbol of M that begins
at the position on tape 2 scanned by U. This transition is the one M would next
make. U should:
(a) Change the contents of tape 3 to 0k; that is, simulate the state change
(b) Replace 0j on tape 2 by 0l; that is, change the tape symbol of M.
(c) Move the head on tape 2 to the position of the next 1 to the left or right
4. If M has no transition that matches the simulated state and tape symbol, then in
(3), no transition will be found. Thus, M halts
5. If M enters its accepting state, then U accepts.
In this manner, U simulates M on w. U accepts the coded pair (M,w) if and only if
M accepts w.
U simulates T on t

halts and accepts halts and rejects gets into a loop


Decidability
• A problem is said to be Decidable if we can always construct a
corresponding algorithm that can answer the problem correctly.
• e.g., compute all the prime numbers in the range of 1000 to 2000 -
devise an algorithm that can enumerate all the prime numbers in this
range
• A problem is said to be a Decidable problem if there exists a
corresponding Turing machine which halts on every input with an
answer- yes or no.
• These problems are termed as Turing Decidable since a Turing
machine always halts on every input, accepting or rejecting it.
Decidability
• Semi-Decidable Problems:
The problems for which a Turing machine halts on the input accepted
by it but it can either halt or loop forever on the input which is
rejected by the Turing Machine.
• Such problems are termed as Turing Recognisable problems.
Decidability
• Undecidable Problems:
The problems for which we cannot construct an algorithm that can
answer the problem correctly in finite time are termed as
Undecidable Problems.
• These problems may be partially decidable, but they will never be
decidable.
• That is there will always be a condition that will lead the Turing
Machine into an infinite loop without providing an answer at all.
Decidability
Recursive language - TM will always halt
- Turing Decidable
Recursively enumerable - TM will halt sometimes and
language may not halt sometimes
- Turing Recognisable
- Partially decidable

Undecidable - No TM for the language


1.Every decidable (recursive) problem is also semi-decidable
(recursively enumerable).
2.Every semi-decidable (recursively enumerable) problem that is not
decidable (recursive) is undecidable.
3.There are undecidable problems that are not semi-decidable
(recursively enumerable).
Halting Problem
The halting problem for Turing machines:
Given a TM in an arbitrary configuration will it eventually halt?

This problem is undecidable i.e., there cannot exist an algorithm which


will take as input a description of a TM T and input t and say whether T
on t will halt or not.
Halting Problem

Proof by Contradiction:
Step1: Assume we can create a machine called
HM(P, I), where HM is the Halting machine, P is
the program, and I is the input. After receiving
both inputs, the machine HM will output
whether or not the program P terminates.

Step2: Now, create an inverted halting machine


IM that takes a program P as input and,
•Loops forever If HM returns YES.
•Halts if HM returns NO.
Halting Problem
Step3: Now, take a situation where the
program IM is passed to the IM function as an
input. Here, we got a contradiction.

IM is designed to do the opposite of what HM


says:
When HM determines that IM will halt, IM ends
up in running forever => HM is wrong
When HM determines that IM will run for ever,
IM ends up by halting => HM is wrong.
i.e., if HM existed, and we built IM using HM,
then HM can be wrong. So, contradiction !!!

You might also like