'sympy - finding analytical form of infinite geometric series with symbolic growth rates

I tried to find the analytical form of the infinite geometric series using sympy:

from sympy import *
i, T, r = symbols('i T r')
Sum((1/(1+r))**i,(i,T,oo)).doit()
simplify(Sum((1/(1+r))**i,(i,T,oo)))
simplify(Sum((1/(1+r))**i,(i,1,oo)).doit())
_.n()

The closed form is a routine exercise of algebra, so I assumed it won't be challenging for sympy. But the result is always the non-derived summation form. The finite sum, however, can be evaluated to obtain closed form:

simplify(Sum((1/(1+r))**i,(i,1,T)).doit())

Is this problem solvable with sympy? If no, can it be solved by any other package of Python?



Solution 1:[1]

Is r positive? If so, declare it so and you will get a closed form:

>>> r = Symbol('r', positive=True)
>>> i, T = symbols('i T')
>>> Sum((1/(1+r))**i,(i,T,oo)).doit().simplify()
       1 - T
(r + 1)     
------------
     r      

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 smichr