Is it possible to evaluate a sum in SymPy without breaking the expression?

  • Context: Python 
  • Thread starter Thread starter Gaussian97
  • Start date Start date
  • Tags Tags
    Sum
Gaussian97
Homework Helper
Messages
683
Reaction score
412
TL;DR
SymPy doesn't evaluate a sum
I want to evaluate the sum

gif.gif


using Python and SymPy, I'm relatively new using SymPy and the first thing I tried was

Python:
from sympy import exp, oo, summation, symbols

n, x = symbols('n,x')
summation(exp(-n*x), (n, 1, oo))

But it doesn't work, it just returns the unevaluated sum. I can make it work using

Python:
from sympy import exp, oo, summation, symbols

n, x = symbols('n,x')
f = exp(-x)
summation(x**(-n), (n, 1, oo)).subs(x,f)

But I would like to know if it is possible to make it work without need to break the expression into x^n and then substitute x by e^-x.

Thank you
 
  • Like
Likes   Reactions: pbuk
on Phys.org
Probably not.

Sympy knows that [itex]\sum_{n=1}^\infty z^n = z/(1 - z)[/itex] when [itex]|z| < 1[/itex], but can't work out that [itex]\sum_{n=1}^\infty e^{-nx}[/itex] reduces to that on substituting [itex]z = e^{-x}[/itex]. You have to do that yourself.

You may also want to check the range of your summation:
Python:
>>> from sympy import *
>>> x = Dummy('x', real = True, positive=True)
>>> summation(x**n, (n, 1, oo))
Piecewise((_x/(1 - _x), _x < 1), (Sum(_x**n, (n, 1, oo)), True))
>>> summation(x**n, (n, 0, oo))
Piecewise((1/(1 - _x), _x < 1), (Sum(_x**n, (n, 0, oo)), True))
 
  • Like
Likes   Reactions: WWGD

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 9 ·
Replies
9
Views
10K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 15 ·
Replies
15
Views
4K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 15 ·
Replies
15
Views
3K