|
Orbital library | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object orbital.math.MathUtilities
public final class MathUtilities
This class contains basic mathematical utilities.
Property Name | Property Value |
---|---|
orbital.math.MathUtilities.defaultPrecisionDigits | the default number of precision digits (for display etc.). |
orbital.math.MathUtilities.defaultTolerance | the default tolerance for two numbers to be treated equal. (experimental) |
Math
,
Utility
,
AlgebraicAlgorithms
,
NumericalAlgorithms
,
Stat
,
Evaluations
Method Summary | |
---|---|
static double |
ceily(double a)
|
static double |
ceily(double a,
double precision)
Returns the smallest (closest to negative infinity) double value that is not less than the argument and
is equal for at least a precision value. |
static boolean |
equals(Arithmetic a,
Arithmetic b,
double tolerance)
|
static boolean |
equals(double a,
double b,
double tolerance)
Checks whether two numbers are roughly equal. |
static boolean |
even(int value)
This function is true only when the value is an even number. |
static long |
factorial(int n)
n! factorial. |
static double |
floory(double a)
|
static double |
floory(double a,
double precision)
Returns the largest (closest to positive infinity) double value that is not greater than the argument and
is equal for at least a precision value. |
static java.lang.String |
format(byte[] v)
|
static java.lang.String |
format(double v)
formats a numeric double-value. |
static java.lang.String |
format(double v,
int precisionDigits)
Formats a numeric double-value as a String representation with a specified number of precision digits. |
static java.lang.String |
format(java.lang.Object o)
Formats an object as a String representation. |
static double |
fract(double a)
Returns the fractional part of a double value that is in range of [0,1[ and
is equal for all fractional digits. |
static int |
gaussian(double a)
Returns the Gaussian integer part of a double value. |
static Euclidean[] |
gcd(Euclidean[] elements)
Deprecated. Use AlgebraicAlgorithms.gcd(Euclidean[]) instead. |
static Euclidean |
gcd(Euclidean a,
Euclidean b)
Deprecated. Use AlgebraicAlgorithms.gcd(Euclidean,Euclidean) instead. |
static int |
gcd(int a,
int b)
Returns greatest common divisor (GCD) of two integers. |
static java.math.BigInteger |
generatePrime(int strength,
int certainty,
java.util.Random randSource,
boolean strongPrime)
Generate a probable prime number. |
static java.math.BigInteger |
generatePrime(int strength,
java.util.Random randSource)
Generate a true prime number. |
static int |
getDefaultPrecisionDigits()
Get the default number of precision digits (for display etc.). |
static double |
getDefaultTolerance()
Get the default tolerance for two numbers to be treated equal. |
static Function |
getEqualizer()
Deprecated. Since Orbital.1.1 use Values.getDefault() .ValueFactory.getCoercer() instead. |
static Arithmetic |
integrate(Function f,
Arithmetic a,
Arithmetic b)
Returns ∫ab f dx. |
static boolean |
isin(double value,
double lower,
double higher)
Whether a value is in a specified range. |
static boolean |
isin(int value,
int lower,
int higher)
Whether a value is in a specified range. |
static boolean |
isin(Real value,
Real lower,
Real higher)
Whether a value is in a specified range. |
static boolean |
isInteger(double value)
Check whether the given value is an integer, only. |
static boolean |
isPrime(java.math.BigInteger val)
Really check whether a BigInteger is prime. |
static boolean |
isProbability(double value)
Check whether the given value is a probability value. |
static Euclidean |
lcm(Euclidean a,
Euclidean b)
Deprecated. Use AlgebraicAlgorithms.lcm(Euclidean,Euclidean) instead. |
static int |
lcm(int a,
int b)
Returns least common multiple (LCM) of two integers. |
static int |
multinomial(int[] n)
Multinomial coefficient which is a generalized binomial coefficient. |
static int |
nCr(int n,
int r)
binomial coefficient (nr) = nCr number of combinations without repetition. |
static int |
nPr(int n,
int r)
nPr number of permutations without repetition. |
static boolean |
odd(int value)
This function is true only when the value is an odd number. |
static double |
precisionFor(double a)
Get the precision for a default tolerance relative to the magnitude of a. |
static double |
precisionFor(double a,
double tolerance)
Get the precision for a given a specified tolerance relative to the magnitude of a. |
static int |
round(double a,
int rounding_style)
Returns the mathematically rounded part of a double value. |
static double |
roundy(double a)
|
static double |
roundy(double a,
double precision)
Returns the closest double to the argument that is equal for at least a precision value. |
static void |
setDefaultPrecisionDigits(int defaultPrecisionDigits)
Set the default number of precision digits (for display etc.). |
static void |
setDefaultTolerance(double defaultTolerance)
Set the default tolerance for two numbers to be treated equal. |
static void |
setEqualizer(Function equalizer)
Deprecated. Since Orbital.1.1 use Values.getDefault() .ValueFactory.setCoercer(orbital.logic.functor.Function) instead. |
static int |
sign(double value)
The signum of a number. |
static int |
sign(int value)
|
static java.lang.String |
toRoman(short arabic)
Converts arabic numbers to roman numbers. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static void setDefaultPrecisionDigits(int defaultPrecisionDigits)
public static int getDefaultPrecisionDigits()
public static void setDefaultTolerance(double defaultTolerance)
public static double getDefaultTolerance()
public static final boolean isin(int value, int lower, int higher)
public static final boolean isin(double value, double lower, double higher)
public static final boolean isin(Real value, Real lower, Real higher)
public static final boolean even(int value)
public static final boolean odd(int value)
public static final int sign(double value)
public static final int sign(int value)
public static boolean isProbability(double value)
public static boolean isInteger(double value)
public static Euclidean gcd(Euclidean a, Euclidean b)
AlgebraicAlgorithms.gcd(Euclidean,Euclidean)
instead.
public static Euclidean lcm(Euclidean a, Euclidean b)
AlgebraicAlgorithms.lcm(Euclidean,Euclidean)
instead.
public static Euclidean[] gcd(Euclidean[] elements)
AlgebraicAlgorithms.gcd(Euclidean[])
instead.
public static int gcd(int a, int b)
AlgebraicAlgorithms.gcd(int,int)
public static int lcm(int a, int b)
AlgebraicAlgorithms.lcm(int,int)
public static java.math.BigInteger generatePrime(int strength, int certainty, java.util.Random randSource, boolean strongPrime)
strength
- - bitlength of the result.certainty
- - the probability for being prime exceeds 1 - 1/2certainty.randSource
- - the Random-Source necessary to generate primes. For privacy should be an instance of SecureRandom.strongPrime
- - true to produce cryptographically strong primes where (p-1)/2 is prime again.BigInteger.BigInteger(int,int,Random)
public static java.math.BigInteger generatePrime(int strength, java.util.Random randSource)
strength
- - bitlength of the result.randSource
- - the Random-Source necessary to generate primes. For privacy should be an instance of SecureRandom.public static boolean isPrime(java.math.BigInteger val)
If you have all factors d that divide p evenly and are d≤√(p), then you can get the complements p/d. To test whether p is prime, you check all d that divide p evenly with d≤√(p)≤t≤p. If you cannot calculate squarer roots (as with BigNumbers) you must find a clever t. Since with p having bitlength n, then p≤2n+1, therefore √(p)≤2(n+1)/2=:t. So all d's that you need to check for divisibility are those with bitlength≤(n+1)/2.
The d's starting at 3 will be increased by 4, 2, 2, 2, and again 4, 2, 2, 2 because those numbers divisible by 2 and 5 are already checked for earlier.
BigInteger.isProbablePrime(int)
public static long factorial(int n)
public static int nCr(int n, int r)
getCombinations(int, int, false)
public static int nPr(int n, int r)
getPermutations(int, int, false)
public static int multinomial(int[] n)
nCr(int, int)
public static int round(double a, int rounding_style)
double
value.
public static double fract(double a)
double
value that is in range of [0,1[ and
is equal for all fractional digits.
a - ⌊a⌋
.Math.floor(double)
public static int gaussian(double a)
double
value. Its the largest integer
that is smaller than or equal.
⌈a⌉ := sup {z in Z | z<=a} == (int) Math.floor(a)
.Math.floor(double)
public static double ceily(double a, double precision)
double
value that is not less than the argument and
is equal for at least a precision value.
Math.ceil(a/precision)*precision
.floory(double, double)
public static double ceily(double a)
public static double floory(double a, double precision)
double
value that is not greater than the argument and
is equal for at least a precision value.
MathUtilities.floory(a, .01)
will result in a
rounded down
to a number formated as .##
,
while MathUtilities.floory(a, 100)
will result in a
rounded down
to a number formated as several #s preceding######00.
.
Math.floor(a/precision)*precision
.ceily(double, double)
public static double floory(double a)
public static double roundy(double a, double precision)
double
to the argument that is equal for at least a precision value.
a
- a double
value.precision
- a double
value setting the precision.
The smaller the precision, the more precise, the number returned,
the larger the less precise and rounded earlier.
Precisions above 1 will even round the non-fractional part.
public static double roundy(double a)
public static double precisionFor(double a, double tolerance)
Roughly gives the precision for tolerance percent of a, but adjusted to decimal digits.
public static double precisionFor(double a)
public static boolean equals(double a, double b, double tolerance)
tolerance
- specifies how much a and b may differ to be treated as equal.
|a-b| < tolerance
.Arithmetic.equals(Object,Real)
public static boolean equals(Arithmetic a, Arithmetic b, double tolerance)
public static final Function getEqualizer()
Values.getDefault()
.ValueFactory.getCoercer()
instead.
public static final void setEqualizer(Function equalizer) throws java.lang.SecurityException
Values.getDefault()
.ValueFactory.setCoercer(orbital.logic.functor.Function)
instead.
java.lang.SecurityException
public static Arithmetic integrate(Function f, Arithmetic a, Arithmetic b)
NumericalAlgorithms.integrate(orbital.math.functional.Function, Arithmetic, Arithmetic)
public static java.lang.String format(double v, int precisionDigits)
public static java.lang.String format(double v)
DefaultTolerance
public static java.lang.String format(byte[] v)
public static java.lang.String format(java.lang.Object o)
Does special handling for numbers, arithmetic objects, functors, for arrays, for two-dimensional arrays, etc.
ArithmeticFormat
public static java.lang.String toRoman(short arabic)
arabic
- the short value (in arabic chiffres) to be converted into roman chiffres.
It must be an integer value between 1 (I) and 3999 (MMMCMXCIX).
|
Orbital library 1.3.0: 11 Apr 2009 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |