[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
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

fix(core): tests for 2-arg Mul restriction #27205

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

oscarbenjamin
Copy link
Collaborator

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

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.
@sympy-bot
Copy link

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.

  • No release notes entry will be added for this pull request.
Click here to see the pull request description that was parsed.
<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->

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

<!-- Write the release notes for this release below between the BEGIN and END
statements. The basic format is a bulleted list with the name of the subpackage
and the release note for this PR. For example:

* solvers
  * Added a new solver for logarithmic equations.

* functions
  * Fixed a bug with log of integers. Formerly, `log(-x)` incorrectly gave `-log(x)`.

* physics.units
  * Corrected a semantical error in the conversion between volt and statvolt which
    reported the volt as being larger than the statvolt.

or if no release note(s) should be included use:

NO ENTRY

See https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more
information on how to write release notes. The bot will check your release
notes automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
NO ENTRY
<!-- END RELEASE NOTES -->

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants