Unit-3 TOC
Unit-3 TOC
Turing machine was invented in 1936 by Alan Turing. It is an accepting device which
accepts Recursive Enumerable Language generated by type 0 grammar.
The mapping function shows the mapping from states of finite automata and input
symbol on the tape to the next states, external symbols and the direction for moving the
tape head. This is known as a triple or a program for turing machine.
1. (q0, a) → (q1, A, R)
That means in q0 state, if we read symbol 'a' then it will go to state q1, replaced a by X
and move ahead right(R stands for right).
Example:
Construct TM for the language L ={0n1n} where n>=1.
Solution:
We have already solved this problem by PDA. In PDA, we have a stack to remember the
previous symbol. The main advantage of the Turing machine is we have a tape head which
can be moved forward or backward, and the input tape can be scanned.
The simple logic which we will apply is read out each '0' mark it by A and then move ahead
along with the input tape and find out 1 convert it to B. Now, repeat this process for all
a's and b's.
Now we will see how this turing machine work for 0011.
Now, we will see how this turing machine will works for 0011. Initially, state is q0 and
head points to 0 as:
The move will be δ(q0, 0) = δ(q1, A, R) which means it will go to state q1, replaced 0 by
A and head will move to the right as:
The move will be δ(q1, 0) = δ(q1, 0, R) which means it will not change any symbol,
remain in the same state and move to the right as:
The move will be δ(q1, 1) = δ(q2, B, L) which means it will go to state q2, replaced 1 by B
and head will move to left as:
Now move will be δ(q2, 0) = δ(q2, 0, L) which means it will not change any symbol,
remain in the same state and move to left as:
The move will be δ(q2, A) = δ(q0, A, R), it means will go to state q0, replaced A by A and
head will move to the right as:
The move will be δ(q0, 0) = δ(q1, A, R) which means it will go to state q1, replaced 0 by
A, and head will move to right as:
The move will be δ(q1, B) = δ(q1, B, R) which means it will not change any symbol,
remain in the same state and move to right as:
The move will be δ(q1, 1) = δ(q2, B, L) which means it will go to state q2, replaced 1 by B
and head will move to left as:
The move δ(q2, B) = (q2, B, L) which means it will not change any symbol, remain in the
same state and move to left as:
Now immediately before B is A that means all the 0?s are market by A. So we will move
right to ensure that no 1 is present. The move will be δ(q2, A) = (q0, A, R) which means it
will go to state q0, will not change any symbol, and move to right as:
The move δ(q0, B) = (q3, B, R) which means it will go to state q3, will not change any
symbol, and move to right as:
The move δ(q3, B) = (q3, B, R) which means it will not change any symbol, remain in the
same state and move to right as:
The move δ(q3, Δ) = (q4, Δ, R) which means it will go to state q4 which is the HALT state
and HALT state is always an accept state for any TM.
2. The finite control and the tape head which is responsible for reading the current input symbol.
The tape head can move to left to right.
4. Finite set of symbols called external symbols which are used in building the logic of
turing machine.
Example:
Construct a turing machine which accepts the language of aba over ∑ = {a, b}.
Solution:
We will assume that on input tape the string 'aba' is placed like this:
The tape head will read out the sequence up to the Δ characters. If the tape head is
readout 'aba' string then TM will halt after reading Δ.
Now, we will see how this turing machine will work for aba. Initially, state is q0 and head
points to a as:
The move will be δ(q0, a) = δ(q1, A, R) which means it will go to state q1, replaced a by A and
head will move to right as:
The move will be δ(q1, b) = δ(q2, B, R) which means it will go to state q2, replaced b by B and
head will move to right as:
The move will be δ(q2, a) = δ(q3, A, R) which means it will go to state q3, replaced a by A and
head will move to right as:
The move δ(q3, Δ) = (q4, Δ, S) which means it will go to state q4 which is the HALT state and
HALT state is always an accept state for any TM.
q0 (q1, A, R) – –
q1 – (q2, B, R) –
q2 (q3, A, R) – –
q3 – – (q4, Δ, S)
q4 – – –
Examples of TM
Example 1:
Construct a TM for the language L = {0n1n2n} where n≥1
Solution:
L = {0n1n2n | n≥1} represents language where we use only 3 character, i.e., 0, 1 and 2. In
this, some number of 0's followed by an equal number of 1's and then followed by an
equal number of 2's. Any type of string which falls in this category will be accepted by this
language.
The simulation for 001122 can be shown as below:Skip Ad
Now, we will see how this Turing machine will work for 001122. Initially, state is q0 and
head points to 0 as:
The move will be δ(q0, 0) = δ(q1, A, R) which means it will go to state q1, replaced 0 by A and
head will move to the right as:
The move will be δ(q1, 0) = δ(q1, 0, R) which means it will not change any symbol, remain in the
same state and move to the right as:
The move will be δ(q1, 1) = δ(q2, B, R) which means it will go to state q2, replaced 1 by B
and head will move to right as:
The move will be δ(q2, 1) = δ(q2, 1, R) which means it will not change any symbol, remain
in the same state and move to right as:
The move will be δ(q2, 2) = δ(q3, C, R) which means it will go to state q3, replaced 2 by C
and head will move to right as:
Now move δ(q3, 2) = δ(q3, 2, L) and δ(q3, C) = δ(q3, C, L) and δ(q3, 1) = δ(q3, 1, L) and δ(q3, B)
= δ(q3, B, L) and δ(q3, 0) = δ(q3, 0, L), and then move δ(q3, A) = δ(q0, A, R), it means will go to
state q0, replaced A by A and head will move to right as:
The move will be δ(q0, 0) = δ(q1, A, R) which means it will go to state q1, replaced 0 by
A, and head will move to right as:
The move will be δ(q1, B) = δ(q1, B, R) which means it will not change any symbol, remain
in the same state and move to right as:
The move will be δ(q1, 1) = δ(q2, B, R) which means it will go to state q2, replaced 1 by B
and head will move to right as:
The move will be δ(q2, C) = δ(q2, C, R) which means it will not change any symbol, remain in the
same state and move to right as:
The move will be δ(q2, 2) = δ(q3, C, L) which means it will go to state q3, replaced 2 by C and
head will move to left until we reached A as:
immediately before B is A that means all the 0's are market by A. So we will move right to
ensure that no 1 or 2 is present. The move will be δ(q2, B) = (q4, B, R) which means it will
go to state q4, will not change any symbol, and move to right as:
The move will be (q4, B) = δ(q4, B, R) and (q4, C) = δ(q4, C, R) which means it will not
change any symbol, remain in the same state and move to right as:
The move δ(q4, X) = (q5, X, R) which means it will go to state q5 which is the HALT state
and HALT state is always an accept state for any TM.
The same TM can be represented by Transition Diagram:
Example 2:
Construct a TM machine for checking the palindrome of the string of even length.
Solution:
Firstly we read the first symbol from the left and then we compare it with the first symbol
from right to check whether it is the same.
Again we compare the second symbol from left with the second symbol from right. We
repeat this process for all the symbols. If we found any symbol not matching, we cannot
lead the machine to HALT state.
Suppose the string is ababbabaΔ. The simulation for ababbabaΔ can be shown as follows:
Now, we will see how this Turing machine will work for ababbabaΔ. Initially, state is q0
and head points to a as:
Go to HALT state
Solution:
Firstly we read the first symbol from left and then we compare it with the first symbol
from right to check whether it is the same.
Again we compare the second symbol from left with the second symbol from right. We
repeat this process for all the symbols. If we found any symbol not matching, we lead the
machine to HALT state.
Suppose the string is 00100Δ. The simulation for 00100Δ can be shown as follows:
Now, we will see how this Turing machine will work for 00100Δ. Initially, state is q0 and
head points to 0 as:
Now replace 0 by * and move right as:
Moved right up to Δ
Move left and replace 0 by Δ as:
Move left
Solution:
The unary number is made up of only one character, i.e. The number 5 can be written in
unary number system as 11111. In this TM, we are going to perform the addition of two
unary numbers.
For example
2 + 3
i.e. 11 + 111 = 11111
If you observe this process of addition, you will find the resemblance with string
concatenation function.
In this case, we simply replace + by 1 and move ahead right for searching end of the string
we will convert last 1 to Δ.
Input: 3+2
Thus the tape now consists of the addition of two unary numbers.
Here, we are implementing the function of f(a + b) = c. We assume a and b both are non
zero elements.
Example 5:
Construct a TM for subtraction of two unary numbers f(a-b) = c where a is always greater
than b.
Solution: Here we have certain assumptions as the first number is greater than the second
one. Let us assume that a = 3, b = 2, so the input tape will be:
We will move right to - symbol as perform reduction of a number of 1's from the first
number. Let us look at the simulation for understanding the logic:
Introduction to Undecidability
In the theory of computation, we often come across such problems that are answered
either 'yes' or 'no'. The class of problems which can be answered as 'yes' are called solvable
or decidable. Otherwise, the class of problems is said to be unsolvable or undecidable.
Reduction
Reduction is a technique in which if a problem P1 is reduced to a problem P2 then any
solution of P2 solves P1. In general, if we have an algorithm to convert an instance of a
problem P1 to an instance of a problem P2 that have the same answer then it is called as
P1 reduced P2. Hence if P1 is not recursive then P2 is also not recursive. Similarly, if P1 is
not recursively enumerable then P2 also is not recursively enumerable.
1. Consider an instance w of P1. Then construct an algorithm such that the algorithm
takes instance w as input and converts it into another instance x of P2. Then apply
that algorithm to check whether x is in P2. If the algorithm answer 'yes' then that
means x is in P2, similarly we can also say that w is in P1. Since we have obtained
P2 after reduction of P1. Similarly if algorithm answer 'no' then x is not in P2, that
also means w is not in P1. This proves that if P1 is undecidable, then P1 is also
undecidable.
2. We assume that P1 is non-RE but P2 is RE. Now construct an algorithm to reduce
P1 to P2, but by this algorithm, P2 will be recognized. That means there will be a
Turing machine that says 'yes' if the input is P2 but may or may not halt for the
input which is not in P2. As we know that one can convert an instance of w in P1
to an instance x in P2. Then apply a TM to check whether x is in P2. If x is accepted
that also means w is accepted. This procedure describes a TM whose language is
P1 if w is in P1 then x is also in P2 and if w is not in P1 then x is also not in P2. This
proves that if P1 is non-RE then P2 is also non-RE.
Le = {M | L(M) = Ф}
Lne = {M | L(M) ≠ Ф}
• Multi-track
• Multi-tape
• Multi-head
• Multi-dimensional tape
• The off-line Turing machine
Multi-tape Turing Machine
A Turing machine with several tapes we call it a multi tape Turing machine.
Every tape’s have their own Read/Write head
For N-tape Turing Machine
M={( Q,X, ∑,δ,q0,B,F)}
We define
δ=QxXN ->Q x XN x {L,R}N
Example
If n=2 with current configuration δ(q0,a,e)=(q1,X,Y,L,R)
All NP-hard problems are not in NP and it takes a long time to check
NP-hard them.
• Program P
• Input S.
If P stops on S, then H results in “halt”, otherwise H gives the result
“loop”.
The diagrammatic representation of H is as follows −
Example
ATM = {(M,w) | M is a TM and M halts at input w }.
We can build a universal Turing machine which can simulate any Turing
machine on any input.
Let’s consider TM which recognizing the Altering Turing Machine (ATM)
−
Recognize-ATM (<M,w>)
Simulate M using UTM till it halts
If M halts and accept then
Accept
Else
Reject
Suppose, if M goes into an infinite loop on input w, then the TM
Recognize-ATM is going to run forever which means TM is only a
recognizer, not a decider.
A decider for this problem would call a halt to simulations that loop
forever.
Now the question is whether an ATM is TM decidable is equivalent to
asking the question whether we can tell if a TM M will halt on input w.
Because of this, both versions of this question are generally called the
halting problem.
Solution
Subtraction of two unary integers
3-2=1
In Turing Machine 3 represents − 111
2 represents: 11
Let ‘M’ be a symbol used to separate two integers
B 1 1 1 M 1 1 B
Here B= blank
M= Symbol used two separate two integers
Algorithm
Follow the step wise algorithm given below to construct a TM for subtraction −
Step 1 − Let’s take two unary integers as an input. We start from the initial state q0.
Step 2 − If we find the 1 in the string then go to the same state without changing the value
of 1, and go to the right of the string.
Step 3 − If we find the m symbol then ignore this symbol without changing the symbol
and go to the right of the string.
Step 4 − If we find the 1 after the pass the M symbol then change the value of 1 into the
X and go to the left of the string.
Step 5 − Then pass the symbol of M and go to the left and if we find the 1 then change
the value of 1 to X and go to the right.
Step 6 − So, this type after the symbol(M) we change all values of 1's into X and the same
total number of 1's change into the X before the symbol M.
Step 7 − Apply these steps and get the Turing machine subtraction of two unary integers.
While working with subtraction, the Turing machine considers any of the three cases
based on input given by the user.
If ‘a’ and ‘b’ are two integers, we have two consider whether −
• a>b
• a<b
• a=b
By consider all the three conditions, the final Turing machine is as follows−
Explanation of the diagram
Step 1 − Consider an input string as 110111
i.e. a=11 and b=111, according to given input a
Step 2 − Scan string from left to right.
Step 3 − Mark '1' as 'X' and then move to the right.
Step 4 − Reaching to the right of '0' and marking '1' as 'X' and moving left.
Step 5 − Reaching 'X' on left of '0' and moving one step right.
Step 6 − Again mark '1' as 'X' and then move to the right.
Step 7 − Reaching to the right of '0' and passing 'X', mark '1' as 'X' and move left.
Step 8 − Reach 'X' in the left of '0'and move one step right.
Step 9 − If there is a ‘0’ after 'X' that means all '1's are finished before '0'.
Step 10 − Pass '0', 'X' and there is '1' remaining. That is, the second number is greater
than the first one.
Step 11 − And then the final state is "a<b"