Solutions of Pythagorean Equation

Primitive Solutions of Pythagorean Equation
The set of all primitive Pythagorean triples is generated by:
 * $$\left({2 m n, m^2 - n^2, m^2 + n^2}\right)$$

where:
 * $$m, n \in \Z$$ are positive integers;
 * $$m \perp n$$, i.e. $$m$$ and $$n$$ are coprime;
 * $$m$$ and $$n$$ are of opposite parity;
 * $$m > n$$.

General Solutions of Pythagorean Equation
Let $$x, y, z$$ be a solution to the Pythagorean equation.

Then $$x = k x', y = k y', z = k z'$$, where:
 * $$\left({x', y', z'}\right)$$ is a primitive Pythagorean triple;
 * $$k \in \Z: k \ge 1$$.

Primitive Solutions

 * First we show that $$\left({2 m n, m^2 - n^2, m^2 + n^2}\right)$$ is a Pythagorean triple:

$$ $$ $$

So $$\left({2 m n, m^2 - n^2, m^2 + n^2}\right)$$ is indeed a Pythagorean triple.


 * Now we establish that $$\left({2 m n, m^2 - n^2, m^2 + n^2}\right)$$ is primitive:

Suppose to the contrary, that $$\left({2 m n, m^2 - n^2, m^2 + n^2}\right)$$ is not primitive.

So there is a prime divisor $$p$$ of both $$2 m n$$ and $$m^2 - n^2$$.

That is, that $$p \in \mathbb{P}: p \backslash \left({2 m n}\right), p \backslash \left({m^2 - n^2}\right)$$.

Then from Prime Divides Power, $$p \backslash \left({2 m n}\right)^2$$ and $$p \backslash \left({m^2 - n^2}\right)^2$$.

Hence $$p \backslash \left({m^2 + n^2}\right)^2$$ from Common Divisor Divides Integer Combination, and from Prime Divides Power again, $$p \backslash \left({m^2 + n^2}\right)$$.

So:
 * $$p \backslash \left({m^2 + n^2}\right) + \left({m^2 - n^2}\right) = 2 m^2$$ from Common Divisor Divides Integer Combination;
 * $$p \backslash \left({m^2 + n^2}\right) - \left({m^2 - n^2}\right) = 2 n^2$$ from Common Divisor Divides Integer Combination.

But $$p \ne 2$$ as, because $$m$$ and $$n$$ are of opposite parity, $$m^2 - n^2$$ must be odd.

So $$p \backslash n^2$$ and $$p \backslash m^2$$ and so from Prime Divides Power, $$p \backslash n$$ and $$p \backslash m$$.

But as we specified that $$m \perp n$$, this is a contradiction.

Therefore $$\left({2 m n, m^2 - n^2, m^2 + n^2}\right)$$ is primitive.


 * Now we need to show that every primitive Pythagorean triple is of this form:

So, suppose that $$\left({x, y, z}\right)$$ is any primitive Pythagorean triple given in canonical form.

That is, $$x$$ is even and $$y$$ and $$z$$ are both odd.

As $$y$$ and $$z$$ are both odd, their sum and difference are both even.

Hence we can define $$s, t \in Z: s = \frac {z + y} 2, t = \frac {z - y} 2$$.

Note that $$s \perp t$$ as any common divisor would also divide $$s + t = z$$ and $$s - t = y$$, and we know that $$z \perp y$$ from All Elements of Primitive Pythagorean Triple are Coprime.

Then from the Pythagorean equation, we have:
 * $$x^2 = x^2 - y^2 = \left({x+y}\right) \left({x-y}\right) = 4 s t$$

Hence
 * $$\left({\frac x 2}\right)^2 = s t$$.

As $$x$$ is even, $$\frac x 2$$ is an integer and so $$s t$$ is a square.

So each of $$s$$ and $$t$$ must be square as they are coprime.

Now, we write $$s = m^2$$ and $$t = n^2$$ and substitute back:


 * $$x^2 = 4 s t = 4 m^2 n^2$$ and so $$x = 2 m n$$;
 * $$y = s - t = m^2 - n^2$$;
 * $$z = m^2 + n^2$$.

Finally, note that:
 * $$m \perp n$$ from $$s \perp t$$ and Prime Divides Power;
 * $$m$$ and $$n$$ have opposite parity otherwise $$y$$ and $$z$$ would be even.

Thus, our primitive Pythagorean triple is of the form $$\left({2 m n, m^2 - n^2, m^2 + n^2}\right)$$.

General Solutions
Let $$\left({x, y, z}\right)$$ be non-primitive solution to the Pythagorean equation.


 * Let $$\exists k \in \Z: k \ge 2, k \backslash x, k \backslash y$$ such that $$x \perp y$$.

Then we can express $$x$$ and $$y$$ as $$x = k x', y = k y'$$.

Thus $$z^2 = k^2 x'^2 + k^2 y'^2 = k^2 z'^2$$ for some $$z' \in \Z$$.


 * Let $$\exists k \in \Z: k \ge 2, k \backslash x, k \backslash z$$ such that $$x \perp z$$.

Then we can express $$x$$ and $$z$$ as $$x = k x', z = k z'$$.

Thus $$y^2 = k^2 z'^2 - k^2 x'^2 = k^2 y'^2$$ for some $$y' \in \Z$$.


 * Similarly for any common divisor of $$y$$ and $$z$$.

Thus any common divisor of any pair of $$x, y, z$$ has to be a common divisor of the other.

Hence any non-primitive solution to the Pythagorean equation is a constant multiple of some primitive solution.

Historical Note
This solution was known to Diophantus of Alexandria.