Class PrimeFactors

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

public class PrimeFactors extends Object
Immutable prime factor combinations as representation of Rationals, thus with positive or negative exponents. Internally they maintain a Map from bases to exponents. Bases with exponent==0 are removed from the maps.
  • Field Details Link icon

  • Method Details Link icon

    • __clearCaches Link icon

      static void __clearCaches()
    • of Link icon

      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 Link icon

      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 Link icon

      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 Link icon

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

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

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

      public boolean equals(PrimeFactors b)
    • primes Link icon

      public SortedSet<Integer> primes()
    • isIntegerMultipleOf Link icon

      public boolean isIntegerMultipleOf(PrimeFactors b)
      Returns whether arg is a factor of this
    • isPrime Link icon

      public static boolean isPrime(int i)
      Whether the argument is a prime number >=1. 1 and 2 count as prime.
    • isPrimePower Link icon

      public static boolean isPrimePower(int i)
      Whether the argument is a power (possibly with an exponent ==0) of only one single basis.
    • isPrimePower Link icon

      public static boolean isPrimePower(Rational r)
      Whether the argument is a power (possibly with an exponent ==0) of only one single basis.
    • isPowerOf Link icon

      public boolean isPowerOf(int b)
      Whether this is a power (possibly with an exponent ==0) of the one single basis.
    • isOne Link icon

      public boolean isOne()
      evident
    • isInteger Link icon

      public boolean isInteger()
      evident
    • getExponent Link icon

      public int getExponent(int p)
      Returns:
      the exponent for the given base.
    • countPrimes Link icon

      public int countPrimes()
      Returns:
      the number of different bases.
    • complexity Link icon

      public int complexity()
      Returns:
      the number of different factors, which is the sum of the absolute values of all exponents.
    • intValue Link icon

      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 Link icon

      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 Link icon

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

      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 Link icon

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

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

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

      public PrimeFactors with(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. Attention: prime check costs.
    • add Link icon

      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 Link icon

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

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

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

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