Information
ELSEVIER
Processing
Information Processing Letters
Letters 52 ( 1994) 229-233
Refined simulation of multihead automata H. Petersen
’
Fachbereich Informatik. Universitdt Hamburg, Vogt-KClln-Str. 30, 22527 Hamburg, Germany Communicated
Keywords: Automata
theory; Computational
by L. Boasson; received 29 March
complexity:
1994; revised 10 August
1994
Formal languages
Many algorithms in computer science can be described conveniently in terms of suitable automata. Sometimes a theoretical result in automata theory even stimulates the search for efficient implementations, the most prominent example being string-matching [ 2,4]. The investigation of multihead automata is also closely linked with the main open problems in complexity theory. For more motivation and results in this area see [3]. In this paper we will study the relationships between multihead automata with different types of storage and modes of acceptance. We improve several previously known results summarized in [ 3, Table 11. We do not introduce the forma1 definitions of the automata under consideration but refer the reader to e.g. [ 131. For alternating finite automata see also [ 31. Although this is not necessary for the one-way models we will generally assume that the input tape is bordered by special symbols (endmarkers) that will prevent the automaton from leaving the valid part of the input tape. The length of the input tape is therefore IZ+ 2 if the size of the word to be decided is n. All automata will start with their heads on the left endmarker and accept with final state. The classes of k-head automata will be denoted as fol1ows:
’ Email:
[email protected]. 0020-0190/94/$07.00 @ 1994 Elsevier Science B.V. All rights reserved SSDIOO20-0190(94)00152-9
lDFA( k): one-way deterministic finite automata 2NFA( k): two-way nondeterministic finite automata 2AFA( k): two-way alternating finite automata lDPDA( k): one-way deterministic pushdown automata lNPDA( k): one-way nondeterministic pushdown automata 2DPDA( k): two-way deterministic pushdown automata 2NPDA( k): two-way nondeterministic pushdown automata The classes of languages accepted by the respective devices will be printed in bold face. By the parameter multi we will denote the union over all numbers of heads for a specific type of automaton. We start by proving a relation between classes of finite automata: Theorem
1. Every
lDFA( k) can be simulated
by a
2AFA(2). Proof. Let lDFA( k) A be given, without loss of generality A moves exactly one of its heads in every step, and accepts with all heads scanning the right endmarker. Note that every computation consists of exactly k (n + 1) steps and the number of a step uniquely determines A’s configuration.
230
H. Peier.sen/Information Processing L.&km 52 (1994) 229-233
A 2AFA( 2) B (with heads a and b) simulates A by guessing a computation path in reverse order. Head b is used as a counter of the length of the computation and is extended within the finite control to capacity k( n + 1) (we will simply call this counter c) ; head a is used to simulate A’s heads. We introduce existential states [i, j] , where i is a state of A and j a head number 1 < j < k. Whenever B is in [i, j] with c storing m, it accepts if and only if A after m steps is in state i and has head j on the input tape cell scanned by head a. If c = 0 then B accepts if and only if i is the initial state and a scans the left endmarker. Otherwise B decrements c, existentially guesses a vector u of k input symbols scanned by A’s heads and a state i’ corresponding to a valid predecessor configuration for state i (i.e. if A is in i’ and reads u it will switch to i). If in the predecessor configuration head j is moved, B moves a left and checks that the jth symbol of u is scanned by a. Now A existentially guesses for every head j’ other than j a position stored in a consistent with the j’th symbol of u and universally verifies this head position (by going to state [i’, j’]) as well as the remaining headpositions. B simulates A by initially moving head a to the right endmarker, storing k( n + 1) in c, and universally branching to all [i, j] , where i is the final state. In order to prove that A accepts if B does we proceed by induction on the number stored in c. If c stores 0 then B verifies that the head to be checked scans the left endmarker. If c stores m > 0 then B may guess any placement of the heads enabling a step m of A taking head j to the stored position. Since these head positions are verified recursively for m - 1 they have to be correct by the induction hypothesis if B eventually accepts. Head j is updated according to the finite control of A, which shows that B checks head j correctly for step m. The converse statement, that B accepts if A accepts, is obvious. 0 Remark. This result is optimal since 2AFA(l) cides with the family of regular sets [6].
coin-
We will now recall a technique due to Monien [7] that has consequences for relationships between classes of multihead automata. Monien developed a method for simulating a time bounded random access machine by a certain type of one-head pushdown
automaton, the deterministic counter-pushdown automaton (CPDA) . The random access machine differs slightly from the usual model, e.g. [2]. It offers indirect memory access, reading of input, conditional jump, and increment, but no addition and subtraction. As an immediate consequence memory contents are bounded by the running time. The CPDA is allowed to leave its input to the right (all squares beyond the input hold blanks) and thus use its input head as a (bounded) counter. The CPDA may also be viewed as a usual 2DPDA( 1) that receives its input padded with a sufficient number of blanks. It has been shown in [9] that a CPDA with bound nk on the number of squares scanned by the input head is equivalent in accepting power to a k-head two-way pushdown automaton. The following is shown as a corollary of Theorem 4 in [7] ; a simplified presentation avoiding recursive schemes is given in [ 51: Fact 2. Every RAM which has increment as its only arithmetical operation (successor RAM) and has a time bound t(n) under the unit-cost measure can be simulated by a CPDA with a bound t(n) log’( t(n) ) on its counter (input head). Note that every algorithm running in 0( nk) on this restricted RAM can be simulated by a 2DPDA( k + 1) by the encoding described in the proof of Theorem 1 in [9] since log(n) is constructible on a pushdown automaton. Some consequences of this remarkable result have been reported before, e.g. %NPDA(k) C 2DPDA(3k + 1) in [ 10,131. Next we will give a stronger version of Theorem 6.2 in [ 31 concerning the simulation of 2AFA( k) on a successor RAM: Theorem 3. Every 2AFA( k) can be simulated unit-cost successor RAM in 0( nk) steps.
by a
Proof. We refer to the algorithm given in [ 31. It uses dynamic programming in a bottom-up approach to establish for every possible configuration acceptance or nonacceptance. This is easy for existential configurations since one accepting successor configuration suffices. For universal configurations the number of accepting successor configurations is counted and compared with the total number of such configurations.
H. Petersen/Information
Processing
Note that this number is bounded above by a constant associated with the 2AFA(k) being simulated. The data structures used in the algorithm are a configuration array holding the count and flags, and a queue for bookkeeping. It remains to be shown that this algorithm can be implemented on a machine as limited as the successor RAM. As outlined in [ 71 and presented with more details in [ 81 additional operations can be performed using a tabulation technique. We will explain this by describing how a register ri holding n > 0 will be decremented. The usual solution is to have two auxiliary registers ~1, r2, initially set to rl = 0, r2 = 1, and increment both registers simultaneously until ri = r2. Equality can be checked by using the contents of the two registers as addresses into an array of O’s which is temporarily modified. Then ri = n - 1 but we need O(n) instructions. Therefore we keep an array of flags (initially 0) indicating for which arguments the decremented value has been determined, an array of these values, and the index m of the last entry in the arrays. If a number IZhas to be decremented the corresponding flag is checked and if it is 1 then n - 1 can be retrieved in a single operation. Otherwise n is greater than m and the arrays are extended from m to n. These operations will take 0( m’) operations where m’ is the final value of m. But the successor RAM needs at least ml steps to generate m’ which shows that a RAM with a decrement operation is only faster by a constant factor. Similar observations hold for other arithmetical operations as long as they do not exceed the running time of the computation of the RAM. Above we have assumed that several arrays of registers are available whereas the basic model from [ 71 has got only one. This can be overcome by interleaving 1 arrays such that the first block of 1 registers holds the first register from each array, the second block holds the second etc. Since the RAM is too weak to even multiply by a constant, it stores 1. n instead of n. This value can immediately be used as an address. Coming back to the algorithm from [ 31 we notice that the addressing of the configuration array maintained by the algorithm cannot be done in a straightforward manner since a successor RAM cannot afford to construct an index from individual head positions in every step (recall that there is no addition). But a single transition from one head configuration to another never takes more than 0( nk) operations and by
Letters 52 (1994) 229-233
231
the tabulation method described above can be carried out by a RAM in a total of 0( nk) steps. A more direct way to see this is to precompute arrays corresponding to left and right movements of every head by cycling a counter through all head positions (represented as kdigit IZ+2-ary numbers) and keeping k other counters started withdelays 1, n+2, (n+2)2,. . ., (n+2)k-1 encoding a left movement of head 1, . . . , k. The arrays are derived from these counters in an obvious way. Cl From Theorem 3 and Fact 2 we now derive a generalization of the inclusion 2NFA(k) C_ 2DPDA(k + 1) [ IO] : Theorem 4. Every language accepted by a 2AFA( k) can be accepted by a 2DPDA( k + 1) . It is a classical result [ 21 that deterministic k-head two-way pushdown automata (2DPDA( k)) can be simulated in O(nk) steps on a unit-cost RAM. The technique of tabulation has been refined by Rytter [ 111 for automata with q one-way heads and p twoway heads yielding an 0( nJ’+‘) algorithm. Theorem 5. Every language accepted by a deterministic pushdown automaton with q one-way head and p two-way heads can be accepted by a 2DPDA( p + 2) ; i.e., any number of one-way heads can be simulated with two additional two-way heads. Proof. The general RAM simulation uses configurations of a given 2DPDA( k) consisting of state, topmost pushdown symbol, and all head positions. These configurations can be written as tuples (s,t,il,... , ik). Rytter observed that the sum of all one-way head positions provides enough information to determine the position of all one-way heads on an input, given the other components of the tuple. Therefore it is possible to compress configurations to one entry for all one-way heads. While Rytter’s simulation uses addition to compress configurations, we can avoid it by keeping the sum of all one-way head positions. Since in every step this sum changes at most by a constant amount it can certainly be maintained by the RAM. This shows that within the same order of running time Rytter’s simulation can be performed by the successor RAM. By Fact 2 the RAM can be simulated by a
232
2DPDA(p
H. Petersen/fnformation
+ 2).
ProcessingLetters 52 (1994) 229-233
0
As a special case of Theorem 5 we have: Corollary 6. Every language accepted by a lDPDA(k) can be accepted by a 2DPDA(2); i.e., every language accepted by a deterministic oneway pushdown automaton with multiple input heads can be accepted by a two head two-way pushdown automaton. By the trivial inclusions lDFA(Iz) C lDPDA(R), 2DPDA(2) C 2NPDA(2), and the result 2NPDA(R) g 2AFA(3k) proved by King in [3] we obtain several improvements on the simulations listed in [ 3, Table I] : Corollary
7. The following
inclusions hold
lDFA(R) C 2DPDA(2), lDPDA(k)
c 2NPDA(2),
lDPDA(k)
C 2AFA(6).
A further improvement is possible for lDFA(2). Every IDFA(2) can be simulated by a 2DPDA( 1) which stores a copy of the input onto the pushdown (starting from the right endmarker) and then reading symbols off the pushdown whenever the second head is moved: lDFA(2) C 2DPDA(l) C 2NPDA(l). Further we remark that by avoiding intermediate two-way pushdown automata we get lDPDA(R) C 2AFA(2), an improvement of Theorem 1. Let us briefly sketch the construction of a 2AFA(2) simulating a lDPDA( k), We introduce a new state (in addition to the ones mentioned in the proof of Theorem 1) with the intuitive meaning that in step m (stored by head c) the pushdown-height equals n (stored by head a). Then the 2AFA( 2) can determine the topmost symbol on the pushdown in the following way: It repeatedly decrements the step counter and verifies (universally) that the pushdown height is at least n (by increasing a and branching to the new state) until it reaches a step m’ where it guesses that the height is n - 1. Then it determines (recursively) the topmost symbol in step m’ as well as the symbols scanned by the heads and consequently the symbol pushed in step m’. This simulation is proved correct in the same way as Theorem 1.
As the last simulation result, we give an improved simulation of nondeterministic one-way pushdown automata: Theorem 8. Let na be an upper bound on the time required to accept context-free languages on a deterministic multitape Turing-machine. Then for every p > LYevery lNPDA( k) can be simulated by a 2DPDA ( [,Bkj ) . Proof. Sudborough has shown in [ 121 how to transform the membership problem for a lNPDA( k) into the corresponding problem for a context-free language by increasing input-lengths to O(nk). As noted in [ 121 this yields a recognition algorithm of time complexity O(nk”). The RAM in Fact 2 may of course be substituted by a deterministic multitape Turingmachine and the additional counter length log2 ( nka) is compensated by p since n(Ppa) grows faster than log2(n). 0 Finally we will point out limits of simulation techniques. The arguments based on Kolmogorov complexity employed in [ I] lead to explicit witness sets and we have the following lemma: Lemma 9. There is a language L accepted by a 2DPDA(l), but not by any lDPDA(k); i.e., 2DPDA(l) \ lDPDA(multi) # 0. Proof. Chrobak and Li [ 1] proved that for any k there is a b such that Lb = { wi #w2# ’ ’ ’ #wb$k”b# ’ ’ ’ #w2#wl 1 w E
(0, 1)‘)
is not accepted by any lNPDA(k). As witness set L take L = U,,t Lb. Then Lb can be recovered from L by intersection with the regular set ((0, 1}*#)~-‘{0,1}*$({0,
I}*++-'(0,
l}*
therefore L +! lDPDA(multi). Clearly L is accepted by a 2DPDA( 1) A. It moves to the first #, scans the input backwards as it pushes wl#, moves to the next #, pushes wz# and so on. When A encounters the $ it compares the pushdown contents with the remaining input. 0 Combining
Corollary
6 and Lemma 9 we obtain:
H. Petersen/Information
Processing
Theorem 10. The inclusions in Corollary 7 are proper. The inclusion oflDPDA(multi) in 2DPDA(2) is proper: lDPDA(multi)
c
2DPDA(2).
We summarize some known simulations in the following table; other results are found in [ 3, Table 11. An entry in column x and row y means that a k-head device y may be simulated by a device of type x with as many heads as indicated by the entry. An asterisk marks results in the present paper, otherwise references to the sources are given.
IDFA(k) 2AFA(k) lDPDA( k) INPDA( k)
2AFA( )
2DPDA( )
2NPDA( )
2* a k 2* 3k [3]
2* b k+l”
2” b
&*
k 131 2* B k
a If k= I. h If k < 2.
Acknowledgements I would like to thank M. Ladermann and B. Kirsig for fruitful discussions. I am grateful to the anonymous referee for comments which improved the presentation of the paper and for simplifying automaton A in the proof of Lemma 9.
larrers
52 (1994) 229-233
233
References M. Chrobak and M. Li, k + 1 heads are better than k for PDA, J. Compuf. System Sci. 37 (1988) 144-155. [21 S.A. Cook, Linear time simulation of deterministic two-way pushdown automata, in: Pmt. IFIP Congress on Information Processing (North-Holland, Amsterdam, 1972) 75-80. 131 K.N. King, Alternating multihead finite automata, Theoret. Cornput. Sci. 61 (1988) 149-174. [41 D. Knuth, .I. Morris and V. Pratt, Fast pattern matching in strings, SIAM .I. Compur. 6 ( 1977) 323-350. Simulating random access machines by [51 M. Ladermann, counter-pushdown automata, in preparation. 161 R.E. Ladner, R.J. Lipton and L.J. Stockmeyer, Alternating pushdown and stack automata, SIAM J. Cornput. 13 ( 1984) 135-155. of time-bounded computations 171 B. Monien, Characterizations by limited primitive recursion, in: Proc. 2nd ICALP, Lecture Notes in Computer Science 14 (Springer, Berlin, 1974) 280-293. von Automatenmodellen 181 B. Monien, Komplexitatsklassen und beschrankte Rekursion, Bericht Nr. 8, Fachbereich Informatik, Universitlt Hamburg ( 1974), in German. methods and their application [91 B. Monien, Transformational to complexity problems, Acfa Inform. 6 (1976) 95-108; Corrigendum, Acra Inform. 8 ( 1977) 383-384. I101 B. Monien and 1.H. Sudborough, The interface between language theory and complexity theory, in: R.V. Book, ed., Formal Language Theory, Perspectives and Open Problems (Academic Press, New York, 1980) 287-323. [Ill W. Rytter, An effective simulation of deterministic pushdown automata with many two-way and one-way heads, I$brm. Process. Left. 12 ( 1981) 234-236. Some remarks on multihead automata, 1121 I.H. Sudborough, RAIRO 11 (1977) 181-195. I131 K. Wagner and G. Wechsung, Computarional Complexity (Reidel, Dordrecht, 1986). Ill