Skip to main content

stirling_second_kind

Function stirling_second_kind 

Source
pub fn stirling_second_kind(n: u64, k: u64) -> Result<u64, CombinatoricsError>
Expand description

Count surjections from an n-element set onto a k-element set: the Stirling number of the second kind S(n, k), i.e. the number of ways to partition n labelled elements into exactly k non-empty unlabelled blocks (a surjection onto k elements is exactly a choice of which block maps to which target element, and blocks are otherwise interchangeable until that assignment – so partitioning first and multiplying by k! elsewhere gives the surjection count; this function returns the partition count alone).

§Formula

S(n, k) = k * S(n-1, k) + S(n-1, k-1), with S(0, 0) = 1, S(n, 0) = 0 for n > 0, and S(n, k) = 0 for k > n.