Class LogBinomialCoefficient


  • public final class LogBinomialCoefficient
    extends java.lang.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 int LIMIT_M_DOUBLE
      The maximum m that can be computed without overflow of a double for any n.
      private static int LIMIT_N_DOUBLE
      The maximum n that can be computed without overflow of a double for an m.
      private static int LIMIT_N_LONG
      The maximum n that can be computed without overflow of a long for any m.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private LogBinomialCoefficient()
      Private constructor.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      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 Detail

      • 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:
        Constant Field Values
      • 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:
        Constant Field Values
      • 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:
        Constant Field Values
    • Constructor Detail

      • LogBinomialCoefficient

        private LogBinomialCoefficient()
        Private constructor.
    • Method Detail

      • 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:
        java.lang.IllegalArgumentException - if n < 0, k < 0 or k > n.