# Primitive Pythagorean triple generator

I was wondering how to prove the following fact about primitive Pythagorean triples:

Let $(z,u,w)$ be a primitive Pythagorean triple. Then there exist relatively prime positive integers $a,b$ of different parity such that $$z = a^2-b^2, \quad u = 2ab, \quad \text{and} \quad w = a^2+b^2.$$

I see how $z,u,w$ must form the sides of a triangle, where $c$ is the hypotenuse, but how do we show that $\gcd(z,u,w) = 1$ and that these generate all the triples?

It is easy to see that if $(z,u,w)$ is a primitive pythagorean triple, then $w$ is odd and either $z$ is odd and $u$ is even or $z$ is even and $u$ is odd. WLOG suppose that $u=2x$ is even, so $z$ is odd. Then

$$u^2=4x^2=w^2-z^2=(w+z)(w-z).$$

It is plain that $\gcd(w+z,w-z)=2$, so $y_1:=(w+z)/2$ and $y_2:=(w-z)/2$ are relatively prime positive integers. Thus

$$x^2=y_1y_2,$$

and therefore $y_1$ and $y_2$ are relatively prime divisors of $x^2$. This implies that $y_1$ and $y_2$ are perfect squares, so write $y_1=a^2$ and $y_2=b^2$. Hence,

$$u=2x=2ab,\quad z=y_1-y_2=a^2-b^2,\qquad\text{and}\qquad w=y_1+y_2=a^2+b^2.$$

This proves that every primitive triple has the form $(a^2-b^2,2ab,a^2+b^2)$, as wanted.

Of course, the condition $\gcd(a,b)=1$ is needed, otherwise $(a^2-b^2,2ab,a^2+b^2)$ won't be primitive.

• Why must $w$ be odd? – user19405892 Oct 7 '16 at 20:25
• Suppose the $w$ is even. Then $z$ and $u$ have the same parity. If both are even, then the triple is not primitive. If both are odd, then $w^2$ is multiple of $4$, but $z^2+u^2$ is not multiple of $4$ (it is $\equiv2\bmod 4$ since $x^2\equiv1\pmod4$ for any odd $x$), which is a contradiction. Therefore, $w$ must be odd. – user246336 Oct 7 '16 at 20:28

Even in the wikipedia article cited by @JeanMarie I could not find the following quick argument which gives all the Pyhagorean triples at one stroke: the Pythagorean equation being homogeneous, it is equivalent to the equation in rational variables $Z^2 + U^2 = 1$, or equivalently $N(Z + iU) = 1$, where $N$ denotes the norm map from $\mathbf Q(i)$ to $\mathbf Q$ , $i^2 = - 1$. The extension $\mathbf Q(i)/\mathbf Q$ being cyclic, with Galois group generated by the complex conjugation, Hilbert's theorem 90 applies, which shows that $N(Z + iU) = 1$ iff $Z + iU$ is of the form $A + iB /A - iB$. It follows from identification that $Z = A^2 - B^2 /A^2 + B^2$ and $U = 2AB / A^2 + B^2$. Clearing denominators immediately produces the usual Pythagorean integral triples $z = a^2 - b^2 , u = 2ab, w= a^2 + b^2$. Clearing common factors plainly gives the primitive triples.