Stirling numbers of the first kind: Difference between revisions

 
(9 intermediate revisions by 5 users not shown)
Line 115:
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
Uses the Algol 68G LONG LONG INT mode which provides large-precision integers. As the default number of digits is insufficient for the task, the maximum nunber of digits is specified by a pragmatic comment.
<syntaxhighlight lang="algol68">BEGIN
BEGIN # show some (unsigned) Stirling numbers of the first kind #
 
# specify the precision of LONG LONG INT, we need about 160 digits #
Line 145:
REF[,]SINT s1 = make s1( max stirling, FALSE );
print( ( "Unsigned Stirling numbers of the first kind:", newline ) );
print( ( " k 0" ) );
FOR k FROM 0 TO max stirling DO print( ( whole( k, IF k < 6 THEN -10 ELSE -9 FI ) ) ) OD;
print( ( newline, " n", newline ) );
FOR n FROM 0 TO max stirling DO
print( ( whole( n, -2 ), whole( s1[ n, 0 ], -3 ) ) );
FOR k FROM 0 TO n DO
print( ( whole( s1[ n, k ], IF k < 6 THEN -10 ELSE -9 FI ) ) )
OD;
print( ( newline ) )
Line 167:
print( ( whole( max 100, 0 ), newline ) )
END
END
END</syntaxhighlight>
</syntaxhighlight>
{{out}}
<pre>
Unsigned Stirling numbers of the first kind:
k 0 1 2 3 4 5 6 7 8 9 10 11 12
n
0 1
1 0 1
2 0 1 1
3 0 2 3 1
4 0 6 11 6 1
5 0 24 50 35 10 1
6 0 120 274 225 85 15 1
7 0 720 1764 1624 735 175 21 1
8 0 5040 13068 13132 6769 1960 322 28 1
9 0 40320 109584 118124 67284 22449 4536 546 36 1
10 0 362880 1026576 1172700 723680 269325 63273 9450 870 45 1
11 0 3628800 10628640 12753576 8409500 3416930 902055 157773 18150 1320 55 1
12 0 39916800 120543840 150917976 105258076 45995730 13339535 2637558 357423 32670 1925 66 1
Maximum Stirling number of the first kind with n = 100:
19710908747055261109287881673376044669240511161402863823515728791076863288440277983854056472903481625299174865860036734731122707870406148096000000000000000000
Line 191 ⟶ 192:
 
=={{header|ALGOL W}}==
<syntaxhighlight lang="algolw">begin % show some (unsigned) Stirling numbers of the first kind %
begin % show some (unsigned) Stirling numbers of the first kind %
integer MAX_STIRLING;
MAX_STIRLING := 12;
Line 211 ⟶ 213:
% print the Stirling numbers up to n, k = 12 %
write( "Unsigned Stirling numbers of the first kind:" );
write( " k 0" );
for k := 01 until MAX_STIRLING do writeon( i_w := if k < 6 then 10 else 9, s_w := 0, k );
write( " n" );
for n := 0 until MAX_STIRLING do begin
write( i_w := 2, s_w := 0, n, i_w := 3, s1( n, 0 ) );
for k := 01 until n do begin
writeon( i_w := if k < 6 then 10 else 9, s_w := 0, s1( n, k ) )
end for_k
end for_n
end
end.
end.</syntaxhighlight>
</syntaxhighlight>
{{out}}
<pre>
Unsigned Stirling numbers of the first kind:
k 0 1 2 3 4 5 6 7 8 9 10 11 12
n
0 1
1 0 1
2 0 1 1
3 0 2 3 1
4 0 6 11 6 1
5 0 24 50 35 10 1
6 0 120 274 225 85 15 1
7 0 720 1764 1624 735 175 21 1
8 0 5040 13068 13132 6769 1960 322 28 1
9 0 40320 109584 118124 67284 22449 4536 546 36 1
10 0 362880 1026576 1172700 723680 269325 63273 9450 870 45 1
11 0 3628800 10628640 12753576 8409500 3416930 902055 157773 18150 1320 55 1
12 0 39916800 120543840 150917976 105258076 45995730 13339535 2637558 357423 32670 1925 66 1
</pre>
 
Line 471 ⟶ 474:
19710908747055261109287881673376044669240511161402863823515728791076863288440277983854056472903481625299174865860036734731122707870406148096000000000000000000
(158 digits, k = 5)</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
print "Unsigned Stirling numbers of the first kind:"
len a[] 13 ; arrbase a[] 0
len b[] 13 ; arrbase b[] 0
a[0] = 1
print 1
for n = 1 to 12
b[0] = 0
write 0 & " "
for k = 1 to n
b[k] = a[k - 1] + (n - 1) * a[k]
write b[k] & " "
.
print ""
swap a[] b[]
.
</syntaxhighlight>
 
=={{header|Factor}}==
Line 1,118 ⟶ 1,140:
19710908747055261109287881673376044669240511161402863823515728791076863288440277983854056472903481625299174865860036734731122707870406148096000000000000000000
(158 digits, k = 5)</pre>
 
=={{header|Lua}}==
<syntaxhighlight lang="lua">
do -- show some (unsigned) Stirling numbers of the first kind
local MAX_STIRLING = 12
-- construct a matrix of Stirling numbers up to max n, max n
local s1 = {}
for n = 0, MAX_STIRLING do
s1[ n ] = {}
for k = 0, MAX_STIRLING do s1[ n ][ k ] = 0 end
end
s1[ 0 ][ 0 ] = 1
for n = 1, MAX_STIRLING do s1[ n ][ 0 ] = 0 end
for n = 1, MAX_STIRLING do
for k = 1, n do
local s1Term = ( ( n - 1 ) * s1[ n - 1 ][ k ] )
s1[ n ][ k ] = s1[ n - 1 ][ k - 1 ] + s1Term
end
end
io.write( "Unsigned Stirling numbers of the first kind:\n" )
io.write( " k 0" )
for k = 1, MAX_STIRLING do
io.write( string.format( ( k < 6 and "%10d" or "%9d" ), k ) )
end
io.write( "\n" )
io.write( " n\n" );
for n = 0, MAX_STIRLING do
io.write( string.format( "%2d", n ), string.format( "%3d", s1[ n ][ 0 ] ) )
for k = 1, n do
io.write( string.format( ( k < 6 and "%10d" or "%9d" ), s1[ n ][ k ] ) )
end
io.write( "\n" )
end
end
</syntaxhighlight>
{{out}}
<pre>
Unsigned Stirling numbers of the first kind:
k 0 1 2 3 4 5 6 7 8 9 10 11 12
n
0 1
1 0 1
2 0 1 1
3 0 2 3 1
4 0 6 11 6 1
5 0 24 50 35 10 1
6 0 120 274 225 85 15 1
7 0 720 1764 1624 735 175 21 1
8 0 5040 13068 13132 6769 1960 322 28 1
9 0 40320 109584 118124 67284 22449 4536 546 36 1
10 0 362880 1026576 1172700 723680 269325 63273 9450 870 45 1
11 0 3628800 10628640 12753576 8409500 3416930 902055 157773 18150 1320 55 1
12 0 39916800 120543840 150917976 105258076 45995730 13339535 2637558 357423 32670 1925 66 1
</pre>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
Line 1,681 ⟶ 1,757:
The maximum value (which has 158 decimal digits):
19710908747055261109287881673376044669240511161402863823515728791076863288440277983854056472903481625299174865860036734731122707870406148096000000000000000000
</pre>
 
=={{header|RPL}}==
« '''IF''' DUP2 AND NOT '''THEN''' ==
'''ELSE'''
SWAP 1 - DUP ROT
DUP2 1 - <span style="color:blue">US1</span> 4 ROLLD <span style="color:blue">US1</span> * +
'''END'''
» '<span style="color:blue">US1</span>' STO <span style="color:grey">''@ ( n k → unsigned S1(n,k) )''</span>
« { 12 12 } 0 CON
1 12 '''FOR''' n
1 n '''FOR''' k
n k 2 →LIST DUP EVAL <span style="color:blue">US1</span> PUT
'''NEXT NEXT'''
» '<span style="color:blue">TASK</span>' STO
{{out}}
<pre>
1: [[ 1 0 0 0 0 0 0 0 0 0 0 0 ]
[ 1 1 0 0 0 0 0 0 0 0 0 0 ]
[ 2 3 1 0 0 0 0 0 0 0 0 0 ]
[ 6 11 6 1 0 0 0 0 0 0 0 0 ]
[ 24 50 35 10 1 0 0 0 0 0 0 0 ]
[ 120 274 225 85 15 1 0 0 0 0 0 0 ]
[ 720 1764 1624 735 175 21 1 0 0 0 0 0 ]
[ 5040 13068 13132 6769 1960 322 28 1 0 0 0 0 ]
[ 40320 109584 118124 67284 22449 4536 546 36 1 0 0 0 ]
[ 362880 1026576 1172700 723680 269325 63273 9450 870 45 1 0 0 ]
[ 3628800 10628640 12753576 8409500 3416930 902055 157773 18150 1320 55 1 0 ]
[ 39916800 120543840 150917976 105258076 45995730 13339535 2637558 357423 32670 1925 66 1 ]]
</pre>
 
Line 1,885 ⟶ 1,991:
{{trans|Java}}{{libheader|Wren-big}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./big" for BigInt
import "./fmt" for Fmt
 
var computed = {}
1,150

edits