TM Daami
TM Daami
Turing Machines –
–
Properties of Regular Languages
Languages that are not regular and the pumping lemma
• Context Free Languages
– Context Free Grammars
Fall 2008 –
–
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
1
Languages accepted by
Tape A Turing Machine
Turing Machines ...... ......
n n n
a b c ww
Read-Write head
Context-Free Languages
n n Control Unit
a b R
ww
Regular Languages
a* a *b *
...... ......
The Tape
No boundaries -- infinite length
...... ...... Read-Write head
1. Reads a symbol
2. Writes a symbol
The head moves Left or Right 3. Moves Left or Right
2
Example:
Time 1
Time 0
...... a b k c ......
...... a b a c ......
Time 1 Time 2
...... ...... ...... a f k c ......
a b k c
1. Reads a 1. Reads b
2. Writes k 2. Writes f
3. Moves Left 3. Moves Right
head head
3
Example:
Time 1
States & Transitions
Read Write ...... ◊ ◊ a b a c ......
Move Left ◊ ◊ ◊
q1
q1 a → b, L q2 current state
Move Right
q1 a → b, R q2
q1 a → b, R q2
Example:
Time 1 Time 1
...... ◊ ◊ a b a c ◊ ◊ ◊ ...... ...... ◊ ◊ a b a c ◊ ◊ ◊ ......
q1 q1
Time 2 Time 2
...... ◊ ◊ a b b c ◊ ◊ ◊ ...... ...... ◊ ◊ a b b c ◊ ◊ ◊ ......
q2 q2
q1 a → b, R q2 q1 a → b, L q2
4
Example:
Time 1 Determinism
...... ◊ ◊ a b a c ◊ ◊ ◊ ...... Turing Machines are deterministic
a → b, R q2 Allowed:
q1 No transition
for input symbol c
b → d, L q3
5
Example:
Final States
q1 q2 Allowed
...... ◊ ◊ a b a c ◊ ◊ ◊ ......
q1
q1 q2 Not Allowed
a → b, R q2
No possible transition
q1 • Final states have no outgoing transitions
HALT!!!
b → d, L q3
• In a final state the machine halts
If machine halts a → a, R
in a non-final state
Reject Input or
◊ → ◊, L
If machine enters q0 q1
an infinite loop
6
Time 0 ◊ ◊ a a a ◊ ◊ Time 1 ◊ ◊ a a a ◊ ◊
q0 q0
a → a, R a → a, R
◊ → ◊, L ◊ → ◊, L
q0 q1 q0 q1
Time 2 ◊ ◊ a a a ◊ ◊ Time 3 ◊ ◊ a a a ◊ ◊
q0 q0
a → a, R a → a, R
◊ → ◊, L ◊ → ◊, L
q0 q1 q0 q1
7
Rejection Example
Time 4 ◊ ◊ a a a ◊ ◊
q1 Time 0 ◊ ◊ a b a ◊ ◊
q0
q0
b → b, L
No possible Transition a → a, R
a → a, R Halt & Reject
◊ → ◊, L
q0 q1
◊ → ◊, L
q0 q1
8
Time 0 ◊ ◊ a b a ◊ ◊ Time 1 ◊ ◊ a b a ◊ ◊
q0 q0
b → b, L b → b, L
a → a, R a → a, R
◊ → ◊, L ◊ → ◊, L
q0 q1 q0 q1
Time 2 ◊ ◊ a b a ◊ ◊ Time 2 ◊ ◊ a b a ◊ ◊
q0
q0
Time 3 ◊ ◊ a b a ◊ ◊
Infinite loop
q0
b → b, L
a → a, R Time 4 ◊ ◊ a b a ◊ ◊
q0
◊ → ◊, L
q0 q1 ◊ ◊ a b a ◊ ◊
Time 5
q0
9
Because of the infinite loop:
Turing Machine Example
Turing machine for the language {a nb n }
•The final state cannot be reached
y → y, R a → x, R b → y, L
q3 q0 q1 q2
x → x, R
Time 0 ◊ a a b b ◊ ◊ Time 1 ◊ x a b b ◊ ◊
q0 q1
q4 y → y, R y → y, L q4 y → y, R y → y, L
y → y, R a → a, R a → a, L y → y, R a → a, R a → a, L
◊ → ◊, L ◊ → ◊, L
y → y, R a → x, R b → y, L y → y, R a → x, R b → y, L
q3 q0 q1 q2 q3 q0 q1 q2
x → x, R x → x, R
10
Time 2 ◊ x a b b ◊ ◊ Time 3 ◊ x a y b ◊ ◊
q1 q2
q4 y → y, R y → y, L q4 y → y, R y → y, L
y → y, R a → a, R a → a, L y → y, R a → a, R a → a, L
◊ → ◊, L ◊ → ◊, L
y → y, R a → x, R b → y, L y → y, R a → x, R b → y, L
q3 q0 q1 q2 q3 q0 q1 q2
x → x, R x → x, R
Time 4 ◊ x a y b ◊ ◊ Time 5 ◊ x a y b ◊ ◊
q2 q0
q4 y → y, R y → y, L q4 y → y, R y → y, L
y → y, R a → a, R a → a, L y → y, R a → a, R a → a, L
◊ → ◊, L ◊ → ◊, L
y → y, R a → x, R b → y, L y → y, R a → x, R b → y, L
q3 q0 q1 q2 q3 q0 q1 q2
x → x, R x → x, R
11
Time 6 ◊ x x y b ◊ ◊ Time 7 ◊ x x y b ◊ ◊
q1 q1
q4 y → y, R y → y, L q4 y → y, R y → y, L
y → y, R a → a, R a → a, L y → y, R a → a, R a → a, L
◊ → ◊, L ◊ → ◊, L
y → y, R a → x, R b → y, L y → y, R a → x, R b → y, L
q3 q0 q1 q2 q3 q0 q1 q2
x → x, R x → x, R
Time 8 ◊ x x y y ◊ ◊ Time 9 ◊ x x y y ◊ ◊
q2 q2
q4 y → y, R y → y, L q4 y → y, R y → y, L
y → y, R a → a, R a → a, L y → y, R a → a, R a → a, L
◊ → ◊, L ◊ → ◊, L
y → y, R a → x, R b → y, L y → y, R a → x, R b → y, L
q3 q0 q1 q2 q3 q0 q1 q2
x → x, R x → x, R
12
Time 10 ◊ x x y y ◊ ◊ Time 11 ◊ x x y y ◊ ◊
q0 q3
q4 y → y, R y → y, L q4 y → y, R y → y, L
y → y, R a → a, R a → a, L y → y, R a → a, R a → a, L
◊ → ◊, L ◊ → ◊, L
y → y, R a → x, R b → y, L y → y, R a → x, R b → y, L
q3 q0 q1 q2 q3 q0 q1 q2
x → x, R x → x, R
Time 12 ◊ x x y y ◊ ◊ Time 13 ◊ x x y y ◊ ◊
q3 q4
Halt & Accept
q4 y → y, R y → y, L q4 y → y, R y → y, L
y → y, R a → a, R a → a, L y → y, R a → a, R a → a, L
◊ → ◊, L ◊ → ◊, L
y → y, R a → x, R b → y, L y → y, R a → x, R b → y, L
q3 q0 q1 q2 q3 q0 q1 q2
x → x, R x → x, R
13
Observation:
q1 a → b, R q2 q1 c → d, L q2
14
Turing Machine:
q2 q0 q2 q0
Time 6 Time 7
◊ x x y b ◊ ◊ ◊ x x y b ◊ ◊
A Move: q2 xayb x q0 ayb
q1 q1
15
Initial configuration: q0 w
q2 xayb x q0 ayb xx q1 yb xxy q1 b
Input string
∗
w
Equivalent notation: q2 xayb xxy q1 b
◊ a a b b ◊ ◊
q0
∗
• Deterministic
L( M ) = {w : q0 w x1 q f x2 }
• Infinite tape in both directions
16
What’s Next
• Read
– 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
– Homework Due Thursday
17