Papers
Topics
Authors
Recent
Search
2000 character limit reached

Colored E-Graph: Memory-Efficient Conditional Reasoning

Updated 17 July 2026
  • Colored e-graphs are data structures that extend ordinary e-graphs with color-coded layers to represent multiple branch-local equality relations under varying assumptions.
  • They leverage a shared root e-graph to avoid expensive cloning, enabling memory-efficient handling of case splits and conditional rewrites.
  • Optimizations such as colored e-nodes, layered union-finds, and pruning techniques improve performance in equality saturation and proof search tasks.

Colored e-graphs are an extension of ordinary e-graphs designed to support equality reasoning simultaneously under many different assumptions, without physically duplicating the entire e-graph for every case split. They were introduced as a way to represent all of the coarsened congruence relations induced by branch-specific assumptions in a single shared structure, rather than maintaining separate cloned e-graphs. In this design, the root e-graph is stored once, while additional “color-coded” layers record which extra equalities hold under which assumptions. The resulting structure is presented as a memory-efficient equivalent of multiple copies of an e-graph, with support for conditional reasoning, logical cuts, case splits, and branch-sensitive equality saturation; the implementation further introduces optimizations to rebuilding and e-matching, and experiments report support for hundreds of assumptions and millions of terms with space requirements that are an order of magnitude lower, and with similar time requirements (Singher et al., 2023).

1. Ordinary e-graphs and the motivation for coloring

Standard e-graphs compactly represent a set of terms together with an equivalence relation closed under congruence. If tisit_i \cong s_i for all arguments of a function symbol ff, then

f(t1,,tr)f(s1,,sr).f(t_1,\ldots,t_r)\cong f(s_1,\ldots,s_r).

In modern equality saturation, as implemented for example in egg, the e-graph is repeatedly expanded by applying rewrite rules, adding new terms and merging equivalence classes until a fixed point or resource bound is reached. Ordinary e-graphs are excellent for unconditional equality reasoning, but they are weak at handling conditional reasoning, logical cuts, and case splits, especially when one must reason under multiple mutually inconsistent assumptions at once (Singher et al., 2023).

The motivating issue is that a rewrite of the form

φts\varphi \Rightarrow t \to s

requires the precondition φ\varphi to hold. In exploratory reasoning, theory exploration, rewrite rule discovery, and proof search, some conclusions are derivable only in one branch and others in another. A naive implementation clones the whole e-graph for each branch. That is expensive because the clones contain many terms unrelated to the assumption, and any subsequent rewrites over shared subterms are redundantly repeated in each clone. Nested splits then cause exponential duplication. The paper’s core observation is that these branch-local copies differ only by additional merges layered on top of a common base structure, which makes a shared representation possible (Singher et al., 2023).

The paper’s examples make the limitation concrete. For max(x,y)max(x,y), under the assumption x>yx>y, one can conclude max(x,y)xmax(x,y)\cong x; under xyx\le y, one concludes max(x,y)ymax(x,y)\cong y. An ordinary e-graph cannot hold both conclusions simultaneously unless it incorrectly merges ff0 and ff1. Similarly, reasoning about

ff2

may require repeated splitting on ff3, ff4, ff5, and ff6, and cloning duplicates the same shared term structure in every branch (Singher et al., 2023).

2. Semantic model: coarsened congruence relations

The central semantic claim is that adding assumptions only ever merges more equivalence classes; it never requires splitting an existing class. If the root e-graph represents a congruence relation ff7, then a clone created under some assumption corresponds to another congruence relation ff8 such that

ff9

The paper calls f(t1,,tr)f(s1,,sr).f(t_1,\ldots,t_r)\cong f(s_1,\ldots,s_r).0 a coarsened congruence relation. “Coarsened” means that some distinctions made in the base relation are erased: equivalence classes become larger unions of base classes. If the root e-graph says two terms are equal, then they remain equal in every assumption-specific clone; an assumption may justify extra unions not valid globally (Singher et al., 2023).

A colored e-graph therefore maintains multiple congruence relations at once, one per color. The “black” color is the root, assumption-free relation. Each additional color corresponds to a set of assumptions, or in the examples a particular case-split branch. The invariant is that every colored e-class is a union of one or more black e-classes. Equivalently, each f(t1,,tr)f(s1,,sr).f(t_1,\ldots,t_r)\cong f(s_1,\ldots,s_r).1 is a coarsening of f(t1,,tr)f(s1,,sr).f(t_1,\ldots,t_r)\cong f(s_1,\ldots,s_r).2. The root layer is stored as a standard e-graph with hash-cons table, union-find, and e-class map; the colored layers record color-specific unions among representatives of black e-classes (Singher et al., 2023).

This layered semantics is easiest to read against the family f(t1,,tr)f(s1,,sr).f(t_1,\ldots,t_r)\cong f(s_1,\ldots,s_r).3 of conceptual clone e-graphs: one for the root congruence and one per color. All those conceptual clones contain the same terms and e-nodes, differing only in how e-class ids are partitioned by unions. A colored e-graph is presented as equivalent to this family in the sense that union, congruence closure, and e-matching have the same effect as if they were executed separately in each clone, but with shared storage for common term structure (Singher et al., 2023).

The f(t1,,tr)f(s1,,sr).f(t_1,\ldots,t_r)\cong f(s_1,\ldots,s_r).4 example illustrates this interpretation. In black, with no assumptions, the e-graph may contain f(t1,,tr)f(s1,,sr).f(t_1,\ldots,t_r)\cong f(s_1,\ldots,s_r).5, f(t1,,tr)f(s1,,sr).f(t_1,\ldots,t_r)\cong f(s_1,\ldots,s_r).6, f(t1,,tr)f(s1,,sr).f(t_1,\ldots,t_r)\cong f(s_1,\ldots,s_r).7, and f(t1,,tr)f(s1,,sr).f(t_1,\ldots,t_r)\cong f(s_1,\ldots,s_r).8, but cannot conclude either f(t1,,tr)f(s1,,sr).f(t_1,\ldots,t_r)\cong f(s_1,\ldots,s_r).9 or φts\varphi \Rightarrow t \to s0. In the blue layer for φts\varphi \Rightarrow t \to s1, one has φts\varphi \Rightarrow t \to s2 and φts\varphi \Rightarrow t \to s3. In the red layer for φts\varphi \Rightarrow t \to s4, one has φts\varphi \Rightarrow t \to s5 and φts\varphi \Rightarrow t \to s6. The same shared term structure therefore supports incompatible equalities under incompatible assumptions (Singher et al., 2023).

3. Core operations and algorithmic behavior

Insertion in the basic design remains root-level: all e-nodes are inserted into the shared black e-graph. This is sound under the paper’s semantic assumption that merely representing a term in the e-graph does not assert it as true; only placing two terms in the same e-class asserts equality. A term discovered only in one colored branch may still be inserted globally, provided its equality consequences are only recorded in the relevant color. The drawback is that this basic strategy can cause many singleton black e-classes and unnecessary e-nodes, because terms generated from colored rewrites become visible everywhere (Singher et al., 2023).

Union is split into black union and colored union. A black union corresponds semantically to merging the same classes in every clone, since every coarsened relation must include the base relation. A colored union affects only one color’s congruence relation, just as it would if applied only in the corresponding cloned e-graph. This preserves the invariant φts\varphi \Rightarrow t \to s7 (Singher et al., 2023).

Rebuild is the most delicate operation. In ordinary egg, rebuild repairs canonicalization and congruence closure after deferred unions by traversing parents, re-canonicalizing e-nodes, and merging duplicate parents that become congruent. In colored e-graphs, the root rebuild proceeds as usual on the black layer. For a color φts\varphi \Rightarrow t \to s8, congruence closure must reflect both the root’s equalities and the color’s extra unions. In the basic design, because there is no full per-color hash-cons, a color-specific hash-cons is reconstructed on the fly by iterating over all relevant e-classes and collecting e-nodes, which is costly. The important optimization is that, since φts\varphi \Rightarrow t \to s9, any union discovered during black rebuild is valid in every color and can be reused rather than recomputed independently (Singher et al., 2023).

E-matching is generalized by exploiting the fact that a color’s e-class is a union of black ones. Colored e-matching can search an e-class together with its “color siblings,” meaning the black e-classes that belong to the same colored e-class. In the optimized procedure, matching starts from the root layer using standard traversal, and when it encounters a point where a colored sibling might satisfy the pattern, the matching procedure forks and jumps to that sibling while continuing the descent. The paper claims that this enumerates all expected matches without duplicate traversal paths because each fork differs by at least one e-class choice, though duplicate colored matches can still arise because the graph is not fully minimized relative to the colored relation (Singher et al., 2023).

4. Optimized representations and implementation refinements

The main implementation issue is how to share enough across colors while avoiding the inefficiencies of putting every colored consequence into the black layer. The most important refinement is the introduction of colored e-nodes. In the optimized design, e-nodes introduced by colored matches are themselves associated with a color, rather than always being inserted into the black layer. Each color therefore gets additional difference structures: a colored hash-cons, colored e-class map, and colored parents, containing only the e-nodes specific to that color. These structures are canonized with respect to that color’s congruence relation, so duplicate insertion of colored e-nodes is prevented at the color level (Singher et al., 2023).

This change addresses a concrete duplication mechanism in the unoptimized design. If a colored e-node φ\varphi0 is inserted using black representatives of colored-equivalent children, each child φ\varphi1 may be represented by any black id in its colored class, giving up to

φ\varphi2

different black representations that may be redundantly re-added. The colored-e-node design sharply reduces this blow-up, as well as the pollution of the root layer that would otherwise propagate into rebuild and matching costs (Singher et al., 2023).

Two further refinements are pruning and colored minimization. Pruning removes colored e-nodes that become redundant once black equalities grow, because any black equality also holds in every color. During rebuild, the colored hash-cons canonicalizes all e-nodes, and redundant colored entries absent from that canonical table can be removed from the colored e-class map. Colored minimization black-merges certain black e-classes that both contain colored e-nodes of the same color and lie in the same colored e-class, maintaining an invariant that each colored equality class has at most one black e-class containing colored e-nodes (Singher et al., 2023).

Variant E-node placement Reported behavior
Separate cloned e-graphs Full copy per assumption set Baseline for size and runtime
Basic colored e-graph “Monochrome” e-nodes, all e-nodes in black Many timeouts and out-of-memory failures
Optimized colored e-graph Colored e-nodes plus structural optimizations Roughly φ\varphi3 lower normalized e-node overhead and runtime similar overall

A major caveat is that the prototype does not directly implement layered union-finds; instead, each new color creates a full copy of the original union-find. The paper explicitly presents this as a caveat rather than as the conceptual endpoint of the design. A plausible implication is that the reported implementation understates the room for further structural compression in the union-find layer itself (Singher et al., 2023).

5. Canonical examples and empirical evaluation

The simplest example is again φ\varphi4, but the paper also gives a richer equality-saturation example proving

φ\varphi5

After several rewrites, the e-nodes for φ\varphi6 and φ\varphi7 lie in the same e-class both in the blue layer and in the red layer, though potentially not in black. This demonstrates a single conclusion derived separately under multiple incompatible assumptions. The filter example shows the combinatorial advantage: reasoning about

φ\varphi8

requires repeated case splits on predicates such as φ\varphi9, max(x,y)max(x,y)0, max(x,y)max(x,y)1, and max(x,y)max(x,y)2; with separate clones, the number of e-graphs grows exponentially with nesting depth, while colors let common black terms be shared once and each assumption add only the extra unions justified in that case (Singher et al., 2023).

The evaluation is aimed at exploratory reasoning, especially equality saturation with automatic case splitting. The authors built a prover based on TheSy’s code, adding a case-splitting mechanism that introduces additional assumptions only when they unlock blocked rewrites. Benchmarks come from inductive proof suites of Reynolds and Kuncak, also used by TheSy: clam, hipspec-rev-equiv, hipspec-rotate, isaplanner, leon-amortize-queue, and leon-heap. Runs continue until saturation or resource cap, not stopping when a proof is found. Experiments were performed on a 64-core AMD EPYC 7742 machine with 512 GB RAM, with each test limited to 32 GB memory and 1 hour runtime (Singher et al., 2023).

The main size metric is the relative e-node overhead per assumption: max(x,y)max(x,y)3 On completed comparisons, both colored variants use roughly max(x,y)max(x,y)4 lower normalized e-node overhead than separate clones, with the optimized version showing a clearer advantage and less scatter. The monochrome colored variant performs poorly, confirming that pushing all colored consequences into the root layer is too expensive. The optimized colored e-graph, however, has runtime similar to separate clones overall, which is the basis for the paper’s memory/runtime tradeoff claim (Singher et al., 2023).

The per-suite totals are heterogeneous. For example, in the optimized version, clam and hipspec-rev-equiv finish quickly with no OOMs or timeouts; hipspec-rotate drops from 7437.7 seconds and 2 OOMs in separate graphs to 78.2 seconds with 2 timeouts and no OOMs in the optimized version; isaplanner remains challenging in both settings; leon-amortize-queue still has failures but substantially less total runtime in the optimized colored version than in separate clones. One stated outlier is leon-heap, where optimized colored e-graphs incurred 12 extra timeouts at split depth 4, attributed not to a conceptual flaw in colors but to implementation differences that changed the number of assumptions discovered (Singher et al., 2023).

6. Limitations, regime of effectiveness, and conceptual boundaries

The paper is strongest when it treats colored e-graphs as a shared representation for many branch-local congruence relations. It is explicit, however, about several limitations. The simple implementation without colored e-nodes is too slow and memory-hungry. Pruning showed little benefit in the reported experiments because many pruned colored e-nodes are regenerated by later rewrites. More broadly, the approach is best when each assumption induces relatively few additional merges over a large shared base graph. In pathological cases where a color causes many changes, a fully separate e-graph could become competitive or preferable; the paper even suggests automatically switching between colored layers and separate e-graphs when beneficial (Singher et al., 2023).

The conceptual boundary with edge-colored graph theory is also important. In this work, “colored” refers to layers of congruence relations over a shared e-graph, not to colorings of graph edges in the combinatorial sense. That distinguishes colored e-graphs from edge-colored graph notions such as colored edge graphs used to model homogeneous faults (Wang et al., 2012), color-line and proper color-line graphs derived from edge-colored graphs (Le et al., 2015), or properly colored cycles in edge-colored complete graphs (Li, 2020). This suggests a common misconception to avoid: a colored e-graph is a data structure for equality reasoning with conditions, not a graph-theoretic object whose edges are assigned colors.

Within automated reasoning, the paper presents colored e-graphs as particularly useful in theory exploration, rewrite rule inference, proof search, conditional simplification, and SMT-like workflows that involve case splits. The central design idea is that branch-specific e-graphs are not separate worlds requiring independent storage, but coarsenings of one shared root congruence. That perspective places the structure between ordinary e-graphs and explicit clone management: more expressive than a single congruence relation, but more memory-efficient than branch-by-branch duplication (Singher et al., 2023).

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 Colored E-Graph.