<s>[INST] Indefinite integral involving arctan How should I evaluate this definite integral? I am unable to figure out how to start.
$$\int \tan^{-1} \left(1 + x + x^{2}\right) dx $$
 [/INST] Proceed by integration by parts, we get
\begin{align*}
\int \arctan \left( 1 + x + x^2 \right) dx & = x \arctan \left(1+x+x^2 \right) - \int \dfrac{x(2x+1)}{(x^2+x+1)^2+1} dx
\end{align*}
Now note that $$\left(x^2+x+1 \right)^2+1 = \left(x^2+1 \right) \left(x^2+2x+2 \right)$$
Hence, $$\dfrac{x(2x+1)}{(x^2+x+1)^2+1} = \dfrac{x}{x^2+1} - \dfrac{x}{x^2 + 2x+2}$$
Hence,
$$\int \dfrac{x(2x+1)}{(x^2+x+1)^2+1} dx = \int \dfrac{x dx}{x^2+1} - \int \dfrac{x dx}{x^2 + 2x+2}$$
$$\int \dfrac{x dx}{x^2+1} = \dfrac12 \log \left(1+x^2 \right)$$
$$\int \dfrac{x dx}{x^2 + 2x+2} = \int \dfrac{\left(x + 1 \right) dx}{\left( x+1 \right)^2+1} - \int \dfrac{dx}{\left( x+1 \right)^2+1} = \dfrac12 \log \left((x+1)^2+1\right) - \arctan(x+1)$$
Putting all this together, we get that
$$x \arctan \left( 1+x+x^2 \right) - \dfrac12 \log \left( 1+x^2\right) + \dfrac12 \log \left((x+1)^2+1\right) - \arctan(x+1)$$
Rearranging gives us
$$x \arctan \left( 1+x+x^2 \right) - \arctan(x+1) + \dfrac12 \log \left(\dfrac{(x+1)^2+1}{x^2+1}\right) + \text{ constant}$$
</s>