# Triangular number

A triangular number or triangle number counts objects arranged in an equilateral triangle. Triangular numbers are a type of figurate number, other examples being square numbers and cube numbers. The nth triangular number is the number of dots in the triangular arrangement with n dots on each side, and is equal to the sum of the n natural numbers from 1 to n. The first 100 terms sequence of triangular numbers, starting with the 0th triangular number, are
(sequence A000217 in the OEIS)

## Formula

The triangular numbers are given by the following explicit formulas:
$\displaystyle {\begin{aligned}T_{n}&=\sum _{k=1}^{n}k=1+2+\dotsb +n\\&={\frac {n^{2}+n{\vphantom {(n+1)}}}{2}}={\frac {n(n+1)}{2}}\\&={n+1 \choose 2}\end{aligned}}$
where $\textstyle {n+1 \choose 2}$ 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 $n$th triangular number equals $n(n+1)/2$ can be illustrated using a visual proof. For every triangular number $T_{n}$, 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\times (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: $T_{n}={\frac {n(n+1)}{2}}$. The example $T_{4}$ follows:
$2T_{4}=4(4+1)=20$
$T_{4}={\frac {4(4+1)}{2}}=10$
This formula can be proven formally using mathematical induction. It is clearly true for $1$:
$T_{1}=\sum _{k=1}^{1}k={\frac {1(1+1)}{2}}={\frac {2}{2}}=1.$
Now assume that, for some natural number $m$, $T_{m}=\sum _{k=1}^{m}k={\frac {m(m+1)}{2}}$. We can then verify it for $m+1$: ${\begin{aligned}\sum _{k=1}^{m+1}k&=\sum _{k=1}^{m}k+(m+1)\\&={\frac {m(m+1)}{2}}+m+1\\&={\frac {m^{2}+m}{2}}+{\frac {2m+2}{2}}\\&={\frac {m^{2}+3m+2}{2}}\\&={\frac {(m+1)(m+2)}{2}},\end{aligned}}$
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.
The German mathematician and scientist, Carl Friedrich Gauss, is said to have 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. However, regardless of the truth of this story, 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, T$_{20}$ = 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.

## Relations to other figurate numbers

Triangular numbers have a wide variety of relations to other figurate numbers.
Most simply, the sum of two consecutive triangular numbers is a square number, since:
    $T_{n-1}+T_{n}$
    $={\frac {1}{2}}\,n(n-1)+{\frac {1}{2}}\,n(n+1)$
    $={\frac {1}{2}}\,n{\Bigl(n-1)+(n+1){\Bigr )}$
    $=n^{2}$
with the sum being the square of the difference between the two (and thus the difference of the two being the square root of the sum): $T_{n}+T_{n-1}=\left({\frac {n^{2}}{2}}+{\frac {n}{2}}\right)+\left({\frac {\left(n-1\right)^{2}}{2}}+{\frac {n-1{\vphantom {\left(n-1\right)^{2}}}}{2}}\right)=\left({\frac {n^{2}}{2}}+{\frac {n}{2}}\right)+\left({\frac {n^{2}}{2}}-{\frac {n}{2}}\right)=n^{2}=(T_{n}-T_{n-1})^{2}.$
This property, colloquially known as the theorem of Theon of Smyrna, is visually demonstrated in the following sum, which represents $T_{4}+T_{5}=5^{2}$ as digit sums:
${\begin{array}{ccccccc}&4&3&2&1&\\+&1&2&3&4&5\\\hline &5&5&5&5&5\end{array}}$
This fact can also be demonstrated graphically by positioning the triangles in opposite directions to create a square:
The double of a triangular number, as in the visual proof from the above section § Formula, is called a pronic number.
There are infinitely many triangular numbers that are also square numbers; e.g., 1, 36, 1225. Some of them can be generated by a simple recursive formula: $S_{n+1}=4S_{n}\left(8S_{n}+1\right)$ with $S_{1}=1.$
All square triangular numbers are found from the recursion $S_{n}=34S_{n-1}-S_{n-2}+2$ with $S_{0}=0$ and $S_{1}=1.$
Also, the square of the nth triangular number is the same as the sum of the cubes of the integers 1 to n. This can also be expressed as $\sum _{k=1}^{n}k^{3}=\left(\sum _{k=1}^{n}k\right)^{2}.$
The sum of the first n triangular numbers is the nth tetrahedral number: $\sum _{k=1}^{n}T_{k}=\sum _{k=1}^{n}{\frac {k(k+1)}{2}}={\frac {n(n+1)(n+2)}{6}}.$
More generally, the difference between the nth m-gonal number and the nth (m + 1)-gonal number is the (n − 1)th triangular number. For example, the sixth heptagonal number (81) minus the sixth hexagonal number (66) equals the fifth triangular number, 15. Every other triangular number is a hexagonal number. Knowing the triangular numbers, one can reckon any centered polygonal number; the nth centered k-gonal number is obtained by the formula $Ck_{n}=kT_{n-1}+1$
where T is a triangular number.
The positive difference of two triangular numbers is a trapezoidal number.
The pattern found for triangular numbers $\sum _{n_{1}=1}^{n_{2}}n_{1}={\binom {n_{2}+1}{2}}$ and for tetrahedral numbers $\sum _{n_{2}=1}^{n_{3}}\sum _{n_{1}=1}^{n_{2}}n_{1}={\binom {n_{3}+2}{3}},$ which uses binomial coefficients, can be generalized. This leads to the formula: $\sum _{n_{k-1}=1}^{n_{k}}\sum _{n_{k-2}=1}^{n_{k-1}}\dots \sum _{n_{2}=1}^{n_{3}}\sum _{n_{1}=1}^{n_{2}}n_{1}={\binom {n_{k}+k-1}{k}}$

## Other properties

Triangular numbers correspond to the first-degree case of Faulhaber's formula.
{{{annotations}}}
Alternating triangular numbers (1, 6, 15, 28, ...) are also hexagonal numbers.
Every even perfect number is triangular (as well as hexagonal), given by the formula $M_{p}2^{p-1}={\frac {M_{p}(M_{p}+1)}{2}}=T_{M_{p}}$ where M$_p$ is a Mersenne prime. No odd perfect numbers are known; hence, all known perfect numbers are triangular.
For example, the third triangular number is (3 × 2 =) 6, the seventh is (7 × 4 =) 28, the 31st is (31 × 16 =) 496, and the 127th is (127 × 64 =) 8128.
The final digit of a triangular number is 0, 1, 3, 5, 6, or 8, and thus such numbers never end in 2, 4, 7, or 9. A final 3 must be preceded by a 0 or 5; a final 8 must be preceded by a 2 or 7.
In base 10, the digital root of a nonzero triangular number is always 1, 3, 6, or 9. Hence, every triangular number is either divisible by three or has a remainder of 1 when divided by 9:
The digital root pattern for triangular numbers, repeating every nine terms, as shown above, is "1, 3, 6, 1, 6, 3, 1, 9, 9".
The converse of the statement above is, however, not always true. For example, the digital root of 12, which is not a triangular number, is 3 and divisible by three.
If x is a triangular number, a is an odd square, and b = ⁠a − 1/8⁠, then ax + b is also a triangular number. Note that b will always be a triangular number, because 8T$_n$ + 1 = (2n + 1)$^2$, which yields all the odd squares are revealed by multiplying a triangular number by 8 and adding 1, and the process for b given a is an odd square is the inverse of this operation. The first several pairs of this form (not counting 1x + 0) are: 9x + 1, 25x + 3, 49x + 6, 81x + 10, 121x + 15, 169x + 21, ... etc. Given x is equal to T$_n$, these formulas yield T$_{3n+1}$, T$_{5n+2}$, T$_{7n+3}$, T$_{9n+4}$, and so on.
The sum of the reciprocals of all the nonzero triangular numbers is $\sum _{n=1}^{\infty }{1 \over {{n^{2}+n} \over 2}}=2\sum _{n=1}^{\infty }{1 \over {n^{2}+n}}=2.$
This can be shown by using the basic sum of a telescoping series: $\sum _{n=1}^{\infty }{1 \over {n(n+1)}}=1.$
In addition, the nth partial sum of this series can be written as ⁠2n/n + 1⁠
Two other formulas regarding triangular numbers are $T_{a+b}=T_{a}+T_{b}+ab$ and $T_{ab}=T_{a}T_{b}+T_{a-1}T_{b-1},$ both of which can easily be established either by looking at dot patterns (see above) or with some simple algebra. The first formula are relevant to multiplication algorithm#Quarter square multiplication.
In 1796, Gauss discovered that every positive integer is representable as a sum of three triangular numbers, writing in his diary his famous words, "ΕΥΡΗΚΑ! num = Δ + Δ + Δ". The three triangular numbers are not necessarily distinct, or nonzero; for example 20 = 10 + 10 + 0. This is a special case of the Fermat polygonal number theorem.
The largest triangular number of the form 2$^k$ − 1 is 4095 (see Ramanujan–Nagell equation).
Wacław Franciszek Sierpiński posed the question as to the existence of four distinct triangular numbers in geometric progression. It was conjectured by Polish mathematician Kazimierz Szymiczek to be impossible and was later proven by Fang and Chen in 2007.
Formulas involving expressing an integer as the sum of triangular numbers are connected to theta functions, in particular the Ramanujan theta function.
The number of line segments between closest pairs of dots in the triangle can be represented in terms of the number of dots or with a recurrence relation: $L_{n}=3T_{n-1}=3{n \choose 2};\qquad L_{n}=L_{n-1}+3(n-1),~L_{1}=0.$
In the limit, the ratio between the two numbers, dots and line segments is $\lim _{n\to \infty }{\frac {T_{n}}{L_{n}}}={\frac {1}{3}}.$

## Applications

The triangular number T$_n$ solves the handshake problem of counting the number of handshakes if each person in a room with n + 1 people shakes hands once with each person. In other words, the solution to the handshake problem of n people is T$_{n−1}$.
Equivalently, a fully connected network of n computing devices requires the presence of T$_{n−1}$ cables or other connections.
In a tournament format that uses a round-robin group stage, the number of matches that need to be played between n teams is equal to the triangular number T$_{n−1}$. For example, a group stage with 4 teams requires 6 matches, and a group stage with 8 teams requires 28 matches. This is also equivalent to the handshake problem and fully connected network problems.
One way of calculating the depreciation of an asset is the sum-of-years' digits method, which involves finding T$_n$, where n is the length in years of the asset's useful life. Each year, the item loses (b − s) × ⁠n − y/T$_n$⁠, where b is the item's beginning value (in units of currency), s is its final salvage value, n is the total number of years the item is usable, and y the current year in the depreciation schedule. Under this method, an item with a usable life of n = 4 years would lose ⁠4/10⁠ of its "losable" value in the first year, ⁠3/10⁠ in the second, ⁠2/10⁠ in the third, and ⁠1/10⁠ in the fourth, accumulating a total depreciation of ⁠10/10⁠ (the whole) of the losable value.
Board game designers Geoffrey Engelstein and Isaac Shalev describe triangular numbers as having achieved "nearly the status of a mantra or koan among game designers", describing them as "deeply intuitive" and "featured in an enormous number of games, [proving] incredibly versatile at providing escalating rewards for larger sets without overly incentivizing specialization to the exclusion of all other strategies".
Relationship between the maximum number of pips on an end of a domino and the number of dominoes in its set (values in bold are common) :
| Max. pips | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| n | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| T$_n$ | 1 | 3 | 6 | 10 | 15 | 21 | 28 | 36 | 45 | 55 | 66 | 78 | 91 | 105 | 120 | 136 | 153 | 161 | 190 | 210 | 231 | 253 |

## Triangular roots and tests for triangular numbers

By analogy with the square root of x, one can define the (positive) triangular root of x as the number n such that T$_n$ = x: $n={\frac {{\sqrt {8x+1}}-1}{2}}$
which follows immediately from the quadratic formula. So an integer x is triangular if and only if 8x + 1 is a square. Equivalently, if the positive triangular root n of x is an integer, then x is the nth triangular number.

## Alternative name

By analogy with the factorial function, a product whose factors are the integers from 1 to n, Donald Knuth proposed the name Termial function, with the notation n? for the sum whose terms are the integers from 1 to n (the nth triangular number). Although some other sources use this name and notation, they are not in wide use.