Solution (source code)

= Solution

A <pole> of order $N$ at $z_0$ has $(z-z_0)^Nf(z)$ extending holomorphically to a nonzero value there. Its <residue> is the coefficient of $(z-z_0)^{-1}$ in the <Laurent series>. The <Cauchy integral theorem> gives $\oint_Cf\,dz=0$ for a closed contour in a simply connected domain of holomorphicity. The <residue theorem> replaces zero by $2\pi i$ times the enclosed residues for a positively oriented simple contour avoiding finitely many poles.

For the first integral, use the upper-half-plane semicircle, with a small clockwise upper semicircle excluding the origin. Near zero,
$$
\frac{e^{iaz}-e^{ibz}}{z^2}=\frac{i(a-b)}z+O(1).
$$
There are no poles inside the indented contour. The large arc vanishes because $a,b>0$ and the integrand there is $O(R^{-2})$; the small arc tends to $-i\pi\,i(a-b)=\pi(a-b)$. Therefore the real-axis complex principal value is $\pi(b-a)$. Taking real parts gives the ordinary convergent <cosine-difference inverse-square integral>
$$
\boxed{\int_{-\infty}^{\infty}\frac{\cos ax-\cos bx}{x^2}dx=\pi(b-a).}
$$
The real numerator cancels to second order at zero, so this final real integral itself needs no principal-value convention.

For $g(z)=e^{az}/\cosh\pi z$, the simple poles are $z_n=i(n+1/2)$, $n\in\mathbb Z$. Differentiating the denominator gives
$$
\boxed{\operatorname{Res}_{z_n}g=\frac{(-1)^n e^{ia(n+1/2)}}{\pi i}.}
$$
Integrate around the rectangle with vertices $-R,R,R+i,-R+i$. It contains only $i/2$. On the top side $g(x+i)=-e^{ia}g(x)$, and reversed traversal therefore contributes $+e^{ia}$ times the bottom integral. The vertical sides vanish for $|a|<\pi$. The <residue theorem> gives $(1+e^{ia})J=2e^{ia/2}$, so the <exponential moment of the hyperbolic secant> is
$$
\boxed{J=\int_{\mathbb R}\frac{e^{ax}}{\cosh\pi x}dx=\frac1{\cos(a/2)},\qquad-\pi<a<\pi.}
$$

\Image[/past-exam-of-the-mathematics-course-of-the-year-2-of-the-natural-sciences-course-of-the-university-of-cambridge/2005/paper-2-residue-contours.png]
{title=Indented semicircle and height-one rectangle for the two real integrals}
{description=Original contour diagrams. The left contour excludes the origin with a clockwise indentation; the right encloses only the pole $i/2$. Other hyperbolic-secant poles are shown outside the rectangle.}