# Indices in a sum of series

how I can express correctely in one serie the following expresion $$\sum _{(k=-20) (k\neq 0)}^{20} -\frac{2 \left(\frac{3}{2} \pi \csc \left(\frac{1}{2} (2 \pi k+\pi )\right) \text{sech}\left(\frac{1}{3} \pi (2 k+1)\right)-\frac{2}{3} \pi \sec (\pi k) \text{sech}\left(\frac{3}{4} \pi (2 k+1)\right)\right)}{\pi ^2 k (2 k+1)^3}$$ normaly I must to divide the expresion in two series from k=-infinite to -1 and for 1 to Infinity to avoid the zero thanks

• Sum[If[k != 0, f[k], 0], {k, -20, 20}] Nov 27, 2017 at 12:11
• How about Sum[f[k] + f[-k], {k, 20}]? Nov 27, 2017 at 13:01

One way could be to explicitly define the index

ks = Join[Range[-5, -3], Range[-1, 1], Range[3, 5]]
Sum[f[i], {i, ks}]


f[-5] + f[-4] + f[-3] + f[-1] + f + f + f + f + f

One can also use a conditional expression as suggested by @coolwater, but it will consume more time

RepeatedTiming[Sum[If[k != 0, f[k], 0], {k, -200, 200}]][]


0.0004

RepeatedTiming[ks = Join[Range[-200, -1], Range[1, 200]];
Sum[f[i], {i, ks}]][]


0.000221

• thanks Sumit but it is possible do it more elegant as the example above Nov 27, 2017 at 12:04
• I am not sure what kind of elegance you are looking for, but my feeling is it might cost some extra time. Anyway, wait for some better answer :) Nov 27, 2017 at 12:40