turing machines (tm) model of computation. jaruloj chongstitvatana 2301379turing machines2 outlines...

58
Turing Machines (TM) Model of Computation

Upload: noah-sharp

Post on 26-Mar-2015

226 views

Category:

Documents


0 download

TRANSCRIPT

  • Slide 1

Turing Machines (TM) Model of Computation Slide 2 Jaruloj Chongstitvatana 2301379Turing Machines2 Outlines Structure of Turing machines Deterministic Turing machines (DTM) Accepting a language Computing a function Composite Turing machines Multitape Turing machines Nondeterministic Turing machines (NTM) Universal Turing machines (UTM) Slide 3 Jaruloj Chongstitvatana 2301379Turing Machines3 Structure of TM CONTROL UNIT TAPE HEAD Finite set of states Move left or right one cell at a time Store input for the TM Can be of any length Can read from and write on tape Start state A single halt state Slide 4 Jaruloj Chongstitvatana 2301379Turing Machines4 What does a TM do? Determine if an input x is in a language. That is, answer if the answer of a problem P for the instance x is yes. Compute a function Given an input x, what is f(x)? Slide 5 Jaruloj Chongstitvatana 2301379Turing Machines5 How does a TM work? At the beginning, A TM is in the start state (initial state) its tape head points at the first cell The tape contains, following by input string, and the rest of the tape contains. Slide 6 Jaruloj Chongstitvatana 2301379Turing Machines6 How does a TM work? For each move, a TM reads the symbol under its tape head According to the transition function on the symbol read from the tape and its current state, the TM: write a symbol on the tape move its tape head to the left or right one cell or not changes its state to the next state Slide 7 Jaruloj Chongstitvatana 2301379Turing Machines7 When does a TM stop working? A TM stops working, when it gets into the special state called halt state. (halts) The output of the TM is on the tape. when the tape head is on the leftmost cell and is moved to the left. (hangs) when there is no next state. (hangs) Slide 8 Jaruloj Chongstitvatana 2301379Turing Machines8 How to define deterministic TM (DTM) a quintuple ( Q,,,, s ), where the set of states Q is finite, not containing halt state h, the input alphabet is a finite set of symbols not including the blank symbol, the tape alphabet is a finite set of symbols containing, but not including the blank symbol, the start state s is in Q, and the transition function is a partial function from Q ( { }) Q {h} ( { }) {L, R, S}. Slide 9 Jaruloj Chongstitvatana 2301379Turing Machines9 Example of a DTM M= ({s,p1,p2,p3,p4,q1,q2}, {0,1},{0,1,@},, s} 1/,R q2 h q1 /1,L @/,R /,L s p1 p4 p2 p3 /@,R 0/,R 0/0,R 1/1,R /,L 0/,L 0/0,L 1/1,L /,R Slide 10 Jaruloj Chongstitvatana 2301379Turing Machines10 How a DTM works 1/,R q2 h q1 /1,L @/,R /,L s p1 p4 p2 p3 /@,R 0/,R 0/0,R 1/1,R /,L 0/,L 0/0,L 1/1,L /,R 01 00000 @ 1 On the input 0001000, the TM halts. Slide 11 Jaruloj Chongstitvatana 2301379Turing Machines11 How a DTM works 1/,R q2 h q1 /1,L @/,R /,L s p1 p4 p2 p3 /@,R 0/,R 0/0,R 1/1,R /,L 0/,L 0/0,L 1/1,L /,R 00 00000 @ On the input 0000000, the TM hangs. Slide 12 Jaruloj Chongstitvatana 2301379Turing Machines12 Configuration Definition Let T = (Q,,,, s) be a DTM. A configuration of T is an element of Q {h} ( { }) ( { }) ( { }) Can be written as (q,l,a,r) or (q,l a r) string to the right of tape head symbol under tape head string to the left of tape head Current state Slide 13 Jaruloj Chongstitvatana 2301379Turing Machines13 Yield the next configuration Definition Let T = (Q,,,, s) be a DTM, and (q 1, 1 a 1 1 ) and (q 2, 2 a 2 2 ) be two configurations of T. We say (q 1, 1 a 1 1 ) yields (q 2, 2 a 2 2 ) in one step, denoted by (q 1, 1 a 1 1 ) T (q 2, 2 a 2 2 ), if (q 1, a 1 ) = (q 2,a 2,s), 1 = 2 and 1 = 2, (q 1, a 1 ) = (q 2,b,R), 2 = 1 b and 1 =a 2 2, (q 1, a 1 ) = (q 2,b,L), 1 = 2 a 2 and 2 =b 1. Slide 14 Jaruloj Chongstitvatana 2301379Turing Machines14 Yield in zero step or more Definition Let T=(Q,,,, s) be a DTM, and (q 1, 1 a 1 1 ) and (q 2, 2 a 2 2 ) be two configurations of T. We say (q 1, 1 a 1 1 ) yields (q 2, 1 a 2 2 ) in zero step or more, denoted by (q 1, 1 a 1 1 ) - * T (q 2, 1 a 2 2 ), if q 1 =q 2, 1 = 2, a 1 = a 2, and 1 = 2, or (q 1, 1 a 1 1 ) - T (q, a ) and (q, a ) - * T (q 2, 1 a 2 2 ) for some q in Q, and in *, and a in. Slide 15 Jaruloj Chongstitvatana 2301379Turing Machines15 Yield in zero step or more: Example (s, 0001000) (p1,@0001000) (p2,@ 001000) (p3,@ 001000) (p4,@ 00100 ) (p1,@ 00100 ) (p2,@ 0100 ) (p3,@ 0100) 1/,R q2 h q1 /1,L @/,R /,L s p1 p4 p2 p3 /@,R 0/,R 0/0,R 1/1,R /,L 0/,L 0/0,L 1/1,L /,R (p4,@ 010) (p1,@ 010) (p2,@ 10) (p3,@ 10) (p4,@ 1) (p1,@ 1) (q1,@ ) (q2, ) (h, 1) Slide 16 Jaruloj Chongstitvatana 2301379Turing Machines16 TM accepting a language Definition Let T=(Q,,,, s) be a TM, and w *. T accepts w if (s,,, w) |- T * (h,,, 1). The language accepted by a TM T, denoted by L(T), is the set of strings accepted by T. Slide 17 Jaruloj Chongstitvatana 2301379Turing Machines17 Example of language accepted by a TM L(T)={0 n 10 n | n 0} T halts on 0 n 10 n T hangs on 0 n+1 10 n at p3 T hangs on 0 n 10 n+1 at q1 T hangs on 0 n 1 2 0 n at q1 1/,R q2 h q1 /1,L @/,R /,L s p1 p4 p2 p3 /@,R 0/,R 0/0,R 1/1,R /,L 0/,L 0/0,L 1/1,L /,R Slide 18 Jaruloj Chongstitvatana 2301379Turing Machines18 TM computing a function Definition Let T=(Q,,,, s) be a TM, and f be a function from * to *. T computes f if, for any string w in *, (s,,, w) |- T * (h,,, f(w)). Slide 19 Jaruloj Chongstitvatana 2301379Turing Machines19 Example of TM Computing Function p3p2 /1,R s p1p4 /,R /,L 1/1,R 1/1,L /,R h 1/,L Slide 20 Jaruloj Chongstitvatana 2301379Turing Machines20 Example of TM Computing Function 1/1,L 0/0,L p3p2 /1,L 1/@,R s p1 r2 /,R 0/0,R 1/1,R /,L /,S 0/0,R 1/1,R q2q1 r1 h 0/0,R 1/1,R 0/0,L 1/1,L 0/0,R 1/1,R /0,L 0/@,R @/1,R @/0,R Slide 21 Jaruloj Chongstitvatana 2301379Turing Machines21 Composite TM Let T1 and T2 be TMs. T1 T2 means executing T1 until T1 halts and then executing T2. T1 - a T2 means executing T1 until T1 halts and if the symbol under the tape head when T1 halts is a then executing T2. Slide 22 Jaruloj Chongstitvatana 2301379Turing Machines22 Example of Composite TM T 0-0 T out1 0 1 T erase1 TsTs 0 /@,R s h q2 h q1 /1,L@/,R /,L 1/,R h s p1p4p2p3 0/,R 0/0,R 1/1,R /,L 0/,L 0/0,L 1/1,L /,R h T 0-0 T erase1 TsTs T out1 1 Slide 23 Jaruloj Chongstitvatana 2301379Turing Machines23 Nondeterministic TM An NTM starts working and stops working in the same way as a DTM. Each move of an NTM can be nondeterministic. Slide 24 Jaruloj Chongstitvatana 2301379Turing Machines24 Each Move in an NTM reads the symbol under its tape head According to the transition relation on the symbol read from the tape and its current state, the TM choose one move nondeterministically to: write a symbol on the tape move its tape head to the left or right one cell or not changes its state to the next state Slide 25 Jaruloj Chongstitvatana 2301379Turing Machines25 How to define nondeterministic TM (NTM) a quintuple (Q,,,, s), where the set of states Q is finite, and does not contain halt state h, the input alphabet is a finite set of symbols, not including the blank symbol, the tape alphabet is a finite set of symbols containing, but not including the blank symbol, the start state s is in Q, and the transition f n : Q ( { }) 2 Q {h} ( { }) {L,R,S}. Slide 26 Jaruloj Chongstitvatana 2301379Turing Machines26 Configuration of an NTM Definition Let T = ( Q,,,, s ) be an TM. A configuration of T is an element of Q Can be written as (q,l,a,r) or (q,l a r) string to the right of tape head string to the left of tape head symbol under tape head Slide 27 Jaruloj Chongstitvatana 2301379Turing Machines27 Yield the next configuration Definition Let T = (Q,,,, s) be an NTM, and (q 1, 1 a 1 1 ) and (q 2, 2 a 2 2 ) be two configurations of T. We say (q 1, 1 a 1 1 ) yields (q 2, 2 a 2 2 ) in one step, denoted by (q 1, 1 a 1 1 ) T (q 2, 2 a 2 2 ), if (q 2,a 2,S) (q 1, a 1 ), 1 = 2 and 1 = 2, (q 2,b,R) (q 1, a 1 ), 2 = 1 b and 1 =a 2 2, (q 2,b,L) (q 1, a 1 ), 1 = 2 a 2 and 2 =b 1. Slide 28 Jaruloj Chongstitvatana 2301379Turing Machines28 NTM accepting a language/computing a function Definition Let T = (Q,,,, s) be an NTM. Let w * and f be a function from * to *. T accepts w if (s,,, w) |- T * (h,,, 1). The language accepted by a TM T, denoted by L(T), is the set of strings accepted by T. T computes f if, for any string w in *, (s,,, w) |- T * (h,,, f(w)). Slide 29 Jaruloj Chongstitvatana 2301379Turing Machines29 Example of NTM Let L={ww| w {0,1} * } s p u q0q0 t0t0 r0r0 h /@,R 0/0,L 1/1,L @/,R 0/,L 1/,L 0/0,L 1/1,L /,L 0/ @,R /,R 0/0,R 1/1,R /,R 0/,L 1/,L q1q1 t1t1 r1r1 @/,R 0/0,L 1/1,L /,L 1/ @,R 0/0,R 1/1,R /,R @/,L v 0/0,R 1/1,R /@,L Slide 30 Jaruloj Chongstitvatana 2301379Turing Machines30 Multitape TM TM with more than one tape. Each tape has its own tape head. Each tape is independent. CONTROL UNIT TAPE Slide 31 Jaruloj Chongstitvatana 2301379Turing Machines31 2-Tape Turing Machine a quintuple (Q,,,, s), where the set of states Q is finite, and does not contain the halt state h, the input alphabet is a finite set of symbols, not including the blank symbol, the tape alphabet is a finite set of symbols containing, but not including the blank symbol, the start state s is in Q, and the transition function is a partial function from Q ( { }) 2 Q {h} ( { }) 2 {L, R, S} 2. Slide 32 Jaruloj Chongstitvatana 2301379Turing Machines32 Example of 2-Tape Turing Machine q2 h, /(, ),(L,R) s p1 p4 p2p3, /(, ),(R,S) 0, /(0, ),(R,S) 1, /(1, ),(R,S) 0, /(0,0),(L,R) 1, /(1,1),(L,R), /(, ),(R,S) 0, /(0, ),(R,S) 1, /(1, ),(R,S), /(, ),(L,L) 0,0/(, ),(L, L) 1,1/(, ),(L, L), /(, ),(R,R), /(1, ),(L,L) Slide 33 Jaruloj Chongstitvatana 2301379Turing Machines33 Equivalence of 2-tape TM and single-tape TM Theorem: For any 2-tape TM T, there exists a single- tape TM M such that for any string in * : if T halts on with on its tape, then M halts on with on its tape, and if T does not halt on, then M does not halt on. Slide 34 Jaruloj Chongstitvatana 2301379Turing Machines34 How 1-tape TM simulates 2-tape TM Marking the position of each tape head in the content of the tape Encode content of 2 tapes on 1 tape When to convert 1-tape symbol into 2-tape symbol Construct 1-tape TM simulating a transition in 2- tape TM Convert the encoding of 2-tape symbols back to 1- tape symbols cannot be done all at once because the tape is infinite Slide 35 Jaruloj Chongstitvatana 2301379Turing Machines35 Encoding 2 tapes in 1 tape New alphabet contains: old alphabet encoding of a symbol on tape 1 and a symbol on tape 2 encoding of a symbol on tape 1 pointed by its tape head and a symbol on tape 2 encoding of a symbol on tape 1 and a symbol on tape 2 pointed by its tape head encoding of a symbol on tape 1 pointed by its tape head and a symbol on tape 2 pointed by its tape head 0 1 1 1 0 0 1 0 1 0 1 1 1 0 0 1 0 1 Slide 36 Jaruloj Chongstitvatana 2301379Turing Machines36 How the tape content is changed 0 1 1 1 0 1 1 1 0 0 Slide 37 Jaruloj Chongstitvatana 2301379Turing Machines37 Tape format c(b,) # c(a,)c(b,)c(c,)c(d,) Whats read on tape 1 and 2 seperator Encoded tape content Slide 38 Jaruloj Chongstitvatana 2301379Turing Machines38 Simulating transitions in 2-tape TM in 1-tape TM p q a 1,a 2 /(b 1,b 2 ),(d 1,d 2 ) p q T_tape1 (a 1,b 1,d 1 ) T_tape2 (a 2,b 2,d 2 ) c(a 1,a 2 ) Slide 39 Jaruloj Chongstitvatana 2301379Turing Machines39 T_tape1(0,1,d) S #/#,R c(?,x)/c(?,x),R c(0,?)/c(1,?),d It is not possible that c(1,?) is found because c(0,?) is wriiten in cell 1. c(0,x)/c(0,x),L 0/c(0,),L ? and x are 0, 1, or c(1,x)/c(1,x),L 1/c(1,),L c(,x)/c(,x),L/c(,),L Remember symbol under tape head in tape 1 #/#,L not #/not #,L c(?,x)/c(0,x),R c(?,x)/c(,x),R c(?,x)/c(1,x),R Convert 1-tape symbol into 2-tape symbol Update the first cell h c(?,?)/c(?,?),R Slide 40 Jaruloj Chongstitvatana 2301379Turing Machines40 T cleanup pnpn p1 p1 c(0, )|0, S c(1, )|1, S c(, )|, S c(0, ?)|, L |, L #/,R ?|, R |c(0, ), R |, L |1, R h |, R /,L c(1,?)|1,L 0|0,L 1|1,L |,R Slide 41 Jaruloj Chongstitvatana 2301379Turing Machines41 T encode s h 0/,R /c(0, ),L 1/,R /,L 0/0,R 1/1.R /,L /c(1, ),L /,R /#,R /,L#/c(, ),R /#,L Slide 42 Jaruloj Chongstitvatana 2301379Turing Machines42 Equivalence of 2-tape TM and single-tape TM Proof: Let T = (Q,,,, s) be a 2-tape TM. We construct a 1-tape TM M=(K,,,, s) such that = {c(a,b)| a,b are in { }} {c(a,b)| a,b are in { }} {c(a,b)|a,b are in { }} {c(a,b)|a,b are in { }} {#} We need to prove that: if T halts on with output, then M halts on with output, and if T does not halt on, then M does not halt on Slide 43 Jaruloj Chongstitvatana 2301379Turing Machines43 if T halts on with output Slide 44 Jaruloj Chongstitvatana 2301379Turing Machines44 if T does not halt on If T loops, then M loops. If T hangs in a state p, M hangs somewhere from p to the next state. Slide 45 Jaruloj Chongstitvatana 2301379Turing Machines45 Equivalence of NTM and DTM Theorem: For any NTM M n, there exists a DTM M d such that: if M n halts on input with output, then M d halts on input with output, and if M n does not halt on input, then M d does not halt on input. Proof: Let M n = (Q,,,, s) be an NTM. We construct a 2-tape TM M d from M n as follows: Slide 46 Jaruloj Chongstitvatana 2301379Turing Machines46 Construct a DTM equivalent to an NTM WriteInitialConfiguration Set WorkingTape FindStateinCurrentConfiguration WriteAllPossibleNextConfiguration EraseCurrentConfiguration FindNewConfiguration h a,h a,q a is any symbol, q is any state in Q Depend on M n Tape 1: simulate M n s tape Tape 2: store configuration tree Slide 47 Jaruloj Chongstitvatana 2301379Turing Machines47 How M d works s01*0 1 # 0011 q01#0 1 #s01#0@1 # Current state: s -------- * @ Current state: q 01q#0 1 #-------- * * Current state: s WriteInitialConfiguration Set Working Tape FindStateinCurrentConfiguration WriteAllPossibleNextConfiguration EraseCurrentConfiguration FindNewConfiguration h a,h a,q sq 0/0,R /@,S /,R Tape 2 Tape 1 Slide 48 Jaruloj Chongstitvatana 2301379Turing Machines48 WriteAllPossibleNextConfiguration pq1q1 q2q2 qnqn a/b 1,d 1 a/b 2,d 2 a/b n,d n Writeq 1 b 1 d 1 Writeq 2 b 2 d 2 Writeq n b n d n a,p For each (p,a,q i,b i,d i ), 1 i n Slide 49 Jaruloj Chongstitvatana 2301379Turing Machines49 Example: WriteAllPossibleNextConfiguration sq 0/0,R /@,S /,R WriteqR Writes@R,s 0,q Writeq0R Nondeterministic move Deterministic move Slide 50 Jaruloj Chongstitvatana 2301379Turing Machines50 if M n halts on input with output Then, there is a positive integer n such that the initial configuration (s, ) of M n yeilds a halting configuration (h, ) in n steps. From the construction of M d, the configuration (h, ) must appear on tape 2 at some time. Then, M d must halt with on tape 1. Slide 51 Jaruloj Chongstitvatana 2301379Turing Machines51 if M n does not halt on input Then, M n cannot reach the halting configuration. That is, ( s, ) never yields a halting configuration ( h, ). From the construction of M d, the configuration ( h, ) never appears on tape 2. Then, M d never halt. Slide 52 Jaruloj Chongstitvatana 2301379Turing Machines52 Universal Turing Machine Given the description of a DTM T and an input string z, a universal TM simulates how T works on input z. Whats need to be done? How to describe T and z on tape Use an encoding function How to simulate T Slide 53 Jaruloj Chongstitvatana 2301379Turing Machines53 Encoding function Let T=(Q,,, s) be a TM. The encoding function e( T ) is defined as follows: e( T )=e( s )#e( ), e( )=e( m 1 )#e( m 2 )#...#e( m n )#, where = { m 1, m 2,..., m n } e( m )=e( p ),e( a ),e( q ),e( b ),e( d ), where m = (p, a, q, b, d) e( z )=1e( z 1 )1e( z 2 )11e( z m )1, where z=z 1 z 2 z m is a string e( )=0, e( a i )=0 i +1, where a i is in e( h )=0, e( q i )=0 i +1, where q i is in Q e(S)=0, e(L)=00, e(R)=000 Slide 54 Jaruloj Chongstitvatana 2301379Turing Machines54 Example of Encoded TM e( )=0,e(a 1 )=00,e(a 2 )=000 e(h)=0,e(q 1 )=00,e(q 2 )=000 e(S)=0, e(L)=00,e(R)=000 e( a 1 a 1 a 2 ) = 1e( )1e(a 1 )1e(a 1 )1e(a 2 )1e( )1 = 101001001000101 e(m 1 ) = (q 1 ),e(a 1 ),e(q 2 ),e(a 2 ),e(R) = 00,00,000,000,000 e(m 2 ) = e(q 2 ),e( ),e(h),e( ),e(S) = 000,0,0,0,0 e( ) = e(m 1 )#e(m 2 )#...# = 00,00,000,000,000#000,0,0,0,0#...# e(T) = e(s)#e( ) = 00#00,00,000,000,000#000,0,0,0,0#...# Input = e(Z)|e(T)| = 101001001000101|00#00,00,000,000,000#000,0,0,0,0#...#| q1q1 q2q2 h a 1 /a 2,R /,s Slide 55 Jaruloj Chongstitvatana 2301379Turing Machines55 Universal Turing Machine Tape 1: I/O tape, store the transition function of T and input of T Tape 2: simulate Ts tape Tape 3: store Ts state CopyInputToTape2 CopyTape2ToTape1UpdateStateOnTape3 UpdateTape2FindRightMove CopyStartStateToTape3 0 (halt) Slide 56 Jaruloj Chongstitvatana 2301379Turing Machines56 How UTM Works CopyInputToTape2 CopyTape2ToTape1UpdateStateOnTape3 UpdateTape2 FindRightMove CopyStartStateToTape3 Not halt halt 0 1 0 0 1 0 1 1 0 0 1 0 1 | 0 0 # 0 0, 0 0, 0 0 0, 0 0 0, 0 0 0 # 0 0 0, 0, 0, 0, 0 #... # | Tape 1 Tape 3 Tape 2 1 0 0 0 1 0 1 0 0 00 a 2 Slide 57 Jaruloj Chongstitvatana 2301379Turing Machines57 Church-Turing Thesis Turing machines are formal versions of algorithms. No computational procedure will be considered an algorithm unless it can be presented as a Turing machine. Slide 58 Jaruloj Chongstitvatana 2301379Turing Machines58 Checklist Construct a DTM, multitape TM, NTM accepting languages or computing function Construct composite TM Prove properties of languages accepted by specific TM Prove the relationship between different types of TM Describe the relationship between TM and FA Prove the relationship between TM and FA