A Pythagorean triple is a set of positive integers that can be the lengths of sides of a right triangle, i.e. numbers *a*, *b*, and *c* such that

*a*² + *b*² = *c*².

A primitive Pythagorean triple (PPT) is a Pythagorean triple whose elements are relatively prime. For example, (50, 120, 130) is a Pythagorean triple, but it’s not primitive because all the entries are divisible by 10. But (5, 12, 13) is a primitive Pythagorean triple.

A method of generating all PPTs has been known since the time of Euclid, but I recently ran across a different approach to generating all PPTs [1].

Let’s standardize things a little by assuming our triples have the form (*a*, *b*, *c*) where *a* is odd, *b* is even, and *c* is the hypotenuse [2]. In every PPT one of the sides is even and one is odd, so we will assume the odd side is listed first.

It turns out that all PPTs can be found by multiplying the column vector [3, 4, 5] repeatedly by matrices *M*_{0}, *M*_{1}, or *M*_{2}. In [1], Romik uses the sequence of matrix multiplications needed to create a PPT as trinary number associated with the PPT.

The three matrices are given as follows.

Note that all three matrices have the same entries, though with different signs. If you number the columns starting at 1 (as mathematicians commonly do and computer scientists may not) then *M*_{k} is the matrix whose *k*th column is negative. There is no 0th column, so *M*_{0} is the matrix with no negative columns. The numbering I’ve used here differs from that used in [1].

For example, the primitive Pythagorean triple [5, 12, 13] is formed by multiplying [3, 4, 5] on the left by *M*_{2}. The PPT [117, 44, 125] is formed by multipling [3, 4, 5] by

*M*_{1} *M*_{1} *M*_{2}.

## More Pythagorean posts

[1] The dynamics of Pythagorean triples by Dan Romik

[2] Either *a* is odd and *b* is even or vice versa, so we let *a* be the odd one.

If *a* and *b* were both even, *c* would be even, and the triple would not be primitive. If *a* and *b* were both odd, *c*² would be divisible by 2 but not by 4, and so it couldn’t be a square.

Allowing negative powers, corresponding to matrix inverses, produces Pythagorean triples with some negative entries.

M0^-1 * [3,4,5] = [-1,0,1]

M0^-2*[3,4,5] = [-3,-4,5]

…