# Why is this infinite series wrongly computed by Mathematica?

Could you let me know if Mathematica (newer versions) is able to correctly compute this one?

Sum[(-1)^(n + 1) Cos[3^n x]^3/3^n, {n, 1, Infinity}]

-
MMA 9.0.1 gives me -3Cos[x]/4 - is that what you expect? So does WolframAlpha wolfr.am/1hdQ8OK –  blochwave Jun 5 '14 at 8:50
@blochwave this is completely wrong. Wolfram|Alpha does the same mistake. Check it and convince yourself. –  Chris's sis Jun 5 '14 at 8:53
Ok, so is -3Cos[x]/4 the same answer you get in MMA 8.0? –  blochwave Jun 5 '14 at 9:03
@blochwave yes, but this is wrong. –  Chris's sis Jun 5 '14 at 9:05
As a workaround, Assuming[Element[x, Reals], Limit[Sum[(-1)^(n + 1) Cos[3^n x]^3/3^n, {n, 1, m}], m -> Infinity]] gives the correct result. –  Bob Hanlon Jun 5 '14 at 14:22

Partial sums of this sequence are given by:

Sum[(-1)^(n + 1) Cos[3^n x]^3/3^n, {n, 1, m}]

(* output: 1/4 Cos[3 x] - 1/4 (-(1/3))^m Cos[3^(1 + m) x] *)


For real $x$, we know this converges because $\cos(3^{1+m}x)$ is bounded.

Mathematica does not assume $x$ is real and, as Bob Hanlon notes, will produce the correct result by evaluating a partial sum, then assuming $x$ is real, then taking a limit.

Assuming[Element[x, Reals],
Limit[Sum[(-1)^(n + 1) Cos[3^n x]^3/3^n, {n, 1, m}], m -> Infinity]]


This yields what you expect. However, notice that this:

Assuming[Element[x, Reals],
Limit[Sum[(-1)^(n + 1) Cos[3^n x I ]^3/3^n, {n, 1, m}], m -> Infinity]]


does not produce (1/4)Cos[3xI] like you might expect, because the cosines become hyperbolic cosines (one of those nice complex/trig/exp identities) and these are not bounded for real values of $x$. Thus the limit is left unevaluated -- and the sum does not converge! The radius of convergence for your sum is zero. Why should Mathematica try to evaluate the sum without any indication that $x$ must be real?

Older version of Mathematica seem to have tried to give you the answer through other means, and we can still see that in Wolfram Alpha, producing an extraneous factor of -1, but newer versions (v10 here) leave the sum unevaluated. Rather than get a plus/minus error that a user may or may not know is incorrect, the user is left to do a bit more work to get the answer -- but now the answer is more likely to be rigorous/correct. So I'm going to answer your question here: Newer versions do compute this sum correctly by failing to do anything. This sum has radius of convergence zero. That is the correct behavior.

I cannot tell you what the particulars of the bug is -- in the sense that I don't know why it has made a sign error and not some other error -- but I can tell you that the reason this bug exists in the first place is that older versions seemed to want to help you out and try to evaluate the sum in a way that makes sense but was clearly error prone.

Rather than attempt to deal with series that do not converge and should not be evaluated as if they do converge, newer versions fail to evaluate these types of sums. That is probably the best thing for Mathematica to do, and knowledge of how these series converge/diverge should lead you to the workaround Bob Hanlon has given, which is the correct way to use Mathematica to obtain this type of summation.

-