# Cube of Sum and Difference

## Related Calculator: Polynomial Calculator

**Cube of sum and difference**:

`huge color(purple)((a+-b)^3=a^3+-3a^2b+3ab^2+-b^3)`

Let's see how to derive it.

Recall, that exponent is just repeating multiplication.

Thus, we can write that `(a+b)^3=(a+b)(a+b)^2`.

From square of sum/difference note, we know, that `(a+b)^2=a^2+2ab+b^2`.

Thus, `(a+b)^3=(a+b)(a^2+2ab+b^2)`.

Finally, just multiply polynomials: `(a+b)(a^2+2ab+b^2)=a*a^2+a*2ab+a*b^2+b*a^2+b*2ab+b*b^2=`

`=a^3+3a^2b+3ab^2+b^3`.

Similarly, it can be shown, that `(a-b)^3=a^3-3a^2b+3ab^2-b^3`.

Or, more shortly: `(a+-b)^3=a^3+-3a^2b+3ab^2+-b^2`.

**Example 1**. Multiply `(2x+y)^3`.

Here `a=2x` and `b=y`.

Just use above formula: `(2x+y)^3=(2x)^3+3*(2x)^2*(y)+3*(2x)*(y)^2+(y)^3=8x^3+12x^2y+6xy^2+y^3`.

Let's see how to handle minus sign.

**Example 2**. Multiply `(3/4ab-2cd)^3`.

Here `a=3/4ab` and `b=2cd`.

Now, use formula for difference: `(3/4ab-2cd)^3=(3/4ab)^3-3*(3/4ab)^2*(2cd)+3*(3/4ab)*(2cd)^2-(2cd)^3=`

`=27/64a^3b^3-27/8a^2b^2cd+9abc^2d^2-8c^3d^3`.

Finally, let's do a slightly harder example.

**Example 3**. Multiply the following: `(-xyz-2x^2)^3`.

Till now, we didn't see two minus signs, but this case can be handled easily.

There are two options:

- `a=-xyz` and `b=-2x^2`; apply sum formula.
- `a=-xyz` and `b=2x^2`; apply difference formula.

I choose second option: `(-xyz-2x^2)^3=(-xyz)^3-3*(-xyz)^2*(2x^2)+3*(-xyz)*(2x^2)^2-(2x^2)^3=`

`=-x^3y^3z^3-6x^4y^2z^2-12x^5yz-8x^6`.

From last example we see, that `color(purple)((-a-b)^3=-(a+b)^3)`.

Now, it is time to exercise.

**Exercise 1**. Multiply `(4z+3y)^3`.

**Answer**: `64z^3+144z^2y+108zy^2+27y^3`.

**Exercise 2**. Multiply `(-1/3x^3y^2+2x)^3`.

**Answer**: `-1/27x^9y^6+2/3x^7y^4-4x^5y^2+8x^3`.

Hint: either swap summands (`(-1/3x^3y^2+2x)^3=(2x-1/3x^3y^2)^3`: commutative property of addition) or proceed as always.

**Exercise 3**. Multiply the following: `(-2x-1)^3`.

**Answer**: `-8x^3-12x^2-6x-1`.