On $k$-piecewise testability (preliminary report)

Tomás Masopust, Michaël ThomazoarXiv 2014

Introduction

In formal language theory, the "simplicity" of a regular language can be characterized by its membership in specific subclasses of regular languages. One such subclass is the set of piecewise testable (PT) languages. A language is piecewise testable if membership can be determined solely by the presence or absence of subwords (pieces) within a string, where a subword is a sequence of characters that appear in the string in the correct order but not necessarily contiguously.

A language is defined as $k$-piecewise testable ($k$-PT) if the maximum length of these subword sequences is $k$. While the general problem of deciding if a language is PT has been understood for decades, determining the minimal $k$ for which a language is $k$-PT is a more complex challenge. This problem has significant practical implications, particularly in the simplification of XML Schema definitions. By reducing a schema to a $k$-PT representation with a low $k$ value, developers can create more human-readable and maintainable definitions, such as those used in the BonXai language.

Complexity Landscape

This research provides a comprehensive mapping of the computational complexity involved in deciding $k$-piecewise testability. The complexity varies significantly depending on the representation of the input (Deterministic Finite Automata vs. Nondeterministic Finite Automata) and the value of $k$.

Complexity for DFAs

For languages represented by a DFA, the complexity of determining $k$-testability scales with $k$:

  • $k=0$: Decidable in $O(1)$ time.
  • $k=1$: Decidable in LOGSPACE.
  • $k=2, 3$: Found to be NL-complete.
  • Fixed $k \ge 4$: The problem is in co-NP. While this preliminary report places it in co-NP, subsequent observations suggest it may be co-NP-complete.

Complexity for NFAs

When the input is an NFA, the problem becomes significantly more difficult. The authors demonstrate that deciding $k$-piecewise testability for NFAs is PSPACE-complete for any fixed $k \ge 0$. This highlights a stark contrast in the computational resources required when moving away from deterministic representations.

Structural Analysis and DFA Depth

A core contribution of this work is the investigation of the relationship between the structural depth of an automaton (the length of its longest simple path) and the testability level $k$.

The Depth Bound

Previously, it was understood that a PT language is $k$-PT if $k$ is at least the depth of its minimal DFA. However, this research reveals that this bound is often inefficient. The authors prove that for a $k$-PT language over an alphabet of size $n$, the depth of the minimal DFA is at most:

$$\binom{k+n}{k} - 1$$

This formula exhibits a fascinating symmetry: increasing the length of the subwords ($k$) has the same combinatorial effect on the maximum possible DFA depth as increasing the size of the alphabet ($n$). Using Stirling cyclic numbers and binomial coefficients, the authors demonstrate that this bound is tight, meaning there exist specific "worst-case" automata that reach this limit exactly.

The Exponential Gap

The paper identifies a massive gap between the minimal $k$ and the automaton's depth. Specifically, the authors constructed a family of $n$-PT languages that require an NFA of depth $n-1$ but result in a minimal DFA of depth $2^n - 1$. This proves that the minimal $k$ can be exponentially smaller than the depth of the corresponding minimal DFA, suggesting that depth is a poor proxy for $k$ in many instances.

Generalization to NFAs

Beyond complexity bounds, the authors extend the structural characterization of PT languages. The classic characterization—which requires a language to be partially ordered and "confluent"—is shown to generalize from DFAs to "complete" NFAs. This theoretical bridge allows for a more unified understanding of piecewise testability across different automaton models.

Conclusion and Future Directions

This report clarifies the complexity of $k$-piecewise testability and provides tight combinatorial bounds on the size of the recognizing structures. However, several avenues for future work remain. While the complexity for $k \ge 4$ is narrowed to co-NP, further refinement is needed to settle its exact status. Additionally, while PT languages have been generalized to tree structures, the specific $k$-testability problem for trees remains an open area for similar rigorous analysis. Finally, the development of practical, optimized algorithms based on these complexity bounds would be a valuable step for XML schema optimization tools.

Summary updated

BibTeX
@misc{masopust2014k,
  author = {Tomás Masopust and Michaël Thomazo},
  title = {{On $k$-piecewise testability (preliminary report)}},
  year = {2014},
  eprint = {1412.1641},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1412.1641},
}
Figure