A Turing Machine
Total Page:16
File Type:pdf, Size:1020Kb
1/45 Turing Machines and General Grammars Alan Turing (1912 – 1954) 2/45 Turing Machines (TM) Gist: The most powerful computational model. Finite State Control Tape: Read-write head a1 a2 … ai … an … moves Note: = blank 3/45 Turing Machines: Definition Definition: A Turing machine (TM) is a 6-tuple M = (Q, , , R, s, F), where • Q is a finite set of states • is an input alphabet • is a tape alphabet; ; • R is a finite set of rules of the form: pa qbt, where p, q Q, a, b , t {S, R, L} • s Q is the start state • F Q is a set of final states Mathematical note: • Mathematically, R is a relation from Q to Q {S, R, L} • Instead of (pa, qbt), we write pa qbt 4/45 Interpretation of Rules • pa qbS: If the current state and tape symbol are p and a, respectively, then replace a with b, change p to q, and keep the head Stationary. p q x a y x b y • pa qbR: If the current state and tape symbol are p and a, respectively, then replace a with b, shift the head a square Right, and change p to q. p q x a y x b y • pa qbL: If the current state and tape symbol are p and a, respectively, then replace a with b, shift the head a square Left, and change p to q. p q x a y x b y 5/45 Graphical Representation q represents q Q s represents the initial state s Q f represents a final state f F p a/b, S q denotes pa qbS R p a/b, R q denotes pa qbR R p a/b, L q denotes pa qbL R 6/45 Turing Machine: Example 1/2 M = (Q, , , R, s, F) where: 6/45 Turing Machine: Example 1/2 M = (Q, , , R, s, F) where: • Q = {s, p, q, f}; s f p q 6/45 Turing Machine: Example 1/2 M = (Q, , , R, s, F) where: • Q = {s, p, q, f}; • = {a, b}; s f p q 6/45 Turing Machine: Example 1/2 M = (Q, , , R, s, F) where: • Q = {s, p, q, f}; • = {a, b}; s f • = {a, b, }; p q 6/45 Turing Machine: Example 1/2 M = (Q, , , R, s, F) where: • Q = {s, p, q, f}; /, S • = {a, b}; s f • = {a, b, }; • R = {s fS, p q 6/45 Turing Machine: Example 1/2 M = (Q, , , R, s, F) where: • Q = {s, p, q, f}; /, S • = {a, b}; s f • = {a, b, }; • R = {s fS, a/a, R sa paR, p q 6/45 Turing Machine: Example 1/2 M = (Q, , , R, s, F) where: • Q = {s, p, q, f}; /, S • = {a, b}; s f • = {a, b, }; • R = {s fS, a/a, R b/b, R sa paR, sb pbR, p q 6/45 Turing Machine: Example 1/2 M = (Q, , , R, s, F) where: • Q = {s, p, q, f}; /, S • = {a, b}; s f • = {a, b, }; • R = {s fS, a/a, R b/b, R sa paR, sb pbR, pa paR, a/a, R p q 6/45 Turing Machine: Example 1/2 M = (Q, , , R, s, F) where: • Q = {s, p, q, f}; /, S • = {a, b}; s f • = {a, b, }; • R = {s fS, a/a, R b/b, R sa paR, sb pbR, pa paR, a/a, R b/b, R pb pbR, p q 6/45 Turing Machine: Example 1/2 M = (Q, , , R, s, F) where: • Q = {s, p, q, f}; /, S • = {a, b}; s f • = {a, b, }; • R = {s fS, a/a, R b/b, R sa paR, sb pbR, pa paR, a/a, R b/b, R pb pbR, p q p qL, /, L 6/45 Turing Machine: Example 1/2 M = (Q, , , R, s, F) where: • Q = {s, p, q, f}; /, S • = {a, b}; s f • = {a, b, }; • R = {s fS, a/a, R b/b, R sa paR, a/, S sb pbR, pa paR, a/a, R b/b, R pb pbR, p q p qL, /, L qa fS, 6/45 Turing Machine: Example 1/2 M = (Q, , , R, s, F) where: • Q = {s, p, q, f}; /, S • = {a, b}; s f • = {a, b, }; • R = {s fS, a/a, R b/b, R sa paR, b/, S a/, S sb pbR, pa paR, a/a, R b/b, R pb pbR, p q p qL, /, L qa fS, qb fS} 6/45 Turing Machine: Example 1/2 M = (Q, , , R, s, F) where: • Q = {s, p, q, f}; /, S • = {a, b}; s f • = {a, b, }; • R = {s fS, a/a, R b/b, R sa paR, b/, S a/, S sb pbR, pa paR, a/a, R b/b, R pb pbR, p q p qL, /, L qa fS, qb fS} 6/45 Turing Machine: Example 1/2 M = (Q, , , R, s, F) where: • Q = {s, p, q, f}; /, S • = {a, b}; s f • = {a, b, }; • R = {s fS, a/a, R b/b, R sa paR, b/, S a/, S sb pbR, pa paR, a/a, R b/b, R pb pbR, p q p qL, /, L qa fS, qb fS} • F = {f} 7/45 Turing Machine: Example 2/2 Note: M deletes a symbol TM M: before the first occurrence of : /, S Illustration: s f s a b … a/a, R b/b, R b/, S a/, S a/a, R b/b, R p q /, L 7/45 Turing Machine: Example 2/2 Note: M deletes a symbol TM M: before the first occurrence of : /, S Illustration: s f s a b … a/a, R b/b, R p b/, S a/, S a b … a/a, R b/b, R p q /, L 7/45 Turing Machine: Example 2/2 Note: M deletes a symbol TM M: before the first occurrence of : /, S Illustration: s f s a b … a/a, R b/b, R p b/, S a/, S a b … p a/a, R b/b, R a b … p q /, L 7/45 Turing Machine: Example 2/2 Note: M deletes a symbol TM M: before the first occurrence of : /, S Illustration: s f s a b … a/a, R b/b, R p b/, S a/, S a b … p a/a, R b/b, R a b … p q q a b … /, L 7/45 Turing Machine: Example 2/2 Note: M deletes a symbol TM M: before the first occurrence of : /, S Illustration: s f s a b … a/a, R b/b, R p b/, S a/, S a b … p a/a, R b/b, R a b … p q q a b … /, L f a … 8/45 TM Configuration Gist: Instantaneous description of TM What does a configuration describes? 1) Current state 2) Tape Contents 3) Position of the head 1. p 2. p a1 a2 … ai ai+1 … an … a1 a2 … an … x y x y Configuration xpy Definition: Let M = (Q, , , R, s, F) be a TM. A configuration of M is a string = xpy, where x *, p Q, y *( – {}) {}. 9/45 Stationary Move Definition: Let , ’ be two configurations of M. Then, M makes a stationary move from to ’ according to r, written as |–S ’ [r] or, simply, |–S ’ if = xpay, ’ = xqby and r: pa qbS R Illustration: p x a y x p a y Configuration 9/45 Stationary Move Definition: Let , ’ be two configurations of M. Then, M makes a stationary move from to ’ according to r, written as |–S ’ [r] or, simply, |–S ’ if = xpay, ’ = xqby and r: pa qbS R Illustration: Rule: pa qbS p x a y x p a y Configuration 9/45 Stationary Move Definition: Let , ’ be two configurations of M. Then, M makes a stationary move from to ’ according to r, written as |–S ’ [r] or, simply, |–S ’ if = xpay, ’ = xqby and r: pa qbS R Illustration: Rule: pa qbS p q x a y x b y x p a y x q b y Configuration New Configuration 10/45 Right Move Definition: Let , ’ be two configurations of M. Then, M makes a right move from to ’ according to r, written as |–R ’ [r] or, simply, |–R ’ if = xpay, r: pa qbR R and (1) ’ = xbqy, y or (2) ’ = xbq, y = p x a y x p a y Configuration 10/45 Right Move Definition: Let , ’ be two configurations of M. Then, M makes a right move from to ’ according to r, written as |–R ’ [r] or, simply, |–R ’ if = xpay, r: pa qbR R and (1) ’ = xbqy, y or (2) ’ = xbq, y = p Rule: pa qbR x a y x p a y Configuration 10/45 Right Move Definition: Let , ’ be two configurations of M. Then, M makes a right move from to ’ according to r, written as |–R ’ [r] or, simply, |–R ’ if = xpay, r: pa qbR R and (1) ’ = xbqy, y or (2) ’ = xbq, y = p Rule: pa qbR q x a y x b y x p a y x b q y Configuration New Configuration 10/45 Right Move Definition: Let , ’ be two configurations of M. Then, M makes a right move from to ’ according to r, written as |–R ’ [r] or, simply, |–R ’ if = xpay, r: pa qbR R and (1) ’ = xbqy, y or (2) ’ = xbq, y = p Rule: pa qbR q x a y x b y x p a y x b q y or Configuration New Configuration p x a … x p a Configuration 10/45 Right Move Definition: Let , ’ be two configurations of M.