Papers
Topics
Authors
Recent
Search
2000 character limit reached

Rewrite System Showdown: Stochastic Search vs. EqSat

Published 18 May 2026 in cs.PL | (2605.19005v1)

Abstract: Equality saturation has become a dominant paradigm for equational program optimization. However, it has never been rigorously compared to another approach to the same problem, even though several exist, the most notable being stochastic search. In this paper, we compare equality saturation to stochastic search over five benchmarks to answer the question: are e-graphs actually good?

Summary

  • The paper demonstrates that neither equality saturation nor stochastic search is universally optimal, with each technique excelling under different benchmarks and problem scales.
  • Stochastic search excels in scalability via parallelism and cost-guided exploration, whereas EqSat struggles with e-graph blowup and unsound rewrites in larger instances.
  • Both methods face challenges such as rule unsoundness and limited rewrite sets, suggesting potential for hybrid approaches to enhance equational program optimization.

Comparative Evaluation of Program Rewriting: Stochastic Search vs. Equality Saturation

Introduction

The study presents the first rigorous, cross-domain experimental comparison between stochastic search and equality saturation (EqSat) as mechanisms for equational program optimization. EqSat, based on e-graphs, compactly captures equivalence classes of programs through rewrite rules, while stochastic search—specifically Markov Chain Monte Carlo (MCMC)-based—applies rules to concrete terms under a cost-guided probabilistic regime. The motivation is to interrogate the default assumption of EqSat's primacy in program optimizers, especially given the lack of empirical comparisons to other established methods.

Methodology

Both techniques are evaluated using a unified interface compatible with the popular egg EqSat library, extended to support per-node analyses and non-syntactic rewrites. Five benchmarks are addressed, spanning matrix chain multiplication, trigonometric simplification, indefinite integration, decompilation of CAD descriptions, and inequality proving in the Halide compiler. The experimental setup normalizes wall-clock time (typically 10 seconds, except for Halide at 3 seconds), with stochastic search leveraging up to 128 threads for maximal parallelism, reflecting its inherent scalability. EqSat is evaluated largely single-threaded, consistent with most practical deployments.

Matrix Chain Multiplication Benchmark

This classical optimization challenge assesses the ability to discover optimal parenthesizations minimizing computation cost in matrix chains of length up to 1000.

Figure 1

Figure 1: Showdown for matrix chain multiplication.

Stochastic search consistently achieves solutions within 0.3% of dynamic programming-optimal cost. EqSat exhibits near-optimality for moderate problem sizes but degrades for larger chains, reflecting its O(n3)O(n^3) space and O(n)O(n) iteration requirements and the e-graph blowup at scale. EqSat performance can be partially salvaged via "pulsing" (periodic re-extraction of best terms to fresh e-graphs), but this technique also deteriorates above n≈800n\approx800.

Trigonometric Simplification Benchmark

A suite of 35 symbolic simplification tasks using both algebraic and trigonometric rewrite rules highlights issues with rule soundness (e.g., unsound cancellations). Both solvers reach 26/35 successes, with only partial overlap in problem instances solved.

Figure 2

Figure 2: Showdown for trigonometric simplification.

Parallel scalability of stochastic search is evident, as the number of proposals—and benchmarks solved—increases nearly linearly with thread count up to about 16.

Figure 3

Figure 3: Number of proposals and benchmarks solved vs.~number of threads for stochastic search on trigonometric simplification.

EqSat is more susceptible to unsoundness from rule directionality due to global equivocation in the e-graph. Mitigation for EqSat involves checkpointing; for stochastic search, detected unsoundness triggers restarts, which are relatively cheap due to limited state.

Indefinite Integration Benchmark

Complexity increases with synthesis tasks involving symbolic integration. Cost models are carefully tailored for each technique to prevent cost function pathologies (e.g., overpenalizing essential rewrites in stochastic search due to function symbol weighting). Of 10 problems, both techniques succeed on 6, with neither strictly dominating. Notably, both approaches are fundamentally limited by an inability to support uu-substitution for integrals—highlighting the challenge of rewrite-based symbolic integration.

CAD Expression Compression Benchmark (Szalinski)

Decompiling and compressing CAD models is a challenging task due to the need for global program restructuring, e.g., converting a union of translated shapes into a compact representation using folds and maps.

Figure 4

Figure 4: Showdown on compressing CAD expressions.

Results show neither EqSat nor stochastic search dominates across programs—EqSat sometimes yields strictly better compression, but stochastic search performance, while competitive, is constrained by rule set suitability for effective hill climbing. The domain highlights the advantage of e-graph compression for "aligned" transformation opportunities but exposes the limitations of search-driven approaches when essential transformations are not cost-guided.

Proving Inequalities in Halide

This large-scale benchmark, derived from Halide compiler internals, evaluates the capacity to decide algebraic inequalities under a restricted rule set.

Figure 5

Figure 5: Cost distribution of unproved Halide inequalities.

Out of 5786 inequalities, both systems solve the same 40%, with EqSat able to additionally solve about 6% that stochastic search cannot, and vice-versa for roughly 3%. The remaining tests remain unsolved, reflecting the inherent incompleteness of the ruleset rather than algorithmic inadequacy.

Discussion

Pareto Optimality: The central result—neither stochastic search nor equality saturation is Pareto optimal over the other. This is consistently observed across all domains, with a notable core of instances solved by both while each also solves unique instances the other misses. This observation challenges the current dominance of EqSat in program transformation libraries.

Scalability: Stochastic search is notably more scalable via trivial parallelization (constant memory per thread, embarrassingly parallel exploration). EqSat's parallelization is hindered by shared mutable state (the global e-graph), and previous work confirms the engineering difficulty of parallel EqSat kernels [scala-egg].

Soundness and Rule Directionality: EqSat's global equivalence reasoning exacerbates unsoundness from non-invertible or non-total rewrites, while stochastic search, being local and stateful, is more robust but can still exploit unsound rules if given enough time.

Hyperparameters: Stochastic search requires non-trivial hyperparameter tuning (restart schedules, temperature annealing), whereas EqSat, while largely parameter-free, may require rule scheduling to mitigate e-graph blowup or implement scheduling-based heuristics.

Expressive Power: Stochastic search is better positioned to leverage non-semantics-preserving rewrites, as done in superoptimization tasks (e.g., STOKE [stoke]), giving it an advantage for program synthesis and search over semantics-ambiguous spaces.

Implications and Future Directions

This empirical comparison underscores that EqSat's complexity and engineering overhead may not always be justified by results—stochastic search is often competitive and sometimes preferable, particularly on highly parallelizable or cost-guided problems. These findings invite future hybridization: e.g., stochastic search with local e-graph neighborhoods or stochastic elements in e-graph propagation, to leverage the strengths of both approaches.

The results also indicate potential in designing new rewriting frameworks capable of dynamically transitioning between EqSat-style and search-style behavior based on domain properties, ruleset, and cost landscape. Additionally, improving support for complex symbolic synthesis (such as supporting uu-substitution in integration) remains a significant open challenge for both paradigms.

On the theoretical side, understanding the expressiveness and computational complexity trade-offs between e-graph-based and search-based optimization will inform the principled development of future rewriting engines and program synthesizers.

Conclusion

The paper establishes, through rigorous cross-domain experiments, that neither equality saturation nor stochastic search is universally superior for equational program optimization. EqSat excels for problems aligned with its compact representation, but can be hindered by scalability and unsoundness challenges. Stochastic search—given adequate parallel resources and cost model tuning—delivers comparable performance and often scales better. These results motivate reconsideration of default tool choices in compiler optimization and synthesis workflows, and highlight fruitful directions for the design of future, more adaptive rewriting systems.

Paper to Video (Beta)

No one has generated a video about this paper yet.

Whiteboard

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

Open Problems

We haven't generated a list of open problems mentioned in this paper yet.

Tweets

Sign up for free to view the 1 tweet with 1 like about this paper.

HackerNews