Evaluating $\int_{-\pi}^{\pi} (e^{ix} + e^{-ix})^n dx $ In an exercise following identity is used:
$$  \int_{-\pi}^{\pi} (e^{ix} + e^{-ix})^n dx = \begin{cases} 0, \hspace{2.1cm} n = 2m+1 \\
2\pi {2m \choose m}, \hspace{1cm} n=2m. \end{cases},  $$
Does anybody know how to prove this result or has some ideas to do so?  

PLEASE NOTE: It seems that the above identity was not quite correct, instead of $(e^{ix} - e^{-ix})^n $ it should be $(e^{ix} + e^{-ix})^n$. I'm sorry for that.

 A: Here is user1952009's approach, which seems much better to me than the other answers.
First, remark that, for any non-zero integer,
$$\int_{-\pi}^{\pi} e^{inx} \ dx = \left[ \frac{1}{in} e^{inx} \right]_{-pi}^{\pi} = \frac{e^{in\pi}-e^{-in\pi}}{in} = 0.$$
For $n = 0$, however, the result is different (since you can't divide by $n$):
$$\int_{-\pi}^{\pi} e^{i0x} \ dx = \int_{-\pi}^{\pi} 1 \ dx = 2 \pi.$$
This fact is very useful to remember (especially if you ever have to work with Fourier transforms). The next step is to develop $(e^{ix}+e^{-ix})^n$ with Newton's formula. We will get a bunch of terms, but by the fact above, the integration will remove any one with non-zero exponents in the exponential:
$$I_n := \int_{-\pi}^{\pi} (e^{ix}+e^{-ix})^n \ dx = \int_{-\pi}^{\pi} \sum_{k=0}^n \binom{n}{k} e^{ikx}e^{-i(n-k)x} \ dx = \sum_{k=0}^n \binom{n}{k} \int_{-\pi}^{\pi}  e^{i(2k-n)x} \ dx.$$
For any $n$, $k$, if $2k-n$ is non-zero, then the rightmost integral is zero. If $n = 2k$, then the rightmost integral is $2\pi$. Hence :


*

*If $n$ is odd, then $n-2k$ is non-zero for any integer $k$, so $I_n = 0$.

*If $n$ is even, then the only non-zero term is for $k = n/2$, in which case:
$$I_n = 2 \pi\binom{n}{n/2}.$$
A: hint: The main part is the integral $I_n=\displaystyle \int_{-\pi}^{\pi} \sin^n xdx= -\displaystyle \int_{-\pi}^{\pi} \sin^{n-1}xd(\cos x)=-\sin^nx\cos x\mid_{x=-\pi}^{\pi}=0+\displaystyle \int_{-\pi}^{\pi}\cos x\cdot (n-1)\sin^{n-2}x\cos xdx=(n-1)\displaystyle \int_{-\pi}^{\pi}(1-\sin^2x)\sin^{n-2}xdx\Rightarrow nI_n = (n-1)I_{n-2}$. You can continue to split into $2$ cases as you did above and find a formula for $I_n$
A: Notice, $e^{ix}+e^{-ix}=2\cos x$,  hence one should have
$$\int_{-\pi}^{\pi}(e^{ix}+e^{-ix})^n\ dx=\int_{-\pi}^{\pi}(2\cos x)^n\ dx$$
$$=2^n\int_{-\pi}^{\pi}\cos^n x\ dx$$
since, $\cos(-x)=\cos x$, 
$$=2\cdot 2^{n}\int_{0}^{\pi}\cos^n x\ dx$$
$$=2^{n+1}\int_{0}^{\pi}\cos^n (\pi-x)\ dx$$
Case-1: if $n=2m+1$ then $\cos^{2m+1}(\pi-x)=-\cos^{2m+1}(x)$  hence 
$$2^{n+1}\int_{0}^{\pi}\cos^n (\pi-x)\ dx=2^{2m+2}\int_{0}^{\pi}\cos^{2m+1} (\pi-x)\ dx=2^{2m+2}(0)=\color{red}{0}$$
Case-2: if $n=2m$ then $\cos^{2m}(\pi-x)=\cos^{2m}(x)$, hence 
$$2^{n+1}\int_{0}^{\pi}\cos^n (\pi-x)\ dx=2^{2m+1}\int_{0}^{\pi}\cos^{2m} (\pi-x)\ dx$$$$=2\cdot 2^{2m+1}\int_{0}^{\pi/2}\cos^{2m} (x)\ dx$$$$=2^{2m+2}\int_{0}^{\pi/2}\cos^{2m} (x)\ dx$$$$=2^{2m+2}\int_{0}^{\pi/2}\sin^{0}(x)\cos^{2m} (x)\ dx$$
Using formula: $\color{blue}{\int_{0}^{\pi/2}\sin^mx\cos^n x\ dx=\frac{\Gamma\left(\frac{m+1}{2}\right)\Gamma\left(\frac{n+1}{2}\right)}{2\Gamma\left(\frac{m+n+2}{2}\right)}}$, 
$$=2^{2m+2}\frac{\Gamma\left(\frac{0+1}{2}\right)\Gamma\left(\frac{2m+1}{2}\right)}{2\Gamma\left(\frac{0+2m+2}{2}\right)}$$
$$=2^{2m+1}\frac{\Gamma\left(\frac{1}{2}\right)\Gamma\left(\frac{2m+1}{2}\right)}{\Gamma\left(m+1\right)}$$
$$=2^{2m+1}\frac{\sqrt \pi\left(\underbrace{\frac{2m-1}{2}\cdot \frac{2m-3}{2}\cdot \frac{2m-5}{2}\cdots \frac{3}{2}\cdot \frac{1}{2}}_{\text{m times }}\Gamma\left(\frac{1}{2}\right)\right)}{m!}$$
$$=2^{2m+1}\frac{\sqrt \pi\left(\frac{(2m-1)(2m-3)(2m-5)\cdots 3\cdot 1 }{2^{m}}\sqrt \pi\right)}{m!}$$
$$=2^{m+1}\pi \frac{\frac{(2m)(2m-1)(2m-2)(2m-3)(2m-4)(2m-5)\cdots 4\cdot 3\cdot 2\cdot 1 }{(2m)(2m-2)(2m-4)\cdots 4\cdot 2}}{m!}$$
$$=2^{m+1}\pi \frac{\frac{(2m)!}{2^m\cdot m!}}{m!}$$
$$=2\pi\frac{(2m)!}{(m!)^2}$$
$$=\color{red}{2\pi \binom{2m}{m}}$$
hence, one should have   

$$\int_{-\pi}^{\pi}(e^{ix}+e^{-ix})^n\ dx=\begin{cases}0, \ \ \  \ \ \ \ \ \ \ \ \ \ n=2m+1\\ 2\pi \binom{2m}{m}, \ \ \ n=2m 
\end{cases}$$

