5. Turing Machine (1)
5. Turing Machine (1)
Chapter 5
5.1 BASICS OF TURING MACHINE
Introduction:
y A Turing machine is a control unit with a finite number of states and
unbounded tape(s).
y Although, the Turing machine seems to be very simple from the
structural point of view, it is as powerful as simple it looks.
y There are so many problems that are unsolvable by push down
automaton. Such problems are solved using a Turing Machine.
y According to the Turing thesis, the only general type of automaton
whose power almost matches with a computer is nothing but the
Turing machine.
Where
Q is the set of finite states,
∑ is the set of input alphabets,
Γ is a finite set of symbols called the tape alphabet,
δ is the transition function, defined as
δ: Q × Γ → Q × Γ × {L, R}
where L = left movement & R = right movement,
B ∈ Γ is a special symbol called the blank,
Turing Machine
187
Chapter 5
SOLVED EXAMPLES
Sol:
Transition diagram
Turing Machine
188
Chapter 5
The transition means q0 by getting ‘a’; it is replacing ‘a’ with
‘X’ & going to state q1 and read-write head move one cell right.
We can even give transition table for L = anbn/n ≥ 1 as shows below:
δ(q0, a) → (q1, X, R)
δ(q0, Y) → (q3, Y, R)
δ(q1, a) → (q1, a, R)
δ(q1, Y) → (q1, Y, R)
δ(q1, b) → (q2, Y, L)
δ(q2, a) → (q2, a, L)
δ(q2, Y) → (q2, Y, L)
δ(q2, X) → (q0, X, R)
δ(q3, Y) → (q3, Y, R)
δ(q3, B) → (q4, B, L)
If the string will be in language then it will get accepted and halt at state q4
otherwise it will either go dead state or dead configuration.
Note: The transition table and transition diagram both are equivalent in power.
Sol:
Transition diagram
Turing Machine
189
Chapter 5
δ(q0, Y) → (q4, Y, R)
δ(q4, Y) → (q4, Y, R)
δ(q4, Z) → (q4, Z, R)
δ(q4, B) → (qf, B, L)
δ(q1, b) → (q2, Y, R)
δ(q1, a) → (q1, a, R)
δ(q1, Y) → (q1, Y, R)
δ(q2, b) → (q2, b, R)
δ(q2, Z) → (q2, Z, R)
δ(q2, c) → (q3, Z, L)
δ(q3, b) → (q3, b, L)
δ(q3, Z) → (q3, Z, L)
δ(q3, Y) → (q3, Y, L)
δ(q3, a) → (q3, a, L)
δ(q3, X) → (q0, X, R)
Transducer:
This is a more general automaton,which is able to produce strings of symbols as output and
it is called a transducer.
SOLVED EXAMPLES
Sol:
Turing Machine
190
Chapter 5
Sol:
Note: Always, the read-write head of Turing machine will point to starting of the input.
Sol: Ex.: 3 + 4 can be represented as input tape as BB00010000BB and the output will
be BB0000000BB.
So, it is the same as a concatenation of two numbers.
191
Chapter 5
Note:
Sol:
Turing Machine
192
Chapter 5
Rack Your Brain
1) For ∑ = {0, 1}, design a Turing machine that accepts the language
denoted by the regular expression 00*.
2) What language is accepted by the Turing machine whose transition
graph is in the figure below?
Computable:
The necessary condition of Turing computable or computable for a function
with a given domain is, there should be some Turing machine M(Q, ∑, Γ, δ,
q0, B, F) such that,
Turing Machine
193
Chapter 5
Halting problem:
y There are some Turing machines which never halt. It may go into infinite
loop.
Example:
y In a Turing machine, the not halting issue i.e whether the TM is ever
halted or not, which is commonly known as the halting problem.
y This type of problem does not occur either in Finite Automata and
Pushdown Automata because there we have only one move in a forward
direction.
y So, when input gets over, either the FA or PDA will definitely halt, but in
the case of TM it can go either forward or backwards.
y Anyway, this option will not add extra power to the automaton.
194
Chapter 5
Turing machines with semi-infinite tape:
y The tape is bounded only in one direction.
y Let’s visualize a tape with a left boundary.
195
Chapter 5
δ : Q × Γ → Q × Γ × {L,R,U,D}
where, U represents the up movement of the read-write head and D represents the down
movement.
Turing Machine
196
Chapter 5
Jumping turing machine:
y In this jumping TM, instead of moving just one step ahead either to the
left or to the right, it can move many steps in one go.
y Here, the δ is given below
δ : Q × Γ → Q × Γ × {L,R} × {n}
↑
Here, ‘n’ number of steps.
y This jumping TM is also equivalent in power to standard TM.
Multihead TM:
y This modified TM have more than 1 read-write head.
y Multiple heads simultaneously look after the scanned symbol and make
the needful, i.e. move or write onto the tape independently.
y A Single head Turing machine can simulate a multi head Turing machine.
197
Chapter 5
Where
Q = finite set of internal states
∑ = finite set of input alphabets
Γ = Finite set of symbols or tape alphabets
δ = the transition function
δ : Q × Γ → 2QxΓ×{L,R}
Note: A NPDA with one extra independent stack. The δ is given below:-
δ: Q × (U{∈}) × Γ × Γ 2Q×Γ*×Γ*
This is also equivalent to standard TM.
Multistack machines:
y The tapes of a multi tape Turing machine in such a way, that it starts
behaving like a stack.
y A one-stack machine is a DPDA, while a machine with two stacks is a
Turing Machine
Turing Machine.
198
Chapter 5
Grey Matter Alert!
199
Chapter 5
Γ = {a , a ,......,a },
1 2 m
Fig. 5.6
Note:
y It follows from this that any turing machine has a finite encoding as
a string on {0,1}+ and that, given any encoding of M, we can decode it
uniquely.
y But any combination of strings will not represent any Turing machine
(e.g. the string 00011).
Turing Machine
200
Chapter 5
Working procedure of universal turing machine:
y The encoded definition of M will be kept in the tape 1, given an input M
and w.
y The tape symbols of M will be placed in the tape 2 and tape 3 will
contain the states of M.
y The universal Turing machine identifies the configuration of M by looking
at the tape 2 and tape 3.
y The tape 1 will help for the transition by seeing tape 2 and tape 3.
y Finally, the changes will be reflected on the tape 2 and tape 3, the
results will be reflected in tape 2.
y As it can be implemented using any programming language, we can
implement the same using any standard Turing machine also.
A single tape Turing Machine M has two states q0 and q1, of which q0 is the starting
state. The tape alphabet of M is {0, 1, B} and its input alphabet is {0, 1}.
The symbol B is the blank symbol used to indicate end of an input string. The transition
function of M is described in the following table. (GATE-2003)
201
Chapter 5
Note:
y FA + tape = FA + 2stack = FA + queue = TM
y TM = FA+ 2 stack
= FA +3 stack
= FA + 4 stack
.
.
.
= FA+ n stack (n ≥ 2)
Recursively enumerable:
y To ensure a language L is recursively enumerable, we have to find a
Turing machine for it.
y Recursive Enumerable can be defined as a Turing machine M, where, for
every w ∈ L,
q0w |-*M x1 qf x2,
with qf a final state.
y If string w is not in the language, then the definition doesn’t say whether
it will go in a non-final state and halt or it may go into an infinite loop.
Fig. 5.7
Recursive language:
1) A formal language for which a standard Turing machine exists, i.e., any
Turing Machine
strings from that language will be accepted by the Turing machine and
the machine halts as well is called recursive language.
202
Chapter 5
2) “The Turing machine that always halt is called Halting TM/decider/Total
Turing machine.”
Fig. 5.8
Conclusion
Fig. 5.9
203
Chapter 5
Chomsky hierarchy:
1) All formal languages are divided into 4 classes by Chomsky and those
class hierarchy known as “Chomsky Hierarchy”.
Fig. 5.10
Note:
Recursive language is not type (0) language. Only recursively enumerable
language is type (0) language.
Turing Machine
204
Chapter 5
Extended Version of Chomsky Hierarchy:
Fig. 5.11
Turing Machine
Fig. 5.12
205
Chapter 5
Theorem 1:
“If a language L and its complement L are both recursively enumerable
then both languages are recursive.”
Theorem 2:
“If L is recursive, then L is also recursive and consequently both are
recursively enumerable.”
Ex.: S → S1B
S1 → aS1b
bB → bbB
aS1B → aa
B→∈
Closure properties of Recursive and Recursive Enumerable Language
Turing Machine
206
Chapter 5
l
Theorem 1:
“For all recursive language ‘L’ there is an enumeration technique for it.”
Proof:
m
Turing Machine
Fig. 5.13
207
Chapter 5
~
If the alphabet is {a, b} then M enumerate strings as follows:
‘a’
‘b’
‘aa’
‘ab’
‘ba’
‘bb’
‘aaa’
‘aab’
…
Enumeration Procedure
Repeat:
~
M generates a string w
M checks if w ∈ L
Yes: Print w to output
No: Ignore w
End of proof.
~
M L(M) Enumeration Output
b b b
aa
ab ab ab
ba
bb bb bb
aab
208
Chapter 5
Note:
Theorem 2:
“A language is recursively enumerable if and only if there is an enumeration
procedure for it.”
209
Chapter 5
y If we limit the Turing machine to use only finite amount of cell and only
unidirectional tape movement is allowed then it can converges into
finite automata.
y If we limit tape of Turing machine to use only that part of the tape
where the input is present and not beyond it, then it converge to LBA
(Linear Bounded Automata).
y A linear bounded automata is designed with an unbounded tape. It
extents up to which the tape needs to be made use of purposely, with
an instant of the input. Practically, the unbounded tape is restricted by
the input string.
y To enforce this, we can envision the input as bracketed by the two
special symbols, the left-end marker and the right-end marker.
y LBA is less powerful than TM and it is more powerful than PDA. Ex.:
anbncn | n ³ 1 is accepted by LBA but not by PDA.
y Here, we don’t know whether the deterministic LBA are equivalent in
power to non-deterministic LBA. It is undecidable.
y Complement of the CFL is CSL.
y Language accepted by LBA is called context sensitive language.
y LBA is halting, Turing machine as context sensitive language is also a
recursive language.
Countability
210
Chapter 5
Hence, the set of odd number is countable.
Uncountable set definition: “A set is uncountable if it is infinite and not
countable.”
Output : 0 2 4 6 8 ...
Steps : 1 2 3 4 5 ...
Output : 1 3 5 7 9 11 ...
Steps : 1 2 3 4 5 6
Turing Machine
211
Chapter 5
SOLVED EXAMPLES
Sol: T he set S is countable since we are having an enumeration procedure for set S.
ere, we don’t go either in increasing order of numerator or denominator, we just
H
add numerator and denominator and we just go in the increasing order of sum.
Here, the smallest number is 1/1.
So, the 1st sum is 2.
Within the sum we can enumerate in increasing order.
1 1 2 1 2 3
So, the enumeration order is , , , , , , ...
1 2 1 3 2 1
Hence, it is countable.
Lexicographic ordering:
y Lexicographic ordering is nothing but the alphabetical order, i.e., the sequence of letters
present in the dictionary.
y Suppose we have a set S = {a, b} and S* in lexicographical order will be {∈, a, b, aa, ab,
ba, bb, aaa, aab, …}
Note:
y Set of all string possible over any alphabet is countable.
y So, Σ* = set of all string over Σ is countable.
y Every subset of countable set is either finite or countable.
y Since every language is a subset of Σ*. Therefore, every language is countable.
y It means given any language it is definitely either countable language or finite language.
Turing Machine
212
Chapter 5
Sol: Since every Turing machine can be encoded as a string of 0’s and 1’s.
Let S = {0, 1} then S* = set of all strings over {0, 1}.
Since, S* is countable and T is subset of S*.
Hence, T = set of all Turing machines.
Implication of the fact that the set of all turing machines are countable:
y Since we know that the set of Turing machines are countable, then the set of recursively
enumerable language are also countable.
y Since the set of recursive language is subset of the set of recursively enumerable
language. Hence, a set of recursive languages is countable.
y Similarly, a set of context free language, a set of context sensitive language, and the set
of regular language are also countable.
y We can also modify a turing machine in such a way that it can act as
PDA. Therefore, if set of TM is countable it implies that the set of PDA is also countable.
y Since, all machines are subset of set of Turing machine. So, the set of LBA, and set of
FA are also countable.
Turing Machine
Fig. 5.14
213
Chapter 5
Theorem:
“set of all languages are uncountable”.
Proof:
Suppose there is a set S = {a, b}.
We need to prove that, 2S* is uncountable.
Let us assume, 2S* is countable.
As, S = {a, b}
S* = {∈, a, b, aa, ab, ba, bb, aaa, aab,....}
Note:
This kind of argument, because it involves a manipulation of the diagonal
elements of a table is called diagonalization.
Turing Machine
214
Chapter 5
Note:
Theorem:
“There exists a recursively enumerable language whose complement is not
recursively enumerable.”
Theorem:
“There exists a recursively enumerable language that is not recursive i.e., the
family of recursive languages is a proper subset of the family of recursively
enumerable languages.”
y Diagonalization method is used to prove that a language is not
recursively enumerable because if for a language, we proved that it
is not countable then it means there is no enumeration procedure for
that language.
And theorem says that a language is Recursive Enumerable Language if
and only if there is enumeration procedure for it. Hence, that language
is not recursively enumerable.
Theorem:
“If S1 and S2 are countable sets, then S1 U S2 and S1 × S2 are countable and
union and cross-product can be extended to any number of finite sets.”
Theorem:
“The set of all languages that are not recursively enumerable is uncountable.”
Proof:
The set of all languages is 2S* (set of all subsets of S*), and out of that some
languages are already recursive enumerable, because if there is TM for a
language then that language is recursively enumerable and we already know
that the number of TM is countable. Therefore, the number of languages in
the total language which is recursively enumerable are countable and that
will be equal to a number of Turing machines.
And in the remaining set, we don’t know anything, so we are just assuming
that it is countable. So, the resulting set is the union of a countable set;
therefore overall, that should be countable. And if that is true, then our
*
initial proof that 2Σ is uncountable is a failure as we know that set of
*
all languages 2Σ is uncountable. Therefore, our assumption that, the
remaining language i.e., the set of all languages that are not- recursively
enumerable is countable, is false. So, set of all languages which are not
recursively enumerable, must be uncountable.
Turing Machine
215
Chapter 5
216
Chapter 5
Grey Matter Alert!
Function
y If f denotes a function, then the first set is called the domain of f and the second
set is its range. We write
f : S1 → S2
to indicate that the domain of f is a subset of S1 and that the range of f is a subset
of S2.
y If the domain of f is all of S1, we say that f is a total function on S1, otherwise f is
said to be a partial function.
Turing Machine
217
Chapter 5
SOLVED EXAMPLES
Sol: 1) E xplanation: It is a CSL because we can give a linear bound automata. We cannot
compare number of X’s and number of Y’s using one stack here.
Turing Machine
218
Chapter 5
Sol: 2) E xplanation: Statement S1 is incorrect because set of all irrational number are
uncountable.
Statement S2: Since L is finite language. So, it is regular. All regular language
are recursively enumerable language and recursively enumerable language are
closed under Kleene closure. Hence, L* is recursively enumerable language.
Sol: 3) Explanation:
S1 : L2 − L1 =
L2 L1
= REL Rec L
= REL Rec L
= RE L.
So, statement S1 is correct.
S2 : L = {wwwk | w∈ (a, b)+} is CSL because for this we can give a LBA.
It needs more than one stack to accept this language L, so it is CSL.
Turing Machine
219
Chapter 5
Sol: 3) Explanation:
L = (L2 L1 ) − L3
= (Rec L REL) − CFL
= (Rec L ∩ REL) – CFL
= REL (CFL)
= REL ∩ CSL = REL.
[Here, Rec L means recursive language,
REL means recursively enumerable language,
CFL means context free language,
Turing Machine
220
Chapter 5
Sol: 1) Explanation: The given grammar is in the form of u → v
where u belongs to (V+T)+ v belongs to (V+T)*
here, V is set of non-terminals and T is set of terminals
Hence, it is unrestricted grammar or type-0 grammar.
Sol: 1) E xplanation:
Recursively enumerable language is not closed under
“complementation” and it is closed under “union”, “intersection”, “concatenation”,
etc.
Sol: 1) E xplanation: In the definition of Turing machine, ‘Q’ represents the “Set of finite
number of states”. Turing Machine
221
Chapter 5
Chapter Summary
222
y Unrestricted Grammar/Type 0 Grammar: A grammar is called unrestricted if all Chapter 5
the productions are of the form X → Y
y where X is in (V + T)+ and Y is in (V + T)*
[Here, V indicates set of variables and T indicates set of terminals]
y Closure Property of Recursive and Recursively Enumerable Language
Turing Machine
223
Chapter 5
y Linear Bound Automata: If we limit the tape of the Turing machine to use only
where the input is present and not beyond it, then it converges to LBA.
y In LBA, whether deterministic LBA is equivalent to non-deterministic LBA is not
known.
y Language accepted by LBA is called context-sensitive language.
y Countable Set: If there persists a one-to-one mapping from the elements of a set
to the set of positive integers, such a set is classified as countable.
y Uncountable Set: A set S is uncountable if it is infinite and not countable.
Turing Machine
224
Chapter 5
y Set of all languages possible is uncountable.
y There exists a recursively enumerable language whose complement is not
recursively enumerable.
y There exists a recursively enumerable language that is not recursive i.e., the family
of recursive language is a proper subset of the family of recursively enumerable
language.
y If S1 and S2 are countable sets, then S1 U S2 and S1 × S2 are countable, and union
and cross-product can be extended to any number of finite sets.
y The set of all languages that are not recursively enumerable is uncountable.
Turing Machine
225