<s>[INST] Integrate $\int \ln(x^2 +1)\ dx$ $$\int \ln(x^2 +1)\ dx$$
I done it using integration by parts where 
$\int u\ dv = uv - \int v\ du$
Let $u$ = $\ln(x^2 +1)$ 
$du = \frac{2x}{x^2+1} dx $
Let $dv = dx$ so $v=x$ 
$\int \ln(x^2 +1)\ dx = x \ln (x^2 +1) - \int \frac{2x^2}{x^2+1} $
I integrate $2\int \frac{x^2}{x^2+1} $ separately using substitution.
Let $u$ = $x^2 + 1$ -> $dx= \frac{1}{2x} du $
substitute $u$ back into it I get a simplified $\int \frac{x}{x^2 + 1} dx$ 
I used substitution again and got $ \frac{1}{2} \int \frac{1}{u} du$
When I sub it back into the original question, this is my final answer, 
$x\ln(x^2 +1) + \frac{1}{2} \ln(x^2 +1) + C$
However, this answer is wrong, 
The answer is, $x\ln(x^2 +1) - 2x + 2\tan^{-1} (x) + C $
I believe my integration of  $2\int \frac{x^2}{x^2+1} $ is wrong. Where did I went wrong ?  
 [/INST] Your integration by parts in the beginning is correct. Truly :
$${\displaystyle\int}\ln\left(x^2+1\right)\,\mathrm{d}x =x\ln\left(x^2+1\right)-{\displaystyle\int}\dfrac{2x^2}{x^2+1}\,\mathrm{d}x$$
Now, handling the second integral, first of all let's factor out the constant and write $x^2$ as $x^2 + 1 - 1$ to split it up :
$${\displaystyle\int}\dfrac{2x^2}{x^2+1}\,\mathrm{d}x =\class{steps-node}{\cssId{steps-node-1}{2}}{\displaystyle\int}\dfrac{x^2}{x^2+1}\,\mathrm{d}x ={\displaystyle\int}\left(\dfrac{\class{steps-node}{\cssId{steps-node-4}{x^2+1}}}{x^2+1}-\dfrac{\class{steps-node}{\cssId{steps-node-5}{1}}}{x^2+1}\right)\mathrm{d}x $$
$$=$$
$$={\displaystyle\int}\left(1-\dfrac{1}{x^2+1}\right)\mathrm{d}x ={\displaystyle\int}1\,\mathrm{d}x-{\displaystyle\int}\dfrac{1}{x^2+1}\,\mathrm{d}x =2x-2\arctan\left(x\right)$$
The integral is now solved and we yield the result :
$${\displaystyle\int}\ln\left(x^2+1\right)\,\mathrm{d}x=x\ln\left(x^2+1\right)+2\arctan\left(x\right)-2x + C$$
</s>