Manuscript Offprint
arXiv:2610.06717Subsequence Analysis Problems for Binary Parikh Matrices
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Szilárd Zsolt Fazekas
Akita University
szilard.fazekas@ie.akita-u.ac.jp
Xinhao Huang
Akita University
Robert Mercas
Loughborough University
The universality index corresponding to a word is the largest integer such that every word of length 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 , while the latter considers the index across all words that the language contains.
In this work we study the existential (∃-universality) and universal (∀-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 ∃- and ∀-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.
1 Introduction
A word u is a subsequence of a word w if u can be obtained from w 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 w over an alphabet is called k-subsequence universal, or simply k-universal, if every word in , i.e., every word over of length k, occurs in w as a subsequence. Equivalently, the set of subsequences of w contains the full k-spectrum . 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.
This work was supported by JSPS KAKENHI Grant Number JP26K14700.
M. Hospodár et al. (Eds.): 17th International Conference on Automata and Formal Languages (AFL 2026) EPTCS 451, 2026, pp. 140–154, doi:10.4204/EPTCS.451.10
© Fazekas, Huang, Mercas This work is licensed under the Creative Commons Attribution License.
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 k-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 . For nonnegative integers , let be the language of all binary words with the numbers of letters , letters , and scattered subwords equal , and , 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 , characterizing the former, determines the whole count of length-2 subsequences, which describes the latter. The language is nonempty if and only if , and throughout the paper the entries are part of the input, encoded in binary.
Our first goal is to determine the existential and universal subsequence universality indices of . For a language , we say that is - -universal if some word is -universal, and we write
We say that a nonempty language is -∀-universal if every word is -universal, and we write
The notions, introduced in [1], capture the two natural quantifier choices over the language: the largest k such that a k-universal representative exists, and the largest k such that all representatives are k-universal.
We prove that, for binary 2-deck classes, both indices are computable in polynomial time in the bitlength of A, B, C. In the existential case, we prove that is the minimum among A, B and a simple formula depending on the three input multiplicities. On the universal side, we show that no nonempty language 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 .
Finally, we consider a probabilistic refinement of the existential and universal subsequence questions. For a fixed binary pattern w and a nonempty language , define to be the probability that a uniformly chosen word from contains w as a subsequence. The endpoint conditions and are exactly the existential and universal subsequence problems for the fixed pattern abab. The probability therefore interpolates between the two quantifier extremes: instead of asking whether at least one representative contains w, or whether all representatives contain w, it asks for the density of representatives containing w.
Exact computation of this probability is not expected to be easy in general, since the universal subsequence problem, that is, testing , is as hard as factoring integers already for the fixed pattern . Nevertheless, for every fixed word pattern and fixed error tolerance , we give an additive approximation algorithm for running in time polynomial in the bitlength of . The proof uses the correspondence between binary Parikh matrix/2-deck classes and partitions inside an rectangle: each word in corresponds to a partition of area , in the form of Young diagrams
Subsequence Analysis Problems for Binary Parikh Matrices
(for more details, see Richomme’s discussion of this connection [19]). We combine this partition model with a polynomial bound on the number of w-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 - C is bounded. This yields a constant-error approximation scheme for fixed word patterns, complementing the exact arithmetic characterizations of the - and -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 k-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.
For any integer , let denote the multiplicative monoid of upper triangular matrices with nonnegative integer entries and 1's on the main diagonal. The Parikh matrix mapping [16] with respect to the ordered alphabet , denoted by , is a morphism from into , where
As is a morphism, it maps a word to the matrix . Matrices of the form , for , are termed Parikh matrices. Hence, over the alphabet , Parikh matrices are upper triangular matrix with 1'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 , and in the respective word, i.e., appears in position , in position , and in position .
Note that when considering binary subsequences every pair of positions consisting of one a and one b contributes either to the total number of subsequences ab or to ba. Therefore, we have that in every binary word w the following equality holds
The k-deck of a word is the multiset resulting from counting all occurrences of subsequences of length at most k that the respective word contains. As such, one can define the language corresponding to a given k-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 , its equivalence class, with respect to the Parikh matrix mapping, is the language determined by its matrix . We call such a language a (binary) Parikh matrix language, and for the rest of this work, for nonnegative integers , define
We also denote and have . By definition, this equivalence class is identical to the one corresponding to the 2-deck notion. Moreover, it is straightforward that a language is nonempty if and only if . Indeed, writing a word in the form , we have and . Every integer between 0 and AB is obtainable by distributing the B letters b among the gaps separating the occurrences of a.
For more details on Parikh matrices we refer to [16, 5, 20], while for k-decks we suggest [12, 21].
A word is called -subsequence universal, or simply -universal, over , if . Equivalently, every word of length over occurs in as a subsequence. The universality index of , denoted , is the largest such that is -universal.
For a language , we use the two language-level notions from the -universality literature, see [1]. We say that is - -universal if there exists such that and define is - -universal}. We say that a nonempty is - -universal if every satisfies and define is - -universal}.
As the universality index 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 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 , the arch-factorization of aabbabaa is aab.ba.ba.a, whereas that of aabbb is aab.bb. The following characterization of k-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 and , the following are equivalent:
(i) w is k-universal over ;
(ii) w contains, as a subsequence, some word .
Proof. The implication (ii) (i) is immediate. Every factor ab and every factor ba of (the arches) contains both letters and . Obviously, from a subsequence , where , one can obtain every possible word by choosing the symbol for from the -th arch . Hence , and therefore also , are -universal.
For , we use the standard greedy arch factorization, see [10]. Since is -universal, its arch-factorization contains at least complete arches, i.e., non-overlapping factors having both and . Therefore, each of the arches contains either or as a subsequence; choosing one such two-letter subsequence from each of the first arches gives a subsequence belonging to .
From the lemma above we can directly conclude the following consequence.
Corollary 2.2 ([4]). The shortest k-universal binary words are exactly the words in .
3 ∃-universality
We first turn our attention to when contains a k-universal word. The next lemma is the main interval-realization tool.
Subsequence Analysis Problems for Binary Parikh Matrices
Lemma 3.1. Let , and fix integers and . Then the set of possible values of , over all words with and , and having as subsequence, i.e., , is the integer interval .
Proof. First, if , then the embedded contributes at least pairs of type . Thus . Similarly, the copy of in contributes at least pairs of type . Since Eq. 1 holds for , we get . So every attainable value lies in the stated interval.
Conversely, start with , and insert all extra letters to the far left and all extra letters to the far right. The resulting word has letters , letters , contains as a subsequence, and has exactly subsequences of type .
Now move continuously to the opposite extreme, where all extra letters are placed to the far left and all extra letters are placed to the far right, keeping the original copy of in its original relative order. This can be done by adjacent swaps , each involving at least one of the discussed extra letters. Such a swap preserves the chosen copy of and increases by exactly 1. At the opposite extreme, no pair involving an extra letter contributes to , so the only remaining -pairs are those already inside . Hence the final value of is .
Since at each step changes by one, every integer between and is realized.
Lemma 3.2. If denotes the number of length-2 factors starting at odd positions (blocks) equal to ab in , then , and .
Proof. Each pair of distinct blocks contributes one ab-pair: choose the letter from block and the letter from block . There are such cross-block contributions. In addition, every block contributes one ab-pair, while a block does not. Hence . The formula for follows either by the same argument or from , that is, Eq. 1.
Theorem 3.3. For every , a nonempty language is - -universal if and only if , , , and .
Proof. Suppose first that is - -universal. Then there exists with . By Lemma 2.1, contains a subsequence . Hence contains at least letters and at least letters , so and .
Since , we have that also contains as subsequences at least as many pairs and , as does. Thus, by Lemma 3.2, we conclude that , and .
Conversely, assume , , , and , where . We shall choose such that , for some .
By Lemmas 3.2 and 3.1, a word with blocks can be embedded in some word with parameters , , and if and only if .
Equivalently, . We need an integer satisfying this inequality. Since, from the statement, , we have , and since , we have . Finally,
Because and , we have . Hence the interval has a nonempty intersection with . Choose an integer in this intersection and choose any word with exactly blocks . Then Lemma 3.1 gives a word with . By Lemma 2.1, this word is -universal.
We can now summarize our results so far.
Corollary 3.4. For nonempty , we have .
Proof. By Theorem 3.3, the largest admissible is bounded by , by , and by the largest satisfying . Solving , for , gives .
Furthermore, we draw the following algorithmic consequences.
Corollary 3.5. Given nonnegative integers , , , and in binary, one can decide in polynomial time whether is --universal. When , we can compute in polynomial time.
Proof. First we check whether . If this test fails, then the input does not correspond to any word, i.e., is empty, so the answer is negative. The decision test consists of integer comparisons involving and . The index formula uses an integer square root of , which is computable in polynomial time in the bitlength of the input.
4 -universality
We now turn to the -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 --universal language . Consequently, .
Proof. If or , then no word in 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 , while the maximal is of the form . 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 is 1--universal if and only if every one of its words contains both symbols of the alphabet.
Proposition 4.2. A nonempty language is --universal if and only if and .
Proof. A binary word is 2-universal if and only if it contains all of the four words , , , and as subsequences. The pattern occurs in every word of if and only if , and occurs in every word if and only if . The pattern occurs in every word if and only if , while occurs in every word if and only if .
For --universality we need to understand when a representative of can avoid a fixed binary word of length 3.
Lemma 4.3. Let be nonempty. For each , there exists a word that does not have as a subsequence, if and only if the following avoidability conditions hold (where ):
| pattern u | aaa | bbb | aab | abb | baa | bba | aba | bab |
|---|---|---|---|---|---|---|---|---|
| condition | A < 3 | B < 3 | C ≤ B | C ≤ A | D ≤ B | D ≤ A | A = 0 or A | C | B = 0 or B | C |
In particular, if , the last two conditions reduce to and , respectively.
Subsequence Analysis Problems for Binary Parikh Matrices
Proof. The first two conditions are immediate: every word with at least three a's contains aaa, and every word with at least three b's contains bbb.
For aab, write a word as . The letters within the blocks have exactly letters before them. Thus avoids aab if and only if every has at most one before it, i.e., if and only if all 's lie in the first two blocks. This is possible with total ab-count if and only if . Hence the third condition follows.
The condition for abb is dual. A word avoids abb if and only if every letter a has at most one b after it. Since , this is possible if and only if .
Similarly, a word avoids baa if and only if every letter has at most one after it. Since , this is possible if and only if . A word avoids bba if and only if every letter has at most one before it, which is possible if and only if .
A word avoids aba if and only if no lies between two occurrences of . Equivalently, every is either before all 's or after all 's. If , this is automatic. If , such a word has the form , for some , and its ab-count is . Hence such a word exists if and only if .
The proof for bab is symmetric. A word avoids bab if and only if every is either before all 's or after all 's. If , this is automatic. If , such a word has the form , and its ab-count is . Hence such a word exists if and only if .
Theorem 4.4. A nonempty language is 3-∀-universal if and only if , , and and .
Proof. A binary word is 3-universal if and only if it contains all eight words in . Thus is 3-∀-universal if and only if no word in avoids any of these eight patterns.
By Lemma 4.3, avoidance of aaa is possible if and only if , and avoidance of bbb is possible if and only if . Therefore we must have and .
Under this assumption, the remaining six avoidance conditions are
The negation of the first two is , the negation of the next two is , and the negation of the last two is and . This leads to the stated condition.
Combining the preceding results yields the -universality index.
Theorem 4.5. For a nonempty language we have
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 . If or , no word in the language is 1-universal over the fixed alphabet , so the value is 0.
As a consequence we get the following algorithmic result.
Corollary 4.6. Given nonnegative integers A, B, C, and k in binary, one can decide in polynomial time whether is -universal. One can also compute in polynomial time.
Proof. First check nonemptiness, i.e., . 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 - C, and divisibility tests A | C and B | C. These are polynomial-time operations on binary integers.
5 An additive approximation scheme for fixed-pattern containment
For a fixed word and a finite language , define the subsequence probability of with respect to as the ratio , that is, the probability that a uniformly randomly chosen word from contains as a subsequence.
In our binary setting, we restrict notation and say that for a binary word w and a nonempty language , described via nonnegative integers A, B, C, we have
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 and a word , decide whether there exists such that .
• ∀-SUBSEQUENCE: For a language L and a word w, decide whether holds, for all .
In terms of the ratio defined above, the -SUBSEQUENCE and -SUBSEQUENCE problems ask to decide whether and , 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 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 abab. Here FACTORING* denotes the following interval-divisor problem: given positive integers , with , decide whether has a divisor in the interval . It is easy to see that the usual decision version of factoring integers (does the input integer have a prime factor at most ?) 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 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 abab.
Proof. Set , , , and , so the instance of “do all contain as a subsequence?” created for the FACTORING* instance is . The resulting language 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 abab 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 abab. Equivalently, it
Subsequence Analysis Problems for Binary Parikh Matrices
has the form , possibly allowing some of the four unary blocks to be empty. Thus, if abab is not a common subsequence of all words in , then one of those words has the form . If , where and , then the word is in and it does not contain abab as subsequence.
Conversely, suppose some does not contain abab, i.e., it has the form , for some and . This means that the number of ab's in the word is exactly , so . Moreover, , so , which gives . Finally, , since it is the length of an a-block in a word with V occurrences of a. Note that the division by q above is always valid, since .
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 first and if yes, answer negatively to the factoring instance. If the language is not empty, testing 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 w and error tolerance , the ratio admits an additive polynomial-time approximation scheme in the binary encoding of A,B,C. When A,B,C are fixed and no confusion arises, we streamline the notation further and use only for the ratio with respect to the fixed language .
The endpoint cases and correspond respectively to the -SUBSEQUENCE and -SUBSEQUENCE problems discussed above. Thus 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 from , 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 corresponds uniquely to a partition of area (that is, an integer partition of the number ), where . Thus , where .
Consequently we have
where
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 in this polynomial, which is the number of non-increasing partitions with area C in a bounded box . 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 is called -avoiding if . Let be the size of the subset of consisting of -avoiding words. We first bound by a fixed polynomial in the smaller of the two subsequences' pair counts and . In what follows, a template is an alternating binary word, that is, , for some , where and , for . A word matches the template, if there exist positive integers such that .
Lemma 5.2. For every fixed binary pattern w, there exists a constant such that every w-avoiding binary word matches one of finitely many templates with , where with , for , and the finite set of templates depends only on w.
Proof. To see this, start by using the usual greedy subsequence automaton for . The state means that has been greedily matched. A word avoids if and only if the automaton never reaches state . The automaton can advance at most 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 -avoiding word has at most maximal unary blocks, and therefore matches one of finitely many alternating templates.
Lemma 5.3. For every fixed binary pattern w, there exist constants such that, for all nonempty languages , we have .
Proof. Fix one template from the finite family established by Lemma 5.2. We count the words of matching that template, that is, words of the form , where all . For each such we have .
First assume that , and we bound the number of such words in terms of . If a block participates in at least one summand in this expression, then, since all block lengths are positive, that summand is at least . Hence . Thus every interacting block has length at most . The only blocks not participating in any ab-summand are the possible initial -run and the possible final -run. Moreover, adjacent symbols in the template are distinct, there is at most one initial -block and one final -block. Once the interacting block lengths have been chosen, these outer lengths are uniquely determined by and, respectively, . Therefore this template gives at most possible words.
If , apply the same argument to the reversed words. Reversal sends bijectively to , and is equivalent to . Since is fixed, the same polynomial bound applies with in place of . Thus the number of -avoiding words is polynomial in in this case.
It remains to sum these bounds over the finite template families from Lemma 5.2. We choose (the larger of the constants from Lemma 5.2 for and its reverse) to be the bound on the number of blocks, and the maximum of the numbers of templates associated with and .
The counts of letters or the subsequences ab or ba 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 , there exists such that whenever , we have .
Proof. Let . Thus is the number of partitions of whose Young diagrams fit inside an rectangle. The coefficients are unimodal by Sylvester's classical result (for a more modern reference, see [17]).
Let . First we recall that the coefficients of a Gaussian binomial coefficient are symmetric, that is,
Subsequence Analysis Problems for Binary Parikh Matrices
This symmetry follows from the fact that complementing a Young diagram of area in the rectangle and rotating it by gives a Young diagram enclosed in the same rectangle, but with area . By this symmetry, it is enough to prove a lower bound for , where . Indeed, if , then , while if , then .
Fix . We choose sufficiently large so that and, for all ,
The reason for requiring in the exponent here instead of just is due to a cancellation argument at the end. Now, what we need to show is that, whenever and , we have
The reason for considering the cumulative sum is the following. If we can find a subrectangle of the rectangle whose area is at most s, then every partition fitting inside this subrectangle has area at most s, and therefore contributes to one of the coefficients . Thus a large enough subrectangle of area at most s gives a lower bound on the cumulative sum. We shall choose such a subrectangle so that one of its sides is of order , while the other has fixed size H. This will give polynomially many partitions, with exponent controlled by H.
Set and . We want to construct a subrectangle such that , , and . There are two cases.
First suppose that and we take . This square fits inside , since , and its area is at most . Since , both sides are at least . Also , so the larger side is at least .
Now suppose that . We take and . Then , and . Moreover, since , we have , and hence . Therefore the rectangle fits inside . We also have . Since , we get , and hence
where the last inequality holds because is large enough. In particular, . Thus the required properties hold in this case as well.
Since is either or , the constructed rectangle fits inside the rectangle, possibly after transposing it when . In the latter case, transposition gives an area-preserving bijection between partitions fitting inside the rectangle and partitions fitting inside the rectangle. Hence, after possibly interchanging and , we may assume that and .
We have therefore found, in all cases, a subrectangle with area at most , both sides at least , and larger side at least . Consequently,
Let . Since the rectangle has one side and the other side at least , it contains, up to transposition, an rectangle. Hence
Using , we obtain
Since , we have , and therefore
Finally, since , symmetry and unimodality imply that is the largest coefficient among . Hence
By the choice of , the right-hand side is at least . Therefore, as required, . Since , symmetry gives . Therefore
Next we show that, if each of A, 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 w and . There exists such that if and the language contains at least one word having w as subsequence, then .
Proof. Let and be the constants from Lemma 5.3. Choose an integer . By Lemma 5.4, whenever we have that
On the other hand, . Therefore
Choose sufficiently large that
Since , and are constants, such a choice is possible, and guarantees that the right-hand side of inequality (3) above is at most . Hence
Let be fixed. We show that can be computed exactly in time whenever at least one of , or is at most . Note that here denotes a function which in general is not necessarily polynomial in .
Subsequence Analysis Problems for Binary Parikh Matrices
Lemma 5.6. Fix a binary pattern w and an integer R. There is an algorithm which computes in time , whenever is nonempty and at least one of A, B, C, AB - C is at most R.
Proof. If any of the input counts are 0, then the probability can be computed trivially. Now assume the counts are positive.
Small area . Every partition of area C fits inside a square. Thus we enumerate all partitions of C, discard those with more than A parts (rows) or largest part greater than B, and test whether the corresponding word contains w as subsequence.
If has nonzero parts and largest part , then the corresponding word has the form , where that has at most occurrences of and at most occurrences of . For testing containment of the fixed pattern , the outer blocks may be capped at :
Thus each test is performed on a word of length .
Since the number of partitions of is , the small-area case is exact in time poly(|w|, logA, logB).
Small coarea . By reversing the word we have , and is equivalent to . Hence , which reduces to the small-area case.
Small height . Write
where and . In , 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 on the input above. Consider one of its unary -blocks of length, say, . From any state of the automaton, reading can advance the greedy match by at most states. Hence, for determining the resulting state, it is enough to distinguish the cases and . Therefore, since both and are fixed, the condition is a finite disjoint union of systems of linear inequalities in the variables . 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 .
Small width . Let be the morphism exchanging and . The map is a bijection from to , since reversing changes -pairs into -pairs and then exchanging the letters changes them back into -pairs. Moreover, if and only if . Thus the small-width case reduces to the small-height case for the fixed pattern .
Finally, we combine the preceding lemmas to get the main result.
Theorem 5.7. Fix a binary pattern w and an error tolerance . There is an algorithm which, on input nonnegative integers A, B, C with , outputs a rational number p satisfying
and runs in time polynomial in the bitlength of A, B, C, where the polynomial may depend on w and .
Proof. Choose as in Lemma 5.5.
First test whether there exists any word in containing w as subsequence. For binary Parikh matrices, this is decidable in polynomial time by the interval criterion of Lemma 3.1 for the possible ab-count after embedding the pattern. If no such word exists, then , and the algorithm outputs 0.
Otherwise, if one of A, B, C, or AB - C is at most R, compute exactly by the boundary algorithms from Lemma 5.6.
If none of these four quantities is at most , then . By Lemma 5.5, we have . The algorithm outputs 1, which has an additive error at most .
The algorithms in the boundary regimes (constant-bounded counts) run in time depending on and , times a polynomial in the bitlength of . For fixed and fixed , the number is a constant. Hence the boundary algorithms run in 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.
6 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 Section 5. All arguments were checked, revised, and approved by the authors, who take full responsibility for the content.
References
[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.
[2] Laura Barker, Pamela Fleischmann, Katharina Harwardt, 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] 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.
[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.
[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] 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.
[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.
[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, LIPIcs 187, Schloss Dagstuhl–Leibniz-Zentrum für Informatik, pp. 34:1–34:18, doi:10.4230/LIPIcs.STACS.2021.34.
[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.
[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.
Subsequence Analysis Problems for Binary Parikh Matrices
[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.
[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] 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.
[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.
[15] Maria Kosche, Tore Koß, Florin Manea & Stefan Siemer (2022): Absent subsequences in words. Fundamenta Informaticae 189(3–4), pp. 199–240, doi:10.3233/FI-222159.
[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.
[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.
[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)90134-1.
[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.
[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.
[21] A. D. Scott (1997): Reconstructing sequences. Discrete Mathematics 175(1–3), pp. 231–238, doi:10.1016/S0012-365X(96)00153-7.
[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.
[23] Richard P. Stanley (1999): Enumerative combinatorics. Cambridge University Press, doi:10.1017/CBO9780511609589. Available at http://math.mit.edu/~rstan/ec/.
[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.
[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.