Let $R$ be a rational function of two variables in $\mathbb{C}$, i.e., $R \in \mathbb{C}(x, y)$. Our goal is to evaluate integrals of the form
\[
\int_{0}^{2 \pi} R(\cos \theta, \sin \theta) \, d\theta.
\] Let $z = e^{i \theta}$. Then
\[
\cos \theta = \frac{1}{2}(z + z^{-1}), \qquad \sin \theta = \frac{1}{2i}(z- z^{-1})
\] and $d\theta = dz/(iz)$. Therefore
\[
\int_{0}^{2 \pi} R(\cos \theta, \sin \theta) \, d \theta = \int_{C(0, 1)} R \left( \frac{1}{2}(z + z^{-1}), \frac{1}{2 i} (z- z^{-1}) \right) \, \frac{dz}{iz}.
\]
Example. Let $0 < a < 1$. We will evaluate
\[
\int_{0}^{2\pi} \frac{d\theta}{1- 2 a \cos \theta + a^2}.
\] Let $z = e^{i \theta}$. Then
\begin{align} \int_{0}^{2 \pi} \frac{d \theta}{1- 2 a \cos \theta + a^2} &= \int_{C(0, 1)} \frac{1}{1- a (z + z^{-1}) + a^2} \frac{dz}{iz} \\ &= -i\int_{C(0, 1)} \frac{dz}{(1 + a^2)z- a z^2- a} \\ &= -i \int_{C(0, 1)} \frac{dz}{(z- a)(1- az)}. \end{align} Let
\[
f(z) = \frac{-i}{(z- a)(1- az)}.
\] Then $f$ has simple poles at $z = a$ and $z = a^{-1}$. Since $0 < a < 1$, only $z = a$ is in the interior of $C(0, 1)$. We have
\[
\text{Res}(f, a) = \lim_{z \to a} (z- a) f(z) = \frac{-i}{1- a^2}.
\] Therefore, by Cauchy’s residue theorem we have
\[
\int_{0}^{2 \pi} \frac{d \theta}{1- 2 a \cos \theta + a^2} = 2 \pi i \, \text{Res}(f, a) = \frac{2 \pi}{1- a^2}.
\]
If $f$ is a rational function, i.e., $f \in \mathbb{C}(z)$, such that $f(z) = o(|z|^{-1})$ for $z$ large and $f$ has no singularities on the real line, then we can evaluate integrals of the form
\[
\int_{-\infty}^{\infty} f(x) \, dx.
\] Here the integral converges in the principal sense. Pick $R$ sufficiently large so that all the poles of $f$ in the upper half plane are in the interior of the contour $C_R$ describing the line segment $[-R, R]$ and the semicircle of radius $R$ in the upper half plane centered at the origin. If $z_1, \dots, z_n$ are the poles of $f$ in the upper half plane, then
\[
\int_{-\infty}^{\infty} f(x) \, dx = 2 \pi i \sum_{i = 1}^{n} \text{Res}(f, z_i).
\]
Example. We will now show that
\[
\int_{-\infty}^{\infty} \frac{x^2}{(1 + x^2)^2} \, dx = \frac{\pi}{2}.
\] Consider
\[
\int_{C_R} f(z) \, dz,
\] where
\[
f(z) = \frac{z^2}{(1 + z^2)^2}.
\] The integrand of $f$ clearly has poles of order $2$ at $z = \pm i$, but only $i$ is in the upper half plane. Note that $f(z) \ll |z|^{-2}$. Moreover, we have
\[
\text{Res}(f, i) = \lim_{z \to i} \frac{d}{dz} (z- i)^2 f(z) = \lim_{z \to i} \frac{2z(z + i)^2- 2z^2 (z + i)}{(z + i)^4} = -\frac{i}{4}.
\] Hence, we find that
\[
\int_{-\infty}^{\infty} \frac{x^2}{(1 + x^2)^2} \, dx = 2 \pi i \left( -\frac{i}{4} \right) = \frac{\pi}{2}.
\]
Consider integrals
\[
\int_{-\infty}^{\infty} f(x) \cos nx \, dx, \qquad \int_{-\infty}^{\infty} f(x)\sin nx \, dx,
\] where $n$ is a positive integer. Such integrals are very important in Fourier analysis. In order to evaluate such integrals we consider
\[
\int_{C_R} f(z) e^{i m z} \, dx,
\] where $C_R$ consists of the line segment $[-R, R]$, together with the semicircle of radius $R$ in the upper half plane centered at the origin taken in the positive orientation. If $|f(z)| \leq M/|z|$ for $|z|$ large, then we show that
\[
\lim_{R \to \infty} \int_{S_R} f(z) e^{imz} \, dz = 0,
\] where $S_R$ is the semicircle. Note that
\[
\left| \int_{S_R} f(z) e^{i n z} \, dz \right| = \left| \int_{0}^{\pi} f(R e^{i \theta}) e^{i n R e^{i \theta}} i R e^{i \theta} \, d\theta \right| \leq M\int_{0}^{\pi} e^{- n R \sin \theta} \, d \theta = 2 M \int_{0}^{\pi/2} e^{-nR \sin \theta} \, d\theta.
\] Using the inequality $(\sin \theta)/\theta \geq 2 /\pi$ for $0 < \theta \leq \pi/2$ we find that
\[
\int_{0}^{\pi/2} e^{-n R \sin \theta} \, d \theta \leq \int_{0}^{\pi/2} e^{-2n R \theta/\pi} \, d\theta = \frac{\pi}{2 n R} (1- e^{-nR}) \leq \frac{\pi}{2 n R}.
\] Hence, we have
\[
\left| \int_{S_R} f(z) \, dz \right| \leq \frac{M \pi}{n R}
\] and so the assertion follows.
Example. We will evaluate
\[
\int_{-\infty}^{\infty} \frac{\cos x}{1 + x^2} \, dx.
\] Consider
\[
f(z) = \frac{e^{iz}}{1 + z^2}
\] and
\[
\int_{C_R} f(z) \, dz,
\] where $C_R$ is as above. Clearly, $f$ has simple poles at $z = \pm i$ and only $i$ is in the interior of $C$. We have
\[
\text{Res}(f, i) = \lim_{z \to i} (z- i) f(z) = \lim_{z \to i} \frac{e^{iz}}{z + i} = \frac{1}{2 i e}.
\] By Cauchy’s residue theorem,
\[
\int_{-R}^{R} \frac{e^{ix}}{1 + x^2} \, dx + \int_{S_R} f(x) \, dz = 2 \pi i \cdot \frac{1}{2 i e} = \frac{\pi}{e}.
\] Since $1/(1 + z^2) \ll |z|^{-2}$, it follows that
\[
\lim_{R \to \infty}\int_{S_R} f(z) \, dz = 0
\] Hence, we find that
\[
\int_{- \infty}^{\infty} \frac{e^{ix}}{1 + x^2} \, dx = \frac{\pi}{e}
\] and so
\[
\int_{-\infty}^{\infty} \frac{\cos x}{1 + x^2} \, dx = \frac{\pi}{e}.
\]