pythonanacondasympylimitintegrate

Calculate symbolic limit in sympy error message


I´ve tried to calculate symbolic limit in sympy but got an error message.

import sympy as smp
from sympy import *
n,x=smp.symbols('n x')
limit(simplify(integrate(exp(-x)*exp(-smp.I*n*x),x).args[0][0]),x,smp.oo)

I`ve got following error message:

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
Cell In[26], line 1
----> 1 limit(exp(-n*x),x,smp.oo)

File ~\anaconda3\Lib\site-packages\sympy\series\limits.py:64, in limit(e, z, z0, dir)
     13 def limit(e, z, z0, dir="+"):
     14     """Computes the limit of ``e(z)`` at the point ``z0``.
     15 
     16     Parameters
   (...)
     61      limit_seq : returns the limit of a sequence.
     62     """
---> 64     return Limit(e, z, z0, dir).doit(deep=False)

File ~\anaconda3\Lib\site-packages\sympy\series\limits.py:375, in Limit.doit(self, **hints)
    372 l = None
    374 try:
--> 375     r = gruntz(e, z, z0, dir)
    376     if r is S.NaN or l is S.NaN:
    377         raise PoleError()

File ~\anaconda3\Lib\site-packages\sympy\series\gruntz.py:732, in gruntz(e, z, z0, dir)
    729     else:
    730         raise NotImplementedError("dir must be '+' or '-'")
--> 732 r = limitinf(e0, z)
    734 # This is a bit of a heuristic for nice results... we always rewrite
    735 # tractable functions in terms of familiar intractable ones.
    736 # It might be nicer to rewrite the exactly to what they were initially,
    737 # but that would take some work to implement.
    738 return r.rewrite('intractable', deep=True)

File ~\anaconda3\Lib\site-packages\sympy\core\cache.py:72, in __cacheit.<locals>.func_wrapper.<locals>.wrapper(*args, **kwargs)
     69 @wraps(func)
     70 def wrapper(*args, **kwargs):
     71     try:
---> 72         retval = cfunc(*args, **kwargs)
     73     except TypeError as e:
     74         if not e.args or not e.args[0].startswith('unhashable type:'):

File ~\anaconda3\Lib\site-packages\sympy\series\gruntz.py:452, in limitinf(e, x)
    450     c0, e0 = mrv_leadterm(e.min, x)
    451 else:
--> 452     c0, e0 = mrv_leadterm(e, x)
    453 sig = sign(e0, x)
    454 if sig == 1:

File ~\anaconda3\Lib\site-packages\sympy\core\cache.py:72, in __cacheit.<locals>.func_wrapper.<locals>.wrapper(*args, **kwargs)
     69 @wraps(func)
     70 def wrapper(*args, **kwargs):
     71     try:
---> 72         retval = cfunc(*args, **kwargs)
     73     except TypeError as e:
     74         if not e.args or not e.args[0].startswith('unhashable type:'):

File ~\anaconda3\Lib\site-packages\sympy\series\gruntz.py:554, in mrv_leadterm(e, x)
    546 #
    547 # The positive dummy, w, is used here so log(w*2) etc. will expand;
    548 # a unique dummy is needed in this algorithm
   (...)
    551 # improved, or just find limits of Re and Im components separately.
    552 #
    553 w = Dummy("w", positive=True)
--> 554 f, logw = rewrite(exps, Omega, x, w)
    555 try:
    556     lt = f.leadterm(w, logx=logw)

File ~\anaconda3\Lib\site-packages\sympy\series\gruntz.py:647, in rewrite(e, Omega, x, wsym)
    645     sig = sign(g.exp, x)
    646     if sig != 1 and sig != -1 and not sig.has(AccumBounds):
--> 647         raise NotImplementedError('Result depends on the sign of %s' % sig)
    648 if sig == 1:
    649     wsym = 1/wsym  # if g goes to oo, substitute 1/w

NotImplementedError: Result depends on the sign of -sign(n)

.........................................................................................................................

In mathematics result should be 0

Can anybody explain me output and fix that?


Solution

  • Setting n and Im to be a positive number when creating the symbol will resolve this issue.

    import sympy as smp
    from sympy import *
    x=symbols('x')
    #Im is symbol for imaginary unit to avoid overwriting smp.I
    n,Im=symbols('n Im',positive=True)
    limit(simplify(integrate(exp(-x)*exp(-Im*n*x),x)),x,smp.oo) # 0