Finding Pythagorean Triples
I have previously posted about a proof of the Pythagorean equation, a² + b² = c². However, is there a good way to find whole number solutions, otherwise known as Pythagorean triples? These are solutions like 3² + 4² = 5² or 5² + 12² = 13².
Of course there is.
I’ll explain all the workings out to show you why this works, but I will summarise the recipe at the end.
This method will find primitive solutions, such as 5² + 12² = 13², i.e. the lowest unique triplet of numbers. Multiples of these primitive solutions are easy to generate. An example of this is: 10² + 24² = 26² or 15² + 36² = 39²
The Derivation
We seek to find solutions of a² + b² = c² such that a, b and c are all integers. We also want them to be in their simplest form.
We cannot have two of a, b, and c even, as this would imply the other term is even. If all were even, then a,b, and c could all be divided by 2, and our solution would not be primitive.
Thus, I will specify that ‘a’ is odd (if we have a solution like 4² + 3² = 5², we just swap the roles of a and b so that a=3)
Let’s rearrange the equation:
b² = c² - a²
We can factorise this to get:
b² = (c - a) (c+a)
This in turn can be rearranged:
b/(c-a) = (c+a)/b
Now, we know that a, b and c are all whole numbers, so c-a and c+a are all whole numbers.
Let’s define two new numbers, m and n such that:
b/(c-a) = m/n
This can be rearranged:
(c-a)/b = n/m
or
c/b - a/c = n/m (eqn1)
As we already know that:
b/(c-a) = (c+a)/b
As the left hand side equals m/n, so does the right.
Thus, we can also write:
(c+a)/b = m/n.
This can be rearranged to say
c/b + a/b = m/n (eqn2)
The two labelled equations can be combined by addition. If we do that, we find the following result:
c/b = ½(m/n + n/m)
A little algebra yields this:
c/b = (m² + n²)/2mn
Now, if we subtract eqn 1 from eqn 2 we get:
a/b = (m² - n²)/2mn
This gives us our recipe.
The Recipe
We can generate pythagorean triples by picking two numbers, m and n and plugging them into these formulae:
a = m² - n²
b = 2mn
c = m² + n²
Here are the caveats:
If you want positive values for a, b, c then m and n are both positive and m>n.
Additionally, One of m and n is even, the other odd.
Also, m and n should be co-prime.
The caveats explained
m and n are both coprime, i.e. no common divisors except 1.
If they are not, then we don’t get a primitive solution. This is because if m and n are coprime, then n÷m can be simplified, and a,b,c will be a multiple of a solution already obtained.
This means, trivially, than m and n cannot both be even.
If both m and n were odd, then this would force a to be even.
This condition is because a = m² - n². If we square an odd number, we get an odd number. And subtracting one odd number from another ALWAYS gives an even number. As b=2mn, b will always be even, and we cannot have a and b even as that means c will be even, and we won’t have a primitive Pythagorean triple as all three numbers are a multiple of 2.
These conditions combined mean that one, and only one, of m and n should be even.
You are at liberty to ignore these caveats and use the formulae anyway - if you do, then you will not get a primitive, instead you’ll get multiples of primitive mixed in).
Using the equation (to find primitives)
Pick an integer, call it m.
Write a list of all values that n from 1 to m-1.
Eliminate any even-even or odd-odd pairings of m,n
Eliminate any values of n that are coprime with m
For the values of n you have left, generate a, b, and c using the recipe
a = m² - n²
b = 2mn
c = m² + n²
Here are a few Pythagorean triples that I’ve generated, you will notice that the one in the thumbnail is from m=7, n=2..
m=3, n=1 is missing, for instance, as both m and n are odd (this generates the 6, 8, 10 triangle - a scaled up 3, 4, 5)
More Maths