Documentation of 'umontreal.iro.lecuyer.util.Num' Java class
Num
umontreal.iro.lecuyer.util

Class Num



  • public class Num
    extends java.lang.Object
    This class provides a few constants and some methods to compute numerical quantities such as factorials, combinations, gamma functions, and so on.
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static int DBL_DIG
      Number of decimal digits of precision in a double.
      static double DBL_EPSILON
      Difference between 1.0 and the smallest double greater than 1.0.
      static int DBL_MAX_10_EXP
      Largest int x such that 10x is representable (approximately) as a double.
      static int DBL_MAX_EXP
      Largest int x such that 2x-1 is representable (approximately) as a double.
      static double DBL_MIN
      Smallest normalized positive floating-point double.
      static int DBL_MIN_EXP
      Smallest int x such that 2x-1 is representable (approximately) as a normalised double.
      static double EBASE
      The constant e.
      static double EULER
      The Euler-Mascheroni constant.
      static double ILN2
      The values of 1/ln 2.
      static double IRAC2
      The value of 1/(2)1/2.
      static double LN_DBL_MIN
      Natural logarithm of DBL_MIN.
      static double LN2
      The values of ln 2.
      static double MAXINTDOUBLE
      Largest integer n0 = 253 such that any integer n <= n0 is represented exactly as a double.
      static double MAXTWOEXP
      Powers of 2 up to MAXTWOEXP are stored exactly in the array TWOEXP.
      static double RAC2
      The value of (2)1/2.
      static double[] TEN_NEG_POW
      Contains the precomputed negative powers of 10.
      static double[] TWOEXP
      Contains the precomputed positive powers of 2.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static double bernoulliPoly(int n, double x)
      Evaluates the Bernoulli polynomial Bn(x) of degree n at x.
      static double besselK025(double x)
      Returns the value of K1/4(x), where Ka is the modified Bessel's function of the second kind.
      static double[][] calcMatStirling(int m, int n)
      Computes and returns the Stirling numbers of the second kind
      static double combination(int n, int s)
      Returns the number of different combinations of s objects amongst n.
      static double digamma(double x)
      Returns the value of the logarithmic derivative of the Gamma function ψ(x) = Γ'(x)/Γ(x).
      static double erf(double x)
      Returns the value of erf(x), the error function.
      static double erfc(double x)
      Returns the value of erfc(x), the complementary error function.
      static double erfInv(double x)
      Returns the value of y = erf-1(x), the inverse of the error function such that x = erf(y).
      static double evalCheby(double[] a, int n, double x)
      Evaluates a series of Chebyshev polynomials Tj at x over the basic interval [- 1,  1].
      static double evalChebyStar(double[] a, int n, double x)
      Evaluates a series of shifted Chebyshev polynomials Tj* at x over the basic interval [0,  1].
      static double expBesselK1(double x, double y)
      Returns the value of exK1(y), where K1 is the modified Bessel function of the second kind of order 1.
      static double factorial(int n)
      Returns the value of factorial n.
      static double gammaRatioHalf(double x)
      Returns the value of the ratio Γ(x + 1/2)/Γ(x) of two gamma functions, evaluated in a numerically stable way.
      static int gcd(int x, int y)
      Returns the greatest common divisor (gcd) of x and y.
      static long gcd(long x, long y)
      Returns the greatest common divisor (gcd) of x and y.
      static double harmonic(long n)
      Computes the n-th harmonic number Hn = ∑j=1n1/j.
      static double harmonic2(long n)
      .
      static double lnBeta(double lam, double nu)
      Computes the natural logarithm of the Beta function B(λ, ν).
      static double lnFactorial(int n)
      Returns the value of the natural logarithm of factorial n.
      static double lnGamma(double x)
      Returns the natural logarithm of the gamma function Γ(x) evaluated at x.
      static double log2(double x)
      Returns log2(x).
      static double tetragamma(double x)
      Returns the value of the tetragamma function d2ψ(x)/d2x, the second derivative of the digamma function, evaluated at x.
      static double trigamma(double x)
      Returns the value of the trigamma function (x)/dx, the derivative of the digamma function, evaluated at x.
      static double volumeSphere(double p, int t)
      Returns the volume V of a sphere of radius 1 in t dimensions using the norm Lp.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DBL_EPSILON

        public static final double DBL_EPSILON
        Difference between 1.0 and the smallest double greater than 1.0.
        See Also:
        Constant Field Values
      • DBL_MAX_EXP

        public static final int DBL_MAX_EXP
        Largest int x such that 2x-1 is representable (approximately) as a double.
        See Also:
        Constant Field Values
      • DBL_MIN_EXP

        public static final int DBL_MIN_EXP
        Smallest int x such that 2x-1 is representable (approximately) as a normalised double.
        See Also:
        Constant Field Values
      • DBL_MAX_10_EXP

        public static final int DBL_MAX_10_EXP
        Largest int x such that 10x is representable (approximately) as a double.
        See Also:
        Constant Field Values
      • DBL_MIN

        public static final double DBL_MIN
        Smallest normalized positive floating-point double.
        See Also:
        Constant Field Values
      • LN_DBL_MIN

        public static final double LN_DBL_MIN
        Natural logarithm of DBL_MIN.
        See Also:
        Constant Field Values
      • DBL_DIG

        public static final int DBL_DIG
        Number of decimal digits of precision in a double.
        See Also:
        Constant Field Values
      • MAXINTDOUBLE

        public static final double MAXINTDOUBLE
        Largest integer n0 = 253 such that any integer n <= n0 is represented exactly as a double.
        See Also:
        Constant Field Values
      • MAXTWOEXP

        public static final double MAXTWOEXP
        Powers of 2 up to MAXTWOEXP are stored exactly in the array TWOEXP.
        See Also:
        Constant Field Values
      • TWOEXP

        public static final double[] TWOEXP
        Contains the precomputed positive powers of 2. One has TWOEXP[j]= 2j, for j = 0,..., 64.
      • TEN_NEG_POW

        public static final double[] TEN_NEG_POW
        Contains the precomputed negative powers of 10. One has TEN_NEG_POW[j]= 10-j, for j = 0,…, 16.
    • Method Detail

      • gcd

        public static int gcd(int x,
                              int y)
        Returns the greatest common divisor (gcd) of x and y.
        Parameters:
        x - integer
        y - integer
        Returns:
        the GCD of x and y
      • gcd

        public static long gcd(long x,
                               long y)
        Returns the greatest common divisor (gcd) of x and y.
        Parameters:
        x - integer
        y - integer
        Returns:
        the GCD of x and y
      • combination

        public static double combination(int n,
                                         int s)
        Returns the number of different combinations of s objects amongst n. Uses an algorithm that prevents overflows (when computing factorials), if possible.
        Parameters:
        n - total number of objects
        s - number of chosen objects on a combination
        Returns:
        the number of different combinations of s objects amongst n
      • factorial

        public static double factorial(int n)
        Returns the value of factorial n.
        Parameters:
        n - the integer for which the factorial must be computed
        Returns:
        the value of n!
      • lnFactorial

        public static double lnFactorial(int n)
        Returns the value of the natural logarithm of factorial n. Gives 16 decimals of precision (relative error < 0.5×10-15).
        Parameters:
        n - the integer for which the log-factorial has to be computed
        Returns:
        the natural logarithm of n factorial
      • calcMatStirling

        public static double[][] calcMatStirling(int m,
                                                 int n)
        Computes and returns the Stirling numbers of the second kind
        Parameters:
        m - number of rows of the allocated matrix
        n - number of columns of the allocated matrix
        Returns:
        the matrix of Stirling numbers
      • log2

        public static double log2(double x)
        Returns log2(x).
        Parameters:
        x - the value for which the logarithm must be computed
        Returns:
        the value of log2(x)
      • lnGamma

        public static double lnGamma(double x)
        Returns the natural logarithm of the gamma function Γ(x) evaluated at x. Gives 16 decimals of precision, but is implemented only for x > 0.
        Parameters:
        x - the value for which the lnGamma function must be computed
        Returns:
        the natural logarithm of the gamma function
      • lnBeta

        public static double lnBeta(double lam,
                                    double nu)
        Computes the natural logarithm of the Beta function B(λ, ν). It is defined in terms of the Gamma function as

        B(λ, ν) = $\displaystyle {\frac{{\Gamma(\lambda)\Gamma(\nu)}}{{\Gamma(\lambda + \nu)}}}$

        with lam = λ and nu = ν.
      • digamma

        public static double digamma(double x)
        Returns the value of the logarithmic derivative of the Gamma function ψ(x) = Γ'(x)/Γ(x).
      • trigamma

        public static double trigamma(double x)
        Returns the value of the trigamma function (x)/dx, the derivative of the digamma function, evaluated at x.
      • tetragamma

        public static double tetragamma(double x)
        Returns the value of the tetragamma function d2ψ(x)/d2x, the second derivative of the digamma function, evaluated at x.
      • gammaRatioHalf

        public static double gammaRatioHalf(double x)
        Returns the value of the ratio Γ(x + 1/2)/Γ(x) of two gamma functions, evaluated in a numerically stable way. Restriction: x > 0.
      • harmonic

        public static double harmonic(long n)
        Computes the n-th harmonic number Hn = ∑j=1n1/j.
      • harmonic2

        public static double harmonic2(long n)
        . Computes the sum

        $\displaystyle \sideset{}{'}\htsum_{{-n/2<j\le n/2}}^{}$  $\displaystyle {\frac{1}{{\vert j\vert}}}$,

        where the symbol means that the term with j = 0 is excluded from the sum.
      • volumeSphere

        public static double volumeSphere(double p,
                                          int t)
        Returns the volume V of a sphere of radius 1 in t dimensions using the norm Lp. It is given by the formula

        V = ([2Γ(1 + 1/p)]t)/Γ(1 + t/p),        p > 0,

        where Γ is the gamma function. The case of the sup norm L is obtained by choosing p = 0. Restrictions: p >=  0 and t >= 1.
        Parameters:
        p - index of the used norm
        t - number of dimensions
        Returns:
        the volume of a sphere
      • bernoulliPoly

        public static double bernoulliPoly(int n,
                                           double x)
        Evaluates the Bernoulli polynomial Bn(x) of degree n at x. Only degrees n <= 8 are programmed for now. The first Bernoulli polynomials of even degree are:
        B0(x) = 1  
        B2(x) = x2 - x + 1/6  
        B4(x) = x4 -2x3 + x2 - 1/30  
        B6(x) = x6 -3x5 +5x4/2 - x2/2 + 1/42  
        B8(x) = x8 -4x7 +14x6/3 - 7x4/3 + 2x2/3 - 1/30.  

      • evalCheby

        public static double evalCheby(double[] a,
                                       int n,
                                       double x)
        Evaluates a series of Chebyshev polynomials Tj at x over the basic interval [- 1,  1]. It uses the method of Clenshaw, i.e., computes and returns

        y = $\displaystyle {\frac{{a_0}}{2}}$ + ∑j=1najTj(x).

        Parameters:
        a - coefficients of the polynomials
        n - largest degree of polynomials
        x - the parameter of the Tj functions
        Returns:
        the value of a series of Chebyshev polynomials Tj.
      • evalChebyStar

        public static double evalChebyStar(double[] a,
                                           int n,
                                           double x)
        Evaluates a series of shifted Chebyshev polynomials Tj* at x over the basic interval [0,  1]. It uses the method of Clenshaw, i.e., computes and returns

        y = [tex2html_wrap_indisplay679] + ∑j=1najTj*(x).

        Parameters:
        a - coefficients of the polynomials
        n - largest degree of polynomials
        x - the parameter of the Tj* functions
        Returns:
        the value of a series of Chebyshev polynomials Tj*.
      • besselK025

        public static double besselK025(double x)
        Returns the value of K1/4(x), where Ka is the modified Bessel's function of the second kind. The relative error on the returned value is less than 0.5×10-6 for x > 10-300.
        Parameters:
        x - value at which the function is calculated
        Returns:
        the value of K1/4(x)
      • expBesselK1

        public static double expBesselK1(double x,
                                         double y)
        Returns the value of exK1(y), where K1 is the modified Bessel function of the second kind of order 1. Restriction: y > 0.
      • erf

        public static double erf(double x)
        Returns the value of erf(x), the error function. It is defined as

        erf(x) = 2/[(π)1/2]∫0xdt e-t2.

        Parameters:
        x - value at which the function is calculated
        Returns:
        the value of erf(x)
      • erfc

        public static double erfc(double x)
        Returns the value of erfc(x), the complementary error function. It is defined as

        erfc(x) = 2/[(π)1/2]∫xdt e-t2.

        Parameters:
        x - value at which the function is calculated
        Returns:
        the value of erfc(x)
      • erfInv

        public static double erfInv(double x)
        Returns the value of y = erf-1(x), the inverse of the error function such that x = erf(y).
        Parameters:
        x - value at which the function is calculated
        Returns:
        the value of erfInv(x)

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.