Lably
Skip to content

Triangular number

Figurate number

  • 10 min read
  • 6 chapters

Related on Lably

Through Equilateral triangle, Binomial coefficient and Mathematical induction

Triangular numbers are the simplest kind of figurate number – figurate numbers generalize their concept to other two-dimensional polygons, such as the pentagonal numbers, as well as higher-dimensional polyhedra, such as the tetrahedral numbers. Taking T0=0 (see empty sum), the first few terms are

0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210...

(sequence A000217 in the OEIS)

Formula

The triangular numbers are given by the following explicit formulas:

Tn=∑k=1nk=1+2+⋯+n=n2+n(n+1)2=n(n+1)2=(n+12)

where (n+12) is notation for a binomial coefficient. It represents the number of distinct pairs that can be selected from n + 1 objects, and it is read aloud as "n plus one choose two".

The fact that the nth triangular number equals n(n+1)/2 can be illustrated using a visual proof. For every triangular number Tn, imagine a "half-rectangle" arrangement of objects corresponding to the triangular number, as in the figure below. Copying this arrangement and rotating it to create a rectangular figure doubles the number of objects, producing a rectangle with dimensions n×(n+1), which is also the number of objects in the rectangle. Clearly, the triangular number itself is always exactly half of the number of objects in such a figure, or: Tn=n(n+1)2. The example T4 follows:

2T4=4(4+1)=20 (green plus yellow) implies that T4=4(4+1)2=10 (green).

This formula can be proven formally using mathematical induction. It is clearly true for 1:

T1=∑k=11k=1(1+1)2=22=1.

Now assume that, for some natural number m, Tm=∑k=1mk=m(m+1)2. We can then verify it for m+1: ∑k=1m+1k=∑k=1mk+(m+1)=m(m+1)2+m+1=m2+m2+2m+22=m2+3m+22=(m+1)(m+2)2,

so if the formula is true for m, it is true for m+1. Since it is clearly true for 1, it is therefore true for 2, 3, and ultimately all natural numbers n by induction.

An apocryphal story claims that the German mathematician Gauss found this relationship in his early youth, by multiplying ⁠n/2⁠ pairs of numbers in the sum by the values of each pair n + 1. In any case, Gauss was not the first to discover this formula, and some find it likely that its origin goes back to the Pythagoreans in the 5th century BC. The two formulas were described by the Irish monk Dicuil in about 816 in his Computus. An English translation of Dicuil's account is available.

Occasionally it is necessary to compute large triangular numbers where the standard formula t = n*(n+1)/2 would suffer integer overflow before the final division by 2. For example, T20 = 210 < 256, so will fit into an 8-bit byte, but not the intermediate product 420. This can be solved by dividing either n or n+1 by 2 before the multiplication, whichever is even. This does not require a conditional branch if implemented as t = (n|1) * ((n+1)/2). If n is odd, the binary OR operation n|1 has no effect, so this is equivalent to t = n * ((n+1)/2) and thus correct. If n is even, setting the low bit with n|1 is the same as adding 1, while the 1 added before the division is truncated away, so this is equivalent to t = (n+1) * (n/2) and also correct.

Sign in to keep reading

5 more chapters are free with a Lably account.

More in Topics in mathematics