Essays/Stirling Numbers

From J Wiki
Jump to navigation Jump to search

Stirling numbers of the first kind and of the second kind can be computed as follows:

   s1=: 1: ` (<:    ((0,]) + [ * ],0:) $:@<:) @. *
   s2=: 1: ` (i.@>: ((0,]) + [ * ],0:) $:@<:) @. *

   s1"0 i.7
1   0   0   0  0  0 0
0   1   0   0  0  0 0
0   1   1   0  0  0 0
0   2   3   1  0  0 0
0   6  11   6  1  0 0
0  24  50  35 10  1 0
0 120 274 225 85 15 1
   s2"0 i.7
1 0  0  0  0  0 0
0 1  0  0  0  0 0
0 1  1  0  0  0 0
0 1  3  1  0  0 0
0 1  7  6  1  0 0
0 1 15 25 10  1 0
0 1 31 90 65 15 1

The Stirling numbers of the first and second kinds are related in a simple way:

   %. s2"0 i.7
1    0   0    0   0   0 0
0    1   0    0   0   0 0
0   _1   1    0   0   0 0
0    2  _3    1   0   0 0
0   _6  11   _6   1   0 0
0   24 _50   35 _10   1 0
0 _120 274 _225  85 _15 1

   (s1"0 i.7) -: | %. s2"0 i.7
1
   (s2"0 i.7) -: | %. s1"0 i.7
1

That is, the table of Stirling numbers of one kind are the absolute values of the matrix inverse of the table of Stirling numbers of the other kind.



See also

of the first kind and of the second kind



Contributed by Roger Hui. s1 and s2 are slightly modified from Roger Hui and Kenneth E. Iverson, Representations of Recursion, APL95 Conference Proceedings, June 1995.