Pythagorean triples (a² + b² = c²)

Many people learn in math class about Pythagorean triples, meaning 3 positive integers, a, b, and c, where a < b < c, which represent the lengths of the sides of a right triangle and fit the equation:

a² + b² = c²

Probably the most commonly known example is a = 3, b = 4, c = 5, but two other of the more commonly known such triples are 5, 12, 13 and 7, 24, and 25.

What many people don't know is that there are an infinite number of these Pythagorean triples, and they can be straightforwardly generated as described below.

Choose two positive integers, u and v, that have no common divisors. That is, there is no integer greater than 1 which is a factor of both u and v. Another requirement is that one of u and v is even and the other is odd. You can then generate a, b, and c Pythagorean triples using the following formulas:

a (or b) = u² - v²
b (or a) = 2uv
c        = u² + v²

Sometimes u² - v² > 2uv, sometimes u² - v² < 2uv. Since we have dictated that a < b < c as part of our initial conditions, only c's value in terms of u and v is the same in all cases.

Some sample values:
  u    v      a    b    c
2 1 3 4 5
3 2 5 12 13
4 3 7 24 25
4 1 15 8 17
5 2 21 20 29

The derivation of the above formulas is an interesting part of number theory and significantly longer than this explanation. There is a nice treatment of it in Harold Stark's book, An Introduction to Number Theory.

Ken Ho's home page