<s>[INST] How to integrate when the degree of the numerator is higher than the denominator? I need to solve
$$\int\frac{x^5+4}{x^3+x^2}\,dx$$
I first tried to do a division, which gave me
$$\int\bigg[\frac{x^3}{x+1}+\frac{4}{x^2(x+1)}\bigg]\,dx$$
However, looking at the book, the integral is supposed to be transformed to
$$\int\bigg[x^2-x+1-\frac{4}{x}+\frac{4}{x^2}+\frac{3}{x+1}\bigg]\,dx$$
How am I suppose to end up with this integral ?
 [/INST] You can also do this using series expansions. If you have a rational function $R(x) = \frac{p(x)}{q(x)}$ then you can consider the expansion around each zero of the denominator $q(x)$. If you keep only the singular terms and subtract all of those from $R(x)$ for each singularity, then you are left with a rational function that doesn't have any singularities left, which must therefore be a polynomial. That polynomial can, of course, be found using long division, but also by expanding around x = infinity (which is more efficient, this is equivalent to synthetic division).
The advantage of this method is that you are computing each term directly, so errors made in computing one term don't get propagated to other terms.
In this case, the expansion around x = 0 yields:
$$R(x) = (x^5+4)\frac{1}{x^2}\frac{1}{1+x} = (x^5+4)\frac{1}{x^2}(1-x +\mathcal{O}(x^2)) = \frac{4}{x^2} - \frac{4}{x}+\mathcal{O}(1)$$
The expansion around x = -1 yields
$$R(x) = (x^5+4)\frac{1}{x^2}\frac{1}{1+x} = \frac{3}{x+1} + \mathcal{O}(1)$$
The sum of all the singular terms of the expansions around all the singularities is thus:
$$S(x) =  \frac{4}{x^2} - \frac{4}{x} + \frac{3}{x+1}$$
For large $x$ we can expand as follows:
$$R(x) = \frac{x^5+4}{x^3}\frac{1}{1+x^{-1}} = x^2 (1-\frac{1}{x} + \frac{1}{x^2})+\mathcal{O}(x^{-1}) = x^2 - x + 1+\mathcal{O}(x^{-1})$$
The expansion of $S(x)$ for large $x$ only contains negative powers of $x$, so we also have:
$$R(x) - S(x)= x^2 - x + 1+\mathcal{O}(x^{-1})$$
But we know that $R(x) - S(x)$ is a polynomial, therefore:
$$R(x) - S(x)= x^2 - x + 1$$
The partial fraction expansion is thus given by:
$$R(x) = x^2 - x + 1 +  \frac{4}{x^2} - \frac{4}{x} + \frac{3}{x+1}$$
</s>