Class Stirling
- java.lang.Object
-
- org.apache.commons.numbers.combinatorics.Stirling
-
public final class Stirling extends Object
Computation of Stirling numbers.- Since:
- 1.2
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static long
stirlingS1(int n, int k)
Returns the signed Stirling number of the first kind, "s(n,k)
".static long
stirlingS2(int n, int k)
Returns the Stirling number of the second kind, "S(n,k)
", the number of ways of partitioning ann
-element set intok
non-empty subsets.
-
-
-
Method Detail
-
stirlingS1
public static long stirlingS1(int n, int k)
Returns the signed Stirling number of the first kind, "s(n,k)
". The number of permutations ofn
elements which contain exactlyk
permutation cycles is the nonnegative number:|s(n,k)| = (-1)^(n-k) s(n,k)
- Parameters:
n
- Size of the setk
- Number of permutation cycles (0 <= k <= n
)- Returns:
s(n,k)
- Throws:
IllegalArgumentException
- ifn < 0
,k < 0
ork > n
.ArithmeticException
- if some overflow happens, typically for n exceeding 20 (s(n,n-1) is handled specifically and does not overflow)
-
stirlingS2
public static long stirlingS2(int n, int k)
Returns the Stirling number of the second kind, "S(n,k)
", the number of ways of partitioning ann
-element set intok
non-empty subsets.- Parameters:
n
- Size of the setk
- Number of non-empty subsets (0 <= k <= n
)- Returns:
S(n,k)
- Throws:
IllegalArgumentException
- ifn < 0
,k < 0
ork > n
.ArithmeticException
- if some overflow happens, typically for n exceeding 25 and k between 20 and n-2 (S(n,n-1) is handled specifically and does not overflow)
-
-