# Stirling2: Compute Stirling numbers of the second kind In multicool: Permutations of Multisets in Cool-Lex Order

## Description

This function computes Stirling numbers of the second kind, S(n, k), which count the number of ways of partitioning n distinct objects in to k non-empty sets.

## Usage

 ```1 2``` ```Stirling2(n, k) S2(n, k) ```

## Arguments

 `n` A vector of one or more positive integers `k` A vector of one or more positive integers

## Details

The implementation on this function is a simple recurrence relation which defines

S(n, k) = kS(n - 1, k), + S(n - 1, k - 1)

for k > 0 with the inital conditions S(0, 0) = 1 and S(n, 0) = S(0, n) = 0. If `n` and `n` have different lengths then `expand.grid` is used to construct a vector of (n, k) pairs

## Value

An vector of Stirling numbers of the second kind

James Curran

## Examples

 ```1 2 3 4 5 6 7 8``` ```## returns S(6, 3) Stirling2(6, 3) ## returns S(6,1), S(6,2), ..., S(6,6) S2(6, 1:6) ## returns S(6,1), S(5, 2), S(4, 3) S2(6:4, 1:3) ```

multicool documentation built on May 30, 2017, 5:51 a.m.