Manuscript Offprint
arXiv:2611.12315Beating Rytter's Bound: All-Pairs CFL Reachability in Time
Beating Rytter's Bound: All-Pairs CFL Reachability in Time
RUPAK MAJUMDAR, Max Planck Institute for Software Systems, Germany
Context-free reachability and 2NPDA recognition are fundamental problems in program analysis and language theory. Despite years of effort, the best algorithms for these problems run in time on a word RAM model; they are based on an observation of Rytter in 1985 for 2NPDA which was adapted for CFL reachability by Chaudhuri in 2008. No better algorithm has been designed since.
We give the first improvement to Rytter's algorithm. For both all-pairs context-free reachability and 2NPDA recognition, we show a deterministic algorithm running in time and words of space for every fixed on a word RAM. Our improvement is based on a new data structure that reports set differences using batched maintenance of exact intersection counts, allowing saturation to skip regions that contain no new reachability information.
A related problem in language theory is 2NPDA recognition. Given a fixed 2NPDA and an input word of length , it asks whether the (fixed) 2NPDA accepts [24, 25]. An algorithm for 2NPDA recognition saturates paths in the automaton, its run time is again cubic. The equivalent run times are not an accident: 2NPDA recognition and CFL reachability are linear-time inter-reducible [18, 26]. In fact, these are two representative problems from a class of many problems in program analysis for which the natural algorithms run in cubic time (the “cubic bottleneck”). These problems include slicing, dataflow, heap-shape, points-to analysis, and set constraints [5, 18, 26, 29, 40, 42].
A natural question is whether the cubic bottleneck can be improved. In 1985, Rytter showed that a logarithmic improvement is possible [44]. He obtained an -time algorithm for 2NPDA recognition, which implements the saturation procedure on top of packed-set data structures. Chaudhuri applied the corresponding speedup to CFL and recursive-state-machine reachability to obtain an algorithm for CFL reachability that runs in time for a graph with vertices [17]. No better algorithm is known and breaking Rytter's bound in the general case is a longstanding open problem (see, e.g., [41]). There are barriers from fine-grained complexity to finding truly subcubic algorithms (algorithms running in time for some constant ) for this class, [13, 18]. However, obtaining a polylogarithmic improvement is consistent with fine-grained barriers, which only obstruct truly sub-cubic algorithms. But, no such improvement was found in 40 years.
In this paper, we show a new algorithm for all-pairs CFL reachability that improves Rytter's bound by a factor .
Author's Contact Information: Rupak Majumdar, Max Planck Institute for Software Systems, Kaiserslautern, Germany, rupak@mpi-sws.org.
Rupak Majumdar
THEOREM 1.1 (ALL-PAIRS CFL REACHABILITY). For every fixed context-free grammar and fixed , all-pairs CFL reachability on an -vertex directed labeled graph can be computed in
deterministic time and words of space on a word RAM with -bit words.
Our algorithm explicitly returns the Boolean relation for every nonterminal , including the start symbol. As an immediate corollary, we can also decide CFL reachability between a designated start and an end state as well as 2NPDA recognition. (Note that the space requirement for our algorithm is for any fixed ; the standard algorithm requires quadratic space.)
Main ideas The saturation algorithm for CFL reachability repeatedly performs the following step: When it learns a new fact and the grammar has a rule , it finds all vertices with already known but not yet known. Symmetrically, when it learns a new fact , it finds all such that is known but not known.
Each of these steps requires querying a set difference of two sets of vertices. With bit vector representations of sets, one difference costs about word operations, and there are about such questions. This gives the bound of Rytter and Chaudhuri. Across all difference queries, only elements are reported, because each report produces a previously unknown fact. Nevertheless, the packed-set implementation performs a linear scan for every query, even when its answer is empty. Any improvement to Rytter's bound has to bound this wasted work.
Our main technical contribution is a data structure for reporting set differences between two families of sets that grow independently during saturation. It extends the sparse-subset tabulation principle [10] to exact integer counts. The data structure combines the following three ideas.
Idea 1: count before you scan. We divide the vertices of the graph into about groups. For each choice of sets and in the saturation algorithm and for each group, we keep track of how many elements of in that group also lie in . If this count equals the number of elements of in the group, the group holds nothing new and is skipped in the saturation procedure. Only groups that are certain to contain a new fact are scanned. Each scan therefore pays for itself with a new fact, and there are only new facts in total.
Idea 2: update the counts lazily. Keeping the counts exact after every insertion is expensive. A new element of a set changes its counts against all sets of the other side. Our idea is to make new elements first wait in a short pending list. Subsequent queries inspect this list directly. Only after about elements have accumulated in the pending list are the counts brought up to date, in one batch.
Idea 3: precompute small pieces of a batch. A batch update must add the contributions of many elements to the counts of all opposite sets. We precompute these contributions for every small set of coordinates, of size up to about , inside a block of coordinates. A batch is split into such small pieces, and each piece costs one table lookup and one word-parallel vector addition instead of one addition per element. Because only small sets are tabulated, the blocks can be much longer than while the tables stay polynomial in size. This ensures that we maintain small space while answering queries.
One subtlety is that, as saturation progresses, both and grow. An element that belongs to both sets must be counted exactly once, when the later of its two batches is processed. For each set, we maintain a snapshot containing the elements whose pending batches have already been processed. The key is maintaining snapshots on both sides of a query. We split the stored counts between two arrays, one supporting word-parallel row updates and the other supporting word-parallel column updates. Short pending lists correct the snapshot counts exactly, allowing the algorithm to identify regions that contain a new fact before scanning them. Every such scan can therefore be charged to a newly derived fact.
Outcome. Together, these ideas save a factor of over the packed-set algorithm. The two factors come from the size of the small pieces and from the bits needed to store their counts. The result is the bound of Theorem 1.1.
Our contribution is a purely theoretical analysis. We do not claim that our algorithm will outperform existing, optimized implementations of CFL reachability. However, we consider breaking Rytter's bound an important breakthrough for the problem which may open the door to further improvements.
2 Related Work
Practical CFL-reachability algorithms A lot of research has gone into making CFL reachability faster in practice, by exploiting either client needs or the program structure, or by providing engineering improvements that scale in practice but do not provide a better worst-case complexity.
Demand-driven analyses avoid computing facts unrelated to a client's queries. Horwitz, Reps, and Sagiv [28] formulate interprocedural dataflow analysis around requests for individual facts at individual program points. Zheng and Rugina [53] answer alias queries by exploring a CFL-reachability graph until enough evidence is found, without first constructing and intersecting complete points-to sets. These approaches exploit selective queries; however, they do not break the cubic bottleneck.
Systems work addresses the cost of storing and processing large analysis graphs. Graspan [47] uses disk-based graph processing to scale interprocedural analyses beyond main memory. Chianina [54] adds an evolving-graph formulation for flow sensitivity and disk support for the memory demands of context sensitivity. These systems separate analysis logic from the mechanisms used to execute it efficiently.
Other methods reduce redundant derivations. The partially ordered solver of Lei et al. [35] maintains spanning-tree representations of transitive relations to avoid repeatedly deriving the same consequences. Graph folding [36] uses a recursive state-machine representation of the grammar to guide reductions of the input graph. Skewed tabulation [34] changes how recursive productions are evaluated, through grammar transformations or a specialized solver, to avoid intermediate summary edges that do not contribute to the requested relation. Our structure addresses a different source of work within saturation: testing set differences that contain few or no new facts. Understanding how its batching costs interact with these evaluation strategies is a question for future implementations.
Faster algorithms under restrictions Restrictions on the language, graph, or machine can change the complexity substantially [41]. For Dyck-1, stack height determines stack content, since there is only one parenthesis type. Mathiasen and Pavlogiannis [38] give an all-pairs algorithm; related algebraic bounds were obtained by Bradford [12]. General CFL reachability reduces to Dyck-2 reachability, for which the above algorithms do not work. Grammar-specific classifications also distinguish tractable languages from harder ones [31].
In bidirected Dyck graphs, each opening edge has a reverse edge with the matching closing label. Reachability then forms an equivalence relation, allowing algorithms to maintain classes of vertices. Following earlier work [51, 52], Chatterjee, Choudhary, and Pavlogiannis [15] compute this compact representation in time, where counts edges and is the inverse Ackermann function. Explicitly listing all reachable pairs can still require quadratic output. Treewidth offers another restriction: Chatterjee et al. [16] exploit constant treewidth of recursive state-machine
Rupak Majumdar
components to preprocess interprocedural queries. This differs from assuming constant treewidth of an arbitrary Dyck graph, which retains combinatorial Boolean matrix-multiplication hardness [15].
Restrictions on computations give further improvements. On loop-free 2NPDAs [44] and bounded-stack recursive state machines [17], one can get an algorithms. For fixed deterministic two-way pushdown automata, Cook showed a linear time recognition algorithm [20, 23], famously used in Knuth-Morris-Pratt's algorithm for string matching. However, his procedure does not establish the same bound for 2NPDA recognition.
Parsing and matrix-vector algorithms A different direction of research relates CFL problems with matrix multiplication. Valiant's parser [46] uses Boolean matrix multiplication to combine facts about substrings. Substring intervals give the recursive computation an order that arbitrary cyclic graphs do not provide. For a static Boolean product, Four Russians tabulation [4] precomputes combinations of small groups of coordinates; together with word packing, it gives time. Subsequent combinatorial algorithms obtain larger savings [7, 14, 50], including a recent algorithm [2].
Preprocessing is also useful when the second operand arrives later. Williams [48] preprocesses a fixed matrix over a fixed finite semiring in time to support vector products in time. In online Boolean matrix-vector multiplication, each answer must be returned before the next vector arrives. Larsen and Williams [32] process such vectors in randomized time . Dudek and Gawrychowski [22] transfer online-product improvements to online context-free string recognition. Dynamic variants also handle changing matrices and adaptive queries [37]. These results make matrix products promising tools for saturation, but a transfer must match the operations and their frequency. The discussion at the end of Section 6 explains the additional requirements of correcting snapshots and discovering missing facts.
Sparse tabulation and set data structures The closest tabulation precedent is Blelloch, Vassilevska, and Williams [10]. They divide matrix columns into blocks and precompute Boolean products for subsets containing only a few coordinates. Splitting a sparse query into these subsets reduces the number of combinations needed; the tables also support replacing a matrix column. Their applications include sparse transitive closure and other graph problems. We extend this sparse-subset principle to integer sums. Unlike Boolean answers or a fixed finite semiring, exact counts have a range growing with the input. Our analysis charges for their representation width, carries, and table maintenance, and combines these tables with independently growing snapshots on both sides of a set query.
Dynamic set-intersection structures provide a different tradeoff. Kopelowitz, Pettie, and Porat [30, Theorem 1] give a randomized structure with constant expected update time. On a logarithmic-word RAM its reporting time is in expectation, where bounds set size and counts outputs. Their applications include triangle enumeration. A difference can be written as an intersection with a complement; insertions into the subtracted set then become deletions from its complement. Our insertion-only structure spends more time on updates and more space to obtain deterministic exact counts and faster empty-difference queries for dense sets. Static structures additionally support set disjointness and union-intersection expressions [9, 19]. Batching has precedents in static-to-dynamic transformations [8]; semi-naive evaluation likewise organizes deductions around newly added facts [6].
Conditional lower bounds CFL reachability has been studied through the lens of fine-grained complexity. For string parsing, Lee's BMM reduction uses an input-dependent grammar [33], whereas Abboud, Backurs, and Vassilevska Williams obtain -Clique barriers for a fixed grammar [1]. Chatterjee, Choudhary, and Pavlogiannis show a reduction from combinatorial BMM to CFL reachability [15]. Under the NFA Acceptance Hypothesis [13], there is no truly subcubic
algorithm for CFL reachability. These conditional bounds do not preclude logarithmic improvements. Chistikov, Majumdar, and Schepper [18] show subcubic verification of certificates for both reachability and non-reachability. Such certificates establish a distinction between checking a supplied answer and constructing the reachability relation.
3 Preliminaries: All-Pairs CFL Reachability
We write . A labeled graph , over a (fixed) alphabet consists of a (finite) set of vertices, with , and labeled edges . A walk is a sequence of vertices
such that for each . Thus, a walk may repeat vertices and edges. The label of a walk is the word formed by the concatenation of its edge labels; the empty walk has label .
Definition 3.1 (All-pairs CFL reachability). Let be a context-free grammar (CFG), where is its set of nonterminals, its productions, and its start symbol. For each , let be the language derivable from , and define the relation
The all-pairs CFL reachability problem takes as input a graph and a CFG and outputs, for every nonterminal , the Boolean matrix of : for every ordered pair , its entry is one if and only if . The output includes diagonal pairs and accounts for empty walks when . We consider the grammar to be fixed in our principal bound; the graph is the varying input. For a fixed grammar the output matrices have Boolean entries in total.
The (designated-pair) CFL reachability problem additionally takes two vertices and outputs the single bit indicating whether . Clearly, the complexity of CFL reachability is at most that of all-pairs CFL reachability (but could be asymptotically better). Our algorithm solves the all-pairs problem, returning for every , and also solves the designated-pair problem.
We assume that the grammar is in Chomsky normal form, that is, its productions are of the forms , and . In statements with grammar dependence, refers to this normalized representation (which is polynomial in the size of the original grammar), and we write for its number of binary productions. A fact is an entry in a nonterminal relation. If , then holds for each , and if , then holds for all .
The Dyck language with types consists of properly matched words in openings and closings . It is generated by . For fixed , its normalization has constant size. It is known that Dyck-1 reachability can be solved in time [38], and any all-pairs reachability problem for a fixed grammar can be reduced to Dyck-2 reachability in linear time in the bitsize of the input [18].
Computational model. We use a word RAM with Boolean operations, shifts, integer arithmetic, and random access to words. Each operation on one word costs unit time, and space is measured in words. The word size is , with a fixed constant large enough to address all the memory we use. This memory is polynomial in .
If the grammar is part of the input, memory also holds one matrix per nonterminal, so an address needs bits. In that case we take . Our data structures never pack more than bits of data into one word, even when is larger. Extra bits in a word are used only for addresses and do not provide additional parallelism. All bounds are therefore stated in terms of and not in terms of . For a fixed grammar, , so the two choices of word size agree.
Rupak Majumdar
Packed sets. A packed set represents a subset by its characteristic bit vector, stored in consecutive words. Element is bit of word . Rows and columns of Boolean matrices are stored as packed sets.
LEMMA 3.2 (PACKED SETS). After preprocessing that takes time and space, packed sets over support the following operations.
(1) Membership test, insertion, and deletion of one element in time.
(2) Union, intersection, and difference of two packed sets, producing a packed set, in time.
(3) Enumeration of the elements of in time.
In particular, the elements of can be listed in time.
PROOF. For (1), we compute and , and test, set, or clear the bit using a one-bit mask built by a shift. For (2), we apply the corresponding bitwise operation word by word. The difference is AND (NOT ). For (3), we scan the words and skip each zero word in time. For a nonzero word we need the positions of its one bits. So, we split the word into chunks of at most bits. Since , there are chunks. During preprocessing, we build a table that lists, for every chunk value , the positions of the one bits of . The table has at most entries, each a list of at most positions, so it takes time and space. We extract each chunk by a shift and a mask, look up its list, and add the chunk's offset. A nonzero word thus costs plus the number of its elements, which gives the bound. (A word RAM with a constant-time instruction for the lowest set bit would not need the table. However, we do not assume such an instruction.)
We use the following conventions when we talk about data structures later. All stated time bounds include the time to build tables such as the one in Lemma 3.2. Bounds are asymptotic. Inputs with below a fixed constant are handled by brute force in constant time, so we may assume that is large enough whenever convenient.
The saturation algorithm. The relations computed by all-pairs CFL reachability are the least solution of a system of equations. To see this, we first represent each relation as a Boolean matrix. Let contain the pairs with for some rule , together with the diagonal when is a rule. Then the matrices form the least simultaneous solution of
where multiplication is Boolean and is entrywise OR.
The classical algorithm for all-pairs CFL reachability computes this least solution by saturation [43]. It starts with the initial facts in and repeatedly derives new facts until no rule applies. Pending facts are kept in a queue , called the worklist. During saturation, denotes the set of facts found so far. The algorithm has no designated source or target and treats all ordered vertex pairs alike.
When a fact is processed and is a rule, the new conclusions are the facts with already known and not yet known. In matrix terms, the candidates form the row difference
Symmetrically, when a fact is processed, the new conclusions are given by the column difference .
Algorithm 1 shows the saturation algorithm. We summarize its properties below (see, e.g., [43]).
Algorithm 1 The algorithm SATURATE. Each difference is computed completely before its elements are inserted. This matters for rules such as , where the insertions change the set being subtracted.
INSERT(Z, a, b): If , return. Add to and append to .
SATURATE: For each rule and each edge , call INSERT(A, u, v). For each rule and each , call INSERT(A, v, v). While is nonempty, remove its first element . For each rule , call INSERT(A, a, b). For each rule , compute ; for every , call INSERT(A, a, x). For each rule , compute ; for every , call INSERT(A, u, b). Return .
LEMMA 3.3 (SATURATION). SATURATE terminates. For every nonterminal and every ordered pair , the returned matrix satisfies if and only if some walk from to has a label in .
PROOF. INSERT adds each fact at most once, and there are at most facts. So receives finitely many elements and the loop terminates. Soundness: every inserted fact has a witness walk. The base cases are witnessed by single edges or empty walks. A unit rule maintains the witness. A binary rule concatenates the witnesses of its two premises.
Completeness: we show that the returned relations satisfy every rule. Equation (1) then implies that they contain the least solution. Seed edges are inserted at the start. Every inserted fact is later processed, and processing it applies all unit rules to it. Now take a binary rule and returned facts and . Consider whichever of the two is processed later. If it is , then at that moment, so either is already known or is in the row difference and is inserted. The case of is symmetric and uses the column difference.
Cost of saturation. Let be the number of facts at termination; for a fixed grammar . Each fact is processed once. For each binary rule containing its nonterminal on the right-hand side, processing a fact issues one difference query. So there are difference queries. Every element reported by a query is absent from when the query starts and is inserted immediately afterwards. It is therefore never reported again, by this query or by any later one. Summed over the whole run, the reported elements number at most .
- Naive implementation. Computing a difference by testing all coordinates takes time. The total is . For a fixed grammar this is .
- Packed sets. Store every row and every column of every as a packed set. An insertion updates one row and one column in time. By Lemma 3.2, a difference with reported elements takes time. The total is , which is for a fixed grammar.
This packed-set speedup is the technique of Rytter for two-way pushdown automata [44]. Chaudhuri applied it to CFL reachability [17]. Its bound is the baseline that we improve.
The data-structure problem. The cost of saturation is dominated by the difference queries. Both operands only grow during the run: rows and columns of each gain elements as saturation proceeds and never lose them. Abstractly, we need to maintain two families of sets and ,
Rupak Majumdar
, where all sets are subsets of . We want to allow insertions into these sets and answer queries
For a row instance of , the sets are and . Column instances are symmetric.
With packed sets, a query costs even when the answer is empty. There can be such queries, which gives the cubic term. To beat , a query reporting elements should cost plus a term that can be charged to the reported elements, while insertions remain cheap in amortized terms. Next, in Sections 4 and 5, we show how to build such a data structure (Theorem 5.4). Finally, Section 6 plugs the new data structure into SATURATE and work out the complexity bounds.
Equation (1) explains the connection of CFL reachability to matrix multiplication. However, the Four Russians bound for one static Boolean product (Section 2) does not carry over to our setting. First, the unknown matrices occur on both sides. Second, the relations change and the queries are generated adaptively. Thus, a bound for one matrix product with fixed operands does not bound either the number of products or the cost of their incremental changes.
4 Sparse subset tabulation
Sections 4 and 5 solve the data-structure problem stated at the end of Section 3. Since the problem does not depend on CFL reachability and is of independent interest, we state it in a general form.
The set-pair problem. The goal of the data structure is to maintain two families of sets over the universe for and for . Equivalently, we can assume that there are two Boolean matrices whose rows are the sets and the sets , respectively. Each such row is called a line: is an line and is a line. The lines of the other family are called the opposite lines; for an line, these are the lines , and vice versa. Initially every line is empty. The data structure supports two operations.
-
Insert an element into a line, that is, change one matrix entry from 0 to 1. Entries never change back.
-
Report the difference for a given pair .
In SATURATE, a binary rule gives a row instance with and , and a column instance that is symmetric. As we saw, with packed sets, a report costs even when the difference is empty. Our goal is to make reports with few outputs cheaper, while keeping insertions cheap on average. In the following, we will describe the data structure and use a number of parameters, , etc. as we go along. These parameters will be picked later to derive the asymptotic bounds.
Overview of the solution. The data structure combines two ideas.
-
Groups and counts. We partition the universe into groups of consecutive elements. If, for each group , we knew the count , a report could compare it with and scan only the groups that contain an output. The parameter will be picked later.
-
Snapshots and batched updates. Maintaining these counts exactly after every insertion would be too expensive: one insertion into an line changes its counts with all opposite lines. We therefore split each line into two parts. The snapshot consists of the elements whose effect on the stored counts has already been accounted for. The pending list holds the remaining elements, which were inserted since then. The same holds for and . Counts are stored only for snapshots. Reports correct them
by additionally using the (short) pending lists. When a pending list reaches a threshold of elements, the line is promoted: its pending elements join its snapshot, the counts of this line with all opposite lines are updated, and the pending list is emptied. As with the parameter , the parameter will be picked later.
A promotion is the expensive step. Suppose is promoted with pending list , so . The update needs, for every group and every opposite line , the number . Arrange the snapshots as the rows of a Boolean matrix, the snapshot matrix of the family. Then the required numbers, for all at once, form the vector obtained by adding the columns of this matrix indexed by . Adding the columns one at a time costs at least operations on -entry vectors per promotion.
This section develops the tool that does this step faster, the sparse subset table. It works for any Boolean matrix whose entries change from 0 to 1, such as a snapshot matrix, which changes whenever a line of its family is promoted. The table adds the columns indexed by using about vector additions instead of (Lemma 4.2), where is a suitably chosen sparsity parameter to be decided later. Section 5 then maintains the counts, implements promotions and reports, proves their correctness, and fixes all parameters.
The tabulation problem. Throughout this section, is a Boolean matrix with rows and columns, whose columns are called coordinates. Initially is zero, and it changes only by setting entries from 0 to 1. Fix a partition of its coordinates into groups, as described below. A query supplies a set of coordinates as a sorted list and asks, for every group meeting , for the vector
whose th entry is the number of coordinates of that lie in row . Groups disjoint from have the zero vector implicitly. The tabulation problem is to maintain a representation of under these insertions and answer these queries efficiently.
In Section 5, we will set to be the snapshot matrix of one family, so and after padding, and will be the pending list of a line of the other family that is being promoted.
Parameters. The section uses four parameters. Their values will be fixed later. Until then, all statements hold for arbitrary values.
-
, the block length. Coordinates are split into blocks of consecutive coordinates, and tables are built per block.
-
, the sparsity. Tables store only subsets of a block with at most elements.
-
, the number of groups. These are the groups of the outline. Each group is a union of consecutive blocks.
-
, the promotion size. A query set is a promoted pending list, so . is used only at the end of this section, to choose .
For orientation, the final choice will be , , , and . Blocks are therefore polylogarithmic in size and much smaller than groups.
Blocks and groups. We add zero columns ("padding") to until is a multiple of . We number the columns of by and then partition the columns into blocks of consecutive columns. A group is a union of consecutive blocks, so every block lies inside exactly one group.
Sparse subsets. For integers , let
Rupak Majumdar

Fig. 1. Bit-plane addition with and two-bit operands (). Reading a column from top to bottom gives the binary expansion of the entry above it. Each horizontal plane fits in one word in this example, so each Boolean operation in the full-adder equations acts on all four entries at once. Carries move to the next plane at the same entry position; they never pass between entries. The sum needs a third plane. For general , each plane occupies words.
A block has subsets of size at most , since the th term counts the subsets of size exactly . The term for counts only the empty set, so of these subsets are nonempty. By algebra, we have . The point of the bound is that is far smaller than the subsets of a block when . So we can afford long blocks, provided each lookup uses only a few coordinates of a block.
The table. For every nonempty set of at most coordinates within one block, the sparse table stores the vector
Its ith entry is the number of elements of in row of .
Bit planes. Entries of are at most , so they need bits. We store in bit planes: plane packs bit of all entries into words. Two such vectors are added with word-parallel ripple-carry addition, for all entries at once. For one word position, write the operand planes as and set . The output and carry planes are
Each bit position implements the usual full adder independently. An extra plane keeps the final carry when the result needs one more bit. With this representation, adding two vectors with k-bit entries therefore costs word operations, not . Figure 1 shows an example of the representation.
Pieces. To answer a query , we split , for each block , into pieces of at most coordinates each. Every piece is a set with a stored vector . The sum over is the sum of the vectors of the pieces inside . The number of pieces is
where is the number of blocks meeting . The inequality follows from .
Example 4.1. Let , , , and . The blocks are and . Let the rows of be , , and , and let , all in one group. The pieces are and in the first block and in the second, so . Their stored vectors are
with sum , which is . The entries are counts. Replacing the sum by a Boolean or would give , which records only that the intersections are nonempty.
LEMMA 4.2 (SPARSE TABLES). The sparse table, consisting of the vectors for all nonempty sets of at most coordinates within a block, occupies words. With incidence lists of total size , a previously zero entry can be set to one in time, keeping the table correct. For a set of coordinates supplied as a sorted list, all group sums can be computed in
time, where is the number of groups meeting and is the number of pieces in (3). The matrix is initially zero, and initialization costs the stated storage and incidence bounds.
PROOF. Space. There are blocks, each with stored vectors, and each vector has planes of words.
Updates. Fix a coordinate . The stored sets that contain consist of and at most other coordinates of its block. There are exactly of them. The incidence list of stores the addresses of their vectors. Setting to one increments entry of each of these vectors. One such increment reads and updates at most planes. No entry exceeds , so planes suffice.
Initialization. The matrix is initially zero, so every stored vector is zero: the tables are allocated and cleared. The incidence lists are built by enumerating, for each block, the nonempty sets of at most coordinates and appending the address of each set to the lists of its members, in time proportional to their total size.
Queries. We cut the sorted list at block boundaries and split each block's part into pieces of at most consecutive elements. To locate the vector of a piece, we compute its rank: if the piece has local positions within its block, its rank among sets of size is , plus an offset for the sets of smaller size. With a precomputed table of binomial coefficients, all ranks take time in total. Ranks and table addresses fit in a word, since the tables fit in polynomial space. For a group with pieces, we add their vectors along a balanced binary tree. At level of the tree, the operands have at most planes and there are at most additions. An unpaired operand is passed up without arithmetic. Summing over levels, the geometric part gives . The ceilings contribute at most one extra addition per level, there are levels, and the extra addition at level costs ; together these give . Since and the pieces partition , summing over the groups gives the bound and the correct sums.
Choosing the block length. We now relate to the promotion size . Let be the size of the original coordinate universe, before padding, and choose . With groups, pad to a multiple of , so . A promotion has , and the number of blocks meeting is at most . With , this gives
For the number of pieces is whenever . The additions of a promotion then cost word operations. Adding the columns one at a time would cost at least . In our application is polylogarithmic. Then is polynomial even for .
Sparse subset tables are a variant of the data structure of Blelloch, Vassilevska, and Williams [10, Theorem 1]. They store a Boolean matrix and split its columns into blocks of length . For every block and every vector with at most nonzeros, they precompute the Boolean product of the block with that vector. A query vector is split, within each block, into pieces with at most nonzeros,
Rupak Majumdar
which saves a factor of about when is large. Their structure also supports replacing a column. Our tables use the same blocks, sparse subsets, and pieces, with and . The difference is the stored values: we need exact counts, that is, integer sums of columns, rather than Boolean products. This requires the bit-plane representation, word-parallel carries, and the integer-width accounting above. In addition, our updates set single entries, which incidence lists handle at cost each.
5 Two-sided incremental counting
This section completes the set-pair structure of Section 4 and proves its main guarantee, Theorem 5.4. A report of should scan only the groups that contain an output. To find these groups, the structure maintains, for every group and every pair of lines, the snapshot intersection count
The section has four steps.
(1) What is stored. Besides the lines themselves, we store the sparse tables of Section 4 for both snapshot matrices. We also store the counts , split into two counter arrays whose sum is (invariant (5)).
(2) Promotions. A promotion updates the counts of the promoted line with all opposite lines at once. It uses a sparse-table query whose cost is given by Lemma 4.2.
(3) Reports. The counts, corrected by the two short pending lists, identify exactly the groups that contain an output. Only those groups are scanned.
(4) Costs and parameters. We bound the cost of each operation (Lemma 5.3), choose the parameters, and obtain Theorem 5.4.
Intuition: counting when both families grow. The difficulty is that both families change, so neither family's snapshots can be treated as fixed. Consider an element . It belongs to exactly when it is in both snapshots, that is, after the later of the two promotions that move into and into . That later promotion finds already in the opposite snapshot. So the rule is simple: each promotion counts its promoted elements against the current opposite snapshots. The earlier promotion does not count , and the later one does, so is counted exactly once. No coordination between lines and no common snapshot time are needed.
The second question is where to store the counts. A promotion of produces, for each group, a vector of counts indexed by , one for each opposite line . To add this vector to the stored counts with one word-parallel vector addition (Section 4), the counters for this fixed must be stored contiguously. Thinking of as a matrix with rows and columns , these counters form column of . Symmetrically, a promotion of needs row of stored contiguously. A single array cannot be laid out both ways. We therefore keep two arrays: receives the contributions of promotions, stored by columns, and receives the contributions of promotions, stored by rows. Their sum is .
We store the following:
-
Every line , and every snapshot , is stored as a packed set, so that membership tests take constant time. Every pending list is also stored as a list of its elements.
-
Two sparse tables: for the snapshot matrix of the family, whose rows are the sets , and for the snapshot matrix of the family. Both use the same blocks and the same groups.
-
For every group and every , the count .
-
Two families of counter vectors. For every group and every , a vector of counters indexed by . For every group and every , a vector of counters
indexed by . Counters never exceed , so each vector is stored in bit planes, as in Section 4.
The counter arrays satisfy the invariant
Initially all lines are empty and all stored quantities are zero, so the invariant holds.
To insert an element into a line, we first test whether it is already present; if so, we do nothing. Otherwise we add it to the line's packed set and its pending list. If the pending list now has D elements, we promote the line as described next. Operations are executed one at a time, and a promotion finishes before the next operation begins. Hence every pending list has fewer than D elements between operations.
Promoting a Y line. Next, we describe promotions. Let , so . Lemma 4.2 needs in sorted order. Since and both sets are stored packed, enumerating their packed difference lists in increasing order in time (Lemma 3.2). Here is how promotions work:
(1) Query with (see Lemma 4.2 for costs). For every group this gives the vector with entries for all .
(2) Add to for every group .
(3) Move into . In , set the entries for to one, using the update operation of Lemma 4.2. Empty the pending list.
Before the promotion, . So the right side of (5) increases by exactly for every , and the left side increases by the same amount. The X snapshots do not change, so the invariant is preserved for all other pairs.
Promoting an line. This is symmetric. Let . Query with to obtain for all . Add to , and increase by . Then move into , update , and empty the pending list. The same argument preserves (5). Promotions of the two families may interleave arbitrarily. The argument holds for every interleaving, because each promotion counts against the opposite snapshots exactly as they are just before it.
Example 5.1. Let an element belong to both and . Suppose is promoted first. At that time does not contain , so this promotion adds zero for . When is promoted later, is in , and the promotion adds one to . In the opposite order, the promotion comes second and adds one to . Either way the sum in (5) counts exactly once.
Reporting a difference. We want . Every output lies either in the pending list or in the snapshot :
The first part is found by scanning the short pending list. For the second part, the stored counts tell how many elements of are missing from . Some of these may already be in , namely in its pending list . These must be subtracted, which takes a scan of the short list . The procedure is as follows.
(1) Scan . Mark the group of every element that is not in .
(2) For every group G, compute
Rupak Majumdar
(3) Scan once, testing membership in , to compute for every group . These elements are in and in but not in , so
(4) Call a group live if it was marked in step 1 or . For each live group, compute the packed difference of and restricted to the words of and list its elements (Lemma 3.2).
By (6) and (7), a group is live if and only if it contains an element of S. Hence the report lists exactly S: every element of S lies in a live group, and the scan of a live group lists the elements of S in it. Moreover, every scan of a live group reports at least one output. We call such scans productive. In Section 6, every reported element is a new fact, so the cost of each productive scan can be charged to a new fact. This is how empty or nearly empty reports avoid paying for full scans.
Example 5.2. Take groups and , and lines with , , , and . Then . For the snapshot count is , because . But , so and : the group is not live and is not scanned. The pending element 2 of makes live, and its scan returns exactly 2. Without the correction , the group would be scanned without reporting anything, and that scan could not be charged to an output.
LEMMA 5.3 (GENERAL COSTS). A report operation on the data structure costs
where is the number of live groups. If , a promotion costs
excluding the sparse-table updates, which cost an additional for every promoted element.
PROOF. Reports. The scans of the two pending lists cost . Reading one counter from a vector stored in bit planes takes time, and step 2 reads a constant number of counters for each of the groups. Each group has coordinates after padding, so scanning a live group costs plus its outputs (Lemma 3.2).
Promotions. Listing in sorted order costs ; this cost is absorbed by the other terms. We apply Lemma 4.2 with and , and bound the number of pieces by (4). With this gives , which gives us the second and third terms. Adding the resulting vectors into the counter arrays costs , which the last term absorbs. The table updates are the update operation of Lemma 4.2, applied once per promoted element.
Parameter choice. Now we pick the parameters to balance the costs in Lemma 5.3. The promotion size must be large, because a promotion costs about and is paid for by its insertions. This gives about per insertion, independently of , but only if the other promotion terms are smaller than this. must also be small, because every report scans pending lists of size up to . The choice makes these scans as cheap as scanning one group. With groups, reading the counters costs and scanning one group costs . The sparsity is as large as possible while each block has at most stored vectors, which gives . The block length then follows from Section 4.
Precisely, let and fix . For sufficiently large , choose
Pad the universe to a multiple of , and add empty lines so that there are as many lines as coordinates. The new size is , so all asymptotic bounds are unchanged. We have
The last property implies , as Lemma 5.3 requires.
THEOREM 5.4 (INCREMENTAL SET-PAIR STRUCTURE). With the parameters above and initialization and space, the following bounds hold.
• Inserting an element that is not yet in the line costs amortized time, for either family.
-
A report of costs , where is the number of live groups.
-
The exact intersection count , and a test of whether , cost in the worst case.
PROOF. Space. The two sparse tables occupy words each, and their incidence lists . The two counter families occupy words. Packed lines, lists, and group counts add at most words. All polylogarithmic factors are absorbed by the slack , giving space and initialization.
Insertions. Charge each promotion to the distinct insertions in its pending list. By Lemma 5.3, the dominant term per insertion is . By (8), , , and , so this term is . The other terms per insertion are , which is polylogarithmic. The table updates cost at most per inserted element. Since , all these terms are for large .
Reports. This is Lemma 5.3, since , , and .
Intersection counts. Use the disjoint union
The size of the first part is the sum of (5) over all groups. The other two parts are found by scanning the pending lists. The total cost is . Finally, holds if and only if .
REMARK 1. If the lines are the rows of a Boolean matrix and the lines are the columns of a Boolean matrix , both changing only from 0 to 1, then the structure maintains the integer product : each entry is available at the intersection-count cost of Theorem 5.4.
Figure 2 shows one set-pair instance. The three ingredients are the two families of lines with their snapshots and pending lists (Section 4), the sparse tables that turn a sorted pending list into per-group count vectors with table lookups instead of D column additions (Lemma 4.2), and the two counter arrays whose opposite layouts let both kinds of promotion add their vectors contiguously. The report never reads the sparse tables. It reads counters, scans the two pending lists, and touches the packed words of a group only when the corrected count or a pending element guarantees an output there.
6 The all-pairs CFL reachability algorithm
This section combines SATURATE (Section 3) with the set-pair structure (Theorem 5.4) and proves the main theorem. It has three steps.
(1) Instantiation. Each binary production gets two set-pair instances, one for the row differences and one for the column differences of SATURATE. Every insertion into a relation is forwarded to the instances that contain it.
Rupak Majumdar
(a) Stored bit vectors and separate pending lists

Separate pending lists (entries are coordinate numbers):
Bits: 1 0
(b) Sort the pending batch, split into pieces, and query

Each lookup returns a vector: for every opposite line .
(c) Update the counters for each group G
Y promotion: add

: columns stored contiguously

: rows stored contiguously
The two dark cells sum to .
(d) Report : test before scanning
, or a pending element of in group is missing from
Scan group G to get at least one output
Fig. 2. The set-pair structure. (a) Current sets and snapshots are stored as separate packed bit vectors. Pending members are already set in the current vector, absent from its snapshot, and also recorded in an explicit list below. The fifth pending Y insertion triggers a promotion; other pending lists have fewer than D elements. (b) The pending coordinates are enumerated in sorted order and split into pieces of at most s = 2 coordinates within a block. Sparse-table vectors are added separately for each group; for the displayed X[v] line, and . (c) A Y promotion adds a column vector; an X promotion symmetrically uses and adds a row vector. The matrices show the two storage orientations schematically, and the dark cells represent the same pair . After a promotion, its pending elements enter its snapshot and its own sparse table is updated. (d) A report reads the two counters and corrects for pending insertions before scanning a group. A group that fails the test is skipped.
(2) Charging. Each report costs , plus for each live group, plus its output. There can be reports with live groups each, so bounding each report separately is too weak. Instead, every live group contains a new fact, so the total number of live groups over the whole run is at most the number of facts.
(3) Running time. Summing the costs of Theorem 5.4 with this charging gives the main theorem.
Set-pairs. For every binary production , we create two instances of the set-pair structure:
| Instance | X lines | Y lines | Processed fact | Report |
|---|---|---|---|---|
| Row instance | rows of | rows of | ||
| Column instance | columns of | columns of |
The row instance reports the row difference (2), and the column instance reports the column difference. Each instance keeps its own copies of its lines. A relation can occur in several instances, by rows or by columns and as the or the family. Relations only grow during saturation. This matches the set-pair structure, which supports insertions but no deletions.
Instantiating saturation. We run SATURATE (Algorithm 1) with two changes.
-
After INSERT() sets the bit of , it notifies every instance in which is a family. If the instance uses the rows of , the notification inserts into line . If it uses the columns, it inserts into line . Such an insertion may cause a promotion inside the instance. A promotion changes only the instance's internal data. It does not call INSERT and does not touch the worklist.
-
Each difference in SATURATE is computed by a report query to the corresponding instance. The full pseudocode is given in the supplementary material. As in SATURATE, a report is completed before any of its elements are inserted. This matters here because the insertions notify the same instance, and they would otherwise change the line being subtracted, or trigger a promotion, during the report.
Every insertion into a relation is forwarded to all instances containing it. So, at all times, the lines of every instance are the current rows or columns of the corresponding relations. A report returns exactly the requested difference (Section 5). Hence the run computes the same differences as SATURATE, and Lemma 3.3 applies.
LEMMA 6.1 (ALL-PAIRS CORRECTNESS). The algorithm terminates and, for every nonterminal and every ordered pair , its returned matrix satisfies if and only if some walk from to has a label in . In particular, the returned solves all-pairs CFL reachability.
Charging. Let be the number of facts in the final relations, including the initial facts. This counts facts over all ordered vertex pairs, not only those relevant to a designated query. For a fixed grammar, we have . Fix the row instance of a production ; the column instance is symmetric.
-
Insertions. Its lines receive one insertion for each fact of and one for each fact of , so at most insertions. (The two relations may coincide, when .)
-
Reports. There is one report for each processed fact , so at most reports.
-
Promotions. Each promotion empties a pending list of elements, so there are at most promotions.
-
Live groups. Each live group of a report contains at least one reported element (Section 5). Such an element is a new fact : it is absent from when the report starts and is inserted right after the report. Afterwards is in the line , so no later report of this
Rupak Majumdar
instance returns it again. Hence the total number of live groups, summed over all reports of the instance, is at most .
The last item is the key to the analysis. Bounding each report by its worst case of g live groups would give a total of Fg group scans, which is too large.
THEOREM 6.2 (REFINED ALL-PAIRS SATURATION BOUND). For a Chomsky normal form grammar with P binary productions, size , and F final nonterminal facts, saturation computes all nonterminal relations and takes
time and words of space. The constants in the O do not depend on .
PROOF. Fix one instance. By Lemma 5.3 and the counts above, its cost besides initialization is
The first line covers the reports: the fixed part of each of the at most reports, the scans of at most live groups in total, and at most reported elements. The second line covers the promotions and the table updates. Each inserted element is promoted once, and its table updates cost . With (8), the leading term is the promotion term with (see the proof of Theorem 5.4). The remaining terms are, per fact, , all dominated by .
The two instances of each binary production are initialized in time, for in total. Seeding terminal and nullable facts and processing unit rules cost , apart from the notifications already counted: each unit rule is applied once to each of the at most facts of , including attempts that find the fact already present. Summing over all productions proves the time bound. The space bound adds the space of each instance (Theorem 5.4) to the space of the relations and the worklist.
PROOF OF THEOREM 1.1. Lemma 6.1 establishes correctness for every entry of all the returned matrices. Apply Theorem 6.2 with a fixed grammar and to bound their computation. Returning , or all the nonterminal matrices, requires no further saturation; even copying their packed representation costs only time. Since , initialization and all lower-order polynomial and polylogarithmic terms are eventually dominated by the stated time.
The two factors in the bound have different origins. One is the inverse sparsity . It arises because and (equation (8)). The other is the number of bit planes needed for an exact count of a piece. Improving either one would improve the final bound.
The two counter families occupy only words. The exponent in the space accounting comes entirely from the two sparse tables, whose size is words. A smaller sparsity trades time for space. With in place of the choice in (8), the bound gives , so the structure uses words, while the amortized insertion cost becomes . The proofs above use only for some and , so they apply unchanged. Consequently, the algorithm of Section 6 also solves all-pairs CFL reachability for a fixed grammar in time and space.
Relation to fast matrix-vector products. The connection with known fast matrix-vector algorithms [32, 37, 48] can be seen from a single worklist event. Recall that processing a fact for a rule asks for destinations in : those reachable through from whose corresponding fact from is still missing. A Boolean matrix-vector product can test whether this difference is nonempty. Take the matrix whose row marks the elements missing from , and multiply it by the characteristic vector of . The product answers the nonemptiness question for every at once, although this worklist event asks about only one . There are worklist queries, so invoking a whole product for each query does not give a better bound. Even dynamic algorithms that support changing matrices and adaptive queries [37] need a way to share this work across many events.
Batching updates offers such sharing, but then the stored answers describe snapshots, and queries must account for insertions that have not yet been included. The difficulty already appears when stays fixed and only grows. Suppose the snapshot difference is either or . A Boolean answer records “nonempty” in both cases. If is then inserted into , the first difference becomes empty, while the second still contains . The stored Boolean answer cannot distinguish these outcomes, and storing as a witness does not help. A stored count does: it starts at one or two, respectively, and subtracting the contribution of the pending insertion gives zero or one. Our structure performs this correction within each group by inspecting the short pending lists.
Maintaining exact counts is itself expensive if every insertion updates its counts against all opposite lines separately. Our sparse tables make these updates affordable by processing a batch of new elements together. The corrected counts then identify precisely which groups contain a missing fact. Scanning each such group discovers at least one new fact, so the bound on new facts also bounds the total number of these scans. Thus the improvement combines efficient batch updates, correction of snapshot answers, and a bound on the work spent discovering new facts. We do not know if existing matrix-vector algorithms can be modified to provide these combinations.
7 2NPDA recognition
A 2NPDA has finite state and stack alphabets, reads a fixed input tape in either direction, uses an unbounded stack, and has a nondeterministic transition relation [25]. Recall that the recognition problem for a fixed 2NPDA asks whether it accepts a given input word of length . Chistikov, Majumdar, and Schepper show linear-time reductions between 2NPDA recognition and designated-pair Dyck-2 reachability in the bit-size of the input [18, Proposition 20 and Appendix E]. Since an explicitly encoded dense graph may require bits, these equivalences cannot equate the length of an input word with graph vertex count. Therefore, we give a direct -vertex construction needed for our recognition bound. Our all-pairs algorithm yields recognition by answering the designated queries arising in that construction.
Fix a 2NPDA with states , stack alphabet , and bottom symbol . Its input tape contains with positions , where and are special end-of-tape markers. A transition tests the current state, tape symbol, and stack top, changes the state, moves by , or , and performs a push or pop on the stack or leaves the stack as it is. The head stays within the endmarkers and cannot be popped. Any 2NPDA can be normalized this way. For conventional final-state acceptance, reserve a bottom symbol that is never pushed and append a clearing phase. We use acceptance in a final state with only the bottom remaining.
We now reduce 2NPDA recognition to (designated-pair) CFL reachability. The graph has vertices . For a legal transition at position , ending in state and position , , we introduce the following edges:
Rupak Majumdar
| No change | |
|---|---|
| Push | |
| Pop | for every |
A pop edge guesses the revealed symbol. We use a fixed grammar, a Dyck grammar with one parenthesis type per stack symbol and a neutral letter , to check this guess by recording the old top through the opening label: for .
LEMMA 7.1 (FLAT COMPUTATIONS). There is an S-labeled walk from to if and only if and there is a computation from stack to that same stack, with these control states and head positions, that never pops the displayed .
PROOF. Transitions inspect only the top, so a computation preserving the displayed prefix is independent of . For the forward direction, induct on the grammar derivation. Empty and walks give the empty computation and a no-change step. Concatenation composes flat computations. For , the initial surface top must be . The opening edge pushes some , and the inductive interior begins and ends with top without removing it. The final pop exposes and reaches the specified surface. Thus the guessed pop destination is correct.
Conversely, induct on the length of a flat computation. The first step cannot pop its protected top. A no-change step gives an edge and a shorter flat remainder. After an initial push of , take the first step returning to the original height. Before that pop, the computation is flat at ; apply induction to this interior and to the remainder. The outer edges are and , yielding followed by the remainder. This proves the grammar derivation.
COROLLARY 7.2. Recognition by any fixed 2NPDA can be solved in time and words of space.
PROOF. The graph has vertices and edges and is constructed in linear time. By Lemma 7.1, acceptance is precisely an S-walk from to some with final. Apply the all-pairs algorithm of Theorem 1.1 to this graph and test these entries of the returned relation. This recognition consequence uses only designated entries of an output that is computed for all pairs.
8 Discussion and open problems
We have made the first progress on the running time of context-free reachability and 2NPDA recognition since Rytter's packed sets [17, 44]: we show an asymptotic improvement by a factor. The key innovations are to use a novel sparse-set data structure and to batch updates to the data structure within a line. A natural follow-up is to remove the factor to get a “pure” algorithm. A more ambitious goal will be to match the best algorithms for NFA acceptance. While our improvements are theoretical, we hope that our ideas of using sparse sets can also lead to more efficient implementations in practice.
AI Use
We used Claude Opus 5.5 to understand the key ideas of [10, 27, 32, 48] and why they do not show an improvement for CFL reachability. We used Claude Opus 5.5 to iterate over the design of the data structure and its proof of correctness. We wrote our own exposition of the results starting from those proofs. We used Claude Fable 5.1 to autoformalize the main results from this draft except for the word-RAM model. The formalization found no errors.
References
[1] Amir Abboud, Arturs Backurs, and Virginia Vassilevska Williams. 2018. If the Current Clique Algorithms Are Optimal, so Is Valiant's Parser. SIAM J. Comput. 47, 6 (2018), 2527–2555. doi:10.1137/16M1061771 Preliminary version in FOCS 2015, pp. 98–117.
[2] Amir Abboud, Nick Fischer, Zander Kelley, Shachar Lovett, and Raghu Meka. 2024. New Graph Decompositions and Combinatorial Boolean Matrix Multiplication Algorithms. In Proceedings of the ACM Symposium on Theory of Computing (STOC).
[3] Rajeev Alur, Michael Benedikt, Kousha Etesami, Patrice Godefroid, Thomas W. Reps, and Mihalis Yannakakis. 2005. Analysis of recursive state machines. ACM Trans. Program. Lang. Syst. 27, 4 (2005), 786–818. doi:10.1145/1075382.1075387
[4] Vladimir L. Arlazarov, Efim A. Dinic, Mikhail A. Kronrod, and Igor A. Faradzev. 1970. On economical construction of the transitive closure of an oriented graph. Soviet Mathematics Doklady 11 (1970), 1209–1210.
[5] A. R. Balasubramanian, Dmitry Chistikov, and Rupak Majumdar. 2025. Pushdown Model Checking above the Cubic Bottleneck. In 40th Annual ACM/IEEE Symposium on Logic in Computer Science, LICS 2025, Singapore, June 23–26, 2025. IEEE, 622–635. doi:10.1109/LICS65433.2025.00053
[6] François Bancilhon and Raghu Ramakrishnan. 1986. An Amateur's Introduction to Recursive Query Processing Strategies. In Proceedings of the 1986 ACM SIGMOD International Conference on Management of Data. 16–52. doi:10.1145/16894.16859
[7] Nikhil Bansal and Ryan Williams. 2012. Regularity Lemmas and Combinatorial Algorithms. Theory of Computing 8, 1 (2012), 69–94. Preliminary version in FOCS 2009.
[8] Jon Louis Bentley and James B. Saxe. 1980. Decomposable Searching Problems I: Static-to-Dynamic Transformation. Journal of Algorithms 1, 4 (1980), 301–358. doi:10.1016/0196-6774(80)90015-2
[9] Philip Bille, Anna Pagh, and Rasmus Pagh. 2007. Fast Evaluation of Union-Intersection Expressions. In Algorithms and Computation, 18th International Symposium (ISAAC) (Lecture Notes in Computer Science, Vol. 4835). 739–750. doi:10.1007/978-3-540-77120-3_64
[10] Guy E. Belloch, Virginia Vassilevska, and Ryan Williams. 2008. A New Combinatorial Approach for Sparse Graph Problems. In Proceedings of the International Colloquium on Automata, Languages, and Programming (ICALP). https://people.csail.mit.edu/rrw/icalp08.pdf
[11] Ahmed Bouajjani, Javier Esparza, and Oded Maler. 1997. Reachability Analysis of Pushdown Automata: Application to Model-Checking. In CONCUR '97: Concurrency Theory, 8th International Conference, Warsaw, Poland, July 1-4, 1997, Proceedings (Lecture Notes in Computer Science, Vol. 1243). Springer, 135–150.
[12] Phillip G. Bradford. 2018. Efficient Exact Paths For Dyck and semi-Dyck Labeled Path Reachability. CoRR abs/1802.05239 (2018). arXiv:1802.05239
[13] Karl Bringmann, Allan Grønlund, Marvin Künnemann, and Kasper Green Larsen. 2024. The NFA Acceptance Hypothesis: Non-Combinatorial and Dynamic Lower Bounds. In Proceedings of the Innovations in Theoretical Computer Science Conference (ITCS). Full version at https://arxiv.org/abs/2311.10204.
[14] Timothy M. Chan. 2015. Speeding up the Four Russians Algorithm by About One More Logarithmic Factor. In Proceedings of the ACM-SIAM Symposium on Discrete Algorithms (SODA). 212–217.
[15] Krishnendu Chatterjee, Bhavya Choudhary, and Andreas Pavlogiannis. 2018. Optimal Dyck reachability for data-dependence and alias analysis. Proc. ACM Program. Lang. 2, POPL (2018), 30:1–30:30. doi:10.1145/3158118
[16] Krishnendu Chatterjee, Rasmus Ibsen-Jensen, Andreas Pavlogiannis, and Prateesh Goyal. 2015. Faster Algorithms for Algebraic Path Properties in Recursive State Machines with Constant Treewidth. In Proceedings of the 42nd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL). 97–109. doi:10.1145/2676726.2676979
[17] Swarat Chaudhuri. 2008. Subcubic Algorithms for Recursive State Machines. In Proceedings of the ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL). https://www.cs.utexas.edu/~swarat/pubs/pop08.pdf
[18] Dmitry Chistikov, Rupak Majumdar, and Philipp Schepper. 2022. Subcubic Certificates for CFL Reachability. In Proceedings of the ACM SIGPLAN Symposium on Principles of Programming Languages (POPL). https://arxiv.org/abs/2102.13095
[19] Hagai Cohen and Ely Porat. 2010. Fast Set Intersection and Two-Patterns Matching. Theoretical Computer Science 411, 40–42 (2010), 3795–3800. doi:10.1016/j.tcs.2010.06.002
[20] Stephen A. Cook. 1972. Linear Time Simulation of Deterministic Two-Way Pushdown Automata. In Information Processing 71 (IFIP Congress, 1971). North-Holland, 75–80.
[21] Danny Dolev, Shimon Even, and Richard M. Karp. 1982. On the Security of Ping-Pong Protocols. Inf. Control. 55, 1-3 (1982), 57–68. doi:10.1016/S0019-9958(82)90401-6
[22] Bartlomiej Dudek and Pawel Gawrychowski. 2024. Online Context-Free Recognition in OMv Time. In Proceedings of the Annual Symposium on Combinatorial Pattern Matching (CPM) (LIPIcs, Vol. 296). 13:1–13:9. doi:10.4230/LIPIcs.CPM.2024.13
Rupak Majumdar
[23] Robert Glück. 2013. Simulation of Two-Way Pushdown Automata Revisited. In Semantics, Abstract Interpretation, and Reasoning about Programs (EPTCS, Vol. 129). 250–258. https://arxiv.org/abs/1309.5142
[24] Jim Gray, Michael A. Harrison, and Oscar H. Ibarra. 1967. Two-Way Pushdown Automata. Information and Control 11, 1/2 (1967), 30–70.
[25] Michael A. Harrison and Oscar H. Ibarra. 1968. Multi-Tape and Multi-Head Pushdown Automata. Inf. Control. 13, 5 (1968), 433–470. doi:10.1016/S0019-9958(68)90901-7
[26] Nevin Heintze and David A. McAllester. 1997. On the Cubic Bottleneck in Subtyping and Flow Analysis. In Proceedings, 12th Annual IEEE Symposium on Logic in Computer Science (LICS), Warsaw, Poland, June 29 - July 2, 1997. IEEE Computer Society, 342–351. doi:10.1109/LICS.1997.614960
[27] Monika Henzinger, Sebastian Krinningger, Danupon Nanongkai, and Thatchaphol Saranurak. 2015. Unifying and Strengthening Hardness for Dynamic Problems via the Online Matrix-Vector Multiplication Conjecture. In Proceedings of the ACM Symposium on Theory of Computing (STOC). https://arxiv.org/abs/1511.06773
[28] Susan Horwitz, Thomas W. Reps, and Moody Sagiv. 1995. Demand Interprocedural Dataflow Analysis. In Proceedings of the ACM SIGSOFT Symposium on Foundations of Software Engineering (FSE). 104–115.
[29] John Kodumal and Alexander Aiken. 2004. The Set Constraint/CFL Reachability Connection in Practice. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI). 207–218.
[30] Tsvi Kopelowitz, Seth Pettie, and Ely Porat. 2015. Dynamic Set Intersection. In Algorithms and Data Structures, 14th International Symposium (WADS) (Lecture Notes in Computer Science, Vol. 9214). 470–481. doi:10.1007/978-3-319-21840-3_39
[31] Paraschos Koutris and Shaleen Deep. 2023. The Fine-Grained Complexity of CFL Reachability. Proc. ACM Program. Lang. 7, POPL, Article 59 (2023). doi:10.1145/3571252
[32] Kasper Green Larsen and Ryan Williams. 2017. Faster Online Matrix-Vector Multiplication. In Proceedings of the ACM-SIAM Symposium on Discrete Algorithms (SODA). https://arxiv.org/abs/1605.01695
[33] Lillian Lee. 2002. Fast Context-Free Grammar Parsing Requires Fast Boolean Matrix Multiplication. J. ACM 49, 1 (2002), 1–15. doi:10.1145/505241.505242
[34] Yuxiang Lei, Camille Bossut, Yulei Sui, and Qirun Zhang. 2024. Context-Free Language Reachability via Skewed Tabulation. Proceedings of the ACM on Programming Languages 8, PLDI, Article 221 (2024). doi:10.1145/3656451
[35] Yuxiang Lei, Yulei Sui, Shuo Ding, and Qirun Zhang. 2022. Taming Transitive Redundancy for Context-Free Language Reachability. Proceedings of the ACM on Programming Languages 6, OOPSLA2 (2022), 180:1–180:27.
[36] Yuxiang Lei, Yulei Sui, Shin Hwei Tan, and Qirun Zhang. 2023. Recursive State Machine Guided Graph Folding for Context-Free Language Reachability. Proceedings of the ACM on Programming Languages 7, PLDI (2023), 119:1–119:25.
[37] Yang P. Liu. 2024. On Approximate Fully-Dynamic Matching and Online Matrix-Vector Multiplication. arXiv:2403.02582 https://arxiv.org/abs/2403.02582v1
[38] Anders Alnor Mathiasen and Andreas Pavlogiannis. 2021. The Fine-Grained and Parallel Complexity of Andersen's Pointer Analysis. Proceedings of the ACM on Programming Languages 5, POPL, Article 34 (2021). doi:10.1145/3434315
[39] David Melski and Thomas Reps. 2000. Interconvertibility of a class of set constraints and context-free-language reachability. Theor. Comput. Sci. 248(1-2) (2000), 29–98.
[40] Radford Neal. 1989. The computational complexity of taxonomic inference. (1989). Unpublished manuscript. Available at http://www.cs.toronto.edu/~radford/ftp/taxc.pdf.
[41] Andreas Pavlogiannis. 2022. CFL/Dyck Reachability: An Algorithmic Perspective. ACM SIGLOG News 9, 4 (2022), 5–25. doi:10.1145/3583660.3583664
[42] Thomas Reps. 1998. Program Analysis via Graph Reachability. Information and Software Technology 40, 11–12 (1998), 701–726. doi:10.1016/S0950-5849(98)00093-7
[43] Thomas Reps, Susan Horwitz, and Moody Sagiv. 1995. Precise Interprocedural Dataflow Analysis via Graph Reachability. In Proceedings of the ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL). 49–61. doi:10.1145/199448.199462
[44] Wojciech Rytter. 1985. Fast Recognition of Pushdown Automaton and Context-Free Languages. Information and Control 67, 1–3 (1985), 12–22. doi:10.1016/S0019-9958(85)80024-3
[45] Micha Sharir and Amir Pnueli. 1981. Two Approaches to Interprocedural Data Flow Analysis. In Program Flow Analysis: Theory and Applications, Steven S. Muchnick and Neil D. Jones (Eds.). Prentice-Hall, 189–233.
[46] Leslie G. Valiant. 1975. General Context-Free Recognition in Less than Cubic Time. J. Comput. System Sci. 10, 2 (1975), 308–315. doi:10.1016/S0022-0000(75)80046-8
[47] Kai Wang, Aftab Hussain, Zhiqiang Zuo, Guoqing Xu, and Ardalan Amiri Sani. 2017. Graspan: A Single-Machine Disk-Based Graph System for Interprocedural Static Analyses of Large-Scale Systems Code. In Proceedings of the International Conference on Architectural Support for Programming Languages and Operating Systems (ASPLOS). 389–404.
[48] Ryan Williams. 2007. Matrix-Vector Multiplication in Sub-Quadratic Time (Some Preprocessing Required). In Proceedings of the ACM-SIAM Symposium on Discrete Algorithms (SODA). https://people.csail.mit.edu/rrw/mat-vec3.pdf
[49] Mihalis Yannakakis. 1990. Graph-Theoretic Methods in Database Theory. In Proceedings of the Ninth ACM SIGACT-SIGMOD-SIGART Symposium on Principles of Database Systems, April 2-4, 1990, Nashville, Tennessee, USA. ACM Press, 230-242.
[50] Huacheng Yu. 2018. An Improved Combinatorial Algorithm for Boolean Matrix Multiplication. Information and Computation 261 (2018), 240–247. Preliminary version in ICALP 2015.
[51] Qirun Zhang, Michael R. Lyu, Hao Yuan, and Zhendong Su. 2013. Fast Algorithms for Dyck-CFL-Reachability with Applications to Alias Analysis. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI). 435–446.
[52] Qirun Zhang, Xiao Xiao, Charles Zhang, Hao Yuan, and Zhendong Su. 2014. Efficient Subcubic Alias Analysis for C. In Proceedings of the ACM International Conference on Object Oriented Programming Systems Languages and Applications (OOPSLA). 829–845.
[53] Xin Zheng and Radu Rugina. 2008. Demand-Driven Alias Analysis for C. In Proceedings of the ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL). 197–208.
[54] Zhiqiang Zuo, Yiyu Zhang, Qiuhong Pan, Shenming Lu, Yue Li, Linzhang Wang, Xuandong Li, and Guoqing Harry Xu. 2021. Chianina: An Evolving Graph System for Flow- and Context-Sensitive Analyses of Million Lines of C Code. In Proceedings of the ACM SIGPLAN International Conference on Programming Language Design and Implementation (PLDI). 914–929.
Rupak Majumdar
Algorithm 2 The operations of one set-pair instance. REPORT scans the packed words of a group only when that group is live, and every live group contains an output. holds if and only if .
INSERT: If , return. Add to the packed set and to the pending list . If , call PROMOTE.
PROMOTE: the elements of in increasing order (packed difference). Cut at block boundaries; split each part into pieces of at most consecutive elements. For each group : a piece inside , added along a balanced tree of bit-plane additions. For each group : (one vector addition of counters). ; for each set entry of to one; .
PROMOTE: as above with , in place of , , and additionally for each group .
REPORT: Live ; . For each : if , add to Live. For each group : ; . For each : if , increment . For each group : if , add to Live. For each : append to the elements of , found by a packed scan of the words of . Return .
COUNT: Return .
A Pseudocode and a worked example
The appendix shows the pseudocode for the four operations on the set-pair structure (Algorithm 2) and a small saturation run in which the counts let one report finish without scanning any group.
A.1 Pseudocode
Algorithm 2 gives the four operations of one set-pair instance in the notation of Section 5. We write for the group containing coordinate , and and for the stored vectors of the tables and . PROMOTE is obtained from PROMOTE by exchanging the roles of the two families, with the two differences noted in its description. In Section 6, INSERT of Algorithm 1 calls INSERT of this algorithm on every instance containing the updated relation, and each difference of Algorithm 1 is one call to REPORT.
A.2 A worked saturation run
We trace one row instance on a small input. The parameters are chosen for readability, not from (8): eight vertices , two groups and , blocks equal to groups , sparsity , and promotion threshold . The grammar has the rules , and . The graph has the edges
listed in the order in which SATURATE inserts them. We follow the row instance of : its lines are the rows of , its lines are the rows of , and processing a fact asks for , that is, REPORT. The sparse table stores, for each block, the vectors of all nonempty with inside the block, ten vectors per block, each with eight counters (one per line) in bit planes.
Seeding. The two facts enter the worklist and do not touch this instance. The facts are forwarded as insertions into lines. Line receives 3 and 5; its pending list reaches , so PROMOTE runs with . The table is still all zero, so and stays zero; the promotion sets , , and records 3 and 5 in . Then receives 6, which stays pending: . Line receives 3 and 6 and is promoted the same way: , , . All lines are empty. After seeding, the table entries relevant below are
indexed by : coordinate 3 lies in and , coordinate 5 only in .
Processing : a report with outputs. REPORT computes . The pending element is not in , so is marked live. The counts are and ; the list is empty, so and both groups are live. The scan of returns 3 and the scan of returns 5 and 6. Both scans are productive. SATURATE now inserts , , and . The first two insertions fill to size , which triggers PROMOTE with . The sorted list is cut at the block boundary into the pieces and , whose vectors are read from :
These are added to column 0 of and , so now and , all other counters being zero. The promotion sets . This is the two-sided rule at work: the promotions came first and counted nothing, and the later promotion counted each shared element once. Finally is inserted and stays pending, .
Processing : an empty report without a scan. REPORT asks for , which is empty. The pending list is empty, so no group is marked. The counts are
The snapshot count for is positive because is not in the snapshot . The scan of finds , so and . No group is live. The report returns after reading six counters and two pending lists of total length one, without touching the packed words of either line. Without the correction , group would have been scanned for nothing, and that scan could not be charged to a new fact. As a check, , confirming .
The remaining facts. The five facts are processed next. For the rule they query the column instance, whose reports are all empty because every fact was already found above; they are handled exactly as the report just described. The worklist then contains , , and , which match no rule, and saturation ends with .