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:


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

  • $\begingroup$ 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$? $\endgroup$ Jul 28, 2017 at 12:13
  • $\begingroup$ @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? $\endgroup$ Jul 28, 2017 at 12:29
  • $\begingroup$ 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. $\endgroup$
    – CrmnCA
    Jul 28, 2017 at 12:33
  • $\begingroup$ @Dr.WolfgangHintze My bad, I think it is okay now. $\endgroup$
    – CrmnCA
    Jul 28, 2017 at 12:44
  • $\begingroup$ You can try /.\[Infinity]->0, but only if you normalize both sums to have an exponent of k on c. $\endgroup$
    – rogerl
    Jul 28, 2017 at 14:07

2 Answers 2


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.

  • $\begingroup$ Thank you very much, this was really helpful. $\endgroup$
    – CrmnCA
    Jul 28, 2017 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 *)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.