Class Combinatorics
java.lang.Object
org.episteme.core.mathematics.discrete.Combinatorics
Combinatorial functions and utilities.
Provides methods for counting, permutations, combinations, and binomial coefficients.
- Since:
- 1.0
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BigIntegerbinomial(int n, int k) Computes binomial coefficient C(n, k) = n!static longbinomialMod(int n, int k, int m) Computes binomial coefficient modulo m using Lucas' theorem for prime m.static BigIntegercatalan(int n) Computes Catalan number C_n = (2n)!static BigIntegercentralBinomial(int n) Computes central binomial coefficient C(2n, n).static BigIntegerfactorial(int n) Computes n!static BigIntegermultinomial(int n, int... groups) Computes multinomial coefficient n!static BigInteger[][]pascalTriangle(int n) Computes Pascal's triangle up to row n.static BigIntegerpermutations(int n, int k) Computes the number of permutations P(n, k) = n!static BigIntegerstirling2(int n, int k) Computes Stirling number of the second kind S(n, k).static booleanverifyPascal(int n, int k) Verifies Pascal's identity: C(n, k) = C(n-1, k-1) + C(n-1, k).static booleanverifySymmetry(int n, int k) Verifies the symmetry property: C(n, k) = C(n, n-k).
-
Constructor Details
-
Combinatorics
public Combinatorics()
-
-
Method Details
-
factorial
Computes n! (factorial).- Parameters:
n- non-negative integer- Returns:
- n!
-
binomial
Computes binomial coefficient C(n, k) = n! / (k! * (n-k)!). Also known as "n choose k".- Parameters:
n- total itemsk- items to choose- Returns:
- binomial coefficient
-
permutations
Computes the number of permutations P(n, k) = n! / (n-k)!.- Parameters:
n- total itemsk- items to arrange- Returns:
- number of permutations
-
catalan
Computes Catalan number C_n = (2n)! / ((n+1)! * n!).- Parameters:
n- index- Returns:
- nth Catalan number
-
stirling2
Computes Stirling number of the second kind S(n, k). Represents the number of ways to partition n objects into k non-empty subsets.- Parameters:
n- number of objectsk- number of subsets- Returns:
- Stirling number S(n, k)
-
pascalTriangle
Computes Pascal's triangle up to row n.- Parameters:
n- number of rows (0-indexed)- Returns:
- 2D array where triangle[i][j] = C(i, j)
-
multinomial
Computes multinomial coefficient n! / (k1! * k2! * ... * km!).- Parameters:
n- total itemsgroups- sizes of each group (must sum to n)- Returns:
- multinomial coefficient
-
binomialMod
public static long binomialMod(int n, int k, int m) Computes binomial coefficient modulo m using Lucas' theorem for prime m.- Parameters:
n- total itemsk- items to choosem- modulus (should be prime for Lucas' theorem)- Returns:
- C(n, k) mod m
-
centralBinomial
Computes central binomial coefficient C(2n, n).- Parameters:
n- the parameter- Returns:
- C(2n, n)
-
verifySymmetry
public static boolean verifySymmetry(int n, int k) Verifies the symmetry property: C(n, k) = C(n, n-k).- Parameters:
n- total itemsk- items to choose- Returns:
- true if symmetry holds
-
verifyPascal
public static boolean verifyPascal(int n, int k) Verifies Pascal's identity: C(n, k) = C(n-1, k-1) + C(n-1, k).- Parameters:
n- total itemsk- items to choose- Returns:
- true if Pascal's identity holds
-