Why does SymPy not work properly with real numbers?
<p>I am trying to evaluate an infinite sum in SymPy. While the first expression is calculated the way I expect it, SymPy seems to have trouble with the second expression.</p>

<pre><code>from sympy import *
n = symbols('n')
print Sum((2)**(-n), (n, 1, oo)).doit()
print Sum((0.5)**(n), (n, 1, oo)).doit()
</code></pre>

<p>Results in:</p>

<pre><code>1
Sum(0.5**n, (n, 1, oo))
</code></pre>

<p>I assume that the reason is that I am using a float number instead of an integer value.</p>

<p>Is there a way to approximate the sum instead?</p>

<p>That's <a href="https://github.com/sympy/sympy/issues/11642" rel="nofollow">a bug</a>. It ought to work. In general, however, it's best to prefer exact rational numbers over floats in SymPy, wherever possible. If you replace <code>0.5</code> with <code>Rational(1, 2)</code> it works. </p>

python sympy