Difference of two squares (source code)

= Difference of two squares
{wiki}

= Difference of squares
{synonym}

The <difference of two squares> identity is
$$
r^2-s^2=(r-s)(r+s).
$$
It follows by expanding the right side and cancelling its cross terms. It holds for <real numbers> and, more generally, in a <commutative ring>.

For <integers> $r,s$, the factors $u=r-s$ and $v=r+s$ have the same <parity>. Conversely, any <integer factorization> $n=uv$ with factors of the same <parity> yields $r=(u+v)/2$ and $s=(v-u)/2$. Thus an <integer> is a <difference of two squares> exactly when it is not congruent to two <modulo> four: odd values use $u=1,v=n$, and multiples of four use $u=2,v=n/2$. This is the factor-pair interpretation behind <Fermat's factorization method>.