Add egraph-unary for maximal unary context extraction#1579
Draft
pavpanchekha wants to merge 2 commits intomainfrom
Draft
Add egraph-unary for maximal unary context extraction#1579pavpanchekha wants to merge 2 commits intomainfrom
pavpanchekha wants to merge 2 commits intomainfrom
Conversation
obround
approved these changes
Apr 20, 2026
Contributor
obround
left a comment
There was a problem hiding this comment.
Looks very cool, I've been playing around with egraph-unary for interval-based series, and the expressions returned seem pretty useful.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Unary expressions are special in numerics: they can be efficiently and accurately approximated by polynomials. So one thing we might want is to rewrite an expression like
log(exp(a) + exp(b))into a form likea + log(1 + exp(b - 1)), where there's a nice unary subcomponent likelog(1 + exp(x)). Since this requires some rewriting, we want to do it on an e-graph.This PR thus adds
egraph-unary, which extracts non-trivial (notxorsin(x)) distinct unary expressions in an e-graph. It works is a pretty straightforward way, though I got here in a complicated way involving dominator trees:eis a unary function ofewith expressionxf(e_1, ..., e_n)is also a unary function ofeif eache_iis a unary function ofe, with the obvious witness termSo you compute this via an eclass analysis where the value is a map
{ eclass → expr }such that if the data fore1has{ e2 → E[x] }thene1 = E[e2]. Pretty neat and pretty fast! Kinda ugly to do this on the Racket side but whatever.