SSJ API Documentation
Stochastic Simulation in Java
Loading...
Searching...
No Matches
umontreal.ssj.util.Num Class Reference

This class provides various constants and methods to compute numerical quantities such as factorials, combinations, gamma functions, and so on. More...

Static Public Member Functions

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 combination (int n, int s)
 Returns the value of \(\binom{n}{s}\), the number of different combinations of \(s\) objects amongst.
static double lnCombination (int n, int s)
 Returns the natural logarithm of.
static double factorial (int n)
 Returns the value of \(n!\).
static double lnFactorial (int n)
 Returns the value of \(\ln(n!)\), the natural logarithm of factorial \(n\).
static double lnFactorial (long n)
 Returns the value of \(\ln(n!)\), the natural logarithm of factorial \(n\).
static double factoPow (int n)
 Returns the value of \(n!/n^n\).
static double[][] calcMatStirling (int m, int n)
 Computes and returns the Stirling numbers of the second kind.
static double log2 (double x)
 Returns \(\log_2 (\)x \()\).
static double lnGamma (double x)
 Returns the natural logarithm of the gamma function \(\Gamma(x)\) evaluated at x.
static double lnBeta (double lam, double nu)
 Computes the natural logarithm of the Beta function \(B(\lambda, \nu)\).
static double digamma (double x)
 Returns the value of the logarithmic derivative of the Gamma function \(\psi(x) = \Gamma’(x) / \Gamma(x)\).
static double trigamma (double x)
 Returns the value of the trigamma function \(d\psi(x)/dx\), the derivative of the digamma function, evaluated at \(x\).
static double tetragamma (double x)
 Returns the value of the tetragamma function \(d^2\psi(x)/d^2x\), the second derivative of the digamma function, evaluated at \(x\).
static double gammaRatioHalf (double x)
 Returns the value of the ratio \(\Gamma(x+1/2)/\Gamma(x)\) of two gamma functions.
static double sumKahan (double[] A, int n)
 Implementation of the Kahan summation algorithm.
static double harmonic (long n)
 Computes the \(n\)-th harmonic number \(H_n = \sum_{j=1}^n 1/j\).
static double harmonic2 (long n)
 Computes the sum.
static double volumeSphere (double p, int t)
 Returns the volume \(V\) of a sphere of radius 1 in \(t\) dimensions using the norm \(L_p\).
static double bernoulliPoly (int n, double x)
 Evaluates the Bernoulli polynomial \(B_n(x)\) of degree \(n\) at.
static double evalCheby (double a[], int n, double x)
 Evaluates a series of Chebyshev polynomials \(T_j\) at \(x\) over the basic interval \([-1, \;1]\), using the method of Clenshaw [34] , i.e., computes and returns.
static double evalChebyStar (double a[], int n, double x)
 Evaluates a series of shifted Chebyshev polynomials \(T_j^*\) at.
static double besselK025 (double x)
 Returns the value of \(K_{1/4}(x)\), where.
static double expBesselK1 (double x, double y)
 Returns the value of \(e^x K_1(y)\), where \( K_1\) is the modified Bessel function of the second kind of order 1.
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 u)
 Returns the value of erf \({}^{-1}(u)\), the inverse of the error function.
static double erfcInv (double u)
 Returns the value of erfc \({}^{-1}(u)\), the inverse of the complementary error function.

Static Public Attributes

Constants @{
static final double DBL_EPSILON = 2.2204460492503131e-16
 Difference between 1.0 and the smallest double greater than 1.0.
static final int DBL_MAX_EXP = 1024
 Largest int \(x\) such that \(2^{x-1}\) is representable (approximately) as a double.
static final int DBL_MIN_EXP = -1021
 Smallest int \(x\) such that \(2^{x-1}\) is representable (approximately) as a normalised double.
static final int DBL_MAX_10_EXP = 308
 Largest int \(x\) such that \(10^x\) is representable (approximately) as a double.
static final double DBL_MIN = 2.2250738585072014e-308
 Smallest normalized positive floating-point double.
static final double LN_DBL_MIN = -708.3964185322641
 Natural logarithm of DBL_MIN.
static final int DBL_DIG = 15
 Number of decimal digits of precision in a double.
static final double EBASE = 2.7182818284590452354
 The constant \(e\).
static final double EULER = 0.57721566490153286
 The Euler-Mascheroni constant.
static final double RAC2 = 1.41421356237309504880
 The value of \(\sqrt{2}\).
static final double IRAC2 = 0.70710678118654752440
 The value of \(1/\sqrt{2}\).
static final double LN2 = 0.69314718055994530941
 The values of \(\ln2\).
static final double ILN2 = 1.44269504088896340737
 The values of \(1/\ln2\).
static final double MAXINTDOUBLE = 9007199254740992.0
 Largest integer \(n_0 = 2^{53}\) such that any integer \(n \le n_0\) is represented exactly as a double.
static final double MAXTWOEXP = 64
 Powers of 2 up to MAXTWOEXP are stored exactly in the array TWOEXP.
static final double TWOEXP []
 Contains the precomputed positive powers of 2.
static final double TEN_NEG_POW []
 Contains the precomputed negative powers of 10.

Detailed Description

This class provides various constants and methods to compute numerical quantities such as factorials, combinations, gamma functions, and so on.

Definition at line 35 of file Num.java.

Member Function Documentation

◆ bernoulliPoly()

double umontreal.ssj.util.Num.bernoulliPoly ( int n,
double x )
static

Evaluates the Bernoulli polynomial \(B_n(x)\) of degree \(n\) at.

\(x\). Only degrees \(n\le8\) are programmed for now. The first Bernoulli polynomials of even degree are:

\begin{align} B_0(x) & = 1 \nonumber \\ B_2(x) & = x^2-x+1/6 \nonumber \\ B_4(x) & = x^4-2x^3+x^2-1/30 \tag{bernoulli} \\ B_6(x) & = x^6-3x^5+5x^4/2-x^2/2+1/42 \nonumber \\ B_8(x) & = x^8-4x^7+14x^6/3 - 7x^4/3 +2x^2/3-1/30. \nonumber \end{align}

Definition at line 775 of file Num.java.

◆ besselK025()

double umontreal.ssj.util.Num.besselK025 ( double x)
static

Returns the value of \(K_{1/4}(x)\), where.

\(K_{\nu}\) is the modified Bessel’s function of the second kind. The relative error on the returned value is less than \(0.5\times10^{-6}\) for \(x > 10^{-300}\).

Parameters
xvalue at which the function is calculated
Returns
the value of \(K_{1/4}(x)\)

Definition at line 863 of file Num.java.

◆ calcMatStirling()

double[][] umontreal.ssj.util.Num.calcMatStirling ( int m,
int n )
static

Computes and returns the Stirling numbers of the second kind.

\[ M[i,j] = \left\{\begin{matrix} j \\ i \end{matrix}\right\} \quad\mbox{ for $0\le i\le m$ and $0\le i\le j\le n$}. \tag{Stirling2} \]

See [107]  (Section 1.2.6). The matrix \(M\) is the transpose of Knuth’s (1973).

Parameters
mnumber of rows of the allocated matrix
nnumber of columns of the allocated matrix
Returns
the matrix of Stirling numbers

Definition at line 377 of file Num.java.

◆ combination()

double umontreal.ssj.util.Num.combination ( int n,
int s )
static

Returns the value of \(\binom{n}{s}\), the number of different combinations of \(s\) objects amongst.

\(n\).

Parameters
ntotal number of objects
snumber of chosen objects on a combination
Returns
the combination of \(s\) objects amongst \(n\)

Definition at line 243 of file Num.java.

◆ digamma()

double umontreal.ssj.util.Num.digamma ( double x)
static

Returns the value of the logarithmic derivative of the Gamma function \(\psi(x) = \Gamma’(x) / \Gamma(x)\).

Definition at line 487 of file Num.java.

◆ erf()

double umontreal.ssj.util.Num.erf ( double x)
static

Returns the value of erf( \(x\)), the error function.

It is defined as

\[ \mbox{erf}(x) = \frac{2}{\sqrt{\pi}}\int_0^x dt  e^{-t^2}. \]

Parameters
xvalue at which the function is calculated
Returns
the value of erf \((x)\)

Definition at line 930 of file Num.java.

◆ erfc()

double umontreal.ssj.util.Num.erfc ( double x)
static

Returns the value of erfc( \(x\)), the complementary error function.

It is defined as

\[ \mbox{erfc}(x) = \frac{2}{\sqrt{\pi}}\int_x^{\infty}dt  e^{-t^2}. \]

Parameters
xvalue at which the function is calculated
Returns
the value of erfc \((x)\)

Definition at line 953 of file Num.java.

◆ erfcInv()

double umontreal.ssj.util.Num.erfcInv ( double u)
static

Returns the value of erfc \({}^{-1}(u)\), the inverse of the complementary error function.

If \(u = \)erfc \((x)\), then \(x = \)erfc \({}^{-1}(u)\).

Parameters
uvalue at which the function is calculated
Returns
the value of erfcInv \((u)\)

Definition at line 1042 of file Num.java.

◆ erfInv()

double umontreal.ssj.util.Num.erfInv ( double u)
static

Returns the value of erf \({}^{-1}(u)\), the inverse of the error function.

If \(u = \)erf \((x)\), then \(x = \)erf \({}^{-1}(u)\).

Parameters
uvalue at which the function is calculated
Returns
the value of erfInv \((u)\)

Definition at line 998 of file Num.java.

◆ evalCheby()

double umontreal.ssj.util.Num.evalCheby ( double a[],
int n,
double x )
static

Evaluates a series of Chebyshev polynomials \(T_j\) at \(x\) over the basic interval \([-1, \;1]\), using the method of Clenshaw [34] , i.e., computes and returns.

\[ y = \frac{a_0}{2} + \sum_{j=1}^n a_j T_j (x). \]

Parameters
acoefficients of the polynomials
nlargest degree of polynomials
xthe parameter of the \(T_j\) functions
Returns
the value of a series of Chebyshev polynomials \(T_j\).

Definition at line 812 of file Num.java.

◆ evalChebyStar()

double umontreal.ssj.util.Num.evalChebyStar ( double a[],
int n,
double x )
static

Evaluates a series of shifted Chebyshev polynomials \(T_j^*\) at.

\(x\) over the basic interval \( [0, \;1]\), using the method of Clenshaw [34] , i.e., computes and returns

\[ y = \frac{a_0}{2} + \sum_{j=1}^n a_j T_j^* (x). \]

Parameters
acoefficients of the polynomials
nlargest degree of polynomials
xthe parameter of the \(T_j^*\) functions
Returns
the value of a series of Chebyshev polynomials \(T_j^*\).

Definition at line 838 of file Num.java.

◆ expBesselK1()

double umontreal.ssj.util.Num.expBesselK1 ( double x,
double y )
static

Returns the value of \(e^x K_1(y)\), where \( K_1\) is the modified Bessel function of the second kind of order 1.

Restriction:

\(y > 0\).

Definition at line 909 of file Num.java.

◆ factoPow()

double umontreal.ssj.util.Num.factoPow ( int n)
static

Returns the value of \(n!/n^n\).

Parameters
ninteger
Returns
the value of \(n!/n^n\)

Definition at line 356 of file Num.java.

◆ factorial()

double umontreal.ssj.util.Num.factorial ( int n)
static

Returns the value of \(n!\).

Parameters
nthe integer for which the factorial must be computed
Returns
the value of \(n!\)

Definition at line 296 of file Num.java.

◆ gammaRatioHalf()

double umontreal.ssj.util.Num.gammaRatioHalf ( double x)
static

Returns the value of the ratio \(\Gamma(x+1/2)/\Gamma(x)\) of two gamma functions.

This ratio is evaluated in a numerically stable way. Restriction: \(x>0\).

Definition at line 635 of file Num.java.

◆ gcd() [1/2]

int umontreal.ssj.util.Num.gcd ( int x,
int y )
static

Returns the greatest common divisor (gcd) of \(x\) and \(y\).

Parameters
xinteger
yinteger
Returns
the GCD of \(x\) and \(y\)

Definition at line 200 of file Num.java.

◆ gcd() [2/2]

long umontreal.ssj.util.Num.gcd ( long x,
long y )
static

Returns the greatest common divisor (gcd) of \(x\) and \(y\).

Parameters
xinteger
yinteger
Returns
the GCD of \(x\) and \(y\)

Definition at line 221 of file Num.java.

◆ harmonic()

double umontreal.ssj.util.Num.harmonic ( long n)
static

Computes the \(n\)-th harmonic number \(H_n = \sum_{j=1}^n 1/j\).

Definition at line 695 of file Num.java.

◆ harmonic2()

double umontreal.ssj.util.Num.harmonic2 ( long n)
static

Computes the sum.

\[ \sideset{}’\sum_{-n/2<j\le n/2}\; \frac{1}{|j|}, \]

where the symbol \(\sum^{\prime}\) means that the term with

\(j=0\) is excluded from the sum.

Definition at line 707 of file Num.java.

◆ lnBeta()

double umontreal.ssj.util.Num.lnBeta ( double lam,
double nu )
static

Computes the natural logarithm of the Beta function \(B(\lambda, \nu)\).

It is defined in terms of the Gamma function as

\[ B(\lambda, \nu) = \frac{\Gamma(\lambda)\Gamma(\nu)}{\Gamma(\lambda+ \nu)} \]

with lam \(=\lambda\) and nu \(=\nu\).

Definition at line 475 of file Num.java.

◆ lnCombination()

double umontreal.ssj.util.Num.lnCombination ( int n,
int s )
static

Returns the natural logarithm of.

\(\binom{n}{s}\), the number of different combinations of \(s\) objects amongst \(n\).

Parameters
ntotal number of objects
snumber of chosen objects on a combination
Returns
the natural log of the combination

Definition at line 280 of file Num.java.

◆ lnFactorial() [1/2]

double umontreal.ssj.util.Num.lnFactorial ( int n)
static

Returns the value of \(\ln(n!)\), the natural logarithm of factorial \(n\).

Gives 16 decimals of precision (relative error

\(< 0.5\times10^{-15}\)).

Parameters
nargument of the log-factorial
Returns
natural logarithm of \(n\) factorial

Definition at line 313 of file Num.java.

◆ lnFactorial() [2/2]

double umontreal.ssj.util.Num.lnFactorial ( long n)
static

Returns the value of \(\ln(n!)\), the natural logarithm of factorial \(n\).

Gives 16 decimals of precision (relative error

\(< 0.5\times10^{-15}\)).

Parameters
nargument of the log-factorial
Returns
natural logarithm of \(n\) factorial

Definition at line 325 of file Num.java.

◆ lnGamma()

double umontreal.ssj.util.Num.lnGamma ( double x)
static

Returns the natural logarithm of the gamma function \(\Gamma(x)\) evaluated at x.

Gives 16 decimals of precision, but is implemented only for \(x>0\).

Parameters
xthe value for which the lnGamma function must be computed
Returns
the natural logarithm of the gamma function

Definition at line 417 of file Num.java.

◆ log2()

double umontreal.ssj.util.Num.log2 ( double x)
static

Returns \(\log_2 (\)x \()\).

Parameters
xthe value for which the logarithm must be computed
Returns
the value of \(\log_2 (\)x \()\)

Definition at line 405 of file Num.java.

◆ sumKahan()

double umontreal.ssj.util.Num.sumKahan ( double[] A,
int n )
static

Implementation of the Kahan summation algorithm.

Sums the first

\(n\) elements of \(A\) and returns the sum. This algorithm is more precise than the naive algorithm. See http://en.wikipedia.org/wiki/Kahan_summation_algorithm.

Definition at line 675 of file Num.java.

◆ tetragamma()

double umontreal.ssj.util.Num.tetragamma ( double x)
static

Returns the value of the tetragamma function \(d^2\psi(x)/d^2x\), the second derivative of the digamma function, evaluated at \(x\).

Definition at line 583 of file Num.java.

◆ trigamma()

double umontreal.ssj.util.Num.trigamma ( double x)
static

Returns the value of the trigamma function \(d\psi(x)/dx\), the derivative of the digamma function, evaluated at \(x\).

Definition at line 532 of file Num.java.

◆ volumeSphere()

double umontreal.ssj.util.Num.volumeSphere ( double p,
int t )
static

Returns the volume \(V\) of a sphere of radius 1 in \(t\) dimensions using the norm \(L_p\).

It is given by the formula

\[ V = \frac{\left[2 \Gamma(1 + 1/p)\right]^t}{\Gamma\left(1 + t/p\right)}, \qquad p > 0, \]

where \(\Gamma\) is the gamma function. The case of the sup norm

\(L_{\infty}\) is obtained by choosing \(p=0\). Restrictions: \(p\ge0\) and \(t\ge1\).

Parameters
pindex of the used norm
tnumber of dimensions
Returns
the volume of a sphere

Definition at line 733 of file Num.java.

Member Data Documentation

◆ DBL_DIG

final int umontreal.ssj.util.Num.DBL_DIG = 15
static

Number of decimal digits of precision in a double.

Definition at line 123 of file Num.java.

◆ DBL_EPSILON

final double umontreal.ssj.util.Num.DBL_EPSILON = 2.2204460492503131e-16
static

Difference between 1.0 and the smallest double greater than 1.0.

Definition at line 90 of file Num.java.

◆ DBL_MAX_10_EXP

final int umontreal.ssj.util.Num.DBL_MAX_10_EXP = 308
static

Largest int \(x\) such that \(10^x\) is representable (approximately) as a double.

Definition at line 108 of file Num.java.

◆ DBL_MAX_EXP

final int umontreal.ssj.util.Num.DBL_MAX_EXP = 1024
static

Largest int \(x\) such that \(2^{x-1}\) is representable (approximately) as a double.

Definition at line 96 of file Num.java.

◆ DBL_MIN

final double umontreal.ssj.util.Num.DBL_MIN = 2.2250738585072014e-308
static

Smallest normalized positive floating-point double.

Definition at line 113 of file Num.java.

◆ DBL_MIN_EXP

final int umontreal.ssj.util.Num.DBL_MIN_EXP = -1021
static

Smallest int \(x\) such that \(2^{x-1}\) is representable (approximately) as a normalised double.

Definition at line 102 of file Num.java.

◆ EBASE

final double umontreal.ssj.util.Num.EBASE = 2.7182818284590452354
static

The constant \(e\).

Definition at line 128 of file Num.java.

◆ EULER

final double umontreal.ssj.util.Num.EULER = 0.57721566490153286
static

The Euler-Mascheroni constant.

Definition at line 133 of file Num.java.

◆ ILN2

final double umontreal.ssj.util.Num.ILN2 = 1.44269504088896340737
static

The values of \(1/\ln2\).

Definition at line 153 of file Num.java.

◆ IRAC2

final double umontreal.ssj.util.Num.IRAC2 = 0.70710678118654752440
static

The value of \(1/\sqrt{2}\).

Definition at line 143 of file Num.java.

◆ LN2

final double umontreal.ssj.util.Num.LN2 = 0.69314718055994530941
static

The values of \(\ln2\).

Definition at line 148 of file Num.java.

◆ LN_DBL_MIN

final double umontreal.ssj.util.Num.LN_DBL_MIN = -708.3964185322641
static

Natural logarithm of DBL_MIN.

Definition at line 118 of file Num.java.

◆ MAXINTDOUBLE

final double umontreal.ssj.util.Num.MAXINTDOUBLE = 9007199254740992.0
static

Largest integer \(n_0 = 2^{53}\) such that any integer \(n \le n_0\) is represented exactly as a double.

Definition at line 159 of file Num.java.

◆ MAXTWOEXP

final double umontreal.ssj.util.Num.MAXTWOEXP = 64
static

Powers of 2 up to MAXTWOEXP are stored exactly in the array TWOEXP.

Definition at line 164 of file Num.java.

◆ RAC2

final double umontreal.ssj.util.Num.RAC2 = 1.41421356237309504880
static

The value of \(\sqrt{2}\).

Definition at line 138 of file Num.java.

◆ TEN_NEG_POW

final double umontreal.ssj.util.Num.TEN_NEG_POW[]
static
Initial value:
= { 1.0, 1.0e-1, 1.0e-2, 1.0e-3, 1.0e-4, 1.0e-5, 1.0e-6, 1.0e-7, 1.0e-8,
1.0e-9, 1.0e-10, 1.0e-11, 1.0e-12, 1.0e-13, 1.0e-14, 1.0e-15, 1.0e-16 }

Contains the precomputed negative powers of 10.

One has TEN_NEG_POW[j] \( = 10^{-j}\), for \(j=0,…,16\).

Definition at line 186 of file Num.java.

◆ TWOEXP

final double umontreal.ssj.util.Num.TWOEXP[]
static
Initial value:
= { 1.0, 2.0, 4.0, 8.0, 1.6e1, 3.2e1, 6.4e1, 1.28e2, 2.56e2, 5.12e2, 1.024e3,
2.048e3, 4.096e3, 8.192e3, 1.6384e4, 3.2768e4, 6.5536e4, 1.31072e5, 2.62144e5, 5.24288e5, 1.048576e6,
2.097152e6, 4.194304e6, 8.388608e6, 1.6777216e7, 3.3554432e7, 6.7108864e7, 1.34217728e8, 2.68435456e8,
5.36870912e8, 1.073741824e9, 2.147483648e9, 4.294967296e9, 8.589934592e9, 1.7179869184e10, 3.4359738368e10,
6.8719476736e10, 1.37438953472e11, 2.74877906944e11, 5.49755813888e11, 1.099511627776e12, 2.199023255552e12,
4.398046511104e12, 8.796093022208e12, 1.7592186044416e13, 3.5184372088832e13, 7.0368744177664e13,
1.40737488355328e14, 2.81474976710656e14, 5.62949953421312e14, 1.125899906842624e15, 2.251799813685248e15,
4.503599627370496e15, 9.007199254740992e15, 1.8014398509481984e16, 3.6028797018963968e16,
7.2057594037927936e16, 1.44115188075855872e17, 2.88230376151711744e17, 5.76460752303423488e17,
1.152921504606846976e18, 2.305843009213693952e18, 4.611686018427387904e18, 9.223372036854775808e18,
1.8446744073709551616e19 }

Contains the precomputed positive powers of 2.

One has TWOEXP[j] \(= 2^j\), for \(j=0,…,64\).

Definition at line 170 of file Num.java.


The documentation for this class was generated from the following file:
  • src/main/java/umontreal/ssj/util/Num.java