Skip to content

Commit

Permalink
core: avoid deep expanding in Mul._eval_nseries()
Browse files Browse the repository at this point in the history
This finally fix diofant#1139
Closes sympy/sympy#21176
  • Loading branch information
skirpichev committed Jun 8, 2021
1 parent 29221ab commit 21fd3aa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion diofant/core/mul.py
Expand Up @@ -1382,7 +1382,7 @@ def ndiv(a, b):
def _eval_nseries(self, x, n, logx):
from ..simplify import powsimp
terms = [t.nseries(x, n=n, logx=logx) for t in self.args]
return powsimp(self.func(*terms).expand(), combine='exp', deep=True)
return powsimp(self.func(*terms).expand(deep=False), combine='exp', deep=True)

def _eval_as_leading_term(self, x):
return self.func(*[t.as_leading_term(x) for t in self.args])
Expand Down
12 changes: 10 additions & 2 deletions diofant/tests/series/test_residues.py
@@ -1,7 +1,7 @@
import pytest

from diofant import (Function, I, Rational, Symbol, cot, exp, factorial, log,
pi, residue, root, sin, sqrt, tanh)
from diofant import (Function, I, Mul, Rational, Symbol, cot, exp, factorial,
log, pi, residue, root, sin, sqrt, tan, tanh)
from diofant.abc import a, s, x, z


Expand Down Expand Up @@ -85,3 +85,11 @@ def test_sympyissue_21177():

assert residue(e1, x, pt) == ans
assert residue(e2, x, pt) == ans


def test_sympyissue_21176():
e = x**2*cot(pi*x)/(x**4 + 1)
pt = -sqrt(2)/2 - sqrt(2)*I/2
assert residue(e, x, pt) == Mul(Rational(1, 4), sqrt(2), 1/(1 + I),
1/tan(sqrt(2)*pi/2 + sqrt(2)*I*pi/2),
evaluate=False)
1 change: 1 addition & 0 deletions docs/release/notes-0.13.rst
Expand Up @@ -93,3 +93,4 @@ These Sympy issues also were addressed:
* :sympyissue:`21550`: Bug: limit returns wrong result for rational function
* :sympyissue:`21177`: Incorrect residue for cot(pi*x)/(x**2 - 3*x + 3)
* :sympyissue:`21245`: laurent series Fibonacci generating fuction
* :sympyissue:`21176`: Incorrect residue of x**2*cot(pi*x)/(x**4 + 1)

0 comments on commit 21fd3aa

Please sign in to comment.