Fast and Optimal Extraction for Sparse Equality Graphs
Amir Kafshdar Goharshady, Chun Kit Lam, Lionel Parreaux
Abstract
Equality graphs (e-graphs) are used to compactly represent equivalence classes of terms in symbolic reasoning systems. Beyond their original roots in automated theorem proving, e-graphs have been used in a variety of applications. They have become particularly important as the key ingredient in the popular technique of equality saturation , which has notable applications in compiler optimization, program synthesis, program verification, and symbolic execution, among others. In a typical equality saturation workflow, an e-graph is used to store a large number of equalities that are generated by local rewrites during a saturation phase, after which an optimal term is extracted from the e-graph as the output of the technique. However, despite its crucial role in equality saturation, e-graph extraction has received relatively little attention in the literature, which we seek to start addressing in this paper. Extraction is a challenging problem and is notably known to be NP-hard in general, so current equality saturation tools rely either on slow optimal extraction algorithms based on integer linear programming (ILP) or on heuristics that may not always produce the optimal result. In fact, in this paper, we show that e-graph extraction is hard to approximate within any constant ratio. Thus, any such heuristic will produce wildly suboptimal results in the worst case. Fortunately, we show that the problem becomes tractable when the e-graph is sparse, which is the case in many practical applications. We present a novel parameterized algorithm for extracting optimal terms from e-graphs with low treewidth, a measure of how “tree-like” a graph is, and prove its correctness. We also present an efficient Rust implementation of our algorithm and evaluate it against ILP on a number of benchmarks extracted from the Cranelift benchmark suite, a real-world compiler optimization library based on equality saturation. Our algorithm optimally extracts e-graphs with treewidths of up to 10 in a fraction of the time taken by ILP. These results suggest that our algorithm can be a valuable tool for equality saturation users who need to extract optimal terms from sparse e-graphs.
Ask about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Your agent calls
Luneget_paper_fulltext
Free to start. No credit card required.
Terminal
Install the CLIlune papers fulltext 64d72f7a-32e9-4174-85a6-65be40b906caCited by top-tier papers7
- HeuriGym: An Agentic Benchmark for LLM-Crafted Heuristics in Combinatorial OptimizationHongzheng Chen, Yingheng Wang, Yaohui Cai, Hins Hu et al.ICLR 2026 · 26 citations
- EGG-SR: Embedding Symbolic Equivalence into Symbolic Regression via Equality GraphNan Jiang, Ziyi Wang, Yexiang XueICLR 2026 · 3 citations
- Efficient Extraction for Effectful E-graphsOliver Flatt, Anjali Pal, Yihong Zhang, Ryan Tjoa et al.OOPSLA 2026 · 1 citation
- Improving Equality Saturation for EDA via Semantic E-GraphsSijie Kong, Jingtao Xia, Daniel Ruelas-Petrisko, Zachary D. Sisco et al.PLDI 2026
- Equality Saturation for Quantum Circuit OptimizationGanxiang Yang, Paige Raun, Runzhou Tao, Ronghui GuPLDI 2026
Builds on14
- Synthesizing structured CAD models with equality saturation and inverse transformationsChandrakana Nandi, Max Willsey, Adam Anderson, James R. Wilcox et al.PLDI 2020 · 65 citations
- Semantic code search via equational reasoningVarot Premtoon, James Koppel, Armando Solar-LezamaPLDI 2020 · 49 citations
- A Single-Exponential Time 2-Approximation Algorithm for TreewidthTuukka KorhonenFOCS 2021 · 49 citations
- Better Together: Unifying Datalog and Equality SaturationYihong Zhang, Yisu Remy Wang, Oliver Flatt, David Cao et al.PLDI 2023 · 38 citations
- Rewrite rule inference using equality saturationChandrakana Nandi, Max Willsey, Amy Zhu, Yisu Remy Wang et al.OOPSLA 2021 · 35 citations
Related papers
- egg: Fast and extensible equality saturationMax Willsey, Chandrakana Nandi, Yisu Remy Wang, Oliver Flatt et al.POPL 2021 · 170 citations
- Slotted E-Graphs: First-Class Support for (Bound) Variables in E-GraphsRudi Schneider, Marcus Rossel, Amir Shaikhha, Andrés Goens et al.PLDI 2025 · 1 citation
- Equivalence Hypergraphs: DPO Rewriting for Monoidal E-GraphsAleksei Tiurin, Chris Barrett, Dan R. Ghica, Nick HuLICS 2025
- Dis/Equality GraphsGeorge Zakhour, Pascal Weisenburger, Jahrim Gabriele Cesario, Guido SalvaneschiPOPL 2025 · 3 citations
- Optimism in Equality SaturationRussel Arbore, Alvin Cheung, Max WillseyPLDI 2026
