Package org.nevec.rjm

Class Ifactor

  • All Implemented Interfaces:
    java.lang.Cloneable, java.lang.Comparable<Ifactor>

    public class Ifactor
    extends java.lang.Object
    implements java.lang.Cloneable, java.lang.Comparable<Ifactor>
    Factored integers. This class contains a non-negative integer with the prime factor decomposition attached.
    Since:
    2006-08-14, 2012-02-14 The internal representation contains the bases, and becomes sparser if few prime factors are present.
    Author:
    Richard J. Mathar
    • Field Summary

      Fields 
      Modifier and Type Field Description
      java.math.BigInteger n
      The standard representation of the number
      static Ifactor ONE  
      java.util.Vector<java.lang.Integer> primeexp  
      static Ifactor ZERO  
    • Constructor Summary

      Constructors 
      Constructor Description
      Ifactor​(int number)
      Constructor given an integer.
      Ifactor​(java.math.BigInteger number)
      Constructor given a BigInteger .
      Ifactor​(java.util.Vector<java.lang.Integer> pows)
      Constructor given a list of exponents of the prime factor decomposition.
      Ifactor​(Ifactor oth)
      Copy constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Ifactor add​(java.math.BigInteger oth)
      Summation with another positive integer
      int bigomega()
      The sum of the prime factor exponents, with multiplicity.
      Ifactor clone()
      Deep copy.
      int compareTo​(Ifactor oth)
      Compare value against another Ifactor
      java.math.BigInteger core()
      The square-free part.
      Ifactor divide​(Ifactor oth)
      Integer division through another positive integer.
      java.util.Vector<java.math.BigInteger> divisors()
      The set of positive divisors.
      Ifactor dropPrime()
      Divide through the highest possible power of the highest prime.
      boolean equals​(Ifactor oth)
      Comparison of two numbers.
      Ifactor gcd​(Ifactor oth)
      Greatest common divisor of this and oth.
      boolean issquare()
      Test whether this is a square of an integer (perfect square).
      Ifactor lcm​(Ifactor oth)
      Lowest common multiple of this with oth.
      static void main​(java.lang.String[] args)
      Test program.
      static Ifactor max​(java.util.Vector<Ifactor> set)
      Maximum of a list of values.
      Ifactor max​(Ifactor oth)
      Maximum of two values.
      static Ifactor min​(java.util.Vector<Ifactor> set)
      Minimum of a list of values.
      Ifactor min​(Ifactor oth)
      Minimum of two values.
      int moebius()
      The Moebius function.
      protected Ifactor multGcdLcm​(Ifactor oth, int type)
      Multiply with another positive integer.
      Ifactor multiply​(int oth)
      Multiply with another positive integer.
      Ifactor multiply​(java.math.BigInteger oth)
      Multiply with another positive integer.
      Ifactor multiply​(Ifactor oth)
      Multiply with another positive integer.
      int omega()
      The sum of the prime factor exponents, without multiplicity.
      Ifactor pow​(int exponent)
      Exponentiation with a positive integer.
      Rational root​(int r)
      Pulling the r-th root.
      Ifactor sigma()
      Sum of the divisors of the number.
      Ifactor sigma​(int k)
      Sum of the k-th powers of divisors of the number.
      java.lang.String toString()
      Convert to printable format
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • n

        public java.math.BigInteger n
        The standard representation of the number
      • primeexp

        public java.util.Vector<java.lang.Integer> primeexp
      • ONE

        public static final Ifactor ONE
      • ZERO

        public static final Ifactor ZERO
    • Constructor Detail

      • Ifactor

        public Ifactor​(int number)
        Constructor given an integer. constructor with an ordinary integer
        Parameters:
        number - the standard representation of the integer
      • Ifactor

        public Ifactor​(java.math.BigInteger number)
        Constructor given a BigInteger . Constructor with an ordinary integer, calling a prime factor decomposition.
        Parameters:
        number - the BigInteger representation of the integer
      • Ifactor

        public Ifactor​(java.util.Vector<java.lang.Integer> pows)
        Constructor given a list of exponents of the prime factor decomposition.
        Parameters:
        pows - the vector with the sorted list of exponents. pows[0] is the exponent of 2, pows[1] the exponent of 3, pows[2] the exponent of 5 etc. Note that this list does not include the primes, but assumes a continuous prime-smooth basis.
      • Ifactor

        public Ifactor​(Ifactor oth)
        Copy constructor.
        Parameters:
        oth - the value to be copied
    • Method Detail

      • clone

        public Ifactor clone()
        Deep copy.
        Overrides:
        clone in class java.lang.Object
        Since:
        2009-08-14
      • equals

        public boolean equals​(Ifactor oth)
        Comparison of two numbers. The value of this method is in allowing the Vector<>.contains() calls that use the value, not the reference for comparison.
        Parameters:
        oth - the number to compare this with.
        Returns:
        true if both are the same numbers, false otherwise.
      • multiply

        public Ifactor multiply​(java.math.BigInteger oth)
        Multiply with another positive integer.
        Parameters:
        oth - the second factor.
        Returns:
        the product of both numbers.
      • multiply

        public Ifactor multiply​(int oth)
        Multiply with another positive integer.
        Parameters:
        oth - the second factor.
        Returns:
        the product of both numbers.
      • multiply

        public Ifactor multiply​(Ifactor oth)
        Multiply with another positive integer.
        Parameters:
        oth - the second factor.
        Returns:
        the product of both numbers.
      • lcm

        public Ifactor lcm​(Ifactor oth)
        Lowest common multiple of this with oth.
        Parameters:
        oth - the second parameter of lcm(this,oth)
        Returns:
        the lowest common multiple of both numbers. Returns zero if any of both arguments is zero.
      • gcd

        public Ifactor gcd​(Ifactor oth)
        Greatest common divisor of this and oth.
        Parameters:
        oth - the second parameter of gcd(this,oth)
        Returns:
        the lowest common multiple of both numbers. Returns zero if any of both arguments is zero.
      • multGcdLcm

        protected Ifactor multGcdLcm​(Ifactor oth,
                                     int type)
        Multiply with another positive integer.
        Parameters:
        oth - the second factor.
        type - 0 to multiply, 1 for gcd, 2 for lcm
        Returns:
        the product, gcd or lcm of both numbers.
      • divide

        public Ifactor divide​(Ifactor oth)
        Integer division through another positive integer.
        Parameters:
        oth - the denominator.
        Returns:
        the division of this through the oth, discarding the remainder.
      • add

        public Ifactor add​(java.math.BigInteger oth)
        Summation with another positive integer
        Parameters:
        oth - the other term.
        Returns:
        the sum of both numbers
      • pow

        public Ifactor pow​(int exponent)
                    throws java.lang.ArithmeticException
        Exponentiation with a positive integer.
        Parameters:
        exponent - the non-negative exponent
        Returns:
        n^exponent. If exponent=0, the result is 1.
        Throws:
        java.lang.ArithmeticException
      • root

        public Rational root​(int r)
                      throws java.lang.ArithmeticException
        Pulling the r-th root.
        Parameters:
        r - the positive or negative (nonzero) root.
        Returns:
        n^(1/r). The return value falls into the Ifactor class if r is positive, but if r is negative a Rational type is needed.
        Throws:
        java.lang.ArithmeticException
        Since:
        2009-05-18
      • divisors

        public java.util.Vector<java.math.BigInteger> divisors()
        The set of positive divisors.
        Returns:
        the vector of divisors of the absolute value, sorted.
        Since:
        2010-08-27
      • sigma

        public Ifactor sigma()
        Sum of the divisors of the number.
        Returns:
        the sum of all divisors of the number, 1+....+n.
      • sigma

        public Ifactor sigma​(int k)
        Sum of the k-th powers of divisors of the number.
        Returns:
        the sum of all divisors of the number, 1^k+....+n^k.
      • dropPrime

        public Ifactor dropPrime()
        Divide through the highest possible power of the highest prime. If the current number is the prime factor product p1^e1 * p2*e2* p3^e3*...*py^ey * pz^ez, the value returned has the final factor pz^ez eliminated, which gives p1^e1 * p2*e2* p3^e3*...*py^ey.
        Returns:
        the new integer obtained by removing the highest prime power. If this here represents 0 or 1, it is returned without change.
        Since:
        2006-08-20
      • issquare

        public boolean issquare()
        Test whether this is a square of an integer (perfect square).
        Returns:
        true if this is an integer squared (including 0), else false
      • bigomega

        public int bigomega()
        The sum of the prime factor exponents, with multiplicity.
        Returns:
        the sum over the primeexp numbers
      • omega

        public int omega()
        The sum of the prime factor exponents, without multiplicity.
        Returns:
        the number of distinct prime factors.
        Since:
        2008-10-16
      • core

        public java.math.BigInteger core()
        The square-free part.
        Returns:
        the minimum m such that m times this number is a square.
        Since:
        2008-10-16
      • moebius

        public int moebius()
        The Moebius function. 1 if n=1, else, if k is the number of distinct prime factors, return (-1)^k, else, if k has repeated prime factors, return 0.
        Returns:
        the moebius function.
      • max

        public Ifactor max​(Ifactor oth)
        Maximum of two values.
        Parameters:
        oth - the number to compare this with.
        Returns:
        the larger of the two values.
      • min

        public Ifactor min​(Ifactor oth)
        Minimum of two values.
        Parameters:
        oth - the number to compare this with.
        Returns:
        the smaller of the two values.
      • max

        public static Ifactor max​(java.util.Vector<Ifactor> set)
        Maximum of a list of values.
        Parameters:
        set - list of numbers.
        Returns:
        the largest in the list.
      • min

        public static Ifactor min​(java.util.Vector<Ifactor> set)
        Minimum of a list of values.
        Parameters:
        set - list of numbers.
        Returns:
        the smallest in the list.
      • compareTo

        public int compareTo​(Ifactor oth)
        Compare value against another Ifactor
        Specified by:
        compareTo in interface java.lang.Comparable<Ifactor>
        Parameters:
        oth - The value to be compared agains.
        Returns:
        1, 0 or -1 according to being larger, equal to or smaller than oth.
        Since:
        2012-02-15
      • toString

        public java.lang.String toString()
        Convert to printable format
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string of the form n:prime^pow*prime^pow*prime^pow...
      • main

        public static void main​(java.lang.String[] args)
                         throws java.lang.Exception
        Test program. It takes a single argument n and prints the integer factorizaton.
        java -cp . org.nevec.rjm.Ifactor n
        Throws:
        java.lang.Exception