# Extracting order n coefficients from a non-closed form summation

I am trying to evaluate the following expression when $c=0$:

$$\sum _{k=1}^{\infty} \dfrac{(k+1) c^{k-1} g(k)}{(k-1)!}+\left(\sum_{k=0}^{\infty} \dfrac{(k+1) c^k g(k)}{k!}\right)^2$$

(copyable Mathematica plaintext version):

Sum[((k+1) c^(k-1) g[k])/(k-1)!, {k, 1, Infinity}] +
(Sum[((k+1) c^k g[k])/k!, {k, 0, Infinity}])^2


but when I tell Mathematica to do so, it simply gives me:

$$\sum_{k=1}^{\infty} \dfrac{0^{k-1} (k+1) g(k)}{(k-1)!}+\left(\sum _{k=0}^{\infty} \dfrac{0^k (k+1) g(k)}{k!}\right)^2$$

So to find the result that I am looking for, I suppose I should somehow isolate the order zero terms $\cal{O}(c^0)$ and then evaluate these when $c=0$, so the final result is:

$$2g(1)+g(0)^2$$

Is there any way of obtaining the $0$th order coefficients from a non-closed expression as the one I have using only Mathematica?

• You've already given an excellent way to produce just the constant term, if that is your only problem. I presume your actual problem is producing the coefficient of $c^k$? – J. M. will be back soon Jul 28 '17 at 12:13
• @CrmnCA The first term of the first sum is c^(-1) which is infinite for $c\to 0$ unless $g(0) = 0$ What do you expect? – Dr. Wolfgang Hintze Jul 28 '17 at 12:29
• Actually, it is for $c^0$.However I will potentially have more complicated expressions where it is not so straightforward to compute the result by hand. – CrmnCA Jul 28 '17 at 12:33
• @Dr.WolfgangHintze My bad, I think it is okay now. – CrmnCA Jul 28 '17 at 12:44
• You can try /.\[Infinity]->0, but only if you normalize both sums to have an exponent of k on c. – rogerl Jul 28 '17 at 14:07

## 2 Answers

First, you should always include copyable Mathematica plaintext, so that people can help you without having to type in your input. I modified your question to include a copyable version.

Now, one idea is to replace c^n_ instead of c.

expr = Sum[((k+1)c^(k-1)g[k])/(k-1)!,{k,1,Infinity}] +
(Sum[((k+1)c^k g[k])/k!,{k,0,Infinity}])^2;

expr /. c^n_ :> Piecewise[{{1, n==0}}, 0]


g[0]^2 + 2 g[1]

This won't work if the exponent can be negative, although in that case you can do something like:

Sum[c^k g[k], {k, -1, Infinity}] /. c^n_ :> Piecewise[{{Infinity, n<0}, {1, n==0}}, 0] //InputForm


Sum[g[k]*Piecewise[{{Infinity, k < 0}, {1, k == 0}}, 0], {k, -1, Infinity}]

and at least Mathematica will indicate that there is an issue.

• Thank you very much, this was really helpful. – CrmnCA Jul 28 '17 at 15:37

Maybe these lines can help you to find the appropriate command for your case:

(* 1 *)
c^k /. c -> 0

(* Out[314]= 0^k *)

(* 2 *)
Assuming[{k >= 0}, c^k /. c -> 0]

(* Out[321]= 0^k *)

(* 3 *)
Limit[c^k, c -> 0, Assumptions -> k >= 0]

(* Out[320]= 0 *)

(* 4 *)
Limit[c^k, c -> 0, Assumptions -> k == 0]

(* Out[319]= 1 *)