New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sympy series gives TypeError on x^(-3/2) * exp(x) at x = 0 #14885

Closed
Electric-tric opened this Issue Jul 9, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@Electric-tric
Copy link

Electric-tric commented Jul 9, 2018

Hi! I tried the following code (trying to reproduce a minimal example here)

import sympy as sp
x = sp.Symbol('x')
expression = x**(-sp.Rational(3,2)) * sp.exp(x)
sp.series(expression, x, 0)

and obtained a strange TypeError, seems to be some internal exception.
Maybe this is a non-implemented feature, I don't know, maybe a bug.
I've also tried different variations on the input, and they all give the same error.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-3b4874b78f1d> in <module>()
      3 expression = x**(-sp.Rational(3,2)) * sp.exp(x)
      4 #debug_expression = x**(-sp.Rational(5, 2)) * (1 - x) * sp.exp(-3*x/2 + sp.Rational(3, 2))
----> 5 sp.series(expression, x, 0)

/usr/local/lib/python3.6/site-packages/sympy-1.1.1-py3.6.egg/sympy/series/series.py in series(expr, x, x0, n, dir)
     10     """
     11     expr = sympify(expr)
---> 12     return expr.series(x, x0, n, dir)

/usr/local/lib/python3.6/site-packages/sympy-1.1.1-py3.6.egg/sympy/core/expr.py in series(self, x, x0, n, dir, logx)
   2581             # replace x with an x that has a positive assumption
   2582             xpos = Dummy('x', positive=True, finite=True)
-> 2583             rv = self.subs(x, xpos).series(xpos, x0, n, dir, logx=logx)
   2584             if n is None:
   2585                 return (s.subs(xpos, x) for s in rv)

/usr/local/lib/python3.6/site-packages/sympy-1.1.1-py3.6.egg/sympy/core/expr.py in series(self, x, x0, n, dir, logx)
   2610                         if newn != ngot:
   2611                             ndo = n + (n - ngot)*more/(newn - ngot)
-> 2612                             s1 = self._eval_nseries(x, n=ndo, logx=logx)
   2613                             while s1.getn() < n:
   2614                                 s1 = self._eval_nseries(x, n=ndo, logx=logx)

/usr/local/lib/python3.6/site-packages/sympy-1.1.1-py3.6.egg/sympy/core/mul.py in _eval_nseries(self, x, n, logx)
   1616     def _eval_nseries(self, x, n, logx):
   1617         from sympy import Order, powsimp
-> 1618         terms = [t.nseries(x, n=n, logx=logx) for t in self.args]
   1619         res = powsimp(self.func(*terms).expand(), combine='exp', deep=True)
   1620         if res.has(Order):

/usr/local/lib/python3.6/site-packages/sympy-1.1.1-py3.6.egg/sympy/core/mul.py in <listcomp>(.0)
   1616     def _eval_nseries(self, x, n, logx):
   1617         from sympy import Order, powsimp
-> 1618         terms = [t.nseries(x, n=n, logx=logx) for t in self.args]
   1619         res = powsimp(self.func(*terms).expand(), combine='exp', deep=True)
   1620         if res.has(Order):

/usr/local/lib/python3.6/site-packages/sympy-1.1.1-py3.6.egg/sympy/core/expr.py in nseries(self, x, x0, n, dir, logx)
   2787             return self.series(x, x0, n, dir)
   2788         else:
-> 2789             return self._eval_nseries(x, n=n, logx=logx)
   2790 
   2791     def _eval_nseries(self, x, n, logx):

/usr/local/lib/python3.6/site-packages/sympy-1.1.1-py3.6.egg/sympy/functions/elementary/exponential.py in _eval_nseries(self, x, n, logx)
    411             return self
    412         t = Dummy("t")
--> 413         exp_series = exp(t)._taylor(t, n)
    414         o = exp_series.getO()
    415         exp_series = exp_series.removeO()

/usr/local/lib/python3.6/site-packages/sympy-1.1.1-py3.6.egg/sympy/functions/elementary/exponential.py in _taylor(self, x, n)
    423         l = []
    424         g = None
--> 425         for i in range(n):
    426             g = self.taylor_term(i, self.args[0], g)
    427             g = g.nseries(x, n=n)

TypeError: 'Rational' object cannot be interpreted as an integer

@Electric-tric Electric-tric changed the title Sympy series gives TypeError on x^(-3/2) * exp(1 - x) Sympy series gives TypeError on x^(3/2) * exp(x) at x = 0 Jul 9, 2018

@Electric-tric Electric-tric changed the title Sympy series gives TypeError on x^(3/2) * exp(x) at x = 0 Sympy series gives TypeError on x^(-3/2) * exp(x) at x = 0 Jul 9, 2018

@Electric-tric

This comment has been minimized.

Copy link

Electric-tric commented Jul 9, 2018

UPD: I discovered that with positive fractional index the function still works:

expression = x**(sp.Rational(3,2)) * sp.exp(x)

but once it becomes negative fractional, the error appears again.
The negative fractional indices by themselves work, but in combination with some other functions they fail.

expression = x**(-sp.Rational(3,2)) * sp.log(x) # <--- success
expression = x**(-sp.Rational(3,2)) * sp.sin(x) # <--- success
expression = x**(-sp.Rational(3,2)) * sp.exp(x) # <--- fail

skirpichev added a commit to skirpichev/diofant that referenced this issue Jul 9, 2018

@skirpichev

This comment has been minimized.

Copy link
Contributor

skirpichev commented Jul 9, 2018

TypeError is a bug, of course. BTW, it's fixed in the diofant long time ago.

@Electric-tric

This comment has been minimized.

Copy link

Electric-tric commented Jul 9, 2018

What is diofant? It is like a development version of sympy?

@skirpichev

This comment has been minimized.

Copy link
Contributor

skirpichev commented Jul 9, 2018

skirpichev added a commit to skirpichev/diofant that referenced this issue Jul 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment