NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Complexity of Problems for Commutative Grammars

Eryk Kopczynski

Introduction

In formal language theory, the order of symbols in a string is typically paramount. However, many computational systems—ranging from resource-tracking models to specific XML schemas—are order-independent. This paper investigates the computational complexity of problems related to commutative grammars, where strings are treated as multisets. In this setting, we analyze the Parikh image of a language, transforming strings into points in a $d$-dimensional space, where $d$ represents the size of the alphabet.

The Problem Context

Standard grammars allow for the encoding of large alphabets into binary ones (e.g., using sequences like "01" and "011"). In commutative grammars, this reduction is impossible because "011" and "101" are identical multisets. Consequently, every additional character in the alphabet introduces a literal new dimension to the problem. This dimensionality makes many problems that are tractable in standard formal languages significantly more difficult in the commutative domain.

This research addresses the complexity of membership, equivalence, and disjointness for both regular and context-free commutative grammars. It specifically focuses on the impact of a fixed alphabet size $d$ versus an unfixed alphabet.

Methodology

The author utilizes a combination of graph theory and linear algebra to analyze "commutative runs." Key techniques include:

  1. Euler Conditions: Rather than constructing full derivation trees, the author employs the Euler condition—ensuring each state is entered as many times as it is exited—to verify if a multiset of transitions constitutes a valid commutative run.
  2. Skeleton and Cycle Decomposition: Long runs are decomposed into a "skeleton" (a core path) and a set of "simple cycles" (loops). For regular grammars, these components are bounded polynomially relative to the grammar size.
  3. Geometric Interpretation: By viewing multisets as vectors in $\mathbb{N}^d$, the author applies linear algebraic tools, such as Cramer’s rule and determinant properties, to demonstrate that large multisets can be represented as a combination of a small base run and several extreme cycles.
  4. A, B-frames: For the specific case of a two-letter alphabet ($d=2$), the author introduces "A, B-frames," a geometric method to represent reachable multisets as a union of linear sets shifted in two directions.

Key Insights and Results

The Impact of Fixed Alphabet Size

A primary finding is that the size of the alphabet is the determining factor for complexity. For regular grammars over a fixed alphabet, membership and disjointness tests can be performed in polynomial time (P). This is a significant reduction from the NP-complete complexity encountered when the alphabet size is part of the input.

The $d=2$ vs. $d=3$ Threshold

The research highlights a sharp complexity jump between two and three letters:

  • Two Letters ($d=2$): The "extreme cycles" (those with the highest ratio of letter $a$ to $b$ and vice versa) are sufficient to describe the entire language, allowing for an efficient normal form representation.
  • Three Letters ($d=3$): The author proves that the polynomial representation used for two letters fails. A context-free grammar with three letters can generate a "cone" with an exponential number of edges, meaning it cannot be covered by a polynomial number of simple frames.

Complexity Summary

The paper establishes several tight bounds, summarized below:

Grammar Type Problem Fixed Alphabet ($d$) Unfixed Alphabet
Regular Membership P NP-complete
Regular Disjointness P coNP-complete
Context-Free Membership NP-complete NP-complete
Context-Free Equivalence $\Pi^P_2$-complete $\Pi^P_2$-hard / coNEXPTIME

Significant theorems include Theorem 5.3, which places membership for regular commutative grammars over a fixed alphabet in P, and Theorem 6.3, which proves that inclusion/equivalence for context-free commutative grammars over a 2-letter alphabet is $\Pi^P_2$-complete.

Conclusion and Future Work

While this paper provides a systematic analysis of commutative grammar complexity, several gaps remain. For context-free grammars with an unfixed alphabet, the exact complexity of the equivalence problem remains wide, bounded between $\Pi^P_2$-hard and coNEXPTIME. Additionally, the universality problem for context-free grammars (determining if a grammar generates all possible multisets) is known to be in $\Pi^P_2$, but the current lower bound is only coNP. The author suggests that the techniques developed here—specifically the use of "negative" transitions during intermediate algorithmic steps—may be applicable to a broader theory of commutative structures.

Summary updated

BibTeX
@inproceedings{kopczynski2015complexity,
  author = {Eryk Kopczynski},
  title = {{Complexity of Problems for Commutative Grammars}},
  booktitle = {Log. Methods Comput. Sci},
  year = {2015},
  url = {https://openreview.net/forum?id=TmFspZ7fcc5},
}
Figure