5
$\begingroup$

Is there an efficient way to numerically compute Stirling numbers of the second kind?

An approximate (not exact) method would suffice. Something similar to the connection between factorials and gamma functions would work for me.

I googled it a bit and didn't find anything too helpful.

$\endgroup$
7
$\begingroup$

You can use the following recurrence relation

$\mathop{S}\nolimits\left(n,k\right)=k\mathop{S}\nolimits\left(n-1,k\right)+\mathop{S}\nolimits\!\left(n-1,k-1\right)$

see DLMF equation 26.8.E22

and build the (triangular) table.

$\endgroup$
  • $\begingroup$ Is there some relationships between Stirling numbers of the second kind and some analytical functions? I can use an approximate value in my case. $\endgroup$ – Tianyang Li Mar 8 '12 at 23:17
  • 2
    $\begingroup$ there are asymptotics available. For these, you can also consult the DLMF or works by Nico Temme (N.M. Temme, "Asymptotic estimates of Stirling numbers", Stud. Appl. Math. 89, p233-243, 1993) $\endgroup$ – GertVdE Mar 9 '12 at 8:13
1
$\begingroup$

The accepted answer takes $O(kn)$ multiplications and additions. There is also a method using $O(k\log n)$ additions, multiplications and divisions, using the below identity: $$ S(n,k)=\frac1{k!}\sum_{j=0}^k(-1)^j\binom{k}j(k-j)^n $$

Pseudocode:

accum ← 0
k_choose_j ← 1
for j = 0,1,...,k-1:
  accum ← accum + (-1)^j * k_choose_j * (k - j)^n
  k_choose_j ← k_choose_j * (k-j-1) / (j+1)
return accum / factorial(k)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.