Complexity of regular abstractions of one-counter languages
Mohamed Faouzi Atig Dmitry Chistikov Piotr Hofman ∗ Uppsala University, Sweden MPI-SWS, Germany LSV, CNRS & ENS Cachan, [email protected] [email protected] Université Paris-Saclay, France [email protected]
K Narayan Kumar Prakash Saivasan Georg Zetzsche † Chennai Mathematical Institute, Chennai Mathematical Institute, LSV, CNRS & ENS Cachan, India India Université Paris-Saclay, France [email protected] [email protected] [email protected]
Abstract Reasoning about OCA, however, is hardly an easy task. We study the computational and descriptional complexity For example, checking whether two OCA accept some word of the following transformation: Given a one-counter au- in common is undecidable even in the deterministic case; for tomaton (OCA) A, construct a nondeterministic finite au- nondeterministic OCA, even language universality, as well tomaton (NFA) B that recognizes an abstraction of the lan- as language equivalence, is undecidable. For deterministic guage L(A): its (1) downward closure, (2) upward closure, OCA, equivalence is NL-complete; the proof of the member- or (3) Parikh image. For the Parikh image over a fixed al- ship in NL took 40 years [9, 35]. phabet and for the upward and downward closures, we find This lack of tractability suggests the study of finite-state polynomial-time algorithms that compute such an NFA. For abstractions for OCA. Such a transition is a recurrent theme the Parikh image with the alphabet as part of the input, we in formal methods: features of programs beyond finite state find a quasi-polynomial time algorithm and prove a com- are modeled with infinite-state systems (such as pushdown pleteness result: we construct a sequence of OCA that ad- automata, counter systems, Petri nets, etc.), and then finite- mits a polynomial-time algorithm iff there is one for all state abstractions of these systems come as an important OCA. For all three abstractions, it was previously unknown tool for analysis (see, e.g., [4–7, 15, 31, 34]). In our work, we if appropriate NFA of sub-exponential size exist. focus on the following three regular abstractions, each capturing a specific feature of a language L ⊆ Σ∗: • The 1. Introduction downward closure of L, denoted L↓, is the set of all subwords (subsequences) of all words w ∈ L, i.e., the set of all words The family of one-counter languages is an intermedi- that can be obtained from words in L by removing some ate class between context-free and regular languages: it is letters. The downward closure is always a superset of the strictly less expressive than the former and strictly more ex- original language, L ⊆ L↓, and, moreover, a regular one, no pressive than the latter. For example, the language {ambm | matter what L is, by Higman’s lemma [22]. m ≥ 0} is one-counter, but not regular, and the set of palin- dromes over the alphabet {a, b} is context-free, but not one- • The upward closure of L, denoted L↑, is the set of all counter. From the verification perspective, the correspond- superwords (supersequences) of all words w ∈ L, i.e., the ing class of automata, one-counter automata (OCA), can set of all words that can be obtained from words in L by model some infinite-state phenomena with its ability to keep inserting some letters. Similarly to L↓, the language L↑ track of a non-negative integer counter, see, e.g., [10], [29, satisfies L ⊆ L↑ and is always regular. Section 5.1], and [3, Section 5.2]. • The Parikh image of L, denoted ψ(L), is the set of |Σ| ∗ Supported by Labex Digicosme, Univ. Paris-Saclay, project all vectors v ∈ N , that count the number of occur- VERICONISS rences of letters of Σ in words from L. That is, suppose Σ = {a , . . . , a }, then every word w ∈ L corresponds to a † Supported by a fellowship within the Postdoc-Program of the 1 k German Academic Exchange Service (DAAD). vector ψ(w) = (v1, . . . , vk) such that vi is the number of oc- currences of ai in w. The set ψ(L) is always a regular subset |Σ| of N if L is context-free, by the Parikh theorem [33]. It has long been known that all three abstractions can be ef- fectively computed for context-free languages (CFL), by the results of van Leeuwen [36] and Parikh [33]. Algorithms per- forming these tasks, as well as finite automata recognizing these abstractions, are now widely used as building blocks in the language-theoretic approach to verification. Specifi- cally, computing upward and downward closures occurs as an ingredient in the analysis of systems communicating via [Copyright notice will appear here once ’preprint’ option is removed.] shared memory, see, e.g., [4, 6, 7, 31]. As the recent pa-
1 2016/1/19 per [28] shows, for parameterized networks of such systems construction has two steps, both of which are of interest: the decidability hinges on the ability to compute downward in the first step we show, using a combination of local and closures. The Parikh image as an abstraction in the verifica- global transformations on runs (Lemmas 20 and 21), that we tion of infinite-state systems has been used extensively; see, may focus our attention on runs with at most polynomially e.g., [1, 2, 5, 13, 15, 17, 20, 25, 34]. For pushdown systems, it many reversals. In the second step, which also works for is possible to construct a linear-sized existential Presburger pushdown automata, we turn the bound on reversals, using formula that captures the Parikh image [37], which leads, for an argument with a flavour of Strahler numbers [16], into a a variety of problems (see, e.g., [1, 13, 20, 25]), to algorithms logarithmic bound on the stack size of a pushdown system that rely on deciding satisfiability for such formulas (which (Lemma 23). is in NP). Finite automata for Parikh images are used as • We prove a lower-bound type result (Theorem 24): We find intermediate representations, for example, in the analysis of a sequence of OCA (Hn)n≥1, where n denotes the number multi-threaded programs [5, 15, 34] and in recent work on of states, over alphabets of growing size, that admits a so-called availability languages [2]. polynomial-time algorithm for computing an NFA for the Extending the scope of these three abstractions from CFL Parikh image if and only if there is such an algorithm for to other classes of languages has been a natural topic of all OCA. Thus, the problem of transforming an arbitrary interest. Effective constructions for the downward closure OCA A into an NFA for ψ(L(A)) is reduced to performing have been developed for Petri nets [19] and stacked counter this transformation on Hn, which enables us to call Hn automata [39]. The paper [38] gives a sufficient condition for complete. This result also has a counterpart referring to just a class of languages to have effective downward closures; this the existence of NFA of polynomial size. condition has since been applied to higher-order pushdown For the Parikh image of CFL, a number of constructions automata [21]. The effective regularity of the Parikh image is can be found in the literature as well; we refer the reader to known for linear indexed languages [12], phase-bounded and the paper by Esparza et al. [14] for a survey and state-of- scope-bounded multi-stack visibly pushdown languages [26, the-art results: exponential upper and lower bounds of the 27], and availability languages [2]. However, there are also form 2Θ(n) on the size of NFA for ψ(L). negative results: for example, it is not possible to effectively compute the downward closure of languages recognized by Applications lossy channels automata—this is a corollary of the fact that, Our results show that for OCA, unlike for pushdown sys- for the set of reachable configurations of a lossy channel tems, NFA representations of downward and upward clo- system, boundedness is undecidable [32]. sures and Parikh image (for fixed alphabet size) have ef- Our contribution ficient polynomial constructions. This suggests a possible way around standard NP procedures that handle existential We study the construction of nondeterministic finite au- Presburger formulas. This insight also leads to significant tomata (NFA) for L↓, L↑, and ψ(L), if L is given as an OCA gains when abstractions are used in a nested manner, as A with n states: L = L(A). It turns out that for one-counter illustrated by the following examples. languages—a proper subclass of CFL—all three abstractions Consider a network of pushdown systems communicat- can be computed much more efficiently than for the entire ing via a shared memory. The reachability problem is un- class of CFL. decidable in this setting. In [7] a restriction called stage- boundedness, generalizing context-boundedness, is explored. Upward and downward closures: We show, for OCA, how During a stage, the memory can be written to only by one to construct NFA accepting L↑ and L↓ in polynomial time system. Reachability along runs with at most k stages is (Theorems 2 and 7). The construction for L↑ is straightfor- decidable when all but one pushdown in the network are ward, but the one for L↓ is involved and uses pumping-like counters. The procedure in [7] uses NFA that accept up- techniques from automata theory. ward and downward closures of one-counter languages; the These results are in contrast with the exponential lower polynomial-time algorithms developed in the present paper bounds known for both closures in the case of CFL [36]: bring the complexity from NEXP down to NP for any net- Several constructions for L↑ and L↓ have been proposed in work with a fixed number of components. the literature (see, e.g., [8, 11, 18, 36]), and the best in terms Availability expressions [23] extend regular expressions of the size of NFA are exponential, due to van Leeuwen [36] by an additional counting operator to express quantitative and Bachmeier, Luttenberger, and Schlund [8], respectively. properties of behaviours. It uses a feature called occurrence Parikh image: For OCA, the problem of constructing NFA constraint to impose a set of linear constraints on the num- for the Parikh image turns out to be quite tricky. While ber of occurrences of alphabet symbols in sub-expressions. we were unable to solve the problem completely, we make As the paper [2] shows, the emptiness problem for avail- significant progress towards its solution: ability expressions is decidable, and the algorithm involves nested calls to Parikh-image computation for OCA. Our • For any fixed alphabet Σ we provide a complete solution: quasi-polynomial time algorithm for the Parikh image brings We find a polynomial-time algorithm that computes an NFA the complexity from non-elementary down to 2EXP. for ψ(L(A)) that has size O(|A|poly(|Σ|)) (Theorem 8). Two key ingredients of this construction are a sophisticated ver- sion of a pumping lemma (Lemma 14; cf. a standard pump- 2. Preliminaries ing lemma for one-counter languages, due to Latteux [30]) 2.1 One-counter automata and the classic Carathéodory theorem for cones in a multi- A one-counter automaton (OCA) A is a 5-tuple (Q, Σ, δ, q ,F ) dimensional space. 0 where Q a a finite set of states, q0 ∈ Q is an initial state, • We provide a quasi-polynomial solution to this problem and F ⊆ Q is a set of final states. Σ is a finite alphabet and in the general case: We find an algorithm that constructs a δ ⊆ Q × (Σ ∪ {ε}) × {−1, 0, +1, z} × Q is a set of transitions. O(log(|A|)) suitable NFA of size O(|Σ|·|A| ) (Theorem 22). This Transitions (p1, a, s, p2) ∈ δ are classified as incrementing
2 2016/1/19 Σ (s = +1), decrementing (s = −1), internal (s = 0), or tests Parikh image of a language L is the following subset of N : for zero (s = z). The size of A, denoted |A|, is its number ψ(L) = {ψ(w) | w ∈ L}. of states, |Q|. Σ |Σ| A configuration of an OCA is a pair that consists of a In the sequel, we usually identify N and N . state and a (non-negative) counter value, i.e., (q, n) ∈ Q×N. It follows from Higman’s lemma [22] that, for any L ⊆ Σ∗, A pair (p1, c1) ∈ Q × Z may evolve to a pair (p2, c2) ∈ Q × Z the languages L↑ and L↓ are regular; since they abstract via a transition t = (p1, a, s, p2) ∈ δ iff either s ∈ {−1, 0, +1} away some specifics of L, they are regular abstractions of and c1 + s = c2, or s = z and c1 = c2 = 0. We denote this L. For Parikh images, the situation is different: for example, t ∗ by (p1, c1) −→(p2, c2). unary languages L ⊆ {a} are essentially unaffected by the Consider a sequence of the form π = (p0, c0), t1, (p1, c1), Parikh mapping ψ, but it is easy to find unary languages that t2,..., tm, (pm, cm) where (pi, ci) ∈ Q × for 0 ≤ i ≤ are not even decidable, let alone regular. However, Parikh’s Z ∗ m and, whenever i > 0, it also holds that ti ∈ δ and theorem [33] states that if L ⊆ Σ is a context-free language, ∗ ti then there exists a regular language R ⊆ Σ that is Parikh- (pi−1, ci−1) −−→(pi, ci). We say that π induces a word w = ∗ equivalent to L, i.e., such that ψ(L) = ψ(R). Hence, such a1a2 . . . am ∈ Σ where ai ∈ Σ∪{ε} and ti = (pi−1, ai, s, pi); we also say that the word w can be read or observed along languages R are also regular abstractions of L; since all one- the sequence π. We call the sequence π: counter languages are context-free, every OCA A has at least one regular language that is Parikh-equivalent to L(A). w • a quasi-run, denoted π = (p0, c0) =⇒A (pm, cm), if none of ti is a test for zero; 2.3 Convention on OCA w To simplify the presentation, everywhere below we focus our • a run, denoted π = (p0, c0) −−→A(pm, cm), if all (pi, ci) ∈ attention on a sublcass of OCA that we call simple one- Q × N. counter automata (simple OCA). A simple OCA is defined We abuse notation and write =⇒w (resp. −−→w ) to mean =⇒w analogously to OCA and is different in the following aspects: w (resp. −−→A) when it is clear from context. For m = 0, (1) there are no zero tests, (2) there is a unique final state, we also use this notation with w = ε. In addition, for any F = {qfinal}, (3) only runs that start from the configuration quasi-run π as above, the sequence of transitions t1, . . . , tm (qinit, 0) and end at the configuration (qfinal, 0) are considered is called a walk from the state p0 to the state pm. accepting. The language of a simple OCA A, also denoted We will concatenate runs, quasi-runs, and walks, using L(A), is the set of words induced by accepting runs. We now the notation π1 ·π2 and sometimes dropping the dot. If π2 is show that this restriction is without loss of generality. a walk and π1 is a run, then π1 · π2 will also denote a run. In For an OCA A = (Q, Σ, q0, δ, F ) and any p, q ∈ Q, define this and other cases, we will often assume that the counter a simple OCA Ap,q def= (Q, Σ, p, δ+, {q}) where δ+ ⊆ δ is the values in π2 are picked or adjusted automatically to match set of all transitions in δ that are not tests for zero. the last configuration of π1. For any simple OCA A, define a sequence of approximants The number m is the length of π, denoted |π|; for a walk, L(n)(A), n ≥ 0: the language L(n)(A) is the set of all words its length is equal to the length of the sequence. All concepts observed along runs of A from (q0, n) to (qfinal, n). and attributes naturally carry over from runs to walks and vice versa. Quasi-runs are not used until further sections; Lemma 1. Let K ∈ N and ♦ ∈ {↑,↓, ψ} be an abstraction. the semantics of OCA is defined just using runs. Assume that there is a polynomial g♦ such that for any w OCA A the following holds: for every Ap,q there is an NFA A run (p0, c0) −−→(pm, cm) is called accepting in A if p,q p,q Bp,q,♦ such that ♦L(A ) ⊆ L(Bp,q,♦) ⊆ ♦(L(K)(A )) (p0, c0) = (q0, 0) where q0 is the initial state of A and pm is and |Bp,q,♦| ≤ g♦(|A|). Then there is a polynomial f such a final state of A, i.e., pm ∈ F . In such a case the word w ♦ is accepted by A; the set of all accepted words is called the that for any A there is an NFA B of size at most f(|A|,K) ♦ language of A, denoted L(A). with L(B ) = ♦(L(A)).
2.2 Regular abstractions Proof (sketch). We use the following two ideas: (i) to com- pute the abstraction of {w} where w = w1 · w2, it suffices A nondeterministic finite automaton with ε-transitions to concatenate abstractions of {w1} and {w2};(ii) for any (NFA) is a one-counter automaton where all transitions K ∈ N, every run of A can be described as interleaving of are tests for zero. Languages of the form L(N ), where N is runs below K and above K. The NFA B♦ is constructed an NFA, are regular. If A is an OCA, then L(A) —a one- as follows: first encode counter values below K using states, counter language— is not necessarily regular. In what fol- and then insert NFA Bp,q,♦ in between (p, n) and (q, n). lows, we consider three regular abstractions of (one-counter) languages: downward closures, upward closures, and Parikh- Restriction to simple OCA is now a consequence of equivalent regular languages. Lemma 1 for K = 0. Let w, w0 ∈ Σ∗. We say that a word w is a subword of a 0 ∗ word w if w = a1 . . . an and there are xi ∈ Σ , 1 ≤ i ≤ n+1, 0 0 3. Upward and Downward Closures such that w = x1a1x2a2 . . . xnanxn+1. We write w w to indicate this. For any language L ⊆ Σ∗, the upward and The standard argument used to bound the length of accept- downward closures of L are the languages ing runs of PDAs (or OCAs) can be adapted easily to show L↑ = {w0 | ∃w ∈ L. w w0} and Theorem 2. There is a polynomial-time algorithm that takes as input an OCA A = (Q, Σ, δ, s, F ) and computes 0 0 L↓ = {w | ∃w ∈ L. w w }, respectively. an NFA with O(|A|3) states accepting L(A)↑. ∗ Any w ∈ Σ defines a function ψ(w):Σ → N, called the Next we show a polynomial time procedure that con- Σ ∗ Parikh image of w (i.e., ψ(w) ∈ N for all w ∈ Σ ). The structs an NFA accepting the downward closure of the lan- value ψ(w)(a) is the number of occurrences of a in w. The guage of any simple OCA. For pushdown automata the
3 2016/1/19 construction involves a necessary exponential blow-up. We K at some point. Any such run may be broken into 3 stages: sketch some observations that lead to our polynomial time the first stage where counter value starts at 0 and remains construction. strictly below K +1, a second stage where it starts and ends Let A = (Q, Σ, δ, s, F ) be a simple OCA and let K = |Q|. at K + 1 and a last stage where the value begins at K and Consider any run ρ of A from a configuration (p, i) to a remains below K and ends at 0 (the 3 stages are connected configuration (q, j). If the value of the counter increases by two transitions, an increment and a decrement). Suppose, (resp. decreases) by at least K in ρ then, it contains a we write the given accepting run as (p, 0) −−→w1 (q, c) −−→w2 (r, 0) segment that can be pumped (or iterated) to increase (resp. where (q, c) is a configuration in the second stage. If a ∈ Σ decrease) the value of the counter. Quite clearly, the word is a letter that may be read in some transition on some read along this iterated run will be a superword of word read walk from q to q. Then, w1aw2 is in L(A) ↓. This is a along ρ. The following lemmas formalize this. direct consequence of the above lemma. It means that in x the configurations in the middle stage we may freely read Lemma 3. Let (p, i) −→(q, j) with j − i > K. Then, there certain letters without bothering to update the counters. is an integer k > 0 such that for each N ≥ 0 there is a run N+1 This turns out to be a crucial step in our construction. To w=y1.(y2) .y3 0 (p, i) −−−−−−−−−−−−→(p , j + N.k) with x = y1y2y3. turn this relaxation idea into a construction, the following 0 0 z 0 0 0 0 seems a natural. Lemma 4. Let (q , j ) −→(p , i ) with j − i > K. Then, We make an equivalent, but expanded version of A. This there is an integer k0 > 0 such that for every N ≥ 0 there is N+1 version has 3 copies of the state space: The first copy is 0 0 0 w=y1(y2) y3 0 0 a run (q , j + N.k ) −−−−−−−−−−−→(p , i ) with z = y1y2y3. used as long as the value of the counter stays below K + 1 and on attaining this value the second copy is entered. The A consequence of these somewhat innocous lemmas is the second copy simulates A exactly but nondeterministically following interesting fact: we can turn a triple consisting of chooses to enter third copy whenever the counter value is two runs, where the first one increases the counter by at least moves from K + 1 to K. The third copy simulates A but K and the second one decreases the counter by at least K, does not permit the counter value to exceed K. For every and a quasi-run that connects them, into a real run provided letter a and state q with a walk from q to q along which a is we are content to read a superword along the way. read on some transition, we add a self-loop transition to the y Lemma 5. Let (p, i) −→x (q, j) =⇒ (q0, j0) −→z (p0, i0), with j − state corresponding to q in the second copy that does not i > K and j0 − i0 > K. Then, there is a run (p, i) −−→w (p0, i0) affect the counter and reads the letter a. This idea has two such that xyz w. deficiencies: first, it is not clear how to define the transition from the second copy to the third copy, as that requires Interesting as this may be, this lemma still relies on knowing that value of the counter is K + 1, and second, the counter value being recorded exactly in all the three this is still an OCA (since the second copy simply faithfully segments in its antecedent and we weaken this next. simulates A) and not an NFA. x z Suppose we bound the value of the counter by some Lemma 6. Let (p, i) −→(q, j),(q, j) −→(p0, i0), with j − i > value U in the second stage. Then we can overcome both K and j0 −i0 > K. Let there be a walk from q to q that reads w 0 0 of these defects and construct a finite automaton. By using y. Then, there is a run (p, i) −−→(p , i ) such that xyz w. a slight generalization of Lemma 6, which allows for the
y simultaneous insertion of a number of walks (or by applying Proof. Let the given walk result in the quasi-run (q, j) =⇒ the Lemma iteratively), we can show that any word accepted (q, j+d) (where d is the net effect of the walk on the counter, by such a finite automaton lies L(A)↓. However, there is no which may be positive or negative). Iterating this quasi-run guarantee that such an automaton will accept every word ym m times yields a quasi-run (q, j) ==⇒ (q, j + m.d), for any in L(A)↓. The second crucial point is that we are able to 2 m ≥ 0. Next, we use Lemma 3 to find a k > 0 such that show that if U ≥ K + K + 1 then every word in L(A) for each N > 0 we have a run (p, i) −−−→xN (q, j + N.k) with is accepted by this 3 stage NFA. We show that for each 0 accepting run ρ in A there is an accepting run in the NFA x xN . Similarly, we use Lemma 4 to find a k > 0 such y 0 reading the same word. The proof is by a double induction, that for each N 0 > 0 we have a run (q, j +N 0.k0) −−−→N (p0, i0) first on the maximum value attained by the counter and with y y 0 . N then on the number of times this value is attained along Now, we pick m and N to be multiples of k0 in such a the run. Clearly, segments of the run where the value of the way that N.k + m.d > 0. This can always be done since k is counter does not exceed K2 + K + 1 can be simulated as positive. Thus, N.k + m.d = N 0.k0 with N 0 > 0. Now we try is. We then show that whenever the counter value exceeds and combine the (quasi) runs (p, i) −−−→xN (q, j + N.k), (q, j + m this number, we can find suitable segments whose net effect y y 0 N.k) ==⇒ (q, j + N.k + m.d) and (q, j + N 0.k0) −−−→N (p0, i0) to on the counter is 0 and which can be simulated using the form a run. We are almost there, as j+N.k+m.d = j+N 0.k0. self-loop transitions added to stage 2 (which do not modify However, it is not guaranteed that this combined quasi-run is the counters), reducing the maximum value of the counter actually a run as the value of the counter may turn negative along the run. Formalizing this gives: ym in the segment (q, j+N.k) ==⇒ (q, j+N.k+m.d). Let −N 00 be Theorem 7. There is a polynomial-time algorithm that the smallest value attained by the counter in this segment. takes as input a simple OCA A = (Q, Σ, δ, s, F ) and com- Then by replacing N by N +N 00.k0 and N 0 by N 0 +N 00.k we putes an NFA with O(|A|3) states accepting L(A)↓. can manufacture a triple which actually yields a run (since the counter values are ≥ 0), completing the proof.
With this lemma in place we can now explain how to 4. Parikh image: Fixed alphabet relax the usage of counters. Let us focus on runs that are The result of this section is the following theorem. interesting, that is, those in which the counter value exceeds
4 2016/1/19 Theorem 8. For any fixed alphabet Σ there is a polynomial- Second and most importantly, it is crucial for the pe- time algorithm that, given as input a one-counter automaton riodic structure of the set that individual “pumpings” and over Σ with n states, computes a Parikh-equivalent NFA. “unpumpings” can be performed independently. That is, sup- pose we can insert a copy of a sub-run σ into π, as above; Note that in Theorem 8 the size of Σ is fixed. The theo- also suppose we can remove from π some other sub-run σ0. rem implies, in particular, that any one-counter automaton What we need to ensure is that, after removing σ0 from π, over Σ with n states has a Parikh-equivalent NFA of size the obtained run π0 will have the property that we can still poly (n), where poly is a polynomial of degree bounded Σ Σ insert a σ in it, as in the original run π. In general, of course, by f(|Σ|) for some computable function f. this does not have to be the case: even for finite-state ma- We now provide the intuition behind the proof of Theo- chines, removal of loops can lead to removal of individual rem 8. Our key technical contribution is capturing the struc- control states, which can, in turn, prevent the insertion of ture of the Parikh image of the language L(A). |Σ| other loops (in our case the automaton also has a counter Recall that a set A ⊆ N is called linear if it is of def that must always stay non-negative). To deal with this phe- the form Lin(b; P ) = {b + λ1p1 + ... + λrpr | λ1, . . . , λr ∈ nomenon, we introduce the concept of “availability” (Defi- |Σ| N, p1, . . . , pr ∈ P } for some vector b ∈ N and some nition 11). Essentially, a “pumpable” part of the run—i.e., |Σ| finite set P ⊆ N ; this vector b is called the base and a “split walk”—defines a direction (Definition 10); we say d vectors p ∈ P periods. A set S ⊆ N is called semilinear that a direction is available at the run π if it is possible to if it is a finite union of linear sets, S = ∪i∈I Lin(bi; Pi). insert its copy into π. Thus, when doing “unpumping”, we Semilinear sets were introduced in the 1960s and have since need to make sure that the set of available directions does received a lot of attention in formal language theory and not change: we call such unpumpings safe (Definition 13). its applications to verification. They are precisely the sets We show that long accepting runs can always be safely un- definable in Presburger arithmetic, the first-order theory of pumped (Lemma 14), which will lead us (Lemma 15) to the natural numbers with addition. Intuitively, semilinear sets semilinear representation that we sketched at the beginning are a multi-dimensional analogue of ultimately periodic sets of this subsection. in N. For our purposes, of most importance is the following We now describe the formalism behind our arguments. way of stating the Parikh theorem [33]: the Parikh image of Definition 10 (direction). A direction is a pair of walks α any context-free language is a semilinear set; in particular, so and β, denoted d = hα, βi, such that: is the Parikh image of any one-counter language, ψ(L(A)). Our proof of Theorem 8 captures the periodic structure • α begins and ends in the same control state, of this set ψ(L(A)). More precisely, we prove polynomial • β begins and ends in the same control state, upper bounds on the number of linear sets in the semilinear • 0 < |α| + |β| < n(2n2 + 3)(n3) + 1, representation of ψ(L(A)) and on the magnitude of periods • 0 ≤ effect(α) ≤ n3, and base vectors. Since converting such a semilinear repre- • effect(α) + effect(β) = 0, sentation into a polynomial-size NFA is easy, these bounds • if effect(α) = 0, then either |α| = 0 or |β| = 0. (subsection 4.1) entail the existence of an appropriate NFA. After this, we show how to compute, in time polynomial in The direction is of the first kind if effect(α) = 0, and of the |A|, this semilinear representation from A (subsection 4.2). second kind otherwise. 4.1 Semilinear representation of ψ(L(A)) One can think of a direction as a pair of short loops with zero total effect on the counter. Pairs of words induced by We now explain where the periodic structure of the set these loops are sometimes known as iterative pairs. Direc- ψ(L(A)) comes from. Consider an individual accepting run tions of the first kind are essentially just individual loops; in π and assume that one can factorize it as π = ρ · σ · τ so a direction of the second kind, the first loop increases and that for any k ≥ 0 the run ρ · σk · τ is also accepting. Values the second loop decreases the counter value (this restric- k > 0 correspond to pumping the run “up”, and the value tion, however, only concerns the total effects of α and β; i.e., k = 0 corresponds to “unpumping” the infix σ. If we apply proper prefixes of α can have negative effects and proper pre- this “unpumping” to π several times (each time taking a fixes of β positive effects). The condition that effect(α) ≤ n3 new appropriate factorization of shorter and shorter runs), is a pure technicality and is only put in to make some aux- then the remaining part eventually becomes small (short). iliary statements in the proof more laconic; in contrast, the Its Parikh image will be a base vector, and the Parikh images upper bound |α| + |β| < n(2n2 + 3)(n3) + 1 is crucial (al- of different infixes σ will be period vectors of a linear set in though the choice of larger polynomial is, of course, possible, the semilinear representation. at the expense of an increase in the obtained upper bound However, this strategy faces several obstacles. First, the on the size of NFA). overall reasoning should work on the level of the whole au- tomaton, as opposed to individual runs; this means that we Definition 11 (availability of directions). Suppose π is need to rely on a form of a pumping lemma to factorize long an accepting run. A direction d = hα, βi is available at runs appropriately. The pumping lemma for one-counter lan- π if there exists a factorization π = π1 · π2 · π3 such that 0 guages involves, instead of individual infixes σ, their pairs π = π1 · απ2β · π3 is also an accepting run. We write π + d 0 (σ1, σ2), so that the entire run factorizes as π = ρ·σ1 ·υ·σ2 ·τ, to refer to π . and runs π = ρ · σk · υ · σk · τ are accepting for all k ≥ 0. 1 2 Note that for a particular run π there can be more than We incorporate this into our argument, talking about split one factorization of π into π , π , π such that π · απ β · π runs (Definition 9). Here and below, for any run ζ, effect(ζ) 1 2 3 1 2 3 is an accepting run. In such cases the direction d can be denotes the effect of ζ on the counter, i.e., the difference introduced at different points inside π. We only use the between the final and initial counter value along ζ. notation π + d to refer to a single run π0 obtained in this Definition 9 (split run). A split run is a pair of runs way, without specifying a particular factorization of π. (σ1, σ2) such that effect(σ1) ≥ 0 and effect(σ2) ≤ 0. Denote by avail(π) the set of all directions available at π.
5 2016/1/19 Lemma 12 (monotonicity of availability). If π is an ac- We now explain why this algorithm works in polynomial cepting run of an OCA and d is a direction available at π, time. Recall that the size of the alphabet, |Σ|, is fixed. Note then avail(π) ⊆ avail(π + d). that by Definition 10 the total length of runs αi and βi in a direction d = hα , β i is at most polynomial in n; Definition 13 (unpumping). A run π0 can be unpumped if i i i similarly, equation (1) in Lemma 15 only refers to accepting there exist a run π and a direction d such that π0 = π + d. runs π of polynomial length. Therefore, all the components If additionally avail(π0) = avail(π), then we say that π0 can of all potential Parikh images v and v , . . . , v are upper- be safely unpumped. 1 r bounded by polynomials in n of fixed degree. The number 0 |Σ| Note that avail(π ) is always a superset of avail(π) by of such vectors in N is polynomial, and so is the number of Lemma 12. The key part of our argument is the proof that, appropriate tuples (v, v1, . . . , vr), r ≤ |Σ|. It now remains to indeed, every long run can be unpumped in a safe way: argue that each tuple can be processed in polynomial time. Lemma 14 (safe unpumping lemma). Every accepting run Lemma 16. For every Σ there is a polynomial-time al- π0 of A of length greater than n2((2n2 + 3)(n3))3 can be gorithm that, given a simple OCA A over Σ and vectors Σ safely unpumped. v, v1,..., vr ∈ N , 0 ≤ r ≤ |Σ|, with all numbers written in unary, decides if A has an accepting run π and directions Proof (sketch). We consider two cases, depending on whether d1, . . . , dr ∈ avail(π) with ψ(π) = v and ψ(di) = vi for all i. the height (largest counter value) of π0 exceeds a certain polynomial in n. The strategy of the proof is the same for Lemma 16 is based on the following building block: both cases (although the details are somewhat different). Lemma 17. For every Σ there is a polynomial-time al- We first show that sufficiently large parts (runs or split gorithm that, given a simple OCA A over Σ, two config- runs) of π0 can always be unpumped (as in standard pump- Σ urations (q1, c1) and (q2, c2) and a vector v ∈ N with all ing arguments). We notice that for such an unpumping to numbers written in unary, decides if A has a run π = be unsafe, it is necessary that the part contain a configura- (q1, c1) −→(q2, c2) with ψ(π) = v. tion whose removal shrinks the set of available directions—a reason for non-safety; this important configuration cannot The algorithm of Lemma 17 solves a version of the appear anywhere else in π0. We prove that the total number Parikh membership problem for OCA. It constructs a multi- of important configurations is at most poly(n). As a result, if dimensional table by dynamic programming: for all pairs of 0 0 0 0 0 0 0 we divide the run π into sufficiently many sufficiently large configurations (q1, c1), (q2, c2) with bounded c1, c2 and all 0 Σ parts, at least one of the parts will contain no important vectors v ∈ N of appropriate size, it keeps the information 0 0 0 0 0 configurations and, therefore, can be unpumped safely. whether A has a run (q1, c1) −→(q2, c2) with Parikh image v . This completes our description of how to compute, from Lemma 14 ensures that we faithfully represent the semi- an OCA A, a semilinear representation of ψ(L(A)). Trans- linear structure of the Parikh image of the entire language forming this representation into an NFA is a simple exercise. when we take Parikh images of short runs as base vectors and Parikh images of available directions as period vectors 5. Parikh image: Unbounded alphabet in the semilinear representation: In this section we describe an algorithm to construct an NFA Lemma 15. For any OCA A, it holds that Parikh-equivalent to an OCA A without assumptions |Σ|. [ O(log K) ψ(L(A)) = Lin(ψ(π); ψ(avail(π))), (1) The NFA has at most O(|Σ|K ) states where K = |A|, poly(K,|Σ|) |π| ≤ s(n) a significant improvement over O(2 ) for PDA. We establish this result in two steps. In the first step, where the union is taken over all accepting runs of A of 2 2 3 3 we show that we can focus our attention on computing length at most s(n) = n ((2n + 3)(n )) . Parikh-images of words recognized along reversal bounded Finally, to keep the representation of the Parikh image runs. A reversal in a run occurs when the OCA switches small, we rely on a Carathéodory-style argument ensuring to incrementing the counter after a non-empty sequence of that the number of the linear sets in the semilinear repre- decrements (and internal moves) or when it switches to sentation needs to grow only polynomially in the size of the decrementing the counter after a non-empty sequence of original automaton, while the sets of period vectors is also increments (and internal moves). For a number R, a run kept small. For this (and only this) part of the argument, is R reversal bounded, if the number of reversals along the we need the alphabet size, |Σ|, to be fixed. run is ≤ R. Let us use LR(A) to denote the set of words accepted by A along runs with at most R reversals. 4.2 Computing the semilinear representation We construct a new polynomial size simple OCA from Lemma 15 suggests the following algorithm for computing A and show that we can restrict our attention to runs with the semilinear representation of ψ(L(A)). Enumerate all at most R reversals of this OCA, where R is a polynomial potential Parikh images v of small accepting runs π of A in K. In the second step, from any simple OCA A with K states and any integer R we construct an NFA of size and all potential Parikh images of directions. For every v O(log(R)) and for every tuple of r ≤ |Σ| vectors v , . . . , v that could O(K ) whose Parikh image is LR(A). Combination 1 r O(logK) be Parikh images of directions in A, check if A indeed has of the two steps gives a O(K ) construction. an accepting run π and directions d , . . . , d available at π 1 r 5.1 Reversal bounding such that ψ(π) = v and ψ(d)i = vi for all i (Parikh images of runs and directions are defined as Parikh images of words We establish that, up to Parikh-image, it suffices to consider induced by them). Whenever the answer is yes, take a linear runs with 2K2 + K reversals. We use two constructions: set Lin(v; {v1, . . . , vr}) into the semilinear representation of one that eliminates large reversals (think of a waveform) ψ(L(A)). Terminate when all tuples (v, v1, . . . , vr) have been and another that eliminates small reversals (think of the considered for all r ≤ |Σ|. noise on a noisy waveform). For the large reversals, the idea
6 2016/1/19 used is the following: we can reorder the transitions used With these two lemmas we have enough information along a run, hence preserving Parikh-image, to turn it into about A[D] and its relationship with A. We need a bit more one with few large reversals (a noisy waveform with few terminology to proceed. We say that a run of is an D≤ run reversals). The key idea used is to move each simple cycle at (resp. D≥ run) if the value of the counter is bounded from state q with a positive (resp. negative) effect on the counter above (resp. below) by D in every configuration encountered to the first (resp. last) occurrence of the state along the along the run. We say that a run of A is an D> run if it is of run. To eliminate the smaller reversals (noise), the idea is to the form (p, D) −−→w (q, D), it has at least 3 configurations and maintain the changes to the counter in the state and transfer the value of the counter at every configuration other than the it only when necessary to the counter to avoid unnecessary first and last is > D. Consider any run from a configuration reversals. (p, 0) to (q, 0) in A. Once we identify the maximal D> sub-
counter runs, what is left is a collection of D≤ subruns. w
noise Let ρ = (p, c) −−→(q, d) be a run of A with c, d ≤ D.
noise noise If ρ is a D run then its D-decomposition is ρ. Other- large reversal ≤ time wise, its D-decomposition is given by a sequence of runs Consider a run of A starting at a configuration (p, c) 0 0 0 0 0 0 ρ0, ρ0, ρ1, ρ1 . . . ρn−1, ρn with ρ = ρ0.ρ0.ρ1.ρ1 . . . .ρn−1.ρn, and ending at some configuration (q, d) such that the value 0 where each ρi is a D≤ run and each ρi is a D> run for of the counter e in any intermediate configuration satisfies 0 ≤ i ≤ n. Notice, that some of the ρ ’s may be trivial. c − D ≤ e ≤ c + D (where D is some positive integer). We i Since the D> subruns are uniquely identified this definition refer to such a run as an D-band run. Reversals along such a is unambiguous. We refer to the ρ0 ’s (resp. ρ s) as the D run are not important and we get rid of them by maintaining i i > (resp. D≤) components of ρ. the (bounded) changes to the counter within the state. Observe that the D runs of A can be easily simulated We construct a simple OCA A[D] as follows: its states are ≤ by an NFA. Thus we may focus on transforming the D> Q∪Q1 ∪Q2 where Q1 = Q×[−D,D] and Q2 = [−D,D]×Q. runs, preserving just the Parikh-image, into a suitable form. All transitions of A are transitions of A[D] as well and thus For D,M ∈ N, we say that a D> run ρ is a (D,M)-good run using Q it can simulate any run of A faithfully. From any (think noisy waveform with few reversals) if there are runs state q ∈ Q the automaton may move nondeterministically σ1, σ2 . . . , σn, σn+1 and iterated D-band runs ρ1, ρ2, . . . , ρn to (q, 0) in Q1. The states in Q1 are used to simulate D-band such that ρ = σ1ρ1σ2ρ2 . . . σnρnσn+1 and |σ1|+...+|σn+1|+ runs of A without altering the counter and by keeping track 2.n ≤ M. Using Lemma 18 and that it is a D run we show of the net change to the counter in the second component > w of the state. From a state (q, j) in Q1, A[D] is allowed Lemma 20. Let (p, D) −−→(q, D) be an (D,M)-good run of to nondeterministically move to (j, q) indicating that it will A. Then, there is a run (p, 0) −−→w (q, 0) in A[D] with atmost now transfer the (positive or negative) value j to the counter. M reversals. After completing the transfer it reaches a state (0, q) from where it can enter the state q via an internal move to So far we have not used the fact that we can ignore continue the simulation of A. the ordering of the letters read along a run (since we are Observe that there are no reversals in the simulation and only interested in the Parikh-image of L(A)). We show it involves only increments (if d > c) or only decrements (if that for any run ρ of A we may find another run ρ0 of A, d < c). Actually this automaton A[D] does even better. that is equivalent up to Parikh-image, such that every D> Concatenation of D-band runs is often not an D-band run component in the D-decomposition of ρ0 is (D,M)-good, but the idea of reversal free simulation extends to certain where M and D are polynomially related to K. w 2 concatenations. We say that a run (p0, c0) −−→(pn, cn) is an We fix D = K in what follows. We take M = 2K +K for increasing (resp. decreasing) iterated D-band run if it can reasons that will become clear soon. We focus our attention be decomposed as on some D> component ξ of ρ which is not (D,M)-good. Let X ⊆ Q be the set of states of Q that occur in at w1 w2 wn (p0, c0) −−→(p1, c1) −−→ ... (pn−1, cn−1) −−→(pn, cn) least two different configurations along ξ. For each of the states in X we identify the configuration along ξ where it wi+1 where each (pi, ci) −−−−→(pi+1, ci+1) is an D-band run and occurs for the very first time and the configuration where ci ≤ ci+1 (resp. ci ≥ ci+1). We say it is an iterated D-band it occurs for the last time. There are at most 2|X|(≤ 2K) run if it is an increasing or decreasing iterated D-band run. such configurations and these decompose the run ξ into a concatenation of 2|X| + 1(≤ 2K + 1) runs ξ = ξ1.ξ2 . . . ξm w Lemma 18. Let (p, c) −−→(q, d) be an increasing (resp. de- where ξi, 1 < i < m is a segment connecting two such w creasing) D-band run in A. Then, there is a run (p, c) −−→(q, d) configurations. Now, suppose one of these ξi’s has length K in A[D] along which the counter value is never decremented or more. Then it must contain a sub-run (p, c) −→(p, d) with (resp. incremented). at most K moves, for some p ∈ X (so, this is necessarily a K-band run). If d − c ≥ 0 (resp. d − c < 0), then we transfer While clearly L(A) ⊆ L(A[D]), the converse is not in this subrun from its current position to the first occurrence general true as along a run of A[D] the real value of the (resp. last occurrence) of p in the run. This still leaves a valid 0 counter, i.e. the current value of the counter plus the offset run ξ since ξ begins with a K as counter value and |ξi| ≤ K. available in the state, may be negative, leading to runs that Moreover ξ and ξ0 are equivalent upto Parikh-image. 0 are not simulations of runs of A. The trick that helps us If this ξ continues to be a K> run then we again examine get around this is to relate runs of A[D] to A with a shift in if it is (K,M)-good and otherwise, repeat the operation counter values. The following lemma summarizes this shifted described above. As we proceed, we continue to accumulate relationship: a increasing iterated K-band run at the first occurrence of each state and decreasing iterated K-band run at the w Lemma 19. Let p, q ∈ Q. If (p, 0) −−→(q, 0) is a run in A[D] last occurrence of each state. We also ensure that in each then (p, D) −−→w (q, D) is a run in A. iteration we only pick a segment that does NOT appear in
7 2016/1/19 these 2|X| iterated K-bands. Thus, these iterations will stop Unfortunately, such a naive simulation would not work if when either the segments outside the iterated K-bands are the run had more reversals. For then the ith increment in the all of length < K and we cannot find any suitable segment simulation from the left need not necessarily correspond to to transfer, or when the resulting run is no longer a K> run. the ith decrement in the reverse simulation from the right. In the first case, we must necessarily have a (K, 2K2 + K)- In this case, the run ρ can be written as follows: good run. In the latter case, the resulting run decomposes τ1 0 0 as usual in K≤ and K> components, and we have that every (p, 0)ρ1(p1, c) −−→(p1, c + 1)ρ3(p2, c + 1) K component is strictly shorter than ξ, allowing us to use τ > −−→2 (p , c)ρ (q , c)ρ (q, 0) an inductive argument to prove the following: 2 4 1 5 w Lemma 21. Let ρ = (p, 0) −−→(q, 0) be any run in A. Then, where, the increment τ1 corresponds to the decrement τ2 and w0 all the increments in ρ are exactly matched by decrements there is a run ρ0 = (p, 0) −−→(q, 0) of A with ψ(w) = 1 in ρ . Notice that the increments in the run ρ are exactly ψ(w0) such that every K component ξ in the canonical 5 3 > matched by the decrements in that run and similarly for decomposition of ρ0 is (K, 2K2 + K)-good. ρ4. Thus, to simulate such a well-matched run from p to pq rev Let B , p, q ∈ Q, be NFA Parikh-equivalent to L2K2+K q, after simulating ρ1 and ρ5 simultaneously matching (A[K]p,q) where A[K]pq is A[K] with p as the only initial corresponding increments and decrements, and reaching the and q as the only final state. As a consequence of Lemmas state p1 on the left and q1 on the right, we can choose to 21,20 and 19, we can obtain an NFA B such that ψ(L(B)) = now simulate matching runs from p1 to p2 and from p2 to q1 ψ(L(A)). The number of states in the automaton B is (for some p2). Our idea is to choose one of these pairs and P pq 2 simulate it first, storing the other in a stack. We call such p,q∈Q |B | + K . What remains to be settled is the size of the automata Bpq. This problem is solved in the next pairs obligations. The simulation of the chosen obligation subsection and the solution (see Lemma 23) implies that may produce further such obligations which are also stored that the size of Bpq is bounded by O(|Σ|KO(logK)). Thus we in the stack. The simulation of an obligation succeeds when have the state reached from the left and right simulations are identical, and at this point we we may choose to close this Theorem 22. There is an algorithm, which given an OCA simulation and pick up the next obligation from the stack with K states and alphabet Σ, constructs a Parikh-equivalent or continue simulating the current pair further. The entire NFA with O(|Σ|.KO(log K)) states. simulation terminates when no obligations are left. Thus, to go from a single reversal case to the general case, we have 5.2 Parikh image under reversal bounds introduced a stack into which states of the NFA used for Here we show that, for an OCA A, with K states and whose the single reversal case are stored. This can be formalized alphabet is Σ, and any R ∈ N, an NFA Parikh-equivalent to to show that the resulting PDA is Parikh-equivalent to A. O(logK) LR(A) can be constructed with size O(|Σ|.K ). As a But a little more analysis shows that there is a simulating matter of fact, this construction works even for pushdown run where the height of the stack is bounded by log(R) where systems and not just OCAs. R is the number of reversals in the original run. Thus, to Let A be a simple OCA. It will be beneficial to think simulate all runs of A with at most R reversals, we may of the counter as a stack with a single letter alphabet, with bound the stack height of the PDA by log(R). pushes for increments and pops for decrements. Then, in any We show that if the stack height is h then we can choose run from (p, 0) to (q, 0), we may relate an increment move to simulate only runs with at most 2log(R)−h reversals for uniquely with its corresponding decrement move, the pop the obligation on hand. Once we show this, notice that when that removes the value inserted by this push. h = log(R) we only need to simulate runs with 1 reversal Now, consider a one reversal run ρ of A from say (p, 0) which can be done without any further obligations being to (q, 0) involving two phases, a first phase ρ1 with no decre- generated. Thus, the overall height of the stack is bounded ment moves and a second phase ρ2 with no increment moves. by log(R). Now, we explain why the claim made above holds. Such a run can be simulated, up to equivalent Parikh image Clearly it holds initially when h = 0. Inductively, whenever (i.e. upto reordering of the letters read along the run) by we split an obligation, we choose the obligation with fewer an NFA as follows: simultaneously simulate the first phase reversals to simulate first, pushing the other obligation onto (ρ1) from the source and the second phase, in reverse or- the stack. Notice that this obligation with fewer reversals is rev rev der (ρ2 ), from the target. (The simulation of ρ2 uses the guaranteed to contain at most half the number of reversals of transitions in the opposite direction, moving from the target the current obligation (which is being split). Thus, whenever of the transition to the source of the transition). The sim- the stack height increases by 1, the number of reversals to ulation matches increment moves of ρ1 against decrement be explored in the current obligation falls at least by half rev moves in ρ2 (more precisely, matching the ith increment as required. On the other hand, an obligation (p, q) that rev ρ1 with the ith decrement in ρ2 ) while carrying out moves lies in the stack at position h from the bottom, was placed that do not alter the counters independently in both direc- there while executing (earlier) an obligation (p0, q0) that tions. The simulation terminates (or potentially terminates) only required 2k−h+1 reversals. Since the obligation (p, q) 0 0 when a common state, signifying the boundary between ρ1 contributes only a part of the obligation (p , q ), its number k−h+1 and ρ2 is reached from both ends. of reversals is also bounded by 2 . And when (p, q) is The state space of such an NFA will need pairs of states removed from the stack for simulation, the stack height is from Q, to maintain the current state reached by the forward h − 1. Thus, the invariant is maintained. Once we have this and backward simulations. Since, only one letter of the input bound on the stack, for a given R, we can simulate it by an can be read in each move, we will also need two moves to exponentially large NFA. This yields the following lemma: simulate a matched increment and decrement and will need states of the form Q × Q × Σ for the intermediate state that Lemma 23. There is a procedure that takes a simple OCA lies between the two moves. A with K states and whose alphabet is Σ, and a number
8 2016/1/19 A is acyclic if it has no proper cycles, i.e. if all cycles consist a |n a |−n a |n n+1 1,n 2,n 3,n an,n|(−1) n solely of loops. Equivalently, an OCA is acyclic if there is a ...... n+1 partial order ≤ on the set of states such that if a transition a1,2|2 a2,2|−2 a3,2|2 an,2|(−1) 2 leads from a state p to q, then p ≤ q. n+1 a1,1|1 a2,1|−1 a3,1|1 an,1|(−1) A transition (p, a, s, q) is called positive (negative) if s > 0 c1,2 c2,3 q1 q2 q3 ··· qn (s < 0). We say that a walk contains k reversals if it c3,n has a scattered subword of length k + 1 in which positive c1,3 c2,n and negative transitions alternate. An (extended) OCA is c1,n called (r-)reversal-bounded if none of its walks contains r + 1 reversals. Observe that an acyclic (extended) OCA is Figure 1. The one-counter automaton Hn reversal-bounded if and only if on each state, there are either no positive transitions or no negative transitions. We call such automata RBA (reversal-bounded acyclic automata). R ∈ N and returns an NFA Parikh-equivalent to LR(A) of Recall that we have seen in section 5.1 that constructing O(log(R)) size O(|Σ|.(RK) ). Parikh-equivalent NFAs essentially reduces to the case of reversal-bounded simple OCA. The first construction here 5.3 Completeness result takes a reversal-bounded automaton and decomposes it into In this section, we present a simple sequence of OCA that an RBA and a regular substitution. This means, if we is complete with respect to small Parikh-equivalent NFAs. can find Parikh-equivalent OCA for RBAs, we can do so This means, if the OCA in this sequence have polynomial- for arbitrary OCA: Given an NFA for the RBA, we can size Parikh-equivalent NFAs, then all OCA have polynomial- replace every letter by the finite automaton specified by size Parikh-equivalent NFAs. the substitution. Here, the size of the substitution σ is the It will be convenient to slightly extend the definition of maximal number of states of an automaton specified for a OCA. An extended OCA is defined as an OCA, but in its language σ(a), a ∈ Σ. transition (p, a, s, q), the entry s can assume any integer Lemma 25. Given an r-reversal-bounded simple OCA A (in addition to z). Of course here, the number of states is 5 not an appropriate measure of size. Therefore, the size of of size n, one can construct an RBA B of size 6n (r + 1) a transition t = (p, a, s, q) of A is |t| = max(0, |s| − 1) if and a regular substitution σ of size n(n + 1) such that ψ(σ(L(B))) = ψ(L(A)). s ∈ Z and 0 if s = z. If A has n states, then we define P its size is |A| = n + t∈δ |t|. Given an extended OCA of We prove this lemma by showing that runs of reversal- size n, one can clearly construct an equivalent OCA with n bounded simple OCA can be ‘flattened’: Each run can be states. Furthermore, if one consideres an (ordinary) OCA as turned into one with Parikh-equivalent input that consists an extended OCA, then its size is the number of states. of a skeleton of polynomial length in which simple cycles The complete sequence (Hn)n≥1 of automata consists of are inserted flat, i.e. without nesting them. The RBA B extended OCA and is illustrated in Figure 1. The automaton simulates the skeleton and has self-loop which are replaced Hn has n states, q1, . . . , qn. On each qi and for each k ∈ by σ with a regular language that simulates simple cycles. i+1 [1, n], there is a loop reading ai,k and adding (−1) · k to In the next construction of our proof (Lemma 27), we the counter. Moreover, for i, j ∈ [1, n] with i < j, there is employ a combinatorial fact. A Dyck sequence is a sequence a transition reading ci,j that does not use the counter. For Pk x1, . . . , xn ∈ Z such that i=1 xi ≥ 0 for every k ∈ [1, n]. each k ∈ [1, n], Hn has n transitions of size k−1. Since it has We call a subset I ⊆ [1, n] removable if removing all xi, Pn 1 n states, this results in a size of n+ k=1(k−1) = 2 n(n+1). i ∈ I, from the sequence yields again a Dyck sequence and The result of this section is the following. P Pn i∈I xi = i=1 xi. We call the sequence r-reversal-bounded Theorem 24. There are polynomials p and q such that the if there are at most r alternations between positive numbers following holds. and negative numbers.
1. If for each n, there is a Parikh-equivalent NFA for Hn Lemma 26. Let N ≥ 0 and x1, . . . , xn be an r-reversal- with h(n) states, then for every OCA of size n, there is bounded Dyck sequence with xi ∈ [−N,N] for each i ∈ [1, n] P a Parikh-equivalent NFA with at most q(h(p(n))) states. such that i=1 xi ∈ [0,N]. Then it has a removable subset 2 2. If there is an algorithm that computes a Parikh-equivalent I ⊆ [1, n] with |I| ≤ 2r(2N + N). NFA for Hn in time O(h(n)), then one can compute We now want to make sure that the self-loops on our a Parikh-equivalent NFA for arbitrary OCA in time states are the only transitions that use the counter. Note O(q(h(p(n)))). that this is a feature of Hn. An RBA is said to be loop- Explicitly, we only prove the first statement and keep the counting if its loops are the only transitions that use the analogous statements in terms of time complexity implicit. counter, i.e. all other transitions (p, a, s, q) have s = 0. Our proof consists of three steps (Lemmas 25, 27, and 28). Lemma 27. Given an RBA A, one can construct a loop- Intuitively, each of them is one algorithmic step one has to counting RBA B of polynomial size such that L(A) ⊆ carry out when constructing a Parikh-equivalent NFA for a L(B) ⊆ L (A) for a polynomially bounded K. given OCA. (K) For the first step in our proof, we need some terminology. Here, the idea is to add a counter that tracks the counter Let A = (Q, Σ, δ, q0,F ) be an extended OCA. Recall that a actions of non-loop transitions. However, in order to show 0 0 word (p1, a1, s1, p1) ··· (pn, an, sn, pn) over δ is called a walk that the resulting automaton can still simulate all runs while 0 if pi = pi+1 for every i ∈ [1, n−1]. The walk u is called a p1- respecting its own counter (i.e. it has to reach zero in the 0 cycle (or just cycle) if pn = p1. If, in addition, i 6= j implies end and cannot drop belo zero), we use Lemma 26. It allows pi 6= pj , then u is called simple. A cycle as above is called us to ‘switch’ parts of the run so as not to use B’s counter, proper if there is some i ∈ [1, n] with pi 6= p1. We say that but the internal one in the state. Note that according to
9 2016/1/19 Lemma 1, it suffices to construct Parikh-equivalent NFAs [17] P. Ganty and R. Majumdar. Algorithmic verification of that fulfill the approximation relation in the lemma here. asynchronous programs. ACM Trans. Program. Lang. Syst., We are now ready to reduce to the NFA Hn. 34(1):6:1–6:48, May 2012. ISSN 0164-0925. [18] H. Gruber, M. Holzer, and M. Kutrib. More on the size Lemma 28. Given a loop-counting RBA A of size n, one of higman-haines sets: Effective constructions. In MCU’07, can construct a regular substitution σ of size at most 2 such volume 4664 of LNCS, pages 193–204, 2007. that ψ(σ(L(H2n+2))) = ψ(L(A)). [19] P. Habermehl, R. Meyer, and H. Wimmel. The downward- Here, roughly speaking, we embed the partial order on closure of Petri net languages. In ICALP’10, volume 6199 of LNCS, pages 466–477, 2010. the set of states into the one in H2n+2. Then, the substi- [20] M. Hague and A. W. Lin. Synchronisation- and reversal- tution σ replaces each symbol in H2n+2 by the outputs of the correponding transition in A. Here, we have to deal with bounded analysis of multithreaded programs with counters. In CAV’12, volume 7358 of LNCS, pages 260–276, 2012. the fact that in A, there might be loops that do not read [21] M. Hague, J. Kochems, and C. L. Ong. Unboundedness and input, but those do not exist in H2n+2. However, we can replace the symbols on non-loops by regular languages so as downward closures of higher-order pushdown automata. In POPL’16, pages 151–163, 2016. to produce the output of their neighboring loops. [22] G. Higman. Ordering by divisibility in abstract algebras. Proc. London Math. Soc. (3), 2(7), 1952. References [23] J. Hoenicke, R. Meyer, and E. Olderog. Kleene, rabin, and [1] P. A. Abdulla, M. F. Atig, and J. Cederberg. Analysis of scott are available. In CONCUR’10, pages 462–477, 2010. message passing programs using SMT-solvers. In ATVA’13, [24] D. T. Huynh. The complexity of equivalence problems for volume 8172 of LNCS, pages 272–286, 2013. commutative grammars. Information and Control, 66(1/2): 103–121, 1985. . [2] P. A. Abdulla, M. F. Atig, R. Meyer, and M. S. Salehi. What’s decidable about availability languages? In [25] E. Kopczynski and A. W. To. Parikh images of grammars: FSTTCS’15, volume 45 of LIPIcs, pages 192–205, 2015. Complexity and applications. In LICS’10, pages 80–89, 2010. . [3] R. Alur and P. Černý. Streaming transducers for algorith- mic verification of single-pass list-processing programs. In [26] S. La Torre, P. Madhusudan, and G. Parlato. A robust class POPL’11, pages 599–610, 2011. of context-sensitive languages. In LICS’07, pages 161–170, 2007. . [4] M. F. Atig, A. Bouajjani, and T. Touili. On the reacha- bility analysis of acyclic networks of pushdown systems. In [27] S. La Torre, M. Napoli, and G. Parlato. Scope-bounded CONCUR’08, volume 5201 of LNCS, pages 356–371, 2008. pushdown languages. In DLT’14, volume 8633 of Lecture Notes in Computer Science, pages 116–128, 2014. . [5] M. F. Atig, A. Bouajjani, and T. Touili. Analyzing asyn- [28] S. La Torre, A. Muscholl, and I. Walukiewicz. Safety of chronous programs with preemption. In FSTTCS’08, vol- parametrized asynchronous shared-memory systems is al- ume 2 of LIPIcs, pages 37–48, 2008. most always decidable. In CONCUR’15, volume 42 of [6] M. F. Atig, A. Bouajjani, and S. Qadeer. Context-bounded LIPIcs, pages 72–84, 2015. analysis for concurrent programs with dynamic creation of [29] P. Lafourcade, D. Lugiez, and R. Treinen. Intruder deduction threads. Logical Methods in Computer Science, 7(4), 2011. for AC -like equational theories with homomorphisms. In [7] M. F. Atig, A. Bouajjani, K. N. Kumar, and P. Saivasan. On RTA’05, pages 308–322, 2005. bounded reachability analysis of shared memory systems. In [30] M. Latteux. Langages à un compteur. J. Comput. Syst. Sci., FSTTCS’14, volume 29 of LIPIcs, pages 611–623, 2014. 26(1):14–33, 1983. [8] G. Bachmeier, M. Luttenberger, and M. Schlund. Finite au- [31] Z. Long, G. Calin, R. Majumdar, and R. Meyer. Language- tomata for the sub- and superword closure of CFLs: Descrip- theoretic abstraction refinement. In FASE’12, volume 7212 tional and computational complexity. In LATA’15, volume of LNCS, pages 362–376, 2012. 8977 of LNCS, pages 473–485, 2015. [32] R. Mayr. Undecidable problems in unreliable computations. [9] S. Böhm, S. Göller, and P. Jancar. Equivalence of determin- Theor. Comput. Sci., 297(1-3):337–354, 2003. istic one-counter automata is NL-complete. In STOC’13, [33] R. J. Parikh. On context-free languages. J. ACM, 13(4): pages 131–140, 2013. . 570–581, Oct. 1966. [10] C. Chitic and D. Rosu. On validation of XML streams using [34] K. Sen and M. Viswanathan. Model checking multithreaded finite state machines. In WebDB’04, pages 85–90, 2004. programs with asynchronous atomic methods. In CAV’14, [11] B. Courcelle. On constructing obstruction sets of words. volume 4144 of LNCS, pages 300–314, 2006. Bulletin of the EATCS, 44:178–186, 1991. [35] L. G. Valiant and M. Paterson. Deterministic one-counter [12] J. Duske and R. Parchmann. Linear indexed languages. automata. J. Comput. Syst. Sci., 10(3):340–350, 1975. . Theor. Comput. Sci., 32:47–60, 1984. . [36] J. van Leeuwen. Effective constructions in well-partially- [13] J. Esparza and P. Ganty. Complexity of pattern-based ordered free monoids. Discrete Mathematics, 21(3):237–252, verification for multithreaded programs. In POPL’11, pages 1978. 499–510, 2011. [37] K. N. Verma, H. Seidl, and T. Schwentick. On the complexity [14] J. Esparza, P. Ganty, S. Kiefer, and M. Luttenberger. of equational horn clauses. In CADE-20, volume 3632 of Parikh’s theorem: A simple and direct automaton construc- LNCS, pages 337–352, 2005. tion. Inf. Process. Lett., 111(12):614–619, 2011. [38] G. Zetzsche. An approach to computing downward closures. [15] J. Esparza, P. Ganty, and T. Poch. Pattern-based verification In ICALP’15, volume 9135 of LNCS, pages 440–451, 2015. for multithreaded programs. ACM Trans. Program. Lang. [39] G. Zetzsche. Computing downward closures for stacked Syst., 36(3):9:1–9:29, 2014. counter automata. In STACS’15, volume 30 of LIPIcs, pages [16] J. Esparza, M. Luttenberger, and M. Schlund. A brief history 743–756, 2015. of Strahler numbers. In LATA’14, volume 8370 of Lecture Notes in Computer Science, pages 1–13, 2014. .
10 2016/1/19 A. Equivalence between problems of Figure 2. Substitution operation. characterizations of the three regular p,q,♦ a ε B ε abstractions for OCA and simple OCA p q =⇒ p qinit qinit q Due to a following Lemma 30 without loosing of generality we can restrict our attention to considering problem of com- puting the regular abstractions of a subclass OCA, namely F × {0}. The last thing is set of transitions; for p, q ∈ Q simple OCA defined analogously to OCA but different in it contains transition ((p, n), (n, p, q), 0, (q, n)) and for any the following aspects: (1) there are no zero tests, (2) there i, j ∈ {0 . . . n} the transition ((p, i)a, 0, (q, j)) if and only if is a unique final state, F = {q }, (3) only runs that start final there is a move (p, i) −→a (q, j) in A. from the configuration (qinit, 0) and end at the configuration (q , 0) are considered accepting. The language of a simple The φ is simply induced by its definition on elements of final Π: for every a ∈ Π we have that if a ∈ Σ then φ(a) = {a} OCA A, also denoted L(A), is the set of words induced by p,q accepting runs. else if a = (n, p, q) and φ(a) = L(n)(A ). It is easy check that L(A) = φ(L(B)). Definition 29. Let A be a simple OCA. We define a sequence of L(n)(A) called approximants defined as language Next, we show how use B if we are interested in F - of words observed along runs of A from a configuration abstractions of L(A). We start from a following simple (q0, n) to a configuration (qfinal, n). observations; for any language L = L1 ·L2 we have that:
Let OCA A = (Q, Σ, q0, δ, F ), for any p, q ∈ Q we • L↓ = L1↓ · L2↓ p,q def + + define A = (Q, Σ, p, δ , {q}) where δ is the subset of • L↑ = L1↑ · L2↑ all transitions in δ which are not test for zero transitions. • ψ(L) = ψ(L1) · ψ(L2) Lemma 30. Let K ∈ N and ♦ ∈ {↑,↓, ψ} be an abstraction. The natural consequences is a following lemma. Assume that there is a polynomial g♦ such that for any p,q OCA A following holds: for every A there is an NFA Lemma 34. Let B be an automaton like one defined in p,q p,q Bp,q,♦ such that ♦L(A ) ⊆ L(Bp,q,♦) ⊆ ♦(L(K)(A )) Lemma 33 for a given OCA A. Now let φ↓, φ↑, φ ψ are defined and |Bp,q,♦| ≤ g♦(|A|). Then there is a polynomial f such as follows: If a ∈ Σ then φ↓(a) = {a}↓, φ↑(a) = {a}↑, ♦ that for any A there is an NFA B of size at most f(|A|,K) φ ψ(a) = {a}, on the other hand if a is of the form (n, p, q) ♦ p,q with L(B ) = ♦(L(A)). i.e. a ∈ Π\Σ then φ↓((n, p, q)) = L(n)(A )↓, φ↑((n, p, q)) = p,q p,q Remark 31. Restricting ourself to simple OCA, mentioned L(n)(A )↑, φ ψ((n, p, q)) = ψ(L(n)(A )). in the beginning of the section, is a consequence of Lemma 30 Then the following equalities hold for K = 0. Indeed, if we can build polynomially bounded • L(A)↓ = φ↓(L(B)), NFA for an abstraction of any given NFA, then we can do • L(A)↑ = φ↑(L(B)), it for any simple OCA as well. On the other hand, if we can • ψ(L(A)) = φ ψ(L(B)). do it, for any simple OCA than due to Lemma 30 we can construct a polynomially bounded NFA that is abstraction Proof. Lemma contains three claims which have very similar of any given OCA. proofs, thus we present only one of them, for downward In order to prove Lemma properly start from definitions. closure. 0 0 ∗ The first inclusion. Let w ∈ L(A)↓ thus there is w ∈ Definition 32. Let L, L ⊆ Σ . By a concatenation of L(A) such that w0 w. Due to Lemma 33 we know languages denoted L·L0 we mean a set of all words that that there is a word u = u1 . . . uk, where ui ∈ Π, such can be obtained by concatenation of a word from L and a that w ∈ φ(u) (φ is defined in the proof of Lemma 33). word L0 i.e. {w · w0|w ∈ L, w0 ∈ L0}. 0 We claim that w ∈ φ↓(u). Indeed, observe that φ↓(u) = Let Π be a finite alphabet. A substitution is a function φ↓(u1) ··· φ↓(uk) = φ(u1)↓ · · · φ(uk)↓; further recall that if ∗ Σ ∗ L = L1 ·L2 implies L↓ = L1↓ · L2↓ so we conclude that φ:Π → 2 . Suppose L ⊆ Π is a language. For w = 0 φ↓(u) = (φ(u1) ··· φ(uk))↓ = φ(u)↓ ⊇ w↓. As w ∈ w↓, this w1 ··· wn with w1, . . . , wn ∈ Π, the set φ(w) contains all 0 gives us what we need, so w ∈ φ↓(u). words x1 ··· xn where xi ∈ φ(wi). Lifting this notation to 0 S In the opposite direction. Let w ∈ φ↓(L(B)). Then languages, we get φ(L) = w∈L φ(w). 0 w ∈ φ↓(u) for some u ∈ L(B). Using similar calculation 0 Lemma 33. Let A = (Q, Σ, δ, q0,F ) be an OCA and like previously we can show that w ∈ φ(u)↓ but this mean p,q 0 suppose we are given, for each A , an OCA Bp,q with that w ∈ w↓ for some w ∈ φ(u). Now as we know that p,q p,q 0 L(A ) ⊆ L(Bp,q) ⊆ L(n)(A ). Then there is an NFA B φ(u) ∈ L(A) we have that w ∈ L(A)↓ which ends the proof. ∗ over an alphabet Π and substitution φ :Π −→ 2Σ such that L(A) = φ(L(B)) and that for every letter a ∈ Π hold φ(a) ∈ Σ or φ(a) equals L(Bp,q) for some p, q ∈ Q. Finally we can prove the Lemma 30.
Proof. First, for any n ∈ N holds that, an accepting run π of Proof. We start from Lemma 34. We take automaton B 0 0 0 A can be decomposed into π = π1π1π2π2 . . . πn−1πn where and choose suitable substitution φ♦, where ♦ ∈ {↑,↓, ψ}, each πi is a run in OCA such that counter values along πi depending on the abstraction that we are interested in. 0 stay below n, and where each run πi induces a word from a The idea is to substitute every transition in B, say τ = init.state(π0 ),final.state(π0 ) p,q,♦ language L(n)(A i i ). (p, a, 0, q), by a suitable designed automaton B = Thus we define B as follows: Π is a Σ plus the set of (Qp,q, Σ, qinit, δp,q, {qfinal}) that accepts the language φ♦(a). triples (n, p, q) where p, q ∈ Q, the set of states is equal If a ∈ Π \ Σ then automaton is Bp,q, else if a ∈ Σ then Q × {0 . . . n}, initial state is (q0, 0) and final states are automaton that we glue is one of following:
11 2016/1/19 Σ Σ the sequence of transitions corresponding to the segment ρi+1 . . . ρj leading from (pi, i) to (pj , j) and the sequence 0 0 a corresponding to the segment ρj−1 . . . ρi from (qj , j) to for φ↑ qinit qfinal , (qi, i) and still obtain a valid run of the system. That is, 0 0 0 a ρ0ρ1 . . . ρiρj+1[−d]ρj+2[−d] . . . ρj [−d]ρi−1 . . . ρ0 is a valid run, where d = j − i. Clearly the word accepted by such for φ qinit qfinal ↓ ε , a run is a subword of w, and further this run has at least a one fewer occurrence of the maximal counter value m. The for φ qinit qfinal ψ . Lemma follows by an application of the induction hypoth- It is obvious that this construction provides a required esis to this run and using the transitivity of the subword NFA. The last question is about its size. According to relation. Lemma 33 we have that |B| = |A| · K. So to estimate The set of words in L(A) accepted along runs where the the size of the final construction we need to add at most 2 2 value of the counter does not exceed |Q| + 1 is accepted by |Σ|·2|B|+(|A|) ·g(|A|) states, which proves the polynomial 2 bound on the size of B♦. an NFA with |Q|.(|Q| +1) states (it keeps the counter values as part of the state). Combining this with the standard Remark 35. It is easy observation that above construction construction for upward closure for NFAs we get can be preformed in polynomial time in K, |A| and time Theorem 2. There is a polynomial-time algorithm that needed to construct all automata Bp,q,♦ where ♦ ∈ {↑,↓, ψ}. takes as input an OCA A = (Q, Σ, δ, s, F ) and computes an NFA with O(|A|3) states accepting L(A)↑. B. Upward and Downward Closures The construction can be extended to general OCA with- We begin by showing that for any OCA A we can effectively out any change in the complexity construct, in P, a NFA that accepts L(A)↑. This easy con- Next we show a polynomial time procedure that con- struction follows the argument traditionally used to bound structs an NFA accepting the downward closure of the lan- the length of the shortest accepting run in a pushdown au- guage of any simple OCA. For pushdown automata the tomaton. We give the details as the ideas used here recur construction involves a necessary exponential blow-up. We elsewhere. We use the following notation in what follows: sketch some observations that lead to our polynomial time for a run ρ and an integer D we write ρ[D] to refer to the construction. quasi-run ρ0 obtained from ρ by replacing the counter value Let A = (Q, Σ, δ, s, F ) be a simple OCA and let K = |Q|. v by v + D in every configuration along the run. Consider any run ρ of A from a configuration (p, i) to a configuration (q, j). If the value of the counter increases Lemma 36. Let A = (Q, Σ, δ, s, F ) be a OCA and let w (resp. decreases) by at least K in ρ then, it contains a be a word accepted by A. Then there is a word y w in segment that can be pumped (or iterated) to increase (resp. L(A) such that y is accepted by a run where the value of the 2 decrease) the value of the counter. If the increase in the counter never exceeds |Q| + 1. value of the counter in this iterable segment is k then by choosing an appropriate number of iterations we may Proof. We show that for any accepting run ρ reading a word 0 increase the value of the counter at the end of the run by w, there is an accepting run ρ , reading a word y w, in any multiple of this k. Quite clearly, the word read along which the maximum value of the counter does not exceed 2 this iterated run will be a superword of word read along ρ. |Q| +1. We prove this by double induction on the maximum The following lemmas,whose proof is a simplified version of value of the counter and the number of times this value is that of Lemma 36, formalize this. attained during the run ρ. x If the maximum value is below |Q|2 + 1 there is nothing Lemma 37. Let (p, i) −→(q, j) with j − i > K. Then, there to prove. Otherwise let the maximum value m > |Q|2 + 1 be is an integer k > 0 such that for each N ≥ 0 there is a run N+1 attained c times along ρ. We break the run up as a concate- w=y1.(y2) .y3 0 0 0 0 0 (p, i) −−−−−−−−−−−−→(p , j + N.k) with x = y1y2y3. nation of subruns ρ = ρ0ρ1ρ2ρ3 . . . ρmρm−1 . . . ρ2ρ1ρ0 where Proof. Consider the run (p, i) −→x (q, j) and break it up as 1. ρ0ρ1ρ2 . . . ρm is the shortest prefix of ρ after which the counter reaches the value m. x1 x2 (p, i) =(pi, i) −−→(pi+1, i + 1) −−→(pi+2, i + 2) ... 2. ρ0ρ1ρ2 . . . ρi is the longest prefix of ρ0ρ1ρ2 . . . ρm after xj x0 which the counter value is i, 1 ≤ i ≤ m − 1. ... −−→(pj , j) −−→(q, j) 0 0 3. ρ0ρ1ρ2 . . . ρm.ρm−1 . . . ρi, is the shortest prefix of ρ with x1 xr where the run (pi, i) −−→ ... −−→(pr, r) is the shortest prefix ρ0ρ1ρ2 . . . ρm as a prefix and after which the counter value is i, 0 ≤ i ≤ m − 1. after which the value of the counter attains the value r. Since j − i > K it follows that there are r, r0 with i ≤ r < r0 ≤ j Let the configuration reached after the prefix ρ0 . . . ρi be such that pr = pr0 . Clearly one may iterate the segment of 0 (pi, i), for 1 ≤ i ≤ m. Similarly let the configuration the run from (pr, r) to (pr, r ) any number of times, say 0 0 w 0 reached after the prefix ρ0ρ1ρ2 . . . ρm.ρm−1 . . . ρi be (qi, i), N ≥ 0, to get a run (p, i) −−→(q, j + (r − r)N). where N+1 0 for 0 ≤ i ≤ m − 1. w = x1 . . . xr(xr+1 . . . xr0 ) xr+1 . . . xk. Setting k = r − r Now we make two observations: firstly, the value of yields the lemma. the counter never falls below i during the segment of 0 the run ρi+1 . . . ρi — this is by the definition of the ρis An analogous argument shows that if the value of the 0 and ρis. Secondly, there are i < j such that pi = pj counter decreases by at least K in ρ then we may iterate a 2 and qi = qj — this is because m ≥ |Q| + 1. Together suitable segment to reduce the value of the counter by any this means that we may shorten the run by deleting multiple of k0 (where the k0 is the net decrease in the value of
12 2016/1/19 y the counter along this segment) while reading a superword. Proof. Let the given walk result in the quasi-run (q, j) =⇒ This is formalized as (q, j+d) (where d is the net effect of the walk on the counter, Lemma 38. Let (q0, j0) −→z (p0, i0) with j0 − i0 > K. Then, which may be positive or negative). Iterating this quasi-run ym there is an integer k0 > 0 such that for every N ≥ 0 there is m times yields a quasi-run (q, j) ==⇒ (q, j + m.d), for any N+1 w=y1(y2) y3 m ≥ 0. Next, we use Lemma 3 to find a k > 0 such that a run (q0, j0 + N.k0) −−−−−−−−−−−→(p0, i0) with z = y y y . 1 2 3 for each N > 0 we have a run (p, i) −−−→xN (q, j + N.k) with 0 x xN . Similarly, we use Lemma 4 to find a k > 0 such Proof. We break the run into segments as: y that for each N 0 > 0 we have a run (q, j +N 0.k0) −−−→N0 (p0, i0) 0 0 0 zj0−1 0 zj0−2 0 (q , j ) =(qj0 , j ) −−−−→(qj0−1, j − 1) −−−−→(qj0−2, j − 2) ... with y yN0 . 0 0 Now, we pick m and N to be multiples of k in such a zi0 0 z 0 0 ... −−→(qi0 , i ) −−→(p , i ) way that N.k + m.d > 0. This can always be done since k is 0 0 0 z 0 z 0 positive. Thus, N.k + m.d = N .k with N > 0. Now we try 0 j −1 0 j −2 0 x where (qj0 , j ) −−−−→(qj0−1, j − 1) −−−−→(qj0−2, j − 2) ... and combine the (quasi) runs (p, i) −−−→N (q, j + N.k), (q, j + zt m −−→(qt, t) is the shortest prefix after which the value of y 0 0 yN0 0 0 0 0 N.k) ==⇒ (q, j + N.k + m.d) and (q, j + N .k ) −−−→(p , i ) to counter is t. Since j − i > K it follows that there are 0 0 0 0 0 0 form a run. We are almost there, as j+N.k+m.d = j+N .k . t, t ,j ≥ t > t ≥ i such that qt = qt0 . Then, starting at 0 However, it is not guaranteed that this combined quasi-run is any configuration (qt, t + (t − t )N), N ∈ N we may iterate 0 actually a run as the value of the counter may turn negative the transitions in the run (qt, t) −→(qt0 , t ) an additional N ym 00 00 0 z 0 in the segment (q, j+N.k) ==⇒ (q, j+N.k+m.d). Let −N be times. This yields a run (qt, t + (t − t )N) −−→(qt0 , t ) where 00 N+1 0 the smallest value attained by the counter in this segment. z = (zt−1 . . . zt0 ) . Observe that zt−1 . . . zt is a subword Then by replacing N by N +N 00.k0 and N 0 by N 0 +N 00.k we of z00. Finally, notice that this also means that (q0, j0 +N.(t− 00 z ...z can manufacture a triple which actually yields a run (since 0 z1...zt 0 z 0 t0+1 i 0 0 t )) −−−−−→(qt, t + N.(t − t )) −−→(qt0 , t ) −−−−−−−→(p , i ). the counter values are ≥ 0), completing the proof. Taking k0 = (t − t0) completes the proof. With this lemma in place we can now explain how to A consequence of these somewhat innocous lemmas is the relax the usage of counters. Let us focus on runs that are following interesting fact: we can turn a triple consisting of interesting, that is, those in which the counter value exceeds two runs, where the first one increases the counter by at least K at some point. Any such run may be broken into 3 stages: K and the second one decreases the counter by at least K, the first stage where counter value starts at 0 and remains and a quasi-run that connects them, into a real run provided strictly below K +1, a second stage where it starts and ends we are content to read a superword along the way. at K + 1 and a last stage where the value begins at K and remains below K and ends at 0 (the 3 stages are connected y Lemma 39. Let (p, i) −→x (q, j) =⇒ (q0, j0) −→z (p0, i0), with j− by two transitions, an increment and a decrement). Suppose, i > K and j0 − i0 > K. Then, there is a run (p, i) −−→w (p0, i0) we write the given accepting run as (p, 0) −−→w1 (q, c) −−→w2 (r, 0) such that xyz w. where (q, c) is a configuration in the second stage. If a ∈ Σ is a letter that may be read in some transition on some Proof. Let the lowest value of counter in the entire run be walk from q to q. Then, w1aw2 is in L(A) ↓. This is a m. If m ≥ 0 then the given quasi-run is by itself a run and direct consequence of the above lemma. It means that in hence there is is nothing to prove. Let us assume that m is the configurations in the middle stage we may freely read negative. certain letters without bothering to update the counters. First we use Lemma 3, to get a k and an x0 for any N > 1 This turns out to be a crucial step in our construction. To x0 turn this relaxation idea into a construction, the following and a run (p, i) −−→(q, j + k.N) with x x0. We can then seems a natural. x0 y extend this to a run (p, i) −−→(q, j + k.N) =⇒ (q0, j0 + k.N), We make an equivalent, but expanded version of A. This by simply choosing N so that k.N > m. Then, we have that version has 3 copies of the state space: The first copy is the value of the counter is ≥ 0 in every configuration of this used as long as the value of the counter stays below K + 1 0 quasi-run. Thus (p, i) −−→x (q, j+k.N) −→y (q0, j0 +k.N) for any and on attaining this value the second copy is entered. The such N. Now, we apply Lemma 4 to the run (q0, j0) −→z (p0, i0) second copy simulates A exactly but nondeterministically to obtain the k0. We now set our N to be a value divisible by chooses to enter third copy whenever the counter value is 0 0 0 x 0 y 0 0 0 moves from K + 1 to K. The third copy simulates A but k , say k .I. Thus, (p, i) −−→(q, j + k.k .I) −→(q , j + k.k .I) does not permit the counter value to exceed K. For every and now we may again use Lemma 4 to conclude that 00 letter a and state q with a walk from q to q along which a is (q0, j0 + k.k0.I) −−→z (p0, i0) with x x0 and z z00. This read on some transition, we add a self-loop transition to the completes the proof. state corresponding to q in the second copy that does not affect the counter and reads the letter a. This idea has two Interesting as this may be, this lemma still relies on deficiencies: first, it is not clear how to define the transition the counter value being recorded exactly in all the three from the second copy to the third copy, as that requires segments in its antecedent and this is not sufficient. In the knowing that value of the counter is K + 1, and second, next step, we weaken this requirement (while imposing the this is still an OCA (since the second copy simply faithfully condition that q = q0 and j = j0) by releasing the (quasi) simulates A) and not an NFA. middle segment from this obligation. Suppose we bound the value of the counter by some value U in the second stage. Then we can overcome both Lemma 40. Let (p, i) −→x (q, j),(q, j) −→z (p0, i0), with j − i > 0 0 of these defects and construct a finite automaton as follows: K and j −i > K. Let there be a walk from q to q that reads The state space of the resulting NFA has stages of the w 0 0 y. Then, there is a run (p, i) −−→(p , i ) such that xyz w. form (q, i, j) where j ∈ {1, 2, 3} denotes the stage to which
13 2016/1/19 this copy of q belongs. The value i is the value of the 2. (q, n, 3) −→a (q0, n − 1, 3) for all n ∈ {1 ...K} whenever counter as maintained within the state of the NFA. The (q, a, −1, q0) ∈ δ. Simulate a decrement. transitions interconnecting the stages go from a state of 3. (q, n, 3) −→a (q0, n+1, 3) for all n ∈ {0 ...K −1} whenever 0 the form (q, K, 1) to one of the form (q ,K + 1, 2) (while (q, a, +1, q0) ∈ δ. Simulate an increment move. simulating a transition involving an increment) and from a 0 stage of the form (q, K + 1, 2) to one of the form (q ,K, 3) The following Lemma, which is easy to prove, states that (while simulating a decrement). The value of i is bounded the first and third phases simulate faithfully any run where by K if j ∈ {1, 3} while it is bounded by U if j = 2. (States the value of the counter is bounded by K. of the form (q, i, 2) also have self-loop transitions described above.) By using a slight generalization of Lemma 6, which w 0 w 0 Lemma 41. 1. If (q, i, l) −−→(q , j, l) in AU then (q, i) −−→(q , j) allows for the simultaneous insertion of a number of walks in A, for l ∈ {1, 3}. (or by applying the Lemma iteratively), we can show that w 0 any word accepted by such a finite automaton lies L(A)↓. 2. If (q, i) −−→(q , j) in A through a run where the value of the counter is ≤ K in all the configurations along the run However, there is no guarantee that such an automaton will w 0 accept every word in L(A)↓. The second crucial point is that then (q, i, l) −−→(q , i, l) for l ∈ {1, 3}. we are able to show that if U ≥ K2+K+1 then every word in L(A) is accepted by this 3 stage NFA. We show that for each The next Lemma extends this to runs involving the accepting run ρ in A there is an accepting run in the NFA second phase as well. All moves other than those simulating reading the same word. The proof is by a double induction, unconstrained walks can be simulated by A. The second first on the maximum value attained by the counter and phase of AU can also simulate any run where the counter is then on the number of times this value is attained along bounded by U. Again the easy proof is omitted. the run. Clearly, segments of the run where the value of the w 0 0 counter does not exceed K2 + K + 1 can be simulated as Lemma 42. 1. If (q, i, l) −−→(q , j, l ) is a run of AU in is. We then show that whenever the counter value exceeds which no transition from ∆2 of type 5 is used then w 0 this number, we can find suitable segments whose net effect (q, i) −−→(q , j) is a run of A. a1 a2 am on the counter is 0 and which can be simulated using the 2. If ρ = (q0, i0) −−→(q1, i1) −−→ ... −−−→(qm, im) is a run self-loop transitions added to stage 2 (which do not modify in A in which the value of the counter never exceeds U 0 a1 a2 am the counters), reducing the maximum value of the counter then ρ = (q0, i0, 2) −−→(q1, i1, 2) −−→ ... −−−→(qm, im, 2) along the run. is a run in AU . We now present the formal details. We begin by describ- ing the NFA AU where U ≥ K + 1. Now, we are in a take the first step towards generalizing Lemma 6 to prove that L(AU ) ⊆ L(A)↓. AU = (Q1 ∪ Q2 ∪ Q3, Σ, ∆, iU ,FU })
w 0 where Q1 = Q × {0 ...K} × {1}, Q2 = Q × {0 ...U} × {2} Lemma 43. Let (q, i, 2) −−→(q , j, 2) be a run in AU . Then, and Q3 = Q × {0 ...K} × {3}. We let iU = (s, 0, 1) and there is an N ∈ N, words x0, y0, x1, y1, . . . , xN , and integers FU = {(f, 0, 1), (f, 0, 3) | f ∈ F }. The transition relation is n0, n1, . . . , nN−1 such that, in A we have: the union of the relations ∆1, ∆2 and ∆3 defined as follows: 1. w x0y0x1y1 . . . xN . Transitions in ∆1: x0y0...xN 0 0 0 2. (q, i) ======⇒ (q , j ) where j = j + n0 + n1 ... + nN−1. a 0 1. (q, n, 1) −→(q , n, 1) for all n ∈ {0 ...K} whenever m0 m1 x0y0 x1y1 ...xN 0 00 00 (q, a, i, q0) ∈ δ. Simulate an internal move. 3. (q, i) ======⇒ (q , j ) where j = j + m0.n0 + a m .n ... + m .n , for any 1 ≤ m , m , . . . m . 2. (q, n, 1) −→(q0, n − 1, 1) for all n ∈ {1 ...K} whenever 1 1 N−1 N−1 0 1 N−1 (q, a, −1, q0) ∈ δ. Simulate a decrement. Note that 2 is just a special case of 3 when mr = 1 for all r. 3. (q, n, 1) −→a (q0, n+1, 1) for all n ∈ {0 ...K −1} whenever (q, a, +1, q0) ∈ δ. Simulate an increment. 4. (q, K, 1) −→a (q0,K +1, 2) whenever (q, a, +1, q0) ∈ δ. Sim- ulate an increment and shift to second phase. w 0 Transitions in ∆2: Proof. The run (q, i, 2) −−→(q , j, 2) in AU uses only transi- a 0 0 tions of the types 1, 2, 4 and 5 in ∆2. Let N be the number 1. (q, n, 2) −→(q , n, 2) for all n ∈ {0 ...U} when (q, a, i, q ) ∈ of transitions of type 5 used in the run. We then break up δ. Simulate an internal move. the run as follows: 2. (q, n, 2) −→a (q0, n − 1, 2) for all n ∈ {1 ...U} whenever 0 x0 a0 x1 (q, a, −1, q ) ∈ δ. Simulate a decrement. (q, i, 2) −−→(p0, i0, 2) −−→(p0, i0, 2) −−→(p1, i1, 2) ... a 0 0 3. (q, K +1, 2) −→(q ,K, 3) whenever (q, a, −1, q ) ∈ δ. Sim- aN−1 xN 0 ulate a decrement and shift to third phase. ... (pN−1, iN−1, 2) −−−−→(pN−1, iN−1, 2) −−−→(q , j, 2) 4. (q, n, 2) −→a (q0, n + 1, 2) for all n ∈ {0 ...U − 1} whenever 0 where the transitions, indicated above, on ai’s are the N (q, a, +1, q ) ∈ δ. Simulate an increment move. yr a moves using transitions of type 5 in the run. Let (pr, ir) =⇒ 5. (q, n, 2) −→(q, n, 2) whenever there is a walk from q to q 0 0 (pr, i ) be a quasi-run with ar yr and let nr = i − ir. on some word w and, a w. Freely simulate loops. r r Clearly w x0y0x1y1 . . . xN . Transitions in ∆ : It is quite easy to show by induction on r, 0 ≤ r < N, 3 by replacing moves of types 1, 2 and 4 by the corresponding 1. (q, n, 3) −→a (q0, n, 3) for all n ∈ {0 ...K} whenever moves in A and moves of type 5 by the iterations of the (q, a, i, q0) ∈ δ. Simulate an internal move. quasi-runs identified above that:
14 2016/1/19 Suppose l < 0. Then, we let I be a positive integer such 0 00 0 m0 that I.k + l > 0 and I = k .m (i.e. I is divisible by k ) x0 y0 x1 (q, i) −−→(p0, i0) ==⇒ (p0, i0 + m0.n0) =⇒ (p1, i1 + m0.n0) which must exist since k > 0. Then m y 1 m0 m1 1 x0y0 x1y1 ...xN 0 0 ==⇒ (p1, i1 + m0.n0 + m1.n1) (q, K+1+(m−1).k+I.k) ======⇒ (r, K+1+I.k+k .m ) ... is a quasi-run in which the counter values are always ≥ 0 xr −−→(pr, ir + m0.n0 ... + mr−1.nr−1) and is thus a run. Once again, we may use Lemmas 3 and 4 (since I.k is a multiple of k0) to get ymr ==r⇒ (p , i + m .n . . . m .n ) r r 0 0 r r (s, 0) −−→w (p, K + (m − 1).k + I.k) xr+1 −−−−→(p , i + m n . . . m .n ) a1 r+1 r+1 0 0 r r −−→(q, K + 1 + (m − 1).k + I.k) m m and with r = N − 1 we have the desired result. x y 0 x y 1 ...x −−−−−−−−−−−−−→0 0 1 1 N (r, K + 1 + k0.m0) Now, we use an argument that generalizes Lemma 6 in −−→a2 (t, K + k0.m0 + I.k) order to show that: z −→(f, 0, 3) Lemma 44. Let w be any word accepted by the automaton with w w, w x ym0 x ym1 . . . x and w z. This A . Then, there is a word w0 ∈ A such that w w0. 1 2 0 0 1 1 N 3 U completes the proof of the Lemma.
Proof. If states in Q2 are not visited in the accepting run of AU on w then we can use Lemma 41 to conclude that 2 Next, we show that if U ≥ K + K + 1 then L(A) ⊆ w ∈ A. Otherwise, we break up the run of AU on w into L(A ). three parts as follows: U Lemma 45. Let U ≥ K2 + K + 1. Let w be any word in (s, 0, 1) −−→w1 (p, K, 1) −−→a1 (q, K + 1, 2) −−→w2 (r, K + 1, 2) L(A). Then, w is also accepted by AU . −−→a2 (t, K, 3) −−→w3 (f, 0, 3) Proof. The proof is accomplished by examining runs of the w1 w3 Using Lemma 41 we have (s, 0) −−→(p, K) and (t, K) −−→(f, 0). from (s, 0) −−→w (f, 0) and showing that such a run may be We then apply Lemmas 3 and 4 to these two segments re- simulated by AU transition by transition in a manner to be spectively to identify k and k0. Next we use Lemma 43 to w described below. Any run ρ = (s, 0) −−→S (f, 0) can be broken identify the positive integer N, integers n0, n1, . . . nN−1 and up into parts as follow: the quasi-run x y 0 0 z x0y0...xN (s, 0) −→(h, j) −→(h , j ) −→(f, 0) (q, K + 1) ======⇒ (r, K + 1 + n0 + n1 ... + nN−1) x where, ρ1 = (s, 0) −→(h, j) is the longest prefix where the with w2 x0y0x1y1 . . . xN−1yN−1xN . We identify numbers 0 0 z counter value does not exceed K, ρ3 = (h , j ) −→(f, 0), m, m0, m1, . . . , mN−1, all ≥ 1, such that (m−1).k+m0.n0 + 0 0 0 is the longest suffix, of what is left after removing ρ1, in . . . mN−1.nN−1 = k .m for some m ≥ 0. By taking m − 1 0 which the value of the counter does not exceed K, and and each mi to be some multiple of k we get the sum y 0 0 (m − 1).k + m .n + . . . m n to be a multiple of k0, ρ2 = (h, j) −→(h , j ) is what lies in between. We note 0 0 N−1 N−1 that using Lemma 41 we can conclude that there are runs however this multiple may not be positive. Since k > 0, by x 0 0 z choosing m − 1 to be a sufficiently large multiple of k0 we (s, 0, 1) −→(h, j, 1) and (h , j , 3) −→(f, 0, 3). Further, ob- can ensure that m0 ≥ 0. Using these numbers we construct serve that if value of the counter never exceeds K then ρ2 the quasi-run and ρ3 are empty, x = w, h = f and j = 0. In this case, using Lemma 41, there is a (accepting) run (s, 0, 1) −−→w (f, 0, 1). m m x y 0 x y 1 ...x 0 (q,K + 1 + (m − 1).k) ======0 0 1 1 ⇒N If the value of the counter exceeds K then j = j = K and by Lemma 41, (s, 0, 1) −→x (h, K, 1), (h0,K, 3) −→z (f, 0, 3) (r, K + 1 + (m − 1).k + m0n0 + . . . mN−1nN ) and ρ2 is non-empty. Further suppose that, ρ2, when written 0 0 out as a sequence of transitions is of the form with K +1+(m−1).k+m0n0 +. . . mN−1nN = K +1+k .m . Let l be the lowest value attained in this quasi-run. If l ≥ 0 a a1 ρ2 =(h, K) −→(p, K + 1) = (p0, i0) −−→(p1, i1) then a2 an b 0 m m −−→(p , i ) ... −−→(p , i ) = (q, K + 1) −→(h ,K) x y 0 x y 1 ...x 2 2 n n (q, K + 1 + (m − 1).k) −−−−−−−−−−−−−→0 0 1 1 N (r, K + 1 + k0.m0) We will show by double induction on the maximum value and using Lemma 3 and 4 we get of the counter value attained in the run ρ2 and the number of times the maximum is attained that there is a run (s, 0) −−→w (p, K + (m − 1).k) ρ0 =(h, K, 1) −→a (p, K + 1, 2) = (p0 , i0 , 2) −−→a1 (p0 , i0 , 2) −−→a1 (q, K + 1 + (m − 1).k) 2 0 0 1 1 a2 0 0 an 0 0 b 0 m m x y 0 x y 1 ...x −−→(p2, i2, 2) ... −−→(pn, in, 2) = (q, K + 1, 2) −→(h ,K, 3) −−−−−−−−−−−−−→0 0 1 1 N (r, K + 1 + k0.m0) such that for all i, 0 ≤ i < n, −−→a2 (t, K + k0.m0) 0 0 z 1. either p = p and p = p and the ith transition (on −→(f, 0, 3) i i i+1 i+1 ai+1) is of type 1, 2 or 4, m0 m1 0 0 0 0 0 0 with w1 w, w2 x0y0 x1y1 . . . xN and w3 z as 2. or pi = pi+1, ii = ii+1, pi =⇒ pi and pi+1 =⇒ pi so that required. the ith transition (on ai+1) is a transition of type 5.
15 2016/1/19 0 0 For the basis, notice that if the maximum value attained we can extend the run ρd to a run ρ2 that simulates ρ2 2 is ≤ K + K + 1 then, by Lemma 42, there is a run of AU fulfilling the requirements of the induction hypothesis. This that simulates ρ2 such that item 1 above is satisfied for all completes the proof of this lemma. i. 2 Now, suppose the maximum value attained along the run Notice that the size of the state space of AU is K.(K + 2 is m > K2 + K + 1. We proceed along the lines of the proof K + 1) when U = K + K + 1. Since downward closures of Lemma 36. We first break up the run ρ2 as of NFAs can be constructed by just adding additional (ε) y transitions, Lemmas 44 and 45 imply that: (h, K) −→a (p ,K + 1) = (q ,K + 1) −−−−→K+2 (q ,K + 2) 0 K+1 K+2 Theorem 7. There is a polynomial-time algorithm that yK+3 ym −−−−→(qK+3,K + 3) ... −−−→(qm, m) takes as input a simple OCA A = (Q, Σ, δ, s, F ) and com- 3 y0 y0 putes an NFA with O(|A| ) states accepting L(A)↓. −−−−→m−1 (q0 , m − 1) ... −−−−→K+1 (q0 ,K + 1) m−1 K+1 A closer look reveals that the complexity remains the z b 0 −→(q, K + 1) −→(h ,K) same even for general OCA. We only need one copy of AU . where C. Bounded alphabet • The prefix upto (qm, m), henceforth referred to as σm, is The result of this section is the following theorem. the shortest prefix after which the counter value is m. • The prefix upto (q , i), K + 1 ≤ i < m is the longest Theorem 46. For any fixed alphabet Σ there is a polynomial- i time algorithm that, given as input a one-counter automaton prefix of σm after which the value of the counter is i. 0 over Σ with n states, computes a Parikh-equivalent NFA. • The prefix upto (qi, i), K + 1 ≤ i < m is the shortest prefix of ρ2 with σm as a prefix after which the counter Note that in Theorem 46 the size of the alphabet Σ is value is i. fixed. The theorem implies, in particular, that any one- counter automaton over Σ with n states has a Parikh- By construction, the value of the counter in the segment of equivalent NFA of size poly (n), where poly is a poly- 0 Σ Σ the run from (qi, i) −→ ... −→(qi, i) never falls below i. Further, nomial of degree bounded by f(|Σ|) for some computable by simple counting, there are i, j with K + 1 ≤ i < j ≤ m function f. 0 0 such that qi = qj and qi = qj . Thus, by deleting the segment The numbering sequence from the conference version is 0 0 of the runs from (qi, i) to (qi, j) and (qj , j) to (qj , i) we get mapped as follows: a shorter run ρd which looks like • a Theorem 8 is Theorem 46, (h, K) −→(p0,K + 1) = (qK+1,K + 1) ... • Definition 9 is Definition 50, yi yj+1 −−→(qi, i) −−−−→(qj+1, i + 1) ... • Definition 10 is Definition 51, 0 ym ym−1 −−−→(qm, m − j + i) −−−−→ ... • Definition 11 is Definition 52, y0 y0 • Lemma 12 is Lemma 54, −−→j (q0 , i) −−−−→i−1 (q0 , i − 1) ... (q0 ,K + 1) j i−1 K+1 • Definition 13 is Definition 55, −→z (q, K + 1) −→b (h0,K) • Lemma 14 is Lemma 56, This run reaches the value m at least one time fewer than ρ2 • Lemma 15 is Lemma 57, and thus we may apply the induction hypothesis to conclude 0 • Lemma 16 is Lemma 64, the existence of a run ρd of AU that simulates this run move for move satisfying the properties indicated in the induction • Lemma 17 is Lemma 60. hypothesis. Let this run be: a Remark 47. We start with yet another simplifying assump- (h, K, 1) −→(r0,K + 1, 2) ... tion (in addition to that of subsection 2.3). In one part of y −−→yi (r , c , 2)) −−−−→j+1 (r , c , 2) ... our proof (subsection C.2 below) we will need to rely on the i i j+1 j+1 fact that short input words can only be observed along short y0 ym m−1 runs; this is, of course, always true if all OCA in question −−−→(rm, cm, 2) −−−−→ ... have to ε-transitions. We note here that, for the purpose of y0 y0 −−→j (r0 , c0 , 2) −−−−→i−1 (r0 , c0 , 2) ... (r0 , c0 , 2) computing the Parikh image, we can indeed assume without j j i−1 i−1 K+1 K+1 loss of generality that this is the case. To see this, replace −→z (r0,K + 1, 2) −→b (h0,K) all ε on transitions of an OCA A with a fresh letter e 6∈ Σ; i.e., increase the cardinality of Σ by 1. Now construct an al+1 Now, if (pl, il) −−−−→(pl+1, il+1) was a transition in ρ2 NFA Parikh-equivalent to the new OCA over the extended in the part of the run from (qi, i) to (qi, j) then, qi =⇒ pl, alphabet; it is easy to see that replacing all occurrences of al+1 pl ===⇒ qi and pl+1 =⇒ qi. Now, either ri = qi or ri =⇒ qi, e in the NFA by ε will give us an appropriate NFA. In this and qj+1 =⇒ ri and (qi, aj+1, op, qj+1) is a transition for some NFA ε-transitions can be eliminated in a standard way. al+1 op. In the both cases clearly ri ===⇒ ri. Thus every such C.1 Basic definitions deleted transition can be simulated by a transition of the al+1 We start from a sequence of definitions which are necessary form (r , c , 2) −−−−→(r , c , 2). i i i i to describe pumping schemas for one-counter automata, that A similar argument shows that every transition of the al+1 0 are crucial to capture the linear structure of the Parikh form (pl, il) −−−−→(pl+1, il+1) deleted in the segment (qj , j) image of the language accepted by a given one-counter 0 0 0 al+1 0 0 to (qj , i) can be simulated by (rj , cj , 2) −−−−→(rj , cj , 2). Thus automaton.
16 2016/1/19 Definition 48 (attributes of runs and walks). For a run is just a sub-run of π, that is, no implicit shifting occurs in π = (p0, c0), t1, (p1, c1), t2, . . . , tm, (pm, cm) or a walk (if it this particular concatenation. 1 has sense) we define the following attributes: We say that a run π2 is in π if π = π1π2π3 for some runs π , π and final.counter(π ) = init.counter(π ), |π| = m, (length) 1 3 1 2 final.counter(π3) = init.counter(π3). init.state(π) = p0, (initial control state) We say that runs π1, π2, . . . , πk are disjoint in π if 0 0 0 0 0 0 0 0 final.state(π) = pm, (final control state) π = π1π1π2π2π3 . . . πkπkπk+1 for some runs π1, π2 . . . πk+1, 0 where final.counter(πi) = init.counter(πi) and final.counter(πi) = init.counter(π) = c0, (initial counter value) 0 init.counter(πi+1) for all 1 ≤ i ≤ k. final.counter(π) = cm, (final counter value) C.2 Semilinear representation of ψ(L(A)) high(π) = max{ci | 0 ≤ i ≤ m}, Definition 50 (split run). A split run is a pair of runs low(π) = min{ci | 0 ≤ i ≤ m}, (ρ, σ) such that effect(ρ) ≥ 0 and effect(σ) ≤ 0. drop(π) = init.counter(π) − low(π), In fact, we can even drop these inequalities in the defini- height(π) = high(π) − low(π), tion, but we believe it’s more visual this way. effect(π) = final.counter(π) − init.counter(π). Definition 51 (direction). A direction is a pair of walks α We also use the following terms for quasi runs and walks: and β, denoted d = hα, βi, such that: ∗ • the induced word is w = a1a2 . . . am ∈ Σ where ti = • init.state(α) = final.state(α), (pi−1, ai, s, pi) ∈ δ with ai ∈ Σ ∪ {ε}, • init.state(β) = final.state(β), • the Parikh image, denoted ψ(π), is the Parikh image of • 0 < |α| + |β| < n(2n2 + 3)(n3) + 1, the induced word. • 0 ≤ effect(α) ≤ n3, Note that a run of length 0 is a single configuration. • effect(α) + effect(β) = 0, Definition 49 (concatenation). The concatenation of a run • if effect(α) = 0, then either |α| = 0 or |β| = 0. π1 and a quasi run π2 One can think of a direction as a pair of short loops with
π1 = (p0, c0), t1, (p1, c1), t2, . . . , tm, (pm, cm) and zero total effect on the counter. Pairs of words induced by ¯ ¯ ¯ these loops are sometimes known as iterative pairs. Direc- π2 = (q0, c¯0), t1, (q1, c¯1), t2,..., tk, (qk, c¯k) tions of the first kind are essentially just individual loops; in def a direction of the second kind, the first loop increases and where p = q and c = final.counter(π ) ≥ drop(π ) is the m 0 m 1 2 the second loop decreases the counter value (even though sequence the values drop(α) and drop(β) are allowed to be strictly positive). The condition that effect(α) ≤ n3 is a pure tech- π3 = (p0, c0), t1, (p1, c1), t2, . . . , tm, (pm, cm), nicality and is only exploited at a later stage of the proof; ¯ 0 ¯ ¯ 0 t1, (q1, c¯1), t2,..., tk, (qk, c¯k) in contrast, the upper bound |α| + |β| < n(2n2 + 3)(n3) + 1 0 is crucial. where c¯i =c ¯i − c¯0 + cm; note that this sequence π3 is a run. The concatenation of π1 and π2 is denoted by π3 = π1 ·π2; we We also use the following terms: also write π = π π when we want no additional emphasis def 3 1 2 • the Parikh image of a split run (ρ, σ) is ψ((ρ, σ)) = on this operation. ψ(ρ) + ψ(σ), Note that in our definition of concatenation the value • similarly, the Parikh image of a direction hα, βi is final.counter(π1) can be different from init.counter(π2), in ψ(hα, βi) def= ψ(α) + ψ(β), which case the counter values all configurations in π2 are adjusted accordingly. The condition final.counter(π1) ≥ • split runs (ρ1, σ1) ... (ρk, σk) are disjoint in a run π iff drop(π2) ensures that all the adjusted values stay non- ρ1, σ1, . . . , ρk, σk form disjoint subsequences of transi- negative, i.e., that the concatenation π1 · π2 is indeed a tions in the sequence π; run. Remark: the number of directions can be exponential, We extend Definition 49 of concatenation to a concate- 2 nation of a run π and a walk α. Let α be a sequence of but the number of their Parikh images is at most (n(2n + 1 3 |Σ| transitions in some quasi-run π2. The concatenation π1 and 3)(n ) + 1) . Since |Σ| is fixed, this is polynomial in n. α is allowed only if π1 · π2 is well-defined, and the effect of Definition 52 (availability of directions). Suppose π is a def π1 ·α = π1 ·π2, so it is a run. To sum up, we can concatenate run. A direction d = hα, βi is available at π if there exists a 0 runs, quasi-runs, and walks, using the notation π1 · π2 and factorization π = π1 · π2 · π3 such that π = π1 · απ2β · π3 is sometimes dropping the dot. If π2 is a walk and π1 is a run, also a run. then π · π will also denote a run. In this and other cases, 1 2 In the context of the definition above we write π + d we will often assume that the counter values in π2 are picked 0 or adjusted automatically to match the last configuration of to refer to π . This plus operation is non-commutative and binds from the left. Whenever we use this notation, we π1. However, whenever we introduce parts of the run, e.g., by writing “suppose π = π · π ”, we always assume that π implicitly assume that the direction d is available at π. 1 2 2 Note that for a particular run π there can be more than 1 To define attributes for walk we take a quasi run such that its one factorization of π into π1, π2, π3 such that π1απ2βπ3 is sequence of transitions is equal to the walk. All attributes ex- a valid run. In such cases the direction d can be introduced cept of init.counter(), final.counter(), high(), low() are well defined at different points inside π. In what follows we only use the 0 for walk, as their value is purely determined by a sequence of notation π + d to refer to a single run π obtained in this transitions. way, without specifying a particular factorization of π. We
17 2016/1/19 ensure that all statements that refer to π +d hold regardless Lemma 56 is the key lemma in the entire Appendix C; we of which factorization is chosen of π. prove it in subsection C.4. |Σ| Recall that a set A ⊆ N is called linear if it is of Lemma 53 (characterization of availability). A direction def hα, βi is available at a run π if and only if π has two the form Lin(b; P ) = {b + λ1p1 + ... + λrpr | λ1, . . . , λr ∈ |Σ| configurations (init.state(α), c1) and (init.state(β), c2), occur- N, p1, . . . , pr ∈ P } for some vector b ∈ N and some finite |Σ| ring in this particular order, such that c1 ≥ drop(α) and set P ⊆ N ; this vector b is called the base and vectors d c2 + effect(α) ≥ drop(β). p ∈ P periods. A set S ⊆ N is called semilinear if it is a finite union of linear sets, S = ∪i∈I Lin(bi; Pi). Semilinear Proof. Denote p = init.state(α) and q = init.state(β). It is sets were introduced by FIXME in 1960s and have since immediate that for a direction hα, βi to be available, it is received a lot of attention in formal language theory and necessary that π have some configurations of the form (p, c1) its applications to verification. They are precisely the sets and (q, c2) that occur in this order. Let π = π1π2π3 where definable in Presburger arithmetic, the first-order theory of π1 ends in (p, c1) and π2 ends in (q, c2). We now show that natural numbers with addition. Intuitively, semilinear sets the direction hα, βi is available if and only if c1 ≥ drop(α) are a multi-dimensional analogue of ultimately periodic sets and c2 + effect(α) ≥ drop(β). in N. We first suppose that these two inequalities hold. Ob- The following lemma characterizes the semilinear set serve that π1α is then a run as c1 ≥ drop(α); furthermore, ψ(L(A)) through sets of directions available at short ac- final.counter(π1α) = c1+effect(α) ≥ c1: by our definition of a cepting runs. direction, we have effect(α) ≥ 0. Hence, final.counter(π1α) ≥ c ≥ drop(π ), where the last inequality holds because Lemma 57. For any one-counter automaton A, it holds 1 2 that π1π2 is a run. It follows that π1απ2 is also a run; we note [ that final.counter(π1απ2) = final.counter(π1π2) + effect(α) = ψ(L(A)) = Lin(ψ(π); ψ(avail(π))), c2 + effect(α) ≥ drop(β). This, in turn, implies that π1απ2β |π| ≤ small1 is a run. Moreover effect(α) = −effect(β) by our definition of a direction, so final.counter(π1απ2β) = final.counter(π1π2) = where the union is taken over all runs of A of length at most def 2 2 3 3 c2. Since π1π2π3 is a run, we have c2 ≥ drop(π3); hence, small1 = n ((2n + 3)(n )) . π1απ2βπ3 is also a run. Conversely, suppose π απ βπ is a run. Recall that π 1 2 3 1 Proof. Start with the ⊇ part. It suffices to show that, for any ends in (p, c ); we conclude that c ≥ drop(α). Also recall 1 1 run π of A and any vector v ∈ Lin(ψ(π); ψ(avail(π))), the that in the run π π π the fragment π ends in (q, c ); 1 2 3 2 2 set L(A) contains at least one word with Parikh image v. here c = final.counter(π π ). But π απ βπ is a run, so 2 1 2 1 2 3 Indeed, take such a v and suppose that v = v + Pm λ v , final.counter(π απ ) ≥ drop(β); since final.counter(π απ ) = 0 i=1 i i 1 2 1 2 where the vector v is the Parikh image of the word induced final.counter(π π ) + effect(α), we also conclude that c + 0 1 2 2 by the run π, vectors v , . . . , v are Parikh images of the effect(α) ≥ drop(β). This completes the proof. 1 m words induced by some directions d1, . . . , dm available at π, and λ , . . . , λ are nonnegative integers. Lemma 54 ensures By avail(π) we denote the set of all directions available 1 m that we can form a run at π. π + d1 + ... + d1 + ... + dm + ... + dm . Lemma 54 (monotonicity of availability). If π is a run of | {z } | {z } a one-counter automaton and d is a direction available at π, λ1 times λm times then avail(π) ⊆ avail(π + d). This run induces a word accepted by A, and the Parikh image of this word is v, as desired. Proof. By Lemma 53 it suffices to show that for every pair Now turn to the ⊆ part and take some vector v in of configurations (p, c1), (q, c2) that appear in π in this par- 0 0 ψ(L(A)). This vector v is the Parikh image of a word in ticular order there is a pair of configurations (p, c1), (q, c2) 0 L(A), which is induced by some accepting run π0 of A. that appear in π = π + d, in this particular order, such that 2 2 3 3 0 0 If the length of π0 does not exceed n ((2n + 3)(n )) , c1 ≥ c1 and c2 ≥ c2. Now, this claim is not difficult to sub- there is nothing to prove, so assume otherwise. By the main stantiate. Suppose d = hα, βi. Indeed, for any decomposition 0 lemma 56, π0 can be safely unpumped. This implies that of π = π1π2π3 such that there is a π = π1απ2βπ3, define 0 0 π0 = π1 + d1 for some direction d1. Note that the length π1 = π1, π2 = (init.state(π2), init.counter(π2) + effect(α))π2, 0 0 of π1 is strictly less than the length of π0; if it is greater π3 = π3. Now π2 is simply π2 shifted up, as effect(α) ≥ 0. than n2((2n2 + 3)(n3))3, then we apply the safe unpumping Observe that now π0 = π0 απ0 βπ0 . Thus for any pair of 1 2 3 lemma again: π1 = π2 + d2. We repeat the process until the configurations in π there is a corresponding pair of configu- length of the run drops to n2((2n2 + 3)(n3))3 or below: rations with the needed properties in π0. This completes the proof. π0 = πk + dk + dk−1 + ... + d1, (2) 2 2 3 3 where |πk| ≤ n ((2n + 3)(n )) . Take Parikh images of the Definition 55 (unpumping). A run π0 can be unpumped if words that are induced by the runs on both sides of (2): on there exist a run π and a direction d such that π0 = π + d. the left-hand side, we obtain v; we claim that on the right- If additionally avail(π0) = avail(π), then we say that hand side we obtain a vector from Lin(ψ(πk); ψ(avail(πk))). π0 can be safely unpumped. Note that avail(π0) is always a Indeed, recall that Lemma 56 guarantees that all these superset of avail(π) by Lemma 54. unpumpings are safe, i.e., avail(πi) = avail(πi−1) for 0 < i ≤ k. Since each direction di is available at the run πi, it follows Lemma 56 (safe unpumping lemma). Every accepting run that all the directions d1, . . . , dk are available at πk, so the π0 of A of length greater than n2((2n2 + 3)(n3))3 can be Parikh image of the word induced by the run on the right- safely unpumped. hand side of (2) indeed belongs to Lin(ψ(πk); ψ(avail(πk))).
18 2016/1/19 But, by our choice above, the run πk has length at most Due to the above characterization, we can bound the number n2((2n2 + 3)(n3))3. This concludes the proof. of possible pairs (b, Q) by ((M + 1)poly(|Σ|))|Σ| · ((M + 1)|Σ|)|Σ|, Up to now we were focused on building some semilinear representation of ψ(L(A)). Our next goal is to improve which is again a polynomial in M, because |Σ| is fixed. Thus, (poly(|Σ|)+|Σ|)·|Σ| this representation, before we start we introduce two useful #J ≤ (M+1) . This completes the proof. def notions. For a given vector v we define kvk∞ = max{v(a) | Lemma 59. For any one-counter automaton A, it holds a ∈ Σ} and kvk def= P v(a). For a set of vectors F by 1 a∈Σ that kF k∞ we denote max{kvk∞ | v ∈ F }. We also denote the [ cardinality of a finite set F by #F . ψ(L(A)) = Lin(ψ(π); ψ(Dπ)), The following lemma uses results from Huynh [24] and |π| ≤ small2 in Kopczyński and To [25], which rely on the Carathéodory where the union is taken over all runs of A of length at most theorem for cones in a multi-dimensional space. Essentially, def 2 2 3 3 small2 = poly(n ((2n + 3)(n )) ) and, for each π, Dπ is the underlying idea is that if a vector is a linear combination a subset of avail(π) of cardinality at most |Σ|. of more than |Σ| vectors in a |Σ|-dimensional space, then, by using linear dependencies, one can reduce this number to Proof. From Lemma 57 we know that just |Σ|. For non-negative integer combinations, the situa- [ 0 0 tion is slightly more complicated, but the same idea can be ψ(L(A)) = Lin(ψ(π ); ψ(avail(π ))). carried through. 0 |π | ≤ small1 |Σ| Lemma 58. Let S ⊆ N be a semilinear set with represen- If we apply to it Lemma 58 we get the desired statement. It is S tation S = i∈I Lin(ci; Pi) and suppose M ∈ N is such that worth emphasizing that Dπ ⊆ avail(π) due to the following kcik∞, kPik∞ ≤ M for all i ∈ I. Then S also has a represen- reasoning: S poly(|Σ|) 0 0 tation S = j∈J Lin(bj ; Qj ), where #J ≤ (M + 1) First due to Lemma 58, ψ(π) ∈ Lin(ψ(π ); ψ(avail(π ))) for and for each j ∈ J there exists an i ∈ I such that the fol- some π0 and π can be obtained from π0 by pumping some of lowing conditions hold: directions in the set avail(π0). Thus according to Lemma 58 the set avail(π0) ⊆ avail(π) and consequently (according to • Lin(bj ; Qj ) ⊆ Lin(ci; Pi), 0 Lemma 58) as Dπ ⊆ avail(π ) we get Dπ ⊆ avail(π). • Qj is a linearly independent subset of Pi, and poly(|Σ|) • kbj k∞ ≤ (M + 1) . C.3 Computing the semilinear representation Below we state sub-procedures used in the algorithm. Proof. The case #I = 1 appears in Huynh [24, Lemma 2.8] and in Kopczyński and To [25, Theorem 6]. In these results, Lemma 60. For every fixed Σ there is a polynomial-time al- upper bounds on #J are only stated implicitly and only for gorithm for the following task: given a one-counter automa- ton A over Σ, two configurations (q1, c1) and (q2, c2) and a I = 1. We will rely on results of Kopczyński and To, as Σ it seems simpler to extract an explicit upper bound from vector v ∈ N with all numbers written in unary, decide if their arguments. Their results can be stated as follows: If A has a run π = (q1, c1) −→(q2, c2) with ψ(π) = v. S = Lin(c1,P1;), then S has also a representation S = S Lin(bj ; Qj ) such that for each j ∈ J1 the following Proof. Our algorithm leverages the unary representation of j∈J1 conditions hold: c1, c2, and components of v. Define H0 = max(c1, c2) + kvk1 + 1. Observe that for any run π = (q1, c1) −→(q2, c2) such that ψ(π) = v the counter value stays below H , as in • Lin(b ; Q ) ⊆ Lin(c ; P ), 0 j j 1 1 one move the counter can not be changed by more than 1 • Qj is a linearly independent subset of P1, and and the number of moves is bounded by kvk . poly(|Σ|) 1 • kbj k∞ ≤ (M + 1) . The algorithm constructs a multi-dimensional table that 0 0 0 0 0 0 for all pairs of configurations (q1, c1), (q2, c2) with c1, c2 < 0 Σ In fact, the precise bound we get from [25, Theorem 6] is as H0 and all vectors v ∈ {0,...,H0} keeps the information follows: whether there exists a w0 ∈ Σ∗ such that A has a run 0 |Σ| 0 0 w 0 0 |Σ| |Σ| 2 2 (q1, c1) −−→(q2, c2) where the counter value stays below H0 kbj k∞ ≤ (2M + 1) · (M · |Σ| ) . 0 0 2 and ψ(w ) = v . The size of the table is at most (|A| · H0) · S |Σ| Observe that if S = Lin(ci,Pi;), then we can transfer (H0 + 1) , which is polynomial in the size of the input for i∈I S S the above result directly: S = Lin(bj ; Qj ) = a fixed Σ. i∈I j∈Ji S The algorithm fills the entries of the table using dy- j∈J Lin(bj ; Qj ) and the above bounds are transfered as well. namic programming. To begin with, runs whose Parikh im- 0 0 So the only remaining part is to prove that #J ≤ (M + age is the zero vector only connect pairs where (q1, c1) = poly(|Σ|) 0 0 0 Σ 1) . To do this, we start from the observation that (q2, c2). Now take a non-zero vector v ∈ {0,...,H0} ; 0 0 0 w 0 0 0 0 every element j ∈ J is uniquely determined by the pair a run (q1, c1) −−→(q2, c2) with ψ(w ) = v exists if and (bj ,Qj ), so #J is bounded by the cardinality of a set of all only if there exists an intermediate configuration (¯q, c¯) such possible pairs (b, Q) where 0 w¯ a 0 0 ∗ that (q1, c1) −−→(¯q, c¯) −→(q2, c2), where w¯ ∈ Σ , a ∈ Σ, and ψ(w ¯) + ψ(a) = v0; note that the vector ψ(a) has 1 |Σ| poly(|Σ|) • b ∈ N and kbk∞ ≤ (M + 1) in exactly one component and 0 in other components, so Σ 0 • Q is an r-tuple of vectors (v1, . . . vr) where r ≤ |Σ| and ψ(w ¯) ∈ {0,...,H0} and kψ(w ¯)k1 = kv k1 − 1. This com- |Σ| each vi ∈ N and kvik∞ ≤ M. pletes the description of the algorithm.
19 2016/1/19 Corollary 61. For a fixed alphabet Σ the Parikh member- there are runs α and β using algorithm from Lemma 60. The ship problem for (simple) one-counter automata is in P: number of possible choices is polynomial and for each choice there exists a polynomial-time algorithm that takes as an we execute a polynomial time procedure so the algorithm input a (simple) one-counter automaton A over Σ with n works in polynomial time. |Σ| states and a vector v ∈ N with components written in unary, and outputs some accepting run π of A with ψ(π) = v Lemma 64. For every fixed Σ there is a polynomial-time al- if such a run exists or “none” otherwise. gorithm for the following task: given a one-counter automa- Σ Lemma 62. For every fixed Σ there is a polynomial-time ton A over Σ and vectors v, v1,..., vr ∈ N , 0 ≤ r ≤ |Σ|, algorithm for the following task: given a one-counter au- with all numbers written in unary, decide if A has an ac- def cepting run π and directions d , . . . , d available at π such tomaton A over Σ, a sequence of 2|Σ| configurations C = 1 r Σ that ψ(π) = v and ψ(di) = vi for all i. (q1, c1), (q2, c2) ... (q2|Σ|, c2|Σ|) and a vector v ∈ N with all numbers written in unary, decide if A has an accepting run π such that ψ(π) = v and π contains C as a subsequence. Proof. First observe that if there is such a run π then according to Lemma 53 for every vi ∈ {v1 . . . v|Σ|} there is a Proof. Observe, that if there is such a run π then configu- pair of configurations such that it makes available a direction rations in C are cutting π into 2|Σ| + 1 fragments. Each of di where ψ(di) = vi. Thus for a set of vectors {v1 . . . v|Σ|} these fragments have its own Parikh image u1, u2 . . . u2|Σ|+1 there is a sequence C of 2|Σ| configurations such that it is that sum up to v. Thus the procedure iterates through all a subsequence of π and for every vector vi there is a pair of possible partitions of v into 2|Σ| + 1 vectors, and for each configurations in C which makes some direction di available such partition it checks if there exists a required set of runs: in sense of Lemma 53. between consecutive elements of C, a run from the initial Second observation is that the counter value of any con- configuration (q0, 0) to the first element of C and run form figuration C can not exceed kvk1; thus the sequence C has the last element of C to some accepting configuration. Each to be an element of a family of 2|Σ|-sequences of configu- of those small test can be done in polynomial time using al- rations bounded by kvk1. The size of this family is at most 2|Σ| gorithm form Lemma 60. The crucial fact is that the number (|A| · kvk1) . of possible partitions of v into 2|Σ| + 1 vectors is polynomial From above we derive a following procedure. For every in kvk1 as the dimension is fixed i.e. number of partitions is possible choice of the sequence C test: |Σ| 2|Σ|+1 bounded by (kvk1 ) . This implies that the presented procedure works in polynomial time. • if there is an accepting run π that contains C as a subsequence and where ψ(π) = v, Lemma 63. For every fixed Σ there is a polynomial-time • if for every v ∈ {v . . . v } there is a pair of configura- algorithm for the following task: given a one-counter au- i 1 |Σ| def tions in C which makes available (in sense of Lemma 53) tomaton A over Σ, a sequence of 2|Σ| configurations C = some direction di such that ψ(di) = vi. (q1, c1), (q2, c2) ... (q2|Σ|, c2|Σ|) and a vector v with all num- bers written in unary, decide if in A there exist a direc- The first item is handle by algorithm from Lemma 62, the tion hα, βi and two configurations (pi, ci), (pj , cj ) ∈ C where second by Lemma 63. i ≤ j such that: The proposed algorithm is polynomial time as the num- • ψ(hα, βi) = v, ber of possible C is polynomial in the size of the input and • init.state(α) = p , low(α) ≤ c and for each possible C we execute small number of times poly- i i nomial time algorithms from Lemmas 62 and 63. • init.state(β) = pj , low(β) ≤ cj + effect(α)