SLIDE 1 1
CS 301 - Lecture 19 Turing Machines
Fall 2008
Review
– Alphabets, strings, languages
– Deterministic Finite and Nondeterministic Automata – Equivalence of NFA and DFA and Minimizing a DFA – Regular Expressions – Regular Grammars – Properties of Regular Languages – Languages that are not regular and the pumping lemma
– Context Free Grammars – Derivations: leftmost, rightmost and derivation trees – Parsing and ambiguity – Simplifications and Normal Forms – Nondeterministic Pushdown Automata – Pushdown Automata and Context Free Grammars – Deterministic Pushdown Automata – Pumping Lemma for context free grammars – Properties of Context Free Grammars
Turing Machines
The Language Hierarchy
* a
Regular Languages Context-Free Languages n nb
a
R
ww
n n n
c b a ww
?
* *b a
?
SLIDE 2 2 * a
Regular Languages Context-Free Languages n nb
a
R
ww
n n n
c b a ww * *b a
Languages accepted by Turing Machines
A Turing Machine
...... ...... Tape Read-Write head Control Unit
The Tape
...... ...... Read-Write head No boundaries -- infinite length The head moves Left or Right ...... ...... Read-Write head The head at each time step:
- 1. Reads a symbol
- 2. Writes a symbol
- 3. Moves Left or Right
SLIDE 3 3
...... ...... Example: Time 0 ...... ...... Time 1
a a c b a b k c
a k
...... ...... Time 1
a b k c
...... ...... Time 2
a k c f
b f
The Input String
...... ......
◊ ◊ ◊ ◊
Blank symbol head
◊ a b c a
Head starts at the leftmost position
Input string ...... ......
◊ ◊ ◊ ◊
Blank symbol head
◊ a b c a
Input string Remark: the input string is never empty
SLIDE 4
4
States & Transitions
1
q
2
q L b a , →
Read Write Move Left
1
q
2
q R b a , →
Move Right Example:
1
q
2
q R b a , →
...... ......
◊ ◊ ◊ ◊ ◊ a b c a
Time 1
1
q
current state ...... ......
◊ ◊ ◊ ◊ ◊ a b c a
Time 1
1
q
2
q R b a , →
...... ......
◊ ◊ ◊ ◊ ◊ a b c b
Time 2
1
q
2
q
...... ......
◊ ◊ ◊ ◊ ◊ a b c a
Time 1
1
q
2
q L b a , →
...... ......
◊ ◊ ◊ ◊ ◊ a b c b
Time 2
1
q
2
q
Example:
SLIDE 5
5
...... ......
◊ ◊ ◊ ◊ ◊ a b c a
Time 1
1
q
2
q R g, → ◊
...... ......
◊ ◊ ◊ ◊ g a b c b
Time 2
1
q
2
q
Example:
Determinism
1
q
2
q R b a , →
Allowed
Not Allowed
3
q L d b , →
1
q
2
q R b a , →
3
q L d a , →
No lambda transitions allowed Turing Machines are deterministic
Partial Transition Function
1
q
2
q R b a , →
3
q L d b , →
...... ......
◊ ◊ ◊ ◊ ◊ a b c a
1
q
Example: No transition for input symbol c Allowed:
Halting
The machine halts if there are no possible transitions to follow
SLIDE 6 6
Example: ...... ......
◊ ◊ ◊ ◊ ◊ a b c a
1
q
1
q
2
q R b a , →
3
q L d b , →
No possible transition HALT!!!
Final States
1
q
2
q
Allowed
1
q
2
q Not Allowed
- Final states have no outgoing transitions
- In a final state the machine halts
Acceptance
Accept Input If machine halts in a final state Reject Input If machine halts in a non-final state
If machine enters an infinite loop
Turing Machine Example
A Turing machine that accepts the language:
* aa
q R a a , → L , ◊ → ◊
1
q
SLIDE 7
7
◊ ◊ ◊ ◊ a a
Time 0
q a q R a a , → L , ◊ → ◊
1
q ◊ ◊ ◊ ◊ a a
Time 1
q a q R a a , → L , ◊ → ◊
1
q ◊ ◊ ◊ ◊ a a
Time 2
q a q R a a , → L , ◊ → ◊
1
q ◊ ◊ ◊ ◊ a a
Time 3
q a q R a a , → L , ◊ → ◊
1
q
SLIDE 8
8
◊ ◊ ◊ ◊ a a
Time 4
1
q a q R a a , → L , ◊ → ◊
1
q
Halt & Accept Rejection Example
q R a a , → L , ◊ → ◊
1
q ◊ ◊ ◊ ◊ b a
Time 0
q a q R a a , → L , ◊ → ◊
1
q ◊ ◊ ◊ ◊ b a
Time 1
q a
No possible Transition Halt & Reject
Infinite Loop Example
q R a a , → L , ◊ → ◊
1
q L b b , →
SLIDE 9
9
◊ ◊ ◊ ◊ b a
Time 0
q a q R a a , → L , ◊ → ◊
1
q L b b , → ◊ ◊ ◊ ◊ b a
Time 1
q a q R a a , → L , ◊ → ◊
1
q L b b , → ◊ ◊ ◊ ◊ b a
Time 2
q a q R a a , → L , ◊ → ◊
1
q L b b , → ◊ ◊ ◊ ◊ b a
Time 2
q a ◊ ◊ ◊ ◊ b a
Time 3
q a ◊ ◊ ◊ ◊ b a
Time 4
q a ◊ ◊ ◊ ◊ b a
Time 5
q a Infinite loop
SLIDE 10 10
Because of the infinite loop:
- The final state cannot be reached
- The machine never halts
- The input is not accepted
Turing Machine Example
Turing machine for the language
} {
n nb
a
q
1
q
2
q
3
q R x a , → R a a , → R y y , → L y b , → L a a , → L y y , → R x x , → R y y , → R y y , →
4
q L , ◊ → ◊ q
1
q
2
q
3
q R x a , → R a a , → R y y , → L y b , → L a a , → L y y , → R x x , → R y y , → R y y , →
4
q L , ◊ → ◊ ◊ ◊ b a q a b
Time 0
◊ q
1
q
2
q
3
q R x a , → R a a , → R y y , → L y b , → L a a , → L y y , → R x x , → R y y , → R y y , →
4
q L , ◊ → ◊ ◊ ◊ b x
1
q a b ◊
Time 1
SLIDE 11
11
q
1
q
2
q
3
q R x a , → R a a , → R y y , → L y b , → L a a , → L y y , → R x x , → R y y , → R y y , →
4
q L , ◊ → ◊ ◊ ◊ b x
1
q a b ◊
Time 2
q
1
q
2
q
3
q R x a , → R a a , → R y y , → L y b , → L a a , → L y y , → R x x , → R y y , → R y y , →
4
q L , ◊ → ◊ ◊ ◊ y x
2
q a b ◊
Time 3
q
1
q
2
q
3
q R x a , → R a a , → R y y , → L y b , → L a a , → L y y , → R x x , → R y y , → R y y , →
4
q L , ◊ → ◊ ◊ ◊ y x
2
q a b ◊
Time 4
q
1
q
2
q
3
q R x a , → R a a , → R y y , → L y b , → L a a , → L y y , → R x x , → R y y , → R y y , →
4
q L , ◊ → ◊ ◊ ◊ y x q a b ◊
Time 5
SLIDE 12
12
q
1
q
2
q
3
q R x a , → R a a , → R y y , → L y b , → L a a , → L y y , → R x x , → R y y , → R y y , →
4
q L , ◊ → ◊ ◊ ◊ y x
1
q x b ◊
Time 6
q
1
q
2
q
3
q R x a , → R a a , → R y y , → L y b , → L a a , → L y y , → R x x , → R y y , → R y y , →
4
q L , ◊ → ◊ ◊ ◊ y x
1
q x b ◊
Time 7
q
1
q
2
q
3
q R x a , → R a a , → R y y , → L y b , → L a a , → L y y , → R x x , → R y y , → R y y , →
4
q L , ◊ → ◊ ◊ ◊ y x x y
2
q ◊
Time 8
q
1
q
2
q
3
q R x a , → R a a , → R y y , → L y b , → L a a , → L y y , → R x x , → R y y , → R y y , →
4
q L , ◊ → ◊ ◊ ◊ y x x y
2
q ◊
Time 9
SLIDE 13
13
q
1
q
2
q
3
q R x a , → R a a , → R y y , → L y b , → L a a , → L y y , → R x x , → R y y , → R y y , →
4
q L , ◊ → ◊ ◊ ◊ y x q x y ◊
Time 10
q
1
q
2
q
3
q R x a , → R a a , → R y y , → L y b , → L a a , → L y y , → R x x , → R y y , → R y y , →
4
q L , ◊ → ◊ ◊ ◊ y x
3
q x y ◊
Time 11
q
1
q
2
q
3
q R x a , → R a a , → R y y , → L y b , → L a a , → L y y , → R x x , → R y y , → R y y , →
4
q L , ◊ → ◊ ◊ ◊ y x
3
q x y ◊
Time 12
q
1
q
2
q
3
q R x a , → R a a , → R y y , → L y b , → L a a , → L y y , → R x x , → R y y , → R y y , →
4
q L , ◊ → ◊ ◊ ◊ y x
4
q x y
◊
Halt & Accept Time 13
SLIDE 14
14
If we modify the machine for the language
} {
n nb
a
we can easily construct a machine for the language
} {
n n n
c b a
Observation:
Formal Definitions for Turing Machines
Transition Function
1
q
2
q R b a , →
) , , ( ) , (
2 1
R b q a q = δ
1
q
2
q L d c , →
) , , ( ) , (
2 1
L d q c q = δ
Transition Function
SLIDE 15
15
Turing Machine:
) , , , , , , ( F q Q M ◊ Γ Σ = δ
States Input alphabet Tape alphabet Transition function Initial state blank Final states
Configuration
◊ ◊ ◊ b a
1
q a
Instantaneous description:
c ◊
ba q ca
1
◊ ◊ y x
2
q a b
Time 4
◊ ◊ y x q a b
Time 5
◊
◊
A Move:
ayb q x xayb q
2
◊ ◊ y x
2
q a b
Time 4
◊ ◊ y x q a b
Time 5
◊
◊ b q xxy yb q xx ayb q x xayb q
1 1 2
◊ ◊ y x
1
q x b
Time 6
◊ ◊ y x
1
q x b
Time 7
◊
◊
SLIDE 16 16 b q xxy yb q xx ayb q x xayb q
1 1 2
b q xxy xayb q
1 2 ∗
Equivalent notation: Initial configuration:
w q0
◊ ◊ b a q a b ◊
w
Input string
The Accepted Language
For any Turing Machine M
} : { ) (
2 1
x q x w q w M L
f ∗
=
Initial state Final state
Standard Turing Machine
- Deterministic
- Infinite tape in both directions
- Tape is the input/output file
The machine we described is the standard:
SLIDE 17 17
What’s Next
– Linz Chapter 1,2.1, 2.2, 2.3, (skip 2.4), 3, 4, 5, 6.1, 6.2, (skip 6.3), 7.1, 7.2, 7.3, (skip 7.4), 8, 9 – JFLAP Chapter 1, 2.1, (skip 2.2), 3, 4, 5, 6, 7, (skip 8), 9
- Next Lecture Topics From 9.2 and 9.3
– Complex Tasks and Turing’s Thesis
- Quiz 3 in Recitation on Wednesday 11/12
– Covers Linz 7.1, 7.2, 7.3, (skip 7.4), 8, and JFLAP 5,6,7 – Closed book, but you may bring one sheet of 8.5 x 11 inch paper with any notes you like. – Quiz will take the full hour
– Homework Due Thursday