### Theory:

We will now extend this idea of expanding algebraic terms/numbers with cubic order using the identities.
Let us derive the cubic identities with the help of known square identities.
1. We will now prove $$(a+b)^3$$$$=$$ $$a^3+3a^2b+3ab^2+b^3$$ by direct multiplication.

Consider the LHS $$(a+b)^3$$.

Here $$(a+b)$$ raised to the power $$3$$.  It means we need to multiply $$(a+b)$$ by itself two times.

That is $$(a+b)\times(a+b)\times(a+b)$$ $$=$$ $$(a+b)^3$$

$$(a+b)^3$$ $$=$$ $$[(a+b)\times(a+b)]$$$$\times(a+b)$$

$$=$$ $$(a+b)^2\times(a+b)$$

$$=$$ $$(a^2+b^2+2ab)$$$$\times(a+b)$$

Apply the distributive property.

$$=$$ $$(a^2\times a)$$ $$+$$ $$(b^2\times a)$$ $$+$$ $$(2ab\times a)$$ $$+$$ $$(a^2\times b)$$ $$+$$ $$(b^2\times b)$$ $$+$$ $$(2ab\times b)$$

$$=$$ $$a^3+ab^2+2a^2b+a^2b+b^3+2ab^2$$

$$=$$ $$a^3+3a^2b+3ab^2+b^3$$

$$=$$ RHS

Thus, the identity is $$(a+b)^3$$ $$=$$ $$a^3+3a^2b+3ab^2+b^3$$.

Take the factor $$3ab$$ from the middle two terms of RHS we get:

$$(a+b)^3$$ $$=$$ $$a^3+b^3+3ab(a+b)$$

2. We will now prove $$(a-b)^3$$ $$=$$ $$a^3-3a^2b+3ab^2-b^3$$ by replacing $$b$$ by $$-b$$ in the above identity.

Consider the identity $$(a+b)^3$$ $$=$$ $$a^3+3a^2b+3ab^2+b^3$$.

Replace $$b$$ by $$-b$$ in the above equation.

$$(a-b)^3$$ $$=$$ $$a^3+3a^2(-b)+3a(-b)^2+(-b)^3$$

$$=$$ $$a^3-3a^2b+3ab^2-b^3$$

Thus, the identity is $$(a-b)^3$$ $$=$$ $$a^3-3a^2b+3ab^2-b^3$$

Take the factor $$-3ab$$ from the middle two terms of RHS we get:

$$(a-b)^3$$ $$=$$ $$a^3+b^3-3ab(a-b)$$

Let us summarize the identities...

Identity VI: $$(a+b)^3$$ $$=$$ $$a^3+3a^2b+3ab^2+b^3$$ or $$(a+b)^3$$ $$=$$ $$a^3+b^3+3ab(a+b)$$

Identity VII: $$(a-b)^3$$ $$=$$ $$a^3-3a^2b+3ab^2-b^3$$ or $$(a-b)^3$$ $$=$$ $$a^3-b^3-3ab(a-b)$$

Important!
The formula for three different values:

The general form of the above two identities is given by the following identity expression:

$$(x+a)(x+b)(x+c)$$ $$=$$ $$x^3$$$$+(a+b+c)x^2$$$$+(ab+bc+ca)x+abc$$.

Consider the LHS, $$(x+a)(x+b)(x+c)$$.

Apply the distributive property for the first two terms.

$$[(x+a)(x+b)](x+c)$$ $$=$$ $$[(x\times x)]$$$$+(x\times b)$$$$+(a\times x)$$$$+(a\times b)]$$$$(x+c)$$

$$=$$ $$(x^2+bx+ax+ab)$$$$(x+c)$$

Again apply distributive law.

$$(x^2+bx+ax+ab)(x+c)$$

$$=$$ $$(x^2\times x)$$$$+(bx\times x)$$$$+(ax\times x)$$$$+(ab\times x)$$$$+(x^2\times c)$$$$+(bx\times c)$$$$+(ax\times c)$$$$+(ab\times c)$$.

$$=$$ $$x^3+bx^2$$$$+ax^2+abx$$$$+cx^2+bcx$$$$+acx+abc$$

Separate the cubic, square, variables and constants terms.

$$=$$ $$x^3+ax^2$$$$+bx^2+cx^2$$$$+abx+bcx$$$$+acx+abc$$

$$=$$ $$x^3+(a+b+c)x^2+(ab+bc+ac)x+abc$$

$$=$$ RHS

Thus we have the identity $$(x+a)(x+b)(x+c)$$ $$=$$ $$x^3$$$$+(a+b+c)x^2$$$$+(ab+bc+ca)x+abc$$.