-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Unexpected truncation to integer when using evalf #13365
Labels
Comments
SymPy evaluates sums of hypergeometric series by using integer arithmetic. All numbers are truncated to integers by
To make use of non-integer factors the truncation should occur after the operation, not before:
|
asmeurer
added
concrete
core.evalf
Wrong Result
The output produced by SymPy is mathematically incorrect.
labels
Sep 28, 2017
Mayer318
added a commit
to FIT-CSE2410-A-Bombs/sympy
that referenced
this issue
Nov 14, 2017
TheGluck
added a commit
to FIT-CSE2410-A-Bombs/sympy
that referenced
this issue
Nov 14, 2017
cchaffin2013
added a commit
to FIT-CSE2410-A-Bombs/sympy
that referenced
this issue
Dec 11, 2017
cchaffin2013
added a commit
to FIT-CSE2410-A-Bombs/sympy
that referenced
this issue
Dec 11, 2017
Possible solution: diff --git a/sympy/core/evalf.py b/sympy/core/evalf.py
index 0ce7def..5815c61 100644
--- a/sympy/core/evalf.py
+++ b/sympy/core/evalf.py
@@ -1127,11 +1127,10 @@ def hypsum(expr, n, start, prec):
s = term
k = 1
while abs(term) > 5:
- term *= MPZ(func1(k - 1))
- term //= MPZ(func2(k - 1))
+ term *= func1(k - 1)/func2(k - 1)
s += term
k += 1
- return from_man_exp(s, -prec)
+ return from_man_exp(MPZ(s), -prec)
else:
alt = g < 0
if abs(g) < 1:
diff --git a/sympy/core/tests/test_evalf.py b/sympy/core/tests/test_evalf.py
index 27daed9..46de791 100644
--- a/sympy/core/tests/test_evalf.py
+++ b/sympy/core/tests/test_evalf.py
@@ -525,3 +525,9 @@ def test_issue_13098():
assert ceiling(log(S('9.'+'9'*20), 10)) == 1
assert floor(log(20 - S('9.'+'9'*20), 10)) == 1
assert ceiling(log(20 - S('9.'+'9'*20), 10)) == 2
+
+
+def test_issue_13365():
+ s = Sum(1.9**x/factorial(x), (x, 0, oo))
+ a = S.Exp1**1.9
+ assert (s - a).evalf() < 1e-12 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Calling
Sum(1.9**k/factorial(k), (k, 0, oo)).evalf()
returns the value for e^1 instead of e^1.9. CallingSum(x**k/factorial(k), (k, 0, oo)).doit().subs(x,1.9)
however gives the expected result.The text was updated successfully, but these errors were encountered: