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

Closed
opened this Issue Jul 9, 2018 · 4 comments

Projects
None yet
2 participants

### Electric-tric commented Jul 9, 2018 • edited

 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) in () 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 (.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 commented Jul 9, 2018 • edited

 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

``` Add regression test ```
`Closes sympy/sympy#14885`
``` 2100fab ```
Contributor

### skirpichev commented Jul 9, 2018

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

### Electric-tric commented Jul 9, 2018

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

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

``` Add regression test ```
`Closes sympy/sympy#14885`
``` f8b59de ```

Merged