0

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?

3
  • 1
    Is n positive? An integer? Commented May 28, 2024 at 20:34
  • 2
    Full error message, please!. It might help to evaluate the expression piece by piece. In other words, all the standard debugging steps. Commented May 28, 2024 at 22:11
  • Did you try n=symbols('n', positive=True)? (Or negative=True?) Commented May 29, 2024 at 6:35

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

4 Comments

Note that you're overwriting the sympy imaginary number with a simple symbol.
Yeah I know what you mean. It´s a fatal error by myself. I edited my answer. You edited my answer too. But you should also mention the sign for imaginary unit Im and not just like for n. I run this code without setting Im symbol as positive and it doesn´t work.
What does it mean for the imaginary number i to be positive or negative?
In sympy every variable is a symbol. You have to set Im as positive in this code otherwise it doesn´t work. Try it. Remove symbol creation of Im as positive and it will come an error message. You can create symbols separately. n=symbols('n',positive=True) and Im=symbol('Im') This doesn´t work without setting sign for symbol Im

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.