David Evans cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing...

24
David Evans http://www.cs.virginia.edu/ evans s302: Theory of Computation niversity of Virginia omputer Science Lecture 13: Lecture 13: Turing Turing Machines Machines

Transcript of David Evans cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing...

Page 1: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

David Evanshttp://www.cs.virginia.edu/evans

cs302: Theory of ComputationUniversity of VirginiaComputer Science

Lecture 13: Lecture 13: Turing MachinesTuring Machines

Page 2: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

2Lecture 13: Turing Machines

The Story So Far

Regular Languages

Context-Free Languages

Violates Pumping

Lemma For RLs

Viol

ates

Pum

ping

Le

mm

aFo

r CFL

s

Described by DFA, NFA, RegExp, RegGram

Described by CFG,

NDPDA0n1n

0 n1 n2 n

0n

w

Deterministic CFLs

LL(k) Languages

Described by LL(k)

Grammar

Indexed Grammars

Page 3: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

3Lecture 13: Turing Machines

The Story So Far (Simplified)

Regular Languages

Context-Free Languages

Violates Pumping

Lemma For RLs

Viol

ates

Pum

ping

Le

mm

aFo

r CFL

s

Described by DFA, NFA, RegExp, RegGram

Described by CFG,

NDPDA0n1n

0n

w

Page 4: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

4Lecture 13: Turing Machines

Computability Story: This Week

Languages recognizable by any mechanical computing machine

Page 5: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

5Lecture 13: Turing Machines

Computability Story: Next Week

Undecidable Problems

Decidable Problems

Recognizable Languages

Page 6: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

6Lecture 13: Turing Machines

Computability Complexity (April)

Decidable ProblemsDecidable Problems

Problems that can be solved by a computer (eventually).

Problems that can be solved by a computer in a reasonable time.

NP

P

Note: not known if P NP or P = NP

Page 7: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

7Lecture 13: Turing Machines

Exam 1

Page 8: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

8Lecture 13: Turing Machines

Exam 1• Problem 4c: Prove that the language {0n1n2} is

not context-free.

Lengths of strings in L:n = 0 0 + 02 = 0n = 1 1 + 12 = 2n = 2 2 + 22 = 6n = 3 3 + 32 = 12...n = k k + k2

Pumping lemma for CFLs saysthere must be some way of picking s = uvxyz such that m = |v| + |y| > 0 and uvixyiz in L for all i. So, increasing i by 1 adds m symbols to the string, which must produce a string of a length that is not the length of a string in L.

Page 9: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

9Lecture 13: Turing Machines

Recognizing {0n1n2}

DPDA with two stacks?

DPDA with three stacks?

...

?

Page 10: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

10Lecture 13: Turing Machines

3-Stack DPDA Recognizing {0n1n2}

0, ε/ε/ε $/$/$

0, ε/ε/ε +/ε/+

1, $/$/$ ε/ε/ε1, +/ε/ε ε/+/ε

1, +/ε/ε ε/+/ε

1, $/+/+ $/ε/ε

1, ε/+/ε

+/ε/ε

Start

Done

Count 0s

1s b->r

1s r->b

1, ε/$/$ ε/ε/ε

1, +/$/+ ε/+/ε

1, $/ε

/$ ε/ε/ε

Page 11: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

11Lecture 13: Turing Machines

Can it be done with 2 Stacks?

Page 12: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

12Lecture 13: Turing Machines

Simulating 3-DPDA with 2-DPDA

#

#

A B

Page 13: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

13Lecture 13: Turing Machines

Simulating 3-DPDA with 2-DPDA

3-DPDA

#

#pop green

pushB($)pushB(popA())...pushB(popA(#))pushB(popA())...pushB(popA(#))res = popA()pushA(popB(#))pushA(popB())...popB($)

A B

$

+

Page 14: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

14Lecture 13: Turing Machines

2-DPDA + Forced ε-Transitions

A B

Need to do lots of stack manipulation to simulate 3-DPDA on one transition: need transitions with no input symbol (but not nondeterminism!)

#

#

$

Page 15: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

15Lecture 13: Turing Machines

Impact of Forced ε-Transitions

A B

#

#

$

What is the impact of addingnon-input consuming transitions?

DPDA in length n input: runs for n steps

DPDA+ε in length n input:can run forever!

Page 16: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

16Lecture 13: Turing Machines

Is there any computing machine we can’t simulate

with a 2-DPDA+?

Page 17: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

17Lecture 13: Turing Machines

What about an NDPDA?

A B

Use one stack to simulate the NDPDA’s stack.

Use the other stack to keep track of nondeterminism points: copy of stack and decisions left to make.

Page 18: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

18Lecture 13: Turing Machines

Turing Machine?

A B

Tape Head

Page 19: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

19Lecture 13: Turing Machines

Turing Machine

. . .

Infinite tape: Γ*Tape head: read current square on tape,

write into current square,move one square left or right

FSM: like PDA, except: transitions also include direction (left/right) final accepting and rejecting states

FSM

Page 20: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

20Lecture 13: Turing Machines

Turing Machine Formal Description

. . .

FSM7-tuple: (Q, , Γ, δ, q0, qaccept, qreject)Q: finite set of states: input alphabet (cannot include blank symbol, _)Γ: tape alphabet, includes and _δ: transition function: Q Γ Q Γ {L, R}q0: start state, q0 Q qaccept: accepting state, qaccept Q qreject: rejecting state, qreject Q (Sipser’s notation)

Page 21: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

21Lecture 13: Turing Machines

Turing Machine Computing Model

. . .

FSMq0

input

_ _ _ _

blanks

Initial configuration:

x x x x x x x

x

TM Configuration: Γ* Q Γ*

tape contentsleft of head

tape contentshead and right

currentFSM state

Page 22: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

22Lecture 13: Turing Machines

TM Computing Model

δ*: Γ* Q Γ* Γ* Q Γ*

δ*(L, qaccept, R) (L, qaccept, R)δ*(L, qreject, R) (L, qreject, R)

The qaccept and qreject states are final:

Page 23: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

23Lecture 13: Turing Machines

TM Computing Modelδ*: Γ* Q Γ* Γ* Q Γ*

. . .

FSMq

a

u, v Γ*, a, b Γ

u

b

v

δ*(ua, q, bv) = (uac, qr, v) if δ(q, b) = (qr, c, R)δ*(ua, q, bv) = (u, qr, acv) if δ(q, b) = (qr, c, L)

Also: need a rule to cover what happens at left edge of tape

Page 24: David Evans  cs302: Theory of Computation University of Virginia Computer Science Lecture 13: Turing Machines.

24Lecture 13: Turing Machines

Thursday’s Class

• Robustness of TM model

• Church-Turing Thesis

Read Chapter 3:It contains the most bogus sentence in the whole book. Identify it for +25 bonus points (only 1 guess allowed!)