E-Graphs: Equality Saturation & Optimization
- E-graphs are compact representations that group equivalent expressions using e-nodes and e-classes, enabling non-destructive equality saturation.
- They facilitate compiler optimizations and precise analyses by preserving a large search space of rewrites through techniques like hash-consing and union-find.
- Integrated methods such as conditional rewriting, abstract interpretation, and theory-specific canonization make e-graphs powerful for equational reasoning and semantic precision.
E-graphs, in the modern equality-saturation sense, are a compact representation of many equivalent expressions at once. They generalise the typical DAG representation of terms to include equivalence classes: e-nodes encode function applications, e-classes collect e-nodes known to be equal, and congruence closure ensures compatibility of equality with function symbols. As the substrate for equality saturation, an e-graph accumulates rewrite consequences non-destructively, thereby preserving a large search space of equivalent expressions until a later extraction step chooses a representative (Cheli et al., 2024, Singher et al., 2023). This usage is distinct from unrelated meanings such as “elastic graphs” in geometric topology and graph-theoretic “e-positivity” in chromatic symmetric function theory (Thurston, 2016, Foley et al., 2018).
1. Core representation and invariants
Formally, an e-graph can be described as representing a set of terms together with a congruence relation . The defining closure property is that equality must be stable under function application:
In implementation terms, an e-node is an operator applied to child e-classes, and an e-class is a collection of e-nodes represented using a union-find. Variables and constants appear as zero-arity e-nodes, while non-zero-arity operations are represented by e-nodes composed of a function symbol and a list of children e-classes (Singher et al., 2023, Merckx et al., 18 Feb 2026).
Practical systems typically combine a hash-cons table mapping canonical e-nodes to e-class IDs, a union-find for merged e-classes, and an e-class map storing nodes and parent links. This organization is what allows many terms to share structure while still supporting large-scale congruence closure. It also explains why e-graphs are well suited to equational reasoning over ground terms: the data structure stores a whole set of terms modulo equality rather than a single rewritten term (Singher et al., 2023, Zucker, 19 Apr 2025).
A union can invalidate canonicality. If two e-classes are merged, parent nodes that were previously distinct may become congruent, which can cascade through the graph. Standard practice is therefore to rebuild the e-graph after batches of rewrites. Deferred rebuilding, emphasized in egg-style systems, amortizes these updates; compiler-oriented systems adopt the same idea to restore the congruence invariant after constructive rewriting (Singher et al., 2023, Merckx et al., 18 Feb 2026).
2. Equality saturation and extraction
Equality saturation is the algorithmic regime in which e-graphs are most commonly used. The standard workflow is: start with an initial expression, insert it into an e-graph, repeatedly e-match rewrite rules against the whole graph, add the resulting expressions, merge equalities as discovered, continue until a limit or saturation criterion is reached, and then extract the cheapest expression from each relevant e-class (Cheli et al., 2024). The essential methodological shift is that rewrites are non-destructive: the system does not replace one term with another, but accumulates both.
This non-destructive behavior addresses the phase-ordering problem. Rather than committing early to one rewrite path, the e-graph keeps many equivalent forms simultaneously and defers commitment until extraction. In compiler settings, this is precisely the attraction of equality saturation: equalities discovered at one point can remain available for later optimization decisions instead of being discarded after a destructive pass (Merckx et al., 18 Feb 2026).
Extraction turns the saturated equivalence space into a concrete result. In the standard additive setting, the objective is to minimize
where is the selected extraction. This optimization problem is not merely an implementation detail: optimal extraction is NP-hard (Sun et al., 2024). Consequently, practical systems rely either on heuristic cost-guided extraction or on exact methods that exploit additional structure, such as treewidth, discussed in later research.
3. Analysis, conditions, and reasoning under assumptions
E-graphs need not be limited to concrete equivalence. A central development is the integration of abstract interpretation with e-class analysis. In that setting, each e-class is assigned an abstract value, and the abstraction of a class is the meet over the abstractions of its member e-nodes:
$\mathcal{A}\llbracket s \rrbracket = \bigsqcap_{n\in \mathcal{N}_s} \mathcal{A}\llbracket n \rrbracket.$
For interval arithmetic, the meet is intersection. This makes an e-class a natural site for precision refinement: multiple equivalent expressions can yield different sound over-approximations of the same quantity, and intersecting them produces a tighter bound (Coward et al., 2022, Coward et al., 2022).
The interval example and illustrates the point. Ordinary interval arithmetic yields
whereas rewrite knowledge gives , hence the tighter interval 0. On 40 FPBench benchmarks, e-graph rewriting plus interval analysis increased node count by 4% on average, up to 84%; the resulting intervals were on average 85% of the width of the naive interval approximation; and runtime overhead from interval analysis was less than 1% on average (Coward et al., 2022). This suggests that e-graphs can act not only as rewrite engines but also as semantic precision amplifiers.
Conditional rewriting sharpens this interaction further. Many practically useful rewrites are valid only under domain restrictions, such as 1 when 2. Abstract interpretation supplies the proof obligations needed to fire such rules during e-graph growth, while the enlarged e-graph in turn produces tighter abstractions that unlock deeper rewrites (Coward et al., 2022). In RTL optimization, this idea is made explicit through an ASSUME operator with semantics
3
allowing sub-domain equivalence to be reduced to ordinary e-graph equivalence. In that setting, the combined system automatically discovered known floating-point architectures and generated up to 33% faster and 41% smaller circuits (Coward et al., 2023).
A separate line of work addresses multiple inconsistent assumptions. Standard e-graphs are weak at case splitting because one branch typically requires a separate cloned structure. Colored E-Graphs replace this duplication with one shared structure that represents several coarsened congruence relations at once. The result is a memory-efficient equivalent of multiple copies of an e-graph, with support for hundreds of assumptions and millions of terms, space requirements that are an order of magnitude lower, and similar time requirements (Singher et al., 2023).
4. Beyond expression equivalence: control-flow graphs
Classical e-graphs are most natural for tree-like or DAG-like expressions. Recent work argues that this model does not naturally extend to arbitrary control-flow graphs, where optimization is usually destructive and therefore sensitive to pass ordering. E-Path addresses this gap by acting as a CFG-oriented analogue of an e-graph: instead of recording congruence between individual expressions, it records equivalence between instruction sequences or control-flow regions embedded in a CFG (Garcia, 27 May 2026).
The basic unit is an E-Sequence
4
where each 5 is a basic block in a CFG 6. Equivalence is introduced by validated CFG rewrite rules, and the representation is monotonic: existing sequences are never modified, and every rewrite adds a new equivalent sequence. This preserves multiple program variants simultaneously, including loop-containing and loop-transformed forms (Garcia, 27 May 2026).
The paper’s loop-invariant code motion example makes the analogy to expression-level equality saturation explicit. Rather than destructively moving invariant code out of a loop, E-Path keeps both the original and the hoisted version in the same equivalence space. LICM is expressed as the rewrite
7
and extraction then selects among globally available CFG variants. The prototype is instantiated over a restricted ANF-based CFG in the Crabstar backend, but the model is presented as IR-agnostic in intent (Garcia, 27 May 2026).
5. Variables, bindings, and theories
Standard e-graphs are strong for ground terms but struggle with variable binding. In languages such as the 8-calculus, sharing is entangled with scope, 9-equivalence, and capture-avoiding substitution. “E-Graphs With Bindings” extends the categorical account of e-graphs from semilattice-enriched symmetric monoidal categories to closed symmetric monoidal categories, adding the structure needed to model abstraction and application. The resulting combinatorial representation uses hierarchical hypergraphs and a corresponding DPO rewriting mechanism, and establishes the equivalence of term rewriting and DPO rewriting while absorbing the equations of the symmetric monoidal category into the representation itself (Tiurin et al., 1 May 2025).
A more operational treatment of variables appears in lifting e-graphs. Here context is treated as part of the term representation rather than external bookkeeping. The structure replaces plain e-class identifiers with “fat” identifiers carrying thinning bitvectors, uses lift-pulling smart constructors, and equips union-find with thinning awareness. The stated goal is support for rigid 0 canonical variables, with the central intuition that the surrounding context is part of what a term is, not merely where it is (Zucker, 22 Jun 2026). This line of work is explicitly inspired by slotted e-graphs and Co-de Bruijn syntax.
E-graphs modulo theories push in another direction. The motivating problem is that generic e-graph rewriting can handle identities such as associativity and commutativity declaratively, but often less efficiently than bespoke routines for sets, multisets, linear expressions, polynomials, and binders. The proposed EMT approach combines bottom-up e-matching with semantic e-ids, generalizing union-find into a theory-specific canonizer. The paper contrasts top-down matching of approximate cost
1
with bottom-up matching of approximate cost
2
and argues that bottom-up matching is more compatible with theory-rich canonicalized data (Zucker, 19 Apr 2025). The result is a pragmatic route toward integrating e-graphs with AC reasoning, linear algebra, Gröbner-basis-like normalization, and related theories.
6. Compiler integration and software ecosystems
One major trend is to make e-graphs native compiler objects rather than external optimization tools. “E-Graphs as a Persistent Compiler Abstraction” proposes an MLIR dialect, eqsat, built on xDSL. The dialect introduces eqsat.eclass, eqsat.const_eclass, eqsat.egraph, and eqsat.yield, allowing the e-graph itself to persist in compiler IR across passes. Rewriting is reinterpreted constructively rather than destructively, congruence is restored by rebuilding, and extraction is split into separate selection and replacement passes. The stated effect is to let equality saturation coexist with lowering, inlining, and analyses across multiple abstraction levels in a single MLIR flow (Merckx et al., 18 Feb 2026).
At the library level, Metatheory.jl presents a pure Julia implementation of e-graphs and equality saturation. It follows the standard pipeline of construction, matching, saturation, and extraction, but integrates directly with Julia syntax and with custom symbolic types through TermInterface.jl. Its rule language distinguishes equational rules (==), dynamic rules (=>), and directed rules (-->). The paper reports up to 226× speedup on simple propositional theorem-proving tasks and about 41× speedup on average across the benchmarks for EqSat time, while maintaining direct integration with a dynamic, high-level host language (Cheli et al., 2024).
A complementary ecosystem effort is Egglog Python, which exposes Python bindings for the experimental egg-smol library. The design provides both a lower-level API and a higher-level Pythonic API, implemented with PyO3, and emphasizes Python functions, classes, methods, type annotations, operator overloading, Jupyter compatibility, and static-analysis support from MyPy and PyLance. Typed variables are required, and rewrites are intended to be type-checked. The broader significance is to make e-graphs accessible for optimization, synthesis, and verification in the Python scientific-computing and machine-learning ecosystem (Shanabrook, 2023).
7. Formal semantics and exact algorithms
Recent work has supplied increasingly explicit mathematical foundations for e-graphs. “Equivalence Hypergraphs: DPO Rewriting for Monoidal E-Graphs” interprets e-graphs categorically as morphisms in semilattice-enriched categories and then generalizes from Cartesian categories to monoidal categories. In this semantics, the join
3
models the equivalence-class structure, and composition and tensor distribute over 4. The concrete syntax is given by e-hypergraphs, a hierarchical generalization of hypergraphs, and the paper proves a sound and complete rewriting account via convex EDPOI rewriting (Tiurin et al., 2024). This matters because it relocates e-graphs from a compiler-specific trick to a general rewriting formalism for monoidal theories.
Extraction has also been reanalyzed structurally. “E-Graphs as Circuits, and Optimal Extraction via Treewidth” shows that an e-graph can be translated into a weighted cyclic monotone circuit in which each e-class becomes an OR gate, each e-node becomes an AND gate, and each e-node gets its own input vertex of the same cost. Minimal satisfying evaluations of the circuit are in acyclicity-preserving bijection with minimal satisfying extractions of the e-graph (Sun et al., 2024). This yields an exact extraction algorithm parameterized by treewidth with runtime
5
where 6 is treewidth and 7 is the number of circuit vertices after translation.
The circuit view also imports a simplification toolbox from Boolean-circuit theory. The reported empirical effect is substantial: in many cases, e-graph size and treewidth drop by 40–80%, and for eggcc-bril the reductions are about 65% in treewidth, 97% in 8, and 96% in 9 (Sun et al., 2024). A plausible implication is that the future of e-graph research lies as much in representation change and cross-domain transfer as in rewrite scheduling alone: once the equivalence space is given a sharper semantic or combinatorial model, both the theory and the algorithms of equality saturation broaden accordingly.