How to Generate Pythagorean Triplets

In sixth grade, I spent a lot of time exploring number theory. I'm impressed, in hindsight, at how far I got without the benefit of any algebra. My crowning achievement of the year was a method for generating Pythagorean triplets—that is, sets of three integers such that the sum of the squares of the first two is the square of the third; a triangle with sides these lengths will be, per the Pythagorean theorem, a right triangle.

My original formulas were a mixture of verbal description and geometric drawings. HTML may not be the best format for algebra, but it's even worse at drawing, so in this recreation of the method, I'll use algebra in the place of diagrams. Besides, it's more powerful. Specifically, at the time, I suspected the method produced all possible triplets, but couldn't prove it. Using algebra, I can show that it does doesn't. In addition, I can show which results are unique triplets—that is to say, those that are relatively prime (such as {3,4,5}) and not multiples of smaller triplets (such as {6,8,10}).

The method is built around the observation that the series of squares of integers is successive sums of the odd integers. Specifically, the square of n is the sum of all odd numbers less than 2n: 52 = 25 = 1 + 3 + 5 + 7 + 9. To get the next square, add the next odd number 2n+1: 36 = 25 + 11. I noticed this fact using graph paper: draw a square; to get the square with the next largest size, add a row of unit squares to two adjacent sides, then one more to get the corner.

If that odd number is itself a square, you've got a Pythagorean triplet: {sqrt(2n+1), n, n+1}.

The Method, part 1:

March through successive odd squares, and derive the associated triplet of each.

This means march through the odd numbers, as the squares of these are the odd squares. (Remember, odd times odd = odd, even times either even or odd = even.) The relevant formula is, for each odd number m, n = (m2 - 1) / 2. Since m is odd, write m = 2k+1, and so

n = ((2k+1)2 - 1)/2 = (4k2 + 4k + 1 - 1)/2 = 2k2 + 2k = 2k(k+1).

Thus, for the set of integers k, the triplets {2k+1, 2k(k+1), 2k(k+1)+1} will include all triplets with a difference of 1 between the second and third numbers. Thus:

For k = 1, m = 3 and n = (9-1)/2 = 4, so {3,4,5}. Familiar. Good.

k = 2 gives m = 5 and n = (25-1)/2 = 12, so {5,12,13}. The next most common. We're on a roll.

k = 3 gives m = 7 and n = (49-1)/2 = 24, so {7,24,25}. That's new.

k = 4 gives m = 9 and n = (81-1)/