# Generating Primitive Pythagorean Triplets

That is quite a title to unpack. It has been a while sense I’ve done something mathematical, and this week I found something really, really cool. So, I felt like sharing.

First, a little background. Long ago, Pythagoras came up with a cool theorem that says that if you sum the squared sides of a right triangle, that is the same as the squared length of the hypotenuse. That is, $a^2+b^2=c^2$.

Three values that satisfy this equation are called Pythagorean triplets. Many of us are familiar with the triplet (3,4,5). It can generate many others by multiplying all of the sides by any number. For example, we can create (6,8,10) and (9,12,15) using the multipliers 2 and 3, respectively.

While (3,4,5) is a primitive Pythagorean triplet, (6,8,10) and (9,12,15) are not, as they were generated by another.

### The Magic Matrices

Last week, I stumbled upon these three amazing matrices that generate primitive Pythagorean triplets. I’ve never seen such a thing before in all my years of studying math, so I was compelled to share. Here are the matrices.

$U = \left[\begin{array}{ccc} 1 & 2 & 2 \\ -2 & -1 & -2 \\ 2 & 2 & 3 \end{array} \right]$
$A = \left[\begin{array}{ccc} 1 & 2 & 2 \\ 2 & 1 & 2 \\ 2 & 2 & 3 \end{array} \right]$
$D = \left[\begin{array}{ccc} -1 & -2 & -2 \\ 2 & 1 & 2 \\ 2 & 2 & 3 \end{array} \right]$

Now, check out what happens when we multiply [3,4,5] by any of these matrices. I will write them down and explain how they are obtained.

$[3,4,5]U = [5,12,13]$, $[3,4,5]A = [21,20,29]$, and $[3,4,5]D = [15,8,17]$

What? You get other primitive triplets?!? Cool. (Notice that $5^2+12^2=13^2$, $20^2+21^2=29^2$ and $8^2+15^2=17^2$.)

To understand how to multiply matrices, you must be able to pat your head and rub your stomach at the same time. As we move across the row [3,4,5] we must go down each of the columns of U. So, when finding the first entry of $[3,4,5]U$ we calculate $3(1)+4(-2)+5(2) = 5$. The second entry goes down the 2nd column of U, which is $3(2)+4(-1)+5(2) =12$. The third entry is $3(2)+4(-2)+5(3)=13$. The math is analogous for the other matrices.

### The Really, Really, Cool Part

This creates an infinite tree of primitive Pythagorean triplets. Note how the [3,4,5] triplet generated 3. Well, each of those three generate 3 in the same way, and so on, forever.

Maybe more interesting: This infinite tree is exhaustive of primitive Pythagorean triplets. That means any primitive Pythagorean triplet is a member of this tree.

Of course, I’ve been playing like crazy on R and generating all kinds to see what I can learn. Here was one fun fact I found in my play time. Each of these triplets represents a right triangle, and the sum of the triplet represents a perimeter. The smallest pair of primitive triangles with the same perimeter I found were (364, 627, 725) and (195, 748, 773).

### How I Found This Result

When I need a challenge, I often look to Project Euler for a really difficult problem. Problem 75 is about Singular Integer Right Triangles. This requires a lot of knowledge about Pythagorean triplets.

The article I found that gave all the results that I’ve shared was on Wolfram MathWorld.