stirlingS2(): Stirling Numbers of the Second Kind
stirlingS2(n, k) counts ways to partition n labeled items into k nonempty unlabeled groups. It is a core combinatorics function used in grouping and recurrence problems.
Valid parameters
n and k should be nonnegative integers, with k no larger than n for ordinary nonzero cases. For example, stirlingS2(3, 2) is 3. Use bellNumbers() to count partitions across all possible group counts.
Compare with combinations() and permutations(): those select or order items, while Stirling numbers partition every item. Values grow quickly, so retain exact integer arithmetic where possible.