Integral of cosine of complex exponential I have the following integral:
\begin{equation}
I=\int_{0}^{1}dx\,\cos\left(e^{2\pi ix }\right).
\end{equation}
If I do the substitution $u=e^{2\pi ix }$, then ( $e^{2\pi i}=1$),
\begin{equation}
I=\int_1^1du\,\frac{1}{2\pi i u}\cos(u)=0.
\end{equation}
Since both limits coincide, i.e. they are both 1, the integral is zero.
Hower, using Wolfram Mathematica the answer is
\begin{equation}
I=\int_{0}^{1}dx\,\cos\left(e^{2\pi ix }\right)=1.
\end{equation}
How is it possible?
 A: After the change of variable $x\to u$ defined by $u=e^{2\,\pi\,i\,x}$ you arrive to
$$\int_0^1\cos(e^{2\,\pi\,i\,x})dx=\frac{1}{2\,\pi\,i}\int_C \frac{\cos(u)}{u}du$$
where C es the unit circle. Now, applying Residue theorem to above integral
$$\frac{1}{2\,\pi\,i}\int_C \frac{\cos(u)}{u}du=\frac{1}{2\,\pi\,i}*2\,\pi\,i\,*res(\frac{\cos(u)}{u},0)=\frac{1}{2\,\pi\,i}*2\,\pi\,i*1=1$$
A: You need to use contour integration for complex numbers. If you have a function $f:\mathbb{C}\to\mathbb{C},$ then one has that $$\int_{\gamma}f(z)\,\mathrm{d}z=\int_{t_0}^{t_1}f(\gamma(t))\gamma'(t)\,\mathrm{d}t,$$ where $\gamma:[t_0,t_1]\to\mathbb{C}$ is a differentiable function on $(t_0,t_1).$ Here, what you have is $$\int_0^1\cos\left(e^{2\pi{x}i}\right)\,\mathrm{d}x=\int_0^1\frac{\cos\left(e^{2\pi{x}i}\right)}{2\pi{i}e^{2\pi{x}i}}2\pi{i}e^{2\pi{x}i}\,\mathrm{d}x=\frac1{2\pi{i}}\int_0^1\frac{\cos\left(e^{2\pi{x}i}\right)}{e^{2\pi{x}i}}2\pi{i}e^{2\pi{x}i}\,\mathrm{d}x.$$ The situation here suggests that we have $\gamma(x)=e^{2\pi{x}i}$ and $f(z)=\frac{\cos(z)}{z}.$ With that, you have $$\frac1{2\pi{i}}\int_0^1\frac{\cos\left(e^{2\pi{x}i}\right)}{e^{2\pi{x}i}}2\pi{i}e^{2\pi{x}i}\,\mathrm{d}x=\frac1{2\pi{i}}\int_{\gamma}\frac{\cos(z)}{z}\,\mathrm{d}z.$$ Notice that the contour $\gamma$ is a closed curve in the complex plane, with $\gamma(0)=\gamma(1),$ and it has winding number $1.$ Therefore, by Cauchy's residue theorem, one has that $$\frac1{2\pi{i}}\int_{\gamma}\frac{\cos(z)}{z}\,\mathrm{d}z=\mathrm{Res}\left(0,\frac{\cos(z)}{z}\right)=\lim_{z\to0}z\frac{\cos(z)}{z}=\lim_{z\to0}\cos(z)=\cos(0)=1.$$
The reason the substitution you used does not work is because you failed to account for the fact that your substitution is a closed curve enclosing a singularity at $0.$
