Membership Testing for Semantic Regular Expressions
Open Access
- 10 June 2025
- journal article
- Published by Association for Computing Machinery (ACM) in Proceedings of the ACM on Programming Languages
- Vol. 9 (PLDI) , 1245-1268
Abstract
This paper is about semantic regular expressions (SemREs). This is a concept that was recently proposed by Smore (Chen et al. 2023) in which classical regular expressions are extended with a primitive to query external oracles such as databases and large language models (LLMs). SemREs can be used to identify lines of text containing references to semantic concepts such as cities, celebrities, political entities, etc. The focus in their paper was on automatically synthesizing semantic regular expressions from positive and negative examples. In this paper, we study the membership testing problem . First, we present a two-pass NFA-based algorithm to determine whether a string w matches a SemRE r in O (| r | 2 | w | 2 + | r | | w | 3 ) time, assuming the oracle responds to each query in unit time. In common situations, where oracle queries are not nested, we show that this procedure runs in O (| r | 2 | w | 2 ) time. Experiments with a prototype implementation of this algorithm validate our theoretical analysis, and show that the procedure massively outperforms a dynamic programming-based baseline, and incurs a ≈ 2 × overhead over the time needed for interaction with the oracle. Second, we establish connections between SemRE membership testing and the triangle finding problem from graph theory, which suggest that developing algorithms which are simultaneously practical and asymptotically faster might be challenging. Furthermore, algorithms for classical regular expressions primarily aim to optimize their time and memory consumption. In contrast, an important consideration in our setting is to minimize the cost of invoking the oracle. We demonstrate an Ω(| w | 2 ) lower bound on the number of oracle queries necessary to make this determination.Keywords
All Related Versions
Funding Information
- National Science Foundation (CCF 2313062, CCF 2146518, CCF 2107261)
This publication has 22 references indexed in Scilit:
- Tight bounds for reachability problems on one-counter and pushdown systemsInformation Processing Letters, 2021
- An improved combinatorial algorithm for Boolean matrix multiplicationInformation and Computation, 2018
- Symbolic finite state transducers2012
- Subcubic Equivalences between Path, Matrix and Triangle Problems2010
- An Effective Algorithm for the Membership Problem for Extended Regular Expressions2007
- Visibly pushdown languages2004
- Partial derivatives of regular expressions and finite automaton constructionsTheoretical Computer Science, 1996
- Learning regular sets from queries and counterexamplesInformation and Computation, 1987
- General context-free recognition in less than cubic timeJournal of Computer and System Sciences, 1975
- Ambiguity in Graphs and ExpressionsIEEE Transactions on Computers, 1971