Stupid T uring Mac hine T ric ks Often it is useful to think of the state and the tap e sym b ol as ha ving structure. � The comp onen ts of a tap e sym b ol are tr acks . � Usually one comp onen t of the state is the c ontr ol , resp onsible for running the \program" of the TM; other comp onen ts hold data. Example Let M = ( Q; � ; � ; � ; q ; B ; F ). Supp ose the 0 program of M needs to sw ap the con ten ts of adjacen t tap e cells sometimes. � Some of the states in Q will b e of the form [ q ; X ] and [ p; X ], where X is an y sym b ol in �. W e also need states r to b egin and s to end. � In state r , M will pic k up the sym b ol scanned in to the data p ortion of the state. ✦ � ( r ; X ) = ([ q ; X ] ; X ; R ) for all X in �. � In con trol state q , M dep osits the sym b ol in its data comp onen t and pic ks up the sym b ol that w as there, going to con trol state p . ✦ ([ q ] ; ) = ([ p; ] ; L ) for all and � ; X Y Y X ; X in �. Y � In con trol state p , dep osits its data and M en ters state s , mo ving righ t. ✦ ([ p; ] ; ) = ( s; R ) for all and in � X Y X ; X Y �. Example: Multiple T rac ks A common use for m ultiple trac ks is to use one trac k for data the other for a single \mark." � Sym b ols of � are pairs [ A; ], where is the X X \real" sym b ol, and is either (blank) or � . A B ✦ Input sym b ol is iden ti�ed with [ B a ]. a ; ✦ The blank is [ B ]. ; B � Here's a program to �nd the � , assuming it is somewhere to the left of the presen t p osition. 1. ( q [ B ]) = ( q [ B ] ; L ) � ; ; X ; ; X 2. ( q [ � ; ]) = ( p; [ B ] ; R ) � ; X ; X Other TM Mo dels While regular or CF languages are classes of languages that w e de�ned b y con v enien t notations (RE's, CF G's, etc.), no one supp osed that they represen ted \ev erything w e can compute." 1
� The purp ose of the TM w as to de�ne \ev erything w e can compute." ✦ F or con v enience, w e use recognition of languages as the space of p ossibly computable things; other spaces, e.g., computing arithmetic functions, yield the same conclusions. � Th us, it w ould b e a wkw ard if w e could �nd another notion of \ev erything" that w as di�eren t from the TM. ✦ A real computer is an imp ortan t sp ecial case. Do real computers and TM's de�ne the same set of computable things? � Our next steps are to consider p oten tially more p o w erful notions of computing and see that the TM mo del w e de�ned can sim ulate them. ✦ These mo dels are: m ultitap e TM, nondeterministic TM, m ultistac k mac hines, coun ter mac hines, \real" computers. Multitap e TM's Allo w the TM to ha v e some �nite n um b er of tap es , with a head for eac h tap e. k � Mo v e is a function of the state and the sym b ol scanned b y eac h tap e head. � Action = new state, new sym b ol for eac h tap e, and a head motion (L, R, or S, for \stationary"). � First tap e holds the input, other tap es are initially blank. Man y T ap es to One T ap e Sim ulati on T o sim ulate tap es, use one tap e with 2 k trac ks. k � One trac k holds the con ten ts of eac h tap e. � Another trac k holds a mark represen ting the head p osition of that tap e, as � W X Y Z � T o sim ulate one mo v e of the m ultitap e TM, the one-tap e TM m ust remem b er ho w man y *'s are to its left. 2
1. Mo v e left, then righ t, visiting all the *'s to see what eac h tap e head is scanning. 2. Decide on the m ultitap e TM's mo v e, based on the scanned sym b ols and its state (remem b ered in the state of the one- tap e TM). 3. Visit eac h * again, making the necessary adjustmen ts: c hange sym b ols and mo v e *'s one cell left or righ t, as needed. � Imp ortan t observ ation for when w e study p olynomial time TM's: If the m ultitap e TM mak es ( n ) mo v es when the input is of length T � 2 � n , then the one-tap e TM mak es ( n ) O T mo v es. ✦ Th us, if the m ultitap e TM tak es p olynomial time, so do es the one-tap e TM. ✦ Key p oin t in pro of: The *'s can't get more than ( n ) cells apart, so one mo v e T � � is sim ulated in ( n ) mo v es of the one- O T tap e TM. Nondetermini st ic TM Let the TM ha v e a �nite set of c hoices of mo v e. � As with the (nondeterministic) PD A, there is no \mix-and-m a tc h"; if ( p; X ; L ) and ( q ; Y ; R ) are c hoices, w e cannot go to state q , prin t X on the cell and mo v e righ t, e.g., unless ( q ; X ; R ) is another c hoice. Nondetermini st ic to Determini sti c Sim ulati on Let the NTM ha v e one tap e, but �rst sim ulate with a m ultitap e DTM; later con v ert the m ultitap e DTM to a one-tap e DTM. � Use one tap e of DTM to hold a queue of ID's of the NTM, separated b y sp ecial mark ers (*). � When an ID reac hes the fron t of the queue, �nd all its next ID's, and add them to the bac k of the queue. � Accept if y ou ev er reac h an ID with an accepting state. ✦ Note that the queue discipline is imp ortan t, so that the DTM ev en tually reac hes ev ery ID that the NTM can en ter. ✦ In con trast, if w e used a stac k discipline, the NTM migh t reac h acceptance, but the 3
DTM w ould go o� on some in�nite c hase of ID's and nev er reac h the accepting ID of the NTM. MultiStac k Mac hines Lik e PD A, but with more than one stac k. � One stac k is not enough to sim ulate a TM; y ou get only CFL's. ✦ While w e ha v en't emphasized the p oin t, all the examples in Section 7.2.3 of non- CFL's are recognized b y TM's. � But 2 stac ks is enough! � Key idea: use one stac k to hold what is to the left of the tap e head, use the other to hold what is to the righ t. Coun ter Mac hines Tw o equiv alen t w a ys to think of a coun ter: 1. A stac k with a b ottom-mark er, sa y , and Z 0 one other sym b ol, sa y X , that can b e placed on the stac k. ✦ Th us, stac k alw a ys lo oks lik e � � � . X X X Z 0 2. A device that holds a nonnegativ e in teger, with the op erations add 1, subtract 1, and test-if-0. � 1 coun ter = subset of CFL's, including all regular languages and some nonregular n n languages lik e f 0 1 j � 1 g . n � 2 coun ters = TM! ✦ Pro of in t w o stages: 3 coun ters sim ulate 2 stac ks, then 2 coun ters sim ulate 3 coun ters. 2 Stac ks to 3 Coun ters Supp ose a stac k has r � 1 sym b ols. Think of the stac k con ten ts as a base- r n um b er, with the sym b ols as digits 1 through r � 1. � Use one coun ter for eac h stac k, plus one \scratc h" coun ter. � Multiply and divide b y r using t w o coun ters. ✦ Subtract r from one, add 1 to the other, or vice-v ersa. � Push X = m ultiply b y r , then add digit represen ted b y X . 4
Recommend
More recommend