/ sympy Public

# Modified order.py#19546

Merged
merged 2 commits into from
Jun 17, 2020
Merged

# Modified order.py #19546

merged 2 commits into from
Jun 17, 2020

## 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

Fixes #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.

modified: sympy/concrete/tests/test_sums_products.py
modified: sympy/series/order.py
modified: sympy/series/tests/test_order.py

#### Release Notes

• series
• modified order.py to better work with Add objects.

``` Modified order.py ```
``` b777e46 ```
```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.

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: series modified order.py to better work with Add objects. (#19546 by @maurogaravello) 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. `````` #### 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))` 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. 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 - series - modified order.py to better work with Add objects. `````` Update The release notes on the wiki have been updated.

# Codecov Report

Merging #19546 into master will increase coverage by `0.093%`.
The diff coverage is `100.000%`.

```@@              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     ```

reviewed
 @@ -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()

### jksuom Jun 15, 2020

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.

### maurogaravello Jun 15, 2020

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
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.

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()` ?

### maurogaravello Jun 15, 2020

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
``````

### jksuom Jun 15, 2020

It looks like only `factor` factor will help here.

``` Changed the position of factor ```
``` 7ab9748 ```

### jksuom commented Jun 15, 2020

 Sphinx test failed though nothing was changed in the documentation. I'll try to restart it.

### jksuom commented Jun 15, 2020

 The restart button has vanished again.

 Sphinx test failed though nothing was changed in the documentation. I'll try to restart it. It will: #19551 There is no point restarting it.

### jksuom commented Jun 16, 2020

 Closing and opening to restart the build.

closed this Jun 16, 2020
reopened this Jun 16, 2020

### jksuom commented Jun 17, 2020

merged commit `1059dae` into sympy:master Jun 17, 2020