I was trying to evalute the integral $$\int \frac{1}{x^2+1} \,dx$$ by partial fractions.
$$\frac{1}{x^2+1} = \frac{1}{2i}\left(\frac{1}{x-i} - \frac{1}{x+i}\right)$$
Therefore, \begin{aligned} \int \frac{1}{x^2+1} \,dx &= \frac{1}{2i} \int \left(\frac{1}{x-i} - \frac{1}{x+i}\right) \,dx \\ &= \frac{1}{2i} (\ln(x-i) - \ln(x+i)) \\ &= \arctan\left(\frac{1}{x}\right) +C \end{aligned}
Because $$ x - i = \exp\left(\sqrt{x^2+1}+i\arctan{\frac{1}{x}}\right)$$ and $$ x + i = \exp\left(\sqrt{x^2+1}-i\arctan{\frac{1}{x}}\right).$$
This differs from what you get from trigonometric substitution, which is where I'm having difficulties in finding my error.
In the last step, I'm assuming that $\ln(z)$ works as you would expect for complex numbers.
In the your fifth equation you will actually get $$I=-\tan^{-1}(1/x)+C$$ and due to the identity: $$\tan^{-1} x+\tan^{-1} (1/x)= \pi/2$$ We get $$I=\pi/2+\tan^{-1} x+ D$$ Uther wise the standard formula gives $$I=\tan^{-1} x+E$$ These two results differ only by a constant, which is normal in indefinite integration.