<<   >>

43. Stirling Numbers

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

   s1←{0=⍵:,1 ⋄ (0,t)+(t,0)× ⍵-1⊣t←∇ ⍵-1}
   s2←{0=⍵:,1 ⋄ (0,t)+(t,0)×⍳⍵+1⊣t←∇ ⍵-1}

   s1⍤0 ⍳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 ⍳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 two kinds are related in a simple way:

   (s1⍤0 ⍳7) ≡ | ⌹ s2⍤0 ⍳7
1
   (s2⍤0 ⍳7) ≡ | ⌹ s1⍤0 ⍳7
1

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

   pascal← {0=⍵:,1 ⋄ (0,t)+(t,0)⊣t←∇ ⍵-1}

   pascal⍤0 ⍳7
1 0  0  0  0 0 0
1 1  0  0  0 0 0
1 2  1  0  0 0 0
1 3  3  1  0 0 0
1 4  6  4  1 0 0
1 5 10 10  5 1 0
1 6 15 20 15 6 1


Appeared in J in [119, 120].