[shape_poly] Simplify and speed-up the __eq__ functions for symbolic expressions #19231
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.
Equality is used heavily for symbolic expressions because we use them as dictionary keys or in sets. Previously, we used a more complete and more expensive form of equality where we attempted to prove that "e1 - e2 >= 0" and "e1 - e2 <= 0". This is an overkill and none of the tests we have so far rely on this power. Now we just normalize "e1 - e2" and if it reduces syntactically to an integer we check if the integer is 0. If the difference does not reduce to an integer we say that the expressions are disequal.
This may possibly change user-visible behavior when it depends on the outcome of equality comparisons of symbolic dimensions in presence of shape polymorphism.