Calculates number of ways to partition a group of elements into a subgroups.