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 10, 2021
1 parent b04244e commit d897be4
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 @@ -95,3 +95,4 @@ These Sympy issues also were addressed:
* :sympyissue:`21245`: laurent series Fibonacci generating fuction
* :sympyissue:`11833`: error in limit involving exp, sinh and an assumption (maybe related to caching)
* :sympyissue:`9127`: ntheory.AskEvenHandler.Mul is order-dependent
* :sympyissue:`21176`: Incorrect residue of x**2*cot(pi*x)/(x**4 + 1)

0 comments on commit d897be4

Please sign in to comment.