SSJ  3.3.1
Stochastic Simulation in Java
Static Public Member Functions | List of all members
Num Class Reference

This class provides a few constants and some 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\). More...
 
static long gcd (long x, long y)
 Returns the greatest common divisor (gcd) of \(x\) and \(y\). More...
 
static double combination (int n, int s)
 Returns the value of \(\binom{n}{s}\), the number of different combinations of \(s\) objects amongst \(n\). More...
 
static double lnCombination (int n, int s)
 Returns the natural logarithm of \(\binom{n}{s}\), the number of different combinations of \(s\) objects amongst \(n\). More...
 
static double factorial (int n)
 Returns the value of \(n!\). More...
 
static double lnFactorial (int n)
 Returns the value of \(\ln(n!)\), the natural logarithm of factorial \(n\). More...
 
static double lnFactorial (long n)
 Returns the value of \(\ln(n!)\), the natural logarithm of factorial \(n\). More...
 
static double factoPow (int n)
 Returns the value of \(n!/n^n\). More...
 
static double [][] calcMatStirling (int m, int n)
 Computes and returns the Stirling numbers of the second kind. More...
 
static double log2 (double x)
 Returns \(\log_2 (\)x \()\). More...
 
static double lnGamma (double x)
 Returns the natural logarithm of the gamma function \(\Gamma(x)\) evaluated at x. More...
 
static double lnBeta (double lam, double nu)
 Computes the natural logarithm of the Beta function \(B(\lambda, \nu)\). More...
 
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. More...
 
static double sumKahan (double[] A, int n)
 Implementation of the Kahan summation algorithm. More...
 
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

\[ \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.

 
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\). More...
 
static double bernoulliPoly (int n, double x)
 Evaluates the Bernoulli polynomial \(B_n(x)\) of degree \(n\) at \(x\). More...
 
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 [35] , i.e., computes and returns

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

. More...

 
static double evalChebyStar (double a[], int n, double x)
 Evaluates a series of shifted Chebyshev polynomials \(T_j^*\) at \(x\) over the basic interval \( [0, \;1]\), using the method of Clenshaw [35] , i.e., computes and returns

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

. More...

 
static double besselK025 (double x)
 Returns the value of \(K_{1/4}(x)\), where \(K_{\nu}\) is the modified Bessel’s function of the second kind. More...
 
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. More...
 
static double erf (double x)
 Returns the value of erf( \(x\)), the error function. More...
 
static double erfc (double x)
 Returns the value of erfc( \(x\)), the complementary error function. More...
 
static double erfInv (double u)
 Returns the value of erf \({}^{-1}(u)\), the inverse of the error function. More...
 
static double erfcInv (double u)
 Returns the value of erfc \({}^{-1}(u)\), the inverse of the complementary error function. More...
 

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. More...
 
static final double TEN_NEG_POW []
 Contains the precomputed negative powers of 10. More...
 

Detailed Description

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

Member Function Documentation

◆ bernoulliPoly()

static double 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}

◆ besselK025()

static double 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)\)

◆ calcMatStirling()

static double [][] 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 [111]  (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

◆ combination()

static double 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\)

◆ erf()

static double 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)\)

◆ erfc()

static double 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)\)

◆ erfcInv()

static double 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)\)

◆ erfInv()

static double 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)\)

◆ evalCheby()

static double 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 [35] , 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\).

◆ evalChebyStar()

static double 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 [35] , 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^*\).

◆ expBesselK1()

static double 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\).

◆ factoPow()

static double factoPow ( int  n)
static

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

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

◆ factorial()

static double factorial ( int  n)
static

Returns the value of \(n!\).

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

◆ gammaRatioHalf()

static double 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\).

◆ gcd() [1/2]

static int 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\)

◆ gcd() [2/2]

static long 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\)

◆ lnBeta()

static double 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\).

◆ lnCombination()

static double 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

◆ lnFactorial() [1/2]

static double 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

◆ lnFactorial() [2/2]

static double 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

◆ lnGamma()

static double 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

◆ log2()

static double 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 \()\)

◆ sumKahan()

static double 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.

◆ volumeSphere()

static double 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

Member Data Documentation

◆ TEN_NEG_POW

final double 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\).

◆ TWOEXP

final double 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\).


The documentation for this class was generated from the following file: