Factoring $a^3-b^3$ I recently got interested in mathematics after having slacked through it in highschool. Therefore I picked up the book "Algebra" by I.M. Gelfand and A.Shen
At problem 113, the reader is asked to factor $a^3-b^3.$
The given solution is: 
$$a^3-b^3 = a^3 - a^2b + a^2b -ab^2 + ab^2 -b^3 = a^2(a-b) + ab(a-b) + b^2(a-b) = (a-b)(a^2+ab+b^2)$$
I was wondering how the second equality is derived. From what is it derived, from $a^2-b^2$? I know that the result is the difference of cubes formula, however searching for it on the internet i only get exercises where the formula is already given. Can someone please point me in the right direction?
 A: The second equality is the typical trick of adding/subtracting things until you get something you want. It is usually not terribly insightful but is nonetheless standard. In general, one can factor $a^n-b^n$ as
$$ a^n-b^n = (a-b)(a^{n-1} + a^{n-2}b^1 + a^{n-3}b^2 + \cdots + a^2 b^{n-3} + a b^{n-2} + b^{n-1}).$$
One way of seeing this more general result is as follows: Consider the polynomial equation $x^3-b^3$ (where I have just used $x$ instead of $a$!). Clearly $x=b$ is a root of this equation, so we should be able to factor out an $(x-b)$ term from the polynomial. Polynomial long division then gives the desired result. This can be generalized to higher $n$.
A: Being able to quickly derive the factorization for a difference of cubes (and most other things) prevented me from having to memorize many things in school. I cannot help but share this with you as it was something I must have done a hundred times in a pinch. I will answer your question by delivering a proper full derivation of the standard factorization for a difference of cubes. Close inspection of the result will answer your question I am sure. Begin by expanding $(a-b)^3$ in any manner you choose.
$$(a-b)^3 = a^3-3a^2b+3ab^2-b^3.$$
We will now solve this equality for $a^3-b^3$ and manipulate the other side of the equality into the standard formula.
\begin{align*}
             (a-b)^3 &= a^3-3a^2b+3ab^2-b^3 \\
\Rightarrow  a^3-b^3 &=(a-b)^3+3a^2b-3ab^2 \\
                     &=(a-b)^3+3ab(a-b) \\
                     &=(a-b)\left((a-b)^2+3ab\right) \\
                     &=(a-b)(a^2-2ab+b^2+3ab) \\
                     &=(a-b)(a^2+ab+b^2).
\end{align*}
This is one handy derivation. The sum of cubes can be derived in a similar manner.
A: The second equality is obtained by first grouping terms in the middle expression and then factoring the grouped terms:
$$\begin{align}
a^3-a^2b+a^2b-ab^2+ab^2-b^3&=(a^3-a^2b)+(a^2b-ab^2)+(ab^2-b^3)\cr
&=a^2(a-b)+ab(a-b)+b^2(a-b)\cr
\end{align}$$
If the OP is wondering where the middle expression came from in the first place, it's kind of a deus ex machina:  All you're doing is sticking two $0$'s between $a^3$ and $-b^3$ (the expressions $-a^2b+a^2b$ and $-ab^2+ab^2$ are both obviously equal to $0$), but when you do, lo and behold, the regrouping and factoring work their magic.  
A: I am not sure I get your question. The last formula is just obtained factoring a and b. For example, the first part
$a^2(a-b) = a^3 -a^2b$
So once you get the last formula you can take $(a-b)$ and obtain
$(a-b)(a^2+ab+b^2)$
and to obtain the second formula you simply add and subtract the same quantities, in particular $-a^2b+a^2b$ and $ab^2-ab^2$.
Does this answer your question?
