# Algorithms for Various Trigonometric Power Sums
## 5 Twisted Trigonometric Power Sums
\begin{array}{l}\text{Do[If[Exp[($2(i$-$v$-$k$)]$] $\pi/m$]}==-1,\text{H}=(m+1),\text{H}=(1+(-1)^{\wedge}\text{m})/2];\\ \text{e}2=(-1)^{\wedge}\text{(i$-$v$+$k$) Binomial[$2$ (i$-$v$),$k$]$H/2$^{\wedge}$($2(i$-$v$)$-$1);\text{e}1$ =$e1$ +$ e2,[$k,0,(i$-$v$)]$];\\ \text{(sgn}==-1)\&\&\&(1==2),\\ \text{e}1=-\text{Binomial[$2$ (i$-$v$),$i$-$v$]$}(1+(-1)^{\wedge}\text{m})/2 \text{($2$ (i$-$v$)+$1);}\\ \text{Do[If [Exp[($i$-$v$-$k$)]$ $\pi/m$]}==-1,\text{H}=(m+1),\text{H}=(1+(-1)^{ \wedge}\text{(i$-$v$+$m$-$k$))}/2];\\ \text{e}2=(-1)^{\wedge}\text{(i$-$v$+$k$) Binomial[$2$ (i$-$v$),$k$]$H/2$^{\wedge}$($2(i$-$v$)$-$1);\text{e}1$ =$e1$ +$ e2,[$k,0,i$-$v$]$];\\ \text{If}[]=2,\text{e}1=(-1)^{\wedge}\text{i Binomial[j,i][$2$ e1$ -$(-1)^{\wedge}\text{m}),}\\ \text{e}1=(-1)^{\wedge}\text{i Binomial[j,i][$i$] e1$;totval = totval + e1,i,v + 1j]};\\ \text{Which[(sgn == 1)\&\&(1==1),e3=m-1,\text{(sgn == 1)\&\&(1==2),e3=2m-1,}\\ \text{(sgn == --1)\&\&(1==1),e3=-(1+(-1)^{\wedge}\text{m})/2,\text{(sgn == --1)\&\&(1==2),e3=-1)};}\\ \text{scndval = (-1)^{\wedge}\text{Binomial[j,v]}\,\text{e}3;totval = totval + scndval;}\\ \text{totval = totval + (-1)^{\wedge}\text{v Binomial[j,v]}\,\text{Sum(sgn)}^{ \wedge}\text{k,[k,1,Im-1]};\\ \text{Print[``For I=\",J,\",sgn=\",sgn,\",\"j=\",v=\",v,\" and m=\",m,\", the sum of the basic trigonometric power sums in \(U_{v,j,l}^{\pm}\) is equal to \",totval]]].}\end{array} \]  
This interim module is essentially the same as the previous one, except it calculates the last two terms in (68) and adds them to total. Therefore, to produce a code that determines values of \(V_{v,j,l}^{\pm}(m)\), we only require the code to evaluate the first term on the rhs of (68) when \(j\geq v\). Moreover, this term is identical to the rhs of (67), except for the upper limit of the outer sum. Hence, one can use the same code to calculate (67), except for a change in the upper limit. To handle this problem, a conditional If instruction has been inserted near the beginning of the program. This instruction tests whether the upper limit of the outer sum equals \(j\) when \(j<v\) or equals \(v-1\) for all other values of \(j\). It then assigns a variable called upplmt to whichever case applies. Moreover, the same instructions can be used to evaluate the double sum in either case. As a result of the introduction of upplmt into the code, there needs to be another conditional If instruction or statement following the calculation of the double sum, which calculates the remaining terms in (68) for \(v\leq j\). In Section 3, we introduced a summand factor to cover both the \(l\!=\!1\) and \(l\!=\!2\) cases of \(S_{v,l}^{-}(m)\). Here, we adopt this approach further by noting that the four cases of \(S_{v,l}^{\pm}(m)\) all include \(\zeta(2v-2n)s(v,n)/\pi^{2v-2n}(2v-2n)_{2n}\) in their summands. Therefore, we can employ the Which instruction again to determine the appropriate summation factor for the case of \(V_{v,j,l}^{\pm}(m)\) we are studying. This is achieved by implementing the following instruction:  
\[ \begin{array}{l}\text{Which[sgn == 1 \&\&(1==1),\,\text{Sfctr}=2^{\wedge}(2n+1)\,\,(m^{\wedge}(2\,v -2\,\text{n})\,\,-1),}\\ \text{sgn == 1 \&\&(1==2),\,\text{Sfctr}=2^{\wedge}(2v+1)\,\,(m^{\wedge}(2v-2n) \,\,-1),}\\ \text{sgn == --1 \&\&(1==1),\,\text{Sfctr}=2^{\wedge}(2n)(1+(-1)^{\wedge}\text{m})(((2^{ \wedge}(2\,n-2\,v+1)\,\,-1)\,\,m^{\wedge}(2\,v-2n)\,\,-1),}\\ \text{sgn == --1 \&\&(1==2),\,\text{Sfctr}=(2^{\wedge}(2n+2)-2^{\wedge}(2v+1))\,\,m^{ \wedge}(2v-2n)\,\,-\,(-1)^{\wedge}\text{m}\,\,2^{\wedge}(2v+1)\\ \text{+}((-1)^{\wedge}\text{m}\,\,-1)2^{\wedge}(2n+1)].}\end{array} \]  
Now, we are in a position to present an algorithm for determining rational values of \(V_{v,j,l}^{\pm}(m)\) by combining the preceding material into one module called \(\text{Vpm}[sgn\_{-}]\_{-,\,\text{v}-,}\), \(\text{j--}\). To execute the module, one needs to input the values of \(sgn\), \(l\), \(v\), \(j\) and \(m\), although the value of \(m\) can be algebraic.