public class Algebra extends Constants
| Constructor and Description |
|---|
Algebra() |
| Modifier and Type | Method and Description |
|---|---|
static double |
binomial(double n,
long k)
Efficiently returns the binomial coefficient, often also referred to as
"n over k" or "n choose k".
|
static double |
binomial(long n,
long k)
Efficiently returns the binomial coefficient, often also referred to as "n over k" or "n choose k".
|
static long |
ceil(double val)
Returns the smallest
long >= value. |
static double |
chbevl(double x,
double[] coef,
int N)
Evaluates the series of Chebyshev polynomials Ti at argument x/2.
|
static double |
evalPoly(double x,
double[] coef,
int n)
Evaluates the given polynomial of degree
N at x. |
static double |
evalPoly1(double x,
double[] coef,
int n)
Evaluates the given polynomial of degree
N at x, assuming coefficient of N is 1.0. |
static long |
floor(double val)
Returns the largest
long <= value. |
static double |
hypot(double a,
double b)
Gets
sqrt(a^2 + b^2) without under/overflow. |
static double |
log(double base,
double val)
Returns
log<sub>base</sub>value. |
static double |
log10(double val)
Returns
log<sub>10</sub>value. |
static double |
log2(double val)
Returns
log<sub>2</sub>value. |
static double |
logFactorial(int k)
Returns
log(k!). |
static long |
longFactorial(int k)
Instantly returns the factorial
k!. |
static double |
stirlingCorrection(int k)
Returns the StirlingCorrection.
|
public static double binomial(double n,
long k)
(n * n-1 * ... * n-k+1 ) / ( 1 * 2 * ... * k ).
k<0: 0.k==0: 1.k==1: n.(n * n-1 * ... * n-k+1 ) / ( 1 * 2 * ... * k).n - Size of set.k - Size of subset.public static double binomial(long n,
long k)
k<0: 0. k==0 || k==n: 1. k==1 || k==n-1:
n. (n * n-1 * ... * n-k+1 ) / ( 1 * 2 * ... * k ). n - Size of set.k - Size of subset.public static long ceil(double val)
long >= value.
1.0 -> 1, 1.2 -> 2, 1.9 -> 2. This
method is safer than using (long) Math.ceil(value), because of possible rounding error.val - Value for ceil.public static double chbevl(double x,
double[] coef,
int N)
N-1 - ' y = > coef[i] T (x/2) - i i=0Coefficients are stored in reverse order, i.e. the zero order term is last in the array. Note N is the number of coefficients, not the order.
If coefficients are for the interval a to b, x must have been transformed to x -< 2(2x - b - a)/(b-a) before entering the routine. This maps x from (a, b) to (-1, 1), over which the Chebyshev polynomials are defined.
If the coefficients are for the inverted interval, in which (a, b) is
mapped to (1/b, 1/a), the transformation required is x -> 2(2ab/x - b - a)/(b-a). If b is infinity, this
becomes x -> 4a/x - 1.
SPEED:
Taking advantage of the recurrence properties of the Chebyshev polynomials, the routine requires one more addition per loop than evaluating a nested polynomial of the same degree.x - Argument to the polynomial.coef - Coefficients of the polynomial.N - Number of coefficients.public static long floor(double val)
long <= value.
1.0 -> 1, 1.2 -> 1, 1.9 -> 1 <dt> 2.0 -> 2, 2.2 -> 2, 2.9 -> 2public static double log(double base,
double val)
log<sub>base</sub>value.public static double log10(double val)
log<sub>10</sub>value.public static double log2(double val)
log<sub>2</sub>value.public static double logFactorial(int k)
log(k!). Tries to avoid overflows. For k<30 simply looks up a table in O(1).
For k>=30 uses Stirling's approximation.k - must hold k >= 0.public static long longFactorial(int k)
k!.k - must hold k >= 0 && k < 21public static double stirlingCorrection(int k)
Correction term of the Stirling approximation for log(k!) (series in
1/k, or table values for small k) with int parameter k. log k! = (k + 1/2)log(k + 1) - (k + 1) +
(1/2)log(2Pi) + STIRLING_CORRECTION(k + 1) log k! = (k + 1/2)log(k) - k + (1/2)log(2Pi) +
STIRLING_CORRECTION(k)
public static double evalPoly1(double x,
double[] coef,
int n)
N at x, assuming coefficient of N is 1.0. Otherwise same
as evalPoly(double, double[], int).
2 N y = C + C x + C x +...+ C x 0 1 2 Nwhere
C = 1 Nand hence is omitted from the array.
Coefficients are stored in reverse order:
coef[0] = C , ..., coef[N-1] = C . N-1 0Calling arguments are otherwise the same as
evalPoly(double, double[], int).
In the interest of speed, there are no checks for out of bounds arithmetic.
x - Argument to the polynomial.coef - Coefficients of the polynomial.n - Degree of the polynomial.public static double evalPoly(double x,
double[] coef,
int n)
N at x.
2 N y = C + C x + C x +...+ C x 0 1 2 N
Coefficients are stored in reverse order:
coef[0] = C , ..., coef[N] = C . N 0
In the interest of speed, there are no checks for out of bounds arithmetic.
x - Argument to the polynomial.coef - Coefficients of the polynomial.n - Degree of the polynomial.public static double hypot(double a,
double b)
sqrt(a^2 + b^2) without under/overflow.a - First side value.b - Second side value.
Follow @ApacheIgnite
Ignite Fabric : ver. 2.5.0 Release Date : May 23 2018