Pythagorean Triples
Pythagorean Triples
I. Introduction
The Pythagorean theorem carries the name of the Greek mathematician Pythagoras, who lived in the 6th century BCE, though the theorem
had been known elsewhere for some time before. Although the Pythagorean theorem arose in geometry, we will be concerned strictly with
the number theoretic properties of the Pythagorean equation, using the connection to geometry only as a jumping off point.
Theorem 1 (Pythagorean Theorem and converse) Let x, y, and z be positive reals. Then z is the length of the hypotenuse of a right triangle
with side lengths x, y, and z if and only if
(1)
A Pythagorean triple is an ordered triple (x, y, z) of three positive integers such that x2 + y2 = z2. If x, y, and z are relatively prime, then the
triple is called primitive.
Let us first note the parity of x, y, and z in primitive triples, that is their values modulo 2. Since 02 ≡ 0, 12 ≡ 1, 22 ≡ 0, and 32 ≡ 1 mod 4, the
only squares modulo 4 are 0 and 1. Letting X = x2, Y = y2, and Z = z2, we have the following solutions to X + Y ≡ Z mod 4:
0+0≡0
0+1≡1
1+0≡1
(1 + 1 ≡ 2 is not a solution because 2 is not a square modulo 4.) The first of these solutions corresponds only to nonprimitive triples — x, y,
and z are all divisible by 2. Therefore any primitive triple corresponds to one of the other two solutions. In either case, Z is odd, and exactly
one of X and Y is always odd. Thus z is odd, and exactly one of x and y is odd. To establish a convention, let us say that x is always odd and
y is always even, since otherwise we can rename the variables of a given triple to obtain this. A primitive Pythagorean triple therefore has a
unique representation (x, y, z), where y is even and x and z are odd.
or In fact, only one of these values for z holds. The solution results in x or y being negative, so we
take
(2)
Define
(3)
(4)
The generators r and s will provide the basis of study for primitive triples. Most texts use the more common generators m and n, where x =
m2 – n2, y = 2mn, and z = m2 + n2. Though I believe r and s as defined above are more natural choices (since they emphasize symmetry in
the generators and not in the side lengths), the analysis is the same in the end, as m = r + s and n = r.
Proof. Let (x, y, z) be a primitive Pythagorean triple (with even y). The quantities z + y and 2y are relatively prime because z and y are
relatively prime in primitive triples and z + y is odd. We have
so z + y and z – y are relatively prime (because any common divisor would also divide 2y). The Pythagorean relation (1) implies that
so z + y and z – y must both be squares because they are relatively prime. Therefore is an odd integer. By (4), r is also an
integer because
is even.
Now that we have established that r and s are integers for primitive triples, we will show that they are relatively prime. Let m = (r, s). Since
m divides both r and s, m divides x, y, and z by (3). But since x and y (in particular) are relatively prime, this means m = 1.
For the converse, assume s is odd and (r, s) = 1. Because , we have that (r, z) = 1, since any divisor of both r and z is a
divisor of s but r and s are relatively prime. By the definition of r, x + 2r2 = z, so similarly (x, z) = 1. Therefore the triple (x, y, z) is
primitive. ■
Proof. Since each relatively prime pair (r, s) with odd s gives a unique primitive triple, it suffices to consider the cardinality of the set S =
{(r, s) | r and s are relatively prime and s is odd}. This set is infinite since for each odd s there is at least one r relatively prime to s, but S is
no larger than the rationals (by mapping S injectively into the rationals by sending (r, s) to r / s). Therefore the set S is countably infinite. ■
Remark 1 If (x, y, z) is a primitive Pythagorean triple, then y ≡ 0 mod 4, z ≡ 1 mod 4, exactly one of {x, y} satisfies k ≡ 0 mod 3, and
exactly one of {x, y, z} satisfies k ≡ 0 mod 5.
Proof. From (3), y = 2r (r + s). Either r is even or r + s is even (since s is odd), so 4 divides y.
As shown above, the only squares modulo 4 are 0 and 1. Since z = r2 + (r + s)2 is a sum of two squares and s is odd, there are two
possibilities. If r is odd then z ≡ 1 + 0 ≡ 1 mod 4, and if r is even then z ≡ 0 + 1 ≡ 1 mod 4.
The only squares modulo 3 are 0 and 1. With X = x2, Y = y2, and Z = z2, the congruence X + Y ≡ Z mod 3 has the following solutions:
0+0≡0
0+1≡1
1+0≡1
The first case is nonprimitive, so either x2 or y2 is divisible by 3, and this implies that either x or y is divisible by 3.
The only squares modulo 5 are 0, 1, and 4, so X + Y ≡ Z mod 5 has solutions (up to permutation of X and Y):
0+0≡0
0+1≡1
0+4≡4
1+4≡0
To convince yourself that these are the only three generalizations we can make like this, experiment with different prime moduli with the
Tripes Modulo p JavaScript program. Larger numbers (7, 11, 13,...) yield no obvious statements about the divisors of the respective triple
members.
x y z r s
33 56 65 4 3
63 16 65 1 7
x y z r s
13 84 85 6 1
77 36 85 2 7
If we search larger numbers, we can find larger sets of siblings. There are, for example, four primitive triples with hypotenuse 1105:
x y z r s
47 1104 1105 23 1
817 744 1105 12 19
943 576 1105 9 23
1073 264 1105 4 29
In general, the number of primitive Pythagorean triples of hypotenuse n is dependent on the number of prime factors of n that are
congruent to 1 modulo 4. It turns out that only powers of 2 appear as these numbers. The numbers in the sequence 5, 65, 1105, 32045,
1185665, 48612265, 2576450045,... are the smallest hypotenuses that harbor 1, 2, 4, 8, 16, 32, 64,... primitive Pythagorean triples. The
terms are given by multiplying successive primes that satisfy p ≡ 1 mod 4:
x y z r s
2277 31964 32045 122 9
8283 30956 32045 109 33
17253 27004 32045 86 71
21093 24124 32045 74 89
23067 22244 32045 67 99
27813 15916 32045 46 127
31323 6764 32045 19 159
32037 716 32045 2 177
But why do primitive triples form only in sets of 2α, and what is the connection to primes p ≡ 1 mod 4? Let us look at the prime factors of
n more closely.
By examining the data, it appears that the prime factors of each hypotenuse satisfy p ≡ 1 mod 4. Further, each prime hyptenuse holds only
one triple, and the more factors a hypotenuse has, the more triples it holds. Specifically, if ω(n) is the number of distinct prime factors of n
and all of the prime factors of n satisfy p ≡ 1 mod 4, then n appears to be the hypotenuse of exactly 2ω(n) – 1 primitive Pythagorean triples.
(If n has any prime factors p ≡ 2 or 3 mod 4, then n is not the hypotenuse of any primitive triples.) In light of this, it makes sense that the
first sibling sets of order 2α will be found on the multiples of the first α primes that satisfy p ≡ 1 mod 4.
Of course, explaining where 2ω(z) – 1 arises is more tricky. Some experimentation shows that, for n with the above criteria, (3) has 2ω(n) – 1
positive integral solutions for r and s. We are interested in solutions to n = r2 + (r + s)2 where r and r + s are relatively prime (or,
equivalently, (r, s) = 1). To see what is happening, first let us quote a theorem attributed to Fermat, the proof of which we leave to a book
covering introductory number theory.
Theorem 3 (Fermat) Let p be a prime such that p ≡ 1 mod 4. Then p can be expressed uniquely as a sum of two squares.
By "uniquely" it is meant that there exist unique integers a and b such that 0 < a < b and p = a2 + b2. Using Fermat's theorem, we
decompose a number n into is prime factors and write each prime as a sum of two squares. We then make use of the Fibonacci identity,
(5)
by which we can write the product of sums of two squares again as the sum of two squares. Multiplying together the sum of squares
representations for the prime factors of n gives a sum of squares representation for n, and since the hypotenuse of a primitive triple is a sum
r2 + (r + s)2 of two squares (by (3)), we will be able to generate primitive triples of hypotenuse n simply by knowing the sum of squares
representations of the prime factors of n.
This solution corresponds to r = 23, s = 1, which generate the triple (47, 1104, 1105). The other solutions to 1105 = r2 + (r + s)2 can be
obtained by changing the order in which the factors are multiplied together and by reversing the sum of squares expressions of some
factors.
Actually counting the solutions that we get in this way is cumbersome, however. The system is not a very natural one, and "Fibonacci
multiplication" is in fact not even associative. Much better are the Gaussian integers — complex numbers of the form a + bi, where a and b
are ordinary integers and i2 = –1. By Fermat's theorem, each prime factor p ≡ 1 mod 4 of n conveniently has the representation p = a2 + b2
= (a + bi) (a – bi). Multiplying two Gaussian integers exactly results in the Fibonacci identity:
Rather than multiplying sum of squares representations, we will multiply Gaussian integers. We obtain the four solutions to 1105 = r2 + (r
+ s)2 by multiplying (Gaussian) "halves" of its (integer) factors p = (a + bi) (a – bi) . For each of the three primes dividing 1105, we have
two choices of which Gaussian factor to take. Complex conjugation of a solution does not change the sum of squares representation, so we
can choose the first such factor to have positive imaginary part. The solutions are then
By multiplying each by its complex conjugate, these correspond to the four representations of 1105 as a sum of two relatively prime
squares (and thus to the four primitive triples with hypotenuse 1105).
Proposition Let n > 1 be a natural number whose prime factors all satisfy p ≡ 1 mod 4. Then the number of distinct ways that n can be
expressed as a sum a2 + b2 of two squares with a and b are relatively prime is 2ω(n) – 1, where ω(n) is the number of distinct prime factors
of n.
This result allows us to count triples of a given hypotenuse: Because z has 2ω(z) – 1 sum of squares representations when all its factors
satisfy p ≡ 1 mod 4, there are 2ω(z) – 1 distinct solutions to (3). In each of these solutions, r and s are relatively prime (because r + si is not
divisible by any integer prime) and s is odd (because an even s results in an even z). Therefore z is the hypotenuse of exactly 2ω(z) – 1
primitive Pythagorean triples. Not only does it allow counting, however, but it provides an algorithm to actually construct the triples given
the sums of square representations of its prime factors. A simple program can readily compute, for example, the 214 = 16384 primitive
triples with hypotenuse n = 16880412096169215173498945, which is the product of the first fifteen primes that satisfy p ≡ 1 mod 4.
Until now we have considered triples based only on z; with what we have learned it is now easy to understand them sorted also by x or by y
(where "P" denotes a prime leg and "P" denotes a prime power leg):
x y z r s x y z r s x y z r s x y z r s
3 P 4 5 1 1 21 20 29 2 3 3 4 P 5 1 1 45 28 53 2 5
5 P 12 13 2 1 21 220 221 10 1 15 8 P 17 1 3 195 28 197 1 13
7 P 24 25 3 1 23 P 264 265 11 1 5 12 13 2 1 255 32 P 257 1 15
9 P 40 41 4 1 25 P 312 313 12 1 35 12 37 1 5 77 36 85 2 7
11 P 60 61 5 1 27 P 364 365 13 1 63 16 P 65 1 7 323 36 325 1 17
13 P 84 85 6 1 29 P 420 421 14 1 21 20 29 2 3 9 40 41 4 1
15 8 17 1 3 31 P 480 481 15 1 99 20 101 1 9 399 40 401 1 19
15 112 113 7 1 33 56 65 4 3 7 24 25 3 1 117 44 125 2 9
17 P 144 145 8 1 33 544 545 16 1 143 24 145 1 11 483 44 485 1 21
19 P 180 181 9 1
Very similar to the case of z, the prime factors of a given x determine how many triples have x as a leg (without the restriction that the
prime factors must satisfy p ≡ 1 mod 4): If x ≡ 1 mod 2, then x is a leg of 2ω(x) – 1 primitive triples. And if y ≡ 0 mod 4, then y is a leg of
2ω(y) – 1 primitive triples.
Theorem 3 Let ω(n) be the number of distinct prime factors of a natural number n > 1. The number of primitive Pythagorean triples of
which n is a member is
(8)
We now generalize the problem of counting to include nonprimitive triples. (For a nonprimitive triple, r and s are irrational unless the
common factor of the triple is a square.)
with pi ≡ 1 mod 4 for all i and qj ≡ 3 mod 4 for all j, then z is the hypotenuse of exactly
(9)
Pythagorean triples.
Proof. Let z be a natural number. Since primes q ≡ 3 mod 4 and the prime 2 do not contribute to primitive triples, these factors in z do not
contribute to the total number of triples with hypotenuse z (i.e., removing all of these factors from a given z results in an integer that is the
hypotenuse of the same number of triples as z). Therefore it suffices to consider natural numbers of the form with
pi ≡ 1 mod 4 for each i. The number of divisors of z that can be written as a product of powers of exactly j primes is σj(α1,α2,...,αk), the jth
elementary symmetric polynomial on the exponents α1, α2, ..., αk. Each such divisor d of z is the hypotenuse of 2ω(d) – 1 = 2j – 1 primitive
triples, by Theorem 3, and so contributes 2j – 1 nonprimitive triples of hypotenuse z by simply multiplying by z / d. Thus, by a property of
the elementary symmetric polynomials,
Corollary Let z = Q p1 p2 ... pk > 1 be a natural number with exactly k distinct prime factors satisfying p ≡ 1 mod 4 and no factor of the
form p2 for any prime p ≡ 1 mod 4. Then the number of Pythagorean triples with hypotenuse z is T(z) = (3k – 1) / 2.
(10)
Any odd x then gives such a triple. Substituting this into the definition of r gives
Since s = √b = 1, the first few triples with b = 1 are:
x y z r s
3 4 5 1 1
5 12 13 2 1
7 24 25 3 1
9 40 41 4 1
11 60 61 5 1
13 84 85 6 1
Moreover, the sequence of y values is 4 times the triangular numbers, since, by (3),
This same procedure can be used for any valid a or b value because the resulting equation will always be linear in z. From (3) we see that
the nth triples with fixed a and b values are given by
(11)
We now turn to primitive triples with the restriction that |x – y| is a given difference d. The following is a list of the first few triples for
which d = 1. (The first twenty-five of these triples are listed.)
x y z r s x–y
3 4 5 1 1 –1
21 20 29 2 3 1
119 120 169 5 7 –1
697 696 985 12 17 1
4059 4060 5741 29 41 –1
To find the general form of these triples we must resort to a new technique, for the equation x2 + (x + d)2 = z2 does not lead to a natural
assignment of an index to one of the generators. But since r and s display simple patterns in fixed-a and -b triples, we might suspect that
they will for fixed-d triples also. We notice two (among many) recurrence relations that seem to hold: rn = rn – 1 + sn – 1 and sn = rn + rn – 1.
Substituting for sn – 1 we find
Second-order recurrence relations have solutions of the form rn = kn. Thus, from the recurrence relation,
Both of these values for k satisfy the recurrence, but we want the first and second terms to be 1 and 2 (the r values of the first two triples).
Since a linear combination of the two values for k also satisfies the recurrence, we construct the general solution for rn,
and solve for the constants we introduce by specifying the first two terms:
We find that
Then
(12)
Clearly the difference of xn and yn is always 1. Intuitively, we know that as n gets large, the triples (xn, yn, zn) approach the side lengths of
a right isosceles triangle, the ratios zn / xn and zn / yn approaching √2. It is interesting, however, to examine the ratio sn / rn as n gets large;
one finds that not only does this ratio also approach √2, but sn / rn is the nth continued fraction convergent to √2. This connection becomes
apparent when we approach the solution of |x – y| = 1 triples another way and obtain a Pell equation, the solutions of which are these
convergents:
or
Because the sequence sn / rn are the continued fraction convergents to √2, rn and sn are relatively prime. Moreover, s is odd, and so r and s
generate a primitive triple.
When d ≠ 1, the situation is slightly more complicated. Take d = 7 for example. The first few triples are:
x y z r s x–y
5 12 13 2 1 –7
15 8 17 1 3 7
55 48 73 3 5 7
65 72 97 4 5 –7
297 304 425 8 11 –7
403 396 565 9 13 7
1755 1748 2477 19 27 7
2325 2332 3293 22 31 –7
10205 10212 14437 46 65 –7
13575 13568 19193 53 75 7
At first glance it appears that these r and s values hardly form nice recurrence relations. But in fact they do; there are two "threads" of the
same relation (with different initial values) running through these triples, more easily seen when they are sorted:
x y z r s x–y x y z r s x–y
5 12 13 2 1 –7 15 8 17 1 3 7
55 48 73 3 5 7 65 72 97 4 5 –7
297 304 425 8 11 –7 403 396 565 9 13 7
1755 1748 2477 19 27 7 2325 2332 3293 22 31 –7
10205 10212 14437 46 65 –7 13575 13568 19193 53 75 7
(13)
In general, x – y = s2 – 2r2, and the only numbers of this form, for r and s relatively prime and s odd, are those whose prime factors all
satisfy p ≡ ±1 mod 8. These primes comprise the sequence 7, 17, 23, 31, 41, 47, 71, 73, 79, 89, 97,... As representations as a sum of two
squares were counted by factoring over Z[i] in Section III, we can count "fundamental" representations of a given number as s2 – 2r2 = (s
+ r√2) (s – r√2) by factoring over Z[√2]. For example, –1 = 12 – 2 · 12. The ring Z[√2] has infinitely many units, given by ±(1 + √2)n for
integers n. Call a representation s2 – 2r2 fundamental if s ≤ r or s ≥ 2r. Each fundamental representation s12 – 2r12 gives rise to a thread of
triples generated by sn + rn√2 = (s1 + r1√2) (1 + √2)n for nonnegative integers n. Each prime factor contributes two fundamental solutions,
so we have the following result.
Proposition 2 Let d be a natural number whose prime factors all satisfy p ≡ ±1 mod 8. Then the number of fundamental representations of
d in the form s2 – 2r2 for positive integers r and s is 2ω(d), where ω(d) is the number of distinct prime factors of d.
(Alternatively, we could have considered sequences of triples that are infinitely long in both the positive and negative directions. In this
case, there are 2ω(d) – 1 (double-sided) threads for a given d, and the case d = 1 must be separated from the others (since it still has only one
thread, which is redundant). In this setup, however, we obtain triples with negative legs.)
Each fundamental solution (r1, s1) gives rise to the sequence of triples
For example, let d = 2737 = 7 · 17 · 23. The fundamental representations for these prime factors are
Thus 2737 has the following fundamental representations (where we divide each product by a power of 1 + √2 to obtain fundamental
representations, in this case the first power):
References
Relevant links: