Turing Machines Human-aware Rbtics 2017/10/17 & 19 Chapter 3.2 & 3.3 in Sipser Ø Annuncement: q q q q Slides fr this lecture are here: http://www.public.asu.edu/~yzhan442/teaching/cse355/lectures/tm-ii.pdf N quiz fr the next class Review sessin next Tuesday N late hmewrk will be accepted fr HW5 1
Last time Human-aware Rbtics The church-turing thesis Turing machines q Definitin f TM q Cmputatin f TM q Design f TM FA (DFA & NFA) express Regular Expressins (RE) CFL Recursively enumerable Ø Gals: Learned abut TM 2
Outline fr tday Human-aware Rbtics The church-turing thesis Turing machines q Definitin f TM q Cmputatin f TM q Design f TM Variants f TMs Multitape TM Nndeterminstic TM Enumeratrs FA (DFA & NFA) express Regular Expressins (RE) CFL Recursively enumerable Ø Gals: Learn abut variants f TM and their equivalences 3
Rbustness f TMs Human-aware Rbtics Variatins d nt imprve TMs! Add STAY in additin t L, R Add kl, kr (k < N) in additin t L, R Randm access memry Multitape TMs Add nndeterminism 4
Equivalence Human-aware Rbtics Hw d prve that tw machines are equivalent? 5
Equivalence Human-aware Rbtics Hw d prve that tw machines are equivalent? They must recgnize the same languages what did we d with DFA and NFA? 6
Equivalence Human-aware Rbtics Hw d prve that tw machines are equivalent? what did we d with DFA and NFA (add nndeterminism)? q DFA -> NFA (simple) use NFA t simulate DFA q NFA -> DFA (mre difficult) use DFA t simulate NFA Given a TM M and a mdified M q q M simulates M (simple when M is mre general) M simulates M (simple when M is mre general) 7
Add STAY Human-aware Rbtics Variatins d nt imprve TMs! Add STAY in additin t L, R M =? q i, a -> q j, b, {L, R, S} Given a TM M and a mdified M Ø M simulates M --- Given M and its input, use M t simulate M q M simulates M --- Given M and its input, use M t simulate M M = q i, a -> q j, b, {L, R} 8
Add STAY Human-aware Rbtics Variatins d nt imprve TMs! Add STAY in additin t L, R M = (Q,,,,q 0,q accept,q reject ) q i, a -> q j, b, {L, R, S} Given a TM M and a mdified M Ø M simulates M --- Given M and its input, use M t simulate M: Just cpy everything frm M t M! q M simulates M --- Given M and its input, use M t simulate M M = q i, a -> q j, b, {L, R} 9
Add STAY Human-aware Rbtics Variatins d nt imprve TMs! Add STAY in additin t L, R M = q i, a -> q j, b, {L, R, S} Given a TM M and a mdified M q M simulates M --- Given M and its input, use M t simulate Ø M: Just cpy everything frm M t M! M simulates M --- Given M and its input, use M t simulate M M =? q i, a -> q j, b, {L, R} 10
Add STAY Variatins d nt imprve TMs! Human-aware Rbtics Add STAY in additin t L, R M = q i, a -> q j, b, {L, R, S} Given a TM M and a mdified M q M simulates M --- Given M and its input, use M t simulate M: Just cpy everything frm M t M! Ø M simulates M --- Given M and its input, use M t simulate M M =? Hw t simulate q i, a -> q j, b, S? q i, a -> q j, b, {L, R} 11
Add STAY Human-aware Rbtics Variatins d nt imprve TMs! Add STAY in additin t L, R M = q i, a -> q j, b, {L, R, S} Given a TM M and a mdified M q M simulates M --- Given M and its input, use M t simulate Ø M: Just cpy everything frm M t M! M simulates M --- Given M and its input, use M t simulate M: cpy everything frm M t M; add intermediate state ad M = transitins when encuntering q i, a -> q j, b, S (Q 0,,, 0,q 0,q accept,q reject ) Hw t simulate q i, a -> q j, b, S? q i, a -> q j, b, {L, R} 12
Add kl and kr Human-aware Rbtics Variatins d nt imprve TMs! Add kl, kr (k < N) in additin t L, R Ø Similar t adding STAY M q i, a -> q j, b, {L k, R k } Given a TM M and a mdified M q M simulates M --- Given M and its input, use M t simulate M: Just cpy everything frm M t M! q M simulates M --- Given M and its input, use M t simulate M: cpy everything frm M t M; add intermediate state ad transitins when encuntering q i, a -> q j, b, L k R k M q i, a -> q j, b, {L, R} 13
Randm access memry Human-aware Rbtics Variatins d nt imprve TMs! Randm access memry Given a TM M and a mdified M Ø M simulates M --- Given M and its input, use M t simulate M M =? Hw t simulate q i, a -> q j, b, {L,R}? q i, a -> q j, b, {addr} Ø M simulates M --- Given M and its input, use M t simulate M M = q i, a -> q j, b, {L, R} 14
Randm access memry Human-aware Rbtics Variatins d nt imprve TMs! Randm access memry Given a TM M and a mdified M Ø M simulates M --- Given M and its input, use M t simulate M: must add address blck n the tape fr all symbls befre simulating q M simulates M --- Given M and its input, use M t simulate M M = (Q 0,, 0, 0,q 0,q accept,q reject ) Hw t simulate q i, a -> q j, b, {L,R}? q i, a -> q j, b, {addr} M = q i, a -> q j, b, {L, R} 15
Randm access memry Variatins d nt imprve TMs! Human-aware Rbtics Randm access memry M = q i, a -> q j, b, {addr} Given a TM M and a mdified M q M simulates M --- Given M and its input, use M t simulate M: must add address blck n the tape fr all symbls befre simulating Ø M simulates M --- Given M and its input, use M t simulate M M =? Hw t simulate q i, a -> q j, b, addr q i, a -> q j, b, {L, R} 16
Randm access memry Variatins d nt imprve TMs! Human-aware Rbtics Randm access memry M = q i, a -> q j, b, {addr} Given a TM M and a mdified M q M simulates M --- Given M and its input, use M t simulate M: must add address blck n the tape fr all symbls befre simulating Ø M simulates M --- Given M and its input, use M t simulate M: must add intermediate states t mve t the left mst psitin and step by step t addr; must als add a blank symbl t the head M = (Q 0,, 0, 0,q 0,q accept,q reject ) Hw t simulate q i, a -> q j, b, addr q i, a -> q j, b, {L, R} 17
Last time 10/17 Human-aware Rbtics The church-turing thesis Turing machines q Definitin f TM q Cmputatin f TM q Design f TM (review) Variants f TMs Multitape TM Nndeterminstic TM Enumeratrs FA (DFA & NFA) express Regular Expressins (RE) CFL Recursively enumerable Ø Gals: Learn abut variants f TM and their equivalences 18
Design f Turing machines {w#w w 2 {0, 1} } Human-aware Rbtics General idea high level descriptin Cmpare each symbl n the left hand side f # with that n the right hand side sequentially; if match, crss bth (using x ) and cntinue; therwise, reject Accept if all match and n symbls are left n bth sides; therwise, reject Can we implement a Turing machine t achieve this? 19
Design f Turing machines {w#w w 2 {0, 1} } Human-aware Rbtics M n input u: implementatin descriptin (by default what we need in midterm #2) 1. Start frm the first nne x symbl, dented as c, t the left f # 2. Crss it ff as x and mve t the first nne x symbl t the right f #. If the symbl is als c in stage 1, crss it ff and mve t the left end f the tape; if n such symbl is fund befre reaching, reject 3. G t stage 1 unless all nne x symbls are crssed ff t the left f # ; g t stage 4 therwise. 4. If all the symbls are als crssed ff t the right f #, accept; therwise, reject 20
Design f Turing machines Human-aware Rbtics Example tape state: x1#x1 {w#w w 2 {0, 1} } Cnsider input 01#01. M n input u: -- frmal descriptin At q 1, if the input symbl is, reject; therwise, if the input symbl is #, mve right (q 1, # ->q 8, R); add self lp q 8, q 8 (q 8, x ->q 8, R); At q 8, if the input symbl is, accept; therwise, reject At q 1, if the current symbl is c (0 r 1), crss it ff and mve right (q 1, c ->q 2 q 3, x, R) At q 2 r q 3, self lp n 0 r 1 while mving right (q 2 q 3, 0 1 ->q 2 q 3, R) At q 2 r q 3, if the current symbl is #, mve right (q 2 q 3, # ->q 4 q 5, R) At q 4 q 5, self lp n x and if the current symbl is c, mve left (q 4 q 5, c ->q 6, L) At q 6, self lp n 0, 1, x (q 6, 0 1 x ->q 6, L) when n # (q 6, # ->q 7, L) At q 7, self lp n 0, 1 (q 7, 0 1 ->q 7, L) when n x mve right (q 7, x ->q 1, R) G back t q 1 21
Last time 10/17 Human-aware Rbtics The church-turing thesis Turing machines q Definitin f TM q Cmputatin f TM q Design f TM (review) Variants f TMs (STAY, {L k, R k } ) Multitape TM Nndeterminstic TM Enumeratrs FA (DFA & NFA) express Regular Expressins (RE) CFL Recursively enumerable Ø Gals: Learn abut variants f TM and their equivalences 22
Let us play a game! Human-aware Rbtics Each f yu represents a small Turing machine Mi n the tape f a large Turing machine, input is <M1, M2, M3, Mk, Q1, Q2., Qm> 1. We start with a randm number [-max, max], which is yur seat index 2. ANSWER the questin in rder AND prvide the crrect explanatin 3. The chsen persn may chse t SKIP the questin, it becmes the next persn s term (in increasing rder) 4. If the current persn failed, the next persn may chse t ANSWER r SKIP it 5. The persn that chse t skip a questin, hwever, must share with the next persn f his/her current thught (it culd be a guess but can als include hints t the next persn) 6. The persn succeeded can chse t perfrm randm memry access [-max, max], LEFT r RIGHT [1, 10]. Clear and ready t g? 23
Let us play a game! Human-aware Rbtics 1. There is a nn-regular language that can be recgnized by a Turing Machine. 2. A Turing Machine can have infinitely many states in Q. 3. A Turing Machine can have infinitely many input symbls. 4. A Turing Machine can have infinitely many tape symbls. 5. A Turing Machine can have infinitely many cnfiguratins. 6. If TM M decides L, then M recgnizes L. 7. If TM M recgnizes L, then M decides L. 8. If a TM M recgnizes L and M lps n sme string, then L is nt decidable. 9. A Turing machine may fail t accept given a string in the language that it recgnizes 10. An FA (PDA) can als lp, s RLs (r CFLs) are Turing recgnizable but nt decidable 24
Outline fr tday Human-aware Rbtics The church-turing thesis Turing machines q Definitin f TM q Cmputatin f TM q Design f TM Variants f TMs Multitape TM Nndeterminstic TM Enumeratrs FA (DFA & NFA) express Regular Expressins (RE) CFL Recursively enumerable Ø Gals: Learn abut variants f TM and their equivalences 25
Multitape Human-aware Rbtics Variatins d nt imprve TMs! Multitape TMs: Turing machines with multiple tapes and R/W heads; when starting, input is kept n the first tape, and ther tapes are empty M q i, a 1, a 2 a n -> q j, b 1, b 2 b n, {L, R} n q i, s a -> q j, s, b, {L, R} M 26
Multitape Human-aware Rbtics Variatins d nt imprve TMs! Multitape TMs: Turing machines with multiple tapes and R/W heads; when starting, input is kept n the first tape, and ther tapes are empty M q i, a 1, a 2 a n -> q j, b 1, b 2 b n, {L, R} n What infrmatin is needed t simulate M n M? q i, s a -> q j, s, b, {L, R} M 27
Multitape Variatins d nt imprve TMs! Human-aware Rbtics Multitape TMs: Turing machines with multiple tapes and R/W heads; when starting, input is kept n the first tape, and ther tapes are empty M q i, a 1, a 2 a n -> q j, b 1, b 2 b n, {L, R} n What infrmatin is needed t simulate M n M? All tape cntent R/W heads infrmatin q i, s a -> q j, s, b, {L, R} M 28
Multitape Variatins d nt imprve TMs! Human-aware Rbtics Multitape TMs: Turing machines with multiple tapes and R/W heads; when starting, input is kept n the first tape, and ther tapes are empty M q i, a 1, a 2 a n -> q j, b 1, b 2 b n, {L, R} n What infrmatin is needed t simulate M n M? All tape cntent R/W heads infrmatin q i, a -> q j, b, {L, R} M Valid? 29
Multitape Variatins d nt imprve TMs! Human-aware Rbtics Multitape TMs: Turing machines with multiple tapes and R/W heads; when starting, input is kept n the first tape, and ther tapes are empty M q i, a 1, a 2 a n -> q j, b 1, b 2 b n, {L, R} n What infrmatin is needed t simulate M n M? All tape cntent R/W heads infrmatin q i, a -> q j, b, {L, R} M Valid? (finite steps & symbls) yes! 30
Multitape Variatins d nt imprve TMs! Human-aware Rbtics Multitape TMs: Turing machines with multiple tapes and R/W heads; when starting, input is kept n the first tape, and ther tapes are empty TM M n input string w: 1. Frmat the tape in a way that represents all strings, i.e., 2. Scan L t R t find ut which the current symbls under the virtual heads. Make a secnd pass and update tapes accrding t finite cntrl. 3. If a virtual tape mves right nt a #, then add and shift cntents ne psitin t the right. 4. Repeat. M M 31
Outline fr tday Human-aware Rbtics The church-turing thesis Turing machines q Definitin f TM q Cmputatin f TM q Design f TM Variants f TMs Multitape TM Nndeterminstic TM Enumeratrs FA (DFA & NFA) express Regular Expressins (RE) CFL Recursively enumerable Ø Gals: Learn abut variants f TM and their equivalences 32
Nndeterminism Human-aware Rbtics Variatins d nt imprve TMs! Add nndeterminism " D we need? Fr an NTM t accept a string, we require that at least ne f its cmputatins end up accepting the input Ø Sme f the ther cmputatin paths culd be rejecting Fr an NTM t decide a language, we require that all f its cmputatins halt. 33
Nndeterminism Human-aware Rbtics Variatins d nt imprve TMs! Add nndeterminism M q i, a -> q j, b, {L, R} q i, a -> q k, c, {L, R} M q i, a -> q j, b, {L, R} 34
Nndeterminism Human-aware Rbtics Variatins d nt imprve TMs! Add nndeterminism M What infrmatin is needed t simulate M n M? M 35
Nndeterminism Variatins d nt imprve TMs! Human-aware Rbtics Add nndeterminism M What infrmatin is needed t simulate M n M? Ø Need t iterate the tree! q The current cnfiguratin q The branch infrmatin up t the current cnfiguratin M 36
Nndeterminism Variatins d nt imprve TMs! Human-aware Rbtics Add nndeterminism M What infrmatin is needed t simulate M n M? Ø Need t iterate the tree! q q The current cnfiguratin Hw? need t backtrack The branch infrmatin up t the current cnfiguratin M 37
Nndeterminism Variatins d nt imprve TMs! Human-aware Rbtics Add nndeterminism M What infrmatin is needed t simulate M n M? Ø Need t iterate the tree! q q The current cnfiguratin Hw? need t backtrack The branch infrmatin up t the current cnfiguratin Hw? need t systematically traverse the tree M 38
Nndeterminism Human-aware Rbtics Variatins d nt imprve TMs! Add nndeterminism M q i, a -> q j, b, {L, R} q i, a -> q k, c, {L, R} M M 39
Nndeterminism Variatins d nt imprve TMs! Human-aware Rbtics Add nndeterminism TM M n input string w (fr M ): 1. Cpy tape 1 t cntain w, tape 2 and 3 are empty 2. Cpy tape 1 t tape 2 3. Use tape 2 t simulate M based n branch infrmatin frm tape 3; accept accrdingly t M ; if nt accept, g t step 4 4. Iterate the string n tape 3 using shrtlex rder and gt step 2 M q i, a -> q j, b, {L, R} q i, a -> q k, c, {L, R} M 40
Rbustness f TMs Human-aware Rbtics Variatins d nt imprve TMs! Add STAY in additin t L, R Add kl, kr (k < N) in additin t L, R Randm access memry Multitape TMs Add nndeterminism and many crllaries! 41
Remark: undecidable Human-aware language Rbtics M (decider)= On input p : where p is a plynmial ver the variable V. 1. Evaluate p with V successively t all pssible integral assignments t V. If at any pint the plynmial evaluates t 0, accept 2. If we have explre all pssible assignments, reject. Crrect? 42
Remark: undecidable Human-aware language Rbtics M (decider)= On input p : where p is a plynmial ver the variable V. 1. Evaluate p with V successively t all pssible integral assignments t V. If at any pint the plynmial evaluates t 0, accept 2. If we have explre all pssible assignments, reject. Crrect? N. (See Prblem 3.21 fr a similar prblem that is decidable) 43
Remark: undecidable Human-aware language Rbtics M (decider)= On input p : where p is a plynmial ver the variable V. 1. Evaluate p with V successively t all pssible integral assignments t V. If at any pint the plynmial evaluates t 0, accept 2. If we have explre all pssible assignments, reject. Crrect? N. (See Prblem 3.21 fr a similar prblem that is decidable) Undecidable but recgnizable! M= On input p : where p is a plynmial ver the variable x. 1. Evaluate p with V set successively t the all pssible integral assignments t V. If at any pint the plynmial evaluates t 0, accept. Crrect? 44
Remark: undecidable Human-aware language Rbtics M (decider)= On input p : where p is a plynmial ver the variable V. 1. Evaluate p with V successively t all pssible integral assignments t V. If at any pint the plynmial evaluates t 0, accept 2. If we have explre all pssible assignments, reject. Crrect? N. (See Prblem 3.21 fr a similar prblem that is decidable) Undecidable but recgnizable! M= On input p : where p is a plynmial ver the variable x. 1. Evaluate p with V set successively t the all pssible integral assignments t V. If at any pint the plynmial evaluates t 0, accept. Crrect? Yes but with tweaks that ensure prper rdering f assignments 45
Outline fr tday Human-aware Rbtics The church-turing thesis Turing machines q Definitin f TM q Cmputatin f TM q Design f TM Variants f TMs Multitape TM Nndeterminstic TM Enumeratrs FA (DFA & NFA) express Regular Expressins (RE) CFL Recursively enumerable Ø Gals: Learn abut variants f TM and their equivalences 46
Enumeratr Human-aware Rbtics A TM that des nt require any input Print ut strings in the language Ø Given a string w in the languge, it will eventually be printed ut 47
Enumeratr Human-aware Rbtics Valid? 48
Enumeratr Human-aware Rbtics Valid? Yes but with tweaks f rdering f pssible strings 49
Outline fr tday Human-aware Rbtics The church-turing thesis Turing machines q Definitin f TM q Cmputatin f TM q Design f TM Variants f TMs Multitape TM Nndeterminstic TM Enumeratrs FA (DFA & NFA) express Regular Expressins (RE) CFL Recursively enumerable Ø Gals: Learn abut variants f TM and their equivalences 50