Package eu.bandm.tools.util2
Class PrimeFactors
java.lang.Object
eu.bandm.tools.util2.PrimeFactors
Calculates prime factor combinations for Rationals, i.e. positive or negative
exponents.
Objects exist in two flavours:
Modifiable for setting and clearing exponents.
Unmodifiable for being cached and cheaply retrieved.
Between these flavours there are conversion functions, making new copies.
Internally they maintain a
Modifiable for setting and clearing exponents.
Unmodifiable for being cached and cheaply retrieved.
Between these flavours there are conversion functions, making new copies.
Internally they maintain a
Map
from bases to exponents.
Bases with exponent==0 are removed from the maps.-
Field Summary
Modifier and TypeFieldDescriptionstatic Comparator<PrimeFactors>
static Comparator<PrimeFactors>
protected static Map<Integer,
PrimeFactors> protected static Map<Rational,
PrimeFactors> static final PrimeFactors
static final PrimeFactors
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(int p) Add 1(one) to the currently present exponent (maybe ==0) of p.void
add
(int p, int v) Add exponent v to the currently present exponent (maybe ==0) of p.void
clear()
Clear all exponents to zero(0).int
cmp
(PrimeFactors other) Returns -1/0/+1 for inclusion or equality, negative exponents are smaller than positives, and returns a different int (here: -100) iff not comparable.boolean
Returns whether arg is a factor of thisint
count
(int p) int
int
domain()
Only those bases with exp!=0boolean
boolean
static PrimeFactors
get
(int value) static PrimeFactors
static PrimeFactors
get
(BigInteger bi) int
hashCode()
int
intValue()
Return the integer value.boolean
boolean
isOne()
boolean
isPowerOf
(int b) Whether this is a power (with an exponent !=0) of the one single basis.static boolean
isPrime
(int i) Whether the argument is a prim number >=1.static boolean
isSingleBased
(int i) Whether the argument is a power of only one single basis.max
(PrimeFactors b) Return an instance with the more positive exponents of both arguments.min
(PrimeFactors b) Return an instance with the more negative exponents of both arguments.Subtract exponents, ie.Always makes a new copy, which is modifiable.plus
(PrimeFactors b) Add exponents, ie.ratValue()
Return the rational value.void
removeDomain
(int p) Remove basis from domain.simpleFactors
(boolean reverse) Iterate over identic factors seperated, like "2, 2, 3, 5, 5", not "4,3,25".toString()
Make a new unmodifiable version, iff not already unmodifiable.with
(int base, int exp) Return an instance with the base and ecponent overwritten.
-
Field Details
-
cache_int
-
cache_rat
-
ONE
-
TWO
-
byRatValue
-
byIntValue
-
-
Method Details
-
modifiable
Always makes a new copy, which is modifiable. -
unmodifiable
Make a new unmodifiable version, iff not already unmodifiable. -
get
- Returns:
- an unmodifiable prime factor map for the given value.
-
get
- Returns:
- an unmodifiable prime factor map for the given value.
-
get
- Returns:
- the prime factor map for the given value.
-
isPrime
public static boolean isPrime(int i) Whether the argument is a prim number >=1. 1 and 2 count as prime. -
isSingleBased
public static boolean isSingleBased(int i) Whether the argument is a power of only one single basis. -
toString
-
isOne
public boolean isOne() -
isInteger
public boolean isInteger() -
count
public int count(int p) - Returns:
- the exponent for the given base.
-
countBases
public int countBases()- Returns:
- the number of different bases.
-
countFactors
public int countFactors()- 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 iff this is not modifiable. -
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. -
domain
Only those bases with exp!=0 -
isPowerOf
public boolean isPowerOf(int b) Whether this is a power (with an exponent !=0) of the one single basis. -
simpleFactors
Iterate over identic factors seperated, like "2, 2, 3, 5, 5", not "4,3,25". -
add
public void add(int p) Add 1(one) to the currently present exponent (maybe ==0) of p. Only supported if modifiable==true. -
add
public void add(int p, int v) Add exponent v to the currently present exponent (maybe ==0) of p. Only supported if modifiable==true. -
removeDomain
public void removeDomain(int p) Remove basis from domain. Only supported if modifiable==true. -
clear
public void clear()Clear all exponents to zero(0). Only supported if modifiable==true. -
cmp
Returns -1/0/+1 for inclusion or equality, negative exponents are smaller than positives, and returns a different int (here: -100) iff not comparable. -
containsAsFactor
Returns whether arg is a factor of this -
max
Return an instance with the more positive exponents of both arguments. -
min
Return an instance with the more negative exponents of both arguments. -
with
Return an instance with the base and ecponent overwritten. -
minus
Subtract exponents, ie. divide values. -
plus
Add exponents, ie. multiply values. -
hashCode
public int hashCode() -
equals
-
equals
-
denominator
- Returns:
- prime factors in denominator, as positive exponents of the original negatives.
-
numerator
- Returns:
- prime factors in numerators, i.e. all which are originally positive.
-