12

If I sum all the positive-numbered Fourier coefficients of $\cos(x)$, I get the correct answer. If I sum the negative-numbered ones, I get a wrong answer. Splitting the sum into two parts somehow fixes the issue.

Sum[FourierCoefficient[Cos[x], x, k], {k, 1, Infinity}]
Sum[FourierCoefficient[Cos[x], x, -k], {k, 1, Infinity}]
Sum[FourierCoefficient[Cos[x], x, -k], {k, 1, 2}] +  Sum[FourierCoefficient[Cos[x], x, -k], {k, 3, Infinity}]

Out:
1/2
0
1/2
QuantumDot
  • 19,601
  • 7
  • 45
  • 121
Alex Bogatskiy
  • 1,680
  • 12
  • 19
  • 1
    This is the wrong place to report bugs. Please report bugs directly to Wolfram Research: https://www.wolfram.com/support/contact/email/. – QuantumDot Oct 07 '17 at 15:38
  • 3
    @QuantumDot is correct that bugs should be reported directly to Wolfram, Inc. Nonetheless, warning StackExchange uses about bugs is a useful service, and I thank you for doing so. Be sure to attached the usual bug header to your question, along with the case number that Wolfram, Inc assigns to your report, in a day or so, after others have had a chance to comment on the problem you identified here. – bbgodfrey Oct 07 '17 at 17:36

2 Answers2

15

The problem is not with Sum:

FourierCoefficient[Cos[x], x, -k]
(*  0  *)

FourierCoefficient[Cos[x], x, k]

Mathematica graphics

The second code is also much faster. It suggests to me that FourierCoefficient calls Integrate in the first case and uses a short-cut in the second. In fact Integrate (from a Trace of FourierCoefficient) gives a result that is only generically correct:

Integrate[E^(I k x) Cos[x], {x, -π, π}, 
 Assumptions -> k ∈ Integers, GenerateConditions -> False]
(* -((2 k Sin[k π])/(-1 + k^2))  *)
Michael E2
  • 235,386
  • 17
  • 334
  • 747
  • Interesting, so it's a consequence of the fact that the symbolic value of that integral formally breaks down at $k=\pm 1$? I wonder how FourierCoefficient normally avoids this problem. – Alex Bogatskiy Oct 07 '17 at 23:06
  • @level1807 It seems for a simple symbol k as opposed to an expression -k, that instead of integration, Cos[x] is expanded as a series in q = Exp[I x] and SeriesCoefficient is used to get the general series coefficient of order k. SeriesCoefficient does a better job than Integrate in this case. – Michael E2 Oct 08 '17 at 01:13
8

This is not an answer as why it happens. But the change happened after version 7.

I went back to verion 7 to be able to obtain different result. I tried versions 11, 10, 9, and 8 and they all gave same result as above. But in version 7:

enter image description here

Nasser
  • 143,286
  • 11
  • 154
  • 359