umontreal.iro.lecuyer.util
Class Num
- java.lang.Object
-
- umontreal.iro.lecuyer.util.Num
-
public class Num extends java.lang.ObjectThis 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 intDBL_DIGNumber of decimal digits of precision in a double.static doubleDBL_EPSILONDifference between 1.0 and the smallest double greater than 1.0.static intDBL_MAX_10_EXPLargest int x such that 10x is representable (approximately) as a double.static intDBL_MAX_EXPLargest int x such that 2x-1 is representable (approximately) as a double.static doubleDBL_MINSmallest normalized positive floating-point double.static intDBL_MIN_EXPSmallest int x such that 2x-1 is representable (approximately) as a normalised double.static doubleEBASEThe constant e.static doubleEULERThe Euler-Mascheroni constant.static doubleILN2The values of 1/ln 2.static doubleIRAC2The value of 1/(2)1/2.static doubleLN_DBL_MINNatural logarithm of DBL_MIN.static doubleLN2The values of ln 2.static doubleMAXINTDOUBLELargest integer n0 = 253 such that any integer n <= n0 is represented exactly as a double.static doubleMAXTWOEXPPowers of 2 up to MAXTWOEXP are stored exactly in the array TWOEXP.static doubleRAC2The value of (2)1/2.static double[]TEN_NEG_POWContains the precomputed negative powers of 10.static double[]TWOEXPContains the precomputed positive powers of 2.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static doublebernoulliPoly(int n, double x)Evaluates the Bernoulli polynomial Bn(x) of degree n at x.static doublebesselK025(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 kindstatic doublecombination(int n, int s)Returns the number of different combinations of s objects amongst n.static doubledigamma(double x)Returns the value of the logarithmic derivative of the Gamma function ψ(x) = Γ'(x)/Γ(x).static doubleerf(double x)Returns the value of erf(x), the error function.static doubleerfc(double x)Returns the value of erfc(x), the complementary error function.static doubleerfInv(double x)Returns the value of y = erf-1(x), the inverse of the error function such that x = erf(y).static doubleevalCheby(double[] a, int n, double x)Evaluates a series of Chebyshev polynomials Tj at x over the basic interval [- 1, 1].static doubleevalChebyStar(double[] a, int n, double x)Evaluates a series of shifted Chebyshev polynomials Tj* at x over the basic interval [0, 1].static doubleexpBesselK1(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 doublefactorial(int n)Returns the value of factorial n.static doublegammaRatioHalf(double x)Returns the value of the ratio Γ(x + 1/2)/Γ(x) of two gamma functions, evaluated in a numerically stable way.static intgcd(int x, int y)Returns the greatest common divisor (gcd) of x and y.static longgcd(long x, long y)Returns the greatest common divisor (gcd) of x and y.static doubleharmonic(long n)Computes the n-th harmonic number Hn = ∑j=1n1/j.static doubleharmonic2(long n).static doublelnBeta(double lam, double nu)Computes the natural logarithm of the Beta function B(λ, ν).static doublelnFactorial(int n)Returns the value of the natural logarithm of factorial n.static doublelnGamma(double x)Returns the natural logarithm of the gamma function Γ(x) evaluated at x.static doublelog2(double x)Returns log2(x).static doubletetragamma(double x)Returns the value of the tetragamma function d2ψ(x)/d2x, the second derivative of the digamma function, evaluated at x.static doubletrigamma(double x)Returns the value of the trigamma function dψ(x)/dx, the derivative of the digamma function, evaluated at x.static doublevolumeSphere(double p, int t)Returns the volume V of a sphere of radius 1 in t dimensions using the norm Lp.
-
-
-
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
-
EBASE
public static final double EBASE
The constant e.- See Also:
- Constant Field Values
-
EULER
public static final double EULER
The Euler-Mascheroni constant.- See Also:
- Constant Field Values
-
RAC2
public static final double RAC2
The value of (2)1/2.- See Also:
- Constant Field Values
-
IRAC2
public static final double IRAC2
The value of 1/(2)1/2.- See Also:
- Constant Field Values
-
LN2
public static final double LN2
The values of ln 2.- See Also:
- Constant Field Values
-
ILN2
public static final double ILN2
The values of 1/ln 2.- 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- integery- 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- integery- 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 objectss- 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 matrixn- 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 asB(λ, ν) =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 dψ(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 sumwhere 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 formulaV = ([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 normt- number of dimensions- Returns:
- the volume of a sphere
-
bernoulliPoly
public static double bernoulliPoly(int n, double x)
-
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 returnsy =
+ ∑j=1najTj(x).
- Parameters:
a- coefficients of the polynomialsn- largest degree of polynomialsx- 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 returnsy = [tex2html_wrap_indisplay679] + ∑j=1najTj*(x).- Parameters:
a- coefficients of the polynomialsn- largest degree of polynomialsx- 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 aserf(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 aserfc(x) = 2/[(π)1/2]∫x∞dt 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