# Pythagorean Triples

## Introduction

Pythagorean triples are sets of three integers (a,b,c) where a2 + b2 = c2. The simplest of these (where 'a', 'b' and 'c' are all greater than 0) is (3,4,5) as 9 + 16 = 25. There are clearly an unlimited number of these triples as any multiple of (3,4,5), say (33,44,55), also meets the requirements: (1089 + 1936 = 3025).

Ignoring these multiples, how many of these triples are there? The image on the left is constructed by taking the first two terms (a and b) an plotting them on squared paper. In this chart the 'c' value is now the distance of the points from the origin (the centre). Light blue points represent those values of 'a' and 'b' that have no common factors. There are basically five of these - (3,4), (5,12), (7,24), (8,15) and (20, 21) - with c values of (5,13,25,17 and 29). The 8 fold symmetry and the other 35 light blue points arise because if a2 + b2 = c2 is true for (a,b) it is also true for (b,a), (−b,a), (−a,−b) etc. The darker blue points represent the multiples of the basic points, (6,8), (9,12), (10,24) etc. Note: the images on this page omit the triple (0,0,0) and all the multiples and permutations of (0,1,1).

I will call the triples where 'a' and 'b' have no common factors and b > a > 0 the prime triples. So how many prime triples are there? The next image shows all the triples (prime or otherwise) out to (320,320). The prime ones are shown in light blue and their multiples darker. Each prime triple generates a line of evenly spaced multiples, which are shown in darker blue. The really obvious lines are generated by variations of (3,4). There are 57 prime triples in this diagram, repeated 8 times through reflection and permutation. They are:

 (3, 4, 5) (8, 15, 17) (60, 221, 229) (65, 72, 97) (175, 288, 337) (5, 12, 13) (12, 35, 37) (68, 285, 293) (85, 132, 157) (140, 171, 221) (7, 24, 25) (16, 63, 65) (33, 56, 65) (95, 168, 193) (160, 231, 281) (9, 40, 41) (20, 99, 101) (39, 80, 89) (105, 208, 233) (180, 299, 349) (11, 60, 61) (24, 143, 145) (51, 140, 149) (115, 252, 277) (204, 253, 325) (13, 84, 85) (28, 195, 197) (57, 176, 185) (88, 105, 137) (207, 224, 305) (15, 112, 113) (32, 255, 257) (69, 260, 269) (104, 153, 185) (225, 272, 353) (17, 144, 145) (20, 21, 29) (75, 308, 317) (120, 209, 241) (252, 275, 373) (19, 180, 181) (28, 45, 53) (48, 55, 73) (136, 273, 305) (297, 304, 425) (21, 220, 221) (36, 77, 85) (60, 91, 109) (119, 120, 169) (23, 264, 265) (44, 117, 125) (84, 187, 205) (133, 156, 205) (25, 312, 313) (52, 165, 173) (96, 247, 265) (161, 240, 289)

Table 1.

## Algorithms

The simplest way to generate a sequence of triples is to notice that difference between consecutive square numbers [1,4,9,16,...] generates the sequence of odd numbers [3,5,7,9,...]. If the odd number is also a square [9,25,49,...] you have a triple. And because two consecutive square numbers can't have any common factors it must be prime. So we have already found a mechanism for generating an unlimited number of prime triples. The numbers in the first column of the table 1 (above) belong to this sequence. We can create a generic formula for these triples as follows:

Although the above algorithm generates an unending sequence of prime triples it doesn't generate them all. Of the 57 prime triples in table 1, only 12 follow this pattern.

### A more general approach

Starting with c = b + n, where n is a positive integer;

So n × (2b + n) must be a square number.

To find solutons to this equation we look at the prime factors of n and (2b + n), starting with n. Some prime factors will appear an odd number of times and others an even number. We collect all the even ones into one list and all the odd ones into another. If a prime factor appears an odd number of times more than 2, then one goes into the odd list and the remainder into the even list.

The product off all the even factors will be a square number and the product off all the odd ones will have no repeated prime factors. This is a rather long winded way of demonstrating that all integers can be factorised into the product of a square and a term with no repeating factors, so long as we allow the posibility that the square number is 1.

For n × (2b + n) to be a square number, (2b + n) must be the product of 'k' and another square number (y2). So

Where 'x', 'y' and 'k' are all integers. When 'n' is even, another factorisation is possible:

In the interactive element above, if you set y = (1+√2)x (or as close as you can get), the 'a' and 'b' values will be similar.

### Some examples

#### n = 1

When 'n' is 1, 'x' is 1 and 'k' is 1. So

For integer solutions y must be odd (1,3,5,...). This generates the triples [1,0,1], [3,4,5], [5,12,13], etc.

#### n = 2

When 'n' is 2 we use the second factorisation based on, n = 2m. So 'x' is 1 and 'k' is 1, giving;

This generates the sequence

When 'y' is odd, y2±1 is even and all the terms can be divided by 2, so this formulation only generates prime triples when 'y' is even, making 'a' is a multiple of 4. Eliminating the permutation of (3,4,5), multiples of (0,1,1) and other multiples leaves the prime sequence:

#### n = 3

For n = 3 we use the original formulation where k = 3 and x = 1.

'a', 'b' and 'c' are all divisible by 3 so all triples generated are multiples of those generated by n = 1. In general when k > 1 'a', 'b' and 'c' will have 'k' as a common factor so the triple can't be prime.

### Summary

Above we identified two sets of equations

The equations in the second column are equivalent to the ones in the first column, when k is even. For instance setting k = 2 in the first column generates the same triple as k = 1 in the second. So we can generate all triples using just the first set of equations. All the prime triples can generated using k values of 1 or 2. When k is odd x2 − y2 must be even.

## Source Code

Pythagoras.py contains code for generating the triples and the diagrams that illustrate this page. It is a bit out of date so the agorithms don't match exactly those decribed here, though they get the correct results.

## Images

A plot of the prime triples out to (3200x3200). Each pixel represents a 10x10 cell. This is quite interesting as most of the points appear to lie on curves and there are 'special' points where three of these curves appear to intersect. The same area with the non prime triples (red) included. The straight lines are generated by multiples of the smaller triples like (3,4,5). And finally the prime triples shown out to (32000,32000). Each pixel now represents 100x100 points. ## Curves

The (a, b) values from the following set of triples appear to lie on a curve. They can be divided into two sub sets bases on whether 'a' is odd or even:

Even Odd Image
−6162 + 6632 = 9052
−5402 + 6292 = 8292
−4682 + 5952 = 7572
−4002 + 5612 = 6892
−3362 + 5272 = 6252
−2762 + 4932 = 5652
−2202 + 4592 = 5092
−1682 + 4252 = 4572
−1202 + 3912 = 4092
−762 + 3572 = 3652
−362 + 3232 = 3252
322 + 2552 = 2572
602 + 2212 = 2292
842 + 1872 = 2052
1042 + 1532 = 1852
1202 + 1192 = 1692
1322 + 852 = 1572
1402 + 512 = 1492
1442 + 172 = 1452
−4812 + 6002 = 7692
−3852 + 5522 = 6732
−2172 + 4562 = 5052
−1452 + 4082 = 4332
−252 + 3122 = 3132
232 + 2642 = 2652
952 + 1682 = 1932
1192 + 1202 = 1692
1432 + 242 = 1452 These two lists actually define two parabolas that are almost coincident. If we take two points from one of the lists, say (a1, b1) and (a2, b2), we can construct the equation:

a neater formulation is

In the above example the points in the left column lie on the curve

b2 + 578a − 83521 = 0

and those on the right

b2 + 576a − 82944 = 0

These curves intersect the a-axis at 144.5 (172/2) and 144 (122) respectively. The are nearly co-incident because 17/12 isn't a bad approximation for √2. They are examples of the general curves:

b2 + 2m2a − m4 = 0 and b2 + 4m2a − 4m4 = 0

where 'm' is a positive integer. These can be derived from the generating equations: a = x × k × y and b = (y2 − x2) × (k/2). Substituting x = a/ky into the second equation gives:

b = (y2 − a2 / k2y2) × (k/2).

which can be aranged to give

a2 + (2ky2)b − k2y4 = 0.

The 2 equations above correspond to the cases where k = 1 and 2, and m = y (a and b have been swapped). There are actually 4 sets of parabolas, the other three are generated through the transformations: (a,b) ⇔ (a,−b), (a,b) ⇔ (b,a) and (a,b) ⇔ (b,−a), representing reflections in the lines a = 0, a = b and a = −b.

The interactive Triples application can be used to visualise these sets of parameters, for instance, this image: Shows the set of parabolas for k = 1 with the prime triples superimposed. I've called these the 'West' parabolas as they extend infinitely to the left. This shows that about half the prime triples fall on these lines. If we add in the k = 2 we see that now all the primes are accounted for. If we add in the "East" parabolas (generated by the transformation (a,b) ⇔ (a,−b)) we get the following image, which shows that all the prime triples lie on the intersection of an East and a West parabola with the same 'k' value (1 or 2). Interestingly, if we add in the other two sets of parabolas, North and South (generated from (b,a) and (b,−a)) we now see that the triples that were the intersection of 2 East/West parameters are also at the intersection of two North/South parabolas of the opposite k value (1 ⇔ 2). So we can locate all the prime triples using just one set of parabolas. You can verify this using the interactive application. The intersections that don't have prime triples do have non prime triples, which you can aslo verify using the application.

## Complex Numbers

If we take two complex numbers (a1,b1) and (a2,b2) and multiply them together we get a third complex number (a3,b3). If these numbers are interpreted as vectors then the lengths (l) of the three vectors are related as l3 = l1 x l2. So if (a1,b1,l1) and (a2,b2,l2) are Pythagorean triples so is (a3,b3,l3).

When multiplying complex numbers;

We can use this as another way of generating unlimited series of triples, for instance the powers of (3,4) are;

 (3 + 4i)n = a b c x y k (3 + 4i)1 (3 + 4i) 3 4 5 1 3 1 (3 + 4i)2 (-7 + 24i) 7 24 25 1 7 1 (3 + 4i)3 (-117 + 44i) 44 117 125 2 11 2 (3 + 4i)4 (-527 - 336i) 336 527 625 7 24 2 (3 + 4i)5 (-237 - 3116i) 237 3,116 3,125 3 79 1 (3 + 4i)6 (11753 - 10296i) 10,296 11,753 15,625 44 117 2 (3 + 4i)7 (76443 + 16124i) 16,124 76,443 78,125 29 278 2 (3 + 4i)8 (164833 + 354144i) 164,833 354,144 390,625 191 863 1 (3 + 4i)9 (-922077 + 1721764i) 922,077 1,721,764 1,953,125 481 1917 1 (3 + 4i)10 (-9653287 + 1476984i) 1,476,984 9,653,287 9,765,625 237 3116 2

Although this series is unlimited the examples it generates are rather far apart, only the first six appear in our diagrams above. The 'x', 'y' and 'k' columns shows the values used to generate this triple, using the first set of equations. Notice that all the 'k' values are 1 or 2, so all these triples are prime, according to our original definition. An alternative definition of primeness based on this complex number mutiplication would render all but (3,4,5) composite.

The series generated by (5,12) shoots out of sight even more rapidly.

 a b c x y k 5 12 13 1 5 1 119 120 132 7 17 1 828 2,035 133 3 138 2 239 28,560 134 1 239 1 145,668 341,525 135 122 1194 2 3,369,960 3,455,641 136 828 2035 2 23,161,315 58,317,492 137 2105 11003 1 13,651,680 815,616,479 138 239 28560 2 4,241,902,555 9,719,139,348 139 29755 142561 1 95,420,159,401 99,498,527,400 1310 195857 487193 1

When multiplying two different triples together there are two possible result sets, for instance multiplying the 64 permutations of (3,4,5) and (5,12,13) generates two sets of 32 values based on (16, 63, 65) and (33, 56, 65). For instance;

Generally, if 'c1' and 'c2' are the largest values in different triples, then c1 × c2 will be the largest value in two different triples. This rule doesn't work when c1 = c2 as one of the triples turns out to be (0,c,c).

## The interactive Calculator

If you have google Chrome with the native client plugin enabled you can use this application to calculate the triples in particlar ranges and generate images like those on this page.

This doesn't really work any more, I will replace it with a javascript version when I get a chance.

## Other pages

(c) John Whitehouse 2012 - 2017