<s>[INST] Transform $\int \frac{x^2}{x - 2}$ to $ \int x +\frac{4}{x-2} + 2 $ I was trying to solve the following integral and I failed so I went to wolframalpha to see the step by step solution, but the following transformation is confusing me.
$\int \frac{x^2}{x - 2} = \int x +\frac{4}{x-2} + 2  $
I am unable to do the transformation by myself. Could you please explain the steps  to get from $\int \frac{x^2}{x - 2} $ to $\int x +\frac{4}{x-2} + 2  $ ? The step is labeled as a "long division", but I have no idea what that means.
 [/INST] You can rewrite the expression in exactly the same way you normally complete the square: $x^2 = (x^2 - 4x + 4) + 4x - 4 = (x-2)^2 + 4x-4$.
Then work with the linear terms in the same way: $4x - 4 = 4(x-2) + 8 - 4 = 4(x-2) + 4$.
Put it together to get $x^2 = (x-2)^2 + 4(x-2) + 4$.
Then you can throw in your denominator of $x-2$ and simplify:
$$\boxed{\frac{x^2}{x-2}} = \frac{(x-2)^2 + 4(x-2) + 4}{x-2} = (x-2 ) + 4 + \frac{4}{x-2} = \boxed{x + \frac{4}{x-2} + 2}$$
as desired.
</s>