Home page

Home Page

Pythagorean Triples

Updated February 2012 - Added interactive calculator

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?

Map

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).

Map

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.

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.

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;

      a2 + b2 = (b + 1)2

      => a2 + b2 = b2 + 2b + 1
      => a2 = 2b + 1

    (substitute a = 2k + 1)

      => (2k + 1)2 = 2b + 1
      => 4 × k2 + 4 × k + 1 = 2b + 1
      => 2 × k2 + 2 × k = b

      a = 2 × k + 1
      b = 2 × k × (k + 1)
      c = 2 × k × (k + 1) + 1
    

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;

      a2 + b2 = (b+n)2

      => a2 + b2 = b2 + 2nb + n2
      => a2 = 2nb + n2
      => a2 = n × (2b + n)
    

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.

      n = x2 * k
    

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

      a2 = n × (2b + n) = (x2 × k) × (k × y2) = (x × k × y)2

    Giving:

      a = x × k × y
      b = (y2 − x2) × (k/2)
      c = b + n
        = (y2 − x2) × (k/2) + x2 × k
        = (y2 + x2) × (k/2)
    

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

      n = 2m
      a2 = 2m × (2b + 2m) = 4m × (b + m)

    Set

      m     = k × x2
      b + m = k × y2

    Giving:

      a = 2 × x × k × y
      b = k × (y2 − x2)
      c = k × (y2 + x2)
    

Some examples

n = 1

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

      a = y
      b = (y2 - 1) / 2
      c = (y2 + 1) / 2
    

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;

      a = 2 × x × k × y = 2 × y
      b = k × (y2 − x2) = (y2 − 1)
      c = k × (y2 + x2) = (y2 + 1)
    

This generates the sequence

        [ 2,  0,   2]
        [ 4,  3,   5] = [3, 4,  5]
        [ 6,  8,  10] = 2 × [3, 4, 5]
        [ 8, 15,  17]
        [10, 24,  26] = 2 × [5, 12, 13]
        [12, 35,  37]
        [14, 48,  50] = 2 × [7, 24, 25]
        [16, 63,  65]
        [18, 80,  82] = 2 × [9, 40, 41]
        [20, 99, 101]

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:

        [ 8, 15,  17]
        [12, 35,  37]
        [16, 63,  65]
        [20, 99, 101]
        ...

n = 3

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

      a = x × k × y = 3 × y
      b = (y2 − x2) × (k/2) = (y2 − 1) × (3/2)
      c = (y2 + 1) × (3/2)
    

'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

The above discussions shows us that all prime triples can be generated from a2 + b2 = (b+n)2 where 'n' is either a square number or twice a square number (because for all other 'n' the generated terms will have a common factor 'k', greater than 1). Previously we calculated the series based on x = 1, (n is 1 or 2). The next set of prime triples will be generated when x = 2 (n is 4 or 8).

If we reformulate the equations with k = 1 and 'x' as the key driver rather than 'n' we get

      a = x × y
      b = (y2 − x2) / 2
      c = (y2 + x2) / 2

    and

      a = 2 × x × y
      b = (y2 − x2)
      c = (y2 + x2)
      
    

which will generate all prime triples (and some that aren't).

These equations generate none prime triples when

  1. x and y have factors in common.
  2. If x and y are both odd, the second set of equations will generate triples with a common factor of 2.

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.

Map

The same area with the non prime triples (red) included. The straight lines are generated by multiples of the smaller triples like (3,4).

Map

And finally the prime triples shown out to (32000,32000). Each pixel now represents 100x100 points.

Map

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;

      a3 = a1 × a2 − b1 × b2
      b3 = a1 × b2 + b1 × a2
    

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

(3 + 4i)i = a b c n
(3 + 4i)1 (3 + 4i) 3 4 5 12
(3 + 4i)2 (-7 + 24i) 7 24 25 12
(3 + 4i)3 (-117 + 44i)  44 117 125 2 × 22
(3 + 4i)4 (-527 - 336i)  336 527 625 2 × 72
(3 + 4i)5 (-237 - 3116i)  237 3,116 3,125 32
(3 + 4i)6 (11753 - 10296i)  10,296 11,752 15,625 2 × 442
(3 + 4i)7 (76443 + 16124i)  16,124 76,443 78,125 2 × 292
(3 + 4i)8 (164833 + 354144i)  164,833 354,144 390,625 1912
(3 + 4i)9 (-922077 + 1721764i) 922,077 1,721,764 1,953,125 4812
(3 + 4i)10 (-9653287 + 1476984i) 1,476,984 9,653,287 9,765,625 2 × 2372

Although this series is unlimited the examples it generates are rather far apart, only the first six appear in our diagrams above. It also shows that all powers of 5 are the square root of the sum of two squares. The 'n' column allows us to identify the 'x' value associated with the new triple.

The series generated by (5,12) shoots out of sight even more rapidly, but at the same time shows that all powers of 13 can also be represented as the square root of the sum of two squares.

a b c n
5 12 13 12
119 120 132 72
828 2,035 133 2 × 92
239 28,560 134 12
145,668 341,525 135 2 × 1222
3,369,960 3,455,641 136 2 × 8282
23,161,315 58,317,492 137 21052
13,651,680 815,616,479 138 2 × 2392
4,241,902,555 9,719,139,348 139 297552
95,420,159,401 99,498,527,400 1310 1958572

Generally, if 'c' is the largest value in a triple, then so is ci.

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;


      (3 + 4j) x ( 5 + 12j) = (-33 + 56j)
      (3 + 4j) x (12 +  5j) = ( 16 + 63j)
      (4 + 3j) x (12 +  5j) = ( 33 + 56j)
      (4 + 3j) x ( 5 + 12j) = (-16 + 63j)

      => 652 = 162 + 632 = 332 + 562
    

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).

(c) John Whitehouse 2011