Consider the following sum:

s[x_] = Sum[x^n*Log[x]^k*((n + k)/n!), {n, 0, Infinity}, {k, 0, n/2}]

and this partial sum:

f[x_, nMax_Integer] := Sum[x^n*Log[x]^k*((n + k)/n!), {n, 0, nMax}, {k, 0, n/2}]

When plotting them side by side, comparing as f converges to something with s, using the following code

 Plot[{Re@s[x], Im@s[x], Re@f[x, nMax], Im@f[x, nMax]} // 
   Evaluate, {x, -2, 2}, PerformanceGoal -> "Speed"], {{nMax, 3}, 0, 
  100, 1}]

, for some reason I get completely different curves of real and imaginary parts. What's happening? Is Mathematica treating n/2 in the upper limit of the sum over k in the series in some strange generalized sense of allowing n to be a half-integer? Is it actually expected behavior or a bug?

  • $\begingroup$ Mathematica does indeed not infrequently convert symbolic sums to certain analytical expressions when the upper limit is not explicitly a number $\endgroup$
    – LLlAMnYP
    Commented Feb 16, 2017 at 12:57

2 Answers 2


To expand on my comment consider this example

f1[n_] = Product[i, {i, n}]
f2[n_] := Product[i, {i, n}]
(* n! *)

where the difference is only Set vs. SetDelayed.

enter image description here

as you can see, while the delayed version waits for a numeric n to inject into the Product[] and then behaves as iterators normally do in MMA, the undelayed version symbolically evaluates to n! which is evaluated via the gamma-function for non-integer arguments.

A similar intermediate evaluation is happening for your first function which is set undelayed.


you may find this useful at least academically. we can rewrite the original form in terms of m->n/2, (taking pairs of terms for each m in the sum):

s[x_] := Sum[
  x^(2*m)*((k + 2*m)/(2*m)! + ((1 + k + 2*m)*x)/(1 + 2*m)!)*Log[x]^k,
  {m, 0, Infinity}, {k, 0, m}]

this agrees well with your finite n form. It is very slow so I'll just show a few values:

Table[{x, s[x], f[x, 100]}, {x, -1.9, 1.9, .5}]  // MatrixForm

enter image description here

This form can be evaluated for a symbolic x (use = instead of := ). It is really unwieldy however ( many pages of HypergeometricPFQ terms ).

This blows up for integer x btw.


manually simplifying a bit more yields a more reasonable analytic result:

s[x_] = Sum[
  x^(2*m)/(2*m)! *(k + 2*m + (k/(2 m + 1) + 1) x)*Log[x]^k, {m, 0, 
   Infinity}, {k, 0, m}] //FullSimplify

enter image description here

now its fast enough to plot:

 Plot[{Re[s[x]], Im[s[x]]}, {x, -2, 2}]

enter image description here


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.