# Pythagorean triples… and so on

Now, here’s a real oldie but goodie: Find positive integers x, y, and z such that

x2 + y2 = z2 .

Of course, the three sides of any right triangle will satisfy that equation, but few right triangles have all three sides of integer length. The most well known example of such a Pythagorean triple is (3,4,5): 32+42=9+16=25=52. There are an infinite number of others, of course: if you have one triple (x,y,z) then for any positive integer n, (nx,ny,nz) is also a triple. But that’s not very interesting. However, there are an infinite number of primitive triples — ones in which x,y, and z have no common factor.

I think the best way to approach Pythagorean triples is to start with a simple and not at all obviously relevant fact: If two integers a and b have the same parity (i.e., both are even or both are odd), then there exist two integers c and d such that

a = c + d and
b = cd

Specifically, c is the arithmetic mean of a and b, (a+b)/2, and d is half their difference, (ab)/2. Of course, if a and b did not have the same parity (if one was even and the other odd), their sum and difference would be odd and c and d would not be integers. Since they do have the same parity, their sum and difference is even and c and d are integers. Furthermore, it’s clear that if a and b are odd, then c and d must have opposite parity; if they’re even, c and d must have the same parity.

So what does this have to do with Pythagorean triples? Well…

First of all, in a triple, can x and y both be odd? If they are, then their squares are too, and the sum of their squares must be even but not divisible by 4: (2m+1)2+(2n+1)2 = 4(m2+n2+m+n)+2. But if z is odd, z2 is odd, and if it’s even, z2 is divisible by 4. Therefore x and y cannot both be odd. Of course since (3,4,5) and (6,8,10) are both triples, we can see x and y can both be even (and then z will be even), or they can be opposite parity (and z will be odd.) Either way, at least one of x and y will be even (let’s say y must be even) and the other (let’s say x) will have the same parity as z.

Where to go from here? Well, x and z have the same parity, so let’s write them as sums and differences of two integers — this time we call them u and v:

x = uv and
z = u + v

But we can rewrite x2 + y2 = z2 as

y2 = z2x2
= (z+x)(zx)
= 4uv

Now if y2 is a perfect square, that means each of its prime factors occurs to an even number of powers. To get y2 = 4uv, any prime factors of u occurring with an odd number of powers must also occur in v with an odd number of powers, and vice versa. In other words, u and v must each be a product of a square number and a factor common to both:

u = ab2 and
v = ac2 .

Then 4uv = 4a2b2c2 = a perfect square as required. We also know that, since x is positive, u>v and therefore b>c.

Summarizing: all Pythagorean triples are of the form

x = a(b2c2)
y = 2abc
z = a(b2+c2)

where a, b, and c are positive integers with b > c.

For a triple to be primitive, x and y (and therefore z) must have no common factors. That means a = 1, b and c must have no common factors, and b and c must have opposite parity (else x and y would both be even).

It’s amusing to consider some particular types of triples. For instance, it’s clear that the difference between z and x is 2ac2. This means they’ll differ by their minimum amount, 2, only if a = c = 1; these triples are (3,4,5), (8,6,10), (15,8,17), (24,10,26)…. For b even (odd), these are (are not) primitive.

y and z can differ by 1, if 2bc+1 = b2 + c2. (a, of course, must be 1.) Rewriting, b2 – 2bc + c2 = (bc)2 = 1, so b = c+1. These triples are (3,4,5), (5,12,13), (7,24,25), (9,40,41)…

x and y can differ by 1, if 2bc±1 = b2c2. (Again, a must be 1.) This is a Pell equation, much trickier to deal with than the foregoing. I’ll merely point out that, if x and y are large and differ by unity, then a triangle with sides x, y, and z is nearly isoceles, so that x/z or y/z, or better yet (x+y)/2z, is an excellent rational approximation to the inverse of the square root of 2. That might lead you to suspect a connection between Pell equations and continued fractions. Indeed there is such a connection, and these triples are numerically related to the continued fraction expansion of the square root of 2. For more on Pell equations I refer you to this MathWorld page.

## Another approach

(See http://mathforum.org/pcmi/hstp/sum2001/wg/number…/session13.pdf.) Consider the Gaussian integer p = b + ci where b and c are integers and i is √–1. The square of p is

p2= (b + ci)2 = (b2c2) + 2bci.

The norm of p2 is

|p2| = (p2)(p2)* = (b2 – c2) 2 + 4b2c2.

But the norm of p2 equals the square of the norm of p:

|p2| =|p|2 = (b2c2) 2 = (b2 – c2) 2 + 4b2c2

which gives us x = (b2 – c2), y = 2bc, z = (b2c2) as a Pythagorean triple. It’s the same formula as before (for a = 1) derived differently.

## Triples II

Let’s consider some generalizations of the Pythagorean triple concept, starting with solutions to:

x2 + y2 = nz2

where of course n as well as x, y, and z are integers. I don’t have much to say about this for now, other than a few comments for n = 2. In that case x and y have the same parity so we can write

x = uv
y = u + v

and

x2 + y2 =
(u2 – 2uv + v2) + (u2 + 2uv + v2) =
2(u2 + v2) = 2z2

Then u, v, and z are a Pythagorean triple. We can illustrate this graphically as follows: Here DAB and DCB are two right triangles, with integer legs, and with the latter isoceles: CD = BC. Then AB2 + AD2 = 2 CD2. Now drop perpendiculars CE to AB and DF to CE. Right triangles BEC and CFD have congruent hypoteneuses, and since angles DCF and BCE sum to a right angle, angles BCE and CDF must be congruent; therefore triangles BEC and CFD are congruent. Then AB = DF + EB and AD = CECF = DFEB. Since AB and AD are integers, DF and EB must be integers or half integers, and the latter is ruled out by their being legs of right triangles with integer hypoteneuses. Therefore DF, EB, and CD are a Pythagorean triple, and the Cartesian coordinates of C (taking A as the origin) are integers (as are, of course, those of all the other labelled points).

For example, if CF = 3, DF = 4, and CD = 5, then the coordinates of all points are:

A = (0, 0)
B = (7, 0)
C = (4, 4)
D = (0, 1)
E = (4, 0)
F = (4, 1)

The diagonals of the quadrilateral are sqrt (50) and sqrt (32) — not integers, but their product is sqrt (1600) = 40, an integer! As was pointed out in a thread on alt.math.recreational, points A, B, C, and D lie on a circle, and there is a theorem that tells us A, B, C, and D lie on a circle if and only if AC * BD = AD * BC + AB * CD. In this case, the product of the diagonals must be 7*5 + 1*5 = 40.

## Triples III

Another variant on Pythagorean triples is Eisenstein triples, which satisfy

x2 + y2xy = z2 .

Such a triple is the lengths of the sides of a 60-degree triangle, using the law of cosines and cos (60°) = 0.5. For example, a triangle with sides 5, 8 and 7 has a 60 degree angle between the first two sides.

To generate Eisenstein triples we can make use of the number α = –1/2 + √3/2i, which satisfies:

α2 = –α–1
|α| = 1
α + α* = –1

Using these relations you can show z2 = (x+yα)(x+yα*). So now: Proceeding analogously to above where we used Gaussian integers to generate Pythagorean triples, square the number p = a+bα:

p2 = a2 + b2α2 + 2abα = a2 + b2(–α–1) + 2abα
= a2 – b2 + (2abb2)α .

The norm |p2|, after some algebra, turns out to be equal to (a2 – ab + b2)2. But |p2| = |p|2. This then gives us Eisenstein triples: x = a2 – b2, y = 2abb2, z = a2 – ab + b2. For instance, a = 3, b = 2 gives x = 5, y = 8, z = 7.

You can get triples corresponding to integer sides of 120° triangles similarly, using 1/2 + √3/2i.

The Pythagorean triples correspond to points in the plane whose x coordinate, y coordinate, and distance from the origin all are integers.

The obvious generalization to n-dimensional space is the (n+1)ples (x1, x2xn, z) such that

sum(i=1..n) xi2 = z2 .

In the case n = 3, these are quadruples (x, y, z, w). What can we say about them? Well, let’s start again with parity considerations. At least two of x, y, and z — say x and y — must have the same parity. But then z must have the same parity as w. Then we can write x and y as sums and differences of two integers a and b, and z and w as sums and differences of two other integers, c and d. We can then get the relation

a2 + b2 = 2cd.

Obviously this means a and b must have the same parity — meaning x and y must be even.

And that’s about all there is to say. Pick two positive integers a and b<a with the same parity, compute (a2 + b2)/2, then split the result into two factors and call them c and d<c; then x=ab, y=a+b, z=cd, and w=c+d are a solution quadruple. Example: a and b are 12 and 8; then we need factors of (122+82)/2 = 104. We can use c=13, d=8. Then x=12-8=4, y=12+8=20, z=13-8=5, and w=13+8=21. And indeed 42+202+52=241=212. (We also could have used c=26, d=4, or c=104, d=1, et cetera., to get other quadruples.)

This is almost too easy. You can go to quintuples, if you like, but that just adds variables without really making things any more interesting. In fact, there’s a theorem that almost all positive integers can be written as the sum of three squares (possibly including 02) and all positive integers can be written as the sum of four squares. So the “special” nature of Pythagorean triples becomes watered down in higher dimensions.

But there’s still some fun to be had with quadruples of a different nature…

What if we generalize Pythagorean triples to (n+1)ples (x1, x2xn, z) such that

sum(i=1..n) xi2 = (n-1)z2 ?

Why would you want to? Well, it’s not clear that you would; but for n = 3, this is

x2 + y2 + z2 = 2w2 .

And this arises in the following problem: Find three integers such that the sums of any two, and the sum of all three, all are perfect squares. Obviously if two of them sum to x2, another two sum to y2, and the third pair sum to z2, then the sum of all three must be (x2 + y2 + z2)/2 = w2. Find all the solutions of the latter and some of them may give you solutions to the former.

So, OK, that’s some sort of motivation. Once more, consider parity. Take x and y as being the same parity. Then the sum of their squares is even and z must be even to make the sum of all three squares even. But what’s the parity of w? z2 is divisible by 4; x2+y2 is too, if x and y are even, or not, if they’re odd. Therefore the left side is divisible by 4 if and only if x and y are even, and that means w has to have the same parity as x and y.

In that case we can have integers s, t, u, and v such that

w=s+t = u+v
x=st; y = uv .

Then

z2 = 4d2 = 4st + 4uv
= 4(st + u(s+tu))
d2 = st+su+tuu2 .

If t = –u then this becomes

d2 = -2u2

with no real solutions. Therefore t+u is nonzero and we can solve for s getting

s = (d2 + u2tu) / (t+u)
= (d2 + u2 – (pu)u) / p
= (d2 + 2u2) / pu .

Here p = t+u. And this tells us our prescription. Pick positive integers d and u. Compute f = d2 + 2u2 and let positive integer p be one of the factors of f less than sqrt(f). Compute s = f / pu and t = pu. Then the solution quadruples are to be found among

x = st
y = 2ust
z = 2d
w = s+t

I said “to be found among”. This prescription can give negative values for y. (Of course, if you take the absolute value of y, you end up with a solution quadruple in positive integers.) y can also come out to zero. You also can get the same quadruple (in a different order) from different starting values of d, p, and u. So the choices of these parameters do not map onto the positive solution quadruples. But all the solutions are found with this recipe.

For example, take d=10 and u=20. d2 + 2u2 = 900, so a possible value for p is 25. Then s = 900/25-20 = 16. t = 25-20 = 5. Then x=11, y=19,

z=20, and w=21 is a solution quadruple: 112+192+202 = 121+361+400 = 882 = 2(212).

Not all solution quadruples can be solved to get three positive integers which add pairwise or all three to squares, but this one can. It’s simple to solve

l + m = 112
l + n = 192
m + n = 202 .

The result is l = 41, m = 80, n = 320, all three of which sum to 441 = 212.