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
Series expansion around float fails with NotImplementedError #23432
Comments
I think whenever diff --git a/sympy/core/expr.py b/sympy/core/expr.py
index e607234d0e..51f1283dd8 100644
--- a/sympy/core/expr.py
+++ b/sympy/core/expr.py
@@ -2933,6 +2933,10 @@ def series(self, x=None, x0=0, n=6, dir="+", logx=None, cdir=0):
If "x0" is an infinity object
"""
+ x0 = sympify(x0)
+ if isinstance(x0, Float):
+ x0 = Rational(x0)
+
if x is None:
syms = self.free_symbols
if not syms: |
To avoid issues with inexact numbers all Floats should probably be converted to Rationals. In this case, the problem is that Line 1689 in 0322154
Expansion was prevented for some reason. (I forget why but maybe @0sidharth would remember.) Expansion could be reintroduced on this "last resort" line: Line 1734 in 0322154
simplify does not help. (I does not make the rounding error disappear.) Instead, g could be recomputed on this line with expansion like in
or possibly only
|
With this change, diff --git a/sympy/core/expr.py b/sympy/core/expr.py
index e607234d0e..51f1283dd8 100644
--- a/sympy/core/expr.py
+++ b/sympy/core/expr.py
@@ -2933,6 +2933,10 @@ def series(self, x=None, x0=0, n=6, dir="+", logx=None, cdir=0):
If "x0" is an infinity object
"""
+ x0 = sympify(x0)
+ if isinstance(x0, Float):
+ x0 = Rational(x0)
+
if x is None:
syms = self.free_symbols
if not syms:
diff --git a/sympy/core/power.py b/sympy/core/power.py
index b62d839811..5f2ff67321 100644
--- a/sympy/core/power.py
+++ b/sympy/core/power.py
@@ -1734,7 +1734,7 @@ def mul(d1, d2):
else:
raise NotImplementedError()
if not d.is_positive:
- g = g.simplify()
+ g = ((b - f)/f).cancel()
_, d = g.leadterm(x)
if not d.is_positive:
raise NotImplementedError() The output is now,
|
But with the above change there are some failing tests in
|
Maybe the Lines 1736 to 1737 in 0322154
together with a yet another if not d.is_positive: test before raising NotImplementedError.
|
Do you mean a change something like this? But this change still raises the same errors. diff --git a/sympy/core/power.py b/sympy/core/power.py
index b62d839811..e4505b274d 100644
--- a/sympy/core/power.py
+++ b/sympy/core/power.py
@@ -1736,6 +1736,8 @@ def mul(d1, d2):
if not d.is_positive:
g = g.simplify()
_, d = g.leadterm(x)
+ if not d.is_positive:
+ g = ((b - f)/f).expand()
if not d.is_positive:
raise NotImplementedError() |
Also d has to be recomputed. |
Yes, this change is working, But should'nt all floats be converted to Rationals? diff --git a/sympy/core/power.py b/sympy/core/power.py
index b62d839811..4b54b19980 100644
--- a/sympy/core/power.py
+++ b/sympy/core/power.py
@@ -1736,6 +1736,9 @@ def mul(d1, d2):
if not d.is_positive:
g = g.simplify()
_, d = g.leadterm(x)
+ if not d.is_positive:
+ g = ((b - f)/f).cancel()
+ _, d = g.leadterm(x)
if not d.is_positive:
raise NotImplementedError() Adding code for converting diff --git a/sympy/core/expr.py b/sympy/core/expr.py
index e607234d0e..51f1283dd8 100644
--- a/sympy/core/expr.py
+++ b/sympy/core/expr.py
@@ -2933,6 +2933,10 @@ def series(self, x=None, x0=0, n=6, dir="+", logx=None, cdir=0):
If "x0" is an infinity object
"""
+ x0 = sympify(x0)
+ if isinstance(x0, Float):
+ x0 = Rational(x0)
+
if x is None:
syms = self.free_symbols
if not syms:
diff --git a/sympy/core/power.py b/sympy/core/power.py
index b62d839811..4b54b19980 100644
--- a/sympy/core/power.py
+++ b/sympy/core/power.py
@@ -1736,6 +1736,9 @@ def mul(d1, d2):
if not d.is_positive:
g = g.simplify()
_, d = g.leadterm(x)
+ if not d.is_positive:
+ g = ((b - f)/f).cancel()
+ _, d = g.leadterm(x)
if not d.is_positive:
raise NotImplementedError() |
There might be Floats also elsewhere in the expression. Changing x0 looks like a partial solution. I would recommend the change to Rationals only if nothing else would help. |
The change that you have suggested: diff --git a/sympy/core/power.py b/sympy/core/power.py
index b62d839811..12f8f723a6 100644
--- a/sympy/core/power.py
+++ b/sympy/core/power.py
@@ -1736,6 +1736,9 @@ def mul(d1, d2):
if not d.is_positive:
g = g.simplify()
_, d = g.leadterm(x)
+ if not d.is_positive:
+ g = ((b - f)/f).expand()
+ _, d = g.leadterm(x)
if not d.is_positive:
raise NotImplementedError() This is causing errors in |
This is unfortunately typical when series code is modified. It looks like the expanded |
Also on a side note, this output is different from what we get initially, after the change output is
But initially the output was,
|
It seems that the only test in test_limit_seq() that will run this code is this one: sympy/sympy/series/tests/test_limitseq.py Lines 90 to 91 in 0322154
where g.simplify() is zero. Currently, NotImplementedError is returned, but it would be more correct to return f**e . It looks like g.is_zero should be tested before recomputing g .
|
The error is resolved now, but now the output is in exact form,
instead of something like this,
Should'nt the outputs for both |
Not necessarily, I think. |
I guess same as #13061 ( another Maybe someone familiar could help to handle it - Earlier -
Current -
|
How about replacing the float with a dummy variable and then substituting back the |
I don't recall exactly either - most probably, it was to prevent a test case from failing, or, although unlikely, added to prevent the unnecessary expansion (at that time) and speed up slightly. |
This works fine with rational
S.Half
but fails with float0.5
:The text was updated successfully, but these errors were encountered: