Making Pythagorean Triples



What's a Pythagorean Triple?

A Pythagorean Triple is a set of three integers which would fit as sides of a right triangle. In other words, three numbers a, b, and c such that a2 + b2 = c2.

Finding triples - the formula

The short story goes like this:

Examples

You can verify algebraically that a2 + b2 = c2 in all cases.

Foundations - adding odd integers

So how does this work?

Somewhere around 8th grade I learned that the sum of the first n odd integers is equal to the square of n.

Note that (2n - 1) is the nth odd integer.

So the difference between any two consecutive squares is an odd number, and the difference between any two squares is the sum of consecutive odd numbers

Finding the triples - odd numbers

We're trying to find three numbers - a, b, and c - such that a2 + b2 = c2.

Let's pick any number for a. If a is an odd number, then a2 is an odd integer and is also the difference between two squares. For example, 32 = 9. Since 9 is the 5th odd integer, it's the difference between the 4th and 5th squares - 16 and 25. So (3, 4, 5) is a Pythagorean triple.

Pick an odd number. This will be your first number - a. 3 5 n
Square it. 9 25 n2
Find out where the square comes among the odd numbers - add one and divide by two. This will be your highest number, c. (9 + 1) / 2 = 5 (25 + 1) / 2 = 13 (n2 + 1) / 2
Subtract one to find the other number, b. 4 12 [(n2 + 1) / 2] - 1 =
(n2 - 1) / 2
Triple 3, 4, 5 5, 12, 13

So we get the formulas:

Finding the triples - even numbers (gap of two)

If a is an even number, a2 is not odd, but it is the sum of two odd numbers. So a2 will be the difference between squares that are two apart.

Pick an even number. This will be our first number - a. 6 8 n
Square it. 36 64 n2
The two odd numbers that add up to the square will average half the square. 18 32 (n2 / 2)
Add and subtract one to get the two odd numbers. 17 + 19 31 + 33 ((n2 / 2) - 1) +
(n2 / 2) + 1)
Add one to the higher number and divide by two. This will be the highest number, c. (19 + 1) / 2 = 10 (33 + 1) / 2 = 17 (((n2 / 2) + 1) + 1) / 2 =
(n2 + 4) / 4
Subtract two to get the third number, b. 8 15 ((n2 + 4) / 4) - 2 =
(n2 - 4) / 4

In general...

Let's try a general case. For the example we'll use 92 = 81 = 25 + 27 + 29. Since 29 is the 15th odd number, our high number will be 15. And since there were three odd numbers the other number for our triple will be three less, i.e. 12. So we get the triple (9, 12, 15).

Pick any positive integer. 9 n
Square it. 81 n2
Guess how many odd numbers will add up to the square. Call it our "gap". 3 g
Divide the square by the gap to find the average value. 27 n2 / g
The range - difference between the highest and lowest of the odd numbers - will be two less than twice the gap. 4 2g - 2
Half of that will be above the average, so the add half the range to the average to get the highest of the odd numbers. 27 + 2 = 29 (n2 / g) + (2g - 2) / 2 =
(n2 / g) + (g - 1)
Add one and divide by two to find the highest number in our triple. (29 + 1) / 2 = 15 (((n2 / g) + (g - 1)) + 1) / 2 =
((n2 / g) + g) / 2 =
(n2 + g2) / 2g
Subtract the gap to get the other number for the triple. 15 - 3 = 12 ((n2 + g2) / 2g) - g =
(n2 + g2 - 2g2) / 2g =
(n2 - g2) / 2g

So our final result is the formula from the top:

Limiting the choices

We can pick any number for n, but what should be use for our gap, g?

Try it out!

We'll find all the Pythagorean triples that have 20 as one of the smaller numbers (a or b). Since 20 is even, we'll try all even values for g that are less than 20 and factors of 202 = 400. If (n2 + g2) / 2g is an integer, we've found a triple.

g n (n2 + g2) / 2g Triple Reduced Triple
2 20 404 / 4 = 101 20, 99, 101 20, 99, 101
4 20 416 / 8 = 52 20, 48, 52 5, 12, 13
6 20 6 not a factor of 400
8 20 464 / 16 = 29 20, 21, 29 20, 21, 29
10 20 500 / 20 = 25 15, 20, 25 3, 4, 5
12 20 12 not a factor of 400
14 20 14 not a factor of 400
16 20 656 / 32, not an integer
18 20 18 not a factor of 400