Every large scientific corpus quietly depends on a few dozen lines of string-handling code that decide what counts as a paper. Examples include a title blacklist ("Front Matter", "Publication Information"), a minimum abstract length, a regex for section headings, and a cap on author count. These filters let in journal mastheads, committee listings and obituaries, and they also drop real papers with unusual layouts. Today they are judged only by spot-checking samples. We propose to treat each filter as a string program: a program built from concatenation, regex matching, replacement and length tests. We then ask a string constraint solver, an automated reasoner that decides whether some string satisfies a formula mixing word equations, regular expressions and length arithmetic, to construct the documents a filter gets wrong. The point is not to classify individual documents better. It is to search the whole space of inputs for systematic holes in a filter, and to report each hole as a concrete counterexample that can be checked against the real corpus.
The project has a second purpose. Specifications of "looks like a research paper" quickly climb the hierarchy of formal languages. "Title, then abstract, then sections" is regular. Nested sections with balanced structure are context-free. "Every cited key has a bibliography entry, and the counts match" is a counting property over copy-like structure, which sits in the territory of indexed languages, the class recognized by automata with a stack of stacks. Solvers are almost never evaluated on that territory. Our document specifications therefore give a natural, graded benchmark for a question nobody has measured: how do practical string solvers degrade as the required counting and nesting climb from regular toward indexed?
Core Claim
Heuristic corpus filters, written as straight-line string programs, fall into decidable fragments of string logic. A solver that couples length and counting constraints directly to automata will find filter errors that occur in real corpora. It will do so at lower cost than random sampling or grammar-based fuzzing on the same budget, and the advantage should grow exactly when the specification needs counting rather than pure regex shape. The scaling half of the claim is that solver time grows sharply with the depth of nesting and the number of coupled counts. The coupling of counts and automata is where the theoretical boundary lies.
Grounding in Prior Work
The decidability side supplies the method. Word Equations with Length Constraints: What's Decidable? and (Un)Decidability Results for Word Equations with Length and Regular Expression Constraints show that quantifier-free equations with length constraints are decidable once they are in "solved form". In that form each variable is defined by a parametric word, so string structure and integer arithmetic separate. The same papers report that roughly 80% to 87% of real symbolic-execution constraints were already in that form. They also prove that adding a universal quantifier over the same constraints makes the problem undecidable. We therefore keep every query existential: "does some document pass the filter while violating the spec?" We never pose the universal query "do all documents satisfy it?" directly.
What Is Decidable about String Constraints with the ReplaceAll Function shows that straight-line programs with global replacement are decidable. That is precisely the shape of normalization-then-match filters. Quadratic Word Equations with Length Constraints, Counter Systems, and Presburger Arithmetic with Divisibility gives a second decidable island, used where variables repeat at most twice.
OSTRICH2: Solver for Complex String Constraints is our primary engine. It includes a cost-enriched automaton engine, meaning automata that carry numeric counters on their transitions, which is the natural home for "abstract length ≥ 50" and "number of section headings ≥ 3". It also handles ECMAScript-style regex semantics, which is what Python and JavaScript filters actually use. Our contribution relative to OSTRICH2 is a new problem domain and a scaling study, not a new solver. Like the other solvers in this literature, it has been evaluated on web-security and competition constraints, not on document pipelines.
The hierarchy side constrains the scope. Slice closures of indexed languages and word equations with counting constraints proves that word equations with letter-counting constraints are decidable, and that checking $|w|_a = |w|_b$ over indexed languages is decidable. This is the theoretical warrant for citation-count specifications. However, its saturation procedure has no explicit complexity bound and is expected to be Ackermannian, and nobody has implemented it. Beyond order 2 the picture is worse. Pumping Lemma for Higher-order Languages gives a pumping lemma only conditionally on an unproven extension of Kruskal's theorem. The complexity of downward closures of indexed languages notes that order-2 algebraic methods break under deeper stack nesting.
We therefore make no claims at order 3 or above. Instead we bound nesting depth $k$, which flattens each specification into a regular language with counters. We then measure empirically how cost grows in $k$ and in the number of coupled counts. This tells practitioners where the Ackermannian worry actually bites on realistic inputs.
The document side motivates the work. S2ORC builds an 81.1-million-entry corpus and relies on heuristic filtering to discard non-research records. Lacuna's own index contains IEEE publication-information sheets such as IEEE Transactions on Cybernetics publication information, proceedings front matter such as Front Matter, tutorial-abstract volumes, and memorials such as A memorial tribute: Adriano Garsia (1928--2024). These entries are evidence that such filters leak. DocBank supplies token-level labels (Title, Abstract, Section, Reference, and others) that let us render arbitrary papers into the labeled token stream our filters and specifications read.
Research Program
First, we build an encoding layer. We collect real filter code: the heuristics described for S2ORC-style pipelines, keyword blacklists, length and author-count thresholds, and regex section detectors that we reimplement from public descriptions. We translate each into the SMT-LIB string-and-integer logic, where SMT means "satisfiability modulo theories". The input is a document serialized as a string over a small tag alphabet plus text, for example <T>…<A>…<S>…<R>…, matching DocBank's categories.
Second, we write specifications at three tiers. The regular tier covers tag ordering and heading patterns. The context-free tier, bounded to depth $k$, covers properly nested sections and floats. The counting tier covers constraints such as "number of reference entries equals number of distinct citation keys" and "abstract length exceeds 50 tokens while total body length exceeds the bibliography length". Each query asks for a string that the filter accepts but that violates the specification (a leaked non-paper), or that the filter rejects although it satisfies the specification (a dropped paper).
Third, every satisfying string the solver returns is a schematic document. We map it back to a search pattern and query S2ORC and the Lacuna non-research items for real instances. A counterexample counts as a confirmed bug only if real documents match it. This guards against the obvious failure mode of reporting absurd strings that never occur.
Fourth, we run the scaling study. Specifications are generated parametrically in nesting depth $k$ from 1 to 6 and in the number $c$ of coupled counts from 0 to 5. We record solver time and memory for each OSTRICH2 engine and for the regex-and-length solver of An SMT Solver for Regular Expressions and Linear Arithmetic over String Length. The prediction is that the counter-carrying engine degrades gracefully in $c$ while the alternatives do not, and that the cost growth in $k$ is the empirical analogue of the hierarchy breakdown the theory papers describe.
Baselines
The naive reference point is passive sampling. We draw documents uniformly from S2ORC metadata plus the labeled non-research set, run the filter, and hand-check disagreements with the specification. This is how filters are evaluated today. Given the same human-checking budget as the confirmation step, beating it means finding more distinct confirmed bug patterns per hour.
The strongest competitor is grammar-based fuzzing. We generate documents from a probabilistic grammar over the same tag alphabet, mutate real DocBank-rendered papers, and keep inputs where filter and specification disagree. It is strong because it shares our grammar knowledge without any solver. To make the comparison fair, it receives the same specifications, the same CPU budget per filter, and the same confirmation procedure. We report confirmed bug patterns found within the budget and the time to the first bug in each pattern. No reported result found on Lacuna for either fuzzing or solver-based bug finding on document filters, so both are measured fresh.
For the detection task itself, we train a learned classifier on the tagged token stream, initialized from the layout models in DocBank, as an alternative filter. On DocBank's own token-labeling task, LayoutLM-Large reaches Macro F1 0.9350 and a Faster R-CNN plus LayoutLM ensemble reaches 0.9488. That is a layout-labeling number, not a non-research detection number: no reported result found on Lacuna for non-research document classification. We measure the classifier on our labeled held-out set. Our repaired filters beat it if they match its F1 while remaining auditable. Losing to it on accuracy is acceptable only if the solver still exposes errors the classifier shares.
Two ablations isolate the key ingredient. The first removes all length and counting constraints, leaving pure regex shape. The second keeps lengths but removes coupled counts. If the confirmed-bug yield does not drop when counting is removed, the hierarchy-climbing part of the proposal is not pulling its weight.
Why not just…?
Why not just train a classifier and stop writing filters? That is the likely end state for detection accuracy, and we do not claim the solver beats it there. But a classifier also has blind spots, and nobody can enumerate them. We will apply the same counterexample search to a distilled rule surrogate of the classifier. Together with the held-out evaluation, this shows whether its errors cluster on the patterns the solver finds. If the classifier has none of the solver-found failure patterns and wins on F1, the practical argument for verifying hand-written filters weakens to auditability alone, and we will say so.
Why not just fuzz? This is the real threat. Many filter bugs are shallow, for example a blacklist that misses "Publication Information" when it is written in capitals, and fuzzing will find them cheaply. The solver should win only where a bug requires several thresholds to hold simultaneously, such as a masthead long enough to pass the abstract check but with a reference count of zero. Random generation rarely hits such narrow numeric intersections. The fuzzing comparison, split by specification tier, settles this. If fuzzing matches the solver on the counting tier, the contribution reduces to a benchmark and a scaling study.
Why not just check each document's invariants directly in Python? Checking a single document is trivial, and we do it in the confirmation step. The question is different: whether a filter can ever leak a given class of document. That is a statement about all inputs, which per-document checks cannot make. The existential encoding keeps it decidable, following the solved-form and straight-line results above.
Proposed Experiments and Decisive Checks
The labeled set combines the non-research items catalogued in Lacuna (mastheads, front matter, committee lists, tutorial volumes, memorials, calls for papers) with a size-matched random sample of S2ORC full-text papers. It is augmented with the ETD cover pages from Automatic Metadata Extraction Incorporating Visual Features from Scanned Electronic Theses and Dissertations as a hard, non-standard-layout case; on those pages a visual-feature conditional random field reaches field-level F1 between 81.3% and 96%. The solver-scaling study uses our generated specification families alongside the SMT-LIB string tracks as a sanity anchor; no reported result found on Lacuna for specific solver times on those tracks.
There are three decisive checks. The first is whether solver counterexamples yield more confirmed, real-corpus bug patterns than fuzzing under equal budget on the counting tier specifically. The second is whether filters repaired using those counterexamples improve held-out precision and recall on the labeled set without overfitting to the patterns found. The third is whether solving time shows a clear knee in nesting depth $k$ and coupled counts $c$. Such a knee would give a practical, measured boundary between the cheap regular-plus-counter regime and the region where the indexed-language theory warns of non-elementary cost. A negative result on the first check is informative too: it would show that, for real filters, string-length interaction is shallow enough that testing suffices.
References
- Word Equations with Length Constraints: What's Decidable?
- (Un)Decidability Results for Word Equations with Length and Regular Expression Constraints
- What is decidable about string constraints with the ReplaceAll function
- Quadratic Word Equations with Length Constraints, Counter Systems, and Presburger Arithmetic with Divisibility
- OSTRICH2: Solver for Complex String Constraints
- Slice closures of indexed languages and word equations with counting constraints
- Pumping Lemma for Higher-order Languages
- The complexity of downward closures of indexed languages
- S2ORC: The Semantic Scholar Open Research Corpus
- IEEE Transactions on Cybernetics publication information
- Front Matter
- A memorial tribute: Adriano Garsia (1928--2024)
- DocBank: A Benchmark Dataset for Document Layout Analysis
- An SMT Solver for Regular Expressions and Linear Arithmetic over String Length
- Automatic Metadata Extraction Incorporating Visual Features from Scanned Electronic Theses and Dissertations