# Difference of two squares

In mathematics, the difference of two squares is a squared (multiplied by itself) number subtracted from another squared number. Every difference of squares may be factored according to the identity

$a^{2}-b^{2}=(a+b)(a-b)\,\!$

## Proof

The proof of the factorization identity is straightforward. Starting from the right-hand side, apply the distributive law to get

$(a+b)(a-b)=a^{2}+ba-ab-b^{2}\,\!$,

and set

$ba-ab=0\,\!$

as an application of the commutative law. The resulting identity is one of the most commonly used in mathematics. Among many uses, it gives a simple proof of the AM–GM inequality in two variables.

The proof just given indicates the scope of the identity in abstract algebra: it will hold in any commutative ring R.

Conversely, if this identity holds in a ring R for all pairs of elements a and b of the ring, then R is commutative. To see this, apply the distributive law to the right-hand side of the original equation and get

$a^{2}+ba-ab-b^{2}\,\!$

and for this to be equal to $a^{2}-b^{2}$, we must have

$ba-ab=0\,\!$

for all pairs a, b of elements of R, so the ring R is commutative.

## Geometrical demonstrations

The difference of two squares can also be illustrated geometrically as the difference of two square areas in a plane. In the diagram, the shaded part represents the difference between the areas of the two squares, i.e. $a^{2}-b^{2}$. The area of the shaded part can be found by adding the areas of the two rectangles; $a(a-b)+b(a-b)$, which can be factorized to $(a+b)(a-b)$. Therefore $a^{2}-b^{2}=(a+b)(a-b)$

Another geometric proof proceeds as follows: We start with the figure shown in the first diagram below, a large square with a smaller square removed from it. The side of the entire square is a, and the side of the small removed square is b. The area of the shaded region is $a^{2}-b^{2}$. A cut is made, splitting the region into two rectangular pieces, as shown in the second diagram. The larger piece, at the top, has width a and height a-b. The smaller piece, at the bottom, has width a-b and height b. Now the smaller piece can be detached, rotated, and placed to the right of the larger piece. In this new arrangement, shown in the last diagram below, the two pieces together form a rectangle, whose width is $a+b$ and whose height is $a-b$. This rectangle's area is $(a+b)(a-b)$. Since this rectangle came from rearranging the original figure, it must have the same area as the original figure. Therefore, $a^{2}-b^{2}=(a+b)(a-b)$.

## Uses

### Factorisation of polynomials

The formula for the difference of two squares can be used for factoring polynomials that contain the square of a first quantity minus the square of a second quantity. For example, the polynomial $x^{4}-1$ can be factored as follows:

$x^{4}-1=(x^{2}+1)(x^{2}-1)=(x^{2}+1)(x+1)(x-1)$

As a second example, the first two terms of $x^{2}-y^{2}+x-y$ can be factored as $(x+y)(x-y)$, so we have:

$x^{2}-y^{2}+x-y=(x+y)(x-y)+x-y=(x-y)(x+y+1)$

### Complex number case: sum of two squares

The difference of two squares is used to find the linear factors of the sum of two squares, using complex number coefficients.

For example, the root of $z^{2}+5\,\!$ can be found using difference of two squares:

$z^{2}+5\,\!$
$=z^{2}-i^{2}\cdot 5$
$=z^{2}-(i{\sqrt 5})^{2}$
$=(z+i{\sqrt 5})(z-i{\sqrt 5})$

Therefore the linear factors are $(z+i{\sqrt 5})$ and $(z-i{\sqrt 5})$.

Since the two factors found by this method are Complex conjugates, we can use this in reverse as a method of multiplying a complex number to get a real number. This is used to get real denominators in complex fractions.[1]

### Rationalising denominators

The difference of two squares can also be used in the rationalising of irrational denominators.[2] This is a method for removing surds from expressions (or at least moving them), applying to division by some combinations involving square roots.

For example: The denominator of ${\dfrac {5}{{\sqrt {3}}+4}}\,\!$ can be rationalised as follows:

${\dfrac {5}{{\sqrt {3}}+4}}\,\!$
$={\dfrac {5}{{\sqrt {3}}+4}}\times {\dfrac {{\sqrt {3}}-4}{{\sqrt {3}}-4}}\,\!$
$={\dfrac {5({\sqrt {3}}-4)}{({\sqrt {3}}+4)({\sqrt {3}}-4)}}\,\!$
$={\dfrac {5({\sqrt {3}}-4)}{{\sqrt {3}}^{2}-4^{2}}}\,\!$
$={\dfrac {5({\sqrt {3}}-4)}{3-16}}\,\!$
$=-{\dfrac {5({\sqrt {3}}-4)}{13}}.\,\!$

Here, the irrational denominator ${\sqrt {3}}+4\,\!$ has been rationalised to $13\,\!$.

### Mental arithmetic

The difference of two squares can also be used as an arithmetical short cut. If you are multiplying two numbers whose average is a number which is easily squared the difference of two squares can be used to give you the product of the original two numbers.

For example: $27\times 33=(30-3)(30+3)$

Which means using the difference of two squares $27\times 33$ can be restated as

$a^{2}-b^{2}$ which is $30^{2}-3^{2}=891$.

### Difference of two perfect squares

The difference of two consecutive perfect squares is the sum of the two bases n and n+1. This can be seen as follows:

${\begin{array}{lcl}(n+1)^{2}-n^{2}&=&((n+1)+n)((n+1)-n)\\&=&2n+1\end{array}}$

Therefore the difference of two consecutive perfect squares is an odd number. Similarly, the difference of two arbitrary perfect squares is calculated as follows:

${\begin{array}{lcl}(n+k)^{2}-n^{2}&=&((n+k)+n)((n+k)-n)\\&=&k(2n+k)\end{array}}$

Therefore the difference of two even perfect squares is a multiple of 4 and the difference of two odd perfect squares is a multiple of 8.

## Generalizations

Vectors a (purple), b (cyan) and a + b (blue) are shown with arrows

The identity also holds in inner product spaces over the field of real numbers, such as for dot product of Euclidean vectors:

${{\mathbf a}}\cdot {{\mathbf a}}-{{\mathbf b}}\cdot {{\mathbf b}}=({{\mathbf a}}+{{\mathbf b}})\cdot ({{\mathbf a}}-{{\mathbf b}})\,\!$

The proof is identical. By the way, assuming that a and b have equal norms (which means that their dot squares are equal), it demonstrates analytically the fact that two diagonals of a rhombus are perpendicular.