# 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? Oct 7, 2016 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. Oct 7, 2016 at 20:28
• Even with A odd, B even, C odd, in a triple, it may not be primitive as in $(27,36,45), (75,100,125), (147,196,245), (243,324,405)$ with $GCDs$ of $3^2, 5^2, 7^2, 9^2$, respectively. Jun 2, 2019 at 12:48

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.

I thought I had a proof that, if $$m,n$$ are mutually prime, $$m,n$$ would generate only primitive Pythagorean triples. The $$proof$$ is between the asterisk below. $$\text{*************************}$$

$$\text{We are given }\quad A=m^2n^2\quad B=2mn\quad C=m^2+n^2$$

Let $$x$$ be the GCD of $$m,n$$ and let $$p$$ and $$q$$ be the cofactors of $$m$$ and $$n$$ respectively. Then we have

$$A=(xp)^2-(xq)^2\quad B=2xpxq\quad C=(xp)^2+(xq)^2$$ $$A=x^2(p^2-q^2)\quad B=2x^2(pq)\quad C=x^2(p^2+q^2)$$

If $$GCD(m,n)=1$$, then $$GCD(A,B,C)=1$$ and $$(A,B,C)$$ is a primitive triple. This means that $$m$$ and $$n$$ must be co-prime to generate a primitive.

$$\text{*************************}$$

However, a counter-example destroys to so-called proof: $$\quad\text{Let }m,n=7,3$$. $$A=49-9=40\quad B=2*7*3=42\quad C=49+9=58\quad GCD(40,42,58)=2$$ $$\therefore GCD(m,n)=1\neg\implies GCD(A,B,C)=1$$ The only two formulas I know about that will generate only primitive triplets do not generate all of them but $$C-B=1$$ in the first one and $$C-A=2$$ in the second one.

$$A=2n^2+1\quad B=2n^2+2n\quad C=2n^2+2n+1$$ $$A=4n^2-1\quad B=4n\quad C=4n^2+1$$

• I don't understand why there's an argument. You give various formulas which are the well-known formula of Pythagoras. $$x^2+y^2=z^2$$ $$x=2ps$$ $$y=p^2-s^2$$ $$z=p^2+s^2$$ Your whole game... this is a substitution of numbers of another form. Like this. $$p=2n-1+k$$ $$s=k$$ It's not worth the time. Another formula describing all the solutions - can not be obtained... Jun 2, 2019 at 12:59