Package eu.bandm.tools.ops
Class PrimeFactors
java.lang.Object
eu.bandm.tools.ops.PrimeFactors
Immutable prime factor combinations as representation of Rationals, thus wiht
positive or negative exponents.
Internally they maintain a
Map
from bases to exponents.
Bases with exponent==0 are removed from the maps.-
Field Summary
Modifier and TypeFieldDescriptionstatic final Comparator<PrimeFactors>
static final Comparator<PrimeFactors>
protected static Map<Integer,
PrimeFactors> protected static Map<Rational,
PrimeFactors> static final PrimeFactors
static final PrimeFactors
static final int
-
Method Summary
Modifier and TypeMethodDescription(package private) static void
add
(int base, int exp) Return an instance with the base and exponent overwritten.int
cmp
(PrimeFactors other) Returns -1/0/+1 for inclusion or equality, negative exponents are smaller than positives, and returns a different int (hereUNCOMPARABLE
) iff not comparable.int
int
Subtract exponents, ie.boolean
boolean
int
getExponent
(int p) int
hashCode()
Return an instance with the more negative exponents of both arguments.Return an instance with the more positive exponents of both arguments.int
intValue()
Return the integer value.boolean
evidentboolean
Returns whether arg is a factor of thisboolean
isOne()
evidentboolean
isPowerOf
(int b) Whether this is a power (possibly with an exponent ==0) of the one single basis.static boolean
isPrime
(int i) Whether the argument is a prime number >=1.static boolean
isPrimePower
(int i) Whether the argument is a power (possibly with an exponent ==0) of only one single basis.static boolean
Whether the argument is a power (possibly with an exponent ==0) of only one single basis.Add exponents, ie.static PrimeFactors
of
(int value) Central service provider and also the implementation: Calculate the prime factors, cache and return them.static PrimeFactors
Returns the prime factor map for the given value.static PrimeFactors
of
(BigInteger bi) Central service provider: Calculate the prime factors and return them as an immutable instance.primes()
ratValue()
Return the rational value.simpleFactors
(boolean reverse) Iterate over identic factors seperatedly, like "2, 2, 3, 5, 5", not "4,3,25".toString()
with
(int base, int exp) Return an instance with the base and exponent overwritten.without
(int p) Remove basis from domain.
-
Field Details
-
UNCOMPARABLE
public static final int UNCOMPARABLE- See Also:
-
cache_int
-
cache_rat
-
ONE
-
TWO
-
byRatValue
-
byIntValue
-
-
Method Details
-
__clearCaches
static void __clearCaches() -
of
Central service provider: Calculate the prime factors and return them as an immutable instance. Works only for BigIntegeres which are representable as int.- Returns:
- prime factor map for the given value.
-
of
Central service provider and also the implementation: Calculate the prime factors, cache and return them.- Returns:
- prime factor map for the given value.
-
of
Returns the prime factor map for the given value. Assumes that Rationals are always normalized- Returns:
- the prime factor map for the given value.
-
toString
-
hashCode
public int hashCode() -
equals
-
equals
-
primes
-
isIntegerMultipleOf
Returns whether arg is a factor of this -
isPrime
public static boolean isPrime(int i) Whether the argument is a prime number >=1. 1 and 2 count as prime. -
isPrimePower
public static boolean isPrimePower(int i) Whether the argument is a power (possibly with an exponent ==0) of only one single basis. -
isPrimePower
Whether the argument is a power (possibly with an exponent ==0) of only one single basis. -
isPowerOf
public boolean isPowerOf(int b) Whether this is a power (possibly with an exponent ==0) of the one single basis. -
isOne
public boolean isOne()evident -
isInteger
public boolean isInteger()evident -
getExponent
public int getExponent(int p) - Returns:
- the exponent for the given base.
-
countPrimes
public int countPrimes()- Returns:
- the number of different bases.
-
complexity
public int complexity()- Returns:
- the number of different factors, which is the sum of the absolute values of all exponents.
-
intValue
public int intValue()Return the integer value. If there is no such, ie. some exponent is negative, an IllegalArgumentException is thrown. If "this" was created with an exponent map, this value must be calculated and is stored locally. -
ratValue
Return the rational value. If "this" was created with an exponent map, this value must be calculated and is stored locally iff this is not modifiable. -
simpleFactors
Iterate over identic factors seperatedly, like "2, 2, 3, 5, 5", not "4,3,25". -
cmp
Returns -1/0/+1 for inclusion or equality, negative exponents are smaller than positives, and returns a different int (hereUNCOMPARABLE
) iff not comparable. -
without
Remove basis from domain. Works also for arguments which are not valid prime bases. -
integerLCM
Return an instance with the more positive exponents of both arguments. -
integerGCD
Return an instance with the more negative exponents of both arguments. -
with
Return an instance with the base and exponent overwritten. -
add
Return an instance with the base and exponent overwritten.- Parameters:
base
- must be a valid prime basis. ==1 is allowed, but has no effect.exp
- ==0 works also with invalid bases and has no effect (= returns this)- See Also:
-
divide
Subtract exponents, ie. divide values. -
multiply
Add exponents, ie. multiply values. -
getDenominator
- Returns:
- prime factors in denominator, as positive exponents of the original negatives.
-
getNumerator
- Returns:
- prime factors in numerators, i.e. all which are originally positive.
-