A challenge question that found its way to me:

Find the exact value of $\int_0^\pi \frac{\sin^2(x)}{1+\cos^2(x)}\dx$.

“Looks pretty standard,” I thought. “How hard can it be?” Poor, naive past-Colin.

Poor naive past-Colin tried a barrage of substitutions – $u = \tan(x)$ looked briefly promising – before finally settling on some fractions work. Writing the integrand as $\frac{1 - \cos^2(x)}{1+\cos^2(x)}$, there are two “obvious” ways to make it nicer:

  • $1 - \frac{2\cos^2(x)}{1+\cos^2(x)}$; or
  • $\frac{2}{1+\cos^2(x)} - 1$.

The second looks significantly better – and now there’s scope to bring in a $\tan$ substitution. Leaving the trivial-to-integrate 1 for later, if we’ve got

$\int \frac{2}{1+\cos^2(x)}\dx$, we can let $u = \tan(x)$ and $\diff{u}{x} = \sec^2(x)$, or $1 + u^2$. Until recently – by which I mean last night at MathsJam – I would have written $\d u = \sec^2(x) \d x$ and felt dirty about it; $\diff ux$ is not a fraction and it’s strictly incorrect to treat it as one, even if it works. Instead, it’s better to write $1 = \diff ux \frac{1}{1+u^2}$ and simply multiply by $1$. Lovely.

That makes our (current) integral $\int \frac{2}{1 + \frac{1}{1+u^2}} \cdot \frac{1}{1+u^2} \diff ux \dx$, which simplifies to $\int \frac{2}{u^2 + 2} \d u$.

That can be done with another $\tan$ substitution (I think something like $u = \tan(t)\sqrt{2}$), or by inspection: either way, you get $\sqrt{2} \arctan\left( \frac{u}{\sqrt{2}}\right)$ (plus a constant).

And the limits… the limits are both zero. Eh? The integral clearly isn’t zero, it’s positive everywhere on the domain except the ends. What’s going on?

Did you spot the problem with the substitution? $\tan(x)$ is undefined at $x=\piby2$, and that wreaks havoc with everything.

Fortunately, there’s a workaround: because the integrand is symmetric around $x=\piby2$, we can (conceptually) fold it over and say $\int_0^\pi \frac{2}{1+\cos^2(x)} \dx = \int_0^{\piby2} \frac{4}{1+\cos^2(x)}\dx$ – and now the discontinuity is at the end of the interval rather than inside it. (We should still do some sort of limiting process, to be completely ok, but I’ll leave that as an exercise).

So our (current) integral works out to $2\sqrt{2} \arctan\left( \frac{u}{\sqrt{2}} \right)$ with limits of 0 and $\infty$ – and this evaluates very quickly to $\pi \sqrt{2}$

We’ve still got $\int_0^\pi 1 \dx$, which is trivially $\pi$, to take away, so the integral’s final answer is $\pi\left(\sqrt{2}-1\right)$.

Ooft. An unpleasant one, that – do you have a less circuitous route to the answer? I’d love to hear it.

  • Thanks to James Anthony for showing me the happy path to integration.