Skip to content

Commit

Permalink
Merge pull request #19916 from sachin-4099/gsoc#14
Browse files Browse the repository at this point in the history
[GSoC] Functions: Fixes limit evaluations related to trigonometric functions
  • Loading branch information
jksuom committed Aug 8, 2020
2 parents 8269423 + f6a7c15 commit 1b9a569
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
21 changes: 20 additions & 1 deletion 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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down
20 changes: 16 additions & 4 deletions sympy/series/tests/test_limits.py
Expand Up @@ -859,6 +859,12 @@ def test_issue_15055():
assert limit(n**3*((-n - 1)*sin(1/n) + (n + 2)*sin(1/(n + 1)))/(-n + 1), n, oo) == 1


def test_issue_16708():
m, vi = symbols('m vi', positive=True)
B, ti, d = symbols('B ti d')
assert limit((B*ti*vi - sqrt(m)*sqrt(-2*B*d*vi + m*(vi)**2) + m*vi)/(B*vi), B, 0) == (d + ti*vi)/vi


def test_issue_19739():
assert limit((-S(1)/4)**x, x, oo) == 0

Expand All @@ -867,7 +873,13 @@ def test_issue_19766():
assert limit(2**(-x)*sqrt(4**(x + 1) + 1), x, oo) == 2


def test_issue_16708():
m, vi = symbols('m vi', positive=True)
B, ti, d = symbols('B ti d')
assert limit((B*ti*vi - sqrt(m)*sqrt(-2*B*d*vi + m*(vi)**2) + m*vi)/(B*vi), B, 0) == (d + ti*vi)/vi
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)
# 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

0 comments on commit 1b9a569

Please sign in to comment.