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

  • Thread starter Thread starter Gaussian97
  • Start date Start date
  • Tags Tags
    Sum
AI Thread Summary
The discussion focuses on evaluating the infinite sum using Python's SymPy library. A user initially attempts to compute the sum of exp(-n*x) from n=1 to infinity but encounters an issue where SymPy returns an unevaluated sum. They successfully find a workaround by substituting x with exp(-x) after breaking the expression into x^(-n). However, they seek a method to evaluate the sum directly without this substitution. It is noted that while SymPy can recognize certain series, it does not automatically simplify the sum of exp(-n*x) to a known form. Additionally, the importance of checking the range of summation is highlighted, with examples demonstrating how to use Piecewise functions in SymPy to handle different conditions for convergence.
Gaussian97
Homework Helper
Messages
683
Reaction score
412
TL;DR Summary
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
 
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))
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
1
Views
3K
Replies
1
Views
2K
Replies
2
Views
3K
Replies
4
Views
4K
Replies
15
Views
3K
Replies
9
Views
3K
Replies
15
Views
2K
Back
Top