3. The mathematical models (FAs, TGs, PDAs) that have been
discussed so far can decide whether a string is accepted
or not by them i.e. these models are language identifiers.
However, there are still some languages which can’t be
accepted by them e.g. there does not exist any FA or TG
or PDA accepting any non-CFLs.
Alan Mathison Turing developed the machines called
Turing machines, which accept some non-CFLs as well, in
addition to CFLs.
3
6. 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).
6
7. 3. A tape Head that can read the contents of cell on
the TAPE in one step and it can replace the
character at the cell and can reposition itself to
the next cell to the right or to the left of that it
has just read.
. . .
∆
a
b
a
iv
iii
ii
i
TAPE Head
Input TAPE
7
8. 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.
8
9. 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)
9
10. It may be noted that in the triplet on any edge
(a, b, R) the first letter, a , is the character the
TAPE Head reads from the cell to which it is
pointing. The second letter, b , is what the
TAPE Head prints the cell before it leaves. The
third letter, R , signifies the direction the TAPE
Head whether to move one cell to the right, R,
or one cell to the left, L. Following is a note
10
11. 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 non-determinism 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 a path for
a letter to be read from the TAPE and the
corresponding string is supposed to be rejected.
11
12. 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
12
13. Consider the following Turing machine
Let the input string aba be run over this TM
(a,a,R)
3
1 START 4 HALT
(b,b,R)
(b,b,R)
(b,b,R)
(a,a,R)
(∆, ∆,R)
2
13
14. Example continued …
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.
. . .
∆
a
b
a
iv
iii
ii
i
TAPE Head
Input TAPE
14
15. Chapter 19: Turing Machines
3
(a,a,R)
(b,b,R)
∆
∆
(a,a,R)
(b,b,R)
2
(b,b,R)
START 1 HALT 4
(∆,∆,R)
a …
b a ∆
1 → 2 → 3 → 3 → HALT
aba aba aba abaΔ
a …
b a ∆
…
a b a
∆
1
5
16. 1
6
◼ Theorem. For every regular language, there is a Turing
machine that accepts it.
Proof: We transform a finite automaton to a Turing
machine.
◼ The start state of the finite automaton is the start state of the
Turing machine.
◼ Add a halt state to the Turing machine, and one transition from
every final state of the finite automaton to the new halt state.
(Erase all the + symbols.) Label the new transitions
(∆,∆,R).
◼ Change each label a of the finite automaton to (a,a,R), and
similarly for all other letters of Σ.
18. 1 START
9 HALT
(∆, ∆,R) (a,*,R)
(*,*,R)
(a,a,L)
(b,b,L) (a, ∆,L) (a, ∆,L)
(∆, ∆,L)
(a,a,R)
(b,a,R)
(a,a,L)
(b,b,R)
(b,b,R)
(a,a,R)
6
2 3 4
5
7
8
Example
Consider the following TM
18
anbnan
19. 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}.
19
20. 20
Must have double ‘aa’
1. Those with a double a. They are accepted by the TM.
2. Those without aa that end in a. They crash.
3. Those without aa that end in b. They loop forever.
21. 21
DEFINITION
Every Turing machine T over the alphabet divides the set of strings into three
classes:
1. ACCEPT(T) is the set of all strings leading to a HALT state. This is also
called the language accepted by T.
2. REJECT(T) is the set of all strings that crash during execution by moving left
from cell i or by being in a state that has no exit edge that wants to read the
character the TAPE HEAD is reading.
3. LOOP(T) is the set of all other strings, that is, strings that loop forever while
running on T.
22. 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.
22
23. 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
23
24. INSERT a
INSERT b
INSERT #
The above diagrams show that the characters a,b
and # are to be inserted, respectively. Following is
an example showing how does the subprogram
INSERT perform its function
24
25. If the letter b is inserted at the cell where the
TAPE Head is pointing as shown below
then, it is expressed as
∆. . .
∆
X
b
b
a
X
b
. . .
INSERT b
∆. . .
∆
X
b
b
a
X
b
. . .
25
26. The function of subprogram INSERT b can be
observed from the following diagram
Following is the INSERT subprogram
∆. . .
∆
X
b
b
a
b
X
b
. . .
26
27. 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
27
29. 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
29
30. After reading a from the TAPE, the program
replaces a by Q and the TAPE Head will be
moved one step right. Here the state 2 is
entered. Reading b at state 2, b will be replaced
by a and state 3 will be entered. At state 3 b is
read which is not replaced by any character and
the state 3 will not be left.
∆. . .
∆
X
b
b
a
X
b
. . .
30
31. At state 3, the next letter to be read is X, which will be
replaced by b and the state 4 will be entered. At state
4, ∆ will be read, which will be replaced by X and state
5 will be entered. At state 5 ∆ will be read and without
any change state 6 will be entered, while TAPE Head
will be moved one step left. The state 6 makes no
change whatever (except Q) is read at that state.
However at each step, the TAPE Head is moved one
step left. Finally, Q is read which is replaced by b and
the TAPE Head is moved to one step right.
31
33. Hence, the required situation of the TAPE can
be shown as
∆. . .
∆
X
b
b
a
X
b
. . .
33
34. 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.
34
35. 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
35
36. If the letter a is to be deleted from the string
bcabbc, shown below
then, it is expressed as
∆. . .
∆
c
b
b
a
c
b
. . .
DELETE
∆. . .
∆
c
b
b
a
c
b
. . .
36
37. The function of subprogram DELETE can be
observed from the following diagram
Following is the DELETE subprogram
. .
.
∆
∆
c
b
b
c
b
. . .
37
39. The process of deletion of letter a from the
string bcabbc can easily be checked, giving the
TAPE situation as shown below
. .
.
∆
∆
c
b
b
c
b
. . .
39
45. 45
The language this TM accepts is DOUBLEWORD, the set of all words of the
form ww where w is a nonnull string in {a, b}*.
DOUBLEWORD = {aa bb aaaa abab baba bbbb aaaaaa aabaab . . }
Double Word Problem
47. Let us define a two-stack pushdown automaton
as follows
M = (K, , , D, s, F)
K is a finite set of states,
is an alphabet (the input symbols),
is an alphabet (the stack symbols),
s K is the start state,
F K is the set of final states, and
Finite set of transition from one state to
another state
47
48. As we have two stacks for storage purpose, so
change the name of POP and PUSH stack
accordingly.
POP1 will pop from the first stack
POP2 will pop from the second stack
PUSH1 will push into first stack
PUSH2 will push into second stack
48
51. Minsky’s Theorem
Theorem:
Any language accepted by a 2PDA can be
accepted by some TM and any language
accepted by a TM can also accepted by 2PDA.
Proof :
2PDA has 3 locations for storage
1. Stack1
2. Stack2
3. Input Tape
51