Finding something worth knowing…

Science

Triangular numbers, the stacked dots behind a famous schoolboy legend

Arrange dots in rows of one, two, three and so on until they form a neat equilateral triangle, and the total is a triangular number. A popular tale says young Gauss found their shortcut formula as a boy. The story is probably apocryphal, and he was certainly not the first to find it.

The shortcut is n times n plus one, divided by two. A neat picture shows why: copy the triangle of dots, flip it, and fit the two together into a rectangle n dots by n plus one. The triangle is exactly half. The same count also tells you how many different pairs can be picked from n plus one objects. The Irish monk Dicuil described the formulas around 816, and some historians trace the idea to the Pythagoreans in the 5th century BC.

Programmers meet a practical wrinkle. Multiplying first and halving afterwards can overflow a small integer: the 20th triangular number, 210, fits in an 8-bit byte, but the intermediate product 420 does not. The fix is to halve whichever of n or n plus one is even before multiplying.

The numbers link to many other shapes. Add two neighbouring triangular numbers and you always get a perfect square, a fact credited to Theon of Smyrna. Double one and you get a pronic number, a product of two consecutive integers. Summing the first several triangular numbers produces tetrahedral numbers, counts of balls in a triangular pyramid. Every other triangular number is also hexagonal.

Some coincidences run deeper. Infinitely many triangular numbers are also perfect squares, beginning 1, 36 and 1225. And squaring the nth triangular number gives exactly the same result as adding up the cubes of every whole number from 1 to n. Triangular numbers are the simplest figurate numbers, cousins of pentagonal and other polygon-based counts.

Source: Triangular number

Related

More in Science · All topics