Class PrimeFactors

java.lang.Object
eu.bandm.tools.ops.PrimeFactors

public class PrimeFactors extends Object
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 Details

  • Method Details

    • __clearCaches

      static void __clearCaches()
    • of

      public static PrimeFactors of(BigInteger bi)
      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

      public static PrimeFactors of(int value)
      Central service provider and also the implementation: Calculate the prime factors, cache and return them.
      Returns:
      prime factor map for the given value.
    • of

      public static PrimeFactors of(Rational rat)
      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

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object b)
      Overrides:
      equals in class Object
    • equals

      public boolean equals(PrimeFactors b)
    • primes

      public SortedSet<Integer> primes()
    • isIntegerMultipleOf

      public boolean isIntegerMultipleOf(PrimeFactors b)
      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

      public static boolean isPrimePower(Rational r)
      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

      public Rational 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

      public List<Integer> simpleFactors(boolean reverse)
      Iterate over identic factors seperatedly, like "2, 2, 3, 5, 5", not "4,3,25".
    • cmp

      public int cmp(PrimeFactors other)
      Returns -1/0/+1 for inclusion or equality, negative exponents are smaller than positives, and returns a different int (here UNCOMPARABLE) iff not comparable.
    • without

      public PrimeFactors without(int p)
      Remove basis from domain. Works also for arguments which are not valid prime bases.
    • integerLCM

      public PrimeFactors integerLCM(PrimeFactors b)
      Return an instance with the more positive exponents of both arguments.
    • integerGCD

      public PrimeFactors integerGCD(PrimeFactors b)
      Return an instance with the more negative exponents of both arguments.
    • with

      public PrimeFactors with(int base, int exp)
      Return an instance with the base and exponent overwritten.
    • add

      public PrimeFactors add(int base, int exp)
      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

      public PrimeFactors divide(PrimeFactors b)
      Subtract exponents, ie. divide values.
    • multiply

      public PrimeFactors multiply(PrimeFactors b)
      Add exponents, ie. multiply values.
    • getDenominator

      public PrimeFactors getDenominator()
      Returns:
      prime factors in denominator, as positive exponents of the original negatives.
    • getNumerator

      public PrimeFactors getNumerator()
      Returns:
      prime factors in numerators, i.e. all which are originally positive.