Class LogBinomialCoefficient

java.lang.Object
org.apache.commons.numbers.combinatorics.LogBinomialCoefficient

public final class LogBinomialCoefficient extends Object
Natural logarithm of the binomial coefficient. It is "n choose k", the number of k-element subsets that can be selected from an n-element set.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final int
    The maximum m that can be computed without overflow of a double for any n.
    private static final int
    The maximum n that can be computed without overflow of a double for an m.
    private static final int
    The maximum n that can be computed without overflow of a long for any m.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Private constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    value(int n, int k)
    Computes the logarithm of the binomial coefficient.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LIMIT_N_LONG

      private static final int LIMIT_N_LONG
      The maximum n that can be computed without overflow of a long for any m. C(66, 33) < 2^63.
      See Also:
    • LIMIT_N_DOUBLE

      private static final int LIMIT_N_DOUBLE
      The maximum n that can be computed without overflow of a double for an m. C(1029, 514) ~ 1.43e308.
      See Also:
    • LIMIT_M_DOUBLE

      private static final int LIMIT_M_DOUBLE
      The maximum m that can be computed without overflow of a double for any n. C(2147483647, 37) ~ 1.39e302.
      See Also:
  • Constructor Details

    • LogBinomialCoefficient

      private LogBinomialCoefficient()
      Private constructor.
  • Method Details

    • value

      public static double value(int n, int k)
      Computes the logarithm of the binomial coefficient.

      This returns a finite result for any valid n choose k.

      Parameters:
      n - Size of the set.
      k - Size of the subsets to be counted.
      Returns:
      log(n choose k).
      Throws:
      IllegalArgumentException - if n < 0, k < 0 or k > n.