1 Turing Machines
Mar 29, 2015
1
Turing Machines
2
A Turing Machine
............Tape
Read-Write head
Control Unit
3
The Tape
............
Read-Write head
No boundaries -- infinite length
The head moves Left or Right
4
............
Read-Write head
The head at each time step:
1. Reads a symbol 2. Writes a symbol 3. Moves Left or Right
5
............
Example:Time 0
............Time 1
1. Reads
2. Writes
a a cb
a b k c
a
k3. Moves Left
6
............Time 1
a b k c
............Time 2
a k cf
1. Reads
2. Writes
bf
3. Moves Right
7
The Input String
............
Blank symbol
head
a b ca
Head starts at the leftmost positionof the input string
Input string
8
............
Blank symbol
head
a b ca
Input string
Remark: the input string is never empty
9
States & Transitions
1q 2qLba ,
Read Write Move Left
1q 2qRba ,
Move Right
10
Example:
1q 2qRba ,
............ a b ca
Time 1
1qcurrent state
11
............ a b caTime 1
1q 2qRba ,
............ a b cbTime 2
1q
2q
12
............ a b caTime 1
1q 2qLba ,
............ a b cbTime 2
1q
2q
Example:
13
............ a b caTime 1
1q 2qRg,
............ ga b cbTime 2
1q
2q
Example:
14
Determinism
1q
2qRba ,
Allowed Not Allowed
3qLdb ,
1q
2qRba ,
3qLda ,
No lambda transitions allowed
Turing Machines are deterministic
15
Partial Transition Function
1q
2qRba ,
3qLdb ,
............ a b ca
1q
Example:
No transitionfor input symbol c
Allowed:
16
Halting
The machine halts if there areno possible transitions to follow
17
Example:
............ a b ca
1q
1q
2qRba ,
3qLdb ,
No possible transition
HALT!!!
18
Final States
1q 2q Allowed
1q 2q Not Allowed
• Final states have no outgoing transitions
• In a final state the machine halts
19
Acceptance
Accept Input If machine halts in a final state
Reject Input
If machine halts in a non-final state or If machine enters an infinite loop
20
Turing Machine Example
A Turing machine that accepts the language:
*aa
0q
Raa ,
L,1q
21
aaTime 0
0q
a
0q
Raa ,
L,1q
22
aaTime 1
0q
a
0q
Raa ,
L,1q
23
aaTime 2
0q
a
0q
Raa ,
L,1q
24
aaTime 3
0q
a
0q
Raa ,
L,1q
25
aaTime 4
1q
a
0q
Raa ,
L,1q
Halt & Accept
26
Rejection Example
0q
Raa ,
L,1q
baTime 0
0q
a
27
0q
Raa ,
L,1q
baTime 1
0q
a
No possible Transition
Halt & Reject
28
Infinite Loop Example
0q
Raa ,
L,1q
Lbb ,
A Turing machine for language *)(* babaa
29
baTime 0
0q
a
0q
Raa ,
L,1q
Lbb ,
30
baTime 1
0q
a
0q
Raa ,
L,1q
Lbb ,
31
baTime 2
0q
a
0q
Raa ,
L,1q
Lbb ,
32
baTime 2
0q
a
baTime 3
0q
a
baTime 4
0q
a
baTime 5
0q
a
Infinite
loop
33
Because of the infinite loop:
•The final state cannot be reached
•The machine never halts
•The input is not accepted
34
Another Turing Machine Example
Turing machine for the language }{ nnba
0q 1q 2q3qRxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx ,
Ryy ,
Ryy ,4q
L,
35
0q 1q 2q3qRxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx ,
Ryy ,
Ryy ,4q
L,
ba
0q
a bTime 0
36
0q 1q 2q3qRxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx ,
Ryy ,
Ryy ,4q
L,
bx
1q
a b Time 1
37
0q 1q 2q3qRxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx ,
Ryy ,
Ryy ,4q
L,
bx
1q
a b Time 2
38
0q 1q 2q3qRxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx ,
Ryy ,
Ryy ,4q
L,
yx
2q
a b Time 3
39
0q 1q 2q3qRxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx ,
Ryy ,
Ryy ,4q
L,
yx
2q
a b Time 4
40
0q 1q 2q3qRxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx ,
Ryy ,
Ryy ,4q
L,
yx
0q
a b Time 5
41
0q 1q 2q3qRxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx ,
Ryy ,
Ryy ,4q
L,
yx
1q
x b Time 6
42
0q 1q 2q3qRxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx ,
Ryy ,
Ryy ,4q
L,
yx
1q
x b Time 7
43
0q 1q 2q3qRxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx ,
Ryy ,
Ryy ,4q
L,
yx x y
2q
Time 8
44
0q 1q 2q3qRxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx ,
Ryy ,
Ryy ,4q
L,
yx x y
2q
Time 9
45
0q 1q 2q3qRxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx ,
Ryy ,
Ryy ,4q
L,
yx
0q
x y Time 10
46
0q 1q 2q3qRxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx ,
Ryy ,
Ryy ,4q
L,
yx
3q
x y Time 11
47
0q 1q 2q3qRxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx ,
Ryy ,
Ryy ,4q
L,
yx
3q
x y Time 12
48
0q 1q 2q3qRxa ,
Raa ,Ryy ,
Lyb ,
Laa ,Lyy ,
Rxx ,
Ryy ,
Ryy ,4q
L,
yx
4q
x y
Halt & Accept
Time 13
49
If we modify the machine for the language }{ nnba
we can easily construct a machine for the language }{ nnn cba
Observation:
50
Formal Definitionsfor
Turing Machines
51
Transition Function
1q 2qRba ,
),,(),( 21 Rbqaq
52
1q 2qLdc ,
),,(),( 21 Ldqcq
Transition Function
53
Turing Machine:
),,,,,,( 0 FqQM
States
Inputalphabet
Tapealphabet
Transitionfunction
Initialstate
blank
Finalstates
54
Assignment (10%)Form a group consist <= 4 members.Find the implementation/usage/ function/benefit of:
1.FA/NFA2.Content Free Language/Grammar3.Pushdown Automata4.Turing Machine
Due date: during next week class55