I just started learning complex analysis and I'm struggling with some complex contour integration. One problem I recently saw was $$ \int_{-\infty}^{\infty}e^{-x^{2}}\cos(2x)dx $$
To my understanding, since the function is continuous everywhere $$ \oint_{C}f(z)dz = \int_{-R}^{R}f(z)dz + \int_{\gamma_{r}}f(z)dz = 0 $$ from the Cauchy-Goursat theorem, where $[-R,R]$ is along the real axis with a limit as $R$ goes to infinity, and the contour $\gamma_r$ is a semi circle in the complex plane with $|z|>0$. Now I'm struggling with evaluating the contour integral in the second part. How do I go about solving this, assuming my steps so far are correct?
Consider $f(x)=e^{-x^{2}}$ and define $\Gamma$ to be the rectangular contour connecting the vertices at the points $-R, R, R+i, -R+i$. Furthermore, define $\gamma_{1},\gamma_{2},\gamma_{3},\gamma_{4}$ are the lines represented by
\begin{align*} \gamma_{1}&: t, &t\in[-R,R]\\ \gamma_{2}&: R+ti, &t\in [0,1]\\ \gamma_{3}&: i-t, &t\in[-R,R]\\ \gamma_{4}&: -R+(1-t)i, &t\in[0,1] \end{align*}
so that, by abusing notation,
$$\oint_{\Gamma} = \int_{\gamma_{1}} +\int_{\gamma_{2}} + \int_{\gamma_{3}} + \int_{\gamma_{4}},$$
and by Cauchy-Goursat,
$$\oint_{\Gamma} e^{-z^{2}}\operatorname{d}\!z = 0.$$
We will show that $\int_{\gamma_{2}}$ vanishes (and similarly for $\int_{\gamma_{4}}$). Indeed, under the map $z=R+ti$, $\operatorname{d}\!z = i\operatorname{d}\!t$ and by the ML lemma,
$$\left\lvert\int_{\gamma_{2}} e^{-z^{2}} \operatorname{d}\!z\right\rvert = \left\lvert\int_{0}^{1}ie^{-(R+ti)^{2}}\operatorname{d}\!t\right\rvert = \left\lvert\int_{0}^{1}ie^{-(R^{2}+2ti-t^{2})}\operatorname{d}\!t\right\rvert \leq \int_{0}^{1}\left\lvert e^{-R^{2}-t^{2}}\right\rvert\operatorname{d}\!t \leq e^{-R^{2}}\longrightarrow 0.$$
Now,
\begin{align*} \int_{\gamma_{1}} f(z)\operatorname{d}\!z + \int_{\gamma_{3}}f(z)\operatorname{d}\!z &= \int_{-R}^{R} e^{-t^{2}} \operatorname{d}\!t - \int_{-R}^{R}e^{-t^{2}-2it+1} \operatorname{d}\!t\\ &=\int_{-R}^{R} e^{-t^{2}} \operatorname{d}\!t-e \int_{-R}^{R}e^{-t^{2}}(\cos(2t) - i\sin(2t))\operatorname{d}\!t. \end{align*}
It should be easy to see from here that
$$\int_{-\infty}^{\infty}e^{-x^{2}}\cos(2x)\operatorname{d}\!x = \frac{\sqrt{\pi}}{e}.$$