arXiv:2610.01198cs.PLOct 2026

Manuscript Offprint

arXiv:2610.01198

Associativity and Commutativity in Equality Saturation

Tarik Rosin, Marcel Ullrich, Sebastian Hack

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

TARIK ROSIN, Saarland University, Germany

MARCEL ULLRICH, Saarland University, Germany

SEBASTIAN HACK, Saarland University, Germany

Equality saturation is a promising technique for program optimization which sidesteps the phase ordering problem. However, current e-graph implementations grow exponentially large, even for simple examples. Many practical applications involve associative and commutative (AC) operators. We present an extension of relational e-matching that handles AC operators natively by storing terms as multisets. Preliminary results show that equality saturation modulo AC uses asymptotically less memory in certain cases.

Additional Key Words and Phrases: E-Graph, Equality Saturation, E-matching

1 Motivation

In this paper we study the effects of associativity and commutativity (AC) rules on equality saturation. Equality saturation is a technique of exploring equivalent terms by rewriting, while storing deduplicated terms in an e-graph.

When used for program optimization, equality saturation allows for good flexibility. It does not require an ordering on terms or another kind of canonicalization strategy. Rules can be bidirectional without the danger of non-productive cyclic rewriting. This is because the e-graph acts as a compact database of all explored programs. Equality saturation can be interrupted at any time to extract the best program discovered so far.

However, e-graphs tend to explode in size, even for small programs and few rewrite rules. The e-graph is explicitly storing the entire search space. Two prominent rewrite rules, associativity and commutativity, are known to cause combinatorial blowup.

(x+y)+z=x+(y+z)(x+y)+z=x+(y+z)

(A)

x+y=y+xx+y=y+x

(C)

AC is ubiquitous in applications of equality saturation such as hardware synthesis [Coward et al. 2024; Wang et al. 2023], program optimization [Nandi et al. 2021; Panchekha et al. 2015], and theorem proving [de Moura and Bjørner 2007].

Example 1.1. Consider only the associative law and x⋅0=0x \cdot 0 = 0 with the initial term a⋅0a \cdot 0. First, equality saturation determines that a⋅0=0a \cdot 0 = 0. In the next iteration, the associative pattern would match on a⋅(a⋅0)a \cdot (a \cdot 0) by backwards substituting a⋅0a \cdot 0 for 0 in the initial term. This produces the new term (a⋅a)⋅0(a \cdot a) \cdot 0 and the same process repeats indefinitely.

This paper reports on an extension of e-graphs to mitigate the blowup caused by AC rules. We first present bounds on the AC blow-up of standard e-graphs. We then show how to extend the database view of e-graphs to support efficient e-matching and leverage an existing algorithm for AC congruence closure to support efficient rebuilding.