-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
fix(core): tests for 2-arg Mul restriction #27205
Draft
oscarbenjamin
wants to merge
9
commits into
sympy:master
Choose a base branch
from
oscarbenjamin:pr_2argmul_tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains 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
Since 3e835b5 from sympygh-716 there is the following behaviour: >>> 2*(x + y) 2*x + 2*y Specifically if there is a Mul with 2 args and one arg is a Rational and the other an Add then the Rational is distributed into the Add. More generally if there is a Mul and the arguments collapse to a number and an Add e.g. Mul(2, 3.0, x + y) then the coefficient is distributed into the Add. There are various problems with this behaviour such as the fact that it breaks associativity (a*b)*c != a*(b*c). There have been previous attempts to remove this e.g. sympygh-17242 but it is not easy because so much code now depends on it. This commit attempts a more limited change in which the 2-arg Mul is mostly removed but kept for one important special case: if we have Mul(-1, Add(...)) then the -1 will be distributed into the Add. This special case is important because it arises when subtracting to Adds e.g.: >>> x + y - (x + y) 0 It could perhaps be possible to special case negation and subtraction somehow so that negating the terms of an Add happens specifically in subtraction rather than more generally in a Mul but here we just preserve the 2-arg behaviour for -1 specifically as a more limited change to existing behaviour. Keeping this particular special case of the 2-arg Mul dramatically reduces the number of test failures seen in the test suite comared to removing automatic distribution altogether.
✅ Hi, I am the SymPy bot. I'm here to help you write a release notes entry. Please read the guide on how to write release notes.
Click here to see the pull request description that was parsed.
|
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.
References to other Issues or PRs
Updates tests wrt gh-27200. This is built on top of gh-27200 to keep changes to tests separate from the actual behaviour changes.
Brief description of what is fixed or changed
Other comments
Release Notes
NO ENTRY