# egg

Type: Open Source

egg is an open-source library for equality saturation. It represents many equivalent expressions in an e-graph so a program can explore alternative rewrites before choosing a result. The library was introduced by Max Willsey and colleagues in a paper presented at POPL 2021.[1][2]

## Equality saturation

An e-graph groups expressions known to be equal and allows multiple forms to share structure. Equality saturation applies rewrite rules to add alternatives to the graph. It can retain alternatives that a conventional optimizer might immediately discard after applying a rule. An extraction step can then select an expression according to a cost criterion. The Rust crate exposes graph, rewrite and extraction types for building an optimizer. [1][2]

## Rebuilding and analyses

The authors identified restoring the graph’s invariants as a recurring cost. Their rebuilding method batches part of that work during equality saturation. They also introduced e-class analyses, which allow applications to attach domain-specific facts to groups of equivalent expressions. The paper evaluates the approach in three applications of equality saturation. [2]

## Related articles

- [Formal solvers and proof search](/wiki/research-track-math-factgraph-solvers/) (covered-in)

## References

1. [egg crate API documentation · egg project](https://egraphs-good.github.io/egg/egg/)
2. [egg: Fast and Extensible Equality Saturation](https://arxiv.org/abs/2004.03082)
