Pythagorean Triples
Three positive integers a, b, c satisfying a² + b² = c² form a Pythagorean triple. The simplest is (3, 4, 5) — but the family is infinite, and the ancient Babylonians already knew it.
The Babylonian connection
The clay tablet Plimpton 322, dating to around 1800 BCE, lists fifteen Pythagorean triples in cuneiform script. One of them is (12709, 13500, 18541) — numbers far too large to have been discovered by trial and error. Exactly how the Babylonians generated them is still debated by historians of mathematics.
One modern explanation uses three 3×3 matrices — traditionally called A, B, and C — first written down by Berggren in 1934. Starting from any primitive Pythagorean triple, multiplying by combinations of these matrices generates every other primitive triple exactly once.

The three matrices
Each matrix, when applied to a column vector representing a Pythagorean triple, produces a new Pythagorean triple. Together they form a complete ternary tree of all primitive triples.
Starting from (3, 4, 5) and applying each matrix repeatedly produces every primitive Pythagorean triple exactly once — forming the Berggren ternary tree shown below.
An example: applying B to (3, 4, 5)T
Multiplying the column vector representing the (3, 4, 5) triple by B:
We can verify this is indeed a Pythagorean triple:
Reaching the Babylonian triple
The code below checks whether the Babylonian triple (12709, 13500, 18541) can be reached from (3, 4, 5) by the specific sequence B·C·A⁵·B.
Edit the code and press Run Code to execute it in your browser. Python runs locally via Pyodide — no server involved. The first run may take a few seconds while the environment loads.
Setting up Python environment…
