=========================================================================== CSC 363 Formal example of TM equivalence Winter 2008 =========================================================================== Formal proof that TMs with 2-way infinite tape ("2WITM" for "2-way infinite TM") are equivalent to regular TMs. Given an arbitrary TM M = (Q,\Sigma,\Gamma,q_1,q_A,q_R,\delta), where # !(- \Gamma, define a 2WITM M' as follows: \Sigma' = \Sigma \Gamma' = \Gamma U {#} Q' = Q U {q'_0, q_0} initial state = q'_0 accept state = q_A reject state = q_R - Implementation level description: On input w, 1. Write # immediately to the left of the input and move the head back to the first square of w, in state q_1. 2. Run the computation of M on w. Each time the new symbol # is encountered, leave it there and move one square right to continue the computation (this simulates the behaviour of M when it attempts to move left while on its leftmost square). - Formal description: One way to think of what must be done is to imagine the transition function of M written down in a table, where Q = {q_1,...,q_n,q_A,q_R} and \Gamma = {_,a_1,...a_m}: _ a_1 ... a_m -------------------------------------------- q_1 | | ... | Transition table of M. | q_n | | -------------------------------------------- In M', we simply copy this entire table and add to it. We've added two new states q'_0 and q_0 and one new symbol #, so the table for M' looks like this: _ a_1 ... a_m # q'_0 q_0 -------------------------------------------- q_1 | | ... | Transition table of M. | q_n | | -------------------------------------------- In addition to the transitions from M, we must specify transitions for the new states on each symbol, and for each state on the new symbol. Accordingly, define \delta' as follows (with comments to explain the purpose of groups of transitions): . write # to the left of input, then start in same state as M: \delta'(q'_0,a) = (q_0,a,L) for all a (- \Gamma' \delta'(q_0,a) = (q_1,#,R) for all a (- \Gamma' . behave the same as M for all original states and symbols: \delta'(q,a) = \delta(q,a) for all q (- Q-{q_A,q_R,q'_0,q_0}, a (- \Gamma . # is encountered when M tries to move left on leftmost square -- just leave # there, move right, and stay in same state: \delta'(q,#) = (q,#,R) for all q (- Q-{q_A,q_R,q'_0,q_0} Note that the transitions \delta'(q'_0,#) and \delta'(q_0,a) for a != _ are superfluous (they can never arise, because of the design of M'), so they could be defined arbitrarily without affecting the behaviour of M'. However, they are formally required as part of the definition -- so we pick a simplest definition possible (and point this out to avoid confusion). - Clearly, M' has the same behaviour as M on every input string w (- \Sigma*: . The initial configuration of M: q_1 w becomes in M': q'_0 w -> q_0 _w -> # q_1 w . Each transition of M: u q_i av -> ub q_j v becomes in M': #u q_i av -> #ub q_j v . Each transition of M: uc q_i av -> u q_j cbv becomes in M': #uc q_i av -> #u q_j cbv . Each transition of M: q_i av ----------------> q_i bv becomes in M': # q_i av -> q_i #bv -> # q_i bv So M' accepts/rejects/loops exactly when M accepts/rejects/loops, for all input strings. (If we wanted, we could prove this formally, by induction on the number of transitions in the computation of M.) Given an arbitrary 2WITM M = (Q,\Sigma,\Gamma,q_1,q_A,q_R,\delta), where Q = {q_1,...,q_n,q_A,q_R} and \Gamma = {_,a_1,...,a_m} does not contain the symbols $, #, or #_1, ..., #_n, define a TM M' as follows: \Sigma' = \Sigma \Gamma' = \Gamma U {$,#,#_1,...,#_n} Q' = Q U {q_0^#,q_0^1,...,q_0^m} U {q'_1,...,q'_n} U {q_S^_,q_S^1,...,q_S^m,q_S^$,q_S^#} initial state = q_0^# accept state = q_A reject state = q_R - Implementation level description: On input w, 1. Shift w one square right to insert # on the leftmost square, and add $ to the right of w (the tape now contains #w$) -- # will be used to detect when M moves left to a previously unvisited cell on its tape, while $ will be used to detect when this happens on the right. We need different symbols because once a transition is complete, a TM has no "memory" of the last direction of its head movement. 2. Run the computation of M on w. Each time the new symbol $ is encountered while in some state q_i (- Q, move $ one square to the right (insert _) and move back to the newly inserted _ in state q_i -- this requires one new state for each original state, to remember what state to go back to. Each time the new symbol # is encountered while in some state q_i (- Q, replace it with #_i (to remember the state we were in when # was read), then shift the contents of the tape one square right to insert a _ ($ marks the last square that requires shifting), before going back to the newly inserted _ in state q_i. Note that we are using two different techniques for remembering what state to return to after inserting an extra _ on the tape: different new states when we shift $ one square right, and different new symbols when we shift the entire tape content one square right. These are not the only possibilities, but they are the most convenient in this case. - Formal description: Suppose the transition table of M is as follows: _ a_1 ... a_m q_1 \delta(q_1, _ ) \delta(q_1,a_1) ... \delta(q_1,a_m) ... ... ... ... ... q_n \delta(q_n, _ ) \delta(q_n,a_1) ... \delta(q_n,a_m) I am going to represent this with the following shorthand notation, where "q_i" stands for all the rows from q_1 to q_n, and "a_j" stands for all the columns from a_1 to a_m: _ a_j q_i d(q_i, _ ) d(q_i,a_j) Then here is the transition table of M', given in sections, together with comments about the purpose of each group of states -- superfluous transitions (those that can never be encountered by the design of M') are surrounded by square brackets []. . insert # left of input (shift input one square right) and $ right of input (for 1 <= i <= m, 1 <= j <= m, 1 <= k <= n): _ a_j $ # #_k q_0^# q_S^$,#_1,R q_0^j,#_1,R [q_0^#,#_1,R][q_0^#,#_1,R][q_0^#,#_1,R] q_0^i q_S^$,a_i,R q_0^j,a_i,R [q_0^#,a_i,R][q_0^#,a_i,R][q_0^#,a_i,R] . behave the same as M for all original states and symbols; when encountering $, shift it one space right, inserting _, and when encountering #, shift the entire tape content (up to $) one square right, inserting _ (for 1 <= i <= n, 1 <= j <= m, 1 <= k <= n): _ a_j $ # #_k q_i d(q_i, _ ) d(q_i,a_j) q'_i, _ ,R q_S^_,#_i,R [q_S^_,#_i,R] . move $ one square right, inserting _ (for 1 <= i <= n, 1 <= j <= m, 1 <= k <= n): _ a_j $ # #_k q'_i q_i , $ ,L [ q_i , $ ,L][ q_i , $ ,L][ q_i , $ ,L][ q_i , $ ,L] . shift tape content of M one square right, inserting _, then move head back to leftmost square, change #_k to #, and move one square right into state q_k (for 1 <= i <= m, 1 <= j <= m, 1 <= k <= n): _ a_j $ # #_k q_S^_ q_S^_, _ ,R q_S^j, _ ,R q_S^$, _ ,R [q_S^#, _ ,R][q_S^#, _ ,R] q_S^i q_S^_,a_i,R q_S^j,a_i,R q_S^$,a_i,R [q_S^#,a_i,R][q_S^#,a_i,R] q_S^$ q_S^#, $ ,L [q_S^#, $ ,L][q_S^#, $ ,L][q_S^#, $ ,L][q_S^#, $ ,L] q_S^# q_S^#, _ ,L q_S^#,a_j,L [q_S^#, $ ,L][q_S^#, # ,L] q_k , # ,R - While it may not be as obvious as for the first part, M' has the same behaviour as M on every input string w (- \Sigma*: . Initial configuration in M: q_1 w becomes in M': q_0^# w -> ... -> # q_1 w$ . Transition in M: u q_i av ---> ub q_j v becomes in M': #u q_i av$ -> #ub q_j v$ . Transition in M: uc q_i av ---> u q_j cbv becomes in M': #uc q_i av$ -> #u q_j cbv$ . Transition in M: u q_i a ----------------------------> ub q_j _ becomes in M': #u q_i a$ -> #ub q_j $ -> #ub_ q'_j _ -> #ub q_j _$ . Transition in M: q_i av ------------------------> q_j _cv becomes in M': # q_i av$ -> q_j #cv$ -> #_j q_S^_ cv$ -> ... -> q_S^# #_j _cv$ -> # q_j _cv$ So M' accepts/rejects/loops exactly when M accepts/rejects/loops, for all input strings. (If we wanted, we could prove this formally, by induction on the number of transitions in the computation of M.)