Imaginary numbers and partial fraction decomposition in integration If I have a function whose denominator has only complex roots, could I integrate it and perform partial fraction decomposition by separating the factors? For example, am I allowed to evaluate $$\int\frac{1}{(x+i)(x-i)}dx$$Or $$\int\frac{1}{(x+2i)(x-2i)}dx$$By partial fractions (without getting rid of $i$)?  I don't think I could continue since we are integrating along the $x$-axis. Edit: I am asking if in general I could integrating with imaginary numbers, not just in this specific example. I was giving a background.

Yes, but you need to be a bit careful. Formally you are just embedding the space of integrable functions $\mathbb{R} \to \mathbb{R}$ into the space of integrable functions $\mathbb{R} \to \mathbb{C}$ (which is its complexification), and this embedding is compatible with taking antiderivatives. Even though complex numbers appear in the calculation, because the original function you're integrating is real, the final answer must necessarily be real, so the imaginary parts have to cancel out somehow. Note that it is not necessary to allow $x$ to be complex.
The simplest examples where everything works out quite cleanly involve trigonometric functions. For example you can see this old thread which explains how to compute $\int_0^{2 \pi} \sin^{100} x \, dx$ by writing $\sin x = \frac{e^{ix} - e^{-ix}}{2i}$ and then expanding using the binomial theorem.
The case of rational functions is more complicated because logarithms appear. $\int \frac{1}{x^2 + 1} \, dx$ is a good example so let's work through that in some detail. The partial fraction decomposition is
$$\frac{1}{(x + i)(x - i)} = \frac{1}{2i} \left( \frac{1}{x + i} - \frac{1}{x - i} \right)$$
and integrating formally gives an antiderivative of
$$\int \frac{1}{1 + x^2} \, dx = \frac{1}{2i} \left( \ln (x + i) - \ln (x - i) \right).$$
But is this the right answer? We were expecting $\arctan x$, of course. This answer is actually correct if properly interpreted, but there is a subtlety here. Even if $x$ is real, $x + i$ and $x - i$ are complex, so to make sense of these expressions we have to pick a branch of the complex logarithm, which complicates things; different choices will differ by a constant (which isn't a big deal, that's just how antiderivatives work), but we also have to pick a branch cut, which is a complication you might want to avoid since the final answer shouldn't really depend on this choice.
To make things less confusing I would personally rewrite the partial fraction decomposition slightly, as
$$\frac{1}{(1 + ix)(1 - ix)} = \frac{1}{2} \left( \frac{1}{1 + ix} + \frac{1}{1 - ix} \right)$$
which, again integrating formally, gives an antiderivative of
$$\int \frac{1}{1 + x^2} \, dx = \frac{1}{2} \left( \frac{\log (1 + ix)}{i} - \frac{\log (1 - ix)}{i} \right)$$
where we define
$$\log (1 + z) = \sum_{n \ge 1} (-1)^{n-1} \frac{z^n}{n}$$
even if $z$ is complex (as long as $|z| < 1$). Now there's no issue with branches and branch cuts, or rather, the choice to use the Taylor series around $1$ makes this choice for us. From here we can write
$$\log (1 + ix) - \log (1 - ix) = \log \frac{1 + ix}{1 - ix}$$
(this is no longer entirely obvious with our specific choice of branch of the logarithm and needs to be checked) and now we need to stop and think a bit about what this function is actually doing. If $x$ is real, $1 + ix$ is a complex number which has polar form $re^{i \theta}$ such that $x = \tan \theta$. Then $1 - ix$ is its complex conjugate, which is $re^{-i \theta}$. So their ratio is $e^{2 i \theta}$. This gives, again at least formally,
$$\frac{1}{2i} \left( \log (1 + ix) - \log (1 - ix) \right) = \frac{1}{2i} \log e^{2i \theta} = \theta = \arctan x.$$
But you might rightfully feel a little wary of this argument, since it involves applying logarithm rules to the complex logarithm (again, even if $x$ is real) which generally only hold up to a multiple of $2 \pi i$, due to the whole issue with branches, and we also need to potentially say some things about the domain and range of $\arctan$ and so forth. You can check that everything is fine (computationally the worst that'll happen is that you pick up an additive constant, which is not an issue for antiderivatives) but at this point it is maybe more work than it's worth.
