|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.numericalmethod.suanshu.analysis.function.FunctionOps
public class FunctionOps
This class collects some commonly used mathematical functions.
| Constructor Summary | |
|---|---|
FunctionOps()
|
|
| Method Summary | |
|---|---|
static double |
combination(int n,
int k)
Compute the combination function/binomial coefficient. |
static double |
dotProduct(double[] x1,
double[] x2)
Compute the element-wise multiplication between two double[]s. |
static long |
dotProduct(long[] x1,
long[] x2)
Compute the element-wise multiplication between two long[]s. |
static double |
factorial(int n)
Compute the n factorial. |
static long |
mod(long x,
long m)
Compute the positive modulus of a number. |
static long |
modpow(long base,
long exponent,
long modulus)
be mod m
This implements a variant of the algorithm
on page 244 of Bruce Schneier's Applied Cryptography, 2e, ISBN 0-471-11709-9. |
static double |
permutation(int n,
int k)
Compute the permutation function. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public FunctionOps()
| Method Detail |
|---|
public static long modpow(long base,
long exponent,
long modulus)
be mod m
This implements a variant of the algorithm
on page 244 of Bruce Schneier's Applied Cryptography, 2e, ISBN 0-471-11709-9.
We use the fact that
(a * b) mod m = ((a mod m) * (b mod m)) mod m
This code may fail without being noticed for very large numbers because overflow in integer operations does not throw any exception in the JVM.
base - positive integer bexponent - positive integer emodulus - positive integer m
be mod m
java.lang.IllegalArgumentException - if not all inputs are positive integers
public static long mod(long x,
long m)
If x is positive, we return x % m; otherwise, we return the smallest positive integer less than m, having the same modulo.
For example,
-1 mod 5 = 4
x - an integerm - the modulus
x mod m
public static long dotProduct(long[] x1,
long[] x2)
x1 - a long arrayx2 - a long array
public static double dotProduct(double[] x1,
double[] x2)
x1 - a double arrayx2 - a double array
public static double factorial(int n)
n factorial.
n - an integer
n!
public static double combination(int n,
int k)
k-combinations (each of size k) from a set S with n elements (size n).
n - the size of the full setk - the size of a combination
n! / (n-k)! / k!
public static double permutation(int n,
int k)
k-permutations (each of size k) from a set S with n elements (size n).
n - the size of the full setk - the size of a permutation
n! / (n-k)!
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||