Evaluate $\int \frac{x^2 + x+3}{x^2+2x+5}\ dx$ How can we evaluate $$\displaystyle\int \frac{x^2 + x+3}{x^2+2x+5} dx$$  
To be honest, I'm embarrassed. I decomposed it and know what the answer should be but
I can't get the right answer. 
 A: You can decompose your integrand as follows:
$$ \frac{ x^2 + 2x + 5 - x - 1 - 1}{x^2 + 2x + 5} = 1 - \frac{x + 1}{x^2 + 2x + 5} - \frac{1}{(x+1)^2 + 4}$$
You can integrate the first term directly, the second term after the substitution $u = x^2 + 2x + 5$, and the third term by recalling that $(\arctan{x})' = 1/(x^2 + 1)$, and then using another substitution to make the expression look like the derivative of $\arctan$.
A: Hint Use the decomposition
$$\frac{x^2 + x+3}{x^2+2x+5}=1-\frac{ x+2}{x^2+2x+5}=1-\frac{1}{2}\frac{ 2x+2}{x^2+2x+5}-\frac{ 1}{x^2+2x+5}$$
and 
$$\frac{ 1}{x^2+2x+5}=\frac{ 1}{(x+1)^2+4}=\frac{1}{4}\frac{ 1}{(\frac{x+1}{2})^2+1}$$
the first fraction is on the form $\frac{f'}{f}$ and the second have the form $\frac{1}{u^2+1}$ by change of variable.
A: $$I=\int \frac{x^2 + x+3}{x^2+2x+5} dx=\int \frac{x(x+1)+3}{(x+1)^2+2^2} dx$$ 
Putting $x+1=2\tan\theta,dx=2\sec^2\theta d\theta,$
$$I= \frac{2\tan\theta(2\tan\theta-1)+3}{4\sec^2\theta d\theta}2\sec^2\theta d\theta$$
$$2\tan\theta(2\tan\theta-1)+3=4\tan^2\theta-2\tan\theta+3=4\sec^2\theta-2\tan\theta-1$$
$$\text{So,} I=\frac12\int(4\sec^2\theta-2\tan\theta-1)d\theta=2\tan\theta-\log|\sec\theta+\tan\theta|-\theta+C $$ where $C$ is an arbitrary constant for indefinite integration.
As $\tan\theta=\frac{x+1}2,$
$\sec^2\theta =1+\left(\frac{x+1}2\right)^2=\frac{x^2+2x+5}4$
$\theta=\arctan \left(\frac{x+1}2\right)$
