betaFeedback

WorksComputer Science

Conditional Membership in Regular Languages

Abstract

We study a formulation of regular language membership as a promise problem, which we dub conditional membership: we fix a promise language PP and a target language T⊆PT \subseteq P, we are given a word ww which is promised to belong to PP, and we must determine whether ww belongs to TT. We study the deterministic worst-case query complexity of this task, when the length nn of ww is known in advance and where each query examines the ii-th position of ww for some 1≤i≤n1 \leq i \leq n and returns the ii-th letter wiw_i of ww. Our goal is to characterize the asymptotic complexity as a function of the word length nn, depending on the fixed languages PP and TT. Our main result is to show that the complexity of this task admits a trichotomy between three regimes: O(1)O(1) queries, Θ(log⁡n)Θ(\log n) queries, and Θ(n)Θ(n) queries. We further show that the trichotomy criterion is decidable, namely, it is PSPACE-complete to decide which regime applies, given nondeterministic automata APA_P and ATA_T respectively representing PP and TT.

Usage of AI AI tools assisted with drafting, editing, proofreading, background research, proposing some technical arguments in discussions with the authors (in particular the lower bound of Theorem 5.1), and reviewing the ideas and proofs, including checks for gaps, missing assumptions, edge cases and counterexamples, and suggestions for simpler proofs. The authors retain full responsibility for the final manuscript.

Introduction

We study the standard question of deciding whether an input word ww belongs to a fixed regular language TT. The task is well-known to admit a linear-time algorithm, by feeding ww to an automaton representing TT. Further, this bound is generally optimal if we must read the entire input ww. However, in settings where ww is stored in an array and we can examine any cell in constant time, then there are cases where we can decide membership more efficiently. For instance, with the target language T=Σ∗aT = \Sigma^*a, we can decide membership in constant time, simply by examining the last cell. Likewise, for the language T=a(ΣΣ)∗b∣c(ΣΣ)∗ΣdT = a(\Sigma\Sigma)^*b \mid c(\Sigma\Sigma)^*\Sigma d, we can decide membership simply by examining the first and last letter of the word, if we assume that the length of the word (and hence its parity) is known in advance. Thus, there are regular languages for which we can solve membership with just O(1)O(1) queries. A characterization of such languages is given in [1]1, together with a proof that all other regular languages require linear query complexity, i.e., Θ(n)\Theta(n) queries on a word of length nn.

However, in some cases we may be able to test membership to such languages more efficiently if we can leverage some hypotheses on the word ww. For instance, we may already know that ww is a valid Unicode string; or more generally we may have been given the information that ww belongs to some language and want to test membership to another. This motivates us to study regular membership posed as a promise problem [14], which we dub conditional membership. Specifically, we fix a target language TT together with a promise language PP, we are given a word ww which is promised to lie in PP, and we wish to determine whether ww belongs to TT (the algorithm can return an arbitrary answer if we try to run it on a word outside of PP).

To our knowledge, this natural conditional membership problem has not been studied for regular languages, despite its proximity to many similar questions. The one exception is the conclusion of [1] which mentions it as an open problem, and already highlights an intriguing phenomenon: with the target language T0:=(ΣΣ)∗(01)Σ∗T_0 := (\Sigma\Sigma)^*(01)\Sigma^* asking for an occurrence of 0101 at an odd position, and the language P0:=0∗1∗P_0 := 0^*1^* asserting that the input is sorted, they notice that we can decide membership to T0T_0 conditional to P0P_0 using binary search, i.e., with an intermediate regime of O(log⁡n)O(\log n) queries. This seems not to have been investigated further since 2019, leaving open the question of whether other regimes are possible (beyond constant, logarithmic, and linear), and how to characterize the language pairs that achieve them.

Contributions. In this paper, we give an effective trichotomy on the query complexity of conditional membership for arbitrary pairs of a regular target language TT and a regular promise language PP. We assume for simplicity that T⊆PT \subseteq P throughout, we assume that the length nn of the input word ww is known in advance, and we consider the model where ww can be accessed by queries that determine the ii-th letter wiw_i for each 1≤i≤n1 \le i \le n (i.e., random-access to the cells of an array that stores ww). We study the worst-case query complexity, i.e., the complexity for length nn is the minimum height of a decision tree that correctly classifies membership to TT on input words of length nn that belong to PP. To avoid periodic phenomena, we regularize the complexity by making it monotone, i.e., we study the asymptotic regime as nn grows of the query complexity obtained by taking the maximum optimal decision tree height across all lengths 0≤n′≤n0 \le n' \le n.

Our trichotomy result is then the following, with the three cases exemplified in Table 1:

Query complexityPromise PPTarget TTDefined in
O(1)O(1)(c∣d)a∗(c \mid d)a^*ca∗ca^*Example 3.7
Θ(log⁡n)\Theta(\log n)a∗(c∣d)b∗a^*(c \mid d)b^*a∗cb∗a^*cb^*Example 3.11
Θ(n)\Theta(n)a∗(c∣d)a∗a^*(c \mid d)a^*a∗caa∗a^*caa^*Example 4.19

Table 1. Examples of conditional membership problems.

Theorem 1.1. For any fixed regular language pair T⊆PT \subseteq P, the query complexity of conditional membership to TT assuming PP follows one of three regimes:

  • Constant, i.e., O(1)O(1) queries

  • Logarithmic, i.e., Θ(log⁡n)\Theta(\log n) queries

  • Linear, i.e., Θ(n)\Theta(n) queries

Further, the trichotomy criterion is effective: given nondeterministic automata APA_P and ATA_T that accept PP and TT respectively, it is PSPACE-complete to decide which case applies.

To prove this result, we use the framework of algebraic automata theory. Specifically, the characterization is based on a so-called mutual presentation of PP and TT, i.e., an arbitrary finite monoid MM that recognizes them both. Because the regime only depends on the choice of language pair, any choice of mutual presentation will give the same regime. The main challenge that we face is that conditional membership is a promise problem parameterized not by a single language, but by a language pair. For this reason, usual tools such as language varieties are not immediately applicable, and new methods are needed: the present paper can also be seen as first steps towards the development of such algebraic techniques in a new context, which may be relevant beyond the specific problem that we study.

At a high level, our proof proceeds by defining two tolerances on the mutual presentation MM: tolerances are similar to congruences on monoids but forego the transitivity requirement [25]. The tolerances intuitively relate pairs of elements that may be hard to distinguish, i.e., which would require at least some asymptotic number of queries to be told apart. The first tolerance is the guard tolerance which relates pairs of the form (exf,eyf)(exf, eyf), where ee and ff are two idempotents with nonempty preimages and where xx and yy are two elements with equal-length preimages. The matched-guard tolerance is a refinement of this relation obtained by relating pairs of the form (exe,eye)(exe, eye) with one common surrounding idempotent ee (still having a nonempty preimage), and with different preimage length requirements. We are interested in whether these tolerances shatter the promise-target pair, i.e., whether they relate two elements whose preimages are in PP but where one of them has preimages in TT and the other does not. Intuitively, when a tolerance is not shattered, then it justifies that a conditional membership algorithm can safely avoid querying some parts of the word. And whenever a tolerance is shattered, then the witnessing pair can be used to design a lower bound justifying that some number of queries is necessary to distinguish between the two elements (i.e., to locate the equal-length middle part that can achieve either xx or yy depending on its contents, and which may be “hidden” in a long sequence of idempotent factors).

Our specific technical upper bounds are then the following. First, when the guard tolerance is not shattered, we show that the language pair has constant query complexity. This is not too difficult and is simply done by querying a constant-length prefix and suffix of the input word, similarly to the constant query complexity case of regular language membership without a promise. Second, when the matched-guard tolerance is not shattered, we show the language pair has query complexity O(log⁡n)O(\log n). The idea for this upper bound is a binary search, similar to the example from [1] mentioned earlier, but made much more complicated by the fact that we need to perform constantly many binary searches with some elements playing different roles in different parts of the word. In both upper bounds, we rely on the fact that sufficiently long word infixes are guaranteed to contain idempotent factors as a consequence of Ramsey’s theorem (see [19 Section 1.2]), so we always query word blocks that are long enough to contain idempotents (to be used for pairs in our tolerances).

As for lower bounds, our methodology is the same for both: when one of the tolerances shatters the promise-target pair P,TP,T, we use a shattering pair in the tolerance as a building block to design a reduction. We always reduce from two concrete promise-target pairs, given as the two bottom rows of Table 1. The first one, with T=a∗cb∗T = a^*cb^* and P=a∗(c∣d)b∗P = a^*(c|d)b^*, has a logarithmic query complexity lower bound, intuitively because we must locate the middle part. The second one, with T=a∗c∗a∗T = a^*c^*a^* and P=a∗(c∣d)a∗P = a^*(c|d)a^*, has a linear lower bound. To reduce from these languages, we design general-purpose algebraic lemmas showing that intractability is intuitively preserved under some operations: moving to a more specific promise-target specification, taking quotients, taking inverse image by length-multiplying morphisms, and performing a form of concatenation.

We last show that all our algebraic techniques can be applied in polynomial time on the mutual presentation of the languages, so that the trichotomy criterion can be decided in PSPACE given automata representing the promise and target languages, going via an implicit representation of the mutual presentation; and show PSPACE-hardness of telling constant and linear languages apart. We next review some related work, and give the outline of the paper.

Related work. Our result uses algebraic automata theory, which is a common methodology to classify the complexity of problems parameterized by regular languages, provided that the tractable or intractable cases are closed under some algebraic operations (e.g., form a variety). Examples of the methodology include [5] (for circuit complexity), [28] (for communication complexity), [3] (for dynamic membership), [20] (for trail queries on graph databases), [12] (for sliding window membership) and [4] (for out-of-order membership). However, in all these works, the studied problem is parameterized by one single language, unlike ours. We also note that our work classifies arbitrary regular language pairs and not monoids, i.e., we do not assume the presence of a neutral letter: this is achieved by some of the works above [3, 20, 12] but not others [28, 4].

Other works have investigated the complexity of membership to regular languages in the so-called property testing model. This is somewhat reminiscent of our promise problem: the access model is the same, and the tester must accept for words in the target and reject words that are ϵ\epsilon-far from the target; otherwise the tester can answer arbitrarily. This problem was introduced in [2], with recent work showing a trichotomy on the query complexity of property testing depending on the target language [6]. However, they do not cover our setting where the target and promise language are arbitrary regular languages (rather than being defined in terms of the distance to a single language).

Our problem is also reminiscent of the question of regular language separation [24]: given two disjoint languages, the objective is to find a separator (often in a restricted language class) that accepts the first and rejects the second. However, the goal of finding a separator is different from our task of efficient conditional membership testing. Furthermore, conditional membership does not boil down to simply rewriting the promise language PP and target language TT to a single separator regular language T′T' on which to test membership (unconditionally). Indeed, if this were the case, then conditional membership would only admit constant and linear complexity regimes, but the example of [1] already shows that conditional membership also has a logarithmic regime.

One setting in which conditional membership for regular languages has been significantly studied is through the lens of state complexity, i.e., determining the minimum number of states needed in an automaton that must separate one language from another [13]. The best known instance of this setting is perhaps the separating words problem [15], where the two languages to be separated are singleton languages. This relates to works that have investigated three-valued automata variants (which may accept, reject, or return a “don’t know” answer) in the context of verification: these are called separating DFAs in [9] and 3DFAs in [10]. In all these works, however, the focus is on optimizing the state complexity of separating automata, unlike our work which focuses on query complexity and is independent of the representation of the languages.

Perhaps the most closely related work to ours is the work of Moshkov [21]. He fixes a promise language PP, and studies the following problem: given an unknown word ww which is promised to belong to PP, study how many queries are needed to determine ww exactly in the worst case. His work also shows a trichotomy on PP with three different regimes (constant, logarithmic, and linear), with a criterion defined in terms of an automaton for PP. While the problems are different, the upper bounds of [21] transfer to our setting in the following sense: whenever a promise language PP enjoys a sublinear upper bound thanks to [21], then conditional membership for any target language TT relative to PP enjoys the same upper bound. This is because determining ww exactly is sufficient to determine whether ww belongs to any target language. However, we are not aware of a reduction in the other direction, because the focus of [21] is on (non-fixed) single-word target languages. Further, and more importantly, the classification of [21] only applies to the promise language, whereas our result characterizes the complexity of conditional membership as a function of both languages.

Paper outline. We give prerequisites, formally define our problem, and state our main result in Section 2. The proof then spans Sections 3 and 4. In Section 3, we define the guard tolerance, show the constant upper bound when the guard tolerance is not shattering, and show the logarithmic lower bound when it is shattering. In Section 4, we define the matched-guard tolerance, show the logarithmic upper bound when the matched-guard tolerance is not shattering, and show the linear lower bound when it is shattering. Last, in Section 5, we show that the trichotomy criterion is effective, by giving our PSPACE-completeness result. We conclude and propose future work directions in Section 6. For lack of space, most detailed proofs are deferred to the appendix.

Preliminaries and Main Result

Write N={0,1,2,…}\mathbb{N} = \{0,1,2,\ldots\}, N+:=N∖{0}\mathbb{N}_+ := \mathbb{N} \setminus\{0\}, and [n]={1,…,n}[n] = \{1,\ldots,n\} for n∈Nn \in\mathbb{N}, with [0]=∅[0] = \varnothing. All logarithms are base two unless otherwise specified. We assume the finite alphabet Σ\Sigma has at least two letters, because for ∣Σ∣=1|\Sigma| = 1 knowing the length suffices to determine the word without making queries. Write Σ∗\Sigma^* for all words over Σ\Sigma, ε\varepsilon for the empty word, Σ+:=Σ∗∖{ε}\Sigma^+ := \Sigma^* \setminus\{\varepsilon\}, Σn\Sigma^n for words of length n∈Nn \in\mathbb{N}. For w∈Σnw \in\Sigma^n, its length is ∣w∣=n|w| = n, and wi∈Σw_i \in\Sigma denotes its letter at position i∈[n]i \in[n].

We use the usual definitions and notation for regular languages, regular expressions, union, concatenation, and Kleene star as in [18]. For u∈Σ∗u \in\Sigma^*, we write u+=uu∗u^+ = uu^*. For L⊆Σ∗L \subseteq\Sigma^* and u,v∈Σ∗u,v \in\Sigma^*, the quotient u−1Lv−1u^{-1}Lv^{-1} is {w∈Σ∗∣uwv∈L}\{w \in\Sigma^* \mid uwv \in L\}.

Our conditional membership problem will be defined by two regular languages T⊆P⊆Σ∗T \subseteq P \subseteq\Sigma^*, with promise PP and target TT. The unknown promised word ww belongs to PP, its length n:=∣w∣n := |w| is known, and its target value is 1 if w∈Tw \in T and 0 otherwise: we will have to determine it by making letter queries, where a query at i∈[n]i \in[n] reveals the letter wiw_i. We will introduce decision trees to formally define solutions to this problem and thus to measure complexity.

Decision trees and partial words. For n∈Nn \in\mathbb{N} a word length, a decision tree T\mathcal{T} is a finite rooted tree whose internal nodes are labeled by positions in [n][n] and have one child edge per letter in Σ\Sigma, and whose leaves are labeled 0 or 1. We require that any two distinct internal nodes on the same root-to-leaf path have different position labels. Thus, on every root-to-leaf path (called a branch), no position is queried twice. The semantics of T\mathcal{T} is that it maps every input word w∈Σnw \in\Sigma^n to a value in {0,1}\{0,1\} obtained by following a branch defined as follows: we start at the root, whenever we reach a node labeled ii then we query wiw_i and follow the child edge labeled with the letter wi∈Σw_i \in\Sigma that we receive; and we eventually reach a leaf whose label is in {0,1}\{0,1\}. We say that T\mathcal{T} accepts ww if the label is 1, and that it rejects ww if the label is 0. We say that T\mathcal{T} is correct for (P,T)(P,T) at length nn if the language LL of the words that it accepts is such that (L∩P)∩Σn=T∩Σn(L \cap P) \cap\Sigma^n = T \cap\Sigma^n, i.e., the tree must accept the words of TT and reject the words of P∖TP \setminus T; the answer for words outside of PP is unrestricted. We simply call T\mathcal{T} correct and omit the pair (P,T)(P,T) and the length nn when clear from context.

The depth of T\mathcal{T} is the maximum number of queries that can be made on a branch; the depth of a node dd is the number of queries made before reaching dd. Note that in particular, for n=0n = 0, the tree must always consist of a single leaf at depth zero. The query complexity QP,T:N→NQ_{P,T} : \mathbb{N} \to\mathbb{N} at nn is the maximum across all lengths 0≤k≤n0 \leq k \leq n of the minimum depth of a correct decision tree at length kk. The reason why we take the maximum over 0≤k≤n0 \leq k \leq n is to make the function nondecreasing: this regularization avoids periodic phenomena that would complicate the study of asymptotic complexity (e.g., if PP contains no words of even length, then a correct decision tree of depth 0 exists at every even length). Of course, we always have QP,T(n)≤nQ_{P,T}(n) \leq n, as witnessed by the tree that always queries every position (i.e., every branch has length nn and nodes at depth ii are labeled by position i+1i+1 for each $0 \leq i < n). Note that our definitions focus on depth, not tree size (see [7] for a broader landscape of complexity measures).

Throughout the paper, we will study the semantics of decision trees in terms of the partial words specified by their branches. Fix a fresh symbol □∉Σ\square\notin\Sigma. For n∈Nn \in\mathbb{N}, a partial word of length nn is a word w∈(Σ∪{□})nw \in(\Sigma\cup\{\square\})^n. A completion of ww is a word of Σn\Sigma^n obtained by replacing every □\square of ww with a letter of Σ\Sigma. The transcript of a node dd in a decision tree TT is the partial word containing the answers to queries along the path from the root of TT to dd (not including the query that labels dd), and □\square elsewhere. Note that TT reaches node dd while reading a word w∈Σnw \in\Sigma^n precisely when ww is a completion of the transcript of dd. We say that a partial word ww shatters (P,T)(P,T) if ww has two completions u,v∈Σnu,v \in\Sigma^n forming a shattered pair: one lies in TT and the other in P∖TP \setminus T. The following easy lemma shows that we can in fact define the correctness of trees simply via shattered pairs:

Lemma 2.1. If a decision tree TT for words of length n∈Nn \in\mathbb{N} is correct for (P,T)(P,T) at length nn, then for any leaf ℓ\ell of TT the transcript of ℓ\ell does not shatter (P,T)(P,T). Conversely, if a decision tree TT ensures that all its leaves have a transcript that does not shatter (P,T)(P,T), then we can make TT correct for (P,T)(P,T) at length nn by assigning labels to its leaves.

Thus, in subsequent constructions that define decision trees, we can always leave the leaf labels of the tree unspecified: by Lemma 2.1, it suffices to show that no leaf transcript shatters (P,T)(P,T) to show that the leaves can be labeled to make the tree correct.

References

  1. [1]Scott Aaronson, Daniel Grier, and Luke Schaeffer. A quantum query complexity trichotomy for regular languages. In FOCS, 2019. doi:10.1109/FOCS.2019.00061.DOI
  2. [2]Noga Alon, Michael Krivelevich, Ian Newman, and Mario Szegedy. Regular languages are testable with a constant number of queries. SIAM Journal on Computing, 30(6), 2001. doi:10.1137/S0097539700366528.DOI
  3. [3]Antoine Amarilli, Louis Jachiet, and Charles Paperman. Dynamic membership for regular languages. In ICALP, volume 198, 2021. doi:10.4230/LIPIcs.ICALP.2021.116.DOI
  4. [4]Antoine Amarilli, Sebastien Labbe, and Charles Paperman. Out-of-order membership in regular languages. In ICALP, volume 374, 2026. doi:10.4230/LIPIcs.ICALP.2026.161.DOI
  5. [5]David A. Mix Barrington, Kevin J. Compton, Howard Straubing, and Denis Thérien. Regular languages in NC¹. J. Comput. Syst. Sci., 44(3), 1992. doi:10.1016/0022-0000(92)90014-A.DOI
  6. [6]Gabriel Bathie, Nathanaël Fijalkow, and Corto Mascle. The trichotomy of regular property testing. In ICALP, volume 334, 2025. doi:10.4230/LIPIcs.ICALP.2025.141.DOI
  7. [7]Harry Buhrman and Ronald de Wolf. Complexity measures and decision tree complexity: A survey. Theoretical Computer Science, 288(1), 2002. doi:10.1016/S0304-3975(01)00144-X.DOI
  8. [8]Laura Chaubard, Jean-Éric Pin, and Howard Straubing. First order formulas with modular predicates. In LICS, 2006. doi:10.1109/LICS.2006.24.DOI
  9. [9]Yu-Fang Chen, Azadeh Farzan, Edmund M Clarke, Yih-Kuen Tsay, and Bow-Yaw Wang. Learning minimal separating DFA’s for compositional verification. In International Conference on Tools and Algorithms for the Construction and Analysis of Systems, 2009.DOI
  10. [10]Daniele Dell’Erba, Yong Li, and Sven Schewe. Dfaminer: Mining minimal separating DFAs from labelled samples. In International Symposium on Formal Methods, 2024.
  11. [11]Samuel Eilenberg. Automata, languages, and machines. Volume B. Academic Press, 1976.
  12. [12]Moses Ganardi, Danny Hucke, Markus Lohrey, Konstantinos Mamouras, and Tatiana Starikovskaya. Regular languages in the sliding window model. TheoreticCS, 4, 2025. URL: https://doi.org/10.46298/theoretics.25.8, doi:10.46298/THEORETICS.25.8.
  13. [13]Viliam Geffert and Abuzer Yakaryilmaz. Classical automata on promise problems. Discrete Mathematics & Theoretical Computer Science, 17(Automata, Logic and Semantics), 2015.
  14. [14]Oded Goldreich. On promise problems: A survey. In Theoretical Computer Science: Essays in Memory of Shimon Even. 2006.DOI
  15. [15]Pavel Goralčík and Václav Koubek. On discerning words by automata. In ICALP, 1986.DOI
  16. [16]Sheila Greibach. A note on undecidable properties of formal languages. Mathematical systems theory, 2(1), 1968.DOI
  17. [17]Markus Holzer and Barbara König. On deterministic finite automata and syntactic monoid size. Theoretical Computer Science, 327(3), 2004.
  18. [18]John E. Hopcroft, Rajeev Motwani, and Jeffrey D. Ullman. Introduction to automata theory, languages, and computation. Addison-Wesley, 2nd edition, 2001.
  19. [19]Ismaël Jecker. A Ramsey theorem for finite monoids. In STACS, volume 187, 2021. doi:10.4230/LIPIcs.STACS.2021.44.
  20. [20]Wim Martens, Matthias Niewerth, and Tina Popp. A trichotomy for regular trail queries. Logical Methods in Computer Science, 19, 2023.
  21. [21]Mikhail Moshkov. Decision trees for regular language word recognition. Fundamenta Informaticae, 41(4), 2000. doi:10.3233/FI-2000-41405.DOI
  22. [22]Jean-Éric Pin. Varieties of formal languages. North Oxford Academic, 1986.DOI
  23. [23]Jean-Éric Pin. Mathematical foundations of automata theory, 2025. Version of March 24, 2025. URL: https://www.irif.fr/~jep/PDF/MPRI/MPRI.pdf.
  24. [24]Thomas Place and Marc Zeitoun. Separating regular languages with first-order logic. Logical Methods in Computer Science, 12(1), 2016. doi:10.2168/LMCS-12(1:5)2016.DOI
  25. [25]Sándor Radelecki. Compatible tolerances on groupoids. Czechoslovak Mathematical Journal, 41(3), 1991. doi:10.21136/CMJ.1991.102478.DOI
  26. [26]Walter J. Savitch. Relationships between nondeterministic and deterministic tape complexities. Journal of Computer and System Sciences, 4(2), 1970. doi:10.1016/S0022-0000(70)80006-X.DOI
  27. [27]Benjamin Steinberg. Representation theory of finite monoids. Springer, Cham, 2016. doi: 10.1007/978-3-319-43932-7.DOI
  28. [28]Pascal Tesson and Denis Thérien. Complete classifications for the communication complexity of regular languages. Theory of Computing Systems, 38(2), 2005. doi:10.1007/s00224-004-1190-2.DOI

Paper details

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

views · 1

downloads · 0

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

  • Computer Science

AI tools

View statement
Looking for related papers…
Contents