← A-level

Number theory

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.

Plimpton 322 — a Babylonian cuneiform clay tablet listing Pythagorean triples, c. 1800 BCE
Plimpton 322, c. 1800 BCE. Columbia University Libraries. Public domain.

The three matrices

A-level Further Maths — Further Pure (compulsory)Edexcel (Core Pure 1)AQA (Further Pure 1)OCR (Pure Core 1)OCR MEI (Core Pure A)

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.

(3, 4, 5)(5, 12, 13)(21, 20, 29)(15, 8, 17)(7, 24, 25)(55, 48, 73)(45, 28, 53)(39, 80, 89)(119, 120, 169)(77, 36, 85)(33, 56, 65)(65, 72, 97)(35, 12, 37)(9, 40, 41)(105, 88, 137)(91, 60, 109)(105, 208, 233)(297, 304, 425)(187, 84, 205)(95, 168, 193)(207, 224, 305)(117, 44, 125)(57, 176, 185)(377, 336, 505)(299, 180, 349)(217, 456, 505)(697, 696, 985)(459, 220, 509)(175, 288, 337)(319, 360, 481)(165, 52, 173)(51, 140, 149)(275, 252, 373)(209, 120, 241)(115, 252, 277)(403, 396, 565)(273, 136, 305)(85, 132, 157)(133, 156, 205)(63, 16, 65)Gen 1Gen 2Gen 3Matrix AMatrix BMatrix C
The Berggren ternary tree. Every primitive Pythagorean triple appears exactly once. Third-generation labels are displayed radially outward from each node.

An example: applying B to (3, 4, 5)T

A-level Further Maths — Further Pure (compulsory)Edexcel (Core Pure 1)AQA (Further Pure 1)OCR (Pure Core 1)OCR MEI (Core Pure A)

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.

PythonLoading…
Output
Setting up Python environment…
Ready to start?
Book an online lesson
Book a lesson