Presentation is loading. Please wait.

Presentation is loading. Please wait.

Turing Machines (TM) Model of Computation. Jaruloj Chongstitvatana 2301379Turing Machines2 Outlines Structure of Turing machines Deterministic Turing.

Similar presentations


Presentation on theme: "Turing Machines (TM) Model of Computation. Jaruloj Chongstitvatana 2301379Turing Machines2 Outlines Structure of Turing machines Deterministic Turing."— Presentation transcript:

1 Turing Machines (TM) Model of Computation

2 Jaruloj Chongstitvatana Turing 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)

3 Jaruloj Chongstitvatana Turing 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

4 Jaruloj Chongstitvatana Turing 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)?

5 Jaruloj Chongstitvatana Turing 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.

6 Jaruloj Chongstitvatana Turing 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

7 Jaruloj Chongstitvatana Turing 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)

8 Jaruloj Chongstitvatana Turing 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}.

9 Jaruloj Chongstitvatana Turing Machines9 Example of a DTM M= ({s,p1,p2,p3,p4,q1,q2}, s} 1/,R q2 h q1 /,L s p1 p4 p2 p3 0/,R 0/0,R 1/1,R /,L 0/,L 0/0,L 1/1,L /,R

10 Jaruloj Chongstitvatana Turing Machines10 How a DTM works 1/,R q2 h q1 /,L s p1 p4 p2 p3 0/,R 0/0,R 1/1,R /,L 0/,L 0/0,L 1/1,L /,R 01 1 On the input , the TM halts.

11 Jaruloj Chongstitvatana Turing Machines11 How a DTM works 1/,R q2 h q1 /,L s p1 p4 p2 p3 0/,R 0/0,R 1/1,R /,L 0/,L 0/0,L 1/1,L /,R 00 On the input , the TM hangs.

12 Jaruloj Chongstitvatana Turing 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

13 Jaruloj Chongstitvatana Turing 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.

14 Jaruloj Chongstitvatana Turing 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.

15 Jaruloj Chongstitvatana Turing Machines15 Yield in zero step or more: Example (s, ) ) ) ) ) 0100 ) 0100) 1/,R q2 h q1 /,L s p1 p4 p2 p3 0/,R 0/0,R 1/1,R /,L 0/,L 0/0,L 1/1,L /,R 010) 010) 10) 10) 1) 1) ) (q2, ) (h, 1)

16 Jaruloj Chongstitvatana Turing 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.

17 Jaruloj Chongstitvatana Turing 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 n at q1 1/,R q2 h q1 /,L s p1 p4 p2 p3 0/,R 0/0,R 1/1,R /,L 0/,L 0/0,L 1/1,L /,R

18 Jaruloj Chongstitvatana Turing 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)).

19 Jaruloj Chongstitvatana Turing Machines19 Example of TM Computing Function p3p2 /1,R s p1p4 /,R /,L 1/1,R 1/1,L /,R h 1/,L

20 Jaruloj Chongstitvatana Turing Machines20 Example of TM Computing Function 1/1,L 0/0,L p3p2 /1,L 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

21 Jaruloj Chongstitvatana Turing 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.

22 Jaruloj Chongstitvatana Turing Machines22 Example of Composite TM T 0-0 T out1 0 1 T erase1 TsTs 0 s h q2 h q1 /,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

23 Jaruloj Chongstitvatana Turing 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.

24 Jaruloj Chongstitvatana Turing 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

25 Jaruloj Chongstitvatana Turing 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}.

26 Jaruloj Chongstitvatana Turing 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

27 Jaruloj Chongstitvatana Turing 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.

28 Jaruloj Chongstitvatana Turing 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)).

29 Jaruloj Chongstitvatana Turing Machines29 Example of NTM Let L={ww| w {0,1} * } s p u q0q0 t0t0 r0r0 h 0/0,L 0/,L 1/,L 0/0,L 1/1,L /,L /,R 0/0,R 1/1,R /,R 0/,L 1/,L q1q1 t1t1 0/0,L 1/1,L /,L 0/0,R 1/1,R v 0/0,R 1/1,R

30 Jaruloj Chongstitvatana Turing Machines30 Multitape TM TM with more than one tape. Each tape has its own tape head. Each tape is independent. CONTROL UNIT TAPE

31 Jaruloj Chongstitvatana Turing 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.

32 Jaruloj Chongstitvatana Turing 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)

33 Jaruloj Chongstitvatana Turing 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.

34 Jaruloj Chongstitvatana Turing 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

35 Jaruloj Chongstitvatana Turing 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

36 Jaruloj Chongstitvatana Turing Machines36 How the tape content is changed

37 Jaruloj Chongstitvatana Turing Machines37 Tape format c(b,) # c(a,)c(b,)c(c,)c(d,) … Whats read on tape 1 and 2 seperator Encoded tape content

38 Jaruloj Chongstitvatana Turing 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 )

39 Jaruloj Chongstitvatana Turing 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

40 Jaruloj Chongstitvatana Turing 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

41 Jaruloj Chongstitvatana Turing 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

42 Jaruloj Chongstitvatana Turing 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

43 Jaruloj Chongstitvatana Turing Machines43 if T halts on with output

44 Jaruloj Chongstitvatana Turing 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.

45 Jaruloj Chongstitvatana Turing 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:

46 Jaruloj Chongstitvatana Turing 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

47 Jaruloj Chongstitvatana Turing Machines47 How M d works s01*0 1 # 0011 q01#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 /,R Tape 2 Tape 1

48 Jaruloj Chongstitvatana Turing 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

49 Jaruloj Chongstitvatana Turing Machines49 Example: WriteAllPossibleNextConfiguration sq 0/0,R /,R WriteqR 0,q Writeq0R … Nondeterministic move Deterministic move

50 Jaruloj Chongstitvatana Turing 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.

51 Jaruloj Chongstitvatana Turing 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.

52 Jaruloj Chongstitvatana Turing 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

53 Jaruloj Chongstitvatana Turing 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 )1…1e( 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

54 Jaruloj Chongstitvatana Turing 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 = 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)| = |00#00,00,000,000,000#000,0,0,0,0#...#| q1q1 q2q2 h a 1 /a 2,R /,s

55 Jaruloj Chongstitvatana Turing 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)

56 Jaruloj Chongstitvatana Turing Machines56 How UTM Works CopyInputToTape2 CopyTape2ToTape1UpdateStateOnTape3 UpdateTape2 FindRightMove CopyStartStateToTape3 Not halt halt | 0 0 # 0 0, 0 0, 0 0 0, 0 0 0, # 0 0 0, 0, 0, 0, 0 #... # | Tape 1 Tape 3 Tape a 2

57 Jaruloj Chongstitvatana Turing 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.

58 Jaruloj Chongstitvatana Turing 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


Download ppt "Turing Machines (TM) Model of Computation. Jaruloj Chongstitvatana 2301379Turing Machines2 Outlines Structure of Turing machines Deterministic Turing."

Similar presentations


Ads by Google