# Complex integration tricks for evaluating real integrals

I was doing some homework and I stumbled upon this integral: $$\int_{-\infty}^{\infty}dx \, \frac{\cos(x)-1+\frac{x^2}{2}}{x^4}$$ My first thoughts were:

1. at $$\pm\infty$$ it should converge, since the order of the denominator is bigger.
2. expanding in Taylor's series of the argument at $$0$$ should be: $$\frac{1}{4!}+O(x^6)$$. This means that the integral also converges near $$0$$, and the function is continuous (so there is an analytic continuation in $$0$$).

Im a little bit stuck because if the function is analytical its integral should be $$0$$? But this is not the case in the solution. Also, when adding two arcs (one at infinity and one around $$0$$) to close the loop, no other non-analytic points exists, so the residue theorem also says that the integral is $$0$$. What am I doing wrong? Thanks in advance for any help.

• Thanks, for the answer and also the spelling mistake :) Commented Aug 25, 2023 at 11:06
• Integration by part several times simplify the evaluation: $$\int_{-\infty}^\infty \frac{\cos x-1+\frac{x^2}{2}}{x^4}dx=-\frac{\cos x-1+\frac{x^2}{2}}{x^3}\bigg|_{-\infty}^\infty+\frac13\int_{-\infty}^\infty \frac{-\sin x +x}{x^3}dx$$ $$=-\frac16\frac{-\sin x +x}{x^2}\bigg|_{-\infty}^\infty+\frac16\int_{-\infty}^\infty \frac{-\cos x +1}{x^2}dx$$ $$=-\frac16\frac{-\cos x +1}{x}\bigg|_{-\infty}^\infty+\frac16\int_{-\infty}^\infty \frac{\sin x}{x}dx=\frac\pi{3\cdot2\cdot1}$$ Commented Aug 25, 2023 at 16:34
• This way we can get a more general result: $$\int_{-\infty}^\infty \frac{\cos x-\sum_{k=0}^n(-1)^k\frac{x^{2k}}{(2k)!}}{x^{2(n+1)}}dx=(-1)^{n+1}\frac\pi{(2n+1)!}$$ Commented Aug 25, 2023 at 16:41
• @Svyatoslav Nice. You can also argue that $$\int_{-\infty}^{\infty} \frac{\cos x-\sum_{k=0}^n(-1)^k\frac{x^{2k}}{(2k)!}}{x^{2(n+1)}} \, \mathrm dx = 2\lim_{s \to -(2n+1)} \Gamma(s) \cos \left(\frac{\pi s}{2} \right).$$ Commented Aug 25, 2023 at 17:16
• Are you using a contour in the shape of half of a donut in the upper half plane (AKA Random Variable's contour)? If so, the contour integral over the entire closed loop equals $0$ by Cauchy's Integral Theorem. Then you use that to your advantage to solve for the integral in question. I'm willing to bet money you can use a contour in the shape of one-fourth of a donut in the first quadrant as another alternative using $f(z) = \frac{e^{iz}-1+z^2/2}{z^4}$, just by doing some quick calculations in my head. Commented Aug 25, 2023 at 20:06

As stated in the comments, $$\cos z$$ grows exponentially unbounded on the circular arc from $$R$$ to $$-R$$ that traverses either half plane. The secret is to consider

$$I = \operatorname{Re}\left\{\lim_{R\to\infty}\int_{-R}^R\frac{e^{ix}-1-ix+\frac{1}{2}x^2+\frac{i}{6}x^3}{x^4}dx\right\}$$

The reason is that $$e^{ix}$$ does exponentially decay on the arc in the upper half plane whereas $$\cos x$$ did not, and the extra imaginary terms are to make sure the integrand is still analytic at $$0$$. For any complex integral you can add as many real/imaginary terms as you'd like if you're only taking the imaginary/real part of the integral at the end anyway, respectively.

Closing off the integral with the semicircular arc in the upper half plane, we do indeed get that there are no poles, hence

$$\int_{\Bbb{R}}\frac{e^{iz}-1-iz+\frac{1}{2}z^2+\frac{i}{6}z^3}{z^4}dz + \int_{\text{arc}}\frac{e^{iz}-1-iz+\frac{1}{2}z^2+\frac{i}{6}z^3}{z^4}dz = 0$$

We can compute the integral over the arc with the substitution $$z = Re^{i\theta}$$

$$= i\int_0^\pi \frac{\left(e^{iR\cos\theta}e^{-R\sin\theta}\right)}{R^3e^{3i\theta}}-\frac{\left(1+iRe^{i\theta}-\frac{R^2}{2}e^{2i\theta}\right)}{R^3e^{3i\theta}}+\frac{i}{6}\:d\theta$$

The relationship between the two integrals holds for all values of $$R$$, so simply take the limit as $$R\to\infty$$ at this stage

$$I = -\operatorname{Re}\left\{\lim_{R\to\infty}\int_{\text{arc}}\cdots\right\} = \int_0^\pi 0 - 0 + \frac{1}{6}\:d\theta = \boxed{\frac{\pi}{6}}$$

• Nice answer (+1). Commented Aug 25, 2023 at 11:22
• Nice indeed. Maybe you can add that you added those imaginary terms to make the function analytic at z=0 ? Commented Aug 25, 2023 at 12:04
• At least to me it took a while to understand this point but maybe the other readers are faster :) Commented Aug 25, 2023 at 12:06
• @Thomas I have added a note about why the choice was made :) Commented Aug 25, 2023 at 17:46
• Nice explanation thanks Commented Aug 26, 2023 at 8:15

Alternatively, let $$f(z) = \frac{e^{iz}-1+ \frac{z^{2}}{2}}{z^{4}}.$$

About the origin, $$f(z)$$ has the Laurent series expansion $$f(z)= \frac{i}{z^{3}}- \frac{i}{6z} + O(1).$$

If we integrate $$f(z)$$ around the indented semicircular contour $$[-R, -r] \cup re^{i[\pi, 0]} \cup [r, R] \cup Re^{i[0, \pi]},$$ the integral vanishes on the large semicircle as $$R \to \infty$$ by a combination of Jordan's lemma and the estimation lemma (or by just the estimation lemma by itself).

And using the result from this question, the integral on the small clockwise-oriented semicircle goes to $$- i \pi \left(- \frac{i}{6} \right) = -\frac{\pi}{6}$$ as $$r \to 0$$.

Therefore, we have $$\operatorname{PV} \int_{-\infty}^{\infty} \frac{e^{ix}-1+ \frac{x^{2}}{2}}{x^{4}} \, \mathrm dx - \frac{\pi}{6} =0.$$

Equating the real parts on both sides of the above equation, we get $$\int_{-\infty}^{\infty} \frac{\cos(x)-1+ \frac{x^{2}}{2}}{x^{4}} \, \mathrm dx = \frac{\pi}{6}.$$

In general, the Laurent series of $$g(z) = \frac{e^{iz}-\sum_{k=0}^n(-1)^k\frac{ x^{2k}}{(2k)!}}{z^{2(n+1)}}$$ about the origin is $$g(z) = \sum_{m=-n}^{0} \frac{i(-1)^{m+n} z^{2k-1}}{(2m+2n+1)!} + O(1).$$

Integrating $$g(z)$$ around the same contour, we get $$\operatorname{PV} \int_{-\infty}^{\infty} \frac{e^{ix}-\sum_{k=0}^n(-1)^k\frac{ x^{2k}}{(2k)!}}{x^{2(n+1)}}\, \mathrm dx - i \pi \left( \frac{i(-1)^{n}}{(2n+1)!} \right) =0.$$

Therefore, $$\int_{-\infty}^{\infty} \frac{\cos(x)-\sum_{k=0}^n(-1)^k\frac{ x^{2k}}{(2k)!}}{x^{2(n+1)}}\, \mathrm dx = \frac{(-1)^{n+1}\pi}{(2n+1)!}.$$

Consider $$I_n=\int_{-n\pi}^{+n \pi} \frac{\cos(x)-1+\frac{1}{2}x^2}{x^4}\,dx$$ where $$n$$ is an integer.

$$I_n=\frac{\text{Si}(n \pi )}{3}-\frac{3-(-1)^n}{3 \pi n}+\frac{2 \left(1-(-1)^n\right)}{3 \pi ^3 n^3}$$

$$\text{Si}(n \pi )=\frac \pi 2 -(-1)^n \left(\frac{1}{\pi n}-\frac{2}{\pi ^3 n^3}+O\left(\frac{1}{n^5}\right)\right)$$

$$I_n=\frac{\pi }{6}-\frac{1}{\pi n}+\frac{2}{3 \pi ^3 n^3}+O\left(\frac{1}{n^5}\right)$$ is a quite good approximation.

Edit

Using the generalization proposed by @Svyatoslav in comments

$$J_m=\int_{-n\pi}^{+n\pi} \frac{\cos x-\sum_{k=0}^m(-1)^k\frac{x^{2k}}{(2k)!}}{x^{2(m+1)}}dx$$ $$J_m=\frac{(-1)^{m+1}}{(2m+1)!}\left( \pi -\frac{2 (2 m+1)}{\pi n}+\frac{4 m (2 m-1) (2 m+1)}{3 \pi ^3 n^3}+O\left(\frac{1}{n^5}\right) \right)$$

• nice answer ............ +1 Commented Aug 28, 2023 at 14:10

INTEGRATION BY PARTS THRICE \begin{aligned} \int_{-\infty}^{\infty} \frac{\cos x-1+\frac{x^2}{2}}{x^4} d x=&2 \int_0^{\infty} \frac{\cos x-1+\frac{x^2}{2}}{x^4} d x\\ = & -\frac{1}{3} \int_0^{\infty}\left(\cos x-1+\frac{x^2}{2}\right) d\left(\frac{1}{x^3}\right) \\ = & -\frac{2}{3}\left[\frac{\cos x-1+\frac{x^2}{2}}{x^3}\right]_0^{\infty}+\frac{2}{3} \int_0^{\infty} \frac{-\sin x+x}{x^3} d x \\ = & -\frac{1}{3} \int_0^{\infty}(-\sin x+x) d\left(\frac{1}{x^2}\right) \\ = & \frac{1}{3} \int_0^{\infty} \frac{-\cos x+1}{x^2} d x \\ = & -\frac{1}{3} \int_0^{\infty}(-\cos x+1) d\left(\frac{1}{x}\right) \\ = & \frac{1}{3} \int_0^{\infty} \frac{\sin x}{x} d x\\=&\frac{\pi}{6} \end{aligned}