How do we get $(b-a)^2/12$ from factorisation? I am in the final steps of calculating the variance of the uniform distribution for $(a,b)$. I'd like to see the steps involved in getting $$\frac{1}{12}(b-a)^2$$ from $$\frac{4(b^3-a^3)-3(b-a)(a+b)^2}{12(b-a)}$$ which is the result after integrating the variable $X^2$ between $b$ and $a$ and subtracting the mean squared. I'm struggling to perform the algebra so I would appreciate any assistance you could provide in showing the steps involved. Thanks!
 A: $4(b^3-a^3)-3(b-a)(b+a)^2=4b^3-4a^3-3(b^2-a^2)(b+a)$ 
[using $(b-a)(b+a)=b^2-a^2$]
$=4b^3-4a^3-3b^3-3b^2a+3a^2b+3a^3$
$=b^3-3b^2a+3ba^2-a^3$
$=(b-a)^3\quad(*)$.
Dividing by $12(b-a)$ gives $\frac{1}{12}(b-a)^2$
So how did we do $(*)$? Well I did it because I recognize a few well-known factorisations like:
$(a+b)^2=a^2+2ab+b^2$
$(a+b)^3=a^3+3a^2b+3ab^2+b^3$
and the second of those gives you what you need if you replace $a$ by $-a$.
Suppose you don't recognize the factorisation immediately. The first thing to notice is whether every term has the same degree. It does here. So you can think of the expression as $a^3(x^3-3x^2+3x-1)$ where $x=b/a$. You may remember that checking a polynomial with integer coefficients for integer roots is easy: you just check the factors of the constant term. So the only possible integer roots of $x^3-3x^2+3x-1$ are $\pm1$. You quickly find that 1 is a root which means that $(x-1)$ is a factor. Find the other factor as $(x^2-2x+1)$. You can either factor that on sight or repeat the process to find that the polynomial is $(x-1)^3$ and hence the original is $(b-a)^3$.
A: Here is another method that doesn't include lengthy algebraic calculations.
$$Var(X) =E[(X-\mu)^2]$$
$$ = \int_a^b\frac{\left(x-\frac{a+b}{2}\right)^2}{b-a}\mathrm dx$$
Now apply substitution $t=x-\dfrac{b+a}{2}$. Let $k=b-a$. Then
$$Var(X) = \int_{-\frac{k}{2}}^\frac{k}{2}\frac{t^2}{k}\mathrm dt$$
$$=\frac{2}{k}\int_0^\frac{k}{2}t^2\mathrm dt$$
$$=\frac{2}{k}\times\frac{1}{3}\times\left(\frac{k}{2}\right)^3$$
$$=\frac{(b-a)^2}{12}$$
A: Alternatively:
$$Var(X)=E(X^2)-E(X)^2=\int_a^bx^2f(x)dx-\left[\int_a^bxf(x)dx\right]^2=\\
\int_a^b \frac{x^2}{b-a}dx-\left[\int_a^b\frac{x}{b-a}dx\right]^2=\frac{x^3}{3(b-a)}|_a^b-\left[\frac{x^2}{2(b-a)}|_a^b\right]^2=\\
\frac{(b-a)(b^2+ba+a^2)}{3(b-a)}-\left[\frac{(b-a)(b+a)}{2(b-a)}\right]^2=\\
\frac{4(b^2+ba+a^2)-3(b^2+2ab+a^2)}{12}=\frac{(b-a)^2}{12}.$$
