IT lexicon › Programming › E-graph

E-graph

Programming På svenska → Updated: 2026-11-05

A data structure that stores many equivalent expressions at once, compactly, so an optimizer can try rewrites without throwing the original away.

Conventional optimizers rewrite destructively: once x*2 has become x<<1 the original is gone, and the order of the passes decides what can be found — the phase-ordering problem. An e-graph instead groups expressions into equivalence classes. Each rewrite merely adds another option to a class. When no rule produces anything new — equality saturation — the cheapest expression is extracted from each class.

The structure comes from theorem provers; Greg Nelson used it in the early 1980s. Tate, Stepp, Tatlock and Lerner turned it into an optimization technique in 2009, and the Rust library egg made it approachable in 2021. Cranelift builds its mid-level optimizer on an acyclic variant. The catch is blow-up: associativity and commutativity alone can fill memory.

← Back to the lexicon