Pythagorean triples

Bill Casselman, UBC Mathematics Department

In a right triangle with sides a and b and hypotenuse c we have

a^{2} + b^{2} = c^{2} .

If a, b, and c are all positive integers, this is called a Pythagorean triple. The best known example is 3, 4, 5 since

9 + 16 = 25

and another well known one is 5, 12, 13.

One of the very earliest mathematical documents we know of is concerned with Pythagorean triples—it is a table from Babylon dated to roughly 1800 B.C. In order to understand even this early work, we need to be able to answer this question:

• How can we construct all possible Pythagorean triples?

If (a, b, c) is a Pythagorean triple then so is (ma, mb, mc) for any positive integer m. A Pythagorean triple is called primitive if it is not a scalar multiple of another triple. Thus (a, b, c) is primitive if there exists no divisor of all three coordinates other than 1.

• A Pythagorean triple is primitive if and only if each pair of coordinates is relatively prime.

Since if a prime number divides, say, a and b it will also divide c^{2}. All triples can be generated from the primitive ones, so the question we are really interested in answering is

• How can we construct all possible primitive Pythagorean triples?

If (a, b, c) is a Pythagorean triple, then

(\frac{a}{c})^{2} + (\frac{b}{c})^{2} = 1 .

If the triple is primitive then each fraction a/c and b/c will be irreducible. Therefore the primitive Pythagorean triples correspond to a subset of the points (x, y) on the unit circle x^{2}+y^{2} = 1 whose coordinates are rational numbers, and also lying in the positive quadrant. Conversely, suppose that (a/c, b/d) is such a point, with (a, c) and (b, d) relatively prime. Then

(\frac{a}{c})^{2} + (\frac{b}{d})^{2} = 1 .

If we multiply by d^{2} we get

(\frac{a}{c})^{2} d^{2} = (\frac{ad}{c})^{2} = d^{2} − b^{2}

which implies that c^{2}|a^{2}d^{2}. Since a and c are relatively prime, this implies that c|d. Similarly d|c, and hence c = d, so that every rational point (x, y) gives rise to a Pythagorean triple. The only ambiguity involved is that the points (x, y) and (y, x) will give rise to essentially the same triple. Therefore the question now becomes:

• How can we construct all possible points (x, y) with x > 0 and y > 0 rational numbers?

The trick we use is this: any line through the point (1, 0), other than the vertical one, will intercept the unit circle in exactly one other point.

If m is the slope of this line then its equation is

\frac{y}{x − 1} = m, y = mx − m

and to find the intersection point (x, y) we must solve

\begin{aligned}y & = mx − m \\ x^{2} + y^{2} & = 1 \end{aligned}

which gives

(m^{2} + 1)x^{2} − 2m^{2}x + (m^{2} − 1) = 0 .

Of course x = 1 is a root of this, and we have a factorization

(m^{2} + 1)x^{2} − 2m^{2}x + (m^{2} − 1) = (x − 1)((m^{2} + 1)x − (m^{2} − 1)) .

This gives for the pair (x, y)

x = \frac{m^{2} − 1}{m^{2} + 1}, y = \frac{−2m}{m^{2} + 1} .

The point (x, y) will be in the positive quadrant when m < −1. If we set m = −p/q with p and q relatively prime positive integers and p > q then we get

x = \frac{p^{2} − q^{2}}{p^{2} + q^{2}} , y = \frac{2pq}{p^{2} + q^{2}} .

This suggests the formulas

\begin{aligned}a & = p^{2} − q^{2} \\ b & = 2pq \\ c & = p^{2} + q^{2} \end{aligned}

for a Pythagorean triple. When is it primitive? If p and q are both odd, then a, b, c will all be even, so the triple will not be primitive. But:

• If (a) p and q are relatively prime; (b) p > q; (c) one of p and q is odd and the other even, then (a, b, c) make up a primitive Pythagorean triple.

In these circumstances, the pair (p, q) will be called proper. It is straightforward to verify that if (p, q) is proper then (a, b, c) is primitive.

In fact:

• We get all primitive Pythagorean triples, up to a permutation of a and b, in this fashion.

If (x, y) corresponds to the line with slope −m, then (y, x) corresponds to that with slope −(m − 1)/(m + 1). We know at least that an arbitrary triple will arise from some rational slope p/q. If p and q are both odd then we obtain the triple (b, a, c) from the slope

−\frac{(p/q) − 1}{(p/q) + 1} = −\frac{p − q}{p + q} = −\frac{(p − q)/2}{(p + q)/2}

• If p > q are relatively prime and both are odd, then the pair (p − q)/2, (p + q)/2 is proper.

Explicitly, if we are given a primitive triple (a, b, c) with a odd and b even, then we can calculate

\begin{aligned}p & = \sqrt{\frac{a + c}{2}} \\ q & = \frac{b}{2p} . \end{aligned}

The construction of Pythagorean triples triples described here was known to Euclid (Lemma 1 to Book X, Proposition 29) and used frequently by Diophantus. That the parametrization is complete was perhaps first asserted by Leonardo of Pisa.