Bell numbers: Difference between revisions

Content added Content deleted
(add RPL)
imported>Maxima enthusiast
No edit summary
Line 2,567: Line 2,567:
36401, 43833, 52922, 64077, 77821, 94828, 115975}}
36401, 43833, 52922, 64077, 77821, 94828, 115975}}
</syntaxhighlight>
</syntaxhighlight>

=={{header|Maxima}}==
It exists in Maxima the belln built-in function.

Below is another way
<syntaxhighlight lang="maxima">
/* Subfactorial numbers */
subfactorial(n):=block(
subf[0]:1,
subf[n]:n*subf[n-1]+(-1)^n,
subf[n])$

/* Bell numbers implementation */
my_bell(n):=if n=0 then 1 else block(
makelist((1/((n-1)!))*subfactorial(j)*binomial(n-1,j)*(n-j)^(n-1),j,0,n-1),
apply("+",%%))$

/* First 50 */
block(
makelist(my_bell(u),u,0,49),
table_form(%%));
</syntaxhighlight>
{{out}}
<pre>
matrix(
[1],
[1],
[2],
[5],
[15],
[52],
[203],
[877],
[4140],
[21147],
[115975],
[678570],
[4213597],
[27644437],
[190899322],
[1382958545],
[10480142147],
[82864869804],
[682076806159],
[5832742205057],
[51724158235372],
[474869816156751],
[4506715738447323],
[44152005855084346],
[445958869294805289],
[4638590332229999353],
[49631246523618756274],
[545717047936059989389],
[6160539404599934652455],
[71339801938860275191172],
[846749014511809332450147],
[10293358946226376485095653],
[128064670049908713818925644],
[1629595892846007606764728147],
[21195039388640360462388656799],
[281600203019560266563340426570],
[3819714729894818339975525681317],
[52868366208550447901945575624941],
[746289892095625330523099540639146],
[10738823330774692832768857986425209],
[157450588391204931289324344702531067],
[2351152507740617628200694077243788988],
[35742549198872617291353508656626642567],
[552950118797165484321714693280737767385],
[8701963427387055089023600531855797148876],
[139258505266263669602347053993654079693415],
[2265418219334494002928484444705392276158355],
[37450059502461511196505342096431510120174682],
[628919796303118415420210454071849537746015761],
[10726137154573358400342215518590002633917247281]
)
</pre>


=={{header|Modula-2}}==
=={{header|Modula-2}}==