Skip to content
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

Swap operands of commutative operators to reduce the number of parentheses #151

Merged
merged 1 commit into from
Oct 11, 2022

Conversation

laurentlb
Copy link
Owner

x*(y*z) -> y*z*x
x+(y+z) -> y+z+x
x+(y-z) -> y-z+x
x-(y+z) -> x-y-z
x-(y-z) -> x-y+z

…heses

x*(y*z) -> y*z*x
x+(y+z) -> y+z+x
x+(y-z) -> y-z+x
x-(y+z) -> x-y-z
x-(y-z) -> x-y+z
@laurentlb laurentlb merged commit bc96e9c into master Oct 11, 2022
@laurentlb laurentlb deleted the operands branch October 11, 2022 20:23
laurentlb added a commit that referenced this pull request May 24, 2024
Followup to #151 

This transformation preserves the order of the operands (x, y, z), but
it changes the order of evaluation of the operators. This should be fine
for + and -.

For the multiplication: we preserve the evaluation order of the
multiplications (because of float precision), but we swap the operands
only when it's pure.

---------

Co-authored-by: Eldritch Conundrum <eldritch.conundrum@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant