Class Combinatorics

java.lang.Object
org.episteme.core.mathematics.discrete.Combinatorics

public class Combinatorics extends Object
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 Details

    • Combinatorics

      public Combinatorics()
  • Method Details

    • factorial

      public static BigInteger factorial(int n)
      Computes n! (factorial).
      Parameters:
      n - non-negative integer
      Returns:
      n!
    • binomial

      public static BigInteger binomial(int n, int k)
      Computes binomial coefficient C(n, k) = n! / (k! * (n-k)!). Also known as "n choose k".
      Parameters:
      n - total items
      k - items to choose
      Returns:
      binomial coefficient
    • permutations

      public static BigInteger permutations(int n, int k)
      Computes the number of permutations P(n, k) = n! / (n-k)!.
      Parameters:
      n - total items
      k - items to arrange
      Returns:
      number of permutations
    • catalan

      public static BigInteger catalan(int n)
      Computes Catalan number C_n = (2n)! / ((n+1)! * n!).
      Parameters:
      n - index
      Returns:
      nth Catalan number
    • stirling2

      public static BigInteger stirling2(int n, int k)
      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 objects
      k - number of subsets
      Returns:
      Stirling number S(n, k)
    • pascalTriangle

      public static BigInteger[][] pascalTriangle(int n)
      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

      public static BigInteger multinomial(int n, int... groups)
      Computes multinomial coefficient n! / (k1! * k2! * ... * km!).
      Parameters:
      n - total items
      groups - 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 items
      k - items to choose
      m - modulus (should be prime for Lucas' theorem)
      Returns:
      C(n, k) mod m
    • centralBinomial

      public static BigInteger centralBinomial(int n)
      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 items
      k - 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 items
      k - items to choose
      Returns:
      true if Pascal's identity holds