Can every perfect square exist as the sum or difference of two perfect squares?

I believe this is trivial and I'm over-complicating it. But can every squared integer be expressed as the sum of two squared integers OR the difference of two squared integers? And is there a proof for it?

Algebraically, assuming integers $x, y, z ≥ 0:$

\begin{align}z^2 &= x^2 + y^2 \\ z^2 &= x^2 - y^2\end{align}

In other words, can every positive integer, regardless of the other two variables, be expressed as a part of a Pythagorean triple $(a,b,c)$?

I ask this because I cannot seem to find any explicit answers for it. I understand that the set of all sums of two squared integers is closed under multiplication by the Fibonacci identity, but I'm not sure how it applies in this situation. Also, I'm not sure if a proof of the Pythagorean theorem would be able to answer this question, but I need some clarification.

• If $z=1$ I think you'll have a problem assuming $x, y>0$. – TravisJ Apr 12 '15 at 1:07
• Ah, right, I shall edit that – CuriousMathematics Apr 12 '15 at 1:07
• Let $y=0$ and $x=z$. – George V. Williams Apr 12 '15 at 1:14

Every square can be written as the difference of two squares.

$(x+1)^2-x^2=2x+1$

This shows that any odd number, in particular an odd square, is the difference of two squares.

$(x+1)^2-(x-1)^2=4x$.

Any multiple of 4 is the difference of squares. An even square will be divisible by 4, so even squares are also the difference of two squares.

Every square number is expressible as the difference of two squares. First, note that every odd number $2n+1$ can be written as $(n+1)^2 - n^2$. Next, you can write every even square as $4n^2 = (n^2+1)^2 - (n^2-1)^2$. Note that if you specify that it has to be a difference of two nonzero squares, then $1$ and $4$ do not count.

In general, the only integers that cannot be written as differences of squares are the numbers congruent to $2$ modulo $4$. This can be obtained by solving for $x-y = n_1, x+y = n_2$, whenever you have a factorization $n = n_1n_2$ into terms of the same parity. (Again, if you specify difference of nonzero squares, $1$ and $4$ do not count.)

First of all an integer $n$ can be expressed as the difference of two squres if and only if it's odd or divisible by $4$ and here are the expression: $$n=2k+1=(k+1)^2-k^2\ \ \ n=4k=(k+1)^2-(k-1)^2$$

And because $n^2$ is either odd or divisible by $4$ we can conclude that:

Every square is the difference of two squares

I'm going to be more general, and cover all integers that can be expressed as a sum or difference of squares.

Suppose $n$ is an integer with factors $k$ and $m$, one of which could be $1$. Then if $$n = a^2-b^2 = (a+b)(a-b),$$ you need to solve the equations $$a+b = k \\ a-b = m,$$ so $a=(k+m)/2$, $b=(k-m)/2$. Therefore you can express a number as the difference of two squares if, and only if, you can find a factorisation into two factors whose sum and difference is even. This can only occur if the factors are both odd, or both even.

Since 1 is an odd number, if $n$ is odd we can use $n=n \times 1$, so all odd numbers are so expressible. Hence, looking modulo 4, the residue classes $n \equiv 1,3 \pmod{4}$ are covered. $n \equiv 0 \pmod{4}$ is also obvious since $n = 2 \times 2 (n/4)$. However, if $n=4k+2=2(2k+1)$, this cannot work.

Now, what about a sum of two squares? Working modulo $8$, the squares are $$0^2 \equiv 0, 1^2 \equiv 1, 2^2 \equiv 4,3^3 \equiv 1,4^2 \equiv 0,5^2 \equiv 1,6^2 \equiv 4,7^2 \equiv 1,$$ so all squares are $0,1$ or $4 \pmod{8}$. Hence anything that is $6,7 \pmod{8}$ cannot be a sum of two squares. (and anything that is $7 \pmod{8}$ is not even a sum of three squares. Four squares, on the other hand, are enough for anything sufficiently large - this is the solution to Waring's problem for squares)

In fact all Pythagorean triples are given by $((m^2+n^2),2mn,(m^2-n^2))$ for integer $m,n$.

Even more is true: a squared integer can be expressed as the difference of two squared integers in as many ways as there are factorisations of the squared integer into $$2$$ unequal factors of the same parity. The case $$n=2$$ in Fermat's Last Theorem is indeed very special.

Example: \begin{aligned} 12\times 12 &= 2\times 72 = 37\times3 7 - 35\times 35\\ &= 4\times 36 = 20\times 20 - 16\times 16\\ &= 6\times 24 = 15\times 15 - 9\times 9\\ &= 8\times 18 = 13\times 13 - 5\times 5. \end{aligned}

For primes and even semi-primes ($$2\times$$odd prime), the expression is unique and consists of consecutive integers in the former case and of integers which differ by two in the latter (e.g. $$5\times5= 13\times13 - 12\times12$$ and $$10\times 10= 26\times 26 -24\times 24.$$

This also implies immediately that if $$x < y < z,\; y$$ cannot be a prime.