The art of using the Residue Theorem in evaluating definite integrals

As many of you know, using the Residue Theorem to evaluate a definite integral involves not only choosing a contour over which to integrate a function, but also choosing a function as the integrand. Many times, this is an easy task when integrating, say, rational functions over the real line. Sometimes there are less trivial but still well-known techniques, such as multiplying a function to be integrated over the positive reals by $\log{z}$ and integrating over a keyhole contour. And sometimes we just have to fumble our way through, as I will illustrate with the following example.

The problem is to evaluate

$$\int_{0}^{\infty} dx \frac {\sinh ax \sinh bx}{\cosh cx} $$

Consider the contour integral

$$\oint_C dz \frac{\sinh{a z} \sinh{b z}}{\sinh{c z}} $$

where $C$ is the rectangle $-R-i \pi/(2 c), R-i \pi/(2 c), R+i \pi/(2 c), -R+i \pi/(2 c)$. Note that

$$\sinh{c (x \pm i \pi/2 c)} = \pm i \cosh{c x} $$

Therefore the contour integral is

$$\int_{-R}^R dx \, \frac{\sinh{a(x-i \pi/(2 c))} \sinh{b(x-i \pi/(2 c))}}{-i \cosh{c x}}\\ +i \int_{-\pi/(2 c)}^{\pi/(2 c)} dy \, \frac{\sinh{a (R+i y)} \sinh{b (R+i y)}}{\sinh{c (R+i y)}}\\ + \int_{R}^{-R} dx \, \frac{\sinh{a(x+i \pi/(2 c))} \sinh{b(x+i \pi/(2 c))}}{i \cosh{c x}} \\-i \int_{\pi/(2 c)}^{-\pi/(2 c)} dy \, \frac{\sinh{a (R-i y)} \sinh{b (R-i y)}}{\sinh{c (R-i y)}}$$

Note that, for the second and fourth integrals to vanish as $R \to \infty$, we must have $|a|+|b| \lt |c|$; assume this is the case. The contour integral then becomes, after simplification (the algebra of which I will spare the reader) (*):

$$i 2 \cos \left(\frac{\pi a}{2 c}\right) \cos \left(\frac{\pi b}{2
c}\right) \int_{-\infty}^{\infty} dx \frac{ \sinh (a x) \sinh (b x)}{\cosh{c x}}\\-i 2 \sin \left(\frac{\pi a}{2 c}\right) \sin
\left(\frac{\pi b}{2 c}\right) \int_{-\infty}^{\infty} dx \frac{\cosh (a x) \cosh (b x)}{\cosh{c x}}$$

Note that we don’t quite have the integral we want. So now consider

$$\oint_C dz \frac{\cosh{a z} \cosh{b z}}{\sinh{c z}} $$

and as a result of similar steps as above, the contour integral becomes (**)

$$i 2 \cos \left(\frac{\pi a}{2 c}\right) \cos \left(\frac{\pi b}{2
c}\right) \int_{-\infty}^{\infty} dx \frac{ \cosh (a x) \cosh (b x)}{\cosh{c x}}\\-i 2 \sin \left(\frac{\pi a}{2 c}\right) \sin
\left(\frac{\pi b}{2 c}\right) \int_{-\infty}^{\infty} dx \frac{\sinh (a x) \sinh (b x)}{\cosh{c x}}$$

We can eliminate the integral we are not seeking by multiplying $\text{(*)}$ by $\cos \left(\frac{\pi a}{2 c}\right) \cos \left(\frac{\pi b}{2
c}\right)$ and $\text{(**)}$ by $\sin \left(\frac{\pi a}{2 c}\right) \sin \left(\frac{\pi b}{2
c}\right)$. Thus, really, we are then seeking

$$\oint_C dz \, \frac{f(z)}{\sinh{c z}}$$

where

$$f(z) = \cos \left(\frac{\pi a}{2 c}\right) \cos \left(\frac{\pi b}{2 c}\right) \sinh{a z} \sinh{b z} + \sin \left(\frac{\pi a}{2 c}\right) \sin \left(\frac{\pi b}{2 c}\right) \cosh{a z} \cosh{b z} $$

The contour integral now takes the form

$$i 2 \left [\cos^2 \left(\frac{\pi a}{2 c}\right) \cos^2 \left(\frac{\pi b}{2 c}\right) – \sin^2 \left(\frac{\pi a}{2 c}\right) \sin^2 \left(\frac{\pi b}{2 c}\right) \right ] \int_{-\infty}^{\infty} dx \frac{\sinh (a x) \sinh (b x)}{\cosh{c x}}$$

This is equal to $i 2 \pi$ times the residue of $f(z) \operatorname{csch}{c z}$ at the pole $z=0$, which is simply $f(0)/c$. Using the symmetry of the integral, we finally have

$$\begin{align}\int_{0}^{\infty} dx \frac{\sinh (a x) \sinh (b x)}{\cosh{c x}} &= \frac{\pi}{2 c} \frac{\sin \left(\frac{\pi a}{2 c}\right) \sin \left(\frac{\pi b}{2 c}\right )}{\cos^2 \left(\frac{\pi a}{2 c}\right) \cos^2 \left(\frac{\pi b}{2 c}\right) – \sin^2 \left(\frac{\pi a}{2 c}\right) \sin^2 \left(\frac{\pi b}{2 c}\right) } \\ &= \frac{\pi}{4 c} \frac{\cos{\left(\frac{\pi (a-b)}{2 c}\right)}-\cos{\left(\frac{\pi (a+b)}{2 c}\right)}}{\cos{\left(\frac{\pi (a-b)}{2 c}\right)} \cos{\left(\frac{\pi (a+b)}{2 c}\right)}}\\ &= \frac{\pi}{4 c} \left [\sec{\left(\frac{\pi (a+b)}{2 c}\right)}-\sec{\left(\frac{\pi (a-b)}{2 c}\right)} \right ] \end{align}$$

where, again, $|a|+|b|\lt|c|$.


A Tale of Two Integrals

Two integrals look almost the same, and even to those fairly well-versed in the art, are the same. But alas, as we shall see. Consider the integral $$I_1 = \int_0^{\pi} dx \frac{x \sin{x}}{1+\cos^2{x}} $$ This may be evaluated by subbing $x \mapsto \pi-x$ as follows: $$\begin{align} I_1 &= \int_0^{\pi} dx \frac{(\pi-x) \sin{x}}{1+\cos^2{x}} \\&= \pi \int_0^{\pi} […]


Weird integral whose simplicity is only apparent in the complex plane

Every so often we come across an integral that seems absolutely impossible on its face, but is easily attacked – in fact, is custom designed – for the residue theorem. I wonder why a first year complex analysis class doesn’t show off this case as Exhibit A in why the residue theorem is so useful. […]


Expansions of $e^x$

A very basic question was asked recently: What is a better approximation to $e^x$, the usual Taylor approximation, or a similar approximation involving $1/e^{-x}$? More precisely, given an integer $m$, which is a better approximation to $e^x$: $$f_1(x) = \sum_{k=0}^m \frac{x^k}{k!} $$ or $$f_2(x) = \frac1{\displaystyle \sum_{k=0}^m \frac{(-1)^k x^k}{k!}} $$ The answer is amazingly simple: […]


Real evaluation of an improper log integral

The problem posed in M.SE concerns real methods of evaluating $$\int_0^{\infty} dx\frac{\log(x)}{\cosh(x) \sec(x)- \tan(x)} $$ The place I started is the nifty result, proven here, that $$\frac{\sin{x}}{\cosh{t} – \cos{x}} = 2 \sum_{k=1}^{\infty} e^{-k t} \sin{k x} $$ Of course, the integral actually looks like $$\int_0^{\infty} dx \frac{\cos{x}}{\cosh{x} – \sin{x}} \log{x} $$ so we need to […]


Generalizing an already tough integral

I did the case $p=1$ here. The generalization to higher $p$ may involve higher-order derivatives as follows: $$\begin{align}K_p &= \int_0^{\pi/2} dx \frac{x^{2 p}}{1+\cos^2{x}} = \frac1{2^{4 p-1}} \int_{-\pi}^{\pi} dy \frac{y^{2 p}}{3+\cos{y}} \end{align}$$ So define, as before, $$J(a) = \int_{-\pi}^{\pi} dy \frac{e^{i a y}}{3+\cos{y}} $$ Then $$K_p = \frac{(-1)^p}{2^{4 p-1}} \left [\frac{d^{2 p}}{da^{2 p}} J(a) \right ]_{a=0}$$ […]


Mathematica v9.0.1 states that this integral does not converge.

The problem is to evaluate the following integral: $$\int_0^{\infty} dx \frac{\log(1+x)}{\left(1+x^2\right)\,\left(1+x^3\right)}$$ This one turned out to be messy but straightforward. What did surprise is the way in which I would need to employ the residue theorem. Clearly, the integral is more amenable to real methods than a contour integration. What happens, though, is that the […]


An unusually alternating sum

Problem: evaluate the following sum… $$\sum_{k=0}^{\infty}\dfrac{(-1)^{\frac{k(k+1)}{2}}}{(2k+1)^2}$$ This is unusual because the $-1$ is raised to the $k (k+1)/2$ power, rather than the usual $k$th power. On the surface, this problem may look hopeless, but really, it is all about determining the pattern of odd and even numbers from the sequence $k (k+1)/2$, which turns out […]


Algebraically difficult integral

Well, some integrals are not all that hard to evaluate in principle. The one I am posting here should be an open and shut application of the residue theorem, using the unit circle as a contour. The form of the integrand, however, should give a little pause. It turns out that actually computing residues on […]


An integral involving a quadratic phase

This one was first posted on the site Integrals and Series and was brought to my attention on M.SE by Cody. My solution involves a contour integration, although the approach is far from trivial. Yet again, the solution boils down to finding a contour and a function to integrate over the contour. The problem involves […]


An integral that illustrates the beauty of contour integration methods

I attack many of the integrals in this blog using contour integration methods, some of which are obvious and some of which take a little more imagination. Here is one that illustrates the beauty an power of such methods as much as any other integral here. The problem is to derive the integral representation $$\sin […]


Funky triple integral

Note: There was a sign error in the original solution, which I have since fixed. Problem: Evaluate $$ \int _0 ^{\infty}\int _0 ^{\infty}\int _0 ^{\infty} \log(x)\log(y)\log(z)\cos(x^2+y^2+z^2)dzdydx$$ Solution: One way to attack this is to exploit the symmetry of the integral. Start by expanding the cosine term into individual pieces, i.e., $$\begin{align}\cos{(x^2+y^2+z^2)} &= \cos{x^2} \cos{(y^2+z^2)} – […]


An odd-looking integral of a square root of trig functions

The integral to evaluate is $$\int_0^{\pi/3} \big((\sqrt{3}\cos x-\sin x)\sin x\big)^{1/2}\cos x \,dx $$ A cursory glance at this specimen leads to exasperation, as the $\pi/3$ in the limit seems arbitrary, and the integrand seems devoid of an antiderivative. It turns out, however, that one way to attack this integral is to transform it into a […]


Integral of function with deceptive triple pole

One integral posted came from Hermite’s integral representation of the Hurwitz zeta function. The integral is not the most difficult that I have ever evaluated, but is interesting from a pedagogical point of view. The problem is to evaluate $$\int_0^{\infty} dx \frac{x}{(e^x-1) (x^2+4 \pi^2)^2}$$ This integral may be done via the residue theorem, by considering […]


Deceptively Tricky Integral II

Evaluate the following integral $$\int_0^{\pi/2} dx \frac{x^2}{1+\cos^2 x}$$ This integral is deviously difficult. It may look like it has the solution I provided for this integral, but, as you will see, there is an additional wrinkle. As in the linked solution, I will express the integral in a form in which I may attack via […]


Improper integral of a high power of log

I feel like I’ve developed something new in evaluating this integral. Previously, when confronted with an integral of log to the n times a function, I considered the integral of log to the n+1 times the function over a keyhole contour. This gave me the original integral, but also all of the other integrals of […]


Two integrals, each easier than it looks

I start with an integral that stymied a bunch of people for the better part of an hour. The following solution had a lot of people slapping their heads. The problem is to evaluate, for any real $\alpha$, the following integral: $$\int_0^{\pi/2} \frac{dx}{1+\tan^{\alpha}{x}}$$ Solution: use the fact that $$\tan{\left (\frac{\pi}{2}-x\right)} = \frac{1}{\tan{x}}$$ i.e., $$\frac1{1+\tan^{\alpha}{x}} = […]


A crazy-ass integral, the evaluation of which got a lot of love at Math.SE

There are a lot of integrals posted at Math.SE. I attempt to evaluate quite a few of them. Many times, I fail spectacularly; you will typically not hear of those because I feel there is nothing to say. Occasionally, I succeed; of course, you will hear about those because I post and then post again […]


Deceptively tricky integral

Someone wanted us to evaluate the following integral: $$\int\limits_0^\pi dx{\frac{{{x^2}}}{{\sqrt 5-2\cos x}}}$$ This looks straightforward, although the factor of $x^2$ does seem to complicate things a little. Actually, a lot. The usual tricks to deal with powers leads us down a road that leads to interesting territory involving dilogarithms. Let’s define $$J(a) = \int_{-\pi}^{\pi} dx […]


Unlikely application of Parseval’s equality

A poster somehow got a numerical value for an integral and wondered if it could be expressed in terms of simple constants. Let $\operatorname{erfi}(x)$ be the imaginary error function $$\operatorname{erfi}(x)=\frac{2}{\sqrt{\pi}}\int_0^xe^{z^2}dz.$$ Consider the integral $$I=\int_0^\infty\frac{\sin(x)\ \operatorname{erfi}\left(\sqrt{x}\right)\ e^{-x\sqrt{2}}}{x}dx.$$ Its numeric value is approximately $0.625773669454426$ The question is: Is it possible to express $I$ in a closed form […]


A nifty integral worked out via contour integration

Problem: evaluate the following integral: $$\int_0^{\infty}dx \frac{e^{-a x^2(x^2-\pi^2)}\cos(2\pi a x^3)}{\cosh x} $$ To evaluate this integral, consider the following integral in the complex plane: $$\oint_C \frac{dz}{\sinh{z}} e^{-a (z^2-\pi^2/4)^2}$$ where $C=C_1+C_2+C_3+C_4+C_5+C_6$ as illustrated below: $$\int_{C_1} \frac{dz}{\sinh{z}} e^{-a (z^2-\pi^2/4)^2} = \int_{i \pi/2}^{R+i \pi/2} \frac{dx}{\sinh{x}} e^{-a (x^2-\pi^2/4)^2}$$ $$\int_{C_2} \frac{dz}{\sinh{z}} e^{-a (z^2-\pi^2/4)^2} = i\int_{\pi/2}^{-\pi/2} \frac{dy}{\sinh{(R+iy)}} e^{-a [(R+i y)^2-\pi^2/4]^2} $$ […]


An integral with difficult branch points

The challenge here is merely to evaluate the following integral: $$\int_0^{\infty} dx \frac{\log{(1+x^3)}}{(1+x^2)^2}$$ This integral is a tough one because of the branch points strewn throughout the complex plane, as well as the utter lack of symmetry. It turns out, however, that we may still use the residue theorem to evaluate the integral so long […]