Succinctness of two-way probabilistic and quantum finite automata

We prove that two-way probabilistic and quantum finite automata (2PFA's and 2QFA's) can be considerably more concise than both their one-way versions (1PFA's and 1QFA's), and two-way nondeterministic finite automata (2NFA's). For this purpose, we demonstrate several infinite families of regular languages which can be recognized with some fixed probability greater than $ {1/2} $ by just tuning the transition amplitudes of a 2QFA (and, in one case, a 2PFA) with a constant number of states, whereas the sizes of the corresponding 1PFA's, 1QFA's and 2NFA's grow without bound. We also show that 2QFA's with mixed states can support highly efficient probability amplification. The weakest known model of computation where quantum computers recognize more languages with bounded error than their classical counterparts is introduced.


Introduction
In recent years, the research effort on quantum versions of finite automata has mainly focused on oneway models, with the study of two-way quantum finite automata (2QFA's), which are synonymous with constant space quantum Turing machines, receiving relatively less attention. In their seminal paper, Kondacs and Watrous [KW97] proved that 2QFA's recognize all regular languages with zero error, and the language L eq = {a n b n | n ≥ 0} with any desired error bound ǫ > 0, in time O( 1 ǫ |w|), using O( 1 ǫ 2 ) states, where w is the input string. Since two-way probabilistic finite automata (2PFA's) can decide L eq only in exponential time [Fre81,KF90,DS92], this established the superiority of 2QFA's over 2PFA's. Parallelling work by Aharonov et al. [AKN98] on quantum circuits with mixed states, Ambainis and Watrous [AW02] introduced an alternative model, the two-way finite automaton with quantum and classical states (2QCFA), which includes a constant-size quantum part which may be in a mixed state, but requires the tape head position to be classical. Yakaryılmaz and Say [YS09a] noted that conventional methods of probability amplification give significantly inefficient results when applied to 2QFA's, and presented methods which can be used to decide L eq with error bound ǫ in as low as O(|w|) steps (i.e. with runtime independent of ǫ), and with as low as O(log 2 ( 1 ǫ ) log log( 1 ǫ )) states. Issues of succinctness, as exemplified above, constitute a rich subtopic of automata theory [DS90,KF90,AF98,MPP01,ANTSV02, FOM09,YS09a]. In this paper, we examine how the combination of two-wayness and (quantum or classical) probabilistic transitions affects succinctness. As our main result, we demonstrate several infinite families of regular languages which can be recognized with some fixed probability greater than 1 2 by just tuning the transition amplitudes of a 2QFA (and, in one case, a 2PFA) with a constant number of states, whereas the sizes of the corresponding one-way machines, and two-way nondeterministic finite automata (2NFA's) grow without bound. The Kondacs-Watrous model of quantum finite automaton (to be called, from now on, KWQFA), which allows measurements of a restricted type, rather than the full set sanctioned by quantum theory, has been proven to be weaker in terms of language recognition power [KW97], probability amplification capability [AF98], and, in some cases at least, succinctness [ANTSV02], than the corresponding classical model, in the one-way case. More general models, such as the 2QCFA, employing mixed states, are able to simulate the corresponding classical probabilistic automata efficiently in both the one-way and two-way settings, and to recognize some languages that 2PFA's cannot [AW02]. We show that 2QFA's with mixed states can support highly efficient probability amplification, surpassing the best known methods for 2KWQFA's recognizing these languages.
We introduce a new model of quantum automaton, named the two-way quantum finite automaton with reset. This is an enhancement to the 2KWQFA, endowing it with the capability of resetting the position of the tape head to the left end of the tape in a single move during the computation. We use this model both in the proof of our main result, and in the demonstration of our probability amplification techniques. We mostly focus on a restricted form of these machines, called the one-way quantum finite automaton with restart (1QFA ), which can switch only to the initial state during left resets, and cannot perform single-step left or stationary moves. We give evidence that this is the weakest known model of computation where quantum computers recognize more languages with bounded error than their classical counterparts.
The rest of this paper is structured as follows: Section 2 contains the definitions and some basic facts about our new model that will be used throughout the paper. In Section 3, we prove some key lemmata about the relationship between one-way quantum finite automata with and without restart, and examine the class of languages recognized with bounded error by 1QFA 's. Our main succinctness result is presented in Section 4. In Section 5, we present several algorithms that improve previous results about the efficiency of probability amplification in 2KWQFA's and 2QCFA's. In Section 6, we investigate the computational power of probabilistic finite automata with restart. Section 7 is a conclusion.

Preliminaries
Watrous [Wat97] notes that a 2KWQFA algorithm he presents for recognizing a nonregular language is remarkably costly in terms of probability amplification, and states that this problem stems from the fact that 2KWQFA's cannot "reset" themselves during execution to repeatedly carry out the same computation. The 2QCFA model provides one way of solving this problem, by having a classical part, in addition to the quantum register. We present an alternative 2QFA model, employing only quantum states, whose only difference from the 2KWQFA is the existence of an additional "reset move" in its repertory. Section 2.1 contains the definitions of this and the other models that will be examined in the paper. Section 2.2 describes some facts which will make the analyses of the algorithms in later sections easier.

Definitions
Let Σ be an input alphabet, not containing the end-marker symbols and $, and let Γ = Σ ∪ { , $} be the tape alphabet.
A 2-way quantum finite automaton with reset (2QFA ) is a 7-tuple where 1. Q = {q 0 , . . . , q n } is the finite set of states; 2. δ is the transition function, described below; 3. q 0 ∈ Q is the initial state; 4. Q acc is the set of accepting states; 5. Q rej is the set of rejecting states; 6. Q non = Q \ (Q acc ∪ Q rej ∪ Q reset ) is the set of nonhalting and nonresetting states; 7. Q reset is the union of disjoint reset sets, i.e., each Q q∈Qnon contains reset states that cause the computation to restart with state q, as described below.
We assume that the states in Q non have smaller indices than other members of Q; q i ∈ Q non for 0 ≤ i < |Q non |.
The configurations of a 2QFA are pairs of the form (state, head position). Initially, the head is on the left end-marker , and so the machine starts computation in the superposition |q 0 , 0 .
The transition function of a 2QFA working on an input string w ∈ Σ * , (that is, a tape containing w = w$,) is required to induce a unitary operator U w δ on the Hilbert space ℓ 2 (Q × Z |w| ), since quantum machines can exist in superpositions of more than one configuration.
In all 2QFA 's described in this paper, every transition entering the same state involves the tape head moving in the same direction (left, right, or stationary). With this simplification, considering the Hilbert space ℓ 2 (Q), a syntactically correct 2QFA (that is, one where U w δ is unitary for every w,) can be specified easily by just providing a unitary operator U σ : ℓ 2 (Q) → ℓ 2 (Q) for each symbol σ ∈ Γ . More formally, is the amplitude with which the machine currently in state q and scanning symbol σ will jump to state q ′ and move the head in direction d q ′ . Here, d q ′ ∈ {−1, 0, 1} is the direction of the tape head determined by q ′ . For the remaining directions, all transitions with target q ′ have amplitude zero.
Apart from the left reset capability, 2QFA 's are identical to 2KWQFA's. In the following, we focus on this new capability, and refer the reader to [KW97] for detailed coverage of the technical properties of 2KWQFA's.
In each step of its execution, a 2QFA undergoes two linear operations: The first one is a unitary transformation of the current superposition according to δ, and the second one is a measurement. The observable describing this measurement process is designed so that the outcome of any observation is one of "accept", "reject", "continue without resetting", or "reset with state q", for any q ∈ Q non . Formally, we use the observable O, corresponding to the decomposition 6. S acc ⊂ S is the set of classical accepting states; 7. S rej ⊂ S is the set of classical rejecting states.
The functions Θ and δ specify the evolution of the quantum and classical parts of M, respectively. Both functions take the currently scanned symbol σ ∈ Γ and current classical state s ∈ S as arguments. Θ(s, σ) is either a unitary transformation, or an orthogonal measurement. In the first case, the new classical state and tape head direction (left, right, or stationary) are determined by δ, depending on s and σ. In the second case, when an orthogonal measurement is applied on the quantum part, δ determines the new classical state and the tape head direction using the result of that measurement, as well as s and σ. The quantum and classical parts are initialized with |q 0 and s 0 , respectively, and the tape head starts on the first cell of the tape, on which w$ is written for a given input string w ∈ Σ * . During the computation, if an accepting or rejecting state is entered, the machine halts with the relevant response to the input string.
Note that like the 1QFA , and unlike the 2QFA and the 2QFA , the tape head position of a 2QCFA is classical, (that is, there are no superpositions with the head in more than one position simultaneously,) meaning that the machine can be implemented using a quantum part of constant size.

Basic facts
We start by stating some basic facts concerning automata with restart, which will be used in later sections.
A segment of computation which begins with a (re)start, and ends with a halting or restarting configuration will be called a round. Clearly, every automaton with restart which makes nontrivial use of its restarting capability will run for infinitely many rounds on some input strings. Throughout this paper, we make the assumption that our two-way automata do not contain infinite loops within a round, that is, the computation restarts or halts with probability 1 in a finite number steps for each round.
Everywhere in this section, R will stand for a finite state automaton with restart, and w ∈ Σ * will represent an input string using the alphabet Σ.

Definition 1.
• p acc (R, w), p rej (R, w), and p restart (R, w) denote the probabilities that R will accept, reject, or restart, respectively, on input w, in the first round. • P acc (R, w) and P rej (R, w) denote the overall acceptance and rejection probabilities of w by R, respectively.
. P rej (R, w) is calculated in the same way.
Proof. This follows from Lemma 1, since, for all p ≥ 0, ǫ ∈ [0, 1 2 ), Lemma 3. Let p = p halt (R, w), and let s(w) be the maximum number of steps in any branch of a round of R on w. The worst-case expected runtime of R on w is Lemma 4. Any one-way automaton with restart with expected runtime t can be simulated by a corresponding two-way automaton without restart in expected time no more than 2t.
Proof. The program of the two-way machine (R 2 ) is identical to that of the one-way machine with restart (R 1 ), except for the fact that each restart move of R 1 is imitated by R 2 by moving the head one square per step all the way to the left end-marker. This causes the runtimes of the i nonhalting rounds in the summation in Equation (9) in Lemma 3 to increase by a factor of 2.
We will now give a quick review of the technique of probability amplification. Suppose that we are given a machine (with or without reset) A, which recognizes a language L with error bounded by ǫ, and we wish to construct another machine which recognizes L with a much smaller, but still positive, probability of error, say, ǫ ′ . It is well known 1 that one can achieve this by running A O(log( 1 ǫ ′ )) times on the same input, and then giving the majority answer as our verdict about the membership of the input string in L.
Suppose that the original machine A needs to be run 2k + 1 times for the overall procedure to work with the desired correctness probability. Two counters can be used to count the acceptance and rejection responses, and the overall computation accepts (rejects) when the number of recorded acceptances (rejections) reaches k + 1. To implement these counters in the finite automaton setting, we need to "connect" (k + 1) 2 copies of A, {A i,j | 0 ≤ i, j ≤ k}, where the subscripts indicate the values of the two counters, i.e., the states of A i,j encode the information that A has accepted i times and rejected j times in its previous runs. The new machine M is constructed from the A i,j as follows: -The start state of M is the start state of A 0,0 ; -Upon reaching any accept state of A i,j (0 ≤ i, j < k), M moves the head back to the left end-marker and then switches to the start state of A i+1,j ; -Upon reaching any reject states of A i,j (0 ≤ i, j < k), M moves the head back to the left end-marker and then switches to the start state of A i,j+1 ; -The accept states of M are the accept states of A k,j (0 ≤ j < k); -The reject states of M are the reject states of A i,k (0 ≤ i < k).
Lemma 5. If language L ⊆ Σ * is recognized by R with a fixed error bound ǫ > 0, then for any positive error bound ǫ ′ < ǫ, there exists a finite automaton with reset, R ′ , recognizing L . Moreover, if R has n states and its (expected) runtime is O(s(|w|)), then R ′ has O(log 2 ( 1 ǫ ′ )n) states, and its (expected) runtime is O(log( 1 ǫ ′ )s(|w|)), where w is the input string. Proof. Follows easily from the above description.
Finally, we note the following relationship between the computational powers of the 2QCFA and the 1QFA .
Lemma 6. For any 1QFA M 1 with n states and expected runtime t(|w|), there exists a 2QCFA M 2 with n quantum states, O(n) classical states, and expected runtime O(t(|w|)), such that M 2 accepts every input string w with the same probability that M 1 accepts w.
Proof. We utilize the 2QCFA's ability of making arbitrary orthogonal measurements. Given a 1QFA M 1 , we construct a 2QCFA M 2 with the same set of quantum states. On each tape square, M 2 first performs the unitary transformation associated with the current symbol by the program of M 1 . It then makes a measurement (over the space spanned by the set of quantum states) using an observable O ′ , which is formed by replacing each subspace of the form E reset−i in The outcome associated with E reset−i−q i j is simply the name of q i j . M 2 takes the action specified below according to the result of this observation: 1. "continue without resetting": move the head one square to the right, 2. "accept": accept, 3. "reject": reject, 4. "q i j ": enter a classical state that moves the head left until the left end-marker is seen, and perform a unitary transformation that transforms the quantum register from state q i j to q i .

Computational power of 1QFA 's
In this section, we focus on the 1QFA , which turns out to be the simplest and most restricted known model of quantum computation that is strictly superior in terms of bounded-error language recognition to its classical counterpart.
Our first result shows that 1QFA 's can simulate any 1PFA with small state cost, albeit with great slowdown. Note that no such relation is known between the 2KWQFA and its classical counterpart, the 2PFA. Theorem 1. Any language L ⊆ Σ * recognized by an n-state 1PFA with error bound ǫ can be recognized by a 2n + 4-state 1QFA with the same error bound. Moreover, if the expected runtime of the 1PFA is O(s(|w|)), then the expected runtime of the 1QFA is O(l 2|w| s 2 (|w|)) for a constant l > 1 depending on n, where w is the input string.
Proof. Let P be an n-state 1PFA recognizing L with error bound ǫ. We will construct a 2n+4-state 1QFA M recognizing the same language with error bound ǫ ′ ≤ ǫ.
By adding two more states, s acc and s rej , to P, we obtain a new 1PFA , P ′ , where the halting of the computation in each round is postponed to the last symbol, $, on which the overall accepting and rejecting probabilities are summed up into s acc and s rej , respectively. Therefore, for any given input string w ∈ Σ * , the value of s acc and s rej are p acc (P, w) and p rej (P, w), respectively, at the end of the first round. By using the method described in [YS09b], each stochastic matrix can be converted to a unitary one with twice the size as shown in the template where A is the original stochastic matrix; the columns of B, corresponding to newly added states, are filled in to ensure that each row of (A | B) is pairwise orthogonal to the others, and has the same length l, which depends only on the dimension of A, and the entries of D are then selected to make U a unitary matrix. Each transition matrix of P ′ can be converted to a (2n + 4) × (2n + 4)-dimensional unitary matrix according to this template. These are the transition matrices of M. The state set of M can be specified as follows: 1. The states corresponding to s acc and s rej are the accepting and rejecting states, q acc and q rej , respectively, 2. the states corresponding to the non-halting and non-restarting states of P ′ are non-halting and non-restarting states, and, 3. all remaining states are restarting states.
The initial state of M is the state corresponding to the initial state of P.
When M runs on input string |w|, the amplitudes of q acc and q rej , the only halting states of M, at the end of the first round are 1 l |w|+2 p acc (P, w) and 1 l |w|+2 p rej (P, w), respectively. Therefore, and similarly, when w / ∈ L, By solving the equation ǫ The expected runtime of P is 1 p acc (P, w) + p rej (P, w) ∈ O(s(|w|)), and so the expected runtime of M is (l) 2|w|+4 1 p 2 acc (P, w) + p 2 rej (P, w) < 3 (l) 2|w|+4 1 p acc (P, w) + p rej (P, w) 2 ∈ O(l 2|w| s 2 (|w|)). To establish the strict superiority of 1QFA 's over 1PFA 's, we will make use of the following concepts.
An automaton M is said to recognize a language L with positive one-sided unbounded error if every input string w ∈ L is accepted by M with nonzero probability, and every w / ∈ L is rejected by M with probability 1. An automaton M is said to recognize a language L with negative one-sided unbounded error if every input string w ∈ L is accepted by M with probability 1, and every w / ∈ L is rejected by M with nonzero probability.
For an automaton M recognizing a language L, we define the gap function, g M : N → [0, 1], such that g M (n) is the difference between the minimum acceptance probability of a member of L with length at most n and the maximum acceptance probability of a non-member of L with length at most n 3 .
Lemma 7. If a language L is recognized by a 1KWQFA M with positive (negative) one-sided unbounded error such that g M (n) ≥ c −n for some c > 1, then for all ǫ ∈ (0, 1 2 ), L is recognized by some 1QFA having three more states than M with positive (negative) one-sided error ǫ in expected time O( 1 ǫ c |w| |w|).
Proof. We consider the case of positive one-sided error. The adaptation to the other case is trivial. M is converted into a 1QFA M ′ ǫ as follows. M ′ ǫ starts by branching to two equiprobable paths, path 1 and path 2 , at the beginning of the computation. path 1 imitates the computation of M, except that all reject states that appear in its subpaths are replaced by restart states. Regardless of the form of the input, path 2 moves right with amplitude 1 √ c , (and so restarts the computation with the remaining probability,) on every input symbol. When it arrives at the right end-marker, path 2 rejects with amplitude √ ǫ, and restarts the computation with amplitude √ 1 − ǫ. Lemma 8. If a language L is recognized by a 1KWQFA M with positive (negative) one-sided bounded error such that g M (n) ≥ c −1 for some c > 1, then for all ǫ ∈ (0, 1 2 ), L is recognized by some 1QFA having three more states than M with positive (negative) one-sided error ǫ in expected time O( 1 ǫ c|w|).
Proof. The construction is almost identical to that in Lemma 7, except that path 2 rejects with amplitude √ ǫ, and restarts the computation with amplitude √ 1 − ǫ immediately on the left endmarker, thereby causing every input to be rejected with the constant probability ǫ 2c . Hence, the expected runtime of M ′ ǫ turns out to be O( 1 ǫ c|w|).
Lemma 7 is a useful step towards an eventual characterization of the class of languages that are recognized with one-sided bounded error by 1QFA 's, since full classical characterizations are known [YS09c] for the classes of languages recognized by one-sided unbounded error by several 1QFA models, including the 1KWQFA.
A language L is said to belong to the class S = rat [Tur69,Mac93] if there exists a rational 1PFA that accepts all and only the members of L with probability 1 2 .
Theorem 2. For every language L ∈ S = rat , there exists a number n such that for all error bounds ǫ > 0, there exist n-state 1QFA 's that recognize L and L with one-sided error bounded by ǫ.
Proof. For a language L in S = rat , let P be the rational 1PFA associated by L as described above. Turakainen [Tur69] showed that there exists a constant b > 1 such that for any string w / ∈ L, the probability that P accepts w cannot be in the interval ( 1 2 − b −|w| , 1 2 + b −|w| ). By using the method described in [YS09c], we can convert P to a 1KWQFA M recognizing L with one-sided unbounded error, so that M accepts any w ∈ L with probability greater than c −|w| , for a constant c > b. We can conclude with Lemma 7. S = rat contains many well-known languages, such as, L eq , L pal = {w | w = w R }, L twin = {wcw | w ∈ {a, b} * }, L mult = {x#y#z | x, y, z are natural numbers in binary notation and x × y = z}, L square = {a n b n 2 | n > 0}, L power = {a n b 2 n }, and all polynomial languages, [Tur82] defined as {a n 1 1 · · · a n k k b where a 1 , · · · , a k , b 1 , · · · , b r are distinct symbols, and each p i is a polynomial with integer coefficients. Note that Theorem 2 and Lemma 6 answer a question posed by Ambainis and Watrous [AW02] about whether L square and L power can be recognized with bounded error by 2QCFA's affirmatively. Proof. This follows from Theorems 1 and 2, Lemma 4, and the fact [DS92] that L pal cannot be recognized with bounded error by 2PFA's.
Since general 1QFA's are known to be equivalent in language recognition power to 1PFA's, one has to consider a two-way model to demonstrate the superiority of quantum computers over classical ones. The 2QCFA is known [AW02] to be superior to its classical counterpart, the 2PFA, also by virtue of L pal . Recall that, by Lemma 6, 2QCFA's can simulate 1QFA 's easily, and we do not know of a simulation in the other direction.

Conciseness of 2QFA's with mixed states and 2PFA's
In this section, we demonstrate several infinite families of regular languages which can be recognized with some fixed probability greater than 1 2 by just tuning the transition amplitudes of a 1QFA with a constant number of states, whereas the sizes of the corresponding 1QFA's, 1PFA's, and 2NFA's grow without bound. One of our constructions can be adapted easily to show that 1PFA 's, (and, equivalently, 2PFA's), also possess the same advantage over those machines.

Definition 2.
For an alphabet Σ containing symbol a, and m ∈ Z + , the family of languages A m is defined as Note that Ambainis et al. [ANTSV02] report that any Nayak one-way quantum finite automaton 4 that recognizes A m with some fixed probability greater than 1 2 has 2 Ω(m) states.
and the transitions not mentioned above can be completed easily, by extending each U σ to be unitary.
On the left end-marker, M m,ǫ rejects with probability ǫ 2m+5 , goes on to scan the input string with amplitude ǫ, and restarts immediately with the remaining probability. States q 0 and q 1 implement the check for the regular expression Σ * a, but the machine restarts with probability 1 − ǫ 2 on all input symbols during this check.
By a theorem of Rabin [Rab63], for any fixed error bound, if a language L is recognized with bounded error by a 1PFA with n states, then there exists a deterministic finite automaton (DFA) that recognizes L with 2 O(n) states. Parallelly, Freivalds et al. [FOM09] note that one-way quantum finite automata with mixed states are no more than superexponentially more concise than DFA's. These facts can be used to conclude that a collection of 1PFA's (or 1QFA's) with a fixed common number of states that recognize an infinite family of languages with a fixed common error bound less than 1 2 ,à la the two-way quantum automata of Theorem 3, cannot exist, since that would imply the existence of a similar family of DFA's of fixed size. By the same reasoning, the existence of such families of 2NFA's can also be overruled.
The reader should note that there exists a bounded-error 1PFA (and therefore, a 2PFA 5 ,) for A m , which one can obtain simply by replacing each transition amplitude of 1QFA M m,ǫ defined in Theorem 3 by the square of its modulus. This establishes the fact that 2PFA's also possess the succinctness advantage discussed above over 1PFA's, 1QFA's and 2NFA's.
We proceed to present two more examples.
Definition 3. For m ∈ Z + , the language family B m ⊆ {a} * is defined as Theorem 4. For any error bound ǫ > 0, there exists a 7-state 1QFA M m,ǫ which accepts any w ∈ B m with certainty, and rejects any w / ∈ B m with probability at least 1−ǫ. Moreover, the expected runtime of M m,ǫ on w is O 1 ǫ sin −2 ( π m )|w| .
Proof. We will construct a 4-state 1KWQFA recognizing B m with positive one-sided unbounded error, as described in and the transition amplitudes not listed above are filled in to satisfy unitarity. M m begins computation at the |q 0 -axis, and performs a rotation by angle π m in the |q 0 -|q 1 plane for each a it reads. Therefore, the value of the gap function, g Mm , is not less than sin 2 ( π m ) for |w| > 0. By Lemma 8, there exists a 7-state 1QFA M m,ǫ recognizing B m with positive one-sided bounded error and whose expected runtime is O 1 ǫ sin −2 ( π m )|w| . By swapping the accepting and rejecting states of M m,ǫ , we can get the desired machine.
Definition 4. For an alphabet Σ, and m ∈ Z + , the language family C m is defined as Theorem 5. For any error bound ǫ > 0, there exists a 7-state 1QFA M m,ǫ which accepts any w ∈ C m with certainty, and rejects any w / ∈ C m with probability at least 1−ǫ. Moreover, the expected runtime of M m,ǫ on w is O( 1 ǫ 2 m |w|).
Proof. We will contruct a 4-state 1KWQFA recognizing C m with positive one-sided unbounded error. Let M m = (Q, Σ, δ, q 0 , Q acc , Q rej ) be 1KWQFA with Q non = {q 0 , q 1 }, Q acc = {A}, Q rej = {R}. M m contains the transitions with the amplitudes of the transitions not mentioned above filled in to ensure unitarity.
M m encodes the length of the input string in the amplitude of state q 0 , which equals 1 just before the processing of the right end-marker. The desired length m is "hardwired" into the amplitudes of q 1 . For a given input string w ∈ Σ * , if w ∈ C m , then the amplitudes of states q 0 and q 1 are equal, and the quantum Fourier transform (QFT) [KW97] performed on the right end-marker sets the amplitude of A to 0. Therefore, w is rejected with certainty. If w ∈ C m , then the accepting probability is equal to and it is minimized when |w| = m + 1, which gives us the inequality By Lemma 8, there exists a 7-state 1QFA M m,ǫ recognizing C m with positive one-sided bounded error and whose expected runtime is O 1 ǫ 2 m |w| . By swapping the accepting and rejecting states of M m,ǫ , we can get the desired machine.
Note that, unlike what we had with Theorem 3, the QFA's of Theorems 4 and 5 cannot be converted so easily to 2PFA's. In fact, we can prove that there exist no 2PFA families of fixed size which recognize B m and C m with fixed one-sided error less than 1 2 , like those QFA's: Assume that such a 2PFA family exists. Switch the accept and reject states to obtain a family for the complements of the languages. The 2PFA's thus obtained operate with cutpoint 0. Obtain an equivalent 2NFA with the same number of states by converting all transitions with nonzero weight to nondeterministic transitions. But there are only finitely many 2NFA's of this size, meaning that they cannot recognize our infinite family of languages.

Efficient Probability Amplification
Many automaton descriptions in this paper, and elsewhere in the theory of probabilistic and quantum automata, describe not a single algorithm, but a general template which one can use for building a machine M ǫ that operates with a desired error bound ǫ. The dependences of the runtime and number of states of M ǫ on 1 ǫ are measures of the complexity of the probability amplification process involved in the construction method used. Viewed as such, the constructions described in the theorems in Section 4 are maximally efficient in terms of the state cost, with no dependence on the error bound. In this section, we present improvements over previous results about the efficiency of probability amplification in 2QFA's.

Improved algorithms for L eq
In classical computation, one only needs to sequence O(log( 1 ǫ )) identical copies of a given probabilistic automaton with one sided error p < 1 to run on the same input in order to obtain a machine with error bound ǫ. Yakaryılmaz and Say [YS09a] noted that this method of probability amplification does not yield efficient results for 2KWQFA's; the number of machine copies required to reduce the error to ǫ can be as high as ( 1 ǫ ) 2 . The most succinct 2KWQFA's for L eq produced by alternative methods developed in [YS09a] have O(log 2 ( 1 ǫ ) log log( 1 ǫ )) states, and runtime linear in the size of the input w. In Appendix A, we present a construction which yields (exponential time) 1QFA 's that recognize L eq within any desired error bound ǫ, with no dependence of the state set size on ǫ. Ambainis and Watrous [AW02] present a method which can be used to build 2QCFA's that recognize L eq also with constant state set size, where the "tuning" of the automaton for a particular error bound is achieved by setting some transition amplitudes appropriately, and the expected runtime of those machines is O(|w| 4 ). We now show that the 2QFA formalism allows more efficient probability amplification.
Theorem 6. There exists a constant n, such that, for any ǫ > 0, an n-state 2QFA which recognizes L eq with one-sided error bound ǫ within O( 1 ǫ |w|) expected runtime can be constructed, where w is the input string.
Proof. We start with Kondacs and Watrous' original 2KWQFA [KW97] M N , which recognizes L eq with one-sided error 1 N , for any integer N > 1. After a deterministic test for membership of a * b * , M N branches to N computational paths, each of which perform a QFT at the end of the computation. Set N = 2. M 2 accepts all members of L eq with probability 1. Non-members of L eq are rejected with probability at least 1 2 . We convert M 2 to a 2QFA M ′ ǫ by changing the target states of the QFT as follows: where the amplitude of each path is 1 It is easily seen that the error is one-sided. Since pacc(M ′ ǫ ,w) p rej (M ′ ǫ ,w) = ǫ, we can conclude with Lemma 2. Moreover, the minimum halting probability occurs in the third case above, and so the expected Theorem 7. For any ǫ ∈ (0, 1 2 ), there exists a 2QFA with O(log( 1 ǫ )) states that recognizes L eq with one-sided error bound ǫ in O(log( 1 ǫ )|w|) steps, where w is the input string. Proof. Let M 2 be the 2KWQFA recognizing L eq with one-sided error bound 1 2 mentioned in the proof of Theorem 6. Then, a 2QFA that is constructed by sequentially connecting O(log( 1 ǫ )) copies of M 2 , so that the input is accepted only if it is accepted by all the copies, and rejected otherwise, can recognize L eq with one-sided error bound ǫ. a 2KWQFA which accepts all members of the complement of L pal with probability 1, and fails to halt for all palindromes; it is not known if 2KWQFA's can recognize this language by halting for all inputs.) We will now present a 1QFA construction, which, by Lemma 6, can be adapted to yield 2QCFA's with the same complexity, which reduces the dependence of the Ambainis-Watrous method on the desired error bound considerably.
Theorem 8. For any ǫ > 0, there exists a 15-state 1QFA M ǫ which accepts any w ∈ L pal with certainty, and rejects any w / ∈ L pal with probability at least 1 − ǫ. Moreover, the expected runtime of M ǫ on w is O( 1 ǫ 3 |w| |w|). Proof. We will first construct a modified version of the 1KWQFA algorithm of Lāce et al. [LSDF09] for recognizing the nonpalindrome language. The idea behind the construction is that we encode both the input string and its reverse into the amplitudes of two of the states of the machine, and then perform a substraction between these amplitudes using the QFT [LSDF09]. If the input is not a palindrome, the two amplitudes do not cancel each other completely, and the nonzero difference is transferred to an accept state. Otherwise, the accepting probability will be zero.
Let M = (Q, Σ, δ, q 0 , Q acc , Q rej ) be 1KWQFA with Q non = {p 1 , p 2 , q 0 , q 1 , q 2 , q 3 } , Q acc = {A}, Q rej = {R i | 1 ≤ i ≤ 5}. The transition function of M is shown in Figure 1. As before, we assume that the transitions not specified in the figure are filled in to ensure that the U σ are unitary. path 2 and path 1 encode the input string and its reverse [Rab63,Paz71] into the amplitudes of states q 2 and p 2 , respectively. If the input is w = w 1 w 2 · · · w l , then the values of these amplitudes just before the transition associated with the right end-marker in the first round are as follows: -State p 2 has amplitude 1 √ 2 2 3 |w| (0.w l w l−1 · · · w 1 ) 2 , and state q 2 has amplitude 1 √ 2 2 3 |w| (0.w 1 w 2 · · · w l ) 2 .
The factor of 2 3 is due to the "loss" of amplitude necessitated by the fact that the originally nonunitary encoding matrices of [Rab63,Paz71] have to be "embedded" in a unitary matrix [YS09b]. Note that the symbols a and b are encoded by 0 and 1, respectively.
If w ∈ L pal , the acceptance probability is zero. If w ∈ L pal , the acceptance probability is minimized by strings which are almost palindromes, except for a single defect in the middle, that is, when |w| = 2k for k ∈ Z + , w i = w 2k−i+1 , where 1 ≤ i ≤ k − 1, and w k = w k+1 , so, By Lemma 7, there exists a 15-state 1QFA M ǫ recognizing L pal with positive one-sided bounded error, whose expected runtime is O( 1 ǫ 3 |w| |w|). By swapping accepting and rejecting states of M m , we can get the desired machine.
Note that the technique used in the proof above can be extended easily to handle bigger input alphabets by using the matrices defined on Page 169 of [Paz71], and the method of simulating stochastic matrices by unitary matrices described in [YS09b].

1PFA vs. 2PFA
It is interesting to examine the power of the restart move in classical computation as well. Any 1PFA which runs in expected t steps can be simulated by a 2PFA which runs in expected 2t steps (see Lemma 4). We ask in this section whether the restart move can substitute the "left" and "stationary" moves of a 2PFA without loss of computational power. Since every polynomialtime 2PFA recognizes a regular language, which can of course be recognized by using only "right" moves, we focus on the best-known example of a nonregular language that can be recognized by an exponential-time 2PFA.
Theorem 9. There exists a natural number k, such that for any ǫ > 0, there exists a k-state 1PFA P ǫ recognizing language L eq with error bound ǫ and expected runtime O(( 2 ǫ 2 ) |w| |w|), where w is the input string.