<s>[INST] How to simplify $\sin(n\frac{\pi}{2})$ as we do with $\cos(n\pi)$ When calculating Fourier series we almost always get some expression that look like:
\begin{equation} ...\left[\cos(nx) \right]_0^\pi.
\end{equation}
Then we use $\cos(n\pi) = (-1)^n$.
However, lately I have come across expressions like this:
\begin{equation} ...\left[\sin(nx) \right]_0^{\pi/2}.
\end{equation}
Which is equal to:
\begin{array}{|c|c|c|c|}
\hline
n& 1 & 2 & 3 & 4 \\ \hline
\sin(nx)&\sin(\frac{\pi}{2}) & \sin(\pi) & \sin(\frac{3\pi}{2})& \sin(2\pi)\\ \hline
 val &1 &0 &-1 &0\\ \hline
\end{array}
How do we simplify this so that it looks like the $\cos(n\pi) = (-1)^n$.
 [/INST] You have a sequence with period $4$ (specifically $0,1,0,-1,0,1,\cdots$), but $(-1)^n$ has period $2$, so it can't be used in this form.
However, $(-1)^{\binom n2}=(-1)^{n(n-1)/2}$ does have period $4$:
$$(-1)^0=1,\quad(-1)^1=-1,\quad(-1)^3=-1,\quad(-1)^6=1,$$
$$(-1)^{10}=1,\quad(-1)^{15}=-1,\quad(-1)^{21}=-1,\quad(-1)^{28}=1,$$
$$\cdots$$
To prove periodicity:
$$(-1)^{(n+4)(n+3)/2}=(-1)^{(n^2+7n+12)/2}=(-1)^{4n+6+(n^2-n)/2}\\=((-1)^2)^{2n+3}(-1)^{n(n-1)/2}=(-1)^{n(n-1)/2}$$
Now let's try shifting and combining these:
$$\begin{matrix}n&=&(0,&1,&2,&3,&\cdots) \\ (-1)^n&=&(1,&-1,&1,&-1,&\cdots) \\ (-1)^{n(n-1)/2}&=&(1,&1,&-1,&-1,&\cdots) \\ (-1)^{n(n+1)/2}&=&(1,&-1,&-1,&1,&\cdots) \\ (-1)^{n(n-1)/2}-(-1)^{n(n+1)/2}&=&(0,&2,&0,&-2,&\cdots)\end{matrix}$$
And there's your answer:
$$\sin(n\pi/2)=\frac{(-1)^{n(n-1)/2}-(-1)^{n(n+1)/2}}{2}$$
In fact any $4$-periodic sequence can be expressed in this way:
$$f_n=\frac{1+(-1)^n+(-1)^{n(n-1)/2}+(-1)^{n(n+1)/2}}{4}=(1,0,0,0,1,0,0,0,1,\cdots)$$
$$(a_0,a_1,a_2,a_3,a_0,a_1,a_2,a_3,a_0,\cdots)=a_0f_n+a_1f_{n-1}+a_2f_{n-2}+a_3f_{n-3}$$
$$=a_0\frac{1+(-1)^n+(-1)^{n(n-1)/2}+(-1)^{n(n+1)/2}}{4} \\ +a_1\frac{1-(-1)^n+(-1)^{n(n-1)/2}-(-1)^{n(n+1)/2}}{4} \\ +a_2\frac{1+(-1)^n-(-1)^{n(n-1)/2}-(-1)^{n(n+1)/2}}{4} \\ +a_3\frac{1-(-1)^n-(-1)^{n(n-1)/2}+(-1)^{n(n+1)/2}}{4}$$
See also What is a mathematical expression for the sequence $\{1,1,-1,-1,1,1,-1,-1,\dots\}$? and the linked posts.
</s>