Turing Machines Context-Free Languages n b n R a ww Regular - - PDF document

turing machines
SMART_READER_LITE
LIVE PREVIEW

Turing Machines Context-Free Languages n b n R a ww Regular - - PDF document

Review Languages and Grammars Alphabets, strings, languages Regular Languages Deterministic Finite and Nondeterministic Automata Equivalence of NFA and DFA and Minimizing a DFA CS 301 - Lecture 19 Regular Expressions


slide-1
SLIDE 1

1

CS 301 - Lecture 19 Turing Machines

Fall 2008

Review

  • Languages and Grammars

– Alphabets, strings, languages

  • Regular 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 Languages

– 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

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
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
SLIDE 3

3

...... ...... Example: Time 0 ...... ...... Time 1

  • 1. Reads
  • 2. Writes

a a c b a b k c

a k

  • 3. Moves Left

...... ...... Time 1

a b k c

...... ...... Time 2

a k c f

  • 1. Reads
  • 2. Writes

b f

  • 3. Moves Right

The Input String

...... ......

◊ ◊ ◊ ◊

Blank symbol head

◊ a b c a

Head starts at the leftmost position

  • f the input string

Input string ...... ......

◊ ◊ ◊ ◊

Blank symbol head

◊ a b c a

Input string Remark: the input string is never empty

slide-4
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
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
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

  • r

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
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
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
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
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
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
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
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
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
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
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
SLIDE 17

17

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