# A "creative" integral

An interesting “creative” integral pointed my way by the marvellous @DavidKButlerUoA:

Find $\int {\frac{1}{(1+x^2)^2}} \dx$

There are “proper” ways to do this - in his tweet, David shows a clever way to do it by parts, and suggests a trig substitution as an alternative. I want to show a third way: partial fractions.

But wait - it’s already as partial-fractioned as it’s going to get, surely? Well, yes - but only if you stick to the reals.

If we bring imaginary numbers into play, we get:

$\frac{1}{(1+x^2)^2} = \frac{A}{x+i} + \frac{B}{(x+i)^2} + \frac{C}{x-i} + \frac{D}{(x-i)^2}$

Let’s multiply all of that up:

$1 = A(x+i)(x-i)^2 + B(x-i)^2 + C(x-i)(x+i)^2 + D(x+i)^2$

Then, when $x=i$, $1 = -4D$; when $x=-i$, $1=-4B$.

When $x=0$, $1= -(B+D) + (C-A)i$, which tells us that $C-A = -\frac{i}{2}$

And, considering just the $x^3$ terms, we have $0=A + C$, so $A=\frac{i}{4}$ and $C=-\frac{i}{4}$.

Putting it all together, we have $\frac{1}{(1+x^2)^2} = \frac{1}{4}\left( \frac{i}{x+i} - \frac{1}{(x+i)^2} - \frac{i}{x-i} - \frac{1}{(x-i)^2} \right)$

## Now to integrate!

I’ll start by farming the 4 out to the other side.

$4I = \int \left( \frac{i}{x+i} - \frac{1}{(x+i)^2} - \frac{i}{x-i} - \frac{1}{(x-i)^2} \right) \dx$

Then we can integrate. All of these pan out as you’d expect:

$\dots = i \ln |x+i| + (x+i)^{-1} - i \ln |x-i| + (x-i)^{-1} + C$

… and we can start to simplify.

$\dots = i \ln \left| \frac{x+i}{x-i} \right| + \frac{ (x-i) + (x+i) }{(x-i)(x+i) } + C$

The second term is going to play nicely (it’s $\frac{2x}{x^2+1}$), but the first looks a bit off. We don’t really want to let on that we’ve used imaginary numbers now, do we?

## A bit of legerdemain

A complex number - like, for example, $z = x+i$ - can be written in the form $Re^{i\theta}$, where $R$ is a real number, the magnitude, and $\theta$ is a real angle, the argument.

That leads to the conclusion that $\ln(z) = \ln(R) + i\theta$, if we’re willing to play fast and loose with the fact that we could have multiple arguments.

In particular, if $x$ is real, then $\ln(x+i) = \ln(x^2+1) + i\arctan\left(\frac{1}{x}\right)$.

Similarly, $\ln(x-i) = \ln(x^2 + 1) - i \arctan\left(\frac{1}{x}\right)$.

In turn, that means $i\left(\ln(x+i) - \ln(x-i)\right) = -2\arctan\left(\frac{1}{x}\right)$: our first term has turned into something much more approachable! We can even rewrite it immediately as an arccotangent.

## Back to the plan

$4I = i \ln \left| \frac{x+i}{x-i} \right| + \frac{ (x-i) + (x+i) }{(x-i)(x+i) } + C$

$\dots = -2 \arccot(x) + \frac{2x}{x^2+1} + C$

Now, I’m not a big fan of arccotangents. Luckily, I have an arbitrary constant at hand, and I know that $\frac{\pi}{2} - \arccot(x) = \arctan(x)$. So, if I muddle the $\piby 2$ into the constant, I can turn my $-\arccot(x)$ into $\arctan(x)$:

$4I = 2\arctan(x) + \frac{2x}{x^2+1} + C_2$

Or, finally:

$\int \frac{1}{(1+x^2)^2} dx = \frac{1}{2} \arctan(x) + \frac{1}{2} \frac{x}{x^2+1} + c$.