Turing Machines Human-aware Roboticsyzhan442/teaching/CSE355/Lectures/TM... · 2017-10-25 · o...

Post on 10-Jul-2020

2 views 0 download

transcript

Human-awareRobotics

1

Turing Machines• 2017/10/17 & 19

• Chapter 3.2 & 3.3 in Sipser

Ø Announcement:q Slides for this lecture are here:

http://www.public.asu.edu/~yzhan442/teaching/CSE355/Lectures/TM-II.pdf

q No quiz for the next class

q Review session next Tuesday

q No late homework will be accepted for HW5

Human-awareRobotics

2

Last time

FA (DFA & NFA) expressRegular Expressions (RE)

• The church-turing thesiso Turing machines

q Definition of TM

q Computation of TM

q Design of TM

Ø Goals:

o Learned about TM

CFL

Recursively enumerable

Human-awareRobotics

3

Outline for today

FA (DFA & NFA) expressRegular Expressions (RE)

• The church-turing thesiso Turing machines

q Definition of TM

q Computation of TM

q Design of TM

o Variants of TMs

o Multitape TM

o Nondeterminstic TM

o Enumerators

Ø Goals:

o Learn about variants of TM and their equivalences

CFL

Recursively enumerable

Human-awareRobotics

4

Robustness of TMs• Variations do not improve TMs!

o Add STAY in addition to L, R

o Add kL, kR (k < N) in addition to L, R

o Random access memory

o Multitape TMs

o Add nondeterminism

Human-awareRobotics

5

Equivalence• How do prove that two machines are equivalent?

Human-awareRobotics

6

Equivalence• How do prove that two machines are equivalent? They must recognize the same languages

o what did we do with DFA and NFA?

Human-awareRobotics

7

Equivalence• How do prove that two machines are equivalent?

o what did we do with DFA and NFA (add nondeterminism)?

q DFA -> NFA (simple) – use NFA to simulate DFA

q NFA -> DFA (more difficult) – use DFA to simulate NFA

o Given a TM M and a modified M’

q M’ simulates M (simple when M’ is more general)

q M simulates M’ (simple when M is more general)

Human-awareRobotics

8

• Variations do not improve TMs!

o Add STAY in addition to L, R

qi, a -> qj, b, {L, R, S}

M =

M’ = ?

qi, a -> qj, b, {L, R}

Add STAY

Given a TM M and a modified M’

Ø M’ simulates M --- Given M and its input, use M’ to simulate

M

q M simulates M’ --- Given M’ and its input, use M to simulate

M

Human-awareRobotics

9

• Variations do not improve TMs!

o Add STAY in addition to L, R

qi, a -> qj, b, {L, R, S}

M =

M’ =

qi, a -> qj, b, {L, R}

Given a TM M and a modified M’

Ø M’ simulates M --- Given M and its input, use M’ to simulate

M: Just copy everything from M to M’!

q M simulates M’ --- Given M’ and its input, use M to simulate

M

Add STAY

(Q,⌃,�, �, q0, qaccept, qreject)

Human-awareRobotics

10

• Variations do not improve TMs!

o Add STAY in addition to L, R

qi, a -> qj, b, {L, R}

qi, a -> qj, b, {L, R, S}

M = ?

M’ =

Add STAY

Given a TM M and a modified M’

q M’ simulates M --- Given M and its input, use M’ to simulate

M: Just copy everything from M to M’!

Ø M simulates M’ --- Given M’ and its input, use M to simulate

M

Human-awareRobotics

11

Add STAY• Variations do not improve TMs!

o Add STAY in addition to L, R

qi, a -> qj, b, {L, R}How to simulate qi, a -> qj, b, S?

qi, a -> qj, b, {L, R, S}

M = ?

M’ =

Given a TM M and a modified M’

q M’ simulates M --- Given M and its input, use M’ to simulate

M: Just copy everything from M to M’!

Ø M simulates M’ --- Given M’ and its input, use M to simulate

M

Human-awareRobotics

12

Add STAY• Variations do not improve TMs!

o Add STAY in addition to L, R

qi, a -> qj, b, {L, R}How to simulate qi, a -> qj, b, S?

qi, a -> qj, b, {L, R, S}

M =

M’ =

Given a TM M and a modified M’

q M’ simulates M --- Given M and its input, use M’ to simulate

M: Just copy everything from M to M’!

Ø M simulates M’ --- Given M’ and its input, use M to simulate

M: copy everything from M’ to M; add intermediate state ad

transitions when encountering qi, a -> qj, b, S (Q0,⌃,�, �0, q0, qaccept, qreject)

Human-awareRobotics

13

• Variations do not improve TMs!

o Add kL, kR (k < N) in addition to L, R

Ø Similar to adding STAY

qi, a -> qj, b, {Lk, Rk}

qi, a -> qj, b, {L, R}

M

M’

Add kL and kR

Given a TM M and a modified M’

q M’ simulates M --- Given M and its input, use M’ to simulate

M: Just copy everything from M to M’!

q M simulates M’ --- Given M’ and its input, use M to simulate

M: copy everything from M’ to M; add intermediate state ad

transitions when encountering qi, a -> qj, b, Lk|Rk

Human-awareRobotics

14

Random access memory• Variations do not improve TMs!

o Random access memory

qi, a -> qj, b, {addr}

qi, a -> qj, b, {L, R}

M =

M’ = ? How to simulate qi, a -> qj, b, {L,R}?

Given a TM M and a modified M’

Ø M’ simulates M --- Given M and its input, use M’ to simulate

M

Ø M simulates M’ --- Given M’ and its input, use M to simulate

M

Human-awareRobotics

15

Random access memory• Variations do not improve TMs!

o Random access memory

qi, a -> qj, b, {addr}

qi, a -> qj, b, {L, R}

M =

M’ = How to simulate qi, a -> qj, b, {L,R}?

Given a TM M and a modified M’

Ø M’ simulates M --- Given M and its input, use M’ to simulate

M: must add address block on the tape for all symbols before

simulating

q M simulates M’ --- Given M’ and its input, use M to simulate

M

(Q0,⌃,�0, �0, q0, qaccept, qreject)

Human-awareRobotics

16

Random access memory• Variations do not improve TMs!

o Random access memory

qi, a -> qj, b, {addr}

qi, a -> qj, b, {L, R}

M = ?

M’ =

Given a TM M and a modified M’

q M’ simulates M --- Given M and its input, use M’ to simulate

M: must add address block on the tape for all symbols before

simulating

Ø M simulates M’ --- Given M’ and its input, use M to simulate

MHow to simulate qi, a -> qj, b, addr

Human-awareRobotics

17

Random access memory• Variations do not improve TMs!

o Random access memory

qi, a -> qj, b, {addr}

qi, a -> qj, b, {L, R}

M =

M’ =

Given a TM M and a modified M’

q M’ simulates M --- Given M and its input, use M’ to simulate

M: must add address block on the tape for all symbols before

simulating

Ø M simulates M’ --- Given M’ and its input, use M to simulate

M: must add intermediate states to move to the left most

position and step by step to addr; must

also add a blank symbol to the head

How to simulate qi, a -> qj, b, addr

(Q0,⌃,�0, �0, q0, qaccept, qreject)

Human-awareRobotics

18

Last time 10/17

FA (DFA & NFA) expressRegular Expressions (RE)

• The church-turing thesiso Turing machines

q Definition of TM

q Computation of TM

q Design of TM (review)

o Variants of TMs

o Multitape TM

o Nondeterminstic TM

o Enumerators

Ø Goals:

o Learn about variants of TM and their equivalences

CFL

Recursively enumerable

Human-awareRobotics

19

• General idea – high level descriptiono Compare each symbol on the left hand side of # with that on the right hand side

sequentially; if match, cross both (using ‘x’) and continue; otherwise, rejecto Accept if all match and no symbols are left on both sides; otherwise, reject

o Can we implement a Turing machine to achieve this?

Design of Turing machines{w#w|w 2 {0, 1}⇤}

Human-awareRobotics

20

Design of Turing machines{w#w|w 2 {0, 1}⇤}• M on input u: – implementation description (by default what we need in midterm #2)

1. Start from the first none x symbol, denoted as c, to the left of ‘#’2. Cross it off as ‘x’ and move to the first none x symbol to the right of ‘#’. If the symbol is

also c in stage 1, cross it off and move to the left end of the tape; if no such symbol is found before reaching ‘ ’, reject

3. Go to stage 1 unless all none x symbols are crossed off to the left of ‘#’; go to stage 4 otherwise.

4. If all the symbols are also crossed off to the right of ‘#’, accept; otherwise, reject

Human-awareRobotics

21

Design of Turing machines

• M on input u: -- formal descriptiono At q1, if the input symbol is ‘ ’, reject; otherwise, if the input symbol is ‘#’, move right

(q1, # ->q8, R); add self loop q8, q8 (q8, x ->q8, R); o At q8, if the input symbol is ‘ ’, accept; otherwise, rejecto At q1, if the current symbol is c (0 or 1), cross it off and move right (q1, c ->q2|q3, x, R)o At q2 or q3, self loop on 0 or 1 while moving right (q2 |q3, 0|1 ->q2 |q3, R)o At q2 or q3, if the current symbol is ‘#’, move right (q2 |q3, # ->q4|q5, R)o At q4|q5, self loop on x and if the current symbol is c, move left (q4|q5, c ->q6, L)o At q6, self loop on 0, 1, x (q6, 0|1|x ->q6, L) when on ‘#’ (q6, # ->q7, L)o At q7, self loop on 0, 1 (q7, 0|1 ->q7, L) when on ‘x’ move right (q7, x ->q1, R) o Go back to q1

{w#w|w 2 {0, 1}⇤} Consider input 01#01. …

Example tape state: x1#x1

Human-awareRobotics

22

Last time 10/17

FA (DFA & NFA) expressRegular Expressions (RE)

• The church-turing thesiso Turing machines

q Definition of TM

q Computation of TM

q Design of TM (review)

o Variants of TMs (STAY, {Lk, Rk}…)

o Multitape TM

o Nondeterminstic TM

o Enumerators

Ø Goals:

o Learn about variants of TM and their equivalences

CFL

Recursively enumerable

Human-awareRobotics

23

Let us play a game!

• Each of you represents a small Turing machine Mi on the tape of a large Turing machine, input is <M1, M2, M3, … Mk, Q1, Q2., … Qm>

1. We start with a random number [-max, max], which is your seat index2. ANSWER the question in order AND provide the correct explanation3. The chosen person may choose to SKIP the question, it becomes the next person’s term

(in increasing order)4. If the current person failed, the next person may choose to ANSWER or SKIP it5. The person that chose to skip a question, however, must share with the next person of

his/her current thought (it could be a guess but can also include hints to the next person)6. The person succeeded can choose to perform random memory access [-max, max],

LEFT or RIGHT [1, 10].

Clear and ready to go?

Human-awareRobotics

24

Let us play a game!

1. There is a non-regular language that can be recognized by a Turing Machine. 2. A Turing Machine can have infinitely many states in Q.3. A Turing Machine can have infinitely many input symbols.4. A Turing Machine can have infinitely many tape symbols.5. A Turing Machine can have infinitely many configurations.6. If TM M decides L, then M recognizes L.7. If TM M recognizes L, then M decides L.8. If a TM M recognizes L and M loops on some string, then L is not decidable.9. A Turing machine may fail to accept given a string in the language that it recognizes10. An FA (PDA) can also loop, so RLs (or CFLs) are Turing recognizable but not decidable

Human-awareRobotics

25

Outline for today

FA (DFA & NFA) expressRegular Expressions (RE)

• The church-turing thesiso Turing machines

q Definition of TM

q Computation of TM

q Design of TM

o Variants of TMs

o Multitape TM

o Nondeterminstic TM

o Enumerators

Ø Goals:

o Learn about variants of TM and their equivalences

CFL

Recursively enumerable

Human-awareRobotics

26

Multitape• Variations do not improve TMs!

o Multitape TMs: Turing machines with multiple tapes and R/W heads;

when starting, input is kept on the first tape, and other tapes are empty

qi, s -> qj, s, {L, R}

M’

M

qi, a1, a2…an -> qj, b1, b2…bn, {L, R}n

qi, a -> qj, b, {L, R}

Human-awareRobotics

27

Multitape• Variations do not improve TMs!

o Multitape TMs: Turing machines with multiple tapes and R/W heads;

when starting, input is kept on the first tape, and other tapes are empty

qi, s -> qj, s, {L, R}

M’

M

qi, a1, a2…an -> qj, b1, b2…bn, {L, R}n

What information is needed to simulate M’on M?

qi, a -> qj, b, {L, R}

Human-awareRobotics

28

Multitape• Variations do not improve TMs!

o Multitape TMs: Turing machines with multiple tapes and R/W heads;

when starting, input is kept on the first tape, and other tapes are empty

qi, s -> qj, s, {L, R}

M’

M

qi, a1, a2…an -> qj, b1, b2…bn, {L, R}n

What information is needed to simulate M’on M?

• All tape content• R/W heads information

qi, a -> qj, b, {L, R}

Human-awareRobotics

29

• Variations do not improve TMs!

o Multitape TMs: Turing machines with multiple tapes and R/W heads;

when starting, input is kept on the first tape, and other tapes are empty

qi, a -> qj, b, {L, R}

qi, a1, a2…an -> qj, b1, b2…bn, {L, R}nM’

M

Multitape

Valid?

What information is needed to simulate M’on M?

• All tape content• R/W heads information

Human-awareRobotics

30

• Variations do not improve TMs!

o Multitape TMs: Turing machines with multiple tapes and R/W heads;

when starting, input is kept on the first tape, and other tapes are empty

qi, a -> qj, b, {L, R}

qi, a1, a2…an -> qj, b1, b2…bn, {L, R}nM’

M

Multitape

Valid? (finite steps & symbols) yes!

What information is needed to simulate M’on M?

• All tape content• R/W heads information

Human-awareRobotics

31

• Variations do not improve TMs!

o Multitape TMs: Turing machines with multiple tapes and R/W heads;

when starting, input is kept on the first tape, and other tapes are empty

M’

• TM M on input string w:1. Format the tape in a way that represents all strings, i.e., 2. Scan L to R to find out which the current symbols under the

virtual heads. Make a second pass and update tapes according to finite control.

3. If a virtual tape moves right onto a #, then add and shift contents one position to the right.

4. Repeat.

Multitape

M

Human-awareRobotics

32

Outline for today

FA (DFA & NFA) expressRegular Expressions (RE)

• The church-turing thesiso Turing machines

q Definition of TM

q Computation of TM

q Design of TM

o Variants of TMs

o Multitape TM

o Nondeterminstic TM

o Enumerators

Ø Goals:

o Learn about variants of TM and their equivalences

CFL

Recursively enumerable

Human-awareRobotics

33

Nondeterminism• Variations do not improve TMs!

o Add nondeterminism

Do we need ?

For an NTM to accept a string, we require that at least one of its computations end up accepting the input

Ø Some of the other computation paths could be rejecting

For an NTM to decide a language, we require that all of its computations halt.

"

Human-awareRobotics

34

• Variations do not improve TMs!

o Add nondeterminism

M

M’

Nondeterminism

qi, a -> qj, b, {L, R}

qi, a -> qj, b, {L, R}qi, a -> qk, c, {L, R}…

Human-awareRobotics

35

• Variations do not improve TMs!

o Add nondeterminism

Nondeterminism

What information is needed to simulate M’ on M?

M

M’

Human-awareRobotics

36

• Variations do not improve TMs!

o Add nondeterminism

Nondeterminism

What information is needed to simulate M’ on M? Ø Need to iterate the tree!q The current configuration

q The branch information

up to the current configuration

M

M’

Human-awareRobotics

37

• Variations do not improve TMs!

o Add nondeterminism

Nondeterminism

What information is needed to simulate M’ on M? Ø Need to iterate the tree!q The current configuration How? need to

backtrack

q The branch information

up to the current configuration

M

M’

Human-awareRobotics

38

• Variations do not improve TMs!

o Add nondeterminism

Nondeterminism

What information is needed to simulate M’ on M? Ø Need to iterate the tree!q The current configuration How? need to

backtrack

q The branch information

up to the current configuration How? need to

systematically traverse the tree

M

M’

Human-awareRobotics

39

• Variations do not improve TMs!

o Add nondeterminism

M

Nondeterminism

M

M’ qi, a -> qj, b, {L, R}qi, a -> qk, c, {L, R}…

Human-awareRobotics

40

• Variations do not improve TMs!

o Add nondeterminism

Nondeterminism

M

M’ qi, a -> qj, b, {L, R}qi, a -> qk, c, {L, R}…

• TM M on input string w (for M’):1. Copy tape 1 to contain w, tape 2 and 3 are empty2. Copy tape 1 to tape 23. Use tape 2 to simulate M’ based on branch information from tape

3; accept accordingly to M’; if not accept, go to step 44. Iterate the string on tape 3 using shortlex order and goto step 2

Human-awareRobotics

41

Robustness of TMs• Variations do not improve TMs!

o Add STAY in addition to L, R

o Add kL, kR (k < N) in addition to L, R

o Random access memory

o Multitape TMs

o Add nondeterminism

and many corollaries!

Human-awareRobotics

42

Remark: undecidable language

M (decider)= “On input ⟨p⟩: where p is a polynomial over the variable V.1. Evaluate p with V successively to all possible integral assignments to V. If at any point the polynomial evaluates to 0, accept 2. If we have explore all possible assignments, reject.”

Correct?

Human-awareRobotics

43

Remark: undecidable language

M (decider)= “On input ⟨p⟩: where p is a polynomial over the variable V.1. Evaluate p with V successively to all possible integral assignments to V. If at any point the polynomial evaluates to 0, accept 2. If we have explore all possible assignments, reject.”

Correct? No. (See Problem 3.21 for a similar problem that is decidable)

Human-awareRobotics

44

M (decider)= “On input ⟨p⟩: where p is a polynomial over the variable V.1. Evaluate p with V successively to all possible integral assignments to V. If at any point the polynomial evaluates to 0, accept 2. If we have explore all possible assignments, reject.”

Correct? No. (See Problem 3.21 for a similar problem that is decidable)Undecidable but recognizable!M= “On input ⟨p⟩: where p is a polynomial over the variable x.1. Evaluate p with V set successively to the all possible integral assignments to V. If at any point the polynomial evaluates to 0, accept .”

Correct?

Remark: undecidable language

Human-awareRobotics

45

M (decider)= “On input ⟨p⟩: where p is a polynomial over the variable V.1. Evaluate p with V successively to all possible integral assignments to V. If at any point the polynomial evaluates to 0, accept2. If we have explore all possible assignments, reject.”

Correct? No. (See Problem 3.21 for a similar problem that is decidable)Undecidable but recognizable!M= “On input ⟨p⟩: where p is a polynomial over the variable x.1. Evaluate p with V set successively to the all possible integral assignments to V. If at any point the polynomial evaluates to 0, accept .”

Correct? Yes but with tweaks that ensure proper ordering of assignments

Remark: undecidable language

Human-awareRobotics

46

Outline for today

FA (DFA & NFA) expressRegular Expressions (RE)

• The church-turing thesiso Turing machines

q Definition of TM

q Computation of TM

q Design of TM

o Variants of TMs

o Multitape TM

o Nondeterminstic TM

o Enumerators

Ø Goals:

o Learn about variants of TM and their equivalences

CFL

Recursively enumerable

Human-awareRobotics

47

Enumerator• A TM that does not require any input

• Print out strings in the language

Ø Given a string w in the languge, it will eventually be printed out

Human-awareRobotics

48

Enumerator

Valid?

Human-awareRobotics

49

Enumerator

Valid? Yes but with tweaks of ordering of possible strings

Human-awareRobotics

50

Outline for today

FA (DFA & NFA) expressRegular Expressions (RE)CFL

Recursively enumerable

• The church-turing thesiso Turing machines

q Definition of TM

q Computation of TM

q Design of TM

o Variants of TMs

o Multitape TM

o Nondeterminstic TM

o Enumerators

Ø Goals:

o Learn about variants of TM and their equivalences