Languages and Finite Automata

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
ww
n n n
a b c
Context-Free Languages
n n
R
a b
ww
Regular Languages
a*
a *b *
3
Tape
......
A Turing Machine
......
Read-Write head
Control Unit
4
The Tape
No boundaries -- infinite length
......
......
Read-Write head
The head moves Left or Right
5
......
......
Read-Write head
The head at each time step:
1. Reads a symbol
2. Writes a symbol
3. Moves Left or Right
6
Example:
Time 0
......
a b a c
Time 1
......
1. Reads
2. Writes
a b k c
......
......
a
k
3. Moves Left
7
Time 1
......
a b k c
Time 2
......
1. Reads
2. Writes
a f k c
......
......
b
f
3. Moves Right
8
The Input String
Input string
......
  a b a c
Blank symbol
  
......
head
Head starts at the leftmost position
of the input string
9
Input string
......
  a b a c
Blank symbol
  
......
head
Remark: the input string is never empty
10
States & Transitions
Read
q1
Write
a  b, L
Move Left
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
Not Allowed
Allowed
a  b, R
q2
a  b, R
q2
a  d, L
q3
q1
q1
b  d, L
q3
No lambda transitions allowed
16
Partial Transition Function
Example:
......
  a b a c
  
......
q1
a  b, R
q2
q1
b  d, L
q3
Allowed:
No transition
for input symbol
c
17
Halting
The machine halts if there are
no possible transitions to follow
18
Example:
......
  a b a c
  
......
q1
a  b, R
q2
q1
b  d, L
q3
No possible transition
HALT!!!
19
Final States
q1
q2
Allowed
q1
q2
Not Allowed
• Final states have no outgoing transitions
• In a final state the machine halts
20
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
21
Turing Machine Example
A Turing machine that accepts the language:
aa *
a  a, R
q0
  , L
q1
22
Time 0
  a a a  
q0
a  a, R
q0
  , L
q1
23
Time 1
  a a a  
q0
a  a, R
q0
  , L
q1
24
Time 2
  a a a  
q0
a  a, R
q0
  , L
q1
25
Time 3
  a a a  
q0
a  a, R
q0
  , L
q1
26
Time 4
  a a a  
q1
a  a, R
q0
Halt & Accept
  , L
q1
27
Rejection Example
Time 0
  a b a  
q0
a  a, R
q0
  , L
q1
28
Time 1
  a b a  
q0
No possible Transition
Halt & Reject
a  a, R
q0
  , L
q1
29
Infinite Loop Example
A Turing machine
for language aa * b( a  b) *
b  b, L
a  a, R
q0
  , L
q1
30
Time 0
  a b a  
q0
b  b, L
a  a, R
q0
  , L
q1
31
Time 1
  a b a  
q0
b  b, L
a  a, R
q0
  , L
q1
32
Time 2
  a b a  
q0
b  b, L
a  a, R
q0
  , L
q1
33
Time 2
  a b a  
q0
  a b a  
q0
Time 4
  a b a  
q0
Time 5
  a b a  
q0
Infinite loop
Time 3
34
Because of the infinite loop:
•The final state cannot be reached
•The machine never halts
•The input is not accepted
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:
States
Input
alphabet
Tape
alphabet
M  (Q, , ,  , q0 , , F )
Transition
function
Initial
state
Final
states
blank
39
Configuration
  c a b a  
q1
Instantaneous description:
ca q1 ba
40
Time 4
Time 5
 x a y b  
q2
A Move:
 x a y b  
q0
q2 xayb  x q0 ayb
41
Time 4
 x a y b  
Time 5
 x a y b  
q0
q2
Time 6
 x x y b  
q1
Time 7
 x x y b  
q1
q2 xayb  x q0 ayb  xx q1 yb  xxy q1 b
42
q2 xayb  x q0 ayb  xx q1 yb  xxy q1 b

Equivalent notation:
q2 xayb  xxy q1 b
43
Initial configuration:
q0 w
Input string
w
 a a b b  
q0
44
The Accepted Language
For any Turing Machine
L( M )  {w :
M

q0 w  x1 q f x2 }
Initial state
Final state
45
Standard Turing Machine
The machine we described is the standard:
• Deterministic
• Infinite tape in both directions
•Tape is the input/output file
46