Documentation of 'org.spaceroots.rkcheck.QuadraticSurd' Java class
QuadraticSurd
org.spaceroots.rkcheck

Class QuadraticSurd



  • public class QuadraticSurd
    extends java.lang.Object
    This class implements quadratic irrational numbers (which are also called quadratic surds).

    Quadratic irrational numbers are roots of quadratic polynoms with integer coefficients. They can be written:

             p1 + p2 sqrt (d)
       z =  ------------------
                   q
       
    where p1 and p2 are integers, d is a square free strictly positive integer and q is a strictly positive integer. This number is a root of:
         2  2                2       2
        q  X  - 2 q p1 X + p1  - d p2  = 0
       

    The set of quadratic irrational numbers associated with a given number d is a field denoted F[sqrt(d)]. This class implements computation within such a field.

    • Constructor Detail

      • QuadraticSurd

        public QuadraticSurd()
        Simple constructor. Build a null quadratic surd
      • QuadraticSurd

        public QuadraticSurd(long l)
        Simple constructor. Build a quadratic surd from a single integer
        Parameters:
        l - value of the quadratic surd
      • QuadraticSurd

        public QuadraticSurd(java.math.BigInteger l)
        Simple constructor. Build a quadratic surd from a single integer
        Parameters:
        l - value of the quadratic surd
      • QuadraticSurd

        public QuadraticSurd(long numerator,
                             long denominator)
        Simple constructor. Build a quadratic surd from a numerator and a denominator. This is a simple rational number.
        Parameters:
        numerator - numerator of the quadratic surd
        denominator - denominator of the quadratic surd
        Throws:
        java.lang.ArithmeticException - if the denominator is zero
      • QuadraticSurd

        public QuadraticSurd(java.math.BigInteger numerator,
                             java.math.BigInteger denominator)
        Simple constructor. Build a quadratic surd from a numerator and a denominator. This is a simple rational number.
        Parameters:
        numerator - numerator of the quadratic surd
        denominator - denominator of the quadratic surd
        Throws:
        java.lang.ArithmeticException - if the denominator is zero
      • QuadraticSurd

        public QuadraticSurd(long p1,
                             long p2,
                             long d,
                             long q)
        Simple constructor. Build a quadratic surd from its coordinates
        Parameters:
        p1 - integer part of the numerator
        p2 - coefficient of the root part of the numerator
        d - root
        q - denominator
        Throws:
        java.lang.ArithmeticException - if the root is negative
        java.lang.ArithmeticException - if the denominator is zero
      • QuadraticSurd

        public QuadraticSurd(java.math.BigInteger p1,
                             java.math.BigInteger p2,
                             java.math.BigInteger d,
                             java.math.BigInteger q)
        Simple constructor. Build a quadratic surd from its coordinates
        Parameters:
        p1 - integer part of the numerator
        p2 - coefficient of the root part of the numerator
        d - root
        q - denominator
        Throws:
        java.lang.ArithmeticException - if the root is negative
        java.lang.ArithmeticException - if the denominator is zero
      • QuadraticSurd

        public QuadraticSurd(java.math.BigDecimal r,
                             java.math.BigDecimal tolerance)
        Simple constructor. Build a quadratic surd by approximating a BigDecimal to a given tolerance using continued fractions
        Parameters:
        r - real number to approximate
        tolerance - tolerance allowed for the approximation
      • QuadraticSurd

        public QuadraticSurd(QuadraticSurd qs)
        Copy-constructor.
        Parameters:
        qs - quadratic surd to copy
    • Method Detail

      • sameField

        public boolean sameField(QuadraticSurd qs)
        Check if a quadratic surd belong to the same field as the instance.
        Parameters:
        qs - quadratic surd to check against the instance
        Returns:
        true if the specified quadratic surd belong to the same field as the instance
      • negateSelf

        public void negateSelf()
        Negate the instance
      • negate

        public static QuadraticSurd negate(QuadraticSurd qs)
        Negate a quadratic surd.
        Parameters:
        qs - quadratic surd to negate
        Returns:
        a new quadratic surd which is the opposite of r
      • addToSelf

        public void addToSelf(QuadraticSurd qs)
                       throws java.lang.ArithmeticException
        Add a quadratic surd to the instance.
        Parameters:
        qs - quadratic surd to add.
        Throws:
        java.lang.ArithmeticException - if the two quadratic surds do not belong to the same field (i.e. if they do not share the same root)
      • add

        public static QuadraticSurd add(QuadraticSurd qs1,
                                        QuadraticSurd qs2)
                                 throws java.lang.ArithmeticException
        Add two quadratic surds.
        Parameters:
        qs1 - first quadratic surd
        qs2 - second quadratic surd
        Returns:
        a new quadratic surd which is the sum of qs1 and qs2
        Throws:
        java.lang.ArithmeticException - if the two quadratic surds do not belong to the same field (i.e. if they do not share the same root)
      • subtractFromSelf

        public void subtractFromSelf(QuadraticSurd qs)
                              throws java.lang.ArithmeticException
        Subtract a quadratic surd to the instance.
        Parameters:
        qs - quadratic surd to subtract.
        Throws:
        java.lang.ArithmeticException - if the two quadratic surds do not belong to the same field (i.e. if they do not share the same root)
      • subtract

        public static QuadraticSurd subtract(QuadraticSurd qs1,
                                             QuadraticSurd qs2)
                                      throws java.lang.ArithmeticException
        Subtract two quadratic surds.
        Parameters:
        qs1 - first quadratic surd
        qs2 - second quadratic surd
        Returns:
        a new quadratic surd which is the difference qs1 minus qs2
        Throws:
        java.lang.ArithmeticException - if the two quadratic surds do not belong to the same field (i.e. if they do not share the same root)
      • multiplySelf

        public void multiplySelf(long l)
        Multiply the instance by an integer.
        Parameters:
        l - integer to multiply by
      • multiply

        public static QuadraticSurd multiply(QuadraticSurd qs,
                                             long l)
        Multiply a quadratic surd by an integer.
        Parameters:
        qs - quadratic surd
        l - integer to multiply by
      • multiplySelf

        public void multiplySelf(QuadraticSurd qs)
                          throws java.lang.ArithmeticException
        Multiply the instance by a quadratic surd.
        Parameters:
        qs - quadratic surd to multiply by
        Throws:
        java.lang.ArithmeticException - if the two quadratic surds do not belong to the same field (i.e. if they do not share the same root)
      • multiply

        public static QuadraticSurd multiply(QuadraticSurd qs1,
                                             QuadraticSurd qs2)
                                      throws java.lang.ArithmeticException
        Multiply two quadratic surds.
        Parameters:
        qs1 - first quadratic surd
        qs2 - second quadratic surd
        Returns:
        a new quadratic surd which is the product of qs1 and qs2
        Throws:
        java.lang.ArithmeticException - if the two quadratic surds do not belong to the same field (i.e. if they do not share the same root)
      • divideSelf

        public void divideSelf(long l)
                        throws java.lang.ArithmeticException
        Divide the instance by an integer.
        Parameters:
        l - integer to divide by
        Throws:
        java.lang.ArithmeticException - if l is zero
      • divide

        public static QuadraticSurd divide(QuadraticSurd qs,
                                           long l)
                                    throws java.lang.ArithmeticException
        Divide a quadratic surd by an integer
        Parameters:
        qs - quadratic surd
        l - integer
        Returns:
        a new quadratic surd which is the quotient of qs by l
        Throws:
        java.lang.ArithmeticException - if l is zero
      • divideSelf

        public void divideSelf(QuadraticSurd qs)
                        throws java.lang.ArithmeticException
        Divide the instance by a quadratic surd.
        Parameters:
        qs - quadratic surd to divide by
        Throws:
        java.lang.ArithmeticException - if qs is zero
        java.lang.ArithmeticException - if the two quadratic surds do not belong to the same field (i.e. if they do not share the same root)
      • divide

        public static QuadraticSurd divide(QuadraticSurd qs1,
                                           QuadraticSurd qs2)
        Divide two quadratic surds.
        Parameters:
        qs1 - first quadratic surd
        qs2 - second quadratic surd
        Returns:
        a new quadratic surd which is the quotient of qs1 by qs2
        Throws:
        java.lang.ArithmeticException - if qs2 is zero
        java.lang.ArithmeticException - if the two quadratic surds do not belong to the same field (i.e. if they do not share the same root)
      • invertSelf

        public void invertSelf()
                        throws java.lang.ArithmeticException
        Invert the instance. Replace the instance by its inverse.
        Throws:
        java.lang.ArithmeticException - if the instance is zero
      • invert

        public static QuadraticSurd invert(QuadraticSurd qs)
                                    throws java.lang.ArithmeticException
        Invert a quadratic surd.
        Parameters:
        qs - quadratic surd to invert
        Returns:
        a new quadratic surd which is the inverse of qs
        Throws:
        java.lang.ArithmeticException - if qs is zero
      • isZero

        public boolean isZero()
        Check if the instance is equal to 0.
        Returns:
        true if the instance is equal to 0
      • isOne

        public boolean isOne()
        Check if the instance is equal to 1.
        Returns:
        true if the instance is equal to 1
      • isInteger

        public boolean isInteger()
        Check if the number is integer.
        Returns:
        true if the number is an integer
      • isRational

        public boolean isRational()
        Check if the instance holds a rational number.
        Returns:
        true if the instance holds a rational number
      • equals

        public boolean equals(java.lang.Object o)
        Check if the instance is equal to another quadratic surd. Equality here is having the same value.
        Overrides:
        equals in class java.lang.Object
        Returns:
        true if the object is a quadratic surd which has the same value as the instance
      • hashCode

        public int hashCode()
        Returns a hash code value for the object. The hash code value is computed from the reduced coefficents, hence equal quadratic surds have the same hash code, as required by the method specification.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        a hash code value for this object.
      • getRationalNumerator

        public java.math.BigInteger getRationalNumerator()
        Get the numerator of the rational part.

        If the instance is a number of the form:

                 p1 + p2 sqrt (d)
           z =  ------------------
                       q
         
        then this method returns p1

        Returns:
        numerator of the rational part
      • getRootCoefficient

        public java.math.BigInteger getRootCoefficient()
        Get the coefficient of the irrational part.

        If the instance is a number of the form:

                 p1 + p2 sqrt (d)
           z =  ------------------
                       q
         
        then this method returns p2

        Returns:
        coefficient of the irrational part
      • getRootElement

        public java.math.BigInteger getRootElement()
        Get the root element of the irrational part.

        If the instance is a number of the form:

                 p1 + p2 sqrt (d)
           z =  ------------------
                       q
         
        then this method returns d

        Returns:
        root element of the irrational part
      • getDenominator

        public java.math.BigInteger getDenominator()
        Get the denominator.

        If the instance is a number of the form:

                 p1 + p2 sqrt (d)
           z =  ------------------
                       q
         
        then this method returns q

        Returns:
        denominator
      • doubleValue

        public double doubleValue()
        Returns the value of the underlying number as a double.
        Returns:
        the numeric value represented by this object after conversion to type double.
      • bigDecimalValue

        public java.math.BigDecimal bigDecimalValue(int scale)
        Returns the value of the underlying number as a BigDecimal.
        Parameters:
        scale - scale of the BigDecimal to return
        Returns:
        the numeric value represented by this object after conversion to type BigDecimal.
      • toString

        public java.lang.String toString()
        Returns a string representation of the underlying number.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation of the underlying number

DataMelt 3.0 © DataMelt by jWork.ORG

Ads help maintain this website.