Recall the equation x²+y²=z² from your school days. We associate this with Pythagoras’ theorem for calculating the sides of a right-angled triangle.
Mathematicians are also interested in natural number (positive integer) solutions to this equation. Such solutions are called Pythagorean Triples.
An example of a Pythagorean Triple is x=3, y=4, z=5 since 3²+4²=5². We can write it more conveniently as (3, 4, 5).
From any Pythagorean Triple, we can construct infinitely many Pythagorean Triples by multiplying through by a number e.g. multiplying (3, 4, 5) by 2 we get (6, 8, 10) which is also a Pythagorean Triple. An exercise for the reader is to show why this always works.
A primitive Pythagorean Triple (x, y, z) is one where x, y, and z are coprime, that is, they have no common factor greater than 1. (3, 4, 5) is primitive.
One challenge is to create a formula for generating Pythagorean Triples.
Here is Euclid’s Formula, where m and n can be any integers of our choice (providing m>n>0) and x, y and z will yield a Pythagorean Triple.
x=2mn
y=m²-n²
z=m²+n²
Example: If m=5 and n=1 then we get the Pythagorean Triple (10, 24, 26). Observe 10²+24²=100+576=676=26².
The following quick check shows that Euclid’s Formula will always work:
x²+y²=4m²n²+(m²-n²)²=4m²n²+m⁴+n⁴-2m²n²=m⁴+n⁴+2m²n²=(m²+n²)²=z²
However, it’s unsatisfying to be given this without understanding where it comes from. Below we will go through a method for deriving Euclid’s Formula from scratch:
Let’s rewrite x²+y²=z² as x²=z²-y²=(z-y)(z+y). This implies x/(z-y)=(z+y)/x.
Note: Division by zero is not an issue because if z=y then this would imply x=0 which is not allowed for a Pythagorean Triple.
However, given x, y and z are positive integers, x/(z-y) is some rational number. Recall the definition of a rational number is any number that can be expressed as m/n where m and n≠0 are integers e.g. 0.5 is a rational number since it’s equal to 1/2.
We can then set x/(z-y)=(z+y)/x=m/n for some integers m and n≠0. We then have the following two equations:
(z-y)/x=n/m — here we took the reciprocal
(z+y)/x=m/n
If we add equations 1 and 2 we get 2z/x=n/m+m/n=(n²+m²)/mn which means we can set x=2mn and z=n²+m².
Similarly, if we subtract equation 2 from 1 then we get 2y/x=m/n-n/m=(m²-n²)/mn which means we can set y=m²-n².
We have then arrived at Euclid’s formula for generating Pythagorean Triples (where m>n>0):
x=2mn
y=m²-n²
z=m²+n²