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
Click For Summary
SUMMARY

This discussion addresses the limitations of evaluating sums in SymPy, specifically when attempting to compute the infinite sum of the expression exp(-n*x) using the summation function. Users found that while SymPy can recognize certain summation forms, it fails to automatically simplify the expression without manual substitution. The recommended approach involves breaking the expression into x^(-n) and substituting x with exp(-x) to achieve the desired result. Additionally, users are advised to check the range of summation to ensure accurate evaluations.

PREREQUISITES
  • Familiarity with Python programming
  • Understanding of the SymPy library (version 1.8 or later)
  • Knowledge of infinite series and summation concepts
  • Basic experience with symbolic mathematics
NEXT STEPS
  • Learn advanced techniques for symbolic manipulation in SymPy
  • Explore the use of Dummy variables in SymPy for better range handling
  • Investigate the properties of infinite series and convergence criteria
  • Study the implementation of Piecewise functions in SymPy for conditional evaluations
USEFUL FOR

Mathematicians, data scientists, and software developers who utilize SymPy for symbolic computation and require efficient methods for evaluating infinite sums.

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
Technology news on Phys.org
Probably not.

Sympy knows that \sum_{n=1}^\infty z^n = z/(1 - z) when |z| < 1, but can't work out that \sum_{n=1}^\infty e^{-nx} reduces to that on substituting z = e^{-x}. 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
9K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 15 ·
Replies
15
Views
2K