Two-Way Automata Making Choices Only at the Endmarkers
Abstract. The question of the state-size cost for simulation of two-way nondeterministic automata (2nfas) by two-way deterministic automata (2dfas) was raised in 1978 and, despite many attempts, it is still open. Subsequently, the problem was attacked by restricting the power of 2dfas (e.g., using a restricted input head movement) to the degree for which it was already possible to derive some exponential gaps between the weaker model and the standard 2nfas. Here we use an opposite approach, increasing the power of 2dfas to the degree for which it is still possible to obtain a subexponential conversion from the stronger model to the standard 2dfas. In particular, it turns out that subexponential conversion is possible for two-way automata that make nondeterministic choices only when the input head scans one of the input tape endmarkers. However, there is no restriction on the input head movement. This implies that an exponential gap between 2nfas and 2dfas can be obtained only for unrestricted 2nfas using capabilities beyond the proposed new model.
As an additional bonus, conversion into a machine for the complement of the original language is polynomial in this model. The same holds for making such machines self-verifying, halting, or unambiguous. Finally, any superpolynomial lower bound for the simulation of such machines by standard 2dfas would imply . In the same way, the alternating version of these machines is related to , the classical computational complexity problems.
Keywords: two-way automata, descriptional complexity, regular languages
1 . Introduction
The cost, in terms of states, of the simulation of two-way nondeterministic automata (2nfas, for short) by two-way deterministic automata (2dfas) is one of the most important and challenging open problems in automata theory and, in general, in theoretical computer science. This problem was proposed in 1978 by Sakoda and Sipser [SS78], who conjectured that the cost is exponential. However, in spite of all effort, exponential gaps were proved only between 2nfas and some restricted weaker versions of 2dfas.
In 1980, Sipser proved that if the resulting machine is required to be sweeping (deterministic and reversing the direction of its input head only at the endmarkers, two special symbols used to mark the left and right ends of the input), the simulation of a 2nfa is indeed exponential [Sip80]. However, Berman and Micali [Ber80, Mic81] proved independently that this does not solve the general problem: in fact the simulation of unrestricted 2dfas by sweeping 2dfas also requires an exponential number of states. The Sipser’s result was generalized by Hromkovič and Schnitger [HS03], who considered oblivious machines (following the same trajectory of input head movements along all inputs of equal length) and, recently, by Kapoutsis [Kap11b], considering 2dfas with the number of input head reversals that is sublinear in the length of the input. However, even the last condition gives a machine provably less succinct than unrestricted 2dfas, and hence the general problem remains open.
Starting from 2003 with a paper by Geffert et al. [GMP03], a different kind of restriction has been investigated: the subclass or regular languages using a single-letter input alphabet. Even under this restriction, the problem of Sakoda and Sipser looks difficult, since it is connected with , an open question in complexity theory. ( and denote the respective classes of languages accepted in deterministic and nondeterministic logarithmic space.) First, in [GMP03], a new normal form was obtained for unary automata, in which all nondeterministic choices and input head reversals take place only at the endmarkers. Moreover, the state-size cost of the conversion into this normal form is only linear. This normal form is a starting point for several other properties of unary 2nfas. First, in the same paper, each -state unary 2nfa is simulated by an equivalent 2dfa with states, which gives a subexponential but still superpolynomial upper bound. It is not known whether this simulation is tight. However, a positive answer would imply the separation between the classes and . In fact, under assumption that , each unary 2nfa with states can be simulated by a 2dfa with a number of states polynomial in [GP11]. After a minor modification (without assuming ), this gives that each unary 2nfa can be made unambiguous, keeping the number of the states polynomial. (For further connections between two-way automata and logarithmic space, we address the reader to [BL77, Kap11a].)
Along these lines of investigation, in [GMP07], the problem of the complementation for unary 2nfas has been considered, by proving that each -state 2nfa accepting a unary language can be replaced by a 2nfa with states accepting the complement of . The proof combines the above normal form for unary 2nfas with inductive counting arguments.
Kapoutsis [Kap06] considered the complementation in the case general input alphabets, but restricting the input head reversals. He showed that the complementation of sweeping 2nfas (with the input head reversals only at the endmarkers) requires exponentially many states, thus emphasizing a relevant difference with the unary case.
In this paper, we use a different approach. Instead of restricting the power of 2dfas to the degree for which it is already possible to derive an exponential gap between the weaker model and the standard 2nfas, we increase the power of 2dfas, towards 2nfas, to the degree for which it is still possible to obtain a subexponential conversion from the stronger model to the standard 2dfas. Such new stronger model then clearly shows that, in order to prove an exponential gap between 2nfas and 2dfas, one must use capabilities not allowed in the proposed new model. More precisely, in our new model, we neither restrict the cardinality of input alphabets, nor put any constraint on the head movement, i.e., head reversals can take place at any input position. On the other hand, we permit nondeterministic choices only when the input head is scanning one of the endmarkers. We shall call such machine a two-way outer-nondeterministic finite automaton (2onfa).
It turns out that this machine has its natural counterpart also in the case of two-way alternating finite automata (2afas), which is a two-way outer-alternating finite automaton (2oafa), making universal and existential choices only at the endmarkers. (For recent results on 2afas, see [Kap09, Gef11].)
We show that several results obtained for unary 2nfas can be extended to 2onfas, and some of them even to the alternating version, 2oafas, with any input alphabet. In particular, we prove the following:
Each -state 2onfa can be simulated by a halting two-way self-verifying automaton (2svfa) [DHRS97] with many states. This fact has two important implications:
The complementation of 2onfas can be done by using a polynomial number of states. Note the contrast with the above mentioned case of sweeping 2nfas studied in [Kap06].
Each 2onfa can be simulated by a halting 2onfa using a polynomial number of states.
Each -state 2onfa can be simulated by a 2dfa with states.
If , then each -state 2onfa can be simulated by a 2dfa with a number of states polynomial in . Hence, a superpolynomial lower bound for the simulation of 2onfas by 2dfas would imply . (Unlike in [BL77], there are no restrictions on the length of potential witness inputs.)
Each -state 2onfa can be simulated by an unambiguous 2onfa with a polynomial number of states.
If , then each -state 2oafa can be simulated by a 2dfa with a number of states polynomial in , with the same consequences as presented for . ( denotes, as usual, the class of languages recognizable by deterministic Turing machines in polynomial time.)
Similarly, if , we get the corresponding polynomial conversion from 2oafas to 2nfas.
These results are obtained by generalizing the constructions given in [GMP03, GMP07, GP11] for the unary case. However, here we do not have a normal form for simplifying the automata, by restricting input head reversals to the endmarkers. Our generalization rely on a different tool, presented in the first part of the paper. Basically, we extend some techniques developed originally for deterministic devices [Sip80h, GMP07] to machines with nondeterminism at the endmarkers. This permits us to check the existence of certain computation paths, including infinite loops, by the use of a linear number of states.
The paper is organized as follows. In Section 2 we recall basic definitions and preliminary results required later. In Section 3, after introducing 2onfas, we develop a fundamental tool that will be used several times, namely, a deterministic procedure that allows us to check the existence of computation paths between two given states in the given 2onfa, starting and ending at the left endmarker and do not visiting the endmarkers in the meantime. This procedure is also useful to make all computations halting. The next sections are devoted to our main results. In Section 4, we present the polynomial simulation of 2onfas by 2svfas and its consequences. In Section 5, we show the subexponential simulation of 2onfas by 2dfas. Then, in Section 6, under the assumption , such simulation is with a polynomial number of states. Furthermore, we show how to simulate a 2onfa by an unambiguous 2nfa using a polynomial number of states. Finally, in Section 7, we present the corresponding results for the alternating case. Some concluding remarks are briefly discussed in Section 8.
2 . Preliminaries
Let us start by briefly recalling some basic definitions from automata theory. For a detailed exposition, we refer the reader to [HU79]. Given a set , denotes its cardinality and the family of all its subsets.
A two-way nondeterministic finite automaton (2nfa, for short) is defined as a quintuple , in which is a finite set of states, is a finite input alphabet, is a transition function, where are two special symbols, called the left and the right endmarkers, respectively, is an initial state, and is a set of final states. The input is stored onto the input tape surrounded by the two endmarkers, the left endmarker being at the position zero. In one move, reads an input symbol, changes its state, and moves the input head one position forward, backward, or keeps it stationary depending on whether returns , , or , respectively. The machine accepts the input, if there exists a computation path from the initial state with the head on the left endmarker to some final state . The language accepted by , denoted by , consists of all input strings that are accepted. is said to be halting if each computation ends in a finite number of steps.
Observing that if an accepting computation visits the same endmarker two times in the same state then there exists a shorter accepting computation on same input, we immediately get the following lemma, which will be used in the proofs of some of our results:
If a 2nfa with states accepts an input , then it also accept with a computation that visits the left (right) endmarker at most times.
Throughout the paper, given a 2nfa , we will call computation segment (or just segment) from to on , each computation path on an input that starts at the left endmarker in the state , ends at the left endmarker in the state and never visits the same endmarker in the meantime.
A sequence of segments from a state to a state on input is a sequence of segments such that there are states , with , , and the th segment is from to , .
A 2nfa is said to be deterministic (2dfa), whenever , for any and , is called unambiguous (2ufa), if there exists at most one accepting computation path for each input. A two-way self-verifying automaton (2svfa) is a 2nfa which, besides the set of accepting states , is equipped also with a disjoint set of rejecting states . For each input there exists one computation path halting in a state , and no path may halt in a state . Conversely, for there exists one computation path halting in a state , and no path may halt in a state . Note that some computation paths of a 2svfa may end with a “don’t-know” answer, by ending in one state not belonging to , or entering into an infinite loop.
An automaton working over a single letter alphabet is called unary.
We assume that the reader is familiar with the standard Turing machine model and the basic facts from space complexity theory. For more details, see e.g. [HU79, Sze94]. Our Turing machine (both deterministic and nondeterministic) is equipped with a finite state control, a two-way read-only input tape, and a separate semi-infinite two-way read-write worktape, initially empty. Such machine is -space bounded, if no computation uses more than worktape cells, for each input of length .
The class of languages accepted in space by deterministic Turing machines is denoted by , while the corresponding classes for nondeterministic machines by .
3 . Outer-nondeterministic automata and the subroutine Reach
In this section we introduce the computational model investigated in the paper, and we develop some preliminary results concerning it. First, we provide a simplification of the model with respect to the definition. After that, we will present the main result of this section. We will show how to detect the existence of computational segments in our devices. This result will be a fundamental tool, used in the proof of all the other results presented in the paper.
A two-way outer-nondeterministic finite automaton (2onfa, for short) is a 2nfa that can take nondeterministic decisions only when the input head is scanning one of the two endmarkers, i.e., for each , , . Actually, with a linear increasing in the number of the states, we can further restrict the use of the nondeterminism to the left endmarker only. We can also obtain some other restrictions, which will be useful to simplify our proofs:
For any -state 2onfa there exists an equivalent 2onfa with no more than states that satisfies the following properties:
nondeterministic choices are taken only when the input head is scanning the left endmarker,
there is a unique accepting state and this state is also halting,
is reachable only at the left endmarker by stationary moves,
stationary moves can occur only at the left endmarker to enter the state .
Proof: If then accept the empty language and it can be replaced by the trivial automaton with two states and , and without any transition. So, from now on let us suppose .
First, we can make each final state also halting, by making the transition function undefined from final states. Furthermore, each stationary move leading to a final state can be replaced by a transition to the same final state that moves the head either to the left or to the right. Now, by inspecting the transition function, for each and , we compute the set of pairs such that in the state scanning an input square containing the symbol , after a possible sequence of stationary moves, will finally reach the state moving the head in the direction . Stationary moves from the state with input are replaced by all possible transitions described by those pairs . Notice that if is an ordinary input symbol, i.e., , then we can have at most one such a pair. Hence, after this transformation, nondeterministic choices remain confined at the endmarkers and the resulting automaton does not perform any stationary move.
Now, from the automaton so modified, we build an automatom making nondeterministic choices only on the left endmarker. Normally, makes the same moves as . However, when the head reaches the right endmarker in a state , traverses the input from right to left, using a copy of , to reach the left endmarker. At this position, the automaton simulates a transition from at the right endmarker, i.e., it chooses a state such that and, using a copy of , it traverses the input from left to right until to reach the right endmarker. Here, moves its head one position to the left entering the original state . From this configuration resumes the simulations of the ordinary moves of .
Finally, to accept in on the left endmarker, we make two further small changes. First, when enters a state , it starts to move its head to the left using the state , until to reach the left endmarker. At that position, from , finally enters without moving the input head. Furthermore, when , scanning the left endmarker, should move in a state , for some , then it enters directly without moving the input head. This second change permit us to save the states , for .
It can be easily seen that the resulting automaton is equivalent to the given 2onfa and satisfies the properties listed in the statement of the lemma. The set of states consists of copies of the set plus the state . However, for each final state of , the copy is useless. Hence, the total number of states of does not exceed .
The remaining part of this section is devoted to develop a tool which will be fundamental in the proof of our results. Given a 2onfa with states, we show the existence of a subroutine Reach that receives as parameters two states of and decides whether or not has a computation segment from to on an input string . We will show that this subroutine can be implemented using a deterministic finite state control with states whose input is stored on a two-way tape.
At a first glance, we could try to compute by initializing the automaton in the state with the input head at the left endmarker and by stopping its computation as soon as the input head, in one of the following steps, reaches again the left endmarker, then testing whether or not the state so reached is . However, this approach presents two problems: first of all, the original automaton could enter into a infinite loop, never coming back to the left endmarker; second, the first move from the state on the left endmarker can be nondeterministic.
In order to solve the first problem, we adapt the construction given in [GMP07] to transform each -state 2dfa into an equivalent halting -state 2dfa, which, it turns, was a refinement of the construction obtained by Sipser [Sip80h] to make space bounded Turing machines halting. We give a brief outline. For each , a deterministic machine accepts if and only if there is a “backward” path, following the history of the computation in reverse, from the unique accepting configuration to the unique initial configuration . In our setting, a “configuration” is a pair , where is a state and is an input head position.
Consider the graph whose nodes represent configurations and edges computation steps. If the machine under consideration is deterministic, the component of the graph containing the accepting configuration is a tree rooted at this configuration, with backward paths branching to all possible predecessors of . In addition, if the accepting configuration is also halting, no backward path starting from can cycle (hence, it is of finite length). Thus, the equivalent halting machine can perform a depth-first search of this tree in order to detect whether the initial configuration belongs to the predecessors of . If this is the case, then the simulator accepts. On the other hand, if all the tree is examined without reaching , this means that there are no paths from to and so is not in the language. Hence, the simulator rejects.
We adapt such a procedure by choosing and , where and are the two parameters. Furthermore, since we are interested to detect the existence of just one segment from to , we do not consider the transitions on the left endmarker from states different than . However, the remaining transition, i.e., that from configuration , can be nondeterministic. Thus, we need further modifications. Suppose . Hence, there is a segment from to if and only if there is a path from to , for some , visiting the left endmarker only in . Hence, the backward search can be done starting from , without considering all the transitions of the original automaton from the left endmarker, stopping and accepting when one of the ’s is reached, or rejecting when all the tree has been visited without reaching any of the ’s.
To do that, our procedure needs to detect when the head position of the original 2onfa is scanning the first “real” input symbol, i.e., that immediately to the right of the left endmarker, in cell number . This can be done as follows. We say that a left predecessor for the configuration is a configuration , with the input head scanning a symbol , such that . Hence, in the construction of the backward path from to , the configuration can be reached only as a left predecessor of some , . By a closer look to the simulation in [GMP07], we can observe that all the left precedessors of a configuration are examined in a copy of the state , with the input head one position to the left of the actual position of the original machine, i.e., in position . Hence, when the simulating machine reaches one of the states , with the input head scanning the left endmarker at the same time, it can stop the computation and accept. There are only two points which depend on the states : the choice of the initial state, i.e., of the configuration , and the detection of configurations of , when the head of is scanning the left endmarker.
This construction can be implemented by a deterministic finite state control with states (not counting the space needed to store the parameters , which will be used in a “read-only” way). More details are presented in Appendix A. Hence, with this strategy we obtain the following result which will be a fundamental tool in the next sections:
For each 2onfa with states (in the form of Lemma 3.1), it is possible to construct a deterministic finite state control with states that given an input string stored on a two-way tape and two states of decides whether or not the automaton has a computation segment from to on .
4 . Simulation by halting self-verifying automata
In this section we prove that for each -state 2onfa accepting a language there exists an equivalent halting 2svfa using a polynomial number of states and making nondeterministic choices only when the input head is scanning the left endmarker. As a consequence, we can derive halting 2onfas with polynomial many states that accept and the complement of .
Even in this case, our starting point is a proof given in [GMP07] for the unary case, which was based on the well known technique of the inductive counting. However, there are deep differences. In particular, the proof in [GMP07] uses a normal form for unary 2nfas in which a computation is a sequence of deterministic traversals of the input from one endmarker to the opposite one. In this normal form there are no parts of computations starting and ending at the same endmarker without visiting the other one in the meantime (these parts are usually called U-turns). Furthermore, the only possible infinite loops involve the endmarkers and can be easily avoided using Lemma 2.1. The simulation inductively counts, for increasing values of , how many states are reachable from the initial state in traversals of the input and, as a side effect of this counting procedure, also lists these states. In this way, after a certain number of traversals, all the states which are reachable at the endmarkers have been listed and, hence, it is possible to decide whether or not the input was accepted by the original machine.
In the case we are considering, we do not have such a kind of normal form. Hence, a computation can present traversals of the input from one endmarker to the opposite one as well as -turns. Furthermore, a computation can reject by entering into a infinite loop: in this case infinite loops which never visits the endmarkers are also possible. To overcome the first problem, instead of traversals, our inductive counting procedure considers computation segments: for increasing values of , it counts how many states are reachable from the initial state in a computation consisting of segments, i.e., visiting the left endmarker times, and, at the same time, the procedure lists these states. Since, as stated in Lemma 2.1, each accepted input has an accepting computation which visits the left endmarker at most times, it is enough to consider computations consisting of at most segments. This avoid infinite loops involving the endmarkers. We will discuss later on how to deal with the remaining infinite loops, namely those that do not involve endmarkers.
In some steps, the simulation we present can reach the “don’t-know” state . We always assume that this state is halting: hence, when it is reached, even in the code of the subroutines, the entire simulation will be aborted.
To simulate single computation segments, we will make use of the subroutine Reach, discussed in Section 3. Furthermore we use another subroutine tReach which with parameters and verifies the existence of sequence of segments from the initial state to on the input under consideration. In negative case, tReach aborts the simulation in the state , otherwise the subroutine returns to the main simulation in a different state. (As we will see, this subroutine is nondeterministic. It can also halt in the state , due to a wrong sequence of nondeterministic guesses. However, if there exists a sequence of segments from to , the subroutine has at least one computation ending in a state other than .)
The algorithm proceeds by counting, for , the number of states reachable by at the left endmarker by all computation paths starting from the initial configuration and consisting of exactly segments (loop from line 1). During this process, the algorithm also generates all states reachable at the left endmarker, and hence it can correctly decide whether to accept or reject the given input.
At the beginning of the -th iteration of this loop (line 1), a variable contains the number of states reachable at the left endmarker by all computation paths with exactly segments. (In line 1, we prepare for , the only state reachable by segments being the initial state .) In line 1, we save the “old” value of in the variable , and clear for counting the number of states reachable upon completing one more segment, i.e., with exactly segments.
The value of is computed in the loop from line 1: for each state , we test whether or not it is reachable by a path with exactly segments. If it is, we increment the value of .
To decide whether can be reached by exactly segments, we generate all states that are reachable at the left endmarker by all computation paths of exactly segments and we verify if can be reached by any of these states by a single segment. This part is realized by the innermost loop (from line 1)
The loop generates in a nondeterministic way all the sequences of states. To avoid to consider a same set of states twice, or to consider sequences containing repeated states, the sequences that do not respect a preliminary fixed order on are discarded, aborting the computation in (line 1). As a side effect of the call (line 1), among the remaining sequences the procedure filters the only one consisting of the states reachable in exactly segments, discarding the remaining. In fact, if the subroutine does not find a sequence of segments from to , then it aborts the computation in . (Further details about this subroutine, which is also nondeterministic, are given below.) Hence, the only computation which “survive” is the one generating, according to the fixed order, all states reachable in exactly segments. For each among these states, the algorithm tests whether the state under examination is reachable from in one step (call on line 1; for implementation reasons, the first parameter in the call is which was initialized in line 1 with the value of ). If also the result of this test is positive, then the variable is incremented. At this point we can abort the innermost loop (line 1) and continue with the next iteration, if any, of the loop from line 1, to state the reachability in segments of another state. Furthermore, if during this process we discover that the final state is reachable at the left endmarker, we stop the computation and accept by halting in the state .
On the other hand, if the iteration of the outermost loop has been completed for each , never reaching at the left endmarker, then the input is not accepted by the original automaton. (Otherwise, the search would have stopped already, in line 1.) Therefore, in line 1, we stop in the rejecting state .
It is not hard to see that: (i) if the input is accepted by , at least one computation path halts in the state , and no path halts in , (ii) if the input is rejected, at least one path halts in , and no path halts in . (iii) Due to wrong sequences of nondeterministic guesses, some computation paths halt in , but no path can get into an infinite loop.
Finally, we briefly discuss a possible implementation of the subroutine tReach (for further details see Appendix B). Firstly, we can modify the backward seach described in Section 3, to obtain subroutine that given as parameter a state outputs a nondeterministically chosen state such that has a computation segment from to on the given input . This subroutine, called nReach, can also end in the state , aborting the entire computation, if it is not able to find such a state . This can be done using states, besides . The implementation of consists of a loop of iterations. In each one of them, nReach is called on the parameter , assigning to it the result. Hence, at the end, if contains the initial state then the search was successful and tReach returns the control to the caller, implicitly giving a positive answer, otherwise it aborts the entire computation in . Instead of this approch, we could use, as in [GMP07, subroutine ], a direct nondeterministic simulation of , in order to generate all the states reachable in exactly segments. This will also produce a correct inductive counting procedure. However, due to the fact that can enter some infinite loop that does not visit the endmarkers, the resulting procedure could also enter some loop. Our implementation produces an halting automata, obtaining, as shown below, the same upper bound for the number of the states, as the implementation in [GMP07] for the unary case.
The number of possible values of each one of the variables is bounded by . The subroutine tReach uses one counter bounded by and states to run nReach, besides the “global” variable , hence states. The implementation of Reach uses states, however, it can recycle part of the space used by tReach. Hence, all the simulation can be carried out using states.
Finally, we also observe that in the main algorithm and in the subroutines all the nondeterministic choices can be taken when the input head is scanning the left endmarker.
By summarizing, we have proved the following:
Each -state 2onfa can be simulated by an equivalent halting -state 2svfa making nondeterministic choices only when the input head is scanning the left endmarker.
For each -state 2onfa there exist an equivalent halting 2onfa with states and a 2onfa with states accepting the complement of the language accepted by .
5 . Subexponential deterministic simulation
In this section, we prove that each 2onfa with states can be simulated by an equivalent 2dfa with states, i.e., with a subexpontential, but still superpolynomial, number of states. In the authors’ knowledge this is the first case of a model using nondeterminism and an unrestricted alphabet, having a subexponential simulation by 2dfas.
This result generalizes a result proved for the unary case in [GMP03]. Actually, even the proof is very similar: the new “ingredient” in our version is the subroutine Reach presented in Section 3. So we give a very short presentation, addressing the reader to [GMP03] for further details.
Let be a 2onfa with states in the form of Lemma 3.1. The 2dfa simulating implements a recursive function, called Reachable, based on the well known divide-and-conquere technique.
The function receives three parameters: two states and and an integer , and returns a boolean. On these parameters, returns true if and only if on the input under consideration the automaton has a sequence of at most segments from the state to the state . Hence, according to Lemma 2.1, to decide whether or not is accepted by , we call . The pseudocode of the function is given below. We point out that is the base of the recursion, , we have to verify the existence of a sequence of at most segment from to . A sequence with segments is possible if and only if . The existence of a sequence of just one segment can be verified using the subroutine Reach.
We can prove the following:
Each -state 2onfa can be simulated by an equivalent 2dfa with states.
Proof: The implementation of Reachable and its complexity analysis are very close to those given in [GMP03] for the unary case. We just outline a rough estimation of the state upper bound.
First, we suppose that the given 2onfa is in the form given in Lemma 3.1. The implementation of the function Reachable can be done using a constant height stack, as in [GMP03], with the following differences:
the height of the stack is (instead of ),
the subroutine Reach uses state (the corresponding subroutine in [GMP03] was implemented with states).
This leads to an upper limit for the number of different stack configurations (for the sake of simplicity, we deleted some negative terms, so it could be possible to give a slightly more accurate upper bound), which is bounded by . If the automaton is not in form of Lemma 3.1, we need to convert it using states. Hence, by replacing by in the above upper bound, we obtain the following rough upper estimation:
We can observe that .
It is natural to wonder if the upper bound stated in Theorem 5.1 is optimal. We remind the reader that the best known lower bound for the number of the states of 2dfas simulating -state 2nfas is [Chr86]. In the next section we will show that the optimality of the upper bound in Theorem 5.1 or any other superpolynomial state lower bound for the simulation of 2onfas by 2dfas would imply the separation between deterministic and nondeterministic logarithmic space, hence solving a longstanding open problem in structural complexity.
6 . Conditional and unambiguous simulations
In this section we discuss how to reduce the language accepted by a given 2onfa to the graph accessibility problem (), i.e., the problem of deciding whether a directed graph contains a path connecting two designated vertices. This problem is well known to be complete for , the class of languages accepted by space bounded machines. As a consequence of this reduction we will prove that the equality between the classes and would imply a polynomial simulation of 2onfas by 2dfas. Furthermore, we also prove that each 2onfa can be made unambiguous with a polynomial increasing in the number of the states. An extension of this reduction to the alternating case will be discussed in Section 7.
Let us start to present our reduction. As for the results in Sections 4 and 5, it is obtained by combining a technique developed for the unary case [GP11], with the use of the subroutine Reach presented in Section 3.
From now on, we consider an -state 2onfa in the form of Lemma 3.1. With each input string we associate the directed graph , where is the set of states of and
i.e., it is the set of pairs of states such that on input has a segment from to .
It should be clear that is accepted by if and only if the graph contains a path from vertex , the initial state, to vertex , the accepting state. Hence, this defines a reduction from the language accepted by to .
As mentioned before, is complete for under logarithmic space reductions [Sav70]. Hence, if and only if . This permit us to prove the following:111The result in Theorem 6.1 is presented, in a different context, also in [KP1X].
If then each -state 2onfa can be simulated by a 2dfa with a number of states polynomial in .
Proof: Let us denote by be the language accepted by the given -state 2onfa and by a deterministic machine which solves in logarithmic space. Such a machine exists, under the hypothesis .
We can build a machine deciding whether or not a string belongs to by composing the reduction above described with the machine (see Figure 1).
The input of is the graph , more precisely its adjacency matrix, which can be encoded with bits. Hence, uses space on its worktape. This space can be represented in a finite state control with a number of states polynomial in . (Notice that since the automaton is fixed, does not depend on the length of the input .)
On the other hand, the adjacency matrix of cannot be stored in the finite control of , because it would require a number of states exponential in . Hence, each time needs to access one symbol from its input, such a bit is computed “on the fly”. The bit represents a position in the adjacency matrix, corresponding to a pair of states of . Its value is if and only if the automaton has a segment from to on input . Hence, it can be computed by calling , the subroutine presented in Section 3, which uses states. The proof can completed as in [GP11, Lemma 4.1], where a similar result has been proved for the unary case.
While the deterministic simulation in Theorem 6.1 is under the condition , the next simulation by unambiguous machines does not require any extra condition:
Each -state 2onfa can be simulated by an unambiguous 2onfa with a number of states polynomial in .
Proof: In [RA00] it was proved for each nondeterministic machine working in logarithmic space there exists an equivalent unambiguous machine still working in logarithmic space, which uses of a polynomial advice [KL82], i.e., of a family of strings of polynomial length. The machine receives, besides an input string , the advice string corresponding to the length of , i.e., the string . Hence, there exists an unambiguous machine of this kind that, with an appropriate advice, solves .
Given a 2onfa with states, by applying a construction similar to that in the proof of Theorem 6.1, we can obtain an unambiguous two-way automaton with a number of states polynomial in that recognize the same language as . Essentially, in the construction we have to replace the machine by the machine with the appropriate advice (see Figure 1). However, the advice depends only on the size of the input of , namely on the size of the graph , which, in turns, depends only on the number of states of , not on the input string . So, given the 2onfa , the advice is fixed, hence it can be encoded in the “hardware” of .
Finally, we observe that accesses its input tape only to compute the bits of the adjacency matrix of , i.e., when the subroutine Reach is running. This subroutine is deterministic. It starts and ends its computation with the head at left endmarker. Hence, when the machine takes nondeterministic decisions the head is scanning the left endmarker. This permit us to conclude that the unambiguous machine is a 2onfa.
7 . The alternating case
In this section we briefly discuss an extension of the technique used in Section 6, to the case of automata with alternations [CKS81], recently considered in [Kap09, Gef11].
A two-way alternating automaton (2afa, for short) is defined as a quintuple , exactly as a 2nfa. However, the set is partitioned in two sets and , the sets of existential and universal states, respectively. The acceptance of an input string is witnessed by an accepting computation tree . The nodes of are labeled by configurations, the root is labeled by the initial configuration, the leaves are labeled by accepting configurations (we can assume that accepting configurations are also halting). Each node of labeled by a configuration whose state is existential has exactly one son. The label of this son is one of the possible successors of . Each node of labeled by a configuration whose state is universal has one son for each possible successor of . Notice that nondeterministic automata are just alternating automata without universal states.
Even for 2afas, we can restrict the use of the nondeterminism as we did for 2nfas, considering outer-alternating finite automata (2oafas). In these models, each configuration scanning an ordinary input symbol can have at most one successor, namely (existential or universal) nondeterministic choices can be taken only when the head is scanning one of the endmarkers. Actually, we can further restrict the use of the nondeterminism only at the left endmarker. In particular, using arguments similar to those of Lemma 3.1, we can prove the following result:222Notice a small difference with respect to Lemma 3.1. Stationary moves are possible only at the left endmarker. However, here they can be used also to reach states different than . Due to the presence of both universal and existential states, the removal of these moves would require an argument more complicated than the simple one used to prove Lemma 3.1. However, for our purposes, we do not need to remove them.
For any -state 2oafa there exists an equivalent 2oafa with no more than states that satisfies the following properties:
nondeterministic choices are taken only when the input head is scanning the left endmarker,
there is a unique accepting state and this state is also halting,
is reachable only at the left endmarker by stationary moves,
stationary moves can occur only at the left endmarker.
Now, we consider the alternating graph accessibility problem (, for short), an alternating version of . The instance of the problem is an alternating direct graph, i.e., a graph with a partition of in two sets and , and two designated vertices and . The question is if the predicate is true, where, for , holds true if and only if:
and exists with such that is true, or
and for all , implies that is true.
This problem is known to be complete for the class , with respect to logarithmic space reductions [Imm81].
As is Section 6, we can reduce the language accepted by a given 2oafa to , by associating with each input string the graph , where if and only if has a computation segment from to on input . (The extension of the notion of computation segment to 2afa is obvious.) Since the subroutine Reach presented in Section 3 depends only on the transition function of the given automaton and not on the acceptance condition, we can use it to detect segments even in the case of outer 2afas.333Due to the possibility of stationary moves on the left endmarker, the subroutine Reach needs just one small change (line 7 in the implementation presented in Appendix A). Given the two parameters and , it preliminary checks if or if is reachable from by a stationary move on the left endmarker. If the answer is positive, it immediately accepts, otherwise, it works as we described.
These permit us to prove the following result:
If then each 2oafa can be simulated by a 2dfa with a polynomial number of states.
Proof: Since is complete for , if then there exists a deterministic machine that in logarithmic space solves . Applying the same construction of Theorem 6.1, just replacing the machine by the machine , given an -state 2oafa , we can define an equivalent 2dfa with a number of states polynomial in .
In a similar way, we are able to prove the following:
If then each 2oafa can be simulated by a 2nfa with a polynomial number of states.
Proof: Under the hyphothesis , there exists a nondeterministic machine that in logarithmic space solves . By replacing in the previous proof the machine by the machine we obtain a 2nfa with a number of states polynomial in equivalent to the given 2oafa.
8 . Concluding remarks
In this paper we generalized, in a unified framework, some results previously obtained for unary 2nfas to machines with arbitrary input alphabets, but making nondeterministic choices only at the input tape endmarkers. Among others, we have shown that any superpolynomial lower bound for the simulation of such machines by standard 2dfas would imply . (Unlike in [BL77], there are no restrictions on the length of potential witness inputs.) In Section 7, we also related the alternating version of such machines to , the classical computational complexity open problems.
Comparing our results with those obtained for other restricted models of two-way automata we observe that:
Actually, unary 2nfas can use only a restricted form of nondeterminism. In fact, we can restrict their nondeterminism to the endmarkers without increasing significantly their size [GMP03]. (A similar phenomenon has been observed by Chrobak in the case of unary one-way automata [Chr86].)
In the general case, the possibility of reversing the input head movement at any input position does not seem so powerful as the possibility of making nondeterministic decisions at any input position. (Compare our polynomial upper bound for the complementation of 2onfas with the exponential lower bound for the complementation of sweeping 2nfas in [Kap06].)
However, in the deterministic case, the possibility of reversing the input head at any input position can make automata exponentially smaller than machines reversing the input head only at the endmarkers [Ber80, Mic81].
It would be interesting to see if the results proved in this paper could not be extended to a model using the nondeterminism in a less restricted way than the one considered here.
Appendix A . The subroutine Reach
Let be a 2onfa in the form of Lemma 3.1. Fixed , we first describe a 2dfa which halts on every input and accept a word if and only if on input has a computation segment from to . Subsequently, we will discuss how to modify the construction to use and as parameters.
First, we examine some trivial cases:
If then can immediately accept.
If and then can immediately reject.
If and then if then immediately accepts, otherwise it immediately rejects.
Now, we consider the remaining cases. Since the construction we present is obtained by modifying that given in [GMP07] for making 2dfas halting, the presentation will be given along the same lines and by keeping, as much as possible, the same notations.
First, let us fix a linear order on the state set of the original automaton. As usual, the symbols “” and “” denote the ordering relation. We do not need to further consider the final state and stationary moves. In fact, the only possible stationary moves are those reaching on the left endmarker, cannot be reached in any other input position and it is halting (see Lemma 3.1). All these possibilities have been already considered in the case of segments ending in .
Our implementation of the depth-first search examines each configuration in two modes:
Mode 1: Examination of the “left” predecessors of , namely configurations such that ,
Mode 2: Examination of the “right” predecessors, namely configurations such that .
For each and both modes, we introduce a starting and a finishing state. So our machine will use the following set of states:
These states are interpreted as follows:
Starting state for the Mode 1: examination of left predecessors for the configuration . Left predecessors will be examined one after another, according to the linear order induced by the relation “”. To inspect the content of the input square , the simulator (if it is in the state ) has its input head one position to the left of the actual position of the original machine in configuration .
Finishing state for the Mode 1. All the left predecessors of have been examined, but we still have to examine the right predecessors of . In the state , the input head of the simulator is in the actual position, i.e., the position .
Starting state for the Mode 2, examination of right predecessors for , when the left predecessors have been finished. The right predecessors will also be examined in the linear order induced by “”. In the state , the simulator has its input head one position to the right of the actual position of the configuration , to inspect the symbol in the input square .
Finishing state for the Mode 2. Both the left and the right predecessors of have been examined. In the state , the input head of the simulator is in the actual position, i.e., the position .
Halting accepting state.
Let us now describe the transition function of implementing this strategy. For each (type of) state and each symbol , we first display a procedure that assigns a value of to the transition table and, after that, we present an explanation for this procedure. Note that the simulator will use stationary moves. The reader should also keep in mind that the procedures displayed below are not executed by the machine but, rather, they are used to fill in the entries in the transition table for . In the description, we will suppose that the input string is , with , for .
This part presents several differences with the corresponding one in [GMP07]. Recall that gets to the state when, for some , it starts the examination of the left predecessors of the configuration , that is, of configurations such that . By definition of , has its input head already at the position . The procedure considers four cases:
(line 3): actually this case is unreachabale, it is given just for completeness, to fill in all entries in the transition table for .
(from line 3): in this case the original machine is scanning the first input cell, i.e., that containing . There are two possibilities depending on the first parameter . If from the state on the left endmarker it is possible to move right in the state , i.e., , then the backward simulation of the segment is completed. Hence, the machine halts and accept (line 3). Otherwise, since we are interested just in one segment, we ignore the left predecessors of , since they correspond to moves from the left endmarker, i.e., to the starting of segments others than the one we are interested in. The machine immediately enters in the ending state of Mode 1 , moving right the input head, to reach the real position in the simulated machine (line 3).
There are no left predecessors (line 3): the machine ends Mode 1 (notice that, since we already considered , in this case and in the next one the transitions we have to consider are deterministic).
This case is exactly as in [GMP07]. In this state, the examination of the left predecessors of has been completed. Hence, the search continues with the examination of the right predecessors in the Mode 2 (line 4), by switching to the state and moving the head to the position . If the input head is already on the right endmarker, i.e., , then the configuration does not have any right predecessors (line 4). Hence, by switching to , we finish the Mode 2 immediately, as if all right predecessors had been searched.
Even this case is as in [GMP07]. In the state , starts to examine right predecessors of , i.e., configurations such that . has its head already at the position . We observe that in a right predecessor of a configuration, the head cannot scan the left endmarker. Hence, all transitions from right predecessors are deterministic. There are three main cases:
This state concludes the examination of the configuration , and all configurations in the subtree rooted at . The machine has its head at the position , the actual position of the head of the simulated machine . There are three main cases:
The head is scanning the left endmarker (line 6): since in the backward simulation we ignore the transitions from the left endmarker (see line 3 in the definition of ), the only reachable configuration of the form that can be reached is , namely, the configuration from which the backward simulation started. If this happens, it means that we have examined all the tree rooted at , never accepting. Hence, a computation segments from to on input does not exists and have to reject. This can be done by leaving the transition undefined: the computation stops in a state different from the accepting state .
The configuration does not have any successor (line 6): a such configuration is never reached in the backward search. This case is included only for completeness.
In the remaining case (from line 6), since the head is scanning a position different from the left endmarker, the configuration has as unique successor , which can obtained using the transition function of (line 6), and . Depending on the value of , we have to consider either left predecessors () or right predecessors () of (we call them “-predecessors”, for short). First we try to find a state greater than such that is a -predecessor. If it does not exists then is the last -predecessor of . Hence (depending on ), we complete Mode 1 or Mode 2 for (lines 6–6). Otherwise, we start to examine in Mode 1, with the same method, the next -predecessor of (lines 6–6).
To complete the description of the automaton , we have to specify that the initial state is . In fact, we are interested in a segment from to on input . By definition, such a segment should end in the configuration . This configuration does not have left predecessors. This permits us to state the depth-first search from the state , with the head on the left endmarker. If there exists the segment we are looking for, then the computation ends, as explained before, in the state (line 3). Otherwise, it ends in some different state (line 6) after traversing the whole subtree rooted at .
We observe that the automaton so described has states and it depends on the two states and we have fixed at the beginning. What happens if we change those states, i.e., if we consider them as parameters?
The only parts of the construction that depend on and are the choice of the initial state and the transitions from the endmarkers and states (lines 3–3). We can modify by keeping, for each possible value of the parameter , a table with the values of . During the execution will consult the appropriate table depending on the value of the parameter. All the other transitions of are unchanged. Furthermore, we can initialize in a suitable state, depending on the parameter .
Hence, using states (not including the space used to store the two parameters ), we can implement with the following procedure (which also considers the trivial cases and which never modify the two parameters):
Appendix B . The subroutines nReach and tReach
Given a state , should return a nondeterministic chosen state such that there exists a computation segment from to on the given input string. If the subroutine is not able to find such a segment, due to the fact that such a state does not exist or due to wrong nondeterministic choices, then the subroutine halts in the state , aborting the entire computation.
The implementation can be given as a modification of that of Reach. In particular, uses the backward search described in Section A, starting from the configuration . When a configuration with the input head scanning the first input symbol is reached, i.e., , then the subroutine nondeterministically selects one between these two actions:
Output a nondeterministically chosen state such that . This means that is a left predecessor of and so there is a segment from to . (If such a state does not exists, the computation is aborted in .)
Ignore the left predecessors of and continue the backward simulation. Hence, the machine try to detect a longer segment.
:= a nondeterministically choosen state such that (if such a state does not exist the entire computation is aborted in ).
This stop the computation by producing the output in the parameter, as a side effect.
The computation can also traverse the whole subtree rooted at without reaching the starting configuration of a segment. This can happen either because a segment ending in does not exist or because a wrong sequence of nondeterministic choices. In this case we have to halt in the state , aborting the entire computation. In the implementation of Reach this case was managed in line 6. We need simply to change the assignment into .
This implementation of nReach uses the same set of states of Reach, with the exception of , plus the “global” state . Hence it can implemented with states. We should also notice that it can produce, as a side effect, a modification of the parameter.
The nondeteministic subroutine tReach is implemented calling times nReach as shown in the following high-level code:444The (redundant) assignment on line 8 is to emphasize that leaves its output in the parameter.