Triangular numbers: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(Added XPL0 example.)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(16 intermediate revisions by 11 users not shown)
Line 40:
In general, these all belong to the class [[wp:Figurate_number|figurate numbers]] as they are
based on '''r''' dimensional geometric figures. Sometimes they are referred to as '''r-simplex'''
numbers. In geometry a [[wp:Simplex|simplex]] is the simplest possible '''r-dimensional'''
object possible.
 
You may easily extend to an arbitrary dimension '''r''' using binomials. Each term '''n''' in dimension '''r''' is <math>r_n = \binom{n + r - 1}{r}</math>
 
There is no known general formula to find roots of higher r-simplex numbersroots.
 
 
Line 73:
;* [[Pascal's_triangle|Related task: Pascal's triangle]]
 
 
=={{header|ALGOL 68}}==
Assumes LONG INT is at least 64 bits.
<br>
Some roots that should be integers have non-integral values when calculated by the formulae in the task.
To get the correct values (if possible), the root procedures used here calculate float value and then use the nearest integer or nearest integer + 1 if they are exact.
<syntaxhighlight lang="algol68">
BEGIN # show some triangular, tetrahedral, ... numbers and roots #
# prints a row of LONG INTs, with a title, newlines after every per-line #
# and each number in the specified width #
PROC show values = ( STRING title, []LONG INT v, INT per line, INT width )VOID:
BEGIN
print( ( title, ":", newline ) );
INT on line := 0;
FOR i FROM LWB v TO UPB v DO
print( ( whole( v[ i ], -width ) ) );
IF ( on line +:= 1 ) = per line THEN
print( ( newline ) );
on line := 0
FI
OD;
IF on line /= 0 THEN print( ( newline ) ) FI;
print( ( newline ) )
END # show values # ;
 
# calculate the first 30 triangular, tetrahedral, etc. numbers #
[ 1 : 30 ]LONG INT triangular; triangular[ 1 ] := 0;
[ 1 : 30 ]LONG INT tetrahedral; tetrahedral[ 1 ] := 0;
[ 1 : 30 ]LONG INT pentatopic; pentatopic[ 1 ] := 0;
[ 1 : 30 ]LONG INT simplex12; simplex12[ 1 ] := 0;
FOR i FROM 2 TO 30 DO
triangular[ i ] := triangular[ i - 1 ] + i - 1;
tetrahedral[ i ] := tetrahedral[ i - 1 ] + triangular[ i ];
pentatopic[ i ] := pentatopic[ i - 1 ] + tetrahedral[ i ];
simplex12[ i ] := pentatopic[ i ]
OD;
FROM 5 TO 12 DO
FOR i FROM 2 TO 30 DO
simplex12[ i ] +:= simplex12[ i - 1 ]
OD
OD;
show values( "First 30 Triangular numbers", triangular, 6, 4 );
show values( "First 30 Tetrahedral numbers", tetrahedral, 6, 5 );
show values( "First 30 Pentatopic numbers", pentatopic, 6, 6 );
show values( "First 30 12-Simplex numbers", simplex12, 6, 12 );
 
# show some triangular, tetrahedral, etc. roots #
 
# returns the cube root of x #
PROC long crt = ( LONG REAL x )LONG REAL: long exp( long ln( x ) / 3 );
# returns a LONG REAL approximation to the triangular root of x #
PROC real triangular root = ( LONG INT x )LONG REAL: ( long sqrt( ( 8 * x ) + 1 ) - 1 ) / 2;
# returns a LONG REAL approximation to the tetrahedral root of x #
PROC real tetrahedral root = ( LONG INT x )LONG REAL:
BEGIN
LONG REAL t = long sqrt( ( 9 * x * x ) - ( 1 / 27 ) );
long crt( ( 3 * x ) + t ) + long crt( ( 3 * x ) - t ) - 1
END # tetrahedral root # ;
# returns a LONG REAL approximation to the pentatopic root of x #
PROC real pentatopic root = ( LONG INT x )LONG REAL:
( long sqrt( 5 + ( 4 * long sqrt( ( 24 * x ) + 1 ) ) ) - 3 ) / 2;
# returns an integer root of x, if the approximation (possibly + 1 ) = x #
# the approximation otherwise #
PROC try integer root = ( LONG INT x, LONG REAL real root, PROC( LONG INT )LONG INT f )LONG REAL:
IF LONG INT ir = ENTIER real root;
f( ir ) = x
THEN ir
ELIF f( ir + 1 ) = x
THEN ir + 1
ELSE real root
FI # try integer root # ;
# returns the triangular root of x #
PROC triangular root = ( LONG INT x )LONG REAL:
try integer root( x
, real triangular root( x )
, ( LONG INT n )LONG INT: ( n * ( n + 1 ) ) OVER 2
);
# returns the tetrahedral root of x #
PROC tetrahedral root = ( LONG INT x )LONG REAL:
try integer root( x
, real tetrahedral root( x )
, ( LONG INT n )LONG INT: ( n * ( n + 1 ) * ( n + 2 ) ) OVER 6
);
# returns the pentatopic root of x #
PROC pentatopic root = ( LONG INT x )LONG REAL:
try integer root( x
, real pentatopic root( x )
, ( LONG INT n )LONG INT: ( n * ( n + 1 ) * ( n + 2 ) * ( n + 3 ) ) OVER 24
);
[]LONG INT root test = ( 7140, 21408696, 26728085384, 14545501785001 );
FOR i FROM LWB root test TO UPB root test DO
PROC show = ( LONG REAL x )STRING:
IF ENTIER x = x THEN whole( x, -6 ) + " " ELSE fixed( x, -12, 5 ) FI;
print( ( "Roots of ", whole( root test[ i ], 0 ), newline, " " ) );
print( ( " triangular: ", show( triangular root( root test[ i ] ) ) ) );
print( ( " tetrahedral: ", show( tetrahedral root( root test[ i ] ) ) ) );
print( ( " pentatopic: ", show( pentatopic root( root test[ i ] ) ) ) );
print( ( newline ) )
OD
END
</syntaxhighlight>
{{out}}
<pre>
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: 119 tetrahedral: 34 pentatopic: 18.87665
Roots of 21408696
triangular: 6543 tetrahedral: 503.56183 pentatopic: 149.06095
Roots of 26728085384
triangular: 231205.40557 tetrahedral: 5432 pentatopic: 893.44246
Roots of 14545501785001
triangular: 5393607.1581 tetrahedral: 44355.77738 pentatopic: 4321
</pre>
 
=={{header|AppleScript}}==
Line 195 ⟶ 335:
Tetrahedral root: 4.435577737656E+4
Pentatopic root: 4321.0"</syntaxhighlight>
 
=={{header|FreeBASIC}}==
{{trans|Wren}}
<syntaxhighlight lang="freebasic">Dim As Integer n, r, t(0 To 30)
t(0) = 0
 
Print "The first 30 triangular numbers are:"
For n = 1 To 30
t(n) = t(n-1) + n - 1
If n Mod 6 = 0 Then Print Using "####"; t(n) Else Print Using "####"; t(n);
Next n
 
Print !"\nThe first 30 tetrahedral numbers are:"
For n = 1 To 30
t(n) += t(n-1)
Print Using "#####"; t(n);
If n Mod 6 = 0 Then Print
Next n
 
Print !"\nThe first 30 pentatopic numbers are:"
For n = 1 To 30
t(n) += t(n-1)
Print Using "######"; t(n);
If n Mod 6 = 0 Then Print
Next n
 
Print !"\nThe first 30 12-simplex numbers are:"
For r = 5 To 12
For n = 1 To 30
t(n) += t(n-1)
If r = 12 Then
Print Using "###########"; t(n);
If n Mod 6 = 0 Then Print
End If
Next n
Next r
 
#define cRec27 1/sqr(27)
Dim As Integer xs(1 To 4) = {7140, 21408696, 26728085384, 14545501785001}
Dim As Double x, y, z
 
For i As Byte = 1 To 4
z = xs(i)
Print !"\nRoots of"; xs(i); ":"
Print " triangular:"; (Sqr(8*z+1)-1)/2
y = 3*z
x = Sqr((y-cRec27)*(y+cRec27))
Print "tetrahedral:"; Iif(x < y, Exp(Log(y+x)/3)+Exp(Log(y-x)/3)-1, Exp(Log(6)/3)*Exp(Log(z)/3)-1)
Print " pentatopic:"; (Sqr(5+4*Sqr(24*z+1))-3)/2
Next i
Sleep</syntaxhighlight>
{{out}}
<pre>The first 30 triangular numbers are:
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
 
The first 30 tetrahedral numbers are:
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
 
The first 30 pentatopic numbers are:
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
 
The first 30 12-simplex numbers are:
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: 119
tetrahedral: 34.00000000179027
pentatopic: 18.87664661592801
 
Roots of 21408696:
triangular: 6543
tetrahedral: 503.5611663345483
pentatopic: 149.0609473752659
 
Roots of 26728085384:
triangular: 231205.4055652559
tetrahedral: 5431.99993864654
pentatopic: 893.4424567516849
 
Roots of 14545501785001:
triangular: 5393607.158145173
tetrahedral: 44355.77737655847
pentatopic: 4321</pre>
 
=={{header|Go}}==
Line 391 ⟶ 632:
5.39361e6 44356.2 4321
</syntaxhighlight>
 
=={{header|jq}}==
{{works with|jq}}
 
'''Also works with gojq and fq, the Go implementations of jq'''
 
The main point of interest in the following is probably `figurates/0`, which generates
an indefinitely long stream of the $r-simplex numbers if $r >= 2, where $r is the input to the filter.
For the sake of illustration, however, `tetrahedrals` and `pentatopics` are defined without reference to `figurates/0`.
 
'''Preliminaries'''
<syntaxhighlight lang=jq>
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
 
# Display a stream of items in Z-style, n per line
def neatly(s; $n; $width):
def p: lpad($width);
foreach s as $x ({n: 1, s:""};
if .n >= $n
then .emit = .s + " " + ($x|p)
| .s = null
| .n = 1
else .emit = null
| .s = .s + " " + ($x|p)
| .n += 1
end;
select(.emit).emit);
 
# nCk assuming n >= k
def binomial(n; k):
if k > n / 2 then binomial(n; n-k)
else reduce range(1; k+1) as $i (1; . * (n - $i + 1) / $i)
end;
</syntaxhighlight>
<syntaxhighlight lang=jq>
def figurate($r; $n): binomial($n + $r -1; $r);
 
def triangular: binomial(.+1;2);
 
# r=2
def triangulars: foreach range(0; infinite) as $i (0; . + $i);
 
# r=3
def tetrahedrals: foreach triangulars as $t (0; . + $t);
 
# r=4
def pentatopics: foreach tetrahedrals as $t (0; . + $t);
 
# input: r
def figurates:
. as $r
| if $r == 2 then triangulars
else foreach ($r - 1 |figurates) as $t (0; . + $t)
end;
# r=12
def twelveSimplexes: 12 | figurates;
 
### r-simplex roots
 
def triangularRoot: ((8*. + 1 | sqrt) -1) /2;
 
def tetrahedralRoot:
def term(sign):
(3 * .) as $y
| ($y + sign * ( (($y*$y) - (1/27))|sqrt)) | cbrt;
term(1) + term(-1) -1;
 
def pentatopicRoot:
(((5 + 4 * (( 24*. + 1)|sqrt)) | sqrt) - 3) / 2;
 
def xs: [7140, 21408696, 26728085384, 14545501785001];
 
def tasks:
def round($ndec): pow(10;$ndec) as $p | . * $p | round / $p;
def r: round(4) | lpad(12);
def s(stream): limit(30; neatly(stream; 5; 8));
"The first 30 triangular numbers are:", s(triangulars),
"\nThe first 30 tetrahedral numbers are:", s(tetrahedrals),
"\nThe first 30 pentatopic numbers are:", s(pentatopics),
"\nThe first 30 12-simplex numbers are:", neatly(limit(30; twelveSimplexes); 5; 12),
"",
"Approximate r-simplex roots:",
"\("x "|lpad(15)) triangularRoot tetrahedralRoot pentatopicRoot",
(xs[]
| "\(lpad(15)): \(triangularRoot|r) \(tetrahedralRoot|r) \(pentatopicRoot|r)")
 
;
 
tasks
</syntaxhighlight>
{{output}}
<pre>
The first 30 triangular numbers are:
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
465 496 528 561 595
630 666 703 741 780
820 861 903 946 990
1035 1081 1128 1176 1225
1275 1326 1378 1431 1485
1540 1596 1653 1711 1770
1830 1891 1953 2016 2080
2145 2211 2278 2346 2415
2485 2556 2628 2701 2775
2850 2926 3003 3081 3160
3240 3321 3403 3486 3570
3655 3741 3828 3916 4005
4095 4186 4278 4371 4465
4560 4656 4753 4851 4950
5050 5151 5253 5356 5460
5565 5671 5778 5886 5995
6105 6216 6328 6441 6555
6670 6786 6903 7021 7140
7260 7381 7503 7626 7750
7875 8001 8128 8256 8385
8515 8646 8778 8911 9045
9180 9316 9453 9591 9730
9870 10011 10153 10296 10440
10585 10731 10878 11026 11175
 
The first 30 tetrahedral numbers are:
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
4960 5456 5984 6545 7140
7770 8436 9139 9880 10660
11480 12341 13244 14190 15180
16215 17296 18424 19600 20825
22100 23426 24804 26235 27720
29260 30856 32509 34220 35990
37820 39711 41664 43680 45760
47905 50116 52394 54740 57155
59640 62196 64824 67525 70300
73150 76076 79079 82160 85320
88560 91881 95284 98770 102340
105995 109736 113564 117480 121485
125580 129766 134044 138415 142880
147440 152096 156849 161700 166650
171700 176851 182104 187460 192920
198485 204156 209934 215820 221815
227920 234136 240464 246905 253460
260130 266916 273819 280840 287980
295240 302621 310124 317750 325500
333375 341376 349504 357760 366145
374660 383306 392084 400995 410040
419220 428536 437989 447580 457310
467180 477191 487344 497640 508080
518665 529396 540274 551300 562475
 
The first 30 pentatopic numbers are:
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
40920 46376 52360 58905 66045
73815 82251 91390 101270 111930
123410 135751 148995 163185 178365
194580 211876 230300 249900 270725
292825 316251 341055 367290 395010
424270 455126 487635 521855 557845
595665 635376 677040 720720 766480
814385 864501 916895 971635 1028790
1088430 1150626 1215450 1282975 1353275
1426425 1502501 1581580 1663740 1749060
1837620 1929501 2024785 2123555 2225895
2331890 2441626 2555190 2672670 2794155
2919735 3049501 3183545 3321960 3464840
3612280 3764376 3921225 4082925 4249575
4421275 4598126 4780230 4967690 5160610
5359095 5563251 5773185 5989005 6210820
6438740 6672876 6913340 7160245 7413705
7673835 7940751 8214570 8495410 8783390
9078630 9381251 9691375 10009125 10334625
10668000 11009376 11358880 11716640 12082785
12457445 12840751 13232835 13633830 14043870
14463090 14891626 15329615 15777195 16234505
16701685 17178876 17666220 18163860 18671940
19190605 19720001 20260275 20811575 21374050
 
The first 30 12-simplex numbers are:
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
 
Approximate r-simplex roots:
x triangularRoot tetrahedralRoot pentatopicRoot
7140: 119 34 18.8766
21408696: 6543 503.5612 149.0609
26728085384: 231205.4056 5431.9999 893.4425
14545501785001: 5393607.1581 44355.7774 4321
</pre>
 
=={{header|Julia}}==
Line 402 ⟶ 849:
 
function tetrahedral_root(x)
return Float64(round((3x + sqrt(9 * big(x)^big"2" - big"1"/27))^(big"1"/3) +
(3x - sqrt(9 * big(x)^big"2" - big"1"/27))^(big"1"/3) - 1, digits=1118))
end
 
Line 460 ⟶ 907:
Roots of 21408696:
triangular-root: 6543.0
tetrahedral-root: 503.561826974645618269746365
pentatopic-root: 149.06094737526587
 
Line 470 ⟶ 917:
Roots of 14545501785001:
triangular-root: 5.3936071581451725e6
tetrahedral-root: 44355.77738407323777384073255
pentatopic-root: 4321.0
</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
{{trans|Julia}}
<syntaxhighlight lang="Mathematica">
(* Polytopic number generation function *)
Polytopic[r_, range_] := Binomial[# + r - 1, r] & /@ range
 
(* Triangular root function *)
TriangularRoot[x_] := (Sqrt[8 x + 1] - 1)/2
 
(* Tetrahedral root function *)
TetrahedralRoot[x_] := N[((3 x + Sqrt[9 x^2 - 1/27])^(1/3) +
(3 x - Sqrt[9 x^2 - 1/27])^(1/3) - 1), 18]
 
(* Pentatopic root function *)
PentatopicRoot[x_] := (Sqrt[5 + 4 Sqrt[24 x + 1]] - 3)/2
 
(* Displaying polytopic numbers *)
Do[
name = Which[
r == 2, "triangular",
r == 3, "tetrahedral",
r == 4, "pentatopic",
r == 12, "12-simplex"
];
Print["\nFirst 30 ", name, " numbers:\n", Polytopic[r, Range[0, 29]]],
{r,{2,3,4,12}}
]
 
(* Displaying roots of specific numbers *)
nums = {7140, 21408696, 26728085384, 14545501785001};
For[i = 1, i <= Length[nums], i++,
n = nums[[i]];
Print["\nRoots of ", n, ":"];
Print[" triangular-root: ", N@TriangularRoot[n]];
Print[" tetrahedral-root: ", N@TetrahedralRoot[n]];
Print[" pentatopic-root: ", N@PentatopicRoot[n]]
]
</syntaxhighlight>
{{out}}
<pre>
 
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.876646615928006
 
Roots of 21408696:
triangular-root: 6543.
tetrahedral-root: 503.5618269746365
pentatopic-root: 149.06094737526587
 
Roots of 26728085384:
triangular-root: 231205.40556525585
tetrahedral-root: 5432.
pentatopic-root: 893.4424567516849
 
Roots of 14545501785001:
triangular-root: 5.3936071581451725*^6
tetrahedral-root: 44355.777384073255
pentatopic-root: 4321.
 
</pre>
 
 
=={{header|Nim}}==
As described in the task presentation, we start the sequences at index 1.
<syntaxhighlight lang="Nim">import std/[math, strformat, strutils]
 
 
proc printNSimplexNumbers(r, count, width: Positive; title: string) =
## Print the first "count" terms of the "r-simplex" sequence
## using "width" characters.
echo title
for n in 1..count:
stdout.write align($binom(n + r - 1, r), width)
stdout.write if n mod 5 == 0: '\n' else: ' '
echo()
 
printNSimplexNumbers(2, 30, 3, "First 30 triangular numbers:")
printNSimplexNumbers(3, 30, 4, "First 30 tetrahedral numbers:")
printNSimplexNumbers(4, 30, 5, "First 30 pentatopic numbers:")
printNSimplexNumbers(12, 30, 10, "First 30 12-simplex numbers:")
 
 
func triangularRoot(x: float): float =
## Return the triangular root of "x".
(sqrt(8 * x + 1) - 1) * 0.5
 
func tetrahedralRoot(x: float): float =
## Return the tetrahedral root of "x".
let t1 = 3 * x
let t2 = sqrt(t1 * t1 - 1 / 27)
result = cbrt(t1 + t2) + cbrt(t1 - t2) - 1
 
func pentatopicRoot(x: float): float =
## Return the pentatopic root of "x".
(sqrt(5 + 4 * sqrt(24 * x + 1)) - 3) * 0.5
 
for n in [int64 7140, 21408696, 26728085384, 14545501785001]:
echo &"Roots of {n}:"
for (title, f) in {"triangular: ": triangularRoot,
"tetrahedral:": tetrahedralRoot,
"pentatopic: ": pentatopicRoot}:
echo &" {title} {f(n.float):.6f}"
echo()
</syntaxhighlight>
 
{{out}}
<pre>First 30 triangular numbers:
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 465
 
First 30 tetrahedral numbers:
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 4960
 
First 30 pentatopic numbers:
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 40920
 
First 30 12-simplex numbers:
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 7898654920
 
Roots of 7140:
triangular: 119.000000
tetrahedral: 34.000000
pentatopic: 18.876647
 
Roots of 21408696:
triangular: 6543.000000
tetrahedral: 503.561166
pentatopic: 149.060947
 
Roots of 26728085384:
triangular: 231205.405565
tetrahedral: 5431.999939
pentatopic: 893.442457
 
Roots of 14545501785001:
triangular: 5393607.158145
tetrahedral: 44355.777377
pentatopic: 4321.000000
</pre>
 
=={{header|PARI/GP}}==
{{trans|Julia}}
<syntaxhighlight lang="PARI/GP">
/* Polytopic number generation function */
polytopic(r, range) = {
vector(#range, i, binomial(range[i] + r - 1, r))
}
 
/* Triangular root function */
triangularRoot(x) = {
(sqrt(8*x + 1) - 1)/2
}
 
/* Tetrahedral root function */
tetrahedralRoot(x) = {
N = (3*x + sqrt(9*x^2 - 1/27))^(1/3) + (3*x - sqrt(9*x^2 - 1/27))^(1/3) - 1;
precision(N, 18)
}
 
/* Pentatopic root function */
pentatopicRoot(x) = {
(sqrt(5 + 4*sqrt(24*x + 1)) - 3)/2
}
 
 
{
/* Displaying polytopic numbers */
r_sel=[2,3,4,12];
for(i = 1, #r_sel,
r=r_sel[i];
casename="place_holder";
if(r == 2, casename="triangular"; ,
r == 3, casename="tetrahedral"; ,
r == 4, casename="pentatopic"; ,
r == 12, casename="12-simplex";
);
printf("\nFirst 30 %s numbers:\n %s\n" , Str(casename) , Str(polytopic(r, [0..29])) )
);
 
/* Displaying roots of specific numbers */
nums = [7140, 21408696, 26728085384, 14545501785001];
for(i = 1, #nums,
n = nums[i];
printf("\nRoots of %s:\n", Str(n));
printf(" triangular-root: %s\n", Str(triangularRoot(n)));
printf(" tetrahedral-root: %s\n", Str(tetrahedralRoot(n)));
printf(" pentatopic-root: %s\n", Str(pentatopicRoot(n)))
);
}
</syntaxhighlight>
{{out}}
<pre>
 
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.00000000000000000000000000000000000
tetrahedral-root: 34.00000000000000000
pentatopic-root: 18.876646615928006607901782826667566229
 
Roots of 21408696:
triangular-root: 6543.0000000000000000000000000000000000
tetrahedral-root: 503.5618269746365141
pentatopic-root: 149.06094737526586748438757488471336807
 
Roots of 26728085384:
triangular-root: 231205.40556525583695729103196069412230
tetrahedral-root: 5432.000000000000000
pentatopic-root: 893.44245675168486988846621152924537039
 
Roots of 14545501785001:
triangular-root: 5393607.1581451723164973047246554846080
tetrahedral-root: 44355.77738407325605
pentatopic-root: 4321.0000000000000000000000000000000000
 
</pre>
 
Line 643 ⟶ 1,350:
</pre>
 
=={{header|RakuPerl}}==
{{trans|Raku}}
<syntaxhighlight lang="raku" line>use Math::Root;
<syntaxhighlight lang="perl" line>
use v5.36;
use experimental <builtin for_list>;
use Math::AnyNum <binomial cbrt max round>;
 
sub table { my $t = 6 * (my $c = 1 + length max @_); ( sprintf( ('%'.$c.'d')x@_, @_) ) =~ s/.{1,$t}\K/\n/gr }
my \ε = FatRat.new: 1, 10**24;
 
sub triangular_root ($x) {
sub binomial { [×] ($^n … 0) Z/ 1 .. $^p }
round( (sqrt(8 * $x + 1) - 1) / 2, -3);
}
 
sub tetrahedral_root ($x) {
sub polytopic (Int $r, @range) { @range.map: { binomial $_ + $r - 1, $r } }
round(
cbrt(3 * $x + sqrt 9 * $x**2 - 1/27) +
cbrt(3 * $x - sqrt 9 * $x**2 - 1/27) - 1,
-3)
}
 
sub pentatopic_root ($x) {
round( (sqrt(5 + 4 * sqrt 24 * $x + 1) - 3) / 2, -3)
}
 
sub triangular-rootpolytopic ($xr, @range) { roundmap ((8{ ×binomial $x_ + 1).&root$r - 1), /$r 2,} ε@range }
 
for my($r,$label) (2, 'triangular', 3, 'tetrahedral', 4, 'pentatopic', 12, '12-simplex') {
sub tetrahedral-root ($x) {
say "First 30 $label numbers:\n" . table polytopic $r, 0..29
((3 × $x + (9 × $x² - 1/27).&root).&root(3) +
(3 × $x - (9 × $x² - 1/27).&root).&root(3) - 1).round: ε
}
 
for (7140, 21408696, 26728085384, 14545501785001) {
sub pentatopic-root ($x) { round ((5 + 4 × (24 × $x + 1).&root).&root - 3) / 2, ε }
printf "Roots of $_:
triangular-root: %s
tetrahedral-root: %s
pentatopic-root: %s\n\n",
triangular_root($_), tetrahedral_root($_), pentatopic_root($_);
}
</syntaxhighlight>
{{out}}
<pre>
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.877
 
Roots of 21408696:
triangular-root: 6543
tetrahedral-root: 503.561
pentatopic-root: 149.061
 
Roots of 26728085384:
triangular-root: 231205.406
tetrahedral-root: 5432
pentatopic-root: 893.442
 
Roots of 14545501785001:
triangular-root: 5393607.158
tetrahedral-root: 44355.777
pentatopic-root: 4321
</pre>
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">t</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">30</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">=</span><span style="color: #000000;">2</span> <span style="color: #008080;">to</span> <span style="color: #000000;">30</span> <span style="color: #008080;">do</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">[</span><span style="color: #000000;">n</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">[</span><span style="color: #000000;">n</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span> <span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The first 30 triangular numbers are:\n%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #000000;">t</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">6</span><span style="color: #0000FF;">,</span><span style="color: #000000;">fmt</span><span style="color: #0000FF;">:=</span><span style="color: #008000;">"%3d"</span><span style="color: #0000FF;">)})</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">=</span><span style="color: #000000;">2</span> <span style="color: #008080;">to</span> <span style="color: #000000;">30</span> <span style="color: #008080;">do</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">[</span><span style="color: #000000;">n</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">[</span><span style="color: #000000;">n</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">[</span><span style="color: #000000;">n</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The first 30 tetrahedral numbers are:\n%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #000000;">t</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">6</span><span style="color: #0000FF;">,</span><span style="color: #000000;">fmt</span><span style="color: #0000FF;">:=</span><span style="color: #008000;">"%4d"</span><span style="color: #0000FF;">)})</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">=</span><span style="color: #000000;">2</span> <span style="color: #008080;">to</span> <span style="color: #000000;">30</span> <span style="color: #008080;">do</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">[</span><span style="color: #000000;">n</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">[</span><span style="color: #000000;">n</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">[</span><span style="color: #000000;">n</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The first 30 pentatopic numbers are:\n%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #000000;">t</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">6</span><span style="color: #0000FF;">,</span><span style="color: #000000;">fmt</span><span style="color: #0000FF;">:=</span><span style="color: #008000;">"%5d"</span><span style="color: #0000FF;">)})</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">r</span><span style="color: #0000FF;">=</span><span style="color: #000000;">5</span> <span style="color: #008080;">to</span> <span style="color: #000000;">12</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">=</span><span style="color: #000000;">2</span> <span style="color: #008080;">to</span> <span style="color: #000000;">30</span> <span style="color: #008080;">do</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">[</span><span style="color: #000000;">n</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">[</span><span style="color: #000000;">n</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">[</span><span style="color: #000000;">n</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span> <span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The first 30 12-simplex numbers are:\n%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #000000;">t</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">6</span><span style="color: #0000FF;">,</span><span style="color: #000000;">fmt</span><span style="color: #0000FF;">:=</span><span style="color: #008000;">"%10d"</span><span style="color: #0000FF;">)})</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">x</span> <span style="color: #008080;">in</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">7140</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">21408696</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">26728085384</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">14545501785001</span><span style="color: #0000FF;">}</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\nRoots of %d:\n"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">x</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">root</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">(</span><span style="color: #7060A8;">sqrt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">x</span><span style="color: #0000FF;">*</span><span style="color: #000000;">8</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">)-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)/</span><span style="color: #000000;">2</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%14s: %f\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"triangular"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">root</span><span style="color: #0000FF;">})</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">temp</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sqrt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">x</span><span style="color: #0000FF;">*</span><span style="color: #000000;">x</span><span style="color: #0000FF;">*</span><span style="color: #000000;">9</span> <span style="color: #0000FF;">-</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">/</span><span style="color: #000000;">27</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">root</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">power</span><span style="color: #0000FF;">(</span><span style="color: #000000;">x</span><span style="color: #0000FF;">*</span><span style="color: #000000;">3</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">temp</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">/</span><span style="color: #000000;">3</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">+</span> <span style="color: #7060A8;">power</span><span style="color: #0000FF;">(</span><span style="color: #000000;">x</span><span style="color: #0000FF;">*</span><span style="color: #000000;">3</span> <span style="color: #0000FF;">-</span> <span style="color: #000000;">temp</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">/</span><span style="color: #000000;">3</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">-</span> <span style="color: #000000;">1</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%14s: %f\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"tetrahedral"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">root</span><span style="color: #0000FF;">})</span>
<span style="color: #000000;">root</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">(</span><span style="color: #7060A8;">sqrt</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sqrt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">x</span><span style="color: #0000FF;">*</span><span style="color: #000000;">24</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">)*</span><span style="color: #000000;">4</span> <span style="color: #0000FF;">+</span> <span style="color: #000000;">5</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">-</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">)</span> <span style="color: #0000FF;">/</span> <span style="color: #000000;">2</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%14s: %f\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"pentatopic"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">root</span><span style="color: #0000FF;">})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
The first 30 triangular numbers are:
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
 
The first 30 tetrahedral numbers are:
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
 
The first 30 pentatopic numbers are:
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
 
The first 30 12-simplex numbers are:
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: 119.000000
tetrahedral: 34.000000
pentatopic: 18.876647
 
Roots of 21408696:
triangular: 6543.000000
tetrahedral: 503.561166
pentatopic: 149.060947
 
Roots of 26728085384:
triangular: 231205.405565
tetrahedral: 5431.999939
pentatopic: 893.442457
 
Roots of 14545501785001:
triangular: 5393607.158145
tetrahedral: 44355.777377
pentatopic: 4321.000000
</pre>
 
=={{header|Raku}}==
<syntaxhighlight lang="raku" line>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) {
Line 670 ⟶ 1,534:
 
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
}</syntaxhighlight>
Line 727 ⟶ 1,593:
tetrahedral-root: 44355.777384073256052620916903
pentatopic-root: 4321</pre>
 
=={{header|RPL}}==
≪ DUP ROT + 1 - SWAP COMB
≫ ''''SMPLX'''' STO
≪ 8 * 1 + √ 1 - 2 /
≫ ''''TROOT'''' STO
≪ DUP SQ 9 * 27 INV - √ SWAP 3 *
DUP2 + 3 INV ^ SWAP ROT - 3 INV ^ + 1 -
≫ ''''TeROOT'''' STO
≪ 24 * 1 + √ 4 * 5 + √ 3 - 2 /
≫ ''''PROOT'''' STO
≪ {} 1 30 '''FOR''' n n 3 PICK '''SMPLX''' + '''NEXT'''
≫ ''''SPX30'''' STO
≪ {7140 21408696 26728085384 14545501785001}
1 4 '''FOR''' n
DUP n GET {}
OVER '''TROOT''' + OVER '''TeROOT''' + SWAP '''PROOT''' + SWAP
'''NEXT''' DROP
≫ ''''ROOTS'''' STO
{{in}}
<pre>
2 SPX30
3 SPX30
4 SPX30
12 SPX30
ROOTS
</pre>
{{out}}
<pre>
8: { 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 465 }
7: { 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 4960 }
6: { 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 40920 }
5: { 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 7898654920 }
4: { 119 34.0000000018 18.8766466159 }
3: { 6543 503.561166335 149.060947375 }
2: { 231205.405565 5431.99993865 893.442456752 }
1: { 5393607.15814 44355.7773766 4321 }
</pre>
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">func pentatopic_root(x) {
(sqrt(5 + 4*sqrt(24*x + 1)) - 3)/2
}
 
func polytopic (r, range) {
range.map {|n| binomial(n + r - 1, r) }
}
 
[
2, 'triangular', 3, 'tetrahedral', 4, 'pentatopic', 12, '12-simplex'
].slices(2).each_2d {|r,label|
say "\nFirst 30 #{label} numbers:"
polytopic(r, ^30).slices(6).each{.join(' ').say}
}
 
for n in (7140, 21408696, 26728085384, 14545501785001) {
printf ("\nRoots of #{n}:
triangular-root: %s
tetrahedral-root: %s
pentatopic-root: %s\n",
polygonal_root(n,3), pyramidal_root(n,3), pentatopic_root(n))
}</syntaxhighlight>
{{out}}
<pre>
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.8766466159280066079017828266675662291603339398
 
Roots of 21408696:
triangular-root: 6543
tetrahedral-root: 503.56182697463651404819613028417773405650502954
pentatopic-root: 149.060947375265867484387574884713368069543117436
 
Roots of 26728085384:
triangular-root: 231205.405565255836957291031960694122304324644392
tetrahedral-root: 5432
pentatopic-root: 893.442456751684869888466211529245370387840101701
 
Roots of 14545501785001:
triangular-root: 5393607.1581451723164973047246554846079685622181
tetrahedral-root: 44355.7773840732560526209168894228874431786835756
pentatopic-root: 4321
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-fmt}}
{{libheader|Wren-big}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
import "./big" for BigRat
 
9,476

edits