A Regularity Measure for Context Free Grammars

A Regularity Measure for Context Free Grammars
Notice: This research summary and analysis were automatically generated using AI technology. For absolute accuracy, please refer to the [Original Paper Viewer] below or the Original ArXiv Source.

Parikh’s theorem states that every Context Free Language (CFL) has the same Parikh image as that of a regular language. A finite state automaton accepting such a regular language is called a Parikh-equivalent automaton. In the worst case, the number of states in any non-deterministic Parikh-equivalent automaton is exponentially large in the size of the Context Free Grammar (CFG). We associate a regularity width d with a CFG that measures the closeness of the CFL with regular languages. The degree m of a CFG is one less than the maximum number of variable occurrences in the right hand side of any production. Given a CFG with n variables, we construct a Parikh-equivalent non-deterministic automaton whose number of states is upper bounded by a polynomial in $n (d^{2d(m+1)}), the degree of the polynomial being a small fixed constant. Our procedure is constructive and runs in time polynomial in the size of the automaton. In the terminology of parameterized complexity, we prove that constructing a Parikh-equivalent automaton for a given CFG is Fixed Parameter Tractable (FPT) when the degree m and regularity width d are parameters. We also give an example from program verification domain where the degree and regularity are small compared to the size of the grammar.


💡 Research Summary

The paper addresses the classic problem raised by Parikh’s theorem: every context‑free language (CFL) has the same Parikh image as some regular language, yet constructing a Parikh‑equivalent nondeterministic finite automaton (NFA) can require a number of states exponential in the size of the underlying context‑free grammar (CFG). The authors introduce two structural parameters of a CFG—regularity width d and degree m—and show that, when these parameters are small, a Parikh‑equivalent NFA can be built with a number of states that is only polynomial in n·d^{2d(m+1)}, where n is the number of variables of the grammar. Consequently, the construction is Fixed‑Parameter Tractable (FPT) with respect to the pair (d, m).

Key definitions.

  • The degreem of a CFG is one less than the maximum number of variable occurrences on the right‑hand side of any production.
  • The reminder graph R(G) of a CFG G has a vertex for each variable. An edge (A_i, A_j) is added whenever A_i and A_j appear together in the right‑hand side of some production, and additionally for any variable A_i that can reach another variable A′ (via the transitive closure of the “→” accessibility relation) while A_j also appears in the same production.
  • The regularity width d is defined as the treewidth of R(G) plus one. Regular grammars have treewidth 0, hence d = 1.

Intuitively, the reminder graph captures the “simultaneous obligations” that an automaton must remember while simulating a parse tree: if two variables may need to be processed later, the automaton must keep track of both. A small treewidth means that only a bounded number of such obligations can coexist, which directly limits the number of distinct configurations the automaton must distinguish.

Automaton construction.
The authors introduce reminder pairs (A, v), where A∈V∪{⊥} is the current variable (or a special sink ⊥) and v is a multiset over V representing variables that still have to be processed later. A reminder sequence is a finite list of reminder pairs; each such sequence is a state of the constructed NFA, provided that no variable occurs more than twice in the sequence. The transition relation mirrors the productions of the grammar:

  1. If the current pair is (A, ∅) and A→w₀A₁w₁…A_rw_r is a production, the automaton consumes the terminals w₀…w_r and replaces the pair with (A_j, {A₁,…,A_r}{A_j}) for each j.
  2. If the current pair is (A, v) with v≠∅, the same expansion is performed while preserving v.
  3. When a production has no variables on the right‑hand side, the automaton moves to the sink (⊥, ∅).
  4. Additional rules allow “popping” a variable from the multiset v and making it the current variable.

A crucial invariant (Lemma 7) shows that the set of variables appearing in any prefix of a reminder sequence induces a clique in the reminder graph. Because the reminder graph’s treewidth is d − 1, any such clique has size at most d·(m+1). Consequently, the number of possible reminder sequences—and thus the number of NFA states—is bounded by O(n·d^{2d(m+1)}). The exponent 2d(m+1) is a constant for fixed d and m, so the construction runs in time polynomial in the output size, establishing an FPT algorithm.

Complexity and parameterized perspective.
The result can be expressed as: given a CFG with n variables, degree m, and regularity width d, one can construct a Parikh‑equivalent NFA with at most f(d,m)·poly(n) states, where f(d,m)=d^{2d(m+1)}. This places the problem in the class FPT with respect to the combined parameter (d,m), contrasting with the general case where the state blow‑up is exponential in n.

Application to program verification.
The paper illustrates the practical relevance by considering concurrent programs modeled as CFGs. Each subroutine call and synchronization point is represented by a “port” variable. The reminder graph then contains edges only between ports and control locations, yielding a treewidth equal to the number of ports plus one. Since real programs typically have a modest number of ports, the regularity width d remains small, and the constructed automaton is dramatically smaller than the worst‑case exponential bound.

Related work and contributions.
Earlier work


Comments & Academic Discussion

Loading comments...

Leave a Comment