Physics
Universitymathematical-methods

Complex Analysis: Contour Integration and the Residue Theorem

A real integral with no elementary antiderivative falls out in three lines once you stop insisting the variable stay real — analytic functions, Cauchy's theorem, and the residue theorem turn a hopeless calculus problem into a single number read off a pole.

Before this, you should know:

Try to evaluate

cosx1+x2dx\int_{-\infty}^{\infty}\frac{\cos x}{1+x^2}\,dx

using only the tools of ordinary calculus. Integration by parts pushes the derivative back and forth between cosx\cos x and 1/(1+x2)1/(1+x^2) without ever terminating. Substitution finds nothing to substitute. There is no elementary function whose derivative is cosx/(1+x2)\cos x/(1+x^2) — not a gap in your technique, but a theorem: the antiderivative genuinely cannot be written using any finite combination of polynomials, exponentials, logarithms, and trigonometric functions. And yet the integral converges to a perfectly ordinary-looking number. It is π/e\pi/e.

Here is the strange part. That number falls out in about four lines, once you are willing to let xx — which has been a real number this entire time, on every page of this site so far — wander off the real line and roam through the complex plane instead. You compute one residue, a single number extracted from a single point, multiply it by 2πi2\pi i, and the answer is sitting in front of you. This is not a trick restricted to this one integral; it is a general method, and by the end of this topic you will run it in full on a simpler cousin of the integral above, then come back and cash in on this one. To get there we need four ideas: what it means for a complex function to be well-behaved, a theorem about integrating such functions around closed loops, the concept of a residue, and the theorem that ties a residue to the value of an integral.

Analytic functions and the Cauchy-Riemann equations

A complex function ff assigns a complex number to a complex number, f(z)=f(x+iy)f(z)=f(x+iy). Split it into real and imaginary parts,

f(z)=u(x,y)+iv(x,y),f(z) = u(x,y) + iv(x,y),

where uu and vv are ordinary real-valued functions of the two real variables x,yx,y. Nothing so far is more than bookkeeping — every complex function is secretly a pair of real functions of two real variables.

The interesting question is whether ff has a derivative. Define it exactly as in ordinary calculus,

f(z)=limh0f(z+h)f(z)h,f'(z) = \lim_{h\to0}\frac{f(z+h)-f(z)}{h},

but now notice something that never came up for real functions: hh is a complex number, so it can approach 00 from any direction in the plane — along the real axis, along the imaginary axis, spiraling in, anything. A real function only ever had two directions to worry about, left and right, and they had to agree. A complex function has infinitely many directions, and for the limit to exist, all of them must agree on the same value. This is an enormously more restrictive demand, and functions that satisfy it are called analytic (or holomorphic) at that point.

To see what the demand costs, evaluate the limit along two particular directions and require them to match. Along the real axis, hh is a small real number, and

f(z)=limh0f(x+h,y)f(x,y)h=ux+ivx.f'(z) = \lim_{h\to0}\frac{f(x+h,y)-f(x,y)}{h} = \frac{\partial u}{\partial x} + i\frac{\partial v}{\partial x}.

Along the imaginary axis, h=ikh=ik for small real kk, and

f(z)=limk0f(x,y+k)f(x,y)ik=1i(uy+ivy)=vyiuy.f'(z) = \lim_{k\to0}\frac{f(x,y+k)-f(x,y)}{ik} = \frac{1}{i}\left(\frac{\partial u}{\partial y}+i\frac{\partial v}{\partial y}\right) = \frac{\partial v}{\partial y} - i\frac{\partial u}{\partial y}.

These two expressions for f(z)f'(z) must be the identical complex number. Matching real parts and matching imaginary parts gives the Cauchy-Riemann equations:

ux=vy,uy=vx.\frac{\partial u}{\partial x} = \frac{\partial v}{\partial y}, \qquad \frac{\partial u}{\partial y} = -\frac{\partial v}{\partial x}.

A function is analytic on a region exactly when uu and vv have continuous partial derivatives there satisfying these two equations at every point. Polynomials in zz, eze^z, sinz\sin z, cosz\cos z, and 1/z1/z (away from z=0z=0) are all analytic wherever they are defined; a function as simple-looking as f(z)=zˉ=xiyf(z)=\bar z=x-iy is not analytic anywhere, since here u=x,v=yu=x,v=-y gives u/x=1\partial u/\partial x=1 but v/y=1\partial v/\partial y=-1, and the equations fail at every point. Analyticity is a genuine, checkable restriction, not a technicality.

Cauchy's integral theorem

Everything that follows rests on one theorem about integrating an analytic function around a closed loop. Let CC be a simple closed curve (one that does not cross itself) traversed counterclockwise, and suppose ff is analytic everywhere on CC and everywhere inside it. Then

Cf(z)dz=0.\oint_C f(z)\,dz = 0.

This is Cauchy's integral theorem, and it is not an assumption — it follows directly from the Cauchy-Riemann equations, by a route that should look familiar. Write dz=dx+idydz=dx+i\,dy and expand:

f(z)dz=(u+iv)(dx+idy)=(udxvdy)+i(vdx+udy).f(z)\,dz = (u+iv)(dx+i\,dy) = (u\,dx - v\,dy) + i(v\,dx+u\,dy).

Each of the two bracketed expressions is a real line integral of the form (Pdx+Qdy)\oint(P\,dx+Q\,dy), and Green's theorem converts each into an area integral:

C(Pdx+Qdy)=D(QxPy)dA.\oint_C (P\,dx+Q\,dy) = \iint_D \left(\frac{\partial Q}{\partial x}-\frac{\partial P}{\partial y}\right)dA.

For the real part, P=u, Q=vP=u,\ Q=-v, so the integrand becomes v/xu/y-\partial v/\partial x - \partial u/\partial y. The Cauchy-Riemann equations say u/y=v/x\partial u/\partial y=-\partial v/\partial x, so this is v/x(v/x)=0-\partial v/\partial x-(-\partial v/\partial x)=0. For the imaginary part, P=v, Q=uP=v,\ Q=u, and the integrand becomes u/xv/y\partial u/\partial x-\partial v/\partial y, which the other Cauchy-Riemann equation sets to zero directly. Both area integrals vanish identically, so the loop integral vanishes:

Cf(z)dz=0.\oint_C f(z)\,dz = 0.

This is exactly the fact already met as curl-free fields: a vector field integrates to zero around every closed loop precisely when its curl vanishes. Cauchy's theorem is that same statement, applied simultaneously to the two real vector fields (u,v)(u,-v) and (v,u)(v,u) built from an analytic function's real and imaginary parts — and the Cauchy-Riemann equations are exactly what force both curls to vanish at once. Analyticity is curl-freeness, worn as a disguise.

Cauchy's integral formula

Cauchy's theorem has a companion that turns out to be even more useful. Suppose ff is analytic on and inside a closed contour CC, and aa is some point strictly inside CC. Then

f(a)=12πiCf(z)zadz.f(a) = \frac{1}{2\pi i}\oint_C \frac{f(z)}{z-a}\,dz.

This says something remarkable: the value of an analytic function anywhere inside a loop is completely determined by its values on the loop. To see why, notice that f(z)/(za)f(z)/(z-a) is analytic everywhere inside CC except at the single point z=az=a. Shrink the original contour down to a tiny circle of radius ϵ\epsilon centered at aa; Cauchy's theorem, applied to the ring-shaped region between the two contours (where the integrand is analytic throughout), guarantees the two contour integrals are equal. So

Cf(z)zadz=za=ϵf(z)zadz.\oint_C \frac{f(z)}{z-a}\,dz = \oint_{|z-a|=\epsilon} \frac{f(z)}{z-a}\,dz.

Parametrize the small circle as z=a+ϵeiθz=a+\epsilon e^{i\theta}, so dz=iϵeiθdθdz=i\epsilon e^{i\theta}\,d\theta and za=ϵeiθz-a=\epsilon e^{i\theta}:

za=ϵf(z)zadz=02πf(a+ϵeiθ)ϵeiθiϵeiθdθ=i02πf(a+ϵeiθ)dθ.\oint_{|z-a|=\epsilon}\frac{f(z)}{z-a}\,dz = \int_0^{2\pi}\frac{f(a+\epsilon e^{i\theta})}{\epsilon e^{i\theta}}\,i\epsilon e^{i\theta}\,d\theta = i\int_0^{2\pi}f(a+\epsilon e^{i\theta})\,d\theta.

The radius ϵ\epsilon has canceled completely out of the integrand. Now let ϵ0\epsilon\to0: since ff is continuous, f(a+ϵeiθ)f(a)f(a+\epsilon e^{i\theta})\to f(a) for every θ\theta, and the integral becomes

i02πf(a)dθ=2πif(a).i\int_0^{2\pi}f(a)\,d\theta = 2\pi i\,f(a).

Putting the two results together gives Cauchy's integral formula. Differentiating both sides with respect to aa, nn times, under the integral sign — a mechanical but slightly lengthy step, not repeated here — produces the generalized version for derivatives:

f(n)(a)=n!2πiCf(z)(za)n+1dz.f^{(n)}(a) = \frac{n!}{2\pi i}\oint_C \frac{f(z)}{(z-a)^{n+1}}\,dz.

This single formula, turning an nnth derivative into a contour integral, is going to reappear by name in the closing section of this topic.

Poles and residues

Suppose ff fails to be analytic at an isolated point aa, but is analytic everywhere in a small punctured disk around it. If (za)nf(z)(z-a)^nf(z) stays finite and nonzero as zaz\to a for some positive integer nn, then aa is called a pole of order nn. Near such a point, ff has a Laurent series — an ordinary power series extended to include a finite number of negative powers of (za)(z-a):

f(z)=cn(za)n++c1za+c0+c1(za)+f(z) = \frac{c_{-n}}{(z-a)^n}+\cdots+\frac{c_{-1}}{z-a}+c_0+c_1(z-a)+\cdots

Every coefficient here carries information about ff, but one of them is special: the coefficient of 1/(za)1/(z-a), called the residue of ff at aa and written Resz=af\operatorname{Res}_{z=a}f.

Here is why it is special. Integrate the Laurent series term by term around a tiny circle centered at aa. Parametrizing as before, z=a+ϵeiθz=a+\epsilon e^{i\theta},

za=ϵ(za)kdz=02πϵkeikθiϵeiθdθ=iϵk+102πei(k+1)θdθ,\oint_{|z-a|=\epsilon}(z-a)^k\,dz = \int_0^{2\pi}\epsilon^ke^{ik\theta}\,i\epsilon e^{i\theta}\,d\theta = i\epsilon^{k+1}\int_0^{2\pi}e^{i(k+1)\theta}\,d\theta,

for any integer kk (positive, negative, or zero). If k1k\neq-1, the exponent k+1k+1 is a nonzero integer, and 02πei(k+1)θdθ=0\int_0^{2\pi}e^{i(k+1)\theta}\,d\theta=0, since a nonzero-frequency complex exponential integrates to zero over a full period. But if k=1k=-1, the exponential disappears entirely: 02π1dθ=2π\int_0^{2\pi}1\,d\theta=2\pi, and the prefactor ϵk+1=ϵ0=1\epsilon^{k+1}=\epsilon^0=1 is independent of ϵ\epsilon. So every term in the Laurent series integrates to zero except the 1/(za)1/(z-a) term, which contributes exactly 2πic12\pi i\,c_{-1}. That is,

za=ϵf(z)dz=2πiResz=af.\oint_{|z-a|=\epsilon}f(z)\,dz = 2\pi i\operatorname{Res}_{z=a}f.

Out of an entire infinite series of coefficients, integration is a filter that lets exactly one of them through. For a simple pole (n=1n=1), the residue has a convenient shortcut:

Resz=af=limza(za)f(z).\operatorname{Res}_{z=a}f = \lim_{z\to a}(z-a)f(z).

In particular, for a ratio f(z)=p(z)/q(z)f(z)=p(z)/q(z) where qq has a simple zero at aa (so q(a)=0q(a)=0 but q(a)0q'(a)\neq0), L'Hôpital's rule applied to this limit gives the frequently useful form

Resz=af=p(a)q(a).\operatorname{Res}_{z=a}f = \frac{p(a)}{q'(a)}.

The residue theorem

Now combine everything. Suppose ff is analytic on and inside a closed contour CC, except for finitely many isolated poles a1,,aNa_1,\ldots,a_N located strictly inside CC. Cut a tiny circle out around each pole and connect each one to CC with a thin corridor; on the resulting region, with all the poles excised, ff is analytic everywhere, so Cauchy's theorem applies and the integral around the whole boundary of this region is zero. The corridor contributions are traversed once in each direction and cancel exactly. What remains is CC itself, traversed counterclockwise, together with the small circles around each pole, traversed clockwise (since they are cut out of the region). Flipping their orientation back to counterclockwise introduces a sign, giving the residue theorem:

Cf(z)dz=2πik=1NResz=akf.\oint_C f(z)\,dz = 2\pi i\sum_{k=1}^N \operatorname{Res}_{z=a_k}f.

An entire loop integral, however complicated the function looks elsewhere in the plane, collapses to a finite sum of numbers extracted at isolated points.

Closing the contour: turning a real integral into a complex one

The residue theorem is a statement about closed loops in the complex plane, but the integral we started with runs along the entire real line. The bridge between them is a standard construction called closing the contour. Build a closed loop CRC_R out of two pieces: the straight segment from R-R to RR along the real axis, and a semicircular arc ΓR\Gamma_R of radius RR in the upper half-plane connecting RR back to R-R. As RR\to\infty, the straight piece becomes the entire real-line integral we want.

Everything hinges on what happens to the arc. If f(z)|f(z)| falls off fast enough as z|z|\to\infty in the upper half-plane, the arc's contribution vanishes in the limit, by the estimation lemma: if f(z)MR|f(z)|\leq M_R everywhere on ΓR\Gamma_R, then

ΓRf(z)dzMR(length of ΓR)=MRπR.\left|\int_{\Gamma_R}f(z)\,dz\right| \leq M_R\cdot(\text{length of }\Gamma_R) = M_R\cdot\pi R.

For a ratio of polynomials whose denominator degree exceeds the numerator degree by two or more, MR1/R2M_R\sim1/R^2, and MRπR0M_R\cdot\pi R\to0. For integrands carrying an oscillating factor eize^{iz} instead — which only decays in the upper half-plane, since for z=x+iyz=x+iy with y>0y>0, eiz=eixey=ey<1|e^{iz}|=|e^{ix}e^{-y}|=e^{-y}<1 — a sharper argument called Jordan's lemma shows the arc still vanishes even when the remaining factor only decays as slowly as 1/R1/R. Either way, once the arc is shown to vanish,

f(x)dx=limRCRf(z)dz=2πi(residues enclosed in the upper half-plane).\int_{-\infty}^{\infty}f(x)\,dx = \lim_{R\to\infty}\oint_{C_R}f(z)\,dz = 2\pi i\sum(\text{residues enclosed in the upper half-plane}).

A real integral over an infinite line has become a finite sum of residues, provided you can show the far-away arc contributes nothing.

A complex plane diagram showing the real axis with a segment from minus R to plus R, closed by a semicircular arc through the upper half-plane back to minus R. A filled amber dot inside the contour marks the enclosed pole at z equals i, with an arrow indicating the counterclockwise direction of travel along both the segment and the arc. A fainter gray dot below the real axis marks the excluded pole at z equals minus i, outside the contour.

Closing the contour: the real line from minus R to R, plus a semicircular arc through the upper half-plane, encloses only the poles above the real axis — here the one at z equals positive i, but not the one at minus i.

Worked example

Evaluate dx1+x2\displaystyle\int_{-\infty}^{\infty}\frac{dx}{1+x^2} by contour integration, showing every step: closing the contour, identifying the enclosed pole, computing the residue, and applying the residue theorem. (click to reveal the solution)

Setting up: extend the integrand to the complex plane, f(z)=11+z2f(z)=\dfrac{1}{1+z^2}. Factor the denominator:

1+z2=(zi)(z+i),1+z^2 = (z-i)(z+i),

so ff has two simple poles, at z=iz=i and z=iz=-i, and is analytic everywhere else.

Closing the contour: build CRC_R from the real segment [R,R][-R,R] together with the semicircular arc ΓR: z=Reiθ, θ[0,π]\Gamma_R:\ z=Re^{i\theta},\ \theta\in[0,\pi], closing the loop in the upper half-plane.

Showing the arc vanishes: on ΓR\Gamma_R, the reverse triangle inequality gives

1+z2=z2(1)z21=R21,|1+z^2| = |z^2-(-1)| \geq |z|^2-1 = R^2-1,

so

f(z)1R21everywhere on ΓR.|f(z)| \leq \frac{1}{R^2-1} \quad\text{everywhere on }\Gamma_R.

The arc has length πR\pi R, so by the estimation lemma,

ΓRf(z)dz1R21πR=πRR21R0.\left|\int_{\Gamma_R}f(z)\,dz\right| \leq \frac{1}{R^2-1}\cdot\pi R = \frac{\pi R}{R^2-1}\xrightarrow[R\to\infty]{}0.

The arc contributes nothing in the limit.

Identifying the enclosed pole: the upper-half-plane contour CRC_R, for any R>1R>1, encloses z=iz=i (since i=1<R|i|=1<R and ii lies above the real axis) but not z=iz=-i (which lies below the real axis, outside the region enclosed by this particular contour).

Computing the residue: since z=iz=i is a simple pole,

Resz=if=limzi(zi)1(zi)(z+i)=1i+i=12i.\operatorname{Res}_{z=i}f = \lim_{z\to i}(z-i)\cdot\frac{1}{(z-i)(z+i)} = \frac{1}{i+i} = \frac{1}{2i}.

Applying the residue theorem:

CRf(z)dz=2πi12i=π.\oint_{C_R}f(z)\,dz = 2\pi i\cdot\frac{1}{2i} = \pi.

Taking the limit: the left side splits into the straight segment and the arc,

CRf(z)dz=RRdx1+x2+ΓRf(z)dz.\oint_{C_R}f(z)\,dz = \int_{-R}^{R}\frac{dx}{1+x^2} + \int_{\Gamma_R}f(z)\,dz.

As RR\to\infty, the arc term vanishes and the segment term becomes the full real-line integral, so

dx1+x2=π.\int_{-\infty}^{\infty}\frac{dx}{1+x^2} = \pi.

Checking the result: this integral also has an elementary antiderivative, arctanx\arctan x, and

dx1+x2=[arctanx]=π2(π2)=π,\int_{-\infty}^{\infty}\frac{dx}{1+x^2} = \Big[\arctan x\Big]_{-\infty}^{\infty} = \frac{\pi}{2}-\left(-\frac{\pi}{2}\right) = \pi,

exactly matching the contour-integration answer. This is reassuring precisely because it is a case where you could check the machinery against an answer obtained the ordinary way — before turning it loose, in the next section, on an integral that offers no such elementary check.

Cashing in the trick: the integral we started with

Return to cosx1+x2dx\displaystyle\int_{-\infty}^\infty\frac{\cos x}{1+x^2}\,dx, the integral with no elementary antiderivative. The move is to stop looking at cosx\cos x directly and instead consider

eix1+x2dx.\int_{-\infty}^{\infty}\frac{e^{ix}}{1+x^2}\,dx.

Since 1+x21+x^2 is real and eix=cosx+isinxe^{ix}=\cos x+i\sin x, this integral's real part is exactly cosx/(1+x2)dx\int\cos x/(1+x^2)\,dx, and its imaginary part is sinx/(1+x2)dx\int\sin x/(1+x^2)\,dx, which vanishes automatically because sinx/(1+x2)\sin x/(1+x^2) is an odd function integrated over a symmetric interval. So computing the complex integral hands back the real one, for free, as its real part.

The function g(z)=eiz/(1+z2)g(z)=e^{iz}/(1+z^2) has the same two poles as before, at z=±iz=\pm i, and the same contour closes it: on the upper-half-plane arc, z=Reiθz=Re^{i\theta} with θ[0,π]\theta\in[0,\pi], so eiz=eRsinθ1|e^{iz}|=e^{-R\sin\theta}\leq1, while 1/(1+z2)1/(R21)|1/(1+z^2)|\leq1/(R^2-1) as before. The same estimation-lemma bound applies without needing Jordan's lemma at all here — the polynomial factor alone already decays like 1/R21/R^2, and eiz1|e^{iz}|\leq1 throughout the upper half-plane is enough to keep the product decaying just as fast, so the arc vanishes as RR\to\infty exactly as in the worked example.

Only z=iz=i is enclosed. The residue there is

Resz=ig=limzi(zi)eiz(zi)(z+i)=ei(i)2i=e12i.\operatorname{Res}_{z=i}g = \lim_{z\to i}(z-i)\cdot\frac{e^{iz}}{(z-i)(z+i)} = \frac{e^{i(i)}}{2i} = \frac{e^{-1}}{2i}.

By the residue theorem,

CRg(z)dz=2πie12i=πe.\oint_{C_R}g(z)\,dz = 2\pi i\cdot\frac{e^{-1}}{2i} = \frac{\pi}{e}.

Taking RR\to\infty exactly as before,

eix1+x2dx=πe.\int_{-\infty}^{\infty}\frac{e^{ix}}{1+x^2}\,dx = \frac{\pi}{e}.

The right side is already a real number, consistent with the vanishing imaginary part noted above, and it is entirely the real part:

cosx1+x2dx=πe.\int_{-\infty}^{\infty}\frac{\cos x}{1+x^2}\,dx = \frac{\pi}{e}.

The number promised at the very start of this topic drops out of exactly one residue calculation — the same pole, z=iz=i, doing the same job it did in the worked example, just carrying one extra factor of eize^{iz} along for the ride.

Where this leads

The residue theorem is not a curiosity confined to definite integrals. Real integrals that show up throughout physics as Fourier transforms of decaying or oscillating signals — exactly the kind built on Fourier analysis — are routinely evaluated this same way: extend the integrand to the complex plane, close the contour, read off the residues.

There is also a much closer connection, one flagged explicitly at the end of the special functions topic. Rodrigues' formula generates the Legendre polynomials as an ll-th derivative,

Pl(x)=12ll!dldxl(x21)l.P_l(x) = \frac{1}{2^ll!}\frac{d^l}{dx^l}\left(x^2-1\right)^l.

Apply the generalized Cauchy integral formula from earlier in this topic, f(n)(a)=n!2πiCf(z)(za)n+1dzf^{(n)}(a)=\dfrac{n!}{2\pi i}\displaystyle\oint_C\dfrac{f(z)}{(z-a)^{n+1}}\,dz, to f(z)=(z21)lf(z)=(z^2-1)^l with n=ln=l and a=xa=x:

dldzl(z21)lz=x=l!2πiC(t21)l(tx)l+1dt.\frac{d^l}{dz^l}(z^2-1)^l\bigg|_{z=x} = \frac{l!}{2\pi i}\oint_C\frac{(t^2-1)^l}{(t-x)^{l+1}}\,dt.

Substituting this into Rodrigues' formula, the two factors of l!l! cancel:

Pl(x)=12ll!l!2πiC(t21)l(tx)l+1dt=12πiC(t21)l2l(tx)l+1dt.P_l(x) = \frac{1}{2^ll!}\cdot\frac{l!}{2\pi i}\oint_C\frac{(t^2-1)^l}{(t-x)^{l+1}}\,dt = \frac{1}{2\pi i}\oint_C\frac{(t^2-1)^l}{2^l(t-x)^{l+1}}\,dt.

This is Schläfli's integral representation of the Legendre polynomials — the same functions built by repeated differentiation on that earlier page, rebuilt here as a single contour integral, with the differentiation itself packaged inside the generalized Cauchy formula derived above. A derivative repeated ll times and a loop integral around one point turn out to be the same object, viewed from two different angles.