user
A triangular number is a count of objects arranged into an equilateral triangle.
Much like how a square number is a count of objects arranged into a square.

The *nth* triangular number is the sum of the first **n** non-negative integers. 

T

n
=

∑

k
=
1

n
k
=
1
+
2
+
3
+
⋯
+
n
{\displaystyle {\displaystyle T\_{n}=\sum \_{k=1}^{n}k=1+2+3+\dotsb +n}}

Triangular numbers may be calculated by the explicit formulas: 

T

n
=

n
(
n
+
1
)
2
=

(


n
+
1
2

)
{\displaystyle {\displaystyle T\_{n}={\frac {n(n+1)}{2}}={n+1 \choose 2}}}

where 

(


n
+
1
2

)
{\displaystyle {\displaystyle \textstyle {n+1 \choose 2}}}
 is the binomial coefficient "n plus one choose two".

Analogous to square roots, we may also calculate a triangular root. Numbers that have an integer triangular
root are triangular numbers.

The real triangular root of a number *x* may be found using: 

n
=

8
x
+
1
−
1
2
{\displaystyle {\displaystyle n={\frac {{\sqrt {8x+1}}-1}{2}}}}

Similar to how cubic numbers are square numbers extended into a third dimension,
triangular numbers extended into a third dimension are known as tetrahedral numbers.

The *nth* tetrahedral number is the sum of the first **n** triangular numbers. 

T

e

n
=

∑

k
=
1

n

T

k
{\displaystyle {\displaystyle Te\_{n}=\sum \_{k=1}^{n}T\_{k}}}

Or, may be calculated directly: 

T

e

n
=

n
(
n
+
1
)
(
n
+
2
)
6
=

n


3
¯

3
!
=

(


n
+
2
3

)
{\displaystyle {\displaystyle Te\_{n}={\frac {n(n+1)(n+2)}{6}}={\frac {n^{\overline {3}}}{3!}}={\binom {n+2}{3}}}}
 (Binomial "n plus two choose three".)

One may find the real tetrahedral root of *x* using the formula: 

n
=

3
x
+


9


x

2
−


1
27

3
+

3
x
−


9


x

2
−


1
27

3
−
1
{\displaystyle {\displaystyle n={\sqrt[{3}]{3x+{\sqrt {9{x^{2}}-{\frac {1}{27}}}}}}+{\sqrt[{3}]{3x-{\sqrt {9{x^{2}}-{\frac {1}{27}}}}}}-1}}
  
*Depending on the math precision of your particular language, may need to be rounded to the nearest 1e-16 or so.*

Extending into a fourth dimension we get pentatopic numbers.

Again, the *nth* pentatope is the sum of the first **n** tetrahedral numbers, 

P

n
=

∑

k
=
1

n
T

e

k
{\displaystyle {\displaystyle P\_{n}=\sum \_{k=1}^{n}Te\_{k}}}

or explicitly: 

P

n
=

n
(
n
+
1
)
(
n
+
2
)
(
n
+
3
)
24
=

(


n
+
3
4

)
{\displaystyle {\displaystyle P\_{n}={\frac {n(n+1)(n+2)(n+3)}{24}}={\binom {n+3}{4}}}}
 (Binomial "n plus three choose four".)

The pentatopic real root of *x* may be found using: 

n
=

5
+
4


24
x
+
1
−
3
2
.
{\displaystyle {\displaystyle n={\frac {{\sqrt {5+4{\sqrt {24x+1}}}}-3}{2}}.}}

In general, these all belong to the class figurate numbers as they are
based on **r** dimensional geometric figures. Sometimes they are referred to as **r-simplex**
numbers. In geometry a simplex is the simplest possible **r-dimensional**
object.

You may easily extend to an arbitrary dimension **r** using binomials. Each term **n** in dimension **r** is 

r

n
=

(


n
+
r
−
1
r

)
{\displaystyle {\displaystyle r\_{n}={\binom {n+r-1}{r}}}}

There is no known general formula to find higher r-simplex roots.

Task

* Find and display the first 30 triangular numbers (**r** = 2).
* Find and display the first 30 tetrahedral numbers (**r** = 3).
* Find and display the first 30 pentatopic numbers (**r** = 4).
* Find and display the first 30 12-simplex numbers (**r** = 12).
* Find and display the triangular root, the tetrahedral root, and the pentatopic root for the integers:
  + 7140
  + 21408696
  + 26728085384
  + 14545501785001

See also

* Wikipedia: Triangular numbers * Wikipedia: Tetrahedral numbers * Wikipedia: Pentatopic numbers * Wikipedia: Figurate numbers * Wikipedia: Simplex(geometry) * OEIS:A000217 - Triangular numbers: a(n) = binomial(n+1,2) * OEIS:A000292 - Tetrahedral numbers: a(n) = binomial(n+2,3) * OEIS:A000332 - Pentatope numbers: a(n) = binomial(n+3,4) * Related task: Evaluate binomial coefficients * Related task: Pascal's triangle
assistant
```
use Math::Root:ver<0.0.4>;

sub binomial { [×] ($^n … 0) Z/ 1 .. $^p }

sub polytopic (Int $r, @range) { @range.map: { binomial $_ + $r - 1, $r } }

sub display (@values) {
    my $c = @values.max.chars;
    @values.batch(6)».fmt("%{$c}d").join: "\n";
}

for 2, 'triangular', 3, 'tetrahedral', 4, 'pentatopic', 12, '12-simplex'
  -> $r, $name { say "\nFirst 30 $name numbers:\n" ~ display polytopic $r, ^30 }

say '';

my \ε = FatRat.new: 1, 10**24;

for 7140, 21408696, 26728085384, 14545501785001 {
  say qq:to/R/;
  Roots of $_:
    triangular-root: {.&triangular-root.round:  ε}
   tetrahedral-root: {.&tetrahedral-root.round: ε}
    pentatopic-root: {.&pentatopic-root.round:  ε}
  R
}

```

Output:

```
First 30 triangular numbers:
  0   1   3   6  10  15
 21  28  36  45  55  66
 78  91 105 120 136 153
171 190 210 231 253 276
300 325 351 378 406 435

First 30 tetrahedral numbers:
   0    1    4   10   20   35
  56   84  120  165  220  286
 364  455  560  680  816  969
1140 1330 1540 1771 2024 2300
2600 2925 3276 3654 4060 4495

First 30 pentatopic numbers:
    0     1     5    15    35    70
  126   210   330   495   715  1001
 1365  1820  2380  3060  3876  4845
 5985  7315  8855 10626 12650 14950
17550 20475 23751 27405 31465 35960

First 30 12-simplex numbers:
         0          1         13         91        455       1820
      6188      18564      50388     125970     293930     646646
   1352078    2704156    5200300    9657700   17383860   30421755
  51895935   86493225  141120525  225792840  354817320  548354040
 834451800 1251677700 1852482996 2707475148 3910797436 5586853480

Roots of 7140:
  triangular-root: 119
 tetrahedral-root: 34
  pentatopic-root: 18.876646615928006607901783

Roots of 21408696:
  triangular-root: 6543
 tetrahedral-root: 503.56182697463651404819613
  pentatopic-root: 149.060947375265867484387575

Roots of 26728085384:
  triangular-root: 231205.405565255836957291031961
 tetrahedral-root: 5432
  pentatopic-root: 893.442456751684869888466212

Roots of 14545501785001:
  triangular-root: 5393607.158145172316497304724655
 tetrahedral-root: 44355.777384073256052620916903
  pentatopic-root: 4321
```