# Wards Attic

Come browse the miscellany...

• • • Pythagorean Triples

## Triple of the Day

A Pythagorean triple is a set of three positive integers which could be the side lengths of a right triangle - popularly known as a2 + b2 = c2.  Some folks remember {3, 4, 5}, {5, 12, 13}, and {8, 15, 17}.  Others might know {20, 21, 29}.

It turns out that every natural number greater than two is part of at least one Pythagorean triple!  Enter a number between 3 and 999, then press the button to see its triples.  The program finds triples for your number as a or b, not c. Check out the "Making Triples" to see how it's done.

## Making 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:

• Pick an integer n.
• Pick another integer "gap" between 1 and n.  Call it g.
• If 2g divides n2 + g2, then you have a Pythagorean triple, namely
• a = n
• b = (n2 - g2) / 2g
• c = (n2 + g2) / 2g

Examples

• If n = 5 and g = 1, you get the triple 5, 12, 13.
• If n = 8 and g = 2, you get the triple 8, 15, 17.

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.

• 1 = 1 = 12
• 1 + 3 = 4 = 22
• 1 + 3 + 5 = 9 = 32
• 1 + 3 + 5 + 7 = 16 = 42
• 1 + 3 + 5 + ... + (2n - 1) = n2

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

• 52 - 42 = 25 - 16 = 9 = (2*5 - 1)
• 62 - 52 = 36 - 25 = 11 = (2*6 - 1)
• n2 - (n - 1)2 = (2n - 1)
• 172 - 152 = 289 - 225 = 64 = 31 + 33
• 292 - 212 = 841 - 441 = 400 = 93 + 95 + 97 + 99 + 101 + 103 + 105 + 107

#### 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:

• a = n
• b = c - 1 = (n2 - 1) / 2
• c = (n2 + 1) / 2

#### 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:

• a = n
• b = (n2 - g2) / 2g
• c = (n2 + g2) / 2g

#### Limiting the choices

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

• Obviously g has to be less than n, since otherwise our value for b would be zero or negative.
• Since (n2 + g2) / 2g = ((n2 / g) + g) / 2, we know n2 / g must be an integer, so g must be a factor of n2.
• If n is odd, n2 will also be odd, so b will be odd and c will be even, or vice versa.  So g will have to be odd.  Likewise if n is even, g will also be even.

#### 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