betaFeedback

WorksComputer Science

Subsequence Analysis Problems for Binary Parikh Matrices

Abstract

The universality index corresponding to a word is the largest integer k such that every word of length k over the given alphabet occurs in it as a subsequence. Relative to languages this notion can be investigated with respect to both existential and universal quantifiers, with the former corresponding to the existence of a word in the language with universality index at least k, while the latter considers the index across all words that the language contains. In this work we study the existential (exists-universality) and universal (forall-universality) subsequence universality (as introduced in [Adamson et al., ISAAC 2023]) for binary languages consisting of all words with a fixed number of letters a, letters b, and subsequences ab. We prove that both exists- and forall-universality admit exact arithmetic characterizations for these languages. Extending the above notions, we end the paper by initiating the analysis of the probability of a fixed word occurring as subsequence of the words in such a language. To this end, we prove that, for every fixed pattern word w and an error tolerance, given as input the subsequence counts describing a language, the ratio of words in the language having the pattern w as a subsequence admits an additive approximation scheme that is polynomial-time in the binary encoding of the input counts.

Introduction

A word uu is a subsequence of a word ww if uu can be obtained from ww by deleting letters without changing the order of the remaining letters. This relation is central in combinatorics on words and formal language theory, not least because of the classical theorem of Higman, which states that finite words over a finite alphabet are well-quasi-ordered by the subsequence relation [11], and a closely related theorem of Haines [9] that states that the downward closure of every language is regular. These results have made subsequences a natural tool in the study of languages, well-quasi-orders, and verification problems: even when a language itself is complicated, the set of all subsequences occurring in its words admits a finite automata-theoretic representation. This observation has been used repeatedly in algorithmic formal language theory and in the analysis of infinite-state systems, where downward closures and subword orderings provide regular over-approximations and decidability tools [24, 25, 14].

Beyond the existence of finite representations for downward closures, one may ask more refined algorithmic questions about the subsequences occurring in words or in languages. For a single word, this includes subsequence matching (decidable in linear time), testing whether two words have the same subsequences of at most a given length, i.e., testing Simon’s congruence [22, 13, 8], identifying absent subsequences [15], and studying universality with respect to subsequences. A word ww over an alphabet Σ\Sigma is called kk-subsequence universal, or simply kk-universal, if every word in Σk\Sigma^k, i.e., every word over Σ\Sigma of length kk, occurs in ww as a subsequence. Equivalently, the set of subsequences of ww contains the full kk-spectrum Σk\Sigma^k. This notion and several variants have been investigated for individual words and compressed words, e.g., see the work on scattered factor universality [2, 1] and the references therein.

Recently, the same family of questions has been studied for formal languages rather than individual words. In this setting, the input language is typically represented succinctly, e.g., by an automaton or a grammar, and one asks whether a given pattern occurs as a subsequence in some word of the language, in all words of the language, or whether the language contains a word that is kk-universal. These existential and universal variants have been considered for language classes from the Chomsky hierarchy, including regular, context-free, and context-sensitive languages [1, 6]. In particular, the transition from individual words to languages naturally introduces two questions: an existential one, asking whether some word in the language has the desired subsequence property, and a universal problem, asking whether all words in the language have it.

In this paper we study these subsequence analysis problems for a different, arithmetically defined class of finite languages. We work over the binary alphabet {a,b}\{a,b\}. For nonnegative integers A,B,CA,B,C, let LA,B,CL_{A,B,C} be the language of all binary words with the numbers of letters aa, letters bb, and scattered subwords abab equal AA, BB and CC, respectively. Equivalently, this is the equivalence class determined by a binary Parikh matrix [18, 16], and also by the binary 2-deck [12, 21], since over a binary alphabet the count of length-one subsequences and that of abab, characterizing the former, determines the whole count of length-2 subsequences, which describes the latter. The language is nonempty if and only if 0≤C≤AB0 \le C \le AB, and throughout the paper the entries A,B,CA,B,C are part of the input, encoded in binary.

Our first goal is to determine the existential and universal subsequence universality indices of LA,B,CL_{A,B,C}. For a language LL, we say that LL is kk-∃\exists-universal if some word w∈Lw \in L is kk-universal, and we write

ι∃(L)=max⁡{k∣some w∈L is k-universal}.\iota_{\exists}(L) = \max\{k \mid\text{some } w \in L \text{ is } k\text{-universal}\}.

We say that a nonempty language LL is kk-∀\forall-universal if every word w∈Lw \in L is kk-universal, and we write

ι∀(L)=max⁡{k∣every w∈L is k-universal}.\iota_{\forall}(L) = \max\{k \mid\text{every } w \in L \text{ is } k\text{-universal}\}.

The notions, introduced in [1], capture the two natural quantifier choices over the language: the largest kk such that a kk-universal representative exists, and the largest kk such that all representatives are kk-universal.

We prove that, for binary 2-deck classes, both indices are computable in polynomial time in the bitlength of A,B,CA,B,C. In the existential case, we prove that ι∃(LA,B,C)\iota_{\exists}(L_{A,B,C}) is the minimum among AA, BB and a simple formula depending on the three input multiplicities. On the universal side, we show that no nonempty language LA,B,CL_{A,B,C} is 4-universal; thus only the patterns of lengths one, two, and three need to be considered. A complete avoidance analysis for the eight binary patterns of length three then yields a characterization of ι∀(LA,B,C)\iota_{\forall}(L_{A,B,C}).

Finally, we consider a probabilistic refinement of the existential and universal subsequence questions. For a fixed binary pattern ww and a nonempty language LA,B,CL_{A,B,C}, define pw(A,B,C)p_w(A,B,C) to be the probability that a uniformly chosen word from LA,B,CL_{A,B,C} contains ww as a subsequence. The endpoint conditions pw(A,B,C)>0p_w(A,B,C)>0 and pw(A,B,C)=1p_w(A,B,C)=1 are exactly the existential and universal subsequence problems for the fixed pattern abababab. The probability pw(A,B,C)p_w(A,B,C) therefore interpolates between the two quantifier extremes: instead of asking whether at least one representative contains ww, or whether all representatives contain ww, it asks for the density of representatives containing ww.

Exact computation of this probability is not expected to be easy in general, since the universal subsequence problem, that is, testing pw(A,B,C)=1p_w(A,B,C)=1, is as hard as factoring integers already for the fixed pattern ww. Nevertheless, for every fixed word pattern ww and fixed error tolerance ε>0\varepsilon>0, we give an additive approximation algorithm for pw(A,B,C)p_w(A,B,C) running in time polynomial in the bitlength of A,B,CA,B,C. The proof uses the correspondence between binary Parikh matrix/2-deck classes and partitions inside an A×BA \times B rectangle: each word in LA,B,CL_{A,B,C} corresponds to a partition of area CC, in the form of Young diagrams (for more details, see Richomme’s discussion of this connection [19]). We combine this partition model with a polynomial bound on the number of ww-avoiding representatives, a lower bound for Gaussian binomial coefficients when the input counts are not bounded by a constant, and exact counting procedures when one of A,B,C,AB−CA,B,C,AB-C is bounded. This yields a constant-error approximation scheme for fixed word patterns, complementing the exact arithmetic characterizations of the ∃\exists- and ∀\forall-universality indices.

We structure our paper as follows. The next section contains preliminaries for our work. Sections 3 and 4 are dedicated to the investigation of the kk-universal existence and universality, while the last section introduces the concept of probability with respect to membership of subsequences and gives an approximation scheme for it.

Preliminaries

Let Σ={a<b}\Sigma=\{a<b\} be an ordered binary alphabet, and let Σ∗\Sigma^* denote the language of all words over Σ\Sigma. Let ∣w∣|w| denote the number of occurrences of symbols of Σ\Sigma in a word w=w1w2⋯w∣w∣w=w_1w_2\cdots w_{|w|} with wi∈Σw_i\in\Sigma, for i∈[1,∣w∣]i\in[1,|w|], and by wR=w∣w∣⋯w2w1w^R=w_{|w|}\cdots w_2w_1 denote its reversal. For words u,w∈Σ∗u,w\in\Sigma^*, we write u⪯wu\preceq w if uu occurs in ww as a subsequence, i.e., if there exist indices 1≤i1<⋯<i∣u∣≤∣w∣1\le i_1<\cdots<i_{|u|}\le|w| such that u=w[i1]⋯w[i∣u∣]u=w[i_1]\cdots w[i_{|u|}]. By Subseq⁡(w)\operatorname{Subseq}(w) we denote the set of all subsequences occurring in ww. Let ∣w∣u|w|_u denote the number of occurrences of uu in ww as a subsequence, for any u,w∈Σ∗u,w\in\Sigma^*, where occurrences are allowed to overlap, and are distinct if they differ in at least one position, e.g., ∣abb∣ab=2|abb|_{ab}=2. For i<ji<j, by [i,j][i,j] we denote the set of integers starting at ii and ending at jj, inclusive.

For any integer s≥2s\ge2, let Ms\mathcal{M}_s denote the multiplicative monoid of s×ss\times s upper triangular matrices with nonnegative integer entries and 11’s on the main diagonal. The Parikh matrix mapping [16] with respect to the ordered alphabet Σ={a<b}\Sigma=\{a<b\}, denoted by Ψ\Psi, is a morphism from Σ∗\Sigma^* into M3\mathcal{M}_3, where

Ψ(a)=(110010001)andΨ(b)=(100011001).\Psi(a)=\begin{pmatrix}1&1&0\\0&1&0\\0&0&1\end{pmatrix} \qquad\text{and}\qquad \Psi(b)=\begin{pmatrix}1&0&0\\0&1&1\\0&0&1\end{pmatrix}.

As Ψ\Psi is a morphism, it maps a word w=a1a2⋯a∣w∣∈Σ∗w=a_1a_2\cdots a_{|w|}\in\Sigma^* to the matrix Ψ(w)=Ψ(a1)⋯Ψ(a∣w∣)\Psi(w)=\Psi(a_1)\cdots\Psi(a_{|w|}). Matrices of the form Ψ(w)\Psi(w), for w∈Σ∗w\in\Sigma^*, are termed Parikh matrices. Hence, over the alphabet {a<b}\{a<b\}, Parikh matrices are 3×33\times3 upper triangular matrix with 11’s on the diagonal, regardless of the described word, and the fundamental theorem of the Parikh matrix mapping [16] shows that the upper part tracks the number of occurrences, as subsequences, of aa, bb and abab in the respective word, i.e., ∣w∣a|w|_a appears in position (1,2)(1,2), ∣w∣b|w|_b in position (2,3)(2,3), and ∣w∣ab|w|_{ab} in position (1,3)(1,3).

Note that when considering binary subsequences every pair of positions consisting of one aa and one bb contributes either to the total number of subsequences abab or to baba. Therefore, we have that in every binary word ww the following equality holds

∣w∣ab=∣w∣a⋅∣w∣b−∣w∣ba.(1)|w|_{ab}=|w|_a\cdot|w|_b-|w|_{ba}. \tag*{(1)}

The kk-deck of a word is the multiset resulting from counting all occurrences of subsequences of length at most kk that the respective word contains. As such, one can define the language corresponding to a given kk-deck as the language of all words sharing the respective multiset. Furthermore, when the underlying alphabet is binary, as a straightforward consequence of Eq. (1), both the Parikh matrices and the 2-decks associated with a word contain the same information.

For a word w∈Σ∗w\in\Sigma^*, its equivalence class, with respect to the Parikh matrix mapping, is the language L(M)={v∈Σ∗∣Ψ(v)=M}L(M)=\{v\in\Sigma^*\mid\Psi(v)=M\} determined by its matrix M=Ψ(w)M=\Psi(w). We call such a language a (binary) Parikh matrix language, and for the rest of this work, for nonnegative integers A,B,CA,B,C, define

LA,B,C={w∈{a,b}∗∣∣w∣a=A, ∣w∣b=B, ∣w∣ab=C}.(2)L_{A,B,C}=\{w\in\{a,b\}^*\mid|w|_a=A,\ |w|_b=B,\ |w|_{ab}=C\}. \tag*{(2)}

We also denote ∣w∣ba=D|w|_{ba}=D and have D=AB−CD=AB-C. By definition, this equivalence class is identical to the one corresponding to the 2-deck notion. Moreover, it is straightforward that a language LA,B,CL_{A,B,C} is nonempty if and only if 0≤C≤AB0\le C\le AB. Indeed, writing a word in the form w=bx0abx1a⋯abxAw=b^{x_0}ab^{x_1}a\cdots ab^{x_A}, we have

∑i=0Axi=B\sum_{i=0}^{A}x_i=B

and ∣w∣ab=∑i=0Aixi|w|_{ab}=\sum_{i=0}^{A}ix_i. Every integer between 0 and ABAB is obtainable by distributing the BB letters bb among the A+1A+1 gaps separating the occurrences of aa.

For more details on Parikh matrices we refer to [16, 5, 20], while for kk-decks we suggest [12, 21].

A word w∈Σ∗w\in\Sigma^* is called kk-subsequence universal, or simply kk-universal, over Σ\Sigma, if Σk⊆Subseq⁡(w)\Sigma^k\subseteq\operatorname{Subseq}(w). Equivalently, every word of length kk over Σ\Sigma occurs in ww as a subsequence. The universality index of ww, denoted ι(w)\iota(w), is the largest kk such that ww is kk-universal.

For a language L⊆Σ∗L\subseteq\Sigma^*, we use the two language-level notions from the kk-universality literature, see [1]. We say that LL is kk-∃\exists-universal if there exists w∈Lw\in L such that ι(w)≥k\iota(w)\ge k and define ι∃(L)=max⁡{k:L is k-∃-universal}\iota_{\exists}(L)=\max\{k:L\text{ is }k\text{-}\exists\text{-universal}\}. We say that a nonempty LL is kk-∀\forall-universal if every w∈Lw\in L satisfies ι(w)≥k\iota(w)\ge k and define ι∀(L)=max⁡{k:L is k-∀-universal}\iota_{\forall}(L)=\max\{k:L\text{ is }k\text{-}\forall\text{-universal}\}.

As the universality index ι∀(L)\iota_{\forall}(L) above is meaningless for empty languages, and one can easily decide the emptiness of Parikh matrix/2-deck languages over binary alphabets, from here on we assume that computing ι∀(L)\iota_{\forall}(L) means computing it for a nonempty language.

The arch-factorization of a word is a decomposition into non-overlapping factors starting from the left, such that each factor – except for, possibly, the last one – is the shortest possible, while containing each letter of the alphabet. The factorization is unique and its factors are called arches, with the ones containing all letters called complete arches. For example, over the alphabet {a,b}\{a,b\}, the arch-factorization of aabbabaaaabbabaa is aab.ba.ba.aaab.ba.ba.a, whereas that of aabbbaabbb is aab.bbaab.bb. The following characterization of kk-universality of binary words is a well-known argument based on the arch-factorization (see [2, 10] for the general case); we shall use it in order to develop some of the tools we use in our analysis.

Lemma 2.1. For w∈{a,b}∗w\in\{a,b\}^* and k≥0k\ge0, the following are equivalent:

(i) ww is kk-universal over {a,b}\{a,b\};

(ii) ww contains, as a subsequence, some word v∈{ab,ba}kv\in\{ab,ba\}^k.

Proof. The implication (ii) ⇒\Rightarrow (i) is immediate. Every factor abab and every factor baba of vv (the arches) contains both letters aa and bb. Obviously, from a subsequence v=s1s2⋯skv=s_1s_2\cdots s_k, where si∈{ab,ba}s_i\in\{ab,ba\}, one can obtain every possible word x1x2⋯xk∈{a,b}kx_1x_2\cdots x_k\in\{a,b\}^k by choosing the symbol for xix_i from the ii-th arch sis_i. Hence vv, and therefore also ww, are kk-universal.

For (i) ⇒\Rightarrow (ii), we use the standard greedy arch factorization, see [10]. Since ww is kk-universal, its arch-factorization contains at least kk complete arches, i.e., non-overlapping factors having both aa and bb. Therefore, each of the arches contains either abab or baba as a subsequence; choosing one such two-letter subsequence from each of the first kk arches gives a subsequence belonging to {ab,ba}k\{ab,ba\}^k.

From the lemma above we can directly conclude the following consequence.

Corollary 2.2 [4]. The shortest kk-universal binary words are exactly the words in {ab,ba}k\{ab,ba\}^k.

∃\exists-universality

We first turn our attention to when LA,B,CL_{A,B,C} contains a kk-universal word. The next lemma is the main interval-realization tool.

Lemma 3.1. Let v∈{a,b}∗v \in\{a,b\}^{*}, and fix integers A≥∣v∣aA \geq|v|_{a} and B≥∣v∣bB \geq|v|_{b}. Then the set of possible values of ∣w∣ab|w|_{ab}, over all words ww with ∣w∣a=A|w|_{a} = A and ∣w∣b=B|w|_{b} = B, and having vv as subsequence, i.e., v⪯wv \preceq w, is the integer interval [∣v∣ab,AB−∣v∣ba]∩Z[|v|_{ab}, AB - |v|_{ba}] \cap\mathbb{Z}.

Proof. First, if v⪯wv \preceq w, then the embedded vv contributes at least ∣v∣ab|v|_{ab} pairs of type abab. Thus ∣w∣ab≥∣v∣ab|w|_{ab} \geq|v|_{ab}. Similarly, the copy of vv in ww contributes at least ∣v∣ba|v|_{ba} pairs of type baba. Since Eq. (1) holds for ww, we get ∣w∣ab≤AB−∣v∣ba|w|_{ab} \leq AB - |v|_{ba}. So every attainable value lies in the stated interval.

Conversely, start with vv, and insert all extra B−∣v∣bB - |v|_{b} letters bb to the far left and all extra A−∣v∣aA - |v|_{a} letters aa to the far right. The resulting word has AA letters aa, BB letters bb, contains vv as a subsequence, and has exactly ∣v∣ab|v|_{ab} subsequences of type abab.

Now move continuously to the opposite extreme, where all extra letters aa are placed to the far left and all extra letters bb are placed to the far right, keeping the original copy of vv in its original relative order. This can be done by adjacent swaps ba↦abba \mapsto ab, each involving at least one of the discussed extra letters. Such a swap preserves the chosen copy of vv and increases ∣w∣ab|w|_{ab} by exactly 1. At the opposite extreme, no pair involving an extra letter contributes to ∣w∣ba|w|_{ba}, so the only remaining baba-pairs are those already inside vv. Hence the final value of ∣w∣ab|w|_{ab} is AB−∣v∣baAB - |v|_{ba}.

Since at each step ∣w∣ab|w|_{ab} changes by one, every integer between ∣v∣ab|v|_{ab} and AB−∣v∣baAB - |v|_{ba} is realized.

Lemma 3.2. If t(v)t(v) denotes the number of length-2 factors starting at odd positions (blocks) equal to abab in v∈{ab,ba}kv \in\{ab,ba\}^{k}, then ∣v∣ab=(k2)+t(v)|v|_{ab} = \binom{k}{2} + t(v), and ∣v∣ba=(k2)+k−t(v)|v|_{ba} = \binom{k}{2} + k - t(v).

Proof. Each pair of distinct blocks i<ji < j contributes one abab-pair: choose the letter aa from block ii and the letter bb from block jj. There are (k2)\binom{k}{2} such cross-block contributions. In addition, every block abab contributes one abab-pair, while a block baba does not. Hence ∣v∣ab=(k2)+t(v)|v|_{ab} = \binom{k}{2} + t(v). The formula for ∣v∣ba|v|_{ba} follows either by the same argument or from ∣v∣ab+∣v∣ba=k2|v|_{ab} + |v|_{ba} = k^{2}, that is, Eq. (1).

Theorem 3.3. For every k≥0k \geq0, a nonempty language LA,B,CL_{A,B,C} is kk-∃\exists-universal if and only if A≥kA \geq k, B≥kB \geq k, C≥(k2)C \geq\binom{k}{2}, and AB−C≥(k2)AB - C \geq\binom{k}{2}.

Proof. Suppose first that LA,B,CL_{A,B,C} is kk-∃\exists-universal. Then there exists w∈LA,B,Cw \in L_{A,B,C} with ι(w)≥k\iota(w) \geq k. By Lemma 2.1, ww contains a subsequence v∈{ab,ba}kv \in\{ab,ba\}^{k}. Hence ww contains at least kk letters aa and at least kk letters bb, so A≥kA \geq k and B≥kB \geq k.

Since v⪯wv \preceq w, we have that ww also contains as subsequences at least as many pairs abab and baba, as vv does. Thus, by Lemma 3.2, we conclude that C=∣w∣ab≥(k2)C = |w|_{ab} \geq\binom{k}{2}, and ∣w∣ba≥(k2)|w|_{ba} \geq\binom{k}{2}.

Conversely, assume A≥kA \geq k, B≥kB \geq k, C≥NC \geq N, and D=AB−C≥ND = AB - C \geq N, where N=(k2)N = \binom{k}{2}. We shall choose v∈{ab,ba}kv \in\{ab,ba\}^{k} such that v⪯wv \preceq w, for some w∈LA,B,Cw \in L_{A,B,C}.

By Lemmas 3.2 and 3.1, a word v∈{ab,ba}kv \in\{ab,ba\}^{k} with t(v)t(v) blocks abab can be embedded in some word ww with parameters AA, BB, and CC if and only if N+t(v)≤C≤AB−(N+k−t(v))N + t(v) \leq C \leq AB - (N + k - t(v)).

Equivalently, N+k−D≤t(v)≤C−NN + k - D \leq t(v) \leq C - N. We need an integer t(v)∈{0,…,k}t(v) \in\{0,\ldots,k\} satisfying this inequality. Since, from the statement, D≥ND \geq N, we have N+k−D≤kN + k - D \leq k, and since C≥NC \geq N, we have C−N≥0C - N \geq0. Finally,

(C−N)−(N+k−D)=C+D−2N−k=AB−k2.(C-N)-(N+k-D)=C+D-2N-k=AB-k^{2}.

Because A≥kA \geq k and B≥kB \geq k, we have AB≥k2AB \geq k^{2}. Hence the interval [N+k−D,C−N][N+k-D,C-N] has a nonempty intersection with {0,…,k}\{0,\ldots,k\}. Choose an integer t(v)t(v) in this intersection and choose any word v∈{ab,ba}kv \in\{ab,ba\}^{k} with exactly t(v)t(v) blocks abab. Then Lemma 3.1 gives a word w∈LA,B,Cw \in L_{A,B,C} with v⪯wv \preceq w. By Lemma 2.1, this word ww is kk-universal.

We can now summarize our results so far.

Corollary 3.4. For nonempty LA,B,CL_{A,B,C}, we have ι∃(LA,B,C)=min⁡{A,B,⌊1+1+8min⁡(C,AB−C)2⌋}\iota_{\exists}(L_{A,B,C})=\min\left\{A,B,\left\lfloor\frac{1+\sqrt{1+8\min(C,AB-C)}}{2}\right\rfloor\right\}.

Proof. By Theorem 3.3, the largest admissible kk is bounded by AA, by BB, and by the largest kk satisfying (k2)≤min⁡(C,AB−C)\binom{k}{2}\leq\min(C,AB-C). Solving k(k−1)/2≤Mk(k-1)/2\leq M, for M=min⁡(C,AB−C)M=\min(C,AB-C), gives k≤⌊1+1+8M2⌋k\leq\left\lfloor\frac{1+\sqrt{1+8M}}{2}\right\rfloor.

Furthermore, we draw the following algorithmic consequences.

Corollary 3.5. Given nonnegative integers AA, BB, CC, and kk in binary, one can decide in polynomial time whether LA,B,CL_{A,B,C} is kk-∃\exists-universal. When LA,B,C≠∅L_{A,B,C}\neq\varnothing, we can compute ι∃(LA,B,C)\iota_{\exists}(L_{A,B,C}) in polynomial time.

Proof. First we check whether 0≤C≤AB0\leq C\leq AB. If this test fails, then the input does not correspond to any word, i.e., LA,B,CL_{A,B,C} is empty, so the answer is negative. The decision test consists of integer comparisons involving A,B,C,AB−CA,B,C,AB-C and k(k−1)/2k(k-1)/2. The index formula uses an integer square root of 1+8min⁡(C,AB−C)1+8\min(C,AB-C), which is computable in polynomial time in the bitlength of the input.

∀\forall-universality

We now turn to the ∀\forall-universality index. The first observation is that this index is always at most 3 for nonempty binary Parikh matrix languages.

Lemma 4.1. There exists no nonempty 4-∀\forall-universal language LA,B,CL_{A,B,C}. Consequently, ι∀(LA,B,C)≤3\iota_{\forall}(L_{A,B,C})\leq3.

Proof. If A=0A=0 or B=0B=0, then no word in LA,B,CL_{A,B,C} is even 1-universal, so the claim is immediate.

For binary words, a concrete characterization of lexicographically minimal (and maximal) representatives of a Parikh matrix language is given in [20 Theorem 3]. These descriptions can also be deduced from the languages given in [5 page 9].

In particular, the minimal representative is an element of the language a∗b∗ab∗a∗a^{*}b^{*}ab^{*}a^{*}, while the maximal is of the form b∗a∗ba∗b∗b^{*}a^{*}ba^{*}b^{*}. Since those two contain only words with at most 3 arches, together with Lemma 2.1, we conclude.

It is trivial that a nonempty language LA,B,CL_{A,B,C} is 1-∀\forall-universal if and only if every one of its words contains both symbols of the alphabet.

Proposition 4.2. A nonempty language LA,B,CL_{A,B,C} is 2-∀\forall-universal if and only if A,B≥2A,B\geq2 and min⁡(C,AB−C)>0\min(C,AB-C)>0.

Proof. A binary word is 2-universal if and only if it contains all of the four words aaaa, abab, baba, and bbbb as subsequences. The pattern aaaa occurs in every word of LA,B,CL_{A,B,C} if and only if A≥2A\geq2, and bbbb occurs in every word if and only if B≥2B\geq2. The pattern abab occurs in every word if and only if C=∣w∣ab>0C=|w|_{ab}>0, while baba occurs in every word if and only if ∣w∣ba>0|w|_{ba}>0.

For 3-∀\forall-universality we need to understand when a representative of LA,B,CL_{A,B,C} can avoid a fixed binary word of length 3.

Lemma 4.3. Let LA,B,CL_{A,B,C} be nonempty. For each u∈{a,b}3u\in\{a,b\}^{3}, there exists a word ww that does not have uu as a subsequence, if and only if the following avoidability conditions hold (where D=AB−CD=AB-C):

pattern uuaaaaaabbbbbbaabaababbabbbaabaabbabbaabaabababbab
conditionA<3A<3B<3B<3C≤BC\leq BC≤AC\leq AD≤BD\leq BD≤AD\leq AA=0A=0 or A∣CA\mid CB=0B=0 or B∣CB\mid C

Table 1.

In particular, if A,B≥3A,B\geq3, the last two conditions reduce to A∣CA\mid C and B∣CB\mid C, respectively.

Proof. The first two conditions are immediate: every word with at least three aa’s contains aaaaaa, and every word with at least three bb’s contains bbbbbb.

For aabaab, write a word as w=bx0abx1a⋯abxAw=b^{x_0}ab^{x_1}a\cdots ab^{x_A}. The letters bb within the bxib^{x_i} blocks have exactly ii letters aa before them. Thus ww avoids aabaab if and only if every bb has at most one aa before it, i.e., if and only if all bb’s lie in the first two blocks. This is possible with total abab-count CC if and only if C≤BC\le B. Hence the third condition follows.

The condition for abbabb is dual. A word avoids abbabb if and only if every letter aa has at most one bb after it. Since ∣w∣ab=∑letters a#{b after this a}|w|_{ab}=\sum_{\text{letters }a}\#\{b\text{ after this }a\}, this is possible if and only if C≤AC\le A.

Similarly, a word avoids baabaa if and only if every letter bb has at most one aa after it. Since D=∣w∣baD=|w|_{ba}, this is possible if and only if D≤BD\le B. A word avoids bbabba if and only if every letter aa has at most one bb before it, which is possible if and only if D≤AD\le A.

A word avoids abaaba if and only if no bb lies between two occurrences of aa. Equivalently, every bb is either before all aa’s or after all aa’s. If A=0A=0, this is automatic. If A>0A>0, such a word has the form bB−qaAbqb^{B-q}a^A b^q, for some 0≤q≤B0\le q\le B, and its abab-count is qAqA. Hence such a word exists if and only if A∣CA\mid C.

The proof for babbab is symmetric. A word avoids babbab if and only if every aa is either before all bb’s or after all bb’s. If B=0B=0, this is automatic. If B>0B>0, such a word has the form apbBaA−pa^p b^B a^{A-p}, and its abab-count is pBpB. Hence such a word exists if and only if B∣CB\mid C.

Theorem 4.4. A nonempty language LA,B,CL_{A,B,C} is 33-∀\forall-universal if and only if A,B≥3A,B\ge3, min⁡(C,AB−C)>max⁡(A,B)\min(C,AB-C)>\max(A,B), and A∤CA\nmid C and B∤CB\nmid C.

Proof. A binary word is 33-universal if and only if it contains all eight words in {a,b}3\{a,b\}^3. Thus LA,B,CL_{A,B,C} is 33-∀\forall-universal if and only if no word in LA,B,CL_{A,B,C} avoids any of these eight patterns.

By Lemma 4.3, avoidance of aaaaaa is possible if and only if A<3A<3, and avoidance of bbbbbb is possible if and only if B<3B<3. Therefore we must have A≥3A\ge3 and B≥3B\ge3.

Under this assumption, the remaining six avoidance conditions are

C≤B,C≤A,AB−C≤B,AB−C≤A,A∣C,B∣C.C\le B,\qquad C\le A,\qquad AB-C\le B,\qquad AB-C\le A,\qquad A\mid C,\qquad B\mid C.

The negation of the first two is C>max⁡(A,B)C>\max(A,B), the negation of the next two is AB−C>max⁡(A,B)AB-C>\max(A,B), and the negation of the last two is A∤CA\nmid C and B∤CB\nmid C. This leads to the stated condition.

Combining the preceding results yields the ∀\forall-universality index.

Theorem 4.5. For a nonempty language LA,B,CL_{A,B,C} we have

ι∀(LA,B,C)={3,if A,B≥3, min⁡(C,AB−C)>max⁡(A,B), A∤C, B∤C,2,if the previous condition fails, and A,B≥2, min⁡(C,AB−C)>0,1,if the previous conditions fail, and A,B≥1,0,if A=0 or B=0.\iota_{\forall}(L_{A,B,C})= \begin{cases} 3, & \text{if } A,B\ge3,\ \min(C,AB-C)>\max(A,B),\ A\nmid C,\ B\nmid C,\\ 2, & \text{if the previous condition fails, and } A,B\ge2,\ \min(C,AB-C)>0,\\ 1, & \text{if the previous conditions fail, and } A,B\ge1,\\ 0, & \text{if } A=0\text{ or }B=0. \end{cases}

Proof. By Lemma 4.1, the universal index is at most 3. The condition for value at least 3 is exactly Theorem 4.4. If this condition fails, the index is at most 2, and Proposition 4.2 gives the condition for being at least 2. If that condition also fails, the index is at most 1. It is at least 1 exactly when every word contains both letters, i.e., when A,B≥1A,B\ge1. If A=0A=0 or B=0B=0, no word in the language is 1-universal over the fixed alphabet {a,b}\{a,b\}, so the value is 0.

As a consequence we get the following algorithmic result.

Corollary 4.6. Given nonnegative integers AA, BB, CC, and kk in binary, one can decide in polynomial time whether LA,B,CL_{A,B,C} is kk-∀-universal. One can also compute ι∀(LA,B,C)\iota_{\forall}(L_{A,B,C}) in polynomial time.

Proof. First check nonemptiness, i.e., 0≤C≤AB0 \le C \le AB. For an empty language, the answer is vacuously YES. For nonempty languages, Theorem 4.5 gives a constant number of arithmetic tests: comparisons involving A,B,C,AB−CA,B,C,AB-C, and divisibility tests A∣CA \mid C and B∣CB \mid C. These are polynomial-time operations on binary integers.

An additive approximation scheme for fixed-pattern containment

For a fixed word ww and a finite language LL, define the subsequence probability of ww with respect to LL as the ratio pw(L)=∣{u∈L∣w⪯u}∣∣L∣p_w(L)=\frac{|\{u\in L\mid w\preceq u\}|}{|L|}, that is, the probability that a uniformly randomly chosen word from LL contains ww as a subsequence.

In our binary setting, we restrict notation and say that for a binary word ww and a nonempty language LA,B,CL_{A,B,C}, described via nonnegative integers A,B,CA,B,C, we have

pw(A,B,C)=∣{u∈LA,B,C∣w⪯u}∣∣LA,B,C∣.p_w(A,B,C)=\frac{|\{u\in L_{A,B,C}\mid w\preceq u\}|}{|L_{A,B,C}|}.

The extremal cases of the problem considered in this section are the so-called ∃-SUBSEQUENCE and ∀-SUBSEQUENCE problems [6], defined as follows:

  • ∃-SUBSEQUENCE: For a language LL and a word ww, decide whether there exists u∈Lu\in L such that w⪯uw\preceq u.

  • ∀-SUBSEQUENCE: For a language LL and a word ww, decide whether w⪯uw\preceq u holds, for all u∈Lu\in L.

In terms of the ratio pw(L)p_w(L) defined above, the ∃-SUBSEQUENCE and ∀-SUBSEQUENCE problems ask to decide whether pw(L)>0p_w(L)>0 and pw(L)=1p_w(L)=1, respectively. First we show that ∀-SUBSEQUENCE is intractable in the case of binary 2-deck languages, directly implying that it is not expected that the ratio pw(A,B,C)p_w(A,B,C) is computable exactly in polynomial time unless factoring integers is easy.

We use a simple reduction showing that the complement of the ∀-SUBSEQUENCE problem (“is there a word in the language of a given Parikh matrix that does not contain the given subsequence”) for binary Parikh matrix languages is FACTORING*-hard, even for the fixed pattern abababab. Here FACTORING* denotes the following interval-divisor problem: given positive integers U,V,NU,V,N, with U≤V≤NU\le V\le N, decide whether NN has a divisor in the interval [U,V][U,V]. It is easy to see that the usual decision version of factoring integers (does the input integer NN have a prime factor at most VV?) reduces trivially to FACTORING*. Therefore FACTORING* is not expected to have a polynomial-time algorithm, since factoring integers is a candidate for an NP-intermediate problem (in NP ∩\cap coNP, but believed to be outside P).

Theorem 5.1. The complement of ∀-SUBSEQUENCE for binary Parikh matrix languages is FACTORING*-hard, even for the fixed pattern abababab.

Proof. Set C=NC=N, A=VA=V, B=⌊NU⌋B=\left\lfloor\frac{N}{U}\right\rfloor, and w=ababw=abab, so the instance of “do all v∈LA,B,Cv\in L_{A,B,C} contain ww as a subsequence?” created for the FACTORING* instance (U,V,N)(U,V,N) is ⟨LA,B,C,abab⟩\langle L_{A,B,C},abab\rangle. The resulting language LA,B,CL_{A,B,C} may be empty, but this is not a problem; the universal statement becomes vacuously true, and the corresponding instance of the complement problem is negative.

A binary word avoids abababab as a subsequence if and only if its print, that is, the word obtained by replacing every maximal unary block by a single occurrence of its letter, avoids abababab. Equivalently, it has the form b∗a∗b∗a∗b^*a^*b^*a^*, possibly allowing some of the four unary blocks to be empty. Thus, if abababab is not a common subsequence of all words in LA,B,CL_{A,B,C}, then one of those words has the form b∗a∗b∗a∗b^*a^*b^*a^*. If N=dq=CN=dq=C, where U≤d≤VU\le d\le V and q≤⌊NU⌋q\le\left\lfloor\frac{N}{U}\right\rfloor, then the word bB−qadbqaA−db^{B-q}a^db^qa^{A-d} is in LA,B,CL_{A,B,C} and it does not contain abababab as subsequence.

Conversely, suppose x∈LA,B,Cx\in L_{A,B,C} does not contain abababab, i.e., it has the form bB−qadbqaA−db^{B-q}a^db^qa^{A-d}, for some d≤Ad\le A and q≤Bq\le B. This means that the number of abab's in the word is exactly dqdq, so C=dqC=dq. Moreover, q≤⌊NU⌋q\le\left\lfloor\frac{N}{U}\right\rfloor, so d=C/q=N/q≥N/⌊NU⌋d=C/q=N/q\ge N/\left\lfloor\frac{N}{U}\right\rfloor, which gives d≥Ud\ge U. Finally, d≤Vd\le V, since it is the length of an aa-block in a word with VV occurrences of aa. Note that the division by qq above is always valid, since dq=C=N>0dq=C=N>0.

We showed that the complement of ∀-SUBSEQUENCE is FACTORING*-hard, which is at least as hard as factoring integers into primes. To decide factoring, one would test LA,B,C=∅L_{A,B,C}=\varnothing first and if yes, answer negatively to the factoring instance. If the language is not empty, testing pabab(A,B,C)=1p_{abab}(A,B,C)=1 is equivalent to the ∀-SUBSEQUENCE problem. Thus, an exact polynomial-time algorithm for the former would yield a polynomial-time algorithm for FACTORING*. This motivates the additive approximation result below.

In what follows, we prove that, for every fixed ww and error tolerance ε\varepsilon, the ratio pw(A,B,C)p_w(A,B,C) admits an additive polynomial-time approximation scheme in the binary encoding of A,B,CA,B,C. When A,B,CA,B,C are fixed and no confusion arises, we streamline the notation further and use only pwp_w for the ratio with respect to the fixed language LA,B,CL_{A,B,C}.

The endpoint cases pw>0p_w>0 and pw=1p_w=1 correspond respectively to the ∃-SUBSEQUENCE and ∀-SUBSEQUENCE problems discussed above. Thus pwp_w interpolates between those two endpoint questions. As we have just seen, the ∀-SUBSEQUENCE problem can be hard even for fixed patterns, but that hardness only distinguishes pw=1p_w=1 from pw≤1−1/∣LA,B,C∣p_w\le1-1/|L_{A,B,C}|, an exponentially small gap. Hence it does not preclude constant-error additive approximation.

In line with the geometric approach in [19], we note that every word u∈LA,B,Cu\in L_{A,B,C} corresponds uniquely to a partition λ=(λ1,…,λA)⊆{0,…,B}A\lambda=(\lambda_1,\ldots,\lambda_A)\subseteq\{0,\ldots,B\}^A of area CC (that is, an integer partition of the number CC), where λi=#{\lambda_i=\#\{\text{}b$'s after the iith aa in uu}}$. Thus B≥λ1≥⋯≥λA≥0B\ge\lambda_1\ge\cdots\ge\lambda_A\ge0, where ∣λ∣=λ1+⋯+λA=C|\lambda|=\lambda_1+\cdots+\lambda_A=C.

Consequently we have

∣LA,B,C∣=#{λ⊆{0,…,B}A∣∣λ∣=C}=[qC](A+BA)q,|L_{A,B,C}|=\#\{\lambda\subseteq\{0,\ldots,B\}^A\mid|\lambda|=C\}=[q^C]\binom{A+B}{A}_q,

where

(A+BA)q=∏i=1A1−qB+i1−qi\binom{A+B}{A}_q=\prod_{i=1}^{A}\frac{1-q^{B+i}}{1-q^i}

is the standard Gaussian binomial coefficient, whose correspondence with the number of partitions of the above type is a classical result (see [23 Section 1.7]). In other words, this formula gives the coefficient of qCq^C in this polynomial, which is the number of non-increasing partitions with area CC in a bounded box A×BA\times B. The binary Parikh matrix equivalence classes are equivalently described by this partition model; e.g., see the binary characterizations of Fossé–Richomme [7] and later uses of the partition viewpoint.

In what follows, a binary word uu is called ww-avoiding if w⪯̸uw\not\preceq u. Let Avoid⁡w(A,B,C)={u∈LA,B,C∣w⪯̸u}\operatorname{Avoid}_w(A,B,C)=\{u\in L_{A,B,C}\mid w\not\preceq u\} be the size of the subset of LA,B,CL_{A,B,C} consisting of ww-avoiding words. We first bound Avoid⁡w\operatorname{Avoid}_w by a fixed polynomial in the smaller of the two subsequences' pair counts ∣ab∣=C|ab|=C and ∣ba∣=AB−C|ba|=AB-C. In what follows, a template is an alternating binary word, that is, σ1σ2⋯σr\sigma_1\sigma_2\cdots\sigma_r, for some rr, where σi,σi+1∈{a,b}\sigma_i,\sigma_{i+1}\in\{a,b\} and σi≠σi+1\sigma_i\ne\sigma_{i+1}, for 1≤i<r1\le i<r. A word uu matches the template, if there exist positive integers x1,x2,…,xrx_1,x_2,\ldots,x_r such that u=σ1x1σ2x2⋯σrxru=\sigma_1^{x_1}\sigma_2^{x_2}\cdots\sigma_r^{x_r}.

Lemma 5.2. For every fixed binary pattern ww, there exists a constant rwr_w such that every ww-avoiding binary word matches one of finitely many templates σ1σ2⋯σr\sigma_1\sigma_2\cdots\sigma_r with r≤rwr \le r_w, where σi,σi+1∈{a,b}\sigma_i,\sigma_{i+1} \in\{a,b\} with σi≠σi+1\sigma_i \ne\sigma_{i+1}, for 1≤i<r1 \le i < r, and the finite set of templates depends only on ww.

Proof. To see this, start by using the usual greedy subsequence automaton for w=w1⋯wℓw = w_1\cdots w_\ell. The state qq means that w1⋯wqw_1\cdots w_q has been greedily matched. A word avoids ww if and only if the automaton never reaches state ℓ\ell. The automaton can advance at most ℓ−1\ell-1 times. Between two consecutive advances, as well as before the first and after the last, the automaton can only read repetitions of one letter. Hence, every ww-avoiding word has at most 2ℓ−12\ell-1 maximal unary blocks, and therefore matches one of finitely many alternating templates.

Lemma 5.3. For every fixed binary pattern ww, there exist constants mw,ewm_w,e_w such that, for all nonempty languages LA,B,CL_{A,B,C}, we have Avoid⁡w(A,B,C)≤mw⋅(min⁡{C,AB−C}+1)ew\operatorname{Avoid}_w(A,B,C) \le m_w\cdot(\min\{C,AB-C\}+1)^{e_w}.

Proof. Fix one template σ1σ2⋯σr\sigma_1\sigma_2\cdots\sigma_r from the finite family established by Lemma 5.2. We count the words of LA,B,CL_{A,B,C} matching that template, that is, words of the form u=σ1x1σ2x2⋯σrxr∈LA,B,Cu=\sigma_1^{x_1}\sigma_2^{x_2}\cdots\sigma_r^{x_r}\in L_{A,B,C}, where all xi≥1x_i\ge1. For each such uu we have C=∣u∣ab=∑i<j,σi=a,σj=bxixjC=|u|_{ab}=\sum_{\substack{i<j,\,\sigma_i=a,\,\sigma_j=b}}x_ix_j.

First assume that C≤AB−CC\le AB-C, and we bound the number of such words in terms of CC. If a block ii participates in at least one summand in this expression, then, since all block lengths are positive, that summand is at least xix_i. Hence xi≤Cx_i\le C. Thus every interacting block has length at most CC. The only blocks not participating in any abab-summand are the possible initial bb-run and the possible final aa-run. Moreover, adjacent symbols in the template are distinct, there is at most one initial bb-block and one final aa-block. Once the interacting block lengths have been chosen, these outer lengths are uniquely determined by ∑σi=axi=A\sum_{\sigma_i=a}x_i=A and, respectively, ∑σi=bxi=B\sum_{\sigma_i=b}x_i=B. Therefore this template gives at most (C+1)r(C+1)^r possible words.

If AB−C<CAB-C<C, apply the same argument to the reversed words. Reversal sends LA,B,CL_{A,B,C} bijectively to LA,B,AB−CL_{A,B,AB-C}, and w⪯uw\preceq u is equivalent to wR⪯uRw^R\preceq u^R. Since wRw^R is fixed, the same polynomial bound applies with AB−CAB-C in place of CC. Thus the number of ww-avoiding words is polynomial in AB−CAB-C in this case.

It remains to sum these bounds over the finite template families from Lemma 5.2. We choose ew=max⁡{rw,rwR}e_w=\max\{r_w,r_{w^R}\} (the larger of the constants from Lemma 5.2 for ww and its reverse) to be the bound on the number of blocks, and mwm_w the maximum of the numbers of templates associated with ww and wRw^R.

The counts of letters or the subsequences abab or baba being bounded by a constant (boundary regimes) implies languages with few words or very simple structure. We first give a simple lower bound for coefficients of Gaussian binomials when we are not in those boundary regimes.

Lemma 5.4. For every fixed integer E≥0E\ge0, there exists RER_E such that whenever A,B,C,AB−C≥REA,B,C,AB-C\ge R_E, we have [qC](A+BA)q≥(min⁡{C,AB−C}+1)E\left[q^C\right]\binom{A+B}{A}_q\ge\left(\min\{C,AB-C\}+1\right)^E.

Proof. Let PA,B(t)=[qt](A+BA)qP_{A,B}(t)=\left[q^t\right]\binom{A+B}{A}_q. Thus PA,B(t)P_{A,B}(t) is the number of partitions of tt whose Young diagrams fit inside an A×BA\times B rectangle. The coefficients PA,B(t)P_{A,B}(t) are unimodal by Sylvester’s classical result (for a more modern reference, see [17]).

Let s=min⁡{C,AB−C}s=\min\{C,AB-C\}. First we recall that the coefficients of a Gaussian binomial coefficient are symmetric, that is,

[qt](A+BA)q=[qAB−t](A+BA)q\left[q^t\right]\binom{A+B}{A}_q=\left[q^{AB-t}\right]\binom{A+B}{A}_q

This symmetry follows from the fact that complementing a Young diagram of area tt in the A×BA \times B rectangle and rotating it by 180∘180^\circ gives a Young diagram enclosed in the same rectangle, but with area AB−tAB-t. By this symmetry, it is enough to prove a lower bound for PA,B(s)P_{A,B}(s), where s≤AB/2s \le AB/2. Indeed, if s=Cs=C, then PA,B(C)=PA,B(s)P_{A,B}(C)=P_{A,B}(s), while if s=AB−Cs=AB-C, then PA,B(C)=PA,B(AB−C)=PA,B(s)P_{A,B}(C)=P_{A,B}(AB-C)=P_{A,B}(s).

Fix H=2E+4H=2E+4. We choose RER_E sufficiently large so that RE≥(2H)2R_E \ge(2H)^2 and, for all s≥REs \ge R_E,

sE+2(2H)H≥(s+1)E+1.\frac{s^{E+2}}{(2H)^H} \ge(s+1)^{E+1}.

The reason for requiring E+1E+1 in the exponent here instead of just EE is due to a cancellation argument at the end. Now, what we need to show is that, whenever A,B,s≥REA,B,s \ge R_E and s≤AB/2s \le AB/2, we have

∑t=0sPA,B(t)≥sE+2(2H)H.\sum_{t=0}^{s} P_{A,B}(t) \ge\frac{s^{E+2}}{(2H)^H}.

The reason for considering the cumulative sum is the following. If we can find a subrectangle of the A×BA \times B rectangle whose area is at most ss, then every partition fitting inside this subrectangle has area at most ss, and therefore contributes to one of the coefficients PA,B(0),…,PA,B(s)P_{A,B}(0),\ldots,P_{A,B}(s). Thus a large enough subrectangle of area at most ss gives a lower bound on the cumulative sum. We shall choose such a subrectangle so that one of its sides is of order s\sqrt{s}, while the other has fixed size HH. This will give polynomially many partitions, with exponent controlled by HH.

Set M=min⁡{A,B}M=\min\{A,B\} and N=max⁡{A,B}N=\max\{A,B\}. We want to construct a subrectangle α×β⊆M×N\alpha\times\beta\subseteq M \times N such that αβ≤s\alpha\beta\le s, min⁡{α,β}≥H\min\{\alpha,\beta\} \ge H, and max⁡{α,β}≥s/2\max\{\alpha,\beta\} \ge\sqrt{s}/2. There are two cases.

First suppose that M≥sM \ge\sqrt{s} and we take α=β=⌊s⌋\alpha=\beta=\lfloor\sqrt{s}\rfloor. This square fits inside M×NM \times N, since α,β≤M≤N\alpha,\beta\le M \le N, and its area is at most ss. Since s≥RE≥(2H)2s \ge R_E \ge(2H)^2, both sides are at least HH. Also ⌊s⌋≥s/2\lfloor\sqrt{s}\rfloor\ge\sqrt{s}/2, so the larger side is at least s/2\sqrt{s}/2.

Now suppose that M<sM < \sqrt{s}. We take α=M\alpha=M and β=⌊sM⌋\beta=\left\lfloor\frac{s}{M}\right\rfloor. Then α≤M\alpha\le M, and αβ≤s\alpha\beta\le s. Moreover, since s≤MN/2s \le MN/2, we have sM≤N2\frac{s}{M} \le\frac{N}{2}, and hence β≤N\beta\le N. Therefore the rectangle α×β\alpha\times\beta fits inside M×NM \times N. We also have α=M≥RE≥H\alpha=M \ge R_E \ge H. Since M<sM < \sqrt{s}, we get s/M>ss/M > \sqrt{s}, and hence

β=⌊sM⌋≥s−1≥s2.\beta=\left\lfloor\frac{s}{M}\right\rfloor\ge\sqrt{s}-1 \ge\frac{\sqrt{s}}{2}.

where the last inequality holds because s≥REs \ge R_E is large enough. In particular, β≥H\beta\ge H. Thus the required properties hold in this case as well.

Since M×NM \times N is either A×BA \times B or B×AB \times A, the constructed rectangle fits inside the A×BA \times B rectangle, possibly after transposing it when B<AB<A. In the latter case, transposition gives an area-preserving bijection between partitions fitting inside the α×β\alpha\times\beta rectangle and partitions fitting inside the β×α\beta\times\alpha rectangle. Hence, after possibly interchanging α\alpha and β\beta, we may assume that α≤A\alpha\le A and β≤B\beta\le B.

We have therefore found, in all cases, a subrectangle α×β⊆A×B\alpha\times\beta\subseteq A \times B with area at most ss, both sides at least HH, and larger side at least s/2\sqrt{s}/2. Consequently,

∑t=0sPA,B(t)≥#{(λ1,…,λα)∣β≥λ1≥⋯≥λα≥0}=(α+βα).\sum_{t=0}^{s}P_{A,B}(t)\ge\#\{(\lambda_1,\ldots,\lambda_\alpha)\mid\beta\ge\lambda_1\ge\cdots\ge\lambda_\alpha\ge0\}=\binom{\alpha+\beta}{\alpha}.

Let J=max⁡{α,β}J=\max\{\alpha,\beta\}. Since the rectangle α×β\alpha\times\beta has one side JJ and the other side at least HH, it contains, up to transposition, an H×JH \times J rectangle. Hence

(α+βα)≥(H+JH)=∏i=1HJ+ii≥(JH)H.\binom{\alpha+\beta}{\alpha}\ge\binom{H+J}{H}=\prod_{i=1}^{H}\frac{J+i}{i}\ge\left(\frac{J}{H}\right)^H.

Using J≥s/2J \ge\sqrt{s}/2, we obtain

∑t=0sPA,B(t)≥(s2H)H=sH/2(2H)H.\sum_{t=0}^{s} P_{A,B}(t) \ge\left(\frac{\sqrt{s}}{2H}\right)^{H} = \frac{s^{H/2}}{(2H)^{H}}.

Since H=2E+4H=2E+4, we have H/2=E+2H/2=E+2, and therefore

∑t=0sPA,B(t)≥sE+2(2H)H.\sum_{t=0}^{s} P_{A,B}(t) \ge\frac{s^{E+2}}{(2H)^{H}}.

Finally, since s≤AB/2s \le AB/2, symmetry and unimodality imply that PA,B(s)P_{A,B}(s) is the largest coefficient among PA,B(0),PA,B(1),…,PA,B(s)P_{A,B}(0),P_{A,B}(1),\ldots,P_{A,B}(s). Hence

(s+1)PA,B(s)≥∑t=0sPA,B(t),and thereforePA,B(s)≥1s+1⋅sE+2(2H)H.(s+1)P_{A,B}(s) \ge\sum_{t=0}^{s} P_{A,B}(t), \qquad\text{and therefore} \qquad P_{A,B}(s) \ge\frac{1}{s+1}\cdot\frac{s^{E+2}}{(2H)^{H}}.

By the choice of RER_E, the right-hand side is at least (s+1)E(s+1)^E. Therefore, as required, PA,B(s)≥(s+1)EP_{A,B}(s) \ge(s+1)^E. Since s=min⁡{C,AB−C}s=\min\{C,AB-C\}, symmetry gives PA,B(C)=PA,B(s)P_{A,B}(C)=P_{A,B}(s). Therefore

(A+BA)q[qC]=PA,B(C)=PA,B(s)≥(min⁡{C,AB−C}+1)E.\binom{A+B}{A}_{q}^{[q^{C}]} = P_{A,B}(C) = P_{A,B}(s) \ge\left(\min\{C,AB-C\}+1\right)^E.

Next we show that, if each of A,B,C,AB−CA,B,C,AB-C is large enough, the containment probability of a fixed pattern is either 0 or arbitrarily close to 1.

Lemma 5.5. Fix a binary pattern ww and ε>0\varepsilon>0. There exists R=R(w,ε)R=R(w,\varepsilon) such that if A,B,C,AB−C≥RA,B,C,AB-C\ge R and the language LA,B,CL_{A,B,C} contains at least one word having ww as subsequence, then pw(A,B,C)≥1−εp_w(A,B,C)\ge1-\varepsilon.

Proof. Let mwm_w and ewe_w be the constants from Lemma 5.3. Choose an integer E>ewE>e_w. By Lemma 5.4, whenever A,B,C,AB−C≥REA,B,C,AB-C\ge R_E we have that

∣LA,B,C∣=[qC](A+BA)q≥(min⁡{C,AB−C}+1)E.|L_{A,B,C}| = [q^C]\binom{A+B}{A}_{q} \ge\left(\min\{C,AB-C\}+1\right)^E.

On the other hand, Avoid⁡w(A,B,C)≤mw(min⁡{C,AB−C}+1)ew\operatorname{Avoid}_w(A,B,C)\le m_w\left(\min\{C,AB-C\}+1\right)^{e_w}. Therefore

Avoid⁡w(A,B,C)∣LA,B,C∣≤mw(min⁡{C,AB−C}+1)E−ew.(3)\frac{\operatorname{Avoid}_w(A,B,C)}{|L_{A,B,C}|} \le\frac{m_w}{\left(\min\{C,AB-C\}+1\right)^{E-e_w}}. \tag*{(3)}

Choose R≥RER\ge R_E sufficiently large that

mw(R+1)E−ew≤ε.\frac{m_w}{(R+1)^{E-e_w}}\le\varepsilon.

Since mwm_w, ewe_w and EE are constants, such a choice is possible, and A,B,C,AB−C≥RA,B,C,AB-C\ge R guarantees that the right-hand side of inequality (3) above is at most ε\varepsilon. Hence

pw(A,B,C)=1−Avoid⁡w(A,B,C)∣LA,B,C∣≥1−ε.p_w(A,B,C)=1-\frac{\operatorname{Avoid}_w(A,B,C)}{|L_{A,B,C}|}\ge1-\varepsilon.

Let RR be fixed. We show that pw(A,B,C)p_w(A,B,C) can be computed exactly in time fw(R)⋅poly⁡(log⁡A+log⁡B+log⁡C)f_w(R)\cdot\operatorname{poly}(\log A+\log B+\log C) whenever at least one of AA, BB, CC, or AB−CAB-C is at most RR. Note that here fw(R)f_w(R) denotes a function which in general is not necessarily polynomial in RR.

Lemma 5.6. Fix a binary pattern ww and an integer RR. There is an algorithm which computes pw(A,B,C)p_w(A,B,C) in time fw(R)⋅poly⁡(log⁡A+log⁡B+log⁡C)f_w(R)\mathbin{\cdot}\operatorname{poly}(\log A+\log B+\log C), whenever LA,B,CL_{A,B,C} is nonempty and at least one of A,B,C,AB−CA,B,C,AB-C is at most RR.

Proof. If any of the input counts are 0, then the probability can be computed trivially. Now assume the counts are positive.

Small area C≤RC \le R. Every partition of area CC fits inside a C×CC \times C square. Thus we enumerate all partitions λ\lambda of CC, discard those with more than AA parts (rows) or largest part greater than BB, and test whether the corresponding word contains ww as subsequence.

If λ\lambda has r≤Cr \le C nonzero parts and largest part s≤Cs \le C, then the corresponding word has the form bB−sUλaA−rb^{B-s}U_\lambda a^{A-r}, where Uλ=abλ1−λ2abλ2−λ3⋯abλr−1−λrabλrU_\lambda= ab^{\lambda_1-\lambda_2}ab^{\lambda_2-\lambda_3}\cdots ab^{\lambda_{r-1}-\lambda_r}ab^{\lambda_r}, that has at most CC occurrences of aa and at most CC occurrences of bb. For testing containment of the fixed pattern ww, the outer blocks may be capped at ∣w∣|w|:

bB−s⇝bmin⁡{B−s,∣w∣},aA−r⇝amin⁡{A−r,∣w∣}.b^{B-s}\quad\rightsquigarrow\quad b^{\min\{B-s,|w|\}},\qquad a^{A-r}\quad\rightsquigarrow\quad a^{\min\{A-r,|w|\}}.

Thus each test is performed on a word of length O(C+∣w∣)\mathcal{O}(C+|w|).

Since the number p(C)p(C) of partitions of CC is p(C)∈exp⁡(O(C))p(C)\in\exp(\mathcal{O}(\sqrt{C})), the small-area case is exact in time exp⁡(O(R))poly⁡(∣w∣,log⁡A,log⁡B)\exp(\mathcal{O}(\sqrt{R}))\operatorname{poly}(|w|,\log A,\log B).

Small coarea AB−C≤RAB-C \le R. By reversing the word we have ∣uR∣ab=∣u∣ba=AB−C|u^{R}|_{ab}=|u|_{ba}=AB-C, and w⪯uw\preceq u is equivalent to wR⪯uRw^{R}\preceq u^{R}. Hence pw(A,B,C)=pwR(A,B,AB−C)p_w(A,B,C)=p_{w^{R}}(A,B,AB-C), which reduces to the small-area case.

Small height A≤RA \le R. Write

uλ=bB−λ1abλ1−λ2a⋯abλA,u_\lambda=b^{B-\lambda_1}ab^{\lambda_1-\lambda_2}a\cdots ab^{\lambda_A},

where B≥λ1≥⋯≥λA≥0B\ge\lambda_1\ge\cdots\ge\lambda_A\ge0 and ∑iλi=C\sum_i\lambda_i=C. In pw(A,B,C)=∣{u∈LA,B,C∣w⪯u}∣∣LA,B,C∣p_w(A,B,C)=\frac{|\{u\in L_{A,B,C}\mid w\preceq u\}|}{|L_{A,B,C}|}, the denominator is the number of integer points in this fixed-dimensional polytope. For the numerator, run the deterministic greedy subsequence automaton for the fixed word ww on the input uλu_\lambda above. Consider one of its unary bb-blocks of length, say, tt. From any state of the automaton, reading btb^t can advance the greedy match by at most ∣w∣|w| states. Hence, for determining the resulting state, it is enough to distinguish the cases t=0,1,…,∣w∣−1t=0,1,\ldots,|w|-1 and t≥∣w∣t\ge|w|. Therefore, since both A≤RA\le R and ww are fixed, the condition w⪯uλw\preceq u_\lambda is a finite disjoint union of systems of linear inequalities in the variables λ1,…,λA\lambda_1,\ldots,\lambda_A. Therefore, both the numerator and the denominator can be computed by fixed-dimensional integer-point counting, for instance by Barvinok’s algorithm [3], in time fw(R)⋅poly⁡(log⁡A+log⁡B+log⁡C)f_w(R)\mathbin{\cdot}\operatorname{poly}(\log A+\log B+\log C).

Small width B≤RB \le R. Let τ\tau be the morphism exchanging aa and bb. The map u↦τ(uR)u\mapsto\tau(u^{R}) is a bijection from LA,B,CL_{A,B,C} to LB,A,CL_{B,A,C}, since reversing changes abab-pairs into baba-pairs and then exchanging the letters changes them back into abab-pairs. Moreover, w⪯uw\preceq u if and only if τ(wR)⪯τ(uR)\tau(w^{R})\preceq\tau(u^{R}). Thus the small-width case reduces to the small-height case for the fixed pattern τ(wR)\tau(w^{R}).

Finally, we combine the preceding lemmas to get the main result.

Theorem 5.7. Fix a binary pattern ww and an error tolerance ε>0\varepsilon>0. There is an algorithm which, on input nonnegative integers A,B,CA,B,C with LA,B,C≠∅L_{A,B,C}\ne\varnothing, outputs a rational number pp satisfying

∣p−pw(A,B,C)∣≤ε,|p-p_w(A,B,C)|\le\varepsilon,

and runs in time polynomial in the bitlength of A,B,CA,B,C, where the polynomial may depend on ww and ε\varepsilon.

Proof. Choose R=R(w,ε)R=R(w,\varepsilon) as in Lemma 5.5.

First test whether there exists any word in LA,B,CL_{A,B,C} containing ww as subsequence. For binary Parikh matrices, this is decidable in polynomial time by the interval criterion of Lemma 3.1 for the possible abab-count after embedding the pattern. If no such word exists, then pw(A,B,C)=0p_w(A,B,C)=0, and the algorithm outputs 0.

Otherwise, if one of AA, BB, CC, or AB−CAB-C is at most RR, compute pw(A,B,C)p_w(A,B,C) exactly by the boundary algorithms from Lemma 5.6.

If none of these four quantities is at most RR, then A,B,C,AB−C>RA,B,C,AB-C>R. By Lemma 5.5, we have pw(A,B,C)≥1−εp_w(A,B,C)\ge1-\varepsilon. The algorithm outputs 1, which has an additive error at most ε\varepsilon.

The algorithms in the boundary regimes (constant-bounded counts) run in time depending on RR and ww, times a polynomial in the bitlength of A,B,CA,B,C. For fixed ww and fixed ε\varepsilon, the number R=R(w,ε)R=R(w,\varepsilon) is a constant. Hence the boundary algorithms run in fw(R)⋅poly⁡(log⁡A+log⁡B+log⁡C)f_w(R)\cdot\operatorname{poly}(\log A+\log B+\log C) time, and the interior case is decided by the constant number of arithmetic tests above. Thus the total running time is polynomial in the input bitlength.

Acknowledgements

The authors used OpenAI’s ChatGPT 5.5 to assist with drafting this manuscript, editing it for clarity, and consolidating the preliminary proof ideas of § 5. All arguments were checked, revised, and approved by the authors, who take full responsibility for the content.

References

  1. [1]Duncan Adamson, Pamela Fleischmann, Annika Huch, Tore Koß, Florin Manea & Dirk Nowotka (2025): k-universality of regular languages. Information and Computation 307 (105357), doi:10.1016/j.ic.2025.105357.DOI
  2. [2]Laura Barker, Pamela Fleischmann, Katharina Harwarth, Florin Manea & Dirk Nowotka (2020): Scattered factor-universality of words. In: Developments in Language Theory, LNCS, Springer International Publishing, Cham, pp. 14–28, doi:10.1007/978-3-030-48516-0_2.
  3. [3]Alexander I. Barvinok (1994): A polynomial time algorithm for counting integral points in polyhedra when the dimension is fixed. Mathematics of Operations Research 19(4), pp. 769–779, doi:10.1287/moor.19.4.769.DOI
  4. [4]Joel D. Day, Pamela Fleischmann, Florin Manea & Dirk Nowotka (2019): k-spectra of weakly c-balanced words. In: DLT 2019, Lecture Notes in Computer Science, Springer, pp. 265–277, doi:10.1007/978-3-030-24886-4_20.DOI
  5. [5]Chao Ding & Arto Salomaa (2006): On some problems of Mateescu concerning subword occurrences. Fundamenta Informaticae 73(1-2), pp. 65–79, doi:10.3233/FUN-2006-731-207.
  6. [6]Szilárd Zsolt Fazekas, Tore Koß, Florin Manea, Robert Mercas & Timo Specht (2024): Subsequence matching and analysis problems for formal languages. In: ISAAC 2024, Leibniz International Proceedings in Informatics (LIPIcs) 322, pp. 28:1–28:23, doi:10.4230/LIPIcs.ISAAC.2024.28.arxiv.org/abs/2410.07992
  7. [7]Stéphane Fossé & Gwénaël Richomme (2004): Some characterizations of Parikh matrix equivalent binary words. Information Processing Letters 92(2), pp. 77–82, doi:10.1016/J.IPL.2004.06.011.DOI
  8. [8]Paweł Gawrychowski, Maria Kosche, Tore Koß, Florin Manea & Stefan Siemer (2021): Efficiently testing Simon’s congruence. In: 38th International Symposium on Theoretical Aspects of Computer Science, STACS 2021, STACS 2021, LIPIcs 187, Schloss Dagstuhl–Leibniz-Zentrum für Informatik, pp. 34:1–34:18, doi:10.4230/LIPIcs.STACS.2021.34.DOI
  9. [9]Leonard H. Haines (1969): On free monoids partially ordered by embedding. Journal of Combinatorial Theory 6(1), pp. 94–98, doi:10.1016/S0021-9800(69)80111-0.DOI
  10. [10]Jean-Jacques Hebrard (1991): An algorithm for distinguishing efficiently bit-strings by their subsequences. Theoretical Computer Science 82(1), pp. 35–49, doi:10.1016/0304-3975(91)90170-7.DOI
  11. [11]Graham Higman (1952): Ordering by divisibility in abstract algebras. Proceedings of the London Mathematical Society 3(1), pp. 326–336, doi:10.1112/plms/s3-2.1.326.DOI
  12. [12]L. O. Kalashnik (1973): The reconstruction of a word from fragments. Numerical Mathematics and Computer Technology, Akad. Nauk Ukrain. SSR Fiz.-Tehn. Inst. Nizkih Temperatur, Kharkov, pp. 56–57.
  13. [13]Prateek Karandikar, Manfred Kufleitner & Philippe Schnoebelen (2015): On the index of Simon’s congruence for piecewise testability. Information Processing Letters 115(4), pp. 515–519, doi:10.1016/j.ipl.2014.11.008.DOI
  14. [14]Prateek Karandikar, Matthias Niewerth & Philippe Schnoebelen (2016): On the state complexity of closures and interiors of regular languages with subwords and superwords. Theoretical Computer Science 610, pp. 91–107, doi:10.1016/j.tcs.2015.09.028.DOI
  15. [15]Maria Kosche, Tore Kōb, Florin Manea & Stefan Siemer (2022): Absent subsequences in words. Fundamenta Informaticae 189(3–4), pp. 199–240, doi:10.3233/FI-222159.
  16. [16]Alexandru Mateescu, Arto Salomaa, Kai Salomaa & Sheng Yu (2001): A sharpening of the Parikh mapping. RAIRO – Theoretical Informatics and Applications 35(6), pp. 551–564, doi:10.1051/ita:2001131. A tribute to Aldo de Luca.DOI
  17. [17]Kathleen M O’Hara (1990): Unimodality of Gaussian coefficients: A constructive proof. Journal of Combinatorial Theory, Series A 53(1), pp. 29–52, doi:10.1016/0097-3165(90)90018-R. Available at https://www.sciencedirect.com/science/article/pii/009731659090018R.DOI
  18. [18]Helmut Prodinger (1979): On a generalization of the Dyck-language over a two letter alphabet. Discrete Mathematics 28(3), pp. 269–276, doi:10.1016/0012-365X(79)90034-1.DOI
  19. [19]Gwénaël Richomme (2026): On some 2-binomial coefficients of binary words: geometrical interpretation, partitions of integers, and fair words. Theoretical Computer Science 1066, p. 115732, doi:10.1016/J.TCS.2025.115732.DOI
  20. [20]Arto Salomaa & Sheng Yu (2010): Subword occurrences, Parikh matrices and Lyndon images. International Journal of Foundations of Computer Science 21(1), pp. 91–111, doi:10.1142/S0129054110007155.DOI
  21. [21]A. D. Scott (1997): Reconstructing sequences. Discrete Mathematics 175(1–3), pp. 231–238, doi:10.1016/S0012-365X(96)00153-7.DOI
  22. [22]Imre Simon (1975): Piecewise testable events. In: Automata Theory and Formal Languages, 2nd GI Conference, Lecture Notes in Computer Science 33, Springer, pp. 214–222, doi:10.1007/3-540-07407-4_23.DOI
  23. [23]Richard P. Stanley (1999): Enumerative combinatorics. Cambridge University Press, doi:10.1017/CBO9780511609589. Available at http://math.mit.edu/~rstan/ec/.DOI
  24. [24]Georg Zetzsche (2015): An approach to computing downward closures. In: Automata, Languages, and Programming - 42nd International Colloquium, ICALP 2015, Proceedings, Part II, Lecture Notes in Computer Science 9135, Springer, pp. 440–451, doi:10.1007/978-3-662-47666-6_35.DOI
  25. [25]Georg Zetzsche (2016): The complexity of downward closure comparisons. In: 43rd International Colloquium on Automata, Languages, and Programming, ICALP 2016, LIPics 55, Schloss Dagstuhl–Leibniz-Zentrum für Informatik, pp. 123:1–123:14, doi:10.4230/LIPIcs.ICALP.2016.123.DOI

Paper details

vlnc:W_bkt6yuj3
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 0

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

GPT-5.5 (bare)

View statement
Looking for related papers…
Contents