https://docs.rs/egg/0.6.0/egg/tutorials/_01_background/index...
https://www.youtube.com/watch?v=LKELTEOFY-s https://www.cs.cornell.edu/~ross/publications/eqsat/
These e-graph data structures are in the heart of SMT solvers but giving easier access to end users and specializing the algorithm to the different needs of optimizing rewrites really changes the game.
There's some cool applications linked on the site that I recommend people check out. A kind of neat thing about it being in rust is that you can compile to WASM to throw stuff on the web. I had a little demo of using egg to rewrite some category theory on my blog here https://www.philipzucker.com/rust-category/
Do these equalities carry all the way into general programming, to the point where we could for example say a short loop is equivalent to an unrolled loop, and thus suggest that optimization? Would we have to come up with an exhaustive list of equivalences, or is the list actually short and well known like they are in logic (Identity Laws)?
Will we at some point basically plug Egg into LLVM and have it find new optimization passes?
They won't find new equivalences on their own though. I doubt that is even possible, you can't in general prove equivalence of functions without also solving the halting problem. Also, even just defining the equivalences we know about are often only valid in certain circumstances that I doubt a computer could figure out in the general case.
From Tate et al 2009:
Better yet, because optimizations are allowed to freely interact during equality saturation, without any consideration for ordering, our approach can discover intricate optimization opportunities that compiler writers may not have anticipated, and hence would not have implemented in a general purpose compiler.
> From Tate et al 2009:
> Better yet, because optimizations are allowed to freely interact during equality saturation, without any consideration for ordering, our approach can discover intricate optimization opportunities that compiler writers may not have anticipated, and hence would not have implemented in a general purpose compiler.
That's not finding new equivalences, it is finding known equivalences that are nested or composed. I suppose you could look at it as a form of unobfuscating the equivalences.
mentally, I'm modelling term rewriting as a state space search where each edge transition is a single possible rewrite. As always with state space search, the goal is to find the global optimum.
It's funny how many problems come back to search heuristics.