Keywords

1 Introduction

A classic idea in the theory of formal languages is the concept of boundedness of a language. A language L over an alphabet \(\varSigma \) is called bounded if there exists a number \(n\in \mathbb {N}\) and words \(w_1,\ldots ,w_n\in \varSigma ^*\) such that \(L\subseteq w_1^*\cdots w_n^*\). What makes boundedness important is that a rich variety of algorithmic problems become decidable for bounded languages. For example, when Ginsburg and Spanier [25] introduced boundedness in 1964, they already showed that given two context-free languages, one of them bounded, one can decide inclusion [25, Theorem 6.3]. This is because if \(L\subseteq w_1^*\cdots w_n^*\) for a context-free language, then the set \(\{(x_1,\ldots ,x_n)\in \mathbb {N}^n \mid w_1^{x_1}\cdots w_n^{x_n}\in L\}\) is effectively semilinear, which permits expressing inclusion in Presburger arithmetic. Here, boundedness is a crucial assumption: Hopcroft has shown that if \(L_0\subseteq \varSigma ^*\) is context-free, then the problem of deciding \(L_0\subseteq L\) for a given context-free language L is decidable if and only if \(L_0\) is bounded [35, Theorem 3.3].

The idea of translating questions about bounded languages into Presburger arithmetic has been applied in several other contexts. For example, Esparza, Ganty, and Majumdar [20] have shown that many classes of infinite-state systems are perfect modulo bounded languages, meaning that the bounded languages form a subclass that is amenable to many algorithmic problems. As another example, the subword ordering has a decidable first-order theory on bounded context-free languages [45], whereas on languages \(\varSigma ^*\), even the existential theory is undecidable [33]. This, in turn, implies that initial limit Datalog is decidable for the subword ordering on bounded context-free languages [7]. Finally, bounded context-free languages can be closely approximated by regular ones [16].

This raises the question of how one can decide whether a given language is bounded. For context-free languages this problem is decidable [25, Theorem 5.2(a)] in polynomial time [24, Theorem 19].

Boundedness for RBCA. Despite the importance of boundedness, it had been open for many years [9, 17]Footnote 1 whether boundedness is decidable for one of the most well-studied types of infinite-state systems: reversal-bounded (multi-)counter automata (RBCA). These are machines with counters that can be incremented, decremented, and even tested for zero. However, in order to achieve decidability of basic questions, there is a bound on the number of times each counter can reverse, that is, switch between incrementing and decrementing phases. They were first studied in the 1970s [2, 36] and have received a lot of attention since [8,9,10,11,12,13, 18, 23, 28, 32, 33, 39,40,41, 58]. The desirable properties mentioned above for bounded context-free languages also apply to bounded RBCA. Furthermore, any bounded language accepted by an RBCA (even one augmented with a stack) can be effectively determinized [38] (see also [9, 11]), opening up even more avenues to algorithmic analysis. This makes it surprising that decidability of boundedness remained open for many years.

Decidability of boundedness for RBCA was settled in [15], which proves boundedness decidable even for the larger class of vector addition systems with states (VASS), with acceptance by configuration. However, the results from [15] leave several aspects unclarified, which we investigate here:

  1. Q1:

    What is the complexity of deciding boundedness for RBCA? The algorithm in [15] employs the KLMST decomposition for VASS [43, 46, 48, 50, 54], which is well-known to incur Ackermannian complexity [49].

  2. Q2:

    Is boundedness decidable for pushdown RBCA (PRBCA) [36]? These are automata which, in addition to reversal-bounded counters, feature a stack. They can model recursive programs with numeric data types [32]. Whether boundedness is decidable was stated as open in [17, 18].

  3. Q3:

    Are there languages of RBCA of intermediate growth? As far as we know, this is a long-standing open question in itself [37]. The growth of a language \(L\subseteq \varSigma ^*\) is the counting function \(g_L:\mathbb {N}\rightarrow \mathbb {N}\), where \(g_L(n)\) is the number of words of length n in L. This concept is closely tied to boundedness: For regular and context-free languages, it is known that a language has polynomial growth if and only if it is bounded (and it has exponential growth otherwise). A language is said to have intermediate growth if it has neither polynomial nor exponential growth.

Contribution I: We prove versions of one of the main results in [15], one for RBCA and one for PRBCA. Specifically, the paper [15] not only shows that boundedness is decidable for VASS, but it introduces a general class of unboundedness predicates for formal languages. It is then shown in [15] that any unboundedness predicate is decidable for VASS if and only if it is decidable for regular languages. Our first two main results are:

  1. MR1:

    Deciding any unboundedness predicate for RBCA reduces in \(\textsf{NP}\) to deciding the same predicate for regular languages.

  2. MR2:

    Deciding any unboundedness predicate for PRBCA reduces in \(\textsf{NP}\) to deciding the same predicate for context-free languages.

However, it should be noted that our results only apply to those unboundedness predicates from [15] that are one-dimensional. Fortunately, these are enough for our applications. These results allow us to settle questions (Q1)–(Q3) above and derive the exact complexity of several other problems. It follows that boundedness for both RBCA and PRBCA is \(\textsf{coNP}\)-complete, thus answering (Q1) and (Q2). Furthermore, the proof shows that if boundedness of a PRBCA does not hold, then its language has exponential growth. This implies that there are no RBCA languages of intermediate growth (thus settling (Q3)), and even that the same holds for PRBCA. In particular, deciding polynomial growth of (P)RBCA is \(\textsf{coNP}\)-complete and deciding exponential growth of (P)RBCA is \(\textsf{NP}\)-complete. We can also derive from our result that deciding whether a (P)RBCA language is infinite is \(\textsf{NP}\)-complete (but this also follows easily from [32], see Section 2). Finally, our results imply that it is \(\textsf{PSPACE}\)-complete to decide if an RBCA language \(L\subseteq \varSigma ^*\) is factor universal, meaning it contains every word of \(\varSigma ^*\) as a factor (i.e. as an infix). Whether this problem is decidable for RBCA was also left as an open problem in [17, 18] (under the name infix density).

We prove our results (MR1) and (MR2) by first translating (P)RBCA into models that have \(\mathbb {Z}\)-counters instead of reversal-bounded counters. A \(\mathbb {Z}\)-counter is one that can be incremented and decremented, but cannot be tested for zero. Moreover, it can assume negative values. With these counters, acceptance is defined by reaching a configuration where all counters are zero (in particular, the acceptance condition permits a single zero-test on each counter). Here, finite automata with \(\mathbb {Z}\)-counters are called \(\mathbb {Z}\)-VASS [29]. \(\mathbb {Z}\)-counters are also known as blind counters [26] and it is a standard fact that RBCA are equivalent (in terms of accepted languages) to \(\mathbb {Z}\)-VASS [26, Theorem 2].

Despite the equivalence between RBCA and \(\mathbb {Z}\)-VASS being so well-known, there was apparently no known translation from RBCA to \(\mathbb {Z}\)-VASS in polynomial time. Here, the difficulty stems from simulating zero-tests (which can occur an unbounded number of times in an RBCA): To simulate these, the \(\mathbb {Z}\)-VASS needs to keep track of which counter has completed which incrementing/decrementing phase, using only polynomially many control states. It is also not obvious how to employ the \(\mathbb {Z}\)-counters for this, as they are only checked in the end.

Contribution II: As the first step of showing (MR1), we show that

  1. MR3:

    RBCA can be translated (preserving the language) into \(\mathbb {Z}\)-VASS in logarithmic space.

This also implies that translations to and from another equivalent model, Parikh automata [41], are possible in polynomial time: It was recently shown that Parikh automata (which have received much attention in recent years [6, 8,9,10, 13, 22]) can be translated in polynomial time into \(\mathbb {Z}\)-VASS [30]. Together with our new result, this implies that one can translate among RBCA, \(\mathbb {Z}\)-VASS, and Parikh automata in polynomial time. Furthermore, our result yields a logspace translation of PRBCA into \(\mathbb {Z}\)-grammars, an extension of context-free grammars with \(\mathbb {Z}\)-counters. The latter is the first step for (MR2).

2 Main Results: Unboundedness and (P)RBCA

Table 1. Complexity results. The completeness statements are meant with respect to deterministic logspace reductions.

Reversal-bounded counter automata and pushdowns. A pushdown automaton with k counters is a tuple \(\mathcal {A}= (Q,\varSigma ,\varGamma ,q_0,T,F)\) where Q is a finite set of states, \(\varSigma \) is an input alphabet, \(\varGamma \) is a stack alphabet, \(q_0 \in Q\) is an initial state, T is a finite set of transitions \((p,w,\textrm{op},q) \in Q \times \varSigma ^* \times \textrm{Op} \times Q\), and \(F\subseteq Q\) is a set of final states. Here \(\textrm{Op}\) is defined as

$$ \textrm{Op} = \{ \textsf{inc}_i, \textsf{dec}_i, \textsf{zero}_i, \textsf{nz}_i \mid 1 \le i \le k \} \cup \varGamma \cup \bar{\varGamma } \cup \{\varepsilon \}, $$

containing counter and stack operations. Here \(\bar{\varGamma } = \{ \bar{\gamma } \mid \gamma \in \varGamma \}\) is a disjoint copy of \(\varGamma \). A configuration is a tuple \((p,\alpha ,\boldsymbol{v}) \in Q \times \varGamma ^* \times \mathbb {N}^k\). We write \((p,\alpha ,\boldsymbol{u})\xrightarrow {w}(p',\alpha ',\boldsymbol{u}')\) if there is a \((p,w,\textrm{op},p')\in T\) such that one of the following holds:

  • \(\textrm{op} = \textsf{inc}_i\), \(\boldsymbol{u}' = \boldsymbol{u} + \boldsymbol{e}_i\), and \(\alpha ' = \alpha \) where \(\boldsymbol{e}_i \in \mathbb {N}^k\) is the i-th unit vector,

  • \(\textrm{op} = \textsf{dec}_i\), \(\boldsymbol{u}' = \boldsymbol{u} - \boldsymbol{e}_i\), and \(\alpha ' = \alpha \),

  • \(\textrm{op} = \textsf{zero}_i\), \(\boldsymbol{u}[i] = 0\), \(\boldsymbol{u}' = \boldsymbol{u}\), and \(\alpha ' = \alpha \)

  • \(\textrm{op} = \textsf{nz}_i\), \(\boldsymbol{u}[i] \ne 0\), \(\boldsymbol{u}' = \boldsymbol{u}\), and \(\alpha ' = \alpha \),

  • \(\textrm{op} = \gamma \in \varGamma \), \(\boldsymbol{u}' = \boldsymbol{u}\), and \(\alpha ' = \alpha \gamma \),

  • \(\textrm{op} = \bar{\gamma } \in \bar{\varGamma }\), \(\boldsymbol{u}' = \boldsymbol{u}\), and \(\alpha ' \gamma = \alpha \),

  • \(\textrm{op} = \varepsilon \), \(\boldsymbol{u}' = \boldsymbol{u}\), and \(\alpha ' = \alpha \).

We extend this notation to longer runs in the natural way.

A (kr)-PRBCA (pushdown reversal-bounded counter automaton) \((\mathcal {A},r)\) consists of a pushdown automaton with k counters \(\mathcal {A}\) and a number \(r \in \mathbb {N}\), encoded in unary. A counter \(\textsf{c}_i\) reverses if the last (non-test) operation affecting it was \(\textsf{inc}_i\) and the next operation is \(\textsf{dec}_i\), or vice versa. A run is r-reversal bounded if every counter reverses at most r times. The language of \((\mathcal {A},r)\) is

$$ \begin{aligned} L(\mathcal {A},r)=\{w\in \varSigma ^* \mid&~\exists q\in F,~r\text {-reversal bounded run } (q_0,\varepsilon ,\boldsymbol{0})\xrightarrow {w}(q,\varepsilon ,\boldsymbol{0}) \}. \end{aligned} $$

A (kr)-RBCA (reversal-bounded counter automaton) is a (kr)-PRBCA where \(\mathcal {A}\) only uses counter operations. We denote by \(\textsf{RBCA}\) and \(\textsf{PRBCA}\) the class of (P)RBCA languages.

Notice that we impose the reversal bound externally (following [32]) whereas in alternative definitions found in the literature the automaton has to ensure internally that the number of reversals on every (accepting) run does not exceed r, e.g. [36]. Clearly, our definition subsumes the latter one; in particular, Theorem 1 also holds for (P)RBCAs with an internally checked reversal bound.

A d-dimensional \(\mathbb {Z}\)-VASS (\(\mathbb {Z}\)-vector addition system with states) is a tuple \(\mathcal {V}=(Q,\varSigma ,q_0,T,F)\), where Q is a finite set of states, \(\varSigma \) is an alphabet, \(q_0 \in Q\) is an initial state, T is a finite set of transitions \((p,w,\boldsymbol{v},p') \in Q \times \varSigma ^* \times \mathbb {Z}^d \times Q\), and \(F\subseteq Q\) is a set of final states. A configuration of a \(\mathbb {Z}\)-VASS is a tuple \((p,\boldsymbol{v}) \in Q \times \mathbb {Z}^d\). We write \((p,\boldsymbol{u})\xrightarrow {w}(p',\boldsymbol{u}')\) if there is a transition \((p,w,\boldsymbol{v},p')\) such that \(\boldsymbol{u}'=\boldsymbol{u}+\boldsymbol{v}\). We extend this notation to longer runs in the natural way. The language of the \(\mathbb {Z}\)-VASS is defined as

$$\begin{aligned} L(\mathcal {V})=\{w\in \varSigma ^* \mid \exists q\in F:~(q_0,\boldsymbol{0})\xrightarrow {w}(q,\boldsymbol{0})\}. \end{aligned}$$

A (d-dimensional) \(\mathbb {Z}\)-grammar is a tuple \(G = (N,\varSigma ,S,P)\) with disjoint finite sets N and \(\varSigma \) of nonterminal and terminal symbols, a start nonterminal \(S \in N\), and a finite set of productions P of the form \((A,u,\boldsymbol{v}) \in N \times (N \cup \varSigma )^* \times \mathbb {Z}^d\). We also write \((A\rightarrow u,\boldsymbol{v})\) instead of \((A,u,\boldsymbol{v})\). We call \(\boldsymbol{v}\) the (counter) effect of the production \((A \rightarrow u,\boldsymbol{v})\). For words \(x,y\in (N\cup \varSigma )^{*}\), we write if there is a production \((A\rightarrow u,\boldsymbol{v})\) such that \(x=rAs\) and \(y=rus\). Moreover, we write if there are words \(x_1,\ldots ,x_n\in (N\cup \varSigma )^*\) and \(\boldsymbol{v}_1,\ldots ,\boldsymbol{v}_n\in \mathbb {Z}^d\) with and \(\boldsymbol{v}=\boldsymbol{v}_1+\cdots +\boldsymbol{v}_n\). We use the notation if the counter effects do not matter: We have if there exists \(\boldsymbol{v}\) such that ; and similarly for . If derivations are restricted to a subset \(Q\subseteq P\) of productions, we write (resp. ).

The language of the \(\mathbb {Z}\)-grammar G is the set of all words \(w \in \varSigma ^*\) such that . In other words, if there exists a derivation where the effects of all occurring productions sum to the zero vector \(\boldsymbol{0}\). \(\mathbb {Z}\)-grammars of dimension d are also known as valence grammars over \(\mathbb {Z}^d\) [21].

For our purposes it suffices to assume a unary encoding of the \(\mathbb {Z}^d\)-vectors (effects) occurring in \(\mathbb {Z}\)-VASS and \(\mathbb {Z}\)-grammars. However, this is not a restriction: Counter updates with n-bit binary encoded numbers can be easily simulated with unary encodings at the expense of dn many fresh counters (see the full version [5]).

Conversion results. The following is our first main theorem:

Theorem 1

RBCA can be converted into \(\mathbb {Z}\)-VASS in logarithmic space. PRBCA can be converted into \(\mathbb {Z}\)-grammars in logarithmic space.

By convert, we mean a translation that preserves the accepted (resp. generated) language. There are several machine models that are equivalent (in terms of accepted languages) to RBCA. With Theorem 1, we provide the last missing translation:

Corollary 1

The following models can be converted into each other in logarithmic space: (i) RBCA, (ii) \(\mathbb {Z}\)-VASS, (iii) Parikh automata with \(\exists \)PA acceptance, and (iv) Parikh automata with semilinear acceptance.

Roughly speaking, a Parikh automaton is a machine with counters that can only be incremented. Then, a run is accepting if the final counter values belong to some semilinear set. Parikh automata were introduced by Klaedtke and Rueß [41], where the acceptance condition is specified using a semilinear representation (with base and period vectors), yielding (iv) above. As done, e.g., in [33], one could also specify it using an existential Presburger formula (briefly \(\exists \)PA), yielding the model in (iii) above. Theorem 1 proves (i)\(\Rightarrow \)(ii), whereas (ii)\(\Rightarrow \)(i) is easy (a clever and very efficient translation is given in [40, Theorem 4.5]). Moreover, (ii)\(\Rightarrow \)(iii) and (ii)\(\Rightarrow \)(iv) are clear as well. For (iii)\(\Rightarrow \)(ii), one can proceed as in [30, Prop. V.1], and (iv)\(\Rightarrow \)(ii) is also simple.

Unboundedness predicates. We shall use Theorem 1 to prove our second main theorem, which involves unboundedness predicates as introduced in [15]. In [15], unboundedness predicates can be one-dimensional or multi-dimensional, but in this work, we only consider one-dimensional unboundedness predicates.

Let \(\varSigma \) be an alphabet. A (language) predicate is a set of languages over \(\varSigma \). If \(\mathfrak {p}\) is a predicate and \(L\subseteq \varSigma ^*\) is a language, then we write \(\mathfrak {p}(L)\) to denote that \(\mathfrak {p}\) holds for the language L (i.e. \(L \in \mathfrak {p}\)). A predicate \(\mathfrak {p}\) is called a (one-dimensional) unboundedness predicate if the following conditions are met for all \(K,L\subseteq \varSigma ^*\):

figure l

Here \(F(L)=\{v\in \varSigma ^* \mid \exists u,w\in \varSigma ^*:uvw\in L\}\) is the set of factors of L (sometimes also called infixes). In particular, the last condition says that \(\mathfrak {p}\) only depends on the set of factors occurring in a language.

For an unboundedness predicate \(\mathfrak {p}\) and a class \(\mathcal {C}\) of finitely represented languages (such as automata or grammars), let \(\mathfrak {p}(\mathcal {C})\) denote the problem of deciding \(\mathfrak {p}\) for a given language L from \(\mathcal {C}\). Formally, \(\mathfrak {p}(\mathcal {C})\) is the following decision problem:

  • Given A language L from \(\mathcal {C}\).

  • Question Does \(\mathfrak {p}(L)\) hold?

For example, \(\mathfrak {p}(\textsf{RBCA})\) is the problem of deciding \(\mathfrak {p}\) for reversal-bounded multi-counter automata and \(\mathfrak {p}(\textsf{NFA})\) is the problem of deciding \(\mathfrak {p}\) for NFAs. We mention that the axioms (U1)–(U4) are slightly stronger than the axioms used in [15], but the resulting set of decision problems is the same with either definition (since in [15], one always decides whether \(\mathfrak {p}(F(L))\) holds). Thus, the statement of Theorem 2 is unaffected by which definition is used. See the full version [5] for details.

The following examples of (one-dimensional) unboundedness predicates for languages \(L\subseteq \varSigma ^*\) have already been established in [15]. We mention them here to give an intuition for the range of applications of our results:

  • Not being bounded Let \(\mathfrak {p}_{\textsf{notb}}(L)\) if and only if L is not a bounded language.

  • Non-emptiness Let \(\mathfrak {p}_{\ne \emptyset }(L)\) if and only if \(L\ne \emptyset \).

  • Infinity Let \(\mathfrak {p}_{\infty }(L)\) if and only if L is infinite.

  • Factor-universality Let \(\mathfrak {p}_{\textsf{funi}}(L)\) if and only if \(\varSigma ^*\subseteq F(L)\).

It is not difficult to prove that these are unboundedness predicates, but proofs can be found in [15]. The following is our second main theorem:

Theorem 2

Let \(\mathfrak {p}\) be a one-dimensional unboundedness predicate. There is an \(\textsf{NP}\) reduction from \(\mathfrak {p}(\textsf{PRBCA})\) to \(\mathfrak {p}(\textsf{PDA})\). Moreover, there is an \(\textsf{NP}\) reduction from \(\mathfrak {p}(\textsf{RBCA})\) to \(\mathfrak {p}(\textsf{NFA})\).

Here, an \(\textsf{NP}\) reduction from problem \(A\subseteq \varSigma ^*\) to \(B\subseteq \varSigma ^*\) is a non-deterministic polynomial-time Turing machine such that for every input word \(w\in \varSigma ^*\), we have \(w \in A\) iff there exists a run of the Turing machine producing a word in B.

Let us now see some applications of Theorem 2, see also Table 1. The following completeness results are all meant w.r.t. deterministic logspace reductions.

Corollary 2

Boundedness for \(\textsf{PRBCA}\) and for \(\textsf{RBCA}\) is \(\textsf{coNP}\)-complete.

For Corollary 2, we argue that deciding non-boundedness is \(\textsf{NP}\)-complete. To this end, we apply Theorem 2 to the predicate \(\mathfrak {p}_{\textsf{notb}}\) and obtain an \(\textsf{NP}\) upper bound, because boundedness for context-free languages is decidable in polynomial time [24]. The \(\textsf{NP}\) lower bound follows easily from \(\textsf{NP}\)-hardness of the non-emptiness problem for \(\textsf{RBCA}\) [28, Theorem 3] and thus \(\textsf{PRBCA}\).

Corollary 3

Finiteness for \(\textsf{PRBCA}\) and for \(\textsf{RBCA}\) is \(\textsf{coNP}\)-complete.

We show Corollary 3 by proving that checking infinity is \(\textsf{NP}\)-complete. The upper bound follows from Theorem 2 via the predicate \(\mathfrak {p}_\infty \). As above, \(\textsf{NP}\)-hardness is inherited from the non-emptiness problem for \(\textsf{RBCA}\) and \(\textsf{PRBCA}\).

The results in Corollary 3 are, however, not new. They follow directly from the fact that for a given \(\textsf{PRBCA}\) (or \(\textsf{RBCA}\)), one can construct in polynomial time a formula in existential Presburger arithmetic (\(\exists \)PA) for its Parikh image, as shown in [36] for RBCA and in [32] for PRBCA. It is a standard result about \(\exists \)PA that for each formula \(\varphi \), there exists a bound B such that (i) B is at most exponential in the size of \(\varphi \) and (ii) \(\varphi \) defines an infinite set if and only if \(\varphi \) is satisfied for some vector with some entry above B. For example, this can be deduced from [53]. Therefore, one can easily construct a second \(\exists \)PA formula \(\varphi '\) such that \(\varphi \) defines an infinite set if and only if \(\varphi '\) is satisfiable.

Corollary 4

Factor universality for \(\textsf{RBCA}\) is \(\textsf{PSPACE}\)-complete.

Whether factor universality is decidable for \(\textsf{RBCA}\) was left as an open problem in [17, 18] (there under the term infix density). Corollary 4 follows from Theorem 2 using \(\mathfrak {p}_{\textsf{funi}}\), because factor universality for NFAs is \(\textsf{PSPACE}\)-complete: To decide if \(\varSigma ^*\subseteq F(R)\), for a regular language R, we can just compute an automaton for F(R) and check inclusion in \(\textsf{PSPACE}\). For the lower bound, one can reduce the \(\textsf{PSPACE}\)-complete universality problem for NFAs, since for \(R\subseteq \varSigma ^*\), the language \((R\#)^*\subseteq (\varSigma \cup \{\#\})^*\) is factor universal if only if \(R=\varSigma ^*\). Note that factor universality is known to be undecidable already for one-counter languages [18], and thus in particular for \(\textsf{PRBCA}\). However, it is decidable for pushdown automata with a bounded number of reversals of the stack [18].

Beyond pushdowns. Theorem 2 raises the question of whether for any class \(\mathcal {M}\) of machines, one can reduce any unboundedness predicates for \(\mathcal {M}\) extended with reversal-bounded counters to the same predicate for just \(\mathcal {M}\). This is not the case: For example, consider second-order pushdown automata, short 2-PDA. If we extend these by adding reversal-bounded counters, then we obtain 2-PRBCA. Then, the infinity problem is decidable for 2-PDA [34] (see [3, 4, 14, 31, 52, 56] for stronger results). However, the class of 2-PRBCA does not even have decidable emptiness, let alone decidable infinity. This is shown in [57, Proposition 7] (see [42, Theorem 4] for an alternative proof). Thus, infinity for 2-PRBCA cannot be reduced to infinity for 2-PDA.

Growth. Finally, we employ the methods of the proof of Theorem 2 to show a dichotomy of the growth behavior of languages accepted by RBCA. For an alphabet \(\varSigma \), we denote by \(\varSigma ^{\le m}\) the set of all words over \(\varSigma \) of length at most m. We say that a language \(L\subseteq \varSigma ^*\) has polynomial growthFootnote 2 if there is a polynomial p(x) such that \(|L\cap \varSigma ^{\le m}|\le p(m)\) for all \(m\ge 0\). Languages of polynomial growth are also called sparse or poly-slender. We say that L has exponential growth if there is a real number \(r>1\) such hat \(|L\cap \varSigma ^{\le m}|\ge r^m\) for infinitely many m. Since a language of the form \(w_1^*\cdots w_n^*\) clearly has polynomial growth, it is well-known that bounded languages have polynomial growth. We show that (a) within the PRBCA languages (and in particular within the RBCA languages), the converse is true as well and (b) all other languages have exponential growth (in contrast to some models, such as 2-PDA [27], where this dichotomy does not hold):

Theorem 3

Let L be a language accepted by a PRBCA. Then L has polynomial growth if and only if L is bounded. If L is not bounded, it has exponential growth.

3 Translating reversal-bounded counters into \(\mathbb {Z}\)-counters

Reducing the number of reversals to one. In this section we prove Theorem 1, the conversion from RBCA to \(\mathbb {Z}\)-VASS. In [28, Lemma 1], it is claimed that given a (kr)-RBCA, one can construct in time polynomial in k and r a \((k\lceil (r+1)/2\rceil ,1)\)-RBCA that accepts the same language. The reference [2] that they provide does include such a construction [2, proof of Theorem 5]. The construction in [2] is only a rough sketch and makes no claims about complexity, but by our reading of the construction, it keeps track of the reversals of each counter in the state, which would result in an exponential blow-up.

Instead, we proceed as follows. Consider a (kr)-RBCA with counters \(\textsf{c}_1, \dots , \textsf{c}_k\). Without loss of generality, assume \(r=2m-1\). We will construct an equivalent \((2k(r+1),1)\)-RBCA. Looking at the behavior of a single counter \(\textsf{c}_i\), we can decompose every r-reversal bounded run into subruns without reversals. We call these subruns phases and number them from 1 to at most 2m. The odd (even) numbered phases are positive (negative), where \(\textsf{c}_i\) is only incremented (decremented). We replace \(\textsf{c}_i\) by m one-reversal counters \(\textsf{c}_{i,1}, \dots , \textsf{c}_{i,m}\), where \(\textsf{c}_{i,j}\) records the increments on \(\textsf{c}_i\) during the positive phase \(2j-1\).

However, our machine needs to keep track of which counters are in which phase, in order to know which of the counters \(\textsf{c}_{i,j}\) it currently has to use. We achieve this as follows: For each of the k counters \(\textsf{c}_i\), we also have an additional set of \(2m = r + 1\) “phase counters” \(\textsf{p}_{i,1}, \dots , \textsf{p}_{i,2m}\) to store which phase we are in. This gives \(km+k(r+1)\le 2k(r+1)\) counters in total. We encode that counter \(\textsf{c}_i\) is in phase j by setting \(\textsf{p}_{i,j}\) to 1 and setting \(\textsf{p}_{i,j'}\) to 0 for each \(j' \ne j\). Since we only ever increase the phase, the phase counters are one-reversal as well.

Using non-zero-tests, at any point, the automaton can nondeterministically guess and verify the current phase of each counter. This allows it to pick the correct counter \(\textsf{c}_{i,j}\) for each instruction. When counter \(\textsf{c}_i\) is in a positive phase \(2j-1\), then increments and decrements on \(\textsf{c}_i\) are simulated as follows:

  • increment increment \(\textsf{c}_{i,j}\)

  • decrement go into the next (negative) phase 2j; then non-deterministically pick some \(\ell \in [1,j]\) and decrement \(\textsf{c}_{i,\ell }\). We cannot simply decrement \(\textsf{c}_{i,j}\) as we might have switched to phase j while \(\textsf{c}_i\) had a non-zero value and hence it is possible that \(\textsf{c}_i\) could be decremented further than just \(\textsf{c}_{i,j}\) allows.

When counter \(\textsf{c}_i\) is in a negative phase 2j, then we simulate increments and decrements as follows:

  • increment go into the next phase \(2j+1\) (unless \(j = m\); then the machine blocks) and increment \(\textsf{c}_{i,j+1}\).

  • decrement non-deterministically pick some \(\ell \in [1,j]\) and decrement \(\textsf{c}_{i,\ell }\).

Finally, to simulate a zero-test on \(\textsf{c}_i\), we test all counters \(\textsf{c}_{i,1},\ldots ,\textsf{c}_{i,m}\) for zero, while for the simulation of a non-zero-test on \(\textsf{c}_i\) we non-deterministically pick one of the counters \(\textsf{c}_{i,1},\ldots ,\textsf{c}_{i,m}\) to test for non-zero.

Correctness can be easily verified by the following properties. If at some point \(\textsf{c}_i\) is in phase \(2j-1\) or 2j then (i) \(\sum _{\ell =1}^{j} \textsf{c}_{i,\ell } = \textsf{c}_i\), (ii) the counters \(\textsf{c}_{i,1}, \dots , \textsf{c}_{i,j}\) have made at most one reversal, and (iii) the counters \(\textsf{c}_{i,j+1}, \dots , \textsf{c}_{i,m}\) have not been touched (in particular, they are zero). Furthermore, if \(\textsf{c}_i\) is in a positive phase \(2j-1\) then \(\textsf{c}_{i,j}\) has made no reversal yet.

Note that this construction replaces every transition of the original system with \(\mathcal {O}(r)\) new transitions (and states). Our construction therefore yields only a linear blowup in the size of the system (constant if r is fixed). See the full version [5] for the details of the construction.

From 1-reversal to \(\mathbb {Z}\)-counters. We now turn the (k, 1)-RBCA into a \(\mathbb {Z}\)-VASS. The difference between a 1-reversal-bounded counter and a \(\mathbb {Z}\)-counter is that (i) a non-negative counter should block if it is decremented on counter value 0, and (ii) a 1-reversal-bounded counter allows (non-)zero-tests. Observe that all zero-tests occur before the first increment or after the last decrement. All non-zero-tests occur between the first increment and the last decrement.

If the number k of counters is bounded, then the following simple solution works. The \(\mathbb {Z}\)-VASS stores the information which of the counters has not been incremented yet and which counters will not be incremented again in the future. This information suffices to simulate the counters faithfully (in terms of the properties (i) and (ii) above) and increases the state space by a factor of \(2^k \cdot 2^k\). The latter information needs to be guessed (by the automaton) and is verified by means that all counters are zero in the end.

In the general case we introduce a variant of \(\mathbb {Z}\)-VASS that can guess polynomially many bits in the beginning and read them throughout the run. A d-dimensional \(\mathbb {Z}\)-VASS with guessing (\(\mathbb {Z}\)-VASSG) has almost the same format as a d-dimensional \(\mathbb {Z}\)-VASS, except that each transition additionally carries a propositional formula over some finite set of variables X. A word \(w \in \varSigma ^*\) is accepted by the \(\mathbb {Z}\)-VASSG if there exists an assignment \(\nu :X \rightarrow \{0,1\}\) and an accepting run \((q_0,\boldsymbol{0}) \xrightarrow {w} (q,\boldsymbol{0})\) for some \(q \in F\) such that all formulas appearing throughout the run are satisfied by \(\nu \).

We have to eliminate zero- and non-zero-tests of the (k, 1)-RBCA. Whether a (non-)zero-test is successful depends on which phase a counter is currently in (and whether in the end, every counter is zero; but we assume that our acceptance condition ensures this). Each counter goes through at most 4 phases:

figure m

Hence, every run can be decomposed into 4k (possibly empty) segments, in which no counter changes its phase. The idea is to guess the phase of each counter in each segment. Hence, we have propositional variables \(\texttt{p}_{i,j,\ell }\) for \(i\in [1,4k]\), \(j\in [1,k]\), and \(\ell \in [1,4]\). Then \(\texttt{p}_{i,j,\ell }\) is true iff in segment i, counter j is in phase \(\ell \). We will have to check that the assignment is admissible for each counter, meaning that the sequence of phases for each counter adheres to the order described above.

We modify the machine as follows. In its state, it keeps a number \(i\in [1,4k]\) which holds the current segment. At the beginning of the run, the machine checks that the assignment \(\nu \) is admissible using a propositional formula: It checks that (i) for each segment i and each counter j there exists exactly one phase \(\ell \) so that \(\texttt{p}_{i,j,\ell }\) is true, and (ii) the order of phases above is obeyed. Then, for every operation on a counter, the machine checks that the operation is consistent with the current segment. Moreover, if the current operation warrants a change of the segment, then the segment counter i is incremented. For example, if a counter in phase 1 is incremented, it switches to phase 2 and the segment counter is incremented; or, if a counter in phase 3 is tested for zero, it switches to phase 4 and the segment counter is incremented.

With these modifications, we can zero-test by checking variables corresponding to the current segment: A zero-test can only succeed in phase 1 and 4. Similarly, for a non-zero-test, we can check if the counter is in phase 2 or 3.

Turning a \(\mathbb {Z}\)-VASSG into a \(\mathbb {Z}\)-VASS. To handle the general case mentioned above, we need to show how to convert \(\mathbb {Z}\)-VASSG into ordinary \(\mathbb {Z}\)-VASS. In a preparatory step, we ensure that each formula is a literal. A transition labeled by a formula \(\varphi \) is replaced by a series-parallel graph: After bringing \(\varphi \) in negation normal form by pushing negations inwards, we can replace conjunctions by a series composition and disjunctions by a parallel composition (non-determinism).

The \(\mathbb {Z}\)-VASS works as follows. In addition to the original counters of the \(\mathbb {Z}\)-VASSG, it has for each variable \(\texttt{x}\in X\) two additional counters: \(\texttt{x}^+\) and \(\texttt{x}^-\). Here, \(\texttt{x}^+\) (\(\texttt{x}^-\)) counts how many times \(\texttt{x}\) is read with a positive (negative) assignment. By making sure that either \(\texttt{x}^+=0\) or \(\texttt{x}^-=0\) in the end, we guarantee that we always read the same value of \(\texttt{x}\).

Thus, in order to check a literal, our \(\mathbb {Z}\)-VASS increments the corresponding counter. In the end, before reaching a final state, it goes through each variable \(\texttt{x}\in X\) and either enters a loop decrementing \(\texttt{x}^+\) or a loop decrementing \(\texttt{x}^-\). Then, it can reach the zero vector only if all variable checks had been consistent.

From PRBCA to \(\mathbb {Z}\)-grammars. It remains to convert in logspace an (rk)-PRBCA into an equivalent \(\mathbb {Z}\)-grammar. Just as for converting an RBCA into a \(\mathbb {Z}\)-VASS, one can convert a PRBCA into an equivalent \(\mathbb {Z}\)-PVASS (pushdown vector addition system with \(\mathbb {Z}\)-counters). Afterwards, one applies the classical transformation from pushdown automata to context-free grammars (a.k.a. triple construction), cf. [1, Lemma 2.26]: We introduce for every state pair (pq) a nonterminal \(X_{p,q}\), deriving all words which are read between p to q (starting and ending with empty stacks). For example, we introduce productions \(X_{p,q} \rightarrow a X_{p',q'} b\) for all push transitions \((p, a, \gamma , p')\) and pop transitions \((q', b, \bar{\gamma }, q)\). The counter effects of transitions in the \(\mathbb {Z}\)-PVASS (vectors in \(\mathbb {Z}^k\)) are translated into effects of the productions, e.g. the effect of the production \(X_{p,q} \rightarrow a X_{p',q'} b\) above is the sum of the effects of the corresponding push- and pop-transition.

4 Deciding unboundedness predicates

Proof overview. In this section, we prove Theorem 2. Let us begin with a sketch. Our task is to take a PRBCA \(\mathcal {A}\) and non-deterministically compute a PDA \(\mathcal {A}'\) so that \(L(\mathcal {A})\) satisfies \(\mathfrak {p}\) if and only if some of the outcomes for \(\mathcal {A}'\) satisfy \(\mathfrak {p}\). It will be clear from the construction that if the input was an RBCA, then the resulting PDA will be an NFA. Using Theorem 1 we will phrase the main part of the reduction in terms of \(\mathbb {Z}\)-grammars, meaning we take a \(\mathbb {Z}\)-grammar G as input and non-deterministically compute context-free grammars \(G'\).

The idea of the reduction is to identify a set of productions in G that, in some appropriate sense, can be canceled (regarding the integer counter values) by a collection of other productions. Then, \(G'\) is obtained by only using a set of productions that can be canceled. Moreover, these productions are used regardless of what counter updates they perform. Then, to show the correctness, we argue in two directions: First, we show that any word derivable by \(G'\) occurs as a factor of L(G). Essentially, this is because each production used in \(G'\) can be canceled by adding more productions in G, thus yielding a complete derivation of G. Thus, we have that \(L(G')\subseteq F(L(G))\), which by the axioms of unboundedness predicates means that \(\mathfrak {p}(L(G'))\) implies \(\mathfrak {p}(L(G))\). Second, we show that L(G) is a finite union of products (i.e. concatenations) \(P_i = L_1 \cdot L_2 \cdots L_k\) such that each \(L_i\) is either finite or included in \(L(G')\) for some \(G'\) among all non-deterministic outcomes. Again, by the axioms of unboundedness predicates, this means that if \(\mathfrak {p}(L(G))\), then \(\mathfrak {p}(L(G'))\) must hold for some \(G'\).

Unboundedness predicates and finite languages. Before we start with the proof, let us observe that we may assume that our unboundedness predicate is only satisfied for infinite sets. First, suppose \(\mathfrak {p}\) is satisfied for \(\{\varepsilon \}\). This implies that \(\mathfrak {p}=\mathfrak {p}_{\ne \emptyset }\) and hence we can just decide whether \(\mathfrak {p}(L)\) by deciding whether \(L\ne \emptyset \), which can be done in \(\textsf{NP}\) [32]. From now on, suppose that \(\mathfrak {p}\) is not satisfied for \(\{\varepsilon \}\). Consider the alphabet \(\varSigma _1:=\{a\in \varSigma \mid \mathfrak {p}(\{a\})\}\). Now observe that if \(K\subseteq \varSigma ^*\) is finite, then by the axioms of unboundedness predicates, we have \(\mathfrak {p}(K)\) if and only if some letter from \(\varSigma _1\) appears in K. Thus, if \(L\subseteq (\varSigma \setminus \varSigma _1)^*\), then \(\mathfrak {p}(L)\) can only hold if L is infinite. This motivates the following definition. Given a language \(L\subseteq \varSigma ^*\), we define

$$\begin{aligned} \begin{aligned} L_0=L\cap (\varSigma \setminus \varSigma _1)^*, \quad \ L_1=L\cap \varSigma ^*\varSigma _1\varSigma ^*. \end{aligned} \end{aligned}$$

Then, \(\mathfrak {p}(L)\) if and only if \(\mathfrak {p}(L_0)\) or \(\mathfrak {p}(L_1)\). Moreover, \(\mathfrak {p}(L_1)\) is equivalent to \(L_1\ne \emptyset \).

Therefore, our reduction proceeds as follows. We construct (P)RBCA for \(L_0\) and for \(L_1\). This can be done in logspace, because intersections with regular languages can be done with a simple product construction. Then, we check in \(\textsf{NP}\) whether \(L_1\ne \emptyset \). If yes, then we return “unbounded”. If no, we regard \(\mathfrak {p}\) as an unboundedness predicate on languages over \(\varSigma \setminus \varSigma _1\) with the additional property that \(\mathfrak {p}\) is only satisfied for infinite languages. Thus, it suffices to prove Theorem 2 in the case that \(\mathfrak {p}\) is only satisfied for infinite sets.

Pumps and cancelation. In order to define our notion of cancelable productions, we need some terminology. We will need to argue about derivation trees for \(\mathbb {Z}\)-grammars. For any alphabet \(\varGamma \) and \(d\in \mathbb {N}\), let \(\mathcal {T}_{\varGamma ,d}\) be the set of all finite trees where every node is labeled by both (i) a letter from \(\varGamma \) and (ii) a vector from \(\mathbb {Z}^d\). Suppose \(G=(N,\varSigma ,P,S)\) is a d-dimensional \(\mathbb {Z}\)-grammar. For a production \(p = (A \rightarrow u,\boldsymbol{v})\), we write \(\varphi (p):=\boldsymbol{v}\) for its associated counter effect. To each derivation in G, we associate a derivation tree from \(\mathcal {T}_{N \cup \varSigma ,d}\) as for context-free grammars. The only difference is that whenever we apply a production \((A\rightarrow u,\boldsymbol{v})\), then the node corresponding to the rewritten A is also labeled with \(\boldsymbol{v}\). As in context-free grammars, the leaf nodes carry terminal letters; their vector label is just \(\boldsymbol{0}\in \mathbb {Z}^d\).

We extend the map \(\varphi \) to both vectors in \(\mathbb {N}^P\) and to derivation trees. If \(\boldsymbol{u}\in \mathbb {N}^P\), then \(\varphi (\boldsymbol{u}) = \sum _{p \in P}\varphi (p) \cdot \boldsymbol{u}[p]\). Similarly, if \(\tau \) is a derivation tree, then \(\varphi (\tau )\in \mathbb {Z}^d\) is the sum of all labels from \(\mathbb {Z}^d\). A derivation tree \(\tau \) for a derivation is called complete if \(A = S\), \(u \in \varSigma ^*\) and \(\varphi (\tau ) = \boldsymbol{0}\). In other words, \(\tau \) derives a terminal word and the total counter effect of the derivation is zero. For such a complete derivation, we also write \(\textsf{yield}(\tau )\) for the word u. A derivation tree \(\tau \) is called a pump if it is the derivation tree of a derivation of the form for some \(u,v\in \varSigma ^*\) and \(A\in N\). A subset \(M\subseteq N\) of the non-terminals is called realizable if there exists a complete derivation of G that contains all non-terminals in M and no non-terminals outside of M.

A production p in P is called M-cancelable if there exist pumps \(\tau _1,\ldots ,\tau _k\) (for some \(k\in \mathbb {N}\)) such that (i) p occurs in some \(\tau _i\) and (ii) \(\varphi (\tau _1)+\cdots +\varphi (\tau _k)=\boldsymbol{0}\), i.e. the total counter effect of \(\tau _1,\ldots ,\tau _k\) is zero and (iii) all productions in \(\tau _1,\ldots ,\tau _k\) only use non-terminals from M. We say that a subset \(Q\subseteq P\) is M-cancelable if all productions in Q are M-cancelable.

The reduction. Using the notions of M-cancelable productions, we are ready to describe how the context-free grammars are constructed. Suppose that M is realizable, that \(Q\subseteq P\) is M-cancelable, and that \(A\in M\). Consider the language

figure p

Thus \(L_{A,Q}\) consists of all words u and v appearing in derivations (whose counter values are not necessarily zero) of the form , if we only use M-cancelable productions. The \(L_{A,Q}\) will be the languages \(L(G')\) mentioned above.

It is an easy observation that we can, given G and a subset \(Q\subseteq P\), construct a context-free grammar for \(L_{A,Q}\):

Lemma 1

Given a \(\mathbb {Z}\)-grammar G, a non-terminal A, and a subset \(Q\subseteq P\), we can construct in logspace a context-free grammar for \(L_{A,Q}\). Moreover, if G is left-linear, then the construction yields an NFA for \(L_{A,Q}\).

We provide details in the full version [5]. Now, our reduction works as follows:

  1. 1.

    Guess a subset \(M\subseteq N\) and an \(A\in M\); verify that M is realizable.

  2. 2.

    Guess a subset \(Q\subseteq P\); verify that Q is M-cancelable.

  3. 3.

    Compute a context-free grammar for \(L_{A,Q}\).

Here, we need to show that steps 1 and 2 can be done in \(\textsf{NP}\):

Lemma 2

Given a subset \(M\subseteq N\), we can check in \(\textsf{NP}\) whether M is realizable. Moreover, given \(M\subseteq N\) and \(p\in P\), we can check in \(\textsf{NP}\) if p is M-cancelable.

Both can be done using the fact that for a given context-free grammar, one can construct a Parikh-equivalent existential Presburger formula [55] and the fact that satisfiability of existential Presburger formulas is in \(\textsf{NP}\). See the full version [5] for details. This completes the description of our reduction. Therefore, it remains to show correctness of the reduction. In other words, to prove:

Proposition 1

We have \(\mathfrak {p}(L(G))\) if and only if \(\mathfrak {p}(L_{A,Q})\) for some subset \(Q\subseteq P\) such that there is a realizable \(M\subseteq N\) with \(A\in M\) and Q being M-cancelable.

Proposition 1 will be shown in two lemmas:

Lemma 3

If M is realizable and Q is M-cancelable, then \(L_{A,Q}\subseteq F(L(G))\) for every \(A\in M\).

Lemma 4

L(G) is included in a finite union of sets of the form \(K_1 \cdot K_2 \cdots K_m\), where each \(K_i\) is either finite or a set \(L_{A,Q}\), where Q is M-cancelable for some realizable \(M\subseteq N\), and \(A\in M\).

Let us see why Proposition 1 follows from Lemmas 3 and 4.

Proof

( Proposition 1). We begin with the “if” direction. Thus, suppose \(\mathfrak {p}(L_{A,Q})\) for A and Q as described. Then by Lemma 3 and the first and fourth axioms of unboundedness predicates, this implies \(\mathfrak {p}(L(G))\).

For the “only if” direction, suppose \(\mathfrak {p}(L(G))\). By the first axiom of unboundedness predicates, \(\mathfrak {p}\) must hold for the finite union provided by Lemma 4. By the second axiom, this implies that \(\mathfrak {p}(K_1\cdots K_m)\) for a finite product \(K_1\cdots K_m\) as in Lemma 4. Moreover, by the third axiom, this implies that \(\mathfrak {p}(K_i)\) for some \(i\in \{1,\ldots ,m\}\). If \(K_i\) is finite, then by assumption, \(\mathfrak {p}(K_i)\) does not hold. Therefore, we must have \(\mathfrak {p}(K_i)\) for some \(K_i=L_{A,Q}\), as required.    \(\square \)

Flows. It remains to prove Lemmas 3 and 4. We begin with Lemma 3 and for this we need some more terminology. Let \(\varSigma \) be an alphabet. By \(\varPsi :\varSigma ^*\rightarrow \mathbb {N}^\varSigma \), we denote the Parikh map, which is defined as \(\varPsi (w)(a)=|w|_a\) for \(w\in \varSigma ^*\) and \(a\in \varSigma \). In other words, \(\varPsi (w)(a)\) is the number of occurrences of a in \(w\in \varSigma ^*\). If \(\varGamma \subseteq \varSigma \) is a subset, then \(\pi _\varGamma :\varSigma ^*\rightarrow \varGamma ^*\) is the homomorphism with \(\pi _\varGamma (a)=\varepsilon \) for \(a\in \varSigma \setminus \varGamma \) and \(\pi _\varGamma (a)=a\) for \(a\in \varGamma \). We also call \(\pi _\varGamma \) the projection to \(\varGamma \).

Suppose we have a \(\mathbb {Z}\)-grammar \(G=(N,\varSigma ,P,S)\) with non-terminals N and productions P. For a derivation tree \(\tau \), we write \(\varPsi (\tau )\) for the vector in \(\mathbb {N}^P\) that counts how many times each production appears in \(\tau \). We introduce a map \(\partial \), which counts how many non-terminals each production consumes and produces. Formally, \(\partial :\mathbb {N}^P\rightarrow \mathbb {Z}^N\) is the monoid homomorphism that sends the production \(p=A\rightarrow w\) to the vector \(\partial (p)=-A+\varPsi (\pi _N(w))\). Here, \(-A\in \mathbb {Z}^N\) denotes the vector with \(-1\) at the position of A and 0 everywhere else. A vector \(\boldsymbol{u}\in \mathbb {N}^P\) is a flow if \(\partial (\boldsymbol{u})=\boldsymbol{0}\). Observe that a derivation tree \(\tau \) is a pump if and only if \(\varPsi (\tau )\) is a flow. In this case, we also call the vector \(\boldsymbol{u}\in \mathbb {N}^P\) with \(\boldsymbol{u}=\varPsi (\tau )\) a pump.

The following lemma will provide an easy way to construct derivations. It is a well-known result by Esparza [19, Theorem 3.1], and has since been exploited in several results on context-free grammars. Our formulation is slightly weaker than Esparza’s. However, it is enough for our purposes and admits a simple proof, which is inspired by a proof of Kufleitner [44].

Lemma 5

Let \(\boldsymbol{f}\in \mathbb {N}^P\). Then \(\boldsymbol{f}\) is a flow if and only if it is a sum of pumps.

Proof

The “if” direction is trivial, because every pump is clearly a flow. Conversely, suppose \(\boldsymbol{f}\in \mathbb {N}^P\) is a flow. We can clearly write \(\boldsymbol{f}=\varPsi (\tau _1)+\cdots +\varPsi (\tau _n)\), where \(\tau _1,\ldots ,\tau _n\) are derivation trees: We can just view each production in \(\boldsymbol{f}\) as its own derivation tree. Now suppose that we have \(\boldsymbol{f}=\varPsi (\tau _1)+\cdots +\varPsi (\tau _n)\) so that n is minimal. We claim that then, each \(\tau _i\) is a pump, proving the lemma.

Suppose not, then without loss of generality, \(\tau _1\) is not a pump. Since \(\tau _1\) is a derivation, this means \(\varPsi (\tau _1)\) cannot be a flow and thus there must be a non-terminal A with \(\partial (\tau _1)(A)\ne 0\).

Let us first assume that \(\partial (\tau _1)(A)>0\). This means there is a non-terminal A occurring at a leaf of \(\tau _1\) such that A is not the start symbol of \(\tau _1\). Since \(\boldsymbol{f}=\varPsi (\tau _1)+\cdots +\varPsi (\tau _n)\) is a flow, we must have \(\partial (\varPsi (\tau _2)+\cdots +\varPsi (\tau _n))(A)<0\). This, in turn, is only possible if some \(\tau _j\) has A as its start symbol. We can therefore merge \(\tau _1\) and \(\tau _j\) by replacing \(\tau _1\)’s A-labelled leaf by the new subtree \(\tau _j\). We obtain a new collection of \(n-1\) trees whose Parikh image is \(\boldsymbol{f}\), in contradiction to the choice of n. If \(\partial (\tau _1)(A)<0\), then there must be a \(\tau _j\) with \(\partial (\tau _j)(A)>0\) and thus we can insert \(\tau _1\) below \(\tau _j\), reaching a similar contradiction.    \(\square \)

Constructing derivations. Using flows, we can now prove Lemma 3.

Proof

Suppose there is a derivation with \(A\in M\) and \(u,v\in \varSigma ^*\). We have to show that both u and v occur in some word \(w\in L(G)\). Furthermore, if G is in Chomsky normal form, we can choose w such that |w| is linear in |u| and |v|. Our goal is to construct a derivation of G in which we find u and v as factors. We could obtain a derivation tree by inserting \(\tau \) into some derivation tree for G (at some occurrence of A), but this might yield non-zero counter values. Therefore, we will use the fact that Q is M-cancelable to find other pumps that can be inserted as well in order to bring the counter back to zero.

Since \(M\subseteq N\) is realizable, there exists a complete derivation \(\tau _0\) that derives some word \(w_0\in L(G)\) and uses precisely the non-terminals in M. Since \(Q\subseteq P\) is M-cancelable, we know that for each production \(p\in Q\), there exist pumps \(\tau _1,\ldots ,\tau _k\) such that (i) p occurs in some \(\tau _i\), (ii) \(\varphi (\tau _1)+\cdots +\varphi (\tau _k)=\boldsymbol{0}\) and (iii) all productions in \(\tau _1,\ldots ,\tau _k\) only use non-terminals in M. This allows us to define \(\boldsymbol{f}_p:=\varPsi (\tau _1)+\cdots +\varPsi (\tau _k)\). Observe that \(\boldsymbol{f}_p\) contains only productions with non-terminals from M, we have \(\boldsymbol{f}_p[p] > 0\), and \(\varphi (\boldsymbol{f}_p) = {\bf 0}\). We can use the flows \(\boldsymbol{f}_p\) to find the desired canceling pumps. Since by Lemma 5, every flow can be decomposed into a sum of pumps, it suffices to construct a particular flow. Specifically, we look for a flow \(\boldsymbol{f}_\tau \in \mathbb {N}^P\) such that:

  1. 1.

    any production p with \(\boldsymbol{f}_\tau [p] > 0\) uses only non-terminals from M, and

  2. 2.

    \(\varphi (\boldsymbol{f}_\tau + \varPsi (\tau )) = {\bf 0}\).

The first condition ensures that all the resulting pumps can be inserted into \(\tau _0\). The second condition ensures that the resulting total counter values will be zero. We claim that with

$$\begin{aligned} \boldsymbol{f}_\tau = \left( \sum _{p \in Q} \varPsi (\tau )[p] \cdot \boldsymbol{f}_p\right) - \varPsi (\tau ), \end{aligned}$$
(1)

we achieve these conditions. First, observe that \(\boldsymbol{f}_\tau \in \mathbb {N}^P\): We have

$$ \begin{aligned} \boldsymbol{f}_\tau [q] ~~\ge ~~ \varPsi (\tau )[q] \cdot \boldsymbol{f}_q[q] - \varPsi (\tau )[q] ~~=~~\varPsi (\tau )[q] \cdot (\boldsymbol{f}_q[q] - 1) \end{aligned} $$

which is at least zero as \(\boldsymbol{f}_q[q]\) must be non-zero by definition. Second, note that \(\boldsymbol{f}_\tau \) is indeed a flow, because it is a \(\mathbb {Z}\)-linear combination of flows. Moreover, all productions appearing in \(\boldsymbol{f}_\tau \) also appear in \(\boldsymbol{f}_p\) for some \(p\in Q\) or in \(\tau \), meaning that all non-terminals must belong to M. Finally, the total counter effect of \(\boldsymbol{f}_\tau + \varPsi (\tau )\) is zero as \(\boldsymbol{f}_\tau + \varPsi (\tau ) = \sum _{p \in Q} \varPsi (\tau )[p] \cdot \boldsymbol{f}_p\) is a sum of flows each with total counter effect zero.

Now, since \(\boldsymbol{f}_\tau \) is a flow, Lemma 5 tells us that there are pumps \(\tau '_1,\ldots ,\tau '_m\) such that \(\boldsymbol{f}_\tau =\varPsi (\tau '_1)+\cdots +\varPsi (\tau '_m)\). Therefore, inserting \(\tau \) and \(\tau '_1,\ldots ,\tau '_m\) into \(\tau _0\) must yield a derivation of a word that has both u and v as factors and also has counter value

$$\begin{aligned} \underbrace{\varphi (\tau _0)}_{=\boldsymbol{0}}+\underbrace{\varphi (\tau )+\varphi (\tau '_1)+\cdots \varphi (\tau '_m)}_{=\varphi (\tau )+\varphi (\boldsymbol{f}_\tau )=\boldsymbol{0}}=\boldsymbol{0}. \end{aligned}$$

Thus, we have a complete derivation of G. Hence \(L_{A,Q}\subseteq F(L(G))\).    \(\square \)

Decomposition into finite union. It remains to prove Lemma 4. For the decomposition, we show that there exists a finite set \(D_0\) of complete derivations such that all complete derivations of G can be obtained from some derivation in \(D_0\) and then inserting pumps that produce words in \(L_{A,Q}\), for some appropriate A and Q. Here, it is key that the set \(D_0\) of “base derivations” is finite. Showing this for context-free grammars would just require a simple “unpumping” argument based on the pigeonhole principle as in Parikh’s theorem [51]. However, in the case of \(\mathbb {Z}\)-grammars, where \(D_0\) should only contain derivations that have counter value zero, this is not obvious. To achieve this, we employ a well-quasi ordering on (labeled) trees. Recall that a quasi ordering is a reflexive and transitive ordering. For a quasi ordering \((X,\le )\) and a subset \(Y\subseteq X\), we write \(Y\mathop {\uparrow }\) for the set \(\{x\in X\mid \exists y\in Y:y\le x\}\). We say that \((X,\le )\) is a well-quasi ordering (WQO) if every non-empty subset \(Y\subseteq X\) has a finite subset \(Y_0\subseteq Y\) such that \(Y\subseteq Y_0\mathop {\uparrow }\).

We define an ordering on all trees in \(\mathcal {T}_{N\cup \varSigma ,d}\). A tree s is a subtree of t if there exists a node x in t such that s consists of all nodes of t that are descendants of x. If \(\tau _1,\ldots ,\tau _n\) are trees, then we denote by \(r[\tau _1,\ldots ,\tau _n]\) the tree with a root node r and the subtrees \(\tau _1,\ldots ,\tau _n\) directly under the root. Now let \(\tau =(A,\boldsymbol{u})[\tau _1,\ldots ,\tau _n]\) and \(\tau '=(B,\boldsymbol{v})[\sigma _1,\ldots ,\sigma _m]\) be trees in \(\mathcal {T}_{N\cup \varSigma ,d}\). We define the ordering \(\preceq \) as follows. If \(n=0\) (i.e. \(\tau \) consists of only one node), then we have \(\tau \preceq \tau '\) if and only if \(A=B\) and \(m=0\). If \(n\ge 1\), then we define inductively:

$$\begin{aligned} \tau \preceq \tau ' ~~~\iff ~~~ A = B~\text { and }\exists \text { subtree}~&\tau '' = (A,\boldsymbol{u}')[\tau '_1, \ldots , \tau '_n]~\text {of}~\tau '\\&\text {with}~\tau _i \preceq \tau '_i~\text {for}\, i=1,\ldots ,n \end{aligned}$$

Based on \(\preceq \), we define as slight refinement: We write \(\tau \sqsubseteq \tau '\) if and only if \(\tau \preceq \tau '\) and the set of non-terminals appearing in \(\tau \) is the same as in \(\tau '\).

Lemma 6

\((\mathcal {T}_{N\cup \varSigma ,d},\sqsubseteq )\) is a WQO.

Proof

In [47, Lemma 3.3], it was shown that \(\preceq \) is a WQO. Then \(\sqsubseteq \) is the product of equality on a finite set, which is a WQO, and the WQO \(\preceq \).    \(\square \)

Lemma 6 allows us to decompose L(G) into a finite union: For each complete derivation \(\tau \) of G, we define

$$\begin{aligned} L_\tau (G) =\{w\in \varSigma ^* \mid \exists ~\text {complete derivation}\, \tau '\, \text {with}\, \tau \sqsubseteq \tau '\, \text {and}\, \textsf{yield}(\tau ')=w\}. \end{aligned}$$

Lemma 7

There exists a finite set \(D_0\subseteq \mathcal {T}_{N\cup \varSigma ,d}\) of complete derivations of G such that \(L(G)=\bigcup _{\tau \in D_0} L_\tau (G)\).

Proof

Since \((\mathcal {T}_{N\cup \varSigma ,d},\sqsubseteq )\) is a WQO, the set \(D\subseteq \mathcal {T}_{N\cup T,d}\) of all complete derivations of G has a finite subset \(D_0\) with \(D\subseteq D_0\mathop {\uparrow }\). This implies the lemma.    \(\square \)

Decomposition into finite product. In light of Lemma 7, it remains to be shown that for each tree \(\tau \), we can find a product \(K_1 \cdot K_2 \cdots K_m\) of languages such that \(L_\tau (G)\subseteq K_1 \cdot K_2 \cdots K_m\) and each \(K_i\) is either finite or is of the form \(L_{A,Q}\). We construct the overapproximation of \(L_\tau (G)\) inductively as follows. Let \(M\subseteq N\) and \(Q\subseteq P\) be subsets of the non-terminals and the productions, respectively. If \(\tau \) has one node, labeled by \(a\in \varSigma \), then we set \(\textrm{App}_{Q}(\tau ):=\{a\}\). Moreover, if \(\tau =(A,\boldsymbol{u})[\tau _1,\ldots ,\tau _n]\) for \(A\in N\) and trees \(\tau _1,\ldots ,\tau _n\), then we set

$$\begin{aligned} \textrm{App}_{Q}(\tau ):=L_{A,Q} \cdot \textrm{App}_{Q}(\tau _1) \cdot \textrm{App}_{Q}(\tau _2) \cdots \textrm{App}_Q(\tau _n)\cdot L_{A,Q}. \end{aligned}$$

Finally, we set \(\textrm{App}(\tau ):=\textrm{App}_Q(\tau )\), where \(Q\subseteq P\) is the set of all M-cancelable productions, where M is the set of all non-terminals appearing in \(\tau \). Now clearly, each \(\textrm{App}(\tau )\) is a finite product \(K_1 \cdot K_2 \cdots K_m\) as desired: This follows by induction on the size of \(\tau \). Thus, to prove Lemma 4, the following suffices:

Lemma 8

For every complete derivation tree \(\tau \) of G, we have \(L_\tau (G)\subseteq \textrm{App}(\tau )\).

Proof

Suppose \(w\in L_\tau (G)\) is derived using a complete derivation tree \(\tau '\) with \(\tau \sqsubseteq \tau '\). Then, the set of non-terminals appearing in \(\tau \) must be the same as in \(\tau '\); we denote it by M. Let \(Q\subseteq P\) be the set of all M-cancelable productions. Moreover, since \(\tau \preceq \tau '\), we can observe that there exist pumps \(\tau _1,\ldots ,\tau _n\) with root non-terminals \(A_1,\ldots ,A_n\) and nodes \(x_1,\ldots ,x_n\) in \(\tau \) such that \(\tau '\) can be obtained from \(\tau \) by replacing each node \(x_i\) by the pump \(\tau _i\).

Since both \(\tau \) and \(\tau '\) are complete derivations of G, each must have counter effect \(\boldsymbol{0}\). Thus, \(\varphi (\tau _1)+\cdots +\varphi (\tau _n)=\varphi (\tau ')-\varphi (\tau )=\boldsymbol{0}\). Hence, the pumps \(\tau _1,\ldots ,\tau _n\) witness that the productions appearing in \(\tau _1,\ldots ,\tau _n\) are M-cancelable. Thus, the derivation corresponding to \(\tau _i\) uses only productions in Q and thus \(\tau _i\) corresponds to for some \(u_i,v_i\) and we have \(u_i,v_i\in L_{A,Q}\).    \(\square \)

5 Growth

In this section, we prove Theorem 3. Since clearly, a bounded language has polynomial growth, it remains to be shown that if L is accepted by a PRBCA and L is not bounded, then it has exponential growth. For two languages \(L_1,L_2\subseteq \varSigma ^*\), we write \(L_1\hookrightarrow _{\textrm{lin}}L_2\) if there exists a constant \(c\in \mathbb {N}\) such that for every word \(w_1 \in L_1\), there exists \(w_2 \in L_2\) with \(|w_2| \le c\cdot |w_1|\) and \(w_1\) is a factor of \(w_2\). It is not difficult to observe that for two languages \(L_1,L_2\subseteq \varSigma ^*\), if \(L_1\hookrightarrow _{\textrm{lin}}L_2\) and \(L_1\) has exponential growth, then so does \(L_2\).

In order to show Theorem 3, we need an adapted version of Lemma 3. A \(\mathbb {Z}\)-grammar is in Chomsky normal form if all productions are of the form \((A\rightarrow BC,\boldsymbol{v})\) or \((A\rightarrow a,\boldsymbol{v})\) with \(A,B,C\in N\), \(a\in \varSigma \), and \(\boldsymbol{u},\boldsymbol{v}\in \mathbb {Z}^k\). In other words, the context-free grammar obtained by forgetting all counter vectors is in Chomsky normal form. Fernau and Stiebe [21, Proposition 5.12] have shown that every \(\mathbb {Z}\)-grammar has an equivalent \(\mathbb {Z}\)-grammar in Chomsky normal form.

Lemma 9

If \(G=(N,\varSigma ,P,S)\) is a \(\mathbb {Z}\)-grammar in Chomsky normal form, \(M\subseteq N\) is realizable, \(Q\subseteq P\) is M-cancelable, and \(A\in M\), then \(L_{A,Q}\hookrightarrow _{\textrm{lin}}L(G)\).

This is shown essentially the same way as Lemma 3. Let us now show that if a language L accepted by a PRBCA is not bounded, then it must have exponential growth. We have seen above that as a PRBCA language, L is generated by some \(\mathbb {Z}\)-grammar. As shown by Fernau and Stiebe [21, Proposition 5.12], this implies that \(L=L(G)\) for some \(\mathbb {Z}\)-grammar G in Chomsky normal form. Since L is not bounded, Lemma 4 yields A and Q such that \(L_{A,Q}\) is not a bounded language. It is well-known that any context-free language that is not bounded has exponential growth (this fact has apparently been independently discovered at least six times, see [24] for references). Thus, \(L_{A,Q}\) has exponential growth. By Lemma 9, we have \(L_{A,Q}\hookrightarrow _{\textrm{lin}}L\) and thus L has exponential growth.