Introduction
In modern computational tasks involving XML processing, theorem proving, and logic programming, trees serve as a foundational data structure. However, the scale of these trees can frequently reach millions of nodes, exceeding the physical memory limits of standard hardware. While compression techniques such as Directed Acyclic Graphs (DAGs) and Singleton Tree Grammars (STGs) can significantly reduce the memory footprint—often to less than 3% of the original size—most existing algorithms require full decompression before any meaningful processing can occur. This decompression step negates the primary benefits of compression, especially when the expanded tree is too large to fit in RAM.
This paper addresses the challenge of performing First-Order Unification—the process of finding a variable substitution that makes two terms identical—directly on grammar-compressed terms. The authors introduce Unif-STG, a tool designed to execute unification and matching algorithms on STGs without the need for prior decompression.
Methodology
Singleton Tree Grammars (STGs)
STGs represent a powerful generalization of DAGs. While DAGs achieve compression by sharing identical subtrees, STGs can share identical "tree patterns" or connected subgraphs. This allows for much higher compression ratios, particularly in highly repetitive structures like XML documents. However, the compact nature of STGs presents a computational challenge: a small grammar can represent a tree of exponential size, making standard tree navigation via absolute positions prohibitively expensive.
Algorithmic Innovations
To overcome the limitations of standard tree traversal, the authors implemented several key strategies:
- Preorder Traversal Indexing: Instead of relying on traditional tree positions, the algorithm operates on indices within the preorder traversal of the tree. This allows the system to efficiently locate the "first difference" between two terms, a critical step in the unification process.
- Equality Testing: Unification requires frequent checks for term equality. The authors compared three distinct approaches:
- Lifshits’ Algorithm: A classical, exact algorithm with cubic-time complexity.
- Randomized Fingerprinting: Based on the work of Schmidt-Schauß and Schnitger, this linear-time probabilistic approach uses polynomial rolling hashes and modular arithmetic to detect inequalities.
- Randomized with Primes: A refinement of the fingerprinting method using prime numbers to further minimize the probability of hash collisions.
The tool is integrated with TreeRePair, a state-of-the-art grammar-based tree compressor, ensuring it can handle real-world compressed data formats.
Experimental Evaluation
The authors evaluated Unif-STG using several synthetic datasets designed to simulate various structural "corner cases":
- Bin(n): Full binary trees.
- Mon(n): Monadic (path-like) trees, mirroring the "first-child/next-sibling" encoding common in XML.
- Meta: A generator for trees with randomized heights and variable distributions to test general unifiability.
- 3-Stack: Instances where the unification result is significantly deeper than the input terms.
Key Results
The experiments revealed a clear "break-even" point for compressed unification. For terms exceeding 100,000 nodes that exhibit high compressibility, the STG-based approach consistently outperformed standard tree-based unification (tUnif).
On monadic trees with 200,000 nodes, the randomized STG algorithm completed unification in just 10ms, whereas the standard tUnif required 232ms. Furthermore, as tree sizes increased in the Bin dataset, tUnif execution times grew exponentially, while the STG-based algorithms scaled linearly relative to the size of the grammar rather than the size of the expanded tree.
The randomized equality tests proved to be the most efficient in practice. Despite their probabilistic nature, no false positives (incorrectly identifying unequal terms as equal) were observed during the extensive testing phase. In contrast, the exact Lifshits algorithm was significantly slower and frequently encountered memory or bound limits on larger instances.
Discussion and Limitations
The primary advantage of the STG approach is the "speed-up" property: by processing repeated structures only once, the algorithm achieves a performance gain proportional to the compression ratio. However, this approach is not a universal solution. For incompressible data where the grammar size approaches the tree size, the overhead of managing grammar rules can make the STG approach up to 100x slower than uncompressed methods.
Conclusion
The research demonstrates that first-order unification on compressed terms is not only theoretically possible but practically superior for large, repetitive data structures. Future work includes extending optimizations for high-arity non-terminals, integrating the tool into logic programming languages like Xcerpt, and developing methods for dynamic updates to STGs to support real-time data modification without full re-compression.
Summary updated