From 12893accfc6b08193ccedd4a903c0735c84931df Mon Sep 17 00:00:00 2001 From: Sidharth Mundhra Date: Wed, 29 Sep 2021 22:45:40 +0530 Subject: [PATCH] Added powsimp before calling pow_heuristics in limits --- sympy/series/limits.py | 21 +++++++++++---------- sympy/series/tests/test_limits.py | 4 ++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/sympy/series/limits.py b/sympy/series/limits.py index 5b5b83d10751..a085ddcd372c 100644 --- a/sympy/series/limits.py +++ b/sympy/series/limits.py @@ -175,20 +175,20 @@ def free_symbols(self): return isyms - def pow_heuristics(self): + def pow_heuristics(self, e): from sympy import exp, log - expr, z, z0, _ = self.args - b, e = expr.base, expr.exp - if not b.has(z): - res = limit(e*log(b), z, z0) + _, z, z0, _ = self.args + b1, e1 = e.base, e.exp + if not b1.has(z): + res = limit(e1*log(b1), z, z0) return exp(res) - ex_lim = limit(e, z, z0) - base_lim = limit(b, z, z0) + ex_lim = limit(e1, z, z0) + base_lim = limit(b1, z, z0) if base_lim is S.One: if ex_lim in (S.Infinity, S.NegativeInfinity): - res = limit(e*(b - 1), z, z0) + res = limit(e1*(b1 - 1), z, z0) return exp(res) if base_lim is S.NegativeInfinity and ex_lim is S.Infinity: return S.ComplexInfinity @@ -207,7 +207,7 @@ def doit(self, **hints): hints : optional keyword arguments To be passed to ``doit`` methods; only used if deep is True. """ - from sympy import Abs, sign + from sympy import Abs, powsimp, sign e, z, z0, dir = self.args @@ -295,8 +295,9 @@ def set_signs(expr): coeff, ex = newe.leadterm(z, cdir=cdir) except (ValueError, NotImplementedError, PoleError): # The NotImplementedError catching is for custom functions + e = powsimp(e) if e.is_Pow: - r = self.pow_heuristics() + r = self.pow_heuristics(e) if r is not None: return r else: diff --git a/sympy/series/tests/test_limits.py b/sympy/series/tests/test_limits.py index 9ac7a02619a0..6c324df14cd1 100644 --- a/sympy/series/tests/test_limits.py +++ b/sympy/series/tests/test_limits.py @@ -1010,3 +1010,7 @@ def test_issue_21756(): def test_issue_21785(): a = Symbol('a') assert sqrt((-a**2 + x**2)/(1 - x**2)).limit(a, 1, '-') == I + + +def test_issue_22181(): + assert limit((-1)**x * 2**(-x), x, oo) == 0