Generating Pythagorean Triples


Many people have written, noting that some Pythagorean triples will be missing from the table which consists of those of the form

(n2 - m2, 2mn, n2 + m2).

For instance the triple (15,20,25) is not of that form. There is a simple explanation, (15,20,25) is just a multiple of (3,4,5) -- indeed, each number in the former is 5 times the corresponding number in the latter. So, triples that are just multiples of some other triple need not be in the table. A triple that is a multiple of some other triple is called imprimitive, and those that aren't a multiple of another triple are known as primitive.

The quick answer, then, is to say that the table contains all primitive Pythagorean triples, and the others can be found by multiplying these by constants. But this answer is not quite right either. For example, (3,4,5) is found in the [2,1] position in the table because it can be written as (22-12, 2*2*1,22+12), on the other hand, (4,3,5) is also (obviously) a Pythagorean triple but it does not have the desired form. Nevertheless, it has been mathematically proved (in K. K. Kubota, "Pythagorean Triples in Unique Factorization Domains," The American Mathematical Monthly, Vol. 79, No. 5(May, 1972), pp. 503-505) that if we allow for the possible interchange of the two smaller elements of a triple, then every primitive triple is of the desired form -- that is, it appears somewhere in the table.

Strangely, many (but not all) of the imprimitive Pythagorean triples are also in the table. So what exactly is going on?

The answer is two-fold. The first part of the answer (and probably the easier of the two) is that if m and n have a common factor d then the associated triple will consist of numbers that have d2 as a common factor. For example, the triple in position [6,3] is (27, 36, 45) -- 6 and 3 have a common factor of 3 -- and 9 divides into 27, 36 and 45. This first part of the answer explains imprimitive triples that appear in the table which are some perfect square times a primitive triple. If we insist that we only consider values of m and n that have no common factors then many (but not all) of the imprimitive triples in the table will be eliminated.

The second part of the answer is both more complicated and more interesting. The "table" we have been discussing is really a map P from N2 to N3 given by P([m,n]) = [n2-m2,2mn,n2+m2]. This map interacts in an interesting way with a map S that I (only half-jokingly) call the "square root of 2" map. This mapping S is from N2 to itself, and is defined by S([m,n]) = [n-m, n+m]. If you work out what happens when you apply S twice to some pair, you'll see why I call it the "square root of 2" map.

The "interesting interaction" I referred to in the last paragraph comes about when you compose these two maps.

P(S([m,n])) = P([n-m, n+m])

= [(n2+2mn+m2)-(n2-2mn+m2), 2(n-m)(n+m),(n2+2mn+m2)+(n2-2mn+m2)]

= [4mn, 2(n2-m2), 2(n2+m2)]

So, if P([m,n]) = [a,b,c], then P(S([m,n])) = [2b, 2a, 2c].

So any pair [x,y] that is in the image of the map S will be associated with a Pythagorean triple that is the double of a smaller triple with the first two numbers interchanged. It is easy to check that the image of S consists of pairs where both coordinates are even or where both coordinates are odd. The former case (where both coordinates are even) has already been eliminated from consideration as this just means that 2 is a common factor.

We are now ready to make a precise statement about Pythagorean triples.

Every non-trivial, primitive, Pythagorean triple is (up to reordering of its constituents) of the form (n2 - m2, 2mn, n2 + m2) where m and n are relatively prime, positive integers which are not both odd.