-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Modified order.py #19546
Modified order.py #19546
Conversation
References to other Issues or PRs Fixes sympy#19545 Brief description of what is fixed or changed The code `Order(1/n - 3/(3*n +2), (n, oo))` returns `1/n`, which is not a sharp result. As a consequence `Sum(1/n - 3/(3*n +2), (n, 1, oo)).is_convergent()` gives the wrong result `False`. In the lines 208-214 of `order.py`, if the number of variables are >= 2, then the expression is expanded and is handled in `expr.is_Add` case. However in the case of a single variable, the alghorithm for the other case seems better. Factorizing the expression forces to use the better alghoritm in the case of a single variable. See also PR#18340 On branch issue-19545 Changes to be committed: modified: sympy/concrete/tests/test_sums_products.py modified: sympy/series/order.py modified: sympy/series/tests/test_order.py
✅ Hi, I am the SymPy bot (v160). 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.7. 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. |
Codecov Report
@@ Coverage Diff @@
## master #19546 +/- ##
=============================================
+ Coverage 75.664% 75.757% +0.093%
=============================================
Files 654 654
Lines 169939 170565 +626
Branches 40065 40423 +358
=============================================
+ Hits 128583 129216 +633
+ Misses 35740 35739 -1
+ Partials 5616 5610 -6 |
sympy/series/order.py
Outdated
@@ -212,6 +212,8 @@ def __new__(cls, expr, *args, **kwargs): | |||
# x*y (wrong order term!). That's why we want to deal with | |||
# expand()'ed expr (handled in "if expr.is_Add" branch below). | |||
expr = expr.expand() | |||
else: | |||
expr = expr.factor() |
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.
It seems that this aims to transform the sum 1/x - 3/(3*x + 2)
into a product, so it looks like it should only be applied to instances of Add
. The code would probably be better placed here:
Lines 199 to 201 in f7318db
if expr.is_Add: | |
from sympy import expand_multinomial | |
expr = expand_multinomial(expr) |
It is possible that expand_multinomial
could be removed and replaced by this. You could also test something like
num, den = expr.as_numer_denom()
expr = num/den
instead of expr.factor()
which may be more expensive.
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.
It seems that this aims to transform the sum 1/x - 3/(3*x + 2) into a product, so it looks like it should only be applied to instances of Add. The code would probably be better placed here:
sympy/sympy/series/order.py
Lines 199 to 201 in f7318db
if expr.is_Add:
from sympy import expand_multinomial
expr = expand_multinomial(expr)
Right. I changed the location of factor
.
It is possible that expand_multinomial could be removed
Yes, I run the tests and they pass also without expand_multinomial
.
You could also test something like
num, den = expr.as_numer_denom() expr = num/den
instead of expr.factor() which may be more expensive.
Putting this instead of expr.factor()
causes 2 failures in tests. The tests which failure are:
test_wester.py
at lines 2088-2090.test_trigonometric.py
at llines 1224-1225.
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.
Putting this instead of
expr.factor()
causes 2 failures in tests. The tests which failure are:
test_wester.py
at lines 2088-2090.test_trigonometric.py
at llines 1224-1225.
Can you tell what is expr
in these cases using num/den
and when you use expr.factor()
?
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.
For test_wester
.
expr = -exp(-_p**2/(_p + 1) + _p)*exp(_p**2/(_p + 1) - _p)/2 - exp(-_p**2/(_p + 1) + _p)*exp(_p**2/(_p + 1) - _p)/(2*_p)
expr.factor() = -(_p + 1)/(2*_p)
num = -_p*exp(-_p**2/(_p + 1) + _p)*exp(_p**2/(_p + 1) - _p) - exp(-_p**2/(_p + 1) + _p)*exp(_p**2/(_p + 1) - _p)
den = 2*_p
In this case the test does not give an error, but it never finishes.
For test_trigonometric
.
expr = -4*_Dummy_69 + (_Dummy_69 + 1)**4 - 4*(_Dummy_69 + 1)**3 + 6*(_Dummy_69 + 1)**2 - 3
expr.factor() = _Dummy_69**4
num = -4*_Dummy_69 + (_Dummy_69 + 1)**4 - 4*(_Dummy_69 + 1)**3 + 6*(_Dummy_69 + 1)**2 - 3
den = 1
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.
It looks like only factor
factor will help here.
Sphinx test failed though nothing was changed in the documentation. I'll try to restart it. |
The restart button has vanished again. |
It will: #19551 |
Closing and opening to restart the build. |
Thanks, ready to be merged. |
References to other Issues or PRs
Fixes #19545
Brief description of what is fixed or changed
The code
Order(1/n - 3/(3*n +2), (n, oo))
returns1/n
, whichis not a sharp result.
As a consequence
Sum(1/n - 3/(3*n +2), (n, 1, oo)).is_convergent()
gives the wrong result
False
.In the lines 208-214 of
order.py
, if the number of variables are >= 2,then the expression is expanded and is handled in
expr.is_Add
case.However in the case of a single variable,
the alghorithm for the other case seems better.
Factorizing the expression forces to use the better alghoritm in the case
of a single variable.
modified: sympy/concrete/tests/test_sums_products.py
modified: sympy/series/order.py
modified: sympy/series/tests/test_order.py
Other comments
See also #18340
Release Notes