Skip to content

Stirling numbers by recursion

Vector 8:1, page 95

mathematics and statistics programming techniques

Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 95

David Appleton in his article on generating Stirling Numbers of the second kind (Vol.7 No.4) concludes that it may be appropriate to use the recurrence relation:

\[\begin{equation*} \sigma^{n}_{t} = n\,\sigma^{n}_{t-1} + \sigma^{n-1}_{t-1} \end{equation*}\]

I agree, but surely the appropriate development is a recursive function, e.g. ST0 below which generates the nth row of the table:

[0]   Z←ST0 N;T
[1]   →0 IF N=Z←1
[2]   Z←(¯1⌽T)+(⍳N)×T←(ST0 N-1),0

If the entire table is required, use

[0]   Z←ST1 N;T;U
[1]   →0 IF N=↑Z←1 1⍴1
[2]   Z←U,[1](¯1⌽T)+(⍳N)×T←,(¯,N)↑U←(ST1 N-1),0

which contains redundant zeros in its upper triangle but could trivially be transformed to David’s compressed table where Stirling rows are read as diagonals.

Norman Thomson
IBM UK Laboratories Ltd