E-Graphs With Bindings
- The paper demonstrates a binding-aware extension to e-graphs that integrates categorical semantics to correctly handle α-equivalence, scope, and capture-avoiding substitution.
- It introduces hierarchical hypergraph representations, semantic e-ids, and rigid α-canonical variables to preserve local context and ensure numerical rewriting accuracy.
- The work shows practical implications for integrating e-graphs with other theories via bottom-up e-matching and canonicalization, highlighting trade-offs and performance considerations.
Searching arXiv for the cited papers and closely related work on e-graphs with bindings. E-graphs with bindings are extensions of equality-saturation machinery that aim to represent and rewrite terms containing binders, such as -abstractions and quantifiers, without losing correctness for -equivalence, scope, and capture-avoiding substitution. In the ordinary setting, e-graphs are highly effective for equational reasoning over ground terms, but the presence of variables and binding disrupts the standard representation: -equivalent terms may fail to share, substitution becomes non-local, and equalities can propagate across scopes unsafely. Recent work addresses this problem along several axes. One line extends the categorical interpretation of e-graphs from semilattice-enriched symmetric monoidal categories to closed symmetric monoidal categories, yielding a binding-aware combinatorial model based on hierarchical hypergraphs and double-pushout rewriting (Tiurin et al., 1 May 2025). Another line develops a pragmatic e-graphs-modulo-theories perspective in which binders are handled via semantic e-ids, canonizers, and bottom-up e-matching, with de Bruijn, nominal, and closure-style representations as principal options (Zucker, 19 Apr 2025). A further design treats variables, contexts, and binders as first-class through rigid -canonical variables, thinnings, lift-pulling smart constructors, and thinning-aware union-find (Zucker, 22 Jun 2026).
1. Classical e-graphs and the source of the binding problem
An e-graph maintains equivalence classes of ground terms under congruence closure. In the standard formulation, an e-node has the form where is an -ary function symbol and each is an e-class identifier. The core invariant is closure under “plugging equals into equal contexts”: if corresponding children are equal, then the parent e-nodes must lie in the same e-class (Zucker, 19 Apr 2025).
Equality saturation proceeds through add, merge, and rebuild. Add inserts a ground e-node and either joins an existing e-class or creates a new one. Merge asserts equalities between e-classes. Rebuild restores congruence closure, typically by scanning parent links or tables and merging parents that become congruent after child merges; in the e-graphs-modulo-theories setting, rebuild also invokes theory-specific canonizers (Zucker, 19 Apr 2025).
This representation is effective in arithmetic and algebraic domains, but bindings make it hard to preserve sharing and hygiene. Traditional e-graphs store syntax-tree structure, so -equivalent terms remain distinct unless one switches to de Bruijn indices. Yet de Bruijn indices introduce their own cost: the same variable may acquire different indices in different scopes, which can destroy sharing. Explicit substitution nodes further complicate correctness and rewrite scheduling. Blind equality propagation can also introduce variables into scopes where they are unbound; one example given is that rules like can produce scope errors if functions are treated naively as constants (Tiurin et al., 1 May 2025, Zucker, 22 Jun 2026).
A central misconception is that support for 0-equivalence alone solves the problem. The cited works instead treat the issue as a conjunction of requirements: canonical treatment of bound variables, explicit control of context, preservation of congruence closure under binding structure, and a rewrite mechanism whose notion of substitution is intrinsically capture-avoiding (Tiurin et al., 1 May 2025, Zucker, 22 Jun 2026).
2. Categorical and combinatorial foundations
A foundational account is given in "E-Graphs With Bindings" (Tiurin et al., 1 May 2025), which extends the categorical interpretation of e-graphs from semilattice-enriched symmetric monoidal categories to closed symmetric monoidal categories. In this setting, hom-sets carry joins, composition and tensor distribute over joins, and the closed structure introduces an internal hom together with evaluation and currying. The adjunction
1
supports the interpretation of abstraction as currying and application as evaluation (Tiurin et al., 1 May 2025).
Within this formulation, a binding construct is not modeled as a syntactic gadget layered atop first-order structure. Instead, abstraction is represented by 2, application by 3, and substitution by composition. This absorbs core binding phenomena into the ambient categorical structure. In particular, 4-equivalence is treated diagrammatically: renaming a bound variable does not change the corresponding string diagram, because the bound variable is represented by connectivity to the abstraction boundary rather than by a textual name (Tiurin et al., 1 May 2025).
The concrete combinatorial representation is a hierarchical hypergraph, or e-hypergraph. It contains ordinary generator edges, equivalence-box hierarchical edges encoding semilattice structure, and 5-box hierarchical edges encoding closed structure. Parent relations define nesting and therefore scope. Consistency relations partition immediate children of a hierarchical edge and absorb ordering constraints associated with the semilattice and closed structure (Tiurin et al., 1 May 2025).
This representation is designed so that the equations of the symmetric monoidal category are already quotiented when terms are translated into hierarchical hypergraphs. A stated consequence is “absorption”: rewriting is performed modulo the symmetric monoidal equations by construction, rather than by separately normalizing associativity, unit, or symmetry at the term level (Tiurin et al., 1 May 2025). This suggests that the graph representation is not merely an implementation device; it is the semantic object on which equality saturation operates.
3. Binding representations: de Bruijn, nominal, closures, and rigid variables
The e-graphs-modulo-theories perspective in "Omelets Need Onions: E-graphs Modulo Theories via Bottom-up E-matching" (Zucker, 19 Apr 2025) presents binder support as a question of semantic representation. Semantic e-ids generalize flat identifiers to theory-structured identifiers living in a semantic domain, with a canonizer API consisting of create, eq, fresh, canon, and assert_eq. For a binder theory 6, the mapping
7
assigns canonical representatives appropriate to the theory (Zucker, 19 Apr 2025).
Three principal representations are highlighted. De Bruijn indices make 8-equivalence coincide with structural equality of bodies, giving a direct and local normalization procedure. Nominal techniques with permutations express 9-equivalence as orbit equivalence under renaming, and group-labeled union-find can store these equivalences through permutation labels on edges. Closure values in a normalization-by-evaluation style represent 0-abstractions as closure-like semantic values, with application evaluated semantically where possible and stuck terms reified back to syntax (Zucker, 19 Apr 2025).
For de Bruijn terms, the normalization function for binders is given as
1
for 2, with all free and bound occurrences represented by indices. Because names have been eliminated, 3 is 4-canonical (Zucker, 19 Apr 2025).
"Lifting E-Graphs: A Function Isn't a Constant" (Zucker, 22 Jun 2026) develops a different but related design. Variables are rigid and 5-canonical because every term carries a thinning witnessing exactly which surrounding-context variables it depends on. A thinning is an order-preserving embedding between finite contexts, represented by a bitvector. The lifting combinator 6 performs explicit weakening, and the e-graph identifier is “fattened” into
7
where the thinning embeds the e-class’s local context into the ambient context (Zucker, 22 Jun 2026).
This design is inspired by slotted e-graphs and Co-de Bruijn syntax, but it rejects slot permutations in favor of totally ordered contexts and sparse thinnings. The resulting variables are rigid because there is no implicit permutative renaming; only explicit, order-preserving re-embeddings are allowed. A plausible implication is that this approach shifts hygiene from a side condition on rewriting to a structural invariant of the data structure itself (Zucker, 22 Jun 2026).
4. Rewriting, matching, and substitution under binders
In ordinary e-graphs, rewrite application uses e-matching: the left-hand side of a rule is matched against the e-graph, and then the instantiated left- and right-hand sides are united. "Omelets Need Onions" argues for bottom-up e-matching rather than the traditional top-down search. Instead of expanding from candidate root e-classes, bottom-up matching chooses terms for pattern variables from the termbank, constructs the ground left-hand side instance via canonicalization and interning, checks whether it is present, and then unions the instantiated left- and right-hand sides (Zucker, 19 Apr 2025).
The paper states approximate costs for an e-graph with 8 e-classes and 9 e-nodes. Top-down matching costs roughly 0 for pattern depth 1, whereas bottom-up matching costs roughly 2 for 3 variables. The claimed advantage is that bottom-up matching scales with the number of variables rather than pattern depth and avoids repeated child expansion in rich theories (Zucker, 19 Apr 2025).
For binders, this bottom-up style interacts naturally with semantic canonizers. A 4-rule is expressed as
5
and an 6-rule as
7
Under de Bruijn, substitution is defined via shift and substitution operations:
8
which enforces capture-avoidance (Zucker, 19 Apr 2025).
A bottom-up plan for 9 is stated explicitly: for a candidate argument 0 and candidate bodies 1, if 2 exists, construct
3
and unite the application class with the class of 4 (Zucker, 19 Apr 2025). Under nominal representations, the same rule requires freshness side conditions or permutation constraints.
The categorical account uses a different mechanism. In the hierarchical-hypergraph setting, 5-reduction is a double-pushout-with-interfaces rule: a match identifies a 6-box feeding an application node, the pushout complement removes that redex, and the replacement rewires the argument directly into occurrences of the bound wire inside the box. Substitution is therefore implemented structurally rather than textually. The 7-rule removes a 8-box whose body is an application of a function to the bound wire, provided the free-variable condition holds (Tiurin et al., 1 May 2025).
The lifting e-graph offers a third route. Matching composes thinnings as it descends patterns, and under binders it pushes lifting across 9 according to the law
0
Because the bound variable always occupies a rigid front position and all environmental dependence is represented through thinnings, rewriting cannot introduce capture: no renaming step exists, and free-variable access is mediated only through explicit embeddings (Zucker, 22 Jun 2026).
5. Core invariants and correctness criteria
All three lines of work are organized around invariants stronger than ordinary congruence closure. In the e-graphs-modulo-theories formulation, each e-class carries a semantic e-id that is a normal form for some syntactic term in the class. For binders, this semantic normal form includes 1 together with any inner normalizations for AC, arithmetic, or other theories. Soundness holds if the canonizer computes unique representatives consistent with the theory equivalence, and if 2- and 3-rules use correct substitution and freshness checks (Zucker, 19 Apr 2025).
Completeness is explicitly limited by termbank coverage. Bottom-up matching can emulate top-down matching if the relevant subterms are present, but if a witness is absent from the termbank, the rewrite will not be discovered. The paper therefore notes that naive saturation is incomplete and advocates termbank expansion beyond naive saturation (Zucker, 19 Apr 2025). This limitation is especially important under binders, where useful redexes may only become visible after generating additional applications or abstractions.
The hierarchical-hypergraph approach formulates correctness through an equivalence between term rewriting and convex DPOI rewriting. The main correspondence states that rewriting in the free closed semilattice-enriched symmetric monoidal theory is equivalent to EDPOI rewriting over well-typed MDA e-hypergraph cospans, quotiented by structural schemas encoding semilattice axioms and distributivity (Tiurin et al., 1 May 2025). The paper presents this as a soundness-and-completeness result: once quotienting is in place, EDPOI relates exactly the same equalities as term rewriting.
The lifting e-graph makes context well-typedness and thinning normalization invariant at the union-find level. Parent pointers carry thinning labels, find composes those labels under path compression, and union reconciles different contexts via the weakest common thinning wct and residual embeddings div. Canonicalization relies on lift-pulling laws such as
4
and
5
The stated invariant is that every e-class has a canonical local context and every FatId embeds that local context into the ambient context in a well-typed way (Zucker, 22 Jun 2026).
Across these approaches, a common theme is that correctness under binding is achieved not by post hoc repair of substitutions, but by encoding scope and context into the representation on which rewriting and congruence operate.
6. Composition with other theories, practical engineering, and limitations
A major motivation for binder-aware e-graphs is composition with other equational theories. The EMT approach emphasizes multi-sorted logic and theory canonizers: binders live in their own sorts, arithmetic and AC in others, and e-nodes connect these sorts. Rebuild re-normalizes semantic e-ids after merges and re-checks parent tables for congruent parents. One example is
6
where the body is AC-normalized, 7-substitution duplicates the argument into both positions, and the arithmetic canonizer reduces 8 to 9 (Zucker, 19 Apr 2025).
Implementation guidance in the same source describes separate union-finds per sort, e-node tables keyed by heads and child e-class ids, structured semantic e-ids for de Bruijn bodies or AC-normalized multisets, theory canonizers plugged into rebuild, smart constructors that normalize newly added terms immediately, and bottom-up matcher loops pruned by sorts and head indices (Zucker, 19 Apr 2025). The paper argues analytically for the performance of bottom-up matching but does not present binder-specific benchmarks.
The lifting e-graph similarly emphasizes implementation details: bitvector-based thinnings, thinning-aware union-find, lift-pulling smart constructors, caching for leading-0 insertions under deep binders, and use of packed bitsets or SIMD operations for large contexts (Zucker, 22 Jun 2026). Memory overhead is identified explicitly as one bitvector per parent edge, while find and union remain near-amortized 1 with additional label-algebra cost proportional to the bitvector representation (Zucker, 22 Jun 2026).
The hierarchical-hypergraph line is more theoretical and notes practical challenges rather than benchmarks. Matching must respect convexity, boundary complements, box nesting, and type well-formedness, so binding-aware e-matching is more complex than first-order matching. The paper suggests that relational e-matching and database-style techniques can be adapted to hierarchical hypergraph queries, but it presents a theory-first framework rather than an empirical system (Tiurin et al., 1 May 2025).
Several limitations recur across the literature. Completeness depends on term generation. Heavy canonizers such as Gröbner bases can be expensive. Some side conditions, especially freshness constraints, may be easier with nominal techniques or SMT-style side-car checks than with pure canonizers. Certain shallow patterns with many variables may favor top-down or mixed plans. Extensions to richer language features, including polymorphism, effects, modules, subtyping, multi-binders, and explicit substitution, remain open or are identified as future work (Zucker, 19 Apr 2025, Tiurin et al., 1 May 2025, Zucker, 22 Jun 2026).
7. Relationship among the main approaches
The three cited approaches are not mutually exclusive; they occupy different points in the design space.
| Approach | Principal mechanism | Emphasis |
|---|---|---|
| Hierarchical e-hypergraphs (Tiurin et al., 1 May 2025) | Closed symmetric monoidal structure, 2-boxes, EDPOI rewriting | Categorical semantics and soundness/completeness |
| EMT with semantic e-ids (Zucker, 19 Apr 2025) | Canonizers, bottom-up e-matching, de Bruijn/nominal/closure representations | Pragmatic composition with rich theories |
| Lifting e-graphs (Zucker, 22 Jun 2026) | Rigid 3-canonical variables, thinnings, lift-pulling, thinning-aware union-find | Context-sensitive sharing and hygiene by construction |
The categorical framework treats bindings as part of the semantic theory itself. Abstraction and application are internal-hom structure; substitution is composition; and the graph representation quotients symmetric monoidal equalities directly (Tiurin et al., 1 May 2025). This is the most explicit semantic answer to the question of what a binding-aware e-graph represents.
The EMT framework is orthogonal in spirit. It asks how generic e-graph rewriting can be combined with specialized theories and presents binders as one such theory. De Bruijn bodies, permutations, or closures become semantic e-ids, and bottom-up e-matching provides a theory-friendly rule-application strategy (Zucker, 19 Apr 2025). This suggests a route for integrating binders with arithmetic, AC, and polynomial reasoning inside an existing equality-saturation engine.
The lifting e-graph, by contrast, treats context dependence as part of term identity. It responds directly to the observation that “a function isn’t a constant”: a term must record not only its core but also the ambient variables on which it depends. Thinnings, lift-pulling, and thinning-aware union-find preserve sharing across related contexts while preventing capture (Zucker, 22 Jun 2026).
A plausible synthesis is that these approaches separate concerns. The categorical work provides the semantic and rewriting-theoretic foundation; EMT provides an implementation-oriented theory-combination architecture; and lifting e-graphs provide a particularly strong data-structural account of variables and contexts. The combined literature therefore characterizes e-graphs with bindings not as a single construction, but as a family of designs unified by the goal of making 4-equivalence, scope, and substitution native to equality saturation rather than external complications (Tiurin et al., 1 May 2025, Zucker, 19 Apr 2025, Zucker, 22 Jun 2026).