Theorems:
$$ \sum_{n=0}^{N-1} \cos(a + nd) = \frac{\sin(Nd / 2)}{\sin(d / 2)} \cos \bigg ( a + \frac{(N - 1) d}{2} \bigg ) \; \mathrm{for} \; \sin(d / 2) \ne 0 \\ \sum_{n=0}^{N-1} \sin(a + nd) = \frac{\sin(Nd / 2)}{\sin(d / 2)} \sin \bigg ( a + \frac{(N - 1) d}{2} \bigg ) \; \mathrm{for} \; \sin(d / 2) \ne 0 $$
Is this numerically the case?
from __future__ import print_function, division
import numpy as np
def predicted_cos_sum(a, d, n):
d2 = d / 2.
return np.sin(n * d2) / np.sin(d2) * np.cos(a + (n - 1) * d / 2)
def predicted_sin_sum(a, d, n):
d2 = d / 2.
return np.sin(n * d2) / np.sin(d2) * np.sin(a + (n - 1) * d / 2)
def actual_cos_sum(a, d, n):
angles = np.arange(n) * d + a
return np.sum(np.cos(angles))
def actual_sin_sum(a, d, n):
angles = np.arange(n) * d + a
return np.sum(np.sin(angles))
# When sin(d / 2) != 0
print('cos', predicted_cos_sum(4, 0.2, 17), actual_cos_sum(4, 0.2, 17))
print('sin', predicted_sin_sum(4, 0.2, 17), actual_sin_sum(4, 0.2, 17))
cos 7.7038472261 7.7038472261 sin -6.27049470825 -6.27049470825
# When sin(d / 2) ~ 0
print('cos : sin(d/2) ~ 0;', predicted_cos_sum(4, np.pi * 2, 17), actual_cos_sum(4, np.pi * 2, 17))
print('sin : sin(d/2) ~ 0;', predicted_sin_sum(4, np.pi * 2, 17), actual_sin_sum(4, np.pi * 2, 17))
cos : sin(d/2) ~ 0; 7.85033095132 -11.1119415547 sin : sin(d/2) ~ 0; 9.08928024892 -12.8656424202
The basic order of play is to rearrange the sum so that the terms in the current iteration of the sum cancel terms in the previous iteration, and we can therefore get rid of the sum. This is a telescoping series.
We will do the cosine series first. The sine proof is almost identical.
Following the notation of the arithmetic progression of cosines paper, we remember that (angle sum rules):
$$ \sin(A + B) = \sin A \cos B + \cos A \sin B \\ \sin(A - B) = \sin A \cos B - \cos A \sin B \\ \implies \\ \sin(A + B) - \sin(A - B) = 2\cos A \sin B $$Let:
$$ C \triangleq \sum_{n=0}^{N-1}\cos(a + nd) $$Only if $\sin(d/2) \ne 0$, we can safely multiply both sides by $2\sin(d/2)$:
$$ 2C \sin(d / 2) = \sum_{n=0}^{N-1}2 \cos(a + nd) \sin(d/2) $$Use angle sum result:
Now the series will telescope. Write: $$ s_{2n-1} \triangleq \sin \bigg ( a + \frac{(2n - 1)d}{2} \bigg ) \\ s_{2n+1} \triangleq \sin \bigg ( a + \frac{(2n + 1)d}{2} \bigg ) $$
The value of the sum when $n=k$ : $s_{2k + 1} - s_{2k - 1}$.
The value of the sum when $n=k+1$ : $s_{2(k+1)+1} - s_{2(k+1) - 1} = s_{2k+3} - s_{2k+1}$
Therefore the second term at each iteration cancels the first term at the previous iteration, and the sum retains only the first term from the last iteration and the second term from the first:
Now we go the opposite direction with the $\sin(A + B) - \sin(A - B) = 2\cos A \sin B$ rule. We need to do some fancy footwork to get the arguments into $A \pm B$ form:
Then we solve for $C$ to finish the proof.
$\blacksquare$
This is almost identical, but applying:
$$ \cos(A + B) = \cos A \cos B - \sin A \sin B \\ \cos(A - B) = \cos A \cos B + \sin A \sin B \\ \implies \\ \cos(A + B) - \cos(A - B) = -2 \sin A \sin B $$Let:
$$ S \triangleq \sum_{n=0}^{N-1}\sin(a + nd) $$Only if $\sin(d/2) \ne 0$, we can safely multiply both sides by $-2 \sin(d / 2)$ and continue with the same steps as for the cosine:
$$ -2S \sin(d / 2) = \sum_{n=0}^{N-1}-2 \sin(a + nd) \sin(d/2) \\ = \sum_{n=0}^{N-1} \cos \bigg ( a + \frac{(2n + 1)d}{2} \bigg ) - \cos \bigg ( a + \frac{(2n - 1)d}{2} \bigg ) \\ = \cos \bigg ( a + \frac{(2N - 1)d}{2} \bigg ) - \cos \bigg ( a - \frac{d}{2} \bigg ) \\ = -2 \sin \bigg (a + \frac{(N - 1)d}{2} \bigg ) \sin (Nd / 2) $$Then solve for $S$.
$\blacksquare$