# Problem with simplifying trigonometric summations

My problem arises when I evaluate

Q[s_, n_] = 1 - Sum[Cos[-2 π (s - 1)((k - 1)/n)]/n, {k, 1, n}]
F[s_, n_] = FullSimplify[Sum[Q[s, n], {j, 1, n}], {s, n} ∈ Integers]

λ = 3;
Table[{1 - Sum[Cos[-2 π (s - 1)*((k - 1)/λ)]/λ, {k, 1, λ}]}, {s, 1, 2^λ}][[All,1]]
Table[{Q[s, λ]}, {s, 1, 2^λ}][[All, 1]]
Table[{F[s, λ]}, {s, 1, 2^λ}][[All, 1]]
Clear[λ]


Here is a screenshot of the above code and the outputs

Output 29 and 30 are from the first two code boxes, while output 32-34 are from the three different generated tables.

I got this formula from a Wikipedia article on periodic sequences. Only output 32 is showing a result that agrees with the article. Why this is happening and how can I stop it from happening.

• Both F and Q expect a positive integer as their second argument, but Test is undefined. The question must be missing something. Jun 12, 2017 at 4:05
• Sorry, I was using Test instead of the lambda symbol while I was struggling with the problem. They are the same though Jun 12, 2017 at 4:10
• Q[s_, n_] = FullSimplify[1 - Sum[Cos[-2*Pi*(s - 1)* ((k - 1)/n)]/n, {k, 1, n}], Element[{s, n}, Integers]] evaluates to 1 and eliminates the indeterminate expression. Jun 12, 2017 at 4:22
• @BobHanlon But, with s == 1 and n == 3, 1 - Sum[Cos[-2 Pi*(1 - 1) (k - 1)/3]/3, {k, 3}] yields 0. Evidently, FullSimplify is returning a generic result. Jun 12, 2017 at 4:37
• Hint for improving your code: Table[Q[s, λ], {s, 1, 2^λ}] gives the same result as Table[{Q[s, λ]}, {s, 1, 2^λ}][[All, 1]], but with less computation. Jun 12, 2017 at 5:18

Your problem illustrates the difference between Set and SetDelayed. Q employs Set and so evaluates immediately.

Q[s_, n_] = 1 - Sum[Cos[-2 Pi*(s - 1) (k - 1)/n]/n, {k, n}]
(* 1 - (Cos[(π (2 + n - 2 s))/(2 n)] Csc[(π (-1 + s))/n] -
Cos[(-2 π + 3 n π + 2 π s - 4 n π s)/(2 n)] Csc[(π (-1 + s))/n])/(2 n) *)


The Csc[(π (-1 + s))/n] factor gives rise to the error messages when (-1 + s))/n is an integer. But, with SetDelayed,

R[s_, n_] := 1 - Sum[Cos[-2 Pi*(s - 1) (k - 1)/n]/n, {k, n}]


is evaluated only when called.

λ = 3;
Table[{R[s, λ]}, {s, 1, 2^λ}][[All, 1]]
(* {0, 1, 1, 0, 1, 1, 0, 1} *)