SSJ
3.3.1
Stochastic Simulation in Java
|
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... | |
This class provides a few constants and some methods to compute numerical quantities such as factorials, combinations, gamma functions, and so on.
|
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}
|
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}\).
x | value at which the function is calculated |
|
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).
m | number of rows of the allocated matrix |
n | number of columns of the allocated matrix |
|
static |
Returns the value of \(\binom{n}{s}\), the number of different combinations of \(s\) objects amongst \(n\).
n | total number of objects |
s | number of chosen objects on a combination |
|
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}. \]
x | value at which the function is calculated |
erf
\((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}. \]
x | value at which the function is calculated |
erfc
\((x)\)
|
static |
Returns the value of erfc
\({}^{-1}(u)\), the inverse of the complementary error function.
If \(u = \)erfc
\((x)\), then \(x = \)erfc
\({}^{-1}(u)\).
u | value at which the function is calculated |
|
static |
Returns the value of erf
\({}^{-1}(u)\), the inverse of the error function.
If \(u = \)erf
\((x)\), then \(x = \)erf
\({}^{-1}(u)\).
u | value at which the function is calculated |
|
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). \]
.
a | coefficients of the polynomials |
n | largest degree of polynomials |
x | the parameter of the \(T_j\) functions |
|
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). \]
.
a | coefficients of the polynomials |
n | largest degree of polynomials |
x | the parameter of the \(T_j^*\) functions |
|
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\).
|
static |
Returns the value of \(n!/n^n\).
n | integer |
|
static |
Returns the value of \(n!\).
n | the integer for which the factorial must be computed |
|
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\).
|
static |
Returns the greatest common divisor (gcd) of \(x\) and \(y\).
x | integer |
y | integer |
|
static |
Returns the greatest common divisor (gcd) of \(x\) and \(y\).
x | integer |
y | integer |
|
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\).
|
static |
Returns the natural logarithm of \(\binom{n}{s}\), the number of different combinations of \(s\) objects amongst \(n\).
n | total number of objects |
s | number of chosen objects on a combination |
|
static |
Returns the value of \(\ln(n!)\), the natural logarithm of factorial \(n\).
Gives 16 decimals of precision (relative error \(< 0.5\times10^{-15}\)).
n | argument of the log-factorial |
|
static |
Returns the value of \(\ln(n!)\), the natural logarithm of factorial \(n\).
Gives 16 decimals of precision (relative error \(< 0.5\times10^{-15}\)).
n | argument of the log-factorial |
|
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\).
x | the value for which the lnGamma function must be computed |
|
static |
Returns \(\log_2 (\)x
\()\).
x | the value for which the logarithm must be computed |
x
\()\)
|
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.
|
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\).
p | index of the used norm |
t | number of dimensions |
|
static |
Contains the precomputed negative powers of 10.
One has TEN_NEG_POW[j]
\( = 10^{-j}\), for \(j=0,…,16\).
|
static |
Contains the precomputed positive powers of 2.
One has TWOEXP[j]
\( = 2^j\), for \(j=0,…,64\).