Series return an incorrect result #10503

Open
opened this Issue Jan 31, 2016 · 3 comments

Projects
None yet
5 participants
Member

certik commented Jan 31, 2016

 The latest sympy master: ``````In [1]: f=exp(x**3)*cos(x**6) In [2]: f.series(x, 0, 14) Out[2]: 6 9 12 3 x x x ⎛ 14⎞ 1 + x + ── + ── + ─── + O⎝x ⎠ 2 6 24 In [3]: f.series(x, 0, 19) Out[3]: 6 9 12 15 18 3 x x 11⋅x 59⋅x 179⋅x ⎛ 19⎞ 1 + x + ── + ── - ────── - ────── - ─────── + O⎝x ⎠ 2 6 24 120 720 ``````
Member

jksuom commented Jan 31, 2016

 This appears to be caused by the way `range(nterms)` works: `nterms` itself is not included on this line. This is taken care of in many cases by the addition of 2 to the number of terms, but after division by the order `cf` of the argument the effect may be lost In this example `cf` is 6: `````` In [25]: series(cos(x**6), x, 0, 14) Out[25]: ⎛ 14⎞ 1 + O⎝x ⎠ `````` With n + 2 = 16 `nterms` becomes `int(16/6) = 2`, and only the first two terms of the series of cos are taken into account, the constant 1 and the linear term 0.

skirpichev added a commit to diofant/diofant that referenced this issue Jan 31, 2016

``` Function._eval_nseries: Drop heuristic prediction for number of terms ```
```Now all returned by Function.nseries terms are correct.

Fixes #210
Closes sympy/sympy#10503```
``` 1c78c5b ```

skirpichev added a commit to diofant/diofant that referenced this issue Feb 1, 2016

``` Function._eval_nseries: Drop heuristic prediction for number of terms ```
```Now all returned by Function.nseries terms are correct.

Fixes #210
Closes sympy/sympy#10503```
``` 6d45c43 ```

skirpichev added a commit to diofant/diofant that referenced this issue Feb 3, 2016

``` Function._eval_nseries: Drop heuristic prediction for number of terms ```
```Now all returned by Function.nseries terms are correct.

Fixes #210
Closes sympy/sympy#10503```
``` 0df12f6 ```
Contributor

shubhamtibra commented Feb 5, 2016

 Is this issue solved, i would like to work on it.

Closed

Merged

Member

smichr commented Mar 10, 2016

 I is simple enough to not predict, but I am not sure what to put for the power of the Order term: ```diff --git a/sympy/core/function.py b/sympy/core/function.py index 17f7d40..42a922c 100644 --- a/sympy/core/function.py +++ b/sympy/core/function.py @@ -548,6 +548,7 @@ def _eval_nseries(self, x, n, logx): """ This function does compute series for multivariate functio but the expansion is always in terms of *one* variable. + Examples ======== @@ -637,17 +638,15 @@ def _eval_nseries(self, x, n, logx): return e1.nseries(x, n=n, logx=logx) arg = self.args[0] l = [] + i = 0 g = None - # try to predict a number of terms needed - nterms = n + 2 - cf = Order(arg.as_leading_term(x), x).getn() - if cf != 0: - nterms = int(nterms / cf) - for i in range(nterms): + while len(l) != n: g = self.taylor_term(i, arg, g) g = g.nseries(x, n=n, logx=logx) - l.append(g) - return Add(*l) + Order(x**n, x) + if g: + l.append(g) + i += 1 # can we be smarter about skipping terms? + return Add(*l) + Order(x**???, x) def fdiff(self, argindex=1):```

Open