Home > complex analysis > A fun integral

## A fun integral

I am writing this post with the intent of making it a little more accessible than usual, where I mean “accessible” in two senses. If you are a mathematical person who is more interested in analysis than algebra, this will be a much easier and more pleasant read than the usual algebraic geometry and representation theory. On the other hand, if you are not a self-declared mathematical person and ended your mathematical education after high school or maybe a semester in college, I hope that this post will be at least readable and maybe even interesting. To understand all the details requires a lot of calculus, but to follow the outline of the proof you only need to know basic properties of integration (the precise definition of an integral, for example, is not important).

Today I will explain how to evaluate the integral

$\int_{-\infty}^{\infty} \frac{\text{cos } x}{x^2+x+1} \ \mathrm{d}x$.

The reader – mathematically inclined or not – may ask why one would want to do such a thing. I cannot offer any reason other than the fact that the solution invokes some techniques which are not at all obvious from the statement: to a mathematician, this is interesting and makes the effort worth more than simply finding the answer (which we will see is unsatisfyingly complicated). I will use one nontrivial theorem from complex analysis, but if the reader is willing to take this for granted then no knowledge of complex analysis is required. It seems slightly miraculous to me that the integral, which apparently does not involve complex numbers at all, has an elegant solution using complex analysis. An observant reader might have noticed that the integrand is well-defined because $x^2+x+1 \neq 0$ for all real numbers $x \in \mathbb{R}$, but this quadratic polynomial does have two complex roots $\alpha = -\frac12 + i\frac{\sqrt{3}}{2}$ and $\beta = -\frac12 - i\frac{\sqrt{3}}{2}$ (for example, one can apply the quadratic formula).

For reasons which will become apparent later, it is convenient to replace the integrand by the complex-valued function $\frac{e^{ix}}{x^2+x+1}$. Using Euler’s formula $e^{ix} = \text{cos } x + i \text{sin } x$, we can see that the real part of this new function is our original integrand $\frac{\text{cos } x}{x^2+x+1}$, so if we can compute the new integral we can recover the old one by taking the real part of the answer.

We compute this improper integral by integrating over a bounded interval and passing to the limit as the interval becomes larger:

$\lim_{N \to \infty} \int_{-N}^{N} \frac{e^{ix}}{x^2+x+1} \ \mathrm{d}x$.

The trick is to think of the bounded interval $[-N,N]$ as a path in the complex plane, and then connect the end of the path to the beginning via a rectangular path through the upper half-plane, forming a closed loop $\gamma_N$.

It does not matter precisely where the top edge of the rectangle is, as long as the loop encloses the complex number $\alpha$, which we say is a pole of the integrand $\frac{e^{iz}}{z^2+z+1}$ (note that we have changed the variable to $z$ to emphasize that we are considering a function of complex numbers) because the denominator of this function vanishes there. In a sense, this is the best (or rather least bad) kind of pole, since if we multiply the function by $z-\alpha$ the pole disappears and the function is perfectly well-behaved near $\alpha$: we call this a first-order or simple pole.

Here is where the magic of complex analysis comes into play: we will use the residue theorem to evaluate the integral around this loop. A weak form of the residue theorem can be stated as follows: suppose $f(z)$ and $g(z)$ are differentiable functions of the complex variable $z$, that $f'(z)$ and $g'(z)$ are continuous, and that $\frac{f(z)}{g(z)}$ has a simple pole at $\alpha \in \mathbb{C}$. Let $\gamma$ be a “nice” loop in $\mathbb{C}$ (let’s not get into technical details, but “nice” might mean piecewise smooth and not self-intersecting) which goes around $\alpha$ once counterclockwise and encloses no other poles of $\frac{f(z)}{g(z)}$, i.e. zeroes of $g(z)$. Then the residue theorem says that

$\int_{\gamma} \frac{f(z)}{g(z)} \ \mathrm{d}z = 2\pi i\frac{f(\alpha)}{g'(\alpha)}$.

It is not hard to see that the condition that $\alpha$ is a simple pole of the integrand guarantees that $g'(\alpha) \neq 0$, so the answer is well-defined.

Applying this to our situation, we find that

$\int_{\gamma_N} \frac{e^{iz}}{z^2+z+1} \ \mathrm{d}z = 2\pi i \frac{e^{i\alpha}}{2\alpha + 1} = \frac{2\pi}{\sqrt{3}} e^{-\frac{\sqrt{3}}{2}} (\text{cos } \frac12 - i\text{sin } \frac12 )$.

But how does this help us calculate the integral along the real line? First, writing $z = x + iy$ we have $|e^{iz}| = e^{-y} \leq 1$ along $\gamma_N$, and in particular for large $|z|$ we can estimate

$\bigg| \frac{e^{iz}}{z^2+z+1} \bigg| \leq \frac{C}{x}$

where $C \geq 0$ is a constant. Thus if we let $\delta_N$ denote one of the vertical edges of $\gamma_N$ and $M$ the the length of $\delta_N$, we have

$\bigg| \int_{\delta_N} \frac{e^{iz}}{z^2+z+1} \ \mathrm{d}z \bigg| \leq \frac{CM}{N}$,

so this integral vanishes as $N \to \infty$. We conclude that

$\int _{-\infty}^{\infty} \frac{e^{ix}}{x^2+x+1} \ \mathrm{d}x = \frac{2\pi}{\sqrt{3}} e^{-\frac{\sqrt{3}}{2}} (\text{cos } \frac12 - i\text{sin } \frac12 ) + \int _{L_y} \frac{e^{iz}}{z^2+z+1} \ \mathrm{d}z$,

where $y > \text{Im } \alpha = \frac{\sqrt{3}}{2}$ and $L_y = \mathbb{R} + iy$ is the horizontal line that passes through $iy$ (note that since we moved the integral along $L_y$ to other other side of the equation, we must now integrate left-to-right along $L_y$ rather than right-to-left as in $\gamma_N$).

We claim that the integral along $L_y$ vanishes. To this end, consider the following rectangular contour $\epsilon_N$, which lies entirely above $\alpha$.

Now we invoke another special case of the residue theorem, known as Cauchy’s theorem. This result says that when a loop encloses no poles of a continuously differentiable function, or in other words the integrand is well-defined and continuously differentiable everywhere in the interior of the loop, the integral around that loop is actually $0$. So we see that in our case, we have

$\int_{\epsilon_N} \frac{e^{iz}}{z^2+z+1} \ \mathrm{d}z = 0$

By the estimate above, the integral along the vertical edges vanishes as $N \to \infty$, whence

$\int_{L_{y_1}} \frac{e^{iz}}{z^2+z+1} \ \mathrm{d}z = \int_{L_{y_2}} \frac{e^{iz}}{z^2+z+1} \ \mathrm{d}z$

for all $y_1,y_2 > \frac{\sqrt{3}}{2}$. But in fact, the integral along $L_y$ must tend to zero as $y \to \infty$, since for large $|z|$ we can estimate

$\bigg| \frac{e^{iz}}{z^2+z+1} \bigg| \leq e^{-y} \frac{D}{x^2+1}$,

where $D \geq 0$ is another constant: this yields

$\bigg| \int_{L_y} \frac{e^{iz}}{z^2+z+1} \ \mathrm{d}z \bigg| \leq De^{-y} \int_{-\infty}^{\infty} \frac{1}{x^2+1} \ \mathrm{d}x$,

and since $\int_{-\infty}^{\infty} \frac{1}{x^2+1} \ \mathrm{d}x$ is a constant independent of $y$ we see that the integral vanishes as $y \to \infty$. But we already proved that the integral does not depend on $y$, so we must have

$\int_{L_y} \frac{e^{iz}}{z^2+z+1} \ \mathrm{d}z = 0$

for all $y > \frac{\sqrt{3}}{2}$. Combining this with our earlier calculation using the residue theorem, we obtain the final answer

$\int_{-\infty}^{\infty} \frac{\text{cos } x}{x^2+x+1} \ \mathrm{d}x = \text{Re } \int_{-\infty}^{\infty} \frac{e^{ix}}{x^2+x+1} \ \mathrm{d}x = \frac{2\pi}{\sqrt{3}} e^{-\frac{\sqrt{3}}{2}} \text{cos } \frac12$.

If you’re curious, this is $\approx 1.339$: you can check this approximate answer by numerically integrating with Wolfram Alpha or a good calculator.