Topic 12
Topic 12
2
Turing machine
Definition: A Turing machine (TM) consists of
the following
1. An alphabet of input letters.
2. An input TAPE partitioned into cells, having
infinite many locations in one direction. The
input string is placed on the TAPE starting its
first letter on the cell i, the rest of the TAPE
is initially filled with blanks (’s).
3
Turing machine continued …
Input TAPE
i ii iii iv
a b a ...
TAPE Head
3. A tape Head can read the contents of cell on
the TAPE in one step. It can replace the
character at any cell and can reposition itself to
the next cell to the right or to the left of that it
has just read.
4
Turing machine continued …
Initially the TAPE Head is at the cell i. The
TAPE Head can’t move to the left of cell i.
the location of the TAPE Head is denoted by
.
4. An alphabet of characters that can be printed
on the TAPE by the TAPE Head. may
include the letters of . Even the TAPE Head
can print blank , which means to erase some
character from the TAPE.
5
Turing machine continued …
5. Finite set of states containing exactly one START
state and some (may be none) HALT states that
cause execution to terminate when the HALT
states are entered.
6. A program which is the set of rules, which show
that which state is to be entered when a letter is
read form the TAPE and what character is to be
printed. This program is shown by the states
connected by directed edges labeled by triplet
(letter, letter, direction)
6
Turing machine continued …
It may be noted that the first letter is the
character the TAPE Head reads from the
cell to which it is pointing. The second
letter is what the TAPE Head prints the cell
before it leaves. The direction tells the
TAPE Head whether to move one cell to the
right, R, or one cell to the left, L.
Following is a note
7
Note
It may be noted that there may not be any
outgoing edge at certain state for certain letter to
be read from the TAPE, which creates
nondeterminism in Turing machines. It may also
be noted that at certain state, there can’t be more
than one out going edges for certain letter to be
read from the TAPE. The machine crashes if
there is not path for a letter to be read from the
TAPE and the corresponding string is supposed
to be rejected.
8
Note continued …
To terminate execution of certain input
string successfully, a HALT state must be
entered and the corresponding string is
supposed to be accepted by the TM. The
machine also crashes when the TAPE Head
is instructed to move one cell to the left of
cell i.
Following is an example of TM
9
Example
Consider the following Turing machine
(a,a,R)
(b,b,R)
(a,a,R)
(b,b,R) (,,R)
1 START 2 3 4 HALT
(b,b,R)
TAPE Head
Starting from the START state, reading a
form the TAPE and according to the TM
program, a will be printed i.e. a will be
replaced by a and the TAPE Head will be
moved one cell to the right. 11
Which can be seen as
Input TAPE
i ii iii iv
a b a ...
TAPE Head
This process can be expressed as
1 2
aba aba 12
At state 2 reading b, state 3 is entered and
the letter b is replaced by b, i.e.
1 2 3
aba aba aba
At state 3 reading a, will keep the state of
the TM unchanged. Lastly, the blank is
read and is replaced by and the HALT
state is entered. Which can be expressed as
13
1 2 3 3
HALT
aba aba aba aba
Which shows that the string aba is accepted
by this machine. It can be observed, from
the program of the TM, that the machine
accepts the language expressed by
(a+b)b(a+b)*.
14
Theorem: Every regular language is
accepted by some TM.
Example: Consider the EVEN-EVEN
language. Following is a TM accepting the
EVEN-EVEN language.
15
(b,b,R)
5 HALT (,,R) 1 START 2
(b,b,R)
(b,b,R)
3 4
(b,b,R)
(b,b,R) (a,a,L)
2 3 4
(b,a,R)
(,,R) (a,*,R) (a,a,R)
9 HALT 1 START 5
(*,*,R) (,,L)
(a,a,L)
(b,b,L) (a,,L) (a,,L)
8 7 6
17
Example continued …
The string aaabbbaaa can be observed to be
accepted by the above TM. It can also be
observed that the above TM accepts the
non-CFL {anbnan}.
18
INSERT subprogram
Sometimes, a character is required to be
inserted on the TAPE exactly at the spot
where the TAPE Head is pointing, so that
the character occupies the required cell and
the other characters on the TAPE are moved
one cell right. The characters to the left of
the pointed cell are also required to remain
as such.
19
In the situation stated above, the part of TM
program that executes the process of
insertion does not affect the function that
the TM is performing. The subprogram of
insertion is independent and can be
incorporated at any time with any TM
program specifying what character to be
inserted at what location. The subprogram
of insertion can be expressed as
20
INSERT a
INSERT b
INSERT #
then, it is expressed as
... b X a b b X ...
INSERT b 22
The function of subprogram INSERT b can
be observed from the following diagram
... b X b a b b X ...
23
The subprogram INSERT
Keeping in view the same example of
inserting b at specified location, to
determine the required subprogram, first Q
will be inserted as marker at the required
location, so that the TAPE Head must be
able to locate the proper cell to the right of
the insertion cell. The whole subprogram
INSERT is given as
24
(a,a,R) 2
(a,Q,R) (b,a,R)
(a,b,R)
4 (, X,R) 5
(, b,R) (, ,L)
(X,X,R)
(b,b,L)
7 (Q, b,R) 6 (a,a,L)
(X,X,L)
25
Out
It is supposed that machine is at state 1, when b
is to be inserted. All three possibilities of
reading a, b or X are considered by introducing
the states 2,3 and 4 respectively. These states
remember what letter displaced during the
insertion of Q.
Consider the same location where b is to be
inserted
26
... b X a b b X ...
28
Hence, the required situation of the TAPE
can be shown as
... b X a b b X ...
29
DELETE subprogram
Sometimes, a character is required to be
DELETED on the TAPE exactly at the spot
where the TAPE Head is pointing, so that
the other characters on the right of the
TAPE Head are moved one cell left. The
characters to the left of the pointed cell are
also required to remain as such.
30
In the situation stated above, the part of TM
program that executes the process of
deletion does not affect the function that the
TM is performing. The subprogram of
deletion is independent and can be
incorporated at any time with any TM
program specifying what character to be
deleted at what location. The subprogram of
deletion can be expressed as
31
Example
If the letter a is to be deleted from the string
bcabbc, shown below
... b c a b b c ...
then, it is expressed as
... b c a b b c ...
DELETE 32
The function of subprogram DELETE can
be observed from the following diagram
... b c b b c . ..
33
(a,a,R)
(b,b,R)
In (c,c,R)
1 (c,,R) 2 (,,L) 3
(b,,R)
(a,,R)
(b, ,L) (c,,L)
Out 7 34
The process of deletion of letter a from the
string bcabbc can easily be checked, giving
the TAPE situation as shown below
... b c b b c . ..
35
Summing Up
Turing machine, examples, DELETE
subprogram, example, INSERT
subprogram, example.
36