Flat Module 5
Flat Module 5
Turing Machine
The turning machine can be modelled with the help of the following representation.
1. The input tape is having an infinite number of cells, each cell containing one input symbol and
thus the input string can be placed on tape. The empty tape is filled by blank characters.
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.
The turing machine accepts all the language even though they are recursively enumerable.
Recursive means repeating the same set of rules for any number of times and enumerable means
a list of elements. The TM also accepts the computable functions, such as addition,
multiplication, subtraction, division, power function, and many more.
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:
e 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.
States a b Δ
q0 (q1, A, R) – –
q1 – (q2, B, R) –
q2 (q3, A, R) – –
q3 – – (q4, Δ, S)
q4 – – –
Example 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.
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:
L1= {anbncn|n>=0}
L2= {dmemfm|m>=0}
L3= L1.L2
= {anbncndm emfm|m>=0 and n>=0} is also recursive.
L1 says n no. of a’s followed by n no. of b’s followed by n no. of c’s. L2 says m no. of d’s
followed by m no. of e’s followed by m no. of f’s. Their concatenation first matches no. of
a’s, b’s and c’s and then matches no. of d’s, e’s and f’s. So it can be decided by TM.
Kleene Closure: If L1is recursive, its kleene closure L1* will also be recursive. For
Example:
L1= {anbncn|n>=0}
L1*= { a nbncn||n>=0}* is also recursive.
Intersection and complement: If L1 and If L2 are two recursive languages, their
intersection L1 ∩ L2 will also be recursive. For Example:
L1= {anbncndm|n>=0 and m>=0}
L2= {anbncndn|n>=0 and m>=0}
L3=L1 ∩ L2
= { anbncndn |n>=0} will be recursive.
L1 says n no. of a’s followed by n no. of b’s followed by n no. of c’s and then any no. of d’s.
L2 says any no. of a’s followed by n no. of b’s followed by n no. of c’s followed by n no. of
d’s. Their intersection says n no. of a’s followed by n no. of b’s followed by n no. of c’s
followed by n no. of d’s. So it can be decided by turing machine, hence recursive.
Similarly, complement of recursive language L1 which is ∑*-L1, will also be recursive.
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.
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
Variation of Turing Machine
A k-track Turing machine(for some k>0) has k-tracks and one R/W head that reads and
writes all of them one by one.
A k-track Turing Machine can be simulated by a single track Turing machine
2. Two-way infinite Tape Turing Machine:
Infinite tape of two-way infinite tape Turing machine is unbounded in both directions left
and right.
Two-way infinite tape Turing machine can be simulated by one-way infinite Turing
machine(standard Turing machine).
3. Multi-tape Turing Machine:
The multi-tape Turing machine has multiple tapes and multiple heads
Each tape is controlled by a separate head
Multi-Tape Multi-head Turing machine can be simulated by a standard Turing machine.
5. Multi-dimensional Tape Turing Machine:
It has multi-dimensional tape where the head can move in any direction that is left, right,
up or down.
Multi dimensional tape Turing machine can be simulated by one-dimensional Turing
machine
6. Multi-head Turing Machine:
A multi-head Turing machine contains two or more heads to read the symbols on the same
tape.
In one step all the heads sense the scanned symbols and move or write independently.
Multi-head Turing machine can be simulated by a single head Turing machine.
7. Non-deterministic Turing Machine:
A non-deterministic Turing machine has a single, one-way infinite tape.
For a given state and input symbol has at least one choice to move (finite number of
choices for the next move), each choice has several choices of the path that it might follow
for a given input string.
A non-deterministic Turing machine is equivalent to the deterministic Turing machine.
Non-Deterministic Turing Machine
n a Non-Deterministic Turing Machine, for every state and symbol, there are a group of actions
the TM can have. So, here the transitions are not deterministic. The computation of a non-
deterministic Turing Machine is a tree of configurations that can be reached from the start
configuration.
An input is accepted if there is at least one node of the tree which is an accept configuration,
otherwise it is not accepted. If all branches of the computational tree halt on all inputs, the non-
deterministic Turing Machine is called a Decider and if for some input, all branches are rejected,
the input is also rejected.
A non-deterministic Turing machine can be formally defined as a 6-tuple (Q, X, ∑, δ, q 0, B, F)
where −
Q is a finite set of states
X is the tape alphabet
∑ is the input alphabet
δ is a transition function;
δ : Q × X → P(Q × X × {Left_shift, Right_shift}).
q0 is the initial state
B is the blank symbol
F is the set of final states
Unrestricted Grammar
In automaton, Unrestricted Grammar or Phrase Structure Grammar is the most general in
the Chomsky Hierarchy of classification. This is type0 grammar, generally used to
generate Recursively Enumerable languages. It is called unrestricted because no other
restriction is made on this except each of their left hand sides being non-empty. The left hand
sides of the rules can contain terminal and non-terminal, but the condition is at least one of them
must be non-terminal.
A Turning Machine can simulate Unrestricted Grammar and Unrestricted Grammar can
simulate Turning Machine configurations. It can always be found for the language recognized
or generated by any Turning Machine.
Formal Definition
The unrestricted grammar is 4 tuple -
G = (N,Σ,P,S)