-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Breaking up the Rational Factors #16527
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
Breaking up the Rational Factors #16527
Conversation
Fixes sympy#16296. Breaks down the numerator and denominator of Rational factors in a multiplicative expression, fixing the denominator collection issue that collect_const() was having.
|
✅ Hi, I am the SymPy bot (v147). I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like:
This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.5. Note: This comment will be updated with the latest check if you edit the pull request. You need to reload the page to see it. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
sympy/core/exprtools.py
Outdated
| # Handle all rational Coefficients | ||
| for f in list(factors.keys()): | ||
| if type(f) is Rational or type(f) is Half: | ||
| factors[f.p] = (factors[f.p] if f.p in factors else 0) + factors[f] |
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.
Perhaps factors.set_default(f.p, 0) could be used.
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.
f.p is a Python int. It should be converted into a SymPy Integer.
|
The tests seem to be breaking right now so I guess something here isn't working right. This should have some new tests when it is working. |
Converting p, q to Sympy Integer and checking instance of Rational to fix the errors in tests.
All tests working now. Changed condition to Rational and Not integer when breaking up numberator and denominator.
|
Please add a unit test. |
Testing factors directly and checking that collect_const can collect rationals.
Not evaulating Mul allows testing the collect_const function with Rational Factors.
6e4c3c2 to
075f29f
Compare
|
Hope everything works well now, thanks a lot. |
Importing sympy.core.numbers.Half is no longer necessary.
|
Thanks, looks good. |
Factors()splits rational factors into its numerator and denominator.collect_const()can now collect the common dividing factors in an expression.References to other Issues or PRs
Fixes #16296
Brief description of what is fixed or changed
Breaks down the numerator and denominator of Rational factors in a multiplicative expression, fixing the denominator collection issue that collect_const() was having.
Release Notes