Manuscript Offprint
arXiv:2609.35746Near-Optimal Bounds for Testing Residual-String Equality and Parenthesis Languages
Abstract
Residual-String Equality, denoted ResStringEq, is the property consisting of all pairs of strings over that are equal after deleting all ‘*’ symbols from them. This property was first introduced by Fischer, Magniez, and Starikovskaya (SODA 2018), who used it to show a lower bound on testing the Dyck languages, where Dyck is the language consisting of balanced sequences of parentheses over parenthesis types. They showed that testing ResStringEq on inputs of length requires queries, and presented a reduction from testing ResStringEq to testing Dyck where . Furthermore, they showed that Dyck can be tested with queries for every constant proximity parameter, where is an arbitrarily small constant.
In this work, we nearly close the remaining gap, by showing that testing ResStringEq, and hence Dyck where , requires queries. We also show a stronger lower bound of for testers that make non-adaptive queries. We establish that the bound is nearly tight, by presenting a non-adaptive tester for ResStringEq that uses queries for an arbitrarily small constant . Furthermore, we extend this non-adaptive tester to the Dyck languages, with the same query complexity. Finally, we improve the dependence on the proximity parameter in the tester of Fischer, Magniez, and Starikovskaya, reducing it from to .
Contents
1 Introduction 3
1.1 Our results 3
1.2 Organization 5
2 Technical overview 5
2.1 The lower bound 5
2.1.1 An lower bound 5
2.1.2 Improving the lower bound to 9
2.2 A non-adaptive tester 10
3 Preliminaries 13
4 Lower bound 14
4.1 The two distributions 14
4.2 The non-adaptive case 15
4.3 The adaptive case 16
4.3.1 Proof of Lemma 4.8 17
5 A non-adaptive tester for ResStringEq 23
5.1 A warm-up 23
5.1.1 A basic adaptive tester 23
5.1.2 Correctness 24
5.1.3 Making the basic tester non-adaptive 25
5.2 The actual non-adaptive tester 27
5.2.1 Query complexity 30
5.2.2 Correctness 30
5.3 On the adaptive tester for ResStringEq 33
6 Extending the non-adaptive tester to the Dyck languages 33
6.1 Preliminaries 34
6.2 The excess parentheses matching procedure 37
6.3 The tester 39
6.3.1 Query complexity 40
6.3.2 Correctness 40
6.4 On the adaptive tester for the Dyck languages 41
Acknowledgments 42
References 42
Appendices 43
A A reduction to the equal-length case in ResStringEq 43
B Proof of Fact 4.7 43
Standard decision problems generally require reading the entire input, since flipping a single bit can change the decision. In contrast, relaxed decision opens the possibility of algorithms that (probabilistically) read only a sub-linear portion of the input. Thus, in property testing, the input is viewed as a huge object to which the tester gets only oracle access, and the main focus is on minimizing the query complexity.
Perhaps the most basic property is the Equality property, defined as . This property is easy to test by comparing the two input strings at random positions. The focus of this work is on the following natural variant of Equality, introduced by [FMS18], which is significantly harder to test. In this variant, the tester is given two strings over and is required to decide whether the two strings are equal after deleting all ‘*’ symbols from them.
Definition 1.1 (Residual-String Equality (a.k.a. True-String Equality [FMS18])). For every string , let denote the residual string obtained from after deleting all ‘*’ symbols from it. The property is the set of all pairs of strings such that .
The property ResStringEq was first introduced by [FMS18] as a means towards proving a lower bound on the complexity of testing the family of Dyck languages, where Dyck_m is the (context-free) language consisting of all balanced sequences of parentheses over m parenthesis types. The Dyck languages play an important role in the theory of context-free languages (see the Chomsky–Schützenberger representation theorem [CS63]). They were first considered in the context of property testing by [AKNS01], who initiated a general study of testing formal languages. In particular, [AKNS01] showed that testing Dyck_1 (the set of balanced parentheses with one parenthesis type) can be done using queries, whereas testing Dyck_2 requires at least queries. Testing the Dyck languages then became the focus of [PRR03], who showed that, for every , testing Dyck_m requires queries and can be done using queries for every constant . These bounds were then improved by [FMS18] to and , respectively, where is an arbitrarily small constant. To prove their lower bound, [FMS18] first showed a simple reduction from testing ResStringEq to testing Dyck_2, and then showed a lower bound of on testing ResStringEq.
1.1 Our results
Our main result is nearly closing the remaining gap, by showing:
We could also allow s and to differ in length. Note that -testing this more general definition reduces to -testing the equal-length case, by padding the shorter string with ‘*’ symbols. See Appendix A for details.
Note that a lower bound on testing Dyck implies a lower bound on testing Dyck for any .
Specifically, given input , the reduction runs the tester for while emulating its queries to a parentheses sequence defined as follows. First, concatenate with the reverse of . Then, replace each ‘0’ in by ‘(‘ and each ‘1’ by ‘[’. In the reverse of , replace each ‘0’ by ‘)’) and each ‘1’ by ‘[]’. Finally, replace all ‘*’ symbols by ‘()’. (Note that each symbol in is replaced by two symbols in the parentheses-expression so that the correspondence between locations is oblivious of the input strings.)
Theorem 1.2. Testing ResStringEq requires queries.
As a corollary, we obtain:
Corollary 1.3. For every , testing Dyck requires queries.
Both of these results are nearly tight, by the -query tester given in [FMS18] for the Dyck languages, and the reduction they showed from testing ResStringEq to testing Dyck . In particular, these results show that although ResStringEq is a seemingly easier problem than Dyck , both problems actually have similar complexity. We stress that both lower bounds hold for testers with two-sided error.
The non-adaptive setting. An important type of testers are testers that make non-adaptive queries. A tester makes non-adaptive queries if its queries to the input do not depend on the answers to prior queries. Non-adaptive testers allow making all queries to the input in one batch, which is useful in settings in which each round of accessing the input has a large overhead.
Both the earlier -query tester of [PRR03] and the later -query tester of [FMS18] use adaptive queries. We show that non-adaptive testers for ResStringEq (and hence also for the Dyck languages, where ) require queries.
Theorem 1.4. Any non-adaptive tester for ResStringEq must make at least queries.
Theorem 1.4 shows the necessity of adaptivity in the -query tester of [FMS18]. We show that the bound is nearly tight, by designing a nearly matching non-adaptive tester for ResStringEq:
Theorem 1.5. For any (arbitrarily small) constant , and every constant , there exists a non-adaptive -tester for ResStringEq that makes queries.
Building on this tester, we obtain:
Theorem 1.6. For every , every (arbitrarily small) constant , and every constant , there exists a non-adaptive -tester for Dyck that makes queries.
The dependence of the query complexity on the proximity parameter. The query complexity achieved by [FMS18] comes at a high cost in terms of the dependence on , namely, the dependence on in their tester is super-exponential in . More precisely, their tester has query complexity . We show that this super-exponential dependence can be avoided. Specifically, through a more careful analysis and parameter choice, we achieve query complexity for the non-adaptive testers in Theorems 1.5 and 1.6. We show that this improved dependence can be carried over to the tester of [FMS18], yielding adaptive testers for both ResStringEq and the Dyck languages with query complexity (see Theorems 5.15 and 6.12, respectively).
Note that [AKNS01] showed that one-sided error testers for the Dyck languages require queries, even for Dyck . Furthermore, the same linear lower bound holds for ResStringEq: Let , and consider the pair where and . Clearly is -far from ResStringEq. However, if the tester queries at most positions of , then the query answers are consistent with the YES-instance obtained by changing of the unqueried positions in from ‘*’ to ‘0’.
1.2 Organization
A technical overview of our results is presented in Section 2, where Subsection 2.1 contains an overview of the lower bound (Theorem 1.2) and Subsection 2.2 contains an overview of the non-adaptive tester for ResStringEq (Theorem 1.5). Basic preliminaries are presented in Section 3. The proof of the lower bound is presented in Section 4, which also includes a proof of the lower bound for the non-adaptive case (see Subsection 4.2). The non-adaptive tester for ResStringEq and its analysis are presented in Section 5, where Subsection 5.1 begins with a warm-up towards this tester, and the actual tester is presented in Subsection 5.2. Finally, in Section 6 we extend the non-adaptive tester to the Dyck languages.
2 Technical overview
2.1 The lower bound
We prove the lower bound for ResStringEq by the standard indistinguishability method. That is, we construct two distributions over input strings: a YES distribution, which is over inputs in ResStringEq, and a NO distribution, which is concentrated over inputs far from ResStringEq. We then show that any tester making queries cannot distinguish between inputs drawn from these two distributions.
The proof builds on ideas developed in [FMS18] and [PRR03]. We give an overview of the proof in two parts. In the first part (presented in Section 2.1.1), we explain how to obtain a lower bound of . This improved lower bound is obtained by a tighter analysis of (essentially) the same construction of the YES and NO distributions used in [FMS18] and [PRR03]. In the second part of the overview, presented in Section 2.1.2, we explain how we modify the construction to further improve the bound to .
2.1.1 An lower bound
The two distributions. We construct two random pairs of strings over : a YES pair and a NO pair . Roughly speaking, in both distributions, we choose in each string independently random positions for the star (i.e., ‘*’) symbols. We then fill the remaining positions with uniform random bits, such that in the YES distribution we use the same values in the two strings, whereas in the NO distribution, we use the same values only in the “extremities” of the two strings, and use independent values in the “middle” of the strings (specifically, in the middle third of the non-star positions).
More precisely, we first choose the locations of the star symbols identically in the two distributions, as follows. We begin with the first string in the pair (i.e., in the YES pair and in the NO pair). We draw values , and place a star symbol at every position where . To ensure that exactly positions contain star symbols, we draw the first values independently and uniformly from , and then set the other mirror positions to the complementary values; that is, we set for every . Independently, we do the same for the second string (i.e., and ), using fresh values
Although the lower bound in [PRR03] is presented for the Dyck languages, their proof implicitly establishes the lower bound for ResStringEq.
Recall that the previous best known lower bound was [FMS18].
Note that in order for the YES pair to be in ResStringEq, we require that both strings in the pair contain exactly the same number of star positions.
. We stress that we use the same values and to construct both the YES and NO pairs.
For every such that (i.e., is not a star position), we define its rank in the first string, denoted , as the number of non-star positions up to and including ; that is, . If is a star-position (i.e., ), we define . Similarly, we let denote the rank of in the second string, defined analogously with respect to .
We now fill the remaining positions in the strings. In the YES pair , for every , we draw a uniform bit and place it in the two positions with rank ; that is, we set , where and are the positions such that . In the NO pair , we do the same, except that on the middle block of ranks we use independent bits in the two strings. Specifically, let be the middle third of the ranks. Then, for ranks we use a shared uniform bit exactly as before (i.e., we set , where ), while for ranks we draw two independent uniform bits , and use in the first string and in the second (i.e., we set and , where ).
The indistinguishability claim. We say that and are matching positions if . We say that and are interior matching positions if . First, we argue that as long as the tester does not query interior matching positions, it will not be able to distinguish between the two distributions. Roughly speaking, this holds because, if the tester did not query interior matching positions, then in both distributions the answer to any query whose rank is in is a uniform bit, independent of all other answers. On the other hand, we show that the probability of querying interior matching positions is at most , where is the query complexity of the tester. This implies that as long as , the two views are indistinguishable, establishing the lower bound. We proceed to explain how we bound the probability of querying interior matching positions. We will rely on a standard anti-concentration bound that states that for a sum of independent unbiased Bernoulli random variables it holds that .
The non-adaptive case. Let us first consider the case where the tester uses non-adaptive queries. First, note that if , then it must hold that (because there must be at least positions before and at least positions after that have the remaining ranks). We claim that for every and every fixed , it holds that . If , then is a sum of independent Bernoulli random variables, and hence by the anti-concentration bound stated above , where we use the fact that . The case is symmetric: since the total sum of is , we can write , where are independent Bernoulli random variables.
Thus, for any pair of positions , the probability that is at most (because and are independent). Since we assume the queries are non-adaptive, we can take a union bound over all pairs of queried positions, one from each string, and obtain that the probability that the tester queries interior matching positions is at most , as claimed.
The adaptive case. Handling adaptive queries is more challenging. When queries are adaptive, the probability of querying matching positions is influenced by whether we have queried matching positions (not necessarily interior ones) in previous query rounds. Specifically, if we have previously queried matching positions , then positions in the vicinity of and are more likely to match as well (similarly to how there is a high chance of finding matching positions close to the extremities of the strings). However, this probability decreases with the distance from and . To illustrate, suppose that we are given a pair of matching positions , and now consider a new pair of positions that lie on the same side of ; that is, and , or and . Since and are matching, the new positions are matching if and only if the number of non-star positions between and is equal to the number of non-star positions between and . By the anti-concentration bound referenced above, the probability of this event is at most .
For this reason, we will argue that in each query we can make only a limited amount of “progress” from the extremities towards the interior of the string. In order to make this more precise, we focus (for the remainder of this overview) on the following simplified setting, which will convey the main idea in a cleaner form. We will assume that the tester proceeds in two stages: In the first stage, it adaptively queries the second string, at positions denoted . In the second stage, it adaptively queries the first half of the first string at monotonically increasing positions, denoted where for every .
Now, for each query , we let denote the maximal depth of a matched first-string query so far. More precisely, is the maximum position among that matches one of the queried positions in the second string . If there is no such position, we define . We define the progress of query as .
We first bound the probability of making a large amount of progress in a single query. More specifically, for each , we consider the probability that . Notice that if , then the following two events must hold:
-
The first-string query position matches with some queried position in the second string. Let us denote this event by .
-
In the interval (i.e., the positions going back from ) there are no previous first-string queries that match with a queried position in the second string. Let us denote this event by .
In order to analyze the probability that both events and hold, we first condition on the answers to all queries made prior to , which fixes the query positions and . Furthermore, we fix the star-positions in the first string up to position as well as all star-positions in the second string (i.e., we fix the variables for all , and all variables ).
Suppose first that there are no previous queries that lie in the interval (i.e., including queries that do not match any queried position in the second string). In this case, the variables in the interval are independent of the previous query answers that we conditioned on (because these answers concern only positions up to in the first string or positions in the second string). In other words, fixing the previous query answers does not change the distribution of the variables in the interval , and thus we still have independent Bernoulli variables in the sum defining the rank of . Therefore, the probability that matches any specific query position in the second string is at most . By a union bound, the probability that there exists some second-string query position that matches with (i.e., event holds) is at most .
We stress that this is for illustration purposes only; the actual tester does not necessarily know whether previous positions it has queried are matching or not. However, we mention that our lower bound would still hold even if the tester were given this information for free.
In general, there could be up to unmatched queries in the interval (meaning queries that do not match any queried position in the second string). First, note that conditioning on the previous query answers fixes the variables of queried positions inside . More importantly, this conditioning fixes also the bit answers to previous queries at non-star positions in the interval, and fixing these bit answers may affect the distribution of the remaining variables at unqueried positions in the interval. To see why, recall that in the YES distribution, for every , the two positions with rank contain a shared uniform bit . Suppose that the tester previously queried some position in the interval , and that the answer to the query was not a star symbol. Then the answer fixes the bit , where the rank depends on the still-unfixed star-positions that lie before in the interval.
Nevertheless, we rely on the fact that the queries in the interval are all unmatched (i.e., event holds), to show that fixing the previous bit answers has only a limited effect. Specifically, we first show that after fixing all the relevant star-positions (i.e., all the variables at positions and at previously queried positions, as well as all second-string variables ), we have:
where denotes the fixing of the previous bit answers. The main observation needed to prove Eq. (1) is that no matter how we fix the remaining variables such that all queries in the interval are unmatched, the query answers in the interval at non-star positions are always uniform bits, independent of all other answers. In other words, in any such fixing, the distribution of the previous bit answers remains the same. This implies the conditional probability bound in Eq. (1); see Claim 4.13 for details.
Thus, we will aim to show that . Intuitively, we can use the same anti-concentration argument that we have used so far to upper bound the probability of the complement event (i.e., the event that some query in the interval is matched with a second-string query). However, to apply the anti-concentration argument, we need to have sufficiently many unfixed variables prior to each previous query in the interval. We encounter a problem when many previous queries are “crowded together” near to the start of the interval (recall that the variables are fixed at positions , as well as at all previously queried positions).
To handle this, we use the following combinatorial observation. For any , it is possible to partition the progress interval into two parts, and , that satisfy the following two properties:
-
Order the first-string query positions that lie in the second part from left to right, and denote the query position by . Then, for every , there are at least unqueried positions strictly between and .
-
The size of the first part is less than , where is the number of first-string query positions that lie in .
We can always obtain such a partition as follows. Start with . If the first property fails, move to an arbitrary query position for which it fails, and repeat until the property holds. Notice that each time we move , the interval that is skipped must be of length less than times the number of queried positions in that interval. Since the skipped intervals are disjoint, the second property follows.
We stress that we do not actually fix the remaining variables, we only consider all such fixings as part of proving Eq. (1).
Keeping as a parameter to be set later, we denote the progress corresponding to the second part by , and continue our analysis with instead of . Using the first property of the partition, we can now upper bound the probability of the event . Specifically, we may assume that, for every , there are at least unqueried positions in before the query in this interval (if this condition fails, we can increase until the condition holds; if no such exists, then the event is impossible). Hence, the probability that the query point in the interval matches with some second-string query point is at most . Taking a union bound over the at most queries in the interval, the probability that one of them matches some second-string query point (i.e., event holds) is at most , where we use the fact that for every it holds that . Thus, choosing for a sufficiently large constant , we get , implying .
We are left to upper bound the probability of the event (i.e., the event that matches some second-string query point). Notice that there are at least unqueried points in the interval (because for every queried point in the interval there are at least unqueried points). Therefore, we have . Using Eq. (1), we obtain .
We use the foregoing probability bound to bound the expected amount of progress made across all queries. First, for the second part of the progress, we have (where we again use the bound for every ). Summing across all queries, we get .
Next, consider the contribution to the progress coming from the first parts (i.e., ). By the second property of the partition, this contribution across all queries is at most . Recall that we have required that . Therefore, we set , making this contribution . Overall, we obtain .
Now, recall that our goal is to bound the probability that the tester queries interior matching positions, and that this event implies that the total progress exceeds . By Markov's inequality, we obtain that the probability of the latter event is at most , establishing the desired bound.
2.1.2 Improving the lower bound to
To obtain the lower bound, we modify the above construction of the YES and NO distributions as follows. We partition the strings into consecutive blocks of length , where is a parameter that we will specify later. Instead of choosing for each position individually whether it is a star-position or not, we choose for every block a uniformly random value , where will be the number of non-star positions in the block. (As before, to ensure that there are exactly star-positions, we choose the first half of the block values independently, and then set complementary values for the mirror blocks.) Within each block, the locations of the prescribed number of non-star positions can be chosen arbitrarily.
As before, we define the rank of each non-star position to be the number of non-star positions up to and including position . Under the new construction, the rank of position is the sum of all block values prior to the block of , plus the number of non-star positions in the block of up to and including position .
Intuitively, the gain of this new construction comes from making the number of star positions in each block less concentrated. Specifically, whereas in the original construction the number of star positions in each block was highly concentrated around , here this number is spread evenly across all possible values in . Intuitively, making the number of star-positions in the blocks less concentrated makes it harder to find positions of equal rank.
More concretely, for independent random variables that are uniform over , it holds that (as opposed to that we had in the case of Bernoulli random variables). Let us first reconsider the case of non-adaptive testers that we analyzed in the previous section. For every , the rank is now composed of variables that are uniform over . Therefore, for every fixed , the probability is now only (compared to the bound we had before). We set where is a sufficiently small constant, and get that . Taking a union bound over the at most query pairs, it follows that the probability of querying interior matching positions is at most , establishing an lower bound for non-adaptive testers.
Returning to the adaptive case, note that each previous query can now affect an entire block, because star-positions inside the same block are now dependent. We therefore measure progress in blocks; that is, the event now stands for making at least blocks of progress. We use a decomposition of the progress similar to the one we used before, with . The decomposition ensures that in the second part of the progress there are at least unqueried blocks prior to the query, whereas the first parts of the progress consist of up to blocks in total.
We apply the stronger anti-concentration inequality to bound the expected contribution of the second parts of the progress . Specifically, we now have , which is at most provided that for a sufficiently large constant . Furthermore, we have . This gives us .
On the other hand, we need to add the contribution of the first part of the progress, which can now be up to 2q blocks in total. Thus, we get , which in units of string positions is . We set , and by Markov's inequality, we get that the probability of reaching beyond position is at most , giving us the desired bound.
2.2 A non-adaptive tester
Our non-adaptive tester for ResStringEq is an adaptation of the tester of [FMS18]. Recall that [FMS18] showed a tester for the Dyck languages with query complexity , where is an arbitrarily small constant. As a sub-protocol used in their tester, they presented a procedure named “Substring -matching” (see [FMS18, Algorithm 3]). This procedure can essentially be viewed as a tester for ResStringEq, and it has our target query complexity of . However, it is adaptive. We show that it is possible to modify their procedure to be non-adaptive, with essentially no additional overhead.
We next give a high-level overview of the tester. The overview will be structured as follows: As a warm-up, we first present a basic tester, which is adaptive and uses queries. We then explain how we can modify this basic tester to be non-adaptive, at the cost of increasing the query complexity to . Finally, we show how we can improve the query complexity by using recursion, and obtain the desired bound.
The basic tester. For a string and a position , we define the rank of in , denoted , as the number of non-star symbols in up to and including position ; that is, . The basic thing we would like to do is check that at (random) non-star positions of equal rank the two strings match. However, the issue is that we do not know the ranks of positions we query.
The first important observation is that by sampling random positions in the strings, we can obtain estimates of the various ranks. Specifically, for , if we query each string at random positions, we can obtain an estimate of the rank of each position up to an additive deviation of , where the failure probability of each estimate individually is at most (see Claim 5.3). By a union bound, all the estimates are successful simultaneously with high probability.
This gives rise to the following basic tester: For a parameter to be determined later, we first obtain estimates of all ranks up to an additive deviation of . Based on these estimates, we partition the strings into “rank-segments” that each contain approximately non-star symbols. Specifically, the rank-segment of each string consists of the positions whose estimated ranks are between and .
We now know that, for every , the rank-segment of the first input string should “approximately match” with the rank-segment of the second input string. Specifically, assuming the estimates are successful, each such pair of corresponding rank-segments contains the same range of ranks, up to an offset of at most at each endpoint. Thus, in a YES-input, for each pair of corresponding rank-segments, the residual strings in the segments match up to boundary slack , meaning that the two residual strings agree after deleting at most symbols from the beginning of one of them, and possibly leaving at most extra symbols at the end of one of them. On the other hand, if the input is -far from ResStringEq, then at least an fraction of the corresponding rank-segments do not satisfy this boundary-slack matching condition (see Claim 5.4).
Therefore, after partitioning the strings into rank-segments, we uniformly select pairs of corresponding rank-segments, query the entire segments, and check that their residual strings match up to boundary slack . Importantly, we can avoid querying any “long” rank-segments, where we call a rank-segment long if its length is greater than , for a sufficiently small constant . Roughly speaking, this is because long rank-segments are necessarily sparse (i.e., they each contain at most an fraction of non-star symbols), and hence they cannot contribute many mismatches between the strings.
Recall that we set . Thus, for constant , we query positions for obtaining the estimates, and positions when querying the (non-long) rank-segments. To balance these two terms, we set and obtain a tester of query complexity . (In Section 5.1.1 we provide a formal construction and analysis of this basic tester, as a warm-up towards our actual tester.)
Transforming the basic tester to be non-adaptive. Note that the basic tester is inherently adaptive: it must first obtain the rank estimates before it can query the corresponding rank-segments. Hence, rather than directly querying the rank-segments (whose locations are unknown
Note that if each query told us, in addition to the value of the string at the queried position, also the rank of that position, then we could easily get the bound: We would query random positions in each of the two input strings. By the birthday paradox, w.h.p. the queried positions will contain two positions of matching ranks, and we can compare the corresponding values for consistency.
We will set in the basic adaptive tester.
Note that this reestablishes the query complexity bound obtained by combining the reduction of [FMS18] with the tester for the Dyck languages given in [PRR03].
to us), we proceed as follows. We consider a covering of the strings by fixed blocks of equal length that are positioned at shifts of size from one another. Note that this choice of parameters ensures that any non-long rank-segment is necessarily contained in some block of the covering (recall that long rank-segments can be discarded). In addition, note that there are blocks.
Rather than sampling corresponding rank-segments, we uniformly sample (in advance of estimating the ranks) blocks from the covering (and query the selected blocks in their entirety). After obtaining the estimates, we search for pairs of corresponding rank-segments such that each segment is contained in one of the sampled blocks. For each such pair, we check that the residual strings of the two rank-segments match up to boundary slack (as described above). Since we sample blocks, a birthday-paradox-type argument shows that, in the NO-case, with high probability, at least one of the pairs that do not match up to boundary slack will have both rank-segments contained in sampled blocks, and will be detected (see Claim 5.7).
The total query complexity of the foregoing non-adaptive tester is , where the first term accounts for the query complexity of obtaining the estimates (recall that ), and the second term accounts for the query complexity of querying blocks, each of size . Balancing the two terms, we set , which gives us query complexity . (In Section 5.1.3 we present a formal construction and analysis of this basic non-adaptive tester, as a warm-up towards our actual tester.)
Improving the tester by using recursion. The basic tester reads the sampled blocks in their entirety, in order to compare the corresponding rank-segments and check if their residual strings match up to boundary slack. Rather than reading the entire blocks, we would like to continue the comparison of the corresponding rank-segments by recursion. However, in contrast to the original input strings, whose residual strings need to match exactly, the residual strings of the corresponding rank-segments only need to match up to boundary slack . This means that there can be an offset of at most initial symbols that should be skipped in one of the two residual strings before starting the comparison. The issue is that we do not know what the offset is and therefore do not know which positions should be compared.
The solution is to try all offsets, and accept if and only if for one of them all recursive calls accepted. We take a union bound over the failure probability of each offset trial; note that we have only possible offsets, whereas we can reduce the failure probability exponentially with repeated invocations. Crucially, we do not need to sample a separate collection of blocks for each offset. We sample blocks once, independently of the offset, and use the same sampled blocks across all offset trials.
More concretely, the final tester proceeds as follows. It is composed of two sub-procedures that are each recursive: a Query procedure, and a Decision procedure. The Query procedure is run separately on each of the input strings and makes all queries. The Decision procedure receives the outputs of the Query procedure and decides whether to accept or reject the input pair.
On query access to a string , the Query procedure first queries at uniformly random positions, where these queries will later be used for obtaining the rank estimates. It then
We note that the “Substring -matching” procedure of [FMS18] also utilizes the birthday paradox, although for a different reason that will become clearer when we present the final recursive tester. The procedure of [FMS18] directly samples a square-root number of (their analog of the) rank-segments, whereas here we sample the fixed blocks.
In other words, pre-sampling a square-root number of the fixed blocks (rather than sampling corresponding rank-segments, as in the basic adaptive tester) now serves two purposes: it allows the tester to be non-adaptive, and allows the same samples to be reused across the different offset trials.
samples blocks of s, and recursively invokes the Query procedure on each sampled block. In the final recursion round, it queries the entire input string.
We next give only a very high-level description of the Decision procedure; the full details appear in Section 5.2. When comparing strings s and , the Decision procedure first estimates the ranks of all positions in the strings (using the estimation queries made by the Query procedure). Then, at the first recursion level, the procedure searches for pairs of corresponding rank-segments that are both contained in blocks that were sampled by the Query procedure. For each such pair, it checks if the residual strings of the two rank-segments match up to boundary slack , by recursively invoking the Decision procedure on these rank-segments. The recursive call receives the outputs of the Query procedure on the two sampled blocks containing these rank-segments, together with the position of each rank-segment within its respective block.
In the next recursion levels, after estimating the ranks, the Decision procedure considers both possible ways of ordering the two input strings, and for each ordering it considers all relevant offsets h. For each offset, it partitions the two strings into rank-segments as before, except that when partitioning the first string (w.r.t. the current ordering of the two strings), it discards the first h (estimated) ranks. It then searches, as before, for pairs of corresponding rank-segments that are contained in sampled blocks, and recursively checks whether their residual strings match up to boundary slack. The procedure accepts if and only if there was some inspected offset h for which all recursive calls accepted.
Denoting the query complexity of the tester after recursion rounds by , we have , where . We write , where , and we choose so as to balance the terms and , which gives . With this choice of , we get . Together with , the solution to the recursion yields . Thus, the final query complexity after recursion rounds is . (Indeed, the basic non-adaptive -query tester discussed above is a special case corresponding to .) Setting , we get the desired bound.
A remark on obtaining an -query adaptive tester. Composing the basic adaptive tester with the foregoing recursive procedure directly yields an -query adaptive tester for ResStringEq, analogous to the tester of [FMS18] for the Dyck languages. Recall that the basic adaptive tester selects pairs of corresponding rank-segments, and if both segments are short, it queries the segments in their entirety, and checks whether their residual strings match up to boundary slack . Rather than reading the selected rank-segments entirely, we can instead perform each of the boundary-slack matching checks by invoking the recursive procedure described above. For constant , this will require us to query only points in each of the sampled pairs of corresponding rank-segments. To balance this term with the queries needed for the rank estimates, we set , giving us the claimed query complexity.
3 Preliminaries
Property testing. For an alphabet , a property is a collection of sets such that is a set of strings in . The relative hamming distance between two strings is the fraction of positions on which they differ. We say is -far from if the relative hamming distance
Actually, for convenience, in the actual implementation we do not treat the first recursive round separately. Instead, already in the first round, we use the more general procedure (that tries all offsets) described for the second round onward. Hence, our tester accepts inputs even if their residual strings only match up to boundary slack .
between and is greater than , and otherwise we say they are -close. A string is -far from a property if it is -far from any ; otherwise, it is -close to . A tester for a property is a probabilistic algorithm that, on input parameters , and oracle access to , outputs 1 with probability at least if is in ("completeness"), and outputs 0 with probability at least if is -far from ("soundness"). The query complexity of the tester is if, on input , and oracle access to any , the tester makes at most queries to .
Statistical distance and indistinguishability. The statistical distance between random variables X and is defined as
We say that an algorithm distinguishes between two sequences of random variables and if
which implies that . We say that two sequences of random variables and are indistinguishable if .
4 Lower bound
In this section we prove an lower bound for testing ResStringEq (Theorem 1.2), as well as a stronger lower bound for testers that make non-adaptive queries (Theorem 1.4). As described in Section 2.1, the proofs proceed by an indistinguishability argument. We first present the two distributions that are used for both proofs. We then prove the non-adaptive lower bound in Section 4.2, before turning to the general adaptive case in Section 4.3.
4.1 The two distributions
We construct two random pairs of strings in : a YES pair, denoted , and a NO pair, denoted . We first choose the locations of the star symbols identically in the two distributions, as follows. We begin with the first string in the pair (i.e., in the YES pair and in the NO pair). We partition the string into consecutive blocks of length , for a parameter to be specified later. We draw values , such that each is uniform over , where the value indicates that block in the constructed string will contain non-star symbols. To ensure that exactly positions contain star symbols, we draw the first values independently, and then set the other mirror blocks to the complement value; that is, we set for every . Within each block, the locations of the prescribed number of non-star symbols can be chosen arbitrarily. For concreteness and for convenience of presentation, we place the star symbols at the end of each block. Independently, we repeat this process in the second string (i.e., and ), but using fresh values . We stress that we use the same values and to construct both the YES and NO pairs.
We note that the proof will not use the fact that is drawn in the same way as X, only that and X are independent. We could have chosen arbitrary n/2 positions for the star symbols in the second string, as long as they are independent of X.
For every , we define the rank of in the first string, denoted , as follows. If is not a star position (according to ), we define to be the number of non-star positions up to and including ; that is, (we use here our convention that the star symbols are placed at the end of each block). Otherwise (i.e., is a star position), we define . Similarly, we let denote the rank of position in the second string, defined analogously with respect to .
We now fill the remaining positions in the strings (this is done exactly as described in the overview in Section 2.1). In the YES pair , for every , we draw a uniform bit and place it in the two positions with rank ; that is, we set , where and are the positions such that . In the NO pair , we do the same, except that on the middle third of the ranks we use independent bits in the two strings. That is, let be the middle third of the ranks. Then, for ranks we use a shared uniform bit exactly as before (i.e., we set , where ), while for ranks we draw two independent uniform bits , and use in the first string and in the second (i.e., we set and , where ).
Claim 4.1 (implicit in the proof of [FMS18, Lem. 5.4]; see also [PRR03, Lem. 14]). For any sufficiently small , the probability that is -far from ResStringEq is at least .
Thus, to establish Theorem 1.2 (resp., Theorem 1.4), we show that for any tester that makes queries (resp., non-adaptive queries), the view of the tester on input is indistinguishable from its view on input .
4.2 The non-adaptive case
We begin with the non-adaptive case, proving the lower bound stated in Theorem 1.4. Consider an arbitrary non-adaptive tester for ResStringEq with query complexity . Fix the randomness of the tester, and let and be the sets of queries the tester makes to the first and second strings in the input pair, respectively. Let be the view of the tester on input ; that is, is the restriction of to the respective positions in and . Similarly, let be the view of the tester on input .
To bound the statistical distance between A and we will use the following fact:
Fact 4.2. For any two random variables and , and any event over their joint probability space, if and are identically distributed, then .
We say that positions are matching positions if . We say that are interior matching positions if . Let be the event that there exist and such that are interior matching positions.
Claim 4.3. It holds that and are identically distributed.
Proof: Fix the star positions arbitrarily (by fixing X and ) such that holds (note that the event E is determined by the star positions). We show that under this fixing, the conditional distributions of A and are identical. First, note that we only need to consider the answers in A and to the queries (among Q and ) that are made to non-star positions, because the remaining answers are fixed star symbols. Clearly, the answers to queries whose ranks are outside M are
See Appendix B, which provides a proof of a more general statement.
The notation denotes the complement of the event .
identically distributed in A and . Now, since holds, any query whose rank is in M does not match any queried position in the other string. Thus, in both A and , the answer to any query whose rank is in M is a uniform bit independent of all other query answers. The claim follows.
Thus, to bound , it suffices to bound .
Claim 4.4. If n/b is sufficiently large, it holds that .
To derive the lower bound, we set for a sufficiently small constant . By Claim 4.4, we get , which is if . Thus, unless , the views and are indistinguishable, establishing the lower bound.
It remains to prove Claim 4.4. To do so, we will make use of the following fact:
Fact 4.5 (cf. [MR08]). Let , and let be independent random variables, each distributed uniformly over . Then, for every , it holds that .
Proof of Claim 4.4: We first claim that for every , and every , it holds that . Consider first an index . In this case, assuming , we have that where are independent random variables uniformly distributed over . Therefore, by Fact 4.5 we have:
where we relied on the fact that (because ), as well as the fact that is sufficiently large (by the claim's hypothesis), ensuring that . Now, the case where is symmetric: Recall that . Therefore, we can write , where are independent (and uniformly distributed over ). Thus, similarly to the previous case, we have , as claimed.
Recall that our aim is to bound . Note that if then it must hold that (because there must be at least positions before and at least positions after with the remaining ranks). By the previous paragraph, it follows that for each pair , the probability that is at most , where we rely on the fact that and are independent. Taking a union bound over all pairs , we get that , as desired.
4.3 The adaptive case
We turn to the general adaptive case, proving the lower bound stated in Theorem 1.2. Consider an arbitrary (possibly adaptive) tester with query complexity q. As in the previous section, fix the randomness of the tester.
I.e., larger than some sufficiently large constant.
Recall that we use the expression since under our convention the star positions are placed at the end of each block.
Notation. As a convention, we write as a shorthand for . We next introduce notation for the adaptive queries. For each query , let be the position queried by the tester at the query, where denotes the first query answers. Let and be the sets of positions queried in the first and second strings, respectively, prior to the query, and let and be the sets of positions queried up to and including the query. The view of the tester is the full sequence of answers . Let and denote the full sequences of queries to the first and second strings, respectively, given the full sequence of answers .
Let and be the views of the tester when given and as inputs, respectively. For each , let be the event that there exist and such that are interior matching positions (i.e., ).
The subsequent Claim 4.6 together with Fact 4.7 shows that and . First, similarly to Claim 4.3, we have:
Claim 4.6. For each , it holds that (where and denote the complement events of and , respectively).
The proof is identical to that of Claim 4.3, except that is replaced by , and the query sets are replaced by . Next, we use the following fact, which generalizes Fact 4.2:
Fact 4.7 (see Appendix B). Let and be two discrete random variables supported over a domain , and let and be two events over the probability spaces of and , respectively. If for every it holds that , then and .
Thus, in order to upper bound , it suffices to upper bound .
Lemma 4.8. If we set , for a sufficiently large constant , then .
It follows that unless , the views A and are indistinguishable, which establishes Theorem 1.2. It remains to prove Lemma 4.8.
4.3.1 Proof of Lemma 4.8
We start by introducing a few definitions. For a position in block , define its depth as , namely, the number of blocks from the nearest end of the string up to and including the block containing . For each query , let be the maximum depth of any query position in that matches some query position in . If no such position exists, then define . Furthermore, define . Define the progress of the query as .
To prove Lemma 4.8, we will show the following:
Lemma 4.9. Suppose that , for a sufficiently large constant . Then .
From the above lemma we derive Lemma 4.8 as follows. Note that if event holds (i.e., the tester queries interior matching positions when querying ), then the total progress must satisfy (recall that the progress is measured in blocks). For the above Lemma 4.9 gives . By Markov's inequality, we get
Setting , we get , establishing Lemma 4.8.
Towards proving Lemma 4.9, we establish a few preliminaries. We call a depth unqueried at query if there are no first-string query positions in with depth . We call good at query if the following holds. Order the positions in by increasing depth, breaking ties arbitrarily, and denote the position by . Then, for every , there are at least unqueried depths strictly between and .
Claim 4.10. There exist cutting points such that for every , satisfying the following two properties:
-
For every , if , then is good at query .
-
The total length of the initial parts satisfies .
Proof: Consider the cutting points defined as follows. For each , let be the smallest depth larger than or equal to that is good at query , and set . Clearly, the first property of the claim is satisfied. Call a depth bad at query if it is not good at query . To show that the second property is satisfied, we show that there are fewer than bad depths at query . Since all depths in are bad at query , and a depth that is bad at query remains bad at every subsequent query, this will establish the second property.
For any depth , we call a query a violating query for at query if , and the number of queries in whose depth is in the range is greater than the number of unqueried depths in the range . Thus, is good at query if and only if it has no violating query at query .
To bound the number of bad depths at query , consider the following iterative process. Let be the smallest depth in that is bad at query , and let be the depth of an arbitrary query that is violating for at query . Now continue the same process from : Let be the smallest depth from onwards that is bad at query , and choose a violating query of depth . Repeat until there are no bad depths to choose.
For each , let be the number of query positions among whose depths lie in . By the definition of a violating query, the interval contains fewer than unqueried depths, which implies that . Note that since the intervals are pair-wise disjoint, we have . Since the intervals (across all ) cover all bad depths, and we have , the second property follows.
For every , denote the second part of the progress by . The following lemma bounds the probability that is large.
Lemma 4.11. Suppose that , for a sufficiently large constant . Then, for every query , and every , it holds that .
Before proving Lemma 4.11, we use it to establish Lemma 4.9. We will also make use of the following fact:
Fact 4.12. For every it holds that .
This fact can be proved, e.g., by showing via a simple induction on that for every .
Proof of Lemma 4.9: First, for every we have:
where the second equality is by Lemma 4.11, and the last equality uses Fact 4.12. Now, recall that . By Claim 4.10, it holds that . Therefore,
concluding the proof.
It remains to prove Lemma 4.11.
Proof of Lemma 4.11. Recall that our aim is to show that for every . We will prove the bound by showing it holds even when conditioning on any fixed value for the answers . Let be an arbitrary sequence in the support of . Note that fixing the answers to fixes the previous query sets, as well as the current query position and the string to which it is made. Let us denote , and .
Consider the event under the condition . Let us assume first that given the previous answers , the query is made to the first string. The case where is made to the second string is analogous, and will be revisited at the end of the proof. Notice that since the query is made to the first string, the event implies that , and . That is, the following two events must hold:
-
The current query matches with some previous second-string query in . Let us denote this event by .
-
Denoting , there are no previous first-string queries in that match with some previous second-string query in . Let us denote this event by .
Thus,
To bound the above probability, we will further condition on arbitrary values for the block variables of all blocks outside , as well as all blocks inside that contain a previously queried position in . Furthermore, we will condition on arbitrary values for all second-string block variables in .
To define the foregoing condition more precisely, note that fixing any block variable fixes also the value of its mirror block . Let us denote the set of all blocks whose variables will be fixed by ; that is, consists of all blocks that lie outside as well as all blocks where either block or contains a position in . The variables of the complement set of blocks will remain random. Let be an arbitrary sequence in the support

Figure 1: An illustration of the first string in the input pair. The point labeled is the new query point, and the points marked by a cross (i.e., “×”) represent the previous first-string query points (i.e., the points in ). The deepest previous first-string query point that matches with some previous second-string query is at depth . The range contains all points whose depth is greater than . In particular, any previous query point that lies inside necessarily does not match any of the previous query points in the second string. The shaded blocks are the blocks in ; that is, the blocks whose variables we fix. These include all blocks outside the range , as well as all blocks containing previous query points or their mirror positions. The remaining (i.e., unshaded) blocks are the blocks in . The variables of these blocks remain random.
of , and let be an arbitrary sequence in the support of . We will bound the following probability:
See Figure 1 for an illustration of the objects introduced so far.
Consider the condition . Notice that it imposes two types of constraints. First, it determines for every queried position whether it is a star-position or not. However, this is already determined by the block variables that we fixed (i.e., and ), since these blocks contain all previously queried positions. Second, and more importantly, the condition determines the bit values at every non-star position that was queried. In more detail, recall that for every , the two positions with rank contain a shared uniform bit . Let us denote by (resp., ) the set of positions in (resp., ) whose corresponding answer (according to ) is not a star symbol, and let us denote the values seen in and by and , respectively. Then the condition fixes the values and . Thus, we aim to bound the following probability:
where is a sequence of values determined from alone.
Now, consider the event , which asserts that there are no previous first-string query positions in that match with a previously queried position in the second string. We next show that under the conditions , , no matter how we fix the remaining variables such that the event holds, the joint distribution of remains the same.
Claim 4.13. For every such that the event holds when fixing and , , it holds that the joint distribution of under the fixing , , is the same.
We assume that the fixing of the block variables is compatible with the fixing of the previous answers; otherwise, the corresponding probability is trivially 0.
Proof: At a high level, the issue is that changing the value of can change the ranks , which can affect whether there exist and with matching ranks. This can change the joint distribution of , because at equal ranks there are equal values, whereas values at distinct ranks are independent. However, the value of can affect only the ranks of positions in , whereas the event guarantees that there is no queried position in that matches with a queried position in the second string, meaning that all values seen in are uniform bits, independent of all other answers.
To make the foregoing argument more precise, let us denote , and . Fix , . Now, fixing does not affect or , because the corresponding ranks are already determined by and , respectively. Furthermore, no matter how we fix such that the event holds, we have that is a sequence of uniform bits, independent of (and certainly of ). The claim follows.
We use the above claim to establish:
Claim 4.14. It holds that
Proof: For convenience, throughout this proof we omit the explicit condition , from all probability expressions, with the understanding that this condition implicitly applies in all probability terms. Let us denote . Under the foregoing convention, we will show that
For each , let be the predicate satisfying if and only if the event holds when fixing and , . By Claim 4.13, there exists a value , such that for every that satisfies , it holds that . By Bayes' rule, for every such that , it holds that . . Thus,
On the other hand, we have:
Combining the above two equations, we get
concluding the proof.
We are thus left to bound Eq. (2). At this point, we will use the first property guaranteed by Claim 4.10; that is, that is good at query (we use here the fact that is positive, because ). Let us refer to a depth that is good at query as just “good”, for short. Note that we may assume without loss of generality that is good. Otherwise, let be the smallest integer for which is good (if no such exists, the event is impossible). Since is good, by the minimality of , whenever , we also have . Thus, we may replace by throughout our analysis. Note that depends only on and the fixed previous answers, and that increasing makes the bound only stronger.
Using the fact that is good, we proceed to bound the probabilities in Eq. (2). For the subsequent discussion we work under the fixing , , and we let and denote the ranks and , respectively, after this fixing. We first consider the event (i.e., the event in the numerator in Eq. (2)), which states that matches some second-string query in . Note that since is good, there are at least as many unqueried depths as queried depths in the range , implying there are unqueried depths strictly between and . It follows that there are at least unfixed block variables between the block containing and the nearer end of the string. Therefore, using Fact 4.5 similarly to the proof of Claim 4.4, we have that for every second-string query the probability that is at most . By a union bound over the possible second-string queries we obtain:
Next, consider the event in the denominator in Eq. (2). We will upper bound the probability of the complement event ; namely, that there exists a previous first-string query in that matches with a previous second-string query in . Let us order the previous first-string queries in by their depth in increasing order, breaking ties arbitrarily, and denote the ordered positions by . Since is good, for every there are at least unqueried depths strictly between and . Therefore, the probability that there exists a second-string query such that is at most . Taking a union bound over the queries in , we get:
where the equality uses Fact 4.12 together with , and the last inequality uses the lemma's hypothesis that for a sufficiently large constant . Combining Eq. (4), (3), and (2), we obtain the desired bound.
Recall that until now we have focused on the case where, given the previous answers , the query is a first-string query. Let us now consider the case where is a second-string query. Note that in this case, the event implies that some previous first-string query matches with , and . To handle this case, we repeat the same argument above, with the following modification: First, we begin by taking a union bound over the possible choices of , which will replace the union bound over the possible choices of taken in Eq. (3). We change the definition of to be the event that the chosen matches with . We then repeat the same argument, except that the chosen position takes the role of , and takes the role of .
5 A non-adaptive tester for ResStringEq
In this section, we present a non-adaptive -tester for ResStringEq that makes queries, where is an arbitrarily small constant. More precisely, we show:
Theorem 5.1. For every constant , there exists a non-adaptive tester for ResStringEq with query complexity .
We follow the structure of the overview presented in Section 2.2: We begin with a warm-up (Section 5.1), where in Section 5.1.1 we present a basic tester that is adaptive and uses queries for every constant , and in Section 5.1.3 we show how we can modify the basic tester to be non-adaptive, at the cost of increasing the query complexity to . In Section 5.2 we present the actual (recursive) non-adaptive tester that achieves the desired bound.
5.1 A warm-up
5.1.1 A basic adaptive tester
In this section we present, as an initial warm-up, an adaptive tester for ResStringEq that makes queries. For a string and a position , we define the rank of in as ^{23}
Algorithm 5.2 (a basic -query adaptive tester for ResStringEq). On input , and oracle access to , proceed as follows.
-
Let , and , where is a sufficiently small constant (to be set in the analysis).
-
(Estimate the ranks): For each string , independently: Take independent uniform samples from , and query at the sampled positions. For every and every , let equal 1 if the sampled position, denoted , satisfies that and ; otherwise, let . Define
- (Check that the number of non-star symbols is approximately the same in both strings): If , reject. Otherwise, set .
Note that in contrast to Section 4, here we define the rank using the same formula across all positions, rather than setting the rank of star positions to .
- (Partition into rank-segments): Partition each string into rank-segments, where the rank-segment of is defined as:
We say that is short if , where is a sufficiently small constant (to be set in the analysis); otherwise, we say is long.
- (Check that the residual strings of corresponding rank-segments match up to boundary slack): Repeat the following check times.
(a) Select uniformly at random.
(b) If either or is long, continue to the next iteration.
(c) Otherwise (i.e., both and are short), query s at every position in , and query at every position in .
(d) We say that two strings match up to boundary slack if, after deleting at most symbols from the beginning of one of the two strings, and at most extra symbols from the end of one of them (possibly the same one), the remaining strings are equal.
Check if the residual strings of the restriction of s to and the restriction of to match up to boundary slack . If this check fails, then halt and reject.
If none of the iterations rejected, then accept.
Query complexity. The above tester makes queries for obtaining the estimates (Step 2), and queries for reading the short segments (Step 5c). Setting , we get a tester with query complexity .
5.1.2 Correctness
Successful estimates. We say that all estimates are successful if for each string and all (simultaneously) it holds that .
Claim 5.3. Assuming for a sufficiently large constant , it holds that all estimates are successful with probability at least 0.99.
Proof: Consider any and . Note that are independent Bernoulli random variables, where for each , it holds that (because the sampled positions are uniform in , and exactly positions among satisfy that and ). Hence, by the Chernoff bound, it holds that . By setting for a sufficiently large constant , we have that this probability is at most . Taking a union bound over the two input strings and over all , the claim follows.
Completeness: Consider an input . Observe that if all estimates are successful, the tester accepts. Indeed, since we have , and therefore if the estimates are successful the tester does not reject at Step 3. Furthermore, if the estimates are successful, then for every the true ranks of the first positions in and both lie in the range . Hence, these two ranks differ by at most . By a similar argument the true ranks of the last positions in and also differ by at most . Since , it follows that every pair of corresponding rank-segments passes the check for matching up to boundary slack (Step 5d), and the tester accepts. Completeness follows.
Soundness: For , we call the pair of corresponding rank-segments bad if both segments are short, and the residual strings obtained after restricting and to these segments do not match up to boundary slack .
Claim 5.4. Assume the input pair is -far from ResStringEq. If the estimates are successful and Algorithm 5.2 has not rejected at Step 3, then at least of the corresponding rank-segments are bad.
From the above claim it follows that each iteration in Step 5 rejects with probability at least (because the total number of corresponding rank-segments is ). Hence, w.h.p. at least one of the iterations rejects, and soundness follows.
Proof of Claim 5.4: Suppose, towards a contradiction, that fewer than corresponding pairs are bad, where is a sufficiently small constant. We show that we can modify in at most positions so that it becomes a pair in ResStringEq, contradicting the claim's hypothesis.
We modify as follows. For every pair of corresponding rank-segments that is not bad and in which both segments are short, the residual strings in the two segments match up to boundary slack . We keep the non-star symbols in the matching parts of all such pairs, and replace every other non-star symbol in s and by a star. We bound the number of modified positions as follows:
-
First consider the pairs that are not bad and in which both segments are short. In each such pair, we modify at most non-star symbols at the beginning of one of the segments and at most non-star symbols at the end of one of the segments. Hence, we modify at most symbols. Since there are at most corresponding rank-segments, the total number of modifications in these pairs is at most .
-
Consider pairs in which at least one segment is long. Recall that the length of each long rank-segment is greater than . Hence, each string can have at most long rank-segments. Since the estimates are successful, every rank-segment has at most non-star symbols. Thus, replacing all non-star symbols in pairs in which at least one rank-segment is long contributes at most modifications.
-
Next, consider the bad pairs. By our assumption, there are fewer than bad pairs. Since each pair contains at most non-star symbols, replacing all non-star symbols in the bad pairs contributes at most modifications.
-
Finally, after the last corresponding rank-segment, one string may have an additional suffix. Since Step 3 did not reject (by the claim’s hypothesis) and the estimates are successful, this suffix has at most non-star symbols.
Taking , and sufficiently small, the total number of modifications is at most , establishing the claim.
5.1.3 Making the basic tester non-adaptive
In this section we show how we can modify the basic tester from the previous section to be non-adaptive, at the cost of increasing the query complexity to . Note that the queries made in Step 5 of Algorithm 5.2 are inherently adaptive, because the segments queried in this step are defined based on the estimates obtained in Step 2. To get a non-adaptive tester, we modify Algorithm 5.2 so that it pre-samples sufficiently many fixed blocks from both strings, such that w.h.p. both rank-segments in some bad pair are contained in sampled blocks.
Definition 5.5 (blocks). For a string , the covering of by blocks of length and spacing is the set of all intervals of length starting at positions , where the last intervals are truncated at . The intervals are referred to as blocks.
Note that any interval of positions in whose length is at most is necessarily contained in some block. In the following, we use and , which ensures that every short rank-segment (as defined in Step 4 of Algorithm 5.2) is contained in a block.
Algorithm 5.6 (a basic -query non-adaptive tester for ResStringEq). On input , , and oracle access to , proceed as follows.
-
Let , and , where and are the same constants used in Steps 1 and 4 of Algorithm 5.2, respectively.
-
Query-Phase: For each string , independently:
(a) (Prepare estimation queries): Take independent uniform samples from , and query at the sampled positions.
(b) (Select & query blocks): Consider the covering of by blocks of length and spacing (see Definition 5.5). Sample each block in the covering independently with probability , and query each selected block in its entirety.
- Decision-Phase:
(a) (Partition into rank-segments) Using the estimation queries (made in Step 2a), perform Steps 2–4 of Algorithm 5.2.
(b) (Check if the residual strings of corresponding rank-segments match up to boundary slack): Go over all pairs of corresponding rank-segments for . For each such pair, check if there exists a pair of blocks and that were queried in and , respectively (in Step 2b), such that and . If so, check if the residual strings of the restriction of to and the restriction of to match up to boundary slack (as in Step 5d of Algorithm 5.2). If the check fails, then halt and reject.
(c) If no check performed in the last step rejected, then accept.
Query complexity. The above tester makes queries in expectation: As before, the tester makes queries for obtaining the estimates (in Step 2a). We next bound the number of queries made in Step 2b. Notice that there are blocks in total. Since each block is sampled with probability , the expected number of sampled blocks is . Each sampled block has length , therefore the expected number of queries made in Step 2b is . Thus, the expected query complexity of the tester is . Balancing the two terms, we set , giving us expected query complexity . (As mentioned before, to get a worst-case query bound, alter the construction to halt and accept if the number of queries exceeds its expectation by a sufficiently large constant factor.)
For convenience, the query complexity of this construction is bounded only in expectation. To get a worst-case query bound, alter the construction to halt and accept whenever the number of queries exceeds its expectation by a sufficiently large constant factor.
Correctness. Completeness follows exactly as in Section 5.1.2. Furthermore, note that Claim 5.4 still holds as well. That is, for every input that is -far from ResStringEq, if the estimates are successful and the tester did not reject at Step 3a (i.e., when checking that the number of non-star symbols is approximately the same in both strings), then there are at least bad pairs of corresponding rank-segments. It remains to show that, with high probability, both rank-segments in some bad pair are contained in blocks sampled in Step 2b.
Claim 5.7. Assume that the input pair is -far from ResStringEq, that the estimates are successful, and that the tester has not rejected at Step 3a. Then, with probability at least 0.99, there exists a bad pair of corresponding rank-segments such that each rank-segment in the pair is contained in a block sampled in Step 2b.
Proof: Let us assign to each short rank-segment a block such that . Recall that each segment in a bad pair is by definition short, so it has an assigned block. Notice that each block can be assigned to at most rank-segments, because each rank-segment is of length at least whereas each block is of length at most . Thus, since there are at least bad pairs of rank-segments, there must be a set of at least bad pairs such that the assigned blocks of different pairs in are all distinct.
For each bad pair in , consider the event that the assigned blocks of both rank-segments in the pair are sampled. For a single bad pair, the probability of this event is . Since the assigned blocks of the pairs in are distinct, these events are mutually independent for different pairs in . Hence, the probability that none of these events occurs among the pairs in is at most:
Setting for a sufficiently large constant , the claim follows.
5.2 The actual non-adaptive tester
We extend the non-adaptive tester from the preceding section into a recursive tester that achieves the desired query complexity. The tester we construct will actually have a stronger acceptance guarantee: It accepts inputs even if their residual strings match up to boundary slack (while rejecting inputs that are -far from having their residual strings match). Recall that matching up to boundary slack is defined as follows:
Definition 5.8 (match up to boundary slack). We say that two strings match up to boundary slack if, after deleting at most symbols from the beginning of one of the two strings, and at most extra symbols from the end of one of them (possibly the same one), the remaining strings are equal.
The tester is composed of two recursive procedures: a Query procedure, which is run separately on each input string and makes all queries, and a Decision procedure, which receives the outputs of the Query procedure and decides whether to accept or reject the input pair. The Decision procedure also receives endpoint parameters and specifying the first and last positions of two substrings and that are currently being compared; in the first call these substrings are simply the full input strings, whereas in recursive calls they will be rank-segments inside sampled blocks. Both the Query and Decision procedures receive a round parameter specifying the remaining number of recursion rounds. The Query procedure also receives a failure parameter specifying the allowed failure probability.
Algorithm 5.9 (an -query non-adaptive tester for ResStringEq). On inputs , and query access to , proceed as follows:
-
Let , and .
-
For each input string , run the Query procedure (Algorithm 5.10) with inputs and query access to .
-
(Check that the number of non-star symbols is approximately the same in both strings): Using the estimation queries in the output of the Query procedure, check that , where and are as defined in Step 2 of Algorithm 5.2, and is as defined in Algorithm 5.10. If the check fails, then halt and reject.
-
Run the Decision procedure (Algorithm 5.11) with inputs , the two outputs of the Query procedure, and endpoint parameters . Output the Decision procedure's decision.
Algorithm 5.10 (the Query procedure). On inputs , , , and query access to a string , proceed as follows:
• If : Query the entire input string and output the answers.
• Otherwise:
- (Set parameters):
– Let be sufficiently small constants to be set in the analysis.
– Let be a parameter to be set in the analysis (see Section 5.2.1).
– Let , and .
– Let and .
-
(Prepare estimation queries): Take independent uniform samples from , and query at the sampled positions.
-
(Select blocks and continue recursively):
(a) Consider the covering of x by blocks of length b and spacing b/2 (see Definition 5.5).
Sample each block in the covering independently with probability .
(b) For each selected block, recursively run the Query procedure on inputs , and query access to the restriction of x to the selected block.
Output the query positions and answers (from Step 2), the selected blocks (from Step 3), and the output of all recursive calls.
The Decision procedure has the following specification. It receives the outputs obtained by running the Query procedure (Algorithm 5.10) on two strings , with parameters . It also receives the values of and used in these two executions. In addition, it receives endpoints and specifying the first and last positions of a substring in and a substring in , respectively. Denoting , the substrings and are promised to satisfy , as well as , where and are as defined in Algorithm 5.10. The Decision procedure should satisfy the following guarantees, where the probability is over the randomness of the Query procedure.
-
It accepts w.p. at least if and match up to boundary slack (see Definition 5.8).
-
It rejects w.p. at least if one must modify more than positions in the pair so that their residual strings match.
In the following, positions in the output of the Query procedure are indexed relative to u and , whereas the rank-segments are indexed relative to s and . We translate between these two ways of indexing positions when needed.
Algorithm 5.11 (the Decision procedure). On inputs , , , the outputs of the Query procedure, and the endpoints and specifying the positions of the substrings and to be compared, proceed as follows.
For each , let , and let .
- If : The outputs of the Query procedure contain the full strings and . Directly check if the residual strings of and match up to boundary slack , and accept if and only if this check passes.
• Otherwise:
-
(Set parameters): Set L, , , exactly as in Step 1 of the Query procedure (Algorithm 5.10).
-
(Estimate the ranks): For each string : For each , let denote the position of the query in the output of the Query procedure corresponding to . For each and , let equal 1 if and ; otherwise, let . Define:
- (Define rank-segments for every offset): For each and every offset , define the rank-segment of with offset as:
- (Search for a successful offset): Consider each of the two possible orderings of the strings . For each ordering, go over all offsets (the offset is applied to the first string , whereas the second string is left with offset 0). For each such offset , proceed as follows:
(a) Let .
(b) (Recursively check corresponding rank-segments): Go over all pairs of corresponding rank-segments for . For each such pair, check if there exists a pair of selected blocks and in the respective outputs of the Query procedure, such that and , where and are represented with respect to their positions in and . If so, recursively invoke the Decision procedure on inputs , the outputs of the Query procedure in the recursive calls with and and the positions of and inside and respectively.
(c) If any recursive call rejects, then h fails; continue to the next offset. Otherwise (i.e., all recursive calls accepted), h is successful; halt and accept.
If every offset h failed for both orderings of the strings, then reject.
5.2.1 Query complexity
Let be the expected number of queries made by the Query procedure (Algorithm 5.10). Recall that there are blocks. Therefore, the expected number of blocks selected in Step 3a is . Hence,
where . Inductively, we have:
where is determined as follows. We choose so as to balance the terms and , which gives . With this choice, . Together with , this yields .
Thus, for every constant , we may set , , and and get expected query complexity:
Since the above bound holds for every constant , we may apply it with in place of and use , giving us query complexity .
5.2.2 Correctness
Successful estimates. We say that all estimates are successful if for each and all (simultaneously) it holds that . Observe that by a straightforward extension of Claim 5.3, we have:
Claim 5.12. If in Step 2 of the Query procedure (Algorithm 5.10), we set for a sufficiently large constant , then all estimates are successful with probability at least .
Completeness: Consider any pair of strings such that and match up to boundary slack , where . We first show that the Decision procedure accepts such a pair with probability at least . Since (by Claim 5.12) all estimates are successful with probability at least , we assume all estimates are successful and show that under this assumption the Decision procedure accepts with probability at least .
That is, if B occupies positions in the string on which the corresponding Query procedure was run, then, for the purpose of this containment check, we view B as the set , and similarly for .
Since and match up to boundary slack , there exists an ordering of the strings and an offset such that, after deleting the first symbols from , the two residual strings agree until one of them ends. This means that, assuming the estimates are successful, in the iteration of Step 4 that considers this ordering and offset , the residual strings in each pair of corresponding rank-segments match up to boundary slack (where we take to be sufficiently small, and rely on the fact that ). By induction, each recursive call rejects with probability at most . By a union bound over the at most corresponding rank-segments, the Decision procedure rejects with probability at most , as desired.
Now consider the actual tester (Algorithm 5.9). Since and match up to boundary slack , if the estimates are successful the tester will not reject at Step 3 (when checking that ). By the previous paragraph, it follows that the tester accepts with probability at least , as desired.
Soundness: We first show soundness of the Decision procedure (Algorithm 5.11), and derive the soundness of the tester (Algorithm 5.9) at the end of the section. Throughout the following soundness analysis of the Decision procedure, fix a pair of strings and let . Assume that one must modify more than symbols in to make the two residual strings agree. We also assume that and satisfy both promises required by the Decision procedure; that is, and .
We say that a rank-segment is short if ; otherwise, we say is long. For each ordering and each offset considered by Step 4, we call a pair of corresponding rank-segments bad if (1) both rank-segments are short; and (2) one must modify more than non-star positions in the restrictions of and to these rank-segments in order to make the two residual strings agree.
Claim 5.13. Assume the estimates are successful. Then, for each ordering of the strings and every offset considered by Step 4 of the Decision procedure, at least of the corresponding rank-segments , for , are bad.
Proof: Suppose, towards a contradiction, that for some ordering of the strings and some offset , fewer than corresponding pairs are bad, where is a sufficiently small constant. We show that we can modify at most non-star symbols in so that the two residual strings agree, contradicting the hypothesis.
We modify as follows. For each pair of corresponding rank-segments that is not bad and in which both rank-segments in the pair are short, we are guaranteed that the residual strings in the two segments can be made equal by modifying at most non-star positions. We make these modifications for all such pairs, and replace every non-star symbol outside these pairs by a star. We bound the number of modified positions by considering the following cases. (The following generalizes the argument in Claim 5.4, where only the first and last cases are changed.)
-
First, for each pair of corresponding rank-segments that is not bad and both rank-segments in the pair are short, we modify at most positions, where . Summing over all , we get that the total number of modifications is at most .
-
Consider pairs in which at least one rank-segment is long. Recall that the length of each long rank-segment is greater than . Hence, each string can have at most long rank-segments. Since the estimates are successful, every rank-segment has at most non-star symbols. Thus, replacing all non-star symbols in pairs in which at least one rank-segment is long contributes at most modifications.
-
Next, consider the bad pairs. By our assumption, there are fewer than bad pairs. Since each pair contains at most non-star symbols, replacing all non-star symbols in the bad pairs contributes at most modifications.
-
It remains to count the non-star symbols that lie before or after the range covered by corresponding rank-segments. The initial offset in the first residual string contributes at most non-star symbols. Furthermore, one of the two residual strings may have a suffix that lies after the range covered by the corresponding rank-segments. Recall that we are promised that . Together with the offset and the estimation errors, the suffix can be of length at most . Altogether, there are at most non-star positions outside the range of corresponding rank-segments.
Overall, the number of modified symbols is at most . Taking , and sufficiently small, this number is at most , as desired.
Next, similarly to Claim 5.7, we have:
Claim 5.14. Assume the estimates are successful. Then, for every ordering of the strings and every offset considered by Step 4 of the Decision procedure, with probability at least , there exists a bad pair of corresponding rank-segments such that each rank-segment in the pair is contained in a sampled block.
Proof: Recall that we are promised that . By Claim 5.13, in every iteration of Step 4 there are bad pairs of rank-segments. As in Claim 5.7, it follows that there is a set of at least bad pairs of rank-segments that are contained in blocks that are distinct across different pairs (because each block can contain at most rank-segments).
Recall that each block is sampled with probability , where is a sufficiently large constant. Thus, similarly to the proof of Claim 5.7, the probability that in a fixed iteration of Step 4 there is no bad pair for which each rank-segment is contained in a sampled block is at most:
as desired.
Concluding the soundness of the Decision procedure. By Claim 5.12, the probability that the estimates are unsuccessful is at most . Thus, we assume the estimates are successful and show that, under this assumption, the Decision procedure accepts with probability at most . Consider any iteration of Step 4, where the ordering of the strings is and the offset is h. The iteration can falsely accept either because there was no bad pair for which both rank-segments were contained in a sampled block, or because a recursive call on a bad pair falsely accepted. By Claim 5.14, the probability of the former event is at most . As for the latter event, consider any bad pair and let and be the restriction of to and the restriction of to , respectively. Note that since the estimates are successful, it holds that the number of non-star symbols in both and is , which implies that the promises needed for the Decision procedure hold for the pair : Denoting , it holds that , because whereas and . Furthermore, we have (where we take to be sufficiently small, and use ). Thus, both promises are satisfied. Therefore, by induction, the probability that a recursive call on falsely accepts is at most . It follows that each iteration falsely accepts with probability at most . By a union bound over the at most iterations, the probability that the Decision procedure falsely accepts is at most , as desired.
Concluding the soundness of the tester. Consider any pair that is -far from ResStringEq. Assume that the estimates are successful and that the tester (i.e., Algorithm 5.9) has not rejected at Step 3 (where it checks that ). Then, when the tester invokes the Decision procedure, both the required promises on the inputs to the procedure are satisfied. Indeed, in the initial invocation we have , and hence clearly (assuming is sufficiently small). Furthermore, the check at Step 3, together with the successful estimates, implies that . By the previous paragraph, it follows that the tester rejects with probability at least , as desired.
5.3 On the adaptive tester for ResStringEq
By composing the basic -query adaptive tester (Algorithm 5.2) with the recursive -query non-adaptive tester shown above (Algorithm 5.9), we obtain an -query adaptive tester for ResStringEq, analogous to the tester of [FMS18] for the Dyck languages. Recall that Algorithm 5.9 accepts inputs even if they match up to a boundary slack. Hence, we can replace Steps 5c and 5d of Algorithm 5.2 with a call to Algorithm 5.9. The recursive call uses the proximity parameter defined in Algorithm 5.10, and the tester will use the definition of in Algorithm 5.10. The resulting tester uses queries for obtaining the estimates, and queries for the boundary-slack matching checks. Setting gives us query complexity . The correctness analysis of this tester follows straightforwardly from the correctness analysis in Section 5.2.2. Thus, we obtain:
Theorem 5.15. For any constant , there exists an (adaptive) tester for ResStringEq with query complexity .
As discussed in Section 1.1, compared with the tester obtained by combining the reduction of [FMS18] with their tester for Dyck₂, the tester in Theorem 5.15 improves the dependence of the query complexity on from to .
6 Extending the non-adaptive tester to the Dyck languages
In this section, we extend the non-adaptive tester presented for ResStringEq in the previous section to the Dyck languages. Specifically, we establish:
Theorem 6.1. For every , and for any (arbitrarily small) constant , there exists a non-adaptive tester for with query complexity .
The tester closely follows the construction of [FMS18], except that we modify their construction to be non-adaptive using an approach very similar to the one we used for the non-adaptive ResStringEq tester. We rely on several notions developed in [PRR03] and [FMS18], which we briefly survey in the following subsection.
6.1 Preliminaries
Notation. Throughout, we let denote an alphabet of parentheses of types. For a string , we let and denote the suffixes of starting at positions and , respectively. Similarly, let and denote the prefixes of ending at positions and , respectively.
A reduction to Dyck -consistency. We say that a string is Dyck -consistent if it is a consecutive substring of some string in Dyck . We define the property Dyck -consistency to be the set of all Dyck -consistent strings. The following reduction was implicit in the work of [PRR03], and was established explicitly in [FMS18, Lem. 2.4].
Lemma 6.2. If there exists an -tester for Dyck -consistency with query complexity , then there exists a -tester for Dyck with query complexity . Furthermore, if the Dyck -consistency tester is non-adaptive, then the resulting Dyck tester is non-adaptive as well.
The furthermore-claim (in the above lemma) holds since the tester for Dyck simply invokes the tester for Dyck -consistency as well as the tester for Dyck of [AKNS01], and the latter tester is non-adaptive. We will thus focus on showing a non-adaptive tester for Dyck -consistency.
Excess parentheses [PRR03, Def. 6]. Intuitively, the excess parentheses of a substring over are the parentheses in that must match with parentheses outside . Formally, let be the alphabet over one parenthesis type, where denotes the opening parenthesis and denotes the closing parenthesis. Let be a string over , and let be the string obtained from by “removing the types of the parentheses”; that is, by mapping every opening parenthesis to and every closing parenthesis to . Let and be the smallest integers such that . Then is called the excess number of closing parentheses in , and is called the excess number of opening parentheses in . We call and the excess numbers of . We denote and . Let and denote the number of opening and closing parentheses in , respectively. The excess numbers can be computed as follows.
Claim 6.3. With uniform queries to a string , one can obtain estimates of the excess numbers of every consecutive substring of (simultaneously) up to an additive deviation of , with success probability .
Proof: As in Claim 5.3 and 5.12, uniform queries suffice to estimate and for every prefix of up to an additive deviation of , where all the estimates are successful simultaneously with probability at least . For every consecutive substring of , subtracting the estimates for the prefix ending immediately before and the prefix ending at the last position of gives estimates of and up to an additive deviation of . Using these estimates as substitutes in Eq. (5), we get an estimate of the excess numbers of any consecutive substring of , up to deviation .
The matching graph [PRR03, Sec. 3.4]. For each string such that , there exists a unique perfect matching between opening and closing parentheses in , such that each opening parenthesis is matched to a closing parenthesis, and such that the matching is “non-crossing”. By non-crossing we mean that if is matched to , and to where , and , then either or . We denote this unique perfect matching by . This definition is also extended to strings for which as follows: Let . We let be the restriction of to pairs of parentheses that are both in .
We define the matching graph of as follows. Let be a parameter we will specify later. We partition into consecutive blocks of length . The vertices of the matching graph are the blocks of . Two blocks are connected by an edge if and only if the matching matches between excess opening parentheses in block and excess closing parentheses in block . The weight of the edge is the number of excess opening parentheses in block that are matched by to excess closing parentheses in block . By the non-crossing property of the matching , it follows that:
Claim 6.4 ([PRR03, Claim 9]). For every string x over , the matching graph of x is planar, and therefore has at most 3n/b edges.
The next claim shows that we can obtain estimates of the weights for every pair of blocks in the matching graph.
Claim 6.5 ([PRR03, Claim 10]). Given the (exact) excess numbers of all consecutive substrings of a string , one can compute the weight of every pair of blocks in the matching graph of . Furthermore, given estimates of the excess numbers of all consecutive substrings of to within additive deviation , one can compute estimates for every , such that .
Loosely speaking, the next claim states that for each we can estimate the interval in block that contains the excess opening parentheses that should match with excess closing parentheses in block and vice versa. A similar claim is implicit in [PRR03] and [FMS18]; however, for convenience reasons, here we define these estimated intervals slightly differently. Therefore, we include a proof of the claim below.
Claim 6.6. Let , and partition into consecutive blocks of length . For every pair of blocks , let be the smallest interval containing all excess opening parentheses in that are matched by to excess closing parentheses in . Likewise, let be the smallest interval containing all excess closing parentheses in that are matched by to excess opening parentheses in . We refer to and as the matching intervals of blocks . Then, given the (exact) excess numbers of all consecutive substrings of , one can compute the matching intervals of any pair of blocks . Furthermore, suppose that we are given estimates of the excess numbers of all consecutive substrings of to within additive deviation . Then, for every pair of blocks , it is possible to compute approximate matching intervals and such that:
(1) has at most excess opening parentheses outside , and likewise has at most excess closing parentheses outside .
(2) has at most excess opening parentheses that are not excess in , and likewise has at most excess closing parentheses that are not excess in .
Note that the excess opening parentheses of that are not excess in must form a suffix of the excess opening parentheses of . Similarly, the excess closing parentheses of that are not excess in must form a prefix of the excess closing parentheses of .
Proof: Consider any pair of blocks . Let and denote the restrictions of to and , respectively, and let denote the restriction of to (i.e., the interval strictly between blocks and ). Denoting , observe that, by the non-crossing property of the matching , it holds that is the leftmost position in block such that , and is the rightmost position in block such that . Symmetrically, denoting , it holds that is the rightmost position in block such that , and is the leftmost position in block such that .
We next define ; the case of is symmetric. For each substring of , let and be the estimated excess numbers of (as guaranteed by the claim's hypothesis). Let be the estimated weight of the pair as guaranteed by Claim 6.5. If , we define and to be the empty intervals. Since , in this case , and the claim immediately follows. We thus assume henceforth that , and therefore that . Let us denote . We take to be the leftmost position in block such that and , and we take to be the rightmost position such that .
We need to show that , that there are at most excess opening parentheses in that lie outside , and that there are at most excess opening parentheses of that are not excess in . Consider first the right endpoints and . Notice that since satisfies , it must satisfy . Furthermore, notice that must satisfy , and therefore . Thus, by the minimality of it follows that . On the other hand, notice that there can be at most excess opening parentheses between and : Since satisfies , it follows that . Finally, notice that any excess opening parenthesis of that is not excess in must match with an excess closing parenthesis in , and by definition of we have , which implies . Hence, there can be at most excess opening parentheses of that are not excess in .
Similarly, consider the left endpoints and . Since satisfies , it must satisfy . Thus by the maximality of it follows that . On the other hand, there can be at most excess opening parentheses between and : Since satisfies , it follows that . Lastly, notice that : Recall that , whereas we showed that there are at most excess parentheses between and and at most excess parentheses between and .
Finally, observe that if is -consistent, then for every pair of blocks , the excess opening parentheses in and the excess closing parentheses in “match up to boundary slack ”, in the following sense:
Definition 6.7 (match of excess parentheses up to boundary slack). Let and be two non-overlapping substrings of a string , where appears before in . Let denote the subsequence of excess opening parentheses in , and let denote the subsequence of excess closing parentheses in . We say that and match up to boundary slack if, after deleting at most parentheses from the end of , at most parentheses from the beginning of , and at most parentheses either from the beginning of or from the end of (but not both), the following holds: There exists a perfect non-crossing matching between the remaining parentheses in and the remaining parentheses in , such that for every matched pair of parentheses, the two parentheses have the same type, and the number of parentheses in x between them is even.
To compare the above definition with Definition 5.8, consider in reverse order. Under this ordering, the difference is that here we allow deleting up to parentheses from the beginning of both sequences, rather than only one of them.
6.2 The excess parentheses matching procedure
Before presenting the non-adaptive tester for Dyck -consistency, we describe a (non-adaptive) procedure for comparing the excess opening parentheses of one substring s with the excess closing parentheses of another substring , and deciding (approximately) whether they match up to boundary slack (per Definition 6.7). This procedure, which we call the excess parentheses matching procedure, is a modified version of the ResStringEq Decision procedure (i.e., Algorithm 5.11), and it gets the outputs of the same Query procedure that was used in the ResStringEq tester (i.e., Algorithm 5.10).
At a high level, the procedure proceeds analogously to the ResStringEq Decision procedure. It estimates the excess numbers (as guaranteed by Claim 6.3), and uses these estimates to rank the positions in s from right to left according to the excess opening parentheses, and the positions in from left to right according to the excess closing parentheses. It then partitions the strings into segments that each contain approximately L excess parentheses, and recursively compares corresponding segments.
However, here we need to choose the segment boundaries more carefully. Note that if we choose the boundaries arbitrarily, then a segment of s may have opening parentheses that are excess in the segment but not excess in s, and symmetrically for excess closing parentheses in segments of . The recursive call would then include these parentheses in the comparison, even though we want to compare only the excess parentheses of s and . We therefore choose the boundaries more carefully so that each segment can have at most excess parentheses that are not excess in the original string.
Finally, in contrast to the definition of boundary slack that we used in the ResStringEq Decision procedure (i.e., Definition 5.8), here the definition allows deleting at most parentheses from the beginning of both sequences before comparing them (where the excess opening parentheses are read from right to left). To account for this, we skip the first excess parentheses in one string (according to the estimates), and iterate over all offsets between 0 and in the other string.
Algorithm 6.8 (excess parentheses matching procedure). On input , , , the outputs of the Query procedure on two strings of length , and the endpoints of two substrings and of a string such that appears before in , proceed as follows: Let .
- If : The outputs of the Query procedure contain the full strings and . Directly check if the excess opening parentheses of and the excess closing parentheses of match up to boundary slack (see Definition 6.7), and accept if and only if this check passes.
• Otherwise:
-
(Set parameters): Set L, , , exactly as in Step 1 of the Query procedure (Algorithm 5.10).
-
(Estimate the excess numbers): For every substring y of either s or , use the estimation queries in the outputs of the Query procedure to compute estimates and of the numbers of excess opening and closing parentheses in y, respectively, as guaranteed by Claim 6.3.
-
(Define excess-parentheses segments for every offset): For every h, define the excess-parentheses segments of s and with offset h, as follows.
– For s, choose endpoints along s, from right to left, where the endpoint satisfies:
and define the segment of s as .
– Symmetrically, for , choose endpoints along , from left to right, where the endpoint satisfies:
and define the segment of as .
- (Search for a successful offset): Fix , and go over all offsets . For each such do as follows:
(a) Let .
(b) (Recursively check corresponding excess-parentheses segments): Go over all pairs of corresponding segments for . For each such pair, check if there exists a pair of selected blocks B and in the respective outputs of the Query procedure, such that and , where B and are represented with respect to their positions in s and . If so, recursively invoke the excess parentheses matching procedure on inputs , the outputs of the Query procedure in the recursive calls with B and , and the positions of and inside the global string x.
(c) If any recursive call rejects, then h fails; continue to the next offset. Otherwise (i.e., all recursive calls accepted), h is successful; halt and accept.
If every offset h failed then reject.
The following claim states the guarantees of the excess parentheses matching procedure, which are analogous to the guarantees of the ResStringEq Decision procedure (Algorithm 5.11). The proof is analogous to the analysis in Section 5.2.2 and [FMS18, Sec. 4.2], and we omit the details.
Claim 6.9 (completeness and soundness of the excess parentheses matching procedure). Let be a string over , and let and be two substrings of . Denote . Suppose that Algorithm 6.8 is invoked with the outputs obtained by running the Query procedure (Algorithm 5.10) on two substrings of of length containing and , respectively, where both invocations use proximity parameter and failure parameter . Furthermore, suppose that and are promised to satisfy , and that . Then Algorithm 6.8 satisfies the following guarantees (where the probability is over the randomness of the Query procedure).
- It accepts w.p. at least if the excess opening parentheses of s and the excess closing parentheses of match up to boundary slack (see Definition 6.7).
Note that if the estimates are successful then such an endpoint can always be found: the position whose exact excess numbers satisfy and will satisfy these constraints (but other positions may satisfy the constraints as well).
- If it accepts w.p. greater than , then there exists a non-crossing matching between the excess opening parentheses of s and the excess closing parentheses of such that (a) for every matched pair of parentheses, the two parentheses have the same type, and the number of parentheses between them in x is even; (b) at most of the excess parentheses in s and are unmatched.
6.3 The tester
We finally present the non-adaptive tester for Dyck -consistency (recall that Lemma 6.2 establishes a reduction from testing Dyck to testing Dyck -consistency). The tester that we will present uses recursive calls. Therefore, aside from the usual inputs (i.e., and query access to ), it receives two additional parameters: (1) a round parameter indicating the remaining number of recursion rounds, initialized to 3; and (2) a failure parameter indicating the allowed failure probability, initialized to 1/3.
Algorithm 6.10 (an -query non-adaptive tester for Dyck -consistency). On input , and query access to , as well as parameters (initialized to 3) and (initialized to 1/3), proceed as follows:
• If : Query the entire input string , and accept if and only if is Dyck -consistent.
• Otherwise:
-
Let , , , , and , where are sufficiently small constants.
-
Query-Phase:
(a) Take independent uniform samples from , and query x at the sampled positions.
(b) Partition x into consecutive blocks of length b. Sample each block independently with probability .
(c) For each selected block B, run the Query procedure (Algorithm 5.10) with query access to the restriction of x to block B, proximity parameter , failure parameter , and round parameter .
- Decision-Phase:
(a) Using the estimation queries made in Step 2a, compute the estimates of the excess numbers of every consecutive substring of x, with additive deviation at most and failure probability at most , as guaranteed by Claim 6.3.
(b) For each pair of blocks , compute the approximate matching intervals and as guaranteed by Claim 6.6.
(c) For each pair of blocks such that , if both blocks and were selected in Step 2b, then run the excess parentheses matching procedure (Algorithm 6.8) with the same parameters used for the Query procedure in Step 2c, the outputs of the Query procedure when run on the restrictions of to blocks and , as well as the positions of the intervals and inside . If any call rejects, then halt and reject.
(d) Select uniformly random blocks. For each selected block B, recursively run the Dyck -consistency tester (Algorithm 6.10) on the restriction of x to B, using proximity parameter , failure parameter and round parameter r - 1. Accept if and only if all recursive calls accept.
6.3.1 Query complexity
Let us bound the query complexity of Algorithm 6.10. We first bound the expected number of queries made in a single recursion round. Notice that , and therefore in Step 2a Algorithm 6.10 makes queries. In Step 2b the number of blocks sampled in expectation is . Since each block is of length , the expected number of queries made in Step 2c is , where is the expected query complexity of the Query procedure (Algorithm 5.10) invoked in Step 2c. As established in Section 5.2.1, . Since we set , we get that the expected number of queries made in a single recursion round is at most .
Now, in each recursion round, Algorithm 6.10 makes recursive calls. In the recursive calls, the input length shrinks from to . After 3 recursion rounds, the input length becomes , and the input is read entirely. Note that throughout all 3 recursion rounds, the proximity parameter remains (where is the initial proximity parameter), and the failure parameter remains . Thus, altogether, the expected query complexity of Algorithm 6.10 is . Since this bound holds for every constant , we may apply it with in place of and use , giving us query complexity .
6.3.2 Correctness
The correctness analysis of Algorithm 6.10 is very similar to that in [FMS18]. We will detail only the places where some modifications to the analysis in [FMS18] are needed, and indicate where the analysis proceeds exactly as in [FMS18].
The completeness of Algorithm 6.10 follows straightforwardly from the completeness of the excess parentheses matching procedure, similarly to [FMS18]. We therefore focus on the soundness analysis. Let , and consider a partitioning of into consecutive blocks of length . As in [FMS18], we say that a parenthesis in is locally excess if it is excess in its block but is not excess in . Equivalently, the set of locally excess parentheses consists of the excess parentheses that lie in the matching intervals and , for all (see Claim 6.6). We next prove the following claim, which is analogous to [FMS18, Lem. 3.6].
Claim 6.11. Suppose that Algorithm 6.10 is invoked on a string with proximity parameter and failure parameter . If the algorithm accepts with probability greater than , then there exists a non-crossing matching on the locally excess parentheses of such that for every matched pair of parentheses, the two parentheses have the same type, and the number of parentheses in between them is even; at most of the locally excess parentheses of are unmatched.
From the above claim, the soundness of Algorithm 6.10 follows by the same argument as in [FMS18, Sec. 3.2].
Proof of Claim 6.11: Since the estimates of the excess numbers computed in Step 3a of Algorithm 6.10 are successful with probability at least , and is accepted with probability greater than , there exists a fixing of the estimates such that the estimates are successful and, under this fixing, is accepted with probability greater than . Fix such estimates, and consider the resulting approximate matching intervals , for every .
We call a pair of blocks good if there exists a non-crossing matching between the excess opening parentheses in the restriction of to and the excess closing parentheses in the restriction of to such that (a) for every matched pair of parentheses, the two parentheses have the same type, and the number of parentheses in between them is even; and (b) at most of these excess parentheses are unmatched. Otherwise, we call the pair bad.
Note that in every bad pair both approximate matching intervals contain at least excess parentheses: Since the estimates are successful, the numbers of excess parentheses in the two intervals can differ by at most (by the guarantees of Claim 6.6). Thus, both intervals must contain at least parentheses or the pair would be trivially good.
We next claim that there are at most bad pairs. Indeed, suppose to the contrary that there are more than bad pairs. Note that because each interval of a bad pair contains at least parentheses, it holds that each block can participate in at most bad pairs. Thus, there is a set of at least bad pairs that are pair-wise disjoint (i.e., each block appears in at most one pair in ). Setting the sampling probability in Step 2b (of Algorithm 6.10) to , where is a sufficiently large constant, we get that the probability that no pair in has both of its blocks sampled is at most
By Claim 6.9, the excess parentheses matching procedure accepts a bad pair with probability at most . It follows that the tester will accept with probability at most , contradicting our choice of the fixed estimates. Hence, there are at most bad pairs. Since every pair of blocks can contain at most excess parentheses, the bad pairs contain at most locally excess parentheses in total.
We combine the matchings guaranteed for all good pairs (by the definition of good) to create the desired matching on the locally excess parentheses of . Recall that by Claim 6.6 it holds that for every , the approximate matching intervals and are contained in the respective (exact) matching intervals and . Thus, the approximate intervals of different pairs are disjoint, and hence combining the different matchings creates a legal matching (i.e., no parenthesis is matched to more than one parenthesis). Furthermore, since the matching graph is planar, the resulting matching is non-crossing.
It remains to bound the number of locally excess parentheses that are not included in the resulting matching. First, for each good pair , at most of the excess parentheses in and are unmatched. Furthermore, by Claim 6.6, the (exact) matching intervals and contain at most excess parentheses outside and . Hence, for each good pair , at most of the excess parentheses in and are unmatched. By Claim 6.4, the matching graph has at most edges. Therefore, altogether, the number of unmatched locally excess parentheses belonging to good pairs is at most . Together with the at most locally excess parentheses belonging to bad pairs, the total number of unmatched locally excess parentheses is at most . Recalling that , we set sufficiently small so that the claim follows.
6.4 On the adaptive tester for the Dyck languages
Recall that [FMS18] showed an adaptive tester for the Dyck languages with query complexity . Their tester uses a procedure called “Substring -matching”, which has essentially the same guarantees as our “excess parentheses matching” procedure (Algorithm 6.8) when the latter procedure is applied to the output of our Query procedure (Algorithm 5.10). The query complexity of the “Substring -matching” procedure is . Through a more careful analysis and parameter choice, the query complexity of our procedure has an improved dependence on ; namely, our procedure’s query complexity is . By replacing the “Substring -matching” procedure in the adaptive tester of [FMS18] with our procedure, we obtain:
Theorem 6.12. For every , and for any (arbitrarily small) constant , there exists an (adaptive) tester for with query complexity .
Acknowledgments
I am grateful to my advisor, Oded Goldreich, for his guidance throughout the development of this work, and for very helpful feedback on its presentation. I am grateful to Gil Aharoni for valuable suggestions on the presentation. The results in this work were obtained with assistance from GPT 5.5 and 6.0.
References
[AKNS01] Noga Alon, Michael Krivelevich, Ilan Newman, and Mario Szegedy. "Regular Languages are Testable with a Constant Number of Queries". In: SIAM Journal on Computing 30.6 (2001), pp. 1842–1862.
[CS63] Noam Chomsky and Marcel-Paul Schützenberger. "The Algebraic Theory of Context-Free Languages". In: Computer Programming and Formal Systems. Ed. by P. Braffort and D. Hirschberg. North-Holland Publishing Company, 1963, pp. 118–161.
[FMS18] Eldar Fischer, Frédéric Magniez, and Tatiana Starikovskaya. "Improved bounds for testing Dyck languages". In: Proceedings of the Twenty-Ninth Annual ACM-SIAM Symposium on Discrete Algorithms. SODA '18. 2018, pp. 1529–1544.
[GGR98] Oded Goldreich, Shafi Goldwasser, and Dana Ron. "Property testing and its connection to learning and approximation". In: J. ACM 45.4 (1998), pp. 653–750.
[MR08] Lutz Mattner and Bero Roos. “Maximal probabilities of convolution powers of discrete uniform distributions”. In: Statistics & Probability Letters 78 (2008), pp. 2992–2996.
[PRR03] Michal Parnas, Dana Ron, and Ronitt Rubinfeld. "Testing membership in parenthesis languages". In: Random Struct. Algorithms 22.1 (2003), pp. 98–138.
[RS96] Ronitt Rubinfeld and Madhu Sudan. “Robust Characterizations of Polynomials with Applications to Program Testing”. In: SIAM Journal on Computing 25.2 (1996), pp. 252–271.
Specifically, the improvement comes from the fact that in the procedure of [FMS18], the recursive call uses proximity parameter , whereas our analysis allows us to use proximity parameter .
Appendices
A A reduction to the equal-length case in ResStringEq
In Definition 1.1, the property ResStringEq is defined over pairs of strings of equal length. An alternative definition would allow and to differ in length. The purpose of this short appendix is to show that -testing this more general definition reduces to -testing the equal-length case, by padding the shorter string with star (i.e., ‘*’) symbols. Clearly, the padding preserves membership in ResStringEq. On the other hand, consider any modifications to the symbols of the padded pair that make the resulting residual strings equal. Notice that we may assume that no star symbol is modified: if a star symbol in one string is changed into a non-star symbol, we can instead replace the symbol matched with it in the other string by a star symbol. Thus, the padding symbols are not modified, implying the same modifications can be made in the original pair to make its residual strings equal. Since padding at most doubles the input length, an -far pair remains -far.
B Proof of Fact 4.7
This section provides a proof of Fact 4.7 (restated below), which generalizes Fact 4.2.
Fact B.1 (Fact 4.7, restated). Let and be two discrete random variables supported over a domain , and let and be two events over the probability spaces of and , respectively. If for every it holds that , then and .
Proof: First, notice that , and thus . Now, it holds that:
where the inequality is by the triangle inequality. Since , the claim follows.