The tree of primitive Pythagorean triples is an infinite family tree with 3-4-5 at the root, in which every triple has exactly three children, found by multiplying it by three fixed matrices. First published by B. Berggren in 1934, and published again by F. J. M. Barning (1963) and A. Hall (1970), it contains every primitive triple exactly once.
So the Berggren tree, also called the Barning or Hall tree, is a second complete way to generate primitive triples, alongside Euclid's formula. Unlike Euclid's formula, it needs no choices: each triple simply produces the next generation.
The three matrices
Write a primitive triple as a column (a, b, c) with the odd leg first, so a is odd and b is even. (Exactly one leg of a primitive triple is even, so this is always possible.) The three Berggren matrices are:
Multiplying a matrix by a column just means: each row of the matrix tells you how to mix a, b and c. The row 2, −1, 2, for example, means "2a − b + 2c". Written out without matrices, the three children of (a, b, c) are
A: (a − 2b + 2c, 2a − b + 2c, 2a − 2b + 3c)B: (a + 2b + 2c, 2a + b + 2c, 2a + 2b + 3c)C: (−a + 2b + 2c, −2a + b + 2c, −2a + 2b + 3c)You don't need to know anything about matrices to use the tree: these nine little formulas are all there is.
How to compute the children of a triple
Example: the children of 5-12-13
Substitute a = 5, b = 12, c = 13 into each line:
A: (5 − 24 + 26, 10 − 12 + 26, 10 − 24 + 39) = (7, 24, 25)B: (5 + 24 + 26, 10 + 12 + 26, 10 + 24 + 39) = (55, 48, 73)C: (−5 + 24 + 26, −10 + 12 + 26, −10 + 24 + 39) = (45, 28, 53)The children are 7-24-25, 55-48-73 and 45-28-53. Check the middle one: 552 + 482 = 3025 + 2304 = 5329 = 732.
Try one yourself before opening the solution.
Find the three children of 21-20-29
A: (21 − 40 + 58, 42 − 20 + 58, 42 − 40 + 87) = (39, 80, 89)B: (21 + 40 + 58, 42 + 20 + 58, 42 + 40 + 87) = (119, 120, 169)C: (−21 + 40 + 58, −42 + 20 + 58, −42 + 40 + 87) = (77, 36, 85)The children are 39-80-89, 119-120-169 and 77-36-85, all primitive.
Keep the odd leg firstIf you feed in the legs the other way round, for example (4, 3, 5), matrices A and C swap roles: A then gives (8, 15, 17), which is the C-child 15-8-17 with its legs reversed. The tree still works, but your answers won't match the tables here.
The tree to depth 3
Applying the three matrices again and again builds the tree level by level. Level k has 3k triples, so the first four levels hold 1 + 3 + 9 + 27 = 40 different primitive triples:
The same tree as a table, with the path from the root to each triple, reading the matrices in the order they are applied:
| Path from the root | Triple | A-child | B-child | C-child |
|---|---|---|---|---|
| root | 3-4-5 | 5-12-13 | 21-20-29 | 15-8-17 |
| A | 5-12-13 | 7-24-25 | 55-48-73 | 45-28-53 |
| B | 21-20-29 | 39-80-89 | 119-120-169 | 77-36-85 |
| C | 15-8-17 | 33-56-65 | 65-72-97 | 35-12-37 |
| A → A | 7-24-25 | 9-40-41 | 105-88-137 | 91-60-109 |
| A → B | 55-48-73 | 105-208-233 | 297-304-425 | 187-84-205 |
| A → C | 45-28-53 | 95-168-193 | 207-224-305 | 117-44-125 |
| B → A | 39-80-89 | 57-176-185 | 377-336-505 | 299-180-349 |
| B → B | 119-120-169 | 217-456-505 | 697-696-985 | 459-220-509 |
| B → C | 77-36-85 | 175-288-337 | 319-360-481 | 165-52-173 |
| C → A | 33-56-65 | 51-140-149 | 275-252-373 | 209-120-241 |
| C → B | 65-72-97 | 115-252-277 | 403-396-565 | 273-136-305 |
| C → C | 35-12-37 | 85-132-157 | 133-156-205 | 63-16-65 |
The hypotenuses grow quickly. The smallest at depth k lies on the all-A branch and equals 2k2 + 6k + 5 (5, 13, 25, 41, …), while the largest lies on the all-B branch: 5, 29, 169, 985, each about 5.83 times the one before. That ratio tends to 3 + 2√2 ≈ 5.828. So the tree is not in order of size: to list triples by hypotenuse, use the list of Pythagorean triples instead.
Patterns along the three edges
Following the same matrix over and over traces out the edges of the tree, and each edge is a famous family:
| Depth | Always A (c − b = 1) | Always B (legs differ by 1) | Always C (c − a = 2) |
|---|---|---|---|
| 0 | 3-4-5 | 3-4-5 | 3-4-5 |
| 1 | 5-12-13 | 21-20-29 | 15-8-17 |
| 2 | 7-24-25 | 119-120-169 | 35-12-37 |
| 3 | 9-40-41 | 697-696-985 | 63-16-65 |
| 4 | 11-60-61 | 4059-4060-5741 | 99-20-101 |
| 5 | 13-84-85 | 23661-23660-33461 | 143-24-145 |
- Always A gives the triples whose hypotenuse is one more than the even leg: 5-12-13, 7-24-25, 9-40-41 and so on. These are exactly the triples from Pythagoras' formula, (2k + 1, 2k2 + 2k, 2k2 + 2k + 1).
- Always C gives the triples whose hypotenuse is two more than the odd leg: 15-8-17, 35-12-37, 63-16-65. These come from Plato's formula with even k; the even leg goes up by 4 each time.
- Always B gives triangles whose legs differ by 1: 21-20-29, 119-120-169, 697-696-985. They get closer and closer to the isosceles right triangle, and their hypotenuses 5, 29, 169, 985 are every other Pell number (0, 1, 2, 5, 12, 29, 70, 169, …, in which each term is twice the previous one plus the one before).
The same tree with Euclid's m and n
Every primitive triple comes from Euclid's formula with a unique pair (m, n). In terms of those two numbers, the matrices become even simpler:
A: (m, n) → (2m − n, m)B: (m, n) → (2m + n, m)C: (m, n) → (m + 2n, n)The root 3-4-5 is (2, 1). Its children are (3, 2), (5, 2) and (4, 1), which Euclid's formula turns into 5-12-13, 21-20-29 and 15-8-17, exactly as before. Along the all-B branch the pairs are (2, 1), (5, 2), (12, 5), (29, 12): consecutive Pell numbers. This version is the easiest one to run in your head.
Walking back up: the parent of a triple
The process also runs backwards. For any primitive triple other than 3-4-5, with the odd leg first, its parent is
parent = ( |a + 2b − 2c|, |2a + b − 2c|, 3c − 2a − 2b )The signs inside the absolute values tell you which matrix produced the triple: if both are positive it is a B-child; if the first is negative it is a C-child; if the second is negative it is an A-child.
Example: where is 33-56-65 in the tree?
33 + 112 − 130= 1566 + 56 − 130= −8195 − 66 − 112= 17The second value is negative, so 33-56-65 is the A-child of 15-8-17. Repeat for 15-8-17: 15 + 16 − 34 = −3, 30 + 8 − 34 = 4, 51 − 30 − 16 = 5. The first value is negative, so 15-8-17 is the C-child of 3-4-5.
The path from the root is C, then A. You can find 33-56-65 in the table above under "C → A".
Applied to 3-4-5 itself, the formula gives (1, 0, 1), which is not a triangle: the root has no parent.
Why every primitive triple appears exactly once
Here is a sketch of the proof, in five steps.
- Children are Pythagorean triples. Each matrix keeps the quantity a2 + b2 − c2 unchanged. For B, expanding the squares gives (a + 2b + 2c)2 + (2a + b + 2c)2= 5a2 + 5b2 + 8c2 + 8ab + 12ac + 12bc(2a + 2b + 3c)2= 4a2 + 4b2 + 9c2 + 8ab + 12ac + 12bc and the difference is exactly a2 + b2 − c2. A and C work the same way. So if a2 + b2 − c2 = 0 for the parent, it is 0 for every child.
- Children are primitive, with positive sides and the odd leg first. All three matrices have whole-number inverses (their determinants are 1 or −1), so any common factor of a child would also divide its parent. Every entry is positive because c is bigger than each leg, and working with remainders mod 2 shows the odd leg stays odd.
- Every primitive triple except 3-4-5 has a parent, given by the formula above, and the parent's hypotenuse is smaller: 3c − 2a − 2b < c because a + b > c (the two legs together are longer than the hypotenuse), and it is positive because a + b is at most √2 c, which is less than 1.5c. A short calculation shows the formula only produces a zero side for 3-4-5 itself.
- The parent is unique. Which matrix made a triple depends only on its shape, as the figure below shows, so no triple can be the child of two different parents, and the three children of one parent are always different.
- Every chain of parents ends at the root. The hypotenuse drops at every step, and whole numbers cannot drop forever, so climbing up must stop, and the only place it can stop is 3-4-5. Every primitive triple is therefore reached from the root by exactly one path.
The two dividing angles are not random: 36.87° and 53.13° are the angles of the 3-4-5 triangle itself, and the root sits exactly on the border between the A and B wedges. We also checked the result by computer: growing the tree with every hypotenuse up to 20,000 produces 3,186 triples with no repeats, exactly the same 3,186 primitive triples that a brute-force search finds.
History and other trees
The tree was first published by the Swedish mathematician B. Berggren in 1934, in a paper titled "Pytagoreiska trianglar". The Dutch mathematician F. J. M. Barning described it again in 1963, and A. Hall wrote about it in English in 1970 in "Genealogy of Pythagorean Triads", which is why it goes by several names. It is not the only tree of its kind: H. Lee Price published a different set of three matrices in 2008 that also generates every primitive triple exactly once from 3-4-5, in a different order. (The Pythagoras tree, a fractal made of squares, is something else entirely.)
For a quick way to produce lots of triples without matrices, use the Pythagorean triples generator, and for the bigger picture, start at the Pythagorean triples hub.
Frequently asked questions
Who discovered the tree of Pythagorean triples?
B. Berggren published it in 1934. F. J. M. Barning (1963) and A. Hall (1970) published it again later, so you will also see it called the Barning tree or Hall's tree, and the three matrices called the Barning matrices.
Does the tree include non-primitive triples like 6-8-10?
No. Every triple in the tree is primitive, because the matrices preserve primitivity. To get the non-primitive triples, multiply the triples in the tree by 2, 3, 4 and so on: 6-8-10 is 2 × (3-4-5).
How many triples are there at each level?
Level k has 3k triples, so levels 0 to k together hold 3k + 1 − 1 over 2. That is 40 triples down to level 3 and 121 down to level 4.
How do I find where a given triple is in the tree?
Put the odd leg first, then use the parent formula (|a + 2b − 2c|, |2a + b − 2c|, 3c − 2a − 2b) repeatedly until you reach 3-4-5, noting the signs at each step. Reading the matrices from the root downward gives the triple's address, such as C then A for 33-56-65.
Why do the matrices work?
Each one leaves the expression a2 + b2 − c2 unchanged, so it turns solutions of a2 + b2 = c2 into new solutions. They also have whole-number inverses, which is what guarantees that primitive triples stay primitive and that you can always climb back up.
Sources and further reading
- B. Berggren, "Pytagoreiska trianglar" (in Swedish), Elementa: Tidskrift för elementär matematik, fysik och kemi 17 (1934), 129–139.
- F. J. M. Barning, "Over pythagorese en bijna-pythagorese driehoeken en een generatieproces met behulp van unimodulaire matrices" (in Dutch), Mathematisch Centrum Amsterdam, report ZW-011 (1963).
- A. Hall, "Genealogy of Pythagorean Triads", The Mathematical Gazette 54, no. 390 (1970), 377–379.
- H. Lee Price, "The Pythagorean Tree: A New Species" (2008), arXiv:0809.4324.
- Tree of primitive Pythagorean triples, Wikipedia.
Keep exploring
- TriplesPrimitive Pythagorean TriplesWhat makes a Pythagorean triple primitive, the quick gcd test, why exactly one leg is even, and a full proof that Euclid's formula gives every primitive triple.
- TriplesEuclid's Formula for Pythagorean TriplesEuclid's formula a = m² − n², b = 2mn, c = m² + n² explained: two derivations, a table for m ≤ 8, when the triple is primitive, and four other classic generators.
- TriplesPythagorean TriplesWhat Pythagorean triples are, the common ones to know (3-4-5, 5-12-13, 8-15-17…), how to generate and recognize them, and the patterns every triple shares.
- TriplesList of Pythagorean TriplesComplete, computer-checked list of Pythagorean triples: all 52 with hypotenuse up to 100 and all 47 primitive triples up to 300, with m, n, perimeter and area.
- CalculatorsPythagorean Triples GeneratorGenerate every Pythagorean triple up to any hypotenuse, use Euclid's formula, check whether three numbers form a triple, or find all triples with a number.
- TriplesFermat's Last TheoremFermat's Last Theorem says aⁿ + bⁿ = cⁿ has no whole-number solutions for n > 2: Fermat's margin note, his proof for n = 4, Wiles's proof, why squares differ.