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>From the <a href="http://docs.sympy.org/latest/modules/concrete.html#concrete-functions-reference" rel="nofollow">docs:</a></p>

<blockquote>
  <p>If it cannot compute the sum, it returns an unevaluated Sum object.</p>
</blockquote>

<p>Another way to do this would be:</p>

<pre><code>In [40]: Sum((Rational(1,2))**(n), (n, 1, oo)).doit()
Out[40]: 1
</code></pre>

<p>Yet another way to do this:</p>

<pre><code>In [43]: Sum((0.5)**(n), (n, 1, float('inf'))).doit()
Out[43]: 1.00000000000000
</code></pre>

<p>To approximate, you can take a sufficiently large number instead of infinity:</p>

<pre><code>In [51]: import sys

In [52]: Sum((0.5)**(n), (n, 1, sys.maxint)).doit()
Out[52]: 1.00000000000000
</code></pre>

python sympy