# Algorithms for Various Trigonometric Power Sums
## 4 Basic Trigonometric Power Sums
Thus, by typing the instruction as  
\[\sin^{2m}\Bigl{(}\frac{x}{2}\Bigr{)}=\frac{(-1)^{m}}{2^{2m-1}}\sum_{j=0}^{m} \frac{(-2m)_{j}}{j!}\cos\bigl{(}(m-j)x\bigr{)}-\frac{1}{2^{2m}}\binom{2m}{m}. \tag{54}\]9  
followed by  
\[\sum_{k=0}^{n}(-1)^{k}\sin^{2m}\Bigl{(}\frac{k\pi}{n}\Bigr{)} =\frac{(-1)^{m}}{2^{2m-1}}\sum_{j=0}^{m}(-1)^{j}\frac{(-2m)_{j}} {j!}\sum_{k=0}^{n}(-1)^{k}\cos\Bigl{(}\frac{2(m-j)k\pi}{n}\Bigr{)}\]0  
one obtains following output:  
\[\sum_{k=0}^{n}(-1)^{k}\sin^{2m}\Bigl{(}\frac{k\pi}{n}\Bigr{)} =\frac{(-1)^{m}}{2^{2m-1}}\sum_{j=0}^{m}(-1)^{j}\frac{(-2m)_{j}} {j!}\sum_{k=0}^{n}(-1)^{k}\cos\Bigl{(}\frac{2(m-j)k\pi}{n}\Bigr{)}\]1  
Putting \(x=k\pi/n\) in the above result yields \(H_{1}(m,n,j)\), which is given by  
\[\sum_{k=0}^{n}(-1)^{k}\sin^{2m}\Bigl{(}\frac{k\pi}{n}\Bigr{)} =\frac{(-1)^{m}}{2^{2m-1}}\sum_{j=0}^{m}(-1)^{j}\frac{(-2m)_{j}} {j!}\sum_{k=0}^{n}(-1)^{k}\cos\Bigl{(}\frac{2(m-j)k\pi}{n}\Bigr{)}\]2 \[\sum_{k=0}^{n}(-1)^{k}\sin^{2m}\Bigl{(}\frac{k\pi}{n}\Bigr{)} =\frac{(-1)^{m}}{2^{2m-1}}\sum_{j=0}^{m}(-1)^{j}\frac{(-2m)_{j}} {j!}\sum_{k=0}^{n}(-1)^{k}\cos\Bigl{(}\frac{2(m-j)k\pi}{n}\Bigr{)}\]3  
As in the case of \(H_{2}(m,n,j)\), the above result can be simplified further by the application of trigonometric identities. Therefore, after a bit of manipulation, one finds that  
\[\sum_{k=0}^{n}(-1)^{k}\sin^{2m}\Bigl{(}\frac{k\pi}{n}\Bigr{)} =\frac{(-1)^{m}}{2^{2m-1}}\sum_{j=0}^{m}(-1)^{j}\frac{(-2m)_{j}} {j!}\sum_{k=0}^{n}(-1)^{k}\cos\Bigl{(}\frac{2(m-j)k\pi}{n}\Bigr{)}\]4  
However, (64) is not valid when \((m-j)/n=2p+1\) and \(p\) is a non-negative integer. Thus, \(H_{1}(m,n,j)=(n+1)\), and we arrive at (52). Finally, if we replace the sum over \(k\) by \(H_{1}(m,n,j)\) and introduce (62) into (56), then we obtain (51). The results in Lemma 1 indicate that the values of \(S_{0,1}^{-}(m,n)\) and \(S_{0,2}^{-}(m,n)\) are rational. Even though they have been expressed as formulas, in reality, they represent algorithms when one wishes to determine values from them. Consequently, Mathematica modules need to be created. As an example, let us consider the second result in (49). This basic trigonometric sum can be programmed as  
\[\sum_{k=0}^{n}(-1)^{k}\sin^{2m}\Bigl{(}\frac{k\pi}{n}\Bigr{)} =\frac{(-1)^{m}}{2^{2m-1}}\sum_{j=0}^{m}(-1)^{j}\frac{(-2m)_{j}} {j!}\sum_{k=0}^{n}(-1)^{k}\cos\Bigl{(}\frac{2(m-j)k\pi}{n}\Bigr{)}\]5  
For relatively small values of \(n\), typically less than or equal to 6, the above instruction generates rational values. For example, for \(m=16\) and \(n=6\), Mathematica prints out  
In[19] \text{:= Timing[Szero1 minus[16, 6]]}  
\[\sum_{k=0}^{n}(-1)^{k}\sin^{2m}\Bigl{(}\frac{k\pi}{n}\Bigr{)} =\frac{(-1)^{m}}{2^{2m-1}}\sum_{j=0}^{m}(-1)^{j}\frac{(-2m)_{j}} {j!}\sum_{k=0}^{n}(-1)^{k}\cos\Bigl{(}\frac{2(m-j)k\pi}{n}\Bigr{)}\]6However, putting \(m=16\) and \(n=8\) yields  
In[20]:= Timing[Szero1 minus1[16; 8]]  
Out[20] = [0.00016, 32769/32768 - 2 \text{ Cos}[\pi/8]^{32}-2\text{ Sin}[\pi/8]^{32}]\). In number form, this yields 0.841277837753296. Unfortunately, one cannot tell whether the value is rational or not, unless the trigonometric powers are expressed as wards as in Section 5. To create a module that is able to calculate rational values of \(S_{0,1}^{-}(m,n)\) for even integer values of \(n\), we require a Do loop to determine each of the contributions from the summand of the second result of (49). Before entering the Do loop, we calculate the second term on the rhs first, which will be denoted as e1. To obtain the correct value of the summand, we introduce an If statement with the condition being whether \(\exp((2(m-j)i\pi/n)\) is equal to \(-1\) or not. If it is, then \(H2(m,n,j)\) or H2 as it is denoted in the module below equals \(n+1\). Otherwise, it will equal \((1+(-1)^{n})/2\). Then, the summand, which will be denoted as e2, can be evaluated and summed with e1 to yield a new value for e1.