<s>[INST] Evaluation of a general trigonometric integral How can I evaluate the integral
$$\int\sin^k(x)\ dx$$
in which I don't know if $k$ is an even or an odd number?
 [/INST] Let $f(x) = \sin^k x$.
We have $\sin x = \frac{e^{ix} - e^{-ix}}{2i}$. So 
$$
\begin{align*}
f(x) &= \frac{1}{(2i)^k}(e^{ix} - e^{-ix})^k \\
&=\frac{1}{(2i)^k} \sum_{j = 0}^k \binom{k}{j} (e^{ix})^{k-j} (-e^{-ix})^j \\
&=\frac{1}{(2i)^k} \sum_{j = 0}^k (-1)^j \binom{k}{j} e^{(k-2j)ix} \\
&=\frac{1}{(2i)^k} \left(\sum_{0 \leq j < k/2} \left[(-1)^j\binom{k}{j}e^{(k-2j)ix} + (-1)^{k-j} \binom{k}{k-j}e^{(2j-k)ix} \right] + \varepsilon (-1)^{k/2}\binom{k}{k/2}\right), 
\end{align*}
$$
where the term with $\varepsilon$ appears only if $k$ is even, and then $\varepsilon = 1$. On the last line, we've grouped together symmetric terms of the sum. From here on, we distinguish between even $k$ and odd $k$.
If $k$ is even, say $k = 2m$, then
$$
\begin{align*}
f(x) &= \frac{(-1)^m}{2^{2m}} \left[ \sum_{j = 0}^{m-1} (-1)^{j}  \binom{2m}{j} \left(e^{2(m-j)ix} + e^{2(j-m)ix}\right) + (-1)^m\binom{2m}{m} \right]\\
&= \frac{1}{2^{2m}} \left[ \sum_{j=0}^{m-1} (-1)^{m-j} \binom{2m}{j} \cdot 2 \cos 2(m-j)x + \binom{2m}{m} \right] \\
&=\frac{1}{2^{2m-1}} \sum_{h = 1}^m (-1)^h \binom{2m}{m-h} \cos 2hx + \frac{1}{2^{2m}}\binom{2m}{m},
\end{align*}
$$
which is easy to integrate. (From $0$ to $\pi$, only the last term has a nonzero integral.) The last term is like half what the term for $h = 0$ would be. For example, for $k = 6$, we get
$$\sin^6 x =  \frac{20}{64} - \frac{15}{32} \cos 2x + \frac{6}{32} \cos 4x - \frac{1}{32} \cos 6x  $$
If $k$ is odd, say $k = 2m + 1$, then we have 
$$
\begin{align*}
f(x) &= \frac{(-1)^{m}}{2^{2m}} \sum_{j = 0}^m (-1)^j \binom{2m+1}{j} \frac{e^{[2(m-j) + 1]x} - e^{-[2(m-j) + 1]x}}{2i} \\
&=\frac{1}{2^{2m}} \sum_{j = 0}^m (-1)^{m-j} \binom{2m+1}{j} \sin [2(m-j) + 1]x \\
&=\frac{1}{2^{2m}} \sum_{h = 0}^m (-1)^{h} \binom{2m+1}{m-h} \sin (2h + 1)x,
\end{align*}
$$
which is again easy to integrate. From $0$ to $\pi$, this last formula won't immediately give you the simplest form of the integral, which is twice the Wallis integral. Also, there are some circumstances where it might be preferable to integrate directly from one of the complex forms of $f(x)$, using the fact that the integral of $e^{inx}$ is $\displaystyle \frac{e^{inx}}{in}$.
For $k = 7$, we get 
$$\sin^7 x = \frac{35}{64} \sin x - \frac{21}{64} \sin 3x + \frac{7}{64} \sin 5x - \frac{1}{64} \sin 7x.$$
</s>