You are on page 1of 14

Turing Machine

By
Dr.Biplab Das
• Turing machine was invented in 1936 by Alan Turing. It is an accepting device which
accepts Recursive Enumerable Language generated by type 0 grammar.
• There are various features of the Turing machine:
• It has an external memory which remembers arbitrary long sequence of input.
• It has unlimited memory capability.
• The model has a facility by which the input at left or right on the tape can be read
easily.
• The machine can produce a certain output based on its input. Sometimes it may be
required that the same input has to be used to generate the output. So in this
machine, the distinction between input and output has been removed. Thus a
common set of alphabets can be used for the Turing machine.
• Formal definition of Turing machine
• A Turing machine can be defined as a collection of 7 components:
• Q: the finite set of states
∑: the finite set of input symbols
T: the tape symbol
q0: the initial state
F: a set of final states
B: a blank symbol used as a end marker for input
δ: a transition or mapping function.
• 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.
• The simulation for 0011 can be shown as below:


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 marked 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.
• Basic Model of 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.
• 3. A finite set of states through which machine has to undergo.
• 4. Finite set of symbols called external symbols which are used in building the logic of
turing machine.
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.
• Undecidability of Universal Languages:
• The universal language Lu is a recursively enumerable language and we have to prove that it is
undecidable (non-recursive).
• Theorem: Lu is RE but not recursive.
• Proof:
• Consider that language Lu is recursively enumerable language. We will assume that Lu is
recursive. Then the complement of Lu that is L`u is also recursive. However, if we have a TM M to
accept L`u then we can construct a TM Ld. But Ld the diagonalization language is not RE. Thus our
assumption that Lu is recursive is wrong (not RE means not recursive). Hence we can say that
Lu is RE but not recursive. The construction of M for Ld is as shown in the following diagram:
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.
Pumping Lemma For Regular Grammars
Theorem
• Let L be a regular language. Then there exists a
constant ‘c’ such that for every string w in L −
|w| ≥ c
• We can break w into three strings, w = xyz, such that −
• |y| > 0
• |xy| ≤ c
• For all k ≥ 0, the string xykz is also in L.
Applications of Pumping Lemma
• Pumping Lemma is to be applied to show that certain
languages are not regular. It should never be used to show a
language is regular.
• If L is regular, it satisfies Pumping Lemma.
• If L does not satisfy Pumping Lemma, it is non-regular.
Method to prove that a language L is not regular
• At first, we have to assume that L is regular.
• So, the pumping lemma should hold for L.
• Use the pumping lemma to obtain a contradiction
– Select w such that |w| ≥ c
– Select y such that |y| ≥ 1
– Select x such that |xy| ≤ c
– Assign the remaining string to z.
– Select k such that the resulting string is not in L.
• Hence L is not regular.
Problem
Prove that L = {aibi | i ≥ 0} is not regular.
• Solution −
• At first, we assume that L is regular and n is the
number of states.
• Let w = anbn. Thus |w| = 2n ≥ n.
• By pumping lemma, let w = xyz, where |xy| ≤ n.
• Let x = ap, y = aq, and z = arbn, where p + q + r = n, p ≠
0, q ≠ 0, r ≠ 0. Thus |y| ≠ 0.
• Let k = 2. Then xy2z = apa2qarbn.
• Number of as = (p + 2q + r) = (p + q + r) + q = n + q
• Hence, xy2z = an+q bn. Since q ≠ 0, xy2z is not of the
form anbn.
• Thus, xy2z is not in L. Hence L is not regular.
Pumping Lemma for CFG
• If L is a context-free language, there is a pumping length p such that any string w
∈ L of length ≥ p can be written as w = uvxyz, where vy ≠ ε, |vxy| ≤ p, and for all i
≥ 0, uvixyiz ∈ L.
Applications of Pumping Lemma
• Pumping lemma is used to check whether a grammar is context free or not. Let
us take an example and show how it is checked.
Problem
• Find out whether the language L = {xnynzn | n ≥ 1} is context free or not.
Solution
• Let L is context free. Then, L must satisfy pumping lemma.
• At first, choose a number n of the pumping lemma. Then, take z as 0n1n2n.
• Break z into uvwxy, where
• |vwx| ≤ n and vx ≠ ε.
• Hence vwx cannot involve both 0s and 2s, since the last 0 and the first 2 are at
least (n+1) positions apart. There are two cases −
• Case 1 − vwx has no 2s. Then vx has only 0s and 1s. Then uwy, which would have
to be in L, has n 2s, but fewer than n 0s or 1s.
• Case 2 − vwx has no 0s.
• Here contradiction occurs.
• Hence, L is not a context-free language.

You might also like