-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new(rs): fully by-hand expression simplification #273
Conversation
Using our
|
Oh, and the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Got some suggestions. With the simplifications, it is possible to condense multiple cases that do the same thing into a single branch -- I made some suggestion to illustrate, but did not make a suggestion for everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Found some more places where
match
cases could be combined- Pointing these out to avoid code duplicate
- Identified what seem to be redundant calls to
simplify()
- One possible logic error
); | ||
let new = simplify_infix( | ||
multiplier, | ||
// Addition associative, right: a + (b + c) = (a + b) + c, pick the shorter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could merge this with the next case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as before re: reconstructing the original
min_by_key(original, new, size) | ||
} | ||
|
||
// Multiplication associative, right: a * (b * c) = (a * b) * c, pick the shorter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could merge with the next case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as before re: reconstructing the original
min_by_key(original, new, size) | ||
} | ||
|
||
// Subtraction "associative" (not really), right: a - (b - c) = (a + c) - b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could merge with the below case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as before re: reconstructing the original
min_by_key(original, new, size) | ||
} | ||
|
||
// Right distribution: a * (b + c) = (a * b) + (a * c) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could merge with the next case, I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as before re: reconstructing the original
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow. too bad that egg
didn't work out at this point, but good to know that all of this was necessary before doing it!
My approval is pending only validation with internal software.
This combines the work in #267 and #272; putting together multiple passes ofby_hand(by_egg(expression))
yields dramatically simpler results.cargo test --release
on the big expression in #259 yieldedwhich looks pretty darn close.This is just a proof of concept right now. Paying for multiple roundtrips to & from a formategg
likes is inefficient.This now relies solely on by-hand simplification, and does rather well:
affine
, expectingax + b + cx + d
to simplify to(a + c)x + (b + d)
, I can't quite get around a syntax error in trying to cover this case;The by-hand simplification has a maximum limit of times it's allowed to run, to avoid some "test
XXX
has overflowed its stack" issues stemming from infinite recursions.