From 33acfcfce71c64c91375432a9f03c2d9b84cb75c Mon Sep 17 00:00:00 2001 From: Sachin Agarwal Date: Fri, 7 Aug 2020 17:57:58 +0530 Subject: [PATCH 1/2] Fixes limit evaluations related to trigonometric functions --- sympy/functions/elementary/trigonometric.py | 21 ++++++++++++++++++++- sympy/series/tests/test_limits.py | 7 +++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/sympy/functions/elementary/trigonometric.py b/sympy/functions/elementary/trigonometric.py index 1671ff772e51..07e653ecbca4 100644 --- a/sympy/functions/elementary/trigonometric.py +++ b/sympy/functions/elementary/trigonometric.py @@ -1,6 +1,6 @@ from sympy.core.add import Add from sympy.core.basic import sympify, cacheit -from sympy.core.function import Function, ArgumentIndexError, expand_mul +from sympy.core.function import Function, ArgumentIndexError, PoleError, expand_mul from sympy.core.logic import fuzzy_not, fuzzy_or, FuzzyBool from sympy.core.numbers import igcdex, Rational, pi from sympy.core.relational import Ne @@ -388,6 +388,14 @@ def taylor_term(n, x, *previous_terms): else: return (-1)**(n//2)*x**(n)/factorial(n) + def _eval_nseries(self, x, n, logx, cdir=0): + arg = self.args[0] + if logx is not None: + arg = arg.subs(log(x), logx) + if arg.subs(x, 0).has(S.NaN, S.ComplexInfinity): + raise PoleError("Cannot expand %s around 0" % (self)) + return Function._eval_nseries(self, x, n=n, logx=logx, cdir=cdir) + def _eval_rewrite_as_exp(self, arg, **kwargs): I = S.ImaginaryUnit if isinstance(arg, TrigonometricFunction) or isinstance(arg, HyperbolicFunction): @@ -576,6 +584,9 @@ def eval(cls, arg): elif isinstance(arg, SetExpr): return arg._eval_func(cls) + if arg.is_extended_real and arg.is_finite is False: + return AccumBounds(-1, 1) + if arg.could_extract_minus_sign(): return cls(-arg) @@ -708,6 +719,14 @@ def taylor_term(n, x, *previous_terms): else: return (-1)**(n//2)*x**(n)/factorial(n) + def _eval_nseries(self, x, n, logx, cdir=0): + arg = self.args[0] + if logx is not None: + arg = arg.subs(log(x), logx) + if arg.subs(x, 0).has(S.NaN, S.ComplexInfinity): + raise PoleError("Cannot expand %s around 0" % (self)) + return Function._eval_nseries(self, x, n=n, logx=logx, cdir=cdir) + def _eval_rewrite_as_exp(self, arg, **kwargs): I = S.ImaginaryUnit if isinstance(arg, TrigonometricFunction) or isinstance(arg, HyperbolicFunction): diff --git a/sympy/series/tests/test_limits.py b/sympy/series/tests/test_limits.py index 0c9c132e3dd7..aee2d8bd2da4 100644 --- a/sympy/series/tests/test_limits.py +++ b/sympy/series/tests/test_limits.py @@ -861,3 +861,10 @@ def test_issue_15055(): def test_issue_19739(): assert limit((-S(1)/4)**x, x, oo) == 0 + + +def test_issue_19770(): + m = Symbol('m', real=True) + assert limit(cos(m*x)/x, x, oo) == Limit(cos(m*x)/x, x, oo, dir='-') # can be improved to give the correct result 0 + m = Symbol('m', nonzero=True) + assert limit(cos(m*x), x, oo) == AccumBounds(-1, 1) From f6a7c15d94495ac34aefc562cf49a64a91dc98bb Mon Sep 17 00:00:00 2001 From: Sachin Agarwal Date: Fri, 7 Aug 2020 23:37:48 +0530 Subject: [PATCH 2/2] Made minor changes to testcases --- sympy/series/tests/test_limits.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sympy/series/tests/test_limits.py b/sympy/series/tests/test_limits.py index 9cda29f55f6b..145990de7579 100644 --- a/sympy/series/tests/test_limits.py +++ b/sympy/series/tests/test_limits.py @@ -874,7 +874,12 @@ def test_issue_19766(): def test_issue_19770(): + m = Symbol('m') + # the result is not 0 for non-real m + assert limit(cos(m*x)/x, x, oo) == Limit(cos(m*x)/x, x, oo, dir='-') m = Symbol('m', real=True) - assert limit(cos(m*x)/x, x, oo) == Limit(cos(m*x)/x, x, oo, dir='-') # can be improved to give the correct result 0 + # can be improved to give the correct result 0 + assert limit(cos(m*x)/x, x, oo) == Limit(cos(m*x)/x, x, oo, dir='-') m = Symbol('m', nonzero=True) assert limit(cos(m*x), x, oo) == AccumBounds(-1, 1) + assert limit(cos(m*x)/x, x, oo) == 0