<s>[INST] How to solve certain types of integrals I'm asking for a walk through of integrals in the form:
$$\int \frac{a(x)}{b(x)}\,dx$$ 
where both $a(x)$ and $b(x)$ are polynomials in their lowest terms. For instance $$\int \frac{x^3+2x}{x^2+1}\,dx$$
Is there a trick to doing these? or will I have to integrate by a clever substitution?
 [/INST] The first step is generally to divide out the integrand so as to get a polynomial plus a rational function whose numerator has lower degree than its denominator. Here you get
$$\frac{x^3+2x}{1+x^2}=x+\frac{x}{x^2+1}\;.$$
Integrating the $x$ term (and, more generally, the polynomial quotient) is easy, so we’ve reduced the problem to integrating something of the form $\frac{p(x)}{q(x)}$, where $p(x)$ and $q(x)$ are polynomials, and the degree of $p(x)$ is less than the degree of $q(x)$. The general solution for such problems is partial fractions; here, however, we’re more fortunate, because the numerator $x$ is a constant multiple of the derivative of the denominator. If you substitute $u=x^2+1$, you find that $du=2x\,dx$, so that $x\,dx=\frac12du$, and
$$\int\frac{x}{x^2+1}\,dx=\frac12\int\frac{du}u\;,$$
which is a standard, basic integral. I would not call this a clever substitution: recognizing that the numerator of a fraction is a constant multiple of the derivative of the denominator is a standard technique.
Suppose that the original numerator had been $x^3+x+2$. Again we do the division to get a polynomial plus a ‘proper’ rational function:
$$\frac{x^3+x+2}{x^2+1}=x+\frac2{x^2+1}\;.$$
This time you should recognize that $\frac2{x^2+1}$ is just twice the derivative of $\tan^{-1}x$, again a standard integration.
Finally, suppose that the original fraction had been
$$\frac{x^3+x+1}{x^2+2x}=x+\frac{1-x}{x^2+2x}\;.$$
This time you might as well simply reduce the remaining fraction to partial fractions:
$$\frac{1-x}{x(x+2)}=\frac{A}x+\frac{B}{x+2}\;,$$
so $A(x+2)+Bx=1-x$, $(A+B)x+2A=1-x$, $A+B=-1$, and $2A=1$, so $A=\frac12$, and $B=-\frac32$. Thus,
$$\frac{1-x}{x^2+2x}=\frac12\left(\frac1x-\frac3{x+2}\right)\;,$$
leaving you with two easy integrations.
</s>