You are on page 1of 46

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

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
...... 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

Input string Blank symbol

......   a b a c    ......

head

Head starts at the leftmost position


of the input string
9
Input string Blank symbol

......   a b a c    ......

head

Remark: the input string is never empty

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

Allowed Not Allowed


a  b, R q2 a  b, R q2

q1 q1
q3 a  d, L q3
b  d, L

No lambda transitions allowed


16
Partial Transition Function
Example:

......   a b a c    ......

q1

a  b, R q2 Allowed:

q1 No transition
for input symbol c
b  d, L q3
17
Halting

The machine halts if there are


no possible transitions to follow

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

• Final states have no outgoing transitions

• In a final state the machine halts


20
Acceptance

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 Turing machine that accepts the language:


aa *

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

a  a, R Halt & Accept

  , 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:

•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:

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

A Move: q2 xayb  x q0 ayb

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

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

 a a b b  

q0

44
The Accepted Language

For any Turing Machine M


L( M )  {w : 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

You might also like