Professional Documents
Culture Documents
ch9 Turing Machines
ch9 Turing Machines
1
The Language Hierarchy
n n n ?
a b c ww ?
Context-Free Languages
n n R
a b ww
Regular Languages
a* a *b *
2
Languages accepted by
Turing Machines
n n n
a b c ww
Context-Free Languages
n n R
a b ww
Regular Languages
a* a *b *
3
A Turing Machine
Tape
...... ......
Read-Write head
Control Unit
4
The Tape
Read-Write head
5
...... ......
Read-Write head
1. Reads a symbol
2. Writes a symbol
3. Moves Left or Right
6
Example:
Time 0
...... a b a c ......
Time 1
...... a b k c ......
1. Reads a
2. Writes k
3. Moves Left
7
Time 1
...... a b k c ......
Time 2
...... a f k c ......
1. Reads b
2. Writes f
3. Moves Right
8
The Input String
...... a b a c ......
head
...... a b a c ......
head
10
States & Transitions
Read Write
Move Left
q1 a b, L q2
Move Right
q1 a b, R q2
11
Example:
Time 1
...... a b a c ......
q1
current state
q1 a b, R q2
12
Time 1
...... a b a c ......
q1
Time 2
...... a b b c ......
q2
q1 a b, R q2
13
Example:
Time 1
...... a b a c ......
q1
Time 2
...... a b b c ......
q2
q1 a b, L q2
14
Example:
Time 1
...... a b a c ......
q1
Time 2
...... a b b c g ......
q2
q1 g, R q2
15
Determinism
Turing Machines are deterministic
q1 q1
q3 a d, L q3
b d, L
...... a b a c ......
q1
a b, R q2 Allowed:
q1 No transition
for input symbol c
b d, L q3
17
Halting
18
Example:
...... a b a c ......
q1
a b, R q2
No possible transition
q1
HALT!!!
b d, L q3
19
Final States
q1 q2 Allowed
q1 q2 Not Allowed
If machine halts
Accept Input
in a final state
If machine halts
in a non-final state
Reject Input or
If machine enters
an infinite loop
21
Turing Machine Example
a a, R
, L
q0 q1
22
Time 0 a a a
q0
a a, R
, L
q0 q1
23
Time 1 a a a
q0
a a, R
, L
q0 q1
24
Time 2 a a a
q0
a a, R
, L
q0 q1
25
Time 3 a a a
q0
a a, R
, L
q0 q1
26
Time 4 a a a
q1
, L
q0 q1
27
Rejection Example
Time 0 a b a
q0
a a, R
, L
q0 q1
28
Time 1 a b a
q0
No possible Transition
a a, R Halt & Reject
, L
q0 q1
29
Infinite Loop Example
A Turing machine
for language aa * b( a b) *
b b, L
a a, R
, L
q0 q1
30
Time 0 a b a
q0
b b, L
a a, R
, L
q0 q1
31
Time 1 a b a
q0
b b, L
a a, R
, L
q0 q1
32
Time 2 a b a
q0
b b, L
a a, R
, L
q0 q1
33
Time 2 a b a
q0
Time 3 a b a
Infinite loop
q0
Time 4 a b a
q0
Time 5 a b a
q0
34
Because of the infinite loop:
35
Formal Definitions
for
Turing Machines
36
Transition Function
q1 a b, R q2
(q1, a) (q2 , b, R)
37
Transition Function
q1 c d, L q2
(q1, c) (q2 , d , L)
38
Turing Machine:
Input Tape
alphabet alphabet
States
M (Q, , , , q0 , , F )
Transition Final
function states
Initial blank
state 39
Configuration
c a b a
q1
Instantaneous description: ca q1 ba
40
Time 4 Time 5
x a y b x a y b
q2 q0
41
Time 4 Time 5
x a y b x a y b
q2 q0
Time 6 Time 7
x x y b x x y b
q1 q1
Equivalent notation: q2 xayb xxy q1 b
43
Initial configuration: q0 w
Input string
a a b b
q0
44
The Accepted Language
L( M ) {w : q0 w x1 q f x2 }
45
Standard Turing Machine
• Deterministic
46