<s>[INST] Integration by partial fractions I've attempted to integrate the function $$\frac{2x^3 + 5x^2 + 8x + 4}{(x^2 + 2x + 2)^2}$$ using several techniques, but none of them are solving it nicely.
I've tried to slve it by partial fractions:
$$\frac{A + Bx}{x^2 + 2x + 2} + \frac{C + Dx}{(x^2 + 2x + 2)^2},$$ but i get wrong coefficients.
 [/INST] Let us start with $$\frac{2x^3 + 5x^2 + 8x + 4}{(x^2 + 2x + 2)^2}=\frac{A + Bx}{x^2 + 2x + 2} + \frac{C + Dx}{(x^2 + 2x + 2)^2}$$ Remove the denominator, expand and group the terms. You should arrive to $$2x^3 + 5x^2 + 8x + 4=B x^3+ (A+2 B)x^2+(2 A+2 B+D)x+(2 A+C)$$ which gives the four equations $B=2$,$A+2B=5$ so $A=1$, $2A+2B+D=8$ so $D=2$, $2A+C=4$ so $C=2$. 
So we have $$\frac{2x^3 + 5x^2 + 8x + 4}{(x^2 + 2x + 2)^2}=\frac{1 + 2x}{x^2 + 2x + 2} + \frac{2 + 2x}{(x^2 + 2x + 2)^2}=\frac{2x+2-1}{x^2 + 2x + 2} + \frac{2x + 2}{(x^2 + 2x + 2)^2}$$ So, setting $u=x^2+2x+2$, you can notice that $2x+2$ is just $u'$ which make things very simple for two parts and what is basically left is $$\int \frac{dx}{x^2+2x+2}=\int \frac{dx}{(x+1)^2+1}$$
I am sure that you can take from here.
</s>