Papers
Topics
Authors
Recent
Search
2000 character limit reached

Equality Graphs: Structure & Applications

Updated 14 April 2026
  • Equality graphs are specialized data structures that represent many equivalent expressions using e-classes and e-nodes to enforce congruence.
  • They employ union-find based algorithms and e-matching techniques to perform equality saturation efficiently for term rewriting and program optimization.
  • Advanced extensions such as colored E-graphs and abstract interpretation enhance conditional reasoning, memory efficiency, and integration with compiler frameworks.

An equality graph (E-graph) is a data structure that compactly and efficiently represents many expressions together with their known equivalences under a congruence relation. E-graphs have become foundational in equality saturation (EqSat), term rewriting, program optimization, automated reasoning, and related disciplines. Recent theoretical and engineering advances have broadened their application scope and clarified deep algebraic connections.

1. Mathematical Structure and Semantics

At its core, an E-graph is a hierarchical, typically acyclic, directed structure over a signature Σ of function symbols. The main components are e-classes (sets of terms known to be equivalent), e-nodes (function applications referencing child e-classes), and mechanisms to maintain congruence—usually implemented via union-find structures on e-class identifiers. Formally, given Σ and a set of term identifiers, an E-graph G can be defined as follows:

  • E-nodes: Each n=(f,[c1,…,ck])n = (f, [c_1, \ldots, c_k]) is a node labeled by f∈Σf \in \Sigma with child e-class ids.
  • E-classes: Disjoint sets of e-nodes under G’s current congruence, each assigned a unique id.
  • Equivalence: Two terms are equivalent in G iff they are represented in the same e-class.

E-graphs are required to satisfy the congruence invariant: if two e-nodes have function ff and their respective argument e-classes are equivalent pointwise, the nodes reside in the same e-class. This ensures closure under function application (Willsey et al., 2020, Cheli et al., 2024).

Recent semantics formalize E-graphs as deterministic reachable tree automata representing partial congruence relations over terms (Suciu et al., 5 Jan 2025). Every such partial congruence corresponds uniquely to an E-graph up to isomorphism. Categorical approaches capture E-graphs as morphisms in semilattice-enriched (symmetric-)monoidal categories, explaining the algebraic behavior of joins (equivalence class unions) as semilattice operations (Tiurin et al., 1 May 2025, Tiurin et al., 2024, Biondo et al., 17 Mar 2025).

2. Core Algorithms and Data Structures

The centerpiece of E-graph algorithms is the management of equivalence classes through rewriting. This typically involves three phases:

  1. Construction: Insert initial terms bottom-up by hash-consing e-nodes and allocating singleton e-classes.
  2. Saturation (Equality Saturation): Apply rewrite rules in bulk using e-matching, which finds all instances where a pattern can be applied modulo current equivalence. For each match, right-hand sides are inserted and merged, with congruence maintenance.
    • Invariant restoration is efficiently implemented by deferred rebuilding: merging is batched, and congruence/structural properties are repaired in a single traversal, collapsing redundant upward merges (Willsey et al., 2020, Cheli et al., 2024).
  3. Extraction: Select optimal representatives (e.g., minimal-cost terms) from saturated E-classes by solving a bottom-up dynamic programming problem over the e-graph's structure.

Union-find (with path compression and union by rank) supports efficient e-class merging, yielding effective near-constant time complexity per operation (amortized O(α(N))O(\alpha(N)), with α\alpha the inverse Ackermann function) (Cheli et al., 2024).

Procedures for maintaining and exploiting the congruence closure include hash-consing for e-node uniqueness, worklists for deferred repairs, and e-class analyses for integrating semantic properties (e.g., constant folding, interval abstractions, custom analyses) (Willsey et al., 2020, Coward et al., 2022).

3. Extensions: Case Splitting and Conditional Reasoning

Standard E-graphs are effective for universally quantified equality reasoning but are inefficient for case splitting or managing multiple inconsistent assumptions. Ad hoc cloning (creating a full copy per assumption) is impractical for large-scale reasoning.

Colored E-graphs address this by introducing overlay union-find layers—one per "color" or assumption—on a shared term and e-node base structure. Each color corresponds to a sequence of coarsenings of the original congruence relation; merges or congruence closures induced by assumptions are recorded independently. This achieves substantial space savings, supporting hundreds of assumptions and millions of terms with an order of magnitude reduction in overhead compared to naive cloning (Singher et al., 2023). Modified e-matching and congruence checks are color-aware, ensuring conditional rewrites and forked reasoning remain tractable.

Empirical results show that optimized colored E-graphs reduce per-assumption overhead by ≈10×\approx 10 \times (to 100–200 e-nodes/assumption), keep peak memory usage up to 10×10 \times lower, and incur only minor computational overhead versus naive cloning (Singher et al., 2023).

4. Integration with Analyses, Abstract Interpretation, and Higher Structure

E-graphs are augmented with domain-specific analyses to improve rewrite applicability and sharpen the characterization of equivalence. The e-class analysis framework equips every e-class with attributes in a join-semilattice (e.g., constants, ranges, abstract values) (Willsey et al., 2020). These values are updated by custom transfer/join operations triggered on merges and undergoing rebuilding alongside congruence maintenance.

Integrating abstract interpretation enables conditional rewriting: side-conditions for rewrite rules (e.g., invertibility, non-zeroness) can be checked inside the lattice of abstract values. For example, interval abstraction propagates through the e-graph, unlocking rewrites when conditions like x≠0x \neq 0 are inferred for entire equivalence classes (Coward et al., 2022).

Higher-order and binding-intensive domains, such as the lambda calculus, motivate categorical and hypergraph representations. E-graphs with bindings systematically generalize equality saturation to terms with variable binding by interpreting e-graphs as morphisms in semilattice-enriched closed symmetric monoidal categories, combinatorially realized as hierarchical hypergraphs with nested equivalence (join) and binding (lambda) boxes (Tiurin et al., 1 May 2025). Rewriting is implemented as Double-Pushout with Interface (DPOI) transformations, maintaining soundness and completeness with respect to ordinary term rewriting.

5. Applications and Impact

E-graphs underpin a diverse set of systems across program transformation, synthesis, reasoning, and symbolic computation:

  • Equality saturation: Used in compilers and superoptimizers to systematically apply large sets of rewrites and enable phase-ordering-agnostic optimizations. Key case studies (e.g., Herbie, Spores, Szalinski) report orders-of-magnitude runtime reductions using modern E-graph libraries (Willsey et al., 2020).
  • Symbolic regression: In genetic programming, E-graphs record all previously seen (or equivalent) expressions, enabling avoidance of redundant evaluation and improving model diversity (Franca et al., 29 Jan 2025).
  • Obfuscation: Equality-expanding E-graphs facilitate the automatic generation of extremely large and complex MBA expressions in code obfuscation, offering new levels of structural diversity at fixed equivalence (Lee et al., 4 Mar 2026).
  • Proof automation: Integration into theorem provers (e.g., Lean) efficiently automates equational reasoning involving higher-order logic, variable binding, and type systems (Rossel et al., 2024, Tiurin et al., 1 May 2025).
  • Compiler frameworks: E-graphs have been embedded as first-class abstractions in compiler IRs (e.g., the eqsat dialect for MLIR), enabling persistent and multi-level equality tracking throughout program transformation pipelines (Merckx et al., 18 Feb 2026).

6. Recent Theoretical Developments

Recent research has established foundational connections:

  • Automata-theoretic semantics: E-graphs correspond to deterministic, reachable tree automata representing the partial congruence relation on terms. Equality saturation is provably the least fixpoint of an inflationary, monotone immediate consequence operator over this structure (Suciu et al., 5 Jan 2025).
  • Category theory and graph rewriting: E-graphs are morphisms in semilattice-enriched (Cartesian/monoidal/closed) categories; the structure of e-classes arises from semilattice joins. Hypergraph formalisms equipped with equivalence boxes encode these structures combinatorially, enabling adhesive-category rewriting theory, sound and complete DPOI rewriting, and concurrent update/confluence analysis (Tiurin et al., 2024, Biondo et al., 17 Mar 2025, Tiurin et al., 1 May 2025).
  • Termination and complexity: Termination of equality saturation on a given term or E-graph is undecidable in the general case and exhibits RE-complete/Π₂-complete complexity depending on the instance class. Effective syntactic acyclicity criteria for guaranteed termination have been established (Suciu et al., 5 Jan 2025).

Contemporary E-graph libraries (e.g., egg in Rust, Metatheory.jl in Julia) achieve competitive or near-competitive performance with sophisticated scheduling, structural specialization, and integration into dynamic and statically checked languages (Cheli et al., 2024, Willsey et al., 2020). MLIR-based dialects such as eqsat enable cross-layer optimization strategies that retain equivalence information persistently through compilation passes (Merckx et al., 18 Feb 2026). Dynamic optimization strategies—pattern compilation, cost modeling, caching, and parallelization—are actively improving scalability for codebases involving millions of terms and hundreds of assumptions.

Quantitative evidence demonstrates that modern E-graph systems can outperform or match prior superoptimizers and regression engines, with up to 10×10\times memory savings and negligible run-time regression in advanced use cases such as conditional reasoning, symbolic regression, and theorem proving (Singher et al., 2023, Franca et al., 29 Jan 2025, Rossel et al., 2024). The categorical, automata-theoretic, and adhesive perspectives provide robust theoretical guarantees and avenues for further extension to richer equational theories, program logics, and concurrency.


References:

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Equality Graphs (E-graphs).