issue with series expansion of expression with log

35 views
Skip to first unread message

Jesse Carter

unread,
Mar 11, 2020, 6:10:08 PM3/11/20
to sympy
Hi -

First time poster so sorry if this has been discussed before.

I'm having an issue with doing a series expansion of an expression with a log term in it where the argument of log is close to 1.

For instance, if I do a series expansion about an arbitrary point x0, then substitute a value for x0, it works fine. But if I instead try to do an expansion about that point directly in the series function, I can get an error for certain values.

The following gives an error on the last line, but works fine if I set, say, point = 0.49.

import sympy as sym

point = 0.491
x, x0 = sym.symbols(['x', 'x0'])
f = sym.log(x/(1-x))

print(sym.series(f, x=x, x0=x0, n=1).removeO().subs(x0, point))
print(sym.series(f, x=x, x0=point, n=1).removeO())

Is the latter not an intended way of using the series expansion functionality?

For what it's worth I tried both sympy 1.4 and 1.5.1 through Anaconda.

Here is the error:
Traceback (most recent call last):
  File "sympy-bug.py", line 17, in <module>
    print(sym.series(f, x=x, x0=point,n=1).removeO())
  File "/apps/local/anaconda/Anaconda3-2019.10/lib/python3.7/site-packages/sympy/series/series.py", line 12, in series
    return expr.series(x, x0, n, dir)
  File "/apps/local/anaconda/Anaconda3-2019.10/lib/python3.7/site-packages/sympy/core/expr.py", line 2720, in series
    s = self.subs(x, rep).series(x, x0=0, n=n, dir='+', logx=logx)
  File "/apps/local/anaconda/Anaconda3-2019.10/lib/python3.7/site-packages/sympy/core/expr.py", line 2730, in series
    rv = self.subs(x, xpos).series(xpos, x0, n, dir, logx=logx)
  File "/apps/local/anaconda/Anaconda3-2019.10/lib/python3.7/site-packages/sympy/core/expr.py", line 2766, in series
    % (str(n), self))
ValueError: Could not calculate 1 terms for log((_x + 0.491)/(0.509 - _x))

Any ideas? Thanks.

   - Jesse

Aaron Meurer

unread,
Mar 11, 2020, 6:12:22 PM3/11/20
to sympy
It looks like a bug with floating point numbers. It also gives the
right answer if you instead use Rational(point). I would suggest
opening an issue for this on the SymPy issue tracker.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/8a82921e-8b79-4b7d-bd90-f986230db0fb%40googlegroups.com.

Jesse Carter

unread,
Mar 12, 2020, 8:30:11 AM3/12/20
to sympy
Reply all
Reply to author
Forward
0 new messages