Ask Your Question
1

Compute power series

asked 2023-07-09 14:42:59 +0100

Thrash gravatar image

I would like to compute $\sum_{k=0}^\infty (1+(-1)^k) x^k$. In Mathematica, one can do

In[1]:= Sum[(1+(-1)^k)*x^k,{k,0,Infinity}]                                     

          -2
Out[1]= -------
              2
        -1 + x

How does it work in Sage? I tried

sage: var('k')
k
sage: sum((1+(-1)^k)*x^k, k, 0, oo)
sum(((-1)^k + 1)*x^k, k, 0, +Infinity)

which doesn't give me any new information.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-07-09 15:04:13 +0100

achrzesz gravatar image

updated 2023-07-09 15:17:14 +0100

For example

giac('normal(sum((1+(-1)^k)*x^k,k,0,inf))').sage()

-2/(x^2 - 1)
edit flag offensive delete link more

Comments

1

Nice ! I didn't know this one.

Alternate way to express, possibly more "natural"' to Python/Sage :

sage: sum((1+(-1)^k)*x^k, k, 0, oo)._giac_().normal()._sage_()
-2/(x^2 - 1)

Note a convergence condition given by Sympy's solution (currently not directly translatable in Sage) :

sage: sum((1+(-1)^k)*x^k, k, 0, oo)._sympy_().doit()
Piecewise((1/(1 - x), Abs(x) < 1), (Sum(x**k, (k, 0, oo)), True)) + Piecewise((1/(x + 1), Abs(x) < 1), (Sum((-1)**k*x**k, (k, 0, oo)), True))

This convergence radius is important.

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2023-07-09 15:51:52 +0100 )edit

Thank you both!

Thrash gravatar imageThrash ( 2023-07-09 16:35:17 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-07-09 14:42:59 +0100

Seen: 168 times

Last updated: Jul 09 '23